@paprize/core 0.0.2 → 0.0.3
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.
- package/dist/paprize-core.d.ts +29 -5
- package/dist/paprize-core.js +324 -276
- package/dist/paprize-core.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/paprize-core.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export declare const currentElementClassName = "pz-current-element";
|
|
|
36
36
|
|
|
37
37
|
export declare const currentTextClassName = "pz-current-text";
|
|
38
38
|
|
|
39
|
+
export declare const debugPlugin: PaginationPlugin;
|
|
40
|
+
|
|
39
41
|
export declare const defaultPlugins: PaginationPlugin[];
|
|
40
42
|
|
|
41
43
|
export declare class DomState {
|
|
@@ -124,6 +126,7 @@ declare class PageManager {
|
|
|
124
126
|
markPageAsFull(): void;
|
|
125
127
|
appendChild(node: PageElement, withChildren: boolean): PageElement;
|
|
126
128
|
addTextNode(text: string): PageText;
|
|
129
|
+
getPageState(): PageState;
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
declare type PageNode = PageElement | PageText;
|
|
@@ -161,20 +164,22 @@ declare class PageText {
|
|
|
161
164
|
export declare type PaginateResult = string[];
|
|
162
165
|
|
|
163
166
|
export declare type PaginationConfig = Required<ConfigAttribute> & {
|
|
167
|
+
id: string;
|
|
164
168
|
plugins: PaginationPlugin[];
|
|
165
169
|
};
|
|
166
170
|
|
|
167
171
|
export declare interface PaginationPlugin {
|
|
168
172
|
readonly name: string;
|
|
169
|
-
|
|
173
|
+
readonly order: number;
|
|
174
|
+
onVisitText?: (id: string, domState: DomState & {
|
|
170
175
|
currentNode: PageText;
|
|
171
176
|
}, pageManager: PageManager, context: VisitContext) => void;
|
|
172
|
-
onVisitElement?: (domState: DomState & {
|
|
177
|
+
onVisitElement?: (id: string, domState: DomState & {
|
|
173
178
|
currentNode: PageElement;
|
|
174
179
|
}, pageManager: PageManager, context: VisitContext) => void;
|
|
175
|
-
afterVisitNode?: (domState: DomState, pageManager: PageManager) => void;
|
|
176
|
-
onNewPage?: (
|
|
177
|
-
onClone?: (source: Element, cloned: PageElement) => void;
|
|
180
|
+
afterVisitNode?: (id: string, domState: DomState, pageManager: PageManager) => void;
|
|
181
|
+
onNewPage?: (id: string, pageManager: PageManager) => void;
|
|
182
|
+
onClone?: (id: string, source: Element, cloned: PageElement) => void;
|
|
178
183
|
}
|
|
179
184
|
|
|
180
185
|
export declare class Paginator {
|
|
@@ -203,6 +208,25 @@ declare type SafeElement = Omit<Element, 'removeChild' | 'appendChild' | 'replac
|
|
|
203
208
|
|
|
204
209
|
declare type SafeText = Omit<Text, 'remove'>;
|
|
205
210
|
|
|
211
|
+
export declare const sectionTocName = "sectionToc";
|
|
212
|
+
|
|
213
|
+
export declare class SectionTocPlugin implements PaginationPlugin {
|
|
214
|
+
readonly state: SectionTocState[];
|
|
215
|
+
readonly name = "sectionToc";
|
|
216
|
+
readonly order = 1;
|
|
217
|
+
onVisitElement: (id: string, domState: DomState & {
|
|
218
|
+
currentNode: PageElement;
|
|
219
|
+
}, pageManager: PageManager) => void;
|
|
220
|
+
getHeadingLevel(node: SafeElement): number | null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export declare type SectionTocState = {
|
|
224
|
+
sectionId: string;
|
|
225
|
+
pageNumber: number;
|
|
226
|
+
title: string;
|
|
227
|
+
level: number;
|
|
228
|
+
};
|
|
229
|
+
|
|
206
230
|
export declare const SplitResult: {
|
|
207
231
|
readonly None: 0;
|
|
208
232
|
readonly FullNodePlaced: 1;
|
package/dist/paprize-core.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
const
|
|
2
|
-
let
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
},
|
|
6
|
-
function j(
|
|
7
|
-
return
|
|
1
|
+
const re = "paprize", ae = "pz-temp-container", ke = "pz-current-element", Te = "pz-current-text", Pe = "pz-ignored-element", Le = "pz-ignored-text", D = "pz-page", x = "data-pz-";
|
|
2
|
+
let X = !1;
|
|
3
|
+
const Ae = () => {
|
|
4
|
+
X = !0;
|
|
5
|
+
}, Fe = () => X;
|
|
6
|
+
function j(i) {
|
|
7
|
+
return i.nodeType === Node.ELEMENT_NODE;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
return
|
|
9
|
+
function se(i) {
|
|
10
|
+
return i.nodeType === Node.TEXT_NODE;
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
const e =
|
|
14
|
-
return e.height +
|
|
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
|
|
17
|
-
|
|
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,
|
|
24
|
-
this.name = e, this._reader = t, this.defaultValue =
|
|
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, (
|
|
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
|
-
(
|
|
35
|
+
(n) => n === "true",
|
|
36
36
|
t
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
const
|
|
40
|
+
const L = {
|
|
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
|
|
48
|
+
function Re(i) {
|
|
49
49
|
const e = {};
|
|
50
|
-
for (const t in
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
53
|
-
const
|
|
54
|
-
e[`${
|
|
50
|
+
for (const t in i) {
|
|
51
|
+
const n = i[t];
|
|
52
|
+
if (n !== void 0) {
|
|
53
|
+
const o = L[t];
|
|
54
|
+
e[`${x}${o.name}`] = String(n);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
return e;
|
|
58
58
|
}
|
|
59
|
-
const
|
|
60
|
-
Object.entries(
|
|
61
|
-
|
|
59
|
+
const ce = Object.fromEntries(
|
|
60
|
+
Object.entries(L).map(([i, e]) => [
|
|
61
|
+
i,
|
|
62
62
|
e.defaultValue
|
|
63
63
|
])
|
|
64
|
-
),
|
|
65
|
-
function
|
|
66
|
-
if (!
|
|
64
|
+
), U = /* @__PURE__ */ new WeakMap();
|
|
65
|
+
function J(i) {
|
|
66
|
+
if (!i)
|
|
67
67
|
return {};
|
|
68
|
-
if (!(
|
|
69
|
-
return
|
|
68
|
+
if (!(i instanceof Element))
|
|
69
|
+
return J(i?.parentNode);
|
|
70
70
|
const e = {};
|
|
71
|
-
for (const
|
|
72
|
-
const
|
|
73
|
-
|
|
71
|
+
for (const o in L) {
|
|
72
|
+
const r = L[o], s = `${x}${r.name}`, g = i.getAttribute(s);
|
|
73
|
+
g !== null && (e[o] = r.read(g));
|
|
74
74
|
}
|
|
75
|
-
const
|
|
76
|
-
return
|
|
75
|
+
const n = { ...i.parentNode ? U.get(i.parentNode) : void 0, ...e };
|
|
76
|
+
return U.set(i, n), n;
|
|
77
77
|
}
|
|
78
|
-
const
|
|
78
|
+
const K = {
|
|
79
|
+
id: "default",
|
|
79
80
|
plugins: [],
|
|
80
|
-
...
|
|
81
|
+
...ce
|
|
81
82
|
};
|
|
82
|
-
function
|
|
83
|
-
const t =
|
|
84
|
-
return { ...
|
|
83
|
+
function de(i, e) {
|
|
84
|
+
const t = J(i);
|
|
85
|
+
return { ...K, ...e, ...t };
|
|
85
86
|
}
|
|
86
|
-
function ue(
|
|
87
|
-
return
|
|
87
|
+
function ue(i) {
|
|
88
|
+
return i && i.__esModule && Object.prototype.hasOwnProperty.call(i, "default") ? i.default : i;
|
|
88
89
|
}
|
|
89
|
-
var
|
|
90
|
+
var P = { exports: {} }, ge = P.exports, z;
|
|
90
91
|
function pe() {
|
|
91
|
-
return
|
|
92
|
+
return z || (z = 1, (function(i) {
|
|
92
93
|
(function(e, t) {
|
|
93
|
-
|
|
94
|
-
})(
|
|
94
|
+
i.exports ? i.exports = t() : e.log = t();
|
|
95
|
+
})(ge, function() {
|
|
95
96
|
var e = function() {
|
|
96
|
-
}, t = "undefined",
|
|
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
|
-
],
|
|
103
|
-
function
|
|
104
|
-
var
|
|
105
|
-
if (typeof
|
|
106
|
-
return
|
|
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(
|
|
109
|
+
return Function.prototype.bind.call(a, l);
|
|
109
110
|
} catch {
|
|
110
111
|
return function() {
|
|
111
|
-
return Function.prototype.apply.apply(
|
|
112
|
+
return Function.prototype.apply.apply(a, [l, arguments]);
|
|
112
113
|
};
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
|
-
function
|
|
116
|
+
function Y() {
|
|
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
|
|
119
|
-
return l === "debug" && (l = "log"), typeof console === t ? !1 : l === "trace" &&
|
|
119
|
+
function Q(l) {
|
|
120
|
+
return l === "debug" && (l = "log"), typeof console === t ? !1 : l === "trace" && n ? Y : console[l] !== void 0 ? g(console, l) : console.log !== void 0 ? g(console, "log") : e;
|
|
120
121
|
}
|
|
121
|
-
function
|
|
122
|
-
for (var l = this.getLevel(),
|
|
123
|
-
var
|
|
124
|
-
this[
|
|
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
|
-
function
|
|
130
|
+
function Z(l) {
|
|
130
131
|
return function() {
|
|
131
|
-
typeof console !== t && (
|
|
132
|
+
typeof console !== t && (b.call(this), this[l].apply(this, arguments));
|
|
132
133
|
};
|
|
133
134
|
}
|
|
134
|
-
function
|
|
135
|
-
return
|
|
135
|
+
function ee(l, d, a) {
|
|
136
|
+
return Q(l) || Z.apply(this, arguments);
|
|
136
137
|
}
|
|
137
|
-
function
|
|
138
|
-
var
|
|
138
|
+
function $(l, d) {
|
|
139
|
+
var a = this, k, A, m, f = "loglevel";
|
|
139
140
|
typeof l == "string" ? f += ":" + l : typeof l == "symbol" && (f = void 0);
|
|
140
|
-
function
|
|
141
|
-
var
|
|
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] =
|
|
145
|
+
window.localStorage[f] = u;
|
|
145
146
|
return;
|
|
146
147
|
} catch {
|
|
147
148
|
}
|
|
148
149
|
try {
|
|
149
|
-
window.document.cookie = encodeURIComponent(f) + "=" +
|
|
150
|
+
window.document.cookie = encodeURIComponent(f) + "=" + u + ";";
|
|
150
151
|
} catch {
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
|
-
function
|
|
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
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
var u = window.document.cookie, T = encodeURIComponent(f), M = u.indexOf(T + "=");
|
|
165
|
+
M !== -1 && (c = /^([^;]+)/.exec(
|
|
166
|
+
u.slice(M + T.length + 1)
|
|
166
167
|
)[1]);
|
|
167
168
|
} catch {
|
|
168
169
|
}
|
|
169
|
-
return
|
|
170
|
+
return a.levels[c] === void 0 && (c = void 0), c;
|
|
170
171
|
}
|
|
171
172
|
}
|
|
172
|
-
function
|
|
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
|
|
185
|
-
var
|
|
186
|
-
if (typeof
|
|
187
|
-
return
|
|
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
|
-
|
|
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
|
-
},
|
|
198
|
-
return m ??
|
|
199
|
-
},
|
|
200
|
-
return m =
|
|
201
|
-
},
|
|
202
|
-
|
|
203
|
-
},
|
|
204
|
-
m = null,
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
},
|
|
208
|
-
|
|
209
|
-
},
|
|
210
|
-
if (s !==
|
|
211
|
-
for (var c in
|
|
212
|
-
|
|
213
|
-
},
|
|
198
|
+
}, a.methodFactory = d || ee, a.getLevel = function() {
|
|
199
|
+
return m ?? A ?? k;
|
|
200
|
+
}, a.setLevel = function(c, u) {
|
|
201
|
+
return m = y(c), u !== !1 && ne(m), b.call(a);
|
|
202
|
+
}, a.setDefaultLevel = function(c) {
|
|
203
|
+
A = 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 && (k = y(s.getLevel())), b.call(a), s === a)
|
|
212
|
+
for (var c in r)
|
|
213
|
+
r[c].rebuild();
|
|
214
|
+
}, k = y(
|
|
214
215
|
s ? s.getLevel() : "WARN"
|
|
215
216
|
);
|
|
216
|
-
var W =
|
|
217
|
-
W != null && (m =
|
|
217
|
+
var W = B();
|
|
218
|
+
W != null && (m = y(W)), b.call(a);
|
|
218
219
|
}
|
|
219
|
-
s = new
|
|
220
|
-
if (typeof
|
|
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
|
|
223
|
-
return
|
|
224
|
-
|
|
223
|
+
var a = r[d];
|
|
224
|
+
return a || (a = r[d] = new $(
|
|
225
|
+
d,
|
|
225
226
|
s.methodFactory
|
|
226
|
-
)),
|
|
227
|
+
)), a;
|
|
227
228
|
};
|
|
228
|
-
var
|
|
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 =
|
|
231
|
+
return typeof window !== t && window.log === s && (window.log = te), s;
|
|
231
232
|
}, s.getLoggers = function() {
|
|
232
|
-
return
|
|
233
|
+
return r;
|
|
233
234
|
}, s.default = s, s;
|
|
234
235
|
});
|
|
235
|
-
})(
|
|
236
|
+
})(P)), P.exports;
|
|
236
237
|
}
|
|
237
|
-
var
|
|
238
|
-
const _ = /* @__PURE__ */ ue(
|
|
238
|
+
var he = pe();
|
|
239
|
+
const _ = /* @__PURE__ */ ue(he), h = _.getLogger(re);
|
|
239
240
|
h.setDefaultLevel("info");
|
|
240
|
-
const
|
|
241
|
-
function N(
|
|
242
|
-
n.forEach((
|
|
243
|
-
const
|
|
244
|
-
if (
|
|
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
|
-
|
|
247
|
-
`executing plugin ${
|
|
247
|
+
F,
|
|
248
|
+
`executing plugin ${n.name}:${String(e)} ()`,
|
|
248
249
|
t
|
|
249
250
|
);
|
|
250
251
|
try {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
`plugin ${
|
|
252
|
+
o(...t), h.debug(
|
|
253
|
+
F,
|
|
254
|
+
`plugin ${n.name}:${String(e)} executed`,
|
|
254
255
|
t
|
|
255
256
|
);
|
|
256
|
-
} catch (
|
|
257
|
+
} catch (r) {
|
|
257
258
|
h.debug(
|
|
258
|
-
|
|
259
|
-
`plugin ${
|
|
260
|
-
|
|
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,
|
|
276
|
-
this._node = e, this._transaction = t, this.config =
|
|
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),
|
|
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
|
-
|
|
294
|
-
),
|
|
295
|
+
n
|
|
296
|
+
), n;
|
|
295
297
|
}
|
|
296
298
|
getHeight() {
|
|
297
|
-
return
|
|
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
|
|
316
|
+
class fe {
|
|
315
317
|
_node;
|
|
316
318
|
_transaction;
|
|
317
319
|
type = S.Text;
|
|
318
320
|
config;
|
|
319
|
-
constructor(e, t,
|
|
320
|
-
this._node = e, this._transaction = t, this.config =
|
|
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
|
|
338
|
-
if (
|
|
339
|
-
return new
|
|
340
|
-
if (j(
|
|
341
|
-
return new O(
|
|
339
|
+
function I(i, e, t) {
|
|
340
|
+
if (se(i))
|
|
341
|
+
return new fe(i, e, t);
|
|
342
|
+
if (j(i))
|
|
343
|
+
return new O(i, e, t);
|
|
342
344
|
throw new Error("Unsupported node type");
|
|
343
345
|
}
|
|
344
346
|
const C = "\x1B[106mDOM\x1B[0m";
|
|
345
|
-
class
|
|
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,
|
|
353
|
-
this._transaction = t, this._config =
|
|
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
|
);
|
|
@@ -384,17 +386,17 @@ class fe {
|
|
|
384
386
|
return this._treeWalker.firstChild() ? (h.debug(C, "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 =
|
|
389
|
+
this._previousNode = this._currentNode, this._currentNode = I(
|
|
388
390
|
this._treeWalker.currentNode,
|
|
389
391
|
this._transaction,
|
|
390
|
-
|
|
392
|
+
de(this._treeWalker.currentNode, this._config)
|
|
391
393
|
), h.debug(C, "moved to node", {
|
|
392
394
|
currentNode: this.currentNode,
|
|
393
395
|
previousNode: this.previousNode
|
|
394
396
|
});
|
|
395
397
|
}
|
|
396
398
|
}
|
|
397
|
-
class
|
|
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
|
|
427
|
-
class
|
|
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,
|
|
436
|
-
this.currentPage = e, this.activeElement = t, this.currentElement =
|
|
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,
|
|
439
|
-
return new
|
|
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
|
-
|
|
446
|
-
|
|
447
|
+
n,
|
|
448
|
+
o
|
|
447
449
|
);
|
|
448
450
|
}
|
|
449
|
-
clone = () => new
|
|
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
|
|
461
|
+
class H {
|
|
460
462
|
_pageState;
|
|
461
463
|
_transaction;
|
|
462
464
|
_tempContainer;
|
|
463
465
|
_config;
|
|
464
|
-
constructor(e, t,
|
|
465
|
-
this._tempContainer = e, this._config =
|
|
466
|
-
const
|
|
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(
|
|
469
|
-
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 =
|
|
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(
|
|
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
|
|
485
|
-
e.currentElement.appendChild(
|
|
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
|
|
491
|
-
const
|
|
492
|
-
|
|
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
|
-
|
|
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(
|
|
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.
|
|
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
|
-
}),
|
|
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 ||
|
|
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
|
|
540
|
-
return this._pageState.currentElement.appendChild(
|
|
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),
|
|
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(
|
|
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
|
|
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,102 +568,102 @@ 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
|
|
562
|
-
const t =
|
|
563
|
-
if (t !==
|
|
571
|
+
function ve(i, e) {
|
|
572
|
+
const t = q(i, e);
|
|
573
|
+
if (t !== p.None)
|
|
564
574
|
return t;
|
|
565
|
-
const { rollback:
|
|
575
|
+
const { rollback: n, commit: o } = e.startTransaction();
|
|
566
576
|
e.nextPage();
|
|
567
|
-
const
|
|
568
|
-
return
|
|
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
|
|
571
|
-
if (e.hasEmptySpace(
|
|
572
|
-
const
|
|
580
|
+
function q(i, e) {
|
|
581
|
+
if (e.hasEmptySpace(i.getHeight())) {
|
|
582
|
+
const n = e.appendChild(i, !0);
|
|
573
583
|
if (e.isOverFlow())
|
|
574
|
-
|
|
584
|
+
n.remove();
|
|
575
585
|
else
|
|
576
|
-
return
|
|
586
|
+
return p.FullNodePlaced;
|
|
577
587
|
}
|
|
578
|
-
if (
|
|
579
|
-
return
|
|
580
|
-
const t = e.appendChild(
|
|
581
|
-
return e.isOverFlow() ? (t.remove(),
|
|
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
|
|
584
|
-
let t =
|
|
585
|
-
const
|
|
586
|
-
let
|
|
587
|
-
for (;
|
|
588
|
-
const s =
|
|
589
|
-
|
|
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
|
|
603
|
+
function Se(i, e, t) {
|
|
594
604
|
e.hasEmptySpace() || e.nextPage();
|
|
595
|
-
let
|
|
596
|
-
const
|
|
597
|
-
if (
|
|
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
|
-
|
|
602
|
-
const
|
|
611
|
+
n.textContent = o;
|
|
612
|
+
const r = be(i, e, t);
|
|
603
613
|
return {
|
|
604
|
-
pendingToken:
|
|
605
|
-
completed:
|
|
614
|
+
pendingToken: r.leftovers,
|
|
615
|
+
completed: r.completed
|
|
606
616
|
};
|
|
607
617
|
}
|
|
608
|
-
function
|
|
609
|
-
const { rollback:
|
|
610
|
-
if (e.nextPage(), e.addTextNode(
|
|
611
|
-
return
|
|
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 (
|
|
615
|
-
return h.warn("Hyphenation disabled, skipping oversized token:",
|
|
624
|
+
if (n(), !t.hyphenationEnabled)
|
|
625
|
+
return h.warn("Hyphenation disabled, skipping oversized token:", i), {
|
|
616
626
|
completed: !1
|
|
617
627
|
};
|
|
618
|
-
const
|
|
628
|
+
const r = ye(i, t.hyphen, e);
|
|
619
629
|
return {
|
|
620
630
|
completed: !0,
|
|
621
|
-
leftovers:
|
|
631
|
+
leftovers: r && r.length > 0 ? r : void 0
|
|
622
632
|
};
|
|
623
633
|
}
|
|
624
|
-
function ye(
|
|
625
|
-
const
|
|
626
|
-
let
|
|
627
|
-
for (let
|
|
628
|
-
const s =
|
|
629
|
-
if (
|
|
630
|
-
return
|
|
631
|
-
|
|
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
645
|
const E = "\x1B[103mPAGINATOR\x1B[0m";
|
|
636
|
-
class
|
|
646
|
+
class R {
|
|
637
647
|
_domState;
|
|
638
648
|
_pageManager;
|
|
639
649
|
_transaction;
|
|
640
650
|
_tempContainer;
|
|
641
651
|
_config;
|
|
642
|
-
constructor(e, t,
|
|
643
|
-
this._config = { ...
|
|
652
|
+
constructor(e, t, n) {
|
|
653
|
+
this._config = { ...K, ...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
|
|
652
|
-
return e.classList.add(
|
|
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,
|
|
655
|
-
const
|
|
656
|
-
return
|
|
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) => j(s)).map((s) => s.innerHTML);
|
|
657
667
|
}
|
|
658
668
|
processAllNodes() {
|
|
659
669
|
this._domState.nextNode();
|
|
@@ -663,19 +673,20 @@ class I {
|
|
|
663
673
|
"paginating node",
|
|
664
674
|
this._domState.currentNode
|
|
665
675
|
), this.processCurrentNode()) {
|
|
666
|
-
case
|
|
676
|
+
case p.None:
|
|
667
677
|
this.handleNodeSkipped();
|
|
668
678
|
break;
|
|
669
|
-
case
|
|
679
|
+
case p.FullNodePlaced:
|
|
670
680
|
this.handleFullNodePlaced();
|
|
671
681
|
break;
|
|
672
|
-
case
|
|
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
|
);
|
|
@@ -699,16 +710,17 @@ class I {
|
|
|
699
710
|
}
|
|
700
711
|
processCurrentNode() {
|
|
701
712
|
if (!this._domState.currentNode)
|
|
702
|
-
return
|
|
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 :
|
|
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 :
|
|
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
|
|
743
|
+
const G = [
|
|
731
744
|
"ad",
|
|
732
745
|
"adipisicing",
|
|
733
746
|
"aliqua",
|
|
@@ -791,46 +804,81 @@ const q = [
|
|
|
791
804
|
"veniam",
|
|
792
805
|
"voluptate"
|
|
793
806
|
];
|
|
794
|
-
function Oe(
|
|
795
|
-
if (
|
|
807
|
+
function Oe(i, e) {
|
|
808
|
+
if (i <= 0)
|
|
796
809
|
return "";
|
|
797
|
-
const t = [],
|
|
798
|
-
for (let
|
|
799
|
-
const
|
|
800
|
-
|
|
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(
|
|
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
|
|
807
|
-
name:
|
|
808
|
-
|
|
809
|
-
|
|
819
|
+
const Ce = "data-pz-page-break", Ee = "pageBreak", xe = {
|
|
820
|
+
name: Ee,
|
|
821
|
+
order: 1,
|
|
822
|
+
onVisitElement: (i, e, t, n) => {
|
|
823
|
+
e.currentNode.getNode().getAttribute(Ce) === "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(D) || t.classList.add(D), t.setAttribute(`${x}-element`, "page"), t.setAttribute(
|
|
831
|
+
`${x}-height`,
|
|
832
|
+
e.getPageState().pageHeight.toString()
|
|
833
|
+
);
|
|
810
834
|
}
|
|
811
|
-
},
|
|
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
|
+
}
|
|
812
857
|
export {
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
858
|
+
R as Paginator,
|
|
859
|
+
Be as SectionTocPlugin,
|
|
860
|
+
p as SplitResult,
|
|
861
|
+
x as attributePrefix,
|
|
862
|
+
Re as configToAttributeMap,
|
|
817
863
|
Oe as createLoremIpsumParagraph,
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
864
|
+
ke as currentElementClassName,
|
|
865
|
+
Te as currentTextClassName,
|
|
866
|
+
$e as debugPlugin,
|
|
867
|
+
He as defaultPlugins,
|
|
868
|
+
Ae as enableDebugMode,
|
|
869
|
+
le as getVisibleHeight,
|
|
870
|
+
Pe as ignoredElementClassName,
|
|
871
|
+
Le as ignoredTextClassName,
|
|
872
|
+
Fe as isDebugMode,
|
|
826
873
|
j as isElement,
|
|
827
|
-
|
|
874
|
+
se as isTextNode,
|
|
828
875
|
h as logger,
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
876
|
+
re as loggerName,
|
|
877
|
+
Ie as moveOffscreen,
|
|
878
|
+
Ce as pageBreakAttributeName,
|
|
879
|
+
xe as pageBreakPlugin,
|
|
880
|
+
Ee as pageBreakPluginName,
|
|
881
|
+
D as pageClassName,
|
|
882
|
+
we as sectionTocName,
|
|
883
|
+
ae as tempContainerClassName
|
|
836
884
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(l=typeof globalThis<"u"?globalThis:l||self,_(l.paprize_core={}))})(this,(function(l){"use strict";const _="paprize",M="pz-temp-container",oe="pz-current-element",re="pz-current-text",ae="pz-ignored-element",se="pz-ignored-text",le="pz-page",I="data-pz-";let D=!1;const ce=()=>{D=!0},ue=()=>D;function O(n){return n.nodeType===Node.ELEMENT_NODE}function z(n){return n.nodeType===Node.TEXT_NODE}function U(n){const e=n.getBoundingClientRect(),t=getComputedStyle(n),i=parseFloat(t.marginTop)||0,o=parseFloat(t.marginBottom)||0;return e.height+i+o}function de(n){n.style.visibility="hidden",n.style.position="absolute",n.style.left="-9999px",n.style.top="-9999px"}class v{name;defaultValue;_reader;constructor(e,t,i){this.name=e,this._reader=t,this.defaultValue=i}read(e){return this._reader(e)}static createStr(e,t){return new v(e,i=>i,t)}static createBool(e,t){return new v(e,i=>i==="true",t)}}const T={hyphen:v.createStr("hyphen","-"),keepOnSamePage:v.createBool("keep-on-same-page",!1),hyphenationEnabled:v.createBool("hyphenation-enabled",!0)};function ge(n){const e={};for(const t in n){const i=n[t];if(i!==void 0){const o=T[t];e[`${I}${o.name}`]=String(i)}}return e}const pe=Object.fromEntries(Object.entries(T).map(([n,e])=>[n,e.defaultValue])),V=new WeakMap;function q(n){if(!n)return{};if(!(n instanceof Element))return q(n?.parentNode);const e={};for(const o in T){const a=T[o],s=`${I}${a.name}`,f=n.getAttribute(s);f!==null&&(e[o]=a.read(f))}const i={...n.parentNode?V.get(n.parentNode):void 0,...e};return V.set(n,i),i}const j={plugins:[],...pe};function he(n,e){const t=q(n);return{...j,...e,...t}}function fe(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var P={exports:{}},me=P.exports,G;function _e(){return G||(G=1,(function(n){(function(e,t){n.exports?n.exports=t():e.log=t()})(me,function(){var e=function(){},t="undefined",i=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"],a={},s=null;function f(c,d){var r=c[d];if(typeof r.bind=="function")return r.bind(c);try{return Function.prototype.bind.call(r,c)}catch{return function(){return Function.prototype.apply.apply(r,[c,arguments])}}}function Pe(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function Le(c){return c==="debug"&&(c="log"),typeof console===t?!1:c==="trace"&&i?Pe:console[c]!==void 0?f(console,c):console.log!==void 0?f(console,"log"):e}function k(){for(var c=this.getLevel(),d=0;d<o.length;d++){var r=o[d];this[r]=d<c?e:this.methodFactory(r,c,this.name)}if(this.log=this.debug,typeof console===t&&c<this.levels.SILENT)return"No console available for logging"}function Ae(c){return function(){typeof console!==t&&(k.call(this),this[c].apply(this,arguments))}}function Fe(c,d,r){return Le(c)||Ae.apply(this,arguments)}function ee(c,d){var r=this,A,$,y,m="loglevel";typeof c=="string"?m+=":"+c:typeof c=="symbol"&&(m=void 0);function Oe(u){var g=(o[u]||"silent").toUpperCase();if(!(typeof window===t||!m)){try{window.localStorage[m]=g;return}catch{}try{window.document.cookie=encodeURIComponent(m)+"="+g+";"}catch{}}}function te(){var u;if(!(typeof window===t||!m)){try{u=window.localStorage[m]}catch{}if(typeof u===t)try{var g=window.document.cookie,F=encodeURIComponent(m),ie=g.indexOf(F+"=");ie!==-1&&(u=/^([^;]+)/.exec(g.slice(ie+F.length+1))[1])}catch{}return r.levels[u]===void 0&&(u=void 0),u}}function Re(){if(!(typeof window===t||!m)){try{window.localStorage.removeItem(m)}catch{}try{window.document.cookie=encodeURIComponent(m)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}function x(u){var g=u;if(typeof g=="string"&&r.levels[g.toUpperCase()]!==void 0&&(g=r.levels[g.toUpperCase()]),typeof g=="number"&&g>=0&&g<=r.levels.SILENT)return g;throw new TypeError("log.setLevel() called with invalid level: "+u)}r.name=c,r.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},r.methodFactory=d||Fe,r.getLevel=function(){return y??$??A},r.setLevel=function(u,g){return y=x(u),g!==!1&&Oe(y),k.call(r)},r.setDefaultLevel=function(u){$=x(u),te()||r.setLevel(u,!1)},r.resetLevel=function(){y=null,Re(),k.call(r)},r.enableAll=function(u){r.setLevel(r.levels.TRACE,u)},r.disableAll=function(u){r.setLevel(r.levels.SILENT,u)},r.rebuild=function(){if(s!==r&&(A=x(s.getLevel())),k.call(r),s===r)for(var u in a)a[u].rebuild()},A=x(s?s.getLevel():"WARN");var ne=te();ne!=null&&(y=x(ne)),k.call(r)}s=new ee,s.getLogger=function(d){if(typeof d!="symbol"&&typeof d!="string"||d==="")throw new TypeError("You must supply a name when creating a logger.");var r=a[d];return r||(r=a[d]=new ee(d,s.methodFactory)),r};var Ie=typeof window!==t?window.log:void 0;return s.noConflict=function(){return typeof window!==t&&window.log===s&&(window.log=Ie),s},s.getLoggers=function(){return a},s.default=s,s})})(P)),P.exports}var ve=_e();const N=fe(ve),h=N.getLogger(_);h.setDefaultLevel("info");const R="\x1B[46mPLUGIN\x1B[0m";function S(n,e,...t){n.forEach(i=>{const o=i[e];if(o){h.debug(R,`executing plugin ${i.name}:${String(e)}`,t);try{o(...t),h.debug(R,`plugin ${i.name}:${String(e)} executed`,t)}catch(a){h.debug(R,`plugin ${i.name}:${String(e)} failed`,a)}}})}const b={Element:"element",Text:"text"};class B{_node;_transaction;type=b.Element;config;constructor(e,t,i){this._node=e,this._transaction=t,this.config=i}appendChild(e){this._transaction.isActive&&this._transaction.addRollbackCallback(()=>{this._node.removeChild(e.getNode())}),this._node.appendChild(e.getNode())}clone(e){const t=this._node.cloneNode(e),i=new B(t,this._transaction,this.config);return S(this.config.plugins,"onClone",this._node,i),i}getHeight(){return U(this._node)}remove(){this._transaction.addCommitCallback(()=>{this._node.remove()})}isEmpty(){return this._node.innerHTML===""}getChildrenCount(){return this._node.childNodes.length}getNode(){return this._node}}class Ne{_node;_transaction;type=b.Text;config;constructor(e,t,i){this._node=e,this._transaction=t,this.config=i}get textContent(){return this._node.textContent??""}set textContent(e){this._node.textContent=e}remove(){this._transaction.addCommitCallback(()=>{this._node.remove()})}getNode(){return this._node}}function H(n,e,t){if(z(n))return new Ne(n,e,t);if(O(n))return new B(n,e,t);throw new Error("Unsupported node type")}const C="\x1B[106mDOM\x1B[0m";class Se{_transaction;_treeWalker;_config;_completed=!1;_currentNode=null;_previousNode=null;constructor(e,t,i){this._transaction=t,this._config=i,this._treeWalker=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT)}get completed(){return this._completed}get currentNode(){return this._currentNode}get previousNode(){return this._previousNode}nextNode(){this._treeWalker.nextNode()||(this._completed=!0),h.debug(C,"moving to next node"),this.setState()}nextSiblingOrParentSibling(){let e=0;if(this._treeWalker.nextSibling())return h.debug(C,"moving to next sibling node"),this.setState(),{parentsTraversed:e};for(;this._treeWalker.parentNode();)if(e++,this._treeWalker.nextSibling())return h.debug(C,"moving to parent sibling node, traversed:",e),this.setState(),{parentsTraversed:e};return this._completed=!0,{parentsTraversed:e}}firstChildOrNextNode(){return this._treeWalker.firstChild()?(h.debug(C,"moving to first child node"),this.setState(),{parentsTraversed:1}):(this.nextNode(),{parentsTraversed:0})}setState(){this._previousNode=this._currentNode,this._currentNode=H(this._treeWalker.currentNode,this._transaction,he(this._treeWalker.currentNode,this._config)),h.debug(C,"moved to node",{currentNode:this.currentNode,previousNode:this.previousNode})}}class be{_onRollback;_onCommit;isActive;constructor(){this._onRollback=[],this._onCommit=[],this.isActive=!1}start=()=>{if(this.isActive)throw new Error("Transaction already in progress");this.isActive=!0,this._onRollback=[],this._onCommit=[]};addRollbackCallback=e=>{this._onRollback.push(e)};addCommitCallback=e=>{if(!this.isActive){e();return}this._onCommit.push(e)};rollback=()=>{this.isActive&&(this.isActive=!1,this._onRollback.forEach(e=>e()))};commit=()=>{this.isActive&&(this.isActive=!1,this._onCommit.forEach(e=>e()))}}const X="\x1B[102mPAGE\x1B[0m";class E{currentPage;activeElement;currentElement;parentStack;pageIsFull;pageIndex;pageHeight;constructor(e,t,i,o,a,s,f){this.currentPage=e,this.activeElement=t,this.currentElement=i,this.parentStack=o,this.pageIsFull=a,this.pageIndex=s,this.pageHeight=f}static create(e,t,i,o){return new E(e,null,e,t,!1,i,o)}clone=()=>new E(this.currentPage,this.activeElement,this.currentElement,[...this.parentStack],this.pageIsFull,this.pageIndex,this.pageHeight)}class W{_pageState;_transaction;_tempContainer;_config;constructor(e,t,i,o){this._tempContainer=e,this._config=o,this._transaction=i;const a=W.createPageHtmlElement(t.width),s=this.createNewPage(a);this._pageState=E.create(s,[],0,t.height),S(this._config.plugins,"onNewPage",this._pageState)}nextPage(){const e=this.createNewPage(this._pageState.currentPage.getNode().cloneNode(!1)),t=E.create(e,[],this._pageState.pageIndex+1,this._pageState.pageHeight);this.cloneParentStackToNewPage(t),this.cleanupEmptyParent(),this._pageState=t,S(this._config.plugins,"onNewPage",this._pageState)}cloneParentStackToNewPage(e){for(const t of this._pageState.parentStack){const i=t.clone(!1);e.currentElement.appendChild(i),e.currentElement=i,e.parentStack.push(i)}}cleanupEmptyParent(){const e=[...this._pageState.parentStack],t=()=>{for(let i=e.length-1;i>=0;i--){const o=e[i];o.isEmpty()&&o.remove()}};this._transaction.addCommitCallback(t)}enterElement(){if(!this._pageState.activeElement||this._pageState.activeElement.type!==b.Element)throw new Error("Invalid state: activeElement is not an Element");h.debug(X,"entering an element",this._pageState.activeElement),this._pageState.currentElement=this._pageState.activeElement,this._pageState.parentStack.push(this._pageState.activeElement)}leaveElement(){this._pageState.activeElement=null;const e=this._pageState.parentStack.pop();h.debug(X,"leaving a parent element",e);const t=this._pageState.parentStack.at(-1);this._pageState.currentElement=t??this._pageState.currentPage}static createPageHtmlElement(e){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="column",t.style.width=`${e}px`,t.style.maxWidth=`${e}px`,t}createNewPage(e){return this._tempContainer.appendChild(e),this._transaction.isActive&&this._transaction.addRollbackCallback(()=>{this._tempContainer.removeChild(e)}),H(e,this._transaction,this._config)}startTransaction(){this._transaction.start();const e=this._pageState.clone();return this._transaction.addRollbackCallback(()=>{this._pageState=e}),this._transaction}hasEmptySpace(e){return!this._pageState.pageIsFull&&this._pageState.currentPage.getHeight()+(e||1)<=this._pageState.pageHeight}isOverFlow(){return this._pageState.currentPage.getHeight()>this._pageState.pageHeight}markPageAsFull(){this._pageState.pageIsFull=!0}appendChild(e,t){const i=e.clone(t);return this._pageState.currentElement.appendChild(i),this._pageState.activeElement=i,i}addTextNode(e){if(this._pageState.activeElement?.type===b.Text)return this._pageState.activeElement;const t=document.createTextNode(e),i=H(t,this._transaction,this._config);return this._pageState.currentElement.appendChild(i),this._pageState.activeElement=i,i}}const p={None:0,FullNodePlaced:1,SplitChildren:2};function ye(n,e){const t=J(n,e);if(t!==p.None)return t;const{rollback:i,commit:o}=e.startTransaction();e.nextPage();const a=J(n,e);return a!==p.None?(o(),a):(i(),h.debug("Element is too big to fit on a page",n),p.None)}function J(n,e){if(e.hasEmptySpace(n.getHeight())){const i=e.appendChild(n,!0);if(e.isOverFlow())i.remove();else return p.FullNodePlaced}if(n.config.keepOnSamePage||n.getChildrenCount()===0)return p.None;const t=e.appendChild(n,!1);return e.isOverFlow()?(t.remove(),p.None):p.SplitChildren}function Ce(n,e){let t=p.FullNodePlaced;const i=n.textContent.split(/(\s+)/).filter(s=>s!=="");let o,a=0;for(;o||a<i.length;){const s=o??i[a],f=Ee(s,e,n.config);f.completed||(t=p.None),f.pendingToken?o=f.pendingToken:(o=void 0,a++)}return t}function Ee(n,e,t){e.hasEmptySpace()||e.nextPage();let i=e.addTextNode("");const o=i.textContent;if(i.textContent+=n,!e.isOverFlow())return{completed:!0};i.textContent=o;const a=we(n,e,t);return{pendingToken:a.leftovers,completed:a.completed}}function we(n,e,t){const{rollback:i,commit:o}=e.startTransaction();if(e.nextPage(),e.addTextNode(n),!e.isOverFlow())return o(),{completed:!0};if(i(),!t.hyphenationEnabled)return h.warn("Hyphenation disabled, skipping oversized token:",n),{completed:!1};const a=ke(n,t.hyphen,e);return{completed:!0,leftovers:a&&a.length>0?a:void 0}}function ke(n,e,t){const i=t.addTextNode("");let o="";for(let a=0;a<n.length;a++){const s=n[a],f=o+s;if(i.textContent=f+e,!t.hasEmptySpace())return i.textContent=o?o+e:"",t.markPageAsFull(),n.slice(a);o=f}return null}const w="\x1B[103mPAGINATOR\x1B[0m";class L{_domState;_pageManager;_transaction;_tempContainer;_config;constructor(e,t,i){this._config={...j,...i},this._tempContainer=L.createTempContainer(),this._transaction=new be,this._domState=new Se(e,this._transaction,this._config),this._pageManager=new W(this._tempContainer,t,this._transaction,this._config)}static createTempContainer(){const e=document.createElement("div");return e.classList.add(M),document.body.appendChild(e),e}static paginate(e,t,i){const o=new L(e,t,i);return o.processAllNodes(),Array.from(o._tempContainer.childNodes).filter(s=>O(s)).map(s=>s.innerHTML)}processAllNodes(){this._domState.nextNode();do{switch(N.debug(w,"paginating node",this._domState.currentNode),this.processCurrentNode()){case p.None:this.handleNodeSkipped();break;case p.FullNodePlaced:this.handleFullNodePlaced();break;case p.SplitChildren:this.handleChildrenSplit();break}S(this._config.plugins,"afterVisitNode",this._domState,this._pageManager)}while(this._domState.completed===!1);N.debug(w,"pagination completed")}handleNodeSkipped(){N.debug(w,"node skipped - couldn't paginate"),this._domState.nextNode()}handleFullNodePlaced(){N.debug(w,"node fully paginated");const{parentsTraversed:e}=this._domState.nextSiblingOrParentSibling();for(let t=0;t<e;t++)this._pageManager.leaveElement()}handleChildrenSplit(){N.debug(w,"node partially paginated - splitting children"),this._domState.firstChildOrNextNode().parentsTraversed===1&&this._domState.previousNode?.type===b.Element&&this._pageManager.enterElement()}processCurrentNode(){if(!this._domState.currentNode)return p.None;if(this._domState.currentNode.type===b.Element){const e={};return S(this._config.plugins,"onVisitElement",this._domState,this._pageManager,e),e.result!==void 0?e.result:ye(this._domState.currentNode,this._pageManager)}else{const e={};return S(this._config.plugins,"onVisitText",this._domState,this._pageManager,e),e.result!==void 0?e.result:Ce(this._domState.currentNode,this._pageManager)}}}const K=["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"];function xe(n,e){if(n<=0)return"";const t=[],i=Math.floor(e*982451653);for(let o=0;o<n;o++){const a=(i+o*2654435761)%Math.pow(2,32),s=Math.floor(a/Math.pow(2,32)*K.length);t.push(K[s])}return t.length>0&&(t[0]=t[0].charAt(0).toUpperCase()+t[0].slice(1)),t.join(" ")+"."}const Y="data-pz-page-break",Q="pageBreak",Z={name:Q,onVisitElement:(n,e,t)=>{n.currentNode.getNode().getAttribute(Y)==="true"&&(e.markPageAsFull(),t.result=p.FullNodePlaced)}},Te=[Z];l.Paginator=L,l.SplitResult=p,l.attributePrefix=I,l.configToAttributeMap=ge,l.createLoremIpsumParagraph=xe,l.currentElementClassName=oe,l.currentTextClassName=re,l.defaultPlugins=Te,l.enableDebugMode=ce,l.getVisibleHeight=U,l.ignoredElementClassName=ae,l.ignoredTextClassName=se,l.isDebugMode=ue,l.isElement=O,l.isTextNode=z,l.logger=h,l.loggerName=_,l.moveOffscreen=de,l.pageBreakAttributeName=Y,l.pageBreakPlugin=Z,l.pageBreakPluginName=Q,l.pageClassName=le,l.tempContainerClassName=M,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(l,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(l=typeof globalThis<"u"?globalThis:l||self,_(l.paprize_core={}))})(this,(function(l){"use strict";const _="paprize",D="pz-temp-container",ae="pz-current-element",se="pz-current-text",le="pz-ignored-element",ce="pz-ignored-text",O="pz-page",v="data-pz-";let z=!1;const de=()=>{z=!0},ue=()=>z;function R(i){return i.nodeType===Node.ELEMENT_NODE}function U(i){return i.nodeType===Node.TEXT_NODE}function V(i){const e=i.getBoundingClientRect(),t=getComputedStyle(i),n=parseFloat(t.marginTop)||0,o=parseFloat(t.marginBottom)||0;return e.height+n+o}function ge(i){i.style.visibility="hidden",i.style.position="absolute",i.style.left="-9999px",i.style.top="-9999px"}class N{name;defaultValue;_reader;constructor(e,t,n){this.name=e,this._reader=t,this.defaultValue=n}read(e){return this._reader(e)}static createStr(e,t){return new N(e,n=>n,t)}static createBool(e,t){return new N(e,n=>n==="true",t)}}const k={hyphen:N.createStr("hyphen","-"),keepOnSamePage:N.createBool("keep-on-same-page",!1),hyphenationEnabled:N.createBool("hyphenation-enabled",!0)};function pe(i){const e={};for(const t in i){const n=i[t];if(n!==void 0){const o=k[t];e[`${v}${o.name}`]=String(n)}}return e}const he=Object.fromEntries(Object.entries(k).map(([i,e])=>[i,e.defaultValue])),q=new WeakMap;function G(i){if(!i)return{};if(!(i instanceof Element))return G(i?.parentNode);const e={};for(const o in k){const r=k[o],s=`${v}${r.name}`,f=i.getAttribute(s);f!==null&&(e[o]=r.read(f))}const n={...i.parentNode?q.get(i.parentNode):void 0,...e};return q.set(i,n),n}const j={id:"default",plugins:[],...he};function fe(i,e){const t=G(i);return{...j,...e,...t}}function me(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var L={exports:{}},_e=L.exports,X;function ve(){return X||(X=1,(function(i){(function(e,t){i.exports?i.exports=t():e.log=t()})(_e,function(){var e=function(){},t="undefined",n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"],r={},s=null;function f(c,u){var a=c[u];if(typeof a.bind=="function")return a.bind(c);try{return Function.prototype.bind.call(a,c)}catch{return function(){return Function.prototype.apply.apply(a,[c,arguments])}}}function Fe(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function Ie(c){return c==="debug"&&(c="log"),typeof console===t?!1:c==="trace"&&n?Fe:console[c]!==void 0?f(console,c):console.log!==void 0?f(console,"log"):e}function P(){for(var c=this.getLevel(),u=0;u<o.length;u++){var a=o[u];this[a]=u<c?e:this.methodFactory(a,c,this.name)}if(this.log=this.debug,typeof console===t&&c<this.levels.SILENT)return"No console available for logging"}function Oe(c){return function(){typeof console!==t&&(P.call(this),this[c].apply(this,arguments))}}function Re(c,u,a){return Ie(c)||Oe.apply(this,arguments)}function ne(c,u){var a=this,F,M,C,m="loglevel";typeof c=="string"?m+=":"+c:typeof c=="symbol"&&(m=void 0);function He(d){var g=(o[d]||"silent").toUpperCase();if(!(typeof window===t||!m)){try{window.localStorage[m]=g;return}catch{}try{window.document.cookie=encodeURIComponent(m)+"="+g+";"}catch{}}}function ie(){var d;if(!(typeof window===t||!m)){try{d=window.localStorage[m]}catch{}if(typeof d===t)try{var g=window.document.cookie,I=encodeURIComponent(m),re=g.indexOf(I+"=");re!==-1&&(d=/^([^;]+)/.exec(g.slice(re+I.length+1))[1])}catch{}return a.levels[d]===void 0&&(d=void 0),d}}function $e(){if(!(typeof window===t||!m)){try{window.localStorage.removeItem(m)}catch{}try{window.document.cookie=encodeURIComponent(m)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}function x(d){var g=d;if(typeof g=="string"&&a.levels[g.toUpperCase()]!==void 0&&(g=a.levels[g.toUpperCase()]),typeof g=="number"&&g>=0&&g<=a.levels.SILENT)return g;throw new TypeError("log.setLevel() called with invalid level: "+d)}a.name=c,a.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},a.methodFactory=u||Re,a.getLevel=function(){return C??M??F},a.setLevel=function(d,g){return C=x(d),g!==!1&&He(C),P.call(a)},a.setDefaultLevel=function(d){M=x(d),ie()||a.setLevel(d,!1)},a.resetLevel=function(){C=null,$e(),P.call(a)},a.enableAll=function(d){a.setLevel(a.levels.TRACE,d)},a.disableAll=function(d){a.setLevel(a.levels.SILENT,d)},a.rebuild=function(){if(s!==a&&(F=x(s.getLevel())),P.call(a),s===a)for(var d in r)r[d].rebuild()},F=x(s?s.getLevel():"WARN");var oe=ie();oe!=null&&(C=x(oe)),P.call(a)}s=new ne,s.getLogger=function(u){if(typeof u!="symbol"&&typeof u!="string"||u==="")throw new TypeError("You must supply a name when creating a logger.");var a=r[u];return a||(a=r[u]=new ne(u,s.methodFactory)),a};var Be=typeof window!==t?window.log:void 0;return s.noConflict=function(){return typeof window!==t&&window.log===s&&(window.log=Be),s},s.getLoggers=function(){return r},s.default=s,s})})(L)),L.exports}var Ne=ve();const S=me(Ne),h=S.getLogger(_);h.setDefaultLevel("info");const B="\x1B[46mPLUGIN\x1B[0m";function b(i,e,...t){i.sort((n,o)=>n.order-o.order).forEach(n=>{const o=n[e];if(o){h.debug(B,`executing plugin ${n.name}:${String(e)} ()`,t);try{o(...t),h.debug(B,`plugin ${n.name}:${String(e)} executed`,t)}catch(r){h.debug(B,`plugin ${n.name}:${String(e)} failed`,r)}}})}const y={Element:"element",Text:"text"};class H{_node;_transaction;type=y.Element;config;constructor(e,t,n){this._node=e,this._transaction=t,this.config=n}appendChild(e){this._transaction.isActive&&this._transaction.addRollbackCallback(()=>{this._node.removeChild(e.getNode())}),this._node.appendChild(e.getNode())}clone(e){const t=this._node.cloneNode(e),n=new H(t,this._transaction,this.config);return b(this.config.plugins,"onClone",this.config.id,this._node,n),n}getHeight(){return V(this._node)}remove(){this._transaction.addCommitCallback(()=>{this._node.remove()})}isEmpty(){return this._node.innerHTML===""}getChildrenCount(){return this._node.childNodes.length}getNode(){return this._node}}class Se{_node;_transaction;type=y.Text;config;constructor(e,t,n){this._node=e,this._transaction=t,this.config=n}get textContent(){return this._node.textContent??""}set textContent(e){this._node.textContent=e}remove(){this._transaction.addCommitCallback(()=>{this._node.remove()})}getNode(){return this._node}}function $(i,e,t){if(U(i))return new Se(i,e,t);if(R(i))return new H(i,e,t);throw new Error("Unsupported node type")}const E="\x1B[106mDOM\x1B[0m";class be{_transaction;_treeWalker;_config;_completed=!1;_currentNode=null;_previousNode=null;constructor(e,t,n){this._transaction=t,this._config=n,this._treeWalker=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT)}get completed(){return this._completed}get currentNode(){return this._currentNode}get previousNode(){return this._previousNode}nextNode(){this._treeWalker.nextNode()||(this._completed=!0),h.debug(E,"moving to next node"),this.setState()}nextSiblingOrParentSibling(){let e=0;if(this._treeWalker.nextSibling())return h.debug(E,"moving to next sibling node"),this.setState(),{parentsTraversed:e};for(;this._treeWalker.parentNode();)if(e++,this._treeWalker.nextSibling())return h.debug(E,"moving to parent sibling node, traversed:",e),this.setState(),{parentsTraversed:e};return this._completed=!0,{parentsTraversed:e}}firstChildOrNextNode(){return this._treeWalker.firstChild()?(h.debug(E,"moving to first child node"),this.setState(),{parentsTraversed:1}):(this.nextNode(),{parentsTraversed:0})}setState(){this._previousNode=this._currentNode,this._currentNode=$(this._treeWalker.currentNode,this._transaction,fe(this._treeWalker.currentNode,this._config)),h.debug(E,"moved to node",{currentNode:this.currentNode,previousNode:this.previousNode})}}class ye{_onRollback;_onCommit;isActive;constructor(){this._onRollback=[],this._onCommit=[],this.isActive=!1}start=()=>{if(this.isActive)throw new Error("Transaction already in progress");this.isActive=!0,this._onRollback=[],this._onCommit=[]};addRollbackCallback=e=>{this._onRollback.push(e)};addCommitCallback=e=>{if(!this.isActive){e();return}this._onCommit.push(e)};rollback=()=>{this.isActive&&(this.isActive=!1,this._onRollback.forEach(e=>e()))};commit=()=>{this.isActive&&(this.isActive=!1,this._onCommit.forEach(e=>e()))}}const J="\x1B[102mPAGE\x1B[0m";class w{currentPage;activeElement;currentElement;parentStack;pageIsFull;pageIndex;pageHeight;constructor(e,t,n,o,r,s,f){this.currentPage=e,this.activeElement=t,this.currentElement=n,this.parentStack=o,this.pageIsFull=r,this.pageIndex=s,this.pageHeight=f}static create(e,t,n,o){return new w(e,null,e,t,!1,n,o)}clone=()=>new w(this.currentPage,this.activeElement,this.currentElement,[...this.parentStack],this.pageIsFull,this.pageIndex,this.pageHeight)}class W{_pageState;_transaction;_tempContainer;_config;constructor(e,t,n,o){this._tempContainer=e,this._config=o,this._transaction=n;const r=W.createPageHtmlElement(t.width),s=this.createNewPage(r);this._pageState=w.create(s,[],0,t.height),b(this._config.plugins,"onNewPage",o.id,this)}nextPage(){const e=this.createNewPage(this._pageState.currentPage.getNode().cloneNode(!1)),t=w.create(e,[],this._pageState.pageIndex+1,this._pageState.pageHeight);this.cloneParentStackToNewPage(t),this.cleanupEmptyParent(),this._pageState=t,b(this._config.plugins,"onNewPage",this._config.id,this)}cloneParentStackToNewPage(e){for(const t of this._pageState.parentStack){const n=t.clone(!1);e.currentElement.appendChild(n),e.currentElement=n,e.parentStack.push(n)}}cleanupEmptyParent(){const e=[...this._pageState.parentStack],t=()=>{for(let n=e.length-1;n>=0;n--){const o=e[n];o.isEmpty()&&o.remove()}};this._transaction.addCommitCallback(t)}enterElement(){if(!this._pageState.activeElement||this._pageState.activeElement.type!==y.Element)throw new Error("Invalid state: activeElement is not an Element");h.debug(J,"entering an element",this._pageState.activeElement),this._pageState.currentElement=this._pageState.activeElement,this._pageState.parentStack.push(this._pageState.activeElement)}leaveElement(){this._pageState.activeElement=null;const e=this._pageState.parentStack.pop();h.debug(J,"leaving a parent element",e);const t=this._pageState.parentStack.at(-1);this._pageState.currentElement=t??this._pageState.currentPage}static createPageHtmlElement(e){const t=document.createElement("div");return t.style.width=`${e}px`,t.style.maxWidth=`${e}px`,t}createNewPage(e){return this._tempContainer.appendChild(e),this._transaction.isActive&&this._transaction.addRollbackCallback(()=>{this._tempContainer.removeChild(e)}),$(e,this._transaction,this._config)}startTransaction(){this._transaction.start();const e=this._pageState.clone();return this._transaction.addRollbackCallback(()=>{this._pageState=e}),this._transaction}hasEmptySpace(e){return!this._pageState.pageIsFull&&this._pageState.currentPage.getHeight()+(e||1e-4)<=this._pageState.pageHeight}isOverFlow(){return this._pageState.currentPage.getHeight()>this._pageState.pageHeight}markPageAsFull(){this._pageState.pageIsFull=!0}appendChild(e,t){const n=e.clone(t);return this._pageState.currentElement.appendChild(n),this._pageState.activeElement=n,n}addTextNode(e){if(this._pageState.activeElement?.type===y.Text)return this._pageState.activeElement;const t=document.createTextNode(e),n=$(t,this._transaction,this._config);return this._pageState.currentElement.appendChild(n),this._pageState.activeElement=n,n}getPageState(){return this._pageState}}const p={None:0,FullNodePlaced:1,SplitChildren:2};function Ce(i,e){const t=K(i,e);if(t!==p.None)return t;const{rollback:n,commit:o}=e.startTransaction();e.nextPage();const r=K(i,e);return r!==p.None?(o(),r):(n(),h.debug("Element is too big to fit on a page",i),p.None)}function K(i,e){if(e.hasEmptySpace(i.getHeight())){const n=e.appendChild(i,!0);if(e.isOverFlow())n.remove();else return p.FullNodePlaced}if(i.config.keepOnSamePage||i.getChildrenCount()===0)return p.None;const t=e.appendChild(i,!1);return e.isOverFlow()?(t.remove(),p.None):p.SplitChildren}function Ee(i,e){let t=p.FullNodePlaced;const n=i.textContent.split(/(\s+)/).filter(s=>s!=="");let o,r=0;for(;o||r<n.length;){const s=o??n[r],f=we(s,e,i.config);f.completed||(t=p.None),f.pendingToken?o=f.pendingToken:(o=void 0,r++)}return t}function we(i,e,t){e.hasEmptySpace()||e.nextPage();let n=e.addTextNode("");const o=n.textContent;if(n.textContent+=i,!e.isOverFlow())return{completed:!0};n.textContent=o;const r=Te(i,e,t);return{pendingToken:r.leftovers,completed:r.completed}}function Te(i,e,t){const{rollback:n,commit:o}=e.startTransaction();if(e.nextPage(),e.addTextNode(i),!e.isOverFlow())return o(),{completed:!0};if(n(),!t.hyphenationEnabled)return h.warn("Hyphenation disabled, skipping oversized token:",i),{completed:!1};const r=Pe(i,t.hyphen,e);return{completed:!0,leftovers:r&&r.length>0?r:void 0}}function Pe(i,e,t){const n=t.addTextNode("");let o="";for(let r=0;r<i.length;r++){const s=i[r],f=o+s;if(n.textContent=f+e,!t.hasEmptySpace())return n.textContent=o?o+e:"",t.markPageAsFull(),i.slice(r);o=f}return null}const T="\x1B[103mPAGINATOR\x1B[0m";class A{_domState;_pageManager;_transaction;_tempContainer;_config;constructor(e,t,n){this._config={...j,...n},this._tempContainer=A.createTempContainer(this._config.id),this._transaction=new ye,this._domState=new be(e,this._transaction,this._config),this._pageManager=new W(this._tempContainer,t,this._transaction,this._config)}static createTempContainer(e){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="column",t.style.gap="20px",t.setAttribute(`${v}-section-id`,e),t.classList.add(D),document.body.appendChild(t),t}static paginate(e,t,n){const o=new A(e,t,n);return o.processAllNodes(),Array.from(o._tempContainer.childNodes).filter(s=>R(s)).map(s=>s.innerHTML)}processAllNodes(){this._domState.nextNode();do{switch(S.debug(T,"paginating node",this._domState.currentNode),this.processCurrentNode()){case p.None:this.handleNodeSkipped();break;case p.FullNodePlaced:this.handleFullNodePlaced();break;case p.SplitChildren:this.handleChildrenSplit();break}b(this._config.plugins,"afterVisitNode",this._config.id,this._domState,this._pageManager)}while(this._domState.completed===!1);S.debug(T,"pagination completed")}handleNodeSkipped(){S.debug(T,"node skipped - couldn't paginate"),this._domState.nextNode()}handleFullNodePlaced(){S.debug(T,"node fully paginated");const{parentsTraversed:e}=this._domState.nextSiblingOrParentSibling();for(let t=0;t<e;t++)this._pageManager.leaveElement()}handleChildrenSplit(){S.debug(T,"node partially paginated - splitting children"),this._domState.firstChildOrNextNode().parentsTraversed===1&&this._domState.previousNode?.type===y.Element&&this._pageManager.enterElement()}processCurrentNode(){if(!this._domState.currentNode)return p.None;if(this._domState.currentNode.type===y.Element){const e={};return b(this._config.plugins,"onVisitElement",this._config.id,this._domState,this._pageManager,e),e.result!==void 0?e.result:Ce(this._domState.currentNode,this._pageManager)}else{const e={};return b(this._config.plugins,"onVisitText",this._config.id,this._domState,this._pageManager,e),e.result!==void 0?e.result:Ee(this._domState.currentNode,this._pageManager)}}}const Y=["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"];function xe(i,e){if(i<=0)return"";const t=[],n=Math.floor(e*982451653);for(let o=0;o<i;o++){const r=(n+o*2654435761)%Math.pow(2,32),s=Math.floor(r/Math.pow(2,32)*Y.length);t.push(Y[s])}return t.length>0&&(t[0]=t[0].charAt(0).toUpperCase()+t[0].slice(1)),t.join(" ")+"."}const Q="data-pz-page-break",Z="pageBreak",ee={name:Z,order:1,onVisitElement:(i,e,t,n)=>{e.currentNode.getNode().getAttribute(Q)==="true"&&(t.markPageAsFull(),n.result=p.FullNodePlaced)}},ke=[ee],Le={name:"debug",order:Number.MAX_SAFE_INTEGER,onNewPage:(i,e)=>{const t=e.getPageState().currentPage.getNode();t.classList.contains(O)||t.classList.add(O),t.setAttribute(`${v}-element`,"page"),t.setAttribute(`${v}-height`,e.getPageState().pageHeight.toString())}},te="sectionToc";class Ae{state=[];name=te;order=1;onVisitElement=(e,t,n)=>{{const o=t.currentNode.getNode(),r=this.getHeadingLevel(o);if(!r||!o.textContent)return;this.state.push({sectionId:e,pageNumber:n.getPageState().pageIndex+1,title:o.textContent,level:r})}};getHeadingLevel(e){const t=e.tagName;return/^H[1-6]$/.test(t)?parseInt(t.charAt(1),10):null}}l.Paginator=A,l.SectionTocPlugin=Ae,l.SplitResult=p,l.attributePrefix=v,l.configToAttributeMap=pe,l.createLoremIpsumParagraph=xe,l.currentElementClassName=ae,l.currentTextClassName=se,l.debugPlugin=Le,l.defaultPlugins=ke,l.enableDebugMode=de,l.getVisibleHeight=V,l.ignoredElementClassName=le,l.ignoredTextClassName=ce,l.isDebugMode=ue,l.isElement=R,l.isTextNode=U,l.logger=h,l.loggerName=_,l.moveOffscreen=ge,l.pageBreakAttributeName=Q,l.pageBreakPlugin=ee,l.pageBreakPluginName=Z,l.pageClassName=O,l.sectionTocName=te,l.tempContainerClassName=D,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
|