@neuralfog/elemix-compiler-wasm 0.0.0-dev.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 brownhounds
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # ⚙️ Elemix Compiler ⚠️ **Experimental**
2
+
3
+ The compiler that makes Elemix compile-only.
4
+
5
+ This is a personal project built for my own use. It is not open source and comes with no guarantees, warranties, or support.
6
+
7
+ ## Why?
8
+
9
+ Because the runtime should do as little as possible. Elemix components are authored with `tpl` tagged-template views — this compiler lowers them ahead of time so nothing parses, walks, or diffs a template in the browser.
10
+
11
+ ## What it does
12
+
13
+ Written in Rust on the [oxc](https://oxc.rs) parser. It rewrites each component's `tpl` template into a `view()` that builds the DOM directly and wires it to the runtime primitives — no template interpreter ships. Directives (`repeat`, `when`, `choose`) are erased at compile time, and the output imports only the primitives it uses.
14
+
15
+ ## Usage
16
+
17
+ Installed via npm, the compiler exposes two equivalent commands — `ec` (short) and `elemix-compiler`:
18
+
19
+ ```sh
20
+ ec --dirs <dir|glob>... --out <dir>
21
+ ec --file <path>
22
+ ```
@@ -0,0 +1,48 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Compile one source string of elemix components into its compiled `.ts` form.
6
+ */
7
+ export function compile(source: string): string;
8
+
9
+ /**
10
+ * Surface panics as catchable JS errors instead of an unrecoverable wasm abort
11
+ * — the playground feeds half-typed input on every keystroke. Runs on init.
12
+ */
13
+ export function start(): void;
14
+
15
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
16
+
17
+ export interface InitOutput {
18
+ readonly memory: WebAssembly.Memory;
19
+ readonly compile: (a: number, b: number) => [number, number];
20
+ readonly start: () => void;
21
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
22
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
23
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
24
+ readonly __wbindgen_externrefs: WebAssembly.Table;
25
+ readonly __wbindgen_start: () => void;
26
+ }
27
+
28
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
29
+
30
+ /**
31
+ * Instantiates the given `module`, which can either be bytes or
32
+ * a precompiled `WebAssembly.Module`.
33
+ *
34
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
35
+ *
36
+ * @returns {InitOutput}
37
+ */
38
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
39
+
40
+ /**
41
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
42
+ * for everything else, calls `WebAssembly.instantiate` directly.
43
+ *
44
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
45
+ *
46
+ * @returns {Promise<InitOutput>}
47
+ */
48
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,249 @@
1
+ /* @ts-self-types="./elemix_compiler.d.ts" */
2
+
3
+ /**
4
+ * Compile one source string of elemix components into its compiled `.ts` form.
5
+ * @param {string} source
6
+ * @returns {string}
7
+ */
8
+ export function compile(source) {
9
+ let deferred2_0;
10
+ let deferred2_1;
11
+ try {
12
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
13
+ const len0 = WASM_VECTOR_LEN;
14
+ const ret = wasm.compile(ptr0, len0);
15
+ deferred2_0 = ret[0];
16
+ deferred2_1 = ret[1];
17
+ return getStringFromWasm0(ret[0], ret[1]);
18
+ } finally {
19
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Surface panics as catchable JS errors instead of an unrecoverable wasm abort
25
+ * — the playground feeds half-typed input on every keystroke. Runs on init.
26
+ */
27
+ export function start() {
28
+ wasm.start();
29
+ }
30
+ function __wbg_get_imports() {
31
+ const import0 = {
32
+ __proto__: null,
33
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
34
+ let deferred0_0;
35
+ let deferred0_1;
36
+ try {
37
+ deferred0_0 = arg0;
38
+ deferred0_1 = arg1;
39
+ console.error(getStringFromWasm0(arg0, arg1));
40
+ } finally {
41
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
42
+ }
43
+ },
44
+ __wbg_new_227d7c05414eb861: function() {
45
+ const ret = new Error();
46
+ return ret;
47
+ },
48
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
49
+ const ret = arg1.stack;
50
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
51
+ const len1 = WASM_VECTOR_LEN;
52
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
53
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
54
+ },
55
+ __wbindgen_init_externref_table: function() {
56
+ const table = wasm.__wbindgen_externrefs;
57
+ const offset = table.grow(4);
58
+ table.set(0, undefined);
59
+ table.set(offset + 0, undefined);
60
+ table.set(offset + 1, null);
61
+ table.set(offset + 2, true);
62
+ table.set(offset + 3, false);
63
+ },
64
+ };
65
+ return {
66
+ __proto__: null,
67
+ "./elemix_compiler_bg.js": import0,
68
+ };
69
+ }
70
+
71
+ let cachedDataViewMemory0 = null;
72
+ function getDataViewMemory0() {
73
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
74
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
75
+ }
76
+ return cachedDataViewMemory0;
77
+ }
78
+
79
+ function getStringFromWasm0(ptr, len) {
80
+ return decodeText(ptr >>> 0, len);
81
+ }
82
+
83
+ let cachedUint8ArrayMemory0 = null;
84
+ function getUint8ArrayMemory0() {
85
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
86
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
87
+ }
88
+ return cachedUint8ArrayMemory0;
89
+ }
90
+
91
+ function passStringToWasm0(arg, malloc, realloc) {
92
+ if (realloc === undefined) {
93
+ const buf = cachedTextEncoder.encode(arg);
94
+ const ptr = malloc(buf.length, 1) >>> 0;
95
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
96
+ WASM_VECTOR_LEN = buf.length;
97
+ return ptr;
98
+ }
99
+
100
+ let len = arg.length;
101
+ let ptr = malloc(len, 1) >>> 0;
102
+
103
+ const mem = getUint8ArrayMemory0();
104
+
105
+ let offset = 0;
106
+
107
+ for (; offset < len; offset++) {
108
+ const code = arg.charCodeAt(offset);
109
+ if (code > 0x7F) break;
110
+ mem[ptr + offset] = code;
111
+ }
112
+ if (offset !== len) {
113
+ if (offset !== 0) {
114
+ arg = arg.slice(offset);
115
+ }
116
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
117
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
118
+ const ret = cachedTextEncoder.encodeInto(arg, view);
119
+
120
+ offset += ret.written;
121
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
122
+ }
123
+
124
+ WASM_VECTOR_LEN = offset;
125
+ return ptr;
126
+ }
127
+
128
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
129
+ cachedTextDecoder.decode();
130
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
131
+ let numBytesDecoded = 0;
132
+ function decodeText(ptr, len) {
133
+ numBytesDecoded += len;
134
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
135
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
136
+ cachedTextDecoder.decode();
137
+ numBytesDecoded = len;
138
+ }
139
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
140
+ }
141
+
142
+ const cachedTextEncoder = new TextEncoder();
143
+
144
+ if (!('encodeInto' in cachedTextEncoder)) {
145
+ cachedTextEncoder.encodeInto = function (arg, view) {
146
+ const buf = cachedTextEncoder.encode(arg);
147
+ view.set(buf);
148
+ return {
149
+ read: arg.length,
150
+ written: buf.length
151
+ };
152
+ };
153
+ }
154
+
155
+ let WASM_VECTOR_LEN = 0;
156
+
157
+ let wasmModule, wasmInstance, wasm;
158
+ function __wbg_finalize_init(instance, module) {
159
+ wasmInstance = instance;
160
+ wasm = instance.exports;
161
+ wasmModule = module;
162
+ cachedDataViewMemory0 = null;
163
+ cachedUint8ArrayMemory0 = null;
164
+ wasm.__wbindgen_start();
165
+ return wasm;
166
+ }
167
+
168
+ async function __wbg_load(module, imports) {
169
+ if (typeof Response === 'function' && module instanceof Response) {
170
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
171
+ try {
172
+ return await WebAssembly.instantiateStreaming(module, imports);
173
+ } catch (e) {
174
+ const validResponse = module.ok && expectedResponseType(module.type);
175
+
176
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
177
+ 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);
178
+
179
+ } else { throw e; }
180
+ }
181
+ }
182
+
183
+ const bytes = await module.arrayBuffer();
184
+ return await WebAssembly.instantiate(bytes, imports);
185
+ } else {
186
+ const instance = await WebAssembly.instantiate(module, imports);
187
+
188
+ if (instance instanceof WebAssembly.Instance) {
189
+ return { instance, module };
190
+ } else {
191
+ return instance;
192
+ }
193
+ }
194
+
195
+ function expectedResponseType(type) {
196
+ switch (type) {
197
+ case 'basic': case 'cors': case 'default': return true;
198
+ }
199
+ return false;
200
+ }
201
+ }
202
+
203
+ function initSync(module) {
204
+ if (wasm !== undefined) return wasm;
205
+
206
+
207
+ if (module !== undefined) {
208
+ if (Object.getPrototypeOf(module) === Object.prototype) {
209
+ ({module} = module)
210
+ } else {
211
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
212
+ }
213
+ }
214
+
215
+ const imports = __wbg_get_imports();
216
+ if (!(module instanceof WebAssembly.Module)) {
217
+ module = new WebAssembly.Module(module);
218
+ }
219
+ const instance = new WebAssembly.Instance(module, imports);
220
+ return __wbg_finalize_init(instance, module);
221
+ }
222
+
223
+ async function __wbg_init(module_or_path) {
224
+ if (wasm !== undefined) return wasm;
225
+
226
+
227
+ if (module_or_path !== undefined) {
228
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
229
+ ({module_or_path} = module_or_path)
230
+ } else {
231
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
232
+ }
233
+ }
234
+
235
+ if (module_or_path === undefined) {
236
+ module_or_path = new URL('elemix_compiler_bg.wasm', import.meta.url);
237
+ }
238
+ const imports = __wbg_get_imports();
239
+
240
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
241
+ module_or_path = fetch(module_or_path);
242
+ }
243
+
244
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
245
+
246
+ return __wbg_finalize_init(instance, module);
247
+ }
248
+
249
+ export { initSync, __wbg_init as default };
Binary file
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@neuralfog/elemix-compiler-wasm",
3
+ "type": "module",
4
+ "description": "Ahead-of-time compiler for Elemix tpl templates.",
5
+ "version": "0.0.0-dev.2",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/neuralfog/elemix"
10
+ },
11
+ "files": [
12
+ "elemix_compiler_bg.wasm",
13
+ "elemix_compiler.js",
14
+ "elemix_compiler.d.ts"
15
+ ],
16
+ "main": "elemix_compiler.js",
17
+ "types": "elemix_compiler.d.ts",
18
+ "sideEffects": [
19
+ "./snippets/*"
20
+ ]
21
+ }