@leafer/decorator 1.0.0-rc.19 → 1.0.0-rc.20

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/decorator",
3
- "version": "1.0.0-rc.19",
3
+ "version": "1.0.0-rc.20",
4
4
  "description": "@leafer/decorator",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,10 +22,10 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/platform": "1.0.0-rc.19",
26
- "@leafer/debug": "1.0.0-rc.19"
25
+ "@leafer/platform": "1.0.0-rc.20",
26
+ "@leafer/debug": "1.0.0-rc.20"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.0.0-rc.19"
29
+ "@leafer/interface": "1.0.0-rc.20"
30
30
  }
31
31
  }
package/src/data.ts CHANGED
@@ -1,96 +1,90 @@
1
- import { ILeafData, ILeaf, IObject, IValue } from '@leafer/interface'
1
+ import { ILeafData, ILeaf, IObject, IValue, ILeafAttrDescriptor, ILeafAttrDescriptorFn } from '@leafer/interface'
2
2
  import { defineKey, getDescriptor } from './object'
3
3
  import { Debug } from '@leafer/debug'
4
4
 
5
5
 
6
6
  // name
7
7
 
8
- export function defineLeafAttr(target: ILeaf, key: string, defaultValue?: IValue, mergeDescriptor?: IObject & ThisType<ILeaf>): void {
9
- const defaultDescriptor: IObject & ThisType<ILeaf> = {
8
+ export function decorateLeafAttr(defaultValue?: IValue, descriptorFn?: ILeafAttrDescriptorFn) {
9
+ return (target: ILeaf, key: string) => defineLeafAttr(target, key, defaultValue, descriptorFn && descriptorFn(key))
10
+ }
11
+
12
+ export function attr(partDescriptor?: ILeafAttrDescriptor): ILeafAttrDescriptor {
13
+ return partDescriptor
14
+ }
15
+
16
+
17
+ export function defineLeafAttr(target: ILeaf, key: string, defaultValue?: IValue, partDescriptor?: ILeafAttrDescriptor): void {
18
+ const defaultDescriptor: ILeafAttrDescriptor = {
10
19
  get() { return this.__getAttr(key) },
11
20
  set(value: IValue) { this.__setAttr(key, value) },
12
21
  configurable: true,
13
22
  enumerable: true
14
23
  }
15
- defineKey(target, key, Object.assign(defaultDescriptor, mergeDescriptor || {}))
24
+ defineKey(target, key, Object.assign(defaultDescriptor, partDescriptor || {}))
16
25
  defineDataProcessor(target, key, defaultValue)
17
26
  }
18
27
 
28
+
19
29
  export function dataType(defaultValue?: IValue) {
20
- return (target: ILeaf, key: string) => {
21
- defineLeafAttr(target, key, defaultValue)
22
- }
30
+ return decorateLeafAttr(defaultValue)
23
31
  }
24
32
 
25
- export function positionType(defaultValue?: IValue) {
26
- return (target: ILeaf, key: string) => {
27
- defineLeafAttr(target, key, defaultValue, {
28
- set(value: IValue) {
29
- this.__setAttr(key, value)
30
- this.__layout.matrixChanged || this.__layout.matrixChange()
31
- }
32
- })
33
- }
33
+ export function positionType(defaultValue?: IValue, checkFiniteNumber?: boolean) {
34
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
35
+ set(value: IValue) {
36
+ this.__setAttr(key, value, checkFiniteNumber)
37
+ this.__layout.matrixChanged || this.__layout.matrixChange()
38
+ }
39
+ }))
34
40
  }
35
41
 
36
42
  export function autoLayoutType(defaultValue?: IValue) {
37
- return (target: ILeaf, key: string) => {
38
- defineLeafAttr(target, key, defaultValue, {
39
- set(value: IValue) {
40
- this.__setAttr(key, value)
41
- this.__layout.matrixChanged || this.__layout.matrixChange()
42
- this.__hasAutoLayout = !!value
43
- if (!this.__local) this.__layout.createLocal()
44
- }
45
- })
46
- }
43
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
44
+ set(value: IValue) {
45
+ this.__setAttr(key, value)
46
+ this.__layout.matrixChanged || this.__layout.matrixChange()
47
+ this.__hasAutoLayout = !!value
48
+ if (!this.__local) this.__layout.createLocal()
49
+ }
50
+ }))
47
51
  }
