@leafer/image 1.6.1 → 1.6.2

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.6.1",
3
+ "version": "1.6.2",
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.6.1",
26
- "@leafer/file": "1.6.1",
27
- "@leafer/platform": "1.6.1"
25
+ "@leafer/task": "1.6.2",
26
+ "@leafer/file": "1.6.2",
27
+ "@leafer/platform": "1.6.2"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "1.6.1"
30
+ "@leafer/interface": "1.6.2"
31
31
  }
32
32
  }
@@ -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, IProgressData } from '@leafer/interface'
2
2
  import { Platform } from '@leafer/platform'
3
3
  import { Resource } from '@leafer/file'
4
4
  import { IncrementId } from '@leafer/math'
@@ -27,6 +27,8 @@ export class LeaferImage implements ILeaferImage {
27
27
  public error: IObject
28
28
  public loading: boolean
29
29
 
30
+ public progress: IProgressData
31
+
30
32
  public use = 0
31
33
 
32
34
  public config: ILeaferImageConfig
@@ -50,7 +52,9 @@ export class LeaferImage implements ILeaferImage {
50
52
  public load(onSuccess?: IFunction, onError?: IFunction): number {
51
53
  if (!this.loading) {
52
54
  this.loading = true
53
- Resource.tasker.add(async () => await Platform.origin.loadImage(this.url as string).then(img => this.setView(img)).catch((e) => {
55
+ let { loadImage, loadImageWithProgress } = Platform.origin, onProgress = this.config.showProgress && loadImageWithProgress && this.onProgress.bind(this)
56
+ if (onProgress) loadImage = loadImageWithProgress
57
+ Resource.tasker.add(async () => await loadImage(this.url, onProgress).then(img => this.setView(img)).catch((e) => {
54
58
  this.error = e
55
59
  this.onComplete(false)
56
60
  }))
@@ -76,6 +80,10 @@ export class LeaferImage implements ILeaferImage {
76
80
  this.onComplete(true)
77
81
  }
78
82
 
83
+ protected onProgress(progress: IProgressData): void {
84
+ this.progress = progress
85
+ }
86
+
79
87
  protected onComplete(isSuccess: boolean): void {
80
88
  let odd: number
81
89
  this.waitComplete.forEach((item, index) => {
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaferImage, InnerId, IObject, ILeaferImageConfig, IFunction, ILeaferImageCacheCanvas, IMatrixData, ILeaferImagePatternPaint, ICanvasPattern, IImageManager } from '@leafer/interface';
1
+ import { ILeaferImage, InnerId, IObject, IProgressData, ILeaferImageConfig, IFunction, ILeaferImageCacheCanvas, IMatrixData, ILeaferImagePatternPaint, ICanvasPattern, IImageManager } from '@leafer/interface';
2
2
 
3
3
  declare class LeaferImage implements ILeaferImage {
4
4
  readonly innerId: InnerId;
@@ -12,6 +12,7 @@ declare class LeaferImage implements ILeaferImage {
12
12
  ready: boolean;
13
13
  error: IObject;
14
14
  loading: boolean;
15
+ progress: IProgressData;
15
16
  use: number;
16
17
  config: ILeaferImageConfig;
17
18
  protected waitComplete: IFunction[];
@@ -20,6 +21,7 @@ declare class LeaferImage implements ILeaferImage {
20
21
  load(onSuccess?: IFunction, onError?: IFunction): number;
21
22
  unload(index: number, stopEvent?: boolean): void;
22
23
  protected setView(img: any): void;
24
+ protected onProgress(progress: IProgressData): 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): any;