@eigenpal/docx-editor-vue 1.0.3 → 1.2.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,485 +0,0 @@
1
- import { computed as e, onBeforeUnmount as t, onMounted as n, ref as r, shallowRef as i, unref as a } from "vue";
2
- import { EditorState as o } from "prosemirror-state";
3
- import { EditorView as s } from "prosemirror-view";
4
- import { singletonManager as c } from "@eigenpal/docx-editor-core/prosemirror/schema";
5
- import { createEmptyDoc as l, toProseDoc as u } from "@eigenpal/docx-editor-core/prosemirror/conversion";
6
- import "prosemirror-view/style/prosemirror.css";
7
- import { parseDocx as d } from "@eigenpal/docx-editor-core/docx/parser";
8
- import { fromProseDoc as f } from "@eigenpal/docx-editor-core/prosemirror/conversion/fromProseDoc";
9
- import { toFlowBlocks as p } from "@eigenpal/docx-editor-core/layout-bridge/toFlowBlocks";
10
- import { measureBlocksWithFloats as m, measureParagraph as h } from "@eigenpal/docx-editor-core/layout-bridge/measuring";
11
- import { buildFootnoteContentMap as g, buildFootnoteRenderItems as _, collectFootnoteRefs as v, convertHeaderFooterToContent as y, getMargins as b, getPageSize as x, measureTableBlock as S, resolveHeaderFooter as C, stabilizeFootnoteLayout as w } from "@eigenpal/docx-editor-core/layout-bridge";
12
- import { DEFAULT_TEXTBOX_MARGINS as T, DEFAULT_TEXTBOX_WIDTH as E, assertExhaustiveFlowBlock as D, layoutDocument as ee } from "@eigenpal/docx-editor-core/layout-engine";
13
- import { renderPages as te } from "@eigenpal/docx-editor-core/layout-painter/renderPage";
14
- import "@eigenpal/docx-editor-core/prosemirror/editor.css";
15
- //#region src/composables/useDocxEditor.ts
16
- var O = 24;
17
- function k(e, t, n, r) {
18
- switch (e.kind) {
19
- case "paragraph": return h(e, t, {
20
- floatingZones: n,
21
- paragraphYOffset: r ?? 0
22
- });
23
- case "table": return S(e, t, k);
24
- case "image": {
25
- let t = e;
26
- return {
27
- kind: "image",
28
- width: t.width ?? 100,
29
- height: t.height ?? 100
30
- };
31
- }
32
- case "textBox": {
33
- let t = e, n = t.margins ?? T, r = (t.width ?? E) - n.left - n.right, i = t.content.map((e) => h(e, r)), a = i.reduce((e, t) => e + t.totalHeight, 0), o = t.height ?? a + n.top + n.bottom;
34
- return {
35
- kind: "textBox",
36
- width: t.width ?? E,
37
- height: o,
38
- innerMeasures: i
39
- };
40
- }
41
- case "pageBreak": return { kind: "pageBreak" };
42
- case "columnBreak": return { kind: "columnBreak" };
43
- case "sectionBreak": return { kind: "sectionBreak" };
44
- default: D(e, "vue useDocxEditor measureBlock");
45
- }
46
- }
47
- function A(e, t) {
48
- return m(e, t, k);
49
- }
50
- function j(e) {
51
- let { hiddenContainer: n, pagesContainer: m, readOnly: h = !1, pageGap: S = O, onChange: T, onError: E, onSelectionUpdate: D, externalPlugins: k = [], syncCoordinator: j } = e, M = i(null), N = i(null), P = i(null), F = r(!1), I = r(null), L = i(null), R = c;
52
- function z(e) {
53
- let t = m.value;
54
- if (!t || !M.value) return;
55
- let n = j?.getStateSeq() ?? 0;
56
- j?.onLayoutStart();
57
- let r = M.value.package?.document, i = r?.sections?.[0]?.properties ?? r?.finalSectionProperties ?? null, a = r?.finalSectionProperties ?? i, o = x(i), s = b(i), c = x(a), l = b(a), u = o.w - s.left - s.right, d = o.h - s.top - s.bottom, f = M.value.package?.theme ?? null, h = M.value.package?.styles ?? null;
58
- try {
59
- let n = p(e.doc, {
60
- theme: f,
61
- pageContentHeight: d
62
- }), r = A(n, u), { header: a, footer: m, firstHeader: b, firstFooter: x } = C(M.value, i), T = {
63
- section: "header",
64
- pageSize: o,
65
- margins: s
66
- }, E = {
67
- section: "footer",
68
- pageSize: o,
69
- margins: s
70
- }, D = e.doc.attrs?.defaultTabStopTwips, O = {
71
- styles: h,
72
- theme: f,
73
- measureBlocks: A,
74
- defaultTabStopTwips: D
75
- }, k = y(a, u, T, O), j = y(m, u, E, O), N = i?.titlePg === !0, P = N ? y(b, u, T, O) : void 0, F = N ? y(x, u, E, O) : void 0, I = s.header ?? 48, R = s.footer ?? 48, z = s.top - I, B = s.bottom - R, V = (e) => e ? e.visualBottom ?? e.height : 0, H = (e) => e ? Math.max((e.visualBottom ?? e.height) - (e.visualTop ?? 0), e.height) : 0, U = Math.max(V(k), V(P)), W = Math.max(H(j), H(F)), G = U > z, K = W > B;
76
- if (G || K) {
77
- let e = (e) => {
78
- let t = { ...e };
79
- return G && (t.top = Math.max(e.top, I + U)), K && (t.bottom = Math.max(e.bottom, R + W)), t;
80
- };
81
- s = e(s), l = e(l);
82
- for (let t of n) {
83
- if (t.kind !== "sectionBreak") continue;
84
- let n = t;
85
- n.margins &&= e(n.margins);
86
- }
87
- }
88
- let q = {
89
- pageSize: o,
90
- margins: s,
91
- finalPageSize: c,
92
- finalMargins: l,
93
- pageGap: S
94
- }, J = v(n), Y = J.length > 0 && !!M.value.package?.footnotes, X = ee(n, r, q), Z = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map();
95
- if (Y) {
96
- Q = g(M.value.package.footnotes, J, u, {
97
- styles: h,
98
- theme: f,
99
- measureBlocks: A,
100
- defaultTabStopTwips: D
101
- });
102
- let e = w({
103
- blocks: n,
104
- measures: r,
105
- layoutOpts: q,
106
- footnoteRefs: J,
107
- footnoteContentMap: Q,
108
- initialLayout: X
109
- });
110
- X = e.layout, Z = e.pageFootnoteMap;
111
- }
112
- L.value = X;
113
- let $ = /* @__PURE__ */ new Map();
114
- for (let e = 0; e < n.length; e++) {
115
- let t = n[e], i = r[e];
116
- t && i && $.set(String(t.id), {
117
- block: t,
118
- measure: i
119
- });
120
- }
121
- let ne = Y ? _(Z, Q, M.value) : void 0;
122
- te(X.pages, t, {
123
- pageGap: S,
124
- showShadow: !0,
125
- pageBackground: "#fff",
126
- blockLookup: $,
127
- theme: f,
128
- headerContent: k,
129
- footerContent: j,
130
- firstPageHeaderContent: P,
131
- firstPageFooterContent: F,
132
- titlePage: N,
133
- footnotesByPage: ne
134
- }), t.style.overflowY = "auto", t.style.minHeight = "0";
135
- for (let e of Array.from(t.children)) e.style.flexShrink = "0";
136
- } catch (e) {
137
- console.error("[useDocxEditor] Layout pipeline error:", e), E?.(e instanceof Error ? e : Error(String(e)));
138
- } finally {
139
- j?.onLayoutComplete(n);
140
- }
141
- }
142
- function B() {
143
- let e = n.value;
144
- if (!e) return;
145
- let t = M.value ? u(M.value, { styles: M.value.package?.styles ?? void 0 }) : l(), r = [...k, ...R.getPlugins() ?? []], i = o.create({
146
- doc: t,
147
- schema: R.getSchema(),
148
- plugins: r
149
- });
150
- P.value = i;
151
- let c = new s(e, {
152
- state: i,
153
- editable: () => !a(h),
154
- dispatchTransaction(e) {
155
- if (!c) return;
156
- let t = c.state.apply(e);
157
- if (c.updateState(t), P.value = t, e.docChanged) {
158
- j?.incrementStateSeq(), z(t);
159
- try {
160
- if (M.value) {
161
- let e = f(t.doc, M.value);
162
- M.value = e, T?.(e);
163
- }
164
- } catch (e) {
165
- console.error("[useDocxEditor] fromProseDoc error:", e);
166
- }
167
- }
168
- j?.requestRender(), D?.();
169
- }
170
- });
171
- N.value = c, F.value = !0, z(i), j?.requestRender();
172
- }
173
- function V() {
174
- N.value &&= (N.value.destroy(), null), P.value = null, F.value = !1;
175
- }
176
- async function H(e) {
177
- I.value = null, F.value = !1;
178
- try {
179
- let t;
180
- t = e instanceof Blob || e instanceof File ? await e.arrayBuffer() : e instanceof Uint8Array ? e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength) : e, M.value = await d(t), V(), B();
181
- } catch (e) {
182
- let t = e instanceof Error ? e : Error(String(e));
183
- I.value = t.message, E?.(t);
184
- }
185
- }
186
- function U(e) {
187
- I.value = null, M.value = e, V(), B();
188
- }
189
- async function W() {
190
- if (!N.value || !M.value) return null;
191
- let { repackDocx: e, createDocx: t } = await import("@eigenpal/docx-editor-core/docx/rezip"), { injectReplyRangeMarkers: n, injectTCReplyRangeMarkers: r } = await import("@eigenpal/docx-editor-core/docx"), i = f(N.value.state.doc, M.value), a = i.package.document?.comments ?? [];
192
- i.package.document?.content && a.length > 0 && (n(i.package.document.content, a), r(i.package.document.content, a));
193
- let o;
194
- return o = i.originalBuffer ? await e(i) : await t(i), new Blob([o], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
195
- }
196
- function G() {
197
- N.value?.focus();
198
- }
199
- function K() {
200
- V(), M.value = null;
201
- }
202
- function q() {
203
- return M.value;
204
- }
205
- t(() => {
206
- K();
207
- });
208
- function J() {
209
- return R.getCommands();
210
- }
211
- return {
212
- editorView: N,
213
- editorState: P,
214
- isReady: F,
215
- parseError: I,
216
- layout: L,
217
- loadBuffer: H,
218
- loadDocument: U,
219
- save: W,
220
- focus: G,
221
- destroy: K,
222
- getDocument: q,
223
- getCommands: J,
224
- reLayout() {
225
- N.value && z(N.value.state);
226
- }
227
- };
228
- }
229
- //#endregion
230
- //#region src/composables/useZoom.ts
231
- var M = .25, N = 4, P = .1, F = [
232
- .25,
233
- .5,
234
- .75,
235
- 1,
236
- 1.25,
237
- 1.5,
238
- 2,
239
- 3,
240
- 4
241
- ];
242
- function I(i = 1) {
243
- let a = r(Math.max(M, Math.min(N, i))), o = e(() => Math.round(a.value * 100)), s = e(() => a.value <= M), c = e(() => a.value >= N);
244
- function l(e) {
245
- a.value = Math.max(M, Math.min(N, Math.round(e * 100) / 100));
246
- }
247
- function u() {
248
- l(a.value + P);
249
- }
250
- function d() {
251
- l(a.value - P);
252
- }
253
- function f() {
254
- l(1);
255
- }
256
- function p(e) {
257
- (e.ctrlKey || e.metaKey) && (e.preventDefault(), e.deltaY < 0 ? u() : d());
258
- }
259
- function m(e) {
260
- (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())));
261
- }
262
- function h() {
263
- n(() => document.addEventListener("keydown", m)), t(() => document.removeEventListener("keydown", m));
264
- }
265
- return {
266
- zoom: a,
267
- zoomPercent: o,
268
- isMinZoom: s,
269
- isMaxZoom: c,
270
- setZoom: l,
271
- zoomIn: u,
272
- zoomOut: d,
273
- resetZoom: f,
274
- handleWheel: p,
275
- handleKeyDown: m,
276
- installShortcuts: h,
277
- ZOOM_PRESETS: F
278
- };
279
- }
280
- //#endregion
281
- //#region src/composables/useTableResize.ts
282
- var L = 15, R = 300, z = 200, B = 15;
283
- function V() {
284
- let e = {
285
- active: !1,
286
- startX: 0,
287
- handle: null,
288
- columnIndex: 0,
289
- tablePmStart: 0,
290
- origWidths: {
291
- left: 0,
292
- right: 0
293
- }
294
- }, t = {
295
- active: !1,
296
- startY: 0,
297
- handle: null,
298
- rowIndex: 0,
299
- isEdge: !1,
300
- tablePmStart: 0,
301
- origHeight: 0
302
- }, n = {
303
- active: !1,
304
- startX: 0,
305
- handle: null,
306
- columnIndex: 0,
307
- tablePmStart: 0,
308
- origWidth: 0
309
- }, r = null;
310
- function i() {
311
- return e.active || t.active || n.active;
312
- }
313
- function a(i, a) {
314
- let o = i.target;
315
- return o?.classList ? 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), W(a, n), !0) : !1 : !1;
316
- }
317
- function o(r) {
318
- if (e.active && e.handle) {
319
- r.preventDefault();
320
- let t = r.clientX - e.startX, n = parseFloat(e.handle.style.left);
321
- e.handle.style.left = `${n + t}px`, e.startX = r.clientX;
322
- let i = Math.round(t * L), a = e.origWidths.left + i, o = e.origWidths.right - i;
323
- a >= R && o >= R && (e.origWidths = {
324
- left: a,
325
- right: o
326
- });
327
- return;
328
- }
329
- if (t.active && t.handle) {
330
- r.preventDefault();
331
- let e = r.clientY - t.startY, n = parseFloat(t.handle.style.top);
332
- t.handle.style.top = `${n + e}px`, t.startY = r.clientY;
333
- let i = Math.round(e * L), a = t.origHeight + i;
334
- a >= z && (t.origHeight = a);
335
- return;
336
- }
337
- if (n.active && n.handle) {
338
- r.preventDefault();
339
- let e = r.clientX - n.startX, t = parseFloat(n.handle.style.left);
340
- n.handle.style.left = `${t + e}px`, n.startX = r.clientX;
341
- let i = Math.round(e * L), a = n.origWidth + i;
342
- a >= R && (n.origWidth = a);
343
- }
344
- }
345
- function s(i) {
346
- if (e.active) {
347
- e.active = !1, e.handle?.classList.remove("dragging"), r && G(r, e), e.handle = null;
348
- return;
349
- }
350
- if (t.active) {
351
- t.active = !1, t.handle?.classList.remove("dragging"), r && K(r, t), t.handle = null;
352
- return;
353
- }
354
- n.active && (n.active = !1, n.handle?.classList.remove("dragging"), r && q(r, n), n.handle = null);
355
- }
356
- function c() {
357
- return document.addEventListener("mousemove", o), document.addEventListener("mouseup", s), () => {
358
- document.removeEventListener("mousemove", o), document.removeEventListener("mouseup", s);
359
- };
360
- }
361
- return {
362
- tryStartResize: a,
363
- install: c,
364
- isResizing: i
365
- };
366
- }
367
- function H(e, t) {
368
- let n = e.state.doc.resolve(t.tablePmStart + 1);
369
- for (let e = n.depth; e >= 0; e--) {
370
- let r = n.node(e);
371
- if (r.type.name === "table") {
372
- let e = r.attrs.columnWidths;
373
- e && e[t.columnIndex] !== void 0 && e[t.columnIndex + 1] !== void 0 && (t.origWidths = {
374
- left: e[t.columnIndex],
375
- right: e[t.columnIndex + 1]
376
- });
377
- return;
378
- }
379
- }
380
- }
381
- function U(e, t, n) {
382
- let r = e.state.doc.resolve(t.tablePmStart + 1);
383
- for (let e = r.depth; e >= 0; e--) {
384
- let i = r.node(e);
385
- if (i.type.name === "table") {
386
- let e = null, r = 0;
387
- if (i.forEach((n) => {
388
- r === t.rowIndex && (e = n), r++;
389
- }), e) {
390
- let r = e.attrs.height;
391
- if (r) t.origHeight = r;
392
- else {
393
- let e = n.closest(".layout-table")?.querySelector(`[data-row-index="${t.rowIndex}"]`), r = e ? e.getBoundingClientRect().height : 30;
394
- t.origHeight = Math.round(r * B);
395
- }
396
- }
397
- return;
398
- }
399
- }
400
- }
401
- function W(e, t) {
402
- let n = e.state.doc.resolve(t.tablePmStart + 1);
403
- for (let e = n.depth; e >= 0; e--) {
404
- let r = n.node(e);
405
- if (r.type.name === "table") {
406
- let e = r.attrs.columnWidths;
407
- e && e[t.columnIndex] !== void 0 && (t.origWidth = e[t.columnIndex]);
408
- return;
409
- }
410
- }
411
- }
412
- function G(e, t) {
413
- let n = e.state.doc.resolve(t.tablePmStart + 1);
414
- for (let r = n.depth; r >= 0; r--) {
415
- let i = n.node(r);
416
- if (i.type.name !== "table") continue;
417
- let a = n.before(r), o = e.state.tr, s = [...i.attrs.columnWidths || []];
418
- s[t.columnIndex] = t.origWidths.left, s[t.columnIndex + 1] = t.origWidths.right, o.setNodeMarkup(a, void 0, {
419
- ...i.attrs,
420
- columnWidths: s
421
- });
422
- let c = a + 1;
423
- i.forEach((e) => {
424
- let n = c + 1, r = 0;
425
- e.forEach((e) => {
426
- let i = e.attrs.colspan || 1;
427
- if (r === t.columnIndex || r === t.columnIndex + 1) {
428
- let i = r === t.columnIndex ? t.origWidths.left : t.origWidths.right;
429
- o.setNodeMarkup(o.mapping.map(n), void 0, {
430
- ...e.attrs,
431
- width: i,
432
- widthType: "dxa",
433
- colwidth: null
434
- });
435
- }
436
- n += e.nodeSize, r += i;
437
- }), c += e.nodeSize;
438
- }), e.dispatch(o);
439
- return;
440
- }
441
- }
442
- function K(e, t) {
443
- let n = e.state.doc.resolve(t.tablePmStart + 1);
444
- for (let r = n.depth; r >= 0; r--) {
445
- let i = n.node(r);
446
- if (i.type.name !== "table") continue;
447
- let a = n.before(r), o = e.state.tr, s = a + 1, c = 0;
448
- i.forEach((e) => {
449
- c === t.rowIndex && o.setNodeMarkup(o.mapping.map(s), void 0, {
450
- ...e.attrs,
451
- height: t.origHeight,
452
- heightRule: "atLeast"
453
- }), s += e.nodeSize, c++;
454
- }), e.dispatch(o);
455
- return;
456
- }
457
- }
458
- function q(e, t) {
459
- let n = e.state.doc.resolve(t.tablePmStart + 1);
460
- for (let r = n.depth; r >= 0; r--) {
461
- let i = n.node(r);
462
- if (i.type.name !== "table") continue;
463
- let a = n.before(r), o = e.state.tr, s = [...i.attrs.columnWidths || []];
464
- s[t.columnIndex] = t.origWidth, o.setNodeMarkup(a, void 0, {
465
- ...i.attrs,
466
- columnWidths: s
467
- });
468
- let c = a + 1;
469
- i.forEach((e) => {
470
- let n = c + 1, r = 0;
471
- e.forEach((e) => {
472
- let i = e.attrs.colspan || 1;
473
- r === t.columnIndex && o.setNodeMarkup(o.mapping.map(n), void 0, {
474
- ...e.attrs,
475
- width: t.origWidth,
476
- widthType: "dxa",
477
- colwidth: null
478
- }), n += e.nodeSize, r += i;
479
- }), c += e.nodeSize;
480
- }), e.dispatch(o);
481
- return;
482
- }
483
- }
484
- //#endregion
485
- export { I as n, j as r, V as t };
@@ -1 +0,0 @@
1
- let e=require(`vue`),t=require(`prosemirror-state`),n=require(`prosemirror-view`),r=require(`@eigenpal/docx-editor-core/prosemirror/schema`),i=require(`@eigenpal/docx-editor-core/prosemirror/conversion`);require(`prosemirror-view/style/prosemirror.css`);let a=require(`@eigenpal/docx-editor-core/docx/parser`),o=require(`@eigenpal/docx-editor-core/prosemirror/conversion/fromProseDoc`),s=require(`@eigenpal/docx-editor-core/layout-bridge/toFlowBlocks`),c=require(`@eigenpal/docx-editor-core/layout-bridge/measuring`),l=require(`@eigenpal/docx-editor-core/layout-bridge`),u=require(`@eigenpal/docx-editor-core/layout-engine`),d=require(`@eigenpal/docx-editor-core/layout-painter/renderPage`);require(`@eigenpal/docx-editor-core/prosemirror/editor.css`);var f=24;function p(e,t,n,r){switch(e.kind){case`paragraph`:return(0,c.measureParagraph)(e,t,{floatingZones:n,paragraphYOffset:r??0});case`table`:return(0,l.measureTableBlock)(e,t,p);case`image`:{let t=e;return{kind:`image`,width:t.width??100,height:t.height??100}}case`textBox`:{let t=e,n=t.margins??u.DEFAULT_TEXTBOX_MARGINS,r=(t.width??u.DEFAULT_TEXTBOX_WIDTH)-n.left-n.right,i=t.content.map(e=>(0,c.measureParagraph)(e,r)),a=i.reduce((e,t)=>e+t.totalHeight,0),o=t.height??a+n.top+n.bottom;return{kind:`textBox`,width:t.width??u.DEFAULT_TEXTBOX_WIDTH,height:o,innerMeasures:i}}case`pageBreak`:return{kind:`pageBreak`};case`columnBreak`:return{kind:`columnBreak`};case`sectionBreak`:return{kind:`sectionBreak`};default:(0,u.assertExhaustiveFlowBlock)(e,`vue useDocxEditor measureBlock`)}}function m(e,t){return(0,c.measureBlocksWithFloats)(e,t,p)}function h(c){let{hiddenContainer:p,pagesContainer:h,readOnly:g=!1,pageGap:_=f,onChange:v,onError:y,onSelectionUpdate:b,externalPlugins:x=[],syncCoordinator:S}=c,C=(0,e.shallowRef)(null),w=(0,e.shallowRef)(null),T=(0,e.shallowRef)(null),E=(0,e.ref)(!1),D=(0,e.ref)(null),O=(0,e.shallowRef)(null),k=r.singletonManager;function A(e){let t=h.value;if(!t||!C.value)return;let n=S?.getStateSeq()??0;S?.onLayoutStart();let r=C.value.package?.document,i=r?.sections?.[0]?.properties??r?.finalSectionProperties??null,a=r?.finalSectionProperties??i,o=(0,l.getPageSize)(i),c=(0,l.getMargins)(i),f=(0,l.getPageSize)(a),p=(0,l.getMargins)(a),g=o.w-c.left-c.right,v=o.h-c.top-c.bottom,b=C.value.package?.theme??null,x=C.value.package?.styles??null;try{let n=(0,s.toFlowBlocks)(e.doc,{theme:b,pageContentHeight:v}),r=m(n,g),{header:a,footer:h,firstHeader:y,firstFooter:S}=(0,l.resolveHeaderFooter)(C.value,i),w={section:`header`,pageSize:o,margins:c},T={section:`footer`,pageSize:o,margins:c},E=e.doc.attrs?.defaultTabStopTwips,D={styles:x,theme:b,measureBlocks:m,defaultTabStopTwips:E},k=(0,l.convertHeaderFooterToContent)(a,g,w,D),A=(0,l.convertHeaderFooterToContent)(h,g,T,D),j=i?.titlePg===!0,M=j?(0,l.convertHeaderFooterToContent)(y,g,w,D):void 0,N=j?(0,l.convertHeaderFooterToContent)(S,g,T,D):void 0,P=c.header??48,F=c.footer??48,I=c.top-P,L=c.bottom-F,R=e=>e?e.visualBottom??e.height:0,z=e=>e?Math.max((e.visualBottom??e.height)-(e.visualTop??0),e.height):0,B=Math.max(R(k),R(M)),V=Math.max(z(A),z(N)),H=B>I,U=V>L;if(H||U){let e=e=>{let t={...e};return H&&(t.top=Math.max(e.top,P+B)),U&&(t.bottom=Math.max(e.bottom,F+V)),t};c=e(c),p=e(p);for(let t of n){if(t.kind!==`sectionBreak`)continue;let n=t;n.margins&&=e(n.margins)}}let W={pageSize:o,margins:c,finalPageSize:f,finalMargins:p,pageGap:_},G=(0,l.collectFootnoteRefs)(n),K=G.length>0&&!!C.value.package?.footnotes,q=(0,u.layoutDocument)(n,r,W),J=new Map,Y=new Map;if(K){Y=(0,l.buildFootnoteContentMap)(C.value.package.footnotes,G,g,{styles:x,theme:b,measureBlocks:m,defaultTabStopTwips:E});let e=(0,l.stabilizeFootnoteLayout)({blocks:n,measures:r,layoutOpts:W,footnoteRefs:G,footnoteContentMap:Y,initialLayout:q});q=e.layout,J=e.pageFootnoteMap}O.value=q;let X=new Map;for(let e=0;e<n.length;e++){let t=n[e],i=r[e];t&&i&&X.set(String(t.id),{block:t,measure:i})}let Z=K?(0,l.buildFootnoteRenderItems)(J,Y,C.value):void 0;(0,d.renderPages)(q.pages,t,{pageGap:_,showShadow:!0,pageBackground:`#fff`,blockLookup:X,theme:b,headerContent:k,footerContent:A,firstPageHeaderContent:M,firstPageFooterContent:N,titlePage:j,footnotesByPage:Z}),t.style.overflowY=`auto`,t.style.minHeight=`0`;for(let e of Array.from(t.children))e.style.flexShrink=`0`}catch(e){console.error(`[useDocxEditor] Layout pipeline error:`,e),y?.(e instanceof Error?e:Error(String(e)))}finally{S?.onLayoutComplete(n)}}function j(){let r=p.value;if(!r)return;let a=C.value?(0,i.toProseDoc)(C.value,{styles:C.value.package?.styles??void 0}):(0,i.createEmptyDoc)(),s=[...x,...k.getPlugins()??[]],c=t.EditorState.create({doc:a,schema:k.getSchema(),plugins:s});T.value=c;let l=new n.EditorView(r,{state:c,editable:()=>!(0,e.unref)(g),dispatchTransaction(e){if(!l)return;let t=l.state.apply(e);if(l.updateState(t),T.value=t,e.docChanged){S?.incrementStateSeq(),A(t);try{if(C.value){let e=(0,o.fromProseDoc)(t.doc,C.value);C.value=e,v?.(e)}}catch(e){console.error(`[useDocxEditor] fromProseDoc error:`,e)}}S?.requestRender(),b?.()}});w.value=l,E.value=!0,A(c),S?.requestRender()}function M(){w.value&&=(w.value.destroy(),null),T.value=null,E.value=!1}async function N(e){D.value=null,E.value=!1;try{let t;t=e instanceof Blob||e instanceof File?await e.arrayBuffer():e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,C.value=await(0,a.parseDocx)(t),M(),j()}catch(e){let t=e instanceof Error?e:Error(String(e));D.value=t.message,y?.(t)}}function P(e){D.value=null,C.value=e,M(),j()}async function F(){if(!w.value||!C.value)return null;let{repackDocx:e,createDocx:t}=await import(`@eigenpal/docx-editor-core/docx/rezip`),{injectReplyRangeMarkers:n,injectTCReplyRangeMarkers:r}=await import(`@eigenpal/docx-editor-core/docx`),i=(0,o.fromProseDoc)(w.value.state.doc,C.value),a=i.package.document?.comments??[];i.package.document?.content&&a.length>0&&(n(i.package.document.content,a),r(i.package.document.content,a));let s;return s=i.originalBuffer?await e(i):await t(i),new Blob([s],{type:`application/vnd.openxmlformats-officedocument.wordprocessingml.document`})}function I(){w.value?.focus()}function L(){M(),C.value=null}function R(){return C.value}(0,e.onBeforeUnmount)(()=>{L()});function z(){return k.getCommands()}return{editorView:w,editorState:T,isReady:E,parseError:D,layout:O,loadBuffer:N,loadDocument:P,save:F,focus:I,destroy:L,getDocument:R,getCommands:z,reLayout(){w.value&&A(w.value.state)}}}var g=.25,_=4,v=.1,y=[.25,.5,.75,1,1.25,1.5,2,3,4];function b(t=1){let n=(0,e.ref)(Math.max(g,Math.min(_,t))),r=(0,e.computed)(()=>Math.round(n.value*100)),i=(0,e.computed)(()=>n.value<=g),a=(0,e.computed)(()=>n.value>=_);function o(e){n.value=Math.max(g,Math.min(_,Math.round(e*100)/100))}function s(){o(n.value+v)}function c(){o(n.value-v)}function l(){o(1)}function u(e){(e.ctrlKey||e.metaKey)&&(e.preventDefault(),e.deltaY<0?s():c())}function d(e){(e.ctrlKey||e.metaKey)&&(e.shiftKey||e.altKey||(e.key===`=`||e.key===`+`?(e.preventDefault(),s()):e.key===`-`?(e.preventDefault(),c()):e.key===`0`&&(e.preventDefault(),l())))}function f(){(0,e.onMounted)(()=>document.addEventListener(`keydown`,d)),(0,e.onBeforeUnmount)(()=>document.removeEventListener(`keydown`,d))}return{zoom:n,zoomPercent:r,isMinZoom:i,isMaxZoom:a,setZoom:o,zoomIn:s,zoomOut:c,resetZoom:l,handleWheel:u,handleKeyDown:d,installShortcuts:f,ZOOM_PRESETS:y}}var x=15,S=300,C=200,w=15;function T(){let e={active:!1,startX:0,handle:null,columnIndex:0,tablePmStart:0,origWidths:{left:0,right:0}},t={active:!1,startY:0,handle:null,rowIndex:0,isEdge:!1,tablePmStart:0,origHeight:0},n={active:!1,startX:0,handle:null,columnIndex:0,tablePmStart:0,origWidth:0},r=null;function i(){return e.active||t.active||n.active}function a(i,a){let o=i.target;return o?.classList?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),E(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),D(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),O(a,n),!0):!1:!1}function o(r){if(e.active&&e.handle){r.preventDefault();let t=r.clientX-e.startX,n=parseFloat(e.handle.style.left);e.handle.style.left=`${n+t}px`,e.startX=r.clientX;let i=Math.round(t*x),a=e.origWidths.left+i,o=e.origWidths.right-i;a>=S&&o>=S&&(e.origWidths={left:a,right:o});return}if(t.active&&t.handle){r.preventDefault();let e=r.clientY-t.startY,n=parseFloat(t.handle.style.top);t.handle.style.top=`${n+e}px`,t.startY=r.clientY;let i=Math.round(e*x),a=t.origHeight+i;a>=C&&(t.origHeight=a);return}if(n.active&&n.handle){r.preventDefault();let e=r.clientX-n.startX,t=parseFloat(n.handle.style.left);n.handle.style.left=`${t+e}px`,n.startX=r.clientX;let i=Math.round(e*x),a=n.origWidth+i;a>=S&&(n.origWidth=a)}}function s(i){if(e.active){e.active=!1,e.handle?.classList.remove(`dragging`),r&&k(r,e),e.handle=null;return}if(t.active){t.active=!1,t.handle?.classList.remove(`dragging`),r&&A(r,t),t.handle=null;return}n.active&&(n.active=!1,n.handle?.classList.remove(`dragging`),r&&j(r,n),n.handle=null)}function c(){return document.addEventListener(`mousemove`,o),document.addEventListener(`mouseup`,s),()=>{document.removeEventListener(`mousemove`,o),document.removeEventListener(`mouseup`,s)}}return{tryStartResize:a,install:c,isResizing:i}}function E(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let e=n.depth;e>=0;e--){let r=n.node(e);if(r.type.name===`table`){let e=r.attrs.columnWidths;e&&e[t.columnIndex]!==void 0&&e[t.columnIndex+1]!==void 0&&(t.origWidths={left:e[t.columnIndex],right:e[t.columnIndex+1]});return}}}function D(e,t,n){let r=e.state.doc.resolve(t.tablePmStart+1);for(let e=r.depth;e>=0;e--){let i=r.node(e);if(i.type.name===`table`){let e=null,r=0;if(i.forEach(n=>{r===t.rowIndex&&(e=n),r++}),e){let r=e.attrs.height;if(r)t.origHeight=r;else{let e=n.closest(`.layout-table`)?.querySelector(`[data-row-index="${t.rowIndex}"]`),r=e?e.getBoundingClientRect().height:30;t.origHeight=Math.round(r*w)}}return}}}function O(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let e=n.depth;e>=0;e--){let r=n.node(e);if(r.type.name===`table`){let e=r.attrs.columnWidths;e&&e[t.columnIndex]!==void 0&&(t.origWidth=e[t.columnIndex]);return}}}function k(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let r=n.depth;r>=0;r--){let i=n.node(r);if(i.type.name!==`table`)continue;let a=n.before(r),o=e.state.tr,s=[...i.attrs.columnWidths||[]];s[t.columnIndex]=t.origWidths.left,s[t.columnIndex+1]=t.origWidths.right,o.setNodeMarkup(a,void 0,{...i.attrs,columnWidths:s});let c=a+1;i.forEach(e=>{let n=c+1,r=0;e.forEach(e=>{let i=e.attrs.colspan||1;if(r===t.columnIndex||r===t.columnIndex+1){let i=r===t.columnIndex?t.origWidths.left:t.origWidths.right;o.setNodeMarkup(o.mapping.map(n),void 0,{...e.attrs,width:i,widthType:`dxa`,colwidth:null})}n+=e.nodeSize,r+=i}),c+=e.nodeSize}),e.dispatch(o);return}}function A(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let r=n.depth;r>=0;r--){let i=n.node(r);if(i.type.name!==`table`)continue;let a=n.before(r),o=e.state.tr,s=a+1,c=0;i.forEach(e=>{c===t.rowIndex&&o.setNodeMarkup(o.mapping.map(s),void 0,{...e.attrs,height:t.origHeight,heightRule:`atLeast`}),s+=e.nodeSize,c++}),e.dispatch(o);return}}function j(e,t){let n=e.state.doc.resolve(t.tablePmStart+1);for(let r=n.depth;r>=0;r--){let i=n.node(r);if(i.type.name!==`table`)continue;let a=n.before(r),o=e.state.tr,s=[...i.attrs.columnWidths||[]];s[t.columnIndex]=t.origWidth,o.setNodeMarkup(a,void 0,{...i.attrs,columnWidths:s});let c=a+1;i.forEach(e=>{let n=c+1,r=0;e.forEach(e=>{let i=e.attrs.colspan||1;r===t.columnIndex&&o.setNodeMarkup(o.mapping.map(n),void 0,{...e.attrs,width:t.origWidth,widthType:`dxa`,colwidth:null}),n+=e.nodeSize,r+=i}),c+=e.nodeSize}),e.dispatch(o);return}}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return T}});