@darialan/web-printer 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,1158 +1,131 @@
1
- import lt from "html2canvas";
2
- const dt = 72 / 25.4, v = 25.4 / 96, k = 96 / 25.4, R = (t) => Number((t * v).toFixed(4)), U = {
3
- "card-3x4": { widthPx: 1242, heightPx: 1656, marginPx: 60 },
4
- "square-1x1": { widthPx: 1080, heightPx: 1080, marginPx: 54 },
5
- "card-4x5": { widthPx: 1080, heightPx: 1350, marginPx: 54 },
6
- "story-9x16": { widthPx: 1080, heightPx: 1920, marginPx: 54 },
7
- "ecom-750x1000": { widthPx: 750, heightPx: 1e3, marginPx: 0 }
8
- }, Gt = Object.keys(U);
9
- function ut(t) {
10
- return t in U;
11
- }
12
- function jt(t) {
13
- return ut(t) ? "px" : "mm";
14
- }
15
- const Q = {
16
- a4: [210, 297],
17
- a3: [297, 420],
18
- a5: [148, 210],
19
- letter: [215.9, 279.4],
20
- ...Object.fromEntries(
21
- Object.entries(U).map(([t, e]) => [
22
- t,
23
- [R(e.widthPx), R(e.heightPx)]
24
- ])
25
- )
26
- }, q = {
27
- a4: {
28
- widthMm: 210,
29
- heightMm: 297,
30
- marginTopMm: 10,
31
- marginRightMm: 10,
32
- marginBottomMm: 10,
33
- marginLeftMm: 10
34
- },
35
- a3: {
36
- widthMm: 297,
37
- heightMm: 420,
38
- marginTopMm: 10,
39
- marginRightMm: 10,
40
- marginBottomMm: 10,
41
- marginLeftMm: 10
42
- },
43
- a5: {
44
- widthMm: 148,
45
- heightMm: 210,
46
- marginTopMm: 10,
47
- marginRightMm: 10,
48
- marginBottomMm: 10,
49
- marginLeftMm: 10
50
- },
51
- letter: {
52
- widthMm: 215.9,
53
- heightMm: 279.4,
54
- marginTopMm: 10,
55
- marginRightMm: 10,
56
- marginBottomMm: 10,
57
- marginLeftMm: 10
58
- },
59
- custom: {
60
- widthMm: 210,
61
- heightMm: Number((200 * v).toFixed(2)),
62
- marginTopMm: Number((2 * v).toFixed(2)),
63
- marginRightMm: Number((2 * v).toFixed(2)),
64
- marginBottomMm: Number((2 * v).toFixed(2)),
65
- marginLeftMm: Number((2 * v).toFixed(2))
66
- },
67
- ...Object.fromEntries(
68
- Object.entries(U).map(([t, e]) => [
69
- t,
70
- {
71
- widthMm: R(e.widthPx),
72
- heightMm: R(e.heightPx),
73
- marginTopMm: R(e.marginPx),
74
- marginRightMm: R(e.marginPx),
75
- marginBottomMm: R(e.marginPx),
76
- marginLeftMm: R(e.marginPx)
77
- }
78
- ])
79
- )
80
- }, pt = {
81
- unit: "mm",
82
- paper: "a4",
83
- widthMm: 210,
84
- heightMm: 297,
85
- orientation: "portrait",
86
- marginTopMm: 10,
87
- marginRightMm: 10,
88
- marginBottomMm: 10,
89
- marginLeftMm: 10,
90
- pageNumber: {
91
- enabled: !0,
92
- position: "bottom-right",
93
- format: "slash"
94
- }
95
- };
96
- function Vt(t, e = "portrait", n = "mm") {
97
- const r = q[t] || q.a4;
98
- let o, i;
99
- if (t === "custom")
100
- o = r.widthMm, i = r.heightMm;
101
- else {
102
- const [u, l] = Q[t];
103
- o = e === "landscape" ? l : u, i = e === "landscape" ? u : l;
104
- }
105
- const { marginTopMm: a, marginRightMm: s, marginBottomMm: d, marginLeftMm: c } = r;
106
- return n === "px" ? t === "custom" ? {
107
- width: Number((o * k).toFixed(1)),
108
- height: 200,
109
- marginTop: 2,
110
- marginRight: 2,
111
- marginBottom: 2,
112
- marginLeft: 2
113
- } : {
114
- width: Number((o * k).toFixed(1)),
115
- height: Number((i * k).toFixed(1)),
116
- marginTop: Number((a * k).toFixed(1)),
117
- marginRight: Number((s * k).toFixed(1)),
118
- marginBottom: Number((d * k).toFixed(1)),
119
- marginLeft: Number((c * k).toFixed(1))
120
- } : {
121
- width: o,
122
- height: i,
123
- marginTop: a,
124
- marginRight: s,
125
- marginBottom: d,
126
- marginLeft: c
127
- };
128
- }
129
- function T(t) {
130
- return t * dt;
131
- }
132
- function mt(t) {
133
- const e = t.paper === "custom" ? [t.widthMm, t.heightMm] : Q[t.paper];
134
- if (!e || e.some((s) => !Number.isFinite(s) || s <= 0))
135
- throw new Error("页面宽高必须是大于零的数值");
136
- if (!["portrait", "landscape"].includes(t.orientation))
137
- throw new Error("纸张方向无效");
138
- const n = [t.marginTopMm, t.marginRightMm, t.marginBottomMm, t.marginLeftMm];
139
- if (n.some((s) => !Number.isFinite(s) || s < 0))
140
- throw new Error("页边距必须为非负数");
141
- const [r, o] = [...e].sort((s, d) => s - d), [i, a] = t.paper === "custom" ? e : t.orientation === "portrait" ? [r, o] : [o, r];
142
- if (i - n[1] - n[3] <= 0 || a - n[0] - n[2] <= 0)
143
- throw new Error("页边距占满了页面,请减小边距");
144
- return {
145
- pageWidth: T(i),
146
- pageHeight: T(a),
147
- left: T(n[3]),
148
- right: T(n[1]),
149
- top: T(n[0]),
150
- bottom: T(n[2]),
151
- widthMm: i,
152
- heightMm: a
153
- };
154
- }
155
- const ht = ["widthMm", "heightMm", "marginTopMm", "marginRightMm", "marginBottomMm", "marginLeftMm"];
156
- function Yt(t, e) {
157
- const n = { ...t };
158
- return ht.forEach((r) => {
159
- typeof t[r] == "number" && (n[r] = t[r] * e);
160
- }), n;
161
- }
162
- function ft(t, e, n, r, o = !0) {
163
- var x;
164
- const { pageWidth: i, pageHeight: a } = t;
165
- if (!Number.isFinite(e) || e <= 0 || [n, r].some((y) => y !== void 0 && (!Number.isFinite(y) || y < 0)))
166
- throw new Error("打印区域或页眉页脚尺寸无效");
167
- const s = typeof o == "boolean" ? o : o.enabled, d = typeof o == "object" && ((x = o.position) == null ? void 0 : x.startsWith("top")), c = s && d ? 14 : 0, u = s && !d ? 14 : 0, l = i - t.left - t.right, p = l / e, m = (n || 0) * p, h = (r || 0) * p, g = t.top + m + (n !== void 0 ? 6 : 0) + c, f = a - t.bottom - u - h, b = (f - (r !== void 0 ? 6 : 0) - g) / p;
168
- if (b <= 0)
169
- throw new Error("页眉页脚过高,没有剩余正文空间");
170
- return {
171
- pageWidth: i,
172
- pageHeight: a,
173
- contentWidth: l,
174
- ratio: p,
175
- headerHeight: m,
176
- footerHeight: h,
177
- bodyTop: g,
178
- left: t.left,
179
- headerY: t.top,
180
- footerY: f,
181
- pageNumberY: d ? g - 5 : a - Math.max(6, t.bottom / 2),
182
- capacity: b
183
- };
184
- }
185
- function gt(t, e, n, r = 100) {
186
- if (![t, e].every(Number.isFinite) || t <= 0 || e <= 0 || !Number.isSafeInteger(r) || r < 1)
187
- throw new Error("打印区域或纸张尺寸无效");
188
- const o = [], i = n.map((c) => {
189
- if (!Number.isFinite(c.top) || !Number.isFinite(c.bottom) || c.bottom < c.top)
190
- throw new Error("分页测量结果无效");
191
- return { top: Math.max(0, c.top), bottom: Math.min(t, c.bottom) };
192
- }).filter((c) => c.bottom > c.top).sort((c, u) => c.top - u.top);
193
- for (const c of i) {
194
- if (c.bottom - c.top > e)
195
- throw new Error("存在超过单页高度且不可拆分的内容,请缩小图片或调整布局");
196
- const u = o[o.length - 1];
197
- u && c.top < u.bottom ? u.bottom = Math.max(u.bottom, c.bottom) : o.push({ ...c });
198
- }
199
- if (o.some((c) => c.bottom - c.top > e))
200
- throw new Error("重叠的不可拆分内容超过单页高度,无法安全分页");
201
- const a = [];
202
- let s = 0, d = 0;
203
- for (; s < t; ) {
204
- if (a.length >= r)
205
- throw new Error(`文档超过 ${r} 页限制,请拆分导出或增大页面高度`);
206
- let c = Math.min(s + e, t);
207
- if (c < t) {
208
- for (; d < o.length && o[d].bottom <= c; )
209
- d++;
210
- d < o.length && o[d].top < c && (c = o[d].top);
211
- }
212
- if (c <= s)
213
- throw new Error("页面高度不足,无法安全分页,请增大页面高度");
214
- a.push({ start: s, end: c }), s = c;
215
- }
216
- return a;
217
- }
218
- function bt(t, e, n = 0.25) {
219
- const r = t.slice(1).filter((o) => e.some((i) => i.top + n < o.start && i.bottom - n > o.start));
220
- if (r.length)
221
- throw new Error(`分页预览与原页面布局不一致:${r.length} 个断点穿过受保护内容,首个位置 ${r[0].start.toFixed(1)}px`);
222
- }
223
- const wt = 3, yt = 1, Kt = {
224
- /** 不可分割:最小原子化单元,严禁跨页切断,当前页放不下整块换到下一页 */
225
- ATOMIC: 'data-print-atomic="true"',
226
- /** 可分割:声明为流式内容,允许分页线直接穿透内部 */
227
- SPLITTABLE: 'data-print-splittable="true"',
228
- /** 打印忽略:不参与测量、快照与打印渲染 */
229
- IGNORE: 'data-print-ignore="true"',
230
- // 兼容别名
231
- KEEP_TOGETHER: 'data-print-keep-together="true"',
232
- KEEP_OR_SPLIT: 'data-print-keep-together="split"',
233
- FORCE_SPLIT: 'data-print-break="split"'
234
- }, qt = {
235
- ATOMIC: "print-atomic",
236
- SPLITTABLE: "print-splittable",
237
- IGNORE: "print-ignore",
238
- // 兼容别名
239
- KEEP_TOGETHER: "print-keep-together",
240
- KEEP_OR_SPLIT: "print-keep-or-split",
241
- FORCE_SPLIT: "print-force-split"
242
- }, Xt = {
243
- ATOMIC: 'data-pdf-atomic="true"',
244
- SPLITTABLE: 'data-pdf-splittable="true"',
245
- IGNORE: 'data-pdf-ignore="true"',
246
- KEEP_TOGETHER: 'data-pdf-keep-together="true"',
247
- KEEP_OR_SPLIT: 'data-pdf-keep-together="split"',
248
- FORCE_SPLIT: 'data-pdf-break="split"'
249
- }, Zt = {
250
- ATOMIC: "pdf-atomic",
251
- SPLITTABLE: "pdf-splittable",
252
- IGNORE: "pdf-ignore",
253
- KEEP_TOGETHER: "pdf-keep-together",
254
- KEEP_OR_SPLIT: "pdf-keep-or-split",
255
- FORCE_SPLIT: "pdf-force-split"
256
- }, D = [
257
- // 1. 忽略规则(不打印:标准不可见标签与协议标记)
258
- {
259
- selector: 'script, style, template, [hidden], [data-print-debug], [data-print-ignore="true"], .print-ignore, [data-pdf-debug], [data-pdf-ignore="true"], .pdf-ignore',
260
- result: { kind: "ignore" }
261
- },
262
- // 2. 自由可分割规则(流式容器与段落流,允许分页线穿透)
263
- {
264
- selector: '[data-print-splittable="true"], .print-splittable, [data-print-break="split"], .print-force-split, [data-pdf-splittable="true"], .pdf-splittable, [data-pdf-break="split"], .pdf-force-split',
265
- result: { kind: "container" }
266
- },
267
- // 3. 不可分割规则(显式声明的原子保护块:严禁拆分,超高报错)
268
- {
269
- selector: '[data-print-atomic="true"], .print-atomic, [data-print-keep-together="true"], .print-keep-together, [data-pdf-atomic="true"], .pdf-atomic, [data-pdf-keep-together="true"], .pdf-keep-together',
270
- result: { kind: "atomic", label: "不可分割区域", overflow: "error" }
271
- },
272
- // 4. 不可分割规则(表格行与复合原子项:放不下整块换页,超高深入拆分)
273
- {
274
- selector: '[data-print-keep-together="split"], .print-keep-or-split, [data-pdf-keep-together="split"], .pdf-keep-or-split, tr',
275
- result: { kind: "atomic", label: "表格行与复合块", overflow: "split" }
276
- },
277
- // 5. 原生不可切图片媒体与标题
278
- {
279
- selector: "img, canvas, svg",
280
- result: { kind: "atomic", label: "图片媒体", overflow: "error" }
281
- },
282
- {
283
- selector: "h1, h2, h3, h4, h5, h6",
284
- result: { kind: "atomic", label: "标题", overflow: "error" }
285
- }
286
- ], xt = D;
287
- function I(t) {
288
- var o, i, a;
289
- if (!t)
290
- return [...D];
291
- const e = [];
292
- (o = t.customRules) != null && o.length && e.push(...t.customRules), (i = t.ignore) != null && i.length && e.push({
293
- selector: t.ignore.join(", "),
294
- result: { kind: "ignore" }
295
- });
296
- const n = [
297
- ...t.splittable || [],
298
- ...t.forceSplit || []
299
- ];
300
- n.length && e.push({
301
- selector: n.join(", "),
302
- result: { kind: "container" }
303
- });
304
- const r = [
305
- ...t.atomic || [],
306
- ...t.keepTogether || []
307
- ];
308
- return r.length && e.push({
309
- selector: r.join(", "),
310
- result: { kind: "atomic", label: "自定义原子项", overflow: "error" }
311
- }), (a = t.keepOrSplit) != null && a.length && e.push({
312
- selector: t.keepOrSplit.join(", "),
313
- result: { kind: "atomic", label: "可降级拆分区域", overflow: "split" }
314
- }), [...e, ...D];
315
- }
316
- let j = I();
317
- function Qt(t) {
318
- j = I(t);
319
- }
320
- function S() {
321
- return j;
322
- }
323
- function Jt() {
324
- j = I();
325
- }
326
- function L(t, e = S()) {
327
- var n, r;
328
- return t.nodeType === wt ? (n = t.textContent) != null && n.trim() ? { kind: "text" } : { kind: "ignore" } : t.nodeType !== yt || typeof t.matches != "function" ? { kind: "ignore" } : ((r = e.find((o) => t.matches(o.selector))) == null ? void 0 : r.result) || { kind: "container" };
329
- }
330
- function X(t, e, n, r) {
331
- if (e <= n)
332
- return "protect";
333
- if (t.overflow === "split")
334
- return "descend";
335
- const o = r || t.label;
336
- throw new Error(
337
- `不可拆分区域「${o}」高 ${Math.ceil(e)}px,超过正文可用高度 ${Math.floor(n)}px,请缩小该区域或增大页面高度`
338
- );
339
- }
340
- function V(t, e) {
341
- const n = [], r = (o) => {
342
- for (let i = o.childNodes.length - 1; i >= 0; i--)
343
- n.push(o.childNodes[i]);
344
- };
345
- for (r(t); n.length; ) {
346
- const o = n.pop();
347
- e(o) === "descend" && r(o);
348
- }
349
- }
350
- function J(t, e = (n) => n) {
351
- const n = /* @__PURE__ */ new WeakMap(), r = document.createRange();
352
- let o = 0;
353
- return (i) => {
354
- var c, u;
355
- if (o += ((c = i.textContent) == null ? void 0 : c.length) || 0, o > 2e5)
356
- throw new Error("文本超过 200,000 字符限制,请拆分导出");
357
- const a = i.parentElement;
358
- if (a && !n.has(a)) {
359
- const l = ((u = a.ownerDocument) == null ? void 0 : u.defaultView) || window, p = l.getComputedStyle ? l.getComputedStyle(a).lineHeight : window.getComputedStyle(a).lineHeight;
360
- n.set(a, parseFloat(p));
361
- }
362
- const s = a ? n.get(a) : NaN;
363
- return r.selectNodeContents(i), (r.getClientRects ? Array.from(r.getClientRects()) : []).filter((l) => l.width > 0 && l.height > 0).map((l) => {
364
- const p = Number.isFinite(s) ? Math.max(0, s - l.height) / 2 : 0;
365
- return { top: e(l.top - t - p), bottom: e(l.bottom - t + p) };
366
- });
367
- };
368
- }
369
- function te(t) {
370
- const e = J(t.getBoundingClientRect().top), n = [];
371
- return V(t, (r) => {
372
- const o = L(r);
373
- return o.kind === "ignore" ? "skip" : o.kind === "text" ? (n.push(...e(r)), "skip") : "descend";
374
- }), n;
375
- }
376
- function Et(t) {
377
- const e = Math.max(t.getBoundingClientRect().height, t.scrollHeight);
378
- if (e <= 0 || e > 2e5)
379
- throw new Error("打印区域为空或超过 200,000px 高度限制");
380
- return e;
381
- }
382
- function tt(t, e, n = xt) {
383
- const r = t.getBoundingClientRect(), o = Et(t), i = [], a = J(r.top), s = { visitedNodes: 0, atomicElements: 0, textNodes: 0, textFragments: 0 }, d = L(t, n);
384
- if (d.kind === "ignore")
385
- throw new Error("打印区域已被 ignore 规则排除,请选择其他区域");
386
- if (d.kind === "atomic" && X(
387
- d,
388
- o,
389
- e,
390
- t.getAttribute("data-print-label") || t.getAttribute("data-pdf-label") || t.getAttribute("alt")
391
- ) === "protect")
392
- return { height: o, ranges: [{ top: 0, bottom: o }], stats: { ...s, visitedNodes: 1, atomicElements: 1 } };
393
- const c = (u) => {
394
- const l = Math.max(0, u.top), p = Math.min(o, u.bottom);
395
- p > l && i.push({ top: l, bottom: p });
396
- };
397
- return V(t, (u) => {
398
- s.visitedNodes++;
399
- const l = L(u, n);
400
- if (l.kind === "ignore")
401
- return "skip";
402
- if (l.kind === "container")
403
- return "descend";
404
- if (l.kind === "text") {
405
- const g = a(u);
406
- return s.textNodes++, s.textFragments += g.length, g.forEach(c), "skip";
407
- }
408
- const p = u, m = p.getBoundingClientRect();
409
- if (m.width <= 0 || m.height <= 0)
410
- return "skip";
411
- const h = p.getAttribute("data-print-label") || p.getAttribute("data-pdf-label") || p.getAttribute("alt");
412
- return X(l, m.height, e, h) === "descend" ? "descend" : (s.atomicElements++, c({ top: m.top - r.top, bottom: m.bottom - r.top }), "skip");
413
- }), { height: o, ranges: i, stats: s };
414
- }
415
- function M(t) {
416
- if (t != null && t.aborted)
417
- throw new Error("导出已取消");
418
- }
419
- async function Mt(t) {
420
- for (let e = 0; e < 2; e++)
421
- M(t), await new Promise((n) => setTimeout(n, 16));
422
- M(t);
423
- }
424
- async function et(t, e, n = S()) {
425
- M(e);
426
- let r, o = () => {
427
- };
428
- const i = new Promise((a, s) => {
429
- r = setTimeout(() => s(new Error("字体或图片加载超时,请稍后重试")), 15e3), o = () => s(new Error("导出已取消")), e == null || e.addEventListener("abort", o, { once: !0 });
430
- });
1
+ import { p as R, c as T, a as _, b, e as L } from "./page-break-overlay-e5f1b145.mjs";
2
+ import { B as C, y as F, D as U, g as B, I as k, M as x, k as O, j as G, w as H, x as W, t as z, u as J, P as X, f as Z, U as j, z as q, o as K, a3 as Q, F as V, d as Y, Q as $, A as ee, n as ae, O as te, Y as re, a5 as se, W as ne, R as oe, J as ie, X as le, l as ce, h as ge, C as Pe, a2 as ue, i as de, _ as he, N as me, K as Ee, m as fe, T as pe, a0 as we, a1 as ve, q as Se, Z as be, L as ye, E as Re, G as Te, r as _e, $ as Le, S as Ae, a4 as Ie, s as De, v as Me, V as Ne, H as Ce } from "./page-break-overlay-e5f1b145.mjs";
3
+ import "html2canvas";
4
+ async function D(o) {
5
+ var p, w, v;
6
+ const s = new AbortController(), P = () => s.abort();
7
+ (p = o.signal) == null || p.addEventListener("abort", P, { once: !0 }), (w = o.signal) != null && w.aborted && s.abort();
8
+ const y = performance.now();
9
+ let e;
431
10
  try {
432
- await Promise.race([i, (async () => {
433
- var a;
434
- await Promise.all([
435
- (a = t.ownerDocument.fonts) == null ? void 0 : a.ready,
436
- ...[...t.tagName === "IMG" ? [t] : [], ...Array.from(t.querySelectorAll("img"))].filter((s) => {
437
- for (let d = s; d; d = d.parentElement) {
438
- if (L(d, n).kind === "ignore")
439
- return !1;
440
- if (d === t)
441
- break;
442
- }
443
- return !0;
444
- }).map(async (s) => {
445
- try {
446
- await s.decode();
447
- } catch {
448
- throw new Error(`图片加载失败:${s.alt || "未命名图片"}`);
449
- }
450
- if (!s.naturalWidth)
451
- throw new Error(`图片内容为空:${s.alt || "未命名图片"}`);
452
- })
453
- ]), await Mt(e);
454
- })()]), M(e);
455
- } finally {
456
- clearTimeout(r), e == null || e.removeEventListener("abort", o);
457
- }
458
- }
459
- function Tt(t, e) {
460
- var o;
461
- const n = ((o = t.ownerDocument) == null ? void 0 : o.defaultView) || (typeof window < "u" ? window : null), r = n != null && n.getComputedStyle ? n.getComputedStyle(t) : null;
462
- if (r) {
463
- for (let i = 0; i < r.length; i++) {
464
- const a = r.item(i);
465
- /^(width|height|block-size|inline-size)$/.test(a) && !/^(IMG|CANVAS|SVG|TABLE|COL|COLGROUP)$/.test(t.tagName.toUpperCase()) || e.style.setProperty(a, r.getPropertyValue(a), r.getPropertyPriority(a));
466
- }
467
- e.style.animation = "none", e.style.transition = "none";
468
- }
469
- }
470
- function Pt(t, e = S()) {
471
- const n = typeof document < "u" ? document : t.ownerDocument, r = n != null && n.importNode ? n.importNode(t, !0) : t.cloneNode(!0), o = [t, ...Array.from(t.querySelectorAll("*"))], i = [r, ...Array.from(r.querySelectorAll("*"))];
472
- o.forEach((s, d) => {
473
- const c = i[d];
474
- if (!c || c.nodeType !== 1)
475
- return;
476
- if (s !== t && L(s, e).kind === "ignore") {
477
- c.remove();
478
- return;
479
- }
480
- for (const l of Array.from(c.attributes))
481
- (/^on/i.test(l.name) || l.name === "autofocus") && c.removeAttribute(l.name);
482
- const u = (s.tagName || "").toLowerCase();
483
- if (u === "input") {
484
- const l = s, p = c;
485
- p.value = l.value, p.checked = l.checked;
486
- } else if (u === "textarea")
487
- c.value = s.value;
488
- else if (u === "select")
489
- c.selectedIndex = s.selectedIndex;
490
- else if (u === "canvas") {
491
- const l = s, p = c;
492
- p.width = l.width, p.height = l.height;
11
+ e = await R({ ...o, signal: s.signal });
12
+ } catch (a) {
13
+ throw (v = o.signal) == null || v.removeEventListener("abort", P), a;
14
+ }
15
+ const i = T(e.width, s.signal), m = o.settings ? JSON.parse(JSON.stringify(o.settings)) : void 0;
16
+ let u = !1, l = !1;
17
+ const E = () => {
18
+ if (u)
19
+ throw new Error("打印会话已关闭,请重新生成预览");
20
+ if (b(s.signal), l)
21
+ throw new Error("正在处理上一项任务,请稍候");
22
+ }, f = performance.now() - y;
23
+ return {
24
+ layout: e,
25
+ preparedMs: f,
26
+ async thumbnail(a, c = 480) {
27
+ if (E(), !Number.isInteger(a) || a < 0 || a >= e.pages.length)
28
+ throw new Error("预览页码无效");
29
+ l = !0;
30
+ let r, t;
493
31
  try {
494
- l.toDataURL();
495
- const m = p.getContext("2d");
496
- if (!m)
497
- throw new Error("canvas context unavailable");
498
- m.drawImage(l, 0, 0);
499
- } catch {
500
- throw new Error("画布内容无法读取,请检查跨域图片或浏览器的画布支持");
501
- }
502
- } else if (u === "img") {
503
- const l = c;
504
- if (l.loading = "eager", l.src = s.currentSrc || s.src, l.removeAttribute("srcset"), l.removeAttribute("sizes"), /^https?:/.test(l.src) && typeof window < "u")
32
+ const n = e.pages[a], g = await i.capture(e.root, n.start, n.end - n.start);
505
33
  try {
506
- new URL(l.src).origin !== window.location.origin && (l.crossOrigin = "anonymous");
507
- } catch {
34
+ const d = e.header ? await i.capture(e.header, 0, e.headerHeight / e.ratio) : void 0, h = e.footer ? await i.capture(e.footer, 0, e.footerHeight / e.ratio) : void 0;
35
+ try {
36
+ r = _(g, (n.end - n.start) * e.ratio, a, { geometry: e, settings: m, headerCanvas: d, footerCanvas: h, totalPages: e.pages.length });
37
+ } finally {
38
+ d && i.release(d), h && i.release(h);
39
+ }
40
+ } finally {
41
+ i.release(g);
508
42
  }
509
- }
510
- c.style && Tt(s, c);
511
- }), r.querySelectorAll('[data-print-debug], [data-print-ignore="true"], [data-pdf-debug], [data-pdf-ignore="true"]').forEach((s) => s.remove()), r.style.margin = "0", r.style.setProperty("margin-inline", "0"), r.style.setProperty("margin-block", "0");
512
- const a = t.getBoundingClientRect().width;
513
- return a > 0 && (r.style.width = `${a}px`, r.style.maxWidth = "none", r.style.boxSizing = "border-box"), r;
514
- }
515
- function Rt(t, e = S()) {
516
- const n = document.createElement("div");
517
- return n.setAttribute("data-print-snapshot", "true"), n.setAttribute("aria-hidden", "true"), n.setAttribute("inert", ""), n.style.cssText = `position:absolute;left:-100000px;top:0;width:${t}px;pointer-events:none;background:white;`, {
518
- clone: (o) => {
519
- const i = Pt(o, e);
520
- return i.style.width = `${t}px`, i.style.maxWidth = "none", i.style.boxSizing = "border-box", n.appendChild(i), i;
521
- },
522
- mount: () => document.body.appendChild(n),
523
- ready: (o) => et(n, o),
524
- dispose: () => n.remove()
525
- };
526
- }
527
- function ee(t) {
528
- const e = t.cloneNode(!0);
529
- let n = e;
530
- const r = [t, ...Array.from(t.querySelectorAll("*"))], o = [e, ...Array.from(e.querySelectorAll("*"))];
531
- return r.forEach((i, a) => {
532
- const s = o[a];
533
- for (const d of Array.from(s.attributes))
534
- /^on/i.test(d.name) && s.removeAttribute(d.name);
535
- if (i instanceof HTMLCanvasElement) {
536
- const d = document.createElement("img");
537
- d.src = i.toDataURL("image/png"), d.style.cssText = s.style.cssText, d.width = i.width, d.height = i.height, s === e ? n = d : s.replaceWith(d);
538
- } else
539
- i instanceof HTMLInputElement ? (s.setAttribute("value", i.type === "password" ? "" : i.value), s.toggleAttribute("checked", i.checked)) : i instanceof HTMLTextAreaElement ? s.textContent = i.value : i instanceof HTMLOptionElement && s.toggleAttribute("selected", i.selected);
540
- s.matches("a, button, input, textarea, select, [tabindex]") && s.setAttribute("tabindex", "-1");
541
- }), n.outerHTML;
542
- }
543
- function re(t, e) {
544
- const n = /* @__PURE__ */ new Map();
545
- return t.replace(/\sid="([^"]+)"/g, (r, o) => (n.set(o, `${e}-${o}`), r)), t.replace(
546
- /(\s(?:id|for|href|xlink:href|aria-labelledby|aria-describedby)="|url\(#)([^")]+)("|\))/g,
547
- (r, o, i, a) => {
548
- const s = i.startsWith("#"), d = (s ? i.slice(1) : i).split(" ").map((c) => n.get(c) || c).join(" ");
549
- return `${o}${s ? "#" : ""}${d}${a}`;
550
- }
551
- );
552
- }
553
- const St = 8e6;
554
- function At(t, e) {
555
- const n = /* @__PURE__ */ new Set(), r = (o) => {
556
- o.width = 0, o.height = 0, n.delete(o);
557
- };
558
- return {
559
- async capture(o, i, a) {
560
- if (e != null && e.aborted)
561
- throw new Error("导出已取消");
562
- const s = Math.min(2, Math.sqrt(St / (Math.ceil(t) * Math.ceil(a))), 8192 / t, 8192 / a);
563
- if (!Number.isFinite(s) || s < 0.5)
564
- throw new Error("页面像素超限,请缩小打印区域宽度");
565
- const d = await lt(o, {
566
- x: 0,
567
- y: i,
568
- width: t,
569
- height: a,
570
- scale: s,
571
- useCORS: !0,
572
- allowTaint: !1,
573
- backgroundColor: "#ffffff",
574
- logging: !1,
575
- imageTimeout: 15e3,
576
- ignoreElements: (c) => c.hasAttribute("data-print-debug") || c.getAttribute("data-print-ignore") === "true" ? !0 : c.tagName === "HEAD" || c.closest("head") ? !1 : c !== o && !c.contains(o) && !o.contains(c)
577
- });
578
- if (n.add(d), e != null && e.aborted)
579
- throw new Error("导出已取消");
580
- if (!d.width || !d.height)
581
- throw new Error("截图为空,请检查打印区域");
582
- return d;
583
- },
584
- release: r,
585
- dispose: () => n.forEach(r)
586
- };
587
- }
588
- function rt(t, e, n) {
589
- const r = t + 1;
590
- switch (n) {
591
- case "chinese":
592
- return `第 ${r} 页 / 共 ${e} 页`;
593
- case "hyphen":
594
- return `- ${r} -`;
595
- case "slash":
596
- default:
597
- return `${r} / ${e}`;
598
- }
599
- }
600
- async function kt({
601
- geometry: t,
602
- settings: e,
603
- headerCanvas: n,
604
- footerCanvas: r,
605
- totalPages: o
606
- }) {
607
- const { jsPDF: i } = await import("jspdf"), { pageWidth: a, pageHeight: s, contentWidth: d, headerHeight: c, footerHeight: u, left: l, bodyTop: p, headerY: m, footerY: h, pageNumberY: g } = t, f = a > s ? "landscape" : "portrait", b = new i({ unit: "pt", format: [a, s], orientation: f }), x = (e == null ? void 0 : e.marginRightMm) !== void 0 ? T(e.marginRightMm) : T(10);
608
- return {
609
- addPageSlice(y, P, E) {
610
- y > 0 && b.addPage(), b.addImage(P, "PNG", l, p, d, E, void 0, "FAST"), n && b.addImage(n, "PNG", l, m, d, c, "print-header", "FAST"), r && b.addImage(r, "PNG", l, h, d, u, "print-footer", "FAST");
611
- const w = e == null ? void 0 : e.pageNumber;
612
- if (w ? w.enabled : !0) {
613
- b.setFontSize(9), b.setTextColor(120, 120, 120);
614
- const N = (w == null ? void 0 : w.position) || "bottom-right", A = rt(y, o, w == null ? void 0 : w.format);
615
- let _, $;
616
- N === "bottom-center" || N === "top-center" ? (_ = a / 2, $ = "center") : (_ = a - x, $ = "right");
617
- const Y = g;
618
- if ((w == null ? void 0 : w.format) === "chinese") {
619
- const C = document.createElement("canvas");
620
- C.width = 640, C.height = 48;
621
- const F = C.getContext("2d");
622
- if (!F)
623
- throw new Error("浏览器无法渲染中文页码");
624
- F.font = "24px sans-serif";
625
- const st = Math.ceil(F.measureText(A).width);
626
- F.fillStyle = "#787878", F.fillText(A, 0, 34);
627
- const K = st * 9 / 24, ct = $ === "center" ? K / 2 : K;
628
- b.addImage(C, "PNG", _ - ct, Y - 12.75, 240, 18), C.width = 0, C.height = 0;
629
- } else
630
- b.text(A, _, Y, { align: $ });
43
+ t = document.createElement("canvas"), t.width = Math.max(1, Math.min(640, c, r.width)), t.height = Math.ceil(r.height * t.width / r.width);
44
+ const S = t.getContext("2d");
45
+ if (!S)
46
+ throw new Error("浏览器无法生成预览");
47
+ return S.drawImage(r, 0, 0, t.width, t.height), b(s.signal), t.toDataURL("image/jpeg", 0.85);
48
+ } finally {
49
+ r && (r.width = 0, r.height = 0), t && (t.width = 0, t.height = 0), l = !1;
631
50
  }
632
51
  },
633
- async finalize(y, P = !0) {
634
- const E = b.output("blob");
635
- return P && await b.save(`${y.replace(/\.pdf$/i, "") || "document"}.pdf`, { returnPromise: !0 }), E;
636
- }
637
- };
638
- }
639
- function Z(t, e, n) {
640
- const r = document.createElement("div");
641
- return r.className = `print-declarative-${e}`, r.style.width = `${n}px`, r.style.boxSizing = "border-box", r.style.padding = e === "header" ? "8px 0 6px 0" : "6px 0 8px 0", r.style.textAlign = t.align || "center", r.style.fontSize = e === "header" ? "12px" : "11px", r.style.color = e === "header" ? "#334155" : "#64748b", r.style.fontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif', r.style.lineHeight = "1.4", t.showDivider && (e === "header" ? r.style.borderBottom = "1px solid #cbd5e1" : r.style.borderTop = "1px solid #cbd5e1"), r.textContent = t.text || "", r;
642
- }
643
- const H = /* @__PURE__ */ new WeakSet();
644
- function Nt({ root: t, capacity: e, maxPages: n, rules: r, ruleConfig: o }) {
645
- const i = performance.now(), a = r || (o ? I(o) : S()), s = tt(t, e, a), d = performance.now();
646
- return {
647
- pages: gt(s.height, e, s.ranges, n),
648
- stats: s.stats,
649
- timing: {
650
- measurementMs: d - i,
651
- paginationMs: performance.now() - d
652
- }
653
- };
654
- }
655
- function O(t) {
656
- var o, i, a;
657
- if (!t || typeof t != "object")
658
- return !1;
659
- const e = t;
660
- if (e.nodeType !== 1)
661
- return !1;
662
- const n = (o = e.ownerDocument) == null ? void 0 : o.defaultView;
663
- return n && typeof n.HTMLElement == "function" && e instanceof n.HTMLElement || typeof HTMLElement < "u" && e instanceof HTMLElement || typeof e.getBoundingClientRect == "function" && typeof e.cloneNode == "function" ? !!(e.isConnected ?? ((a = (i = e.ownerDocument) == null ? void 0 : i.contains) == null ? void 0 : a.call(i, e))) : !1;
664
- }
665
- function nt(t) {
666
- var e, n, r;
667
- if (!O(t))
668
- return null;
669
- if (((e = t.tagName) == null ? void 0 : e.toLowerCase()) === "iframe") {
670
- const o = t;
671
- let i;
672
- try {
673
- i = o.contentDocument || ((n = o.contentWindow) == null ? void 0 : n.document);
674
- } catch {
675
- throw new Error("无法读取跨域 iframe,请在嵌入系统内接入打印工具或使用其导出接口");
676
- }
677
- if (!(i != null && i.body) || i.readyState === "loading" || i.URL === "about:blank" && o.getAttribute("src"))
678
- throw new Error("iframe 内容尚未就绪,请等待加载完成后重试");
679
- const a = i.getElementById("iframe-report-content") || i.body;
680
- if (!O(a) || !a.childElementCount && !((r = a.textContent) != null && r.trim()))
681
- throw new Error("iframe 中没有可打印的业务内容");
682
- return a;
683
- }
684
- return t;
685
- }
686
- async function ot(t) {
687
- var p, m, h, g, f;
688
- const { header: e, footer: n, signal: r, orientation: o = "portrait" } = t, i = t.maxPages ?? 100, a = nt(t.element);
689
- if (!a)
690
- throw new Error("找不到有效的打印区域");
691
- if (!["portrait", "landscape"].includes(o))
692
- throw new Error("纸张方向必须为 portrait 或 landscape");
693
- const s = mt({ ...pt, orientation: o, ...t.settings || {} });
694
- if (H.has(a))
695
- throw new Error("该区域正在导出,请勿重复提交");
696
- let d = a.getBoundingClientRect().width;
697
- if (!Number.isFinite(d) || d <= 0)
698
- throw new Error("打印区域宽度为零,请先显示内容");
699
- M(r), H.add(a);
700
- const c = t.rules || (t.ruleConfig ? I(t.ruleConfig) : S());
701
- let u;
702
- const l = () => {
703
- u == null || u.dispose(), H.delete(a);
704
- };
705
- try {
706
- if (await et(a, r, c), d = a.getBoundingClientRect().width, !Number.isFinite(d) || d <= 0)
707
- throw new Error("打印区域宽度为零,请先显示内容");
708
- u = Rt(d, c);
709
- const b = u.clone(a);
710
- let x;
711
- if (e && O(e))
712
- x = u.clone(e);
713
- else if ((m = (p = t.settings) == null ? void 0 : p.header) != null && m.enabled && t.settings.header.text) {
714
- const A = Z(t.settings.header, "header", d);
715
- x = u.clone(A);
716
- }
717
- let y;
718
- if (n && O(n))
719
- y = u.clone(n);
720
- else if ((g = (h = t.settings) == null ? void 0 : h.footer) != null && g.enabled && t.settings.footer.text) {
721
- const A = Z(t.settings.footer, "footer", d);
722
- y = u.clone(A);
723
- }
724
- u.mount(), await u.ready(r), M(r);
725
- const P = ((f = t.settings) == null ? void 0 : f.pageNumber) ?? !0, E = ft(
726
- s,
727
- d,
728
- x == null ? void 0 : x.getBoundingClientRect().height,
729
- y == null ? void 0 : y.getBoundingClientRect().height,
730
- P
731
- ), { pages: w, stats: B, timing: N } = Nt({
732
- root: b,
733
- capacity: E.capacity,
734
- maxPages: i,
735
- rules: c
736
- });
737
- return {
738
- ...E,
739
- root: b,
740
- header: x,
741
- footer: y,
742
- width: d,
743
- pages: w,
744
- stats: B,
745
- timing: N,
746
- cleanup: l
747
- };
748
- } catch (b) {
749
- throw l(), b;
750
- }
751
- }
752
- const Ct = Array.from({ length: 256 }, (t, e) => {
753
- let n = e;
754
- for (let r = 0; r < 8; r++)
755
- n = n >>> 1 ^ 3988292384 & -(n & 1);
756
- return n >>> 0;
757
- });
758
- function vt(t) {
759
- if (t.length > 65535)
760
- throw new Error("图片页数超出 ZIP 限制");
761
- const e = [], n = [];
762
- let r = 0, o = 0;
763
- for (const { name: s, data: d } of t) {
764
- const c = Uint8Array.from(s, (g) => g.charCodeAt(0));
765
- let u = 4294967295;
766
- for (let g = 0; g < d.length; g++)
767
- u = u >>> 8 ^ Ct[(u ^ d[g]) & 255];
768
- if (u = (u ^ 4294967295) >>> 0, r + d.length + c.length + 30 > 4294967295)
769
- throw new Error("图片包超过 4GB,请分批导出");
770
- const l = new Uint8Array(30 + c.length), p = new DataView(l.buffer);
771
- p.setUint32(0, 67324752, !0), p.setUint16(4, 20, !0), p.setUint16(12, 33, !0), p.setUint32(14, u, !0), p.setUint32(18, d.length, !0), p.setUint32(22, d.length, !0), p.setUint16(26, c.length, !0), l.set(c, 30);
772
- const m = new Uint8Array(46 + c.length), h = new DataView(m.buffer);
773
- h.setUint32(0, 33639248, !0), h.setUint16(4, 20, !0), h.setUint16(6, 20, !0), h.setUint16(14, 33, !0), h.setUint32(16, u, !0), h.setUint32(20, d.length, !0), h.setUint32(24, d.length, !0), h.setUint16(28, c.length, !0), h.setUint32(42, r, !0), m.set(c, 46), e.push(l, d), n.push(m), r += l.length + d.length, o += m.length;
774
- }
775
- if (r + o + 22 > 4294967295)
776
- throw new Error("图片包超过 4GB,请分批导出");
777
- const i = new Uint8Array(22), a = new DataView(i.buffer);
778
- return a.setUint32(0, 101010256, !0), a.setUint16(8, t.length, !0), a.setUint16(10, t.length, !0), a.setUint32(12, o, !0), a.setUint32(16, r, !0), new Blob([...e, ...n, i], { type: "application/zip" });
779
- }
780
- function Lt(t) {
781
- return new Promise((e, n) => t.toBlob((r) => r ? e(r) : n(new Error("图片编码失败,请重试导出")), "image/png"));
782
- }
783
- function It(t) {
784
- return new Promise((e, n) => {
785
- const r = new FileReader();
786
- r.onload = () => e(new Uint8Array(r.result)), r.onerror = () => n(new Error("图片读取失败,请重试导出")), r.readAsArrayBuffer(t);
787
- });
788
- }
789
- function Bt({ geometry: t, settings: e, headerCanvas: n, footerCanvas: r, totalPages: o, signal: i }) {
790
- const a = [];
791
- return {
792
- async addPageSlice(s, d, c) {
793
- var p, m, h, g;
794
- M(i);
795
- const u = document.createElement("canvas"), l = Math.min(d.width / t.contentWidth, Math.sqrt(8e6 / (t.pageWidth * t.pageHeight)), 8192 / t.pageWidth, 8192 / t.pageHeight);
796
- u.width = Math.ceil(t.pageWidth * l), u.height = Math.ceil(t.pageHeight * l);
52
+ async exportDocument(a) {
53
+ var t, n, g;
54
+ E(), l = !0;
55
+ const c = new AbortController(), r = () => c.abort();
56
+ s.signal.addEventListener("abort", r, { once: !0 }), (t = a.signal) == null || t.addEventListener("abort", r, { once: !0 }), ((n = a.signal) != null && n.aborted || s.signal.aborted) && c.abort();
797
57
  try {
798
- const f = u.getContext("2d");
799
- if (!f)
800
- throw new Error("浏览器无法生成分页图片");
801
- if (f.scale(l, l), f.fillStyle = "#fff", f.fillRect(0, 0, t.pageWidth, t.pageHeight), f.drawImage(d, t.left, t.bodyTop, t.contentWidth, c), n && f.drawImage(n, t.left, t.headerY, t.contentWidth, t.headerHeight), r && f.drawImage(r, t.left, t.footerY, t.contentWidth, t.footerHeight), ((p = e == null ? void 0 : e.pageNumber) == null ? void 0 : p.enabled) !== !1) {
802
- const x = (h = (m = e == null ? void 0 : e.pageNumber) == null ? void 0 : m.position) == null ? void 0 : h.endsWith("center");
803
- f.font = "9px sans-serif", f.fillStyle = "#787878", f.textAlign = x ? "center" : "right", f.fillText(rt(s, o, (g = e == null ? void 0 : e.pageNumber) == null ? void 0 : g.format), x ? t.pageWidth / 2 : t.pageWidth - T((e == null ? void 0 : e.marginRightMm) ?? 10), t.pageNumberY);
804
- }
805
- const b = await It(await Lt(u));
806
- M(i), a.push({ name: `page-${String(s + 1).padStart(Math.max(3, String(o).length), "0")}.png`, data: b });
58
+ return await L(e, { ...a, settings: m, signal: c.signal }, f);
807
59
  } finally {
808
- u.width = 0, u.height = 0;
809
- }
810
- },
811
- async finalize(s, d = !0) {
812
- M(i);
813
- const c = vt(a);
814
- if (M(i), d) {
815
- const u = URL.createObjectURL(c), l = document.createElement("a");
816
- l.href = u, l.download = `${s.replace(/\.(pdf|zip|png)$/i, "") || "document"}-pages.zip`, document.body.appendChild(l);
817
- try {
818
- l.click();
819
- } finally {
820
- l.remove(), setTimeout(() => URL.revokeObjectURL(u), 6e4);
821
- }
60
+ s.signal.removeEventListener("abort", r), (g = a.signal) == null || g.removeEventListener("abort", r), l = !1;
822
61
  }
823
- return c;
824
62
  },
825
63
  dispose() {
826
- a.length = 0;
64
+ var a;
65
+ u || (u = !0, s.abort(), i.dispose(), e.cleanup(), (a = o.signal) == null || a.removeEventListener("abort", P));
827
66
  }
828
67
  };
829
68
  }
830
- const it = {
831
- pdf: kt,
832
- png: Bt
833
- };
834
- function at(t) {
835
- if (!Object.prototype.hasOwnProperty.call(it, t))
836
- throw new Error(`不支持的输出格式:${t}`);
837
- }
838
- function Ft(t, e) {
839
- return at(t), it[t](e);
840
- }
841
- async function _t({ format: t = "pdf", filename: e, download: n = !0, onProgress: r, ...o }) {
842
- var g;
843
- at(t);
844
- const i = performance.now(), a = await ot(o), { root: s, headerHeight: d, footerHeight: c, ratio: u, pages: l } = a, p = performance.now() - i;
845
- let m, h;
846
- try {
847
- m = At(a.width, o.signal);
848
- const { capture: f, release: b } = m, x = a.header ? await f(a.header, 0, d / u) : void 0, y = a.footer ? await f(a.footer, 0, c / u) : void 0;
849
- h = await Ft(t, {
850
- signal: o.signal,
851
- geometry: a,
852
- settings: o.settings,
853
- headerCanvas: x,
854
- footerCanvas: y,
855
- totalPages: l.length
856
- }), r == null || r(0, l.length);
857
- for (let E = 0; E < l.length; E++) {
858
- M(o.signal);
859
- const w = l[E], B = await f(s, w.start, w.end - w.start);
860
- try {
861
- await h.addPageSlice(E, B, (w.end - w.start) * u);
862
- } finally {
863
- b(B);
864
- }
865
- r == null || r(E + 1, l.length), await new Promise((N) => setTimeout(N, 0));
866
- }
867
- M(o.signal);
868
- const P = await h.finalize(e, n);
869
- return {
870
- blob: P,
871
- pages: l.length,
872
- layoutMs: p,
873
- totalMs: performance.now() - i,
874
- bytes: P.size
875
- };
876
- } finally {
877
- (g = h == null ? void 0 : h.dispose) == null || g.call(h), m == null || m.dispose(), a.cleanup();
878
- }
879
- }
880
- function ne(t) {
881
- return _t({ ...t, format: "pdf" });
882
- }
883
- async function $t({
884
- contentElement: t,
885
- ...e
886
- }) {
887
- var i, a;
888
- const n = performance.now(), r = nt(t), o = await ot({ element: r, ...e });
889
- try {
890
- const s = o.pages.map((l) => l.start), d = e.rules || (e.ruleConfig ? I(e.ruleConfig) : S()), c = tt(o.root, o.capacity, d);
891
- bt(o.pages, c.ranges);
892
- const u = {
893
- pageBreaks: s,
894
- pages: o.pages,
895
- totalHeight: c.height,
896
- capacity: o.capacity,
897
- protectedRanges: c.ranges,
898
- stats: o.stats,
899
- timing: {
900
- measurementMs: ((i = o.timing) == null ? void 0 : i.measurementMs) ?? 0,
901
- paginationMs: ((a = o.timing) == null ? void 0 : a.paginationMs) ?? 0,
902
- totalMs: performance.now() - n
903
- }
904
- };
905
- return window.dispatchEvent(new CustomEvent("print-inspection", { detail: u })), window.dispatchEvent(new CustomEvent("pdf-print-inspection", { detail: u })), u;
906
- } finally {
907
- o.cleanup();
908
- }
909
- }
910
- async function oe(t) {
911
- return (await $t(t)).pageBreaks;
912
- }
913
- const z = /* @__PURE__ */ new Map();
914
- function Ot(t) {
915
- (t || document).querySelectorAll("[data-print-debug]").forEach((n) => n.remove());
916
- for (const [n, r] of Array.from(z))
917
- (!t || t === n || t.nodeType === 9 && n.ownerDocument === t) && (r(), z.delete(n));
918
- }
919
- function ie(t, e, n = S()) {
920
- var c;
921
- Ot(e);
922
- const r = {
923
- atomic: 0,
924
- splittable: 0,
925
- ignore: 0
926
- }, o = ((c = e.ownerDocument) == null ? void 0 : c.defaultView) || (typeof window < "u" ? window : null), i = o != null && o.getComputedStyle ? o.getComputedStyle(e) : null;
927
- if (i && i.position === "static") {
928
- const u = e.style.getPropertyValue("position"), l = e.style.getPropertyPriority("position");
929
- e.style.position = "relative", z.set(e, () => {
930
- u ? e.style.setProperty("position", u, l) : e.style.removeProperty("position");
931
- });
932
- }
933
- const a = e.getBoundingClientRect(), s = i && parseFloat(i.borderTopWidth) || 0, d = i && parseFloat(i.borderLeftWidth) || 0;
934
- return V(e, (u) => {
935
- if (u.nodeType !== 1)
936
- return "skip";
937
- const l = u;
938
- if (l.hasAttribute("data-print-debug"))
939
- return "skip";
940
- const p = L(l, n);
941
- if (p.kind === "ignore") {
942
- r.ignore++;
943
- const f = l.getBoundingClientRect();
944
- return f.width > 0 && f.height > 0 && e.appendChild(
945
- W({
946
- left: f.left - a.left - d,
947
- top: f.top - a.top - s,
948
- width: f.width,
949
- height: f.height,
950
- borderColor: "#94a3b8",
951
- borderStyle: "dashed",
952
- backgroundColor: "rgba(148, 163, 184, 0.08)",
953
- badgeText: "ignore",
954
- badgeBg: "#64748b",
955
- badgePosition: "left"
956
- })
957
- ), "skip";
958
- }
959
- const m = l.getBoundingClientRect();
960
- if (m.width <= 0 || m.height <= 0)
961
- return "skip";
962
- if (p.kind === "atomic")
963
- return r.atomic++, e.appendChild(
964
- W({
965
- left: m.left - a.left - d,
966
- top: m.top - a.top - s,
967
- width: m.width,
968
- height: m.height,
969
- borderColor: "#ef4444",
970
- borderStyle: "solid",
971
- backgroundColor: "rgba(239, 68, 68, 0.05)",
972
- badgeText: "atomic",
973
- badgeBg: "#ef4444",
974
- badgePosition: "right"
975
- })
976
- ), "skip";
977
- if (Dt(l, o))
978
- return "skip";
979
- const h = l.matches(Ut), g = Wt(l);
980
- return h || g ? (r.splittable++, e.appendChild(
981
- W({
982
- left: m.left - a.left - d,
983
- top: m.top - a.top - s,
984
- width: m.width,
985
- height: m.height,
986
- borderColor: "#3b82f6",
987
- borderStyle: "dashed",
988
- backgroundColor: "rgba(59, 130, 246, 0.04)",
989
- badgeText: "splittable",
990
- badgeBg: "#3b82f6",
991
- badgePosition: "right"
992
- })
993
- ), h ? "descend" : "skip") : "descend";
994
- }), t.slice(1).forEach((u, l) => {
995
- const p = u - s, m = e.ownerDocument.createElement("div");
996
- m.setAttribute("data-print-debug", "true"), m.style.cssText = `
997
- position: absolute;
998
- left: 0;
999
- top: ${p}px;
1000
- width: 100%;
1001
- height: 0;
1002
- border-top: 2px dashed #7c3aed;
1003
- z-index: ${G.line};
1004
- pointer-events: none;
1005
- box-sizing: border-box;
1006
- `;
1007
- const h = e.ownerDocument.createElement("span");
1008
- h.textContent = `✂️ page-break: ${Math.round(u)}px (p.${l + 1} ➔ p.${l + 2})`, h.style.cssText = `
1009
- position: absolute;
1010
- right: 16px;
1011
- top: -11px;
1012
- background: #7c3aed;
1013
- color: #fff;
1014
- font-size: 11px;
1015
- font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
1016
- line-height: 1;
1017
- padding: 3px 8px;
1018
- border-radius: 10px;
1019
- font-weight: 600;
1020
- letter-spacing: 0.2px;
1021
- box-shadow: 0 1px 4px rgba(124, 58, 237, 0.35);
1022
- white-space: nowrap;
1023
- `, m.appendChild(h), e.appendChild(m);
1024
- }), r;
1025
- }
1026
- const Ut = '[data-print-splittable="true"], .print-splittable, [data-print-break="split"], .print-force-split, [data-pdf-splittable="true"], .pdf-splittable, [data-pdf-break="split"], .pdf-force-split', G = { box: 2, badge: 3, line: 4 }, Ht = /* @__PURE__ */ new Set([
1027
- "SPAN",
1028
- "B",
1029
- "STRONG",
1030
- "EM",
1031
- "I",
1032
- "CODE",
1033
- "A",
1034
- "SMALL",
1035
- "SUP",
1036
- "SUB",
1037
- "MARK",
1038
- "ABBR",
1039
- "CITE",
1040
- "Q",
1041
- "TIME",
1042
- "U",
1043
- "S",
1044
- "KBD",
1045
- "SAMP",
1046
- "VAR",
1047
- "BR"
1048
- ]);
1049
- function Wt(t) {
1050
- var e;
1051
- for (let n = 0; n < t.childNodes.length; n++) {
1052
- const r = t.childNodes[n];
1053
- if (r.nodeType === 3 && ((e = r.textContent) != null && e.trim()))
1054
- return !0;
1055
- }
1056
- return !1;
1057
- }
1058
- function Dt(t, e) {
1059
- return Ht.has(t.tagName) ? !0 : e != null && e.getComputedStyle ? e.getComputedStyle(t).display.startsWith("inline") : !1;
1060
- }
1061
- function W(t) {
1062
- const e = document.createElement("div");
1063
- e.setAttribute("data-print-debug", "true"), e.style.cssText = `
1064
- position: absolute;
1065
- left: ${t.left}px;
1066
- top: ${t.top}px;
1067
- width: ${t.width}px;
1068
- height: ${t.height}px;
1069
- border: 1.5px ${t.borderStyle} ${t.borderColor};
1070
- background: ${t.backgroundColor};
1071
- box-sizing: border-box;
1072
- z-index: ${G.box};
1073
- pointer-events: none;
1074
- border-radius: 2px;
1075
- `;
1076
- const n = document.createElement("span");
1077
- n.textContent = t.badgeText;
1078
- const r = t.badgePosition === "right", o = "2px", i = r ? "right: 4px;" : "left: 4px;";
1079
- return n.style.cssText = `
1080
- position: absolute;
1081
- ${i}
1082
- top: ${o};
1083
- background: ${t.badgeBg};
1084
- color: #ffffff;
1085
- font-size: 9px;
1086
- font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
1087
- font-weight: 600;
1088
- line-height: 1;
1089
- padding: 1.5px 5px;
1090
- border-radius: 3px;
1091
- white-space: nowrap;
1092
- box-shadow: 0 1px 2px rgba(0,0,0,0.18);
1093
- z-index: ${G.badge};
1094
- opacity: 0.95;
1095
- letter-spacing: 0.2px;
1096
- `, e.appendChild(n), e;
1097
- }
1098
69
  export {
1099
- D as BASE_PRINT_RULES,
1100
- xt as DEFAULT_PRINT_RULES,
1101
- pt as DEFAULT_SETTINGS,
1102
- Gt as IMAGE_PAPERS,
1103
- U as IMAGE_PAPER_SIZES,
1104
- v as MM_PER_PX,
1105
- q as PAPER_PRESETS,
1106
- Q as PAPER_SIZES,
1107
- Xt as PDF_PRINT_ATTRIBUTES,
1108
- Zt as PDF_PRINT_CLASSES,
1109
- Kt as PRINT_ATTRIBUTES,
1110
- qt as PRINT_CLASSES,
1111
- dt as PT_PER_MM,
1112
- k as PX_PER_MM,
1113
- ht as UNIT_FIELDS,
1114
- I as buildPrintRules,
1115
- ft as calculateGeometry,
1116
- oe as calculatePagesArray,
1117
- M as checkCancelled,
1118
- L as classifyPrintNode,
1119
- Ot as clearPageBreaks,
1120
- Pt as cloneWithResolvedStyles,
1121
- Qt as configurePrint,
1122
- Yt as convertFields,
1123
- Tt as copyResolvedStyle,
1124
- Z as createDeclarativeElement,
1125
- Ft as createOutputWriter,
1126
- At as createPageCapture,
1127
- kt as createPdfWriter,
1128
- Rt as createPrintSnapshot,
1129
- J as createTextMeasurer,
1130
- rt as formatPageNumber,
1131
- Vt as getPresetDimensions,
1132
- jt as getPresetUnit,
1133
- S as getPrintRules,
1134
- $t as inspectPrintLayout,
1135
- ut as isImagePaper,
1136
- O as isPrintableElement,
1137
- tt as measureDocument,
1138
- te as measureTextLines,
1139
- T as mmToPt,
1140
- re as namespacePreviewHtml,
1141
- _t as outputDocument,
1142
- ne as outputPDF,
1143
- gt as paginate,
1144
- Nt as planDocument,
1145
- ot as prepareLayout,
1146
- Et as readRootHeight,
1147
- Jt as resetPrintRules,
1148
- X as resolveAtomicOverflow,
1149
- mt as resolvePaper,
1150
- nt as resolvePrintElement,
1151
- ee as serializePrintSnapshot,
1152
- at as validateOutputFormat,
1153
- bt as validatePageBreaks,
1154
- ie as visualizePageBreaks,
1155
- et as waitForResources,
1156
- V as walkPrintTree
70
+ C as BASE_PRINT_RULES,
71
+ F as DEFAULT_PRINT_RULES,
72
+ U as DEFAULT_SETTINGS,
73
+ B as IMAGE_PAPERS,
74
+ k as IMAGE_PAPER_SIZES,
75
+ x as MM_PER_PX,
76
+ O as PAPER_PRESETS,
77
+ G as PAPER_SIZES,
78
+ H as PDF_PRINT_ATTRIBUTES,
79
+ W as PDF_PRINT_CLASSES,
80
+ z as PRINT_ATTRIBUTES,
81
+ J as PRINT_CLASSES,
82
+ X as PT_PER_MM,
83
+ Z as PX_PER_MM,
84
+ j as UNIT_FIELDS,
85
+ q as buildPrintRules,
86
+ K as calculateGeometry,
87
+ Q as calculatePagesArray,
88
+ b as checkCancelled,
89
+ V as classifyPrintNode,
90
+ Y as clearPageBreaks,
91
+ $ as cloneWithResolvedStyles,
92
+ ee as configurePrint,
93
+ ae as convertFields,
94
+ te as copyResolvedStyle,
95
+ re as createDeclarativeElement,
96
+ se as createOutputWriter,
97
+ T as createPageCapture,
98
+ ne as createPdfWriter,
99
+ D as createPrintSession,
100
+ oe as createPrintSnapshot,
101
+ ie as createTextMeasurer,
102
+ L as exportPreparedLayout,
103
+ le as formatPageNumber,
104
+ ce as getPresetDimensions,
105
+ ge as getPresetUnit,
106
+ Pe as getPrintRules,
107
+ ue as inspectPrintLayout,
108
+ de as isImagePaper,
109
+ he as isPrintableElement,
110
+ me as measureDocument,
111
+ Ee as measureTextLines,
112
+ fe as mmToPt,
113
+ pe as namespacePreviewHtml,
114
+ we as outputDocument,
115
+ ve as outputPDF,
116
+ Se as paginate,
117
+ be as planDocument,
118
+ R as prepareLayout,
119
+ ye as readRootHeight,
120
+ Re as resetPrintRules,
121
+ Te as resolveAtomicOverflow,
122
+ _e as resolvePaper,
123
+ Le as resolvePrintElement,
124
+ Ae as serializePrintSnapshot,
125
+ Ie as validateOutputFormat,
126
+ De as validatePageBreaks,
127
+ Me as visualizePageBreaks,
128
+ Ne as waitForResources,
129
+ Ce as walkPrintTree
1157
130
  };
1158
131
  //# sourceMappingURL=index.mjs.map