@silurus/ooxml 0.70.2 → 0.71.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,3895 +0,0 @@
1
- import { A as e, B as t, C as n, D as r, E as i, G as a, H as o, J as s, K as c, N as l, O as u, P as d, U as f, V as p, W as m, X as h, Y as g, Z as _, _ as v, b as y, c as b, d as x, f as S, g as C, h as w, i as T, j as E, k as D, l as O, m as k, n as A, o as j, p as M, q as N, r as P, s as F, t as I, u as L, v as R, w as z, x as ee } from "./line-metrics-DG9p1RvA.js";
2
- import { a as B, c as V, d as H, f as U, i as W, l as G, m as K, n as te, p as ne, r as re, s as q, t as J, u as ie } from "./virtual-scroll-CsikPntn.js";
3
- import { t as ae } from "./mathjax-BRfWlbSJ.js";
4
- import { t as oe } from "./segments-BTivjRMw.js";
5
- //#region packages/core/src/draw/double-border.ts
6
- function se(e, t) {
7
- let n = Math.max(1, Math.round(e * t / 3)), r = Math.max(1, Math.round(e * t / 3));
8
- return {
9
- railDev: n,
10
- gapDev: r,
11
- spanDev: 2 * n + r
12
- };
13
- }
14
- function ce(e, t, n, r, i, a, o) {
15
- let { railDev: s, gapDev: c, spanDev: l } = se(a, o);
16
- if (n === i) {
17
- let i = Math.round(n * o - l / 2);
18
- e.fillRect(t, i / o, r - t, s / o), e.fillRect(t, (i + s + c) / o, r - t, s / o);
19
- } else {
20
- let r = Math.round(t * o - l / 2);
21
- e.fillRect(r / o, n, s / o, i - n), e.fillRect((r + s + c) / o, n, s / o, i - n);
22
- }
23
- }
24
- //#endregion
25
- //#region packages/docx/src/worker.ts?worker&inline
26
- var le = "var e=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,n.unregister(this),e}free(){let e=this.__destroy_into_raw();v.__wbg_docxarchive_free(e,0)}extract_image(e){let t=d(e,v.__wbindgen_malloc,v.__wbindgen_realloc),n=_,i=v.docxarchive_extract_image(this.__wbg_ptr,t,n);if(i[3])throw f(i[2]);var a=r(i[0],i[1]).slice();return v.__wbindgen_free(i[0],i[1]*1,1),a}constructor(e,t){let r=u(e,v.__wbindgen_malloc),i=_,a=v.docxarchive_new(r,i,!l(t),l(t)?BigInt(0):t);if(a[2])throw f(a[1]);return this.__wbg_ptr=a[0]>>>0,n.register(this,this.__wbg_ptr,this),this}parse(){let e=v.docxarchive_parse(this.__wbg_ptr);if(e[3])throw f(e[2]);var t=r(e[0],e[1]).slice();return v.__wbindgen_free(e[0],e[1]*1,1),t}to_markdown(){let e,t;try{let i=v.docxarchive_to_markdown(this.__wbg_ptr);var n=i[0],r=i[1];if(i[3])throw n=0,r=0,f(i[2]);return e=n,t=r,o(n,r)}finally{v.__wbindgen_free(e,t,1)}}};Symbol.dispose&&(e.prototype[Symbol.dispose]=e.prototype.free);function t(){return{__proto__:null,\"./docx_parser_bg.js\":{__proto__:null,__wbg___wbindgen_throw_6b64449b9b9ed33c:function(e,t){throw Error(o(e,t))},__wbg_error_a6fa202b58aa1cd3:function(e,t){let n,r;try{n=e,r=t,console.error(o(e,t))}finally{v.__wbindgen_free(n,r,1)}},__wbg_new_227d7c05414eb861:function(){return Error()},__wbg_stack_3b0d974bbf31e44f:function(e,t){let n=t.stack,r=d(n,v.__wbindgen_malloc,v.__wbindgen_realloc),i=_;a().setInt32(e+4,i,!0),a().setInt32(e+0,r,!0)},__wbindgen_cast_0000000000000001:function(e,t){return o(e,t)},__wbindgen_init_externref_table:function(){let e=v.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}}}}const n=typeof FinalizationRegistry>`u`?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>v.__wbg_docxarchive_free(e>>>0,1));function r(e,t){return e>>>=0,c().subarray(e/1,e/1+t)}let i=null;function a(){return(i===null||i.buffer.detached===!0||i.buffer.detached===void 0&&i.buffer!==v.memory.buffer)&&(i=new DataView(v.memory.buffer)),i}function o(e,t){return e>>>=0,h(e,t)}let s=null;function c(){return(s===null||s.byteLength===0)&&(s=new Uint8Array(v.memory.buffer)),s}function l(e){return e==null}function u(e,t){let n=t(e.length*1,1)>>>0;return c().set(e,n/1),_=e.length,n}function d(e,t,n){if(n===void 0){let n=g.encode(e),r=t(n.length,1)>>>0;return c().subarray(r,r+n.length).set(n),_=n.length,r}let r=e.length,i=t(r,1)>>>0,a=c(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=c().subarray(i+o,i+r),a=g.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return _=o,i}function f(e){let t=v.__wbindgen_externrefs.get(e);return v.__externref_table_dealloc(e),t}let p=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0});p.decode();let m=0;function h(e,t){return m+=t,m>=2146435072&&(p=new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!0}),p.decode(),m=t),p.decode(c().subarray(e,e+t))}const g=new TextEncoder;`encodeInto`in g||(g.encodeInto=function(e,t){let n=g.encode(e);return t.set(n),{read:e.length,written:n.length}});let _=0,v;function y(e,t){return v=e.exports,i=null,s=null,v.__wbindgen_start(),v}async function b(e,t){if(typeof Response==`function`&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming==`function`)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(e.ok&&n(e.type)&&e.headers.get(`Content-Type`)!==`application/wasm`)console.warn(\"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}else{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function n(e){switch(e){case`basic`:case`cors`:case`default`:return!0}return!1}}async function x(e){if(v!==void 0)return v;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn(`using deprecated parameters for the initialization function; pass a single object instead`));let n=t();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:r,module:i}=await b(await e,n);return y(r,i)}function S(e){if(!e.startsWith(`data:`))return null;let t=e.indexOf(`,`);if(t===-1)return null;let n=atob(e.slice(t+1)),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r.buffer}let C=null,w=null;function T(){w&&=(w.free(),null)}self.onmessage=async t=>{let n=t.data;if(n.type===`init`){C=x(S(n.wasmUrl)??n.wasmUrl);return}let r=n.id;try{if(await C,n.type===`parse`){let t=typeof n.maxZipEntryBytes==`number`&&n.maxZipEntryBytes>0?BigInt(n.maxZipEntryBytes):void 0;T(),w=new e(new Uint8Array(n.data),t);let i=w.parse().buffer,a={type:`parsed`,id:r,documentJson:i};self.postMessage(a,[i]);return}if(n.type===`extractImage`){if(!w)throw Error(`No docx loaded`);let e=w.extract_image(n.path),t=new Uint8Array(e).slice().buffer,i={type:`imageExtracted`,id:r,bytes:t};self.postMessage(i,[t]);return}}catch(e){let t={type:`error`,id:r,message:String(e)};self.postMessage(t)}};", Y = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", le], { type: "text/javascript;charset=utf-8" });
27
- function ue(e) {
28
- let t;
29
- try {
30
- if (t = Y && (self.URL || self.webkitURL).createObjectURL(Y), !t) throw "";
31
- let n = new Worker(t, {
32
- type: "module",
33
- name: e?.name
34
- });
35
- return n.addEventListener("error", () => {
36
- (self.URL || self.webkitURL).revokeObjectURL(t);
37
- }), n;
38
- } catch {
39
- return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(le), {
40
- type: "module",
41
- name: e?.name
42
- });
43
- }
44
- }
45
- //#endregion
46
- //#region packages/docx/src/wasm/docx_parser_bg.wasm?url
47
- var de = new URL("docx_parser_bg.wasm", import.meta.url).href, fe = (e) => {
48
- let t = e.text;
49
- return typeof t == "string" ? t : void 0;
50
- }, pe = (e) => e.rtl === !0, me = (e) => e.digitsAsAN === !0;
51
- function he(e) {
52
- for (let t of e) {
53
- if (pe(t)) return !0;
54
- let e = fe(t);
55
- if (e !== void 0 && x(e)) return !0;
56
- }
57
- return !1;
58
- }
59
- var ge = /[\p{P}\p{S}]/u;
60
- function _e(e, t) {
61
- let n = e.length;
62
- if (n === 0) return {
63
- order: [],
64
- rtl: []
65
- };
66
- let r = "", i = Array(n), a = Array(n), o, s = () => {
67
- for (o ||= []; o.length < r.length;) o.push(null);
68
- return o;
69
- };
70
- for (let t = 0; t < n; t++) {
71
- let n = fe(e[t]) ?? "";
72
- if (i[t] = r.length, r += n.length > 0 ? n : "", a[t] = r.length, n.length > 0 && (me(e[t]) || pe(e[t]))) {
73
- let n = s(), o = me(e[t]), c = pe(e[t]);
74
- for (let e = i[t]; e < a[t]; e++) {
75
- let t = r.charCodeAt(e);
76
- o && t >= 48 && t <= 57 ? n[e] = "AN" : c && ge.test(r[e]) && (n[e] = "R");
77
- }
78
- }
79
- }
80
- if (o) for (; o.length < r.length;) o.push(null);
81
- let { levels: c, paragraphLevel: l } = S().computeLevels(r, t ? "rtl" : "ltr", o), { order: u } = L(c, l, i), d = Array(n);
82
- for (let e = 0; e < n; e++) {
83
- let t = a[e];
84
- for (; t > i[e] && r[t - 1] === " ";) t--;
85
- let n = !1;
86
- for (let r = i[e]; r < t; r++) {
87
- let e = c[r];
88
- if (e !== 255 && (e & 1) == 1) {
89
- n = !0;
90
- break;
91
- }
92
- }
93
- d[e] = n;
94
- }
95
- return {
96
- order: u,
97
- rtl: d
98
- };
99
- }
100
- function ve(e, t) {
101
- switch (e) {
102
- case "center": return "center";
103
- case "both":
104
- case "justify":
105
- case "distribute": return "justify";
106
- case "end":
107
- case "right": return t ? "left" : "right";
108
- case "start":
109
- case "left":
110
- case void 0:
111
- default: return t ? "right" : "left";
112
- }
113
- }
114
- var ye = .05;
115
- function be(e) {
116
- return (72 - ye) * e;
117
- }
118
- function xe(e) {
119
- return e === "square" || e === "topAndBottom" || e === "tight" || e === "through";
120
- }
121
- function Se(e, t, n, r, i, a, o, s) {
122
- return e < a - .01 && t > i + .01 && n < s - .01 && r > o + .01;
123
- }
124
- function Ce(e, t, n) {
125
- let r = e.slice().sort((e, t) => e.l - t.l), i = t, a = null, o = (e, t) => {
126
- t - e > (a ? a.r - a.l : 0) && (a = {
127
- l: e,
128
- r: t
129
- });
130
- };
131
- for (let e of r) if (e.l > i && o(i, Math.min(e.l, n)), i = Math.max(i, Math.min(e.r, n)), i >= n) break;
132
- return i < n && o(i, n), a;
133
- }
134
- function we(e, t, n, r, i, a) {
135
- for (let t = 0; t < 16; t++) {
136
- let t = e + n, r = null;
137
- for (let n of a) n.mode === "topAndBottom" && t > n.yTop && e < n.yBottom && (r = r === null ? n.yBottom : Math.max(r, n.yBottom));
138
- if (r === null) break;
139
- e = r;
140
- }
141
- let o = r, s = r + i, c = Math.max(t, 1), l = 0, u = i;
142
- for (let t = 0; t < 64; t++) {
143
- let t = e + n, r = [], d = [];
144
- for (let n of a) if (n.mode === "square" && !(t <= n.yTop || e >= n.yBottom)) switch (d.push(n), n.side) {
145
- case "left":
146
- r.push({
147
- l: n.xLeft,
148
- r: s
149
- });
150
- break;
151
- case "right":
152
- r.push({
153
- l: o,
154
- r: n.xRight
155
- });
156
- break;
157
- default:
158
- r.push({
159
- l: n.xLeft,
160
- r: n.xRight
161
- });
162
- break;
163
- }
164
- if (d.length === 0) {
165
- l = 0, u = i;
166
- break;
167
- }
168
- let f = Ce(r, o, s);
169
- if (f && f.r - f.l >= c) {
170
- l = Math.max(0, f.l - o), u = Math.min(i - l, f.r - f.l), u < 0 && (u = 0);
171
- break;
172
- }
173
- let p = Math.max(...d.map((e) => e.yBottom));
174
- if (p <= e) {
175
- l = 0, u = i;
176
- break;
177
- }
178
- e = p;
179
- }
180
- return {
181
- topY: e,
182
- xOffset: l,
183
- maxWidth: u
184
- };
185
- }
186
- function Te(e, t, n, r, i, a, o, s, c, l, u, d, f) {
187
- for (let p = 0; p < 16; p++) {
188
- let p = e - i, m = e + n + a, h = t - o, g = t + r + s, _ = f.filter((e) => (l ? e.paraId !== c : u !== "table" || e.kind === "table") && Se(p, m, h, g, e.xLeft, e.xRight, e.yTop, e.yBottom));
189
- if (_.length === 0) return {
190
- x: e,
191
- y: t
192
- };
193
- let v = Math.max(..._.map((e) => e.xRight)) + i;
194
- if (v + n + a <= d + .5) {
195
- e = v;
196
- continue;
197
- }
198
- t = Math.max(..._.map((e) => e.yBottom)) + o;
199
- }
200
- return {
201
- x: e,
202
- y: t
203
- };
204
- }
205
- function Ee(e, t) {
206
- for (let n = 0; n < 16; n++) {
207
- let n = e;
208
- for (let r of t) r.mode === "topAndBottom" && e >= r.yTop && e < r.yBottom && (n = Math.max(n, r.yBottom));
209
- if (n === e) return e;
210
- e = n;
211
- }
212
- return e;
213
- }
214
- //#endregion
215
- //#region packages/docx/src/text-distribute.ts
216
- function De(e, t, n, r, i = -Infinity, a = !0) {
217
- return re(e, t, {
218
- firstContentSi: n,
219
- lastDrawnSi: r,
220
- minPerGap: i,
221
- ...a ? {} : { isGapChar: () => !1 }
222
- });
223
- }
224
- function Oe(e) {
225
- if (!e) return 0;
226
- let t = 0;
227
- for (let n of e.perSeg.values()) t += n.splitBefore.length + +!!n.trailingGap;
228
- return e.perGap * t;
229
- }
230
- function ke(e, t, n, r, i) {
231
- return t >= 0 ? null : De(e, t, n, r, -i * .25, !1);
232
- }
233
- //#endregion
234
- //#region packages/docx/src/frame-geometry.ts
235
- function Ae(e, t) {
236
- let n = t.scale;
237
- switch (e) {
238
- case "margin": return {
239
- left: t.marginLeft * n,
240
- right: (t.pageWidth - t.marginRight) * n
241
- };
242
- case "page": return {
243
- left: 0,
244
- right: t.pageWidth * n
245
- };
246
- default: return {
247
- left: t.contentX,
248
- right: t.contentX + t.contentW
249
- };
250
- }
251
- }
252
- function je(e, t, n, r) {
253
- let i = r.scale;
254
- switch (e) {
255
- case "margin": return {
256
- start: r.marginTop * i,
257
- end: r.pageH - r.marginBottom * i
258
- };
259
- case "page": return {
260
- start: 0,
261
- end: r.pageH
262
- };
263
- default: return {
264
- start: t,
265
- end: t + n
266
- };
267
- }
268
- }
269
- function Me(e, t, n, r) {
270
- switch (e) {
271
- case "center": return t + (n - t - r) / 2;
272
- case "right":
273
- case "outside": return n - r;
274
- default: return t;
275
- }
276
- }
277
- function Ne(e, t, n) {
278
- switch (e) {
279
- case "center": return t.start + (t.end - t.start - n) / 2;
280
- case "bottom":
281
- case "outside": return t.end - n;
282
- default: return t.start;
283
- }
284
- }
285
- function Pe(e, t, n) {
286
- return e + t <= n.end ? e : Math.max(n.start, n.end - t);
287
- }
288
- function Fe(e, t, n, r, i, a) {
289
- let o = t.scale, s = e.dropCap === "drop" || e.dropCap === "margin", c = Ae(e.hAnchor, t), l = je(e.vAnchor, n, i, t), u = e.w == null ? r : e.w * o, d;
290
- if (s) d = Math.max(1, e.lines) * a;
291
- else {
292
- let t = e.h == null ? 0 : e.h * o;
293
- d = e.hRule === "exact" ? t : e.hRule === "atLeast" ? Math.max(t, i) : i;
294
- }
295
- let f;
296
- f = e.dropCap === "drop" ? c.left : e.dropCap === "margin" ? c.left - u : e.xAlign ? Me(e.xAlign, c.left, c.right, u) : c.left + (e.x == null ? 0 : e.x * o);
297
- let p;
298
- p = s ? l.start : e.yAlign && e.vAnchor !== "text" ? Ne(e.yAlign, l, d) : l.start + (e.y == null ? 0 : e.y * o), (e.vAnchor === "page" || e.vAnchor === "margin") && (p = Pe(p, d, l));
299
- let m = e.wrap === "around" || e.wrap === "auto" ? e.hSpace * o : 0, h = e.vSpace * o;
300
- return {
301
- x: f,
302
- y: p,
303
- w: u,
304
- h: d,
305
- exLeft: f - m,
306
- exRight: f + u + m,
307
- exTop: p - h,
308
- exBottom: p + d + h
309
- };
310
- }
311
- function Ie(e, t) {
312
- let n = t.x, r = t.y;
313
- if (t.avoidOverlap) {
314
- let i = Te(n, r, t.w, t.h, t.dl, t.dr, t.dt, t.db, t.paraId, t.allowOverlap ?? !0, t.kind, e.pageWidth * e.scale, e.floats);
315
- n = i.x, r = i.y;
316
- }
317
- let i = {
318
- kind: t.kind,
319
- mode: t.mode,
320
- imageKey: t.imageKey,
321
- imageX: n,
322
- imageY: r,
323
- imageW: t.w,
324
- imageH: t.h,
325
- xLeft: n - t.dl,
326
- xRight: n + t.w + t.dr,
327
- yTop: r - t.dt,
328
- yBottom: r + t.h + t.db,
329
- side: t.side,
330
- distLeft: t.dl,
331
- distRight: t.dr,
332
- distTop: t.dt,
333
- distBottom: t.db,
334
- paraId: t.paraId,
335
- drawn: t.drawn
336
- };
337
- return e.floats.push(i), i;
338
- }
339
- function Le(e, t, n) {
340
- if (t.wrap === "none" || e.w <= 0 || e.h <= 0) return;
341
- let r = n.floatParaSeq++, i = t.wrap === "notBeside" ? "topAndBottom" : "square";
342
- Ie(n, {
343
- x: e.x,
344
- y: e.y,
345
- w: e.w,
346
- h: e.h,
347
- dl: e.x - e.exLeft,
348
- dr: e.exRight - (e.x + e.w),
349
- dt: e.y - e.exTop,
350
- db: e.exBottom - (e.y + e.h),
351
- kind: "frame",
352
- mode: i,
353
- side: t.dropCap === "drop" || t.dropCap === "margin" ? "right" : "bothSides",
354
- imageKey: "",
355
- drawn: !0,
356
- paraId: r,
357
- avoidOverlap: !1
358
- });
359
- }
360
- //#endregion
361
- //#region packages/docx/src/float-table-geometry.ts
362
- function Re(e, t, n, r, i) {
363
- let a = t.scale, o = e.horzSpecified ? Ae(e.horzAnchor, t) : Ae("text", t), s = je(e.vertAnchor, n, i, t), c;
364
- c = e.tblpXSpec ? Me(e.tblpXSpec, o.left, o.right, r) : o.left + e.tblpX * a;
365
- let l;
366
- return l = e.tblpYSpec && e.vertAnchor !== "text" ? Ne(e.tblpYSpec, s, i) : s.start + e.tblpY * a, (e.vertAnchor === "page" || e.vertAnchor === "margin") && (l = Pe(l, i, s)), {
367
- x: c,
368
- y: l,
369
- w: r,
370
- h: i
371
- };
372
- }
373
- function ze(e, t, n, r, i) {
374
- if (e.w <= 0 || e.h <= 0) return;
375
- let a = n.scale, o = t.leftFromText * a, s = t.rightFromText * a, c = t.topFromText * a, l = t.bottomFromText * a, u = n.floatParaSeq++;
376
- Ie(n, {
377
- x: e.x,
378
- y: e.y,
379
- w: e.w,
380
- h: e.h,
381
- dl: o,
382
- dr: s,
383
- dt: c,
384
- db: l,
385
- kind: "table",
386
- mode: "square",
387
- side: r,
388
- imageKey: "",
389
- drawn: !0,
390
- paraId: u,
391
- avoidOverlap: !0,
392
- allowOverlap: i
393
- });
394
- }
395
- function Be(e, t) {
396
- let n = (t.contentX + (t.contentX + t.contentW)) / 2;
397
- return e.x + e.w <= n ? "right" : e.x >= n ? "left" : "bothSides";
398
- }
399
- //#endregion
400
- //#region packages/docx/src/anchor-geometry.ts
401
- function Ve(e, t, n) {
402
- let { scale: r } = n, i = n.pageWidth * r, a = n.marginLeft * r, o = n.marginRight * r;
403
- switch (e ?? (t ? "margin" : "page")) {
404
- case "page": return {
405
- start: 0,
406
- end: i
407
- };
408
- case "leftMargin": return {
409
- start: 0,
410
- end: a
411
- };
412
- case "rightMargin": return {
413
- start: i - o,
414
- end: i
415
- };
416
- case "insideMargin": return {
417
- start: 0,
418
- end: a
419
- };
420
- case "outsideMargin": return {
421
- start: i - o,
422
- end: i
423
- };
424
- default: return {
425
- start: a,
426
- end: i - o
427
- };
428
- }
429
- }
430
- function He(e, t, n, r) {
431
- let { scale: i } = r, a = r.marginTop * i, o = r.marginBottom * i;
432
- switch (e ?? (t ? "paragraph" : "page")) {
433
- case "page": return {
434
- start: 0,
435
- end: r.pageH
436
- };
437
- case "topMargin": return {
438
- start: 0,
439
- end: a
440
- };
441
- case "bottomMargin": return {
442
- start: r.pageH - o,
443
- end: r.pageH
444
- };
445
- case "paragraph":
446
- case "line": return {
447
- start: n,
448
- end: r.pageH
449
- };
450
- default: return {
451
- start: a,
452
- end: r.pageH - o
453
- };
454
- }
455
- }
456
- function Ue(e, t, n, r, i, a, o, s) {
457
- let { scale: c } = i, l = Ve(a, t, i), u = n * c;
458
- if (o != null) return l.start + (l.end - l.start) * o + u;
459
- if (!e) return l.start + u;
460
- let d = l.end - l.start, f = s == null ? r : s * c;
461
- switch (e) {
462
- case "center": return l.start + (d - f) / 2 + u;
463
- case "right":
464
- case "outside": return l.end - f + u;
465
- default: return l.start + u;
466
- }
467
- }
468
- function We(e, t, n, r, i, a, o, s, c) {
469
- let { scale: l } = a, u = He(o, t, i, a), d = n * l;
470
- if (s != null) return u.start + (u.end - u.start) * s + d;
471
- if (!e) return u.start + d;
472
- let f = u.end - u.start, p = c == null ? r : c * l;
473
- switch (e) {
474
- case "center": return u.start + (f - p) / 2 + d;
475
- case "bottom":
476
- case "outside": return u.end - p + d;
477
- default: return u.start + d;
478
- }
479
- }
480
- function Ge(e, t, n) {
481
- let r = t;
482
- for (let i = t + 1; i < e.rows.length; i++) {
483
- let t = e.rows[i], a = 0, o = !1;
484
- for (let e of t.cells) {
485
- if (a === n) {
486
- e.vMerge === !1 && (o = !0);
487
- break;
488
- }
489
- if (a > n) break;
490
- a += e.colSpan;
491
- }
492
- if (!o) break;
493
- r = i;
494
- }
495
- return r;
496
- }
497
- function Ke(e, t, n, r) {
498
- if (e.rowHeight != null && e.rowHeightRule === "exact") return e.rowHeight * n;
499
- let i = e.rowHeight != null && (e.rowHeightRule === "atLeast" || e.rowHeightRule === "auto") ? e.rowHeight * n : 10 * n, a = 0;
500
- for (let n of e.cells) {
501
- let e = Math.min(n.colSpan, t.length - a);
502
- if (n.vMerge !== !0 && n.vMerge !== !1) {
503
- let o = r(n, t.slice(a, a + e).reduce((e, t) => e + t, 0));
504
- o > i && (i = o);
505
- }
506
- a += e;
507
- }
508
- return i;
509
- }
510
- function qe(e, t, n, r) {
511
- let i = e.rows.map((e) => Ke(e, t, n, r));
512
- for (let n = 0; n < e.rows.length; n++) {
513
- let a = 0;
514
- for (let o of e.rows[n].cells) {
515
- let s = Math.min(o.colSpan, t.length - a);
516
- if (o.vMerge === !0) {
517
- let c = r(o, t.slice(a, a + s).reduce((e, t) => e + t, 0)), l = Ge(e, n, a), u = 0;
518
- for (let e = n; e <= l; e++) u += i[e];
519
- u < c && (i[l] += c - u);
520
- }
521
- a += s;
522
- }
523
- }
524
- return i;
525
- }
526
- //#endregion
527
- //#region packages/docx/src/line-layout.ts
528
- var Je = /* @__PURE__ */ new WeakMap(), Ye = new Set([
529
- "sakkal majalla",
530
- "traditional arabic",
531
- "simplified arabic",
532
- "arabic typesetting",
533
- "univers next arabic",
534
- "noto naskh arabic",
535
- "noto sans arabic"
536
- ]), Xe = new Set([
537
- "sakkal majalla",
538
- "traditional arabic",
539
- "simplified arabic",
540
- "arabic typesetting",
541
- "noto naskh arabic"
542
- ]);
543
- function Ze(e) {
544
- return Ye.has(e.toLowerCase());
545
- }
546
- function Qe(e) {
547
- return e.map((e) => `"${e}"`).join(", ");
548
- }
549
- var $e = ["Noto Naskh Arabic", "Noto Sans Arabic"];
550
- function et(e) {
551
- let t = e && e !== "jp" ? m(e, "sans") : [
552
- "Noto Sans JP",
553
- "Hiragino Sans",
554
- "Meiryo",
555
- ...m("jp", "sans").slice(1)
556
- ];
557
- return e == null ? `${Qe([
558
- ...p,
559
- "Arial",
560
- "Helvetica",
561
- "Liberation Sans",
562
- ...t,
563
- ...$e
564
- ])}, sans-serif` : `${Qe([
565
- ...t,
566
- ...$e,
567
- ...p
568
- ])}, sans-serif`;
569
- }
570
- function tt(e) {
571
- let t = e && e !== "jp" ? m(e, "serif") : [
572
- "Yu Mincho",
573
- "YuMincho",
574
- "Hiragino Mincho ProN",
575
- "MS Mincho",
576
- "Noto Serif JP",
577
- ...m("jp", "serif").slice(1)
578
- ];
579
- return e == null ? `${Qe([
580
- ...o,
581
- "Times New Roman",
582
- "Cambria",
583
- "Liberation Serif",
584
- ...t,
585
- ...$e
586
- ])}, serif` : `${Qe([
587
- ...t,
588
- ...$e,
589
- ...o
590
- ])}, serif`;
591
- }
592
- var nt = /* @__PURE__ */ new WeakMap();
593
- function rt(e, t = {}) {
594
- let n = nt.get(t) ?? (() => {
595
- let e = /* @__PURE__ */ new Map();
596
- return nt.set(t, e), e;
597
- })(), r = e ?? "\0null", i = n.get(r);
598
- if (i !== void 0) return i;
599
- let a = it(e, t);
600
- return n.set(r, a), a;
601
- }
602
- function it(e, t) {
603
- if (!e) return et(null);
604
- let n = `"${((e) => e.replace(/"/g, "\\\""))(e)}"`, r = e.toLowerCase(), i = a(e);
605
- if (Ze(e)) return Xe.has(r) ? `${n}, "Noto Naskh Arabic", "Noto Sans Arabic", "Noto Serif", "Noto Sans JP", "Hiragino Sans", serif` : `${n}, "Noto Sans Arabic", "Noto Naskh Arabic", "Noto Sans JP", "Hiragino Sans", sans-serif`;
606
- let o = t[e];
607
- if (o && o !== "auto") switch (o) {
608
- case "roman": return `${n}, ${tt(i)}`;
609
- case "swiss": return `${n}, ${et(i)}`;
610
- case "modern": return `${n}, "Courier New", monospace`;
611
- default: break;
612
- }
613
- let s = c(e);
614
- if (s === "serif") return `${n}, ${tt(i)}`;
615
- if (s === "mono") return `${n}, "Courier New", monospace`;
616
- if (i == null || i === "jp") {
617
- if (r.includes("meiryo") || e.includes("メイリオ")) return `${n}, "Meiryo UI", "Meiryo", ${et(i)}`;
618
- if (e.includes("游ゴシック") || /\byu\s*gothic\b/i.test(e) || r.includes("yugothic")) return `${n}, "Yu Gothic", "YuGothic", ${et(i)}`;
619
- if (r.includes("ipa")) return `${n}, "IPAexGothic", ${et(i)}`;
620
- if (r.includes("segoe")) return `${n}, "Segoe UI", ${Qe([...$e, ...p])}, sans-serif`;
621
- }
622
- return `${n}, ${et(i)}`;
623
- }
624
- function X(e, t, n, r, i = {}) {
625
- return `${t ? "italic" : "normal"} ${e ? "bold" : "normal"} ${n}px ${rt(r, i)}`;
626
- }
627
- function at(e, t) {
628
- let n = (e.smallCaps ? Math.max(e.fontSize - 2, 1) : e.fontSize) * t;
629
- return e.vertAlign && (n *= .65), n;
630
- }
631
- function ot(e) {
632
- for (let t of e.runs) if (t.type === "text" || t.type === "field") return t.fontSize;
633
- return typeof e.defaultFontSize == "number" ? e.defaultFontSize : 10;
634
- }
635
- function st(e) {
636
- for (let t of e.runs) if (t.type === "text" || t.type === "field") return t.fontFamily;
637
- return e.defaultFontFamily ?? null;
638
- }
639
- function ct(e, t) {
640
- return A(st(e), ot(e) * t);
641
- }
642
- var lt = /[ᄀ-ᇿ⺀-⿟ -〿぀-ヿ㄰-㆏㐀-䶿一-鿿ꥠ-꥿가-퟿豈-﫿＀-￯]/u;
643
- function ut(e, t) {
644
- return !e || e.charSpacePt == null || e.type !== "linesAndChars" && e.type !== "snapToChars" ? 0 : e.charSpacePt * t;
645
- }
646
- function dt(e) {
647
- let t = 0;
648
- for (let n of e) lt.test(n) && t++;
649
- return t;
650
- }
651
- function ft(e, t) {
652
- if (t === 0 || e.length === 0) return 0;
653
- let n = [...e];
654
- return dt(e) === n.length ? n.length * t : 0;
655
- }
656
- function pt(e, t, n) {
657
- return e + ft(t, n);
658
- }
659
- function mt(e) {
660
- return !e || !e.linePitchPt || e.linePitchPt <= 0 ? !1 : e.type === "lines" || e.type === "linesAndChars";
661
- }
662
- function Z(e, t, n, r, i, a, o = 0, s = !1) {
663
- let c = t + n, l = Math.max(c, o), u = mt(i), d = u ? i.linePitchPt * r : 0, f = () => s ? Math.max(d, Math.ceil(c / d) * d) : Math.max(c, d), p = e !== null && e.explicit !== !0;
664
- return !e || (e.rule === "exact" || e.rule === "auto") && e.value <= 0 ? u ? f() : l : e.rule === "auto" ? u ? p ? f() : Math.max(c, d * e.value) : l * e.value : e.rule === "exact" ? e.value * r : e.rule === "atLeast" ? Math.max(l, e.value * r) : l;
665
- }
666
- function ht(e, t) {
667
- return {
668
- asc: e * t * .8,
669
- desc: e * t * .2
670
- };
671
- }
672
- function gt(e, t, n, r) {
673
- return I(t, r, e.fontBoundingBoxAscent ?? e.actualBoundingBoxAscent ?? n * .8, e.fontBoundingBoxDescent ?? e.actualBoundingBoxDescent ?? n * .2);
674
- }
675
- function _t(e, t, n, r, i = !1, a, o = {}) {
676
- let s = ot(e), c = st(e), l, u;
677
- if (a) {
678
- let e = a.font;
679
- a.font = X(!1, !1, s * t, c, o);
680
- let n = a.measureText(i ? "あ" : "x");
681
- a.font = e, {ascent: l, descent: u} = gt(n, c, s * t, s * t);
682
- } else ({asc: l, desc: u} = ht(s, t));
683
- return Z(e.lineSpacing, l, u, t, n, r, ct(e, t), i);
684
- }
685
- function vt(e) {
686
- let t = [];
687
- for (let n of e) {
688
- let e = n.toLowerCase() === n && n.toUpperCase() !== n, r = /\s/.test(n) ? t[t.length - 1]?.reduced ?? !1 : e, i = t[t.length - 1];
689
- i && i.reduced === r ? i.text += n : t.push({
690
- text: n,
691
- reduced: r
692
- });
693
- }
694
- return t.length ? t : [{
695
- text: e,
696
- reduced: !1
697
- }];
698
- }
699
- function yt(e, t) {
700
- for (let n = t - 1; n >= 0; n--) {
701
- let t = e[n];
702
- if (t.type === "text" || t.type === "field") return t.fontSize;
703
- }
704
- for (let n = t + 1; n < e.length; n++) {
705
- let t = e[n];
706
- if (t.type === "text" || t.type === "field") return t.fontSize;
707
- }
708
- return 10;
709
- }
710
- function bt(e, t) {
711
- return e.fieldType === "page" ? String(t.pageIndex + 1) : e.fieldType === "numPages" ? String(t.totalPages) : e.fallbackText;
712
- }
713
- function xt(e) {
714
- for (let t = 0; t < e.length;) {
715
- let n = e.codePointAt(t);
716
- if (T(n)) return !0;
717
- t += n > 65535 ? 2 : 1;
718
- }
719
- return !1;
720
- }
721
- function St(e, t, n, r = 0) {
722
- let i = [...t], a = 0, o = i.length;
723
- for (; a < o;) {
724
- let t = a + o + 1 >> 1, s = i.slice(0, t).join("");
725
- pt(e.measureText(s).width, s, r) <= n ? a = t : o = t - 1;
726
- }
727
- return i.slice(0, a).join("");
728
- }
729
- var Ct = new Set([
730
- "ar",
731
- "fa",
732
- "ur",
733
- "he",
734
- "iw",
735
- "yi",
736
- "ji",
737
- "ps",
738
- "sd",
739
- "ug",
740
- "dv",
741
- "syr",
742
- "ckb"
743
- ]);
744
- function wt(e, t) {
745
- if (e) {
746
- let t = e.split("-")[0].toLowerCase();
747
- if (Ct.has(t)) return !0;
748
- }
749
- return t;
750
- }
751
- function Tt(e) {
752
- let t = [], n = null, r = "";
753
- for (let i of e) {
754
- let e = i.codePointAt(0);
755
- if (!/\p{L}/u.test(i)) {
756
- r += i;
757
- continue;
758
- }
759
- let a = N(e);
760
- n === null ? (n = a, r += i) : a === n ? r += i : (t.push({
761
- text: r,
762
- cs: n
763
- }), n = a, r = i);
764
- }
765
- return r.length > 0 && t.push({
766
- text: r,
767
- cs: n ?? !1
768
- }), t;
769
- }
770
- function Et(e) {
771
- let t = [], n = null, r = "";
772
- for (let i of e) {
773
- let e = T(i.codePointAt(0));
774
- n === null || e === n ? (n = e, r += i) : (t.push({
775
- text: r,
776
- ea: n
777
- }), n = e, r = i);
778
- }
779
- return r.length > 0 && t.push({
780
- text: r,
781
- ea: n ?? !1
782
- }), t;
783
- }
784
- function Dt(e) {
785
- let t = (e) => e >= 48 && e <= 57, n = (e) => e === "." || e === "," || e === ":" || e === "/" || e === "\xA0", r = [], i = "", a = null;
786
- for (let o = 0; o < e.length; o++) {
787
- let s = e[o], c = t(s.charCodeAt(0));
788
- !c && a === !0 && n(s) && t(e.charCodeAt(o + 1)) && (c = !0), a === null || c === a ? i += s : (r.push(i), i = s), a = c;
789
- }
790
- return i.length > 0 && r.push(i), r.length ? r : [e];
791
- }
792
- function Ot(e) {
793
- let t = [], n = 0;
794
- for (; n < e.length;) {
795
- let r = n;
796
- for (; r < e.length && e[r] !== " ";) r++;
797
- for (; r < e.length && e[r] === " ";) r++;
798
- r > n && t.push(e.slice(n, r)), n = r;
799
- }
800
- return t.length ? t : [e];
801
- }
802
- var kt = .25;
803
- function At(e) {
804
- let t = e?.defaultTabStop;
805
- return t != null && t > 0 ? t : 36;
806
- }
807
- function jt(e, t, n) {
808
- let r = null, i = 0;
809
- for (let n of t) n.pos > i && (i = n.pos), n.pos > e && (r === null || n.pos < r.pos) && (r = n);
810
- let a = null;
811
- if (n > 0) {
812
- let t = Math.ceil((Math.max(e, i) + 1e-6) / n) * n;
813
- t <= e && (t += n), a = {
814
- pos: t,
815
- alignment: "left"
816
- };
817
- }
818
- return r && a ? r.pos <= a.pos ? r : a : r ?? a;
819
- }
820
- function Mt(e, t) {
821
- if (e === t) return !0;
822
- if (e.enabled !== t.enabled) return !1;
823
- let n = (e, t) => {
824
- if (e.size !== t.size) return !1;
825
- for (let n of e) if (!t.has(n)) return !1;
826
- return !0;
827
- };
828
- return n(e.lineStartForbidden, t.lineStartForbidden) && n(e.lineEndForbidden, t.lineEndForbidden);
829
- }
830
- function Nt(e) {
831
- for (let t of e.runs) if (t.type === "field") {
832
- let e = t.fieldType;
833
- if (e === "page" || e === "numPages") return !0;
834
- } else if (t.type === "text" && t.noteRef) return !0;
835
- return !1;
836
- }
837
- function Pt(e, t) {
838
- let n = [], r = (e, t, r) => {
839
- let i = !1, a = t.ruby, o = a ? {
840
- text: a.text,
841
- fontSizePt: a.fontSizePt
842
- } : void 0, s = t.revision, c = t, l = c.rtl === !0 ? !0 : void 0, u = c.rtl === !0 || c.cs === !0, d = c.fontSizeCs ?? t.fontSize, f = c.fontFamilyCs ?? t.fontFamily, p = c.boldCs ?? t.bold, m = c.italicCs ?? t.italic, h = t.fontFamilyEastAsia ?? t.fontFamily, g = (u || c.rtl === !0) && wt(c.langBidi, c.rtl === !0), _ = !0, v = !1, y = (e, a, u) => {
843
- n.push({
844
- text: e,
845
- bold: a ? p : t.bold,
846
- italic: a ? m : t.italic,
847
- underline: t.underline,
848
- strikethrough: t.strikethrough,
849
- fontSize: a ? d : t.fontSize,
850
- color: t.color,
851
- fontFamily: u,
852
- vertAlign: r,
853
- measuredWidth: 0,
854
- smallCaps: i,
855
- joinPrev: v ? !0 : void 0,
856
- doubleStrikethrough: t.doubleStrikethrough ?? !1,
857
- highlight: t.highlight ?? null,
858
- background: t.background ?? null,
859
- colorAuto: c.colorAuto ?? !1,
860
- border: c.border ?? null,
861
- ruby: _ ? o : void 0,
862
- revision: s,
863
- rtl: l,
864
- digitsAsAN: g ? !0 : void 0,
865
- eaFloorFamily: h
866
- }), _ = !1, v = !1;
867
- }, b = (e, n) => {
868
- let r = n === "cs", i = n === "cs" ? f : n === "ea" ? h : t.fontFamily;
869
- if (U(i)) {
870
- for (let t of K(e, i)) y(t.text, r, t.mapped ? null : i);
871
- return;
872
- }
873
- y(e, r, i);
874
- }, x = (e) => {
875
- for (let t of Et(e)) b(t.text, t.ea ? "ea" : "latin");
876
- }, S = t.smallCaps ? vt(e) : [{
877
- text: e,
878
- reduced: !1
879
- }], C = "";
880
- for (let e of S) {
881
- i = e.reduced, v = C.length > 0 && !/\s$/.test(C), C = e.text;
882
- let n = t.allCaps || t.smallCaps ? e.text.toUpperCase() : e.text;
883
- for (let e of Ot(n)) if (u) if (g) for (let t of Dt(e)) b(t, "cs");
884
- else b(e, "cs");
885
- else for (let t of Tt(e)) t.cs ? b(t.text, "cs") : x(t.text);
886
- }
887
- };
888
- for (let i of e) if (i.type === "text") {
889
- let e = i, a = e.noteRef ? e.noteRef.id ? t.noteNumbers?.get(`${e.noteRef.kind}:${e.noteRef.id}`) : t.currentNoteNumber : void 0;
890
- if (e.noteRef) {
891
- let t = a == null ? e.text || "" : String(a);
892
- t.length > 0 && r(t, e, e.vertAlign ?? "super");
893
- continue;
894
- }
895
- let o = e.text.split(" ");
896
- for (let t = 0; t < o.length; t++) o[t].length > 0 && r(o[t], e, e.vertAlign), t < o.length - 1 && n.push({
897
- isTab: !0,
898
- fontSize: e.fontSize,
899
- measuredWidth: 0,
900
- bold: e.bold,
901
- italic: e.italic
902
- });
903
- } else if (i.type === "image") {
904
- let e = i;
905
- n.push({
906
- imagePath: e.imagePath,
907
- mimeType: e.mimeType,
908
- widthPt: e.widthPt,
909
- heightPt: e.heightPt,
910
- anchor: e.anchor ?? !1,
911
- anchorXPt: e.anchorXPt ?? 0,
912
- anchorYPt: e.anchorYPt ?? 0,
913
- anchorXFromMargin: e.anchorXFromMargin ?? !1,
914
- anchorYFromPara: e.anchorYFromPara ?? !1,
915
- colorReplaceFrom: e.colorReplaceFrom,
916
- srcRect: e.srcRect ?? void 0,
917
- measuredWidth: 0
918
- });
919
- } else if (i.type === "break") {
920
- if (i.breakType === "line") {
921
- let t = yt(e, e.indexOf(i));
922
- n.push({
923
- lineBreak: !0,
924
- fontSize: t,
925
- measuredWidth: 0
926
- });
927
- }
928
- } else if (i.type === "field") {
929
- let e = i, n = bt(e, t);
930
- n && r(n, e, e.vertAlign);
931
- } else if (i.type === "math") {
932
- let t = i.fontSize || yt(e, e.indexOf(i));
933
- n.push({
934
- mathNodes: i.nodes,
935
- display: i.display,
936
- fontSize: t,
937
- color: null,
938
- measuredWidth: 0,
939
- mathAscent: 0,
940
- mathDescent: 0,
941
- jc: i.jc
942
- });
943
- }
944
- for (let e = 1; e < n.length; e++) {
945
- let t = n[e];
946
- if (!("text" in t) || t.joinPrev) continue;
947
- let r = t.text.codePointAt(0);
948
- if (r === void 0 || !b.lineStartForbidden.has(r)) continue;
949
- let i = n[e - 1];
950
- !("text" in i) || /\s$/.test(i.text) || (t.joinPrev = !0);
951
- }
952
- return n;
953
- }
954
- function Ft(e, t, n, r, i, a = [], o, s = {}, c = 0, l = b, u = 0, d = 36) {
955
- let f = [], p = [], m = 0, h = 0, g = 0, _ = 0, v = 0, y = 0, x = !0, S = n, C = 0, w = o?.startPageY ?? 0, T = () => be(i), E = (e = 0) => {
956
- if (C = 0, S = n, !o) return;
957
- let t = 10 * i, r = we(w, e, t, o.paraX, n, o.floats);
958
- w = r.topY, C = r.xOffset, S = r.maxWidth;
959
- }, D = () => S - (x ? r : 0), O = !1, k = (e, t = !1) => {
960
- let n = e === void 0 ? g || 10 : e, r = _ > 0 || v > 0, a = r ? _ : n * i * .8, s = r ? v : n * i * .2;
961
- f.push({
962
- segments: p,
963
- height: n,
964
- ascent: a,
965
- descent: s,
966
- intendedSingle: y,
967
- xOffset: C,
968
- availWidth: S,
969
- topY: o ? w : void 0,
970
- hasRuby: O,
971
- endsWithBreak: t
972
- }), o && (w += o.lineBoxH(a, s, O, y)), p = [], m = 0, h = 0, g = 0, _ = 0, v = 0, y = 0, O = !1, x = !1, E(T());
973
- }, M = (e, t, n, r, a, o = 0) => {
974
- if (p.push(e), m += t, h += o, n > g && (g = n), r > _ && (_ = r), a > v && (v = a), !("isTab" in e) && !("imagePath" in e) && !("mathNodes" in e)) {
975
- let t = e;
976
- t.ruby && (O = !0);
977
- let n = t.smallCaps && !t.vertAlign ? t.fontSize * i : N(t), r = A(t.fontFamily, n);
978
- r > y && (y = r);
979
- }
980
- }, N = (e) => at(e, i), P = null, I = (t) => {
981
- t !== P && (e.font = t, P = t);
982
- }, L = (t) => (I(X(t.bold, t.italic, N(t), t.fontFamily, s)), e.measureText(t.text)), R = (e) => pt(L(e).width, e.text, u), z = (t, n) => (I(X(t.bold, t.italic, N(t), t.fontFamily, s)), pt(e.measureText(n).width, n, u)), ee = (e) => "isTab" in e ? e.measuredWidth || 0 : "imagePath" in e ? e.widthPt * i : "mathNodes" in e ? e.measuredWidth || 0 : "lineBreak" in e ? 0 : R(e), B = [...t], V = null;
983
- for (E(T()); B.length > 0;) {
984
- let t = B.shift();
985
- if ("lineBreak" in t) {
986
- k(t.fontSize, !0), V = t.fontSize;
987
- continue;
988
- }
989
- if (V = null, "isTab" in t) {
990
- let e = m + (x ? r : 0), n = jt(e + c, a.map((e) => ({
991
- pos: e.pos * i,
992
- alignment: e.alignment,
993
- leader: e.leader
994
- })), d * i), o = n ? n.pos - c : e;
995
- if (n && n.alignment !== "left" && n.alignment !== "bar" && n.alignment !== "clear") {
996
- let r = o;
997
- t.leader = n.leader;
998
- let a = 0;
999
- for (let e of B) {
1000
- if ("isTab" in e || "lineBreak" in e) break;
1001
- a += ee(e);
1002
- }
1003
- let s = n.alignment === "center" ? .5 : 1, c = r - e - a * s;
1004
- for (c <= 0 && (c = t.fontSize * i * .25), t.measuredWidth = c, M(t, c, t.fontSize, t.fontSize * i * .8, t.fontSize * i * .2); B.length > 0;) {
1005
- let e = B[0];
1006
- if ("isTab" in e || "lineBreak" in e) break;
1007
- if (B.shift(), "imagePath" in e) {
1008
- let t = e.widthPt * i;
1009
- e.measuredWidth = t, M(e, t, e.heightPt, e.heightPt * i, 0);
1010
- } else if ("mathNodes" in e) M(e, e.measuredWidth || 0, e.fontSize, e.mathAscent || 0, e.mathDescent || 0);
1011
- else {
1012
- let t = L(e), n = pt(t.width, e.text, u);
1013
- e.measuredWidth = n;
1014
- let r = t.fontBoundingBoxAscent ?? t.actualBoundingBoxAscent ?? e.fontSize * i * .8, a = t.fontBoundingBoxDescent ?? t.actualBoundingBoxDescent ?? e.fontSize * i * .2;
1015
- M(e, n, e.fontSize, r, a);
1016
- }
1017
- }
1018
- continue;
1019
- }
1020
- let s = o - e;
1021
- if (n && (t.leader = n.leader), s <= 0) {
1022
- k(), B.unshift(t);
1023
- continue;
1024
- }
1025
- if (m + s > D() && p.length > 0) {
1026
- k(), B.unshift(t);
1027
- continue;
1028
- }
1029
- t.measuredWidth = s, M(t, s, t.fontSize, t.fontSize * i * .8, t.fontSize * i * .2);
1030
- continue;
1031
- }
1032
- if ("imagePath" in t) {
1033
- if (t.anchor) {
1034
- t.measuredWidth = 0;
1035
- continue;
1036
- }
1037
- let e = t.widthPt * i, n = t.heightPt, r = t.heightPt * i;
1038
- t.measuredWidth = e, p.length > 0 && m + e > D() && k(), M(t, e, n, r, 0);
1039
- continue;
1040
- }
1041
- if ("mathNodes" in t) {
1042
- let e = Je.get(t.mathNodes);
1043
- if (!e) {
1044
- t.measuredWidth = 0;
1045
- continue;
1046
- }
1047
- let n = t.fontSize * i, r = e.widthEm * n, a = e.ascentEm * n, o = e.descentEm * n;
1048
- t.measuredWidth = r, t.mathAscent = a, t.mathDescent = o;
1049
- let s = Math.max(a, n * .8), c = Math.max(o, n * .2);
1050
- p.length > 0 && m + r > D() && k(), M(t, r, t.fontSize, s, c);
1051
- continue;
1052
- }
1053
- let n = t, o = L(n), f = pt(o.width, n.text, u), g = n.fontSize, _ = n.fontSize * i, v = o, y = N(n);
1054
- if (n.smallCaps && !n.vertAlign && y !== _) {
1055
- let t = e.font;
1056
- e.font = X(n.bold, n.italic, _, n.fontFamily, s), v = e.measureText(n.text || "X"), e.font = t, y = _;
1057
- }
1058
- let S = gt(v, n.fontFamily, _, y), C = S.ascent, w = S.descent;
1059
- n.ruby && (C += n.ruby.fontSizePt * i * 1.5);
1060
- let T = n.text.replace(/ +$/, ""), E = n.text.endsWith(" ") ? f - pt(e.measureText(T).width, T, u) : 0, O = f - E, A = h * kt;
1061
- if (!n.joinPrev && p.length > 0 && B[0]?.joinPrev && !xt(n.text)) {
1062
- let t = f, n = E;
1063
- for (let r = 0; r < B.length && B[r].joinPrev; r++) {
1064
- let i = B[r];
1065
- if (xt(i.text)) {
1066
- let e = [...i.text], r = 0;
1067
- for (; r < e.length && b.lineStartForbidden.has(e[r].codePointAt(0));) r++;
1068
- if (r < e.length) {
1069
- t += z(i, e.slice(0, r).join("")), n = 0;
1070
- break;
1071
- }
1072
- }
1073
- let a = R(i);
1074
- t += a;
1075
- let o = i.text.replace(/ +$/, "");
1076
- n = i.text.endsWith(" ") ? a - pt(e.measureText(o).width, o, u) : 0;
1077
- }
1078
- m + (t - n) > D() + A && k();
1079
- }
1080
- if (m + O <= D() + A) n.measuredWidth = f, M(n, f, g, C, w, E);
1081
- else if (xt(n.text)) {
1082
- let t = D() - m;
1083
- e.font = X(n.bold, n.italic, N(n), n.fontFamily, s);
1084
- let r = t > 0 ? St(e, n.text, t, u) : "", i = [...n.text], a = [...r].length, o = F(i, a, l, p.length > 0 ? 0 : 1), c = i.slice(0, o).join("");
1085
- if (c.length > 0) {
1086
- let e = z(n, c);
1087
- M({
1088
- ...n,
1089
- text: c,
1090
- measuredWidth: e
1091
- }, e, g, C, w);
1092
- let t = n.text.slice(c.length);
1093
- t && B.unshift({
1094
- ...n,
1095
- text: t,
1096
- measuredWidth: 0
1097
- });
1098
- } else if (p.length > 0) {
1099
- let e = null, t = n.text.codePointAt(0), r = p[p.length - 1];
1100
- if (t !== void 0 && l.lineStartForbidden.has(t) && "text" in r) {
1101
- let t = r, n = [...t.text], i = j(n, l, p.length > 1 ? 0 : 1);
1102
- if (i > 0) {
1103
- let r = n.slice(0, n.length - i).join(""), a = n.slice(n.length - i).join("");
1104
- if (e = {
1105
- ...t,
1106
- text: a,
1107
- measuredWidth: z(t, a)
1108
- }, r) {
1109
- let e = z(t, r);
1110
- m -= t.measuredWidth - e, p[p.length - 1] = {
1111
- ...t,
1112
- text: r,
1113
- measuredWidth: e
1114
- };
1115
- } else m -= t.measuredWidth, p.pop();
1116
- }
1117
- }
1118
- k(), B.unshift(n), e && B.unshift(e);
1119
- } else {
1120
- let e = [...n.text][0] ?? "";
1121
- if (e) {
1122
- let t = z(n, e);
1123
- M({
1124
- ...n,
1125
- text: e,
1126
- measuredWidth: t
1127
- }, t, g, C, w);
1128
- let r = n.text.slice(e.length);
1129
- r && B.unshift({
1130
- ...n,
1131
- text: r,
1132
- measuredWidth: 0
1133
- });
1134
- }
1135
- }
1136
- } else if (p.length === 0) {
1137
- let t = D();
1138
- e.font = X(n.bold, n.italic, N(n), n.fontFamily, s);
1139
- let r = [...n.text], i = t > 0 ? [...St(e, n.text, t, u)].length : 0;
1140
- if (i < 1 && (i = 1), i >= r.length) n.measuredWidth = f, M(n, f, g, C, w);
1141
- else {
1142
- let e = r.slice(0, i).join(""), t = z(n, e);
1143
- M({
1144
- ...n,
1145
- text: e,
1146
- measuredWidth: t
1147
- }, t, g, C, w), B.unshift({
1148
- ...n,
1149
- text: r.slice(i).join(""),
1150
- measuredWidth: 0
1151
- });
1152
- }
1153
- } else k(), B.unshift(n);
1154
- }
1155
- return p.length > 0 ? k() : V !== null && k(V), f;
1156
- }
1157
- function It(e, t, n, r, i) {
1158
- if (t === 1) return e;
1159
- let a = (e) => {
1160
- let a = at(e, t);
1161
- n.font = X(e.bold, e.italic, a, e.fontFamily, r);
1162
- let o = n.measureText(e.text), s = pt(o.width, e.text, i), c = e.fontSize * t, l = o, u = a;
1163
- e.smallCaps && !e.vertAlign && u !== c && (n.font = X(e.bold, e.italic, c, e.fontFamily, r), l = n.measureText(e.text || "X"), u = c);
1164
- let d = gt(l, e.fontFamily, c, u), f = e.ruby ? d.ascent + e.ruby.fontSizePt * t * 1.5 : d.ascent, p = e.smallCaps && !e.vertAlign ? c : a, m = A(e.fontFamily, p);
1165
- return {
1166
- advance: s,
1167
- asc: f,
1168
- desc: d.descent,
1169
- intended: m
1170
- };
1171
- };
1172
- return e.map((e) => {
1173
- let n = 0, r = 0, i = 0, o = !1, s = e.segments.map((e) => {
1174
- if ("isTab" in e) return {
1175
- ...e,
1176
- measuredWidth: e.measuredWidth * t
1177
- };
1178
- if ("imagePath" in e) return e.anchor ? {
1179
- ...e,
1180
- measuredWidth: 0
1181
- } : {
1182
- ...e,
1183
- measuredWidth: e.widthPt * t
1184
- };
1185
- if ("mathNodes" in e) {
1186
- let i = {
1187
- ...e,
1188
- measuredWidth: e.measuredWidth * t
1189
- };
1190
- return i.mathAscent *= t, i.mathDescent *= t, n = Math.max(n, i.mathAscent, e.fontSize * t * .8), r = Math.max(r, i.mathDescent, e.fontSize * t * .2), i;
1191
- }
1192
- let s = e, c = a(s);
1193
- return o = !0, c.asc > n && (n = c.asc), c.desc > r && (r = c.desc), c.intended > i && (i = c.intended), {
1194
- ...s,
1195
- measuredWidth: c.advance
1196
- };
1197
- });
1198
- return !o && n === 0 && r === 0 && (n = e.ascent * t, r = e.descent * t, i = e.intendedSingle * t), {
1199
- ...e,
1200
- segments: s,
1201
- ascent: n,
1202
- descent: r,
1203
- intendedSingle: i,
1204
- xOffset: e.xOffset * t,
1205
- availWidth: e.availWidth * t,
1206
- topY: e.topY === void 0 ? void 0 : e.topY * t
1207
- };
1208
- });
1209
- }
1210
- function Lt(e) {
1211
- return {
1212
- type: "text",
1213
- text: e.text,
1214
- bold: e.bold ?? !1,
1215
- italic: e.italic ?? !1,
1216
- underline: !1,
1217
- strikethrough: !1,
1218
- fontSize: e.fontSizePt,
1219
- color: e.color ?? null,
1220
- fontFamily: e.fontFamily ?? null,
1221
- fontFamilyEastAsia: e.fontFamilyEastAsia ?? null,
1222
- isLink: !1,
1223
- background: null,
1224
- vertAlign: null,
1225
- hyperlink: null
1226
- };
1227
- }
1228
- function Rt(e, t, n, r) {
1229
- return {
1230
- ctx: e,
1231
- scale: t,
1232
- fontFamilyClasses: n,
1233
- images: r,
1234
- kinsoku: b,
1235
- defaultTabPt: 36
1236
- };
1237
- }
1238
- //#endregion
1239
- //#region packages/docx/src/renderer.ts
1240
- var zt = {
1241
- yellow: "#FFFF00",
1242
- cyan: "#00FFFF",
1243
- green: "#00FF00",
1244
- magenta: "#FF00FF",
1245
- blue: "#0000FF",
1246
- red: "#FF0000",
1247
- darkBlue: "#000080",
1248
- darkCyan: "#008080",
1249
- darkGreen: "#008000",
1250
- darkMagenta: "#800080",
1251
- darkRed: "#800000",
1252
- darkYellow: "#808000",
1253
- darkGray: "#808080",
1254
- lightGray: "#C0C0C0",
1255
- black: "#000000",
1256
- white: "#FFFFFF"
1257
- };
1258
- function Bt(e) {
1259
- return Vt(e).length > 0;
1260
- }
1261
- function Vt(e) {
1262
- let t = [], n = (e) => {
1263
- for (let n of e) n.type === "math" && t.push({
1264
- nodes: n.nodes,
1265
- display: n.display
1266
- });
1267
- }, r = (e) => {
1268
- if ("runs" in e && n(e.runs), "rows" in e) for (let t of e.rows) for (let e of t.cells) for (let t of e.content) r(t);
1269
- };
1270
- return e.forEach(r), t;
1271
- }
1272
- function Ht(e) {
1273
- let t = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`, n = new Image();
1274
- return new Promise((e, r) => {
1275
- n.onload = () => e(n), n.onerror = r, n.src = t;
1276
- });
1277
- }
1278
- async function Ut(e, t) {
1279
- let n = Vt(e);
1280
- if (n.length !== 0) {
1281
- await t.loadMathJax();
1282
- for (let e of n) if (!Je.has(e.nodes)) try {
1283
- let n = await t.mathMLToSvg(v(e.nodes, e.display)), r = await Ht(ae(n.svg, "#000000"));
1284
- Je.set(e.nodes, {
1285
- img: r,
1286
- widthEm: n.widthEm,
1287
- ascentEm: n.ascentEm,
1288
- descentEm: n.descentEm
1289
- });
1290
- } catch {}
1291
- }
1292
- }
1293
- function Wt(e, t) {
1294
- return t ? `${e}|clr:${t}` : e;
1295
- }
1296
- var Gt = /* @__PURE__ */ new WeakMap();
1297
- function Kt(e) {
1298
- let t = Gt.get(e);
1299
- return t || (t = /* @__PURE__ */ new Map(), Gt.set(e, t)), t;
1300
- }
1301
- function qt(e) {
1302
- let t = Gt.get(e);
1303
- if (t) {
1304
- for (let e of t.values()) e.then((e) => e.close()).catch(() => {});
1305
- t.clear(), Gt.delete(e);
1306
- }
1307
- }
1308
- var Jt = [
1309
- "#C00000",
1310
- "#0070C0",
1311
- "#00B050",
1312
- "#7030A0",
1313
- "#E97132",
1314
- "#196B24",
1315
- "#9E480E",
1316
- "#525252"
1317
- ];
1318
- function Yt(e) {
1319
- if (!e) return Jt[0];
1320
- let t = 2166136261;
1321
- for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, 16777619);
1322
- return Jt[Math.abs(t) % Jt.length];
1323
- }
1324
- function Xt(e) {
1325
- let t = /* @__PURE__ */ new Map(), n = (e) => {
1326
- let n = Wt(e.imagePath, e.colorReplaceFrom), r = t.get(n);
1327
- r ? (r.widthPt = Math.max(r.widthPt, e.widthPt), r.heightPt = Math.max(r.heightPt, e.heightPt), r.hasCrop = r.hasCrop || e.hasCrop) : t.set(n, e);
1328
- }, r = (e) => {
1329
- let t = e.numbering, r = t?.picBulletImagePath;
1330
- if (r && t) {
1331
- let i = Qr(t, e);
1332
- n({
1333
- imagePath: r,
1334
- mimeType: t.picBulletMimeType ?? "",
1335
- widthPt: i.w,
1336
- heightPt: i.h
1337
- });
1338
- }
1339
- }, i = (e) => {
1340
- for (let t of e) if (t.type === "image") {
1341
- let e = t;
1342
- n({
1343
- imagePath: e.imagePath,
1344
- mimeType: e.mimeType,
1345
- svgImagePath: e.svgImagePath,
1346
- colorReplaceFrom: e.colorReplaceFrom,
1347
- ...ee(e.mimeType, e.srcRect, e.widthPt ?? 0, e.heightPt ?? 0),
1348
- hasCrop: e.srcRect != null
1349
- });
1350
- } else if (t.type === "shape") {
1351
- let e = t;
1352
- for (let t of e.textBlocks ?? []) t.imagePath && n({
1353
- imagePath: t.imagePath,
1354
- mimeType: t.mimeType ?? "",
1355
- svgImagePath: t.svgImagePath,
1356
- widthPt: t.imageWidthPt ?? 0,
1357
- heightPt: t.imageHeightPt ?? 0
1358
- });
1359
- }
1360
- }, a = (e) => {
1361
- for (let t of e.rows) for (let e of t.cells) for (let t of e.content) if (t.type === "paragraph") {
1362
- let e = t;
1363
- r(e), i(e.runs);
1364
- } else t.type === "table" && a(t);
1365
- }, o = (e) => {
1366
- for (let t of e) {
1367
- if (t.type === "paragraph") {
1368
- let e = t;
1369
- r(e), i(e.runs);
1370
- }
1371
- t.type === "table" && a(t);
1372
- }
1373
- };
1374
- return o(e.body), e.headers.default && o(e.headers.default.body), e.headers.first && o(e.headers.first.body), e.headers.even && o(e.headers.even.body), e.footers.default && o(e.footers.default.body), e.footers.first && o(e.footers.first.body), e.footers.even && o(e.footers.even.body), [...t.values()];
1375
- }
1376
- async function Zt(e, t) {
1377
- let n = parseInt(t.slice(0, 2), 16), r = parseInt(t.slice(2, 4), 16), i = parseInt(t.slice(4, 6), 16), a = new OffscreenCanvas(e.width, e.height), o = a.getContext("2d");
1378
- o.drawImage(e, 0, 0);
1379
- let s = o.getImageData(0, 0, e.width, e.height), c = s.data;
1380
- for (let e = 0; e < c.length; e += 4) c[e] === n && c[e + 1] === r && c[e + 2] === i && (c[e + 3] = 0);
1381
- return o.putImageData(s, 0, 0), createImageBitmap(a);
1382
- }
1383
- async function Qt(e, t, n, r, i = 0, a = 0) {
1384
- let o = await B(e, t, r, {
1385
- widthPt: i,
1386
- heightPt: a,
1387
- suppressBoundaryFrame: !0
1388
- });
1389
- if (!o) throw Error(`${e} produced no drawable output`);
1390
- if (!n) return o;
1391
- let s = Kt(r), c = Wt(e, n), l = s.get(c);
1392
- return l || (l = Zt(o, n), l.catch(() => s.delete(c)), s.set(c, l)), l;
1393
- }
1394
- async function $t(e, t) {
1395
- if (!t) return /* @__PURE__ */ new Map();
1396
- let n = t, r = Xt(e), i = await Promise.all(r.map(async (e) => {
1397
- let t = e.mimeType === "image/svg+xml", r = {
1398
- svgImagePath: e.svgImagePath,
1399
- srcRect: e.hasCrop || null
1400
- };
1401
- try {
1402
- let i;
1403
- if (R(r)) try {
1404
- i = await z(r.svgImagePath, n);
1405
- } catch {
1406
- i = t ? await z(e.imagePath, n) : await Qt(e.imagePath, e.mimeType, e.colorReplaceFrom, n, e.widthPt, e.heightPt);
1407
- }
1408
- else i = t ? await z(e.imagePath, n) : await Qt(e.imagePath, e.mimeType, e.colorReplaceFrom, n, e.widthPt, e.heightPt);
1409
- return [Wt(e.imagePath, e.colorReplaceFrom), i];
1410
- } catch {
1411
- return null;
1412
- }
1413
- }));
1414
- return new Map(i.filter((e) => e !== null));
1415
- }
1416
- var en = /* @__PURE__ */ new WeakMap();
1417
- async function tn(e, t, n, r = {}) {
1418
- let i = (en.get(t) ?? 0) + 1;
1419
- en.set(t, i);
1420
- let a = () => en.get(t) !== i, o = r.dpr ?? w(), s = t.getContext("2d"), c = O(e.settings), l = r.prebuiltPages ?? wn(e, s, e.fontFamilyClasses ?? {}, c, e.footnotes ?? []), u = Math.max(r.totalPages ?? l.length, l.length), d = l[n] ?? l[0] ?? [], f = Un(l, n, e).geom, p = {
1421
- ...e.section,
1422
- ...f
1423
- }, m = r.width ?? p.pageWidth * 1.3333333333333333, h = m / p.pageWidth, g = p.pageHeight * h;
1424
- t.width = Math.round(m * o), t.height = Math.round(g * o), C(t) && (t.style.width = `${m}px`, t.style.height = `${g}px`, t.style.display || (t.style.display = "block")), s.scale(o, o), s.fillStyle = "#ffffff", s.fillRect(0, 0, m, g);
1425
- let _ = await $t(e, r.fetchImage);
1426
- if (a()) return;
1427
- let v = cn(e.footnotes), y = cn(e.endnotes), b = /* @__PURE__ */ new Map();
1428
- for (let [e, t] of v) b.set(`footnote:${e}`, t);
1429
- for (let [e, t] of y) b.set(`endnote:${e}`, t);
1430
- let x = An(e.body), S = Q(p.marginTop), T = Q(p.marginBottom), E = {
1431
- ctx: s,
1432
- scale: h,
1433
- dpr: o,
1434
- contentX: p.marginLeft * h,
1435
- contentW: (p.pageWidth - p.marginLeft - p.marginRight) * h,
1436
- y: S * h,
1437
- pageH: g,
1438
- defaultColor: r.defaultTextColor ?? "#000000",
1439
- pageIndex: n,
1440
- totalPages: u,
1441
- images: _,
1442
- dryRun: !1,
1443
- marginLeft: p.marginLeft,
1444
- marginRight: p.marginRight,
1445
- marginTop: S,
1446
- marginBottom: T,
1447
- pageWidth: p.pageWidth,
1448
- floats: [],
1449
- floatParaSeq: 0,
1450
- docGrid: {
1451
- type: p.docGridType ?? null,
1452
- linePitchPt: p.docGridLinePitch ?? null,
1453
- charSpacePt: p.docGridCharSpace == null ? null : p.docGridCharSpace / 4096
1454
- },
1455
- docEastAsian: x,
1456
- fontFamilyClasses: e.fontFamilyClasses ?? {},
1457
- kinsoku: c,
1458
- defaultTabPt: At(e.settings),
1459
- mathDefJc: e.settings?.mathDefJc,
1460
- onTextRun: r.onTextRun,
1461
- showTrackChanges: r.showTrackChanges ?? !0,
1462
- noteNumbers: b
1463
- }, D = bn(l, n, e), k = 0;
1464
- if (D) {
1465
- let e = Gn(D, E);
1466
- Wn(D, p.headerDistance * h, E), k = _n(e, p.marginTop * h, p.headerDistance * h);
1467
- }
1468
- let A = yn(l, n, e), j = 0;
1469
- if (A) {
1470
- let e = Gn(A, E);
1471
- Wn(A, g - p.footerDistance * h - e, E), j = gn(e, p.marginBottom * h, p.footerDistance * h);
1472
- }
1473
- let M = pn(p), N = {
1474
- ...E,
1475
- y: S * h + k
1476
- };
1477
- if (p.columns?.sep) {
1478
- let e = /* @__PURE__ */ new Set(), t = [];
1479
- for (let n of d) {
1480
- let r = n.colGeom ?? M;
1481
- r.length > 1 && !e.has(r) && (e.add(r), t.push(r));
1482
- }
1483
- t.length === 0 && M.length > 1 && t.push(M);
1484
- for (let e of t) Xn(s, e, p, h);
1485
- }
1486
- Zn(d, N, M, k), rn(d, e, E, h, g, p, j), n === u - 1 && an(e, N, h, g, p);
1487
- }
1488
- function nn(e, t, n, r, i, a, o = 36) {
1489
- return dn(e, En(t, n, r, i, a, o), n.pageWidth - n.marginLeft - n.marginRight);
1490
- }
1491
- function rn(e, t, n, r, i, a, o = 0) {
1492
- if (!t.footnotes || t.footnotes.length === 0) return;
1493
- let s = ln(t.footnotes), c = [], l = /* @__PURE__ */ new Set();
1494
- if (((e) => {
1495
- for (let t of e) if (t.type === "paragraph") for (let e of un(t.runs)) !l.has(e) && s.has(e) && (l.add(e), c.push(e));
1496
- })(e), c.length === 0) return;
1497
- let u = 0, d = 0;
1498
- for (let e of c) {
1499
- let t = s.get(e);
1500
- if (!t) continue;
1501
- let r = nn(t, n.ctx, a, n.fontFamilyClasses, n.kinsoku, n.docEastAsian, n.defaultTabPt);
1502
- u += r.total, d = r.trailingSpaceAfter;
1503
- }
1504
- let f = Math.max(0, u - d), p = on * r, m = i - Q(a.marginBottom) * r - o - f * r, h = a.marginLeft * r, g = Math.round(m - p), _ = n.ctx;
1505
- _.save(), _.strokeStyle = n.defaultColor;
1506
- let v = Math.max(1, Math.round(.5 * r));
1507
- _.lineWidth = v;
1508
- let y = k(g, v, n.dpr);
1509
- _.beginPath(), _.moveTo(h, g + y), _.lineTo(h + (a.pageWidth - a.marginLeft - a.marginRight) * r / 3, g + y), _.stroke(), _.restore();
1510
- let b = {
1511
- ...n,
1512
- y: m
1513
- };
1514
- for (let e of c) {
1515
- let n = s.get(e);
1516
- n && (b.currentNoteNumber = t.footnotes.findIndex((t) => t.id === e) + 1, Qn(n.content.filter((e) => e.type === "paragraph"), b));
1517
- }
1518
- }
1519
- function an(e, t, n, r, i) {
1520
- if (!e.endnotes || e.endnotes.length === 0) return;
1521
- let a = e.endnotes.filter((e) => e.content.some((e) => e.type === "paragraph" && e.runs.length > 0));
1522
- if (a.length === 0) return;
1523
- let o = t.ctx, s = t.y + on * 2 * n;
1524
- if (s >= r - Q(i.marginBottom) * n) return;
1525
- let c = i.marginLeft * n;
1526
- o.save(), o.strokeStyle = t.defaultColor;
1527
- let l = Math.max(1, Math.round(.5 * n));
1528
- o.lineWidth = l;
1529
- let u = Math.round(s), d = k(u, l, t.dpr);
1530
- o.beginPath(), o.moveTo(c, u + d), o.lineTo(c + (i.pageWidth - i.marginLeft - i.marginRight) * n / 3, u + d), o.stroke(), o.restore();
1531
- let f = {
1532
- ...t,
1533
- y: s + on * n
1534
- };
1535
- for (let t of a) f.currentNoteNumber = e.endnotes.findIndex((e) => e.id === t.id) + 1, Qn(t.content.filter((e) => e.type === "paragraph"), f);
1536
- }
1537
- var on = 6, sn = {
1538
- default: null,
1539
- first: null,
1540
- even: null
1541
- };
1542
- function cn(e) {
1543
- let t = /* @__PURE__ */ new Map();
1544
- return e && e.forEach((e, n) => t.set(e.id, n + 1)), t;
1545
- }
1546
- function ln(e) {
1547
- let t = /* @__PURE__ */ new Map();
1548
- if (!e) return t;
1549
- for (let n of e) t.set(n.id, n);
1550
- return t;
1551
- }
1552
- function un(e) {
1553
- let t = [];
1554
- for (let n of e) {
1555
- if (n.type !== "text") continue;
1556
- let e = n.noteRef;
1557
- e && e.kind === "footnote" && e.id && t.push(e.id);
1558
- }
1559
- return t;
1560
- }
1561
- function dn(e, t, n) {
1562
- let r = 0, i = 0;
1563
- for (let a of e.content) {
1564
- if (a.type !== "paragraph") continue;
1565
- let e = a;
1566
- r += Dn(t, e, n, !1), i = e.spaceAfter;
1567
- }
1568
- return {
1569
- total: r,
1570
- trailingSpaceAfter: i
1571
- };
1572
- }
1573
- function fn(e, t, n, r) {
1574
- let { total: i, trailingSpaceAfter: a } = dn(e, t, n);
1575
- return Math.max(0, i - a) + (r ? on : 0);
1576
- }
1577
- function pn(e) {
1578
- let t = e.pageWidth - e.marginLeft - e.marginRight, n = e.columns;
1579
- if (!n || n.count <= 1) return [{
1580
- xPt: e.marginLeft,
1581
- wPt: Math.max(1, t)
1582
- }];
1583
- if (!n.equalWidth && n.cols.length > 0) {
1584
- let t = [], r = e.marginLeft;
1585
- for (let e of n.cols) t.push({
1586
- xPt: r,
1587
- wPt: Math.max(1, e.widthPt)
1588
- }), r += e.widthPt + e.spacePt;
1589
- return t;
1590
- }
1591
- let r = n.count, i = n.spacePt, a = Math.max(1, (t - (r - 1) * i) / r), o = [];
1592
- for (let t = 0; t < r; t++) o.push({
1593
- xPt: e.marginLeft + t * (a + i),
1594
- wPt: a
1595
- });
1596
- return o;
1597
- }
1598
- var mn = {
1599
- top: 0,
1600
- bottom: 0
1601
- };
1602
- function hn(e, t, n, r = {}, i = b, a = [], o = [], s = 36) {
1603
- let c = () => Q(O.marginTop), l = () => Q(O.marginBottom), u = () => O.pageHeight - c() - l(), d = En(n, t, r, i, An(e), s), f = ln(a), p = f.size > 0, m = [0], h = (n) => {
1604
- for (let r = n; r < e.length; r++) {
1605
- let n = e[r];
1606
- if (n.type === "sectionBreak") return pn({
1607
- ...t,
1608
- columns: n.columns ?? null
1609
- });
1610
- }
1611
- return pn(t);
1612
- }, g = (n) => {
1613
- for (let t = n; t < e.length; t++) {
1614
- let n = e[t];
1615
- if (n.type === "sectionBreak") return n.kind ?? "nextPage";
1616
- }
1617
- return t.sectionStart ?? "nextPage";
1618
- }, _ = (t) => Jn(e, t) && g(t + 2) === "continuous", v = (t) => _(t) ? (e[t].spaceBefore ?? 0) === 0 : !1, y = (t) => {
1619
- for (let n = t; n < e.length; n++) {
1620
- let t = e[n];
1621
- if (t.type === "sectionBreak") return {
1622
- headers: t.headers ?? sn,
1623
- footers: t.footers ?? sn,
1624
- titlePage: t.titlePage ?? !1
1625
- };
1626
- }
1627
- }, x = vn(t), S = (t) => {
1628
- for (let n = t; n < e.length; n++) {
1629
- let t = e[n];
1630
- if (t.type === "sectionBreak") return t.geom ?? x;
1631
- }
1632
- return x;
1633
- }, C = h(0), w = 0, T = () => C[w].xPt, E = () => C[w].wPt, D = y(0), O = S(0), k = 0, A = 0, j = null, M = () => c() + k, N = (e) => {
1634
- let t = d.contentX, n = d.contentW;
1635
- d.contentX = T() * d.scale, d.contentW = E() * d.scale;
1636
- try {
1637
- return e();
1638
- } finally {
1639
- d.contentX = t, d.contentW = n;
1640
- }
1641
- }, P = [[]], F = 0, I = null, L = 0;
1642
- d.y = c(), d.floats = [], d.floatParaSeq = 0, d.pageAnchorPrescanned = /* @__PURE__ */ new Set();
1643
- let R = (t) => {
1644
- d.pageAnchorPrescanned = /* @__PURE__ */ new Set(), Sr(e, t, d);
1645
- };
1646
- R(0);
1647
- let z = /* @__PURE__ */ new Set(), ee = (e) => o.length === 0 ? mn : o[Math.min(e, o.length - 1)] ?? mn, B = () => {
1648
- let e = ee(P.length - 1);
1649
- return u() - (m[P.length - 1] ?? 0) - e.bottom - e.top;
1650
- }, V = () => {
1651
- m[P.length - 1] = 0, z = /* @__PURE__ */ new Set();
1652
- }, H = (e) => {
1653
- P[P.length - 1].length > 0 && (P.push([]), F = 0, w = 0, k = 0, A = 0, j = null, I = null, L = 0, d.y = c(), d.floats = [], d.floatParaSeq = 0, R(e), V(), K(e));
1654
- }, U = () => {
1655
- A = Math.max(A, F), w++, F = k, I = null, L = 0, d.y = c() + k;
1656
- }, W = (e) => {
1657
- w < C.length - 1 ? U() : H(e);
1658
- }, G = (t, n) => {
1659
- let r = {
1660
- ...d,
1661
- y: c(),
1662
- floats: [],
1663
- floatParaSeq: 0
1664
- }, i = 0, a = 0, o = null, s = !1;
1665
- for (let c = t; c < e.length; c++) {
1666
- let t = e[c];
1667
- if (t.type === "sectionBreak" || t.type === "pageBreak") {
1668
- s = !0;
1669
- break;
1670
- }
1671
- if (t.type !== "columnBreak") {
1672
- if (t.type === "paragraph") {
1673
- let e = t;
1674
- if (e.pageBreakBefore) return {
1675
- height: Infinity,
1676
- terminated: !1
1677
- };
1678
- if (e.framePr) continue;
1679
- let s = Kn(o, e) || _(c), l = s ? 0 : e.spaceBefore;
1680
- i += Dn(r, e, n, s, 0) - Math.min(a, l), a = e.spaceAfter, o = e;
1681
- } else if (t.type === "table") {
1682
- let e = t;
1683
- if (e.tblpPr) continue;
1684
- i += Nn(r, e, n).reduce((e, t) => e + t, 0), a = 0, o = null;
1685
- }
1686
- }
1687
- }
1688
- return {
1689
- height: i,
1690
- terminated: s
1691
- };
1692
- }, K = (e) => {
1693
- j = null;
1694
- let t = C.length;
1695
- if (t < 2) return;
1696
- let { height: n, terminated: r } = G(e, C[0].wPt);
1697
- if (!r || !Number.isFinite(n)) return;
1698
- let i = B() - k;
1699
- i <= 0 || n > t * i || (j = n / t);
1700
- }, te = (e) => j != null && w < C.length - 1 && F > k && F + e > k + j, ne = (e) => {
1701
- let t = 0;
1702
- for (let n of e.runs) if (n.type === "image") {
1703
- let e = n;
1704
- if (!e.anchor || !e.anchorYFromPara) continue;
1705
- let r = (e.anchorYPt ?? 0) + e.heightPt;
1706
- r > t && (t = r);
1707
- } else if (n.type === "shape") {
1708
- let e = n;
1709
- if (!e.anchorYFromPara) continue;
1710
- let r = mr(e, d, d.y);
1711
- if (r.h <= 0) continue;
1712
- let i = (e.anchorYPt ?? 0) + r.h;
1713
- i > t && (t = i);
1714
- }
1715
- return t;
1716
- }, re = (t) => {
1717
- let n = e[t];
1718
- return n ? n.type === "paragraph" ? Dn(d, n, E(), !1) : n.type === "table" ? Fn(d, n, E()) : 0 : 0;
1719
- }, q = (e) => {
1720
- e.colIndex = w, e.colGeom = C, e.colTopPt = M(), e.sectionHF = D, e.sectionGeom = O, P[P.length - 1].push(e);
1721
- };
1722
- K(0);
1723
- for (let t = 0; t < e.length; t++) {
1724
- let n = e[t];
1725
- if (n.type === "columnBreak") {
1726
- W(t + 1);
1727
- continue;
1728
- }
1729
- if (n.type === "pageBreak") {
1730
- P.push([]), F = 0, k = 0, A = 0, j = null, I = null, L = 0, d.y = c(), d.floats = [], d.floatParaSeq = 0, R(t + 1), V(), (n.parity === "odd" && P.length % 2 == 0 || n.parity === "even" && P.length % 2 == 1) && (P.push([]), V());
1731
- continue;
1732
- }
1733
- if (n.type === "sectionBreak") {
1734
- C = h(t + 1), w = 0, D = y(t + 1), O = S(t + 1);
1735
- let e = g(t + 1);
1736
- if (e === "continuous") {
1737
- let e = Math.max(A, F);
1738
- F = e, d.y = c() + e, k = e, A = e, I = null, L = 0, K(t + 1);
1739
- } else P.push([]), F = 0, k = 0, A = 0, j = null, I = null, L = 0, d.y = c(), d.floats = [], d.floatParaSeq = 0, R(t + 1), V(), K(t + 1), (e === "oddPage" && P.length % 2 == 0 || e === "evenPage" && P.length % 2 == 1) && (P.push([]), V());
1740
- continue;
1741
- }
1742
- if (n.type === "paragraph") {
1743
- let r = n;
1744
- if (r.pageBreakBefore && H(t), r.framePr) {
1745
- let i = r.framePr, a = tr(e, n, d), o = N(() => nr(r, d, a)), s = o.y + o.h - d.y, c = i.vAnchor !== "page" && i.vAnchor !== "margin" && s > 0 && F + s > B(), l = s > 0 && s <= B();
1746
- F > 0 && c && l && W(t), N(() => {
1747
- Le(nr(r, d, a), r.framePr, d);
1748
- }), q(n);
1749
- continue;
1750
- }
1751
- let i = Kn(I, r), a = _(t);
1752
- if (a && (n.sectionBreakSpacer = !0), v(t)) {
1753
- n.collapsedSpacer = !0, q(n);
1754
- continue;
1755
- }
1756
- let o = i || a, s = qn(r) && v(t + 1);
1757
- s && (n.leadsCollapsedRun = !0);
1758
- let l = o ? 0 : r.spaceBefore, u = i || s ? L : Math.min(L, l);
1759
- F -= u, d.y -= u;
1760
- let h = d.floats.length, g = d.floatParaSeq, y = d.y;
1761
- xr(r, d, y);
1762
- let b = Dn(d, r, E(), o, T()), x = [], S = 0, M = (e) => {
1763
- let t = 0;
1764
- for (let n = 0; n < e.length; n++) {
1765
- let r = f.get(e[n]);
1766
- if (!r) continue;
1767
- let i = (m[P.length - 1] ?? 0) === 0 && n === 0;
1768
- t += fn(r, d, E(), i);
1769
- }
1770
- return t;
1771
- };
1772
- if (p) {
1773
- let e = /* @__PURE__ */ new Set();
1774
- for (let t of un(r.runs)) z.has(t) || e.has(t) || f.has(t) && (e.add(t), x.push(t));
1775
- S = M(x);
1776
- }
1777
- let R = r.keepNext ? re(t + 1) : 0, ee = b - r.spaceAfter, V = ee + R + S, U = ne(r), G = U > 0 && F + U > B(), K = U > 0 && U <= B(), J = F > 0 && G && K, ie = F > 0 && F + V > B(), ae = r.keepLines || R > 0 || S > 0, oe = !r.keepLines || b > B(), se = te(ee) && !oe;
1778
- if (J || se || ie && ae && V <= B()) {
1779
- let e = P.length;
1780
- W(t), P.length > e ? (xr(r, d, d.y), p && x.length > 0 && (S = M(x))) : (d.floats.length = h, d.floatParaSeq = g, xr(r, d, d.y));
1781
- }
1782
- let ce = B(), le = () => j != null && w < C.length - 1 ? Math.min(B(), k + j) : B();
1783
- if (ee > le() - F && oe) {
1784
- let e = Mn(d, r, E(), o, T(), F, ce, P, (e) => {
1785
- A = Math.max(A, e), W(t);
1786
- }, () => w, C, () => k, le, () => D, () => O);
1787
- F = e.endY, d.y = c() + e.endY, p && x.length > 0 && (x = x.filter((e) => !z.has(e)), S = M(x));
1788
- } else q(n), F += b, d.y += b;
1789
- if (p && x.length > 0) {
1790
- let e = P.length - 1;
1791
- m[e] = (m[e] ?? 0) + S;
1792
- for (let e of x) z.add(e);
1793
- }
1794
- I = r, L = r.spaceAfter;
1795
- } else if (n.type === "table") {
1796
- let e = n;
1797
- if (e.tblpPr) {
1798
- let r = e.tblpPr, i = N(() => {
1799
- let t = E() * d.scale, n = Tr(e, t, d), i = n.rowHeights.reduce((e, t) => e + t, 0);
1800
- return {
1801
- box: Re(r, d, d.y, n.tableW, i),
1802
- layout: n,
1803
- contentWPt: t / d.scale
1804
- };
1805
- }), a = i.box.y + i.box.h - d.y, o = r.vertAnchor !== "page" && r.vertAnchor !== "margin", s = o && a > 0 && F + a > B();
1806
- if (o && s) {
1807
- let n = Vn(e, r, i.layout.colWidths, i.layout.rowHeights, i.box.y - d.y, i.contentWPt, () => F, () => k, () => B(), () => W(t), (t) => {
1808
- N(() => {
1809
- let n = t, r = t.tblpPr, i = (n.tableColWidthsPt ?? []).reduce((e, t) => e + t, 0) * d.scale, a = (n.tableRowHeightsPt ?? []).reduce((e, t) => e + t, 0) * d.scale, o = Re(r, d, d.y, i, a);
1810
- ze(o, r, d, Be(o, d), e.overlap !== "never");
1811
- }), q(t);
1812
- });
1813
- F = n, d.y = c() + n, I = null, L = 0;
1814
- continue;
1815
- }
1816
- N(() => {
1817
- let t = Be(i.box, d);
1818
- ze(i.box, r, d, t, e.overlap !== "never");
1819
- }), zn(n, i.layout.colWidths, i.layout.rowHeights, i.contentWPt), q(n);
1820
- continue;
1821
- }
1822
- let r = E(), { colWidthsPt: i, rowHeightsPt: a } = Pn(d, e, r), o = a.reduce((e, t) => e + t, 0), s = B();
1823
- if (o > s) {
1824
- let n = Bn(e, a, F, s, P, (e) => {
1825
- A = Math.max(A, e), W(t);
1826
- }, () => w, C, () => k, c(), () => D, () => O, {
1827
- colWidthsPt: i,
1828
- contentWPt: r
1829
- });
1830
- F = n, d.y = c() + n;
1831
- } else (te(o) || F + o > s) && W(t), zn(n, i, a, r), q(n), F += o, d.y += o;
1832
- I = null;
1833
- }
1834
- }
1835
- return P;
1836
- }
1837
- function gn(e, t, n) {
1838
- return t < 0 ? 0 : Math.max(0, n + e - t);
1839
- }
1840
- function _n(e, t, n) {
1841
- return t < 0 ? 0 : Math.max(0, n + e - t);
1842
- }
1843
- function Q(e) {
1844
- return Math.abs(e);
1845
- }
1846
- function vn(e) {
1847
- return {
1848
- pageWidth: e.pageWidth,
1849
- pageHeight: e.pageHeight,
1850
- marginTop: e.marginTop,
1851
- marginRight: e.marginRight,
1852
- marginBottom: e.marginBottom,
1853
- marginLeft: e.marginLeft,
1854
- headerDistance: e.headerDistance,
1855
- footerDistance: e.footerDistance
1856
- };
1857
- }
1858
- function yn(e, t, n) {
1859
- let r = Un(e, t, n);
1860
- return Hn(r.footers, r.isFirstPageOfSection, t % 2 == 1, r.titlePage, n.section.evenAndOddHeaders);
1861
- }
1862
- function bn(e, t, n) {
1863
- let r = Un(e, t, n);
1864
- return Hn(r.headers, r.isFirstPageOfSection, t % 2 == 1, r.titlePage, n.section.evenAndOddHeaders);
1865
- }
1866
- var xn = .5;
1867
- function Sn(e, t, n) {
1868
- return e.map((r, i) => {
1869
- let a = yn(e, i, t);
1870
- if (!a) return 0;
1871
- let o = Gn(a, n), s = e[i]?.[0]?.sectionGeom;
1872
- return gn(o, s?.marginBottom ?? t.section.marginBottom, s?.footerDistance ?? t.section.footerDistance);
1873
- });
1874
- }
1875
- function Cn(e, t, n) {
1876
- return e.map((r, i) => {
1877
- let a = bn(e, i, t);
1878
- if (!a) return 0;
1879
- let o = Gn(a, n), s = e[i]?.[0]?.sectionGeom;
1880
- return _n(o, s?.marginTop ?? t.section.marginTop, s?.headerDistance ?? t.section.headerDistance);
1881
- });
1882
- }
1883
- function wn(e, t, n, r, i) {
1884
- let a = At(e.settings), o = hn(e.body, e.section, t, n, r, i, [], a), s = En(t, e.section, n, r, An(e.body), a), c = Sn(o, e, s), l = Cn(o, e, s), u = (e) => e.some((e) => e > xn);
1885
- if (!u(c) && !u(l)) return o;
1886
- let d = o.map((e, t) => ({
1887
- top: l[t] ?? 0,
1888
- bottom: c[t] ?? 0
1889
- }));
1890
- return hn(e.body, e.section, t, n, r, i, d, a);
1891
- }
1892
- function Tn(e) {
1893
- let t = new OffscreenCanvas(1, 1).getContext("2d");
1894
- return t ? wn(e, t, e.fontFamilyClasses ?? {}, O(e.settings), e.footnotes ?? []) : [e.body];
1895
- }
1896
- function En(e, t, n = {}, r = b, i = !1, a = 36) {
1897
- return {
1898
- ctx: e,
1899
- scale: 1,
1900
- dpr: 1,
1901
- contentX: 0,
1902
- contentW: t.pageWidth - t.marginLeft - t.marginRight,
1903
- y: 0,
1904
- pageH: t.pageHeight,
1905
- defaultColor: "#000000",
1906
- pageIndex: 0,
1907
- totalPages: 1,
1908
- images: /* @__PURE__ */ new Map(),
1909
- dryRun: !0,
1910
- marginLeft: t.marginLeft,
1911
- marginRight: t.marginRight,
1912
- marginTop: Q(t.marginTop),
1913
- marginBottom: Q(t.marginBottom),
1914
- pageWidth: t.pageWidth,
1915
- floats: [],
1916
- floatParaSeq: 0,
1917
- docGrid: {
1918
- type: t.docGridType ?? null,
1919
- linePitchPt: t.docGridLinePitch ?? null,
1920
- charSpacePt: t.docGridCharSpace == null ? null : t.docGridCharSpace / 4096
1921
- },
1922
- docEastAsian: i,
1923
- fontFamilyClasses: n,
1924
- kinsoku: r,
1925
- defaultTabPt: a,
1926
- showTrackChanges: !1
1927
- };
1928
- }
1929
- function Dn(e, t, n, r = !1, i = 0) {
1930
- let a = t.indentLeft, o = t.indentRight, s = Math.max(1, n - a - o), c = i + (t.bidi === !0 ? o : a), l = Pt(t.runs, e), u = kn(t), d = jn(t, e), f = e.floats.length > 0, p = e.y, m = p + (r ? 0 : t.spaceBefore);
1931
- f && (m = Ee(m, e.floats));
1932
- let h = () => {
1933
- if (f) {
1934
- let t = we(m, be(1), 10, c, s, e.floats);
1935
- t.topY > m && (m = t.topY);
1936
- }
1937
- m += _t(t, 1, d, u, e.docEastAsian, e.ctx, e.fontFamilyClasses);
1938
- };
1939
- if (l.length === 0) h();
1940
- else {
1941
- let n = f ? {
1942
- startPageY: m,
1943
- paraX: c,
1944
- floats: e.floats,
1945
- lineBoxH: (e, n, r, i) => Z(t.lineSpacing, e, n, 1, d, u, i ?? 0, $(t)),
1946
- pageH: e.pageH
1947
- } : void 0, r = Ft(e.ctx, l, s, t.indentFirst, 1, t.tabStops, n, e.fontFamilyClasses, a, e.kinsoku, ut(d, 1), e.defaultTabPt);
1948
- if (r.length === 0) h();
1949
- else if (u) {
1950
- let e = On(Math.max(0, ...r.map((e) => Z(t.lineSpacing, e.ascent, e.descent, 1, d, !0, e.intendedSingle, $(t)))), d, 1);
1951
- for (let t of r) t.topY !== void 0 && t.topY > m && (m = t.topY), m += e;
1952
- } else for (let e of r) e.topY !== void 0 && e.topY > m && (m = e.topY), m += Z(t.lineSpacing, e.ascent, e.descent, 1, d, !1, e.intendedSingle, $(t));
1953
- }
1954
- return m += t.spaceAfter, m - p;
1955
- }
1956
- function On(e, t, n) {
1957
- if (!t || !t.linePitchPt || t.linePitchPt <= 0 || t.type !== "lines" && t.type !== "linesAndChars") return e;
1958
- let r = t.linePitchPt * n;
1959
- return r <= 0 ? e : e <= r ? r : Math.ceil(e / r) * r;
1960
- }
1961
- function kn(e) {
1962
- for (let t of e.runs) if (t.type === "text" && t.ruby) return !0;
1963
- return !1;
1964
- }
1965
- function $(e) {
1966
- for (let t of e.runs) if (t.type === "text" && lt.test(t.text)) return !0;
1967
- return !1;
1968
- }
1969
- function An(e) {
1970
- for (let t of e) if (t.type === "paragraph") {
1971
- if ($(t)) return !0;
1972
- } else if (t.type === "table") {
1973
- for (let e of t.rows) for (let t of e.cells) if (An(t.content)) return !0;
1974
- }
1975
- return !1;
1976
- }
1977
- function jn(e, t) {
1978
- return e.snapToGrid === !1 ? {
1979
- type: null,
1980
- linePitchPt: null
1981
- } : t.docGrid;
1982
- }
1983
- function Mn(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m) {
1984
- let h = d ?? (() => 0), g = f ?? (() => o), _ = (t) => (l && (t.colIndex = l()), u && (t.colGeom = u), d && (t.colTopPt = (m ? Q(m().marginTop) : e.marginTop) + h()), p && (t.sectionHF = p()), m && (t.sectionGeom = m()), t), v = t.indentLeft, y = t.indentRight, b = Math.max(1, n - v - y), x = i + (t.bidi === !0 ? y : v), S = () => {
1985
- let o = Dn(e, t, n, r, i), l = a;
1986
- return a > 0 && a + o - t.spaceAfter > g() && (c(a), l = h(), o = Dn(e, t, n, r, i)), s[s.length - 1].push(_(t)), { endY: l + o };
1987
- }, C = Pt(t.runs, e);
1988
- if (C.length === 0) return S();
1989
- let w = e.floats.length > 0 ? {
1990
- startPageY: e.y,
1991
- paraX: x,
1992
- floats: e.floats,
1993
- lineBoxH: (n, r, i, a) => Z(t.lineSpacing, n, r, 1, e.docGrid, kn(t), a ?? 0, $(t)),
1994
- pageH: e.pageH
1995
- } : void 0, T = Ft(e.ctx, C, b, t.indentFirst, 1, t.tabStops, w, e.fontFamilyClasses, v, e.kinsoku, ut(jn(t, e), 1), e.defaultTabPt);
1996
- if (T.length === 0) return S();
1997
- let E = kn(t), D = !Nt(t), O = (n) => Z(t.lineSpacing, n.ascent, n.descent, 1, e.docGrid, E, n.intendedSingle, $(t)), k = E ? On(Math.max(0, ...T.map(O)), e.docGrid, 1) : 0, A = T.map((e) => E ? k : O(e)), j = r ? 0 : t.spaceBefore, M = t.spaceAfter, N = 0, P = a, F = !0;
1998
- for (; N < T.length;) {
1999
- let n = g() - P, r = F ? j : 0, i = N, a = N;
2000
- for (; a < T.length && r + A[a] <= n;) r += A[a], a++;
2001
- if (a === i) {
2002
- if (P > 0) {
2003
- c(P), P = h(), F = !0;
2004
- continue;
2005
- }
2006
- a = i + 1, r += A[i];
2007
- }
2008
- if (t.widowControl !== !1 && a < T.length && (T.length - a === 1 && a - i >= 2 && (a--, r -= A[a]), i === 0 && a - i === 1 && P > 0)) {
2009
- c(P), P = h(), F = !0;
2010
- continue;
2011
- }
2012
- let o = a === T.length;
2013
- o && (r += M);
2014
- let l = {
2015
- ...t,
2016
- type: "paragraph",
2017
- lineSlice: {
2018
- start: i,
2019
- end: a
2020
- }
2021
- };
2022
- D && sr(l, T, {
2023
- paraW: b,
2024
- firstIndent: t.indentFirst,
2025
- tabOriginPx: v,
2026
- gridDeltaPx: ut(jn(t, e), 1),
2027
- hasFloats: w !== void 0,
2028
- kinsoku: e.kinsoku
2029
- }), s[s.length - 1].push(_(l)), N = a, P += r, o || (c(P), P = h(), F = !0);
2030
- }
2031
- return { endY: P };
2032
- }
2033
- function Nn(e, t, n) {
2034
- return Pn(e, t, n).rowHeightsPt;
2035
- }
2036
- function Pn(e, t, n) {
2037
- let r = Ln(t, n, e);
2038
- return {
2039
- colWidthsPt: r,
2040
- rowHeightsPt: qe(t, r, 1, (n, r) => Er(n, t, r, 1, e))
2041
- };
2042
- }
2043
- function Fn(e, t, n) {
2044
- return Nn(e, t, n).reduce((e, t) => e + t, 0);
2045
- }
2046
- function In(e, t, n) {
2047
- let { ctx: r, fontFamilyClasses: i } = n, a = 0, o = (e) => {
2048
- for (let t of e.runs) {
2049
- if (t.type !== "text") continue;
2050
- let e = t;
2051
- if (!e.text) continue;
2052
- let n = e.rtl === !0 || e.cs === !0;
2053
- r.font = X(n ? e.boldCs ?? e.bold : e.bold, n ? e.italicCs ?? e.italic : e.italic, n ? e.fontSizeCs ?? e.fontSize : e.fontSize, n ? e.fontFamilyCs ?? e.fontFamily : e.fontFamily, i);
2054
- for (let t of e.text.split(" ")) for (let e of Ot(t)) {
2055
- let t = e.replace(/\s+$/u, "");
2056
- if (!t) continue;
2057
- let n = xt(t) ? Math.max(...[...t].map((e) => r.measureText(e).width)) : r.measureText(t).width;
2058
- n > a && (a = n);
2059
- }
2060
- }
2061
- };
2062
- for (let t of e.content) t.type === "paragraph" && o(t);
2063
- if (a === 0) return 0;
2064
- let s = jr(e, t);
2065
- return a + s.left + s.right;
2066
- }
2067
- function Ln(e, t, n) {
2068
- let r = e.colWidths.length;
2069
- if (r === 0) return [];
2070
- let i = e.colWidths, a = Array(r).fill(0);
2071
- for (let t of e.rows) {
2072
- let o = 0;
2073
- for (let s of t.cells) {
2074
- let t = Math.min(Math.max(s.colSpan, 1), r - o), c = In(s, e, n);
2075
- if (c > 0) if (t === 1) c > a[o] && (a[o] = c);
2076
- else {
2077
- let e = i.slice(o, o + t), n = e.reduce((e, t) => e + t, 0);
2078
- for (let r = 0; r < t; r++) {
2079
- let i = c * (n > 0 ? e[r] / n : 1 / t);
2080
- i > a[o + r] && (a[o + r] = i);
2081
- }
2082
- }
2083
- o += t;
2084
- }
2085
- }
2086
- let o = (e) => {
2087
- let n = e.reduce((e, t) => e + t, 0);
2088
- if (n <= t || n <= 0) return e;
2089
- let i = a.reduce((e, t) => e + t, 0);
2090
- if (i >= t) {
2091
- let n = t / i;
2092
- return i > 0 ? a.map((e) => e * n) : e.map(() => t / r);
2093
- }
2094
- let o = e.slice(), s = Array(r).fill(!1);
2095
- for (let n = 0; n < r; n++) {
2096
- let n = t, i = 0;
2097
- for (let t = 0; t < r; t++) s[t] ? n -= o[t] : i += e[t];
2098
- if (i <= 0) break;
2099
- let c = !1;
2100
- for (let t = 0; t < r; t++) {
2101
- if (s[t]) continue;
2102
- let r = n * (e[t] / i);
2103
- r < a[t] ? (o[t] = a[t], s[t] = !0, c = !0) : o[t] = r;
2104
- }
2105
- if (!c) break;
2106
- }
2107
- return o;
2108
- };
2109
- if (e.layout === "fixed") {
2110
- let e = i.slice(), n = e.reduce((e, t) => e + t, 0);
2111
- if (n > t && n > 0) {
2112
- let r = t / n;
2113
- return e.map((e) => e * r);
2114
- }
2115
- return e;
2116
- }
2117
- let s = e.widthPt != null || e.widthPct != null;
2118
- if (i.reduce((e, t) => e + t, 0) > 0 && s) return o(i.map((e, t) => Math.max(e, a[t])));
2119
- let c = Array(r).fill(0), l = Array(r).fill(!1), u = (e) => e.widthPt == null ? e.widthPct == null ? null : e.widthPct / 5e3 * t : e.widthPt;
2120
- for (let t of e.rows) {
2121
- let e = 0;
2122
- for (let n of t.cells) {
2123
- let t = Math.min(Math.max(n.colSpan, 1), r - e);
2124
- if (t === 1) {
2125
- let t = u(n);
2126
- t != null && (t > c[e] && (c[e] = t), l[e] = !0);
2127
- }
2128
- e += t;
2129
- }
2130
- }
2131
- for (let t of e.rows) {
2132
- let e = 0;
2133
- for (let n of t.cells) {
2134
- let t = Math.min(Math.max(n.colSpan, 1), r - e);
2135
- if (t > 1) {
2136
- let r = u(n);
2137
- if (r != null) {
2138
- let n = i.slice(e, e + t), a = n.reduce((e, t) => e + t, 0), o = n.reduce((t, n, r) => t + (l[e + r] ? c[e + r] : n), 0);
2139
- if (r > o) {
2140
- let s = r - o;
2141
- for (let r = 0; r < t; r++) {
2142
- let o = a > 0 ? n[r] / a : 1 / t, u = l[e + r] ? c[e + r] : i[e + r];
2143
- c[e + r] = u + s * o, l[e + r] = !0;
2144
- }
2145
- }
2146
- }
2147
- }
2148
- e += t;
2149
- }
2150
- }
2151
- return o(c.map((e, t) => Math.max(l[t] ? e : i[t], a[t])));
2152
- }
2153
- function Rn(e, t) {
2154
- return t <= 0 ? !0 : !e.rows[t].cells.some((e) => e.vMerge === !1);
2155
- }
2156
- function zn(e, t, n, r) {
2157
- e.tableColWidthsPt = t, e.tableRowHeightsPt = n, e.tableLayoutInputs = {
2158
- scale: 1,
2159
- contentWPt: r
2160
- };
2161
- }
2162
- function Bn(e, t, n, r, i, a, o, s, c, l, u, d, f) {
2163
- let p = c ?? (() => 0), m = e.rows.length, h = 0;
2164
- for (; h < m && e.rows[h].isHeader;) h++;
2165
- let g = e.rows.slice(0, h), _ = t.slice(0, h).reduce((e, t) => e + t, 0), v = t.slice(0, h), y = n, b = 0, x = !0;
2166
- for (; b < m;) {
2167
- let n = !x && h > 0 && b >= h, S = r - y, C = n ? _ : 0, w = b;
2168
- for (; w < m;) {
2169
- let n = t[w];
2170
- if (w > b && C + n > S && Rn(e, w)) break;
2171
- C += n, w++;
2172
- }
2173
- let T = e.rows.slice(b, w), E = n ? [...g, ...T] : T, D = {
2174
- ...e,
2175
- type: "table",
2176
- rows: E
2177
- };
2178
- if (o && (D.colIndex = o()), s && (D.colGeom = s), c && l != null && (D.colTopPt = l + p()), u && (D.sectionHF = u()), d && (D.sectionGeom = d()), f) {
2179
- let e = n ? [...v, ...t.slice(b, w)] : t.slice(b, w);
2180
- zn(D, f.colWidthsPt, e, f.contentWPt);
2181
- }
2182
- i[i.length - 1].push(D), y += C, b = w, x = !1, b < m && (a(y), y = p());
2183
- }
2184
- return y;
2185
- }
2186
- function Vn(e, t, n, r, i, a, o, s, c, l, u) {
2187
- let d = r.length, f = 0, p = !0;
2188
- for (; f < d;) {
2189
- let m = p ? o() + i : s(), h = c() - m;
2190
- if (r[f] > h && m > s()) {
2191
- l(), p = !1;
2192
- continue;
2193
- }
2194
- let g = 0, _ = f;
2195
- for (; _ < d;) {
2196
- let t = r[_];
2197
- if (_ > f && g + t > h && Rn(e, _)) break;
2198
- g += t, _++;
2199
- }
2200
- let v = p ? t : {
2201
- ...t,
2202
- tblpY: 0
2203
- }, y = {
2204
- ...e,
2205
- type: "table",
2206
- rows: e.rows.slice(f, _),
2207
- tblpPr: v
2208
- };
2209
- zn(y, n, r.slice(f, _), a), u?.(y), f = _, p = !1, f < d && l();
2210
- }
2211
- return s();
2212
- }
2213
- function Hn(e, t, n, r, i) {
2214
- return r && t && e.first ? e.first : i && n && e.even ? e.even : e.default ?? null;
2215
- }
2216
- function Un(e, t, n) {
2217
- let r = (t) => e[t]?.[0]?.sectionHF, i = r(t);
2218
- return {
2219
- headers: i?.headers ?? n.headers,
2220
- footers: i?.footers ?? n.footers,
2221
- titlePage: i?.titlePage ?? n.section.titlePage,
2222
- isFirstPageOfSection: t === 0 || r(t - 1) !== i,
2223
- geom: e[t]?.[0]?.sectionGeom ?? vn(n.section)
2224
- };
2225
- }
2226
- function Wn(e, t, n) {
2227
- let r = {
2228
- ...n,
2229
- y: t
2230
- };
2231
- Zn(e.body, r);
2232
- }
2233
- function Gn(e, t) {
2234
- let n = {
2235
- ...t,
2236
- y: 0,
2237
- dryRun: !0,
2238
- floats: []
2239
- };
2240
- return Zn(e.body, n), n.y;
2241
- }
2242
- function Kn(e, t) {
2243
- return !!(e?.contextualSpacing && t.contextualSpacing && e.styleId && e.styleId === t.styleId);
2244
- }
2245
- function qn(e) {
2246
- return !(e.runs ?? []).some((e) => {
2247
- let t = e;
2248
- return t.type === "text" ? (t.text ?? "").length > 0 : !0;
2249
- });
2250
- }
2251
- function Jn(e, t) {
2252
- let n = e[t];
2253
- return !n || n.type !== "paragraph" || e[t + 1]?.type !== "sectionBreak" ? !1 : qn(n);
2254
- }
2255
- function Yn(e, t, n) {
2256
- let r = 0, i = null, a = 0;
2257
- for (let o of e) if (o.type === "paragraph") {
2258
- let e = o, s = Kn(i, e), c = s ? 0 : e.spaceBefore, l = s ? a : Math.min(a, c);
2259
- r += t(o) - (s ? e.spaceBefore : 0) * n - l * n, i = e, a = e.spaceAfter;
2260
- } else r += t(o), i = null, a = 0;
2261
- return r;
2262
- }
2263
- function Xn(e, t, n, r) {
2264
- let i = Q(n.marginTop) * r, a = (n.pageHeight - Q(n.marginBottom)) * r;
2265
- e.save(), e.strokeStyle = "#000000", e.lineWidth = Math.max(1, Math.round(.5 * r));
2266
- for (let n = 0; n < t.length - 1; n++) {
2267
- let o = t[n].xPt + t[n].wPt, s = t[n + 1].xPt, c = Math.round((o + s) / 2 * r) + .5;
2268
- e.beginPath(), e.moveTo(c, i), e.lineTo(c, a), e.stroke();
2269
- }
2270
- e.restore();
2271
- }
2272
- function Zn(e, t, n, r = 0) {
2273
- let i = null, a = 0;
2274
- t.pageAnchorPrescanned = /* @__PURE__ */ new Set(), Sr(e, 0, t);
2275
- let o = t.deferFront;
2276
- t.deferFront = [];
2277
- let s = -1, c, l = (e, t) => (e.colGeom ?? n) === (t.colGeom ?? n) && (e.colIndex ?? 0) === (t.colIndex ?? 0), u = (e, t) => {
2278
- if (!t || t.type !== "paragraph" || !l(e, t)) return null;
2279
- let n = t;
2280
- return n.framePr ? null : n;
2281
- }, d = (t) => u(e[t], e[t - 1]), f = (t) => u(e[t], e[t + 1]);
2282
- for (let o = 0; o < e.length; o++) {
2283
- let l = e[o], u = l.colGeom ?? n, p = !!u && u.length > 1, m = l.colIndex ?? 0;
2284
- if (p && (u !== c || m !== s)) {
2285
- let e = u[Math.min(m, u.length - 1)];
2286
- t.contentX = e.xPt * t.scale, t.contentW = e.wPt * t.scale, m > s && u === c && (t.y = (l.colTopPt ?? t.marginTop) * t.scale + r), i = null, a = 0, s = m, c = u;
2287
- } else if (!p && u && u.length === 1 && u !== c) {
2288
- c && c.length > 1 && l.colTopPt != null && (t.y = Math.max(t.y, l.colTopPt * t.scale + r));
2289
- let e = u[0];
2290
- t.contentX = e.xPt * t.scale, t.contentW = e.wPt * t.scale, i = null, a = 0, s = m, c = u;
2291
- }
2292
- if (l.type === "paragraph") {
2293
- let n = l, r = l.lineSlice;
2294
- if (n.framePr) {
2295
- rr(n, t, tr(e, l, t));
2296
- continue;
2297
- }
2298
- if (l.collapsedSpacer) continue;
2299
- let s = Kn(i, n), c = !!l.sectionBreakSpacer, u = s || c, p = !!l.leadsCollapsedRun, m = u ? 0 : n.spaceBefore;
2300
- t.y -= (s || p ? a : Math.min(a, m)) * t.scale;
2301
- let h = !!r && r.start > 0, g = qr(n.borders) ? {
2302
- suppressTop: Jr(d(o), n),
2303
- suppressBottom: Jr(n, f(o))
2304
- } : void 0;
2305
- ar(n, t, u || h, r, !1, g), i = n, a = n.spaceAfter;
2306
- } else if (l.type === "table") {
2307
- let e = l;
2308
- kr(e, t), e.tblpPr || (i = null, a = 0);
2309
- }
2310
- }
2311
- let p = t.deferFront ?? [];
2312
- t.deferFront = o;
2313
- for (let e of p) e();
2314
- }
2315
- function Qn(e, t) {
2316
- let n = null, r = 0;
2317
- for (let i = 0; i < e.length; i++) {
2318
- let a = e[i], o = Kn(n, a), s = o ? 0 : a.spaceBefore;
2319
- t.y -= Math.min(r, s) * t.scale;
2320
- let c = e[i - 1] ?? null, l = e[i + 1] ?? null;
2321
- ar(a, t, o, void 0, !1, qr(a.borders) ? {
2322
- suppressTop: Jr(c, a),
2323
- suppressBottom: Jr(a, l)
2324
- } : void 0), n = a, r = a.spaceAfter;
2325
- }
2326
- }
2327
- function $n(e) {
2328
- switch (e) {
2329
- case "left": return "left";
2330
- case "right": return "right";
2331
- default: return "center";
2332
- }
2333
- }
2334
- function er(e, t, n) {
2335
- let { ctx: r, scale: i, dryRun: a } = t, { grid: o, paraHasRuby: s, contentX: c, indLeft: l, paraW: u, textAreaTopY: d, paragraphStartY: f, markTop: p, totalLines: m, lineSlice: h, borderMerge: g } = n, _ = Math.max(0, p - d);
2336
- p > t.y && (t.y = p);
2337
- let v = t.y, y = _t(e, i, o, s, t.docEastAsian, r, t.fontFamilyClasses);
2338
- if (e.shading && !a) {
2339
- r.fillStyle = `#${e.shading}`;
2340
- let t = Ur(c + l, v, u, y, e.borders, g, i);
2341
- r.fillRect(t.x, t.y, t.w, t.h);
2342
- }
2343
- t.y += y, e.borders && !a && Wr(r, c + l, v, u, y, e.borders, i, t.dpr, g), (!h || h.end >= m) && (t.y += e.spaceAfter * i), (!h || h.start === 0) && fr(e, t, f + _);
2344
- }
2345
- function tr(e, t, n) {
2346
- let r = e.indexOf(t);
2347
- for (let t = r + 1; t < e.length; t++) {
2348
- let r = e[t];
2349
- if (r.type !== "paragraph") continue;
2350
- let i = r;
2351
- if (!i.framePr) return _t(i, n.scale, jn(i, n), kn(i), n.docEastAsian, n.ctx, n.fontFamilyClasses);
2352
- }
2353
- let i = t;
2354
- return _t(i, n.scale, jn(i, n), kn(i), n.docEastAsian, n.ctx, n.fontFamilyClasses);
2355
- }
2356
- function nr(e, t, n) {
2357
- let r = e.framePr, { scale: i } = t, a = t.y, o = jn(e, t), s = kn(e), c = Pt(e.runs, t), l = c.length === 0 ? [] : Ft(t.ctx, c, 1e5, 0, i, e.tabStops, void 0, t.fontFamilyClasses, 0, t.kinsoku, ut(o, i), t.defaultTabPt);
2358
- return Fe(r, t, a, l.length === 0 ? 0 : Math.max(...l.map((e) => e.segments.reduce((e, t) => e + t.measuredWidth, 0))), l.reduce((t, n) => t + Z(e.lineSpacing, n.ascent, n.descent, i, o, s, n.intendedSingle, $(e)), 0), n);
2359
- }
2360
- function rr(e, t, n) {
2361
- let r = e.framePr, i = t.y, a = nr(e, t, n), o = t.contentX, s = t.contentW;
2362
- t.contentX = a.x, t.contentW = Math.max(a.w, a.exRight - a.x), t.y = a.y, ar(e, t, !0, void 0, !0), t.contentX = o, t.contentW = s, t.y = i, Le(a, r, t);
2363
- }
2364
- function ir(e, t, n, r) {
2365
- let { ctx: i, scale: a, fontFamilyClasses: o } = t, s = "", c = 0, l = null, u = 0, d = 0;
2366
- if (e.numbering) {
2367
- s = e.numbering.text, c = e.numbering.tab * a;
2368
- let f = e.numbering.suff || "tab", p = e.numbering.picBulletImagePath;
2369
- if (p) {
2370
- let n = t.images.get(Wt(p));
2371
- if (n) {
2372
- let t = Qr(e.numbering, e);
2373
- l = {
2374
- bmp: n,
2375
- w: t.w * a,
2376
- h: t.h * a
2377
- };
2378
- }
2379
- }
2380
- let m;
2381
- l ? m = l.w : (i.font = X(!1, !1, ot(e) * a, Xr(e.numbering), o), m = i.measureText(Zr(e.numbering)).width);
2382
- let h = e.numbering.jc || "left";
2383
- d = h === "right" ? -m : h === "center" ? -m / 2 : 0;
2384
- let g = r + d + m;
2385
- if (f !== "tab") u = g + (f === "space" ? i.measureText(" ").width : 0);
2386
- else if (g > 0) {
2387
- let r = jt(n + g, (e.tabStops ?? []).map((e) => ({
2388
- pos: e.pos * a,
2389
- alignment: e.alignment,
2390
- leader: e.leader
2391
- })), t.defaultTabPt * a);
2392
- r && (u = r.pos - n);
2393
- }
2394
- }
2395
- return {
2396
- numTab: c,
2397
- picBullet: l,
2398
- numBodyOffset: u,
2399
- markerJcShiftPx: d,
2400
- hasMarker: s !== "" || l !== null
2401
- };
2402
- }
2403
- function ar(e, t, n = !1, r, i = !1, a) {
2404
- let { ctx: o, scale: s, contentX: c, contentW: l, defaultColor: u, dryRun: d, fontFamilyClasses: f } = t, p = t.y;
2405
- n || (t.y += e.spaceBefore * s), i || xr(e, t, p), fr(e, t, p, "behind"), t.y = Ee(t.y, t.floats);
2406
- let m = t.y, h = e.bidi === !0, g = i ? 0 : (h ? e.indentRight : e.indentLeft) * s, _ = i ? 0 : (h ? e.indentLeft : e.indentRight) * s, v = i ? 0 : e.indentFirst * s, { numTab: y, picBullet: b, numBodyOffset: x, markerJcShiftPx: S, hasMarker: C } = ir(e, t, g, v), w = c + g, T = w + v, E = l - g - _, D = Pt(e.runs, t), O = kn(e), k = jn(e, t), A = () => {
2407
- if (t.floats.length === 0) return m;
2408
- let e = 10 * s;
2409
- return we(m, be(s), e, w, E, t.floats).topY;
2410
- };
2411
- if (D.length === 0) {
2412
- er(e, t, {
2413
- grid: k,
2414
- paraHasRuby: O,
2415
- contentX: c,
2416
- indLeft: g,
2417
- paraW: E,
2418
- textAreaTopY: m,
2419
- paragraphStartY: p,
2420
- markTop: A(),
2421
- totalLines: 0,
2422
- lineSlice: void 0,
2423
- borderMerge: a
2424
- });
2425
- return;
2426
- }
2427
- let j = t.floats.length > 0 ? {
2428
- startPageY: t.y,
2429
- paraX: w,
2430
- floats: t.floats,
2431
- lineBoxH: (t, n, r, i) => Z(e.lineSpacing, t, n, s, k, O, i ?? 0, $(e)),
2432
- pageH: t.pageH
2433
- } : void 0, M = C && !h ? x : T - w, N = ut(k, s), P = e, F = l / s - (i ? 0 : h ? e.indentRight : e.indentLeft) - (i ? 0 : h ? e.indentLeft : e.indentRight), I = i ? 0 : h ? e.indentRight : e.indentLeft, L = C && !h ? x / s : e.indentFirst, R = ut(k, 1), z = cr && P.layoutLines !== void 0 && P.layoutLinesInputs !== void 0 && P.layoutLinesInputs.scale === 1 && !j && !P.layoutLinesInputs.hasFloats && Math.abs(P.layoutLinesInputs.paraW - F) <= 1e-6 * Math.max(1, Math.abs(F)) && P.layoutLinesInputs.firstIndent === L && P.layoutLinesInputs.tabOriginPx === I && P.layoutLinesInputs.gridDeltaPx === R && Mt(P.layoutLinesInputs.kinsoku, t.kinsoku) ? It(P.layoutLines, s, o, t.fontFamilyClasses, N) : j ? Ft(o, D, E, M, s, e.tabStops, j, t.fontFamilyClasses, g, t.kinsoku, N, t.defaultTabPt) : It(Ft(o, D, F, L, 1, e.tabStops, void 0, t.fontFamilyClasses, I, t.kinsoku, R, t.defaultTabPt), s, o, t.fontFamilyClasses, N), ee = (() => {
2434
- if (D.some((e) => "isTab" in e)) return null;
2435
- let t = e.tabStops ?? [];
2436
- if (t.length === 0) return null;
2437
- let n = t.reduce((e, t) => t.pos < e.pos ? t : e);
2438
- if (n.alignment !== "decimal") return null;
2439
- let r = e.runs.map((e) => e.text ?? "").join("").trim();
2440
- return r === "" || !/^[+\-(]?[\d., ]+\)?%?$/.test(r) ? null : n.pos * s - g;
2441
- })();
2442
- if (z.length === 0) {
2443
- er(e, t, {
2444
- grid: k,
2445
- paraHasRuby: O,
2446
- contentX: c,
2447
- indLeft: g,
2448
- paraW: E,
2449
- textAreaTopY: m,
2450
- paragraphStartY: p,
2451
- markTop: A(),
2452
- totalLines: z.length,
2453
- lineSlice: r,
2454
- borderMerge: a
2455
- });
2456
- return;
2457
- }
2458
- let B = O ? On(Math.max(0, ...z.map((t) => Z(e.lineSpacing, t.ascent, t.descent, s, k, !0, t.intendedSingle, $(e)))), k, s) : 0, V = (t) => O ? B : Z(e.lineSpacing, t.ascent, t.descent, s, k, !1, t.intendedSingle, $(e)), H = r ? r.start : 0, U = r ? r.end : z.length, W = Math.min(U, z.length);
2459
- if (e.shading && !d) {
2460
- let t = Hr(z, H, W, m, V);
2461
- o.fillStyle = `#${e.shading}`;
2462
- let n = Ur(c + g, m, E, t, e.borders, a, s);
2463
- o.fillRect(n.x, n.y, n.w, n.h);
2464
- }
2465
- let G = e.alignment === "justify" || e.alignment === "both" || e.alignment === "distribute", K = e.alignment === "distribute", te = h || he(D), ne = {
2466
- ctx: o,
2467
- scale: s,
2468
- state: t,
2469
- para: e,
2470
- dryRun: d,
2471
- defaultColor: u,
2472
- fontFamilyClasses: f,
2473
- contentX: c,
2474
- contentW: l,
2475
- lines: z,
2476
- grid: k,
2477
- paraX: w,
2478
- firstLineX: T,
2479
- paraW: E,
2480
- indLeft: g,
2481
- indFirst: v,
2482
- baseRtl: h,
2483
- hasMarker: C,
2484
- numTab: y,
2485
- numBodyOffset: x,
2486
- markerJcShiftPx: S,
2487
- picBullet: b,
2488
- isJustified: G,
2489
- stretchLastLine: K,
2490
- alignEdge: ve(e.alignment, h),
2491
- paraNeedsBidi: te,
2492
- decimalAutoTabPx: ee,
2493
- drawGridDeltaPx: ut(k, s),
2494
- lineHForLine: V
2495
- };
2496
- for (let e = H; e < W; e++) or(e, ne);
2497
- if (e.borders && !d) {
2498
- let n = t.y - m;
2499
- Wr(o, c + g, m, E, n, e.borders, s, t.dpr, a);
2500
- }
2501
- (!r || r.end >= z.length) && (t.y += e.spaceAfter * s), (!r || r.start === 0) && fr(e, t, p);
2502
- }
2503
- function or(e, t) {
2504
- let { ctx: n, scale: r, state: i, para: a, dryRun: o, defaultColor: s, fontFamilyClasses: c, contentX: l, contentW: u, lines: d, grid: f, paraX: p, firstLineX: m, paraW: h, indLeft: g, indFirst: _, baseRtl: v, hasMarker: y, numTab: b, numBodyOffset: x, markerJcShiftPx: S, picBullet: C, isJustified: w, stretchLastLine: T, alignEdge: D, paraNeedsBidi: O, decimalAutoTabPx: A, drawGridDeltaPx: j, lineHForLine: M } = t, N = d[e], P = e === 0, F = e === d.length - 1;
2505
- N.topY !== void 0 && N.topY > i.y && (i.y = N.topY);
2506
- let I = M(N), L = N.ascent + N.descent, R = i.y + (I - L) / 2 + N.ascent, z = p + N.xOffset, ee = N.availWidth, B = P && !v ? y ? z + x : z + _ : z, V = v && P ? ee - _ : ee, H = O ? _e(N.segments, v) : null;
2507
- O && (n.textAlign = "left");
2508
- let U = N.segments.length, W = H ? H.order[U - 1] : U - 1, G = N.segments.reduce((e, t) => e + t.measuredWidth, 0), K = V - (B - z) - G, ne = F || (N.endsWithBreak ?? !1), re = w && (!ne || T), q = null, J = 0, ie = 0;
2509
- if (!O) for (let e = 0; e < U; e++) {
2510
- let t = N.segments[e];
2511
- if (!("text" in t) || /\S/.test(t.text)) {
2512
- ie = e;
2513
- break;
2514
- }
2515
- }
2516
- let ae = 0;
2517
- if (!re && K < 0) {
2518
- let e = ke(N.segments.map((e) => "text" in e ? { text: e.text } : {}), K, ie, O ? W : U, N.ascent);
2519
- e && (q = e.perSeg, J = e.perGap, ae = Oe(e));
2520
- }
2521
- let oe = K - ae, se = 0, ce = N.segments.length === 1 && "mathNodes" in N.segments[0] && N.segments[0].display ? N.segments[0] : null, le = (ce ? $n(ce.jc ?? i.mathDefJc ?? "centerGroup") : null) ?? D;
2522
- if (le === "right" ? se = oe : le === "center" ? se = oe / 2 : le === "justify" && v && !re && (se = oe), A != null && G > 0 && (se = Math.max(0, p + A - G - B)), B += se, P && y && !o) if (C) {
2523
- let { bmp: e, w: t, h: r } = C, i = R - r, a = v ? B + G + b - t : z + _ + S;
2524
- n.drawImage(e, a, i, t, r);
2525
- } else if (n.font = X(!1, !1, ot(a) * r, Xr(a.numbering), c), n.fillStyle = s, v) {
2526
- let e = n.textAlign, t = n.direction;
2527
- n.textAlign = "left", n.direction = "rtl";
2528
- let r = Zr(a.numbering), i = n.measureText(r).width;
2529
- n.fillText(r, B + G + b - i, R), n.textAlign = e, n.direction = t;
2530
- } else n.fillText(Zr(a.numbering), z + _ + S, R);
2531
- if (re) {
2532
- let e = V - (B - z) - G, t = -N.ascent * .25, n = De(N.segments.map((e) => "text" in e ? { text: e.text } : {}), e, ie, O ? W : U, t, e > 0);
2533
- q = n ? n.perSeg : null, J = n ? n.perGap : 0;
2534
- }
2535
- let Y = null, ue = () => {
2536
- if (!Y) return;
2537
- let e = Y;
2538
- Y = null;
2539
- let t = Math.max(1, e.border.width * r), i = (e.border.space ?? 0) * r;
2540
- n.strokeStyle = e.border.color ? `#${e.border.color}` : s, n.lineWidth = t, n.strokeRect(e.left - i, e.top - i, e.right - e.left + 2 * i, e.bottom - e.top + 2 * i);
2541
- };
2542
- for (let e = 0; e < U; e++) {
2543
- let t = H ? H.order[e] : e, a = N.segments[t];
2544
- if (H && (n.direction = H.rtl[t] ? "rtl" : "ltr"), "text" in a || ue(), "isTab" in a) {
2545
- !o && a.leader && a.leader !== "none" && a.measuredWidth > 1 && ur(n, a.leader, B, R, a.measuredWidth, a.fontSize * r, s, a.bold, a.italic), B += a.measuredWidth;
2546
- continue;
2547
- }
2548
- if ("imagePath" in a) {
2549
- o || dr(n, a, B, R, r, i.images), B += a.measuredWidth;
2550
- continue;
2551
- }
2552
- if ("mathNodes" in a) {
2553
- let e = Je.get(a.mathNodes);
2554
- if (!o && e) {
2555
- let t = a.fontSize * r, i = e.widthEm * t, o = (e.ascentEm + e.descentEm) * t, s = R - e.ascentEm * t;
2556
- n.drawImage(e.img, B, s, i, o);
2557
- }
2558
- B += a.measuredWidth;
2559
- continue;
2560
- }
2561
- let l = a, u = q?.get(t), d = u?.internalStretch ?? 0;
2562
- if (!o) {
2563
- let e = at(l, r), t = l.vertAlign === "super" ? -l.fontSize * r * .35 : l.vertAlign === "sub" ? l.fontSize * r * .15 : 0;
2564
- n.font = X(l.bold, l.italic, e, l.fontFamily, c);
2565
- let a = l.measuredWidth + d, o = a + (u?.trailingGap && !O && /\s$/.test(l.text) ? J : 0), f = R + t - e * .85, p = e * 1.1;
2566
- l.highlight && (n.fillStyle = zt[l.highlight] ?? "#FFFF00", n.fillRect(B, f, o, p)), l.background && (n.fillStyle = `#${l.background}`, n.fillRect(B, f, o, p));
2567
- let m = l.border && l.border.style !== "none" && l.border.style !== "nil" ? l.border : null;
2568
- if (m) {
2569
- let e = f, t = e + p;
2570
- Y && Yr(Y.border, m) ? (Y.right = B + o, Y.top = Math.min(Y.top, e), Y.bottom = Math.max(Y.bottom, t)) : (ue(), Y = {
2571
- border: m,
2572
- left: B,
2573
- right: B + o,
2574
- top: e,
2575
- bottom: t
2576
- });
2577
- } else ue();
2578
- let h = i.showTrackChanges && !!l.revision, g = h ? Yt(l.revision.author) : null, _;
2579
- if (_ = g || (l.color ? `#${l.color}` : l.colorAuto ? E(l.background ?? null) : s), n.fillStyle = _, ft(l.text, j) !== 0) {
2580
- let e = te([...l.text], u?.splitBefore ?? [], J, (e) => n.measureText(e).width, j), r = n.letterSpacing;
2581
- n.letterSpacing = `${j}px`;
2582
- for (let { text: r, dx: i } of e) n.fillText(r, B + i, R + t);
2583
- n.letterSpacing = r;
2584
- } else if (u && u.splitBefore.length > 0) {
2585
- let e = [...l.text];
2586
- if (u.splitBefore.length === e.length - 1) {
2587
- let e = n.letterSpacing;
2588
- n.letterSpacing = `${J}px`, n.fillText(l.text, B, R + t), n.letterSpacing = e;
2589
- } else {
2590
- let r = (e) => n.measureText(e).width;
2591
- for (let { text: i, dx: a } of te(e, u.splitBefore, J, r)) n.fillText(i, B + a, R + t);
2592
- }
2593
- } else n.fillText(l.text, B, R + t);
2594
- if (l.ruby) {
2595
- let i = l.ruby.fontSizePt * r, o = X(l.bold, l.italic, i, l.fontFamily, c);
2596
- n.save(), n.font = o;
2597
- let s = n.measureText(l.ruby.text).width, u = B + (a - s) / 2, d = R + t - e * .85 - i * .1;
2598
- n.fillStyle = _, n.fillText(l.ruby.text, u, d), n.restore();
2599
- }
2600
- i.onTextRun && l.text && i.onTextRun({
2601
- text: l.text,
2602
- x: B,
2603
- y: i.y,
2604
- w: a,
2605
- h: I,
2606
- fontSize: e,
2607
- font: n.font
2608
- });
2609
- let v = _, y = Math.max(.5, e * .05), b = h && l.revision?.kind === "insertion", x = h && l.revision?.kind === "deletion";
2610
- if (l.underline || b) {
2611
- n.strokeStyle = v, n.lineWidth = y;
2612
- let r = R + t + e * .12, a = r + k(r, y, i.dpr);
2613
- n.beginPath(), n.moveTo(B, a), n.lineTo(B + o, a), n.stroke();
2614
- }
2615
- if (l.strikethrough || x) {
2616
- n.strokeStyle = v, n.lineWidth = y;
2617
- let r = R + t - e * .3, a = r + k(r, y, i.dpr);
2618
- n.beginPath(), n.moveTo(B, a), n.lineTo(B + o, a), n.stroke();
2619
- }
2620
- if (l.doubleStrikethrough) {
2621
- n.strokeStyle = v, n.lineWidth = y;
2622
- let r = R + t - e * .35, a = R + t - e * .22, s = r + k(r, y, i.dpr), c = a + k(a, y, i.dpr);
2623
- n.beginPath(), n.moveTo(B, s), n.lineTo(B + o, s), n.stroke(), n.beginPath(), n.moveTo(B, c), n.lineTo(B + o, c), n.stroke();
2624
- }
2625
- }
2626
- B += l.measuredWidth + d, u?.trailingGap && (B += J);
2627
- }
2628
- ue(), O && (n.direction = "ltr"), i.y += I;
2629
- }
2630
- function sr(e, t, n) {
2631
- let r = e;
2632
- r.layoutLines = t, r.layoutLinesInputs = {
2633
- scale: 1,
2634
- ...n
2635
- };
2636
- }
2637
- var cr = !0, lr = !0;
2638
- function ur(e, t, n, r, i, a, o, s, c) {
2639
- let l = t === "hyphen" ? "-" : t === "underscore" || t === "heavy" ? "_" : t === "middleDot" ? "·" : ".";
2640
- e.save(), e.font = `${`${c ? "italic " : ""}${s ? "bold " : ""}`}${a}px serif`, e.fillStyle = o;
2641
- let u = e.measureText(l).width;
2642
- if (u > 0) {
2643
- let a = t === "dot" || t === "middleDot" ? u * 1.5 : u, o = u * .5, s = n + i - a - o;
2644
- for (let t = n + o; t <= s; t += a) e.fillText(l, t, r);
2645
- }
2646
- e.restore();
2647
- }
2648
- function dr(e, t, n, r, i, a) {
2649
- if (t.anchor) return;
2650
- let o = a.get(Wt(t.imagePath, t.colorReplaceFrom));
2651
- if (!o) return;
2652
- let s = t.widthPt * i, c = t.heightPt * i;
2653
- y(e, o, t.srcRect, n, r - c, s, c);
2654
- }
2655
- function fr(e, t, n, r = "front") {
2656
- if (!t.dryRun) {
2657
- if (r === "behind") {
2658
- let r = e.runs.filter((e) => e.type === "shape" && !!e.behindDoc).slice().sort((e, t) => (e.zOrder ?? 0) - (t.zOrder ?? 0));
2659
- for (let e of r) hr(e, t, n);
2660
- return;
2661
- }
2662
- if (t.deferFront) {
2663
- let r = t.contentX, i = t.contentW;
2664
- t.deferFront.push(() => {
2665
- let a = t.contentX, o = t.contentW, s = t.deferFront;
2666
- t.contentX = r, t.contentW = i, t.deferFront = null, fr(e, t, n, "front"), t.contentX = a, t.contentW = o, t.deferFront = s;
2667
- });
2668
- return;
2669
- }
2670
- for (let r of e.runs) {
2671
- if (r.type === "shape") {
2672
- let e = r;
2673
- if (e.behindDoc) continue;
2674
- hr(e, t, n);
2675
- continue;
2676
- }
2677
- if (r.type !== "image") continue;
2678
- let e = r;
2679
- if (!e.anchor || xe(e.wrapMode)) continue;
2680
- let i = t.images.get(Wt(e.imagePath, e.colorReplaceFrom));
2681
- if (!i) continue;
2682
- let { x: a, y: o, w: s, h: c } = vr(e, t, n);
2683
- y(t.ctx, i, e.srcRect ?? void 0, a, o, s, c);
2684
- }
2685
- }
2686
- }
2687
- function pr(e) {
2688
- if (e) return {
2689
- type: e.type,
2690
- w: e.w,
2691
- len: e.len
2692
- };
2693
- }
2694
- function mr(e, t, n) {
2695
- let { scale: r } = t, i = e.widthPt * r, a = e.heightPt * r, o = e.anchorXPt, s = e.anchorYPt, c = e.groupWidthPt ?? null, l = e.groupHeightPt ?? null;
2696
- if (e.widthPct != null) {
2697
- let n = Ve(e.widthRelativeFrom, !1, t), a = (n.end - n.start) * e.widthPct / r;
2698
- if (e.groupWidthPt != null && e.groupWidthPt > 0) {
2699
- let t = a / e.groupWidthPt;
2700
- i = e.widthPt * r * t, o = e.anchorXPt * t;
2701
- } else i = a * r;
2702
- c = a;
2703
- }
2704
- if (e.heightPct != null) {
2705
- let i = He(e.heightRelativeFrom, !1, n, t), o = (i.end - i.start) * e.heightPct / r;
2706
- if (e.groupHeightPt != null && e.groupHeightPt > 0) {
2707
- let t = o / e.groupHeightPt;
2708
- a = e.heightPt * r * t, s = e.anchorYPt * t;
2709
- } else a = o * r;
2710
- l = o;
2711
- }
2712
- return {
2713
- x: Ue(e.anchorXAlign, e.anchorXFromMargin, o, i, t, e.anchorXRelativeFrom, e.pctPosH, c),
2714
- y: We(e.anchorYAlign, e.anchorYFromPara, s, a, n, t, e.anchorYRelativeFrom, e.pctPosV, l),
2715
- w: i,
2716
- h: a
2717
- };
2718
- }
2719
- function hr(t, n, a) {
2720
- let { ctx: o, scale: s } = n, { x: c, y: d, w: f, h: p } = mr(t, n, a), m = t.presetGeometry?.toLowerCase() ?? "", h = m === "line" || m.startsWith("straightconnector") || m.startsWith("bentconnector") || m.startsWith("curvedconnector"), g = m === "line" || m.startsWith("straightconnector") || m.startsWith("bentconnector");
2721
- if (f < 0 || p < 0 || (h ? f === 0 && p === 0 : f === 0 || p === 0)) return;
2722
- let _ = t.rotation ?? 0, v = t.flipH ?? !1, y = t.flipV ?? !1;
2723
- o.save(), (_ !== 0 || v || y) && (o.translate(c + f / 2, d + p / 2), _ !== 0 && o.rotate(_ * Math.PI / 180), v && o.scale(-1, 1), y && o.scale(1, -1), o.translate(-(c + f / 2), -(d + p / 2)));
2724
- let b = t.presetGeometry?.toLowerCase() ?? "", x = !!t.presetGeometry && r(b), S = t.adjValues ?? [], C = l(t.fill, o, c, d, f, p), w = t.stroke && (t.strokeWidth ?? 0) > 0 ? {
2725
- color: t.stroke,
2726
- width: t.strokeWidth ?? 0,
2727
- dashStyle: t.strokeDash ?? void 0,
2728
- headEnd: pr(t.headEnd),
2729
- tailEnd: pr(t.tailEnd)
2730
- } : null, T = w ? () => {
2731
- e(o, w, s), o.stroke();
2732
- } : null;
2733
- if (x ? u(o, b, c, d, f, p, [
2734
- S[0] ?? null,
2735
- S[1] ?? null,
2736
- S[2] ?? null,
2737
- S[3] ?? null,
2738
- S[4] ?? null,
2739
- S[5] ?? null,
2740
- S[6] ?? null,
2741
- S[7] ?? null
2742
- ], C, T, () => {}, g ? { skipTrailingStroke: !0 } : void 0) : (o.beginPath(), t.presetGeometry ? ie(o, t.presetGeometry, c, d, f, p, S[0] ?? null, S[1] ?? null, S[2] ?? null, S[3] ?? null) : H(o, t.subpaths, c, d, f, p), C && (o.fillStyle = C, o.fill()), T && T()), w && (w.headEnd || w.tailEnd) && h) {
2743
- let n = i(m, c, d, f, p, t.adjValues ?? []);
2744
- if (n) {
2745
- if (o.setLineDash([]), g && n.vertices.length >= 2) {
2746
- let t = n.vertices.map((e) => ({
2747
- x: e.x,
2748
- y: e.y
2749
- }));
2750
- if (w.tailEnd) {
2751
- let e = V(w.tailEnd, w, s);
2752
- t[t.length - 1] = G(t[t.length - 1], t[t.length - 2], e);
2753
- }
2754
- if (w.headEnd) {
2755
- let e = V(w.headEnd, w, s);
2756
- t[0] = G(t[0], t[1], e);
2757
- }
2758
- e(o, w, s), o.beginPath(), o.moveTo(t[0].x, t[0].y);
2759
- for (let e = 1; e < t.length; e++) o.lineTo(t[e].x, t[e].y);
2760
- o.stroke();
2761
- }
2762
- w.tailEnd && q(o, n.end.x, n.end.y, n.end.angle, w.tailEnd, w, s), w.headEnd && q(o, n.start.x, n.start.y, n.start.angle, w.headEnd, w, s);
2763
- }
2764
- }
2765
- o.restore(), t.textBlocks && t.textBlocks.length > 0 && _r(t, c, d, f, p, o, s, n.fontFamilyClasses, n.images, n);
2766
- }
2767
- function gr(e, t, n, r) {
2768
- let i = (e ?? 0) * r, a = (t ?? 0) * r;
2769
- return i <= 0 || a <= 0 ? {
2770
- w: n,
2771
- h: n
2772
- } : i <= n ? {
2773
- w: i,
2774
- h: a
2775
- } : {
2776
- w: n,
2777
- h: n / i * a
2778
- };
2779
- }
2780
- function _r(e, t, n, r, i, a, o, s = {}, c = /* @__PURE__ */ new Map(), l) {
2781
- let u = l ?? Rt(a, o, s, c), d = u.defaultColor ?? "#000000", f = e.textBlocks ?? [], p = (e.textInsetL ?? 0) * o, m = (e.textInsetT ?? 0) * o, h = (e.textInsetR ?? 0) * o, g = (e.textInsetB ?? 0) * o, _ = t + p, v = Math.max(0, r - p - h), y = n + m, b = Math.max(0, i - m - g), x = (e) => {
2782
- let t = (e.indentLeft ?? 0) * o, n = (e.indentRight ?? 0) * o, r = (e.indentFirst ?? 0) * o, i = Math.max(0, v - t - n);
2783
- return {
2784
- leftPx: t,
2785
- firstPx: r,
2786
- paraW: i,
2787
- firstLineW: Math.max(0, i - r)
2788
- };
2789
- }, S = (e, t, n, r, i, c, l) => {
2790
- let u = A(e ?? null, r), d = A(c ?? null, r), f = l ?? Math.max(u, d), p = d > u ? c ?? null : e ?? null;
2791
- a.font = X(t, n, r, p, s);
2792
- let m = a.measureText("Mg"), h = I(p, r, m.fontBoundingBoxAscent ?? m.actualBoundingBoxAscent ?? r * .8, m.fontBoundingBoxDescent ?? m.actualBoundingBoxDescent ?? r * .2), g = h.ascent + h.descent, _ = Z(i.lineSpacingRule ? {
2793
- value: i.lineSpacingVal ?? 0,
2794
- rule: i.lineSpacingRule
2795
- } : null, h.ascent, h.descent, o, void 0, !1, f, !1);
2796
- return {
2797
- lineH: _,
2798
- baselineOffset: (_ - g) / 2 + h.ascent
2799
- };
2800
- }, C = (e, t) => {
2801
- let n = null, r = 0;
2802
- for (let e of t.segments) {
2803
- if (!("text" in e)) continue;
2804
- let t = e;
2805
- (!n || t.fontSize > n.fontSize) && (n = t);
2806
- let i = t.fontSize * o;
2807
- r = Math.max(r, A(t.fontFamily ?? null, i), A(t.eaFloorFamily ?? null, i));
2808
- }
2809
- let i = (n?.fontSize ?? e.fontSizePt) * o;
2810
- return S(n?.fontFamily ?? e.fontFamily, n?.bold ?? e.bold ?? !1, n?.italic ?? e.italic ?? !1, i, e, n?.eaFloorFamily ?? e.fontFamily, r);
2811
- }, w = f.map((e) => {
2812
- let t = x(e);
2813
- if (e.imagePath) {
2814
- let { w: n, h: r } = gr(e.imageWidthPt ?? 0, e.imageHeightPt ?? 0, t.firstLineW, o);
2815
- return {
2816
- kind: "image",
2817
- fitW: n,
2818
- fitH: r,
2819
- ind: t
2820
- };
2821
- }
2822
- let n = Ft(a, Pt((e.runs && e.runs.length > 0 ? e.runs : [{
2823
- text: e.text,
2824
- fontSizePt: e.fontSizePt,
2825
- color: e.color,
2826
- fontFamily: e.fontFamily,
2827
- bold: e.bold,
2828
- italic: e.italic
2829
- }]).map(Lt), u), t.paraW, t.firstPx, o, e.tabStops ?? [], void 0, s, t.leftPx, u.kinsoku, 0, u.defaultTabPt), r = n.map((t) => C(e, t)), i = oe(e.bidi, e.text) === "rtl";
2830
- return {
2831
- kind: "text",
2832
- lines: n,
2833
- lineHeights: r.map((e) => e.lineH),
2834
- baselineOffsets: r.map((e) => e.baselineOffset),
2835
- baseRtl: i,
2836
- alignment: e.alignment,
2837
- ind: t
2838
- };
2839
- }), T = (e) => e.kind === "image" ? e.fitH : e.lineHeights.reduce((e, t) => e + t, 0), E = f.map((e) => (e.spaceBefore ?? 0) * o), D = f.map((e) => (e.spaceAfter ?? 0) * o), O = (e) => e > 0 ? Math.max(E[e], D[e - 1]) : E[e], k = w.reduce((e, t, n) => e + O(n) + T(t), 0), j = e.textAnchor ?? "t", M;
2840
- M = j === "b" ? y + Math.max(0, b - k) : j === "ctr" ? y + Math.max(0, (b - k) / 2) : y;
2841
- let N = e.textAutofit === "none";
2842
- N && (a.save(), a.beginPath(), a.rect(t, n, r, i), a.clip());
2843
- for (let e = 0; e < f.length; e++) {
2844
- let t = f[e], n = w[e];
2845
- if (M += O(e), n.kind === "image") {
2846
- let { fitW: e, fitH: r, ind: i } = n, o = _ + i.leftPx + i.firstPx, s = i.firstLineW, l = t.imagePath ? c.get(Wt(t.imagePath)) : void 0;
2847
- if (l) {
2848
- let n = o + Math.max(0, (s - e) / 2);
2849
- t.alignment === "left" || t.alignment === "both" ? n = o : t.alignment === "right" && (n = o + Math.max(0, s - e)), a.drawImage(l, n, M, e, r);
2850
- }
2851
- M += r;
2852
- continue;
2853
- }
2854
- if (n.kind === "text") {
2855
- let { lines: e, baseRtl: t, ind: r } = n, i = n.alignment === "distribute" ? "justify" : ve(n.alignment, t), c = i === "justify", l = n.alignment === "distribute", u = t || e.some((e) => he(e.segments));
2856
- a.textAlign = "left";
2857
- for (let f = 0; f < e.length; f++) {
2858
- let p = e[f], m = f === 0, h = f === e.length - 1, g = n.lineHeights[f], v = M + n.baselineOffsets[f], y = _ + r.leftPx + (m ? r.firstPx : 0), b = m ? r.firstLineW : r.paraW, x = p.segments.length, S = u ? _e(p.segments, t) : null, C = S ? S.order[x - 1] : x - 1, w = p.segments.reduce((e, t) => e + t.measuredWidth, 0), T = h || (p.endsWithBreak ?? !1), E = c && (!T || l), D = b - w, O = null, k = 0, A = 0;
2859
- if (!u) for (let e = 0; e < x; e++) {
2860
- let t = p.segments[e];
2861
- if (!("text" in t) || /\S/.test(t.text)) {
2862
- A = e;
2863
- break;
2864
- }
2865
- }
2866
- let j = 0;
2867
- if (!E && D < 0) {
2868
- let e = ke(p.segments.map((e) => "text" in e ? { text: e.text } : {}), D, A, u ? C : x, p.ascent);
2869
- e && (O = e.perSeg, k = e.perGap, j = Oe(e));
2870
- }
2871
- let N = D - j, P = 0;
2872
- E || (i === "right" ? P = Math.max(0, N) : i === "center" ? P = Math.max(0, N / 2) : i === "justify" && t && (P = Math.max(0, N)));
2873
- let F = y + P;
2874
- if (E) {
2875
- let e = -p.ascent * .25, t = De(p.segments.map((e) => "text" in e ? { text: e.text } : {}), D, A, u ? C : x, e, D > 0);
2876
- O = t ? t.perSeg : null, k = t ? t.perGap : 0;
2877
- }
2878
- for (let e = 0; e < x; e++) {
2879
- let t = S ? S.order[e] : e, n = p.segments[t];
2880
- if (S && (a.direction = S.rtl[t] ? "rtl" : "ltr"), "isTab" in n) {
2881
- n.leader && n.leader !== "none" && n.measuredWidth > 1 && ur(a, n.leader, F, v, n.measuredWidth, n.fontSize * o, d, n.bold, n.italic), F += n.measuredWidth;
2882
- continue;
2883
- }
2884
- if ("imagePath" in n || "mathNodes" in n) {
2885
- F += n.measuredWidth;
2886
- continue;
2887
- }
2888
- let r = n, i = O?.get(t), c = i?.internalStretch ?? 0, l = at(r, o), f = r.vertAlign === "super" ? -r.fontSize * o * .35 : r.vertAlign === "sub" ? r.fontSize * o * .15 : 0;
2889
- if (a.font = X(r.bold, r.italic, l, r.fontFamily, s), a.fillStyle = r.color ? `#${r.color}` : "#000000", i && i.splitBefore.length > 0) {
2890
- let e = [...r.text];
2891
- if (i.splitBefore.length === e.length - 1) {
2892
- let e = a.letterSpacing;
2893
- a.letterSpacing = `${k}px`, a.fillText(r.text, F, v + f), a.letterSpacing = e;
2894
- } else {
2895
- let t = (e) => a.measureText(e).width;
2896
- for (let { text: n, dx: r } of te(e, i.splitBefore, k, t)) a.fillText(n, F + r, v + f);
2897
- }
2898
- } else a.fillText(r.text, F, v + f);
2899
- F += r.measuredWidth + c, i?.trailingGap && !u && /\s$/.test(r.text) && (F += k);
2900
- }
2901
- M += g;
2902
- }
2903
- continue;
2904
- }
2905
- }
2906
- N && a.restore(), a.direction = "ltr";
2907
- }
2908
- function vr(e, t, n) {
2909
- let r = t.scale, i = e.widthPt * r, a = e.heightPt * r;
2910
- return {
2911
- x: Ue(e.anchorXAlign, e.anchorXFromMargin ?? !1, e.anchorXPt ?? 0, i, t, e.anchorXRelativeFrom ?? null, null, null),
2912
- y: We(e.anchorYAlign, e.anchorYFromPara ?? !1, e.anchorYPt ?? 0, a, n, t, e.anchorYRelativeFrom ?? null, null, null),
2913
- w: i,
2914
- h: a,
2915
- dl: (e.distLeft ?? 0) * r,
2916
- dr: (e.distRight ?? 0) * r,
2917
- dt: (e.distTop ?? 0) * r,
2918
- db: (e.distBottom ?? 0) * r
2919
- };
2920
- }
2921
- function yr(e, t) {
2922
- if (e == null) return !t;
2923
- switch (e) {
2924
- case "paragraph":
2925
- case "line":
2926
- case "character": return !1;
2927
- default: return !0;
2928
- }
2929
- }
2930
- function br(e) {
2931
- return xe(e.wrapMode) ? yr(e.anchorYRelativeFrom ?? null, e.anchorYFromPara ?? !1) : !1;
2932
- }
2933
- function xr(e, t, n) {
2934
- let r = t.floatParaSeq++, i = t.pageAnchorPrescanned?.has(e) ?? !1;
2935
- for (let a of e.runs) if (a.type === "image") {
2936
- let e = a;
2937
- if (i && br(e)) continue;
2938
- Cr(e, t, n, r);
2939
- } else if (a.type === "shape") {
2940
- let e = a;
2941
- if (i && br(e)) continue;
2942
- wr(e, t, n, r);
2943
- }
2944
- }
2945
- function Sr(e, t, n) {
2946
- n.pageAnchorPrescanned ||= /* @__PURE__ */ new Set();
2947
- for (let r = t; r < e.length; r++) {
2948
- let t = e[r];
2949
- if (!t) continue;
2950
- if (t.type === "pageBreak") break;
2951
- if (t.type === "sectionBreak") {
2952
- let e = t;
2953
- if (e.kind && e.kind !== "continuous") break;
2954
- continue;
2955
- }
2956
- if (t.type !== "paragraph") continue;
2957
- let i = t;
2958
- if (n.pageAnchorPrescanned.has(i)) continue;
2959
- let a = !1;
2960
- for (let e of i.runs) if (e.type === "image") {
2961
- if (br(e)) {
2962
- a = !0;
2963
- break;
2964
- }
2965
- } else if (e.type === "shape" && br(e)) {
2966
- a = !0;
2967
- break;
2968
- }
2969
- if (!a) continue;
2970
- let o = n.floatParaSeq++;
2971
- for (let e of i.runs) if (e.type === "image") {
2972
- let t = e;
2973
- if (!br(t)) continue;
2974
- Cr(t, n, 0, o);
2975
- } else if (e.type === "shape") {
2976
- let t = e;
2977
- if (!br(t)) continue;
2978
- wr(t, n, 0, o);
2979
- }
2980
- n.pageAnchorPrescanned.add(i);
2981
- }
2982
- }
2983
- function Cr(e, t, n, r) {
2984
- if (!e.anchor || !xe(e.wrapMode)) return;
2985
- let i = e.wrapMode === "topAndBottom" ? "topAndBottom" : "square", a = vr(e, t, n), { w: o, h: s, dl: c, dr: l, dt: u, db: d } = a, f = e.allowOverlap ?? !0, p = Wt(e.imagePath, e.colorReplaceFrom), m = Ie(t, {
2986
- x: a.x,
2987
- y: a.y,
2988
- w: o,
2989
- h: s,
2990
- dl: c,
2991
- dr: l,
2992
- dt: u,
2993
- db: d,
2994
- kind: "shape",
2995
- mode: i,
2996
- side: e.wrapSide ?? "bothSides",
2997
- imageKey: p,
2998
- drawn: !1,
2999
- paraId: r,
3000
- avoidOverlap: !0,
3001
- allowOverlap: f
3002
- });
3003
- if (!t.dryRun) {
3004
- let n = t.images.get(p);
3005
- n && y(t.ctx, n, e.srcRect ?? void 0, m.imageX, m.imageY, m.imageW, m.imageH), m.drawn = !0;
3006
- }
3007
- }
3008
- function wr(e, t, n, r) {
3009
- if (!xe(e.wrapMode)) return;
3010
- let { x: i, y: a, w: o, h: s } = mr(e, t, n);
3011
- if (o <= 0 || s <= 0) return;
3012
- let c = e.wrapMode === "topAndBottom" ? "topAndBottom" : "square", l = t.scale;
3013
- Ie(t, {
3014
- x: i,
3015
- y: a,
3016
- w: o,
3017
- h: s,
3018
- dl: (e.distLeft ?? 0) * l,
3019
- dr: (e.distRight ?? 0) * l,
3020
- dt: (e.distTop ?? 0) * l,
3021
- db: (e.distBottom ?? 0) * l,
3022
- kind: "shape",
3023
- mode: c,
3024
- side: e.wrapSide ?? "bothSides",
3025
- imageKey: "",
3026
- drawn: !0,
3027
- paraId: r,
3028
- avoidOverlap: !0,
3029
- allowOverlap: !0
3030
- });
3031
- }
3032
- function Tr(e, t, n) {
3033
- let { scale: r } = n, i = e, a = t / r, o = i.tableLayoutInputs;
3034
- if (lr && o !== void 0 && i.tableColWidthsPt !== void 0 && i.tableRowHeightsPt !== void 0 && o.scale === 1 && i.tableRowHeightsPt.length === e.rows.length && Math.abs(o.contentWPt - a) <= 1e-6 * Math.max(1, Math.abs(a))) {
3035
- let e = i.tableColWidthsPt.map((e) => e * r), t = i.tableRowHeightsPt.map((e) => e * r);
3036
- return {
3037
- colWidths: e,
3038
- tableW: e.reduce((e, t) => e + t, 0),
3039
- rowHeights: t
3040
- };
3041
- }
3042
- let s = Ln(e, a, n).map((e) => e * r);
3043
- return {
3044
- colWidths: s,
3045
- tableW: s.reduce((e, t) => e + t, 0),
3046
- rowHeights: qe(e, s, r, (t, i) => Er(t, e, i, r, n))
3047
- };
3048
- }
3049
- function Er(e, t, n, r, i) {
3050
- let a = jr(e, t), o = n - (a.left + a.right) * r, s = Fr(e.content);
3051
- return (a.top + a.bottom) * r + Yn(s, (e) => Nr(i, e, o, r), r);
3052
- }
3053
- function Dr(e, t, n, r, i, a, o) {
3054
- let { scale: s, dryRun: c } = o, l = e.bidiVisual === !0, u = [], d = a;
3055
- for (let a = 0; a < e.rows.length; a++) {
3056
- let f = e.rows[a], p = r[a], m = i, h = 0;
3057
- for (let g of f.cells) {
3058
- let _ = Math.min(g.colSpan, t.length - h), v = t.slice(h, h + _).reduce((e, t) => e + t, 0), y = l ? i + n - (m - i) - v : m;
3059
- if (g.vMerge !== !1) {
3060
- let n = p, i = a;
3061
- if (g.vMerge === !0) {
3062
- let t = Ge(e, a, h);
3063
- i = t, n = 0;
3064
- for (let e = a; e <= t; e++) n += r[e];
3065
- }
3066
- let l = {
3067
- topRow: a === 0,
3068
- bottomRow: i === e.rows.length - 1,
3069
- leftCol: h === 0,
3070
- rightCol: h + _ === t.length
3071
- }, m = f.rowHeightRule === "exact" && g.vMerge !== !0;
3072
- c ? Mr(g, e, v, s, o) : u.push({
3073
- cell: g,
3074
- x: y,
3075
- y: d,
3076
- w: v,
3077
- h: n,
3078
- edges: l,
3079
- clipExact: m
3080
- });
3081
- }
3082
- m += v, h += _;
3083
- }
3084
- d += p;
3085
- }
3086
- for (let t of u) Pr(t.cell, e, t.x, t.y, t.w, t.h, o, t.clipExact);
3087
- for (let t of u) Rr(o.ctx, t.x, t.y, t.w, t.h, t.cell.borders, e.borders, s, t.edges, l, o.dpr);
3088
- return d;
3089
- }
3090
- function Or(e, t) {
3091
- let n = e.tblpPr, r = t.y, i = t.contentX, a = t.contentW, { colWidths: o, tableW: s, rowHeights: c } = Tr(e, t.contentW, t), l = Re(n, t, r, s, c.reduce((e, t) => e + t, 0)), u = Be(l, t);
3092
- t.contentX = l.x, t.contentW = s, Dr(e, o, s, c, l.x, l.y, t), t.contentX = i, t.contentW = a, t.y = r, ze(l, n, t, u, e.overlap !== "never");
3093
- }
3094
- function kr(e, t) {
3095
- if (e.tblpPr) {
3096
- Or(e, t);
3097
- return;
3098
- }
3099
- let { contentX: n, contentW: r } = t, { colWidths: i, tableW: a, rowHeights: o } = Tr(e, r, t);
3100
- t.y = Dr(e, i, a, o, e.jc === "center" ? n + Math.max(0, (r - a) / 2) : e.jc === "right" ? n + Math.max(0, r - a) : n, t.y, t);
3101
- }
3102
- function Ar(e, t, n, r) {
3103
- let i = Pt(t.runs, e), a = kn(t), o = jn(t, e);
3104
- if (i.length === 0) return _t(t, r, o, a, e.docEastAsian, e.ctx, e.fontFamilyClasses);
3105
- let s = t.indentLeft * r, c = t.indentRight * r, l = Math.max(1, n - s - c), u = Ft(e.ctx, i, l, t.indentFirst * r, r, t.tabStops, void 0, e.fontFamilyClasses, s, e.kinsoku, ut(o, r), e.defaultTabPt);
3106
- if (r === 1 && !Nt(t) && sr(t, u, {
3107
- paraW: l,
3108
- firstIndent: t.indentFirst,
3109
- tabOriginPx: s,
3110
- gridDeltaPx: ut(o, 1),
3111
- hasFloats: !1,
3112
- kinsoku: e.kinsoku
3113
- }), a) {
3114
- let e = On(Math.max(0, ...u.map((e) => Z(t.lineSpacing, e.ascent, e.descent, r, o, !0, e.intendedSingle, $(t)))), o, r);
3115
- return u.length * e;
3116
- }
3117
- return u.reduce((e, n) => e + Z(t.lineSpacing, n.ascent, n.descent, r, o, !1, n.intendedSingle, $(t)), 0);
3118
- }
3119
- function jr(e, t) {
3120
- return {
3121
- top: e.marginTop ?? t.cellMarginTop,
3122
- bottom: e.marginBottom ?? t.cellMarginBottom,
3123
- left: e.marginLeft ?? t.cellMarginLeft,
3124
- right: e.marginRight ?? t.cellMarginRight
3125
- };
3126
- }
3127
- function Mr(e, t, n, r, i) {
3128
- let a = jr(e, t), o = a.left * r, s = a.right * r, c = n - o - s;
3129
- for (let t of e.content) Nr(i, t, c, r);
3130
- }
3131
- function Nr(e, t, n, r) {
3132
- if (t.type === "paragraph") {
3133
- let i = t;
3134
- return Ar(e, i, n, r) + (i.spaceBefore + i.spaceAfter) * r;
3135
- }
3136
- return Fn(e, t, n / r) * r;
3137
- }
3138
- function Pr(e, t, n, r, i, a, o, s = !1) {
3139
- let { ctx: c, scale: l } = o;
3140
- e.background && (c.fillStyle = `#${e.background}`, c.fillRect(n, r, i, a));
3141
- let u = jr(e, t), d = u.top * l, f = u.bottom * l, p = u.left * l, m = u.right * l, h = {
3142
- ...o,
3143
- contentX: n + p,
3144
- contentW: i - p - m,
3145
- y: r + d
3146
- };
3147
- if (e.vAlign === "center" || e.vAlign === "bottom") {
3148
- let t = Fr(e.content), n = t.reduce((e, t) => e + Nr(h, t, i - p - m, l), 0), o = t[0], s = t[t.length - 1], c = o && o.type === "paragraph" ? o.spaceBefore * l : 0;
3149
- n -= c, s && s.type === "paragraph" && (n -= s.spaceAfter * l), e.vAlign === "center" ? h.y = r + (a - n) / 2 - c : h.y = r + a - n - f - c;
3150
- }
3151
- s ? (c.save(), c.beginPath(), c.rect(0, r, c.canvas.width, a), c.clip(), Ir(e.content, h), c.restore()) : Ir(e.content, h);
3152
- }
3153
- function Fr(e) {
3154
- if (e.length < 2) return e;
3155
- let t = e[e.length - 1], n = e[e.length - 2];
3156
- return t.type !== "paragraph" || n.type === "paragraph" || t.runs.length > 0 ? e : e.slice(0, -1);
3157
- }
3158
- function Ir(e, t) {
3159
- let n = null, r = 0;
3160
- for (let i of e) if (i.type === "paragraph") {
3161
- let e = i, a = Kn(n, e), o = a ? 0 : e.spaceBefore;
3162
- t.y -= (a ? r : Math.min(r, o)) * t.scale, ar(e, t, a), n = e, r = e.spaceAfter;
3163
- } else i.type === "table" && (kr(i, t), n = null, r = 0);
3164
- }
3165
- function Lr(e) {
3166
- return !e || e.style === "none" || e.style === "nil" ? null : e;
3167
- }
3168
- function Rr(e, t, n, r, i, a, o, s, c, l = !1, u = 1) {
3169
- let d = (e, t) => Lr(e ?? (t ? o.top : a.insideH ?? o.insideH)), f = (e, t) => Lr(e ?? (t ? o.bottom : a.insideH ?? o.insideH)), p = (e, t) => Lr(e ?? (t ? o.left : a.insideV ?? o.insideV)), m = (e, t) => Lr(e ?? (t ? o.right : a.insideV ?? o.insideV)), h = d(a.top, c.topRow), g = f(a.bottom, c.bottomRow), _ = l ? m(a.right, c.rightCol) : p(a.left, c.leftCol), v = l ? p(a.left, c.leftCol) : m(a.right, c.rightCol);
3170
- h && Vr(e, t, n, t + r, n, h, s, u), g && Vr(e, t, n + i, t + r, n + i, g, s, u), _ && Vr(e, t, n, t, n + i, _, s, u), v && Vr(e, t + r, n, t + r, n + i, v, s, u);
3171
- }
3172
- function zr(e, t, n, r, i, a, o, s) {
3173
- e.lineWidth = a;
3174
- let c = n === i, l = t === r, u = c ? 0 : s, d = c ? s : 0, f = l ? k(t + u, a, o) : 0, p = c ? k(n + d, a, o) : 0;
3175
- e.beginPath(), e.moveTo(t + u + f, n + d + p), e.lineTo(r + u + f, i + d + p), e.stroke();
3176
- }
3177
- function Br(e, t) {
3178
- return d(e, t);
3179
- }
3180
- function Vr(e, t, n, r, i, a, o, s = 1) {
3181
- e.save(), e.strokeStyle = a.color ? `#${a.color}` : "#000000";
3182
- let c = Math.max(.5, a.width * o);
3183
- if (a.style === "double") {
3184
- e.fillStyle = e.strokeStyle, ce(e, t, n, r, i, c, s), e.restore();
3185
- return;
3186
- }
3187
- let l = Br(a.style, c);
3188
- l.length && e.setLineDash(l), zr(e, t, n, r, i, c, s, 0), e.restore();
3189
- }
3190
- function Hr(e, t, n, r, i) {
3191
- let a = r;
3192
- for (let r = t; r < n; r++) {
3193
- let t = e[r];
3194
- t.topY !== void 0 && t.topY > a && (a = t.topY), a += i(t);
3195
- }
3196
- return a - r;
3197
- }
3198
- function Ur(e, t, n, r, i, a, o) {
3199
- if (!i) return {
3200
- x: e,
3201
- y: t,
3202
- w: n,
3203
- h: r
3204
- };
3205
- let s = (e) => e && e.style !== "none" ? (e.space ?? 0) * o : 0, c = a?.suppressTop ? i.between : i.top, l = s(i.left), u = s(i.right), d = s(c), f = a?.suppressBottom ? 0 : s(i.bottom);
3206
- return {
3207
- x: e - l,
3208
- y: t - d,
3209
- w: n + l + u,
3210
- h: r + d + f
3211
- };
3212
- }
3213
- function Wr(e, t, n, r, i, a, o, s = 1, c) {
3214
- let l = (t, n, r, i, a) => {
3215
- !t || t.style === "none" || Vr(e, n, r, i, a, {
3216
- width: t.width,
3217
- color: t.color,
3218
- style: t.style
3219
- }, o, s);
3220
- }, u = (e) => (e?.space ?? 0) * o, d = c?.suppressTop ? a.between : a.top;
3221
- l(d, t, n - u(d), t + r, n - u(d)), c?.suppressBottom || l(a.bottom, t, n + i + u(a.bottom), t + r, n + i + u(a.bottom)), l(a.left, t - u(a.left), n, t - u(a.left), n + i), l(a.right, t + r + u(a.right), n, t + r + u(a.right), n + i);
3222
- }
3223
- function Gr(e, t) {
3224
- let n = (e) => e == null || e.style === "none" ? null : e, r = n(e), i = n(t);
3225
- return r == null || i == null ? r == null && i == null : r.style === i.style && r.width === i.width && (r.space ?? 0) === (i.space ?? 0) && (r.color ?? null) === (i.color ?? null);
3226
- }
3227
- function Kr(e, t) {
3228
- return e == null || t == null ? !1 : Gr(e.top, t.top) && Gr(e.bottom, t.bottom) && Gr(e.left, t.left) && Gr(e.right, t.right) && Gr(e.between, t.between);
3229
- }
3230
- function qr(e) {
3231
- if (!e) return !1;
3232
- let t = (e) => e != null && e.style !== "none";
3233
- return t(e.top) || t(e.bottom) || t(e.left) || t(e.right) || t(e.between);
3234
- }
3235
- function Jr(e, t) {
3236
- return !e || !t || e.framePr || t.framePr || !qr(e.borders) || !qr(t.borders) ? !1 : Kr(e.borders, t.borders);
3237
- }
3238
- function Yr(e, t) {
3239
- return e.style === t.style && e.width === t.width && (e.space ?? 0) === (t.space ?? 0) && (e.color ?? null) === (t.color ?? null);
3240
- }
3241
- function Xr(e) {
3242
- let t = e.text.codePointAt(0) ?? 0, n = e.fontFamily ?? null;
3243
- return T(t) ? e.fontFamilyEastAsia ?? n : n;
3244
- }
3245
- function Zr(e) {
3246
- return ne(e.text, e.fontFamily ?? null);
3247
- }
3248
- function Qr(e, t) {
3249
- let n = ot(t);
3250
- return {
3251
- w: e.picBulletWidthPt ?? n,
3252
- h: e.picBulletHeightPt ?? n
3253
- };
3254
- }
3255
- //#endregion
3256
- //#region packages/docx/src/google-fonts.ts
3257
- var $r = {
3258
- ...g,
3259
- ...f
3260
- };
3261
- function* ei(e) {
3262
- let t = function* (e) {
3263
- for (let t of e) if (t.type === "text") yield t.text;
3264
- else if (t.type === "field") yield t.fallbackText;
3265
- else if (t.type === "shape") for (let e of t.textBlocks ?? []) yield e.text;
3266
- }, n = function* (e) {
3267
- if ("runs" in e && (yield* t(e.runs)), "rows" in e) for (let t of e.rows) for (let e of t.cells) for (let t of e.content) yield* n(t);
3268
- }, r = function* (e) {
3269
- for (let t of e ?? []) yield* n(t);
3270
- };
3271
- yield* r(e.body);
3272
- for (let t of [e.headers, e.footers]) for (let e of [
3273
- t?.default,
3274
- t?.first,
3275
- t?.even
3276
- ]) yield* r(e?.body);
3277
- for (let t of [...e.footnotes ?? [], ...e.endnotes ?? []]) yield* r(t.content);
3278
- }
3279
- function ti(e) {
3280
- let t = a(e.majorFont) ?? a(e.minorFont) ?? null;
3281
- return [
3282
- e.majorFont,
3283
- e.minorFont,
3284
- ...s(ei(e), t)
3285
- ];
3286
- }
3287
- //#endregion
3288
- //#region packages/docx/src/document.ts
3289
- var ni = class e {
3290
- _document = null;
3291
- _meta = null;
3292
- _pages = null;
3293
- _mode = "main";
3294
- _worker;
3295
- _bridge;
3296
- _imageCache = /* @__PURE__ */ new Map();
3297
- _fetchImage = (e, t) => this.getImage(e, t);
3298
- constructor(e, t, n) {
3299
- this._worker = e, this._mode = t, this._bridge = new M(this._worker, {
3300
- correlate: (e) => e.id,
3301
- toError: (e) => e.type === "error" ? e.message : void 0
3302
- });
3303
- let r = new URL(n ?? de, location.href).href;
3304
- this._bridge.post({
3305
- type: "init",
3306
- wasmUrl: r
3307
- });
3308
- }
3309
- static async load(t, n = {}) {
3310
- let r = n.mode ?? "main";
3311
- if (r === "worker" && (typeof Worker > "u" || typeof OffscreenCanvas > "u")) throw Error("mode: 'worker' requires Worker and OffscreenCanvas support");
3312
- let i = new e(r === "worker" ? (await import("./render-worker-host-BcmXt3yA.js")).createRenderWorker() : new ue(), r, n.wasmUrl), a;
3313
- if (typeof t == "string") {
3314
- let e = await fetch(t);
3315
- if (!e.ok) throw Error(`Failed to fetch: ${e.status} ${e.statusText}`);
3316
- a = await e.arrayBuffer();
3317
- } else a = t;
3318
- return n.math && r === "worker" && console.warn("[ooxml] the math engine is unavailable in mode: 'worker'; equations will be skipped. Use mode: 'main' for documents with equations."), await i._parse(a, n.maxZipEntryBytes, r === "worker" ? !!n.useGoogleFonts : !1, n.workerTimeoutMs), r === "main" && n.useGoogleFonts && i._document && await h(ti(i._document), $r), r === "main" && n.math && i._document && Bt(i._document.body) && await Ut(i._document.body, n.math), i;
3319
- }
3320
- async _parse(e, t, n = !1, r) {
3321
- let i = await this._bridge.request((r) => this._mode === "worker" ? {
3322
- type: "parse",
3323
- id: r,
3324
- data: e,
3325
- maxZipEntryBytes: t,
3326
- useGoogleFonts: n
3327
- } : {
3328
- type: "parse",
3329
- id: r,
3330
- data: e,
3331
- maxZipEntryBytes: t
3332
- }, [e], { timeoutMs: r });
3333
- if (this._mode === "worker") this._meta = i.meta;
3334
- else {
3335
- let { documentJson: e } = i;
3336
- this._document = JSON.parse(new TextDecoder().decode(new Uint8Array(e)));
3337
- }
3338
- }
3339
- destroy() {
3340
- this._bridge.terminate(), this._document = null, this._meta = null, this._pages = null, this._imageCache.clear(), W(this._fetchImage), qt(this._fetchImage), n(this._fetchImage);
3341
- }
3342
- async getImage(e, t) {
3343
- let n = this._imageCache.get(e);
3344
- if (n) return n;
3345
- let r = this._bridge.request((t) => ({
3346
- type: "extractImage",
3347
- id: t,
3348
- path: e
3349
- })).then((e) => {
3350
- let n = e.bytes;
3351
- return new Blob([n], { type: t });
3352
- });
3353
- return this._imageCache.set(e, r), r;
3354
- }
3355
- get pageCount() {
3356
- return this._meta ? this._meta.pageCount : this._document ? this._getPages().length : 0;
3357
- }
3358
- get mode() {
3359
- return this._mode;
3360
- }
3361
- get document() {
3362
- if (this._meta && !this._document) throw Error("the raw document model stays in the worker in mode: 'worker'; use mode: 'main' if you need direct model access");
3363
- if (!this._document) throw Error("Document not loaded");
3364
- return this._document;
3365
- }
3366
- get comments() {
3367
- return this._meta?.comments ?? this._document?.comments ?? [];
3368
- }
3369
- get footnotes() {
3370
- return this._meta?.footnotes ?? this._document?.footnotes ?? [];
3371
- }
3372
- get endnotes() {
3373
- return this._meta?.endnotes ?? this._document?.endnotes ?? [];
3374
- }
3375
- _getPages() {
3376
- return this._pages ? this._pages : this._document ? (this._pages = Tn(this._document), this._pages) : [];
3377
- }
3378
- pageSize(e) {
3379
- if (this._meta) {
3380
- let t = this._meta.pageSizes, n = t[Math.max(0, Math.min(e, t.length - 1))];
3381
- return n ? {
3382
- widthPt: n.widthPt,
3383
- heightPt: n.heightPt
3384
- } : {
3385
- widthPt: 0,
3386
- heightPt: 0
3387
- };
3388
- }
3389
- if (!this._document) return {
3390
- widthPt: 0,
3391
- heightPt: 0
3392
- };
3393
- let t = this._getPages(), n = t[Math.max(0, Math.min(e, t.length - 1))]?.[0]?.sectionGeom;
3394
- return {
3395
- widthPt: n?.pageWidth ?? this._document.section.pageWidth,
3396
- heightPt: n?.pageHeight ?? this._document.section.pageHeight
3397
- };
3398
- }
3399
- renderPage(e, t, n = {}) {
3400
- if (this._mode === "worker") throw Error("renderPage(canvas) is unavailable in mode: 'worker'; use renderPageToBitmap() and paint it via an ImageBitmapRenderingContext");
3401
- if (!this._document) throw Error("Document not loaded");
3402
- let r = this._getPages();
3403
- return tn(this._document, e, t, {
3404
- ...n,
3405
- totalPages: r.length,
3406
- prebuiltPages: r,
3407
- fetchImage: this._fetchImage
3408
- });
3409
- }
3410
- async renderPageToBitmap(e, t = {}) {
3411
- let n = {
3412
- ...t,
3413
- dpr: t.dpr ?? w()
3414
- };
3415
- if (this._mode === "worker") {
3416
- if (!Number.isInteger(e) || e < 0 || e >= this.pageCount) throw Error(`Page index ${e} out of range (count: ${this.pageCount})`);
3417
- return (await this._bridge.request((t) => ({
3418
- type: "renderPage",
3419
- id: t,
3420
- pageIndex: e,
3421
- opts: n
3422
- }))).bitmap;
3423
- }
3424
- let r = new OffscreenCanvas(1, 1);
3425
- return await this.renderPage(r, e, n), r.transferToImageBitmap();
3426
- }
3427
- };
3428
- //#endregion
3429
- //#region packages/docx/src/text-layer.ts
3430
- function ri(e, t, n, r) {
3431
- e.innerHTML = "", e.style.width = n, e.style.height = r;
3432
- for (let n of t) {
3433
- let t = document.createElement("span");
3434
- t.textContent = n.text, t.style.cssText = `position:absolute;left:${n.x}px;top:${n.y}px;font:${n.font};line-height:${n.h}px;letter-spacing:0;white-space:pre;color:transparent;cursor:text;pointer-events:all;`, e.appendChild(t);
3435
- }
3436
- }
3437
- //#endregion
3438
- //#region packages/docx/src/viewer.ts
3439
- var ii = class {
3440
- _doc = null;
3441
- _currentPage = 0;
3442
- _canvas;
3443
- _wrapper;
3444
- _originalParent = null;
3445
- _originalNextSibling = null;
3446
- _originalDisplay = "";
3447
- _textLayer = null;
3448
- _opts;
3449
- _mode;
3450
- _bitmapCtx = null;
3451
- _warnedNoTextSelection = !1;
3452
- constructor(e, t = {}) {
3453
- this._canvas = e, this._opts = t, this._mode = t.mode ?? "main";
3454
- let n = e.parentElement;
3455
- this._originalParent = n, this._originalNextSibling = e.nextSibling, this._originalDisplay = e.style.display, this._wrapper = document.createElement("div"), this._wrapper.style.cssText = "position:relative;display:inline-block;vertical-align:top;", e.style.display || (e.style.display = "block"), n && n.insertBefore(this._wrapper, e), this._wrapper.appendChild(e), this._mode === "worker" && (this._bitmapCtx = e.getContext("bitmaprenderer")), t.enableTextSelection && (this._textLayer = document.createElement("div"), this._textLayer.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;user-select:text;-webkit-user-select:text;", this._wrapper.appendChild(this._textLayer));
3456
- }
3457
- async load(e) {
3458
- try {
3459
- this._doc = await ni.load(e, {
3460
- useGoogleFonts: this._opts.useGoogleFonts,
3461
- maxZipEntryBytes: this._opts.maxZipEntryBytes,
3462
- workerTimeoutMs: this._opts.workerTimeoutMs,
3463
- wasmUrl: this._opts.wasmUrl,
3464
- math: this._opts.math,
3465
- mode: this._mode
3466
- }), this._currentPage = 0, await this._render();
3467
- } catch (e) {
3468
- let t = e instanceof Error ? e : Error(String(e));
3469
- if (this._opts.onError) {
3470
- this._opts.onError(t);
3471
- return;
3472
- }
3473
- throw t;
3474
- }
3475
- }
3476
- get pageCount() {
3477
- return this._doc?.pageCount ?? 0;
3478
- }
3479
- get currentPage() {
3480
- return this._currentPage;
3481
- }
3482
- get canvasElement() {
3483
- return this._canvas;
3484
- }
3485
- async goToPage(e) {
3486
- this._doc && (this._currentPage = Math.max(0, Math.min(e, this.pageCount - 1)), await this._render());
3487
- }
3488
- async nextPage() {
3489
- await this.goToPage(this._currentPage + 1);
3490
- }
3491
- async prevPage() {
3492
- await this.goToPage(this._currentPage - 1);
3493
- }
3494
- destroy() {
3495
- if (this._doc?.destroy(), this._doc = null, this._originalParent) {
3496
- let e = this._originalNextSibling && this._originalNextSibling.parentNode === this._originalParent ? this._originalNextSibling : null;
3497
- this._originalParent.insertBefore(this._canvas, e);
3498
- } else this._canvas.parentNode && this._canvas.parentNode.removeChild(this._canvas);
3499
- this._canvas.style.display = this._originalDisplay, this._wrapper.remove();
3500
- }
3501
- async _render() {
3502
- if (!this._doc) return;
3503
- let e = this._mode === "worker";
3504
- if (e && this._textLayer && !this._warnedNoTextSelection && (this._warnedNoTextSelection = !0, console.warn("[ooxml] text selection is unavailable in mode: 'worker'; the overlay will be empty. Use mode: 'main' for selectable text.")), e) {
3505
- let e = this._opts.dpr ?? (typeof window < "u" && window.devicePixelRatio || 1), t = await this._doc.renderPageToBitmap(this._currentPage, {
3506
- width: this._opts.width,
3507
- dpr: this._opts.dpr,
3508
- defaultTextColor: this._opts.defaultTextColor,
3509
- showTrackChanges: this._opts.showTrackChanges
3510
- });
3511
- this._canvas.width = t.width, this._canvas.height = t.height, this._canvas.style.width = `${Math.round(t.width / e)}px`, this._canvas.style.height = `${Math.round(t.height / e)}px`, this._bitmapCtx?.transferFromImageBitmap(t);
3512
- } else {
3513
- let e = [], t = this._textLayer ? (t) => e.push(t) : void 0;
3514
- await this._doc.renderPage(this._canvas, this._currentPage, {
3515
- ...this._opts,
3516
- onTextRun: t
3517
- }), this._textLayer && this._buildTextLayer(this._textLayer, e);
3518
- }
3519
- this._opts.onPageChange?.(this._currentPage, this.pageCount);
3520
- }
3521
- _buildTextLayer(e, t) {
3522
- ri(e, t, this._canvas.style.width || this._canvas.width + "px", this._canvas.style.height || this._canvas.height + "px");
3523
- }
3524
- }, ai = 150, oi = "0 1px 3px rgba(0,0,0,0.2)", si = class {
3525
- _doc = null;
3526
- _injected;
3527
- _opts;
3528
- _container;
3529
- _wrapper;
3530
- _scrollHost;
3531
- _spacer;
3532
- _mode;
3533
- _scale = 1;
3534
- _scaleEstablished = !1;
3535
- _slots = /* @__PURE__ */ new Map();
3536
- _free = [];
3537
- _heights = [];
3538
- _lastRange = null;
3539
- _lastTopIndex = -1;
3540
- _scrollListener = null;
3541
- _destroyed = !1;
3542
- _bitmapInFlight = /* @__PURE__ */ new Set();
3543
- _renderEpoch = 0;
3544
- _settleTimer = null;
3545
- _wheelListener = null;
3546
- _warnedNoTextSelection = !1;
3547
- _resizeObserver = null;
3548
- _prevBase = 0;
3549
- _lastFitWidth = 0;
3550
- _pageShadow;
3551
- constructor(e, t = {}) {
3552
- if (e.tagName === "CANVAS") throw Error("DocxScrollViewer takes a container element (e.g. a <div>), not a <canvas> — the viewer creates and manages its own canvases. Pass a block container; for the single-page canvas API use DocxViewer.");
3553
- if (this._container = e, this._opts = t, this._pageShadow = t.pageShadow ?? oi, this._injected = !!t.document, this._injected) {
3554
- let e = t.document;
3555
- if (t.mode !== void 0 && t.mode !== e.mode) throw Error(`DocxScrollViewer: opts.mode='${t.mode}' conflicts with the injected engine's mode='${e.mode}'. Omit opts.mode when injecting an engine — the engine owns its render mode.`);
3556
- this._doc = e, this._mode = e.mode;
3557
- } else this._mode = t.mode ?? "main";
3558
- this._wrapper = document.createElement("div"), this._wrapper.style.cssText = "position:relative;width:100%;height:100%;overflow:hidden;", this._scrollHost = document.createElement("div"), this._scrollHost.style.cssText = "position:absolute;inset:0;overflow:auto;", t.background && (this._scrollHost.style.background = t.background), this._spacer = document.createElement("div"), this._spacer.style.cssText = "position:absolute;top:0;left:0;width:1px;height:0;pointer-events:none;", this._scrollHost.appendChild(this._spacer), this._wrapper.appendChild(this._scrollHost), this._container.appendChild(this._wrapper), this._scrollListener = () => this._onScroll(), this._scrollHost.addEventListener("scroll", this._scrollListener), this._opts.enableZoom !== !1 && (this._wheelListener = (e) => {
3559
- (e.ctrlKey || e.metaKey) && (e.preventDefault(), e.deltaY !== 0 && this.setScale(P(this._scale, e.deltaY)));
3560
- }, this._scrollHost.addEventListener("wheel", this._wheelListener, { passive: !1 })), typeof ResizeObserver < "u" && (this._resizeObserver = new ResizeObserver(() => this._onResize()), this._resizeObserver.observe(this._container)), this._injected && this.relayout();
3561
- }
3562
- async load(e) {
3563
- if (this._injected) throw Error("DocxScrollViewer.load() is unsupported when an engine is injected via opts.document; the injected engine is already loaded.");
3564
- try {
3565
- this._doc = await ni.load(e, {
3566
- useGoogleFonts: this._opts.useGoogleFonts,
3567
- maxZipEntryBytes: this._opts.maxZipEntryBytes,
3568
- workerTimeoutMs: this._opts.workerTimeoutMs,
3569
- wasmUrl: this._opts.wasmUrl,
3570
- math: this._opts.math,
3571
- mode: this._mode
3572
- }), this.relayout();
3573
- } catch (e) {
3574
- let t = e instanceof Error ? e : Error(String(e));
3575
- if (this._opts.onError) {
3576
- this._opts.onError(t);
3577
- return;
3578
- }
3579
- throw t;
3580
- }
3581
- }
3582
- get pageCount() {
3583
- return this._doc?.pageCount ?? 0;
3584
- }
3585
- _pageWidthPx(e) {
3586
- return this._doc.pageSize(e).widthPt * t * this._scale;
3587
- }
3588
- _pageHeightPx(e) {
3589
- return this._doc.pageSize(e).heightPt * t * this._scale;
3590
- }
3591
- _fitWidthPx() {
3592
- if (this._opts.width && this._opts.width > 0) return this._opts.width;
3593
- let e = this._container.clientWidth || this._scrollHost.clientWidth;
3594
- if (e <= 0) return 0;
3595
- let { left: t, right: n } = this._padH(), r = e - t - n;
3596
- return r > 0 ? r : 0;
3597
- }
3598
- _baseScale() {
3599
- if (!this._doc || this._doc.pageCount === 0) return 0;
3600
- let e = this._fitWidthPx();
3601
- if (e <= 0) return 0;
3602
- let n = this._doc.pageSize(0).widthPt;
3603
- return n <= 0 ? 0 : e / (n * t);
3604
- }
3605
- relayout() {
3606
- if (this._doc) {
3607
- if (!this._scaleEstablished) {
3608
- let e = this._baseScale();
3609
- if (e > 0) this._scale = e, this._prevBase = e, this._lastFitWidth = this._fitWidthPx(), this._scaleEstablished = !0;
3610
- else return;
3611
- }
3612
- this._recomputeHeights(), this._syncSpacer(), this._mountVisible();
3613
- }
3614
- }
3615
- _recomputeHeights() {
3616
- let e = this._doc.pageCount, t = Array(e);
3617
- for (let n = 0; n < e; n++) t[n] = this._pageHeightPx(n);
3618
- this._heights = t;
3619
- }
3620
- _gap() {
3621
- return this._opts.gap ?? 16;
3622
- }
3623
- _overscan() {
3624
- return this._opts.overscan ?? 1;
3625
- }
3626
- _pad() {
3627
- let e = this._gap();
3628
- return {
3629
- leading: this._opts.paddingTop ?? e,
3630
- trailing: this._opts.paddingBottom ?? e
3631
- };
3632
- }
3633
- _padH() {
3634
- let e = this._gap();
3635
- return {
3636
- left: this._opts.paddingLeft ?? e,
3637
- right: this._opts.paddingRight ?? e
3638
- };
3639
- }
3640
- _range() {
3641
- return J(this._heights, this._gap(), this._scrollHost.scrollTop, this._scrollHost.clientHeight, this._overscan(), this._pad());
3642
- }
3643
- _syncSpacer() {
3644
- let e = this._range();
3645
- this._lastRange = e, this._spacer.style.height = `${e.totalHeight}px`, this._syncSpacerWidth();
3646
- }
3647
- _syncSpacerWidth() {
3648
- let { left: e, right: t } = this._padH(), n = 0;
3649
- for (let e = 0; e < this._heights.length; e++) {
3650
- let t = this._pageWidthPx(e);
3651
- t > n && (n = t);
3652
- }
3653
- this._spacer.style.width = `${n + e + t}px`;
3654
- }
3655
- _onScroll() {
3656
- !this._doc || !this._scaleEstablished || this._mountVisible();
3657
- }
3658
- _mountVisible() {
3659
- if (!this._doc || this._doc.pageCount === 0) return;
3660
- let e = this._range();
3661
- this._lastRange = e;
3662
- for (let [t, n] of [...this._slots]) (t < e.start || t > e.end) && this._recycleSlot(t, n);
3663
- for (let t = e.start; t <= e.end; t++) if (this._slots.has(t)) this._positionSlot(this._slots.get(t), t, e);
3664
- else {
3665
- let n = this._acquireSlot();
3666
- this._positionSlot(n, t, e), this._slots.set(t, n), this._renderSlot(t, n);
3667
- }
3668
- e.topIndex !== this._lastTopIndex && (this._lastTopIndex = e.topIndex, this._opts.onVisiblePageChange?.(e.topIndex, this._doc.pageCount));
3669
- }
3670
- _applyPageShadow(e) {
3671
- this._pageShadow !== !1 && (e.style.boxShadow = this._pageShadow);
3672
- }
3673
- _acquireSlot() {
3674
- let e = this._free.pop();
3675
- if (e) return this._scrollHost.appendChild(e.wrapper), e;
3676
- let t = document.createElement("div");
3677
- t.style.cssText = "position:absolute;";
3678
- let n = document.createElement("canvas");
3679
- n.style.cssText = "display:block;background:#fff;", this._applyPageShadow(n), t.appendChild(n);
3680
- let r = null;
3681
- return this._opts.enableTextSelection && (r = document.createElement("div"), r.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;user-select:text;-webkit-user-select:text;", t.appendChild(r)), this._scrollHost.appendChild(t), {
3682
- wrapper: t,
3683
- canvas: n,
3684
- textLayer: r,
3685
- renderedPage: -1,
3686
- renderedScale: -1,
3687
- bitmap: null,
3688
- bitmapCtx: null
3689
- };
3690
- }
3691
- _recycleSlot(e, t) {
3692
- this._slots.delete(e), t.bitmap &&= (t.bitmap.close(), null), t.textLayer && (t.textLayer.innerHTML = "", t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = ""), t.renderedPage = -1, t.renderedScale = -1, t.wrapper.remove(), this._free.push(t);
3693
- }
3694
- _positionSlot(e, t, n) {
3695
- e.wrapper.style.top = `${n.offsets[t]}px`;
3696
- let r = this._pageWidthPx(t), i = this._pageHeightPx(t);
3697
- e.wrapper.style.width = `${r}px`, e.wrapper.style.height = `${i}px`;
3698
- let { left: a } = this._padH(), o = this._scrollHost.clientWidth;
3699
- e.wrapper.style.left = `${Math.max(a, (o - r) / 2)}px`;
3700
- }
3701
- _dpr() {
3702
- return this._opts.dpr ?? (typeof window < "u" && window.devicePixelRatio || 1);
3703
- }
3704
- _renderSlot(e, t) {
3705
- if (!this._doc || t.renderedPage === e) return;
3706
- t.renderedPage = e;
3707
- let n = this._dpr(), r = this._pageWidthPx(e), i = this._renderEpoch, a = this._scale;
3708
- if (this._mode === "worker") {
3709
- this._renderSlotBitmap(e, t, r, n, a);
3710
- return;
3711
- }
3712
- let o = [], s = !!this._opts.enableTextSelection && !!t.textLayer, c = s ? (e) => o.push(e) : void 0;
3713
- this._doc.renderPage(t.canvas, e, {
3714
- width: r,
3715
- dpr: n,
3716
- defaultTextColor: this._opts.defaultTextColor,
3717
- showTrackChanges: this._opts.showTrackChanges,
3718
- onTextRun: c
3719
- }).then(() => {
3720
- i !== this._renderEpoch || this._slots.get(e) !== t || t.renderedPage !== e || (t.renderedScale = a, s && t.textLayer && ri(t.textLayer, o, t.canvas.style.width || `${t.canvas.width}px`, t.canvas.style.height || `${t.canvas.height}px`));
3721
- }).catch((e) => {
3722
- this._reportRenderError(e);
3723
- });
3724
- }
3725
- _maybeWarnNoTextSelection() {
3726
- this._opts.enableTextSelection && !this._warnedNoTextSelection && (this._warnedNoTextSelection = !0, console.warn("[ooxml] text selection is unavailable in mode: 'worker'; the overlay will be empty. Use mode: 'main' for selectable text."));
3727
- }
3728
- _reportRenderError(e) {
3729
- if (this._destroyed) return;
3730
- let t = e instanceof Error ? e : Error(String(e));
3731
- this._opts.onError ? this._opts.onError(t) : console.error("[ooxml] DocxScrollViewer render failed:", t);
3732
- }
3733
- async _renderSlotBitmap(e, t, n, r, i) {
3734
- if (this._maybeWarnNoTextSelection(), this._bitmapInFlight.has(e) || this._slots.get(e) !== t) return;
3735
- let a = this._renderEpoch;
3736
- this._bitmapInFlight.add(e);
3737
- let o = !1;
3738
- t.bitmapCtx ||= t.canvas.getContext("bitmaprenderer");
3739
- try {
3740
- let s = await this._doc.renderPageToBitmap(e, {
3741
- width: n,
3742
- dpr: r,
3743
- defaultTextColor: this._opts.defaultTextColor,
3744
- showTrackChanges: this._opts.showTrackChanges
3745
- });
3746
- if (a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedPage !== e) {
3747
- s.close();
3748
- return;
3749
- }
3750
- t.bitmap && t.bitmap.close(), t.bitmap = s, t.canvas.width = s.width, t.canvas.height = s.height, t.canvas.style.width = `${Math.round(s.width / r)}px`, t.canvas.style.height = `${Math.round(s.height / r)}px`, t.bitmapCtx?.transferFromImageBitmap(s), t.bitmap = null, t.renderedScale = i, o = !0;
3751
- } catch (e) {
3752
- this._reportRenderError(e);
3753
- } finally {
3754
- this._bitmapInFlight.delete(e);
3755
- let n = this._slots.get(e);
3756
- !o && n && (n !== t || a !== this._renderEpoch) && !this._bitmapInFlight.has(e) && !this._destroyed && this._renderSlotBitmap(e, n, this._pageWidthPx(e), this._dpr(), this._scale);
3757
- }
3758
- }
3759
- setScale(e) {
3760
- if (!this._doc || this._doc.pageCount === 0 || !this._scaleEstablished) return;
3761
- let t = this._opts.zoomMin ?? .1, n = this._opts.zoomMax ?? 4, r = Math.min(n, Math.max(t, e));
3762
- if (r === this._scale) return;
3763
- let i = this._range(), a = i.topIndex, o = this._heights[a] || 0, s = o > 0 ? (this._scrollHost.scrollTop - i.offsets[a]) / o : 0;
3764
- s = Math.min(1, Math.max(0, s)), this._renderEpoch++, this._scale = r, this._recomputeHeights();
3765
- let c = J(this._heights, this._gap(), 0, this._scrollHost.clientHeight, this._overscan(), this._pad());
3766
- this._spacer.style.height = `${c.totalHeight}px`, this._syncSpacerWidth();
3767
- let l = Math.max(0, c.totalHeight - this._scrollHost.clientHeight), u = (c.offsets[a] ?? 0) + s * (this._heights[a] || 0);
3768
- this._scrollHost.scrollTop = Math.min(l, Math.max(0, u)), this._previewVisible(), this._scheduleSettle();
3769
- }
3770
- _previewVisible() {
3771
- if (!this._doc || this._doc.pageCount === 0) return;
3772
- let e = this._range();
3773
- this._lastRange = e;
3774
- for (let [t, n] of [...this._slots]) (t < e.start || t > e.end) && this._recycleSlot(t, n);
3775
- for (let t = e.start; t <= e.end; t++) {
3776
- let n = this._slots.get(t);
3777
- if (n) this._previewSlot(n, t, e);
3778
- else {
3779
- let n = this._acquireSlot();
3780
- this._positionSlot(n, t, e), this._slots.set(t, n), this._renderSlot(t, n);
3781
- }
3782
- }
3783
- e.topIndex !== this._lastTopIndex && (this._lastTopIndex = e.topIndex, this._opts.onVisiblePageChange?.(e.topIndex, this._doc.pageCount));
3784
- }
3785
- _previewSlot(e, t, n) {
3786
- if (this._positionSlot(e, t, n), e.canvas.style.width = `${this._pageWidthPx(t)}px`, e.canvas.style.height = `${this._pageHeightPx(t)}px`, e.textLayer && e.renderedScale > 0) {
3787
- let t = this._scale / e.renderedScale;
3788
- e.textLayer.style.transformOrigin = "0 0", e.textLayer.style.transform = `scale(${t})`;
3789
- }
3790
- }
3791
- _scheduleSettle() {
3792
- this._settleTimer !== null && clearTimeout(this._settleTimer), this._settleTimer = setTimeout(() => {
3793
- this._settleTimer = null, this._settleRender();
3794
- }, ai);
3795
- }
3796
- _settleRender() {
3797
- if (!(this._destroyed || !this._doc || this._doc.pageCount === 0)) for (let [e, t] of [...this._slots]) t.renderedScale !== this._scale && this._settleSlot(e, t);
3798
- }
3799
- _settleSlot(e, t) {
3800
- if (!this._doc) return;
3801
- let n = this._dpr(), r = this._pageWidthPx(e), i = this._scale, a = this._renderEpoch;
3802
- if (this._mode === "worker") {
3803
- this._renderSlotBitmap(e, t, r, n, i);
3804
- return;
3805
- }
3806
- let o = document.createElement("canvas");
3807
- o.style.cssText = "display:block;background:#fff;", this._applyPageShadow(o);
3808
- let s = [], c = !!this._opts.enableTextSelection && !!t.textLayer, l = c ? (e) => s.push(e) : void 0;
3809
- this._doc.renderPage(o, e, {
3810
- width: r,
3811
- dpr: n,
3812
- defaultTextColor: this._opts.defaultTextColor,
3813
- showTrackChanges: this._opts.showTrackChanges,
3814
- onTextRun: l
3815
- }).then(() => {
3816
- if (a !== this._renderEpoch || this._slots.get(e) !== t || t.renderedPage !== e) return;
3817
- let n = t.canvas;
3818
- t.wrapper.insertBefore(o, n), n.remove(), t.canvas = o, t.bitmapCtx = null, t.renderedScale = i, t.textLayer && (t.textLayer.style.transform = "", t.textLayer.style.transformOrigin = "", c && ri(t.textLayer, s, o.style.width || `${o.width}px`, o.style.height || `${o.height}px`));
3819
- }).catch((e) => {
3820
- this._reportRenderError(e);
3821
- });
3822
- }
3823
- scrollToPage(e, t) {
3824
- if (!this._doc || this._doc.pageCount === 0 || !this._scaleEstablished) return;
3825
- let n = Math.max(0, Math.min(e, this._doc.pageCount - 1)), r = J(this._heights, this._gap(), 0, this._scrollHost.clientHeight, this._overscan(), this._pad()), i = r.offsets[n] ?? 0, a = Math.max(0, r.totalHeight - this._scrollHost.clientHeight), o = Math.min(a, Math.max(0, i)), s = this._scrollHost;
3826
- typeof s.scrollTo == "function" ? s.scrollTo({
3827
- top: o,
3828
- behavior: t?.behavior ?? "auto"
3829
- }) : this._scrollHost.scrollTop = o, this._mountVisible();
3830
- }
3831
- _onResize() {
3832
- if (!this._doc || this._doc.pageCount === 0) return;
3833
- if (!this._scaleEstablished) {
3834
- this.relayout();
3835
- return;
3836
- }
3837
- let e = this._baseScale();
3838
- if (e <= 0) return;
3839
- let t = this._fitWidthPx();
3840
- if (t === this._lastFitWidth) {
3841
- this._mountVisible();
3842
- return;
3843
- }
3844
- this._lastFitWidth = t;
3845
- let n = this._prevBase > 0 ? this._scale / this._prevBase : 1;
3846
- this._prevBase = e, this.setScale(e * n), this._mountVisible();
3847
- }
3848
- get topVisiblePage() {
3849
- return this._lastRange?.topIndex ?? 0;
3850
- }
3851
- mountedPageIndicesForTest() {
3852
- return [...this._slots.keys()];
3853
- }
3854
- scaleForTest() {
3855
- return this._scale;
3856
- }
3857
- baseScaleForTest() {
3858
- return this._baseScale();
3859
- }
3860
- renderEpochForTest() {
3861
- return this._renderEpoch;
3862
- }
3863
- resizeForTest() {
3864
- this._onResize();
3865
- }
3866
- destroy() {
3867
- this._destroyed = !0, this._scrollListener &&= (this._scrollHost.removeEventListener("scroll", this._scrollListener), null), this._wheelListener &&= (this._scrollHost.removeEventListener("wheel", this._wheelListener), null), this._resizeObserver?.disconnect(), this._resizeObserver = null, this._settleTimer !== null && (clearTimeout(this._settleTimer), this._settleTimer = null);
3868
- for (let [e, t] of [...this._slots]) this._recycleSlot(e, t);
3869
- this._free.length = 0, this._injected || this._doc?.destroy(), this._doc = null, this._wrapper.remove();
3870
- }
3871
- };
3872
- //#endregion
3873
- //#region packages/docx/src/types.ts
3874
- function ci(e) {
3875
- let t = [];
3876
- for (let n of e.content) {
3877
- if (n.type !== "paragraph") continue;
3878
- let e = "";
3879
- for (let t of n.runs) t.type === "text" && !t.noteRef && (e += t.text);
3880
- e = e.trim(), e && t.push(e);
3881
- }
3882
- return t.join(" ");
3883
- }
3884
- //#endregion
3885
- //#region src/docx.ts
3886
- var li = /* @__PURE__ */ _({
3887
- DocxDocument: () => ni,
3888
- DocxScrollViewer: () => si,
3889
- DocxViewer: () => ii,
3890
- autoResize: () => D,
3891
- buildDocxTextLayer: () => ri,
3892
- noteText: () => ci
3893
- });
3894
- //#endregion
3895
- export { ri as a, ii as i, ci as n, ni as o, si as r, li as t };