@leafer/display 1.0.0-beta.12 → 1.0.0-beta.15

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,12 +1,15 @@
1
1
  {
2
2
  "name": "@leafer/display",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.15",
4
4
  "description": "@leafer/display",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
7
  "main": "src/index.ts",
8
+ "types": "types/index.d.ts",
8
9
  "files": [
9
- "src"
10
+ "src",
11
+ "types",
12
+ "dist"
10
13
  ],
11
14
  "repository": {
12
15
  "type": "git",
@@ -19,15 +22,16 @@
19
22
  "leaferjs"
20
23
  ],
21
24
  "dependencies": {
22
- "@leafer/math": "1.0.0-beta.12",
23
- "@leafer/data": "1.0.0-beta.12",
24
- "@leafer/layout": "1.0.0-beta.12",
25
- "@leafer/display-module": "1.0.0-beta.12",
26
- "@leafer/event": "1.0.0-beta.12",
27
- "@leafer/decorator": "1.0.0-beta.12",
28
- "@leafer/helper": "1.0.0-beta.12"
25
+ "@leafer/math": "1.0.0-beta.15",
26
+ "@leafer/data": "1.0.0-beta.15",
27
+ "@leafer/layout": "1.0.0-beta.15",
28
+ "@leafer/display-module": "1.0.0-beta.15",
29
+ "@leafer/event": "1.0.0-beta.15",
30
+ "@leafer/decorator": "1.0.0-beta.15",
31
+ "@leafer/helper": "1.0.0-beta.15",
32
+ "@leafer/platform": "1.0.0-beta.15"
29
33
  },
30
34
  "devDependencies": {
31
- "@leafer/interface": "1.0.0-beta.12"
35
+ "@leafer/interface": "1.0.0-beta.15"
32
36
  }
33
37
  }
package/src/Branch.ts CHANGED
@@ -81,12 +81,16 @@ export class Branch extends Leaf {
81
81
 
82
82
  if (this.leafer) {
83
83
  child.__bindLeafer(this.leafer)
84
- if (this.leafer.ready) this.__emitChildEvent(ChildEvent.ADD, child)
84
+ if (this.leafer.created) this.__emitChildEvent(ChildEvent.ADD, child)
85
85
  }
86
86
 
87
87
  this.__layout.affectChildrenSort && this.__layout.childrenSortChange()
88
88
  }
89
89
 
90
+ public addMany(...children: ILeaf[]): void {
91
+ children.forEach(child => this.add(child))
92
+ }
93
+
90
94
  public remove(child?: Leaf, destroy?: boolean): void {
91
95
  if (child) {
92
96
  const index = this.children.indexOf(child)
@@ -126,8 +130,10 @@ export class Branch extends Leaf {
126
130
  child.parent = null
127
131
  if (this.leafer) {
128
132
  child.__bindLeafer(null)
129
- if (this.leafer.ready) this.__emitChildEvent(ChildEvent.REMOVE, child)
130
- this.leafer.hitCanvasManager.clear()
133
+ if (this.leafer.created) {
134
+ this.__emitChildEvent(ChildEvent.REMOVE, child)
135
+ if (this.leafer.hitCanvasManager) this.leafer.hitCanvasManager.clear()
136
+ }
131
137
  }
132
138
  }
133
139
 
@@ -137,4 +143,5 @@ export class Branch extends Leaf {
137
143
  if (this.hasEvent(type) && !this.isLeafer) this.emitEvent(event)
138
144
  this.leafer.emitEvent(event)
139
145
  }
146
+
140
147
  }
package/src/Leaf.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeafer, ILeaf, ILeafInputData, ILeafData, ILeaferCanvas, IRenderOptions, IMatrixWithBoundsData, __Number, __Boolean, __Value, ILeafLayout, InnerId, IHitCanvas, IRadiusPointData, IEventListenerMap, IEventListener, IEventListenerOptions, IEventListenerId, IEvent, IObject, IFunction, __String, IPointData, IMatrixDecompositionAttr, ILayoutBoundsType, ILayoutLocationType, IBoundsData, IMatrixData, IBranch } from '@leafer/interface'
1
+ import { ILeafer, ILeaf, ILeafInputData, ILeafData, ILeaferCanvas, IRenderOptions, IMatrixWithBoundsData, __Number, __Boolean, __Value, ILeafLayout, InnerId, IHitCanvas, IRadiusPointData, IEventListenerMap, IEventListener, IEventListenerOptions, IEventListenerId, IEvent, IObject, IFunction, __String, IPointData, IMatrixDecompositionAttr, ILayoutBoundsType, ILayoutLocationType, IBoundsData, IBranch, IMatrixWithLayoutData } from '@leafer/interface'
2
2
  import { IncrementId, MatrixHelper, PointHelper } from '@leafer/math'
