@paprize/core 0.0.2 → 0.0.4

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,43 +1,43 @@
1
- const ie = "paprize", re = "pz-temp-container", xe = "pz-current-element", we = "pz-current-text", ke = "pz-ignored-element", Te = "pz-ignored-text", Pe = "pz-page", V = "data-pz-";
2
- let G = !1;
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
3
  const Le = () => {
4
- G = !0;
5
- }, Ae = () => G;
6
- function j(n) {
7
- return n.nodeType === Node.ELEMENT_NODE;
4
+ J = !0;
5
+ }, Fe = () => J;
6
+ function X(i) {
7
+ return i.nodeType === Node.ELEMENT_NODE;
8
8
  }
9
- function ae(n) {
10
- return n.nodeType === Node.TEXT_NODE;
9
+ function se(i) {
10
+ return i.nodeType === Node.TEXT_NODE;
11
11
  }
12
- function se(n) {
13
- const e = n.getBoundingClientRect(), t = getComputedStyle(n), o = parseFloat(t.marginTop) || 0, i = parseFloat(t.marginBottom) || 0;
14
- return e.height + o + i;
12
+ function le(i) {
13
+ const e = i.getBoundingClientRect(), t = getComputedStyle(i), n = parseFloat(t.marginTop) || 0, o = parseFloat(t.marginBottom) || 0;
14
+ return e.height + n + o;
15
15
  }
16
- function Fe(n) {
17
- n.style.visibility = "hidden", n.style.position = "absolute", n.style.left = "-9999px", n.style.top = "-9999px";
16
+ function Ie(i) {
17
+ i.style.visibility = "hidden", i.style.position = "absolute", i.style.left = "-9999px", i.style.top = "-9999px";
18
18
  }
19
19
  class v {
20
20
  name;
21
21
  defaultValue;
22
22
  _reader;
23
- constructor(e, t, o) {
24
- this.name = e, this._reader = t, this.defaultValue = o;
23
+ constructor(e, t, n) {
24
+ this.name = e, this._reader = t, this.defaultValue = n;
25
25
  }
26
26
  read(e) {
27
27
  return this._reader(e);
28
28
  }
29
29
  static createStr(e, t) {
30
- return new v(e, (o) => o, t);
30
+ return new v(e, (n) => n, t);
31
31
  }
32
32
  static createBool(e, t) {
33
33
  return new v(
34
34
  e,
35
- (o) => o === "true",
35
+ (n) => n === "true",
36
36
  t
37
37
  );
38
38
  }
39
39
  }
40
- const P = {
40
+ const A = {
41
41
  hyphen: v.createStr("hyphen", "-"),
42
42
  keepOnSamePage: v.createBool("keep-on-same-page", !1),
43
43
  hyphenationEnabled: v.createBool(
@@ -45,113 +45,114 @@ const P = {
45
45
  !0
46
46
  )
47
47
  };
48
- function Ie(n) {
48
+ function Re(i) {
49
49
  const e = {};
50
- for (const t in n) {
51
- const o = n[t];
52
- if (o !== void 0) {
53
- const i = P[t];
54
- e[`${V}${i.name}`] = String(o);
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
55
  }
56
56
  }
57
57
  return e;
58
58
  }
59
- const le = Object.fromEntries(
60
- Object.entries(P).map(([n, e]) => [
61
- n,
59
+ const ce = Object.fromEntries(
60
+ Object.entries(A).map(([i, e]) => [
61
+ i,
62
62
  e.defaultValue
63
63
  ])
64
- ), M = /* @__PURE__ */ new WeakMap();
65
- function X(n) {
66
- if (!n)
64
+ ), z = /* @__PURE__ */ new WeakMap();
65
+ function j(i) {
66
+ if (!i)
67
67
  return {};
68
- if (!(n instanceof Element))
69
- return X(n?.parentNode);
68
+ if (!(i instanceof Element))
69
+ return j(i?.parentNode);
70
70
  const e = {};
71
- for (const i in P) {
72
- const a = P[i], s = `${V}${a.name}`, p = n.getAttribute(s);
73
- p !== null && (e[i] = a.read(p));
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));
74
74
  }
75
- const o = { ...n.parentNode ? M.get(n.parentNode) : void 0, ...e };
76
- return M.set(n, o), o;
75
+ const n = { ...i.parentNode ? z.get(i.parentNode) : void 0, ...e };
76
+ return z.set(i, n), n;
77
77
  }
78
- const J = {
78
+ const Y = {
79
+ id: "default",
79
80
  plugins: [],
80
- ...le
81
+ ...ce
81
82
  };
82
- function ce(n, e) {
83
- const t = X(n);
84
- return { ...J, ...e, ...t };
83
+ function de(i, e) {
84
+ const t = j(i);
85
+ return { ...Y, ...e, ...t };
85
86
  }
86
- function ue(n) {
87
- return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
87
+ function ue(i) {
88
+ return i && i.__esModule && Object.prototype.hasOwnProperty.call(i, "default") ? i.default : i;
88
89
  }
89
- var T = { exports: {} }, de = T.exports, D;
90
+ var k = { exports: {} }, ge = k.exports, U;
90
91
  function pe() {
91
- return D || (D = 1, (function(n) {
92
+ return U || (U = 1, (function(i) {
92
93
  (function(e, t) {
93
- n.exports ? n.exports = t() : e.log = t();
94
- })(de, function() {
94
+ i.exports ? i.exports = t() : e.log = t();
95
+ })(ge, function() {
95
96
  var e = function() {
96
- }, t = "undefined", o = typeof window !== t && typeof window.navigator !== t && /Trident\/|MSIE /.test(window.navigator.userAgent), i = [
97
+ }, t = "undefined", n = typeof window !== t && typeof window.navigator !== t && /Trident\/|MSIE /.test(window.navigator.userAgent), o = [
97
98
  "trace",
98
99
  "debug",
99
100
  "info",
100
101
  "warn",
101
102
  "error"
102
- ], a = {}, s = null;
103
- function p(l, u) {
104
- var r = l[u];
105
- if (typeof r.bind == "function")
106
- return r.bind(l);
103
+ ], r = {}, s = null;
104
+ function g(l, d) {
105
+ var a = l[d];
106
+ if (typeof a.bind == "function")
107
+ return a.bind(l);
107
108
  try {
108
- return Function.prototype.bind.call(r, l);
109
+ return Function.prototype.bind.call(a, l);
109
110
  } catch {
110
111
  return function() {
111
- return Function.prototype.apply.apply(r, [l, arguments]);
112
+ return Function.prototype.apply.apply(a, [l, arguments]);
112
113
  };
113
114
  }
114
115
  }
115
- function K() {
116
+ function Z() {
116
117
  console.log && (console.log.apply ? console.log.apply(console, arguments) : Function.prototype.apply.apply(console.log, [console, arguments])), console.trace && console.trace();
117
118
  }
118
- function Y(l) {
119
- return l === "debug" && (l = "log"), typeof console === t ? !1 : l === "trace" && o ? K : console[l] !== void 0 ? p(console, l) : console.log !== void 0 ? p(console, "log") : e;
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;
120
121
  }
121
- function y() {
122
- for (var l = this.getLevel(), u = 0; u < i.length; u++) {
123
- var r = i[u];
124
- this[r] = u < l ? e : this.methodFactory(r, l, this.name);
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);
125
126
  }
126
127
  if (this.log = this.debug, typeof console === t && l < this.levels.SILENT)
127
128
  return "No console available for logging";
128
129
  }
129
130
  function Q(l) {
130
131
  return function() {
131
- typeof console !== t && (y.call(this), this[l].apply(this, arguments));
132
+ typeof console !== t && (b.call(this), this[l].apply(this, arguments));
132
133
  };
133
134
  }
134
- function Z(l, u, r) {
135
- return Y(l) || Q.apply(this, arguments);
135
+ function ee(l, d, a) {
136
+ return K(l) || Q.apply(this, arguments);
136
137
  }
137
- function B(l, u) {
138
- var r = this, w, L, m, f = "loglevel";
138
+ function $(l, d) {
139
+ var a = this, P, L, m, f = "loglevel";
139
140
  typeof l == "string" ? f += ":" + l : typeof l == "symbol" && (f = void 0);
140
- function te(c) {
141
- var d = (i[c] || "silent").toUpperCase();
141
+ function ne(c) {
142
+ var u = (o[c] || "silent").toUpperCase();
142
143
  if (!(typeof window === t || !f)) {
143
144
  try {
144
- window.localStorage[f] = d;
145
+ window.localStorage[f] = u;
145
146
  return;
146
147
  } catch {
147
148
  }
148
149
  try {
149
- window.document.cookie = encodeURIComponent(f) + "=" + d + ";";
150
+ window.document.cookie = encodeURIComponent(f) + "=" + u + ";";
150
151
  } catch {
151
152
  }
152
153
  }
153
154
  }
154
- function H() {
155
+ function B() {
155
156
  var c;
156
157
  if (!(typeof window === t || !f)) {
157
158
  try {
@@ -160,16 +161,16 @@ function pe() {
160
161
  }
161
162
  if (typeof c === t)
162
163
  try {
163
- var d = window.document.cookie, k = encodeURIComponent(f), $ = d.indexOf(k + "=");
164
- $ !== -1 && (c = /^([^;]+)/.exec(
165
- d.slice($ + k.length + 1)
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)
166
167
  )[1]);
167
168
  } catch {
168
169
  }
169
- return r.levels[c] === void 0 && (c = void 0), c;
170
+ return a.levels[c] === void 0 && (c = void 0), c;
170
171
  }
171
172
  }
172
- function ne() {
173
+ function ie() {
173
174
  if (!(typeof window === t || !f)) {
174
175
  try {
175
176
  window.localStorage.removeItem(f);
@@ -181,83 +182,83 @@ function pe() {
181
182
  }
182
183
  }
183
184
  }
184
- function b(c) {
185
- var d = c;
186
- if (typeof d == "string" && r.levels[d.toUpperCase()] !== void 0 && (d = r.levels[d.toUpperCase()]), typeof d == "number" && d >= 0 && d <= r.levels.SILENT)
187
- return d;
185
+ function y(c) {
186
+ var u = c;
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
+ return u;
188
189
  throw new TypeError("log.setLevel() called with invalid level: " + c);
189
190
  }
190
- r.name = l, r.levels = {
191
+ a.name = l, a.levels = {
191
192
  TRACE: 0,
192
193
  DEBUG: 1,
193
194
  INFO: 2,
194
195
  WARN: 3,
195
196
  ERROR: 4,
196
197
  SILENT: 5
197
- }, r.methodFactory = u || Z, r.getLevel = function() {
198
- return m ?? L ?? w;
199
- }, r.setLevel = function(c, d) {
200
- return m = b(c), d !== !1 && te(m), y.call(r);
201
- }, r.setDefaultLevel = function(c) {
202
- L = b(c), H() || r.setLevel(c, !1);
203
- }, r.resetLevel = function() {
204
- m = null, ne(), y.call(r);
205
- }, r.enableAll = function(c) {
206
- r.setLevel(r.levels.TRACE, c);
207
- }, r.disableAll = function(c) {
208
- r.setLevel(r.levels.SILENT, c);
209
- }, r.rebuild = function() {
210
- if (s !== r && (w = b(s.getLevel())), y.call(r), s === r)
211
- for (var c in a)
212
- a[c].rebuild();
213
- }, w = b(
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);
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);
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(
214
215
  s ? s.getLevel() : "WARN"
215
216
  );
216
- var W = H();
217
- W != null && (m = b(W)), y.call(r);
217
+ var W = B();
218
+ W != null && (m = y(W)), b.call(a);
218
219
  }
219
- s = new B(), s.getLogger = function(u) {
220
- if (typeof u != "symbol" && typeof u != "string" || u === "")
220
+ s = new $(), s.getLogger = function(d) {
221
+ if (typeof d != "symbol" && typeof d != "string" || d === "")
221
222
  throw new TypeError("You must supply a name when creating a logger.");
222
- var r = a[u];
223
- return r || (r = a[u] = new B(
224
- u,
223
+ var a = r[d];
224
+ return a || (a = r[d] = new $(
225
+ d,
225
226
  s.methodFactory
226
- )), r;
227
+ )), a;
227
228
  };
228
- var ee = typeof window !== t ? window.log : void 0;
229
+ var te = typeof window !== t ? window.log : void 0;
229
230
  return s.noConflict = function() {
230
- return typeof window !== t && window.log === s && (window.log = ee), s;
231
+ return typeof window !== t && window.log === s && (window.log = te), s;
231
232
  }, s.getLoggers = function() {
232
- return a;
233
+ return r;
233
234
  }, s.default = s, s;
234
235
  });
235
- })(T)), T.exports;
236
+ })(k)), k.exports;
236
237
  }
237
- var ge = pe();
238
- const _ = /* @__PURE__ */ ue(ge), h = _.getLogger(ie);
238
+ var he = pe();
239
+ const _ = /* @__PURE__ */ ue(he), h = _.getLogger(re);
239
240
  h.setDefaultLevel("info");
240
- const A = "\x1B[46mPLUGIN\x1B[0m";
241
- function N(n, e, ...t) {
242
- n.forEach((o) => {
243
- const i = o[e];
244
- if (i) {
241
+ const F = "\x1B[46mPLUGIN\x1B[0m";
242
+ function N(i, e, ...t) {
243
+ i.sort((n, o) => n.order - o.order).forEach((n) => {
244
+ const o = n[e];
245
+ if (o) {
245
246
  h.debug(
246
- A,
247
- `executing plugin ${o.name}:${String(e)}`,
247
+ F,
248
+ `executing plugin ${n.name}:${String(e)} ()`,
248
249
  t
249
250
  );
250
251
  try {
251
- i(...t), h.debug(
252
- A,
253
- `plugin ${o.name}:${String(e)} executed`,
252
+ o(...t), h.debug(
253
+ F,
254
+ `plugin ${n.name}:${String(e)} executed`,
254
255
  t
255
256
  );
256
- } catch (a) {
257
+ } catch (r) {
257
258
  h.debug(
258
- A,
259
- `plugin ${o.name}:${String(e)} failed`,
260
- a
259
+ F,
260
+ `plugin ${n.name}:${String(e)} failed`,
261
+ r
261
262
  );
262
263
  }
263
264
  }
@@ -272,8 +273,8 @@ class O {
272
273
  _transaction;
273
274
  type = S.Element;
274
275
  config;
275
- constructor(e, t, o) {
276
- this._node = e, this._transaction = t, this.config = o;
276
+ constructor(e, t, n) {
277
+ this._node = e, this._transaction = t, this.config = n;
277
278
  }
278
279
  appendChild(e) {
279
280
  this._transaction.isActive && this._transaction.addRollbackCallback(() => {
@@ -281,7 +282,7 @@ class O {
281
282
  }), this._node.appendChild(e.getNode());
282
283
  }
283
284
  clone(e) {
284
- const t = this._node.cloneNode(e), o = new O(
285
+ const t = this._node.cloneNode(e), n = new O(
285
286
  t,
286
287
  this._transaction,
287
288
  this.config
@@ -289,12 +290,13 @@ class O {
289
290
  return N(
290
291
  this.config.plugins,
291
292
  "onClone",
293
+ this.config.id,
292
294
  this._node,
293
- o
294
- ), o;
295
+ n
296
+ ), n;
295
297
  }
296
298
  getHeight() {
297
- return se(this._node);
299
+ return le(this._node);
298
300
  }
299
301
  remove() {
300
302
  this._transaction.addCommitCallback(() => {
@@ -311,13 +313,13 @@ class O {
311
313
  return this._node;
312
314
  }
313
315
  }
314
- class he {
316
+ class fe {
315
317
  _node;
316
318
  _transaction;
317
319
  type = S.Text;
318
320
  config;
319
- constructor(e, t, o) {
320
- this._node = e, this._transaction = t, this.config = o;
321
+ constructor(e, t, n) {
322
+ this._node = e, this._transaction = t, this.config = n;
321
323
  }
322
324
  get textContent() {
323
325
  return this._node.textContent ?? "";
@@ -334,23 +336,23 @@ class he {
334
336
  return this._node;
335
337
  }
336
338
  }
337
- function F(n, e, t) {
338
- if (ae(n))
339
- return new he(n, e, t);
340
- if (j(n))
341
- return new O(n, e, t);
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);
342
344
  throw new Error("Unsupported node type");
343
345
  }
344
- const C = "\x1B[106mDOM\x1B[0m";
345
- class fe {
346
+ const E = "\x1B[106mDOM\x1B[0m";
347
+ class me {
346
348
  _transaction;
347
349
  _treeWalker;
348
350
  _config;
349
351
  _completed = !1;
350
352
  _currentNode = null;
351
353
  _previousNode = null;
352
- constructor(e, t, o) {
353
- this._transaction = t, this._config = o, this._treeWalker = document.createTreeWalker(
354
+ constructor(e, t, n) {
355
+ this._transaction = t, this._config = n, this._treeWalker = document.createTreeWalker(
354
356
  e,
355
357
  NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT
356
358
  );
@@ -365,36 +367,36 @@ class fe {
365
367
  return this._previousNode;
366
368
  }
367
369
  nextNode() {
368
- this._treeWalker.nextNode() || (this._completed = !0), h.debug(C, "moving to next node"), this.setState();
370
+ this._treeWalker.nextNode() || (this._completed = !0), h.debug(E, "moving to next node"), this.setState();
369
371
  }
370
372
  nextSiblingOrParentSibling() {
371
373
  let e = 0;
372
374
  if (this._treeWalker.nextSibling())
373
- return h.debug(C, "moving to next sibling node"), this.setState(), { parentsTraversed: e };
375
+ return h.debug(E, "moving to next sibling node"), this.setState(), { parentsTraversed: e };
374
376
  for (; this._treeWalker.parentNode(); )
375
377
  if (e++, this._treeWalker.nextSibling())
376
378
  return h.debug(
377
- C,
379
+ E,
378
380
  "moving to parent sibling node, traversed:",
379
381
  e
380
382
  ), this.setState(), { parentsTraversed: e };
381
383
  return this._completed = !0, { parentsTraversed: e };
382
384
  }
383
385
  firstChildOrNextNode() {
384
- return this._treeWalker.firstChild() ? (h.debug(C, "moving to first child node"), this.setState(), { parentsTraversed: 1 }) : (this.nextNode(), { parentsTraversed: 0 });
386
+ return this._treeWalker.firstChild() ? (h.debug(E, "moving to first child node"), this.setState(), { parentsTraversed: 1 }) : (this.nextNode(), { parentsTraversed: 0 });
385
387
  }
386
388
  setState() {
387
- this._previousNode = this._currentNode, this._currentNode = F(
389
+ this._previousNode = this._currentNode, this._currentNode = I(
388
390
  this._treeWalker.currentNode,
389
391
  this._transaction,
390
- ce(this._treeWalker.currentNode, this._config)
391
- ), h.debug(C, "moved to node", {
392
+ de(this._treeWalker.currentNode, this._config)
393
+ ), h.debug(E, "moved to node", {
392
394
  currentNode: this.currentNode,
393
395
  previousNode: this.previousNode
394
396
  });
395
397
  }
396
398
  }
397
- class me {
399
+ class _e {
398
400
  _onRollback;
399
401
  _onCommit;
400
402
  isActive;
@@ -423,8 +425,8 @@ class me {
423
425
  this.isActive && (this.isActive = !1, this._onCommit.forEach((e) => e()));
424
426
  };
425
427
  }
426
- const U = "\x1B[102mPAGE\x1B[0m";
427
- class x {
428
+ const V = "\x1B[102mPAGE\x1B[0m";
429
+ class w {
428
430
  currentPage;
429
431
  activeElement;
430
432
  currentElement;
@@ -432,21 +434,21 @@ class x {
432
434
  pageIsFull;
433
435
  pageIndex;
434
436
  pageHeight;
435
- constructor(e, t, o, i, a, s, p) {
436
- this.currentPage = e, this.activeElement = t, this.currentElement = o, this.parentStack = i, this.pageIsFull = a, this.pageIndex = s, this.pageHeight = p;
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;
437
439
  }
438
- static create(e, t, o, i) {
439
- return new x(
440
+ static create(e, t, n, o) {
441
+ return new w(
440
442
  e,
441
443
  null,
442
444
  e,
443
445
  t,
444
446
  !1,
445
- o,
446
- i
447
+ n,
448
+ o
447
449
  );
448
450
  }
449
- clone = () => new x(
451
+ clone = () => new w(
450
452
  this.currentPage,
451
453
  this.activeElement,
452
454
  this.currentElement,
@@ -456,40 +458,45 @@ class x {
456
458
  this.pageHeight
457
459
  );
458
460
  }
459
- class R {
461
+ class H {
460
462
  _pageState;
461
463
  _transaction;
462
464
  _tempContainer;
463
465
  _config;
464
- constructor(e, t, o, i) {
465
- this._tempContainer = e, this._config = i, this._transaction = o;
466
- const a = R.createPageHtmlElement(
466
+ constructor(e, t, n, o) {
467
+ this._tempContainer = e, this._config = o, this._transaction = n;
468
+ const r = H.createPageHtmlElement(
467
469
  t.width
468
- ), s = this.createNewPage(a);
469
- this._pageState = x.create(s, [], 0, t.height), N(this._config.plugins, "onNewPage", this._pageState);
470
+ ), s = this.createNewPage(r);
471
+ this._pageState = w.create(s, [], 0, t.height), N(this._config.plugins, "onNewPage", o.id, this);
470
472
  }
471
473
  nextPage() {
472
474
  const e = this.createNewPage(
473
475
  this._pageState.currentPage.getNode().cloneNode(!1)
474
- ), t = x.create(
476
+ ), t = w.create(
475
477
  e,
476
478
  [],
477
479
  this._pageState.pageIndex + 1,
478
480
  this._pageState.pageHeight
479
481
  );
480
- this.cloneParentStackToNewPage(t), this.cleanupEmptyParent(), this._pageState = t, N(this._config.plugins, "onNewPage", this._pageState);
482
+ this.cloneParentStackToNewPage(t), this.cleanupEmptyParent(), this._pageState = t, N(
483
+ this._config.plugins,
484
+ "onNewPage",
485
+ this._config.id,
486
+ this
487
+ );
481
488
  }
482
489
  cloneParentStackToNewPage(e) {
483
490
  for (const t of this._pageState.parentStack) {
484
- const o = t.clone(!1);
485
- e.currentElement.appendChild(o), e.currentElement = o, e.parentStack.push(o);
491
+ const n = t.clone(!1);
492
+ e.currentElement.appendChild(n), e.currentElement = n, e.parentStack.push(n);
486
493
  }
487
494
  }
488
495
  cleanupEmptyParent() {
489
496
  const e = [...this._pageState.parentStack], t = () => {
490
- for (let o = e.length - 1; o >= 0; o--) {
491
- const i = e[o];
492
- i.isEmpty() && i.remove();
497
+ for (let n = e.length - 1; n >= 0; n--) {
498
+ const o = e[n];
499
+ o.isEmpty() && o.remove();
493
500
  }
494
501
  };
495
502
  this._transaction.addCommitCallback(t);
@@ -498,7 +505,7 @@ class R {
498
505
  if (!this._pageState.activeElement || this._pageState.activeElement.type !== S.Element)
499
506
  throw new Error("Invalid state: activeElement is not an Element");
500
507
  h.debug(
501
- U,
508
+ V,
502
509
  "entering an element",
503
510
  this._pageState.activeElement
504
511
  ), this._pageState.currentElement = this._pageState.activeElement, this._pageState.parentStack.push(this._pageState.activeElement);
@@ -506,18 +513,18 @@ class R {
506
513
  leaveElement() {
507
514
  this._pageState.activeElement = null;
508
515
  const e = this._pageState.parentStack.pop();
509
- h.debug(U, "leaving a parent element", e);
516
+ h.debug(V, "leaving a parent element", e);
510
517
  const t = this._pageState.parentStack.at(-1);
511
518
  this._pageState.currentElement = t ?? this._pageState.currentPage;
512
519
  }
513
520
  static createPageHtmlElement(e) {
514
521
  const t = document.createElement("div");
515
- return t.style.display = "flex", t.style.flexDirection = "column", t.style.width = `${e}px`, t.style.maxWidth = `${e}px`, t;
522
+ return t.style.width = `${e}px`, t.style.maxWidth = `${e}px`, t;
516
523
  }
517
524
  createNewPage(e) {
518
525
  return this._tempContainer.appendChild(e), this._transaction.isActive && this._transaction.addRollbackCallback(() => {
519
526
  this._tempContainer.removeChild(e);
520
- }), F(e, this._transaction, this._config);
527
+ }), I(e, this._transaction, this._config);
521
528
  }
522
529
  startTransaction() {
523
530
  this._transaction.start();
@@ -527,7 +534,7 @@ class R {
527
534
  }), this._transaction;
528
535
  }
529
536
  hasEmptySpace(e) {
530
- return !this._pageState.pageIsFull && this._pageState.currentPage.getHeight() + (e || 1) <= this._pageState.pageHeight;
537
+ return !this._pageState.pageIsFull && this._pageState.currentPage.getHeight() + (e || 1e-4) <= this._pageState.pageHeight;
531
538
  }
532
539
  isOverFlow() {
533
540
  return this._pageState.currentPage.getHeight() > this._pageState.pageHeight;
@@ -536,21 +543,24 @@ class R {
536
543
  this._pageState.pageIsFull = !0;
537
544
  }
538
545
  appendChild(e, t) {
539
- const o = e.clone(t);
540
- return this._pageState.currentElement.appendChild(o), this._pageState.activeElement = o, o;
546
+ const n = e.clone(t);
547
+ return this._pageState.currentElement.appendChild(n), this._pageState.activeElement = n, n;
541
548
  }
542
549
  addTextNode(e) {
543
550
  if (this._pageState.activeElement?.type === S.Text)
544
551
  return this._pageState.activeElement;
545
- const t = document.createTextNode(e), o = F(
552
+ const t = document.createTextNode(e), n = I(
546
553
  t,
547
554
  this._transaction,
548
555
  this._config
549
556
  );
550
- return this._pageState.currentElement.appendChild(o), this._pageState.activeElement = o, o;
557
+ return this._pageState.currentElement.appendChild(n), this._pageState.activeElement = n, n;
558
+ }
559
+ getPageState() {
560
+ return this._pageState;
551
561
  }
552
562
  }
553
- const g = {
563
+ const p = {
554
564
  None: 0,
555
565
  // The node fits completely on the page, no further splitting required.
556
566
  FullNodePlaced: 1,
@@ -558,157 +568,159 @@ const g = {
558
568
  SplitChildren: 2
559
569
  // The node is too large for the page, and its children must be paginated individually.
560
570
  };
561
- function _e(n, e) {
562
- const t = z(n, e);
563
- if (t !== g.None)
571
+ function ve(i, e) {
572
+ const t = q(i, e);
573
+ if (t !== p.None)
564
574
  return t;
565
- const { rollback: o, commit: i } = e.startTransaction();
575
+ const { rollback: n, commit: o } = e.startTransaction();
566
576
  e.nextPage();
567
- const a = z(n, e);
568
- return a !== g.None ? (i(), a) : (o(), h.debug("Element is too big to fit on a page", n), g.None);
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);
569
579
  }
570
- function z(n, e) {
571
- if (e.hasEmptySpace(n.getHeight())) {
572
- const o = e.appendChild(n, !0);
580
+ function q(i, e) {
581
+ if (e.hasEmptySpace(i.getHeight())) {
582
+ const n = e.appendChild(i, !0);
573
583
  if (e.isOverFlow())
574
- o.remove();
584
+ n.remove();
575
585
  else
576
- return g.FullNodePlaced;
586
+ return p.FullNodePlaced;
577
587
  }
578
- if (n.config.keepOnSamePage || n.getChildrenCount() === 0)
579
- return g.None;
580
- const t = e.appendChild(n, !1);
581
- return e.isOverFlow() ? (t.remove(), g.None) : g.SplitChildren;
588
+ if (i.config.keepOnSamePage || i.getChildrenCount() === 0)
589
+ return p.None;
590
+ const t = e.appendChild(i, !1);
591
+ return e.isOverFlow() ? (t.remove(), p.None) : p.SplitChildren;
582
592
  }
583
- function ve(n, e) {
584
- let t = g.FullNodePlaced;
585
- const o = n.textContent.split(/(\s+)/).filter((s) => s !== "");
586
- let i, a = 0;
587
- for (; i || a < o.length; ) {
588
- const s = i ?? o[a], p = Ne(s, e, n.config);
589
- p.completed || (t = g.None), p.pendingToken ? i = p.pendingToken : (i = void 0, a++);
593
+ function Ne(i, e) {
594
+ let t = p.FullNodePlaced;
595
+ const n = i.textContent.split(/(\s+)/).filter((s) => s !== "");
596
+ let o, r = 0;
597
+ 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++);
590
600
  }
591
601
  return t;
592
602
  }
593
- function Ne(n, e, t) {
603
+ function Se(i, e, t) {
594
604
  e.hasEmptySpace() || e.nextPage();
595
- let o = e.addTextNode("");
596
- const i = o.textContent;
597
- if (o.textContent += n, !e.isOverFlow())
605
+ let n = e.addTextNode("");
606
+ const o = n.textContent;
607
+ if (n.textContent += i, !e.isOverFlow())
598
608
  return {
599
609
  completed: !0
600
610
  };
601
- o.textContent = i;
602
- const a = Se(n, e, t);
611
+ n.textContent = o;
612
+ const r = be(i, e, t);
603
613
  return {
604
- pendingToken: a.leftovers,
605
- completed: a.completed
614
+ pendingToken: r.leftovers,
615
+ completed: r.completed
606
616
  };
607
617
  }
608
- function Se(n, e, t) {
609
- const { rollback: o, commit: i } = e.startTransaction();
610
- if (e.nextPage(), e.addTextNode(n), !e.isOverFlow())
611
- return i(), {
618
+ function be(i, e, t) {
619
+ const { rollback: n, commit: o } = e.startTransaction();
620
+ if (e.nextPage(), e.addTextNode(i), !e.isOverFlow())
621
+ return o(), {
612
622
  completed: !0
613
623
  };
614
- if (o(), !t.hyphenationEnabled)
615
- return h.warn("Hyphenation disabled, skipping oversized token:", n), {
624
+ if (n(), !t.hyphenationEnabled)
625
+ return h.warn("Hyphenation disabled, skipping oversized token:", i), {
616
626
  completed: !1
617
627
  };
618
- const a = ye(n, t.hyphen, e);
628
+ const r = ye(i, t.hyphen, e);
619
629
  return {
620
630
  completed: !0,
621
- leftovers: a && a.length > 0 ? a : void 0
631
+ leftovers: r && r.length > 0 ? r : void 0
622
632
  };
623
633
  }
624
- function ye(n, e, t) {
625
- const o = t.addTextNode("");
626
- let i = "";
627
- for (let a = 0; a < n.length; a++) {
628
- const s = n[a], p = i + s;
629
- if (o.textContent = p + e, !t.hasEmptySpace())
630
- return o.textContent = i ? i + e : "", t.markPageAsFull(), n.slice(a);
631
- i = p;
634
+ function ye(i, e, t) {
635
+ const n = t.addTextNode("");
636
+ let o = "";
637
+ for (let r = 0; r < i.length; r++) {
638
+ const s = i[r], g = o + s;
639
+ if (n.textContent = g + e, !t.hasEmptySpace())
640
+ return n.textContent = o ? o + e : "", t.markPageAsFull(), i.slice(r);
641
+ o = g;
632
642
  }
633
643
  return null;
634
644
  }
635
- const E = "\x1B[103mPAGINATOR\x1B[0m";
636
- class I {
645
+ const C = "\x1B[103mPAGINATOR\x1B[0m";
646
+ class R {
637
647
  _domState;
638
648
  _pageManager;
639
649
  _transaction;
640
650
  _tempContainer;
641
651
  _config;
642
- constructor(e, t, o) {
643
- this._config = { ...J, ...o }, this._tempContainer = I.createTempContainer(), this._transaction = new me(), this._domState = new fe(e, this._transaction, this._config), this._pageManager = new R(
652
+ 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(
644
654
  this._tempContainer,
645
655
  t,
646
656
  this._transaction,
647
657
  this._config
648
658
  );
649
659
  }
650
- static createTempContainer() {
651
- const e = document.createElement("div");
652
- return e.classList.add(re), document.body.appendChild(e), e;
660
+ static createTempContainer(e) {
661
+ 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;
653
663
  }
654
- static paginate(e, t, o) {
655
- const i = new I(e, t, o);
656
- return i.processAllNodes(), Array.from(i._tempContainer.childNodes).filter((s) => j(s)).map((s) => s.innerHTML);
664
+ 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);
657
667
  }
658
668
  processAllNodes() {
659
669
  this._domState.nextNode();
660
670
  do {
661
671
  switch (_.debug(
662
- E,
672
+ C,
663
673
  "paginating node",
664
674
  this._domState.currentNode
665
675
  ), this.processCurrentNode()) {
666
- case g.None:
676
+ case p.None:
667
677
  this.handleNodeSkipped();
668
678
  break;
669
- case g.FullNodePlaced:
679
+ case p.FullNodePlaced:
670
680
  this.handleFullNodePlaced();
671
681
  break;
672
- case g.SplitChildren:
682
+ case p.SplitChildren:
673
683
  this.handleChildrenSplit();
674
684
  break;
675
685
  }
676
686
  N(
677
687
  this._config.plugins,
678
688
  "afterVisitNode",
689
+ this._config.id,
679
690
  this._domState,
680
691
  this._pageManager
681
692
  );
682
693
  } while (this._domState.completed === !1);
683
- _.debug(E, "pagination completed");
694
+ _.debug(C, "pagination completed");
684
695
  }
685
696
  handleNodeSkipped() {
686
- _.debug(E, "node skipped - couldn't paginate"), this._domState.nextNode();
697
+ _.debug(C, "node skipped - couldn't paginate"), this._domState.nextNode();
687
698
  }
688
699
  handleFullNodePlaced() {
689
- _.debug(E, "node fully paginated");
700
+ _.debug(C, "node fully paginated");
690
701
  const { parentsTraversed: e } = this._domState.nextSiblingOrParentSibling();
691
702
  for (let t = 0; t < e; t++)
692
703
  this._pageManager.leaveElement();
693
704
  }
694
705
  handleChildrenSplit() {
695
706
  _.debug(
696
- E,
707
+ C,
697
708
  "node partially paginated - splitting children"
698
709
  ), this._domState.firstChildOrNextNode().parentsTraversed === 1 && this._domState.previousNode?.type === S.Element && this._pageManager.enterElement();
699
710
  }
700
711
  processCurrentNode() {
701
712
  if (!this._domState.currentNode)
702
- return g.None;
713
+ return p.None;
703
714
  if (this._domState.currentNode.type === S.Element) {
704
715
  const e = {};
705
716
  return N(
706
717
  this._config.plugins,
707
718
  "onVisitElement",
719
+ this._config.id,
708
720
  this._domState,
709
721
  this._pageManager,
710
722
  e
711
- ), e.result !== void 0 ? e.result : _e(
723
+ ), e.result !== void 0 ? e.result : ve(
712
724
  this._domState.currentNode,
713
725
  this._pageManager
714
726
  );
@@ -717,17 +729,18 @@ class I {
717
729
  return N(
718
730
  this._config.plugins,
719
731
  "onVisitText",
732
+ this._config.id,
720
733
  this._domState,
721
734
  this._pageManager,
722
735
  e
723
- ), e.result !== void 0 ? e.result : ve(
736
+ ), e.result !== void 0 ? e.result : Ne(
724
737
  this._domState.currentNode,
725
738
  this._pageManager
726
739
  );
727
740
  }
728
741
  }
729
742
  }
730
- const q = [
743
+ const G = [
731
744
  "ad",
732
745
  "adipisicing",
733
746
  "aliqua",
@@ -791,46 +804,85 @@ const q = [
791
804
  "veniam",
792
805
  "voluptate"
793
806
  ];
794
- function Oe(n, e) {
795
- if (n <= 0)
807
+ function Oe(i, e) {
808
+ if (i <= 0)
796
809
  return "";
797
- const t = [], o = Math.floor(e * 982451653);
798
- for (let i = 0; i < n; i++) {
799
- const a = (o + i * 2654435761) % Math.pow(2, 32), s = Math.floor(
800
- a / Math.pow(2, 32) * q.length
810
+ const t = [], n = Math.floor(e * 982451653);
811
+ for (let o = 0; o < i; o++) {
812
+ const r = (n + o * 2654435761) % Math.pow(2, 32), s = Math.floor(
813
+ r / Math.pow(2, 32) * G.length
801
814
  );
802
- t.push(q[s]);
815
+ t.push(G[s]);
803
816
  }
804
817
  return t.length > 0 && (t[0] = t[0].charAt(0).toUpperCase() + t[0].slice(1)), t.join(" ") + ".";
805
818
  }
806
- const be = "data-pz-page-break", Ce = "pageBreak", Ee = {
819
+ const Ee = "data-pz-page-break", Ce = "pageBreak", xe = {
807
820
  name: Ce,
808
- onVisitElement: (n, e, t) => {
809
- n.currentNode.getNode().getAttribute(be) === "true" && (e.markPageAsFull(), t.result = g.FullNodePlaced);
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
+ );
810
834
  }
811
- }, Re = [Ee];
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";
812
858
  export {
813
- I as Paginator,
814
- g as SplitResult,
815
- V as attributePrefix,
816
- Ie as configToAttributeMap,
859
+ R as Paginator,
860
+ Be as SectionTocPlugin,
861
+ p as SplitResult,
862
+ x as attributePrefix,
863
+ Re as configToAttributeMap,
817
864
  Oe as createLoremIpsumParagraph,
818
- xe as currentElementClassName,
819
- we as currentTextClassName,
820
- Re as defaultPlugins,
865
+ Pe as currentElementClassName,
866
+ Te as currentTextClassName,
867
+ $e as debugPlugin,
868
+ He as defaultPlugins,
821
869
  Le as enableDebugMode,
822
- se as getVisibleHeight,
870
+ le as getVisibleHeight,
823
871
  ke as ignoredElementClassName,
824
- Te as ignoredTextClassName,
825
- Ae as isDebugMode,
826
- j as isElement,
827
- ae as isTextNode,
872
+ Ae as ignoredTextClassName,
873
+ Fe as isDebugMode,
874
+ X as isElement,
875
+ se as isTextNode,
828
876
  h as logger,
829
- ie as loggerName,
830
- Fe as moveOffscreen,
831
- be as pageBreakAttributeName,
832
- Ee as pageBreakPlugin,
877
+ re as loggerName,
878
+ Ie as moveOffscreen,
879
+ Ee as pageBreakAttributeName,
880
+ xe as pageBreakPlugin,
833
881
  Ce as pageBreakPluginName,
834
- Pe as pageClassName,
835
- re as tempContainerClassName
882
+ M as pageClassName,
883
+ We as paprize_isReady,
884
+ De as paprize_readJsonDataFile,
885
+ we as sectionTocName,
886
+ ae as tempContainerClassName
836
887
  };
888
+ //# sourceMappingURL=paprize-core.js.map