@leafer-ui/data 1.7.0 → 1.9.0

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.7.0",
3
+ "version": "1.9.0",
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.7.0",
26
- "@leafer-ui/external": "1.7.0"
25
+ "@leafer/core": "1.9.0",
26
+ "@leafer-ui/external": "1.9.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.7.0",
30
- "@leafer-ui/interface": "1.7.0"
29
+ "@leafer/interface": "1.9.0",
30
+ "@leafer-ui/interface": "1.9.0"
31
31
  }
32
32
  }
package/src/BoxData.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IBoxData } from '@leafer-ui/interface'
1
+ import { IBox, IBoxData } from '@leafer-ui/interface'
2
2
 
3
3
  import { GroupData } from "./GroupData"
4
4
 
@@ -7,9 +7,9 @@ export class BoxData extends GroupData implements IBoxData {
7
7
 
8
8
  public get __boxStroke(): boolean { return !(this as IBoxData).__pathInputed }
9
9
 
10
- // 路径与圆角直接当溢出处理
11
- public get __drawAfterFill(): boolean { const t = this as IBoxData; return (t.overflow === 'hide' && (t.__clipAfterFill || t.innerShadow) && t.__leaf.children.length) as unknown as boolean }
10
+ // 当成整体处理
11
+ public get __drawAfterFill(): boolean { const t = this as IBoxData; return t.__single || t.__clipAfterFill }
12
12
 
13
- public get __clipAfterFill(): boolean { return this.__leaf.isOverflow || super.__clipAfterFill }
13
+ public get __clipAfterFill(): boolean { const t = this as IBoxData; return t.overflow === 'hide' && t.__leaf.children.length && ((t.__leaf as IBox).isOverflow || super.__clipAfterFill) as unknown as boolean }
14
14
 
15
15
  }
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,7 +1,7 @@
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
- import { IUI, IUIData, ILeafPaint } from '@leafer-ui/interface'
4
+ import { IUI, IUIData, ILeafPaint, IStrokeComputedStyle } from '@leafer-ui/interface'
5
5
  import { Paint, PaintImage, ColorConvert } from '@leafer-ui/external'
6
6
 
7
7
 
