@leafer/display 1.0.0-rc.16 → 1.0.0-rc.18

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/display",
3
- "version": "1.0.0-rc.16",
3
+ "version": "1.0.0-rc.18",
4
4
  "description": "@leafer/display",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,16 +22,16 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/math": "1.0.0-rc.16",
26
- "@leafer/data": "1.0.0-rc.16",
27
- "@leafer/layout": "1.0.0-rc.16",
28
- "@leafer/display-module": "1.0.0-rc.16",
29
- "@leafer/event": "1.0.0-rc.16",
30
- "@leafer/decorator": "1.0.0-rc.16",
31
- "@leafer/helper": "1.0.0-rc.16",
32
- "@leafer/platform": "1.0.0-rc.16"
25
+ "@leafer/math": "1.0.0-rc.18",
26
+ "@leafer/data": "1.0.0-rc.18",
27
+ "@leafer/layout": "1.0.0-rc.18",
28
+ "@leafer/display-module": "1.0.0-rc.18",
29
+ "@leafer/event": "1.0.0-rc.18",
30
+ "@leafer/decorator": "1.0.0-rc.18",
31
+ "@leafer/helper": "1.0.0-rc.18",
32
+ "@leafer/platform": "1.0.0-rc.18"
33
33
  },
34
34
  "devDependencies": {
35
- "@leafer/interface": "1.0.0-rc.16"
35
+ "@leafer/interface": "1.0.0-rc.18"
36
36
  }
37
37
  }
package/src/Branch.ts CHANGED
@@ -70,7 +70,9 @@ export class Branch extends Leaf {
70
70
 
71
71
  index === undefined ? this.children.push(child) : this.children.splice(index, 0, child)
72
72
  if (child.isBranch) this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1
73
- child.__layout.boundsChanged || child.__layout.matrixChange() // layouted(removed), need update
73
+
74
+ child.__layout.boxChanged || child.__layout.boxChange() // layouted(removed), need update
75
+ child.__layout.matrixChanged || child.__layout.matrixChange() // layouted(removed), need update
74
76
 
75
77
  if (child.__parentWait) WaitHelper.run(child.__parentWait)
76
78
 
package/src/Leaf.ts CHANGED
@@ -12,7 +12,7 @@ const { LEAF, create } = IncrementId
12
12
  const { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper
13
13
  const { toOuterOf } = BoundsHelper
14
14
  const { tempToOuterOf, copy } = PointHelper
15
- const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, transform, setTransform, drop } = LeafHelper
15
+ const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getRelativeWorld, drop } = LeafHelper
16
16
 
17
17
  @useModule(LeafDataProxy)
18
18
  @useModule(LeafMatrix)
@@ -116,7 +116,10 @@ export class Leaf implements ILeaf {
116
116
  this.__layout = new this.__LayoutProcessor(this)
117
117
 
118
118
  if (this.__level) this.resetCustom()
119
- if (data) data.children ? this.set(data) : Object.assign(this, data)
119
+ if (data) {
120
+ if ((data as ILeaf).__) data = (data as ILeaf).toJSON()
121
+ data.children ? this.set(data) : Object.assign(this, data)
122
+ }
120
123
  }
121
124
 
