@vizejs/wasm 0.100.0 → 0.102.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.
package/index.d.ts ADDED
@@ -0,0 +1,260 @@
1
+ /**
2
+ * Vize - WASM bindings
3
+ *
4
+ * This package provides WebAssembly bindings for the Vue compiler implemented in Rust.
5
+ */
6
+
7
+ /** Compiler options for template compilation */
8
+ export interface CompilerOptions {
9
+ /** Output mode: "module" or "function" */
10
+ mode?: "module" | "function";
11
+ /** Whether to prefix identifiers */
12
+ prefixIdentifiers?: boolean;
13
+ /** Whether to hoist static nodes */
14
+ hoistStatic?: boolean;
15
+ /** Whether to cache event handlers */
16
+ cacheHandlers?: boolean;
17
+ /** Scope ID for scoped CSS */
18
+ scopeId?: string;
19
+ /** Whether in SSR mode */
20
+ ssr?: boolean;
21
+ /** Whether to generate source map */
22
+ sourceMap?: boolean;
23
+ /** Filename for source map */
24
+ filename?: string;
25
+ /** Output mode: "vdom" or "vapor" */
26
+ outputMode?: "vdom" | "vapor";
27
+ /** Whether the template contains TypeScript */
28
+ isTs?: boolean;
29
+ }
30
+
31
+ /** Result of template compilation */
32
+ export interface CompileResult {
33
+ /** Generated code */
34
+ code: string;
35
+ /** Preamble code (imports) */
36
+ preamble: string;
37
+ /** AST (serialized) */
38
+ ast: object;
39
+ /** Source map */
40
+ map?: object | null;
41
+ /** Used helpers */
42
+ helpers: string[];
43
+ /** Template strings for Vapor mode static parts */
44
+ templates?: string[];
45
+ }
46
+
47
+ /** SFC block (template, script, style) */
48
+ export interface SfcBlock {
49
+ /** Block content */
50
+ content: string;
51
+ /** Source location */
52
+ loc: { start: number; end: number };
53
+ /** Language (e.g., "ts", "scss") */
54
+ lang?: string;
55
+ /** External source URL */
56
+ src?: string;
57
+ /** Block attributes */
58
+ attrs: Record<string, string | true>;
59
+ }
60
+
61
+ /** SFC script block */
62
+ export interface SfcScriptBlock extends SfcBlock {
63
+ /** Whether this is a setup script */
64
+ setup: boolean;
65
+ }
66
+
67
+ /** SFC style block */
68
+ export interface SfcStyleBlock extends SfcBlock {
69
+ /** Whether the style is scoped */
70
+ scoped: boolean;
71
+ /** CSS module name */
72
+ module?: string | true;
73
+ }
74
+
75
+ /** Compile-time macro artifact extracted from an SFC */
76
+ export interface MacroArtifact {
77
+ /** Stable artifact kind */
78
+ kind: string;
79
+ /** Macro call name */
80
+ name: string;
81
+ /** Full macro call source */
82
+ source: string;
83
+ /** Extracted macro payload source */
84
+ content: string;
85
+ /** Ready-to-load virtual module code */
86
+ moduleCode?: string;
87
+ /** Absolute start offset in the SFC source */
88
+ start: number;
89
+ /** Absolute end offset in the SFC source */
90
+ end: number;
91
+ }
92
+
93
+ /** SFC descriptor (parsed .vue file) */
94
+ export interface SfcDescriptor {
95
+ /** Filename */
96
+ filename: string;
97
+ /** Original source */
98
+ source: string;
99
+ /** Template block */
100
+ template?: SfcBlock;
101
+ /** Script block */
102
+ script?: SfcScriptBlock;
103
+ /** Script setup block */
104
+ scriptSetup?: SfcScriptBlock;
105
+ /** Style blocks */
106
+ styles: SfcStyleBlock[];
107
+ /** Custom blocks */
108
+ customBlocks: Array<{
109
+ type: string;
110
+ content: string;
111
+ attrs: Record<string, string | true>;
112
+ }>;
113
+ }
114
+
115
+ /** SFC parse options */
116
+ export interface SfcParseOptions {
117
+ /** Filename for the SFC */
118
+ filename?: string;
119
+ }
120
+
121
+ /** SFC compile options */
122
+ export interface SfcCompileOptions extends CompilerOptions {
123
+ /** Filename for the SFC */
124
+ filename?: string;
125
+ }
126
+
127
+ /** Result of SFC compilation */
128
+ export interface SfcCompileResult {
129
+ /** Parsed SFC descriptor */
130
+ descriptor: SfcDescriptor;
131
+ /** Compiled template result */
132
+ template?: CompileResult;
133
+ /** Compiled script result */
134
+ script: {
135
+ /** Generated JavaScript code */
136
+ code: string;
137
+ /** Binding metadata */
138
+ bindings?: object;
139
+ };
140
+ /** Generated CSS */
141
+ css?: string;
142
+ /** Compilation errors */
143
+ errors: string[];
144
+ /** Compilation warnings */
145
+ warnings: string[];
146
+ /** Compile-time macro artifacts */
147
+ macroArtifacts?: MacroArtifact[];
148
+ }
149
+
150
+ /** CSS compile options */
151
+ export interface CssCompileOptions {
152
+ /** Scope ID for scoped CSS */
153
+ scopeId?: string;
154
+ /** Whether to scope the CSS */
155
+ scoped?: boolean;
156
+ /** Whether to minify */
157
+ minify?: boolean;
158
+ /** Whether to generate source map */
159
+ sourceMap?: boolean;
160
+ /** Filename for source map */
161
+ filename?: string;
162
+ /** Browser targets for CSS transformations */
163
+ targets?: {
164
+ chrome?: number;
165
+ firefox?: number;
166
+ safari?: number;
167
+ edge?: number;
168
+ ios?: number;
169
+ android?: number;
170
+ };
171
+ }
172
+
173
+ /** Result of CSS compilation */
174
+ export interface CssCompileResult {
175
+ /** Generated CSS code */
176
+ code: string;
177
+ /** Source map (if requested) */
178
+ map?: string;
179
+ /** CSS variables used via v-bind() */
180
+ cssVars: string[];
181
+ /** Compilation errors */
182
+ errors: string[];
183
+ /** Compilation warnings */
184
+ warnings: string[];
185
+ }
186
+
187
+ /** WASM Compiler class */
188
+ export declare class Compiler {
189
+ constructor();
190
+
191
+ /** Compile template to VDom render function */
192
+ compile(template: string, options?: CompilerOptions): CompileResult;
193
+
194
+ /** Compile template to Vapor mode */
195
+ compileVapor(template: string, options?: CompilerOptions): CompileResult;
196
+
197
+ /** Parse template to AST */
198
+ parse(template: string, options?: CompilerOptions): object;
199
+
200
+ /** Parse SFC (.vue file) */
201
+ parseSfc(source: string, options?: SfcParseOptions): SfcDescriptor;
202
+
203
+ /** Compile SFC (.vue file) */
204
+ compileSfc(source: string, options?: SfcCompileOptions): SfcCompileResult;
205
+
206
+ /** Compile CSS with LightningCSS */
207
+ compileCss(css: string, options?: CssCompileOptions): CssCompileResult;
208
+
209
+ /** Free the WASM memory (called automatically via Symbol.dispose) */
210
+ free(): void;
211
+
212
+ /** Disposable interface */
213
+ [Symbol.dispose](): void;
214
+ }
215
+
216
+ /** Compile template to VDom render function */
217
+ export declare function compile(
218
+ template: string,
219
+ options?: CompilerOptions
220
+ ): CompileResult;
221
+
222
+ /** Compile template to Vapor mode */
223
+ export declare function compileVapor(
224
+ template: string,
225
+ options?: CompilerOptions
226
+ ): CompileResult;
227
+
228
+ /** Parse template to AST */
229
+ export declare function parseTemplate(
230
+ template: string,
231
+ options?: CompilerOptions
232
+ ): object;
233
+
234
+ /** Parse SFC (.vue file) */
235
+ export declare function parseSfc(
236
+ source: string,
237
+ options?: SfcParseOptions
238
+ ): SfcDescriptor;
239
+
240
+ /** Compile SFC (.vue file) */
241
+ export declare function compileSfc(
242
+ source: string,
243
+ options?: SfcCompileOptions
244
+ ): SfcCompileResult;
245
+
246
+ /** Compile CSS with LightningCSS */
247
+ export declare function compileCss(
248
+ css: string,
249
+ options?: CssCompileOptions
250
+ ): CssCompileResult;
251
+
252
+ /** Initialize the WASM module */
253
+ export declare function init(
254
+ moduleOrPath?: RequestInfo | URL | Response | BufferSource | WebAssembly.Module
255
+ ): Promise<void>;
256
+
257
+ /** Check if the WASM module is initialized */
258
+ export declare function isInitialized(): boolean;
259
+
260
+ export default init;
package/index.js ADDED
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Vize - WASM bindings
3
+ *
4
+ * This module provides WebAssembly bindings for the Vue compiler implemented in Rust.
5
+ */
6
+
7
+ import initWasm, {
8
+ Compiler as WasmCompiler,
9
+ compile as wasmCompile,
10
+ compileVapor as wasmCompileVapor,
11
+ parseTemplate as wasmParseTemplate,
12
+ parseSfc as wasmParseSfc,
13
+ compileSfc as wasmCompileSfc,
14
+ compileCss as wasmCompileCss,
15
+ } from "./vize_vitrine.js";
16
+
17
+ let initialized = false;
18
+ let initPromise = null;
19
+
20
+ /**
21
+ * Initialize the WASM module.
22
+ * Must be called before using any other functions.
23
+ *
24
+ * @param {RequestInfo | URL | Response | BufferSource | WebAssembly.Module} [moduleOrPath]
25
+ * @returns {Promise<void>}
26
+ */
27
+ export async function init(moduleOrPath) {
28
+ if (initialized) {
29
+ return;
30
+ }
31
+
32
+ if (initPromise) {
33
+ return initPromise;
34
+ }
35
+
36
+ initPromise = initWasm(moduleOrPath).then(() => {
37
+ initialized = true;
38
+ });
39
+
40
+ return initPromise;
41
+ }
42
+
43
+ /**
44
+ * Check if the WASM module is initialized.
45
+ *
46
+ * @returns {boolean}
47
+ */
48
+ export function isInitialized() {
49
+ return initialized;
50
+ }
51
+
52
+ /**
53
+ * Ensure WASM is initialized, throwing if not.
54
+ */
55
+ function ensureInitialized() {
56
+ if (!initialized) {
57
+ throw new Error(
58
+ "WASM module not initialized. Call `await init()` first."
59
+ );
60
+ }
61
+ }
62
+
63
+ /**
64
+ * WASM Compiler class wrapper.
65
+ */
66
+ export class Compiler {
67
+ #inner;
68
+
69
+ constructor() {
70
+ ensureInitialized();
71
+ this.#inner = new WasmCompiler();
72
+ }
73
+
74
+ /**
75
+ * Compile template to VDom render function.
76
+ *
77
+ * @param {string} template
78
+ * @param {object} [options]
79
+ * @returns {object}
80
+ */
81
+ compile(template, options = {}) {
82
+ return this.#inner.compile(template, options);
83
+ }
84
+
85
+ /**
86
+ * Compile template to Vapor mode.
87
+ *
88
+ * @param {string} template
89
+ * @param {object} [options]
90
+ * @returns {object}
91
+ */
92
+ compileVapor(template, options = {}) {
93
+ return this.#inner.compileVapor(template, options);
94
+ }
95
+
96
+ /**
97
+ * Parse template to AST.
98
+ *
99
+ * @param {string} template
100
+ * @param {object} [options]
101
+ * @returns {object}
102
+ */
103
+ parse(template, options = {}) {
104
+ return this.#inner.parse(template, options);
105
+ }
106
+
107
+ /**
108
+ * Parse SFC (.vue file).
109
+ *
110
+ * @param {string} source
111
+ * @param {object} [options]
112
+ * @returns {object}
113
+ */
114
+ parseSfc(source, options = {}) {
115
+ return this.#inner.parseSfc(source, options);
116
+ }
117
+
118
+ /**
119
+ * Compile SFC (.vue file).
120
+ *
121
+ * @param {string} source
122
+ * @param {object} [options]
123
+ * @returns {object}
124
+ */
125
+ compileSfc(source, options = {}) {
126
+ return this.#inner.compileSfc(source, options);
127
+ }
128
+
129
+ /**
130
+ * Compile CSS with LightningCSS.
131
+ *
132
+ * @param {string} css
133
+ * @param {object} [options]
134
+ * @returns {object}
135
+ */
136
+ compileCss(css, options = {}) {
137
+ return this.#inner.compileCss(css, options);
138
+ }
139
+
140
+ /**
141
+ * Free the WASM memory.
142
+ */
143
+ free() {
144
+ this.#inner.free();
145
+ }
146
+
147
+ /**
148
+ * Disposable interface.
149
+ */
150
+ [Symbol.dispose]() {
151
+ this.free();
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Compile template to VDom render function.
157
+ *
158
+ * @param {string} template
159
+ * @param {object} [options]
160
+ * @returns {object}
161
+ */
162
+ export function compile(template, options = {}) {
163
+ ensureInitialized();
164
+ return wasmCompile(template, options);
165
+ }
166
+
167
+ /**
168
+ * Compile template to Vapor mode.
169
+ *
170
+ * @param {string} template
171
+ * @param {object} [options]
172
+ * @returns {object}
173
+ */
174
+ export function compileVapor(template, options = {}) {
175
+ ensureInitialized();
176
+ return wasmCompileVapor(template, options);
177
+ }
178
+
179
+ /**
180
+ * Parse template to AST.
181
+ *
182
+ * @param {string} template
183
+ * @param {object} [options]
184
+ * @returns {object}
185
+ */
186
+ export function parseTemplate(template, options = {}) {
187
+ ensureInitialized();
188
+ return wasmParseTemplate(template, options);
189
+ }
190
+
191
+ /**
192
+ * Parse SFC (.vue file).
193
+ *
194
+ * @param {string} source
195
+ * @param {object} [options]
196
+ * @returns {object}
197
+ */
198
+ export function parseSfc(source, options = {}) {
199
+ ensureInitialized();
200
+ return wasmParseSfc(source, options);
201
+ }
202
+
203
+ /**
204
+ * Compile SFC (.vue file).
205
+ *
206
+ * @param {string} source
207
+ * @param {object} [options]
208
+ * @returns {object}
209
+ */
210
+ export function compileSfc(source, options = {}) {
211
+ ensureInitialized();
212
+ return wasmCompileSfc(source, options);
213
+ }
214
+
215
+ /**
216
+ * Compile CSS with LightningCSS.
217
+ *
218
+ * @param {string} css
219
+ * @param {object} [options]
220
+ * @returns {object}
221
+ */
222
+ export function compileCss(css, options = {}) {
223
+ ensureInitialized();
224
+ return wasmCompileCss(css, options);
225
+ }
226
+
227
+ export default init;
package/package.json CHANGED
@@ -1,23 +1,42 @@
1
1
  {
2
2
  "name": "@vizejs/wasm",
3
- "type": "module",
3
+ "version": "0.102.0",
4
4
  "description": "Vize WASM bindings for browser environments",
5
- "version": "0.100.0",
5
+ "homepage": "https://github.com/ubugeeei/vize",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/ubugeeei/vize.git",
10
10
  "directory": "npm/vize-wasm"
11
11
  },
12
- "homepage": "https://github.com/ubugeeei/vize",
13
12
  "files": [
13
+ "index.js",
14
+ "index.d.ts",
14
15
  "vize_vitrine_bg.wasm",
15
16
  "vize_vitrine.js",
16
- "vize_vitrine.d.ts"
17
+ "vize_vitrine.d.ts",
18
+ "snippets/**"
17
19
  ],
18
- "main": "vize_vitrine.js",
19
- "types": "vize_vitrine.d.ts",
20
+ "type": "module",
20
21
  "sideEffects": [
21
22
  "./snippets/*"
22
- ]
23
+ ],
24
+ "main": "./index.js",
25
+ "types": "./index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./index.d.ts",
29
+ "import": "./index.js",
30
+ "default": "./index.js"
31
+ },
32
+ "./vize_vitrine.js": {
33
+ "types": "./vize_vitrine.d.ts",
34
+ "import": "./vize_vitrine.js",
35
+ "default": "./vize_vitrine.js"
36
+ },
37
+ "./vize_vitrine_bg.wasm": "./vize_vitrine_bg.wasm"
38
+ },
39
+ "engines": {
40
+ "node": ">=22"
41
+ }
23
42
  }
Binary file