@leafer/web 1.0.0-rc.2 → 1.0.0-rc.20

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/web",
3
- "version": "1.0.0-rc.2",
3
+ "version": "1.0.0-rc.20",
4
4
  "description": "@leafer/web",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,13 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.0.0-rc.2",
26
- "@leafer/partner": "1.0.0-rc.2",
27
- "@leafer/canvas-web": "1.0.0-rc.2",
28
- "@leafer/interaction-web": "1.0.0-rc.2",
29
- "@leafer/image-web": "1.0.0-rc.2"
25
+ "@leafer/core": "1.0.0-rc.20",
26
+ "@leafer/canvas-web": "1.0.0-rc.20",
27
+ "@leafer/image-web": "1.0.0-rc.20"
30
28
  },
31
29
  "devDependencies": {
32
- "@leafer/interface": "1.0.0-rc.2"
30
+ "@leafer/interface": "1.0.0-rc.20"
33
31
  }
34
32
  }
package/src/index.ts CHANGED
@@ -1,16 +1,13 @@
1
1
  export * from '@leafer/core'
2
- export * from '@leafer/partner'
3
2
 
4
3
  export * from '@leafer/canvas-web'
5
4
  export * from '@leafer/image-web'
6
- export * from '@leafer/interaction-web'
7
5
 
8
6
  import { ICreator, IFunction, IExportImageType, IExportFileType, IObject, ICanvasType } from '@leafer/interface'
9
7
  import { Platform, Creator, FileHelper } from '@leafer/core'
10
8
 
11
9
  import { LeaferCanvas } from '@leafer/canvas-web'
12
10
  import { LeaferImage } from '@leafer/image-web'
13
- import { Interaction } from '@leafer/interaction-web'
14
11
 
15
12
 
16
13
  const { mineType, fileType } = FileHelper
@@ -18,10 +15,7 @@ const { mineType, fileType } = FileHelper
18
15
 
19
16
  Object.assign(Creator, {
20
17
  canvas: (options?, manager?) => new LeaferCanvas(options, manager),
21
- image: (options) => new LeaferImage(options),
22
- hitCanvas: (options?, manager?) => new LeaferCanvas(options, manager),
23
-
24
- interaction: (target, canvas, selector, options?) => new Interaction(target, canvas, selector, options),
18
+ image: (options) => new LeaferImage(options)
25
19
  } as ICreator)
26
20
 
27
21
 
@@ -36,9 +30,13 @@ export function useCanvas(_canvasType: ICanvasType, _power?: IObject): void {
36
30
  canvasToDataURL: (canvas: HTMLCanvasElement, type?: IExportImageType, quality?: number) => canvas.toDataURL(mineType(type), quality),
37
31
  canvasToBolb: (canvas: HTMLCanvasElement, type?: IExportFileType, quality?: number) => new Promise((resolve) => canvas.toBlob(resolve, mineType(type), quality)),
38
32
  canvasSaveAs: (canvas: HTMLCanvasElement, filename: string, quality?: any) => {
33
+ const url = canvas.toDataURL(mineType(fileType(filename)), quality)
34
+ return Platform.origin.download(url, filename)
35
+ },
36
+ download(url: string, filename: string,): Promise<void> {
39
37
  return new Promise((resolve) => {
40
38
  let el = document.createElement('a')
41
- el.href = canvas.toDataURL(mineType(fileType(filename)), quality)
39
+ el.href = url
42
40
  el.download = filename
43
41
  document.body.appendChild(el)
44
42
  el.click()
@@ -49,16 +47,25 @@ export function useCanvas(_canvasType: ICanvasType, _power?: IObject): void {
49
47
  loadImage(src: any): Promise<HTMLImageElement> {
50
48
  return new Promise((resolve, reject) => {
51
49
  const img = new Image()
52
- img.setAttribute('crossOrigin', 'anonymous')
53
- img.crossOrigin = 'anonymous'
50
+ const { suffix, crossOrigin } = Platform.image
51
+ if (crossOrigin) {
52
+ img.setAttribute('crossOrigin', crossOrigin)
53
+ img.crossOrigin = crossOrigin
54
+ }
54
55
  img.onload = () => { resolve(img) }
55
56
  img.onerror = (e) => { reject(e) }
56
- if (!src.startsWith('data:') && Platform.imageSuffix) src += (src.includes("?") ? "&" : "?") + Platform.imageSuffix
57
+ if (!src.startsWith('data:') && !src.startsWith('blob:') && suffix) src += (src.includes("?") ? "&" : "?") + suffix
57
58
  img.src = src
58
59
  })
59
60
  }
60
61
  }
61
62
 
63
+ Platform.event = {
64
+ stopDefault(origin: Event): void { origin.preventDefault() },
65
+ stopNow(origin: Event): void { origin.stopImmediatePropagation() },
66
+ stop(origin: Event): void { origin.stopPropagation() }
67
+ }
68
+
62
69
  Platform.canvas = Creator.canvas()
63
70
  Platform.conicGradientSupport = !!Platform.canvas.context.createConicGradient
64
71
  }
@@ -66,8 +73,7 @@ export function useCanvas(_canvasType: ICanvasType, _power?: IObject): void {
66
73
  Platform.name = 'web'
67
74
  Platform.isMobile = 'ontouchstart' in window
68
75
  Platform.requestRender = function (render: IFunction): void { window.requestAnimationFrame(render) }
69
- Platform.devicePixelRatio = devicePixelRatio
70
- Platform.realtimeLayout = true
76
+ Platform.devicePixelRatio = Math.max(1, devicePixelRatio)
71
77
 
72
78
 
73
79
  // same as worker
package/types/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  export * from '@leafer/core';
2
- export * from '@leafer/partner';
3
2
  export * from '@leafer/canvas-web';
4
3
  export * from '@leafer/image-web';
5
- export * from '@leafer/interaction-web';
6
4
  import { ICanvasType, IObject } from '@leafer/interface';
7
5
 
8
6
  declare function useCanvas(_canvasType: ICanvasType, _power?: IObject): void;