@czap/vite 0.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 (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/dist/css-quantize.d.ts +53 -0
  4. package/dist/css-quantize.d.ts.map +1 -0
  5. package/dist/css-quantize.js +247 -0
  6. package/dist/css-quantize.js.map +1 -0
  7. package/dist/environments.d.ts +36 -0
  8. package/dist/environments.d.ts.map +1 -0
  9. package/dist/environments.js +67 -0
  10. package/dist/environments.js.map +1 -0
  11. package/dist/hmr.d.ts +37 -0
  12. package/dist/hmr.d.ts.map +1 -0
  13. package/dist/hmr.js +84 -0
  14. package/dist/hmr.js.map +1 -0
  15. package/dist/html-transform.d.ts +19 -0
  16. package/dist/html-transform.d.ts.map +1 -0
  17. package/dist/html-transform.js +54 -0
  18. package/dist/html-transform.js.map +1 -0
  19. package/dist/index.d.ts +51 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +43 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/normalize-css-eol.d.ts +7 -0
  24. package/dist/normalize-css-eol.d.ts.map +1 -0
  25. package/dist/normalize-css-eol.js +9 -0
  26. package/dist/normalize-css-eol.js.map +1 -0
  27. package/dist/plugin.d.ts +48 -0
  28. package/dist/plugin.d.ts.map +1 -0
  29. package/dist/plugin.js +404 -0
  30. package/dist/plugin.js.map +1 -0
  31. package/dist/primitive-resolve.d.ts +56 -0
  32. package/dist/primitive-resolve.d.ts.map +1 -0
  33. package/dist/primitive-resolve.js +71 -0
  34. package/dist/primitive-resolve.js.map +1 -0
  35. package/dist/resolve-fs.d.ts +13 -0
  36. package/dist/resolve-fs.d.ts.map +1 -0
  37. package/dist/resolve-fs.js +80 -0
  38. package/dist/resolve-fs.js.map +1 -0
  39. package/dist/resolve-utils.d.ts +20 -0
  40. package/dist/resolve-utils.d.ts.map +1 -0
  41. package/dist/resolve-utils.js +45 -0
  42. package/dist/resolve-utils.js.map +1 -0
  43. package/dist/style-transform.d.ts +49 -0
  44. package/dist/style-transform.d.ts.map +1 -0
  45. package/dist/style-transform.js +122 -0
  46. package/dist/style-transform.js.map +1 -0
  47. package/dist/theme-transform.d.ts +44 -0
  48. package/dist/theme-transform.d.ts.map +1 -0
  49. package/dist/theme-transform.js +85 -0
  50. package/dist/theme-transform.js.map +1 -0
  51. package/dist/token-transform.d.ts +42 -0
  52. package/dist/token-transform.d.ts.map +1 -0
  53. package/dist/token-transform.js +84 -0
  54. package/dist/token-transform.js.map +1 -0
  55. package/dist/virtual-modules.d.ts +55 -0
  56. package/dist/virtual-modules.d.ts.map +1 -0
  57. package/dist/virtual-modules.js +141 -0
  58. package/dist/virtual-modules.js.map +1 -0
  59. package/dist/wasm-resolve.d.ts +25 -0
  60. package/dist/wasm-resolve.d.ts.map +1 -0
  61. package/dist/wasm-resolve.js +36 -0
  62. package/dist/wasm-resolve.js.map +1 -0
  63. package/package.json +63 -0
  64. package/src/css-quantize.ts +294 -0
  65. package/src/environments.ts +98 -0
  66. package/src/hmr.ts +121 -0
  67. package/src/html-transform.ts +61 -0
  68. package/src/index.ts +71 -0
  69. package/src/normalize-css-eol.ts +8 -0
  70. package/src/plugin.ts +492 -0
  71. package/src/primitive-resolve.ts +106 -0
  72. package/src/resolve-fs.ts +82 -0
  73. package/src/resolve-utils.ts +54 -0
  74. package/src/style-transform.ts +157 -0
  75. package/src/theme-transform.ts +119 -0
  76. package/src/token-transform.ts +117 -0
  77. package/src/virtual-modules.ts +160 -0
  78. package/src/wasm-resolve.ts +54 -0
@@ -0,0 +1,85 @@
1
+ /**
2
+ * `@theme` CSS block parser and compiler.
3
+ *
4
+ * Parses custom `@theme name { token: value; ... }` blocks from CSS
5
+ * source and compiles them into `html[data-theme]` selector blocks
6
+ * plus transition declarations using resolved `ThemeDef` definitions.
7
+ *
8
+ * @module
9
+ */
10
+ import { ThemeCSSCompiler } from '@czap/compiler';
11
+ import { normalizeCssLineEndings } from './normalize-css-eol.js';
12
+ // ---------------------------------------------------------------------------
13
+ // Parser
14
+ // ---------------------------------------------------------------------------
15
+ /**
16
+ * Parse every `@theme` block from CSS source text.
17
+ *
18
+ * Grammar:
19
+ *
20
+ * ```css
21
+ * @theme name {
22
+ * tokenName: value;
23
+ * }
24
+ * ```
25
+ */
26
+ export function parseThemeBlocks(css, sourceFile) {
27
+ const blocks = [];
28
+ const lines = normalizeCssLineEndings(css).split('\n');
29
+ let i = 0;
30
+ while (i < lines.length) {
31
+ const line = lines[i];
32
+ const atMatch = line.match(/^\s*@theme\s+([a-zA-Z_][a-zA-Z0-9_-]*)\s*\{/);
33
+ if (atMatch) {
34
+ const themeName = atMatch[1];
35
+ const blockStartLine = i + 1; // 1-indexed
36
+ const declarations = {};
37
+ i++; // advance past @theme line
38
+ while (i < lines.length) {
39
+ const currentLine = lines[i].trim();
40
+ // Closing brace for @theme block
41
+ if (currentLine === '}') {
42
+ i++;
43
+ break;
44
+ }
45
+ const propMatch = currentLine.match(/^([a-zA-Z-][a-zA-Z0-9_-]*)\s*:\s*(.+?)\s*;?\s*$/);
46
+ if (propMatch) {
47
+ declarations[propMatch[1]] = propMatch[2].replace(/;$/, '').trim();
48
+ }
49
+ i++;
50
+ }
51
+ blocks.push({ themeName, declarations, sourceFile, line: blockStartLine });
52
+ }
53
+ else {
54
+ i++;
55
+ }
56
+ }
57
+ return blocks;
58
+ }
59
+ // ---------------------------------------------------------------------------
60
+ // Compiler (delegates to @czap/compiler ThemeCSSCompiler)
61
+ // ---------------------------------------------------------------------------
62
+ /**
63
+ * Compile a parsed {@link ThemeBlock} plus a resolved `ThemeDef` into
64
+ * `html[data-theme]` selector blocks and transition declarations.
65
+ * Delegates to the canonical `ThemeCSSCompiler` to avoid duplicating
66
+ * theme-to-CSS logic.
67
+ */
68
+ export function compileThemeBlock(block, theme) {
69
+ const result = ThemeCSSCompiler.compile(theme);
70
+ const parts = [];
71
+ if (result.selectors) {
72
+ parts.push(result.selectors);
73
+ }
74
+ if (result.transitions) {
75
+ parts.push(result.transitions);
76
+ }
77
+ if (Object.keys(block.declarations).length > 0) {
78
+ const overrides = Object.entries(block.declarations)
79
+ .map(([prop, value]) => ` ${prop}: ${value};`)
80
+ .join('\n');
81
+ parts.push(`html {\n${overrides}\n}`);
82
+ }
83
+ return parts.join('\n\n');
84
+ }
85
+ //# sourceMappingURL=theme-transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-transform.js","sourceRoot":"","sources":["../src/theme-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAqBjE,8EAA8E;AAC9E,SAAS;AACT,8EAA8E;AAE9E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,UAAkB;IAC9D,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,uBAAuB,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACvD,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;QACvB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;QAE1E,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;YAC9B,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY;YAC1C,MAAM,YAAY,GAA2B,EAAE,CAAC;YAEhD,CAAC,EAAE,CAAC,CAAC,2BAA2B;YAEhC,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;gBACxB,MAAM,WAAW,GAAG,KAAK,CAA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C,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC;aACjD,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,KAAK,KAAK,GAAG,CAAC;aAC9C,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,KAAK,CAAC,IAAI,CAAC,WAAW,SAAS,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * `@token` CSS block parser and compiler.
3
+ *
4
+ * Parses custom `@token name { prop: value; ... }` blocks from CSS
5
+ * source and compiles them into CSS custom properties plus
6
+ * `@property` registrations using resolved `TokenDef` definitions.
7
+ *
8
+ * @module
9
+ */
10
+ import type { Token } from '@czap/core';
11
+ /**
12
+ * Parsed `@token` block: the token to emit and any inline overrides.
13
+ */
14
+ export interface TokenBlock {
15
+ /** Named token (resolved against exported `TokenDef` values). */
16
+ readonly tokenName: string;
17
+ /** Inline overrides (`{ cssProp: value }`). */
18
+ readonly declarations: Record<string, string>;
19
+ /** Absolute source file path. */
20
+ readonly sourceFile: string;
21
+ /** 1-based line where the block begins. */
22
+ readonly line: number;
23
+ }
24
+ /**
25
+ * Parse every `@token` block from CSS source text.
26
+ *
27
+ * Grammar:
28
+ *
29
+ * ```css
30
+ * @token name {
31
+ * property: value;
32
+ * }
33
+ * ```
34
+ */
35
+ export declare function parseTokenBlocks(css: string, sourceFile: string): readonly TokenBlock[];
36
+ /**
37
+ * Compile a parsed {@link TokenBlock} plus a resolved `TokenDef` into
38
+ * CSS custom property declarations. Delegates to the canonical
39
+ * `TokenCSSCompiler` to avoid duplicating token-to-CSS logic.
40
+ */
41
+ export declare function compileTokenBlock(block: TokenBlock, token: Token.Shape): string;
42
+ //# sourceMappingURL=token-transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-transform.d.ts","sourceRoot":"","sources":["../src/token-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAQxC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,iEAAiE;IACjE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,+CAA+C;IAC/C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,iCAAiC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,UAAU,EAAE,CAuCvF;AAMD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,MAAM,CAmB/E"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * `@token` CSS block parser and compiler.
3
+ *
4
+ * Parses custom `@token name { prop: value; ... }` blocks from CSS
5
+ * source and compiles them into CSS custom properties plus
6
+ * `@property` registrations using resolved `TokenDef` definitions.
7
+ *
8
+ * @module
9
+ */
10
+ import { TokenCSSCompiler } from '@czap/compiler';
11
+ import { normalizeCssLineEndings } from './normalize-css-eol.js';
12
+ // ---------------------------------------------------------------------------
13
+ // Parser
14
+ // ---------------------------------------------------------------------------
15
+ /**
16
+ * Parse every `@token` block from CSS source text.
17
+ *
18
+ * Grammar:
19
+ *
20
+ * ```css
21
+ * @token name {
22
+ * property: value;
23
+ * }
24
+ * ```
25
+ */
26
+ export function parseTokenBlocks(css, sourceFile) {
27
+ const blocks = [];
28
+ const lines = normalizeCssLineEndings(css).split('\n');
29
+ let i = 0;
30
+ while (i < lines.length) {
31
+ const line = lines[i];
32
+ const atMatch = line.match(/^\s*@token\s+([a-zA-Z_][a-zA-Z0-9_-]*)\s*\{/);
33
+ if (atMatch) {
34
+ const tokenName = atMatch[1];
35
+ const blockStartLine = i + 1; // 1-indexed
36
+ const declarations = {};
37
+ i++; // advance past @token line
38
+ while (i < lines.length) {
39
+ const currentLine = lines[i].trim();
40
+ // Closing brace for @token block
41
+ if (currentLine === '}') {
42
+ i++;
43
+ break;
44
+ }
45
+ const propMatch = currentLine.match(/^([a-zA-Z-][a-zA-Z0-9-]*)\s*:\s*(.+?)\s*;?\s*$/);
46
+ if (propMatch) {
47
+ declarations[propMatch[1]] = propMatch[2].replace(/;$/, '').trim();
48
+ }
49
+ i++;
50
+ }
51
+ blocks.push({ tokenName, declarations, sourceFile, line: blockStartLine });
52
+ }
53
+ else {
54
+ i++;
55
+ }
56
+ }
57
+ return blocks;
58
+ }
59
+ // ---------------------------------------------------------------------------
60
+ // Compiler (delegates to @czap/compiler TokenCSSCompiler)
61
+ // ---------------------------------------------------------------------------
62
+ /**
63
+ * Compile a parsed {@link TokenBlock} plus a resolved `TokenDef` into
64
+ * CSS custom property declarations. Delegates to the canonical
65
+ * `TokenCSSCompiler` to avoid duplicating token-to-CSS logic.
66
+ */
67
+ export function compileTokenBlock(block, token) {
68
+ const result = TokenCSSCompiler.compile(token);
69
+ const parts = [];
70
+ if (result.customProperties) {
71
+ parts.push(result.customProperties);
72
+ }
73
+ if (result.themed) {
74
+ parts.push(result.themed);
75
+ }
76
+ if (Object.keys(block.declarations).length > 0) {
77
+ const overrides = Object.entries(block.declarations)
78
+ .map(([prop, value]) => ` ${prop}: ${value};`)
79
+ .join('\n');
80
+ parts.push(`:root {\n${overrides}\n}`);
81
+ }
82
+ return parts.join('\n\n');
83
+ }
84
+ //# sourceMappingURL=token-transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-transform.js","sourceRoot":"","sources":["../src/token-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,g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ading for czap design primitives.
3
+ *
4
+ * Handles Vite's `resolveId` and `load` for virtual module specifiers
5
+ * that provide runtime access to token, boundary, and theme
6
+ * definitions. The modules export placeholder content that the
7
+ * transform pipeline later replaces inline.
8
+ *
9
+ * Virtual IDs:
10
+ *
11
+ * - `virtual:czap/tokens` -- JS exports of token definitions.
12
+ * - `virtual:czap/tokens.css` -- CSS custom properties from tokens.
13
+ * - `virtual:czap/boundaries` -- JS exports of boundary definitions.
14
+ * - `virtual:czap/themes` -- JS exports of theme definitions.
15
+ * - `virtual:czap/hmr-client` -- Client-side HMR handler for
16
+ * `czap:update` events.
17
+ * - `virtual:czap/wasm-url` -- Resolved WASM runtime URL (or `null`).
18
+ * - `virtual:czap/config` -- Typed handle for the workspace
19
+ * `czap.config.ts` hub.
20
+ *
21
+ * @module
22
+ */
23
+ declare const VIRTUAL_IDS: readonly ["virtual:czap/tokens", "virtual:czap/tokens.css", "virtual:czap/boundaries", "virtual:czap/themes", "virtual:czap/hmr-client", "virtual:czap/wasm-url", "virtual:czap/config"];
24
+ /** Recognised virtual module specifiers. */
25
+ export type VirtualModuleId = (typeof VIRTUAL_IDS)[number];
26
+ /**
27
+ * Resolve a virtual module ID to its internal null-byte-prefixed form
28
+ * (as expected by Vite's module graph). Returns `undefined` when `id`
29
+ * is not a recognised czap virtual module.
30
+ */
31
+ export declare function resolveVirtualId(id: string): string | undefined;
32
+ /**
33
+ * Return `true` when `id` is a fully-resolved czap virtual module
34
+ * (null-byte-prefixed). Callers use this to gate `load` handler
35
+ * dispatch.
36
+ */
37
+ export declare function isVirtualId(id: string): boolean;
38
+ /**
39
+ * Return the source for a resolved virtual module ID.
40
+ *
41
+ * Data modules (tokens, boundaries, themes) return empty-object stubs
42
+ * that provide valid JS/CSS so downstream tooling (type-checkers,
43
+ * bundlers) can operate without the full transform pipeline running.
44
+ * Their real content flows through the CSS transform hooks in the
45
+ * plugin -- at build time the transform replaces token, theme, and
46
+ * quantize blocks inline, so these stubs are only hit when a consumer
47
+ * explicitly imports the virtual module (e.g. for runtime JS access
48
+ * to definitions).
49
+ *
50
+ * The `hmr-client` module is the client-side HMR handler that the
51
+ * plugin injects into the page via `transformIndexHtml`.
52
+ */
53
+ export declare function loadVirtualModule(id: string): string | undefined;
54
+ export {};
55
+ //# sourceMappingURL=virtual-modules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"virtual-modules.d.ts","sourceRoot":"","sources":["../src/virtual-modules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAQH,QAAA,MAAM,WAAW,0LAQP,CAAC;AAEX,4CAA4C;AAC5C,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAM3D;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK/D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAE/C;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkChE"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Virtual module resolution and loading for czap design primitives.
3
+ *
4
+ * Handles Vite's `resolveId` and `load` for virtual module specifiers
5
+ * that provide runtime access to token, boundary, and theme
6
+ * definitions. The modules export placeholder content that the
7
+ * transform pipeline later replaces inline.
8
+ *
9
+ * Virtual IDs:
10
+ *
11
+ * - `virtual:czap/tokens` -- JS exports of token definitions.
12
+ * - `virtual:czap/tokens.css` -- CSS custom properties from tokens.
13
+ * - `virtual:czap/boundaries` -- JS exports of boundary definitions.
14
+ * - `virtual:czap/themes` -- JS exports of theme definitions.
15
+ * - `virtual:czap/hmr-client` -- Client-side HMR handler for
16
+ * `czap:update` events.
17
+ * - `virtual:czap/wasm-url` -- Resolved WASM runtime URL (or `null`).
18
+ * - `virtual:czap/config` -- Typed handle for the workspace
19
+ * `czap.config.ts` hub.
20
+ *
21
+ * @module
22
+ */
23
+ // ---------------------------------------------------------------------------
24
+ // Constants
25
+ // ---------------------------------------------------------------------------
26
+ const VIRTUAL_PREFIX = '\0virtual:czap/';
27
+ const VIRTUAL_IDS = [
28
+ 'virtual:czap/tokens',
29
+ 'virtual:czap/tokens.css',
30
+ 'virtual:czap/boundaries',
31
+ 'virtual:czap/themes',
32
+ 'virtual:czap/hmr-client',
33
+ 'virtual:czap/wasm-url',
34
+ 'virtual:czap/config',
35
+ ];
36
+ // ---------------------------------------------------------------------------
37
+ // Resolution
38
+ // ---------------------------------------------------------------------------
39
+ /**
40
+ * Resolve a virtual module ID to its internal null-byte-prefixed form
41
+ * (as expected by Vite's module graph). Returns `undefined` when `id`
42
+ * is not a recognised czap virtual module.
43
+ */
44
+ export function resolveVirtualId(id) {
45
+ if (VIRTUAL_IDS.includes(id)) {
46
+ return VIRTUAL_PREFIX + id.slice('virtual:czap/'.length);
47
+ }
48
+ return undefined;
49
+ }
50
+ /**
51
+ * Return `true` when `id` is a fully-resolved czap virtual module
52
+ * (null-byte-prefixed). Callers use this to gate `load` handler
53
+ * dispatch.
54
+ */
55
+ export function isVirtualId(id) {
56
+ return id.startsWith(VIRTUAL_PREFIX);
57
+ }
58
+ // ---------------------------------------------------------------------------
59
+ // Loading
60
+ // ---------------------------------------------------------------------------
61
+ /**
62
+ * Return the source for a resolved virtual module ID.
63
+ *
64
+ * Data modules (tokens, boundaries, themes) return empty-object stubs
65
+ * that provide valid JS/CSS so downstream tooling (type-checkers,
66
+ * bundlers) can operate without the full transform pipeline running.
67
+ * Their real content flows through the CSS transform hooks in the
68
+ * plugin -- at build time the transform replaces token, theme, and
69
+ * quantize blocks inline, so these stubs are only hit when a consumer
70
+ * explicitly imports the virtual module (e.g. for runtime JS access
71
+ * to definitions).
72
+ *
73
+ * The `hmr-client` module is the client-side HMR handler that the
74
+ * plugin injects into the page via `transformIndexHtml`.
75
+ */
76
+ export function loadVirtualModule(id) {
77
+ if (!id.startsWith(VIRTUAL_PREFIX))
78
+ return undefined;
79
+ const name = id.slice(VIRTUAL_PREFIX.length);
80
+ switch (name) {
81
+ case 'tokens':
82
+ return 'export const tokens = {};';
83
+ case 'tokens.css':
84
+ return ':root {}';
85
+ case 'boundaries':
86
+ return 'export const boundaries = {};';
87
+ case 'themes':
88
+ return 'export const themes = {};';
89
+ case 'hmr-client':
90
+ return HMR_CLIENT_SOURCE;
91
+ case 'wasm-url':
92
+ return 'export const wasmUrl = null;';
93
+ case 'config':
94
+ return [
95
+ '/** czap/config virtual module -- typed stub served by czap/vite */',
96
+ '/** Full config is available via czap.config.ts at the workspace root */',
97
+ 'export const config = null;',
98
+ ].join('\n');
99
+ default:
100
+ return undefined;
101
+ }
102
+ }
103
+ /**
104
+ * Client-side HMR handler injected via virtual module.
105
+ * Listens for czap:update events on import.meta.hot and applies
106
+ * CSS or shader uniform updates surgically without full reload.
107
+ */
108
+ const HMR_CLIENT_SOURCE = `
109
+ if (import.meta.hot) {
110
+ import.meta.hot.on('czap:update', (payload) => {
111
+ if (typeof document === 'undefined') return;
112
+ if (payload.css !== undefined) {
113
+ const sel = 'style[data-czap-boundary="' + payload.boundary + '"]';
114
+ let el = document.querySelector(sel);
115
+ if (!el) {
116
+ el = document.createElement('style');
117
+ el.setAttribute('data-czap-boundary', payload.boundary);
118
+ document.head.appendChild(el);
119
+ }
120
+ el.textContent = payload.css;
121
+ }
122
+ if (payload.uniforms !== undefined) {
123
+ document.dispatchEvent(new CustomEvent('czap:uniform-update', {
124
+ detail: { boundary: payload.boundary, uniforms: payload.uniforms },
125
+ bubbles: true,
126
+ }));
127
+ document.querySelectorAll('canvas[data-czap-boundary="' + payload.boundary + '"]').forEach((canvas) => {
128
+ const gl = canvas.getContext('webgl2') ?? canvas.getContext('webgl');
129
+ if (!gl) return;
130
+ const program = canvas.__czapProgram;
131
+ if (!program) return;
132
+ Object.entries(payload.uniforms).forEach(([name, value]) => {
133
+ const loc = gl.getUniformLocation(program, name);
134
+ if (loc !== null) gl.uniform1f(loc, value);
135
+ });
136
+ });
137
+ }
138
+ });
139
+ }
140
+ `.trim();
141
+ //# sourceMappingURL=virtual-modules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"virtual-modules.js","sourceRoot":"","sources":["../src/virtual-modules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,MAAM,cAAc,GAAG,iBAAiB,CAAC;AAEzC,MAAM,WAAW,GAAG;IAClB,qBAAqB;IACrB,yBAAyB;IACzB,yBAAyB;IACzB,qBAAqB;IACrB,yBAAyB;IACzB,uBAAuB;IACvB,qBAAqB;CACb,CAAC;AAKX,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAAU;IACzC,IAAI,WAAW,CAAC,QAAQ,CAAC,EAAqB,CAAC,EAAE,CAAC;QAChD,OAAO,cAAc,GAAG,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,EAAU;IACpC,OAAO,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;AACvC,CAAC;AAED,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAU;IAC1C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC;QAAE,OAAO,SAAS,CAAC;IAErD,MAAM,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAE7C,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,OAAO,2BAA2B,CAAC;QAErC,KAAK,YAAY;YACf,OAAO,UAAU,CAAC;QAEpB,KAAK,YAAY;YACf,OAAO,+BAA+B,CAAC;QAEzC,KAAK,QAAQ;YACX,OAAO,2BAA2B,CAAC;QAErC,KAAK,YAAY;YACf,OAAO,iBAAiB,CAAC;QAE3B,KAAK,UAAU;YACb,OAAO,8BAA8B,CAAC;QAExC,KAAK,QAAQ;YACX,OAAO;gBACL,qEAAqE;gBACrE,0EAA0E;gBAC1E,6BAA6B;aAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEf;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCzB,CAAC,IAAI,EAAE,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * WASM binary resolution -- locates the czap-compute .wasm file.
3
+ *
4
+ * Searches for the compiled WASM binary in conventional locations:
5
+ * 1. Configured path (if provided)
6
+ * 2. crates/czap-compute/target/wasm32-unknown-unknown/release/czap_compute.wasm
7
+ * 3. public/czap-compute.wasm (pre-copied)
8
+ *
9
+ * @module
10
+ */
11
+ /**
12
+ * Successful WASM-resolution result: the absolute binary path plus the
13
+ * search step that found it (useful for diagnostics).
14
+ */
15
+ export interface WASMResolution {
16
+ /** Absolute filesystem path to the WASM binary. */
17
+ readonly filePath: string;
18
+ /** Which search step matched (`'config'`, `'crate'`, or `'public'`). */
19
+ readonly source: 'config' | 'crate' | 'public';
20
+ }
21
+ /**
22
+ * Resolve the czap-compute WASM binary path.
23
+ */
24
+ export declare function resolveWASM(projectRoot: string, configPath?: string): WASMResolution | null;
25
+ //# sourceMappingURL=wasm-resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm-resolve.d.ts","sourceRoot":"","sources":["../src/wasm-resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;CAChD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAyB3F"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * WASM binary resolution -- locates the czap-compute .wasm file.
3
+ *
4
+ * Searches for the compiled WASM binary in conventional locations:
5
+ * 1. Configured path (if provided)
6
+ * 2. crates/czap-compute/target/wasm32-unknown-unknown/release/czap_compute.wasm
7
+ * 3. public/czap-compute.wasm (pre-copied)
8
+ *
9
+ * @module
10
+ */
11
+ import { fileExists } from './resolve-fs.js';
12
+ import * as path from 'node:path';
13
+ /**
14
+ * Resolve the czap-compute WASM binary path.
15
+ */
16
+ export function resolveWASM(projectRoot, configPath) {
17
+ // 1. Configured path
18
+ if (configPath) {
19
+ const resolved = path.isAbsolute(configPath) ? configPath : path.join(projectRoot, configPath);
20
+ if (fileExists(resolved, 'czap/vite.wasm-resolve')) {
21
+ return { filePath: resolved, source: 'config' };
22
+ }
23
+ }
24
+ // 2. Rust crate build output
25
+ const crateOutput = path.join(projectRoot, 'crates/czap-compute/target/wasm32-unknown-unknown/release/czap_compute.wasm');
26
+ if (fileExists(crateOutput, 'czap/vite.wasm-resolve')) {
27
+ return { filePath: crateOutput, source: 'crate' };
28
+ }
29
+ // 3. Public directory (pre-copied)
30
+ const publicPath = path.join(projectRoot, 'public/czap-compute.wasm');
31
+ if (fileExists(publicPath, 'czap/vite.wasm-resolve')) {
32
+ return { filePath: publicPath, source: 'public' };
33
+ }
34
+ return null;
35
+ }
36
+ //# sourceMappingURL=wasm-resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm-resolve.js","sourceRoot":"","sources":["../src/wasm-resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAalC;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,WAAmB,EAAE,UAAmB;IAClE,qBAAqB;IACrB,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAC/F,IAAI,UAAU,CAAC,QAAQ,EAAE,wBAAwB,CAAC,EAAE,CAAC;YACnD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QAClD,CAAC;IACH,CAAC;IAED,6BAA6B;IAC7B,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAC3B,WAAW,EACX,6EAA6E,CAC9E,CAAC;IACF,IAAI,UAAU,CAAC,WAAW,EAAE,wBAAwB,CAAC,EAAE,CAAC;QACtD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IACpD,CAAC;IAED,mCAAmC;IACnC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,0BAA0B,CAAC,CAAC;IACtE,IAAI,UAAU,CAAC,UAAU,EAAE,wBAAwB,CAAC,EAAE,CAAC;QACrD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IACpD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@czap/vite",
3
+ "version": "0.1.0",
4
+ "description": "Vite 8 plugin for czap CSS/shader transforms and HMR",
5
+ "license": "MIT",
6
+ "author": "Eassa Ayoub <eassa@heyoub.dev>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/heyoub/LiteShip",
10
+ "directory": "packages/vite"
11
+ },
12
+ "bugs": "https://github.com/heyoub/LiteShip/issues",
13
+ "homepage": "https://github.com/heyoub/LiteShip#readme",
14
+ "keywords": [
15
+ "czap",
16
+ "vite",
17
+ "vite-plugin",
18
+ "css-transform",
19
+ "hmr",
20
+ "typescript"
21
+ ],
22
+ "type": "module",
23
+ "sideEffects": false,
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js",
30
+ "development": "./src/index.ts"
31
+ },
32
+ "./html-transform": {
33
+ "types": "./dist/html-transform.d.ts",
34
+ "import": "./dist/html-transform.js",
35
+ "development": "./src/html-transform.ts"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "src",
41
+ "LICENSE"
42
+ ],
43
+ "dependencies": {
44
+ "@czap/core": "0.1.0",
45
+ "@czap/compiler": "0.1.0"
46
+ },
47
+ "peerDependencies": {
48
+ "vite": ">=8.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^22.0.0",
52
+ "vite": "^8.0.0"
53
+ },
54
+ "engines": {
55
+ "node": ">=22.0.0"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "scripts": {
61
+ "build": "tsc"
62
+ }
63
+ }