@leafer/display-module 1.0.0-beta.12 → 1.0.0-beta.16

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.12",
3
+ "version": "1.0.0-beta.16",
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.12",
23
- "@leafer/math": "1.0.0-beta.12"
25
+ "@leafer/event": "1.0.0-beta.16",
26
+ "@leafer/math": "1.0.0-beta.16"
24
27
  },
25
28
  "devDependencies": {
26
- "@leafer/interface": "1.0.0-beta.12"
29
+ "@leafer/interface": "1.0.0-beta.16"
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,7 +2,7 @@ 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 = {
@@ -12,6 +12,12 @@ export const LeafHit: ILeafHitModule = {
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,9 +1,10 @@
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
5
  const { sin, cos } = Math
6
- const defaultWorld = { ...MatrixHelper.defaultMatrix, scaleX: 1, scaleY: 1 }
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
 
@@ -23,8 +24,13 @@ export const LeafMatrix: ILeafMatrixModule = {
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
25
26
 
26
- w.scaleX = pw.scaleX * this.__.scaleX
27
- w.scaleY = pw.scaleY * this.__.scaleY
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
28
34
  } else {
29
35
  w.a = pw.a
30
36
  w.b = pw.b
@@ -35,6 +41,10 @@ export const LeafMatrix: ILeafMatrixModule = {
35
41
 
36
42
  w.scaleX = pw.scaleX
37
43
  w.scaleY = pw.scaleY
44
+
45
+ w.rotation = pw.rotation
46
+ w.skewX = pw.skewX
47
+ w.skewY = pw.skewY
38
48
  }
39
49
  },
40
50
 
@@ -94,12 +104,20 @@ export const LeafMatrix: ILeafMatrixModule = {
94
104
  if (layout.positionChanged) {
95
105
  r.e = this.__.x
96
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
+ }
97
114
  layout.positionChanged = false
98
115
  }
99
116
 
100
117
  this.__layout.matrixChanged = false
101
118
  }
102
119
 
120
+
103
121
  }
104
122
 
105
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 };