@leafer/image 1.6.1 → 1.6.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/image",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
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.3",
26
+ "@leafer/file": "1.6.3",
27
+ "@leafer/platform": "1.6.3"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "1.6.1"
30
+ "@leafer/interface": "1.6.3"
31
31
  }
32
32
  }
@@ -32,8 +32,8 @@ export const ImageManager: IImageManager = {
32
32
  }
33
33
  },
34
34
 
35
- hasOpacityPixel(config: ILeaferImageConfig): boolean {
36
- return FileHelper.opacityTypes.some(item => I.isFormat(item, config))
35
+ hasAlphaPixel(config: ILeaferImageConfig): boolean {
36
+ return FileHelper.alphaPixelTypes.some(item => I.isFormat(item, config))
37
37
  },
38
38
 
39
39
  isFormat(format: IExportFileType, config: ILeaferImageConfig): boolean {
@@ -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'
@@ -19,7 +19,7 @@ export class LeaferImage implements ILeaferImage {
19
19
  public height: number
20
20
 
21
21
  public isSVG: boolean
22
- public hasOpacityPixel: boolean // check png / svg / webp
22
+ public hasAlphaPixel: boolean // check png / svg / webp
23
23
 
24
24
  public get completed() { return this.ready || !!this.error }
25
25
 
@@ -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
@@ -44,13 +46,15 @@ export class LeaferImage implements ILeaferImage {
44
46
  }
45
47
 
46
48
  ImageManager.isFormat('svg', config) && (this.isSVG = true)
47
- ImageManager.hasOpacityPixel(config) && (this.hasOpacityPixel = true)
49
+ ImageManager.hasAlphaPixel(config) && (this.hasAlphaPixel = true)
48
50
  }
49
51
 
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;
@@ -7,11 +7,12 @@ declare class LeaferImage implements ILeaferImage {
7
7
  width: number;
8
8
  height: number;
9
9
  isSVG: boolean;
10
- hasOpacityPixel: boolean;
10
+ hasAlphaPixel: boolean;
11
11
  get completed(): boolean;
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;