@leafer-ui/data 1.0.0-alpha.9 → 1.0.0-bate

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.9",
3
+ "version": "1.0.0-bate",
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.9"
22
+ "@leafer/core": "1.0.0-bate"
23
23
  },
24
24
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-alpha.9",
26
- "@leafer-ui/interface": "1.0.0-alpha.9"
25
+ "@leafer/interface": "1.0.0-bate",
26
+ "@leafer-ui/interface": "1.0.0-bate"
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
+ }
@@ -0,0 +1,8 @@
1
+ import { ICanvasData } from '@leafer-ui/interface'
2
+
3
+ import { UIData } from "./UIData"
4
+
5
+
6
+ export class CanvasData extends UIData implements ICanvasData {
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,52 +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
- if (typeof value === 'string') {
20
- this._fill = value
21
- if (this.__isFills) this.__isFills = false
22
- } else if (value instanceof Array) {
34
+ if (typeof value === 'string' || !value) {
23
35
  this._fill = value
24
- this.__isFills = true
36
+ if (this.__input) this.__removeInput('fill')
37
+ this.__isFills && (this.__isFills = false)
25
38
  } else if (typeof value === 'object') {
26
- this._fill = [value]
39
+ this.__setInput('fill', value)
40
+ this.__leaf.__layout.boxChanged ? this._fill = value : Paint.computeFill(this.__leaf)
27
41
  this.__isFills = true
28
- } else {
29
- this._fill = value
30
- if (this.__isFills) this.__isFills = false
31
42
  }
32
43
  }
33
44
 
34
45
  protected setStroke(value: __Value) {
35
- if (typeof value === 'string') {
46
+ if (typeof value === 'string' || !value) {
36
47
  this._stroke = value
37
- if (this.__isStrokes) this.__isStrokes = false
38
- } else if (value instanceof Array) {
39
- this._stroke = value
40
- this.__isStrokes = true
48
+ if (this.__input) this.__removeInput('stroke')
49
+ this.__isStrokes && (this.__isStrokes = false)
41
50
  } else if (typeof value === 'object') {
42
- this._stroke = [value]
51
+ this.__setInput('stroke', value)
52
+ this.__leaf.__layout.boxChanged ? this._stroke = value : Paint.computeStroke(this.__leaf)
43
53
  this.__isStrokes = true
44
- } else {
45
- this._stroke = value
46
- if (this.__isStrokes) this.__isStrokes = false
47
54
  }
48
55
  }
49
56
 
50
57
  protected setShadow(value: __Value) {
58
+ this.__setInput('shadow', value)
51
59
  if (value instanceof Array) {
52
- 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]
53
64
  } else {
54
- this._shadow = [value]
65
+ this._shadow = null
55
66
  }
56
67
  }
57
68
 
58
69
  protected setInnerShadow(value: __Value) {
70
+ this.__setInput('innerShadow', value)
59
71
  if (value instanceof Array) {
60
- 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]
61
76
  } else {
62
- this._innerShadow = [value]
77
+ this._innerShadow = null
63
78
  }
64
79
  }
65
80
 
66
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,8 @@
1
-
2
- export { UIData } from './UIData'
1
+ export { UIData, UnitConvert } from './UIData'
3
2
  export { GroupData } from './GroupData'
3
+ export { BoxData } from './BoxData'
4
4
 
5
+ export { LeaferData } from './LeaferData'
5
6
  export { FrameData } from './FrameData'
6
7
 
7
8
  export { LineData } from './LineData'
@@ -10,8 +11,7 @@ export { EllipseData } from './EllipseData'
10
11
  export { PolygonData } from './PolygonData'
11
12
  export { StarData } from './StarData'
12
13
  export { PathData } from './PathData'
13
- export { VectorData } from './VectorData'
14
+ export { PenData } from './PenData'
14
15
  export { TextData } from './TextData'
15
16
  export { ImageData } from './ImageData'
16
-
17
-
17
+ export { CanvasData } from './CanvasData'
package/src/VectorData.ts DELETED
@@ -1,8 +0,0 @@
1
- import { IVectorData } from '@leafer-ui/interface'
2
-
3
- import { UIData } from "./UIData"
4
-
5
-
6
- export class VectorData extends UIData implements IVectorData {
7
-
8
- }