@leafer/display-module 1.0.0-alpha.9 → 1.0.0-beta

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.9",
3
+ "version": "1.0.0-beta",
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.9",
23
- "@leafer/math": "1.0.0-alpha.9"
22
+ "@leafer/event": "1.0.0-beta",
23
+ "@leafer/math": "1.0.0-beta"
24
24
  },
25
25
  "devDependencies": {
26
- "@leafer/interface": "1.0.0-alpha.9"
26
+ "@leafer/interface": "1.0.0-beta"
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 { setByBoundsTimesMatrix } = BoundsHelper
5
+ const { toOuterOf, copyAndSpread } = BoundsHelper
6
6
 
7
7
  export const LeafBounds: ILeafBoundsModule = {
8
8
 
@@ -14,97 +14,98 @@ export const LeafBounds: ILeafBoundsModule = {
14
14
  const layout = this.__layout
15
15
 
16
16
 
17
- if (layout.boxBoundsChanged) {
17
+ if (layout.boxChanged) {
18
18
 
19
19
  this.__updatePath()
20
20
  this.__updateRenderPath()
21
21
 
22
22
  this.__updateBoxBounds()
23
- layout.boxBoundsChanged = false
23
+ layout.boxChanged = false
24
24
  resize = true
25
25
  }
26
26
 
27
27
 
28
- if (layout.localBoxBoundsChanged) { // position change
28
+ if (layout.localBoxChanged) { // position change
29
29
 
30
- this.__updateRelativeBoxBounds()
31
- layout.localBoxBoundsChanged = false
30
+ this.__updateLocalBoxBounds()
31
+ layout.localBoxChanged = false
32
32
 
33
- if (layout.eventBoundsSpreadWidth) layout.eventBoundsChanged = true
34
- if (layout.renderBoundsSpreadWidth) layout.renderBoundsChanged = true
35
- this.parent?.__layout.boxBoundsChange()
33
+ if (layout.strokeSpread) layout.strokeChanged = true
34
+ if (layout.renderSpread) layout.renderChanged = true
35
+ this.parent?.__layout.boxChange()
36
36
  }
37
37
 
38
38
 
39
- if (layout.eventBoundsChanged) {
39
+ if (layout.strokeChanged) {
40
40
 
41
- layout.eventBoundsSpreadWidth = this.__updateEventBoundsSpreadWidth()
41
+ layout.strokeSpread = this.__updateStrokeSpread()
42
42
 
43
- if (layout.eventBoundsSpreadWidth) {
43
+ if (layout.strokeSpread) {
44
44
 
45
- if (layout.eventBounds === layout.boxBounds) {
46
- layout.eventBoundsSpread()
45
+ if (layout.strokeBounds === layout.boxBounds) {
46
+ layout.spreadStroke()
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.spreadStrokeCancel()
57
54
  }
58
55
 
59
- this.parent?.__layout.eventBoundsChange()
56
+ layout.strokeChanged = false
57
+ if (layout.renderSpread) layout.renderChanged = true
58
+
59
+ if (this.parent) this.parent.__layout.strokeChange()
60
60
  resize || (resize = true)
61
61
  }
62
62
 
63
63
 
64
- if (layout.renderBoundsChanged) {
64
+ if (layout.renderChanged) {
65
65
 
66
- layout.renderBoundsSpreadWidth = this.__updateRenderBoundsSpreadWidth()
66
+ layout.renderSpread = this.__updateRenderSpread()
67
67
 
68
- if (layout.renderBoundsSpreadWidth) {
68
+ if (layout.renderSpread) {
69
69
 
70
- if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.eventBounds) {
71
- layout.renderBoundsSpread()
70
+ if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds) {
71
+ layout.spreadRender()
72
72
  }
73
73
 
74
74
  this.__updateRenderBounds()
75
- this.__updateRelativeRenderBounds()
76
- layout.renderBoundsChanged = false
75
+ this.__updateLocalRenderBounds()
77
76
 
78
77
  } else {
79
- layout.renderBoundsSpreadCancel()
78
+ layout.spreadRenderCancel()
80
79
  }
81
80
 
82
- this.parent?.__layout.renderBoundsChange()
81
+ layout.renderChanged = false
82
+
83
+ if (this.parent) this.parent.__layout.renderChange()
83
84
  }
84
85
 
85
86
 
86
87
  layout.boundsChanged = false
87
88
 
88
- setByBoundsTimesMatrix(this.__world, this.__layout.renderBounds, 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
- setByBoundsTimesMatrix(this.__world, this.__layout.renderBounds, this.__world)
94
+ toOuterOf(this.__layout.renderBounds, this.__world, this.__world)
94
95
  }
95
96
 
96
97
  },
97
98
 
98
- __updateRelativeBoxBounds(): void {
99
- setByBoundsTimesMatrix(this.__relative, this.__layout.boxBounds, this.__relative)
99
+ __updateLocalBoxBounds(): void {
100
+ toOuterOf(this.__layout.boxBounds, this.__local, this.__local)
100
101
  },
101
102
 
102
- __updateRelativeEventBounds(): void {
103
- setByBoundsTimesMatrix(this.__layout.relativeEventBounds, this.__layout.eventBounds, this.__relative)
103
+ __updateLocalStrokeBounds(): void {
104
+ toOuterOf(this.__layout.strokeBounds, this.__local, this.__layout.localStrokeBounds)
104
105
  },
105
106
 
106
- __updateRelativeRenderBounds(): void {
107
- setByBoundsTimesMatrix(this.__layout.relativeRenderBounds, this.__layout.renderBounds, this.__relative)
107
+ __updateLocalRenderBounds(): void {
108
+ toOuterOf(this.__layout.renderBounds, this.__local, this.__layout.localRenderBounds)
108
109
  },
109
110
 
110
111
 
@@ -114,6 +115,14 @@ export const LeafBounds: ILeafBoundsModule = {
114
115
  b.y = 0
115
116
  b.width = this.__.width
116
117
  b.height = this.__.height
117
- }
118
+ },
119
+
120
+ __updateStrokeBounds(): void {
121
+ copyAndSpread(this.__layout.strokeBounds, this.__layout.boxBounds, this.__layout.strokeSpread)
122
+ },
123
+
124
+ __updateRenderBounds(): void {
125
+ copyAndSpread(this.__layout.renderBounds, this.__layout.strokeBounds, this.__layout.renderSpread)
126
+ },
118
127
 
119
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,6 +1,5 @@
1
1
  import { IEventListener, IEventListenerOptions, IEventListenerMap, IEventListenerItem, IEventListenerId, IEvent, IObject, IEventTarget, ILeafEventerModule } from '@leafer/interface'
2
2
 
3
-
4
3
  const empty = {}
5
4
 
6
5
  export const LeafEventer: ILeafEventerModule = {
@@ -50,13 +49,13 @@ export const LeafEventer: ILeafEventerModule = {
50
49
  })
51
50
  },
52
51
 
53
- on__(type: string | string[], listener: IEventListener, bind?: IObject, options?: IEventListenerOptions | boolean): IEventListenerId {
52
+ on_(type: string | string[], listener: IEventListener, bind?: IObject, options?: IEventListenerOptions | boolean): IEventListenerId {
54
53
  if (bind) listener = listener.bind(bind)
55
54
  this.on(type, listener, options)
56
55
  return { type, listener, options }
57
56
  },
58
57
 
59
- off__(id: IEventListenerId | IEventListenerId[]): void {
58
+ off_(id: IEventListenerId | IEventListenerId[]): void {
60
59
  if (!id) return
61
60
  const list = id instanceof Array ? id : [id]
62
61
  list.forEach(item => {
@@ -77,7 +76,10 @@ export const LeafEventer: ILeafEventerModule = {
77
76
  for (let i = 0, len = list.length; i < len; i++) {
78
77
  item = list[i]
79
78
  item.listener(event)
80
- if (item.once) this.off(type, item.listener, capture)
79
+ if (item.once) {
80
+ this.off(type, item.listener, capture)
81
+ i--, len--
82
+ }
81
83
  if (event && (event as IEvent).isStopNow) break
82
84
  }
83
85
  }
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/LeafRender.ts CHANGED
@@ -7,7 +7,7 @@ export const LeafRender: ILeafRenderModule = {
7
7
  if (this.__worldOpacity) {
8
8
  canvas.setWorld(this.__world, options.matrix)
9
9
  canvas.opacity = this.__worldOpacity
10
- this.__complex ? this.__draw(canvas, options) : this.__drawFast(canvas, options)
10
+ this.__draw(canvas, options)
11
11
  }
12
12
  },
13
13
 
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