@paprize/core 0.0.4 → 0.0.5

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