html2canvas-pro 2.2.1 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/html2canvas-pro.esm.js +22 -5
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +22 -5
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +3 -3
- package/dist/lib/css/index.js +9 -4
- package/dist/lib/css/property-descriptors/background-image.js +1 -0
- package/dist/lib/css/property-descriptors/border-image-source.js +1 -0
- package/dist/lib/css/property-descriptors/list-style-image.js +1 -0
- package/dist/lib/render/canvas/effects-renderer.js +11 -8
- package/dist/lib/render/effects.js +15 -1
- package/dist/types/css/property-descriptor.d.ts +4 -0
- package/dist/types/render/effects.d.ts +9 -1
- package/package.json +1 -1
package/dist/lib/css/index.js
CHANGED
|
@@ -310,10 +310,15 @@ const parse = (context, descriptor, style) => {
|
|
|
310
310
|
valueCache = new Map();
|
|
311
311
|
parseCache.set(descriptor, valueCache);
|
|
312
312
|
}
|
|
313
|
-
// Skip caching for
|
|
314
|
-
//
|
|
315
|
-
//
|
|
316
|
-
|
|
313
|
+
// Skip caching for descriptors whose parse() has the critical side effect
|
|
314
|
+
// of calling context.cache.addImage() which must run on every render pass
|
|
315
|
+
// (different cache instances per html2canvas call). Two paths:
|
|
316
|
+
// 1. Per-descriptor skipCache flag (backgroundImage, listStyleImage,
|
|
317
|
+
// borderImageSource — all call image.parse() internally).
|
|
318
|
+
// 2. TYPE_VALUE + format 'image' — the image type descriptor itself,
|
|
319
|
+
// which calls addImage() directly.
|
|
320
|
+
const skipCache = descriptor.skipCache ||
|
|
321
|
+
(descriptor.type === 3 /* PropertyDescriptorParsingType.TYPE_VALUE */ && descriptor.format === 'image');
|
|
317
322
|
if (!skipCache) {
|
|
318
323
|
if (valueCache.size >= constants_1.PARSE_CACHE_MAX_PER_DESCRIPTOR) {
|
|
319
324
|
const oldestKey = valueCache.keys().next().value;
|
|
@@ -7,6 +7,7 @@ exports.listStyleImage = {
|
|
|
7
7
|
initialValue: 'none',
|
|
8
8
|
type: 0 /* PropertyDescriptorParsingType.VALUE */,
|
|
9
9
|
prefix: false,
|
|
10
|
+
skipCache: true,
|
|
10
11
|
parse: (context, token) => {
|
|
11
12
|
if (token.type === 20 /* TokenType.IDENT_TOKEN */ && token.value === 'none') {
|
|
12
13
|
return null;
|
|
@@ -67,14 +67,17 @@ class EffectsRenderer {
|
|
|
67
67
|
this.ctx.globalCompositeOperation = effect.compositeOperation;
|
|
68
68
|
}
|
|
69
69
|
else if ((0, effects_1.isFilterEffect)(effect)) {
|
|
70
|
-
//
|
|
71
|
-
// drop-shadow()
|
|
72
|
-
//
|
|
73
|
-
// same-origin content
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
// Apply all filters except drop-shadow() via ctx.filter.
|
|
71
|
+
// drop-shadow() is rendered separately through ctx.shadow*
|
|
72
|
+
// because ctx.filter="drop-shadow(...)" taints the canvas
|
|
73
|
+
// even for same-origin content (Chrome, Firefox).
|
|
74
|
+
this.ctx.filter = effect.safeFilterString || 'none';
|
|
75
|
+
if (effect.shadow) {
|
|
76
|
+
this.ctx.shadowOffsetX = effect.shadow.offsetX;
|
|
77
|
+
this.ctx.shadowOffsetY = effect.shadow.offsetY;
|
|
78
|
+
this.ctx.shadowBlur = effect.shadow.blur;
|
|
79
|
+
this.ctx.shadowColor = effect.shadow.color;
|
|
80
|
+
}
|
|
78
81
|
}
|
|
79
82
|
this.activeEffects.push(effect);
|
|
80
83
|
}
|
|
@@ -76,9 +76,23 @@ class BlendEffect {
|
|
|
76
76
|
exports.BlendEffect = BlendEffect;
|
|
77
77
|
class FilterEffect {
|
|
78
78
|
constructor(filterString) {
|
|
79
|
-
this.filterString = filterString;
|
|
80
79
|
this.type = 5 /* EffectType.FILTER */;
|
|
81
80
|
this.target = 2 /* EffectTarget.BACKGROUND_BORDERS */ | 4 /* EffectTarget.CONTENT */;
|
|
81
|
+
// Parse drop-shadow(...) out of the filter string so we can render it
|
|
82
|
+
// via ctx.shadow* instead of ctx.filter (which taints the canvas).
|
|
83
|
+
const dropShadowMatch = filterString.match(/drop-shadow\(\s*([\d.-]+)(px)?\s+([\d.-]+)(px)?\s+([\d.-]+)(px)?\s+(.+?)\s*\)/);
|
|
84
|
+
if (dropShadowMatch) {
|
|
85
|
+
this.shadow = {
|
|
86
|
+
offsetX: parseFloat(dropShadowMatch[1]),
|
|
87
|
+
offsetY: parseFloat(dropShadowMatch[3]),
|
|
88
|
+
blur: parseFloat(dropShadowMatch[5]),
|
|
89
|
+
color: dropShadowMatch[7].trim()
|
|
90
|
+
};
|
|
91
|
+
this.safeFilterString = filterString.replace(/drop-shadow\([^)]+\)\s*/g, '').trim();
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
this.safeFilterString = filterString;
|
|
95
|
+
}
|
|
82
96
|
}
|
|
83
97
|
}
|
|
84
98
|
exports.FilterEffect = FilterEffect;
|
|
@@ -13,6 +13,10 @@ export interface IPropertyDescriptor {
|
|
|
13
13
|
type: PropertyDescriptorParsingType;
|
|
14
14
|
initialValue: string;
|
|
15
15
|
prefix: boolean;
|
|
16
|
+
/** When true, the parse result is never stored in parseCache.
|
|
17
|
+
* Set this for descriptors whose parse() has side effects (e.g.,
|
|
18
|
+
* calling context.cache.addImage) that must run on every render pass. */
|
|
19
|
+
skipCache?: boolean;
|
|
16
20
|
}
|
|
17
21
|
export interface IPropertyIdentValueDescriptor<T> extends IPropertyDescriptor {
|
|
18
22
|
type: PropertyDescriptorParsingType.IDENT_VALUE;
|
|
@@ -57,9 +57,17 @@ export declare class BlendEffect implements IElementEffect {
|
|
|
57
57
|
constructor(mixBlendMode: MixBlendMode);
|
|
58
58
|
}
|
|
59
59
|
export declare class FilterEffect implements IElementEffect {
|
|
60
|
-
readonly filterString: string;
|
|
61
60
|
readonly type: EffectType;
|
|
62
61
|
readonly target: number;
|
|
62
|
+
/** CSS filter string with drop-shadow() stripped (safe for ctx.filter). */
|
|
63
|
+
readonly safeFilterString: string;
|
|
64
|
+
/** Shadow params for drop-shadow(), if present. */
|
|
65
|
+
readonly shadow?: {
|
|
66
|
+
offsetX: number;
|
|
67
|
+
offsetY: number;
|
|
68
|
+
blur: number;
|
|
69
|
+
color: string;
|
|
70
|
+
};
|
|
63
71
|
constructor(filterString: string);
|
|
64
72
|
}
|
|
65
73
|
export declare const isTransformEffect: (effect: IElementEffect) => effect is TransformEffect;
|