@leafer/interface 1.0.0-rc.9 → 1.0.1
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/package.json +1 -1
- package/src/app/ILeafer.ts +22 -11
- package/src/canvas/ICanvas.ts +7 -2
- package/src/canvas/IHitCanvasManager.ts +3 -3
- package/src/canvas/ILeaferCanvas.ts +24 -11
- package/src/data/IData.ts +15 -1
- package/src/data/ILeafData.ts +5 -5
- package/src/display/IBranch.ts +2 -1
- package/src/display/ILeaf.ts +388 -91
- package/src/display/IView.ts +2 -3
- package/src/display/module/IBranchRender.ts +2 -2
- package/src/display/module/ILeafBounds.ts +1 -0
- package/src/display/module/ILeafDataProxy.ts +1 -1
- package/src/display/module/ILeafEventer.ts +1 -1
- package/src/display/module/ILeafHit.ts +4 -1
- package/src/display/module/ILeafRender.ts +2 -1
- package/src/event/IEventer.ts +10 -4
- package/src/event/IUIEvent.ts +10 -2
- package/src/file/IExport.ts +41 -0
- package/src/file/IFileType.ts +1 -1
- package/src/function/IFunction.ts +9 -0
- package/src/image/IImageManager.ts +2 -1
- package/src/image/ILeaferImage.ts +13 -0
- package/src/index.ts +12 -11
- package/src/interaction/ICursor.ts +16 -0
- package/src/interaction/IInteraction.ts +45 -6
- package/src/layout/ILeafLayout.ts +24 -11
- package/src/math/IMath.ts +54 -9
- package/src/path/IPathDrawer.ts +6 -3
- package/src/platform/IPlatform.ts +10 -4
- package/src/renderer/IRenderer.ts +3 -2
- package/src/selector/ISelector.ts +21 -10
- package/types/index.d.ts +703 -322
- package/src/display/module/ILeafMask.ts +0 -12
package/package.json
CHANGED
package/src/app/ILeafer.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ILeaf } from '../display/ILeaf'
|
|
1
|
+
import { ILeaf, ICursorType } from '../display/ILeaf'
|
|
2
2
|
import { IRenderer, IRendererConfig } from '../renderer/IRenderer'
|
|
3
3
|
import { IHitCanvas, ILeaferCanvas, ILeaferCanvasConfig, IHitCanvasConfig } from '../canvas/ILeaferCanvas'
|
|
4
4
|
import { ILayouter, ILayouterConfig } from '../layouter/ILayouter'
|
|
5
5
|
import { ISelector, ISelectorConfig } from '../selector/ISelector'
|
|
6
6
|
import { IInteraction, IInteractionCanvas, IInteractionConfig } from '../interaction/IInteraction'
|
|
7
7
|
import { IWatcher, IWatcherConfig } from '../watcher/IWatcher'
|
|
8
|
-
import { IAutoBounds, IPointData, IScreenSizeData } from '../math/IMath'
|
|
8
|
+
import { IAutoBounds, IBoundsData, IPointData, IScreenSizeData, IBounds, IClientPointData } from '../math/IMath'
|
|
9
9
|
import { ICanvasManager } from '../canvas/ICanvasManager'
|
|
10
10
|
import { IHitCanvasManager } from '../canvas/IHitCanvasManager'
|
|
11
11
|
import { IEventListenerId } from '../event/IEventer'
|
|
12
|
-
import { IObject } from '../data/IData'
|
|
12
|
+
import { IFourNumber, IObject } from '../data/IData'
|
|
13
13
|
import { IZoomView } from '../display/IView'
|
|
14
14
|
import { IAppBase } from './IApp'
|
|
15
15
|
import { ILeaferImage, ILeaferImageConfig } from '../image/ILeaferImage'
|
|
@@ -17,11 +17,13 @@ import { IControl } from '../control/IControl'
|
|
|
17
17
|
import { IFunction } from '../function/IFunction'
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
export type ILeaferType = 'draw' | 'design' | 'board' | 'document' | '
|
|
20
|
+
export type ILeaferType = 'draw' | 'editor' | 'design' | 'board' | 'document' | 'app' | 'website' | 'game' | 'player' | 'chart' | 'custom'
|
|
21
21
|
export interface ILeaferConfig extends IRendererConfig, ILeaferCanvasConfig, IInteractionConfig, ILayouterConfig {
|
|
22
22
|
start?: boolean
|
|
23
23
|
type?: ILeaferType
|
|
24
|
+
mobile?: boolean
|
|
24
25
|
realCanvas?: boolean
|
|
26
|
+
lazySpeard?: IFourNumber
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export interface ILeaferAttrData {
|
|
@@ -33,7 +35,7 @@ export interface ILeaferAttrData {
|
|
|
33
35
|
viewCompleted: boolean
|
|
34
36
|
layoutLocked: boolean
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
transforming: boolean
|
|
37
39
|
|
|
38
40
|
view: unknown
|
|
39
41
|
|
|
@@ -50,10 +52,12 @@ export interface ILeaferAttrData {
|
|
|
50
52
|
hitCanvasManager?: IHitCanvasManager
|
|
51
53
|
|
|
52
54
|
autoLayout?: IAutoBounds
|
|
55
|
+
lazyBounds: IBounds
|
|
53
56
|
|
|
54
57
|
config: ILeaferConfig
|
|
55
58
|
|
|
56
59
|
readonly cursorPoint: IPointData
|
|
60
|
+
readonly clientBounds: IBoundsData
|
|
57
61
|
leafs: number
|
|
58
62
|
|
|
59
63
|
__eventIds: IEventListenerId[]
|
|
@@ -67,16 +71,22 @@ export interface ILeaferAttrData {
|
|
|
67
71
|
unlockLayout(): void
|
|
68
72
|
lockLayout(): void
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
forceFullRender(): void
|
|
72
|
-
updateCursor(): void
|
|
74
|
+
updateCursor(cursor?: ICursorType): void
|
|
73
75
|
resize(size: IScreenSizeData): void
|
|
74
76
|
|
|
75
|
-
waitReady(item: IFunction): void
|
|
76
|
-
waitViewReady(item: IFunction): void
|
|
77
|
-
waitViewCompleted(item: IFunction): void
|
|
77
|
+
waitReady(item: IFunction, bind?: IObject): void
|
|
78
|
+
waitViewReady(item: IFunction, bind?: IObject): void
|
|
79
|
+
waitViewCompleted(item: IFunction, bind?: IObject): void
|
|
80
|
+
|
|
81
|
+
zoom(zoomType: IZoomType, padding?: IFourNumber, fixedScale?: boolean): IBoundsData
|
|
82
|
+
getValidMove(moveX: number, moveY: number): IPointData
|
|
83
|
+
getValidScale(changeScale: number): number
|
|
84
|
+
|
|
85
|
+
getWorldPointByClient(clientPoint: IClientPointData, updateClient?: boolean): IPointData
|
|
78
86
|
}
|
|
79
87
|
|
|
88
|
+
export type IZoomType = 'in' | 'out' | 'fit' | 'fit-width' | 'fit-height' | number | ILeaf | ILeaf[] | IBoundsData
|
|
89
|
+
|
|
80
90
|
export interface ILeaferBase extends IZoomView, IControl, ILeaferAttrData {
|
|
81
91
|
readonly isApp: boolean
|
|
82
92
|
readonly app: ILeaferBase
|
|
@@ -101,6 +111,7 @@ export interface ICreator {
|
|
|
101
111
|
image?(options?: ILeaferImageConfig): ILeaferImage
|
|
102
112
|
canvas?(options?: ILeaferCanvasConfig, manager?: ICanvasManager): ILeaferCanvas
|
|
103
113
|
hitCanvas?(options?: IHitCanvasConfig, manager?: ICanvasManager): IHitCanvas
|
|
114
|
+
hitCanvasManager?(): IHitCanvasManager
|
|
104
115
|
|
|
105
116
|
watcher?(target: ILeaf, options?: IWatcherConfig): IWatcher
|
|
106
117
|
layouter?(target: ILeaf, options?: ILayouterConfig): ILayouter
|
package/src/canvas/ICanvas.ts
CHANGED
|
@@ -111,6 +111,8 @@ export interface CanvasPattern {
|
|
|
111
111
|
setTransform(transform?: DOMMatrix2DInit): void
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
export type ICanvasPattern = CanvasPattern
|
|
115
|
+
|
|
114
116
|
declare var CanvasPattern: {
|
|
115
117
|
prototype: CanvasPattern
|
|
116
118
|
new(): CanvasPattern
|
|
@@ -123,15 +125,18 @@ interface CanvasRect {
|
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
type PredefinedColorSpace = 'display-p3' | 'srgb'
|
|
126
|
-
interface
|
|
128
|
+
interface ICanvasRenderingContext2DSettings {
|
|
127
129
|
alpha?: boolean
|
|
128
130
|
colorSpace?: PredefinedColorSpace
|
|
129
131
|
desynchronized?: boolean
|
|
130
132
|
willReadFrequently?: boolean
|
|
131
133
|
}
|
|
134
|
+
|
|
135
|
+
export type ICanvasContext2DSettings = ICanvasRenderingContext2DSettings
|
|
136
|
+
|
|
132
137
|
export interface ICanvasContext2D extends CanvasCompositing, CanvasDrawImage, CanvasDrawPath, CanvasFillStrokeStyles, CanvasFilters, CanvasImageData, CanvasImageSmoothing, CanvasPath, CanvasPathDrawingStyles, CanvasRect, CanvasShadowStyles, CanvasState, CanvasText, CanvasTextDrawingStyles, CanvasTransform, CanvasUserInterface {
|
|
133
138
|
readonly canvas: HTMLCanvasElement
|
|
134
|
-
getContextAttributes():
|
|
139
|
+
getContextAttributes(): ICanvasRenderingContext2DSettings
|
|
135
140
|
}
|
|
136
141
|
|
|
137
142
|
declare var ICanvasContext2D: {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ILeaf } from '../display/ILeaf'
|
|
2
|
-
import { IScreenSizeData } from '../math/IMath'
|
|
3
2
|
import { ICanvasManager } from './ICanvasManager'
|
|
4
|
-
import { IHitCanvas } from './ILeaferCanvas'
|
|
3
|
+
import { IHitCanvas, ILeaferCanvasConfig } from './ILeaferCanvas'
|
|
5
4
|
|
|
6
5
|
export interface IHitCanvasManager extends ICanvasManager {
|
|
6
|
+
maxTotal: number // 最多缓存多少张画布
|
|
7
7
|
getPathType(leaf: ILeaf): IHitCanvas
|
|
8
|
-
|
|
8
|
+
getPixelType(leaf: ILeaf, config?: ILeaferCanvasConfig): IHitCanvas
|
|
9
9
|
}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { IObject } from '../data/IData'
|
|
2
|
-
import { IBounds, IMatrixData, IBoundsData, IAutoBoundsData, IAutoBounds, IScreenSizeData, IMatrixWithBoundsData, IPointData } from '../math/IMath'
|
|
3
|
-
import { ICanvasContext2D, IWindingRule, IPath2D, ITextMetrics, CanvasGradient, CanvasPattern } from './ICanvas'
|
|
2
|
+
import { IBounds, IMatrixData, IBoundsData, IAutoBoundsData, IAutoBounds, IScreenSizeData, IMatrixWithBoundsData, IPointData, IRadiusPointData } from '../math/IMath'
|
|
3
|
+
import { ICanvasContext2D, IWindingRule, IPath2D, ITextMetrics, CanvasGradient, CanvasPattern, ICanvasContext2DSettings } from './ICanvas'
|
|
4
4
|
import { IResizeEventListener } from '../event/IEvent'
|
|
5
5
|
import { IPathDrawer } from '../path/IPathDrawer'
|
|
6
6
|
import { InnerId } from '../event/IEventer'
|
|
7
7
|
import { ICanvasManager } from './ICanvasManager'
|
|
8
|
-
import {
|
|
8
|
+
import { IExportFileType } from '../file/IFileType'
|
|
9
|
+
import { IExportOptions } from '../file/IExport'
|
|
9
10
|
|
|
10
11
|
export interface ILeaferCanvasConfig extends IAutoBoundsData {
|
|
11
12
|
view?: string | IObject
|
|
13
|
+
canvas?: string | IObject
|
|
12
14
|
fill?: string
|
|
13
15
|
pixelRatio?: number
|
|
14
16
|
smooth?: boolean
|
|
15
17
|
hittable?: boolean
|
|
16
18
|
webgl?: boolean
|
|
19
|
+
contextSettings?: ICanvasContext2DSettings
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
export type IHitCanvasConfig = ILeaferCanvasConfig
|
|
@@ -29,6 +32,11 @@ export interface ICanvasStrokeOptions {
|
|
|
29
32
|
miterLimit?: number
|
|
30
33
|
}
|
|
31
34
|
|
|
35
|
+
export interface ICanvasCacheOptions extends ICanvasStrokeOptions {
|
|
36
|
+
fillStyle?: string | object
|
|
37
|
+
strokeStyle?: string | object
|
|
38
|
+
}
|
|
39
|
+
|
|
32
40
|
export interface ICanvasAttr extends ICanvasStrokeOptions, IObject {
|
|
33
41
|
|
|
34
42
|
smooth: boolean // imageSmoothingEnabled: boolean
|
|
@@ -105,6 +113,8 @@ interface ICanvasMethod {
|
|
|
105
113
|
|
|
106
114
|
hitFill(point: IPointData, fillRule?: string): boolean
|
|
107
115
|
hitStroke(point: IPointData, strokeWidth?: number): boolean
|
|
116
|
+
hitPixel(radiusPoint: IRadiusPointData, offset?: IPointData, scale?: number): boolean
|
|
117
|
+
|
|
108
118
|
|
|
109
119
|
setStroke(strokeStyle: string | object, strokeWidth: number, options?: ICanvasStrokeOptions): void
|
|
110
120
|
setStrokeOptions(options: ICanvasStrokeOptions): void
|
|
@@ -116,7 +126,7 @@ interface ICanvasMethod {
|
|
|
116
126
|
setWorldBlur(blur: number): void
|
|
117
127
|
|
|
118
128
|
copyWorld(canvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData, blendMode?: string): void
|
|
119
|
-
copyWorldByReset(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: string): void
|
|
129
|
+
copyWorldByReset(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: string, onlyResetTransform?: boolean): void
|
|
120
130
|
copyWorldToInner(canvas: ILeaferCanvas, fromWorld: IMatrixWithBoundsData, toInnerBounds: IBoundsData, blendMode?: string): void
|
|
121
131
|
|
|
122
132
|
useMask(maskCanvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData): void
|
|
@@ -130,6 +140,7 @@ interface ICanvasMethod {
|
|
|
130
140
|
clear(): void
|
|
131
141
|
}
|
|
132
142
|
|
|
143
|
+
export type ILeaferCanvasView = any
|
|
133
144
|
export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
|
|
134
145
|
|
|
135
146
|
readonly innerId: InnerId
|
|
@@ -148,6 +159,9 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
|
|
|
148
159
|
backgroundColor?: string
|
|
149
160
|
hittable?: boolean
|
|
150
161
|
|
|
162
|
+
zIndex?: number
|
|
163
|
+
childIndex?: number
|
|
164
|
+
|
|
151
165
|
bounds: IBounds
|
|
152
166
|
clientBounds: IBoundsData
|
|
153
167
|
|
|
@@ -155,7 +169,7 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
|
|
|
155
169
|
|
|
156
170
|
autoLayout: boolean
|
|
157
171
|
|
|
158
|
-
view:
|
|
172
|
+
view: ILeaferCanvasView
|
|
159
173
|
parentView: any
|
|
160
174
|
|
|
161
175
|
unreal?: boolean
|
|
@@ -168,6 +182,7 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
|
|
|
168
182
|
|
|
169
183
|
init(): void
|
|
170
184
|
|
|
185
|
+
export(filename: IExportFileType | string, options?: IExportOptions | number | boolean): string | Promise<any>
|
|
171
186
|
toBlob(type?: string, quality?: number): Promise<IBlob>
|
|
172
187
|
toDataURL(type?: string, quality?: number): string | Promise<string>
|
|
173
188
|
saveAs(filename: string, quality?: number): Promise<boolean>
|
|
@@ -178,23 +193,21 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
|
|
|
178
193
|
resize(size: IScreenSizeData): void
|
|
179
194
|
updateViewSize(): void
|
|
180
195
|
updateClientBounds(): void
|
|
181
|
-
|
|
182
|
-
setCursor(cursor: ICursorType | ICursorType[]): void
|
|
196
|
+
getClientBounds(update?: boolean): IBoundsData
|
|
183
197
|
|
|
184
198
|
// other
|
|
185
199
|
isSameSize(options: ILeaferCanvasConfig): boolean
|
|
186
200
|
getSameCanvas(useSameWorldTransform?: boolean, useSameSmooth?: boolean): ILeaferCanvas
|
|
187
|
-
|
|
188
|
-
recycle(): void
|
|
201
|
+
recycle(clearBounds?: IBoundsData): void
|
|
189
202
|
|
|
190
|
-
updateRender(): void
|
|
203
|
+
updateRender(bounds: IBoundsData): void
|
|
191
204
|
unrealCanvas(): void
|
|
192
205
|
destroy(): void
|
|
193
206
|
}
|
|
194
207
|
|
|
195
208
|
|
|
196
209
|
export interface IHitCanvas extends ILeaferCanvas {
|
|
197
|
-
|
|
210
|
+
hitScale?: number
|
|
198
211
|
}
|
|
199
212
|
|
|
200
213
|
|
package/src/data/IData.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { IPointData } from '../math/IMath'
|
|
2
|
+
import { IFunction } from '../function/IFunction'
|
|
3
|
+
|
|
1
4
|
export type INumber = number // number | string will convert to number
|
|
2
5
|
export type IBoolean = boolean // boolean | string will convert to boolean
|
|
3
6
|
export type IString = string // string | other will convert to string
|
|
4
|
-
export type IValue = INumber | IBoolean | IString | IObject
|
|
7
|
+
export type IValue = INumber | IBoolean | IString | IObject
|
|
5
8
|
export type ITimer = any
|
|
6
9
|
|
|
7
10
|
export type IPathString = string
|
|
8
11
|
|
|
12
|
+
export type IFourNumber = number | number[]
|
|
13
|
+
|
|
9
14
|
export interface IObject {
|
|
10
15
|
[name: string]: any
|
|
11
16
|
}
|
|
@@ -22,6 +27,15 @@ export interface IStringMap {
|
|
|
22
27
|
[name: string]: string
|
|
23
28
|
}
|
|
24
29
|
|
|
30
|
+
export interface IFunctionMap {
|
|
31
|
+
[name: string]: IFunction
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export interface IPointDataMap {
|
|
36
|
+
[name: string]: IPointData
|
|
37
|
+
}
|
|
38
|
+
|
|
25
39
|
export interface IDataTypeHandle {
|
|
26
40
|
(target: any): void
|
|
27
41
|
}
|
package/src/data/ILeafData.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ILeaf, ILeafComputedData } from '../display/ILeaf'
|
|
2
|
+
import { IJSONOptions } from '../file/IExport'
|
|
2
3
|
import { IObject } from './IData'
|
|
3
4
|
|
|
4
5
|
export interface IDataProcessor {
|
|
@@ -6,16 +7,13 @@ export interface IDataProcessor {
|
|
|
6
7
|
__input: IObject
|
|
7
8
|
__middle: IObject
|
|
8
9
|
|
|
9
|
-
__single: boolean
|
|
10
|
-
__checkSingle(): void
|
|
11
|
-
|
|
12
10
|
__get(name: string): any
|
|
13
11
|
__getData(): IObject
|
|
14
12
|
|
|
15
13
|
__setInput(name: string, value: any): void
|
|
16
14
|
__getInput(name: string): any
|
|
17
15
|
__removeInput(name: string): void
|
|
18
|
-
__getInputData(): IObject
|
|
16
|
+
__getInputData(names?: string[] | IObject, options?: IJSONOptions): IObject
|
|
19
17
|
|
|
20
18
|
__setMiddle(name: string, value: any): void
|
|
21
19
|
__getMiddle(name: string): any
|
|
@@ -29,5 +27,7 @@ export interface ILeafDataOptions {
|
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
export interface ILeafData extends IDataProcessor, ILeafComputedData {
|
|
32
|
-
|
|
30
|
+
__single?: boolean
|
|
31
|
+
__checkSingle(): void
|
|
32
|
+
__removeNaturalSize(): void
|
|
33
33
|
}
|
package/src/display/IBranch.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { ILeaf } from './ILeaf'
|
|
1
2
|
import { ILeaferCanvas } from '../canvas/ILeaferCanvas'
|
|
2
3
|
import { IRenderOptions } from '../renderer/IRenderer'
|
|
3
|
-
import { ILeaf } from './ILeaf'
|
|
4
4
|
|
|
5
5
|
export interface IBranch extends ILeaf {
|
|
6
6
|
children: ILeaf[]
|
|
7
7
|
__renderBranch?(canvas: ILeaferCanvas, options: IRenderOptions): void
|
|
8
8
|
addMany(...children: ILeaf[]): void
|
|
9
9
|
removeAll(destroy?: boolean): void
|
|
10
|
+
clear(): void
|
|
10
11
|
}
|