@twick/video-editor 0.14.16 → 0.14.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.js CHANGED
@@ -6898,8 +6898,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6898
6898
  width: canvasSize.width,
6899
6899
  height: canvasSize.height,
6900
6900
  aspectRatio: canvasSize.width / canvasSize.height,
6901
- scaleX: canvasSize.width / videoSize.width,
6902
- scaleY: canvasSize.height / videoSize.height
6901
+ scaleX: Number((canvasSize.width / videoSize.width).toFixed(2)),
6902
+ scaleY: Number((canvasSize.height / videoSize.height).toFixed(2))
6903
6903
  };
6904
6904
  const canvas = new Sn(canvasRef, {
6905
6905
  backgroundColor,
@@ -7149,35 +7149,40 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7149
7149
  canvas,
7150
7150
  canvasMetadata
7151
7151
  }) => {
7152
- var _a2, _b, _c, _d, _e2, _f, _g, _h, _i2, _j, _k, _l, _m, _n2, _o2, _p, _q, _r2, _s2, _t2, _u, _v, _w;
7152
+ var _a2, _b, _c, _d, _e2, _f, _g, _h, _i2, _j, _k, _l, _m, _n2, _o2, _p, _q, _r2, _s2, _t2, _u, _v, _w, _x, _y;
7153
7153
  const { x: x2, y: y2 } = convertToCanvasPosition(
7154
7154
  ((_a2 = element.props) == null ? void 0 : _a2.x) || 0,
7155
7155
  ((_b = element.props) == null ? void 0 : _b.y) || 0,
7156
7156
  canvasMetadata
7157
7157
  );
7158
- const text = new ko(((_c = element.props) == null ? void 0 : _c.text) || element.t || "", {
7158
+ let width = ((_c = element.props) == null ? void 0 : _c.width) ? element.props.width * canvasMetadata.scaleX : canvasMetadata.width;
7159
+ if ((_d = element.props) == null ? void 0 : _d.maxWidth) {
7160
+ width = Math.min(width, element.props.maxWidth * canvasMetadata.scaleX);
7161
+ }
7162
+ const text = new Vo(((_e2 = element.props) == null ? void 0 : _e2.text) || element.t || "", {
7159
7163
  left: x2,
7160
7164
  top: y2,
7161
7165
  originX: "center",
7162
7166
  originY: "center",
7163
- angle: ((_d = element.props) == null ? void 0 : _d.rotation) || 0,
7164
- fontSize: Math.round(
7165
- (((_e2 = element.props) == null ? void 0 : _e2.fontSize) || DEFAULT_TEXT_PROPS.size) * canvasMetadata.scaleX
7167
+ angle: ((_f = element.props) == null ? void 0 : _f.rotation) || 0,
7168
+ fontSize: Math.floor(
7169
+ (((_g = element.props) == null ? void 0 : _g.fontSize) || DEFAULT_TEXT_PROPS.size) * canvasMetadata.scaleX
7166
7170
  ),
7167
- fontFamily: ((_f = element.props) == null ? void 0 : _f.fontFamily) || DEFAULT_TEXT_PROPS.family,
7168
- fontStyle: ((_g = element.props) == null ? void 0 : _g.fontStyle) || "normal",
7169
- fontWeight: ((_h = element.props) == null ? void 0 : _h.fontWeight) || "normal",
7170
- fill: ((_i2 = element.props) == null ? void 0 : _i2.fill) || DEFAULT_TEXT_PROPS.fill,
7171
- opacity: ((_j = element.props) == null ? void 0 : _j.opacity) ?? 1,
7172
- skipWrapping: false,
7173
- textAlign: ((_k = element.props) == null ? void 0 : _k.textAlign) || "center",
7174
- stroke: ((_l = element.props) == null ? void 0 : _l.stroke) || DEFAULT_TEXT_PROPS.stroke,
7175
- strokeWidth: ((_m = element.props) == null ? void 0 : _m.lineWidth) || DEFAULT_TEXT_PROPS.lineWidth,
7176
- shadow: ((_n2 = element.props) == null ? void 0 : _n2.shadowColor) ? new ds({
7177
- offsetX: ((_p = (_o2 = element.props) == null ? void 0 : _o2.shadowOffset) == null ? void 0 : _p.length) && ((_r2 = (_q = element.props) == null ? void 0 : _q.shadowOffset) == null ? void 0 : _r2.length) > 1 ? element.props.shadowOffset[0] / 2 : 1,
7178
- offsetY: ((_t2 = (_s2 = element.props) == null ? void 0 : _s2.shadowOffset) == null ? void 0 : _t2.length) && ((_u = element.props) == null ? void 0 : _u.shadowOffset.length) > 1 ? element.props.shadowOffset[1] / 2 : 1,
7179
- blur: (((_v = element.props) == null ? void 0 : _v.shadowBlur) || 2) / 2,
7180
- color: (_w = element.props) == null ? void 0 : _w.shadowColor
7171
+ fontFamily: ((_h = element.props) == null ? void 0 : _h.fontFamily) || DEFAULT_TEXT_PROPS.family,
7172
+ fontStyle: ((_i2 = element.props) == null ? void 0 : _i2.fontStyle) || "normal",
7173
+ fontWeight: ((_j = element.props) == null ? void 0 : _j.fontWeight) || "normal",
7174
+ fill: ((_k = element.props) == null ? void 0 : _k.fill) || DEFAULT_TEXT_PROPS.fill,
7175
+ opacity: ((_l = element.props) == null ? void 0 : _l.opacity) ?? 1,
7176
+ width,
7177
+ splitByGrapheme: false,
7178
+ textAlign: ((_m = element.props) == null ? void 0 : _m.textAlign) || "center",
7179
+ stroke: ((_n2 = element.props) == null ? void 0 : _n2.stroke) || DEFAULT_TEXT_PROPS.stroke,
7180
+ strokeWidth: ((_o2 = element.props) == null ? void 0 : _o2.lineWidth) || DEFAULT_TEXT_PROPS.lineWidth,
7181
+ shadow: ((_p = element.props) == null ? void 0 : _p.shadowColor) ? new ds({
7182
+ offsetX: ((_r2 = (_q = element.props) == null ? void 0 : _q.shadowOffset) == null ? void 0 : _r2.length) && ((_t2 = (_s2 = element.props) == null ? void 0 : _s2.shadowOffset) == null ? void 0 : _t2.length) > 1 ? element.props.shadowOffset[0] / 2 : 1,
7183
+ offsetY: ((_v = (_u = element.props) == null ? void 0 : _u.shadowOffset) == null ? void 0 : _v.length) && ((_w = element.props) == null ? void 0 : _w.shadowOffset.length) > 1 ? element.props.shadowOffset[1] / 2 : 1,
7184
+ blur: (((_x = element.props) == null ? void 0 : _x.shadowBlur) || 2) / 2,
7185
+ color: (_y = element.props) == null ? void 0 : _y.shadowColor
7181
7186
  }) : void 0
7182
7187
  });
7183
7188
  text.set("id", element.id);
@@ -7589,6 +7594,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7589
7594
  if (twickCanvasRef.current) {
7590
7595
  console.log("Destroying twickCanvas");
7591
7596
  twickCanvasRef.current.off("mouse:up", handleMouseUp);
7597
+ twickCanvasRef.current.off("text:editing:exited", onTextEdit);
7592
7598
  twickCanvasRef.current.dispose();
7593
7599
  }
7594
7600
  const { canvas, canvasMetadata } = createCanvas({
@@ -7605,6 +7611,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7605
7611
  canvasMetadataRef.current = canvasMetadata;
7606
7612
  videoSizeRef.current = videoSize;
7607
7613
  canvas == null ? void 0 : canvas.on("mouse:up", handleMouseUp);
7614
+ canvas == null ? void 0 : canvas.on("text:editing:exited", onTextEdit);
7608
7615
  canvasResolutionRef.current = canvasSize;
7609
7616
  setTwickCanvas(canvas);
7610
7617
  twickCanvasRef.current = canvas;
@@ -7612,6 +7619,23 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7612
7619
  onCanvasReady(canvas);
7613
7620
  }
7614
7621
  };
7622
+ const onTextEdit = (event) => {
7623
+ if (event.target) {
7624
+ const object = event.target;
7625
+ const elementId = object.get("id");
7626
+ elementMap.current[elementId] = {
7627
+ ...elementMap.current[elementId],
7628
+ props: {
7629
+ ...elementMap.current[elementId].props,
7630
+ text: object.text ?? elementMap.current[elementId].props.text
7631
+ }
7632
+ };
7633
+ onCanvasOperation == null ? void 0 : onCanvasOperation(
7634
+ CANVAS_OPERATIONS.ITEM_UPDATED,
7635
+ elementMap.current[elementId]
7636
+ );
7637
+ }
7638
+ };
7615
7639
  const handleMouseUp = (event) => {
7616
7640
  var _a2, _b, _c;
7617
7641
  if (event.target) {