@paprize/puppeteer 0.0.3 → 0.0.5
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.
|
@@ -0,0 +1,2041 @@
|
|
|
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/attributes.ts
|
|
319
|
+
var AttributeValueDef = class _AttributeValueDef {
|
|
320
|
+
name;
|
|
321
|
+
defaultValue;
|
|
322
|
+
_reader;
|
|
323
|
+
constructor(name, reader, defaultValue) {
|
|
324
|
+
this.name = name;
|
|
325
|
+
this._reader = reader;
|
|
326
|
+
this.defaultValue = defaultValue;
|
|
327
|
+
}
|
|
328
|
+
read(value) {
|
|
329
|
+
return this._reader(value);
|
|
330
|
+
}
|
|
331
|
+
static createStr(name, defaultValue) {
|
|
332
|
+
return new _AttributeValueDef(name, (value) => value, defaultValue);
|
|
333
|
+
}
|
|
334
|
+
static createBool(name, defaultValue) {
|
|
335
|
+
return new _AttributeValueDef(
|
|
336
|
+
name,
|
|
337
|
+
(value) => value === "true",
|
|
338
|
+
defaultValue
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
var AttributeDef = {
|
|
343
|
+
hyphen: AttributeValueDef.createStr("hyphen", "-"),
|
|
344
|
+
keepOnSamePage: AttributeValueDef.createBool("keep-on-same-page", false),
|
|
345
|
+
hyphenationEnabled: AttributeValueDef.createBool(
|
|
346
|
+
"hyphenation-enabled",
|
|
347
|
+
true
|
|
348
|
+
)
|
|
349
|
+
};
|
|
350
|
+
var defaultConfigAttribute = Object.fromEntries(
|
|
351
|
+
Object.entries(AttributeDef).map(([key, configValue]) => [
|
|
352
|
+
key,
|
|
353
|
+
configValue.defaultValue
|
|
354
|
+
])
|
|
355
|
+
);
|
|
356
|
+
var attributeCache = /* @__PURE__ */ new WeakMap();
|
|
357
|
+
function getNodeConfigAttribute(node) {
|
|
358
|
+
if (!node) {
|
|
359
|
+
return {};
|
|
360
|
+
}
|
|
361
|
+
if (!(node instanceof Element)) {
|
|
362
|
+
return getNodeConfigAttribute(node?.parentNode);
|
|
363
|
+
}
|
|
364
|
+
const attributes = {};
|
|
365
|
+
for (const key in AttributeDef) {
|
|
366
|
+
const valueDef = AttributeDef[key];
|
|
367
|
+
const attrName = `${attributePrefix}${valueDef.name}`;
|
|
368
|
+
const value = node.getAttribute(attrName);
|
|
369
|
+
if (value !== null) {
|
|
370
|
+
attributes[key] = valueDef.read(value);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const parentAttributes = node.parentNode ? attributeCache.get(node.parentNode) : void 0;
|
|
374
|
+
const result = { ...parentAttributes, ...attributes };
|
|
375
|
+
attributeCache.set(node, result);
|
|
376
|
+
return result;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// ../core/src/paginate/PaginationConfig.ts
|
|
380
|
+
var defaultConfig = {
|
|
381
|
+
id: "default",
|
|
382
|
+
plugins: [],
|
|
383
|
+
...defaultConfigAttribute
|
|
384
|
+
};
|
|
385
|
+
function getConfigFromAttributes(node, globalConfig) {
|
|
386
|
+
const attributes = getNodeConfigAttribute(node);
|
|
387
|
+
return { ...defaultConfig, ...globalConfig, ...attributes };
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ../core/src/logger.ts
|
|
391
|
+
var import_loglevel = __toESM(require_loglevel(), 1);
|
|
392
|
+
var logger = import_loglevel.default.getLogger(loggerName);
|
|
393
|
+
logger.setDefaultLevel("info");
|
|
394
|
+
var logger_default = logger;
|
|
395
|
+
|
|
396
|
+
// ../core/src/paginate/PaginationPlugin.ts
|
|
397
|
+
var logPrefix = "\x1B[46mPLUGIN\x1B[0m";
|
|
398
|
+
function callPluginHook(plugins, hookName, ...args) {
|
|
399
|
+
plugins.sort((a, b) => a.order - b.order).forEach((plugin) => {
|
|
400
|
+
const hook = plugin[hookName];
|
|
401
|
+
if (!hook) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
logger_default.debug(
|
|
405
|
+
logPrefix,
|
|
406
|
+
`executing plugin ${plugin.name}:${String(hookName)} (${String()})`,
|
|
407
|
+
args
|
|
408
|
+
);
|
|
409
|
+
try {
|
|
410
|
+
hook(...args);
|
|
411
|
+
logger_default.debug(
|
|
412
|
+
logPrefix,
|
|
413
|
+
`plugin ${plugin.name}:${String(hookName)} executed`,
|
|
414
|
+
args
|
|
415
|
+
);
|
|
416
|
+
} catch (error) {
|
|
417
|
+
logger_default.debug(
|
|
418
|
+
logPrefix,
|
|
419
|
+
`plugin ${plugin.name}:${String(hookName)} failed`,
|
|
420
|
+
error
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// ../core/src/paginate/PageNodes.ts
|
|
427
|
+
var PageNodeType = {
|
|
428
|
+
Element: "element",
|
|
429
|
+
Text: "text"
|
|
430
|
+
};
|
|
431
|
+
var PageElement = class _PageElement {
|
|
432
|
+
_node;
|
|
433
|
+
config;
|
|
434
|
+
type = PageNodeType.Element;
|
|
435
|
+
transaction;
|
|
436
|
+
clonedFrom;
|
|
437
|
+
cloneCount;
|
|
438
|
+
constructor(element, transaction, config, clonedFrom) {
|
|
439
|
+
this._node = element;
|
|
440
|
+
this.transaction = transaction;
|
|
441
|
+
this.config = config;
|
|
442
|
+
this.clonedFrom = clonedFrom;
|
|
443
|
+
this.cloneCount = clonedFrom ? clonedFrom.cloneCount + 1 : 0;
|
|
444
|
+
}
|
|
445
|
+
getOriginalNode() {
|
|
446
|
+
let current = this.clonedFrom;
|
|
447
|
+
while (current?.clonedFrom) {
|
|
448
|
+
current = current.clonedFrom;
|
|
449
|
+
}
|
|
450
|
+
return current?._node;
|
|
451
|
+
}
|
|
452
|
+
appendChild(node) {
|
|
453
|
+
if (this.transaction.isActive) {
|
|
454
|
+
this.transaction.addRollbackCallback(() => {
|
|
455
|
+
this._node.removeChild(node.getNode());
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
this._node.appendChild(node.getNode());
|
|
459
|
+
}
|
|
460
|
+
clone(withChildren) {
|
|
461
|
+
const clonedElement = this._node.cloneNode(withChildren);
|
|
462
|
+
const clonedPageElement = new _PageElement(
|
|
463
|
+
clonedElement,
|
|
464
|
+
this.transaction,
|
|
465
|
+
this.config,
|
|
466
|
+
this
|
|
467
|
+
);
|
|
468
|
+
callPluginHook(
|
|
469
|
+
this.config.plugins,
|
|
470
|
+
"onClone",
|
|
471
|
+
this.config.id,
|
|
472
|
+
this._node,
|
|
473
|
+
clonedPageElement
|
|
474
|
+
);
|
|
475
|
+
return clonedPageElement;
|
|
476
|
+
}
|
|
477
|
+
getHeight() {
|
|
478
|
+
return getVisibleHeight(this._node);
|
|
479
|
+
}
|
|
480
|
+
remove() {
|
|
481
|
+
this.transaction.addCommitCallback(() => {
|
|
482
|
+
this._node.remove();
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
isEmpty() {
|
|
486
|
+
return this._node.innerHTML === "";
|
|
487
|
+
}
|
|
488
|
+
getChildrenCount() {
|
|
489
|
+
return this._node.childNodes.length;
|
|
490
|
+
}
|
|
491
|
+
getNode() {
|
|
492
|
+
return this._node;
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
var PageText = class {
|
|
496
|
+
_node;
|
|
497
|
+
type = PageNodeType.Text;
|
|
498
|
+
transaction;
|
|
499
|
+
config;
|
|
500
|
+
constructor(text, transaction, config) {
|
|
501
|
+
this._node = text;
|
|
502
|
+
this.transaction = transaction;
|
|
503
|
+
this.config = config;
|
|
504
|
+
}
|
|
505
|
+
get textContent() {
|
|
506
|
+
return this._node.textContent ?? "";
|
|
507
|
+
}
|
|
508
|
+
set textContent(value) {
|
|
509
|
+
this._node.textContent = value;
|
|
510
|
+
}
|
|
511
|
+
remove() {
|
|
512
|
+
this.transaction.addCommitCallback(() => {
|
|
513
|
+
this._node.remove();
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
getNode() {
|
|
517
|
+
return this._node;
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
function createPageNode(node, transaction, config) {
|
|
521
|
+
if (isTextNode(node)) {
|
|
522
|
+
return new PageText(node, transaction, config);
|
|
523
|
+
} else if (isElement(node)) {
|
|
524
|
+
return new PageElement(node, transaction, config);
|
|
525
|
+
}
|
|
526
|
+
throw new Error("Unsupported node type");
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// ../core/src/debugUtilities/pageNodeMarker.ts
|
|
530
|
+
function markIgnoredNode(node) {
|
|
531
|
+
if (!isDebugMode()) {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
if (node && node.type == PageNodeType.Element) {
|
|
535
|
+
node.getNode().classList.add(ignoredElementClassName);
|
|
536
|
+
} else if (node && node.type == PageNodeType.Text) {
|
|
537
|
+
node.getNode().parentElement?.classList.add(ignoredTextClassName);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
function markCurrentNode(node) {
|
|
541
|
+
if (!isDebugMode()) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
if (node && node.type == PageNodeType.Element) {
|
|
545
|
+
node.getNode().classList.add(currentElementClassName);
|
|
546
|
+
} else if (node && node.type == PageNodeType.Text) {
|
|
547
|
+
node.getNode().parentElement?.classList.add(currentTextClassName);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
function unmarkCurrentNode(node) {
|
|
551
|
+
if (!isDebugMode()) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
if (node && node.type == PageNodeType.Element) {
|
|
555
|
+
node.getNode().classList.remove(currentElementClassName);
|
|
556
|
+
} else if (node && node.type == PageNodeType.Text) {
|
|
557
|
+
node.getNode().parentElement?.classList.remove(currentTextClassName);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// ../core/src/paginate/DomState.ts
|
|
562
|
+
var logPrefix2 = "\x1B[106mDOM\x1B[0m";
|
|
563
|
+
var DomState = class {
|
|
564
|
+
_transaction;
|
|
565
|
+
_treeWalker;
|
|
566
|
+
_config;
|
|
567
|
+
_completed = false;
|
|
568
|
+
_currentNode = null;
|
|
569
|
+
_previousNode = null;
|
|
570
|
+
constructor(root, transaction, config) {
|
|
571
|
+
this._transaction = transaction;
|
|
572
|
+
this._config = config;
|
|
573
|
+
this._treeWalker = document.createTreeWalker(
|
|
574
|
+
root,
|
|
575
|
+
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
get completed() {
|
|
579
|
+
return this._completed;
|
|
580
|
+
}
|
|
581
|
+
get currentNode() {
|
|
582
|
+
return this._currentNode;
|
|
583
|
+
}
|
|
584
|
+
get previousNode() {
|
|
585
|
+
return this._previousNode;
|
|
586
|
+
}
|
|
587
|
+
goToNextNode() {
|
|
588
|
+
const result = this._treeWalker.nextNode();
|
|
589
|
+
if (!result) {
|
|
590
|
+
this._completed = true;
|
|
591
|
+
}
|
|
592
|
+
logger_default.debug(logPrefix2, "moving to next node");
|
|
593
|
+
this.setState();
|
|
594
|
+
}
|
|
595
|
+
goToNextSiblingOrParentSibling() {
|
|
596
|
+
let parentsTraversed = 0;
|
|
597
|
+
if (this._treeWalker.nextSibling()) {
|
|
598
|
+
logger_default.debug(logPrefix2, "moving to next sibling node");
|
|
599
|
+
this.setState();
|
|
600
|
+
return { parentsTraversed };
|
|
601
|
+
}
|
|
602
|
+
while (this._treeWalker.parentNode()) {
|
|
603
|
+
parentsTraversed++;
|
|
604
|
+
if (this._treeWalker.nextSibling()) {
|
|
605
|
+
logger_default.debug(
|
|
606
|
+
logPrefix2,
|
|
607
|
+
"moving to parent sibling node, traversed:",
|
|
608
|
+
parentsTraversed
|
|
609
|
+
);
|
|
610
|
+
this.setState();
|
|
611
|
+
return { parentsTraversed };
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
this._completed = true;
|
|
615
|
+
return { parentsTraversed };
|
|
616
|
+
}
|
|
617
|
+
goToFirstChildOrNextNode() {
|
|
618
|
+
if (this._treeWalker.firstChild()) {
|
|
619
|
+
logger_default.debug(logPrefix2, "moving to first child node");
|
|
620
|
+
this.setState();
|
|
621
|
+
return { parentsTraversed: 1 };
|
|
622
|
+
}
|
|
623
|
+
this.goToNextNode();
|
|
624
|
+
return { parentsTraversed: 0 };
|
|
625
|
+
}
|
|
626
|
+
setState() {
|
|
627
|
+
this._previousNode = this._currentNode;
|
|
628
|
+
this._currentNode = createPageNode(
|
|
629
|
+
this._treeWalker.currentNode,
|
|
630
|
+
this._transaction,
|
|
631
|
+
getConfigFromAttributes(this._treeWalker.currentNode, this._config)
|
|
632
|
+
);
|
|
633
|
+
DEV: markCurrentNode(this._currentNode);
|
|
634
|
+
DEV: unmarkCurrentNode(this._previousNode);
|
|
635
|
+
logger_default.debug(logPrefix2, "moved to node", {
|
|
636
|
+
currentNode: this._currentNode,
|
|
637
|
+
previousNode: this._previousNode
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
// ../core/src/paginate/Transaction.ts
|
|
643
|
+
var Transaction = class {
|
|
644
|
+
_onRollback;
|
|
645
|
+
_onCommit;
|
|
646
|
+
isActive;
|
|
647
|
+
constructor() {
|
|
648
|
+
this._onRollback = [];
|
|
649
|
+
this._onCommit = [];
|
|
650
|
+
this.isActive = false;
|
|
651
|
+
}
|
|
652
|
+
start = () => {
|
|
653
|
+
if (this.isActive) {
|
|
654
|
+
throw new Error("Transaction already in progress");
|
|
655
|
+
}
|
|
656
|
+
this.isActive = true;
|
|
657
|
+
this._onRollback = [];
|
|
658
|
+
this._onCommit = [];
|
|
659
|
+
};
|
|
660
|
+
addRollbackCallback = (callback) => {
|
|
661
|
+
this._onRollback.push(callback);
|
|
662
|
+
};
|
|
663
|
+
addCommitCallback = (callback) => {
|
|
664
|
+
if (!this.isActive) {
|
|
665
|
+
callback();
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
this._onCommit.push(callback);
|
|
669
|
+
};
|
|
670
|
+
rollback = () => {
|
|
671
|
+
if (!this.isActive) return;
|
|
672
|
+
this.isActive = false;
|
|
673
|
+
this._onRollback.forEach((func) => func());
|
|
674
|
+
};
|
|
675
|
+
commit = () => {
|
|
676
|
+
if (!this.isActive) return;
|
|
677
|
+
this.isActive = false;
|
|
678
|
+
this._onCommit.forEach((func) => func());
|
|
679
|
+
};
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
// ../core/src/paginate/PageManager.ts
|
|
683
|
+
var logPrefix3 = "\x1B[102mPAGE\x1B[0m";
|
|
684
|
+
var PageState = class _PageState {
|
|
685
|
+
currentPage;
|
|
686
|
+
activeElement;
|
|
687
|
+
currentElement;
|
|
688
|
+
parentStack;
|
|
689
|
+
pageIsFull;
|
|
690
|
+
pageIndex;
|
|
691
|
+
pageHeight;
|
|
692
|
+
constructor(currentPage, activeElement, currentElement, parentStack, pageIsFull, pageIndex, pageHeight) {
|
|
693
|
+
this.currentPage = currentPage;
|
|
694
|
+
this.activeElement = activeElement;
|
|
695
|
+
this.currentElement = currentElement;
|
|
696
|
+
this.parentStack = parentStack;
|
|
697
|
+
this.pageIsFull = pageIsFull;
|
|
698
|
+
this.pageIndex = pageIndex;
|
|
699
|
+
this.pageHeight = pageHeight;
|
|
700
|
+
}
|
|
701
|
+
static create(currentPage, parentStack, pageIndex, pageHeight) {
|
|
702
|
+
return new _PageState(
|
|
703
|
+
currentPage,
|
|
704
|
+
null,
|
|
705
|
+
currentPage,
|
|
706
|
+
parentStack,
|
|
707
|
+
false,
|
|
708
|
+
pageIndex,
|
|
709
|
+
pageHeight
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
clone = () => {
|
|
713
|
+
return new _PageState(
|
|
714
|
+
this.currentPage,
|
|
715
|
+
this.activeElement,
|
|
716
|
+
this.currentElement,
|
|
717
|
+
[...this.parentStack],
|
|
718
|
+
this.pageIsFull,
|
|
719
|
+
this.pageIndex,
|
|
720
|
+
this.pageHeight
|
|
721
|
+
);
|
|
722
|
+
};
|
|
723
|
+
};
|
|
724
|
+
var PageManager = class _PageManager {
|
|
725
|
+
_pageState;
|
|
726
|
+
_transaction;
|
|
727
|
+
_tempContainer;
|
|
728
|
+
_config;
|
|
729
|
+
constructor(tempContainer, pageSize2, transaction, config) {
|
|
730
|
+
this._tempContainer = tempContainer;
|
|
731
|
+
this._config = config;
|
|
732
|
+
this._transaction = transaction;
|
|
733
|
+
const pageHtmlElement = _PageManager.createPageHtmlElement(
|
|
734
|
+
pageSize2.width
|
|
735
|
+
);
|
|
736
|
+
const page2 = this.createNewPage(pageHtmlElement);
|
|
737
|
+
this._pageState = PageState.create(page2, [], 0, pageSize2.height);
|
|
738
|
+
callPluginHook(this._config.plugins, "onNewPage", config.id, this);
|
|
739
|
+
}
|
|
740
|
+
nextPage() {
|
|
741
|
+
const page2 = this.createNewPage(
|
|
742
|
+
this._pageState.currentPage.getNode().cloneNode(false)
|
|
743
|
+
);
|
|
744
|
+
const newPageState = PageState.create(
|
|
745
|
+
page2,
|
|
746
|
+
[],
|
|
747
|
+
this._pageState.pageIndex + 1,
|
|
748
|
+
this._pageState.pageHeight
|
|
749
|
+
);
|
|
750
|
+
this.cloneParentStackToNewPage(newPageState);
|
|
751
|
+
this.cleanupEmptyParent();
|
|
752
|
+
this._pageState = newPageState;
|
|
753
|
+
callPluginHook(
|
|
754
|
+
this._config.plugins,
|
|
755
|
+
"onNewPage",
|
|
756
|
+
this._config.id,
|
|
757
|
+
this
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
cloneParentStackToNewPage(newPageState) {
|
|
761
|
+
for (const parent of this._pageState.parentStack) {
|
|
762
|
+
const clonedParent = parent.clone(false);
|
|
763
|
+
newPageState.currentElement.appendChild(clonedParent);
|
|
764
|
+
newPageState.currentElement = clonedParent;
|
|
765
|
+
newPageState.parentStack.push(clonedParent);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
cleanupEmptyParent() {
|
|
769
|
+
const parentStack = [...this._pageState.parentStack];
|
|
770
|
+
const cleanup = () => {
|
|
771
|
+
for (let i = parentStack.length - 1; i >= 0; i--) {
|
|
772
|
+
const parent = parentStack[i];
|
|
773
|
+
if (parent.isEmpty()) {
|
|
774
|
+
parent.remove();
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
this._transaction.addCommitCallback(cleanup);
|
|
779
|
+
}
|
|
780
|
+
enterElement() {
|
|
781
|
+
if (!this._pageState.activeElement || this._pageState.activeElement.type !== PageNodeType.Element) {
|
|
782
|
+
throw new Error("Invalid state: activeElement is not an Element");
|
|
783
|
+
}
|
|
784
|
+
logger_default.debug(
|
|
785
|
+
logPrefix3,
|
|
786
|
+
"entering an element",
|
|
787
|
+
this._pageState.activeElement
|
|
788
|
+
);
|
|
789
|
+
this._pageState.currentElement = this._pageState.activeElement;
|
|
790
|
+
this._pageState.parentStack.push(this._pageState.activeElement);
|
|
791
|
+
}
|
|
792
|
+
leaveElement() {
|
|
793
|
+
this._pageState.activeElement = null;
|
|
794
|
+
const popped = this._pageState.parentStack.pop();
|
|
795
|
+
logger_default.debug(logPrefix3, "leaving a parent element", popped);
|
|
796
|
+
const parent = this._pageState.parentStack.at(-1);
|
|
797
|
+
this._pageState.currentElement = parent ?? this._pageState.currentPage;
|
|
798
|
+
}
|
|
799
|
+
static createPageHtmlElement(pageWidth) {
|
|
800
|
+
const page2 = document.createElement("div");
|
|
801
|
+
page2.style.width = `${pageWidth}px`;
|
|
802
|
+
page2.style.maxWidth = `${pageWidth}px`;
|
|
803
|
+
return page2;
|
|
804
|
+
}
|
|
805
|
+
createNewPage(pageHtmlElement) {
|
|
806
|
+
this._tempContainer.appendChild(pageHtmlElement);
|
|
807
|
+
if (this._transaction.isActive) {
|
|
808
|
+
this._transaction.addRollbackCallback(() => {
|
|
809
|
+
this._tempContainer.removeChild(pageHtmlElement);
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
return createPageNode(pageHtmlElement, this._transaction, this._config);
|
|
813
|
+
}
|
|
814
|
+
startTransaction() {
|
|
815
|
+
this._transaction.start();
|
|
816
|
+
const state = this._pageState.clone();
|
|
817
|
+
this._transaction.addRollbackCallback(() => {
|
|
818
|
+
this._pageState = state;
|
|
819
|
+
});
|
|
820
|
+
return this._transaction;
|
|
821
|
+
}
|
|
822
|
+
hasEmptySpace(elementHeight) {
|
|
823
|
+
return !this._pageState.pageIsFull && this._pageState.currentPage.getHeight() + (elementHeight || 1e-4) <= this._pageState.pageHeight;
|
|
824
|
+
}
|
|
825
|
+
isOverFlow() {
|
|
826
|
+
return this._pageState.currentPage.getHeight() > this._pageState.pageHeight;
|
|
827
|
+
}
|
|
828
|
+
markPageAsFull() {
|
|
829
|
+
this._pageState.pageIsFull = true;
|
|
830
|
+
}
|
|
831
|
+
appendChild(node, withChildren) {
|
|
832
|
+
const clonedNode = node.clone(withChildren);
|
|
833
|
+
DEV: unmarkCurrentNode(clonedNode);
|
|
834
|
+
this._pageState.currentElement.appendChild(clonedNode);
|
|
835
|
+
this._pageState.activeElement = clonedNode;
|
|
836
|
+
return clonedNode;
|
|
837
|
+
}
|
|
838
|
+
addTextNode(text) {
|
|
839
|
+
if (this._pageState.activeElement?.type === PageNodeType.Text) {
|
|
840
|
+
return this._pageState.activeElement;
|
|
841
|
+
}
|
|
842
|
+
const textNode = document.createTextNode(text);
|
|
843
|
+
const newTextNode = createPageNode(
|
|
844
|
+
textNode,
|
|
845
|
+
this._transaction,
|
|
846
|
+
this._config
|
|
847
|
+
);
|
|
848
|
+
this._pageState.currentElement.appendChild(newTextNode);
|
|
849
|
+
this._pageState.activeElement = newTextNode;
|
|
850
|
+
return newTextNode;
|
|
851
|
+
}
|
|
852
|
+
getPageState() {
|
|
853
|
+
return this._pageState;
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
// ../core/src/paginate/SplitResult.ts
|
|
858
|
+
var SplitResult = {
|
|
859
|
+
None: 0,
|
|
860
|
+
// The node fits completely on the page, no further splitting required.
|
|
861
|
+
FullNodePlaced: 1,
|
|
862
|
+
// The entire node was placed on the page, continue with the next sibling or element.
|
|
863
|
+
SplitChildren: 2
|
|
864
|
+
// The node is too large for the page, and its children must be paginated individually.
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
// ../core/src/paginate/paginateElement.ts
|
|
868
|
+
function paginateElementAcrossPages(currentNode, pageManager) {
|
|
869
|
+
const result = tryPlaceElement(currentNode, pageManager);
|
|
870
|
+
if (result !== SplitResult.None) {
|
|
871
|
+
return result;
|
|
872
|
+
}
|
|
873
|
+
const { rollback, commit } = pageManager.startTransaction();
|
|
874
|
+
pageManager.nextPage();
|
|
875
|
+
const nextPageResult = tryPlaceElement(currentNode, pageManager);
|
|
876
|
+
if (nextPageResult !== SplitResult.None) {
|
|
877
|
+
commit();
|
|
878
|
+
return nextPageResult;
|
|
879
|
+
}
|
|
880
|
+
rollback();
|
|
881
|
+
logger_default.debug("Element is too big to fit on a page", currentNode);
|
|
882
|
+
return SplitResult.None;
|
|
883
|
+
}
|
|
884
|
+
function tryPlaceElement(currentNode, pageManager) {
|
|
885
|
+
if (pageManager.hasEmptySpace(currentNode.getHeight())) {
|
|
886
|
+
const clonedNode2 = pageManager.appendChild(currentNode, true);
|
|
887
|
+
if (pageManager.isOverFlow()) {
|
|
888
|
+
clonedNode2.remove();
|
|
889
|
+
} else {
|
|
890
|
+
return SplitResult.FullNodePlaced;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
if (currentNode.config.keepOnSamePage || currentNode.getChildrenCount() === 0) {
|
|
894
|
+
return SplitResult.None;
|
|
895
|
+
}
|
|
896
|
+
const clonedNode = pageManager.appendChild(currentNode, false);
|
|
897
|
+
if (pageManager.isOverFlow()) {
|
|
898
|
+
clonedNode.remove();
|
|
899
|
+
return SplitResult.None;
|
|
900
|
+
}
|
|
901
|
+
return SplitResult.SplitChildren;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// ../core/src/paginate/paginateText.ts
|
|
905
|
+
function paginateTextByWord(text, pageManager) {
|
|
906
|
+
let splitResult = SplitResult.FullNodePlaced;
|
|
907
|
+
const tokens = text.textContent.split(/(\s+)/).filter((token) => token !== "");
|
|
908
|
+
let pendingToken;
|
|
909
|
+
let tokenIndex = 0;
|
|
910
|
+
while (pendingToken || tokenIndex < tokens.length) {
|
|
911
|
+
const currentToken = pendingToken ?? tokens[tokenIndex];
|
|
912
|
+
const result = processToken(currentToken, pageManager, text.config);
|
|
913
|
+
if (!result.completed) {
|
|
914
|
+
splitResult = SplitResult.None;
|
|
915
|
+
}
|
|
916
|
+
if (result.pendingToken) {
|
|
917
|
+
pendingToken = result.pendingToken;
|
|
918
|
+
} else {
|
|
919
|
+
pendingToken = void 0;
|
|
920
|
+
tokenIndex++;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
return splitResult;
|
|
924
|
+
}
|
|
925
|
+
function processToken(token, pageManager, config) {
|
|
926
|
+
if (!pageManager.hasEmptySpace()) {
|
|
927
|
+
pageManager.nextPage();
|
|
928
|
+
}
|
|
929
|
+
const textNode = pageManager.addTextNode("");
|
|
930
|
+
const originalContent = textNode.textContent;
|
|
931
|
+
textNode.textContent += token;
|
|
932
|
+
if (!pageManager.isOverFlow()) {
|
|
933
|
+
return {
|
|
934
|
+
completed: true
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
textNode.textContent = originalContent;
|
|
938
|
+
const overflowResult = handleTokenOverflow(token, pageManager, config);
|
|
939
|
+
return {
|
|
940
|
+
pendingToken: overflowResult.leftovers,
|
|
941
|
+
completed: overflowResult.completed
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
function handleTokenOverflow(token, pageManager, config) {
|
|
945
|
+
const { rollback, commit } = pageManager.startTransaction();
|
|
946
|
+
pageManager.nextPage();
|
|
947
|
+
pageManager.addTextNode(token);
|
|
948
|
+
if (!pageManager.isOverFlow()) {
|
|
949
|
+
commit();
|
|
950
|
+
return {
|
|
951
|
+
completed: true
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
rollback();
|
|
955
|
+
if (!config.hyphenationEnabled) {
|
|
956
|
+
logger_default.warn("Hyphenation disabled, skipping oversized token:", token);
|
|
957
|
+
return {
|
|
958
|
+
completed: false
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
const leftovers = hyphenation(token, config.hyphen, pageManager);
|
|
962
|
+
return {
|
|
963
|
+
completed: true,
|
|
964
|
+
leftovers: leftovers && leftovers.length > 0 ? leftovers : void 0
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
function hyphenation(word, hyphen, pageManager) {
|
|
968
|
+
const textNode = pageManager.addTextNode("");
|
|
969
|
+
let appended = "";
|
|
970
|
+
for (let i = 0; i < word.length; i++) {
|
|
971
|
+
const char = word[i];
|
|
972
|
+
const tentative = appended + char;
|
|
973
|
+
textNode.textContent = tentative + hyphen;
|
|
974
|
+
if (!pageManager.hasEmptySpace()) {
|
|
975
|
+
textNode.textContent = appended ? appended + hyphen : "";
|
|
976
|
+
pageManager.markPageAsFull();
|
|
977
|
+
return word.slice(i);
|
|
978
|
+
}
|
|
979
|
+
appended = tentative;
|
|
980
|
+
}
|
|
981
|
+
return null;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// ../core/src/paginate/Paginator.ts
|
|
985
|
+
var import_loglevel2 = __toESM(require_loglevel(), 1);
|
|
986
|
+
var logPrefix4 = "\x1B[103mPAGINATOR\x1B[0m";
|
|
987
|
+
var Paginator = class _Paginator {
|
|
988
|
+
_domState;
|
|
989
|
+
_pageManager;
|
|
990
|
+
_transaction;
|
|
991
|
+
_tempContainer;
|
|
992
|
+
_config;
|
|
993
|
+
constructor(root, pageSize2, config) {
|
|
994
|
+
this._config = { ...defaultConfig, ...config };
|
|
995
|
+
this._tempContainer = _Paginator.createTempContainer(this._config.id);
|
|
996
|
+
this._transaction = new Transaction();
|
|
997
|
+
this._domState = new DomState(root, this._transaction, this._config);
|
|
998
|
+
this._pageManager = new PageManager(
|
|
999
|
+
this._tempContainer,
|
|
1000
|
+
pageSize2,
|
|
1001
|
+
this._transaction,
|
|
1002
|
+
this._config
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
static createTempContainer(id) {
|
|
1006
|
+
const tempContainer = document.createElement("div");
|
|
1007
|
+
tempContainer.style.display = "flex";
|
|
1008
|
+
tempContainer.style.flexDirection = "column";
|
|
1009
|
+
tempContainer.style.gap = "20px";
|
|
1010
|
+
tempContainer.setAttribute(`${attributePrefix}-section-id`, id);
|
|
1011
|
+
tempContainer.classList.add(tempContainerClassName);
|
|
1012
|
+
DEV: if (!isDebugMode()) {
|
|
1013
|
+
moveOffscreen(tempContainer);
|
|
1014
|
+
}
|
|
1015
|
+
document.body.appendChild(tempContainer);
|
|
1016
|
+
return tempContainer;
|
|
1017
|
+
}
|
|
1018
|
+
static paginate(root, pageSize2, config) {
|
|
1019
|
+
const paginator = new _Paginator(root, pageSize2, config);
|
|
1020
|
+
paginator.processAllNodes();
|
|
1021
|
+
const result = Array.from(paginator._tempContainer.childNodes).filter((x) => isElement(x)).map((x) => x.innerHTML);
|
|
1022
|
+
DEV: if (!isDebugMode()) {
|
|
1023
|
+
paginator._tempContainer.remove();
|
|
1024
|
+
}
|
|
1025
|
+
return result;
|
|
1026
|
+
}
|
|
1027
|
+
processAllNodes() {
|
|
1028
|
+
this._domState.goToNextNode();
|
|
1029
|
+
do {
|
|
1030
|
+
import_loglevel2.default.debug(
|
|
1031
|
+
logPrefix4,
|
|
1032
|
+
"paginating node",
|
|
1033
|
+
this._domState.currentNode
|
|
1034
|
+
);
|
|
1035
|
+
const result = this.processCurrentNode();
|
|
1036
|
+
callPluginHook(
|
|
1037
|
+
this._config.plugins,
|
|
1038
|
+
"afterVisitNode",
|
|
1039
|
+
this._config.id,
|
|
1040
|
+
result,
|
|
1041
|
+
this._domState,
|
|
1042
|
+
this._pageManager
|
|
1043
|
+
);
|
|
1044
|
+
switch (result) {
|
|
1045
|
+
case SplitResult.None:
|
|
1046
|
+
this.handleNodeSkipped();
|
|
1047
|
+
break;
|
|
1048
|
+
case SplitResult.FullNodePlaced:
|
|
1049
|
+
this.handleFullNodePlaced();
|
|
1050
|
+
break;
|
|
1051
|
+
case SplitResult.SplitChildren:
|
|
1052
|
+
this.handleChildrenSplit();
|
|
1053
|
+
break;
|
|
1054
|
+
}
|
|
1055
|
+
} while (this._domState.completed === false);
|
|
1056
|
+
import_loglevel2.default.debug(logPrefix4, "pagination completed");
|
|
1057
|
+
}
|
|
1058
|
+
handleNodeSkipped() {
|
|
1059
|
+
import_loglevel2.default.debug(logPrefix4, "node skipped - couldn't paginate");
|
|
1060
|
+
DEV: markIgnoredNode(this._domState.currentNode);
|
|
1061
|
+
this._domState.goToNextNode();
|
|
1062
|
+
}
|
|
1063
|
+
handleFullNodePlaced() {
|
|
1064
|
+
import_loglevel2.default.debug(logPrefix4, "node fully paginated");
|
|
1065
|
+
const { parentsTraversed } = this._domState.goToNextSiblingOrParentSibling();
|
|
1066
|
+
for (let i = 0; i < parentsTraversed; i++) {
|
|
1067
|
+
this._pageManager.leaveElement();
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
handleChildrenSplit() {
|
|
1071
|
+
import_loglevel2.default.debug(
|
|
1072
|
+
logPrefix4,
|
|
1073
|
+
"node partially paginated - splitting children"
|
|
1074
|
+
);
|
|
1075
|
+
if (this._domState.goToFirstChildOrNextNode().parentsTraversed === 1 && this._domState.previousNode?.type === PageNodeType.Element) {
|
|
1076
|
+
this._pageManager.enterElement();
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
processCurrentNode() {
|
|
1080
|
+
if (!this._domState.currentNode) {
|
|
1081
|
+
return SplitResult.None;
|
|
1082
|
+
}
|
|
1083
|
+
if (this._domState.currentNode.type === PageNodeType.Element) {
|
|
1084
|
+
const ctx = {};
|
|
1085
|
+
callPluginHook(
|
|
1086
|
+
this._config.plugins,
|
|
1087
|
+
"onVisitElement",
|
|
1088
|
+
this._config.id,
|
|
1089
|
+
this._domState,
|
|
1090
|
+
this._pageManager,
|
|
1091
|
+
ctx
|
|
1092
|
+
);
|
|
1093
|
+
if (ctx.result !== void 0) {
|
|
1094
|
+
return ctx.result;
|
|
1095
|
+
}
|
|
1096
|
+
return paginateElementAcrossPages(
|
|
1097
|
+
this._domState.currentNode,
|
|
1098
|
+
this._pageManager
|
|
1099
|
+
);
|
|
1100
|
+
} else {
|
|
1101
|
+
const ctx = {};
|
|
1102
|
+
callPluginHook(
|
|
1103
|
+
this._config.plugins,
|
|
1104
|
+
"onVisitText",
|
|
1105
|
+
this._config.id,
|
|
1106
|
+
this._domState,
|
|
1107
|
+
this._pageManager,
|
|
1108
|
+
ctx
|
|
1109
|
+
);
|
|
1110
|
+
if (ctx.result !== void 0) {
|
|
1111
|
+
return ctx.result;
|
|
1112
|
+
}
|
|
1113
|
+
return paginateTextByWord(
|
|
1114
|
+
this._domState.currentNode,
|
|
1115
|
+
this._pageManager
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
1120
|
+
|
|
1121
|
+
// ../core/src/report/EventDispatcher.ts
|
|
1122
|
+
var EventDispatcher = class {
|
|
1123
|
+
registry = /* @__PURE__ */ new Map();
|
|
1124
|
+
addEventListener(name, handler) {
|
|
1125
|
+
const { registry } = this;
|
|
1126
|
+
const listeners = new Set(registry.get(name));
|
|
1127
|
+
listeners.add(handler);
|
|
1128
|
+
registry.set(name, listeners);
|
|
1129
|
+
return () => this.removeEventListener(name, handler);
|
|
1130
|
+
}
|
|
1131
|
+
removeEventListener(name, handler) {
|
|
1132
|
+
const { registry } = this;
|
|
1133
|
+
const listeners = new Set(registry.get(name));
|
|
1134
|
+
listeners.delete(handler);
|
|
1135
|
+
registry.set(name, listeners);
|
|
1136
|
+
}
|
|
1137
|
+
dispatch(name, ...args) {
|
|
1138
|
+
const { registry } = this;
|
|
1139
|
+
const listeners = registry.get(name);
|
|
1140
|
+
if (!listeners) {
|
|
1141
|
+
return;
|
|
1142
|
+
}
|
|
1143
|
+
for (const listener of listeners) {
|
|
1144
|
+
listener(...args);
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
|
|
1149
|
+
// ../core/src/report/pageConst.ts
|
|
1150
|
+
var _pageSize = {
|
|
1151
|
+
A1: { height: "841mm", width: "594mm" },
|
|
1152
|
+
A2: { height: "594mm", width: "420mm" },
|
|
1153
|
+
A3: { height: "420mm", width: "297mm" },
|
|
1154
|
+
A4: { height: "297mm", width: "210mm" },
|
|
1155
|
+
A5: { height: "210mm", width: "148mm" },
|
|
1156
|
+
A6: { height: "148mm", width: "105mm" },
|
|
1157
|
+
B3: { height: "500mm", width: "353mm" },
|
|
1158
|
+
B4: { height: "353mm", width: "250mm" },
|
|
1159
|
+
B5: { height: "250mm", width: "176mm" },
|
|
1160
|
+
Letter: { height: "8.5in", width: "11in" },
|
|
1161
|
+
Legal: { height: "11in", width: "8.5in" },
|
|
1162
|
+
Tabloid: { height: "11in", width: "17in" }
|
|
1163
|
+
};
|
|
1164
|
+
var _pageMargin = {
|
|
1165
|
+
Normal: { top: "1in", right: "1in", bottom: "1in", left: "1in" },
|
|
1166
|
+
Narrow: { top: "0.4in", right: "0.6in", bottom: "0.6in", left: "0.6in" },
|
|
1167
|
+
Wide: { top: "0.5in", right: "2in", bottom: "0.5in", left: "2in" },
|
|
1168
|
+
None: { top: "0in", right: "0in", bottom: "0in", left: "0in" }
|
|
1169
|
+
};
|
|
1170
|
+
var pageSize = _pageSize;
|
|
1171
|
+
var pageMargin = _pageMargin;
|
|
1172
|
+
|
|
1173
|
+
// ../core/src/report/utils.ts
|
|
1174
|
+
function getVisibleSize(element) {
|
|
1175
|
+
const rect = element.getBoundingClientRect();
|
|
1176
|
+
const computedStyle = getComputedStyle(element);
|
|
1177
|
+
const marginLeft = parseFloat(computedStyle.marginLeft) || 0;
|
|
1178
|
+
const marginRight = parseFloat(computedStyle.marginRight) || 0;
|
|
1179
|
+
return {
|
|
1180
|
+
height: getVisibleHeight(element),
|
|
1181
|
+
width: rect.width + marginLeft + marginRight
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
function calculatePageDimensions(current, sectionHeader, sectionFooter) {
|
|
1185
|
+
const { height, width } = getVisibleSize(current);
|
|
1186
|
+
const sectionHeaderHeight = sectionHeader ? getVisibleHeight(sectionHeader) : 0;
|
|
1187
|
+
const sectionFooterHeight = sectionFooter ? getVisibleHeight(sectionFooter) : 0;
|
|
1188
|
+
return { height, width, sectionHeaderHeight, sectionFooterHeight };
|
|
1189
|
+
}
|
|
1190
|
+
function createSectionPageHeightPlugin(height, sectionHeaderHeight, sectionFooterHeight) {
|
|
1191
|
+
return {
|
|
1192
|
+
name: "sectionPageHeight",
|
|
1193
|
+
order: 1,
|
|
1194
|
+
afterVisitNode: (_id, _result, domState, pageManager) => {
|
|
1195
|
+
const lastPage = domState.completed;
|
|
1196
|
+
if (!lastPage || sectionFooterHeight <= 0) return;
|
|
1197
|
+
if (!pageManager.hasEmptySpace(sectionFooterHeight)) {
|
|
1198
|
+
pageManager.nextPage();
|
|
1199
|
+
}
|
|
1200
|
+
},
|
|
1201
|
+
onNewPage: (_, pageManager) => {
|
|
1202
|
+
const pageState = pageManager.getPageState();
|
|
1203
|
+
if (pageState.pageIndex === 0) {
|
|
1204
|
+
pageState.pageHeight = height + sectionFooterHeight;
|
|
1205
|
+
} else {
|
|
1206
|
+
pageState.pageHeight = height + sectionHeaderHeight + sectionFooterHeight;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
function shorthand(margin) {
|
|
1212
|
+
return margin ? `${margin.top} ${margin.right} ${margin.bottom} ${margin.left}` : "0";
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
// ../core/src/report/reportStyles.ts
|
|
1216
|
+
var globalStyle = `
|
|
1217
|
+
html {
|
|
1218
|
+
box-sizing: border-box;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
*,
|
|
1222
|
+
*:before,
|
|
1223
|
+
*:after {
|
|
1224
|
+
box-sizing: inherit;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
:root {
|
|
1228
|
+
--paprize-page-background-color: #ffffff;
|
|
1229
|
+
--paprize-page-margin-bottom: 10px;
|
|
1230
|
+
--paprize-page-box-shadow: rgb(142 138 138) -1px 3px 5px 2px;
|
|
1231
|
+
--paprize-section-margin-bottom: 10px;
|
|
1232
|
+
--paprize-preview-background-color: rgb(218 220 224);
|
|
1233
|
+
--paprize-preview-padding: 30px 10px;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
body {
|
|
1237
|
+
margin: 0;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
@media screen {
|
|
1241
|
+
.${previewClassName} {
|
|
1242
|
+
min-height: 100vh;
|
|
1243
|
+
display: flex;
|
|
1244
|
+
flex-direction: column;
|
|
1245
|
+
align-items: center;
|
|
1246
|
+
background-color: var(--paprize-preview-background-color);
|
|
1247
|
+
padding: var(--paprize-preview-padding);
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
.${pageClassName} {
|
|
1251
|
+
box-shadow: var(--paprize-page-box-shadow);
|
|
1252
|
+
margin-bottom: var(--paprize-page-margin-bottom);
|
|
1253
|
+
background-color: var(--paprize-page-background-color);
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
.${sectionClassName} {
|
|
1257
|
+
margin-bottom: var(--paprize-section-margin-bottom);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
@media print {
|
|
1262
|
+
html:has(.${previewClassName}) *:not(.${previewClassName}):not(.${previewClassName} *):not(:has(.${previewClassName})) {
|
|
1263
|
+
display: none !important;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
`;
|
|
1267
|
+
var component = {
|
|
1268
|
+
display: "flex",
|
|
1269
|
+
flexDirection: "column"
|
|
1270
|
+
};
|
|
1271
|
+
var outOfScreen = {
|
|
1272
|
+
position: "absolute",
|
|
1273
|
+
left: "-9999px",
|
|
1274
|
+
top: "-9999px",
|
|
1275
|
+
visibility: "hidden"
|
|
1276
|
+
};
|
|
1277
|
+
var page = (pageDimension, pageMargin2) => ({
|
|
1278
|
+
display: "flex",
|
|
1279
|
+
flexDirection: "column",
|
|
1280
|
+
width: pageDimension.width,
|
|
1281
|
+
height: pageDimension.height,
|
|
1282
|
+
maxHeight: pageDimension.height,
|
|
1283
|
+
position: "relative",
|
|
1284
|
+
padding: shorthand(pageMargin2),
|
|
1285
|
+
zIndex: "1"
|
|
1286
|
+
});
|
|
1287
|
+
var pageContent = {
|
|
1288
|
+
overflow: "hidden",
|
|
1289
|
+
width: "100%",
|
|
1290
|
+
height: "100%"
|
|
1291
|
+
};
|
|
1292
|
+
var overlay = {
|
|
1293
|
+
position: "absolute",
|
|
1294
|
+
width: "100%",
|
|
1295
|
+
height: "100%",
|
|
1296
|
+
left: 0,
|
|
1297
|
+
top: 0
|
|
1298
|
+
};
|
|
1299
|
+
var section = (sectionId2) => ({
|
|
1300
|
+
page: `section-${sectionId2}`
|
|
1301
|
+
});
|
|
1302
|
+
function sectionPageMedia(sectionId2, dimension) {
|
|
1303
|
+
return `@page section-${sectionId2} {
|
|
1304
|
+
margin: none;
|
|
1305
|
+
size:${dimension.width} ${dimension.height};
|
|
1306
|
+
width:${dimension.width};
|
|
1307
|
+
height:${dimension.height};
|
|
1308
|
+
}`;
|
|
1309
|
+
}
|
|
1310
|
+
var reportStyles = {
|
|
1311
|
+
globalStyle,
|
|
1312
|
+
component,
|
|
1313
|
+
outOfScreen,
|
|
1314
|
+
page,
|
|
1315
|
+
overlay,
|
|
1316
|
+
pageContent,
|
|
1317
|
+
sectionPageMedia,
|
|
1318
|
+
section
|
|
1319
|
+
};
|
|
1320
|
+
|
|
1321
|
+
// ../core/src/report/sectionComponents.ts
|
|
1322
|
+
function cloneElement(element) {
|
|
1323
|
+
return element?.cloneNode(true) ?? null;
|
|
1324
|
+
}
|
|
1325
|
+
function cloneComponents(components) {
|
|
1326
|
+
return {
|
|
1327
|
+
sectionHeader: cloneElement(components.sectionHeader),
|
|
1328
|
+
sectionFooter: cloneElement(components.sectionFooter),
|
|
1329
|
+
pageHeader: cloneElement(components.pageHeader),
|
|
1330
|
+
pageFooter: cloneElement(components.pageFooter),
|
|
1331
|
+
pageContent: cloneElement(components.pageContent)
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
// ../core/src/plugins/PageBreakPlugin.ts
|
|
1336
|
+
var pageBreakAttributeName = "data-pz-page-break";
|
|
1337
|
+
var PageBreakPlugin = class {
|
|
1338
|
+
name = "pageBreak";
|
|
1339
|
+
order = 1;
|
|
1340
|
+
onVisitElement = (_id, domState, pageManager, context) => {
|
|
1341
|
+
if (domState.currentNode.getNode().getAttribute(pageBreakAttributeName) === "true") {
|
|
1342
|
+
pageManager.markPageAsFull();
|
|
1343
|
+
context.result = SplitResult.FullNodePlaced;
|
|
1344
|
+
}
|
|
1345
|
+
};
|
|
1346
|
+
};
|
|
1347
|
+
|
|
1348
|
+
// ../core/src/plugins/TablePlugin.ts
|
|
1349
|
+
var TablePlugin = class {
|
|
1350
|
+
_options = {};
|
|
1351
|
+
name = "table";
|
|
1352
|
+
order = 1;
|
|
1353
|
+
constructor(options = {}) {
|
|
1354
|
+
this._options = options;
|
|
1355
|
+
}
|
|
1356
|
+
onNewPage = (_id, pageManager) => {
|
|
1357
|
+
if (this._options.includeHeaderOnlyTables) {
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
const pageState = pageManager.getPageState();
|
|
1361
|
+
const tableElement = pageState.parentStack.find(
|
|
1362
|
+
(node) => this._isTable(node.getNode())
|
|
1363
|
+
);
|
|
1364
|
+
if (!tableElement || !tableElement.clonedFrom) {
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
const openTable = tableElement.clonedFrom;
|
|
1368
|
+
const openTableNode = openTable.getNode();
|
|
1369
|
+
const header = openTableNode.tHead;
|
|
1370
|
+
const hasHeader = header !== null;
|
|
1371
|
+
if (!hasHeader) {
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
const body = openTableNode.tBodies;
|
|
1375
|
+
if (!this._isTableBodyEmpty(body)) {
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1378
|
+
openTable.remove();
|
|
1379
|
+
const newTable = tableElement.getNode();
|
|
1380
|
+
if (newTable.tHead === null) {
|
|
1381
|
+
const headerNode = createPageNode(
|
|
1382
|
+
header.cloneNode(true),
|
|
1383
|
+
tableElement.transaction,
|
|
1384
|
+
tableElement.config
|
|
1385
|
+
);
|
|
1386
|
+
tableElement.appendChild(headerNode);
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
onClone = (_id, source, cloned) => {
|
|
1390
|
+
if (source.tagName === "TR") {
|
|
1391
|
+
cloned.config.keepOnSamePage = true;
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
if (!this._isTable(source) || !cloned.clonedFrom || cloned.cloneCount === 1) {
|
|
1395
|
+
return;
|
|
1396
|
+
}
|
|
1397
|
+
const originalNode = cloned.getOriginalNode();
|
|
1398
|
+
const head = originalNode.tHead;
|
|
1399
|
+
if (head && this._options.cloneHeader === true) {
|
|
1400
|
+
const clonedHead = new PageElement(
|
|
1401
|
+
head.cloneNode(true),
|
|
1402
|
+
cloned.transaction,
|
|
1403
|
+
cloned.config
|
|
1404
|
+
);
|
|
1405
|
+
cloned.appendChild(clonedHead);
|
|
1406
|
+
}
|
|
1407
|
+
const foot = originalNode.tFoot;
|
|
1408
|
+
if (foot && this._options.cloneFooter === true) {
|
|
1409
|
+
const clonedFoot = new PageElement(
|
|
1410
|
+
foot.cloneNode(true),
|
|
1411
|
+
cloned.transaction,
|
|
1412
|
+
cloned.config
|
|
1413
|
+
);
|
|
1414
|
+
cloned.appendChild(clonedFoot);
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
_isTable(element) {
|
|
1418
|
+
return element.tagName === "TABLE";
|
|
1419
|
+
}
|
|
1420
|
+
_isTableBodyEmpty(body) {
|
|
1421
|
+
if (body.length === 0) return true;
|
|
1422
|
+
const tbody = body[0];
|
|
1423
|
+
if (tbody.rows.length !== 1) return false;
|
|
1424
|
+
const row = tbody.rows[0];
|
|
1425
|
+
if (row.cells.length !== 1) return false;
|
|
1426
|
+
const cell = row.cells[0];
|
|
1427
|
+
return cell.textContent.trim() === "";
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
// ../core/src/plugins/defaultPlugins.ts
|
|
1432
|
+
var defaultPlugins = [
|
|
1433
|
+
new PageBreakPlugin(),
|
|
1434
|
+
new TablePlugin()
|
|
1435
|
+
];
|
|
1436
|
+
|
|
1437
|
+
// ../core/src/plugins/debugPlugin.ts
|
|
1438
|
+
var debugPlugin = {
|
|
1439
|
+
name: "debug",
|
|
1440
|
+
order: Number.MAX_SAFE_INTEGER,
|
|
1441
|
+
onNewPage: (_, pageManager) => {
|
|
1442
|
+
const page2 = pageManager.getPageState().currentPage.getNode();
|
|
1443
|
+
if (!page2.classList.contains(pageClassName)) {
|
|
1444
|
+
page2.classList.add(pageClassName);
|
|
1445
|
+
}
|
|
1446
|
+
page2.setAttribute(`${attributePrefix}-element`, "page");
|
|
1447
|
+
page2.setAttribute(
|
|
1448
|
+
`${attributePrefix}-height`,
|
|
1449
|
+
pageManager.getPageState().pageHeight.toString()
|
|
1450
|
+
);
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
|
|
1454
|
+
// ../core/src/window.ts
|
|
1455
|
+
var paprize_isInitialized = "__PAPRIZE_IS_INITIALIZED";
|
|
1456
|
+
var paprize_isReady = "__PAPRIZE_IS_READY";
|
|
1457
|
+
|
|
1458
|
+
// ../core/src/report/PromiseTracker.ts
|
|
1459
|
+
var PromiseTracker = class _PromiseTracker {
|
|
1460
|
+
_promises;
|
|
1461
|
+
monitor;
|
|
1462
|
+
get promise() {
|
|
1463
|
+
return this._promises.length > 0 ? Promise.allSettled(this._promises.map((p) => p.promise)).then(
|
|
1464
|
+
() => {
|
|
1465
|
+
}
|
|
1466
|
+
) : Promise.resolve();
|
|
1467
|
+
}
|
|
1468
|
+
constructor() {
|
|
1469
|
+
this._promises = [];
|
|
1470
|
+
this.monitor = new EventDispatcher();
|
|
1471
|
+
}
|
|
1472
|
+
async add(promises = []) {
|
|
1473
|
+
this._promises.push(...promises.map(_PromiseTracker.toTracked));
|
|
1474
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1475
|
+
if (this.getPending().length === 0) {
|
|
1476
|
+
this.monitor.dispatch("onChange", 0);
|
|
1477
|
+
return;
|
|
1478
|
+
}
|
|
1479
|
+
this._promises.forEach((p) => this.injectEvents(p));
|
|
1480
|
+
}
|
|
1481
|
+
static toTracked(promise) {
|
|
1482
|
+
const tracked = {
|
|
1483
|
+
promise,
|
|
1484
|
+
status: "pending"
|
|
1485
|
+
};
|
|
1486
|
+
tracked.promise.finally(() => {
|
|
1487
|
+
tracked.status = "resolved";
|
|
1488
|
+
});
|
|
1489
|
+
return tracked;
|
|
1490
|
+
}
|
|
1491
|
+
async injectEvents(tracked) {
|
|
1492
|
+
tracked.promise.finally(() => {
|
|
1493
|
+
const pending = this.getPending();
|
|
1494
|
+
this.monitor.dispatch("onChange", pending.length);
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
getPending() {
|
|
1498
|
+
return Array.from(this._promises.values()).filter(
|
|
1499
|
+
(p) => p.status === "pending"
|
|
1500
|
+
);
|
|
1501
|
+
}
|
|
1502
|
+
};
|
|
1503
|
+
|
|
1504
|
+
// ../core/src/report/ReportBuilder.ts
|
|
1505
|
+
var logPrefix5 = "\x1B[43mREPORT\x1B[0m";
|
|
1506
|
+
var ReportBuilder = class {
|
|
1507
|
+
_sections;
|
|
1508
|
+
_monitor;
|
|
1509
|
+
_paginationInProgress;
|
|
1510
|
+
_pendingPaginateResolvers;
|
|
1511
|
+
_currentAbortController;
|
|
1512
|
+
constructor() {
|
|
1513
|
+
this._sections = /* @__PURE__ */ new Map();
|
|
1514
|
+
this._monitor = new EventDispatcher();
|
|
1515
|
+
this._paginationInProgress = false;
|
|
1516
|
+
this._pendingPaginateResolvers = [];
|
|
1517
|
+
this._currentAbortController = null;
|
|
1518
|
+
window[paprize_isInitialized] = true;
|
|
1519
|
+
this._injectStyle(reportStyles.globalStyle);
|
|
1520
|
+
}
|
|
1521
|
+
get monitor() {
|
|
1522
|
+
return this._monitor;
|
|
1523
|
+
}
|
|
1524
|
+
removeSection(sectionId2) {
|
|
1525
|
+
this._sections.delete(sectionId2);
|
|
1526
|
+
}
|
|
1527
|
+
tryAddSection(options, components, onPaginationCompleted) {
|
|
1528
|
+
if (this._sections.has(options.id)) {
|
|
1529
|
+
return false;
|
|
1530
|
+
}
|
|
1531
|
+
const context = {
|
|
1532
|
+
index: this._sections.size,
|
|
1533
|
+
sectionId: options.id,
|
|
1534
|
+
isPaginated: false,
|
|
1535
|
+
isSuspended: !!options.suspense?.length,
|
|
1536
|
+
pages: []
|
|
1537
|
+
};
|
|
1538
|
+
this._sections.set(options.id, {
|
|
1539
|
+
context,
|
|
1540
|
+
options,
|
|
1541
|
+
components,
|
|
1542
|
+
onPaginationCompleted
|
|
1543
|
+
});
|
|
1544
|
+
this._injectStyle(
|
|
1545
|
+
reportStyles.sectionPageMedia(options.id, options.dimension)
|
|
1546
|
+
);
|
|
1547
|
+
this._monitor.dispatch("sectionCreated", context);
|
|
1548
|
+
return true;
|
|
1549
|
+
}
|
|
1550
|
+
async schedulePaginate() {
|
|
1551
|
+
if (this._sections.size === 0) {
|
|
1552
|
+
window[paprize_isReady] = true;
|
|
1553
|
+
return {
|
|
1554
|
+
sections: [],
|
|
1555
|
+
suspension: Promise.resolve()
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
if (this._paginationInProgress && this._currentAbortController) {
|
|
1559
|
+
logger_default.debug(
|
|
1560
|
+
logPrefix5,
|
|
1561
|
+
`Cancelling previous pagination operation.`
|
|
1562
|
+
);
|
|
1563
|
+
this._currentAbortController.abort(
|
|
1564
|
+
"Cancelled by new paginate call"
|
|
1565
|
+
);
|
|
1566
|
+
}
|
|
1567
|
+
if (this._paginationInProgress) {
|
|
1568
|
+
return new Promise((resolve, reject) => {
|
|
1569
|
+
this._pendingPaginateResolvers.push({ resolve, reject });
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
return this._executePagination();
|
|
1573
|
+
}
|
|
1574
|
+
async _executePagination() {
|
|
1575
|
+
this._paginationInProgress = true;
|
|
1576
|
+
this._currentAbortController = new AbortController();
|
|
1577
|
+
const abortSignal = this._currentAbortController.signal;
|
|
1578
|
+
try {
|
|
1579
|
+
logger_default.debug(logPrefix5, `Schedule paginate.`);
|
|
1580
|
+
await document.fonts.ready;
|
|
1581
|
+
if (abortSignal.aborted) {
|
|
1582
|
+
return new Promise((resolve, reject) => {
|
|
1583
|
+
this._pendingPaginateResolvers.push({ resolve, reject });
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
const trackers = [];
|
|
1587
|
+
for (const state of this._sections.values()) {
|
|
1588
|
+
state.context.isPaginated = false;
|
|
1589
|
+
const tracker = new PromiseTracker();
|
|
1590
|
+
await tracker.add(state.options.suspense);
|
|
1591
|
+
tracker.monitor.addEventListener("onChange", (pendingCount) => {
|
|
1592
|
+
logger_default.debug(
|
|
1593
|
+
logPrefix5,
|
|
1594
|
+
`${pendingCount} pending promises in section '${state.options.id}'.`
|
|
1595
|
+
);
|
|
1596
|
+
});
|
|
1597
|
+
tracker.promise.then(async () => {
|
|
1598
|
+
if (abortSignal.aborted) {
|
|
1599
|
+
return;
|
|
1600
|
+
}
|
|
1601
|
+
logger_default.debug(
|
|
1602
|
+
logPrefix5,
|
|
1603
|
+
`Start paginating section '${state.options.id}'.`
|
|
1604
|
+
);
|
|
1605
|
+
state.context.isSuspended = false;
|
|
1606
|
+
this._paginateSection(state);
|
|
1607
|
+
});
|
|
1608
|
+
trackers.push(tracker);
|
|
1609
|
+
}
|
|
1610
|
+
const reportTracker = new PromiseTracker();
|
|
1611
|
+
reportTracker.monitor.addEventListener("onChange", () => {
|
|
1612
|
+
logger_default.debug(logPrefix5, "Report pagination completed.");
|
|
1613
|
+
this._monitor.dispatch("paginationCycleCompleted", {
|
|
1614
|
+
sections: [...this._sections.values()].map(
|
|
1615
|
+
(s) => s.context
|
|
1616
|
+
)
|
|
1617
|
+
});
|
|
1618
|
+
});
|
|
1619
|
+
if (abortSignal.aborted) {
|
|
1620
|
+
return new Promise((resolve, reject) => {
|
|
1621
|
+
this._pendingPaginateResolvers.push({ resolve, reject });
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
await reportTracker.add(trackers.map((t) => t.promise));
|
|
1625
|
+
return {
|
|
1626
|
+
sections: [...this._sections.values()].map((s) => s.context),
|
|
1627
|
+
suspension: reportTracker.promise.then(() => {
|
|
1628
|
+
window[paprize_isReady] = true;
|
|
1629
|
+
})
|
|
1630
|
+
};
|
|
1631
|
+
} finally {
|
|
1632
|
+
this._processPendingPagination();
|
|
1633
|
+
this._paginationInProgress = false;
|
|
1634
|
+
this._currentAbortController = null;
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
async _processPendingPagination() {
|
|
1638
|
+
if (this._pendingPaginateResolvers.length === 0) {
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
logger_default.debug(
|
|
1642
|
+
logPrefix5,
|
|
1643
|
+
`Processing ${this._pendingPaginateResolvers.length} pending paginate calls.`
|
|
1644
|
+
);
|
|
1645
|
+
const pendingResolvers = [...this._pendingPaginateResolvers];
|
|
1646
|
+
this._pendingPaginateResolvers = [];
|
|
1647
|
+
const nextResult = await this._executePagination();
|
|
1648
|
+
for (const resolver of pendingResolvers) {
|
|
1649
|
+
resolver.resolve(nextResult);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
_injectStyle(styleContent) {
|
|
1653
|
+
let style = document.getElementById(
|
|
1654
|
+
globalStyleId
|
|
1655
|
+
);
|
|
1656
|
+
if (!style) {
|
|
1657
|
+
style = document.createElement("style");
|
|
1658
|
+
style.id = globalStyleId;
|
|
1659
|
+
style.textContent = "";
|
|
1660
|
+
document.head.appendChild(style);
|
|
1661
|
+
}
|
|
1662
|
+
style.textContent = (style.textContent + styleContent).replace(/\s+/g, " ").replace(/\s*([:;{}])\s*/g, "$1").trim();
|
|
1663
|
+
}
|
|
1664
|
+
async _paginateSection(state) {
|
|
1665
|
+
const temporarilyContainer = document.createElement("div");
|
|
1666
|
+
Object.assign(
|
|
1667
|
+
temporarilyContainer.style,
|
|
1668
|
+
reportStyles.page(
|
|
1669
|
+
state.options.dimension,
|
|
1670
|
+
state.options.margin ?? pageMargin.None
|
|
1671
|
+
)
|
|
1672
|
+
);
|
|
1673
|
+
if (!isDebugMode()) {
|
|
1674
|
+
Object.assign(temporarilyContainer.style, reportStyles.outOfScreen);
|
|
1675
|
+
}
|
|
1676
|
+
const components = cloneComponents(state.components);
|
|
1677
|
+
if (components.sectionHeader) {
|
|
1678
|
+
Object.assign(
|
|
1679
|
+
components.sectionHeader.style,
|
|
1680
|
+
reportStyles.component
|
|
1681
|
+
);
|
|
1682
|
+
temporarilyContainer.appendChild(components.sectionHeader);
|
|
1683
|
+
}
|
|
1684
|
+
if (components.pageHeader) {
|
|
1685
|
+
Object.assign(components.pageHeader.style, reportStyles.component);
|
|
1686
|
+
temporarilyContainer.appendChild(components.pageHeader);
|
|
1687
|
+
}
|
|
1688
|
+
Object.assign(components.pageContent.style, reportStyles.pageContent);
|
|
1689
|
+
temporarilyContainer.appendChild(components.pageContent);
|
|
1690
|
+
if (components.pageFooter) {
|
|
1691
|
+
Object.assign(components.pageFooter.style, reportStyles.component);
|
|
1692
|
+
temporarilyContainer.appendChild(components.pageFooter);
|
|
1693
|
+
}
|
|
1694
|
+
if (components.sectionFooter) {
|
|
1695
|
+
Object.assign(
|
|
1696
|
+
components.sectionFooter.style,
|
|
1697
|
+
reportStyles.component
|
|
1698
|
+
);
|
|
1699
|
+
temporarilyContainer.appendChild(components.sectionFooter);
|
|
1700
|
+
}
|
|
1701
|
+
document.body.appendChild(temporarilyContainer);
|
|
1702
|
+
const { height, width, sectionHeaderHeight, sectionFooterHeight } = calculatePageDimensions(
|
|
1703
|
+
components.pageContent,
|
|
1704
|
+
components.sectionHeader,
|
|
1705
|
+
components.sectionFooter
|
|
1706
|
+
);
|
|
1707
|
+
const paginatorResult = Paginator.paginate(
|
|
1708
|
+
components.pageContent,
|
|
1709
|
+
{ height, width },
|
|
1710
|
+
{
|
|
1711
|
+
id: state.options.id,
|
|
1712
|
+
plugins: [
|
|
1713
|
+
...state.options.plugins ?? defaultPlugins,
|
|
1714
|
+
createSectionPageHeightPlugin(
|
|
1715
|
+
height,
|
|
1716
|
+
sectionHeaderHeight,
|
|
1717
|
+
sectionFooterHeight
|
|
1718
|
+
)
|
|
1719
|
+
]
|
|
1720
|
+
}
|
|
1721
|
+
);
|
|
1722
|
+
temporarilyContainer.remove();
|
|
1723
|
+
const pageContexts = paginatorResult.map((content, index) => ({
|
|
1724
|
+
index,
|
|
1725
|
+
totalPages: paginatorResult.length,
|
|
1726
|
+
sectionId: state.options.id,
|
|
1727
|
+
pageContentHtml: content
|
|
1728
|
+
}));
|
|
1729
|
+
state.onPaginationCompleted(pageContexts);
|
|
1730
|
+
for (const pageContext of pageContexts) {
|
|
1731
|
+
this._monitor.dispatch("pageCompleted", pageContext);
|
|
1732
|
+
}
|
|
1733
|
+
const sectionContext = {
|
|
1734
|
+
...state.context,
|
|
1735
|
+
isPaginated: true,
|
|
1736
|
+
isSuspended: false,
|
|
1737
|
+
pages: pageContexts
|
|
1738
|
+
};
|
|
1739
|
+
this._sections.set(state.options.id, {
|
|
1740
|
+
...state,
|
|
1741
|
+
context: sectionContext
|
|
1742
|
+
});
|
|
1743
|
+
this._monitor.dispatch("sectionCompleted", sectionContext);
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
|
|
1747
|
+
// ../core/src/utils.ts
|
|
1748
|
+
function buildPageId(sectionId2, pageIndex) {
|
|
1749
|
+
return `${sectionId2}-${pageIndex + 1}`;
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
// ../vanilla/src/attributes.ts
|
|
1753
|
+
var sectionAttribute = `${attributePrefix}section`;
|
|
1754
|
+
var sectionHeaderAttribute = `${attributePrefix}section-header`;
|
|
1755
|
+
var sectionFooterAttribute = `${attributePrefix}section-footer`;
|
|
1756
|
+
var pageHeaderAttribute = `${attributePrefix}page-header`;
|
|
1757
|
+
var pageFooterAttribute = `${attributePrefix}page-footer`;
|
|
1758
|
+
var pageContentAttribute = `${attributePrefix}page-content`;
|
|
1759
|
+
var pageOverlayAttribute = `${attributePrefix}page-overlay`;
|
|
1760
|
+
var sectionIdMetadataAttribute = `${attributePrefix}section-id`;
|
|
1761
|
+
var pageIndexMetadataAttribute = `${attributePrefix}page-index`;
|
|
1762
|
+
var pageNumberValueAttribute = `${attributePrefix}v-page-number`;
|
|
1763
|
+
var totalPagesValueAttribute = `${attributePrefix}v-total-pages`;
|
|
1764
|
+
var sectionNumberValueAttribute = `${attributePrefix}v-section-number`;
|
|
1765
|
+
var totalSectionsValueAttribute = `${attributePrefix}v-total-sections`;
|
|
1766
|
+
|
|
1767
|
+
// ../vanilla/src/PaprizeReport.ts
|
|
1768
|
+
var globalStyles = `
|
|
1769
|
+
[${sectionAttribute}=true] {
|
|
1770
|
+
display: none;
|
|
1771
|
+
}
|
|
1772
|
+
`;
|
|
1773
|
+
var PaprizeReport = class {
|
|
1774
|
+
_sections = /* @__PURE__ */ new Map();
|
|
1775
|
+
_reportManager;
|
|
1776
|
+
_monitor;
|
|
1777
|
+
_root;
|
|
1778
|
+
_options;
|
|
1779
|
+
constructor(options) {
|
|
1780
|
+
const style = document.createElement("style");
|
|
1781
|
+
style.textContent = globalStyles;
|
|
1782
|
+
document.head.appendChild(style);
|
|
1783
|
+
this._options = options ?? {};
|
|
1784
|
+
this._monitor = new EventDispatcher();
|
|
1785
|
+
this._reportManager = new ReportBuilder();
|
|
1786
|
+
this._root = this._createRootElement();
|
|
1787
|
+
this._reportManager.monitor.addEventListener(
|
|
1788
|
+
"sectionCreated",
|
|
1789
|
+
(event) => {
|
|
1790
|
+
this._monitor.dispatch("sectionCreated", {
|
|
1791
|
+
...event,
|
|
1792
|
+
pages: []
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
);
|
|
1796
|
+
this._reportManager.monitor.addEventListener(
|
|
1797
|
+
"sectionCompleted",
|
|
1798
|
+
(event) => {
|
|
1799
|
+
const pages = this._getSectionState(event.sectionId).pages;
|
|
1800
|
+
this._monitor.dispatch("sectionCompleted", {
|
|
1801
|
+
...event,
|
|
1802
|
+
pages: pages ?? []
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1805
|
+
);
|
|
1806
|
+
this._reportManager.monitor.addEventListener(
|
|
1807
|
+
"pageCompleted",
|
|
1808
|
+
(event) => {
|
|
1809
|
+
const pages = this._getSectionState(event.sectionId).pages;
|
|
1810
|
+
this._monitor.dispatch("pageCompleted", pages[event.index]);
|
|
1811
|
+
}
|
|
1812
|
+
);
|
|
1813
|
+
this._reportManager.monitor.addEventListener(
|
|
1814
|
+
"paginationCycleCompleted",
|
|
1815
|
+
(event) => {
|
|
1816
|
+
this._monitor.dispatch("paginationCycleCompleted", {
|
|
1817
|
+
sections: event.sections.map((s) => ({
|
|
1818
|
+
...s,
|
|
1819
|
+
pages: this._sections.get(s.sectionId)?.pages ?? []
|
|
1820
|
+
}))
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
);
|
|
1824
|
+
}
|
|
1825
|
+
_createRootElement() {
|
|
1826
|
+
const wrapper = document.createElement("div");
|
|
1827
|
+
if (this._options.usePreviewMode) {
|
|
1828
|
+
wrapper.classList.add(previewClassName);
|
|
1829
|
+
}
|
|
1830
|
+
(this._options.root ?? document.body).appendChild(wrapper);
|
|
1831
|
+
return wrapper;
|
|
1832
|
+
}
|
|
1833
|
+
async schedulePaginate() {
|
|
1834
|
+
return this._reportManager.schedulePaginate();
|
|
1835
|
+
}
|
|
1836
|
+
get monitor() {
|
|
1837
|
+
return this._monitor;
|
|
1838
|
+
}
|
|
1839
|
+
addSection(options) {
|
|
1840
|
+
if (this._sections.has(options.id)) {
|
|
1841
|
+
return this;
|
|
1842
|
+
}
|
|
1843
|
+
const section2 = document.getElementById(options.id);
|
|
1844
|
+
if (!section2) {
|
|
1845
|
+
throw new Error(
|
|
1846
|
+
`Section with id ${options.id} not found in the DOM.`
|
|
1847
|
+
);
|
|
1848
|
+
}
|
|
1849
|
+
const components = this._getSectionComponents(section2);
|
|
1850
|
+
const sectionElement = this._createSectionInDom(options.id);
|
|
1851
|
+
const result = this._reportManager.tryAddSection(
|
|
1852
|
+
options,
|
|
1853
|
+
components,
|
|
1854
|
+
(pageContexts) => {
|
|
1855
|
+
this._renderSection(options, pageContexts);
|
|
1856
|
+
}
|
|
1857
|
+
);
|
|
1858
|
+
if (!result) {
|
|
1859
|
+
this._root.removeChild(sectionElement);
|
|
1860
|
+
logger_default.error(
|
|
1861
|
+
`Section with id ${options.id} already exists in the report manager.`
|
|
1862
|
+
);
|
|
1863
|
+
return this;
|
|
1864
|
+
}
|
|
1865
|
+
this._sections.set(options.id, {
|
|
1866
|
+
pages: [],
|
|
1867
|
+
sectionElement,
|
|
1868
|
+
components,
|
|
1869
|
+
options
|
|
1870
|
+
});
|
|
1871
|
+
return this;
|
|
1872
|
+
}
|
|
1873
|
+
_getSectionState(id) {
|
|
1874
|
+
const state = this._sections.get(id);
|
|
1875
|
+
if (!state) {
|
|
1876
|
+
throw new Error(`Section with id ${id} not found in the report.`);
|
|
1877
|
+
}
|
|
1878
|
+
return state;
|
|
1879
|
+
}
|
|
1880
|
+
_createSectionInDom(sectionId2) {
|
|
1881
|
+
const section2 = document.createElement("div");
|
|
1882
|
+
section2.setAttribute(sectionIdMetadataAttribute, sectionId2);
|
|
1883
|
+
section2.classList.add(sectionClassName);
|
|
1884
|
+
section2.id = sectionId2;
|
|
1885
|
+
Object.assign(section2.style, reportStyles.section(sectionId2));
|
|
1886
|
+
this._root.appendChild(section2);
|
|
1887
|
+
return section2;
|
|
1888
|
+
}
|
|
1889
|
+
_getSectionComponents(section2) {
|
|
1890
|
+
const pageContent2 = section2.querySelector(
|
|
1891
|
+
`[${pageContentAttribute}]`
|
|
1892
|
+
);
|
|
1893
|
+
if (!pageContent2) {
|
|
1894
|
+
throw new Error(
|
|
1895
|
+
`Page content not found in section with id ${section2.id}`
|
|
1896
|
+
);
|
|
1897
|
+
}
|
|
1898
|
+
return {
|
|
1899
|
+
sectionHeader: section2.querySelector(
|
|
1900
|
+
`[${sectionHeaderAttribute}]`
|
|
1901
|
+
),
|
|
1902
|
+
sectionFooter: section2.querySelector(
|
|
1903
|
+
`[${sectionFooterAttribute}]`
|
|
1904
|
+
),
|
|
1905
|
+
pageHeader: section2.querySelector(
|
|
1906
|
+
`[${pageHeaderAttribute}]`
|
|
1907
|
+
),
|
|
1908
|
+
pageFooter: section2.querySelector(
|
|
1909
|
+
`[${pageFooterAttribute}]`
|
|
1910
|
+
),
|
|
1911
|
+
pageContent: pageContent2
|
|
1912
|
+
};
|
|
1913
|
+
}
|
|
1914
|
+
async _renderSection(options, pageContexts) {
|
|
1915
|
+
const state = this._getSectionState(options.id);
|
|
1916
|
+
if (!this._options.keepInitialElementAfterPagination) {
|
|
1917
|
+
document.getElementById(options.id)?.remove();
|
|
1918
|
+
}
|
|
1919
|
+
const pages = [];
|
|
1920
|
+
for (const pageContext of pageContexts) {
|
|
1921
|
+
const page2 = document.createElement("div");
|
|
1922
|
+
page2.classList.add(pageClassName);
|
|
1923
|
+
page2.id = buildPageId(options.id, pageContext.index);
|
|
1924
|
+
page2.setAttribute(
|
|
1925
|
+
pageIndexMetadataAttribute,
|
|
1926
|
+
pageContext.index.toString()
|
|
1927
|
+
);
|
|
1928
|
+
Object.assign(
|
|
1929
|
+
page2.style,
|
|
1930
|
+
reportStyles.page(
|
|
1931
|
+
options.dimension,
|
|
1932
|
+
options.margin ?? pageMargin.None
|
|
1933
|
+
)
|
|
1934
|
+
);
|
|
1935
|
+
const components = cloneComponents(state.components);
|
|
1936
|
+
if (pageContext.index === 0 && components.sectionHeader) {
|
|
1937
|
+
page2.appendChild(components.sectionHeader);
|
|
1938
|
+
}
|
|
1939
|
+
if (components.pageHeader) {
|
|
1940
|
+
page2.appendChild(components.pageHeader);
|
|
1941
|
+
}
|
|
1942
|
+
const pageContent2 = document.createElement("div");
|
|
1943
|
+
pageContent2.innerHTML = pageContext.pageContentHtml;
|
|
1944
|
+
page2.appendChild(pageContent2);
|
|
1945
|
+
const pageFooterContainer = document.createElement("div");
|
|
1946
|
+
pageFooterContainer.style.marginTop = "auto";
|
|
1947
|
+
if (components.pageFooter) {
|
|
1948
|
+
pageFooterContainer.appendChild(components.pageFooter);
|
|
1949
|
+
}
|
|
1950
|
+
if (pageContext.index === pageContexts.length - 1 && components.sectionFooter) {
|
|
1951
|
+
pageFooterContainer.appendChild(
|
|
1952
|
+
components.sectionFooter.cloneNode(true)
|
|
1953
|
+
);
|
|
1954
|
+
}
|
|
1955
|
+
if (pageFooterContainer.children.length > 0) {
|
|
1956
|
+
page2.appendChild(pageFooterContainer);
|
|
1957
|
+
}
|
|
1958
|
+
this._replaceContentInfoValues(
|
|
1959
|
+
{ ...components, pageContent: pageContent2 },
|
|
1960
|
+
pageContext
|
|
1961
|
+
);
|
|
1962
|
+
state.sectionElement.appendChild(page2);
|
|
1963
|
+
const domPageContext = {
|
|
1964
|
+
sectionId: options.id,
|
|
1965
|
+
index: pageContext.index,
|
|
1966
|
+
totalPages: pageContexts.length,
|
|
1967
|
+
...components,
|
|
1968
|
+
page: page2,
|
|
1969
|
+
pageContent: pageContent2
|
|
1970
|
+
};
|
|
1971
|
+
pages.push(domPageContext);
|
|
1972
|
+
}
|
|
1973
|
+
this._sections.set(options.id, {
|
|
1974
|
+
...state,
|
|
1975
|
+
pages
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
_replaceContentInfoValues(components, pageContext) {
|
|
1979
|
+
for (const component2 of Object.values(components)) {
|
|
1980
|
+
if (!component2) continue;
|
|
1981
|
+
component2.querySelectorAll(`[${pageNumberValueAttribute}]`).forEach((el) => {
|
|
1982
|
+
el.textContent = (pageContext.index + 1).toString();
|
|
1983
|
+
});
|
|
1984
|
+
component2.querySelectorAll(`[${totalPagesValueAttribute}]`).forEach((el) => {
|
|
1985
|
+
el.textContent = pageContext.totalPages.toString();
|
|
1986
|
+
});
|
|
1987
|
+
component2.querySelectorAll(`[${sectionNumberValueAttribute}]`).forEach((el) => {
|
|
1988
|
+
el.textContent = (Array.from(this._sections.keys()).indexOf(
|
|
1989
|
+
pageContext.sectionId
|
|
1990
|
+
) + 1).toString();
|
|
1991
|
+
});
|
|
1992
|
+
component2.querySelectorAll(`[${totalSectionsValueAttribute}]`).forEach((el) => {
|
|
1993
|
+
el.textContent = this._sections.size.toString();
|
|
1994
|
+
});
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
};
|
|
1998
|
+
|
|
1999
|
+
// src/zeroReport.ts
|
|
2000
|
+
var sectionPageSizeAttribute = `${attributePrefix}section-page-size`;
|
|
2001
|
+
var sectionPageMarginAttribute = `${attributePrefix}section-page-margin`;
|
|
2002
|
+
function parsePageSizeAttribute(section2) {
|
|
2003
|
+
const size = section2.getAttribute(sectionPageSizeAttribute);
|
|
2004
|
+
console.warn(
|
|
2005
|
+
"ss",
|
|
2006
|
+
size,
|
|
2007
|
+
section2.getAttributeNames().join(","),
|
|
2008
|
+
sectionPageSizeAttribute,
|
|
2009
|
+
section2.getAttribute("data-pz-section-page-size")
|
|
2010
|
+
);
|
|
2011
|
+
const dimension = Object.entries(pageSize).find(
|
|
2012
|
+
([key]) => key.toLowerCase() === size?.toLowerCase()
|
|
2013
|
+
)?.[1];
|
|
2014
|
+
return dimension ?? pageSize.A4;
|
|
2015
|
+
}
|
|
2016
|
+
function parsePageMarginAttribute(section2) {
|
|
2017
|
+
const size = section2.getAttribute(sectionPageMarginAttribute);
|
|
2018
|
+
const margin = Object.entries(pageMargin).find(
|
|
2019
|
+
([key]) => key.toLowerCase() === size?.toLowerCase()
|
|
2020
|
+
)?.[1];
|
|
2021
|
+
return margin ?? pageMargin.Narrow;
|
|
2022
|
+
}
|
|
2023
|
+
var sectionId = 1;
|
|
2024
|
+
var report = new PaprizeReport();
|
|
2025
|
+
document.querySelectorAll(`[${sectionAttribute}]`).forEach((el) => {
|
|
2026
|
+
const id = el.id || `section-${sectionId++}`;
|
|
2027
|
+
if (!el.id) {
|
|
2028
|
+
el.id = id;
|
|
2029
|
+
}
|
|
2030
|
+
report.addSection({
|
|
2031
|
+
dimension: parsePageSizeAttribute(el),
|
|
2032
|
+
margin: parsePageMarginAttribute(el),
|
|
2033
|
+
id
|
|
2034
|
+
});
|
|
2035
|
+
});
|
|
2036
|
+
report.schedulePaginate();
|
|
2037
|
+
export {
|
|
2038
|
+
sectionPageMarginAttribute,
|
|
2039
|
+
sectionPageSizeAttribute
|
|
2040
|
+
};
|
|
2041
|
+
//# sourceMappingURL=paprize-zero.js.map
|