@leafer/image 2.0.1 → 2.0.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": "2.0.1",
3
+ "version": "2.0.2",
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": "2.0.1",
26
- "@leafer/file": "2.0.1",
27
- "@leafer/data": "2.0.1",
28
- "@leafer/math": "2.0.1",
29
- "@leafer/platform": "2.0.1"
25
+ "@leafer/task": "2.0.2",
26
+ "@leafer/file": "2.0.2",
27
+ "@leafer/data": "2.0.2",
28
+ "@leafer/math": "2.0.2",
29
+ "@leafer/platform": "2.0.2"
30
30
  },
31
31
  "devDependencies": {
32
- "@leafer/interface": "2.0.1"
32
+ "@leafer/interface": "2.0.2"
33
33
  }
34
34
  }
@@ -1,7 +1,6 @@
1
- import { IImageManager, ILeaferImageConfig, ILeaferImage, IExportFileType } from '@leafer/interface'
1
+ import { IImageManager, ILeaferImageConfig, ILeaferImage, IExportFileType, IMultimediaType } from '@leafer/interface'
2
2
  import { Creator, Platform } from '@leafer/platform'
3
3
  import { FileHelper, Resource } from '@leafer/file'
4
- import { TaskProcessor } from '@leafer/task'
5
4
 
6
5
 
