@codehz/draw-call 0.5.1 → 0.5.3
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/{browser → dist/browser}/index.cjs +2 -40
- package/{node → dist/browser}/index.d.cts +1 -1
- package/dist/browser/index.d.ts +454 -0
- package/{browser → dist/browser}/index.js +1 -39
- package/{node → dist/node}/index.cjs +2 -40
- package/dist/node/index.d.cts +454 -0
- package/{node → dist/node}/index.d.mts +1 -1
- package/{node → dist/node}/index.mjs +1 -40
- package/examples/card.ts +1 -1
- package/examples/customdraw-basic.ts +1 -1
- package/examples/customdraw.ts +1 -1
- package/examples/demo.html +114 -0
- package/examples/demo.ts +1 -1
- package/examples/image-smoothing.ts +1 -1
- package/examples/richtext.ts +1 -1
- package/examples/transform.ts +1 -1
- package/package.json +55 -32
- package/browser/index.d.cts +0 -998
- package/browser/index.d.ts +0 -998
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { DOMMatrix, Path2D, createCanvas as createCanvas$1 } from "@napi-rs/canvas";
|
|
2
|
-
|
|
3
2
|
//#region src/compat/index.ts
|
|
4
3
|
function createRawCanvas(width, height) {
|
|
5
4
|
return createCanvas$1(width, height);
|
|
6
5
|
}
|
|
7
|
-
|
|
8
6
|
//#endregion
|
|
9
7
|
//#region src/types/base.ts
|
|
10
8
|
function linearGradient(angle, ...stops) {
|
|
@@ -75,7 +73,6 @@ function normalizeBorderRadius(value) {
|
|
|
75
73
|
];
|
|
76
74
|
return value;
|
|
77
75
|
}
|
|
78
|
-
|
|
79
76
|
//#endregion
|
|
80
77
|
//#region src/layout/components/box.ts
|
|
81
78
|
/**
|
|
@@ -188,7 +185,6 @@ function measureBoxSize(element, ctx, availableWidth, measureChild) {
|
|
|
188
185
|
height: typeof element.height === "number" ? element.height : intrinsicHeight
|
|
189
186
|
};
|
|
190
187
|
}
|
|
191
|
-
|
|
192
188
|
//#endregion
|
|
193
189
|
//#region src/layout/components/customDraw.ts
|
|
194
190
|
/**
|
|
@@ -205,7 +201,6 @@ function measureCustomDrawSize(element, ctx, availableWidth, measureChild) {
|
|
|
205
201
|
height: 0
|
|
206
202
|
};
|
|
207
203
|
}
|
|
208
|
-
|
|
209
204
|
//#endregion
|
|
210
205
|
//#region src/layout/components/image.ts
|
|
211
206
|
/**
|
|
@@ -231,7 +226,6 @@ function measureImageSize(element, _ctx, _availableWidth) {
|
|
|
231
226
|
height: 0
|
|
232
227
|
};
|
|
233
228
|
}
|
|
234
|
-
|
|
235
229
|
//#endregion
|
|
236
230
|
//#region src/layout/components/richtext.ts
|
|
237
231
|
/**
|
|
@@ -399,7 +393,6 @@ function wrapRichText(ctx, spans, maxWidth, lineHeightScale = 1.2, elementStyle
|
|
|
399
393
|
}];
|
|
400
394
|
return lines;
|
|
401
395
|
}
|
|
402
|
-
|
|
403
396
|
//#endregion
|
|
404
397
|
//#region src/layout/components/stack.ts
|
|
405
398
|
/**
|
|
@@ -436,7 +429,6 @@ function measureStackSize(element, ctx, availableWidth, measureChild) {
|
|
|
436
429
|
height: typeof element.height === "number" ? element.height : intrinsicHeight
|
|
437
430
|
};
|
|
438
431
|
}
|
|
439
|
-
|
|
440
432
|
//#endregion
|
|
441
433
|
//#region src/layout/components/svg.ts
|
|
442
434
|
/**
|
|
@@ -470,7 +462,6 @@ function measureSvgSize(element, _ctx, _availableWidth) {
|
|
|
470
462
|
height: 0
|
|
471
463
|
};
|
|
472
464
|
}
|
|
473
|
-
|
|
474
465
|
//#endregion
|
|
475
466
|
//#region src/render/utils/font.ts
|
|
476
467
|
/**
|
|
@@ -481,7 +472,6 @@ function measureSvgSize(element, _ctx, _availableWidth) {
|
|
|
481
472
|
function buildFontString(font) {
|
|
482
473
|
return `${font.style ?? "normal"} ${font.weight ?? "normal"} ${font.size ?? 16}px ${font.family ?? "sans-serif"}`;
|
|
483
474
|
}
|
|
484
|
-
|
|
485
475
|
//#endregion
|
|
486
476
|
//#region src/layout/utils/measure.ts
|
|
487
477
|
function createCanvasMeasureContext(ctx) {
|
|
@@ -573,7 +563,6 @@ function truncateText(ctx, text, maxWidth, font, ellipsis = "...") {
|
|
|
573
563
|
offset
|
|
574
564
|
};
|
|
575
565
|
}
|
|
576
|
-
|
|
577
566
|
//#endregion
|
|
578
567
|
//#region src/layout/components/text.ts
|
|
579
568
|
/**
|
|
@@ -599,7 +588,6 @@ function measureTextSize(element, ctx, availableWidth) {
|
|
|
599
588
|
height: Math.max(height, lineHeightPx)
|
|
600
589
|
};
|
|
601
590
|
}
|
|
602
|
-
|
|
603
591
|
//#endregion
|
|
604
592
|
//#region src/layout/components/transform.ts
|
|
605
593
|
/**
|
|
@@ -610,7 +598,6 @@ function measureTextSize(element, ctx, availableWidth) {
|
|
|
610
598
|
function measureTransformSize(element, ctx, availableWidth, measureIntrinsicSize) {
|
|
611
599
|
return measureIntrinsicSize(element.children, ctx, availableWidth);
|
|
612
600
|
}
|
|
613
|
-
|
|
614
601
|
//#endregion
|
|
615
602
|
//#region src/layout/components/index.ts
|
|
616
603
|
/**
|
|
@@ -632,7 +619,6 @@ function measureIntrinsicSize(element, ctx, availableWidth) {
|
|
|
632
619
|
};
|
|
633
620
|
}
|
|
634
621
|
}
|
|
635
|
-
|
|
636
622
|
//#endregion
|
|
637
623
|
//#region src/layout/utils/offset.ts
|
|
638
624
|
/**
|
|
@@ -645,7 +631,6 @@ function applyOffset(node, dx, dy) {
|
|
|
645
631
|
node.layout.contentY += dy;
|
|
646
632
|
for (const child of node.children) applyOffset(child, dx, dy);
|
|
647
633
|
}
|
|
648
|
-
|
|
649
634
|
//#endregion
|
|
650
635
|
//#region src/types/layout.ts
|
|
651
636
|
function resolveSize(size, available, auto) {
|
|
@@ -660,7 +645,6 @@ function sizeNeedsParent(size) {
|
|
|
660
645
|
if (typeof size === "string" && size.endsWith("%")) return true;
|
|
661
646
|
return false;
|
|
662
647
|
}
|
|
663
|
-
|
|
664
648
|
//#endregion
|
|
665
649
|
//#region src/layout/engine.ts
|
|
666
650
|
/**
|
|
@@ -1078,7 +1062,6 @@ function computeLayoutImpl(element, ctx, constraints, x = 0, y = 0) {
|
|
|
1078
1062
|
}
|
|
1079
1063
|
return node;
|
|
1080
1064
|
}
|
|
1081
|
-
|
|
1082
1065
|
//#endregion
|
|
1083
1066
|
//#region src/render/utils/colors.ts
|
|
1084
1067
|
function isGradientDescriptor$1(color) {
|
|
@@ -1114,7 +1097,6 @@ function resolveColor$1(ctx, color, x, y, width, height) {
|
|
|
1114
1097
|
if (isGradientDescriptor$1(color)) return resolveGradient$1(ctx, color, x, y, width, height);
|
|
1115
1098
|
return color;
|
|
1116
1099
|
}
|
|
1117
|
-
|
|
1118
1100
|
//#endregion
|
|
1119
1101
|
//#region src/render/utils/shadows.ts
|
|
1120
1102
|
function applyShadow$1(ctx, shadow) {
|
|
@@ -1136,7 +1118,6 @@ function clearShadow$1(ctx) {
|
|
|
1136
1118
|
ctx.shadowBlur = 0;
|
|
1137
1119
|
ctx.shadowColor = "transparent";
|
|
1138
1120
|
}
|
|
1139
|
-
|
|
1140
1121
|
//#endregion
|
|
1141
1122
|
//#region src/render/utils/shapes.ts
|
|
1142
1123
|
function roundRectPath(ctx, x, y, width, height, radius) {
|
|
@@ -1153,7 +1134,6 @@ function roundRectPath(ctx, x, y, width, height, radius) {
|
|
|
1153
1134
|
ctx.quadraticCurveTo(x, y, x + tl, y);
|
|
1154
1135
|
ctx.closePath();
|
|
1155
1136
|
}
|
|
1156
|
-
|
|
1157
1137
|
//#endregion
|
|
1158
1138
|
//#region src/render/components/box.ts
|
|
1159
1139
|
function renderBox(ctx, node) {
|
|
@@ -1182,7 +1162,6 @@ function renderBox(ctx, node) {
|
|
|
1182
1162
|
}
|
|
1183
1163
|
if (element.opacity !== void 0 && element.opacity < 1) ctx.globalAlpha = 1;
|
|
1184
1164
|
}
|
|
1185
|
-
|
|
1186
1165
|
//#endregion
|
|
1187
1166
|
//#region src/render/components/ProxiedCanvasContext.ts
|
|
1188
1167
|
/**
|
|
@@ -1300,7 +1279,6 @@ function createProxiedCanvasContext(ctx, baseTransform) {
|
|
|
1300
1279
|
}
|
|
1301
1280
|
});
|
|
1302
1281
|
}
|
|
1303
|
-
|
|
1304
1282
|
//#endregion
|
|
1305
1283
|
//#region src/render/components/customDraw.ts
|
|
1306
1284
|
/**
|
|
@@ -1328,7 +1306,6 @@ function renderCustomDraw(ctx, node) {
|
|
|
1328
1306
|
proxyCtx.destroy();
|
|
1329
1307
|
ctx.restore();
|
|
1330
1308
|
}
|
|
1331
|
-
|
|
1332
1309
|
//#endregion
|
|
1333
1310
|
//#region src/render/components/image.ts
|
|
1334
1311
|
function renderImage(ctx, node) {
|
|
@@ -1414,7 +1391,6 @@ function renderImage(ctx, node) {
|
|
|
1414
1391
|
}
|
|
1415
1392
|
if (element.opacity !== void 0 && element.opacity < 1) ctx.globalAlpha = 1;
|
|
1416
1393
|
}
|
|
1417
|
-
|
|
1418
1394
|
//#endregion
|
|
1419
1395
|
//#region src/render/components/richtext.ts
|
|
1420
1396
|
function renderRichText(ctx, node) {
|
|
@@ -1465,7 +1441,6 @@ function renderRichText(ctx, node) {
|
|
|
1465
1441
|
currentY += line.height;
|
|
1466
1442
|
}
|
|
1467
1443
|
}
|
|
1468
|
-
|
|
1469
1444
|
//#endregion
|
|
1470
1445
|
//#region src/render/components/svg.ts
|
|
1471
1446
|
function isGradientDescriptor(color) {
|
|
@@ -1737,7 +1712,6 @@ function renderSvg(ctx, node) {
|
|
|
1737
1712
|
for (const child of element.children) renderSvgChild(ctx, child, transform, bounds, baseTransform);
|
|
1738
1713
|
ctx.restore();
|
|
1739
1714
|
}
|
|
1740
|
-
|
|
1741
1715
|
//#endregion
|
|
1742
1716
|
//#region src/render/components/text.ts
|
|
1743
1717
|
function renderText(ctx, node) {
|
|
@@ -1772,7 +1746,6 @@ function renderText(ctx, node) {
|
|
|
1772
1746
|
}
|
|
1773
1747
|
if (element.shadow) clearShadow$1(ctx);
|
|
1774
1748
|
}
|
|
1775
|
-
|
|
1776
1749
|
//#endregion
|
|
1777
1750
|
//#region src/render/components/transform.ts
|
|
1778
1751
|
/**
|
|
@@ -1848,7 +1821,6 @@ function renderTransform(ctx, node) {
|
|
|
1848
1821
|
renderNode(ctx, childNode);
|
|
1849
1822
|
ctx.restore();
|
|
1850
1823
|
}
|
|
1851
|
-
|
|
1852
1824
|
//#endregion
|
|
1853
1825
|
//#region src/render/index.ts
|
|
1854
1826
|
function renderNode(ctx, node) {
|
|
@@ -1888,7 +1860,6 @@ function renderNode(ctx, node) {
|
|
|
1888
1860
|
break;
|
|
1889
1861
|
}
|
|
1890
1862
|
}
|
|
1891
|
-
|
|
1892
1863
|
//#endregion
|
|
1893
1864
|
//#region src/canvas.ts
|
|
1894
1865
|
/**
|
|
@@ -1958,7 +1929,6 @@ function createCanvas(options) {
|
|
|
1958
1929
|
}
|
|
1959
1930
|
};
|
|
1960
1931
|
}
|
|
1961
|
-
|
|
1962
1932
|
//#endregion
|
|
1963
1933
|
//#region src/components/Box.ts
|
|
1964
1934
|
function Box(props) {
|
|
@@ -1967,7 +1937,6 @@ function Box(props) {
|
|
|
1967
1937
|
...props
|
|
1968
1938
|
};
|
|
1969
1939
|
}
|
|
1970
|
-
|
|
1971
1940
|
//#endregion
|
|
1972
1941
|
//#region src/components/CustomDraw.ts
|
|
1973
1942
|
function CustomDraw(props) {
|
|
@@ -1976,7 +1945,6 @@ function CustomDraw(props) {
|
|
|
1976
1945
|
...props
|
|
1977
1946
|
};
|
|
1978
1947
|
}
|
|
1979
|
-
|
|
1980
1948
|
//#endregion
|
|
1981
1949
|
//#region src/components/Image.ts
|
|
1982
1950
|
function Image(props) {
|
|
@@ -1985,7 +1953,6 @@ function Image(props) {
|
|
|
1985
1953
|
...props
|
|
1986
1954
|
};
|
|
1987
1955
|
}
|
|
1988
|
-
|
|
1989
1956
|
//#endregion
|
|
1990
1957
|
//#region src/components/RichText.ts
|
|
1991
1958
|
function RichText(props) {
|
|
@@ -1994,7 +1961,6 @@ function RichText(props) {
|
|
|
1994
1961
|
...props
|
|
1995
1962
|
};
|
|
1996
1963
|
}
|
|
1997
|
-
|
|
1998
1964
|
//#endregion
|
|
1999
1965
|
//#region src/components/Stack.ts
|
|
2000
1966
|
function Stack(props) {
|
|
@@ -2003,7 +1969,6 @@ function Stack(props) {
|
|
|
2003
1969
|
...props
|
|
2004
1970
|
};
|
|
2005
1971
|
}
|
|
2006
|
-
|
|
2007
1972
|
//#endregion
|
|
2008
1973
|
//#region src/components/Svg.ts
|
|
2009
1974
|
function Svg(props) {
|
|
@@ -2050,7 +2015,6 @@ const svg = {
|
|
|
2050
2015
|
...props
|
|
2051
2016
|
})
|
|
2052
2017
|
};
|
|
2053
|
-
|
|
2054
2018
|
//#endregion
|
|
2055
2019
|
//#region src/components/Text.ts
|
|
2056
2020
|
function Text(props) {
|
|
@@ -2059,7 +2023,6 @@ function Text(props) {
|
|
|
2059
2023
|
...props
|
|
2060
2024
|
};
|
|
2061
2025
|
}
|
|
2062
|
-
|
|
2063
2026
|
//#endregion
|
|
2064
2027
|
//#region src/components/Transform.ts
|
|
2065
2028
|
function Transform(props) {
|
|
@@ -2068,7 +2031,6 @@ function Transform(props) {
|
|
|
2068
2031
|
...props
|
|
2069
2032
|
};
|
|
2070
2033
|
}
|
|
2071
|
-
|
|
2072
2034
|
//#endregion
|
|
2073
2035
|
//#region src/layout/utils/print.ts
|
|
2074
2036
|
/**
|
|
@@ -2128,6 +2090,5 @@ function printLayout(node) {
|
|
|
2128
2090
|
function layoutToString(node, _indent = " ") {
|
|
2129
2091
|
return printLayoutToString(node, "", true).join("\n");
|
|
2130
2092
|
}
|
|
2131
|
-
|
|
2132
2093
|
//#endregion
|
|
2133
|
-
export { Box, CustomDraw, Image, RichText, Stack, Svg, Text, Transform, computeLayout, createCanvas, createCanvasMeasureContext, layoutToString, linearGradient, printLayout, radialGradient, svg };
|
|
2094
|
+
export { Box, CustomDraw, Image, RichText, Stack, Svg, Text, Transform, computeLayout, createCanvas, createCanvasMeasureContext, layoutToString, linearGradient, printLayout, radialGradient, svg };
|
package/examples/card.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 示例:使用 draw-call 绘制一个卡片
|
|
3
3
|
* 运行: bun examples/card.ts
|
|
4
4
|
*/
|
|
5
|
-
import { Box, createCanvas, linearGradient, printLayout, Svg, svg, Text } from "
|
|
5
|
+
import { Box, createCanvas, linearGradient, printLayout, Svg, svg, Text } from "@/index";
|
|
6
6
|
import { GlobalFonts } from "@napi-rs/canvas";
|
|
7
7
|
import { fileURLToPath } from "bun";
|
|
8
8
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* 展示如何使用 CustomDraw 进行简单的自定义绘制
|
|
4
4
|
* 运行: bun examples/customdraw-basic.ts
|
|
5
5
|
*/
|
|
6
|
-
import { Box, createCanvas, CustomDraw, printLayout, Text } from "
|
|
6
|
+
import { Box, createCanvas, CustomDraw, printLayout, Text } from "@/index";
|
|
7
7
|
import { GlobalFonts } from "@napi-rs/canvas";
|
|
8
8
|
import { fileURLToPath } from "bun";
|
|
9
9
|
|
package/examples/customdraw.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* 展示直接调用 Canvas API、Transform 管理和子元素渲染功能
|
|
4
4
|
* 运行: bun examples/customdraw.ts
|
|
5
5
|
*/
|
|
6
|
-
import { Box, createCanvas, CustomDraw, printLayout, Text } from "
|
|
6
|
+
import { Box, createCanvas, CustomDraw, printLayout, Text } from "@/index";
|
|
7
7
|
import { GlobalFonts } from "@napi-rs/canvas";
|
|
8
8
|
import { fileURLToPath } from "bun";
|
|
9
9
|
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>draw-call 演示</title>
|
|
7
|
+
<style>
|
|
8
|
+
* {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
body {
|
|
15
|
+
font-family:
|
|
16
|
+
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
|
|
17
|
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
|
18
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
19
|
+
min-height: 100vh;
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
justify-content: center;
|
|
23
|
+
padding: 20px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.container {
|
|
27
|
+
background: white;
|
|
28
|
+
border-radius: 16px;
|
|
29
|
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
30
|
+
padding: 40px;
|
|
31
|
+
max-width: 860px;
|
|
32
|
+
width: 100%;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
h1 {
|
|
36
|
+
margin-bottom: 10px;
|
|
37
|
+
color: #333;
|
|
38
|
+
font-size: 28px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.subtitle {
|
|
42
|
+
color: #666;
|
|
43
|
+
margin-bottom: 30px;
|
|
44
|
+
font-size: 14px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.canvas-wrapper {
|
|
48
|
+
background: #f9f9f9;
|
|
49
|
+
border-radius: 12px;
|
|
50
|
+
padding: 20px;
|
|
51
|
+
border: 1px solid #e0e0e0;
|
|
52
|
+
display: flex;
|
|
53
|
+
justify-content: center;
|
|
54
|
+
align-items: center;
|
|
55
|
+
margin-bottom: 30px;
|
|
56
|
+
min-height: 420px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
canvas {
|
|
60
|
+
max-width: 100%;
|
|
61
|
+
height: auto;
|
|
62
|
+
border-radius: 8px;
|
|
63
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.features {
|
|
67
|
+
display: grid;
|
|
68
|
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
69
|
+
gap: 15px;
|
|
70
|
+
margin-top: 30px;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.feature-item {
|
|
74
|
+
background: #f5f5f5;
|
|
75
|
+
padding: 12px;
|
|
76
|
+
border-radius: 8px;
|
|
77
|
+
font-size: 12px;
|
|
78
|
+
color: #666;
|
|
79
|
+
border-left: 3px solid #667eea;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.feature-item strong {
|
|
83
|
+
color: #333;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.loading {
|
|
87
|
+
text-align: center;
|
|
88
|
+
color: #999;
|
|
89
|
+
font-size: 14px;
|
|
90
|
+
}
|
|
91
|
+
</style>
|
|
92
|
+
</head>
|
|
93
|
+
<body>
|
|
94
|
+
<div class="container">
|
|
95
|
+
<h1>🎨 draw-call 演示</h1>
|
|
96
|
+
<p class="subtitle">使用声明式 Canvas 绘图库展示现代 UI 绘制能力</p>
|
|
97
|
+
|
|
98
|
+
<div class="canvas-wrapper">
|
|
99
|
+
<canvas id="canvas"></canvas>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<div class="features">
|
|
103
|
+
<div class="feature-item"><strong>📐 Flexbox 布局</strong><br />支持现代化布局引擎</div>
|
|
104
|
+
<div class="feature-item"><strong>🎨 丰富样式</strong><br />背景、边框、阴影、渐变等</div>
|
|
105
|
+
<div class="feature-item"><strong>📝 文本排版</strong><br />支持换行、对齐、字体自定义</div>
|
|
106
|
+
<div class="feature-item"><strong>🎯 声明式 API</strong><br />类似 React 的组件化方式</div>
|
|
107
|
+
<div class="feature-item"><strong>✨ 高清显示</strong><br />支持高 DPI 设备自适应</div>
|
|
108
|
+
<div class="feature-item"><strong>🚀 TypeScript</strong><br />完整的类型支持和开发体验</div>
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<script src="demo.ts"></script>
|
|
113
|
+
</body>
|
|
114
|
+
</html>
|
package/examples/demo.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* draw-call 网页演示
|
|
3
3
|
* 展示库的各项功能:逐句布局、样式、文本排版、图片渲染等
|
|
4
4
|
*/
|
|
5
|
-
import { Box, createCanvas, Image, linearGradient, Svg, svg, Text } from "
|
|
5
|
+
import { Box, createCanvas, Image, linearGradient, Svg, svg, Text } from "@/index";
|
|
6
6
|
|
|
7
7
|
// 创建一个 canvas 并绘制图片内容,返回用于 Image 组件的 canvas
|
|
8
8
|
function createDemoImage(): HTMLCanvasElement {
|
package/examples/richtext.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 示例:使用 draw-call 的 RichText 组件
|
|
3
3
|
* 运行: bun examples/richtext.ts
|
|
4
4
|
*/
|
|
5
|
-
import { Box, createCanvas, RichText, Text } from "
|
|
5
|
+
import { Box, createCanvas, RichText, Text } from "@/index";
|
|
6
6
|
import { GlobalFonts } from "@napi-rs/canvas";
|
|
7
7
|
import { fileURLToPath } from "bun";
|
|
8
8
|
|
package/examples/transform.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* 展示移动(translate)、旋转(rotate)、放大(scale)等变换效果
|
|
4
4
|
* 运行: bun examples/transform.ts
|
|
5
5
|
*/
|
|
6
|
-
import { Box, createCanvas, printLayout, Text, Transform } from "
|
|
6
|
+
import { Box, createCanvas, printLayout, Text, Transform } from "@/index";
|
|
7
7
|
import { GlobalFonts } from "@napi-rs/canvas";
|
|
8
8
|
import { fileURLToPath } from "bun";
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,47 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codehz/draw-call",
|
|
3
|
-
"
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"main": "./dist/node/index.cjs",
|
|
6
|
+
"module": "./dist/node/index.mjs",
|
|
7
|
+
"types": "./dist/node/index.d.mts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"browser": {
|
|
11
|
+
"types": "./dist/browser/index.d.ts",
|
|
12
|
+
"import": "./dist/browser/index.js",
|
|
13
|
+
"require": "./dist/browser/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"bun": {
|
|
16
|
+
"types": "./dist/node/index.d.mts",
|
|
17
|
+
"import": "./dist/node/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"types": "./dist/node/index.d.mts",
|
|
20
|
+
"import": "./dist/node/index.mjs",
|
|
21
|
+
"require": "./dist/node/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"examples",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
5
30
|
"repository": {
|
|
6
31
|
"type": "git",
|
|
7
32
|
"url": "https://github.com/codehz/draw-call.git"
|
|
8
33
|
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"lint": "eslint --ext .ts,.tsx,.js --quiet",
|
|
36
|
+
"lint:fix": "eslint --ext .ts,.tsx,.js --fix",
|
|
37
|
+
"format": "prettier --write .",
|
|
38
|
+
"test": "bun test",
|
|
39
|
+
"release": "bun scripts/release.ts",
|
|
40
|
+
"prepare": "husky"
|
|
41
|
+
},
|
|
42
|
+
"lint-staged": {
|
|
43
|
+
"*.{ts,tsx}": [
|
|
44
|
+
"prettier --write",
|
|
45
|
+
"eslint --fix"
|
|
46
|
+
],
|
|
47
|
+
"*.{json,md}": [
|
|
48
|
+
"prettier --write"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
9
51
|
"devDependencies": {
|
|
10
52
|
"@fontpkg/unifont": "^15.0.1",
|
|
11
|
-
"@types/bun": "
|
|
12
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
13
|
-
"@typescript-eslint/parser": "^8.
|
|
14
|
-
"eslint": "^
|
|
15
|
-
"eslint-plugin-prettier": "^5.
|
|
16
|
-
"husky": "^9.
|
|
17
|
-
"lint-staged": "^
|
|
18
|
-
"prettier": "^3.
|
|
19
|
-
"prettier-plugin-organize-imports": "^4.
|
|
20
|
-
"tsdown": "^0.
|
|
53
|
+
"@types/bun": "^1.3.13",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^8.59.2",
|
|
55
|
+
"@typescript-eslint/parser": "^8.59.2",
|
|
56
|
+
"eslint": "^10.3.0",
|
|
57
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
58
|
+
"husky": "^9.1.7",
|
|
59
|
+
"lint-staged": "^17.0.2",
|
|
60
|
+
"prettier": "^3.8.3",
|
|
61
|
+
"prettier-plugin-organize-imports": "^4.3.0",
|
|
62
|
+
"tsdown": "^0.22.0"
|
|
21
63
|
},
|
|
22
64
|
"peerDependencies": {
|
|
23
|
-
"typescript": "^
|
|
65
|
+
"typescript": "^6.0.3"
|
|
24
66
|
},
|
|
25
67
|
"optionalDependencies": {
|
|
26
|
-
"@napi-rs/canvas": "^0.
|
|
27
|
-
},
|
|
28
|
-
"version": "0.5.1",
|
|
29
|
-
"main": "./node/index.cjs",
|
|
30
|
-
"types": "./node/index.d.cts",
|
|
31
|
-
"exports": {
|
|
32
|
-
".": {
|
|
33
|
-
"browser": {
|
|
34
|
-
"types": "./browser/index.d.ts",
|
|
35
|
-
"import": "./browser/index.js",
|
|
36
|
-
"require": "./browser/index.cjs"
|
|
37
|
-
},
|
|
38
|
-
"bun": {
|
|
39
|
-
"types": "./node/index.d.mts",
|
|
40
|
-
"import": "./node/index.mjs"
|
|
41
|
-
},
|
|
42
|
-
"types": "./node/index.d.mts",
|
|
43
|
-
"import": "./node/index.mjs",
|
|
44
|
-
"require": "./node/index.cjs"
|
|
45
|
-
}
|
|
68
|
+
"@napi-rs/canvas": "^1.0.0"
|
|
46
69
|
}
|
|
47
70
|
}
|