@remotion/web-renderer 4.0.394 → 4.0.396

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/border-radius.d.ts +31 -0
  2. package/dist/border-radius.js +152 -0
  3. package/dist/calculate-transforms.d.ts +2 -0
  4. package/dist/calculate-transforms.js +17 -0
  5. package/dist/composable.d.ts +2 -8
  6. package/dist/compose-canvas.js +28 -4
  7. package/dist/compose.d.ts +6 -3
  8. package/dist/compose.js +41 -12
  9. package/dist/drawing/border-radius.d.ts +3 -5
  10. package/dist/drawing/border-radius.js +12 -11
  11. package/dist/drawing/calculate-transforms.d.ts +6 -2
  12. package/dist/drawing/calculate-transforms.js +19 -22
  13. package/dist/drawing/canvas-offset-from-rect.d.ts +8 -0
  14. package/dist/drawing/canvas-offset-from-rect.js +12 -0
  15. package/dist/drawing/clamp-rect-to-parent-bounds.d.ts +4 -0
  16. package/dist/drawing/clamp-rect-to-parent-bounds.js +7 -0
  17. package/dist/drawing/compose-canvas.d.ts +1 -0
  18. package/dist/drawing/compose-canvas.js +36 -0
  19. package/dist/drawing/compose-svg.d.ts +1 -0
  20. package/dist/drawing/compose-svg.js +34 -0
  21. package/dist/drawing/compose.d.ts +5 -0
  22. package/dist/drawing/compose.js +6 -0
  23. package/dist/drawing/draw-border.d.ts +2 -5
  24. package/dist/drawing/draw-border.js +307 -55
  25. package/dist/drawing/draw-element-to-canvas.d.ts +4 -1
  26. package/dist/drawing/draw-element-to-canvas.js +9 -26
  27. package/dist/drawing/draw-element.d.ts +5 -3
  28. package/dist/drawing/draw-element.js +29 -14
  29. package/dist/drawing/draw-outline.d.ts +9 -0
  30. package/dist/drawing/draw-outline.js +116 -0
  31. package/dist/drawing/get-bounding-box-including-shadow.d.ts +1 -0
  32. package/dist/drawing/get-bounding-box-including-shadow.js +6 -0
  33. package/dist/drawing/get-computed-style-cache.d.ts +0 -0
  34. package/dist/drawing/get-computed-style-cache.js +1 -0
  35. package/dist/drawing/get-pretransform-rect.d.ts +1 -0
  36. package/dist/drawing/get-pretransform-rect.js +31 -0
  37. package/dist/drawing/handle-3d-transform.d.ts +10 -0
  38. package/dist/drawing/handle-3d-transform.js +39 -0
  39. package/dist/drawing/has-transform.d.ts +4 -0
  40. package/dist/drawing/has-transform.js +14 -0
  41. package/dist/drawing/overflow.d.ts +7 -0
  42. package/dist/drawing/overflow.js +12 -0
  43. package/dist/drawing/process-node.d.ts +17 -0
  44. package/dist/drawing/process-node.js +41 -0
  45. package/dist/drawing/text/draw-text.js +6 -8
  46. package/dist/drawing/text/handle-text-node.d.ts +8 -5
  47. package/dist/drawing/text/handle-text-node.js +6 -5
  48. package/dist/drawing/transform-in-3d.d.ts +7 -7
  49. package/dist/drawing/transform-in-3d.js +27 -13
  50. package/dist/drawing/transform-rect-with-matrix.d.ts +4 -0
  51. package/dist/drawing/transform-rect-with-matrix.js +19 -0
  52. package/dist/drawing/turn-svg-into-drawable.js +7 -0
  53. package/dist/esm/index.mjs +897 -205
  54. package/dist/find-canvas-elements.d.ts +1 -0
  55. package/dist/find-canvas-elements.js +13 -0
  56. package/dist/find-capturable-elements.d.ts +1 -1
  57. package/dist/find-capturable-elements.js +20 -22
  58. package/dist/get-biggest-bounding-client-rect.js +18 -5
  59. package/dist/internal-state.d.ts +9 -0
  60. package/dist/internal-state.js +12 -0
  61. package/dist/opacity.d.ts +4 -0
  62. package/dist/opacity.js +7 -0
  63. package/dist/render-media-on-web.d.ts +3 -0
  64. package/dist/render-media-on-web.js +38 -15
  65. package/dist/render-still-on-web.d.ts +6 -1
  66. package/dist/render-still-on-web.js +29 -8
  67. package/dist/send-telemetry-event.js +1 -1
  68. package/dist/take-screenshot.d.ts +8 -2
  69. package/dist/take-screenshot.js +16 -4
  70. package/dist/transform.d.ts +4 -0
  71. package/dist/transform.js +6 -0
  72. package/package.json +7 -6
