@stll/folio-vue 0.22.0 → 0.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,877 @@
1
+ import { computed as e, inject as t, onBeforeUnmount as n, onMounted as r, onScopeDispose as i, provide as a, ref as o, shallowRef as s, toValue as c, watch as l, watchEffect as u } from "vue";
2
+ import { CANONICAL_GAP as d, canonicalRefusalMessage as f, usesCanonicalSession as ee } from "@stll/folio-core/types/canonicalCapabilities";
3
+ import { TRANSACTION_LAYOUT_TIMING as p, browserClock as m, createLayoutScheduler as h } from "@stll/folio-core/controller/layoutScheduler";
4
+ import { CanonicalSessionRefusalError as g, collectRemoteSelections as te, createHiddenEditorManager as ne, createHiddenEditorState as re } from "@stll/folio-core/controller/hiddenEditorManager";
5
+ import { cloneDocumentWithParagraphPropertySources as ie } from "@stll/folio-core/docx/document-clone";
6
+ import { getMargins as ae, getPageSize as oe, twipsToPixels as _ } from "@stll/folio-core/paged-layout/sectionGeometry";
7
+ import { getEditorScrollRoot as se, scrollEditorBy as ce } from "@stll/folio-core/paged-layout/editorScrollRoot";
8
+ import { createAnonymizationDecorationsPlugin as le } from "@stll/folio-core/prosemirror/plugins/anonymizationDecorations";
9
+ import { autocompleteSuggestionPlugin as ue } from "@stll/folio-core/prosemirror/plugins/autocompleteSuggestion";
10
+ import { createTemplateDirectivesPlugin as de } from "@stll/folio-core/prosemirror/plugins/templateDirectives";
11
+ import { createSuggestionModePlugin as fe, setSuggestionMode as pe } from "@stll/folio-core/prosemirror/plugins/suggestionMode";
12
+ import { getFootnoteText as me } from "@stll/folio-core/docx/storyPlainText";
13
+ import { FOLIO_DOCX_SERIALIZATION_MODE as he, createFolioEditor as ge } from "@stll/folio-core/controller/folioEditor";
14
+ import { createFolioEditorEmitter as _e } from "@stll/folio-core/controller/folioEditorEvents";
15
+ import { prepareCanonicalDocxInput as ve } from "@stll/folio-core/docx/canonicalSessionInput";
16
+ import { CanonicalSaveDiagnosticError as ye, serializeCanonicalSave as be } from "@stll/folio-core/docx/canonicalSave";
17
+ import { loadCollaborationModules as xe } from "@stll/folio-core/controller/collaborationModules";
18
+ import { createHeaderFooterEditorManager as Se } from "@stll/folio-core/controller/headerFooterEditorManager";
19
+ import { createNoteEditorManager as Ce } from "@stll/folio-core/controller/noteEditorManager";
20
+ import { runLayoutPipeline as we } from "@stll/folio-core/controller/layoutPipeline";
21
+ import { createHyphenationReadiness as Te } from "@stll/folio-core/controller/hyphenationReadiness";
22
+ import { readFontSetSignature as Ee, waitForInitialLayoutFonts as De, watchLayoutFontLoads as Oe } from "@stll/folio-core/controller/fontReadiness";
23
+ import { createLayoutSession as ke } from "@stll/folio-core/controller/layoutSession";
24
+ import { parseDocx as Ae } from "@stll/folio-core/docx/parser";
25
+ import { convertHeaderFooterPmDocToContent as je, convertHeaderFooterToContent as Me } from "@stll/folio-core/layout-bridge/convert/headerFooterLayout";
26
+ import { resolveSectionHeaderFooterRefs as Ne } from "@stll/folio-core/layout-engine";
27
+ import { LayoutPainter as Pe } from "@stll/folio-core/layout-painter";
28
+ import { LayoutSelectionGate as Fe } from "@stll/folio-core/paged-layout/LayoutSelectionGate";
29
+ import { fromProseDoc as Ie } from "@stll/folio-core/prosemirror/conversion/fromProseDoc";
30
+ import { createNoteReferenceFollower as Le, withoutUnreferencedNotes as Re } from "@stll/folio-core/prosemirror/noteReferenceReview";
31
+ import { ExtensionManager as ze } from "@stll/folio-core/prosemirror/extensions/ExtensionManager";
32
+ import { getChangedParagraphIds as Be, hasStructuralChanges as Ve, hasUntrackedChanges as He, repackWithEditorSectionRemovals as Ue } from "@stll/folio-core/prosemirror/extensions/features/ParagraphChangeTrackerExtension";
33
+ import { createStarterKit as We } from "@stll/folio-core/prosemirror/extensions/StarterKit";
34
+ import { createTemplatePreviewValuesPlugin as Ge } from "@stll/folio-core/prosemirror/plugins/templatePreviewValues";
35
+ import { templateSlashMenuPlugin as Ke } from "@stll/folio-core/prosemirror/plugins/templateSlashMenu";
36
+ import { resolveHeaderFooterContent as qe } from "@stll/folio-core/utils/headerFooter";
37
+ import { MIN_CELL_WIDTH_TWIPS as v, MIN_ROW_HEIGHT_TWIPS as y, TWIPS_PER_PIXEL as b, commitColumnResize as Je, commitRightEdgeResize as Ye, commitRowResize as x, readColumnWidthAt as Xe, readColumnWidths as Ze, readRowHeight as Qe } from "@stll/folio-core/prosemirror/tableResize";
38
+ import { extractTrackedChanges as $e } from "@stll/folio-core/prosemirror/utils/extractTrackedChanges";
39
+ import { ZOOM_MAX as et, ZOOM_MIN as S, ZOOM_STEP as C } from "@stll/folio-core/utils/zoom";
40
+ //#region src/utils/colorMode.ts
41
+ var tt = "(prefers-color-scheme: dark)";
42
+ function nt() {
43
+ return typeof window < "u" && typeof window.matchMedia == "function";
44
+ }
45
+ function rt(e, t) {
46
+ return e === "dark" || e === "system" && t;
47
+ }
48
+ function it(e) {
49
+ if (!nt()) return () => {};
50
+ let t = window.matchMedia(tt);
51
+ e(t.matches);
52
+ let n = (t) => e(t.matches);
53
+ return t.addEventListener("change", n), () => t.removeEventListener("change", n);
54
+ }
55
+ //#endregion
56
+ //#region src/composables/useColorMode.ts
57
+ var w = "light", T = Symbol("folioColorMode"), at = (t = w) => {
58
+ a(T, e(() => c(t)));
59
+ }, ot = { install(t, n = w) {
60
+ t.provide(T, e(() => c(n)));
61
+ } };
62
+ function E() {
63
+ let n = t(T, e(() => w)), i = o(!1), a = o(!1);
64
+ return r(() => {
65
+ i.value = !0;
66
+ }), u((e) => {
67
+ !i.value || n.value !== "system" || e(it((e) => {
68
+ a.value = e;
69
+ }));
70
+ }), e(() => rt(n.value, i.value && a.value));
71
+ }
72
+ //#endregion
73
+ //#region src/composables/useDocxEditor.ts
74
+ var st = 24, ct = "User", lt = 250, ut = [], dt = [];
75
+ function ft(e) {
76
+ let t = e?.columnCount ?? 1;
77
+ if (t <= 1) return;
78
+ let n = {
79
+ count: t,
80
+ gap: _(e?.columnSpace ?? 720),
81
+ equalWidth: e?.equalWidth ?? !0
82
+ };
83
+ return e?.separator !== void 0 && (n.separator = e.separator), n;
84
+ }
85
+ function pt(e, t, n, r, i, a) {
86
+ if (!e) return;
87
+ let o = t ? {
88
+ ...a,
89
+ rId: t
90
+ } : a, s = t ? n?.getView(t) : null;
91
+ return s ? je(s.state.doc, r, i, o) : Me(e, r, i, o);
92
+ }
93
+ function mt(e, t, n, r, i) {
94
+ if (!e || e.size === 0) return;
95
+ let a = /* @__PURE__ */ new Map();
96
+ for (let [o, s] of e) {
97
+ let e = pt(s, o, t, n, r, i);
98
+ e && a.set(o, e);
99
+ }
100
+ return a.size > 0 ? a : void 0;
101
+ }
102
+ function ht(e, t, n) {
103
+ let r = /* @__PURE__ */ new Map();
104
+ if (!n || !n.package.footnotes) return r;
105
+ let i = /* @__PURE__ */ new Map();
106
+ for (let e of n.package.footnotes) e.noteType && e.noteType !== "normal" || i.set(e.id, e);
107
+ for (let [n, a] of e) {
108
+ let e = [];
109
+ for (let n of a) {
110
+ let r = i.get(n);
111
+ if (!r) continue;
112
+ let a = t.get(n), o = a?.displayNumber ?? 0;
113
+ e.push({
114
+ displayNumber: String(o),
115
+ noteId: n,
116
+ text: me(r),
117
+ ...a ? { content: {
118
+ blocks: a.blocks,
119
+ measures: a.measures,
120
+ height: a.height
121
+ } } : {}
122
+ });
123
+ }
124
+ e.length > 0 && r.set(n, e);
125
+ }
126
+ return r;
127
+ }
128
+ var D = /* @__PURE__ */ new Set([
129
+ "black",
130
+ "blue",
131
+ "cyan",
132
+ "darkBlue",
133
+ "darkCyan",
134
+ "darkGray",
135
+ "darkGreen",
136
+ "darkMagenta",
137
+ "darkRed",
138
+ "darkYellow",
139
+ "green",
140
+ "lightGray",
141
+ "magenta",
142
+ "none",
143
+ "red",
144
+ "white",
145
+ "yellow"
146
+ ]);
147
+ function gt(e) {
148
+ let t = [], n = (e, r) => {
149
+ for (let [n, i] of e.marks.entries()) i.type.name === "highlight" && !D.has(String(i.attrs.color)) && t.push(`${r}.marks[${n}]=${JSON.stringify(i.attrs)}`);
150
+ e.forEach((e, t, i) => {
151
+ n(e, `${r}.content[${i}]`);
152
+ });
153
+ };
154
+ return n(e, "doc"), t.join("; ");
155
+ }
156
+ function O(e) {
157
+ let { hiddenContainer: t, hiddenHeaderFooterContainer: n, noteEditorContainer: r, pagesContainer: a, readOnly: u = !1, experimentalSession: _, pageGap: se = st, pageRenderer: ce, markupView: me = "all-markup", showMarginGuides: je, marginGuideColor: Me, password: v, editorMode: y, author: b, externalPlugins: Je = [], historyShortcuts: Ye = "editor", collaboration: x, onAnonymizationMatchesChange: Xe, showTemplateDirectives: Ze, onSlashMenuChange: Qe, onSlashMenuKeyAction: $e, onChange: et, onError: S, onSelectionUpdate: C, onEditorViewReady: tt, onCopy: nt, onCut: rt, onPaste: it, onReadOnlyEditAttempt: w, featureFlags: T, onSelectiveSaveTripwire: at } = e, ot = n ?? t, E = () => c(b) ?? ct, D = s(null), O = 0, _t = !1, k = 0, A = !1, j = s(null), M = s(null), N = s(null), P = s([]), F = s(null), I = s(null), L = s(null), vt = s([]), yt = s([]), R = o(!1), z = o(null), B = o(!1), V = () => ee(c(_), d.authorityRouting), H = (e) => V() ? ie(e) : e, bt = (e, t) => {
158
+ if (!V()) return !1;
159
+ let n = new g({
160
+ gap: e,
161
+ message: f(e, t)
162
+ });
163
+ return S?.(n), !0;
164
+ }, U = new ze(We({ historyShortcuts: Ye }));
165
+ U.buildSchema(), U.initializeRuntime();
166
+ let xt = fe(!1), St = [xt], Ct = ue({ keymap: !0 }), wt = le({ onMatchesChange: (e) => Xe?.(e) }), Tt = de(), Et = Ke({
167
+ onChange: (e) => Qe?.(e),
168
+ onKeyAction: (e) => $e?.(e) ?? !1
169
+ }), Dt = Ge(), Ot = () => c(Ze) === !0;
170
+ function kt() {
171
+ return [
172
+ Ct,
173
+ xt,
174
+ ...Je,
175
+ ...c(x)?.plugins ?? [],
176
+ wt,
177
+ ...Ot() ? [Tt, Et] : [],
178
+ Dt
179
+ ];
180
+ }
181
+ let W = _e(), G = new Fe(), At = ke(), jt = Te({
182
+ relayout: () => {
183
+ let e = j.value?.state ?? At.lastEditorState;
184
+ e && Y(e, { reason: "hyphenation-ready" });
185
+ },
186
+ onError: (e) => S?.(e)
187
+ });
188
+ i(jt.cancel), i(Oe({
189
+ measuredFontSet: () => At.lastMeasureInputs?.fontSet ?? null,
190
+ relayout: () => {
191
+ if (A) return;
192
+ let e = j.value?.state ?? At.lastEditorState;
193
+ e && Y(e, { reason: "font-ready" });
194
+ }
195
+ }));
196
+ let Mt = new Pe({
197
+ pageGap: se,
198
+ showShadow: !0
199
+ }), K = Se({
200
+ getHost: () => ot.value,
201
+ getDocument: () => Q.api.getCanonicalDocument() ?? D.value,
202
+ getCanonicalApi: () => Q.api,
203
+ getExperimentalSession: () => c(_),
204
+ onSessionRefusal: (e, t, n) => {
205
+ z.value = e, S?.(n ?? new g({
206
+ gap: t,
207
+ message: e
208
+ }));
209
+ },
210
+ getStyles: () => D.value?.package.styles ?? null,
211
+ getTheme: () => D.value?.package.theme ?? null,
212
+ onTransaction: ({ rId: e, kind: t, view: n, docChanged: r, selectionChanged: i }) => {
213
+ if (r && (B.value = !0, X.schedule()), r || i) {
214
+ let { from: r, to: i } = n.state.selection;
215
+ F.value = {
216
+ from: r,
217
+ kind: t,
218
+ rId: e,
219
+ to: i
220
+ }, C?.(n.state), W.emit("selectionChange", {
221
+ from: r,
222
+ to: i
223
+ });
224
+ }
225
+ G.requestRender();
226
+ }
227
+ }), Nt = { current: null }, q = Ce({
228
+ getHost: () => r?.value ?? null,
229
+ getPlugins: () => St,
230
+ getDocument: () => Q.api.getCanonicalDocument() ?? D.value,
231
+ getCanonicalApi: () => Q.api,
232
+ getExperimentalSession: () => c(_),
233
+ onSessionRefusal: (e, t, n) => {
234
+ z.value = e, S?.(n ?? new g({
235
+ gap: t,
236
+ message: e
237
+ }));
238
+ },
239
+ getStyles: () => D.value?.package.styles ?? null,
240
+ getTheme: () => D.value?.package.theme ?? null,
241
+ onTransaction: ({ docChanged: e, selectionChanged: t, view: n }) => {
242
+ if (e) {
243
+ B.value = !0;
244
+ let e = D.value;
245
+ if (e) {
246
+ let t = Q.api.getCanonicalDocument() ?? Nt.current?.snapshotDocument(e) ?? e;
247
+ D.value = t, et?.(H(t)), W.emit("docChange", H(t));
248
+ }
249
+ X.schedule();
250
+ }
251
+ if (e || t) {
252
+ C?.(n.state);
253
+ let { from: e, to: t } = n.state.selection;
254
+ W.emit("selectionChange", {
255
+ from: e,
256
+ to: t
257
+ });
258
+ }
259
+ }
260
+ });
261
+ Nt.current = q;
262
+ let J = () => {
263
+ K.sync(), q.sync();
264
+ };
265
+ l(() => c(_), J);
266
+ function Pt(e) {
267
+ e.layout && (L.value = e.layout), e.blocks && (vt.value = e.blocks), e.measures && (yt.value = e.measures), e.blockLookup && Mt.setBlockLookup(e.blockLookup), e.layout && W.emit("layoutComplete", e.layout);
268
+ }
269
+ function Y(e, t = {}) {
270
+ if (A) return;
271
+ let n = a.value, r = n instanceof HTMLDivElement ? n : null, i = D.value, o = i?.package.document, s = o?.sections?.[0]?.properties ?? o?.finalSectionProperties ?? null, l = oe(s), u = ae(s), d = ft(s), f = l.w - u.left - u.right, ee = i?.package.styles ?? null, p = i?.package.theme ?? null, m = i?.package.settings?.defaultTabStop, h = i?.package.settings?.mirrorMargins === !0, g = qe(i?.package);
272
+ try {
273
+ Pt(we({
274
+ contentWidth: f,
275
+ columns: d,
276
+ pageSize: l,
277
+ margins: u,
278
+ pageGap: se,
279
+ showMarginGuides: c(je) === !0,
280
+ marginGuideColor: c(Me),
281
+ ...(() => {
282
+ let e = c(ce);
283
+ return e === void 0 ? {} : { pageRenderer: e };
284
+ })(),
285
+ syncCoordinator: G,
286
+ headerContent: g.headerContent,
287
+ footerContent: g.footerContent,
288
+ firstPageHeaderContent: g.firstPageHeaderContent,
289
+ firstPageFooterContent: g.firstPageFooterContent,
290
+ headerContentRId: g.activeHeaderRId,
291
+ footerContentRId: g.activeFooterRId,
292
+ firstPageHeaderContentRId: g.activeFirstHeaderRId,
293
+ firstPageFooterContentRId: g.activeFirstFooterRId,
294
+ sectionHeaderFooterRefs: Ne(i),
295
+ theme: p,
296
+ sectionProperties: s,
297
+ document: i,
298
+ defaultTabStop: m,
299
+ mirrorMargins: h,
300
+ styles: ee,
301
+ layout: L.value,
302
+ hfPMs: K,
303
+ painter: Mt,
304
+ pagesContainer: r,
305
+ session: At,
306
+ renderHfFromContentOrPm: pt,
307
+ renderHeaderFooterContentByRId: mt,
308
+ readFontSetSignature: Ee,
309
+ buildFootnoteRenderItems: ht,
310
+ describeInvalidHighlightMarks: gt,
311
+ emptyTemplatePreviewEntries: ut,
312
+ emptyTemplatePreviewHidden: dt,
313
+ hyphenationReadiness: jt,
314
+ markupView: c(me)
315
+ }, e, t));
316
+ } catch (e) {
317
+ let t = e instanceof Error ? e : Error(String(e));
318
+ S?.(t);
319
+ }
320
+ }
321
+ let X = h({
322
+ readState: () => j.value?.state ?? null,
323
+ runLayout: (e, t) => Y(e, t),
324
+ ...p,
325
+ clock: m
326
+ }), Z = null, Ft = Le();
327
+ function It() {
328
+ Z !== null && (window.clearTimeout(Z), Z = null);
329
+ let e = j.value, t = D.value;
330
+ if (!(!e || !t)) try {
331
+ let n = Q.api.getCanonicalDocument();
332
+ if (!n && V()) return;
333
+ let r = n ?? Ft.reconcile(Ie(e.state.doc, t), e.state.doc);
334
+ D.value = r, J(), et?.(H(r)), W.emit("docChange", H(r));
335
+ } catch (e) {
336
+ S?.(e instanceof Error ? e : Error(String(e)));
337
+ }
338
+ }
339
+ function Lt() {
340
+ Z !== null && window.clearTimeout(Z), Z = window.setTimeout(() => {
341
+ Z = null, It();
342
+ }, lt);
343
+ }
344
+ let Q = ne({
345
+ getHost: () => t.value,
346
+ getDocument: () => D.value,
347
+ getStyles: () => D.value?.package.styles ?? null,
348
+ getExtensionManager: () => U,
349
+ getExternalPlugins: kt,
350
+ getCollaboration: () => c(x),
351
+ getCollaborationModules: () => N.value,
352
+ getPrecomputedInitialState: () => null,
353
+ getReadOnly: () => c(u),
354
+ getExperimentalSession: () => c(_),
355
+ getEditingMode: () => c(y) ?? "editing",
356
+ getSuggestionAuthor: E,
357
+ onSessionRefusal: (e, t, n) => {
358
+ S?.(n ?? new g({
359
+ gap: t,
360
+ message: e
361
+ }));
362
+ },
363
+ getDocumentIdentity: () => String(O),
364
+ getDocumentContext: () => D.value,
365
+ onTransaction: zt,
366
+ onSelectionChange: (e) => {
367
+ M.value = e, C?.(e), W.emit("selectionChange", {
368
+ from: e.selection.from,
369
+ to: e.selection.to
370
+ });
371
+ },
372
+ onKeyDown: () => !1,
373
+ onCopy: () => nt?.(),
374
+ onCut: () => rt?.(),
375
+ onPaste: () => it?.(),
376
+ onReadOnlyEditAttempt: () => w?.(),
377
+ onEditorViewReady: Bt,
378
+ onEditorViewDestroy: () => {
379
+ j.value = null, R.value = !1, tt?.(null);
380
+ },
381
+ onRemoteSelectionsChange: (e) => {
382
+ P.value = e;
383
+ }
384
+ }), Rt = () => {
385
+ let e = c(x)?.awareness, t = N.value, n = Q.getView();
386
+ P.value = e && t && n ? te(n.state, e, t) : [];
387
+ };
388
+ l(() => c(x), (e, t, n) => {
389
+ if (P.value = [], !e) {
390
+ N.value = null, Q.retryViewCreation(), Q.syncExternalDocument();
391
+ return;
392
+ }
393
+ let r = !1;
394
+ n(() => {
395
+ r = !0;
396
+ }), N.value = null, xe().then((e) => {
397
+ r || (N.value = e, Q.retryViewCreation(), Q.syncExternalDocument(), Rt());
398
+ }, (e) => {
399
+ r || (N.value = null, S?.(e instanceof Error ? e : Error(String(e))));
400
+ });
401
+ }, { immediate: !0 }), l(() => ({
402
+ awareness: c(x)?.awareness,
403
+ modules: N.value,
404
+ view: j.value
405
+ }), ({ awareness: e, modules: t, view: n }, r, i) => {
406
+ if (!e || !t || !n) {
407
+ P.value = [];
408
+ return;
409
+ }
410
+ e.on("change", Rt), Rt(), i(() => {
411
+ e.off("change", Rt), P.value = [];
412
+ });
413
+ }, { flush: "post" });
414
+ function zt({ newState: e, docChanged: t, transactions: n }) {
415
+ M.value = e;
416
+ let r = n[0]?.before;
417
+ if (t && r && Ft.noteBase(r), t) {
418
+ let e = Q.api.getCanonicalDocument();
419
+ e && (D.value = e, J()), B.value = !0, G.incrementStateSeq(), X.schedule(), Lt();
420
+ }
421
+ G.requestRender();
422
+ }
423
+ function Bt(e) {
424
+ j.value = e, M.value = e.state, R.value = !0;
425
+ let t = D.value, n = O, r = ++k;
426
+ A = !0;
427
+ let i = () => {
428
+ k === r && (A = !1, !(_t || O !== n || Q.getView() !== e) && (Y(e.state, { reason: "initial" }), G.requestRender()));
429
+ };
430
+ De(t, e.state.doc).then(i, i), $(e), tt?.(e), c(u) || requestAnimationFrame(() => {
431
+ j.value === e && e.focus();
432
+ });
433
+ }
434
+ let Vt = {
435
+ getDocx: async (e) => (await Yt(e))?.buffer ?? null,
436
+ loadDocument: Jt,
437
+ loadDocx: qt
438
+ }, Ht = ge({
439
+ getEditorApi: () => Q.api,
440
+ getLayout: () => L.value,
441
+ runLayout: (e, t) => Y(e, t),
442
+ getDocumentIO: () => Vt,
443
+ emitter: W
444
+ });
445
+ function $(e) {
446
+ pe(c(y) === "suggesting", e.state, e.dispatch, E());
447
+ }
448
+ l([() => c(y), E], () => {
449
+ Ht.setCanonicalMode(c(y) === "suggesting" ? {
450
+ type: "suggesting",
451
+ author: E()
452
+ } : { type: "editing" });
453
+ let e = j.value;
454
+ e && $(e);
455
+ for (let e of q.listStories()) {
456
+ let t = q.getView(e);
457
+ t && $(t);
458
+ }
459
+ }), l(() => c(u), (e) => {
460
+ Q.syncEditable(), e && nn();
461
+ });
462
+ function Ut(e) {
463
+ let t = Ot();
464
+ if (t === e.state.plugins.includes(Tt)) return;
465
+ let n = e.state.plugins.filter((e) => e !== Tt && e !== Et);
466
+ if (t) {
467
+ let e = n.indexOf(Dt), t = e === -1 ? n.length : e;
468
+ n.splice(t, 0, Tt, Et);
469
+ }
470
+ e.updateState(e.state.reconfigure({ plugins: n }));
471
+ }
472
+ l(() => Ot(), () => {
473
+ let e = j.value;
474
+ e && Ut(e);
475
+ });
476
+ function Wt() {
477
+ Q.ensureView();
478
+ }
479
+ function Gt() {
480
+ O += 1, B.value = !1, F.value = null, I.value = null, q.activate(null), X.dispose(), Q.destroyView(), V() && Q.ensureView(), J(), Q.ensureView(), Q.getView() || Kt();
481
+ }
482
+ function Kt() {
483
+ let e = D.value;
484
+ if (!(!e || c(x))) try {
485
+ let t = re({
486
+ document: e,
487
+ styles: e.package.styles ?? null,
488
+ manager: U,
489
+ externalPlugins: kt(),
490
+ collaborationModules: null,
491
+ reason: "mount"
492
+ });
493
+ M.value = t;
494
+ let n = O, r = ++k;
495
+ A = !0;
496
+ let i = () => {
497
+ k === r && (A = !1, !(_t || O !== n || D.value !== e || Q.getView()) && Y(t, { reason: "initial" }));
498
+ };
499
+ De(e, t.doc).then(i, i);
500
+ } catch (e) {
501
+ S?.(e instanceof Error ? e : Error(String(e)));
502
+ }
503
+ }
504
+ l([
505
+ t,
506
+ a,
507
+ ot,
508
+ ...r ? [r] : []
509
+ ], () => {
510
+ t.value && D.value && !Q.getView() && Wt(), J();
511
+ }, { flush: "post" });
512
+ async function qt(e) {
513
+ z.value = null, R.value = !1;
514
+ try {
515
+ let t = e;
516
+ if (V()) {
517
+ let n = await ve(e);
518
+ if (n.isErr()) throw n.error;
519
+ t = n.value;
520
+ }
521
+ let n = await Ae(t, { password: c(v) });
522
+ D.value = n, Gt();
523
+ } catch (e) {
524
+ let t = e instanceof Error ? e : Error(String(e));
525
+ z.value = t.message, S?.(t);
526
+ }
527
+ }
528
+ function Jt(e) {
529
+ z.value = null, D.value = e, Ft.reset(), Gt();
530
+ }
531
+ async function Yt(e) {
532
+ let t = j.value, n = D.value;
533
+ if (!t || !n) return null;
534
+ try {
535
+ let t = Q.api.captureCanonicalSave();
536
+ if (t) {
537
+ let n = await be({
538
+ snapshot: t,
539
+ options: e,
540
+ featureFlags: c(T)
541
+ });
542
+ for (let t of n.diagnostics) e?.onDiagnostic || S?.(new ye({
543
+ gap: d.save,
544
+ diagnostic: t,
545
+ message: `Canonical save used a fidelity fallback: ${t.type} (${t.part}).`
546
+ }));
547
+ return n.tripwireResult && at?.(n.tripwireResult), n;
548
+ }
549
+ } catch (e) {
550
+ return S?.(e instanceof Error ? e : Error(String(e))), null;
551
+ }
552
+ if (V()) return null;
553
+ Z !== null && It();
554
+ let r = q.snapshotDocument(K.snapshotDocument(n)), i = t.state, a = Re(Ie(i.doc, r)), { resolveSelectiveSaveFlags: o } = await import("@stll/folio-core/docx/selectiveSaveFlags"), s = o(c(T)), l = a.originalBuffer ?? null, u = s.selectiveSave && e?.mode !== he.full, f = u || s.selectiveSaveTripwire, { repackDocx: ee, createDocx: p } = await import("@stll/folio-core/docx/rezip"), m = null;
555
+ if (f && l) {
556
+ let { attemptSelectiveSave: e } = await import("@stll/folio-core/docx/selectiveSave");
557
+ m = await e(a, l, {
558
+ changedParaIds: Be(i),
559
+ structuralChange: Ve(i),
560
+ hasUntrackedChanges: He(i),
561
+ maxBytes: s.selectiveSaveMaxBytes
562
+ });
563
+ }
564
+ let h = u ? m : null, g = null, te = () => Ue({
565
+ state: i,
566
+ document: a,
567
+ repack: () => ee(a)
568
+ });
569
+ if (!h) g = l ? await te() : await p(a), h = g;
570
+ else if (s.selectiveSaveTripwire) try {
571
+ g = await te();
572
+ } catch {}
573
+ if (s.selectiveSaveTripwire && g && at) try {
574
+ let { compareSelectiveVsFull: e } = await import("@stll/folio-core/docx/selectiveSaveTripwire");
575
+ at(await e(m, g));
576
+ } catch {}
577
+ return {
578
+ buffer: h,
579
+ document: a
580
+ };
581
+ }
582
+ async function Xt(e) {
583
+ let t = j.value, n = t?.state, r = await Yt({ mode: e?.selective === !1 ? he.full : he.preferSelective });
584
+ return r ? (j.value === t && t?.state.doc === n?.doc && (r.version === void 0 || Q.api.isCanonicalSaveCurrent(r.version)) && (D.value = r.document, J(), B.value = !1), new Blob([r.buffer], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" })) : null;
585
+ }
586
+ function Zt() {
587
+ let e = Q.api.getCanonicalDocument();
588
+ if (e) return e;
589
+ if (V()) return null;
590
+ let t = D.value;
591
+ return t ? H(q.snapshotDocument(K.snapshotDocument(t))) : null;
592
+ }
593
+ function Qt(e) {
594
+ bt(d.modelEdits, "Direct document model changes are unavailable in this session.") || (D.value = e, J(), I.value && !q.getView(I.value) && (I.value = null));
595
+ }
596
+ function $t(e) {
597
+ return K.getView(e);
598
+ }
599
+ function en() {
600
+ J();
601
+ }
602
+ function tn(e) {
603
+ let t = q.activate(e);
604
+ t && ($(t), I.value = e, requestAnimationFrame(() => t.focus()));
605
+ }
606
+ function nn() {
607
+ q.activate(null), I.value = null;
608
+ }
609
+ function rn() {
610
+ let e = I.value;
611
+ return e ? q.getView(e) : null;
612
+ }
613
+ function an() {
614
+ return U.getCommands();
615
+ }
616
+ function on() {
617
+ let e = rn();
618
+ e ? e.focus() : j.value?.focus();
619
+ }
620
+ function sn() {
621
+ let e = j.value;
622
+ e && Y(e.state, { reason: "manual" });
623
+ }
624
+ l([
625
+ () => c(je),
626
+ () => c(Me),
627
+ () => c(ce),
628
+ () => c(me)
629
+ ], () => sn());
630
+ function cn() {
631
+ _t = !0, k += 1, A = !1, X.dispose(), Z !== null && (window.clearTimeout(Z), Z = null), Q.destroyView(), P.value = [], K.destroy(), q.destroy(), U.destroy(), M.value = null, L.value = null, D.value = null, R.value = !1;
632
+ }
633
+ return i(cn), {
634
+ editor: Ht,
635
+ editorView: j,
636
+ editorState: M,
637
+ remoteSelections: P,
638
+ headerFooterSelection: F,
639
+ activeNoteStory: I,
640
+ isReady: R,
641
+ isDirty: B,
642
+ parseError: z,
643
+ layout: L,
644
+ blocks: vt,
645
+ measures: yt,
646
+ syncCoordinator: G,
647
+ loadBuffer: qt,
648
+ loadDocument: Jt,
649
+ save: Xt,
650
+ getDocument: Zt,
651
+ setDocument: Qt,
652
+ getHeaderFooterView: $t,
653
+ syncHeaderFooterViews: en,
654
+ openNoteStory: tn,
655
+ closeNoteStory: nn,
656
+ getActiveNoteView: rn,
657
+ getCommands: an,
658
+ focus: on,
659
+ reLayout: sn,
660
+ destroy: cn
661
+ };
662
+ }
663
+ function _t(e, t) {
664
+ if (t < e.top + 40) {
665
+ let n = Math.max(0, e.top + 40 - t);
666
+ return -Math.min(12, n / 40 * 12);
667
+ }
668
+ if (t > e.bottom - 40) {
669
+ let n = Math.max(0, t - (e.bottom - 40));
670
+ return Math.min(12, n / 40 * 12);
671
+ }
672
+ return 0;
673
+ }
674
+ //#endregion
675
+ //#region src/composables/useDragAutoScroll.ts
676
+ function k({ pagesContainer: e, onScrollExtendSelection: t }) {
677
+ let n = null, r = 0, a = 0, o = !1;
678
+ function s() {
679
+ return se(e.value);
680
+ }
681
+ function c() {
682
+ o = !1, n !== null && (cancelAnimationFrame(n), n = null);
683
+ }
684
+ function l() {
685
+ if (!o) return;
686
+ let e = s();
687
+ if (!e) return;
688
+ let i = _t(e.getBoundingClientRect(), a);
689
+ i !== 0 && (ce(e, i), t(r, a)), n = requestAnimationFrame(l);
690
+ }
691
+ function u() {
692
+ o || (o = !0, n = requestAnimationFrame(l));
693
+ }
694
+ function d(e, t) {
695
+ if (r = e, a = t, !o) {
696
+ let e = s();
697
+ if (!e) return;
698
+ let n = e.getBoundingClientRect();
699
+ (t < n.top + 40 || t > n.bottom - 40) && u();
700
+ }
701
+ }
702
+ return i(() => c()), {
703
+ updateMousePosition: d,
704
+ stopAutoScroll: c
705
+ };
706
+ }
707
+ //#endregion
708
+ //#region src/composables/useTableResize.ts
709
+ function A() {
710
+ let e = {
711
+ active: !1,
712
+ startX: 0,
713
+ handle: null,
714
+ columnIndex: 0,
715
+ tablePmStart: 0,
716
+ origWidths: {
717
+ left: 0,
718
+ right: 0
719
+ }
720
+ }, t = {
721
+ active: !1,
722
+ startY: 0,
723
+ handle: null,
724
+ rowIndex: 0,
725
+ isEdge: !1,
726
+ tablePmStart: 0,
727
+ origHeight: 0
728
+ }, n = {
729
+ active: !1,
730
+ startX: 0,
731
+ handle: null,
732
+ columnIndex: 0,
733
+ tablePmStart: 0,
734
+ origWidth: 0
735
+ }, r = null;
736
+ function i() {
737
+ return e.active || t.active || n.active;
738
+ }
739
+ function a(i, a) {
740
+ let o = i.target;
741
+ return o instanceof HTMLElement ? o.classList.contains("layout-table-resize-handle") ? (i.preventDefault(), i.stopPropagation(), r = a, e.active = !0, e.startX = i.clientX, e.handle = o, o.classList.add("dragging"), e.columnIndex = parseInt(o.dataset.columnIndex ?? "0", 10), e.tablePmStart = parseInt(o.dataset.tablePmStart ?? "0", 10), j(a, e), !0) : o.classList.contains("layout-table-row-resize-handle") || o.classList.contains("layout-table-edge-handle-bottom") ? (i.preventDefault(), i.stopPropagation(), r = a, t.active = !0, t.startY = i.clientY, t.handle = o, t.isEdge = o.dataset.isEdge === "bottom", o.classList.add("dragging"), t.rowIndex = parseInt(o.dataset.rowIndex ?? "0", 10), t.tablePmStart = parseInt(o.dataset.tablePmStart ?? "0", 10), M(a, t, o), !0) : o.classList.contains("layout-table-edge-handle-right") ? (i.preventDefault(), i.stopPropagation(), r = a, n.active = !0, n.startX = i.clientX, n.handle = o, o.classList.add("dragging"), n.columnIndex = parseInt(o.dataset.columnIndex ?? "0", 10), n.tablePmStart = parseInt(o.dataset.tablePmStart ?? "0", 10), N(a, n), !0) : !1 : !1;
742
+ }
743
+ function o(r) {
744
+ if (e.active && e.handle) {
745
+ r.preventDefault();
746
+ let t = r.clientX - e.startX, n = parseFloat(e.handle.style.left);
747
+ e.handle.style.left = `${n + t}px`, e.startX = r.clientX;
748
+ let i = Math.round(t * b), a = e.origWidths.left + i, o = e.origWidths.right - i;
749
+ a >= v && o >= v && (e.origWidths = {
750
+ left: a,
751
+ right: o
752
+ });
753
+ return;
754
+ }
755
+ if (t.active && t.handle) {
756
+ r.preventDefault();
757
+ let e = r.clientY - t.startY, n = parseFloat(t.handle.style.top);
758
+ t.handle.style.top = `${n + e}px`, t.startY = r.clientY;
759
+ let i = Math.round(e * b), a = t.origHeight + i;
760
+ a >= y && (t.origHeight = a);
761
+ return;
762
+ }
763
+ if (n.active && n.handle) {
764
+ r.preventDefault();
765
+ let e = r.clientX - n.startX, t = parseFloat(n.handle.style.left);
766
+ n.handle.style.left = `${t + e}px`, n.startX = r.clientX;
767
+ let i = Math.round(e * b), a = n.origWidth + i;
768
+ a >= v && (n.origWidth = a);
769
+ }
770
+ }
771
+ function s(i) {
772
+ if (e.active) {
773
+ e.active = !1, e.handle?.classList.remove("dragging"), r && Je(r, {
774
+ pmStart: e.tablePmStart,
775
+ colIdx: e.columnIndex,
776
+ newLeft: e.origWidths.left,
777
+ newRight: e.origWidths.right
778
+ }), e.handle = null;
779
+ return;
780
+ }
781
+ if (t.active) {
782
+ t.active = !1, t.handle?.classList.remove("dragging"), r && x(r, {
783
+ pmStart: t.tablePmStart,
784
+ rowIdx: t.rowIndex,
785
+ newHeight: t.origHeight
786
+ }), t.handle = null;
787
+ return;
788
+ }
789
+ n.active && (n.active = !1, n.handle?.classList.remove("dragging"), r && Ye(r, {
790
+ pmStart: n.tablePmStart,
791
+ colIdx: n.columnIndex,
792
+ newWidth: n.origWidth
793
+ }), n.handle = null);
794
+ }
795
+ function c() {
796
+ return document.addEventListener("mousemove", o), document.addEventListener("mouseup", s), () => {
797
+ document.removeEventListener("mousemove", o), document.removeEventListener("mouseup", s);
798
+ };
799
+ }
800
+ return {
801
+ tryStartResize: a,
802
+ install: c,
803
+ isResizing: i
804
+ };
805
+ }
806
+ function j(e, t) {
807
+ let n = Ze(e, t.tablePmStart, t.columnIndex);
808
+ n && (t.origWidths = n);
809
+ }
810
+ function M(e, t, n) {
811
+ let r = Qe(e, t.tablePmStart, t.rowIndex);
812
+ if (r != null) {
813
+ t.origHeight = r;
814
+ return;
815
+ }
816
+ let i = n.closest(".layout-table")?.querySelector(`[data-row-index="${t.rowIndex}"]`), a = i ? i.getBoundingClientRect().height : 30;
817
+ t.origHeight = Math.round(a * b);
818
+ }
819
+ function N(e, t) {
820
+ let n = Xe(e, t.tablePmStart, t.columnIndex);
821
+ n != null && (t.origWidth = n);
822
+ }
823
+ //#endregion
824
+ //#region src/composables/useTrackedChanges.ts
825
+ function P(t, n) {
826
+ return e(() => (n.value, $e(t.value?.state ?? null)));
827
+ }
828
+ //#endregion
829
+ //#region src/composables/useZoom.ts
830
+ var F = S, I = et, L = [
831
+ .5,
832
+ .75,
833
+ 1,
834
+ 1.25,
835
+ 1.5,
836
+ 2
837
+ ];
838
+ function vt(t = 1) {
839
+ let i = o(Math.max(F, Math.min(I, t))), a = e(() => Math.round(i.value * 100)), s = e(() => i.value <= F), c = e(() => i.value >= I);
840
+ function l(e) {
841
+ i.value = Math.max(F, Math.min(I, Math.round(e * 100) / 100));
842
+ }
843
+ function u() {
844
+ l(i.value + C);
845
+ }
846
+ function d() {
847
+ l(i.value - C);
848
+ }
849
+ function f() {
850
+ l(1);
851
+ }
852
+ function ee(e) {
853
+ (e.ctrlKey || e.metaKey) && (e.preventDefault(), e.deltaY < 0 ? u() : d());
854
+ }
855
+ function p(e) {
856
+ (e.ctrlKey || e.metaKey) && (e.shiftKey || e.altKey || (e.key === "=" || e.key === "+" ? (e.preventDefault(), u()) : e.key === "-" ? (e.preventDefault(), d()) : e.key === "0" && (e.preventDefault(), f())));
857
+ }
858
+ function m() {
859
+ r(() => document.addEventListener("keydown", p)), n(() => document.removeEventListener("keydown", p));
860
+ }
861
+ return {
862
+ zoom: i,
863
+ zoomPercent: a,
864
+ isMinZoom: s,
865
+ isMaxZoom: c,
866
+ setZoom: l,
867
+ zoomIn: u,
868
+ zoomOut: d,
869
+ resetZoom: f,
870
+ handleWheel: ee,
871
+ handleKeyDown: p,
872
+ installShortcuts: m,
873
+ ZOOM_PRESETS: L
874
+ };
875
+ }
876
+ //#endregion
877
+ export { k as a, w as c, A as i, at as l, $e as n, O as o, P as r, ot as s, vt as t, E as u };