@leafer-ui/node 1.5.2 → 1.6.0
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/dist/node.cjs +68 -71
- package/dist/node.cjs.map +1 -1
- package/dist/node.esm.js +68 -71
- package/dist/node.esm.js.map +1 -1
- package/dist/node.esm.min.js +1 -1
- package/dist/node.esm.min.js.map +1 -1
- package/dist/node.min.cjs +1 -1
- package/dist/node.min.cjs.map +1 -1
- package/package.json +12 -11
- package/src/core.ts +73 -0
- package/src/index.ts +2 -2
- package/types/index.d.ts +8 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "@leafer-ui/node",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,15 +32,16 @@
|
|
|
32
32
|
"leaferjs"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@leafer/core": "1.
|
|
36
|
-
"@leafer/node": "1.
|
|
37
|
-
"@leafer/
|
|
38
|
-
"@leafer/
|
|
39
|
-
"@leafer
|
|
40
|
-
"@leafer-ui/
|
|
41
|
-
"@leafer-ui/
|
|
42
|
-
"@leafer-ui/
|
|
43
|
-
"@leafer-
|
|
44
|
-
"@leafer-in/
|
|
35
|
+
"@leafer/core": "1.6.0",
|
|
36
|
+
"@leafer/canvas-node": "1.6.0",
|
|
37
|
+
"@leafer/image-node": "1.6.0",
|
|
38
|
+
"@leafer/partner": "1.6.0",
|
|
39
|
+
"@leafer/interface": "1.6.0",
|
|
40
|
+
"@leafer-ui/draw": "1.6.0",
|
|
41
|
+
"@leafer-ui/core": "1.6.0",
|
|
42
|
+
"@leafer-ui/partner": "1.6.0",
|
|
43
|
+
"@leafer-ui/interface": "1.6.0",
|
|
44
|
+
"@leafer-in/export": "1.6.0",
|
|
45
|
+
"@leafer-in/interface": "1.6.0"
|
|
45
46
|
}
|
|
46
47
|
}
|
package/src/core.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export * from '@leafer/core'
|
|
2
|
+
|
|
3
|
+
export * from '@leafer/canvas-node'
|
|
4
|
+
export * from '@leafer/image-node'
|
|
5
|
+
|
|
6
|
+
import { ICanvasType, ICreator, IExportFileType, IExportImageType, IFunction, IObject, ISkiaCanvas, ISkiaNAPICanvas } from '@leafer/interface'
|
|
7
|
+
import { Platform, Creator, FileHelper, defineKey } from '@leafer/core'
|
|
8
|
+
|
|
9
|
+
import { LeaferCanvas } from '@leafer/canvas-node'
|
|
10
|
+
import { LeaferImage } from '@leafer/image-node'
|
|
11
|
+
|
|
12
|
+
import { writeFileSync } from 'fs'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const { mineType, fileType } = FileHelper
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
Object.assign(Creator, {
|
|
19
|
+
canvas: (options?, manager?) => new LeaferCanvas(options, manager),
|
|
20
|
+
image: (options) => new LeaferImage(options)
|
|
21
|
+
} as ICreator)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export function useCanvas(canvasType: ICanvasType, power: IObject): void {
|
|
25
|
+
|
|
26
|
+
Platform.canvasType = canvasType
|
|
27
|
+
|
|
28
|
+
if (!Platform.origin) {
|
|
29
|
+
if (canvasType === 'skia') {
|
|
30
|
+
|
|
31
|
+
const { Canvas, loadImage } = power
|
|
32
|
+
Platform.origin = {
|
|
33
|
+
createCanvas: (width: number, height: number, format?: string) => new Canvas(width, height, format),
|
|
34
|
+
canvasToDataURL: (canvas: ISkiaCanvas, type?: IExportImageType, quality?: number) => canvas.toDataURLSync(type, { quality }),
|
|
35
|
+
canvasToBolb: (canvas: ISkiaCanvas, type?: IExportFileType, quality?: number) => canvas.toBuffer(type, { quality }),
|
|
36
|
+
canvasSaveAs: (canvas: ISkiaCanvas, filename: string, quality?: number) => canvas.saveAs(filename, { quality }),
|
|
37
|
+
download(_url: string, _filename: string): Promise<void> { return undefined },
|
|
38
|
+
loadImage(src: any) { return loadImage(Platform.image.getRealURL(src)) }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Platform.roundRectPatch = true
|
|
42
|
+
|
|
43
|
+
} else if (canvasType === 'napi') {
|
|
44
|
+
|
|
45
|
+
const { Canvas, loadImage } = power
|
|
46
|
+
Platform.origin = {
|
|
47
|
+
createCanvas: (width: number, height: number, format?: string) => new Canvas(width, height, format),
|
|
48
|
+
canvasToDataURL: (canvas: ISkiaNAPICanvas, type?: IExportImageType, quality?: number) => canvas.toDataURL(mineType(type), quality),
|
|
49
|
+
canvasToBolb: async (canvas: ISkiaNAPICanvas, type?: IExportFileType, quality?: number) => canvas.toBuffer(mineType(type), quality),
|
|
50
|
+
canvasSaveAs: async (canvas: ISkiaNAPICanvas, filename: string, quality?: number) => writeFileSync(filename, canvas.toBuffer(mineType(fileType(filename)), quality)),
|
|
51
|
+
download(_url: string, _filename: string): Promise<void> { return undefined },
|
|
52
|
+
loadImage(src: any) { return loadImage(Platform.image.getRealURL(src)) }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Platform.ellipseToCurve = true
|
|
58
|
+
|
|
59
|
+
Platform.event = {
|
|
60
|
+
stopDefault(_origin: IObject): void { },
|
|
61
|
+
stopNow(_origin: IObject): void { },
|
|
62
|
+
stop(_origin: IObject): void { }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
Platform.canvas = Creator.canvas()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
Platform.name = 'node'
|
|
70
|
+
Platform.backgrounder = true
|
|
71
|
+
Platform.requestRender = function (render: IFunction): void { setTimeout(render, 16) }
|
|
72
|
+
defineKey(Platform, 'devicePixelRatio', { get() { return 1 } })
|
|
73
|
+
Platform.conicGradientSupport = true
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '@leafer-ui/interface'
|
|
2
2
|
|
|
3
|
-
export * from '
|
|
3
|
+
export * from './core'
|
|
4
4
|
export * from '@leafer/partner'
|
|
5
5
|
|
|
6
6
|
export * from '@leafer-ui/core'
|
|
@@ -9,7 +9,7 @@ export * from '@leafer-ui/partner'
|
|
|
9
9
|
export * from '@leafer-in/export'
|
|
10
10
|
|
|
11
11
|
import { ICreator } from '@leafer/interface'
|
|
12
|
-
import { Creator, LeaferCanvas } from '
|
|
12
|
+
import { Creator, LeaferCanvas } from './core'
|
|
13
13
|
import { InteractionBase, HitCanvasManager } from '@leafer-ui/core'
|
|
14
14
|
|
|
15
15
|
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export * from '@leafer-ui/interface';
|
|
2
|
-
|
|
2
|
+
import { ICanvasType, IObject } from '@leafer/interface';
|
|
3
3
|
export * from '@leafer/partner';
|
|
4
4
|
export * from '@leafer-ui/core';
|
|
5
5
|
export * from '@leafer-ui/partner';
|
|
6
6
|
export * from '@leafer-in/export';
|
|
7
|
+
export * from '@leafer/core';
|
|
8
|
+
export * from '@leafer/canvas-node';
|
|
9
|
+
export * from '@leafer/image-node';
|
|
10
|
+
|
|
11
|
+
declare function useCanvas(canvasType: ICanvasType, power: IObject): void;
|
|
12
|
+
|
|
13
|
+
export { useCanvas };
|