fabric 6.0.2 → 6.2.0
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 +15 -0
- package/dist/index.js +250 -101
- 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 +250 -101
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +250 -101
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +250 -101
- 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/ClassRegistry.d.ts +1 -0
- package/dist/src/ClassRegistry.d.ts.map +1 -1
- package/dist/src/ClassRegistry.min.mjs +1 -1
- package/dist/src/ClassRegistry.min.mjs.map +1 -1
- package/dist/src/ClassRegistry.mjs +3 -0
- package/dist/src/ClassRegistry.mjs.map +1 -1
- package/dist/src/Collection.d.ts +3 -3
- package/dist/src/Collection.d.ts.map +1 -1
- package/dist/src/EventTypeDefs.d.ts +19 -11
- 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 +2 -2
- package/dist/src/LayoutManager/LayoutManager.mjs.map +1 -1
- package/dist/src/Shadow.d.ts.map +1 -1
- package/dist/src/Shadow.min.mjs +1 -1
- package/dist/src/Shadow.min.mjs.map +1 -1
- package/dist/src/Shadow.mjs +1 -5
- package/dist/src/Shadow.mjs.map +1 -1
- package/dist/src/canvas/DOMManagers/util.d.ts.map +1 -1
- package/dist/src/canvas/DOMManagers/util.min.mjs +1 -1
- package/dist/src/canvas/DOMManagers/util.min.mjs.map +1 -1
- package/dist/src/canvas/DOMManagers/util.mjs +9 -15
- package/dist/src/canvas/DOMManagers/util.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 +3 -0
- package/dist/src/canvas/SelectableCanvas.mjs.map +1 -1
- package/dist/src/canvas/StaticCanvas.d.ts +20 -24
- package/dist/src/canvas/StaticCanvas.d.ts.map +1 -1
- package/dist/src/color/util.d.ts.map +1 -1
- package/dist/src/constants.d.ts +1 -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 +2 -1
- package/dist/src/constants.mjs.map +1 -1
- package/dist/src/controls/controlRendering.d.ts +1 -1
- package/dist/src/controls/controlRendering.d.ts.map +1 -1
- package/dist/src/controls/controlRendering.min.mjs.map +1 -1
- package/dist/src/controls/controlRendering.mjs.map +1 -1
- package/dist/src/controls/fireEvent.d.ts +2 -2
- package/dist/src/controls/fireEvent.d.ts.map +1 -1
- package/dist/src/controls/fireEvent.min.mjs.map +1 -1
- package/dist/src/controls/fireEvent.mjs.map +1 -1
- package/dist/src/controls/index.d.ts +1 -0
- package/dist/src/controls/index.d.ts.map +1 -1
- package/dist/src/controls/index.min.mjs +1 -1
- package/dist/src/controls/index.mjs +1 -0
- package/dist/src/controls/index.mjs.map +1 -1
- package/dist/src/controls/pathControl.d.ts +12 -0
- package/dist/src/controls/pathControl.d.ts.map +1 -0
- package/dist/src/controls/pathControl.min.mjs +2 -0
- package/dist/src/controls/pathControl.min.mjs.map +1 -0
- package/dist/src/controls/pathControl.mjs +156 -0
- package/dist/src/controls/pathControl.mjs.map +1 -0
- 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 +1 -9
- package/dist/src/controls/polyControl.mjs.map +1 -1
- package/dist/src/controls/util.d.ts +1 -1
- package/dist/src/controls/wrapWithFireEvent.d.ts +5 -3
- package/dist/src/controls/wrapWithFireEvent.d.ts.map +1 -1
- package/dist/src/controls/wrapWithFireEvent.min.mjs +1 -1
- package/dist/src/controls/wrapWithFireEvent.min.mjs.map +1 -1
- package/dist/src/controls/wrapWithFireEvent.mjs +7 -4
- package/dist/src/controls/wrapWithFireEvent.mjs.map +1 -1
- package/dist/src/controls/wrapWithFixedAnchor.d.ts.map +1 -1
- package/dist/src/env/index.d.ts.map +1 -1
- package/dist/src/env/node.d.ts.map +1 -1
- package/dist/src/filters/BaseFilter.d.ts.map +1 -1
- package/dist/src/filters/BaseFilter.min.mjs.map +1 -1
- package/dist/src/filters/BaseFilter.mjs +0 -1
- package/dist/src/filters/BaseFilter.mjs.map +1 -1
- package/dist/src/filters/ColorMatrix.d.ts.map +1 -1
- package/dist/src/filters/ColorMatrixFilters.d.ts +8 -96
- package/dist/src/filters/ColorMatrixFilters.d.ts.map +1 -1
- package/dist/src/filters/Convolute.d.ts +2 -1
- package/dist/src/filters/Convolute.d.ts.map +1 -1
- package/dist/src/filters/shaders/baseFilter.d.ts +1 -1
- package/dist/src/filters/shaders/baseFilter.d.ts.map +1 -1
- package/dist/src/filters/utils.d.ts.map +1 -1
- package/dist/src/parser/normalizeAttr.d.ts.map +1 -1
- package/dist/src/parser/parseStyleString.d.ts.map +1 -1
- package/dist/src/parser/parseStyleString.min.mjs +1 -1
- package/dist/src/parser/parseStyleString.min.mjs.map +1 -1
- package/dist/src/parser/parseStyleString.mjs +1 -0
- package/dist/src/parser/parseStyleString.mjs.map +1 -1
- package/dist/src/parser/parseUseDirectives.d.ts.map +1 -1
- package/dist/src/parser/parseUseDirectives.min.mjs +1 -1
- package/dist/src/parser/parseUseDirectives.min.mjs.map +1 -1
- package/dist/src/parser/parseUseDirectives.mjs +61 -43
- package/dist/src/parser/parseUseDirectives.mjs.map +1 -1
- package/dist/src/shapes/Group.d.ts +20 -20
- package/dist/src/shapes/Group.d.ts.map +1 -1
- package/dist/src/shapes/IText/DraggableTextDelegate.d.ts.map +1 -1
- package/dist/src/shapes/IText/ITextBehavior.d.ts.map +1 -1
- package/dist/src/shapes/IText/ITextBehavior.min.mjs.map +1 -1
- package/dist/src/shapes/IText/ITextBehavior.mjs +0 -1
- package/dist/src/shapes/IText/ITextBehavior.mjs.map +1 -1
- package/dist/src/shapes/Image.d.ts.map +1 -1
- package/dist/src/shapes/Image.min.mjs.map +1 -1
- package/dist/src/shapes/Image.mjs +0 -2
- package/dist/src/shapes/Image.mjs.map +1 -1
- package/dist/src/shapes/Path.d.ts +9 -9
- package/dist/src/shapes/Path.d.ts.map +1 -1
- package/dist/src/shapes/Polyline.d.ts +1 -1
- package/dist/src/shapes/Rect.d.ts +1 -1
- package/dist/src/shapes/Text/Text.d.ts +1 -1
- package/dist/src/shapes/Text/Text.d.ts.map +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.d.ts.map +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.min.mjs.map +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.mjs +0 -2
- package/dist/src/shapes/Text/TextSVGExportMixin.mjs.map +1 -1
- package/dist/src/shapes/Textbox.d.ts.map +1 -1
- package/dist/src/shapes/Textbox.min.mjs.map +1 -1
- package/dist/src/shapes/Textbox.mjs +0 -2
- package/dist/src/shapes/Textbox.mjs.map +1 -1
- package/dist/src/util/applyMixins.d.ts.map +1 -1
- package/dist/src/util/dom_misc.d.ts.map +1 -1
- package/dist/src/util/dom_misc.min.mjs +1 -1
- package/dist/src/util/dom_misc.min.mjs.map +1 -1
- package/dist/src/util/dom_misc.mjs +7 -9
- package/dist/src/util/dom_misc.mjs.map +1 -1
- package/dist/src/util/internals/cloneDeep.d.ts.map +1 -1
- package/dist/src/util/internals/console.d.ts +1 -1
- package/dist/src/util/internals/findRight.d.ts.map +1 -1
- package/dist/src/util/internals/removeFromArray.d.ts.map +1 -1
- package/dist/src/util/misc/dom.d.ts.map +1 -1
- package/dist/src/util/misc/groupSVGElements.d.ts.map +1 -1
- package/dist/src/util/misc/matrix.d.ts.map +1 -1
- package/dist/src/util/misc/objectEnlive.d.ts +1 -1
- package/dist/src/util/misc/objectEnlive.d.ts.map +1 -1
- package/dist/src/util/misc/objectEnlive.min.mjs +1 -1
- package/dist/src/util/misc/objectEnlive.min.mjs.map +1 -1
- package/dist/src/util/misc/objectEnlive.mjs +7 -11
- package/dist/src/util/misc/objectEnlive.mjs.map +1 -1
- package/dist/src/util/misc/objectTransforms.d.ts.map +1 -1
- package/dist/src/util/misc/pick.d.ts.map +1 -1
- package/dist/src/util/misc/planeChange.d.ts.map +1 -1
- package/dist/src/util/misc/svgParsing.d.ts.map +1 -1
- package/dist/src/util/misc/textStyles.d.ts.map +1 -1
- package/dist/src/util/path/index.d.ts +0 -1
- package/dist/src/util/path/index.d.ts.map +1 -1
- package/dist/src/util/path/index.min.mjs +1 -1
- package/dist/src/util/path/index.min.mjs.map +1 -1
- package/dist/src/util/path/index.mjs +1 -2
- package/dist/src/util/path/index.mjs.map +1 -1
- package/dist/src/util/path/typedefs.d.ts +1 -0
- package/dist/src/util/path/typedefs.d.ts.map +1 -1
- package/dist/src/util/typeAssertions.d.ts +2 -2
- package/dist/src/util/typeAssertions.d.ts.map +1 -1
- package/lib/aligning_guidelines.js +76 -1
- package/lib/centering_guidelines.js +3 -1
- package/package.json +3 -3
- package/src/ClassRegistry.spec.ts +39 -0
- package/src/ClassRegistry.ts +4 -0
- package/src/EventTypeDefs.ts +22 -10
- package/src/LayoutManager/ActiveSelectionLayoutManager.spec.ts +1 -0
- package/src/LayoutManager/LayoutManager.spec.ts +1 -0
- package/src/LayoutManager/LayoutManager.ts +2 -0
- package/src/Shadow.ts +1 -6
- package/src/canvas/DOMManagers/util.ts +11 -15
- package/src/canvas/SelectableCanvas.spec.ts +18 -0
- package/src/canvas/SelectableCanvas.ts +3 -0
- package/src/constants.ts +1 -0
- package/src/controls/controlRendering.ts +4 -2
- package/src/controls/fireEvent.ts +2 -2
- package/src/controls/index.ts +1 -0
- package/src/controls/pathControl.spec.ts +75 -0
- package/src/controls/pathControl.ts +293 -0
- package/src/controls/polyControl.ts +1 -1
- package/src/controls/wrapWithFireEvent.ts +14 -5
- package/src/filters/BaseFilter.ts +1 -2
- package/src/parser/parseStyleString.ts +1 -0
- package/src/parser/parseUseDirectives.test.ts +113 -0
- package/src/parser/parseUseDirectives.ts +64 -58
- package/src/shapes/IText/ITextBehavior.ts +4 -2
- package/src/shapes/Image.ts +0 -2
- package/src/shapes/Text/TextSVGExportMixin.ts +0 -2
- package/src/shapes/Textbox.ts +0 -2
- package/src/util/dom_misc.ts +17 -10
- package/src/util/misc/objectEnlive.spec.ts +68 -0
- package/src/util/misc/objectEnlive.ts +7 -13
- package/src/util/path/__snapshots__/index.spec.ts.snap +327 -0
- package/src/util/path/index.spec.ts +13 -2
- package/src/util/path/index.ts +2 -4
- package/src/util/path/typedefs.ts +2 -0
- package/.gitmodules +0 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var r="6.0
|
|
1
|
+
var r="6.2.0";export{r as version};
|
|
2
2
|
//# sourceMappingURL=package.json.min.mjs.map
|
package/dist/package.json.mjs
CHANGED
|
@@ -4,6 +4,7 @@ export declare class ClassRegistry {
|
|
|
4
4
|
[JSON]: Map<string, any>;
|
|
5
5
|
[SVG]: Map<string, any>;
|
|
6
6
|
constructor();
|
|
7
|
+
has(classType: string): boolean;
|
|
7
8
|
getClass<T>(classType: string): T;
|
|
8
9
|
setClass(classConstructor: any, classType?: string): void;
|
|
9
10
|
getSVGClass(SVGTagName: string): any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassRegistry.d.ts","sourceRoot":"","sources":["../../src/ClassRegistry.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,IAAI,SAAS,CAAC;AAC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als/console.min.mjs";const t="json",e="svg";class o{constructor(){this[t]=new Map,this[e]=new Map}getClass(e){const o=this[t].get(e);if(!o)throw new s("No class registered for ".concat(e));return o}setClass(s,e){e?this[t].set(e,s):(this[t].set(s.type,s),this[t].set(s.type.toLowerCase(),s))}getSVGClass(s){return this[e].get(s)}setSVGClass(s,t){this[e].set(null!=t?t:s.type.toLowerCase(),s)}}const n=new o;export{o as ClassRegistry,t as JSON,e as SVG,n as classRegistry};
|
|
1
|
+
import{FabricError as s}from"./util/internals/console.min.mjs";const t="json",e="svg";class o{constructor(){this[t]=new Map,this[e]=new Map}has(s){return this[t].has(s)}getClass(e){const o=this[t].get(e);if(!o)throw new s("No class registered for ".concat(e));return o}setClass(s,e){e?this[t].set(e,s):(this[t].set(s.type,s),this[t].set(s.type.toLowerCase(),s))}getSVGClass(s){return this[e].get(s)}setSVGClass(s,t){this[e].set(null!=t?t:s.type.toLowerCase(),s)}}const n=new o;export{o as ClassRegistry,t as JSON,e as SVG,n as classRegistry};
|
|
2
2
|
//# sourceMappingURL=ClassRegistry.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassRegistry.min.mjs","sources":["../../src/ClassRegistry.ts"],"sourcesContent":["import { FabricError } from './util/internals/console';\n\n/*\n * This Map connects the objects type value with their\n * class implementation. It used from any object to understand which are\n * the classes to enlive when requesting a object.type = 'path' for example.\n * Objects uses it for clipPath, Canvas uses it for everything.\n * This is necessary for generic code to run and enlive instances from serialized representation.\n * You can customize which classes get enlived from SVG parsing using this classRegistry.\n * The Registry start empty and gets filled in depending which files you import.\n * If you want to be able to parse arbitrary SVGs or JSON representation of canvases, coming from\n * different sources you will need to import all fabric because you may need all classes.\n */\n\nexport const JSON = 'json';\nexport const SVG = 'svg';\n\nexport class ClassRegistry {\n declare [JSON]: Map<string, any>;\n declare [SVG]: Map<string, any>;\n\n constructor() {\n this[JSON] = new Map();\n this[SVG] = new Map();\n }\n\n getClass<T>(classType: string): T {\n const constructor = this[JSON].get(classType);\n if (!constructor) {\n throw new FabricError(`No class registered for ${classType}`);\n }\n return constructor;\n }\n\n setClass(classConstructor: any, classType?: string) {\n if (classType) {\n this[JSON].set(classType, classConstructor);\n } else {\n this[JSON].set(classConstructor.type, classConstructor);\n // legacy\n // @TODO: needs to be removed in fabric 7 or 8\n this[JSON].set(classConstructor.type.toLowerCase(), classConstructor);\n }\n }\n\n getSVGClass(SVGTagName: string): any {\n return this[SVG].get(SVGTagName);\n }\n\n setSVGClass(classConstructor: any, SVGTagName?: string) {\n this[SVG].set(\n SVGTagName ?? classConstructor.type.toLowerCase(),\n classConstructor\n );\n }\n}\n\nexport const classRegistry = new ClassRegistry();\n"],"names":["JSON","SVG","ClassRegistry","constructor","this","Map","
|
|
1
|
+
{"version":3,"file":"ClassRegistry.min.mjs","sources":["../../src/ClassRegistry.ts"],"sourcesContent":["import { FabricError } from './util/internals/console';\n\n/*\n * This Map connects the objects type value with their\n * class implementation. It used from any object to understand which are\n * the classes to enlive when requesting a object.type = 'path' for example.\n * Objects uses it for clipPath, Canvas uses it for everything.\n * This is necessary for generic code to run and enlive instances from serialized representation.\n * You can customize which classes get enlived from SVG parsing using this classRegistry.\n * The Registry start empty and gets filled in depending which files you import.\n * If you want to be able to parse arbitrary SVGs or JSON representation of canvases, coming from\n * different sources you will need to import all fabric because you may need all classes.\n */\n\nexport const JSON = 'json';\nexport const SVG = 'svg';\n\nexport class ClassRegistry {\n declare [JSON]: Map<string, any>;\n declare [SVG]: Map<string, any>;\n\n constructor() {\n this[JSON] = new Map();\n this[SVG] = new Map();\n }\n\n has(classType: string): boolean {\n return this[JSON].has(classType);\n }\n\n getClass<T>(classType: string): T {\n const constructor = this[JSON].get(classType);\n if (!constructor) {\n throw new FabricError(`No class registered for ${classType}`);\n }\n return constructor;\n }\n\n setClass(classConstructor: any, classType?: string) {\n if (classType) {\n this[JSON].set(classType, classConstructor);\n } else {\n this[JSON].set(classConstructor.type, classConstructor);\n // legacy\n // @TODO: needs to be removed in fabric 7 or 8\n this[JSON].set(classConstructor.type.toLowerCase(), classConstructor);\n }\n }\n\n getSVGClass(SVGTagName: string): any {\n return this[SVG].get(SVGTagName);\n }\n\n setSVGClass(classConstructor: any, SVGTagName?: string) {\n this[SVG].set(\n SVGTagName ?? classConstructor.type.toLowerCase(),\n classConstructor\n );\n }\n}\n\nexport const classRegistry = new ClassRegistry();\n"],"names":["JSON","SVG","ClassRegistry","constructor","this","Map","has","classType","getClass","get","FabricError","concat","setClass","classConstructor","set","type","toLowerCase","getSVGClass","SVGTagName","setSVGClass","classRegistry"],"mappings":"+DAcO,MAAMA,EAAO,OACPC,EAAM,MAEZ,MAAMC,EAIXC,WAAAA,GACEC,KAAKJ,GAAQ,IAAIK,IACjBD,KAAKH,GAAO,IAAII,GAClB,CAEAC,GAAAA,CAAIC,GACF,OAAOH,KAAKJ,GAAMM,IAAIC,EACxB,CAEAC,QAAAA,CAAYD,GACV,MAAMJ,EAAcC,KAAKJ,GAAMS,IAAIF,GACnC,IAAKJ,EACH,MAAM,IAAIO,EAAW,2BAAAC,OAA4BJ,IAEnD,OAAOJ,CACT,CAEAS,QAAAA,CAASC,EAAuBN,GAC1BA,EACFH,KAAKJ,GAAMc,IAAIP,EAAWM,IAE1BT,KAAKJ,GAAMc,IAAID,EAAiBE,KAAMF,GAGtCT,KAAKJ,GAAMc,IAAID,EAAiBE,KAAKC,cAAeH,GAExD,CAEAI,WAAAA,CAAYC,GACV,OAAOd,KAAKH,GAAKQ,IAAIS,EACvB,CAEAC,WAAAA,CAAYN,EAAuBK,GACjCd,KAAKH,GAAKa,IACRI,QAAAA,EAAcL,EAAiBE,KAAKC,cACpCH,EAEJ,QAGWO,EAAgB,IAAIlB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassRegistry.mjs","sources":["../../src/ClassRegistry.ts"],"sourcesContent":["import { FabricError } from './util/internals/console';\n\n/*\n * This Map connects the objects type value with their\n * class implementation. It used from any object to understand which are\n * the classes to enlive when requesting a object.type = 'path' for example.\n * Objects uses it for clipPath, Canvas uses it for everything.\n * This is necessary for generic code to run and enlive instances from serialized representation.\n * You can customize which classes get enlived from SVG parsing using this classRegistry.\n * The Registry start empty and gets filled in depending which files you import.\n * If you want to be able to parse arbitrary SVGs or JSON representation of canvases, coming from\n * different sources you will need to import all fabric because you may need all classes.\n */\n\nexport const JSON = 'json';\nexport const SVG = 'svg';\n\nexport class ClassRegistry {\n declare [JSON]: Map<string, any>;\n declare [SVG]: Map<string, any>;\n\n constructor() {\n this[JSON] = new Map();\n this[SVG] = new Map();\n }\n\n getClass<T>(classType: string): T {\n const constructor = this[JSON].get(classType);\n if (!constructor) {\n throw new FabricError(`No class registered for ${classType}`);\n }\n return constructor;\n }\n\n setClass(classConstructor: any, classType?: string) {\n if (classType) {\n this[JSON].set(classType, classConstructor);\n } else {\n this[JSON].set(classConstructor.type, classConstructor);\n // legacy\n // @TODO: needs to be removed in fabric 7 or 8\n this[JSON].set(classConstructor.type.toLowerCase(), classConstructor);\n }\n }\n\n getSVGClass(SVGTagName: string): any {\n return this[SVG].get(SVGTagName);\n }\n\n setSVGClass(classConstructor: any, SVGTagName?: string) {\n this[SVG].set(\n SVGTagName ?? classConstructor.type.toLowerCase(),\n classConstructor\n );\n }\n}\n\nexport const classRegistry = new ClassRegistry();\n"],"names":["JSON","SVG","ClassRegistry","constructor","Map","
|
|
1
|
+
{"version":3,"file":"ClassRegistry.mjs","sources":["../../src/ClassRegistry.ts"],"sourcesContent":["import { FabricError } from './util/internals/console';\n\n/*\n * This Map connects the objects type value with their\n * class implementation. It used from any object to understand which are\n * the classes to enlive when requesting a object.type = 'path' for example.\n * Objects uses it for clipPath, Canvas uses it for everything.\n * This is necessary for generic code to run and enlive instances from serialized representation.\n * You can customize which classes get enlived from SVG parsing using this classRegistry.\n * The Registry start empty and gets filled in depending which files you import.\n * If you want to be able to parse arbitrary SVGs or JSON representation of canvases, coming from\n * different sources you will need to import all fabric because you may need all classes.\n */\n\nexport const JSON = 'json';\nexport const SVG = 'svg';\n\nexport class ClassRegistry {\n declare [JSON]: Map<string, any>;\n declare [SVG]: Map<string, any>;\n\n constructor() {\n this[JSON] = new Map();\n this[SVG] = new Map();\n }\n\n has(classType: string): boolean {\n return this[JSON].has(classType);\n }\n\n getClass<T>(classType: string): T {\n const constructor = this[JSON].get(classType);\n if (!constructor) {\n throw new FabricError(`No class registered for ${classType}`);\n }\n return constructor;\n }\n\n setClass(classConstructor: any, classType?: string) {\n if (classType) {\n this[JSON].set(classType, classConstructor);\n } else {\n this[JSON].set(classConstructor.type, classConstructor);\n // legacy\n // @TODO: needs to be removed in fabric 7 or 8\n this[JSON].set(classConstructor.type.toLowerCase(), classConstructor);\n }\n }\n\n getSVGClass(SVGTagName: string): any {\n return this[SVG].get(SVGTagName);\n }\n\n setSVGClass(classConstructor: any, SVGTagName?: string) {\n this[SVG].set(\n SVGTagName ?? classConstructor.type.toLowerCase(),\n classConstructor\n );\n }\n}\n\nexport const classRegistry = new ClassRegistry();\n"],"names":["JSON","SVG","ClassRegistry","constructor","Map","has","classType","getClass","get","FabricError","concat","setClass","classConstructor","set","type","toLowerCase","getSVGClass","SVGTagName","setSVGClass","classRegistry"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,MAAMA,IAAI,GAAG,OAAM;AACnB,MAAMC,GAAG,GAAG,MAAK;AAEjB,MAAMC,aAAa,CAAC;AAIzBC,EAAAA,WAAWA,GAAG;AACZ,IAAA,IAAI,CAACH,IAAI,CAAC,GAAG,IAAII,GAAG,EAAE,CAAA;AACtB,IAAA,IAAI,CAACH,GAAG,CAAC,GAAG,IAAIG,GAAG,EAAE,CAAA;AACvB,GAAA;EAEAC,GAAGA,CAACC,SAAiB,EAAW;IAC9B,OAAO,IAAI,CAACN,IAAI,CAAC,CAACK,GAAG,CAACC,SAAS,CAAC,CAAA;AAClC,GAAA;EAEAC,QAAQA,CAAID,SAAiB,EAAK;IAChC,MAAMH,WAAW,GAAG,IAAI,CAACH,IAAI,CAAC,CAACQ,GAAG,CAACF,SAAS,CAAC,CAAA;IAC7C,IAAI,CAACH,WAAW,EAAE;AAChB,MAAA,MAAM,IAAIM,WAAW,CAAA,0BAAA,CAAAC,MAAA,CAA4BJ,SAAS,CAAE,CAAC,CAAA;AAC/D,KAAA;AACA,IAAA,OAAOH,WAAW,CAAA;AACpB,GAAA;AAEAQ,EAAAA,QAAQA,CAACC,gBAAqB,EAAEN,SAAkB,EAAE;AAClD,IAAA,IAAIA,SAAS,EAAE;MACb,IAAI,CAACN,IAAI,CAAC,CAACa,GAAG,CAACP,SAAS,EAAEM,gBAAgB,CAAC,CAAA;AAC7C,KAAC,MAAM;MACL,IAAI,CAACZ,IAAI,CAAC,CAACa,GAAG,CAACD,gBAAgB,CAACE,IAAI,EAAEF,gBAAgB,CAAC,CAAA;AACvD;AACA;AACA,MAAA,IAAI,CAACZ,IAAI,CAAC,CAACa,GAAG,CAACD,gBAAgB,CAACE,IAAI,CAACC,WAAW,EAAE,EAAEH,gBAAgB,CAAC,CAAA;AACvE,KAAA;AACF,GAAA;EAEAI,WAAWA,CAACC,UAAkB,EAAO;IACnC,OAAO,IAAI,CAAChB,GAAG,CAAC,CAACO,GAAG,CAACS,UAAU,CAAC,CAAA;AAClC,GAAA;AAEAC,EAAAA,WAAWA,CAACN,gBAAqB,EAAEK,UAAmB,EAAE;IACtD,IAAI,CAAChB,GAAG,CAAC,CAACY,GAAG,CACXI,UAAU,aAAVA,UAAU,KAAA,KAAA,CAAA,GAAVA,UAAU,GAAIL,gBAAgB,CAACE,IAAI,CAACC,WAAW,EAAE,EACjDH,gBACF,CAAC,CAAA;AACH,GAAA;AACF,CAAA;MAEaO,aAAa,GAAG,IAAIjB,aAAa;;;;"}
|
package/dist/src/Collection.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Group } from './shapes/Group';
|
|
|
4
4
|
import type { InteractiveFabricObject } from './shapes/Object/InteractiveObject';
|
|
5
5
|
import type { FabricObject } from './shapes/Object/FabricObject';
|
|
6
6
|
export declare const isCollection: (fabricObject?: FabricObject) => fabricObject is Group | ActiveSelection;
|
|
7
|
-
export declare function createCollectionMixin<TBase extends Constructor>(Base: TBase): {
|
|
7
|
+
export declare function createCollectionMixin<TBase extends Constructor>(Base: TBase): ({
|
|
8
8
|
new (...args: any[]): {
|
|
9
9
|
/**
|
|
10
10
|
* @type {FabricObject[]}
|
|
@@ -134,8 +134,8 @@ export declare function createCollectionMixin<TBase extends Constructor>(Base: T
|
|
|
134
134
|
* @returns array of objects contained in the bounding box, ordered from top to bottom stacking wise
|
|
135
135
|
*/
|
|
136
136
|
collectObjects({ left, top, width, height }: TBBox, { includeIntersecting }?: {
|
|
137
|
-
includeIntersecting?: boolean
|
|
137
|
+
includeIntersecting?: boolean;
|
|
138
138
|
}): InteractiveFabricObject<Partial<import("..").FabricObjectProps>, import("..").SerializedObjectProps, import("./EventTypeDefs").ObjectEvents>[];
|
|
139
139
|
};
|
|
140
|
-
} & TBase;
|
|
140
|
+
} & TBase) & TBase;
|
|
141
141
|
//# sourceMappingURL=Collection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../src/Collection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEjE,eAAO,MAAM,YAAY,kBACR,YAAY,
|
|
1
|
+
{"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../src/Collection.ts"],"names":[],"mappings":"AAAA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;;;;;;WAOG;qDAE6B,KAAK,4BACH;YAAE,mBAAmB,CAAC,EAAE,OAAO,CAAA;SAAE;;aA0B5B,KAAK,CAC/C"}
|
|
@@ -8,7 +8,7 @@ import type { Canvas } from './canvas/Canvas';
|
|
|
8
8
|
import type { IText } from './shapes/IText/IText';
|
|
9
9
|
import type { StaticCanvas } from './canvas/StaticCanvas';
|
|
10
10
|
import type { LayoutBeforeEvent, LayoutAfterEvent } from './LayoutManager/types';
|
|
11
|
-
import type { MODIFY_POLY, MOVING, RESIZING, ROTATING, SCALING, SKEWING } from './constants';
|
|
11
|
+
import type { MODIFIED, MODIFY_PATH, MODIFY_POLY, MOVING, RESIZING, ROTATING, SCALING, SKEWING } from './constants';
|
|
12
12
|
export type ModifierKey = keyof Pick<MouseEvent | PointerEvent | TouchEvent, 'altKey' | 'shiftKey' | 'ctrlKey' | 'metaKey'>;
|
|
13
13
|
export type TOptionalModifierKey = ModifierKey | null | undefined;
|
|
14
14
|
export type TPointerEvent = MouseEvent | TouchEvent | PointerEvent;
|
|
@@ -67,21 +67,26 @@ export interface BasicTransformEvent<E extends Event = TPointerEvent> extends TE
|
|
|
67
67
|
transform: Transform;
|
|
68
68
|
pointer: Point;
|
|
69
69
|
}
|
|
70
|
-
export type TModificationEvents = typeof MOVING | typeof SCALING | typeof ROTATING | typeof SKEWING | typeof RESIZING | typeof MODIFY_POLY;
|
|
70
|
+
export type TModificationEvents = typeof MOVING | typeof SCALING | typeof ROTATING | typeof SKEWING | typeof RESIZING | typeof MODIFY_POLY | typeof MODIFY_PATH;
|
|
71
71
|
export interface ModifiedEvent<E extends Event = TPointerEvent> {
|
|
72
72
|
e?: E;
|
|
73
73
|
transform?: Transform;
|
|
74
74
|
target: FabricObject;
|
|
75
75
|
action?: string;
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
export interface ModifyPathEvent {
|
|
78
|
+
commandIndex: number;
|
|
79
|
+
pointIndex: number;
|
|
80
|
+
}
|
|
81
|
+
export type ObjectModificationEvents = {
|
|
82
|
+
[MOVING]: BasicTransformEvent;
|
|
83
|
+
[SCALING]: BasicTransformEvent;
|
|
84
|
+
[ROTATING]: BasicTransformEvent;
|
|
85
|
+
[SKEWING]: BasicTransformEvent;
|
|
86
|
+
[RESIZING]: BasicTransformEvent;
|
|
87
|
+
[MODIFY_POLY]: BasicTransformEvent;
|
|
88
|
+
[MODIFY_PATH]: BasicTransformEvent & ModifyPathEvent;
|
|
89
|
+
[MODIFIED]: ModifiedEvent;
|
|
85
90
|
};
|
|
86
91
|
type CanvasModificationEvents = {
|
|
87
92
|
'before:transform': TEvent & {
|
|
@@ -105,6 +110,9 @@ type CanvasModificationEvents = {
|
|
|
105
110
|
'object:modifyPoly': BasicTransformEvent & {
|
|
106
111
|
target: FabricObject;
|
|
107
112
|
};
|
|
113
|
+
'object:modifyPath': BasicTransformEvent & {
|
|
114
|
+
target: FabricObject;
|
|
115
|
+
} & ModifyPathEvent;
|
|
108
116
|
'object:modified': ModifiedEvent;
|
|
109
117
|
};
|
|
110
118
|
export interface TPointerEventInfo<E extends TPointerEvent = TPointerEvent> extends TEvent<E> {
|
|
@@ -269,7 +277,7 @@ export interface CanvasEvents extends StaticCanvasEvents, CanvasPointerEvents, C
|
|
|
269
277
|
};
|
|
270
278
|
'text:editing:entered': {
|
|
271
279
|
target: IText;
|
|
272
|
-
}
|
|
280
|
+
} & Partial<TEvent>;
|
|
273
281
|
'text:editing:exited': {
|
|
274
282
|
target: IText;
|
|
275
283
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventTypeDefs.d.ts","sourceRoot":"","sources":["../../src/EventTypeDefs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;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;YACT,eAAe,CAAC,EAAE,YAAY,CAAC;YAC/B,YAAY,CAAC,EAAE,YAAY,CAAC;SAC7B,CAAC;KACH,CAAC;IAGN,wBAAwB,EAAE;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE,CAAC;IAC5C,cAAc,EAAE;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE,CAAC;IAClC,sBAAsB,EAAE;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5D,qBAAqB,EAAE;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE,CAAC;CAC1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LayoutManager.d.ts","sourceRoot":"","sources":["../../../src/LayoutManager/LayoutManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LayoutManager.d.ts","sourceRoot":"","sources":["../../../src/LayoutManager/LayoutManager.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAIlE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AASxE,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAMjB,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,qBAAa,aAAa;IACxB,QAAgB,mBAAmB,CAAC,CAAiB;IACrD,UAAkB,cAAc,EAAE,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,CAAC,CAAC;IAEpE,QAAQ,EAAE,cAAc,CAAC;gBAEb,QAAQ,GAAE,cAAuC;IAKtD,aAAa,CAAC,OAAO,EAAE,aAAa;IAsB3C;;;;;;;OAOG;IACH,SAAS,CAAC,cAAc,CACtB,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC,GAC1D,YAAY,EAAE;IAmCjB;;;;;OAKG;IACH,SAAS,CAAC,SAAS,CACjB,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAO7D;;OAEG;IACH,SAAS,CAAC,WAAW,CACnB,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAM9D,kBAAkB,CAChB,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAK7D,gBAAgB,CACd,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAK7D,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,mBAAmB;IAmCrD,SAAS,CAAC,eAAe,CACvB,OAAO,EAAE,mBAAmB,GAC3B,QAAQ,CAAC,YAAY,CAAC,GAAG,SAAS;IAuCrC,SAAS,CAAC,YAAY,CACpB,OAAO,EAAE,mBAAmB,EAC5B,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC;IA4BtC,SAAS,CAAC,aAAa,CACrB,OAAO,EAAE,mBAAmB,EAC5B,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC;IAatC;;;OAGG;IACH,SAAS,CAAC,YAAY,CACpB,OAAO,EAAE,mBAAmB,EAC5B,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,YAAY,CAAC,EAClC,MAAM,EAAE,YAAY;IAWtB,SAAS,CAAC,aAAa,CACrB,OAAO,EAAE,mBAAmB,EAC5B,YAAY,CAAC,EAAE,YAAY;IAqC7B,OAAO;IAMP,QAAQ;;;;IAOR,MAAM;;;;CAGP"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{defineProperty as t,objectSpread2 as e,objectWithoutProperties as r}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{Point as s}from"../Point.min.mjs";import{MODIFIED as o,MOVING as a,RESIZING as i,ROTATING as n,SCALING as u,SKEWING as c,CHANGED as y,MODIFY_POLY as g,
|
|
1
|
+
import{defineProperty as t,objectSpread2 as e,objectWithoutProperties as r}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{Point as s}from"../Point.min.mjs";import{MODIFIED as o,MOVING as a,RESIZING as i,ROTATING as n,SCALING as u,SKEWING as c,CHANGED as y,MODIFY_POLY as g,MODIFY_PATH as l,iMatrix as b,CENTER as p}from"../constants.min.mjs";import{invertTransform as h}from"../util/misc/matrix.min.mjs";import{resolveOrigin as m}from"../util/misc/resolveOrigin.min.mjs";import{FitContentLayout as f}from"./LayoutStrategies/FitContentLayout.min.mjs";import{LAYOUT_TYPE_OBJECT_MODIFIED as j,LAYOUT_TYPE_OBJECT_MODIFYING as d,LAYOUT_TYPE_INITIALIZATION as L,LAYOUT_TYPE_ADDED as v,LAYOUT_TYPE_REMOVED as x,LAYOUT_TYPE_IMPERATIVE as O}from"./constants.min.mjs";import{classRegistry as C}from"../ClassRegistry.min.mjs";const P=["strategy"],_=["target","strategy","bubbles","prevStrategy"],S="layoutManager";class w{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new f;t(this,"strategy",void 0),this.strategy=e,this._subscriptions=new Map}performLayout(t){const r=e(e({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(r);const s=this.getLayoutResult(r);s&&this.commitLayout(r,s),this.onAfterLayout(r,s),this._prevLayoutStrategy=r.strategy}attachHandlers(t,e){const{target:r}=e;return[o,a,i,n,u,c,y,g,l].map((e=>t.on(e,(t=>this.performLayout(e===o?{type:j,trigger:e,e:t,target:r}:{type:d,trigger:e,e:t,target:r})))))}subscribe(t,e){this.unsubscribe(t,e);const r=this.attachHandlers(t,e);this._subscriptions.set(t,r)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach((t=>t())),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach((e=>this.unsubscribe(e,t)))}subscribeTargets(t){t.targets.forEach((e=>this.subscribe(e,t)))}onBeforeLayout(t){const{target:s,type:o}=t,{canvas:a}=s;if(o===L||o===v?this.subscribeTargets(t):o===x&&this.unsubscribeTargets(t),s.fire("layout:before",{context:t}),a&&a.fire("object:layout:before",{target:s,context:t}),o===O&&t.deep){const o=r(t,P);s.forEachObject((t=>t.layoutManager&&t.layoutManager.performLayout(e(e({},o),{},{bubbles:!1,target:t}))))}}getLayoutResult(t){const{target:e,strategy:r,type:o}=t,a=r.calcLayoutResult(t,e.getObjects());if(!a)return;const i=o===L?new s:e.getRelativeCenterPoint(),{center:n,correction:u=new s,relativeCorrection:c=new s}=a,y=i.subtract(n).add(u).transform(o===L?b:h(e.calcOwnMatrix()),!0).add(c);return{result:a,prevCenter:i,nextCenter:n,offset:y}}commitLayout(t,e){const{target:r}=t,{result:{size:s},nextCenter:o}=e;var a,i;(r.set({width:s.x,height:s.y}),this.layoutObjects(t,e),t.type===L)?r.set({left:null!==(a=t.x)&&void 0!==a?a:o.x+s.x*m(r.originX),top:null!==(i=t.y)&&void 0!==i?i:o.y+s.y*m(r.originY)}):(r.setPositionByOrigin(o,p,p),r.setCoords(),r.set("dirty",!0))}layoutObjects(t,e){const{target:r}=t;r.forEachObject((s=>{s.group===r&&this.layoutObject(t,e,s)})),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,r.clipPath)}layoutObject(t,e,r){let{offset:s}=e;r.set({left:r.left+s.x,top:r.top+s.y})}onAfterLayout(t,s){const{target:o,strategy:a,bubbles:i,prevStrategy:n}=t,u=r(t,_),{canvas:c}=o;o.fire("layout:after",{context:t,result:s}),c&&c.fire("object:layout:after",{context:t,result:s,target:o});const y=o.parent;i&&null!=y&&y.layoutManager&&((u.path||(u.path=[])).push(o),y.layoutManager.performLayout(e(e({},u),{},{target:y}))),o.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach((t=>t.forEach((t=>t())))),t.clear()}toObject(){return{type:S,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}C.setClass(w,S);export{w as LayoutManager};
|
|
2
2
|
//# sourceMappingURL=LayoutManager.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LayoutManager.min.mjs","sources":["../../../src/LayoutManager/LayoutManager.ts"],"sourcesContent":["import { Point } from '../Point';\nimport {\n CENTER,\n CHANGED,\n MODIFIED,\n MODIFY_POLY,\n MOVING,\n RESIZING,\n ROTATING,\n SCALING,\n SKEWING,\n iMatrix,\n} from '../constants';\nimport type { Group } from '../shapes/Group';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport { invertTransform } from '../util/misc/matrix';\nimport { resolveOrigin } from '../util/misc/resolveOrigin';\nimport { FitContentLayout } from './LayoutStrategies/FitContentLayout';\nimport type { LayoutStrategy } from './LayoutStrategies/LayoutStrategy';\nimport {\n LAYOUT_TYPE_INITIALIZATION,\n LAYOUT_TYPE_ADDED,\n LAYOUT_TYPE_REMOVED,\n LAYOUT_TYPE_IMPERATIVE,\n LAYOUT_TYPE_OBJECT_MODIFIED,\n LAYOUT_TYPE_OBJECT_MODIFYING,\n} from './constants';\nimport type {\n LayoutContext,\n LayoutResult,\n RegistrationContext,\n StrictLayoutContext,\n} from './types';\nimport { classRegistry } from '../ClassRegistry';\nimport type { TModificationEvents } from '../EventTypeDefs';\n\nconst LAYOUT_MANAGER = 'layoutManager';\n\nexport type SerializedLayoutManager = {\n type: string;\n strategy: string;\n};\n\nexport class LayoutManager {\n private declare _prevLayoutStrategy?: LayoutStrategy;\n protected declare _subscriptions: Map<FabricObject, VoidFunction[]>;\n\n strategy: LayoutStrategy;\n\n constructor(strategy: LayoutStrategy = new FitContentLayout()) {\n this.strategy = strategy;\n this._subscriptions = new Map();\n }\n\n public performLayout(context: LayoutContext) {\n const strictContext: StrictLayoutContext = {\n bubbles: true,\n strategy: this.strategy,\n ...context,\n prevStrategy: this._prevLayoutStrategy,\n stopPropagation() {\n this.bubbles = false;\n },\n };\n\n this.onBeforeLayout(strictContext);\n\n const layoutResult = this.getLayoutResult(strictContext);\n if (layoutResult) {\n this.commitLayout(strictContext, layoutResult);\n }\n\n this.onAfterLayout(strictContext, layoutResult);\n this._prevLayoutStrategy = strictContext.strategy;\n }\n\n /**\n * Attach handlers for events that we know will invalidate the layout when\n * performed on child objects ( general transforms ).\n * Returns the disposers for later unsubscribing and cleanup\n * @param {FabricObject} object\n * @param {RegistrationContext & Partial<StrictLayoutContext>} context\n * @returns {VoidFunction[]} disposers remove the handlers\n */\n protected attachHandlers(\n object: FabricObject,\n context: RegistrationContext & Partial<StrictLayoutContext>\n ): VoidFunction[] {\n const { target } = context;\n return (\n [\n MODIFIED,\n MOVING,\n RESIZING,\n ROTATING,\n SCALING,\n SKEWING,\n CHANGED,\n MODIFY_POLY,\n ] as (TModificationEvents & 'modified')[]\n ).map((key) =>\n object.on(key, (e) =>\n this.performLayout(\n key === MODIFIED\n ? {\n type: LAYOUT_TYPE_OBJECT_MODIFIED,\n trigger: key,\n e,\n target,\n }\n : {\n type: LAYOUT_TYPE_OBJECT_MODIFYING,\n trigger: key,\n e,\n target,\n }\n )\n )\n );\n }\n\n /**\n * Subscribe an object to transform events that will trigger a layout change on the parent\n * This is important only for interactive groups.\n * @param object\n * @param context\n */\n protected subscribe(\n object: FabricObject,\n context: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n this.unsubscribe(object, context);\n const disposers = this.attachHandlers(object, context);\n this._subscriptions.set(object, disposers);\n }\n\n /**\n * unsubscribe object layout triggers\n */\n protected unsubscribe(\n object: FabricObject,\n context?: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n (this._subscriptions.get(object) || []).forEach((d) => d());\n this._subscriptions.delete(object);\n }\n\n unsubscribeTargets(\n context: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n context.targets.forEach((object) => this.unsubscribe(object, context));\n }\n\n subscribeTargets(\n context: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n context.targets.forEach((object) => this.subscribe(object, context));\n }\n\n protected onBeforeLayout(context: StrictLayoutContext) {\n const { target, type } = context;\n const { canvas } = target;\n // handle layout triggers subscription\n // @TODO: gate the registration when the group is interactive\n if (type === LAYOUT_TYPE_INITIALIZATION || type === LAYOUT_TYPE_ADDED) {\n this.subscribeTargets(context);\n } else if (type === LAYOUT_TYPE_REMOVED) {\n this.unsubscribeTargets(context);\n }\n // fire layout event (event will fire only for layouts after initialization layout)\n target.fire('layout:before', {\n context,\n });\n canvas &&\n canvas.fire('object:layout:before', {\n target,\n context,\n });\n\n if (type === LAYOUT_TYPE_IMPERATIVE && context.deep) {\n const { strategy: _, ...tricklingContext } = context;\n // traverse the tree\n target.forEachObject(\n (object) =>\n (object as Group).layoutManager &&\n (object as Group).layoutManager.performLayout({\n ...tricklingContext,\n bubbles: false,\n target: object as Group,\n })\n );\n }\n }\n\n protected getLayoutResult(\n context: StrictLayoutContext\n ): Required<LayoutResult> | undefined {\n const { target, strategy, type } = context;\n\n const result = strategy.calcLayoutResult(context, target.getObjects());\n\n if (!result) {\n return;\n }\n\n const prevCenter =\n type === LAYOUT_TYPE_INITIALIZATION\n ? new Point()\n : target.getRelativeCenterPoint();\n\n const {\n center: nextCenter,\n correction = new Point(),\n relativeCorrection = new Point(),\n } = result;\n const offset = prevCenter\n .subtract(nextCenter)\n .add(correction)\n .transform(\n // in `initialization` we do not account for target's transformation matrix\n type === LAYOUT_TYPE_INITIALIZATION\n ? iMatrix\n : invertTransform(target.calcOwnMatrix()),\n true\n )\n .add(relativeCorrection);\n\n return {\n result,\n prevCenter,\n nextCenter,\n offset,\n };\n }\n\n protected commitLayout(\n context: StrictLayoutContext,\n layoutResult: Required<LayoutResult>\n ) {\n const { target } = context;\n const {\n result: { size },\n nextCenter,\n } = layoutResult;\n // set dimensions\n target.set({ width: size.x, height: size.y });\n // layout descendants\n this.layoutObjects(context, layoutResult);\n // set position\n // in `initialization` we do not account for target's transformation matrix\n if (context.type === LAYOUT_TYPE_INITIALIZATION) {\n // TODO: what about strokeWidth?\n target.set({\n left:\n context.x ?? nextCenter.x + size.x * resolveOrigin(target.originX),\n top: context.y ?? nextCenter.y + size.y * resolveOrigin(target.originY),\n });\n } else {\n target.setPositionByOrigin(nextCenter, CENTER, CENTER);\n // invalidate\n target.setCoords();\n target.set('dirty', true);\n }\n }\n\n protected layoutObjects(\n context: StrictLayoutContext,\n layoutResult: Required<LayoutResult>\n ) {\n const { target } = context;\n // adjust objects to account for new center\n target.forEachObject((object) => {\n object.group === target &&\n this.layoutObject(context, layoutResult, object);\n });\n // adjust clip path to account for new center\n context.strategy.shouldLayoutClipPath(context) &&\n this.layoutObject(context, layoutResult, target.clipPath as FabricObject);\n }\n\n /**\n * @param {FabricObject} object\n * @param {Point} offset\n */\n protected layoutObject(\n context: StrictLayoutContext,\n { offset }: Required<LayoutResult>,\n object: FabricObject\n ) {\n // TODO: this is here for cache invalidation.\n // verify if this is necessary since we have explicit\n // cache invalidation at the end of commitLayout\n object.set({\n left: object.left + offset.x,\n top: object.top + offset.y,\n });\n }\n\n protected onAfterLayout(\n context: StrictLayoutContext,\n layoutResult?: LayoutResult\n ) {\n const {\n target,\n strategy,\n bubbles,\n prevStrategy: _,\n ...bubblingContext\n } = context;\n const { canvas } = target;\n\n // fire layout event (event will fire only for layouts after initialization layout)\n target.fire('layout:after', {\n context,\n result: layoutResult,\n });\n canvas &&\n canvas.fire('object:layout:after', {\n context,\n result: layoutResult,\n target,\n });\n\n // bubble\n const parent = target.parent;\n if (bubbles && parent?.layoutManager) {\n // add target to context#path\n (bubblingContext.path || (bubblingContext.path = [])).push(target);\n // all parents should invalidate their layout\n parent.layoutManager.performLayout({\n ...bubblingContext,\n target: parent,\n });\n }\n target.set('dirty', true);\n }\n\n dispose() {\n const { _subscriptions } = this;\n _subscriptions.forEach((disposers) => disposers.forEach((d) => d()));\n _subscriptions.clear();\n }\n\n toObject() {\n return {\n type: LAYOUT_MANAGER,\n strategy: (this.strategy.constructor as typeof LayoutStrategy).type,\n };\n }\n\n toJSON() {\n return this.toObject();\n }\n}\n\nclassRegistry.setClass(LayoutManager, LAYOUT_MANAGER);\n"],"names":["LAYOUT_MANAGER","LayoutManager","constructor","strategy","arguments","length","undefined","FitContentLayout","_defineProperty","this","_subscriptions","Map","performLayout","context","strictContext","_objectSpread","bubbles","prevStrategy","_prevLayoutStrategy","stopPropagation","onBeforeLayout","layoutResult","getLayoutResult","commitLayout","onAfterLayout","attachHandlers","object","target","MODIFIED","MOVING","RESIZING","ROTATING","SCALING","SKEWING","CHANGED","MODIFY_POLY","map","key","on","e","type","LAYOUT_TYPE_OBJECT_MODIFIED","trigger","LAYOUT_TYPE_OBJECT_MODIFYING","subscribe","unsubscribe","disposers","set","get","forEach","d","delete","unsubscribeTargets","targets","subscribeTargets","canvas","LAYOUT_TYPE_INITIALIZATION","LAYOUT_TYPE_ADDED","LAYOUT_TYPE_REMOVED","fire","LAYOUT_TYPE_IMPERATIVE","deep","tricklingContext","_objectWithoutProperties","_excluded","forEachObject","layoutManager","result","calcLayoutResult","getObjects","prevCenter","Point","getRelativeCenterPoint","center","nextCenter","correction","relativeCorrection","offset","subtract","add","transform","iMatrix","invertTransform","calcOwnMatrix","size","_context$x","_context$y","width","x","height","y","layoutObjects","left","resolveOrigin","originX","top","originY","setPositionByOrigin","CENTER","setCoords","group","layoutObject","shouldLayoutClipPath","clipPath","_ref","_","bubblingContext","_excluded2","parent","path","push","dispose","clear","toObject","toJSON","classRegistry","setClass"],"mappings":"m3BAoCMA,EAAiB,gBAOhB,MAAMC,EAMXC,WAAAA,GAA+D,IAAnDC,EAAwBC,UAAAC,OAAAD,QAAAE,IAAAF,UAAAE,GAAAF,UAAA,GAAG,IAAIG,EAAkBC,EAAAC,KAAA,gBAAA,GAC3DA,KAAKN,SAAWA,EAChBM,KAAKC,eAAiB,IAAIC,GAC5B,CAEOC,aAAAA,CAAcC,GACnB,MAAMC,EAAkCC,EAAAA,EAAA,CACtCC,SAAS,E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AASD,YAAsCsC,KAEnE,CAEA0E,MAAAA,GACE,OAAOzG,KAAKwG,UACd,EAGFE,EAAcC,SAASnH,EAAeD"}
|
|
1
|
+
{"version":3,"file":"LayoutManager.min.mjs","sources":["../../../src/LayoutManager/LayoutManager.ts"],"sourcesContent":["import { Point } from '../Point';\nimport {\n CENTER,\n CHANGED,\n MODIFIED,\n MODIFY_PATH,\n MODIFY_POLY,\n MOVING,\n RESIZING,\n ROTATING,\n SCALING,\n SKEWING,\n iMatrix,\n} from '../constants';\nimport type { Group } from '../shapes/Group';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport { invertTransform } from '../util/misc/matrix';\nimport { resolveOrigin } from '../util/misc/resolveOrigin';\nimport { FitContentLayout } from './LayoutStrategies/FitContentLayout';\nimport type { LayoutStrategy } from './LayoutStrategies/LayoutStrategy';\nimport {\n LAYOUT_TYPE_INITIALIZATION,\n LAYOUT_TYPE_ADDED,\n LAYOUT_TYPE_REMOVED,\n LAYOUT_TYPE_IMPERATIVE,\n LAYOUT_TYPE_OBJECT_MODIFIED,\n LAYOUT_TYPE_OBJECT_MODIFYING,\n} from './constants';\nimport type {\n LayoutContext,\n LayoutResult,\n RegistrationContext,\n StrictLayoutContext,\n} from './types';\nimport { classRegistry } from '../ClassRegistry';\nimport type { TModificationEvents } from '../EventTypeDefs';\n\nconst LAYOUT_MANAGER = 'layoutManager';\n\nexport type SerializedLayoutManager = {\n type: string;\n strategy: string;\n};\n\nexport class LayoutManager {\n private declare _prevLayoutStrategy?: LayoutStrategy;\n protected declare _subscriptions: Map<FabricObject, VoidFunction[]>;\n\n strategy: LayoutStrategy;\n\n constructor(strategy: LayoutStrategy = new FitContentLayout()) {\n this.strategy = strategy;\n this._subscriptions = new Map();\n }\n\n public performLayout(context: LayoutContext) {\n const strictContext: StrictLayoutContext = {\n bubbles: true,\n strategy: this.strategy,\n ...context,\n prevStrategy: this._prevLayoutStrategy,\n stopPropagation() {\n this.bubbles = false;\n },\n };\n\n this.onBeforeLayout(strictContext);\n\n const layoutResult = this.getLayoutResult(strictContext);\n if (layoutResult) {\n this.commitLayout(strictContext, layoutResult);\n }\n\n this.onAfterLayout(strictContext, layoutResult);\n this._prevLayoutStrategy = strictContext.strategy;\n }\n\n /**\n * Attach handlers for events that we know will invalidate the layout when\n * performed on child objects ( general transforms ).\n * Returns the disposers for later unsubscribing and cleanup\n * @param {FabricObject} object\n * @param {RegistrationContext & Partial<StrictLayoutContext>} context\n * @returns {VoidFunction[]} disposers remove the handlers\n */\n protected attachHandlers(\n object: FabricObject,\n context: RegistrationContext & Partial<StrictLayoutContext>\n ): VoidFunction[] {\n const { target } = context;\n return (\n [\n MODIFIED,\n MOVING,\n RESIZING,\n ROTATING,\n SCALING,\n SKEWING,\n CHANGED,\n MODIFY_POLY,\n MODIFY_PATH,\n ] as (TModificationEvents & 'modified')[]\n ).map((key) =>\n object.on(key, (e) =>\n this.performLayout(\n key === MODIFIED\n ? {\n type: LAYOUT_TYPE_OBJECT_MODIFIED,\n trigger: key,\n e,\n target,\n }\n : {\n type: LAYOUT_TYPE_OBJECT_MODIFYING,\n trigger: key,\n e,\n target,\n }\n )\n )\n );\n }\n\n /**\n * Subscribe an object to transform events that will trigger a layout change on the parent\n * This is important only for interactive groups.\n * @param object\n * @param context\n */\n protected subscribe(\n object: FabricObject,\n context: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n this.unsubscribe(object, context);\n const disposers = this.attachHandlers(object, context);\n this._subscriptions.set(object, disposers);\n }\n\n /**\n * unsubscribe object layout triggers\n */\n protected unsubscribe(\n object: FabricObject,\n context?: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n (this._subscriptions.get(object) || []).forEach((d) => d());\n this._subscriptions.delete(object);\n }\n\n unsubscribeTargets(\n context: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n context.targets.forEach((object) => this.unsubscribe(object, context));\n }\n\n subscribeTargets(\n context: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n context.targets.forEach((object) => this.subscribe(object, context));\n }\n\n protected onBeforeLayout(context: StrictLayoutContext) {\n const { target, type } = context;\n const { canvas } = target;\n // handle layout triggers subscription\n // @TODO: gate the registration when the group is interactive\n if (type === LAYOUT_TYPE_INITIALIZATION || type === LAYOUT_TYPE_ADDED) {\n this.subscribeTargets(context);\n } else if (type === LAYOUT_TYPE_REMOVED) {\n this.unsubscribeTargets(context);\n }\n // fire layout event (event will fire only for layouts after initialization layout)\n target.fire('layout:before', {\n context,\n });\n canvas &&\n canvas.fire('object:layout:before', {\n target,\n context,\n });\n\n if (type === LAYOUT_TYPE_IMPERATIVE && context.deep) {\n const { strategy: _, ...tricklingContext } = context;\n // traverse the tree\n target.forEachObject(\n (object) =>\n (object as Group).layoutManager &&\n (object as Group).layoutManager.performLayout({\n ...tricklingContext,\n bubbles: false,\n target: object as Group,\n })\n );\n }\n }\n\n protected getLayoutResult(\n context: StrictLayoutContext\n ): Required<LayoutResult> | undefined {\n const { target, strategy, type } = context;\n\n const result = strategy.calcLayoutResult(context, target.getObjects());\n\n if (!result) {\n return;\n }\n\n const prevCenter =\n type === LAYOUT_TYPE_INITIALIZATION\n ? new Point()\n : target.getRelativeCenterPoint();\n\n const {\n center: nextCenter,\n correction = new Point(),\n relativeCorrection = new Point(),\n } = result;\n const offset = prevCenter\n .subtract(nextCenter)\n .add(correction)\n .transform(\n // in `initialization` we do not account for target's transformation matrix\n type === LAYOUT_TYPE_INITIALIZATION\n ? iMatrix\n : invertTransform(target.calcOwnMatrix()),\n true\n )\n .add(relativeCorrection);\n\n return {\n result,\n prevCenter,\n nextCenter,\n offset,\n };\n }\n\n protected commitLayout(\n context: StrictLayoutContext,\n layoutResult: Required<LayoutResult>\n ) {\n const { target } = context;\n const {\n result: { size },\n nextCenter,\n } = layoutResult;\n // set dimensions\n target.set({ width: size.x, height: size.y });\n // layout descendants\n this.layoutObjects(context, layoutResult);\n // set position\n // in `initialization` we do not account for target's transformation matrix\n if (context.type === LAYOUT_TYPE_INITIALIZATION) {\n // TODO: what about strokeWidth?\n target.set({\n left:\n context.x ?? nextCenter.x + size.x * resolveOrigin(target.originX),\n top: context.y ?? nextCenter.y + size.y * resolveOrigin(target.originY),\n });\n } else {\n target.setPositionByOrigin(nextCenter, CENTER, CENTER);\n // invalidate\n target.setCoords();\n target.set('dirty', true);\n }\n }\n\n protected layoutObjects(\n context: StrictLayoutContext,\n layoutResult: Required<LayoutResult>\n ) {\n const { target } = context;\n // adjust objects to account for new center\n target.forEachObject((object) => {\n object.group === target &&\n this.layoutObject(context, layoutResult, object);\n });\n // adjust clip path to account for new center\n context.strategy.shouldLayoutClipPath(context) &&\n this.layoutObject(context, layoutResult, target.clipPath as FabricObject);\n }\n\n /**\n * @param {FabricObject} object\n * @param {Point} offset\n */\n protected layoutObject(\n context: StrictLayoutContext,\n { offset }: Required<LayoutResult>,\n object: FabricObject\n ) {\n // TODO: this is here for cache invalidation.\n // verify if this is necessary since we have explicit\n // cache invalidation at the end of commitLayout\n object.set({\n left: object.left + offset.x,\n top: object.top + offset.y,\n });\n }\n\n protected onAfterLayout(\n context: StrictLayoutContext,\n layoutResult?: LayoutResult\n ) {\n const {\n target,\n strategy,\n bubbles,\n prevStrategy: _,\n ...bubblingContext\n } = context;\n const { canvas } = target;\n\n // fire layout event (event will fire only for layouts after initialization layout)\n target.fire('layout:after', {\n context,\n result: layoutResult,\n });\n canvas &&\n canvas.fire('object:layout:after', {\n context,\n result: layoutResult,\n target,\n });\n\n // bubble\n const parent = target.parent;\n if (bubbles && parent?.layoutManager) {\n // add target to context#path\n (bubblingContext.path || (bubblingContext.path = [])).push(target);\n // all parents should invalidate their layout\n parent.layoutManager.performLayout({\n ...bubblingContext,\n target: parent,\n });\n }\n target.set('dirty', true);\n }\n\n dispose() {\n const { _subscriptions } = this;\n _subscriptions.forEach((disposers) => disposers.forEach((d) => d()));\n _subscriptions.clear();\n }\n\n toObject() {\n return {\n type: LAYOUT_MANAGER,\n strategy: (this.strategy.constructor as typeof LayoutStrategy).type,\n };\n }\n\n toJSON() {\n return this.toObject();\n }\n}\n\nclassRegistry.setClass(LayoutManager, LAYOUT_MANAGER);\n"],"names":["LAYOUT_MANAGER","LayoutManager","constructor","strategy","arguments","length","undefined","FitContentLayout","_defineProperty","this","_subscriptions","Map","performLayout","context","strictContext","_objectSpread","bubbles","prevStrategy","_prevLayoutStrategy","stopPropagation","onBeforeLayout","layoutResult","getLayoutResult","commitLayout","onAfterLayout","attachHandlers","object","target","MODIFIED","MOVING","RESIZING","ROTATING","SCALING","SKEWING","CHANGED","MODIFY_POLY","MODIFY_PATH","map","key","on","e","type","LAYOUT_TYPE_OBJECT_MODIFIED","trigger","LAYOUT_TYPE_OBJECT_MODIFYING","subscribe","unsubscribe","disposers","set","get","forEach","d","delete","unsubscribeTargets","targets","subscribeTargets","canvas","LAYOUT_TYPE_INITIALIZATION","LAYOUT_TYPE_ADDED","LAYOUT_TYPE_REMOVED","fire","LAYOUT_TYPE_IMPERATIVE","deep","tricklingContext","_objectWithoutProperties","_excluded","forEachObject","layoutManager","result","calcLayoutResult","getObjects","prevCenter","Point","getRelativeCenterPoint","center","nextCenter","correction","relativeCorrection","offset","subtract","add","transform","iMatrix","invertTransform","calcOwnMatrix","size","_context$x","_context$y","width","x","height","y","layoutObjects","left","resolveOrigin","originX","top","originY","setPositionByOrigin","CENTER","setCoords","group","layoutObject","shouldLayoutClipPath","clipPath","_ref","_","bubblingContext","_excluded2","parent","path","push","dispose","clear","toObject","toJSON","classRegistry","setClass"],"mappings":"o4BAqCMA,EAAiB,gBAOhB,MAAMC,EAMXC,WAAAA,GAA+D,IAAnDC,EAAwBC,UAAAC,OAAAD,QAAAE,IAAAF,UAAAE,GAAAF,UAAA,GAAG,IAAIG,EAAkBC,EAAAC,KAAA,gBAAA,GAC3DA,KAAKN,SAAWA,EAChBM,KAAKC,eAAiB,IAAIC,GAC5B,CAEOC,aAAAA,CAAcC,GACnB,MAAMC,EAAkCC,EAAAA,EAAA,CACtCC,SAAS,EACTb,SAAUM,K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YAAsCuC,KAEnE,CAEA0E,MAAAA,GACE,OAAO1G,KAAKyG,UACd,EAGFE,EAAcC,SAASpH,EAAeD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineProperty as _defineProperty, objectSpread2 as _objectSpread2, objectWithoutProperties as _objectWithoutProperties } from '../../_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
2
|
import { Point } from '../Point.mjs';
|
|
3
|
-
import { MODIFIED, MOVING, RESIZING, ROTATING, SCALING, SKEWING, CHANGED, MODIFY_POLY, iMatrix, CENTER } from '../constants.mjs';
|
|
3
|
+
import { MODIFIED, MOVING, RESIZING, ROTATING, SCALING, SKEWING, CHANGED, MODIFY_POLY, MODIFY_PATH, iMatrix, CENTER } from '../constants.mjs';
|
|
4
4
|
import { invertTransform } from '../util/misc/matrix.mjs';
|
|
5
5
|
import { resolveOrigin } from '../util/misc/resolveOrigin.mjs';
|
|
6
6
|
import { FitContentLayout } from './LayoutStrategies/FitContentLayout.mjs';
|
|
@@ -48,7 +48,7 @@ class LayoutManager {
|
|
|
48
48
|
const {
|
|
49
49
|
target
|
|
50
50
|
} = context;
|
|
51
|
-
return [MODIFIED, MOVING, RESIZING, ROTATING, SCALING, SKEWING, CHANGED, MODIFY_POLY].map(key => object.on(key, e => this.performLayout(key === MODIFIED ? {
|
|
51
|
+
return [MODIFIED, MOVING, RESIZING, ROTATING, SCALING, SKEWING, CHANGED, MODIFY_POLY, MODIFY_PATH].map(key => object.on(key, e => this.performLayout(key === MODIFIED ? {
|
|
52
52
|
type: LAYOUT_TYPE_OBJECT_MODIFIED,
|
|
53
53
|
trigger: key,
|
|
54
54
|
e,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LayoutManager.mjs","sources":["../../../src/LayoutManager/LayoutManager.ts"],"sourcesContent":["import { Point } from '../Point';\nimport {\n CENTER,\n CHANGED,\n MODIFIED,\n MODIFY_POLY,\n MOVING,\n RESIZING,\n ROTATING,\n SCALING,\n SKEWING,\n iMatrix,\n} from '../constants';\nimport type { Group } from '../shapes/Group';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport { invertTransform } from '../util/misc/matrix';\nimport { resolveOrigin } from '../util/misc/resolveOrigin';\nimport { FitContentLayout } from './LayoutStrategies/FitContentLayout';\nimport type { LayoutStrategy } from './LayoutStrategies/LayoutStrategy';\nimport {\n LAYOUT_TYPE_INITIALIZATION,\n LAYOUT_TYPE_ADDED,\n LAYOUT_TYPE_REMOVED,\n LAYOUT_TYPE_IMPERATIVE,\n LAYOUT_TYPE_OBJECT_MODIFIED,\n LAYOUT_TYPE_OBJECT_MODIFYING,\n} from './constants';\nimport type {\n LayoutContext,\n LayoutResult,\n RegistrationContext,\n StrictLayoutContext,\n} from './types';\nimport { classRegistry } from '../ClassRegistry';\nimport type { TModificationEvents } from '../EventTypeDefs';\n\nconst LAYOUT_MANAGER = 'layoutManager';\n\nexport type SerializedLayoutManager = {\n type: string;\n strategy: string;\n};\n\nexport class LayoutManager {\n private declare _prevLayoutStrategy?: LayoutStrategy;\n protected declare _subscriptions: Map<FabricObject, VoidFunction[]>;\n\n strategy: LayoutStrategy;\n\n constructor(strategy: LayoutStrategy = new FitContentLayout()) {\n this.strategy = strategy;\n this._subscriptions = new Map();\n }\n\n public performLayout(context: LayoutContext) {\n const strictContext: StrictLayoutContext = {\n bubbles: true,\n strategy: this.strategy,\n ...context,\n prevStrategy: this._prevLayoutStrategy,\n stopPropagation() {\n this.bubbles = false;\n },\n };\n\n this.onBeforeLayout(strictContext);\n\n const layoutResult = this.getLayoutResult(strictContext);\n if (layoutResult) {\n this.commitLayout(strictContext, layoutResult);\n }\n\n this.onAfterLayout(strictContext, layoutResult);\n this._prevLayoutStrategy = strictContext.strategy;\n }\n\n /**\n * Attach handlers for events that we know will invalidate the layout when\n * performed on child objects ( general transforms ).\n * Returns the disposers for later unsubscribing and cleanup\n * @param {FabricObject} object\n * @param {RegistrationContext & Partial<StrictLayoutContext>} context\n * @returns {VoidFunction[]} disposers remove the handlers\n */\n protected attachHandlers(\n object: FabricObject,\n context: RegistrationContext & Partial<StrictLayoutContext>\n ): VoidFunction[] {\n const { target } = context;\n return (\n [\n MODIFIED,\n MOVING,\n RESIZING,\n ROTATING,\n SCALING,\n SKEWING,\n CHANGED,\n MODIFY_POLY,\n ] as (TModificationEvents & 'modified')[]\n ).map((key) =>\n object.on(key, (e) =>\n this.performLayout(\n key === MODIFIED\n ? {\n type: LAYOUT_TYPE_OBJECT_MODIFIED,\n trigger: key,\n e,\n target,\n }\n : {\n type: LAYOUT_TYPE_OBJECT_MODIFYING,\n trigger: key,\n e,\n target,\n }\n )\n )\n );\n }\n\n /**\n * Subscribe an object to transform events that will trigger a layout change on the parent\n * This is important only for interactive groups.\n * @param object\n * @param context\n */\n protected subscribe(\n object: FabricObject,\n context: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n this.unsubscribe(object, context);\n const disposers = this.attachHandlers(object, context);\n this._subscriptions.set(object, disposers);\n }\n\n /**\n * unsubscribe object layout triggers\n */\n protected unsubscribe(\n object: FabricObject,\n context?: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n (this._subscriptions.get(object) || []).forEach((d) => d());\n this._subscriptions.delete(object);\n }\n\n unsubscribeTargets(\n context: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n context.targets.forEach((object) => this.unsubscribe(object, context));\n }\n\n subscribeTargets(\n context: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n context.targets.forEach((object) => this.subscribe(object, context));\n }\n\n protected onBeforeLayout(context: StrictLayoutContext) {\n const { target, type } = context;\n const { canvas } = target;\n // handle layout triggers subscription\n // @TODO: gate the registration when the group is interactive\n if (type === LAYOUT_TYPE_INITIALIZATION || type === LAYOUT_TYPE_ADDED) {\n this.subscribeTargets(context);\n } else if (type === LAYOUT_TYPE_REMOVED) {\n this.unsubscribeTargets(context);\n }\n // fire layout event (event will fire only for layouts after initialization layout)\n target.fire('layout:before', {\n context,\n });\n canvas &&\n canvas.fire('object:layout:before', {\n target,\n context,\n });\n\n if (type === LAYOUT_TYPE_IMPERATIVE && context.deep) {\n const { strategy: _, ...tricklingContext } = context;\n // traverse the tree\n target.forEachObject(\n (object) =>\n (object as Group).layoutManager &&\n (object as Group).layoutManager.performLayout({\n ...tricklingContext,\n bubbles: false,\n target: object as Group,\n })\n );\n }\n }\n\n protected getLayoutResult(\n context: StrictLayoutContext\n ): Required<LayoutResult> | undefined {\n const { target, strategy, type } = context;\n\n const result = strategy.calcLayoutResult(context, target.getObjects());\n\n if (!result) {\n return;\n }\n\n const prevCenter =\n type === LAYOUT_TYPE_INITIALIZATION\n ? new Point()\n : target.getRelativeCenterPoint();\n\n const {\n center: nextCenter,\n correction = new Point(),\n relativeCorrection = new Point(),\n } = result;\n const offset = prevCenter\n .subtract(nextCenter)\n .add(correction)\n .transform(\n // in `initialization` we do not account for target's transformation matrix\n type === LAYOUT_TYPE_INITIALIZATION\n ? iMatrix\n : invertTransform(target.calcOwnMatrix()),\n true\n )\n .add(relativeCorrection);\n\n return {\n result,\n prevCenter,\n nextCenter,\n offset,\n };\n }\n\n protected commitLayout(\n context: StrictLayoutContext,\n layoutResult: Required<LayoutResult>\n ) {\n const { target } = context;\n const {\n result: { size },\n nextCenter,\n } = layoutResult;\n // set dimensions\n target.set({ width: size.x, height: size.y });\n // layout descendants\n this.layoutObjects(context, layoutResult);\n // set position\n // in `initialization` we do not account for target's transformation matrix\n if (context.type === LAYOUT_TYPE_INITIALIZATION) {\n // TODO: what about strokeWidth?\n target.set({\n left:\n context.x ?? nextCenter.x + size.x * resolveOrigin(target.originX),\n top: context.y ?? nextCenter.y + size.y * resolveOrigin(target.originY),\n });\n } else {\n target.setPositionByOrigin(nextCenter, CENTER, CENTER);\n // invalidate\n target.setCoords();\n target.set('dirty', true);\n }\n }\n\n protected layoutObjects(\n context: StrictLayoutContext,\n layoutResult: Required<LayoutResult>\n ) {\n const { target } = context;\n // adjust objects to account for new center\n target.forEachObject((object) => {\n object.group === target &&\n this.layoutObject(context, layoutResult, object);\n });\n // adjust clip path to account for new center\n context.strategy.shouldLayoutClipPath(context) &&\n this.layoutObject(context, layoutResult, target.clipPath as FabricObject);\n }\n\n /**\n * @param {FabricObject} object\n * @param {Point} offset\n */\n protected layoutObject(\n context: StrictLayoutContext,\n { offset }: Required<LayoutResult>,\n object: FabricObject\n ) {\n // TODO: this is here for cache invalidation.\n // verify if this is necessary since we have explicit\n // cache invalidation at the end of commitLayout\n object.set({\n left: object.left + offset.x,\n top: object.top + offset.y,\n });\n }\n\n protected onAfterLayout(\n context: StrictLayoutContext,\n layoutResult?: LayoutResult\n ) {\n const {\n target,\n strategy,\n bubbles,\n prevStrategy: _,\n ...bubblingContext\n } = context;\n const { canvas } = target;\n\n // fire layout event (event will fire only for layouts after initialization layout)\n target.fire('layout:after', {\n context,\n result: layoutResult,\n });\n canvas &&\n canvas.fire('object:layout:after', {\n context,\n result: layoutResult,\n target,\n });\n\n // bubble\n const parent = target.parent;\n if (bubbles && parent?.layoutManager) {\n // add target to context#path\n (bubblingContext.path || (bubblingContext.path = [])).push(target);\n // all parents should invalidate their layout\n parent.layoutManager.performLayout({\n ...bubblingContext,\n target: parent,\n });\n }\n target.set('dirty', true);\n }\n\n dispose() {\n const { _subscriptions } = this;\n _subscriptions.forEach((disposers) => disposers.forEach((d) => d()));\n _subscriptions.clear();\n }\n\n toObject() {\n return {\n type: LAYOUT_MANAGER,\n strategy: (this.strategy.constructor as typeof LayoutStrategy).type,\n };\n }\n\n toJSON() {\n return this.toObject();\n }\n}\n\nclassRegistry.setClass(LayoutManager, LAYOUT_MANAGER);\n"],"names":["LAYOUT_MANAGER","LayoutManager","constructor","strategy","arguments","length","undefined","FitContentLayout","_defineProperty","_subscriptions","Map","performLayout","context","strictContext","_objectSpread","bubbles","prevStrategy","_prevLayoutStrategy","stopPropagation","onBeforeLayout","layoutResult","getLayoutResult","commitLayout","onAfterLayout","attachHandlers","object","target","MODIFIED","MOVING","RESIZING","ROTATING","SCALING","SKEWING","CHANGED","MODIFY_POLY","map","key","on","e","type","LAYOUT_TYPE_OBJECT_MODIFIED","trigger","LAYOUT_TYPE_OBJECT_MODIFYING","subscribe","unsubscribe","disposers","set","get","forEach","d","delete","unsubscribeTargets","targets","subscribeTargets","canvas","LAYOUT_TYPE_INITIALIZATION","LAYOUT_TYPE_ADDED","LAYOUT_TYPE_REMOVED","fire","LAYOUT_TYPE_IMPERATIVE","deep","tricklingContext","_objectWithoutProperties","_excluded","forEachObject","layoutManager","result","calcLayoutResult","getObjects","prevCenter","Point","getRelativeCenterPoint","center","nextCenter","correction","relativeCorrection","offset","subtract","add","transform","iMatrix","invertTransform","calcOwnMatrix","size","width","x","height","y","layoutObjects","_context$x","_context$y","left","resolveOrigin","originX","top","originY","setPositionByOrigin","CENTER","setCoords","group","layoutObject","shouldLayoutClipPath","clipPath","_ref","_","bubblingContext","_excluded2","parent","path","push","dispose","clear","toObject","toJSON","classRegistry","setClass"],"mappings":";;;;;;;;;;;AAoCA,MAAMA,cAAc,GAAG,eAAe,CAAA;AAO/B,MAAMC,aAAa,CAAC;AAMzBC,EAAAA,WAAWA,GAAoD;AAAA,IAAA,IAAnDC,QAAwB,GAAAC,SAAA,CAAAC,MAAA,GAAAD,CAAAA,IAAAA,SAAA,CAAAE,CAAAA,CAAAA,KAAAA,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,IAAIG,gBAAgB,EAAE,CAAA;IAAAC,eAAA,CAAA,IAAA,EAAA,UAAA,EAAA,KAAA,CAAA,CAAA,CAAA;IAC3D,IAAI,CAACL,QAAQ,GAAGA,QAAQ,CAAA;AACxB,IAAA,IAAI,CAACM,cAAc,GAAG,IAAIC,GAAG,EAAE,CAAA;AACjC,GAAA;EAEOC,aAAaA,CAACC,OAAsB,EAAE;AAC3C,IAAA,MAAMC,aAAkC,GAAAC,cAAA,CAAAA,cAAA,CAAA;AACtCC,MAAAA,OAAO,EAAE,IAAI;MACbZ,QAAQ,EAAE,IAAI,CAACA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A,CAACwC,eAAe,CAACG,IAAI,KAAKH,eAAe,CAACG,IAAI,GAAG,EAAE,CAAC,EAAEC,IAAI,CAACnF,MAAM,CAAC,CAAA;AAClE;MACAiF,MAAM,CAAC1C,aAAa,CAACtD,aAAa,CAAAG,cAAA,CAAAA,cAAA,CAAA,EAAA,EAC7B2F,eAAe,CAAA,EAAA,EAAA,EAAA;AAClB/E,QAAAA,MAAM,EAAEiF,MAAAA;AAAM,OAAA,CACf,CAAC,CAAA;AACJ,KAAA;AACAjF,IAAAA,MAAM,CAACoB,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AAC3B,GAAA;AAEAgE,EAAAA,OAAOA,GAAG;IACR,MAAM;AAAErG,MAAAA,cAAAA;AAAe,KAAC,GAAG,IAAI,CAAA;AAC/BA,IAAAA,cAAc,CAACuC,OAAO,CAAEH,SAAS,IAAKA,SAAS,CAACG,OAAO,CAAEC,CAAC,IAAKA,CAAC,EAAE,CAAC,CAAC,CAAA;IACpExC,cAAc,CAACsG,KAAK,EAAE,CAAA;AACxB,GAAA;AAEAC,EAAAA,QAAQA,GAAG;IACT,OAAO;AACLzE,MAAAA,IAAI,EAAEvC,cAAc;AACpBG,MAAAA,QAAQ,EAAG,IAAI,CAACA,QAAQ,CAACD,WAAW,CAA2BqC,IAAAA;KAChE,CAAA;AACH,GAAA;AAEA0E,EAAAA,MAAMA,GAAG;AACP,IAAA,OAAO,IAAI,CAACD,QAAQ,EAAE,CAAA;AACxB,GAAA;AACF,CAAA;AAEAE,aAAa,CAACC,QAAQ,CAAClH,aAAa,EAAED,cAAc,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"LayoutManager.mjs","sources":["../../../src/LayoutManager/LayoutManager.ts"],"sourcesContent":["import { Point } from '../Point';\nimport {\n CENTER,\n CHANGED,\n MODIFIED,\n MODIFY_PATH,\n MODIFY_POLY,\n MOVING,\n RESIZING,\n ROTATING,\n SCALING,\n SKEWING,\n iMatrix,\n} from '../constants';\nimport type { Group } from '../shapes/Group';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport { invertTransform } from '../util/misc/matrix';\nimport { resolveOrigin } from '../util/misc/resolveOrigin';\nimport { FitContentLayout } from './LayoutStrategies/FitContentLayout';\nimport type { LayoutStrategy } from './LayoutStrategies/LayoutStrategy';\nimport {\n LAYOUT_TYPE_INITIALIZATION,\n LAYOUT_TYPE_ADDED,\n LAYOUT_TYPE_REMOVED,\n LAYOUT_TYPE_IMPERATIVE,\n LAYOUT_TYPE_OBJECT_MODIFIED,\n LAYOUT_TYPE_OBJECT_MODIFYING,\n} from './constants';\nimport type {\n LayoutContext,\n LayoutResult,\n RegistrationContext,\n StrictLayoutContext,\n} from './types';\nimport { classRegistry } from '../ClassRegistry';\nimport type { TModificationEvents } from '../EventTypeDefs';\n\nconst LAYOUT_MANAGER = 'layoutManager';\n\nexport type SerializedLayoutManager = {\n type: string;\n strategy: string;\n};\n\nexport class LayoutManager {\n private declare _prevLayoutStrategy?: LayoutStrategy;\n protected declare _subscriptions: Map<FabricObject, VoidFunction[]>;\n\n strategy: LayoutStrategy;\n\n constructor(strategy: LayoutStrategy = new FitContentLayout()) {\n this.strategy = strategy;\n this._subscriptions = new Map();\n }\n\n public performLayout(context: LayoutContext) {\n const strictContext: StrictLayoutContext = {\n bubbles: true,\n strategy: this.strategy,\n ...context,\n prevStrategy: this._prevLayoutStrategy,\n stopPropagation() {\n this.bubbles = false;\n },\n };\n\n this.onBeforeLayout(strictContext);\n\n const layoutResult = this.getLayoutResult(strictContext);\n if (layoutResult) {\n this.commitLayout(strictContext, layoutResult);\n }\n\n this.onAfterLayout(strictContext, layoutResult);\n this._prevLayoutStrategy = strictContext.strategy;\n }\n\n /**\n * Attach handlers for events that we know will invalidate the layout when\n * performed on child objects ( general transforms ).\n * Returns the disposers for later unsubscribing and cleanup\n * @param {FabricObject} object\n * @param {RegistrationContext & Partial<StrictLayoutContext>} context\n * @returns {VoidFunction[]} disposers remove the handlers\n */\n protected attachHandlers(\n object: FabricObject,\n context: RegistrationContext & Partial<StrictLayoutContext>\n ): VoidFunction[] {\n const { target } = context;\n return (\n [\n MODIFIED,\n MOVING,\n RESIZING,\n ROTATING,\n SCALING,\n SKEWING,\n CHANGED,\n MODIFY_POLY,\n MODIFY_PATH,\n ] as (TModificationEvents & 'modified')[]\n ).map((key) =>\n object.on(key, (e) =>\n this.performLayout(\n key === MODIFIED\n ? {\n type: LAYOUT_TYPE_OBJECT_MODIFIED,\n trigger: key,\n e,\n target,\n }\n : {\n type: LAYOUT_TYPE_OBJECT_MODIFYING,\n trigger: key,\n e,\n target,\n }\n )\n )\n );\n }\n\n /**\n * Subscribe an object to transform events that will trigger a layout change on the parent\n * This is important only for interactive groups.\n * @param object\n * @param context\n */\n protected subscribe(\n object: FabricObject,\n context: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n this.unsubscribe(object, context);\n const disposers = this.attachHandlers(object, context);\n this._subscriptions.set(object, disposers);\n }\n\n /**\n * unsubscribe object layout triggers\n */\n protected unsubscribe(\n object: FabricObject,\n context?: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n (this._subscriptions.get(object) || []).forEach((d) => d());\n this._subscriptions.delete(object);\n }\n\n unsubscribeTargets(\n context: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n context.targets.forEach((object) => this.unsubscribe(object, context));\n }\n\n subscribeTargets(\n context: RegistrationContext & Partial<StrictLayoutContext>\n ) {\n context.targets.forEach((object) => this.subscribe(object, context));\n }\n\n protected onBeforeLayout(context: StrictLayoutContext) {\n const { target, type } = context;\n const { canvas } = target;\n // handle layout triggers subscription\n // @TODO: gate the registration when the group is interactive\n if (type === LAYOUT_TYPE_INITIALIZATION || type === LAYOUT_TYPE_ADDED) {\n this.subscribeTargets(context);\n } else if (type === LAYOUT_TYPE_REMOVED) {\n this.unsubscribeTargets(context);\n }\n // fire layout event (event will fire only for layouts after initialization layout)\n target.fire('layout:before', {\n context,\n });\n canvas &&\n canvas.fire('object:layout:before', {\n target,\n context,\n });\n\n if (type === LAYOUT_TYPE_IMPERATIVE && context.deep) {\n const { strategy: _, ...tricklingContext } = context;\n // traverse the tree\n target.forEachObject(\n (object) =>\n (object as Group).layoutManager &&\n (object as Group).layoutManager.performLayout({\n ...tricklingContext,\n bubbles: false,\n target: object as Group,\n })\n );\n }\n }\n\n protected getLayoutResult(\n context: StrictLayoutContext\n ): Required<LayoutResult> | undefined {\n const { target, strategy, type } = context;\n\n const result = strategy.calcLayoutResult(context, target.getObjects());\n\n if (!result) {\n return;\n }\n\n const prevCenter =\n type === LAYOUT_TYPE_INITIALIZATION\n ? new Point()\n : target.getRelativeCenterPoint();\n\n const {\n center: nextCenter,\n correction = new Point(),\n relativeCorrection = new Point(),\n } = result;\n const offset = prevCenter\n .subtract(nextCenter)\n .add(correction)\n .transform(\n // in `initialization` we do not account for target's transformation matrix\n type === LAYOUT_TYPE_INITIALIZATION\n ? iMatrix\n : invertTransform(target.calcOwnMatrix()),\n true\n )\n .add(relativeCorrection);\n\n return {\n result,\n prevCenter,\n nextCenter,\n offset,\n };\n }\n\n protected commitLayout(\n context: StrictLayoutContext,\n layoutResult: Required<LayoutResult>\n ) {\n const { target } = context;\n const {\n result: { size },\n nextCenter,\n } = layoutResult;\n // set dimensions\n target.set({ width: size.x, height: size.y });\n // layout descendants\n this.layoutObjects(context, layoutResult);\n // set position\n // in `initialization` we do not account for target's transformation matrix\n if (context.type === LAYOUT_TYPE_INITIALIZATION) {\n // TODO: what about strokeWidth?\n target.set({\n left:\n context.x ?? nextCenter.x + size.x * resolveOrigin(target.originX),\n top: context.y ?? nextCenter.y + size.y * resolveOrigin(target.originY),\n });\n } else {\n target.setPositionByOrigin(nextCenter, CENTER, CENTER);\n // invalidate\n target.setCoords();\n target.set('dirty', true);\n }\n }\n\n protected layoutObjects(\n context: StrictLayoutContext,\n layoutResult: Required<LayoutResult>\n ) {\n const { target } = context;\n // adjust objects to account for new center\n target.forEachObject((object) => {\n object.group === target &&\n this.layoutObject(context, layoutResult, object);\n });\n // adjust clip path to account for new center\n context.strategy.shouldLayoutClipPath(context) &&\n this.layoutObject(context, layoutResult, target.clipPath as FabricObject);\n }\n\n /**\n * @param {FabricObject} object\n * @param {Point} offset\n */\n protected layoutObject(\n context: StrictLayoutContext,\n { offset }: Required<LayoutResult>,\n object: FabricObject\n ) {\n // TODO: this is here for cache invalidation.\n // verify if this is necessary since we have explicit\n // cache invalidation at the end of commitLayout\n object.set({\n left: object.left + offset.x,\n top: object.top + offset.y,\n });\n }\n\n protected onAfterLayout(\n context: StrictLayoutContext,\n layoutResult?: LayoutResult\n ) {\n const {\n target,\n strategy,\n bubbles,\n prevStrategy: _,\n ...bubblingContext\n } = context;\n const { canvas } = target;\n\n // fire layout event (event will fire only for layouts after initialization layout)\n target.fire('layout:after', {\n context,\n result: layoutResult,\n });\n canvas &&\n canvas.fire('object:layout:after', {\n context,\n result: layoutResult,\n target,\n });\n\n // bubble\n const parent = target.parent;\n if (bubbles && parent?.layoutManager) {\n // add target to context#path\n (bubblingContext.path || (bubblingContext.path = [])).push(target);\n // all parents should invalidate their layout\n parent.layoutManager.performLayout({\n ...bubblingContext,\n target: parent,\n });\n }\n target.set('dirty', true);\n }\n\n dispose() {\n const { _subscriptions } = this;\n _subscriptions.forEach((disposers) => disposers.forEach((d) => d()));\n _subscriptions.clear();\n }\n\n toObject() {\n return {\n type: LAYOUT_MANAGER,\n strategy: (this.strategy.constructor as typeof LayoutStrategy).type,\n };\n }\n\n toJSON() {\n return this.toObject();\n }\n}\n\nclassRegistry.setClass(LayoutManager, LAYOUT_MANAGER);\n"],"names":["LAYOUT_MANAGER","LayoutManager","constructor","strategy","arguments","length","undefined","FitContentLayout","_defineProperty","_subscriptions","Map","performLayout","context","strictContext","_objectSpread","bubbles","prevStrategy","_prevLayoutStrategy","stopPropagation","onBeforeLayout","layoutResult","getLayoutResult","commitLayout","onAfterLayout","attachHandlers","object","target","MODIFIED","MOVING","RESIZING","ROTATING","SCALING","SKEWING","CHANGED","MODIFY_POLY","MODIFY_PATH","map","key","on","e","type","LAYOUT_TYPE_OBJECT_MODIFIED","trigger","LAYOUT_TYPE_OBJECT_MODIFYING","subscribe","unsubscribe","disposers","set","get","forEach","d","delete","unsubscribeTargets","targets","subscribeTargets","canvas","LAYOUT_TYPE_INITIALIZATION","LAYOUT_TYPE_ADDED","LAYOUT_TYPE_REMOVED","fire","LAYOUT_TYPE_IMPERATIVE","deep","tricklingContext","_objectWithoutProperties","_excluded","forEachObject","layoutManager","result","calcLayoutResult","getObjects","prevCenter","Point","getRelativeCenterPoint","center","nextCenter","correction","relativeCorrection","offset","subtract","add","transform","iMatrix","invertTransform","calcOwnMatrix","size","width","x","height","y","layoutObjects","_context$x","_context$y","left","resolveOrigin","originX","top","originY","setPositionByOrigin","CENTER","setCoords","group","layoutObject","shouldLayoutClipPath","clipPath","_ref","_","bubblingContext","_excluded2","parent","path","push","dispose","clear","toObject","toJSON","classRegistry","setClass"],"mappings":";;;;;;;;;;;AAqCA,MAAMA,cAAc,GAAG,eAAe,CAAA;AAO/B,MAAMC,aAAa,CAAC;AAMzBC,EAAAA,WAAWA,GAAoD;AAAA,IAAA,IAAnDC,QAAwB,GAAAC,SAAA,CAAAC,MAAA,GAAAD,CAAAA,IAAAA,SAAA,CAAAE,CAAAA,CAAAA,KAAAA,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,IAAIG,gBAAgB,EAAE,CAAA;IAAAC,eAAA,CAAA,IAAA,EAAA,UAAA,EAAA,KAAA,CAAA,CAAA,CAAA;IAC3D,IAAI,CAACL,QAAQ,GAAGA,QAAQ,CAAA;AACxB,IAAA,IAAI,CAACM,cAAc,GAAG,IAAIC,GAAG,EAAE,CAAA;AACjC,GAAA;EAEOC,aAAaA,CAACC,OAAsB,EAAE;AAC3C,IAAA,MAAMC,aAAkC,GAAAC,cAAA,CAAAA,cAAA,CAAA;AACtCC,MAAAA,OAAO,EAAE,IAAI;MACbZ,QAAQ,EAAE,IAAI,CAACA,QAAA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AE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,MAAM;IACjB;;;;OAIG;IACK,KAAK,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACK,IAAI,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACK,OAAO,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACK,OAAO,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACK,YAAY,EAAE,OAAO,CAAC;IAE9B;;;;OAIG;IACK,oBAAoB,EAAE,OAAO,CAAC;IAEtC;;;;;;OAMG;IACK,UAAU,EAAE,OAAO,CAAC;IAEpB,EAAE,EAAE,MAAM,CAAC;IAEnB,MAAM,CAAC,WAAW,oCAAuB;IAEzC,MAAM,CAAC,IAAI,SAAY;IAEvB;;;OAGG;gBACS,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;gBAC1C,YAAY,EAAE,MAAM;IAQhC;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM;;;;;;IAehC;;;;OAIG;IACH,QAAQ;IAIR;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,YAAY;IAmD1B;;;OAGG;IACH,QAAQ;WAgBK,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;CAGnE"}
|
package/dist/src/Shadow.min.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{defineProperty as t}from"../_virtual/_rollupPluginBabelHelpers.min.mjs";import{classRegistry as o}from"./ClassRegistry.min.mjs";import{Color as e}from"./color/Color.min.mjs";import{config as s}from"./config.min.mjs";import{reNum as i}from"./parser/constants.min.mjs";import{Point as r}from"./Point.min.mjs";import{uid as n}from"./util/internals/uid.min.mjs";import{pickBy as f}from"./util/misc/pick.min.mjs";import{degreesToRadians as c}from"./util/misc/radiansDegreesConversion.min.mjs";import{toFixed as a}from"./util/misc/toFixed.min.mjs";import{rotateVector as l}from"./util/misc/vectors.min.mjs";const m="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",u=new RegExp("(?:\\s|^)"+m+m+"("+i+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)"),h={color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1};class p{constructor(t){const o="string"==typeof t?p.parseShadow(t):t;Object.assign(this,p.ownDefaults
|
|
1
|
+
import{defineProperty as t}from"../_virtual/_rollupPluginBabelHelpers.min.mjs";import{classRegistry as o}from"./ClassRegistry.min.mjs";import{Color as e}from"./color/Color.min.mjs";import{config as s}from"./config.min.mjs";import{reNum as i}from"./parser/constants.min.mjs";import{Point as r}from"./Point.min.mjs";import{uid as n}from"./util/internals/uid.min.mjs";import{pickBy as f}from"./util/misc/pick.min.mjs";import{degreesToRadians as c}from"./util/misc/radiansDegreesConversion.min.mjs";import{toFixed as a}from"./util/misc/toFixed.min.mjs";import{rotateVector as l}from"./util/misc/vectors.min.mjs";const m="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",u=new RegExp("(?:\\s|^)"+m+m+"("+i+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)"),h={color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1};class p{constructor(t){const o="string"==typeof t?p.parseShadow(t):t;Object.assign(this,p.ownDefaults,o),this.id=n()}static parseShadow(t){const o=t.trim(),[,e=0,s=0,i=0]=(u.exec(o)||[]).map((t=>parseFloat(t)||0));return{color:(o.replace(u,"")||"rgb(0,0,0)").trim(),offsetX:e,offsetY:s,blur:i}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const o=l(new r(this.offsetX,this.offsetY),c(-t.angle)),i=new e(this.color);let n=40,f=40;return t.width&&t.height&&(n=100*a((Math.abs(o.x)+this.blur)/t.width,s.NUM_FRACTION_DIGITS)+20,f=100*a((Math.abs(o.y)+this.blur)/t.height,s.NUM_FRACTION_DIGITS)+20),t.flipX&&(o.x*=-1),t.flipY&&(o.y*=-1),'<filter id="SVGID_'.concat(this.id,'" y="-').concat(f,'%" height="').concat(100+2*f,'%" x="-').concat(n,'%" width="').concat(100+2*n,'%" >\n\t<feGaussianBlur in="SourceAlpha" stdDeviation="').concat(a(this.blur?this.blur/2:0,s.NUM_FRACTION_DIGITS),'"></feGaussianBlur>\n\t<feOffset dx="').concat(a(o.x,s.NUM_FRACTION_DIGITS),'" dy="').concat(a(o.y,s.NUM_FRACTION_DIGITS),'" result="oBlur" ></feOffset>\n\t<feFlood flood-color="').concat(i.toRgb(),'" flood-opacity="').concat(i.getAlpha(),'"/>\n\t<feComposite in2="oBlur" operator="in" />\n\t<feMerge>\n\t\t<feMergeNode></feMergeNode>\n\t\t<feMergeNode in="SourceGraphic"></feMergeNode>\n\t</feMerge>\n</filter>\n')}toObject(){const t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling,type:this.constructor.type},o=p.ownDefaults;return this.includeDefaultValues?t:f(t,((t,e)=>t!==o[e]))}static async fromObject(t){return new this(t)}}t(p,"ownDefaults",h),t(p,"type","shadow"),o.setClass(p,"shadow");export{p as Shadow,h as shadowDefaultValues};
|
|
2
2
|
//# sourceMappingURL=Shadow.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Shadow.min.mjs","sources":["../../src/Shadow.ts"],"sourcesContent":["import { classRegistry } from './ClassRegistry';\nimport { Color } from './color/Color';\nimport { config } from './config';\nimport { reNum } from './parser/constants';\nimport { Point } from './Point';\nimport type { FabricObject } from './shapes/Object/FabricObject';\nimport type { TClassProperties } from './typedefs';\nimport { uid } from './util/internals/uid';\nimport { pickBy } from './util/misc/pick';\nimport { degreesToRadians } from './util/misc/radiansDegreesConversion';\nimport { toFixed } from './util/misc/toFixed';\nimport { rotateVector } from './util/misc/vectors';\n\n/**\n * Regex matching shadow offsetX, offsetY and blur (ex: \"2px 2px 10px rgba(0,0,0,0.2)\", \"rgb(0,255,0) 2px 2px\")\n * - (?:\\s|^): This part captures either a whitespace character (\\s) or the beginning of a line (^). It's non-capturing (due to (?:...)), meaning it doesn't create a capturing group.\n * - (-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?: This captures the first component of the shadow, which is the horizontal offset. Breaking it down:\n * - (-?\\d+): Captures an optional minus sign followed by one or more digits (integer part of the number).\n * - (?:\\.\\d*)?: Optionally captures a decimal point followed by zero or more digits (decimal part of the number).\n * - (?:px)?: Optionally captures the \"px\" unit.\n * - (?:\\s?|$): Captures either an optional whitespace or the end of the line. This whole part is wrapped in a non-capturing group and marked as optional with ?.\n * - (-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?: Similar to the previous step, this captures the vertical offset.\n\n(\\d+(?:\\.\\d*)?(?:px)?)?: This captures the blur radius. It's similar to the horizontal offset but without the optional minus sign.\n\n(?:\\s+(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?){0,1}: This captures an optional part for the color. It allows for whitespace followed by a component with an optional minus sign, digits, decimal point, and \"px\" unit.\n\n(?:$|\\s): This captures either the end of the line or a whitespace character. It ensures that the match ends either at the end of the string or with a whitespace character.\n */\n// eslint-disable-next-line max-len\n\nconst shadowOffsetRegex = '(-?\\\\d+(?:\\\\.\\\\d*)?(?:px)?(?:\\\\s?|$))?';\n\nconst reOffsetsAndBlur = new RegExp(\n '(?:\\\\s|^)' +\n shadowOffsetRegex +\n shadowOffsetRegex +\n '(' +\n reNum +\n '?(?:px)?)?(?:\\\\s?|$)(?:$|\\\\s)'\n);\n\nexport const shadowDefaultValues: Partial<TClassProperties<Shadow>> = {\n color: 'rgb(0,0,0)',\n blur: 0,\n offsetX: 0,\n offsetY: 0,\n affectStroke: false,\n includeDefaultValues: true,\n nonScaling: false,\n};\n\nexport type SerializedShadowOptions = {\n color: string;\n blur: number;\n offsetX: number;\n offsetY: number;\n affectStroke: boolean;\n nonScaling: boolean;\n type: string;\n};\n\nexport class Shadow {\n /**\n * Shadow color\n * @type String\n * @default\n */\n declare color: string;\n\n /**\n * Shadow blur\n * @type Number\n */\n declare blur: number;\n\n /**\n * Shadow horizontal offset\n * @type Number\n * @default\n */\n declare offsetX: number;\n\n /**\n * Shadow vertical offset\n * @type Number\n * @default\n */\n declare offsetY: number;\n\n /**\n * Whether the shadow should affect stroke operations\n * @type Boolean\n * @default\n */\n declare affectStroke: boolean;\n\n /**\n * Indicates whether toObject should include default values\n * @type Boolean\n * @default\n */\n declare includeDefaultValues: boolean;\n\n /**\n * When `false`, the shadow will scale with the object.\n * When `true`, the shadow's offsetX, offsetY, and blur will not be affected by the object's scale.\n * default to false\n * @type Boolean\n * @default\n */\n declare nonScaling: boolean;\n\n declare id: number;\n\n static ownDefaults = shadowDefaultValues;\n\n static type = 'shadow';\n\n /**\n * @see {@link http://fabricjs.com/shadows|Shadow demo}\n * @param {Object|String} [options] Options object with any of color, blur, offsetX, offsetY properties or string (e.g. \"rgba(0,0,0,0.2) 2px 2px 10px\")\n */\n constructor(options: Partial<TClassProperties<Shadow>>);\n constructor(svgAttribute: string);\n constructor(arg0: string | Partial<TClassProperties<Shadow>>) {\n const options: Partial<TClassProperties<Shadow>> =\n typeof arg0 === 'string' ? Shadow.parseShadow(arg0) : arg0;\n Object.assign(this, Shadow.ownDefaults);\n for (const prop in options) {\n // @ts-expect-error for loops are so messy in TS\n this[prop] = options[prop];\n }\n\n this.id = uid();\n }\n\n /**\n * @param {String} value Shadow value to parse\n * @return {Object} Shadow object with color, offsetX, offsetY and blur\n */\n static parseShadow(value: string) {\n const shadowStr = value.trim(),\n [, offsetX = 0, offsetY = 0, blur = 0] = (\n reOffsetsAndBlur.exec(shadowStr) || []\n ).map((value) => parseFloat(value) || 0),\n color = (shadowStr.replace(reOffsetsAndBlur, '') || 'rgb(0,0,0)').trim();\n\n return {\n color,\n offsetX,\n offsetY,\n blur,\n };\n }\n\n /**\n * Returns a string representation of an instance\n * @see http://www.w3.org/TR/css-text-decor-3/#text-shadow\n * @return {String} Returns CSS3 text-shadow declaration\n */\n toString() {\n return [this.offsetX, this.offsetY, this.blur, this.color].join('px ');\n }\n\n /**\n * Returns SVG representation of a shadow\n * @param {FabricObject} object\n * @return {String} SVG representation of a shadow\n */\n toSVG(object: FabricObject) {\n const offset = rotateVector(\n new Point(this.offsetX, this.offsetY),\n degreesToRadians(-object.angle)\n ),\n BLUR_BOX = 20,\n color = new Color(this.color);\n let fBoxX = 40,\n fBoxY = 40;\n\n if (object.width && object.height) {\n //http://www.w3.org/TR/SVG/filters.html#FilterEffectsRegion\n // we add some extra space to filter box to contain the blur ( 20 )\n fBoxX =\n toFixed(\n (Math.abs(offset.x) + this.blur) / object.width,\n config.NUM_FRACTION_DIGITS\n ) *\n 100 +\n BLUR_BOX;\n fBoxY =\n toFixed(\n (Math.abs(offset.y) + this.blur) / object.height,\n config.NUM_FRACTION_DIGITS\n ) *\n 100 +\n BLUR_BOX;\n }\n if (object.flipX) {\n offset.x *= -1;\n }\n if (object.flipY) {\n offset.y *= -1;\n }\n\n return `<filter id=\"SVGID_${this.id}\" y=\"-${fBoxY}%\" height=\"${\n 100 + 2 * fBoxY\n }%\" x=\"-${fBoxX}%\" width=\"${\n 100 + 2 * fBoxX\n }%\" >\\n\\t<feGaussianBlur in=\"SourceAlpha\" stdDeviation=\"${toFixed(\n this.blur ? this.blur / 2 : 0,\n config.NUM_FRACTION_DIGITS\n )}\"></feGaussianBlur>\\n\\t<feOffset dx=\"${toFixed(\n offset.x,\n config.NUM_FRACTION_DIGITS\n )}\" dy=\"${toFixed(\n offset.y,\n config.NUM_FRACTION_DIGITS\n )}\" result=\"oBlur\" ></feOffset>\\n\\t<feFlood flood-color=\"${color.toRgb()}\" flood-opacity=\"${color.getAlpha()}\"/>\\n\\t<feComposite in2=\"oBlur\" operator=\"in\" />\\n\\t<feMerge>\\n\\t\\t<feMergeNode></feMergeNode>\\n\\t\\t<feMergeNode in=\"SourceGraphic\"></feMergeNode>\\n\\t</feMerge>\\n</filter>\\n`;\n }\n\n /**\n * Returns object representation of a shadow\n * @return {Object} Object representation of a shadow instance\n */\n toObject() {\n const data: SerializedShadowOptions = {\n color: this.color,\n blur: this.blur,\n offsetX: this.offsetX,\n offsetY: this.offsetY,\n affectStroke: this.affectStroke,\n nonScaling: this.nonScaling,\n type: (this.constructor as typeof Shadow).type,\n };\n const defaults = Shadow.ownDefaults as SerializedShadowOptions;\n return !this.includeDefaultValues\n ? pickBy(data, (value, key) => value !== defaults[key])\n : data;\n }\n\n static async fromObject(options: Partial<TClassProperties<Shadow>>) {\n return new this(options);\n }\n}\n\nclassRegistry.setClass(Shadow, 'shadow');\n"],"names":["shadowOffsetRegex","reOffsetsAndBlur","RegExp","reNum","shadowDefaultValues","color","blur","offsetX","offsetY","affectStroke","includeDefaultValues","nonScaling","Shadow","constructor","arg0","options","parseShadow","Object","assign","this","ownDefaults","prop","id","uid","value","shadowStr","trim","exec","map","parseFloat","replace","toString","join","toSVG","object","offset","rotateVector","Point","degreesToRadians","angle","Color","fBoxX","fBoxY","width","height","toFixed","Math","abs","x","config","NUM_FRACTION_DIGITS","y","flipX","flipY","concat","toRgb","getAlpha","toObject","data","type","defaults","pickBy","key","fromObject","_defineProperty","classRegistry","setClass"],"mappings":"gmBA+BA,MAAMA,EAAoB,yCAEpBC,EAAmB,IAAIC,OAC3B,YACEF,EACAA,EACA,IACAG,EACA,iCAGSC,EAAyD,CACpEC,MAAO,aACPC,KAAM,EACNC,QAAS,EACTC,QAAS,EACTC,cAAc,EACdC,sBAAsB,EACtBC,YAAY,GAaP,MAAMC,EA+DXC,WAAAA,CAAYC,GACV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EAAI,EAC5B2C,EAAOC,qBACR,yCAAAI,OAAwCT,EACvCV,EAAOa,EACPC,EAAOC,+BACRI,OAAST,EACRV,EAAOgB,EACPF,EAAOC,qBACRI,2DAAAA,OAA0DjD,EAAMkD,6BAAOD,OAAoBjD,EAAMmD,WAAU,gLAC9G,CAMAC,QAAAA,GACE,MAAMC,EAAgC,CACpCrD,MAAOc,KAAKd,MACZC,KAAMa,KAAKb,KACXC,QAASY,KAAKZ,QACdC,QAASW,KAAKX,QACdC,aAAcU,KAAKV,aACnBE,WAAYQ,KAAKR,WACjBgD,KAAOxC,KAAKN,YAA8B8C,MAEtCC,EAAWhD,EAAOQ,YACxB,OAAQD,KAAKT,qBAETgD,EADAG,EAAOH,GAAM,CAAClC,EAAOsC,IAAQtC,IAAUoC,EAASE,IAEtD,CAEA,uBAAaC,CAAWhD,GACtB,OAAO,IAAII,KAAKJ,EAClB,EA3IAiD,EA1CWpD,EAAM,cAqDIR,GAAmB4D,EArD7BpD,EAAM,OAuDH,UAiIhBqD,EAAcC,SAAStD,EAAQ"}
|
|
1
|
+
{"version":3,"file":"Shadow.min.mjs","sources":["../../src/Shadow.ts"],"sourcesContent":["import { classRegistry } from './ClassRegistry';\nimport { Color } from './color/Color';\nimport { config } from './config';\nimport { reNum } from './parser/constants';\nimport { Point } from './Point';\nimport type { FabricObject } from './shapes/Object/FabricObject';\nimport type { TClassProperties } from './typedefs';\nimport { uid } from './util/internals/uid';\nimport { pickBy } from './util/misc/pick';\nimport { degreesToRadians } from './util/misc/radiansDegreesConversion';\nimport { toFixed } from './util/misc/toFixed';\nimport { rotateVector } from './util/misc/vectors';\n\n/**\n * Regex matching shadow offsetX, offsetY and blur (ex: \"2px 2px 10px rgba(0,0,0,0.2)\", \"rgb(0,255,0) 2px 2px\")\n * - (?:\\s|^): This part captures either a whitespace character (\\s) or the beginning of a line (^). It's non-capturing (due to (?:...)), meaning it doesn't create a capturing group.\n * - (-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?: This captures the first component of the shadow, which is the horizontal offset. Breaking it down:\n * - (-?\\d+): Captures an optional minus sign followed by one or more digits (integer part of the number).\n * - (?:\\.\\d*)?: Optionally captures a decimal point followed by zero or more digits (decimal part of the number).\n * - (?:px)?: Optionally captures the \"px\" unit.\n * - (?:\\s?|$): Captures either an optional whitespace or the end of the line. This whole part is wrapped in a non-capturing group and marked as optional with ?.\n * - (-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?: Similar to the previous step, this captures the vertical offset.\n\n(\\d+(?:\\.\\d*)?(?:px)?)?: This captures the blur radius. It's similar to the horizontal offset but without the optional minus sign.\n\n(?:\\s+(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?){0,1}: This captures an optional part for the color. It allows for whitespace followed by a component with an optional minus sign, digits, decimal point, and \"px\" unit.\n\n(?:$|\\s): This captures either the end of the line or a whitespace character. It ensures that the match ends either at the end of the string or with a whitespace character.\n */\n// eslint-disable-next-line max-len\n\nconst shadowOffsetRegex = '(-?\\\\d+(?:\\\\.\\\\d*)?(?:px)?(?:\\\\s?|$))?';\n\nconst reOffsetsAndBlur = new RegExp(\n '(?:\\\\s|^)' +\n shadowOffsetRegex +\n shadowOffsetRegex +\n '(' +\n reNum +\n '?(?:px)?)?(?:\\\\s?|$)(?:$|\\\\s)'\n);\n\nexport const shadowDefaultValues: Partial<TClassProperties<Shadow>> = {\n color: 'rgb(0,0,0)',\n blur: 0,\n offsetX: 0,\n offsetY: 0,\n affectStroke: false,\n includeDefaultValues: true,\n nonScaling: false,\n};\n\nexport type SerializedShadowOptions = {\n color: string;\n blur: number;\n offsetX: number;\n offsetY: number;\n affectStroke: boolean;\n nonScaling: boolean;\n type: string;\n};\n\nexport class Shadow {\n /**\n * Shadow color\n * @type String\n * @default\n */\n declare color: string;\n\n /**\n * Shadow blur\n * @type Number\n */\n declare blur: number;\n\n /**\n * Shadow horizontal offset\n * @type Number\n * @default\n */\n declare offsetX: number;\n\n /**\n * Shadow vertical offset\n * @type Number\n * @default\n */\n declare offsetY: number;\n\n /**\n * Whether the shadow should affect stroke operations\n * @type Boolean\n * @default\n */\n declare affectStroke: boolean;\n\n /**\n * Indicates whether toObject should include default values\n * @type Boolean\n * @default\n */\n declare includeDefaultValues: boolean;\n\n /**\n * When `false`, the shadow will scale with the object.\n * When `true`, the shadow's offsetX, offsetY, and blur will not be affected by the object's scale.\n * default to false\n * @type Boolean\n * @default\n */\n declare nonScaling: boolean;\n\n declare id: number;\n\n static ownDefaults = shadowDefaultValues;\n\n static type = 'shadow';\n\n /**\n * @see {@link http://fabricjs.com/shadows|Shadow demo}\n * @param {Object|String} [options] Options object with any of color, blur, offsetX, offsetY properties or string (e.g. \"rgba(0,0,0,0.2) 2px 2px 10px\")\n */\n constructor(options: Partial<TClassProperties<Shadow>>);\n constructor(svgAttribute: string);\n constructor(arg0: string | Partial<TClassProperties<Shadow>>) {\n const options: Partial<TClassProperties<Shadow>> =\n typeof arg0 === 'string' ? Shadow.parseShadow(arg0) : arg0;\n Object.assign(this, Shadow.ownDefaults, options);\n this.id = uid();\n }\n\n /**\n * @param {String} value Shadow value to parse\n * @return {Object} Shadow object with color, offsetX, offsetY and blur\n */\n static parseShadow(value: string) {\n const shadowStr = value.trim(),\n [, offsetX = 0, offsetY = 0, blur = 0] = (\n reOffsetsAndBlur.exec(shadowStr) || []\n ).map((value) => parseFloat(value) || 0),\n color = (shadowStr.replace(reOffsetsAndBlur, '') || 'rgb(0,0,0)').trim();\n\n return {\n color,\n offsetX,\n offsetY,\n blur,\n };\n }\n\n /**\n * Returns a string representation of an instance\n * @see http://www.w3.org/TR/css-text-decor-3/#text-shadow\n * @return {String} Returns CSS3 text-shadow declaration\n */\n toString() {\n return [this.offsetX, this.offsetY, this.blur, this.color].join('px ');\n }\n\n /**\n * Returns SVG representation of a shadow\n * @param {FabricObject} object\n * @return {String} SVG representation of a shadow\n */\n toSVG(object: FabricObject) {\n const offset = rotateVector(\n new Point(this.offsetX, this.offsetY),\n degreesToRadians(-object.angle)\n ),\n BLUR_BOX = 20,\n color = new Color(this.color);\n let fBoxX = 40,\n fBoxY = 40;\n\n if (object.width && object.height) {\n //http://www.w3.org/TR/SVG/filters.html#FilterEffectsRegion\n // we add some extra space to filter box to contain the blur ( 20 )\n fBoxX =\n toFixed(\n (Math.abs(offset.x) + this.blur) / object.width,\n config.NUM_FRACTION_DIGITS\n ) *\n 100 +\n BLUR_BOX;\n fBoxY =\n toFixed(\n (Math.abs(offset.y) + this.blur) / object.height,\n config.NUM_FRACTION_DIGITS\n ) *\n 100 +\n BLUR_BOX;\n }\n if (object.flipX) {\n offset.x *= -1;\n }\n if (object.flipY) {\n offset.y *= -1;\n }\n\n return `<filter id=\"SVGID_${this.id}\" y=\"-${fBoxY}%\" height=\"${\n 100 + 2 * fBoxY\n }%\" x=\"-${fBoxX}%\" width=\"${\n 100 + 2 * fBoxX\n }%\" >\\n\\t<feGaussianBlur in=\"SourceAlpha\" stdDeviation=\"${toFixed(\n this.blur ? this.blur / 2 : 0,\n config.NUM_FRACTION_DIGITS\n )}\"></feGaussianBlur>\\n\\t<feOffset dx=\"${toFixed(\n offset.x,\n config.NUM_FRACTION_DIGITS\n )}\" dy=\"${toFixed(\n offset.y,\n config.NUM_FRACTION_DIGITS\n )}\" result=\"oBlur\" ></feOffset>\\n\\t<feFlood flood-color=\"${color.toRgb()}\" flood-opacity=\"${color.getAlpha()}\"/>\\n\\t<feComposite in2=\"oBlur\" operator=\"in\" />\\n\\t<feMerge>\\n\\t\\t<feMergeNode></feMergeNode>\\n\\t\\t<feMergeNode in=\"SourceGraphic\"></feMergeNode>\\n\\t</feMerge>\\n</filter>\\n`;\n }\n\n /**\n * Returns object representation of a shadow\n * @return {Object} Object representation of a shadow instance\n */\n toObject() {\n const data: SerializedShadowOptions = {\n color: this.color,\n blur: this.blur,\n offsetX: this.offsetX,\n offsetY: this.offsetY,\n affectStroke: this.affectStroke,\n nonScaling: this.nonScaling,\n type: (this.constructor as typeof Shadow).type,\n };\n const defaults = Shadow.ownDefaults as SerializedShadowOptions;\n return !this.includeDefaultValues\n ? pickBy(data, (value, key) => value !== defaults[key])\n : data;\n }\n\n static async fromObject(options: Partial<TClassProperties<Shadow>>) {\n return new this(options);\n }\n}\n\nclassRegistry.setClass(Shadow, 'shadow');\n"],"names":["shadowOffsetRegex","reOffsetsAndBlur","RegExp","reNum","shadowDefaultValues","color","blur","offsetX","offsetY","affectStroke","includeDefaultValues","nonScaling","Shadow","constructor","arg0","options","parseShadow","Object","assign","this","ownDefaults","id","uid","value","shadowStr","trim","exec","map","parseFloat","replace","toString","join","toSVG","object","offset","rotateVector","Point","degreesToRadians","angle","Color","fBoxX","fBoxY","width","height","toFixed","Math","abs","x","config","NUM_FRACTION_DIGITS","y","flipX","flipY","concat","toRgb","getAlpha","toObject","data","type","defaults","pickBy","key","fromObject","_defineProperty","classRegistry","setClass"],"mappings":"gmBA+BA,MAAMA,EAAoB,yCAEpBC,EAAmB,IAAIC,OAC3B,YACEF,EACAA,EACA,IACAG,EACA,iCAGSC,EAAyD,CACpEC,MAAO,aACPC,KAAM,EACNC,QAAS,EACTC,QAAS,EACTC,cAAc,EACdC,sBAAsB,EACtBC,YAAY,GAaP,MAAMC,EA+DXC,WAAAA,CAAYC,GACV,MAAMC,EACY,iBAATD,EAAoBF,EAAOI,YAAYF,GAAQA,EACxDG,OAAOC,OAAOC,KAAMP,EAAOQ,YAAaL,GACxCI,KAAKE,GAAKC,GACZ,CAMA,kBAAON,CAAYO,GACjB,MAAMC,EAAYD,EAAME,QACnBlB,CAAAA,EAAU,EAAGC,EAAU,EAAGF,EAAO,IAClCL,EAAiByB,KAAKF,IAAc,IACpCG,KAAKJ,GAAUK,WAAWL,IAAU,IAGxC,MAAO,CACLlB,OAHSmB,EAAUK,QAAQ5B,EAAkB,KAAO,cAAcwB,OAIlElB,UACAC,UACAF,OAEJ,CAOAwB,QAAAA,GACE,MAAO,CAACX,KAAKZ,QAASY,KAAKX,QAASW,KAAKb,KAAMa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BAAaC,CAAW/C,GACtB,OAAO,IAAII,KAAKJ,EAClB,EAtIAgD,EA1CWnD,EAAM,cAqDIR,GAAmB2D,EArD7BnD,EAAM,OAuDH,UA4HhBoD,EAAcC,SAASrD,EAAQ"}
|
package/dist/src/Shadow.mjs
CHANGED
|
@@ -47,11 +47,7 @@ class Shadow {
|
|
|
47
47
|
|
|
48
48
|
constructor(arg0) {
|
|
49
49
|
const options = typeof arg0 === 'string' ? Shadow.parseShadow(arg0) : arg0;
|
|
50
|
-
Object.assign(this, Shadow.ownDefaults);
|
|
51
|
-
for (const prop in options) {
|
|
52
|
-
// @ts-expect-error for loops are so messy in TS
|
|
53
|
-
this[prop] = options[prop];
|
|
54
|
-
}
|
|
50
|
+
Object.assign(this, Shadow.ownDefaults, options);
|
|
55
51
|
this.id = uid();
|
|
56
52
|
}
|
|
57
53
|
|