@leafer/interface 1.0.0-rc.3 → 1.0.0-rc.30

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.
Files changed (40) hide show
  1. package/package.json +1 -1
  2. package/src/app/IApp.ts +3 -3
  3. package/src/app/ILeafer.ts +46 -21
  4. package/src/canvas/ICanvas.ts +7 -2
  5. package/src/canvas/IHitCanvasManager.ts +3 -3
  6. package/src/canvas/ILeaferCanvas.ts +23 -11
  7. package/src/canvas/ISkiaCanvas.ts +20 -1
  8. package/src/data/IData.ts +12 -5
  9. package/src/data/ILeafData.ts +12 -6
  10. package/src/data/IList.ts +9 -6
  11. package/src/display/IBranch.ts +2 -1
  12. package/src/display/ILeaf.ts +452 -108
  13. package/src/display/IView.ts +2 -6
  14. package/src/display/module/IBranchRender.ts +2 -2
  15. package/src/display/module/ILeafBounds.ts +3 -0
  16. package/src/display/module/ILeafDataProxy.ts +5 -3
  17. package/src/display/module/ILeafEventer.ts +1 -1
  18. package/src/display/module/ILeafHit.ts +4 -1
  19. package/src/display/module/ILeafRender.ts +2 -1
  20. package/src/event/IEvent.ts +3 -23
  21. package/src/event/IEventer.ts +7 -2
  22. package/src/event/IUIEvent.ts +14 -9
  23. package/src/file/IExport.ts +41 -0
  24. package/src/file/IFileType.ts +1 -1
  25. package/src/function/IFunction.ts +18 -0
  26. package/src/image/IImageManager.ts +4 -0
  27. package/src/image/ILeaferImage.ts +13 -0
  28. package/src/index.ts +16 -15
  29. package/src/interaction/ICursor.ts +16 -0
  30. package/src/interaction/IInteraction.ts +40 -5
  31. package/src/layout/ILeafLayout.ts +41 -18
  32. package/src/layouter/ILayouter.ts +3 -0
  33. package/src/math/IMath.ts +98 -37
  34. package/src/path/IPathDrawer.ts +6 -3
  35. package/src/platform/IPlatform.ts +22 -4
  36. package/src/plugin/IPlugin.ts +2 -2
  37. package/src/renderer/IRenderer.ts +4 -2
  38. package/src/selector/ISelector.ts +38 -9
  39. package/types/index.d.ts +884 -418
  40. package/src/display/module/ILeafMask.ts +0 -12
