csskit 0.0.30-canary.dfdb2d1a65 → 0.0.30

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/README.md CHANGED
@@ -4,8 +4,9 @@ csskit is a suite of high performance tools for CSS, written in Rust.
4
4
 
5
5
  ## Goals
6
6
 
7
- The goal of this project is to provide a high quality set of tools for writing native CSS and shipping said CSS into
8
- production the best way possible. This means:
7
+ The goal of this project is to provide a high quality set of tools for writing
8
+ native CSS and shipping said CSS into production the best way possible.
9
+ This means:
9
10
 
10
11
  - Preventing mistakes at author time (parsing & linting).
11
12
  - Advising best practices and highlighting pitfalls (linting).
@@ -17,4 +18,50 @@ production the best way possible. This means:
17
18
 
18
19
  ## Usage
19
20
 
20
- - Visit the [Getting started guide](https://csskit.rs/docs/getting-started/) for more detail.
21
+ ### Binary
22
+
23
+ When installed, `csskit` will be available as a binary. Run `csskit --help` to
24
+ see how to use it, with full instructions and examples.
25
+
26
+ ### Library
27
+
28
+ csskit can also be used as a library, for creating custom scripts:
29
+
30
+ ```js
31
+ import { parse, StyleRule, StyleSheet } from "csskit";
32
+
33
+ const sheet = parse("a { color: red }");
34
+ sheet instanceof StyleSheet; // true
35
+
36
+ for (const rule of sheet.querySelectorAll("style-rule")) {
37
+ console.log(rule.constructor.name, rule.text); // StyleRule a { color: red }
38
+ }
39
+ ```
40
+
41
+ Every AST node kind has its own class, similar to way the DOM has
42
+ `HTMLDivElement`. Each one has a `parse` method. This allows you to parse
43
+ individual grammars, for example:
44
+
45
+ ```js
46
+ import { parse, Color, MediaRule, WidthStyleValue } from "csskit/nodes";
47
+
48
+ Color.parse("#ff0000");
49
+ WidthStyleValue.parse("100px");
50
+ parse("@media print { a { color: red } }", { context: MediaRule });
51
+ ```
52
+
53
+ #### Client Side
54
+
55
+ While the main entry is a native addon, therefore only possible to use in Node,
56
+ a simplified WASM API is available for client side code:
57
+
58
+ ```js
59
+ import { minify } from "csskit/bundle";
60
+ const min = minify("a{color:#ff0000}");
61
+ console.assert(min === "a{color:red}");
62
+ ```
63
+
64
+ The WASM build exposes `lex`, `minify`, `format` and `parseErrorReport`, but no
65
+ object model, so classes like `Color` are not available.
66
+
67
+ Visit the [Getting started guide](https://csskit.rs/docs/getting-started/) for more detail.
package/addon.js ADDED
@@ -0,0 +1,42 @@
1
+ // Resolves the native addon (csskit_napi).
2
+ //
3
+ // It ships in the platform `csskit-<platform>` packages. A local `./csskit.node` wins if present.
4
+
5
+ import { createRequire } from 'node:module';
6
+
7
+ const requireFrom = createRequire(import.meta.url);
8
+
9
+ function platformPackage() {
10
+ const { platform, arch } = process;
11
+ if (platform === 'linux') {
12
+ if (arch === 'x64') return 'csskit-linux-x64';
13
+ if (arch === 'arm64') return 'csskit-linux-arm64';
14
+ } else if (platform === 'darwin') {
15
+ if (arch === 'x64') return 'csskit-darwin-x64';
16
+ if (arch === 'arm64') return 'csskit-darwin-arm64';
17
+ } else if (platform === 'win32') {
18
+ if (arch === 'x64') return 'csskit-win32-x64';
19
+ if (arch === 'arm64') return 'csskit-win32-arm64';
20
+ }
21
+ return null;
22
+ }
23
+
24
+ function loadAddon() {
25
+ const pkg = platformPackage();
26
+ const candidates = pkg ? [`${pkg}/csskit.node`, './csskit.node'] : ['./csskit.node'];
27
+ for (const spec of candidates) {
28
+ try {
29
+ return requireFrom(spec);
30
+ } catch {
31
+ // try the next candidate
32
+ }
33
+ }
34
+ throw new Error(
35
+ `csskit: no native addon for ${process.platform}-${process.arch}. ` +
36
+ `Install the '${pkg || 'csskit-<platform>'}' package, or use the WebAssembly build at 'csskit/bundle'.`,
37
+ );
38
+ }
39
+
40
+ const addon = loadAddon();
41
+
42
+ export default addon;
Binary file
@@ -0,0 +1,535 @@
1
+ /* @ts-self-types="./csskit_wasm.d.ts" */
2
+ import { readFileSync } from 'node:fs';
3
+
4
+
5
+ export class SerializableParserResult {
6
+ static __wrap(ptr) {
7
+ const obj = Object.create(SerializableParserResult.prototype);
8
+ obj.__wbg_ptr = ptr;
9
+ SerializableParserResultFinalization.register(obj, obj.__wbg_ptr, obj);
10
+ return obj;
11
+ }
12
+ __destroy_into_raw() {
13
+ const ptr = this.__wbg_ptr;
14
+ this.__wbg_ptr = 0;
15
+ SerializableParserResultFinalization.unregister(this);
16
+ return ptr;
17
+ }
18
+ free() {
19
+ const ptr = this.__destroy_into_raw();
20
+ wasm.__wbg_serializableparserresult_free(ptr, 0);
21
+ }
22
+ /**
23
+ * @returns {any}
24
+ */
25
+ get ast() {
26
+ const ret = wasm.serializableparserresult_ast(this.__wbg_ptr);
27
+ return takeObject(ret);
28
+ }
29
+ /**
30
+ * @returns {any[]}
31
+ */
32
+ get diagnostics() {
33
+ try {
34
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
35
+ wasm.serializableparserresult_diagnostics(retptr, this.__wbg_ptr);
36
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
37
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
38
+ var v1 = getArrayJsValueFromWasm0(r0, r1);
39
+ wasm.__wbindgen_export3(r0, r1 * 4, 4);
40
+ return v1;
41
+ } finally {
42
+ wasm.__wbindgen_add_to_stack_pointer(16);
43
+ }
44
+ }
45
+ }
46
+ if (Symbol.dispose) SerializableParserResult.prototype[Symbol.dispose] = SerializableParserResult.prototype.free;
47
+
48
+ /**
49
+ * @param {string} source_text
50
+ * @param {any} options
51
+ * @returns {string}
52
+ */
53
+ export function format(source_text, options) {
54
+ let deferred3_0;
55
+ let deferred3_1;
56
+ try {
57
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
58
+ const ptr0 = passStringToWasm0(source_text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
59
+ const len0 = WASM_VECTOR_LEN;
60
+ wasm.format(retptr, ptr0, len0, addHeapObject(options));
61
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
62
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
63
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
64
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
65
+ var ptr2 = r0;
66
+ var len2 = r1;
67
+ if (r3) {
68
+ ptr2 = 0; len2 = 0;
69
+ throw takeObject(r2);
70
+ }
71
+ deferred3_0 = ptr2;
72
+ deferred3_1 = len2;
73
+ return getStringFromWasm0(ptr2, len2);
74
+ } finally {
75
+ wasm.__wbindgen_add_to_stack_pointer(16);
76
+ wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
77
+ }
78
+ }
79
+
80
+ /**
81
+ * @param {string} source_text
82
+ * @returns {any}
83
+ */
84
+ export function lex(source_text) {
85
+ try {
86
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
87
+ const ptr0 = passStringToWasm0(source_text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
88
+ const len0 = WASM_VECTOR_LEN;
89
+ wasm.lex(retptr, ptr0, len0);
90
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
91
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
92
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
93
+ if (r2) {
94
+ throw takeObject(r1);
95
+ }
96
+ return takeObject(r0);
97
+ } finally {
98
+ wasm.__wbindgen_add_to_stack_pointer(16);
99
+ }
100
+ }
101
+
102
+ export function main() {
103
+ wasm.main();
104
+ }
105
+
106
+ /**
107
+ * @param {string} source_text
108
+ * @returns {string}
109
+ */
110
+ export function minify(source_text) {
111
+ let deferred3_0;
112
+ let deferred3_1;
113
+ try {
114
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
115
+ const ptr0 = passStringToWasm0(source_text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
116
+ const len0 = WASM_VECTOR_LEN;
117
+ wasm.minify(retptr, ptr0, len0);
118
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
119
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
120
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
121
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
122
+ var ptr2 = r0;
123
+ var len2 = r1;
124
+ if (r3) {
125
+ ptr2 = 0; len2 = 0;
126
+ throw takeObject(r2);
127
+ }
128
+ deferred3_0 = ptr2;
129
+ deferred3_1 = len2;
130
+ return getStringFromWasm0(ptr2, len2);
131
+ } finally {
132
+ wasm.__wbindgen_add_to_stack_pointer(16);
133
+ wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
134
+ }
135
+ }
136
+
137
+ /**
138
+ * @param {string} source_text
139
+ * @returns {SerializableParserResult}
140
+ */
141
+ export function parse(source_text) {
142
+ try {
143
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
144
+ const ptr0 = passStringToWasm0(source_text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
145
+ const len0 = WASM_VECTOR_LEN;
146
+ wasm.parse(retptr, ptr0, len0);
147
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
148
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
149
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
150
+ if (r2) {
151
+ throw takeObject(r1);
152
+ }
153
+ return SerializableParserResult.__wrap(r0);
154
+ } finally {
155
+ wasm.__wbindgen_add_to_stack_pointer(16);
156
+ }
157
+ }
158
+
159
+ /**
160
+ * @param {string} source_text
161
+ * @returns {string}
162
+ */
163
+ export function parse_error_report(source_text) {
164
+ let deferred2_0;
165
+ let deferred2_1;
166
+ try {
167
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
168
+ const ptr0 = passStringToWasm0(source_text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
169
+ const len0 = WASM_VECTOR_LEN;
170
+ wasm.parse_error_report(retptr, ptr0, len0);
171
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
172
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
173
+ deferred2_0 = r0;
174
+ deferred2_1 = r1;
175
+ return getStringFromWasm0(r0, r1);
176
+ } finally {
177
+ wasm.__wbindgen_add_to_stack_pointer(16);
178
+ wasm.__wbindgen_export3(deferred2_0, deferred2_1, 1);
179
+ }
180
+ }
181
+ function __wbg_get_imports() {
182
+ const import0 = {
183
+ __proto__: null,
184
+ __wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
185
+ const ret = Error(getStringFromWasm0(arg0, arg1));
186
+ return addHeapObject(ret);
187
+ },
188
+ __wbg_Number_9a4e0ecb0fa16705: function(arg0) {
189
+ const ret = Number(getObject(arg0));
190
+ return ret;
191
+ },
192
+ __wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(arg0) {
193
+ const v = getObject(arg0);
194
+ const ret = typeof(v) === 'boolean' ? v : undefined;
195
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
196
+ },
197
+ __wbg___wbindgen_debug_string_c25d447a39f5578f: function(arg0, arg1) {
198
+ const ret = debugString(getObject(arg1));
199
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
200
+ const len1 = WASM_VECTOR_LEN;
201
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
202
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
203
+ },
204
+ __wbg___wbindgen_in_aca499c5de7ff5e5: function(arg0, arg1) {
205
+ const ret = getObject(arg0) in getObject(arg1);
206
+ return ret;
207
+ },
208
+ __wbg___wbindgen_is_object_a27215656b807791: function(arg0) {
209
+ const val = getObject(arg0);
210
+ const ret = typeof(val) === 'object' && val !== null;
211
+ return ret;
212
+ },
213
+ __wbg___wbindgen_is_string_ea5e6cc2e4141dfe: function(arg0) {
214
+ const ret = typeof(getObject(arg0)) === 'string';
215
+ return ret;
216
+ },
217
+ __wbg___wbindgen_is_undefined_c05833b95a3cf397: function(arg0) {
218
+ const ret = getObject(arg0) === undefined;
219
+ return ret;
220
+ },
221
+ __wbg___wbindgen_jsval_loose_eq_db4c3b15f63fc170: function(arg0, arg1) {
222
+ const ret = getObject(arg0) == getObject(arg1);
223
+ return ret;
224
+ },
225
+ __wbg___wbindgen_number_get_394265ed1e1b84ee: function(arg0, arg1) {
226
+ const obj = getObject(arg1);
227
+ const ret = typeof(obj) === 'number' ? obj : undefined;
228
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
229
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
230
+ },
231
+ __wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
232
+ const obj = getObject(arg1);
233
+ const ret = typeof(obj) === 'string' ? obj : undefined;
234
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
235
+ var len1 = WASM_VECTOR_LEN;
236
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
237
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
238
+ },
239
+ __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
240
+ throw new Error(getStringFromWasm0(arg0, arg1));
241
+ },
242
+ __wbg_entries_015dc610cd81ede0: function(arg0) {
243
+ const ret = Object.entries(getObject(arg0));
244
+ return addHeapObject(ret);
245
+ },
246
+ __wbg_get_507a50627bffa49b: function(arg0, arg1) {
247
+ const ret = getObject(arg0)[arg1 >>> 0];
248
+ return addHeapObject(ret);
249
+ },
250
+ __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
251
+ const ret = getObject(arg0)[getObject(arg1)];
252
+ return addHeapObject(ret);
253
+ },
254
+ __wbg_instanceof_ArrayBuffer_4480b9e0068a8adb: function(arg0) {
255
+ let result;
256
+ try {
257
+ result = getObject(arg0) instanceof ArrayBuffer;
258
+ } catch (_) {
259
+ result = false;
260
+ }
261
+ const ret = result;
262
+ return ret;
263
+ },
264
+ __wbg_instanceof_Uint8Array_309b927aaf7a3fc7: function(arg0) {
265
+ let result;
266
+ try {
267
+ result = getObject(arg0) instanceof Uint8Array;
268
+ } catch (_) {
269
+ result = false;
270
+ }
271
+ const ret = result;
272
+ return ret;
273
+ },
274
+ __wbg_isSafeInteger_04f36e4056f1b851: function(arg0) {
275
+ const ret = Number.isSafeInteger(getObject(arg0));
276
+ return ret;
277
+ },
278
+ __wbg_length_1f0964f4a5e2c6d8: function(arg0) {
279
+ const ret = getObject(arg0).length;
280
+ return ret;
281
+ },
282
+ __wbg_length_370319915dc99107: function(arg0) {
283
+ const ret = getObject(arg0).length;
284
+ return ret;
285
+ },
286
+ __wbg_new_32b398fb48b6d94a: function() {
287
+ const ret = new Array();
288
+ return addHeapObject(ret);
289
+ },
290
+ __wbg_new_cd45aabdf6073e84: function(arg0) {
291
+ const ret = new Uint8Array(getObject(arg0));
292
+ return addHeapObject(ret);
293
+ },
294
+ __wbg_new_da52cf8fe3429cb2: function() {
295
+ const ret = new Object();
296
+ return addHeapObject(ret);
297
+ },
298
+ __wbg_prototypesetcall_4770620bbe4688a0: function(arg0, arg1, arg2) {
299
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
300
+ },
301
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
302
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
303
+ },
304
+ __wbg_set_8a16b38e4805b298: function(arg0, arg1, arg2) {
305
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
306
+ },
307
+ __wbindgen_cast_0000000000000001: function(arg0) {
308
+ // Cast intrinsic for `F64 -> Externref`.
309
+ const ret = arg0;
310
+ return addHeapObject(ret);
311
+ },
312
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
313
+ // Cast intrinsic for `Ref(String) -> Externref`.
314
+ const ret = getStringFromWasm0(arg0, arg1);
315
+ return addHeapObject(ret);
316
+ },
317
+ __wbindgen_cast_0000000000000003: function(arg0) {
318
+ // Cast intrinsic for `U64 -> Externref`.
319
+ const ret = BigInt.asUintN(64, arg0);
320
+ return addHeapObject(ret);
321
+ },
322
+ __wbindgen_object_clone_ref: function(arg0) {
323
+ const ret = getObject(arg0);
324
+ return addHeapObject(ret);
325
+ },
326
+ __wbindgen_object_drop_ref: function(arg0) {
327
+ takeObject(arg0);
328
+ },
329
+ };
330
+ return {
331
+ __proto__: null,
332
+ "./csskit_wasm_bg.js": import0,
333
+ };
334
+ }
335
+
336
+ const SerializableParserResultFinalization = (typeof FinalizationRegistry === 'undefined')
337
+ ? { register: () => {}, unregister: () => {} }
338
+ : new FinalizationRegistry(ptr => wasm.__wbg_serializableparserresult_free(ptr, 1));
339
+
340
+ function addHeapObject(obj) {
341
+ if (heap_next === heap.length) heap.push(heap.length + 1);
342
+ const idx = heap_next;
343
+ heap_next = heap[idx];
344
+
345
+ heap[idx] = obj;
346
+ return idx;
347
+ }
348
+
349
+ function debugString(val) {
350
+ // primitive types
351
+ const type = typeof val;
352
+ if (type == 'number' || type == 'boolean' || val == null) {
353
+ return `${val}`;
354
+ }
355
+ if (type == 'string') {
356
+ return `"${val}"`;
357
+ }
358
+ if (type == 'symbol') {
359
+ const description = val.description;
360
+ if (description == null) {
361
+ return 'Symbol';
362
+ } else {
363
+ return `Symbol(${description})`;
364
+ }
365
+ }
366
+ if (type == 'function') {
367
+ const name = val.name;
368
+ if (typeof name == 'string' && name.length > 0) {
369
+ return `Function(${name})`;
370
+ } else {
371
+ return 'Function';
372
+ }
373
+ }
374
+ // objects
375
+ if (Array.isArray(val)) {
376
+ const length = val.length;
377
+ let debug = '[';
378
+ if (length > 0) {
379
+ debug += debugString(val[0]);
380
+ }
381
+ for(let i = 1; i < length; i++) {
382
+ debug += ', ' + debugString(val[i]);
383
+ }
384
+ debug += ']';
385
+ return debug;
386
+ }
387
+ // Test for built-in
388
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
389
+ let className;
390
+ if (builtInMatches && builtInMatches.length > 1) {
391
+ className = builtInMatches[1];
392
+ } else {
393
+ // Failed to match the standard '[object ClassName]'
394
+ return toString.call(val);
395
+ }
396
+ if (className == 'Object') {
397
+ // we're a user defined class or Object
398
+ // JSON.stringify avoids problems with cycles, and is generally much
399
+ // easier than looping through ownProperties of `val`.
400
+ try {
401
+ return 'Object(' + JSON.stringify(val) + ')';
402
+ } catch (_) {
403
+ return 'Object';
404
+ }
405
+ }
406
+ // errors
407
+ if (val instanceof Error) {
408
+ return `${val.name}: ${val.message}\n${val.stack}`;
409
+ }
410
+ // TODO we could test for more things here, like `Set`s and `Map`s.
411
+ return className;
412
+ }
413
+
414
+ function dropObject(idx) {
415
+ if (idx < 1028) return;
416
+ heap[idx] = heap_next;
417
+ heap_next = idx;
418
+ }
419
+
420
+ function getArrayJsValueFromWasm0(ptr, len) {
421
+ ptr = ptr >>> 0;
422
+ const mem = getDataViewMemory0();
423
+ const result = [];
424
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
425
+ result.push(takeObject(mem.getUint32(i, true)));
426
+ }
427
+ return result;
428
+ }
429
+
430
+ function getArrayU8FromWasm0(ptr, len) {
431
+ ptr = ptr >>> 0;
432
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
433
+ }
434
+
435
+ let cachedDataViewMemory0 = null;
436
+ function getDataViewMemory0() {
437
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
438
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
439
+ }
440
+ return cachedDataViewMemory0;
441
+ }
442
+
443
+ function getStringFromWasm0(ptr, len) {
444
+ return decodeText(ptr >>> 0, len);
445
+ }
446
+
447
+ let cachedUint8ArrayMemory0 = null;
448
+ function getUint8ArrayMemory0() {
449
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
450
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
451
+ }
452
+ return cachedUint8ArrayMemory0;
453
+ }
454
+
455
+ function getObject(idx) { return heap[idx]; }
456
+
457
+ let heap = new Array(1024).fill(undefined);
458
+ heap.push(undefined, null, true, false);
459
+
460
+ let heap_next = heap.length;
461
+
462
+ function isLikeNone(x) {
463
+ return x === undefined || x === null;
464
+ }
465
+
466
+ function passStringToWasm0(arg, malloc, realloc) {
467
+ if (realloc === undefined) {
468
+ const buf = cachedTextEncoder.encode(arg);
469
+ const ptr = malloc(buf.length, 1) >>> 0;
470
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
471
+ WASM_VECTOR_LEN = buf.length;
472
+ return ptr;
473
+ }
474
+
475
+ let len = arg.length;
476
+ let ptr = malloc(len, 1) >>> 0;
477
+
478
+ const mem = getUint8ArrayMemory0();
479
+
480
+ let offset = 0;
481
+
482
+ for (; offset < len; offset++) {
483
+ const code = arg.charCodeAt(offset);
484
+ if (code > 0x7F) break;
485
+ mem[ptr + offset] = code;
486
+ }
487
+ if (offset !== len) {
488
+ if (offset !== 0) {
489
+ arg = arg.slice(offset);
490
+ }
491
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
492
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
493
+ const ret = cachedTextEncoder.encodeInto(arg, view);
494
+
495
+ offset += ret.written;
496
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
497
+ }
498
+
499
+ WASM_VECTOR_LEN = offset;
500
+ return ptr;
501
+ }
502
+
503
+ function takeObject(idx) {
504
+ const ret = getObject(idx);
505
+ dropObject(idx);
506
+ return ret;
507
+ }
508
+
509
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
510
+ cachedTextDecoder.decode();
511
+ function decodeText(ptr, len) {
512
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
513
+ }
514
+
515
+ const cachedTextEncoder = new TextEncoder();
516
+
517
+ if (!('encodeInto' in cachedTextEncoder)) {
518
+ cachedTextEncoder.encodeInto = function (arg, view) {
519
+ const buf = cachedTextEncoder.encode(arg);
520
+ view.set(buf);
521
+ return {
522
+ read: arg.length,
523
+ written: buf.length
524
+ };
525
+ };
526
+ }
527
+
528
+ let WASM_VECTOR_LEN = 0;
529
+
530
+ const wasmUrl = new URL('csskit_wasm_bg.wasm', import.meta.url);
531
+ const wasmBytes = readFileSync(wasmUrl);
532
+ const wasmModule = new WebAssembly.Module(wasmBytes);
533
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
534
+ let wasm = wasmInstance.exports;
535
+ wasm.__wbindgen_start();
package/bundle.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ // Type definitions for the WebAssembly entry (`csskit/bundle`).
2
+
3
+ /** A parse diagnostic produced by the wasm backend. */
4
+ export interface Diagnostic {
5
+ from: number;
6
+ to: number;
7
+ severity: string;
8
+ code: string;
9
+ message: string;
10
+ help: string;
11
+ }
12
+
13
+ /** Result of a wasm parse: a serialised AST plus diagnostics. */
14
+ export interface ParserResult {
15
+ ast: unknown;
16
+ diagnostics: Diagnostic[];
17
+ }
18
+
19
+ /** Parse `source` into a serialised AST plus diagnostics. */
20
+ export declare function parse(source: string): ParserResult;
21
+
22
+ /** Tokenise `source`. */
23
+ export declare function lex(source: string): unknown;
24
+
25
+ /** Minify `source`. */
26
+ export declare function minify(source: string): string;
27
+
28
+ /** Format `source` with the given options. */
29
+ export declare function format(source: string, options?: unknown): string;
30
+
31
+ /** Render a human-readable parse-error report for `source`. */
32
+ export declare function parseErrorReport(source: string): string;
package/bundle.js ADDED
@@ -0,0 +1,13 @@
1
+ // The WebAssembly build of csskit: lex, minify, format and parse-error reports.
2
+ //
3
+ // This entry needs no native addon, thus it runs where wasm runs. It has no object model: `parse`
4
+ // gives a serialised AST and diagnostics. For the object model use the `csskit` entry.
5
+
6
+ import { parse_error_report } from './bundle/csskit_wasm_node.js';
7
+
8
+ export { format, lex, minify, parse } from './bundle/csskit_wasm_node.js';
9
+
10
+ /** Render a human-readable parse-error report for `source`. */
11
+ export function parseErrorReport(source) {
12
+ return parse_error_report(source);
13
+ }