@leafer/interface 1.0.0-rc.8 → 1.0.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/interface",
3
- "version": "1.0.0-rc.8",
3
+ "version": "1.0.0",
4
4
  "description": "@leafer/interface",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -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,12 @@ import { IControl } from '../control/IControl'
17
17
  import { IFunction } from '../function/IFunction'
18
18
 
19
19
 
20
- export type ILeaferType = 'draw' | 'design' | 'board' | 'document' | 'user'
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
24
  realCanvas?: boolean
25
+ lazySpeard?: IFourNumber
25
26
  }
26
27
 
27
28
  export interface ILeaferAttrData {
@@ -33,7 +34,7 @@ export interface ILeaferAttrData {
33
34
  viewCompleted: boolean
34
35
  layoutLocked: boolean
35
36
 
36
- pixelRatio: number
37
+ transforming: boolean
37
38
 
38
39
  view: unknown
39
40
 
@@ -50,10 +51,12 @@ export interface ILeaferAttrData {
50
51
  hitCanvasManager?: IHitCanvasManager
51
52
 
52
53
  autoLayout?: IAutoBounds
54
+ lazyBounds: IBounds
53
55
 
54
56
  config: ILeaferConfig
55
57
 
56
58
  readonly cursorPoint: IPointData
59
+ readonly clientBounds: IBoundsData
57
60
  leafs: number
58
61
 
59
62
  __eventIds: IEventListenerId[]
@@ -67,16 +70,22 @@ export interface ILeaferAttrData {
67
70
  unlockLayout(): void
68
71
  lockLayout(): void
69
72
 
70
- setZoomLayer(zoomLayer: ILeaf): void
71
- forceFullRender(): void
72
- updateCursor(): void
73
+ updateCursor(cursor?: ICursorType): void
73
74
  resize(size: IScreenSizeData): void
74
75
 
75
- waitReady(item: IFunction): void
76
- waitViewReady(item: IFunction): void
77
- waitViewCompleted(item: IFunction): void
76
+ waitReady(item: IFunction, bind?: IObject): void
77
+ waitViewReady(item: IFunction, bind?: IObject): void
78
+ waitViewCompleted(item: IFunction, bind?: IObject): void
79
+
80
+ zoom(zoomType: IZoomType, padding?: IFourNumber, fixedScale?: boolean): IBoundsData
81
+ getValidMove(moveX: number, moveY: number): IPointData
82
+ getValidScale(changeScale: number): number
83
+
84
+ getWorldPointByClient(clientPoint: IClientPointData, updateClient?: boolean): IPointData
78
85
  }
79
86
 
87
+ export type IZoomType = 'in' | 'out' | 'fit' | 'fit-width' | 'fit-height' | number | ILeaf | ILeaf[] | IBoundsData
88
+
80
89
  export interface ILeaferBase extends IZoomView, IControl, ILeaferAttrData {
81
90
  readonly isApp: boolean
82
91
  readonly app: ILeaferBase
@@ -101,6 +110,7 @@ export interface ICreator {
101
110
  image?(options?: ILeaferImageConfig): ILeaferImage
102
111
  canvas?(options?: ILeaferCanvasConfig, manager?: ICanvasManager): ILeaferCanvas
103
112
  hitCanvas?(options?: IHitCanvasConfig, manager?: ICanvasManager): IHitCanvas
113
+ hitCanvasManager?(): IHitCanvasManager
104
114
 
105
115
  watcher?(target: ILeaf, options?: IWatcherConfig): IWatcher
106
116
  layouter?(target: ILeaf, options?: ILayouterConfig): ILayouter
@@ -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 CanvasRenderingContext2DSettings {
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(): CanvasRenderingContext2DSettings
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
- getImageType(leaf: ILeaf, size: IScreenSizeData): IHitCanvas
8
+ getPixelType(leaf: ILeaf, config?: ILeaferCanvasConfig): IHitCanvas
9
9
  }
@@ -1,11 +1,12 @@
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 { ICursorType } from '../display/ILeaf'
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
@@ -14,6 +15,7 @@ export interface ILeaferCanvasConfig extends IAutoBoundsData {
14
15
  smooth?: boolean
15
16
  hittable?: boolean
16
17
  webgl?: boolean
18
+ contextSettings?: ICanvasContext2DSettings
17
19
  }
18
20
 
19
21
  export type IHitCanvasConfig = ILeaferCanvasConfig
@@ -29,6 +31,11 @@ export interface ICanvasStrokeOptions {
29
31
  miterLimit?: number
30
32
  }
31
33
 
34
+ export interface ICanvasCacheOptions extends ICanvasStrokeOptions {
35
+ fillStyle?: string | object
36
+ strokeStyle?: string | object
37
+ }
38
+
32
39
  export interface ICanvasAttr extends ICanvasStrokeOptions, IObject {
33
40
 
34
41
  smooth: boolean // imageSmoothingEnabled: boolean
@@ -105,6 +112,8 @@ interface ICanvasMethod {
105
112
 
106
113
  hitFill(point: IPointData, fillRule?: string): boolean
107
114
  hitStroke(point: IPointData, strokeWidth?: number): boolean
115
+ hitPixel(radiusPoint: IRadiusPointData, offset?: IPointData, scale?: number): boolean
116
+
108
117
 
109
118
  setStroke(strokeStyle: string | object, strokeWidth: number, options?: ICanvasStrokeOptions): void
110
119
  setStrokeOptions(options: ICanvasStrokeOptions): void
@@ -116,7 +125,7 @@ interface ICanvasMethod {
116
125
  setWorldBlur(blur: number): void
117
126
 
118
127
  copyWorld(canvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData, blendMode?: string): void
119
- copyWorldByReset(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: string): void
128
+ copyWorldByReset(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: string, onlyResetTransform?: boolean): void
120
129
  copyWorldToInner(canvas: ILeaferCanvas, fromWorld: IMatrixWithBoundsData, toInnerBounds: IBoundsData, blendMode?: string): void
121
130
 
122
131
  useMask(maskCanvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData): void
@@ -130,6 +139,7 @@ interface ICanvasMethod {
130
139
  clear(): void
131
140
  }
132
141
 
142
+ export type ILeaferCanvasView = any
133
143
  export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
134
144
 
135
145
  readonly innerId: InnerId
@@ -148,6 +158,9 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
148
158
  backgroundColor?: string
149
159
  hittable?: boolean
150
160
 
161
+ zIndex?: number
162
+ childIndex?: number
163
+
151
164
  bounds: IBounds
152
165
  clientBounds: IBoundsData
153
166
 
@@ -155,7 +168,7 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
155
168
 
156
169
  autoLayout: boolean
157
170
 
158
- view: any
171
+ view: ILeaferCanvasView
159
172
  parentView: any
160
173
 
161
174
  unreal?: boolean
@@ -168,6 +181,7 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
168
181
 
169
182
  init(): void
170
183
 
184
+ export(filename: IExportFileType | string, options?: IExportOptions | number | boolean): string | Promise<any>
171
185
  toBlob(type?: string, quality?: number): Promise<IBlob>
172
186
  toDataURL(type?: string, quality?: number): string | Promise<string>
173
187
  saveAs(filename: string, quality?: number): Promise<boolean>
@@ -178,14 +192,12 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
178
192
  resize(size: IScreenSizeData): void
179
193
  updateViewSize(): void
180
194
  updateClientBounds(): void
181
-
182
- setCursor(cursor: ICursorType | ICursorType[]): void
195
+ getClientBounds(update?: boolean): IBoundsData
183
196
 
184
197
  // other
185
198
  isSameSize(options: ILeaferCanvasConfig): boolean
186
199
  getSameCanvas(useSameWorldTransform?: boolean, useSameSmooth?: boolean): ILeaferCanvas
187
- getBiggerCanvas(addWidth: number, addHeight: number): ILeaferCanvas
188
- recycle(): void
200
+ recycle(clearBounds?: IBoundsData): void
189
201
 
190
202
  updateRender(): void
191
203
  unrealCanvas(): void
@@ -194,7 +206,7 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
194
206
 
195
207
 
196
208
  export interface IHitCanvas extends ILeaferCanvas {
197
-
209
+ hitScale?: number
198
210
  }
199
211
 
200
212
 
package/src/data/IData.ts CHANGED
@@ -1,11 +1,15 @@
1
+ import { IPointData } from '../math/IMath'
2
+
1
3
  export type INumber = number // number | string will convert to number
2
4
  export type IBoolean = boolean // boolean | string will convert to boolean
3
5
  export type IString = string // string | other will convert to string
4
- export type IValue = INumber | IBoolean | IString | IObject //
6
+ export type IValue = INumber | IBoolean | IString | IObject
5
7
  export type ITimer = any
6
8
 
7
9
  export type IPathString = string
8
10
 
11
+ export type IFourNumber = number | number[]
12
+
9
13
  export interface IObject {
10
14
  [name: string]: any
11
15
  }
@@ -22,6 +26,10 @@ export interface IStringMap {
22
26
  [name: string]: string
23
27
  }
24
28
 
29
+ export interface IPointDataMap {
30
+ [name: string]: IPointData
31
+ }
32
+
25
33
  export interface IDataTypeHandle {
26
34
  (target: any): void
27
35
  }
@@ -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
  }
@@ -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
  }