@leafer/display-module 1.0.0-rc.2 → 1.0.0-rc.20

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-rc.2",
3
+ "version": "1.0.0-rc.20",
4
4
  "description": "@leafer/display-module",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -15,17 +15,19 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/leaferjs/leafer.git"
17
17
  },
18
- "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/display-module",
18
+ "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/display-module/display-module",
19
19
  "bugs": "https://github.com/leaferjs/leafer/issues",
20
20
  "keywords": [
21
21
  "leafer",
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/event": "1.0.0-rc.2",
26
- "@leafer/math": "1.0.0-rc.2"
25
+ "@leafer/helper": "1.0.0-rc.20",
26
+ "@leafer/event": "1.0.0-rc.20",
27
+ "@leafer/math": "1.0.0-rc.20",
28
+ "@leafer/debug": "1.0.0-rc.20"
27
29
  },
28
30
  "devDependencies": {
29
- "@leafer/interface": "1.0.0-rc.2"
31
+ "@leafer/interface": "1.0.0-rc.20"
30
32
  }
31
33
  }
@@ -1,6 +1,9 @@
1
- import { ILeaf, ILeaferCanvas, IRenderOptions, IBranchRenderModule } from '@leafer/interface'
1
+ import { LeafBoundsHelper } from '@leafer/helper'
2
+ import { ILeaferCanvas, IRenderOptions, IBranchRenderModule } from '@leafer/interface'
2
3
 
3
4
 
