@leafer-ui/data 1.0.0-rc.9 → 1.0.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.0.0-rc.9",
3
+ "version": "1.0.1",
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.9",
26
- "@leafer-ui/external": "1.0.0-rc.9"
25
+ "@leafer/core": "1.0.1",
26
+ "@leafer-ui/external": "1.0.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.0.0-rc.9",
30
- "@leafer-ui/interface": "1.0.0-rc.9"
29
+ "@leafer/interface": "1.0.1",
30
+ "@leafer-ui/interface": "1.0.1"
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/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,10 +1,11 @@
1
- import { INumber, IValue, IBoolean } 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 {
@@ -16,9 +17,23 @@ export class UIData extends LeafData implements IUIData {
16
17
  public __isFills?: boolean
17
18
  public __isStrokes?: boolean
18
19
 
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
+
19
32
  public __pixelFill?: boolean // png / svg / webp
20
33
  public __pixelStroke?: boolean
21
34
 
35
+ public __needComputePaint: boolean
36
+
22
37
  protected _visible?: IBoolean
23
38
 
24
39
  protected _width?: INumber
@@ -27,13 +42,15 @@ export class UIData extends LeafData implements IUIData {
27
42
  protected _fill?: IValue
28
43
  protected _stroke?: IValue
29
44
 
45
+ protected _path: IPathCommandData
46
+
30
47
  protected _shadow?: IValue
31
48
  protected _innerShadow?: IValue
32
49
 
33
50
  public get __autoWidth() { return !this._width }
34
51
  public get __autoHeight() { return !this._height }
35
- public get __autoBounds() { return !this._width && !this._height }
36
-
52
+ public get __autoSide() { return !this._width || !this._height }
53
+ public get __autoSize() { return !this._width && !this._height }
37
54
 
38
55
  protected setVisible(value: IBoolean) {
39
56
  if (this.__leaf.leafer) this.__leaf.leafer.watcher.hasVisible = true
@@ -62,11 +79,11 @@ export class UIData extends LeafData implements IUIData {
62
79
 
63
80
 
64
81
  protected setFill(value: IValue) {
65
- if (this.__naturalWidth) this.__naturalWidth = this.__naturalHeight = undefined
82
+ if (this.__naturalWidth) this.__removeNaturalSize()
66
83
  if (typeof value === 'string' || !value) {
67
84
  if (this.__isFills) {
68
85
  this.__removeInput('fill')
69
- Paint.recycleImage('fill', this)
86
+ PaintImage.recycleImage('fill', this)
70
87
  this.__isFills = false
71
88
  if (this.__pixelFill) this.__pixelFill = false
72
89
  }
@@ -83,7 +100,7 @@ export class UIData extends LeafData implements IUIData {
83
100
  if (typeof value === 'string' || !value) {
84
101
  if (this.__isStrokes) {
85
102
  this.__removeInput('stroke')
86
- Paint.recycleImage('stroke', this)
103
+ PaintImage.recycleImage('stroke', this)
87
104
  this.__isStrokes = false
88
105
  if (this.__pixelStroke) this.__pixelStroke = false
89
106
  }
@@ -97,6 +114,17 @@ export class UIData extends LeafData implements IUIData {
97
114
  }
98
115
 
99
116
 
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
+
100
128
  protected setShadow(value: IValue) {
101
129
  this.__setInput('shadow', value)
102
130
  if (value instanceof Array) {
@@ -121,13 +149,22 @@ export class UIData extends LeafData implements IUIData {
121
149
  }
122
150
  }
123
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
+
124
161
  }
125
162
 
126
163
 
127
164
  export const UnitConvert = {
128
165
 
129
166
  number(value: number | IUnitData, percentRefer?: number): number {
130
- 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
131
168
  return value
132
169
  }
133
170
 
package/src/index.ts CHANGED
@@ -6,7 +6,6 @@ export { LeaferData } from './LeaferData'
6
6
  export { FrameData } from './FrameData'
7
7
 
8
8
  export { LineData } from './LineData'
9
- export { ArrowData } from './ArrowData'
10
9
  export { RectData } from './RectData'
11
10
  export { EllipseData } from './EllipseData'
12
11
  export { PolygonData } from './PolygonData'
package/types/index.d.ts CHANGED
@@ -1,31 +1,37 @@
1
- import { IBoolean, INumber, IValue, 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, IArrowData, IRectData, IEllipseData, IPolygonData, IStarData, IPathString, IPenData, ITextData, IFontWeight, IImageData, IImage, IObject, 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
+ get __strokeWidth(): number;
10
11
  __pixelFill?: boolean;
11
12
  __pixelStroke?: boolean;
13
+ __needComputePaint: boolean;
12
14
  protected _visible?: IBoolean;
13
15
  protected _width?: INumber;
14
16
  protected _height?: INumber;
15
17
  protected _fill?: IValue;
16
18
  protected _stroke?: IValue;
19
+ protected _path: IPathCommandData;
17
20
  protected _shadow?: IValue;
18
21
  protected _innerShadow?: IValue;
19
22
  get __autoWidth(): boolean;
20
23
  get __autoHeight(): boolean;
21
- get __autoBounds(): boolean;
24
+ get __autoSide(): boolean;
25
+ get __autoSize(): boolean;
22
26
  protected setVisible(value: IBoolean): void;
23
27
  protected setWidth(value: INumber): void;
24
28
  protected setHeight(value: INumber): void;
25
29
  protected setFill(value: IValue): void;
26
30
  protected setStroke(value: IValue): void;
31
+ protected setPath(value: IPathCommandData | IPathString): void;
27
32
  protected setShadow(value: IValue): void;
28
33
  protected setInnerShadow(value: IValue): void;
34
+ __computePaint(): void;
29
35
  }
30
36
  declare const UnitConvert: {
31
37
  number(value: number | IUnitData, percentRefer?: number): number;
@@ -47,9 +53,6 @@ declare class FrameData extends BoxData implements IFrameData {
47
53
  declare class LineData extends UIData implements ILineData {
48
54
  }
49
55
 
50
- declare class ArrowData extends LineData implements IArrowData {
51
- }
52
-
53
56
  declare class RectData extends UIData implements IRectData {
54
57
  get __boxStroke(): boolean;
55
58
  }
@@ -64,15 +67,14 @@ declare class PolygonData extends UIData implements IPolygonData {
64
67
  declare class StarData extends UIData implements IStarData {
65
68
  }
66
69
 
67
- declare class PathData extends UIData {
68
- protected _path: IPathCommandData;
69
- protected setPath(value: IPathCommandData | IPathString): void;
70
+ declare class PathData extends UIData implements IPathData {
70
71
  }
71
72
 
72
73
  declare class PenData extends GroupData implements IPenData {
73
74
  }
74
75
 
75
76
  declare class TextData extends UIData implements ITextData {
77
+ get __useNaturalRatio(): boolean;
76
78
  protected _fontWeight?: number;
77
79
  setFontWeight(value: IFontWeight): void;
78
80
  }
@@ -89,4 +91,4 @@ declare class ImageData extends RectData implements IImageData {
89
91
  declare class CanvasData extends RectData implements ICanvasData {
90
92
  }
91
93
 
92
- export { ArrowData, BoxData, CanvasData, EllipseData, FrameData, GroupData, ImageData, LeaferData, LineData, PathData, PenData, PolygonData, RectData, StarData, TextData, UIData, UnitConvert };
94
+ export { BoxData, CanvasData, EllipseData, FrameData, GroupData, ImageData, LeaferData, LineData, PathData, PenData, PolygonData, RectData, StarData, TextData, UIData, UnitConvert };
package/src/ArrowData.ts DELETED
@@ -1,8 +0,0 @@
1
- import { IArrowData } from "@leafer-ui/interface"
2
-
3
- import { LineData } from "./LineData"
4
-
5
-
6
- export class ArrowData extends LineData implements IArrowData {
7
-
8
- }