@casualoffice/sheets 0.9.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.
Files changed (92) hide show
  1. package/LICENSE +200 -0
  2. package/dist/embed/embed-runtime.js +537 -0
  3. package/dist/embed/embed.html +29 -0
  4. package/dist/embed/parser.worker.js +48474 -0
  5. package/dist/embed.cjs +225 -0
  6. package/dist/embed.cjs.map +1 -0
  7. package/dist/embed.d.cts +100 -0
  8. package/dist/embed.d.ts +100 -0
  9. package/dist/embed.js +204 -0
  10. package/dist/embed.js.map +1 -0
  11. package/dist/index.cjs +1549 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.cts +9 -0
  14. package/dist/index.d.ts +9 -0
  15. package/dist/index.js +1530 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/parser.worker.cjs +48469 -0
  18. package/dist/parser.worker.cjs.map +1 -0
  19. package/dist/parser.worker.js +48474 -0
  20. package/dist/parser.worker.js.map +1 -0
  21. package/dist/protocol--KyBQUjU.d.cts +171 -0
  22. package/dist/protocol-cEzy7S0i.d.ts +171 -0
  23. package/dist/sheets.cjs +677 -0
  24. package/dist/sheets.cjs.map +1 -0
  25. package/dist/sheets.d.cts +177 -0
  26. package/dist/sheets.d.ts +177 -0
  27. package/dist/sheets.js +658 -0
  28. package/dist/sheets.js.map +1 -0
  29. package/dist/signing.cjs +706 -0
  30. package/dist/signing.cjs.map +1 -0
  31. package/dist/signing.d.cts +141 -0
  32. package/dist/signing.d.ts +141 -0
  33. package/dist/signing.js +683 -0
  34. package/dist/signing.js.map +1 -0
  35. package/dist/styles.cjs +10 -0
  36. package/dist/styles.cjs.map +1 -0
  37. package/dist/styles.d.cts +2 -0
  38. package/dist/styles.d.ts +2 -0
  39. package/dist/styles.js +8 -0
  40. package/dist/styles.js.map +1 -0
  41. package/dist/types-s_O0u6Cg.d.cts +90 -0
  42. package/dist/types-s_O0u6Cg.d.ts +90 -0
  43. package/dist/univer.cjs +220 -0
  44. package/dist/univer.cjs.map +1 -0
  45. package/dist/univer.d.cts +60 -0
  46. package/dist/univer.d.ts +60 -0
  47. package/dist/univer.js +187 -0
  48. package/dist/univer.js.map +1 -0
  49. package/dist/xlsx.cjs +3388 -0
  50. package/dist/xlsx.cjs.map +1 -0
  51. package/dist/xlsx.d.cts +383 -0
  52. package/dist/xlsx.d.ts +383 -0
  53. package/dist/xlsx.js +3383 -0
  54. package/dist/xlsx.js.map +1 -0
  55. package/package.json +293 -0
  56. package/src/embed/EmbedHostTransport.ts +226 -0
  57. package/src/embed/EmbedTransport.ts +323 -0
  58. package/src/embed/EmbedTransport.unit.test.ts +161 -0
  59. package/src/embed/index.ts +40 -0
  60. package/src/embed/protocol.ts +258 -0
  61. package/src/embed-runtime/embed.html +29 -0
  62. package/src/embed-runtime/index.tsx +440 -0
  63. package/src/index.ts +16 -0
  64. package/src/sheets/CasualSheets.tsx +319 -0
  65. package/src/sheets/CasualSheetsIframe.tsx +220 -0
  66. package/src/sheets/api.ts +108 -0
  67. package/src/sheets/index.ts +11 -0
  68. package/src/signing/SigningPane.tsx +374 -0
  69. package/src/signing/SigningProvider.tsx +126 -0
  70. package/src/signing/captures.tsx +316 -0
  71. package/src/signing/controller.ts +151 -0
  72. package/src/signing/controller.unit.test.ts +133 -0
  73. package/src/signing/index.ts +44 -0
  74. package/src/signing/types.ts +89 -0
  75. package/src/styles.ts +16 -0
  76. package/src/univer/index.ts +17 -0
  77. package/src/univer/lazy-plugins.ts +280 -0
  78. package/src/xlsx/_perf.ts +14 -0
  79. package/src/xlsx/_snapshot-constants.ts +15 -0
  80. package/src/xlsx/comments-resource.ts +209 -0
  81. package/src/xlsx/constants.ts +9 -0
  82. package/src/xlsx/data-validation-resource.ts +219 -0
  83. package/src/xlsx/import.ts +35 -0
  84. package/src/xlsx/index.ts +40 -0
  85. package/src/xlsx/page-setup-resource.ts +205 -0
  86. package/src/xlsx/parse-impl.ts +418 -0
  87. package/src/xlsx/parse-in-worker.ts +82 -0
  88. package/src/xlsx/parser.worker.ts +39 -0
  89. package/src/xlsx/passthrough-resource.ts +175 -0
  90. package/src/xlsx/pivot-passthrough.ts +359 -0
  91. package/src/xlsx/style-mapping.ts +171 -0
  92. package/src/xlsx/tables-resource.ts +211 -0