@@ -0,0 +1,34 @@
1
+ export const turnSvgIntoDrawable = (svg) => {
2
+ const originalTransform = svg.style.transform;
3
+ const originalTransformOrigin = svg.style.transformOrigin;
4
+ const originalMarginLeft = svg.style.marginLeft;
5
+ const originalMarginRight = svg.style.marginRight;
6
+ const originalMarginTop = svg.style.marginTop;
7
+ const originalMarginBottom = svg.style.marginBottom;
8
+ svg.style.transform = 'none';
9
+ svg.style.transformOrigin = '';
10
+ // Margins were already included in the positioning calculation,
11
+ // so we need to remove them to avoid double counting.
12
+ svg.style.marginLeft = '0';
13
+ svg.style.marginRight = '0';
14
+ svg.style.marginTop = '0';
15
+ svg.style.marginBottom = '0';
16
+ const svgData = new XMLSerializer().serializeToString(svg);
17
+ svg.style.marginLeft = originalMarginLeft;
18
+ svg.style.marginRight = originalMarginRight;
19
+ svg.style.marginTop = originalMarginTop;
20
+ svg.style.marginBottom = originalMarginBottom;
21
+ svg.style.transform = originalTransform;
22
+ svg.style.transformOrigin = originalTransformOrigin;
23
+ return new Promise((resolve, reject) => {
24
+ const image = new Image();
25
+ const url = `data:image/svg+xml;base64,${btoa(svgData)}`;
26
+ image.onload = function () {
27
+ resolve(image);
28
+ };
29
+ image.onerror = () => {
30
+ reject(new Error('Failed to convert SVG to image'));
31
+ };
32
+ image.src = url;
33
+ });
34
+ };
@@ -0,0 +1,5 @@
1
+ import type { Composable } from '../composable';
2
+ export declare const compose: ({ composables, context, }: {
3
+ composables: Composable[];
4
+ context: OffscreenCanvasRenderingContext2D;
5
+ }) => Promise<void>;
@@ -0,0 +1,6 @@
1
+ import { drawElementToCanvas } from './draw-element-to-canvas';
2
+ export const compose = async ({ composables, context, }) => {
3
+ for (const composable of composables) {
4
+ await drawElementToCanvas(composable.element, context);
5
+ }
6
+ };
@@ -1,10 +1,7 @@
1
1
  import type { BorderRadiusCorners } from './border-radius';
