@leafer-ui/data 1.0.0-alpha.23 → 1.0.0-alpha.31

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-alpha.23",
3
+ "version": "1.0.0-alpha.31",
4
4
  "description": "@leafer-ui/data",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,10 +19,10 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "dependencies": {
22
- "@leafer/core": "1.0.0-alpha.23"
22
+ "@leafer/core": "1.0.0-alpha.31"
23
23
  },
24
24
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-alpha.23",
26
- "@leafer-ui/interface": "1.0.0-alpha.23"
25
+ "@leafer/interface": "1.0.0-alpha.31",
26
+ "@leafer-ui/interface": "1.0.0-alpha.31"
27
27
  }
28
28
  }
package/src/BoxData.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { IBoxData } from '@leafer-ui/interface'
2
+
3
+ import { GroupData } from "./GroupData"
4
+
5
+
6
+ export class BoxData extends GroupData implements IBoxData {
7
+
8
+ }
package/src/FrameData.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { IFrameData } from '@leafer-ui/interface'
2
2
 
3
- import { GroupData } from "./GroupData"
3
+ import { BoxData } from './BoxData'
4
4
 
5
5
 
6
- export class FrameData extends GroupData implements IFrameData {
6
+ export class FrameData extends BoxData implements IFrameData {
7
7
 
8
8
  }
@@ -0,0 +1,8 @@
1
+ import { ILeaferData } from '@leafer-ui/interface'
2
+
3
+ import { GroupData } from './GroupData'
4
+
5
+
6
+ export class LeaferData extends GroupData implements ILeaferData {
7
+
8
+ }
package/src/PathData.ts CHANGED
@@ -12,7 +12,13 @@ export class PathData extends UIData {
12
12
  protected _path: IPathCommandData
13
13
 
14
14
  protected setPath(value: IPathCommandData | IPathString) {
15
- this._path = (typeof value === 'string') ? parse(value) : value
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
+ }
16
22
  }
17
23
 
18
24
  }
package/src/PenData.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { IPenData } from '@leafer-ui/interface'
2
+
3
+ import { GroupData } from './GroupData'
4
+
5
+
6
+ export class PenData extends GroupData implements IPenData {
7
+
8
+ }
package/src/TextData.ts CHANGED
@@ -1,8 +1,32 @@
1
- import { ITextData } from '@leafer-ui/interface'
1
+ import { IFontWeight, ITextData } from '@leafer-ui/interface'
2
2
 
3
3
  import { UIData } from "./UIData"
4
4
 
5
5
 
6
+ const fontWeightMap = {
7
+ 'thin': 100,
8
+ 'extra-light': 200,
9
+ 'light': 300,
10
+ 'normal': 400,
11
+ 'medium': 500,
12
+ 'semi-bold': 600,
13
+ 'bold': 700,
14
+ 'extra-bold': 800,
15
+ 'black': 900
16
+ }
17
+
6
18
  export class TextData extends UIData implements ITextData {
7
19
 
20
+ protected _fontWeight?: number
21
+
22
+ setFontWeight(value: IFontWeight): void {
23
+ if (typeof value === 'string') {
24
+ this.__setInput('fontWeight', value)
25
+ this._fontWeight = fontWeightMap[value] || 400
26
+ } else {
27
+ if (this.__input) this.__removeInput('fontWeight')
28
+ this._fontWeight = value
29
+ }
30
+ }
31
+
8
32
  }
package/src/UIData.ts CHANGED
@@ -1,11 +1,17 @@
1
- import { __Value } from '@leafer/interface'
1
+ import { IBlendMode, __Value } from '@leafer/interface'
2
2
  import { LeafData } from '@leafer/core'
3
3
 
4
- import { IUIData } from '@leafer-ui/interface'
4
+ import { IShadowEffect, IUI, IUIData, IUnitData } from '@leafer-ui/interface'
5
+ import { Paint } from '@leafer-ui/external'
5
6
 
6
7
 