48
52
 
49
- export function scaleType(defaultValue?: IValue) {
50
- return (target: ILeaf, key: string) => {
51
- defineLeafAttr(target, key, defaultValue, {
52
- set(value: IValue) {
53
- this.__setAttr(key, value)
54
- this.__layout.scaleChanged || this.__layout.scaleChange()
55
- }
56
- })
57
- }
53
+ export function scaleType(defaultValue?: IValue, checkFiniteNumber?: boolean) {
54
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
55
+ set(value: IValue) {
56
+ this.__setAttr(key, value, checkFiniteNumber)
57
+ this.__layout.scaleChanged || this.__layout.scaleChange()
58
+ }
59
+ }))
58
60
  }
59
61
 
62
+ export function rotationType(defaultValue?: IValue, checkFiniteNumber?: boolean) {
63
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
64
+ set(value: IValue) {
65
+ this.__setAttr(key, value, checkFiniteNumber)
66
+ this.__layout.rotationChanged || this.__layout.rotationChange()
67
+ }
60
68
 
61
- export function rotationType(defaultValue?: IValue) {
62
- return (target: ILeaf, key: string) => {
63
- defineLeafAttr(target, key, defaultValue, {
64
- set(value: IValue) {
65
- this.__setAttr(key, value)
66
- this.__layout.rotationChanged || this.__layout.rotationChange()
67
-
68
- }
69
- })
70
- }
69
+ }))
71
70
  }
72
71
 
73
- export function boundsType(defaultValue?: IValue) {
74
- return (target: ILeaf, key: string) => {
75
- defineLeafAttr(target, key, defaultValue, {
76
- set(value: IValue) {
77
- this.__setAttr(key, value)
78
- doBoundsType(this)
79
- }
80
- })
81
- }
72
+ export function boundsType(defaultValue?: IValue, checkFiniteNumber?: boolean) {
73
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
74
+ set(value: IValue) {
75
+ this.__setAttr(key, value, checkFiniteNumber) && doBoundsType(this)
76
+ }
77
+ }))
82
78
  }
83
79
 
84
80
  export function naturalBoundsType(defaultValue?: IValue) {
85
- return (target: ILeaf, key: string) => {
86
- defineLeafAttr(target, key, defaultValue, {
87
- set(value: IValue) {
88
- this.__setAttr(key, value)
89
- doBoundsType(this)
90
- this.__.__removeNaturalSize()
91
- }
92
- })
93
- }
81
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
82
+ set(value: IValue) {
83
+ this.__setAttr(key, value)
84
+ doBoundsType(this)
85
+ this.__.__removeNaturalSize()
86
+ }
87
+ }))
94
88
  }
95
89
 
96
90
  export function doBoundsType(leaf: ILeaf): void {
@@ -99,29 +93,24 @@ export function doBoundsType(leaf: ILeaf): void {
99
93
  }
100
94
 
101
95
  export function pathInputType(defaultValue?: IValue) {
102
- return (target: ILeaf, key: string) => {
103
- defineLeafAttr(target, key, defaultValue, {
104
- set(value: IValue) {
105
- if (this.__.__pathInputed !== 2) this.__.__pathInputed = value ? 1 : 0
106
- this.__setAttr(key, value)
107
- doBoundsType(this)
108
- }
109
- })
110
- }
96
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
97
+ set(value: IValue) {
98
+ if (this.__.__pathInputed !== 2) this.__.__pathInputed = value ? 1 : 0
99
+ this.__setAttr(key, value)
100
+ doBoundsType(this)
101
+ }
102
+ }))
111
103
  }
112
104
 
113
105
  export const pathType = boundsType
114
106
 
115
107
 
116
108
  export function affectStrokeBoundsType(defaultValue?: IValue) {
117
- return (target: ILeaf, key: string) => {
118
- defineLeafAttr(target, key, defaultValue, {
119
- set(value: IValue) {
120
- this.__setAttr(key, value)
121
- doStrokeType(this)
122
- }
123
- })
124
- }
109
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
110
+ set(value: IValue) {
111
+ this.__setAttr(key, value) && doStrokeType(this)
112
+ }
113
+ }))
125
114
  }
126
115
 
