From 42c9ed21b0bd71e98fedc91bb314c881a55ec0f0 Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Sat, 13 May 2023 16:39:48 +0900 Subject: [PATCH 1/7] Update fabric.ts --- CHANGELOG.md | 1 + fabric.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d11875e6dda..dbb9c8e72cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [next] +- chore(TS): export types - chore(lint) Add a rule for import type [#8907](https://github.com/fabricjs/fabric.js/pull/8907) - fix(Object): dirty unflagging inconsistency [#8910](https://github.com/fabricjs/fabric.js/pull/8910) - chore(TS): minor type/import fixes [#8904](https://github.com/fabricjs/fabric.js/pull/8904) diff --git a/fabric.ts b/fabric.ts index b02ae2d96a7..63f5c210ce3 100644 --- a/fabric.ts +++ b/fabric.ts @@ -5,12 +5,16 @@ export { config } from './src/config'; export { classRegistry } from './src/ClassRegistry'; export { runningAnimations } from './src/util/animation/AnimationRegistry'; +export * from './src/typedefs'; + +export * from './src/EventTypeDefs'; export { Observable } from './src/Observable'; export { StaticCanvas } from './src/canvas/StaticCanvas'; export { Canvas } from './src/canvas/Canvas'; export { Point } from './src/Point'; +export type { IntersectionType } from './src/Intersection'; export { Intersection } from './src/Intersection'; export { Color } from './src/color/Color'; From b04ef3070755ded383c6c14282b707ec93cb2361 Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Sat, 13 May 2023 16:44:06 +0900 Subject: [PATCH 2/7] Update findScaleTo.ts --- src/util/misc/findScaleTo.ts | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/util/misc/findScaleTo.ts b/src/util/misc/findScaleTo.ts index 5146d0b0f3e..425b5ccdf4b 100644 --- a/src/util/misc/findScaleTo.ts +++ b/src/util/misc/findScaleTo.ts @@ -1,26 +1,14 @@ -export interface IWithDimensions { - /** - * natural unscaled width of the object - */ - width: number; - /** - * natural unscaled height of the object - */ - height: number; -} +import type { TSize } from '../../typedefs'; /** * Finds the scale for the object source to fit inside the object destination, * keeping aspect ratio intact. * respect the total allowed area for the cache. - * @param {IWithDimensions} source - * @param {IWithDimensions} destination + * @param {TSize} source natural unscaled size of the object + * @param {TSize} destination natural unscaled size of the object * @return {Number} scale factor to apply to source to fit into destination */ -export const findScaleToFit = ( - source: IWithDimensions, - destination: IWithDimensions -) => +export const findScaleToFit = (source: TSize, destination: TSize) => Math.min( destination.width / source.width, destination.height / source.height @@ -30,14 +18,11 @@ export const findScaleToFit = ( * Finds the scale for the object source to cover entirely the object destination, * keeping aspect ratio intact. * respect the total allowed area for the cache. - * @param {IWithDimensions} source - * @param {IWithDimensions} destination + * @param {TSize} source natural unscaled size of the object + * @param {TSize} destination natural unscaled size of the object * @return {Number} scale factor to apply to source to cover destination */ -export const findScaleToCover = ( - source: IWithDimensions, - destination: IWithDimensions -) => +export const findScaleToCover = (source: TSize, destination: TSize) => Math.max( destination.width / source.width, destination.height / source.height From 07a2126e7f1721d9a7ccef30fb47b7318a2faa7f Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Sat, 13 May 2023 16:48:46 +0900 Subject: [PATCH 3/7] more --- src/util/index.ts | 5 +++++ src/util/misc/objectEnlive.ts | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util/index.ts b/src/util/index.ts index 942126b8ae6..fbf6a38556f 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -28,6 +28,7 @@ export { multiplyTransformMatrixArray, isIdentityMatrix, } from './misc/matrix'; +export type { TextStyleArray } from './misc/textStyles'; export { stylesFromArray, stylesToArray, @@ -65,6 +66,10 @@ export { sendObjectToPlane, } from './misc/planeChange'; export * as string from './lang_string'; +export type { + EnlivenObjectOptions, + LoadImageOptions, +} from './misc/objectEnlive'; export { loadImage, enlivenObjects, diff --git a/src/util/misc/objectEnlive.ts b/src/util/misc/objectEnlive.ts index 40c25c27767..15d78c567b9 100644 --- a/src/util/misc/objectEnlive.ts +++ b/src/util/misc/objectEnlive.ts @@ -84,7 +84,6 @@ export const enlivenObjects = ( objects.map((obj) => classRegistry .getClass(obj.type) - // @ts-ignore .fromObject(obj, { signal, reviver, From e99668d10e006cf3dd098b790a5404f2a5268ab4 Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Sat, 13 May 2023 16:54:22 +0900 Subject: [PATCH 4/7] rename --- src/canvas/Canvas.ts | 2 +- src/canvas/SelectableCanvas.ts | 2 +- src/canvas/StaticCanvas.ts | 7 ++++++- src/shapes/Line.ts | 2 +- src/shapes/Object/Object.ts | 6 +++++- src/shapes/Object/StackedObject.ts | 2 +- src/util/{types.ts => typeAssertions.ts} | 0 7 files changed, 15 insertions(+), 6 deletions(-) rename src/util/{types.ts => typeAssertions.ts} (100%) diff --git a/src/canvas/Canvas.ts b/src/canvas/Canvas.ts index a1a55725ac4..36495710375 100644 --- a/src/canvas/Canvas.ts +++ b/src/canvas/Canvas.ts @@ -19,7 +19,7 @@ import { sendPointToPlane } from '../util/misc/planeChange'; import { isFabricObjectWithDragSupport, isInteractiveTextObject, -} from '../util/types'; +} from '../util/typeAssertions'; import { SelectableCanvas } from './SelectableCanvas'; import { TextEditingManager } from './TextEditingManager'; diff --git a/src/canvas/SelectableCanvas.ts b/src/canvas/SelectableCanvas.ts index f7e00f361e0..e8a3e0af570 100644 --- a/src/canvas/SelectableCanvas.ts +++ b/src/canvas/SelectableCanvas.ts @@ -16,7 +16,7 @@ import { saveObjectTransform, } from '../util/misc/objectTransforms'; import { StaticCanvas } from './StaticCanvas'; -import { isCollection } from '../util/types'; +import { isCollection } from '../util/typeAssertions'; import { invertTransform, transformPoint } from '../util/misc/matrix'; import { isTransparent } from '../util/misc/isTransparent'; import type { diff --git a/src/canvas/StaticCanvas.ts b/src/canvas/StaticCanvas.ts index 98b88152cf1..795b4ae4f61 100644 --- a/src/canvas/StaticCanvas.ts +++ b/src/canvas/StaticCanvas.ts @@ -39,7 +39,12 @@ import { import { pick } from '../util/misc/pick'; import { matrixToSVG } from '../util/misc/svgParsing'; import { toFixed } from '../util/misc/toFixed'; -import { isCollection, isFiller, isPattern, isTextObject } from '../util/types'; +import { + isCollection, + isFiller, + isPattern, + isTextObject, +} from '../util/typeAssertions'; type TDestroyed = { // @ts-expect-error TS doesn't recognize protected/private fields using the `keyof` directive so we use `keyof any` diff --git a/src/shapes/Line.ts b/src/shapes/Line.ts index fb2de170c72..ce34d94cb8f 100644 --- a/src/shapes/Line.ts +++ b/src/shapes/Line.ts @@ -4,7 +4,7 @@ import type { TClassProperties } from '../typedefs'; import { classRegistry } from '../ClassRegistry'; import { FabricObject, cacheProperties } from './Object/FabricObject'; import { Point } from '../Point'; -import { isFiller } from '../util/types'; +import { isFiller } from '../util/typeAssertions'; import type { FabricObjectProps, SerializedObjectProps, diff --git a/src/shapes/Object/Object.ts b/src/shapes/Object/Object.ts index 88b2f39e4b7..f339412099b 100644 --- a/src/shapes/Object/Object.ts +++ b/src/shapes/Object/Object.ts @@ -28,7 +28,11 @@ import { pick, pickBy } from '../../util/misc/pick'; import { toFixed } from '../../util/misc/toFixed'; import type { Group } from '../Group'; import { StaticCanvas } from '../../canvas/StaticCanvas'; -import { isFiller, isSerializableFiller, isTextObject } from '../../util/types'; +import { + isFiller, + isSerializableFiller, + isTextObject, +} from '../../util/typeAssertions'; import type { Image } from '../Image'; import { cacheProperties, diff --git a/src/shapes/Object/StackedObject.ts b/src/shapes/Object/StackedObject.ts index b4f23fe0700..ca7876a1891 100644 --- a/src/shapes/Object/StackedObject.ts +++ b/src/shapes/Object/StackedObject.ts @@ -3,7 +3,7 @@ import type { Group } from '../Group'; import type { Canvas } from '../../canvas/Canvas'; import type { StaticCanvas } from '../../canvas/StaticCanvas'; import { ObjectGeometry } from './ObjectGeometry'; -import { isActiveSelection } from '../../util/types'; +import { isActiveSelection } from '../../util/typeAssertions'; type TAncestor = StackedObject | Canvas | StaticCanvas; type TCollection = Group | Canvas | StaticCanvas; diff --git a/src/util/types.ts b/src/util/typeAssertions.ts similarity index 100% rename from src/util/types.ts rename to src/util/typeAssertions.ts From ff0fa3bf73d396f84aaca84bdcc7dc7a796bd282 Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Sat, 13 May 2023 16:55:13 +0900 Subject: [PATCH 5/7] mv to controls --- src/canvas/canvas_gestures.mixin.ts | 2 +- src/controls/drag.ts | 2 +- src/{util => controls}/fireEvent.ts | 0 src/controls/wrapWithFireEvent.ts | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename src/{util => controls}/fireEvent.ts (100%) diff --git a/src/canvas/canvas_gestures.mixin.ts b/src/canvas/canvas_gestures.mixin.ts index 536b50ecbf9..99e4be6a766 100644 --- a/src/canvas/canvas_gestures.mixin.ts +++ b/src/canvas/canvas_gestures.mixin.ts @@ -1,7 +1,7 @@ //@ts-nocheck import { scalingEqually } from '../controls/scale'; -import { fireEvent } from '../util/fireEvent'; +import { fireEvent } from '../controls/fireEvent'; import { degreesToRadians, radiansToDegrees, diff --git a/src/controls/drag.ts b/src/controls/drag.ts index ceefee19850..4d7a4456d76 100644 --- a/src/controls/drag.ts +++ b/src/controls/drag.ts @@ -1,5 +1,5 @@ import type { TransformActionHandler } from '../EventTypeDefs'; -import { fireEvent } from '../util/fireEvent'; +import { fireEvent } from './fireEvent'; import { commonEventInfo, isLocked } from './util'; /** diff --git a/src/util/fireEvent.ts b/src/controls/fireEvent.ts similarity index 100% rename from src/util/fireEvent.ts rename to src/controls/fireEvent.ts diff --git a/src/controls/wrapWithFireEvent.ts b/src/controls/wrapWithFireEvent.ts index 019d21134f2..1f009bf3133 100644 --- a/src/controls/wrapWithFireEvent.ts +++ b/src/controls/wrapWithFireEvent.ts @@ -3,7 +3,7 @@ import type { Transform, TransformActionHandler, } from '../EventTypeDefs'; -import { fireEvent } from '../util/fireEvent'; +import { fireEvent } from './fireEvent'; import { commonEventInfo } from './util'; /** From d8bfa1966afcfa7affc560eb57763b5d00961628 Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Sat, 13 May 2023 16:55:57 +0900 Subject: [PATCH 6/7] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbb9c8e72cb..8818d04a43a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## [next] -- chore(TS): export types +- chore(TS): export util types [#8915](https://github.com/fabricjs/fabric.js/pull/8915) - chore(lint) Add a rule for import type [#8907](https://github.com/fabricjs/fabric.js/pull/8907) - fix(Object): dirty unflagging inconsistency [#8910](https://github.com/fabricjs/fabric.js/pull/8910) - chore(TS): minor type/import fixes [#8904](https://github.com/fabricjs/fabric.js/pull/8904) From d986753cc9c5dc8d82e7fcb3f0919acf5464b9d9 Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Sat, 13 May 2023 17:06:02 +0900 Subject: [PATCH 7/7] more --- src/util/animation/index.ts | 2 ++ src/util/index.ts | 5 +++-- src/util/misc/projectStroke/index.ts | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 src/util/animation/index.ts diff --git a/src/util/animation/index.ts b/src/util/animation/index.ts new file mode 100644 index 00000000000..17631c43cc9 --- /dev/null +++ b/src/util/animation/index.ts @@ -0,0 +1,2 @@ +export * from './animate'; +export * from './types'; diff --git a/src/util/index.ts b/src/util/index.ts index fbf6a38556f..46372bd04fb 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -12,7 +12,7 @@ export { radiansToDegrees, } from './misc/radiansDegreesConversion'; export { rotatePoint } from './misc/rotatePoint'; -export { projectStrokeOnPoints } from './misc/projectStroke'; +export * from './misc/projectStroke'; export { transformPoint, invertTransform, @@ -76,6 +76,7 @@ export { enlivenObjectEnlivables, } from './misc/objectEnlive'; export { pick } from './misc/pick'; +export * from './path/typedefs'; export { joinPath, parsePath, @@ -97,7 +98,7 @@ export { } from './dom_misc'; export { isTransparent } from './misc/isTransparent'; export { mergeClipPaths } from './misc/mergeClipPaths'; -export { animate, animateColor } from './animation/animate'; +export * from './animation'; export * as ease from './animation/easing'; export { requestAnimFrame, diff --git a/src/util/misc/projectStroke/index.ts b/src/util/misc/projectStroke/index.ts index c0717ca1a7f..531fa6de3a6 100644 --- a/src/util/misc/projectStroke/index.ts +++ b/src/util/misc/projectStroke/index.ts @@ -3,6 +3,8 @@ import { StrokeLineCapProjections } from './StrokeLineCapProjections'; import { StrokeLineJoinProjections } from './StrokeLineJoinProjections'; import type { TProjection, TProjectStrokeOnPointsOptions } from './types'; +export * from './types'; + /** * * Used to calculate object's bounding box