@paprize/core 0.0.12 → 0.2.0

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