@leafer/image 1.0.0-alpha.21 → 1.0.0-alpha.23
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 +2 -2
- package/src/ImageManager.ts +37 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/image",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.23",
|
|
4
4
|
"description": "@leafer/image",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@leafer/interface": "1.0.0-alpha.
|
|
22
|
+
"@leafer/interface": "1.0.0-alpha.23"
|
|
23
23
|
}
|
|
24
24
|
}
|
package/src/ImageManager.ts
CHANGED
|
@@ -1,16 +1,50 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ILeafer, ILeaferCanvasConfig, IImageManager, ILeaferImageConfig, ILeaferImage, ILeaferImageOnLoaded, ILeaferImageOnError } from '@leafer/interface'
|
|
2
|
+
import { Creator } from '@leafer/platform'
|
|
3
|
+
|
|
4
|
+
interface ILeaferImageMap {
|
|
5
|
+
[name: string]: ILeaferImage
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface ILeaferImageOnLoadMap {
|
|
9
|
+
[name: string]: ILeaferImageOnLoaded[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface ILeaferImageOnErrorMap {
|
|
13
|
+
[name: string]: ILeaferImageOnError[]
|
|
14
|
+
}
|
|
2
15
|
|
|
3
16
|
export class ImageManager implements IImageManager {
|
|
4
17
|
|
|
5
18
|
public leafer: ILeafer
|
|
6
19
|
|
|
7
|
-
public
|
|
20
|
+
public map: ILeaferImageMap = {}
|
|
21
|
+
|
|
22
|
+
protected __onLoadMap: ILeaferImageOnLoadMap = {}
|
|
23
|
+
protected __onErrorMap: ILeaferImageOnErrorMap = {}
|
|
8
24
|
|
|
9
25
|
constructor(leafer: ILeafer, _config: ILeaferCanvasConfig) {
|
|
10
26
|
this.leafer = leafer
|
|
11
27
|
}
|
|
12
28
|
|
|
13
|
-
public
|
|
29
|
+
public get(config: ILeaferImageConfig): ILeaferImage {
|
|
30
|
+
let image = this.map[config.url]
|
|
31
|
+
if (!image) {
|
|
32
|
+
image = Creator.image(config)
|
|
33
|
+
this.map[config.url] = image
|
|
34
|
+
}
|
|
35
|
+
return image
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public onLoad(config: ILeaferImageConfig, onLoaded: ILeaferImageOnLoaded): void {
|
|
39
|
+
const image = this.map[config.url]
|
|
40
|
+
if (image && image.ready) {
|
|
41
|
+
onLoaded(image)
|
|
42
|
+
} else {
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public onError(config: ILeaferImageConfig, onError: ILeaferImageOnError): void {
|
|
14
48
|
|
|
15
49
|
}
|
|
16
50
|
|