127
116
  export function doStrokeType(leaf: ILeaf): void {
@@ -132,94 +121,78 @@ export function doStrokeType(leaf: ILeaf): void {
132
121
  export const strokeType = affectStrokeBoundsType
133
122
 
134
123
  export function affectRenderBoundsType(defaultValue?: IValue) {
135
- return (target: ILeaf, key: string) => {
136
- defineLeafAttr(target, key, defaultValue, {
137
- set(value: IValue) {
138
- this.__setAttr(key, value)
139
- this.__layout.renderChanged || this.__layout.renderChange()
140
- }
141
- })
142
- }
124
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
125
+ set(value: IValue) {
126
+ this.__setAttr(key, value)
127
+ this.__layout.renderChanged || this.__layout.renderChange()
128
+ }
129
+ }))
143
130
  }
144
131
 
145
132
  export function surfaceType(defaultValue?: IValue) {
146
- return (target: ILeaf, key: string) => {
147
- defineLeafAttr(target, key, defaultValue, {
148
- set(value: IValue) {
149
- this.__setAttr(key, value)
150
- this.__layout.surfaceChanged || this.__layout.surfaceChange()
151
- }
152
- })
153
- }
133
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
134
+ set(value: IValue) {
135
+ this.__setAttr(key, value)
136
+ this.__layout.surfaceChanged || this.__layout.surfaceChange()
137
+ }
138
+ }))
154
139
  }
155
140
 
156
141
  export function opacityType(defaultValue?: IValue) {
157
- return (target: ILeaf, key: string) => {
158
- defineLeafAttr(target, key, defaultValue, {
159
- set(value: IValue) {
160
- this.__setAttr(key, value)
161
- this.__layout.opacityChanged || this.__layout.opacityChange()
162
- }
163
- })
164
- }
142
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
143
+ set(value: IValue) {
144
+ this.__setAttr(key, value)
145
+ this.__layout.opacityChanged || this.__layout.opacityChange()
146
+ }
147
+ }))
165
148
  }
166
149
 
167
150
  export function sortType(defaultValue?: IValue) {
168
- return (target: ILeaf, key: string) => {
169
- defineLeafAttr(target, key, defaultValue, {
170
- set(value: IValue) {
171
- this.__setAttr(key, value)
172
- this.__layout.surfaceChanged || this.__layout.surfaceChange()
173
- this.waitParent(() => { this.parent.__layout.childrenSortChange() })
174
- }
175
- })
176
- }
151
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
152
+ set(value: IValue) {
153
+ this.__setAttr(key, value)
154
+ this.__layout.surfaceChanged || this.__layout.surfaceChange()
155
+ this.waitParent(() => { this.parent.__layout.childrenSortChange() })
156
+ }
157
+ }))
177
158
  }
178
159
 
179
160
  export function maskType(defaultValue?: IValue) {
180
- return (target: ILeaf, key: string) => {
181
- defineLeafAttr(target, key, defaultValue, {
182
- set(value: boolean) {
183
- this.__setAttr(key, value)
184
- this.__layout.boxChanged || this.__layout.boxChange()
185
- this.waitParent(() => { this.parent.__updateMask(value) })
186
- }
187
- })
188
- }
161
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
162
+ set(value: boolean) {
163
+ this.__setAttr(key, value)
164
+ this.__layout.boxChanged || this.__layout.boxChange()
165
+ this.waitParent(() => { this.parent.__updateMask(value) })
166
+ }
167
+ }))
189
168
  }
190
169
 
191
170
  export function eraserType(defaultValue?: IValue) {
192
- return (target: ILeaf, key: string) => {
193
- defineLeafAttr(target, key, defaultValue, {
194
- set(value: boolean) {
195
- this.__setAttr(key, value)
196
- this.waitParent(() => { this.parent.__updateEraser(value) })
197
- }
198
- })
199
- }
171
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
172
+ set(value: boolean) {
173
+ this.__setAttr(key, value)
174
+ this.waitParent(() => { this.parent.__updateEraser(value) })
175
+ }
176
+ }))
200
177
  }
201
178
 
202
179
  export function hitType(defaultValue?: IValue) {
203
- return (target: ILeaf, key: string) => {
204
- defineLeafAttr(target, key, defaultValue, {
205
- set(value: IValue) {
206
- this.__setAttr(key, value)
207
- if (Debug.showHitView) { this.__layout.surfaceChanged || this.__layout.surfaceChange() }
208
- if (this.leafer) this.leafer.updateCursor()
209
- }
210
- })
211
- }
180
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
181
+ set(value: IValue) {
182
+ this.__setAttr(key, value)
183
+ if (Debug.showHitView) { this.__layout.surfaceChanged || this.__layout.surfaceChange() }
184
+ if (this.leafer) this.leafer.updateCursor()
185
+ }
186
+ }))
212
187
  }
