@leafer/image 1.9.12 → 1.10.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/image",
3
- "version": "1.9.12",
3
+ "version": "1.10.1",
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.9.12",
26
- "@leafer/file": "1.9.12",
27
- "@leafer/data": "1.9.12",
28
- "@leafer/math": "1.9.12",
29
- "@leafer/platform": "1.9.12"
25
+ "@leafer/task": "1.10.1",
26
+ "@leafer/file": "1.10.1",
27
+ "@leafer/data": "1.10.1",
28
+ "@leafer/math": "1.10.1",
29
+ "@leafer/platform": "1.10.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@leafer/interface": "1.9.12"
32
+ "@leafer/interface": "1.10.1"
33
33
  }
34
34
  }
@@ -1,14 +1,13 @@
1
- import { ILeaferImage, ILeaferImageConfig, IFunction, IObject, InnerId, IMatrixData, ICanvasPattern, ILeaferImageCacheCanvas, ILeaferImagePatternPaint, IProgressData } from '@leafer/interface'
1
+ import { ILeaferImage, ILeaferImageConfig, IFunction, IObject, InnerId, IMatrixData, ICanvasPattern, ILeaferImageCacheCanvas, ILeaferImagePatternPaint } from '@leafer/interface'
2
2
  import { Platform } from '@leafer/platform'
3
3
  import { Resource } from '@leafer/file'
4
4
  import { IncrementId } from '@leafer/math'
5
- import { DataHelper } from '@leafer/data'
5
+ import { isUndefined } from '@leafer/data'
6
6
 
7
7
  import { ImageManager } from './ImageManager'
8
8
 
9
9
 
10
10
  const { IMAGE, create } = IncrementId
11
- const { floor, max } = Math
12
11
 
13
12
  export class LeaferImage implements ILeaferImage {
14
13
 
@@ -29,8 +28,6 @@ export class LeaferImage implements ILeaferImage {
29
28
  public error: IObject
30
29
  public loading: boolean
31
30
 
32
- public progress: IProgressData
33
-
34
31
  public use = 0
35
32
 
36
33
  public config: ILeaferImageConfig
@@ -54,9 +51,8 @@ export class LeaferImage implements ILeaferImage {
54
51
  public load(onSuccess?: IFunction, onError?: IFunction): number {
55
52
  if (!this.loading) {
56
53
  this.loading = true
57
- let { loadImage, loadImageWithProgress } = Platform.origin, onProgress = this.config.showProgress && loadImageWithProgress && this.onProgress.bind(this)
58
- if (onProgress) loadImage = loadImageWithProgress
59
- Resource.tasker.add(async () => await loadImage(this.url, onProgress).then(img => this.setView(img)).catch((e) => {
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) => {
60
56
  this.error = e
61
57
  this.onComplete(false)
62
58
  }))
@@ -82,10 +78,6 @@ export class LeaferImage implements ILeaferImage {
82
78
  this.onComplete(true)
83
79
  }
84
80
 
85
- protected onProgress(progress: IProgressData): void {
86
- this.progress = progress
87
- }
88
-
89
81
  protected onComplete(isSuccess: boolean): void {
90
82
  let odd: number
91
83
  this.waitComplete.forEach((item, index) => {
@@ -106,7 +98,7 @@ export class LeaferImage implements ILeaferImage {
106
98
  return this.view
107
99
  }
108
100
 
109
- public getCanvas(width: number, height: number, opacity?: number, _filters?: IObject, xGap?: number, yGap?: number, smooth?: boolean): any {
101
+ public getCanvas(width: number, height: number, opacity?: number, filters?: IObject, xGap?: number, yGap?: number, smooth?: boolean): any {
110
102
  width || (width = this.width)
111
103
  height || (height = this.height)
112
104
 
@@ -116,11 +108,7 @@ export class LeaferImage implements ILeaferImage {
116
108
  if (data) return data
117
109
  }
118
110
 
119
- const canvas = Platform.origin.createCanvas(max(floor(width + (xGap || 0)), 1), max(floor(height + (yGap || 0)), 1))
120
- const ctx = canvas.getContext('2d')
121
- if (opacity) ctx.globalAlpha = opacity
122
- ctx.imageSmoothingEnabled = smooth === false ? false : true // 平滑绘制
123
- ctx.drawImage(this.view, 0, 0, width, height)
111
+ const canvas = Platform.image.resize(this.view, width, height, xGap, yGap, undefined, smooth, opacity, filters)
124
112
 
125
113
  this.cache = this.use > 1 ? { data: canvas, params: arguments } : null
126
114
 
@@ -129,16 +117,11 @@ export class LeaferImage implements ILeaferImage {
129
117
 
130
118
  public getPattern(canvas: any, repeat: string | null, transform?: IMatrixData, paint?: ILeaferImagePatternPaint): ICanvasPattern {
131
119
  const pattern = Platform.canvas.createPattern(canvas, repeat)
132
- try {
133
- if (transform && pattern.setTransform) {
134
- pattern.setTransform(transform) // maybe error
135
- transform = undefined
136
- }
137
- } catch { }
138
- if (paint) DataHelper.stintSet(paint, 'transform', transform)
120
+ Platform.image.setPatternTransform(pattern, transform, paint)
139
121
  return pattern
140
122
  }
141
123
 
124
+
142
125
  public destroy(): void {
143
126
  this.config = { url: '' }
144
127
  this.cache = null
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaferImage, InnerId, IObject, IProgressData, ILeaferImageConfig, IFunction, ILeaferImageCacheCanvas, IMatrixData, ILeaferImagePatternPaint, ICanvasPattern, IImageManager } from '@leafer/interface';
1
+ import { ILeaferImage, InnerId, IObject, 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,7 +12,6 @@ declare class LeaferImage implements ILeaferImage {
12
12
  ready: boolean;
13
13
  error: IObject;
14
14
  loading: boolean;
15
- progress: IProgressData;
16
15
  use: number;
17
16
  config: ILeaferImageConfig;
18
17
  protected waitComplete: IFunction[];
@@ -21,10 +20,9 @@ declare class LeaferImage implements ILeaferImage {
21
20
  load(onSuccess?: IFunction, onError?: IFunction): number;
22
21
  unload(index: number, stopEvent?: boolean): void;
23
22
  protected setView(img: any): void;
24
- protected onProgress(progress: IProgressData): void;
25
23
  protected onComplete(isSuccess: boolean): void;
26
24
  getFull(_filters?: IObject): any;
27
- getCanvas(width: number, height: number, opacity?: number, _filters?: IObject, xGap?: number, yGap?: number, smooth?: boolean): any;
25
+ getCanvas(width: number, height: number, opacity?: number, filters?: IObject, xGap?: number, yGap?: number, smooth?: boolean): any;
28
26
  getPattern(canvas: any, repeat: string | null, transform?: IMatrixData, paint?: ILeaferImagePatternPaint): ICanvasPattern;
29
27
  destroy(): void;
30
28
  }