@twick/canvas 0.15.15 → 0.15.16
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/index.d.ts +15 -0
- package/dist/index.js +28 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { addBackgroundColor } from './components/elements';
|
|
2
2
|
import { addCaptionElement } from './components/elements';
|
|
3
|
+
import { AddElementToCanvasOptions } from './types';
|
|
3
4
|
import { addImageElement } from './components/elements';
|
|
4
5
|
import { addRectElement } from './components/elements';
|
|
5
6
|
import { addTextElement } from './components/elements';
|
|
6
7
|
import { addVideoElement } from './components/elements';
|
|
8
|
+
import { AddWatermarkToCanvasOptions } from './types';
|
|
9
|
+
import { BuildCanvasOptions } from './types';
|
|
7
10
|
import { CANVAS_OPERATIONS } from './helpers/constants';
|
|
8
11
|
import { CanvasElement } from './types';
|
|
9
12
|
import { CanvasElementAddParams } from './types';
|
|
@@ -24,7 +27,9 @@ import { default as elementController } from './controllers/element.controller';
|
|
|
24
27
|
import { FrameEffect } from './types';
|
|
25
28
|
import { getCurrentFrameEffect } from './helpers/canvas.util';
|
|
26
29
|
import { reorderElementsByZIndex } from './helpers/canvas.util';
|
|
30
|
+
import { ResizeCanvasOptions } from './types';
|
|
27
31
|
import { rotateControl } from './components/element-controls';
|
|
32
|
+
import { SetCanvasElementsOptions } from './types';
|
|
28
33
|
import { useTwickCanvas } from './hooks/use-twick-canvas';
|
|
29
34
|
import { WatermarkUpdatePayload } from './types';
|
|
30
35
|
|
|
@@ -32,6 +37,8 @@ export { addBackgroundColor }
|
|
|
32
37
|
|
|
33
38
|
export { addCaptionElement }
|
|
34
39
|
|
|
40
|
+
export { AddElementToCanvasOptions }
|
|
41
|
+
|
|
35
42
|
export { addImageElement }
|
|
36
43
|
|
|
37
44
|
export { addRectElement }
|
|
@@ -40,6 +47,10 @@ export { addTextElement }
|
|
|
40
47
|
|
|
41
48
|
export { addVideoElement }
|
|
42
49
|
|
|
50
|
+
export { AddWatermarkToCanvasOptions }
|
|
51
|
+
|
|
52
|
+
export { BuildCanvasOptions }
|
|
53
|
+
|
|
43
54
|
export { CANVAS_OPERATIONS }
|
|
44
55
|
|
|
45
56
|
export { CanvasElement }
|
|
@@ -80,8 +91,12 @@ export { getCurrentFrameEffect }
|
|
|
80
91
|
|
|
81
92
|
export { reorderElementsByZIndex }
|
|
82
93
|
|
|
94
|
+
export { ResizeCanvasOptions }
|
|
95
|
+
|
|
83
96
|
export { rotateControl }
|
|
84
97
|
|
|
98
|
+
export { SetCanvasElementsOptions }
|
|
99
|
+
|
|
85
100
|
export { useTwickCanvas }
|
|
86
101
|
|
|
87
102
|
export { WatermarkUpdatePayload }
|
package/dist/index.js
CHANGED
|
@@ -54,9 +54,9 @@ const CANVAS_OPERATIONS = {
|
|
|
54
54
|
CAPTION_PROPS_UPDATED: "CAPTION_PROPS_UPDATED",
|
|
55
55
|
/** Watermark has been updated */
|
|
56
56
|
WATERMARK_UPDATED: "WATERMARK_UPDATED",
|
|
57
|
-
/** A new element was added via drop on canvas; payload is
|
|
57
|
+
/** A new element was added via drop on canvas; payload is { element } */
|
|
58
58
|
ADDED_NEW_ELEMENT: "ADDED_NEW_ELEMENT",
|
|
59
|
-
/** Z-order changed (bring to front / send to back). Payload is
|
|
59
|
+
/** Z-order changed (bring to front / send to back). Payload is { elementId, direction }. Timeline should reorder tracks. */
|
|
60
60
|
Z_ORDER_CHANGED: "Z_ORDER_CHANGED"
|
|
61
61
|
};
|
|
62
62
|
const ELEMENT_TYPES = {
|
|
@@ -1616,6 +1616,30 @@ const useTwickCanvas = ({
|
|
|
1616
1616
|
scaleX: 1,
|
|
1617
1617
|
scaleY: 1
|
|
1618
1618
|
});
|
|
1619
|
+
const resizeCanvas = ({
|
|
1620
|
+
canvasSize,
|
|
1621
|
+
videoSize = videoSizeRef.current
|
|
1622
|
+
}) => {
|
|
1623
|
+
const canvas = twickCanvasRef.current;
|
|
1624
|
+
if (!canvas || !getCanvasContext(canvas)) return;
|
|
1625
|
+
if (!(videoSize == null ? void 0 : videoSize.width) || !(videoSize == null ? void 0 : videoSize.height)) return;
|
|
1626
|
+
if (canvasResolutionRef.current.width === canvasSize.width && canvasResolutionRef.current.height === canvasSize.height) {
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1629
|
+
canvasMetadataRef.current = {
|
|
1630
|
+
width: canvasSize.width,
|
|
1631
|
+
height: canvasSize.height,
|
|
1632
|
+
aspectRatio: canvasSize.width / canvasSize.height,
|
|
1633
|
+
scaleX: Number((canvasSize.width / videoSize.width).toFixed(2)),
|
|
1634
|
+
scaleY: Number((canvasSize.height / videoSize.height).toFixed(2))
|
|
1635
|
+
};
|
|
1636
|
+
canvas.setDimensions({
|
|
1637
|
+
width: canvasSize.width,
|
|
1638
|
+
height: canvasSize.height
|
|
1639
|
+
});
|
|
1640
|
+
canvasResolutionRef.current = canvasSize;
|
|
1641
|
+
canvas.requestRenderAll();
|
|
1642
|
+
};
|
|
1619
1643
|
const onVideoSizeChange = (videoSize) => {
|
|
1620
1644
|
if (videoSize) {
|
|
1621
1645
|
videoSizeRef.current = videoSize;
|
|
@@ -1892,9 +1916,7 @@ const useTwickCanvas = ({
|
|
|
1892
1916
|
reorderElementsByZIndex(twickCanvas);
|
|
1893
1917
|
}
|
|
1894
1918
|
};
|
|
1895
|
-
const addWatermarkToCanvas = ({
|
|
1896
|
-
element
|
|
1897
|
-
}) => {
|
|
1919
|
+
const addWatermarkToCanvas = ({ element }) => {
|
|
1898
1920
|
if (!twickCanvas) return;
|
|
1899
1921
|
const handler = elementController.get("watermark");
|
|
1900
1922
|
if (handler) {
|
|
@@ -1924,6 +1946,7 @@ const useTwickCanvas = ({
|
|
|
1924
1946
|
return {
|
|
1925
1947
|
twickCanvas,
|
|
1926
1948
|
buildCanvas,
|
|
1949
|
+
resizeCanvas,
|
|
1927
1950
|
onVideoSizeChange,
|
|
1928
1951
|
addWatermarkToCanvas,
|
|
1929
1952
|
addElementToCanvas,
|