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