@kbach/core-engine 1.0.0-beta.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/README.md +28 -0
- package/dist/README.md +28 -0
- package/dist/kbach_core_engine.d.ts +50 -0
- package/dist/kbach_core_engine.js +239 -0
- package/dist/kbach_core_engine_bg.wasm +0 -0
- package/dist/kbach_core_engine_bg.wasm.d.ts +10 -0
- package/dist/package.json +16 -0
- package/dist-node/README.md +28 -0
- package/dist-node/kbach_core_engine.d.ts +15 -0
- package/dist-node/kbach_core_engine.js +143 -0
- package/dist-node/kbach_core_engine_bg.wasm +0 -0
- package/dist-node/kbach_core_engine_bg.wasm.d.ts +10 -0
- package/dist-node/package.json +12 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @kbach/core-engine
|
|
2
|
+
|
|
3
|
+
The Rust/WASM utility-resolution engine that powers
|
|
4
|
+
[`@kbach/react`](https://www.npmjs.com/package/@kbach/react).
|
|
5
|
+
|
|
6
|
+
> **Beta.** This package is an internal dependency of `@kbach/react` and
|
|
7
|
+
> `@kbach/react-native`. If you're building a React app, install
|
|
8
|
+
> `@kbach/react` instead — it re-exports everything you need and pulls this
|
|
9
|
+
> package in automatically.
|
|
10
|
+
|
|
11
|
+
## What this is
|
|
12
|
+
|
|
13
|
+
Given a class string (e.g. `"flex items-center bg-blue-6"`) and a theme
|
|
14
|
+
definition, this package resolves it to real CSS rules — the same logic runs
|
|
15
|
+
both at build time (Node target, used by the Vite plugin to generate a
|
|
16
|
+
static `kbach.css`) and at runtime in the browser (web target, used for
|
|
17
|
+
dynamic/runtime class resolution), so the two can never disagree about what
|
|
18
|
+
a class name means.
|
|
19
|
+
|
|
20
|
+
Two builds are published:
|
|
21
|
+
|
|
22
|
+
- `@kbach/core-engine` — the browser (`--target web`) build, async `init()`.
|
|
23
|
+
- `@kbach/core-engine/node` — the Node.js (`--target nodejs`) build, used by
|
|
24
|
+
build tooling; synchronous, no `init()` required.
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
MIT
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @kbach/core-engine
|
|
2
|
+
|
|
3
|
+
The Rust/WASM utility-resolution engine that powers
|
|
4
|
+
[`@kbach/react`](https://www.npmjs.com/package/@kbach/react).
|
|
5
|
+
|
|
6
|
+
> **Beta.** This package is an internal dependency of `@kbach/react` and
|
|
7
|
+
> `@kbach/react-native`. If you're building a React app, install
|
|
8
|
+
> `@kbach/react` instead — it re-exports everything you need and pulls this
|
|
9
|
+
> package in automatically.
|
|
10
|
+
|
|
11
|
+
## What this is
|
|
12
|
+
|
|
13
|
+
Given a class string (e.g. `"flex items-center bg-blue-6"`) and a theme
|
|
14
|
+
definition, this package resolves it to real CSS rules — the same logic runs
|
|
15
|
+
both at build time (Node target, used by the Vite plugin to generate a
|
|
16
|
+
static `kbach.css`) and at runtime in the browser (web target, used for
|
|
17
|
+
dynamic/runtime class resolution), so the two can never disagree about what
|
|
18
|
+
a class name means.
|
|
19
|
+
|
|
20
|
+
Two builds are published:
|
|
21
|
+
|
|
22
|
+
- `@kbach/core-engine` — the browser (`--target web`) build, async `init()`.
|
|
23
|
+
- `@kbach/core-engine/node` — the Node.js (`--target nodejs`) build, used by
|
|
24
|
+
build tooling; synchronous, no `init()` required.
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
MIT
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Serializes `theme::DEFAULT_COLORS` (Phase 16) to a flat JSON object —
|
|
6
|
+
* consumed at build time (not runtime; see that const's own doc comment)
|
|
7
|
+
* by `scripts/generate-palette.mjs` via the Node-target build of this
|
|
8
|
+
* same `#[wasm_bindgen]` export, which is what makes this usable without
|
|
9
|
+
* an async init step. `BTreeMap` (alphabetical key order) rather than
|
|
10
|
+
* `DEFAULT_COLORS`'s own family-grouped order — fine for a generated
|
|
11
|
+
* file nobody hand-edits, and deterministic across regenerations either way.
|
|
12
|
+
*/
|
|
13
|
+
export function default_colors_json(): string;
|
|
14
|
+
|
|
15
|
+
export function generate_css(class_string: string, theme_json: string): string;
|
|
16
|
+
|
|
17
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
18
|
+
|
|
19
|
+
export interface InitOutput {
|
|
20
|
+
readonly memory: WebAssembly.Memory;
|
|
21
|
+
readonly default_colors_json: () => [number, number];
|
|
22
|
+
readonly generate_css: (a: number, b: number, c: number, d: number) => [number, number];
|
|
23
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
24
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
25
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
26
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
27
|
+
readonly __wbindgen_start: () => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
34
|
+
* a precompiled `WebAssembly.Module`.
|
|
35
|
+
*
|
|
36
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
37
|
+
*
|
|
38
|
+
* @returns {InitOutput}
|
|
39
|
+
*/
|
|
40
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
44
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
45
|
+
*
|
|
46
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
47
|
+
*
|
|
48
|
+
* @returns {Promise<InitOutput>}
|
|
49
|
+
*/
|
|
50
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/* @ts-self-types="./kbach_core_engine.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Serializes `theme::DEFAULT_COLORS` (Phase 16) to a flat JSON object —
|
|
5
|
+
* consumed at build time (not runtime; see that const's own doc comment)
|
|
6
|
+
* by `scripts/generate-palette.mjs` via the Node-target build of this
|
|
7
|
+
* same `#[wasm_bindgen]` export, which is what makes this usable without
|
|
8
|
+
* an async init step. `BTreeMap` (alphabetical key order) rather than
|
|
9
|
+
* `DEFAULT_COLORS`'s own family-grouped order — fine for a generated
|
|
10
|
+
* file nobody hand-edits, and deterministic across regenerations either way.
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
export function default_colors_json() {
|
|
14
|
+
let deferred1_0;
|
|
15
|
+
let deferred1_1;
|
|
16
|
+
try {
|
|
17
|
+
const ret = wasm.default_colors_json();
|
|
18
|
+
deferred1_0 = ret[0];
|
|
19
|
+
deferred1_1 = ret[1];
|
|
20
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
21
|
+
} finally {
|
|
22
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} class_string
|
|
28
|
+
* @param {string} theme_json
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
31
|
+
export function generate_css(class_string, theme_json) {
|
|
32
|
+
let deferred3_0;
|
|
33
|
+
let deferred3_1;
|
|
34
|
+
try {
|
|
35
|
+
const ptr0 = passStringToWasm0(class_string, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
36
|
+
const len0 = WASM_VECTOR_LEN;
|
|
37
|
+
const ptr1 = passStringToWasm0(theme_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
38
|
+
const len1 = WASM_VECTOR_LEN;
|
|
39
|
+
const ret = wasm.generate_css(ptr0, len0, ptr1, len1);
|
|
40
|
+
deferred3_0 = ret[0];
|
|
41
|
+
deferred3_1 = ret[1];
|
|
42
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
43
|
+
} finally {
|
|
44
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function __wbg_get_imports() {
|
|
48
|
+
const import0 = {
|
|
49
|
+
__proto__: null,
|
|
50
|
+
__wbindgen_init_externref_table: function() {
|
|
51
|
+
const table = wasm.__wbindgen_externrefs;
|
|
52
|
+
const offset = table.grow(4);
|
|
53
|
+
table.set(0, undefined);
|
|
54
|
+
table.set(offset + 0, undefined);
|
|
55
|
+
table.set(offset + 1, null);
|
|
56
|
+
table.set(offset + 2, true);
|
|
57
|
+
table.set(offset + 3, false);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
__proto__: null,
|
|
62
|
+
"./kbach_core_engine_bg.js": import0,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getStringFromWasm0(ptr, len) {
|
|
67
|
+
return decodeText(ptr >>> 0, len);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let cachedUint8ArrayMemory0 = null;
|
|
71
|
+
function getUint8ArrayMemory0() {
|
|
72
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
73
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
74
|
+
}
|
|
75
|
+
return cachedUint8ArrayMemory0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
79
|
+
if (realloc === undefined) {
|
|
80
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
81
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
82
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
83
|
+
WASM_VECTOR_LEN = buf.length;
|
|
84
|
+
return ptr;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let len = arg.length;
|
|
88
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
89
|
+
|
|
90
|
+
const mem = getUint8ArrayMemory0();
|
|
91
|
+
|
|
92
|
+
let offset = 0;
|
|
93
|
+
|
|
94
|
+
for (; offset < len; offset++) {
|
|
95
|
+
const code = arg.charCodeAt(offset);
|
|
96
|
+
if (code > 0x7F) break;
|
|
97
|
+
mem[ptr + offset] = code;
|
|
98
|
+
}
|
|
99
|
+
if (offset !== len) {
|
|
100
|
+
if (offset !== 0) {
|
|
101
|
+
arg = arg.slice(offset);
|
|
102
|
+
}
|
|
103
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
104
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
105
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
106
|
+
|
|
107
|
+
offset += ret.written;
|
|
108
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
WASM_VECTOR_LEN = offset;
|
|
112
|
+
return ptr;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
116
|
+
cachedTextDecoder.decode();
|
|
117
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
118
|
+
let numBytesDecoded = 0;
|
|
119
|
+
function decodeText(ptr, len) {
|
|
120
|
+
numBytesDecoded += len;
|
|
121
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
122
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
123
|
+
cachedTextDecoder.decode();
|
|
124
|
+
numBytesDecoded = len;
|
|
125
|
+
}
|
|
126
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const cachedTextEncoder = new TextEncoder();
|
|
130
|
+
|
|
131
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
132
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
133
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
134
|
+
view.set(buf);
|
|
135
|
+
return {
|
|
136
|
+
read: arg.length,
|
|
137
|
+
written: buf.length
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let WASM_VECTOR_LEN = 0;
|
|
143
|
+
|
|
144
|
+
let wasmModule, wasmInstance, wasm;
|
|
145
|
+
function __wbg_finalize_init(instance, module) {
|
|
146
|
+
wasmInstance = instance;
|
|
147
|
+
wasm = instance.exports;
|
|
148
|
+
wasmModule = module;
|
|
149
|
+
cachedUint8ArrayMemory0 = null;
|
|
150
|
+
wasm.__wbindgen_start();
|
|
151
|
+
return wasm;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function __wbg_load(module, imports) {
|
|
155
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
156
|
+
if (!module.ok) {
|
|
157
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
161
|
+
try {
|
|
162
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
163
|
+
} catch (e) {
|
|
164
|
+
const validResponse = expectedResponseType(module.type);
|
|
165
|
+
|
|
166
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
167
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
168
|
+
|
|
169
|
+
} else { throw e; }
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const bytes = await module.arrayBuffer();
|
|
174
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
175
|
+
} else {
|
|
176
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
177
|
+
|
|
178
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
179
|
+
return { instance, module };
|
|
180
|
+
} else {
|
|
181
|
+
return instance;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function expectedResponseType(type) {
|
|
186
|
+
switch (type) {
|
|
187
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function initSync(module) {
|
|
194
|
+
if (wasm !== undefined) return wasm;
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
if (module !== undefined) {
|
|
198
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
199
|
+
({module} = module)
|
|
200
|
+
} else {
|
|
201
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const imports = __wbg_get_imports();
|
|
206
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
207
|
+
module = new WebAssembly.Module(module);
|
|
208
|
+
}
|
|
209
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
210
|
+
return __wbg_finalize_init(instance, module);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async function __wbg_init(module_or_path) {
|
|
214
|
+
if (wasm !== undefined) return wasm;
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
if (module_or_path !== undefined) {
|
|
218
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
219
|
+
({module_or_path} = module_or_path)
|
|
220
|
+
} else {
|
|
221
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (module_or_path === undefined) {
|
|
226
|
+
module_or_path = new URL('kbach_core_engine_bg.wasm', import.meta.url);
|
|
227
|
+
}
|
|
228
|
+
const imports = __wbg_get_imports();
|
|
229
|
+
|
|
230
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
231
|
+
module_or_path = fetch(module_or_path);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
235
|
+
|
|
236
|
+
return __wbg_finalize_init(instance, module);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const default_colors_json: () => [number, number];
|
|
5
|
+
export const generate_css: (a: number, b: number, c: number, d: number) => [number, number];
|
|
6
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
7
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
8
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
9
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
10
|
+
export const __wbindgen_start: () => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kbach-core-engine",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"kbach_core_engine_bg.wasm",
|
|
8
|
+
"kbach_core_engine.js",
|
|
9
|
+
"kbach_core_engine.d.ts"
|
|
10
|
+
],
|
|
11
|
+
"main": "kbach_core_engine.js",
|
|
12
|
+
"types": "kbach_core_engine.d.ts",
|
|
13
|
+
"sideEffects": [
|
|
14
|
+
"./snippets/*"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @kbach/core-engine
|
|
2
|
+
|
|
3
|
+
The Rust/WASM utility-resolution engine that powers
|
|
4
|
+
[`@kbach/react`](https://www.npmjs.com/package/@kbach/react).
|
|
5
|
+
|
|
6
|
+
> **Beta.** This package is an internal dependency of `@kbach/react` and
|
|
7
|
+
> `@kbach/react-native`. If you're building a React app, install
|
|
8
|
+
> `@kbach/react` instead — it re-exports everything you need and pulls this
|
|
9
|
+
> package in automatically.
|
|
10
|
+
|
|
11
|
+
## What this is
|
|
12
|
+
|
|
13
|
+
Given a class string (e.g. `"flex items-center bg-blue-6"`) and a theme
|
|
14
|
+
definition, this package resolves it to real CSS rules — the same logic runs
|
|
15
|
+
both at build time (Node target, used by the Vite plugin to generate a
|
|
16
|
+
static `kbach.css`) and at runtime in the browser (web target, used for
|
|
17
|
+
dynamic/runtime class resolution), so the two can never disagree about what
|
|
18
|
+
a class name means.
|
|
19
|
+
|
|
20
|
+
Two builds are published:
|
|
21
|
+
|
|
22
|
+
- `@kbach/core-engine` — the browser (`--target web`) build, async `init()`.
|
|
23
|
+
- `@kbach/core-engine/node` — the Node.js (`--target nodejs`) build, used by
|
|
24
|
+
build tooling; synchronous, no `init()` required.
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Serializes `theme::DEFAULT_COLORS` (Phase 16) to a flat JSON object —
|
|
6
|
+
* consumed at build time (not runtime; see that const's own doc comment)
|
|
7
|
+
* by `scripts/generate-palette.mjs` via the Node-target build of this
|
|
8
|
+
* same `#[wasm_bindgen]` export, which is what makes this usable without
|
|
9
|
+
* an async init step. `BTreeMap` (alphabetical key order) rather than
|
|
10
|
+
* `DEFAULT_COLORS`'s own family-grouped order — fine for a generated
|
|
11
|
+
* file nobody hand-edits, and deterministic across regenerations either way.
|
|
12
|
+
*/
|
|
13
|
+
export function default_colors_json(): string;
|
|
14
|
+
|
|
15
|
+
export function generate_css(class_string: string, theme_json: string): string;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/* @ts-self-types="./kbach_core_engine.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Serializes `theme::DEFAULT_COLORS` (Phase 16) to a flat JSON object —
|
|
5
|
+
* consumed at build time (not runtime; see that const's own doc comment)
|
|
6
|
+
* by `scripts/generate-palette.mjs` via the Node-target build of this
|
|
7
|
+
* same `#[wasm_bindgen]` export, which is what makes this usable without
|
|
8
|
+
* an async init step. `BTreeMap` (alphabetical key order) rather than
|
|
9
|
+
* `DEFAULT_COLORS`'s own family-grouped order — fine for a generated
|
|
10
|
+
* file nobody hand-edits, and deterministic across regenerations either way.
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
function default_colors_json() {
|
|
14
|
+
let deferred1_0;
|
|
15
|
+
let deferred1_1;
|
|
16
|
+
try {
|
|
17
|
+
const ret = wasm.default_colors_json();
|
|
18
|
+
deferred1_0 = ret[0];
|
|
19
|
+
deferred1_1 = ret[1];
|
|
20
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
21
|
+
} finally {
|
|
22
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.default_colors_json = default_colors_json;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} class_string
|
|
29
|
+
* @param {string} theme_json
|
|
30
|
+
* @returns {string}
|
|
31
|
+
*/
|
|
32
|
+
function generate_css(class_string, theme_json) {
|
|
33
|
+
let deferred3_0;
|
|
34
|
+
let deferred3_1;
|
|
35
|
+
try {
|
|
36
|
+
const ptr0 = passStringToWasm0(class_string, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
37
|
+
const len0 = WASM_VECTOR_LEN;
|
|
38
|
+
const ptr1 = passStringToWasm0(theme_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
39
|
+
const len1 = WASM_VECTOR_LEN;
|
|
40
|
+
const ret = wasm.generate_css(ptr0, len0, ptr1, len1);
|
|
41
|
+
deferred3_0 = ret[0];
|
|
42
|
+
deferred3_1 = ret[1];
|
|
43
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
44
|
+
} finally {
|
|
45
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.generate_css = generate_css;
|
|
49
|
+
function __wbg_get_imports() {
|
|
50
|
+
const import0 = {
|
|
51
|
+
__proto__: null,
|
|
52
|
+
__wbindgen_init_externref_table: function() {
|
|
53
|
+
const table = wasm.__wbindgen_externrefs;
|
|
54
|
+
const offset = table.grow(4);
|
|
55
|
+
table.set(0, undefined);
|
|
56
|
+
table.set(offset + 0, undefined);
|
|
57
|
+
table.set(offset + 1, null);
|
|
58
|
+
table.set(offset + 2, true);
|
|
59
|
+
table.set(offset + 3, false);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
__proto__: null,
|
|
64
|
+
"./kbach_core_engine_bg.js": import0,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getStringFromWasm0(ptr, len) {
|
|
69
|
+
return decodeText(ptr >>> 0, len);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let cachedUint8ArrayMemory0 = null;
|
|
73
|
+
function getUint8ArrayMemory0() {
|
|
74
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
75
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
76
|
+
}
|
|
77
|
+
return cachedUint8ArrayMemory0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
81
|
+
if (realloc === undefined) {
|
|
82
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
83
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
84
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
85
|
+
WASM_VECTOR_LEN = buf.length;
|
|
86
|
+
return ptr;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let len = arg.length;
|
|
90
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
91
|
+
|
|
92
|
+
const mem = getUint8ArrayMemory0();
|
|
93
|
+
|
|
94
|
+
let offset = 0;
|
|
95
|
+
|
|
96
|
+
for (; offset < len; offset++) {
|
|
97
|
+
const code = arg.charCodeAt(offset);
|
|
98
|
+
if (code > 0x7F) break;
|
|
99
|
+
mem[ptr + offset] = code;
|
|
100
|
+
}
|
|
101
|
+
if (offset !== len) {
|
|
102
|
+
if (offset !== 0) {
|
|
103
|
+
arg = arg.slice(offset);
|
|
104
|
+
}
|
|
105
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
106
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
107
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
108
|
+
|
|
109
|
+
offset += ret.written;
|
|
110
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
WASM_VECTOR_LEN = offset;
|
|
114
|
+
return ptr;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
118
|
+
cachedTextDecoder.decode();
|
|
119
|
+
function decodeText(ptr, len) {
|
|
120
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const cachedTextEncoder = new TextEncoder();
|
|
124
|
+
|
|
125
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
126
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
127
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
128
|
+
view.set(buf);
|
|
129
|
+
return {
|
|
130
|
+
read: arg.length,
|
|
131
|
+
written: buf.length
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let WASM_VECTOR_LEN = 0;
|
|
137
|
+
|
|
138
|
+
const wasmPath = `${__dirname}/kbach_core_engine_bg.wasm`;
|
|
139
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
140
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
141
|
+
let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
|
|
142
|
+
let wasm = wasmInstance.exports;
|
|
143
|
+
wasm.__wbindgen_start();
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const default_colors_json: () => [number, number];
|
|
5
|
+
export const generate_css: (a: number, b: number, c: number, d: number) => [number, number];
|
|
6
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
7
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
8
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
9
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
10
|
+
export const __wbindgen_start: () => void;
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kbach/core-engine",
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
|
+
"description": "Rust/WASM utility-class resolution engine powering @kbach/react and @kbach/react-native.",
|
|
5
|
+
"keywords": ["css", "wasm", "rust", "tailwind", "utility-first", "styling"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "semsakadanupol",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/semsakadanupol/kbach.git",
|
|
11
|
+
"directory": "packages/core-engine"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/semsakadanupol/kbach#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/semsakadanupol/kbach/issues"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./dist/kbach_core_engine.js",
|
|
22
|
+
"types": "./dist/kbach_core_engine.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/kbach_core_engine.d.ts",
|
|
26
|
+
"default": "./dist/kbach_core_engine.js"
|
|
27
|
+
},
|
|
28
|
+
"./node": {
|
|
29
|
+
"types": "./dist-node/kbach_core_engine.d.ts",
|
|
30
|
+
"default": "./dist-node/kbach_core_engine.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": ["dist", "dist-node"],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "wasm-pack build --target web --out-dir dist && wasm-pack build --target nodejs --out-dir dist-node && node -e \"require('fs').rmSync('dist/.gitignore',{force:true});require('fs').rmSync('dist-node/.gitignore',{force:true})\"",
|
|
36
|
+
"test": "cargo test",
|
|
37
|
+
"lint": "cargo check",
|
|
38
|
+
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true});require('fs').rmSync('dist-node',{recursive:true,force:true});require('fs').rmSync('target',{recursive:true,force:true})\""
|
|
39
|
+
}
|
|
40
|
+
}
|