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,105 +0,0 @@
|
|
|
1
|
-
import { ElementContainer } from '../element-container';
|
|
2
|
-
import { BORDER_STYLE } from '../../css/property-descriptors/border-style';
|
|
3
|
-
import { BACKGROUND_CLIP } from '../../css/property-descriptors/background-clip';
|
|
4
|
-
import { BACKGROUND_ORIGIN } from '../../css/property-descriptors/background-origin';
|
|
5
|
-
import { TokenType } from '../../css/syntax/tokenizer';
|
|
6
|
-
import { LengthPercentageTuple } from '../../css/types/length-percentage';
|
|
7
|
-
import { Bounds } from '../../css/layout/bounds';
|
|
8
|
-
import { Context } from '../../core/context';
|
|
9
|
-
|
|
10
|
-
const CHECKBOX_BORDER_RADIUS: LengthPercentageTuple = [
|
|
11
|
-
{
|
|
12
|
-
type: TokenType.DIMENSION_TOKEN,
|
|
13
|
-
flags: 0,
|
|
14
|
-
unit: 'px',
|
|
15
|
-
number: 3
|
|
16
|
-
}
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
const RADIO_BORDER_RADIUS: LengthPercentageTuple = [
|
|
20
|
-
{
|
|
21
|
-
type: TokenType.PERCENTAGE_TOKEN,
|
|
22
|
-
flags: 0,
|
|
23
|
-
number: 50
|
|
24
|
-
}
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
const reformatInputBounds = (bounds: Bounds): Bounds => {
|
|
28
|
-
if (bounds.width > bounds.height) {
|
|
29
|
-
return new Bounds(bounds.left + (bounds.width - bounds.height) / 2, bounds.top, bounds.height, bounds.height);
|
|
30
|
-
} else if (bounds.width < bounds.height) {
|
|
31
|
-
return new Bounds(bounds.left, bounds.top + (bounds.height - bounds.width) / 2, bounds.width, bounds.width);
|
|
32
|
-
}
|
|
33
|
-
return bounds;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const getInputValue = (node: HTMLInputElement): string => {
|
|
37
|
-
const value = node.type === PASSWORD ? new Array(node.value.length + 1).join('\u2022') : node.value;
|
|
38
|
-
|
|
39
|
-
return value.length === 0 ? node.placeholder || '' : value;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const isPlaceholder = (node: HTMLInputElement): boolean => {
|
|
43
|
-
return node.value.length === 0 && !!node.placeholder;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const CHECKBOX = 'checkbox';
|
|
47
|
-
export const RADIO = 'radio';
|
|
48
|
-
export const PASSWORD = 'password';
|
|
49
|
-
export const INPUT_COLOR = 0x2a2a2aff;
|
|
50
|
-
// Default placeholder color (similar to browsers: rgba(117, 117, 117, 1) or #757575)
|
|
51
|
-
export const PLACEHOLDER_COLOR = 0x757575ff;
|
|
52
|
-
|
|
53
|
-
export class InputElementContainer extends ElementContainer {
|
|
54
|
-
readonly type: string;
|
|
55
|
-
readonly checked: boolean;
|
|
56
|
-
readonly value: string;
|
|
57
|
-
readonly isPlaceholder: boolean;
|
|
58
|
-
|
|
59
|
-
constructor(context: Context, input: HTMLInputElement) {
|
|
60
|
-
super(context, input);
|
|
61
|
-
this.type = input.type.toLowerCase();
|
|
62
|
-
this.checked = input.checked;
|
|
63
|
-
this.value = getInputValue(input);
|
|
64
|
-
this.isPlaceholder = isPlaceholder(input);
|
|
65
|
-
|
|
66
|
-
if (this.type === CHECKBOX || this.type === RADIO) {
|
|
67
|
-
this.styles.backgroundColor = 0xdededeff;
|
|
68
|
-
this.styles.borderTopColor =
|
|
69
|
-
this.styles.borderRightColor =
|
|
70
|
-
this.styles.borderBottomColor =
|
|
71
|
-
this.styles.borderLeftColor =
|
|
72
|
-
0xa5a5a5ff;
|
|
73
|
-
this.styles.borderTopWidth =
|
|
74
|
-
this.styles.borderRightWidth =
|
|
75
|
-
this.styles.borderBottomWidth =
|
|
76
|
-
this.styles.borderLeftWidth =
|
|
77
|
-
1;
|
|
78
|
-
this.styles.borderTopStyle =
|
|
79
|
-
this.styles.borderRightStyle =
|
|
80
|
-
this.styles.borderBottomStyle =
|
|
81
|
-
this.styles.borderLeftStyle =
|
|
82
|
-
BORDER_STYLE.SOLID;
|
|
83
|
-
this.styles.backgroundClip = [BACKGROUND_CLIP.BORDER_BOX];
|
|
84
|
-
this.styles.backgroundOrigin = [BACKGROUND_ORIGIN.BORDER_BOX];
|
|
85
|
-
this.bounds = reformatInputBounds(this.bounds);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
switch (this.type) {
|
|
89
|
-
case CHECKBOX:
|
|
90
|
-
this.styles.borderTopRightRadius =
|
|
91
|
-
this.styles.borderTopLeftRadius =
|
|
92
|
-
this.styles.borderBottomRightRadius =
|
|
93
|
-
this.styles.borderBottomLeftRadius =
|
|
94
|
-
CHECKBOX_BORDER_RADIUS;
|
|
95
|
-
break;
|
|
96
|
-
case RADIO:
|
|
97
|
-
this.styles.borderTopRightRadius =
|
|
98
|
-
this.styles.borderTopLeftRadius =
|
|
99
|
-
this.styles.borderBottomRightRadius =
|
|
100
|
-
this.styles.borderBottomLeftRadius =
|
|
101
|
-
RADIO_BORDER_RADIUS;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
File without changes
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ElementContainer } from '../element-container';
|
|
2
|
-
import { parseBounds } from '../../css/layout/bounds';
|
|
3
|
-
import { Context } from '../../core/context';
|
|
4
|
-
|
|
5
|
-
export class SVGElementContainer extends ElementContainer {
|
|
6
|
-
svg: string;
|
|
7
|
-
intrinsicWidth: number;
|
|
8
|
-
intrinsicHeight: number;
|
|
9
|
-
|
|
10
|
-
constructor(context: Context, img: SVGSVGElement) {
|
|
11
|
-
super(context, img);
|
|
12
|
-
const s = new XMLSerializer();
|
|
13
|
-
const bounds = parseBounds(context, img);
|
|
14
|
-
img.setAttribute('width', `${bounds.width}px`);
|
|
15
|
-
img.setAttribute('height', `${bounds.height}px`);
|
|
16
|
-
|
|
17
|
-
this.svg = `data:image/svg+xml,${encodeURIComponent(s.serializeToString(img))}`;
|
|
18
|
-
this.intrinsicWidth = img.width.baseVal.value;
|
|
19
|
-
this.intrinsicHeight = img.height.baseVal.value;
|
|
20
|
-
|
|
21
|
-
this.context.cache.addImage(this.svg);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { CSSParsedDeclaration } from '../css/index';
|
|
2
|
-
import { TEXT_TRANSFORM } from '../css/property-descriptors/text-transform';
|
|
3
|
-
import { parseTextBounds, TextBounds } from '../css/layout/text';
|
|
4
|
-
import { Context } from '../core/context';
|
|
5
|
-
|
|
6
|
-
export class TextContainer {
|
|
7
|
-
text: string;
|
|
8
|
-
textBounds: TextBounds[];
|
|
9
|
-
|
|
10
|
-
constructor(context: Context, node: Text, styles: CSSParsedDeclaration) {
|
|
11
|
-
this.text = transform(node.data, styles.textTransform);
|
|
12
|
-
// Range offsets below are based on transformed text; keep the node in sync
|
|
13
|
-
// when casing changes string length, for example "ß".toUpperCase() === "SS".
|
|
14
|
-
if (this.text.length !== node.data.length) {
|
|
15
|
-
node.data = this.text;
|
|
16
|
-
}
|
|
17
|
-
this.textBounds = parseTextBounds(context, this.text, styles, node);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const transform = (text: string, transform: TEXT_TRANSFORM) => {
|
|
22
|
-
switch (transform) {
|
|
23
|
-
case TEXT_TRANSFORM.LOWERCASE:
|
|
24
|
-
return text.toLowerCase();
|
|
25
|
-
case TEXT_TRANSFORM.CAPITALIZE:
|
|
26
|
-
return text.replace(CAPITALIZE, capitalize);
|
|
27
|
-
case TEXT_TRANSFORM.UPPERCASE:
|
|
28
|
-
return text.toUpperCase();
|
|
29
|
-
default:
|
|
30
|
-
return text;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const CAPITALIZE = /(^|\s|:|-|\(|\))([a-z])/g;
|
|
35
|
-
|
|
36
|
-
const capitalize = (m: string, p1: string, p2: string) => {
|
|
37
|
-
if (m.length > 0) {
|
|
38
|
-
return p1 + p2.toUpperCase();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return m;
|
|
42
|
-
};
|
package/src/global.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
interface CSSStyleDeclaration {
|
|
2
|
-
textDecorationColor: string;
|
|
3
|
-
textDecorationLine: string;
|
|
4
|
-
textDecorationStyle: string;
|
|
5
|
-
textDecorationThickness: string;
|
|
6
|
-
textUnderlineOffset: string;
|
|
7
|
-
overflowWrap: string;
|
|
8
|
-
rotate: string;
|
|
9
|
-
webkitLineClamp: string;
|
|
10
|
-
webkitBoxOrient: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface DocumentType extends Node, ChildNode {
|
|
14
|
-
readonly internalSubset: string | null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface Document {
|
|
18
|
-
fonts: any;
|
|
19
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { Html2CanvasConfig, ConfigOptions, setDefaultConfig } from './config';
|
|
2
|
-
import { createDefaultValidator, Validator, ValidationResult } from './core/validator';
|
|
3
|
-
import { PerformanceMonitor } from './core/performance-monitor';
|
|
4
|
-
import { renderElement } from './core/render-element';
|
|
5
|
-
import type { Options } from './options';
|
|
6
|
-
|
|
7
|
-
export type { Options };
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Renders an HTML element to a `<canvas>` element.
|
|
11
|
-
*
|
|
12
|
-
* The function clones the target element and its subtree into a hidden iframe,
|
|
13
|
-
* resolves all computed styles, and paints the result onto a canvas —
|
|
14
|
-
* producing a visual snapshot of the DOM as it appears in the browser.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* import html2canvas from 'html2canvas-pro';
|
|
19
|
-
*
|
|
20
|
-
* const canvas = await html2canvas(document.body, {
|
|
21
|
-
* backgroundColor: '#ffffff',
|
|
22
|
-
* scale: 2,
|
|
23
|
-
* useCORS: true
|
|
24
|
-
* });
|
|
25
|
-
* document.body.appendChild(canvas);
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @param element - The root HTMLElement to render.
|
|
29
|
-
* @param options - Rendering options.
|
|
30
|
-
* @param config - Advanced configuration. In most cases this is auto-created;
|
|
31
|
-
* only pass it if you need to share a cache across multiple calls.
|
|
32
|
-
* @returns A promise that resolves to the rendered HTMLCanvasElement.
|
|
33
|
-
*
|
|
34
|
-
* @throws {Error} If the element is not attached to a document.
|
|
35
|
-
* @throws {DOMException} If an {@link Options.signal|AbortSignal} was provided and the operation was aborted.
|
|
36
|
-
*/
|
|
37
|
-
const html2canvas = (
|
|
38
|
-
element: HTMLElement,
|
|
39
|
-
options: Partial<Options> = {},
|
|
40
|
-
config?: Html2CanvasConfig
|
|
41
|
-
): Promise<HTMLCanvasElement> => {
|
|
42
|
-
const finalConfig =
|
|
43
|
-
config ||
|
|
44
|
-
Html2CanvasConfig.fromElement(element, {
|
|
45
|
-
cspNonce: options.cspNonce,
|
|
46
|
-
cache: options.cache
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
return renderElement(element, options, finalConfig);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Set CSP nonce for inline styles.
|
|
54
|
-
*
|
|
55
|
-
* @deprecated Since 2.0.0. Pass `cspNonce` in options instead:
|
|
56
|
-
* `html2canvas(element, { cspNonce: '...' })`
|
|
57
|
-
*/
|
|
58
|
-
const setCspNonce = (nonce: string) => {
|
|
59
|
-
console.warn(
|
|
60
|
-
'[html2canvas-pro] setCspNonce is deprecated. ' +
|
|
61
|
-
'Pass cspNonce in options instead: html2canvas(element, { cspNonce: "..." })'
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
if (typeof window !== 'undefined') {
|
|
65
|
-
setDefaultConfig(new Html2CanvasConfig({ window, cspNonce: nonce }));
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
html2canvas.setCspNonce = setCspNonce;
|
|
70
|
-
|
|
71
|
-
export default html2canvas;
|
|
72
|
-
export {
|
|
73
|
-
html2canvas,
|
|
74
|
-
Html2CanvasConfig,
|
|
75
|
-
ConfigOptions,
|
|
76
|
-
Validator,
|
|
77
|
-
ValidationResult,
|
|
78
|
-
createDefaultValidator,
|
|
79
|
-
PerformanceMonitor
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export { IMAGE_RENDERING } from './css/property-descriptors/image-rendering';
|
package/src/invariant.ts
DELETED
package/src/options.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { CloneOptions, WindowOptions } from './dom/document-cloner';
|
|
2
|
-
import { RenderOptions } from './render/canvas/canvas-renderer';
|
|
3
|
-
import { ContextOptions } from './core/context';
|
|
4
|
-
import { Validator } from './core/validator';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Options passed to {@link html2canvas}.
|
|
8
|
-
*
|
|
9
|
-
* Combines clone, window, render, and context configuration into a single
|
|
10
|
-
* options object. All properties are optional.
|
|
11
|
-
*/
|
|
12
|
-
export type Options = CloneOptions &
|
|
13
|
-
WindowOptions &
|
|
14
|
-
RenderOptions &
|
|
15
|
-
ContextOptions & {
|
|
16
|
-
/** Background color for the resulting canvas. Use `null` for transparent. */
|
|
17
|
-
backgroundColor: string | null;
|
|
18
|
-
/** Use foreignObject rendering (SVG-based) instead of the default Canvas 2D pipeline. */
|
|
19
|
-
foreignObjectRendering: boolean;
|
|
20
|
-
/** Whether to remove the cloned iframe after rendering. @default true */
|
|
21
|
-
removeContainer?: boolean;
|
|
22
|
-
/** CSP nonce for inline style elements. */
|
|
23
|
-
cspNonce?: string;
|
|
24
|
-
/** Custom input validator. */
|
|
25
|
-
validator?: Validator;
|
|
26
|
-
/** Skip pre-render validation of element and options. */
|
|
27
|
-
skipValidation?: boolean;
|
|
28
|
-
/** Enable performance monitoring and log a timing summary. */
|
|
29
|
-
enablePerformanceMonitoring?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* An AbortSignal that can be used to cancel an in-progress render.
|
|
32
|
-
* When the signal is aborted, the returned promise rejects with an
|
|
33
|
-
* `AbortError` DOMException.
|
|
34
|
-
*/
|
|
35
|
-
signal?: AbortSignal;
|
|
36
|
-
/**
|
|
37
|
-
* Enable/disable image smoothing (anti-aliasing) globally.
|
|
38
|
-
* - `false`: Pixel-perfect rendering for pixel art, sprites, and retro graphics
|
|
39
|
-
* - `true`: Smooth rendering for photos and high-quality images
|
|
40
|
-
* - CSS `image-rendering` property on individual elements takes precedence
|
|
41
|
-
* @default true (browser default)
|
|
42
|
-
*/
|
|
43
|
-
imageSmoothing?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Image smoothing quality level when imageSmoothing is enabled.
|
|
46
|
-
* - `'low'`: Faster, lower quality (good for preview)
|
|
47
|
-
* - `'medium'`: Balanced (default in most browsers)
|
|
48
|
-
* - `'high'`: Slower, best quality (good for final export)
|
|
49
|
-
*
|
|
50
|
-
* Browser support: Chrome 54+, Firefox 94+, Safari 17+
|
|
51
|
-
* Falls back gracefully in older browsers.
|
|
52
|
-
* @default browser default (usually 'low' or 'medium')
|
|
53
|
-
*/
|
|
54
|
-
imageSmoothingQuality?: 'low' | 'medium' | 'high';
|
|
55
|
-
};
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { deepStrictEqual } from 'assert';
|
|
2
|
-
import { OBJECT_FIT } from '../../css/property-descriptors/object-fit';
|
|
3
|
-
import { calculateObjectFitRendering } from '../object-fit';
|
|
4
|
-
|
|
5
|
-
describe('calculateObjectFitRendering', () => {
|
|
6
|
-
const box = { left: 10, top: 20, width: 100, height: 50 };
|
|
7
|
-
|
|
8
|
-
it('should preserve fill rendering by default', () => {
|
|
9
|
-
deepStrictEqual(calculateObjectFitRendering(200, 100, box, OBJECT_FIT.FILL), {
|
|
10
|
-
sx: 0,
|
|
11
|
-
sy: 0,
|
|
12
|
-
sw: 200,
|
|
13
|
-
sh: 100,
|
|
14
|
-
dx: 10,
|
|
15
|
-
dy: 20,
|
|
16
|
-
dw: 100,
|
|
17
|
-
dh: 50
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should calculate contain destination rectangle', () => {
|
|
22
|
-
deepStrictEqual(calculateObjectFitRendering(100, 100, box, OBJECT_FIT.CONTAIN), {
|
|
23
|
-
sx: 0,
|
|
24
|
-
sy: 0,
|
|
25
|
-
sw: 100,
|
|
26
|
-
sh: 100,
|
|
27
|
-
dx: 35,
|
|
28
|
-
dy: 20,
|
|
29
|
-
dw: 50,
|
|
30
|
-
dh: 50
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should calculate cover source rectangle', () => {
|
|
35
|
-
deepStrictEqual(calculateObjectFitRendering(100, 100, box, OBJECT_FIT.COVER), {
|
|
36
|
-
sx: 0,
|
|
37
|
-
sy: 25,
|
|
38
|
-
sw: 100,
|
|
39
|
-
sh: 50,
|
|
40
|
-
dx: 10,
|
|
41
|
-
dy: 20,
|
|
42
|
-
dw: 100,
|
|
43
|
-
dh: 50
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should calculate none with centered clipping', () => {
|
|
48
|
-
deepStrictEqual(calculateObjectFitRendering(200, 100, box, OBJECT_FIT.NONE), {
|
|
49
|
-
sx: 50,
|
|
50
|
-
sy: 25,
|
|
51
|
-
sw: 100,
|
|
52
|
-
sh: 50,
|
|
53
|
-
dx: 10,
|
|
54
|
-
dy: 20,
|
|
55
|
-
dw: 100,
|
|
56
|
-
dh: 50
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should scale down using contain logic when image is larger than box', () => {
|
|
61
|
-
deepStrictEqual(calculateObjectFitRendering(200, 50, box, OBJECT_FIT.SCALE_DOWN), {
|
|
62
|
-
sx: 0,
|
|
63
|
-
sy: 0,
|
|
64
|
-
sw: 200,
|
|
65
|
-
sh: 50,
|
|
66
|
-
dx: 10,
|
|
67
|
-
dy: 32.5,
|
|
68
|
-
dw: 100,
|
|
69
|
-
dh: 25
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should scale down using none logic when image is smaller than box', () => {
|
|
74
|
-
deepStrictEqual(calculateObjectFitRendering(60, 30, box, OBJECT_FIT.SCALE_DOWN), {
|
|
75
|
-
sx: 0,
|
|
76
|
-
sy: 0,
|
|
77
|
-
sw: 60,
|
|
78
|
-
sh: 30,
|
|
79
|
-
dx: 30,
|
|
80
|
-
dy: 30,
|
|
81
|
-
dw: 60,
|
|
82
|
-
dh: 30
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
});
|