@leafer/file 1.4.0 → 1.4.1
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/Resource.ts +58 -0
- package/src/index.ts +2 -1
- package/types/index.d.ts +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/file",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "@leafer/file",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/debug": "1.4.
|
|
25
|
+
"@leafer/debug": "1.4.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.4.
|
|
28
|
+
"@leafer/interface": "1.4.1"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/Resource.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ILeaferImage, IResource, IObject, ILeaferCanvas, IExportFileType, ILeaferImageConfig } from '@leafer/interface'
|
|
2
|
+
|
|
3
|
+
import { Creator } from '@leafer/platform'
|
|
4
|
+
import { TaskProcessor } from '@leafer/task'
|
|
5
|
+
import { Debug } from '@leafer/debug'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const debug = Debug.get('Resource')
|
|
9
|
+
|
|
10
|
+
export const Resource: IResource = {
|
|
11
|
+
|
|
12
|
+
tasker: new TaskProcessor(),
|
|
13
|
+
|
|
14
|
+
map: {},
|
|
15
|
+
|
|
16
|
+
get isComplete() { return R.tasker.isComplete },
|
|
17
|
+
|
|
18
|
+
// 通用
|
|
19
|
+
|
|
20
|
+
set(key: string, value: any): void {
|
|
21
|
+
if (R.map[key]) debug.repeat(key)
|
|
22
|
+
R.map[key] = value
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
get(key: string): any {
|
|
26
|
+
return R.map[key]
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
remove(key: string) {
|
|
30
|
+
delete R.map[key]
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
// image
|
|
34
|
+
|
|
35
|
+
loadImage(key: string, format?: IExportFileType): Promise<ILeaferImage> {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const image = this.setImage(key, key, format)
|
|
38
|
+
image.load(() => resolve(image), (e: any) => reject(e))
|
|
39
|
+
})
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
setImage(key: string, value: string | IObject | ILeaferImage | ILeaferCanvas, format?: IExportFileType): ILeaferImage {
|
|
43
|
+
let config: ILeaferImageConfig
|
|
44
|
+
if (typeof value === 'string') config = { url: value }
|
|
45
|
+
else if (!value.url) config = { url: key, view: value }
|
|
46
|
+
if (config) format && (config.format = format), value = Creator.image(config)
|
|
47
|
+
R.set(key, value)
|
|
48
|
+
return value as ILeaferImage
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
destroy(): void {
|
|
53
|
+
R.map = {}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const R = Resource
|
package/src/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { FileHelper } from './FileHelper'
|
|
1
|
+
export { FileHelper } from './FileHelper'
|
|
2
|
+
export { Resource } from './Resource'
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IExportFileType, IStringMap, IExportOptions } from '@leafer/interface';
|
|
1
|
+
import { IExportFileType, IStringMap, IExportOptions, IResource } from '@leafer/interface';
|
|
2
2
|
|
|
3
3
|
declare const FileHelper: {
|
|
4
4
|
opacityTypes: IExportFileType[];
|
|
@@ -9,4 +9,6 @@ declare const FileHelper: {
|
|
|
9
9
|
getExportOptions(options?: IExportOptions | number | boolean): IExportOptions;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
declare const Resource: IResource;
|
|
13
|
+
|
|
14
|
+
export { FileHelper, Resource };
|