@leafer/display-module 1.0.0-rc.3 → 1.0.0-rc.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-rc.3",
3
+ "version": "1.0.0-rc.30",
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.3",
26
- "@leafer/math": "1.0.0-rc.3"
25
+ "@leafer/helper": "1.0.0-rc.30",
26
+ "@leafer/event": "1.0.0-rc.30",
27
+ "@leafer/math": "1.0.0-rc.30",
28
+ "@leafer/debug": "1.0.0-rc.30"
27
29
  },
28
30
  "devDependencies": {
29
- "@leafer/interface": "1.0.0-rc.3"
31
+ "@leafer/interface": "1.0.0-rc.30"
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,54 @@ 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
+ if (this.__.eraser === 'path') return this.__renderEraser(canvas, options)
26
+
27
+ const tempCanvas = canvas.getSameCanvas(false, true)
23
28
 
24
29
  this.__renderBranch(tempCanvas, options)
25
30
 
26
- canvas.opacity = this.__worldOpacity
31
+ const nowWorld = this.__getNowWorld(options)
27
32
 
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)
33
+ canvas.opacity = this.__.opacity
34
+ canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, this.__.__blendMode, true)
35
+
36
+ tempCanvas.recycle(nowWorld)
30
37
 
31
- tempCanvas.recycle()
32
38
  } else {
39
+
33
40
  this.__renderBranch(canvas, options)
41
+
34
42
  }
35
43
 
36
44
  }
45
+
37
46
  },
38
47
 
39
48
  __renderBranch(canvas: ILeaferCanvas, options: IRenderOptions): void {
49
+ if (this.__hasMask) {
40
50
 
41
- let child: ILeaf
42
- const { children } = this
43
-
44
- if (this.__hasMask && children.length > 1) {
51
+ this.__renderMask(canvas, options)
45
52
 
46
- let mask: boolean
47
- let maskCanvas = canvas.getSameCanvas()
48
- let contentCanvas = canvas.getSameCanvas()
53
+ } else {
49
54
 
55
+ const { children } = this
50
56
  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)
57
+ if (excludeRenderBounds(children[i], options)) continue
58
+ children[i].__render(canvas, options)
67
59
  }
68
60
 
69
- this.__renderMask(canvas, contentCanvas, maskCanvas)
70
- maskCanvas.recycle()
71
- contentCanvas.recycle()
72
-
73
- } else {
61
+ }
62
+ },
74
63
 
75
- const { bounds, hideBounds } = options
76
64
 
65
+ __clip(canvas: ILeaferCanvas, options: IRenderOptions): void {
66
+ if (this.__worldOpacity) {
67
+ const { children } = this
77
68
  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)
69
+ if (excludeRenderBounds(children[i], options)) continue
70
+ children[i].__clip(canvas, options)
84
71
  }
85
-
86
72
  }
87
-
88
73
  }
89
-
90
74
  }
package/src/LeafBounds.ts CHANGED
@@ -1,140 +1,170 @@
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 } = 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.resized = true
36
+ }
29
37
 
30
- this.__updateLocalBoxBounds()
31
- layout.localBoxChanged = false
32
38
 
