@leafer/image 1.0.0-rc.4 → 1.0.0-rc.5

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.0.0-rc.4",
3
+ "version": "1.0.0-rc.5",
4
4
  "description": "@leafer/image",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,10 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/task": "1.0.0-rc.4",
26
- "@leafer/platform": "1.0.0-rc.4"
25
+ "@leafer/task": "1.0.0-rc.5",
26
+ "@leafer/file": "1.0.0-rc.5",
27
+ "@leafer/platform": "1.0.0-rc.5"
27
28
  },
28
29
  "devDependencies": {
29
- "@leafer/interface": "1.0.0-rc.4"
30
+ "@leafer/interface": "1.0.0-rc.5"
30
31
  }
31
32
  }
@@ -1,7 +1,9 @@
1
- import { IImageManager, ILeaferImageConfig, ILeaferImage } from '@leafer/interface'
1
+ import { IImageManager, ILeaferImageConfig, ILeaferImage, IExportFileType } from '@leafer/interface'
2
2
  import { Creator } from '@leafer/platform'
3
+ import { FileHelper } from '@leafer/file'
3
4
  import { TaskProcessor } from '@leafer/task'
4
5
 
6
+
5
7
  export const ImageManager: IImageManager = {
6
8
 
7
9
  map: {},
@@ -42,6 +44,21 @@ export const ImageManager: IImageManager = {
42
44
  }
43
45
  },
44
46
 
47
+ isPixel(config: ILeaferImageConfig): boolean {
48
+ return FileHelper.opacityTypes.some(item => I.isFormat(item, config))
49
+ },
50
+
51
+ isFormat(format: IExportFileType, config: ILeaferImageConfig): boolean {
52
+ if (config.format === format) return true
53
+ const { url } = config
54
+ if (url.startsWith('data:')) {
55
+ if (url.startsWith('data:' + FileHelper.mineType(format))) return true
56
+ } else {
57
+ if (url.includes('.' + format) || url.includes('.' + FileHelper.upperCaseTypeMap[format])) return true
58
+ }
59
+ return false
60
+ },
61
+
45
62
  destroy(): void {
46
63
  I.map = {}
47
64
  }
@@ -34,13 +34,7 @@ export class LeaferImage implements ILeaferImage {
34
34
  constructor(config: ILeaferImageConfig) {
35
35
  this.innerId = create(IMAGE)
36
36
  this.config = config || { url: '' }
37
- const { url } = config
38
- if (url.startsWith('data:')) {
39
- if (url.startsWith('data:image/svg')) this.isSVG = true
40
- } else {
41
- if (url.includes('.svg')) this.isSVG = true
42
- }
43
- if (this.config.format === 'svg') this.isSVG = true
37
+ this.isSVG = ImageManager.isFormat('svg', config)
44
38
  }
45
39
 
46
40
  public load(onSuccess: IFunction, onError: IFunction): number {