@remotion/web-renderer 4.0.393 → 4.0.395
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/calculate-transforms.d.ts +9 -0
- package/dist/calculate-transforms.js +74 -0
- package/dist/composable.d.ts +10 -0
- package/dist/composable.js +1 -0
- package/dist/compose-canvas.d.ts +1 -0
- package/dist/compose-canvas.js +12 -0
- package/dist/compose-svg.d.ts +1 -0
- package/dist/compose-svg.js +34 -0
- package/dist/compose.d.ts +3 -1
- package/dist/compose.js +5 -3
- package/dist/drawing/draw-border.js +307 -55
- package/dist/drawing/draw-element-to-canvas.d.ts +3 -1
- package/dist/drawing/draw-element-to-canvas.js +16 -5
- package/dist/drawing/text/draw-text.js +6 -8
- package/dist/drawing/text/get-base-height.d.ts +1 -0
- package/dist/drawing/text/get-base-height.js +13 -0
- package/dist/drawing/text/handle-text-node.d.ts +3 -1
- package/dist/drawing/text/handle-text-node.js +2 -1
- package/dist/drawing/transform-in-3d.js +7 -1
- package/dist/drawing/turn-svg-into-drawable.js +7 -0
- package/dist/esm/index.mjs +494 -85
- package/dist/find-capturable-elements.d.ts +2 -0
- package/dist/find-capturable-elements.js +28 -0
- package/dist/get-biggest-bounding-client-rect.d.ts +1 -0
- package/dist/get-biggest-bounding-client-rect.js +18 -0
- package/dist/parse-transform-origin.d.ts +4 -0
- package/dist/parse-transform-origin.js +7 -0
- package/dist/render-media-on-web.d.ts +1 -0
- package/dist/render-media-on-web.js +33 -15
- package/dist/render-still-on-web.d.ts +1 -0
- package/dist/render-still-on-web.js +25 -7
- package/dist/send-telemetry-event.d.ts +5 -0
- package/dist/send-telemetry-event.js +22 -0
- package/dist/take-screenshot.d.ts +5 -2
- package/dist/take-screenshot.js +4 -4
- package/package.json +7 -6
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { parseTransformOrigin } from './parse-transform-origin';
|
|
2
|
+
const getInternalTransformOrigin = (transform) => {
|
|
3
|
+
var _a;
|
|
4
|
+
const centerX = transform.boundingClientRect.width / 2;
|
|
5
|
+
const centerY = transform.boundingClientRect.height / 2;
|
|
6
|
+
const origin = (_a = parseTransformOrigin(transform.transformOrigin)) !== null && _a !== void 0 ? _a : {
|
|
7
|
+
x: centerX,
|
|
8
|
+
y: centerY,
|
|
9
|
+
};
|
|
10
|
+
return origin;
|
|
11
|
+
};
|
|
12
|
+
const getGlobalTransformOrigin = (transform) => {
|
|
13
|
+
const { x: originX, y: originY } = getInternalTransformOrigin(transform);
|
|
14
|
+
return {
|
|
15
|
+
x: originX + transform.boundingClientRect.left,
|
|
16
|
+
y: originY + transform.boundingClientRect.top,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export const calculateTransforms = (element) => {
|
|
20
|
+
// Compute the cumulative transform by traversing parent nodes
|
|
21
|
+
let parent = element;
|
|
22
|
+
const transforms = [];
|
|
23
|
+
const toReset = [];
|
|
24
|
+
while (parent) {
|
|
25
|
+
const computedStyle = getComputedStyle(parent);
|
|
26
|
+
if ((computedStyle.transform && computedStyle.transform !== 'none') ||
|
|
27
|
+
parent === element) {
|
|
28
|
+
const toParse = computedStyle.transform === 'none' || computedStyle.transform === ''
|
|
29
|
+
? undefined
|
|
30
|
+
: computedStyle.transform;
|
|
31
|
+
const matrix = new DOMMatrix(toParse);
|
|
32
|
+
const { transform } = parent.style;
|
|
33
|
+
parent.style.transform = 'none';
|
|
34
|
+
transforms.push({
|
|
35
|
+
matrix,
|
|
36
|
+
rect: parent,
|
|
37
|
+
transformOrigin: computedStyle.transformOrigin,
|
|
38
|
+
boundingClientRect: null,
|
|
39
|
+
});
|
|
40
|
+
const parentRef = parent;
|
|
41
|
+
toReset.push(() => {
|
|
42
|
+
parentRef.style.transform = transform;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
parent = parent.parentElement;
|
|
46
|
+
}
|
|
47
|
+
for (const transform of transforms) {
|
|
48
|
+
transform.boundingClientRect = transform.rect.getBoundingClientRect();
|
|
49
|
+
}
|
|
50
|
+
const dimensions = transforms[0].boundingClientRect;
|
|
51
|
+
const nativeTransformOrigin = getInternalTransformOrigin(transforms[0]);
|
|
52
|
+
const totalMatrix = new DOMMatrix();
|
|
53
|
+
for (const transform of transforms.slice().reverse()) {
|
|
54
|
+
if (!transform.boundingClientRect) {
|
|
55
|
+
throw new Error('Bounding client rect not found');
|
|
56
|
+
}
|
|
57
|
+
const globalTransformOrigin = getGlobalTransformOrigin(transform);
|
|
58
|
+
const transformMatrix = new DOMMatrix()
|
|
59
|
+
.translate(globalTransformOrigin.x, globalTransformOrigin.y)
|
|
60
|
+
.multiply(transform.matrix)
|
|
61
|
+
.translate(-globalTransformOrigin.x, -globalTransformOrigin.y);
|
|
62
|
+
totalMatrix.multiplySelf(transformMatrix);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
dimensions,
|
|
66
|
+
totalMatrix,
|
|
67
|
+
reset: () => {
|
|
68
|
+
for (const reset of toReset) {
|
|
69
|
+
reset();
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
nativeTransformOrigin,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const composeCanvas: (canvas: HTMLCanvasElement | HTMLImageElement | SVGSVGElement, context: OffscreenCanvasRenderingContext2D) => Promise<void>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { calculateTransforms } from './calculate-transforms';
|
|
2
|
+
import { turnSvgIntoDrawable } from './compose-svg';
|
|
3
|
+
export const composeCanvas = async (canvas, context) => {
|
|
4
|
+
const { totalMatrix, reset, dimensions } = calculateTransforms(canvas);
|
|
5
|
+
context.setTransform(totalMatrix);
|
|
6
|
+
const drawable = canvas instanceof SVGSVGElement
|
|
7
|
+
? await turnSvgIntoDrawable(canvas)
|
|
8
|
+
: canvas;
|
|
9
|
+
context.drawImage(drawable, dimensions.left, dimensions.top, dimensions.width, dimensions.height);
|
|
10
|
+
context.setTransform(new DOMMatrix());
|
|
11
|
+
reset();
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const turnSvgIntoDrawable: (svg: SVGSVGElement) => Promise<HTMLImageElement>;
|
|
@@ -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
|
+
};
|
package/dist/compose.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import type { LogLevel } from 'remotion';
|
|
2
|
+
export declare const compose: ({ element, context, offsetLeft, offsetTop, logLevel, }: {
|
|
2
3
|
element: HTMLElement | SVGElement;
|
|
3
4
|
context: OffscreenCanvasRenderingContext2D;
|
|
4
5
|
offsetLeft: number;
|
|
5
6
|
offsetTop: number;
|
|
7
|
+
logLevel: LogLevel;
|
|
6
8
|
}) => Promise<void>;
|
package/dist/compose.js
CHANGED
|
@@ -2,7 +2,7 @@ import { drawDomElement } from './drawing/draw-dom-element';
|
|
|
2
2
|
import { drawElementToCanvas } from './drawing/draw-element-to-canvas';
|
|
3
3
|
import { handleTextNode } from './drawing/text/handle-text-node';
|
|
4
4
|
import { skipToNextNonDescendant } from './walk-tree';
|
|
5
|
-
const walkOverNode = ({ node, context, offsetLeft, offsetTop, }) => {
|
|
5
|
+
const walkOverNode = ({ node, context, offsetLeft, offsetTop, logLevel, }) => {
|
|
6
6
|
if (node instanceof HTMLElement || node instanceof SVGElement) {
|
|
7
7
|
return drawElementToCanvas({
|
|
8
8
|
element: node,
|
|
@@ -10,14 +10,15 @@ const walkOverNode = ({ node, context, offsetLeft, offsetTop, }) => {
|
|
|
10
10
|
draw: drawDomElement(node),
|
|
11
11
|
offsetLeft,
|
|
12
12
|
offsetTop,
|
|
13
|
+
logLevel,
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
16
|
if (node instanceof Text) {
|
|
16
|
-
return handleTextNode({ node, context, offsetLeft, offsetTop });
|
|
17
|
+
return handleTextNode({ node, context, offsetLeft, offsetTop, logLevel });
|
|
17
18
|
}
|
|
18
19
|
throw new Error('Unknown node type');
|
|
19
20
|
};
|
|
20
|
-
export const compose = async ({ element, context, offsetLeft, offsetTop, }) => {
|
|
21
|
+
export const compose = async ({ element, context, offsetLeft, offsetTop, logLevel, }) => {
|
|
21
22
|
const treeWalker = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, (node) => {
|
|
22
23
|
if (node instanceof Element) {
|
|
23
24
|
// SVG does have children, but we process SVG elements in its
|
|
@@ -38,6 +39,7 @@ export const compose = async ({ element, context, offsetLeft, offsetTop, }) => {
|
|
|
38
39
|
context,
|
|
39
40
|
offsetLeft,
|
|
40
41
|
offsetTop,
|
|
42
|
+
logLevel,
|
|
41
43
|
});
|
|
42
44
|
if (val === 'skip-children') {
|
|
43
45
|
if (!skipToNextNonDescendant(treeWalker)) {
|
|
@@ -1,88 +1,205 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
ctx.
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
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 -
|
|
49
|
-
vertical: Math.max(0, borderRadius.topLeft.vertical -
|
|
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 -
|
|
53
|
-
vertical: Math.max(0, borderRadius.topRight.vertical -
|
|
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 -
|
|
57
|
-
vertical: Math.max(0, borderRadius.bottomRight.vertical -
|
|
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 -
|
|
61
|
-
vertical: Math.max(0, borderRadius.bottomLeft.vertical -
|
|
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 +
|
|
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 +
|
|
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 +
|
|
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 +
|
|
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 +
|
|
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 +
|
|
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
|
-
|
|
213
|
+
};
|
|
214
|
+
export const drawBorder = ({ ctx, x, y, width, height, 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,
|
|
244
|
+
y,
|
|
245
|
+
width,
|
|
246
|
+
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,
|
|
259
|
+
y,
|
|
260
|
+
width,
|
|
261
|
+
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,
|
|
272
|
+
y,
|
|
273
|
+
width,
|
|
274
|
+
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,
|
|
285
|
+
y,
|
|
286
|
+
width,
|
|
287
|
+
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,
|
|
298
|
+
y,
|
|
299
|
+
width,
|
|
300
|
+
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,
|
|
312
|
+
y,
|
|
313
|
+
width,
|
|
314
|
+
height,
|
|
315
|
+
borderRadius,
|
|
316
|
+
borderProperties: borders.top,
|
|
317
|
+
});
|
|
318
|
+
drawBorderSide({
|
|
319
|
+
ctx,
|
|
320
|
+
side: 'right',
|
|
321
|
+
x,
|
|
322
|
+
y,
|
|
323
|
+
width,
|
|
324
|
+
height,
|
|
325
|
+
borderRadius,
|
|
326
|
+
borderProperties: borders.right,
|
|
327
|
+
});
|
|
328
|
+
drawBorderSide({
|
|
329
|
+
ctx,
|
|
330
|
+
side: 'bottom',
|
|
331
|
+
x,
|
|
332
|
+
y,
|
|
333
|
+
width,
|
|
334
|
+
height,
|
|
335
|
+
borderRadius,
|
|
336
|
+
borderProperties: borders.bottom,
|
|
337
|
+
});
|
|
338
|
+
drawBorderSide({
|
|
339
|
+
ctx,
|
|
340
|
+
side: 'left',
|
|
341
|
+
x,
|
|
342
|
+
y,
|
|
343
|
+
width,
|
|
344
|
+
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,11 @@
|
|
|
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, }: {
|
|
4
5
|
element: HTMLElement | SVGElement;
|
|
5
6
|
context: OffscreenCanvasRenderingContext2D;
|
|
6
7
|
draw: DrawFn;
|
|
7
8
|
offsetLeft: number;
|
|
8
9
|
offsetTop: number;
|
|
10
|
+
logLevel: LogLevel;
|
|
9
11
|
}) => Promise<DrawElementToCanvasReturnValue>;
|