@remotion/web-renderer 4.0.421 → 4.0.423

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 (72) hide show
  1. package/dist/add-sample.js +20 -0
  2. package/dist/artifact.js +56 -0
  3. package/dist/audio.js +42 -0
  4. package/dist/can-use-webfs-target.js +19 -0
  5. package/dist/compose.js +85 -0
  6. package/dist/create-audio-sample-source.d.ts +1 -1
  7. package/dist/create-scaffold.js +104 -0
  8. package/dist/drawing/border-radius.js +151 -0
  9. package/dist/drawing/calculate-object-fit.js +208 -0
  10. package/dist/drawing/calculate-transforms.js +127 -0
  11. package/dist/drawing/clamp-rect-to-parent-bounds.js +18 -0
  12. package/dist/drawing/do-rects-intersect.js +6 -0
  13. package/dist/drawing/draw-background.js +62 -0
  14. package/dist/drawing/draw-border.js +353 -0
  15. package/dist/drawing/draw-box-shadow.js +103 -0
  16. package/dist/drawing/draw-dom-element.js +85 -0
  17. package/dist/drawing/draw-element.js +84 -0
  18. package/dist/drawing/draw-outline.js +93 -0
  19. package/dist/drawing/draw-rounded.js +34 -0
  20. package/dist/drawing/drawn-fn.js +1 -0
  21. package/dist/drawing/fit-svg-into-its-dimensions.js +35 -0
  22. package/dist/drawing/get-clipped-background.d.ts +8 -0
  23. package/dist/drawing/get-clipped-background.js +14 -0
  24. package/dist/drawing/get-padding-box.js +30 -0
  25. package/dist/drawing/get-pretransform-rect.js +49 -0
  26. package/dist/drawing/handle-3d-transform.js +26 -0
  27. package/dist/drawing/handle-mask.js +21 -0
  28. package/dist/drawing/has-transform.js +14 -0
  29. package/dist/drawing/mask-image.js +14 -0
  30. package/dist/drawing/opacity.js +7 -0
  31. package/dist/drawing/overflow.js +14 -0
  32. package/dist/drawing/parse-linear-gradient.js +260 -0
  33. package/dist/drawing/parse-transform-origin.js +7 -0
  34. package/dist/drawing/precompose.d.ts +11 -0
  35. package/dist/drawing/precompose.js +14 -0
  36. package/dist/drawing/process-node.js +122 -0
  37. package/dist/drawing/round-to-expand-rect.js +7 -0
  38. package/dist/drawing/text/apply-text-transform.js +12 -0
  39. package/dist/drawing/text/draw-text.js +53 -0
  40. package/dist/drawing/text/find-line-breaks.text.js +118 -0
  41. package/dist/drawing/text/get-collapsed-text.d.ts +1 -0
  42. package/dist/drawing/text/get-collapsed-text.js +46 -0
  43. package/dist/drawing/text/handle-text-node.js +24 -0
  44. package/dist/drawing/transform-in-3d.js +177 -0
  45. package/dist/drawing/transform-rect-with-matrix.js +19 -0
  46. package/dist/drawing/transform.js +10 -0
  47. package/dist/drawing/turn-svg-into-drawable.js +41 -0
  48. package/dist/esm/index.mjs +11 -3
  49. package/dist/frame-range.d.ts +1 -1
  50. package/dist/frame-range.js +15 -0
  51. package/dist/get-audio-encoding-config.js +18 -0
  52. package/dist/get-biggest-bounding-client-rect.js +43 -0
  53. package/dist/index.js +2 -0
  54. package/dist/internal-state.js +36 -0
  55. package/dist/mediabunny-mappings.d.ts +1 -1
  56. package/dist/mediabunny-mappings.js +63 -0
  57. package/dist/output-target.js +1 -0
  58. package/dist/props-if-has-props.js +1 -0
  59. package/dist/render-media-on-web.js +304 -0
  60. package/dist/render-operations-queue.js +3 -0
  61. package/dist/render-still-on-web.js +110 -0
  62. package/dist/send-telemetry-event.js +22 -0
  63. package/dist/take-screenshot.js +30 -0
  64. package/dist/throttle-progress.js +43 -0
  65. package/dist/tree-walker-cleanup-after-children.js +33 -0
  66. package/dist/update-time.js +17 -0
  67. package/dist/validate-video-frame.js +34 -0
  68. package/dist/wait-for-ready.js +39 -0
  69. package/dist/walk-tree.js +14 -0
  70. package/dist/web-fs-target.js +41 -0
  71. package/dist/with-resolvers.js +9 -0
  72. package/package.json +9 -8
@@ -0,0 +1,208 @@
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
+ };
@@ -0,0 +1,127 @@
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
+ };
@@ -0,0 +1,18 @@
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
+ };
@@ -0,0 +1,6 @@
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
+ }
@@ -0,0 +1,62 @@
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
+ };