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,133 +0,0 @@
|
|
|
1
|
-
import { strictEqual } from 'assert';
|
|
2
|
-
import { DOMNormalizer } from '../dom-normalizer';
|
|
3
|
-
import { CSSParsedDeclaration } from '../../css';
|
|
4
|
-
import { Context } from '../../core/context';
|
|
5
|
-
import { Bounds } from '../../css/layout/bounds';
|
|
6
|
-
import { Html2CanvasConfig } from '../../config';
|
|
7
|
-
|
|
8
|
-
describe('DOMNormalizer', () => {
|
|
9
|
-
let context: Context;
|
|
10
|
-
let mockElement: HTMLElement;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
const mockWindow = {
|
|
14
|
-
document: {
|
|
15
|
-
createElement: (_name: string) => {
|
|
16
|
-
let _href = '';
|
|
17
|
-
return {
|
|
18
|
-
set href(value: string) {
|
|
19
|
-
_href = value;
|
|
20
|
-
},
|
|
21
|
-
get href() {
|
|
22
|
-
return _href;
|
|
23
|
-
},
|
|
24
|
-
get protocol() {
|
|
25
|
-
return 'http:';
|
|
26
|
-
},
|
|
27
|
-
get hostname() {
|
|
28
|
-
return 'localhost';
|
|
29
|
-
},
|
|
30
|
-
get port() {
|
|
31
|
-
return '';
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
location: { href: 'http://localhost/' },
|
|
37
|
-
getComputedStyle: () => ({
|
|
38
|
-
animationDuration: '1s',
|
|
39
|
-
transform: 'rotate(45deg)',
|
|
40
|
-
rotate: '45deg'
|
|
41
|
-
})
|
|
42
|
-
} as unknown as Window;
|
|
43
|
-
|
|
44
|
-
const config = new Html2CanvasConfig({ window: mockWindow });
|
|
45
|
-
context = new Context(
|
|
46
|
-
{
|
|
47
|
-
logging: false,
|
|
48
|
-
imageTimeout: 15000,
|
|
49
|
-
useCORS: false,
|
|
50
|
-
allowTaint: false
|
|
51
|
-
},
|
|
52
|
-
new Bounds(0, 0, 800, 600),
|
|
53
|
-
config
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
// Create a mock HTMLElement with style property
|
|
57
|
-
mockElement = {
|
|
58
|
-
nodeType: 1, // Node.ELEMENT_NODE
|
|
59
|
-
tagName: 'DIV',
|
|
60
|
-
style: {
|
|
61
|
-
animationDuration: '1s',
|
|
62
|
-
transform: 'rotate(45deg)',
|
|
63
|
-
rotate: '45deg'
|
|
64
|
-
}
|
|
65
|
-
} as unknown as HTMLElement;
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should disable animations on element', () => {
|
|
69
|
-
const styles = new CSSParsedDeclaration(context, {
|
|
70
|
-
animationDuration: '1s',
|
|
71
|
-
transform: null,
|
|
72
|
-
rotate: null
|
|
73
|
-
} as any);
|
|
74
|
-
|
|
75
|
-
DOMNormalizer.normalizeElement(mockElement, styles);
|
|
76
|
-
|
|
77
|
-
strictEqual(mockElement.style.animationDuration, '0s');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should replace transform with identity translate (preserves containing block, Issue #101)', () => {
|
|
81
|
-
const styles = new CSSParsedDeclaration(context, {
|
|
82
|
-
animationDuration: '0s',
|
|
83
|
-
transform: 'rotate(45deg)',
|
|
84
|
-
rotate: null
|
|
85
|
-
} as any);
|
|
86
|
-
|
|
87
|
-
DOMNormalizer.normalizeElement(mockElement, styles);
|
|
88
|
-
|
|
89
|
-
strictEqual(mockElement.style.transform, 'translate(0, 0)');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should replace rotate with 0deg (preserves containing block, Issue #101)', () => {
|
|
93
|
-
const styles = new CSSParsedDeclaration(context, {
|
|
94
|
-
animationDuration: '0s',
|
|
95
|
-
transform: null,
|
|
96
|
-
rotate: '45deg'
|
|
97
|
-
} as any);
|
|
98
|
-
|
|
99
|
-
DOMNormalizer.normalizeElement(mockElement, styles);
|
|
100
|
-
|
|
101
|
-
strictEqual(mockElement.style.rotate, '0deg');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should normalize all properties when all are set', () => {
|
|
105
|
-
const styles = new CSSParsedDeclaration(context, {
|
|
106
|
-
animationDuration: '2s',
|
|
107
|
-
transform: 'rotate(90deg)',
|
|
108
|
-
rotate: '90deg'
|
|
109
|
-
} as any);
|
|
110
|
-
|
|
111
|
-
DOMNormalizer.normalizeElement(mockElement, styles);
|
|
112
|
-
|
|
113
|
-
strictEqual(mockElement.style.animationDuration, '0s');
|
|
114
|
-
strictEqual(mockElement.style.transform, 'translate(0, 0)');
|
|
115
|
-
strictEqual(mockElement.style.rotate, '0deg');
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('should not modify element if it is not an HTMLElement', () => {
|
|
119
|
-
const svgElement = {
|
|
120
|
-
nodeType: 1,
|
|
121
|
-
tagName: 'svg'
|
|
122
|
-
} as unknown as Element;
|
|
123
|
-
|
|
124
|
-
const styles = new CSSParsedDeclaration(context, {
|
|
125
|
-
animationDuration: '1s',
|
|
126
|
-
transform: 'rotate(45deg)',
|
|
127
|
-
rotate: '45deg'
|
|
128
|
-
} as any);
|
|
129
|
-
|
|
130
|
-
// Should not throw and should not try to access style
|
|
131
|
-
DOMNormalizer.normalizeElement(svgElement, styles);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { strictEqual, ok } from 'assert';
|
|
2
|
-
import { ElementContainer, ElementContainerOptions } from '../element-container';
|
|
3
|
-
import { Context } from '../../core/context';
|
|
4
|
-
import { Bounds } from '../../css/layout/bounds';
|
|
5
|
-
import { Html2CanvasConfig } from '../../config';
|
|
6
|
-
|
|
7
|
-
describe('ElementContainer', () => {
|
|
8
|
-
let context: Context;
|
|
9
|
-
let mockElement: HTMLElement;
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
const mockWindow = {
|
|
13
|
-
document: {
|
|
14
|
-
createElement: (_name: string) => {
|
|
15
|
-
let _href = '';
|
|
16
|
-
return {
|
|
17
|
-
set href(value: string) {
|
|
18
|
-
_href = value;
|
|
19
|
-
},
|
|
20
|
-
get href() {
|
|
21
|
-
return _href;
|
|
22
|
-
},
|
|
23
|
-
get protocol() {
|
|
24
|
-
return 'http:';
|
|
25
|
-
},
|
|
26
|
-
get hostname() {
|
|
27
|
-
return 'localhost';
|
|
28
|
-
},
|
|
29
|
-
get port() {
|
|
30
|
-
return '';
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
location: { href: 'http://localhost/' },
|
|
36
|
-
getComputedStyle: () =>
|
|
37
|
-
({
|
|
38
|
-
animationDuration: '1s',
|
|
39
|
-
transform: 'rotate(45deg)',
|
|
40
|
-
rotate: '45deg',
|
|
41
|
-
display: 'block',
|
|
42
|
-
position: 'static'
|
|
43
|
-
}) as CSSStyleDeclaration
|
|
44
|
-
} as unknown as Window;
|
|
45
|
-
|
|
46
|
-
const config = new Html2CanvasConfig({ window: mockWindow });
|
|
47
|
-
context = new Context(
|
|
48
|
-
{
|
|
49
|
-
logging: false,
|
|
50
|
-
imageTimeout: 15000,
|
|
51
|
-
useCORS: false,
|
|
52
|
-
allowTaint: false
|
|
53
|
-
},
|
|
54
|
-
new Bounds(0, 0, 800, 600),
|
|
55
|
-
config
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
mockElement = {
|
|
59
|
-
nodeType: 1,
|
|
60
|
-
tagName: 'DIV',
|
|
61
|
-
style: {
|
|
62
|
-
animationDuration: '1s',
|
|
63
|
-
transform: 'rotate(45deg)',
|
|
64
|
-
rotate: '45deg'
|
|
65
|
-
},
|
|
66
|
-
getAttribute: () => null,
|
|
67
|
-
getBoundingClientRect: () => ({
|
|
68
|
-
left: 0,
|
|
69
|
-
top: 0,
|
|
70
|
-
width: 100,
|
|
71
|
-
height: 100,
|
|
72
|
-
right: 100,
|
|
73
|
-
bottom: 100
|
|
74
|
-
})
|
|
75
|
-
} as unknown as HTMLElement;
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should normalize DOM by default', () => {
|
|
79
|
-
const container = new ElementContainer(context, mockElement);
|
|
80
|
-
|
|
81
|
-
ok(container.styles);
|
|
82
|
-
ok(container.bounds);
|
|
83
|
-
// DOM should be normalized (animationDuration set to '0s')
|
|
84
|
-
strictEqual(mockElement.style.animationDuration, '0s');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should not normalize DOM when normalizeDom is false', () => {
|
|
88
|
-
const originalAnimation = mockElement.style.animationDuration;
|
|
89
|
-
const options: ElementContainerOptions = {
|
|
90
|
-
normalizeDom: false
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const container = new ElementContainer(context, mockElement, options);
|
|
94
|
-
|
|
95
|
-
ok(container.styles);
|
|
96
|
-
ok(container.bounds);
|
|
97
|
-
// DOM should NOT be normalized
|
|
98
|
-
strictEqual(mockElement.style.animationDuration, originalAnimation);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should support explicit normalizeDom: true', () => {
|
|
102
|
-
const options: ElementContainerOptions = {
|
|
103
|
-
normalizeDom: true
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const container = new ElementContainer(context, mockElement, options);
|
|
107
|
-
|
|
108
|
-
ok(container.styles);
|
|
109
|
-
ok(container.bounds);
|
|
110
|
-
strictEqual(mockElement.style.animationDuration, '0s');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should initialize empty arrays for textNodes and elements', () => {
|
|
114
|
-
const container = new ElementContainer(context, mockElement);
|
|
115
|
-
|
|
116
|
-
ok(Array.isArray(container.textNodes));
|
|
117
|
-
ok(Array.isArray(container.elements));
|
|
118
|
-
strictEqual(container.textNodes.length, 0);
|
|
119
|
-
strictEqual(container.elements.length, 0);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should initialize stacking context flags to false', () => {
|
|
123
|
-
const container = new ElementContainer(context, mockElement);
|
|
124
|
-
|
|
125
|
-
strictEqual(container.createsStackingContext, false);
|
|
126
|
-
strictEqual(container.createsRealStackingContext, false);
|
|
127
|
-
strictEqual(container.isListOwner, false);
|
|
128
|
-
});
|
|
129
|
-
});
|