@leafer/display-module 1.0.0-beta → 1.0.0-beta.11

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-beta",
3
+ "version": "1.0.0-beta.11",
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-beta",
23
- "@leafer/math": "1.0.0-beta"
22
+ "@leafer/event": "1.0.0-beta.11",
23
+ "@leafer/math": "1.0.0-beta.11"
24
24
  },
25
25
  "devDependencies": {
26
- "@leafer/interface": "1.0.0-beta"
26
+ "@leafer/interface": "1.0.0-beta.11"
27
27
  }
28
28
  }
@@ -0,0 +1,90 @@
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
+ }
@@ -7,9 +7,12 @@ export const LeafEventer: ILeafEventerModule = {
7
7
  on(type: string | string[], listener: IEventListener, options?: IEventListenerOptions | boolean): void {
8
8
  let capture: boolean, once: boolean
9
9
  if (options) {
10
- const isBoolean = typeof options === 'boolean'
11
- capture = isBoolean ? options : options.capture
12
- once = isBoolean ? false : options.once
10
+ if (typeof options === 'boolean') {
11
+ capture = options
12
+ } else {
13
+ capture = options.capture
14
+ once = options.once
15
+ }
13
16
  }
14
17
 
15
18
  let events: IEventListenerItem[]
package/src/LeafMask.ts CHANGED
@@ -3,6 +3,10 @@ import { ILeaf, ILeaferCanvas, ILeafMaskModule } from '@leafer/interface'
3
3
 
4
4
  export const LeafMask: ILeafMaskModule = {
5
5
 
6
+ __updateEraser(value?: boolean): void {
7
+ this.__hasEraser = value ? true : this.children.some(item => item.__.isEraser)
8
+ },
9
+
6
10
  __updateMask(value?: boolean): void {
7
11
  this.__hasMask = value ? true : this.children.some(item => item.__.isMask)
8
12
  },
@@ -11,6 +15,7 @@ export const LeafMask: ILeafMaskModule = {
11
15
  content.resetTransform()
12
16
  content.useMask(mask)
13
17
  canvas.resetTransform()
18
+ canvas.opacity = this.__worldOpacity
14
19
  canvas.copyWorld(content)
15
20
  },
16
21
 
package/src/LeafMatrix.ts CHANGED
@@ -2,14 +2,14 @@ import { ILeafMatrixModule } from '@leafer/interface'
2
2
  import { OneRadian, MatrixHelper } from '@leafer/math'
3
3
 
4
4
 
5
- const { defaultMatrix } = MatrixHelper
6
5
  const { sin, cos } = Math
6
+ const defaultWorld = { ...MatrixHelper.defaultMatrix, scaleX: 1, scaleY: 1 }
7
7
 
8
8
  export const LeafMatrix: ILeafMatrixModule = {
9
9
 
10
10
  __updateWorldMatrix(): void {
11
11
 
12
- const pw = this.parent ? this.parent.__world : defaultMatrix
12
+ const pw = this.parent ? this.parent.__world : defaultWorld
13
13
  const r = this.__local
14
14
  const w = this.__world
15
15
 
@@ -22,6 +22,9 @@ export const LeafMatrix: ILeafMatrixModule = {
22
22
  w.d = r.c * pw.b + r.d * pw.d
23
23
  w.e = r.e * pw.a + r.f * pw.c + pw.e
24
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
25
28
  } else {
26
29
  w.a = pw.a
27
30
  w.b = pw.b
@@ -29,6 +32,9 @@ export const LeafMatrix: ILeafMatrixModule = {
29
32
  w.d = pw.d
30
33
  w.e = r.e * pw.a + r.f * pw.c + pw.e
31
34
  w.f = r.e * pw.b + r.f * pw.d + pw.f
35
+
36
+ w.scaleX = pw.scaleX
37
+ w.scaleY = pw.scaleY
32
38
  }
33
39
  },
34
40
 
package/src/LeafRender.ts CHANGED
@@ -7,7 +7,23 @@ 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.__draw(canvas, options)
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
+ }
11
27
  }
12
28
  },
13
29
 
package/src/index.ts CHANGED
@@ -6,3 +6,4 @@ export { LeafHit } from './LeafHit'
6
6
  export { LeafRender } from './LeafRender'
7
7
  export { LeafMask } from './LeafMask'
8
8
 
9
+ export { BranchRender } from './BranchRender'