33
- if (layout.strokeSpread) layout.strokeChanged = true
34
- if (layout.renderSpread) layout.renderChanged = true
35
- this.parent?.__layout.boxChange()
36
- }
39
+ if (layout.localBoxChanged) { // position change
37
40
 
41
+ if (this.__local) this.__updateLocalBoxBounds()
42
+ layout.localBoxChanged = false
38
43
 
39
- if (layout.strokeChanged) {
40
-
41
- layout.strokeSpread = this.__updateStrokeSpread()
44
+ if (layout.strokeSpread) layout.strokeChanged = true
45
+ if (layout.renderSpread) layout.renderChanged = true
46
+ if (this.parent) this.parent.__layout.boxChange()
47
+ }
42
48
 
43
- if (layout.strokeSpread) {
44
49
 
45
- if (layout.strokeBounds === layout.boxBounds) {
46
- layout.spreadStroke()
47
- }
50
+ layout.boxChanged = false // must after updateLocalBoxBounds()
48
51
 
49
- this.__updateStrokeBounds()
50
- this.__updateLocalStrokeBounds()
51
52
 
52
- } else {
53
- layout.spreadStrokeCancel()
54
- }
53
+ if (layout.strokeChanged) {
55
54
 
56
- layout.strokeChanged = false
57
- if (layout.renderSpread) layout.renderChanged = true
55
+ layout.strokeSpread = this.__updateStrokeSpread()
58
56
 
59
- if (this.parent) this.parent.__layout.strokeChange()
60
- resize || (resize = true)
61
- }
57
+ if (layout.strokeSpread) {
62
58
 
59
+ if (layout.strokeBounds === layout.boxBounds) layout.spreadStroke()
63
60
 
64
- if (layout.renderChanged) {
61
+ this.__updateStrokeBounds()
62
+ this.__updateLocalStrokeBounds()
65
63
 
66
- layout.renderSpread = this.__updateRenderSpread()
64
+ } else {
65
+ layout.spreadStrokeCancel()
66
+ }
67
67
 
68
- if (layout.renderSpread) {
68
+ layout.strokeChanged = false
69
+ if (layout.renderSpread || layout.strokeSpread !== layout.strokeBoxSpread) layout.renderChanged = true
69
70
 
70
- if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds) {
71
- layout.spreadRender()
72
- }
71
+ if (this.parent) this.parent.__layout.strokeChange()
72
+ layout.resized = true
73
+ }
73
74
 
74
- this.__updateRenderBounds()
75
- this.__updateLocalRenderBounds()
76
75
 
77
- } else {
78
- layout.spreadRenderCancel()
79
- }
76
+ if (layout.renderChanged) {
80
77
 
81
- layout.renderChanged = false
78
+ layout.renderSpread = this.__updateRenderSpread()
82
79
 
83
- if (this.parent) this.parent.__layout.renderChange()
84
- }
80
+ if (layout.renderSpread) {
85
81
 
82
+ if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds) layout.spreadRender()
86
83
 
87
- layout.boundsChanged = false
84
+ this.__updateRenderBounds()
85
+ this.__updateLocalRenderBounds()
88
86
 
89
- toOuterOf(this.__layout.renderBounds, this.__world, this.__world)
87
+ } else {
88
+ layout.spreadRenderCancel()
89
+ }
90
90
 
91
- if (resize) this.__onUpdateSize()
91
+ layout.renderChanged = false
92
92
 
93
- } else {
94
- toOuterOf(this.__layout.renderBounds, this.__world, this.__world)
93
+ if (this.parent) this.parent.__layout.renderChange()
95
94
  }
96
95
 
96
+ layout.boundsChanged = false
97
+
97
98
  },
98
99
 
99
100
  __updateLocalBoxBounds(): void {
101
+ if (this.__hasAutoLayout) this.__updateAutoLayout() // origin / around / flow
100
102
  toOuterOf(this.__layout.boxBounds, this.__local, this.__local)
101
103
  },
102
104
 
103
105
  __updateLocalStrokeBounds(): void {
104
- toOuterOf(this.__layout.strokeBounds, this.__local, this.__layout.localStrokeBounds)
106
+ toOuterOf(this.__layout.strokeBounds, this.__localMatrix, this.__layout.localStrokeBounds)
105
107
  },
106
108
 
107
109
  __updateLocalRenderBounds(): void {
108
- toOuterOf(this.__layout.renderBounds, this.__local, this.__layout.localRenderBounds)
110
+ toOuterOf(this.__layout.renderBounds, this.__localMatrix, this.__layout.localRenderBounds)
109
111
  },
110
112
 
111
113
 
