@leafer/image 1.12.2 → 1.12.4

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