{"version":3,"names":["ownerDocument","DISABLE_SCROLLBAR_STYLE","ATTRIBUTE","registry","WeakMap","registerDisableScrollbarStyle","anchor","nonce","doc","entry","get","existing","querySelector","element","createElement","setAttribute","textContent","head","appendChild","count","set","current","remove","delete"],"sources":["register-disable-scrollbar-style.ts"],"sourcesContent":["import { ownerDocument } from \"../dom/owner-document.ts\";\nimport { DISABLE_SCROLLBAR_STYLE } from \"./style-disable-scrollbar.ts\";\n\n/**\n * Per-document ref-counted disable-scrollbar style registration.\n *\n * Each `<ScrollArea.Root>` would otherwise inject its own `<style>` tag with\n * identical CSS — multiple roots on the page give you N copies of the same\n * rules. This helper installs a single `<style>` per document (keyed by the\n * element's owning document so shadow roots and iframe documents don't\n * cross-pollute with the main document) and increments a counter for every\n * mount; only the last unmount removes the tag.\n *\n * Shadow-DOM note: `ownerDocument` walks up to the owning `Document` (not\n * the shadow-root), so a style registered from inside a shadow tree still\n * lives in the owning document's `<head>`. This matches the rest of the\n * `internals/dom/` utilities.\n */\n\nconst ATTRIBUTE = \"data-quoin-scroll-area-disable\";\n\ninterface Entry {\n\tcount: number;\n\telement: HTMLStyleElement;\n}\n\nconst registry = new WeakMap<Document, Entry>();\n\nexport function registerDisableScrollbarStyle(\n\tanchor: Node | null | undefined,\n\tnonce: string | undefined,\n): () => void {\n\tconst doc = ownerDocument(anchor);\n\n\tlet entry = registry.get(doc);\n\tif (entry == null) {\n\t\t// Look for an existing tag injected by a prior registration that lost\n\t\t// its WeakMap entry (e.g. during HMR). Reuse it rather than stacking.\n\t\tconst existing = doc.querySelector<HTMLStyleElement>(`style[${ATTRIBUTE}]`);\n\t\tconst element = existing ?? doc.createElement(\"style\");\n\t\tif (existing == null) {\n\t\t\telement.setAttribute(ATTRIBUTE, \"\");\n\t\t\tif (nonce) element.setAttribute(\"nonce\", nonce);\n\t\t\telement.textContent = DISABLE_SCROLLBAR_STYLE;\n\t\t\tdoc.head.appendChild(element);\n\t\t}\n\t\tentry = { count: 0, element };\n\t\tregistry.set(doc, entry);\n\t}\n\n\tentry.count += 1;\n\n\treturn () => {\n\t\tconst current = registry.get(doc);\n\t\tif (current == null) return;\n\t\tcurrent.count -= 1;\n\t\tif (current.count <= 0) {\n\t\t\tcurrent.element.remove();\n\t\t\tregistry.delete(doc);\n\t\t}\n\t};\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,0BAA0B;AACxD,SAASC,uBAAuB,QAAQ,8BAA8B;;AAEtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,SAAS,GAAG,gCAAgC;AAOlD,MAAMC,QAAQ,GAAG,IAAIC,OAAO,CAAkB,CAAC;AAE/C,OAAO,SAASC,6BAA6BA,CAC5CC,MAA+B,EAC/BC,KAAyB,EACZ;EACb,MAAMC,GAAG,GAAGR,aAAa,CAACM,MAAM,CAAC;EAEjC,IAAIG,KAAK,GAAGN,QAAQ,CAACO,GAAG,CAACF,GAAG,CAAC;EAC7B,IAAIC,KAAK,IAAI,IAAI,EAAE;IAClB;IACA;IACA,MAAME,QAAQ,GAAGH,GAAG,CAACI,aAAa,CAAmB,SAASV,SAAS,GAAG,CAAC;IAC3E,MAAMW,OAAO,GAAGF,QAAQ,IAAIH,GAAG,CAACM,aAAa,CAAC,OAAO,CAAC;IACtD,IAAIH,QAAQ,IAAI,IAAI,EAAE;MACrBE,OAAO,CAACE,YAAY,CAACb,SAAS,EAAE,EAAE,CAAC;MACnC,IAAIK,KAAK,EAAEM,OAAO,CAACE,YAAY,CAAC,OAAO,EAAER,KAAK,CAAC;MAC/CM,OAAO,CAACG,WAAW,GAAGf,uBAAuB;MAC7CO,GAAG,CAACS,IAAI,CAACC,WAAW,CAACL,OAAO,CAAC;IAC9B;IACAJ,KAAK,GAAG;MAAEU,KAAK,EAAE,CAAC;MAAEN;IAAQ,CAAC;IAC7BV,QAAQ,CAACiB,GAAG,CAACZ,GAAG,EAAEC,KAAK,CAAC;EACzB;EAEAA,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