@leafer/display-module 1.0.0-alpha.21 → 1.0.0-alpha.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/display-module",
3
- "version": "1.0.0-alpha.21",
3
+ "version": "1.0.0-alpha.30",
4
4
  "description": "@leafer/display-module",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,10 +19,10 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "dependencies": {
22
- "@leafer/event": "1.0.0-alpha.21",
23
- "@leafer/math": "1.0.0-alpha.21"
22
+ "@leafer/event": "1.0.0-alpha.30",
23
+ "@leafer/math": "1.0.0-alpha.30"
24
24
  },
25
25
  "devDependencies": {
26
- "@leafer/interface": "1.0.0-alpha.21"
26
+ "@leafer/interface": "1.0.0-alpha.30"
27
27
  }
28
28
  }
package/src/LeafBounds.ts CHANGED
@@ -2,7 +2,7 @@ import { ILeafBoundsModule } from '@leafer/interface'
2
2
  import { BoundsHelper } from '@leafer/math'
3
3
 
4
4
 
5
- const { toWorld, copyAndSpread } = BoundsHelper
5
+ const { toOuterOf, copyAndSpread } = BoundsHelper
6
6
 
7
7
  export const LeafBounds: ILeafBoundsModule = {
8
8
 
@@ -27,36 +27,36 @@ export const LeafBounds: ILeafBoundsModule = {
27
27
 
28
28
  if (layout.localBoxBoundsChanged) { // position change
29
29
 
30
- this.__updateRelativeBoxBounds()
30
+ this.__updateLocalBoxBounds()
31
31
  layout.localBoxBoundsChanged = false
32
32
 
33
- if (layout.eventBoundsSpreadWidth) layout.eventBoundsChanged = true
33
+ if (layout.strokeBoundsSpreadWidth) layout.strokeBoundsChanged = true
34
34
  if (layout.renderBoundsSpreadWidth) layout.renderBoundsChanged = true
35
35
  this.parent?.__layout.boxBoundsChange()
36
36
  }
37
37
 
38
38
 
39
- if (layout.eventBoundsChanged) {
39
+ if (layout.strokeBoundsChanged) {
40
40
 
41
- layout.eventBoundsSpreadWidth = this.__updateEventBoundsSpreadWidth()
41
+ layout.strokeBoundsSpreadWidth = this.__updateStrokeBoundsSpreadWidth()
42
42
 
43
- if (layout.eventBoundsSpreadWidth) {
43
+ if (layout.strokeBoundsSpreadWidth) {
44
44
 
45
- if (layout.eventBounds === layout.boxBounds) {
46
- layout.eventBoundsSpread()
45
+ if (layout.strokeBounds === layout.boxBounds) {
46
+ layout.strokeBoundsSpread()
47
47
  }
48
48
 
49
- this.__updateEventBounds()
50
- this.__updateRelativeEventBounds()
51
- layout.eventBoundsChanged = false
52
-
53
- if (layout.renderBoundsSpreadWidth) layout.renderBoundsChanged = true
49
+ this.__updateStrokeBounds()
50
+ this.__updateLocalStrokeBounds()
54
51
 
55
52
  } else {
56
- layout.eventBoundsSpreadCancel()
53
+ layout.strokeBoundsSpreadCancel()
57
54
  }
58
55
 
59
- this.parent?.__layout.eventBoundsChange()
56
+ layout.strokeBoundsChanged = false
57
+ if (layout.renderBoundsSpreadWidth) layout.renderBoundsChanged = true
58
+
59
+ if (this.parent) this.parent.__layout.strokeBoundsChange()
60
60
  resize || (resize = true)
61
61
  }
62
62
 
@@ -67,44 +67,45 @@ export const LeafBounds: ILeafBoundsModule = {
67
67
 
68
68
  if (layout.renderBoundsSpreadWidth) {
69
69
 
70
- if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.eventBounds) {
70
+ if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds) {
71
71
  layout.renderBoundsSpread()
72
72
  }
73
73
 
74
74
  this.__updateRenderBounds()
75
- this.__updateRelativeRenderBounds()
76
- layout.renderBoundsChanged = false
75
+ this.__updateLocalRenderBounds()
77
76
 
78
77
  } else {
79
78
  layout.renderBoundsSpreadCancel()
80
79
  }
81
80
 
82
- this.parent?.__layout.renderBoundsChange()
81
+ layout.renderBoundsChanged = false
82
+
83
+ if (this.parent) this.parent.__layout.renderBoundsChange()
83
84
  }
84
85
 
85
86
 
86
87
  layout.boundsChanged = false
87
88
 
88
- toWorld(this.__layout.renderBounds, this.__world, this.__world)
89
+ toOuterOf(this.__layout.renderBounds, this.__world, this.__world)
89
90
 
90
91
  if (resize) this.__onUpdateSize()
91
92
 
92
93
  } else {
93
- toWorld(this.__layout.renderBounds, this.__world, this.__world)
94
+ toOuterOf(this.__layout.renderBounds, this.__world, this.__world)
94
95
  }
95
96
 
96
97
  },
97
98
 
98
- __updateRelativeBoxBounds(): void {
99
- toWorld(this.__layout.boxBounds, this.__relative, this.__relative)
99
+ __updateLocalBoxBounds(): void {
100
+ toOuterOf(this.__layout.boxBounds, this.__local, this.__local)
100
101
  },
101
102
 
102
- __updateRelativeEventBounds(): void {
103
- toWorld(this.__layout.eventBounds, this.__relative, this.__layout.relativeEventBounds)
103
+ __updateLocalStrokeBounds(): void {
104
+ toOuterOf(this.__layout.strokeBounds, this.__local, this.__layout.localStrokeBounds)
104
105
  },
105
106
 
106
- __updateRelativeRenderBounds(): void {
107
- toWorld(this.__layout.renderBounds, this.__relative, this.__layout.relativeRenderBounds)
107
+ __updateLocalRenderBounds(): void {
108
+ toOuterOf(this.__layout.renderBounds, this.__local, this.__layout.localRenderBounds)
108
109
  },
109
110
 
110
111
 
@@ -116,12 +117,12 @@ export const LeafBounds: ILeafBoundsModule = {
116
117
  b.height = this.__.height
117
118
  },
118
119
 
119
- __updateEventBounds(): void {
120
- copyAndSpread(this.__layout.eventBounds, this.__layout.boxBounds, this.__layout.eventBoundsSpreadWidth)
120
+ __updateStrokeBounds(): void {
121
+ copyAndSpread(this.__layout.strokeBounds, this.__layout.boxBounds, this.__layout.strokeBoundsSpreadWidth)
121
122
  },
122
123
 
123
124
  __updateRenderBounds(): void {
124
- copyAndSpread(this.__layout.renderBounds, this.__layout.eventBounds, this.__layout.renderBoundsSpreadWidth)
125
+ copyAndSpread(this.__layout.renderBounds, this.__layout.strokeBounds, this.__layout.renderBoundsSpreadWidth)
125
126
  },
126
127
 
127
128
  }
@@ -1,30 +1,23 @@
1
1
  import { ILeafDataProxyModule } from '@leafer/interface'
2
- import { AttrEvent } from '@leafer/event'
2
+ import { PropertyEvent } from '@leafer/event'
3
3
 
4
4
 
5
5
  export const LeafDataProxy: ILeafDataProxyModule = {
6
6
 
7
- __set(attrName: string, newValue: unknown): void {
8
- if (this.root) {
9
- const oldValue = this.__.__getInput(attrName)
10
- if (oldValue !== newValue) {
11
- this.__[attrName] = newValue
12
- this.root.emitEvent(new AttrEvent(AttrEvent.CHANGE, this, attrName, oldValue, newValue))
13
- }
7
+ __setAttr(name: string, newValue: unknown): void {
8
+ if (this.leafer && this.leafer.ready) {
9
+ this.__[name] = newValue
10
+ const { CHANGE } = PropertyEvent
11
+ const event = new PropertyEvent(CHANGE, this, name, this.__.__get(name), newValue)
12
+ if (this.hasEvent(CHANGE) && !this.isLeafer) this.emitEvent(event)
13
+ this.leafer.emitEvent(event)
14
14
  } else {
15
- this.__[attrName] = newValue
15
+ this.__[name] = newValue
16
16
  }
17
17
  },
18
18
 
19
- __get(attrName: string): unknown {
20
- return this.__.__getInput(attrName)
21
- },
22
-
23
- __updateAttr(attrName: string): void {
24
- if (this.root) {
25
- const value = this.__.__getInput(attrName)
26
- this.root.emitEvent(new AttrEvent(AttrEvent.CHANGE, this, attrName, value, value))
27
- }
19
+ __getAttr(name: string): unknown {
20
+ return this.__.__get(name)
28
21
  }
29
22
 
30
23
  }
@@ -1,7 +1,5 @@
1
1
  import { IEventListener, IEventListenerOptions, IEventListenerMap, IEventListenerItem, IEventListenerId, IEvent, IObject, IEventTarget, ILeafEventerModule } from '@leafer/interface'
2
- import { Debug } from '@leafer/debug'
3
2
 
4
- const debug = Debug.get('Life')
5
3
  const empty = {}
6
4
 
7
5
  export const LeafEventer: ILeafEventerModule = {
@@ -71,8 +69,6 @@ export const LeafEventer: ILeafEventerModule = {
71
69
  },
72
70
 
73
71
  emit(type: string, event?: IEvent | IObject, capture?: boolean): void {
74
- if (Debug.enable) debug.log(type)
75
-
76
72
  const map = __getListenerMap(this, capture)
77
73
  const list = map[type]
78
74
  if (list) {
package/src/LeafHit.ts CHANGED
@@ -1,24 +1,23 @@
1
- import { ILeafHitModule, IRadiusPointData } from '@leafer/interface'
1
+ import { ILeafHitModule, IRadiusPointData, ILeaferCanvas } from '@leafer/interface'
2
2
  import { PointHelper } from '@leafer/math'
3
3
 
4
4
 
5
- const { toLocalRadiusPoint } = PointHelper
6
- const local = {} as IRadiusPointData
5
+ const { toInnerRadiusPointOf } = PointHelper
6
+ const inner = {} as IRadiusPointData
7
7
 
8
8
  export const LeafHit: ILeafHitModule = {
9
9
 
10
- __updateHitCanvas(): void {
11
- if (!this.__hitCanvas) this.__hitCanvas = this.leafer.hitCanvasManager.getPathType(this)
12
- this.__drawRenderPath(this.__hitCanvas)
13
- },
14
-
15
10
  __hitWorld(point: IRadiusPointData): boolean {
16
11
  if (this.__layout.hitCanvasChanged) {
17
12
  this.__updateHitCanvas()
18
13
  this.__layout.hitCanvasChanged = false
19
14
  }
20
- toLocalRadiusPoint(point, this.__world, local)
21
- return this.__hit(local)
15
+ toInnerRadiusPointOf(point, this.__world, inner)
16
+ return this.__hit(inner)
17
+ },
18
+
19
+ __drawHitPath(canvas: ILeaferCanvas): void {
20
+ this.__drawRenderPath(canvas)
22
21
  }
23
22
 
24
23
  }
@@ -0,0 +1,33 @@
1
+ import { ILeaf, ILeaferCanvas, ILeafMaskModule } from '@leafer/interface'
2
+
3
+
4
+ export const LeafMask: ILeafMaskModule = {
5
+
6
+ __updateMask(value?: boolean): void {
7
+ this.__hasMask = value ? true : this.children.some(item => item.__.isMask)
8
+ },
9
+
10
+ __renderMask(canvas: ILeaferCanvas, content: ILeaferCanvas, mask: ILeaferCanvas): void {
11
+ content.resetTransform()
12
+ content.useMask(mask)
13
+ canvas.resetTransform()
14
+ canvas.copyWorld(content)
15
+ },
16
+
17
+ __removeMask(child?: ILeaf): void {
18
+ if (child) {
19
+ child.isMask = false
20
+ this.remove(child)
21
+ } else {
22
+ const { children } = this
23
+ for (let i = 0, len = children.length; i < len; i++) {
24
+ child = children[i]
25
+ if (child.isMask) {
26
+ this.__removeMask(child)
27
+ len--, i--
28
+ }
29
+ }
30
+ }
31
+ }
32
+
33
+ }
package/src/LeafMatrix.ts CHANGED
@@ -10,10 +10,10 @@ export const LeafMatrix: ILeafMatrixModule = {
10
10
  __updateWorldMatrix(): void {
11
11
 
12
12
  const pw = this.parent ? this.parent.__world : defaultMatrix
13
- const r = this.__relative
13
+ const r = this.__local
14
14
  const w = this.__world
15
15
 
16
- if (this.__layout.matrixChanged) this.__updateRelativeMatrix()
16
+ if (this.__layout.matrixChanged) this.__updateLocalMatrix()
17
17
 
18
18
  if (this.__layout.affectScaleOrRotation) {
19
19
  w.a = r.a * pw.a + r.b * pw.c
@@ -32,9 +32,9 @@ export const LeafMatrix: ILeafMatrixModule = {
32
32
  }
33
33
  },
34
34
 
35
- __updateRelativeMatrix(): void {
35
+ __updateLocalMatrix(): void {
36
36
 
37
- const r = this.__relative
37
+ const r = this.__local
38
38
  const layout = this.__layout
39
39
 
40
40
  if (layout.affectScaleOrRotation) {
package/src/index.ts CHANGED
@@ -4,4 +4,5 @@ export { LeafMatrix } from './LeafMatrix'
4
4
  export { LeafBounds } from './LeafBounds'
5
5
  export { LeafHit } from './LeafHit'
6
6
  export { LeafRender } from './LeafRender'
7
+ export { LeafMask } from './LeafMask'
7
8