@proveanything/smartlinks-utils-ui 0.9.2 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/assertStylesLoaded.ts"],"names":[],"mappings":";AAUA,IAAI,MAAA,GAAS,KAAA;AACb,IAAM,eAAA,uBAAsB,GAAA,EAAY;AAEjC,SAAS,kBAAA,GAA2B;AACzC,EAAA,IAAI,MAAA,EAAQ;AACZ,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,OAAO,aAAa,WAAA,EAAa;AAEtE,EAAA,MAAM,GAAA,GAAO,UAAA,CAA6D,OAAA,EAAS,GAAA,EAAK,QAAA;AACxF,EAAA,IAAI,QAAQ,YAAA,EAAc;AAC1B,EAAA,MAAA,GAAS,IAAA;AAGT,EAAA,UAAA,CAAW,MAAM;AACf,IAAA,IAAI;AACF,MAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AAC1C,MAAA,KAAA,CAAM,SAAA,GAAY,qBAAA;AAClB,MAAA,KAAA,CAAM,MAAM,QAAA,GAAW,UAAA;AACvB,MAAA,KAAA,CAAM,MAAM,UAAA,GAAa,QAAA;AACzB,MAAA,KAAA,CAAM,MAAM,aAAA,GAAgB,MAAA;AAC5B,MAAA,QAAA,CAAS,IAAA,CAAK,YAAY,KAAK,CAAA;AAC/B,MAAA,MAAM,MAAA,GAAS,gBAAA,CAAiB,KAAK,CAAA,CAAE,iBAAiB,gBAAgB,CAAA;AACxE,MAAA,QAAA,CAAS,IAAA,CAAK,YAAY,KAAK,CAAA;AAC/B,MAAA,IAAI,MAAA,CAAO,IAAA,EAAK,KAAM,QAAA,EAAU;AAE9B,QAAA,OAAA,CAAQ,IAAA;AAAA,UACN;AAAA,SAGF;AAAA,MACF;AAAA,IACF,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF,GAAG,CAAC,CAAA;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ers have imported the library stylesheet.\r\n *\r\n * The compiled `dist/index.css` ships an `.sl-ui-styles-loaded` utility\r\n * (synthesised from a Tailwind class used nowhere else in the build). If a\r\n * host app forgets `import '@proveanything/smartlinks-utils-ui/styles.css'`,\r\n * that class won't resolve and we log a one-time console warning.\r\n *\r\n * No-op in production builds, on the server, and after the first call.\r\n */\r\nlet warned = false;\r\nconst componentWarned = new Set<string>();\r\n\r\nexport function assertStylesLoaded(): void {\r\n if (warned) return;\r\n if (typeof window === 'undefined' || typeof document === 'undefined') return;\r\n // Best-effort prod check without depending on Node typings.\r\n const env = (globalThis as { process?: { env?: { NODE_ENV?: string } } }).process?.env?.NODE_ENV;\r\n if (env === 'production') return;\r\n warned = true;\r\n\r\n // Defer to next tick so the host's own stylesheet has a chance to load.\r\n setTimeout(() => {\r\n try {\r\n const probe = document.createElement('div');\r\n probe.className = 'sl-ui-styles-loaded';\r\n probe.style.position = 'absolute';\r\n probe.style.visibility = 'hidden';\r\n probe.style.pointerEvents = 'none';\r\n document.body.appendChild(probe);\r\n const marker = getComputedStyle(probe).getPropertyValue('--sl-ui-styles');\r\n document.body.removeChild(probe);\r\n if (marker.trim() !== 'loaded') {\r\n // eslint-disable-next-line no-console\r\n console.warn(\r\n '[@proveanything/smartlinks-utils-ui] Stylesheet not detected. ' +\r\n \"Add `import '@proveanything/smartlinks-utils-ui/styles.css';` \" +\r\n 'to your app entry. Components will render but look unstyled.'\r\n );\r\n }\r\n } catch {\r\n // Probe failed (jsdom, restrictive CSP, etc.) — stay silent.\r\n }\r\n }, 0);\r\n}\r\n\r\n/**\r\n * Per-component sentinel check. Each component's CSS file appends a\r\n * `.sl-ui-{name}-styles-loaded` rule with `--sl-ui-{name}-styles: loaded`.\r\n * When the base stylesheet is present but a component's CSS chunk wasn't\r\n * pulled in (e.g. host imported the main stylesheet but their bundler\r\n * stripped sibling CSS imports from the JS module graph), this surfaces\r\n * a targeted warning so the consumer knows exactly which import is\r\n * missing rather than puzzling at a totally-unstyled tree.\r\n */\r\nexport function assertComponentStylesLoaded(name: string): void {\r\n if (componentWarned.has(name)) return;\r\n if (typeof window === 'undefined' || typeof document === 'undefined') return;\r\n const env = (globalThis as { process?: { env?: { NODE_ENV?: string } } }).process?.env?.NODE_ENV;\r\n if (env === 'production') return;\r\n componentWarned.add(name);\r\n\r\n setTimeout(() => {\r\n try {\r\n const cls = `sl-ui-${name}-styles-loaded`;\r\n const cssVar = `--sl-ui-${name}-styles`;\r\n const probe = document.createElement('div');\r\n probe.className = cls;\r\n probe.style.position = 'absolute';\r\n probe.style.visibility = 'hidden';\r\n probe.style.pointerEvents = 'none';\r\n document.body.appendChild(probe);\r\n const marker = getComputedStyle(probe).getPropertyValue(cssVar);\r\n document.body.removeChild(probe);\r\n if (marker.trim() !== 'loaded') {\r\n // eslint-disable-next-line no-console\r\n console.warn(\r\n `[@proveanything/smartlinks-utils-ui] \"${name}\" component CSS not detected. ` +\r\n \"Re-import `'@proveanything/smartlinks-utils-ui/styles.css'` AFTER any of \" +\r\n 'your own Tailwind/global stylesheets — a stale `dist/index.css` build that ' +\r\n \"predates this component will also trigger this. The base stylesheet is loaded, \" +\r\n \"so the component CSS chunk is what's missing.\"\r\n );\r\n }\r\n } catch {\r\n // Probe failed (jsdom, restrictive CSP, etc.) — stay silent.\r\n }\r\n }, 0);\r\n}"]}