@leafer-ui/data 1.5.2 → 1.6.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.5.2",
3
+ "version": "1.6.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.5.2",
26
- "@leafer-ui/external": "1.5.2"
25
+ "@leafer/core": "1.6.0",
26
+ "@leafer-ui/external": "1.6.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.5.2",
30
- "@leafer-ui/interface": "1.5.2"
29
+ "@leafer/interface": "1.6.0",
30
+ "@leafer-ui/interface": "1.6.0"
31
31
  }
32
32
  }
package/src/TextData.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { IFontWeight, ITextData } from '@leafer-ui/interface'
1
+ import { UICreator } from '@leafer/core'
2
+
3
+ import { IFontWeight, ITextData, IUI, IText, IObject, IBackgroundBoxStyle } from '@leafer-ui/interface'
2
4
 
3
5
  import { UIData } from "./UIData"
4
6
 
@@ -20,6 +22,7 @@ export class TextData extends UIData implements ITextData {
20
22
  public get __useNaturalRatio() { return false }
21
23
 
22
24
  protected _fontWeight?: number
25
+ protected _boxStyle?: IBackgroundBoxStyle
23
26
 
24
27
  setFontWeight(value: IFontWeight): void {
25
28
  if (typeof value === 'string') {
@@ -31,4 +34,30 @@ export class TextData extends UIData implements ITextData {
31
34
  }
32
35
  }
33
36
 
37
+ setBoxStyle(value: IUI) {
38
+ let t = this.__leaf as IText, box = t.__box
39
+
40
+ if (value) {
41
+
42
+ const { boxStyle } = this as ITextData
43
+ if (box) for (let key in boxStyle) (box as IObject)[key] = undefined
44
+ else box = t.__box = UICreator.get('Rect', 0 as any) as IUI // 传递 0 可以优化内存占用
45
+
46
+ const layout = t.__layout, boxLayout = box.__layout
47
+ if (!boxStyle) box.parent = t as any, box.__world = t.__world, boxLayout.boxBounds = layout.boxBounds
48
+
49
+ box.set(value)
50
+ if (boxLayout.strokeChanged) layout.strokeChange()
51
+ if (boxLayout.renderChanged) layout.renderChange()
52
+ box.__updateChange()
53
+
54
+ } else if (box) {
55
+ t.__box = box.parent = null
56
+ box.destroy()
57
+ }
58
+
59
+ this._boxStyle = value
60
+
61
+ }
62
+
34
63
  }
package/src/UIData.ts CHANGED
@@ -30,6 +30,7 @@ export class UIData extends LeafData implements IUIData {
30
30
  }
31
31
 
32
32
  public get __hasStroke(): boolean { return (this as IUIData).stroke && (this as IUIData).strokeWidth as unknown as boolean }
33
+ public get __hasHalf(): number { const t = this as IUIData; return (t.stroke && t.strokeAlign === 'center' && t.strokeWidth % 2) || undefined }
33
34
  public get __hasMultiPaint(): boolean { // fix: opacity
34
35
  const t = this as IUIData
35
36
  if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect) return true
@@ -94,12 +95,13 @@ export class UIData extends LeafData implements IUIData {
94
95
  this.__removeInput('fill')
95
96
  PaintImage.recycleImage('fill', this)
96
97
  this.__isFills = false
97
- if (this.__pixelFill) this.__pixelFill = false
98
+ this.__pixelFill && (this.__pixelFill = false)
98
99
  }
99
100
  this._fill = value
100
101
  } else if (typeof value === 'object') {
101
102
  this.__setInput('fill', value)
102
- this.__leaf.__layout.boxChanged || this.__leaf.__layout.boxChange()
103
+ const layout = this.__leaf.__layout
104
+ layout.boxChanged || layout.boxChange()
103
105
  this.__isFills = true
104
106
  this._fill || (this._fill = emptyPaint)
105
107
  }
@@ -111,12 +113,13 @@ export class UIData extends LeafData implements IUIData {
111
113
  this.__removeInput('stroke')
112
114
  PaintImage.recycleImage('stroke', this)
113
115
  this.__isStrokes = false
114
- if (this.__pixelStroke) this.__pixelStroke = false
116
+ this.__pixelStroke && (this.__pixelStroke = false)
115
117
  }
116
118
  this._stroke = value
117
119
  } else if (typeof value === 'object') {
118
120
  this.__setInput('stroke', value)
119
- this.__leaf.__layout.boxChanged || this.__leaf.__layout.boxChange()
121
+ const layout = this.__leaf.__layout
122
+ layout.boxChanged || layout.boxChange()
120
123
  this.__isStrokes = true
121
124
  this._stroke || (this._stroke = emptyPaint)
122
125
  }
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, IFontWeight, IImageData, IImage, ICanvasData } from '@leafer-ui/interface';
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';
4
4
 
5
5
  declare class UIData extends LeafData implements IUIData {
6
6
  __leaf: IUI;
@@ -10,6 +10,7 @@ declare class UIData extends LeafData implements IUIData {
10
10
  __isStrokes?: boolean;
11
11
  get __strokeWidth(): number;
12
12
  get __hasStroke(): boolean;
13
+ get __hasHalf(): number;
13
14
  get __hasMultiPaint(): boolean;
14
15
  __pixelFill?: boolean;
15
16
  __pixelStroke?: boolean;
@@ -83,7 +84,9 @@ declare class PenData extends GroupData implements IPenData {
83
84
  declare class TextData extends UIData implements ITextData {
84
85
  get __useNaturalRatio(): boolean;
85
86
  protected _fontWeight?: number;
87
+ protected _boxStyle?: IBackgroundBoxStyle;
86
88
  setFontWeight(value: IFontWeight): void;
89
+ setBoxStyle(value: IUI): void;
87
90
  }
88
91
 
89
92
  declare class ImageData extends RectData implements IImageData {