@@ -20,20 +20,13 @@ export class UIData extends LeafData implements IUIData {
20
20
  public __isFills?: boolean
21
21
  public __isStrokes?: boolean
22
22
 
23
- public get __strokeWidth(): number {
24
- const { strokeWidth, strokeWidthFixed } = this as IUIData
25
- if (strokeWidthFixed) {
26
- const ui = this.__leaf
27
- let { scaleX } = ui.__nowWorld || ui.__world
28
- if (scaleX < 0) scaleX = -scaleX
29
- return scaleX > 1 ? strokeWidth / scaleX : strokeWidth
30
- } else return strokeWidth
31
- }
23
+ public get __strokeWidth(): number { return this.__getRealStrokeWidth() }
32
24
 
33
- public get __hasMultiPaint(): boolean { // fix: opacity
34
- const t = this as IUIData
35
- return (t.fill && this.__useStroke) || (t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect
36
- }
25
+ public get __maxStrokeWidth(): number { const t = this as IUIData; return t.__hasMultiStrokeStyle ? Math.max(t.__hasMultiStrokeStyle, t.strokeWidth) : t.strokeWidth }
26
+
27
+ public __hasMultiStrokeStyle?: number // 是否存在多个不同的描述样式(同时存储多个描边样式中的最大宽度用于运算)
28
+
29
+ public get __hasMultiPaint(): boolean { const t = this as IUIData; return (t.fill && this.__useStroke) || (t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect } // fix: opacity
37
30
 
38
31
  public __isAlphaPixelFill?: boolean // png / svg / webp
39
32
  public __isAlphaPixelStroke?: boolean
@@ -41,7 +34,7 @@ export class UIData extends LeafData implements IUIData {
41
34
  public __isTransparentFill?: boolean // 半透明的
42
35
  public __isTransparentStroke?: boolean
43
36
 
44
- public get __clipAfterFill(): boolean { const t = this as IUIData; return (t.cornerRadius || t.innerShadow || t.__pathInputed) as unknown as boolean } // 用于 __drawAfterFill()
37
+ public get __clipAfterFill(): boolean { const t = this as IUIData; return (t.cornerRadius || t.innerShadow || t.__pathInputed) as unknown as boolean } // 用于 (Box | Canvas | Robot) __drawAfterFill() 时裁剪内容
45
38
  public get __hasSurface(): boolean { const t = this as IUIData; return (t.fill || t.stroke) as unknown as boolean }
46
39
 
47
40
  public __needComputePaint: boolean
@@ -91,31 +84,31 @@ export class UIData extends LeafData implements IUIData {
91
84
 
92
85
  protected setFill(value: IValue) {
93
86
  if (this.__naturalWidth) this.__removeNaturalSize()
94
- if (typeof value === 'string' || !value) {
87
+ if (isString(value) || !value) {
95
88
  stintSet(this, '__isTransparentFill', hasTransparent(value as string))
96
89
  this.__isFills && this.__removePaint('fill', true)
97
90
  this._fill = value
98
- } else if (typeof value === 'object') {
91
+ } else if (isObject(value)) {
99
92
  this.__setPaint('fill', value)
100
93
  }
101
94
  }
102
95
 
103
96
  protected setStroke(value: IValue) {
104
- if (typeof value === 'string' || !value) {
97
+ if (isString(value) || !value) {
105
98
  stintSet(this, '__isTransparentStroke', hasTransparent(value as string))
106
99
  this.__isStrokes && this.__removePaint('stroke', true)
107
100
  this._stroke = value
108
- } else if (typeof value === 'object') {
101
+ } else if (isObject(value)) {
109
102
  this.__setPaint('stroke', value)
110
103
  }
111
104
  }
112
105
 
113
106
 
114
107
  protected setPath(value: IPathCommandData | IPathCommandObject[] | IPathString) {
115
- const isString = typeof value === 'string'
116
- if (isString || (value && typeof value[0] === 'object')) {
108
+ const isStr = isString(value)
109
+ if (isStr || (value && isObject(value[0]))) {
117
110
  this.__setInput('path', value)
118
- this._path = isString ? parse(value) : objectToCanvasData(value as IPathCommandObject[])
111
+ this._path = isStr ? parse(value) : objectToCanvasData(value as IPathCommandObject[])
119
112
  } else {
120
113
  if (this.__input) this.__removeInput('path')
121
114
  this._path = value as IPathCommandData
@@ -145,11 +138,25 @@ export class UIData extends LeafData implements IUIData {
145
138
  this.__needComputePaint = undefined
146
139
  }
147
140
 
141
+
142
+ public __getRealStrokeWidth(childStyle?: IStrokeComputedStyle): number {
143
+ let { strokeWidth, strokeWidthFixed } = this as IUIData
144
+ if (childStyle) {
145
+ if (childStyle.strokeWidth) strokeWidth = childStyle.strokeWidth
146
+ if (!isUndefined(childStyle.strokeWidthFixed)) strokeWidthFixed = childStyle.strokeWidthFixed
147
+ }
148
+ if (strokeWidthFixed) {
149
+ const scale = this.__leaf.getClampRenderScale()
150
+ return scale > 1 ? strokeWidth / scale : strokeWidth
151
+ } else return strokeWidth
152
+ }
153
+
154
+
148
155
  public __setPaint(attrName: 'fill' | 'stroke', value: IValue): void {
149
156
  this.__setInput(attrName, value)
150
157
  const layout = this.__leaf.__layout
151
158
  layout.boxChanged || layout.boxChange()
152
- if (value instanceof Array && !value.length) {
159
+ if (isArray(value) && !value.length) {
153
160
  this.__removePaint(attrName)
154
161
  } else {
155
162
  if (attrName === 'fill') this.__isFills = true, this._fill || (this._fill = emptyPaint)
@@ -165,6 +172,7 @@ export class UIData extends LeafData implements IUIData {
165
172
  this._fill = this.__isFills = undefined
166
173
  } else {
167
174
  stintSet(this, '__isAlphaPixelStroke', undefined)
175
+ stintSet(this, '__hasMultiStrokeStyle', undefined)
168
176
  this._stroke = this.__isStrokes = undefined
169
177
  }
170
178
  }
@@ -173,7 +181,7 @@ export class UIData extends LeafData implements IUIData {
173
181
 
174
182
  function setArray(data: IUIData, key: string, value: IValue) {
175
183
  data.__setInput(key, value)
176
- if (value instanceof Array) {
184
+ if (isArray(value)) {
177
185
  if (value.some((item: IFilter) => item.visible === false)) value = value.filter((item: IFilter) => item.visible !== false)
178
186
  value.length || (value = undefined)
179
187
  } else value = value && (value as IFilter).visible !== false ? [value] : undefined;
package/types/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { INumber, IPointData, IBoolean, IValue, IPathCommandData, IPathCommandObject, IPathString } from '@leafer/interface';
2
2
  import { LeafData } from '@leafer/core';
3
- import { IUIData, IUI, IGroupData, IBoxData, ILeaferData, IObject, IJSONOptions, IFrameData, ILineData, IRectData, IEllipseData, IPolygonData, IStarData, IPathData, IPenData, ITextData, IBackgroundBoxStyle, IFontWeight, IImageData, IImage, ICanvasData } from '@leafer-ui/interface';
3
+ import { IUIData, IUI, IStrokeComputedStyle, IGroupData, IBoxData, ILeaferData, IObject, IJSONOptions, IFrameData, ILineData, IRectData, IEllipseData, IPolygonData, IStarData, IPathData, IPenData, ITextData, IBackgroundBoxStyle, IFontWeight, IImageData, IImage, ICanvasData } from '@leafer-ui/interface';
4
4
 
5
5
  declare class UIData extends LeafData implements IUIData {
6
6
  __leaf: IUI;
@@ -9,6 +9,8 @@ declare class UIData extends LeafData implements IUIData {
9
9
  __isFills?: boolean;
10
10
  __isStrokes?: boolean;
11
11
  get __strokeWidth(): number;
12
+ get __maxStrokeWidth(): number;
13
+ __hasMultiStrokeStyle?: number;
12
14
  get __hasMultiPaint(): boolean;
13
15
  __isAlphaPixelFill?: boolean;
14
16
  __isAlphaPixelStroke?: boolean;
@@ -39,6 +41,7 @@ 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
+ __getRealStrokeWidth(childStyle?: IStrokeComputedStyle): number;
42
45
  __setPaint(attrName: 'fill' | 'stroke', value: IValue): void;
43
46
  __removePaint(attrName: 'fill' | 'stroke', removeInput?: boolean): void;
44
47
  }