html2canvas-pro 2.4.4 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -13
- package/dist/html2canvas-pro.cjs +3246 -1601
- package/dist/html2canvas-pro.cjs.map +1 -1
- package/dist/html2canvas-pro.esm.js +3246 -1601
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +3242 -1597
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +5 -5
- package/dist/types/core/cache-storage.d.ts +4 -1
- package/dist/types/core/context.d.ts +10 -1
- package/dist/types/core/render-element.d.ts +11 -0
- package/dist/types/core/util.d.ts +6 -0
- package/dist/types/css/index.d.ts +77 -46
- package/dist/types/css/parse.d.ts +15 -0
- package/dist/types/css/property-descriptors/accent-color.d.ts +5 -0
- package/dist/types/css/property-descriptors/backdrop-filter.d.ts +9 -0
- package/dist/types/css/property-descriptors/background-blend-mode.d.ts +16 -16
- package/dist/types/css/property-descriptors/border-image-width.d.ts +36 -0
- package/dist/types/css/property-descriptors/clip-path.d.ts +16 -2
- package/dist/types/css/property-descriptors/isolation.d.ts +6 -0
- package/dist/types/css/property-descriptors/mask.d.ts +25 -0
- package/dist/types/css/property-descriptors/mix-blend-mode.d.ts +16 -16
- package/dist/types/css/property-descriptors/outline.d.ts +15 -0
- package/dist/types/css/property-descriptors/text-emphasis.d.ts +22 -0
- package/dist/types/css/property-descriptors/text-shadow.d.ts +1 -1
- package/dist/types/css/property-descriptors/webkit-box-reflect.d.ts +19 -0
- package/dist/types/css/property-descriptors/webkit-text-fill-color.d.ts +9 -0
- package/dist/types/css/syntax/token-constants.d.ts +1 -1
- package/dist/types/css/types/color-math.d.ts +7 -1
- package/dist/types/css/types/color-spaces/a98.d.ts +2 -1
- package/dist/types/css/types/color-spaces/p3.d.ts +5 -4
- package/dist/types/css/types/color-spaces/pro-photo.d.ts +5 -4
- package/dist/types/css/types/color-spaces/rec2020.d.ts +5 -4
- package/dist/types/css/types/color-spaces/srgb.d.ts +5 -4
- package/dist/types/css/types/color-utilities.d.ts +11 -11
- package/dist/types/css/types/color.d.ts +1 -0
- package/dist/types/css/types/functions/conic-gradient.d.ts +11 -0
- package/dist/types/css/types/functions/image-set.d.ts +11 -0
- package/dist/types/css/types/functions/repeating-radial-gradient.d.ts +8 -0
- package/dist/types/css/types/image.d.ts +15 -2
- package/dist/types/css/types/safe-eval.d.ts +0 -6
- package/dist/types/dom/copy-css-styles.d.ts +8 -0
- package/dist/types/dom/document-cloner.d.ts +3 -13
- package/dist/types/dom/iframe-mount.d.ts +37 -0
- package/dist/types/dom/pseudo-content.d.ts +33 -0
- package/dist/types/dom/replaced-elements/iframe-element-container.d.ts +2 -2
- package/dist/types/options.d.ts +8 -2
- package/dist/types/render/canvas/background-renderer.d.ts +19 -0
- package/dist/types/render/canvas/border-image-renderer.d.ts +50 -1
- package/dist/types/render/canvas/box-shadow-geometry.d.ts +3 -0
- package/dist/types/render/canvas/box-shadow-painter.d.ts +13 -0
- package/dist/types/render/canvas/box-shadow-transform.d.ts +16 -0
- package/dist/types/render/canvas/canvas-renderer.d.ts +21 -15
- package/dist/types/render/canvas/mask-renderer.d.ts +36 -0
- package/dist/types/render/canvas/text-clip-renderer.d.ts +36 -0
- package/dist/types/render/canvas/text-renderer.d.ts +22 -0
- package/dist/types/render/stacking-context.d.ts +4 -1
- package/package.json +39 -40
- package/dist/lib/config.js +0 -49
- package/dist/lib/core/abort-helper.js +0 -20
- package/dist/lib/core/background-parser.js +0 -41
- package/dist/lib/core/bitwise.js +0 -5
- package/dist/lib/core/cache-storage.js +0 -283
- package/dist/lib/core/config-assembler.js +0 -88
- package/dist/lib/core/constants.js +0 -25
- package/dist/lib/core/context.js +0 -19
- package/dist/lib/core/debugger.js +0 -27
- package/dist/lib/core/features.js +0 -190
- package/dist/lib/core/logger.js +0 -56
- package/dist/lib/core/lru-map.js +0 -66
- package/dist/lib/core/origin-checker.js +0 -53
- package/dist/lib/core/performance-monitor.js +0 -185
- package/dist/lib/core/render-element.js +0 -131
- package/dist/lib/core/util.js +0 -4
- package/dist/lib/core/validator.js +0 -500
- package/dist/lib/css/grouped/background-styles.js +0 -36
- package/dist/lib/css/grouped/border-styles.js +0 -75
- package/dist/lib/css/grouped/font-styles.js +0 -93
- package/dist/lib/css/grouped/layout-styles.js +0 -127
- package/dist/lib/css/index.js +0 -339
- package/dist/lib/css/layout/bounds.js +0 -52
- package/dist/lib/css/layout/text.js +0 -133
- package/dist/lib/css/property-descriptor.js +0 -2
- package/dist/lib/css/property-descriptors/background-blend-mode.js +0 -41
- package/dist/lib/css/property-descriptors/background-clip.js +0 -25
- package/dist/lib/css/property-descriptors/background-color.js +0 -10
- package/dist/lib/css/property-descriptors/background-image.js +0 -24
- package/dist/lib/css/property-descriptors/background-origin.js +0 -23
- package/dist/lib/css/property-descriptors/background-position.js +0 -19
- package/dist/lib/css/property-descriptors/background-repeat.js +0 -33
- package/dist/lib/css/property-descriptors/background-size.js +0 -23
- package/dist/lib/css/property-descriptors/border-color.js +0 -14
- package/dist/lib/css/property-descriptors/border-image-repeat.js +0 -42
- package/dist/lib/css/property-descriptors/border-image-slice.js +0 -45
- package/dist/lib/css/property-descriptors/border-image-source.js +0 -22
- package/dist/lib/css/property-descriptors/border-radius.js +0 -15
- package/dist/lib/css/property-descriptors/border-style.js +0 -26
- package/dist/lib/css/property-descriptors/border-width.js +0 -20
- package/dist/lib/css/property-descriptors/box-decoration-break.js +0 -18
- package/dist/lib/css/property-descriptors/box-shadow.js +0 -54
- package/dist/lib/css/property-descriptors/clip-path.js +0 -189
- package/dist/lib/css/property-descriptors/color.js +0 -10
- package/dist/lib/css/property-descriptors/content.js +0 -19
- package/dist/lib/css/property-descriptors/counter-increment.js +0 -35
- package/dist/lib/css/property-descriptors/counter-reset.js +0 -18
- package/dist/lib/css/property-descriptors/direction.js +0 -18
- package/dist/lib/css/property-descriptors/display.js +0 -81
- package/dist/lib/css/property-descriptors/duration.js +0 -14
- package/dist/lib/css/property-descriptors/filter.js +0 -86
- package/dist/lib/css/property-descriptors/float.js +0 -22
- package/dist/lib/css/property-descriptors/font-family.js +0 -47
- package/dist/lib/css/property-descriptors/font-size.js +0 -10
- package/dist/lib/css/property-descriptors/font-style.js +0 -20
- package/dist/lib/css/property-descriptors/font-variant-ligatures.js +0 -34
- package/dist/lib/css/property-descriptors/font-variant.js +0 -13
- package/dist/lib/css/property-descriptors/font-weight.js +0 -25
- package/dist/lib/css/property-descriptors/image-rendering.js +0 -33
- package/dist/lib/css/property-descriptors/letter-spacing.js +0 -21
- package/dist/lib/css/property-descriptors/line-break.js +0 -23
- package/dist/lib/css/property-descriptors/line-height.js +0 -24
- package/dist/lib/css/property-descriptors/list-style-image.js +0 -17
- package/dist/lib/css/property-descriptors/list-style-position.js +0 -18
- package/dist/lib/css/property-descriptors/list-style-type.js +0 -122
- package/dist/lib/css/property-descriptors/margin.js +0 -13
- package/dist/lib/css/property-descriptors/mix-blend-mode.js +0 -31
- package/dist/lib/css/property-descriptors/object-fit.js +0 -28
- package/dist/lib/css/property-descriptors/object-position.js +0 -42
- package/dist/lib/css/property-descriptors/opacity.js +0 -16
- package/dist/lib/css/property-descriptors/overflow-wrap.js +0 -18
- package/dist/lib/css/property-descriptors/overflow.js +0 -27
- package/dist/lib/css/property-descriptors/padding.js +0 -14
- package/dist/lib/css/property-descriptors/paint-order.js +0 -33
- package/dist/lib/css/property-descriptors/position.js +0 -22
- package/dist/lib/css/property-descriptors/quotes.js +0 -41
- package/dist/lib/css/property-descriptors/rotate.js +0 -27
- package/dist/lib/css/property-descriptors/text-align.js +0 -21
- package/dist/lib/css/property-descriptors/text-decoration-color.js +0 -10
- package/dist/lib/css/property-descriptors/text-decoration-line.js +0 -28
- package/dist/lib/css/property-descriptors/text-decoration-style.js +0 -24
- package/dist/lib/css/property-descriptors/text-decoration-thickness.js +0 -26
- package/dist/lib/css/property-descriptors/text-overflow.js +0 -18
- package/dist/lib/css/property-descriptors/text-shadow.js +0 -46
- package/dist/lib/css/property-descriptors/text-transform.js +0 -20
- package/dist/lib/css/property-descriptors/text-underline-offset.js +0 -23
- package/dist/lib/css/property-descriptors/transform-origin.js +0 -24
- package/dist/lib/css/property-descriptors/transform.js +0 -57
- package/dist/lib/css/property-descriptors/visibility.js +0 -20
- package/dist/lib/css/property-descriptors/webkit-line-clamp.js +0 -26
- package/dist/lib/css/property-descriptors/webkit-text-stroke-color.js +0 -10
- package/dist/lib/css/property-descriptors/webkit-text-stroke-width.js +0 -16
- package/dist/lib/css/property-descriptors/white-space.js +0 -32
- package/dist/lib/css/property-descriptors/word-break.js +0 -26
- package/dist/lib/css/property-descriptors/writing-mode.js +0 -28
- package/dist/lib/css/property-descriptors/z-index.js +0 -19
- package/dist/lib/css/property-descriptors/zoom.js +0 -18
- package/dist/lib/css/syntax/parser.js +0 -141
- package/dist/lib/css/syntax/token-constants.js +0 -214
- package/dist/lib/css/syntax/token-singletons.js +0 -36
- package/dist/lib/css/syntax/token-types.js +0 -10
- package/dist/lib/css/syntax/tokenizer.js +0 -502
- package/dist/lib/css/type-descriptor.js +0 -2
- package/dist/lib/css/types/angle.js +0 -80
- package/dist/lib/css/types/color-math.js +0 -25
- package/dist/lib/css/types/color-spaces/a98.js +0 -78
- package/dist/lib/css/types/color-spaces/p3.js +0 -86
- package/dist/lib/css/types/color-spaces/pro-photo.js +0 -83
- package/dist/lib/css/types/color-spaces/rec2020.js +0 -85
- package/dist/lib/css/types/color-spaces/srgb.js +0 -79
- package/dist/lib/css/types/color-utilities.js +0 -342
- package/dist/lib/css/types/color.js +0 -400
- package/dist/lib/css/types/functions/-prefix-linear-gradient.js +0 -32
- package/dist/lib/css/types/functions/-prefix-radial-gradient.js +0 -83
- package/dist/lib/css/types/functions/-webkit-gradient.js +0 -59
- package/dist/lib/css/types/functions/counter.js +0 -367
- package/dist/lib/css/types/functions/gradient.js +0 -163
- package/dist/lib/css/types/functions/linear-gradient.js +0 -27
- package/dist/lib/css/types/functions/radial-gradient.js +0 -90
- package/dist/lib/css/types/functions/repeating-linear-gradient.js +0 -9
- package/dist/lib/css/types/image.js +0 -62
- package/dist/lib/css/types/index.js +0 -2
- package/dist/lib/css/types/length-percentage.js +0 -197
- package/dist/lib/css/types/length.js +0 -5
- package/dist/lib/css/types/safe-eval.js +0 -80
- package/dist/lib/css/types/time.js +0 -17
- package/dist/lib/dom/document-cloner.js +0 -618
- package/dist/lib/dom/dom-normalizer.js +0 -115
- package/dist/lib/dom/element-container.js +0 -71
- package/dist/lib/dom/elements/li-element-container.js +0 -11
- package/dist/lib/dom/elements/ol-element-container.js +0 -12
- package/dist/lib/dom/elements/select-element-container.js +0 -12
- package/dist/lib/dom/elements/textarea-element-container.js +0 -11
- package/dist/lib/dom/node-parser.js +0 -125
- package/dist/lib/dom/node-type-guards.js +0 -81
- package/dist/lib/dom/replaced-elements/canvas-element-container.js +0 -13
- package/dist/lib/dom/replaced-elements/iframe-element-container.js +0 -38
- package/dist/lib/dom/replaced-elements/image-element-container.js +0 -14
- package/dist/lib/dom/replaced-elements/index.js +0 -2
- package/dist/lib/dom/replaced-elements/input-element-container.js +0 -89
- package/dist/lib/dom/replaced-elements/svg-element-container.js +0 -57
- package/dist/lib/dom/slot-cloner.js +0 -176
- package/dist/lib/dom/text-container.js +0 -35
- package/dist/lib/index.js +0 -49
- package/dist/lib/options.js +0 -2
- package/dist/lib/render/background.js +0 -188
- package/dist/lib/render/bezier-curve.js +0 -34
- package/dist/lib/render/border.js +0 -104
- package/dist/lib/render/bound-curves.js +0 -188
- package/dist/lib/render/box-sizing.js +0 -20
- package/dist/lib/render/canvas/background-renderer.js +0 -338
- package/dist/lib/render/canvas/border-image-renderer.js +0 -153
- package/dist/lib/render/canvas/border-renderer.js +0 -184
- package/dist/lib/render/canvas/canvas-path.js +0 -25
- package/dist/lib/render/canvas/canvas-renderer.js +0 -633
- package/dist/lib/render/canvas/content-renderer.js +0 -270
- package/dist/lib/render/canvas/effects-renderer.js +0 -171
- package/dist/lib/render/canvas/filter-surface.js +0 -270
- package/dist/lib/render/canvas/font-utils.js +0 -46
- package/dist/lib/render/canvas/foreignobject-renderer.js +0 -38
- package/dist/lib/render/canvas/surface-bounds.js +0 -64
- package/dist/lib/render/canvas/text/text-decoration-renderer.js +0 -99
- package/dist/lib/render/canvas/text-renderer.js +0 -486
- package/dist/lib/render/effects.js +0 -231
- package/dist/lib/render/font-metrics.js +0 -53
- package/dist/lib/render/object-fit.js +0 -91
- package/dist/lib/render/path.js +0 -26
- package/dist/lib/render/renderer-interface.js +0 -2
- package/dist/lib/render/stacking-context.js +0 -341
- package/dist/lib/render/vector.js +0 -16
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assembleRenderOptions = exports.assembleCloneOptions = exports.assembleWindowOptions = exports.assembleContextOptions = exports.assembleResourceOptions = exports.coerceNumberOptions = void 0;
|
|
4
|
-
const constants_1 = require("./constants");
|
|
5
|
-
/**
|
|
6
|
-
* Coerce known numeric options from string (or other) values to actual numbers.
|
|
7
|
-
* Mutates the opts object in place — this is intentionally a normalisation
|
|
8
|
-
* (not pure) step that runs once at the beginning of renderElement.
|
|
9
|
-
*/
|
|
10
|
-
const coerceNumberOptions = (opts) => {
|
|
11
|
-
const numKeys = [
|
|
12
|
-
'scale',
|
|
13
|
-
'width',
|
|
14
|
-
'height',
|
|
15
|
-
'imageTimeout',
|
|
16
|
-
'x',
|
|
17
|
-
'y',
|
|
18
|
-
'windowWidth',
|
|
19
|
-
'windowHeight',
|
|
20
|
-
'scrollX',
|
|
21
|
-
'scrollY'
|
|
22
|
-
];
|
|
23
|
-
numKeys.forEach((key) => {
|
|
24
|
-
const v = opts[key];
|
|
25
|
-
if (v !== undefined && v !== null && typeof v !== 'number') {
|
|
26
|
-
const n = Number(v);
|
|
27
|
-
if (!Number.isNaN(n)) {
|
|
28
|
-
opts[key] = n;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
exports.coerceNumberOptions = coerceNumberOptions;
|
|
34
|
-
/** Assemble resource loading options from user-provided Options. */
|
|
35
|
-
const assembleResourceOptions = (opts) => ({
|
|
36
|
-
allowTaint: opts.allowTaint ?? false,
|
|
37
|
-
imageTimeout: opts.imageTimeout ?? constants_1.DEFAULT_IMAGE_TIMEOUT_MS,
|
|
38
|
-
proxy: opts.proxy,
|
|
39
|
-
useCORS: opts.useCORS ?? false,
|
|
40
|
-
customIsSameOrigin: opts.customIsSameOrigin,
|
|
41
|
-
maxCacheSize: opts.maxCacheSize
|
|
42
|
-
});
|
|
43
|
-
exports.assembleResourceOptions = assembleResourceOptions;
|
|
44
|
-
/** Assemble context (logging + cache) options, extending resource options. */
|
|
45
|
-
const assembleContextOptions = (opts, config, resourceOptions) => ({
|
|
46
|
-
logging: opts.logging ?? true,
|
|
47
|
-
cache: opts.cache ?? config.cache,
|
|
48
|
-
...resourceOptions
|
|
49
|
-
});
|
|
50
|
-
exports.assembleContextOptions = assembleContextOptions;
|
|
51
|
-
const DEFAULT_WINDOW_WIDTH = 800;
|
|
52
|
-
const DEFAULT_WINDOW_HEIGHT = 600;
|
|
53
|
-
const DEFAULT_SCROLL = 0;
|
|
54
|
-
const assembleWindowOptions = (opts, defaultView) => {
|
|
55
|
-
const win = defaultView;
|
|
56
|
-
return {
|
|
57
|
-
windowWidth: opts.windowWidth ?? win.innerWidth ?? DEFAULT_WINDOW_WIDTH,
|
|
58
|
-
windowHeight: opts.windowHeight ?? win.innerHeight ?? DEFAULT_WINDOW_HEIGHT,
|
|
59
|
-
scrollX: opts.scrollX ?? win.pageXOffset ?? DEFAULT_SCROLL,
|
|
60
|
-
scrollY: opts.scrollY ?? win.pageYOffset ?? DEFAULT_SCROLL
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
exports.assembleWindowOptions = assembleWindowOptions;
|
|
64
|
-
/** Assemble DOM cloning options. */
|
|
65
|
-
const assembleCloneOptions = (opts, config, foreignObjectRendering) => ({
|
|
66
|
-
allowTaint: opts.allowTaint ?? false,
|
|
67
|
-
onclone: opts.onclone,
|
|
68
|
-
ignoreElements: opts.ignoreElements,
|
|
69
|
-
iframeContainer: opts.iframeContainer,
|
|
70
|
-
inlineImages: foreignObjectRendering,
|
|
71
|
-
copyStyles: foreignObjectRendering,
|
|
72
|
-
cspNonce: opts.cspNonce ?? config.cspNonce
|
|
73
|
-
});
|
|
74
|
-
exports.assembleCloneOptions = assembleCloneOptions;
|
|
75
|
-
/** Assemble canvas rendering options. */
|
|
76
|
-
const assembleRenderOptions = (opts, backgroundColor, left, top, width, height, devicePixelRatio) => ({
|
|
77
|
-
canvas: opts.canvas,
|
|
78
|
-
backgroundColor,
|
|
79
|
-
signal: opts.signal,
|
|
80
|
-
scale: opts.scale ?? devicePixelRatio ?? 1,
|
|
81
|
-
x: (opts.x ?? 0) + left,
|
|
82
|
-
y: (opts.y ?? 0) + top,
|
|
83
|
-
width: opts.width ?? Math.ceil(width),
|
|
84
|
-
height: opts.height ?? Math.ceil(height),
|
|
85
|
-
imageSmoothing: opts.imageSmoothing,
|
|
86
|
-
imageSmoothingQuality: opts.imageSmoothingQuality
|
|
87
|
-
});
|
|
88
|
-
exports.assembleRenderOptions = assembleRenderOptions;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Shared numeric constants used across html2canvas-pro.
|
|
4
|
-
* Centralising magic numbers for maintainability.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.RESOURCE_KEY_LOG_LENGTH = exports.INLINE_IMAGE_RESOLVE_DELAY_MS = exports.IFRAME_READY_POLL_MS = exports.SHADOW_MASK_OFFSET = exports.DEFAULT_IMAGE_TIMEOUT_MS = exports.MAX_IMAGE_CACHE_SIZE = exports.DEFAULT_IMAGE_CACHE_SIZE = exports.PATTERN_CACHE_MAX = exports.PARSE_CACHE_MAX_PER_DESCRIPTOR = void 0;
|
|
8
|
-
/** Maximum entries in the CSS parse cache per descriptor (LRU). */
|
|
9
|
-
exports.PARSE_CACHE_MAX_PER_DESCRIPTOR = 200;
|
|
10
|
-
/** Maximum cached background-image patterns per render session (LRU). */
|
|
11
|
-
exports.PATTERN_CACHE_MAX = 50;
|
|
12
|
-
/** Maximum size of the image-resource cache (entries). */
|
|
13
|
-
exports.DEFAULT_IMAGE_CACHE_SIZE = 100;
|
|
14
|
-
/** Maximum allowed image-resource cache size. */
|
|
15
|
-
exports.MAX_IMAGE_CACHE_SIZE = 10000;
|
|
16
|
-
/** Default image-load timeout in milliseconds. */
|
|
17
|
-
exports.DEFAULT_IMAGE_TIMEOUT_MS = 15000;
|
|
18
|
-
/** Z-axis mask offset used during box-shadow rendering. */
|
|
19
|
-
exports.SHADOW_MASK_OFFSET = 10000;
|
|
20
|
-
/** Polling interval (ms) when waiting for the cloned iframe to become ready. */
|
|
21
|
-
exports.IFRAME_READY_POLL_MS = 50;
|
|
22
|
-
/** Deferred resolution delay (ms) for inline XML images that may fail to parse. */
|
|
23
|
-
exports.INLINE_IMAGE_RESOLVE_DELAY_MS = 500;
|
|
24
|
-
/** Maximum characters logged for image/resource keys. */
|
|
25
|
-
exports.RESOURCE_KEY_LOG_LENGTH = 256;
|
package/dist/lib/core/context.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Context = void 0;
|
|
4
|
-
const logger_1 = require("./logger");
|
|
5
|
-
const cache_storage_1 = require("./cache-storage");
|
|
6
|
-
const origin_checker_1 = require("./origin-checker");
|
|
7
|
-
class Context {
|
|
8
|
-
constructor(options, windowBounds, config) {
|
|
9
|
-
this.windowBounds = windowBounds;
|
|
10
|
-
this.instanceName = `#${Context.instanceCount++}`;
|
|
11
|
-
this.config = config;
|
|
12
|
-
this.logger = new logger_1.Logger({ id: this.instanceName, enabled: options.logging });
|
|
13
|
-
this.originChecker = new origin_checker_1.OriginChecker(config.window);
|
|
14
|
-
this.cache = options.cache ?? config.cache ?? new cache_storage_1.Cache(this, options);
|
|
15
|
-
this.onError = options.onError;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.Context = Context;
|
|
19
|
-
Context.instanceCount = 1;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDebugging = void 0;
|
|
4
|
-
const elementDebuggerAttribute = 'data-html2canvas-debug';
|
|
5
|
-
const getElementDebugType = (element) => {
|
|
6
|
-
if (typeof element.getAttribute !== 'function') {
|
|
7
|
-
return 0 /* DebuggerType.NONE */;
|
|
8
|
-
}
|
|
9
|
-
const attribute = element.getAttribute(elementDebuggerAttribute);
|
|
10
|
-
switch (attribute) {
|
|
11
|
-
case 'all':
|
|
12
|
-
return 1 /* DebuggerType.ALL */;
|
|
13
|
-
case 'clone':
|
|
14
|
-
return 2 /* DebuggerType.CLONE */;
|
|
15
|
-
case 'parse':
|
|
16
|
-
return 3 /* DebuggerType.PARSE */;
|
|
17
|
-
case 'render':
|
|
18
|
-
return 4 /* DebuggerType.RENDER */;
|
|
19
|
-
default:
|
|
20
|
-
return 0 /* DebuggerType.NONE */;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const isDebugging = (element, type) => {
|
|
24
|
-
const elementType = getElementDebugType(element);
|
|
25
|
-
return elementType === 1 /* DebuggerType.ALL */ || type === elementType;
|
|
26
|
-
};
|
|
27
|
-
exports.isDebugging = isDebugging;
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FEATURES = exports.loadSerializedSVG = exports.createForeignObjectSVG = void 0;
|
|
4
|
-
const css_line_break_1 = require("css-line-break");
|
|
5
|
-
const testRangeBounds = (document) => {
|
|
6
|
-
const TEST_HEIGHT = 123;
|
|
7
|
-
if (document.createRange) {
|
|
8
|
-
const range = document.createRange();
|
|
9
|
-
if (range.getBoundingClientRect) {
|
|
10
|
-
const testElement = document.createElement('boundtest');
|
|
11
|
-
testElement.style.height = `${TEST_HEIGHT}px`;
|
|
12
|
-
testElement.style.display = 'block';
|
|
13
|
-
document.body.appendChild(testElement);
|
|
14
|
-
range.selectNode(testElement);
|
|
15
|
-
const rangeBounds = range.getBoundingClientRect();
|
|
16
|
-
const rangeHeight = Math.round(rangeBounds.height);
|
|
17
|
-
document.body.removeChild(testElement);
|
|
18
|
-
if (rangeHeight === TEST_HEIGHT) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
};
|
|
25
|
-
const testIOSLineBreak = (document) => {
|
|
26
|
-
const testElement = document.createElement('boundtest');
|
|
27
|
-
testElement.style.width = '50px';
|
|
28
|
-
testElement.style.display = 'block';
|
|
29
|
-
testElement.style.fontSize = '12px';
|
|
30
|
-
testElement.style.letterSpacing = '0px';
|
|
31
|
-
testElement.style.wordSpacing = '0px';
|
|
32
|
-
document.body.appendChild(testElement);
|
|
33
|
-
const range = document.createRange();
|
|
34
|
-
testElement.innerHTML = typeof ''.repeat === 'function' ? '👨'.repeat(10) : '';
|
|
35
|
-
const node = testElement.firstChild;
|
|
36
|
-
const textList = (0, css_line_break_1.toCodePoints)(node.data).map((i) => (0, css_line_break_1.fromCodePoint)(i));
|
|
37
|
-
let offset = 0;
|
|
38
|
-
let prev = {};
|
|
39
|
-
// ios 13 does not handle range getBoundingClientRect line changes correctly #2177
|
|
40
|
-
const supports = textList.every((text, i) => {
|
|
41
|
-
range.setStart(node, offset);
|
|
42
|
-
range.setEnd(node, offset + text.length);
|
|
43
|
-
const rect = range.getBoundingClientRect();
|
|
44
|
-
offset += text.length;
|
|
45
|
-
const boundAhead = rect.x > prev.x || rect.y > prev.y;
|
|
46
|
-
prev = rect;
|
|
47
|
-
if (i === 0) {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
return boundAhead;
|
|
51
|
-
});
|
|
52
|
-
document.body.removeChild(testElement);
|
|
53
|
-
return supports;
|
|
54
|
-
};
|
|
55
|
-
const testCORS = () => typeof new Image().crossOrigin !== 'undefined';
|
|
56
|
-
const testResponseType = () => typeof new XMLHttpRequest().responseType === 'string';
|
|
57
|
-
const testSVG = (document) => {
|
|
58
|
-
const img = new Image();
|
|
59
|
-
const canvas = document.createElement('canvas');
|
|
60
|
-
const ctx = canvas.getContext('2d');
|
|
61
|
-
if (!ctx) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
img.src = `data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>`;
|
|
65
|
-
try {
|
|
66
|
-
ctx.drawImage(img, 0, 0);
|
|
67
|
-
canvas.toDataURL();
|
|
68
|
-
}
|
|
69
|
-
catch (e) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
return true;
|
|
73
|
-
};
|
|
74
|
-
const isGreenPixel = (data) => data[0] === 0 && data[1] === 255 && data[2] === 0 && data[3] === 255;
|
|
75
|
-
const testForeignObject = (document) => {
|
|
76
|
-
const canvas = document.createElement('canvas');
|
|
77
|
-
const size = 100;
|
|
78
|
-
canvas.width = size;
|
|
79
|
-
canvas.height = size;
|
|
80
|
-
const ctx = canvas.getContext('2d');
|
|
81
|
-
if (!ctx) {
|
|
82
|
-
return Promise.reject(new Error('Failed to get 2D rendering context'));
|
|
83
|
-
}
|
|
84
|
-
ctx.fillStyle = 'rgb(0, 255, 0)';
|
|
85
|
-
ctx.fillRect(0, 0, size, size);
|
|
86
|
-
const img = new Image();
|
|
87
|
-
const greenImageSrc = canvas.toDataURL();
|
|
88
|
-
img.src = greenImageSrc;
|
|
89
|
-
const svg = (0, exports.createForeignObjectSVG)(size, size, 0, 0, img);
|
|
90
|
-
ctx.fillStyle = 'red';
|
|
91
|
-
ctx.fillRect(0, 0, size, size);
|
|
92
|
-
return (0, exports.loadSerializedSVG)(svg)
|
|
93
|
-
.then((img) => {
|
|
94
|
-
ctx.drawImage(img, 0, 0);
|
|
95
|
-
const data = ctx.getImageData(0, 0, size, size).data;
|
|
96
|
-
ctx.fillStyle = 'red';
|
|
97
|
-
ctx.fillRect(0, 0, size, size);
|
|
98
|
-
const node = document.createElement('div');
|
|
99
|
-
node.style.backgroundImage = `url(${greenImageSrc})`;
|
|
100
|
-
node.style.height = `${size}px`;
|
|
101
|
-
// Firefox 55 does not render inline <img /> tags
|
|
102
|
-
return isGreenPixel(data)
|
|
103
|
-
? (0, exports.loadSerializedSVG)((0, exports.createForeignObjectSVG)(size, size, 0, 0, node))
|
|
104
|
-
: Promise.reject(new Error('ForeignObject rendering not supported'));
|
|
105
|
-
})
|
|
106
|
-
.then((img) => {
|
|
107
|
-
ctx.drawImage(img, 0, 0);
|
|
108
|
-
// Edge does not render background-images
|
|
109
|
-
return isGreenPixel(ctx.getImageData(0, 0, size, size).data);
|
|
110
|
-
})
|
|
111
|
-
.catch(() => false);
|
|
112
|
-
};
|
|
113
|
-
const createForeignObjectSVG = (width, height, x, y, node) => {
|
|
114
|
-
const xmlns = 'http://www.w3.org/2000/svg';
|
|
115
|
-
const svg = document.createElementNS(xmlns, 'svg');
|
|
116
|
-
const foreignObject = document.createElementNS(xmlns, 'foreignObject');
|
|
117
|
-
svg.setAttributeNS(null, 'width', width.toString());
|
|
118
|
-
svg.setAttributeNS(null, 'height', height.toString());
|
|
119
|
-
foreignObject.setAttributeNS(null, 'width', '100%');
|
|
120
|
-
foreignObject.setAttributeNS(null, 'height', '100%');
|
|
121
|
-
foreignObject.setAttributeNS(null, 'x', x.toString());
|
|
122
|
-
foreignObject.setAttributeNS(null, 'y', y.toString());
|
|
123
|
-
foreignObject.setAttributeNS(null, 'externalResourcesRequired', 'true');
|
|
124
|
-
svg.appendChild(foreignObject);
|
|
125
|
-
foreignObject.appendChild(node);
|
|
126
|
-
return svg;
|
|
127
|
-
};
|
|
128
|
-
exports.createForeignObjectSVG = createForeignObjectSVG;
|
|
129
|
-
const loadSerializedSVG = (svg) => {
|
|
130
|
-
return new Promise((resolve, reject) => {
|
|
131
|
-
const img = new Image();
|
|
132
|
-
img.onload = () => resolve(img);
|
|
133
|
-
img.onerror = reject;
|
|
134
|
-
img.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(new XMLSerializer().serializeToString(svg))}`;
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
exports.loadSerializedSVG = loadSerializedSVG;
|
|
138
|
-
exports.FEATURES = {
|
|
139
|
-
get SUPPORT_RANGE_BOUNDS() {
|
|
140
|
-
'use strict';
|
|
141
|
-
const value = testRangeBounds(document);
|
|
142
|
-
Object.defineProperty(exports.FEATURES, 'SUPPORT_RANGE_BOUNDS', { value });
|
|
143
|
-
return value;
|
|
144
|
-
},
|
|
145
|
-
get SUPPORT_WORD_BREAKING() {
|
|
146
|
-
'use strict';
|
|
147
|
-
const value = exports.FEATURES.SUPPORT_RANGE_BOUNDS && testIOSLineBreak(document);
|
|
148
|
-
Object.defineProperty(exports.FEATURES, 'SUPPORT_WORD_BREAKING', { value });
|
|
149
|
-
return value;
|
|
150
|
-
},
|
|
151
|
-
get SUPPORT_SVG_DRAWING() {
|
|
152
|
-
'use strict';
|
|
153
|
-
const value = testSVG(document);
|
|
154
|
-
Object.defineProperty(exports.FEATURES, 'SUPPORT_SVG_DRAWING', { value });
|
|
155
|
-
return value;
|
|
156
|
-
},
|
|
157
|
-
get SUPPORT_FOREIGNOBJECT_DRAWING() {
|
|
158
|
-
'use strict';
|
|
159
|
-
const value = typeof Array.from === 'function' && typeof window.fetch === 'function'
|
|
160
|
-
? testForeignObject(document)
|
|
161
|
-
: Promise.resolve(false);
|
|
162
|
-
Object.defineProperty(exports.FEATURES, 'SUPPORT_FOREIGNOBJECT_DRAWING', { value });
|
|
163
|
-
return value;
|
|
164
|
-
},
|
|
165
|
-
get SUPPORT_CORS_IMAGES() {
|
|
166
|
-
'use strict';
|
|
167
|
-
const value = testCORS();
|
|
168
|
-
Object.defineProperty(exports.FEATURES, 'SUPPORT_CORS_IMAGES', { value });
|
|
169
|
-
return value;
|
|
170
|
-
},
|
|
171
|
-
get SUPPORT_RESPONSE_TYPE() {
|
|
172
|
-
'use strict';
|
|
173
|
-
const value = testResponseType();
|
|
174
|
-
Object.defineProperty(exports.FEATURES, 'SUPPORT_RESPONSE_TYPE', { value });
|
|
175
|
-
return value;
|
|
176
|
-
},
|
|
177
|
-
get SUPPORT_CORS_XHR() {
|
|
178
|
-
'use strict';
|
|
179
|
-
const value = 'withCredentials' in new XMLHttpRequest();
|
|
180
|
-
Object.defineProperty(exports.FEATURES, 'SUPPORT_CORS_XHR', { value });
|
|
181
|
-
return value;
|
|
182
|
-
},
|
|
183
|
-
get SUPPORT_NATIVE_TEXT_SEGMENTATION() {
|
|
184
|
-
'use strict';
|
|
185
|
-
// Intl.Segmenter is TC39 Stage 4 but not yet in TS lib types
|
|
186
|
-
const value = !!(typeof Intl !== 'undefined' && Intl.Segmenter);
|
|
187
|
-
Object.defineProperty(exports.FEATURES, 'SUPPORT_NATIVE_TEXT_SEGMENTATION', { value });
|
|
188
|
-
return value;
|
|
189
|
-
}
|
|
190
|
-
};
|
package/dist/lib/core/logger.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Logger = void 0;
|
|
4
|
-
class Logger {
|
|
5
|
-
constructor({ id, enabled }) {
|
|
6
|
-
this.id = id;
|
|
7
|
-
this.enabled = enabled;
|
|
8
|
-
this.start = Date.now();
|
|
9
|
-
}
|
|
10
|
-
debug(...args) {
|
|
11
|
-
if (this.enabled) {
|
|
12
|
-
// eslint-disable-next-line no-console
|
|
13
|
-
if (typeof window !== 'undefined' && window.console && typeof console.debug === 'function') {
|
|
14
|
-
// eslint-disable-next-line no-console
|
|
15
|
-
console.debug(this.id, `${this.getTime()}ms`, ...args);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
this.info(...args);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
getTime() {
|
|
23
|
-
return Date.now() - this.start;
|
|
24
|
-
}
|
|
25
|
-
info(...args) {
|
|
26
|
-
if (this.enabled) {
|
|
27
|
-
// eslint-disable-next-line no-console
|
|
28
|
-
if (typeof window !== 'undefined' && window.console && typeof console.info === 'function') {
|
|
29
|
-
// eslint-disable-next-line no-console
|
|
30
|
-
console.info(this.id, `${this.getTime()}ms`, ...args);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
warn(...args) {
|
|
35
|
-
if (this.enabled) {
|
|
36
|
-
if (typeof window !== 'undefined' && window.console && typeof console.warn === 'function') {
|
|
37
|
-
console.warn(this.id, `${this.getTime()}ms`, ...args);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this.info(...args);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
error(...args) {
|
|
45
|
-
if (this.enabled) {
|
|
46
|
-
if (typeof window !== 'undefined' && window.console && typeof console.error === 'function') {
|
|
47
|
-
console.error(this.id, `${this.getTime()}ms`, ...args);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
this.info(...args);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.Logger = Logger;
|
|
56
|
-
Logger.instances = {};
|
package/dist/lib/core/lru-map.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LRUMap = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Generic LRU (Least-Recently-Used) wrapper over a native `Map`.
|
|
6
|
-
*
|
|
7
|
-
* Both the CSS parse cache and the background pattern cache implement the
|
|
8
|
-
* same LRU eviction pattern using Map's insertion-order guarantee. This
|
|
9
|
-
* tiny utility centralises that logic so it can be reused without
|
|
10
|
-
* duplication.
|
|
11
|
-
*
|
|
12
|
-
* Usage:
|
|
13
|
-
* ```ts
|
|
14
|
-
* const cache = new LRUMap<string, CanvasPattern>(50);
|
|
15
|
-
* const entry = cache.get(key); // promotes if found, returns undefined otherwise
|
|
16
|
-
* cache.set(key, value); // evicts oldest entry when at capacity
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
class LRUMap {
|
|
20
|
-
constructor(maxSize) {
|
|
21
|
-
this.maxSize = maxSize;
|
|
22
|
-
this._map = new Map();
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Get a value by key.
|
|
26
|
-
* On cache hit the entry is promoted to the end of the Map (most-recently-used).
|
|
27
|
-
* Returns `undefined` on miss.
|
|
28
|
-
*/
|
|
29
|
-
get(key) {
|
|
30
|
-
if (!this._map.has(key)) {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
// Delete-then-set promotes the entry to MRU position.
|
|
34
|
-
const value = this._map.get(key);
|
|
35
|
-
this._map.delete(key);
|
|
36
|
-
this._map.set(key, value);
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Insert or update a key-value pair.
|
|
41
|
-
* If the key already exists it is moved to MRU position. If the map is
|
|
42
|
-
* at capacity the least-recently-used entry (oldest insertion order) is
|
|
43
|
-
* evicted before inserting.
|
|
44
|
-
*/
|
|
45
|
-
set(key, value) {
|
|
46
|
-
if (this._map.has(key)) {
|
|
47
|
-
this._map.delete(key);
|
|
48
|
-
}
|
|
49
|
-
else if (this._map.size >= this.maxSize) {
|
|
50
|
-
const oldestKey = this._map.keys().next().value;
|
|
51
|
-
if (oldestKey !== undefined) {
|
|
52
|
-
this._map.delete(oldestKey);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
this._map.set(key, value);
|
|
56
|
-
}
|
|
57
|
-
/** Current number of entries. */
|
|
58
|
-
get size() {
|
|
59
|
-
return this._map.size;
|
|
60
|
-
}
|
|
61
|
-
/** Remove all entries. */
|
|
62
|
-
clear() {
|
|
63
|
-
this._map.clear();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.LRUMap = LRUMap;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OriginChecker = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Origin Checker
|
|
6
|
-
*
|
|
7
|
-
* Provides origin checking functionality without global static state.
|
|
8
|
-
* Each instance maintains its own anchor element and origin reference.
|
|
9
|
-
*
|
|
10
|
-
* Replaces the static methods in CacheStorage with instance-based approach.
|
|
11
|
-
*/
|
|
12
|
-
class OriginChecker {
|
|
13
|
-
constructor(window) {
|
|
14
|
-
if (!window || !window.document) {
|
|
15
|
-
throw new Error('Valid window object required for OriginChecker');
|
|
16
|
-
}
|
|
17
|
-
if (!window.location || !window.location.href) {
|
|
18
|
-
throw new Error('Window object must have valid location');
|
|
19
|
-
}
|
|
20
|
-
this.link = window.document.createElement('a');
|
|
21
|
-
this.origin = this.getOrigin(window.location.href);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Get the origin (protocol + hostname + port) of a URL
|
|
25
|
-
*
|
|
26
|
-
* @param url - URL to parse
|
|
27
|
-
* @returns Origin string (e.g., "https://example.com:8080")
|
|
28
|
-
*/
|
|
29
|
-
getOrigin(url) {
|
|
30
|
-
this.link.href = url;
|
|
31
|
-
// IE9 hack: accessing href twice to ensure it's properly parsed
|
|
32
|
-
this.link.href = this.link.href;
|
|
33
|
-
return this.link.protocol + this.link.hostname + this.link.port;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Check if a URL is from the same origin as the context
|
|
37
|
-
*
|
|
38
|
-
* @param src - URL to check
|
|
39
|
-
* @returns true if same origin, false otherwise
|
|
40
|
-
*/
|
|
41
|
-
isSameOrigin(src) {
|
|
42
|
-
return this.getOrigin(src) === this.origin;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Get the current context origin
|
|
46
|
-
*
|
|
47
|
-
* @returns The origin of the context window
|
|
48
|
-
*/
|
|
49
|
-
getContextOrigin() {
|
|
50
|
-
return this.origin;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.OriginChecker = OriginChecker;
|