@remotion/web-renderer 4.0.430 → 4.0.432
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/dist/can-render-types.d.ts +2 -2
- package/dist/esm/index.mjs +274 -94
- package/dist/index.d.ts +1 -1
- package/dist/mediabunny-mappings.d.ts +6 -4
- package/dist/register-mp3-encoder.d.ts +1 -0
- package/dist/render-media-on-web.d.ts +1 -1
- package/package.json +9 -8
- package/dist/add-sample.js +0 -20
- package/dist/artifact.js +0 -56
- package/dist/audio.js +0 -42
- package/dist/can-use-webfs-target.js +0 -19
- package/dist/compose.js +0 -85
- package/dist/create-scaffold.js +0 -104
- package/dist/drawing/border-radius.js +0 -151
- package/dist/drawing/calculate-object-fit.js +0 -208
- package/dist/drawing/calculate-transforms.js +0 -127
- package/dist/drawing/clamp-rect-to-parent-bounds.js +0 -18
- package/dist/drawing/do-rects-intersect.js +0 -6
- package/dist/drawing/draw-background.js +0 -62
- package/dist/drawing/draw-border.js +0 -353
- package/dist/drawing/draw-box-shadow.js +0 -103
- package/dist/drawing/draw-dom-element.js +0 -85
- package/dist/drawing/draw-element.js +0 -84
- package/dist/drawing/draw-outline.js +0 -93
- package/dist/drawing/draw-rounded.js +0 -34
- package/dist/drawing/drawn-fn.js +0 -1
- package/dist/drawing/fit-svg-into-its-dimensions.js +0 -35
- package/dist/drawing/get-clipped-background.d.ts +0 -8
- package/dist/drawing/get-clipped-background.js +0 -14
- package/dist/drawing/get-padding-box.js +0 -30
- package/dist/drawing/get-pretransform-rect.js +0 -49
- package/dist/drawing/handle-3d-transform.js +0 -26
- package/dist/drawing/handle-mask.js +0 -21
- package/dist/drawing/has-transform.js +0 -14
- package/dist/drawing/mask-image.js +0 -14
- package/dist/drawing/opacity.js +0 -7
- package/dist/drawing/overflow.js +0 -14
- package/dist/drawing/parse-linear-gradient.js +0 -260
- package/dist/drawing/parse-transform-origin.js +0 -7
- package/dist/drawing/precompose.d.ts +0 -11
- package/dist/drawing/precompose.js +0 -14
- package/dist/drawing/process-node.js +0 -122
- package/dist/drawing/round-to-expand-rect.js +0 -7
- package/dist/drawing/text/apply-text-transform.js +0 -12
- package/dist/drawing/text/draw-text.js +0 -53
- package/dist/drawing/text/find-line-breaks.text.js +0 -118
- package/dist/drawing/text/get-collapsed-text.d.ts +0 -1
- package/dist/drawing/text/get-collapsed-text.js +0 -46
- package/dist/drawing/text/handle-text-node.js +0 -24
- package/dist/drawing/transform-in-3d.js +0 -177
- package/dist/drawing/transform-rect-with-matrix.js +0 -19
- package/dist/drawing/transform.js +0 -10
- package/dist/drawing/turn-svg-into-drawable.js +0 -41
- package/dist/frame-range.js +0 -15
- package/dist/get-audio-encoding-config.js +0 -18
- package/dist/get-biggest-bounding-client-rect.js +0 -43
- package/dist/index.js +0 -2
- package/dist/internal-state.js +0 -36
- package/dist/mediabunny-mappings.js +0 -63
- package/dist/output-target.js +0 -1
- package/dist/props-if-has-props.js +0 -1
- package/dist/render-media-on-web.js +0 -304
- package/dist/render-operations-queue.js +0 -3
- package/dist/render-still-on-web.js +0 -110
- package/dist/send-telemetry-event.js +0 -22
- package/dist/take-screenshot.js +0 -30
- package/dist/throttle-progress.js +0 -43
- package/dist/tree-walker-cleanup-after-children.js +0 -33
- package/dist/update-time.js +0 -17
- package/dist/validate-video-frame.js +0 -34
- package/dist/wait-for-ready.js +0 -39
- package/dist/walk-tree.js +0 -14
- package/dist/web-fs-target.js +0 -41
- package/dist/with-resolvers.js +0 -9
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
const parseBorderWidth = (value) => {
|
|
2
|
-
return parseFloat(value) || 0;
|
|
3
|
-
};
|
|
4
|
-
const getBorderSideProperties = (computedStyle) => {
|
|
5
|
-
// Parse individual border properties for each side
|
|
6
|
-
// This handles both shorthand (border: "1px solid red") and longhand (border-top-width: "1px") properties
|
|
7
|
-
return {
|
|
8
|
-
top: {
|
|
9
|
-
width: parseBorderWidth(computedStyle.borderTopWidth),
|
|
10
|
-
color: computedStyle.borderTopColor || computedStyle.borderColor || 'black',
|
|
11
|
-
style: computedStyle.borderTopStyle || computedStyle.borderStyle || 'solid',
|
|
12
|
-
},
|
|
13
|
-
right: {
|
|
14
|
-
width: parseBorderWidth(computedStyle.borderRightWidth),
|
|
15
|
-
color: computedStyle.borderRightColor || computedStyle.borderColor || 'black',
|
|
16
|
-
style: computedStyle.borderRightStyle || computedStyle.borderStyle || 'solid',
|
|
17
|
-
},
|
|
18
|
-
bottom: {
|
|
19
|
-
width: parseBorderWidth(computedStyle.borderBottomWidth),
|
|
20
|
-
color: computedStyle.borderBottomColor || computedStyle.borderColor || 'black',
|
|
21
|
-
style: computedStyle.borderBottomStyle || computedStyle.borderStyle || 'solid',
|
|
22
|
-
},
|
|
23
|
-
left: {
|
|
24
|
-
width: parseBorderWidth(computedStyle.borderLeftWidth),
|
|
25
|
-
color: computedStyle.borderLeftColor || computedStyle.borderColor || 'black',
|
|
26
|
-
style: computedStyle.borderLeftStyle || computedStyle.borderStyle || 'solid',
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
const getLineDashPattern = (style, width) => {
|
|
31
|
-
if (style === 'dashed') {
|
|
32
|
-
return [width * 2, width];
|
|
33
|
-
}
|
|
34
|
-
if (style === 'dotted') {
|
|
35
|
-
return [width, width];
|
|
36
|
-
}
|
|
37
|
-
return [];
|
|
38
|
-
};
|
|
39
|
-
const drawBorderSide = ({ ctx, side, x, y, width, height, borderRadius, borderProperties, }) => {
|
|
40
|
-
const { width: borderWidth, color, style } = borderProperties;
|
|
41
|
-
if (borderWidth <= 0 || style === 'none' || style === 'hidden') {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
ctx.beginPath();
|
|
45
|
-
ctx.strokeStyle = color;
|
|
46
|
-
ctx.lineWidth = borderWidth;
|
|
47
|
-
ctx.setLineDash(getLineDashPattern(style, borderWidth));
|
|
48
|
-
const halfWidth = borderWidth / 2;
|
|
49
|
-
if (side === 'top') {
|
|
50
|
-
// Start point (accounting for left border and top-left radius)
|
|
51
|
-
const startX = x + borderRadius.topLeft.horizontal;
|
|
52
|
-
const startY = y + halfWidth;
|
|
53
|
-
// End point (accounting for top-right radius)
|
|
54
|
-
const endX = x + width - borderRadius.topRight.horizontal;
|
|
55
|
-
const endY = y + halfWidth;
|
|
56
|
-
ctx.moveTo(startX, startY);
|
|
57
|
-
ctx.lineTo(endX, endY);
|
|
58
|
-
}
|
|
59
|
-
else if (side === 'right') {
|
|
60
|
-
// Start point (accounting for top border and top-right radius)
|
|
61
|
-
const startX = x + width - halfWidth;
|
|
62
|
-
const startY = y + borderRadius.topRight.vertical;
|
|
63
|
-
// End point (accounting for bottom-right radius)
|
|
64
|
-
const endX = x + width - halfWidth;
|
|
65
|
-
const endY = y + height - borderRadius.bottomRight.vertical;
|
|
66
|
-
ctx.moveTo(startX, startY);
|
|
67
|
-
ctx.lineTo(endX, endY);
|
|
68
|
-
}
|
|
69
|
-
else if (side === 'bottom') {
|
|
70
|
-
// Start point (accounting for bottom-left radius)
|
|
71
|
-
const startX = x + borderRadius.bottomLeft.horizontal;
|
|
72
|
-
const startY = y + height - halfWidth;
|
|
73
|
-
// End point (accounting for right border and bottom-right radius)
|
|
74
|
-
const endX = x + width - borderRadius.bottomRight.horizontal;
|
|
75
|
-
const endY = y + height - halfWidth;
|
|
76
|
-
ctx.moveTo(startX, startY);
|
|
77
|
-
ctx.lineTo(endX, endY);
|
|
78
|
-
}
|
|
79
|
-
else if (side === 'left') {
|
|
80
|
-
// Start point (accounting for top-left radius)
|
|
81
|
-
const startX = x + halfWidth;
|
|
82
|
-
const startY = y + borderRadius.topLeft.vertical;
|
|
83
|
-
// End point (accounting for bottom border and bottom-left radius)
|
|
84
|
-
const endX = x + halfWidth;
|
|
85
|
-
const endY = y + height - borderRadius.bottomLeft.vertical;
|
|
86
|
-
ctx.moveTo(startX, startY);
|
|
87
|
-
ctx.lineTo(endX, endY);
|
|
88
|
-
}
|
|
89
|
-
ctx.stroke();
|
|
90
|
-
};
|
|
91
|
-
const drawCorner = ({ ctx, corner, x, y, width, height, borderRadius, topBorder, rightBorder, bottomBorder, leftBorder, }) => {
|
|
92
|
-
const radius = borderRadius[corner];
|
|
93
|
-
if (radius.horizontal <= 0 && radius.vertical <= 0) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
let border1;
|
|
97
|
-
let border2;
|
|
98
|
-
let centerX;
|
|
99
|
-
let centerY;
|
|
100
|
-
let startAngle;
|
|
101
|
-
let endAngle;
|
|
102
|
-
if (corner === 'topLeft') {
|
|
103
|
-
border1 = leftBorder;
|
|
104
|
-
border2 = topBorder;
|
|
105
|
-
centerX = x + radius.horizontal;
|
|
106
|
-
centerY = y + radius.vertical;
|
|
107
|
-
startAngle = Math.PI;
|
|
108
|
-
endAngle = (Math.PI * 3) / 2;
|
|
109
|
-
}
|
|
110
|
-
else if (corner === 'topRight') {
|
|
111
|
-
border1 = topBorder;
|
|
112
|
-
border2 = rightBorder;
|
|
113
|
-
centerX = x + width - radius.horizontal;
|
|
114
|
-
centerY = y + radius.vertical;
|
|
115
|
-
startAngle = -Math.PI / 2;
|
|
116
|
-
endAngle = 0;
|
|
117
|
-
}
|
|
118
|
-
else if (corner === 'bottomRight') {
|
|
119
|
-
border1 = rightBorder;
|
|
120
|
-
border2 = bottomBorder;
|
|
121
|
-
centerX = x + width - radius.horizontal;
|
|
122
|
-
centerY = y + height - radius.vertical;
|
|
123
|
-
startAngle = 0;
|
|
124
|
-
endAngle = Math.PI / 2;
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
// bottomLeft
|
|
128
|
-
border1 = bottomBorder;
|
|
129
|
-
border2 = leftBorder;
|
|
130
|
-
centerX = x + radius.horizontal;
|
|
131
|
-
centerY = y + height - radius.vertical;
|
|
132
|
-
startAngle = Math.PI / 2;
|
|
133
|
-
endAngle = Math.PI;
|
|
134
|
-
}
|
|
135
|
-
// Draw corner arc - use the average of the two adjacent borders
|
|
136
|
-
// In a more sophisticated implementation, we could blend the two borders
|
|
137
|
-
const avgWidth = (border1.width + border2.width) / 2;
|
|
138
|
-
const useColor = border1.width >= border2.width ? border1.color : border2.color;
|
|
139
|
-
const useStyle = border1.width >= border2.width ? border1.style : border2.style;
|
|
140
|
-
if (avgWidth > 0 && useStyle !== 'none' && useStyle !== 'hidden') {
|
|
141
|
-
ctx.beginPath();
|
|
142
|
-
ctx.strokeStyle = useColor;
|
|
143
|
-
ctx.lineWidth = avgWidth;
|
|
144
|
-
ctx.setLineDash(getLineDashPattern(useStyle, avgWidth));
|
|
145
|
-
// Adjust radius for the border width
|
|
146
|
-
const adjustedRadiusH = Math.max(0, radius.horizontal - avgWidth / 2);
|
|
147
|
-
const adjustedRadiusV = Math.max(0, radius.vertical - avgWidth / 2);
|
|
148
|
-
ctx.ellipse(centerX, centerY, adjustedRadiusH, adjustedRadiusV, 0, startAngle, endAngle);
|
|
149
|
-
ctx.stroke();
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
const drawUniformBorder = ({ ctx, x, y, width, height, borderRadius, borderWidth, borderColor, borderStyle, }) => {
|
|
153
|
-
ctx.beginPath();
|
|
154
|
-
ctx.strokeStyle = borderColor;
|
|
155
|
-
ctx.lineWidth = borderWidth;
|
|
156
|
-
ctx.setLineDash(getLineDashPattern(borderStyle, borderWidth));
|
|
157
|
-
const halfWidth = borderWidth / 2;
|
|
158
|
-
const borderX = x + halfWidth;
|
|
159
|
-
const borderY = y + halfWidth;
|
|
160
|
-
const borderW = width - borderWidth;
|
|
161
|
-
const borderH = height - borderWidth;
|
|
162
|
-
// Adjust border radius for the border width
|
|
163
|
-
const adjustedBorderRadius = {
|
|
164
|
-
topLeft: {
|
|
165
|
-
horizontal: Math.max(0, borderRadius.topLeft.horizontal - halfWidth),
|
|
166
|
-
vertical: Math.max(0, borderRadius.topLeft.vertical - halfWidth),
|
|
167
|
-
},
|
|
168
|
-
topRight: {
|
|
169
|
-
horizontal: Math.max(0, borderRadius.topRight.horizontal - halfWidth),
|
|
170
|
-
vertical: Math.max(0, borderRadius.topRight.vertical - halfWidth),
|
|
171
|
-
},
|
|
172
|
-
bottomRight: {
|
|
173
|
-
horizontal: Math.max(0, borderRadius.bottomRight.horizontal - halfWidth),
|
|
174
|
-
vertical: Math.max(0, borderRadius.bottomRight.vertical - halfWidth),
|
|
175
|
-
},
|
|
176
|
-
bottomLeft: {
|
|
177
|
-
horizontal: Math.max(0, borderRadius.bottomLeft.horizontal - halfWidth),
|
|
178
|
-
vertical: Math.max(0, borderRadius.bottomLeft.vertical - halfWidth),
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
|
-
// Draw continuous path with border radius
|
|
182
|
-
ctx.moveTo(borderX + adjustedBorderRadius.topLeft.horizontal, borderY);
|
|
183
|
-
// Top edge
|
|
184
|
-
ctx.lineTo(borderX + borderW - adjustedBorderRadius.topRight.horizontal, borderY);
|
|
185
|
-
// Top-right corner
|
|
186
|
-
if (adjustedBorderRadius.topRight.horizontal > 0 ||
|
|
187
|
-
adjustedBorderRadius.topRight.vertical > 0) {
|
|
188
|
-
ctx.ellipse(borderX + borderW - adjustedBorderRadius.topRight.horizontal, borderY + adjustedBorderRadius.topRight.vertical, adjustedBorderRadius.topRight.horizontal, adjustedBorderRadius.topRight.vertical, 0, -Math.PI / 2, 0);
|
|
189
|
-
}
|
|
190
|
-
// Right edge
|
|
191
|
-
ctx.lineTo(borderX + borderW, borderY + borderH - adjustedBorderRadius.bottomRight.vertical);
|
|
192
|
-
// Bottom-right corner
|
|
193
|
-
if (adjustedBorderRadius.bottomRight.horizontal > 0 ||
|
|
194
|
-
adjustedBorderRadius.bottomRight.vertical > 0) {
|
|
195
|
-
ctx.ellipse(borderX + borderW - adjustedBorderRadius.bottomRight.horizontal, borderY + borderH - adjustedBorderRadius.bottomRight.vertical, adjustedBorderRadius.bottomRight.horizontal, adjustedBorderRadius.bottomRight.vertical, 0, 0, Math.PI / 2);
|
|
196
|
-
}
|
|
197
|
-
// Bottom edge
|
|
198
|
-
ctx.lineTo(borderX + adjustedBorderRadius.bottomLeft.horizontal, borderY + borderH);
|
|
199
|
-
// Bottom-left corner
|
|
200
|
-
if (adjustedBorderRadius.bottomLeft.horizontal > 0 ||
|
|
201
|
-
adjustedBorderRadius.bottomLeft.vertical > 0) {
|
|
202
|
-
ctx.ellipse(borderX + adjustedBorderRadius.bottomLeft.horizontal, borderY + borderH - adjustedBorderRadius.bottomLeft.vertical, adjustedBorderRadius.bottomLeft.horizontal, adjustedBorderRadius.bottomLeft.vertical, 0, Math.PI / 2, Math.PI);
|
|
203
|
-
}
|
|
204
|
-
// Left edge
|
|
205
|
-
ctx.lineTo(borderX, borderY + adjustedBorderRadius.topLeft.vertical);
|
|
206
|
-
// Top-left corner
|
|
207
|
-
if (adjustedBorderRadius.topLeft.horizontal > 0 ||
|
|
208
|
-
adjustedBorderRadius.topLeft.vertical > 0) {
|
|
209
|
-
ctx.ellipse(borderX + adjustedBorderRadius.topLeft.horizontal, borderY + adjustedBorderRadius.topLeft.vertical, adjustedBorderRadius.topLeft.horizontal, adjustedBorderRadius.topLeft.vertical, 0, Math.PI, (Math.PI * 3) / 2);
|
|
210
|
-
}
|
|
211
|
-
ctx.closePath();
|
|
212
|
-
ctx.stroke();
|
|
213
|
-
};
|
|
214
|
-
export const drawBorder = ({ ctx, rect, borderRadius, computedStyle, }) => {
|
|
215
|
-
const borders = getBorderSideProperties(computedStyle);
|
|
216
|
-
// Check if we have any visible border
|
|
217
|
-
const hasBorder = borders.top.width > 0 ||
|
|
218
|
-
borders.right.width > 0 ||
|
|
219
|
-
borders.bottom.width > 0 ||
|
|
220
|
-
borders.left.width > 0;
|
|
221
|
-
if (!hasBorder) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
// Save original canvas state
|
|
225
|
-
const originalStrokeStyle = ctx.strokeStyle;
|
|
226
|
-
const originalLineWidth = ctx.lineWidth;
|
|
227
|
-
const originalLineDash = ctx.getLineDash();
|
|
228
|
-
// Check if all borders are uniform (same width, color, and style)
|
|
229
|
-
const allSidesEqual = borders.top.width === borders.right.width &&
|
|
230
|
-
borders.top.width === borders.bottom.width &&
|
|
231
|
-
borders.top.width === borders.left.width &&
|
|
232
|
-
borders.top.color === borders.right.color &&
|
|
233
|
-
borders.top.color === borders.bottom.color &&
|
|
234
|
-
borders.top.color === borders.left.color &&
|
|
235
|
-
borders.top.style === borders.right.style &&
|
|
236
|
-
borders.top.style === borders.bottom.style &&
|
|
237
|
-
borders.top.style === borders.left.style &&
|
|
238
|
-
borders.top.width > 0;
|
|
239
|
-
if (allSidesEqual) {
|
|
240
|
-
// Draw as a single continuous border for continuous dashing
|
|
241
|
-
drawUniformBorder({
|
|
242
|
-
ctx,
|
|
243
|
-
x: rect.left,
|
|
244
|
-
y: rect.top,
|
|
245
|
-
width: rect.width,
|
|
246
|
-
height: rect.height,
|
|
247
|
-
borderRadius,
|
|
248
|
-
borderWidth: borders.top.width,
|
|
249
|
-
borderColor: borders.top.color,
|
|
250
|
-
borderStyle: borders.top.style,
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
// Draw corners first (they go underneath the straight edges)
|
|
255
|
-
drawCorner({
|
|
256
|
-
ctx,
|
|
257
|
-
corner: 'topLeft',
|
|
258
|
-
x: rect.left,
|
|
259
|
-
y: rect.top,
|
|
260
|
-
width: rect.width,
|
|
261
|
-
height: rect.height,
|
|
262
|
-
borderRadius,
|
|
263
|
-
topBorder: borders.top,
|
|
264
|
-
rightBorder: borders.right,
|
|
265
|
-
bottomBorder: borders.bottom,
|
|
266
|
-
leftBorder: borders.left,
|
|
267
|
-
});
|
|
268
|
-
drawCorner({
|
|
269
|
-
ctx,
|
|
270
|
-
corner: 'topRight',
|
|
271
|
-
x: rect.left,
|
|
272
|
-
y: rect.top,
|
|
273
|
-
width: rect.width,
|
|
274
|
-
height: rect.height,
|
|
275
|
-
borderRadius,
|
|
276
|
-
topBorder: borders.top,
|
|
277
|
-
rightBorder: borders.right,
|
|
278
|
-
bottomBorder: borders.bottom,
|
|
279
|
-
leftBorder: borders.left,
|
|
280
|
-
});
|
|
281
|
-
drawCorner({
|
|
282
|
-
ctx,
|
|
283
|
-
corner: 'bottomRight',
|
|
284
|
-
x: rect.left,
|
|
285
|
-
y: rect.top,
|
|
286
|
-
width: rect.width,
|
|
287
|
-
height: rect.height,
|
|
288
|
-
borderRadius,
|
|
289
|
-
topBorder: borders.top,
|
|
290
|
-
rightBorder: borders.right,
|
|
291
|
-
bottomBorder: borders.bottom,
|
|
292
|
-
leftBorder: borders.left,
|
|
293
|
-
});
|
|
294
|
-
drawCorner({
|
|
295
|
-
ctx,
|
|
296
|
-
corner: 'bottomLeft',
|
|
297
|
-
x: rect.left,
|
|
298
|
-
y: rect.top,
|
|
299
|
-
width: rect.width,
|
|
300
|
-
height: rect.height,
|
|
301
|
-
borderRadius,
|
|
302
|
-
topBorder: borders.top,
|
|
303
|
-
rightBorder: borders.right,
|
|
304
|
-
bottomBorder: borders.bottom,
|
|
305
|
-
leftBorder: borders.left,
|
|
306
|
-
});
|
|
307
|
-
// Draw each border side
|
|
308
|
-
drawBorderSide({
|
|
309
|
-
ctx,
|
|
310
|
-
side: 'top',
|
|
311
|
-
x: rect.left,
|
|
312
|
-
y: rect.top,
|
|
313
|
-
width: rect.width,
|
|
314
|
-
height: rect.height,
|
|
315
|
-
borderRadius,
|
|
316
|
-
borderProperties: borders.top,
|
|
317
|
-
});
|
|
318
|
-
drawBorderSide({
|
|
319
|
-
ctx,
|
|
320
|
-
side: 'right',
|
|
321
|
-
x: rect.left,
|
|
322
|
-
y: rect.top,
|
|
323
|
-
width: rect.width,
|
|
324
|
-
height: rect.height,
|
|
325
|
-
borderRadius,
|
|
326
|
-
borderProperties: borders.right,
|
|
327
|
-
});
|
|
328
|
-
drawBorderSide({
|
|
329
|
-
ctx,
|
|
330
|
-
side: 'bottom',
|
|
331
|
-
x: rect.left,
|
|
332
|
-
y: rect.top,
|
|
333
|
-
width: rect.width,
|
|
334
|
-
height: rect.height,
|
|
335
|
-
borderRadius,
|
|
336
|
-
borderProperties: borders.bottom,
|
|
337
|
-
});
|
|
338
|
-
drawBorderSide({
|
|
339
|
-
ctx,
|
|
340
|
-
side: 'left',
|
|
341
|
-
x: rect.left,
|
|
342
|
-
y: rect.top,
|
|
343
|
-
width: rect.width,
|
|
344
|
-
height: rect.height,
|
|
345
|
-
borderRadius,
|
|
346
|
-
borderProperties: borders.left,
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
// Restore original canvas state
|
|
350
|
-
ctx.strokeStyle = originalStrokeStyle;
|
|
351
|
-
ctx.lineWidth = originalLineWidth;
|
|
352
|
-
ctx.setLineDash(originalLineDash);
|
|
353
|
-
};
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { Internals } from 'remotion';
|
|
2
|
-
import { drawRoundedRectPath } from './draw-rounded';
|
|
3
|
-
export const parseBoxShadow = (boxShadowValue) => {
|
|
4
|
-
if (!boxShadowValue || boxShadowValue === 'none') {
|
|
5
|
-
return [];
|
|
6
|
-
}
|
|
7
|
-
const shadows = [];
|
|
8
|
-
// Split by comma, but respect rgba() colors
|
|
9
|
-
const shadowStrings = boxShadowValue.split(/,(?![^(]*\))/);
|
|
10
|
-
for (const shadowStr of shadowStrings) {
|
|
11
|
-
const trimmed = shadowStr.trim();
|
|
12
|
-
if (!trimmed || trimmed === 'none') {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
const shadow = {
|
|
16
|
-
offsetX: 0,
|
|
17
|
-
offsetY: 0,
|
|
18
|
-
blurRadius: 0,
|
|
19
|
-
color: 'rgba(0, 0, 0, 0.5)',
|
|
20
|
-
inset: false,
|
|
21
|
-
};
|
|
22
|
-
// Check for inset
|
|
23
|
-
shadow.inset = /\binset\b/i.test(trimmed);
|
|
24
|
-
// Remove 'inset' keyword
|
|
25
|
-
let remaining = trimmed.replace(/\binset\b/gi, '').trim();
|
|
26
|
-
// Extract color (can be rgb(), rgba(), hsl(), hsla(), hex, or named color)
|
|
27
|
-
const colorMatch = remaining.match(/(rgba?\([^)]+\)|hsla?\([^)]+\)|#[0-9a-f]{3,8}|[a-z]+)/i);
|
|
28
|
-
if (colorMatch) {
|
|
29
|
-
shadow.color = colorMatch[0];
|
|
30
|
-
remaining = remaining.replace(colorMatch[0], '').trim();
|
|
31
|
-
}
|
|
32
|
-
// Parse remaining numeric values (offset-x offset-y blur spread)
|
|
33
|
-
const numbers = remaining.match(/[+-]?\d*\.?\d+(?:px|em|rem|%)?/gi) || [];
|
|
34
|
-
const values = numbers.map((n) => parseFloat(n) || 0);
|
|
35
|
-
if (values.length >= 2) {
|
|
36
|
-
shadow.offsetX = values[0];
|
|
37
|
-
shadow.offsetY = values[1];
|
|
38
|
-
if (values.length >= 3) {
|
|
39
|
-
shadow.blurRadius = Math.max(0, values[2]); // Blur cannot be negative
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
shadows.push(shadow);
|
|
43
|
-
}
|
|
44
|
-
return shadows;
|
|
45
|
-
};
|
|
46
|
-
export const drawBorderRadius = ({ ctx, rect, borderRadius, computedStyle, logLevel, }) => {
|
|
47
|
-
const shadows = parseBoxShadow(computedStyle.boxShadow);
|
|
48
|
-
if (shadows.length === 0) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
// Draw shadows from last to first (so first shadow appears on top)
|
|
52
|
-
for (let i = shadows.length - 1; i >= 0; i--) {
|
|
53
|
-
const shadow = shadows[i];
|
|
54
|
-
const newLeft = rect.left + Math.min(shadow.offsetX, 0) - shadow.blurRadius;
|
|
55
|
-
const newRight = rect.right + Math.max(shadow.offsetX, 0) + shadow.blurRadius;
|
|
56
|
-
const newTop = rect.top + Math.min(shadow.offsetY, 0) - shadow.blurRadius;
|
|
57
|
-
const newBottom = rect.bottom + Math.max(shadow.offsetY, 0) + shadow.blurRadius;
|
|
58
|
-
const newRect = new DOMRect(newLeft, newTop, newRight - newLeft, newBottom - newTop);
|
|
59
|
-
const leftOffset = rect.left - newLeft;
|
|
60
|
-
const topOffset = rect.top - newTop;
|
|
61
|
-
const newCanvas = new OffscreenCanvas(newRect.width, newRect.height);
|
|
62
|
-
const newCtx = newCanvas.getContext('2d');
|
|
63
|
-
if (!newCtx) {
|
|
64
|
-
throw new Error('Failed to get context');
|
|
65
|
-
}
|
|
66
|
-
if (shadow.inset) {
|
|
67
|
-
// TODO: Only warn once per render.
|
|
68
|
-
Internals.Log.warn({
|
|
69
|
-
logLevel,
|
|
70
|
-
tag: '@remotion/web-renderer',
|
|
71
|
-
}, 'Detected "box-shadow" with "inset". This is not yet supported in @remotion/web-renderer');
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
// Apply shadow properties to canvas
|
|
75
|
-
newCtx.shadowBlur = shadow.blurRadius;
|
|
76
|
-
newCtx.shadowColor = shadow.color;
|
|
77
|
-
newCtx.shadowOffsetX = shadow.offsetX;
|
|
78
|
-
newCtx.shadowOffsetY = shadow.offsetY;
|
|
79
|
-
newCtx.fillStyle = 'black';
|
|
80
|
-
drawRoundedRectPath({
|
|
81
|
-
ctx: newCtx,
|
|
82
|
-
x: leftOffset,
|
|
83
|
-
y: topOffset,
|
|
84
|
-
width: rect.width,
|
|
85
|
-
height: rect.height,
|
|
86
|
-
borderRadius,
|
|
87
|
-
});
|
|
88
|
-
newCtx.fill();
|
|
89
|
-
// Cut out the shape, leaving only shadow
|
|
90
|
-
newCtx.shadowColor = 'transparent';
|
|
91
|
-
newCtx.globalCompositeOperation = 'destination-out';
|
|
92
|
-
drawRoundedRectPath({
|
|
93
|
-
ctx: newCtx,
|
|
94
|
-
x: leftOffset,
|
|
95
|
-
y: topOffset,
|
|
96
|
-
width: rect.width,
|
|
97
|
-
height: rect.height,
|
|
98
|
-
borderRadius,
|
|
99
|
-
});
|
|
100
|
-
newCtx.fill();
|
|
101
|
-
ctx.drawImage(newCanvas, rect.left - leftOffset, rect.top - topOffset);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { calculateObjectFit, parseObjectFit } from './calculate-object-fit';
|
|
2
|
-
import { fitSvgIntoItsContainer } from './fit-svg-into-its-dimensions';
|
|
3
|
-
import { turnSvgIntoDrawable } from './turn-svg-into-drawable';
|
|
4
|
-
const getReadableImageError = (err, node) => {
|
|
5
|
-
if (!(err instanceof DOMException)) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
if (err.name === 'SecurityError') {
|
|
9
|
-
return new Error(`Could not draw image with src="${node.src}" to canvas: ` +
|
|
10
|
-
`The image is tainted due to CORS restrictions. ` +
|
|
11
|
-
`The server hosting this image must respond with the "Access-Control-Allow-Origin" header. ` +
|
|
12
|
-
`See: https://remotion.dev/docs/client-side-rendering/migration`);
|
|
13
|
-
}
|
|
14
|
-
if (err.name === 'InvalidStateError') {
|
|
15
|
-
return new Error(`Could not draw image with src="${node.src}" to canvas: ` +
|
|
16
|
-
`The image is in a broken state. ` +
|
|
17
|
-
`This usually means the image failed to load - check that the URL is valid and accessible.`);
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Draw an SVG element using "contain" behavior (the default for SVGs).
|
|
23
|
-
*/
|
|
24
|
-
const drawSvg = ({ drawable, dimensions, contextToDraw, }) => {
|
|
25
|
-
const fitted = fitSvgIntoItsContainer({
|
|
26
|
-
containerSize: dimensions,
|
|
27
|
-
elementSize: {
|
|
28
|
-
width: drawable.width,
|
|
29
|
-
height: drawable.height,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
contextToDraw.drawImage(drawable, fitted.left, fitted.top, fitted.width, fitted.height);
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Draw an image or canvas element using the object-fit CSS property.
|
|
36
|
-
*/
|
|
37
|
-
const drawReplacedElement = ({ drawable, dimensions, computedStyle, contextToDraw, }) => {
|
|
38
|
-
const objectFit = parseObjectFit(computedStyle.objectFit);
|
|
39
|
-
const intrinsicSize = drawable instanceof HTMLImageElement
|
|
40
|
-
? { width: drawable.naturalWidth, height: drawable.naturalHeight }
|
|
41
|
-
: { width: drawable.width, height: drawable.height };
|
|
42
|
-
const result = calculateObjectFit({
|
|
43
|
-
objectFit,
|
|
44
|
-
containerSize: {
|
|
45
|
-
width: dimensions.width,
|
|
46
|
-
height: dimensions.height,
|
|
47
|
-
left: dimensions.left,
|
|
48
|
-
top: dimensions.top,
|
|
49
|
-
},
|
|
50
|
-
intrinsicSize,
|
|
51
|
-
});
|
|
52
|
-
// Use the 9-argument drawImage to support source cropping (for cover mode)
|
|
53
|
-
contextToDraw.drawImage(drawable, result.sourceX, result.sourceY, result.sourceWidth, result.sourceHeight, result.destX, result.destY, result.destWidth, result.destHeight);
|
|
54
|
-
};
|
|
55
|
-
export const drawDomElement = (node) => {
|
|
56
|
-
const domDrawFn = async ({ dimensions, contextToDraw, computedStyle, }) => {
|
|
57
|
-
// Handle SVG elements separately - they use "contain" behavior by default
|
|
58
|
-
if (node instanceof SVGSVGElement) {
|
|
59
|
-
const drawable = await turnSvgIntoDrawable(node);
|
|
60
|
-
drawSvg({ drawable, dimensions, contextToDraw });
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
// Handle replaced elements (img, canvas) with object-fit support
|
|
64
|
-
if (node instanceof HTMLImageElement || node instanceof HTMLCanvasElement) {
|
|
65
|
-
try {
|
|
66
|
-
drawReplacedElement({
|
|
67
|
-
drawable: node,
|
|
68
|
-
dimensions,
|
|
69
|
-
computedStyle,
|
|
70
|
-
contextToDraw,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
catch (err) {
|
|
74
|
-
if (node instanceof HTMLImageElement) {
|
|
75
|
-
const readableError = getReadableImageError(err, node);
|
|
76
|
-
if (readableError) {
|
|
77
|
-
throw readableError;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
throw err;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
return domDrawFn;
|
|
85
|
-
};
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { parseBorderRadius, setBorderRadius } from './border-radius';
|
|
2
|
-
import { drawBackground } from './draw-background';
|
|
3
|
-
import { drawBorder } from './draw-border';
|
|
4
|
-
import { drawBorderRadius } from './draw-box-shadow';
|
|
5
|
-
import { drawOutline } from './draw-outline';
|
|
6
|
-
import { setOpacity } from './opacity';
|
|
7
|
-
import { setOverflowHidden } from './overflow';
|
|
8
|
-
import { setTransform } from './transform';
|
|
9
|
-
export const drawElement = async ({ rect, computedStyle, context, draw, opacity, totalMatrix, parentRect, logLevel, element, internalState, }) => {
|
|
10
|
-
const { backgroundImage, backgroundColor, backgroundClip } = computedStyle;
|
|
11
|
-
const borderRadius = parseBorderRadius({
|
|
12
|
-
borderRadius: computedStyle.borderRadius,
|
|
13
|
-
width: rect.width,
|
|
14
|
-
height: rect.height,
|
|
15
|
-
});
|
|
16
|
-
const finishTransform = setTransform({
|
|
17
|
-
ctx: context,
|
|
18
|
-
transform: totalMatrix,
|
|
19
|
-
parentRect,
|
|
20
|
-
});
|
|
21
|
-
const finishOpacity = setOpacity({
|
|
22
|
-
ctx: context,
|
|
23
|
-
opacity,
|
|
24
|
-
});
|
|
25
|
-
// Draw box shadow before border radius clip and background
|
|
26
|
-
drawBorderRadius({
|
|
27
|
-
ctx: context,
|
|
28
|
-
computedStyle,
|
|
29
|
-
rect,
|
|
30
|
-
borderRadius,
|
|
31
|
-
logLevel,
|
|
32
|
-
});
|
|
33
|
-
const finishBorderRadius = setBorderRadius({
|
|
34
|
-
ctx: context,
|
|
35
|
-
rect,
|
|
36
|
-
borderRadius,
|
|
37
|
-
forceClipEvenWhenZero: false,
|
|
38
|
-
computedStyle,
|
|
39
|
-
backgroundClip,
|
|
40
|
-
});
|
|
41
|
-
await drawBackground({
|
|
42
|
-
backgroundImage,
|
|
43
|
-
context,
|
|
44
|
-
rect,
|
|
45
|
-
backgroundColor,
|
|
46
|
-
backgroundClip,
|
|
47
|
-
element,
|
|
48
|
-
logLevel,
|
|
49
|
-
internalState,
|
|
50
|
-
computedStyle,
|
|
51
|
-
offsetLeft: parentRect.left,
|
|
52
|
-
offsetTop: parentRect.top,
|
|
53
|
-
});
|
|
54
|
-
await draw({ dimensions: rect, computedStyle, contextToDraw: context });
|
|
55
|
-
finishBorderRadius();
|
|
56
|
-
drawBorder({
|
|
57
|
-
ctx: context,
|
|
58
|
-
rect,
|
|
59
|
-
borderRadius,
|
|
60
|
-
computedStyle,
|
|
61
|
-
});
|
|
62
|
-
// Drawing outline ignores overflow: hidden, finishing it and starting a new one for the outline
|
|
63
|
-
drawOutline({
|
|
64
|
-
ctx: context,
|
|
65
|
-
rect,
|
|
66
|
-
borderRadius,
|
|
67
|
-
computedStyle,
|
|
68
|
-
});
|
|
69
|
-
const finishOverflowHidden = setOverflowHidden({
|
|
70
|
-
ctx: context,
|
|
71
|
-
rect,
|
|
72
|
-
borderRadius,
|
|
73
|
-
overflowHidden: computedStyle.overflow === 'hidden',
|
|
74
|
-
computedStyle,
|
|
75
|
-
backgroundClip,
|
|
76
|
-
});
|
|
77
|
-
finishTransform();
|
|
78
|
-
return {
|
|
79
|
-
cleanupAfterChildren: () => {
|
|
80
|
-
finishOpacity();
|
|
81
|
-
finishOverflowHidden();
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
};
|