package/package.json ADDED
@@ -0,0 +1,293 @@
1
+ {
2
+ "name": "@casualoffice/sheets",
3
+ "version": "0.9.0",
4
+ "description": "Casual Sheets SDK — signing pipeline, iframe postMessage protocol, and CasualSheets React wrapper around Univer.",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/CasualOffice/sheets.git",
10
+ "directory": "packages/sdk"
11
+ },
12
+ "homepage": "https://github.com/CasualOffice/sheets/tree/main/packages/sdk",
13
+ "main": "./dist/index.cjs",
14
+ "module": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs"
21
+ },
22
+ "./signing": {
23
+ "types": "./dist/signing.d.ts",
24
+ "import": "./dist/signing.js",
25
+ "require": "./dist/signing.cjs"
26
+ },
27
+ "./embed": {
28
+ "types": "./dist/embed.d.ts",
29
+ "import": "./dist/embed.js",
30
+ "require": "./dist/embed.cjs"
31
+ },
32
+ "./sheets": {
33
+ "types": "./dist/sheets.d.ts",
34
+ "import": "./dist/sheets.js",
35
+ "require": "./dist/sheets.cjs"
36
+ },
37
+ "./styles": {
38
+ "import": "./dist/styles.js",
39
+ "require": "./dist/styles.cjs"
40
+ },
41
+ "./xlsx": {
42
+ "types": "./dist/xlsx.d.ts",
43
+ "import": "./dist/xlsx.js",
44
+ "require": "./dist/xlsx.cjs"
45
+ },
46
+ "./univer": {
47
+ "types": "./dist/univer.d.ts",
48
+ "import": "./dist/univer.js",
49
+ "require": "./dist/univer.cjs"
50
+ },
51
+ "./embed-runtime": {
52
+ "import": "./dist/embed/embed-runtime.js"
53
+ },
54
+ "./embed/embed.html": "./dist/embed/embed.html"
55
+ },
56
+ "files": [
57
+ "dist",
58
+ "src",
59
+ "README.md"
60
+ ],
61
+ "peerDependencies": {
62
+ "@univerjs/core": "^0.25.0",
63
+ "@univerjs/design": "^0.25.0",
64
+ "@univerjs/docs": "^0.25.0",
65
+ "@univerjs/docs-ui": "^0.25.0",
66
+ "@univerjs/drawing": "^0.25.0",
67
+ "@univerjs/drawing-ui": "^0.25.0",
68
+ "@univerjs/engine-formula": "^0.25.0",
69
+ "@univerjs/engine-render": "^0.25.0",
70
+ "@univerjs/find-replace": "^0.25.0",
71
+ "@univerjs/sheets": "^0.25.0",
72
+ "@univerjs/sheets-conditional-formatting": "^0.25.0",
73
+ "@univerjs/sheets-conditional-formatting-ui": "^0.25.0",
74
+ "@univerjs/sheets-data-validation": "^0.25.0",
75
+ "@univerjs/sheets-data-validation-ui": "^0.25.0",
76
+ "@univerjs/sheets-drawing": "^0.25.0",
77
+ "@univerjs/sheets-drawing-ui": "^0.25.0",
78
+ "@univerjs/sheets-filter": "^0.25.0",
79
+ "@univerjs/sheets-filter-ui": "^0.25.0",
80
+ "@univerjs/sheets-find-replace": "^0.25.0",
81
+ "@univerjs/sheets-formula": "^0.25.0",
82
+ "@univerjs/sheets-formula-ui": "^0.25.0",
83
+ "@univerjs/sheets-hyper-link": "^0.25.0",
84
+ "@univerjs/sheets-hyper-link-ui": "^0.25.0",
85
+ "@univerjs/sheets-note": "^0.25.0",
86
+ "@univerjs/sheets-note-ui": "^0.25.0",
87
+ "@univerjs/sheets-numfmt": "^0.25.0",
88
+ "@univerjs/sheets-numfmt-ui": "^0.25.0",
89
+ "@univerjs/sheets-sort": "^0.25.0",
90
+ "@univerjs/sheets-sort-ui": "^0.25.0",
91
+ "@univerjs/sheets-table": "^0.25.0",
92
+ "@univerjs/sheets-table-ui": "^0.25.0",
93
+ "@univerjs/sheets-thread-comment": "^0.25.0",
94
+ "@univerjs/sheets-thread-comment-ui": "^0.25.0",
95
+ "@univerjs/sheets-ui": "^0.25.0",
96
+ "@univerjs/themes": "^0.25.0",
97
+ "@univerjs/thread-comment": "^0.25.0",
98
+ "@univerjs/thread-comment-ui": "^0.25.0",
99
+ "@univerjs/ui": "^0.25.0",
100
+ "react": "^18.0.0 || ^19.0.0",
101
+ "react-dom": "^18.0.0 || ^19.0.0"
102
+ },
103
+ "peerDependenciesMeta": {
104
+ "@univerjs/core": {
105
+ "optional": true
106
+ },
107
+ "@univerjs/design": {
108
+ "optional": true
109
+ },
110
+ "@univerjs/docs": {
111
+ "optional": true
112
+ },
113
+ "@univerjs/docs-ui": {
114
+ "optional": true
115
+ },
116
+ "@univerjs/drawing": {
117
+ "optional": true
118
+ },
119
+ "@univerjs/drawing-ui": {
120
+ "optional": true
121
+ },
122
+ "@univerjs/engine-formula": {
123
+ "optional": true
124
+ },
125
+ "@univerjs/engine-render": {
126
+ "optional": true
127
+ },
128
+ "@univerjs/find-replace": {
129
+ "optional": true
130
+ },
131
+ "@univerjs/sheets": {
132
+ "optional": true
133
+ },
134
+ "@univerjs/sheets-conditional-formatting": {
135
+ "optional": true
136
+ },
137
+ "@univerjs/sheets-conditional-formatting-ui": {
138
+ "optional": true
139
+ },
140
+ "@univerjs/sheets-data-validation": {
141
+ "optional": true
142
+ },
143
+ "@univerjs/sheets-data-validation-ui": {
144
+ "optional": true
145
+ },
146
+ "@univerjs/sheets-drawing": {
147
+ "optional": true
148
+ },
149
+ "@univerjs/sheets-drawing-ui": {
150
+ "optional": true
151
+ },
152
+ "@univerjs/sheets-filter": {
153
+ "optional": true
154
+ },
155
+ "@univerjs/sheets-filter-ui": {
156
+ "optional": true
157
+ },
158
+ "@univerjs/sheets-find-replace": {
159
+ "optional": true
160
+ },
161
+ "@univerjs/sheets-formula": {
162
+ "optional": true
163
+ },
164
+ "@univerjs/sheets-formula-ui": {
165
+ "optional": true
166
+ },
167
+ "@univerjs/sheets-hyper-link": {
168
+ "optional": true
169
+ },
170
+ "@univerjs/sheets-hyper-link-ui": {
171
+ "optional": true
172
+ },
173
+ "@univerjs/sheets-note": {
174
+ "optional": true
175
+ },
176
+ "@univerjs/sheets-note-ui": {
177
+ "optional": true
178
+ },
179
+ "@univerjs/sheets-numfmt": {
180
+ "optional": true
181
+ },
182
+ "@univerjs/sheets-numfmt-ui": {
183
+ "optional": true
184
+ },
185
+ "@univerjs/sheets-sort": {
186
+ "optional": true
187
+ },
188
+ "@univerjs/sheets-sort-ui": {
189
+ "optional": true
190
+ },
191
+ "@univerjs/sheets-table": {
192
+ "optional": true
193
+ },
194
+ "@univerjs/sheets-table-ui": {
195
+ "optional": true
196
+ },
197
+ "@univerjs/sheets-thread-comment": {
198
+ "optional": true
199
+ },
200
+ "@univerjs/sheets-thread-comment-ui": {
201
+ "optional": true
202
+ },
203
+ "@univerjs/sheets-ui": {
204
+ "optional": true
205
+ },
206
+ "@univerjs/themes": {
207
+ "optional": true
208
+ },
209
+ "@univerjs/thread-comment": {
210
+ "optional": true
211
+ },
212
+ "@univerjs/thread-comment-ui": {
213
+ "optional": true
214
+ },
215
+ "@univerjs/ui": {
216
+ "optional": true
217
+ },
218
+ "react": {
219
+ "optional": true
220
+ },
221
+ "react-dom": {
222
+ "optional": true
223
+ }
224
+ },
225
+ "devDependencies": {
226
+ "@types/node": "^22.0.0",
227
+ "@types/react": "^19.0.0",
228
+ "@types/react-dom": "^19.0.0",
229
+ "@univerjs/core": "0.25.0",
230
+ "@univerjs/design": "0.25.0",
231
+ "@univerjs/docs": "0.25.0",
232
+ "@univerjs/docs-ui": "0.25.0",
233
+ "@univerjs/drawing": "0.25.0",
234
+ "@univerjs/drawing-ui": "0.25.0",
235
+ "@univerjs/engine-formula": "0.25.0",
236
+ "@univerjs/engine-render": "0.25.0",
237
+ "@univerjs/find-replace": "0.25.0",
238
+ "@univerjs/sheets": "0.25.0",
239
+ "@univerjs/sheets-conditional-formatting": "0.25.0",
240
+ "@univerjs/sheets-conditional-formatting-ui": "0.25.0",
241
+ "@univerjs/sheets-data-validation": "0.25.0",
242
+ "@univerjs/sheets-data-validation-ui": "0.25.0",
243
+ "@univerjs/sheets-drawing": "0.25.0",
244
+ "@univerjs/sheets-drawing-ui": "0.25.0",
245
+ "@univerjs/sheets-filter": "0.25.0",
246
+ "@univerjs/sheets-filter-ui": "0.25.0",
247
+ "@univerjs/sheets-find-replace": "0.25.0",
248
+ "@univerjs/sheets-formula": "0.25.0",
249
+ "@univerjs/sheets-formula-ui": "0.25.0",
250
+ "@univerjs/sheets-hyper-link": "0.25.0",
251
+ "@univerjs/sheets-hyper-link-ui": "0.25.0",
252
+ "@univerjs/sheets-note": "0.25.0",
253
+ "@univerjs/sheets-note-ui": "0.25.0",
254
+ "@univerjs/sheets-numfmt": "0.25.0",
255
+ "@univerjs/sheets-numfmt-ui": "0.25.0",
256
+ "@univerjs/sheets-sort": "0.25.0",
257
+ "@univerjs/sheets-sort-ui": "0.25.0",
258
+ "@univerjs/sheets-table": "0.25.0",
259
+ "@univerjs/sheets-table-ui": "0.25.0",
260
+ "@univerjs/sheets-thread-comment": "0.25.0",
261
+ "@univerjs/sheets-thread-comment-ui": "0.25.0",
262
+ "@univerjs/sheets-ui": "0.25.0",
263
+ "@univerjs/themes": "0.25.0",
264
+ "@univerjs/thread-comment": "0.25.0",
265
+ "@univerjs/thread-comment-ui": "0.25.0",
266
+ "@univerjs/ui": "0.25.0",
267
+ "react": "^19.0.0",
268
+ "react-dom": "^19.0.0",
269
+ "tsup": "^8.0.0",
270
+ "tsx": "^4.0.0",
271
+ "typescript": "^5.4.0"
272
+ },
273
+ "publishConfig": {
274
+ "access": "public"
275
+ },
276
+ "keywords": [
277
+ "sheets",
278
+ "spreadsheet",
279
+ "signing",
280
+ "iframe",
281
+ "postmessage",
282
+ "univer",
283
+ "casual-sheets"
284
+ ],
285
+ "dependencies": {
286
+ "exceljs": "4.4.0"
287
+ },
288
+ "scripts": {
289
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsup",
290
+ "typecheck": "tsc --noEmit",
291
+ "test": "node --test --import tsx 'src/**/*.unit.test.ts'"
292
+ }
293
+ }
@@ -0,0 +1,226 @@
1
+ /**
2
+ * EmbedHostTransport — the parent side of the embed iframe bridge for
3
+ * the sheet SDK. Mirror of @casualoffice/docs's host transport.
4
+ *
5
+ * Wire shape: `docs/SDK_SIGNING_EMBED.md` (cross-link in the doc repo at
6
+ * `docs/internal/13-iframe-protocol.md`) + `16-sdk-iframe-architecture.md`.
7
+ *
8
+ * Lifetime: constructed once when the wrapper mounts the iframe.
9
+ * `destroy()` removes the event listener; safe to call multiple times.
10
+ */
11
+
12
+ import {
13
+ isCasualEnvelope,
14
+ type CasualApp,
15
+ type CasualEnvelope,
16
+ type CasualErrorData,
17
+ type CommandSetReadOnlyData,
18
+ type CommandSetThemeData,
19
+ type CommandSetLocaleData,
20
+ type CommandSetViewModeData,
21
+ type CommandExecuteData,
22
+ type SelectionFormatStateData,
23
+ type EditorHelloData,
24
+ type HostHelloData,
25
+ type LoadRequestData,
26
+ type LoadResponseData,
27
+ type SaveRequestData,
28
+ type SaveResponseData,
29
+ type SelectionChangedData,
30
+ type SignatureCancelData,
31
+ type SignatureCompleteData,
32
+ type SignatureFieldSignedData,
33
+ type SignatureRequestData,
34
+ type TelemetryEventData,
35
+ } from './protocol';
36
+
37
+ export interface EmbedHostTransportOptions {
38
+ app: CasualApp;
39
+ /** The iframe's `contentWindow`. */
40
+ iframeWindow: Window;
41
+ /** Origin allowed to send + receive messages. Same-origin internal
42
+ * embed is `window.location.origin`. */
43
+ embedOrigin: string;
44
+ /** Optional injection — tests pass a stub. */
45
+ hostWindow?: Pick<Window, 'addEventListener' | 'removeEventListener'>;
46
+ }
47
+
48
+ export interface EmbedHostHandlers {
49
+ onEditorReady?: (data: EditorHelloData) => void;
50
+ /** Editor requests bytes for `docId`. */
51
+ onLoadRequest?: (data: LoadRequestData) => Promise<LoadResponseData> | LoadResponseData;
52
+ /** Editor requests a save. */
53
+ onSaveRequest?: (data: SaveRequestData) => Promise<SaveResponseData> | SaveResponseData;
54
+ onSelectionChanged?: (data: SelectionChangedData) => void;
55
+ onSelectionFormatState?: (data: SelectionFormatStateData) => void;
56
+ onTelemetry?: (data: TelemetryEventData) => void;
57
+ onSignatureFieldSigned?: (data: SignatureFieldSignedData) => void;
58
+ onSignatureComplete?: (data: SignatureCompleteData) => void;
59
+ onSignatureCancel?: (data: SignatureCancelData) => void;
60
+ onError?: (data: CasualErrorData) => void;
61
+ }
62
+
63
+ type IframePostMessage = (msg: unknown, targetOrigin: string, transfer?: Transferable[]) => void;
64
+
65
+ export class EmbedHostTransport {
66
+ private readonly opts: EmbedHostTransportOptions;
67
+ private handlers: EmbedHostHandlers = {};
68
+ private readonly boundOnMessage: (ev: MessageEvent) => void;
69
+ private destroyed = false;
70
+
71
+ constructor(opts: EmbedHostTransportOptions) {
72
+ this.opts = opts;
73
+ this.boundOnMessage = this.onMessage.bind(this);
74
+ const target = opts.hostWindow ?? window;
75
+ target.addEventListener('message', this.boundOnMessage);
76
+ }
77
+
78
+ on(handlers: EmbedHostHandlers): void {
79
+ this.handlers = { ...this.handlers, ...handlers };
80
+ }
81
+
82
+ destroy(): void {
83
+ if (this.destroyed) return;
84
+ this.destroyed = true;
85
+ const target = this.opts.hostWindow ?? window;
86
+ target.removeEventListener('message', this.boundOnMessage);
87
+ }
88
+
89
+ sendHostHello(data: HostHelloData): void {
90
+ this.post('casual.hello', data);
91
+ }
92
+
93
+ sendSetViewMode(data: CommandSetViewModeData): void {
94
+ this.post('casual.command.set.viewmode', data);
95
+ }
96
+
97
+ sendSetReadOnly(data: CommandSetReadOnlyData): void {
98
+ this.post('casual.command.set.readonly', data);
99
+ }
100
+
101
+ sendSetTheme(data: CommandSetThemeData): void {
102
+ this.post('casual.command.set.theme', data);
103
+ }
104
+
105
+ sendSetLocale(data: CommandSetLocaleData): void {
106
+ this.post('casual.command.set.locale', data);
107
+ }
108
+
109
+ sendCommandSave(): void {
110
+ this.post('casual.command.save', null);
111
+ }
112
+
113
+ sendCommandFocus(): void {
114
+ this.post('casual.command.focus', null);
115
+ }
116
+
117
+ /** Host → Editor: run a formatting / navigation command (bold,
118
+ * italic, undo, …) against the active selection. v0.6+. */
119
+ sendCommandExecute(data: CommandExecuteData): void {
120
+ this.post('casual.command.execute', data);
121
+ }
122
+
123
+ sendSignatureRequest(id: string, data: SignatureRequestData): void {
124
+ this.post('casual.signature.request', data, id);
125
+ }
126
+
127
+ sendSignatureCancel(data: SignatureCancelData): void {
128
+ this.post('casual.signature.cancel', data);
129
+ }
130
+
131
+ private onMessage(ev: MessageEvent): void {
132
+ if (this.destroyed) return;
133
+ if (ev.origin !== this.opts.embedOrigin) return;
134
+ if (ev.source !== this.opts.iframeWindow) return;
135
+ if (!isCasualEnvelope(ev.data)) return;
136
+ if (ev.data.app !== this.opts.app) return;
137
+
138
+ void this.dispatch(ev.data);
139
+ }
140
+
141
+ private async dispatch(env: CasualEnvelope): Promise<void> {
142
+ switch (env.type) {
143
+ case 'casual.ready':
144
+ this.handlers.onEditorReady?.(env.data as EditorHelloData);
145
+ return;
146
+ case 'casual.load.request': {
147
+ if (!this.handlers.onLoadRequest) return;
148
+ const id = env.id ?? '';
149
+ try {
150
+ const resp = await this.handlers.onLoadRequest(env.data as LoadRequestData);
151
+ const transfer: Transferable[] = resp.ok ? [resp.bytes] : [];
152
+ this.post('casual.load.response', resp, id, transfer);
153
+ } catch (err) {
154
+ this.post(
155
+ 'casual.load.response',
156
+ {
157
+ ok: false as const,
158
+ code: 'host_error',
159
+ message: err instanceof Error ? err.message : String(err),
160
+ },
161
+ id,
162
+ );
163
+ }
164
+ return;
165
+ }
166
+ case 'casual.save.request': {
167
+ if (!this.handlers.onSaveRequest) return;
168
+ const id = env.id ?? '';
169
+ try {
170
+ const resp = await this.handlers.onSaveRequest(env.data as SaveRequestData);
171
+ this.post('casual.save.response', resp, id);
172
+ } catch (err) {
173
+ this.post(
174
+ 'casual.save.response',
175
+ {
176
+ ok: false as const,
177
+ code: 'host_error',
178
+ message: err instanceof Error ? err.message : String(err),
179
+ },
180
+ id,
181
+ );
182
+ }
183
+ return;
184
+ }
185
+ case 'casual.selection.changed':
186
+ this.handlers.onSelectionChanged?.(env.data as SelectionChangedData);
187
+ return;
188
+ case 'casual.selection.format-state':
189
+ this.handlers.onSelectionFormatState?.(env.data as SelectionFormatStateData);
190
+ return;
191
+ case 'casual.telemetry.event':
192
+ this.handlers.onTelemetry?.(env.data as TelemetryEventData);
193
+ return;
194
+ case 'casual.signature.field.signed':
195
+ this.handlers.onSignatureFieldSigned?.(env.data as SignatureFieldSignedData);
196
+ return;
197
+ case 'casual.signature.complete':
198
+ this.handlers.onSignatureComplete?.(env.data as SignatureCompleteData);
199
+ return;
200
+ case 'casual.signature.cancel':
201
+ this.handlers.onSignatureCancel?.(env.data as SignatureCancelData);
202
+ return;
203
+ case 'casual.signature.request.ack':
204
+ return;
205
+ case 'casual.error':
206
+ this.handlers.onError?.(env.data as CasualErrorData);
207
+ return;
208
+ default:
209
+ return;
210
+ }
211
+ }
212
+
213
+ private post(type: string, data: unknown, id?: string, transfer?: Transferable[]): void {
214
+ const env: CasualEnvelope = {
215
+ type,
216
+ app: this.opts.app,
217
+ v: 1,
218
+ data,
219
+ ...(id ? { id } : {}),
220
+ };
221
+ const send = this.opts.iframeWindow.postMessage.bind(
222
+ this.opts.iframeWindow,
223
+ ) as IframePostMessage;
224
+ send(env, this.opts.embedOrigin, transfer);
225
+ }
226
+ }