@paprize/core 0.0.4 → 0.0.6

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