3
3
  import { LeafData } from '@leafer/data'
4
4
  import { LeafLayout } from '@leafer/layout'
@@ -10,7 +10,7 @@ import { LeafHelper, WaitHelper } from '@leafer/helper'
10
10
  const { LEAF, create } = IncrementId
11
11
  const { toInnerPoint, toOuterPoint } = MatrixHelper
12
12
  const { tempToOuterOf, copy } = PointHelper
13
- const { moveLocal, zoomOfLocal, rotateOfLocal } = LeafHelper
13
+ const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal } = LeafHelper
14
14
 
15
15
  @useModule(LeafDataProxy)
16
16
  @useModule(LeafMatrix)
@@ -41,15 +41,17 @@ export class Leaf implements ILeaf {
41
41
  public __: ILeafData
42
42
  public __layout: ILeafLayout
43
43
 
44
+ public __world: IMatrixWithLayoutData
44
45
  public __local: IMatrixWithBoundsData
45
- public __world: IMatrixWithBoundsData
46
+
46
47
  public __worldOpacity: number
47
48
 
48
49
  // now transform
49
- public get worldTransform(): IMatrixData { return this.__layout.getTransform('world') }
50
- public get localTransform(): IMatrixData { return this.__layout.getTransform('local') }
50
+ public get worldTransform(): IMatrixWithLayoutData { return this.__layout.getTransform('world') as IMatrixWithLayoutData }
51
+ public get localTransform(): IMatrixWithBoundsData { return this.__layout.getTransform('local') as IMatrixWithBoundsData }
51
52
 
52
53
  // now bounds
54
+ public get boxBounds(): IBoundsData { return this.getBounds('box', 'inner') }
53
55
  public get worldBoxBounds(): IBoundsData { return this.getBounds('box') }
54
56
  public get worldStrokeBounds(): IBoundsData { return this.getBounds('stroke') }
55
57
  public get worldRenderBounds(): IBoundsData { return this.getBounds('render') }
@@ -60,6 +62,10 @@ export class Leaf implements ILeaf {
60
62
  public __level: number // layer level 0 -> branch -> branch -> deep
61
63
  public __tempNumber: number // temp sort
62
64
 
65
+ public get resizeable(): boolean { return true }
66
+
67
+ public get __hasMirror(): boolean { return this.__world.scaleX < 0 || this.__world.scaleY < 0 }
68
+
63
69
  public __hasMask?: boolean
64
70
  public __hasEraser?: boolean
65
71
  public __hitCanvas?: IHitCanvas
@@ -85,15 +91,21 @@ export class Leaf implements ILeaf {
85
91
 
86
92
  this.innerId = create(LEAF)
87
93
 
94
+ this.__world = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1, rotation: 0, skewX: 0, skewY: 0 }
88
95
  this.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 }
89
- this.__world = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1 }
90
96
 
91
97
  this.__worldOpacity = 1
92
98
 
93
99
  this.__ = new this.__DataProcessor(this)
94
100
  this.__layout = new this.__LayoutProcessor(this)
95
101
 
96
- if (data) Object.assign(this, data)
102
+ if (data) {
103
+ if (data.children) {
104
+ this.set(data)
105
+ } else {
106
+ Object.assign(this, data)
107
+ }
108
+ }
97
109
  }
98
110
 
99
111
 
@@ -105,6 +117,9 @@ export class Leaf implements ILeaf {
105
117
  this.leafer ? item() : (this.__leaferWait ? this.__leaferWait.push(item) : this.__leaferWait = [item])
106
118
  }
107
119
 
120
+ public nextRender(item: IFunction): void {
121
+ this.leafer ? this.leafer.nextRender(item) : this.waitLeafer(() => this.leafer.nextRender(item))
122
+ }
108
123
 
