@leafer/image 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 +5 -5
- package/src/ImageManager.ts +4 -14
- package/src/LeaferImage.ts +22 -10
- package/types/index.d.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/image",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "@leafer/image",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/task": "1.4.
|
|
26
|
-
"@leafer/file": "1.4.
|
|
27
|
-
"@leafer/platform": "1.4.
|
|
25
|
+
"@leafer/task": "1.4.1",
|
|
26
|
+
"@leafer/file": "1.4.1",
|
|
27
|
+
"@leafer/platform": "1.4.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@leafer/interface": "1.4.
|
|
30
|
+
"@leafer/interface": "1.4.1"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/ImageManager.ts
CHANGED
|
@@ -1,27 +1,18 @@
|
|
|
1
1
|
import { IImageManager, ILeaferImageConfig, ILeaferImage, IExportFileType } from '@leafer/interface'
|
|
2
2
|
import { Creator } from '@leafer/platform'
|
|
3
|
-
import { FileHelper } from '@leafer/file'
|
|
3
|
+
import { FileHelper, Resource } from '@leafer/file'
|
|
4
4
|
import { TaskProcessor } from '@leafer/task'
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
export const ImageManager: IImageManager = {
|
|
8
8
|
|
|
9
|
-
map: {},
|
|
10
|
-
|
|
11
9
|
recycledList: [],
|
|
12
10
|
|
|
13
|
-
tasker: new TaskProcessor(),
|
|
14
|
-
|
|
15
11
|
patternTasker: new TaskProcessor(),
|
|
16
12
|
|
|
17
|
-
get isComplete() { return I.tasker.isComplete },
|
|
18
|
-
|
|
19
13
|
get(config: ILeaferImageConfig): ILeaferImage {
|
|
20
|
-
let image =
|
|
21
|
-
if (!image)
|
|
22
|
-
image = Creator.image(config)
|
|
23
|
-
I.map[config.url] = image
|
|
24
|
-
}
|
|
14
|
+
let image: ILeaferImage = Resource.get(config.url)
|
|
15
|
+
if (!image) Resource.set(config.url, image = Creator.image(config))
|
|
25
16
|
image.use++
|
|
26
17
|
return image
|
|
27
18
|
},
|
|
@@ -36,7 +27,7 @@ export const ImageManager: IImageManager = {
|
|
|
36
27
|
if (list.length > 100) { // cache 100
|
|
37
28
|
list.forEach(image => {
|
|
38
29
|
if (!image.use && image.url) {
|
|
39
|
-
|
|
30
|
+
Resource.remove(image.url)
|
|
40
31
|
image.destroy()
|
|
41
32
|
}
|
|
42
33
|
})
|
|
@@ -61,7 +52,6 @@ export const ImageManager: IImageManager = {
|
|
|
61
52
|
},
|
|
62
53
|
|
|
63
54
|
destroy(): void {
|
|
64
|
-
I.map = {}
|
|
65
55
|
I.recycledList = []
|
|
66
56
|
}
|
|
67
57
|
|
package/src/LeaferImage.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ILeaferImage, ILeaferImageConfig, IFunction, IObject, InnerId, IMatrixData, ICanvasPattern, ILeaferImageCacheCanvas, ILeaferImagePatternPaint } from '@leafer/interface'
|
|
2
2
|
import { Platform } from '@leafer/platform'
|
|
3
|
+
import { Resource } from '@leafer/file'
|
|
3
4
|
import { IncrementId } from '@leafer/math'
|
|
4
5
|
|
|
5
6
|
import { ImageManager } from './ImageManager'
|
|
@@ -36,21 +37,20 @@ export class LeaferImage implements ILeaferImage {
|
|
|
36
37
|
|
|
37
38
|
constructor(config: ILeaferImageConfig) {
|
|
38
39
|
this.innerId = create(IMAGE)
|
|
39
|
-
this.config = config || { url: '' }
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
this.config = config || (config = { url: '' })
|
|
41
|
+
if (config.view) {
|
|
42
|
+
const { view } = config
|
|
43
|
+
this.setView(view.config ? view.view : view)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
ImageManager.isFormat('svg', config) && (this.isSVG = true)
|
|
47
|
+
ImageManager.hasOpacityPixel(config) && (this.hasOpacityPixel = true)
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
public load(onSuccess?: IFunction, onError?: IFunction): number {
|
|
45
51
|
if (!this.loading) {
|
|
46
52
|
this.loading = true
|
|
47
|
-
|
|
48
|
-
this.ready = true
|
|
49
|
-
this.width = img.naturalWidth || img.width
|
|
50
|
-
this.height = img.naturalHeight || img.height
|
|
51
|
-
this.view = img
|
|
52
|
-
this.onComplete(true)
|
|
53
|
-
}).catch((e) => {
|
|
53
|
+
Resource.tasker.add(async () => await Platform.origin.loadImage(this.url as string).then(img => this.setView(img)).catch((e) => {
|
|
54
54
|
this.error = e
|
|
55
55
|
this.onComplete(false)
|
|
56
56
|
}))
|
|
@@ -68,6 +68,14 @@ export class LeaferImage implements ILeaferImage {
|
|
|
68
68
|
l[index] = l[index + 1] = undefined
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
protected setView(img: any): void {
|
|
72
|
+
this.ready = true
|
|
73
|
+
this.width = img.naturalWidth || img.width
|
|
74
|
+
this.height = img.naturalHeight || img.height
|
|
75
|
+
this.view = img
|
|
76
|
+
this.onComplete(true)
|
|
77
|
+
}
|
|
78
|
+
|
|
71
79
|
protected onComplete(isSuccess: boolean): void {
|
|
72
80
|
let odd: number
|
|
73
81
|
this.waitComplete.forEach((item, index) => {
|
|
@@ -84,6 +92,10 @@ export class LeaferImage implements ILeaferImage {
|
|
|
84
92
|
this.loading = false
|
|
85
93
|
}
|
|
86
94
|
|
|
95
|
+
public getFull(_filters?: IObject): any {
|
|
96
|
+
return this.view
|
|
97
|
+
}
|
|
98
|
+
|
|
87
99
|
public getCanvas(width: number, height: number, opacity?: number, _filters?: IObject): any {
|
|
88
100
|
width || (width = this.width)
|
|
89
101
|
height || (height = this.height)
|
package/types/index.d.ts
CHANGED
|
@@ -19,7 +19,9 @@ declare class LeaferImage implements ILeaferImage {
|
|
|
19
19
|
constructor(config: ILeaferImageConfig);
|
|
20
20
|
load(onSuccess?: IFunction, onError?: IFunction): number;
|
|
21
21
|
unload(index: number, stopEvent?: boolean): void;
|
|
22
|
+
protected setView(img: any): void;
|
|
22
23
|
protected onComplete(isSuccess: boolean): void;
|
|
24
|
+
getFull(_filters?: IObject): any;
|
|
23
25
|
getCanvas(width: number, height: number, opacity?: number, _filters?: IObject): any;
|
|
24
26
|
getPattern(canvas: any, repeat: string | null, transform?: IMatrixData, paint?: ILeaferImagePatternPaint): ICanvasPattern;
|
|
25
27
|
destroy(): void;
|