@stll/folio-vue 0.21.1 → 0.21.2

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