109
124
  public __bindLeafer(leafer: ILeafer | null): void {
110
125
  if (this.isLeafer) {
@@ -126,10 +141,17 @@ export class Leaf implements ILeaf {
126
141
  }
127
142
  }
128
143
 
144
+ // data
145
+
129
146
  public set(_data: IObject): void { }
130
147
 
131
- public get(_attrNames?: string[]): IObject { return undefined }
148
+ public toJSON(): IObject {
149
+ return this.__.__getInputData()
150
+ }
132
151
 
152
+ public toString(): string {
153
+ return JSON.stringify(this.toJSON())
154
+ }
133
155
 
134
156
  // LeafDataProxy rewrite
135
157
 
@@ -140,9 +162,10 @@ export class Leaf implements ILeaf {
140
162
  // ---
141
163
 
142
164
  public forceUpdate(attrName?: string): void {
143
- if (attrName === undefined) attrName = 'x'
165
+ if (attrName === undefined) attrName = 'scaleX'
144
166
  else if (attrName === 'surface') attrName = 'blendMode'
145
- const value = this.__.__getInput(attrName);
167
+ const value = this.__.__getInput(attrName)
168
+ this.__[attrName] = value === undefined ? null : undefined;
146
169
  (this as any)[attrName] = value
147
170
  }
148
171
 
@@ -175,6 +198,9 @@ export class Leaf implements ILeaf {
175
198
  public __updateRenderBounds(): void { }
176
199
 
177
200
 
201
+ public __updateNaturalSize(): void { }
202
+
203
+
178
204
  public __updateStrokeSpread(): number { return 0 }
179
205
 
180
206
  public __updateRenderSpread(): number { return 0 }
@@ -200,7 +226,10 @@ export class Leaf implements ILeaf {
200
226
  // convert
201
227
 
202
228
  public getWorld(attrName: IMatrixDecompositionAttr): number {
203
- return this.__layout.decomposeTransform('world')[attrName]
229
+ this.__layout.checkUpdate()
230
+ if (attrName === 'x') return this.__world.e
231
+ if (attrName === 'y') return this.__world.f
232
+ return this.__world[attrName]
204
233
  }
205
234
 
206
235
  public getBounds(type: ILayoutBoundsType, locationType: ILayoutLocationType = 'world'): IBoundsData {
@@ -208,28 +237,67 @@ export class Leaf implements ILeaf {
208
237
  }
209
238
 
210
239
 
211
- public worldToLocal(world: IPointData, to?: IPointData, isMovePoint?: boolean): void {
240
+ public worldToLocal(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void {
212
241
  if (this.parent) {
213
- toInnerPoint(this.parent.worldTransform, world, to, isMovePoint)
242
+ this.parent.worldToInner(world, to, distance, relative)
214
243
  } else {
215
244
  if (to) copy(to, world)
216
245
  }
217
246
  }
218
247
 
219
- public localToWorld(local: IPointData, to?: IPointData, isMovePoint?: boolean): void {
248
+ public localToWorld(local: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void {
220
249
  if (this.parent) {
221
- toOuterPoint(this.parent.worldTransform, local, to, isMovePoint)
250
+ this.parent.innerToWorld(local, to, distance, relative)
222
251
  } else {
223
252
  if (to) copy(to, local)
224
253
  }
225
254
  }
226
255
 
227
- public worldToInner(world: IPointData, to?: IPointData, isMovePoint?: boolean): void {
228
- toInnerPoint(this.worldTransform, world, to, isMovePoint)
256
+ public worldToInner(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void {
257
+ if (relative) {
258
+ relative.innerToWorld(world, to, distance)
259
+ world = to ? to : world
260
+ }
261
+ toInnerPoint(this.worldTransform, world, to, distance)
229
262
  }
230
263
 
231
- public innerToWorld(inner: IPointData, to?: IPointData, isMovePoint?: boolean): void {
232
- toOuterPoint(this.worldTransform, inner, to, isMovePoint)
264
+ public innerToWorld(inner: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void {
265
+ toOuterPoint(this.worldTransform, inner, to, distance)
266
+ if (relative) relative.worldToInner(to ? to : inner, null, distance)
267
+ }
268
+
269
+ // simple
270
+
271
+ public getInnerPoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
272
+ const point = change ? world : {} as IPointData
273
+ this.worldToInner(world, point, distance, relative)
274
+ return point
275
+ }
276
+
277
+ public getInnerPointByLocal(local: IPointData, _relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
278
+ return this.getInnerPoint(local, this.parent, distance, change)
279
+ }
280
+
281
+ public getLocalPoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
282
+ const point = change ? world : {} as IPointData
283
+ this.worldToLocal(world, point, distance, relative)
284
+ return point
285
+ }
286
+
287
+ public getLocalPointByInner(inner: IPointData, _relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
288
+ return this.getWorldPoint(inner, this.parent, distance, change)
289
+ }
290
+
291
+ public getWorldPoint(inner: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
292
+ const point = change ? inner : {} as IPointData
293
+ this.innerToWorld(inner, point, distance, relative)
294
+ return point
295
+ }
296
+
297
+ public getWorldPointByLocal(local: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
298
+ const point = change ? local : {} as IPointData
299
+ this.localToWorld(local, point, distance, relative)
300
+ return point
233
301
  }
234
302
 
235
303
 
@@ -240,13 +308,15 @@ export class Leaf implements ILeaf {
240
308
  }
241
309
 
242
310
  public scaleOf(origin: IPointData, x: number, y?: number): void {
243
- this.__layout.checkUpdate()
244
- zoomOfLocal(this, tempToOuterOf(origin, this.__local), x, y)
311
+ zoomOfLocal(this, tempToOuterOf(origin, this.localTransform), x, y)
245
312
  }
246
313
 
247
314
  public rotateOf(origin: IPointData, angle: number): void {
248
- this.__layout.checkUpdate()
249
- rotateOfLocal(this, tempToOuterOf(origin, this.__local), angle)
315
+ rotateOfLocal(this, tempToOuterOf(origin, this.localTransform), angle)
316
+ }
317
+
318
+ public skewOf(origin: IPointData, x: number, y: number): void {
319
+ skewOfLocal(this, tempToOuterOf(origin, this.localTransform), x, y)
250
320
  }
251
321
 
252
322
 
@@ -325,6 +395,7 @@ export class Leaf implements ILeaf {
325
395
 
326
396
  // ---
327
397
 
398
+
328
399
  public destroy(): void {
329
400
  if (!this.destroyed) {
330
401
  if (this.parent) this.remove()
@@ -0,0 +1,134 @@
1
+ import { ILeaf, InnerId, ILeafer, ILeafData, ILeafLayout, IMatrixWithLayoutData, IMatrixWithBoundsData, IBoundsData, IHitCanvas, IEventListenerMap, IFunction, ILeafInputData, IObject, __Value, ILeaferCanvas, IMatrixDecompositionAttr, ILayoutBoundsType, ILayoutLocationType, IPointData, IRadiusPointData, IRenderOptions, IEventListener, IEventListenerOptions, IEventListenerId, IEvent } from '@leafer/interface';
2
+ import { LeafData } from '@leafer/data';
3
+ import { LeafLayout } from '@leafer/layout';
4
+
5
+ declare class Leaf implements ILeaf {
6
+ get tag(): string;
7
+ set tag(_value: string);
8
+ get __tag(): string;
9
+ readonly innerId: InnerId;
10
+ get innerName(): string;
11
+ get __DataProcessor(): typeof LeafData;
12
+ get __LayoutProcessor(): typeof LeafLayout;
13
+ leafer?: ILeafer;
14
+ parent?: ILeaf;
15
+ isLeafer: boolean;
16
+ isBranch: boolean;
17
+ isBranchLeaf: boolean;
18
+ __: ILeafData;
19
+ __layout: ILeafLayout;
20
+ __world: IMatrixWithLayoutData;
21
+ __local: IMatrixWithBoundsData;
22
+ __worldOpacity: number;
23
+ get worldTransform(): IMatrixWithLayoutData;
24
+ get localTransform(): IMatrixWithBoundsData;
25
+ get boxBounds(): IBoundsData;
26
+ get worldBoxBounds(): IBoundsData;
27
+ get worldStrokeBounds(): IBoundsData;
28
+ get worldRenderBounds(): IBoundsData;
29
+ get worldOpacity(): number;
30
+ __level: number;
31
+ __tempNumber: number;
32
+ get resizeable(): boolean;
33
+ get __hasMirror(): boolean;
34
+ __hasMask?: boolean;
35
+ __hasEraser?: boolean;
36
+ __hitCanvas?: IHitCanvas;
37
+ get __onlyHitMask(): boolean;
38
+ get __ignoreHitWorld(): boolean;
39
+ __captureMap?: IEventListenerMap;
40
+ __bubbleMap?: IEventListenerMap;
41
+ __parentWait?: IFunction[];
42
+ __leaferWait?: IFunction[];
43
+ children?: ILeaf[];
44
+ destroyed: boolean;
45
+ constructor(data?: ILeafInputData);
46
+ waitParent(item: IFunction): void;
47
+ waitLeafer(item: IFunction): void;
48
+ waitRender(item: IFunction): void;
49
+ __bindLeafer(leafer: ILeafer | null): void;
50
+ set(_data: IObject): void;
51
+ toJSON(): IObject;
52
+ toString(): string;
53
+ __setAttr(_attrName: string, _newValue: __Value): void;
54
+ __getAttr(_attrName: string): __Value;
55
+ forceUpdate(attrName?: string): void;
56
+ __updateWorldMatrix(): void;
57
+ __updateLocalMatrix(): void;
58
+ __updateWorldBounds(): void;
59
+ __updateLocalBoxBounds(): void;
60
+ __updateLocalStrokeBounds(): void;
61
+ __updateLocalRenderBounds(): void;
62
+ __updateBoxBounds(): void;
63
+ __updateStrokeBounds(): void;
64
+ __updateRenderBounds(): void;
65
+ __updateNaturalSize(): void;
66
+ __updateStrokeSpread(): number;
67
+ __updateRenderSpread(): number;
68
+ __onUpdateSize(): void;
69
+ __updateEraser(_value?: boolean): void;
70
+ __updateMask(_value?: boolean): void;
71
+ __renderMask(_canvas: ILeaferCanvas, _content: ILeaferCanvas, _mask: ILeaferCanvas): void;
72
+ __removeMask(_child?: ILeaf): void;
73
+ getWorld(attrName: IMatrixDecompositionAttr): number;
74
+ getBounds(type: ILayoutBoundsType, locationType?: ILayoutLocationType): IBoundsData;
75
+ worldToLocal(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
76
+ localToWorld(local: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
77
+ worldToInner(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
78
+ innerToWorld(inner: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
79
+ getInnerPoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
80
+ getInnerPointByLocal(local: IPointData, _relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
81
+ getLocalPoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
82
+ getLocalPointByInner(inner: IPointData, _relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
83
+ getWorldPoint(inner: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
84
+ getWorldPointByLocal(local: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
85
+ move(x: number, y?: number): void;
86
+ scaleOf(origin: IPointData, x: number, y?: number): void;
87
+ rotateOf(origin: IPointData, angle: number): void;
88
+ skewOf(origin: IPointData, x: number, y: number): void;
89
+ __hitWorld(_point: IRadiusPointData): boolean;
90
+ __hit(_local: IRadiusPointData): boolean;
91
+ __drawHitPath(_canvas: ILeaferCanvas): void;
92
+ __updateHitCanvas(): void;
93
+ __render(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
94
+ __drawFast(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
95
+ __draw(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
96
+ __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
97
+ __updateWorldOpacity(): void;
98
+ __updateChange(): void;
99
+ __drawPath(_canvas: ILeaferCanvas): void;
100
+ __drawRenderPath(_canvas: ILeaferCanvas): void;
101
+ __updatePath(): void;
102
+ __updateRenderPath(): void;
103
+ __updateSortChildren(): void;
104
+ add(_child: ILeaf, _index?: number): void;
105
+ remove(_child?: ILeaf, destroy?: boolean): void;
106
+ on(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void;
107
+ off(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void;
108
+ on_(_type: string | string[], _listener: IEventListener, _bind?: IObject, _options?: IEventListenerOptions | boolean): IEventListenerId;
109
+ off_(_id: IEventListenerId | IEventListenerId[]): void;
110
+ once(_type: string | string[], _listener: IEventListener, _capture?: boolean): void;
111
+ emit(_type: string, _event?: IEvent | IObject, _capture?: boolean): void;
112
+ emitEvent(_event?: IEvent, _capture?: boolean): void;
113
+ hasEvent(_type: string, _capture?: boolean): boolean;
114
+ destroy(): void;
115
+ }
116
+
117
+ declare class Branch extends Leaf {
118
+ constructor();
119
+ __updateStrokeSpread(): number;
120
+ __updateRenderSpread(): number;
121
+ __updateBoxBounds(): void;
122
+ __updateStrokeBounds(): void;
123
+ __updateRenderBounds(): void;
124
+ __updateSortChildren(): void;
125
+ add(child: ILeaf, index?: number): void;
126
+ addMany(...children: ILeaf[]): void;
127
+ remove(child?: Leaf, destroy?: boolean): void;
128
+ removeAll(destroy?: boolean): void;
129
+ protected __preRemove(): void;
130
+ protected __realRemoveChild(child: ILeaf): void;
131
+ protected __emitChildEvent(type: string, child: ILeaf): void;
132
+ }
133
+
134
+ export { Branch, Leaf };