@leafer/data 1.0.0-rc.9 → 1.0.0
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 +3 -3
- package/src/DataHelper.ts +7 -1
- package/src/LeafData.ts +63 -16
- package/src/index.ts +11 -0
- package/types/index.d.ts +18 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/data",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
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
|
|
25
|
+
"@leafer/interface": "1.0.0"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/DataHelper.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IObject } from '@leafer/interface'
|
|
1
|
+
import { IBooleanMap, IObject } from '@leafer/interface'
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
export const DataHelper = {
|
|
@@ -30,6 +30,12 @@ export const DataHelper = {
|
|
|
30
30
|
|
|
31
31
|
clone(data: unknown): IObject {
|
|
32
32
|
return JSON.parse(JSON.stringify(data))
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
toMap(list: string[]): IBooleanMap {
|
|
36
|
+
const map = {} as IBooleanMap
|
|
37
|
+
for (let i = 0, len = list.length; i < len; i++) map[list[i]] = true
|
|
38
|
+
return map
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
}
|
package/src/LeafData.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeafData, ILeaf, IObject, IValue } from '@leafer/interface'
|
|
1
|
+
import { ILeafData, ILeaf, IObject, IValue, IPathCommandData, IJSONOptions } from '@leafer/interface'
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
export class LeafData implements ILeafData {
|
|
@@ -12,6 +12,19 @@ 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 __useNaturalRatio() { return true }
|
|
19
|
+
|
|
20
|
+
public get __isLinePath(): boolean { return (this as ILeafData).path && (this as ILeafData).path.length === 6 }
|
|
21
|
+
|
|
22
|
+
public get __blendMode(): string {
|
|
23
|
+
if ((this as ILeafData).eraser && (this as ILeafData).eraser !== 'path') return 'destination-out'
|
|
24
|
+
const { blendMode } = (this as ILeafData)
|
|
25
|
+
return blendMode === 'pass-through' ? null : blendMode
|
|
26
|
+
}
|
|
27
|
+
|
|
15
28
|
constructor(leaf: ILeaf) {
|
|
16
29
|
this.__leaf = leaf
|
|
17
30
|
}
|
|
@@ -46,6 +59,9 @@ export class LeafData implements ILeafData {
|
|
|
46
59
|
const value = this.__input[name]
|
|
47
60
|
if (value !== undefined) return value
|
|
48
61
|
}
|
|
62
|
+
|
|
63
|
+
if (name === 'path' && !this.__pathInputed) return // no path mode
|
|
64
|
+
|
|
49
65
|
return (this as IObject)['_' + name]
|
|
50
66
|
}
|
|
51
67
|
|
|
@@ -53,18 +69,43 @@ export class LeafData implements ILeafData {
|
|
|
53
69
|
if (this.__input && this.__input[name] !== undefined) this.__input[name] = undefined
|
|
54
70
|
}
|
|
55
71
|
|
|
56
|
-
public __getInputData(): IObject {
|
|
57
|
-
const data: IObject = {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
72
|
+
public __getInputData(names?: string[] | IObject, options?: IJSONOptions): IObject {
|
|
73
|
+
const data: IObject = {}
|
|
74
|
+
|
|
75
|
+
if (names) {
|
|
76
|
+
|
|
77
|
+
if (names instanceof Array) {
|
|
78
|
+
for (let name of names) data[name] = this.__getInput(name)
|
|
79
|
+
} else {
|
|
80
|
+
for (let name in names) data[name] = this.__getInput(name)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
} else {
|
|
84
|
+
|
|
85
|
+
let value: IValue, inputValue: IValue, { __input } = this
|
|
86
|
+
data.tag = this.__leaf.tag
|
|
87
|
+
for (let key in this) {
|
|
88
|
+
if (key[0] !== '_') {
|
|
89
|
+
value = (this as IObject)['_' + key]
|
|
90
|
+
if (value !== undefined) {
|
|
91
|
+
|
|
92
|
+
if (key === 'path' && !this.__pathInputed) continue // no path mode
|
|
93
|
+
|
|
94
|
+
inputValue = __input ? __input[key] : undefined
|
|
95
|
+
data[key] = (inputValue === undefined) ? value : inputValue
|
|
96
|
+
}
|
|
65
97
|
}
|
|
66
98
|
}
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (options) {
|
|
103
|
+
if (options.matrix) {
|
|
104
|
+
const { a, b, c, d, e, f } = this.__leaf.__localMatrix
|
|
105
|
+
data.matrix = { a, b, c, d, e, f }
|
|
106
|
+
}
|
|
67
107
|
}
|
|
108
|
+
|
|
68
109
|
return data
|
|
69
110
|
}
|
|
70
111
|
|
|
@@ -78,17 +119,23 @@ export class LeafData implements ILeafData {
|
|
|
78
119
|
}
|
|
79
120
|
|
|
80
121
|
public __checkSingle(): void {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
122
|
+
const t = this as ILeafData
|
|
123
|
+
if (t.blendMode === 'pass-through') {
|
|
124
|
+
const leaf = this.__leaf
|
|
125
|
+
if ((t.opacity < 1 && leaf.isBranch) || leaf.__hasEraser || t.eraser) {
|
|
126
|
+
t.__single = true
|
|
127
|
+
} else if (t.__single) {
|
|
128
|
+
t.__single = false
|
|
86
129
|
}
|
|
87
130
|
} else {
|
|
88
|
-
|
|
131
|
+
t.__single = true
|
|
89
132
|
}
|
|
90
133
|
}
|
|
91
134
|
|
|
135
|
+
public __removeNaturalSize(): void {
|
|
136
|
+
this.__naturalWidth = this.__naturalHeight = undefined
|
|
137
|
+
}
|
|
138
|
+
|
|
92
139
|
public destroy(): void {
|
|
93
140
|
this.__input = this.__middle = null
|
|
94
141
|
}
|
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,10 +1,11 @@
|
|
|
1
|
-
import { IObject, ILeafData, ILeaf } from '@leafer/interface';
|
|
1
|
+
import { IObject, IBooleanMap, ILeafData, ILeaf, IPathCommandData, IJSONOptions } from '@leafer/interface';
|
|
2
2
|
|
|
3
3
|
declare const DataHelper: {
|
|
4
4
|
default<T>(t: T, defaultData: IObject): T;
|
|
5
5
|
assign(t: IObject, merge: IObject): void;
|
|
6
6
|
copyAttrs(t: IObject, from: IObject, include: string[]): IObject;
|
|
7
7
|
clone(data: unknown): IObject;
|
|
8
|
+
toMap(list: string[]): IBooleanMap;
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
declare class LeafData implements ILeafData {
|
|
@@ -14,17 +15,31 @@ declare class LeafData implements ILeafData {
|
|
|
14
15
|
__single: boolean;
|
|
15
16
|
__naturalWidth?: number;
|
|
16
17
|
__naturalHeight?: number;
|
|
18
|
+
__pathInputed?: number;
|
|
19
|
+
__pathForRender?: IPathCommandData;
|
|
20
|
+
get __useNaturalRatio(): boolean;
|
|
21
|
+
get __isLinePath(): boolean;
|
|
22
|
+
get __blendMode(): string;
|
|
17
23
|
constructor(leaf: ILeaf);
|
|
18
24
|
__get(name: string): any;
|
|
19
25
|
__getData(): IObject;
|
|
20
26
|
__setInput(name: string, value: any): void;
|
|
21
27
|
__getInput(name: string): any;
|
|
22
28
|
__removeInput(name: string): void;
|
|
23
|
-
__getInputData(): IObject;
|
|
29
|
+
__getInputData(names?: string[] | IObject, options?: IJSONOptions): IObject;
|
|
24
30
|
__setMiddle(name: string, value: any): void;
|
|
25
31
|
__getMiddle(name: string): any;
|
|
26
32
|
__checkSingle(): void;
|
|
33
|
+
__removeNaturalSize(): void;
|
|
27
34
|
destroy(): void;
|
|
28
35
|
}
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
declare enum Answer {
|
|
38
|
+
No = 0,
|
|
39
|
+
Yes = 1,
|
|
40
|
+
NoAndSkip = 2,
|
|
41
|
+
YesAndSkip = 3
|
|
42
|
+
}
|
|
43
|
+
declare const emptyData: IObject;
|
|
44
|
+
|
|
45
|
+
export { Answer, DataHelper, LeafData, emptyData };
|