@remotion/web-renderer 4.0.431 → 4.0.433

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 (93) hide show
  1. package/dist/can-render-types.d.ts +2 -2
  2. package/dist/esm/index.mjs +401 -98
  3. package/dist/index.d.ts +1 -1
  4. package/dist/mediabunny-mappings.d.ts +6 -4
  5. package/dist/register-aac-encoder.d.ts +1 -0
  6. package/dist/register-flac-encoder.d.ts +1 -0
  7. package/dist/render-media-on-web.d.ts +1 -1
  8. package/package.json +11 -8
  9. package/dist/add-sample.js +0 -20
  10. package/dist/artifact.js +0 -56
  11. package/dist/audio.js +0 -42
  12. package/dist/calculate-transforms.d.ts +0 -9
  13. package/dist/calculate-transforms.js +0 -74
  14. package/dist/can-use-webfs-target.js +0 -19
  15. package/dist/composable.d.ts +0 -10
  16. package/dist/composable.js +0 -1
  17. package/dist/compose-canvas.d.ts +0 -1
  18. package/dist/compose-canvas.js +0 -12
  19. package/dist/compose-svg.d.ts +0 -1
  20. package/dist/compose-svg.js +0 -34
  21. package/dist/compose.js +0 -85
  22. package/dist/create-scaffold.js +0 -104
  23. package/dist/drawing/border-radius.js +0 -151
  24. package/dist/drawing/calculate-object-fit.js +0 -208
  25. package/dist/drawing/calculate-transforms.js +0 -127
  26. package/dist/drawing/clamp-rect-to-parent-bounds.js +0 -18
  27. package/dist/drawing/do-rects-intersect.js +0 -6
  28. package/dist/drawing/draw-background.js +0 -62
  29. package/dist/drawing/draw-border.js +0 -353
  30. package/dist/drawing/draw-box-shadow.js +0 -103
  31. package/dist/drawing/draw-dom-element.js +0 -85
  32. package/dist/drawing/draw-element-to-canvas.d.ts +0 -11
  33. package/dist/drawing/draw-element-to-canvas.js +0 -64
  34. package/dist/drawing/draw-element.js +0 -84
  35. package/dist/drawing/draw-outline.js +0 -93
  36. package/dist/drawing/draw-rounded.js +0 -34
  37. package/dist/drawing/drawn-fn.js +0 -1
  38. package/dist/drawing/fit-svg-into-its-dimensions.js +0 -35
  39. package/dist/drawing/get-clipped-background.d.ts +0 -23
  40. package/dist/drawing/get-clipped-background.js +0 -14
  41. package/dist/drawing/get-padding-box.js +0 -30
  42. package/dist/drawing/get-pretransform-rect.js +0 -49
  43. package/dist/drawing/go-rects-intersect.d.ts +0 -1
  44. package/dist/drawing/go-rects-intersect.js +0 -6
  45. package/dist/drawing/handle-3d-transform.js +0 -26
  46. package/dist/drawing/handle-mask.js +0 -21
  47. package/dist/drawing/has-transform.js +0 -14
  48. package/dist/drawing/mask-image.js +0 -14
  49. package/dist/drawing/opacity.js +0 -7
  50. package/dist/drawing/overflow.js +0 -14
  51. package/dist/drawing/parse-linear-gradient.js +0 -260
  52. package/dist/drawing/parse-transform-origin.js +0 -7
  53. package/dist/drawing/precompose.d.ts +0 -27
  54. package/dist/drawing/precompose.js +0 -14
  55. package/dist/drawing/process-node.js +0 -122
  56. package/dist/drawing/round-to-expand-rect.js +0 -7
  57. package/dist/drawing/text/apply-text-transform.js +0 -12
  58. package/dist/drawing/text/draw-text.js +0 -53
  59. package/dist/drawing/text/find-line-breaks.text.js +0 -118
  60. package/dist/drawing/text/get-base-height.d.ts +0 -1
  61. package/dist/drawing/text/get-base-height.js +0 -13
  62. package/dist/drawing/text/get-collapsed-text.d.ts +0 -1
  63. package/dist/drawing/text/get-collapsed-text.js +0 -46
  64. package/dist/drawing/text/handle-text-node.js +0 -24
  65. package/dist/drawing/transform-in-3d.js +0 -177
  66. package/dist/drawing/transform-rect-with-matrix.js +0 -19
  67. package/dist/drawing/transform.js +0 -10
  68. package/dist/drawing/turn-svg-into-drawable.js +0 -41
  69. package/dist/find-capturable-elements.d.ts +0 -2
  70. package/dist/find-capturable-elements.js +0 -28
  71. package/dist/frame-range.js +0 -15
  72. package/dist/get-audio-encoding-config.js +0 -18
  73. package/dist/get-biggest-bounding-client-rect.js +0 -43
  74. package/dist/index.js +0 -2
  75. package/dist/internal-state.js +0 -21
  76. package/dist/mediabunny-mappings.js +0 -63
  77. package/dist/output-target.js +0 -1
  78. package/dist/parse-transform-origin.d.ts +0 -4
  79. package/dist/parse-transform-origin.js +0 -7
  80. package/dist/props-if-has-props.js +0 -1
  81. package/dist/render-media-on-web.js +0 -297
  82. package/dist/render-operations-queue.js +0 -3
  83. package/dist/render-still-on-web.js +0 -109
  84. package/dist/send-telemetry-event.js +0 -22
  85. package/dist/take-screenshot.js +0 -30
  86. package/dist/throttle-progress.js +0 -43
  87. package/dist/tree-walker-cleanup-after-children.js +0 -33
  88. package/dist/update-time.js +0 -17
  89. package/dist/validate-video-frame.js +0 -34
  90. package/dist/wait-for-ready.js +0 -35
  91. package/dist/walk-tree.js +0 -14
  92. package/dist/web-fs-target.js +0 -41
  93. package/dist/with-resolvers.js +0 -9
