@jasonshimmy/custom-elements-runtime 3.0.0 → 3.1.0

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.
Files changed (63) hide show
  1. package/README.md +118 -81
  2. package/dist/custom-elements-runtime.cjs.js +3 -3
  3. package/dist/custom-elements-runtime.cjs.js.map +1 -1
  4. package/dist/custom-elements-runtime.es.js +77 -72
  5. package/dist/custom-elements-runtime.es.js.map +1 -1
  6. package/dist/custom-elements-runtime.jit-css.cjs.js +1 -1
  7. package/dist/custom-elements-runtime.jit-css.cjs.js.map +1 -1
  8. package/dist/custom-elements-runtime.jit-css.es.js +25 -26
  9. package/dist/custom-elements-runtime.jit-css.es.js.map +1 -1
  10. package/dist/custom-elements-runtime.router.cjs.js +8 -8
  11. package/dist/custom-elements-runtime.router.cjs.js.map +1 -1
  12. package/dist/custom-elements-runtime.router.es.js +134 -134
  13. package/dist/custom-elements-runtime.router.es.js.map +1 -1
  14. package/dist/custom-elements-runtime.ssr-middleware.cjs.js +2 -0
  15. package/dist/custom-elements-runtime.ssr-middleware.cjs.js.map +1 -0
  16. package/dist/custom-elements-runtime.ssr-middleware.es.js +63 -0
  17. package/dist/custom-elements-runtime.ssr-middleware.es.js.map +1 -0
  18. package/dist/custom-elements-runtime.ssr.cjs.js +3 -1
  19. package/dist/custom-elements-runtime.ssr.cjs.js.map +1 -1
  20. package/dist/custom-elements-runtime.ssr.es.js +137 -39
  21. package/dist/custom-elements-runtime.ssr.es.js.map +1 -1
  22. package/dist/custom-elements-runtime.vite-plugin.cjs.js +1 -1
  23. package/dist/custom-elements-runtime.vite-plugin.cjs.js.map +1 -1
  24. package/dist/custom-elements-runtime.vite-plugin.es.js +81 -49
  25. package/dist/custom-elements-runtime.vite-plugin.es.js.map +1 -1
  26. package/dist/hooks-B50HhrHh.cjs +6 -0
  27. package/dist/hooks-B50HhrHh.cjs.map +1 -0
  28. package/dist/hooks-Cze3o-F7.js +1462 -0
  29. package/dist/hooks-Cze3o-F7.js.map +1 -0
  30. package/dist/index.d.ts +3 -0
  31. package/dist/namespace-helpers-D4wC2-qA.js +61 -0
  32. package/dist/namespace-helpers-D4wC2-qA.js.map +1 -0
  33. package/dist/namespace-helpers-ckeEOxpR.cjs +2 -0
  34. package/dist/namespace-helpers-ckeEOxpR.cjs.map +1 -0
  35. package/dist/router/matcher.d.ts +14 -0
  36. package/dist/runtime/component/factory.d.ts +16 -2
  37. package/dist/runtime/hydration.d.ts +33 -0
  38. package/dist/runtime/ssr-context.d.ts +45 -0
  39. package/dist/runtime/types.d.ts +18 -0
  40. package/dist/runtime/vdom-ssr-dsd.d.ts +58 -0
  41. package/dist/ssr-middleware.d.ts +125 -0
  42. package/dist/ssr.d.ts +95 -33
  43. package/dist/template-compiler-Cshhqxyd.cjs +23 -0
  44. package/dist/template-compiler-Cshhqxyd.cjs.map +1 -0
  45. package/dist/{template-compiler-B5uN1EQw.js → template-compiler-DtpNsqE-.js} +1296 -1283
  46. package/dist/template-compiler-DtpNsqE-.js.map +1 -0
  47. package/dist/vite-plugin.d.ts +94 -4
  48. package/package.json +6 -1
  49. package/dist/helpers-CweFZFWU.js +0 -987
  50. package/dist/helpers-CweFZFWU.js.map +0 -1
  51. package/dist/helpers-DeWjSmOl.cjs +0 -5
  52. package/dist/helpers-DeWjSmOl.cjs.map +0 -1
  53. package/dist/hooks-BrrLKSub.cjs +0 -3
  54. package/dist/hooks-BrrLKSub.cjs.map +0 -1
  55. package/dist/hooks-DyShDHKo.js +0 -403
  56. package/dist/hooks-DyShDHKo.js.map +0 -1
  57. package/dist/namespace-helpers-CnpZ5__p.js +0 -45
  58. package/dist/namespace-helpers-CnpZ5__p.js.map +0 -1
  59. package/dist/namespace-helpers-CyIDtI97.cjs +0 -2
  60. package/dist/namespace-helpers-CyIDtI97.cjs.map +0 -1
  61. package/dist/template-compiler-B5uN1EQw.js.map +0 -1
  62. package/dist/template-compiler-Cx623BSB.cjs +0 -23
  63. package/dist/template-compiler-Cx623BSB.cjs.map +0 -1
