@jasonshimmy/custom-elements-runtime 3.4.0 → 3.5.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 (105) hide show
  1. package/README.md +28 -7
  2. package/dist/css-utils-Bn-dO44e.js +203 -0
  3. package/dist/{css-utils-CC43BbEy.js.map → css-utils-Bn-dO44e.js.map} +1 -1
  4. package/dist/{css-utils-CC43BbEy.js → css-utils-CFeP8SK1.cjs} +5 -71
  5. package/dist/{css-utils-mgjmH8qX.cjs.map → css-utils-CFeP8SK1.cjs.map} +1 -1
  6. package/dist/custom-elements-runtime.cjs.js +3 -4
  7. package/dist/custom-elements-runtime.cjs.js.map +1 -1
  8. package/dist/custom-elements-runtime.colors.cjs.js +1 -2
  9. package/dist/custom-elements-runtime.colors.cjs.js.map +1 -1
  10. package/dist/custom-elements-runtime.colors.es.js +277 -277
  11. package/dist/custom-elements-runtime.colors.es.js.map +1 -1
  12. package/dist/custom-elements-runtime.directive-enhancements.cjs.js +1 -2
  13. package/dist/custom-elements-runtime.directive-enhancements.cjs.js.map +1 -1
  14. package/dist/custom-elements-runtime.directive-enhancements.es.js +106 -122
  15. package/dist/custom-elements-runtime.directive-enhancements.es.js.map +1 -1
  16. package/dist/custom-elements-runtime.directives.cjs.js +1 -2
  17. package/dist/custom-elements-runtime.directives.cjs.js.map +1 -1
  18. package/dist/custom-elements-runtime.directives.es.js +60 -65
  19. package/dist/custom-elements-runtime.directives.es.js.map +1 -1
  20. package/dist/custom-elements-runtime.dom-jit-css.cjs.js +1 -7
  21. package/dist/custom-elements-runtime.dom-jit-css.cjs.js.map +1 -1
  22. package/dist/custom-elements-runtime.dom-jit-css.es.js +103 -115
  23. package/dist/custom-elements-runtime.dom-jit-css.es.js.map +1 -1
  24. package/dist/custom-elements-runtime.es.js +206 -253
  25. package/dist/custom-elements-runtime.es.js.map +1 -1
  26. package/dist/custom-elements-runtime.event-bus.cjs.js +1 -2
  27. package/dist/custom-elements-runtime.event-bus.cjs.js.map +1 -1
  28. package/dist/custom-elements-runtime.event-bus.es.js +102 -108
  29. package/dist/custom-elements-runtime.event-bus.es.js.map +1 -1
  30. package/dist/custom-elements-runtime.jit-css.cjs.js +1 -2
  31. package/dist/custom-elements-runtime.jit-css.cjs.js.map +1 -1
  32. package/dist/custom-elements-runtime.jit-css.es.js +14 -32
  33. package/dist/custom-elements-runtime.jit-css.es.js.map +1 -1
  34. package/dist/custom-elements-runtime.router.cjs.js +20 -21
  35. package/dist/custom-elements-runtime.router.cjs.js.map +1 -1
  36. package/dist/custom-elements-runtime.router.es.js +866 -926
  37. package/dist/custom-elements-runtime.router.es.js.map +1 -1
  38. package/dist/custom-elements-runtime.ssr-middleware.cjs.js +3 -4
  39. package/dist/custom-elements-runtime.ssr-middleware.cjs.js.map +1 -1
  40. package/dist/custom-elements-runtime.ssr-middleware.es.js +67 -73
  41. package/dist/custom-elements-runtime.ssr-middleware.es.js.map +1 -1
  42. package/dist/custom-elements-runtime.ssr.cjs.js +1 -1
  43. package/dist/custom-elements-runtime.ssr.es.js +3 -14
  44. package/dist/custom-elements-runtime.store.cjs.js +1 -2
  45. package/dist/custom-elements-runtime.store.cjs.js.map +1 -1
  46. package/dist/custom-elements-runtime.store.es.js +32 -33
  47. package/dist/custom-elements-runtime.store.es.js.map +1 -1
  48. package/dist/custom-elements-runtime.transitions.cjs.js +1 -2
  49. package/dist/custom-elements-runtime.transitions.cjs.js.map +1 -1
  50. package/dist/custom-elements-runtime.transitions.es.js +200 -210
  51. package/dist/custom-elements-runtime.transitions.es.js.map +1 -1
  52. package/dist/custom-elements-runtime.vite-plugin.cjs.js +4 -2
  53. package/dist/custom-elements-runtime.vite-plugin.cjs.js.map +1 -1
  54. package/dist/custom-elements-runtime.vite-plugin.es.js +155 -78
  55. package/dist/custom-elements-runtime.vite-plugin.es.js.map +1 -1
  56. package/dist/helpers-DcEpRwq5.cjs +5 -0
  57. package/dist/helpers-DcEpRwq5.cjs.map +1 -0
  58. package/dist/helpers-tJgb4Qve.js +693 -0
  59. package/dist/helpers-tJgb4Qve.js.map +1 -0
  60. package/dist/hooks-CEUnvtsA.js +407 -0
  61. package/dist/hooks-CEUnvtsA.js.map +1 -0
  62. package/dist/hooks-CNfugc95.cjs +2 -0
  63. package/dist/hooks-CNfugc95.cjs.map +1 -0
  64. package/dist/logger-DIJ0UH3R.js +36 -0
  65. package/dist/{logger-L25axmB-.js.map → logger-DIJ0UH3R.js.map} +1 -1
  66. package/dist/logger-Dkht1dCX.cjs +2 -0
  67. package/dist/{logger-BYIN7ysT.cjs.map → logger-Dkht1dCX.cjs.map} +1 -1
  68. package/dist/namespace-helpers-CIUkG8Mn.js +56 -0
  69. package/dist/{namespace-helpers-BucDdgz_.js.map → namespace-helpers-CIUkG8Mn.js.map} +1 -1
  70. package/dist/namespace-helpers-yYIb7INq.cjs +2 -0
  71. package/dist/{namespace-helpers-Bf7rm9JV.cjs.map → namespace-helpers-yYIb7INq.cjs.map} +1 -1
  72. package/dist/runtime/tag-utils.d.ts +11 -0
  73. package/dist/ssr-BpYy9XlW.js +170 -0
  74. package/dist/{ssr-H9GDwbTy.js.map → ssr-BpYy9XlW.js.map} +1 -1
  75. package/dist/ssr-CFabTOyi.cjs +4 -0
  76. package/dist/{ssr-DRsGduIK.cjs.map → ssr-CFabTOyi.cjs.map} +1 -1
  77. package/dist/style-A8l3aQ52.cjs +55 -0
  78. package/dist/{style-Bjn8zDiZ.cjs.map → style-A8l3aQ52.cjs.map} +1 -1
  79. package/dist/style-DSSoCbC9.js +1877 -0
  80. package/dist/{style-DuDoj_xK.js.map → style-DSSoCbC9.js.map} +1 -1
  81. package/dist/tag-utils-CoSXTr1F.js +10 -0
  82. package/dist/tag-utils-CoSXTr1F.js.map +1 -0
  83. package/dist/tag-utils-XJ3dkcPQ.cjs +2 -0
  84. package/dist/tag-utils-XJ3dkcPQ.cjs.map +1 -0
  85. package/dist/template-compiler-B4B_jAPN.cjs +19 -0
  86. package/dist/{template-compiler-BB4JJdqk.cjs.map → template-compiler-B4B_jAPN.cjs.map} +1 -1
  87. package/dist/template-compiler-C3h8_vbE.js +3044 -0
  88. package/dist/{template-compiler-Cs5axmn4.js.map → template-compiler-C3h8_vbE.js.map} +1 -1
  89. package/dist/vite-plugin.d.ts +96 -2
  90. package/package.json +8 -8
  91. package/dist/css-utils-mgjmH8qX.cjs +0 -577
  92. package/dist/hooks-_3xP4G2N.js +0 -1189
  93. package/dist/hooks-_3xP4G2N.js.map +0 -1
  94. package/dist/hooks-fYQgZk2g.cjs +0 -7
  95. package/dist/hooks-fYQgZk2g.cjs.map +0 -1
  96. package/dist/logger-BYIN7ysT.cjs +0 -3
  97. package/dist/logger-L25axmB-.js +0 -41
  98. package/dist/namespace-helpers-Bf7rm9JV.cjs +0 -3
  99. package/dist/namespace-helpers-BucDdgz_.js +0 -61
  100. package/dist/ssr-DRsGduIK.cjs +0 -5
  101. package/dist/ssr-H9GDwbTy.js +0 -172
  102. package/dist/style-Bjn8zDiZ.cjs +0 -56
  103. package/dist/style-DuDoj_xK.js +0 -1972
  104. package/dist/template-compiler-BB4JJdqk.cjs +0 -23
  105. package/dist/template-compiler-Cs5axmn4.js +0 -3236
