@leafer/image 1.0.0-beta.10 → 1.0.0-beta.12
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 +4 -4
- package/src/ImageManager.ts +2 -3
- package/src/LeaferImageBase.ts +9 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/image",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.12",
|
|
4
4
|
"description": "@leafer/image",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer/task": "1.0.0-beta.
|
|
23
|
-
"@leafer/platform": "1.0.0-beta.
|
|
22
|
+
"@leafer/task": "1.0.0-beta.12",
|
|
23
|
+
"@leafer/platform": "1.0.0-beta.12"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-beta.
|
|
26
|
+
"@leafer/interface": "1.0.0-beta.12"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/ImageManager.ts
CHANGED
|
@@ -26,14 +26,14 @@ export const ImageManager: IImageManager = {
|
|
|
26
26
|
|
|
27
27
|
recycle(image: ILeaferImage): void {
|
|
28
28
|
image.use--
|
|
29
|
-
setTimeout(() => { if (!image.use) I.recycledList.push(image) }
|
|
29
|
+
setTimeout(() => { if (!image.use) I.recycledList.push(image) })
|
|
30
30
|
},
|
|
31
31
|
|
|
32
32
|
clearRecycled(): void {
|
|
33
33
|
const list = I.recycledList
|
|
34
34
|
if (list.length) {
|
|
35
35
|
list.forEach(image => {
|
|
36
|
-
if (!image.use) {
|
|
36
|
+
if (!image.use && image.url) {
|
|
37
37
|
delete I.map[image.url]
|
|
38
38
|
image.destroy()
|
|
39
39
|
}
|
|
@@ -44,7 +44,6 @@ export const ImageManager: IImageManager = {
|
|
|
44
44
|
|
|
45
45
|
destroy(): void {
|
|
46
46
|
I.map = {}
|
|
47
|
-
I.tasker = null
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
}
|
package/src/LeaferImageBase.ts
CHANGED
|
@@ -32,7 +32,7 @@ export class LeaferImageBase implements ILeaferImage {
|
|
|
32
32
|
|
|
33
33
|
constructor(config: ILeaferImageConfig) {
|
|
34
34
|
this.innerId = create(IMAGE)
|
|
35
|
-
this.config = config
|
|
35
|
+
this.config = config || { url: '' }
|
|
36
36
|
const { url } = config
|
|
37
37
|
if (url.startsWith('data:')) {
|
|
38
38
|
if (url.startsWith('data:image/svg')) this.isSVG = true
|
|
@@ -44,7 +44,7 @@ export class LeaferImageBase implements ILeaferImage {
|
|
|
44
44
|
public load(onSuccess: IFunction, onError: IFunction): number {
|
|
45
45
|
if (!this.loading) {
|
|
46
46
|
this.loading = true
|
|
47
|
-
ImageManager.tasker.
|
|
47
|
+
ImageManager.tasker.add(async () => await Platform.origin.loadImage(this.url).then((img) => {
|
|
48
48
|
this.ready = true
|
|
49
49
|
this.width = img.naturalWidth || img.width
|
|
50
50
|
this.height = img.naturalHeight || img.height
|
|
@@ -53,16 +53,18 @@ export class LeaferImageBase implements ILeaferImage {
|
|
|
53
53
|
}).catch((e) => {
|
|
54
54
|
this.error = e
|
|
55
55
|
this.onComplete(false)
|
|
56
|
-
})
|
|
56
|
+
}))
|
|
57
57
|
}
|
|
58
58
|
this.waitComplete.push(onSuccess, onError)
|
|
59
59
|
return this.waitComplete.length - 2
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
public unload(index: number): void {
|
|
62
|
+
public unload(index: number, stopEvent?: boolean): void {
|
|
63
63
|
const l = this.waitComplete
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
if (stopEvent) {
|
|
65
|
+
const error = l[index + 1]
|
|
66
|
+
if (error) error({ type: 'stop' })
|
|
67
|
+
}
|
|
66
68
|
l[index] = l[index + 1] = undefined
|
|
67
69
|
}
|
|
68
70
|
|
|
@@ -93,8 +95,7 @@ export class LeaferImageBase implements ILeaferImage {
|
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
public destroy(): void {
|
|
96
|
-
this.
|
|
97
|
-
this.config = null
|
|
98
|
+
this.config = { url: '' }
|
|
98
99
|
this.waitComplete.length = 0
|
|
99
100
|
}
|
|
100
101
|
|