5
+ const { excludeRenderBounds } = LeafBoundsHelper
6
+
4
7
  export const BranchRender: IBranchRenderModule = {
5
8
 
6
9
  __updateChange(): void {
@@ -18,73 +21,52 @@ export const BranchRender: IBranchRenderModule = {
18
21
  if (this.__worldOpacity) {
19
22
 
20
23
  if (this.__.__single) {
21
- canvas.resetTransform()
22
- const tempCanvas = canvas.getSameCanvas()
24
+
25
+ const tempCanvas = canvas.getSameCanvas(false, true)
23
26
 
24
27
  this.__renderBranch(tempCanvas, options)
25
28
 
26
- canvas.opacity = this.__worldOpacity
29
+ const nowWorld = this.__getNowWorld(options)
30
+
31
+ canvas.opacity = this.__.opacity
32
+ canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, this.__.__blendMode, true)
27
33
 
28
- const blendMode = this.__.isEraser ? 'destination-out' : this.__.blendMode
29
- options.matrix ? canvas.copyWorld(tempCanvas, null, null, blendMode) : canvas.copyWorld(tempCanvas, this.__world, this.__world, blendMode)
34
+ tempCanvas.recycle(nowWorld)
30
35
 
31
- tempCanvas.recycle()
32
36
  } else {
37
+
33
38
  this.__renderBranch(canvas, options)
39
+
34
40
  }
35
41
 
36
42
  }
43
+
37
44
  },
38
45
 
39
46
  __renderBranch(canvas: ILeaferCanvas, options: IRenderOptions): void {
47
+ if (this.__hasMask) {
40
48
 
41
- let child: ILeaf
42
- const { children } = this
43
-
44
- if (this.__hasMask && children.length > 1) {
49
+ this.__renderMask(canvas, options)
45
50
 
46
- let mask: boolean
47
- let maskCanvas = canvas.getSameCanvas()
48
- let contentCanvas = canvas.getSameCanvas()
51
+ } else {
49
52
 
53
+ const { children } = this
50
54
  for (let i = 0, len = children.length; i < len; i++) {
51
- child = children[i]
52
-
53
- if (child.isMask) {
54
- if (mask) {
55
- this.__renderMask(canvas, contentCanvas, maskCanvas)
56
- maskCanvas.clear()
57
- contentCanvas.clear()
58
- } else {
59
- mask = true
60
- }
61
-
62
- child.__render(maskCanvas, options)
63
- continue
64
- }
65
-
66
- child.__render(contentCanvas, options)
55
+ if (excludeRenderBounds(children[i], options)) continue
56
+ children[i].__render(canvas, options)
67
57
  }
68
58
 
69
- this.__renderMask(canvas, contentCanvas, maskCanvas)
70
- maskCanvas.recycle()
71
- contentCanvas.recycle()
72
-
73
- } else {
59
+ }
60
+ },
74
61
 
75
- const { bounds, hideBounds } = options
76
62
 
63
+ __clip(canvas: ILeaferCanvas, options: IRenderOptions): void {
64
+ if (this.__worldOpacity) {
65
+ const { children } = this
77
66
  for (let i = 0, len = children.length; i < len; i++) {
78
- child = children[i]
79
-
80
- if (bounds && !bounds.hit(child.__world, options.matrix)) continue
81
- if (hideBounds && hideBounds.includes(child.__world, options.matrix)) continue
82
-
83
- child.__render(canvas, options)
67
+ if (excludeRenderBounds(children[i], options)) continue
68
+ children[i].__clip(canvas, options)
84
69
  }
85
-
86
70
  }
87
-
88
71
  }
89
-
90
72
  }
package/src/LeafBounds.ts CHANGED
@@ -1,132 +1,151 @@
1
1
  import { ILeafBoundsModule } from '@leafer/interface'
2
2
  import { BoundsHelper } from '@leafer/math'
3
+ import { PathBounds } from '@leafer/path'
4
+ import { BranchHelper, LeafHelper } from '@leafer/helper'
3
5
 
4
6
 
5
- const { toOuterOf, copyAndSpread } = BoundsHelper
7
+ const { updateMatrix, updateAllMatrix, hasParentAutoLayout } = LeafHelper
8
+ const { updateBounds } = BranchHelper
9
+ const { toOuterOf, copyAndSpread, copy } = BoundsHelper
10
+ const { toBounds } = PathBounds
6
11
 
7
12
  export const LeafBounds: ILeafBoundsModule = {
8
13
 
9
14
  __updateWorldBounds(): void {
10
15
 
11
- if (this.__layout.boundsChanged) {
16
+ toOuterOf(this.__layout.renderBounds, this.__world, this.__world)
12
17
 
13
- let resize: boolean
14
- const layout = this.__layout
18
+ if (this.__layout.resized) {
19
+ this.__onUpdateSize()
20
+ this.__layout.resized = false
21
+ }
15
22
 
23
+ },
16
24
 
17
- if (layout.boxChanged) {
25
+ __updateLocalBounds(): void {
18
26
 
19
- this.__updatePath()
20
- this.__updateRenderPath()
27
+ const layout = this.__layout
21
28
 
22
- this.__updateBoxBounds()
23
- layout.boxChanged = false
24
- resize = true
25
- }
29
+ if (layout.boxChanged) {
26
30
 
31
+ if (!this.__.__pathInputed) this.__updatePath()
32
+ this.__updateRenderPath()
27
33
 
28
- if (layout.localBoxChanged) { // position change
34
+ this.__updateBoxBounds()
35
+ layout.boxChanged = false
36
+ layout.resized = true
37
+ }
29
38
 
30
- this.__updateLocalBoxBounds()
31
- layout.localBoxChanged = false
32
39
 
33
- if (layout.strokeSpread) layout.strokeChanged = true
34
- if (layout.renderSpread) layout.renderChanged = true
35
- this.parent?.__layout.boxChange()
36
- }
40
+ if (layout.localBoxChanged) { // position change
37
41
 
42
+ if (this.__local) this.__updateLocalBoxBounds()
43
+ layout.localBoxChanged = false
38
44
 
39
- if (layout.strokeChanged) {
45
+ if (layout.strokeSpread) layout.strokeChanged = true
46
+ if (layout.renderSpread) layout.renderChanged = true
47
+ if (this.parent) this.parent.__layout.boxChange()
48
+ }
40
49
 
41
- layout.strokeSpread = this.__updateStrokeSpread()
42
50
 
43
- if (layout.strokeSpread) {
51
+ if (layout.strokeChanged) {
44
52
 
45
- if (layout.strokeBounds === layout.boxBounds) {
46
- layout.spreadStroke()
47
- }
53
+ layout.strokeSpread = this.__updateStrokeSpread()
48
54
 
49
- this.__updateStrokeBounds()
50
- this.__updateLocalStrokeBounds()
55
+ if (layout.strokeSpread) {
51
56
 
52
- } else {
53
- layout.spreadStrokeCancel()
57
+ if (layout.strokeBounds === layout.boxBounds) {
58
+ layout.spreadStroke()
54
59
  }
55
60
 
56
- layout.strokeChanged = false
57
- if (layout.renderSpread) layout.renderChanged = true
61
+ this.__updateStrokeBounds()
62
+ this.__updateLocalStrokeBounds()
58
63
 
59
- if (this.parent) this.parent.__layout.strokeChange()
60
- resize || (resize = true)
64
+ } else {
65
+ layout.spreadStrokeCancel()
61
66
  }
62
67
 
68
+ layout.strokeChanged = false
69
+ if (layout.renderSpread) layout.renderChanged = true
63
70
 
64
- if (layout.renderChanged) {
71
+ if (this.parent) this.parent.__layout.strokeChange()
72
+ layout.resized = true
73
+ }
65
74
 
66
- layout.renderSpread = this.__updateRenderSpread()
67
75
 
68
- if (layout.renderSpread) {
76
+ if (layout.renderChanged) {
69
77
 
70
- if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds) {
71
- layout.spreadRender()
72
- }
78
+ layout.renderSpread = this.__updateRenderSpread()
73
79
 
74
- this.__updateRenderBounds()
75
- this.__updateLocalRenderBounds()
80
+ if (layout.renderSpread) {
76
81
 
77
- } else {
78
- layout.spreadRenderCancel()
82
+ if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds) {
83
+ layout.spreadRender()
79
84
  }
80
85
 
81
- layout.renderChanged = false
86
+ this.__updateRenderBounds()
87
+ this.__updateLocalRenderBounds()
82
88
 
83
- if (this.parent) this.parent.__layout.renderChange()
89
+ } else {
90
+ layout.spreadRenderCancel()
84
91
  }
85
92
 
93
+ layout.renderChanged = false
86
94
 
87
- layout.boundsChanged = false
88
-
89
- toOuterOf(this.__layout.renderBounds, this.__world, this.__world)
90
-
91
- if (resize) this.__onUpdateSize()
92
-
93
- } else {
94
- toOuterOf(this.__layout.renderBounds, this.__world, this.__world)
95
+ if (this.parent) this.parent.__layout.renderChange()
95
96
  }
96
97
 
98
+ layout.boundsChanged = false
99
+
97
100
  },
98
101
 
99
102
  __updateLocalBoxBounds(): void {
103
+ if (this.__hasAutoLayout) this.__updateAutoLayout()
100
104
  toOuterOf(this.__layout.boxBounds, this.__local, this.__local)
101
105
  },
102
106
 
103
107
  __updateLocalStrokeBounds(): void {
104
- toOuterOf(this.__layout.strokeBounds, this.__local, this.__layout.localStrokeBounds)
108
+ toOuterOf(this.__layout.strokeBounds, this.__localMatrix, this.__layout.localStrokeBounds)
105
109
  },
106
110
 
107
111
  __updateLocalRenderBounds(): void {
108
- toOuterOf(this.__layout.renderBounds, this.__local, this.__layout.localRenderBounds)
112
+ toOuterOf(this.__layout.renderBounds, this.__localMatrix, this.__layout.localRenderBounds)
109
113
  },
110
114
 
111
115
 
112
116
  __updateBoxBounds(): void {
113
117
  const b = this.__layout.boxBounds
114
- const { width, height } = this.__
115
- b.x = 0
116
- b.y = 0
117
- b.width = width
118
- b.height = height
118
+ const data = this.__
119
+ if (data.__pathInputed) {
120
+ toBounds(data.__pathForRender, b)
121
+ } else {
122
+ b.x = 0
123
+ b.y = 0
124
+ b.width = data.width
125
+ b.height = data.height
126
+ }
127
+ },
128
+
129
+
130
+ __updateAutoLayout(): void {
131
+ this.__layout.matrixChanged = true
132
+ if (this.isBranch) {
133
+ if (this.leafer) this.leafer.layouter.addExtra(this) // add part render
134
+ if (hasParentAutoLayout(this)) {
135
+ updateMatrix(this)
136
+ } else {
137
+ updateAllMatrix(this)
138
+ updateBounds(this, this)
139
+ }
140
+ } else {
141
+ updateMatrix(this)
142
+ }
119
143
  },
120
144
 
121
145
  __updateNaturalSize(): void {
122
146
  const { __: data, __layout: layout } = this
123
147
  data.__naturalWidth = layout.boxBounds.width
124
148
  data.__naturalHeight = layout.boxBounds.height
125
-
126
- if (this.around) {
127
- layout.positionChanged = layout.matrixChanged = true
128
- this.__updateWorldMatrix()
129
- }
130
149
  },
131
150
 
132
151
  __updateStrokeBounds(): void {
@@ -134,7 +153,8 @@ export const LeafBounds: ILeafBoundsModule = {
134
153
  },
135
154
 
136
155
  __updateRenderBounds(): void {
137
- copyAndSpread(this.__layout.renderBounds, this.__layout.strokeBounds, this.__layout.renderSpread)
156
+ const { renderSpread, strokeBounds, renderBounds } = this.__layout
157
+ renderSpread > 0 ? copyAndSpread(renderBounds, strokeBounds, renderSpread) : copy(renderBounds, strokeBounds) // Box use -1
138
158
  },
139
159
 
140
160
  }
@@ -1,25 +1,50 @@
1
- import { ILeafDataProxyModule } from '@leafer/interface'
1
+ import { ILeafDataProxyModule, IObject, IValue } from '@leafer/interface'
2
2
  import { PropertyEvent } from '@leafer/event'
3
+ import { Debug } from '@leafer/debug'
3
4
 
4
5
 
6
+ const { isFinite } = Number
7
+ const debug = Debug.get('setAttr')
8
+
5
9
  export const LeafDataProxy: ILeafDataProxyModule = {
6
10
 
7
- __setAttr(name: string, newValue: unknown): void {
11
+ __setAttr(name: string, newValue: IValue, checkFiniteNumber?: boolean): boolean {
8
12
  if (this.leafer && this.leafer.created) {
9
- if (typeof newValue === 'object' || this.__.__getInput(name) !== newValue) {
10
- this.__[name] = newValue
13
+ const oldValue = this.__.__getInput(name)
14
+
15
+ if (checkFiniteNumber && !isFinite(newValue) && newValue !== undefined) { // 警告 NaN、Infinity、-Infinity、null、非有效数字
16
+ debug.warn(this.innerName, name, newValue)
17
+ newValue = undefined // must
18
+ }
19
+
20
+ if (typeof newValue === 'object' || oldValue !== newValue) {
21
+ (this.__ as IObject)[name] = newValue
22
+ if (this.__proxyData) this.setProxyAttr(name, newValue)
23
+
11
24
  const { CHANGE } = PropertyEvent
12
- const event = new PropertyEvent(CHANGE, this, name, this.__.__get(name), newValue)
13
- if (this.hasEvent(CHANGE) && !this.isLeafer) this.emitEvent(event)
25
+ const event = new PropertyEvent(CHANGE, this, name, oldValue, newValue)
26
+
27
+ if (this.isLeafer) {
28
+ this.emitEvent(new PropertyEvent(PropertyEvent.LEAFER_CHANGE, this, name, oldValue, newValue))
29
+ } else {
30
+ if (this.hasEvent(CHANGE)) this.emitEvent(event)
31
+ }
32
+
14
33
  this.leafer.emitEvent(event)
34
+ return true
35
+ } else {
36
+ return false
15
37
  }
38
+
16
39
  } else {
17
- this.__[name] = newValue
40
+ (this.__ as IObject)[name] = newValue
41
+ if (this.__proxyData) this.setProxyAttr(name, newValue)
42
+ return true
18
43
  }
19
44
  },
20
45
 
21
- __getAttr(name: string): unknown {
46
+ __getAttr(name: string): IValue {
47
+ if (this.__proxyData) return this.getProxyAttr(name)
22
48
  return this.__.__get(name)
23
49
  }
24
-
25
50
  }
@@ -1,4 +1,5 @@
1
1
  import { IEventListener, IEventListenerOptions, IEventListenerMap, IEventListenerItem, IEventListenerId, IEvent, IObject, IEventTarget, ILeafEventerModule } from '@leafer/interface'
2
+ import { EventCreator } from '@leafer/platform'
2
3
 
3
4
  const empty = {}
4
5
 
@@ -55,13 +56,13 @@ export const LeafEventer: ILeafEventerModule = {
55
56
  on_(type: string | string[], listener: IEventListener, bind?: IObject, options?: IEventListenerOptions | boolean): IEventListenerId {
56
57
  if (bind) listener = listener.bind(bind)
57
58
  this.on(type, listener, options)
58
- return { type, listener, options }
59
+ return { type, current: this, listener, options }
59
60
  },
60
61
 
61
62
  off_(id: IEventListenerId | IEventListenerId[]): void {
62
63
  if (!id) return
63
64
  const list = id instanceof Array ? id : [id]
64
- list.forEach(item => this.off(item.type, item.listener, item.options))
65
+ list.forEach(item => item.current.off(item.type, item.listener, item.options))
65
66
  list.length = 0
66
67
  },
67
68
 
@@ -70,6 +71,8 @@ export const LeafEventer: ILeafEventerModule = {
70
71
  },
71
72
 
72
73
  emit(type: string, event?: IEvent | IObject, capture?: boolean): void {
74
+ if (!event && EventCreator.has(type)) event = EventCreator.get(type, { type, target: this, current: this } as IEvent)
75
+
73
76
  const map = __getListenerMap(this, capture)
74
77
  const list = map[type]
75
78
  if (list) {
@@ -93,11 +96,8 @@ export const LeafEventer: ILeafEventerModule = {
93
96
 
94
97
  hasEvent(type: string, capture?: boolean): boolean {
95
98
  const { __bubbleMap: b, __captureMap: c } = this
96
- if (capture === undefined) {
97
- return !!((c && c[type]) || (b && b[type]))
98
- } else {
99
- return !!(capture ? (c && c[type]) : (b && b[type]))
100
- }
99
+ const hasB = b && b[type], hasC = c && c[type]
100
+ return !!(capture === undefined ? (hasB || hasC) : (capture ? hasC : hasB))
101
101
  },
102
102
 
103
103
  }
package/src/LeafMatrix.ts CHANGED
@@ -1,122 +1,46 @@
1
- import { ILeafMatrixModule, IPointData } from '@leafer/interface'
2
- import { OneRadian, MatrixHelper } from '@leafer/math'
1
+ import { ILeafMatrixModule, ILayoutData } from '@leafer/interface'
2
+ import { AroundHelper, MatrixHelper } from '@leafer/math'
3
3
 
4
4
 
5
- const { sin, cos } = Math
6
- const defaultWorld = { ...MatrixHelper.defaultMatrix, scaleX: 1, scaleY: 1, rotation: 0, skewX: 0, skewY: 0 }
7
- const defaultCenter: IPointData = { x: 0.5, y: 0.5 }
5
+ const { setLayout, multiplyParent, translateInner, defaultWorld } = MatrixHelper
6
+ const { toPoint, tempPoint } = AroundHelper
8
7
 
9
8
  export const LeafMatrix: ILeafMatrixModule = {
10
9
 
11
10
  __updateWorldMatrix(): void {
12
11
 
13
- const pw = this.parent ? this.parent.__world : defaultWorld
14
- const r = this.__local
15
- const w = this.__world
16
-
17
- if (this.__layout.matrixChanged) this.__updateLocalMatrix()
18
-
19
- if (this.__layout.affectScaleOrRotation) {
20
- w.a = r.a * pw.a + r.b * pw.c
21
- w.b = r.a * pw.b + r.b * pw.d
22
- w.c = r.c * pw.a + r.d * pw.c
23
- w.d = r.c * pw.b + r.d * pw.d
24
- w.e = r.e * pw.a + r.f * pw.c + pw.e
25
- w.f = r.e * pw.b + r.f * pw.d + pw.f
26
-
27
- const data = this.__
28
- w.scaleX = pw.scaleX * data.scaleX
29
- w.scaleY = pw.scaleY * data.scaleY
30
-
31
- w.rotation = pw.rotation + data.rotation
32
- w.skewX = pw.skewX + data.skewX
33
- w.skewY = pw.skewY + data.skewY
34
- } else {
35
- w.a = pw.a
36
- w.b = pw.b
37
- w.c = pw.c
38
- w.d = pw.d
39
- w.e = r.e * pw.a + r.f * pw.c + pw.e
40
- w.f = r.e * pw.b + r.f * pw.d + pw.f
41
-
42
- w.scaleX = pw.scaleX
43
- w.scaleY = pw.scaleY
44
-
45
- w.rotation = pw.rotation
46
- w.skewX = pw.skewX
47
- w.skewY = pw.skewY
48
- }
12
+ multiplyParent(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__ as ILayoutData)
13
+
49
14
  },
50
15
 
51
16
  __updateLocalMatrix(): void {
52
17
 
53
- const r = this.__local
54
- const layout = this.__layout
55
-
56
- if (layout.affectScaleOrRotation) {
18
+ if (this.__local) {
57
19
 
58
- const { scaleX, scaleY } = this.__
20
+ const layout = this.__layout, local = this.__local, data = this.__
59
21
 
60
- if (layout.affectRotation) {
22
+ if (layout.affectScaleOrRotation) {
61
23
 
62
24
  if (layout.scaleChanged || layout.rotationChanged) {
63
-
64
- let { rotation, skewX, skewY } = this.__
65
-
66
- if (rotation || skewX || skewY) {
67
-
68
- rotation *= OneRadian
69
- if (skewX) skewX *= OneRadian
70
- if (skewY) skewY *= OneRadian
71
-
72
- r.a = scaleX * cos(rotation + skewY)
73
- r.b = scaleX * sin(rotation + skewY)
74
- r.c = scaleY * -sin(rotation - skewX)
75
- r.d = scaleY * cos(rotation - skewX)
76
-
77
- } else {
78
-
79
- r.a = scaleX
80
- r.b = 0
81
- r.c = 0
82
- r.d = scaleY
83
-
84
- layout.affectRotation = false
85
- }
86
-
87
- layout.scaleChanged = false
88
- layout.rotationChanged = false
89
-
90
- }
91
-
92
- } else {
93
-
94
- if (layout.scaleChanged) {
95
- r.a = scaleX
96
- r.d = scaleY
97
- layout.scaleChanged = false
25
+ setLayout(local, data as ILayoutData, null, layout.affectRotation)
26
+ layout.scaleChanged = layout.rotationChanged = false
98
27
  }
99
28
 
100
29
  }
101
30
 
102
- }
31
+ local.e = data.x
32
+ local.f = data.y
103
33
 
104
- if (layout.positionChanged) {
105
- r.e = this.__.x
106
- r.f = this.__.y
107
- const { width, height, around } = this.__
108
- if (around && width && height) {
109
- const origin = (around === 'center') ? defaultCenter : around
110
- const offsetX = width * origin.x, offsetY = height * origin.y
111
- r.e -= offsetX * r.a + offsetY * r.c
112
- r.f -= offsetX * r.b + offsetY * r.d
34
+ if (data.around) {
35
+ toPoint(data.around, layout.boxBounds, tempPoint)
36
+ translateInner(local, -tempPoint.x, -tempPoint.y)
113
37
  }
114
- layout.positionChanged = false
38
+
115
39
  }
116
40
 
117
41
  this.__layout.matrixChanged = false
118
- }
119
42
 
43
+ }
120
44
 
121
45
  }
122
46
 
package/src/LeafRender.ts CHANGED
@@ -5,24 +5,37 @@ export const LeafRender: ILeafRenderModule = {
5
5
 
6
6
  __render(canvas: ILeaferCanvas, options: IRenderOptions): void {
7
7
  if (this.__worldOpacity) {
8
- canvas.setWorld(this.__world, options.matrix)
9
- canvas.opacity = this.__worldOpacity
8
+
9
+ canvas.setWorld(this.__nowWorld = this.__getNowWorld(options))
10
+ canvas.opacity = this.__.opacity
10
11
 
11
12
  if (this.__.__single) {
12
- const tempCanvas = canvas.getSameCanvas(true)
13
13
 
14
+ const tempCanvas = canvas.getSameCanvas(true, true)
14
15
  this.__draw(tempCanvas, options)
15
16
 
16
- const blendMode = this.__.isEraser ? 'destination-out' : this.__.blendMode
17
- if (options.matrix || this.__hasMirror) {
18
- canvas.copyWorldByReset(tempCanvas, null, null, blendMode)
17
+ if (this.__worldFlipped) {
18
+ canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, this.__.__blendMode, true)
19
19
  } else {
20
- canvas.copyWorldToInner(tempCanvas, this.__world, this.__layout.renderBounds, blendMode)
20
+ canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, this.__.__blendMode)
21
21
  }
22
- tempCanvas.recycle()
22
+
23
+ tempCanvas.recycle(this.__nowWorld)
24
+
23
25
  } else {
26
+
24
27
  this.__draw(canvas, options)
28
+
25
29
  }
30
+
31
+ }
32
+ },
33
+
34
+ __clip(canvas: ILeaferCanvas, options: IRenderOptions): void {
35
+ if (this.__worldOpacity) {
36
+ canvas.setWorld(this.__nowWorld = this.__getNowWorld(options))
37
+ this.__drawRenderPath(canvas)
38
+ this.__.windingRule ? canvas.clip(this.__.windingRule) : canvas.clip()
26
39
  }
27
40
  },
28
41
 
package/src/index.ts CHANGED
@@ -2,8 +2,6 @@ export { LeafEventer } from './LeafEventer'
2
2
  export { LeafDataProxy } from './LeafDataProxy'
3
3
  export { LeafMatrix } from './LeafMatrix'
4
4
  export { LeafBounds } from './LeafBounds'
5
- export { LeafHit } from './LeafHit'
6
5
  export { LeafRender } from './LeafRender'
7
- export { LeafMask } from './LeafMask'
8
6
 
9
7
  export { BranchRender } from './BranchRender'
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeafEventerModule, ILeafDataProxyModule, ILeafMatrixModule, ILeafBoundsModule, ILeafHitModule, ILeafRenderModule, ILeafMaskModule, IBranchRenderModule } from '@leafer/interface';
1
+ import { ILeafEventerModule, ILeafDataProxyModule, ILeafMatrixModule, ILeafBoundsModule, ILeafRenderModule, IBranchRenderModule } from '@leafer/interface';
2
2
 
3
3
  declare const LeafEventer: ILeafEventerModule;
4
4
 
@@ -8,12 +8,8 @@ declare const LeafMatrix: ILeafMatrixModule;
8
8
 
9
9
  declare const LeafBounds: ILeafBoundsModule;
10
10
 
11
- declare const LeafHit: ILeafHitModule;
12
-
13
11
  declare const LeafRender: ILeafRenderModule;
14
12
 
15
- declare const LeafMask: ILeafMaskModule;
16
-
17
13
  declare const BranchRender: IBranchRenderModule;
18
14
 
19
- export { BranchRender, LeafBounds, LeafDataProxy, LeafEventer, LeafHit, LeafMask, LeafMatrix, LeafRender };
15
+ export { BranchRender, LeafBounds, LeafDataProxy, LeafEventer, LeafMatrix, LeafRender };
package/src/LeafHit.ts DELETED
@@ -1,29 +0,0 @@
1
- import { ILeafHitModule, IRadiusPointData, ILeaferCanvas } from '@leafer/interface'
2
- import { PointHelper } from '@leafer/math'
3
-
4
-
5
- const { toInnerRadiusPointOf, copy, setRadius } = PointHelper
6
- const inner = {} as IRadiusPointData
7
-
8
- export const LeafHit: ILeafHitModule = {
9
-
10
- __hitWorld(point: IRadiusPointData): boolean {
11
- if (this.__layout.hitCanvasChanged || !this.__hitCanvas) {
12
- this.__updateHitCanvas()
13
- this.__layout.hitCanvasChanged = false
14
- }
15
-
16
- if (this.__.hitRadius) {
17
- copy(inner, point), point = inner
18
- setRadius(point, this.__.hitRadius)
19
- }
20
-
21
- toInnerRadiusPointOf(point, this.__world, inner)
22
- return this.__hit(inner)
23
- },
24
-
25
- __drawHitPath(canvas: ILeaferCanvas): void {
26
- this.__drawRenderPath(canvas)
27
- }
28
-
29
- }
package/src/LeafMask.ts DELETED
@@ -1,38 +0,0 @@
1
- import { ILeaf, ILeaferCanvas, ILeafMaskModule } from '@leafer/interface'
2
-
3
-
4
- export const LeafMask: ILeafMaskModule = {
5
-
6
- __updateEraser(value?: boolean): void {
7
- this.__hasEraser = value ? true : this.children.some(item => item.__.isEraser)
8
- },
9
-
10
- __updateMask(value?: boolean): void {
11
- this.__hasMask = value ? true : this.children.some(item => item.__.isMask)
12
- },
13
-
14
- __renderMask(canvas: ILeaferCanvas, content: ILeaferCanvas, mask: ILeaferCanvas): void {
15
- content.resetTransform()
16
- content.useMask(mask)
17
- canvas.resetTransform()
18
- canvas.opacity = this.__worldOpacity
19
- canvas.copyWorld(content)
20
- },
21
-
22
- __removeMask(child?: ILeaf): void {
23
- if (child) {
24
- child.isMask = false
25
- this.remove(child)
26
- } else {
27
- const { children } = this
28
- for (let i = 0, len = children.length; i < len; i++) {
29
- child = children[i]
30
- if (child.isMask) {
31
- this.__removeMask(child)
32
- len--, i--
33
- }
34
- }
35
- }
36
- }
37
-
38
- }