@leafer/decorator 1.0.0-rc.22 → 1.0.0-rc.24
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 +4 -4
- package/src/data.ts +55 -38
- package/src/index.ts +1 -1
- package/src/object.ts +2 -1
- package/types/index.d.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/decorator",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.24",
|
|
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.
|
|
26
|
-
"@leafer/debug": "1.0.0-rc.
|
|
25
|
+
"@leafer/platform": "1.0.0-rc.24",
|
|
26
|
+
"@leafer/debug": "1.0.0-rc.24"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.0.0-rc.
|
|
29
|
+
"@leafer/interface": "1.0.0-rc.24"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/data.ts
CHANGED
|
@@ -17,9 +17,7 @@ export function attr(partDescriptor?: ILeafAttrDescriptor): ILeafAttrDescriptor
|
|
|
17
17
|
export function defineLeafAttr(target: ILeaf, key: string, defaultValue?: IValue, partDescriptor?: ILeafAttrDescriptor): void {
|
|
18
18
|
const defaultDescriptor: ILeafAttrDescriptor = {
|
|
19
19
|
get() { return this.__getAttr(key) },
|
|
20
|
-
set(value: IValue) { this.__setAttr(key, value) }
|
|
21
|
-
configurable: true,
|
|
22
|
-
enumerable: true
|
|
20
|
+
set(value: IValue) { this.__setAttr(key, value) }
|
|
23
21
|
}
|
|
24
22
|
defineKey(target, key, Object.assign(defaultDescriptor, partDescriptor || {}))
|
|
25
23
|
defineDataProcessor(target, key, defaultValue)
|
|
@@ -33,8 +31,7 @@ export function dataType(defaultValue?: IValue) {
|
|
|
33
31
|
export function positionType(defaultValue?: IValue, checkFiniteNumber?: boolean) {
|
|
34
32
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
35
33
|
set(value: IValue) {
|
|
36
|
-
this.__setAttr(key, value, checkFiniteNumber)
|
|
37
|
-
this.__layout.matrixChanged || this.__layout.matrixChange()
|
|
34
|
+
this.__setAttr(key, value, checkFiniteNumber) && (this.__layout.matrixChanged || this.__layout.matrixChange())
|
|
38
35
|
}
|
|
39
36
|
}))
|
|
40
37
|
}
|
|
@@ -42,10 +39,11 @@ export function positionType(defaultValue?: IValue, checkFiniteNumber?: boolean)
|
|
|
42
39
|
export function autoLayoutType(defaultValue?: IValue) {
|
|
43
40
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
44
41
|
set(value: IValue) {
|
|
45
|
-
this.__setAttr(key, value)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
if (this.__setAttr(key, value)) {
|
|
43
|
+
this.__layout.matrixChanged || this.__layout.matrixChange()
|
|
44
|
+
this.__hasAutoLayout = !!value
|
|
45
|
+
if (!this.__local) this.__layout.createLocal()
|
|
46
|
+
}
|
|
49
47
|
}
|
|
50
48
|
}))
|
|
51
49
|
}
|
|
@@ -53,8 +51,8 @@ export function autoLayoutType(defaultValue?: IValue) {
|
|
|
53
51
|
export function scaleType(defaultValue?: IValue, checkFiniteNumber?: boolean) {
|
|
54
52
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
55
53
|
set(value: IValue) {
|
|
56
|
-
this.__setAttr(key, value, checkFiniteNumber)
|
|
57
|
-
|
|
54
|
+
this.__setAttr(key, value, checkFiniteNumber) && (this.__layout.scaleChanged || this.__layout.scaleChange())
|
|
55
|
+
|
|
58
56
|
}
|
|
59
57
|
}))
|
|
60
58
|
}
|
|
@@ -62,8 +60,7 @@ export function scaleType(defaultValue?: IValue, checkFiniteNumber?: boolean) {
|
|
|
62
60
|
export function rotationType(defaultValue?: IValue, checkFiniteNumber?: boolean) {
|
|
63
61
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
64
62
|
set(value: IValue) {
|
|
65
|
-
this.__setAttr(key, value, checkFiniteNumber)
|
|
66
|
-
this.__layout.rotationChanged || this.__layout.rotationChange()
|
|
63
|
+
this.__setAttr(key, value, checkFiniteNumber) && (this.__layout.rotationChanged || this.__layout.rotationChange())
|
|
67
64
|
}
|
|
68
65
|
|
|
69
66
|
}))
|
|
@@ -80,9 +77,7 @@ export function boundsType(defaultValue?: IValue, checkFiniteNumber?: boolean) {
|
|
|
80
77
|
export function naturalBoundsType(defaultValue?: IValue) {
|
|
81
78
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
82
79
|
set(value: IValue) {
|
|
83
|
-
this.__setAttr(key, value)
|
|
84
|
-
doBoundsType(this)
|
|
85
|
-
this.__.__removeNaturalSize()
|
|
80
|
+
this.__setAttr(key, value) && (doBoundsType(this), this.__.__removeNaturalSize())
|
|
86
81
|
}
|
|
87
82
|
}))
|
|
88
83
|
}
|
|
@@ -95,7 +90,9 @@ export function doBoundsType(leaf: ILeaf): void {
|
|
|
95
90
|
export function pathInputType(defaultValue?: IValue) {
|
|
96
91
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
97
92
|
set(value: IValue) {
|
|
98
|
-
|
|
93
|
+
const data = this.__
|
|
94
|
+
if (data.__pathInputed !== 2) data.__pathInputed = value ? 1 : 0
|
|
95
|
+
if (!value) data.__pathForRender = undefined
|
|
99
96
|
this.__setAttr(key, value)
|
|
100
97
|
doBoundsType(this)
|
|
101
98
|
}
|
|
@@ -132,8 +129,7 @@ export function affectRenderBoundsType(defaultValue?: IValue) {
|
|
|
132
129
|
export function surfaceType(defaultValue?: IValue) {
|
|
133
130
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
134
131
|
set(value: IValue) {
|
|
135
|
-
this.__setAttr(key, value)
|
|
136
|
-
this.__layout.surfaceChanged || this.__layout.surfaceChange()
|
|
132
|
+
this.__setAttr(key, value) && (this.__layout.surfaceChanged || this.__layout.surfaceChange())
|
|
137
133
|
}
|
|
138
134
|
}))
|
|
139
135
|
}
|
|
@@ -141,8 +137,19 @@ export function surfaceType(defaultValue?: IValue) {
|
|
|
141
137
|
export function opacityType(defaultValue?: IValue) {
|
|
142
138
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
143
139
|
set(value: IValue) {
|
|
144
|
-
this.__setAttr(key, value)
|
|
145
|
-
|
|
140
|
+
this.__setAttr(key, value) && (this.__layout.opacityChanged || this.__layout.opacityChange())
|
|
141
|
+
}
|
|
142
|
+
}))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function visibleType(defaultValue?: IValue) {
|
|
146
|
+
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
147
|
+
set(value: IValue) {
|
|
148
|
+
const oldValue = this.visible
|
|
149
|
+
if (this.__setAttr(key, value)) {
|
|
150
|
+
this.__layout.opacityChanged || this.__layout.opacityChange()
|
|
151
|
+
if (oldValue === 0 || value === 0) doBoundsType(this) // 0 = display: none
|
|
152
|
+
}
|
|
146
153
|
}
|
|
147
154
|
}))
|
|
148
155
|
}
|
|
@@ -150,9 +157,10 @@ export function opacityType(defaultValue?: IValue) {
|
|
|
150
157
|
export function sortType(defaultValue?: IValue) {
|
|
151
158
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
152
159
|
set(value: IValue) {
|
|
153
|
-
this.__setAttr(key, value)
|
|
154
|
-
|
|
155
|
-
|
|
160
|
+
if (this.__setAttr(key, value)) {
|
|
161
|
+
this.__layout.surfaceChanged || this.__layout.surfaceChange()
|
|
162
|
+
this.waitParent(() => { this.parent.__layout.childrenSortChange() })
|
|
163
|
+
}
|
|
156
164
|
}
|
|
157
165
|
}))
|
|
158
166
|
}
|
|
@@ -160,9 +168,10 @@ export function sortType(defaultValue?: IValue) {
|
|
|
160
168
|
export function maskType(defaultValue?: IValue) {
|
|
161
169
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
162
170
|
set(value: boolean) {
|
|
163
|
-
this.__setAttr(key, value)
|
|
164
|
-
|
|
165
|
-
|
|
171
|
+
if (this.__setAttr(key, value)) {
|
|
172
|
+
this.__layout.boxChanged || this.__layout.boxChange()
|
|
173
|
+
this.waitParent(() => { this.parent.__updateMask(value) })
|
|
174
|
+
}
|
|
166
175
|
}
|
|
167
176
|
}))
|
|
168
177
|
}
|
|
@@ -170,8 +179,7 @@ export function maskType(defaultValue?: IValue) {
|
|
|
170
179
|
export function eraserType(defaultValue?: IValue) {
|
|
171
180
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
172
181
|
set(value: boolean) {
|
|
173
|
-
this.__setAttr(key, value)
|
|
174
|
-
this.waitParent(() => { this.parent.__updateEraser(value) })
|
|
182
|
+
this.__setAttr(key, value) && this.waitParent(() => { this.parent.__updateEraser(value) })
|
|
175
183
|
}
|
|
176
184
|
}))
|
|
177
185
|
}
|
|
@@ -179,9 +187,10 @@ export function eraserType(defaultValue?: IValue) {
|
|
|
179
187
|
export function hitType(defaultValue?: IValue) {
|
|
180
188
|
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
181
189
|
set(value: IValue) {
|
|
182
|
-
this.__setAttr(key, value)
|
|
183
|
-
|
|
184
|
-
|
|
190
|
+
if (this.__setAttr(key, value)) {
|
|
191
|
+
if (Debug.showHitView) { this.__layout.surfaceChanged || this.__layout.surfaceChange() }
|
|
192
|
+
if (this.leafer) this.leafer.updateCursor()
|
|
193
|
+
}
|
|
185
194
|
}
|
|
186
195
|
}))
|
|
187
196
|
}
|
|
@@ -236,9 +245,7 @@ export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: I
|
|
|
236
245
|
},
|
|
237
246
|
set(value: IValue) {
|
|
238
247
|
(this as IObject)[computedKey] = value
|
|
239
|
-
}
|
|
240
|
-
configurable: true,
|
|
241
|
-
enumerable: true
|
|
248
|
+
}
|
|
242
249
|
}
|
|
243
250
|
|
|
244
251
|
if (defaultValue === undefined) {
|
|
@@ -246,12 +253,22 @@ export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: I
|
|
|
246
253
|
} else if (key === 'width') {
|
|
247
254
|
property.get = function () {
|
|
248
255
|
const v = this[computedKey]
|
|
249
|
-
|
|
256
|
+
if (v === undefined) {
|
|
257
|
+
const t = this as ILeafData
|
|
258
|
+
return (t as IObject)._height && t.__naturalWidth && t.__useNaturalRatio ? (t as IObject)._height * t.__naturalWidth / t.__naturalHeight : t.__naturalWidth || defaultValue
|
|
259
|
+
} else {
|
|
260
|
+
return v
|
|
261
|
+
}
|
|
250
262
|
}
|
|
251
263
|
} else if (key === 'height') {
|
|
252
264
|
property.get = function () {
|
|
253
265
|
const v = this[computedKey]
|
|
254
|
-
|
|
266
|
+
if (v === undefined) {
|
|
267
|
+
const t = this as ILeafData
|
|
268
|
+
return (t as IObject)._width && t.__naturalHeight && t.__useNaturalRatio ? (t as IObject)._width * t.__naturalHeight / t.__naturalWidth : t.__naturalHeight || defaultValue
|
|
269
|
+
} else {
|
|
270
|
+
return v
|
|
271
|
+
}
|
|
255
272
|
}
|
|
256
273
|
}
|
|
257
274
|
|
|
@@ -269,7 +286,7 @@ export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: I
|
|
|
269
286
|
delete data[setMethodName]
|
|
270
287
|
}
|
|
271
288
|
|
|
272
|
-
|
|
289
|
+
defineKey(data, key, property)
|
|
273
290
|
|
|
274
291
|
}
|
|
275
292
|
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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'
|
|
1
|
+
export { defineLeafAttr, decorateLeafAttr, attr, dataType, positionType, autoLayoutType, boundsType, doBoundsType, naturalBoundsType, affectStrokeBoundsType, doStrokeType, strokeType, affectRenderBoundsType, scaleType, rotationType, surfaceType, opacityType, visibleType, 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/src/object.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IObject } from '@leafer/interface'
|
|
2
2
|
|
|
3
|
-
export function defineKey<T>(target: T, key: string, descriptor: IObject & ThisType<T
|
|
3
|
+
export function defineKey<T>(target: T, key: string, descriptor: IObject & ThisType<T>, noConfigurable?: boolean): void {
|
|
4
|
+
if (!noConfigurable) descriptor.configurable = descriptor.enumerable = true
|
|
4
5
|
Object.defineProperty(target, key, descriptor)
|
|
5
6
|
}
|
|
6
7
|
|
package/types/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ declare const strokeType: typeof affectStrokeBoundsType;
|
|
|
19
19
|
declare function affectRenderBoundsType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
20
20
|
declare function surfaceType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
21
21
|
declare function opacityType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
22
|
+
declare function visibleType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
22
23
|
declare function sortType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
23
24
|
declare function maskType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
24
25
|
declare function eraserType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
|
|
@@ -32,10 +33,10 @@ declare function rewrite(method: IFunction): (target: IObject, key: string) => v
|
|
|
32
33
|
declare function rewriteAble(): (_target: IObject) => void;
|
|
33
34
|
declare function useModule(module: IObject, exclude?: string[]): (target: IObject) => void;
|
|
34
35
|
|
|
35
|
-
declare function defineKey<T>(target: T, key: string, descriptor: IObject & ThisType<T
|
|
36
|
+
declare function defineKey<T>(target: T, key: string, descriptor: IObject & ThisType<T>, noConfigurable?: boolean): void;
|
|
36
37
|
declare function getDescriptor(object: IObject, name: string): PropertyDescriptor;
|
|
37
38
|
|
|
38
39
|
declare function registerUI(): (target: IObject) => void;
|
|
39
40
|
declare function registerUIEvent(): (target: IObject) => void;
|
|
40
41
|
|
|
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 };
|
|
42
|
+
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, visibleType };
|