html2canvas-pro 1.6.6 → 2.0.0
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 +1 -0
- package/demo/image-smoothing-demo.html +256 -0
- package/demo/refactoring-test.html +602 -0
- package/dist/html2canvas-pro.esm.js +2846 -1238
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +2849 -1237
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +5 -4
- package/dist/lib/__tests__/index.js +8 -2
- package/dist/lib/__tests__/index.js.map +1 -1
- package/dist/lib/config.js +72 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/core/__tests__/cache-storage.js +6 -3
- package/dist/lib/core/__tests__/cache-storage.js.map +1 -1
- package/dist/lib/core/__tests__/cache-storage.test.js +158 -0
- package/dist/lib/core/__tests__/cache-storage.test.js.map +1 -0
- package/dist/lib/core/__tests__/validator.js +296 -0
- package/dist/lib/core/__tests__/validator.js.map +1 -0
- package/dist/lib/core/cache-storage.js +130 -11
- package/dist/lib/core/cache-storage.js.map +1 -1
- package/dist/lib/core/context.js +5 -2
- package/dist/lib/core/context.js.map +1 -1
- package/dist/lib/core/debugger.js +3 -0
- package/dist/lib/core/debugger.js.map +1 -1
- package/dist/lib/core/origin-checker.js +54 -0
- package/dist/lib/core/origin-checker.js.map +1 -0
- package/dist/lib/core/performance-monitor.js +208 -0
- package/dist/lib/core/performance-monitor.js.map +1 -0
- package/dist/lib/core/validator.js +501 -0
- package/dist/lib/core/validator.js.map +1 -0
- package/dist/lib/css/index.js +2 -0
- package/dist/lib/css/index.js.map +1 -1
- package/dist/lib/css/property-descriptors/__tests__/background-tests.js +7 -1
- package/dist/lib/css/property-descriptors/__tests__/background-tests.js.map +1 -1
- package/dist/lib/css/property-descriptors/__tests__/image-rendering-integration.test.js +142 -0
- package/dist/lib/css/property-descriptors/__tests__/image-rendering-integration.test.js.map +1 -0
- package/dist/lib/css/property-descriptors/__tests__/image-rendering-performance.test.js +167 -0
- package/dist/lib/css/property-descriptors/__tests__/image-rendering-performance.test.js.map +1 -0
- package/dist/lib/css/property-descriptors/__tests__/image-rendering.test.js +61 -0
- package/dist/lib/css/property-descriptors/__tests__/image-rendering.test.js.map +1 -0
- package/dist/lib/css/property-descriptors/image-rendering.js +34 -0
- package/dist/lib/css/property-descriptors/image-rendering.js.map +1 -0
- package/dist/lib/css/types/__tests__/image-tests.js +7 -1
- package/dist/lib/css/types/__tests__/image-tests.js.map +1 -1
- package/dist/lib/css/types/color-math.js +26 -0
- package/dist/lib/css/types/color-math.js.map +1 -0
- package/dist/lib/css/types/color-spaces/srgb.js +6 -6
- package/dist/lib/css/types/color-spaces/srgb.js.map +1 -1
- package/dist/lib/css/types/color-utilities.js +13 -22
- package/dist/lib/css/types/color-utilities.js.map +1 -1
- package/dist/lib/dom/__tests__/dom-normalizer.test.js +113 -0
- package/dist/lib/dom/__tests__/dom-normalizer.test.js.map +1 -0
- package/dist/lib/dom/__tests__/element-container.test.js +109 -0
- package/dist/lib/dom/__tests__/element-container.test.js.map +1 -0
- package/dist/lib/dom/document-cloner.js +152 -11
- package/dist/lib/dom/document-cloner.js.map +1 -1
- package/dist/lib/dom/dom-normalizer.js +80 -0
- package/dist/lib/dom/dom-normalizer.js.map +1 -0
- package/dist/lib/dom/element-container.js +32 -15
- package/dist/lib/dom/element-container.js.map +1 -1
- package/dist/lib/dom/node-parser.js +16 -20
- package/dist/lib/dom/node-parser.js.map +1 -1
- package/dist/lib/dom/node-type-guards.js +44 -0
- package/dist/lib/dom/node-type-guards.js.map +1 -0
- package/dist/lib/dom/replaced-elements/iframe-element-container.js +5 -4
- package/dist/lib/dom/replaced-elements/iframe-element-container.js.map +1 -1
- package/dist/lib/index.js +148 -41
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/render/canvas/__tests__/background-renderer.test.js +65 -0
- package/dist/lib/render/canvas/__tests__/background-renderer.test.js.map +1 -0
- package/dist/lib/render/canvas/__tests__/border-renderer.test.js +23 -0
- package/dist/lib/render/canvas/__tests__/border-renderer.test.js.map +1 -0
- package/dist/lib/render/canvas/__tests__/effects-renderer.test.js +30 -0
- package/dist/lib/render/canvas/__tests__/effects-renderer.test.js.map +1 -0
- package/dist/lib/render/canvas/__tests__/text-renderer.test.js +63 -0
- package/dist/lib/render/canvas/__tests__/text-renderer.test.js.map +1 -0
- package/dist/lib/render/canvas/background-renderer.js +222 -0
- package/dist/lib/render/canvas/background-renderer.js.map +1 -0
- package/dist/lib/render/canvas/border-renderer.js +185 -0
- package/dist/lib/render/canvas/border-renderer.js.map +1 -0
- package/dist/lib/render/canvas/canvas-renderer.js +61 -689
- package/dist/lib/render/canvas/canvas-renderer.js.map +1 -1
- package/dist/lib/render/canvas/effects-renderer.js +89 -0
- package/dist/lib/render/canvas/effects-renderer.js.map +1 -0
- package/dist/lib/render/canvas/text-renderer.js +508 -0
- package/dist/lib/render/canvas/text-renderer.js.map +1 -0
- package/dist/lib/render/renderer-interface.js +3 -0
- package/dist/lib/render/renderer-interface.js.map +1 -0
- package/dist/types/config.d.ts +54 -0
- package/dist/types/core/__tests__/cache-storage.test.d.ts +1 -0
- package/dist/types/core/__tests__/validator.d.ts +1 -0
- package/dist/types/core/cache-storage.d.ts +42 -1
- package/dist/types/core/context.d.ts +5 -1
- package/dist/types/core/origin-checker.d.ts +33 -0
- package/dist/types/core/performance-monitor.d.ts +131 -0
- package/dist/types/core/validator.d.ts +132 -0
- package/dist/types/css/index.d.ts +2 -0
- package/dist/types/css/property-descriptors/__tests__/image-rendering-integration.test.d.ts +1 -0
- package/dist/types/css/property-descriptors/__tests__/image-rendering-performance.test.d.ts +1 -0
- package/dist/types/css/property-descriptors/__tests__/image-rendering.test.d.ts +1 -0
- package/dist/types/css/property-descriptors/image-rendering.d.ts +8 -0
- package/dist/types/css/types/color-math.d.ts +12 -0
- package/dist/types/css/types/color-utilities.d.ts +2 -3
- package/dist/types/dom/__tests__/dom-normalizer.test.d.ts +1 -0
- package/dist/types/dom/__tests__/element-container.test.d.ts +1 -0
- package/dist/types/dom/document-cloner.d.ts +46 -0
- package/dist/types/dom/dom-normalizer.d.ts +43 -0
- package/dist/types/dom/element-container.d.ts +20 -1
- package/dist/types/dom/node-parser.d.ts +2 -7
- package/dist/types/dom/node-type-guards.d.ts +33 -0
- package/dist/types/dom/replaced-elements/iframe-element-container.d.ts +4 -1
- package/dist/types/index.d.ts +48 -3
- package/dist/types/render/canvas/__tests__/background-renderer.test.d.ts +1 -0
- package/dist/types/render/canvas/__tests__/border-renderer.test.d.ts +1 -0
- package/dist/types/render/canvas/__tests__/effects-renderer.test.d.ts +1 -0
- package/dist/types/render/canvas/__tests__/text-renderer.test.d.ts +1 -0
- package/dist/types/render/canvas/background-renderer.d.ts +87 -0
- package/dist/types/render/canvas/border-renderer.d.ts +67 -0
- package/dist/types/render/canvas/canvas-renderer.d.ts +19 -23
- package/dist/types/render/canvas/effects-renderer.d.ts +64 -0
- package/dist/types/render/canvas/text-renderer.d.ts +57 -0
- package/dist/types/render/renderer-interface.d.ts +26 -0
- package/package.json +2 -1
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
import { Context } from './context';
|
|
2
|
+
/**
|
|
3
|
+
* CacheStorage (Deprecated static methods)
|
|
4
|
+
*
|
|
5
|
+
* @deprecated The static methods of CacheStorage are deprecated.
|
|
6
|
+
* Use OriginChecker class instead for instance-based origin checking.
|
|
7
|
+
*
|
|
8
|
+
* For backward compatibility, these methods remain but should not be used in new code.
|
|
9
|
+
*/
|
|
2
10
|
export declare class CacheStorage {
|
|
3
11
|
private static _link?;
|
|
4
12
|
private static _origin;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use OriginChecker.getOrigin() instead
|
|
15
|
+
*/
|
|
5
16
|
static getOrigin(url: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Use OriginChecker.isSameOrigin() instead
|
|
19
|
+
*/
|
|
6
20
|
static isSameOrigin(src: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated No longer needed. OriginChecker is created per Context.
|
|
23
|
+
*/
|
|
7
24
|
static setContext(window: Window): void;
|
|
8
25
|
}
|
|
9
26
|
export interface ResourceOptions {
|
|
@@ -12,14 +29,38 @@ export interface ResourceOptions {
|
|
|
12
29
|
allowTaint: boolean;
|
|
13
30
|
proxy?: string;
|
|
14
31
|
customIsSameOrigin?: (this: void, src: string, oldFn: (src: string) => boolean) => boolean | Promise<boolean>;
|
|
32
|
+
maxCacheSize?: number;
|
|
15
33
|
}
|
|
16
34
|
export declare class Cache {
|
|
17
35
|
private readonly context;
|
|
18
36
|
private readonly _options;
|
|
19
37
|
private readonly _cache;
|
|
38
|
+
private readonly maxSize;
|
|
39
|
+
private readonly _pendingOperations;
|
|
20
40
|
constructor(context: Context, _options: ResourceOptions);
|
|
21
41
|
addImage(src: string): Promise<void>;
|
|
22
|
-
|
|
42
|
+
private _addImageInternal;
|
|
43
|
+
match(src: string): Promise<any> | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Set a value in cache with LRU eviction
|
|
46
|
+
*/
|
|
47
|
+
private set;
|
|
48
|
+
/**
|
|
49
|
+
* Evict least recently used entry
|
|
50
|
+
*/
|
|
51
|
+
private evictLRU;
|
|
52
|
+
/**
|
|
53
|
+
* Get cache size
|
|
54
|
+
*/
|
|
55
|
+
size(): number;
|
|
56
|
+
/**
|
|
57
|
+
* Get max cache size
|
|
58
|
+
*/
|
|
59
|
+
getMaxSize(): number;
|
|
60
|
+
/**
|
|
61
|
+
* Clear all cache entries
|
|
62
|
+
*/
|
|
63
|
+
clear(): void;
|
|
23
64
|
private loadImage;
|
|
24
65
|
private has;
|
|
25
66
|
keys(): Promise<string[]>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Logger } from './logger';
|
|
2
2
|
import { Cache, ResourceOptions } from './cache-storage';
|
|
3
3
|
import { Bounds } from '../css/layout/bounds';
|
|
4
|
+
import { OriginChecker } from './origin-checker';
|
|
5
|
+
import { Html2CanvasConfig } from '../config';
|
|
4
6
|
export type ContextOptions = {
|
|
5
7
|
logging: boolean;
|
|
6
8
|
cache?: Cache;
|
|
@@ -10,6 +12,8 @@ export declare class Context {
|
|
|
10
12
|
private readonly instanceName;
|
|
11
13
|
readonly logger: Logger;
|
|
12
14
|
readonly cache: Cache;
|
|
15
|
+
readonly originChecker: OriginChecker;
|
|
16
|
+
readonly config: Html2CanvasConfig;
|
|
13
17
|
private static instanceCount;
|
|
14
|
-
constructor(options: ContextOptions, windowBounds: Bounds);
|
|
18
|
+
constructor(options: ContextOptions, windowBounds: Bounds, config: Html2CanvasConfig);
|
|
15
19
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Origin Checker
|
|
3
|
+
*
|
|
4
|
+
* Provides origin checking functionality without global static state.
|
|
5
|
+
* Each instance maintains its own anchor element and origin reference.
|
|
6
|
+
*
|
|
7
|
+
* Replaces the static methods in CacheStorage with instance-based approach.
|
|
8
|
+
*/
|
|
9
|
+
export declare class OriginChecker {
|
|
10
|
+
private readonly link;
|
|
11
|
+
private readonly origin;
|
|
12
|
+
constructor(window: Window);
|
|
13
|
+
/**
|
|
14
|
+
* Get the origin (protocol + hostname + port) of a URL
|
|
15
|
+
*
|
|
16
|
+
* @param url - URL to parse
|
|
17
|
+
* @returns Origin string (e.g., "https://example.com:8080")
|
|
18
|
+
*/
|
|
19
|
+
getOrigin(url: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Check if a URL is from the same origin as the context
|
|
22
|
+
*
|
|
23
|
+
* @param src - URL to check
|
|
24
|
+
* @returns true if same origin, false otherwise
|
|
25
|
+
*/
|
|
26
|
+
isSameOrigin(src: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Get the current context origin
|
|
29
|
+
*
|
|
30
|
+
* @returns The origin of the context window
|
|
31
|
+
*/
|
|
32
|
+
getContextOrigin(): string;
|
|
33
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Context } from './context';
|
|
2
|
+
/**
|
|
3
|
+
* Performance Metric
|
|
4
|
+
*
|
|
5
|
+
* Represents a single performance measurement
|
|
6
|
+
*/
|
|
7
|
+
export interface PerformanceMetric {
|
|
8
|
+
name: string;
|
|
9
|
+
startTime: number;
|
|
10
|
+
endTime?: number;
|
|
11
|
+
duration?: number;
|
|
12
|
+
metadata?: Record<string, any>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Performance Summary
|
|
16
|
+
*
|
|
17
|
+
* Aggregated performance data
|
|
18
|
+
*/
|
|
19
|
+
export interface PerformanceSummary {
|
|
20
|
+
totalDuration: number;
|
|
21
|
+
metrics: PerformanceMetric[];
|
|
22
|
+
breakdown: Array<{
|
|
23
|
+
name: string;
|
|
24
|
+
duration: number;
|
|
25
|
+
percentage: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Performance Monitor
|
|
30
|
+
*
|
|
31
|
+
* Tracks performance metrics throughout the rendering pipeline.
|
|
32
|
+
* Provides insights into where time is spent during rendering.
|
|
33
|
+
*
|
|
34
|
+
* Usage:
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const monitor = new PerformanceMonitor(context);
|
|
37
|
+
*
|
|
38
|
+
* monitor.start('clone');
|
|
39
|
+
* await cloneDocument();
|
|
40
|
+
* monitor.end('clone');
|
|
41
|
+
*
|
|
42
|
+
* const summary = monitor.getSummary();
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class PerformanceMonitor {
|
|
46
|
+
private readonly context;
|
|
47
|
+
private readonly activeMetrics;
|
|
48
|
+
private readonly completedMetrics;
|
|
49
|
+
private readonly enabled;
|
|
50
|
+
private readonly getTime;
|
|
51
|
+
constructor(context: Context | null, enabled?: boolean);
|
|
52
|
+
/**
|
|
53
|
+
* Start measuring a performance metric
|
|
54
|
+
*
|
|
55
|
+
* @param name - Unique name for this metric
|
|
56
|
+
* @param metadata - Optional metadata to attach
|
|
57
|
+
*/
|
|
58
|
+
start(name: string, metadata?: Record<string, any>): void;
|
|
59
|
+
/**
|
|
60
|
+
* End measuring a performance metric
|
|
61
|
+
*
|
|
62
|
+
* @param name - Name of the metric to end
|
|
63
|
+
* @returns The completed metric, or undefined if not found
|
|
64
|
+
*/
|
|
65
|
+
end(name: string): PerformanceMetric | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Measure a synchronous function
|
|
68
|
+
*
|
|
69
|
+
* @param name - Name for this measurement
|
|
70
|
+
* @param fn - Function to measure
|
|
71
|
+
* @param metadata - Optional metadata
|
|
72
|
+
* @returns The function's return value
|
|
73
|
+
*/
|
|
74
|
+
measure<T>(name: string, fn: () => T, metadata?: Record<string, any>): T;
|
|
75
|
+
/**
|
|
76
|
+
* Measure an asynchronous function
|
|
77
|
+
*
|
|
78
|
+
* @param name - Name for this measurement
|
|
79
|
+
* @param fn - Async function to measure
|
|
80
|
+
* @param metadata - Optional metadata
|
|
81
|
+
* @returns Promise resolving to the function's return value
|
|
82
|
+
*/
|
|
83
|
+
measureAsync<T>(name: string, fn: () => Promise<T>, metadata?: Record<string, any>): Promise<T>;
|
|
84
|
+
/**
|
|
85
|
+
* Get all completed metrics
|
|
86
|
+
*
|
|
87
|
+
* @returns Array of completed performance metrics
|
|
88
|
+
*/
|
|
89
|
+
getMetrics(): PerformanceMetric[];
|
|
90
|
+
/**
|
|
91
|
+
* Get a specific metric by name
|
|
92
|
+
*
|
|
93
|
+
* @param name - Metric name
|
|
94
|
+
* @returns The metric, or undefined if not found
|
|
95
|
+
*/
|
|
96
|
+
getMetric(name: string): PerformanceMetric | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Get performance summary
|
|
99
|
+
*
|
|
100
|
+
* @returns Aggregated performance data
|
|
101
|
+
*/
|
|
102
|
+
getSummary(): PerformanceSummary;
|
|
103
|
+
/**
|
|
104
|
+
* Log performance summary to console
|
|
105
|
+
*/
|
|
106
|
+
logSummary(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Clear all metrics
|
|
109
|
+
*/
|
|
110
|
+
clear(): void;
|
|
111
|
+
/**
|
|
112
|
+
* Check if monitoring is enabled
|
|
113
|
+
*/
|
|
114
|
+
isEnabled(): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Get active (uncompleted) metrics
|
|
117
|
+
* Useful for debugging leaked measurements
|
|
118
|
+
*/
|
|
119
|
+
getActiveMetrics(): string[];
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a no-op performance monitor for production
|
|
123
|
+
* Has minimal overhead when disabled
|
|
124
|
+
*/
|
|
125
|
+
export declare class NoOpPerformanceMonitor extends PerformanceMonitor {
|
|
126
|
+
constructor();
|
|
127
|
+
start(): void;
|
|
128
|
+
end(): undefined;
|
|
129
|
+
measure<T>(_name: string, fn: () => T): T;
|
|
130
|
+
measureAsync<T>(_name: string, fn: () => Promise<T>): Promise<T>;
|
|
131
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input Validator
|
|
3
|
+
*
|
|
4
|
+
* Provides validation and sanitization for user inputs to prevent security vulnerabilities
|
|
5
|
+
* including SSRF, XSS, and injection attacks.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Validation result
|
|
9
|
+
*/
|
|
10
|
+
export interface ValidationResult {
|
|
11
|
+
valid: boolean;
|
|
12
|
+
error?: string;
|
|
13
|
+
sanitized?: any;
|
|
14
|
+
/**
|
|
15
|
+
* Indicates if runtime validation is recommended
|
|
16
|
+
* (e.g., for proxy URLs to prevent DNS rebinding attacks)
|
|
17
|
+
*/
|
|
18
|
+
requiresRuntimeCheck?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validator configuration
|
|
22
|
+
*/
|
|
23
|
+
export interface ValidatorConfig {
|
|
24
|
+
/**
|
|
25
|
+
* Allowed proxy domains for SSRF prevention
|
|
26
|
+
* If empty, no domain restrictions
|
|
27
|
+
*/
|
|
28
|
+
allowedProxyDomains?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* Allow localhost/127.0.0.1 as proxy URL. Only set for development or test (e.g. Karma reftests).
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
allowLocalhostProxy?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Maximum allowed image timeout in milliseconds
|
|
36
|
+
*/
|
|
37
|
+
maxImageTimeout?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Whether to allow data URLs
|
|
40
|
+
*/
|
|
41
|
+
allowDataUrls?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Custom validation function
|
|
44
|
+
*/
|
|
45
|
+
customValidator?: (value: any, type: string) => ValidationResult;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Input Validator
|
|
49
|
+
*
|
|
50
|
+
* Validates and sanitizes user inputs for security and correctness.
|
|
51
|
+
*/
|
|
52
|
+
export declare class Validator {
|
|
53
|
+
private readonly config;
|
|
54
|
+
constructor(config?: ValidatorConfig);
|
|
55
|
+
/**
|
|
56
|
+
* Validate a URL
|
|
57
|
+
*
|
|
58
|
+
* @param url - URL to validate
|
|
59
|
+
* @param context - Context for validation (e.g., 'proxy', 'image')
|
|
60
|
+
* @returns Validation result
|
|
61
|
+
*/
|
|
62
|
+
validateUrl(url: string, context?: 'proxy' | 'image' | 'general'): ValidationResult;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a hostname is a private IP address
|
|
65
|
+
*/
|
|
66
|
+
private isPrivateIP;
|
|
67
|
+
/**
|
|
68
|
+
* Check if an IPv6 address is private or special
|
|
69
|
+
* Handles compressed IPv6 addresses (e.g., ::1, fc00::1)
|
|
70
|
+
*/
|
|
71
|
+
private isPrivateIPv6;
|
|
72
|
+
/**
|
|
73
|
+
* Expand compressed IPv6 address to full form
|
|
74
|
+
* e.g., "::1" -> "0000:0000:0000:0000:0000:0000:0000:0001"
|
|
75
|
+
*/
|
|
76
|
+
private expandIPv6;
|
|
77
|
+
/**
|
|
78
|
+
* Fallback prefix matching for IPv6 when expansion fails
|
|
79
|
+
*/
|
|
80
|
+
private isPrivateIPv6Prefix;
|
|
81
|
+
/**
|
|
82
|
+
* Validate CSP nonce
|
|
83
|
+
*
|
|
84
|
+
* @param nonce - CSP nonce to validate
|
|
85
|
+
* @returns Validation result
|
|
86
|
+
*/
|
|
87
|
+
validateCspNonce(nonce: string): ValidationResult;
|
|
88
|
+
/**
|
|
89
|
+
* Validate image timeout
|
|
90
|
+
*
|
|
91
|
+
* @param timeout - Timeout in milliseconds
|
|
92
|
+
* @returns Validation result
|
|
93
|
+
*/
|
|
94
|
+
validateImageTimeout(timeout: number): ValidationResult;
|
|
95
|
+
/**
|
|
96
|
+
* Validate window dimensions
|
|
97
|
+
*
|
|
98
|
+
* @param width - Window width
|
|
99
|
+
* @param height - Window height
|
|
100
|
+
* @returns Validation result
|
|
101
|
+
*/
|
|
102
|
+
validateDimensions(width: number, height: number): ValidationResult;
|
|
103
|
+
/**
|
|
104
|
+
* Validate scale factor
|
|
105
|
+
*
|
|
106
|
+
* @param scale - Scale factor
|
|
107
|
+
* @returns Validation result
|
|
108
|
+
*/
|
|
109
|
+
validateScale(scale: number): ValidationResult;
|
|
110
|
+
/**
|
|
111
|
+
* Validate HTML element
|
|
112
|
+
*
|
|
113
|
+
* @param element - Element to validate
|
|
114
|
+
* @returns Validation result
|
|
115
|
+
*/
|
|
116
|
+
validateElement(element: any): ValidationResult;
|
|
117
|
+
/**
|
|
118
|
+
* Validate entire options object
|
|
119
|
+
*
|
|
120
|
+
* @param options - Options to validate
|
|
121
|
+
* @returns Validation result with all errors
|
|
122
|
+
*/
|
|
123
|
+
validateOptions(options: any): ValidationResult;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Create a default validator instance
|
|
127
|
+
*/
|
|
128
|
+
export declare function createDefaultValidator(config?: ValidatorConfig): Validator;
|
|
129
|
+
/**
|
|
130
|
+
* Create a strict validator with security-focused settings
|
|
131
|
+
*/
|
|
132
|
+
export declare function createStrictValidator(allowedProxyDomains: string[]): Validator;
|
|
@@ -51,6 +51,7 @@ import { webkitLineClamp } from './property-descriptors/webkit-line-clamp';
|
|
|
51
51
|
import { Context } from '../core/context';
|
|
52
52
|
import { objectFit } from './property-descriptors/object-fit';
|
|
53
53
|
import { textOverflow } from './property-descriptors/text-overflow';
|
|
54
|
+
import { imageRendering } from './property-descriptors/image-rendering';
|
|
54
55
|
export declare class CSSParsedDeclaration {
|
|
55
56
|
animationDuration: ReturnType<typeof duration.parse>;
|
|
56
57
|
backgroundClip: ReturnType<typeof backgroundClip.parse>;
|
|
@@ -125,6 +126,7 @@ export declare class CSSParsedDeclaration {
|
|
|
125
126
|
wordBreak: ReturnType<typeof wordBreak.parse>;
|
|
126
127
|
zIndex: ReturnType<typeof zIndex.parse>;
|
|
127
128
|
objectFit: ReturnType<typeof objectFit.parse>;
|
|
129
|
+
imageRendering: ReturnType<typeof imageRendering.parse>;
|
|
128
130
|
constructor(context: Context, declaration: CSSStyleDeclaration);
|
|
129
131
|
isVisible(): boolean;
|
|
130
132
|
isTransparent(): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color mathematics utilities
|
|
3
|
+
* Extracted to break circular dependency between srgb.ts and color-utilities.ts
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Clamp a value between min and max
|
|
7
|
+
*/
|
|
8
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
|
9
|
+
/**
|
|
10
|
+
* Multiply two 3x3 matrices
|
|
11
|
+
*/
|
|
12
|
+
export declare const multiplyMatrices: (A: number[], B: number[]) => [number, number, number];
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Context } from '../../core/context';
|
|
2
2
|
import { CSSValue } from '../syntax/parser';
|
|
3
|
+
import { clamp, multiplyMatrices } from './color-math';
|
|
3
4
|
type Color = number;
|
|
4
5
|
export declare const isTransparent: (color: Color) => boolean;
|
|
5
6
|
export declare const asString: (color: Color) => string;
|
|
6
7
|
export declare const pack: (r: number, g: number, b: number, a: number) => Color;
|
|
7
8
|
export declare const getTokenColorValue: (token: CSSValue, i: number) => number;
|
|
8
9
|
export declare const isRelativeTransform: (tokens: CSSValue[]) => boolean;
|
|
9
|
-
export
|
|
10
|
-
export declare const multiplyMatrices: (A: number[], B: number[]) => [number, number, number];
|
|
10
|
+
export { clamp, multiplyMatrices };
|
|
11
11
|
export declare const packSrgb: (args: number[]) => number;
|
|
12
12
|
export declare const packSrgbLinear: ([r, g, b, a]: [number, number, number, number]) => number;
|
|
13
13
|
export declare const packXYZ: (args: number[]) => number;
|
|
@@ -105,4 +105,3 @@ export declare const convertXyz: (args: number[]) => number;
|
|
|
105
105
|
* @param args
|
|
106
106
|
*/
|
|
107
107
|
export declare const convertXyz50: (args: number[]) => number;
|
|
108
|
-
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -34,6 +34,52 @@ export declare class DocumentCloner {
|
|
|
34
34
|
createCanvasClone(canvas: HTMLCanvasElement): HTMLImageElement | HTMLCanvasElement;
|
|
35
35
|
createVideoClone(video: HTMLVideoElement): HTMLCanvasElement;
|
|
36
36
|
appendChildNode(clone: HTMLElement | SVGElement, child: Node, copyStyles: boolean): void;
|
|
37
|
+
/**
|
|
38
|
+
* Check if a child node should be cloned based on filtering rules
|
|
39
|
+
* Filters out: scripts, ignored elements, and optionally styles
|
|
40
|
+
*/
|
|
41
|
+
private shouldCloneChild;
|
|
42
|
+
/**
|
|
43
|
+
* Check if a style element should be cloned based on copyStyles option
|
|
44
|
+
*/
|
|
45
|
+
private shouldCloneStyleElement;
|
|
46
|
+
/**
|
|
47
|
+
* Safely append a cloned child to a target, applying all filtering rules
|
|
48
|
+
*/
|
|
49
|
+
private safeAppendClonedChild;
|
|
50
|
+
/**
|
|
51
|
+
* Clone assigned nodes from a slot element to the target
|
|
52
|
+
*/
|
|
53
|
+
private cloneAssignedNodes;
|
|
54
|
+
/**
|
|
55
|
+
* Clone fallback content from a slot element when no nodes are assigned
|
|
56
|
+
*/
|
|
57
|
+
private cloneSlotFallbackContent;
|
|
58
|
+
/**
|
|
59
|
+
* Handle cloning of a slot element, including assigned nodes or fallback content
|
|
60
|
+
*/
|
|
61
|
+
private cloneSlotElement;
|
|
62
|
+
/**
|
|
63
|
+
* Clone shadow DOM children to the target shadow root
|
|
64
|
+
*/
|
|
65
|
+
private cloneShadowDOMChildren;
|
|
66
|
+
/**
|
|
67
|
+
* Clone light DOM children to the target element
|
|
68
|
+
*/
|
|
69
|
+
private cloneLightDOMChildren;
|
|
70
|
+
/**
|
|
71
|
+
* Clone slot element as light DOM when shadow root creation failed
|
|
72
|
+
*/
|
|
73
|
+
private cloneSlotElementAsLightDOM;
|
|
74
|
+
/**
|
|
75
|
+
* Clone shadow DOM content as light DOM when shadow root creation failed
|
|
76
|
+
* This is a fallback mechanism to ensure content is not lost
|
|
77
|
+
*/
|
|
78
|
+
private cloneShadowDOMAsLightDOM;
|
|
79
|
+
/**
|
|
80
|
+
* Clone child nodes from source element to clone element
|
|
81
|
+
* Handles shadow DOM, slots, and light DOM appropriately
|
|
82
|
+
*/
|
|
37
83
|
cloneChildNodes(node: Element, clone: HTMLElement | SVGElement, copyStyles: boolean): void;
|
|
38
84
|
cloneNode(node: Node, copyStyles: boolean): Node;
|
|
39
85
|
resolvePseudoContent(node: Element, clone: Element, style: CSSStyleDeclaration, pseudoElt: PseudoElementType): HTMLElement | void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM Normalizer
|
|
3
|
+
* Handles DOM side effects that need to happen before rendering
|
|
4
|
+
* Extracted from ElementContainer to follow SRP
|
|
5
|
+
*/
|
|
6
|
+
import { CSSParsedDeclaration } from '../css';
|
|
7
|
+
/**
|
|
8
|
+
* Stored original styles for restoration
|
|
9
|
+
*/
|
|
10
|
+
export interface OriginalStyles {
|
|
11
|
+
animationDuration?: string;
|
|
12
|
+
transform?: string;
|
|
13
|
+
rotate?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Normalize element styles for accurate rendering
|
|
17
|
+
* This includes disabling animations and resetting transforms
|
|
18
|
+
*/
|
|
19
|
+
export declare class DOMNormalizer {
|
|
20
|
+
/**
|
|
21
|
+
* Normalize a single element and return original styles
|
|
22
|
+
*
|
|
23
|
+
* @param element - Element to normalize
|
|
24
|
+
* @param styles - Parsed CSS styles
|
|
25
|
+
* @returns Original styles map for restoration
|
|
26
|
+
*/
|
|
27
|
+
static normalizeElement(element: Element, styles: CSSParsedDeclaration): OriginalStyles;
|
|
28
|
+
/**
|
|
29
|
+
* Normalize element and its descendants recursively
|
|
30
|
+
*
|
|
31
|
+
* @param element - Element to normalize
|
|
32
|
+
* @param styles - Parsed CSS styles
|
|
33
|
+
* @returns Original styles map for restoration
|
|
34
|
+
*/
|
|
35
|
+
static normalizeTree(element: Element, styles: CSSParsedDeclaration): OriginalStyles;
|
|
36
|
+
/**
|
|
37
|
+
* Restore element styles after rendering
|
|
38
|
+
*
|
|
39
|
+
* @param element - Element to restore
|
|
40
|
+
* @param originalStyles - Original styles to restore
|
|
41
|
+
*/
|
|
42
|
+
static restoreElement(element: Element, originalStyles: OriginalStyles): void;
|
|
43
|
+
}
|
|
@@ -8,6 +8,13 @@ export declare const enum FLAGS {
|
|
|
8
8
|
IS_LIST_OWNER = 8,
|
|
9
9
|
DEBUG_RENDER = 16
|
|
10
10
|
}
|
|
11
|
+
export interface ElementContainerOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Whether to normalize DOM (disable animations, reset transforms)
|
|
14
|
+
* Default: true for backward compatibility
|
|
15
|
+
*/
|
|
16
|
+
normalizeDom?: boolean;
|
|
17
|
+
}
|
|
11
18
|
export declare class ElementContainer {
|
|
12
19
|
protected readonly context: Context;
|
|
13
20
|
readonly styles: CSSParsedDeclaration;
|
|
@@ -15,5 +22,17 @@ export declare class ElementContainer {
|
|
|
15
22
|
readonly elements: ElementContainer[];
|
|
16
23
|
bounds: Bounds;
|
|
17
24
|
flags: number;
|
|
18
|
-
|
|
25
|
+
private originalStyles?;
|
|
26
|
+
private originalElement?;
|
|
27
|
+
constructor(context: Context, element: Element, options?: ElementContainerOptions);
|
|
28
|
+
/**
|
|
29
|
+
* Restore original element styles (if normalized)
|
|
30
|
+
* Call this after rendering is complete to clean up DOM state
|
|
31
|
+
*/
|
|
32
|
+
restore(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Recursively restore all elements in the tree
|
|
35
|
+
* Call this on the root container after rendering is complete
|
|
36
|
+
*/
|
|
37
|
+
restoreTree(): void;
|
|
19
38
|
}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { ElementContainer } from './element-container';
|
|
2
2
|
import { Context } from '../core/context';
|
|
3
|
+
import { isElementNode, isTextNode, isSVGElementNode, isHTMLElementNode, isLIElement, isOLElement, isCustomElement } from './node-type-guards';
|
|
4
|
+
export { isElementNode, isTextNode, isSVGElementNode, isHTMLElementNode, isLIElement, isOLElement, isCustomElement };
|
|
3
5
|
export declare const parseTree: (context: Context, element: HTMLElement) => ElementContainer;
|
|
4
|
-
export declare const isTextNode: (node: Node) => node is Text;
|
|
5
|
-
export declare const isElementNode: (node: Node) => node is Element;
|
|
6
|
-
export declare const isHTMLElementNode: (node: Node) => node is HTMLElement;
|
|
7
|
-
export declare const isSVGElementNode: (element: Element) => element is SVGElement;
|
|
8
|
-
export declare const isLIElement: (node: Element) => node is HTMLLIElement;
|
|
9
|
-
export declare const isOLElement: (node: Element) => node is HTMLOListElement;
|
|
10
6
|
export declare const isInputElement: (node: Element) => node is HTMLInputElement;
|
|
11
7
|
export declare const isHTMLElement: (node: Element) => node is HTMLHtmlElement;
|
|
12
8
|
export declare const isSVGElement: (node: Element) => node is SVGSVGElement;
|
|
@@ -20,4 +16,3 @@ export declare const isScriptElement: (node: Element) => node is HTMLScriptEleme
|
|
|
20
16
|
export declare const isTextareaElement: (node: Element) => node is HTMLTextAreaElement;
|
|
21
17
|
export declare const isSelectElement: (node: Element) => node is HTMLSelectElement;
|
|
22
18
|
export declare const isSlotElement: (node: Element) => node is HTMLSlotElement;
|
|
23
|
-
export declare const isCustomElement: (node: Element) => node is HTMLElement;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM Node Type Guards
|
|
3
|
+
* Extracted to break circular dependencies
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Check if node is an Element
|
|
7
|
+
*/
|
|
8
|
+
export declare const isElementNode: (node: Node) => node is Element;
|
|
9
|
+
/**
|
|
10
|
+
* Check if node is a Text node
|
|
11
|
+
*/
|
|
12
|
+
export declare const isTextNode: (node: Node) => node is Text;
|
|
13
|
+
/**
|
|
14
|
+
* Check if element is an SVG element
|
|
15
|
+
*/
|
|
16
|
+
export declare const isSVGElementNode: (element: Element) => element is SVGElement;
|
|
17
|
+
/**
|
|
18
|
+
* Check if node is an HTML element
|
|
19
|
+
*/
|
|
20
|
+
export declare const isHTMLElementNode: (node: Node) => node is HTMLElement;
|
|
21
|
+
/**
|
|
22
|
+
* Check if node is an LI element
|
|
23
|
+
*/
|
|
24
|
+
export declare const isLIElement: (node: Element) => node is HTMLLIElement;
|
|
25
|
+
/**
|
|
26
|
+
* Check if node is an OL element
|
|
27
|
+
*/
|
|
28
|
+
export declare const isOLElement: (node: Element) => node is HTMLOListElement;
|
|
29
|
+
/**
|
|
30
|
+
* Check if element is a custom element
|
|
31
|
+
* Custom elements must have a hyphen and cannot be SVG elements
|
|
32
|
+
*/
|
|
33
|
+
export declare const isCustomElement: (element: Element) => element is HTMLElement;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { ElementContainer } from '../element-container';
|
|
2
2
|
import { Color } from '../../css/types/color';
|
|
3
3
|
import { Context } from '../../core/context';
|
|
4
|
+
type ParseTreeFunction = (context: Context, node: Node) => ElementContainer;
|
|
4
5
|
export declare class IFrameElementContainer extends ElementContainer {
|
|
5
6
|
src: string;
|
|
6
7
|
width: number;
|
|
7
8
|
height: number;
|
|
8
9
|
tree?: ElementContainer;
|
|
9
10
|
backgroundColor: Color;
|
|
10
|
-
|
|
11
|
+
private parseTreeFn?;
|
|
12
|
+
constructor(context: Context, iframe: HTMLIFrameElement, parseTreeFn?: ParseTreeFunction);
|
|
11
13
|
}
|
|
14
|
+
export {};
|