@termaxjs/editor-adapter 0.1.1

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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 cmdworks
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @termaxjs/editor-adapter
2
+
3
+ Host runtime adapters for TermaxEditor. An adapter connects the headless
4
+ React tier to a buffer engine; the UI stays usable when no engine exists.
5
+
6
+ ## Tiers
7
+
8
+ | Adapter | Engine | Use when |
9
+ |---|---|---|
10
+ | `InMemoryEditorAdapter` | TypeScript, in-process | Tests, SSR, fallback |
11
+ | `TauriEditorAdapter` | Rust rope via Tauri IPC | Termax desktop, demo app |
12
+ | `WasmEditorAdapter` | Worker thread (see below) | Browser apps |
13
+ | `ElectronEditorAdapter` | Native host via Electron IPC | Electron apps |
14
+
15
+ Every adapter implements `IEditorHostAdapter` from `@termaxjs/editor-core`.
16
+ `packages/adapter/src/contract.test.ts` runs the same lifecycle, emoji,
17
+ ordering, and error script against all four; a tier that disagrees with the
18
+ UI on any of them is a bug.
19
+
20
+ ## Offset units
21
+
22
+ `applyEdit` offsets are UTF-16 code units (JS `string` indexing). The Rust
23
+ tier converts them to char indices at its boundary, so emoji and astral
24
+ characters stay in sync. Never pass char indices or byte offsets.
25
+
26
+ ## Fallback conditions
27
+
28
+ `TauriEditorAdapter`, `ElectronEditorAdapter`, and `WasmEditorAdapter` all
29
+ degrade to an in-memory engine:
30
+
31
+ - Tauri/Electron: when their native IPC global is absent (browser, SSR,
32
+ tests) or a custom invoke function is not supplied.
33
+ - WASM: when `Worker` is unavailable, no worker is supplied, or the worker
34
+ errors at runtime (pending requests reject, later calls use memory).
35
+ Note: `editorWorker.ts` currently runs the TypeScript in-memory engine
36
+ inside the worker thread. The Rust `wasm-bridge` crate compiles to
37
+ WebAssembly but is not loaded by the worker yet; loading it (wasm-pack
38
+ glue plus worker init) is tracked follow-up work, not a silent fallback.
39
+ - In fallback mode `saveBuffer` throws: there is no native filesystem to
40
+ write to. Callers must surface this instead of reporting a saved file.
41
+
42
+ `EditorProvider` additionally detaches a failing adapter after the first
43
+ error and continues in-memory, so one broken host call cannot take editing
44
+ down with it.
45
+
46
+ ## Tauri IPC key contract
47
+
48
+ JS sends camelCase argument keys; Tauri maps them to the snake_case Rust
49
+ parameters (`pathOrContent` to `path_or_content`, `charOffset` to
50
+ `char_offset`, `deleteLen` to `delete_len`, `insertText` to `insert_text`,
51
+ `targetPath` to `target_path`, `startLine` to `start_line`). A rename on one
52
+ side compiles clean and fails at runtime, so `contract.test.ts` asserts the
53
+ exact argument shapes.
54
+
55
+ ## Large files
56
+
57
+ Files at or above 10 MB (`LARGE_FILE_THRESHOLD_BYTES`) open as read-only
58
+ memory-mapped sessions on backends with a filesystem. Snapshots report
59
+ `isLargeFile: true`; edits, undo, and redo are rejected and the UI should
60
+ render the buffer read-only. Small files and untitled buffers are unaffected.
@@ -0,0 +1,40 @@
1
+ import type { BufferSnapshot, IEditorHostAdapter } from "@termaxjs/editor-core";
2
+ export interface ElectronRawBufferSnapshot {
3
+ id: string;
4
+ total_lines?: number;
5
+ totalLines?: number;
6
+ total_chars?: number;
7
+ totalChars?: number;
8
+ total_bytes?: number;
9
+ totalBytes?: number;
10
+ isLargeFile?: boolean;
11
+ is_large_file?: boolean;
12
+ encoding?: string;
13
+ }
14
+ export type ElectronInvokeFn = (channel: string, ...args: unknown[]) => Promise<unknown>;
15
+ declare global {
16
+ interface Window {
17
+ electron?: {
18
+ ipcRenderer?: {
19
+ invoke: (channel: string, ...args: unknown[]) => Promise<unknown>;
20
+ };
21
+ };
22
+ ipcRenderer?: {
23
+ invoke: (channel: string, ...args: unknown[]) => Promise<unknown>;
24
+ };
25
+ }
26
+ }
27
+ export declare class ElectronEditorAdapter implements IEditorHostAdapter {
28
+ private invoke;
29
+ private fallback;
30
+ constructor(customInvoke?: ElectronInvokeFn);
31
+ openBuffer(id: string, content: string, isFile?: boolean): Promise<BufferSnapshot>;
32
+ closeBuffer(id: string): Promise<void>;
33
+ getLines(id: string, startLine: number, count: number): Promise<string[]>;
34
+ applyEdit(id: string, charOffset: number, deleteLen: number, insertText: string): Promise<void>;
35
+ undo(id: string): Promise<boolean>;
36
+ redo(id: string): Promise<boolean>;
37
+ getContent(id: string): Promise<string>;
38
+ saveBuffer(id: string, targetPath: string): Promise<void>;
39
+ }
40
+ //# sourceMappingURL=ElectronEditorAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ElectronEditorAdapter.d.ts","sourceRoot":"","sources":["../../src/electron/ElectronEditorAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAGhF,MAAM,WAAW,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEzF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,QAAQ,CAAC,EAAE;YACT,WAAW,CAAC,EAAE;gBACZ,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;aACnE,CAAC;SACH,CAAC;QACF,WAAW,CAAC,EAAE;YACZ,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;SACnE,CAAC;KACH;CACF;AAED,qBAAa,qBAAsB,YAAW,kBAAkB;IAC9D,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,QAAQ,CAAsC;gBAE1C,YAAY,CAAC,EAAE,gBAAgB;IAgBrC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,OAAO,CAAC,cAAc,CAAC;IAwBhF,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtC,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAOzE,SAAS,CACb,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;IAYV,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOlC,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOlC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAOvC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAKhE"}
@@ -0,0 +1,91 @@
1
+ import { InMemoryEditorAdapter } from "../memory/InMemoryEditorAdapter.js";
2
+ export class ElectronEditorAdapter {
3
+ invoke;
4
+ fallback = null;
5
+ constructor(customInvoke) {
6
+ if (customInvoke) {
7
+ this.invoke = customInvoke;
8
+ }
9
+ else if (typeof window !== "undefined" && window.electron?.ipcRenderer?.invoke) {
10
+ const invoker = window.electron.ipcRenderer;
11
+ this.invoke = (channel, ...args) => invoker.invoke(channel, ...args);
12
+ }
13
+ else if (typeof window !== "undefined" && window.ipcRenderer?.invoke) {
14
+ const invoker = window.ipcRenderer;
15
+ this.invoke = (channel, ...args) => invoker.invoke(channel, ...args);
16
+ }
17
+ else {
18
+ // In-memory fallback for non-Electron / browser / SSR environments
19
+ this.fallback = new InMemoryEditorAdapter();
20
+ this.invoke = async () => null;
21
+ }
22
+ }
23
+ async openBuffer(id, content, isFile = false) {
24
+ if (this.fallback) {
25
+ return this.fallback.openBuffer(id, content);
26
+ }
27
+ const raw = (await this.invoke("termax:editor:openBuffer", {
28
+ id,
29
+ pathOrContent: content,
30
+ isFile,
31
+ }));
32
+ if (!raw) {
33
+ throw new Error(`Failed to open buffer in Electron backend: ${id}`);
34
+ }
35
+ return {
36
+ id: raw.id,
37
+ totalLines: raw.totalLines ?? raw.total_lines ?? 0,
38
+ totalChars: raw.totalChars ?? raw.total_chars ?? 0,
39
+ totalBytes: raw.totalBytes ?? raw.total_bytes ?? 0,
40
+ isLargeFile: raw.isLargeFile ?? raw.is_large_file ?? false,
41
+ encoding: raw.encoding || "utf-8",
42
+ };
43
+ }
44
+ async closeBuffer(id) {
45
+ if (this.fallback) {
46
+ return this.fallback.closeBuffer(id);
47
+ }
48
+ await this.invoke("termax:editor:closeBuffer", { id });
49
+ }
50
+ async getLines(id, startLine, count) {
51
+ if (this.fallback) {
52
+ return this.fallback.getLines(id, startLine, count);
53
+ }
54
+ return (await this.invoke("termax:editor:getLines", { id, startLine, count }));
55
+ }
56
+ async applyEdit(id, charOffset, deleteLen, insertText) {
57
+ if (this.fallback) {
58
+ return this.fallback.applyEdit(id, charOffset, deleteLen, insertText);
59
+ }
60
+ await this.invoke("termax:editor:applyEdit", {
61
+ id,
62
+ charOffset,
63
+ deleteLen,
64
+ insertText,
65
+ });
66
+ }
67
+ async undo(id) {
68
+ if (this.fallback) {
69
+ return this.fallback.undo(id);
70
+ }
71
+ return (await this.invoke("termax:editor:undo", { id }));
72
+ }
73
+ async redo(id) {
74
+ if (this.fallback) {
75
+ return this.fallback.redo(id);
76
+ }
77
+ return (await this.invoke("termax:editor:redo", { id }));
78
+ }
79
+ async getContent(id) {
80
+ if (this.fallback) {
81
+ return this.fallback.getContent(id);
82
+ }
83
+ return (await this.invoke("termax:editor:getContent", { id }));
84
+ }
85
+ async saveBuffer(id, targetPath) {
86
+ if (this.fallback)
87
+ throw new Error("Cannot save buffer in fallback mode: native Electron IPC is unavailable");
88
+ await this.invoke("termax:editor:saveBuffer", { id, targetPath });
89
+ }
90
+ }
91
+ //# sourceMappingURL=ElectronEditorAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ElectronEditorAdapter.js","sourceRoot":"","sources":["../../src/electron/ElectronEditorAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AA8B3E,MAAM,OAAO,qBAAqB;IACxB,MAAM,CAAmB;IACzB,QAAQ,GAAiC,IAAI,CAAC;IAEtD,YAAY,YAA+B;QACzC,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;QAC7B,CAAC;aAAM,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;YACjF,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC;YAC5C,IAAI,CAAC,MAAM,GAAG,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QAC1F,CAAC;aAAM,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC;YACvE,MAAM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,IAAI,CAAC,EAAU;QACnB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,EAAE,EAAE,EAAE,CAAC,CAAY,CAAC;IACtE,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,0BAA0B,EAAE,EAAE,EAAE,EAAE,CAAC,CAAW,CAAC;IAC3E,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU,EAAE,UAAkB;QAC7C,IAAI,IAAI,CAAC,QAAQ;YACf,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;QAC7F,MAAM,IAAI,CAAC,MAAM,CAAC,0BAA0B,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACpE,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ export type { IEditorHostAdapter, BufferSnapshot } from "@termaxjs/editor-core";
2
+ export * from "./memory/InMemoryEditorAdapter.js";
3
+ export * from "./wasm/WasmEditorAdapter.js";
4
+ export * from "./wasm/editorWorker.js";
5
+ export * from "./tauri/TauriEditorAdapter.js";
6
+ export * from "./electron/ElectronEditorAdapter.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEhF,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./memory/InMemoryEditorAdapter.js";
2
+ export * from "./wasm/WasmEditorAdapter.js";
3
+ export * from "./wasm/editorWorker.js";
4
+ export * from "./tauri/TauriEditorAdapter.js";
5
+ export * from "./electron/ElectronEditorAdapter.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { BufferSnapshot } from "@termaxjs/editor-core";
2
+ import type { IEditorHostAdapter } from "../index.js";
3
+ export declare class InMemoryEditorAdapter implements IEditorHostAdapter {
4
+ private sessions;
5
+ openBuffer(id: string, content: string): Promise<BufferSnapshot>;
6
+ closeBuffer(id: string): Promise<void>;
7
+ getLines(id: string, startLine: number, count: number): Promise<string[]>;
8
+ applyEdit(id: string, charOffset: number, deleteLen: number, insertText: string): Promise<void>;
9
+ undo(id: string): Promise<boolean>;
10
+ redo(id: string): Promise<boolean>;
11
+ getContent(id: string): Promise<string>;
12
+ }
13
+ //# sourceMappingURL=InMemoryEditorAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryEditorAdapter.d.ts","sourceRoot":"","sources":["../../src/memory/InMemoryEditorAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAStD,qBAAa,qBAAsB,YAAW,kBAAkB;IAC9D,OAAO,CAAC,QAAQ,CAAsC;IAEhD,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAmBhE,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItC,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAQzE,SAAS,CACb,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;IAkBV,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAWlC,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAWlC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAK9C"}
@@ -0,0 +1,76 @@
1
+ import { DEFAULT_UNDO_DEPTH } from "@termaxjs/editor-core";
2
+ export class InMemoryEditorAdapter {
3
+ sessions = new Map();
4
+ async openBuffer(id, content) {
5
+ const lines = content.split(/\r?\n/);
6
+ this.sessions.set(id, {
7
+ id,
8
+ lines,
9
+ undoStack: [],
10
+ redoStack: [],
11
+ });
12
+ return {
13
+ id,
14
+ totalLines: lines.length,
15
+ totalChars: content.length,
16
+ totalBytes: new TextEncoder().encode(content).length,
17
+ isLargeFile: false,
18
+ encoding: "utf-8",
19
+ };
20
+ }
21
+ async closeBuffer(id) {
22
+ this.sessions.delete(id);
23
+ }
24
+ async getLines(id, startLine, count) {
25
+ const session = this.sessions.get(id);
26
+ if (!session)
27
+ throw new Error(`Buffer not found: ${id}`);
28
+ const start = Math.max(0, startLine);
29
+ const end = Math.min(session.lines.length, start + count);
30
+ return session.lines.slice(start, end);
31
+ }
32
+ async applyEdit(id, charOffset, deleteLen, insertText) {
33
+ const session = this.sessions.get(id);
34
+ if (!session)
35
+ throw new Error(`Buffer not found: ${id}`);
36
+ const currentText = session.lines.join("\n");
37
+ session.undoStack.push(currentText);
38
+ if (session.undoStack.length > DEFAULT_UNDO_DEPTH) {
39
+ session.undoStack.splice(0, session.undoStack.length - DEFAULT_UNDO_DEPTH);
40
+ }
41
+ session.redoStack = [];
42
+ const before = currentText.slice(0, charOffset);
43
+ const after = currentText.slice(charOffset + deleteLen);
44
+ const nextText = before + insertText + after;
45
+ session.lines = nextText.split(/\r?\n/);
46
+ }
47
+ async undo(id) {
48
+ const session = this.sessions.get(id);
49
+ if (!session || session.undoStack.length === 0)
50
+ return false;
51
+ const prevText = session.undoStack.pop();
52
+ if (prevText === undefined)
53
+ return false;
54
+ session.redoStack.push(session.lines.join("\n"));
55
+ session.lines = prevText.split(/\r?\n/);
56
+ return true;
57
+ }
58
+ async redo(id) {
59
+ const session = this.sessions.get(id);
60
+ if (!session || session.redoStack.length === 0)
61
+ return false;
62
+ const nextText = session.redoStack.pop();
63
+ if (nextText === undefined)
64
+ return false;
65
+ session.undoStack.push(session.lines.join("\n"));
66
+ session.lines = nextText.split(/\r?\n/);
67
+ return true;
68
+ }
69
+ async getContent(id) {
70
+ const session = this.sessions.get(id);
71
+ if (!session)
72
+ throw new Error(`Buffer not found: ${id}`);
73
+ return session.lines.join("\n");
74
+ }
75
+ }
76
+ //# sourceMappingURL=InMemoryEditorAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryEditorAdapter.js","sourceRoot":"","sources":["../../src/memory/InMemoryEditorAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAU3D,MAAM,OAAO,qBAAqB;IACxB,QAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;IAEtD,KAAK,CAAC,UAAU,CAAC,EAAU,EAAE,OAAe;QAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,C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AI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAU;QACnB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAE7D,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;QACzC,IAAI,QAAQ,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QACzC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACjD,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;QACzD,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ import type { BufferSnapshot } from "@termaxjs/editor-core";
2
+ import type { IEditorHostAdapter } from "../index.js";
3
+ export interface TauriRawBufferSnapshot {
4
+ id: string;
5
+ total_lines?: number;
6
+ totalLines?: number;
7
+ total_chars?: number;
8
+ totalChars?: number;
9
+ total_bytes?: number;
10
+ totalBytes?: number;
11
+ isLargeFile?: boolean;
12
+ is_large_file?: boolean;
13
+ encoding?: string;
14
+ }
15
+ export interface TauriInternals {
16
+ invoke: (cmd: string, args?: Record<string, unknown>) => Promise<unknown>;
17
+ }
18
+ declare global {
19
+ interface Window {
20
+ __TAURI_INTERNALS__?: TauriInternals;
21
+ }
22
+ }
23
+ export type TauriInvokeFn = (cmd: string, args?: Record<string, unknown>) => Promise<unknown>;
24
+ export declare class TauriEditorAdapter implements IEditorHostAdapter {
25
+ private invoke;
26
+ private fallback;
27
+ constructor(customInvoke?: TauriInvokeFn);
28
+ openBuffer(id: string, content: string, isFile?: boolean): Promise<BufferSnapshot>;
29
+ closeBuffer(id: string): Promise<void>;
30
+ getLines(id: string, startLine: number, count: number): Promise<string[]>;
31
+ applyEdit(id: string, charOffset: number, deleteLen: number, insertText: string): Promise<void>;
32
+ undo(id: string): Promise<boolean>;
33
+ redo(id: string): Promise<boolean>;
34
+ getContent(id: string): Promise<string>;
35
+ saveBuffer(id: string, targetPath: string): Promise<void>;
36
+ }
37
+ //# sourceMappingURL=TauriEditorAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TauriEditorAdapter.d.ts","sourceRoot":"","sources":["../../src/tauri/TauriEditorAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtD,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CA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} from "../memory/InMemoryEditorAdapter.js";
2
+ export class TauriEditorAdapter {
3
+ invoke;
4
+ fallback = null;
5
+ constructor(customInvoke) {
6
+ if (customInvoke) {
7
+ this.invoke = customInvoke;
8
+ }
9
+ else if (typeof window !== "undefined" && window.__TAURI_INTERNALS__?.invoke) {
10
+ this.invoke = window.__TAURI_INTERNALS__.invoke;
11
+ }
12
+ else {
13
+ // In-memory fallback for non-Tauri browser / SSR environments
14
+ this.fallback = new InMemoryEditorAdapter();
15
+ this.invoke = async () => null;
16
+ }
17
+ }
18
+ async openBuffer(id, content, isFile = false) {
19
+ if (this.fallback) {
20
+ return this.fallback.openBuffer(id, content);
21
+ }
22
+ const raw = (await this.invoke("editor_open_buffer", {
23
+ id,
24
+ pathOrContent: content,
25
+ isFile,
26
+ }));
27
+ if (!raw) {
28
+ throw new Error(`Failed to open buffer in Tauri backend: ${id}`);
29
+ }
30
+ return {
31
+ id: raw.id,
32
+ totalLines: raw.total_lines ?? raw.totalLines ?? 0,
33
+ totalChars: raw.total_chars ?? raw.totalChars ?? 0,
34
+ totalBytes: raw.total_bytes ?? raw.totalBytes ?? 0,
35
+ isLargeFile: raw.isLargeFile ?? raw.is_large_file ?? false,
36
+ encoding: raw.encoding || "utf-8",
37
+ };
38
+ }
39
+ async closeBuffer(id) {
40
+ if (this.fallback) {
41
+ return this.fallback.closeBuffer(id);
42
+ }
43
+ await this.invoke("editor_close_buffer", { id });
44
+ }
45
+ async getLines(id, startLine, count) {
46
+ if (this.fallback) {
47
+ return this.fallback.getLines(id, startLine, count);
48
+ }
49
+ return (await this.invoke("editor_get_lines", { id, startLine, count }));
50
+ }
51
+ async applyEdit(id, charOffset, deleteLen, insertText) {
52
+ if (this.fallback) {
53
+ return this.fallback.applyEdit(id, charOffset, deleteLen, insertText);
54
+ }
55
+ await this.invoke("editor_apply_edit", {
56
+ id,
57
+ charOffset,
58
+ deleteLen,
59
+ insertText,
60
+ });
61
+ }
62
+ async undo(id) {
63
+ if (this.fallback) {
64
+ return this.fallback.undo(id);
65
+ }
66
+ return (await this.invoke("editor_undo", { id }));
67
+ }
68
+ async redo(id) {
69
+ if (this.fallback) {
70
+ return this.fallback.redo(id);
71
+ }
72
+ return (await this.invoke("editor_redo", { id }));
73
+ }
74
+ async getContent(id) {
75
+ if (this.fallback) {
76
+ return this.fallback.getContent(id);
77
+ }
78
+ return (await this.invoke("editor_get_content", { id }));
79
+ }
80
+ async saveBuffer(id, targetPath) {
81
+ if (this.fallback)
82
+ throw new Error("Cannot save buffer in fallback mode: native Tauri IPC is unavailable");
83
+ await this.invoke("editor_save_buffer", { id, targetPath });
84
+ }
85
+ }
86
+ //# sourceMappingURL=TauriEditorAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TauriEditorAdapter.js","sourceRoot":"","sources":["../../src/tauri/TauriEditorAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AA2B3E,MAAM,OAAO,kBAAkB;IACrB,MAAM,CAAgB;IACtB,QAAQ,GAAiC,IAAI,CAAC;IAEtD,YAAY,YAA4B;QACtC,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;QAC7B,CAAC;aAAM,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,mBAAmB,EAAE,MAAM,EAAE,CAAC;YAC/E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC;QAClD,CAAC;aAAM,CAAC;YACN,8DAA8D;YAC9D,IAAI,CAAC,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAC;YAC5C,IAAI,CAAC,MAAM,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC;QACjC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU,EAAE,OAAe,EAAE,MAAM,GAAG,KAAK;QAC1D,IAAI,IAAI,CAAC,QAAQ,EAAE,CA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AE,EAAE,CAAC,CAAW,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU,EAAE,UAAkB;QAC7C,IAAI,IAAI,CAAC,QAAQ;YACf,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;QAC1F,MAAM,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF"}
@@ -0,0 +1,38 @@
1
+ import type { BufferSnapshot } from "@termaxjs/editor-core";
2
+ import type { IEditorHostAdapter } from "../index.js";
3
+ export type WasmWorkerPayload = string | undefined | {
4
+ startLine: number;
5
+ count: number;
6
+ } | {
7
+ charOffset: number;
8
+ deleteLen: number;
9
+ insertText: string;
10
+ };
11
+ export interface WasmWorkerRequest {
12
+ id: number;
13
+ type: "open" | "close" | "getLines" | "applyEdit" | "undo" | "redo" | "getContent";
14
+ bufferId: string;
15
+ payload?: WasmWorkerPayload;
16
+ }
17
+ export interface WasmWorkerResponse {
18
+ id: number;
19
+ result?: unknown;
20
+ error?: string;
21
+ }
22
+ export declare class WasmEditorAdapter implements IEditorHostAdapter {
23
+ private worker;
24
+ private reqId;
25
+ private pending;
26
+ private fallback;
27
+ constructor(workerUrlOrInstance?: string | Worker);
28
+ private dispatchFallback;
29
+ private sendRequest;
30
+ openBuffer(id: string, content: string): Promise<BufferSnapshot>;
31
+ closeBuffer(id: string): Promise<void>;
32
+ getLines(id: string, startLine: number, count: number): Promise<string[]>;
33
+ applyEdit(id: string, charOffset: number, deleteLen: number, insertText: string): Promise<void>;
34
+ undo(id: string): Promise<boolean>;
35
+ redo(id: string): Promise<boolean>;
36
+ getContent(id: string): Promise<string>;
37
+ }
38
+ //# sourceMappingURL=WasmEditorAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WasmEditorAdapter.d.ts","sourceRoot":"","sources":["../../src/wasm/WasmEditorAdapter.ts"],"names":[],"mappings":"AAAA,OAA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IAIzE,SAAS,CACb,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;IAIV,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIlC,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIlC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAG9C"}
@@ -0,0 +1,111 @@
1
+ import { InMemoryEditorAdapter } from "../memory/InMemoryEditorAdapter.js";
2
+ export class WasmEditorAdapter {
3
+ worker = null;
4
+ reqId = 0;
5
+ pending = new Map();
6
+ fallback = null;
7
+ constructor(workerUrlOrInstance) {
8
+ if (typeof window !== "undefined" && typeof Worker !== "undefined") {
9
+ if (workerUrlOrInstance instanceof Worker) {
10
+ this.worker = workerUrlOrInstance;
11
+ }
12
+ else if (typeof workerUrlOrInstance === "string") {
13
+ this.worker = new Worker(workerUrlOrInstance, { type: "module" });
14
+ }
15
+ if (this.worker) {
16
+ this.worker.onerror = (err) => {
17
+ console.warn("[termax-editor] Wasm worker error; falling back to in-memory adapter.", err);
18
+ if (!this.fallback)
19
+ this.fallback = new InMemoryEditorAdapter();
20
+ for (const [id, promise] of this.pending.entries()) {
21
+ this.pending.delete(id);
22
+ promise.reject(err);
23
+ }
24
+ this.worker?.terminate();
25
+ this.worker = null;
26
+ };
27
+ this.worker.onmessage = (e) => {
28
+ const { id, result, error } = e.data;
29
+ const promise = this.pending.get(id);
30
+ if (!promise)
31
+ return;
32
+ this.pending.delete(id);
33
+ if (error) {
34
+ promise.reject(new Error(error));
35
+ }
36
+ else {
37
+ promise.resolve(result);
38
+ }
39
+ };
40
+ }
41
+ }
42
+ if (!this.worker) {
43
+ // Graceful fallback for non-worker environments (SSR/Node)
44
+ this.fallback = new InMemoryEditorAdapter();
45
+ }
46
+ }
47
+ async dispatchFallback(type, bufferId, payload) {
48
+ if (!this.fallback)
49
+ throw new Error("Fallback adapter not initialized");
50
+ switch (type) {
51
+ case "open":
52
+ return (await this.fallback.openBuffer(bufferId, payload ?? ""));
53
+ case "close":
54
+ return (await this.fallback.closeBuffer(bufferId));
55
+ case "getLines": {
56
+ const p = payload;
57
+ return (await this.fallback.getLines(bufferId, p.startLine, p.count));
58
+ }
59
+ case "applyEdit": {
60
+ const p = payload;
61
+ return (await this.fallback.applyEdit(bufferId, p.charOffset, p.deleteLen, p.insertText));
62
+ }
63
+ case "undo":
64
+ return (await this.fallback.undo(bufferId));
65
+ case "redo":
66
+ return (await this.fallback.redo(bufferId));
67
+ case "getContent":
68
+ return (await this.fallback.getContent(bufferId));
69
+ }
70
+ }
71
+ sendRequest(type, bufferId, payload) {
72
+ if (this.fallback) {
73
+ return this.dispatchFallback(type, bufferId, payload);
74
+ }
75
+ return new Promise((resolve, reject) => {
76
+ const id = ++this.reqId;
77
+ this.pending.set(id, {
78
+ resolve: resolve,
79
+ reject: reject,
80
+ });
81
+ const worker = this.worker;
82
+ if (!worker) {
83
+ reject(new Error("Editor worker is not running"));
84
+ return;
85
+ }
86
+ worker.postMessage({ id, type, bufferId, payload });
87
+ });
88
+ }
89
+ async openBuffer(id, content) {
90
+ return this.sendRequest("open", id, content);
91
+ }
92
+ async closeBuffer(id) {
93
+ return this.sendRequest("close", id);
94
+ }
95
+ async getLines(id, startLine, count) {
96
+ return this.sendRequest("getLines", id, { startLine, count });
97
+ }
98
+ async applyEdit(id, charOffset, deleteLen, insertText) {
99
+ return this.sendRequest("applyEdit", id, { charOffset, deleteLen, insertText });
100
+ }
101
+ async undo(id) {
102
+ return this.sendRequest("undo", id);
103
+ }
104
+ async redo(id) {
105
+ return this.sendRequest("redo", id);
106
+ }
107
+ async getContent(id) {
108
+ return this.sendRequest("getContent", id);
109
+ }
110
+ }
111
+ //# sourceMappingURL=WasmEditorAdapter.js.map
@@ -0,0 +1 @@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AAC;IACpD,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import type { WasmWorkerRequest, WasmWorkerResponse } from "./WasmEditorAdapter.js";
2
+ export declare function setupEditorWorker(scope: {
3
+ onmessage: ((e: MessageEvent<WasmWorkerRequest>) => void) | null;
4
+ postMessage: (msg: WasmWorkerResponse) => void;
5
+ }): void;
6
+ //# sourceMappingURL=editorWorker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editorWorker.d.ts","sourceRoot":"","sources":["../../src/wasm/editorWorker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEpF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACjE,WAAW,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,CAAC;CAChD,GAAG,IAAI,CA4CP"}
@@ -0,0 +1,52 @@
1
+ import { InMemoryEditorAdapter } from "../memory/InMemoryEditorAdapter.js";
2
+ export function setupEditorWorker(scope) {
3
+ const adapter = new InMemoryEditorAdapter();
4
+ scope.onmessage = async (e) => {
5
+ const { id, type, bufferId, payload } = e.data;
6
+ try {
7
+ let result;
8
+ switch (type) {
9
+ case "open":
10
+ result = await adapter.openBuffer(bufferId, payload ?? "");
11
+ break;
12
+ case "close":
13
+ result = await adapter.closeBuffer(bufferId);
14
+ break;
15
+ case "getLines": {
16
+ const p = payload;
17
+ result = await adapter.getLines(bufferId, p.startLine, p.count);
18
+ break;
19
+ }
20
+ case "applyEdit": {
21
+ const p = payload;
22
+ result = await adapter.applyEdit(bufferId, p.charOffset, p.deleteLen, p.insertText);
23
+ break;
24
+ }
25
+ case "undo":
26
+ result = await adapter.undo(bufferId);
27
+ break;
28
+ case "redo":
29
+ result = await adapter.redo(bufferId);
30
+ break;
31
+ case "getContent":
32
+ result = await adapter.getContent(bufferId);
33
+ break;
34
+ default:
35
+ throw new Error(`Unknown request type: ${type}`);
36
+ }
37
+ scope.postMessage({ id, result });
38
+ }
39
+ catch (err) {
40
+ scope.postMessage({
41
+ id,
42
+ error: err instanceof Error ? err.message : String(err),
43
+ });
44
+ }
45
+ };
46
+ }
47
+ if (typeof self !== "undefined" &&
48
+ typeof self.window === "undefined" &&
49
+ typeof self.postMessage === "function") {
50
+ setupEditorWorker(self);
51
+ }
52
+ //# sourceMappingURL=editorWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editorWorker.js","sourceRoot":"","sources":["../../src/wasm/editorWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAG3E,MAAM,UAAU,iBAAiB,CAAC,KAGjC;IACC,MAAM,OAAO,GAAG,IAAI,qBAAqB,EAAE,CAAC;IAE5C,KAAK,CAAC,SAAS,GAAG,KAAK,EAAE,CAAkC,EAAE,EAAE;QAC7D,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;QAC/C,IAAI,CAAC;YACH,IAAI,MAAe,CAAC;YACpB,QAAQ,IAAI,EAAE,CAAC;gBACb,KAAK,MAAM;oBACT,MAAM,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAG,OAAkB,IAAI,EAAE,CAAC,CAAC;oBACvE,MAAM;gBACR,KAAK,OAAO;oBACV,MAAM,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;oBAC7C,MAAM;gBACR,KAAK,UAAU,CAAC,CAAC,CAAC;oBAChB,MAAM,CAAC,GAAG,OAA+C,CAAC;oBAC1D,MAAM,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC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"0.1.1",
4
+ "description": "Host runtime adapters (WASM Web Worker, Native Tauri, and In-Memory) for TermaxEditor",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./memory": {
15
+ "types": "./dist/memory/InMemoryEditorAdapter.d.ts",
16
+ "import": "./dist/memory/InMemoryEditorAdapter.js",
17
+ "default": "./dist/memory/InMemoryEditorAdapter.js"
18
+ },
19
+ "./wasm": {
20
+ "types": "./dist/wasm/WasmEditorAdapter.d.ts",
21
+ "import": "./dist/wasm/WasmEditorAdapter.js",
22
+ "default": "./dist/wasm/WasmEditorAdapter.js"
23
+ },
24
+ "./tauri": {
25
+ "types": "./dist/tauri/TauriEditorAdapter.d.ts",
26
+ "import": "./dist/tauri/TauriEditorAdapter.js",
27
+ "default": "./dist/tauri/TauriEditorAdapter.js"
28
+ },
29
+ "./electron": {
30
+ "types": "./dist/electron/ElectronEditorAdapter.d.ts",
31
+ "import": "./dist/electron/ElectronEditorAdapter.js",
32
+ "default": "./dist/electron/ElectronEditorAdapter.js"
33
+ }
34
+ },
35
+ "dependencies": {
36
+ "@termaxjs/editor-core": "0.1.1"
37
+ },
38
+ "type": "module",
39
+ "devDependencies": {
40
+ "typescript": "^5.7.2",
41
+ "vitest": "^3.0.5"
42
+ },
43
+ "license": "Apache-2.0",
44
+ "files": [
45
+ "dist",
46
+ "LICENSE",
47
+ "README.md"
48
+ ],
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "scripts": {
53
+ "build": "tsc",
54
+ "check-types": "tsc --noEmit",
55
+ "test": "vitest run --passWithNoTests"
56
+ }
57
+ }