const DATA_ATTRIBUTE = "data-ds-style-id"; const DEFAULT_SELECTOR = ":scope"; const SCOPE_REGISTRY = new Map(); const DOCUMENT_MANAGERS = new WeakMap(); function sanitizeScopeId(baseId) { if (typeof baseId !== "string") { return "ds-scope"; } const trimmed = baseId.trim(); if (!trimmed) { return "ds-scope"; } const normalized = trimmed.replace(/[^a-zA-Z0-9_-]+/g, "-"); return normalized || "ds-scope"; } function resolveDocument(documentRef) { if (documentRef && typeof documentRef === "object" && documentRef.nodeType === 9) { return documentRef; } if (typeof globalThis.document === "object" && globalThis.document?.nodeType === 9) { return globalThis.document; } return null; } function supportsConstructableStylesheets(doc) { return ( !!doc && Array.isArray(doc.adoptedStyleSheets) && typeof doc.adoptedStyleSheets.splice === "function" && typeof globalThis.CSSStyleSheet === "function" ); } function ensureManager(doc) { if (!doc) { return null; } let manager = DOCUMENT_MANAGERS.get(doc); if (manager) { return manager; } let sheet = null; let styleElement = null; const constructable = supportsConstructableStylesheets(doc); if (constructable) { sheet = new globalThis.CSSStyleSheet(); try { doc.adoptedStyleSheets = [...doc.adoptedStyleSheets, sheet]; } catch (error) { // Fall back to a