fabric 6.0.0 → 6.0.2
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/CHANGELOG.md +12 -0
- package/README.md +8 -18
- package/dist/fabric.d.ts +4 -0
- package/dist/fabric.d.ts.map +1 -1
- package/dist/fabric.min.mjs +1 -1
- package/dist/fabric.mjs +1 -0
- package/dist/fabric.mjs.map +1 -1
- package/dist/index.js +146 -107
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +146 -108
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +146 -107
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +146 -108
- package/dist/index.node.mjs.map +1 -1
- package/dist/package.json.min.mjs +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/EventTypeDefs.d.ts +2 -1
- package/dist/src/EventTypeDefs.d.ts.map +1 -1
- package/dist/src/LayoutManager/LayoutManager.d.ts.map +1 -1
- package/dist/src/LayoutManager/LayoutManager.min.mjs +1 -1
- package/dist/src/LayoutManager/LayoutManager.min.mjs.map +1 -1
- package/dist/src/LayoutManager/LayoutManager.mjs +13 -8
- package/dist/src/LayoutManager/LayoutManager.mjs.map +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.min.mjs +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.min.mjs.map +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.mjs +3 -3
- package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.mjs.map +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.d.ts +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.d.ts.map +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.min.mjs +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.min.mjs.map +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.mjs +15 -9
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.mjs.map +1 -1
- package/dist/src/Observable.d.ts +8 -0
- package/dist/src/Observable.d.ts.map +1 -1
- package/dist/src/Observable.min.mjs.map +1 -1
- package/dist/src/Observable.mjs +8 -0
- package/dist/src/Observable.mjs.map +1 -1
- package/dist/src/canvas/SelectableCanvas.d.ts.map +1 -1
- package/dist/src/canvas/SelectableCanvas.min.mjs +1 -1
- package/dist/src/canvas/SelectableCanvas.min.mjs.map +1 -1
- package/dist/src/canvas/SelectableCanvas.mjs +5 -5
- package/dist/src/canvas/SelectableCanvas.mjs.map +1 -1
- package/dist/src/canvas/StaticCanvas.d.ts +1 -1
- package/dist/src/constants.d.ts +16 -0
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.min.mjs +1 -1
- package/dist/src/constants.min.mjs.map +1 -1
- package/dist/src/constants.mjs +17 -1
- package/dist/src/constants.mjs.map +1 -1
- package/dist/src/controls/Control.d.ts.map +1 -1
- package/dist/src/controls/Control.min.mjs +1 -1
- package/dist/src/controls/Control.min.mjs.map +1 -1
- package/dist/src/controls/Control.mjs +2 -1
- package/dist/src/controls/Control.mjs.map +1 -1
- package/dist/src/controls/changeWidth.min.mjs +1 -1
- package/dist/src/controls/changeWidth.min.mjs.map +1 -1
- package/dist/src/controls/changeWidth.mjs +2 -2
- package/dist/src/controls/changeWidth.mjs.map +1 -1
- package/dist/src/controls/commonControls.d.ts.map +1 -1
- package/dist/src/controls/commonControls.min.mjs +1 -1
- package/dist/src/controls/commonControls.min.mjs.map +1 -1
- package/dist/src/controls/commonControls.mjs +4 -3
- package/dist/src/controls/commonControls.mjs.map +1 -1
- package/dist/src/controls/controlRendering.min.mjs +1 -1
- package/dist/src/controls/controlRendering.min.mjs.map +1 -1
- package/dist/src/controls/controlRendering.mjs +3 -3
- package/dist/src/controls/controlRendering.mjs.map +1 -1
- package/dist/src/controls/drag.min.mjs +1 -1
- package/dist/src/controls/drag.min.mjs.map +1 -1
- package/dist/src/controls/drag.mjs +2 -2
- package/dist/src/controls/drag.mjs.map +1 -1
- package/dist/src/controls/polyControl.d.ts.map +1 -1
- package/dist/src/controls/polyControl.min.mjs +1 -1
- package/dist/src/controls/polyControl.min.mjs.map +1 -1
- package/dist/src/controls/polyControl.mjs +2 -1
- package/dist/src/controls/polyControl.mjs.map +1 -1
- package/dist/src/controls/rotate.d.ts.map +1 -1
- package/dist/src/controls/rotate.min.mjs +1 -1
- package/dist/src/controls/rotate.min.mjs.map +1 -1
- package/dist/src/controls/rotate.mjs +2 -1
- package/dist/src/controls/rotate.mjs.map +1 -1
- package/dist/src/controls/scale.d.ts.map +1 -1
- package/dist/src/controls/scale.min.mjs +1 -1
- package/dist/src/controls/scale.min.mjs.map +1 -1
- package/dist/src/controls/scale.mjs +8 -7
- package/dist/src/controls/scale.mjs.map +1 -1
- package/dist/src/controls/scaleSkew.d.ts.map +1 -1
- package/dist/src/controls/scaleSkew.min.mjs +1 -1
- package/dist/src/controls/scaleSkew.min.mjs.map +1 -1
- package/dist/src/controls/scaleSkew.mjs +3 -2
- package/dist/src/controls/scaleSkew.mjs.map +1 -1
- package/dist/src/controls/skew.d.ts.map +1 -1
- package/dist/src/controls/skew.min.mjs +1 -1
- package/dist/src/controls/skew.min.mjs.map +1 -1
- package/dist/src/controls/skew.mjs +7 -7
- package/dist/src/controls/skew.mjs.map +1 -1
- package/dist/src/filters/Blur.min.mjs +1 -1
- package/dist/src/filters/Blur.min.mjs.map +1 -1
- package/dist/src/filters/Blur.mjs +1 -1
- package/dist/src/filters/Blur.mjs.map +1 -1
- package/dist/src/filters/Pixelate.min.mjs +1 -1
- package/dist/src/filters/Pixelate.min.mjs.map +1 -1
- package/dist/src/filters/Pixelate.mjs +1 -1
- package/dist/src/filters/Pixelate.mjs.map +1 -1
- package/dist/src/parser/attributes.d.ts.map +1 -1
- package/dist/src/parser/attributes.min.mjs +1 -1
- package/dist/src/parser/attributes.min.mjs.map +1 -1
- package/dist/src/parser/attributes.mjs +3 -1
- package/dist/src/parser/attributes.mjs.map +1 -1
- package/dist/src/parser/elements_parser.min.mjs +1 -1
- package/dist/src/parser/elements_parser.min.mjs.map +1 -1
- package/dist/src/parser/elements_parser.mjs +3 -3
- package/dist/src/parser/elements_parser.mjs.map +1 -1
- package/dist/src/parser/normalizeValue.min.mjs +1 -1
- package/dist/src/parser/normalizeValue.min.mjs.map +1 -1
- package/dist/src/parser/normalizeValue.mjs +7 -7
- package/dist/src/parser/normalizeValue.mjs.map +1 -1
- package/dist/src/parser/parseTransformAttribute.min.mjs +1 -1
- package/dist/src/parser/parseTransformAttribute.min.mjs.map +1 -1
- package/dist/src/parser/parseTransformAttribute.mjs +5 -5
- package/dist/src/parser/parseTransformAttribute.mjs.map +1 -1
- package/dist/src/shapes/Circle.d.ts.map +1 -1
- package/dist/src/shapes/Circle.min.mjs +1 -1
- package/dist/src/shapes/Circle.min.mjs.map +1 -1
- package/dist/src/shapes/Circle.mjs +3 -2
- package/dist/src/shapes/Circle.mjs.map +1 -1
- package/dist/src/shapes/Ellipse.min.mjs +1 -1
- package/dist/src/shapes/Ellipse.min.mjs.map +1 -1
- package/dist/src/shapes/Ellipse.mjs +3 -3
- package/dist/src/shapes/Ellipse.mjs.map +1 -1
- package/dist/src/shapes/IText/DraggableTextDelegate.min.mjs +1 -1
- package/dist/src/shapes/IText/DraggableTextDelegate.min.mjs.map +1 -1
- package/dist/src/shapes/IText/DraggableTextDelegate.mjs +3 -3
- package/dist/src/shapes/IText/DraggableTextDelegate.mjs.map +1 -1
- package/dist/src/shapes/IText/IText.min.mjs +1 -1
- package/dist/src/shapes/IText/IText.min.mjs.map +1 -1
- package/dist/src/shapes/IText/IText.mjs +3 -3
- package/dist/src/shapes/IText/IText.mjs.map +1 -1
- package/dist/src/shapes/IText/ITextBehavior.min.mjs +1 -1
- package/dist/src/shapes/IText/ITextBehavior.min.mjs.map +1 -1
- package/dist/src/shapes/IText/ITextBehavior.mjs +2 -2
- package/dist/src/shapes/IText/ITextBehavior.mjs.map +1 -1
- package/dist/src/shapes/IText/ITextKeyBehavior.min.mjs +1 -1
- package/dist/src/shapes/IText/ITextKeyBehavior.min.mjs.map +1 -1
- package/dist/src/shapes/IText/ITextKeyBehavior.mjs +2 -2
- package/dist/src/shapes/IText/ITextKeyBehavior.mjs.map +1 -1
- package/dist/src/shapes/Image.min.mjs +1 -1
- package/dist/src/shapes/Image.min.mjs.map +1 -1
- package/dist/src/shapes/Image.mjs +2 -2
- package/dist/src/shapes/Image.mjs.map +1 -1
- package/dist/src/shapes/Object/AnimatableObject.d.ts.map +1 -1
- package/dist/src/shapes/Object/AnimatableObject.min.mjs +1 -1
- package/dist/src/shapes/Object/AnimatableObject.min.mjs.map +1 -1
- package/dist/src/shapes/Object/AnimatableObject.mjs +2 -1
- package/dist/src/shapes/Object/AnimatableObject.mjs.map +1 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.d.ts.map +1 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.min.mjs +1 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.min.mjs.map +1 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.mjs +4 -4
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.mjs.map +1 -1
- package/dist/src/shapes/Object/InteractiveObject.d.ts.map +1 -1
- package/dist/src/shapes/Object/InteractiveObject.min.mjs +1 -1
- package/dist/src/shapes/Object/InteractiveObject.min.mjs.map +1 -1
- package/dist/src/shapes/Object/InteractiveObject.mjs +2 -1
- package/dist/src/shapes/Object/InteractiveObject.mjs.map +1 -1
- package/dist/src/shapes/Object/Object.d.ts +9 -7
- package/dist/src/shapes/Object/Object.d.ts.map +1 -1
- package/dist/src/shapes/Object/Object.min.mjs +1 -1
- package/dist/src/shapes/Object/Object.min.mjs.map +1 -1
- package/dist/src/shapes/Object/Object.mjs +14 -12
- package/dist/src/shapes/Object/Object.mjs.map +1 -1
- package/dist/src/shapes/Object/ObjectGeometry.min.mjs +1 -1
- package/dist/src/shapes/Object/ObjectGeometry.min.mjs.map +1 -1
- package/dist/src/shapes/Object/ObjectGeometry.mjs +3 -3
- package/dist/src/shapes/Object/ObjectGeometry.mjs.map +1 -1
- package/dist/src/shapes/Object/defaultValues.d.ts.map +1 -1
- package/dist/src/shapes/Object/defaultValues.min.mjs +1 -1
- package/dist/src/shapes/Object/defaultValues.min.mjs.map +1 -1
- package/dist/src/shapes/Object/defaultValues.mjs +4 -4
- package/dist/src/shapes/Object/defaultValues.mjs.map +1 -1
- package/dist/src/shapes/Object/types/ControlProps.d.ts +4 -3
- package/dist/src/shapes/Object/types/ControlProps.d.ts.map +1 -1
- package/dist/src/shapes/Polyline.d.ts.map +1 -1
- package/dist/src/shapes/Polyline.min.mjs +1 -1
- package/dist/src/shapes/Polyline.min.mjs.map +1 -1
- package/dist/src/shapes/Polyline.mjs +3 -3
- package/dist/src/shapes/Polyline.mjs.map +1 -1
- package/dist/src/shapes/Text/Text.d.ts +2 -2
- package/dist/src/shapes/Text/Text.d.ts.map +1 -1
- package/dist/src/shapes/Text/Text.min.mjs +1 -1
- package/dist/src/shapes/Text/Text.min.mjs.map +1 -1
- package/dist/src/shapes/Text/Text.mjs +5 -5
- package/dist/src/shapes/Text/Text.mjs.map +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.d.ts.map +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.min.mjs +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.min.mjs.map +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.mjs +2 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.mjs.map +1 -1
- package/dist/src/shapes/Text/constants.min.mjs +1 -1
- package/dist/src/shapes/Text/constants.min.mjs.map +1 -1
- package/dist/src/shapes/Text/constants.mjs +2 -2
- package/dist/src/shapes/Text/constants.mjs.map +1 -1
- package/dist/src/util/misc/objectEnlive.d.ts +1 -0
- package/dist/src/util/misc/objectEnlive.d.ts.map +1 -1
- package/dist/src/util/misc/objectEnlive.min.mjs.map +1 -1
- package/dist/src/util/misc/objectEnlive.mjs +1 -0
- package/dist/src/util/misc/objectEnlive.mjs.map +1 -1
- package/dist/src/util/misc/svgParsing.min.mjs +1 -1
- package/dist/src/util/misc/svgParsing.min.mjs.map +1 -1
- package/dist/src/util/misc/svgParsing.mjs +2 -2
- package/dist/src/util/misc/svgParsing.mjs.map +1 -1
- package/dist/src/util/transform_matrix_removal.min.mjs +1 -1
- package/dist/src/util/transform_matrix_removal.min.mjs.map +1 -1
- package/dist/src/util/transform_matrix_removal.mjs +3 -3
- package/dist/src/util/transform_matrix_removal.mjs.map +1 -1
- package/fabric.ts +4 -0
- package/package.json +1 -1
- package/src/EventTypeDefs.ts +14 -6
- package/src/LayoutManager/LayoutManager.ts +28 -19
- package/src/LayoutManager/LayoutStrategies/ClipPathLayout.ts +2 -2
- package/src/LayoutManager/LayoutStrategies/LayoutStrategy.ts +7 -7
- package/src/Observable.ts +8 -0
- package/src/canvas/SelectableCanvas.ts +25 -11
- package/src/canvas/canvas_gestures.mixin.ts +6 -5
- package/src/constants.ts +17 -0
- package/src/controls/Control.ts +2 -1
- package/src/controls/changeWidth.ts +2 -2
- package/src/controls/commonControls.ts +4 -3
- package/src/controls/controlRendering.ts +3 -3
- package/src/controls/drag.ts +2 -2
- package/src/controls/polyControl.ts +2 -1
- package/src/controls/rotate.ts +2 -1
- package/src/controls/scale.ts +8 -7
- package/src/controls/scaleSkew.ts +3 -2
- package/src/controls/skew.ts +14 -7
- package/src/filters/Blur.ts +1 -1
- package/src/filters/Pixelate.ts +1 -1
- package/src/parser/attributes.ts +4 -2
- package/src/parser/elements_parser.ts +3 -3
- package/src/parser/normalizeValue.ts +7 -7
- package/src/parser/parseTransformAttribute.ts +5 -5
- package/src/shapes/Circle.ts +3 -2
- package/src/shapes/Ellipse.ts +3 -3
- package/src/shapes/IText/DraggableTextDelegate.ts +3 -3
- package/src/shapes/IText/IText.ts +3 -3
- package/src/shapes/IText/ITextBehavior.ts +2 -2
- package/src/shapes/IText/ITextKeyBehavior.ts +2 -2
- package/src/shapes/Image.ts +2 -2
- package/src/shapes/Object/AnimatableObject.ts +2 -1
- package/src/shapes/Object/FabricObjectSVGExportMixin.ts +4 -6
- package/src/shapes/Object/InteractiveObject.ts +2 -1
- package/src/shapes/Object/Object.ts +16 -11
- package/src/shapes/Object/ObjectGeometry.ts +3 -3
- package/src/shapes/Object/defaultValues.ts +17 -8
- package/src/shapes/Object/types/ControlProps.ts +4 -3
- package/src/shapes/Polyline.spec.ts +0 -1
- package/src/shapes/Polyline.ts +12 -4
- package/src/shapes/Text/Text.ts +7 -7
- package/src/shapes/Text/TextSVGExportMixin.ts +3 -2
- package/src/shapes/Text/constants.ts +3 -3
- package/src/util/misc/objectEnlive.ts +1 -0
- package/src/util/misc/svgParsing.ts +2 -2
- package/src/util/transform_matrix_removal.ts +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svgParsing.mjs","sources":["../../../../src/util/misc/svgParsing.ts"],"sourcesContent":["import { Color } from '../../color/Color';\nimport { config } from '../../config';\nimport { DEFAULT_SVG_FONT_SIZE, NONE } from '../../constants';\nimport type {\n TBBox,\n TMat2D,\n SVGElementName,\n SupportedSVGUnit,\n} from '../../typedefs';\nimport { toFixed } from './toFixed';\n\n/**\n * Returns array of attributes for given svg that fabric parses\n * @param {SVGElementName} type Type of svg element (eg. 'circle')\n * @return {Array} string names of supported attributes\n */\nexport const getSvgAttributes = (type: SVGElementName) => {\n const commonAttributes = ['instantiated_by_use', 'style', 'id', 'class'];\n switch (type) {\n case 'linearGradient':\n return commonAttributes.concat([\n 'x1',\n 'y1',\n 'x2',\n 'y2',\n 'gradientUnits',\n 'gradientTransform',\n ]);\n case 'radialGradient':\n return commonAttributes.concat([\n 'gradientUnits',\n 'gradientTransform',\n 'cx',\n 'cy',\n 'r',\n 'fx',\n 'fy',\n 'fr',\n ]);\n case 'stop':\n return commonAttributes.concat(['offset', 'stop-color', 'stop-opacity']);\n }\n return commonAttributes;\n};\n\n/**\n * Converts from attribute value to pixel value if applicable.\n * Returns converted pixels or original value not converted.\n * @param {string} value number to operate on\n * @param {number} fontSize\n * @return {number}\n */\nexport const parseUnit = (value: string, fontSize = DEFAULT_SVG_FONT_SIZE) => {\n const unit = /\\D{0,2}$/.exec(value),\n number = parseFloat(value);\n const dpi = config.DPI;\n switch (unit?.[0] as SupportedSVGUnit) {\n case 'mm':\n return (number * dpi) / 25.4;\n\n case 'cm':\n return (number * dpi) / 2.54;\n\n case 'in':\n return number * dpi;\n\n case 'pt':\n return (number * dpi) / 72; // or * 4 / 3\n\n case 'pc':\n return ((number * dpi) / 72) * 12; // or * 16\n\n case 'em':\n return number * fontSize;\n\n default:\n return number;\n }\n};\n\nexport type MeetOrSlice = 'meet' | 'slice';\n\nexport type MinMidMax = 'Min' | 'Mid' | 'Max' | 'none';\n\nexport type TPreserveArParsed = {\n meetOrSlice: MeetOrSlice;\n alignX: MinMidMax;\n alignY: MinMidMax;\n};\n\n// align can be either none or undefined or a combination of mid/max\nconst parseAlign = (align: string): MinMidMax[] => {\n //divide align in alignX and alignY\n if (align && align !== NONE) {\n return [align.slice(1, 4) as MinMidMax, align.slice(5, 8) as MinMidMax];\n } else if (align === NONE) {\n return [align, align];\n }\n return ['Mid', 'Mid'];\n};\n\n/**\n * Parse preserveAspectRatio attribute from element\n * https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio\n * @param {string} attribute to be parsed\n * @return {Object} an object containing align and meetOrSlice attribute\n */\nexport const parsePreserveAspectRatioAttribute = (\n attribute: string\n): TPreserveArParsed => {\n const [firstPart, secondPart] = attribute.trim().split(' ') as [\n MinMidMax,\n MeetOrSlice | undefined\n ];\n const [alignX, alignY] = parseAlign(firstPart);\n return {\n meetOrSlice: secondPart || 'meet',\n alignX,\n alignY,\n };\n};\n\n/**\n * given an array of 6 number returns something like `\"matrix(...numbers)\"`\n * @param {TMat2D} transform an array with 6 numbers\n * @return {String} transform matrix for svg\n */\nexport const matrixToSVG = (transform: TMat2D) =>\n 'matrix(' +\n transform\n .map((value) => toFixed(value, config.NUM_FRACTION_DIGITS))\n .join(' ') +\n ')';\n\n/**\n * Adobe Illustrator (at least CS5) is unable to render rgba()-based fill values\n * we work around it by \"moving\" alpha channel into opacity attribute and setting fill's alpha to 1\n * @param prop\n * @param value\n * @param {boolean} inlineStyle The default is inline style, the separator used is \":\", The other is \"=\"\n * @returns\n */\nexport const colorPropToSVG = (\n prop: string,\n value?: any,\n inlineStyle = true\n) => {\n let colorValue;\n let opacityValue;\n if (!value) {\n colorValue = 'none';\n } else if (value.toLive) {\n colorValue = `url(#SVGID_${value.id})`;\n } else {\n const color = new Color(value),\n opacity = color.getAlpha();\n\n colorValue = color.toRgb();\n if (opacity !== 1) {\n opacityValue = opacity.toString();\n }\n }\n if (inlineStyle) {\n return `${prop}: ${colorValue}; ${\n opacityValue ? `${prop}-opacity: ${opacityValue}; ` : ''\n }`;\n } else {\n return `${prop}=\"${colorValue}\" ${\n opacityValue ? `${prop}-opacity=\"${opacityValue}\" ` : ''\n }`;\n }\n};\n\nexport const createSVGRect = (\n color: string,\n { left, top, width, height }: TBBox,\n precision = config.NUM_FRACTION_DIGITS\n) => {\n const svgColor = colorPropToSVG('fill', color, false);\n const [x, y, w, h] = [left, top, width, height].map((value) =>\n toFixed(value, precision)\n );\n return `<rect ${svgColor} x=\"${x}\" y=\"${y}\" width=\"${w}\" height=\"${h}\"></rect>`;\n};\n"],"names":["getSvgAttributes","type","commonAttributes","concat","parseUnit","value","fontSize","arguments","length","undefined","DEFAULT_SVG_FONT_SIZE","unit","exec","number","parseFloat","dpi","config","DPI","parseAlign","align","NONE","slice","parsePreserveAspectRatioAttribute","attribute","firstPart","secondPart","trim","split","alignX","alignY","meetOrSlice","matrixToSVG","transform","map","toFixed","NUM_FRACTION_DIGITS","join","colorPropToSVG","prop","inlineStyle","colorValue","opacityValue","toLive","id","color","Color","opacity","getAlpha","toRgb","toString","createSVGRect","_ref","left","top","width","height","precision","svgColor","x","y","w","h"],"mappings":";;;;;AAWA;AACA;AACA;AACA;AACA;AACaA,MAAAA,gBAAgB,GAAIC,IAAoB,IAAK;EACxD,MAAMC,gBAAgB,GAAG,CAAC,qBAAqB,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;AACxE,EAAA,QAAQD,IAAI;AACV,IAAA,KAAK,gBAAgB;AACnB,MAAA,OAAOC,gBAAgB,CAACC,MAAM,CAAC,CAC7B,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,eAAe,EACf,mBAAmB,CACpB,CAAC,CAAA;AACJ,IAAA,KAAK,gBAAgB;MACnB,OAAOD,gBAAgB,CAACC,MAAM,CAAC,CAC7B,eAAe,EACf,mBAAmB,EACnB,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,IAAI,EACJ,IAAI,CACL,CAAC,CAAA;AACJ,IAAA,KAAK,MAAM;MACT,OAAOD,gBAAgB,CAACC,MAAM,CAAC,CAAC,QAAQ,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC,CAAA;AAC5E,GAAA;AACA,EAAA,OAAOD,gBAAgB,CAAA;AACzB,EAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;MACaE,SAAS,GAAG,UAACC,KAAa,EAAuC;AAAA,EAAA,IAArCC,QAAQ,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAGG,qBAAqB,CAAA;AACvE,EAAA,MAAMC,IAAI,GAAG,UAAU,CAACC,IAAI,CAACP,KAAK,CAAC;AACjCQ,IAAAA,MAAM,GAAGC,UAAU,CAACT,KAAK,CAAC,CAAA;AAC5B,EAAA,MAAMU,GAAG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OAAO,CAAC7B,KAAK,EAAEmD,SAAS,CAC1B,CAAC,CAAA;AACD,EAAA,OAAA,QAAA,CAAArD,MAAA,CAAgBsD,QAAQ,WAAAtD,MAAA,CAAOuD,CAAC,EAAAvD,SAAAA,CAAAA,CAAAA,MAAA,CAAQwD,CAAC,iBAAAxD,MAAA,CAAYyD,CAAC,EAAAzD,cAAAA,CAAAA,CAAAA,MAAA,CAAa0D,CAAC,EAAA,YAAA,CAAA,CAAA;AACtE;;;;"}
|
|
1
|
+
{"version":3,"file":"svgParsing.mjs","sources":["../../../../src/util/misc/svgParsing.ts"],"sourcesContent":["import { Color } from '../../color/Color';\nimport { config } from '../../config';\nimport { DEFAULT_SVG_FONT_SIZE, FILL, NONE } from '../../constants';\nimport type {\n TBBox,\n TMat2D,\n SVGElementName,\n SupportedSVGUnit,\n} from '../../typedefs';\nimport { toFixed } from './toFixed';\n\n/**\n * Returns array of attributes for given svg that fabric parses\n * @param {SVGElementName} type Type of svg element (eg. 'circle')\n * @return {Array} string names of supported attributes\n */\nexport const getSvgAttributes = (type: SVGElementName) => {\n const commonAttributes = ['instantiated_by_use', 'style', 'id', 'class'];\n switch (type) {\n case 'linearGradient':\n return commonAttributes.concat([\n 'x1',\n 'y1',\n 'x2',\n 'y2',\n 'gradientUnits',\n 'gradientTransform',\n ]);\n case 'radialGradient':\n return commonAttributes.concat([\n 'gradientUnits',\n 'gradientTransform',\n 'cx',\n 'cy',\n 'r',\n 'fx',\n 'fy',\n 'fr',\n ]);\n case 'stop':\n return commonAttributes.concat(['offset', 'stop-color', 'stop-opacity']);\n }\n return commonAttributes;\n};\n\n/**\n * Converts from attribute value to pixel value if applicable.\n * Returns converted pixels or original value not converted.\n * @param {string} value number to operate on\n * @param {number} fontSize\n * @return {number}\n */\nexport const parseUnit = (value: string, fontSize = DEFAULT_SVG_FONT_SIZE) => {\n const unit = /\\D{0,2}$/.exec(value),\n number = parseFloat(value);\n const dpi = config.DPI;\n switch (unit?.[0] as SupportedSVGUnit) {\n case 'mm':\n return (number * dpi) / 25.4;\n\n case 'cm':\n return (number * dpi) / 2.54;\n\n case 'in':\n return number * dpi;\n\n case 'pt':\n return (number * dpi) / 72; // or * 4 / 3\n\n case 'pc':\n return ((number * dpi) / 72) * 12; // or * 16\n\n case 'em':\n return number * fontSize;\n\n default:\n return number;\n }\n};\n\nexport type MeetOrSlice = 'meet' | 'slice';\n\nexport type MinMidMax = 'Min' | 'Mid' | 'Max' | 'none';\n\nexport type TPreserveArParsed = {\n meetOrSlice: MeetOrSlice;\n alignX: MinMidMax;\n alignY: MinMidMax;\n};\n\n// align can be either none or undefined or a combination of mid/max\nconst parseAlign = (align: string): MinMidMax[] => {\n //divide align in alignX and alignY\n if (align && align !== NONE) {\n return [align.slice(1, 4) as MinMidMax, align.slice(5, 8) as MinMidMax];\n } else if (align === NONE) {\n return [align, align];\n }\n return ['Mid', 'Mid'];\n};\n\n/**\n * Parse preserveAspectRatio attribute from element\n * https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio\n * @param {string} attribute to be parsed\n * @return {Object} an object containing align and meetOrSlice attribute\n */\nexport const parsePreserveAspectRatioAttribute = (\n attribute: string\n): TPreserveArParsed => {\n const [firstPart, secondPart] = attribute.trim().split(' ') as [\n MinMidMax,\n MeetOrSlice | undefined\n ];\n const [alignX, alignY] = parseAlign(firstPart);\n return {\n meetOrSlice: secondPart || 'meet',\n alignX,\n alignY,\n };\n};\n\n/**\n * given an array of 6 number returns something like `\"matrix(...numbers)\"`\n * @param {TMat2D} transform an array with 6 numbers\n * @return {String} transform matrix for svg\n */\nexport const matrixToSVG = (transform: TMat2D) =>\n 'matrix(' +\n transform\n .map((value) => toFixed(value, config.NUM_FRACTION_DIGITS))\n .join(' ') +\n ')';\n\n/**\n * Adobe Illustrator (at least CS5) is unable to render rgba()-based fill values\n * we work around it by \"moving\" alpha channel into opacity attribute and setting fill's alpha to 1\n * @param prop\n * @param value\n * @param {boolean} inlineStyle The default is inline style, the separator used is \":\", The other is \"=\"\n * @returns\n */\nexport const colorPropToSVG = (\n prop: string,\n value?: any,\n inlineStyle = true\n) => {\n let colorValue;\n let opacityValue;\n if (!value) {\n colorValue = 'none';\n } else if (value.toLive) {\n colorValue = `url(#SVGID_${value.id})`;\n } else {\n const color = new Color(value),\n opacity = color.getAlpha();\n\n colorValue = color.toRgb();\n if (opacity !== 1) {\n opacityValue = opacity.toString();\n }\n }\n if (inlineStyle) {\n return `${prop}: ${colorValue}; ${\n opacityValue ? `${prop}-opacity: ${opacityValue}; ` : ''\n }`;\n } else {\n return `${prop}=\"${colorValue}\" ${\n opacityValue ? `${prop}-opacity=\"${opacityValue}\" ` : ''\n }`;\n }\n};\n\nexport const createSVGRect = (\n color: string,\n { left, top, width, height }: TBBox,\n precision = config.NUM_FRACTION_DIGITS\n) => {\n const svgColor = colorPropToSVG(FILL, color, false);\n const [x, y, w, h] = [left, top, width, height].map((value) =>\n toFixed(value, precision)\n );\n return `<rect ${svgColor} x=\"${x}\" y=\"${y}\" width=\"${w}\" height=\"${h}\"></rect>`;\n};\n"],"names":["getSvgAttributes","type","commonAttributes","concat","parseUnit","value","fontSize","arguments","length","undefined","DEFAULT_SVG_FONT_SIZE","unit","exec","number","parseFloat","dpi","config","DPI","parseAlign","align","NONE","slice","parsePreserveAspectRatioAttribute","attribute","firstPart","secondPart","trim","split","alignX","alignY","meetOrSlice","matrixToSVG","transform","map","toFixed","NUM_FRACTION_DIGITS","join","colorPropToSVG","prop","inlineStyle","colorValue","opacityValue","toLive","id","color","Color","opacity","getAlpha","toRgb","toString","createSVGRect","_ref","left","top","width","height","precision","svgColor","FILL","x","y","w","h"],"mappings":";;;;;AAWA;AACA;AACA;AACA;AACA;AACaA,MAAAA,gBAAgB,GAAIC,IAAoB,IAAK;EACxD,MAAMC,gBAAgB,GAAG,CAAC,qBAAqB,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;AACxE,EAAA,QAAQD,IAAI;AACV,IAAA,KAAK,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
import{CENTER as t}from"../constants.min.mjs";import{qrDecompose as
|
|
1
|
+
import{CENTER as t,SCALE_X as r,SCALE_Y as e}from"../constants.min.mjs";import{qrDecompose as s}from"./misc/matrix.min.mjs";const o=(o,i)=>{let a=o._findCenterFromElement();o.transformMatrix&&((t=>{if(t.transformMatrix){const{scaleX:o,scaleY:i,angle:a,skewX:n}=s(t.transformMatrix);t.flipX=!1,t.flipY=!1,t.set(r,o),t.set(e,i),t.angle=a,t.skewX=n,t.skewY=0}})(o),a=a.transform(o.transformMatrix)),delete o.transformMatrix,i&&(o.scaleX*=i.scaleX,o.scaleY*=i.scaleY,o.cropX=i.cropX,o.cropY=i.cropY,a.x+=i.offsetLeft,a.y+=i.offsetTop,o.width=i.width,o.height=i.height),o.setPositionByOrigin(a,t,t)};export{o as removeTransformMatrixForSvgParsing};
|
|
2
2
|
//# sourceMappingURL=transform_matrix_removal.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform_matrix_removal.min.mjs","sources":["../../../src/util/transform_matrix_removal.ts"],"sourcesContent":["import { CENTER } from '../constants';\nimport type { FabricImage } from '../shapes/Image';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TMat2D } from '../typedefs';\nimport { qrDecompose } from './misc/matrix';\n\ntype FabricObjectWithTransformMatrix = FabricObject & {\n transformMatrix?: TMat2D;\n};\n\n/**\n * This function is an helper for svg import. it decompose the transformMatrix\n * and assign properties to object.\n * untransformed coordinates\n * @private\n */\nconst _assignTransformMatrixProps = (\n object: FabricObjectWithTransformMatrix\n) => {\n if (object.transformMatrix) {\n const { scaleX, scaleY, angle, skewX } = qrDecompose(\n object.transformMatrix\n );\n object.flipX = false;\n object.flipY = false;\n object.set(
|
|
1
|
+
{"version":3,"file":"transform_matrix_removal.min.mjs","sources":["../../../src/util/transform_matrix_removal.ts"],"sourcesContent":["import { CENTER, SCALE_X, SCALE_Y } from '../constants';\nimport type { FabricImage } from '../shapes/Image';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TMat2D } from '../typedefs';\nimport { qrDecompose } from './misc/matrix';\n\ntype FabricObjectWithTransformMatrix = FabricObject & {\n transformMatrix?: TMat2D;\n};\n\n/**\n * This function is an helper for svg import. it decompose the transformMatrix\n * and assign properties to object.\n * untransformed coordinates\n * @private\n */\nconst _assignTransformMatrixProps = (\n object: FabricObjectWithTransformMatrix\n) => {\n if (object.transformMatrix) {\n const { scaleX, scaleY, angle, skewX } = qrDecompose(\n object.transformMatrix\n );\n object.flipX = false;\n object.flipY = false;\n object.set(SCALE_X, scaleX);\n object.set(SCALE_Y, scaleY);\n object.angle = angle;\n object.skewX = skewX;\n object.skewY = 0;\n }\n};\n\n/**\n * This function is an helper for svg import. it removes the transform matrix\n * and set to object properties that fabricjs can handle\n * @private\n * @param {Object} preserveAspectRatioOptions\n */\nexport const removeTransformMatrixForSvgParsing = (\n object: FabricObjectWithTransformMatrix,\n preserveAspectRatioOptions?: any\n) => {\n let center = object._findCenterFromElement();\n if (object.transformMatrix) {\n _assignTransformMatrixProps(object);\n center = center.transform(object.transformMatrix);\n }\n delete object.transformMatrix;\n if (preserveAspectRatioOptions) {\n object.scaleX *= preserveAspectRatioOptions.scaleX;\n object.scaleY *= preserveAspectRatioOptions.scaleY;\n (object as FabricImage).cropX = preserveAspectRatioOptions.cropX;\n (object as FabricImage).cropY = preserveAspectRatioOptions.cropY;\n center.x += preserveAspectRatioOptions.offsetLeft;\n center.y += preserveAspectRatioOptions.offsetTop;\n object.width = preserveAspectRatioOptions.width;\n object.height = preserveAspectRatioOptions.height;\n }\n object.setPositionByOrigin(center, CENTER, CENTER);\n};\n"],"names":["removeTransformMatrixForSvgParsing","object","preserveAspectRatioOptions","center","_findCenterFromElement","transformMatrix","scaleX","scaleY","angle","skewX","qrDecompose","flipX","flipY","set","SCALE_X","SCALE_Y","skewY","_assignTransformMatrixProps","transform","cropX","cropY","x","offsetLeft","y","offsetTop","width","height","setPositionByOrigin","CENTER"],"mappings":"4HAgBA,MAuBaA,EAAqCA,CAChDC,EACAC,KAEA,IAAIC,EAASF,EAAOG,yBAChBH,EAAOI,kBA3BXJ,KAEA,GAAIA,EAAOI,gBAAiB,CAC1B,MAAMC,OAAEA,EAAMC,OAAEA,EAAMC,MAAEA,EAAKC,MAAEA,GAAUC,EACvCT,EAAOI,iBAETJ,EAAOU,OAAQ,EACfV,EAAOW,OAAQ,EACfX,EAAOY,IAAIC,EAASR,GACpBL,EAAOY,IAAIE,EAASR,GACpBN,EAAOO,MAAQA,EACfP,EAAOQ,MAAQA,EACfR,EAAOe,MAAQ,CACjB,GAeEC,CAA4BhB,GAC5BE,EAASA,EAAOe,UAAUjB,EAAOI,yBAE5BJ,EAAOI,gBACVH,IACFD,EAAOK,QAAUJ,EAA2BI,OAC5CL,EAAOM,QAAUL,EAA2BK,OAC3CN,EAAuBkB,MAAQjB,EAA2BiB,MAC1DlB,EAAuBmB,MAAQlB,EAA2BkB,MAC3DjB,EAAOkB,GAAKnB,EAA2BoB,WACvCnB,EAAOoB,GAAKrB,EAA2BsB,UACvCvB,EAAOwB,MAAQvB,EAA2BuB,MAC1CxB,EAAOyB,OAASxB,EAA2BwB,QAE7CzB,EAAO0B,oBAAoBxB,EAAQyB,EAAQA,EAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CENTER } from '../constants.mjs';
|
|
1
|
+
import { CENTER, SCALE_X, SCALE_Y } from '../constants.mjs';
|
|
2
2
|
import { qrDecompose } from './misc/matrix.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -17,8 +17,8 @@ const _assignTransformMatrixProps = object => {
|
|
|
17
17
|
} = qrDecompose(object.transformMatrix);
|
|
18
18
|
object.flipX = false;
|
|
19
19
|
object.flipY = false;
|
|
20
|
-
object.set(
|
|
21
|
-
object.set(
|
|
20
|
+
object.set(SCALE_X, scaleX);
|
|
21
|
+
object.set(SCALE_Y, scaleY);
|
|
22
22
|
object.angle = angle;
|
|
23
23
|
object.skewX = skewX;
|
|
24
24
|
object.skewY = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform_matrix_removal.mjs","sources":["../../../src/util/transform_matrix_removal.ts"],"sourcesContent":["import { CENTER } from '../constants';\nimport type { FabricImage } from '../shapes/Image';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TMat2D } from '../typedefs';\nimport { qrDecompose } from './misc/matrix';\n\ntype FabricObjectWithTransformMatrix = FabricObject & {\n transformMatrix?: TMat2D;\n};\n\n/**\n * This function is an helper for svg import. it decompose the transformMatrix\n * and assign properties to object.\n * untransformed coordinates\n * @private\n */\nconst _assignTransformMatrixProps = (\n object: FabricObjectWithTransformMatrix\n) => {\n if (object.transformMatrix) {\n const { scaleX, scaleY, angle, skewX } = qrDecompose(\n object.transformMatrix\n );\n object.flipX = false;\n object.flipY = false;\n object.set(
|
|
1
|
+
{"version":3,"file":"transform_matrix_removal.mjs","sources":["../../../src/util/transform_matrix_removal.ts"],"sourcesContent":["import { CENTER, SCALE_X, SCALE_Y } from '../constants';\nimport type { FabricImage } from '../shapes/Image';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TMat2D } from '../typedefs';\nimport { qrDecompose } from './misc/matrix';\n\ntype FabricObjectWithTransformMatrix = FabricObject & {\n transformMatrix?: TMat2D;\n};\n\n/**\n * This function is an helper for svg import. it decompose the transformMatrix\n * and assign properties to object.\n * untransformed coordinates\n * @private\n */\nconst _assignTransformMatrixProps = (\n object: FabricObjectWithTransformMatrix\n) => {\n if (object.transformMatrix) {\n const { scaleX, scaleY, angle, skewX } = qrDecompose(\n object.transformMatrix\n );\n object.flipX = false;\n object.flipY = false;\n object.set(SCALE_X, scaleX);\n object.set(SCALE_Y, scaleY);\n object.angle = angle;\n object.skewX = skewX;\n object.skewY = 0;\n }\n};\n\n/**\n * This function is an helper for svg import. it removes the transform matrix\n * and set to object properties that fabricjs can handle\n * @private\n * @param {Object} preserveAspectRatioOptions\n */\nexport const removeTransformMatrixForSvgParsing = (\n object: FabricObjectWithTransformMatrix,\n preserveAspectRatioOptions?: any\n) => {\n let center = object._findCenterFromElement();\n if (object.transformMatrix) {\n _assignTransformMatrixProps(object);\n center = center.transform(object.transformMatrix);\n }\n delete object.transformMatrix;\n if (preserveAspectRatioOptions) {\n object.scaleX *= preserveAspectRatioOptions.scaleX;\n object.scaleY *= preserveAspectRatioOptions.scaleY;\n (object as FabricImage).cropX = preserveAspectRatioOptions.cropX;\n (object as FabricImage).cropY = preserveAspectRatioOptions.cropY;\n center.x += preserveAspectRatioOptions.offsetLeft;\n center.y += preserveAspectRatioOptions.offsetTop;\n object.width = preserveAspectRatioOptions.width;\n object.height = preserveAspectRatioOptions.height;\n }\n object.setPositionByOrigin(center, CENTER, CENTER);\n};\n"],"names":["_assignTransformMatrixProps","object","transformMatrix","scaleX","scaleY","angle","skewX","qrDecompose","flipX","flipY","set","SCALE_X","SCALE_Y","skewY","removeTransformMatrixForSvgParsing","preserveAspectRatioOptions","center","_findCenterFromElement","transform","cropX","cropY","x","offsetLeft","y","offsetTop","width","height","setPositionByOrigin","CENTER"],"mappings":";;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,2BAA2B,GAC/BC,MAAuC,IACpC;EACH,IAAIA,MAAM,CAACC,eAAe,EAAE;IAC1B,MAAM;MAAEC,MAAM;MAAEC,MAAM;MAAEC,KAAK;AAAEC,MAAAA,KAAAA;AAAM,KAAC,GAAGC,WAAW,CAClDN,MAAM,CAACC,eACT,CAAC,CAAA;IACDD,MAAM,CAACO,KAAK,GAAG,KAAK,CAAA;IACpBP,MAAM,CAACQ,KAAK,GAAG,KAAK,CAAA;AACpBR,IAAAA,MAAM,CAACS,GAAG,CAACC,OAAO,EAAER,MAAM,CAAC,CAAA;AAC3BF,IAAAA,MAAM,CAACS,GAAG,CAACE,OAAO,EAAER,MAAM,CAAC,CAAA;IAC3BH,MAAM,CAACI,KAAK,GAAGA,KAAK,CAAA;IACpBJ,MAA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|
|
61
61
|
*/
|
|
62
62
|
export { FabricObject as BaseFabricObject } from './src/shapes/Object/Object';
|
|
63
|
+
/**
|
|
64
|
+
* Exported so we can tweak default values
|
|
65
|
+
*/
|
|
66
|
+
export { InteractiveFabricObject } from './src/shapes/Object/InteractiveObject';
|
|
63
67
|
|
|
64
68
|
export type {
|
|
65
69
|
TFabricObjectProps,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "fabric",
|
|
3
3
|
"description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
|
|
4
4
|
"homepage": "http://fabricjs.com/",
|
|
5
|
-
"version": "6.0.
|
|
5
|
+
"version": "6.0.2",
|
|
6
6
|
"author": "Juriy Zaytsev <kangax@gmail.com>",
|
|
7
7
|
"contributors": [
|
|
8
8
|
{
|
package/src/EventTypeDefs.ts
CHANGED
|
@@ -11,6 +11,14 @@ import type {
|
|
|
11
11
|
LayoutBeforeEvent,
|
|
12
12
|
LayoutAfterEvent,
|
|
13
13
|
} from './LayoutManager/types';
|
|
14
|
+
import type {
|
|
15
|
+
MODIFY_POLY,
|
|
16
|
+
MOVING,
|
|
17
|
+
RESIZING,
|
|
18
|
+
ROTATING,
|
|
19
|
+
SCALING,
|
|
20
|
+
SKEWING,
|
|
21
|
+
} from './constants';
|
|
14
22
|
|
|
15
23
|
export type ModifierKey = keyof Pick<
|
|
16
24
|
MouseEvent | PointerEvent | TouchEvent,
|
|
@@ -97,12 +105,12 @@ export interface BasicTransformEvent<E extends Event = TPointerEvent>
|
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
export type TModificationEvents =
|
|
100
|
-
|
|
|
101
|
-
|
|
|
102
|
-
|
|
|
103
|
-
|
|
|
104
|
-
|
|
|
105
|
-
|
|
|
108
|
+
| typeof MOVING
|
|
109
|
+
| typeof SCALING
|
|
110
|
+
| typeof ROTATING
|
|
111
|
+
| typeof SKEWING
|
|
112
|
+
| typeof RESIZING
|
|
113
|
+
| typeof MODIFY_POLY;
|
|
106
114
|
|
|
107
115
|
export interface ModifiedEvent<E extends Event = TPointerEvent> {
|
|
108
116
|
e?: E;
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { Point } from '../Point';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
CENTER,
|
|
4
|
+
CHANGED,
|
|
5
|
+
MODIFIED,
|
|
6
|
+
MODIFY_POLY,
|
|
7
|
+
MOVING,
|
|
8
|
+
RESIZING,
|
|
9
|
+
ROTATING,
|
|
10
|
+
SCALING,
|
|
11
|
+
SKEWING,
|
|
12
|
+
iMatrix,
|
|
13
|
+
} from '../constants';
|
|
3
14
|
import type { Group } from '../shapes/Group';
|
|
4
15
|
import type { FabricObject } from '../shapes/Object/FabricObject';
|
|
5
16
|
import { invertTransform } from '../util/misc/matrix';
|
|
@@ -78,19 +89,19 @@ export class LayoutManager {
|
|
|
78
89
|
const { target } = context;
|
|
79
90
|
return (
|
|
80
91
|
[
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
MODIFIED,
|
|
93
|
+
MOVING,
|
|
94
|
+
RESIZING,
|
|
95
|
+
ROTATING,
|
|
96
|
+
SCALING,
|
|
97
|
+
SKEWING,
|
|
98
|
+
CHANGED,
|
|
99
|
+
MODIFY_POLY,
|
|
89
100
|
] as (TModificationEvents & 'modified')[]
|
|
90
101
|
).map((key) =>
|
|
91
102
|
object.on(key, (e) =>
|
|
92
103
|
this.performLayout(
|
|
93
|
-
key ===
|
|
104
|
+
key === MODIFIED
|
|
94
105
|
? {
|
|
95
106
|
type: LAYOUT_TYPE_OBJECT_MODIFIED,
|
|
96
107
|
trigger: key,
|
|
@@ -184,19 +195,16 @@ export class LayoutManager {
|
|
|
184
195
|
protected getLayoutResult(
|
|
185
196
|
context: StrictLayoutContext
|
|
186
197
|
): Required<LayoutResult> | undefined {
|
|
187
|
-
const { target } = context;
|
|
198
|
+
const { target, strategy, type } = context;
|
|
188
199
|
|
|
189
|
-
const result =
|
|
190
|
-
context,
|
|
191
|
-
target.getObjects()
|
|
192
|
-
);
|
|
200
|
+
const result = strategy.calcLayoutResult(context, target.getObjects());
|
|
193
201
|
|
|
194
202
|
if (!result) {
|
|
195
203
|
return;
|
|
196
204
|
}
|
|
197
205
|
|
|
198
206
|
const prevCenter =
|
|
199
|
-
|
|
207
|
+
type === LAYOUT_TYPE_INITIALIZATION
|
|
200
208
|
? new Point()
|
|
201
209
|
: target.getRelativeCenterPoint();
|
|
202
210
|
|
|
@@ -210,7 +218,7 @@ export class LayoutManager {
|
|
|
210
218
|
.add(correction)
|
|
211
219
|
.transform(
|
|
212
220
|
// in `initialization` we do not account for target's transformation matrix
|
|
213
|
-
|
|
221
|
+
type === LAYOUT_TYPE_INITIALIZATION
|
|
214
222
|
? iMatrix
|
|
215
223
|
: invertTransform(target.calcOwnMatrix()),
|
|
216
224
|
true
|
|
@@ -328,8 +336,9 @@ export class LayoutManager {
|
|
|
328
336
|
}
|
|
329
337
|
|
|
330
338
|
dispose() {
|
|
331
|
-
|
|
332
|
-
|
|
339
|
+
const { _subscriptions } = this;
|
|
340
|
+
_subscriptions.forEach((disposers) => disposers.forEach((d) => d()));
|
|
341
|
+
_subscriptions.clear();
|
|
333
342
|
}
|
|
334
343
|
|
|
335
344
|
toObject() {
|
|
@@ -26,7 +26,7 @@ export class ClipPathLayout extends LayoutStrategy {
|
|
|
26
26
|
objects: FabricObject[]
|
|
27
27
|
): LayoutStrategyResult | undefined {
|
|
28
28
|
const { target } = context;
|
|
29
|
-
const { clipPath } = target;
|
|
29
|
+
const { clipPath, group } = target;
|
|
30
30
|
if (!clipPath || !this.shouldPerformLayout(context)) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
@@ -40,7 +40,7 @@ export class ClipPathLayout extends LayoutStrategy {
|
|
|
40
40
|
const clipPathCenter = sendPointToPlane(
|
|
41
41
|
clipPath.getRelativeCenterPoint(),
|
|
42
42
|
undefined,
|
|
43
|
-
|
|
43
|
+
group ? group.calcTransformMatrix() : undefined
|
|
44
44
|
);
|
|
45
45
|
return {
|
|
46
46
|
center: clipPathCenter,
|
|
@@ -39,11 +39,11 @@ export abstract class LayoutStrategy {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
shouldPerformLayout(
|
|
42
|
+
shouldPerformLayout({ type, prevStrategy, strategy }: StrictLayoutContext) {
|
|
43
43
|
return (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
(!!
|
|
44
|
+
type === LAYOUT_TYPE_INITIALIZATION ||
|
|
45
|
+
type === LAYOUT_TYPE_IMPERATIVE ||
|
|
46
|
+
(!!prevStrategy && strategy !== prevStrategy)
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -69,13 +69,13 @@ export abstract class LayoutStrategy {
|
|
|
69
69
|
objects: FabricObject[],
|
|
70
70
|
context: StrictLayoutContext
|
|
71
71
|
): LayoutStrategyResult | undefined {
|
|
72
|
-
|
|
72
|
+
const { type, target } = context;
|
|
73
|
+
if (type === LAYOUT_TYPE_IMPERATIVE && context.overrides) {
|
|
73
74
|
return context.overrides;
|
|
74
75
|
}
|
|
75
76
|
if (objects.length === 0) {
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
78
|
-
const { target } = context;
|
|
79
79
|
const { left, top, width, height } = makeBoundingBoxFromPoints(
|
|
80
80
|
objects
|
|
81
81
|
.map((object) => getObjectBounds(target, object))
|
|
@@ -85,7 +85,7 @@ export abstract class LayoutStrategy {
|
|
|
85
85
|
const bboxLeftTop = new Point(left, top);
|
|
86
86
|
const bboxCenter = bboxLeftTop.add(bboxSize.scalarDivide(2));
|
|
87
87
|
|
|
88
|
-
if (
|
|
88
|
+
if (type === LAYOUT_TYPE_INITIALIZATION) {
|
|
89
89
|
const actualSize = this.getInitialSize(context, {
|
|
90
90
|
size: bboxSize,
|
|
91
91
|
center: bboxCenter,
|
package/src/Observable.ts
CHANGED
|
@@ -112,6 +112,14 @@ export class Observable<EventSpec> {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Unsubscribe all event listeners for eventname.
|
|
117
|
+
* Do not use this pattern. You could kill internal fabricJS events.
|
|
118
|
+
* We know we should have protected events for internal flows, but we don't have yet
|
|
119
|
+
* @deprecated
|
|
120
|
+
* @param {string} eventName event name (eg. 'after:render')
|
|
121
|
+
*/
|
|
122
|
+
off<K extends keyof EventSpec>(eventName: K): void;
|
|
115
123
|
/**
|
|
116
124
|
* unsubscribe an event listener
|
|
117
125
|
* @param {string} eventName event name (eg. 'after:render')
|
|
@@ -32,7 +32,21 @@ import { pick } from '../util/misc/pick';
|
|
|
32
32
|
import { sendPointToPlane } from '../util/misc/planeChange';
|
|
33
33
|
import { cos, createCanvasElement, sin } from '../util';
|
|
34
34
|
import { CanvasDOMManager } from './DOMManagers/CanvasDOMManager';
|
|
35
|
-
import {
|
|
35
|
+
import {
|
|
36
|
+
BOTTOM,
|
|
37
|
+
CENTER,
|
|
38
|
+
LEFT,
|
|
39
|
+
MODIFIED,
|
|
40
|
+
RESIZING,
|
|
41
|
+
RIGHT,
|
|
42
|
+
ROTATE,
|
|
43
|
+
SCALE,
|
|
44
|
+
SCALE_X,
|
|
45
|
+
SCALE_Y,
|
|
46
|
+
SKEW_X,
|
|
47
|
+
SKEW_Y,
|
|
48
|
+
TOP,
|
|
49
|
+
} from '../constants';
|
|
36
50
|
import type { CanvasOptions } from './CanvasOptions';
|
|
37
51
|
import { canvasDefaults } from './CanvasOptions';
|
|
38
52
|
import { Intersection } from '../Intersection';
|
|
@@ -517,13 +531,13 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents>
|
|
|
517
531
|
let centerTransform;
|
|
518
532
|
|
|
519
533
|
if (
|
|
520
|
-
action ===
|
|
521
|
-
action ===
|
|
522
|
-
action ===
|
|
523
|
-
action ===
|
|
534
|
+
action === SCALE ||
|
|
535
|
+
action === SCALE_X ||
|
|
536
|
+
action === SCALE_Y ||
|
|
537
|
+
action === RESIZING
|
|
524
538
|
) {
|
|
525
539
|
centerTransform = this.centeredScaling || target.centeredScaling;
|
|
526
|
-
} else if (action ===
|
|
540
|
+
} else if (action === ROTATE) {
|
|
527
541
|
centerTransform = this.centeredRotation || target.centeredRotation;
|
|
528
542
|
}
|
|
529
543
|
|
|
@@ -1241,7 +1255,7 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents>
|
|
|
1241
1255
|
|
|
1242
1256
|
if (transform.actionPerformed) {
|
|
1243
1257
|
this.fire('object:modified', options);
|
|
1244
|
-
target.fire(
|
|
1258
|
+
target.fire(MODIFIED, options);
|
|
1245
1259
|
}
|
|
1246
1260
|
}
|
|
1247
1261
|
|
|
@@ -1340,10 +1354,10 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents>
|
|
|
1340
1354
|
'flipX',
|
|
1341
1355
|
'flipY',
|
|
1342
1356
|
LEFT,
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1357
|
+
SCALE_X,
|
|
1358
|
+
SCALE_Y,
|
|
1359
|
+
SKEW_X,
|
|
1360
|
+
SKEW_Y,
|
|
1347
1361
|
TOP,
|
|
1348
1362
|
] as (keyof typeof instance)[];
|
|
1349
1363
|
const originalValues = pick<typeof instance>(instance, layoutProps);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-nocheck
|
|
2
2
|
|
|
3
3
|
import { scalingEqually } from '../controls/scale';
|
|
4
4
|
import { fireEvent } from '../controls/fireEvent';
|
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
radiansToDegrees,
|
|
8
8
|
} from '../util/misc/radiansDegreesConversion';
|
|
9
9
|
import { Canvas } from './Canvas';
|
|
10
|
-
import { CENTER } from '../constants';
|
|
10
|
+
import { CENTER, ROTATING, ROTATE, SCALE } from '../constants';
|
|
11
|
+
|
|
11
12
|
/**
|
|
12
13
|
* Adds support for multi-touch gestures using the Event.js library.
|
|
13
14
|
* Fires the following custom events:
|
|
@@ -61,13 +62,13 @@ Object.assign(Canvas.prototype, {
|
|
|
61
62
|
const t = this._currentTransform;
|
|
62
63
|
const e = this.__gesturesParams.e;
|
|
63
64
|
|
|
64
|
-
t.action =
|
|
65
|
+
t.action = SCALE;
|
|
65
66
|
t.originX = t.originY = CENTER;
|
|
66
67
|
|
|
67
68
|
this._scaleObjectBy(self.scale, e);
|
|
68
69
|
|
|
69
70
|
if (self.rotation !== 0) {
|
|
70
|
-
t.action =
|
|
71
|
+
t.action = ROTATE;
|
|
71
72
|
this._rotateObjectByAngle(self.rotation, e);
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -171,7 +172,7 @@ Object.assign(Canvas.prototype, {
|
|
|
171
172
|
return;
|
|
172
173
|
}
|
|
173
174
|
t.target.rotate(radiansToDegrees(degreesToRadians(curAngle) + t.theta));
|
|
174
|
-
fireEvent(
|
|
175
|
+
fireEvent(ROTATING, {
|
|
175
176
|
target: t.target,
|
|
176
177
|
e: e,
|
|
177
178
|
transform: t,
|
package/src/constants.ts
CHANGED
|
@@ -25,3 +25,20 @@ export const RIGHT = 'right';
|
|
|
25
25
|
export const NONE = 'none';
|
|
26
26
|
|
|
27
27
|
export const reNewline = /\r?\n/;
|
|
28
|
+
|
|
29
|
+
export const MOVING = 'moving';
|
|
30
|
+
export const SCALING = 'scaling';
|
|
31
|
+
export const ROTATING = 'rotating';
|
|
32
|
+
export const ROTATE = 'rotate';
|
|
33
|
+
export const SKEWING = 'skewing';
|
|
34
|
+
export const RESIZING = 'resizing';
|
|
35
|
+
export const MODIFY_POLY = 'modifyPoly';
|
|
36
|
+
export const CHANGED = 'changed';
|
|
37
|
+
export const SCALE = 'scale';
|
|
38
|
+
export const SCALE_X = 'scaleX';
|
|
39
|
+
export const SCALE_Y = 'scaleY';
|
|
40
|
+
export const SKEW_X = 'skewX';
|
|
41
|
+
export const SKEW_Y = 'skewY';
|
|
42
|
+
export const FILL = 'fill';
|
|
43
|
+
export const STROKE = 'stroke';
|
|
44
|
+
export const MODIFIED = 'modified';
|
package/src/controls/Control.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
} from '../EventTypeDefs';
|
|
7
7
|
import { Intersection } from '../Intersection';
|
|
8
8
|
import { Point } from '../Point';
|
|
9
|
+
import { SCALE } from '../constants';
|
|
9
10
|
import type { InteractiveFabricObject } from '../shapes/Object/InteractiveObject';
|
|
10
11
|
import type { TCornerPoint, TDegree, TMat2D } from '../typedefs';
|
|
11
12
|
import {
|
|
@@ -39,7 +40,7 @@ export class Control {
|
|
|
39
40
|
* @type {String}
|
|
40
41
|
* @default 'scale'
|
|
41
42
|
*/
|
|
42
|
-
actionName =
|
|
43
|
+
actionName = SCALE;
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* Drawing angle of the control.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TransformActionHandler } from '../EventTypeDefs';
|
|
2
|
-
import { CENTER, LEFT, RIGHT } from '../constants';
|
|
2
|
+
import { CENTER, LEFT, RESIZING, RIGHT } from '../constants';
|
|
3
3
|
import { resolveOrigin } from '../util/misc/resolveOrigin';
|
|
4
4
|
import { getLocalPoint, isTransformCentered } from './util';
|
|
5
5
|
import { wrapWithFireEvent } from './wrapWithFireEvent';
|
|
@@ -51,6 +51,6 @@ export const changeObjectWidth: TransformActionHandler = (
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
export const changeWidth = wrapWithFireEvent(
|
|
54
|
-
|
|
54
|
+
RESIZING,
|
|
55
55
|
wrapWithFixedAnchor(changeObjectWidth)
|
|
56
56
|
);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RESIZING, ROTATE } from '../constants';
|
|
1
2
|
import { changeWidth } from './changeWidth';
|
|
2
3
|
import { Control } from './Control';
|
|
3
4
|
import { rotationStyleHandler, rotationWithSnapping } from './rotate';
|
|
@@ -78,7 +79,7 @@ export const createObjectDefaultControls = () => ({
|
|
|
78
79
|
cursorStyleHandler: rotationStyleHandler,
|
|
79
80
|
offsetY: -40,
|
|
80
81
|
withConnection: true,
|
|
81
|
-
actionName:
|
|
82
|
+
actionName: ROTATE,
|
|
82
83
|
}),
|
|
83
84
|
});
|
|
84
85
|
|
|
@@ -88,14 +89,14 @@ export const createResizeControls = () => ({
|
|
|
88
89
|
y: 0,
|
|
89
90
|
actionHandler: changeWidth,
|
|
90
91
|
cursorStyleHandler: scaleSkewCursorStyleHandler,
|
|
91
|
-
actionName:
|
|
92
|
+
actionName: RESIZING,
|
|
92
93
|
}),
|
|
93
94
|
ml: new Control({
|
|
94
95
|
x: -0.5,
|
|
95
96
|
y: 0,
|
|
96
97
|
actionHandler: changeWidth,
|
|
97
98
|
cursorStyleHandler: scaleSkewCursorStyleHandler,
|
|
98
|
-
actionName:
|
|
99
|
+
actionName: RESIZING,
|
|
99
100
|
}),
|
|
100
101
|
});
|
|
101
102
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { twoMathPi } from '../constants';
|
|
1
|
+
import { FILL, STROKE, twoMathPi } from '../constants';
|
|
2
2
|
import type { InteractiveFabricObject } from '../shapes/Object/InteractiveObject';
|
|
3
3
|
import { degreesToRadians } from '../util/misc/radiansDegreesConversion';
|
|
4
4
|
import type { Control } from './Control';
|
|
@@ -50,7 +50,7 @@ export function renderCircleControl(
|
|
|
50
50
|
typeof styleOverride.transparentCorners !== 'undefined'
|
|
51
51
|
? styleOverride.transparentCorners
|
|
52
52
|
: fabricObject.transparentCorners,
|
|
53
|
-
methodName = transparentCorners ?
|
|
53
|
+
methodName = transparentCorners ? STROKE : FILL,
|
|
54
54
|
stroke =
|
|
55
55
|
!transparentCorners &&
|
|
56
56
|
(styleOverride.cornerStrokeColor || fabricObject.cornerStrokeColor);
|
|
@@ -111,7 +111,7 @@ export function renderSquareControl(
|
|
|
111
111
|
typeof styleOverride.transparentCorners !== 'undefined'
|
|
112
112
|
? styleOverride.transparentCorners
|
|
113
113
|
: fabricObject.transparentCorners,
|
|
114
|
-
methodName = transparentCorners ?
|
|
114
|
+
methodName = transparentCorners ? STROKE : FILL,
|
|
115
115
|
stroke =
|
|
116
116
|
!transparentCorners &&
|
|
117
117
|
(styleOverride.cornerStrokeColor || fabricObject.cornerStrokeColor),
|
package/src/controls/drag.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TransformActionHandler } from '../EventTypeDefs';
|
|
2
|
-
import { LEFT, TOP } from '../constants';
|
|
2
|
+
import { LEFT, TOP, MOVING } from '../constants';
|
|
3
3
|
import { fireEvent } from './fireEvent';
|
|
4
4
|
import { commonEventInfo, isLocked } from './util';
|
|
5
5
|
|
|
@@ -26,7 +26,7 @@ export const dragHandler: TransformActionHandler = (
|
|
|
26
26
|
moveX && target.set(LEFT, newLeft);
|
|
27
27
|
moveY && target.set(TOP, newTop);
|
|
28
28
|
if (moveX || moveY) {
|
|
29
|
-
fireEvent(
|
|
29
|
+
fireEvent(MOVING, commonEventInfo(eventData, transform, x, y));
|
|
30
30
|
}
|
|
31
31
|
return moveX || moveY;
|
|
32
32
|
};
|
|
@@ -11,8 +11,9 @@ import type {
|
|
|
11
11
|
} from '../EventTypeDefs';
|
|
12
12
|
import { wrapWithFireEvent } from './wrapWithFireEvent';
|
|
13
13
|
import { sendPointToPlane } from '../util';
|
|
14
|
+
import { MODIFY_POLY } from '../constants';
|
|
14
15
|
|
|
15
|
-
const ACTION_NAME: TModificationEvents =
|
|
16
|
+
const ACTION_NAME: TModificationEvents = MODIFY_POLY;
|
|
16
17
|
|
|
17
18
|
type TTransformAnchor = Transform & { pointIndex: number };
|
|
18
19
|
|
package/src/controls/rotate.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
ControlCursorCallback,
|
|
3
3
|
TransformActionHandler,
|
|
4
4
|
} from '../EventTypeDefs';
|
|
5
|
+
import { ROTATING } from '../constants';
|
|
5
6
|
import { radiansToDegrees } from '../util/misc/radiansDegreesConversion';
|
|
6
7
|
import { isLocked, NOT_ALLOWED_CURSOR } from './util';
|
|
7
8
|
import { wrapWithFireEvent } from './wrapWithFireEvent';
|
|
@@ -82,6 +83,6 @@ const rotateObjectWithSnapping: TransformActionHandler = (
|
|
|
82
83
|
};
|
|
83
84
|
|
|
84
85
|
export const rotationWithSnapping = wrapWithFireEvent(
|
|
85
|
-
|
|
86
|
+
ROTATING,
|
|
86
87
|
wrapWithFixedAnchor(rotateObjectWithSnapping)
|
|
87
88
|
);
|