213
188
 
214
189
  export function cursorType(defaultValue?: IValue) {
215
- return (target: ILeaf, key: string) => {
216
- defineLeafAttr(target, key, defaultValue, {
217
- set(value: IValue) {
218
- this.__setAttr(key, value)
219
- if (this.leafer) this.leafer.updateCursor()
220
- }
221
- })
222
- }
190
+ return decorateLeafAttr(defaultValue, (key: string) => attr({
191
+ set(value: IValue) {
192
+ this.__setAttr(key, value)
193
+ if (this.leafer) this.leafer.updateCursor()
194
+ }
195
+ }))
223
196
  }
224
197
 
225
198
 
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { defineLeafAttr, dataType, positionType, autoLayoutType, boundsType, doBoundsType, naturalBoundsType, affectStrokeBoundsType, doStrokeType, strokeType, affectRenderBoundsType, scaleType, rotationType, surfaceType, opacityType, sortType, maskType, eraserType, hitType, pathType, pathInputType, cursorType, dataProcessor, layoutProcessor, defineDataProcessor } from './data'
1
+ export { defineLeafAttr, decorateLeafAttr, attr, dataType, positionType, autoLayoutType, boundsType, doBoundsType, naturalBoundsType, affectStrokeBoundsType, doStrokeType, strokeType, affectRenderBoundsType, scaleType, rotationType, surfaceType, opacityType, sortType, maskType, eraserType, hitType, pathType, pathInputType, cursorType, dataProcessor, layoutProcessor, defineDataProcessor } from './data'
2
2
  export { useModule, rewrite, rewriteAble } from './rewrite'
3
3
  export { defineKey, getDescriptor } from './object'
4
4
  export { registerUI, registerUIEvent } from './class'
package/types/index.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { ILeaf, IValue, IObject, IFunction } from '@leafer/interface';
1
+ import { IValue, ILeafAttrDescriptorFn, ILeaf, ILeafAttrDescriptor, IObject, IFunction } from '@leafer/interface';
2
2
 
3
- declare function defineLeafAttr(target: ILeaf, key: string, defaultValue?: IValue, mergeDescriptor?: IObject & ThisType<ILeaf>): void;
3
+ declare function decorateLeafAttr(defaultValue?: IValue, descriptorFn?: ILeafAttrDescriptorFn): (target: ILeaf, key: string) => void;
4
+ declare function attr(partDescriptor?: ILeafAttrDescriptor): ILeafAttrDescriptor;
5
+ declare function defineLeafAttr(target: ILeaf, key: string, defaultValue?: IValue, partDescriptor?: ILeafAttrDescriptor): void;
4
6
  declare function dataType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
5
- declare function positionType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
7
+ declare function positionType(defaultValue?: IValue, checkFiniteNumber?: boolean): (target: ILeaf, key: string) => void;
6
8
  declare function autoLayoutType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
7
- declare function scaleType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
8
- declare function rotationType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
9
- declare function boundsType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
9
+ declare function scaleType(defaultValue?: IValue, checkFiniteNumber?: boolean): (target: ILeaf, key: string) => void;
10
+ declare function rotationType(defaultValue?: IValue, checkFiniteNumber?: boolean): (target: ILeaf, key: string) => void;
11
+ declare function boundsType(defaultValue?: IValue, checkFiniteNumber?: boolean): (target: ILeaf, key: string) => void;
10
12
  declare function naturalBoundsType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
11
13
  declare function doBoundsType(leaf: ILeaf): void;
12
14
  declare function pathInputType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
@@ -36,4 +38,4 @@ declare function getDescriptor(object: IObject, name: string): PropertyDescripto
36
38
  declare function registerUI(): (target: IObject) => void;
37
39
  declare function registerUIEvent(): (target: IObject) => void;
38
40
 
39
- export { affectRenderBoundsType, affectStrokeBoundsType, autoLayoutType, boundsType, cursorType, dataProcessor, dataType, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, eraserType, getDescriptor, hitType, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, useModule };
41
+ export { affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, eraserType, getDescriptor, hitType, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, useModule };