@@ -1,7 +1,8 @@
1
1
  /**
2
- * Vite plugins for build-time JIT CSS generation and SSR configuration.
2
+ * Vite plugins for build-time JIT CSS generation, SSR configuration, and
3
+ * per-page component code splitting.
3
4
  *
4
- * Two plugins are exported:
5
+ * Three plugins are exported:
5
6
  *
6
7
  * - **`cerJITCSS`** — Scans source files for utility class names and emits
7
8
  * pre-generated CSS, eliminating all runtime parsing cost for projects with
@@ -12,6 +13,18 @@
12
13
  * resolved SSR render options so server entry files can import and use them
13
14
  * without duplication.
14
15
  *
16
+ * - **`cerComponentImports`** — Transform plugin that scans each app file for
17
+ * custom element tags used in `html\`` template literals and injects static
18
+ * `import` statements pointing to the corresponding component source files.
19
+ * This gives Rollup the module graph edges it needs to automatically
20
+ * code-split components per page chunk.
21
+ *
22
+ * Three build-time utilities are also exported:
23
+ *
24
+ * - **`resolveTagName`** — Normalize a component name to its registered tag name.
25
+ * - **`extractTemplateTagNames`** — Extract hyphenated tag names from `html\`` sources.
26
+ * - **`extractComponentRegistrations`** — Extract registered tag names from `component()` calls.
27
+ *
15
28
  * @example cerJITCSS only
16
29
  * ```ts
17
30
  * // vite.config.ts
@@ -55,9 +68,26 @@
55
68
  *
56
69
  * const { htmlWithStyles } = renderToStringWithJITCSS(appVNode, ssrConfig);
57
70
  * ```
71
+ *
72
+ * @example cerComponentImports for per-page code splitting
73
+ * ```ts
74
+ * // vite.config.ts
75
+ * import { defineConfig } from 'vite';
76
+ * import { cerComponentImports } from '@jasonshimmy/custom-elements-runtime/vite-plugin';
77
+ *
78
+ * export default defineConfig({
79
+ * plugins: [
80
+ * cerComponentImports({
81
+ * componentsDir: '/absolute/path/to/app/components',
82
+ * appRoot: '/absolute/path/to/app',
83
+ * }),
84
+ * ],
85
+ * });
86
+ * ```
58
87
  */
