html2canvas-pro 2.1.0 → 2.1.1
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 +21 -7
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +21 -7
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +3 -3
- package/dist/lib/core/cache-storage.js +2 -2
- package/dist/lib/core/features.js +2 -2
- package/dist/lib/render/canvas/background-renderer.js +6 -0
- package/dist/lib/render/canvas/canvas-renderer.js +5 -1
- package/dist/lib/render/canvas/foreignobject-renderer.js +5 -1
- package/package.json +3 -11
- package/dist/lib/invariant.js +0 -9
- package/dist/types/invariant.d.ts +0 -1
- package/src/__tests__/index.ts +0 -99
- package/src/config.ts +0 -107
- package/src/core/__mocks__/cache-storage.ts +0 -1
- package/src/core/__mocks__/context.ts +0 -19
- package/src/core/__mocks__/features.ts +0 -8
- package/src/core/__mocks__/logger.ts +0 -17
- package/src/core/__tests__/cache-storage.test.ts +0 -205
- package/src/core/__tests__/cache-storage.ts +0 -278
- package/src/core/__tests__/logger.ts +0 -29
- package/src/core/__tests__/validator.ts +0 -359
- package/src/core/bitwise.ts +0 -1
- package/src/core/cache-storage.ts +0 -315
- package/src/core/context.ts +0 -31
- package/src/core/debugger.ts +0 -32
- package/src/core/features.ts +0 -222
- package/src/core/logger.ts +0 -64
- package/src/core/origin-checker.ts +0 -57
- package/src/core/performance-monitor.ts +0 -241
- package/src/core/render-element.ts +0 -272
- package/src/core/util.ts +0 -1
- package/src/core/validator.ts +0 -593
- package/src/css/index.ts +0 -427
- package/src/css/layout/__mocks__/bounds.ts +0 -6
- package/src/css/layout/bounds.ts +0 -79
- package/src/css/layout/text.ts +0 -161
- package/src/css/property-descriptor.ts +0 -49
- package/src/css/property-descriptors/__tests__/background-tests.ts +0 -65
- package/src/css/property-descriptors/__tests__/clip-path.test.ts +0 -280
- package/src/css/property-descriptors/__tests__/font-family.ts +0 -25
- package/src/css/property-descriptors/__tests__/image-rendering-integration.test.ts +0 -153
- package/src/css/property-descriptors/__tests__/image-rendering-performance.test.ts +0 -175
- package/src/css/property-descriptors/__tests__/image-rendering.test.ts +0 -72
- package/src/css/property-descriptors/__tests__/paint-order.ts +0 -87
- package/src/css/property-descriptors/__tests__/text-shadow.ts +0 -94
- package/src/css/property-descriptors/__tests__/transform-tests.ts +0 -18
- package/src/css/property-descriptors/background-clip.ts +0 -30
- package/src/css/property-descriptors/background-color.ts +0 -9
- package/src/css/property-descriptors/background-image.ts +0 -27
- package/src/css/property-descriptors/background-origin.ts +0 -31
- package/src/css/property-descriptors/background-position.ts +0 -38
- package/src/css/property-descriptors/background-repeat.ts +0 -44
- package/src/css/property-descriptors/background-size.ts +0 -27
- package/src/css/property-descriptors/border-color.ts +0 -13
- package/src/css/property-descriptors/border-radius.ts +0 -19
- package/src/css/property-descriptors/border-style.ts +0 -34
- package/src/css/property-descriptors/border-width.ts +0 -20
- package/src/css/property-descriptors/box-shadow.ts +0 -60
- package/src/css/property-descriptors/clip-path.ts +0 -271
- package/src/css/property-descriptors/color.ts +0 -9
- package/src/css/property-descriptors/content.ts +0 -26
- package/src/css/property-descriptors/counter-increment.ts +0 -43
- package/src/css/property-descriptors/counter-reset.ts +0 -36
- package/src/css/property-descriptors/direction.ts +0 -23
- package/src/css/property-descriptors/display.ts +0 -117
- package/src/css/property-descriptors/duration.ts +0 -14
- package/src/css/property-descriptors/float.ts +0 -29
- package/src/css/property-descriptors/font-family.ts +0 -38
- package/src/css/property-descriptors/font-size.ts +0 -9
- package/src/css/property-descriptors/font-style.ts +0 -25
- package/src/css/property-descriptors/font-variant.ts +0 -12
- package/src/css/property-descriptors/font-weight.ts +0 -26
- package/src/css/property-descriptors/image-rendering.ts +0 -33
- package/src/css/property-descriptors/letter-spacing.ts +0 -25
- package/src/css/property-descriptors/line-break.ts +0 -22
- package/src/css/property-descriptors/line-height.ts +0 -22
- package/src/css/property-descriptors/list-style-image.ts +0 -19
- package/src/css/property-descriptors/list-style-position.ts +0 -22
- package/src/css/property-descriptors/list-style-type.ts +0 -179
- package/src/css/property-descriptors/margin.ts +0 -13
- package/src/css/property-descriptors/mix-blend-mode.ts +0 -35
- package/src/css/property-descriptors/object-fit.ts +0 -39
- package/src/css/property-descriptors/opacity.ts +0 -15
- package/src/css/property-descriptors/overflow-wrap.ts +0 -22
- package/src/css/property-descriptors/overflow.ts +0 -34
- package/src/css/property-descriptors/padding.ts +0 -14
- package/src/css/property-descriptors/paint-order.ts +0 -42
- package/src/css/property-descriptors/position.ts +0 -30
- package/src/css/property-descriptors/quotes.ts +0 -57
- package/src/css/property-descriptors/rotate.ts +0 -34
- package/src/css/property-descriptors/text-align.ts +0 -26
- package/src/css/property-descriptors/text-decoration-color.ts +0 -9
- package/src/css/property-descriptors/text-decoration-line.ts +0 -38
- package/src/css/property-descriptors/text-decoration-style.ts +0 -32
- package/src/css/property-descriptors/text-decoration-thickness.ts +0 -30
- package/src/css/property-descriptors/text-overflow.ts +0 -23
- package/src/css/property-descriptors/text-shadow.ts +0 -52
- package/src/css/property-descriptors/text-transform.ts +0 -27
- package/src/css/property-descriptors/text-underline-offset.ts +0 -27
- package/src/css/property-descriptors/transform-origin.ts +0 -29
- package/src/css/property-descriptors/transform.ts +0 -74
- package/src/css/property-descriptors/visibility.ts +0 -25
- package/src/css/property-descriptors/webkit-line-clamp.ts +0 -30
- package/src/css/property-descriptors/webkit-text-stroke-color.ts +0 -8
- package/src/css/property-descriptors/webkit-text-stroke-width.ts +0 -15
- package/src/css/property-descriptors/word-break.ts +0 -25
- package/src/css/property-descriptors/writing-mode.ts +0 -37
- package/src/css/property-descriptors/z-index.ts +0 -27
- package/src/css/syntax/__tests__/tokernizer-tests.ts +0 -29
- package/src/css/syntax/parser.ts +0 -188
- package/src/css/syntax/tokenizer.ts +0 -822
- package/src/css/type-descriptor.ts +0 -7
- package/src/css/types/__tests__/color-tests.ts +0 -147
- package/src/css/types/__tests__/image-tests.ts +0 -239
- package/src/css/types/angle.ts +0 -86
- package/src/css/types/color-math.ts +0 -22
- package/src/css/types/color-spaces/a98.ts +0 -86
- package/src/css/types/color-spaces/p3.ts +0 -92
- package/src/css/types/color-spaces/pro-photo.ts +0 -87
- package/src/css/types/color-spaces/rec2020.ts +0 -90
- package/src/css/types/color-spaces/srgb.ts +0 -87
- package/src/css/types/color-utilities.ts +0 -452
- package/src/css/types/color.ts +0 -485
- package/src/css/types/functions/-prefix-linear-gradient.ts +0 -35
- package/src/css/types/functions/-prefix-radial-gradient.ts +0 -106
- package/src/css/types/functions/-webkit-gradient.ts +0 -69
- package/src/css/types/functions/__tests__/radial-gradient.ts +0 -69
- package/src/css/types/functions/counter.ts +0 -511
- package/src/css/types/functions/gradient.ts +0 -206
- package/src/css/types/functions/linear-gradient.ts +0 -28
- package/src/css/types/functions/radial-gradient.ts +0 -101
- package/src/css/types/image.ts +0 -120
- package/src/css/types/index.ts +0 -1
- package/src/css/types/length-percentage.ts +0 -137
- package/src/css/types/length.ts +0 -7
- package/src/css/types/time.ts +0 -20
- package/src/dom/__mocks__/document-cloner.ts +0 -22
- package/src/dom/__tests__/dom-normalizer.test.ts +0 -133
- package/src/dom/__tests__/element-container.test.ts +0 -129
- package/src/dom/document-cloner.ts +0 -929
- package/src/dom/dom-normalizer.ts +0 -133
- package/src/dom/element-container.ts +0 -75
- package/src/dom/elements/li-element-container.ts +0 -10
- package/src/dom/elements/ol-element-container.ts +0 -12
- package/src/dom/elements/select-element-container.ts +0 -10
- package/src/dom/elements/textarea-element-container.ts +0 -9
- package/src/dom/node-parser.ts +0 -177
- package/src/dom/node-type-guards.ts +0 -70
- package/src/dom/replaced-elements/canvas-element-container.ts +0 -15
- package/src/dom/replaced-elements/iframe-element-container.ts +0 -55
- package/src/dom/replaced-elements/image-element-container.ts +0 -16
- package/src/dom/replaced-elements/index.ts +0 -5
- package/src/dom/replaced-elements/input-element-container.ts +0 -105
- package/src/dom/replaced-elements/pseudo-elements.ts +0 -0
- package/src/dom/replaced-elements/svg-element-container.ts +0 -23
- package/src/dom/text-container.ts +0 -42
- package/src/global.d.ts +0 -19
- package/src/index.ts +0 -82
- package/src/invariant.ts +0 -5
- package/src/options.ts +0 -55
- package/src/render/__tests__/object-fit.test.ts +0 -85
- package/src/render/background.ts +0 -298
- package/src/render/bezier-curve.ts +0 -47
- package/src/render/border.ts +0 -165
- package/src/render/bound-curves.ts +0 -388
- package/src/render/box-sizing.ts +0 -31
- package/src/render/canvas/__tests__/background-renderer.test.ts +0 -72
- package/src/render/canvas/__tests__/border-renderer.test.ts +0 -24
- package/src/render/canvas/__tests__/effects-renderer.test.ts +0 -32
- package/src/render/canvas/__tests__/text-renderer.test.ts +0 -471
- package/src/render/canvas/background-renderer.ts +0 -271
- package/src/render/canvas/border-renderer.ts +0 -224
- package/src/render/canvas/canvas-path.ts +0 -31
- package/src/render/canvas/canvas-renderer.ts +0 -641
- package/src/render/canvas/effects-renderer.ts +0 -130
- package/src/render/canvas/foreignobject-renderer.ts +0 -53
- package/src/render/canvas/text-renderer.ts +0 -700
- package/src/render/effects.ts +0 -75
- package/src/render/font-metrics.ts +0 -72
- package/src/render/object-fit.ts +0 -100
- package/src/render/path.ts +0 -37
- package/src/render/renderer-interface.ts +0 -28
- package/src/render/stacking-context.ts +0 -386
- package/src/render/vector.ts +0 -19
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Effects Renderer
|
|
3
|
-
*
|
|
4
|
-
* Handles rendering effects including:
|
|
5
|
-
* - Opacity effects
|
|
6
|
-
* - Transform effects (matrix transformations)
|
|
7
|
-
* - Clip effects (overflow / border-radius clipping via Path[])
|
|
8
|
-
* - Clip-path effects (CSS clip-path shapes: inset, circle, ellipse, polygon, path)
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
IElementEffect,
|
|
13
|
-
isBlendEffect,
|
|
14
|
-
isClipEffect,
|
|
15
|
-
isClipPathEffect,
|
|
16
|
-
isOpacityEffect,
|
|
17
|
-
isTransformEffect
|
|
18
|
-
} from '../effects';
|
|
19
|
-
import { Path } from '../path';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Dependencies required for EffectsRenderer
|
|
23
|
-
*/
|
|
24
|
-
export interface EffectsRendererDependencies {
|
|
25
|
-
ctx: CanvasRenderingContext2D;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Path callback for clip effects
|
|
30
|
-
*/
|
|
31
|
-
export interface EffectsPathCallback {
|
|
32
|
-
path(paths: Path[]): void;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Effects Renderer
|
|
37
|
-
*
|
|
38
|
-
* Manages rendering effects stack including opacity, transforms, and clipping.
|
|
39
|
-
* Extracted from CanvasRenderer to improve code organization and maintainability.
|
|
40
|
-
*/
|
|
41
|
-
export class EffectsRenderer {
|
|
42
|
-
private readonly ctx: CanvasRenderingContext2D;
|
|
43
|
-
private readonly pathCallback: EffectsPathCallback;
|
|
44
|
-
private readonly activeEffects: IElementEffect[] = [];
|
|
45
|
-
|
|
46
|
-
constructor(deps: EffectsRendererDependencies, pathCallback: EffectsPathCallback) {
|
|
47
|
-
this.ctx = deps.ctx;
|
|
48
|
-
this.pathCallback = pathCallback;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Apply multiple effects
|
|
53
|
-
* Clears existing effects and applies new ones
|
|
54
|
-
*
|
|
55
|
-
* @param effects - Array of effects to apply
|
|
56
|
-
*/
|
|
57
|
-
applyEffects(effects: IElementEffect[]): void {
|
|
58
|
-
// Clear all existing effects
|
|
59
|
-
while (this.activeEffects.length) {
|
|
60
|
-
this.popEffect();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Apply new effects
|
|
64
|
-
effects.forEach((effect) => this.applyEffect(effect));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Apply a single effect
|
|
69
|
-
*
|
|
70
|
-
* @param effect - Effect to apply
|
|
71
|
-
*/
|
|
72
|
-
applyEffect(effect: IElementEffect): void {
|
|
73
|
-
this.ctx.save();
|
|
74
|
-
|
|
75
|
-
if (isOpacityEffect(effect)) {
|
|
76
|
-
// Opacity: multiply into the current global alpha for nested transparency.
|
|
77
|
-
this.ctx.globalAlpha = effect.opacity;
|
|
78
|
-
} else if (isTransformEffect(effect)) {
|
|
79
|
-
// Transform: translate to origin, apply matrix, translate back.
|
|
80
|
-
this.ctx.translate(effect.offsetX, effect.offsetY);
|
|
81
|
-
this.ctx.transform(
|
|
82
|
-
effect.matrix[0],
|
|
83
|
-
effect.matrix[1],
|
|
84
|
-
effect.matrix[2],
|
|
85
|
-
effect.matrix[3],
|
|
86
|
-
effect.matrix[4],
|
|
87
|
-
effect.matrix[5]
|
|
88
|
-
);
|
|
89
|
-
this.ctx.translate(-effect.offsetX, -effect.offsetY);
|
|
90
|
-
} else if (isClipEffect(effect)) {
|
|
91
|
-
// Clip (overflow / border-radius): build path via callback then clip.
|
|
92
|
-
this.pathCallback.path(effect.path);
|
|
93
|
-
this.ctx.clip();
|
|
94
|
-
} else if (isClipPathEffect(effect)) {
|
|
95
|
-
// Clip-path: delegate shape drawing (beginPath … clip()) to the effect.
|
|
96
|
-
effect.applyClip(this.ctx);
|
|
97
|
-
} else if (isBlendEffect(effect)) {
|
|
98
|
-
this.ctx.globalCompositeOperation = effect.compositeOperation;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
this.activeEffects.push(effect);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Remove the most recent effect
|
|
106
|
-
* Restores the canvas state before the effect was applied
|
|
107
|
-
*/
|
|
108
|
-
popEffect(): void {
|
|
109
|
-
this.activeEffects.pop();
|
|
110
|
-
this.ctx.restore();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Get the current number of active effects
|
|
115
|
-
*
|
|
116
|
-
* @returns Number of active effects
|
|
117
|
-
*/
|
|
118
|
-
getActiveEffectCount(): number {
|
|
119
|
-
return this.activeEffects.length;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Check if there are any active effects
|
|
124
|
-
*
|
|
125
|
-
* @returns True if there are active effects
|
|
126
|
-
*/
|
|
127
|
-
hasActiveEffects(): boolean {
|
|
128
|
-
return this.activeEffects.length > 0;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { RenderConfigurations } from './canvas-renderer';
|
|
2
|
-
import { createForeignObjectSVG, loadSerializedSVG } from '../../core/features';
|
|
3
|
-
import { asString } from '../../css/types/color-utilities';
|
|
4
|
-
import { Context } from '../../core/context';
|
|
5
|
-
|
|
6
|
-
export class ForeignObjectRenderer {
|
|
7
|
-
canvas: HTMLCanvasElement;
|
|
8
|
-
ctx: CanvasRenderingContext2D;
|
|
9
|
-
options: RenderConfigurations;
|
|
10
|
-
private readonly context: Context;
|
|
11
|
-
|
|
12
|
-
constructor(context: Context, options: RenderConfigurations) {
|
|
13
|
-
this.context = context;
|
|
14
|
-
this.options = options;
|
|
15
|
-
this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
|
|
16
|
-
this.ctx = this.canvas.getContext('2d') as CanvasRenderingContext2D;
|
|
17
|
-
this.canvas.width = Math.floor(options.width * options.scale);
|
|
18
|
-
this.canvas.height = Math.floor(options.height * options.scale);
|
|
19
|
-
this.canvas.style.width = `${options.width}px`;
|
|
20
|
-
this.canvas.style.height = `${options.height}px`;
|
|
21
|
-
|
|
22
|
-
this.ctx.scale(this.options.scale, this.options.scale);
|
|
23
|
-
this.ctx.translate(-options.x, -options.y);
|
|
24
|
-
this.context.logger.debug(
|
|
25
|
-
`EXPERIMENTAL ForeignObject renderer initialized (${options.width}x${options.height} at ${options.x},${options.y}) with scale ${options.scale}`
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async render(element: HTMLElement): Promise<HTMLCanvasElement> {
|
|
30
|
-
if (this.options.signal?.aborted) {
|
|
31
|
-
throw new DOMException('The operation was aborted.', 'AbortError');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const svg = createForeignObjectSVG(
|
|
35
|
-
this.options.width * this.options.scale,
|
|
36
|
-
this.options.height * this.options.scale,
|
|
37
|
-
this.options.scale,
|
|
38
|
-
this.options.scale,
|
|
39
|
-
element
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const img = await loadSerializedSVG(svg);
|
|
43
|
-
|
|
44
|
-
if (this.options.backgroundColor) {
|
|
45
|
-
this.ctx.fillStyle = asString(this.options.backgroundColor);
|
|
46
|
-
this.ctx.fillRect(0, 0, this.options.width * this.options.scale, this.options.height * this.options.scale);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.ctx.drawImage(img, -this.options.x * this.options.scale, -this.options.y * this.options.scale);
|
|
50
|
-
|
|
51
|
-
return this.canvas;
|
|
52
|
-
}
|
|
53
|
-
}
|