@schnsrw/casual-sheets 0.2.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,200 @@
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 tracking or 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 restrict the use of trade names,
139
+ trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ 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 Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
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 you
185
+ include the bracketed text in any "NOTICE" file as part of the
186
+ complete work for distribution.
187
+
188
+ Copyright 2026 Casual Sheets contributors
189
+
190
+ Licensed under the Apache License, Version 2.0 (the "License");
191
+ you may not use this file except in compliance with the License.
192
+ You may obtain a copy of the License at
193
+
194
+ http://www.apache.org/licenses/LICENSE-2.0
195
+
196
+ Unless required by applicable law or agreed to in writing, software
197
+ distributed under the License is distributed on an "AS IS" BASIS,
198
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
199
+ implied. See the License for the specific language governing
200
+ permissions and limitations under the License.
package/dist/embed.cjs ADDED
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/embed/index.ts
21
+ var embed_exports = {};
22
+ __export(embed_exports, {
23
+ EmbedTransport: () => EmbedTransport,
24
+ isCasualEnvelope: () => isCasualEnvelope
25
+ });
26
+ module.exports = __toCommonJS(embed_exports);
27
+
28
+ // src/embed/protocol.ts
29
+ function isCasualEnvelope(value) {
30
+ if (!value || typeof value !== "object") return false;
31
+ const v = value;
32
+ return typeof v.type === "string" && v.type.startsWith("casual.") && (v.app === "docs" || v.app === "sheet") && v.v === 1 && "data" in v;
33
+ }
34
+
35
+ // src/embed/EmbedTransport.ts
36
+ var EmbedTransport = class {
37
+ opts;
38
+ handlers = {};
39
+ destroyed = false;
40
+ pendingRequests = /* @__PURE__ */ new Map();
41
+ constructor(opts) {
42
+ this.opts = {
43
+ ...opts,
44
+ parentWindow: opts.parentWindow ?? (typeof window !== "undefined" ? window.parent : { postMessage: () => void 0 }),
45
+ hostWindow: opts.hostWindow ?? (typeof window !== "undefined" ? window : {
46
+ addEventListener: () => void 0,
47
+ removeEventListener: () => void 0
48
+ })
49
+ };
50
+ this.boundMessage = this.boundMessage.bind(this);
51
+ this.opts.hostWindow.addEventListener("message", this.boundMessage);
52
+ }
53
+ /** Replaces the handler set. Idempotent — call multiple times. */
54
+ on(handlers) {
55
+ this.handlers = { ...this.handlers, ...handlers };
56
+ }
57
+ /** Editor → Host: announce ourselves. Call once after handlers are wired. */
58
+ sendHello() {
59
+ const data = {
60
+ capabilities: this.opts.capabilities,
61
+ version: this.opts.version,
62
+ commit: this.opts.commit
63
+ };
64
+ this.post("casual.hello", data);
65
+ }
66
+ /** Editor → Host: editor is ready to receive commands. */
67
+ sendReady() {
68
+ this.post("casual.ready", {});
69
+ }
70
+ /** Editor → Host: ask the host to supply document bytes for `docId`. */
71
+ async requestLoad(docId, timeoutMs = 3e4) {
72
+ return this.request(
73
+ "casual.load.request",
74
+ { docId },
75
+ timeoutMs
76
+ );
77
+ }
78
+ /** Editor → Host: ask the host to persist `bytes`. */
79
+ async requestSave(req, timeoutMs = 3e4) {
80
+ return this.request("casual.save.request", req, timeoutMs, [req.bytes]);
81
+ }
82
+ /** Editor → Host: selection moved. Fire-and-forget. */
83
+ sendSelectionChanged(data) {
84
+ this.post("casual.selection.changed", data);
85
+ }
86
+ /** Editor → Host: a noteworthy event. */
87
+ sendTelemetry(data) {
88
+ this.post("casual.telemetry.event", data);
89
+ }
90
+ /** Editor → Host: per-field progress during a signing session. */
91
+ sendSignatureFieldSigned(data) {
92
+ this.post("casual.signature.field.signed", data, [data.bytes]);
93
+ }
94
+ /** Editor → Host: signing session is finished. */
95
+ sendSignatureComplete(data) {
96
+ this.post("casual.signature.complete", data, [data.bytes]);
97
+ }
98
+ /** Editor → Host: editor-side cancel of a signing session. */
99
+ sendSignatureCancel(reason) {
100
+ this.post("casual.signature.cancel", { reason });
101
+ }
102
+ /** Tear down listeners. Idempotent. */
103
+ destroy() {
104
+ if (this.destroyed) return;
105
+ this.opts.hostWindow.removeEventListener("message", this.boundMessage);
106
+ this.pendingRequests.clear();
107
+ this.destroyed = true;
108
+ }
109
+ // ---------------------------------------------------------------
110
+ // Internals
111
+ // ---------------------------------------------------------------
112
+ boundMessage(ev) {
113
+ const msg = ev;
114
+ if (msg.origin && msg.origin !== this.opts.hostOrigin) return;
115
+ if (!isCasualEnvelope(msg.data)) return;
116
+ void this.dispatch(msg.data);
117
+ }
118
+ async dispatch(env) {
119
+ if (env.id && this.pendingRequests.has(env.id)) {
120
+ const resolve = this.pendingRequests.get(env.id);
121
+ this.pendingRequests.delete(env.id);
122
+ resolve(env);
123
+ return;
124
+ }
125
+ switch (env.type) {
126
+ case "casual.hello":
127
+ await this.handlers.onHostHello?.(env.data);
128
+ this.sendReady();
129
+ return;
130
+ case "casual.command.setReadOnly":
131
+ await this.handlers.onCommandSetReadOnly?.(env.data);
132
+ return;
133
+ case "casual.command.setTheme":
134
+ await this.handlers.onCommandSetTheme?.(env.data);
135
+ return;
136
+ case "casual.command.setLocale":
137
+ await this.handlers.onCommandSetLocale?.(env.data);
138
+ return;
139
+ case "casual.command.focus":
140
+ await this.handlers.onCommandFocus?.();
141
+ return;
142
+ case "casual.command.save":
143
+ await this.handlers.onCommandSave?.();
144
+ return;
145
+ case "casual.command.load":
146
+ await this.handlers.onCommandLoad?.();
147
+ return;
148
+ case "casual.signature.request": {
149
+ const ack = await this.handlers.onSignatureRequest?.(
150
+ env.data
151
+ ) ?? {
152
+ ok: false,
153
+ code: "unhandled"
154
+ };
155
+ if (env.id) {
156
+ this.postReply(env.id, "casual.signature.request.ack", ack);
157
+ }
158
+ return;
159
+ }
160
+ case "casual.signature.cancel":
161
+ await this.handlers.onSignatureCancel?.(env.data);
162
+ return;
163
+ default:
164
+ return;
165
+ }
166
+ }
167
+ post(type, data, transfer) {
168
+ const env = { type, app: this.opts.app, v: 1, data };
169
+ try {
170
+ this.opts.parentWindow.postMessage(env, this.opts.hostOrigin, transfer);
171
+ } catch {
172
+ }
173
+ }
174
+ postReply(id, type, data) {
175
+ const env = { type, app: this.opts.app, id, v: 1, data };
176
+ try {
177
+ this.opts.parentWindow.postMessage(env, this.opts.hostOrigin);
178
+ } catch {
179
+ }
180
+ }
181
+ async request(type, data, timeoutMs, transfer) {
182
+ const id = newRequestId();
183
+ return new Promise((resolve, reject) => {
184
+ const timer = timeoutMs > 0 ? setTimeout(() => {
185
+ this.pendingRequests.delete(id);
186
+ reject(new Error(`Embed request ${type} timed out after ${timeoutMs}ms`));
187
+ }, timeoutMs) : null;
188
+ this.pendingRequests.set(id, (env2) => {
189
+ if (timer) clearTimeout(timer);
190
+ resolve(env2.data);
191
+ });
192
+ const env = { type, app: this.opts.app, id, v: 1, data };
193
+ try {
194
+ this.opts.parentWindow.postMessage(env, this.opts.hostOrigin, transfer);
195
+ } catch (err) {
196
+ if (timer) clearTimeout(timer);
197
+ this.pendingRequests.delete(id);
198
+ reject(err);
199
+ }
200
+ });
201
+ }
202
+ };
203
+ function newRequestId() {
204
+ return Math.random().toString(16).slice(2, 10);
205
+ }
206
+ // Annotate the CommonJS export names for ESM import in node:
207
+ 0 && (module.exports = {
208
+ EmbedTransport,
209
+ isCasualEnvelope
210
+ });
211
+ //# sourceMappingURL=embed.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/embed/index.ts","../src/embed/protocol.ts","../src/embed/EmbedTransport.ts"],"sourcesContent":["/**\n * Embed — iframe delivery surface.\n *\n * EmbedTransport bridges postMessage to React handlers. The\n * envelope shapes (`./protocol.ts`) mirror the documentation\n * contract in `docs/internal/13-iframe-protocol.md` and the\n * signing payloads from `../signing/types.ts`.\n */\n\nexport {\n EmbedTransport,\n type EmbedTransportHandlers,\n type EmbedTransportOptions,\n} from './EmbedTransport';\nexport {\n isCasualEnvelope,\n type CasualApp,\n type CasualEnvelope,\n type EditorHelloData,\n type HostHelloData,\n type LoadRequestData,\n type LoadResponseData,\n type LoadResponseDataOk,\n type LoadResponseDataErr,\n type SaveRequestData,\n type SaveResponseData,\n type SaveResponseDataOk,\n type SaveResponseDataErr,\n type SelectionChangedData,\n type TelemetryEventData,\n type LockLostData,\n type CommandSetReadOnlyData,\n type CommandSetThemeData,\n type CommandSetLocaleData,\n type SignatureRequestData,\n type SignatureRequestAckData,\n type SignatureFieldSignedData,\n type SignatureCompleteData,\n type SignatureCancelData,\n} from './protocol';\n","/**\n * Iframe protocol — wire envelopes that match\n * `docs/internal/13-iframe-protocol.md`.\n *\n * Mirror updates to the doc whenever a new envelope shape lands.\n * The discriminator on `type` (always starts with `casual.`) and\n * the per-envelope `data` shape are the contract.\n */\n\nimport type {\n CancelReason,\n SignatureCompletePayload,\n SignatureField,\n SignatureMode,\n SignedFieldPayload,\n} from '../signing/types';\n\nexport type CasualApp = 'docs' | 'sheet';\n\n/** Common envelope shape — every postMessage on the wire matches this. */\nexport interface CasualEnvelope<T = unknown> {\n type: string;\n app: CasualApp;\n /** Per-request id for request/response correlation. Empty for fire-and-forget. */\n id?: string;\n /** Protocol version. Bumped only on breaking changes. */\n v: 1;\n data: T;\n}\n\n// ---------------------------------------------------------------\n// Handshake\n// ---------------------------------------------------------------\n\nexport interface EditorHelloData {\n capabilities: string[];\n version: string;\n commit: string;\n}\n\nexport interface HostHelloData {\n capabilities: string[];\n authToken?: string;\n}\n\n// ---------------------------------------------------------------\n// Load + save (editor → host requests; host → editor responses)\n// ---------------------------------------------------------------\n\nexport interface LoadRequestData {\n docId: string;\n}\n\nexport interface LoadResponseDataOk {\n ok: true;\n bytes: ArrayBuffer;\n etag?: string;\n fileName: string;\n readOnly?: boolean;\n}\n\nexport interface LoadResponseDataErr {\n ok: false;\n code: string;\n message?: string;\n}\n\nexport type LoadResponseData = LoadResponseDataOk | LoadResponseDataErr;\n\nexport interface SaveRequestData {\n docId: string;\n bytes: ArrayBuffer;\n baseEtag?: string;\n}\n\nexport interface SaveResponseDataOk {\n ok: true;\n etag: string;\n}\n\nexport interface SaveResponseDataErr {\n ok: false;\n code: string;\n etag?: string;\n message?: string;\n}\n\nexport type SaveResponseData = SaveResponseDataOk | SaveResponseDataErr;\n\n// ---------------------------------------------------------------\n// Selection + telemetry + lock (editor → host notifications)\n// ---------------------------------------------------------------\n\nexport interface SelectionChangedData {\n docs?: { paraId: string; from: number; to: number; selectedText: string };\n sheet?: { sheet: string; from: string; to: string };\n}\n\nexport interface TelemetryEventData {\n kind: string;\n /** Arbitrary metric fields. */\n [k: string]: unknown;\n}\n\nexport interface LockLostData {\n reason: 'taken_by_other' | 'expired' | 'host_revoked';\n}\n\n// ---------------------------------------------------------------\n// Commands (host → editor)\n// ---------------------------------------------------------------\n\nexport interface CommandSetReadOnlyData {\n readOnly: boolean;\n}\n\nexport interface CommandSetThemeData {\n theme: 'light' | 'dark' | 'system';\n}\n\nexport interface CommandSetLocaleData {\n locale: string;\n}\n\n// ---------------------------------------------------------------\n// Signing (uniform with the SDK `signing` prop)\n// ---------------------------------------------------------------\n\nexport interface SignatureRequestData {\n fields: SignatureField[];\n mode: SignatureMode;\n banner?: string;\n}\n\nexport interface SignatureRequestAckData {\n ok: boolean;\n code?: string;\n}\n\nexport type SignatureFieldSignedData = SignedFieldPayload;\nexport type SignatureCompleteData = SignatureCompletePayload;\n\nexport interface SignatureCancelData {\n reason: CancelReason;\n}\n\n// ---------------------------------------------------------------\n// Type guards\n// ---------------------------------------------------------------\n\nexport function isCasualEnvelope(value: unknown): value is CasualEnvelope {\n if (!value || typeof value !== 'object') return false;\n const v = value as Record<string, unknown>;\n return (\n typeof v.type === 'string' &&\n v.type.startsWith('casual.') &&\n (v.app === 'docs' || v.app === 'sheet') &&\n v.v === 1 &&\n 'data' in v\n );\n}\n","/**\n * EmbedTransport — postMessage bridge for the iframe-embedded\n * editor. Validates origin, dispatches envelopes to handlers,\n * sends responses back to the host. Pure TypeScript — no React.\n *\n * Wire shape defined in\n * `docs/internal/13-iframe-protocol.md` + `./protocol.ts`.\n *\n * Lifetime: constructed once when the /embed page mounts.\n * Destroyed when the page unloads. Concurrent calls into the same\n * handler are the host's responsibility (well-behaved hosts\n * serialise requests by id).\n */\n\nimport {\n isCasualEnvelope,\n type CasualApp,\n type CasualEnvelope,\n type EditorHelloData,\n type HostHelloData,\n type LoadResponseData,\n type LoadRequestData,\n type SaveRequestData,\n type SaveResponseData,\n type SelectionChangedData,\n type TelemetryEventData,\n type CommandSetReadOnlyData,\n type CommandSetThemeData,\n type CommandSetLocaleData,\n type SignatureRequestData,\n type SignatureRequestAckData,\n type SignatureFieldSignedData,\n type SignatureCompleteData,\n type SignatureCancelData,\n} from './protocol';\n\nexport interface EmbedTransportOptions {\n app: CasualApp;\n /** Origin allowed to send messages. Required — no `*` default. */\n hostOrigin: string;\n /** Editor build identity, surfaced in the editor.hello handshake. */\n version: string;\n commit: string;\n /** Editor-side capabilities advertised at handshake. */\n capabilities: string[];\n /** Optional injection for `window.parent` — tests pass a stub. */\n parentWindow?: {\n postMessage: (msg: unknown, targetOrigin: string, transfer?: Transferable[]) => void;\n };\n /** Optional injection for the window receiving messages — tests pass a stub. */\n hostWindow?: Pick<Window, 'addEventListener' | 'removeEventListener'>;\n}\n\nexport interface EmbedTransportHandlers {\n /** Host → editor handshake. Editor responds with `editor.ready`. */\n onHostHello?: (data: HostHelloData) => void | Promise<void>;\n /** Host → editor: command.* messages. */\n onCommandSetReadOnly?: (data: CommandSetReadOnlyData) => void | Promise<void>;\n onCommandSetTheme?: (data: CommandSetThemeData) => void | Promise<void>;\n onCommandSetLocale?: (data: CommandSetLocaleData) => void | Promise<void>;\n onCommandFocus?: () => void | Promise<void>;\n onCommandSave?: () => void | Promise<void>;\n onCommandLoad?: () => void | Promise<void>;\n /** Host → editor signing session. Editor responds with `signature.request.ack`. */\n onSignatureRequest?: (\n data: SignatureRequestData,\n ) => SignatureRequestAckData | Promise<SignatureRequestAckData>;\n onSignatureCancel?: (data: SignatureCancelData) => void | Promise<void>;\n /** Host → editor: response to a prior load.request the editor issued. */\n onLoadResponse?: (id: string, data: LoadResponseData) => void;\n /** Host → editor: response to a prior save.request the editor issued. */\n onSaveResponse?: (id: string, data: SaveResponseData) => void;\n}\n\nexport class EmbedTransport {\n private readonly opts: Required<Omit<EmbedTransportOptions, 'parentWindow' | 'hostWindow'>> & {\n parentWindow: NonNullable<EmbedTransportOptions['parentWindow']>;\n hostWindow: NonNullable<EmbedTransportOptions['hostWindow']>;\n };\n private handlers: EmbedTransportHandlers = {};\n private destroyed = false;\n private pendingRequests = new Map<string, (env: CasualEnvelope) => void>();\n\n constructor(opts: EmbedTransportOptions) {\n this.opts = {\n ...opts,\n parentWindow:\n opts.parentWindow ??\n (typeof window !== 'undefined'\n ? (window.parent as unknown as NonNullable<EmbedTransportOptions['parentWindow']>)\n : { postMessage: () => undefined }),\n hostWindow:\n opts.hostWindow ??\n (typeof window !== 'undefined'\n ? window\n : ({\n addEventListener: () => undefined,\n removeEventListener: () => undefined,\n } as unknown as NonNullable<EmbedTransportOptions['hostWindow']>)),\n };\n this.boundMessage = this.boundMessage.bind(this);\n this.opts.hostWindow.addEventListener('message', this.boundMessage as EventListener);\n }\n\n /** Replaces the handler set. Idempotent — call multiple times. */\n on(handlers: EmbedTransportHandlers): void {\n this.handlers = { ...this.handlers, ...handlers };\n }\n\n /** Editor → Host: announce ourselves. Call once after handlers are wired. */\n sendHello(): void {\n const data: EditorHelloData = {\n capabilities: this.opts.capabilities,\n version: this.opts.version,\n commit: this.opts.commit,\n };\n this.post('casual.hello', data);\n }\n\n /** Editor → Host: editor is ready to receive commands. */\n sendReady(): void {\n this.post('casual.ready', {});\n }\n\n /** Editor → Host: ask the host to supply document bytes for `docId`. */\n async requestLoad(docId: string, timeoutMs = 30000): Promise<LoadResponseData> {\n return this.request<LoadResponseData>(\n 'casual.load.request',\n { docId } as LoadRequestData,\n timeoutMs,\n );\n }\n\n /** Editor → Host: ask the host to persist `bytes`. */\n async requestSave(req: SaveRequestData, timeoutMs = 30000): Promise<SaveResponseData> {\n return this.request<SaveResponseData>('casual.save.request', req, timeoutMs, [req.bytes]);\n }\n\n /** Editor → Host: selection moved. Fire-and-forget. */\n sendSelectionChanged(data: SelectionChangedData): void {\n this.post('casual.selection.changed', data);\n }\n\n /** Editor → Host: a noteworthy event. */\n sendTelemetry(data: TelemetryEventData): void {\n this.post('casual.telemetry.event', data);\n }\n\n /** Editor → Host: per-field progress during a signing session. */\n sendSignatureFieldSigned(data: SignatureFieldSignedData): void {\n // Bytes ride the transfer list.\n this.post('casual.signature.field.signed', data, [data.bytes]);\n }\n\n /** Editor → Host: signing session is finished. */\n sendSignatureComplete(data: SignatureCompleteData): void {\n this.post('casual.signature.complete', data, [data.bytes]);\n }\n\n /** Editor → Host: editor-side cancel of a signing session. */\n sendSignatureCancel(reason: SignatureCancelData['reason']): void {\n this.post('casual.signature.cancel', { reason });\n }\n\n /** Tear down listeners. Idempotent. */\n destroy(): void {\n if (this.destroyed) return;\n this.opts.hostWindow.removeEventListener('message', this.boundMessage as EventListener);\n this.pendingRequests.clear();\n this.destroyed = true;\n }\n\n // ---------------------------------------------------------------\n // Internals\n // ---------------------------------------------------------------\n\n private boundMessage(ev: Event): void {\n // MessageEvent isn't always available on the typing side when\n // a stub window is injected; cast pragmatically.\n const msg = ev as unknown as MessageEvent;\n if (msg.origin && msg.origin !== this.opts.hostOrigin) return;\n if (!isCasualEnvelope(msg.data)) return;\n void this.dispatch(msg.data as CasualEnvelope);\n }\n\n private async dispatch(env: CasualEnvelope): Promise<void> {\n // Responses to outbound requests route through the correlation map.\n if (env.id && this.pendingRequests.has(env.id)) {\n const resolve = this.pendingRequests.get(env.id)!;\n this.pendingRequests.delete(env.id);\n resolve(env);\n return;\n }\n\n switch (env.type) {\n case 'casual.hello':\n await this.handlers.onHostHello?.(env.data as HostHelloData);\n this.sendReady();\n return;\n case 'casual.command.setReadOnly':\n await this.handlers.onCommandSetReadOnly?.(env.data as CommandSetReadOnlyData);\n return;\n case 'casual.command.setTheme':\n await this.handlers.onCommandSetTheme?.(env.data as CommandSetThemeData);\n return;\n case 'casual.command.setLocale':\n await this.handlers.onCommandSetLocale?.(env.data as CommandSetLocaleData);\n return;\n case 'casual.command.focus':\n await this.handlers.onCommandFocus?.();\n return;\n case 'casual.command.save':\n await this.handlers.onCommandSave?.();\n return;\n case 'casual.command.load':\n await this.handlers.onCommandLoad?.();\n return;\n case 'casual.signature.request': {\n const ack = (await this.handlers.onSignatureRequest?.(\n env.data as SignatureRequestData,\n )) ?? {\n ok: false,\n code: 'unhandled',\n };\n if (env.id) {\n this.postReply(env.id, 'casual.signature.request.ack', ack);\n }\n return;\n }\n case 'casual.signature.cancel':\n await this.handlers.onSignatureCancel?.(env.data as SignatureCancelData);\n return;\n default:\n // Unknown envelope — silently drop per the forward-compat\n // convention in the protocol doc.\n return;\n }\n }\n\n private post(type: string, data: unknown, transfer?: Transferable[]): void {\n const env: CasualEnvelope = { type, app: this.opts.app, v: 1, data };\n try {\n this.opts.parentWindow.postMessage(env, this.opts.hostOrigin, transfer);\n } catch {\n // Cross-origin postMessage can throw if the parent went away;\n // silently swallow — the next user action will retry.\n }\n }\n\n private postReply(id: string, type: string, data: unknown): void {\n const env: CasualEnvelope = { type, app: this.opts.app, id, v: 1, data };\n try {\n this.opts.parentWindow.postMessage(env, this.opts.hostOrigin);\n } catch {\n // see post()\n }\n }\n\n private async request<T>(\n type: string,\n data: unknown,\n timeoutMs: number,\n transfer?: Transferable[],\n ): Promise<T> {\n const id = newRequestId();\n return new Promise<T>((resolve, reject) => {\n const timer =\n timeoutMs > 0\n ? setTimeout(() => {\n this.pendingRequests.delete(id);\n reject(new Error(`Embed request ${type} timed out after ${timeoutMs}ms`));\n }, timeoutMs)\n : null;\n this.pendingRequests.set(id, (env) => {\n if (timer) clearTimeout(timer);\n resolve(env.data as T);\n });\n const env: CasualEnvelope = { type, app: this.opts.app, id, v: 1, data };\n try {\n this.opts.parentWindow.postMessage(env, this.opts.hostOrigin, transfer);\n } catch (err) {\n if (timer) clearTimeout(timer);\n this.pendingRequests.delete(id);\n reject(err);\n }\n });\n }\n}\n\nfunction newRequestId(): string {\n // 8 hex chars is plenty — IDs only need to be unique within a\n // single editor session. Math.random is fine; the host can't\n // use these for security.\n return Math.random().toString(16).slice(2, 10);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsJO,SAAS,iBAAiB,OAAyC;AACxE,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,QAAM,IAAI;AACV,SACE,OAAO,EAAE,SAAS,YAClB,EAAE,KAAK,WAAW,SAAS,MAC1B,EAAE,QAAQ,UAAU,EAAE,QAAQ,YAC/B,EAAE,MAAM,KACR,UAAU;AAEd;;;ACtFO,IAAM,iBAAN,MAAqB;AAAA,EACT;AAAA,EAIT,WAAmC,CAAC;AAAA,EACpC,YAAY;AAAA,EACZ,kBAAkB,oBAAI,IAA2C;AAAA,EAEzE,YAAY,MAA6B;AACvC,SAAK,OAAO;AAAA,MACV,GAAG;AAAA,MACH,cACE,KAAK,iBACJ,OAAO,WAAW,cACd,OAAO,SACR,EAAE,aAAa,MAAM,OAAU;AAAA,MACrC,YACE,KAAK,eACJ,OAAO,WAAW,cACf,SACC;AAAA,QACC,kBAAkB,MAAM;AAAA,QACxB,qBAAqB,MAAM;AAAA,MAC7B;AAAA,IACR;AACA,SAAK,eAAe,KAAK,aAAa,KAAK,IAAI;AAC/C,SAAK,KAAK,WAAW,iBAAiB,WAAW,KAAK,YAA6B;AAAA,EACrF;AAAA;AAAA,EAGA,GAAG,UAAwC;AACzC,SAAK,WAAW,EAAE,GAAG,KAAK,UAAU,GAAG,SAAS;AAAA,EAClD;AAAA;AAAA,EAGA,YAAkB;AAChB,UAAM,OAAwB;AAAA,MAC5B,cAAc,KAAK,KAAK;AAAA,MACxB,SAAS,KAAK,KAAK;AAAA,MACnB,QAAQ,KAAK,KAAK;AAAA,IACpB;AACA,SAAK,KAAK,gBAAgB,IAAI;AAAA,EAChC;AAAA;AAAA,EAGA,YAAkB;AAChB,SAAK,KAAK,gBAAgB,CAAC,CAAC;AAAA,EAC9B;AAAA;AAAA,EAGA,MAAM,YAAY,OAAe,YAAY,KAAkC;AAC7E,WAAO,KAAK;AAAA,MACV;AAAA,MACA,EAAE,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,YAAY,KAAsB,YAAY,KAAkC;AACpF,WAAO,KAAK,QAA0B,uBAAuB,KAAK,WAAW,CAAC,IAAI,KAAK,CAAC;AAAA,EAC1F;AAAA;AAAA,EAGA,qBAAqB,MAAkC;AACrD,SAAK,KAAK,4BAA4B,IAAI;AAAA,EAC5C;AAAA;AAAA,EAGA,cAAc,MAAgC;AAC5C,SAAK,KAAK,0BAA0B,IAAI;AAAA,EAC1C;AAAA;AAAA,EAGA,yBAAyB,MAAsC;AAE7D,SAAK,KAAK,iCAAiC,MAAM,CAAC,KAAK,KAAK,CAAC;AAAA,EAC/D;AAAA;AAAA,EAGA,sBAAsB,MAAmC;AACvD,SAAK,KAAK,6BAA6B,MAAM,CAAC,KAAK,KAAK,CAAC;AAAA,EAC3D;AAAA;AAAA,EAGA,oBAAoB,QAA6C;AAC/D,SAAK,KAAK,2BAA2B,EAAE,OAAO,CAAC;AAAA,EACjD;AAAA;AAAA,EAGA,UAAgB;AACd,QAAI,KAAK,UAAW;AACpB,SAAK,KAAK,WAAW,oBAAoB,WAAW,KAAK,YAA6B;AACtF,SAAK,gBAAgB,MAAM;AAC3B,SAAK,YAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA,EAMQ,aAAa,IAAiB;AAGpC,UAAM,MAAM;AACZ,QAAI,IAAI,UAAU,IAAI,WAAW,KAAK,KAAK,WAAY;AACvD,QAAI,CAAC,iBAAiB,IAAI,IAAI,EAAG;AACjC,SAAK,KAAK,SAAS,IAAI,IAAsB;AAAA,EAC/C;AAAA,EAEA,MAAc,SAAS,KAAoC;AAEzD,QAAI,IAAI,MAAM,KAAK,gBAAgB,IAAI,IAAI,EAAE,GAAG;AAC9C,YAAM,UAAU,KAAK,gBAAgB,IAAI,IAAI,EAAE;AAC/C,WAAK,gBAAgB,OAAO,IAAI,EAAE;AAClC,cAAQ,GAAG;AACX;AAAA,IACF;AAEA,YAAQ,IAAI,MAAM;AAAA,MAChB,KAAK;AACH,cAAM,KAAK,SAAS,cAAc,IAAI,IAAqB;AAC3D,aAAK,UAAU;AACf;AAAA,MACF,KAAK;AACH,cAAM,KAAK,SAAS,uBAAuB,IAAI,IAA8B;AAC7E;AAAA,MACF,KAAK;AACH,cAAM,KAAK,SAAS,oBAAoB,IAAI,IAA2B;AACvE;AAAA,MACF,KAAK;AACH,cAAM,KAAK,SAAS,qBAAqB,IAAI,IAA4B;AACzE;AAAA,MACF,KAAK;AACH,cAAM,KAAK,SAAS,iBAAiB;AACrC;AAAA,MACF,KAAK;AACH,cAAM,KAAK,SAAS,gBAAgB;AACpC;AAAA,MACF,KAAK;AACH,cAAM,KAAK,SAAS,gBAAgB;AACpC;AAAA,MACF,KAAK,4BAA4B;AAC/B,cAAM,MAAO,MAAM,KAAK,SAAS;AAAA,UAC/B,IAAI;AAAA,QACN,KAAM;AAAA,UACJ,IAAI;AAAA,UACJ,MAAM;AAAA,QACR;AACA,YAAI,IAAI,IAAI;AACV,eAAK,UAAU,IAAI,IAAI,gCAAgC,GAAG;AAAA,QAC5D;AACA;AAAA,MACF;AAAA,MACA,KAAK;AACH,cAAM,KAAK,SAAS,oBAAoB,IAAI,IAA2B;AACvE;AAAA,MACF;AAGE;AAAA,IACJ;AAAA,EACF;AAAA,EAEQ,KAAK,MAAc,MAAe,UAAiC;AACzE,UAAM,MAAsB,EAAE,MAAM,KAAK,KAAK,KAAK,KAAK,GAAG,GAAG,KAAK;AACnE,QAAI;AACF,WAAK,KAAK,aAAa,YAAY,KAAK,KAAK,KAAK,YAAY,QAAQ;AAAA,IACxE,QAAQ;AAAA,IAGR;AAAA,EACF;AAAA,EAEQ,UAAU,IAAY,MAAc,MAAqB;AAC/D,UAAM,MAAsB,EAAE,MAAM,KAAK,KAAK,KAAK,KAAK,IAAI,GAAG,GAAG,KAAK;AACvE,QAAI;AACF,WAAK,KAAK,aAAa,YAAY,KAAK,KAAK,KAAK,UAAU;AAAA,IAC9D,QAAQ;AAAA,IAER;AAAA,EACF;AAAA,EAEA,MAAc,QACZ,MACA,MACA,WACA,UACY;AACZ,UAAM,KAAK,aAAa;AACxB,WAAO,IAAI,QAAW,CAAC,SAAS,WAAW;AACzC,YAAM,QACJ,YAAY,IACR,WAAW,MAAM;AACf,aAAK,gBAAgB,OAAO,EAAE;AAC9B,eAAO,IAAI,MAAM,iBAAiB,IAAI,oBAAoB,SAAS,IAAI,CAAC;AAAA,MAC1E,GAAG,SAAS,IACZ;AACN,WAAK,gBAAgB,IAAI,IAAI,CAACA,SAAQ;AACpC,YAAI,MAAO,cAAa,KAAK;AAC7B,gBAAQA,KAAI,IAAS;AAAA,MACvB,CAAC;AACD,YAAM,MAAsB,EAAE,MAAM,KAAK,KAAK,KAAK,KAAK,IAAI,GAAG,GAAG,KAAK;AACvE,UAAI;AACF,aAAK,KAAK,aAAa,YAAY,KAAK,KAAK,KAAK,YAAY,QAAQ;AAAA,MACxE,SAAS,KAAK;AACZ,YAAI,MAAO,cAAa,KAAK;AAC7B,aAAK,gBAAgB,OAAO,EAAE;AAC9B,eAAO,GAAG;AAAA,MACZ;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEA,SAAS,eAAuB;AAI9B,SAAO,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE;AAC/C;","names":["env"]}
@@ -0,0 +1,193 @@
1
+ import { c as SignatureField, e as SignatureMode, C as CancelReason, f as SignedFieldPayload, b as SignatureCompletePayload } from './types-s_O0u6Cg.cjs';
2
+
3
+ /**
4
+ * Iframe protocol — wire envelopes that match
5
+ * `docs/internal/13-iframe-protocol.md`.
6
+ *
7
+ * Mirror updates to the doc whenever a new envelope shape lands.
8
+ * The discriminator on `type` (always starts with `casual.`) and
9
+ * the per-envelope `data` shape are the contract.
10
+ */
11
+
12
+ type CasualApp = 'docs' | 'sheet';
13
+ /** Common envelope shape — every postMessage on the wire matches this. */
14
+ interface CasualEnvelope<T = unknown> {
15
+ type: string;
16
+ app: CasualApp;
17
+ /** Per-request id for request/response correlation. Empty for fire-and-forget. */
18
+ id?: string;
19
+ /** Protocol version. Bumped only on breaking changes. */
20
+ v: 1;
21
+ data: T;
22
+ }
23
+ interface EditorHelloData {
24
+ capabilities: string[];
25
+ version: string;
26
+ commit: string;
27
+ }
28
+ interface HostHelloData {
29
+ capabilities: string[];
30
+ authToken?: string;
31
+ }
32
+ interface LoadRequestData {
33
+ docId: string;
34
+ }
35
+ interface LoadResponseDataOk {
36
+ ok: true;
37
+ bytes: ArrayBuffer;
38
+ etag?: string;
39
+ fileName: string;
40
+ readOnly?: boolean;
41
+ }
42
+ interface LoadResponseDataErr {
43
+ ok: false;
44
+ code: string;
45
+ message?: string;
46
+ }
47
+ type LoadResponseData = LoadResponseDataOk | LoadResponseDataErr;
48
+ interface SaveRequestData {
49
+ docId: string;
50
+ bytes: ArrayBuffer;
51
+ baseEtag?: string;
52
+ }
53
+ interface SaveResponseDataOk {
54
+ ok: true;
55
+ etag: string;
56
+ }
57
+ interface SaveResponseDataErr {
58
+ ok: false;
59
+ code: string;
60
+ etag?: string;
61
+ message?: string;
62
+ }
63
+ type SaveResponseData = SaveResponseDataOk | SaveResponseDataErr;
64
+ interface SelectionChangedData {
65
+ docs?: {
66
+ paraId: string;
67
+ from: number;
68
+ to: number;
69
+ selectedText: string;
70
+ };
71
+ sheet?: {
72
+ sheet: string;
73
+ from: string;
74
+ to: string;
75
+ };
76
+ }
77
+ interface TelemetryEventData {
78
+ kind: string;
79
+ /** Arbitrary metric fields. */
80
+ [k: string]: unknown;
81
+ }
82
+ interface LockLostData {
83
+ reason: 'taken_by_other' | 'expired' | 'host_revoked';
84
+ }
85
+ interface CommandSetReadOnlyData {
86
+ readOnly: boolean;
87
+ }
88
+ interface CommandSetThemeData {
89
+ theme: 'light' | 'dark' | 'system';
90
+ }
91
+ interface CommandSetLocaleData {
92
+ locale: string;
93
+ }
94
+ interface SignatureRequestData {
95
+ fields: SignatureField[];
96
+ mode: SignatureMode;
97
+ banner?: string;
98
+ }
99
+ interface SignatureRequestAckData {
100
+ ok: boolean;
101
+ code?: string;
102
+ }
103
+ type SignatureFieldSignedData = SignedFieldPayload;
104
+ type SignatureCompleteData = SignatureCompletePayload;
105
+ interface SignatureCancelData {
106
+ reason: CancelReason;
107
+ }
108
+ declare function isCasualEnvelope(value: unknown): value is CasualEnvelope;
109
+
110
+ /**
111
+ * EmbedTransport — postMessage bridge for the iframe-embedded
112
+ * editor. Validates origin, dispatches envelopes to handlers,
113
+ * sends responses back to the host. Pure TypeScript — no React.
114
+ *
115
+ * Wire shape defined in
116
+ * `docs/internal/13-iframe-protocol.md` + `./protocol.ts`.
117
+ *
118
+ * Lifetime: constructed once when the /embed page mounts.
119
+ * Destroyed when the page unloads. Concurrent calls into the same
120
+ * handler are the host's responsibility (well-behaved hosts
121
+ * serialise requests by id).
122
+ */
123
+
124
+ interface EmbedTransportOptions {
125
+ app: CasualApp;
126
+ /** Origin allowed to send messages. Required — no `*` default. */
127
+ hostOrigin: string;
128
+ /** Editor build identity, surfaced in the editor.hello handshake. */
129
+ version: string;
130
+ commit: string;
131
+ /** Editor-side capabilities advertised at handshake. */
132
+ capabilities: string[];
133
+ /** Optional injection for `window.parent` — tests pass a stub. */
134
+ parentWindow?: {
135
+ postMessage: (msg: unknown, targetOrigin: string, transfer?: Transferable[]) => void;
136
+ };
137
+ /** Optional injection for the window receiving messages — tests pass a stub. */
138
+ hostWindow?: Pick<Window, 'addEventListener' | 'removeEventListener'>;
139
+ }
140
+ interface EmbedTransportHandlers {
141
+ /** Host → editor handshake. Editor responds with `editor.ready`. */
142
+ onHostHello?: (data: HostHelloData) => void | Promise<void>;
143
+ /** Host → editor: command.* messages. */
144
+ onCommandSetReadOnly?: (data: CommandSetReadOnlyData) => void | Promise<void>;
145
+ onCommandSetTheme?: (data: CommandSetThemeData) => void | Promise<void>;
146
+ onCommandSetLocale?: (data: CommandSetLocaleData) => void | Promise<void>;
147
+ onCommandFocus?: () => void | Promise<void>;
148
+ onCommandSave?: () => void | Promise<void>;
149
+ onCommandLoad?: () => void | Promise<void>;
150
+ /** Host → editor signing session. Editor responds with `signature.request.ack`. */
151
+ onSignatureRequest?: (data: SignatureRequestData) => SignatureRequestAckData | Promise<SignatureRequestAckData>;
152
+ onSignatureCancel?: (data: SignatureCancelData) => void | Promise<void>;
153
+ /** Host → editor: response to a prior load.request the editor issued. */
154
+ onLoadResponse?: (id: string, data: LoadResponseData) => void;
155
+ /** Host → editor: response to a prior save.request the editor issued. */
156
+ onSaveResponse?: (id: string, data: SaveResponseData) => void;
157
+ }
158
+ declare class EmbedTransport {
159
+ private readonly opts;
160
+ private handlers;
161
+ private destroyed;
162
+ private pendingRequests;
163
+ constructor(opts: EmbedTransportOptions);
164
+ /** Replaces the handler set. Idempotent — call multiple times. */
165
+ on(handlers: EmbedTransportHandlers): void;
166
+ /** Editor → Host: announce ourselves. Call once after handlers are wired. */
167
+ sendHello(): void;
168
+ /** Editor → Host: editor is ready to receive commands. */
169
+ sendReady(): void;
170
+ /** Editor → Host: ask the host to supply document bytes for `docId`. */
171
+ requestLoad(docId: string, timeoutMs?: number): Promise<LoadResponseData>;
172
+ /** Editor → Host: ask the host to persist `bytes`. */
173
+ requestSave(req: SaveRequestData, timeoutMs?: number): Promise<SaveResponseData>;
174
+ /** Editor → Host: selection moved. Fire-and-forget. */
175
+ sendSelectionChanged(data: SelectionChangedData): void;
176
+ /** Editor → Host: a noteworthy event. */
177
+ sendTelemetry(data: TelemetryEventData): void;
178
+ /** Editor → Host: per-field progress during a signing session. */
179
+ sendSignatureFieldSigned(data: SignatureFieldSignedData): void;
180
+ /** Editor → Host: signing session is finished. */
181
+ sendSignatureComplete(data: SignatureCompleteData): void;
182
+ /** Editor → Host: editor-side cancel of a signing session. */
183
+ sendSignatureCancel(reason: SignatureCancelData['reason']): void;
184
+ /** Tear down listeners. Idempotent. */
185
+ destroy(): void;
186
+ private boundMessage;
187
+ private dispatch;
188
+ private post;
189
+ private postReply;
190
+ private request;
191
+ }
192
+
193
+ export { type CasualApp, type CasualEnvelope, type CommandSetLocaleData, type CommandSetReadOnlyData, type CommandSetThemeData, type EditorHelloData, EmbedTransport, type EmbedTransportHandlers, type EmbedTransportOptions, type HostHelloData, type LoadRequestData, type LoadResponseData, type LoadResponseDataErr, type LoadResponseDataOk, type LockLostData, type SaveRequestData, type SaveResponseData, type SaveResponseDataErr, type SaveResponseDataOk, type SelectionChangedData, type SignatureCancelData, type SignatureCompleteData, type SignatureFieldSignedData, type SignatureRequestAckData, type SignatureRequestData, type TelemetryEventData, isCasualEnvelope };