@paprize/core 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,26 @@
1
- const me = "paprize", fe = "pz-temp-container", it = "pz-current-element", ot = "pz-current-text", rt = "pz-ignored-element", st = "pz-ignored-text", X = "paprize-global-style", U = "pz-page", _e = "pz-section", T = "pz-preview", C = "data-pz-";
2
- let oe = !1;
3
- const at = () => {
4
- oe = !0;
5
- }, ve = () => oe;
6
- function re(i) {
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
7
  return i.nodeType === Node.ELEMENT_NODE;
8
8
  }
9
9
  function be(i) {
10
10
  return i.nodeType === Node.TEXT_NODE;
11
11
  }
12
- function $(i) {
12
+ function z(i) {
13
13
  const e = i.getBoundingClientRect(), t = getComputedStyle(i), n = parseFloat(t.marginTop) || 0, o = parseFloat(t.marginBottom) || 0;
14
14
  return e.height + n + o;
15
15
  }
16
- function lt(i) {
16
+ function ye(i) {
17
17
  i.style.visibility = "hidden", i.style.position = "absolute", i.style.left = "-9999px", i.style.top = "-9999px";
18
18
  }
19
- const se = {
19
+ const ae = {
20
20
  hyphen: "-",
21
21
  keepOnSamePage: !1,
22
22
  hyphenationDisabled: !1
23
- }, ae = {
23
+ }, le = {
24
24
  hyphen: {
25
25
  key: `${C}hyphen`,
26
26
  reader: (i) => String(i)
@@ -37,49 +37,49 @@ const se = {
37
37
  function ct(i) {
38
38
  const e = {};
39
39
  for (const [t, n] of Object.entries(i)) {
40
- const o = ae[t];
40
+ const o = le[t];
41
41
  o !== void 0 && n !== void 0 && (e[o.key] = String(n));
42
42
  }
43
43
  return e;
44
44
  }
45
- const K = /* @__PURE__ */ new WeakMap();
46
- function ye(i, e, t, n) {
45
+ const Y = /* @__PURE__ */ new WeakMap();
46
+ function we(i, e, t, n) {
47
47
  if (t == null)
48
48
  return;
49
49
  const o = e(t);
50
50
  o !== void 0 && (n[i] = o);
51
51
  }
52
- function le(i) {
52
+ function ce(i) {
53
53
  if (!i)
54
54
  return {};
55
55
  if (!(i instanceof Element))
56
- return le(i?.parentNode);
56
+ return ce(i?.parentNode);
57
57
  const e = {};
58
- for (const o of Object.keys(se)) {
59
- const r = o, s = ae[r], d = i.getAttribute(s.key);
60
- ye(r, s.reader, d, 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
61
  }
62
- const n = { ...i.parentNode ? K.get(i.parentNode) : void 0, ...e };
63
- return K.set(i, n), n;
62
+ const n = { ...i.parentNode ? Y.get(i.parentNode) : void 0, ...e };
63
+ return Y.set(i, n), n;
64
64
  }
65
- const ce = {
65
+ const de = {
66
66
  id: "default",
67
67
  plugins: [],
68
- ...se
68
+ ...ae
69
69
  };
70
- function we(i, e) {
71
- const t = le(i);
72
- return { ...ce, ...e, ...t };
70
+ function Se(i, e) {
71
+ const t = ce(i);
72
+ return { ...de, ...e, ...t };
73
73
  }
74
- function Se(i) {
74
+ function Ce(i) {
75
75
  return i && i.__esModule && Object.prototype.hasOwnProperty.call(i, "default") ? i.default : i;
76
76
  }
77
- var O = { exports: {} }, Ce = O.exports, Y;
78
- function Ne() {
79
- return Y || (Y = 1, (function(i) {
77
+ var $ = { exports: {} }, Ne = $.exports, Q;
78
+ function xe() {
79
+ return Q || (Q = 1, (function(i) {
80
80
  (function(e, t) {
81
81
  i.exports ? i.exports = t() : e.log = t();
82
- })(Ce, function() {
82
+ })(Ne, function() {
83
83
  var e = function() {
84
84
  }, t = "undefined", n = typeof window !== t && typeof window.navigator !== t && /Trident\/|MSIE /.test(window.navigator.userAgent), o = [
85
85
  "trace",
@@ -119,13 +119,13 @@ function Ne() {
119
119
  typeof console !== t && (f.call(this), this[l].apply(this, arguments));
120
120
  };
121
121
  }
122
- function W(l, p, a) {
122
+ function j(l, p, a) {
123
123
  return b(l) || _.apply(this, arguments);
124
124
  }
125
- function q(l, p) {
126
- var a = this, R, j, y, m = "loglevel";
125
+ function J(l, p) {
126
+ var a = this, H, W, y, m = "loglevel";
127
127
  typeof l == "string" ? m += ":" + l : typeof l == "symbol" && (m = void 0);
128
- function pe(c) {
128
+ function ue(c) {
129
129
  var u = (o[c] || "silent").toUpperCase();
130
130
  if (!(typeof window === t || !m)) {
131
131
  try {
@@ -139,7 +139,7 @@ function Ne() {
139
139
  }
140
140
  }
141
141
  }
142
- function J() {
142
+ function G() {
143
143
  var c;
144
144
  if (!(typeof window === t || !m)) {
145
145
  try {
@@ -148,16 +148,16 @@ function Ne() {
148
148
  }
149
149
  if (typeof c === t)
150
150
  try {
151
- var u = window.document.cookie, H = encodeURIComponent(m), Z = u.indexOf(H + "=");
152
- Z !== -1 && (c = /^([^;]+)/.exec(
153
- u.slice(Z + H.length + 1)
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
154
  )[1]);
155
155
  } catch {
156
156
  }
157
157
  return a.levels[c] === void 0 && (c = void 0), c;
158
158
  }
159
159
  }
160
- function ue() {
160
+ function he() {
161
161
  if (!(typeof window === t || !m)) {
162
162
  try {
163
163
  window.localStorage.removeItem(m);
@@ -182,48 +182,48 @@ function Ne() {
182
182
  WARN: 3,
183
183
  ERROR: 4,
184
184
  SILENT: 5
185
- }, a.methodFactory = p || W, a.getLevel = function() {
186
- return y ?? j ?? R;
185
+ }, a.methodFactory = p || j, a.getLevel = function() {
186
+ return y ?? W ?? H;
187
187
  }, a.setLevel = function(c, u) {
188
- return y = E(c), u !== !1 && pe(y), f.call(a);
188
+ return y = E(c), u !== !1 && ue(y), f.call(a);
189
189
  }, a.setDefaultLevel = function(c) {
190
- j = E(c), J() || a.setLevel(c, !1);
190
+ W = E(c), G() || a.setLevel(c, !1);
191
191
  }, a.resetLevel = function() {
192
- y = null, ue(), f.call(a);
192
+ y = null, he(), f.call(a);
193
193
  }, a.enableAll = function(c) {
194
194
  a.setLevel(a.levels.TRACE, c);
195
195
  }, a.disableAll = function(c) {
196
196
  a.setLevel(a.levels.SILENT, c);
197
197
  }, a.rebuild = function() {
198
- if (s !== a && (R = E(s.getLevel())), f.call(a), s === a)
198
+ if (s !== a && (H = E(s.getLevel())), f.call(a), s === a)
199
199
  for (var c in r)
200
200
  r[c].rebuild();
201
- }, R = E(
201
+ }, H = E(
202
202
  s ? s.getLevel() : "WARN"
203
203
  );
204
- var G = J();
205
- G != null && (y = E(G)), f.call(a);
204
+ var Z = G();
205
+ Z != null && (y = E(Z)), f.call(a);
206
206
  }
207
- s = new q(), s.getLogger = function(p) {
207
+ s = new J(), s.getLogger = function(p) {
208
208
  if (typeof p != "symbol" && typeof p != "string" || p === "")
209
209
  throw new TypeError("You must supply a name when creating a logger.");
210
210
  var a = r[p];
211
- return a || (a = r[p] = new q(
211
+ return a || (a = r[p] = new J(
212
212
  p,
213
213
  s.methodFactory
214
214
  )), a;
215
215
  };
216
- var ge = typeof window !== t ? window.log : void 0;
216
+ var pe = typeof window !== t ? window.log : void 0;
217
217
  return s.noConflict = function() {
218
- return typeof window !== t && window.log === s && (window.log = ge), s;
218
+ return typeof window !== t && window.log === s && (window.log = pe), s;
219
219
  }, s.getLoggers = function() {
220
220
  return r;
221
221
  }, s.default = s, s;
222
222
  });
223
- })(O)), O.exports;
223
+ })($)), $.exports;
224
224
  }
225
- var xe = Ne();
226
- const S = /* @__PURE__ */ Se(xe), g = S.getLogger(me);
225
+ var Pe = xe();
226
+ const S = /* @__PURE__ */ Ce(Pe), g = S.getLogger(fe);
227
227
  g.setDefaultLevel("info");
228
228
  const M = "\x1B[46mPLUGIN\x1B[0m";
229
229
  function N(i, e, ...t) {
@@ -292,7 +292,7 @@ class F {
292
292
  ), n;
293
293
  }
294
294
  getHeight() {
295
- return $(this._node);
295
+ return z(this._node);
296
296
  }
297
297
  remove() {
298
298
  this.transaction.addCommitCallback(() => {
@@ -309,7 +309,7 @@ class F {
309
309
  return this._node;
310
310
  }
311
311
  }
312
- class Pe {
312
+ class Ee {
313
313
  _node;
314
314
  type = x.Text;
315
315
  transaction;
@@ -332,15 +332,15 @@ class Pe {
332
332
  return this._node;
333
333
  }
334
334
  }
335
- function z(i, e, t) {
335
+ function B(i, e, t) {
336
336
  if (be(i))
337
- return new Pe(i, e, t);
338
- if (re(i))
337
+ return new Ee(i, e, t);
338
+ if (se(i))
339
339
  return new F(i, e, t);
340
340
  throw new Error("Unsupported node type");
341
341
  }
342
342
  const k = "\x1B[106mDOM\x1B[0m";
343
- class Ee {
343
+ class Te {
344
344
  _transaction;
345
345
  _treeWalker;
346
346
  _config;
@@ -382,17 +382,17 @@ class Ee {
382
382
  return this._treeWalker.firstChild() ? (g.debug(k, "moving to first child node"), this.setState(), { parentsTraversed: 1 }) : (this.goToNextNode(), { parentsTraversed: 0 });
383
383
  }
384
384
  setState() {
385
- this._previousNode = this._currentNode, this._currentNode = z(
385
+ this._previousNode = this._currentNode, this._currentNode = B(
386
386
  this._treeWalker.currentNode,
387
387
  this._transaction,
388
- we(this._treeWalker.currentNode, this._config)
388
+ Se(this._treeWalker.currentNode, this._config)
389
389
  ), g.debug(k, "moved to node", {
390
390
  currentNode: this._currentNode,
391
391
  previousNode: this._previousNode
392
392
  });
393
393
  }
394
394
  }
395
- class Te {
395
+ class ke {
396
396
  _onRollback;
397
397
  _onCommit;
398
398
  isActive;
@@ -421,7 +421,7 @@ class Te {
421
421
  this.isActive && (this.isActive = !1, this._onCommit.forEach((e) => e()));
422
422
  };
423
423
  }
424
- const Q = "\x1B[102mPAGE\x1B[0m";
424
+ const ee = "\x1B[102mPAGE\x1B[0m";
425
425
  class I {
426
426
  currentPage;
427
427
  activeElement;
@@ -454,14 +454,14 @@ class I {
454
454
  this.pageHeight
455
455
  );
456
456
  }
457
- class V {
457
+ class q {
458
458
  _pageState;
459
459
  _transaction;
460
460
  _tempContainer;
461
461
  _config;
462
462
  constructor(e, t, n, o) {
463
463
  this._tempContainer = e, this._config = o, this._transaction = n;
464
- const r = V.createPageHtmlElement(
464
+ const r = q.createPageHtmlElement(
465
465
  t.width
466
466
  ), s = this.createNewPage(r);
467
467
  this._pageState = I.create(s, [], 0, t.height), N(this._config.plugins, "onNewPage", o.id, this);
@@ -501,7 +501,7 @@ class V {
501
501
  if (!this._pageState.activeElement || this._pageState.activeElement.type !== x.Element)
502
502
  throw new Error("Invalid state: activeElement is not an Element");
503
503
  g.debug(
504
- Q,
504
+ ee,
505
505
  "entering an element",
506
506
  this._pageState.activeElement
507
507
  ), this._pageState.currentElement = this._pageState.activeElement, this._pageState.parentStack.push(this._pageState.activeElement);
@@ -509,7 +509,7 @@ class V {
509
509
  leaveElement() {
510
510
  this._pageState.activeElement = null;
511
511
  const e = this._pageState.parentStack.pop();
512
- g.debug(Q, "leaving a parent element", e);
512
+ g.debug(ee, "leaving a parent element", e);
513
513
  const t = this._pageState.parentStack.at(-1);
514
514
  this._pageState.currentElement = t ?? this._pageState.currentPage;
515
515
  }
@@ -520,7 +520,7 @@ class V {
520
520
  createNewPage(e) {
521
521
  return this._tempContainer.appendChild(e), this._transaction.isActive && this._transaction.addRollbackCallback(() => {
522
522
  this._tempContainer.removeChild(e);
523
- }), z(e, this._transaction, this._config);
523
+ }), B(e, this._transaction, this._config);
524
524
  }
525
525
  startTransaction() {
526
526
  this._transaction.start();
@@ -545,7 +545,7 @@ class V {
545
545
  addTextNode(e) {
546
546
  if (this._pageState.activeElement?.type === x.Text)
547
547
  return this._pageState.activeElement;
548
- const t = document.createTextNode(e), n = z(
548
+ const t = document.createTextNode(e), n = B(
549
549
  t,
550
550
  this._transaction,
551
551
  this._config
@@ -564,16 +564,16 @@ const h = {
564
564
  SplitChildren: 2
565
565
  // The node is too large for the page, and its children must be paginated individually.
566
566
  };
567
- function ke(i, e) {
568
- const t = ee(i, e);
567
+ function Ae(i, e) {
568
+ const t = te(i, e);
569
569
  if (t !== h.None)
570
570
  return t;
571
571
  const { rollback: n, commit: o } = e.startTransaction();
572
572
  e.nextPage();
573
- const r = ee(i, e);
573
+ const r = te(i, e);
574
574
  return r !== h.None ? (o(), r) : (n(), g.debug("Element is too big to fit on a page", i), h.None);
575
575
  }
576
- function ee(i, e) {
576
+ function te(i, e) {
577
577
  if (e.hasEmptySpace(i.getHeight())) {
578
578
  const n = e.appendChild(i, !0);
579
579
  if (e.isOverFlow())
@@ -586,17 +586,17 @@ function ee(i, e) {
586
586
  const t = e.appendChild(i, !1);
587
587
  return e.isOverFlow() ? (t.remove(), h.None) : h.SplitChildren;
588
588
  }
589
- function Ae(i, e) {
589
+ function Le(i, e) {
590
590
  let t = h.FullNodePlaced;
591
591
  const n = i.textContent.split(/(\s+)/).filter((s) => s !== "");
592
592
  let o, r = 0;
593
593
  for (; o || r < n.length; ) {
594
- const s = o ?? n[r], d = Le(s, e, i.config);
594
+ const s = o ?? n[r], d = Fe(s, e, i.config);
595
595
  d.completed || (t = h.None), d.pendingToken ? o = d.pendingToken : (o = void 0, r++);
596
596
  }
597
597
  return t;
598
598
  }
599
- function Le(i, e, t) {
599
+ function Fe(i, e, t) {
600
600
  e.hasEmptySpace() || e.nextPage();
601
601
  const n = e.addTextNode(""), o = n.textContent;
602
602
  if (n.textContent += i, !e.isOverFlow())
@@ -604,13 +604,13 @@ function Le(i, e, t) {
604
604
  completed: !0
605
605
  };
606
606
  n.textContent = o;
607
- const r = Fe(i, e, t);
607
+ const r = Ie(i, e, t);
608
608
  return {
609
609
  pendingToken: r.leftovers,
610
610
  completed: r.completed
611
611
  };
612
612
  }
613
- function Fe(i, e, t) {
613
+ function Ie(i, e, t) {
614
614
  const { rollback: n, commit: o } = e.startTransaction();
615
615
  if (e.nextPage(), e.addTextNode(i), !e.isOverFlow())
616
616
  return o(), {
@@ -620,13 +620,13 @@ function Fe(i, e, t) {
620
620
  return g.warn("Hyphenation disabled, skipping oversized token:", i), {
621
621
  completed: !1
622
622
  };
623
- const r = Ie(i, t.hyphen, e);
623
+ const r = Re(i, t.hyphen, e);
624
624
  return {
625
625
  completed: !0,
626
626
  leftovers: r && r.length > 0 ? r : void 0
627
627
  };
628
628
  }
629
- function Ie(i, e, t) {
629
+ function Re(i, e, t) {
630
630
  const n = t.addTextNode("");
631
631
  let o = "";
632
632
  for (let r = 0; r < i.length; r++) {
@@ -638,14 +638,14 @@ function Ie(i, e, t) {
638
638
  return null;
639
639
  }
640
640
  const A = "\x1B[103mPAGINATOR\x1B[0m";
641
- class B {
641
+ class D {
642
642
  _domState;
643
643
  _pageManager;
644
644
  _transaction;
645
645
  _tempContainer;
646
646
  _config;
647
647
  constructor(e, t, n) {
648
- this._config = { ...ce, ...n }, this._tempContainer = B.createTempContainer(this._config.id), this._transaction = new Te(), this._domState = new Ee(e, this._transaction, this._config), this._pageManager = new V(
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
649
  this._tempContainer,
650
650
  t,
651
651
  this._transaction,
@@ -654,11 +654,13 @@ class B {
654
654
  }
655
655
  static createTempContainer(e) {
656
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(fe), document.body.appendChild(t), t;
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
658
  }
659
659
  static paginate(e, t, n) {
660
- const o = new B(e, t, n);
661
- return o.processAllNodes(), Array.from(o._tempContainer.childNodes).filter((s) => re(s)).map((s) => s.innerHTML);
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;
662
664
  }
663
665
  processAllNodes() {
664
666
  this._domState.goToNextNode();
@@ -717,7 +719,7 @@ class B {
717
719
  this._domState,
718
720
  this._pageManager,
719
721
  e
720
- ), e.result !== void 0 ? e.result : ke(
722
+ ), e.result !== void 0 ? e.result : Ae(
721
723
  this._domState.currentNode,
722
724
  this._pageManager
723
725
  );
@@ -730,14 +732,14 @@ class B {
730
732
  this._domState,
731
733
  this._pageManager,
732
734
  e
733
- ), e.result !== void 0 ? e.result : Ae(
735
+ ), e.result !== void 0 ? e.result : Le(
734
736
  this._domState.currentNode,
735
737
  this._pageManager
736
738
  );
737
739
  }
738
740
  }
739
741
  }
740
- class de {
742
+ class ge {
741
743
  registry = /* @__PURE__ */ new Map();
742
744
  addEventListener(e, t) {
743
745
  const { registry: n } = this, o = new Set(n.get(e));
@@ -779,7 +781,7 @@ const dt = {
779
781
  Legal: { height: "11in", width: "8.5in" },
780
782
  /** 11in x 17in */
781
783
  Tabloid: { height: "11in", width: "17in" }
782
- }, Re = {
784
+ }, He = {
783
785
  /** Top, Right, Bottom, Left: 1in */
784
786
  Normal: {
785
787
  top: "1in",
@@ -808,19 +810,19 @@ const dt = {
808
810
  bottom: "0in",
809
811
  left: "0in"
810
812
  }
811
- }, He = "__PAPRIZE_IS_INITIALIZED", te = "__PAPRIZE_IS_READY", ne = "__PAPRIZE_READ_JSON_DATA_FILE";
812
- function Oe(i) {
813
+ }, Oe = "__PAPRIZE_IS_INITIALIZED", ne = "__PAPRIZE_IS_READY", ie = "__PAPRIZE_READ_JSON_DATA_FILE";
814
+ function $e(i) {
813
815
  const e = i.getBoundingClientRect(), t = getComputedStyle(i), n = parseFloat(t.marginLeft) || 0, o = parseFloat(t.marginRight) || 0;
814
816
  return {
815
- height: $(i),
817
+ height: z(i),
816
818
  width: e.width + n + o
817
819
  };
818
820
  }
819
- function $e(i, e, t) {
820
- const { height: n, width: o } = Oe(i), r = e ? $(e) : 0, s = t ? $(t) : 0;
821
+ function ze(i, e, t) {
822
+ const { height: n, width: o } = $e(i), r = e ? z(e) : 0, s = t ? z(t) : 0;
821
823
  return { height: n, width: o, sectionHeaderHeight: r, sectionFooterHeight: s };
822
824
  }
823
- function ze(i, e, t) {
825
+ function Be(i, e, t) {
824
826
  return {
825
827
  name: "sectionPageHeight",
826
828
  order: 1,
@@ -833,20 +835,20 @@ function ze(i, e, t) {
833
835
  }
834
836
  };
835
837
  }
836
- function Be(i) {
838
+ function De(i) {
837
839
  return i ? `${i.top} ${i.right} ${i.bottom} ${i.left}` : "0";
838
840
  }
839
- function De(i) {
841
+ function je(i) {
840
842
  let e = null;
841
843
  return () => (e || (e = i()), e);
842
844
  }
843
845
  async function We() {
844
- if (!(ne in window))
846
+ if (!(ie in window))
845
847
  return null;
846
- const i = await window[ne]?.();
848
+ const i = await window[ie]?.();
847
849
  return i ? JSON.parse(i) : null;
848
850
  }
849
- const je = `
851
+ const Me = `
850
852
  html {
851
853
  box-sizing: border-box;
852
854
  }
@@ -886,7 +888,7 @@ const je = `
886
888
  background-color: var(--paprize-page-background-color);
887
889
  }
888
890
 
889
- .${_e} {
891
+ .${ve} {
890
892
  margin-bottom: var(--paprize-section-margin-bottom);
891
893
  }
892
894
  }
@@ -896,37 +898,37 @@ const je = `
896
898
  display: none !important;
897
899
  }
898
900
  }
899
- `, Me = {
901
+ `, Ue = {
900
902
  display: "flex",
901
903
  flexDirection: "column"
902
- }, Ue = {
904
+ }, Ve = {
903
905
  position: "absolute",
904
906
  left: "-9999px",
905
907
  top: "-9999px",
906
908
  visibility: "hidden"
907
- }, Ve = (i, e) => ({
909
+ }, qe = (i, e) => ({
908
910
  display: "flex",
909
911
  flexDirection: "column",
910
912
  width: i.width,
911
913
  height: i.height,
912
914
  maxHeight: i.height,
913
915
  position: "relative",
914
- padding: Be(e),
916
+ padding: De(e),
915
917
  zIndex: "1"
916
- }), qe = {
918
+ }), Je = {
917
919
  overflow: "hidden",
918
920
  width: "100%",
919
921
  height: "100%"
920
- }, Je = {
922
+ }, Ge = {
921
923
  position: "absolute",
922
924
  width: "100%",
923
925
  height: "100%",
924
926
  left: 0,
925
927
  top: 0
926
- }, Ge = (i) => ({
928
+ }, Ze = (i) => ({
927
929
  page: `section-${i}`
928
930
  });
929
- function Ze(i, e) {
931
+ function Xe(i, e) {
930
932
  return `@page section-${i} {
931
933
  margin: none;
932
934
  size:${e.width} ${e.height};
@@ -935,19 +937,19 @@ function Ze(i, e) {
935
937
  }`;
936
938
  }
937
939
  const v = {
938
- globalStyle: je,
939
- component: Me,
940
- outOfScreen: Ue,
941
- page: Ve,
942
- overlay: Je,
943
- pageContent: qe,
944
- sectionPageMedia: Ze,
945
- section: Ge
940
+ globalStyle: Me,
941
+ component: Ue,
942
+ outOfScreen: Ve,
943
+ page: qe,
944
+ overlay: Ge,
945
+ pageContent: Je,
946
+ sectionPageMedia: Xe,
947
+ section: Ze
946
948
  };
947
949
  function L(i) {
948
950
  return i?.cloneNode(!0) ?? null;
949
951
  }
950
- function Xe(i) {
952
+ function Ke(i) {
951
953
  return {
952
954
  sectionHeader: L(i.sectionHeader),
953
955
  sectionFooter: L(i.sectionFooter),
@@ -956,15 +958,15 @@ function Xe(i) {
956
958
  pageContent: L(i.pageContent)
957
959
  };
958
960
  }
959
- const Ke = "data-pz-page-break";
960
- class Ye {
961
+ const Ye = "data-pz-page-break";
962
+ class Qe {
961
963
  name = "pageBreak";
962
964
  order = 1;
963
965
  onVisitElement = (e, t, n, o) => {
964
- t.currentNode.getNode().getAttribute(Ke) === "true" && (n.markPageAsFull(), o.result = h.FullNodePlaced);
966
+ t.currentNode.getNode().getAttribute(Ye) === "true" && (n.markPageAsFull(), o.result = h.FullNodePlaced);
965
967
  };
966
968
  }
967
- class Qe {
969
+ class et {
968
970
  _options = {};
969
971
  name = "table";
970
972
  order = 1;
@@ -986,7 +988,7 @@ class Qe {
986
988
  if (!this._isTableBodyEmpty(b))
987
989
  return;
988
990
  if (r.remove(), o.getNode().tHead === null) {
989
- const _ = z(
991
+ const _ = B(
990
992
  d.cloneNode(!0),
991
993
  o.transaction,
992
994
  o.config
@@ -1031,9 +1033,9 @@ class Qe {
1031
1033
  return n.cells.length !== 1 ? !1 : n.cells[0].textContent.trim() === "";
1032
1034
  }
1033
1035
  }
1034
- const et = [
1035
- new Ye(),
1036
- new Qe()
1036
+ const tt = [
1037
+ new Qe(),
1038
+ new et()
1037
1039
  ], gt = {
1038
1040
  name: "debug",
1039
1041
  order: Number.MAX_SAFE_INTEGER,
@@ -1044,9 +1046,9 @@ const et = [
1044
1046
  e.getPageState().pageHeight.toString()
1045
1047
  );
1046
1048
  }
1047
- }, tt = "sectionToc";
1049
+ }, nt = "sectionToc";
1048
1050
  class pt {
1049
- name = tt;
1051
+ name = nt;
1050
1052
  order = 1;
1051
1053
  _state = /* @__PURE__ */ new Map();
1052
1054
  getContentList = () => Array.from(this._state.values()).flat();
@@ -1068,20 +1070,29 @@ class pt {
1068
1070
  return /^H[1-6]$/.test(t) ? parseInt(t.charAt(1), 10) : null;
1069
1071
  }
1070
1072
  }
1071
- class D {
1073
+ class R {
1072
1074
  _promises;
1073
1075
  monitor;
1074
- get promise() {
1076
+ constructor() {
1077
+ this._promises = [], this.monitor = new ge();
1078
+ }
1079
+ toPromise() {
1075
1080
  return this._promises.length > 0 ? Promise.allSettled(this._promises.map((e) => e.promise)).then(
1076
- () => {
1081
+ (e) => {
1082
+ const t = e.find(
1083
+ (n) => n.status === "rejected"
1084
+ );
1085
+ return t ? Promise.reject(t.reason) : Promise.resolve();
1077
1086
  }
1078
1087
  ) : Promise.resolve();
1079
1088
  }
1080
- constructor() {
1081
- this._promises = [], this.monitor = new de();
1089
+ then(e) {
1090
+ this._promises.push(
1091
+ R.toTracked(this.toPromise().then(e))
1092
+ );
1082
1093
  }
1083
1094
  async add(e = []) {
1084
- if (this._promises.push(...e.map(D.toTracked)), await new Promise((t) => setTimeout(t, 0)), this.getPending().length === 0) {
1095
+ if (this._promises.push(...e.map(R.toTracked)), await new Promise((t) => setTimeout(t, 0)), this.getPending().length === 0) {
1085
1096
  this.monitor.dispatch("onChange", 0);
1086
1097
  return;
1087
1098
  }
@@ -1092,8 +1103,10 @@ class D {
1092
1103
  promise: e,
1093
1104
  status: "pending"
1094
1105
  };
1095
- return t.promise.finally(() => {
1106
+ return t.promise.then(() => {
1096
1107
  t.status = "resolved";
1108
+ }).catch(() => {
1109
+ t.status = "rejected";
1097
1110
  }), t;
1098
1111
  }
1099
1112
  async injectEvents(e) {
@@ -1111,7 +1124,7 @@ class D {
1111
1124
  function ut(i, e) {
1112
1125
  return `${i}-${e + 1}`;
1113
1126
  }
1114
- function nt(i, e) {
1127
+ function it(i, e) {
1115
1128
  return e === "landscape" ? { height: i.width, width: i.height } : i;
1116
1129
  }
1117
1130
  const w = "\x1B[43mREPORT\x1B[0m";
@@ -1122,7 +1135,7 @@ class ht {
1122
1135
  _pendingPaginateResolvers;
1123
1136
  _currentAbortController;
1124
1137
  constructor() {
1125
- this._sections = /* @__PURE__ */ new Map(), this._monitor = new de(), this._paginationInProgress = !1, this._pendingPaginateResolvers = [], this._currentAbortController = null, window[He] = !0, this._injectStyle(v.globalStyle);
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);
1126
1139
  }
1127
1140
  /**
1128
1141
  * Monitor instance used to subscribe to pagination events.
@@ -1159,7 +1172,7 @@ class ht {
1159
1172
  context: o,
1160
1173
  options: {
1161
1174
  ...e,
1162
- size: nt(
1175
+ size: it(
1163
1176
  e.size,
1164
1177
  e.orientation ?? "portrait"
1165
1178
  )
@@ -1186,7 +1199,7 @@ class ht {
1186
1199
  * `suspension` property of the returned result object.
1187
1200
  */
1188
1201
  async schedulePagination() {
1189
- return this._sections.size === 0 ? (window[te] = !0, {
1202
+ return this._sections.size === 0 ? (window[ne] = !0, {
1190
1203
  sections: [],
1191
1204
  suspension: Promise.resolve()
1192
1205
  }) : (this._paginationInProgress && this._currentAbortController && (g.debug(
@@ -1215,7 +1228,7 @@ class ht {
1215
1228
  async getJsonData(e) {
1216
1229
  return await this._lazyJsonDataReader().catch(() => e) ?? e ?? null;
1217
1230
  }
1218
- _lazyJsonDataReader = De(We);
1231
+ _lazyJsonDataReader = je(We);
1219
1232
  async _executePagination() {
1220
1233
  this._paginationInProgress = !0, this._currentAbortController = new AbortController();
1221
1234
  const e = this._currentAbortController.signal;
@@ -1227,20 +1240,20 @@ class ht {
1227
1240
  const t = [];
1228
1241
  for (const o of this._sections.values()) {
1229
1242
  o.context.isPaginated = !1;
1230
- const r = new D();
1243
+ const r = new R();
1231
1244
  await r.add(o.options.suspense), r.monitor.addEventListener("onChange", (s) => {
1232
1245
  g.debug(
1233
1246
  w,
1234
1247
  `${s} pending promises in section '${o.options.id}'.`
1235
1248
  );
1236
- }), r.promise.then(async () => {
1249
+ }), r.then(async () => {
1237
1250
  e.aborted || (g.debug(
1238
1251
  w,
1239
1252
  `Start paginating section '${o.options.id}'.`
1240
- ), o.context.isSuspended = !1, this._paginateSection(o));
1253
+ ), o.context.isSuspended = !1, await this._paginateSection(o));
1241
1254
  }), t.push(r);
1242
1255
  }
1243
- const n = new D();
1256
+ const n = new R();
1244
1257
  return n.monitor.addEventListener("onChange", async () => {
1245
1258
  g.debug(w, "Report pagination completed."), await this._monitor.dispatch("paginationCycleCompleted", {
1246
1259
  sections: [...this._sections.values()].map(
@@ -1249,10 +1262,10 @@ class ht {
1249
1262
  });
1250
1263
  }), e.aborted ? new Promise((o, r) => {
1251
1264
  this._pendingPaginateResolvers.push({ resolve: o, reject: r });
1252
- }) : (await n.add(t.map((o) => o.promise)), {
1265
+ }) : (await n.add(t.map((o) => o.toPromise())), {
1253
1266
  sections: [...this._sections.values()].map((o) => o.context),
1254
- suspension: n.promise.then(() => {
1255
- window[te] = !0;
1267
+ suspension: n.toPromise().then(() => {
1268
+ window[ne] = !0;
1256
1269
  })
1257
1270
  });
1258
1271
  } finally {
@@ -1274,9 +1287,9 @@ class ht {
1274
1287
  }
1275
1288
  _injectStyle(e) {
1276
1289
  let t = document.getElementById(
1277
- X
1290
+ K
1278
1291
  );
1279
- t || (t = document.createElement("style"), t.id = X, t.textContent = "", document.head.appendChild(t)), t.textContent = (t.textContent + e).replace(/\s+/g, " ").replace(/\s*([:;{}])\s*/g, "$1").trim();
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();
1280
1293
  }
1281
1294
  async _paginateSection(e) {
1282
1295
  const t = document.createElement("div");
@@ -1284,10 +1297,10 @@ class ht {
1284
1297
  t.style,
1285
1298
  v.page(
1286
1299
  e.options.size,
1287
- e.options.margin ?? Re.None
1300
+ e.options.margin ?? He.None
1288
1301
  )
1289
- ), ve() || Object.assign(t.style, v.outOfScreen);
1290
- const n = Xe(e.components);
1302
+ ), V() || Object.assign(t.style, v.outOfScreen);
1303
+ const n = Ke(e.components);
1291
1304
  n.sectionHeader && (Object.assign(
1292
1305
  n.sectionHeader.style,
1293
1306
  v.component
@@ -1295,18 +1308,25 @@ class ht {
1295
1308
  n.sectionFooter.style,
1296
1309
  v.component
1297
1310
  ), t.appendChild(n.sectionFooter)), document.body.appendChild(t);
1298
- const { height: o, width: r, sectionHeaderHeight: s, sectionFooterHeight: d } = $e(
1311
+ const { height: o, width: r, sectionHeaderHeight: s, sectionFooterHeight: d } = ze(
1299
1312
  n.pageContent,
1300
1313
  n.sectionHeader,
1301
1314
  n.sectionFooter
1302
- ), P = B.paginate(
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(
1303
1323
  n.pageContent,
1304
1324
  { height: o, width: r },
1305
1325
  {
1306
1326
  id: e.options.id,
1307
1327
  plugins: [
1308
- ...e.options.plugins ?? et,
1309
- ze(
1328
+ ...e.options.plugins ?? tt,
1329
+ Be(
1310
1330
  o,
1311
1331
  s,
1312
1332
  d
@@ -1315,13 +1335,13 @@ class ht {
1315
1335
  }
1316
1336
  );
1317
1337
  t.remove();
1318
- const b = P.map((_, W) => ({
1319
- pageIndex: W,
1338
+ const b = P.map((_, j) => ({
1339
+ pageIndex: j,
1320
1340
  totalPages: P.length,
1321
1341
  sectionId: e.options.id,
1322
1342
  pageContentHtml: _
1323
1343
  }));
1324
- e.onPaginationCompleted(b);
1344
+ await e.onPaginationCompleted(b);
1325
1345
  for (const _ of b)
1326
1346
  await this._monitor.dispatch("pageCompleted", _);
1327
1347
  const f = {
@@ -1336,7 +1356,7 @@ class ht {
1336
1356
  }), await this._monitor.dispatch("sectionCompleted", f);
1337
1357
  }
1338
1358
  }
1339
- const ie = [
1359
+ const oe = [
1340
1360
  "ad",
1341
1361
  "adipisicing",
1342
1362
  "aliqua",
@@ -1406,53 +1426,53 @@ function mt(i, e) {
1406
1426
  const t = [], n = Math.floor(e * 982451653);
1407
1427
  for (let o = 0; o < i; o++) {
1408
1428
  const r = (n + o * 2654435761) % Math.pow(2, 32), s = Math.floor(
1409
- r / Math.pow(2, 32) * ie.length
1429
+ r / Math.pow(2, 32) * oe.length
1410
1430
  );
1411
- t.push(ie[s]);
1431
+ t.push(oe[s]);
1412
1432
  }
1413
1433
  return t.length > 0 && (t[0] = t[0].charAt(0).toUpperCase() + t[0].slice(1)), t.join(" ") + ".";
1414
1434
  }
1415
1435
  export {
1416
- de as EventDispatcher,
1417
- Ye as PageBreakPlugin,
1418
- B as Paginator,
1436
+ ge as EventDispatcher,
1437
+ Qe as PageBreakPlugin,
1438
+ D as Paginator,
1419
1439
  ht as ReportBuilder,
1420
1440
  pt as SectionTocPlugin,
1421
1441
  h as SplitResult,
1422
- Qe as TablePlugin,
1423
- nt as adjustPageSize,
1442
+ et as TablePlugin,
1443
+ it as adjustPageSize,
1424
1444
  C as attributePrefix,
1425
1445
  ut as buildPageId,
1426
- Xe as cloneComponents,
1446
+ Ke as cloneComponents,
1427
1447
  mt as createLoremIpsumParagraph,
1428
- it as currentElementClassName,
1429
- ot as currentTextClassName,
1448
+ ot as currentElementClassName,
1449
+ rt as currentTextClassName,
1430
1450
  gt as debugPlugin,
1431
- et as defaultPlugins,
1432
- at as enableDebugMode,
1433
- $ as getVisibleHeight,
1434
- je as globalStyle,
1435
- X as globalStyleId,
1436
- rt as ignoredElementClassName,
1437
- st as ignoredTextClassName,
1438
- ve as isDebugMode,
1439
- re as isElement,
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,
1440
1460
  be as isTextNode,
1441
1461
  ct as layoutOptionsToAttributes,
1442
1462
  g as logger,
1443
- me as loggerName,
1444
- lt as moveOffscreen,
1445
- Ke as pageBreakAttributeName,
1463
+ fe as loggerName,
1464
+ ye as moveOffscreen,
1465
+ Ye as pageBreakAttributeName,
1446
1466
  U as pageClassName,
1447
- Re as pageMargin,
1467
+ He as pageMargin,
1448
1468
  dt as pageSize,
1449
- He as paprize_isInitialized,
1450
- te as paprize_isReady,
1451
- ne as paprize_readJsonDataFile,
1469
+ Oe as paprize_isInitialized,
1470
+ ne as paprize_isReady,
1471
+ ie as paprize_readJsonDataFile,
1452
1472
  T as previewClassName,
1453
1473
  v as reportStyles,
1454
- _e as sectionClassName,
1455
- tt as sectionTocName,
1456
- fe as tempContainerClassName
1474
+ ve as sectionClassName,
1475
+ nt as sectionTocName,
1476
+ _e as tempContainerClassName
1457
1477
  };
1458
1478
  //# sourceMappingURL=paprize-core.js.map