@leafer/image 1.12.2 → 1.12.3
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 +7 -7
- package/src/LeaferImage.ts +18 -7
- package/types/index.d.ts +8 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/image",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.3",
|
|
4
4
|
"description": "@leafer/image",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/task": "1.12.
|
|
26
|
-
"@leafer/file": "1.12.
|
|
27
|
-
"@leafer/data": "1.12.
|
|
28
|
-
"@leafer/math": "1.12.
|
|
29
|
-
"@leafer/platform": "1.12.
|
|
25
|
+
"@leafer/task": "1.12.3",
|
|
26
|
+
"@leafer/file": "1.12.3",
|
|
27
|
+
"@leafer/data": "1.12.3",
|
|
28
|
+
"@leafer/math": "1.12.3",
|
|
29
|
+
"@leafer/platform": "1.12.3"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@leafer/interface": "1.12.
|
|
32
|
+
"@leafer/interface": "1.12.3"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/LeaferImage.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeaferImage, ILeaferImageConfig, IFunction, IObject, InnerId, IMatrixData, ICanvasPattern, ILeaferImageCacheCanvas, ILeaferImagePatternPaint } from '@leafer/interface'
|
|
1
|
+
import { ILeaferImage, ILeaferImageConfig, IFunction, IObject, InnerId, IMatrixData, ICanvasPattern, ILeaferImageCacheCanvas, ILeaferImagePatternPaint, ILeaferImageLevel, ISizeData, IImageCrossOrigin } from '@leafer/interface'
|
|
2
2
|
import { Platform } from '@leafer/platform'
|
|
3
3
|
import { Resource } from '@leafer/file'
|
|
4
4
|
import { IncrementId } from '@leafer/math'
|
|
@@ -13,6 +13,7 @@ export class LeaferImage implements ILeaferImage {
|
|
|
13
13
|
|
|
14
14
|
public readonly innerId: InnerId
|
|
15
15
|
public get url() { return this.config.url }
|
|
16
|
+
public get crossOrigin(): IImageCrossOrigin { const { crossOrigin } = this.config; return isUndefined(crossOrigin) ? Platform.image.crossOrigin : crossOrigin }
|
|
16
17
|
|
|
17
18
|
public view: any
|
|
18
19
|
|
|
@@ -48,11 +49,13 @@ export class LeaferImage implements ILeaferImage {
|
|
|
48
49
|
ImageManager.hasAlphaPixel(config) && (this.hasAlphaPixel = true)
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
public load(onSuccess?: IFunction, onError?: IFunction): number {
|
|
52
|
+
public load(onSuccess?: IFunction, onError?: IFunction, thumbSize?: ISizeData): number {
|
|
52
53
|
if (!this.loading) {
|
|
53
54
|
this.loading = true
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
Resource.tasker.add(async () => await Platform.origin.loadImage(this.getLoadUrl(thumbSize), this.crossOrigin, this).then(img => {
|
|
56
|
+
if (thumbSize) this.setThumbView(img)
|
|
57
|
+
this.setView(img)
|
|
58
|
+
}).catch((e) => {
|
|
56
59
|
this.error = e
|
|
57
60
|
this.onComplete(false)
|
|
58
61
|
}))
|
|
@@ -72,9 +75,11 @@ export class LeaferImage implements ILeaferImage {
|
|
|
72
75
|
|
|
73
76
|
protected setView(img: any): void {
|
|
74
77
|
this.ready = true
|
|
75
|
-
this.width
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
if (!this.width) {
|
|
79
|
+
this.width = img.width
|
|
80
|
+
this.height = img.height
|
|
81
|
+
this.view = img
|
|
82
|
+
}
|
|
78
83
|
this.onComplete(true)
|
|
79
84
|
}
|
|
80
85
|
|
|
@@ -122,6 +127,12 @@ export class LeaferImage implements ILeaferImage {
|
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
// need rewrite
|
|
130
|
+
public getLoadUrl(_thumbSize?: ISizeData): string { return this.url }
|
|
131
|
+
public setThumbView(_view: number): void { }
|
|
132
|
+
public getThumbSize(): ISizeData { return undefined }
|
|
133
|
+
|
|
134
|
+
public getMinLevel(): number { return undefined }
|
|
135
|
+
public getLevelData(_level: number): ILeaferImageLevel { return undefined }
|
|
125
136
|
public clearLevels(_checkUse?: boolean): void { }
|
|
126
137
|
|
|
127
138
|
public destroy(): void {
|
package/types/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ILeaferImage, InnerId, IObject, ILeaferImageConfig, IFunction, ILeaferImageCacheCanvas, IMatrixData, ILeaferImagePatternPaint, ICanvasPattern, IImageManager } from '@leafer/interface';
|
|
1
|
+
import { ILeaferImage, InnerId, IImageCrossOrigin, IObject, ILeaferImageConfig, IFunction, ILeaferImageCacheCanvas, ISizeData, IMatrixData, ILeaferImagePatternPaint, ICanvasPattern, ILeaferImageLevel, IImageManager } from '@leafer/interface';
|
|
2
2
|
|
|
3
3
|
declare class LeaferImage implements ILeaferImage {
|
|
4
4
|
readonly innerId: InnerId;
|
|
5
5
|
get url(): string;
|
|
6
|
+
get crossOrigin(): IImageCrossOrigin;
|
|
6
7
|
view: any;
|
|
7
8
|
width: number;
|
|
8
9
|
height: number;
|
|
@@ -17,13 +18,18 @@ declare class LeaferImage implements ILeaferImage {
|
|
|
17
18
|
protected waitComplete: IFunction[];
|
|
18
19
|
protected cache: ILeaferImageCacheCanvas;
|
|
19
20
|
constructor(config: ILeaferImageConfig);
|
|
20
|
-
load(onSuccess?: IFunction, onError?: IFunction): number;
|
|
21
|
+
load(onSuccess?: IFunction, onError?: IFunction, thumbSize?: ISizeData): number;
|
|
21
22
|
unload(index: number, stopEvent?: boolean): void;
|
|
22
23
|
protected setView(img: any): void;
|
|
23
24
|
protected onComplete(isSuccess: boolean): void;
|
|
24
25
|
getFull(_filters?: IObject): any;
|
|
25
26
|
getCanvas(width: number, height: number, opacity?: number, filters?: IObject, xGap?: number, yGap?: number, smooth?: boolean): any;
|
|
26
27
|
getPattern(canvas: any, repeat: string | null, transform?: IMatrixData, paint?: ILeaferImagePatternPaint): ICanvasPattern;
|
|
28
|
+
getLoadUrl(_thumbSize?: ISizeData): string;
|
|
29
|
+
setThumbView(_view: number): void;
|
|
30
|
+
getThumbSize(): ISizeData;
|
|
31
|
+
getMinLevel(): number;
|
|
32
|
+
getLevelData(_level: number): ILeaferImageLevel;
|
|
27
33
|
clearLevels(_checkUse?: boolean): void;
|
|
28
34
|
destroy(): void;
|
|
29
35
|
}
|