@leafer-ui/data 1.6.1 → 1.6.3

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-ui/data",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "@leafer-ui/data",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.6.1",
26
- "@leafer-ui/external": "1.6.1"
25
+ "@leafer/core": "1.6.3",
26
+ "@leafer-ui/external": "1.6.3"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.6.1",
30
- "@leafer-ui/interface": "1.6.1"
29
+ "@leafer/interface": "1.6.3",
30
+ "@leafer-ui/interface": "1.6.3"
31
31
  }
32
32
  }
package/src/ImageData.ts CHANGED
@@ -15,7 +15,6 @@ export class ImageData extends RectData implements IImageData {
15
15
  }
16
16
 
17
17
  public __setImageFill(value: string): void {
18
- if (this.__leaf.image) this.__leaf.image = null;
19
18
  (this as IImageInputData).fill = value ? { type: 'image', mode: 'stretch', url: value } : undefined
20
19
  }
21
20
 
package/src/TextData.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { UICreator } from '@leafer/core'
2
2
 
3
- import { IFontWeight, ITextData, IUI, IText, IObject, IBackgroundBoxStyle } from '@leafer-ui/interface'
3
+ import { IFontWeight, ITextData, IUI, IText, IObject, IBackgroundBoxStyle, IFontWeightNumer } from '@leafer-ui/interface'
4
4
 
5
5
  import { UIData } from "./UIData"
6
6
 
@@ -27,11 +27,9 @@ export class TextData extends UIData implements ITextData {
27
27
  setFontWeight(value: IFontWeight): void {
28
28
  if (typeof value === 'string') {
29
29
  this.__setInput('fontWeight', value)
30
- this._fontWeight = fontWeightMap[value] || 400
31
- } else {
32
- if (this.__input) this.__removeInput('fontWeight')
33
- this._fontWeight = value
34
- }
30
+ value = fontWeightMap[value] as IFontWeightNumer || 400
31
+ } else if (this.__input) this.__removeInput('fontWeight')
32
+ this._fontWeight = value
35
33
  }
36
34
 