@@ -1,73 +1,105 @@
1
- import { globSync as y, mkdirSync as C, writeFileSync as v, readFileSync as I } from "node:fs";
2
- import { resolve as u, dirname as F } from "node:path";
3
- import { e as b, b as g, j } from "./style-BmyOIMcU.js";
4
- const T = "virtual:cer-jit-css", m = "\0virtual:cer-jit-css";
5
- function w(f, s) {
6
- s && Object.keys(s).length > 0 && b(s);
7
- const o = process.cwd(), i = [];
8
- for (const r of f) {
9
- const e = y(r, { cwd: o }).map((c) => u(o, c));
10
- i.push(...e);
1
+ import { globSync as I, mkdirSync as w, writeFileSync as g, readFileSync as y } from "node:fs";
2
+ import { resolve as S, dirname as j } from "node:path";
3
+ import { e as V, b, j as L } from "./style-BmyOIMcU.js";
4
+ const R = "virtual:cer-jit-css", m = "\0virtual:cer-jit-css";
5
+ function p(t, r) {
6
+ r && Object.keys(r).length > 0 && V(r);
7
+ const e = process.cwd(), n = [];
8
+ for (const i of t) {
9
+ const o = I(i, { cwd: e }).map((l) => S(e, l));
10
+ n.push(...o);
11
11
  }
12
- const S = [...new Set(i)], a = /* @__PURE__ */ new Set();
13
- for (const r of S)
12
+ const c = [...new Set(n)], d = /* @__PURE__ */ new Set();
13
+ for (const i of c)
14
14
  try {
15
- const e = I(r, "utf-8"), c = g(e);
16
- for (const t of c) a.add(t);
15
+ const o = y(i, "utf-8"), l = b(o);
16
+ for (const s of l) d.add(s);
17
17
  } catch {
18
18
  }
19
- if (a.size === 0) return "";
20
- const p = `<div class="${[...a].join(" ")}"></div>`;
21
- return j(p);
19
+ if (d.size === 0) return "";
20
+ const v = `<div class="${[...d].join(" ")}"></div>`;
21
+ return L(v);
22
22
  }
23
- function V(f) {
23
+ const T = "virtual:cer-ssr-config", C = "\0virtual:cer-ssr-config";
24
+ function D(t) {
25
+ const r = [];
26
+ if (t.content && t.content.length > 0 && r.push(
27
+ _({
28
+ content: t.content,
29
+ output: t.output,
30
+ virtualModule: t.virtualModule,
31
+ extendedColors: t.extendedColors,
32
+ customColors: t.customColors,
33
+ disableVariants: t.disableVariants
34
+ })
35
+ ), t.ssr) {
36
+ const e = t.ssr, n = {
37
+ dsd: e.dsd ?? !0,
38
+ dsdPolyfill: e.dsdPolyfill ?? !0,
39
+ ...e.jit ? { jit: e.jit } : {}
40
+ };
41
+ r.push({
42
+ name: "cer-ssr-config",
43
+ resolveId(c) {
44
+ if (c === T) return C;
45
+ },
46
+ load(c) {
47
+ if (c === C)
48
+ return `export default ${JSON.stringify(n)};`;
49
+ }
50
+ });
51
+ }
52
+ return r;
53
+ }
54
+ function _(t) {
24
55
  const {
25
- content: s,
26
- output: o,
27
- virtualModule: i = !0,
28
- extendedColors: S,
29
- customColors: a,
30
- disableVariants: p
31
- } = f, r = {
32
- extendedColors: S,
33
- customColors: a,
34
- disableVariants: p
56
+ content: r,
57
+ output: e,
58
+ virtualModule: n = !0,
59
+ extendedColors: c,
60
+ customColors: d,
61
+ disableVariants: v
62
+ } = t, i = {
63
+ extendedColors: c,
64
+ customColors: d,
65
+ disableVariants: v
35
66
  };
36
- let e = "", c = null;
67
+ let o = "", l = null;
37
68
  return {
38
69
  name: "cer-jit-css",
39
70
  buildStart() {
40
- const t = process.cwd(), d = /* @__PURE__ */ new Set();
41
- for (const l of s)
42
- y(l, { cwd: t }).forEach((n) => d.add(u(t, n)));
43
- if (c = d, e = w(s, r), o) {
44
- const l = u(process.cwd(), o);
45
- C(F(l), { recursive: !0 }), v(l, e, "utf-8");
71
+ const s = process.cwd(), f = /* @__PURE__ */ new Set();
72
+ for (const a of r)
73
+ I(a, { cwd: s }).forEach((u) => f.add(S(s, u)));
74
+ if (l = f, o = p(r, i), e) {
75
+ const a = S(process.cwd(), e);
76
+ w(j(a), { recursive: !0 }), g(a, o, "utf-8");
46
77
  }
47
78
  },
48
- resolveId(t) {
49
- if (i && t === T)
79
+ resolveId(s) {
80
+ if (n && s === R)
50
81
  return m;
51
82
  },
52
- load(t) {
53
- if (t === m)
54
- return `export default ${JSON.stringify(e)};`;
83
+ load(s) {
84
+ if (s === m)
85
+ return `export default ${JSON.stringify(o)};`;
55
86
  },
56
- handleHotUpdate({ file: t, server: d }) {
57
- if (c?.has(t) ?? !1) {
58
- if (e = w(s, r), o) {
59
- const n = u(process.cwd(), o);
60
- v(n, e, "utf-8");
87
+ handleHotUpdate({ file: s, server: f }) {
88
+ if (l?.has(s) ?? !1) {
89
+ if (o = p(r, i), e) {
90
+ const u = S(process.cwd(), e);
91
+ g(u, o, "utf-8");
61
92
  }
62
- if (i) {
63
- const n = d, h = n.moduleGraph.getModuleById(m);
64
- h && n.reloadModule(h);
93
+ if (n) {
94
+ const u = f, h = u.moduleGraph.getModuleById(m);
95
+ h && u.reloadModule(h);
65
96
  }
66
97
  }
67
98
  }
68
99
  };
69
100
  }
70
101
  export {
71
- V as cerJITCSS
102
+ _ as cerJITCSS,
103
+ D as cerPlugin
72
104
  };
73
105
  //# sourceMappingURL=custom-elements-runtime.vite-plugin.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom-elements-runtime.vite-plugin.es.js","sources":["../src/lib/vite-plugin.ts"],"sourcesContent":["/**\n * Vite plugin for build-time JIT CSS generation.\n *\n * Scans source files for utility class names and emits pre-generated CSS,\n * eliminating all runtime parsing cost for projects with static class lists.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import { cerJITCSS } from '@jasonshimmy/custom-elements-runtime/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [\n * cerJITCSS({\n * content: ['./src/**\\/*.{ts,tsx,html}'],\n * output: 'src/generated-jit.css',\n * extendedColors: true,\n * }),\n * ],\n * });\n * ```\n */\n\nimport type { Plugin } from 'vite';\nimport { readFileSync, writeFileSync, mkdirSync, globSync } from 'node:fs';\nimport { resolve, dirname } from 'node:path';\nimport {\n jitCSS,\n enableJITCSS,\n extractClassesFromHTML,\n type JITCSSOptions,\n} from './runtime/style';\n\n// --- Re-export extractClassesFromHTML for plugin consumers ---\n\n/**\n * Options for the `cerJITCSS` Vite plugin.\n */\nexport interface CerJITCSSPluginOptions extends JITCSSOptions {\n /**\n * Glob patterns (relative to `process.cwd()`) that identify which source\n * files the plugin should scan for utility class names.\n *\n * @example `['./src/**\\/*.{ts,html}', './index.html']`\n */\n content: string[];\n /**\n * File path (relative to `process.cwd()`) where the generated CSS will\n * be written. When omitted the plugin only emits a virtual module.\n */\n output?: string;\n /**\n * Whether to emit a virtual module `virtual:cer-jit-css` that resolves to\n * the generated CSS text. Defaults to `true`.\n */\n virtualModule?: boolean;\n}\n\nconst VIRTUAL_ID = 'virtual:cer-jit-css';\nconst RESOLVED_VIRTUAL_ID = '\\0virtual:cer-jit-css';\n\nfunction generateFromFiles(\n contentPatterns: string[],\n jitOptions: JITCSSOptions,\n): string {\n if (jitOptions && Object.keys(jitOptions).length > 0) {\n enableJITCSS(jitOptions);\n }\n\n const cwd = process.cwd();\n const files: string[] = [];\n\n for (const pattern of contentPatterns) {\n const matches = globSync(pattern, { cwd }).map((f) => resolve(cwd, f));\n files.push(...matches);\n }\n\n // Deduplicate files\n const uniqueFiles = [...new Set(files)];\n\n // Aggregate all class names across all files\n const allClasses = new Set<string>();\n\n for (const file of uniqueFiles) {\n try {\n const content = readFileSync(file, 'utf-8');\n const classes = extractClassesFromHTML(content);\n for (const cls of classes) allClasses.add(cls);\n } catch {\n // Skip unreadable files\n }\n }\n\n if (allClasses.size === 0) return '';\n\n // Build a fake HTML string containing all discovered classes so jitCSS()\n // can process the full set in one pass.\n const fakeHTML = `<div class=\"${[...allClasses].join(' ')}\"></div>`;\n return jitCSS(fakeHTML);\n}\n\n/**\n * Vite plugin that performs a build-time scan of source files and emits\n * pre-generated JIT CSS as a file and/or `virtual:cer-jit-css` module.\n */\nexport function cerJITCSS(options: CerJITCSSPluginOptions): Plugin {\n const {\n content,\n output,\n virtualModule = true,\n extendedColors,\n customColors,\n disableVariants,\n } = options;\n\n const jitOptions: JITCSSOptions = {\n extendedColors,\n customColors,\n disableVariants,\n };\n\n let generatedCSS = '';\n // Resolved file set built in buildStart and reused in handleHotUpdate to\n // avoid re-running globSync for every HMR file-change event.\n let watchedFiles: Set<string> | null = null;\n\n return {\n name: 'cer-jit-css',\n\n buildStart() {\n const cwd = process.cwd();\n const resolved = new Set<string>();\n for (const pattern of content) {\n globSync(pattern, { cwd }).forEach((f) => resolved.add(resolve(cwd, f)));\n }\n watchedFiles = resolved;\n\n generatedCSS = generateFromFiles(content, jitOptions);\n\n if (output) {\n const outputPath = resolve(process.cwd(), output);\n mkdirSync(dirname(outputPath), { recursive: true });\n writeFileSync(outputPath, generatedCSS, 'utf-8');\n }\n },\n\n resolveId(id: string) {\n if (virtualModule && id === VIRTUAL_ID) {\n return RESOLVED_VIRTUAL_ID;\n }\n return undefined;\n },\n\n load(id: string) {\n if (id === RESOLVED_VIRTUAL_ID) {\n return `export default ${JSON.stringify(generatedCSS)};`;\n }\n return undefined;\n },\n\n handleHotUpdate({ file, server }: { file: string; server: unknown }) {\n // Re-generate when a watched source file changes.\n // Use the cached file set from buildStart to avoid re-globbing.\n const isWatched = watchedFiles?.has(file) ?? false;\n\n if (!isWatched) return;\n\n generatedCSS = generateFromFiles(content, jitOptions);\n\n if (output) {\n const outputPath = resolve(process.cwd(), output);\n writeFileSync(outputPath, generatedCSS, 'utf-8');\n }\n\n if (virtualModule) {\n // Invalidate the virtual module so HMR triggers a reload\n const viteServer = server as {\n moduleGraph: { getModuleById: (id: string) => unknown };\n reloadModule: (mod: unknown) => void;\n };\n const mod = viteServer.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);\n if (mod) viteServer.reloadModule(mod);\n }\n },\n };\n}\n"],"names":["VIRTUAL_ID","RESOLVED_VIRTUAL_ID","generateFromFiles","contentPatterns","jitOptions","enableJITCSS","cwd","files","pattern","matches","globSync","f","resolve","uniqueFiles","allClasses","file","content","readFileSync","classes","extractClassesFromHTML","cls","fakeHTML","jitCSS","cerJITCSS","options","output","virtualModule","extendedColors","customColors","disableVariants","generatedCSS","watchedFiles","resolved","outputPath","mkdirSync","dirname","writeFileSync","id","server","viteServer","mod"],"mappings":";;;AA2DA,MAAMA,IAAa,uBACbC,IAAsB;AAE5B,SAASC,EACPC,GACAC,GACQ;AACR,EAAIA,KAAc,OAAO,KAAKA,CAAU,EAAE,SAAS,KACjDC,EAAaD,CAAU;AAGzB,QAAME,IAAM,QAAQ,IAAA,GACdC,IAAkB,CAAA;AAExB,aAAWC,KAAWL,GAAiB;AACrC,UAAMM,IAAUC,EAASF,GAAS,EAAE,KAAAF,EAAA,CAAK,EAAE,IAAI,CAACK,MAAMC,EAAQN,GAAKK,CAAC,CAAC;AACrE,IAAAJ,EAAM,KAAK,GAAGE,CAAO;AAAA,EACvB;AAGA,QAAMI,IAAc,CAAC,GAAG,IAAI,IAAIN,CAAK,CAAC,GAGhCO,wBAAiB,IAAA;AAEvB,aAAWC,KAAQF;AACjB,QAAI;AACF,YAAMG,IAAUC,EAAaF,GAAM,OAAO,GACpCG,IAAUC,EAAuBH,CAAO;AAC9C,iBAAWI,KAAOF,EAAS,CAAAJ,EAAW,IAAIM,CAAG;AAAA,IAC/C,QAAQ;AAAA,IAER;AAGF,MAAIN,EAAW,SAAS,EAAG,QAAO;AAIlC,QAAMO,IAAW,eAAe,CAAC,GAAGP,CAAU,EAAE,KAAK,GAAG,CAAC;AACzD,SAAOQ,EAAOD,CAAQ;AACxB;AAMO,SAASE,EAAUC,GAAyC;AACjE,QAAM;AAAA,IACJ,SAAAR;AAAA,IACA,QAAAS;AAAA,IACA,eAAAC,IAAgB;AAAA,IAChB,gBAAAC;AAAA,IACA,cAAAC;AAAA,IACA,iBAAAC;AAAA,EAAA,IACEL,GAEEpB,IAA4B;AAAA,IAChC,gBAAAuB;AAAA,IACA,cAAAC;AAAA,IACA,iBAAAC;AAAA,EAAA;AAGF,MAAIC,IAAe,IAGfC,IAAmC;AAEvC,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,aAAa;AACX,YAAMzB,IAAM,QAAQ,IAAA,GACd0B,wBAAe,IAAA;AACrB,iBAAWxB,KAAWQ;AACpB,QAAAN,EAASF,GAAS,EAAE,KAAAF,EAAA,CAAK,EAAE,QAAQ,CAACK,MAAMqB,EAAS,IAAIpB,EAAQN,GAAKK,CAAC,CAAC,CAAC;AAMzE,UAJAoB,IAAeC,GAEfF,IAAe5B,EAAkBc,GAASZ,CAAU,GAEhDqB,GAAQ;AACV,cAAMQ,IAAarB,EAAQ,QAAQ,IAAA,GAAOa,CAAM;AAChD,QAAAS,EAAUC,EAAQF,CAAU,GAAG,EAAE,WAAW,IAAM,GAClDG,EAAcH,GAAYH,GAAc,OAAO;AAAA,MACjD;AAAA,IACF;AAAA,IAEA,UAAUO,GAAY;AACpB,UAAIX,KAAiBW,MAAOrC;AAC1B,eAAOC;AAAA,IAGX;AAAA,IAEA,KAAKoC,GAAY;AACf,UAAIA,MAAOpC;AACT,eAAO,kBAAkB,KAAK,UAAU6B,CAAY,CAAC;AAAA,IAGzD;AAAA,IAEA,gBAAgB,EAAE,MAAAf,GAAM,QAAAuB,KAA6C;AAKnE,UAFkBP,GAAc,IAAIhB,CAAI,KAAK,IAM7C;AAAA,YAFAe,IAAe5B,EAAkBc,GAASZ,CAAU,GAEhDqB,GAAQ;AACV,gBAAMQ,IAAarB,EAAQ,QAAQ,IAAA,GAAOa,CAAM;AAChD,UAAAW,EAAcH,GAAYH,GAAc,OAAO;AAAA,QACjD;AAEA,YAAIJ,GAAe;AAEjB,gBAAMa,IAAaD,GAIbE,IAAMD,EAAW,YAAY,cAActC,CAAmB;AACpE,UAAIuC,KAAKD,EAAW,aAAaC,CAAG;AAAA,QACtC;AAAA;AAAA,IACF;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"custom-elements-runtime.vite-plugin.es.js","sources":["../src/lib/vite-plugin.ts"],"sourcesContent":["/**\n * Vite plugins for build-time JIT CSS generation and SSR configuration.\n *\n * Two plugins are exported:\n *\n * - **`cerJITCSS`** — Scans source files for utility class names and emits\n * pre-generated CSS, eliminating all runtime parsing cost for projects with\n * static class lists.\n *\n * - **`cerPlugin`** — All-in-one plugin combining `cerJITCSS` with SSR\n * configuration. Exposes a `virtual:cer-ssr-config` module containing the\n * resolved SSR render options so server entry files can import and use them\n * without duplication.\n *\n * @example cerJITCSS only\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import { cerJITCSS } from '@jasonshimmy/custom-elements-runtime/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [\n * cerJITCSS({\n * content: ['./src/**\\/*.{ts,tsx,html}'],\n * output: 'src/generated-jit.css',\n * extendedColors: true,\n * }),\n * ],\n * });\n * ```\n *\n * @example cerPlugin with SSR\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import { cerPlugin } from '@jasonshimmy/custom-elements-runtime/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [\n * cerPlugin({\n * content: ['./src/**\\/*.{ts,tsx,html}'],\n * ssr: {\n * dsd: true,\n * jit: { extendedColors: true },\n * },\n * }),\n * ],\n * });\n * ```\n *\n * Then in your server entry:\n * ```ts\n * import ssrConfig from 'virtual:cer-ssr-config';\n * import { renderToStringWithJITCSS } from '@jasonshimmy/custom-elements-runtime/ssr';\n *\n * const { htmlWithStyles } = renderToStringWithJITCSS(appVNode, ssrConfig);\n * ```\n */\n\nimport type { Plugin } from 'vite';\nimport { readFileSync, writeFileSync, mkdirSync, globSync } from 'node:fs';\nimport { resolve, dirname } from 'node:path';\nimport {\n jitCSS,\n enableJITCSS,\n extractClassesFromHTML,\n type JITCSSOptions,\n} from './runtime/style';\n\n// --- Re-export extractClassesFromHTML for plugin consumers ---\n\n/**\n * Options for the `cerJITCSS` Vite plugin.\n */\nexport interface CerJITCSSPluginOptions extends JITCSSOptions {\n /**\n * Glob patterns (relative to `process.cwd()`) that identify which source\n * files the plugin should scan for utility class names.\n *\n * @example `['./src/**\\/*.{ts,html}', './index.html']`\n */\n content: string[];\n /**\n * File path (relative to `process.cwd()`) where the generated CSS will\n * be written. When omitted the plugin only emits a virtual module.\n */\n output?: string;\n /**\n * Whether to emit a virtual module `virtual:cer-jit-css` that resolves to\n * the generated CSS text. Defaults to `true`.\n */\n virtualModule?: boolean;\n}\n\nconst VIRTUAL_ID = 'virtual:cer-jit-css';\nconst RESOLVED_VIRTUAL_ID = '\\0virtual:cer-jit-css';\n\nfunction generateFromFiles(\n contentPatterns: string[],\n jitOptions: JITCSSOptions,\n): string {\n if (jitOptions && Object.keys(jitOptions).length > 0) {\n enableJITCSS(jitOptions);\n }\n\n const cwd = process.cwd();\n const files: string[] = [];\n\n for (const pattern of contentPatterns) {\n const matches = globSync(pattern, { cwd }).map((f) => resolve(cwd, f));\n files.push(...matches);\n }\n\n // Deduplicate files\n const uniqueFiles = [...new Set(files)];\n\n // Aggregate all class names across all files\n const allClasses = new Set<string>();\n\n for (const file of uniqueFiles) {\n try {\n const content = readFileSync(file, 'utf-8');\n const classes = extractClassesFromHTML(content);\n for (const cls of classes) allClasses.add(cls);\n } catch {\n // Skip unreadable files\n }\n }\n\n if (allClasses.size === 0) return '';\n\n // Build a fake HTML string containing all discovered classes so jitCSS()\n // can process the full set in one pass.\n const fakeHTML = `<div class=\"${[...allClasses].join(' ')}\"></div>`;\n return jitCSS(fakeHTML);\n}\n\n// ---------------------------------------------------------------------------\n// cerPlugin — combined JIT CSS + SSR configuration plugin\n// ---------------------------------------------------------------------------\n\n/**\n * SSR render options exposed via `virtual:cer-ssr-config`.\n */\nexport interface CerSSROptions {\n /**\n * Emit Declarative Shadow DOM output for registered custom elements.\n * @default true\n */\n dsd?: boolean;\n /**\n * Append the DSD polyfill `<script>` for browsers without native support.\n * @default true\n */\n dsdPolyfill?: boolean;\n /**\n * JIT CSS options forwarded to the SSR render pass.\n */\n jit?: JITCSSOptions;\n}\n\n/**\n * Options for the combined {@link cerPlugin}.\n */\nexport interface CerPluginOptions extends Partial<CerJITCSSPluginOptions> {\n /**\n * SSR configuration. When provided, a `virtual:cer-ssr-config` module is\n * registered so server entry files can import the resolved render options:\n *\n * ```ts\n * import ssrConfig from 'virtual:cer-ssr-config';\n * import { renderToStringWithJITCSS } from '@jasonshimmy/custom-elements-runtime/ssr';\n *\n * const { htmlWithStyles } = renderToStringWithJITCSS(appVNode, ssrConfig);\n * ```\n */\n ssr?: CerSSROptions;\n}\n\nconst VIRTUAL_SSR_ID = 'virtual:cer-ssr-config';\nconst RESOLVED_VIRTUAL_SSR_ID = '\\0virtual:cer-ssr-config';\n\n/**\n * All-in-one Vite plugin combining build-time JIT CSS generation with SSR\n * configuration. Returns an array of plugins so it can be spread directly\n * into the `plugins` array without nesting.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * export default defineConfig({\n * plugins: [\n * cerPlugin({\n * content: ['./src/**\\/*.{ts,html}'],\n * ssr: { dsd: true, jit: { extendedColors: true } },\n * }),\n * ],\n * });\n * ```\n */\nexport function cerPlugin(options: CerPluginOptions): Plugin[] {\n const plugins: Plugin[] = [];\n\n // JIT CSS plugin — only added when a `content` glob is provided\n if (options.content && options.content.length > 0) {\n plugins.push(\n cerJITCSS({\n content: options.content,\n output: options.output,\n virtualModule: options.virtualModule,\n extendedColors: options.extendedColors,\n customColors: options.customColors,\n disableVariants: options.disableVariants,\n }),\n );\n }\n\n // SSR config virtual module — registered whenever `ssr` is provided\n if (options.ssr) {\n const ssrConfig = options.ssr;\n const resolvedConfig = {\n dsd: ssrConfig.dsd ?? true,\n dsdPolyfill: ssrConfig.dsdPolyfill ?? true,\n ...(ssrConfig.jit ? { jit: ssrConfig.jit } : {}),\n };\n\n plugins.push({\n name: 'cer-ssr-config',\n resolveId(id: string) {\n if (id === VIRTUAL_SSR_ID) return RESOLVED_VIRTUAL_SSR_ID;\n return undefined;\n },\n load(id: string) {\n if (id === RESOLVED_VIRTUAL_SSR_ID) {\n return `export default ${JSON.stringify(resolvedConfig)};`;\n }\n return undefined;\n },\n });\n }\n\n return plugins;\n}\n\n// ---------------------------------------------------------------------------\n// cerJITCSS — build-time JIT CSS plugin\n// ---------------------------------------------------------------------------\n\n/**\n * Vite plugin that performs a build-time scan of source files and emits\n * pre-generated JIT CSS as a file and/or `virtual:cer-jit-css` module.\n */\nexport function cerJITCSS(options: CerJITCSSPluginOptions): Plugin {\n const {\n content,\n output,\n virtualModule = true,\n extendedColors,\n customColors,\n disableVariants,\n } = options;\n\n const jitOptions: JITCSSOptions = {\n extendedColors,\n customColors,\n disableVariants,\n };\n\n let generatedCSS = '';\n // Resolved file set built in buildStart and reused in handleHotUpdate to\n // avoid re-running globSync for every HMR file-change event.\n let watchedFiles: Set<string> | null = null;\n\n return {\n name: 'cer-jit-css',\n\n buildStart() {\n const cwd = process.cwd();\n const resolved = new Set<string>();\n for (const pattern of content) {\n globSync(pattern, { cwd }).forEach((f) => resolved.add(resolve(cwd, f)));\n }\n watchedFiles = resolved;\n\n generatedCSS = generateFromFiles(content, jitOptions);\n\n if (output) {\n const outputPath = resolve(process.cwd(), output);\n mkdirSync(dirname(outputPath), { recursive: true });\n writeFileSync(outputPath, generatedCSS, 'utf-8');\n }\n },\n\n resolveId(id: string) {\n if (virtualModule && id === VIRTUAL_ID) {\n return RESOLVED_VIRTUAL_ID;\n }\n return undefined;\n },\n\n load(id: string) {\n if (id === RESOLVED_VIRTUAL_ID) {\n return `export default ${JSON.stringify(generatedCSS)};`;\n }\n return undefined;\n },\n\n handleHotUpdate({ file, server }: { file: string; server: unknown }) {\n // Re-generate when a watched source file changes.\n // Use the cached file set from buildStart to avoid re-globbing.\n const isWatched = watchedFiles?.has(file) ?? false;\n\n if (!isWatched) return;\n\n generatedCSS = generateFromFiles(content, jitOptions);\n\n if (output) {\n const outputPath = resolve(process.cwd(), output);\n writeFileSync(outputPath, generatedCSS, 'utf-8');\n }\n\n if (virtualModule) {\n // Invalidate the virtual module so HMR triggers a reload\n const viteServer = server as {\n moduleGraph: { getModuleById: (id: string) => unknown };\n reloadModule: (mod: unknown) => void;\n };\n const mod = viteServer.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);\n if (mod) viteServer.reloadModule(mod);\n }\n },\n };\n}\n"],"names":["VIRTUAL_ID","RESOLVED_VIRTUAL_ID","generateFromFiles","contentPatterns","jitOptions","enableJITCSS","cwd","files","pattern","matches","globSync","f","resolve","uniqueFiles","allClasses","file","content","readFileSync","classes","extractClassesFromHTML","cls","fakeHTML","jitCSS","VIRTUAL_SSR_ID","RESOLVED_VIRTUAL_SSR_ID","cerPlugin","options","plugins","cerJITCSS","ssrConfig","resolvedConfig","id","output","virtualModule","extendedColors","customColors","disableVariants","generatedCSS","watchedFiles","resolved","outputPath","mkdirSync","dirname","writeFileSync","server","viteServer","mod"],"mappings":"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"}
@@ -0,0 +1,6 @@
1
+ "use strict";const p=require("./logger-CSALKaYm.cjs"),j=require("./css-utils-RqkyBWft.cjs");function Z(){const r=(()=>{try{return globalThis.process?.env?.NODE_ENV}catch{return}})(),e=(()=>{try{if(typeof window>"u")return{vitest:!1,cypress:!1};const t=window;return{vitest:!!t.__vitest__,cypress:!!t.Cypress}}catch{return{vitest:!1,cypress:!1}}})();return{isTest:r==="test"||e.vitest||e.cypress,isVitest:e.vitest,isCypress:e.cypress}}class B{pendingUpdates=new Map;isFlushScheduled=!1;isFlushing=!1;testEnv;lastCleanup=0;CLEANUP_INTERVAL=300*1e3;MAX_PENDING_SIZE=1e4;pendingIdleUpdates=new Map;idleCallbackHandle=null;constructor(){this.testEnv=Z(),this.schedulePeriodicCleanup()}schedule(e,n){const t=n||e;this.pendingUpdates.size>=this.MAX_PENDING_SIZE&&this.performEmergencyCleanup(),this.pendingUpdates.set(t,e),this.isFlushScheduled||this.scheduleFlush()}scheduleFlush(){this.isFlushScheduled=!0,this.testEnv.isTest&&!this.isFlushing?this.flush():queueMicrotask(()=>this.flush())}flush(){if(this.isFlushing)return;this.isFlushing=!0;const e=this.pendingUpdates;this.pendingUpdates=new Map,this.isFlushScheduled=!1;try{for(const n of e.values())try{n()}catch(t){p.devError("Error in batched update:",t)}}finally{this.isFlushing=!1}}flushImmediately(){this.pendingUpdates.size!==0&&(this.isFlushScheduled=!1,this.flush())}get pendingCount(){return this.pendingUpdates.size}get hasPendingUpdates(){return this.pendingUpdates.size>0}get isFlushingUpdates(){return this.isFlushing}schedulePeriodicCleanup(){if(this.testEnv.isTest)return;const e=()=>{this.performPeriodicCleanup(),this.testEnv.isTest||setTimeout(e,this.CLEANUP_INTERVAL)};setTimeout(e,this.CLEANUP_INTERVAL)}performPeriodicCleanup(){const e=Date.now();e-this.lastCleanup<this.CLEANUP_INTERVAL||(this.pendingUpdates.size>100&&p.devWarn(`Scheduler has ${this.pendingUpdates.size} pending updates. Consider investigating.`),this.lastCleanup=e)}performEmergencyCleanup(e=this.pendingUpdates){p.devWarn("Scheduler emergency cleanup: too many pending updates, clearing oldest entries");const n=Array.from(e.entries()),t=Math.floor(n.length/2);for(let s=0;s<t;s++)e.delete(n[s][0])}scheduleWithPriority(e,n="normal",t){if(n==="immediate"){try{e()}catch(o){p.devError("Error in immediate update:",o)}return}if(n==="idle"){const o=t??e;this.pendingIdleUpdates.size>=this.MAX_PENDING_SIZE&&this.performEmergencyCleanup(this.pendingIdleUpdates),this.pendingIdleUpdates.set(o,e),this.scheduleIdleFlush();return}const s=t??e;this.pendingUpdates.size>=this.MAX_PENDING_SIZE&&this.performEmergencyCleanup(),this.pendingUpdates.set(s,e),this.isFlushScheduled||(this.isFlushScheduled=!0,queueMicrotask(()=>this.flush()))}scheduleIdleFlush(){if(this.idleCallbackHandle===null){if(this.testEnv.isTest){this.idleCallbackHandle=setTimeout(()=>{this.idleCallbackHandle=null,this.flushIdleUpdates(null)},0);return}if(typeof requestIdleCallback<"u"){const e=requestIdleCallback(n=>{this.idleCallbackHandle=null,this.flushIdleUpdates(n)},{timeout:2e3});this.idleCallbackHandle=e}else this.idleCallbackHandle=setTimeout(()=>{this.idleCallbackHandle=null;const e=Date.now();this.flushIdleUpdates({timeRemaining:()=>Math.max(0,50-(Date.now()-e)),didTimeout:!1})},5)}}flushIdleUpdates(e){const n=Array.from(this.pendingIdleUpdates.entries());this.pendingIdleUpdates=new Map;for(let t=0;t<n.length;t++){if(e&&!e.didTimeout&&e.timeRemaining()<=0){for(let s=t;s<n.length;s++)this.pendingIdleUpdates.set(n[s][0],n[s][1]);this.scheduleIdleFlush();return}try{n[t][1]()}catch(s){p.devError("Error in idle update:",s)}}}}const E=new B;function z(r,e){E.schedule(r,e)}function Y(r,e="normal",n){E.scheduleWithPriority(r,e,n)}function J(){E.flushImmediately()}function Q(){return new Promise(r=>{let n=0;for(;E.hasPendingUpdates&&n<100;)E.flushImmediately(),n++;n>=100&&p.devWarn("[nextTick] Maximum flush iterations reached — possible circular update loop. Check for watchers or computed values that unconditionally mutate reactive state."),queueMicrotask(r)})}const U=new WeakSet;class ee{static cache=new WeakMap;static arrayHandlerCache=new WeakMap;static objectHandlerCache=new WeakMap;static getOrCreateProxy(e,n,t=!1){const s=this.cache.get(e);if(s)return s;const o=t?this.getOrCreateArrayHandler(n):this.getOrCreateObjectHandler(n),i=new Proxy(e,o);try{G.markAsProxy(i)}catch{}return this.cache.set(e,i),i}static getOrCreateArrayHandler(e){if(!this.arrayHandlerCache.has(e)){const n={get:(t,s,o)=>{const i=Reflect.get(t,s,o);return typeof i=="function"&&typeof s=="string"&&["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].includes(s)?function(...u){const c=i.apply(t,u);return e.triggerUpdate(),c}:i!==null&&typeof i=="object"&&typeof s=="string"?e.makeReactiveValue(i):i},set:(t,s,o)=>(t[s]=e.makeReactiveValue(o),e.triggerUpdate(),!0),deleteProperty:(t,s)=>(delete t[s],e.triggerUpdate(),!0)};this.arrayHandlerCache.set(e,n)}return this.arrayHandlerCache.get(e)}static getOrCreateObjectHandler(e){if(!this.objectHandlerCache.has(e)){const n={get:(t,s,o)=>{const i=Reflect.get(t,s,o);return i!==null&&typeof i=="object"&&typeof s=="string"?e.makeReactiveValue(i):i},set:(t,s,o)=>(t[s]=e.makeReactiveValue(o),e.triggerUpdate(),!0),deleteProperty:(t,s)=>(delete t[s],e.triggerUpdate(),!0)};this.objectHandlerCache.set(e,n)}return this.objectHandlerCache.get(e)}static hasProxy(e){return this.cache.has(e)}static clear(){this.cache=new WeakMap,this.arrayHandlerCache=new WeakMap,this.objectHandlerCache=new WeakMap}static getStats(){return{hasCachedProxies:this.cache instanceof WeakMap}}}class G{static contextCache=new WeakMap;static createReactiveProxy(e,n,t){try{if(U.has(e))return e}catch{}const s=Array.isArray(e);let o=this.contextCache.get(n);o||(o=new WeakMap,this.contextCache.set(n,o));let i=o.get(t);return i||(i={triggerUpdate:n,makeReactiveValue:t},o.set(t,i)),ee.getOrCreateProxy(e,i,s)}static markAsProxy(e){if(e)try{U.add(e)}catch{}}}let T=!1;function h(){return T}function te(){T&&p.devWarn("[CER] beginDiscoveryRender() called while a discovery render is already active. This usually means a component was registered inside another component's render function. Ensure component() calls are at module top-level."),T=!0}function ne(){T=!1}let re=0;function A(r){return`${r}-${++re}`}class se{currentComponentStack=[];componentData=new Map;stateStorage=new Map;trackingDisabled=!1;setCurrentComponent(e,n){if(this.currentComponentStack.push(e),!this.componentData.has(e))this.componentData.set(e,{dependencies:new Set,renderFn:n,stateIndex:0,lastWarnTime:0,watchers:new Map});else{const t=this.componentData.get(e);if(t.watchers&&t.watchers.size){for(const s of t.watchers.values())try{this.cleanup(s)}catch{}t.watchers.clear()}t.renderFn=n,t.stateIndex=0}}clearCurrentComponent(){this.currentComponentStack.pop()}getCurrentComponentId(){return this.currentComponentStack.length?this.currentComponentStack[this.currentComponentStack.length-1]:null}registerWatcher(e,n){const t=this.componentData.get(e);t&&t.watchers.set(n,n)}disableTracking(){this.trackingDisabled=!0}enableTracking(){this.trackingDisabled=!1}isRenderingComponent(){return this.currentComponentStack.length>0}shouldEmitRenderWarning(){const e=this.currentComponentStack.length?this.currentComponentStack[this.currentComponentStack.length-1]:null;if(!e)return!0;const n=this.componentData.get(e);if(!n)return!0;const t=Date.now();return t-n.lastWarnTime<1e3?!1:(n.lastWarnTime=t,!0)}withoutTracking(e){const n=this.trackingDisabled;this.trackingDisabled=!0;try{return e()}finally{this.trackingDisabled=n}}getOrCreateState(e){const n=this.currentComponentStack.length?this.currentComponentStack[this.currentComponentStack.length-1]:null;if(!n)return new D(e);const t=this.componentData.get(n);if(!t)return new D(e);const s=`${n}:${t.stateIndex++}`;let o=this.stateStorage.get(s);return o||(o=new D(e),this.stateStorage.set(s,o)),o}trackDependency(e){if(this.trackingDisabled)return;const n=this.currentComponentStack.length?this.currentComponentStack[this.currentComponentStack.length-1]:null;if(!n)return;const t=this.componentData.get(n);t&&(t.dependencies.add(e),e.addDependent(n))}propagateDependencies(e){if(this.trackingDisabled)return;const n=this.currentComponentStack.length?this.currentComponentStack[this.currentComponentStack.length-1]:null;if(!n||n===e)return;const t=this.componentData.get(e);if(!t)return;const s=this.componentData.get(n);if(s)for(const o of t.dependencies)s.dependencies.add(o),o.addDependent(n)}triggerUpdate(e){const n=e.getDependents();for(const t of n){const s=this.componentData.get(t);s&&z(s.renderFn,t)}}cleanup(e){const n=this.componentData.get(e);if(n){for(const s of n.dependencies)s.removeDependent(e);this.componentData.delete(e)}const t=e+":";for(const s of this.stateStorage.keys())s.startsWith(t)&&this.stateStorage.delete(s)}}const d=new se;class D{_value;_rawValue;dependents=new Set;constructor(e){this._rawValue=e,this._value=this.makeReactive(e);try{Object.defineProperty(this,Symbol.for("@cer/ReactiveState"),{value:!0,enumerable:!1,configurable:!1})}catch{}}get value(){return d.trackDependency(this),this._value}set value(e){Object.is(e,this._rawValue)||(d.isRenderingComponent()&&d.shouldEmitRenderWarning()&&p.devWarn(`🚨 State modification detected during render! This can cause infinite loops.
2
+ • Move state updates to event handlers
3
+ • Use watchEffect/watch for side effects
4
+ • Ensure computed properties don't modify state`),this._rawValue=e,this._value=this.makeReactive(e),d.triggerUpdate(this))}peek(){return this._value}initSilent(e){this._rawValue=e,this._value=e}addDependent(e){this.dependents.add(e)}removeDependent(e){this.dependents.delete(e)}getDependents(){return this.dependents}makeReactive(e){return e===null||typeof e!="object"||e instanceof Node||e instanceof Element||e instanceof HTMLElement?e:G.createReactiveProxy(e,()=>d.triggerUpdate(this),n=>this.makeReactive(n))}}function oe(r){return d.getOrCreateState(r===void 0?null:r)}function C(r){if(!r||typeof r!="object")return!1;try{const e=Symbol.for("@cer/ReactiveState");return Object.prototype.hasOwnProperty.call(r,e)}catch{return!1}}function ie(r){let e,n=!0;const t=A("computed"),s=()=>{n=!0};try{const o=d.getCurrentComponentId();o&&d.registerWatcher(o,t)}catch{}return d.setCurrentComponent(t,s),e=r(),d.clearCurrentComponent(),n=!1,{get value(){return n&&(d.setCurrentComponent(t,s),e=r(),d.clearCurrentComponent(),n=!1),d.propagateDependencies(t),e}}}function ae(r){if(h())return()=>{};const e=A("effect");try{const t=d.getCurrentComponentId();t&&d.registerWatcher(t,e)}catch{}const n=()=>{d.setCurrentComponent(e,n);try{r()}finally{d.clearCurrentComponent()}};return n(),()=>{d.cleanup(e)}}const L=50;function R(r,e=new WeakMap,n=0){if(r===null||typeof r!="object")return r;const t=r;if(e.has(t))return e.get(t);if(n>L)return p.devWarn(`[watch] Deep clone exceeded ${L} nesting levels. Returning a reference at this depth instead of cloning further. Consider restructuring your state or switching to a shallow watch.`),r;if(typeof Node<"u"&&t instanceof Node)return r;if(t instanceof Date)return new Date(t.getTime());if(Array.isArray(t)){const o=[];e.set(t,o);for(let i=0;i<t.length;i++)o.push(R(t[i],e,n+1));return o}const s={};e.set(t,s);for(const o of Object.keys(t))try{s[o]=R(t[o],e,n+1)}catch{}return s}function ce(r,e,n){if(h())return()=>{};let t;const s=C(r)?()=>r.value:r,o=A("watch");try{const a=d.getCurrentComponentId();a&&d.registerWatcher(a,o)}catch{}const i=()=>{d.setCurrentComponent(o,i);const a=s();if(d.clearCurrentComponent(),n?.deep){const u=d.withoutTracking(()=>R(a));e(u,t),t=u}else a!==t&&(e(a,t),t=a)};return d.setCurrentComponent(o,i),t=s(),d.clearCurrentComponent(),n?.deep&&(t=d.withoutTracking(()=>R(t))),n&&n.immediate&&e(t,void 0),()=>{d.cleanup(o)}}const ue=r=>{try{r()}catch{}},v=new Map,_=new Map,M=new Map,O=500;let k,q,W=!1,F=!1,$;const le=!!globalThis.process?.versions?.node;function K(r){if(v.has(r))return v.get(r);const e=r.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();return v.size<O&&v.set(r,e),e}function x(r){if(_.has(r))return _.get(r);const e=r.replace(/-([a-z])/g,(n,t)=>t.toUpperCase());return _.size<O&&_.set(r,e),e}function de(r){if(typeof r=="string"){if(M.has(r))return M.get(r);const e=r.replace(/[&<>"']/g,n=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[n]);return e!==r&&M.size<O&&M.set(r,e),e}return r}function y(r){if(!r)return"";const e=String(r);if(typeof document<"u"&&typeof document.createElement=="function"){const a=e.replace(/</g,"").replace(/>/g,""),u=$||($=document.createElement("div"));try{y._el=u}catch{}return u.innerHTML=a,(u.textContent||"").replace(new RegExp("","g"),"<").replace(new RegExp("","g"),">")}const n={lt:"<",gt:">",amp:"&",quot:'"',apos:"'",nbsp:" "},t=k??y._namedMap;let s=t;if(!s&&le)try{const o=globalThis.require;if(typeof o=="function"){const i=["@jasonshimmy/custom-elements-runtime/entities.json","../../entities.json","../../../entities.json","../entities.json","./entities.json"];for(const a of i)try{const u=o(a);if(u&&typeof u=="object"){s=u;break}}catch{}}}catch{}if(!s){s=n,W=!0;try{y._usedFallback=!0}catch{}const o=y._namedMapLoader??q;o&&o().then(i=>{k=i;try{y._namedMap=i}catch{}}).catch(()=>{})}if((W||y._usedFallback)&&!(F||y._warnedFallback)){F=!0;try{y._warnedFallback=!0}catch{}try{p.devWarn("decodeEntities: using small SSR fallback entity map. Register the full entities.json via registerEntityMap(entities) on the server to enable full HTML5 named-entity decoding.")}catch{}}return e.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g,(o,i)=>{if(i.charCodeAt(0)===35){const c=(i.charAt(1)||"").toLowerCase()==="x"?parseInt(i.slice(2),16):parseInt(i.slice(1),10);return Number.isNaN(c)?`&${i};`:String.fromCodePoint(c)}const a=s[i]??(t&&t[i]);return a!==void 0?a:`&${i};`})}async function P(){const r=["@jasonshimmy","custom-elements-runtime","entities.json"].join("/");try{const e=await import(r);return e&&(e.default||e)}catch{try{const e=[r,"./entities.json","../../entities.json","../../../entities.json"];for(const n of e)try{const t=await import(n);if(t)return t&&(t.default||t)}catch{}return{lt:"<",gt:">",amp:"&",quot:'"',apos:"'",nbsp:" "}}catch{return{lt:"<",gt:">",amp:"&",quot:'"',apos:"'",nbsp:" "}}}}q=P;y._namedMapLoader=P;function fe(r,e){!r||typeof r!="object"||k&&!e?.overwrite||(k=r)}function he(){k=void 0}function pe(r){const e=String(r);return{__unsafeHTML:e,__rawHTML:e}}function ge(r){return!!r&&(typeof r.__unsafeHTML=="string"||typeof r.__rawHTML=="string")}function me(r,e){if(typeof e=="string"){if(e==="")return;const n=e.split(".");let t=r;for(const s of n){if(t==null||typeof t!="object"){t=void 0;break}t=t[s]}return C(t)?t.value:t}return e}function ye(r,e,n){const t=String(e).split("."),s=t.pop();if(!s)return;const o=t.reduce((i,a)=>(i[a]==null&&(i[a]={}),i[a]),r);C(o[s])?o[s].value=n:o[s]=n}function Ce(r){try{if(r&&typeof r=="object"){if(C(r))return r.value;if("value"in r){const e=r.value;return e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"?e:r}}}catch{}return r}function be(r){const e=Ce(r);if(e==null)return null;const n=typeof e;return n==="string"||n==="number"||n==="boolean"?String(e):null}function we(r){if(!r||typeof r!="string")return!1;if(r==="class"||r.endsWith("Class"))return!0;if(r.includes("-"))try{if(r.split("-").some(n=>n==="class"))return!0}catch{}return!1}let w=null;function Se(){w=[]}function Ee(){const r=w??[];return w=null,r}function ke(r){return w!==null?(r&&!w.includes(r)&&w.push(r),!0):!1}function ve(r,e,n="unknown"){const t={};for(const[u,c]of Object.entries(e??{}))t[x(u)]=c;const s={getAttribute(u){const c=x(u);if(t[c]!==void 0&&t[c]!==null)return String(t[c]);const m=(e??{})[u];return m!=null?String(m):null},hasAttribute(u){return this.getAttribute(u)!==null},shadowRoot:null,tagName:"",parentElement:null},o={...t,_componentId:`cer-ssr-${Object.keys(t).join("-")||"root"}`,requestRender:()=>{},_requestRender:()=>{},emit:()=>!0,refs:{}};Object.defineProperty(o,"_host",{value:s,writable:!0,enumerable:!1,configurable:!0}),N(o);let i=null;try{const u=r.render(o);u instanceof Promise?p.devWarn(`[SSR] Component "${n}" has an async render function. Async renders are not supported in the synchronous SSR pass — the shadow DOM will be empty and hydrated on the client instead.`):i=u}catch(u){p.devWarn(`[SSR] Component "${n}" threw during SSR render. The shadow DOM will be empty. Error:`,u)}finally{H()}const a=String(o._computedStyle??"");return{shadowVNode:i,useStyleCSS:a}}function _e(){return h()}let l=null;const S=Symbol("cer:provides");function N(r){l=r}function H(){l=null}function Me(){return l}function De(){if(!l)throw new Error("useEmit must be called during component render");if(h())return()=>!1;const r=l.emit;if(typeof r!="function")throw new Error("useEmit requires an emit function on the component context");const e=r;return(n,t,s)=>e(n,t,s)}function b(r){r._hookCallbacks||Object.defineProperty(r,"_hookCallbacks",{value:{},writable:!0,enumerable:!1,configurable:!0})}function Te(r){if(!l)throw new Error("useOnConnected must be called during component render");if(h())return;b(l);const e=l._hookCallbacks;e.onConnected||(e.onConnected=[]),e.onConnected.push(r)}function Re(r){if(!l)throw new Error("useOnDisconnected must be called during component render");if(h())return;b(l);const e=l._hookCallbacks;e.onDisconnected||(e.onDisconnected=[]),e.onDisconnected.push(r)}function Ne(r){if(!l)throw new Error("useOnAttributeChanged must be called during component render");if(h())return;b(l);const e=l._hookCallbacks;e.onAttributeChanged||(e.onAttributeChanged=[]),e.onAttributeChanged.push(r)}function xe(r){if(!l)throw new Error("useOnError must be called during component render");if(h())return;b(l);const e=l._hookCallbacks;e.onError||(e.onError=[]),e.onError.push(n=>{try{n instanceof Error?r(n):r(new Error(String(n)))}catch(t){p.devError("[useOnError] The error handler itself threw an exception:",t)}})}function X(r){if(!l)throw new Error("useProps must be called during component render");b(l);const e=l._hookCallbacks;e.props={...e.props||{},...r};const n=l;try{const s=Object.keys(r||{});for(const o of s){if(typeof o!="string"||o.startsWith("_"))continue;const i=Object.getOwnPropertyDescriptor(n,o);if(!(i&&!i.configurable))try{let u=Object.prototype.hasOwnProperty.call(n,o)?n[o]:void 0;Object.defineProperty(n,o,{configurable:!0,enumerable:!0,get(){try{const c=n&&n._host;if(c){const m=K(o),g=c.getAttribute(m);if(g!==null){const f=typeof r[o];return f==="boolean"?g===""||g==="true":f==="number"?Number(g):g}if(typeof c[o]<"u"){const f=c[o];if(C(f)||f&&typeof f=="object"&&"value"in f&&!(f instanceof Node))return f.value;const I=typeof r[o];if(!(I==="string"&&f&&typeof f=="object"))return I==="boolean"&&typeof f=="string"?f===""||f==="true":f}}}catch{}return u},set(c){u=c}})}catch{}}}catch{}return new Proxy({},{get(s,o){if(typeof o!="string")return;const i=r[o];try{const u=n&&n._host;if(u){if(u instanceof HTMLElement||typeof u.getAttribute=="function"&&typeof u.hasAttribute=="function"){const m=o.replace(/([A-Z])/g,"-$1").toLowerCase(),g=u.getAttribute(m);if(g!==null)return typeof i=="boolean"?g===""||g==="true":typeof i=="number"?Number(g):g}const c=u[o];if(typeof c<"u"&&c!==""){const m=c&&typeof c=="object"&&"value"in c&&!(c instanceof Node);if(!(typeof i=="string"&&c&&typeof c=="object"&&!m&&!C(c)))return typeof i=="boolean"&&i===!1&&c===""?i:C(c)||m?c.value:typeof i=="boolean"&&typeof c=="string"?c===""||c==="true":typeof i=="number"&&typeof c=="string"&&!Number.isNaN(Number(c))?Number(c):c}}}catch{}const a=n[o];return typeof i=="boolean"&&a===""?i===!1?i:!0:C(a)||a&&typeof a=="object"&&"value"in a&&!(a instanceof Node)?a.value:a!=null&&a!==""?typeof i=="boolean"&&typeof a=="string"?a==="true":typeof i=="number"&&typeof a=="string"&&!Number.isNaN(Number(a))?Number(a):a:i},has(s,o){return typeof o=="string"&&(o in n||o in r)},ownKeys(){return Array.from(new Set([...Object.keys(r),...Object.keys(n||{})]))},getOwnPropertyDescriptor(){return{configurable:!0,enumerable:!0}}})}function Ae(r){if(!l)throw new Error("useStyle must be called during component render");if(!h()){b(l);try{const e=r();Object.defineProperty(l,"_computedStyle",{value:e,writable:!0,enumerable:!1,configurable:!0})}catch(e){p.devWarn("Error in useStyle callback:",e),Object.defineProperty(l,"_computedStyle",{value:"",writable:!0,enumerable:!1,configurable:!0})}}}const V=new Map;function Oe(r){let e;try{e=r()}catch{return}if(ke(e)||typeof document>"u"||typeof CSSStyleSheet>"u")return;p.devWarn("[useGlobalStyle] Injecting global styles from a component. This escapes Shadow DOM encapsulation — use sparingly.");const n=j.minifyCSS(j.sanitizeCSS(e));if(!(!n||V.has(n)))try{const t=new CSSStyleSheet;t.replaceSync(n),document.adoptedStyleSheets=[...document.adoptedStyleSheets,t],V.set(n,t)}catch{const t=document.createElement("style");t.textContent=n,(document.head??document.documentElement).appendChild(t)}}function Pe(r){if(!l)throw new Error("useDesignTokens must be called during component render");if(h())return;const e=[],n={primary:"--cer-color-primary-500",secondary:"--cer-color-secondary-500",neutral:"--cer-color-neutral-500",success:"--cer-color-success-500",info:"--cer-color-info-500",warning:"--cer-color-warning-500",error:"--cer-color-error-500"},t={fontSans:"--cer-font-sans",fontSerif:"--cer-font-serif",fontMono:"--cer-font-mono"};for(const[u,c]of Object.entries(r))c!==void 0&&(u in n?e.push(`${n[u]}:${c}`):u in t?e.push(`${t[u]}:${c}`):u.startsWith("--")&&e.push(`${u}:${c}`));if(e.length===0)return;const s=`:host{${e.join(";")}}`,i=l._computedStyle??"",a=i?`${i}
5
+ ${s}`:s;Object.defineProperty(l,"_computedStyle",{value:a,writable:!0,enumerable:!1,configurable:!0})}function He(r,e){if(!l)throw new Error("provide must be called during component render");if(h())return;const n=l;n[S]||Object.defineProperty(n,S,{value:new Map,writable:!1,enumerable:!1,configurable:!0}),n[S].set(r,e)}function Ie(r,e){if(!l)throw new Error("inject must be called during component render");if(h())return e;try{const n=l._host;if(n){let t=n.parentNode;t||(t=n.getRootNode());let s=0;const o=50;for(;t&&s<o;)if(s++,t instanceof ShadowRoot){const i=t.host,a=i.context;if(a){const c=a[S];if(c?.has(r))return c.get(r)}if(t=i.parentNode??i.getRootNode(),t===document||t===i)break}else{if(t instanceof Element){const u=t.context;if(u){const c=u[S];if(c?.has(r))return c.get(r)}}const i=t;if(t=t.parentNode??t.getRootNode?.(),t===document||t===i)break}}}catch{}return e}function je(r){return e=>{const n=e??l;if(!n)throw new Error("createComposable: no component context available. Pass a context explicitly or call inside a render function.");const t=l;N(n);try{return r()}finally{t?N(t):H()}}}function Ue(r){if(!l)throw new Error("useExpose must be called during component render");if(h())return;b(l);const e=l._hookCallbacks;e.expose={...e.expose??{},...r};const n=l._host;if(n)for(const[t,s]of Object.entries(r))try{n[t]=s}catch{}}function Le(){if(!l)throw new Error("useSlots must be called during component render");if(h())return{has:()=>!1,getNodes:()=>[],names:()=>[]};const r=l._host,e=()=>{const n=new Map;if(!r)return n;for(const t of r.children){const s=t.getAttribute("slot")??"default",o=n.get(s);o?o.push(t):n.set(s,[t])}return n};return{has(n){if(!r)return!1;const t=!n||n==="default"?"default":n,s=e().get(t);return s!==void 0&&s.length>0},getNodes(n){if(!r)return[];const t=!n||n==="default"?"default":n;return e().get(t)??[]},names(){return r?Array.from(e().keys()):[]}}}function We(...r){if(!l)throw new Error("defineModel must be called during component render");const e=r.length===2?r[0]:"modelValue",n=r.length===2?r[1]:r.length===1?r[0]:void 0,t=X({[e]:n}),o=h()?null:(()=>{const a=l.emit;return typeof a!="function"?null:a})(),i={get value(){return t[e]},set value(a){o&&o(`update:${e}`,a)}};try{Object.defineProperty(i,Symbol.for("@cer/ReactiveState"),{value:!0,enumerable:!1,configurable:!1})}catch{}return i}exports.ReactiveState=D;exports.beginDiscoveryRender=te;exports.beginSSRGlobalStyleCollection=Se;exports.clearCurrentComponentContext=H;exports.clearRegisteredEntityMap=he;exports.computed=ie;exports.createComposable=je;exports.decodeEntities=y;exports.defineModel=We;exports.endDiscoveryRender=ne;exports.endSSRGlobalStyleCollection=Ee;exports.escapeHTML=de;exports.flushDOMUpdates=J;exports.getCurrentComponentContext=Me;exports.getNestedValue=me;exports.inject=Ie;exports.isClassLikeAttr=we;exports.isDiscoveryRender=_e;exports.isDiscoveryRender$1=h;exports.isReactiveState=C;exports.isUnsafeHTML=ge;exports.loadEntityMap=P;exports.nextTick=Q;exports.provide=He;exports.reactiveSystem=d;exports.ref=oe;exports.registerEntityMap=fe;exports.runComponentSSRRender=ve;exports.safe=ue;exports.safeSerializeAttr=be;exports.scheduleDOMUpdate=z;exports.scheduleWithPriority=Y;exports.setCurrentComponentContext=N;exports.setNestedValue=ye;exports.toCamel=x;exports.toKebab=K;exports.unsafeHTML=pe;exports.useDesignTokens=Pe;exports.useEmit=De;exports.useExpose=Ue;exports.useGlobalStyle=Oe;exports.useOnAttributeChanged=Ne;exports.useOnConnected=Te;exports.useOnDisconnected=Re;exports.useOnError=xe;exports.useProps=X;exports.useSlots=Le;exports.useStyle=Ae;exports.watch=ce;exports.watchEffect=ae;
6
+ //# sourceMappingURL=hooks-B50HhrHh.cjs.map