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.
@@ -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 image descriptors their parse() has the critical
314
- // side effect of calling context.cache.addImage(url) which must run
315
- // on every render pass (different cache instances per html2canvas call).
316
- const skipCache = descriptor.type === 3 /* PropertyDescriptorParsingType.TYPE_VALUE */ && descriptor.format === 'image';
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;
@@ -8,6 +8,7 @@ exports.backgroundImage = {
8
8
  initialValue: 'none',
9
9
  type: 1 /* PropertyDescriptorParsingType.LIST */,
10
10
  prefix: false,
11
+ skipCache: true,
11
12
  parse: (context, tokens) => {
12
13
  if (tokens.length === 0) {
13
14
  return [];
@@ -8,6 +8,7 @@ exports.borderImageSource = {
8
8
  initialValue: 'none',
9
9
  prefix: false,
10
10
  type: 1 /* PropertyDescriptorParsingType.LIST */,
11
+ skipCache: true,
11
12
  parse: (context, tokens) => {
12
13
  if (tokens.length === 0) {
13
14
  return null;
@@ -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
- // Canvas 2D `ctx.filter` accepts CSS filter strings including
71
- // drop-shadow(). However, using drop-shadow() on the canvas context
72
- // can taint the canvas in some browsers (Chrome, Firefox) even for
73
- // same-origin content. Our filter parser wraps shadows with
74
- // drop-shadow(...) strip that single function so we never set
75
- // a filter that could taint the canvas.
76
- const safe = effect.filterString.replace(/drop-shadow\([^)]+\)\s*/g, '').trim();
77
- this.ctx.filter = safe || 'none';
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;
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "default": "./dist/html2canvas-pro.esm.js"
20
20
  }
21
21
  },
22
- "version": "2.2.1",
22
+ "version": "2.2.3",
23
23
  "author": {
24
24
  "name": "yorickshan",
25
25
  "email": "yorickshan@gmail.com",