diff --git a/CHANGELOG.md b/CHANGELOG.md index 78acf6e5fc0..47ae5f74045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [next] +- chore(TS): export util types [#8915](https://github.com/fabricjs/fabric.js/pull/8915) - chore(TS): change enums with types [#8918](https://github.com/fabricjs/fabric.js/pull/8918) - chore(TS): export gradient types - chore(lint) export filter colors and brushes types [#8913](https://github.com/fabricjs/fabric.js/pull/8913) diff --git a/fabric.ts b/fabric.ts index dcf9a7269d6..a70879fdcab 100644 --- a/fabric.ts +++ b/fabric.ts @@ -5,6 +5,9 @@ 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'; @@ -12,6 +15,7 @@ export { Canvas } from './src/canvas/Canvas'; export type { XY } from './src/Point'; export { Point } from './src/Point'; +export type { IntersectionType } from './src/Intersection'; export { Intersection } from './src/Intersection'; export { Color } from './src/color/Color'; export * from './src/color/typedefs'; 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 4591479770b..c1317b12c97 100644 --- a/src/canvas/StaticCanvas.ts +++ b/src/canvas/StaticCanvas.ts @@ -38,7 +38,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/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'; /** 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/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 942126b8ae6..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, @@ -28,6 +28,7 @@ export { multiplyTransformMatrixArray, isIdentityMatrix, } from './misc/matrix'; +export type { TextStyleArray } from './misc/textStyles'; export { stylesFromArray, stylesToArray, @@ -65,12 +66,17 @@ export { sendObjectToPlane, } from './misc/planeChange'; export * as string from './lang_string'; +export type { + EnlivenObjectOptions, + LoadImageOptions, +} from './misc/objectEnlive'; export { loadImage, enlivenObjects, enlivenObjectEnlivables, } from './misc/objectEnlive'; export { pick } from './misc/pick'; +export * from './path/typedefs'; export { joinPath, parsePath, @@ -92,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/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 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, 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 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