@leafer/data 1.0.0-beta.9 → 1.0.0-rc.10

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