@@ -34,6 +34,7 @@ export interface ILayouterConfig {
34
34
  export interface ILayouter extends IControl {
35
35
  target: ILeaf
36
36
  layoutedBlocks: ILayoutBlockData[]
37
+ extraBlock: ILayoutBlockData
37
38
 
38
39
  totalTimes: number
39
40
  times: number
@@ -54,6 +55,8 @@ export interface ILayouter extends IControl {
54
55
  partLayout(): void
55
56
  fullLayout(): void
56
57
 
58
+ addExtra(leaf: ILeaf): void
59
+
57
60
  createBlock(data: ILeafList | ILeaf[]): ILayoutBlockData
58
61
  getBlocks(list: ILeafList): ILayoutBlockData[]
59
62
  addBlocks(current: ILayoutBlockData[]): void
package/src/math/IMath.ts CHANGED
@@ -1,26 +1,54 @@
1
- import { IObject } from '../data/IData'
1
+ import { IFourNumber, IObject } from '../data/IData'
2
2
 
3
3
  export interface IPointData {
4
4
  x: number
5
5
  y: number
6
6
  }
7
7
 
8
+ export interface IUnitPointData {
9
+ type?: 'percent' | 'px'
10
+ x: number
11
+ y: number
12
+ }
13
+
14
+ export interface IFromToData {
15
+ from: IPointData
16
+ to: IPointData
17
+ }
18
+
19
+ export interface IScrollPointData {
20
+ scrollX: number
21
+ scrollY: number
22
+ }
23
+
24
+ export interface IClientPointData {
25
+ clientX: number
26
+ clientY: number
27
+ }
28
+
8
29
  export interface IPoint extends IPointData {
9
- set(x?: number, y?: number): void
10
- copy(point: IPointData): IPoint
30
+ set(x?: number | IPointData, y?: number): IPoint
31
+ get(): IPointData
11
32
  clone(): IPoint
12
33
 
13
- rotate(angle: number, center?: IPointData): IPoint
34
+ move(x: number, y: number): IPoint
35
+ scale(scaleX: number, scaleY?: number): IPoint
36
+ scaleOf(origin: IPointData, scaleX: number, scaleY?: number): IPoint
37
+ rotate(rotation: number, origin?: IPointData): IPoint
38
+ rotateOf(origin: IPointData, rotation: number): IPoint
39
+ getRotation(origin: IPointData, to: IPointData, toOrigin?: IPointData): number
14
40
 
15
41
  toInnerOf(matrix: IMatrixData, to?: IPointData): IPoint
16
42
  toOuterOf(matrix: IMatrixData, to?: IPointData): IPoint
17
43
 
18
- getCenter(to: IPointData): IPointData
44
+ getCenter(to: IPointData): IPoint
19
45
  getDistance(to: IPointData): number
46
+ getDistancePoint(to: IPointData, distance: number, changeTo?: boolean): IPoint
47
+
20
48
  getAngle(to: IPointData): number
21
49
  getAtan2(to: IPointData): number
22
50
 
23
- reset(): void
51
+ reset(): IPoint
24
52
  }
25
53
 
26
54
  export interface IRadiusPointData extends IPointData {
@@ -47,29 +75,38 @@ export interface IOffsetBoundsData extends IBoundsData {
47
75
  offsetY: number
48
76
  }
49
77
 
50
- export interface IBoundsDataHandle {
78
+ export interface IBoundsDataFn {
51
79
  (target: any): IBoundsData
52
80
  }
53
81
 
54
- export interface IBounds extends IBoundsData {
55
- set(x?: number, y?: number, width?: number, height?: number): void
56
- copy(bounds: IBoundsData): IBounds
82
+ export interface IBounds extends IBoundsData, ITwoPointBoundsData {
83
+ set(x?: number | IBoundsData, y?: number, width?: number, height?: number): IBounds
84
+ get(): IBoundsData
57
85
  clone(): IBounds
58
86
 
87
+ move(x: number, y: number): IBounds
59
88
  scale(scaleX: number, scaleY?: number): IBounds
89
+ scaleOf(origin: IPointData, scaleX: number, scaleY?: number): IBounds
60
90
  toOuterOf(matrix: IMatrixData, to?: IBoundsData): IBounds
61
- getFitMatrix(put: IBoundsData): IMatrix
91
+ toInnerOf(matrix: IMatrixData, to?: IBoundsData): IBounds
92
+ getFitMatrix(put: IBoundsData, baseScale?: number): IMatrix
62
93
 
63
- spread(size: number): IBounds
94
+ spread(fourNumber: IFourNumber): IBounds
95
+ shrink(fourNumber: IFourNumber): IBounds
64
96
  ceil(): IBounds
65
97
  unsign(): IBounds
98
+ float(maxLength?: number): IBounds
66
99
 
67
100
  add(bounds: IBoundsData): IBounds
68
- addList(boundsList: IBounds[]): IBounds
69
- setByList(boundsList: IBounds[], addMode?: boolean): IBounds
70
- addListWithHandle(list: IObject[], boundsDataHandle: IBoundsDataHandle): IBounds
71
- setByListWithHandle(list: IObject[], boundsDataHandle: IBoundsDataHandle, addMode: boolean): IBounds
72
- setByPoints(points: IPointData[]): IBounds
101
+ addList(boundsList: IBoundsData[]): IBounds
102
+ setList(boundsList: IBoundsData[]): IBounds
103
+ addListWithFn(list: IObject[], boundsDataHandle: IBoundsDataFn): IBounds
104
+ setListWithFn(list: IObject[], boundsDataHandle: IBoundsDataFn): IBounds
105
+
106
+ setPoint(point: IPointData): IBounds
107
+ setPoints(points: IPointData[]): IBounds
108
+ addPoint(point: IPointData): IBounds
109
+ getPoints(): IPointData[] // topLeft, topRight, bottomRight, bottomLeft
73
110
 
74
111
  hitPoint(point: IPointData, pointMatrix?: IMatrixData): boolean
75
112
  hitRadiusPoint(point: IRadiusPointData, pointMatrix?: IMatrixWithLayoutData): boolean
@@ -91,19 +128,15 @@ export interface ITwoPointBoundsData {
91
128
  maxY: number
92
129
  }
93
130
 
94
- export interface ITwoPointBounds extends ITwoPointBoundsData {
95
- addPoint(x: number, y: number): void
96
- addBounds(x: number, y: number, width: number, height: number): void
97
- add(pointBounds: ITwoPointBoundsData): void
98
- }
99
-
100
-
101
- export interface IAutoBoundsData {
131
+ export interface IAutoBoxData {
102
132
  top?: number
103
133
  right?: number
104
134
  bottom?: number
105
135
  left?: number
136
+ }
137
+
106
138
 
139
+ export interface IAutoBoundsData extends IAutoBoxData {
107
140
  width?: number
108
141
  height?: number
109
142
  }
@@ -125,17 +158,24 @@ export interface IMatrixData {
125
158
  f: number
126
159
  }
127
160
 
128
- export interface IMatrixDecompositionData {
129
- x: number
130
- y: number
161
+ export interface IScaleData {
131
162
  scaleX: number
132
163
  scaleY: number
164
+ }
165
+
166
+ export interface IScaleRotationData extends IScaleData {
133
167
  rotation: number
168
+ }
169
+
170
+ export interface ISkewData {
134
171
  skewX: number
135
172
  skewY: number
136
173
  }
137
174
 
138
- export type IMatrixDecompositionAttr =
175
+ export interface ILayoutData extends IScaleRotationData, ISkewData, IPointData {
176
+ }
177
+
178
+ export type ILayoutAttr =
139
179
  | 'x'
140
180
  | 'y'
141
181
  | 'scaleX'
@@ -144,15 +184,21 @@ export type IMatrixDecompositionAttr =
144
184
  | 'skewX'
145
185
  | 'skewY'
146
186
 
147
- export interface IMatrix extends IMatrixData {
148
- set(a: number, b: number, c: number, d: number, e: number, f: number): void
149
- copy(matrix: IMatrixData): IMatrix
187
+
188
+ export interface ILayoutBoundsData extends ILayoutData, IBoundsData {
189
+ }
190
+ export interface IMatrix extends IMatrixWithScaleData {
191
+
192
+ set(a: number | IMatrixData, b: number, c: number, d: number, e: number, f: number): IMatrix
193
+ setWith(dataWithScale: IMatrixWithScaleData): IMatrix // set scaleX scaleY
194
+ get(): IMatrixData
150
195
  clone(): IMatrix
151
196
 
152
197
  translate(x: number, y: number): IMatrix
153
198
  translateInner(x: number, y: number): IMatrix
154
199
 
155
200
  scale(x: number, y?: number): IMatrix
201
+ scaleWith(x: number, y?: number): IMatrix // change scaleX scaleY
156
202
  scaleOfOuter(origin: IPointData, x: number, y?: number): IMatrix
157
203
  scaleOfInner(origin: IPointData, x: number, y?: number): IMatrix
158
204
 
@@ -164,19 +210,34 @@ export interface IMatrix extends IMatrixData {
164
210
  skewOfOuter(origin: IPointData, x: number, y?: number): IMatrix
165
211
  skewOfInner(origin: IPointData, x: number, y?: number): IMatrix
166
212
 
167
- multiply(matrix: IMatrixData): IMatrix
168
- divide(matrix: IMatrixData): IMatrix
169
- preMultiply(matrix: IMatrixData): IMatrix
213
+ multiply(child: IMatrixData): IMatrix
214
+ multiplyParent(parent: IMatrixData): IMatrix
215
+
216
+ divide(child: IMatrixData): IMatrix
217
+ divideParent(parent: IMatrixData): IMatrix
170
218
  invert(): IMatrix
219
+ invertWith(): IMatrix // change scaleX scaleY
171
220
 
172
221
  toOuterPoint(inner: IPointData, to?: IPointData, distance?: boolean): void
173
222
  toInnerPoint(outer: IPointData, to?: IPointData, distance?: boolean): void
174
223
 
175
- decompose(): IMatrixDecompositionData
224
+ setLayout(data: ILayoutData, origin?: IPointData): IMatrix
225
+ getLayout(origin?: IPointData, firstSkewY?: boolean): ILayoutData
226
+
227
+ withScale(scaleX?: number, scaleY?: number): IMatrixWithScaleData
176
228
 
177
229
  reset(): void
178
230
  }
179
231
 
180
232
  export interface IMatrixWithBoundsData extends IMatrixData, IBoundsData { }
181
233
 
182
- export interface IMatrixWithLayoutData extends IMatrixData, IMatrixDecompositionData, IBoundsData { }
234
+ export interface IMatrixWithScaleData extends IMatrixData, IScaleData { }
235
+
236
+ export interface IMatrixWithOptionScaleData extends IMatrixData {
237
+ scaleX?: number
238
+ scaleY?: number
239
+ }
240
+
241
+ export interface IMatrixWithBoundsScaleData extends IMatrixData, IBoundsData, IScaleData { }
242
+
243
+ export interface IMatrixWithLayoutData extends IMatrixData, ILayoutBoundsData { }
@@ -16,8 +16,9 @@ export interface IPathDrawer {
16
16
  roundRect(x: number, y: number, width: number, height: number, radius?: number | number[]): void
17
17
  }
18
18
 
19
- export interface IPathCreator {
19
+ export interface IPathCreator extends IPathDrawer {
20
20
  path: IPathCommandData
21
+ __path: IPathCommandData
21
22
 
22
23
  beginPath(): IPathCreator
23
24
 
@@ -27,9 +28,9 @@ export interface IPathCreator {
27
28
  quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): IPathCreator
28
29
  closePath(): IPathCreator
29
30
 
30
- arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): IPathCreator
31
+ arc(x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): IPathCreator
31
32
  arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): IPathCreator
32
- ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean): IPathCreator
33
+ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): IPathCreator
33
34
 
34
35
  rect(x: number, y: number, width: number, height: number): IPathCreator
35
36
  roundRect(x: number, y: number, width: number, height: number, radius?: number | number[]): IPathCreator
@@ -38,4 +39,6 @@ export interface IPathCreator {
38
39
  drawEllipse(x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): IPathCreator
39
40
  drawArc(x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): IPathCreator
40
41
  drawPoints(points: number[], curve?: boolean | number, close?: boolean): IPathCreator
42
+
43
+ clearPath(): IPathCreator
41
44
  }
@@ -1,35 +1,53 @@
1
- import { IFunction } from '../function/IFunction'
1
+ import { IFunction, IStringFunction } from '../function/IFunction'
2
2
  import { ILeaferCanvas } from '../canvas/ILeaferCanvas'
3
3
  import { ILeaf } from '../display/ILeaf'
4
4
  import { IExportFileType, IExportImageType } from '../file/IFileType'
5
5
  import { IBoundsData, ISizeData } from '../math/IMath'
6
6
  import { IObject } from '../data/IData'
7
+ import { ICanvasType } from '../canvas/ISkiaCanvas'
7
8
 
8
9
  export interface IPlatform {
9
10
  name?: 'web' | 'node' | 'miniapp'
10
11
  os?: 'Mac' | 'Windows' | 'Linux'
12
+ toURL(text: string, fileType?: 'text' | 'svg'): string
11
13
  requestRender?(render: IFunction): void
12
14
  canvas?: ILeaferCanvas
15
+ canvasType?: ICanvasType
13
16
  isWorker?: boolean
14
17
  isMobile?: boolean
15
18
  devicePixelRatio?: number
16
19
  intWheelDeltaY?: boolean // firefox / Windows need
17
20
  conicGradientSupport?: boolean
18
21
  conicGradientRotate90?: boolean // firefox need rotate
19
- fullImageShadow?: boolean // safari need
22
+ fullImageShadow?: boolean // safari need
20
23
  syncDomFont?: boolean // firefox need
21
24
  layout?(target: ILeaf): void
22
- realtimeLayout?: boolean
23
25
  origin?: {
24
26
  createCanvas(width: number, height: number, format?: 'svg' | 'pdf'): any
25
27
  canvasToDataURL(canvas: any, type?: IExportImageType, quality?: number): string | Promise<string>
26
28
  canvasToBolb(canvas: any, type?: IExportFileType, quality?: number): Promise<any>
27
29
  canvasSaveAs(canvas: any, filename: string, quality?: number): Promise<void>
30
+ download(url: string, filename: string): Promise<void>
28
31
  loadImage(url: string): Promise<any>
29
32
  noRepeat?: string // fix: 微信小程序 createPattern 直接使用 no-repeat 有bug,导致无法显示
30
33
  },
34
+ roundRectPatch?: boolean // fix: skia-canvas roundRect
35
+ ellipseToCurve?: boolean, // fix: skia 绘制圆环和椭圆弧
36
+ event?: {
37
+ stopDefault(origin: IObject): void
38
+ stopNow(origin: IObject): void
39
+ stop(origin: IObject): void
40
+ },
31
41
  miniapp?: IMiniapp
32
- imageSuffix?: string // 需要带上后缀区分dom中image标签的缓存,否则会导致浏览器缓存跨域问题
42
+ image: {
43
+ hitCanvasSize: number // 图片生成碰撞画布的最大尺寸(单边)
44
+ maxCacheSize: number // 最大等级缓存,一般取当前屏幕大小,默认2k: 2560 * 1600
45
+ maxPatternSize: number // 最大repeat pattern缓存, 默认4k: 4096 * 2160
46
+ prefix?: string // url加前缀
47
+ suffix?: string // 需要带上后缀区分dom中image标签的缓存,否则会导致浏览器缓存跨域问题
48
+ crossOrigin: string | false // 跨域设置
49
+ getRealURL: IStringFunction // 处理前缀、后缀
50
+ }
33
51
  }
34
52
 
35
53
 
@@ -1,4 +1,4 @@
1
- import { ILeafer } from '../app/ILeafer'
1
+ import { ILeaferBase } from '../app/ILeafer'
2
2
  import { IObject } from '../data/IData'
3
3
 
4
4
  export interface IPlugin extends IObject {
@@ -6,5 +6,5 @@ export interface IPlugin extends IObject {
6
6
  importVersion: string
7
7
  import: string[]
8
8
  run(LeaferUI: IObject, config: IObject): void
9
- onLeafer?(leafer: ILeafer): void
9
+ onLeafer?(leafer: ILeaferBase): void
10
10
  }
@@ -1,13 +1,14 @@
1
1
  import { ILeaferCanvas } from '../canvas/ILeaferCanvas'
2
2
  import { ILeaf } from '../display/ILeaf'
3
- import { IBounds, IMatrix } from '../math/IMath'
3
+ import { IBounds, IMatrixWithScaleData } from '../math/IMath'
4
4
  import { IFunction } from '../function/IFunction'
5
5
  import { IControl } from '../control/IControl'
6
6
 
7
7
  export interface IRenderOptions {
8
+ includes?: boolean,
8
9
  bounds?: IBounds,
9
10
  hideBounds?: IBounds,
10
- matrix?: IMatrix,
11
+ matrix?: IMatrixWithScaleData,
11
12
  inCamera?: boolean
12
13
  }
13
14
 
@@ -31,6 +32,7 @@ export interface IRenderer extends IControl {
31
32
 
32
33
  waitAgain: boolean
33
34
  changed: boolean
35
+ ignore: boolean
34
36
 
35
37
  config: IRendererConfig
36
38
 
@@ -1,35 +1,64 @@
1
1
  import { ILeaf } from '../display/ILeaf'
2
2
  import { ILeafList } from '../data/IList'
3
3
  import { IPointData } from '../math/IMath'
4
+ import { IBranch } from '../display/IBranch'
4
5
 
5
- export interface ISelectPathResult {
6
- leaf: ILeaf
6
+ export interface IPickResult {
7
+ target: ILeaf
7
8
  path: ILeafList
8
9
  throughPath?: ILeafList
9
10
  }
10
11
 
11
- export interface ISelectPathOptions {
12
+ export interface IPickOptions {
12
13
  name?: string
14
+ hitRadius?: number
13
15
  through?: boolean
16
+ target?: IBranch
17
+ findList?: ILeaf[]
18
+ bottomList?: IPickBottom[] // 底部可拾取的虚拟元素
14
19
  exclude?: ILeafList
15
20
  ignoreHittable?: boolean
16
21
  }
17
22
 
23
+ export interface IPickBottom {
24
+ target: ILeaf
25
+ proxy?: ILeaf
26
+ }
27
+
18
28
  export interface ISelectorConfig {
19
29
 
20
30
  }
21
31
 
32
+ export type IAnswer = 0 | 1 | 2 | 3
33
+
34
+ export interface IFindCondition {
35
+ id?: number | string,
36
+ className?: string,
37
+ tag?: string | string[]
38
+ }
39
+
40
+ export interface IFindMethod {
41
+ (leaf: ILeaf, options?: any): IAnswer
42
+ }
43
+
44
+ export interface ISelectorProxy {
45
+ list: ILeaf[]
46
+ }
47
+
22
48
  export interface ISelector {
23
49
  target: ILeaf
24
50
 
51
+ proxy?: ISelectorProxy
52
+
25
53
  config: ISelectorConfig
26
54
 
27
- getByPoint(hitPoint: IPointData, hitRadius: number, options?: ISelectPathOptions): ISelectPathResult
55
+ getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult
28
56
 
29
- find(name: number | string, branch?: ILeaf): ILeaf | ILeaf[]
30
- getByInnerId(name: number, branch?: ILeaf): ILeaf
31
- getById(name: string, branch?: ILeaf): ILeaf
32
- getByClassName(name: string, branch?: ILeaf): ILeaf[]
33
- getByTagName(name: string, branch?: ILeaf): ILeaf[]
57
+ getBy(condition: number | string | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[]
58
+ getByInnerId(innerId: number, branch?: ILeaf): ILeaf
59
+ getById(id: string, branch?: ILeaf): ILeaf
60
+ getByClassName(className: string, branch?: ILeaf): ILeaf[]
61
+ getByTag(tag: string, branch?: ILeaf): ILeaf[]
62
+ getByMethod(method: IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[]
34
63
  destroy(): void
35
64
  }