@remotion/web-renderer 4.0.387 → 4.0.388
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 +0 -2
- package/dist/calculate-transforms.js +0 -17
- package/dist/composable.d.ts +8 -2
- package/dist/compose-canvas.js +4 -28
- package/dist/find-capturable-elements.d.ts +1 -1
- package/dist/find-capturable-elements.js +22 -20
- package/package.json +5 -5
- package/dist/border-radius.d.ts +0 -31
- package/dist/border-radius.js +0 -152
- package/dist/drawing/compose-canvas.d.ts +0 -1
- package/dist/drawing/compose-canvas.js +0 -36
- package/dist/drawing/compose-svg.d.ts +0 -1
- package/dist/drawing/compose-svg.js +0 -34
- package/dist/drawing/compose.d.ts +0 -5
- package/dist/drawing/compose.js +0 -6
- package/dist/drawing/get-computed-style-cache.d.ts +0 -0
- package/dist/drawing/get-computed-style-cache.js +0 -1
- package/dist/drawing/text/draw-text.d.ts +0 -1
- package/dist/drawing/text/draw-text.js +0 -57
- package/dist/find-canvas-elements.d.ts +0 -1
- package/dist/find-canvas-elements.js +0 -13
- package/dist/opacity.d.ts +0 -4
- package/dist/opacity.js +0 -7
- package/dist/transform.d.ts +0 -4
- package/dist/transform.js +0 -6
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { parseBorderRadius } from './drawing/border-radius';
|
|
2
1
|
import { parseTransformOrigin } from './parse-transform-origin';
|
|
3
2
|
const getInternalTransformOrigin = (transform) => {
|
|
4
3
|
var _a;
|
|
@@ -22,18 +21,8 @@ export const calculateTransforms = (element) => {
|
|
|
22
21
|
let parent = element;
|
|
23
22
|
const transforms = [];
|
|
24
23
|
const toReset = [];
|
|
25
|
-
let borderRadius = '';
|
|
26
|
-
let opacity = 1;
|
|
27
24
|
while (parent) {
|
|
28
25
|
const computedStyle = getComputedStyle(parent);
|
|
29
|
-
if (parent === element) {
|
|
30
|
-
borderRadius = computedStyle.borderRadius;
|
|
31
|
-
}
|
|
32
|
-
// Multiply opacity values from element and all parents
|
|
33
|
-
const parentOpacity = computedStyle.opacity;
|
|
34
|
-
if (parentOpacity && parentOpacity !== '') {
|
|
35
|
-
opacity *= parseFloat(parentOpacity);
|
|
36
|
-
}
|
|
37
26
|
if ((computedStyle.transform && computedStyle.transform !== 'none') ||
|
|
38
27
|
parent === element) {
|
|
39
28
|
const toParse = computedStyle.transform === 'none' || computedStyle.transform === ''
|
|
@@ -81,11 +70,5 @@ export const calculateTransforms = (element) => {
|
|
|
81
70
|
}
|
|
82
71
|
},
|
|
83
72
|
nativeTransformOrigin,
|
|
84
|
-
borderRadius: parseBorderRadius({
|
|
85
|
-
borderRadius,
|
|
86
|
-
width: dimensions.width,
|
|
87
|
-
height: dimensions.height,
|
|
88
|
-
}),
|
|
89
|
-
opacity,
|
|
90
73
|
};
|
|
91
74
|
};
|
package/dist/composable.d.ts
CHANGED
package/dist/compose-canvas.js
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
|
-
import { setBorderRadius } from './border-radius';
|
|
2
1
|
import { calculateTransforms } from './calculate-transforms';
|
|
3
|
-
import { turnSvgIntoDrawable } from './
|
|
4
|
-
import { setOpacity } from './drawing/opacity';
|
|
5
|
-
import { setTransform } from './drawing/transform';
|
|
2
|
+
import { turnSvgIntoDrawable } from './compose-svg';
|
|
6
3
|
export const composeCanvas = async (canvas, context) => {
|
|
7
|
-
const { totalMatrix, reset, dimensions
|
|
8
|
-
|
|
9
|
-
reset();
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
4
|
+
const { totalMatrix, reset, dimensions } = calculateTransforms(canvas);
|
|
5
|
+
context.setTransform(totalMatrix);
|
|
12
6
|
const drawable = canvas instanceof SVGSVGElement
|
|
13
7
|
? await turnSvgIntoDrawable(canvas)
|
|
14
8
|
: canvas;
|
|
15
|
-
const finishTransform = setTransform({
|
|
16
|
-
ctx: context,
|
|
17
|
-
transform: totalMatrix,
|
|
18
|
-
});
|
|
19
|
-
const finishBorderRadius = setBorderRadius({
|
|
20
|
-
ctx: context,
|
|
21
|
-
x: dimensions.left,
|
|
22
|
-
y: dimensions.top,
|
|
23
|
-
width: dimensions.width,
|
|
24
|
-
height: dimensions.height,
|
|
25
|
-
borderRadius,
|
|
26
|
-
});
|
|
27
|
-
const finishOpacity = setOpacity({
|
|
28
|
-
ctx: context,
|
|
29
|
-
opacity,
|
|
30
|
-
});
|
|
31
9
|
context.drawImage(drawable, dimensions.left, dimensions.top, dimensions.width, dimensions.height);
|
|
32
|
-
|
|
33
|
-
finishBorderRadius();
|
|
34
|
-
finishTransform();
|
|
10
|
+
context.setTransform(new DOMMatrix());
|
|
35
11
|
reset();
|
|
36
12
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Composable } from './composable';
|
|
2
|
-
export declare const findCapturableElements: (element: HTMLDivElement
|
|
2
|
+
export declare const findCapturableElements: (element: HTMLDivElement) => Composable[];
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const treeWalker = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, (node) => {
|
|
4
|
-
if (node instanceof Element) {
|
|
5
|
-
const computedStyle = getComputedStyle(node);
|
|
6
|
-
return computedStyle.display === 'none'
|
|
7
|
-
? NodeFilter.FILTER_REJECT
|
|
8
|
-
: NodeFilter.FILTER_ACCEPT;
|
|
9
|
-
}
|
|
10
|
-
return NodeFilter.FILTER_ACCEPT;
|
|
11
|
-
});
|
|
1
|
+
export const findCapturableElements = (element) => {
|
|
2
|
+
const canvasAndSvgElements = element.querySelectorAll('svg,canvas,img');
|
|
12
3
|
const composables = [];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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;
|
|
19
14
|
composables.push({
|
|
20
|
-
type: '
|
|
21
|
-
element:
|
|
15
|
+
type: 'svg',
|
|
16
|
+
element: svg,
|
|
22
17
|
});
|
|
23
18
|
}
|
|
24
|
-
|
|
19
|
+
else if (capturableElement.tagName.toLocaleLowerCase() === 'img') {
|
|
20
|
+
const img = capturableElement;
|
|
21
|
+
composables.push({
|
|
22
|
+
type: 'img',
|
|
23
|
+
element: img,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
25
27
|
return composables;
|
|
26
28
|
};
|
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.388",
|
|
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.388",
|
|
20
20
|
"mediabunny": "1.25.8"
|
|
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.388",
|
|
24
|
+
"@remotion/player": "4.0.388",
|
|
25
|
+
"@remotion/media": "4.0.388",
|
|
26
26
|
"@vitejs/plugin-react": "4.1.0",
|
|
27
27
|
"@vitest/browser-playwright": "4.0.9",
|
|
28
28
|
"playwright": "1.55.1",
|
package/dist/border-radius.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export type BorderRadiusCorners = {
|
|
2
|
-
topLeft: {
|
|
3
|
-
horizontal: number;
|
|
4
|
-
vertical: number;
|
|
5
|
-
};
|
|
6
|
-
topRight: {
|
|
7
|
-
horizontal: number;
|
|
8
|
-
vertical: number;
|
|
9
|
-
};
|
|
10
|
-
bottomRight: {
|
|
11
|
-
horizontal: number;
|
|
12
|
-
vertical: number;
|
|
13
|
-
};
|
|
14
|
-
bottomLeft: {
|
|
15
|
-
horizontal: number;
|
|
16
|
-
vertical: number;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export declare function parseBorderRadius({ borderRadius, width, height, }: {
|
|
20
|
-
borderRadius: string;
|
|
21
|
-
width: number;
|
|
22
|
-
height: number;
|
|
23
|
-
}): BorderRadiusCorners;
|
|
24
|
-
export declare function setBorderRadius({ ctx, x, y, width, height, borderRadius, }: {
|
|
25
|
-
ctx: OffscreenCanvasRenderingContext2D;
|
|
26
|
-
x: number;
|
|
27
|
-
y: number;
|
|
28
|
-
width: number;
|
|
29
|
-
height: number;
|
|
30
|
-
borderRadius: BorderRadiusCorners;
|
|
31
|
-
}): () => void;
|
package/dist/border-radius.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
function parseValue({ value, reference, }) {
|
|
2
|
-
value = value.trim();
|
|
3
|
-
if (value.endsWith('%')) {
|
|
4
|
-
const percentage = parseFloat(value);
|
|
5
|
-
return (percentage / 100) * reference;
|
|
6
|
-
}
|
|
7
|
-
if (value.endsWith('px')) {
|
|
8
|
-
return parseFloat(value);
|
|
9
|
-
}
|
|
10
|
-
// If no unit, assume pixels
|
|
11
|
-
return parseFloat(value);
|
|
12
|
-
}
|
|
13
|
-
function expandShorthand(values) {
|
|
14
|
-
if (values.length === 1) {
|
|
15
|
-
// All corners the same
|
|
16
|
-
return [values[0], values[0], values[0], values[0]];
|
|
17
|
-
}
|
|
18
|
-
if (values.length === 2) {
|
|
19
|
-
// [0] = top-left & bottom-right, [1] = top-right & bottom-left
|
|
20
|
-
return [values[0], values[1], values[0], values[1]];
|
|
21
|
-
}
|
|
22
|
-
if (values.length === 3) {
|
|
23
|
-
// [0] = top-left, [1] = top-right & bottom-left, [2] = bottom-right
|
|
24
|
-
return [values[0], values[1], values[2], values[1]];
|
|
25
|
-
}
|
|
26
|
-
// 4 values: top-left, top-right, bottom-right, bottom-left
|
|
27
|
-
return [values[0], values[1], values[2], values[3]];
|
|
28
|
-
}
|
|
29
|
-
function clampBorderRadius({ borderRadius, width, height, }) {
|
|
30
|
-
// According to CSS spec, if the sum of border radii on adjacent corners
|
|
31
|
-
// exceeds the length of the edge, they should be proportionally reduced
|
|
32
|
-
const clamped = {
|
|
33
|
-
topLeft: { ...borderRadius.topLeft },
|
|
34
|
-
topRight: { ...borderRadius.topRight },
|
|
35
|
-
bottomRight: { ...borderRadius.bottomRight },
|
|
36
|
-
bottomLeft: { ...borderRadius.bottomLeft },
|
|
37
|
-
};
|
|
38
|
-
// Check top edge
|
|
39
|
-
const topSum = clamped.topLeft.horizontal + clamped.topRight.horizontal;
|
|
40
|
-
if (topSum > width) {
|
|
41
|
-
const factor = width / topSum;
|
|
42
|
-
clamped.topLeft.horizontal *= factor;
|
|
43
|
-
clamped.topRight.horizontal *= factor;
|
|
44
|
-
}
|
|
45
|
-
// Check right edge
|
|
46
|
-
const rightSum = clamped.topRight.vertical + clamped.bottomRight.vertical;
|
|
47
|
-
if (rightSum > height) {
|
|
48
|
-
const factor = height / rightSum;
|
|
49
|
-
clamped.topRight.vertical *= factor;
|
|
50
|
-
clamped.bottomRight.vertical *= factor;
|
|
51
|
-
}
|
|
52
|
-
// Check bottom edge
|
|
53
|
-
const bottomSum = clamped.bottomRight.horizontal + clamped.bottomLeft.horizontal;
|
|
54
|
-
if (bottomSum > width) {
|
|
55
|
-
const factor = width / bottomSum;
|
|
56
|
-
clamped.bottomRight.horizontal *= factor;
|
|
57
|
-
clamped.bottomLeft.horizontal *= factor;
|
|
58
|
-
}
|
|
59
|
-
// Check left edge
|
|
60
|
-
const leftSum = clamped.bottomLeft.vertical + clamped.topLeft.vertical;
|
|
61
|
-
if (leftSum > height) {
|
|
62
|
-
const factor = height / leftSum;
|
|
63
|
-
clamped.bottomLeft.vertical *= factor;
|
|
64
|
-
clamped.topLeft.vertical *= factor;
|
|
65
|
-
}
|
|
66
|
-
return clamped;
|
|
67
|
-
}
|
|
68
|
-
export function parseBorderRadius({ borderRadius, width, height, }) {
|
|
69
|
-
// Split by '/' to separate horizontal and vertical radii
|
|
70
|
-
const parts = borderRadius.split('/').map((part) => part.trim());
|
|
71
|
-
const horizontalPart = parts[0];
|
|
72
|
-
const verticalPart = parts[1];
|
|
73
|
-
// Split each part into individual values
|
|
74
|
-
const horizontalValues = horizontalPart.split(/\s+/).filter((v) => v);
|
|
75
|
-
const verticalValues = verticalPart
|
|
76
|
-
? verticalPart.split(/\s+/).filter((v) => v)
|
|
77
|
-
: horizontalValues; // If no '/', use horizontal values for vertical
|
|
78
|
-
// Expand shorthand to 4 values
|
|
79
|
-
const [hTopLeft, hTopRight, hBottomRight, hBottomLeft] = expandShorthand(horizontalValues);
|
|
80
|
-
const [vTopLeft, vTopRight, vBottomRight, vBottomLeft] = expandShorthand(verticalValues);
|
|
81
|
-
return clampBorderRadius({
|
|
82
|
-
borderRadius: {
|
|
83
|
-
topLeft: {
|
|
84
|
-
horizontal: parseValue({ value: hTopLeft, reference: width }),
|
|
85
|
-
vertical: parseValue({ value: vTopLeft, reference: height }),
|
|
86
|
-
},
|
|
87
|
-
topRight: {
|
|
88
|
-
horizontal: parseValue({ value: hTopRight, reference: width }),
|
|
89
|
-
vertical: parseValue({ value: vTopRight, reference: height }),
|
|
90
|
-
},
|
|
91
|
-
bottomRight: {
|
|
92
|
-
horizontal: parseValue({ value: hBottomRight, reference: width }),
|
|
93
|
-
vertical: parseValue({ value: vBottomRight, reference: height }),
|
|
94
|
-
},
|
|
95
|
-
bottomLeft: {
|
|
96
|
-
horizontal: parseValue({ value: hBottomLeft, reference: width }),
|
|
97
|
-
vertical: parseValue({ value: vBottomLeft, reference: height }),
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
width,
|
|
101
|
-
height,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
export function setBorderRadius({ ctx, x, y, width, height, borderRadius, }) {
|
|
105
|
-
if (borderRadius.topLeft.horizontal === 0 &&
|
|
106
|
-
borderRadius.topLeft.vertical === 0 &&
|
|
107
|
-
borderRadius.topRight.horizontal === 0 &&
|
|
108
|
-
borderRadius.topRight.vertical === 0 &&
|
|
109
|
-
borderRadius.bottomRight.horizontal === 0 &&
|
|
110
|
-
borderRadius.bottomRight.vertical === 0 &&
|
|
111
|
-
borderRadius.bottomLeft.horizontal === 0 &&
|
|
112
|
-
borderRadius.bottomLeft.vertical === 0) {
|
|
113
|
-
return () => { };
|
|
114
|
-
}
|
|
115
|
-
ctx.save();
|
|
116
|
-
ctx.beginPath();
|
|
117
|
-
// Start at top-left corner, after the horizontal radius
|
|
118
|
-
ctx.moveTo(x + borderRadius.topLeft.horizontal, y);
|
|
119
|
-
// Top edge to top-right corner
|
|
120
|
-
ctx.lineTo(x + width - borderRadius.topRight.horizontal, y);
|
|
121
|
-
// Top-right corner (elliptical arc)
|
|
122
|
-
if (borderRadius.topRight.horizontal > 0 ||
|
|
123
|
-
borderRadius.topRight.vertical > 0) {
|
|
124
|
-
ctx.ellipse(x + width - borderRadius.topRight.horizontal, y + borderRadius.topRight.vertical, borderRadius.topRight.horizontal, borderRadius.topRight.vertical, 0, -Math.PI / 2, 0);
|
|
125
|
-
}
|
|
126
|
-
// Right edge to bottom-right corner
|
|
127
|
-
ctx.lineTo(x + width, y + height - borderRadius.bottomRight.vertical);
|
|
128
|
-
// Bottom-right corner (elliptical arc)
|
|
129
|
-
if (borderRadius.bottomRight.horizontal > 0 ||
|
|
130
|
-
borderRadius.bottomRight.vertical > 0) {
|
|
131
|
-
ctx.ellipse(x + width - borderRadius.bottomRight.horizontal, y + height - borderRadius.bottomRight.vertical, borderRadius.bottomRight.horizontal, borderRadius.bottomRight.vertical, 0, 0, Math.PI / 2);
|
|
132
|
-
}
|
|
133
|
-
// Bottom edge to bottom-left corner
|
|
134
|
-
ctx.lineTo(x + borderRadius.bottomLeft.horizontal, y + height);
|
|
135
|
-
// Bottom-left corner (elliptical arc)
|
|
136
|
-
if (borderRadius.bottomLeft.horizontal > 0 ||
|
|
137
|
-
borderRadius.bottomLeft.vertical > 0) {
|
|
138
|
-
ctx.ellipse(x + borderRadius.bottomLeft.horizontal, y + height - borderRadius.bottomLeft.vertical, borderRadius.bottomLeft.horizontal, borderRadius.bottomLeft.vertical, 0, Math.PI / 2, Math.PI);
|
|
139
|
-
}
|
|
140
|
-
// Left edge to top-left corner
|
|
141
|
-
ctx.lineTo(x, y + borderRadius.topLeft.vertical);
|
|
142
|
-
// Top-left corner (elliptical arc)
|
|
143
|
-
if (borderRadius.topLeft.horizontal > 0 ||
|
|
144
|
-
borderRadius.topLeft.vertical > 0) {
|
|
145
|
-
ctx.ellipse(x + borderRadius.topLeft.horizontal, y + borderRadius.topLeft.vertical, borderRadius.topLeft.horizontal, borderRadius.topLeft.vertical, 0, Math.PI, (Math.PI * 3) / 2);
|
|
146
|
-
}
|
|
147
|
-
ctx.closePath();
|
|
148
|
-
ctx.clip();
|
|
149
|
-
return () => {
|
|
150
|
-
ctx.restore();
|
|
151
|
-
};
|
|
152
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const drawElementToCanvas: (canvas: HTMLCanvasElement | HTMLImageElement | SVGSVGElement, context: OffscreenCanvasRenderingContext2D) => Promise<void>;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { setBorderRadius } from './border-radius';
|
|
2
|
-
import { calculateTransforms } from './calculate-transforms';
|
|
3
|
-
import { turnSvgIntoDrawable } from './compose-svg';
|
|
4
|
-
import { setOpacity } from './opacity';
|
|
5
|
-
import { setTransform } from './transform';
|
|
6
|
-
export const drawElementToCanvas = async (canvas, context) => {
|
|
7
|
-
const { totalMatrix, reset, dimensions, borderRadius, opacity } = calculateTransforms(canvas);
|
|
8
|
-
if (opacity === 0) {
|
|
9
|
-
reset();
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const drawable = canvas instanceof SVGSVGElement
|
|
13
|
-
? await turnSvgIntoDrawable(canvas)
|
|
14
|
-
: canvas;
|
|
15
|
-
const finishTransform = setTransform({
|
|
16
|
-
ctx: context,
|
|
17
|
-
transform: totalMatrix,
|
|
18
|
-
});
|
|
19
|
-
const finishBorderRadius = setBorderRadius({
|
|
20
|
-
ctx: context,
|
|
21
|
-
x: dimensions.left,
|
|
22
|
-
y: dimensions.top,
|
|
23
|
-
width: dimensions.width,
|
|
24
|
-
height: dimensions.height,
|
|
25
|
-
borderRadius,
|
|
26
|
-
});
|
|
27
|
-
const finishOpacity = setOpacity({
|
|
28
|
-
ctx: context,
|
|
29
|
-
opacity,
|
|
30
|
-
});
|
|
31
|
-
context.drawImage(drawable, dimensions.left, dimensions.top, dimensions.width, dimensions.height);
|
|
32
|
-
finishOpacity();
|
|
33
|
-
finishBorderRadius();
|
|
34
|
-
finishTransform();
|
|
35
|
-
reset();
|
|
36
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const turnSvgIntoDrawable: (svg: SVGSVGElement) => Promise<HTMLImageElement>;
|
|
@@ -1,34 +0,0 @@
|
|
|
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/drawing/compose.js
DELETED
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const drawTextToCanvas: (parentElement: HTMLElement, context: OffscreenCanvasRenderingContext2D) => Promise<void>;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { withResolvers } from '../../with-resolvers';
|
|
2
|
-
export const drawTextToCanvas = async (parentElement, context) => {
|
|
3
|
-
const clientRect = parentElement.getBoundingClientRect();
|
|
4
|
-
const computedStyle = getComputedStyle(parentElement);
|
|
5
|
-
const clonedNode = parentElement.cloneNode(true);
|
|
6
|
-
for (let i = 0; i < computedStyle.length; i++) {
|
|
7
|
-
const propertyName = computedStyle[i];
|
|
8
|
-
const value = computedStyle.getPropertyValue(propertyName);
|
|
9
|
-
if (propertyName === 'margin-top' ||
|
|
10
|
-
propertyName === 'margin-bottom' ||
|
|
11
|
-
propertyName === 'margin-left' ||
|
|
12
|
-
propertyName === 'margin-right' ||
|
|
13
|
-
propertyName === 'margin') {
|
|
14
|
-
// @ts-expect-error - propertyName is a valid CSS property
|
|
15
|
-
clonedNode.style[propertyName] = '0px';
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
// @ts-expect-error - propertyName is a valid CSS property
|
|
19
|
-
clonedNode.style[propertyName] = value;
|
|
20
|
-
}
|
|
21
|
-
// Create an SVG that contains the cloned node via a foreignObject
|
|
22
|
-
const svgNS = 'http://www.w3.org/2000/svg';
|
|
23
|
-
const svg = document.createElementNS(svgNS, 'svg');
|
|
24
|
-
svg.setAttribute('width', `${clientRect.width}`);
|
|
25
|
-
svg.setAttribute('height', `${clientRect.height}`);
|
|
26
|
-
const foreignObject = document.createElementNS(svgNS, 'foreignObject');
|
|
27
|
-
foreignObject.setAttribute('x', '0');
|
|
28
|
-
foreignObject.setAttribute('y', '0');
|
|
29
|
-
foreignObject.setAttribute('width', `${clientRect.width}`);
|
|
30
|
-
foreignObject.setAttribute('height', `${clientRect.height}`);
|
|
31
|
-
// The cloned node must be in XHTML namespace to render properly
|
|
32
|
-
const xhtmlNS = 'http://www.w3.org/1999/xhtml';
|
|
33
|
-
const wrappedDiv = document.createElementNS(xhtmlNS, 'div');
|
|
34
|
-
wrappedDiv.style.width = `${clientRect.width}px`;
|
|
35
|
-
wrappedDiv.style.height = `${clientRect.height}px`;
|
|
36
|
-
wrappedDiv.appendChild(clonedNode);
|
|
37
|
-
foreignObject.appendChild(wrappedDiv);
|
|
38
|
-
svg.appendChild(foreignObject);
|
|
39
|
-
// Convert SVG to data URL
|
|
40
|
-
const serializer = new XMLSerializer();
|
|
41
|
-
const svgString = serializer.serializeToString(svg);
|
|
42
|
-
const svgDataUrl = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgString)}`;
|
|
43
|
-
const { promise, resolve, reject } = withResolvers();
|
|
44
|
-
// Create image and draw when loaded
|
|
45
|
-
const img = new window.Image();
|
|
46
|
-
img.onload = function () {
|
|
47
|
-
resolve(img);
|
|
48
|
-
};
|
|
49
|
-
img.onerror = function (err) {
|
|
50
|
-
// We may want to add robust error handling here
|
|
51
|
-
reject(err);
|
|
52
|
-
};
|
|
53
|
-
img.src = svgDataUrl;
|
|
54
|
-
await promise;
|
|
55
|
-
console.log(clientRect);
|
|
56
|
-
context.drawImage(img, clientRect.left, clientRect.top, clientRect.width, clientRect.height);
|
|
57
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const findCanvasElements: (element: HTMLDivElement) => HTMLCanvasElement[];
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findCanvasElements = void 0;
|
|
4
|
-
const findCanvasElements = (element) => {
|
|
5
|
-
const canvasElements = element.querySelectorAll('canvas');
|
|
6
|
-
const composables = [];
|
|
7
|
-
Array.from(canvasElements).forEach((canvasElement) => {
|
|
8
|
-
const canvas = canvasElement;
|
|
9
|
-
composables.push(canvas);
|
|
10
|
-
});
|
|
11
|
-
return composables;
|
|
12
|
-
};
|
|
13
|
-
exports.findCanvasElements = findCanvasElements;
|
package/dist/opacity.d.ts
DELETED
package/dist/opacity.js
DELETED
package/dist/transform.d.ts
DELETED