@filium/flite-js 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.
package/LICENSE ADDED
@@ -0,0 +1,91 @@
1
+ Business Source License 1.1
2
+
3
+ NOTE: This is the standard Business Source License 1.1 with the Parameters below
4
+ filled in for Filium Flite. Before public release, verify the body text against the
5
+ canonical source at https://mariadb.com/bsl11. Filium™ is a trademark of MFG Media UG.
6
+
7
+ -----------------------------------------------------------------------------
8
+
9
+ Parameters
10
+
11
+ Licensor: MFG Media UG
12
+ Licensed Work: Filium Flite, Version 0.1.0 or later.
13
+ The Licensed Work is © 2026 MFG Media UG.
14
+ Additional Use Grant: You may make production use of the Licensed Work, provided that
15
+ your organization, together with its affiliates, has annual gross
16
+ revenue of less than USD $10,000,000. For the purposes of this
17
+ grant, "production use" includes use of the Licensed Work as a
18
+ component of — or to provide — any product or service. Production
19
+ use by an organization at or above that threshold requires a
20
+ commercial license from the Licensor.
21
+ Change Date: Four years from the date the specific version of the Licensed Work
22
+ is first made publicly available.
23
+ Change License: Apache License, Version 2.0
24
+
25
+ For information about alternative licensing arrangements for the Licensed Work, please
26
+ contact licensing@filium.io.
27
+
28
+ -----------------------------------------------------------------------------
29
+
30
+ Terms
31
+
32
+ The Licensor hereby grants you the right to copy, modify, create derivative works,
33
+ redistribute, and make non-production use of the Licensed Work. The Licensor may make
34
+ an Additional Use Grant, above, permitting limited production use.
35
+
36
+ Effective on the Change Date, or the fourth anniversary of the first publicly available
37
+ distribution of a specific version of the Licensed Work under this License, whichever
38
+ comes first, the Licensor hereby grants you rights under the terms of the Change License,
39
+ and the rights granted in the paragraph above terminate.
40
+
41
+ If your use of the Licensed Work does not comply with the requirements currently in
42
+ effect as described in this License, you must purchase a commercial license from the
43
+ Licensor, its affiliated entities, or authorized resellers, or you must refrain from
44
+ using the Licensed Work.
45
+
46
+ All copies of the original and modified Licensed Work, and derivative works of the
47
+ Licensed Work, are subject to this License. This License applies separately for each
48
+ version of the Licensed Work and the Change Date may vary for each version of the
49
+ Licensed Work released by Licensor.
50
+
51
+ You must conspicuously display this License on each original or modified copy of the
52
+ Licensed Work. If you receive the Licensed Work in original or modified form from a
53
+ third party, the terms and conditions set forth in this License apply to your use of
54
+ that work.
55
+
56
+ Any use of the Licensed Work in violation of this License will automatically terminate
57
+ your rights under this License for the current and all other versions of the Licensed
58
+ Work.
59
+
60
+ This License does not grant you any right in any trademark or logo of Licensor or its
61
+ affiliates (provided that you may use a trademark or logo of Licensor to the extent
62
+ required to comply with the notice requirement above).
63
+
64
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS"
65
+ BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED,
66
+ INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
67
+ PURPOSE, NON-INFRINGEMENT, AND TITLE.
68
+
69
+ MariaDB hereby grants you permission to use this License's text to license your works,
70
+ and to refer to it using the trademark "Business Source License", as long as you comply
71
+ with the Covenants of Licensor below.
72
+
73
+ Covenants of Licensor
74
+
75
+ In consideration of the right to use this License's text and the "Business Source
76
+ License" name and trademark, Licensor covenants to MariaDB, and to all other recipients
77
+ of the licensed work to be provided by Licensor:
78
+
79
+ 1. To specify as the Change License the GPL Version 2.0 or any later version, or a
80
+ license that is compatible with GPL Version 2.0 or a later version, where "compatible"
81
+ means that software provided under the Change License can be included in a program with
82
+ software provided under GPL Version 2.0 or a later version. Licensor may specify
83
+ additional Change Licenses without limitation.
84
+
85
+ 2. To either: (a) specify an additional grant of rights to use that does not impose any
86
+ additional restriction on the right granted in this License, as the Additional Use
87
+ Grant; or (b) insert the text "None".
88
+
89
+ 3. To specify a Change Date.
90
+
91
+ 4. Not to modify this License in any other way.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # filium-flite-js
2
+
3
+ Byte-exact, token-saving source editor — a compiled **wasm** core (resilient
4
+ sectioning + byte-exact splicing) plus file I/O. The standalone tool behind the
5
+ [`filium-flite` Claude Code plugin](../filium-flite-plugin). Runs in **Node** and **Deno**.
6
+
7
+ ```js
8
+ import { Session } from "@filium/flite-js";
9
+
10
+ const s = new Session();
11
+ const outline = await s.open("src/big.rs"); // sections (id, heading, lines, balanced) — not the whole file
12
+ const text = s.zoom("src/big.rs", outline[3].id); // read just one section
13
+ s.edit("src/big.rs", outline[3].id, newBody); // replace it byte-exact; rest untouched
14
+ await s.save("src/big.rs"); // refuses if the file changed on disk since open
15
+ ```
16
+
17
+ Reading a 10k-line file to change one function costs ~20k tokens; `open → zoom → edit`
18
+ costs a few hundred — and because the engine splices bytes rather than re-serializing,
19
+ the rest of the file is guaranteed identical.
20
+
21
+ ## API
22
+
23
+ `Session`: `open(path)` · `zoom(path, id)` · `find(path, query)` · `edit` · `replace` ·
24
+ `insertBefore` · `insertAfter` · `append` · `readSlice` · `save(path)` · `close` · `list`.
25
+ `Doc` (fs-less, edit a source string). `openSource(path, source)`. `initFlite(pathOrBytes)`
26
+ to override the wasm location (for bundlers).
27
+
28
+ ## Bundling
29
+
30
+ The default resolves the co-located `wasm/`. When you bundle (esbuild etc.), call
31
+ `initFlite(<path-or-bytes-to-flite_wasm_bg.wasm>)` before first use.
32
+
33
+ ---
34
+
35
+ ## License
36
+
37
+ Filium Flite is source-available under the **[Business Source License 1.1](LICENSE)** —
38
+ free for non-production use, and free for production use by organizations under **$10M**
39
+ annual revenue. Larger commercial use (including embedding it in a product or platform at
40
+ scale) requires a commercial license: **licensing@filium.io**. Each version converts to
41
+ Apache-2.0 four years after release.
42
+
43
+ The **Filium file format and ledger** are a separate, fully open standard (Apache-2.0).
44
+
45
+ **Filium™** by **MFG Media UG** — © 2026.
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@filium/flite-js",
3
+ "version": "0.1.0",
4
+ "description": "Byte-exact, token-saving source editor — a compiled wasm core (resilient sectioning + byte-exact splicing) plus fs. The standalone tool behind the filium-flite plugin. Runs in Node and Deno.",
5
+ "type": "module",
6
+ "publishConfig": { "access": "public" },
7
+ "main": "./src/index.js",
8
+ "exports": {
9
+ ".": "./src/index.js"
10
+ },
11
+ "files": ["src", "wasm"],
12
+ "scripts": {
13
+ "test": "node test/smoke.mjs"
14
+ },
15
+ "keywords": ["editor", "wasm", "tokens", "llm", "agent", "filium", "flite"],
16
+ "license": "BUSL-1.1",
17
+ "engines": { "node": ">=18" }
18
+ }
package/src/index.js ADDED
@@ -0,0 +1,142 @@
1
+ // filium-flite-js — the standalone byte-exact source editor.
2
+ //
3
+ // The wasm crate (flite-wasm) is the pure editor: sectioning + byte-exact splices,
4
+ // no fs. This module is the thin host that the wasm deliberately lacks — it adds
5
+ // file I/O and a path-keyed Session, so the API matches the daemon (open/zoom/edit/
6
+ // save by path). Works in Node and Deno (both support the `node:` specifiers).
7
+
8
+ import { readFile, writeFile } from "node:fs/promises";
9
+ import { createHash } from "node:crypto";
10
+ import initWasm, { FliteBuffer } from "../wasm/flite_wasm.js";
11
+
12
+ let ready;
13
+ let wasmSource = null; // optional override (path | URL | bytes) set via initFlite()
14
+
15
+ /**
16
+ * Point the loader at a specific wasm before first use — a path, URL, or the raw
17
+ * bytes. Needed when this package is BUNDLED (esbuild etc.), where the co-located
18
+ * `../wasm/` no longer sits next to the running file. Not needed for a plain npm
19
+ * install, where the default resolves correctly.
20
+ */
21
+ export function initFlite(source) {
22
+ wasmSource = source;
23
+ }
24
+
25
+ /** Initialise the wasm once (idempotent). */
26
+ async function ensureWasm() {
27
+ if (!ready) {
28
+ let bytes;
29
+ if (wasmSource == null) {
30
+ bytes = await readFile(new URL("../wasm/flite_wasm_bg.wasm", import.meta.url));
31
+ } else if (typeof wasmSource === "string" || wasmSource instanceof URL) {
32
+ bytes = await readFile(wasmSource);
33
+ } else {
34
+ bytes = wasmSource; // already bytes
35
+ }
36
+ ready = initWasm({ module_or_path: bytes });
37
+ }
38
+ return ready;
39
+ }
40
+
41
+ const sha256 = (s) => createHash("sha256").update(s, "utf8").digest("hex");
42
+
43
+ /**
44
+ * One open file: the wasm Buffer + its disk baseline hash (for the save-precondition).
45
+ * Editing is synchronous and in-memory; only the Session touches disk.
46
+ */
47
+ export class Doc {
48
+ constructor(path, source) {
49
+ this.path = path;
50
+ this.buf = new FliteBuffer(path, source);
51
+ this.baseline = sha256(source);
52
+ }
53
+ get source() {
54
+ return this.buf.source;
55
+ }
56
+ outline() {
57
+ return this.buf.outline();
58
+ }
59
+ zoom(id) {
60
+ return this.buf.zoom(id);
61
+ }
62
+ find(query) {
63
+ return this.buf.find(query);
64
+ }
65
+ readSlice(startLine, endLine) {
66
+ return this.buf.read_slice(startLine, endLine);
67
+ }
68
+ edit(id, text) {
69
+ return this.buf.edit(id, text);
70
+ }
71
+ replace(anchor, replacement) {
72
+ return this.buf.replace(anchor, replacement);
73
+ }
74
+ insertBefore(id, text) {
75
+ return this.buf.insert_before(id, text);
76
+ }
77
+ insertAfter(id, text) {
78
+ return this.buf.insert_after(id, text);
79
+ }
80
+ append(text) {
81
+ return this.buf.append(text);
82
+ }
83
+ }
84
+
85
+ /** Path-keyed session: fs read/write + the byte-exact save-precondition. */
86
+ export class Session {
87
+ #docs = new Map();
88
+
89
+ /** Read the file into a buffer; returns its outline. */
90
+ async open(path) {
91
+ await ensureWasm();
92
+ const source = await readFile(path, "utf8");
93
+ const doc = new Doc(path, source);
94
+ this.#docs.set(path, doc);
95
+ return doc.outline();
96
+ }
97
+
98
+ #get(path) {
99
+ const d = this.#docs.get(path);
100
+ if (!d) throw { kind: "not_open", message: `file not open: ${path}` };
101
+ return d;
102
+ }
103
+
104
+ outline(path) { return this.#get(path).outline(); }
105
+ zoom(path, id) { return this.#get(path).zoom(id); }
106
+ find(path, query) { return this.#get(path).find(query); }
107
+ readSlice(path, a, b) { return this.#get(path).readSlice(a, b); }
108
+ edit(path, id, text) { return this.#get(path).edit(id, text); }
109
+ replace(path, anchor, rep) { return this.#get(path).replace(anchor, rep); }
110
+ insertBefore(path, id, text) { return this.#get(path).insertBefore(id, text); }
111
+ insertAfter(path, id, text) { return this.#get(path).insertAfter(id, text); }
112
+ append(path, text) { return this.#get(path).append(text); }
113
+
114
+ /** Write the buffer verbatim. Refuses if the file changed on disk since open. */
115
+ async save(path) {
116
+ const doc = this.#get(path);
117
+ try {
118
+ const disk = await readFile(path, "utf8");
119
+ if (sha256(disk) !== doc.baseline && disk !== doc.source) {
120
+ throw { kind: "conflict", message: `${path} changed on disk since open` };
121
+ }
122
+ } catch (e) {
123
+ if (e && e.kind === "conflict") throw e; // a missing file is fine (new file)
124
+ }
125
+ await writeFile(path, doc.source);
126
+ doc.baseline = sha256(doc.source);
127
+ return { status: "saved", path };
128
+ }
129
+
130
+ close(path) {
131
+ this.#docs.delete(path);
132
+ }
133
+ list() {
134
+ return [...this.#docs.keys()];
135
+ }
136
+ }
137
+
138
+ /** Fs-less: edit a source string directly (browser / in-memory). Returns a Doc. */
139
+ export async function openSource(path, source) {
140
+ await ensureWasm();
141
+ return new Doc(path, source);
142
+ }
@@ -0,0 +1,88 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * A source file opened for byte-exact editing. `path` picks the language
6
+ * sectioner (by extension); it is NEVER read from disk here — the JS host owns fs.
7
+ */
8
+ export class FliteBuffer {
9
+ free(): void;
10
+ [Symbol.dispose](): void;
11
+ append(text: string): any;
12
+ /**
13
+ * Replace a section's bytes with `new_text`. Returns `{ status, warnings }`.
14
+ */
15
+ edit(id: string, new_text: string): any;
16
+ /**
17
+ * Sections whose text contains `query` (case-insensitive).
18
+ */
19
+ find(query: string): any;
20
+ insert_after(id: string, text: string): any;
21
+ insert_before(id: string, text: string): any;
22
+ constructor(path: string, source: string);
23
+ /**
24
+ * Sections: `[{ id, heading, start_line, end_line, depth, balanced }]`.
25
+ */
26
+ outline(): any;
27
+ /**
28
+ * Verbatim text of the line range `[start_line, end_line)` (0-based).
29
+ */
30
+ read_slice(start_line: number, end_line: number): string;
31
+ /**
32
+ * Replace the first verbatim occurrence of `anchor`.
33
+ */
34
+ replace(anchor: string, replacement: string): any;
35
+ /**
36
+ * The verbatim text of one section.
37
+ */
38
+ zoom(id: string): string;
39
+ /**
40
+ * The current (possibly edited) buffer content, verbatim — the host writes
41
+ * this back to disk. Byte-exact: untouched bytes are never re-serialized.
42
+ */
43
+ readonly source: string;
44
+ }
45
+
46
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
47
+
48
+ export interface InitOutput {
49
+ readonly memory: WebAssembly.Memory;
50
+ readonly __wbg_flitebuffer_free: (a: number, b: number) => void;
51
+ readonly flitebuffer_append: (a: number, b: number, c: number, d: number) => void;
52
+ readonly flitebuffer_edit: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
53
+ readonly flitebuffer_find: (a: number, b: number, c: number, d: number) => void;
54
+ readonly flitebuffer_insert_after: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
55
+ readonly flitebuffer_insert_before: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
56
+ readonly flitebuffer_new: (a: number, b: number, c: number, d: number) => number;
57
+ readonly flitebuffer_outline: (a: number, b: number) => void;
58
+ readonly flitebuffer_read_slice: (a: number, b: number, c: number, d: number) => void;
59
+ readonly flitebuffer_replace: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
60
+ readonly flitebuffer_source: (a: number, b: number) => void;
61
+ readonly flitebuffer_zoom: (a: number, b: number, c: number, d: number) => void;
62
+ readonly __wbindgen_export: (a: number, b: number) => number;
63
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
64
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
65
+ readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
66
+ }
67
+
68
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
69
+
70
+ /**
71
+ * Instantiates the given `module`, which can either be bytes or
72
+ * a precompiled `WebAssembly.Module`.
73
+ *
74
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
75
+ *
76
+ * @returns {InitOutput}
77
+ */
78
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
79
+
80
+ /**
81
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
82
+ * for everything else, calls `WebAssembly.instantiate` directly.
83
+ *
84
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
85
+ *
86
+ * @returns {Promise<InitOutput>}
87
+ */
88
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,537 @@
1
+ /* @ts-self-types="./flite_wasm.d.ts" */
2
+
3
+ /**
4
+ * A source file opened for byte-exact editing. `path` picks the language
5
+ * sectioner (by extension); it is NEVER read from disk here — the JS host owns fs.
6
+ */
7
+ export class FliteBuffer {
8
+ __destroy_into_raw() {
9
+ const ptr = this.__wbg_ptr;
10
+ this.__wbg_ptr = 0;
11
+ FliteBufferFinalization.unregister(this);
12
+ return ptr;
13
+ }
14
+ free() {
15
+ const ptr = this.__destroy_into_raw();
16
+ wasm.__wbg_flitebuffer_free(ptr, 0);
17
+ }
18
+ /**
19
+ * @param {string} text
20
+ * @returns {any}
21
+ */
22
+ append(text) {
23
+ try {
24
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
25
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
26
+ const len0 = WASM_VECTOR_LEN;
27
+ wasm.flitebuffer_append(retptr, this.__wbg_ptr, ptr0, len0);
28
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
29
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
30
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
31
+ if (r2) {
32
+ throw takeObject(r1);
33
+ }
34
+ return takeObject(r0);
35
+ } finally {
36
+ wasm.__wbindgen_add_to_stack_pointer(16);
37
+ }
38
+ }
39
+ /**
40
+ * Replace a section's bytes with `new_text`. Returns `{ status, warnings }`.
41
+ * @param {string} id
42
+ * @param {string} new_text
43
+ * @returns {any}
44
+ */
45
+ edit(id, new_text) {
46
+ try {
47
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
48
+ const ptr0 = passStringToWasm0(id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
49
+ const len0 = WASM_VECTOR_LEN;
50
+ const ptr1 = passStringToWasm0(new_text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
51
+ const len1 = WASM_VECTOR_LEN;
52
+ wasm.flitebuffer_edit(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
53
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
54
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
55
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
56
+ if (r2) {
57
+ throw takeObject(r1);
58
+ }
59
+ return takeObject(r0);
60
+ } finally {
61
+ wasm.__wbindgen_add_to_stack_pointer(16);
62
+ }
63
+ }
64
+ /**
65
+ * Sections whose text contains `query` (case-insensitive).
66
+ * @param {string} query
67
+ * @returns {any}
68
+ */
69
+ find(query) {
70
+ try {
71
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
72
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export, wasm.__wbindgen_export2);
73
+ const len0 = WASM_VECTOR_LEN;
74
+ wasm.flitebuffer_find(retptr, this.__wbg_ptr, ptr0, len0);
75
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
76
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
77
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
78
+ if (r2) {
79
+ throw takeObject(r1);
80
+ }
81
+ return takeObject(r0);
82
+ } finally {
83
+ wasm.__wbindgen_add_to_stack_pointer(16);
84
+ }
85
+ }
86
+ /**
87
+ * @param {string} id
88
+ * @param {string} text
89
+ * @returns {any}
90
+ */
91
+ insert_after(id, text) {
92
+ try {
93
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
94
+ const ptr0 = passStringToWasm0(id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
95
+ const len0 = WASM_VECTOR_LEN;
96
+ const ptr1 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
97
+ const len1 = WASM_VECTOR_LEN;
98
+ wasm.flitebuffer_insert_after(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
99
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
100
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
101
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
102
+ if (r2) {
103
+ throw takeObject(r1);
104
+ }
105
+ return takeObject(r0);
106
+ } finally {
107
+ wasm.__wbindgen_add_to_stack_pointer(16);
108
+ }
109
+ }
110
+ /**
111
+ * @param {string} id
112
+ * @param {string} text
113
+ * @returns {any}
114
+ */
115
+ insert_before(id, text) {
116
+ try {
117
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
118
+ const ptr0 = passStringToWasm0(id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
119
+ const len0 = WASM_VECTOR_LEN;
120
+ const ptr1 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
121
+ const len1 = WASM_VECTOR_LEN;
122
+ wasm.flitebuffer_insert_before(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
123
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
124
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
125
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
126
+ if (r2) {
127
+ throw takeObject(r1);
128
+ }
129
+ return takeObject(r0);
130
+ } finally {
131
+ wasm.__wbindgen_add_to_stack_pointer(16);
132
+ }
133
+ }
134
+ /**
135
+ * @param {string} path
136
+ * @param {string} source
137
+ */
138
+ constructor(path, source) {
139
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
140
+ const len0 = WASM_VECTOR_LEN;
141
+ const ptr1 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
142
+ const len1 = WASM_VECTOR_LEN;
143
+ const ret = wasm.flitebuffer_new(ptr0, len0, ptr1, len1);
144
+ this.__wbg_ptr = ret;
145
+ FliteBufferFinalization.register(this, this.__wbg_ptr, this);
146
+ return this;
147
+ }
148
+ /**
149
+ * Sections: `[{ id, heading, start_line, end_line, depth, balanced }]`.
150
+ * @returns {any}
151
+ */
152
+ outline() {
153
+ try {
154
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
155
+ wasm.flitebuffer_outline(retptr, this.__wbg_ptr);
156
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
157
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
158
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
159
+ if (r2) {
160
+ throw takeObject(r1);
161
+ }
162
+ return takeObject(r0);
163
+ } finally {
164
+ wasm.__wbindgen_add_to_stack_pointer(16);
165
+ }
166
+ }
167
+ /**
168
+ * Verbatim text of the line range `[start_line, end_line)` (0-based).
169
+ * @param {number} start_line
170
+ * @param {number} end_line
171
+ * @returns {string}
172
+ */
173
+ read_slice(start_line, end_line) {
174
+ let deferred1_0;
175
+ let deferred1_1;
176
+ try {
177
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
178
+ wasm.flitebuffer_read_slice(retptr, this.__wbg_ptr, start_line, end_line);
179
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
180
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
181
+ deferred1_0 = r0;
182
+ deferred1_1 = r1;
183
+ return getStringFromWasm0(r0, r1);
184
+ } finally {
185
+ wasm.__wbindgen_add_to_stack_pointer(16);
186
+ wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
187
+ }
188
+ }
189
+ /**
190
+ * Replace the first verbatim occurrence of `anchor`.
191
+ * @param {string} anchor
192
+ * @param {string} replacement
193
+ * @returns {any}
194
+ */
195
+ replace(anchor, replacement) {
196
+ try {
197
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
198
+ const ptr0 = passStringToWasm0(anchor, wasm.__wbindgen_export, wasm.__wbindgen_export2);
199
+ const len0 = WASM_VECTOR_LEN;
200
+ const ptr1 = passStringToWasm0(replacement, wasm.__wbindgen_export, wasm.__wbindgen_export2);
201
+ const len1 = WASM_VECTOR_LEN;
202
+ wasm.flitebuffer_replace(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
203
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
204
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
205
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
206
+ if (r2) {
207
+ throw takeObject(r1);
208
+ }
209
+ return takeObject(r0);
210
+ } finally {
211
+ wasm.__wbindgen_add_to_stack_pointer(16);
212
+ }
213
+ }
214
+ /**
215
+ * The current (possibly edited) buffer content, verbatim — the host writes
216
+ * this back to disk. Byte-exact: untouched bytes are never re-serialized.
217
+ * @returns {string}
218
+ */
219
+ get source() {
220
+ let deferred1_0;
221
+ let deferred1_1;
222
+ try {
223
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
224
+ wasm.flitebuffer_source(retptr, this.__wbg_ptr);
225
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
226
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
227
+ deferred1_0 = r0;
228
+ deferred1_1 = r1;
229
+ return getStringFromWasm0(r0, r1);
230
+ } finally {
231
+ wasm.__wbindgen_add_to_stack_pointer(16);
232
+ wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
233
+ }
234
+ }
235
+ /**
236
+ * The verbatim text of one section.
237
+ * @param {string} id
238
+ * @returns {string}
239
+ */
240
+ zoom(id) {
241
+ let deferred3_0;
242
+ let deferred3_1;
243
+ try {
244
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
245
+ const ptr0 = passStringToWasm0(id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
246
+ const len0 = WASM_VECTOR_LEN;
247
+ wasm.flitebuffer_zoom(retptr, this.__wbg_ptr, ptr0, len0);
248
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
249
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
250
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
251
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
252
+ var ptr2 = r0;
253
+ var len2 = r1;
254
+ if (r3) {
255
+ ptr2 = 0; len2 = 0;
256
+ throw takeObject(r2);
257
+ }
258
+ deferred3_0 = ptr2;
259
+ deferred3_1 = len2;
260
+ return getStringFromWasm0(ptr2, len2);
261
+ } finally {
262
+ wasm.__wbindgen_add_to_stack_pointer(16);
263
+ wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
264
+ }
265
+ }
266
+ }
267
+ if (Symbol.dispose) FliteBuffer.prototype[Symbol.dispose] = FliteBuffer.prototype.free;
268
+ function __wbg_get_imports() {
269
+ const import0 = {
270
+ __proto__: null,
271
+ __wbg_Error_9dc85fe1bc224456: function(arg0, arg1) {
272
+ const ret = Error(getStringFromWasm0(arg0, arg1));
273
+ return addHeapObject(ret);
274
+ },
275
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
276
+ const ret = String(getObject(arg1));
277
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
278
+ const len1 = WASM_VECTOR_LEN;
279
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
280
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
281
+ },
282
+ __wbg___wbindgen_throw_bbadd78c1bac3a77: function(arg0, arg1) {
283
+ throw new Error(getStringFromWasm0(arg0, arg1));
284
+ },
285
+ __wbg_new_0b303268aa395a38: function() {
286
+ const ret = new Array();
287
+ return addHeapObject(ret);
288
+ },
289
+ __wbg_new_20b778a4c5c691c3: function() {
290
+ const ret = new Object();
291
+ return addHeapObject(ret);
292
+ },
293
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
294
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
295
+ },
296
+ __wbg_set_da33c120a6584674: function(arg0, arg1, arg2) {
297
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
298
+ },
299
+ __wbindgen_cast_0000000000000001: function(arg0) {
300
+ // Cast intrinsic for `F64 -> Externref`.
301
+ const ret = arg0;
302
+ return addHeapObject(ret);
303
+ },
304
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
305
+ // Cast intrinsic for `Ref(String) -> Externref`.
306
+ const ret = getStringFromWasm0(arg0, arg1);
307
+ return addHeapObject(ret);
308
+ },
309
+ __wbindgen_cast_0000000000000003: function(arg0) {
310
+ // Cast intrinsic for `U64 -> Externref`.
311
+ const ret = BigInt.asUintN(64, arg0);
312
+ return addHeapObject(ret);
313
+ },
314
+ __wbindgen_object_clone_ref: function(arg0) {
315
+ const ret = getObject(arg0);
316
+ return addHeapObject(ret);
317
+ },
318
+ __wbindgen_object_drop_ref: function(arg0) {
319
+ takeObject(arg0);
320
+ },
321
+ };
322
+ return {
323
+ __proto__: null,
324
+ "./flite_wasm_bg.js": import0,
325
+ };
326
+ }
327
+
328
+ const FliteBufferFinalization = (typeof FinalizationRegistry === 'undefined')
329
+ ? { register: () => {}, unregister: () => {} }
330
+ : new FinalizationRegistry(ptr => wasm.__wbg_flitebuffer_free(ptr, 1));
331
+
332
+ function addHeapObject(obj) {
333
+ if (heap_next === heap.length) heap.push(heap.length + 1);
334
+ const idx = heap_next;
335
+ heap_next = heap[idx];
336
+
337
+ heap[idx] = obj;
338
+ return idx;
339
+ }
340
+
341
+ function dropObject(idx) {
342
+ if (idx < 1028) return;
343
+ heap[idx] = heap_next;
344
+ heap_next = idx;
345
+ }
346
+
347
+ let cachedDataViewMemory0 = null;
348
+ function getDataViewMemory0() {
349
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
350
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
351
+ }
352
+ return cachedDataViewMemory0;
353
+ }
354
+
355
+ function getStringFromWasm0(ptr, len) {
356
+ return decodeText(ptr >>> 0, len);
357
+ }
358
+
359
+ let cachedUint8ArrayMemory0 = null;
360
+ function getUint8ArrayMemory0() {
361
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
362
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
363
+ }
364
+ return cachedUint8ArrayMemory0;
365
+ }
366
+
367
+ function getObject(idx) { return heap[idx]; }
368
+
369
+ let heap = new Array(1024).fill(undefined);
370
+ heap.push(undefined, null, true, false);
371
+
372
+ let heap_next = heap.length;
373
+
374
+ function passStringToWasm0(arg, malloc, realloc) {
375
+ if (realloc === undefined) {
376
+ const buf = cachedTextEncoder.encode(arg);
377
+ const ptr = malloc(buf.length, 1) >>> 0;
378
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
379
+ WASM_VECTOR_LEN = buf.length;
380
+ return ptr;
381
+ }
382
+
383
+ let len = arg.length;
384
+ let ptr = malloc(len, 1) >>> 0;
385
+
386
+ const mem = getUint8ArrayMemory0();
387
+
388
+ let offset = 0;
389
+
390
+ for (; offset < len; offset++) {
391
+ const code = arg.charCodeAt(offset);
392
+ if (code > 0x7F) break;
393
+ mem[ptr + offset] = code;
394
+ }
395
+ if (offset !== len) {
396
+ if (offset !== 0) {
397
+ arg = arg.slice(offset);
398
+ }
399
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
400
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
401
+ const ret = cachedTextEncoder.encodeInto(arg, view);
402
+
403
+ offset += ret.written;
404
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
405
+ }
406
+
407
+ WASM_VECTOR_LEN = offset;
408
+ return ptr;
409
+ }
410
+
411
+ function takeObject(idx) {
412
+ const ret = getObject(idx);
413
+ dropObject(idx);
414
+ return ret;
415
+ }
416
+
417
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
418
+ cachedTextDecoder.decode();
419
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
420
+ let numBytesDecoded = 0;
421
+ function decodeText(ptr, len) {
422
+ numBytesDecoded += len;
423
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
424
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
425
+ cachedTextDecoder.decode();
426
+ numBytesDecoded = len;
427
+ }
428
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
429
+ }
430
+
431
+ const cachedTextEncoder = new TextEncoder();
432
+
433
+ if (!('encodeInto' in cachedTextEncoder)) {
434
+ cachedTextEncoder.encodeInto = function (arg, view) {
435
+ const buf = cachedTextEncoder.encode(arg);
436
+ view.set(buf);
437
+ return {
438
+ read: arg.length,
439
+ written: buf.length
440
+ };
441
+ };
442
+ }
443
+
444
+ let WASM_VECTOR_LEN = 0;
445
+
446
+ let wasmModule, wasmInstance, wasm;
447
+ function __wbg_finalize_init(instance, module) {
448
+ wasmInstance = instance;
449
+ wasm = instance.exports;
450
+ wasmModule = module;
451
+ cachedDataViewMemory0 = null;
452
+ cachedUint8ArrayMemory0 = null;
453
+ return wasm;
454
+ }
455
+
456
+ async function __wbg_load(module, imports) {
457
+ if (typeof Response === 'function' && module instanceof Response) {
458
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
459
+ try {
460
+ return await WebAssembly.instantiateStreaming(module, imports);
461
+ } catch (e) {
462
+ const validResponse = module.ok && expectedResponseType(module.type);
463
+
464
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
465
+ 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);
466
+
467
+ } else { throw e; }
468
+ }
469
+ }
470
+
471
+ const bytes = await module.arrayBuffer();
472
+ return await WebAssembly.instantiate(bytes, imports);
473
+ } else {
474
+ const instance = await WebAssembly.instantiate(module, imports);
475
+
476
+ if (instance instanceof WebAssembly.Instance) {
477
+ return { instance, module };
478
+ } else {
479
+ return instance;
480
+ }
481
+ }
482
+
483
+ function expectedResponseType(type) {
484
+ switch (type) {
485
+ case 'basic': case 'cors': case 'default': return true;
486
+ }
487
+ return false;
488
+ }
489
+ }
490
+
491
+ function initSync(module) {
492
+ if (wasm !== undefined) return wasm;
493
+
494
+
495
+ if (module !== undefined) {
496
+ if (Object.getPrototypeOf(module) === Object.prototype) {
497
+ ({module} = module)
498
+ } else {
499
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
500
+ }
501
+ }
502
+
503
+ const imports = __wbg_get_imports();
504
+ if (!(module instanceof WebAssembly.Module)) {
505
+ module = new WebAssembly.Module(module);
506
+ }
507
+ const instance = new WebAssembly.Instance(module, imports);
508
+ return __wbg_finalize_init(instance, module);
509
+ }
510
+
511
+ async function __wbg_init(module_or_path) {
512
+ if (wasm !== undefined) return wasm;
513
+
514
+
515
+ if (module_or_path !== undefined) {
516
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
517
+ ({module_or_path} = module_or_path)
518
+ } else {
519
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
520
+ }
521
+ }
522
+
523
+ if (module_or_path === undefined) {
524
+ module_or_path = new URL('flite_wasm_bg.wasm', import.meta.url);
525
+ }
526
+ const imports = __wbg_get_imports();
527
+
528
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
529
+ module_or_path = fetch(module_or_path);
530
+ }
531
+
532
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
533
+
534
+ return __wbg_finalize_init(instance, module);
535
+ }
536
+
537
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,19 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_flitebuffer_free: (a: number, b: number) => void;
5
+ export const flitebuffer_append: (a: number, b: number, c: number, d: number) => void;
6
+ export const flitebuffer_edit: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
7
+ export const flitebuffer_find: (a: number, b: number, c: number, d: number) => void;
8
+ export const flitebuffer_insert_after: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
9
+ export const flitebuffer_insert_before: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
10
+ export const flitebuffer_new: (a: number, b: number, c: number, d: number) => number;
11
+ export const flitebuffer_outline: (a: number, b: number) => void;
12
+ export const flitebuffer_read_slice: (a: number, b: number, c: number, d: number) => void;
13
+ export const flitebuffer_replace: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
14
+ export const flitebuffer_source: (a: number, b: number) => void;
15
+ export const flitebuffer_zoom: (a: number, b: number, c: number, d: number) => void;
16
+ export const __wbindgen_export: (a: number, b: number) => number;
17
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
18
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
19
+ export const __wbindgen_export3: (a: number, b: number, c: number) => void;
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "flite-wasm",
3
+ "type": "module",
4
+ "description": "flite-wasm — wasm-bindgen wrapper exposing filium-flite's pure Buffer editing API to JS. Built with wasm-pack; the fs-owning host (filium-flite-js) drives it. The wasm is the substance; this crate is pure protocol glue.",
5
+ "version": "0.1.0",
6
+ "files": [
7
+ "flite_wasm_bg.wasm",
8
+ "flite_wasm.js",
9
+ "flite_wasm.d.ts"
10
+ ],
11
+ "main": "flite_wasm.js",
12
+ "types": "flite_wasm.d.ts",
13
+ "sideEffects": [
14
+ "./snippets/*"
15
+ ]
16
+ }