59
88
  import type { Plugin } from 'vite';
60
89
  import { type JITCSSOptions } from './runtime/style';
90
+ import { resolveTagName as _resolveTagName } from './runtime/tag-utils';
61
91
  /**
62
92
  * Options for the `cerJITCSS` Vite plugin.
63
93
  */
@@ -140,3 +170,67 @@ export declare function cerPlugin(options: CerPluginOptions): Plugin[];
140
170
  * pre-generated JIT CSS as a file and/or `virtual:cer-jit-css` module.
141
171
  */
142
172
  export declare function cerJITCSS(options: CerJITCSSPluginOptions): Plugin;
173
+ /**
174
+ * Resolves a component() tag argument to the actual registered tag name.
175
+ * Re-exported from runtime/tag-utils so consumers have a single import surface.
176
+ *
177
+ * Rules:
178
+ * camelCase → kebab-case (myButton → my-button)
179
+ * no hyphen → cer- prefix (app → cer-app)
180
+ * has hyphen → unchanged (ks-badge → ks-badge)
181
+ */
182
+ export declare const resolveTagName: typeof _resolveTagName;
183
+ /**
184
+ * Scan TypeScript source text for all custom element tag names referenced
185
+ * in html`` template literals.
186
+ *
187
+ * Strips line (//) and block (/* *\/) comments first to avoid false
188
+ * positives from commented-out code.
189
+ *
190
+ * Returns a Set of already-hyphenated tag names as they appear in the source
191
+ * (e.g. "ks-badge", "cer-app"). Single-word names that would receive a
192
+ * "cer-" prefix at runtime never appear as bare tags in templates — they
193
+ * always appear as "cer-something" — so no normalization is needed here.
194
+ *
195
+ * Closing tags (</ks-badge>) do NOT match because the regex requires the
196
+ * first character after < to be [a-z], not /.
197
+ */
198
+ export declare function extractTemplateTagNames(source: string): Set<string>;
199
+ /**
200
+ * Extract all component tag names registered in a component source file.
201
+ * Handles files that call component() more than once (returns all of them).
202
+ *
203
+ * Uses \bcomponent\( so it matches the standalone function name but not
204
+ * names like importComponent( or registerComponent(.
205
+ *
206
+ * Returns resolved (normalized) tag names, ready to match against the output
207
+ * of extractTemplateTagNames().
208
+ */
209
+ export declare function extractComponentRegistrations(source: string): string[];
210
+ /**
211
+ * Options for the {@link cerComponentImports} Vite plugin.
212
+ */
213
+ export interface CerComponentImportsOptions {
214
+ /**
215
+ * Absolute path to the directory containing component files.
216
+ * Every .ts file found here is scanned for component() registrations.
217
+ */
218
+ componentsDir: string;
219
+ /**
220
+ * Absolute path to the app source root. The transform is restricted to
221
+ * files under this directory so node_modules and generated files are skipped.
222
+ */
223
+ appRoot: string;
224
+ }
225
+ /**
226
+ * Vite plugin that injects static `import` statements for custom element
227
+ * components used in each page/layout/component file.
228
+ *
229
+ * Replaces the eager `virtual:cer-components` side-effect import with
230
+ * per-file static imports, giving Rollup graph edges it needs to
231
+ * automatically code-split components per page chunk.
232
+ *
233
+ * Must be used with `enforce: 'pre'` (already set internally) to ensure
234
+ * the transform sees the original TypeScript source before esbuild runs.
235
+ */
236
+ export declare function cerComponentImports(options: CerComponentImportsOptions): Plugin;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jasonshimmy/custom-elements-runtime",
3
3
  "description": "A powerful, modern, and lightweight runtime for creating reactive web components with TypeScript",
