@paprize/core 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1478 @@
1
+ const fe = "paprize", _e = "pz-temp-container", ot = "pz-current-element", rt = "pz-current-text", st = "pz-ignored-element", at = "pz-ignored-text", K = "paprize-global-style", U = "pz-page", ve = "pz-section", T = "pz-preview", C = "data-pz-";
2
+ let re = !1;
3
+ const lt = () => {
4
+ re = !0;
5
+ }, V = () => re;
6
+ function se(i) {
7
+ return i.nodeType === Node.ELEMENT_NODE;
8
+ }
9
+ function be(i) {
10
+ return i.nodeType === Node.TEXT_NODE;
11
+ }
12
+ function z(i) {
13
+ const e = i.getBoundingClientRect(), t = getComputedStyle(i), n = parseFloat(t.marginTop) || 0, o = parseFloat(t.marginBottom) || 0;
14
+ return e.height + n + o;
15
+ }
16
+ function ye(i) {
17
+ i.style.visibility = "hidden", i.style.position = "absolute", i.style.left = "-9999px", i.style.top = "-9999px";
18
+ }
19
+ const ae = {
20
+ hyphen: "-",
21
+ keepOnSamePage: !1,
22
+ hyphenationDisabled: !1
23
+ }, le = {
24
+ hyphen: {
25
+ key: `${C}hyphen`,
26
+ reader: (i) => String(i)
27
+ },
28
+ keepOnSamePage: {
29
+ key: `${C}keep-on-same-page`,
30
+ reader: (i) => i === "true"
31
+ },
32
+ hyphenationDisabled: {
33
+ key: `${C}hyphenation-disabled`,
34
+ reader: (i) => i === "true"
35
+ }
36
+ };
37
+ function ct(i) {
38
+ const e = {};
39
+ for (const [t, n] of Object.entries(i)) {
40
+ const o = le[t];
41
+ o !== void 0 && n !== void 0 && (e[o.key] = String(n));
42
+ }
43
+ return e;
44
+ }
45
+ const Y = /* @__PURE__ */ new WeakMap();
46
+ function we(i, e, t, n) {
47
+ if (t == null)
48
+ return;
49
+ const o = e(t);
50
+ o !== void 0 && (n[i] = o);
51
+ }
52
+ function ce(i) {
53
+ if (!i)
54
+ return {};
55
+ if (!(i instanceof Element))
56
+ return ce(i?.parentNode);
57
+ const e = {};
58
+ for (const o of Object.keys(ae)) {
59
+ const r = o, s = le[r], d = i.getAttribute(s.key);
60
+ we(r, s.reader, d, e);
61
+ }
62
+ const n = { ...i.parentNode ? Y.get(i.parentNode) : void 0, ...e };
63
+ return Y.set(i, n), n;
64
+ }
65
+ const de = {
66
+ id: "default",
67
+ plugins: [],
68
+ ...ae
69
+ };
70
+ function Se(i, e) {
71
+ const t = ce(i);
72
+ return { ...de, ...e, ...t };
73
+ }
74
+ function Ce(i) {
75
+ return i && i.__esModule && Object.prototype.hasOwnProperty.call(i, "default") ? i.default : i;
76
+ }
77
+ var $ = { exports: {} }, Ne = $.exports, Q;
78
+ function xe() {
79
+ return Q || (Q = 1, (function(i) {
80
+ (function(e, t) {
81
+ i.exports ? i.exports = t() : e.log = t();
82
+ })(Ne, function() {
83
+ var e = function() {
84
+ }, t = "undefined", n = typeof window !== t && typeof window.navigator !== t && /Trident\/|MSIE /.test(window.navigator.userAgent), o = [
85
+ "trace",
86
+ "debug",
87
+ "info",
88
+ "warn",
89
+ "error"
90
+ ], r = {}, s = null;
91
+ function d(l, p) {
92
+ var a = l[p];
93
+ if (typeof a.bind == "function")
94
+ return a.bind(l);
95
+ try {
96
+ return Function.prototype.bind.call(a, l);
97
+ } catch {
98
+ return function() {
99
+ return Function.prototype.apply.apply(a, [l, arguments]);
100
+ };
101
+ }
102
+ }
103
+ function P() {
104
+ console.log && (console.log.apply ? console.log.apply(console, arguments) : Function.prototype.apply.apply(console.log, [console, arguments])), console.trace && console.trace();
105
+ }
106
+ function b(l) {
107
+ return l === "debug" && (l = "log"), typeof console === t ? !1 : l === "trace" && n ? P : console[l] !== void 0 ? d(console, l) : console.log !== void 0 ? d(console, "log") : e;
108
+ }
109
+ function f() {
110
+ for (var l = this.getLevel(), p = 0; p < o.length; p++) {
111
+ var a = o[p];
112
+ this[a] = p < l ? e : this.methodFactory(a, l, this.name);
113
+ }
114
+ if (this.log = this.debug, typeof console === t && l < this.levels.SILENT)
115
+ return "No console available for logging";
116
+ }
117
+ function _(l) {
118
+ return function() {
119
+ typeof console !== t && (f.call(this), this[l].apply(this, arguments));
120
+ };
121
+ }
122
+ function j(l, p, a) {
123
+ return b(l) || _.apply(this, arguments);
124
+ }
125
+ function J(l, p) {
126
+ var a = this, H, W, y, m = "loglevel";
127
+ typeof l == "string" ? m += ":" + l : typeof l == "symbol" && (m = void 0);
128
+ function ue(c) {
129
+ var u = (o[c] || "silent").toUpperCase();
130
+ if (!(typeof window === t || !m)) {
131
+ try {
132
+ window.localStorage[m] = u;
133
+ return;
134
+ } catch {
135
+ }
136
+ try {
137
+ window.document.cookie = encodeURIComponent(m) + "=" + u + ";";
138
+ } catch {
139
+ }
140
+ }
141
+ }
142
+ function G() {
143
+ var c;
144
+ if (!(typeof window === t || !m)) {
145
+ try {
146
+ c = window.localStorage[m];
147
+ } catch {
148
+ }
149
+ if (typeof c === t)
150
+ try {
151
+ var u = window.document.cookie, O = encodeURIComponent(m), X = u.indexOf(O + "=");
152
+ X !== -1 && (c = /^([^;]+)/.exec(
153
+ u.slice(X + O.length + 1)
154
+ )[1]);
155
+ } catch {
156
+ }
157
+ return a.levels[c] === void 0 && (c = void 0), c;
158
+ }
159
+ }
160
+ function he() {
161
+ if (!(typeof window === t || !m)) {
162
+ try {
163
+ window.localStorage.removeItem(m);
164
+ } catch {
165
+ }
166
+ try {
167
+ window.document.cookie = encodeURIComponent(m) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
168
+ } catch {
169
+ }
170
+ }
171
+ }
172
+ function E(c) {
173
+ var u = c;
174
+ if (typeof u == "string" && a.levels[u.toUpperCase()] !== void 0 && (u = a.levels[u.toUpperCase()]), typeof u == "number" && u >= 0 && u <= a.levels.SILENT)
175
+ return u;
176
+ throw new TypeError("log.setLevel() called with invalid level: " + c);
177
+ }
178
+ a.name = l, a.levels = {
179
+ TRACE: 0,
180
+ DEBUG: 1,
181
+ INFO: 2,
182
+ WARN: 3,
183
+ ERROR: 4,
184
+ SILENT: 5
185
+ }, a.methodFactory = p || j, a.getLevel = function() {
186
+ return y ?? W ?? H;
187
+ }, a.setLevel = function(c, u) {
188
+ return y = E(c), u !== !1 && ue(y), f.call(a);
189
+ }, a.setDefaultLevel = function(c) {
190
+ W = E(c), G() || a.setLevel(c, !1);
191
+ }, a.resetLevel = function() {
192
+ y = null, he(), f.call(a);
193
+ }, a.enableAll = function(c) {
194
+ a.setLevel(a.levels.TRACE, c);
195
+ }, a.disableAll = function(c) {
196
+ a.setLevel(a.levels.SILENT, c);
197
+ }, a.rebuild = function() {
198
+ if (s !== a && (H = E(s.getLevel())), f.call(a), s === a)
199
+ for (var c in r)
200
+ r[c].rebuild();
201
+ }, H = E(
202
+ s ? s.getLevel() : "WARN"
203
+ );
204
+ var Z = G();
205
+ Z != null && (y = E(Z)), f.call(a);
206
+ }
207
+ s = new J(), s.getLogger = function(p) {
208
+ if (typeof p != "symbol" && typeof p != "string" || p === "")
209
+ throw new TypeError("You must supply a name when creating a logger.");
210
+ var a = r[p];
211
+ return a || (a = r[p] = new J(
212
+ p,
213
+ s.methodFactory
214
+ )), a;
215
+ };
216
+ var pe = typeof window !== t ? window.log : void 0;
217
+ return s.noConflict = function() {
218
+ return typeof window !== t && window.log === s && (window.log = pe), s;
219
+ }, s.getLoggers = function() {
220
+ return r;
221
+ }, s.default = s, s;
222
+ });
223
+ })($)), $.exports;
224
+ }
225
+ var Pe = xe();
226
+ const S = /* @__PURE__ */ Ce(Pe), g = S.getLogger(fe);
227
+ g.setDefaultLevel("info");
228
+ const M = "\x1B[46mPLUGIN\x1B[0m";
229
+ function N(i, e, ...t) {
230
+ i.sort((n, o) => n.order - o.order).forEach((n) => {
231
+ const o = n[e];
232
+ if (o) {
233
+ g.debug(
234
+ M,
235
+ `executing plugin ${n.name}:${String(e)} ()`,
236
+ t
237
+ );
238
+ try {
239
+ o(...t), g.debug(
240
+ M,
241
+ `plugin ${n.name}:${String(e)} executed`,
242
+ t
243
+ );
244
+ } catch (r) {
245
+ g.debug(
246
+ M,
247
+ `plugin ${n.name}:${String(e)} failed`,
248
+ r
249
+ );
250
+ }
251
+ }
252
+ });
253
+ }
254
+ const x = {
255
+ Element: "element",
256
+ Text: "text"
257
+ };
258
+ class F {
259
+ _node;
260
+ config;
261
+ type = x.Element;
262
+ transaction;
263
+ clonedFrom;
264
+ cloneCount;
265
+ constructor(e, t, n, o) {
266
+ this._node = e, this.transaction = t, this.config = n, this.clonedFrom = o, this.cloneCount = o ? o.cloneCount + 1 : 0;
267
+ }
268
+ getOriginalNode() {
269
+ let e = this.clonedFrom;
270
+ for (; e?.clonedFrom; )
271
+ e = e.clonedFrom;
272
+ return e?._node;
273
+ }
274
+ appendChild(e) {
275
+ this.transaction.isActive && this.transaction.addRollbackCallback(() => {
276
+ this._node.removeChild(e.getNode());
277
+ }), this._node.appendChild(e.getNode());
278
+ }
279
+ clone(e) {
280
+ const t = this._node.cloneNode(e), n = new F(
281
+ t,
282
+ this.transaction,
283
+ this.config,
284
+ this
285
+ );
286
+ return N(
287
+ this.config.plugins,
288
+ "onClone",
289
+ this.config.id,
290
+ this._node,
291
+ n
292
+ ), n;
293
+ }
294
+ getHeight() {
295
+ return z(this._node);
296
+ }
297
+ remove() {
298
+ this.transaction.addCommitCallback(() => {
299
+ this._node.remove();
300
+ });
301
+ }
302
+ isEmpty() {
303
+ return this._node.innerHTML === "";
304
+ }
305
+ getChildrenCount() {
306
+ return this._node.childNodes.length;
307
+ }
308
+ getNode() {
309
+ return this._node;
310
+ }
311
+ }
312
+ class Ee {
313
+ _node;
314
+ type = x.Text;
315
+ transaction;
316
+ config;
317
+ constructor(e, t, n) {
318
+ this._node = e, this.transaction = t, this.config = n;
319
+ }
320
+ get textContent() {
321
+ return this._node.textContent ?? "";
322
+ }
323
+ set textContent(e) {
324
+ this._node.textContent = e;
325
+ }
326
+ remove() {
327
+ this.transaction.addCommitCallback(() => {
328
+ this._node.remove();
329
+ });
330
+ }
331
+ getNode() {
332
+ return this._node;
333
+ }
334
+ }
335
+ function B(i, e, t) {
336
+ if (be(i))
337
+ return new Ee(i, e, t);
338
+ if (se(i))
339
+ return new F(i, e, t);
340
+ throw new Error("Unsupported node type");
341
+ }
342
+ const k = "\x1B[106mDOM\x1B[0m";
343
+ class Te {
344
+ _transaction;
345
+ _treeWalker;
346
+ _config;
347
+ _completed = !1;
348
+ _currentNode = null;
349
+ _previousNode = null;
350
+ constructor(e, t, n) {
351
+ this._transaction = t, this._config = n, this._treeWalker = document.createTreeWalker(
352
+ e,
353
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT
354
+ );
355
+ }
356
+ get completed() {
357
+ return this._completed;
358
+ }
359
+ get currentNode() {
360
+ return this._currentNode;
361
+ }
362
+ get previousNode() {
363
+ return this._previousNode;
364
+ }
365
+ goToNextNode() {
366
+ this._treeWalker.nextNode() || (this._completed = !0), g.debug(k, "moving to next node"), this.setState();
367
+ }
368
+ goToNextSiblingOrParentSibling() {
369
+ let e = 0;
370
+ if (this._treeWalker.nextSibling())
371
+ return g.debug(k, "moving to next sibling node"), this.setState(), { parentsTraversed: e };
372
+ for (; this._treeWalker.parentNode(); )
373
+ if (e++, this._treeWalker.nextSibling())
374
+ return g.debug(
375
+ k,
376
+ "moving to parent sibling node, traversed:",
377
+ e
378
+ ), this.setState(), { parentsTraversed: e };
379
+ return this._completed = !0, { parentsTraversed: e };
380
+ }
381
+ goToFirstChildOrNextNode() {
382
+ return this._treeWalker.firstChild() ? (g.debug(k, "moving to first child node"), this.setState(), { parentsTraversed: 1 }) : (this.goToNextNode(), { parentsTraversed: 0 });
383
+ }
384
+ setState() {
385
+ this._previousNode = this._currentNode, this._currentNode = B(
386
+ this._treeWalker.currentNode,
387
+ this._transaction,
388
+ Se(this._treeWalker.currentNode, this._config)
389
+ ), g.debug(k, "moved to node", {
390
+ currentNode: this._currentNode,
391
+ previousNode: this._previousNode
392
+ });
393
+ }
394
+ }
395
+ class ke {
396
+ _onRollback;
397
+ _onCommit;
398
+ isActive;
399
+ constructor() {
400
+ this._onRollback = [], this._onCommit = [], this.isActive = !1;
401
+ }
402
+ start = () => {
403
+ if (this.isActive)
404
+ throw new Error("Transaction already in progress");
405
+ this.isActive = !0, this._onRollback = [], this._onCommit = [];
406
+ };
407
+ addRollbackCallback = (e) => {
408
+ this._onRollback.push(e);
409
+ };
410
+ addCommitCallback = (e) => {
411
+ if (!this.isActive) {
412
+ e();
413
+ return;
414
+ }
415
+ this._onCommit.push(e);
416
+ };
417
+ rollback = () => {
418
+ this.isActive && (this.isActive = !1, this._onRollback.forEach((e) => e()));
419
+ };
420
+ commit = () => {
421
+ this.isActive && (this.isActive = !1, this._onCommit.forEach((e) => e()));
422
+ };
423
+ }
424
+ const ee = "\x1B[102mPAGE\x1B[0m";
425
+ class I {
426
+ currentPage;
427
+ activeElement;
428
+ currentElement;
429
+ parentStack;
430
+ pageIsFull;
431
+ pageIndex;
432
+ pageHeight;
433
+ constructor(e, t, n, o, r, s, d) {
434
+ this.currentPage = e, this.activeElement = t, this.currentElement = n, this.parentStack = o, this.pageIsFull = r, this.pageIndex = s, this.pageHeight = d;
435
+ }
436
+ static create(e, t, n, o) {
437
+ return new I(
438
+ e,
439
+ null,
440
+ e,
441
+ t,
442
+ !1,
443
+ n,
444
+ o
445
+ );
446
+ }
447
+ clone = () => new I(
448
+ this.currentPage,
449
+ this.activeElement,
450
+ this.currentElement,
451
+ [...this.parentStack],
452
+ this.pageIsFull,
453
+ this.pageIndex,
454
+ this.pageHeight
455
+ );
456
+ }
457
+ class q {
458
+ _pageState;
459
+ _transaction;
460
+ _tempContainer;
461
+ _config;
462
+ constructor(e, t, n, o) {
463
+ this._tempContainer = e, this._config = o, this._transaction = n;
464
+ const r = q.createPageHtmlElement(
465
+ t.width
466
+ ), s = this.createNewPage(r);
467
+ this._pageState = I.create(s, [], 0, t.height), N(this._config.plugins, "onNewPage", o.id, this);
468
+ }
469
+ nextPage() {
470
+ const e = this.createNewPage(
471
+ this._pageState.currentPage.getNode().cloneNode(!1)
472
+ ), t = I.create(
473
+ e,
474
+ [],
475
+ this._pageState.pageIndex + 1,
476
+ this._pageState.pageHeight
477
+ );
478
+ this.cloneParentStackToNewPage(t), this.cleanupEmptyParent(), this._pageState = t, N(
479
+ this._config.plugins,
480
+ "onNewPage",
481
+ this._config.id,
482
+ this
483
+ );
484
+ }
485
+ cloneParentStackToNewPage(e) {
486
+ for (const t of this._pageState.parentStack) {
487
+ const n = t.clone(!1);
488
+ e.currentElement.appendChild(n), e.currentElement = n, e.parentStack.push(n);
489
+ }
490
+ }
491
+ cleanupEmptyParent() {
492
+ const e = [...this._pageState.parentStack], t = () => {
493
+ for (let n = e.length - 1; n >= 0; n--) {
494
+ const o = e[n];
495
+ o.isEmpty() && o.remove();
496
+ }
497
+ };
498
+ this._transaction.addCommitCallback(t);
499
+ }
500
+ enterElement() {
501
+ if (!this._pageState.activeElement || this._pageState.activeElement.type !== x.Element)
502
+ throw new Error("Invalid state: activeElement is not an Element");
503
+ g.debug(
504
+ ee,
505
+ "entering an element",
506
+ this._pageState.activeElement
507
+ ), this._pageState.currentElement = this._pageState.activeElement, this._pageState.parentStack.push(this._pageState.activeElement);
508
+ }
509
+ leaveElement() {
510
+ this._pageState.activeElement = null;
511
+ const e = this._pageState.parentStack.pop();
512
+ g.debug(ee, "leaving a parent element", e);
513
+ const t = this._pageState.parentStack.at(-1);
514
+ this._pageState.currentElement = t ?? this._pageState.currentPage;
515
+ }
516
+ static createPageHtmlElement(e) {
517
+ const t = document.createElement("div");
518
+ return t.style.width = `${e}px`, t.style.maxWidth = `${e}px`, t;
519
+ }
520
+ createNewPage(e) {
521
+ return this._tempContainer.appendChild(e), this._transaction.isActive && this._transaction.addRollbackCallback(() => {
522
+ this._tempContainer.removeChild(e);
523
+ }), B(e, this._transaction, this._config);
524
+ }
525
+ startTransaction() {
526
+ this._transaction.start();
527
+ const e = this._pageState.clone();
528
+ return this._transaction.addRollbackCallback(() => {
529
+ this._pageState = e;
530
+ }), this._transaction;
531
+ }
532
+ hasEmptySpace(e) {
533
+ return !this._pageState.pageIsFull && this._pageState.currentPage.getHeight() + (e || 1e-4) <= this._pageState.pageHeight;
534
+ }
535
+ isOverFlow() {
536
+ return this._pageState.currentPage.getHeight() > this._pageState.pageHeight;
537
+ }
538
+ markPageAsFull() {
539
+ this._pageState.pageIsFull = !0;
540
+ }
541
+ appendChild(e, t) {
542
+ const n = e.clone(t);
543
+ return this._pageState.currentElement.appendChild(n), this._pageState.activeElement = n, n;
544
+ }
545
+ addTextNode(e) {
546
+ if (this._pageState.activeElement?.type === x.Text)
547
+ return this._pageState.activeElement;
548
+ const t = document.createTextNode(e), n = B(
549
+ t,
550
+ this._transaction,
551
+ this._config
552
+ );
553
+ return this._pageState.currentElement.appendChild(n), this._pageState.activeElement = n, n;
554
+ }
555
+ getPageState() {
556
+ return this._pageState;
557
+ }
558
+ }
559
+ const h = {
560
+ None: 0,
561
+ // The node fits completely on the page, no further splitting required.
562
+ FullNodePlaced: 1,
563
+ // The entire node was placed on the page, continue with the next sibling or element.
564
+ SplitChildren: 2
565
+ // The node is too large for the page, and its children must be paginated individually.
566
+ };
567
+ function Ae(i, e) {
568
+ const t = te(i, e);
569
+ if (t !== h.None)
570
+ return t;
571
+ const { rollback: n, commit: o } = e.startTransaction();
572
+ e.nextPage();
573
+ const r = te(i, e);
574
+ return r !== h.None ? (o(), r) : (n(), g.debug("Element is too big to fit on a page", i), h.None);
575
+ }
576
+ function te(i, e) {
577
+ if (e.hasEmptySpace(i.getHeight())) {
578
+ const n = e.appendChild(i, !0);
579
+ if (e.isOverFlow())
580
+ n.remove();
581
+ else
582
+ return h.FullNodePlaced;
583
+ }
584
+ if (i.config.keepOnSamePage || i.getChildrenCount() === 0)
585
+ return h.None;
586
+ const t = e.appendChild(i, !1);
587
+ return e.isOverFlow() ? (t.remove(), h.None) : h.SplitChildren;
588
+ }
589
+ function Le(i, e) {
590
+ let t = h.FullNodePlaced;
591
+ const n = i.textContent.split(/(\s+)/).filter((s) => s !== "");
592
+ let o, r = 0;
593
+ for (; o || r < n.length; ) {
594
+ const s = o ?? n[r], d = Fe(s, e, i.config);
595
+ d.completed || (t = h.None), d.pendingToken ? o = d.pendingToken : (o = void 0, r++);
596
+ }
597
+ return t;
598
+ }
599
+ function Fe(i, e, t) {
600
+ e.hasEmptySpace() || e.nextPage();
601
+ const n = e.addTextNode(""), o = n.textContent;
602
+ if (n.textContent += i, !e.isOverFlow())
603
+ return {
604
+ completed: !0
605
+ };
606
+ n.textContent = o;
607
+ const r = Ie(i, e, t);
608
+ return {
609
+ pendingToken: r.leftovers,
610
+ completed: r.completed
611
+ };
612
+ }
613
+ function Ie(i, e, t) {
614
+ const { rollback: n, commit: o } = e.startTransaction();
615
+ if (e.nextPage(), e.addTextNode(i), !e.isOverFlow())
616
+ return o(), {
617
+ completed: !0
618
+ };
619
+ if (n(), t.hyphenationDisabled)
620
+ return g.warn("Hyphenation disabled, skipping oversized token:", i), {
621
+ completed: !1
622
+ };
623
+ const r = Re(i, t.hyphen, e);
624
+ return {
625
+ completed: !0,
626
+ leftovers: r && r.length > 0 ? r : void 0
627
+ };
628
+ }
629
+ function Re(i, e, t) {
630
+ const n = t.addTextNode("");
631
+ let o = "";
632
+ for (let r = 0; r < i.length; r++) {
633
+ const s = i[r], d = o + s;
634
+ if (n.textContent = d + e, !t.hasEmptySpace())
635
+ return n.textContent = o ? o + e : "", t.markPageAsFull(), i.slice(r);
636
+ o = d;
637
+ }
638
+ return null;
639
+ }
640
+ const A = "\x1B[103mPAGINATOR\x1B[0m";
641
+ class D {
642
+ _domState;
643
+ _pageManager;
644
+ _transaction;
645
+ _tempContainer;
646
+ _config;
647
+ constructor(e, t, n) {
648
+ this._config = { ...de, ...n }, this._tempContainer = D.createTempContainer(this._config.id), this._transaction = new ke(), this._domState = new Te(e, this._transaction, this._config), this._pageManager = new q(
649
+ this._tempContainer,
650
+ t,
651
+ this._transaction,
652
+ this._config
653
+ );
654
+ }
655
+ static createTempContainer(e) {
656
+ const t = document.createElement("div");
657
+ return t.style.display = "flex", t.style.flexDirection = "column", t.style.gap = "20px", t.setAttribute(`${C}-section-id`, e), t.classList.add(_e), V() || ye(t), document.body.appendChild(t), t;
658
+ }
659
+ static paginate(e, t, n) {
660
+ const o = new D(e, t, n);
661
+ o.processAllNodes();
662
+ const r = Array.from(o._tempContainer.childNodes).filter((s) => se(s)).map((s) => s.innerHTML);
663
+ return V() || o._tempContainer.remove(), r;
664
+ }
665
+ processAllNodes() {
666
+ this._domState.goToNextNode();
667
+ do {
668
+ S.debug(
669
+ A,
670
+ "paginating node",
671
+ this._domState.currentNode
672
+ );
673
+ const e = this.processCurrentNode();
674
+ switch (N(
675
+ this._config.plugins,
676
+ "afterVisitNode",
677
+ this._config.id,
678
+ e,
679
+ this._domState,
680
+ this._pageManager
681
+ ), e) {
682
+ case h.None:
683
+ this.handleNodeSkipped();
684
+ break;
685
+ case h.FullNodePlaced:
686
+ this.handleFullNodePlaced();
687
+ break;
688
+ case h.SplitChildren:
689
+ this.handleChildrenSplit();
690
+ break;
691
+ }
692
+ } while (this._domState.completed === !1);
693
+ S.debug(A, "pagination completed");
694
+ }
695
+ handleNodeSkipped() {
696
+ S.debug(A, "node skipped - couldn't paginate"), this._domState.goToNextNode();
697
+ }
698
+ handleFullNodePlaced() {
699
+ S.debug(A, "node fully paginated");
700
+ const { parentsTraversed: e } = this._domState.goToNextSiblingOrParentSibling();
701
+ for (let t = 0; t < e; t++)
702
+ this._pageManager.leaveElement();
703
+ }
704
+ handleChildrenSplit() {
705
+ S.debug(
706
+ A,
707
+ "node partially paginated - splitting children"
708
+ ), this._domState.goToFirstChildOrNextNode().parentsTraversed === 1 && this._domState.previousNode?.type === x.Element && this._pageManager.enterElement();
709
+ }
710
+ processCurrentNode() {
711
+ if (!this._domState.currentNode)
712
+ return h.None;
713
+ if (this._domState.currentNode.type === x.Element) {
714
+ const e = {};
715
+ return N(
716
+ this._config.plugins,
717
+ "onVisitElement",
718
+ this._config.id,
719
+ this._domState,
720
+ this._pageManager,
721
+ e
722
+ ), e.result !== void 0 ? e.result : Ae(
723
+ this._domState.currentNode,
724
+ this._pageManager
725
+ );
726
+ } else {
727
+ const e = {};
728
+ return N(
729
+ this._config.plugins,
730
+ "onVisitText",
731
+ this._config.id,
732
+ this._domState,
733
+ this._pageManager,
734
+ e
735
+ ), e.result !== void 0 ? e.result : Le(
736
+ this._domState.currentNode,
737
+ this._pageManager
738
+ );
739
+ }
740
+ }
741
+ }
742
+ class ge {
743
+ registry = /* @__PURE__ */ new Map();
744
+ addEventListener(e, t) {
745
+ const { registry: n } = this, o = new Set(n.get(e));
746
+ return o.add(t), n.set(e, o), () => this.removeEventListener(e, t);
747
+ }
748
+ removeEventListener(e, t) {
749
+ const { registry: n } = this, o = new Set(n.get(e));
750
+ o.delete(t), n.set(e, o);
751
+ }
752
+ async dispatch(e, ...t) {
753
+ const { registry: n } = this, o = n.get(e);
754
+ if (o)
755
+ for (const r of o)
756
+ await r(...t);
757
+ }
758
+ }
759
+ const dt = {
760
+ /** 841mm x 594mm */
761
+ A1: { height: "841mm", width: "594mm" },
762
+ /** 594mm x 420mm */
763
+ A2: { height: "594mm", width: "420mm" },
764
+ /** 420mm x 297mm */
765
+ A3: { height: "420mm", width: "297mm" },
766
+ /** 297mm x 210mm */
767
+ A4: { height: "297mm", width: "210mm" },
768
+ /** 210mm x 148mm */
769
+ A5: { height: "210mm", width: "148mm" },
770
+ /** 148mm x 105mm */
771
+ A6: { height: "148mm", width: "105mm" },
772
+ /** 500mm x 353mm */
773
+ B3: { height: "500mm", width: "353mm" },
774
+ /** 353mm x 250mm */
775
+ B4: { height: "353mm", width: "250mm" },
776
+ /** 250mm x 176mm */
777
+ B5: { height: "250mm", width: "176mm" },
778
+ /** 8.5in x 11in */
779
+ Letter: { height: "8.5in", width: "11in" },
780
+ /** 11in x 8.5in */
781
+ Legal: { height: "11in", width: "8.5in" },
782
+ /** 11in x 17in */
783
+ Tabloid: { height: "11in", width: "17in" }
784
+ }, He = {
785
+ /** Top, Right, Bottom, Left: 1in */
786
+ Normal: {
787
+ top: "1in",
788
+ right: "1in",
789
+ bottom: "1in",
790
+ left: "1in"
791
+ },
792
+ /** Top: 0.4in, Right, Bottom, Left: 0.6in */
793
+ Narrow: {
794
+ top: "0.4in",
795
+ right: "0.6in",
796
+ bottom: "0.6in",
797
+ left: "0.6in"
798
+ },
799
+ /** Top, Bottom: 0.5in, Right, Left: 2in */
800
+ Wide: {
801
+ top: "0.5in",
802
+ right: "2in",
803
+ bottom: "0.5in",
804
+ left: "2in"
805
+ },
806
+ /** Top, Right, Bottom, Left: 0 */
807
+ None: {
808
+ top: "0in",
809
+ right: "0in",
810
+ bottom: "0in",
811
+ left: "0in"
812
+ }
813
+ }, Oe = "__PAPRIZE_IS_INITIALIZED", ne = "__PAPRIZE_IS_READY", ie = "__PAPRIZE_READ_JSON_DATA_FILE";
814
+ function $e(i) {
815
+ const e = i.getBoundingClientRect(), t = getComputedStyle(i), n = parseFloat(t.marginLeft) || 0, o = parseFloat(t.marginRight) || 0;
816
+ return {
817
+ height: z(i),
818
+ width: e.width + n + o
819
+ };
820
+ }
821
+ function ze(i, e, t) {
822
+ const { height: n, width: o } = $e(i), r = e ? z(e) : 0, s = t ? z(t) : 0;
823
+ return { height: n, width: o, sectionHeaderHeight: r, sectionFooterHeight: s };
824
+ }
825
+ function Be(i, e, t) {
826
+ return {
827
+ name: "sectionPageHeight",
828
+ order: 1,
829
+ afterVisitNode: (n, o, r, s) => {
830
+ !r.completed || t <= 0 || s.hasEmptySpace(t) || s.nextPage();
831
+ },
832
+ onNewPage: (n, o) => {
833
+ const r = o.getPageState();
834
+ r.pageIndex === 0 ? r.pageHeight = i + t : r.pageHeight = i + e + t;
835
+ }
836
+ };
837
+ }
838
+ function De(i) {
839
+ return i ? `${i.top} ${i.right} ${i.bottom} ${i.left}` : "0";
840
+ }
841
+ function je(i) {
842
+ let e = null;
843
+ return () => (e || (e = i()), e);
844
+ }
845
+ async function We() {
846
+ if (!(ie in window))
847
+ return null;
848
+ const i = await window[ie]?.();
849
+ return i ? JSON.parse(i) : null;
850
+ }
851
+ const Me = `
852
+ html {
853
+ box-sizing: border-box;
854
+ }
855
+
856
+ *,
857
+ *:before,
858
+ *:after {
859
+ box-sizing: inherit;
860
+ }
861
+
862
+ :root {
863
+ --paprize-page-background-color: #ffffff;
864
+ --paprize-page-margin-bottom: 10px;
865
+ --paprize-page-box-shadow: rgb(142 138 138) -1px 3px 5px 2px;
866
+ --paprize-section-margin-bottom: 10px;
867
+ --paprize-preview-background-color: rgb(218 220 224);
868
+ --paprize-preview-padding: 30px 10px;
869
+ }
870
+
871
+ body {
872
+ margin: 0;
873
+ }
874
+
875
+ @media screen {
876
+ .${T} {
877
+ min-height: 100vh;
878
+ display: flex;
879
+ flex-direction: column;
880
+ align-items: center;
881
+ background-color: var(--paprize-preview-background-color);
882
+ padding: var(--paprize-preview-padding);
883
+ }
884
+
885
+ .${U} {
886
+ box-shadow: var(--paprize-page-box-shadow);
887
+ margin-bottom: var(--paprize-page-margin-bottom);
888
+ background-color: var(--paprize-page-background-color);
889
+ }
890
+
891
+ .${ve} {
892
+ margin-bottom: var(--paprize-section-margin-bottom);
893
+ }
894
+ }
895
+
896
+ @media print {
897
+ html:has(.${T}) *:not(.${T}):not(.${T} *):not(:has(.${T})) {
898
+ display: none !important;
899
+ }
900
+ }
901
+ `, Ue = {
902
+ display: "flex",
903
+ flexDirection: "column"
904
+ }, Ve = {
905
+ position: "absolute",
906
+ left: "-9999px",
907
+ top: "-9999px",
908
+ visibility: "hidden"
909
+ }, qe = (i, e) => ({
910
+ display: "flex",
911
+ flexDirection: "column",
912
+ width: i.width,
913
+ height: i.height,
914
+ maxHeight: i.height,
915
+ position: "relative",
916
+ padding: De(e),
917
+ zIndex: "1"
918
+ }), Je = {
919
+ overflow: "hidden",
920
+ width: "100%",
921
+ height: "100%"
922
+ }, Ge = {
923
+ position: "absolute",
924
+ width: "100%",
925
+ height: "100%",
926
+ left: 0,
927
+ top: 0
928
+ }, Ze = (i) => ({
929
+ page: `section-${i}`
930
+ });
931
+ function Xe(i, e) {
932
+ return `@page section-${i} {
933
+ margin: none;
934
+ size:${e.width} ${e.height};
935
+ width:${e.width};
936
+ height:${e.height};
937
+ }`;
938
+ }
939
+ const v = {
940
+ globalStyle: Me,
941
+ component: Ue,
942
+ outOfScreen: Ve,
943
+ page: qe,
944
+ overlay: Ge,
945
+ pageContent: Je,
946
+ sectionPageMedia: Xe,
947
+ section: Ze
948
+ };
949
+ function L(i) {
950
+ return i?.cloneNode(!0) ?? null;
951
+ }
952
+ function Ke(i) {
953
+ return {
954
+ sectionHeader: L(i.sectionHeader),
955
+ sectionFooter: L(i.sectionFooter),
956
+ pageHeader: L(i.pageHeader),
957
+ pageFooter: L(i.pageFooter),
958
+ pageContent: L(i.pageContent)
959
+ };
960
+ }
961
+ const Ye = "data-pz-page-break";
962
+ class Qe {
963
+ name = "pageBreak";
964
+ order = 1;
965
+ onVisitElement = (e, t, n, o) => {
966
+ t.currentNode.getNode().getAttribute(Ye) === "true" && (n.markPageAsFull(), o.result = h.FullNodePlaced);
967
+ };
968
+ }
969
+ class et {
970
+ _options = {};
971
+ name = "table";
972
+ order = 1;
973
+ constructor(e = {}) {
974
+ this._options = e;
975
+ }
976
+ onNewPage = (e, t) => {
977
+ if (this._options.includeHeaderOnlyTables)
978
+ return;
979
+ const o = t.getPageState().parentStack.find(
980
+ (_) => this._isTable(_.getNode())
981
+ );
982
+ if (!o || !o.clonedFrom)
983
+ return;
984
+ const r = o.clonedFrom, s = r.getNode(), d = s.tHead;
985
+ if (!(d !== null))
986
+ return;
987
+ const b = s.tBodies;
988
+ if (!this._isTableBodyEmpty(b))
989
+ return;
990
+ if (r.remove(), o.getNode().tHead === null) {
991
+ const _ = B(
992
+ d.cloneNode(!0),
993
+ o.transaction,
994
+ o.config
995
+ );
996
+ o.appendChild(_);
997
+ }
998
+ };
999
+ onClone = (e, t, n) => {
1000
+ if (t.tagName === "TR") {
1001
+ n.config.keepOnSamePage = !0;
1002
+ return;
1003
+ }
1004
+ if (!this._isTable(t) || !n.clonedFrom || n.cloneCount === 1)
1005
+ return;
1006
+ const o = n.getOriginalNode(), r = o.tHead;
1007
+ if (r && this._options.cloneHeader === !0) {
1008
+ const d = new F(
1009
+ r.cloneNode(!0),
1010
+ n.transaction,
1011
+ n.config
1012
+ );
1013
+ n.appendChild(d);
1014
+ }
1015
+ const s = o.tFoot;
1016
+ if (s && this._options.cloneFooter === !0) {
1017
+ const d = new F(
1018
+ s.cloneNode(!0),
1019
+ n.transaction,
1020
+ n.config
1021
+ );
1022
+ n.appendChild(d);
1023
+ }
1024
+ };
1025
+ _isTable(e) {
1026
+ return e.tagName === "TABLE";
1027
+ }
1028
+ _isTableBodyEmpty(e) {
1029
+ if (e.length === 0) return !0;
1030
+ const t = e[0];
1031
+ if (t.rows.length !== 1) return !1;
1032
+ const n = t.rows[0];
1033
+ return n.cells.length !== 1 ? !1 : n.cells[0].textContent.trim() === "";
1034
+ }
1035
+ }
1036
+ const tt = [
1037
+ new Qe(),
1038
+ new et()
1039
+ ], gt = {
1040
+ name: "debug",
1041
+ order: Number.MAX_SAFE_INTEGER,
1042
+ onNewPage: (i, e) => {
1043
+ const t = e.getPageState().currentPage.getNode();
1044
+ t.classList.contains(U) || t.classList.add(U), t.setAttribute(`${C}-element`, "page"), t.setAttribute(
1045
+ `${C}-height`,
1046
+ e.getPageState().pageHeight.toString()
1047
+ );
1048
+ }
1049
+ }, nt = "sectionToc";
1050
+ class pt {
1051
+ name = nt;
1052
+ order = 1;
1053
+ _state = /* @__PURE__ */ new Map();
1054
+ getContentList = () => Array.from(this._state.values()).flat();
1055
+ onVisitElement = (e, t, n) => {
1056
+ {
1057
+ const o = t.currentNode.getNode(), r = this.getHeadingLevel(o);
1058
+ if (!r || !o.textContent) return;
1059
+ const s = n.getPageState().pageIndex;
1060
+ s === 0 && this._state.set(e, []), this._state.get(e)?.push({
1061
+ sectionId: e,
1062
+ pageIndex: s,
1063
+ title: o.textContent,
1064
+ level: r
1065
+ });
1066
+ }
1067
+ };
1068
+ getHeadingLevel(e) {
1069
+ const t = e.tagName;
1070
+ return /^H[1-6]$/.test(t) ? parseInt(t.charAt(1), 10) : null;
1071
+ }
1072
+ }
1073
+ class R {
1074
+ _promises;
1075
+ monitor;
1076
+ constructor() {
1077
+ this._promises = [], this.monitor = new ge();
1078
+ }
1079
+ toPromise() {
1080
+ return this._promises.length > 0 ? Promise.allSettled(this._promises.map((e) => e.promise)).then(
1081
+ (e) => {
1082
+ const t = e.find(
1083
+ (n) => n.status === "rejected"
1084
+ );
1085
+ return t ? Promise.reject(t.reason) : Promise.resolve();
1086
+ }
1087
+ ) : Promise.resolve();
1088
+ }
1089
+ then(e) {
1090
+ this._promises.push(
1091
+ R.toTracked(this.toPromise().then(e))
1092
+ );
1093
+ }
1094
+ async add(e = []) {
1095
+ if (this._promises.push(...e.map(R.toTracked)), await new Promise((t) => setTimeout(t, 0)), this.getPending().length === 0) {
1096
+ this.monitor.dispatch("onChange", 0);
1097
+ return;
1098
+ }
1099
+ this._promises.forEach((t) => this.injectEvents(t));
1100
+ }
1101
+ static toTracked(e) {
1102
+ const t = {
1103
+ promise: e,
1104
+ status: "pending"
1105
+ };
1106
+ return t.promise.then(() => {
1107
+ t.status = "resolved";
1108
+ }).catch(() => {
1109
+ t.status = "rejected";
1110
+ }), t;
1111
+ }
1112
+ async injectEvents(e) {
1113
+ e.promise.finally(() => {
1114
+ const t = this.getPending();
1115
+ this.monitor.dispatch("onChange", t.length);
1116
+ });
1117
+ }
1118
+ getPending() {
1119
+ return Array.from(this._promises.values()).filter(
1120
+ (e) => e.status === "pending"
1121
+ );
1122
+ }
1123
+ }
1124
+ function ut(i, e) {
1125
+ return `${i}-${e + 1}`;
1126
+ }
1127
+ function it(i, e) {
1128
+ return e === "landscape" ? { height: i.width, width: i.height } : i;
1129
+ }
1130
+ const w = "\x1B[43mREPORT\x1B[0m";
1131
+ class ht {
1132
+ _sections;
1133
+ _monitor;
1134
+ _paginationInProgress;
1135
+ _pendingPaginateResolvers;
1136
+ _currentAbortController;
1137
+ constructor() {
1138
+ this._sections = /* @__PURE__ */ new Map(), this._monitor = new ge(), this._paginationInProgress = !1, this._pendingPaginateResolvers = [], this._currentAbortController = null, window[Oe] = !0, this._injectStyle(v.globalStyle);
1139
+ }
1140
+ /**
1141
+ * Monitor instance used to subscribe to pagination events.
1142
+ * See {@link ReportBuilderEvents} for available event types.
1143
+ */
1144
+ get monitor() {
1145
+ return this._monitor;
1146
+ }
1147
+ /**
1148
+ * Removes a section from the registered sections, if it has already been registered in the report.
1149
+ */
1150
+ removeSection(e) {
1151
+ this._sections.delete(e);
1152
+ }
1153
+ /**
1154
+ * Registers a section by its ID, specifying the page size, margins, and other options.
1155
+ *
1156
+ * @param options - Configuration options for the section.
1157
+ * @param components - The DOM components associated with the section.
1158
+ * @param onPaginationCompleted - Callback invoked when pagination for the section is completed.
1159
+ * @returns `true` if the section was added to the report’s section list, or `false` if it already exists.
1160
+ */
1161
+ async tryAddSection(e, t, n) {
1162
+ if (this._sections.has(e.id))
1163
+ return !1;
1164
+ const o = {
1165
+ sectionIndex: this._sections.size,
1166
+ sectionId: e.id,
1167
+ isPaginated: !1,
1168
+ isSuspended: !!e.suspense?.length,
1169
+ pages: []
1170
+ };
1171
+ return this._sections.set(e.id, {
1172
+ context: o,
1173
+ options: {
1174
+ ...e,
1175
+ size: it(
1176
+ e.size,
1177
+ e.orientation ?? "portrait"
1178
+ )
1179
+ },
1180
+ components: t,
1181
+ onPaginationCompleted: n
1182
+ }), this._injectStyle(
1183
+ v.sectionPageMedia(e.id, e.size)
1184
+ ), await this._monitor.dispatch("sectionCreated", o), !0;
1185
+ }
1186
+ /**
1187
+ * Schedules a pagination operation.
1188
+ *
1189
+ * It is not possible to schedule multiple pagination operations in parallel,
1190
+ * as the process involves DOM manipulation, and concurrent modifications
1191
+ * could cause conflicts and unexpected results.
1192
+ * Each newly scheduled operation is queued and executed sequentially.
1193
+ * When a new pagination is scheduled, any ongoing or pending operations
1194
+ * will be aborted, and the new pagination will start immediately afterward.
1195
+ *
1196
+ * @returns A promise that resolves when the first pagination cycle is completed.
1197
+ * It does not wait for suspended sections to resolve and be paginated.
1198
+ * To wait for all sections to complete pagination, use the
1199
+ * `suspension` property of the returned result object.
1200
+ */
1201
+ async schedulePagination() {
1202
+ return this._sections.size === 0 ? (window[ne] = !0, {
1203
+ sections: [],
1204
+ suspension: Promise.resolve()
1205
+ }) : (this._paginationInProgress && this._currentAbortController && (g.debug(
1206
+ w,
1207
+ "Cancelling previous pagination operation."
1208
+ ), this._currentAbortController.abort(
1209
+ "Cancelled by new paginate call"
1210
+ )), this._paginationInProgress ? new Promise((e, t) => {
1211
+ this._pendingPaginateResolvers.push({ resolve: e, reject: t });
1212
+ }) : this._executePagination());
1213
+ }
1214
+ /**
1215
+ * Retrieves JSON data injected by **@paprize/puppeteer** during server-side rendering (SSR).
1216
+ *
1217
+ * If no injected data is available, the function returns the provided `defaultData`, or `null` if none is given.
1218
+ *
1219
+ * ⚠️ **Important Notes:**
1220
+ * - This function is **not type-safe** — it performs **no runtime type validation** on the returned data.
1221
+ * - It is available **only during server-side rendering** when using **@paprize/puppeteer**.
1222
+ * - When used in **client-side rendering** or **development** mode, you should provide a `defaultData` value for testing purposes.
1223
+ *
1224
+ * @template T - The expected type of the injected JSON data.
1225
+ * @param defaultData - Optional fallback value to return if no injected data is found.
1226
+ * @returns A promise resolving to the injected JSON data if available, otherwise the provided default value or `null`.
1227
+ */
1228
+ async getJsonData(e) {
1229
+ return await this._lazyJsonDataReader().catch(() => e) ?? e ?? null;
1230
+ }
1231
+ _lazyJsonDataReader = je(We);
1232
+ async _executePagination() {
1233
+ this._paginationInProgress = !0, this._currentAbortController = new AbortController();
1234
+ const e = this._currentAbortController.signal;
1235
+ try {
1236
+ if (g.debug(w, "Schedule paginate."), await document.fonts.ready, e.aborted)
1237
+ return new Promise((o, r) => {
1238
+ this._pendingPaginateResolvers.push({ resolve: o, reject: r });
1239
+ });
1240
+ const t = [];
1241
+ for (const o of this._sections.values()) {
1242
+ o.context.isPaginated = !1;
1243
+ const r = new R();
1244
+ await r.add(o.options.suspense), r.monitor.addEventListener("onChange", (s) => {
1245
+ g.debug(
1246
+ w,
1247
+ `${s} pending promises in section '${o.options.id}'.`
1248
+ );
1249
+ }), r.then(async () => {
1250
+ e.aborted || (g.debug(
1251
+ w,
1252
+ `Start paginating section '${o.options.id}'.`
1253
+ ), o.context.isSuspended = !1, await this._paginateSection(o));
1254
+ }), t.push(r);
1255
+ }
1256
+ const n = new R();
1257
+ return n.monitor.addEventListener("onChange", async () => {
1258
+ g.debug(w, "Report pagination completed."), await this._monitor.dispatch("paginationCycleCompleted", {
1259
+ sections: [...this._sections.values()].map(
1260
+ (o) => o.context
1261
+ )
1262
+ });
1263
+ }), e.aborted ? new Promise((o, r) => {
1264
+ this._pendingPaginateResolvers.push({ resolve: o, reject: r });
1265
+ }) : (await n.add(t.map((o) => o.toPromise())), {
1266
+ sections: [...this._sections.values()].map((o) => o.context),
1267
+ suspension: n.toPromise().then(() => {
1268
+ window[ne] = !0;
1269
+ })
1270
+ });
1271
+ } finally {
1272
+ this._processPendingPagination(), this._paginationInProgress = !1, this._currentAbortController = null;
1273
+ }
1274
+ }
1275
+ async _processPendingPagination() {
1276
+ if (this._pendingPaginateResolvers.length === 0)
1277
+ return;
1278
+ g.debug(
1279
+ w,
1280
+ `Processing ${this._pendingPaginateResolvers.length} pending paginate calls.`
1281
+ );
1282
+ const e = [...this._pendingPaginateResolvers];
1283
+ this._pendingPaginateResolvers = [];
1284
+ const t = await this._executePagination();
1285
+ for (const n of e)
1286
+ n.resolve(t);
1287
+ }
1288
+ _injectStyle(e) {
1289
+ let t = document.getElementById(
1290
+ K
1291
+ );
1292
+ t || (t = document.createElement("style"), t.id = K, t.textContent = "", document.head.appendChild(t)), t.textContent = (t.textContent + e).replace(/\s+/g, " ").replace(/\s*([:;{}])\s*/g, "$1").trim();
1293
+ }
1294
+ async _paginateSection(e) {
1295
+ const t = document.createElement("div");
1296
+ Object.assign(
1297
+ t.style,
1298
+ v.page(
1299
+ e.options.size,
1300
+ e.options.margin ?? He.None
1301
+ )
1302
+ ), V() || Object.assign(t.style, v.outOfScreen);
1303
+ const n = Ke(e.components);
1304
+ n.sectionHeader && (Object.assign(
1305
+ n.sectionHeader.style,
1306
+ v.component
1307
+ ), t.appendChild(n.sectionHeader)), n.pageHeader && (Object.assign(n.pageHeader.style, v.component), t.appendChild(n.pageHeader)), Object.assign(n.pageContent.style, v.pageContent), t.appendChild(n.pageContent), n.pageFooter && (Object.assign(n.pageFooter.style, v.component), t.appendChild(n.pageFooter)), n.sectionFooter && (Object.assign(
1308
+ n.sectionFooter.style,
1309
+ v.component
1310
+ ), t.appendChild(n.sectionFooter)), document.body.appendChild(t);
1311
+ const { height: o, width: r, sectionHeaderHeight: s, sectionFooterHeight: d } = ze(
1312
+ n.pageContent,
1313
+ n.sectionHeader,
1314
+ n.sectionFooter
1315
+ );
1316
+ if (o === 0)
1317
+ throw g.error(
1318
+ `Pagination failed for section '${e.options.id}': insufficient space for page content or content is empty. Ensure that the section has content and that the header and footer do not occupy all available space.`
1319
+ ), t.remove(), new Error(
1320
+ `Pagination failed: no available space for content in section '${e.options.id}'.`
1321
+ );
1322
+ const P = D.paginate(
1323
+ n.pageContent,
1324
+ { height: o, width: r },
1325
+ {
1326
+ id: e.options.id,
1327
+ plugins: [
1328
+ ...e.options.plugins ?? tt,
1329
+ Be(
1330
+ o,
1331
+ s,
1332
+ d
1333
+ )
1334
+ ]
1335
+ }
1336
+ );
1337
+ t.remove();
1338
+ const b = P.map((_, j) => ({
1339
+ pageIndex: j,
1340
+ totalPages: P.length,
1341
+ sectionId: e.options.id,
1342
+ pageContentHtml: _
1343
+ }));
1344
+ await e.onPaginationCompleted(b);
1345
+ for (const _ of b)
1346
+ await this._monitor.dispatch("pageCompleted", _);
1347
+ const f = {
1348
+ ...e.context,
1349
+ isPaginated: !0,
1350
+ isSuspended: !1,
1351
+ pages: b
1352
+ };
1353
+ this._sections.set(e.options.id, {
1354
+ ...e,
1355
+ context: f
1356
+ }), await this._monitor.dispatch("sectionCompleted", f);
1357
+ }
1358
+ }
1359
+ const oe = [
1360
+ "ad",
1361
+ "adipisicing",
1362
+ "aliqua",
1363
+ "aliquip",
1364
+ "amet",
1365
+ "anim",
1366
+ "aute",
1367
+ "cillum",
1368
+ "commodo",
1369
+ "consectetur",
1370
+ "consequat",
1371
+ "culpa",
1372
+ "cupidatat",
1373
+ "deserunt",
1374
+ "do",
1375
+ "dolor",
1376
+ "dolore",
1377
+ "duis",
1378
+ "ea",
1379
+ "eiusmod",
1380
+ "elit",
1381
+ "enim",
1382
+ "esse",
1383
+ "est",
1384
+ "et",
1385
+ "eu",
1386
+ "ex",
1387
+ "excepteur",
1388
+ "exercitation",
1389
+ "fugiat",
1390
+ "id",
1391
+ "in",
1392
+ "incididunt",
1393
+ "ipsum",
1394
+ "irure",
1395
+ "labore",
1396
+ "laboris",
1397
+ "laborum",
1398
+ "Lorem",
1399
+ "magna",
1400
+ "minim",
1401
+ "mollit",
1402
+ "nisi",
1403
+ "non",
1404
+ "nostrud",
1405
+ "nulla",
1406
+ "occaecat",
1407
+ "officia",
1408
+ "pariatur",
1409
+ "proident",
1410
+ "qui",
1411
+ "quis",
1412
+ "reprehenderit",
1413
+ "sint",
1414
+ "sit",
1415
+ "sunt",
1416
+ "tempor",
1417
+ "ullamco",
1418
+ "ut",
1419
+ "velit",
1420
+ "veniam",
1421
+ "voluptate"
1422
+ ];
1423
+ function mt(i, e) {
1424
+ if (i <= 0)
1425
+ return "";
1426
+ const t = [], n = Math.floor(e * 982451653);
1427
+ for (let o = 0; o < i; o++) {
1428
+ const r = (n + o * 2654435761) % Math.pow(2, 32), s = Math.floor(
1429
+ r / Math.pow(2, 32) * oe.length
1430
+ );
1431
+ t.push(oe[s]);
1432
+ }
1433
+ return t.length > 0 && (t[0] = t[0].charAt(0).toUpperCase() + t[0].slice(1)), t.join(" ") + ".";
1434
+ }
1435
+ export {
1436
+ ge as EventDispatcher,
1437
+ Qe as PageBreakPlugin,
1438
+ D as Paginator,
1439
+ ht as ReportBuilder,
1440
+ pt as SectionTocPlugin,
1441
+ h as SplitResult,
1442
+ et as TablePlugin,
1443
+ it as adjustPageSize,
1444
+ C as attributePrefix,
1445
+ ut as buildPageId,
1446
+ Ke as cloneComponents,
1447
+ mt as createLoremIpsumParagraph,
1448
+ ot as currentElementClassName,
1449
+ rt as currentTextClassName,
1450
+ gt as debugPlugin,
1451
+ tt as defaultPlugins,
1452
+ lt as enableDebugMode,
1453
+ z as getVisibleHeight,
1454
+ Me as globalStyle,
1455
+ K as globalStyleId,
1456
+ st as ignoredElementClassName,
1457
+ at as ignoredTextClassName,
1458
+ V as isDebugMode,
1459
+ se as isElement,
1460
+ be as isTextNode,
1461
+ ct as layoutOptionsToAttributes,
1462
+ g as logger,
1463
+ fe as loggerName,
1464
+ ye as moveOffscreen,
1465
+ Ye as pageBreakAttributeName,
1466
+ U as pageClassName,
1467
+ He as pageMargin,
1468
+ dt as pageSize,
1469
+ Oe as paprize_isInitialized,
1470
+ ne as paprize_isReady,
1471
+ ie as paprize_readJsonDataFile,
1472
+ T as previewClassName,
1473
+ v as reportStyles,
1474
+ ve as sectionClassName,
1475
+ nt as sectionTocName,
1476
+ _e as tempContainerClassName
1477
+ };
1478
+ //# sourceMappingURL=paprize-core.js.map