@leafer/node 1.0.0-beta.4 → 1.0.0-beta.6

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.
Files changed (2) hide show
  1. package/package.json +12 -2
  2. package/src/index.ts +20 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/node",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.6",
4
4
  "description": "@leafer/node",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -17,5 +17,15 @@
17
17
  "keywords": [
18
18
  "leafer",
19
19
  "leaferjs"
20
- ]
20
+ ],
21
+ "dependencies": {
22
+ "@leafer/core": "1.0.0-beta.6",
23
+ "@leafer/partner": "1.0.0-beta.6",
24
+ "@leafer/canvas-node": "1.0.0-beta.6",
25
+ "@leafer/interaction": "1.0.0-beta.6",
26
+ "@leafer/image-node": "1.0.0-beta.6"
27
+ },
28
+ "devDependencies": {
29
+ "@leafer/interface": "1.0.0-beta.6"
30
+ }
21
31
  }
package/src/index.ts CHANGED
@@ -4,7 +4,7 @@ export * from '@leafer/partner'
4
4
  export * from '@leafer/canvas-node'
5
5
  export * from '@leafer/image-web'
6
6
 
7
- import { ICreator, IFunction, IObject } from '@leafer/interface'
7
+ import { ICanvasType, ICreator, IExportFileType, IExportImageType, IFunction, IObject, ISkiaCanvas } from '@leafer/interface'
8
8
  import { Platform, Creator } from '@leafer/core'
9
9
 
10
10
  import { LeaferCanvas } from '@leafer/canvas-node'
@@ -20,15 +20,24 @@ Object.assign(Creator, {
20
20
  interaction: (target, canvas, selector, options?) => { return new InteractionBase(target, canvas, selector, options) }
21
21
  } as ICreator)
22
22
 
23
- Platform.requestRender = function (render: IFunction): void { setTimeout(render) }
24
- Platform.devicePixelRatio = devicePixelRatio
25
- Platform.conicGradientSupport = true
26
23
 
27
- export function useSkiaCanvas(skia: IObject): void {
28
- const { Canvas, loadImage } = skia
29
- Platform.origin = {
30
- createCanvas: (width: number, height: number) => new Canvas(width, height),
31
- loadImage
24
+ export function useCanvas(canvasType: ICanvasType, power: IObject): void {
25
+ if (!Platform.origin) {
26
+ if (canvasType === 'skia') {
27
+ const { Canvas, loadImage } = power
28
+ Platform.origin = {
29
+ createCanvas: (width: number, height: number, format?: string) => new Canvas(width, height, format),
30
+ canvasToDataURL: (canvas: ISkiaCanvas, type?: IExportImageType, quality?: number) => canvas.toDataURLSync(type, { quality }),
31
+ canvasToBolb: (canvas: ISkiaCanvas, type?: IExportFileType, quality?: number) => canvas.toBuffer(type, { quality }),
32
+ canvasSaveAs: (canvas: ISkiaCanvas, filename: string, quality?: any) => canvas.saveAs(filename, { quality }),
33
+ loadImage
34
+ }
35
+ }
36
+ Platform.canvas = Creator.canvas()
32
37
  }
33
- Platform.canvas = Creator.canvas()
34
- }
38
+ }
39
+
40
+ Platform.requestRender = function (render: IFunction): void { setTimeout(render) }
41
+ Platform.devicePixelRatio = 1
42
+ Platform.conicGradientSupport = true
43
+ Platform.realtimeLayout = true