4
- "version": "3.4.0",
4
+ "version": "3.5.0",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "web-components",
@@ -37,19 +37,19 @@
37
37
  "devDependencies": {
38
38
  "@eslint/js": "^10.0.1",
39
39
  "@testing-library/jest-dom": "^6.9.1",
40
- "@types/jsdom": "^28.0.0",
40
+ "@types/jsdom": "^28.0.1",
41
41
  "@typescript-eslint/eslint-plugin": "^8.46.2",
42
42
  "@typescript-eslint/parser": "^8.46.2",
43
- "@vitest/coverage-v8": "^4.1.0",
44
- "cypress": "^15.12.0",
45
- "eslint": "^10.0.3",
43
+ "@vitest/coverage-v8": "^4.1.2",
44
+ "cypress": "^15.13.0",
45
+ "eslint": "^10.1.0",
46
46
  "eslint-config-prettier": "^10.1.8",
47
47
  "eslint-plugin-prettier": "^5.5.5",
48
- "jsdom": "^29.0.0",
48
+ "jsdom": "^29.0.1",
49
49
  "prettier": "^3.8.1",
50
50
  "typescript": "^5.9.3",
51
- "typescript-eslint": "^8.57.1",
52
- "vite": "^8.0.0",
51
+ "typescript-eslint": "^8.57.2",
52
+ "vite": "^8.0.3",
53
53
  "vitest": "^4.0.12"
54
54
  },
55
55
  "main": "dist/custom-elements-runtime.cjs.js",