@twick/canvas 0.15.8 → 0.15.10
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 +25 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Canvas, Control, controlsUtils, FabricImage, Rect, Textbox, Shadow,
|
|
1
|
+
import { Canvas, Control, controlsUtils, FabricImage, Rect, Textbox, Shadow, Group, Circle } from "fabric";
|
|
2
2
|
import { useState, useRef } from "react";
|
|
3
3
|
const DEFAULT_TEXT_PROPS = {
|
|
4
4
|
/** Font family for text elements */
|
|
@@ -593,6 +593,7 @@ const getObjectFitSize = (objectFit, elementSize, containerSize) => {
|
|
|
593
593
|
};
|
|
594
594
|
}
|
|
595
595
|
};
|
|
596
|
+
const MARGIN = 10;
|
|
596
597
|
const addTextElement = ({
|
|
597
598
|
element,
|
|
598
599
|
index,
|
|
@@ -605,7 +606,7 @@ const addTextElement = ({
|
|
|
605
606
|
((_b = element.props) == null ? void 0 : _b.y) || 0,
|
|
606
607
|
canvasMetadata
|
|
607
608
|
);
|
|
608
|
-
let width = ((_c = element.props) == null ? void 0 : _c.width) ? element.props.width * canvasMetadata.scaleX : canvasMetadata.width;
|
|
609
|
+
let width = ((_c = element.props) == null ? void 0 : _c.width) ? element.props.width * canvasMetadata.scaleX : canvasMetadata.width - 2 * MARGIN;
|
|
609
610
|
if ((_d = element.props) == null ? void 0 : _d.maxWidth) {
|
|
610
611
|
width = Math.min(width, element.props.maxWidth * canvasMetadata.scaleX);
|
|
611
612
|
}
|
|
@@ -681,33 +682,40 @@ const addCaptionElement = ({
|
|
|
681
682
|
captionProps,
|
|
682
683
|
canvasMetadata
|
|
683
684
|
}) => {
|
|
684
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G;
|
|
685
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J;
|
|
685
686
|
const { x, y } = convertToCanvasPosition(
|
|
686
|
-
((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.x : (_a = element.props) == null ? void 0 : _a.x) ?? 0,
|
|
687
|
-
((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.y : (_b = element.props) == null ? void 0 : _b.y) ?? 0,
|
|
687
|
+
((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.x : ((_a = element.props) == null ? void 0 : _a.x) ?? (captionProps == null ? void 0 : captionProps.x)) ?? 0,
|
|
688
|
+
((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.y : ((_b = element.props) == null ? void 0 : _b.y) ?? (captionProps == null ? void 0 : captionProps.y)) ?? 0,
|
|
688
689
|
canvasMetadata
|
|
689
690
|
);
|
|
690
|
-
|
|
691
|
+
let width = ((_c = element.props) == null ? void 0 : _c.width) ? element.props.width * canvasMetadata.scaleX : canvasMetadata.width - 2 * MARGIN;
|
|
692
|
+
if ((_d = element.props) == null ? void 0 : _d.maxWidth) {
|
|
693
|
+
width = Math.min(width, element.props.maxWidth * canvasMetadata.scaleX);
|
|
694
|
+
}
|
|
695
|
+
const caption = new Textbox(((_e = element.props) == null ? void 0 : _e.text) || element.t || "", {
|
|
691
696
|
left: x,
|
|
692
697
|
top: y,
|
|
693
698
|
originX: "center",
|
|
694
699
|
originY: "center",
|
|
695
|
-
angle: ((
|
|
700
|
+
angle: ((_f = element.props) == null ? void 0 : _f.rotation) || 0,
|
|
696
701
|
fontSize: Math.round(
|
|
697
|
-
(((captionProps == null ? void 0 : captionProps.applyToAll) ? (
|
|
702
|
+
(((captionProps == null ? void 0 : captionProps.applyToAll) ? (_g = captionProps == null ? void 0 : captionProps.font) == null ? void 0 : _g.size : ((_i = (_h = element.props) == null ? void 0 : _h.font) == null ? void 0 : _i.size) ?? ((_j = captionProps == null ? void 0 : captionProps.font) == null ? void 0 : _j.size)) ?? DEFAULT_CAPTION_PROPS.size) * canvasMetadata.scaleX
|
|
698
703
|
),
|
|
699
|
-
fontFamily: ((captionProps == null ? void 0 : captionProps.applyToAll) ? (
|
|
700
|
-
fill: ((captionProps == null ? void 0 : captionProps.applyToAll) ? (
|
|
701
|
-
fontWeight: ((captionProps == null ? void 0 : captionProps.applyToAll) ? (
|
|
702
|
-
stroke: ((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.stroke : ((
|
|
703
|
-
opacity: ((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.opacity : ((
|
|
704
|
+
fontFamily: ((captionProps == null ? void 0 : captionProps.applyToAll) ? (_k = captionProps == null ? void 0 : captionProps.font) == null ? void 0 : _k.family : ((_m = (_l = element.props) == null ? void 0 : _l.font) == null ? void 0 : _m.family) ?? ((_n = captionProps == null ? void 0 : captionProps.font) == null ? void 0 : _n.family)) ?? DEFAULT_CAPTION_PROPS.family,
|
|
705
|
+
fill: ((captionProps == null ? void 0 : captionProps.applyToAll) ? (_o = captionProps.color) == null ? void 0 : _o.text : ((_p = element.props) == null ? void 0 : _p.fill) ?? ((_q = captionProps.color) == null ? void 0 : _q.text)) ?? DEFAULT_CAPTION_PROPS.fill,
|
|
706
|
+
fontWeight: ((captionProps == null ? void 0 : captionProps.applyToAll) ? (_r = captionProps == null ? void 0 : captionProps.font) == null ? void 0 : _r.weight : ((_s = element.props) == null ? void 0 : _s.fontWeight) ?? ((_t = captionProps == null ? void 0 : captionProps.font) == null ? void 0 : _t.weight)) ?? DEFAULT_CAPTION_PROPS.fontWeight,
|
|
707
|
+
stroke: ((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.stroke : ((_u = element.props) == null ? void 0 : _u.stroke) ?? (captionProps == null ? void 0 : captionProps.stroke)) ?? DEFAULT_CAPTION_PROPS.stroke,
|
|
708
|
+
opacity: ((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.opacity : ((_v = element.props) == null ? void 0 : _v.opacity) ?? (captionProps == null ? void 0 : captionProps.opacity)) ?? 1,
|
|
709
|
+
width,
|
|
710
|
+
splitByGrapheme: false,
|
|
711
|
+
textAlign: ((_w = element.props) == null ? void 0 : _w.textAlign) ?? "center",
|
|
704
712
|
shadow: new Shadow({
|
|
705
|
-
offsetX: ((captionProps == null ? void 0 : captionProps.applyToAll) ? (
|
|
706
|
-
offsetY: ((captionProps == null ? void 0 : captionProps.applyToAll) ? (
|
|
707
|
-
blur: ((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.shadowBlur : ((
|
|
708
|
-
color: ((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.shadowColor : ((
|
|
713
|
+
offsetX: ((captionProps == null ? void 0 : captionProps.applyToAll) ? (_x = captionProps == null ? void 0 : captionProps.shadowOffset) == null ? void 0 : _x[0] : ((_z = (_y = element.props) == null ? void 0 : _y.shadowOffset) == null ? void 0 : _z[0]) ?? ((_A = captionProps == null ? void 0 : captionProps.shadowOffset) == null ? void 0 : _A[0])) ?? ((_B = DEFAULT_CAPTION_PROPS.shadowOffset) == null ? void 0 : _B[0]),
|
|
714
|
+
offsetY: ((captionProps == null ? void 0 : captionProps.applyToAll) ? (_C = captionProps == null ? void 0 : captionProps.shadowOffset) == null ? void 0 : _C[1] : ((_E = (_D = element.props) == null ? void 0 : _D.shadowOffset) == null ? void 0 : _E[1]) ?? ((_F = captionProps == null ? void 0 : captionProps.shadowOffset) == null ? void 0 : _F[1])) ?? ((_G = DEFAULT_CAPTION_PROPS.shadowOffset) == null ? void 0 : _G[1]),
|
|
715
|
+
blur: ((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.shadowBlur : ((_H = element.props) == null ? void 0 : _H.shadowBlur) ?? (captionProps == null ? void 0 : captionProps.shadowBlur)) ?? DEFAULT_CAPTION_PROPS.shadowBlur,
|
|
716
|
+
color: ((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.shadowColor : ((_I = element.props) == null ? void 0 : _I.shadowColor) ?? (captionProps == null ? void 0 : captionProps.shadowColor)) ?? DEFAULT_CAPTION_PROPS.shadowColor
|
|
709
717
|
}),
|
|
710
|
-
strokeWidth: ((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.lineWidth : ((
|
|
718
|
+
strokeWidth: ((captionProps == null ? void 0 : captionProps.applyToAll) ? captionProps == null ? void 0 : captionProps.lineWidth : ((_J = element.props) == null ? void 0 : _J.lineWidth) ?? (captionProps == null ? void 0 : captionProps.lineWidth)) ?? DEFAULT_CAPTION_PROPS.lineWidth
|
|
711
719
|
});
|
|
712
720
|
caption.set("id", element.id);
|
|
713
721
|
caption.set("zIndex", index);
|