@twick/canvas 0.15.15 → 0.15.18

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.mjs CHANGED
@@ -52,9 +52,9 @@ const CANVAS_OPERATIONS = {
52
52
  CAPTION_PROPS_UPDATED: "CAPTION_PROPS_UPDATED",
53
53
  /** Watermark has been updated */
54
54
  WATERMARK_UPDATED: "WATERMARK_UPDATED",
55
- /** A new element was added via drop on canvas; payload is { element } */
55
+ /** A new element was added via drop on canvas; payload is { element } */
56
56
  ADDED_NEW_ELEMENT: "ADDED_NEW_ELEMENT",
57
- /** Z-order changed (bring to front / send to back). Payload is { elementId, direction }. Timeline should reorder tracks. */
57
+ /** Z-order changed (bring to front / send to back). Payload is { elementId, direction }. Timeline should reorder tracks. */
58
58
  Z_ORDER_CHANGED: "Z_ORDER_CHANGED"
59
59
  };
60
60
  const ELEMENT_TYPES = {
@@ -1614,6 +1614,30 @@ const useTwickCanvas = ({
1614
1614
  scaleX: 1,
1615
1615
  scaleY: 1
1616
1616
  });
1617
+ const resizeCanvas = ({
1618
+ canvasSize,
1619
+ videoSize = videoSizeRef.current
1620
+ }) => {
1621
+ const canvas = twickCanvasRef.current;
1622
+ if (!canvas || !getCanvasContext(canvas)) return;
1623
+ if (!(videoSize == null ? void 0 : videoSize.width) || !(videoSize == null ? void 0 : videoSize.height)) return;
1624
+ if (canvasResolutionRef.current.width === canvasSize.width && canvasResolutionRef.current.height === canvasSize.height) {
1625
+ return;
1626
+ }
1627
+ canvasMetadataRef.current = {
1628
+ width: canvasSize.width,
1629
+ height: canvasSize.height,
1630
+ aspectRatio: canvasSize.width / canvasSize.height,
1631
+ scaleX: Number((canvasSize.width / videoSize.width).toFixed(2)),
1632
+ scaleY: Number((canvasSize.height / videoSize.height).toFixed(2))
1633
+ };
1634
+ canvas.setDimensions({
1635
+ width: canvasSize.width,
1636
+ height: canvasSize.height
1637
+ });
1638
+ canvasResolutionRef.current = canvasSize;
1639
+ canvas.requestRenderAll();
1640
+ };
1617
1641
  const onVideoSizeChange = (videoSize) => {
1618
1642
  if (videoSize) {
1619
1643
  videoSizeRef.current = videoSize;
@@ -1890,9 +1914,7 @@ const useTwickCanvas = ({
1890
1914
  reorderElementsByZIndex(twickCanvas);
1891
1915
  }
1892
1916
  };
1893
- const addWatermarkToCanvas = ({
1894
- element
1895
- }) => {
1917
+ const addWatermarkToCanvas = ({ element }) => {
1896
1918
  if (!twickCanvas) return;
1897
1919
  const handler = elementController.get("watermark");
1898
1920
  if (handler) {
@@ -1922,6 +1944,7 @@ const useTwickCanvas = ({
1922
1944
  return {
1923
1945
  twickCanvas,
1924
1946
  buildCanvas,
1947
+ resizeCanvas,
1925
1948
  onVideoSizeChange,
1926
1949
  addWatermarkToCanvas,
1927
1950
  addElementToCanvas,