@leafer/node 1.0.0-rc.5 → 1.0.0-rc.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 +6 -6
  2. package/src/index.ts +28 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/node",
3
- "version": "1.0.0-rc.5",
3
+ "version": "1.0.0-rc.6",
4
4
  "description": "@leafer/node",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,12 +22,12 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.0.0-rc.5",
26
- "@leafer/partner": "1.0.0-rc.5",
27
- "@leafer/canvas-node": "1.0.0-rc.5",
28
- "@leafer/image-node": "1.0.0-rc.5"
25
+ "@leafer/core": "1.0.0-rc.6",
26
+ "@leafer/partner": "1.0.0-rc.6",
27
+ "@leafer/canvas-node": "1.0.0-rc.6",
28
+ "@leafer/image-node": "1.0.0-rc.6"
29
29
  },
30
30
  "devDependencies": {
31
- "@leafer/interface": "1.0.0-rc.5"
31
+ "@leafer/interface": "1.0.0-rc.6"
32
32
  }
33
33
  }
package/src/index.ts CHANGED
@@ -5,12 +5,17 @@ export * from '@leafer/partner'
5
5
  export * from '@leafer/canvas-node'
6
6
  export * from '@leafer/image-web'
7
7
 
8
- import { ICanvasType, ICreator, IExportFileType, IExportImageType, IFunction, IObject, ISkiaCanvas } from '@leafer/interface'
9
- import { Platform, Creator, InteractionBase } from '@leafer/core'
8
+ import { ICanvasType, ICreator, IExportFileType, IExportImageType, IFunction, IObject, ISkiaCanvas, ISkiaNAPICanvas } from '@leafer/interface'
9
+ import { Platform, Creator, InteractionBase, FileHelper } from '@leafer/core'
10
10
 
11
11
  import { LeaferCanvas } from '@leafer/canvas-node'
12
12
  import { LeaferImage } from '@leafer/image-node'
13
13
 
14
+ import { writeFileSync } from 'fs'
15
+
16
+
17
+ const { mineType, fileType } = FileHelper
18
+
14
19
 
15
20
  Object.assign(Creator, {
16
21
  canvas: (options?, manager?) => new LeaferCanvas(options, manager),
@@ -22,18 +27,38 @@ Object.assign(Creator, {
22
27
 
23
28
 
24
29
  export function useCanvas(canvasType: ICanvasType, power: IObject): void {
30
+
31
+ Platform.canvasType = canvasType
32
+
25
33
  if (!Platform.origin) {
26
34
  if (canvasType === 'skia') {
35
+
27
36
  const { Canvas, loadImage } = power
28
37
  Platform.origin = {
29
38
  createCanvas: (width: number, height: number, format?: string) => new Canvas(width, height, format),
30
39
  canvasToDataURL: (canvas: ISkiaCanvas, type?: IExportImageType, quality?: number) => canvas.toDataURLSync(type, { quality }),
31
40
  canvasToBolb: (canvas: ISkiaCanvas, type?: IExportFileType, quality?: number) => canvas.toBuffer(type, { quality }),
32
- canvasSaveAs: (canvas: ISkiaCanvas, filename: string, quality?: any) => canvas.saveAs(filename, { quality }),
41
+ canvasSaveAs: (canvas: ISkiaCanvas, filename: string, quality?: number) => canvas.saveAs(filename, { quality }),
42
+ loadImage
43
+ }
44
+
45
+ Platform.roundRectPatch = true
46
+
47
+ } else if (canvasType === 'napi') {
48
+
49
+ const { Canvas, loadImage } = power
50
+ Platform.origin = {
51
+ createCanvas: (width: number, height: number, format?: string) => new Canvas(width, height, format),
52
+ canvasToDataURL: (canvas: ISkiaNAPICanvas, type?: IExportImageType, quality?: number) => canvas.toDataURL(mineType(type), quality),
53
+ canvasToBolb: async (canvas: ISkiaNAPICanvas, type?: IExportFileType, quality?: number) => canvas.toBuffer(mineType(type), quality),
54
+ canvasSaveAs: async (canvas: ISkiaNAPICanvas, filename: string, quality?: number) => writeFileSync(filename, canvas.toBuffer(mineType(fileType(filename)), quality)),
33
55
  loadImage
34
56
  }
57
+
35
58
  }
36
59
 
60
+ Platform.ellipseToCurve = true
61
+
37
62
  Platform.event = {
38
63
  stopDefault(_origin: IObject): void { },
39
64
  stopNow(_origin: IObject): void { },