@codehz/draw-call 0.1.0 → 0.1.1

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/node.d.mts ADDED
@@ -0,0 +1,12 @@
1
+ import { n as DrawCallCanvas, t as CanvasOptions } from "./canvas-BYrCq8eS.mjs";
2
+
3
+ //#region src/node.d.ts
4
+ /**
5
+ * 创建适用于 Node.js/Bun 环境的 Canvas
6
+ *
7
+ * 此函数需要 @napi-rs/canvas 作为依赖
8
+ * 安装: bun add @napi-rs/canvas
9
+ */
10
+ declare function createCanvas(options: Omit<CanvasOptions, "canvas">): DrawCallCanvas;
11
+ //#endregion
12
+ export { createCanvas };
package/node.mjs ADDED
@@ -0,0 +1,47 @@
1
+ import { n as computeLayout, r as createCanvasMeasureContext, t as renderNode } from "./engine-C88lMGbX.mjs";
2
+ import { createCanvas as createCanvas$1 } from "@napi-rs/canvas";
3
+
4
+ //#region src/node.ts
5
+ /**
6
+ * 创建适用于 Node.js/Bun 环境的 Canvas
7
+ *
8
+ * 此函数需要 @napi-rs/canvas 作为依赖
9
+ * 安装: bun add @napi-rs/canvas
10
+ */
11
+ function createCanvas(options) {
12
+ const { width, height, pixelRatio = 1 } = options;
13
+ const canvas = createCanvas$1(width * pixelRatio, height * pixelRatio);
14
+ const ctx = canvas.getContext("2d");
15
+ if (pixelRatio !== 1) ctx.scale(pixelRatio, pixelRatio);
16
+ const measureCtx = createCanvasMeasureContext(ctx);
17
+ return {
18
+ width,
19
+ height,
20
+ pixelRatio,
21
+ render(element) {
22
+ const layoutTree = computeLayout(element, measureCtx, {
23
+ minWidth: 0,
24
+ maxWidth: width,
25
+ minHeight: 0,
26
+ maxHeight: height
27
+ });
28
+ renderNode(ctx, layoutTree);
29
+ return layoutTree;
30
+ },
31
+ clear() {
32
+ ctx.clearRect(0, 0, width, height);
33
+ },
34
+ getContext() {
35
+ return ctx;
36
+ },
37
+ toDataURL(type, quality) {
38
+ return canvas.toDataURL(type, quality);
39
+ },
40
+ async toBuffer(type = "image/png") {
41
+ return canvas.toBuffer(type);
42
+ }
43
+ };
44
+ }
45
+
46
+ //#endregion
47
+ export { createCanvas };
package/package.json CHANGED
@@ -25,19 +25,33 @@
25
25
  "optionalDependencies": {
26
26
  "@napi-rs/canvas": "^0.1.88"
27
27
  },
28
- "version": "0.1.0",
28
+ "version": "0.1.1",
29
29
  "main": "./index.cjs",
30
30
  "types": "./index.d.cts",
31
31
  "exports": {
32
- "require": {
33
- "types": "./index.d.cts",
34
- "import": "./index.cjs",
35
- "default": "./index.cjs"
32
+ ".": {
33
+ "require": {
34
+ "types": "./index.d.cts",
35
+ "import": "./index.cjs",
36
+ "default": "./index.cjs"
37
+ },
38
+ "import": {
39
+ "types": "./index.d.mts",
40
+ "import": "./index.mjs",
41
+ "default": "./index.mjs"
42
+ }
36
43
  },
37
- "import": {
38
- "types": "./index.d.mts",
39
- "import": "./index.mjs",
40
- "default": "./index.mjs"
44
+ "./node": {
45
+ "require": {
46
+ "types": "./node.d.cts",
47
+ "import": "./node.cjs",
48
+ "default": "./node.cjs"
49
+ },
50
+ "import": {
51
+ "types": "./node.d.mts",
52
+ "import": "./node.mjs",
53
+ "default": "./node.mjs"
54
+ }
41
55
  }
42
56
  }
43
57
  }