@remotion/web-renderer 4.0.396 → 4.0.398
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/artifact.d.ts +2 -2
- package/dist/compose.js +11 -5
- package/dist/create-scaffold.js +10 -3
- package/dist/drawing/border-radius.js +9 -32
- package/dist/drawing/calculate-transforms.d.ts +9 -3
- package/dist/drawing/calculate-transforms.js +31 -9
- package/dist/drawing/clamp-rect-to-parent-bounds.d.ts +4 -0
- package/dist/drawing/clamp-rect-to-parent-bounds.js +11 -0
- package/dist/drawing/do-rects-intersect.d.ts +1 -0
- package/dist/drawing/do-rects-intersect.js +6 -0
- package/dist/drawing/draw-box-shadow.d.ts +18 -0
- package/dist/drawing/draw-box-shadow.js +103 -0
- package/dist/drawing/draw-element.d.ts +4 -1
- package/dist/drawing/draw-element.js +37 -6
- package/dist/drawing/draw-outline.js +9 -32
- package/dist/drawing/draw-rounded.d.ts +9 -0
- package/dist/drawing/draw-rounded.js +34 -0
- package/dist/drawing/get-pretransform-rect.js +5 -0
- package/dist/drawing/handle-3d-transform.d.ts +9 -8
- package/dist/drawing/handle-3d-transform.js +11 -25
- package/dist/drawing/handle-mask.d.ts +8 -0
- package/dist/drawing/handle-mask.js +19 -0
- package/dist/drawing/mask-image.d.ts +3 -0
- package/dist/drawing/mask-image.js +14 -0
- package/dist/drawing/parse-linear-gradient.d.ts +14 -0
- package/dist/drawing/parse-linear-gradient.js +260 -0
- package/dist/drawing/precompose.d.ts +11 -0
- package/dist/drawing/precompose.js +13 -0
- package/dist/drawing/process-node.d.ts +4 -3
- package/dist/drawing/process-node.js +89 -14
- package/dist/drawing/round-to-expand-rect.d.ts +1 -0
- package/dist/drawing/round-to-expand-rect.js +7 -0
- package/dist/drawing/text/draw-text.d.ts +5 -1
- package/dist/drawing/text/draw-text.js +10 -5
- package/dist/drawing/text/find-line-breaks.text.d.ts +1 -1
- package/dist/drawing/text/find-line-breaks.text.js +2 -2
- package/dist/drawing/text/handle-text-node.d.ts +2 -1
- package/dist/drawing/text/handle-text-node.js +3 -2
- package/dist/drawing/transform-in-3d.d.ts +3 -1
- package/dist/drawing/transform-in-3d.js +30 -28
- package/dist/drawing/transform.d.ts +2 -1
- package/dist/drawing/transform.js +6 -2
- package/dist/esm/index.mjs +797 -215
- package/dist/get-biggest-bounding-client-rect.js +19 -4
- package/dist/index.d.ts +4 -2
- package/dist/internal-state.d.ts +2 -2
- package/dist/internal-state.js +7 -7
- package/dist/mediabunny-mappings.d.ts +3 -3
- package/dist/render-media-on-web.d.ts +5 -4
- package/dist/render-media-on-web.js +29 -16
- package/dist/render-still-on-web.d.ts +2 -2
- package/dist/send-telemetry-event.js +1 -1
- package/package.json +6 -6
|
@@ -1,39 +1,25 @@
|
|
|
1
|
-
import { Internals } from 'remotion';
|
|
2
|
-
import { compose } from '../compose';
|
|
3
1
|
import { getBiggestBoundingClientRect } from '../get-biggest-bounding-client-rect';
|
|
4
2
|
import { getNarrowerRect } from './clamp-rect-to-parent-bounds';
|
|
5
3
|
import { getPreTransformRect } from './get-pretransform-rect';
|
|
6
4
|
import { transformIn3d } from './transform-in-3d';
|
|
7
|
-
export const
|
|
5
|
+
export const getPrecomposeRectFor3DTransform = ({ element, parentRect, matrix, }) => {
|
|
8
6
|
const unclampedBiggestBoundingClientRect = getBiggestBoundingClientRect(element);
|
|
9
7
|
const biggestPossiblePretransformRect = getPreTransformRect(parentRect, matrix);
|
|
10
8
|
const preTransformRect = getNarrowerRect({
|
|
11
9
|
firstRect: unclampedBiggestBoundingClientRect,
|
|
12
10
|
secondRect: biggestPossiblePretransformRect,
|
|
13
11
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
logLevel,
|
|
20
|
-
parentRect: preTransformRect,
|
|
21
|
-
internalState,
|
|
22
|
-
});
|
|
23
|
-
const afterCompose = Date.now();
|
|
24
|
-
const { canvas: transformed, rect: transformedRect } = transformIn3d({
|
|
25
|
-
untransformedRect: preTransformRect,
|
|
12
|
+
return preTransformRect;
|
|
13
|
+
};
|
|
14
|
+
export const handle3dTransform = ({ matrix, precomposeRect, tempCanvas, rectAfterTransforms, }) => {
|
|
15
|
+
const { canvas: transformed, rect: transformedRect, cleanup, } = transformIn3d({
|
|
16
|
+
untransformedRect: precomposeRect,
|
|
26
17
|
matrix,
|
|
27
18
|
sourceCanvas: tempCanvas,
|
|
19
|
+
rectAfterTransforms,
|
|
28
20
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
tag: '@remotion/web-renderer',
|
|
34
|
-
}, `Transforming element in 3D - canvas size: ${transformedRect.width}x${transformedRect.height} - compose: ${afterCompose - start}ms - draw: ${afterDraw - afterCompose}ms`);
|
|
35
|
-
internalState.add3DTransform({
|
|
36
|
-
canvasWidth: Math.ceil(transformedRect.width),
|
|
37
|
-
canvasHeight: Math.ceil(transformedRect.height),
|
|
38
|
-
});
|
|
21
|
+
if (transformedRect.width <= 0 || transformedRect.height <= 0) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return [transformed, cleanup];
|
|
39
25
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LinearGradientInfo } from './parse-linear-gradient';
|
|
2
|
+
export declare const getPrecomposeRectForMask: (element: HTMLElement | SVGElement) => DOMRect;
|
|
3
|
+
export declare const handleMask: ({ gradientInfo, rect, precomposeRect, tempContext, }: {
|
|
4
|
+
gradientInfo: LinearGradientInfo;
|
|
5
|
+
rect: DOMRect;
|
|
6
|
+
precomposeRect: DOMRect;
|
|
7
|
+
tempContext: OffscreenCanvasRenderingContext2D;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getBiggestBoundingClientRect } from '../get-biggest-bounding-client-rect';
|
|
2
|
+
import { createCanvasGradient } from './parse-linear-gradient';
|
|
3
|
+
export const getPrecomposeRectForMask = (element) => {
|
|
4
|
+
const boundingRect = getBiggestBoundingClientRect(element);
|
|
5
|
+
return boundingRect;
|
|
6
|
+
};
|
|
7
|
+
export const handleMask = ({ gradientInfo, rect, precomposeRect, tempContext, }) => {
|
|
8
|
+
const rectOffsetX = rect.left - precomposeRect.left;
|
|
9
|
+
const rectOffsetY = rect.top - precomposeRect.top;
|
|
10
|
+
const rectToFill = new DOMRect(rectOffsetX, rectOffsetY, rect.width, rect.height);
|
|
11
|
+
const gradient = createCanvasGradient({
|
|
12
|
+
ctx: tempContext,
|
|
13
|
+
rect: rectToFill,
|
|
14
|
+
gradientInfo,
|
|
15
|
+
});
|
|
16
|
+
tempContext.globalCompositeOperation = 'destination-in';
|
|
17
|
+
tempContext.fillStyle = gradient;
|
|
18
|
+
tempContext.fillRect(rectToFill.left, rectToFill.top, rectToFill.width, rectToFill.height);
|
|
19
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { parseLinearGradient } from './parse-linear-gradient';
|
|
2
|
+
export const getMaskImageValue = (computedStyle) => {
|
|
3
|
+
// Check both standard and webkit-prefixed properties
|
|
4
|
+
const { maskImage, webkitMaskImage } = computedStyle;
|
|
5
|
+
const value = maskImage || webkitMaskImage;
|
|
6
|
+
if (!value || value === 'none') {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
export const parseMaskImage = (maskImageValue) => {
|
|
12
|
+
// Only linear gradients are supported for now
|
|
13
|
+
return parseLinearGradient(maskImageValue);
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ColorStop {
|
|
2
|
+
color: string;
|
|
3
|
+
position: number;
|
|
4
|
+
}
|
|
5
|
+
export interface LinearGradientInfo {
|
|
6
|
+
angle: number;
|
|
7
|
+
colorStops: ColorStop[];
|
|
8
|
+
}
|
|
9
|
+
export declare const parseLinearGradient: (backgroundImage: string) => LinearGradientInfo | null;
|
|
10
|
+
export declare const createCanvasGradient: ({ ctx, rect, gradientInfo, }: {
|
|
11
|
+
ctx: OffscreenCanvasRenderingContext2D;
|
|
12
|
+
rect: DOMRect;
|
|
13
|
+
gradientInfo: LinearGradientInfo;
|
|
14
|
+
}) => CanvasGradient;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { NoReactInternals } from 'remotion/no-react';
|
|
2
|
+
const isValidColor = (color) => {
|
|
3
|
+
try {
|
|
4
|
+
const result = NoReactInternals.processColor(color);
|
|
5
|
+
return result !== null && result !== undefined;
|
|
6
|
+
}
|
|
7
|
+
catch (_a) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
const parseDirection = (directionStr) => {
|
|
12
|
+
const trimmed = directionStr.trim().toLowerCase();
|
|
13
|
+
// Handle keywords like "to right", "to bottom", etc.
|
|
14
|
+
if (trimmed.startsWith('to ')) {
|
|
15
|
+
const direction = trimmed.substring(3).trim();
|
|
16
|
+
switch (direction) {
|
|
17
|
+
case 'top':
|
|
18
|
+
return 0;
|
|
19
|
+
case 'right':
|
|
20
|
+
return 90;
|
|
21
|
+
case 'bottom':
|
|
22
|
+
return 180;
|
|
23
|
+
case 'left':
|
|
24
|
+
return 270;
|
|
25
|
+
case 'top right':
|
|
26
|
+
case 'right top':
|
|
27
|
+
return 45;
|
|
28
|
+
case 'bottom right':
|
|
29
|
+
case 'right bottom':
|
|
30
|
+
return 135;
|
|
31
|
+
case 'bottom left':
|
|
32
|
+
case 'left bottom':
|
|
33
|
+
return 225;
|
|
34
|
+
case 'top left':
|
|
35
|
+
case 'left top':
|
|
36
|
+
return 315;
|
|
37
|
+
default:
|
|
38
|
+
return 180; // Default to bottom
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Handle angle values: deg, rad, grad, turn
|
|
42
|
+
const angleMatch = trimmed.match(/^(-?\d+\.?\d*)(deg|rad|grad|turn)$/);
|
|
43
|
+
if (angleMatch) {
|
|
44
|
+
const value = parseFloat(angleMatch[1]);
|
|
45
|
+
const unit = angleMatch[2];
|
|
46
|
+
switch (unit) {
|
|
47
|
+
case 'deg':
|
|
48
|
+
return value;
|
|
49
|
+
case 'rad':
|
|
50
|
+
return (value * 180) / Math.PI;
|
|
51
|
+
case 'grad':
|
|
52
|
+
return (value * 360) / 400;
|
|
53
|
+
case 'turn':
|
|
54
|
+
return value * 360;
|
|
55
|
+
default:
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Default: to bottom
|
|
60
|
+
return 180;
|
|
61
|
+
};
|
|
62
|
+
const parseColorStops = (colorStopsStr) => {
|
|
63
|
+
// Split by comma, but respect parentheses in rgba(), rgb(), hsl(), hsla()
|
|
64
|
+
const parts = colorStopsStr.split(/,(?![^(]*\))/);
|
|
65
|
+
const stops = [];
|
|
66
|
+
for (const part of parts) {
|
|
67
|
+
const trimmed = part.trim();
|
|
68
|
+
if (!trimmed)
|
|
69
|
+
continue;
|
|
70
|
+
// Extract color: can be rgb(), rgba(), hsl(), hsla(), hex, or named color
|
|
71
|
+
const colorMatch = trimmed.match(/(rgba?\([^)]+\)|hsla?\([^)]+\)|#[0-9a-f]{3,8}|[a-z]+)/i);
|
|
72
|
+
if (!colorMatch) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const colorStr = colorMatch[0];
|
|
76
|
+
// Validate that this is actually a valid CSS color
|
|
77
|
+
if (!isValidColor(colorStr)) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const remaining = trimmed
|
|
81
|
+
.substring(colorMatch.index + colorStr.length)
|
|
82
|
+
.trim();
|
|
83
|
+
// Canvas API supports CSS colors directly, so we can use the color string as-is
|
|
84
|
+
const normalizedColor = colorStr;
|
|
85
|
+
// Parse position if provided
|
|
86
|
+
let position = null;
|
|
87
|
+
if (remaining) {
|
|
88
|
+
const posMatch = remaining.match(/(-?\d+\.?\d*)(%|px)?/);
|
|
89
|
+
if (posMatch) {
|
|
90
|
+
const value = parseFloat(posMatch[1]);
|
|
91
|
+
const unit = posMatch[2];
|
|
92
|
+
if (unit === '%') {
|
|
93
|
+
position = value / 100;
|
|
94
|
+
}
|
|
95
|
+
else if (unit === 'px') {
|
|
96
|
+
// px values need element dimensions, which we don't have here
|
|
97
|
+
// We'll handle this as a percentage for now (not fully CSS-compliant but good enough)
|
|
98
|
+
position = null;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
position = value / 100; // Assume percentage if no unit
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
stops.push({
|
|
106
|
+
color: normalizedColor,
|
|
107
|
+
position: position !== null ? position : -1, // -1 means needs to be calculated
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (stops.length === 0) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
// Distribute positions evenly for stops that don't have explicit positions
|
|
114
|
+
let lastExplicitIndex = -1;
|
|
115
|
+
let lastExplicitPosition = 0;
|
|
116
|
+
for (let i = 0; i < stops.length; i++) {
|
|
117
|
+
if (stops[i].position !== -1) {
|
|
118
|
+
// Found an explicit position
|
|
119
|
+
if (lastExplicitIndex >= 0) {
|
|
120
|
+
// Interpolate between last explicit and current explicit
|
|
121
|
+
const numImplicit = i - lastExplicitIndex - 1;
|
|
122
|
+
if (numImplicit > 0) {
|
|
123
|
+
const step = (stops[i].position - lastExplicitPosition) / (numImplicit + 1);
|
|
124
|
+
for (let j = lastExplicitIndex + 1; j < i; j++) {
|
|
125
|
+
stops[j].position =
|
|
126
|
+
lastExplicitPosition + step * (j - lastExplicitIndex);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// Backfill from start to first explicit
|
|
132
|
+
const numImplicit = i;
|
|
133
|
+
if (numImplicit > 0) {
|
|
134
|
+
const step = stops[i].position / (numImplicit + 1);
|
|
135
|
+
for (let j = 0; j < i; j++) {
|
|
136
|
+
stops[j].position = step * (j + 1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
lastExplicitIndex = i;
|
|
141
|
+
lastExplicitPosition = stops[i].position;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// If no explicit positions were provided at all, distribute evenly
|
|
145
|
+
// Check this BEFORE handling trailing stops
|
|
146
|
+
if (stops.every((s) => s.position === -1)) {
|
|
147
|
+
if (stops.length === 1) {
|
|
148
|
+
stops[0].position = 0.5;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
for (let i = 0; i < stops.length; i++) {
|
|
152
|
+
stops[i].position = i / (stops.length - 1);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (lastExplicitIndex < stops.length - 1) {
|
|
157
|
+
const numImplicit = stops.length - 1 - lastExplicitIndex;
|
|
158
|
+
const step = (1 - lastExplicitPosition) / (numImplicit + 1);
|
|
159
|
+
for (let i = lastExplicitIndex + 1; i < stops.length; i++) {
|
|
160
|
+
stops[i].position = lastExplicitPosition + step * (i - lastExplicitIndex);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Clamp positions to 0-1
|
|
164
|
+
for (const stop of stops) {
|
|
165
|
+
stop.position = Math.max(0, Math.min(1, stop.position));
|
|
166
|
+
}
|
|
167
|
+
return stops;
|
|
168
|
+
};
|
|
169
|
+
const extractGradientContent = (backgroundImage) => {
|
|
170
|
+
const prefix = 'linear-gradient(';
|
|
171
|
+
const startIndex = backgroundImage.toLowerCase().indexOf(prefix);
|
|
172
|
+
if (startIndex === -1) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
// Find matching closing parenthesis, handling nested parens from rgb(), rgba(), etc.
|
|
176
|
+
let depth = 0;
|
|
177
|
+
const contentStart = startIndex + prefix.length;
|
|
178
|
+
for (let i = contentStart; i < backgroundImage.length; i++) {
|
|
179
|
+
const char = backgroundImage[i];
|
|
180
|
+
if (char === '(') {
|
|
181
|
+
depth++;
|
|
182
|
+
}
|
|
183
|
+
else if (char === ')') {
|
|
184
|
+
if (depth === 0) {
|
|
185
|
+
return backgroundImage.substring(contentStart, i).trim();
|
|
186
|
+
}
|
|
187
|
+
depth--;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
};
|
|
192
|
+
export const parseLinearGradient = (backgroundImage) => {
|
|
193
|
+
if (!backgroundImage || backgroundImage === 'none') {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
const content = extractGradientContent(backgroundImage);
|
|
197
|
+
if (!content) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
// Try to identify the direction/angle part vs color stops
|
|
201
|
+
// Direction/angle is optional and comes first
|
|
202
|
+
// It can be: "to right", "45deg", etc.
|
|
203
|
+
// Split into parts, respecting parentheses
|
|
204
|
+
const parts = content.split(/,(?![^(]*\))/);
|
|
205
|
+
let angle = 180; // Default: to bottom
|
|
206
|
+
let colorStopsStart = 0;
|
|
207
|
+
// Check if first part is a direction/angle
|
|
208
|
+
if (parts.length > 0) {
|
|
209
|
+
const firstPart = parts[0].trim();
|
|
210
|
+
// Check if it looks like a direction or angle (not a color)
|
|
211
|
+
const isDirection = firstPart.startsWith('to ') ||
|
|
212
|
+
/^-?\d+\.?\d*(deg|rad|grad|turn)$/.test(firstPart);
|
|
213
|
+
if (isDirection) {
|
|
214
|
+
angle = parseDirection(firstPart);
|
|
215
|
+
colorStopsStart = 1;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// Parse color stops
|
|
219
|
+
const colorStopsStr = parts.slice(colorStopsStart).join(',');
|
|
220
|
+
const colorStops = parseColorStops(colorStopsStr);
|
|
221
|
+
if (!colorStops || colorStops.length === 0) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
angle,
|
|
226
|
+
colorStops,
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
export const createCanvasGradient = ({ ctx, rect, gradientInfo, }) => {
|
|
230
|
+
// Convert angle to radians
|
|
231
|
+
// CSS angles: 0deg = to top, 90deg = to right, 180deg = to bottom, 270deg = to left
|
|
232
|
+
// We need to calculate the gradient line that spans the rectangle at the given angle
|
|
233
|
+
const angleRad = ((gradientInfo.angle - 90) * Math.PI) / 180;
|
|
234
|
+
const centerX = rect.left + rect.width / 2;
|
|
235
|
+
const centerY = rect.top + rect.height / 2;
|
|
236
|
+
// Calculate gradient line endpoints
|
|
237
|
+
// The gradient line passes through the center and has the specified angle
|
|
238
|
+
const cos = Math.cos(angleRad);
|
|
239
|
+
const sin = Math.sin(angleRad);
|
|
240
|
+
// Find the intersection of the gradient line with the rectangle edges
|
|
241
|
+
const halfWidth = rect.width / 2;
|
|
242
|
+
const halfHeight = rect.height / 2;
|
|
243
|
+
// Calculate the length from center to edge along the gradient line.
|
|
244
|
+
// Primary formula should always be > 0 for valid angles and non-zero rects;
|
|
245
|
+
// fall back to diagonal length only for degenerate or invalid cases.
|
|
246
|
+
let length = Math.abs(cos) * halfWidth + Math.abs(sin) * halfHeight;
|
|
247
|
+
if (!Number.isFinite(length) || length === 0) {
|
|
248
|
+
length = Math.sqrt(halfWidth ** 2 + halfHeight ** 2);
|
|
249
|
+
}
|
|
250
|
+
const x0 = centerX - cos * length;
|
|
251
|
+
const y0 = centerY - sin * length;
|
|
252
|
+
const x1 = centerX + cos * length;
|
|
253
|
+
const y1 = centerY + sin * length;
|
|
254
|
+
const gradient = ctx.createLinearGradient(x0, y0, x1, y1);
|
|
255
|
+
// Add color stops
|
|
256
|
+
for (const stop of gradientInfo.colorStops) {
|
|
257
|
+
gradient.addColorStop(stop.position, stop.color);
|
|
258
|
+
}
|
|
259
|
+
return gradient;
|
|
260
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LogLevel } from 'remotion';
|
|
2
|
+
import type { InternalState } from '../internal-state';
|
|
3
|
+
export declare const precomposeDOMElement: ({ boundingRect, element, logLevel, internalState, }: {
|
|
4
|
+
boundingRect: DOMRect;
|
|
5
|
+
element: HTMLElement | SVGElement;
|
|
6
|
+
logLevel: LogLevel;
|
|
7
|
+
internalState: InternalState;
|
|
8
|
+
}) => Promise<{
|
|
9
|
+
tempCanvas: OffscreenCanvas;
|
|
10
|
+
tempContext: OffscreenCanvasRenderingContext2D;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { compose } from '../compose';
|
|
2
|
+
export const precomposeDOMElement = async ({ boundingRect, element, logLevel, internalState, }) => {
|
|
3
|
+
const tempCanvas = new OffscreenCanvas(boundingRect.width, boundingRect.height);
|
|
4
|
+
const tempContext = tempCanvas.getContext('2d');
|
|
5
|
+
await compose({
|
|
6
|
+
element,
|
|
7
|
+
context: tempContext,
|
|
8
|
+
logLevel,
|
|
9
|
+
parentRect: boundingRect,
|
|
10
|
+
internalState,
|
|
11
|
+
});
|
|
12
|
+
return { tempCanvas, tempContext };
|
|
13
|
+
};
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LogLevel } from 'remotion';
|
|
2
2
|
import type { InternalState } from '../internal-state';
|
|
3
3
|
import type { DrawFn } from './drawn-fn';
|
|
4
4
|
export type ProcessNodeReturnValue = {
|
|
5
5
|
type: 'continue';
|
|
6
|
-
cleanupAfterChildren: () => void;
|
|
6
|
+
cleanupAfterChildren: null | (() => void);
|
|
7
7
|
} | {
|
|
8
8
|
type: 'skip-children';
|
|
9
9
|
};
|
|
10
|
-
export declare const processNode: ({ element, context, draw, logLevel, parentRect, internalState, }: {
|
|
10
|
+
export declare const processNode: ({ element, context, draw, logLevel, parentRect, internalState, rootElement, }: {
|
|
11
11
|
element: HTMLElement | SVGElement;
|
|
12
12
|
context: OffscreenCanvasRenderingContext2D;
|
|
13
13
|
draw: DrawFn;
|
|
14
14
|
logLevel: LogLevel;
|
|
15
15
|
parentRect: DOMRect;
|
|
16
16
|
internalState: InternalState;
|
|
17
|
+
rootElement: HTMLElement | SVGElement;
|
|
17
18
|
}) => Promise<ProcessNodeReturnValue>;
|
|
@@ -1,40 +1,115 @@
|
|
|
1
|
+
import { Internals } from 'remotion';
|
|
1
2
|
import { calculateTransforms } from './calculate-transforms';
|
|
3
|
+
import { getWiderRectAndExpand } from './clamp-rect-to-parent-bounds';
|
|
4
|
+
import { doRectsIntersect } from './do-rects-intersect';
|
|
2
5
|
import { drawElement } from './draw-element';
|
|
3
|
-
import { handle3dTransform } from './handle-3d-transform';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
import { getPrecomposeRectFor3DTransform, handle3dTransform, } from './handle-3d-transform';
|
|
7
|
+
import { getPrecomposeRectForMask, handleMask } from './handle-mask';
|
|
8
|
+
import { precomposeDOMElement } from './precompose';
|
|
9
|
+
import { roundToExpandRect } from './round-to-expand-rect';
|
|
10
|
+
import { transformDOMRect } from './transform-rect-with-matrix';
|
|
11
|
+
export const processNode = async ({ element, context, draw, logLevel, parentRect, internalState, rootElement, }) => {
|
|
12
|
+
const { totalMatrix, reset, dimensions, opacity, computedStyle, precompositing, } = calculateTransforms({
|
|
6
13
|
element,
|
|
7
|
-
|
|
8
|
-
offsetTop: parentRect.y,
|
|
14
|
+
rootElement,
|
|
9
15
|
});
|
|
10
|
-
const { totalMatrix, reset, dimensions, opacity, computedStyle } = transforms;
|
|
11
16
|
if (opacity === 0) {
|
|
12
17
|
reset();
|
|
13
|
-
return { type: '
|
|
18
|
+
return { type: 'skip-children' };
|
|
14
19
|
}
|
|
15
20
|
if (dimensions.width <= 0 || dimensions.height <= 0) {
|
|
16
21
|
reset();
|
|
17
|
-
return { type: 'continue', cleanupAfterChildren:
|
|
22
|
+
return { type: 'continue', cleanupAfterChildren: null };
|
|
18
23
|
}
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
const rect = new DOMRect(dimensions.left - parentRect.x, dimensions.top - parentRect.y, dimensions.width, dimensions.height);
|
|
25
|
+
if (precompositing.needsPrecompositing) {
|
|
26
|
+
const start = Date.now();
|
|
27
|
+
let precomposeRect = null;
|
|
28
|
+
if (precompositing.needsMaskImage) {
|
|
29
|
+
precomposeRect = getWiderRectAndExpand({
|
|
30
|
+
firstRect: precomposeRect,
|
|
31
|
+
secondRect: getPrecomposeRectForMask(element),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (precompositing.needs3DTransformViaWebGL) {
|
|
35
|
+
precomposeRect = getWiderRectAndExpand({
|
|
36
|
+
firstRect: precomposeRect,
|
|
37
|
+
secondRect: getPrecomposeRectFor3DTransform({
|
|
38
|
+
element,
|
|
39
|
+
parentRect,
|
|
40
|
+
matrix: totalMatrix,
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (!precomposeRect) {
|
|
45
|
+
throw new Error('Precompose rect not found');
|
|
46
|
+
}
|
|
47
|
+
if (precomposeRect.width <= 0 || precomposeRect.height <= 0) {
|
|
48
|
+
return { type: 'continue', cleanupAfterChildren: null };
|
|
49
|
+
}
|
|
50
|
+
if (!doRectsIntersect(precomposeRect, parentRect)) {
|
|
51
|
+
return { type: 'continue', cleanupAfterChildren: null };
|
|
52
|
+
}
|
|
53
|
+
const { tempCanvas, tempContext } = await precomposeDOMElement({
|
|
54
|
+
boundingRect: precomposeRect,
|
|
21
55
|
element,
|
|
22
|
-
matrix: totalMatrix,
|
|
23
|
-
parentRect,
|
|
24
|
-
context,
|
|
25
56
|
logLevel,
|
|
26
57
|
internalState,
|
|
27
58
|
});
|
|
59
|
+
let drawable = tempCanvas;
|
|
60
|
+
let cleanupWebGL = () => { };
|
|
61
|
+
const rectAfterTransforms = roundToExpandRect(transformDOMRect({
|
|
62
|
+
rect: precomposeRect,
|
|
63
|
+
matrix: totalMatrix,
|
|
64
|
+
}));
|
|
65
|
+
if (precompositing.needsMaskImage) {
|
|
66
|
+
handleMask({
|
|
67
|
+
gradientInfo: precompositing.needsMaskImage,
|
|
68
|
+
rect,
|
|
69
|
+
precomposeRect,
|
|
70
|
+
tempContext,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (precompositing.needs3DTransformViaWebGL) {
|
|
74
|
+
const t = handle3dTransform({
|
|
75
|
+
matrix: totalMatrix,
|
|
76
|
+
precomposeRect,
|
|
77
|
+
tempCanvas: drawable,
|
|
78
|
+
rectAfterTransforms,
|
|
79
|
+
});
|
|
80
|
+
if (t) {
|
|
81
|
+
const [transformed, cleanup] = t;
|
|
82
|
+
drawable = transformed;
|
|
83
|
+
cleanupWebGL = cleanup;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const previousTransform = context.getTransform();
|
|
87
|
+
if (drawable) {
|
|
88
|
+
context.setTransform(new DOMMatrix());
|
|
89
|
+
context.drawImage(drawable, rectAfterTransforms.left - parentRect.x, rectAfterTransforms.top - parentRect.y, rectAfterTransforms.width, rectAfterTransforms.height);
|
|
90
|
+
context.setTransform(previousTransform);
|
|
91
|
+
Internals.Log.trace({
|
|
92
|
+
logLevel,
|
|
93
|
+
tag: '@remotion/web-renderer',
|
|
94
|
+
}, `Transforming element in 3D - canvas size: ${precomposeRect.width}x${precomposeRect.height} - compose: ${Date.now() - start}ms`);
|
|
95
|
+
internalState.addPrecompose({
|
|
96
|
+
canvasWidth: precomposeRect.width,
|
|
97
|
+
canvasHeight: precomposeRect.height,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
28
100
|
reset();
|
|
101
|
+
cleanupWebGL();
|
|
29
102
|
return { type: 'skip-children' };
|
|
30
103
|
}
|
|
31
104
|
const { cleanupAfterChildren } = await drawElement({
|
|
32
|
-
rect
|
|
105
|
+
rect,
|
|
33
106
|
computedStyle,
|
|
34
107
|
context,
|
|
35
108
|
draw,
|
|
36
109
|
opacity,
|
|
37
110
|
totalMatrix,
|
|
111
|
+
parentRect,
|
|
112
|
+
logLevel,
|
|
38
113
|
});
|
|
39
114
|
reset();
|
|
40
115
|
return { type: 'continue', cleanupAfterChildren };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const roundToExpandRect: (rect: DOMRect) => DOMRect;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
import type { LogLevel } from 'remotion';
|
|
1
2
|
import type { DrawFn } from '../drawn-fn';
|
|
2
|
-
export declare const drawText: (span
|
|
3
|
+
export declare const drawText: ({ span, logLevel, }: {
|
|
4
|
+
span: HTMLSpanElement;
|
|
5
|
+
logLevel: LogLevel;
|
|
6
|
+
}) => DrawFn;
|
|
@@ -2,14 +2,14 @@ import { Internals } from 'remotion';
|
|
|
2
2
|
import { applyTextTransform } from './apply-text-transform';
|
|
3
3
|
import { findLineBreaks } from './find-line-breaks.text';
|
|
4
4
|
import { getCollapsedText } from './get-collapsed-text';
|
|
5
|
-
export const drawText = (span) => {
|
|
5
|
+
export const drawText = ({ span, logLevel, }) => {
|
|
6
6
|
const drawFn = ({ dimensions: rect, computedStyle, contextToDraw }) => {
|
|
7
7
|
const { fontFamily, fontSize, fontWeight, color, direction, writingMode, letterSpacing, textTransform, } = computedStyle;
|
|
8
8
|
const isVertical = writingMode !== 'horizontal-tb';
|
|
9
9
|
if (isVertical) {
|
|
10
10
|
// TODO: Only warn once per render.
|
|
11
11
|
Internals.Log.warn({
|
|
12
|
-
logLevel
|
|
12
|
+
logLevel,
|
|
13
13
|
tag: '@remotion/web-renderer',
|
|
14
14
|
}, 'Detected "writing-mode" CSS property. Vertical text is not yet supported in @remotion/web-renderer');
|
|
15
15
|
return;
|
|
@@ -30,10 +30,15 @@ export const drawText = (span) => {
|
|
|
30
30
|
const xPosition = isRTL ? rect.right : rect.left;
|
|
31
31
|
const lines = findLineBreaks(span, isRTL);
|
|
32
32
|
let offsetTop = 0;
|
|
33
|
-
const
|
|
33
|
+
const measurements = contextToDraw.measureText(lines[0].text);
|
|
34
|
+
const { fontBoundingBoxDescent, fontBoundingBoxAscent } = measurements;
|
|
35
|
+
const fontHeight = fontBoundingBoxAscent + fontBoundingBoxDescent;
|
|
34
36
|
for (const line of lines) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
// Calculate leading
|
|
38
|
+
const leading = line.height - fontHeight;
|
|
39
|
+
const halfLeading = leading / 2;
|
|
40
|
+
contextToDraw.fillText(line.text, xPosition + line.offsetHorizontal, rect.top + halfLeading + fontBoundingBoxAscent + offsetTop);
|
|
41
|
+
offsetTop += line.height;
|
|
37
42
|
}
|
|
38
43
|
span.textContent = originalText;
|
|
39
44
|
contextToDraw.restore();
|
|
@@ -37,7 +37,7 @@ export function findLineBreaks(span, rtl) {
|
|
|
37
37
|
const shouldCollapse = !computedStyle.whiteSpaceCollapse.includes('preserve');
|
|
38
38
|
lines.push({
|
|
39
39
|
text: shouldCollapse ? currentLine.trim() : currentLine,
|
|
40
|
-
|
|
40
|
+
height: currentHeight - previousRect.height,
|
|
41
41
|
offsetHorizontal,
|
|
42
42
|
});
|
|
43
43
|
currentLine = wordsToAdd;
|
|
@@ -57,7 +57,7 @@ export function findLineBreaks(span, rtl) {
|
|
|
57
57
|
: lastRect.left - originalRect.left;
|
|
58
58
|
lines.push({
|
|
59
59
|
text: currentLine,
|
|
60
|
-
|
|
60
|
+
height: rect.height - lines.reduce((acc, curr) => acc + curr.height, 0),
|
|
61
61
|
offsetHorizontal,
|
|
62
62
|
});
|
|
63
63
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { LogLevel } from 'remotion';
|
|
2
2
|
import type { InternalState } from '../../internal-state';
|
|
3
3
|
import type { ProcessNodeReturnValue } from '../process-node';
|
|
4
|
-
export declare const handleTextNode: ({ node, context, logLevel, parentRect, internalState, }: {
|
|
4
|
+
export declare const handleTextNode: ({ node, context, logLevel, parentRect, internalState, rootElement, }: {
|
|
5
5
|
node: Text;
|
|
6
6
|
context: OffscreenCanvasRenderingContext2D;
|
|
7
7
|
logLevel: LogLevel;
|
|
8
8
|
parentRect: DOMRect;
|
|
9
9
|
internalState: InternalState;
|
|
10
|
+
rootElement: HTMLElement | SVGElement;
|
|
10
11
|
}) => Promise<ProcessNodeReturnValue>;
|