@leafer-ui/data 1.0.0-rc.3 → 1.0.0-rc.30

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.0.0-rc.3",
3
+ "version": "1.0.0-rc.30",
4
4
  "description": "@leafer-ui/data",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -15,18 +15,18 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/leaferjs/ui.git"
17
17
  },
18
- "homepage": "https://github.com/leaferjs/ui/tree/main/packages/data",
18
+ "homepage": "https://github.com/leaferjs/ui/tree/main/packages/display-module/data",
19
19
  "bugs": "https://github.com/leaferjs/ui/issues",
20
20
  "keywords": [
21
21
  "leafer-ui",
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.0.0-rc.3",
26
- "@leafer-ui/external": "1.0.0-rc.3"
25
+ "@leafer/core": "1.0.0-rc.30",
26
+ "@leafer-ui/external": "1.0.0-rc.30"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.0.0-rc.3",
30
- "@leafer-ui/interface": "1.0.0-rc.3"
29
+ "@leafer/interface": "1.0.0-rc.30",
30
+ "@leafer-ui/interface": "1.0.0-rc.30"
31
31
  }
32
32
  }
package/src/BoxData.ts CHANGED
@@ -4,5 +4,5 @@ import { GroupData } from "./GroupData"
4
4
 
5
5
 
6
6
  export class BoxData extends GroupData implements IBoxData {
7
- get __boxStroke(): boolean { return true }
7
+ get __boxStroke(): boolean { return !this.__pathInputed }
8
8
  }
@@ -4,5 +4,5 @@ import { UIData } from "./UIData"
4
4
 
5
5
 
6
6
  export class EllipseData extends UIData implements IEllipseData {
7
- get __boxStroke(): boolean { return true }
7
+ get __boxStroke(): boolean { return !this.__pathInputed }
8
8
  }
package/src/ImageData.ts CHANGED
@@ -1,8 +1,33 @@
1
- import { IImageData } from '@leafer-ui/interface'
1
+ import { IImageData, IImageInputData, IImage, IObject } from '@leafer-ui/interface'
2
2
 
3
3
  import { RectData } from './RectData'
4
4
 
5
5
 
6
6
  export class ImageData extends RectData implements IImageData {
7
7
 
8
+ declare public __leaf: IImage
9
+
10
+ protected _url: string
11
+
12
+ protected setUrl(value: string) {
13
+ this.__setImageFill(value)
14
+ this._url = value
15
+ }
16
+
17
+ public __setImageFill(value: string): void {
18
+ if (this.__leaf.image) this.__leaf.image = null;
19
+ (this as IImageInputData).fill = value ? { type: 'image', mode: 'strench', url: value } : undefined
20
+ }
21
+
22
+ public __getData(): IObject {
23
+ const data = super.__getData()
24
+ delete data.fill
25
+ return data
26
+ }
27
+
28
+ public __getInputData(): IObject {
29
+ const data = super.__getInputData()
30
+ delete data.fill
31
+ return data
32
+ }
8
33
  }
package/src/PathData.ts CHANGED
@@ -1,24 +1,8 @@
1
- import { IPathCommandData } from '@leafer/interface'
2
- import { PathConvert } from '@leafer/core'
1
+ import { IPathData } from '@leafer-ui/interface'
3
2
 
4
- import { IPathString } from '@leafer-ui/interface'
5
3
  import { UIData } from "./UIData"
6
4
 
7
5
 