112
114
  __updateBoxBounds(): void {
113
115
  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
116
+ const data = this.__
117
+ if (data.__pathInputed) {
118
+ toBounds(data.__pathForRender, b)
119
+ } else {
120
+ b.x = 0
121
+ b.y = 0
122
+ b.width = data.width
123
+ b.height = data.height
124
+ }
125
+ },
126
+
127
+
128
+ __updateAutoLayout(): void {
129
+ this.__layout.matrixChanged = true
130
+ if (this.isBranch) {
131
+ if (this.leafer && this.leafer.ready) this.leafer.layouter.addExtra(this) // add part
132
+
133
+ if (this.__.flow) {
134
+
135
+ if (this.__layout.boxChanged) this.__updateFlowLayout()
136
+
137
+ updateAllMatrix(this)
138
+ updateBounds(this, this)
139
+
140
+ if (this.__.__autoSide) this.__updateBoxBounds()
141
+
142
+ } else {
143
+
144
+ updateAllMatrix(this)
145
+ updateBounds(this, this)
146
+
147
+ }
148
+
149
+ } else {
150
+ updateMatrix(this)
151
+ }
119
152
  },
120
153
 
121
154
  __updateNaturalSize(): void {
122
155
  const { __: data, __layout: layout } = this
123
156
  data.__naturalWidth = layout.boxBounds.width
124
157
  data.__naturalHeight = layout.boxBounds.height
125
-
126
- if (this.around) {
127
- layout.positionChanged = layout.matrixChanged = true
128
- this.__updateWorldMatrix()
129
- }
130
158
  },
131
159
 
132
160
  __updateStrokeBounds(): void {
133
- copyAndSpread(this.__layout.strokeBounds, this.__layout.boxBounds, this.__layout.strokeSpread)
161
+ const layout = this.__layout
162
+ copyAndSpread(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread)
134
163
  },
135
164
 
136
165
  __updateRenderBounds(): void {
137
- copyAndSpread(this.__layout.renderBounds, this.__layout.strokeBounds, this.__layout.renderSpread)
138
- },
166
+ const layout = this.__layout
167
+ layout.renderSpread > 0 ? copyAndSpread(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy(layout.renderBounds, layout.strokeBounds) // Box use -1
168
+ }
139
169
 
140
170
  }
@@ -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
  }
@@ -33,36 +33,59 @@ export const LeafEventer: ILeafEventerModule = {
33
33
  })
34
34
  },
35
35
 
36
- off(type: string | string[], listener: IEventListener, options?: IEventListenerOptions | boolean): void {
37
- let capture: boolean
38
- if (options) capture = typeof options === 'boolean' ? options : options.capture
36
+ off(type?: string | string[], listener?: IEventListener, options?: IEventListenerOptions | boolean): void {
37
+ if (type) {
39
38
 
40
- let events: IEventListenerItem[], index: number
41
- const map = __getListenerMap(this, capture)
42
- const typeList = typeof type === 'string' ? type.split(' ') : type
39
+ const typeList = typeof type === 'string' ? type.split(' ') : type
40
+
41
+ if (listener) {
42
+
43
+ let capture: boolean
44
+ if (options) capture = typeof options === 'boolean' ? options : options.capture
45
+
46
+ let events: IEventListenerItem[], index: number
47
+ const map = __getListenerMap(this, capture)
48
+
49
+ typeList.forEach(type => {
50
+ if (type) {
51
+ events = map[type]
52
+ if (events) {
53
+ index = events.findIndex(item => item.listener === listener)
54
+ if (index > -1) events.splice(index, 1)
55
+ if (!events.length) delete map[type]
56
+ }
57
+ }
58
+ })
59
+
60
+ } else {
61
+
62
+ // off type
63
+ const { __bubbleMap: b, __captureMap: c } = this
64
+ typeList.forEach(type => {
65
+ if (b) delete b[type]
66
+ if (c) delete c[type]
67
+ })
43
68
 
44
- typeList.forEach(type => {
45
- if (type) {
46
- events = map[type]
47
- if (events) {
48
- index = events.findIndex(item => item.listener === listener)
49
- if (index > -1) events.splice(index, 1)
50
- if (!events.length) delete map[type]
51
- }
52
69
  }
53
- })
70
+
71
+ } else {
72
+
73
+ this.__bubbleMap = this.__captureMap = undefined // off all
74
+
75
+ }
76
+
54
77
  },
55
78
 
56
79
  on_(type: string | string[], listener: IEventListener, bind?: IObject, options?: IEventListenerOptions | boolean): IEventListenerId {
57
80
  if (bind) listener = listener.bind(bind)
58
81
  this.on(type, listener, options)
59
- return { type, listener, options }
82
+ return { type, current: this, listener, options }
60
83
  },
61
84
 
62
85
  off_(id: IEventListenerId | IEventListenerId[]): void {
63
86
  if (!id) return
64
87
  const list = id instanceof Array ? id : [id]
65
- list.forEach(item => this.off(item.type, item.listener, item.options))
88
+ list.forEach(item => item.current.off(item.type, item.listener, item.options))
66
89
  list.length = 0
67
90
  },
68
91
 
@@ -87,6 +110,8 @@ export const LeafEventer: ILeafEventerModule = {
87
110
  if (event && (event as IEvent).isStopNow) break
88
111
  }
89
112
  }
113
+
114
+ this.syncEventer && this.syncEventer.emitEvent(event, capture)
90
115
  },