7
6
  export const ImageManager: IImageManager = {
@@ -10,11 +9,11 @@ export const ImageManager: IImageManager = {
10
9
 
11
10
  recycledList: [],
12
11
 
13
- patternTasker: new TaskProcessor({ parallel: 1 }),
12
+ patternTasker: Resource.queue, // 全局按顺序执行的任务队列,防止阻塞主线程
14
13
 
15
- get(config: ILeaferImageConfig): ILeaferImage {
14
+ get(config: ILeaferImageConfig, type?: IMultimediaType): ILeaferImage {
16
15
  let image: ILeaferImage = Resource.get(config.url)
17
- if (!image) Resource.set(config.url, image = Creator.image(config))
16
+ if (!image) Resource.set(config.url, image = type === 'film' ? Creator.film(config) : Creator.image(config))
18
17
  image.use++
19
18
  return image
20
19
  },
@@ -57,7 +56,7 @@ export const ImageManager: IImageManager = {
57
56
  if (config.format) return config.format === format
58
57
  const { url } = config
59
58
  if (url.startsWith('data:')) {
60
- if (url.startsWith('data:' + FileHelper.mineType(format))) return true
59
+ if (url.startsWith('data:' + FileHelper.mimeType(format))) return true
61
60
  } else {
62
61
  if (url.includes('.' + format) || url.includes('.' + FileHelper.upperCaseTypeMap[format])) return true
63
62
  else if (format === 'png' && !url.includes('.')) return true // blob: 等无后缀名协议的图片无法分析类型,直接当透明图片处理
@@ -0,0 +1,10 @@
1
+ import { ILeaferFilm } from '@leafer/interface'
2
+
3
+ import { LeaferImage } from './LeaferImage'
4
+
5
+
6
+ export class LeaferFilm extends LeaferImage implements ILeaferFilm {
7
+
8
+ public get tag() { return 'Film' }
9
+
10
+ }
@@ -1,4 +1,4 @@
1
- import { ILeaferImage, ILeaferImageConfig, IFunction, IObject, InnerId, IMatrixData, ICanvasPattern, ILeaferImageCacheCanvas, ILeaferImagePatternPaint, ILeaferImageLevel, ISizeData, IImageCrossOrigin, IImageLOD, IInterlace } from '@leafer/interface'
1
+ import { ILeaferImage, ILeaferImageConfig, IFunction, IObject, InnerId, ILeaf, IMatrixData, ICanvasPattern, ILeaferImageCacheCanvas, ILeaferImagePatternPaint, ILeaferImageLevel, ISizeData, IImageCrossOrigin, IImageLOD, IInterlace } from '@leafer/interface'
2
2
  import { Platform } from '@leafer/platform'
3
3
  import { Resource } from '@leafer/file'
4
4
  import { IncrementId } from '@leafer/math'
@@ -12,6 +12,8 @@ const { IMAGE, create } = IncrementId
12
12
  export class LeaferImage implements ILeaferImage {
13
13
 
14
14
  public readonly innerId: InnerId
15
+ public get tag() { return 'Image' }
16
+
15
17
  public get url() { return this.config.url }
16
18
  public lod?: IImageLOD
17
19
  public get crossOrigin(): IImageCrossOrigin { const { crossOrigin } = this.config; return isUndefined(crossOrigin) ? Platform.image.crossOrigin : crossOrigin }
@@ -53,7 +55,7 @@ export class LeaferImage implements ILeaferImage {
53
55
  public load(onSuccess?: IFunction, onError?: IFunction, thumbSize?: ISizeData): number {
54
56
  if (!this.loading) {
55
57
  this.loading = true
56
- Resource.tasker.add(async () => await Platform.origin.loadImage(this.getLoadUrl(thumbSize), this.crossOrigin, this).then(img => {
58
+ Resource.tasker.add(async () => await Platform.origin['load' + this.tag as 'loadImage'](this.getLoadUrl(thumbSize), this.crossOrigin, this).then(img => {
57
59
  if (thumbSize) this.setThumbView(img)
58
60
  this.setView(img)
59
61
  }).catch((e) => {
@@ -127,6 +129,10 @@ export class LeaferImage implements ILeaferImage {
127
129
  return pattern
128
130
  }
129
131
 
132
+ public render(canvas: any, x: number, y: number, width: number, height: number, _leaf: ILeaf, _paint: any, _imageScaleX: number, _imageScaleY: number): void {
133
+ canvas.drawImage(this.view, x, y, width, height)
134
+ }
135
+
130
136
  // need rewrite
131
137
  public getLoadUrl(_thumbSize?: ISizeData): string { return this.url }
132
138
  public setThumbView(_view: number): void { }
@@ -0,0 +1,10 @@
1
+ import { ILeaferVideo } from '@leafer/interface'
2
+
3
+ import { LeaferImage } from './LeaferImage'
4
+
5
+
6
+ export class LeaferVideo extends LeaferImage implements ILeaferVideo {
7
+
8
+ public get tag() { return 'Video' }
9
+
10
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { LeaferImage } from './LeaferImage'
2
+ export { LeaferFilm } from './LeaferFilm'
3
+ export { LeaferVideo } from './LeaferVideo'
2
4
  export { ImageManager } from './ImageManager'
package/types/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { ILeaferImage, InnerId, IImageLOD, IImageCrossOrigin, IObject, ILeaferImageConfig, IFunction, ILeaferImageCacheCanvas, ISizeData, IInterlace, IMatrixData, ILeaferImagePatternPaint, ICanvasPattern, ILeaferImageLevel, IImageManager } from '@leafer/interface';
1
+ import { ILeaferImage, InnerId, IImageLOD, IImageCrossOrigin, IObject, ILeaferImageConfig, IFunction, ILeaferImageCacheCanvas, ISizeData, IInterlace, IMatrixData, ILeaferImagePatternPaint, ICanvasPattern, ILeaf, ILeaferImageLevel, ILeaferFilm, ILeaferVideo, IImageManager } from '@leafer/interface';
2
2
 
3
3
  declare class LeaferImage implements ILeaferImage {
4
4
  readonly innerId: InnerId;
5
+ get tag(): string;
5
6
  get url(): string;
6
7
  lod?: IImageLOD;
7
8
  get crossOrigin(): IImageCrossOrigin;
@@ -26,6 +27,7 @@ declare class LeaferImage implements ILeaferImage {
26
27
  getFull(_filters?: IObject): any;
27
28
  getCanvas(width: number, height: number, opacity?: number, filters?: IObject, xGap?: number, yGap?: number, smooth?: boolean, interlace?: IInterlace): any;
28
29
  getPattern(canvas: any, repeat: string | null, transform?: IMatrixData, paint?: ILeaferImagePatternPaint): ICanvasPattern;
30
+ render(canvas: any, x: number, y: number, width: number, height: number, _leaf: ILeaf, _paint: any, _imageScaleX: number, _imageScaleY: number): void;
29
31
  getLoadUrl(_thumbSize?: ISizeData): string;
30
32
  setThumbView(_view: number): void;
31
33
  getThumbSize(_lod?: IImageLOD): ISizeData;
@@ -35,6 +37,14 @@ declare class LeaferImage implements ILeaferImage {
35
37
  destroy(): void;
36
38
  }
37
39
 
40
+ declare class LeaferFilm extends LeaferImage implements ILeaferFilm {
41
+ get tag(): string;
42
+ }
43
+
44
+ declare class LeaferVideo extends LeaferImage implements ILeaferVideo {
45
+ get tag(): string;
46
+ }
47
+
38
48
  declare const ImageManager: IImageManager;
39
49
 
40
- export { ImageManager, LeaferImage };
50
+ export { ImageManager, LeaferFilm, LeaferImage, LeaferVideo };