37
35
  setBoxStyle(value: IUI) {
package/src/UIData.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { INumber, IValue, IBoolean, IPathCommandData, IPathString, IPointData, IPathCommandObject, IObject, IFilter } from '@leafer/interface'
2
- import { PathConvert, LeafData, Debug } from '@leafer/core'
2
+ import { PathConvert, DataHelper, LeafData, Debug } from '@leafer/core'
3
3
 
4
4
  import { IUI, IUIData, ILeafPaint } from '@leafer-ui/interface'
5
- import { Paint, PaintImage } from '@leafer-ui/external'
5
+ import { Paint, PaintImage, ColorConvert } from '@leafer-ui/external'
6
6
 
7
7
 
8
8
  const { parse, objectToCanvasData } = PathConvert
9
+ const { stintSet } = DataHelper, { hasTransparent } = ColorConvert
9
10
  const emptyPaint: ILeafPaint = {}
10
11
  const debug = Debug.get('UIData')
11
12
  export class UIData extends LeafData implements IUIData {
@@ -37,8 +38,11 @@ export class UIData extends LeafData implements IUIData {
37
38
  return t.fill && this.__hasStroke
38
39
  }
39
40
 
40
- public __pixelFill?: boolean // png / svg / webp
41
- public __pixelStroke?: boolean
41
+ public __isAlphaPixelFill?: boolean // png / svg / webp
42
+ public __isAlphaPixelStroke?: boolean
43
+
44
+ public __isTransparentFill?: boolean // 半透明的
45
+ public __isTransparentStroke?: boolean
42
46
 
43
47
  public get __clipAfterFill(): boolean { const t = this as IUIData; return (t.cornerRadius || t.innerShadow || t.__pathInputed) as unknown as boolean } // 用于 __drawAfterFill()
44
48
  public get __hasSurface(): boolean { const t = this as IUIData; return (t.fill || t.stroke) as unknown as boolean }
@@ -91,37 +95,21 @@ export class UIData extends LeafData implements IUIData {
91
95
  protected setFill(value: IValue) {
92
96
  if (this.__naturalWidth) this.__removeNaturalSize()
93
97
  if (typeof value === 'string' || !value) {
94
- if (this.__isFills) {
95
- this.__removeInput('fill')
96
- PaintImage.recycleImage('fill', this)
97
- this.__isFills = false
98
- this.__pixelFill && (this.__pixelFill = false)
99
- }
98
+ stintSet(this, '__isTransparentFill', hasTransparent(value as string))
99
+ this.__isFills && this.__removePaint('fill', true)
100
100
  this._fill = value
101
101
  } else if (typeof value === 'object') {
102
- this.__setInput('fill', value)
103
- const layout = this.__leaf.__layout
104
- layout.boxChanged || layout.boxChange()
105
- this.__isFills = true
106
- this._fill || (this._fill = emptyPaint)
102
+ this.__setPaint('fill', value)
107
103
  }
108
104
  }
109
105
 
110
106
  protected setStroke(value: IValue) {
111
107
  if (typeof value === 'string' || !value) {
112
- if (this.__isStrokes) {
113
- this.__removeInput('stroke')
114
- PaintImage.recycleImage('stroke', this)
115
- this.__isStrokes = false
116
- this.__pixelStroke && (this.__pixelStroke = false)
117
- }
108
+ stintSet(this, '__isTransparentStroke', hasTransparent(value as string))
109
+ this.__isStrokes && this.__removePaint('stroke', true)
118
110
  this._stroke = value
119
111
  } else if (typeof value === 'object') {
120
- this.__setInput('stroke', value)
121
- const layout = this.__leaf.__layout
122
- layout.boxChanged || layout.boxChange()
123
- this.__isStrokes = true
124
- this._stroke || (this._stroke = emptyPaint)
112
+ this.__setPaint('stroke', value)
125
113
  }
126
114
  }
127
115
 
@@ -157,9 +145,32 @@ export class UIData extends LeafData implements IUIData {
157
145
  const { fill, stroke } = this.__input
158
146
  if (fill) Paint.compute('fill', this.__leaf)
159
147
  if (stroke) Paint.compute('stroke', this.__leaf)
160
- this.__needComputePaint = false
148
+ this.__needComputePaint = undefined
149
+ }
150
+
151
+ public __setPaint(attrName: 'fill' | 'stroke', value: IValue): void {
152
+ this.__setInput(attrName, value)
153
+ const layout = this.__leaf.__layout
154
+ layout.boxChanged || layout.boxChange()
155
+ if (value instanceof Array && !value.length) {
156
+ this.__removePaint(attrName)
157
+ } else {
158
+ if (attrName === 'fill') this.__isFills = true, this._fill || (this._fill = emptyPaint)
159
+ else this.__isStrokes = true, this._stroke || (this._stroke = emptyPaint)
160
+ }
161
161
  }
162
162
 
163
+ public __removePaint(attrName: 'fill' | 'stroke', removeInput?: boolean): void {
164
+ if (removeInput) this.__removeInput(attrName)
165
+ PaintImage.recycleImage(attrName, this)
166
+ if (attrName === 'fill') {
167
+ stintSet(this, '__isAlphaPixelFill', undefined)
168
+ this._fill = this.__isFills = undefined
169
+ } else {
170
+ stintSet(this, '__isAlphaPixelStroke', undefined)
171
+ this._stroke = this.__isStrokes = undefined
172
+ }
173
+ }
163
174
  }
164
175
 
165
176
 
@@ -167,7 +178,7 @@ function setArray(data: IUIData, key: string, value: IValue) {
167
178
  data.__setInput(key, value)
168
179
  if (value instanceof Array) {
169
180
  if (value.some((item: IFilter) => item.visible === false)) value = value.filter((item: IFilter) => item.visible !== false)
170
- value.length || (value = null)
171
- } else value = value && (value as IFilter).visible !== false ? [value] : null;
181
+ value.length || (value = undefined)
182
+ } else value = value && (value as IFilter).visible !== false ? [value] : undefined;
172
183
  (data as IObject)['_' + key] = value
173
184
  }
package/types/index.d.ts CHANGED
@@ -12,8 +12,10 @@ declare class UIData extends LeafData implements IUIData {
12
12
  get __hasStroke(): boolean;
13
13
  get __hasHalf(): number;
14
14
  get __hasMultiPaint(): boolean;
15
- __pixelFill?: boolean;
16
- __pixelStroke?: boolean;
15
+ __isAlphaPixelFill?: boolean;
16
+ __isAlphaPixelStroke?: boolean;
17
+ __isTransparentFill?: boolean;
18
+ __isTransparentStroke?: boolean;
17
19
  get __clipAfterFill(): boolean;
18
20
  get __hasSurface(): boolean;
19
21
  __needComputePaint: boolean;
@@ -39,6 +41,8 @@ declare class UIData extends LeafData implements IUIData {
39
41
  protected setInnerShadow(value: IValue): void;
40
42
  protected setFilter(value: IValue): void;
41
43
  __computePaint(): void;
44
+ __setPaint(attrName: 'fill' | 'stroke', value: IValue): void;
45
+ __removePaint(attrName: 'fill' | 'stroke', removeInput?: boolean): void;
42
46
  }
43
47
 
44
48
  declare class GroupData extends UIData implements IGroupData {