7
8
  export class UIData extends LeafData implements IUIData {
8
9
 
10
+ public __leaf: IUI
11
+
12
+ public __blendLayer?: boolean
13
+ public _blendMode: string
14
+
9
15
  public __isFills?: boolean
10
16
  public __isStrokes?: boolean
11
17
 
@@ -15,46 +21,71 @@ export class UIData extends LeafData implements IUIData {
15
21
  protected _shadow?: __Value
16
22
  protected _innerShadow?: __Value
17
23
 
24
+ protected setBlendMode(value: IBlendMode) {
25
+ this._blendMode = value
26
+ if (value === 'pass-through' || !value) {
27
+ if (this.__blendLayer) this.__blendLayer = false
28
+ } else {
29
+ this.__blendLayer = true
30
+ }
31
+ }
32
+
18
33
  protected setFill(value: __Value) {
19
- this._fill = value
20
34
  if (typeof value === 'string' || !value) {
21
- if (this.__isFills) this.__isFills = false
22
- } else if (value instanceof Array) {
23
- this.__setInput('fill', value)
24
- this.__isFills = true
35
+ this._fill = value
36
+ if (this.__input) this.__removeInput('fill')
37
+ this.__isFills && (this.__isFills = false)
25
38
  } else if (typeof value === 'object') {
26
- this.__setInput('fill', [value])
39
+ this.__setInput('fill', value)
40
+ this.__leaf.__layout.boxBoundsChanged ? this._fill = value : Paint.computeFill(this.__leaf)
27
41
  this.__isFills = true
28
42
  }
29
43
  }
30
44
 
31
45
  protected setStroke(value: __Value) {
32
- this._stroke = value
33
46
  if (typeof value === 'string' || !value) {
34
- if (this.__isStrokes) this.__isStrokes = false
35
- } else if (value instanceof Array) {
36
- this.__setInput('stroke', value)
37
- this.__isStrokes = true
47
+ this._stroke = value
48
+ if (this.__input) this.__removeInput('stroke')
49
+ this.__isStrokes && (this.__isStrokes = false)
38
50
  } else if (typeof value === 'object') {
39
- this.__setInput('stroke', [value])
51
+ this.__setInput('stroke', value)
52
+ this.__leaf.__layout.boxBoundsChanged ? this._stroke = value : Paint.computeStroke(this.__leaf)
40
53
  this.__isStrokes = true
41
54
  }
42
55
  }
43
56
 
44
57
  protected setShadow(value: __Value) {
58
+ this.__setInput('shadow', value)
45
59
  if (value instanceof Array) {
46
- this._shadow = value
60
+ if (value.some((item: IShadowEffect) => item.visible === false)) value = value.filter((item: IShadowEffect) => item.visible !== false)
61
+ this._shadow = value.length ? value : null
62
+ } else if (value) {
63
+ this._shadow = (value as IShadowEffect).visible === false ? null : [value]
47
64
  } else {
48
- this._shadow = [value]
65
+ this._shadow = null
49
66
  }
50
67
  }
51
68
 
52
69
  protected setInnerShadow(value: __Value) {
70
+ this.__setInput('innerShadow', value)
53
71
  if (value instanceof Array) {
54
- this._innerShadow = value
72
+ if (value.some((item: IShadowEffect) => item.visible === false)) value = value.filter((item: IShadowEffect) => item.visible !== false)
73
+ this._innerShadow = value.length ? value : null
74
+ } else if (value) {
75
+ this._innerShadow = (value as IShadowEffect).visible === false ? null : [value]
55
76
  } else {
56
- this._innerShadow = [value]
77
+ this._innerShadow = null
57
78
  }
58
79
  }
59
80
 
60
81
  }
82
+
83
+
84
+ export const UnitConvert = {
85
+
86
+ number(value: number | IUnitData, percentRefer?: number): number {
87
+ if (typeof value === 'object') return value.type === 'percent' ? value.value / 100 * percentRefer : value.value
88
+ return value
89
+ }
90
+
91
+ }
package/src/index.ts CHANGED
@@ -1,7 +1,9 @@
1
1
 
2
- export { UIData } from './UIData'
2
+ export { UIData, UnitConvert } from './UIData'
3
3
  export { GroupData } from './GroupData'
4
+ export { BoxData } from './BoxData'
4
5
 
6
+ export { LeaferData } from './LeaferData'
5
7
  export { FrameData } from './FrameData'
6
8
 
7
9
  export { LineData } from './LineData'
@@ -10,8 +12,10 @@ export { EllipseData } from './EllipseData'
10
12
  export { PolygonData } from './PolygonData'
11
13
  export { StarData } from './StarData'
12
14
  export { PathData } from './PathData'
15
+ export { PenData } from './PenData'
13
16
  export { VectorData } from './VectorData'
14
17
  export { TextData } from './TextData'
15
18
  export { ImageData } from './ImageData'
16
19
 
17
20
 
21
+