@leafer-ui/data 1.8.0 → 1.9.1

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.8.0",
3
+ "version": "1.9.1",
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.8.0",
26
- "@leafer-ui/external": "1.8.0"
25
+ "@leafer/core": "1.9.1",
26
+ "@leafer-ui/external": "1.9.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.8.0",
30
- "@leafer-ui/interface": "1.8.0"
29
+ "@leafer/interface": "1.9.1",
30
+ "@leafer-ui/interface": "1.9.1"
31
31
  }
32
32
  }
package/src/TextData.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UICreator } from '@leafer/core'
1
+ import { UICreator, isString } from '@leafer/core'
2
2
 
3
3
  import { IFontWeight, ITextData, IUI, IText, IObject, IBackgroundBoxStyle, IFontWeightNumer } from '@leafer-ui/interface'
4
4
 
@@ -25,7 +25,7 @@ export class TextData extends UIData implements ITextData {
25
25
  protected _boxStyle?: IBackgroundBoxStyle
26
26
 
27
27
  setFontWeight(value: IFontWeight): void {
28
- if (typeof value === 'string') {
28
+ if (isString(value)) {
29
29
  this.__setInput('fontWeight', value)
30
30
  value = fontWeightMap[value] as IFontWeightNumer || 400
31
31
  } else if (this.__input) this.__removeInput('fontWeight')
package/src/UIData.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { INumber, IValue, IBoolean, IPathCommandData, IPathString, IPointData, IPathCommandObject, IObject, IFilter } from '@leafer/interface'
2
- import { PathConvert, DataHelper, LeafData, Debug } from '@leafer/core'
2
+ import { PathConvert, DataHelper, LeafData, Debug, isArray, isObject, isString, isUndefined } from '@leafer/core'
3
3
 
4
4
  import { IUI, IUIData, ILeafPaint, IStrokeComputedStyle } from '@leafer-ui/interface'
5
5
  import { Paint, PaintImage, ColorConvert } from '@leafer-ui/external'
@@ -84,31 +84,31 @@ export class UIData extends LeafData implements IUIData {
84
84
 
85
85
  protected setFill(value: IValue) {
86
86
  if (this.__naturalWidth) this.__removeNaturalSize()
87
- if (typeof value === 'string' || !value) {
87
+ if (isString(value) || !value) {
88
88
  stintSet(this, '__isTransparentFill', hasTransparent(value as string))
89
89
  this.__isFills && this.__removePaint('fill', true)
90
90
  this._fill = value
91
- } else if (typeof value === 'object') {
91
+ } else if (isObject(value)) {
92
92
  this.__setPaint('fill', value)
93
93
  }
94
94
  }
95
95
 
96
96
  protected setStroke(value: IValue) {
97
- if (typeof value === 'string' || !value) {
97
+ if (isString(value) || !value) {
98
98
  stintSet(this, '__isTransparentStroke', hasTransparent(value as string))
99
99
  this.__isStrokes && this.__removePaint('stroke', true)
100
100
  this._stroke = value
101
- } else if (typeof value === 'object') {
101
+ } else if (isObject(value)) {
102
102
  this.__setPaint('stroke', value)
103
103
  }
104
104
  }
105
105
 
106
106
 
107
107
  protected setPath(value: IPathCommandData | IPathCommandObject[] | IPathString) {
108
- const isString = typeof value === 'string'
109
- if (isString || (value && typeof value[0] === 'object')) {
108
+ const isStr = isString(value)
109
+ if (isStr || (value && isObject(value[0]))) {
110
110
  this.__setInput('path', value)
111
- this._path = isString ? parse(value) : objectToCanvasData(value as IPathCommandObject[])
111
+ this._path = isStr ? parse(value) : objectToCanvasData(value as IPathCommandObject[])
112
112
  } else {
113
113
  if (this.__input) this.__removeInput('path')
114
114
  this._path = value as IPathCommandData
@@ -143,7 +143,7 @@ export class UIData extends LeafData implements IUIData {
143
143
  let { strokeWidth, strokeWidthFixed } = this as IUIData
144
144
  if (childStyle) {
145
145
  if (childStyle.strokeWidth) strokeWidth = childStyle.strokeWidth
146
- if (childStyle.strokeWidthFixed !== undefined) strokeWidthFixed = childStyle.strokeWidthFixed
146
+ if (!isUndefined(childStyle.strokeWidthFixed)) strokeWidthFixed = childStyle.strokeWidthFixed
147
147
  }
148
148
  if (strokeWidthFixed) {
149
149
  const scale = this.__leaf.getClampRenderScale()
@@ -156,7 +156,7 @@ export class UIData extends LeafData implements IUIData {
156
156
  this.__setInput(attrName, value)
157
157
  const layout = this.__leaf.__layout
158
158
  layout.boxChanged || layout.boxChange()
159
- if (value instanceof Array && !value.length) {
159
+ if (isArray(value) && !value.length) {
160
160
  this.__removePaint(attrName)
161
161
  } else {
162
162
  if (attrName === 'fill') this.__isFills = true, this._fill || (this._fill = emptyPaint)
@@ -181,7 +181,7 @@ export class UIData extends LeafData implements IUIData {
181
181
 
182
182
  function setArray(data: IUIData, key: string, value: IValue) {
183
183
  data.__setInput(key, value)
184
- if (value instanceof Array) {
184
+ if (isArray(value)) {
185
185
  if (value.some((item: IFilter) => item.visible === false)) value = value.filter((item: IFilter) => item.visible !== false)
186
186
  value.length || (value = undefined)
187
187
  } else value = value && (value as IFilter).visible !== false ? [value] : undefined;