122
125
  public resetCustom(): void {
@@ -125,16 +128,22 @@ export class Leaf implements ILeaf {
125
128
  }
126
129
 
127
130
 
128
- public waitParent(item: IFunction): void {
131
+ public waitParent(item: IFunction, bind?: IObject): void {
132
+ if (bind) item = item.bind(bind)
129
133
  this.parent ? item() : (this.__parentWait ? this.__parentWait.push(item) : this.__parentWait = [item])
130
134
  }
131
135
 
132
- public waitLeafer(item: IFunction): void {
136
+ public waitLeafer(item: IFunction, bind?: IObject): void {
137
+ if (bind) item = item.bind(bind)
133
138
  this.leafer ? item() : (this.__leaferWait ? this.__leaferWait.push(item) : this.__leaferWait = [item])
134
139
  }
135
140
 
136
- public nextRender(item: IFunction, off?: 'off'): void {
137
- this.leafer ? this.leafer.nextRender(item, off) : this.waitLeafer(() => this.leafer.nextRender(item, off))
141
+ public nextRender(item: IFunction, bind?: IObject, off?: 'off'): void {
142
+ this.leafer ? this.leafer.nextRender(item, bind, off) : this.waitLeafer(() => this.leafer.nextRender(item, bind, off))
143
+ }
144
+
145
+ public removeNextRender(item: IFunction): void {
146
+ this.nextRender(item, null, 'off')
138
147
  }
139
148
 
140
149
  public __bindLeafer(leafer: ILeaferBase | null): void {
@@ -194,6 +203,14 @@ export class Leaf implements ILeaf {
194
203
 
195
204
  // ---
196
205
 
206
+
207
+ // state
208
+
209
+ public focus(_value?: boolean): void { }
210
+
211
+ // ---
212
+
213
+
197
214
  public forceUpdate(attrName?: string): void {
198
215
  if (attrName === undefined) attrName = 'width'
199
216
  else if (attrName === 'surface') attrName = 'blendMode'
@@ -288,6 +305,11 @@ export class Leaf implements ILeaf {
288
305
  return this.getLayoutBounds()[attrName]
289
306
  }
290
307
 
308
+ public getTransform(relative?: ILocationType | ILeaf): IMatrixData {
309
+ return this.__layout.getTransform(relative || 'local')
310
+ }
311
+
312
+
291
313
  public getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData {
292
314
  return this.__layout.getBounds(type, relative)
293
315
  }
@@ -301,6 +323,14 @@ export class Leaf implements ILeaf {
301
323
  }
302
324
 
303
325
 
326
+ public getWorldBounds(inner: IBoundsData, relative?: ILeaf, change?: boolean): IBoundsData {
327
+ const matrix = relative ? getRelativeWorld(this, relative) : this.worldTransform
328
+ const to = change ? inner : {} as IBoundsData
329
+ toOuterOf(inner, matrix, to)
330
+ return to
331
+ }
332
+
333
+
304
334
  public worldToLocal(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void {
305
335
  if (this.parent) {
306
336
  this.parent.worldToInner(world, to, distance, relative)
@@ -375,7 +405,7 @@ export class Leaf implements ILeaf {
375
405
  }
376
406
 
377
407
 
378
- // transform
408
+ // transform
379
409
 
380
410
  public setTransform(matrix: IMatrixData, resize?: boolean): void {
381
411
  setTransform(this, matrix, resize)
@@ -401,6 +431,28 @@ export class Leaf implements ILeaf {
401
431
  skewOfLocal(this, tempToOuterOf(origin, this.localTransform), skewX, skewY, resize)
402
432
  }
403
433
 
434
+
435
+ public transformWorld(worldTransform?: IMatrixData, resize?: boolean): void {
436
+ transformWorld(this, worldTransform, resize)
437
+ }
438
+
439
+ public moveWorld(x: number, y?: number): void {
440
+ moveWorld(this, x, y)
441
+ }
442
+
443
+ public scaleOfWorld(worldOrigin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
444
+ zoomOfWorld(this, worldOrigin, scaleX, scaleY, resize)
445
+ }
446
+
447
+ public rotateOfWorld(worldOrigin: IPointData, rotation: number): void {
448
+ rotateOfWorld(this, worldOrigin, rotation)
449
+ }
450
+
451
+ public skewOfWorld(worldOrigin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
452
+ skewOfWorld(this, worldOrigin, skewX, skewY, resize)
453
+ }
454
+
455
+
404
456
  // @leafer-ui/scale rewrite
405
457
 
406
458
  public scaleResize(scaleX: number, scaleY = scaleX, _noResize?: boolean): void {
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaf, InnerId, ILeaferBase, ILeafData, ILeafLayout, IMatrixWithBoundsScaleData, IMatrixWithBoundsData, IMatrixData, IBoundsData, IMatrixWithScaleData, IHitCanvas, IEventListenerMap, IFunction, ILeafInputData, IObject, IValue, IFindMethod, ILeaferCanvas, IRenderOptions, ILayoutAttr, IBoundsType, ILocationType, ILayoutBoundsData, IPointData, IRadiusPointData, IEventListener, IEventListenerOptions, IEventListenerId, IEvent, IAttrDecorator } from '@leafer/interface';
1
+ import { ILeaf, InnerId, ILeaferBase, ILeafData, ILeafLayout, IMatrixWithBoundsScaleData, IMatrixWithBoundsData, IMatrixData, IBoundsData, IMatrixWithScaleData, IHitCanvas, IEventListenerMap, IFunction, ILeafInputData, IObject, IValue, IFindMethod, ILeaferCanvas, IRenderOptions, ILayoutAttr, ILocationType, IBoundsType, ILayoutBoundsData, IPointData, IRadiusPointData, IEventListener, IEventListenerOptions, IEventListenerId, IEvent, IAttrDecorator } from '@leafer/interface';
2
2
  import { LeafData } from '@leafer/data';
3
3
  import { LeafLayout } from '@leafer/layout';
4
4
 
@@ -53,9 +53,10 @@ declare class Leaf implements ILeaf {
53
53
  constructor(data?: ILeafInputData);
54
54
  reset(data?: ILeafInputData): void;
55
55
  resetCustom(): void;
56
- waitParent(item: IFunction): void;
57
- waitLeafer(item: IFunction): void;
58
- nextRender(item: IFunction, off?: 'off'): void;
56
+ waitParent(item: IFunction, bind?: IObject): void;
57
+ waitLeafer(item: IFunction, bind?: IObject): void;
58
+ nextRender(item: IFunction, bind?: IObject, off?: 'off'): void;
59
+ removeNextRender(item: IFunction): void;
59
60
  __bindLeafer(leafer: ILeaferBase | null): void;
60
61
  set(_data: IObject): void;
61
62
  get(_name?: string): ILeafInputData | IValue;
@@ -67,6 +68,7 @@ declare class Leaf implements ILeaf {
67
68
  getProxyAttr(_attrName: string): IValue;
68
69
  find(_condition: number | string | IFindMethod, _options?: any): ILeaf[];
69
70
  findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf;
71
+ focus(_value?: boolean): void;
70
72
  forceUpdate(attrName?: string): void;
71
73
  updateLayout(): void;
72
74
  __updateWorldMatrix(): void;
@@ -89,9 +91,11 @@ declare class Leaf implements ILeaf {
89
91
  __renderMask(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
90
92
  __getNowWorld(options: IRenderOptions): IMatrixWithBoundsScaleData;
91
93
  getWorld(attrName: ILayoutAttr): number;
94
+ getTransform(relative?: ILocationType | ILeaf): IMatrixData;
92
95
  getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData;
93
96
  getLayoutBounds(type?: IBoundsType, relative?: ILocationType | ILeaf, unscale?: boolean): ILayoutBoundsData;
94
97
  getLayoutPoints(type?: IBoundsType, relative?: ILocationType | ILeaf): IPointData[];
98
+ getWorldBounds(inner: IBoundsData, relative?: ILeaf, change?: boolean): IBoundsData;
95
99
  worldToLocal(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
96
100
  localToWorld(local: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
97
101
  worldToInner(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
@@ -110,6 +114,11 @@ declare class Leaf implements ILeaf {
110
114
  scaleOf(origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
111
115
  rotateOf(origin: IPointData, rotation: number): void;
112
116
  skewOf(origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
117
+ transformWorld(worldTransform?: IMatrixData, resize?: boolean): void;
118
+ moveWorld(x: number, y?: number): void;
119
+ scaleOfWorld(worldOrigin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
120
+ rotateOfWorld(worldOrigin: IPointData, rotation: number): void;
121
+ skewOfWorld(worldOrigin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
113
122
  scaleResize(scaleX: number, scaleY?: number, _noResize?: boolean): void;
114
123
  __scaleResize(_scaleX: number, _scaleY: number): void;
115
124
  __hitWorld(_point: IRadiusPointData): boolean;