diff --git a/packages/core/src/types.d.ts b/packages/core/src/types.d.ts new file mode 100644 index 000000000..1837e5d4f --- /dev/null +++ b/packages/core/src/types.d.ts @@ -0,0 +1,264 @@ +import type React from 'react'; +import type { ForwardedRef } from 'react'; +export declare type Patch = Partial<{ + [P in keyof T]: T | Partial | Patch; +}>; +export interface TLPage { + id: string; + name?: string; + childIndex?: number; + shapes: Record; + bindings: Record; +} +export interface TLPageState { + id: string; + selectedIds: string[]; + camera: { + point: number[]; + zoom: number; + }; + brush?: TLBounds; + pointedId?: string | null; + hoveredId?: string | null; + editingId?: string | null; + bindingId?: string | null; + boundsRotation?: number; + currentParentId?: string | null; +} +export interface TLHandle { + id: string; + index: number; + point: number[]; + canBind?: boolean; + bindingId?: string; +} +export interface TLShape { + id: string; + type: string; + parentId: string; + childIndex: number; + name: string; + point: number[]; + rotation?: number; + children?: string[]; + handles?: Record; + isLocked?: boolean; + isHidden?: boolean; + isEditing?: boolean; + isGenerated?: boolean; + isAspectRatioLocked?: boolean; +} +export declare type TLShapeUtils = Record>; +export interface TLRenderInfo { + shape: T; + isEditing: boolean; + isBinding: boolean; + isHovered: boolean; + isSelected: boolean; + isCurrentParent: boolean; + meta: M extends any ? M : never; + onShapeChange?: TLCallbacks['onShapeChange']; + onShapeBlur?: TLCallbacks['onShapeBlur']; + events: { + onPointerDown: (e: React.PointerEvent) => void; + onPointerUp: (e: React.PointerEvent) => void; + onPointerEnter: (e: React.PointerEvent) => void; + onPointerMove: (e: React.PointerEvent) => void; + onPointerLeave: (e: React.PointerEvent) => void; + }; +} +export interface TLShapeProps extends TLRenderInfo { + ref: ForwardedRef; + shape: T; +} +export interface TLTool { + id: string; + name: string; +} +export interface TLBinding { + id: string; + type: string; + toId: string; + fromId: string; + meta: M; +} +export interface TLTheme { + brushFill?: string; + brushStroke?: string; + selectFill?: string; + selectStroke?: string; + background?: string; + foreground?: string; +} +export declare type TLWheelEventHandler = (info: TLPointerInfo, e: React.WheelEvent | WheelEvent) => void; +export declare type TLPinchEventHandler = (info: TLPointerInfo, e: React.WheelEvent | WheelEvent | React.TouchEvent | TouchEvent | React.PointerEvent | PointerEventInit) => void; +export declare type TLPointerEventHandler = (info: TLPointerInfo, e: React.PointerEvent) => void; +export declare type TLCanvasEventHandler = (info: TLPointerInfo<'canvas'>, e: React.PointerEvent) => void; +export declare type TLBoundsEventHandler = (info: TLPointerInfo<'bounds'>, e: React.PointerEvent) => void; +export declare type TLBoundsHandleEventHandler = (info: TLPointerInfo, e: React.PointerEvent) => void; +export interface TLCallbacks { + onPinchStart: TLPinchEventHandler; + onPinchEnd: TLPinchEventHandler; + onPinch: TLPinchEventHandler; + onPan: TLWheelEventHandler; + onZoom: TLWheelEventHandler; + onPointerMove: TLPointerEventHandler; + onPointerUp: TLPointerEventHandler; + onPointerDown: TLPointerEventHandler; + onPointCanvas: TLCanvasEventHandler; + onDoubleClickCanvas: TLCanvasEventHandler; + onRightPointCanvas: TLCanvasEventHandler; + onDragCanvas: TLCanvasEventHandler; + onReleaseCanvas: TLCanvasEventHandler; + onPointShape: TLPointerEventHandler; + onDoubleClickShape: TLPointerEventHandler; + onRightPointShape: TLPointerEventHandler; + onDragShape: TLPointerEventHandler; + onHoverShape: TLPointerEventHandler; + onUnhoverShape: TLPointerEventHandler; + onReleaseShape: TLPointerEventHandler; + onPointBounds: TLBoundsEventHandler; + onDoubleClickBounds: TLBoundsEventHandler; + onRightPointBounds: TLBoundsEventHandler; + onDragBounds: TLBoundsEventHandler; + onHoverBounds: TLBoundsEventHandler; + onUnhoverBounds: TLBoundsEventHandler; + onReleaseBounds: TLBoundsEventHandler; + onPointBoundsHandle: TLBoundsHandleEventHandler; + onDoubleClickBoundsHandle: TLBoundsHandleEventHandler; + onRightPointBoundsHandle: TLBoundsHandleEventHandler; + onDragBoundsHandle: TLBoundsHandleEventHandler; + onHoverBoundsHandle: TLBoundsHandleEventHandler; + onUnhoverBoundsHandle: TLBoundsHandleEventHandler; + onReleaseBoundsHandle: TLBoundsHandleEventHandler; + onPointHandle: TLPointerEventHandler; + onDoubleClickHandle: TLPointerEventHandler; + onRightPointHandle: TLPointerEventHandler; + onDragHandle: TLPointerEventHandler; + onHoverHandle: TLPointerEventHandler; + onUnhoverHandle: TLPointerEventHandler; + onReleaseHandle: TLPointerEventHandler; + onRenderCountChange: (ids: string[]) => void; + onShapeChange: (shape: { + id: string; + } & Partial) => void; + onShapeBlur: () => void; + onError: (error: Error) => void; +} +export interface TLBounds { + minX: number; + minY: number; + maxX: number; + maxY: number; + width: number; + height: number; + rotation?: number; +} +export declare type TLIntersection = { + didIntersect: boolean; + message: string; + points: number[][]; +}; +export declare enum TLBoundsEdge { + Top = "top_edge", + Right = "right_edge", + Bottom = "bottom_edge", + Left = "left_edge" +} +export declare enum TLBoundsCorner { + TopLeft = "top_left_corner", + TopRight = "top_right_corner", + BottomRight = "bottom_right_corner", + BottomLeft = "bottom_left_corner" +} +export interface TLPointerInfo { + target: T; + pointerId: number; + origin: number[]; + point: number[]; + delta: number[]; + pressure: number; + shiftKey: boolean; + ctrlKey: boolean; + metaKey: boolean; + altKey: boolean; +} +export interface TLKeyboardInfo { + origin: number[]; + point: number[]; + key: string; + keys: string[]; + shiftKey: boolean; + ctrlKey: boolean; + metaKey: boolean; + altKey: boolean; +} +export interface TLTransformInfo { + type: TLBoundsEdge | TLBoundsCorner; + initialShape: T; + scaleX: number; + scaleY: number; + transformOrigin: number[]; +} +export interface TLBezierCurveSegment { + start: number[]; + tangentStart: number[]; + normalStart: number[]; + pressureStart: number; + end: number[]; + tangentEnd: number[]; + normalEnd: number[]; + pressureEnd: number; +} +export declare type TLShapeUtil = K & { + type: T['type']; + defaultProps: T; + Component(this: TLShapeUtil, props: TLRenderInfo, ref: React.ForwardedRef): React.ReactElement, E['tagName']>; + Indicator(this: TLShapeUtil, props: { + shape: T; + }): React.ReactElement | null; + getBounds(this: TLShapeUtil, shape: T): TLBounds; + refMap: Map>; + boundsCache: WeakMap; + isAspectRatioLocked: boolean; + canEdit: boolean; + canBind: boolean; + getRotatedBounds(this: TLShapeUtil, shape: T): TLBounds; + hitTest(this: TLShapeUtil, shape: T, point: number[]): boolean; + hitTestBounds(this: TLShapeUtil, shape: T, bounds: TLBounds): boolean; + shouldRender(this: TLShapeUtil, prev: T, next: T): boolean; + getCenter(this: TLShapeUtil, shape: T): number[]; + getRef(this: TLShapeUtil, shape: T): React.RefObject; + getBindingPoint(this: TLShapeUtil, shape: T, fromShape: K, point: number[], origin: number[], direction: number[], padding: number, bindAnywhere: boolean): { + point: number[]; + distance: number; + } | undefined; + create: (this: TLShapeUtil, props: { + id: string; + } & Partial) => T; + mutate: (this: TLShapeUtil, shape: T, props: Partial) => Partial; + transform: (this: TLShapeUtil, shape: T, bounds: TLBounds, info: TLTransformInfo) => Partial | void; + transformSingle: (this: TLShapeUtil, shape: T, bounds: TLBounds, info: TLTransformInfo) => Partial | void; + updateChildren: (this: TLShapeUtil, shape: T, children: K[]) => Partial[] | void; + onChildrenChange: (this: TLShapeUtil, shape: T, children: TLShape[]) => Partial | void; + onBindingChange: (this: TLShapeUtil, shape: T, binding: TLBinding, target: TLShape, targetBounds: TLBounds, center: number[]) => Partial | void; + onHandleChange: (this: TLShapeUtil, shape: T, handle: Partial, info: Partial) => Partial | void; + onRightPointHandle: (this: TLShapeUtil, shape: T, handle: Partial, info: Partial) => Partial | void; + onDoubleClickHandle: (this: TLShapeUtil, shape: T, handle: Partial, info: Partial) => Partial | void; + onDoubleClickBoundsHandle: (this: TLShapeUtil, shape: T) => Partial | void; + onSessionComplete: (this: TLShapeUtil, shape: T) => Partial | void; + onStyleChange: (this: TLShapeUtil, shape: T) => Partial | void; + _Component: React.ForwardRefExoticComponent; +}; +export interface IShapeTreeNode { + shape: T; + children?: IShapeTreeNode[]; + isEditing: boolean; + isBinding: boolean; + isHovered: boolean; + isSelected: boolean; + isCurrentParent: boolean; + meta?: M extends any ? M : never; +} diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 331a24f0a..35909fae4 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -419,13 +419,11 @@ export interface IShapeTreeNode { /* Utility Types */ /* -------------------------------------------------- */ -/** @internal */ export type MappedByType = { // eslint-disable-next-line @typescript-eslint/no-explicit-any [P in T['type']]: T extends any ? (P extends T['type'] ? T : never) : never } -/** @internal */ export type RequiredKeys = { [K in keyof T]-?: Record extends Pick ? never : K }[keyof T] diff --git a/packages/core/tsconfig.build.json b/packages/core/tsconfig.build.json index d3d6e819b..2f0aedbb9 100644 --- a/packages/core/tsconfig.build.json +++ b/packages/core/tsconfig.build.json @@ -13,8 +13,14 @@ "compilerOptions": { "composite": false, "incremental": false, - "declarationMap": false, - "sourceMap": false, - "emitDeclarationOnly": true - } + "declarationMap": true, + "sourceMap": true, + "emitDeclarationOnly": true, + "paths": { + "+*": ["./*"], + "@tldraw/vec": ["../vec"], + "@tldraw/intersect": ["../intersect"] + } + }, + "references": [{ "path": "../vec" }, { "path": "../intersect" }] } diff --git a/packages/intersect/tsconfig.build.json b/packages/intersect/tsconfig.build.json index d3d6e819b..83bed1073 100644 --- a/packages/intersect/tsconfig.build.json +++ b/packages/intersect/tsconfig.build.json @@ -15,6 +15,10 @@ "incremental": false, "declarationMap": false, "sourceMap": false, - "emitDeclarationOnly": true - } + "emitDeclarationOnly": true, + "paths": { + "@tldraw/vec": ["../vec"] + } + }, + "references": [{ "path": "../vec" }] } diff --git a/packages/tldraw/src/shape/shapes/text/text.tsx b/packages/tldraw/src/shape/shapes/text/text.tsx index 1738a3815..b979d03e1 100644 --- a/packages/tldraw/src/shape/shapes/text/text.tsx +++ b/packages/tldraw/src/shape/shapes/text/text.tsx @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import * as React from 'react' -import { HTMLContainer, TLBounds, Utils, TLTransformInfo, ShapeUtil } from '@tldraw/core' +import { HTMLContainer, TLBounds, Utils, ShapeUtil } from '@tldraw/core' import { Vec } from '@tldraw/vec' import { getShapeStyle, getFontStyle, defaultStyle } from '~shape/shape-styles' import { TextShape, TLDrawShapeType, TLDrawToolType, TLDrawMeta } from '~types' @@ -227,11 +227,7 @@ export const Text = new ShapeUtil(() => ( return Utils.translateBounds(bounds, shape.point) }, - transform( - _shape, - bounds: TLBounds, - { initialShape, scaleX, scaleY }: TLTransformInfo - ) { + transform(_shape, bounds, { initialShape, scaleX, scaleY }) { const { rotation = 0, style: { scale = 1 }, @@ -250,11 +246,7 @@ export const Text = new ShapeUtil(() => ( } }, - transformSingle( - _shape, - bounds: TLBounds, - { initialShape, scaleX, scaleY }: TLTransformInfo - ) { + transformSingle(_shape, bounds, { initialShape, scaleX, scaleY }) { const { style: { scale = 1 }, } = initialShape diff --git a/packages/tldraw/src/state/command/reset-bounds/reset-bounds.command.ts b/packages/tldraw/src/state/command/reset-bounds/reset-bounds.command.ts index d17f30ee1..5bd67dfd4 100644 --- a/packages/tldraw/src/state/command/reset-bounds/reset-bounds.command.ts +++ b/packages/tldraw/src/state/command/reset-bounds/reset-bounds.command.ts @@ -1,6 +1,5 @@ import type { Data, TLDrawCommand } from '~types' import { TLDR } from '~state/tldr' -import { TLBoundsEdge } from '~../../core/src/types' export function resetBounds(data: Data, ids: string[], pageId: string): TLDrawCommand { const { before, after } = TLDR.mutateShapes( diff --git a/packages/tldraw/tsconfig.build.json b/packages/tldraw/tsconfig.build.json index d3d6e819b..97e6a425d 100644 --- a/packages/tldraw/tsconfig.build.json +++ b/packages/tldraw/tsconfig.build.json @@ -11,10 +11,19 @@ "docs" ], "compilerOptions": { + "rootDir": "src", + "baseUrl": "src", "composite": false, "incremental": false, "declarationMap": false, "sourceMap": false, - "emitDeclarationOnly": true - } + "emitDeclarationOnly": true, + "paths": { + "~*": ["./*"], + "@tldraw/core": ["../core"], + "@tldraw/vec": ["../vec"], + "@tldraw/intersect": ["../intersect"] + } + }, + "references": [{ "path": "../vec" }, { "path": "../intersect" }, { "path": "../core" }] }