@remotion/web-renderer 4.0.393 → 4.0.394
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/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 +15 -0
- package/dist/parse-transform-origin.d.ts +4 -0
- package/dist/parse-transform-origin.js +7 -0
- package/dist/send-telemetry-event.d.ts +5 -0
- package/dist/send-telemetry-event.js +22 -0
- package/package.json +5 -5
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const findCapturableElements = (element) => {
|
|
2
|
+
const canvasAndSvgElements = element.querySelectorAll('svg,canvas,img');
|
|
3
|
+
const composables = [];
|
|
4
|
+
Array.from(canvasAndSvgElements).forEach((capturableElement) => {
|
|
5
|
+
if (capturableElement.tagName.toLocaleLowerCase() === 'canvas') {
|
|
6
|
+
const canvas = capturableElement;
|
|
7
|
+
composables.push({
|
|
8
|
+
type: 'canvas',
|
|
9
|
+
element: canvas,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
else if (capturableElement.tagName.toLocaleLowerCase() === 'svg') {
|
|
13
|
+
const svg = capturableElement;
|
|
14
|
+
composables.push({
|
|
15
|
+
type: 'svg',
|
|
16
|
+
element: svg,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
else if (capturableElement.tagName.toLocaleLowerCase() === 'img') {
|
|
20
|
+
const img = capturableElement;
|
|
21
|
+
composables.push({
|
|
22
|
+
type: 'img',
|
|
23
|
+
element: img,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return composables;
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getBiggestBoundingClientRect: (element: HTMLElement | SVGElement) => DOMRect;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const getBiggestBoundingClientRect = (element) => {
|
|
2
|
+
const treeWalker = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT);
|
|
3
|
+
let mostLeft = Infinity;
|
|
4
|
+
let mostTop = Infinity;
|
|
5
|
+
let mostRight = -Infinity;
|
|
6
|
+
let mostBottom = -Infinity;
|
|
7
|
+
while (treeWalker.nextNode()) {
|
|
8
|
+
const rect = treeWalker.currentNode.getBoundingClientRect();
|
|
9
|
+
mostLeft = Math.min(mostLeft, rect.left);
|
|
10
|
+
mostTop = Math.min(mostTop, rect.top);
|
|
11
|
+
mostRight = Math.max(mostRight, rect.right);
|
|
12
|
+
mostBottom = Math.max(mostBottom, rect.bottom);
|
|
13
|
+
}
|
|
14
|
+
return new DOMRect(mostLeft, mostTop, mostRight - mostLeft, mostBottom - mostTop);
|
|
15
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { registerUsageEvent } from '@remotion/licensing';
|
|
2
|
+
import { Internals } from 'remotion';
|
|
3
|
+
export const sendUsageEvent = async ({ licenseKey, succeeded, apiName, }) => {
|
|
4
|
+
var _a;
|
|
5
|
+
const host = typeof window === 'undefined'
|
|
6
|
+
? null
|
|
7
|
+
: typeof window.location === 'undefined'
|
|
8
|
+
? null
|
|
9
|
+
: ((_a = window.location.origin) !== null && _a !== void 0 ? _a : null);
|
|
10
|
+
if (host === null) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (licenseKey === null) {
|
|
14
|
+
Internals.Log.warn({ logLevel: 'warn', tag: 'web-renderer' }, `Pass "licenseKey" to ${apiName}(). If you qualify for the free license (https://remotion.dev/license), pass "free-license" instead.`);
|
|
15
|
+
}
|
|
16
|
+
await registerUsageEvent({
|
|
17
|
+
apiKey: licenseKey,
|
|
18
|
+
event: 'webcodec-conversion',
|
|
19
|
+
host,
|
|
20
|
+
succeeded,
|
|
21
|
+
});
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"url": "https://github.com/remotion-dev/remotion/tree/main/packages/web-renderer"
|
|
4
4
|
},
|
|
5
5
|
"name": "@remotion/web-renderer",
|
|
6
|
-
"version": "4.0.
|
|
6
|
+
"version": "4.0.394",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"scripts": {
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"author": "Remotion <jonny@remotion.dev>",
|
|
17
17
|
"license": "UNLICENSED",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"remotion": "4.0.
|
|
19
|
+
"remotion": "4.0.394",
|
|
20
20
|
"mediabunny": "1.27.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
24
|
-
"@remotion/player": "4.0.
|
|
25
|
-
"@remotion/media": "4.0.
|
|
23
|
+
"@remotion/eslint-config-internal": "4.0.394",
|
|
24
|
+
"@remotion/player": "4.0.394",
|
|
25
|
+
"@remotion/media": "4.0.394",
|
|
26
26
|
"@vitejs/plugin-react": "4.1.0",
|
|
27
27
|
"@vitest/browser-playwright": "4.0.9",
|
|
28
28
|
"playwright": "1.55.1",
|