2
- export declare const drawBorder: ({ ctx, x, y, width, height, borderRadius, computedStyle, }: {
2
+ export declare const drawBorder: ({ ctx, rect, borderRadius, computedStyle, }: {
3
3
  ctx: OffscreenCanvasRenderingContext2D;
4
- x: number;
5
- y: number;
6
- width: number;
7
- height: number;
4
+ rect: DOMRect;
8
5
  borderRadius: BorderRadiusCorners;
9
6
  computedStyle: CSSStyleDeclaration;
10
7
  }) => void;
@@ -1,88 +1,205 @@
1
- export const drawBorder = ({ ctx, x, y, width, height, borderRadius, computedStyle, }) => {
2
- const { borderStyle, borderColor, borderWidth: computedBorderWidth, } = computedStyle;
3
- // Parse border width (can be shorthand like "1px 2px 3px 4px")
4
- const borderWidths = computedBorderWidth
5
- .split(/\s+/)
6
- .map((w) => parseFloat(w));
7
- const borderTop = borderWidths[0] || 0;
8
- const borderRight = borderWidths[1] || borderTop;
9
- const borderBottom = borderWidths[2] || borderTop;
10
- const borderLeft = borderWidths[3] || borderRight;
11
- // Check if we have a visible border
12
- const hasBorder = borderStyle &&
13
- borderStyle !== 'none' &&
14
- borderStyle !== 'hidden' &&
15
- (borderTop > 0 || borderRight > 0 || borderBottom > 0 || borderLeft > 0);
16
- if (!hasBorder) {
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') {
17
42
  return;
18
43
  }
19
- const originalStrokeStyle = ctx.strokeStyle;
20
- const originalLineWidth = ctx.lineWidth;
21
- const originalLineDash = ctx.getLineDash();
22
- ctx.strokeStyle = borderColor;
23
- // Set line dash based on border style
24
- if (borderStyle === 'dashed') {
25
- const max = Math.max(borderTop, borderRight, borderBottom, borderLeft);
26
- ctx.setLineDash([max * 2, max]);
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);
27
88
  }
28
- else if (borderStyle === 'dotted') {
29
- ctx.setLineDash([
30
- Math.max(borderTop, borderRight, borderBottom, borderLeft),
31
- ]);
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;
32
125
  }
33
126
  else {
34
- ctx.setLineDash([]);
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();
35
150
  }
36
- // For simplicity, use the maximum border width if they differ
37
- // A full implementation would draw each side separately
38
- const maxBorderWidth = Math.max(borderTop, borderRight, borderBottom, borderLeft);
39
- // Create path for border (inset by half the border width to draw inside)
151
+ };
152
+ const drawUniformBorder = ({ ctx, x, y, width, height, borderRadius, borderWidth, borderColor, borderStyle, }) => {
40
153
  ctx.beginPath();
41
- const borderX = x + maxBorderWidth / 2;
42
- const borderY = y + maxBorderWidth / 2;
43
- const borderWidth = width - maxBorderWidth;
44
- const borderHeight = height - maxBorderWidth;
45
- // Account for border radius, adjusted for the border width
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
46
163
  const adjustedBorderRadius = {
47
164
  topLeft: {
48
- horizontal: Math.max(0, borderRadius.topLeft.horizontal - maxBorderWidth / 2),
49
- vertical: Math.max(0, borderRadius.topLeft.vertical - maxBorderWidth / 2),
165
+ horizontal: Math.max(0, borderRadius.topLeft.horizontal - halfWidth),
166
+ vertical: Math.max(0, borderRadius.topLeft.vertical - halfWidth),
50
167
  },
51
168
  topRight: {
52
- horizontal: Math.max(0, borderRadius.topRight.horizontal - maxBorderWidth / 2),
53
- vertical: Math.max(0, borderRadius.topRight.vertical - maxBorderWidth / 2),
169
+ horizontal: Math.max(0, borderRadius.topRight.horizontal - halfWidth),
170
+ vertical: Math.max(0, borderRadius.topRight.vertical - halfWidth),
54
171
  },
55
172
  bottomRight: {
56
- horizontal: Math.max(0, borderRadius.bottomRight.horizontal - maxBorderWidth / 2),
57
- vertical: Math.max(0, borderRadius.bottomRight.vertical - maxBorderWidth / 2),
173
+ horizontal: Math.max(0, borderRadius.bottomRight.horizontal - halfWidth),
174
+ vertical: Math.max(0, borderRadius.bottomRight.vertical - halfWidth),
58
175
  },
59
176
  bottomLeft: {
60
- horizontal: Math.max(0, borderRadius.bottomLeft.horizontal - maxBorderWidth / 2),
61
- vertical: Math.max(0, borderRadius.bottomLeft.vertical - maxBorderWidth / 2),
177
+ horizontal: Math.max(0, borderRadius.bottomLeft.horizontal - halfWidth),
178
+ vertical: Math.max(0, borderRadius.bottomLeft.vertical - halfWidth),
62
179
  },
63
180
  };
64
- // Draw path with border radius
181
+ // Draw continuous path with border radius
65
182
  ctx.moveTo(borderX + adjustedBorderRadius.topLeft.horizontal, borderY);
66
183
  // Top edge
67
- ctx.lineTo(borderX + borderWidth - adjustedBorderRadius.topRight.horizontal, borderY);
184
+ ctx.lineTo(borderX + borderW - adjustedBorderRadius.topRight.horizontal, borderY);
68
185
  // Top-right corner
69
186
  if (adjustedBorderRadius.topRight.horizontal > 0 ||
70
187
  adjustedBorderRadius.topRight.vertical > 0) {
71
- ctx.ellipse(borderX + borderWidth - adjustedBorderRadius.topRight.horizontal, borderY + adjustedBorderRadius.topRight.vertical, adjustedBorderRadius.topRight.horizontal, adjustedBorderRadius.topRight.vertical, 0, -Math.PI / 2, 0);
188
+ ctx.ellipse(borderX + borderW - adjustedBorderRadius.topRight.horizontal, borderY + adjustedBorderRadius.topRight.vertical, adjustedBorderRadius.topRight.horizontal, adjustedBorderRadius.topRight.vertical, 0, -Math.PI / 2, 0);
72
189
  }
73
190
  // Right edge
74
- ctx.lineTo(borderX + borderWidth, borderY + borderHeight - adjustedBorderRadius.bottomRight.vertical);
191
+ ctx.lineTo(borderX + borderW, borderY + borderH - adjustedBorderRadius.bottomRight.vertical);
75
192
  // Bottom-right corner
76
193
  if (adjustedBorderRadius.bottomRight.horizontal > 0 ||
77
194
  adjustedBorderRadius.bottomRight.vertical > 0) {
78
- ctx.ellipse(borderX + borderWidth - adjustedBorderRadius.bottomRight.horizontal, borderY + borderHeight - adjustedBorderRadius.bottomRight.vertical, adjustedBorderRadius.bottomRight.horizontal, adjustedBorderRadius.bottomRight.vertical, 0, 0, Math.PI / 2);
195
+ ctx.ellipse(borderX + borderW - adjustedBorderRadius.bottomRight.horizontal, borderY + borderH - adjustedBorderRadius.bottomRight.vertical, adjustedBorderRadius.bottomRight.horizontal, adjustedBorderRadius.bottomRight.vertical, 0, 0, Math.PI / 2);
79
196
  }
80
197
  // Bottom edge
81
- ctx.lineTo(borderX + adjustedBorderRadius.bottomLeft.horizontal, borderY + borderHeight);
198
+ ctx.lineTo(borderX + adjustedBorderRadius.bottomLeft.horizontal, borderY + borderH);
82
199
  // Bottom-left corner
83
200
  if (adjustedBorderRadius.bottomLeft.horizontal > 0 ||
84
201
  adjustedBorderRadius.bottomLeft.vertical > 0) {
85
- ctx.ellipse(borderX + adjustedBorderRadius.bottomLeft.horizontal, borderY + borderHeight - adjustedBorderRadius.bottomLeft.vertical, adjustedBorderRadius.bottomLeft.horizontal, adjustedBorderRadius.bottomLeft.vertical, 0, Math.PI / 2, Math.PI);
202
+ ctx.ellipse(borderX + adjustedBorderRadius.bottomLeft.horizontal, borderY + borderH - adjustedBorderRadius.bottomLeft.vertical, adjustedBorderRadius.bottomLeft.horizontal, adjustedBorderRadius.bottomLeft.vertical, 0, Math.PI / 2, Math.PI);
86
203
  }
87
204
  // Left edge
88
205
  ctx.lineTo(borderX, borderY + adjustedBorderRadius.topLeft.vertical);
@@ -92,9 +209,144 @@ export const drawBorder = ({ ctx, x, y, width, height, borderRadius, computedSty
92
209
  ctx.ellipse(borderX + adjustedBorderRadius.topLeft.horizontal, borderY + adjustedBorderRadius.topLeft.vertical, adjustedBorderRadius.topLeft.horizontal, adjustedBorderRadius.topLeft.vertical, 0, Math.PI, (Math.PI * 3) / 2);
93
210
  }
94
211
  ctx.closePath();
95
- ctx.lineWidth = maxBorderWidth;
96
212
  ctx.stroke();
97
- // Restore original values
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
98
350
  ctx.strokeStyle = originalStrokeStyle;
99
351
  ctx.lineWidth = originalLineWidth;
100
352
  ctx.setLineDash(originalLineDash);
@@ -1,9 +1,12 @@
1
+ import type { LogLevel } from 'remotion';
1
2
  import type { DrawFn } from './drawn-fn';
2
3
  export type DrawElementToCanvasReturnValue = 'continue' | 'skip-children';
3
- export declare const drawElementToCanvas: ({ element, context, draw, offsetLeft, offsetTop, }: {
4
+ export declare const drawElementToCanvas: ({ element, context, draw, offsetLeft, offsetTop, logLevel, parentRect, }: {
4
5
  element: HTMLElement | SVGElement;
5
6
  context: OffscreenCanvasRenderingContext2D;
6
7
  draw: DrawFn;
7
8
  offsetLeft: number;
8
9
  offsetTop: number;
10
+ logLevel: LogLevel;
11
+ parentRect: DOMRect;
9
12
  }) => Promise<DrawElementToCanvasReturnValue>;
@@ -1,9 +1,9 @@
1
- import { compose } from '../compose';
2
1
  import { calculateTransforms } from './calculate-transforms';
3
2
  import { drawElement } from './draw-element';
4
- import { transformIn3d } from './transform-in-3d';
5
- export const drawElementToCanvas = async ({ element, context, draw, offsetLeft, offsetTop, }) => {
6
- const { totalMatrix, reset, dimensions, opacity, computedStyle } = calculateTransforms(element);
3
+ import { handle3dTransform } from './handle-3d-transform';
4
+ export const drawElementToCanvas = async ({ element, context, draw, offsetLeft, offsetTop, logLevel, parentRect, }) => {
5
+ const transforms = calculateTransforms({ element, offsetLeft, offsetTop });
6
+ const { totalMatrix, reset, dimensions, opacity, computedStyle } = transforms;
7
7
  if (opacity === 0) {
8
8
  reset();
9
9
  return 'continue';
@@ -13,30 +13,13 @@ export const drawElementToCanvas = async ({ element, context, draw, offsetLeft,
13
13
  return 'continue';
14
14
  }
15
15
  if (!totalMatrix.is2D) {
16
- const canvasOffsetLeft = Math.min(dimensions.left, 0);
17
- const canvasOffsetTop = Math.min(dimensions.top, 0);
18
- const tempCanvasWidth = Math.max(dimensions.width, dimensions.right);
19
- const tempCanvasHeight = Math.max(dimensions.height, dimensions.bottom);
20
- const tempCanvas = new OffscreenCanvas(tempCanvasWidth, tempCanvasHeight);
21
- const context2 = tempCanvas.getContext('2d');
22
- if (!context2) {
23
- throw new Error('Could not get context');
24
- }
25
- await compose({
16
+ await handle3dTransform({
26
17
  element,
27
- context: context2,
28
- offsetLeft: canvasOffsetLeft,
29
- offsetTop: canvasOffsetTop,
18
+ totalMatrix,
19
+ parentRect,
20
+ context,
21
+ logLevel,
30
22
  });
31
- const transformed = transformIn3d({
32
- canvasWidth: tempCanvasWidth,
33
- canvasHeight: tempCanvasHeight,
34
- matrix: totalMatrix,
35
- sourceCanvas: tempCanvas,
36
- offsetLeft: canvasOffsetLeft,
37
- offsetTop: canvasOffsetTop,
38
- });
39
- context.drawImage(transformed, 0, 0);
40
23
  reset();
41
24
  return 'skip-children';
42
25
  }
@@ -1,9 +1,11 @@
1
1
  import type { DrawFn } from './drawn-fn';
2
- export declare const drawElement: ({ dimensions, computedStyle, context, draw, opacity, totalMatrix, }: {
3
- dimensions: DOMRect;
2
+ export declare const drawElement: ({ rect, computedStyle, context, draw, opacity, totalMatrix, }: {
3
+ rect: DOMRect;
4
4
  computedStyle: CSSStyleDeclaration;
5
5
  context: OffscreenCanvasRenderingContext2D;
6
6
  opacity: number;
7
7
  totalMatrix: DOMMatrix;
8
8
  draw: DrawFn;
9
- }) => Promise<void>;
9
+ }) => Promise<{
10
+ cleanupAfterChildren: () => void;
11
+ }>;
@@ -1,13 +1,15 @@
1
1
  import { parseBorderRadius, setBorderRadius } from './border-radius';
2
2
  import { drawBorder } from './draw-border';
3
+ import { drawOutline } from './draw-outline';
3
4
  import { setOpacity } from './opacity';
5
+ import { setOverflowHidden } from './overflow';
4
6
  import { setTransform } from './transform';
5
- export const drawElement = async ({ dimensions, computedStyle, context, draw, opacity, totalMatrix, }) => {
7
+ export const drawElement = async ({ rect, computedStyle, context, draw, opacity, totalMatrix, }) => {
6
8
  const background = computedStyle.backgroundColor;
7
9
  const borderRadius = parseBorderRadius({
8
10
  borderRadius: computedStyle.borderRadius,
9
- width: dimensions.width,
10
- height: dimensions.height,
11
+ width: rect.width,
12
+ height: rect.height,
11
13
  });
12
14
  const finishTransform = setTransform({
13
15
  ctx: context,
@@ -15,11 +17,9 @@ export const drawElement = async ({ dimensions, computedStyle, context, draw, op
15
17
  });
16
18
  const finishBorderRadius = setBorderRadius({
17
19
  ctx: context,
18
- x: dimensions.left,
19
- y: dimensions.top,
20
- width: dimensions.width,
21
- height: dimensions.height,
20
+ rect,
22
21
  borderRadius,
22
+ forceClipEvenWhenZero: false,
23
23
  });
24
24
  const finishOpacity = setOpacity({
25
25
  ctx: context,
@@ -31,20 +31,35 @@ export const drawElement = async ({ dimensions, computedStyle, context, draw, op
31
31
  (background.endsWith(', 0)') || background.endsWith(',0')))) {
32
32
  const originalFillStyle = context.fillStyle;
33
33
  context.fillStyle = background;
34
- context.fillRect(dimensions.left, dimensions.top, dimensions.width, dimensions.height);
34
+ context.fillRect(rect.left, rect.top, rect.width, rect.height);
35
35
  context.fillStyle = originalFillStyle;
36
36
  }
37
- await draw({ dimensions, computedStyle, contextToDraw: context });
37
+ await draw({ dimensions: rect, computedStyle, contextToDraw: context });
38
38
  drawBorder({
39
39
  ctx: context,
40
- x: dimensions.left,
41
- y: dimensions.top,
42
- width: dimensions.width,
43
- height: dimensions.height,
40
+ rect,
44
41
  borderRadius,
45
42
  computedStyle,
46
43
  });
47
- finishOpacity();
48
44
  finishBorderRadius();
45
+ // Drawing outline ignores overflow: hidden, finishing it and starting a new one for the outline
46
+ drawOutline({
47
+ ctx: context,
48
+ rect,
49
+ borderRadius,
50
+ computedStyle,
51
+ });
52
+ const finishOverflowHidden = setOverflowHidden({
53
+ ctx: context,
54
+ rect,
55
+ borderRadius,
56
+ overflowHidden: computedStyle.overflow === 'hidden',
57
+ });
49
58
  finishTransform();
59
+ return {
60
+ cleanupAfterChildren: () => {
61
+ finishOpacity();
62
+ finishOverflowHidden();
63
+ },
64
+ };
50
65
  };
@@ -0,0 +1,9 @@
1
+ import type { BorderRadiusCorners } from './border-radius';
2
+ export declare const parseOutlineWidth: (value: string) => number;
3
+ export declare const parseOutlineOffset: (value: string) => number;
4
+ export declare const drawOutline: ({ ctx, rect, borderRadius, computedStyle, }: {
5
+ ctx: OffscreenCanvasRenderingContext2D;
6
+ rect: DOMRect;
7
+ borderRadius: BorderRadiusCorners;
8
+ computedStyle: CSSStyleDeclaration;
9
+ }) => void;