@@ -1,151 +0,0 @@
1
- import { drawRoundedRectPath } from './draw-rounded';
2
- import { getBoxBasedOnBackgroundClip } from './get-padding-box';
3
- function parseValue({ value, reference, }) {
4
- value = value.trim();
5
- if (value.endsWith('%')) {
6
- const percentage = parseFloat(value);
7
- return (percentage / 100) * reference;
8
- }
9
- if (value.endsWith('px')) {
10
- return parseFloat(value);
11
- }
12
- // If no unit, assume pixels
13
- return parseFloat(value);
14
- }
15
- function expandShorthand(values) {
16
- if (values.length === 1) {
17
- // All corners the same
18
- return [values[0], values[0], values[0], values[0]];
19
- }
20
- if (values.length === 2) {
21
- // [0] = top-left & bottom-right, [1] = top-right & bottom-left
22
- return [values[0], values[1], values[0], values[1]];
23
- }
24
- if (values.length === 3) {
25
- // [0] = top-left, [1] = top-right & bottom-left, [2] = bottom-right
26
- return [values[0], values[1], values[2], values[1]];
27
- }
28
- // 4 values: top-left, top-right, bottom-right, bottom-left
29
- return [values[0], values[1], values[2], values[3]];
30
- }
31
- function clampBorderRadius({ borderRadius, width, height, }) {
32
- // According to CSS spec, if the sum of border radii on adjacent corners
33
- // exceeds the length of the edge, they should be proportionally reduced
34
- const clamped = {
35
- topLeft: { ...borderRadius.topLeft },
36
- topRight: { ...borderRadius.topRight },
37
- bottomRight: { ...borderRadius.bottomRight },
38
- bottomLeft: { ...borderRadius.bottomLeft },
39
- };
40
- // Check top edge
41
- const topSum = clamped.topLeft.horizontal + clamped.topRight.horizontal;
42
- if (topSum > width) {
43
- const factor = width / topSum;
44
- clamped.topLeft.horizontal *= factor;
45
- clamped.topRight.horizontal *= factor;
46
- }
47
- // Check right edge
48
- const rightSum = clamped.topRight.vertical + clamped.bottomRight.vertical;
49
- if (rightSum > height) {
50
- const factor = height / rightSum;
51
- clamped.topRight.vertical *= factor;
52
- clamped.bottomRight.vertical *= factor;
53
- }
54
- // Check bottom edge
55
- const bottomSum = clamped.bottomRight.horizontal + clamped.bottomLeft.horizontal;
56
- if (bottomSum > width) {
57
- const factor = width / bottomSum;
58
- clamped.bottomRight.horizontal *= factor;
59
- clamped.bottomLeft.horizontal *= factor;
60
- }
61
- // Check left edge
62
- const leftSum = clamped.bottomLeft.vertical + clamped.topLeft.vertical;
63
- if (leftSum > height) {
64
- const factor = height / leftSum;
65
- clamped.bottomLeft.vertical *= factor;
66
- clamped.topLeft.vertical *= factor;
67
- }
68
- return clamped;
69
- }
70
- export function parseBorderRadius({ borderRadius, width, height, }) {
71
- // Split by '/' to separate horizontal and vertical radii
72
- const parts = borderRadius.split('/').map((part) => part.trim());
73
- const horizontalPart = parts[0];
74
- const verticalPart = parts[1];
75
- // Split each part into individual values
76
- const horizontalValues = horizontalPart.split(/\s+/).filter((v) => v);
77
- const verticalValues = verticalPart
78
- ? verticalPart.split(/\s+/).filter((v) => v)
79
- : horizontalValues; // If no '/', use horizontal values for vertical
80
- // Expand shorthand to 4 values
81
- const [hTopLeft, hTopRight, hBottomRight, hBottomLeft] = expandShorthand(horizontalValues);
82
- const [vTopLeft, vTopRight, vBottomRight, vBottomLeft] = expandShorthand(verticalValues);
83
- return clampBorderRadius({
84
- borderRadius: {
85
- topLeft: {
86
- horizontal: parseValue({ value: hTopLeft, reference: width }),
87
- vertical: parseValue({ value: vTopLeft, reference: height }),
88
- },
89
- topRight: {
90
- horizontal: parseValue({ value: hTopRight, reference: width }),
91
- vertical: parseValue({ value: vTopRight, reference: height }),
92
- },
93
- bottomRight: {
94
- horizontal: parseValue({ value: hBottomRight, reference: width }),
95
- vertical: parseValue({ value: vBottomRight, reference: height }),
96
- },
97
- bottomLeft: {
98
- horizontal: parseValue({ value: hBottomLeft, reference: width }),
99
- vertical: parseValue({ value: vBottomLeft, reference: height }),
100
- },
101
- },
102
- width,
103
- height,
104
- });
105
- }
106
- export function setBorderRadius({ ctx, rect, borderRadius, forceClipEvenWhenZero = false, computedStyle, backgroundClip, }) {
107
- if (borderRadius.topLeft.horizontal === 0 &&
108
- borderRadius.topLeft.vertical === 0 &&
109
- borderRadius.topRight.horizontal === 0 &&
110
- borderRadius.topRight.vertical === 0 &&
111
- borderRadius.bottomRight.horizontal === 0 &&
112
- borderRadius.bottomRight.vertical === 0 &&
113
- borderRadius.bottomLeft.horizontal === 0 &&
114
- borderRadius.bottomLeft.vertical === 0 &&
115
- !forceClipEvenWhenZero) {
116
- return () => { };
117
- }
118
- ctx.save();
119
- const boundingRect = getBoxBasedOnBackgroundClip(rect, computedStyle, backgroundClip);
120
- // See background-clip tests for why this logic matters!
121
- const actualBorderRadius = {
122
- topLeft: {
123
- horizontal: Math.max(0, borderRadius.topLeft.horizontal - (boundingRect.left - rect.left)),
124
- vertical: Math.max(0, borderRadius.topLeft.vertical - (boundingRect.top - rect.top)),
125
- },
126
- topRight: {
127
- horizontal: Math.max(0, borderRadius.topRight.horizontal - (rect.right - boundingRect.right)),
128
- vertical: Math.max(0, borderRadius.topRight.vertical - (boundingRect.top - rect.top)),
129
- },
130
- bottomRight: {
131
- horizontal: Math.max(0, borderRadius.bottomRight.horizontal - (rect.right - boundingRect.right)),
132
- vertical: Math.max(0, borderRadius.bottomRight.vertical - (rect.bottom - boundingRect.bottom)),
133
- },
134
- bottomLeft: {
135
- horizontal: Math.max(0, borderRadius.bottomLeft.horizontal - (boundingRect.left - rect.left)),
136
- vertical: Math.max(0, borderRadius.bottomLeft.vertical - (rect.bottom - boundingRect.bottom)),
137
- },
138
- };
139
- drawRoundedRectPath({
140
- ctx,
141
- x: boundingRect.left,
142
- y: boundingRect.top,
143
- width: boundingRect.width,
144
- height: boundingRect.height,
145
- borderRadius: actualBorderRadius,
146
- });
147
- ctx.clip();
148
- return () => {
149
- ctx.restore();
150
- };
151
- }
@@ -1,208 +0,0 @@
1
- /**
2
- * fill: Stretch the image to fill the container, ignoring aspect ratio
3
- */
4
- const calculateFill = ({ containerSize, intrinsicSize, }) => {
5
- return {
6
- sourceX: 0,
7
- sourceY: 0,
8
- sourceWidth: intrinsicSize.width,
9
- sourceHeight: intrinsicSize.height,
10
- destX: containerSize.left,
11
- destY: containerSize.top,
12
- destWidth: containerSize.width,
13
- destHeight: containerSize.height,
14
- };
15
- };
16
- /**
17
- * contain: Scale the image to fit inside the container while maintaining aspect ratio.
18
- * This may result in letterboxing (empty space on sides or top/bottom).
19
- */
20
- const calculateContain = ({ containerSize, intrinsicSize, }) => {
21
- const containerAspect = containerSize.width / containerSize.height;
22
- const imageAspect = intrinsicSize.width / intrinsicSize.height;
23
- let destWidth;
24
- let destHeight;
25
- if (imageAspect > containerAspect) {
26
- // Image is wider than container (relative to their heights)
27
- // Fit by width, letterbox top/bottom
28
- destWidth = containerSize.width;
29
- destHeight = containerSize.width / imageAspect;
30
- }
31
- else {
32
- // Image is taller than container (relative to their widths)
33
- // Fit by height, letterbox left/right
34
- destHeight = containerSize.height;
35
- destWidth = containerSize.height * imageAspect;
36
- }
37
- // Center the image in the container
38
- const destX = containerSize.left + (containerSize.width - destWidth) / 2;
39
- const destY = containerSize.top + (containerSize.height - destHeight) / 2;
40
- return {
41
- sourceX: 0,
42
- sourceY: 0,
43
- sourceWidth: intrinsicSize.width,
44
- sourceHeight: intrinsicSize.height,
45
- destX,
46
- destY,
47
- destWidth,
48
- destHeight,
49
- };
50
- };
51
- /**
52
- * cover: Scale the image to cover the container while maintaining aspect ratio.
53
- * Parts of the image may be cropped.
54
- */
55
- const calculateCover = ({ containerSize, intrinsicSize, }) => {
56
- // Guard against zero or non-positive heights to avoid division by zero and NaN/Infinity.
57
- if (containerSize.height <= 0 || intrinsicSize.height <= 0) {
58
- return {
59
- sourceX: 0,
60
- sourceY: 0,
61
- sourceWidth: 0,
62
- sourceHeight: 0,
63
- destX: containerSize.left,
64
- destY: containerSize.top,
65
- destWidth: 0,
66
- destHeight: 0,
67
- };
68
- }
69
- const containerAspect = containerSize.width / containerSize.height;
70
- const imageAspect = intrinsicSize.width / intrinsicSize.height;
71
- let sourceX = 0;
72
- let sourceY = 0;
73
- let sourceWidth = intrinsicSize.width;
74
- let sourceHeight = intrinsicSize.height;
75
- if (imageAspect > containerAspect) {
76
- // Image is wider than container - crop horizontally
77
- // Scale by height, then crop width
78
- sourceWidth = intrinsicSize.height * containerAspect;
79
- sourceX = (intrinsicSize.width - sourceWidth) / 2;
80
- }
81
- else {
82
- // Image is taller than container - crop vertically
83
- // Scale by width, then crop height
84
- sourceHeight = intrinsicSize.width / containerAspect;
85
- sourceY = (intrinsicSize.height - sourceHeight) / 2;
86
- }
87
- return {
88
- sourceX,
89
- sourceY,
90
- sourceWidth,
91
- sourceHeight,
92
- destX: containerSize.left,
93
- destY: containerSize.top,
94
- destWidth: containerSize.width,
95
- destHeight: containerSize.height,
96
- };
97
- };
98
- /**
99
- * none: Draw the image at its natural size, centered in the container.
100
- * Clips to the container bounds if the image overflows.
101
- */
102
- const calculateNone = ({ containerSize, intrinsicSize, }) => {
103
- // Calculate centered position (can be negative if image is larger than container)
104
- const centeredX = containerSize.left + (containerSize.width - intrinsicSize.width) / 2;
105
- const centeredY = containerSize.top + (containerSize.height - intrinsicSize.height) / 2;
106
- // Calculate clipping bounds
107
- let sourceX = 0;
108
- let sourceY = 0;
109
- let sourceWidth = intrinsicSize.width;
110
- let sourceHeight = intrinsicSize.height;
111
- let destX = centeredX;
112
- let destY = centeredY;
113
- let destWidth = intrinsicSize.width;
114
- let destHeight = intrinsicSize.height;
115
- // Clip left edge
116
- if (destX < containerSize.left) {
117
- const clipAmount = containerSize.left - destX;
118
- sourceX = clipAmount;
119
- sourceWidth -= clipAmount;
120
- destX = containerSize.left;
121
- destWidth -= clipAmount;
122
- }
123
- // Clip top edge
124
- if (destY < containerSize.top) {
125
- const clipAmount = containerSize.top - destY;
126
- sourceY = clipAmount;
127
- sourceHeight -= clipAmount;
128
- destY = containerSize.top;
129
- destHeight -= clipAmount;
130
- }
131
- // Clip right edge
132
- const containerRight = containerSize.left + containerSize.width;
133
- if (destX + destWidth > containerRight) {
134
- const clipAmount = destX + destWidth - containerRight;
135
- sourceWidth -= clipAmount;
136
- destWidth -= clipAmount;
137
- }
138
- // Clip bottom edge
139
- const containerBottom = containerSize.top + containerSize.height;
140
- if (destY + destHeight > containerBottom) {
141
- const clipAmount = destY + destHeight - containerBottom;
142
- sourceHeight -= clipAmount;
143
- destHeight -= clipAmount;
144
- }
145
- return {
146
- sourceX,
147
- sourceY,
148
- sourceWidth,
149
- sourceHeight,
150
- destX,
151
- destY,
152
- destWidth,
153
- destHeight,
154
- };
155
- };
156
- /**
157
- * Calculates how to draw an image based on object-fit CSS property.
158
- *
159
- * @param objectFit - The CSS object-fit value
160
- * @param containerSize - The container dimensions (where the image should be drawn)
161
- * @param intrinsicSize - The natural/intrinsic size of the image
162
- * @returns Source and destination rectangles for drawImage
163
- */
164
- export const calculateObjectFit = ({ objectFit, containerSize, intrinsicSize, }) => {
165
- switch (objectFit) {
166
- case 'fill':
167
- return calculateFill({ containerSize, intrinsicSize });
168
- case 'contain':
169
- return calculateContain({ containerSize, intrinsicSize });
170
- case 'cover':
171
- return calculateCover({ containerSize, intrinsicSize });
172
- case 'none':
173
- return calculateNone({ containerSize, intrinsicSize });
174
- case 'scale-down': {
175
- // scale-down behaves like contain or none, whichever results in a smaller image
176
- const containResult = calculateContain({ containerSize, intrinsicSize });
177
- const noneResult = calculateNone({ containerSize, intrinsicSize });
178
- // Compare the rendered size - use whichever is smaller
179
- const containArea = containResult.destWidth * containResult.destHeight;
180
- const noneArea = noneResult.destWidth * noneResult.destHeight;
181
- return containArea < noneArea ? containResult : noneResult;
182
- }
183
- default: {
184
- const exhaustiveCheck = objectFit;
185
- throw new Error(`Unknown object-fit value: ${exhaustiveCheck}`);
186
- }
187
- }
188
- };
189
- /**
190
- * Parse an object-fit CSS value string into our ObjectFit type.
191
- * Returns 'fill' as the default if the value is not recognized.
192
- */
193
- export const parseObjectFit = (value) => {
194
- if (!value) {
195
- return 'fill';
196
- }
197
- const normalized = value.trim().toLowerCase();
198
- switch (normalized) {
199
- case 'fill':
200
- case 'contain':
201
- case 'cover':
202
- case 'none':
203
- case 'scale-down':
204
- return normalized;
205
- default:
206
- return 'fill';
207
- }
208
- };
@@ -1,127 +0,0 @@
1
- import { hasAnyTransformCssValue, hasTransformCssValue } from './has-transform';
2
- import { getMaskImageValue, parseMaskImage } from './mask-image';
3
- import { parseTransformOrigin } from './parse-transform-origin';
4
- const getInternalTransformOrigin = (transform) => {
5
- var _a;
6
- const centerX = transform.boundingClientRect.width / 2;
7
- const centerY = transform.boundingClientRect.height / 2;
8
- const origin = (_a = parseTransformOrigin(transform.transformOrigin)) !== null && _a !== void 0 ? _a : {
9
- x: centerX,
10
- y: centerY,
11
- };
12
- return origin;
13
- };
14
- const getGlobalTransformOrigin = ({ transform }) => {
15
- const { x: originX, y: originY } = getInternalTransformOrigin(transform);
16
- return {
17
- x: originX + transform.boundingClientRect.left,
18
- y: originY + transform.boundingClientRect.top,
19
- };
20
- };
21
- export const calculateTransforms = ({ element, rootElement, }) => {
22
- // Compute the cumulative transform by traversing parent nodes
23
- let parent = element;
24
- const transforms = [];
25
- const toReset = [];
26
- let opacity = 1;
27
- let elementComputedStyle = null;
28
- let maskImageInfo = null;
29
- while (parent) {
30
- const computedStyle = getComputedStyle(parent);
31
- if (parent === element) {
32
- elementComputedStyle = computedStyle;
33
- opacity = parseFloat(computedStyle.opacity);
34
- const maskImageValue = getMaskImageValue(computedStyle);
35
- maskImageInfo = maskImageValue ? parseMaskImage(maskImageValue) : null;
36
- const originalMaskImage = parent.style.maskImage;
37
- const originalWebkitMaskImage = parent.style.webkitMaskImage;
38
- parent.style.maskImage = 'none';
39
- parent.style.webkitMaskImage = 'none';
40
- const parentRef = parent;
41
- toReset.push(() => {
42
- parentRef.style.maskImage = originalMaskImage;
43
- parentRef.style.webkitMaskImage = originalWebkitMaskImage;
44
- });
45
- }
46
- if (hasAnyTransformCssValue(computedStyle) || parent === element) {
47
- const toParse = hasTransformCssValue(computedStyle)
48
- ? computedStyle.transform
49
- : undefined;
50
- const matrix = new DOMMatrix(toParse);
51
- const { transform, scale, rotate } = parent.style;
52
- const additionalMatrices = [];
53
- // The order of transformations is:
54
- // 1. Translate --> We do not have to consider it since it changes getClientBoundingRect()
55
- // 2. Rotate
56
- // 3. Scale
57
- // 4. CSS "transform"
58
- if (rotate !== '' && rotate !== 'none') {
59
- additionalMatrices.push(new DOMMatrix(`rotate(${rotate})`));
60
- }
61
- if (scale !== '' && scale !== 'none') {
62
- additionalMatrices.push(new DOMMatrix(`scale(${scale})`));
63
- }
64
- additionalMatrices.push(matrix);
65
- parent.style.transform = 'none';
66
- parent.style.scale = 'none';
67
- parent.style.rotate = 'none';
68
- transforms.push({
69
- element: parent,
70
- transformOrigin: computedStyle.transformOrigin,
71
- boundingClientRect: null,
72
- matrices: additionalMatrices,
73
- });
74
- const parentRef = parent;
75
- toReset.push(() => {
76
- parentRef.style.transform = transform;
77
- parentRef.style.scale = scale;
78
- parentRef.style.rotate = rotate;
79
- });
80
- }
81
- if (parent === rootElement) {
82
- break;
83
- }
84
- parent = parent.parentElement;
85
- }
86
- for (const transform of transforms) {
87
- transform.boundingClientRect = transform.element.getBoundingClientRect();
88
- }
89
- const dimensions = transforms[0].boundingClientRect;
90
- const nativeTransformOrigin = getInternalTransformOrigin(transforms[0]);
91
- const totalMatrix = new DOMMatrix();
92
- for (const transform of transforms.slice().reverse()) {
93
- for (const matrix of transform.matrices) {
94
- const globalTransformOrigin = getGlobalTransformOrigin({
95
- transform,
96
- });
97
- const transformMatrix = new DOMMatrix()
98
- .translate(globalTransformOrigin.x, globalTransformOrigin.y)
99
- .multiply(matrix)
100
- .translate(-globalTransformOrigin.x, -globalTransformOrigin.y);
101
- totalMatrix.multiplySelf(transformMatrix);
102
- }
103
- }
104
- if (!elementComputedStyle) {
105
- throw new Error('Element computed style not found');
106
- }
107
- const needs3DTransformViaWebGL = !totalMatrix.is2D;
108
- const needsMaskImage = maskImageInfo !== null;
109
- return {
110
- dimensions,
111
- totalMatrix,
112
- reset: () => {
113
- for (const reset of toReset) {
114
- reset();
115
- }
116
- },
117
- nativeTransformOrigin,
118
- computedStyle: elementComputedStyle,
119
- opacity,
120
- maskImageInfo,
121
- precompositing: {
122
- needs3DTransformViaWebGL,
123
- needsMaskImage: maskImageInfo,
124
- needsPrecompositing: Boolean(needs3DTransformViaWebGL || needsMaskImage),
125
- },
126
- };
127
- };
@@ -1,18 +0,0 @@
1
- import { roundToExpandRect } from './round-to-expand-rect';
2
- export const getNarrowerRect = ({ firstRect, secondRect, }) => {
3
- const left = Math.max(firstRect.left, secondRect.left);
4
- const top = Math.max(firstRect.top, secondRect.top);
5
- const bottom = Math.min(firstRect.bottom, secondRect.bottom);
6
- const right = Math.min(firstRect.right, secondRect.right);
7
- return new DOMRect(left, top, right - left, bottom - top);
8
- };
9
- export const getWiderRectAndExpand = ({ firstRect, secondRect, }) => {
10
- if (firstRect === null) {
11
- return roundToExpandRect(secondRect);
12
- }
13
- const left = Math.min(firstRect.left, secondRect.left);
14
- const top = Math.min(firstRect.top, secondRect.top);
15
- const bottom = Math.max(firstRect.bottom, secondRect.bottom);
16
- const right = Math.max(firstRect.right, secondRect.right);
17
- return roundToExpandRect(new DOMRect(left, top, right - left, bottom - top));
18
- };
@@ -1,6 +0,0 @@
1
- export function doRectsIntersect(rect1, rect2) {
2
- return !(rect1.right <= rect2.left ||
3
- rect1.left >= rect2.right ||
4
- rect1.bottom <= rect2.top ||
5
- rect1.top >= rect2.bottom);
6
- }
@@ -1,62 +0,0 @@
1
- import { getClippedBackground } from './get-clipped-background';
2
- import { getBoxBasedOnBackgroundClip } from './get-padding-box';
3
- import { createCanvasGradient, parseLinearGradient, } from './parse-linear-gradient';
4
- export const drawBackground = async ({ backgroundImage, context, rect, backgroundColor, backgroundClip, element, logLevel, internalState, computedStyle, offsetLeft: parentOffsetLeft, offsetTop: parentOffsetTop, }) => {
5
- let contextToDraw = context;
6
- const originalCompositeOperation = context.globalCompositeOperation;
7
- let offsetLeft = 0;
8
- let offsetTop = 0;
9
- const finish = () => {
10
- context.globalCompositeOperation = originalCompositeOperation;
11
- if (context !== contextToDraw) {
12
- context.drawImage(contextToDraw.canvas, offsetLeft, offsetTop, contextToDraw.canvas.width, contextToDraw.canvas.height);
13
- }
14
- };
15
- const boundingRect = getBoxBasedOnBackgroundClip(rect, computedStyle, backgroundClip);
16
- if (backgroundClip.includes('text')) {
17
- offsetLeft = boundingRect.left;
18
- offsetTop = boundingRect.top;
19
- const originalBackgroundClip = element.style.backgroundClip;
20
- const originalWebkitBackgroundClip = element.style.webkitBackgroundClip;
21
- element.style.backgroundClip = 'initial';
22
- element.style.webkitBackgroundClip = 'initial';
23
- const drawn = await getClippedBackground({
24
- element,
25
- boundingRect: new DOMRect(boundingRect.left + parentOffsetLeft, boundingRect.top + parentOffsetTop, boundingRect.width, boundingRect.height),
26
- logLevel,
27
- internalState,
28
- });
29
- element.style.backgroundClip = originalBackgroundClip;
30
- element.style.webkitBackgroundClip = originalWebkitBackgroundClip;
31
- contextToDraw = drawn;
32
- contextToDraw.globalCompositeOperation = 'source-in';
33
- }
34
- if (backgroundImage && backgroundImage !== 'none') {
35
- const gradientInfo = parseLinearGradient(backgroundImage);
36
- if (gradientInfo) {
37
- const gradient = createCanvasGradient({
38
- ctx: contextToDraw,
39
- rect: boundingRect,
40
- gradientInfo,
41
- offsetLeft,
42
- offsetTop,
43
- });
44
- const originalFillStyle = contextToDraw.fillStyle;
45
- contextToDraw.fillStyle = gradient;
46
- contextToDraw.fillRect(boundingRect.left - offsetLeft, boundingRect.top - offsetTop, boundingRect.width, boundingRect.height);
47
- contextToDraw.fillStyle = originalFillStyle;
48
- return finish();
49
- }
50
- }
51
- // Fallback to solid background color if no gradient was drawn
52
- if (backgroundColor &&
53
- backgroundColor !== 'transparent' &&
54
- !(backgroundColor.startsWith('rgba') &&
55
- (backgroundColor.endsWith(', 0)') || backgroundColor.endsWith(',0')))) {
56
- const originalFillStyle = contextToDraw.fillStyle;
57
- contextToDraw.fillStyle = backgroundColor;
58
- contextToDraw.fillRect(boundingRect.left - offsetLeft, boundingRect.top - offsetTop, boundingRect.width, boundingRect.height);
59
- contextToDraw.fillStyle = originalFillStyle;
60
- }
61
- finish();
62
- };