html2canvas-pro 2.5.1 → 2.5.2
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/README.md +11 -1
- package/dist/html2canvas-pro.cjs +1835 -1470
- package/dist/html2canvas-pro.cjs.map +1 -1
- package/dist/html2canvas-pro.esm.js +1835 -1470
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +1839 -1471
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +6 -5
- package/dist/types/core/cache-storage.d.ts +6 -2
- package/dist/types/core/constants.d.ts +11 -0
- package/dist/types/core/context.d.ts +9 -1
- package/dist/types/core/features.d.ts +9 -5
- package/dist/types/core/origin-checker.d.ts +7 -4
- package/dist/types/core/validator.d.ts +0 -2
- package/dist/types/css/grouped/background-styles.d.ts +4 -0
- package/dist/types/css/grouped/border-styles.d.ts +4 -0
- package/dist/types/css/grouped/font-styles.d.ts +4 -0
- package/dist/types/css/grouped/layout-styles.d.ts +4 -0
- package/dist/types/css/index.d.ts +4 -0
- package/dist/types/css/property-descriptor.d.ts +11 -3
- package/dist/types/css/property-descriptors/scale.d.ts +9 -0
- package/dist/types/css/property-descriptors/translate.d.ts +10 -0
- package/dist/types/css/syntax/tokenizer.d.ts +8 -0
- package/dist/types/css/types/color-utilities.d.ts +21 -0
- package/dist/types/css/types/functions/color-mix.d.ts +17 -0
- package/dist/types/dom/adopted-styles.d.ts +23 -0
- package/dist/types/dom/document-cloner.d.ts +12 -0
- package/dist/types/dom/dom-normalizer.d.ts +2 -0
- package/dist/types/dom/elements/li-element-container.d.ts +2 -2
- package/dist/types/dom/elements/ol-element-container.d.ts +2 -2
- package/dist/types/dom/elements/select-element-container.d.ts +2 -2
- package/dist/types/dom/elements/textarea-element-container.d.ts +2 -2
- package/dist/types/dom/iframe-mount.d.ts +17 -0
- package/dist/types/dom/node-parser.d.ts +2 -2
- package/dist/types/dom/replaced-elements/canvas-element-container.d.ts +2 -2
- package/dist/types/dom/replaced-elements/iframe-element-container.d.ts +2 -2
- package/dist/types/dom/replaced-elements/image-element-container.d.ts +2 -2
- package/dist/types/dom/replaced-elements/input-element-container.d.ts +2 -2
- package/dist/types/dom/replaced-elements/svg-element-container.d.ts +2 -2
- package/dist/types/dom/slot-cloner.d.ts +10 -0
- package/dist/types/options.d.ts +24 -0
- package/dist/types/render/canvas/border-image-renderer.d.ts +7 -0
- package/dist/types/render/canvas/canvas-renderer.d.ts +2 -3
- package/dist/types/render/canvas/filter-surface.d.ts +37 -11
- package/dist/types/render/canvas/gradient-rasterizer.d.ts +53 -0
- package/dist/types/render/canvas/mask-renderer.d.ts +5 -2
- package/dist/types/render/canvas/text-clip-renderer.d.ts +0 -1
- package/dist/types/render/canvas/text-renderer.d.ts +1 -0
- package/package.json +9 -31
- package/dist/types/render/font-metrics.d.ts +0 -11
- package/dist/types/render/renderer-interface.d.ts +0 -28
|
@@ -1,17 +1,43 @@
|
|
|
1
1
|
export declare class FilterSurfaceError extends Error {
|
|
2
2
|
}
|
|
3
3
|
export declare const releaseSurface: (canvas: HTMLCanvasElement) => void;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A parsed CSS filter chain. Functions keep their declaration order — CSS
|
|
6
|
+
* applies them left to right, and the native canvas backend reproduces that
|
|
7
|
+
* order exactly. Chains containing functions the backends cannot express
|
|
8
|
+
* (url() references, unknown functions) fail parsing and stay on the legacy
|
|
9
|
+
* renderer, where ctx.filter receives the full string natively.
|
|
10
|
+
*/
|
|
11
|
+
export type FilterFunction = {
|
|
12
|
+
kind: 'blur';
|
|
13
|
+
value: number;
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'drop-shadow';
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
5
18
|
blur: number;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
color: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'unitless';
|
|
22
|
+
name: UnitlessFilterName;
|
|
23
|
+
value: number;
|
|
24
|
+
};
|
|
25
|
+
export type UnitlessFilterName = 'brightness' | 'contrast' | 'grayscale' | 'hue-rotate' | 'invert' | 'opacity' | 'saturate' | 'sepia';
|
|
26
|
+
export interface ParsedFilter {
|
|
27
|
+
functions: FilterFunction[];
|
|
12
28
|
}
|
|
13
|
-
export declare function
|
|
14
|
-
|
|
29
|
+
export declare function parseFilterChain(value: string | null): ParsedFilter | null;
|
|
30
|
+
/**
|
|
31
|
+
* Render the chain as a canvas ctx.filter string, scaling all device-space
|
|
32
|
+
* lengths (blur radii, shadow offsets) by the capture scale. Unitless
|
|
33
|
+
* functions and hue angles are scale-invariant.
|
|
34
|
+
*/
|
|
35
|
+
export declare const nativeFilterString: (filter: ParsedFilter, scale: number) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Outset (in CSS pixels) a surface must grow so blur/shadow spillover is not
|
|
38
|
+
* cropped. Unitless functions never spread beyond the bounds. Consecutive
|
|
39
|
+
* blurs compound, so their radii sum.
|
|
40
|
+
*/
|
|
41
|
+
export declare function filterOutset(filter: ParsedFilter): number;
|
|
15
42
|
export declare function supportsNativeFilters(owner?: Document): boolean;
|
|
16
|
-
export declare function renderFilterSurface(source: HTMLCanvasElement, filter:
|
|
17
|
-
export declare function renderSvgFilterSurface(source: HTMLCanvasElement, { blur, shadow }: SimpleFilter, opacity: number, scale: number, signal?: AbortSignal): Promise<HTMLCanvasElement>;
|
|
43
|
+
export declare function renderFilterSurface(source: HTMLCanvasElement, filter: ParsedFilter, opacity: number, scale: number, signal?: AbortSignal): Promise<HTMLCanvasElement>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared gradient rasterisation primitives.
|
|
3
|
+
*
|
|
4
|
+
* Canvas 2D has no repeating gradients and no native elliptical radial
|
|
5
|
+
* gradients, so every gradient painter (background, mask, border-image) needs
|
|
6
|
+
* the same two building blocks:
|
|
7
|
+
*
|
|
8
|
+
* 1. periodic stop stacking — the one-cycle stop list re-added k·period + s
|
|
9
|
+
* for k = 0..cycles-1, clamped to the [0, 1] gradient range;
|
|
10
|
+
* 2. ellipse rasterisation — a circle of radius rx scaled vertically by
|
|
11
|
+
* ry / rx, painted on a 2rx × 2ry offscreen canvas.
|
|
12
|
+
*
|
|
13
|
+
* Centralising them keeps the subtle invariants in one place:
|
|
14
|
+
* - stop positions are normalised against rx (the canvas gradient radius),
|
|
15
|
+
* NOT the diameter — normalising against the diameter halves every
|
|
16
|
+
* absolute-px stop;
|
|
17
|
+
* - the fill must cover the pre-scale circle (fillRect of the rx*2 square),
|
|
18
|
+
* not the post-scale ellipse box — a user-space (2rx × 2ry) rect shrinks
|
|
19
|
+
* vertically under the y-scale and clips the ellipse whenever ry < rx;
|
|
20
|
+
* - outside the ending shape a radial gradient continues with its last
|
|
21
|
+
* colour, which callers must paint across the full area first.
|
|
22
|
+
*/
|
|
23
|
+
import { UnprocessedGradientColorStop, GradientColorStop } from '../../css/types/image';
|
|
24
|
+
export interface StringColorStop {
|
|
25
|
+
stop: number;
|
|
26
|
+
color: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Stack the one-cycle stop list periodically across [0, 1]. Returns null for
|
|
30
|
+
* a degenerate period (all stops clamped to one point) — CSS renders the
|
|
31
|
+
* last colour across the whole area in that case, and callers should paint
|
|
32
|
+
* the last colour instead of stacking.
|
|
33
|
+
*/
|
|
34
|
+
export declare const stackRepeatingStops: (processed: GradientColorStop[]) => StringColorStop[] | null;
|
|
35
|
+
/** Map parsed stops to string-colour stops clamped into the canvas [0, 1] range. */
|
|
36
|
+
export declare const toCanvasStops: (processed: GradientColorStop[]) => StringColorStop[];
|
|
37
|
+
export interface RasterizedRadialGradient {
|
|
38
|
+
/** 2rx × 2ry device-pixel canvas holding the gradient ellipse. */
|
|
39
|
+
canvas: HTMLCanvasElement;
|
|
40
|
+
/** Colour beyond the ending shape (the last stop's colour). */
|
|
41
|
+
lastColor: string;
|
|
42
|
+
rx: number;
|
|
43
|
+
ry: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Rasterise a radial gradient's ending-shape ellipse to an offscreen canvas.
|
|
47
|
+
*
|
|
48
|
+
* The ellipse is a circle of radius rx scaled vertically by ry / rx around
|
|
49
|
+
* the canvas centre, so the offscreen canvas is the ellipse's full 2rx × 2ry
|
|
50
|
+
* bounding box and callers draw it at (centre - rx, centre - ry). Handles the
|
|
51
|
+
* repeating variant by stacking stops across the [0, 1] gradient range.
|
|
52
|
+
*/
|
|
53
|
+
export declare const rasterizeRadialGradient: (ownerDocument: Document, rx: number, ry: number, stops: UnprocessedGradientColorStop[], repeating?: boolean) => RasterizedRadialGradient | null;
|
|
@@ -10,8 +10,11 @@
|
|
|
10
10
|
* always fills the whole area — a mask surface is about alpha coverage, not
|
|
11
11
|
* about what is visible underneath.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Gradient layers share the rasterisation primitives of the background
|
|
14
|
+
* renderer (gradient-rasterizer.ts): repeating gradients stack their stop
|
|
15
|
+
* cycles, and the area beyond a radial gradient's ending shape keeps the
|
|
16
|
+
* last stop's colour. Limitations (v1): mask-mode is alpha-only; layers
|
|
17
|
+
* composite with source-over (≈ the spec-default `add`).
|
|
15
18
|
*/
|
|
16
19
|
import { ICSSImage } from '../../css/types/image';
|
|
17
20
|
import { LengthPercentage } from '../../css/types/length-percentage';
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"default": "./dist/html2canvas-pro.esm.js"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
|
-
"version": "2.5.
|
|
22
|
+
"version": "2.5.2",
|
|
23
23
|
"author": {
|
|
24
24
|
"name": "yorickshan",
|
|
25
25
|
"email": "yorickshan@gmail.com",
|
|
@@ -41,27 +41,18 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@commitlint/cli": "^21.2.3",
|
|
43
43
|
"@commitlint/config-conventional": "^21.2.3",
|
|
44
|
-
"@types/chai": "^5.2.3",
|
|
45
44
|
"@types/express": "^5.0.6",
|
|
46
|
-
"@types/karma": "^6.3.9",
|
|
47
|
-
"@types/mocha": "^10.0.10",
|
|
48
45
|
"@types/node": "^26.6.3",
|
|
49
|
-
"@types/platform": "^1.3.6",
|
|
50
46
|
"@types/pngjs": "^6.0.5",
|
|
51
47
|
"@types/serve-index": "^1.9.4",
|
|
52
48
|
"@typescript-eslint/eslint-plugin": "^8.70.1",
|
|
53
49
|
"@typescript-eslint/parser": "^8.70.1",
|
|
54
50
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
55
51
|
"@vitest/coverage-v8": "^5.0.2",
|
|
56
|
-
"appium-ios-simulator": "^8.2.8",
|
|
57
|
-
"base64-arraybuffer": "1.0.2",
|
|
58
52
|
"body-parser": "^2.3.0",
|
|
59
|
-
"chai": "6.2.2",
|
|
60
|
-
"change-case": "^5.4.4",
|
|
61
53
|
"conventional-changelog": "^8.1.3",
|
|
62
54
|
"conventional-changelog-conventionalcommits": "^10.4.0",
|
|
63
55
|
"cors": "^2.8.6",
|
|
64
|
-
"cz-conventional-changelog": "^3.3.0",
|
|
65
56
|
"eslint": "^10.11.0",
|
|
66
57
|
"eslint-config-prettier": "^10.1.8",
|
|
67
58
|
"eslint-plugin-prettier": "^5.5.6",
|
|
@@ -70,23 +61,11 @@
|
|
|
70
61
|
"glob": "^13.0.6",
|
|
71
62
|
"husky": "^9.1.7",
|
|
72
63
|
"jsdom": "^30.1.1",
|
|
73
|
-
"karma": "^6.4.4",
|
|
74
|
-
"karma-chrome-launcher": "^3.2.0",
|
|
75
|
-
"karma-edge-launcher": "^0.4.2",
|
|
76
|
-
"karma-firefox-launcher": "^2.1.3",
|
|
77
|
-
"karma-ie-launcher": "^1.0.0",
|
|
78
|
-
"karma-junit-reporter": "^2.0.1",
|
|
79
|
-
"karma-mocha": "^2.0.1",
|
|
80
|
-
"karma-safarinative-launcher": "^1.1.0",
|
|
81
64
|
"lint-staged": "^17.6.0",
|
|
82
|
-
"mocha": "^12.0.2",
|
|
83
|
-
"node-simctl": "^8.2.9",
|
|
84
65
|
"pixelmatch": "^7.2.0",
|
|
85
|
-
"platform": "^1.3.6",
|
|
86
66
|
"playwright": "1.63.0",
|
|
87
67
|
"pngjs": "^7.0.0",
|
|
88
68
|
"prettier": "^3.9.9",
|
|
89
|
-
"puppeteer": "^25.12.0",
|
|
90
69
|
"rimraf": "^6.1.3",
|
|
91
70
|
"rolldown": "^1.2.11",
|
|
92
71
|
"serve-index": "^1.9.2",
|
|
@@ -99,10 +78,7 @@
|
|
|
99
78
|
"vitest": "^5.0.2",
|
|
100
79
|
"yargs": "^18.2.0"
|
|
101
80
|
},
|
|
102
|
-
"dependencies": {
|
|
103
|
-
"css-line-break": "^2.1.0",
|
|
104
|
-
"text-segmentation": "^1.0.3"
|
|
105
|
-
},
|
|
81
|
+
"dependencies": {},
|
|
106
82
|
"lint-staged": {
|
|
107
83
|
"{src,tests}/**/*.ts": [
|
|
108
84
|
"prettier --write",
|
|
@@ -111,20 +87,19 @@
|
|
|
111
87
|
},
|
|
112
88
|
"scripts": {
|
|
113
89
|
"prebuild": "rimraf dist/ && rimraf build/ && mkdir -p dist && mkdir -p build",
|
|
114
|
-
"build": "tsc -p tsconfig.build.json && rolldown -c rolldown.config.ts && pnpm build:create-reftest-list &&
|
|
90
|
+
"build": "tsc -p tsconfig.build.json && rolldown -c rolldown.config.ts && pnpm build:create-reftest-list && node scripts/bundle-filter-surface.mjs",
|
|
115
91
|
"build:testrunner": "rolldown -c tests/rolldown.testrunner.config.ts",
|
|
116
92
|
"build:reftest-result-list": "tsx scripts/create-reftest-result-list.ts",
|
|
117
93
|
"build:create-reftest-list": "tsx scripts/create-reftest-list.ts tests/reftests/ignore.txt build/reftests.js",
|
|
118
94
|
"release": "sh scripts/version-upgrade.sh",
|
|
119
95
|
"format": "prettier --write \"{src,tests,scripts}/**/*.ts\"",
|
|
120
96
|
"lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" \"scripts/**/*.ts\" \"scripts/**/*.mjs\" --max-warnings 0",
|
|
121
|
-
"test": "pnpm lint && pnpm unittest && pnpm
|
|
97
|
+
"test": "pnpm lint && pnpm unittest && pnpm reftests:pw",
|
|
122
98
|
"unittest": "vitest run",
|
|
123
99
|
"unittest:coverage": "vitest run --coverage",
|
|
124
100
|
"bench:css-parse": "tsx scripts/benchmarks/css-parse.bench.ts",
|
|
101
|
+
"bench:render": "node scripts/benchmarks/render.bench.mjs",
|
|
125
102
|
"reftests-diff": "mkdir -p tmp/snapshots && vitest run --config vitest.reftest.config.ts",
|
|
126
|
-
"prekarma": "node scripts/ensure-karma-prereqs.mjs",
|
|
127
|
-
"karma": "tsx tests/karma",
|
|
128
103
|
"watch": "rolldown -w",
|
|
129
104
|
"watch:unittest": "vitest",
|
|
130
105
|
"start": "tsx tests/server --port=8080 --cors=8081",
|
|
@@ -133,6 +108,9 @@
|
|
|
133
108
|
"docs:build": "vitepress build docs",
|
|
134
109
|
"docs:preview": "vitepress preview docs",
|
|
135
110
|
"docs:api": "typedoc",
|
|
136
|
-
"docs:api:watch": "typedoc --watch"
|
|
111
|
+
"docs:api:watch": "typedoc --watch",
|
|
112
|
+
"reftests:pw": "tsx tests/reftests-playwright.ts",
|
|
113
|
+
"reftests": "pnpm reftests:pw",
|
|
114
|
+
"prebrowser": "node scripts/ensure-browser-prereqs.mjs"
|
|
137
115
|
}
|
|
138
116
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export interface FontMetric {
|
|
2
|
-
baseline: number;
|
|
3
|
-
middle: number;
|
|
4
|
-
}
|
|
5
|
-
export declare class FontMetrics {
|
|
6
|
-
private readonly _data;
|
|
7
|
-
private readonly _document;
|
|
8
|
-
constructor(document: Document);
|
|
9
|
-
private parseMetrics;
|
|
10
|
-
getMetrics(fontFamily: string, fontSize: string): FontMetric;
|
|
11
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base interface for all specialized renderers.
|
|
3
|
-
* Each renderer is responsible for rendering a specific aspect of an element.
|
|
4
|
-
*
|
|
5
|
-
* @internal This interface is a structural contract; prefer using concrete
|
|
6
|
-
* renderer classes (BackgroundRenderer, BorderRenderer, etc.)
|
|
7
|
-
* directly rather than relying on the generic IRenderer shape.
|
|
8
|
-
*/
|
|
9
|
-
export interface IRenderer {
|
|
10
|
-
render(...args: unknown[]): void | Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Common dependencies required by renderers.
|
|
14
|
-
* RenderConfigurations from canvas-renderer.ts provides a concrete type.
|
|
15
|
-
*/
|
|
16
|
-
export interface RendererDependencies {
|
|
17
|
-
ctx: CanvasRenderingContext2D;
|
|
18
|
-
scale: number;
|
|
19
|
-
options: Record<string, unknown>;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Performance tracking for renderers.
|
|
23
|
-
*/
|
|
24
|
-
export interface RenderMetrics {
|
|
25
|
-
renderCount: number;
|
|
26
|
-
totalTime: number;
|
|
27
|
-
averageTime: number;
|
|
28
|
-
}
|