@leafer/display-module 1.0.0-beta.11 → 1.0.0-beta.15
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 +7 -5
- package/types/index.d.ts +19 -0
- package/src/BranchRender.ts +0 -90
- package/src/LeafBounds.ts +0 -128
- package/src/LeafDataProxy.ts +0 -23
- package/src/LeafEventer.ts +0 -127
- package/src/LeafHit.ts +0 -23
- package/src/LeafMask.ts +0 -38
- package/src/LeafMatrix.ts +0 -105
- package/src/LeafRender.ts +0 -35
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/display-module",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.15",
|
|
4
4
|
"description": "@leafer/display-module",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.ts",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
8
9
|
"files": [
|
|
9
|
-
"
|
|
10
|
+
"types",
|
|
11
|
+
"dist"
|
|
10
12
|
],
|
|
11
13
|
"repository": {
|
|
12
14
|
"type": "git",
|
|
@@ -19,10 +21,10 @@
|
|
|
19
21
|
"leaferjs"
|
|
20
22
|
],
|
|
21
23
|
"dependencies": {
|
|
22
|
-
"@leafer/event": "1.0.0-beta.
|
|
23
|
-
"@leafer/math": "1.0.0-beta.
|
|
24
|
+
"@leafer/event": "1.0.0-beta.15",
|
|
25
|
+
"@leafer/math": "1.0.0-beta.15"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-beta.
|
|
28
|
+
"@leafer/interface": "1.0.0-beta.15"
|
|
27
29
|
}
|
|
28
30
|
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ILeafEventerModule, ILeafDataProxyModule, ILeafMatrixModule, ILeafBoundsModule, ILeafHitModule, ILeafRenderModule, ILeafMaskModule, IBranchRenderModule } from '@leafer/interface';
|
|
2
|
+
|
|
3
|
+
declare const LeafEventer: ILeafEventerModule;
|
|
4
|
+
|
|
5
|
+
declare const LeafDataProxy: ILeafDataProxyModule;
|
|
6
|
+
|
|
7
|
+
declare const LeafMatrix: ILeafMatrixModule;
|
|
8
|
+
|
|
9
|
+
declare const LeafBounds: ILeafBoundsModule;
|
|
10
|
+
|
|
11
|
+
declare const LeafHit: ILeafHitModule;
|
|
12
|
+
|
|
13
|
+
declare const LeafRender: ILeafRenderModule;
|
|
14
|
+
|
|
15
|
+
declare const LeafMask: ILeafMaskModule;
|
|
16
|
+
|
|
17
|
+
declare const BranchRender: IBranchRenderModule;
|
|
18
|
+
|
|
19
|
+
export { BranchRender, LeafBounds, LeafDataProxy, LeafEventer, LeafHit, LeafMask, LeafMatrix, LeafRender };
|
package/src/BranchRender.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { ILeaf, ILeaferCanvas, IRenderOptions, IBranchRenderModule } from '@leafer/interface'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export const BranchRender: IBranchRenderModule = {
|
|
5
|
-
|
|
6
|
-
__updateChange(): void {
|
|
7
|
-
const { __layout: layout } = this
|
|
8
|
-
if (layout.childrenSortChanged) {
|
|
9
|
-
this.__updateSortChildren()
|
|
10
|
-
layout.childrenSortChanged = false
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
this.__.__checkSingle()
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
__render(canvas: ILeaferCanvas, options: IRenderOptions): void {
|
|
18
|
-
if (this.__worldOpacity) {
|
|
19
|
-
|
|
20
|
-
if (this.__.__single) {
|
|
21
|
-
canvas.resetTransform()
|
|
22
|
-
const tempCanvas = canvas.getSameCanvas()
|
|
23
|
-
|
|
24
|
-
this.__renderBranch(tempCanvas, options)
|
|
25
|
-
|
|
26
|
-
canvas.opacity = this.__worldOpacity
|
|
27
|
-
|
|
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)
|
|
30
|
-
|
|
31
|
-
tempCanvas.recycle()
|
|
32
|
-
} else {
|
|
33
|
-
this.__renderBranch(canvas, options)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
__renderBranch(canvas: ILeaferCanvas, options: IRenderOptions): void {
|
|
40
|
-
|
|
41
|
-
let child: ILeaf
|
|
42
|
-
const { children } = this
|
|
43
|
-
|
|
44
|
-
if (this.__hasMask && children.length > 1) {
|
|
45
|
-
|
|
46
|
-
let mask: boolean
|
|
47
|
-
let maskCanvas = canvas.getSameCanvas()
|
|
48
|
-
let contentCanvas = canvas.getSameCanvas()
|
|
49
|
-
|
|
50
|
-
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)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this.__renderMask(canvas, contentCanvas, maskCanvas)
|
|
70
|
-
maskCanvas.recycle()
|
|
71
|
-
contentCanvas.recycle()
|
|
72
|
-
|
|
73
|
-
} else {
|
|
74
|
-
|
|
75
|
-
const { bounds, hideBounds } = options
|
|
76
|
-
|
|
77
|
-
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)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}
|
package/src/LeafBounds.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { ILeafBoundsModule } from '@leafer/interface'
|
|
2
|
-
import { BoundsHelper } from '@leafer/math'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { toOuterOf, copyAndSpread } = BoundsHelper
|
|
6
|
-
|
|
7
|
-
export const LeafBounds: ILeafBoundsModule = {
|
|
8
|
-
|
|
9
|
-
__updateWorldBounds(): void {
|
|
10
|
-
|
|
11
|
-
if (this.__layout.boundsChanged) {
|
|
12
|
-
|
|
13
|
-
let resize: boolean
|
|
14
|
-
const layout = this.__layout
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (layout.boxChanged) {
|
|
18
|
-
|
|
19
|
-
this.__updatePath()
|
|
20
|
-
this.__updateRenderPath()
|
|
21
|
-
|
|
22
|
-
this.__updateBoxBounds()
|
|
23
|
-
layout.boxChanged = false
|
|
24
|
-
resize = true
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (layout.localBoxChanged) { // position change
|
|
29
|
-
|
|
30
|
-
this.__updateLocalBoxBounds()
|
|
31
|
-
layout.localBoxChanged = false
|
|
32
|
-
|
|
33
|
-
if (layout.strokeSpread) layout.strokeChanged = true
|
|
34
|
-
if (layout.renderSpread) layout.renderChanged = true
|
|
35
|
-
this.parent?.__layout.boxChange()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (layout.strokeChanged) {
|
|
40
|
-
|
|
41
|
-
layout.strokeSpread = this.__updateStrokeSpread()
|
|
42
|
-
|
|
43
|
-
if (layout.strokeSpread) {
|
|
44
|
-
|
|
45
|
-
if (layout.strokeBounds === layout.boxBounds) {
|
|
46
|
-
layout.spreadStroke()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.__updateStrokeBounds()
|
|
50
|
-
this.__updateLocalStrokeBounds()
|
|
51
|
-
|
|
52
|
-
} else {
|
|
53
|
-
layout.spreadStrokeCancel()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
layout.strokeChanged = false
|
|
57
|
-
if (layout.renderSpread) layout.renderChanged = true
|
|
58
|
-
|
|
59
|
-
if (this.parent) this.parent.__layout.strokeChange()
|
|
60
|
-
resize || (resize = true)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (layout.renderChanged) {
|
|
65
|
-
|
|
66
|
-
layout.renderSpread = this.__updateRenderSpread()
|
|
67
|
-
|
|
68
|
-
if (layout.renderSpread) {
|
|
69
|
-
|
|
70
|
-
if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds) {
|
|
71
|
-
layout.spreadRender()
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
this.__updateRenderBounds()
|
|
75
|
-
this.__updateLocalRenderBounds()
|
|
76
|
-
|
|
77
|
-
} else {
|
|
78
|
-
layout.spreadRenderCancel()
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
layout.renderChanged = false
|
|
82
|
-
|
|
83
|
-
if (this.parent) this.parent.__layout.renderChange()
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
}
|
|
96
|
-
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
__updateLocalBoxBounds(): void {
|
|
100
|
-
toOuterOf(this.__layout.boxBounds, this.__local, this.__local)
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
__updateLocalStrokeBounds(): void {
|
|
104
|
-
toOuterOf(this.__layout.strokeBounds, this.__local, this.__layout.localStrokeBounds)
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
__updateLocalRenderBounds(): void {
|
|
108
|
-
toOuterOf(this.__layout.renderBounds, this.__local, this.__layout.localRenderBounds)
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
__updateBoxBounds(): void {
|
|
113
|
-
const b = this.__layout.boxBounds
|
|
114
|
-
b.x = 0
|
|
115
|
-
b.y = 0
|
|
116
|
-
b.width = this.__.width
|
|
117
|
-
b.height = this.__.height
|
|
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
|
-
},
|
|
127
|
-
|
|
128
|
-
}
|
package/src/LeafDataProxy.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ILeafDataProxyModule } from '@leafer/interface'
|
|
2
|
-
import { PropertyEvent } from '@leafer/event'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const LeafDataProxy: ILeafDataProxyModule = {
|
|
6
|
-
|
|
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
|
-
} else {
|
|
15
|
-
this.__[name] = newValue
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
__getAttr(name: string): unknown {
|
|
20
|
-
return this.__.__get(name)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|
package/src/LeafEventer.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { IEventListener, IEventListenerOptions, IEventListenerMap, IEventListenerItem, IEventListenerId, IEvent, IObject, IEventTarget, ILeafEventerModule } from '@leafer/interface'
|
|
2
|
-
|
|
3
|
-
const empty = {}
|
|
4
|
-
|
|
5
|
-
export const LeafEventer: ILeafEventerModule = {
|
|
6
|
-
|
|
7
|
-
on(type: string | string[], listener: IEventListener, options?: IEventListenerOptions | boolean): void {
|
|
8
|
-
let capture: boolean, once: boolean
|
|
9
|
-
if (options) {
|
|
10
|
-
if (typeof options === 'boolean') {
|
|
11
|
-
capture = options
|
|
12
|
-
} else {
|
|
13
|
-
capture = options.capture
|
|
14
|
-
once = options.once
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let events: IEventListenerItem[]
|
|
19
|
-
const map = __getListenerMap(this, capture, true)
|
|
20
|
-
const typeList = typeof type === 'string' ? type.split(' ') : type
|
|
21
|
-
const item = once ? { listener, once } : { listener }
|
|
22
|
-
|
|
23
|
-
typeList.forEach(type => {
|
|
24
|
-
if (type) {
|
|
25
|
-
events = map[type]
|
|
26
|
-
if (events) {
|
|
27
|
-
if (events.findIndex(item => item.listener === listener) === -1) events.push(item)
|
|
28
|
-
} else {
|
|
29
|
-
map[type] = [item]
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
off(type: string | string[], listener: IEventListener, options?: IEventListenerOptions | boolean): void {
|
|
36
|
-
let capture: boolean
|
|
37
|
-
if (options) capture = typeof options === 'boolean' ? options : options.capture
|
|
38
|
-
|
|
39
|
-
let events: IEventListenerItem[], index: number
|
|
40
|
-
const map = __getListenerMap(this, capture)
|
|
41
|
-
const typeList = typeof type === 'string' ? type.split(' ') : type
|
|
42
|
-
|
|
43
|
-
typeList.forEach(type => {
|
|
44
|
-
if (type) {
|
|
45
|
-
events = map[type]
|
|
46
|
-
if (events) {
|
|
47
|
-
index = events.findIndex(item => item.listener === listener)
|
|
48
|
-
if (index > -1) events.splice(index, 1)
|
|
49
|
-
if (!events.length) delete map[type]
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
on_(type: string | string[], listener: IEventListener, bind?: IObject, options?: IEventListenerOptions | boolean): IEventListenerId {
|
|
56
|
-
if (bind) listener = listener.bind(bind)
|
|
57
|
-
this.on(type, listener, options)
|
|
58
|
-
return { type, listener, options }
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
off_(id: IEventListenerId | IEventListenerId[]): void {
|
|
62
|
-
if (!id) return
|
|
63
|
-
const list = id instanceof Array ? id : [id]
|
|
64
|
-
list.forEach(item => {
|
|
65
|
-
this.off(item.type, item.listener, item.options)
|
|
66
|
-
})
|
|
67
|
-
list.length = 0
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
once(type: string | string[], listener: IEventListener, capture?: boolean): void {
|
|
71
|
-
this.on(type, listener, { once: true, capture })
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
emit(type: string, event?: IEvent | IObject, capture?: boolean): void {
|
|
75
|
-
const map = __getListenerMap(this, capture)
|
|
76
|
-
const list = map[type]
|
|
77
|
-
if (list) {
|
|
78
|
-
let item: IEventListenerItem
|
|
79
|
-
for (let i = 0, len = list.length; i < len; i++) {
|
|
80
|
-
item = list[i]
|
|
81
|
-
item.listener(event)
|
|
82
|
-
if (item.once) {
|
|
83
|
-
this.off(type, item.listener, capture)
|
|
84
|
-
i--, len--
|
|
85
|
-
}
|
|
86
|
-
if (event && (event as IEvent).isStopNow) break
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
emitEvent(event: IEvent, capture?: boolean): void {
|
|
92
|
-
event.current = this
|
|
93
|
-
this.emit(event.type, event, capture)
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
hasEvent(type: string, capture?: boolean): boolean {
|
|
97
|
-
const { __bubbleMap: b, __captureMap: c } = this
|
|
98
|
-
if (capture === undefined) {
|
|
99
|
-
return !!((c && c[type]) || (b && b[type]))
|
|
100
|
-
} else {
|
|
101
|
-
return !!(capture ? (c && c[type]) : (b && b[type]))
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function __getListenerMap(eventer: IEventTarget, capture?: boolean, create?: boolean): IEventListenerMap {
|
|
108
|
-
if (capture) {
|
|
109
|
-
|
|
110
|
-
const { __captureMap: c } = eventer
|
|
111
|
-
if (c) {
|
|
112
|
-
return c
|
|
113
|
-
} else {
|
|
114
|
-
return create ? eventer.__captureMap = {} : empty
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
} else {
|
|
118
|
-
|
|
119
|
-
const { __bubbleMap: b } = eventer
|
|
120
|
-
if (b) {
|
|
121
|
-
return b
|
|
122
|
-
} else {
|
|
123
|
-
return create ? eventer.__bubbleMap = {} : empty
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
}
|
package/src/LeafHit.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ILeafHitModule, IRadiusPointData, ILeaferCanvas } from '@leafer/interface'
|
|
2
|
-
import { PointHelper } from '@leafer/math'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { toInnerRadiusPointOf } = PointHelper
|
|
6
|
-
const inner = {} as IRadiusPointData
|
|
7
|
-
|
|
8
|
-
export const LeafHit: ILeafHitModule = {
|
|
9
|
-
|
|
10
|
-
__hitWorld(point: IRadiusPointData): boolean {
|
|
11
|
-
if (this.__layout.hitCanvasChanged) {
|
|
12
|
-
this.__updateHitCanvas()
|
|
13
|
-
this.__layout.hitCanvasChanged = false
|
|
14
|
-
}
|
|
15
|
-
toInnerRadiusPointOf(point, this.__world, inner)
|
|
16
|
-
return this.__hit(inner)
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
__drawHitPath(canvas: ILeaferCanvas): void {
|
|
20
|
-
this.__drawRenderPath(canvas)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|
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
|
-
}
|
package/src/LeafMatrix.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { ILeafMatrixModule } from '@leafer/interface'
|
|
2
|
-
import { OneRadian, MatrixHelper } from '@leafer/math'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { sin, cos } = Math
|
|
6
|
-
const defaultWorld = { ...MatrixHelper.defaultMatrix, scaleX: 1, scaleY: 1 }
|
|
7
|
-
|
|
8
|
-
export const LeafMatrix: ILeafMatrixModule = {
|
|
9
|
-
|
|
10
|
-
__updateWorldMatrix(): void {
|
|
11
|
-
|
|
12
|
-
const pw = this.parent ? this.parent.__world : defaultWorld
|
|
13
|
-
const r = this.__local
|
|
14
|
-
const w = this.__world
|
|
15
|
-
|
|
16
|
-
if (this.__layout.matrixChanged) this.__updateLocalMatrix()
|
|
17
|
-
|
|
18
|
-
if (this.__layout.affectScaleOrRotation) {
|
|
19
|
-
w.a = r.a * pw.a + r.b * pw.c
|
|
20
|
-
w.b = r.a * pw.b + r.b * pw.d
|
|
21
|
-
w.c = r.c * pw.a + r.d * pw.c
|
|
22
|
-
w.d = r.c * pw.b + r.d * pw.d
|
|
23
|
-
w.e = r.e * pw.a + r.f * pw.c + pw.e
|
|
24
|
-
w.f = r.e * pw.b + r.f * pw.d + pw.f
|
|
25
|
-
|
|
26
|
-
w.scaleX = pw.scaleX * this.__.scaleX
|
|
27
|
-
w.scaleY = pw.scaleY * this.__.scaleY
|
|
28
|
-
} else {
|
|
29
|
-
w.a = pw.a
|
|
30
|
-
w.b = pw.b
|
|
31
|
-
w.c = pw.c
|
|
32
|
-
w.d = pw.d
|
|
33
|
-
w.e = r.e * pw.a + r.f * pw.c + pw.e
|
|
34
|
-
w.f = r.e * pw.b + r.f * pw.d + pw.f
|
|
35
|
-
|
|
36
|
-
w.scaleX = pw.scaleX
|
|
37
|
-
w.scaleY = pw.scaleY
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
__updateLocalMatrix(): void {
|
|
42
|
-
|
|
43
|
-
const r = this.__local
|
|
44
|
-
const layout = this.__layout
|
|
45
|
-
|
|
46
|
-
if (layout.affectScaleOrRotation) {
|
|
47
|
-
|
|
48
|
-
const { scaleX, scaleY } = this.__
|
|
49
|
-
|
|
50
|
-
if (layout.affectRotation) {
|
|
51
|
-
|
|
52
|
-
if (layout.scaleChanged || layout.rotationChanged) {
|
|
53
|
-
|
|
54
|
-
let { rotation, skewX, skewY } = this.__
|
|
55
|
-
|
|
56
|
-
if (rotation || skewX || skewY) {
|
|
57
|
-
|
|
58
|
-
rotation *= OneRadian
|
|
59
|
-
if (skewX) skewX *= OneRadian
|
|
60
|
-
if (skewY) skewY *= OneRadian
|
|
61
|
-
|
|
62
|
-
r.a = scaleX * cos(rotation + skewY)
|
|
63
|
-
r.b = scaleX * sin(rotation + skewY)
|
|
64
|
-
r.c = scaleY * -sin(rotation - skewX)
|
|
65
|
-
r.d = scaleY * cos(rotation - skewX)
|
|
66
|
-
|
|
67
|
-
} else {
|
|
68
|
-
|
|
69
|
-
r.a = scaleX
|
|
70
|
-
r.b = 0
|
|
71
|
-
r.c = 0
|
|
72
|
-
r.d = scaleY
|
|
73
|
-
|
|
74
|
-
layout.affectRotation = false
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
layout.scaleChanged = false
|
|
78
|
-
layout.rotationChanged = false
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
} else {
|
|
83
|
-
|
|
84
|
-
if (layout.scaleChanged) {
|
|
85
|
-
r.a = scaleX
|
|
86
|
-
r.d = scaleY
|
|
87
|
-
layout.scaleChanged = false
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (layout.positionChanged) {
|
|
95
|
-
r.e = this.__.x
|
|
96
|
-
r.f = this.__.y
|
|
97
|
-
layout.positionChanged = false
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
this.__layout.matrixChanged = false
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
package/src/LeafRender.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ILeaferCanvas, IRenderOptions, ILeafRenderModule } from '@leafer/interface'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export const LeafRender: ILeafRenderModule = {
|
|
5
|
-
|
|
6
|
-
__render(canvas: ILeaferCanvas, options: IRenderOptions): void {
|
|
7
|
-
if (this.__worldOpacity) {
|
|
8
|
-
canvas.setWorld(this.__world, options.matrix)
|
|
9
|
-
canvas.opacity = this.__worldOpacity
|
|
10
|
-
|
|
11
|
-
if (this.__.__single) {
|
|
12
|
-
const tempCanvas = canvas.getSameCanvas(true)
|
|
13
|
-
|
|
14
|
-
this.__draw(tempCanvas, options)
|
|
15
|
-
|
|
16
|
-
const blendMode = this.__.isEraser ? 'destination-out' : this.__.blendMode
|
|
17
|
-
if (options.matrix) {
|
|
18
|
-
canvas.resetTransform()
|
|
19
|
-
canvas.copyWorld(tempCanvas, null, null, blendMode)
|
|
20
|
-
} else {
|
|
21
|
-
canvas.copyWorldToInner(tempCanvas, this.__world, this.__layout.renderBounds, blendMode)
|
|
22
|
-
}
|
|
23
|
-
tempCanvas.recycle()
|
|
24
|
-
} else {
|
|
25
|
-
this.__draw(canvas, options)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
__updateWorldOpacity(): void {
|
|
31
|
-
this.__worldOpacity = this.__.visible ? (this.parent ? this.parent.__worldOpacity * this.__.opacity : this.__.opacity) : 0
|
|
32
|
-
if (this.__layout.opacityChanged) this.__layout.opacityChanged = false
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
}
|