91
116
 
92
117
  emitEvent(event: IEvent, capture?: boolean): void {
@@ -95,12 +120,11 @@ export const LeafEventer: ILeafEventerModule = {
95
120
  },
96
121
 
97
122
  hasEvent(type: string, capture?: boolean): boolean {
123
+ if (this.syncEventer && this.syncEventer.hasEvent(type, capture)) return true
124
+
98
125
  const { __bubbleMap: b, __captureMap: c } = this
99
- if (capture === undefined) {
100
- return !!((c && c[type]) || (b && b[type]))
101
- } else {
102
- return !!(capture ? (c && c[type]) : (b && b[type]))
103
- }
126
+ const hasB = b && b[type], hasC = c && c[type]
127
+ return !!(capture === undefined ? (hasB || hasC) : (capture ? hasC : hasB))
104
128
  },
105
129
 
106
130
  }
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, IScrollPointData } 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, this.parent && this.parent.__ as IScrollPointData)
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 + data.offsetX
32
+ local.f = data.y + data.offsetY
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 || data.origin) {
35
+ toPoint(data.around || data.origin, layout.boxBounds, tempPoint)
36
+ translateInner(local, -tempPoint.x, -tempPoint.y, data.origin as unknown as boolean)
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,39 @@ 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
+ if (this.__.eraser === 'path') return this.__renderEraser(canvas, options)
15
+
16
+ const tempCanvas = canvas.getSameCanvas(true, true)
14
17
  this.__draw(tempCanvas, options)
15
18
 
16
- const blendMode = this.__.isEraser ? 'destination-out' : this.__.blendMode
17
- if (options.matrix || this.__hasMirror) {
18
- canvas.copyWorldByReset(tempCanvas, null, null, blendMode)
19
+ if (this.__worldFlipped) {
20
+ canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, this.__.__blendMode, true)
19
21
  } else {
20
- canvas.copyWorldToInner(tempCanvas, this.__world, this.__layout.renderBounds, blendMode)
22
+ canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, this.__.__blendMode)
21
23
  }
22
- tempCanvas.recycle()
24
+
25
+ tempCanvas.recycle(this.__nowWorld)
26
+
23
27
  } else {
28
+
24
29
  this.__draw(canvas, options)
30
+
25
31
  }
32
+
33
+ }
34
+ },
35
+
36
+ __clip(canvas: ILeaferCanvas, options: IRenderOptions): void {
37
+ if (this.__worldOpacity) {
38
+ canvas.setWorld(this.__nowWorld = this.__getNowWorld(options))
39
+ this.__drawRenderPath(canvas)
40
+ this.__.windingRule ? canvas.clip(this.__.windingRule) : canvas.clip()
26
41
  }
27
42
  },
28
43
 
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
- }