{"version":3,"file":"injectShadowStyles-C40qdwKI.mjs","names":[],"sources":["../src/shadow/isShadowRoot.ts","../src/shadow/injectShadowStyles.ts"],"sourcesContent":["/**\n * Type guard for a real ShadowRoot, used to ensure style injection never targets\n * `document.head`/`document.body` (which would break Shadow DOM style isolation).\n * @param {unknown} value - The candidate value.\n * @returns {boolean} True when the value is a ShadowRoot.\n */\nexport const isShadowRoot = (value: unknown): value is ShadowRoot => {\n  if (!value || typeof value !== 'object') return false\n\n  const nodeType = (value as Node).nodeType\n  return (\n    nodeType === Node.DOCUMENT_FRAGMENT_NODE &&\n    'host' in value &&\n    'mode' in value\n  )\n}\n","import { isShadowRoot } from './isShadowRoot'\n\n/**\n * Injects a CSS string into a ShadowRoot as a `<style>` element.\n *\n * Idempotent: reuses the element with the given id and only updates it when the\n * CSS changed. Throws when the target is not a ShadowRoot, so styles can never\n * leak outside the shadow tree.\n * @param {ShadowRoot} shadowRoot - The shadow root to inject into (required for isolation).\n * @param {string} cssText - The CSS to inject.\n * @param {string} styleElementId - Stable id for the injected `<style>` element.\n * @returns {void} Nothing.\n * @throws {Error} When `shadowRoot` is not a ShadowRoot instance.\n */\nexport const injectShadowStyles = (\n  shadowRoot: ShadowRoot,\n  cssText: string,\n  styleElementId: string,\n): void => {\n  if (!isShadowRoot(shadowRoot)) {\n    throw new Error(\n      'injectShadowStyles: shadowRoot must be a ShadowRoot instance. ' +\n        'CSS must never be injected outside shadowRoot for style isolation.',\n    )\n  }\n\n  const existing = shadowRoot.getElementById(styleElementId)\n  if (existing instanceof HTMLStyleElement) {\n    if (existing.textContent !== cssText) {\n      existing.textContent = cssText\n    }\n    return\n  }\n\n  const styleEl = document.createElement('style')\n  styleEl.id = styleElementId\n  styleEl.textContent = cssText\n  shadowRoot.appendChild(styleEl)\n}\n"],"mappings":";AAMA,IAAa,KAAgB,MACvB,CAAC,KAAS,OAAO,KAAU,WAAiB,KAE9B,EAAe,aAElB,KAAK,0BAClB,UAAU,KACV,UAAU,GCCD,KACX,GACA,GACA,MACS;CACT,IAAI,CAAC,EAAa,CAAU,GAC1B,MAAU,MACR,kIAEF;CAGF,IAAM,IAAW,EAAW,eAAe,CAAc;CACzD,IAAI,aAAoB,kBAAkB;EACxC,AAAI,EAAS,gBAAgB,MAC3B,EAAS,cAAc;EAEzB;CACF;CAEA,IAAM,IAAU,SAAS,cAAc,OAAO;CAG9C,AAFA,EAAQ,KAAK,GACb,EAAQ,cAAc,GACtB,EAAW,YAAY,CAAO;AAChC"}