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