@leafer/data 1.0.0-beta.12 → 1.0.0-beta.15

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,12 +1,14 @@
1
1
  {
2
2
  "name": "@leafer/data",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.15",
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
+ "types",
11
+ "dist"
10
12
  ],
11
13
  "repository": {
12
14
  "type": "git",
@@ -19,6 +21,6 @@
19
21
  "leaferjs"
20
22
  ],
21
23
  "devDependencies": {
22
- "@leafer/interface": "1.0.0-beta.12"
24
+ "@leafer/interface": "1.0.0-beta.15"
23
25
  }
24
26
  }
@@ -0,0 +1,29 @@
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
+ constructor(leaf: ILeaf);
18
+ __get(name: string): any;
19
+ __setInput(name: string, value: any): void;
20
+ __getInput(name: string): any;
21
+ __removeInput(name: string): void;
22
+ __getInputData(): IObject;
23
+ __setMiddle(name: string, value: any): void;
24
+ __getMiddle(name: string): any;
25
+ __checkSingle(): void;
26
+ destroy(): void;
27
+ }
28
+
29
+ export { DataHelper, LeafData };
package/src/DataHelper.ts DELETED
@@ -1,37 +0,0 @@
1
- import { IObject } from '@leafer/interface'
2
-
3
-
4
- export const DataHelper = {
5
-
6
- default<T>(t: T, defaultData: IObject): T {
7
- assign(defaultData, t)
8
- assign(t, defaultData)
9
- return t
10
- },
11
-
12
- assign(t: IObject, merge: IObject): void {
13
- let value: unknown
14
- Object.keys(merge).forEach(key => {
15
- value = merge[key]
16
- if (value?.constructor === Object) {
17
- (t[key]?.constructor === Object) ? assign(t[key], merge[key]) : t[key] = merge[key]
18
- } else {
19
- t[key] = merge[key]
20
- }
21
- })
22
- },
23
-
24
- copyAttrs(t: IObject, from: IObject, include: string[]): IObject {
25
- include.forEach(key => {
26
- if (from[key] !== undefined) t[key] = from[key]
27
- })
28
- return t
29
- },
30
-
31
- clone(data: unknown): IObject {
32
- return JSON.parse(JSON.stringify(data))
33
- }
34
-
35
- }
36
-
37
- const { assign } = DataHelper
package/src/LeafData.ts DELETED
@@ -1,84 +0,0 @@
1
- import { ILeafData, ILeaf, IObject, __Value } from '@leafer/interface'
2
-
3
-
4
- export class LeafData implements ILeafData {
5
-
6
- public __leaf: ILeaf
7
- public __input: IObject
8
- public __middle: IObject
9
-
10
- public __single: boolean
11
-
12
- public __naturalWidth?: number
13
- public __naturalHeight?: number
14
-
15
- constructor(leaf: ILeaf) {
16
- this.__leaf = leaf
17
- }
18
-
19
- public __get(name: string): unknown {
20
- if (this.__input) {
21
- const value = this.__input[name]
22
- return value === undefined ? (this as IObject)[name] : value
23
- } else {
24
- return (this as IObject)[name]
25
- }
26
- }
27
-
28
- public __setInput(name: string, value: any): void {
29
- this.__input || (this.__input = {})
30
- this.__input[name] = value
31
- }
32
-
33
- public __getInput(name: string): unknown {
34
- if (this.__input) {
35
- const value = this.__input[name]
36
- return value === undefined ? (this as IObject)['_' + name] : value
37
- } else {
38
- return (this as IObject)['_' + name]
39
- }
40
- }
41
-
42
- public __removeInput(name: string): void {
43
- if (this.__input && this.__input[name] !== undefined) this.__input[name] = undefined
44
- }
45
-
46
- public __getInputData(): IObject {
47
- const data: IObject = {}, { __input } = this
48
- let realKey: string, value: __Value
49
-
50
- 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
55
- }
56
- }
57
- return data
58
- }
59
-
60
- public __setMiddle(name: string, value: any): void {
61
- this.__middle || (this.__middle = {})
62
- this.__middle[name] = value
63
- }
64
-
65
- public __getMiddle(name: string): any {
66
- return this.__middle && this.__middle[name]
67
- }
68
-
69
- 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
75
- }
76
- } else {
77
- this.__single = true
78
- }
79
- }
80
-
81
- public destroy(): void {
82
- this.__input = this.__middle = null
83
- }
84
- }