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.
Files changed (186) hide show
  1. package/dist/html2canvas-pro.esm.js +21 -7
  2. package/dist/html2canvas-pro.esm.js.map +1 -1
  3. package/dist/html2canvas-pro.js +21 -7
  4. package/dist/html2canvas-pro.js.map +1 -1
  5. package/dist/html2canvas-pro.min.js +3 -3
  6. package/dist/lib/core/cache-storage.js +2 -2
  7. package/dist/lib/core/features.js +2 -2
  8. package/dist/lib/render/canvas/background-renderer.js +6 -0
  9. package/dist/lib/render/canvas/canvas-renderer.js +5 -1
  10. package/dist/lib/render/canvas/foreignobject-renderer.js +5 -1
  11. package/package.json +3 -11
  12. package/dist/lib/invariant.js +0 -9
  13. package/dist/types/invariant.d.ts +0 -1
  14. package/src/__tests__/index.ts +0 -99
  15. package/src/config.ts +0 -107
  16. package/src/core/__mocks__/cache-storage.ts +0 -1
  17. package/src/core/__mocks__/context.ts +0 -19
  18. package/src/core/__mocks__/features.ts +0 -8
  19. package/src/core/__mocks__/logger.ts +0 -17
  20. package/src/core/__tests__/cache-storage.test.ts +0 -205
  21. package/src/core/__tests__/cache-storage.ts +0 -278
  22. package/src/core/__tests__/logger.ts +0 -29
  23. package/src/core/__tests__/validator.ts +0 -359
  24. package/src/core/bitwise.ts +0 -1
  25. package/src/core/cache-storage.ts +0 -315
  26. package/src/core/context.ts +0 -31
  27. package/src/core/debugger.ts +0 -32
  28. package/src/core/features.ts +0 -222
  29. package/src/core/logger.ts +0 -64
  30. package/src/core/origin-checker.ts +0 -57
  31. package/src/core/performance-monitor.ts +0 -241
  32. package/src/core/render-element.ts +0 -272
  33. package/src/core/util.ts +0 -1
  34. package/src/core/validator.ts +0 -593
  35. package/src/css/index.ts +0 -427
  36. package/src/css/layout/__mocks__/bounds.ts +0 -6
  37. package/src/css/layout/bounds.ts +0 -79
  38. package/src/css/layout/text.ts +0 -161
  39. package/src/css/property-descriptor.ts +0 -49
  40. package/src/css/property-descriptors/__tests__/background-tests.ts +0 -65
  41. package/src/css/property-descriptors/__tests__/clip-path.test.ts +0 -280
  42. package/src/css/property-descriptors/__tests__/font-family.ts +0 -25
  43. package/src/css/property-descriptors/__tests__/image-rendering-integration.test.ts +0 -153
  44. package/src/css/property-descriptors/__tests__/image-rendering-performance.test.ts +0 -175
  45. package/src/css/property-descriptors/__tests__/image-rendering.test.ts +0 -72
  46. package/src/css/property-descriptors/__tests__/paint-order.ts +0 -87
  47. package/src/css/property-descriptors/__tests__/text-shadow.ts +0 -94
  48. package/src/css/property-descriptors/__tests__/transform-tests.ts +0 -18
  49. package/src/css/property-descriptors/background-clip.ts +0 -30
  50. package/src/css/property-descriptors/background-color.ts +0 -9
  51. package/src/css/property-descriptors/background-image.ts +0 -27
  52. package/src/css/property-descriptors/background-origin.ts +0 -31
  53. package/src/css/property-descriptors/background-position.ts +0 -38
  54. package/src/css/property-descriptors/background-repeat.ts +0 -44
  55. package/src/css/property-descriptors/background-size.ts +0 -27
  56. package/src/css/property-descriptors/border-color.ts +0 -13
  57. package/src/css/property-descriptors/border-radius.ts +0 -19
  58. package/src/css/property-descriptors/border-style.ts +0 -34
  59. package/src/css/property-descriptors/border-width.ts +0 -20
  60. package/src/css/property-descriptors/box-shadow.ts +0 -60
  61. package/src/css/property-descriptors/clip-path.ts +0 -271
  62. package/src/css/property-descriptors/color.ts +0 -9
  63. package/src/css/property-descriptors/content.ts +0 -26
  64. package/src/css/property-descriptors/counter-increment.ts +0 -43
  65. package/src/css/property-descriptors/counter-reset.ts +0 -36
  66. package/src/css/property-descriptors/direction.ts +0 -23
  67. package/src/css/property-descriptors/display.ts +0 -117
  68. package/src/css/property-descriptors/duration.ts +0 -14
  69. package/src/css/property-descriptors/float.ts +0 -29
  70. package/src/css/property-descriptors/font-family.ts +0 -38
  71. package/src/css/property-descriptors/font-size.ts +0 -9
  72. package/src/css/property-descriptors/font-style.ts +0 -25
  73. package/src/css/property-descriptors/font-variant.ts +0 -12
  74. package/src/css/property-descriptors/font-weight.ts +0 -26
  75. package/src/css/property-descriptors/image-rendering.ts +0 -33
  76. package/src/css/property-descriptors/letter-spacing.ts +0 -25
  77. package/src/css/property-descriptors/line-break.ts +0 -22
  78. package/src/css/property-descriptors/line-height.ts +0 -22
  79. package/src/css/property-descriptors/list-style-image.ts +0 -19
  80. package/src/css/property-descriptors/list-style-position.ts +0 -22
  81. package/src/css/property-descriptors/list-style-type.ts +0 -179
  82. package/src/css/property-descriptors/margin.ts +0 -13
  83. package/src/css/property-descriptors/mix-blend-mode.ts +0 -35
  84. package/src/css/property-descriptors/object-fit.ts +0 -39
  85. package/src/css/property-descriptors/opacity.ts +0 -15
  86. package/src/css/property-descriptors/overflow-wrap.ts +0 -22
  87. package/src/css/property-descriptors/overflow.ts +0 -34
  88. package/src/css/property-descriptors/padding.ts +0 -14
  89. package/src/css/property-descriptors/paint-order.ts +0 -42
  90. package/src/css/property-descriptors/position.ts +0 -30
  91. package/src/css/property-descriptors/quotes.ts +0 -57
  92. package/src/css/property-descriptors/rotate.ts +0 -34
  93. package/src/css/property-descriptors/text-align.ts +0 -26
  94. package/src/css/property-descriptors/text-decoration-color.ts +0 -9
  95. package/src/css/property-descriptors/text-decoration-line.ts +0 -38
  96. package/src/css/property-descriptors/text-decoration-style.ts +0 -32
  97. package/src/css/property-descriptors/text-decoration-thickness.ts +0 -30
  98. package/src/css/property-descriptors/text-overflow.ts +0 -23
  99. package/src/css/property-descriptors/text-shadow.ts +0 -52
  100. package/src/css/property-descriptors/text-transform.ts +0 -27
  101. package/src/css/property-descriptors/text-underline-offset.ts +0 -27
  102. package/src/css/property-descriptors/transform-origin.ts +0 -29
  103. package/src/css/property-descriptors/transform.ts +0 -74
  104. package/src/css/property-descriptors/visibility.ts +0 -25
  105. package/src/css/property-descriptors/webkit-line-clamp.ts +0 -30
  106. package/src/css/property-descriptors/webkit-text-stroke-color.ts +0 -8
  107. package/src/css/property-descriptors/webkit-text-stroke-width.ts +0 -15
  108. package/src/css/property-descriptors/word-break.ts +0 -25
  109. package/src/css/property-descriptors/writing-mode.ts +0 -37
  110. package/src/css/property-descriptors/z-index.ts +0 -27
  111. package/src/css/syntax/__tests__/tokernizer-tests.ts +0 -29
  112. package/src/css/syntax/parser.ts +0 -188
  113. package/src/css/syntax/tokenizer.ts +0 -822
  114. package/src/css/type-descriptor.ts +0 -7
  115. package/src/css/types/__tests__/color-tests.ts +0 -147
  116. package/src/css/types/__tests__/image-tests.ts +0 -239
  117. package/src/css/types/angle.ts +0 -86
  118. package/src/css/types/color-math.ts +0 -22
  119. package/src/css/types/color-spaces/a98.ts +0 -86
  120. package/src/css/types/color-spaces/p3.ts +0 -92
  121. package/src/css/types/color-spaces/pro-photo.ts +0 -87
  122. package/src/css/types/color-spaces/rec2020.ts +0 -90
  123. package/src/css/types/color-spaces/srgb.ts +0 -87
  124. package/src/css/types/color-utilities.ts +0 -452
  125. package/src/css/types/color.ts +0 -485
  126. package/src/css/types/functions/-prefix-linear-gradient.ts +0 -35
  127. package/src/css/types/functions/-prefix-radial-gradient.ts +0 -106
  128. package/src/css/types/functions/-webkit-gradient.ts +0 -69
  129. package/src/css/types/functions/__tests__/radial-gradient.ts +0 -69
  130. package/src/css/types/functions/counter.ts +0 -511
  131. package/src/css/types/functions/gradient.ts +0 -206
  132. package/src/css/types/functions/linear-gradient.ts +0 -28
  133. package/src/css/types/functions/radial-gradient.ts +0 -101
  134. package/src/css/types/image.ts +0 -120
  135. package/src/css/types/index.ts +0 -1
  136. package/src/css/types/length-percentage.ts +0 -137
  137. package/src/css/types/length.ts +0 -7
  138. package/src/css/types/time.ts +0 -20
  139. package/src/dom/__mocks__/document-cloner.ts +0 -22
  140. package/src/dom/__tests__/dom-normalizer.test.ts +0 -133
  141. package/src/dom/__tests__/element-container.test.ts +0 -129
  142. package/src/dom/document-cloner.ts +0 -929
  143. package/src/dom/dom-normalizer.ts +0 -133
  144. package/src/dom/element-container.ts +0 -75
  145. package/src/dom/elements/li-element-container.ts +0 -10
  146. package/src/dom/elements/ol-element-container.ts +0 -12
  147. package/src/dom/elements/select-element-container.ts +0 -10
  148. package/src/dom/elements/textarea-element-container.ts +0 -9
  149. package/src/dom/node-parser.ts +0 -177
  150. package/src/dom/node-type-guards.ts +0 -70
  151. package/src/dom/replaced-elements/canvas-element-container.ts +0 -15
  152. package/src/dom/replaced-elements/iframe-element-container.ts +0 -55
  153. package/src/dom/replaced-elements/image-element-container.ts +0 -16
  154. package/src/dom/replaced-elements/index.ts +0 -5
  155. package/src/dom/replaced-elements/input-element-container.ts +0 -105
  156. package/src/dom/replaced-elements/pseudo-elements.ts +0 -0
  157. package/src/dom/replaced-elements/svg-element-container.ts +0 -23
  158. package/src/dom/text-container.ts +0 -42
  159. package/src/global.d.ts +0 -19
  160. package/src/index.ts +0 -82
  161. package/src/invariant.ts +0 -5
  162. package/src/options.ts +0 -55
  163. package/src/render/__tests__/object-fit.test.ts +0 -85
  164. package/src/render/background.ts +0 -298
  165. package/src/render/bezier-curve.ts +0 -47
  166. package/src/render/border.ts +0 -165
  167. package/src/render/bound-curves.ts +0 -388
  168. package/src/render/box-sizing.ts +0 -31
  169. package/src/render/canvas/__tests__/background-renderer.test.ts +0 -72
  170. package/src/render/canvas/__tests__/border-renderer.test.ts +0 -24
  171. package/src/render/canvas/__tests__/effects-renderer.test.ts +0 -32
  172. package/src/render/canvas/__tests__/text-renderer.test.ts +0 -471
  173. package/src/render/canvas/background-renderer.ts +0 -271
  174. package/src/render/canvas/border-renderer.ts +0 -224
  175. package/src/render/canvas/canvas-path.ts +0 -31
  176. package/src/render/canvas/canvas-renderer.ts +0 -641
  177. package/src/render/canvas/effects-renderer.ts +0 -130
  178. package/src/render/canvas/foreignobject-renderer.ts +0 -53
  179. package/src/render/canvas/text-renderer.ts +0 -700
  180. package/src/render/effects.ts +0 -75
  181. package/src/render/font-metrics.ts +0 -72
  182. package/src/render/object-fit.ts +0 -100
  183. package/src/render/path.ts +0 -37
  184. package/src/render/renderer-interface.ts +0 -28
  185. package/src/render/stacking-context.ts +0 -386
  186. 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
@@ -1,5 +0,0 @@
1
- export const invariant = (assertion: boolean, error: string): void => {
2
- if (!assertion) {
3
- console.error(error);
4
- }
5
- };
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
- });