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