@leafer/data 1.0.0-rc.2 → 1.0.0-rc.20

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/data",
3
- "version": "1.0.0-rc.2",
3
+ "version": "1.0.0-rc.20",
4
4
  "description": "@leafer/data",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -15,13 +15,13 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/leaferjs/leafer.git"
17
17
  },
18
- "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/data",
18
+ "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/display-module/data",
19
19
  "bugs": "https://github.com/leaferjs/leafer/issues",
20
20
  "keywords": [
21
21
  "leafer",
22
22
  "leaferjs"
23
23
  ],
24
24
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-rc.2"
25
+ "@leafer/interface": "1.0.0-rc.20"
26
26
  }
27
27
  }
package/src/LeafData.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeafData, ILeaf, IObject, __Value } from '@leafer/interface'
1
+ import { ILeafData, ILeaf, IObject, IValue, IPathCommandData } from '@leafer/interface'
2
2
 
3
3
 
4
4
  export class LeafData implements ILeafData {
@@ -12,6 +12,15 @@ export class LeafData implements ILeafData {
12
12
  public __naturalWidth?: number
13
13
  public __naturalHeight?: number
14
14
 
15
+ public __pathInputed?: number
16
+ public __pathForRender?: IPathCommandData
17
+
18
+ public get __blendMode(): string {
19
+ if ((this as ILeafData).eraser) return 'destination-out'
20
+ const { blendMode } = (this as ILeafData)
21
+ return blendMode === 'pass-through' ? null : blendMode
22
+ }
23
+
15
24
  constructor(leaf: ILeaf) {
16
25
  this.__leaf = leaf
17
26
  }
@@ -24,6 +33,18 @@ export class LeafData implements ILeafData {
24
33
  return (this as IObject)[name]
25
34
  }
26
35
 
36
+ public __getData(): IObject {
37
+ const data: IObject = { tag: this.__leaf.tag }, { __input } = this
38
+ let inputValue: IValue
39
+ for (let key in this) {
40
+ if (key[0] !== '_') {
41
+ inputValue = __input ? __input[key] : undefined
42
+ data[key] = (inputValue === undefined) ? this[key] : inputValue
43
+ }
44
+ }
45
+ return data
46
+ }
47
+
27
48
  public __setInput(name: string, value: any): void {
28
49
  this.__input || (this.__input = {})
29
50
  this.__input[name] = value
@@ -34,6 +55,9 @@ export class LeafData implements ILeafData {
34
55
  const value = this.__input[name]
35
56
  if (value !== undefined) return value
36
57
  }
58
+
59
+ if (name === 'path' && !this.__pathInputed) return // no path mode
60
+
37
61
  return (this as IObject)['_' + name]
38
62
  }
39
63
 
@@ -41,17 +65,36 @@ export class LeafData implements ILeafData {
41
65
  if (this.__input && this.__input[name] !== undefined) this.__input[name] = undefined
42
66
  }
43
67
 
44
- public __getInputData(): IObject {
45
- const data: IObject = { tag: this.__leaf.tag }, { __input } = this
46
- let realKey: string, value: __Value
68
+ public __getInputData(names?: string[] | IObject): IObject {
69
+ const data: IObject = {}
47
70
 
48
- for (let key in this) {
49
- realKey = key.substring(1)
50
- if ((this as any)[realKey] !== undefined) {
51
- value = __input ? __input[realKey] : undefined
52
- data[realKey] = value === undefined ? this[key] : value
71
+ if (names) {
72
+
73
+ if (names instanceof Array) {
74
+ for (let name of names) data[name] = this.__getInput(name)
75
+ } else {
76
+ for (let name in names) data[name] = this.__getInput(name)
77
+ }
78
+
79
+ } else {
80
+
81
+ let value: IValue, inputValue: IValue, { __input } = this
82
+ data.tag = this.__leaf.tag
83
+ for (let key in this) {
84
+ if (key[0] !== '_') {
85
+ value = (this as IObject)['_' + key]
86
+ if (value !== undefined) {
87
+
88
+ if (key === 'path' && !this.__pathInputed) continue // no path mode
89
+
90
+ inputValue = __input ? __input[key] : undefined
91
+ data[key] = (inputValue === undefined) ? value : inputValue
92
+ }
93
+ }
53
94
  }
95
+
54
96
  }
97
+
55
98
  return data
56
99
  }
57
100
 
@@ -65,17 +108,23 @@ export class LeafData implements ILeafData {
65
108
  }
66
109
 
67
110
  public __checkSingle(): void {
68
- if ((this as ILeafData).blendMode === 'pass-through') {
69
- if (this.__leaf.__hasEraser || (this as ILeafData).isEraser) {
70
- this.__single = true
71
- } else if (this.__single) {
72
- this.__single = false
111
+ const t = this as ILeafData
112
+ if (t.blendMode === 'pass-through') {
113
+ const leaf = this.__leaf
114
+ if ((t.opacity < 1 && leaf.isBranch) || leaf.__hasEraser || t.eraser) {
115
+ t.__single = true
116
+ } else if (t.__single) {
117
+ t.__single = false
73
118
  }
74
119
  } else {
75
- this.__single = true
120
+ t.__single = true
76
121
  }
77
122
  }
78
123
 
124
+ public __removeNaturalSize(): void {
125
+ this.__naturalWidth = this.__naturalHeight = undefined
126
+ }
127
+
79
128
  public destroy(): void {
80
129
  this.__input = this.__middle = null
81
130
  }
package/src/index.ts CHANGED
@@ -1,2 +1,13 @@
1
+ import { IObject } from '@leafer/interface'
2
+
1
3
  export { DataHelper } from './DataHelper'
2
4
  export { LeafData } from './LeafData'
5
+
6
+ export enum Answer {
7
+ No = 0,
8
+ Yes = 1,
9
+ NoAndSkip = 2,
10
+ YesAndSkip = 3
11
+ }
12
+
13
+ export const emptyData: IObject = {}
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IObject, ILeafData, ILeaf } from '@leafer/interface';
1
+ import { IObject, ILeafData, ILeaf, IPathCommandData } from '@leafer/interface';
2
2
 
3
3
  declare const DataHelper: {
4
4
  default<T>(t: T, defaultData: IObject): T;
@@ -14,16 +14,29 @@ declare class LeafData implements ILeafData {
14
14
  __single: boolean;
15
15
  __naturalWidth?: number;
16
16
  __naturalHeight?: number;
17
+ __pathInputed?: number;
18
+ __pathForRender?: IPathCommandData;
19
+ get __blendMode(): string;
17
20
  constructor(leaf: ILeaf);
18
21
  __get(name: string): any;
22
+ __getData(): IObject;
19
23
  __setInput(name: string, value: any): void;
20
24
  __getInput(name: string): any;
21
25
  __removeInput(name: string): void;
22
- __getInputData(): IObject;
26
+ __getInputData(names?: string[] | IObject): IObject;
23
27
  __setMiddle(name: string, value: any): void;
24
28
  __getMiddle(name: string): any;
25
29
  __checkSingle(): void;
30
+ __removeNaturalSize(): void;
26
31
  destroy(): void;
27
32
  }
28
33
 
29
- export { DataHelper, LeafData };
34
+ declare enum Answer {
35
+ No = 0,
36
+ Yes = 1,
37
+ NoAndSkip = 2,
38
+ YesAndSkip = 3
39
+ }
40
+ declare const emptyData: IObject;
41
+
42
+ export { Answer, DataHelper, LeafData, emptyData };