@leafer/display-module 1.0.0-beta.9 → 1.0.0-rc.1

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,12 +1,15 @@
1
1
  {
2
2
  "name": "@leafer/display-module",
3
- "version": "1.0.0-beta.9",
3
+ "version": "1.0.0-rc.1",
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
- "src"
10
+ "src",
11
+ "types",
12
+ "dist"
10
13
  ],
11
14
  "repository": {
12
15
  "type": "git",
@@ -19,10 +22,10 @@
19
22
  "leaferjs"
20
23
  ],
21
24
  "dependencies": {
22
- "@leafer/event": "1.0.0-beta.9",
23
- "@leafer/math": "1.0.0-beta.9"
25
+ "@leafer/event": "1.0.0-rc.1",
26
+ "@leafer/math": "1.0.0-rc.1"
24
27
  },
25
28
  "devDependencies": {
26
- "@leafer/interface": "1.0.0-beta.9"
29
+ "@leafer/interface": "1.0.0-rc.1"
27
30
  }
28
31
  }
package/src/LeafBounds.ts CHANGED
@@ -111,10 +111,22 @@ export const LeafBounds: ILeafBoundsModule = {
111
111
 
112
112
  __updateBoxBounds(): void {
113
113
  const b = this.__layout.boxBounds
114
+ const { width, height } = this.__
114
115
  b.x = 0
115
116
  b.y = 0
116
- b.width = this.__.width
117
- b.height = this.__.height
117
+ b.width = width
118
+ b.height = height
119
+ },
120
+
121
+ __updateNaturalSize(): void {
122
+ const { __: data, __layout: layout } = this
123
+ data.__naturalWidth = layout.boxBounds.width
124
+ data.__naturalHeight = layout.boxBounds.height
125
+
126
+ if (this.around) {
127
+ layout.positionChanged = layout.matrixChanged = true
128
+ this.__updateWorldMatrix()
129
+ }
118
130
  },
119
131
 
120
132
  __updateStrokeBounds(): void {
@@ -5,12 +5,14 @@ import { PropertyEvent } from '@leafer/event'
5
5
  export const LeafDataProxy: ILeafDataProxyModule = {
6
6
 
7
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)
8
+ if (this.leafer && this.leafer.created) {
9
+ if (typeof newValue === 'object' || this.__.__getInput(name) !== newValue) {
10
+ this.__[name] = newValue
11
+ 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)
14
+ this.leafer.emitEvent(event)
15
+ }
14
16
  } else {
15
17
  this.__[name] = newValue
16
18
  }
@@ -61,9 +61,7 @@ export const LeafEventer: ILeafEventerModule = {
61
61
  off_(id: IEventListenerId | IEventListenerId[]): void {
62
62
  if (!id) return
63
63
  const list = id instanceof Array ? id : [id]
64
- list.forEach(item => {
65
- this.off(item.type, item.listener, item.options)
66
- })
64
+ list.forEach(item => this.off(item.type, item.listener, item.options))
67
65
  list.length = 0
68
66
  },
69
67
 
package/src/LeafHit.ts CHANGED
@@ -2,16 +2,22 @@ import { ILeafHitModule, IRadiusPointData, ILeaferCanvas } from '@leafer/interfa
2
2
  import { PointHelper } from '@leafer/math'
3
3
 
4
4
 
5
- const { toInnerRadiusPointOf } = PointHelper
5
+ const { toInnerRadiusPointOf, copy, setRadius } = PointHelper
6
6
  const inner = {} as IRadiusPointData
7
7
 
8
8
  export const LeafHit: ILeafHitModule = {
9
9
 
10
10
  __hitWorld(point: IRadiusPointData): boolean {
11
- if (this.__layout.hitCanvasChanged) {
11
+ if (this.__layout.hitCanvasChanged || !this.__hitCanvas) {
12
12
  this.__updateHitCanvas()
13
13
  this.__layout.hitCanvasChanged = false
14
14
  }
15
+
16
+ if (this.__.hitRadius) {
17
+ copy(inner, point), point = inner
18
+ setRadius(point, this.__.hitRadius)
19
+ }
20
+
15
21
  toInnerRadiusPointOf(point, this.__world, inner)
16
22
  return this.__hit(inner)
17
23
  },
package/src/LeafMatrix.ts CHANGED
@@ -1,15 +1,16 @@
1
- import { ILeafMatrixModule } from '@leafer/interface'
1
+ import { ILeafMatrixModule, IPointData } 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, rotation: 0, skewX: 0, skewY: 0 }
7
+ const defaultCenter: IPointData = { x: 0.5, y: 0.5 }
7
8
 
8
9
  export const LeafMatrix: ILeafMatrixModule = {
9
10
 
10
11
  __updateWorldMatrix(): void {
11
12
 
12
- const pw = this.parent ? this.parent.__world : defaultMatrix
13
+ const pw = this.parent ? this.parent.__world : defaultWorld
13
14
  const r = this.__local
14
15
  const w = this.__world
15
16
 
@@ -22,6 +23,14 @@ export const LeafMatrix: ILeafMatrixModule = {
22
23
  w.d = r.c * pw.b + r.d * pw.d
23
24
  w.e = r.e * pw.a + r.f * pw.c + pw.e
24
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
25
34
  } else {
26
35
  w.a = pw.a
27
36
  w.b = pw.b
@@ -29,6 +38,13 @@ export const LeafMatrix: ILeafMatrixModule = {
29
38
  w.d = pw.d
30
39
  w.e = r.e * pw.a + r.f * pw.c + pw.e
31
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
32
48
  }
33
49
  },
34
50
 
@@ -88,12 +104,20 @@ export const LeafMatrix: ILeafMatrixModule = {
88
104
  if (layout.positionChanged) {
89
105
  r.e = this.__.x
90
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
113
+ }
91
114
  layout.positionChanged = false
92
115
  }
93
116
 
94
117
  this.__layout.matrixChanged = false
95
118
  }
96
119
 
120
+
97
121
  }
98
122
 
99
123
 
package/src/LeafRender.ts CHANGED
@@ -14,9 +14,8 @@ export const LeafRender: ILeafRenderModule = {
14
14
  this.__draw(tempCanvas, options)
15
15
 
16
16
  const blendMode = this.__.isEraser ? 'destination-out' : this.__.blendMode
17
- if (options.matrix) {
18
- canvas.resetTransform()
19
- canvas.copyWorld(tempCanvas, null, null, blendMode)
17
+ if (options.matrix || this.__hasMirror) {
18
+ canvas.copyWorldByReset(tempCanvas, null, null, blendMode)
20
19
  } else {
21
20
  canvas.copyWorldToInner(tempCanvas, this.__world, this.__layout.renderBounds, blendMode)
22
21
  }
@@ -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 };