@leafer-ui/data 1.0.0-beta → 1.0.0-beta.10
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/UIData.ts +44 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/data",
|
|
3
|
-
"version": "1.0.0-beta",
|
|
3
|
+
"version": "1.0.0-beta.10",
|
|
4
4
|
"description": "@leafer-ui/data",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer/core": "1.0.0-beta"
|
|
22
|
+
"@leafer/core": "1.0.0-beta.10"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@leafer/interface": "1.0.0-beta",
|
|
26
|
-
"@leafer-ui/interface": "1.0.0-beta"
|
|
25
|
+
"@leafer/interface": "1.0.0-beta.10",
|
|
26
|
+
"@leafer-ui/interface": "1.0.0-beta.10"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/UIData.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LeafData } from '@leafer/core'
|
|
1
|
+
import { IBooleanMap, ILeaferImage, __Value } from '@leafer/interface'
|
|
2
|
+
import { ImageManager, LeafData } from '@leafer/core'
|
|
3
3
|
|
|
4
|
-
import { IShadowEffect, IUI, IUIData, IUnitData } from '@leafer-ui/interface'
|
|
5
|
-
import { Paint } from '@leafer-ui/external'
|
|
4
|
+
import { IShadowEffect, IUI, IUIData, IUnitData, ILeafPaint } from '@leafer-ui/interface'
|
|
6
5
|
|
|
7
6
|
|
|
7
|
+
const emptyPaint: ILeafPaint = {}
|
|
8
8
|
export class UIData extends LeafData implements IUIData {
|
|
9
9
|
|
|
10
10
|
public __leaf: IUI
|
|
11
11
|
|
|
12
12
|
public __blendLayer?: boolean
|
|
13
|
-
public _blendMode: string
|
|
14
13
|
|
|
15
14
|
public __isFills?: boolean
|
|
16
15
|
public __isStrokes?: boolean
|
|
@@ -21,36 +20,37 @@ export class UIData extends LeafData implements IUIData {
|
|
|
21
20
|
protected _shadow?: __Value
|
|
22
21
|
protected _innerShadow?: __Value
|
|
23
22
|
|
|
24
|
-
protected setBlendMode(value: IBlendMode) {
|
|
25
|
-
this._blendMode = value
|
|
26
|
-
if (value === 'pass-through' || !value) {
|
|
27
|
-
if (this.__blendLayer) this.__blendLayer = false
|
|
28
|
-
} else {
|
|
29
|
-
this.__blendLayer = true
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
23
|
|
|
33
24
|
protected setFill(value: __Value) {
|
|
25
|
+
if (this.__naturalWidth) this.__naturalWidth = this.__naturalHeight = undefined
|
|
34
26
|
if (typeof value === 'string' || !value) {
|
|
27
|
+
if (this.__isFills) {
|
|
28
|
+
this.__removeInput('fill')
|
|
29
|
+
this.__recycleImage('fill')
|
|
30
|
+
this.__isFills = false
|
|
31
|
+
}
|
|
35
32
|
this._fill = value
|
|
36
|
-
if (this.__input) this.__removeInput('fill')
|
|
37
|
-
this.__isFills && (this.__isFills = false)
|
|
38
33
|
} else if (typeof value === 'object') {
|
|
39
34
|
this.__setInput('fill', value)
|
|
40
|
-
this.__leaf.__layout.boxChanged
|
|
35
|
+
this.__leaf.__layout.boxChanged || this.__leaf.__layout.boxChange()
|
|
41
36
|
this.__isFills = true
|
|
37
|
+
this._fill || (this._fill = emptyPaint)
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
protected setStroke(value: __Value) {
|
|
46
42
|
if (typeof value === 'string' || !value) {
|
|
43
|
+
if (this.__isStrokes) {
|
|
44
|
+
this.__removeInput('stroke')
|
|
45
|
+
this.__recycleImage('stroke')
|
|
46
|
+
this.__isStrokes = false
|
|
47
|
+
}
|
|
47
48
|
this._stroke = value
|
|
48
|
-
if (this.__input) this.__removeInput('stroke')
|
|
49
|
-
this.__isStrokes && (this.__isStrokes = false)
|
|
50
49
|
} else if (typeof value === 'object') {
|
|
51
50
|
this.__setInput('stroke', value)
|
|
52
|
-
this.__leaf.__layout.boxChanged
|
|
51
|
+
this.__leaf.__layout.boxChanged || this.__leaf.__layout.boxChange()
|
|
53
52
|
this.__isStrokes = true
|
|
53
|
+
this._stroke || (this._stroke = emptyPaint)
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -78,6 +78,31 @@ export class UIData extends LeafData implements IUIData {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
public __recycleImage(attrName: string): IBooleanMap {
|
|
82
|
+
const paints = (attrName === 'fill' ? this._fill : this._stroke) as ILeafPaint[]
|
|
83
|
+
if (paints instanceof Array) {
|
|
84
|
+
let image: ILeaferImage, map: IBooleanMap
|
|
85
|
+
for (let i = 0, len = paints.length; i < len; i++) {
|
|
86
|
+
image = paints[i].image
|
|
87
|
+
if (image) {
|
|
88
|
+
const { url } = image
|
|
89
|
+
if (!map) map = {}
|
|
90
|
+
map[url] = true
|
|
91
|
+
ImageManager.recycle(image)
|
|
92
|
+
|
|
93
|
+
// stop load
|
|
94
|
+
if (image.loading) {
|
|
95
|
+
const p = this.__input && this.__input[attrName]
|
|
96
|
+
const hasSame = p && (p instanceof Array ? p.some(item => item.url === url) : p.url === url)
|
|
97
|
+
if (!hasSame) image.unload(paints[i].loadId)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return map
|
|
102
|
+
}
|
|
103
|
+
return null
|
|
104
|
+
}
|
|
105
|
+
|
|
81
106
|
}
|
|
82
107
|
|
|
83
108
|
|