8
- const { parse } = PathConvert
9
-
10
- export class PathData extends UIData {
11
-
12
- protected _path: IPathCommandData
13
-
14
- protected setPath(value: IPathCommandData | IPathString) {
15
- if (typeof value === 'string') {
16
- this.__setInput('path', value)
17
- this._path = parse(value)
18
- } else {
19
- if (this.__input) this.__removeInput('path')
20
- this._path = value
21
- }
22
- }
6
+ export class PathData extends UIData implements IPathData {
23
7
 
24
8
  }
package/src/RectData.ts CHANGED
@@ -4,5 +4,5 @@ import { UIData } from "./UIData"
4
4
 
5
5
 
6
6
  export class RectData extends UIData implements IRectData {
7
- get __boxStroke(): boolean { return true }
7
+ get __boxStroke(): boolean { return !this.__pathInputed }
8
8
  }
package/src/TextData.ts CHANGED
@@ -17,6 +17,8 @@ const fontWeightMap = {
17
17
 
18
18
  export class TextData extends UIData implements ITextData {
19
19
 
20
+ public get __useNaturalRatio() { return false }
21
+
20
22
  protected _fontWeight?: number
21
23
 
22
24
  setFontWeight(value: IFontWeight): void {
package/src/UIData.ts CHANGED
@@ -1,39 +1,63 @@
1
- import { __Number, __Value, __Boolean } from '@leafer/interface'
2
- import { LeafData, Debug } from '@leafer/core'
1
+ import { INumber, IValue, IBoolean, IPathCommandData, IPathString } from '@leafer/interface'
2
+ import { PathConvert, LeafData, Debug } from '@leafer/core'
3
3
 
4
4
  import { IShadowEffect, IUI, IUIData, IUnitData, ILeafPaint } from '@leafer-ui/interface'
5
- import { Paint } from '@leafer-ui/external'
5
+ import { Paint, PaintImage } from '@leafer-ui/external'
6
6
 
7
7
 
8
+ const { parse } = PathConvert
8
9
  const emptyPaint: ILeafPaint = {}
9
10
  const debug = Debug.get('UIData')
10
11
  export class UIData extends LeafData implements IUIData {
11
12
 
12
13
  declare public __leaf: IUI
13
14
 
14
- public __blendLayer?: boolean
15
+ public __blendLayer?: boolean // 非元素属性必须以两个下划线开头
15
16
 
16
17
  public __isFills?: boolean
17
18
  public __isStrokes?: boolean
18
19
 
19
- protected _visible?: __Boolean
20
+ public get __strokeWidth(): number {
21
+ const { strokeWidth, strokeWidthFixed } = this as IUIData
22
+ if (strokeWidthFixed) {
23
+ const ui = this.__leaf
24
+ let { scaleX } = ui.__nowWorld || ui.__world
25
+ if (scaleX < 0) scaleX = -scaleX
26
+ return scaleX > 1 ? strokeWidth / scaleX : strokeWidth
27
+ } else {
28
+ return strokeWidth
29
+ }
30
+ }
31
+
32
+ public __pixelFill?: boolean // png / svg / webp
33
+ public __pixelStroke?: boolean
20
34
 
21
- protected _width?: __Number
22
- protected _height?: __Number
35
+ public __needComputePaint: boolean
23
36
 
24
- protected _fill?: __Value
25
- protected _stroke?: __Value
37
+ protected _visible?: IBoolean
26
38
 
27
- protected _shadow?: __Value
28
- protected _innerShadow?: __Value
39
+ protected _width?: INumber
40
+ protected _height?: INumber
29
41
 
42
+ protected _fill?: IValue
43
+ protected _stroke?: IValue
30
44
 
31
- protected setVisible(value: __Boolean) {
45
+ protected _path: IPathCommandData
46
+
47
+ protected _shadow?: IValue
48
+ protected _innerShadow?: IValue
49
+
50
+ public get __autoWidth() { return !this._width }
51
+ public get __autoHeight() { return !this._height }
52
+ public get __autoSide() { return !this._width || !this._height }
53
+ public get __autoSize() { return !this._width && !this._height }
54
+
55
+ protected setVisible(value: IBoolean) {
32
56
  if (this.__leaf.leafer) this.__leaf.leafer.watcher.hasVisible = true
33
57
  this._visible = value
34
58
  }
35
59
 
36
- protected setWidth(value: __Number) {
60
+ protected setWidth(value: INumber) {
37
61
  if (value < 0) {
38
62
  this._width = -value
39
63
  this.__leaf.scaleX *= -1
@@ -43,7 +67,7 @@ export class UIData extends LeafData implements IUIData {
43
67
  }
44
68
  }
45
69
 
46
- protected setHeight(value: __Number) {
70
+ protected setHeight(value: INumber) {
47
71
  if (value < 0) {
48
72
  this._height = -value
49
73
  this.__leaf.scaleY *= -1
@@ -54,13 +78,14 @@ export class UIData extends LeafData implements IUIData {
54
78
  }
55
79
 
56
80
 
57
- protected setFill(value: __Value) {
58
- if (this.__naturalWidth) this.__naturalWidth = this.__naturalHeight = undefined
81
+ protected setFill(value: IValue) {
82
+ if (this.__naturalWidth) this.__removeNaturalSize()
59
83
  if (typeof value === 'string' || !value) {
60
84
  if (this.__isFills) {
61
85
  this.__removeInput('fill')
62
- Paint.recycleImage(this, 'fill')
86
+ PaintImage.recycleImage('fill', this)
63
87
  this.__isFills = false
88
+ if (this.__pixelFill) this.__pixelFill = false
64
89
  }
65
90
  this._fill = value
66
91
  } else if (typeof value === 'object') {
@@ -71,12 +96,13 @@ export class UIData extends LeafData implements IUIData {
71
96
  }
72
97
  }
73
98
 
74
- protected setStroke(value: __Value) {
99
+ protected setStroke(value: IValue) {
75
100
  if (typeof value === 'string' || !value) {
76
101
  if (this.__isStrokes) {
77
102
  this.__removeInput('stroke')
78
- Paint.recycleImage(this, 'stroke')
103
+ PaintImage.recycleImage('stroke', this)
79
104
  this.__isStrokes = false
105
+ if (this.__pixelStroke) this.__pixelStroke = false
80
106
  }
81
107
  this._stroke = value
82
108
  } else if (typeof value === 'object') {
@@ -88,7 +114,18 @@ export class UIData extends LeafData implements IUIData {
88
114
  }
89
115
 
90
116
 
91
- protected setShadow(value: __Value) {
117
+ protected setPath(value: IPathCommandData | IPathString) {
118
+ if (typeof value === 'string') {
119
+ this.__setInput('path', value)
120
+ this._path = parse(value)
121
+ } else {
122
+ if (this.__input) this.__removeInput('path')
123
+ this._path = value
124
+ }
125
+ }
126
+
127
+
128
+ protected setShadow(value: IValue) {
92
129
  this.__setInput('shadow', value)
93
130
  if (value instanceof Array) {
94
131
  if (value.some((item: IShadowEffect) => item.visible === false)) value = value.filter((item: IShadowEffect) => item.visible !== false)
@@ -100,7 +137,7 @@ export class UIData extends LeafData implements IUIData {
100
137
  }
101
138
  }
102
139
 
103
- protected setInnerShadow(value: __Value) {
140
+ protected setInnerShadow(value: IValue) {
104
141
  this.__setInput('innerShadow', value)
105
142
  if (value instanceof Array) {
106
143
  if (value.some((item: IShadowEffect) => item.visible === false)) value = value.filter((item: IShadowEffect) => item.visible !== false)
@@ -112,13 +149,22 @@ export class UIData extends LeafData implements IUIData {
112
149
  }
113
150
  }
114
151
 
152
+ // custom
153
+
154
+ public __computePaint(): void {
155
+ const { fill, stroke } = this.__input
156
+ if (fill) Paint.compute('fill', this.__leaf)
157
+ if (stroke) Paint.compute('stroke', this.__leaf)
158
+ this.__needComputePaint = false
159
+ }
160
+
115
161
  }
116
162
 
117
163
 
118
164
  export const UnitConvert = {
119
165
 
120
166
  number(value: number | IUnitData, percentRefer?: number): number {
121
- if (typeof value === 'object') return value.type === 'percent' ? value.value / 100 * percentRefer : value.value
167
+ if (typeof value === 'object') return value.type === 'percent' ? value.value * percentRefer : value.value
122
168
  return value
123
169
  }
124
170
 
package/types/index.d.ts CHANGED
@@ -1,26 +1,37 @@
1
- import { __Boolean, __Number, __Value, IPathCommandData } from '@leafer/interface';
1
+ import { IBoolean, INumber, IValue, IPathCommandData, IPathString } from '@leafer/interface';
2
2
  import { LeafData } from '@leafer/core';
3
- import { IUIData, IUI, IUnitData, IGroupData, IBoxData, ILeaferData, IFrameData, ILineData, IRectData, IEllipseData, IPolygonData, IStarData, IPathString, IPenData, ITextData, IFontWeight, IImageData, ICanvasData } from '@leafer-ui/interface';
3
+ import { IUIData, IUI, IUnitData, IGroupData, IBoxData, ILeaferData, IFrameData, ILineData, IRectData, IEllipseData, IPolygonData, IStarData, IPathData, IPenData, ITextData, IFontWeight, IImageData, IImage, IObject, ICanvasData } from '@leafer-ui/interface';
4
4
 
5
5
  declare class UIData extends LeafData implements IUIData {
6
6
  __leaf: IUI;
7
7
  __blendLayer?: boolean;
8
8
  __isFills?: boolean;
9
9
  __isStrokes?: boolean;
10
- protected _visible?: __Boolean;
11
- protected _width?: __Number;
12
- protected _height?: __Number;
13
- protected _fill?: __Value;
14
- protected _stroke?: __Value;
15
- protected _shadow?: __Value;
16
- protected _innerShadow?: __Value;
17
- protected setVisible(value: __Boolean): void;
18
- protected setWidth(value: __Number): void;
19
- protected setHeight(value: __Number): void;
20
- protected setFill(value: __Value): void;
21
- protected setStroke(value: __Value): void;
22
- protected setShadow(value: __Value): void;
23
- protected setInnerShadow(value: __Value): void;
10
+ get __strokeWidth(): number;
11
+ __pixelFill?: boolean;
12
+ __pixelStroke?: boolean;
13
+ __needComputePaint: boolean;
14
+ protected _visible?: IBoolean;
15
+ protected _width?: INumber;
16
+ protected _height?: INumber;
17
+ protected _fill?: IValue;
18
+ protected _stroke?: IValue;
19
+ protected _path: IPathCommandData;
20
+ protected _shadow?: IValue;
21
+ protected _innerShadow?: IValue;
22
+ get __autoWidth(): boolean;
23
+ get __autoHeight(): boolean;
24
+ get __autoSide(): boolean;
25
+ get __autoSize(): boolean;
26
+ protected setVisible(value: IBoolean): void;
27
+ protected setWidth(value: INumber): void;
28
+ protected setHeight(value: INumber): void;
29
+ protected setFill(value: IValue): void;
30
+ protected setStroke(value: IValue): void;
31
+ protected setPath(value: IPathCommandData | IPathString): void;
32
+ protected setShadow(value: IValue): void;
33
+ protected setInnerShadow(value: IValue): void;
34
+ __computePaint(): void;
24
35
  }
25
36
  declare const UnitConvert: {
26
37
  number(value: number | IUnitData, percentRefer?: number): number;
@@ -56,20 +67,25 @@ declare class PolygonData extends UIData implements IPolygonData {
56
67
  declare class StarData extends UIData implements IStarData {
57
68
  }
58
69
 
59
- declare class PathData extends UIData {
60
- protected _path: IPathCommandData;
61
- protected setPath(value: IPathCommandData | IPathString): void;
70
+ declare class PathData extends UIData implements IPathData {
62
71
  }
63
72
 
64
73
  declare class PenData extends GroupData implements IPenData {
65
74
  }
66
75
 
67
76
  declare class TextData extends UIData implements ITextData {
77
+ get __useNaturalRatio(): boolean;
68
78
  protected _fontWeight?: number;
69
79
  setFontWeight(value: IFontWeight): void;
70
80
  }
71
81
 
72
82
  declare class ImageData extends RectData implements IImageData {
83
+ __leaf: IImage;
84
+ protected _url: string;
85
+ protected setUrl(value: string): void;
86
+ __setImageFill(value: string): void;
87
+ __getData(): IObject;
88
+ __getInputData(): IObject;
73
89
  }
74
90
 
75
91
  declare class CanvasData extends RectData implements ICanvasData {