@stll/folio-vue 0.32.0 → 0.32.1

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