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":"Polyline.min.mjs","sources":["../../../src/shapes/Polyline.ts"],"sourcesContent":["import { config } from '../config';\nimport { SHARED_ATTRIBUTES } from '../parser/attributes';\nimport { parseAttributes } from '../parser/parseAttributes';\nimport { parsePointsAttribute } from '../parser/parsePointsAttribute';\nimport type { XY } from '../Point';\nimport { Point } from '../Point';\nimport type { Abortable, TClassProperties, TOptions } from '../typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { makeBoundingBoxFromPoints } from '../util/misc/boundingBoxFromPoints';\nimport { calcDimensionsMatrix, transformPoint } from '../util/misc/matrix';\nimport { projectStrokeOnPoints } from '../util/misc/projectStroke';\nimport type { TProjectStrokeOnPointsOptions } from '../util/misc/projectStroke/types';\nimport { degreesToRadians } from '../util/misc/radiansDegreesConversion';\nimport { toFixed } from '../util/misc/toFixed';\nimport { FabricObject, cacheProperties } from './Object/FabricObject';\nimport type { FabricObjectProps, SerializedObjectProps } from './Object/types';\nimport type { ObjectEvents } from '../EventTypeDefs';\nimport { cloneDeep } from '../util/internals/cloneDeep';\nimport { CENTER, LEFT, TOP } from '../constants';\nimport type { CSSRules } from '../parser/typedefs';\n\nexport const polylineDefaultValues: Partial<TClassProperties<Polyline>> = {\n /**\n * @deprecated transient option soon to be removed in favor of a different design\n */\n exactBoundingBox: false,\n};\n\nexport interface SerializedPolylineProps extends SerializedObjectProps {\n points: XY[];\n}\n\nexport class Polyline<\n Props extends TOptions<FabricObjectProps> = Partial<FabricObjectProps>,\n SProps extends SerializedPolylineProps = SerializedPolylineProps,\n EventSpec extends ObjectEvents = ObjectEvents\n> extends FabricObject<Props, SProps, EventSpec> {\n /**\n * Points array\n * @type Array\n * @default\n */\n declare points: XY[];\n\n /**\n * WARNING: Feature in progress\n * Calculate the exact bounding box taking in account strokeWidth on acute angles\n * this will be turned to true by default on fabric 6.0\n * maybe will be left in as an optimization since calculations may be slow\n * @deprecated transient option soon to be removed in favor of a different design\n * @type Boolean\n * @default false\n */\n declare exactBoundingBox: boolean;\n\n private declare initialized: true | undefined;\n\n static ownDefaults = polylineDefaultValues;\n\n static type = 'Polyline';\n\n static getDefaults(): Record<string, any> {\n return {\n ...super.getDefaults(),\n ...Polyline.ownDefaults,\n };\n }\n\n /**\n * A list of properties that if changed trigger a recalculation of dimensions\n * @todo check if you really need to recalculate for all cases\n */\n static layoutProperties: (keyof Polyline)[] = [\n 'skewX',\n 'skewY',\n 'strokeLineCap',\n 'strokeLineJoin',\n 'strokeMiterLimit',\n 'strokeWidth',\n 'strokeUniform',\n 'points',\n ];\n\n declare pathOffset: Point;\n\n declare strokeOffset: Point;\n\n static cacheProperties = [...cacheProperties, 'points'];\n\n strokeDiff: Point;\n\n /**\n * Constructor\n * @param {Array} points Array of points (where each point is an object with x and y)\n * @param {Object} [options] Options object\n * @return {Polyline} thisArg\n * @example\n * var poly = new Polyline([\n * { x: 10, y: 10 },\n * { x: 50, y: 30 },\n * { x: 40, y: 70 },\n * { x: 60, y: 50 },\n * { x: 100, y: 150 },\n * { x: 40, y: 100 }\n * ], {\n * stroke: 'red',\n * left: 100,\n * top: 100\n * });\n */\n constructor(points: XY[] = [], options: Props = {} as Props) {\n super();\n Object.assign(this, Polyline.ownDefaults);\n this.setOptions(options);\n this.points = points;\n const { left, top } = options;\n this.initialized = true;\n this.setBoundingBox(true);\n typeof left === 'number' && this.set(LEFT, left);\n typeof top === 'number' && this.set(TOP, top);\n }\n\n protected isOpen() {\n return true;\n }\n\n private _projectStrokeOnPoints(options: TProjectStrokeOnPointsOptions) {\n return projectStrokeOnPoints(this.points, options, this.isOpen());\n }\n\n /**\n * Calculate the polygon bounding box\n * @private\n */\n _calcDimensions(options?: Partial<TProjectStrokeOnPointsOptions>) {\n options = {\n scaleX: this.scaleX,\n scaleY: this.scaleY,\n skewX: this.skewX,\n skewY: this.skewY,\n strokeLineCap: this.strokeLineCap,\n strokeLineJoin: this.strokeLineJoin,\n strokeMiterLimit: this.strokeMiterLimit,\n strokeUniform: this.strokeUniform,\n strokeWidth: this.strokeWidth,\n ...(options || {}),\n };\n const points = this.exactBoundingBox\n ? this._projectStrokeOnPoints(\n options as TProjectStrokeOnPointsOptions\n ).map((projection) => projection.projectedPoint)\n : this.points;\n if (points.length === 0) {\n return {\n left: 0,\n top: 0,\n width: 0,\n height: 0,\n pathOffset: new Point(),\n strokeOffset: new Point(),\n strokeDiff: new Point(),\n };\n }\n const bbox = makeBoundingBoxFromPoints(points),\n // Remove scale effect, since it's applied after\n matrix = calcDimensionsMatrix({ ...options, scaleX: 1, scaleY: 1 }),\n bboxNoStroke = makeBoundingBoxFromPoints(\n this.points.map((p) => transformPoint(p, matrix, true))\n ),\n scale = new Point(this.scaleX, this.scaleY);\n let offsetX = bbox.left + bbox.width / 2,\n offsetY = bbox.top + bbox.height / 2;\n if (this.exactBoundingBox) {\n offsetX = offsetX - offsetY * Math.tan(degreesToRadians(this.skewX));\n // Order of those assignments is important.\n // offsetY relies on offsetX being already changed by the line above\n offsetY = offsetY - offsetX * Math.tan(degreesToRadians(this.skewY));\n }\n\n return {\n ...bbox,\n pathOffset: new Point(offsetX, offsetY),\n strokeOffset: new Point(bboxNoStroke.left, bboxNoStroke.top)\n .subtract(new Point(bbox.left, bbox.top))\n .multiply(scale),\n strokeDiff: new Point(bbox.width, bbox.height)\n .subtract(new Point(bboxNoStroke.width, bboxNoStroke.height))\n .multiply(scale),\n };\n }\n\n /**\n * This function is an helper for svg import. it returns the center of the object in the svg\n * untransformed coordinates, by look at the polyline/polygon points.\n * @private\n * @return {Point} center point from element coordinates\n */\n _findCenterFromElement(): Point {\n const bbox = makeBoundingBoxFromPoints(this.points);\n return new Point(bbox.left + bbox.width / 2, bbox.top + bbox.height / 2);\n }\n\n setDimensions() {\n this.setBoundingBox();\n }\n\n setBoundingBox(adjustPosition?: boolean) {\n const { left, top, width, height, pathOffset, strokeOffset, strokeDiff } =\n this._calcDimensions();\n this.set({ width, height, pathOffset, strokeOffset, strokeDiff });\n adjustPosition &&\n this.setPositionByOrigin(\n new Point(left + width / 2, top + height / 2),\n CENTER,\n CENTER\n );\n }\n\n /**\n * @deprecated intermidiate method to be removed, do not use\n */\n protected isStrokeAccountedForInDimensions() {\n return this.exactBoundingBox;\n }\n\n /**\n * @override stroke is taken in account in size\n */\n _getNonTransformedDimensions() {\n return this.exactBoundingBox\n ? // TODO: fix this\n new Point(this.width, this.height)\n : super._getNonTransformedDimensions();\n }\n\n /**\n * @override stroke and skewing are taken into account when projecting stroke on points,\n * therefore we don't want the default calculation to account for skewing as well.\n * Though it is possible to pass `width` and `height` in `options`, doing so is very strange, use with discretion.\n *\n * @private\n */\n _getTransformedDimensions(options: any = {}) {\n if (this.exactBoundingBox) {\n let size: Point;\n /* When `strokeUniform = true`, any changes to the properties require recalculating the `width` and `height` because\n the stroke projections are affected.\n When `strokeUniform = false`, we don't need to recalculate for scale transformations, as the effect of scale on\n projections follows a linear function (e.g. scaleX of 2 just multiply width by 2)*/\n if (\n Object.keys(options).some(\n (key) =>\n this.strokeUniform ||\n (this.constructor as typeof Polyline).layoutProperties.includes(\n key as keyof TProjectStrokeOnPointsOptions\n )\n )\n ) {\n const { width, height } = this._calcDimensions(options);\n size = new Point(options.width ?? width, options.height ?? height);\n } else {\n size = new Point(\n options.width ?? this.width,\n options.height ?? this.height\n );\n }\n return size.multiply(\n new Point(options.scaleX || this.scaleX, options.scaleY || this.scaleY)\n );\n } else {\n return super._getTransformedDimensions(options);\n }\n }\n\n /**\n * Recalculates dimensions when changing skew and scale\n * @private\n */\n _set(key: string, value: any) {\n const changed = this.initialized && this[key as keyof this] !== value;\n const output = super._set(key, value);\n if (\n this.exactBoundingBox &&\n changed &&\n (((key === 'scaleX' || key === 'scaleY') &&\n this.strokeUniform &&\n (this.constructor as typeof Polyline).layoutProperties.includes(\n 'strokeUniform'\n )) ||\n (this.constructor as typeof Polyline).layoutProperties.includes(\n key as keyof Polyline\n ))\n ) {\n this.setDimensions();\n }\n return output;\n }\n\n /**\n * Returns object representation of an instance\n * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output\n * @return {Object} Object representation of an instance\n */\n toObject<\n T extends Omit<Props & TClassProperties<this>, keyof SProps>,\n K extends keyof T = never\n >(propertiesToInclude: K[] = []): Pick<T, K> & SProps {\n return {\n ...super.toObject(propertiesToInclude),\n points: cloneDeep(this.points),\n };\n }\n\n /**\n * Returns svg representation of an instance\n * @return {Array} an array of strings with the specific svg representation\n * of the instance\n */\n _toSVG() {\n const points = [],\n diffX = this.pathOffset.x,\n diffY = this.pathOffset.y,\n NUM_FRACTION_DIGITS = config.NUM_FRACTION_DIGITS;\n\n for (let i = 0, len = this.points.length; i < len; i++) {\n points.push(\n toFixed(this.points[i].x - diffX, NUM_FRACTION_DIGITS),\n ',',\n toFixed(this.points[i].y - diffY, NUM_FRACTION_DIGITS),\n ' '\n );\n }\n return [\n `<${\n (this.constructor as typeof Polyline).type.toLowerCase() as\n | 'polyline'\n | 'polygon'\n } `,\n 'COMMON_PARTS',\n `points=\"${points.join('')}\" />\\n`,\n ];\n }\n\n /**\n * @private\n * @param {CanvasRenderingContext2D} ctx Context to render on\n */\n _render(ctx: CanvasRenderingContext2D) {\n const len = this.points.length,\n x = this.pathOffset.x,\n y = this.pathOffset.y;\n\n if (!len || isNaN(this.points[len - 1].y)) {\n // do not draw if no points or odd points\n // NaN comes from parseFloat of a empty string in parser\n return;\n }\n ctx.beginPath();\n ctx.moveTo(this.points[0].x - x, this.points[0].y - y);\n for (let i = 0; i < len; i++) {\n const point = this.points[i];\n ctx.lineTo(point.x - x, point.y - y);\n }\n !this.isOpen() && ctx.closePath();\n this._renderPaintInOrder(ctx);\n }\n\n /**\n * Returns complexity of an instance\n * @return {Number} complexity of this instance\n */\n complexity(): number {\n return this.points.length;\n }\n\n /* _FROM_SVG_START_ */\n\n /**\n * List of attribute names to account for when parsing SVG element (used by {@link Polyline.fromElement})\n * @static\n * @memberOf Polyline\n * @see: http://www.w3.org/TR/SVG/shapes.html#PolylineElement\n */\n static ATTRIBUTE_NAMES = [...SHARED_ATTRIBUTES];\n\n /**\n * Returns Polyline instance from an SVG element\n * @static\n * @memberOf Polyline\n * @param {HTMLElement} element Element to parser\n * @param {Object} [options] Options object\n */\n static async fromElement(\n element: HTMLElement,\n options: Abortable,\n cssRules?: CSSRules\n ) {\n const points = parsePointsAttribute(element.getAttribute('points')),\n // we omit left and top to instruct the constructor to position the object using the bbox\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n { left, top, ...parsedAttributes } = parseAttributes(\n element,\n this.ATTRIBUTE_NAMES,\n cssRules\n );\n return new this(points, {\n ...parsedAttributes,\n ...options,\n });\n }\n\n /* _FROM_SVG_END_ */\n\n /**\n * Returns Polyline instance from an object representation\n * @static\n * @memberOf Polyline\n * @param {Object} object Object to create an instance from\n * @returns {Promise<Polyline>}\n */\n static fromObject<T extends TOptions<SerializedPolylineProps>>(object: T) {\n return this._fromObject<Polyline>(object, {\n extraParam: 'points',\n });\n }\n}\n\nclassRegistry.setClass(Polyline);\nclassRegistry.setSVGClass(Polyline);\n"],"names":["polylineDefaultValues","exactBoundingBox","Polyline","FabricObject","getDefaults","_objectSpread","super","ownDefaults","constructor","points","arguments","length","undefined","options","_defineProperty","this","Object","assign","setOptions","left","top","initialized","setBoundingBox","set","LEFT","TOP","isOpen","_projectStrokeOnPoints","projectStrokeOnPoints","_calcDimensions","scaleX","scaleY","skewX","skewY","strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeUniform","strokeWidth","map","projection","projectedPoint","width","height","pathOffset","Point","strokeOffset","strokeDiff","bbox","makeBoundingBoxFromPoints","matrix","calcDimensionsMatrix","bboxNoStroke","p","transformPoint","scale","offsetX","offsetY","Math","tan","degreesToRadians","subtract","multiply","_findCenterFromElement","setDimensions","adjustPosition","setPositionByOrigin","CENTER","isStrokeAccountedForInDimensions","_getNonTransformedDimensions","_getTransformedDimensions","size","keys","some","key","layoutProperties","includes","_options$width","_options$height","_options$width2","_options$height2","_set","value","changed","output","toObject","propertiesToInclude","cloneDeep","_toSVG","diffX","x","diffY","y","NUM_FRACTION_DIGITS","config","i","len","push","toFixed","concat","type","toLowerCase","join","_render","ctx","isNaN","beginPath","moveTo","point","lineTo","closePath","_renderPaintInOrder","complexity","fromElement","element","cssRules","parsePointsAttribute","getAttribute","_parseAttributes","parseAttributes","ATTRIBUTE_NAMES","parsedAttributes","_objectWithoutProperties","_excluded","fromObject","object","_fromObject","extraParam","cacheProperties","SHARED_ATTRIBUTES","classRegistry","setClass","setSVGClass"],"mappings":"+nCAqBaA,EAA6D,CAIxEC,kBAAkB,GAOb,MAAMC,UAIHC,EAyBR,kBAAOC,GACL,OAAAC,EAAAA,EAAA,GACKC,MAAMF,eACNF,EAASK,YAEhB,CA4CAC,WAAAA,GAA6D,IAAjDC,EAAYC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,GAAIG,EAAcH,UAAAC,OAAA,QAAAC,IAAAF,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AAAJ,EAAAK,GAKlC,OAAO,IAAI5G,KAAKN,EAAMJ,EAAAA,EACjBoH,CAAAA,EAAAA,GACA5G,GAEP,CAWA,iBAAO+G,CAAwDC,GAC7D,OAAO9G,KAAK+G,YAAsBD,EAAQ,CACxCE,WAAY,UAEhB,EA5XAjH,EAZWZ,EAAQ,cAyBEF,GAAqBc,EAzB/BZ,EAAQ,OA2BL,YAAUY,EA3BbZ,EAAQ,mBAwC2B,CAC5C,QACA,QACA,gBACA,iBACA,mBACA,cACA,gBACA,WACDY,EAjDUZ,EAuDc,kBAAA,IAAI8H,EAAiB,WAASlH,EAvD5CZ,EAAQ,kBA+VM,IAAI+H,IA4C/BC,EAAcC,SAASjI,GACvBgI,EAAcE,YAAYlI"}
|
|
1
|
+
{"version":3,"file":"Polyline.min.mjs","sources":["../../../src/shapes/Polyline.ts"],"sourcesContent":["import { config } from '../config';\nimport { SHARED_ATTRIBUTES } from '../parser/attributes';\nimport { parseAttributes } from '../parser/parseAttributes';\nimport { parsePointsAttribute } from '../parser/parsePointsAttribute';\nimport type { XY } from '../Point';\nimport { Point } from '../Point';\nimport type { Abortable, TClassProperties, TOptions } from '../typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { makeBoundingBoxFromPoints } from '../util/misc/boundingBoxFromPoints';\nimport { calcDimensionsMatrix, transformPoint } from '../util/misc/matrix';\nimport { projectStrokeOnPoints } from '../util/misc/projectStroke';\nimport type { TProjectStrokeOnPointsOptions } from '../util/misc/projectStroke/types';\nimport { degreesToRadians } from '../util/misc/radiansDegreesConversion';\nimport { toFixed } from '../util/misc/toFixed';\nimport { FabricObject, cacheProperties } from './Object/FabricObject';\nimport type { FabricObjectProps, SerializedObjectProps } from './Object/types';\nimport type { ObjectEvents } from '../EventTypeDefs';\nimport { cloneDeep } from '../util/internals/cloneDeep';\nimport {\n CENTER,\n LEFT,\n SCALE_X,\n SCALE_Y,\n SKEW_X,\n SKEW_Y,\n TOP,\n} from '../constants';\nimport type { CSSRules } from '../parser/typedefs';\n\nexport const polylineDefaultValues: Partial<TClassProperties<Polyline>> = {\n /**\n * @deprecated transient option soon to be removed in favor of a different design\n */\n exactBoundingBox: false,\n};\n\nexport interface SerializedPolylineProps extends SerializedObjectProps {\n points: XY[];\n}\n\nexport class Polyline<\n Props extends TOptions<FabricObjectProps> = Partial<FabricObjectProps>,\n SProps extends SerializedPolylineProps = SerializedPolylineProps,\n EventSpec extends ObjectEvents = ObjectEvents\n> extends FabricObject<Props, SProps, EventSpec> {\n /**\n * Points array\n * @type Array\n * @default\n */\n declare points: XY[];\n\n /**\n * WARNING: Feature in progress\n * Calculate the exact bounding box taking in account strokeWidth on acute angles\n * this will be turned to true by default on fabric 6.0\n * maybe will be left in as an optimization since calculations may be slow\n * @deprecated transient option soon to be removed in favor of a different design\n * @type Boolean\n * @default false\n */\n declare exactBoundingBox: boolean;\n\n private declare initialized: true | undefined;\n\n static ownDefaults = polylineDefaultValues;\n\n static type = 'Polyline';\n\n static getDefaults(): Record<string, any> {\n return {\n ...super.getDefaults(),\n ...Polyline.ownDefaults,\n };\n }\n\n /**\n * A list of properties that if changed trigger a recalculation of dimensions\n * @todo check if you really need to recalculate for all cases\n */\n static layoutProperties: (keyof Polyline)[] = [\n SKEW_X,\n SKEW_Y,\n 'strokeLineCap',\n 'strokeLineJoin',\n 'strokeMiterLimit',\n 'strokeWidth',\n 'strokeUniform',\n 'points',\n ];\n\n declare pathOffset: Point;\n\n declare strokeOffset: Point;\n\n static cacheProperties = [...cacheProperties, 'points'];\n\n strokeDiff: Point;\n\n /**\n * Constructor\n * @param {Array} points Array of points (where each point is an object with x and y)\n * @param {Object} [options] Options object\n * @return {Polyline} thisArg\n * @example\n * var poly = new Polyline([\n * { x: 10, y: 10 },\n * { x: 50, y: 30 },\n * { x: 40, y: 70 },\n * { x: 60, y: 50 },\n * { x: 100, y: 150 },\n * { x: 40, y: 100 }\n * ], {\n * stroke: 'red',\n * left: 100,\n * top: 100\n * });\n */\n constructor(points: XY[] = [], options: Props = {} as Props) {\n super();\n Object.assign(this, Polyline.ownDefaults);\n this.setOptions(options);\n this.points = points;\n const { left, top } = options;\n this.initialized = true;\n this.setBoundingBox(true);\n typeof left === 'number' && this.set(LEFT, left);\n typeof top === 'number' && this.set(TOP, top);\n }\n\n protected isOpen() {\n return true;\n }\n\n private _projectStrokeOnPoints(options: TProjectStrokeOnPointsOptions) {\n return projectStrokeOnPoints(this.points, options, this.isOpen());\n }\n\n /**\n * Calculate the polygon bounding box\n * @private\n */\n _calcDimensions(options?: Partial<TProjectStrokeOnPointsOptions>) {\n options = {\n scaleX: this.scaleX,\n scaleY: this.scaleY,\n skewX: this.skewX,\n skewY: this.skewY,\n strokeLineCap: this.strokeLineCap,\n strokeLineJoin: this.strokeLineJoin,\n strokeMiterLimit: this.strokeMiterLimit,\n strokeUniform: this.strokeUniform,\n strokeWidth: this.strokeWidth,\n ...(options || {}),\n };\n const points = this.exactBoundingBox\n ? this._projectStrokeOnPoints(\n options as TProjectStrokeOnPointsOptions\n ).map((projection) => projection.projectedPoint)\n : this.points;\n if (points.length === 0) {\n return {\n left: 0,\n top: 0,\n width: 0,\n height: 0,\n pathOffset: new Point(),\n strokeOffset: new Point(),\n strokeDiff: new Point(),\n };\n }\n const bbox = makeBoundingBoxFromPoints(points),\n // Remove scale effect, since it's applied after\n matrix = calcDimensionsMatrix({ ...options, scaleX: 1, scaleY: 1 }),\n bboxNoStroke = makeBoundingBoxFromPoints(\n this.points.map((p) => transformPoint(p, matrix, true))\n ),\n scale = new Point(this.scaleX, this.scaleY);\n let offsetX = bbox.left + bbox.width / 2,\n offsetY = bbox.top + bbox.height / 2;\n if (this.exactBoundingBox) {\n offsetX = offsetX - offsetY * Math.tan(degreesToRadians(this.skewX));\n // Order of those assignments is important.\n // offsetY relies on offsetX being already changed by the line above\n offsetY = offsetY - offsetX * Math.tan(degreesToRadians(this.skewY));\n }\n\n return {\n ...bbox,\n pathOffset: new Point(offsetX, offsetY),\n strokeOffset: new Point(bboxNoStroke.left, bboxNoStroke.top)\n .subtract(new Point(bbox.left, bbox.top))\n .multiply(scale),\n strokeDiff: new Point(bbox.width, bbox.height)\n .subtract(new Point(bboxNoStroke.width, bboxNoStroke.height))\n .multiply(scale),\n };\n }\n\n /**\n * This function is an helper for svg import. it returns the center of the object in the svg\n * untransformed coordinates, by look at the polyline/polygon points.\n * @private\n * @return {Point} center point from element coordinates\n */\n _findCenterFromElement(): Point {\n const bbox = makeBoundingBoxFromPoints(this.points);\n return new Point(bbox.left + bbox.width / 2, bbox.top + bbox.height / 2);\n }\n\n setDimensions() {\n this.setBoundingBox();\n }\n\n setBoundingBox(adjustPosition?: boolean) {\n const { left, top, width, height, pathOffset, strokeOffset, strokeDiff } =\n this._calcDimensions();\n this.set({ width, height, pathOffset, strokeOffset, strokeDiff });\n adjustPosition &&\n this.setPositionByOrigin(\n new Point(left + width / 2, top + height / 2),\n CENTER,\n CENTER\n );\n }\n\n /**\n * @deprecated intermidiate method to be removed, do not use\n */\n protected isStrokeAccountedForInDimensions() {\n return this.exactBoundingBox;\n }\n\n /**\n * @override stroke is taken in account in size\n */\n _getNonTransformedDimensions() {\n return this.exactBoundingBox\n ? // TODO: fix this\n new Point(this.width, this.height)\n : super._getNonTransformedDimensions();\n }\n\n /**\n * @override stroke and skewing are taken into account when projecting stroke on points,\n * therefore we don't want the default calculation to account for skewing as well.\n * Though it is possible to pass `width` and `height` in `options`, doing so is very strange, use with discretion.\n *\n * @private\n */\n _getTransformedDimensions(options: any = {}) {\n if (this.exactBoundingBox) {\n let size: Point;\n /* When `strokeUniform = true`, any changes to the properties require recalculating the `width` and `height` because\n the stroke projections are affected.\n When `strokeUniform = false`, we don't need to recalculate for scale transformations, as the effect of scale on\n projections follows a linear function (e.g. scaleX of 2 just multiply width by 2)*/\n if (\n Object.keys(options).some(\n (key) =>\n this.strokeUniform ||\n (this.constructor as typeof Polyline).layoutProperties.includes(\n key as keyof TProjectStrokeOnPointsOptions\n )\n )\n ) {\n const { width, height } = this._calcDimensions(options);\n size = new Point(options.width ?? width, options.height ?? height);\n } else {\n size = new Point(\n options.width ?? this.width,\n options.height ?? this.height\n );\n }\n return size.multiply(\n new Point(options.scaleX || this.scaleX, options.scaleY || this.scaleY)\n );\n } else {\n return super._getTransformedDimensions(options);\n }\n }\n\n /**\n * Recalculates dimensions when changing skew and scale\n * @private\n */\n _set(key: string, value: any) {\n const changed = this.initialized && this[key as keyof this] !== value;\n const output = super._set(key, value);\n if (\n this.exactBoundingBox &&\n changed &&\n (((key === SCALE_X || key === SCALE_Y) &&\n this.strokeUniform &&\n (this.constructor as typeof Polyline).layoutProperties.includes(\n 'strokeUniform'\n )) ||\n (this.constructor as typeof Polyline).layoutProperties.includes(\n key as keyof Polyline\n ))\n ) {\n this.setDimensions();\n }\n return output;\n }\n\n /**\n * Returns object representation of an instance\n * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output\n * @return {Object} Object representation of an instance\n */\n toObject<\n T extends Omit<Props & TClassProperties<this>, keyof SProps>,\n K extends keyof T = never\n >(propertiesToInclude: K[] = []): Pick<T, K> & SProps {\n return {\n ...super.toObject(propertiesToInclude),\n points: cloneDeep(this.points),\n };\n }\n\n /**\n * Returns svg representation of an instance\n * @return {Array} an array of strings with the specific svg representation\n * of the instance\n */\n _toSVG() {\n const points = [],\n diffX = this.pathOffset.x,\n diffY = this.pathOffset.y,\n NUM_FRACTION_DIGITS = config.NUM_FRACTION_DIGITS;\n\n for (let i = 0, len = this.points.length; i < len; i++) {\n points.push(\n toFixed(this.points[i].x - diffX, NUM_FRACTION_DIGITS),\n ',',\n toFixed(this.points[i].y - diffY, NUM_FRACTION_DIGITS),\n ' '\n );\n }\n return [\n `<${\n (this.constructor as typeof Polyline).type.toLowerCase() as\n | 'polyline'\n | 'polygon'\n } `,\n 'COMMON_PARTS',\n `points=\"${points.join('')}\" />\\n`,\n ];\n }\n\n /**\n * @private\n * @param {CanvasRenderingContext2D} ctx Context to render on\n */\n _render(ctx: CanvasRenderingContext2D) {\n const len = this.points.length,\n x = this.pathOffset.x,\n y = this.pathOffset.y;\n\n if (!len || isNaN(this.points[len - 1].y)) {\n // do not draw if no points or odd points\n // NaN comes from parseFloat of a empty string in parser\n return;\n }\n ctx.beginPath();\n ctx.moveTo(this.points[0].x - x, this.points[0].y - y);\n for (let i = 0; i < len; i++) {\n const point = this.points[i];\n ctx.lineTo(point.x - x, point.y - y);\n }\n !this.isOpen() && ctx.closePath();\n this._renderPaintInOrder(ctx);\n }\n\n /**\n * Returns complexity of an instance\n * @return {Number} complexity of this instance\n */\n complexity(): number {\n return this.points.length;\n }\n\n /* _FROM_SVG_START_ */\n\n /**\n * List of attribute names to account for when parsing SVG element (used by {@link Polyline.fromElement})\n * @static\n * @memberOf Polyline\n * @see: http://www.w3.org/TR/SVG/shapes.html#PolylineElement\n */\n static ATTRIBUTE_NAMES = [...SHARED_ATTRIBUTES];\n\n /**\n * Returns Polyline instance from an SVG element\n * @static\n * @memberOf Polyline\n * @param {HTMLElement} element Element to parser\n * @param {Object} [options] Options object\n */\n static async fromElement(\n element: HTMLElement,\n options: Abortable,\n cssRules?: CSSRules\n ) {\n const points = parsePointsAttribute(element.getAttribute('points')),\n // we omit left and top to instruct the constructor to position the object using the bbox\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n { left, top, ...parsedAttributes } = parseAttributes(\n element,\n this.ATTRIBUTE_NAMES,\n cssRules\n );\n return new this(points, {\n ...parsedAttributes,\n ...options,\n });\n }\n\n /* _FROM_SVG_END_ */\n\n /**\n * Returns Polyline instance from an object representation\n * @static\n * @memberOf Polyline\n * @param {Object} object Object to create an instance from\n * @returns {Promise<Polyline>}\n */\n static fromObject<T extends TOptions<SerializedPolylineProps>>(object: T) {\n return this._fromObject<Polyline>(object, {\n extraParam: 'points',\n });\n }\n}\n\nclassRegistry.setClass(Polyline);\nclassRegistry.setSVGClass(Polyline);\n"],"names":["polylineDefaultValues","exactBoundingBox","Polyline","FabricObject","getDefaults","_objectSpread","super","ownDefaults","constructor","points","arguments","length","undefined","options","_defineProperty","this","Object","assign","setOptions","left","top","initialized","setBoundingBox","set","LEFT","TOP","isOpen","_projectStrokeOnPoints","projectStrokeOnPoints","_calcDimensions","scaleX","scaleY","skewX","skewY","strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeUniform","strokeWidth","map","projection","projectedPoint","width","height","pathOffset","Point","strokeOffset","strokeDiff","bbox","makeBoundingBoxFromPoints","matrix","calcDimensionsMatrix","bboxNoStroke","p","transformPoint","scale","offsetX","offsetY","Math","tan","degreesToRadians","subtract","multiply","_findCenterFromElement","setDimensions","adjustPosition","setPositionByOrigin","CENTER","isStrokeAccountedForInDimensions","_getNonTransformedDimensions","_getTransformedDimensions","size","keys","some","key","layoutProperties","includes","_options$width","_options$height","_options$width2","_options$height2","_set","value","changed","output","SCALE_X","SCALE_Y","toObject","propertiesToInclude","cloneDeep","_toSVG","diffX","x","diffY","y","NUM_FRACTION_DIGITS","config","i","len","push","toFixed","concat","type","toLowerCase","join","_render","ctx","isNaN","beginPath","moveTo","point","lineTo","closePath","_renderPaintInOrder","complexity","fromElement","element","cssRules","parsePointsAttribute","getAttribute","_parseAttributes","parseAttributes","ATTRIBUTE_NAMES","parsedAttributes","_objectWithoutProperties","_excluded","fromObject","object","_fromObject","extraParam","SKEW_X","SKEW_Y","cacheProperties","SHARED_ATTRIBUTES","classRegistry","setClass","setSVGClass"],"mappings":"irCA6BaA,EAA6D,CAIxEC,kBAAkB,GAOb,MAAMC,UAIHC,EAyBR,kBAAOC,GACL,OAAAC,EAAAA,EAAA,GACKC,MAAMF,eACNF,EAASK,YAEhB,CA4CAC,WAAAA,GAA6D,IAAjDC,EAAYC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,GAAIG,EAAcH,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,CAAA,EAC9CJ,QAAQQ,EAAAC,KAAA,kBAAA,GACRC,OAAOC,OAAOF,KAAMb,E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,CAWA,iBAAOiH,CAAwDC,GAC7D,OAAOhH,KAAKiH,YAAsBD,EAAQ,CACxCE,WAAY,UAEhB,EA5XAnH,EAZWZ,EAAQ,cAyBEF,GAAqBc,EAzB/BZ,EAAQ,OA2BL,YAAUY,EA3BbZ,EAAQ,mBAwC2B,CAC5CgI,EACAC,EACA,gBACA,iBACA,mBACA,cACA,gBACA,WACDrH,EAjDUZ,EAuDc,kBAAA,IAAIkI,EAAiB,WAAStH,EAvD5CZ,EAAQ,kBA+VM,IAAImI,IA4C/BC,EAAcC,SAASrI,GACvBoI,EAAcE,YAAYtI"}
|
|
@@ -12,7 +12,7 @@ import { degreesToRadians } from '../util/misc/radiansDegreesConversion.mjs';
|
|
|
12
12
|
import { toFixed } from '../util/misc/toFixed.mjs';
|
|
13
13
|
import { FabricObject } from './Object/FabricObject.mjs';
|
|
14
14
|
import { cloneDeep } from '../util/internals/cloneDeep.mjs';
|
|
15
|
-
import { LEFT, TOP, CENTER } from '../constants.mjs';
|
|
15
|
+
import { LEFT, TOP, CENTER, SCALE_X, SCALE_Y, SKEW_X, SKEW_Y } from '../constants.mjs';
|
|
16
16
|
import { cacheProperties } from './Object/defaultValues.mjs';
|
|
17
17
|
|
|
18
18
|
const _excluded = ["left", "top"];
|
|
@@ -214,7 +214,7 @@ class Polyline extends FabricObject {
|
|
|
214
214
|
_set(key, value) {
|
|
215
215
|
const changed = this.initialized && this[key] !== value;
|
|
216
216
|
const output = super._set(key, value);
|
|
217
|
-
if (this.exactBoundingBox && changed && ((key ===
|
|
217
|
+
if (this.exactBoundingBox && changed && ((key === SCALE_X || key === SCALE_Y) && this.strokeUniform && this.constructor.layoutProperties.includes('strokeUniform') || this.constructor.layoutProperties.includes(key))) {
|
|
218
218
|
this.setDimensions();
|
|
219
219
|
}
|
|
220
220
|
return output;
|
|
@@ -333,7 +333,7 @@ class Polyline extends FabricObject {
|
|
|
333
333
|
*/
|
|
334
334
|
_defineProperty(Polyline, "ownDefaults", polylineDefaultValues);
|
|
335
335
|
_defineProperty(Polyline, "type", 'Polyline');
|
|
336
|
-
_defineProperty(Polyline, "layoutProperties", [
|
|
336
|
+
_defineProperty(Polyline, "layoutProperties", [SKEW_X, SKEW_Y, 'strokeLineCap', 'strokeLineJoin', 'strokeMiterLimit', 'strokeWidth', 'strokeUniform', 'points']);
|
|
337
337
|
_defineProperty(Polyline, "cacheProperties", [...cacheProperties, 'points']);
|
|
338
338
|
_defineProperty(Polyline, "ATTRIBUTE_NAMES", [...SHARED_ATTRIBUTES]);
|
|
339
339
|
classRegistry.setClass(Polyline);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Polyline.mjs","sources":["../../../src/shapes/Polyline.ts"],"sourcesContent":["import { config } from '../config';\nimport { SHARED_ATTRIBUTES } from '../parser/attributes';\nimport { parseAttributes } from '../parser/parseAttributes';\nimport { parsePointsAttribute } from '../parser/parsePointsAttribute';\nimport type { XY } from '../Point';\nimport { Point } from '../Point';\nimport type { Abortable, TClassProperties, TOptions } from '../typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { makeBoundingBoxFromPoints } from '../util/misc/boundingBoxFromPoints';\nimport { calcDimensionsMatrix, transformPoint } from '../util/misc/matrix';\nimport { projectStrokeOnPoints } from '../util/misc/projectStroke';\nimport type { TProjectStrokeOnPointsOptions } from '../util/misc/projectStroke/types';\nimport { degreesToRadians } from '../util/misc/radiansDegreesConversion';\nimport { toFixed } from '../util/misc/toFixed';\nimport { FabricObject, cacheProperties } from './Object/FabricObject';\nimport type { FabricObjectProps, SerializedObjectProps } from './Object/types';\nimport type { ObjectEvents } from '../EventTypeDefs';\nimport { cloneDeep } from '../util/internals/cloneDeep';\nimport { CENTER, LEFT, TOP } from '../constants';\nimport type { CSSRules } from '../parser/typedefs';\n\nexport const polylineDefaultValues: Partial<TClassProperties<Polyline>> = {\n /**\n * @deprecated transient option soon to be removed in favor of a different design\n */\n exactBoundingBox: false,\n};\n\nexport interface SerializedPolylineProps extends SerializedObjectProps {\n points: XY[];\n}\n\nexport class Polyline<\n Props extends TOptions<FabricObjectProps> = Partial<FabricObjectProps>,\n SProps extends SerializedPolylineProps = SerializedPolylineProps,\n EventSpec extends ObjectEvents = ObjectEvents\n> extends FabricObject<Props, SProps, EventSpec> {\n /**\n * Points array\n * @type Array\n * @default\n */\n declare points: XY[];\n\n /**\n * WARNING: Feature in progress\n * Calculate the exact bounding box taking in account strokeWidth on acute angles\n * this will be turned to true by default on fabric 6.0\n * maybe will be left in as an optimization since calculations may be slow\n * @deprecated transient option soon to be removed in favor of a different design\n * @type Boolean\n * @default false\n */\n declare exactBoundingBox: boolean;\n\n private declare initialized: true | undefined;\n\n static ownDefaults = polylineDefaultValues;\n\n static type = 'Polyline';\n\n static getDefaults(): Record<string, any> {\n return {\n ...super.getDefaults(),\n ...Polyline.ownDefaults,\n };\n }\n\n /**\n * A list of properties that if changed trigger a recalculation of dimensions\n * @todo check if you really need to recalculate for all cases\n */\n static layoutProperties: (keyof Polyline)[] = [\n 'skewX',\n 'skewY',\n 'strokeLineCap',\n 'strokeLineJoin',\n 'strokeMiterLimit',\n 'strokeWidth',\n 'strokeUniform',\n 'points',\n ];\n\n declare pathOffset: Point;\n\n declare strokeOffset: Point;\n\n static cacheProperties = [...cacheProperties, 'points'];\n\n strokeDiff: Point;\n\n /**\n * Constructor\n * @param {Array} points Array of points (where each point is an object with x and y)\n * @param {Object} [options] Options object\n * @return {Polyline} thisArg\n * @example\n * var poly = new Polyline([\n * { x: 10, y: 10 },\n * { x: 50, y: 30 },\n * { x: 40, y: 70 },\n * { x: 60, y: 50 },\n * { x: 100, y: 150 },\n * { x: 40, y: 100 }\n * ], {\n * stroke: 'red',\n * left: 100,\n * top: 100\n * });\n */\n constructor(points: XY[] = [], options: Props = {} as Props) {\n super();\n Object.assign(this, Polyline.ownDefaults);\n this.setOptions(options);\n this.points = points;\n const { left, top } = options;\n this.initialized = true;\n this.setBoundingBox(true);\n typeof left === 'number' && this.set(LEFT, left);\n typeof top === 'number' && this.set(TOP, top);\n }\n\n protected isOpen() {\n return true;\n }\n\n private _projectStrokeOnPoints(options: TProjectStrokeOnPointsOptions) {\n return projectStrokeOnPoints(this.points, options, this.isOpen());\n }\n\n /**\n * Calculate the polygon bounding box\n * @private\n */\n _calcDimensions(options?: Partial<TProjectStrokeOnPointsOptions>) {\n options = {\n scaleX: this.scaleX,\n scaleY: this.scaleY,\n skewX: this.skewX,\n skewY: this.skewY,\n strokeLineCap: this.strokeLineCap,\n strokeLineJoin: this.strokeLineJoin,\n strokeMiterLimit: this.strokeMiterLimit,\n strokeUniform: this.strokeUniform,\n strokeWidth: this.strokeWidth,\n ...(options || {}),\n };\n const points = this.exactBoundingBox\n ? this._projectStrokeOnPoints(\n options as TProjectStrokeOnPointsOptions\n ).map((projection) => projection.projectedPoint)\n : this.points;\n if (points.length === 0) {\n return {\n left: 0,\n top: 0,\n width: 0,\n height: 0,\n pathOffset: new Point(),\n strokeOffset: new Point(),\n strokeDiff: new Point(),\n };\n }\n const bbox = makeBoundingBoxFromPoints(points),\n // Remove scale effect, since it's applied after\n matrix = calcDimensionsMatrix({ ...options, scaleX: 1, scaleY: 1 }),\n bboxNoStroke = makeBoundingBoxFromPoints(\n this.points.map((p) => transformPoint(p, matrix, true))\n ),\n scale = new Point(this.scaleX, this.scaleY);\n let offsetX = bbox.left + bbox.width / 2,\n offsetY = bbox.top + bbox.height / 2;\n if (this.exactBoundingBox) {\n offsetX = offsetX - offsetY * Math.tan(degreesToRadians(this.skewX));\n // Order of those assignments is important.\n // offsetY relies on offsetX being already changed by the line above\n offsetY = offsetY - offsetX * Math.tan(degreesToRadians(this.skewY));\n }\n\n return {\n ...bbox,\n pathOffset: new Point(offsetX, offsetY),\n strokeOffset: new Point(bboxNoStroke.left, bboxNoStroke.top)\n .subtract(new Point(bbox.left, bbox.top))\n .multiply(scale),\n strokeDiff: new Point(bbox.width, bbox.height)\n .subtract(new Point(bboxNoStroke.width, bboxNoStroke.height))\n .multiply(scale),\n };\n }\n\n /**\n * This function is an helper for svg import. it returns the center of the object in the svg\n * untransformed coordinates, by look at the polyline/polygon points.\n * @private\n * @return {Point} center point from element coordinates\n */\n _findCenterFromElement(): Point {\n const bbox = makeBoundingBoxFromPoints(this.points);\n return new Point(bbox.left + bbox.width / 2, bbox.top + bbox.height / 2);\n }\n\n setDimensions() {\n this.setBoundingBox();\n }\n\n setBoundingBox(adjustPosition?: boolean) {\n const { left, top, width, height, pathOffset, strokeOffset, strokeDiff } =\n this._calcDimensions();\n this.set({ width, height, pathOffset, strokeOffset, strokeDiff });\n adjustPosition &&\n this.setPositionByOrigin(\n new Point(left + width / 2, top + height / 2),\n CENTER,\n CENTER\n );\n }\n\n /**\n * @deprecated intermidiate method to be removed, do not use\n */\n protected isStrokeAccountedForInDimensions() {\n return this.exactBoundingBox;\n }\n\n /**\n * @override stroke is taken in account in size\n */\n _getNonTransformedDimensions() {\n return this.exactBoundingBox\n ? // TODO: fix this\n new Point(this.width, this.height)\n : super._getNonTransformedDimensions();\n }\n\n /**\n * @override stroke and skewing are taken into account when projecting stroke on points,\n * therefore we don't want the default calculation to account for skewing as well.\n * Though it is possible to pass `width` and `height` in `options`, doing so is very strange, use with discretion.\n *\n * @private\n */\n _getTransformedDimensions(options: any = {}) {\n if (this.exactBoundingBox) {\n let size: Point;\n /* When `strokeUniform = true`, any changes to the properties require recalculating the `width` and `height` because\n the stroke projections are affected.\n When `strokeUniform = false`, we don't need to recalculate for scale transformations, as the effect of scale on\n projections follows a linear function (e.g. scaleX of 2 just multiply width by 2)*/\n if (\n Object.keys(options).some(\n (key) =>\n this.strokeUniform ||\n (this.constructor as typeof Polyline).layoutProperties.includes(\n key as keyof TProjectStrokeOnPointsOptions\n )\n )\n ) {\n const { width, height } = this._calcDimensions(options);\n size = new Point(options.width ?? width, options.height ?? height);\n } else {\n size = new Point(\n options.width ?? this.width,\n options.height ?? this.height\n );\n }\n return size.multiply(\n new Point(options.scaleX || this.scaleX, options.scaleY || this.scaleY)\n );\n } else {\n return super._getTransformedDimensions(options);\n }\n }\n\n /**\n * Recalculates dimensions when changing skew and scale\n * @private\n */\n _set(key: string, value: any) {\n const changed = this.initialized && this[key as keyof this] !== value;\n const output = super._set(key, value);\n if (\n this.exactBoundingBox &&\n changed &&\n (((key === 'scaleX' || key === 'scaleY') &&\n this.strokeUniform &&\n (this.constructor as typeof Polyline).layoutProperties.includes(\n 'strokeUniform'\n )) ||\n (this.constructor as typeof Polyline).layoutProperties.includes(\n key as keyof Polyline\n ))\n ) {\n this.setDimensions();\n }\n return output;\n }\n\n /**\n * Returns object representation of an instance\n * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output\n * @return {Object} Object representation of an instance\n */\n toObject<\n T extends Omit<Props & TClassProperties<this>, keyof SProps>,\n K extends keyof T = never\n >(propertiesToInclude: K[] = []): Pick<T, K> & SProps {\n return {\n ...super.toObject(propertiesToInclude),\n points: cloneDeep(this.points),\n };\n }\n\n /**\n * Returns svg representation of an instance\n * @return {Array} an array of strings with the specific svg representation\n * of the instance\n */\n _toSVG() {\n const points = [],\n diffX = this.pathOffset.x,\n diffY = this.pathOffset.y,\n NUM_FRACTION_DIGITS = config.NUM_FRACTION_DIGITS;\n\n for (let i = 0, len = this.points.length; i < len; i++) {\n points.push(\n toFixed(this.points[i].x - diffX, NUM_FRACTION_DIGITS),\n ',',\n toFixed(this.points[i].y - diffY, NUM_FRACTION_DIGITS),\n ' '\n );\n }\n return [\n `<${\n (this.constructor as typeof Polyline).type.toLowerCase() as\n | 'polyline'\n | 'polygon'\n } `,\n 'COMMON_PARTS',\n `points=\"${points.join('')}\" />\\n`,\n ];\n }\n\n /**\n * @private\n * @param {CanvasRenderingContext2D} ctx Context to render on\n */\n _render(ctx: CanvasRenderingContext2D) {\n const len = this.points.length,\n x = this.pathOffset.x,\n y = this.pathOffset.y;\n\n if (!len || isNaN(this.points[len - 1].y)) {\n // do not draw if no points or odd points\n // NaN comes from parseFloat of a empty string in parser\n return;\n }\n ctx.beginPath();\n ctx.moveTo(this.points[0].x - x, this.points[0].y - y);\n for (let i = 0; i < len; i++) {\n const point = this.points[i];\n ctx.lineTo(point.x - x, point.y - y);\n }\n !this.isOpen() && ctx.closePath();\n this._renderPaintInOrder(ctx);\n }\n\n /**\n * Returns complexity of an instance\n * @return {Number} complexity of this instance\n */\n complexity(): number {\n return this.points.length;\n }\n\n /* _FROM_SVG_START_ */\n\n /**\n * List of attribute names to account for when parsing SVG element (used by {@link Polyline.fromElement})\n * @static\n * @memberOf Polyline\n * @see: http://www.w3.org/TR/SVG/shapes.html#PolylineElement\n */\n static ATTRIBUTE_NAMES = [...SHARED_ATTRIBUTES];\n\n /**\n * Returns Polyline instance from an SVG element\n * @static\n * @memberOf Polyline\n * @param {HTMLElement} element Element to parser\n * @param {Object} [options] Options object\n */\n static async fromElement(\n element: HTMLElement,\n options: Abortable,\n cssRules?: CSSRules\n ) {\n const points = parsePointsAttribute(element.getAttribute('points')),\n // we omit left and top to instruct the constructor to position the object using the bbox\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n { left, top, ...parsedAttributes } = parseAttributes(\n element,\n this.ATTRIBUTE_NAMES,\n cssRules\n );\n return new this(points, {\n ...parsedAttributes,\n ...options,\n });\n }\n\n /* _FROM_SVG_END_ */\n\n /**\n * Returns Polyline instance from an object representation\n * @static\n * @memberOf Polyline\n * @param {Object} object Object to create an instance from\n * @returns {Promise<Polyline>}\n */\n static fromObject<T extends TOptions<SerializedPolylineProps>>(object: T) {\n return this._fromObject<Polyline>(object, {\n extraParam: 'points',\n });\n }\n}\n\nclassRegistry.setClass(Polyline);\nclassRegistry.setSVGClass(Polyline);\n"],"names":["polylineDefaultValues","exactBoundingBox","Polyline","FabricObject","getDefaults","_objectSpread","ownDefaults","constructor","points","arguments","length","undefined","options","_defineProperty","Object","assign","setOptions","left","top","initialized","setBoundingBox","set","LEFT","TOP","isOpen","_projectStrokeOnPoints","projectStrokeOnPoints","_calcDimensions","scaleX","scaleY","skewX","skewY","strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeUniform","strokeWidth","map","projection","projectedPoint","width","height","pathOffset","Point","strokeOffset","strokeDiff","bbox","makeBoundingBoxFromPoints","matrix","calcDimensionsMatrix","bboxNoStroke","p","transformPoint","scale","offsetX","offsetY","Math","tan","degreesToRadians","subtract","multiply","_findCenterFromElement","setDimensions","adjustPosition","setPositionByOrigin","CENTER","isStrokeAccountedForInDimensions","_getNonTransformedDimensions","_getTransformedDimensions","size","keys","some","key","layoutProperties","includes","_options$width","_options$height","_options$width2","_options$height2","_set","value","changed","output","toObject","propertiesToInclude","cloneDeep","_toSVG","diffX","x","diffY","y","NUM_FRACTION_DIGITS","config","i","len","push","toFixed","concat","type","toLowerCase","join","_render","ctx","isNaN","beginPath","moveTo","point","lineTo","closePath","_renderPaintInOrder","complexity","fromElement","element","cssRules","parsePointsAttribute","getAttribute","_parseAttributes","parseAttributes","ATTRIBUTE_NAMES","parsedAttributes","_objectWithoutProperties","_excluded","fromObject","object","_fromObject","extraParam","cacheProperties","SHARED_ATTRIBUTES","classRegistry","setClass","setSVGClass"],"mappings":";;;;;;;;;;;;;;;;;;AAqBO,MAAMA,qBAA0D,GAAG;AACxE;AACF;AACA;AACEC,EAAAA,gBAAgB,EAAE,KAAA;AACpB,EAAC;AAMM,MAAMC,QAAQ,SAIXC,YAAY,CAA2B;EAyB/C,OAAOC,WAAWA,GAAwB;AACxC,IAAA,OAAAC,cAAA,CAAAA,cAAA,CAAA,EAAA,EACK,KAAK,CAACD,WAAW,EAAE,CAAA,EACnBF,QAAQ,CAACI,WAAW,CAAA,CAAA;AAE3B,GAAA;;AAEA;AACF;AACA;AACA;;AAoBE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,WAAWA,GAAkD;AAAA,IAAA,IAAjDC,MAAY,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CA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,CAAA;AAAAjH,eAAA,CAvD5CX,QAAQ,EAAA,iBAAA,EA+VM,CAAC,GAAG6H,iBAAiB,CAAC,CAAA,CAAA;AA4CjDC,aAAa,CAACC,QAAQ,CAAC/H,QAAQ,CAAC,CAAA;AAChC8H,aAAa,CAACE,WAAW,CAAChI,QAAQ,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"Polyline.mjs","sources":["../../../src/shapes/Polyline.ts"],"sourcesContent":["import { config } from '../config';\nimport { SHARED_ATTRIBUTES } from '../parser/attributes';\nimport { parseAttributes } from '../parser/parseAttributes';\nimport { parsePointsAttribute } from '../parser/parsePointsAttribute';\nimport type { XY } from '../Point';\nimport { Point } from '../Point';\nimport type { Abortable, TClassProperties, TOptions } from '../typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { makeBoundingBoxFromPoints } from '../util/misc/boundingBoxFromPoints';\nimport { calcDimensionsMatrix, transformPoint } from '../util/misc/matrix';\nimport { projectStrokeOnPoints } from '../util/misc/projectStroke';\nimport type { TProjectStrokeOnPointsOptions } from '../util/misc/projectStroke/types';\nimport { degreesToRadians } from '../util/misc/radiansDegreesConversion';\nimport { toFixed } from '../util/misc/toFixed';\nimport { FabricObject, cacheProperties } from './Object/FabricObject';\nimport type { FabricObjectProps, SerializedObjectProps } from './Object/types';\nimport type { ObjectEvents } from '../EventTypeDefs';\nimport { cloneDeep } from '../util/internals/cloneDeep';\nimport {\n CENTER,\n LEFT,\n SCALE_X,\n SCALE_Y,\n SKEW_X,\n SKEW_Y,\n TOP,\n} from '../constants';\nimport type { CSSRules } from '../parser/typedefs';\n\nexport const polylineDefaultValues: Partial<TClassProperties<Polyline>> = {\n /**\n * @deprecated transient option soon to be removed in favor of a different design\n */\n exactBoundingBox: false,\n};\n\nexport interface SerializedPolylineProps extends SerializedObjectProps {\n points: XY[];\n}\n\nexport class Polyline<\n Props extends TOptions<FabricObjectProps> = Partial<FabricObjectProps>,\n SProps extends SerializedPolylineProps = SerializedPolylineProps,\n EventSpec extends ObjectEvents = ObjectEvents\n> extends FabricObject<Props, SProps, EventSpec> {\n /**\n * Points array\n * @type Array\n * @default\n */\n declare points: XY[];\n\n /**\n * WARNING: Feature in progress\n * Calculate the exact bounding box taking in account strokeWidth on acute angles\n * this will be turned to true by default on fabric 6.0\n * maybe will be left in as an optimization since calculations may be slow\n * @deprecated transient option soon to be removed in favor of a different design\n * @type Boolean\n * @default false\n */\n declare exactBoundingBox: boolean;\n\n private declare initialized: true | undefined;\n\n static ownDefaults = polylineDefaultValues;\n\n static type = 'Polyline';\n\n static getDefaults(): Record<string, any> {\n return {\n ...super.getDefaults(),\n ...Polyline.ownDefaults,\n };\n }\n\n /**\n * A list of properties that if changed trigger a recalculation of dimensions\n * @todo check if you really need to recalculate for all cases\n */\n static layoutProperties: (keyof Polyline)[] = [\n SKEW_X,\n SKEW_Y,\n 'strokeLineCap',\n 'strokeLineJoin',\n 'strokeMiterLimit',\n 'strokeWidth',\n 'strokeUniform',\n 'points',\n ];\n\n declare pathOffset: Point;\n\n declare strokeOffset: Point;\n\n static cacheProperties = [...cacheProperties, 'points'];\n\n strokeDiff: Point;\n\n /**\n * Constructor\n * @param {Array} points Array of points (where each point is an object with x and y)\n * @param {Object} [options] Options object\n * @return {Polyline} thisArg\n * @example\n * var poly = new Polyline([\n * { x: 10, y: 10 },\n * { x: 50, y: 30 },\n * { x: 40, y: 70 },\n * { x: 60, y: 50 },\n * { x: 100, y: 150 },\n * { x: 40, y: 100 }\n * ], {\n * stroke: 'red',\n * left: 100,\n * top: 100\n * });\n */\n constructor(points: XY[] = [], options: Props = {} as Props) {\n super();\n Object.assign(this, Polyline.ownDefaults);\n this.setOptions(options);\n this.points = points;\n const { left, top } = options;\n this.initialized = true;\n this.setBoundingBox(true);\n typeof left === 'number' && this.set(LEFT, left);\n typeof top === 'number' && this.set(TOP, top);\n }\n\n protected isOpen() {\n return true;\n }\n\n private _projectStrokeOnPoints(options: TProjectStrokeOnPointsOptions) {\n return projectStrokeOnPoints(this.points, options, this.isOpen());\n }\n\n /**\n * Calculate the polygon bounding box\n * @private\n */\n _calcDimensions(options?: Partial<TProjectStrokeOnPointsOptions>) {\n options = {\n scaleX: this.scaleX,\n scaleY: this.scaleY,\n skewX: this.skewX,\n skewY: this.skewY,\n strokeLineCap: this.strokeLineCap,\n strokeLineJoin: this.strokeLineJoin,\n strokeMiterLimit: this.strokeMiterLimit,\n strokeUniform: this.strokeUniform,\n strokeWidth: this.strokeWidth,\n ...(options || {}),\n };\n const points = this.exactBoundingBox\n ? this._projectStrokeOnPoints(\n options as TProjectStrokeOnPointsOptions\n ).map((projection) => projection.projectedPoint)\n : this.points;\n if (points.length === 0) {\n return {\n left: 0,\n top: 0,\n width: 0,\n height: 0,\n pathOffset: new Point(),\n strokeOffset: new Point(),\n strokeDiff: new Point(),\n };\n }\n const bbox = makeBoundingBoxFromPoints(points),\n // Remove scale effect, since it's applied after\n matrix = calcDimensionsMatrix({ ...options, scaleX: 1, scaleY: 1 }),\n bboxNoStroke = makeBoundingBoxFromPoints(\n this.points.map((p) => transformPoint(p, matrix, true))\n ),\n scale = new Point(this.scaleX, this.scaleY);\n let offsetX = bbox.left + bbox.width / 2,\n offsetY = bbox.top + bbox.height / 2;\n if (this.exactBoundingBox) {\n offsetX = offsetX - offsetY * Math.tan(degreesToRadians(this.skewX));\n // Order of those assignments is important.\n // offsetY relies on offsetX being already changed by the line above\n offsetY = offsetY - offsetX * Math.tan(degreesToRadians(this.skewY));\n }\n\n return {\n ...bbox,\n pathOffset: new Point(offsetX, offsetY),\n strokeOffset: new Point(bboxNoStroke.left, bboxNoStroke.top)\n .subtract(new Point(bbox.left, bbox.top))\n .multiply(scale),\n strokeDiff: new Point(bbox.width, bbox.height)\n .subtract(new Point(bboxNoStroke.width, bboxNoStroke.height))\n .multiply(scale),\n };\n }\n\n /**\n * This function is an helper for svg import. it returns the center of the object in the svg\n * untransformed coordinates, by look at the polyline/polygon points.\n * @private\n * @return {Point} center point from element coordinates\n */\n _findCenterFromElement(): Point {\n const bbox = makeBoundingBoxFromPoints(this.points);\n return new Point(bbox.left + bbox.width / 2, bbox.top + bbox.height / 2);\n }\n\n setDimensions() {\n this.setBoundingBox();\n }\n\n setBoundingBox(adjustPosition?: boolean) {\n const { left, top, width, height, pathOffset, strokeOffset, strokeDiff } =\n this._calcDimensions();\n this.set({ width, height, pathOffset, strokeOffset, strokeDiff });\n adjustPosition &&\n this.setPositionByOrigin(\n new Point(left + width / 2, top + height / 2),\n CENTER,\n CENTER\n );\n }\n\n /**\n * @deprecated intermidiate method to be removed, do not use\n */\n protected isStrokeAccountedForInDimensions() {\n return this.exactBoundingBox;\n }\n\n /**\n * @override stroke is taken in account in size\n */\n _getNonTransformedDimensions() {\n return this.exactBoundingBox\n ? // TODO: fix this\n new Point(this.width, this.height)\n : super._getNonTransformedDimensions();\n }\n\n /**\n * @override stroke and skewing are taken into account when projecting stroke on points,\n * therefore we don't want the default calculation to account for skewing as well.\n * Though it is possible to pass `width` and `height` in `options`, doing so is very strange, use with discretion.\n *\n * @private\n */\n _getTransformedDimensions(options: any = {}) {\n if (this.exactBoundingBox) {\n let size: Point;\n /* When `strokeUniform = true`, any changes to the properties require recalculating the `width` and `height` because\n the stroke projections are affected.\n When `strokeUniform = false`, we don't need to recalculate for scale transformations, as the effect of scale on\n projections follows a linear function (e.g. scaleX of 2 just multiply width by 2)*/\n if (\n Object.keys(options).some(\n (key) =>\n this.strokeUniform ||\n (this.constructor as typeof Polyline).layoutProperties.includes(\n key as keyof TProjectStrokeOnPointsOptions\n )\n )\n ) {\n const { width, height } = this._calcDimensions(options);\n size = new Point(options.width ?? width, options.height ?? height);\n } else {\n size = new Point(\n options.width ?? this.width,\n options.height ?? this.height\n );\n }\n return size.multiply(\n new Point(options.scaleX || this.scaleX, options.scaleY || this.scaleY)\n );\n } else {\n return super._getTransformedDimensions(options);\n }\n }\n\n /**\n * Recalculates dimensions when changing skew and scale\n * @private\n */\n _set(key: string, value: any) {\n const changed = this.initialized && this[key as keyof this] !== value;\n const output = super._set(key, value);\n if (\n this.exactBoundingBox &&\n changed &&\n (((key === SCALE_X || key === SCALE_Y) &&\n this.strokeUniform &&\n (this.constructor as typeof Polyline).layoutProperties.includes(\n 'strokeUniform'\n )) ||\n (this.constructor as typeof Polyline).layoutProperties.includes(\n key as keyof Polyline\n ))\n ) {\n this.setDimensions();\n }\n return output;\n }\n\n /**\n * Returns object representation of an instance\n * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output\n * @return {Object} Object representation of an instance\n */\n toObject<\n T extends Omit<Props & TClassProperties<this>, keyof SProps>,\n K extends keyof T = never\n >(propertiesToInclude: K[] = []): Pick<T, K> & SProps {\n return {\n ...super.toObject(propertiesToInclude),\n points: cloneDeep(this.points),\n };\n }\n\n /**\n * Returns svg representation of an instance\n * @return {Array} an array of strings with the specific svg representation\n * of the instance\n */\n _toSVG() {\n const points = [],\n diffX = this.pathOffset.x,\n diffY = this.pathOffset.y,\n NUM_FRACTION_DIGITS = config.NUM_FRACTION_DIGITS;\n\n for (let i = 0, len = this.points.length; i < len; i++) {\n points.push(\n toFixed(this.points[i].x - diffX, NUM_FRACTION_DIGITS),\n ',',\n toFixed(this.points[i].y - diffY, NUM_FRACTION_DIGITS),\n ' '\n );\n }\n return [\n `<${\n (this.constructor as typeof Polyline).type.toLowerCase() as\n | 'polyline'\n | 'polygon'\n } `,\n 'COMMON_PARTS',\n `points=\"${points.join('')}\" />\\n`,\n ];\n }\n\n /**\n * @private\n * @param {CanvasRenderingContext2D} ctx Context to render on\n */\n _render(ctx: CanvasRenderingContext2D) {\n const len = this.points.length,\n x = this.pathOffset.x,\n y = this.pathOffset.y;\n\n if (!len || isNaN(this.points[len - 1].y)) {\n // do not draw if no points or odd points\n // NaN comes from parseFloat of a empty string in parser\n return;\n }\n ctx.beginPath();\n ctx.moveTo(this.points[0].x - x, this.points[0].y - y);\n for (let i = 0; i < len; i++) {\n const point = this.points[i];\n ctx.lineTo(point.x - x, point.y - y);\n }\n !this.isOpen() && ctx.closePath();\n this._renderPaintInOrder(ctx);\n }\n\n /**\n * Returns complexity of an instance\n * @return {Number} complexity of this instance\n */\n complexity(): number {\n return this.points.length;\n }\n\n /* _FROM_SVG_START_ */\n\n /**\n * List of attribute names to account for when parsing SVG element (used by {@link Polyline.fromElement})\n * @static\n * @memberOf Polyline\n * @see: http://www.w3.org/TR/SVG/shapes.html#PolylineElement\n */\n static ATTRIBUTE_NAMES = [...SHARED_ATTRIBUTES];\n\n /**\n * Returns Polyline instance from an SVG element\n * @static\n * @memberOf Polyline\n * @param {HTMLElement} element Element to parser\n * @param {Object} [options] Options object\n */\n static async fromElement(\n element: HTMLElement,\n options: Abortable,\n cssRules?: CSSRules\n ) {\n const points = parsePointsAttribute(element.getAttribute('points')),\n // we omit left and top to instruct the constructor to position the object using the bbox\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n { left, top, ...parsedAttributes } = parseAttributes(\n element,\n this.ATTRIBUTE_NAMES,\n cssRules\n );\n return new this(points, {\n ...parsedAttributes,\n ...options,\n });\n }\n\n /* _FROM_SVG_END_ */\n\n /**\n * Returns Polyline instance from an object representation\n * @static\n * @memberOf Polyline\n * @param {Object} object Object to create an instance from\n * @returns {Promise<Polyline>}\n */\n static fromObject<T extends TOptions<SerializedPolylineProps>>(object: T) {\n return this._fromObject<Polyline>(object, {\n extraParam: 'points',\n });\n }\n}\n\nclassRegistry.setClass(Polyline);\nclassRegistry.setSVGClass(Polyline);\n"],"names":["polylineDefaultValues","exactBoundingBox","Polyline","FabricObject","getDefaults","_objectSpread","ownDefaults","constructor","points","arguments","length","undefined","options","_defineProperty","Object","assign","setOptions","left","top","initialized","setBoundingBox","set","LEFT","TOP","isOpen","_projectStrokeOnPoints","projectStrokeOnPoints","_calcDimensions","scaleX","scaleY","skewX","skewY","strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeUniform","strokeWidth","map","projection","projectedPoint","width","height","pathOffset","Point","strokeOffset","strokeDiff","bbox","makeBoundingBoxFromPoints","matrix","calcDimensionsMatrix","bboxNoStroke","p","transformPoint","scale","offsetX","offsetY","Math","tan","degreesToRadians","subtract","multiply","_findCenterFromElement","setDimensions","adjustPosition","setPositionByOrigin","CENTER","isStrokeAccountedForInDimensions","_getNonTransformedDimensions","_getTransformedDimensions","size","keys","some","key","layoutProperties","includes","_options$width","_options$height","_options$width2","_options$height2","_set","value","changed","output","SCALE_X","SCALE_Y","toObject","propertiesToInclude","cloneDeep","_toSVG","diffX","x","diffY","y","NUM_FRACTION_DIGITS","config","i","len","push","toFixed","concat","type","toLowerCase","join","_render","ctx","isNaN","beginPath","moveTo","point","lineTo","closePath","_renderPaintInOrder","complexity","fromElement","element","cssRules","parsePointsAttribute","getAttribute","_parseAttributes","parseAttributes","ATTRIBUTE_NAMES","parsedAttributes","_objectWithoutProperties","_excluded","fromObject","object","_fromObject","extraParam","SKEW_X","SKEW_Y","cacheProperties","SHARED_ATTRIBUTES","classRegistry","setClass","setSVGClass"],"mappings":";;;;;;;;;;;;;;;;;;AA6BO,MAAMA,qBAA0D,GAAG;AACxE;AACF;AACA;AACEC,EAAAA,gBAAgB,EAAE,KAAA;AACpB,EAAC;AAMM,MAAMC,QAAQ,SAIXC,YAAY,CAA2B;EAyB/C,OAAOC,WAAWA,GAAwB;AACxC,IAAA,OAAAC,cAAA,CAAAA,cAAA,CAAA,EAAA,EACK,KAAK,CAACD,WAAW,EAAE,CAAA,EACnBF,QAAQ,CAACI,WAAW,CAAA,CAAA;AAE3B,GAAA;;AAEA;AACF;AACA;AACA;;AAoBE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,WAAWA,GAAkD;AAAA,IAAA,IAAjDC,MAAY,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,EAAE,CAAA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AAiB,CAAC,CAAA,CAAA;AA4CjDC,aAAa,CAACC,QAAQ,CAACnI,QAAQ,CAAC,CAAA;AAChCkI,aAAa,CAACE,WAAW,CAACpI,QAAQ,CAAC;;;;"}
|
|
@@ -34,7 +34,7 @@ interface UniqueTextProps {
|
|
|
34
34
|
charSpacing: number;
|
|
35
35
|
lineHeight: number;
|
|
36
36
|
fontSize: number;
|
|
37
|
-
fontWeight: string;
|
|
37
|
+
fontWeight: string | number;
|
|
38
38
|
fontFamily: string;
|
|
39
39
|
fontStyle: string;
|
|
40
40
|
pathSide: TPathSide;
|
|
@@ -97,7 +97,7 @@ export declare class FabricText<Props extends TOptions<TextProps> = Partial<Text
|
|
|
97
97
|
* @type {(Number|String)}
|
|
98
98
|
* @default
|
|
99
99
|
*/
|
|
100
|
-
fontWeight: string;
|
|
100
|
+
fontWeight: string | number;
|
|
101
101
|
/**
|
|
102
102
|
* Font family
|
|
103
103
|
* @type String
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../../../../src/shapes/Text/Text.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,4BAA4B,EAC5B,SAAS,EACT,oBAAoB,EACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,KAAK,EACV,SAAS,EACT,sBAAsB,EACtB,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACT,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAQjE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAGpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;A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AAC,CAAC,GAAG,MAAM;IAQrD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG;IA2BlC;;;OAGG;IACH,UAAU,IAAI,MAAM;IAIpB,MAAM,CAAC,YAAY,WAMjB;IAIF;;;;;OAKG;IACH,MAAM,CAAC,eAAe,WAYpB;IAEF;;;;;;OAMG;WACU,WAAW,CACtB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,SAAS,EAClB,QAAQ,CAAC,EAAE,QAAQ;;;;;;;;;;IAqErB;;;;OAIG;IACH,MAAM,CAAC,UAAU,CACf,CAAC,SAAS,QAAQ,CAAC,mBAAmB,CAAC,EACvC,CAAC,SAAS,UAAU,EACpB,MAAM,EAAE,CAAC;CAWZ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{defineProperty as t,objectSpread2 as e,objectWithoutProperties as i}from"../../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{cache as s}from"../../cache.min.mjs";import{BOTTOM as n,TOP as h,CENTER as r,RIGHT as o,LEFT as l,DEFAULT_SVG_FONT_SIZE as a}from"../../constants.min.mjs";import{StyledText as d}from"./StyledText.min.mjs";import{SHARED_ATTRIBUTES as f}from"../../parser/attributes.min.mjs";import{parseAttributes as c}from"../../parser/parseAttributes.min.mjs";import{classRegistry as g}from"../../ClassRegistry.min.mjs";import{graphemeSplit as p}from"../../util/lang_string.min.mjs";import{createCanvasElement as _}from"../../util/misc/dom.min.mjs";import{hasStyleChanged as m,stylesToArray as u,stylesFromArray as x}from"../../util/misc/textStyles.min.mjs";import{getPathSegmentsInfo as S,getPointOnPath as y}from"../../util/path/index.min.mjs";import"../Object/FabricObject.min.mjs";import{TextSVGExportMixin as T}from"./TextSVGExportMixin.min.mjs";import{applyMixins as L}from"../../util/applyMixins.min.mjs";import{JUSTIFY as O,JUSTIFY_CENTER as w,JUSTIFY_RIGHT as C,JUSTIFY_LEFT as k,additionalProps as W,textLayoutProperties as v,textDefaultValues as H}from"./constants.min.mjs";import{isFiller as A}from"../../util/typeAssertions.min.mjs";import{cacheProperties as D}from"../Object/defaultValues.min.mjs";const P=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let b;class j extends d{static getDefaults(){return e(e({},super.getDefaults()),j.ownDefaults)}constructor(e,i){super(),t(this,"__charBounds",[]),Object.assign(this,j.ownDefaults),this.setOptions(i),this.styles||(this.styles={}),this.text=e,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=S(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(O)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,i,s,n,h,r;for(let o=0,l=this._textLines.length;o<l;o++)if((this.textAlign===O||o!==l-1&&!this.isEndOfWrapping(o))&&(s=0,n=this._textLines[o],e=this.getLineWidth(o),e<this.width&&(r=this.textLines[o].match(this._reSpacesAndTabs)))){i=r.length,t=(this.width-e)/i;for(let e=0;e<=n.length;e++)h=this.__charBounds[o][e],this._reSpaceAndTab.test(n[e])?(h.width+=t,h.kernedWidth+=t,h.left+=s,s+=t):h.left+=s}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const i=e?this._unwrappedTextLines:this._textLines;let s;for(s=0;s<i.length;s++){if(t<=i[s].length)return{lineIndex:s,charIndex:t};t-=i[s].length+this.missingNewlineOffset(s,e)}return{lineIndex:s-1,charIndex:i[s-1].length<t?i[s-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){"stroke"===this.paintFirst?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,i){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case r:t.textBaseline="middle";break;case"ascender":t.textBaseline=h;break;case"descender":t.textBaseline=n}t.font=this._getFontDeclaration(e,i)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,i=this._textLines.length;e<i;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,i,s,n,h){this._renderChars(t,e,i,s,n,h)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,i=this._getLeftOffset();let s=this._getTopOffset();for(let e=0,n=this._textLines.length;e<n;e++){const n=this.getHeightOfLine(e);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",e)){s+=n;continue}const h=this._textLines[e].length,r=this._getLineLeftOffset(e);let o,l,a=0,d=0,f=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let c=0;c<h;c++){const h=this.__charBounds[e][c];l=this.getValueOfPropertyAt(e,c,"textBackgroundColor"),this.path?(t.save(),t.translate(h.renderLeft,h.renderTop),t.rotate(h.angle),t.fillStyle=l,l&&t.fillRect(-h.width/2,-n/this.lineHeight*(1-this._fontSizeFraction),h.width,n/this.lineHeight),t.restore()):l!==f?(o=i+r+d,"rtl"===this.direction&&(o=this.width-o-a),t.fillStyle=f,f&&t.fillRect(o,s,a,n/this.lineHeight),d=h.left,a=h.width,f=l):a+=h.kernedWidth}l&&!this.path&&(o=i+r+d,"rtl"===this.direction&&(o=this.width-o-a),t.fillStyle=l,t.fillRect(o,s,a,n/this.lineHeight)),s+=n}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,i,n){const h=s.getFontCache(e),r=this._getFontDeclaration(e),o=i+t,l=i&&r===this._getFontDeclaration(n),a=e.fontSize/this.CACHE_FONT_SIZE;let d,f,c,g;if(i&&void 0!==h[i]&&(c=h[i]),void 0!==h[t]&&(g=d=h[t]),l&&void 0!==h[o]&&(f=h[o],g=f-c),void 0===d||void 0===c||void 0===f){const s=function(){if(!b){const t=_();t.width=t.height=0,b=t.getContext("2d")}return b}();this._setTextStyles(s,e,!0),void 0===d&&(g=d=s.measureText(t).width,h[t]=d),void 0===c&&l&&i&&(c=s.measureText(i).width,h[i]=c),l&&void 0===f&&(f=s.measureText(o).width,h[o]=f,g=f-c)}return{width:d*a,kernedWidth:g*a}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return 0!==this.charSpacing&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,i,s=0;const n=this.pathSide===o,h=this.path,a=this._textLines[t],d=a.length,f=new Array(d);this.__charBounds[t]=f;for(let n=0;n<d;n++){const h=a[n];i=this._getGraphemeBox(h,t,n,e),f[n]=i,s+=i.kernedWidth,e=h}if(f[d]={left:i?i.left+i.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},h&&h.segmentsInfo){let t=0;const e=h.segmentsInfo[h.segmentsInfo.length-1].length;switch(this.textAlign){case l:t=n?e-s:0;break;case r:t=(e-s)/2;break;case o:t=n?0:e-s}t+=this.pathStartOffset*(n?-1:1);for(let s=n?d-1:0;n?s>=0:s<d;n?s--:s++)i=f[s],t>e?t%=e:t<0&&(t+=e),this._setGraphemeOnPath(t,i),t+=i.kernedWidth}return{width:s,numOfSpaces:0}}_setGraphemeOnPath(t,e){const i=t+e.kernedWidth/2,s=this.path,n=y(s.path,i,s.segmentsInfo);e.renderLeft=n.x-s.pathOffset.x,e.renderTop=n.y-s.pathOffset.y,e.angle=n.angle+(this.pathSide===o?Math.PI:0)}_getGraphemeBox(t,e,i,s,n){const h=this.getCompleteStyleDeclaration(e,i),r=s?this.getCompleteStyleDeclaration(e,i-1):{},o=this._measureChar(t,h,s,r);let l,a=o.kernedWidth,d=o.width;0!==this.charSpacing&&(l=this._getWidthOfCharSpacing(),d+=l,a+=l);const f={width:d,left:0,height:h.fontSize,kernedWidth:a,deltaY:h.deltaY};if(i>0&&!n){const t=this.__charBounds[e][i-1];f.left=t.left+t.width+o.kernedWidth-o.width}return f}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let i=1,s=this._textLines[t].length;i<s;i++)e=Math.max(this.getHeightOfChar(t,i),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let i=0,s=this._textLines.length;i<s;i++)t=this.getHeightOfLine(i),e+=i===s-1?t/this.lineHeight:t;return e}_getLeftOffset(){return"ltr"===this.direction?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let i=0;const s=this._getLeftOffset(),n=this._getTopOffset();for(let h=0,r=this._textLines.length;h<r;h++){const r=this.getHeightOfLine(h),o=r/this.lineHeight,l=this._getLineLeftOffset(h);this._renderTextLine(e,t,this._textLines[h],s+l,n+i+o,h),i+=r}t.restore()}_renderTextFill(t){(this.fill||this.styleHas("fill"))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&0!==this.strokeWidth||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,i,s,n,h){const r=this.getHeightOfLine(h),a=this.textAlign.includes(O),d=this.path,f=!a&&0===this.charSpacing&&this.isEmptyStyles(h)&&!d,c="ltr"===this.direction,g="ltr"===this.direction?1:-1,p=e.direction;let _,u,x,S,y,T="",L=0;if(e.save(),p!==this.direction&&(e.canvas.setAttribute("dir",c?"ltr":"rtl"),e.direction=c?"ltr":"rtl",e.textAlign=c?l:o),n-=r*this._fontSizeFraction/this.lineHeight,f)return this._renderChar(t,e,h,0,i.join(""),s,n),void e.restore();for(let r=0,o=i.length-1;r<=o;r++)S=r===o||this.charSpacing||d,T+=i[r],x=this.__charBounds[h][r],0===L?(s+=g*(x.kernedWidth-x.width),L+=x.width):L+=x.kernedWidth,a&&!S&&this._reSpaceAndTab.test(i[r])&&(S=!0),S||(_=_||this.getCompleteStyleDeclaration(h,r),u=this.getCompleteStyleDeclaration(h,r+1),S=m(_,u,!1)),S&&(d?(e.save(),e.translate(x.renderLeft,x.renderTop),e.rotate(x.angle),this._renderChar(t,e,h,r,T,-L/2,0),e.restore()):(y=s,this._renderChar(t,e,h,r,T,y,n)),T="",_=u,s+=g*L,L=0);e.restore()}_applyPatternGradientTransformText(t){const e=_(),i=this.width+this.strokeWidth,s=this.height+this.strokeWidth,n=e.getContext("2d");return e.width=i,e.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(i,0),n.lineTo(i,s),n.lineTo(0,s),n.closePath(),n.translate(i/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(e,"no-repeat")}handleFiller(t,e,i){let s,n;return A(i)?"percentage"===i.gradientUnits||i.gradientTransform||i.patternTransform?(s=-this.width/2,n=-this.height/2,t.translate(s,n),t[e]=this._applyPatternGradientTransformText(i),{offsetX:s,offsetY:n}):(t[e]=i.toLive(t),this._applyPatternGradientTransform(t,i)):(t[e]=i,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:i,strokeWidth:s}=e;return t.lineWidth=s,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",i)}_setFillStyles(t,e){let{fill:i}=e;return this.handleFiller(t,"fillStyle",i)}_renderChar(t,e,i,s,n,h,r){const o=this._getStyleDeclaration(i,s),l=this.getCompleteStyleDeclaration(i,s),a="fillText"===t&&l.fill,d="strokeText"===t&&l.stroke&&l.strokeWidth;if(d||a){if(e.save(),e.font=this._getFontDeclaration(l),o.textBackgroundColor&&this._removeShadow(e),o.deltaY&&(r+=o.deltaY),a){const t=this._setFillStyles(e,l);e.fillText(n,h-t.offsetX,r-t.offsetY)}if(d){const t=this._setStrokeStyles(e,l);e.strokeText(n,h-t.offsetX,r-t.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,i){const s=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(s.lineIndex,s.charIndex,"fontSize"),h=this.getValueOfPropertyAt(s.lineIndex,s.charIndex,"deltaY"),r={fontSize:n*i.size,deltaY:h+n*i.baseline};this.setSelectionStyles(r,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),i=this.width-e,s=this.textAlign,n=this.direction,h=this.isEndOfWrapping(t);let a=0;return s===O||s===w&&!h||s===C&&!h||s===k&&!h?0:(s===r&&(a=i/2),s===o&&(a=i),s===w&&(a=i/2),s===C&&(a=i),"rtl"===n&&(s===o||s===O||s===C?a=0:s===l||s===k?a=-i:s!==r&&s!==w||(a=-i/2)),a)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(void 0!==this.__lineWidths[t])return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return 0!==this.charSpacing?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,i){var s;return null!==(s=this._getStyleDeclaration(t,e)[i])&&void 0!==s?s:this[i]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let i=this._getTopOffset();const s=this._getLeftOffset(),n=this.path,h=this._getWidthOfCharSpacing(),r=this.offsets[e];for(let o=0,l=this._textLines.length;o<l;o++){const l=this.getHeightOfLine(o);if(!this[e]&&!this.styleHas(e,o)){i+=l;continue}const a=this._textLines[o],d=l/this.lineHeight,f=this._getLineLeftOffset(o);let c,g,p=0,_=0,m=this.getValueOfPropertyAt(o,0,e),u=this.getValueOfPropertyAt(o,0,"fill");const x=i+d*(1-this._fontSizeFraction);let S=this.getHeightOfChar(o,0),y=this.getValueOfPropertyAt(o,0,"deltaY");for(let i=0,h=a.length;i<h;i++){const h=this.__charBounds[o][i];c=this.getValueOfPropertyAt(o,i,e),g=this.getValueOfPropertyAt(o,i,"fill");const l=this.getHeightOfChar(o,i),a=this.getValueOfPropertyAt(o,i,"deltaY");if(n&&c&&g)t.save(),t.fillStyle=u,t.translate(h.renderLeft,h.renderTop),t.rotate(h.angle),t.fillRect(-h.kernedWidth/2,r*l+a,h.kernedWidth,this.fontSize/15),t.restore();else if((c!==m||g!==u||l!==S||a!==y)&&_>0){let e=s+f+p;"rtl"===this.direction&&(e=this.width-e-_),m&&u&&(t.fillStyle=u,t.fillRect(e,x+r*S+y,_,this.fontSize/15)),p=h.left,_=h.width,m=c,u=g,S=l,y=a}else _+=h.kernedWidth}let T=s+f+p;"rtl"===this.direction&&(T=this.width-T-_),t.fillStyle=g,c&&g&&t.fillRect(T,x+r*S+y,_-h,this.fontSize/15),i+=l}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:i=this.fontWeight,fontSize:s=this.fontSize}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const h=t.includes("'")||t.includes('"')||t.includes(",")||j.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,i,"".concat(n?this.CACHE_FONT_SIZE:s,"px"),h].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return p(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),i=new Array(e.length),s=["\n"];let n=[];for(let t=0;t<e.length;t++)i[t]=this.graphemeSplit(e[t]),n=n.concat(i[t],s);return n.pop(),{_unwrappedLines:i,lines:e,graphemeText:n,graphemeLines:i}}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return e(e({},super.toObject([...W,...t])),{},{styles:u(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:i}=this.constructor;super.set(t,e);let s=!1,n=!1;if("object"==typeof t)for(const e in t)"path"===e&&this.setPathInfo(),s=s||i.includes(e),n=n||"path"===e;else s=i.includes(t),n="path"===t;return n&&this.setPathInfo(),s&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,s,n){const h=c(t,j.ATTRIBUTE_NAMES,n),d=e(e({},s),h),{textAnchor:f=l,textDecoration:g="",dx:p=0,dy:_=0,top:m=0,left:u=0,fontSize:x=a,strokeWidth:S=1}=d,y=i(d,P),T=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),e({left:u+p,top:m+_,underline:g.includes("underline"),overline:g.includes("overline"),linethrough:g.includes("line-through"),strokeWidth:0,fontSize:x},y)),L=T.getScaledHeight()/T.height,O=((T.height+T.strokeWidth)*T.lineHeight-T.height)*L,w=T.getScaledHeight()+O;let C=0;return f===r&&(C=T.getScaledWidth()/2),f===o&&(C=T.getScaledWidth()),T.set({left:T.left-C,top:T.top-(w-T.fontSize*(.07+T._fontSizeFraction))/T.lineHeight,strokeWidth:S}),T}static fromObject(t){return this._fromObject(e(e({},t),{},{styles:x(t.styles||{},t.text)}),{extraParam:"text"})}}t(j,"textLayoutProperties",v),t(j,"cacheProperties",[...D,...W]),t(j,"ownDefaults",H),t(j,"type","Text"),t(j,"genericFonts",["sans-serif","serif","cursive","fantasy","monospace"]),t(j,"ATTRIBUTE_NAMES",f.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),L(j,[T]),g.setClass(j),g.setSVGClass(j);export{j as FabricText};
|
|
1
|
+
import{defineProperty as t,objectSpread2 as e,objectWithoutProperties as i}from"../../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{cache as s}from"../../cache.min.mjs";import{STROKE as n,BOTTOM as h,TOP as r,CENTER as o,RIGHT as l,FILL as a,LEFT as d,DEFAULT_SVG_FONT_SIZE as f}from"../../constants.min.mjs";import{StyledText as c}from"./StyledText.min.mjs";import{SHARED_ATTRIBUTES as g}from"../../parser/attributes.min.mjs";import{parseAttributes as p}from"../../parser/parseAttributes.min.mjs";import{classRegistry as _}from"../../ClassRegistry.min.mjs";import{graphemeSplit as m}from"../../util/lang_string.min.mjs";import{createCanvasElement as u}from"../../util/misc/dom.min.mjs";import{hasStyleChanged as x,stylesToArray as S,stylesFromArray as y}from"../../util/misc/textStyles.min.mjs";import{getPathSegmentsInfo as T,getPointOnPath as L}from"../../util/path/index.min.mjs";import"../Object/FabricObject.min.mjs";import{TextSVGExportMixin as O}from"./TextSVGExportMixin.min.mjs";import{applyMixins as w}from"../../util/applyMixins.min.mjs";import{JUSTIFY as C,JUSTIFY_CENTER as k,JUSTIFY_RIGHT as W,JUSTIFY_LEFT as v,additionalProps as H,textLayoutProperties as A,textDefaultValues as D}from"./constants.min.mjs";import{isFiller as P}from"../../util/typeAssertions.min.mjs";import{cacheProperties as b}from"../Object/defaultValues.min.mjs";const j=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let z;class F extends c{static getDefaults(){return e(e({},super.getDefaults()),F.ownDefaults)}constructor(e,i){super(),t(this,"__charBounds",[]),Object.assign(this,F.ownDefaults),this.setOptions(i),this.styles||(this.styles={}),this.text=e,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=T(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(C)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,i,s,n,h,r;for(let o=0,l=this._textLines.length;o<l;o++)if((this.textAlign===C||o!==l-1&&!this.isEndOfWrapping(o))&&(s=0,n=this._textLines[o],e=this.getLineWidth(o),e<this.width&&(r=this.textLines[o].match(this._reSpacesAndTabs)))){i=r.length,t=(this.width-e)/i;for(let e=0;e<=n.length;e++)h=this.__charBounds[o][e],this._reSpaceAndTab.test(n[e])?(h.width+=t,h.kernedWidth+=t,h.left+=s,s+=t):h.left+=s}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const i=e?this._unwrappedTextLines:this._textLines;let s;for(s=0;s<i.length;s++){if(t<=i[s].length)return{lineIndex:s,charIndex:t};t-=i[s].length+this.missingNewlineOffset(s,e)}return{lineIndex:s-1,charIndex:i[s-1].length<t?i[s-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===n?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,i){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case o:t.textBaseline="middle";break;case"ascender":t.textBaseline=r;break;case"descender":t.textBaseline=h}t.font=this._getFontDeclaration(e,i)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,i=this._textLines.length;e<i;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,i,s,n,h){this._renderChars(t,e,i,s,n,h)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,i=this._getLeftOffset();let s=this._getTopOffset();for(let e=0,n=this._textLines.length;e<n;e++){const n=this.getHeightOfLine(e);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",e)){s+=n;continue}const h=this._textLines[e].length,r=this._getLineLeftOffset(e);let o,l,a=0,d=0,f=this.getValueOfPropertyAt(e,0,"textBackgroundColor");for(let c=0;c<h;c++){const h=this.__charBounds[e][c];l=this.getValueOfPropertyAt(e,c,"textBackgroundColor"),this.path?(t.save(),t.translate(h.renderLeft,h.renderTop),t.rotate(h.angle),t.fillStyle=l,l&&t.fillRect(-h.width/2,-n/this.lineHeight*(1-this._fontSizeFraction),h.width,n/this.lineHeight),t.restore()):l!==f?(o=i+r+d,"rtl"===this.direction&&(o=this.width-o-a),t.fillStyle=f,f&&t.fillRect(o,s,a,n/this.lineHeight),d=h.left,a=h.width,f=l):a+=h.kernedWidth}l&&!this.path&&(o=i+r+d,"rtl"===this.direction&&(o=this.width-o-a),t.fillStyle=l,t.fillRect(o,s,a,n/this.lineHeight)),s+=n}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,i,n){const h=s.getFontCache(e),r=this._getFontDeclaration(e),o=i+t,l=i&&r===this._getFontDeclaration(n),a=e.fontSize/this.CACHE_FONT_SIZE;let d,f,c,g;if(i&&void 0!==h[i]&&(c=h[i]),void 0!==h[t]&&(g=d=h[t]),l&&void 0!==h[o]&&(f=h[o],g=f-c),void 0===d||void 0===c||void 0===f){const s=function(){if(!z){const t=u();t.width=t.height=0,z=t.getContext("2d")}return z}();this._setTextStyles(s,e,!0),void 0===d&&(g=d=s.measureText(t).width,h[t]=d),void 0===c&&l&&i&&(c=s.measureText(i).width,h[i]=c),l&&void 0===f&&(f=s.measureText(o).width,h[o]=f,g=f-c)}return{width:d*a,kernedWidth:g*a}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return 0!==this.charSpacing&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,i,s=0;const n=this.pathSide===l,h=this.path,r=this._textLines[t],a=r.length,f=new Array(a);this.__charBounds[t]=f;for(let n=0;n<a;n++){const h=r[n];i=this._getGraphemeBox(h,t,n,e),f[n]=i,s+=i.kernedWidth,e=h}if(f[a]={left:i?i.left+i.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},h&&h.segmentsInfo){let t=0;const e=h.segmentsInfo[h.segmentsInfo.length-1].length;switch(this.textAlign){case d:t=n?e-s:0;break;case o:t=(e-s)/2;break;case l:t=n?0:e-s}t+=this.pathStartOffset*(n?-1:1);for(let s=n?a-1:0;n?s>=0:s<a;n?s--:s++)i=f[s],t>e?t%=e:t<0&&(t+=e),this._setGraphemeOnPath(t,i),t+=i.kernedWidth}return{width:s,numOfSpaces:0}}_setGraphemeOnPath(t,e){const i=t+e.kernedWidth/2,s=this.path,n=L(s.path,i,s.segmentsInfo);e.renderLeft=n.x-s.pathOffset.x,e.renderTop=n.y-s.pathOffset.y,e.angle=n.angle+(this.pathSide===l?Math.PI:0)}_getGraphemeBox(t,e,i,s,n){const h=this.getCompleteStyleDeclaration(e,i),r=s?this.getCompleteStyleDeclaration(e,i-1):{},o=this._measureChar(t,h,s,r);let l,a=o.kernedWidth,d=o.width;0!==this.charSpacing&&(l=this._getWidthOfCharSpacing(),d+=l,a+=l);const f={width:d,left:0,height:h.fontSize,kernedWidth:a,deltaY:h.deltaY};if(i>0&&!n){const t=this.__charBounds[e][i-1];f.left=t.left+t.width+o.kernedWidth-o.width}return f}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let i=1,s=this._textLines[t].length;i<s;i++)e=Math.max(this.getHeightOfChar(t,i),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let i=0,s=this._textLines.length;i<s;i++)t=this.getHeightOfLine(i),e+=i===s-1?t/this.lineHeight:t;return e}_getLeftOffset(){return"ltr"===this.direction?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let i=0;const s=this._getLeftOffset(),n=this._getTopOffset();for(let h=0,r=this._textLines.length;h<r;h++){const r=this.getHeightOfLine(h),o=r/this.lineHeight,l=this._getLineLeftOffset(h);this._renderTextLine(e,t,this._textLines[h],s+l,n+i+o,h),i+=r}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(a))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&0!==this.strokeWidth||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,i,s,n,h){const r=this.getHeightOfLine(h),o=this.textAlign.includes(C),a=this.path,f=!o&&0===this.charSpacing&&this.isEmptyStyles(h)&&!a,c="ltr"===this.direction,g="ltr"===this.direction?1:-1,p=e.direction;let _,m,u,S,y,T="",L=0;if(e.save(),p!==this.direction&&(e.canvas.setAttribute("dir",c?"ltr":"rtl"),e.direction=c?"ltr":"rtl",e.textAlign=c?d:l),n-=r*this._fontSizeFraction/this.lineHeight,f)return this._renderChar(t,e,h,0,i.join(""),s,n),void e.restore();for(let r=0,l=i.length-1;r<=l;r++)S=r===l||this.charSpacing||a,T+=i[r],u=this.__charBounds[h][r],0===L?(s+=g*(u.kernedWidth-u.width),L+=u.width):L+=u.kernedWidth,o&&!S&&this._reSpaceAndTab.test(i[r])&&(S=!0),S||(_=_||this.getCompleteStyleDeclaration(h,r),m=this.getCompleteStyleDeclaration(h,r+1),S=x(_,m,!1)),S&&(a?(e.save(),e.translate(u.renderLeft,u.renderTop),e.rotate(u.angle),this._renderChar(t,e,h,r,T,-L/2,0),e.restore()):(y=s,this._renderChar(t,e,h,r,T,y,n)),T="",_=m,s+=g*L,L=0);e.restore()}_applyPatternGradientTransformText(t){const e=u(),i=this.width+this.strokeWidth,s=this.height+this.strokeWidth,n=e.getContext("2d");return e.width=i,e.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(i,0),n.lineTo(i,s),n.lineTo(0,s),n.closePath(),n.translate(i/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(e,"no-repeat")}handleFiller(t,e,i){let s,n;return P(i)?"percentage"===i.gradientUnits||i.gradientTransform||i.patternTransform?(s=-this.width/2,n=-this.height/2,t.translate(s,n),t[e]=this._applyPatternGradientTransformText(i),{offsetX:s,offsetY:n}):(t[e]=i.toLive(t),this._applyPatternGradientTransform(t,i)):(t[e]=i,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:i,strokeWidth:s}=e;return t.lineWidth=s,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",i)}_setFillStyles(t,e){let{fill:i}=e;return this.handleFiller(t,"fillStyle",i)}_renderChar(t,e,i,s,n,h,r){const o=this._getStyleDeclaration(i,s),l=this.getCompleteStyleDeclaration(i,s),a="fillText"===t&&l.fill,d="strokeText"===t&&l.stroke&&l.strokeWidth;if(d||a){if(e.save(),e.font=this._getFontDeclaration(l),o.textBackgroundColor&&this._removeShadow(e),o.deltaY&&(r+=o.deltaY),a){const t=this._setFillStyles(e,l);e.fillText(n,h-t.offsetX,r-t.offsetY)}if(d){const t=this._setStrokeStyles(e,l);e.strokeText(n,h-t.offsetX,r-t.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,i){const s=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(s.lineIndex,s.charIndex,"fontSize"),h=this.getValueOfPropertyAt(s.lineIndex,s.charIndex,"deltaY"),r={fontSize:n*i.size,deltaY:h+n*i.baseline};this.setSelectionStyles(r,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),i=this.width-e,s=this.textAlign,n=this.direction,h=this.isEndOfWrapping(t);let r=0;return s===C||s===k&&!h||s===W&&!h||s===v&&!h?0:(s===o&&(r=i/2),s===l&&(r=i),s===k&&(r=i/2),s===W&&(r=i),"rtl"===n&&(s===l||s===C||s===W?r=0:s===d||s===v?r=-i:s!==o&&s!==k||(r=-i/2)),r)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(void 0!==this.__lineWidths[t])return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return 0!==this.charSpacing?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,i){var s;return null!==(s=this._getStyleDeclaration(t,e)[i])&&void 0!==s?s:this[i]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let i=this._getTopOffset();const s=this._getLeftOffset(),n=this.path,h=this._getWidthOfCharSpacing(),r=this.offsets[e];for(let o=0,l=this._textLines.length;o<l;o++){const l=this.getHeightOfLine(o);if(!this[e]&&!this.styleHas(e,o)){i+=l;continue}const d=this._textLines[o],f=l/this.lineHeight,c=this._getLineLeftOffset(o);let g,p,_=0,m=0,u=this.getValueOfPropertyAt(o,0,e),x=this.getValueOfPropertyAt(o,0,a);const S=i+f*(1-this._fontSizeFraction);let y=this.getHeightOfChar(o,0),T=this.getValueOfPropertyAt(o,0,"deltaY");for(let i=0,h=d.length;i<h;i++){const h=this.__charBounds[o][i];g=this.getValueOfPropertyAt(o,i,e),p=this.getValueOfPropertyAt(o,i,a);const l=this.getHeightOfChar(o,i),d=this.getValueOfPropertyAt(o,i,"deltaY");if(n&&g&&p)t.save(),t.fillStyle=x,t.translate(h.renderLeft,h.renderTop),t.rotate(h.angle),t.fillRect(-h.kernedWidth/2,r*l+d,h.kernedWidth,this.fontSize/15),t.restore();else if((g!==u||p!==x||l!==y||d!==T)&&m>0){let e=s+c+_;"rtl"===this.direction&&(e=this.width-e-m),u&&x&&(t.fillStyle=x,t.fillRect(e,S+r*y+T,m,this.fontSize/15)),_=h.left,m=h.width,u=g,x=p,y=l,T=d}else m+=h.kernedWidth}let L=s+c+_;"rtl"===this.direction&&(L=this.width-L-m),t.fillStyle=p,g&&p&&t.fillRect(L,S+r*y+T,m-h,this.fontSize/15),i+=l}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:i=this.fontWeight,fontSize:s=this.fontSize}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const h=t.includes("'")||t.includes('"')||t.includes(",")||F.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,i,"".concat(n?this.CACHE_FONT_SIZE:s,"px"),h].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return m(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),i=new Array(e.length),s=["\n"];let n=[];for(let t=0;t<e.length;t++)i[t]=this.graphemeSplit(e[t]),n=n.concat(i[t],s);return n.pop(),{_unwrappedLines:i,lines:e,graphemeText:n,graphemeLines:i}}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return e(e({},super.toObject([...H,...t])),{},{styles:S(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:i}=this.constructor;super.set(t,e);let s=!1,n=!1;if("object"==typeof t)for(const e in t)"path"===e&&this.setPathInfo(),s=s||i.includes(e),n=n||"path"===e;else s=i.includes(t),n="path"===t;return n&&this.setPathInfo(),s&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,s,n){const h=p(t,F.ATTRIBUTE_NAMES,n),r=e(e({},s),h),{textAnchor:a=d,textDecoration:c="",dx:g=0,dy:_=0,top:m=0,left:u=0,fontSize:x=f,strokeWidth:S=1}=r,y=i(r,j),T=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),e({left:u+g,top:m+_,underline:c.includes("underline"),overline:c.includes("overline"),linethrough:c.includes("line-through"),strokeWidth:0,fontSize:x},y)),L=T.getScaledHeight()/T.height,O=((T.height+T.strokeWidth)*T.lineHeight-T.height)*L,w=T.getScaledHeight()+O;let C=0;return a===o&&(C=T.getScaledWidth()/2),a===l&&(C=T.getScaledWidth()),T.set({left:T.left-C,top:T.top-(w-T.fontSize*(.07+T._fontSizeFraction))/T.lineHeight,strokeWidth:S}),T}static fromObject(t){return this._fromObject(e(e({},t),{},{styles:y(t.styles||{},t.text)}),{extraParam:"text"})}}t(F,"textLayoutProperties",A),t(F,"cacheProperties",[...b,...H]),t(F,"ownDefaults",D),t(F,"type","Text"),t(F,"genericFonts",["sans-serif","serif","cursive","fantasy","monospace"]),t(F,"ATTRIBUTE_NAMES",g.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),w(F,[O]),_.setClass(F),_.setSVGClass(F);export{F as FabricText};
|
|
2
2
|
//# sourceMappingURL=Text.min.mjs.map
|