Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(TS): export util types #8915

Merged
merged 9 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- chore(TS): export util types [#8915](https://github.com/fabricjs/fabric.js/pull/8915)
- chore(TS): export gradient types
- chore(lint) export filter colors and brushes types [#8913](https://github.com/fabricjs/fabric.js/pull/8913)
- chore(lint) Add a rule for import type [#8907](https://github.com/fabricjs/fabric.js/pull/8907)
Expand Down
4 changes: 4 additions & 0 deletions fabric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ 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 type { XY } from './src/Point';
export { Point } from './src/Point';
export type { IntersectionType } from './src/Intersection';
export { Intersection } from './src/Intersection';
Comment on lines +18 to 19
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export type { IntersectionType } from './src/Intersection';
export { Intersection } from './src/Intersection';
export * from './src/Intersection';

export { Color } from './src/color/Color';
export * from './src/color/typedefs';
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/canvas/SelectableCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion src/canvas/StaticCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, K extends keyof any> = {
// @ts-expect-error TS doesn't recognize protected/private fields using the `keyof` directive so we use `keyof any`
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/canvas_gestures.mixin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ts-nocheck

import { scalingEqually } from '../controls/scale';
import { fireEvent } from '../util/fireEvent';
import { fireEvent } from '../controls/fireEvent';
import {
degreesToRadians,
radiansToDegrees,
Expand Down
2 changes: 1 addition & 1 deletion src/controls/drag.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TransformActionHandler } from '../EventTypeDefs';
import { fireEvent } from '../util/fireEvent';
import { fireEvent } from './fireEvent';
import { commonEventInfo, isLocked } from './util';

/**
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/controls/wrapWithFireEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
Transform,
TransformActionHandler,
} from '../EventTypeDefs';
import { fireEvent } from '../util/fireEvent';
import { fireEvent } from './fireEvent';
import { commonEventInfo } from './util';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/Line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion src/shapes/Object/Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/Object/StackedObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/util/animation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './animate';
export * from './types';
10 changes: 8 additions & 2 deletions src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,6 +28,7 @@ export {
multiplyTransformMatrixArray,
isIdentityMatrix,
} from './misc/matrix';
export type { TextStyleArray } from './misc/textStyles';
export {
stylesFromArray,
stylesToArray,
Expand Down Expand Up @@ -65,12 +66,17 @@ export {
sendObjectToPlane,
} from './misc/planeChange';
export * as string from './lang_string';
export type {
EnlivenObjectOptions,
LoadImageOptions,
} from './misc/objectEnlive';
Comment on lines +69 to +72
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is where i start to have some doubts.
How do i access those types then? Are they on the main export root or do i need and grab them from inside util?

export {
loadImage,
enlivenObjects,
enlivenObjectEnlivables,
} from './misc/objectEnlive';
export { pick } from './misc/pick';
export * from './path/typedefs';
export {
joinPath,
parsePath,
Expand All @@ -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,
Expand Down
29 changes: 7 additions & 22 deletions src/util/misc/findScaleTo.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/util/misc/objectEnlive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export const enlivenObjects = (
objects.map((obj) =>
classRegistry
.getClass(obj.type)
// @ts-ignore
.fromObject(obj, {
signal,
reviver,
Expand Down
2 changes: 2 additions & 0 deletions src/util/misc/projectStroke/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.