@paprize/puppeteer 0.0.7 → 0.0.9
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/LICENSE +201 -0
- package/package.json +51 -56
- package/dist/paprize-puppeteer.d.ts +0 -63
- package/dist/paprize-puppeteer.js +0 -124
- package/dist/paprize-puppeteer.js.map +0 -7
- package/dist/paprize-zero.js +0 -2181
- package/dist/paprize-zero.js.map +0 -7
package/dist/paprize-zero.js
DELETED
|
@@ -1,2181 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
|
|
27
|
-
// ../../node_modules/loglevel/lib/loglevel.js
|
|
28
|
-
var require_loglevel = __commonJS({
|
|
29
|
-
"../../node_modules/loglevel/lib/loglevel.js"(exports, module) {
|
|
30
|
-
(function(root, definition) {
|
|
31
|
-
"use strict";
|
|
32
|
-
if (typeof define === "function" && define.amd) {
|
|
33
|
-
define(definition);
|
|
34
|
-
} else if (typeof module === "object" && module.exports) {
|
|
35
|
-
module.exports = definition();
|
|
36
|
-
} else {
|
|
37
|
-
root.log = definition();
|
|
38
|
-
}
|
|
39
|
-
})(exports, function() {
|
|
40
|
-
"use strict";
|
|
41
|
-
var noop = function() {
|
|
42
|
-
};
|
|
43
|
-
var undefinedType = "undefined";
|
|
44
|
-
var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
|
|
45
|
-
var logMethods = [
|
|
46
|
-
"trace",
|
|
47
|
-
"debug",
|
|
48
|
-
"info",
|
|
49
|
-
"warn",
|
|
50
|
-
"error"
|
|
51
|
-
];
|
|
52
|
-
var _loggersByName = {};
|
|
53
|
-
var defaultLogger = null;
|
|
54
|
-
function bindMethod(obj, methodName) {
|
|
55
|
-
var method = obj[methodName];
|
|
56
|
-
if (typeof method.bind === "function") {
|
|
57
|
-
return method.bind(obj);
|
|
58
|
-
} else {
|
|
59
|
-
try {
|
|
60
|
-
return Function.prototype.bind.call(method, obj);
|
|
61
|
-
} catch (e) {
|
|
62
|
-
return function() {
|
|
63
|
-
return Function.prototype.apply.apply(method, [obj, arguments]);
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function traceForIE() {
|
|
69
|
-
if (console.log) {
|
|
70
|
-
if (console.log.apply) {
|
|
71
|
-
console.log.apply(console, arguments);
|
|
72
|
-
} else {
|
|
73
|
-
Function.prototype.apply.apply(console.log, [console, arguments]);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (console.trace) console.trace();
|
|
77
|
-
}
|
|
78
|
-
function realMethod(methodName) {
|
|
79
|
-
if (methodName === "debug") {
|
|
80
|
-
methodName = "log";
|
|
81
|
-
}
|
|
82
|
-
if (typeof console === undefinedType) {
|
|
83
|
-
return false;
|
|
84
|
-
} else if (methodName === "trace" && isIE) {
|
|
85
|
-
return traceForIE;
|
|
86
|
-
} else if (console[methodName] !== void 0) {
|
|
87
|
-
return bindMethod(console, methodName);
|
|
88
|
-
} else if (console.log !== void 0) {
|
|
89
|
-
return bindMethod(console, "log");
|
|
90
|
-
} else {
|
|
91
|
-
return noop;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
function replaceLoggingMethods() {
|
|
95
|
-
var level = this.getLevel();
|
|
96
|
-
for (var i = 0; i < logMethods.length; i++) {
|
|
97
|
-
var methodName = logMethods[i];
|
|
98
|
-
this[methodName] = i < level ? noop : this.methodFactory(methodName, level, this.name);
|
|
99
|
-
}
|
|
100
|
-
this.log = this.debug;
|
|
101
|
-
if (typeof console === undefinedType && level < this.levels.SILENT) {
|
|
102
|
-
return "No console available for logging";
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function enableLoggingWhenConsoleArrives(methodName) {
|
|
106
|
-
return function() {
|
|
107
|
-
if (typeof console !== undefinedType) {
|
|
108
|
-
replaceLoggingMethods.call(this);
|
|
109
|
-
this[methodName].apply(this, arguments);
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
function defaultMethodFactory(methodName, _level, _loggerName) {
|
|
114
|
-
return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
|
|
115
|
-
}
|
|
116
|
-
function Logger(name, factory) {
|
|
117
|
-
var self = this;
|
|
118
|
-
var inheritedLevel;
|
|
119
|
-
var defaultLevel;
|
|
120
|
-
var userLevel;
|
|
121
|
-
var storageKey = "loglevel";
|
|
122
|
-
if (typeof name === "string") {
|
|
123
|
-
storageKey += ":" + name;
|
|
124
|
-
} else if (typeof name === "symbol") {
|
|
125
|
-
storageKey = void 0;
|
|
126
|
-
}
|
|
127
|
-
function persistLevelIfPossible(levelNum) {
|
|
128
|
-
var levelName = (logMethods[levelNum] || "silent").toUpperCase();
|
|
129
|
-
if (typeof window === undefinedType || !storageKey) return;
|
|
130
|
-
try {
|
|
131
|
-
window.localStorage[storageKey] = levelName;
|
|
132
|
-
return;
|
|
133
|
-
} catch (ignore) {
|
|
134
|
-
}
|
|
135
|
-
try {
|
|
136
|
-
window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";";
|
|
137
|
-
} catch (ignore) {
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
function getPersistedLevel() {
|
|
141
|
-
var storedLevel;
|
|
142
|
-
if (typeof window === undefinedType || !storageKey) return;
|
|
143
|
-
try {
|
|
144
|
-
storedLevel = window.localStorage[storageKey];
|
|
145
|
-
} catch (ignore) {
|
|
146
|
-
}
|
|
147
|
-
if (typeof storedLevel === undefinedType) {
|
|
148
|
-
try {
|
|
149
|
-
var cookie = window.document.cookie;
|
|
150
|
-
var cookieName = encodeURIComponent(storageKey);
|
|
151
|
-
var location = cookie.indexOf(cookieName + "=");
|
|
152
|
-
if (location !== -1) {
|
|
153
|
-
storedLevel = /^([^;]+)/.exec(
|
|
154
|
-
cookie.slice(location + cookieName.length + 1)
|
|
155
|
-
)[1];
|
|
156
|
-
}
|
|
157
|
-
} catch (ignore) {
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (self.levels[storedLevel] === void 0) {
|
|
161
|
-
storedLevel = void 0;
|
|
162
|
-
}
|
|
163
|
-
return storedLevel;
|
|
164
|
-
}
|
|
165
|
-
function clearPersistedLevel() {
|
|
166
|
-
if (typeof window === undefinedType || !storageKey) return;
|
|
167
|
-
try {
|
|
168
|
-
window.localStorage.removeItem(storageKey);
|
|
169
|
-
} catch (ignore) {
|
|
170
|
-
}
|
|
171
|
-
try {
|
|
172
|
-
window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
|
173
|
-
} catch (ignore) {
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
function normalizeLevel(input) {
|
|
177
|
-
var level = input;
|
|
178
|
-
if (typeof level === "string" && self.levels[level.toUpperCase()] !== void 0) {
|
|
179
|
-
level = self.levels[level.toUpperCase()];
|
|
180
|
-
}
|
|
181
|
-
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
|
|
182
|
-
return level;
|
|
183
|
-
} else {
|
|
184
|
-
throw new TypeError("log.setLevel() called with invalid level: " + input);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
self.name = name;
|
|
188
|
-
self.levels = {
|
|
189
|
-
"TRACE": 0,
|
|
190
|
-
"DEBUG": 1,
|
|
191
|
-
"INFO": 2,
|
|
192
|
-
"WARN": 3,
|
|
193
|
-
"ERROR": 4,
|
|
194
|
-
"SILENT": 5
|
|
195
|
-
};
|
|
196
|
-
self.methodFactory = factory || defaultMethodFactory;
|
|
197
|
-
self.getLevel = function() {
|
|
198
|
-
if (userLevel != null) {
|
|
199
|
-
return userLevel;
|
|
200
|
-
} else if (defaultLevel != null) {
|
|
201
|
-
return defaultLevel;
|
|
202
|
-
} else {
|
|
203
|
-
return inheritedLevel;
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
self.setLevel = function(level, persist) {
|
|
207
|
-
userLevel = normalizeLevel(level);
|
|
208
|
-
if (persist !== false) {
|
|
209
|
-
persistLevelIfPossible(userLevel);
|
|
210
|
-
}
|
|
211
|
-
return replaceLoggingMethods.call(self);
|
|
212
|
-
};
|
|
213
|
-
self.setDefaultLevel = function(level) {
|
|
214
|
-
defaultLevel = normalizeLevel(level);
|
|
215
|
-
if (!getPersistedLevel()) {
|
|
216
|
-
self.setLevel(level, false);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
self.resetLevel = function() {
|
|
220
|
-
userLevel = null;
|
|
221
|
-
clearPersistedLevel();
|
|
222
|
-
replaceLoggingMethods.call(self);
|
|
223
|
-
};
|
|
224
|
-
self.enableAll = function(persist) {
|
|
225
|
-
self.setLevel(self.levels.TRACE, persist);
|
|
226
|
-
};
|
|
227
|
-
self.disableAll = function(persist) {
|
|
228
|
-
self.setLevel(self.levels.SILENT, persist);
|
|
229
|
-
};
|
|
230
|
-
self.rebuild = function() {
|
|
231
|
-
if (defaultLogger !== self) {
|
|
232
|
-
inheritedLevel = normalizeLevel(defaultLogger.getLevel());
|
|
233
|
-
}
|
|
234
|
-
replaceLoggingMethods.call(self);
|
|
235
|
-
if (defaultLogger === self) {
|
|
236
|
-
for (var childName in _loggersByName) {
|
|
237
|
-
_loggersByName[childName].rebuild();
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
inheritedLevel = normalizeLevel(
|
|
242
|
-
defaultLogger ? defaultLogger.getLevel() : "WARN"
|
|
243
|
-
);
|
|
244
|
-
var initialLevel = getPersistedLevel();
|
|
245
|
-
if (initialLevel != null) {
|
|
246
|
-
userLevel = normalizeLevel(initialLevel);
|
|
247
|
-
}
|
|
248
|
-
replaceLoggingMethods.call(self);
|
|
249
|
-
}
|
|
250
|
-
defaultLogger = new Logger();
|
|
251
|
-
defaultLogger.getLogger = function getLogger(name) {
|
|
252
|
-
if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
|
|
253
|
-
throw new TypeError("You must supply a name when creating a logger.");
|
|
254
|
-
}
|
|
255
|
-
var logger3 = _loggersByName[name];
|
|
256
|
-
if (!logger3) {
|
|
257
|
-
logger3 = _loggersByName[name] = new Logger(
|
|
258
|
-
name,
|
|
259
|
-
defaultLogger.methodFactory
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
return logger3;
|
|
263
|
-
};
|
|
264
|
-
var _log = typeof window !== undefinedType ? window.log : void 0;
|
|
265
|
-
defaultLogger.noConflict = function() {
|
|
266
|
-
if (typeof window !== undefinedType && window.log === defaultLogger) {
|
|
267
|
-
window.log = _log;
|
|
268
|
-
}
|
|
269
|
-
return defaultLogger;
|
|
270
|
-
};
|
|
271
|
-
defaultLogger.getLoggers = function getLoggers() {
|
|
272
|
-
return _loggersByName;
|
|
273
|
-
};
|
|
274
|
-
defaultLogger["default"] = defaultLogger;
|
|
275
|
-
return defaultLogger;
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
// ../core/src/constants.ts
|
|
281
|
-
var loggerName = "paprize";
|
|
282
|
-
var tempContainerClassName = "pz-temp-container";
|
|
283
|
-
var currentElementClassName = "pz-current-element";
|
|
284
|
-
var currentTextClassName = "pz-current-text";
|
|
285
|
-
var ignoredElementClassName = "pz-ignored-element";
|
|
286
|
-
var ignoredTextClassName = "pz-ignored-text";
|
|
287
|
-
var globalStyleId = "paprize-global-style";
|
|
288
|
-
var pageClassName = "pz-page";
|
|
289
|
-
var sectionClassName = "pz-section";
|
|
290
|
-
var previewClassName = "pz-preview";
|
|
291
|
-
var attributePrefix = "data-pz-";
|
|
292
|
-
|
|
293
|
-
// ../core/src/debugUtilities/debugMode.ts
|
|
294
|
-
var debugMode = false;
|
|
295
|
-
var isDebugMode = () => debugMode;
|
|
296
|
-
|
|
297
|
-
// ../core/src/paginate/domUtilities.ts
|
|
298
|
-
function isElement(node) {
|
|
299
|
-
return node.nodeType === Node.ELEMENT_NODE;
|
|
300
|
-
}
|
|
301
|
-
function isTextNode(node) {
|
|
302
|
-
return node.nodeType === Node.TEXT_NODE;
|
|
303
|
-
}
|
|
304
|
-
function getVisibleHeight(element) {
|
|
305
|
-
const rect = element.getBoundingClientRect();
|
|
306
|
-
const computedStyle = getComputedStyle(element);
|
|
307
|
-
const marginTop = parseFloat(computedStyle.marginTop) || 0;
|
|
308
|
-
const marginBottom = parseFloat(computedStyle.marginBottom) || 0;
|
|
309
|
-
return rect.height + marginTop + marginBottom;
|
|
310
|
-
}
|
|
311
|
-
function moveOffscreen(element) {
|
|
312
|
-
element.style.visibility = "hidden";
|
|
313
|
-
element.style.position = "absolute";
|
|
314
|
-
element.style.left = "-9999px";
|
|
315
|
-
element.style.top = "-9999px";
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// ../core/src/paginate/LayoutOptions.ts
|
|
319
|
-
var defaultLayoutOptions = {
|
|
320
|
-
hyphen: "-",
|
|
321
|
-
keepOnSamePage: false,
|
|
322
|
-
hyphenationDisabled: false
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
// ../core/src/paginate/attributes.ts
|
|
326
|
-
var layoutOptionsAttributes = {
|
|
327
|
-
hyphen: {
|
|
328
|
-
key: `${attributePrefix}hyphen`,
|
|
329
|
-
reader: (value) => String(value)
|
|
330
|
-
},
|
|
331
|
-
keepOnSamePage: {
|
|
332
|
-
key: `${attributePrefix}keep-on-same-page`,
|
|
333
|
-
reader: (value) => value === "true"
|
|
334
|
-
},
|
|
335
|
-
hyphenationDisabled: {
|
|
336
|
-
key: `${attributePrefix}hyphenation-disabled`,
|
|
337
|
-
reader: (value) => value === "true"
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
var attributeCache = /* @__PURE__ */ new WeakMap();
|
|
341
|
-
function assignAttribute(key, reader, value, attributes) {
|
|
342
|
-
if (value == null) {
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
const parsedValue = reader(value);
|
|
346
|
-
if (parsedValue !== void 0) {
|
|
347
|
-
attributes[key] = parsedValue;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
function getNodeLayoutOptionsFromAttribute(node) {
|
|
351
|
-
if (!node) {
|
|
352
|
-
return {};
|
|
353
|
-
}
|
|
354
|
-
if (!(node instanceof Element)) {
|
|
355
|
-
return getNodeLayoutOptionsFromAttribute(node?.parentNode);
|
|
356
|
-
}
|
|
357
|
-
const attributes = {};
|
|
358
|
-
for (const key of Object.keys(defaultLayoutOptions)) {
|
|
359
|
-
const typedKey = key;
|
|
360
|
-
const attribute = layoutOptionsAttributes[typedKey];
|
|
361
|
-
const value = node.getAttribute(attribute.key);
|
|
362
|
-
assignAttribute(typedKey, attribute.reader, value, attributes);
|
|
363
|
-
}
|
|
364
|
-
const parentAttributes = node.parentNode ? attributeCache.get(node.parentNode) : void 0;
|
|
365
|
-
const result = { ...parentAttributes, ...attributes };
|
|
366
|
-
attributeCache.set(node, result);
|
|
367
|
-
return result;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// ../core/src/paginate/PaginationOptions.ts
|
|
371
|
-
var defaultPaginationOptions = {
|
|
372
|
-
id: "default",
|
|
373
|
-
plugins: [],
|
|
374
|
-
...defaultLayoutOptions
|
|
375
|
-
};
|
|
376
|
-
function resolvePaginationOptions(node, globalConfig) {
|
|
377
|
-
const attributes = getNodeLayoutOptionsFromAttribute(node);
|
|
378
|
-
return { ...defaultPaginationOptions, ...globalConfig, ...attributes };
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
// ../core/src/logger.ts
|
|
382
|
-
var import_loglevel = __toESM(require_loglevel(), 1);
|
|
383
|
-
var logger = import_loglevel.default.getLogger(loggerName);
|
|
384
|
-
logger.setDefaultLevel("info");
|
|
385
|
-
var logger_default = logger;
|
|
386
|
-
|
|
387
|
-
// ../core/src/paginate/PaginationPlugin.ts
|
|
388
|
-
var logPrefix = "\x1B[46mPLUGIN\x1B[0m";
|
|
389
|
-
function callPluginHook(plugins, hookName, ...args) {
|
|
390
|
-
plugins.sort((a, b) => a.order - b.order).forEach((plugin) => {
|
|
391
|
-
const hook = plugin[hookName];
|
|
392
|
-
if (!hook) {
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
logger_default.debug(
|
|
396
|
-
logPrefix,
|
|
397
|
-
`executing plugin ${plugin.name}:${String(hookName)} (${String()})`,
|
|
398
|
-
args
|
|
399
|
-
);
|
|
400
|
-
try {
|
|
401
|
-
hook(...args);
|
|
402
|
-
logger_default.debug(
|
|
403
|
-
logPrefix,
|
|
404
|
-
`plugin ${plugin.name}:${String(hookName)} executed`,
|
|
405
|
-
args
|
|
406
|
-
);
|
|
407
|
-
} catch (error) {
|
|
408
|
-
logger_default.debug(
|
|
409
|
-
logPrefix,
|
|
410
|
-
`plugin ${plugin.name}:${String(hookName)} failed`,
|
|
411
|
-
error
|
|
412
|
-
);
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// ../core/src/paginate/PageNodes.ts
|
|
418
|
-
var PageNodeType = {
|
|
419
|
-
Element: "element",
|
|
420
|
-
Text: "text"
|
|
421
|
-
};
|
|
422
|
-
var PageElement = class _PageElement {
|
|
423
|
-
_node;
|
|
424
|
-
config;
|
|
425
|
-
type = PageNodeType.Element;
|
|
426
|
-
transaction;
|
|
427
|
-
clonedFrom;
|
|
428
|
-
cloneCount;
|
|
429
|
-
constructor(element, transaction, config, clonedFrom) {
|
|
430
|
-
this._node = element;
|
|
431
|
-
this.transaction = transaction;
|
|
432
|
-
this.config = config;
|
|
433
|
-
this.clonedFrom = clonedFrom;
|
|
434
|
-
this.cloneCount = clonedFrom ? clonedFrom.cloneCount + 1 : 0;
|
|
435
|
-
}
|
|
436
|
-
getOriginalNode() {
|
|
437
|
-
let current = this.clonedFrom;
|
|
438
|
-
while (current?.clonedFrom) {
|
|
439
|
-
current = current.clonedFrom;
|
|
440
|
-
}
|
|
441
|
-
return current?._node;
|
|
442
|
-
}
|
|
443
|
-
appendChild(node) {
|
|
444
|
-
if (this.transaction.isActive) {
|
|
445
|
-
this.transaction.addRollbackCallback(() => {
|
|
446
|
-
this._node.removeChild(node.getNode());
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
this._node.appendChild(node.getNode());
|
|
450
|
-
}
|
|
451
|
-
clone(withChildren) {
|
|
452
|
-
const clonedElement = this._node.cloneNode(withChildren);
|
|
453
|
-
const clonedPageElement = new _PageElement(
|
|
454
|
-
clonedElement,
|
|
455
|
-
this.transaction,
|
|
456
|
-
this.config,
|
|
457
|
-
this
|
|
458
|
-
);
|
|
459
|
-
callPluginHook(
|
|
460
|
-
this.config.plugins,
|
|
461
|
-
"onClone",
|
|
462
|
-
this.config.id,
|
|
463
|
-
this._node,
|
|
464
|
-
clonedPageElement
|
|
465
|
-
);
|
|
466
|
-
return clonedPageElement;
|
|
467
|
-
}
|
|
468
|
-
getHeight() {
|
|
469
|
-
return getVisibleHeight(this._node);
|
|
470
|
-
}
|
|
471
|
-
remove() {
|
|
472
|
-
this.transaction.addCommitCallback(() => {
|
|
473
|
-
this._node.remove();
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
isEmpty() {
|
|
477
|
-
return this._node.innerHTML === "";
|
|
478
|
-
}
|
|
479
|
-
getChildrenCount() {
|
|
480
|
-
return this._node.childNodes.length;
|
|
481
|
-
}
|
|
482
|
-
getNode() {
|
|
483
|
-
return this._node;
|
|
484
|
-
}
|
|
485
|
-
};
|
|
486
|
-
var PageText = class {
|
|
487
|
-
_node;
|
|
488
|
-
type = PageNodeType.Text;
|
|
489
|
-
transaction;
|
|
490
|
-
config;
|
|
491
|
-
constructor(text, transaction, config) {
|
|
492
|
-
this._node = text;
|
|
493
|
-
this.transaction = transaction;
|
|
494
|
-
this.config = config;
|
|
495
|
-
}
|
|
496
|
-
get textContent() {
|
|
497
|
-
return this._node.textContent ?? "";
|
|
498
|
-
}
|
|
499
|
-
set textContent(value) {
|
|
500
|
-
this._node.textContent = value;
|
|
501
|
-
}
|
|
502
|
-
remove() {
|
|
503
|
-
this.transaction.addCommitCallback(() => {
|
|
504
|
-
this._node.remove();
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
getNode() {
|
|
508
|
-
return this._node;
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
function createPageNode(node, transaction, config) {
|
|
512
|
-
if (isTextNode(node)) {
|
|
513
|
-
return new PageText(node, transaction, config);
|
|
514
|
-
} else if (isElement(node)) {
|
|
515
|
-
return new PageElement(node, transaction, config);
|
|
516
|
-
}
|
|
517
|
-
throw new Error("Unsupported node type");
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
// ../core/src/debugUtilities/pageNodeMarker.ts
|
|
521
|
-
function markIgnoredNode(node) {
|
|
522
|
-
if (!isDebugMode()) {
|
|
523
|
-
return;
|
|
524
|
-
}
|
|
525
|
-
if (node && node.type == PageNodeType.Element) {
|
|
526
|
-
node.getNode().classList.add(ignoredElementClassName);
|
|
527
|
-
} else if (node && node.type == PageNodeType.Text) {
|
|
528
|
-
node.getNode().parentElement?.classList.add(ignoredTextClassName);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
function markCurrentNode(node) {
|
|
532
|
-
if (!isDebugMode()) {
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
if (node && node.type == PageNodeType.Element) {
|
|
536
|
-
node.getNode().classList.add(currentElementClassName);
|
|
537
|
-
} else if (node && node.type == PageNodeType.Text) {
|
|
538
|
-
node.getNode().parentElement?.classList.add(currentTextClassName);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
function unmarkCurrentNode(node) {
|
|
542
|
-
if (!isDebugMode()) {
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
if (node && node.type == PageNodeType.Element) {
|
|
546
|
-
node.getNode().classList.remove(currentElementClassName);
|
|
547
|
-
} else if (node && node.type == PageNodeType.Text) {
|
|
548
|
-
node.getNode().parentElement?.classList.remove(currentTextClassName);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
// ../core/src/paginate/DomState.ts
|
|
553
|
-
var logPrefix2 = "\x1B[106mDOM\x1B[0m";
|
|
554
|
-
var DomState = class {
|
|
555
|
-
_transaction;
|
|
556
|
-
_treeWalker;
|
|
557
|
-
_config;
|
|
558
|
-
_completed = false;
|
|
559
|
-
_currentNode = null;
|
|
560
|
-
_previousNode = null;
|
|
561
|
-
constructor(root, transaction, config) {
|
|
562
|
-
this._transaction = transaction;
|
|
563
|
-
this._config = config;
|
|
564
|
-
this._treeWalker = document.createTreeWalker(
|
|
565
|
-
root,
|
|
566
|
-
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT
|
|
567
|
-
);
|
|
568
|
-
}
|
|
569
|
-
get completed() {
|
|
570
|
-
return this._completed;
|
|
571
|
-
}
|
|
572
|
-
get currentNode() {
|
|
573
|
-
return this._currentNode;
|
|
574
|
-
}
|
|
575
|
-
get previousNode() {
|
|
576
|
-
return this._previousNode;
|
|
577
|
-
}
|
|
578
|
-
goToNextNode() {
|
|
579
|
-
const result = this._treeWalker.nextNode();
|
|
580
|
-
if (!result) {
|
|
581
|
-
this._completed = true;
|
|
582
|
-
}
|
|
583
|
-
logger_default.debug(logPrefix2, "moving to next node");
|
|
584
|
-
this.setState();
|
|
585
|
-
}
|
|
586
|
-
goToNextSiblingOrParentSibling() {
|
|
587
|
-
let parentsTraversed = 0;
|
|
588
|
-
if (this._treeWalker.nextSibling()) {
|
|
589
|
-
logger_default.debug(logPrefix2, "moving to next sibling node");
|
|
590
|
-
this.setState();
|
|
591
|
-
return { parentsTraversed };
|
|
592
|
-
}
|
|
593
|
-
while (this._treeWalker.parentNode()) {
|
|
594
|
-
parentsTraversed++;
|
|
595
|
-
if (this._treeWalker.nextSibling()) {
|
|
596
|
-
logger_default.debug(
|
|
597
|
-
logPrefix2,
|
|
598
|
-
"moving to parent sibling node, traversed:",
|
|
599
|
-
parentsTraversed
|
|
600
|
-
);
|
|
601
|
-
this.setState();
|
|
602
|
-
return { parentsTraversed };
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
this._completed = true;
|
|
606
|
-
return { parentsTraversed };
|
|
607
|
-
}
|
|
608
|
-
goToFirstChildOrNextNode() {
|
|
609
|
-
if (this._treeWalker.firstChild()) {
|
|
610
|
-
logger_default.debug(logPrefix2, "moving to first child node");
|
|
611
|
-
this.setState();
|
|
612
|
-
return { parentsTraversed: 1 };
|
|
613
|
-
}
|
|
614
|
-
this.goToNextNode();
|
|
615
|
-
return { parentsTraversed: 0 };
|
|
616
|
-
}
|
|
617
|
-
setState() {
|
|
618
|
-
this._previousNode = this._currentNode;
|
|
619
|
-
this._currentNode = createPageNode(
|
|
620
|
-
this._treeWalker.currentNode,
|
|
621
|
-
this._transaction,
|
|
622
|
-
resolvePaginationOptions(this._treeWalker.currentNode, this._config)
|
|
623
|
-
);
|
|
624
|
-
DEV: markCurrentNode(this._currentNode);
|
|
625
|
-
DEV: unmarkCurrentNode(this._previousNode);
|
|
626
|
-
logger_default.debug(logPrefix2, "moved to node", {
|
|
627
|
-
currentNode: this._currentNode,
|
|
628
|
-
previousNode: this._previousNode
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
|
|
633
|
-
// ../core/src/paginate/Transaction.ts
|
|
634
|
-
var Transaction = class {
|
|
635
|
-
_onRollback;
|
|
636
|
-
_onCommit;
|
|
637
|
-
isActive;
|
|
638
|
-
constructor() {
|
|
639
|
-
this._onRollback = [];
|
|
640
|
-
this._onCommit = [];
|
|
641
|
-
this.isActive = false;
|
|
642
|
-
}
|
|
643
|
-
start = () => {
|
|
644
|
-
if (this.isActive) {
|
|
645
|
-
throw new Error("Transaction already in progress");
|
|
646
|
-
}
|
|
647
|
-
this.isActive = true;
|
|
648
|
-
this._onRollback = [];
|
|
649
|
-
this._onCommit = [];
|
|
650
|
-
};
|
|
651
|
-
addRollbackCallback = (callback) => {
|
|
652
|
-
this._onRollback.push(callback);
|
|
653
|
-
};
|
|
654
|
-
addCommitCallback = (callback) => {
|
|
655
|
-
if (!this.isActive) {
|
|
656
|
-
callback();
|
|
657
|
-
return;
|
|
658
|
-
}
|
|
659
|
-
this._onCommit.push(callback);
|
|
660
|
-
};
|
|
661
|
-
rollback = () => {
|
|
662
|
-
if (!this.isActive) return;
|
|
663
|
-
this.isActive = false;
|
|
664
|
-
this._onRollback.forEach((func) => func());
|
|
665
|
-
};
|
|
666
|
-
commit = () => {
|
|
667
|
-
if (!this.isActive) return;
|
|
668
|
-
this.isActive = false;
|
|
669
|
-
this._onCommit.forEach((func) => func());
|
|
670
|
-
};
|
|
671
|
-
};
|
|
672
|
-
|
|
673
|
-
// ../core/src/paginate/PageManager.ts
|
|
674
|
-
var logPrefix3 = "\x1B[102mPAGE\x1B[0m";
|
|
675
|
-
var PageState = class _PageState {
|
|
676
|
-
currentPage;
|
|
677
|
-
activeElement;
|
|
678
|
-
currentElement;
|
|
679
|
-
parentStack;
|
|
680
|
-
pageIsFull;
|
|
681
|
-
pageIndex;
|
|
682
|
-
pageHeight;
|
|
683
|
-
constructor(currentPage, activeElement, currentElement, parentStack, pageIsFull, pageIndex, pageHeight) {
|
|
684
|
-
this.currentPage = currentPage;
|
|
685
|
-
this.activeElement = activeElement;
|
|
686
|
-
this.currentElement = currentElement;
|
|
687
|
-
this.parentStack = parentStack;
|
|
688
|
-
this.pageIsFull = pageIsFull;
|
|
689
|
-
this.pageIndex = pageIndex;
|
|
690
|
-
this.pageHeight = pageHeight;
|
|
691
|
-
}
|
|
692
|
-
static create(currentPage, parentStack, pageIndex, pageHeight) {
|
|
693
|
-
return new _PageState(
|
|
694
|
-
currentPage,
|
|
695
|
-
null,
|
|
696
|
-
currentPage,
|
|
697
|
-
parentStack,
|
|
698
|
-
false,
|
|
699
|
-
pageIndex,
|
|
700
|
-
pageHeight
|
|
701
|
-
);
|
|
702
|
-
}
|
|
703
|
-
clone = () => {
|
|
704
|
-
return new _PageState(
|
|
705
|
-
this.currentPage,
|
|
706
|
-
this.activeElement,
|
|
707
|
-
this.currentElement,
|
|
708
|
-
[...this.parentStack],
|
|
709
|
-
this.pageIsFull,
|
|
710
|
-
this.pageIndex,
|
|
711
|
-
this.pageHeight
|
|
712
|
-
);
|
|
713
|
-
};
|
|
714
|
-
};
|
|
715
|
-
var PageManager = class _PageManager {
|
|
716
|
-
_pageState;
|
|
717
|
-
_transaction;
|
|
718
|
-
_tempContainer;
|
|
719
|
-
_config;
|
|
720
|
-
constructor(tempContainer, pageSize2, transaction, config) {
|
|
721
|
-
this._tempContainer = tempContainer;
|
|
722
|
-
this._config = config;
|
|
723
|
-
this._transaction = transaction;
|
|
724
|
-
const pageHtmlElement = _PageManager.createPageHtmlElement(
|
|
725
|
-
pageSize2.width
|
|
726
|
-
);
|
|
727
|
-
const page2 = this.createNewPage(pageHtmlElement);
|
|
728
|
-
this._pageState = PageState.create(page2, [], 0, pageSize2.height);
|
|
729
|
-
callPluginHook(this._config.plugins, "onNewPage", config.id, this);
|
|
730
|
-
}
|
|
731
|
-
nextPage() {
|
|
732
|
-
const page2 = this.createNewPage(
|
|
733
|
-
this._pageState.currentPage.getNode().cloneNode(false)
|
|
734
|
-
);
|
|
735
|
-
const newPageState = PageState.create(
|
|
736
|
-
page2,
|
|
737
|
-
[],
|
|
738
|
-
this._pageState.pageIndex + 1,
|
|
739
|
-
this._pageState.pageHeight
|
|
740
|
-
);
|
|
741
|
-
this.cloneParentStackToNewPage(newPageState);
|
|
742
|
-
this.cleanupEmptyParent();
|
|
743
|
-
this._pageState = newPageState;
|
|
744
|
-
callPluginHook(
|
|
745
|
-
this._config.plugins,
|
|
746
|
-
"onNewPage",
|
|
747
|
-
this._config.id,
|
|
748
|
-
this
|
|
749
|
-
);
|
|
750
|
-
}
|
|
751
|
-
cloneParentStackToNewPage(newPageState) {
|
|
752
|
-
for (const parent of this._pageState.parentStack) {
|
|
753
|
-
const clonedParent = parent.clone(false);
|
|
754
|
-
newPageState.currentElement.appendChild(clonedParent);
|
|
755
|
-
newPageState.currentElement = clonedParent;
|
|
756
|
-
newPageState.parentStack.push(clonedParent);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
cleanupEmptyParent() {
|
|
760
|
-
const parentStack = [...this._pageState.parentStack];
|
|
761
|
-
const cleanup = () => {
|
|
762
|
-
for (let i = parentStack.length - 1; i >= 0; i--) {
|
|
763
|
-
const parent = parentStack[i];
|
|
764
|
-
if (parent.isEmpty()) {
|
|
765
|
-
parent.remove();
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
};
|
|
769
|
-
this._transaction.addCommitCallback(cleanup);
|
|
770
|
-
}
|
|
771
|
-
enterElement() {
|
|
772
|
-
if (!this._pageState.activeElement || this._pageState.activeElement.type !== PageNodeType.Element) {
|
|
773
|
-
throw new Error("Invalid state: activeElement is not an Element");
|
|
774
|
-
}
|
|
775
|
-
logger_default.debug(
|
|
776
|
-
logPrefix3,
|
|
777
|
-
"entering an element",
|
|
778
|
-
this._pageState.activeElement
|
|
779
|
-
);
|
|
780
|
-
this._pageState.currentElement = this._pageState.activeElement;
|
|
781
|
-
this._pageState.parentStack.push(this._pageState.activeElement);
|
|
782
|
-
}
|
|
783
|
-
leaveElement() {
|
|
784
|
-
this._pageState.activeElement = null;
|
|
785
|
-
const popped = this._pageState.parentStack.pop();
|
|
786
|
-
logger_default.debug(logPrefix3, "leaving a parent element", popped);
|
|
787
|
-
const parent = this._pageState.parentStack.at(-1);
|
|
788
|
-
this._pageState.currentElement = parent ?? this._pageState.currentPage;
|
|
789
|
-
}
|
|
790
|
-
static createPageHtmlElement(pageWidth) {
|
|
791
|
-
const page2 = document.createElement("div");
|
|
792
|
-
page2.style.width = `${pageWidth}px`;
|
|
793
|
-
page2.style.maxWidth = `${pageWidth}px`;
|
|
794
|
-
return page2;
|
|
795
|
-
}
|
|
796
|
-
createNewPage(pageHtmlElement) {
|
|
797
|
-
this._tempContainer.appendChild(pageHtmlElement);
|
|
798
|
-
if (this._transaction.isActive) {
|
|
799
|
-
this._transaction.addRollbackCallback(() => {
|
|
800
|
-
this._tempContainer.removeChild(pageHtmlElement);
|
|
801
|
-
});
|
|
802
|
-
}
|
|
803
|
-
return createPageNode(pageHtmlElement, this._transaction, this._config);
|
|
804
|
-
}
|
|
805
|
-
startTransaction() {
|
|
806
|
-
this._transaction.start();
|
|
807
|
-
const state = this._pageState.clone();
|
|
808
|
-
this._transaction.addRollbackCallback(() => {
|
|
809
|
-
this._pageState = state;
|
|
810
|
-
});
|
|
811
|
-
return this._transaction;
|
|
812
|
-
}
|
|
813
|
-
hasEmptySpace(elementHeight) {
|
|
814
|
-
return !this._pageState.pageIsFull && this._pageState.currentPage.getHeight() + (elementHeight || 1e-4) <= this._pageState.pageHeight;
|
|
815
|
-
}
|
|
816
|
-
isOverFlow() {
|
|
817
|
-
return this._pageState.currentPage.getHeight() > this._pageState.pageHeight;
|
|
818
|
-
}
|
|
819
|
-
markPageAsFull() {
|
|
820
|
-
this._pageState.pageIsFull = true;
|
|
821
|
-
}
|
|
822
|
-
appendChild(node, withChildren) {
|
|
823
|
-
const clonedNode = node.clone(withChildren);
|
|
824
|
-
DEV: unmarkCurrentNode(clonedNode);
|
|
825
|
-
this._pageState.currentElement.appendChild(clonedNode);
|
|
826
|
-
this._pageState.activeElement = clonedNode;
|
|
827
|
-
return clonedNode;
|
|
828
|
-
}
|
|
829
|
-
addTextNode(text) {
|
|
830
|
-
if (this._pageState.activeElement?.type === PageNodeType.Text) {
|
|
831
|
-
return this._pageState.activeElement;
|
|
832
|
-
}
|
|
833
|
-
const textNode = document.createTextNode(text);
|
|
834
|
-
const newTextNode = createPageNode(
|
|
835
|
-
textNode,
|
|
836
|
-
this._transaction,
|
|
837
|
-
this._config
|
|
838
|
-
);
|
|
839
|
-
this._pageState.currentElement.appendChild(newTextNode);
|
|
840
|
-
this._pageState.activeElement = newTextNode;
|
|
841
|
-
return newTextNode;
|
|
842
|
-
}
|
|
843
|
-
getPageState() {
|
|
844
|
-
return this._pageState;
|
|
845
|
-
}
|
|
846
|
-
};
|
|
847
|
-
|
|
848
|
-
// ../core/src/paginate/SplitResult.ts
|
|
849
|
-
var SplitResult = {
|
|
850
|
-
None: 0,
|
|
851
|
-
// The node fits completely on the page, no further splitting required.
|
|
852
|
-
FullNodePlaced: 1,
|
|
853
|
-
// The entire node was placed on the page, continue with the next sibling or element.
|
|
854
|
-
SplitChildren: 2
|
|
855
|
-
// The node is too large for the page, and its children must be paginated individually.
|
|
856
|
-
};
|
|
857
|
-
|
|
858
|
-
// ../core/src/paginate/paginateElement.ts
|
|
859
|
-
function paginateElementAcrossPages(currentNode, pageManager) {
|
|
860
|
-
const result = tryPlaceElement(currentNode, pageManager);
|
|
861
|
-
if (result !== SplitResult.None) {
|
|
862
|
-
return result;
|
|
863
|
-
}
|
|
864
|
-
const { rollback, commit } = pageManager.startTransaction();
|
|
865
|
-
pageManager.nextPage();
|
|
866
|
-
const nextPageResult = tryPlaceElement(currentNode, pageManager);
|
|
867
|
-
if (nextPageResult !== SplitResult.None) {
|
|
868
|
-
commit();
|
|
869
|
-
return nextPageResult;
|
|
870
|
-
}
|
|
871
|
-
rollback();
|
|
872
|
-
logger_default.debug("Element is too big to fit on a page", currentNode);
|
|
873
|
-
return SplitResult.None;
|
|
874
|
-
}
|
|
875
|
-
function tryPlaceElement(currentNode, pageManager) {
|
|
876
|
-
if (pageManager.hasEmptySpace(currentNode.getHeight())) {
|
|
877
|
-
const clonedNode2 = pageManager.appendChild(currentNode, true);
|
|
878
|
-
if (pageManager.isOverFlow()) {
|
|
879
|
-
clonedNode2.remove();
|
|
880
|
-
} else {
|
|
881
|
-
return SplitResult.FullNodePlaced;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
if (currentNode.config.keepOnSamePage || currentNode.getChildrenCount() === 0) {
|
|
885
|
-
return SplitResult.None;
|
|
886
|
-
}
|
|
887
|
-
const clonedNode = pageManager.appendChild(currentNode, false);
|
|
888
|
-
if (pageManager.isOverFlow()) {
|
|
889
|
-
clonedNode.remove();
|
|
890
|
-
return SplitResult.None;
|
|
891
|
-
}
|
|
892
|
-
return SplitResult.SplitChildren;
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
// ../core/src/paginate/paginateText.ts
|
|
896
|
-
function paginateTextByWord(text, pageManager) {
|
|
897
|
-
let splitResult = SplitResult.FullNodePlaced;
|
|
898
|
-
const tokens = text.textContent.split(/(\s+)/).filter((token) => token !== "");
|
|
899
|
-
let pendingToken;
|
|
900
|
-
let tokenIndex = 0;
|
|
901
|
-
while (pendingToken || tokenIndex < tokens.length) {
|
|
902
|
-
const currentToken = pendingToken ?? tokens[tokenIndex];
|
|
903
|
-
const result = processToken(currentToken, pageManager, text.config);
|
|
904
|
-
if (!result.completed) {
|
|
905
|
-
splitResult = SplitResult.None;
|
|
906
|
-
}
|
|
907
|
-
if (result.pendingToken) {
|
|
908
|
-
pendingToken = result.pendingToken;
|
|
909
|
-
} else {
|
|
910
|
-
pendingToken = void 0;
|
|
911
|
-
tokenIndex++;
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
return splitResult;
|
|
915
|
-
}
|
|
916
|
-
function processToken(token, pageManager, config) {
|
|
917
|
-
if (!pageManager.hasEmptySpace()) {
|
|
918
|
-
pageManager.nextPage();
|
|
919
|
-
}
|
|
920
|
-
const textNode = pageManager.addTextNode("");
|
|
921
|
-
const originalContent = textNode.textContent;
|
|
922
|
-
textNode.textContent += token;
|
|
923
|
-
if (!pageManager.isOverFlow()) {
|
|
924
|
-
return {
|
|
925
|
-
completed: true
|
|
926
|
-
};
|
|
927
|
-
}
|
|
928
|
-
textNode.textContent = originalContent;
|
|
929
|
-
const overflowResult = handleTokenOverflow(token, pageManager, config);
|
|
930
|
-
return {
|
|
931
|
-
pendingToken: overflowResult.leftovers,
|
|
932
|
-
completed: overflowResult.completed
|
|
933
|
-
};
|
|
934
|
-
}
|
|
935
|
-
function handleTokenOverflow(token, pageManager, config) {
|
|
936
|
-
const { rollback, commit } = pageManager.startTransaction();
|
|
937
|
-
pageManager.nextPage();
|
|
938
|
-
pageManager.addTextNode(token);
|
|
939
|
-
if (!pageManager.isOverFlow()) {
|
|
940
|
-
commit();
|
|
941
|
-
return {
|
|
942
|
-
completed: true
|
|
943
|
-
};
|
|
944
|
-
}
|
|
945
|
-
rollback();
|
|
946
|
-
if (config.hyphenationDisabled) {
|
|
947
|
-
logger_default.warn("Hyphenation disabled, skipping oversized token:", token);
|
|
948
|
-
return {
|
|
949
|
-
completed: false
|
|
950
|
-
};
|
|
951
|
-
}
|
|
952
|
-
const leftovers = hyphenation(token, config.hyphen, pageManager);
|
|
953
|
-
return {
|
|
954
|
-
completed: true,
|
|
955
|
-
leftovers: leftovers && leftovers.length > 0 ? leftovers : void 0
|
|
956
|
-
};
|
|
957
|
-
}
|
|
958
|
-
function hyphenation(word, hyphen, pageManager) {
|
|
959
|
-
const textNode = pageManager.addTextNode("");
|
|
960
|
-
let appended = "";
|
|
961
|
-
for (let i = 0; i < word.length; i++) {
|
|
962
|
-
const char = word[i];
|
|
963
|
-
const tentative = appended + char;
|
|
964
|
-
textNode.textContent = tentative + hyphen;
|
|
965
|
-
if (!pageManager.hasEmptySpace()) {
|
|
966
|
-
textNode.textContent = appended ? appended + hyphen : "";
|
|
967
|
-
pageManager.markPageAsFull();
|
|
968
|
-
return word.slice(i);
|
|
969
|
-
}
|
|
970
|
-
appended = tentative;
|
|
971
|
-
}
|
|
972
|
-
return null;
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
// ../core/src/paginate/Paginator.ts
|
|
976
|
-
var import_loglevel2 = __toESM(require_loglevel(), 1);
|
|
977
|
-
var logPrefix4 = "\x1B[103mPAGINATOR\x1B[0m";
|
|
978
|
-
var Paginator = class _Paginator {
|
|
979
|
-
_domState;
|
|
980
|
-
_pageManager;
|
|
981
|
-
_transaction;
|
|
982
|
-
_tempContainer;
|
|
983
|
-
_config;
|
|
984
|
-
constructor(root, pageSize2, config) {
|
|
985
|
-
this._config = { ...defaultPaginationOptions, ...config };
|
|
986
|
-
this._tempContainer = _Paginator.createTempContainer(this._config.id);
|
|
987
|
-
this._transaction = new Transaction();
|
|
988
|
-
this._domState = new DomState(root, this._transaction, this._config);
|
|
989
|
-
this._pageManager = new PageManager(
|
|
990
|
-
this._tempContainer,
|
|
991
|
-
pageSize2,
|
|
992
|
-
this._transaction,
|
|
993
|
-
this._config
|
|
994
|
-
);
|
|
995
|
-
}
|
|
996
|
-
static createTempContainer(id) {
|
|
997
|
-
const tempContainer = document.createElement("div");
|
|
998
|
-
tempContainer.style.display = "flex";
|
|
999
|
-
tempContainer.style.flexDirection = "column";
|
|
1000
|
-
tempContainer.style.gap = "20px";
|
|
1001
|
-
tempContainer.setAttribute(`${attributePrefix}-section-id`, id);
|
|
1002
|
-
tempContainer.classList.add(tempContainerClassName);
|
|
1003
|
-
DEV: if (!isDebugMode()) {
|
|
1004
|
-
moveOffscreen(tempContainer);
|
|
1005
|
-
}
|
|
1006
|
-
document.body.appendChild(tempContainer);
|
|
1007
|
-
return tempContainer;
|
|
1008
|
-
}
|
|
1009
|
-
static paginate(root, pageSize2, config) {
|
|
1010
|
-
const paginator = new _Paginator(root, pageSize2, config);
|
|
1011
|
-
paginator.processAllNodes();
|
|
1012
|
-
const result = Array.from(paginator._tempContainer.childNodes).filter((x) => isElement(x)).map((x) => x.innerHTML);
|
|
1013
|
-
DEV: if (!isDebugMode()) {
|
|
1014
|
-
paginator._tempContainer.remove();
|
|
1015
|
-
}
|
|
1016
|
-
return result;
|
|
1017
|
-
}
|
|
1018
|
-
processAllNodes() {
|
|
1019
|
-
this._domState.goToNextNode();
|
|
1020
|
-
do {
|
|
1021
|
-
import_loglevel2.default.debug(
|
|
1022
|
-
logPrefix4,
|
|
1023
|
-
"paginating node",
|
|
1024
|
-
this._domState.currentNode
|
|
1025
|
-
);
|
|
1026
|
-
const result = this.processCurrentNode();
|
|
1027
|
-
callPluginHook(
|
|
1028
|
-
this._config.plugins,
|
|
1029
|
-
"afterVisitNode",
|
|
1030
|
-
this._config.id,
|
|
1031
|
-
result,
|
|
1032
|
-
this._domState,
|
|
1033
|
-
this._pageManager
|
|
1034
|
-
);
|
|
1035
|
-
switch (result) {
|
|
1036
|
-
case SplitResult.None:
|
|
1037
|
-
this.handleNodeSkipped();
|
|
1038
|
-
break;
|
|
1039
|
-
case SplitResult.FullNodePlaced:
|
|
1040
|
-
this.handleFullNodePlaced();
|
|
1041
|
-
break;
|
|
1042
|
-
case SplitResult.SplitChildren:
|
|
1043
|
-
this.handleChildrenSplit();
|
|
1044
|
-
break;
|
|
1045
|
-
}
|
|
1046
|
-
} while (this._domState.completed === false);
|
|
1047
|
-
import_loglevel2.default.debug(logPrefix4, "pagination completed");
|
|
1048
|
-
}
|
|
1049
|
-
handleNodeSkipped() {
|
|
1050
|
-
import_loglevel2.default.debug(logPrefix4, "node skipped - couldn't paginate");
|
|
1051
|
-
DEV: markIgnoredNode(this._domState.currentNode);
|
|
1052
|
-
this._domState.goToNextNode();
|
|
1053
|
-
}
|
|
1054
|
-
handleFullNodePlaced() {
|
|
1055
|
-
import_loglevel2.default.debug(logPrefix4, "node fully paginated");
|
|
1056
|
-
const { parentsTraversed } = this._domState.goToNextSiblingOrParentSibling();
|
|
1057
|
-
for (let i = 0; i < parentsTraversed; i++) {
|
|
1058
|
-
this._pageManager.leaveElement();
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
handleChildrenSplit() {
|
|
1062
|
-
import_loglevel2.default.debug(
|
|
1063
|
-
logPrefix4,
|
|
1064
|
-
"node partially paginated - splitting children"
|
|
1065
|
-
);
|
|
1066
|
-
if (this._domState.goToFirstChildOrNextNode().parentsTraversed === 1 && this._domState.previousNode?.type === PageNodeType.Element) {
|
|
1067
|
-
this._pageManager.enterElement();
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
processCurrentNode() {
|
|
1071
|
-
if (!this._domState.currentNode) {
|
|
1072
|
-
return SplitResult.None;
|
|
1073
|
-
}
|
|
1074
|
-
if (this._domState.currentNode.type === PageNodeType.Element) {
|
|
1075
|
-
const ctx = {};
|
|
1076
|
-
callPluginHook(
|
|
1077
|
-
this._config.plugins,
|
|
1078
|
-
"onVisitElement",
|
|
1079
|
-
this._config.id,
|
|
1080
|
-
this._domState,
|
|
1081
|
-
this._pageManager,
|
|
1082
|
-
ctx
|
|
1083
|
-
);
|
|
1084
|
-
if (ctx.result !== void 0) {
|
|
1085
|
-
return ctx.result;
|
|
1086
|
-
}
|
|
1087
|
-
return paginateElementAcrossPages(
|
|
1088
|
-
this._domState.currentNode,
|
|
1089
|
-
this._pageManager
|
|
1090
|
-
);
|
|
1091
|
-
} else {
|
|
1092
|
-
const ctx = {};
|
|
1093
|
-
callPluginHook(
|
|
1094
|
-
this._config.plugins,
|
|
1095
|
-
"onVisitText",
|
|
1096
|
-
this._config.id,
|
|
1097
|
-
this._domState,
|
|
1098
|
-
this._pageManager,
|
|
1099
|
-
ctx
|
|
1100
|
-
);
|
|
1101
|
-
if (ctx.result !== void 0) {
|
|
1102
|
-
return ctx.result;
|
|
1103
|
-
}
|
|
1104
|
-
return paginateTextByWord(
|
|
1105
|
-
this._domState.currentNode,
|
|
1106
|
-
this._pageManager
|
|
1107
|
-
);
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
};
|
|
1111
|
-
|
|
1112
|
-
// ../core/src/report/EventDispatcher.ts
|
|
1113
|
-
var EventDispatcher = class {
|
|
1114
|
-
registry = /* @__PURE__ */ new Map();
|
|
1115
|
-
addEventListener(name, handler) {
|
|
1116
|
-
const { registry } = this;
|
|
1117
|
-
const listeners = new Set(registry.get(name));
|
|
1118
|
-
listeners.add(handler);
|
|
1119
|
-
registry.set(name, listeners);
|
|
1120
|
-
return () => this.removeEventListener(name, handler);
|
|
1121
|
-
}
|
|
1122
|
-
removeEventListener(name, handler) {
|
|
1123
|
-
const { registry } = this;
|
|
1124
|
-
const listeners = new Set(registry.get(name));
|
|
1125
|
-
listeners.delete(handler);
|
|
1126
|
-
registry.set(name, listeners);
|
|
1127
|
-
}
|
|
1128
|
-
async dispatch(name, ...args) {
|
|
1129
|
-
const { registry } = this;
|
|
1130
|
-
const listeners = registry.get(name);
|
|
1131
|
-
if (!listeners) {
|
|
1132
|
-
return;
|
|
1133
|
-
}
|
|
1134
|
-
for (const listener of listeners) {
|
|
1135
|
-
await listener(...args);
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
};
|
|
1139
|
-
|
|
1140
|
-
// ../core/src/report/pageConst.ts
|
|
1141
|
-
var pageSize = {
|
|
1142
|
-
/** 841mm x 594mm */
|
|
1143
|
-
A1: { height: "841mm", width: "594mm" },
|
|
1144
|
-
/** 594mm x 420mm */
|
|
1145
|
-
A2: { height: "594mm", width: "420mm" },
|
|
1146
|
-
/** 420mm x 297mm */
|
|
1147
|
-
A3: { height: "420mm", width: "297mm" },
|
|
1148
|
-
/** 297mm x 210mm */
|
|
1149
|
-
A4: { height: "297mm", width: "210mm" },
|
|
1150
|
-
/** 210mm x 148mm */
|
|
1151
|
-
A5: { height: "210mm", width: "148mm" },
|
|
1152
|
-
/** 148mm x 105mm */
|
|
1153
|
-
A6: { height: "148mm", width: "105mm" },
|
|
1154
|
-
/** 500mm x 353mm */
|
|
1155
|
-
B3: { height: "500mm", width: "353mm" },
|
|
1156
|
-
/** 353mm x 250mm */
|
|
1157
|
-
B4: { height: "353mm", width: "250mm" },
|
|
1158
|
-
/** 250mm x 176mm */
|
|
1159
|
-
B5: { height: "250mm", width: "176mm" },
|
|
1160
|
-
/** 8.5in x 11in */
|
|
1161
|
-
Letter: { height: "8.5in", width: "11in" },
|
|
1162
|
-
/** 11in x 8.5in */
|
|
1163
|
-
Legal: { height: "11in", width: "8.5in" },
|
|
1164
|
-
/** 11in x 17in */
|
|
1165
|
-
Tabloid: { height: "11in", width: "17in" }
|
|
1166
|
-
};
|
|
1167
|
-
var pageMargin = {
|
|
1168
|
-
/** Top, Right, Bottom, Left: 1in */
|
|
1169
|
-
Normal: {
|
|
1170
|
-
top: "1in",
|
|
1171
|
-
right: "1in",
|
|
1172
|
-
bottom: "1in",
|
|
1173
|
-
left: "1in"
|
|
1174
|
-
},
|
|
1175
|
-
/** Top: 0.4in, Right, Bottom, Left: 0.6in */
|
|
1176
|
-
Narrow: {
|
|
1177
|
-
top: "0.4in",
|
|
1178
|
-
right: "0.6in",
|
|
1179
|
-
bottom: "0.6in",
|
|
1180
|
-
left: "0.6in"
|
|
1181
|
-
},
|
|
1182
|
-
/** Top, Bottom: 0.5in, Right, Left: 2in */
|
|
1183
|
-
Wide: {
|
|
1184
|
-
top: "0.5in",
|
|
1185
|
-
right: "2in",
|
|
1186
|
-
bottom: "0.5in",
|
|
1187
|
-
left: "2in"
|
|
1188
|
-
},
|
|
1189
|
-
/** Top, Right, Bottom, Left: 0 */
|
|
1190
|
-
None: {
|
|
1191
|
-
top: "0in",
|
|
1192
|
-
right: "0in",
|
|
1193
|
-
bottom: "0in",
|
|
1194
|
-
left: "0in"
|
|
1195
|
-
}
|
|
1196
|
-
};
|
|
1197
|
-
|
|
1198
|
-
// ../core/src/window.ts
|
|
1199
|
-
var paprize_isInitialized = "__PAPRIZE_IS_INITIALIZED";
|
|
1200
|
-
var paprize_isReady = "__PAPRIZE_IS_READY";
|
|
1201
|
-
var paprize_readJsonDataFile = "__PAPRIZE_READ_JSON_DATA_FILE";
|
|
1202
|
-
|
|
1203
|
-
// ../core/src/report/utils.ts
|
|
1204
|
-
function getVisibleSize(element) {
|
|
1205
|
-
const rect = element.getBoundingClientRect();
|
|
1206
|
-
const computedStyle = getComputedStyle(element);
|
|
1207
|
-
const marginLeft = parseFloat(computedStyle.marginLeft) || 0;
|
|
1208
|
-
const marginRight = parseFloat(computedStyle.marginRight) || 0;
|
|
1209
|
-
return {
|
|
1210
|
-
height: getVisibleHeight(element),
|
|
1211
|
-
width: rect.width + marginLeft + marginRight
|
|
1212
|
-
};
|
|
1213
|
-
}
|
|
1214
|
-
function calculatePageSizes(current, sectionHeader, sectionFooter) {
|
|
1215
|
-
const { height, width } = getVisibleSize(current);
|
|
1216
|
-
const sectionHeaderHeight = sectionHeader ? getVisibleHeight(sectionHeader) : 0;
|
|
1217
|
-
const sectionFooterHeight = sectionFooter ? getVisibleHeight(sectionFooter) : 0;
|
|
1218
|
-
return { height, width, sectionHeaderHeight, sectionFooterHeight };
|
|
1219
|
-
}
|
|
1220
|
-
function createSectionPageHeightPlugin(height, sectionHeaderHeight, sectionFooterHeight) {
|
|
1221
|
-
return {
|
|
1222
|
-
name: "sectionPageHeight",
|
|
1223
|
-
order: 1,
|
|
1224
|
-
afterVisitNode: (_id, _result, domState, pageManager) => {
|
|
1225
|
-
const lastPage = domState.completed;
|
|
1226
|
-
if (!lastPage || sectionFooterHeight <= 0) return;
|
|
1227
|
-
if (!pageManager.hasEmptySpace(sectionFooterHeight)) {
|
|
1228
|
-
pageManager.nextPage();
|
|
1229
|
-
}
|
|
1230
|
-
},
|
|
1231
|
-
onNewPage: (_, pageManager) => {
|
|
1232
|
-
const pageState = pageManager.getPageState();
|
|
1233
|
-
if (pageState.pageIndex === 0) {
|
|
1234
|
-
pageState.pageHeight = height + sectionFooterHeight;
|
|
1235
|
-
} else {
|
|
1236
|
-
pageState.pageHeight = height + sectionHeaderHeight + sectionFooterHeight;
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
};
|
|
1240
|
-
}
|
|
1241
|
-
function shorthand(margin) {
|
|
1242
|
-
return margin ? `${margin.top} ${margin.right} ${margin.bottom} ${margin.left}` : "0";
|
|
1243
|
-
}
|
|
1244
|
-
function lazyPromise(factory) {
|
|
1245
|
-
let promise = null;
|
|
1246
|
-
return () => {
|
|
1247
|
-
if (!promise) {
|
|
1248
|
-
promise = factory();
|
|
1249
|
-
}
|
|
1250
|
-
return promise;
|
|
1251
|
-
};
|
|
1252
|
-
}
|
|
1253
|
-
async function jsonDataReader() {
|
|
1254
|
-
if (!(paprize_readJsonDataFile in window)) {
|
|
1255
|
-
return null;
|
|
1256
|
-
}
|
|
1257
|
-
const strData = await window[paprize_readJsonDataFile]?.();
|
|
1258
|
-
return strData ? JSON.parse(strData) : null;
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
// ../core/src/report/reportStyles.ts
|
|
1262
|
-
var globalStyle = `
|
|
1263
|
-
html {
|
|
1264
|
-
box-sizing: border-box;
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
*,
|
|
1268
|
-
*:before,
|
|
1269
|
-
*:after {
|
|
1270
|
-
box-sizing: inherit;
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
:root {
|
|
1274
|
-
--paprize-page-background-color: #ffffff;
|
|
1275
|
-
--paprize-page-margin-bottom: 10px;
|
|
1276
|
-
--paprize-page-box-shadow: rgb(142 138 138) -1px 3px 5px 2px;
|
|
1277
|
-
--paprize-section-margin-bottom: 10px;
|
|
1278
|
-
--paprize-preview-background-color: rgb(218 220 224);
|
|
1279
|
-
--paprize-preview-padding: 30px 10px;
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
body {
|
|
1283
|
-
margin: 0;
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
@media screen {
|
|
1287
|
-
.${previewClassName} {
|
|
1288
|
-
min-height: 100vh;
|
|
1289
|
-
display: flex;
|
|
1290
|
-
flex-direction: column;
|
|
1291
|
-
align-items: center;
|
|
1292
|
-
background-color: var(--paprize-preview-background-color);
|
|
1293
|
-
padding: var(--paprize-preview-padding);
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
.${pageClassName} {
|
|
1297
|
-
box-shadow: var(--paprize-page-box-shadow);
|
|
1298
|
-
margin-bottom: var(--paprize-page-margin-bottom);
|
|
1299
|
-
background-color: var(--paprize-page-background-color);
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
.${sectionClassName} {
|
|
1303
|
-
margin-bottom: var(--paprize-section-margin-bottom);
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
|
-
@media print {
|
|
1308
|
-
html:has(.${previewClassName}) *:not(.${previewClassName}):not(.${previewClassName} *):not(:has(.${previewClassName})) {
|
|
1309
|
-
display: none !important;
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
`;
|
|
1313
|
-
var component = {
|
|
1314
|
-
display: "flex",
|
|
1315
|
-
flexDirection: "column"
|
|
1316
|
-
};
|
|
1317
|
-
var outOfScreen = {
|
|
1318
|
-
position: "absolute",
|
|
1319
|
-
left: "-9999px",
|
|
1320
|
-
top: "-9999px",
|
|
1321
|
-
visibility: "hidden"
|
|
1322
|
-
};
|
|
1323
|
-
var page = (pageSize2, pageMargin2) => ({
|
|
1324
|
-
display: "flex",
|
|
1325
|
-
flexDirection: "column",
|
|
1326
|
-
width: pageSize2.width,
|
|
1327
|
-
height: pageSize2.height,
|
|
1328
|
-
maxHeight: pageSize2.height,
|
|
1329
|
-
position: "relative",
|
|
1330
|
-
padding: shorthand(pageMargin2),
|
|
1331
|
-
zIndex: "1"
|
|
1332
|
-
});
|
|
1333
|
-
var pageContent = {
|
|
1334
|
-
overflow: "hidden",
|
|
1335
|
-
width: "100%",
|
|
1336
|
-
height: "100%"
|
|
1337
|
-
};
|
|
1338
|
-
var overlay = {
|
|
1339
|
-
position: "absolute",
|
|
1340
|
-
width: "100%",
|
|
1341
|
-
height: "100%",
|
|
1342
|
-
left: 0,
|
|
1343
|
-
top: 0
|
|
1344
|
-
};
|
|
1345
|
-
var section = (sectionId2) => ({
|
|
1346
|
-
page: `section-${sectionId2}`
|
|
1347
|
-
});
|
|
1348
|
-
function sectionPageMedia(sectionId2, size) {
|
|
1349
|
-
return `@page section-${sectionId2} {
|
|
1350
|
-
margin: none;
|
|
1351
|
-
size:${size.width} ${size.height};
|
|
1352
|
-
width:${size.width};
|
|
1353
|
-
height:${size.height};
|
|
1354
|
-
}`;
|
|
1355
|
-
}
|
|
1356
|
-
var reportStyles = {
|
|
1357
|
-
globalStyle,
|
|
1358
|
-
component,
|
|
1359
|
-
outOfScreen,
|
|
1360
|
-
page,
|
|
1361
|
-
overlay,
|
|
1362
|
-
pageContent,
|
|
1363
|
-
sectionPageMedia,
|
|
1364
|
-
section
|
|
1365
|
-
};
|
|
1366
|
-
|
|
1367
|
-
// ../core/src/report/sectionComponents.ts
|
|
1368
|
-
function cloneElement(element) {
|
|
1369
|
-
return element?.cloneNode(true) ?? null;
|
|
1370
|
-
}
|
|
1371
|
-
function cloneComponents(components) {
|
|
1372
|
-
return {
|
|
1373
|
-
sectionHeader: cloneElement(components.sectionHeader),
|
|
1374
|
-
sectionFooter: cloneElement(components.sectionFooter),
|
|
1375
|
-
pageHeader: cloneElement(components.pageHeader),
|
|
1376
|
-
pageFooter: cloneElement(components.pageFooter),
|
|
1377
|
-
pageContent: cloneElement(components.pageContent)
|
|
1378
|
-
};
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
// ../core/src/plugins/PageBreakPlugin.ts
|
|
1382
|
-
var pageBreakAttributeName = "data-pz-page-break";
|
|
1383
|
-
var PageBreakPlugin = class {
|
|
1384
|
-
name = "pageBreak";
|
|
1385
|
-
order = 1;
|
|
1386
|
-
onVisitElement = (_id, domState, pageManager, context) => {
|
|
1387
|
-
if (domState.currentNode.getNode().getAttribute(pageBreakAttributeName) === "true") {
|
|
1388
|
-
pageManager.markPageAsFull();
|
|
1389
|
-
context.result = SplitResult.FullNodePlaced;
|
|
1390
|
-
}
|
|
1391
|
-
};
|
|
1392
|
-
};
|
|
1393
|
-
|
|
1394
|
-
// ../core/src/plugins/TablePlugin.ts
|
|
1395
|
-
var TablePlugin = class {
|
|
1396
|
-
_options = {};
|
|
1397
|
-
name = "table";
|
|
1398
|
-
order = 1;
|
|
1399
|
-
constructor(options = {}) {
|
|
1400
|
-
this._options = options;
|
|
1401
|
-
}
|
|
1402
|
-
onNewPage = (_id, pageManager) => {
|
|
1403
|
-
if (this._options.includeHeaderOnlyTables) {
|
|
1404
|
-
return;
|
|
1405
|
-
}
|
|
1406
|
-
const pageState = pageManager.getPageState();
|
|
1407
|
-
const tableElement = pageState.parentStack.find(
|
|
1408
|
-
(node) => this._isTable(node.getNode())
|
|
1409
|
-
);
|
|
1410
|
-
if (!tableElement || !tableElement.clonedFrom) {
|
|
1411
|
-
return;
|
|
1412
|
-
}
|
|
1413
|
-
const openTable = tableElement.clonedFrom;
|
|
1414
|
-
const openTableNode = openTable.getNode();
|
|
1415
|
-
const header = openTableNode.tHead;
|
|
1416
|
-
const hasHeader = header !== null;
|
|
1417
|
-
if (!hasHeader) {
|
|
1418
|
-
return;
|
|
1419
|
-
}
|
|
1420
|
-
const body = openTableNode.tBodies;
|
|
1421
|
-
if (!this._isTableBodyEmpty(body)) {
|
|
1422
|
-
return;
|
|
1423
|
-
}
|
|
1424
|
-
openTable.remove();
|
|
1425
|
-
const newTable = tableElement.getNode();
|
|
1426
|
-
if (newTable.tHead === null) {
|
|
1427
|
-
const headerNode = createPageNode(
|
|
1428
|
-
header.cloneNode(true),
|
|
1429
|
-
tableElement.transaction,
|
|
1430
|
-
tableElement.config
|
|
1431
|
-
);
|
|
1432
|
-
tableElement.appendChild(headerNode);
|
|
1433
|
-
}
|
|
1434
|
-
};
|
|
1435
|
-
onClone = (_id, source, cloned) => {
|
|
1436
|
-
if (source.tagName === "TR") {
|
|
1437
|
-
cloned.config.keepOnSamePage = true;
|
|
1438
|
-
return;
|
|
1439
|
-
}
|
|
1440
|
-
if (!this._isTable(source) || !cloned.clonedFrom || cloned.cloneCount === 1) {
|
|
1441
|
-
return;
|
|
1442
|
-
}
|
|
1443
|
-
const originalNode = cloned.getOriginalNode();
|
|
1444
|
-
const head = originalNode.tHead;
|
|
1445
|
-
if (head && this._options.cloneHeader === true) {
|
|
1446
|
-
const clonedHead = new PageElement(
|
|
1447
|
-
head.cloneNode(true),
|
|
1448
|
-
cloned.transaction,
|
|
1449
|
-
cloned.config
|
|
1450
|
-
);
|
|
1451
|
-
cloned.appendChild(clonedHead);
|
|
1452
|
-
}
|
|
1453
|
-
const foot = originalNode.tFoot;
|
|
1454
|
-
if (foot && this._options.cloneFooter === true) {
|
|
1455
|
-
const clonedFoot = new PageElement(
|
|
1456
|
-
foot.cloneNode(true),
|
|
1457
|
-
cloned.transaction,
|
|
1458
|
-
cloned.config
|
|
1459
|
-
);
|
|
1460
|
-
cloned.appendChild(clonedFoot);
|
|
1461
|
-
}
|
|
1462
|
-
};
|
|
1463
|
-
_isTable(element) {
|
|
1464
|
-
return element.tagName === "TABLE";
|
|
1465
|
-
}
|
|
1466
|
-
_isTableBodyEmpty(body) {
|
|
1467
|
-
if (body.length === 0) return true;
|
|
1468
|
-
const tbody = body[0];
|
|
1469
|
-
if (tbody.rows.length !== 1) return false;
|
|
1470
|
-
const row = tbody.rows[0];
|
|
1471
|
-
if (row.cells.length !== 1) return false;
|
|
1472
|
-
const cell = row.cells[0];
|
|
1473
|
-
return cell.textContent.trim() === "";
|
|
1474
|
-
}
|
|
1475
|
-
};
|
|
1476
|
-
|
|
1477
|
-
// ../core/src/plugins/defaultPlugins.ts
|
|
1478
|
-
var defaultPlugins = [
|
|
1479
|
-
new PageBreakPlugin(),
|
|
1480
|
-
new TablePlugin()
|
|
1481
|
-
];
|
|
1482
|
-
|
|
1483
|
-
// ../core/src/plugins/debugPlugin.ts
|
|
1484
|
-
var debugPlugin = {
|
|
1485
|
-
name: "debug",
|
|
1486
|
-
order: Number.MAX_SAFE_INTEGER,
|
|
1487
|
-
onNewPage: (_, pageManager) => {
|
|
1488
|
-
const page2 = pageManager.getPageState().currentPage.getNode();
|
|
1489
|
-
if (!page2.classList.contains(pageClassName)) {
|
|
1490
|
-
page2.classList.add(pageClassName);
|
|
1491
|
-
}
|
|
1492
|
-
page2.setAttribute(`${attributePrefix}-element`, "page");
|
|
1493
|
-
page2.setAttribute(
|
|
1494
|
-
`${attributePrefix}-height`,
|
|
1495
|
-
pageManager.getPageState().pageHeight.toString()
|
|
1496
|
-
);
|
|
1497
|
-
}
|
|
1498
|
-
};
|
|
1499
|
-
|
|
1500
|
-
// ../core/src/report/PromiseTracker.ts
|
|
1501
|
-
var PromiseTracker = class _PromiseTracker {
|
|
1502
|
-
_promises;
|
|
1503
|
-
monitor;
|
|
1504
|
-
get promise() {
|
|
1505
|
-
return this._promises.length > 0 ? Promise.allSettled(this._promises.map((p) => p.promise)).then(
|
|
1506
|
-
() => {
|
|
1507
|
-
}
|
|
1508
|
-
) : Promise.resolve();
|
|
1509
|
-
}
|
|
1510
|
-
constructor() {
|
|
1511
|
-
this._promises = [];
|
|
1512
|
-
this.monitor = new EventDispatcher();
|
|
1513
|
-
}
|
|
1514
|
-
async add(promises = []) {
|
|
1515
|
-
this._promises.push(...promises.map(_PromiseTracker.toTracked));
|
|
1516
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1517
|
-
if (this.getPending().length === 0) {
|
|
1518
|
-
this.monitor.dispatch("onChange", 0);
|
|
1519
|
-
return;
|
|
1520
|
-
}
|
|
1521
|
-
this._promises.forEach((p) => this.injectEvents(p));
|
|
1522
|
-
}
|
|
1523
|
-
static toTracked(promise) {
|
|
1524
|
-
const tracked = {
|
|
1525
|
-
promise,
|
|
1526
|
-
status: "pending"
|
|
1527
|
-
};
|
|
1528
|
-
tracked.promise.finally(() => {
|
|
1529
|
-
tracked.status = "resolved";
|
|
1530
|
-
});
|
|
1531
|
-
return tracked;
|
|
1532
|
-
}
|
|
1533
|
-
async injectEvents(tracked) {
|
|
1534
|
-
tracked.promise.finally(() => {
|
|
1535
|
-
const pending = this.getPending();
|
|
1536
|
-
this.monitor.dispatch("onChange", pending.length);
|
|
1537
|
-
});
|
|
1538
|
-
}
|
|
1539
|
-
getPending() {
|
|
1540
|
-
return Array.from(this._promises.values()).filter(
|
|
1541
|
-
(p) => p.status === "pending"
|
|
1542
|
-
);
|
|
1543
|
-
}
|
|
1544
|
-
};
|
|
1545
|
-
|
|
1546
|
-
// ../core/src/utils.ts
|
|
1547
|
-
function buildPageId(sectionId2, pageIndex) {
|
|
1548
|
-
return `${sectionId2}-${pageIndex + 1}`;
|
|
1549
|
-
}
|
|
1550
|
-
function adjustPageSize(size, orientation) {
|
|
1551
|
-
if (orientation === "landscape") {
|
|
1552
|
-
return { height: size.width, width: size.height };
|
|
1553
|
-
}
|
|
1554
|
-
return size;
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
// ../core/src/report/ReportBuilder.ts
|
|
1558
|
-
var logPrefix5 = "\x1B[43mREPORT\x1B[0m";
|
|
1559
|
-
var ReportBuilder = class {
|
|
1560
|
-
_sections;
|
|
1561
|
-
_monitor;
|
|
1562
|
-
_paginationInProgress;
|
|
1563
|
-
_pendingPaginateResolvers;
|
|
1564
|
-
_currentAbortController;
|
|
1565
|
-
constructor() {
|
|
1566
|
-
this._sections = /* @__PURE__ */ new Map();
|
|
1567
|
-
this._monitor = new EventDispatcher();
|
|
1568
|
-
this._paginationInProgress = false;
|
|
1569
|
-
this._pendingPaginateResolvers = [];
|
|
1570
|
-
this._currentAbortController = null;
|
|
1571
|
-
window[paprize_isInitialized] = true;
|
|
1572
|
-
this._injectStyle(reportStyles.globalStyle);
|
|
1573
|
-
}
|
|
1574
|
-
/**
|
|
1575
|
-
* Monitor instance used to subscribe to pagination events.
|
|
1576
|
-
* See {@link ReportBuilderEvents} for available event types.
|
|
1577
|
-
*/
|
|
1578
|
-
get monitor() {
|
|
1579
|
-
return this._monitor;
|
|
1580
|
-
}
|
|
1581
|
-
/**
|
|
1582
|
-
* Removes a section from the registered sections, if it has already been registered in the report.
|
|
1583
|
-
*/
|
|
1584
|
-
removeSection(sectionId2) {
|
|
1585
|
-
this._sections.delete(sectionId2);
|
|
1586
|
-
}
|
|
1587
|
-
/**
|
|
1588
|
-
* Registers a section by its ID, specifying the page size, margins, and other options.
|
|
1589
|
-
*
|
|
1590
|
-
* @param options - Configuration options for the section.
|
|
1591
|
-
* @param components - The DOM components associated with the section.
|
|
1592
|
-
* @param onPaginationCompleted - Callback invoked when pagination for the section is completed.
|
|
1593
|
-
* @returns `true` if the section was added to the report’s section list, or `false` if it already exists.
|
|
1594
|
-
*/
|
|
1595
|
-
async tryAddSection(options, components, onPaginationCompleted) {
|
|
1596
|
-
if (this._sections.has(options.id)) {
|
|
1597
|
-
return false;
|
|
1598
|
-
}
|
|
1599
|
-
const context = {
|
|
1600
|
-
sectionIndex: this._sections.size,
|
|
1601
|
-
sectionId: options.id,
|
|
1602
|
-
isPaginated: false,
|
|
1603
|
-
isSuspended: !!options.suspense?.length,
|
|
1604
|
-
pages: []
|
|
1605
|
-
};
|
|
1606
|
-
this._sections.set(options.id, {
|
|
1607
|
-
context,
|
|
1608
|
-
options: {
|
|
1609
|
-
...options,
|
|
1610
|
-
size: adjustPageSize(
|
|
1611
|
-
options.size,
|
|
1612
|
-
options.orientation ?? "portrait"
|
|
1613
|
-
)
|
|
1614
|
-
},
|
|
1615
|
-
components,
|
|
1616
|
-
onPaginationCompleted
|
|
1617
|
-
});
|
|
1618
|
-
this._injectStyle(
|
|
1619
|
-
reportStyles.sectionPageMedia(options.id, options.size)
|
|
1620
|
-
);
|
|
1621
|
-
await this._monitor.dispatch("sectionCreated", context);
|
|
1622
|
-
return true;
|
|
1623
|
-
}
|
|
1624
|
-
/**
|
|
1625
|
-
* Schedules a pagination operation.
|
|
1626
|
-
*
|
|
1627
|
-
* It is not possible to schedule multiple pagination operations in parallel,
|
|
1628
|
-
* as the process involves DOM manipulation, and concurrent modifications
|
|
1629
|
-
* could cause conflicts and unexpected results.
|
|
1630
|
-
* Each newly scheduled operation is queued and executed sequentially.
|
|
1631
|
-
* When a new pagination is scheduled, any ongoing or pending operations
|
|
1632
|
-
* will be aborted, and the new pagination will start immediately afterward.
|
|
1633
|
-
*
|
|
1634
|
-
* @returns A promise that resolves when the first pagination cycle is completed.
|
|
1635
|
-
* It does not wait for suspended sections to resolve and be paginated.
|
|
1636
|
-
* To wait for all sections to complete pagination, use the
|
|
1637
|
-
* `suspension` property of the returned result object.
|
|
1638
|
-
*/
|
|
1639
|
-
async schedulePagination() {
|
|
1640
|
-
if (this._sections.size === 0) {
|
|
1641
|
-
window[paprize_isReady] = true;
|
|
1642
|
-
return {
|
|
1643
|
-
sections: [],
|
|
1644
|
-
suspension: Promise.resolve()
|
|
1645
|
-
};
|
|
1646
|
-
}
|
|
1647
|
-
if (this._paginationInProgress && this._currentAbortController) {
|
|
1648
|
-
logger_default.debug(
|
|
1649
|
-
logPrefix5,
|
|
1650
|
-
`Cancelling previous pagination operation.`
|
|
1651
|
-
);
|
|
1652
|
-
this._currentAbortController.abort(
|
|
1653
|
-
"Cancelled by new paginate call"
|
|
1654
|
-
);
|
|
1655
|
-
}
|
|
1656
|
-
if (this._paginationInProgress) {
|
|
1657
|
-
return new Promise((resolve, reject) => {
|
|
1658
|
-
this._pendingPaginateResolvers.push({ resolve, reject });
|
|
1659
|
-
});
|
|
1660
|
-
}
|
|
1661
|
-
return this._executePagination();
|
|
1662
|
-
}
|
|
1663
|
-
/**
|
|
1664
|
-
* Retrieves JSON data injected by **@paprize/puppeteer** during server-side rendering (SSR).
|
|
1665
|
-
*
|
|
1666
|
-
* If no injected data is available, the function returns the provided `defaultData`, or `null` if none is given.
|
|
1667
|
-
*
|
|
1668
|
-
* ⚠️ **Important Notes:**
|
|
1669
|
-
* - This function is **not type-safe** — it performs **no runtime type validation** on the returned data.
|
|
1670
|
-
* - It is available **only during server-side rendering** when using **@paprize/puppeteer**.
|
|
1671
|
-
* - When used in **client-side rendering** or **development** mode, you should provide a `defaultData` value for testing purposes.
|
|
1672
|
-
*
|
|
1673
|
-
* @template T - The expected type of the injected JSON data.
|
|
1674
|
-
* @param defaultData - Optional fallback value to return if no injected data is found.
|
|
1675
|
-
* @returns A promise resolving to the injected JSON data if available, otherwise the provided default value or `null`.
|
|
1676
|
-
*/
|
|
1677
|
-
async getJsonData(defaultData) {
|
|
1678
|
-
const json = await this._lazyJsonDataReader().catch(() => defaultData);
|
|
1679
|
-
return json ?? defaultData ?? null;
|
|
1680
|
-
}
|
|
1681
|
-
_lazyJsonDataReader = lazyPromise(jsonDataReader);
|
|
1682
|
-
async _executePagination() {
|
|
1683
|
-
this._paginationInProgress = true;
|
|
1684
|
-
this._currentAbortController = new AbortController();
|
|
1685
|
-
const abortSignal = this._currentAbortController.signal;
|
|
1686
|
-
try {
|
|
1687
|
-
logger_default.debug(logPrefix5, `Schedule paginate.`);
|
|
1688
|
-
await document.fonts.ready;
|
|
1689
|
-
if (abortSignal.aborted) {
|
|
1690
|
-
return new Promise((resolve, reject) => {
|
|
1691
|
-
this._pendingPaginateResolvers.push({ resolve, reject });
|
|
1692
|
-
});
|
|
1693
|
-
}
|
|
1694
|
-
const trackers = [];
|
|
1695
|
-
for (const state of this._sections.values()) {
|
|
1696
|
-
state.context.isPaginated = false;
|
|
1697
|
-
const tracker = new PromiseTracker();
|
|
1698
|
-
await tracker.add(state.options.suspense);
|
|
1699
|
-
tracker.monitor.addEventListener("onChange", (pendingCount) => {
|
|
1700
|
-
logger_default.debug(
|
|
1701
|
-
logPrefix5,
|
|
1702
|
-
`${pendingCount} pending promises in section '${state.options.id}'.`
|
|
1703
|
-
);
|
|
1704
|
-
});
|
|
1705
|
-
tracker.promise.then(async () => {
|
|
1706
|
-
if (abortSignal.aborted) {
|
|
1707
|
-
return;
|
|
1708
|
-
}
|
|
1709
|
-
logger_default.debug(
|
|
1710
|
-
logPrefix5,
|
|
1711
|
-
`Start paginating section '${state.options.id}'.`
|
|
1712
|
-
);
|
|
1713
|
-
state.context.isSuspended = false;
|
|
1714
|
-
this._paginateSection(state);
|
|
1715
|
-
});
|
|
1716
|
-
trackers.push(tracker);
|
|
1717
|
-
}
|
|
1718
|
-
const reportTracker = new PromiseTracker();
|
|
1719
|
-
reportTracker.monitor.addEventListener("onChange", async () => {
|
|
1720
|
-
logger_default.debug(logPrefix5, "Report pagination completed.");
|
|
1721
|
-
await this._monitor.dispatch("paginationCycleCompleted", {
|
|
1722
|
-
sections: [...this._sections.values()].map(
|
|
1723
|
-
(s) => s.context
|
|
1724
|
-
)
|
|
1725
|
-
});
|
|
1726
|
-
});
|
|
1727
|
-
if (abortSignal.aborted) {
|
|
1728
|
-
return new Promise((resolve, reject) => {
|
|
1729
|
-
this._pendingPaginateResolvers.push({ resolve, reject });
|
|
1730
|
-
});
|
|
1731
|
-
}
|
|
1732
|
-
await reportTracker.add(trackers.map((t) => t.promise));
|
|
1733
|
-
return {
|
|
1734
|
-
sections: [...this._sections.values()].map((s) => s.context),
|
|
1735
|
-
suspension: reportTracker.promise.then(() => {
|
|
1736
|
-
window[paprize_isReady] = true;
|
|
1737
|
-
})
|
|
1738
|
-
};
|
|
1739
|
-
} finally {
|
|
1740
|
-
this._processPendingPagination();
|
|
1741
|
-
this._paginationInProgress = false;
|
|
1742
|
-
this._currentAbortController = null;
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
async _processPendingPagination() {
|
|
1746
|
-
if (this._pendingPaginateResolvers.length === 0) {
|
|
1747
|
-
return;
|
|
1748
|
-
}
|
|
1749
|
-
logger_default.debug(
|
|
1750
|
-
logPrefix5,
|
|
1751
|
-
`Processing ${this._pendingPaginateResolvers.length} pending paginate calls.`
|
|
1752
|
-
);
|
|
1753
|
-
const pendingResolvers = [...this._pendingPaginateResolvers];
|
|
1754
|
-
this._pendingPaginateResolvers = [];
|
|
1755
|
-
const nextResult = await this._executePagination();
|
|
1756
|
-
for (const resolver of pendingResolvers) {
|
|
1757
|
-
resolver.resolve(nextResult);
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
_injectStyle(styleContent) {
|
|
1761
|
-
let style = document.getElementById(
|
|
1762
|
-
globalStyleId
|
|
1763
|
-
);
|
|
1764
|
-
if (!style) {
|
|
1765
|
-
style = document.createElement("style");
|
|
1766
|
-
style.id = globalStyleId;
|
|
1767
|
-
style.textContent = "";
|
|
1768
|
-
document.head.appendChild(style);
|
|
1769
|
-
}
|
|
1770
|
-
style.textContent = (style.textContent + styleContent).replace(/\s+/g, " ").replace(/\s*([:;{}])\s*/g, "$1").trim();
|
|
1771
|
-
}
|
|
1772
|
-
async _paginateSection(state) {
|
|
1773
|
-
const temporarilyContainer = document.createElement("div");
|
|
1774
|
-
Object.assign(
|
|
1775
|
-
temporarilyContainer.style,
|
|
1776
|
-
reportStyles.page(
|
|
1777
|
-
state.options.size,
|
|
1778
|
-
state.options.margin ?? pageMargin.None
|
|
1779
|
-
)
|
|
1780
|
-
);
|
|
1781
|
-
if (!isDebugMode()) {
|
|
1782
|
-
Object.assign(temporarilyContainer.style, reportStyles.outOfScreen);
|
|
1783
|
-
}
|
|
1784
|
-
const components = cloneComponents(state.components);
|
|
1785
|
-
if (components.sectionHeader) {
|
|
1786
|
-
Object.assign(
|
|
1787
|
-
components.sectionHeader.style,
|
|
1788
|
-
reportStyles.component
|
|
1789
|
-
);
|
|
1790
|
-
temporarilyContainer.appendChild(components.sectionHeader);
|
|
1791
|
-
}
|
|
1792
|
-
if (components.pageHeader) {
|
|
1793
|
-
Object.assign(components.pageHeader.style, reportStyles.component);
|
|
1794
|
-
temporarilyContainer.appendChild(components.pageHeader);
|
|
1795
|
-
}
|
|
1796
|
-
Object.assign(components.pageContent.style, reportStyles.pageContent);
|
|
1797
|
-
temporarilyContainer.appendChild(components.pageContent);
|
|
1798
|
-
if (components.pageFooter) {
|
|
1799
|
-
Object.assign(components.pageFooter.style, reportStyles.component);
|
|
1800
|
-
temporarilyContainer.appendChild(components.pageFooter);
|
|
1801
|
-
}
|
|
1802
|
-
if (components.sectionFooter) {
|
|
1803
|
-
Object.assign(
|
|
1804
|
-
components.sectionFooter.style,
|
|
1805
|
-
reportStyles.component
|
|
1806
|
-
);
|
|
1807
|
-
temporarilyContainer.appendChild(components.sectionFooter);
|
|
1808
|
-
}
|
|
1809
|
-
document.body.appendChild(temporarilyContainer);
|
|
1810
|
-
const { height, width, sectionHeaderHeight, sectionFooterHeight } = calculatePageSizes(
|
|
1811
|
-
components.pageContent,
|
|
1812
|
-
components.sectionHeader,
|
|
1813
|
-
components.sectionFooter
|
|
1814
|
-
);
|
|
1815
|
-
const paginatorResult = Paginator.paginate(
|
|
1816
|
-
components.pageContent,
|
|
1817
|
-
{ height, width },
|
|
1818
|
-
{
|
|
1819
|
-
id: state.options.id,
|
|
1820
|
-
plugins: [
|
|
1821
|
-
...state.options.plugins ?? defaultPlugins,
|
|
1822
|
-
createSectionPageHeightPlugin(
|
|
1823
|
-
height,
|
|
1824
|
-
sectionHeaderHeight,
|
|
1825
|
-
sectionFooterHeight
|
|
1826
|
-
)
|
|
1827
|
-
]
|
|
1828
|
-
}
|
|
1829
|
-
);
|
|
1830
|
-
temporarilyContainer.remove();
|
|
1831
|
-
const pageContexts = paginatorResult.map((content, index) => ({
|
|
1832
|
-
pageIndex: index,
|
|
1833
|
-
totalPages: paginatorResult.length,
|
|
1834
|
-
sectionId: state.options.id,
|
|
1835
|
-
pageContentHtml: content
|
|
1836
|
-
}));
|
|
1837
|
-
state.onPaginationCompleted(pageContexts);
|
|
1838
|
-
for (const pageContext of pageContexts) {
|
|
1839
|
-
await this._monitor.dispatch("pageCompleted", pageContext);
|
|
1840
|
-
}
|
|
1841
|
-
const sectionContext = {
|
|
1842
|
-
...state.context,
|
|
1843
|
-
isPaginated: true,
|
|
1844
|
-
isSuspended: false,
|
|
1845
|
-
pages: pageContexts
|
|
1846
|
-
};
|
|
1847
|
-
this._sections.set(state.options.id, {
|
|
1848
|
-
...state,
|
|
1849
|
-
context: sectionContext
|
|
1850
|
-
});
|
|
1851
|
-
await this._monitor.dispatch("sectionCompleted", sectionContext);
|
|
1852
|
-
}
|
|
1853
|
-
};
|
|
1854
|
-
|
|
1855
|
-
// ../vanilla/src/attributes.ts
|
|
1856
|
-
var sectionAttribute = `${attributePrefix}section`;
|
|
1857
|
-
var previewAttribute = `${attributePrefix}preview`;
|
|
1858
|
-
var sectionHeaderAttribute = `${attributePrefix}section-header`;
|
|
1859
|
-
var sectionFooterAttribute = `${attributePrefix}section-footer`;
|
|
1860
|
-
var pageHeaderAttribute = `${attributePrefix}page-header`;
|
|
1861
|
-
var pageFooterAttribute = `${attributePrefix}page-footer`;
|
|
1862
|
-
var pageContentAttribute = `${attributePrefix}page-content`;
|
|
1863
|
-
var pageOverlayAttribute = `${attributePrefix}page-overlay`;
|
|
1864
|
-
var sectionIdMetadataAttribute = `${attributePrefix}section-id`;
|
|
1865
|
-
var pageIndexMetadataAttribute = `${attributePrefix}page-index`;
|
|
1866
|
-
var pageNumberValueAttribute = `${attributePrefix}v-page-number`;
|
|
1867
|
-
var totalPagesValueAttribute = `${attributePrefix}v-total-pages`;
|
|
1868
|
-
var sectionNumberValueAttribute = `${attributePrefix}v-section-number`;
|
|
1869
|
-
var totalSectionsValueAttribute = `${attributePrefix}v-total-sections`;
|
|
1870
|
-
var jsonDataValueAttribute = `${attributePrefix}v-json-data-key`;
|
|
1871
|
-
|
|
1872
|
-
// ../vanilla/src/utils.ts
|
|
1873
|
-
function get(obj, path) {
|
|
1874
|
-
if (!obj || !path) {
|
|
1875
|
-
return;
|
|
1876
|
-
}
|
|
1877
|
-
const keys = path.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
|
|
1878
|
-
let result = obj;
|
|
1879
|
-
for (const key of keys) {
|
|
1880
|
-
if (result == null) {
|
|
1881
|
-
return;
|
|
1882
|
-
}
|
|
1883
|
-
result = result[key];
|
|
1884
|
-
}
|
|
1885
|
-
return result?.toString();
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
|
-
// ../vanilla/src/PaprizeReport.ts
|
|
1889
|
-
var globalStyles = `
|
|
1890
|
-
[${sectionAttribute}=true] {
|
|
1891
|
-
display: none;
|
|
1892
|
-
}
|
|
1893
|
-
`;
|
|
1894
|
-
var PaprizeReport = class {
|
|
1895
|
-
_sections = /* @__PURE__ */ new Map();
|
|
1896
|
-
_reportManager;
|
|
1897
|
-
_monitor;
|
|
1898
|
-
_root;
|
|
1899
|
-
_options;
|
|
1900
|
-
/** @public */
|
|
1901
|
-
constructor(options) {
|
|
1902
|
-
const style = document.createElement("style");
|
|
1903
|
-
style.textContent = globalStyles;
|
|
1904
|
-
document.head.appendChild(style);
|
|
1905
|
-
this._options = options ?? {};
|
|
1906
|
-
this._monitor = new EventDispatcher();
|
|
1907
|
-
this._reportManager = new ReportBuilder();
|
|
1908
|
-
this._root = this._createRootElement();
|
|
1909
|
-
this._reportManager.monitor.addEventListener(
|
|
1910
|
-
"sectionCreated",
|
|
1911
|
-
(event) => {
|
|
1912
|
-
this._monitor.dispatch("sectionCreated", {
|
|
1913
|
-
...event,
|
|
1914
|
-
pages: []
|
|
1915
|
-
});
|
|
1916
|
-
}
|
|
1917
|
-
);
|
|
1918
|
-
this._reportManager.monitor.addEventListener(
|
|
1919
|
-
"sectionCompleted",
|
|
1920
|
-
(event) => {
|
|
1921
|
-
const pages = this._getSectionState(event.sectionId).pages;
|
|
1922
|
-
this._monitor.dispatch("sectionCompleted", {
|
|
1923
|
-
...event,
|
|
1924
|
-
pages: pages ?? []
|
|
1925
|
-
});
|
|
1926
|
-
}
|
|
1927
|
-
);
|
|
1928
|
-
this._reportManager.monitor.addEventListener(
|
|
1929
|
-
"pageCompleted",
|
|
1930
|
-
(event) => {
|
|
1931
|
-
const pages = this._getSectionState(event.sectionId).pages;
|
|
1932
|
-
this._monitor.dispatch("pageCompleted", pages[event.pageIndex]);
|
|
1933
|
-
}
|
|
1934
|
-
);
|
|
1935
|
-
this._reportManager.monitor.addEventListener(
|
|
1936
|
-
"paginationCycleCompleted",
|
|
1937
|
-
(event) => {
|
|
1938
|
-
this._monitor.dispatch("paginationCycleCompleted", {
|
|
1939
|
-
sections: event.sections.map((s) => ({
|
|
1940
|
-
...s,
|
|
1941
|
-
pages: this._sections.get(s.sectionId)?.pages ?? []
|
|
1942
|
-
}))
|
|
1943
|
-
});
|
|
1944
|
-
}
|
|
1945
|
-
);
|
|
1946
|
-
}
|
|
1947
|
-
_createRootElement() {
|
|
1948
|
-
const wrapper = document.createElement("div");
|
|
1949
|
-
if (document.querySelector(`[${previewAttribute}]`)) {
|
|
1950
|
-
wrapper.classList.add(previewClassName);
|
|
1951
|
-
}
|
|
1952
|
-
(this._options.root ?? document.body).appendChild(wrapper);
|
|
1953
|
-
return wrapper;
|
|
1954
|
-
}
|
|
1955
|
-
/**
|
|
1956
|
-
* {@inheritDoc @paprize/core!ReportBuilder.schedulePagination}
|
|
1957
|
-
*/
|
|
1958
|
-
async schedulePagination() {
|
|
1959
|
-
const result = await this._reportManager.schedulePagination();
|
|
1960
|
-
return {
|
|
1961
|
-
suspension: result.suspension,
|
|
1962
|
-
sections: result.sections.map((s) => ({
|
|
1963
|
-
...s,
|
|
1964
|
-
pages: this._sections.get(s.sectionId)?.pages ?? []
|
|
1965
|
-
}))
|
|
1966
|
-
};
|
|
1967
|
-
}
|
|
1968
|
-
/**
|
|
1969
|
-
* Monitor instance used to subscribe to pagination events.
|
|
1970
|
-
* See {@link PaprizeReportEvents} for available event types.
|
|
1971
|
-
*/
|
|
1972
|
-
get monitor() {
|
|
1973
|
-
return this._monitor;
|
|
1974
|
-
}
|
|
1975
|
-
/**
|
|
1976
|
-
* Registers a section by its id, specifying the page size, margins, and other options.
|
|
1977
|
-
* If a section with the same id already exists, the operation will be ignored.
|
|
1978
|
-
* @param options - Configuration options for the section.
|
|
1979
|
-
*/
|
|
1980
|
-
async addSection(options) {
|
|
1981
|
-
if (this._sections.has(options.id)) {
|
|
1982
|
-
return this;
|
|
1983
|
-
}
|
|
1984
|
-
const section2 = document.getElementById(options.id);
|
|
1985
|
-
if (!section2) {
|
|
1986
|
-
throw new Error(
|
|
1987
|
-
`Section with id ${options.id} not found in the DOM.`
|
|
1988
|
-
);
|
|
1989
|
-
}
|
|
1990
|
-
const components = this._getSectionComponents(section2);
|
|
1991
|
-
const sectionElement = this._createSectionInDom(options.id);
|
|
1992
|
-
const result = await this._reportManager.tryAddSection(
|
|
1993
|
-
options,
|
|
1994
|
-
components,
|
|
1995
|
-
(pageContexts) => {
|
|
1996
|
-
this._renderSection(options, pageContexts);
|
|
1997
|
-
}
|
|
1998
|
-
);
|
|
1999
|
-
if (!result) {
|
|
2000
|
-
this._root.removeChild(sectionElement);
|
|
2001
|
-
logger_default.error(
|
|
2002
|
-
`Section with id ${options.id} already exists in the report manager.`
|
|
2003
|
-
);
|
|
2004
|
-
return this;
|
|
2005
|
-
}
|
|
2006
|
-
this._sections.set(options.id, {
|
|
2007
|
-
pages: [],
|
|
2008
|
-
sectionElement,
|
|
2009
|
-
components,
|
|
2010
|
-
options
|
|
2011
|
-
});
|
|
2012
|
-
return this;
|
|
2013
|
-
}
|
|
2014
|
-
_getSectionState(id) {
|
|
2015
|
-
const state = this._sections.get(id);
|
|
2016
|
-
if (!state) {
|
|
2017
|
-
throw new Error(`Section with id ${id} not found in the report.`);
|
|
2018
|
-
}
|
|
2019
|
-
return state;
|
|
2020
|
-
}
|
|
2021
|
-
_createSectionInDom(sectionId2) {
|
|
2022
|
-
const section2 = document.createElement("div");
|
|
2023
|
-
section2.setAttribute(sectionIdMetadataAttribute, sectionId2);
|
|
2024
|
-
section2.classList.add(sectionClassName);
|
|
2025
|
-
section2.id = sectionId2;
|
|
2026
|
-
Object.assign(section2.style, reportStyles.section(sectionId2));
|
|
2027
|
-
this._root.appendChild(section2);
|
|
2028
|
-
return section2;
|
|
2029
|
-
}
|
|
2030
|
-
_getSectionComponents(section2) {
|
|
2031
|
-
const pageContent2 = section2.querySelector(
|
|
2032
|
-
`[${pageContentAttribute}]`
|
|
2033
|
-
);
|
|
2034
|
-
if (!pageContent2) {
|
|
2035
|
-
throw new Error(
|
|
2036
|
-
`Page content not found in section with id ${section2.id}`
|
|
2037
|
-
);
|
|
2038
|
-
}
|
|
2039
|
-
return {
|
|
2040
|
-
sectionHeader: section2.querySelector(
|
|
2041
|
-
`[${sectionHeaderAttribute}]`
|
|
2042
|
-
),
|
|
2043
|
-
sectionFooter: section2.querySelector(
|
|
2044
|
-
`[${sectionFooterAttribute}]`
|
|
2045
|
-
),
|
|
2046
|
-
pageHeader: section2.querySelector(
|
|
2047
|
-
`[${pageHeaderAttribute}]`
|
|
2048
|
-
),
|
|
2049
|
-
pageFooter: section2.querySelector(
|
|
2050
|
-
`[${pageFooterAttribute}]`
|
|
2051
|
-
),
|
|
2052
|
-
pageContent: pageContent2
|
|
2053
|
-
};
|
|
2054
|
-
}
|
|
2055
|
-
async _renderSection(options, pageContexts) {
|
|
2056
|
-
const state = this._getSectionState(options.id);
|
|
2057
|
-
if (!this._options.keepInitialElementAfterPagination) {
|
|
2058
|
-
document.getElementById(options.id)?.remove();
|
|
2059
|
-
}
|
|
2060
|
-
const pages = [];
|
|
2061
|
-
for (const pageContext of pageContexts) {
|
|
2062
|
-
const page2 = document.createElement("div");
|
|
2063
|
-
page2.classList.add(pageClassName);
|
|
2064
|
-
page2.id = buildPageId(options.id, pageContext.pageIndex);
|
|
2065
|
-
page2.setAttribute(
|
|
2066
|
-
pageIndexMetadataAttribute,
|
|
2067
|
-
pageContext.pageIndex.toString()
|
|
2068
|
-
);
|
|
2069
|
-
Object.assign(
|
|
2070
|
-
page2.style,
|
|
2071
|
-
reportStyles.page(
|
|
2072
|
-
options.size,
|
|
2073
|
-
options.margin ?? pageMargin.None
|
|
2074
|
-
)
|
|
2075
|
-
);
|
|
2076
|
-
const components = cloneComponents(state.components);
|
|
2077
|
-
if (pageContext.pageIndex === 0 && components.sectionHeader) {
|
|
2078
|
-
page2.appendChild(components.sectionHeader);
|
|
2079
|
-
}
|
|
2080
|
-
if (components.pageHeader) {
|
|
2081
|
-
page2.appendChild(components.pageHeader);
|
|
2082
|
-
}
|
|
2083
|
-
const pageContent2 = document.createElement("div");
|
|
2084
|
-
pageContent2.innerHTML = pageContext.pageContentHtml;
|
|
2085
|
-
page2.appendChild(pageContent2);
|
|
2086
|
-
const pageFooterContainer = document.createElement("div");
|
|
2087
|
-
pageFooterContainer.style.marginTop = "auto";
|
|
2088
|
-
if (components.pageFooter) {
|
|
2089
|
-
pageFooterContainer.appendChild(components.pageFooter);
|
|
2090
|
-
}
|
|
2091
|
-
if (pageContext.pageIndex === pageContexts.length - 1 && components.sectionFooter) {
|
|
2092
|
-
pageFooterContainer.appendChild(
|
|
2093
|
-
components.sectionFooter.cloneNode(true)
|
|
2094
|
-
);
|
|
2095
|
-
}
|
|
2096
|
-
if (pageFooterContainer.children.length > 0) {
|
|
2097
|
-
page2.appendChild(pageFooterContainer);
|
|
2098
|
-
}
|
|
2099
|
-
await this._replaceContentInfoValues(
|
|
2100
|
-
{ ...components, pageContent: pageContent2 },
|
|
2101
|
-
pageContext
|
|
2102
|
-
);
|
|
2103
|
-
state.sectionElement.appendChild(page2);
|
|
2104
|
-
const domPageContext = {
|
|
2105
|
-
sectionId: options.id,
|
|
2106
|
-
pageIndex: pageContext.pageIndex,
|
|
2107
|
-
totalPages: pageContexts.length,
|
|
2108
|
-
page: page2,
|
|
2109
|
-
components: { ...components, pageContent: pageContent2 }
|
|
2110
|
-
};
|
|
2111
|
-
pages.push(domPageContext);
|
|
2112
|
-
}
|
|
2113
|
-
this._sections.set(options.id, {
|
|
2114
|
-
...state,
|
|
2115
|
-
pages
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
async _replaceContentInfoValues(components, pageContext) {
|
|
2119
|
-
const jsonData = await this._reportManager.getJsonData();
|
|
2120
|
-
for (const component2 of Object.values(components)) {
|
|
2121
|
-
if (!component2) continue;
|
|
2122
|
-
component2.querySelectorAll(`[${pageNumberValueAttribute}]`).forEach((el) => {
|
|
2123
|
-
el.textContent = (pageContext.pageIndex + 1).toString();
|
|
2124
|
-
});
|
|
2125
|
-
component2.querySelectorAll(`[${totalPagesValueAttribute}]`).forEach((el) => {
|
|
2126
|
-
el.textContent = pageContext.totalPages.toString();
|
|
2127
|
-
});
|
|
2128
|
-
component2.querySelectorAll(`[${sectionNumberValueAttribute}]`).forEach((el) => {
|
|
2129
|
-
el.textContent = (Array.from(this._sections.keys()).indexOf(
|
|
2130
|
-
pageContext.sectionId
|
|
2131
|
-
) + 1).toString();
|
|
2132
|
-
});
|
|
2133
|
-
component2.querySelectorAll(`[${totalSectionsValueAttribute}]`).forEach((el) => {
|
|
2134
|
-
el.textContent = this._sections.size.toString();
|
|
2135
|
-
});
|
|
2136
|
-
component2.querySelectorAll(`[${jsonDataValueAttribute}]`).forEach((el) => {
|
|
2137
|
-
const key = el.getAttribute(jsonDataValueAttribute);
|
|
2138
|
-
const value = get(jsonData, key);
|
|
2139
|
-
el.textContent = value ?? "";
|
|
2140
|
-
});
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
};
|
|
2144
|
-
|
|
2145
|
-
// src/zeroReport.ts
|
|
2146
|
-
var sectionPageSizeAttribute = `${attributePrefix}section-page-size`;
|
|
2147
|
-
var sectionPageMarginAttribute = `${attributePrefix}section-page-margin`;
|
|
2148
|
-
function parsePageSizeAttribute(section2) {
|
|
2149
|
-
const sizeAttributeValue = section2.getAttribute(sectionPageSizeAttribute);
|
|
2150
|
-
const size = Object.entries(pageSize).find(
|
|
2151
|
-
([key]) => key.toLowerCase() === sizeAttributeValue?.toLowerCase()
|
|
2152
|
-
)?.[1];
|
|
2153
|
-
return size ?? pageSize.A4;
|
|
2154
|
-
}
|
|
2155
|
-
function parsePageMarginAttribute(section2) {
|
|
2156
|
-
const size = section2.getAttribute(sectionPageMarginAttribute);
|
|
2157
|
-
const margin = Object.entries(pageMargin).find(
|
|
2158
|
-
([key]) => key.toLowerCase() === size?.toLowerCase()
|
|
2159
|
-
)?.[1];
|
|
2160
|
-
return margin ?? pageMargin.Narrow;
|
|
2161
|
-
}
|
|
2162
|
-
var sectionId = 1;
|
|
2163
|
-
var report = new PaprizeReport();
|
|
2164
|
-
var elements = document.querySelectorAll(`[${sectionAttribute}]`);
|
|
2165
|
-
for (const el of elements) {
|
|
2166
|
-
const id = el.id || `section-${sectionId++}`;
|
|
2167
|
-
if (!el.id) {
|
|
2168
|
-
el.id = id;
|
|
2169
|
-
}
|
|
2170
|
-
await report.addSection({
|
|
2171
|
-
size: parsePageSizeAttribute(el),
|
|
2172
|
-
margin: parsePageMarginAttribute(el),
|
|
2173
|
-
id
|
|
2174
|
-
});
|
|
2175
|
-
}
|
|
2176
|
-
await report.schedulePagination();
|
|
2177
|
-
export {
|
|
2178
|
-
sectionPageMarginAttribute,
|
|
2179
|
-
sectionPageSizeAttribute
|
|
2180
|
-
};
|
|
2181
|
-
//# sourceMappingURL=paprize-zero.js.map
|