@codehz/draw-call 0.1.1 → 0.2.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/README.md +374 -6
- package/{canvas-BYrCq8eS.d.mts → canvas.d.cts} +145 -34
- package/{canvas-CkpP3RNK.d.cts → canvas.d.mts} +145 -34
- package/examples/card.ts +155 -0
- package/examples/demo.ts +478 -0
- package/examples/richtext.ts +284 -0
- package/index.cjs +139 -9
- package/index.d.cts +51 -2
- package/index.d.mts +51 -2
- package/index.mjs +127 -3
- package/node.cjs +8 -7
- package/node.d.cts +3 -3
- package/node.d.mts +3 -3
- package/node.mjs +7 -6
- package/package.json +1 -1
- package/render.cjs +1555 -0
- package/render.mjs +1531 -0
- package/engine-C88lMGbX.mjs +0 -606
- package/engine-OyKoV7Gn.cjs +0 -636
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 示例:使用 draw-call 的 RichText 组件
|
|
3
|
+
* 运行: bun examples/richtext.ts
|
|
4
|
+
*/
|
|
5
|
+
import { Box, RichText, Text } from "@codehz/draw-call";
|
|
6
|
+
import { createNodeCanvas } from "@codehz/draw-call/node";
|
|
7
|
+
import { GlobalFonts } from "@napi-rs/canvas";
|
|
8
|
+
import { fileURLToPath } from "bun";
|
|
9
|
+
|
|
10
|
+
GlobalFonts.registerFromPath(fileURLToPath(import.meta.resolve("@fontpkg/unifont/unifont-15.0.01.ttf")), "unifont");
|
|
11
|
+
|
|
12
|
+
const canvas = createNodeCanvas({
|
|
13
|
+
width: 400,
|
|
14
|
+
height: 820,
|
|
15
|
+
pixelRatio: 2,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// 绘制背景
|
|
19
|
+
canvas.render(
|
|
20
|
+
Box({
|
|
21
|
+
width: "fill",
|
|
22
|
+
height: "fill",
|
|
23
|
+
background: "#f8f9fa",
|
|
24
|
+
padding: 20,
|
|
25
|
+
direction: "column",
|
|
26
|
+
gap: 20,
|
|
27
|
+
children: [
|
|
28
|
+
// 标题
|
|
29
|
+
Text({
|
|
30
|
+
content: "RichText 富文本演示",
|
|
31
|
+
font: { size: 20, weight: "bold", family: "unifont" },
|
|
32
|
+
color: "#333",
|
|
33
|
+
}),
|
|
34
|
+
|
|
35
|
+
// 基本用法
|
|
36
|
+
Box({
|
|
37
|
+
background: "#ffffff",
|
|
38
|
+
border: { radius: 8 },
|
|
39
|
+
padding: 12,
|
|
40
|
+
shadow: { offsetY: 2, blur: 8, color: "rgba(0,0,0,0.06)" },
|
|
41
|
+
direction: "column",
|
|
42
|
+
gap: 8,
|
|
43
|
+
children: [
|
|
44
|
+
Text({
|
|
45
|
+
content: "基本用法 - 多样式文本",
|
|
46
|
+
font: { size: 12, family: "unifont" },
|
|
47
|
+
color: "#666",
|
|
48
|
+
}),
|
|
49
|
+
RichText({
|
|
50
|
+
spans: [
|
|
51
|
+
{ text: "Hello, ", color: "#333", font: { size: 14, family: "unifont" } },
|
|
52
|
+
{ text: "World", color: "#ff6b6b", font: { size: 18, weight: "bold", family: "unifont" } },
|
|
53
|
+
{ text: "!", color: "#333", font: { size: 14, family: "unifont" } },
|
|
54
|
+
],
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
}),
|
|
58
|
+
|
|
59
|
+
// 渐变色文本
|
|
60
|
+
Box({
|
|
61
|
+
background: "#ffffff",
|
|
62
|
+
border: { radius: 8 },
|
|
63
|
+
padding: 12,
|
|
64
|
+
shadow: { offsetY: 2, blur: 8, color: "rgba(0,0,0,0.06)" },
|
|
65
|
+
direction: "column",
|
|
66
|
+
gap: 8,
|
|
67
|
+
children: [
|
|
68
|
+
Text({
|
|
69
|
+
content: "带背景色的文本",
|
|
70
|
+
font: { size: 12, family: "unifont" },
|
|
71
|
+
color: "#666",
|
|
72
|
+
}),
|
|
73
|
+
RichText({
|
|
74
|
+
spans: [
|
|
75
|
+
{ text: "红色背景", background: "#ffe8e8", color: "#f5222d" },
|
|
76
|
+
{ text: " " },
|
|
77
|
+
{ text: "绿色背景", background: "#f6ffed", color: "#52c41a" },
|
|
78
|
+
{ text: " " },
|
|
79
|
+
{ text: "蓝色背景", background: "#e8f4ff", color: "#1890ff" },
|
|
80
|
+
],
|
|
81
|
+
}),
|
|
82
|
+
],
|
|
83
|
+
}),
|
|
84
|
+
|
|
85
|
+
// 下划线和删除线
|
|
86
|
+
Box({
|
|
87
|
+
background: "#ffffff",
|
|
88
|
+
border: { radius: 8 },
|
|
89
|
+
padding: 12,
|
|
90
|
+
shadow: { offsetY: 2, blur: 8, color: "rgba(0,0,0,0.06)" },
|
|
91
|
+
direction: "column",
|
|
92
|
+
gap: 8,
|
|
93
|
+
children: [
|
|
94
|
+
Text({
|
|
95
|
+
content: "文本装饰 - 下划线和删除线",
|
|
96
|
+
font: { size: 12, family: "unifont" },
|
|
97
|
+
color: "#666",
|
|
98
|
+
}),
|
|
99
|
+
RichText({
|
|
100
|
+
spans: [
|
|
101
|
+
{ text: "下划线文本", underline: true, color: "#333", font: { size: 14, family: "unifont" } },
|
|
102
|
+
{ text: " " },
|
|
103
|
+
{ text: "删除线文本", strikethrough: true, color: "#333", font: { size: 14, family: "unifont" } },
|
|
104
|
+
{ text: " " },
|
|
105
|
+
{
|
|
106
|
+
text: "组合效果",
|
|
107
|
+
underline: true,
|
|
108
|
+
strikethrough: true,
|
|
109
|
+
color: "#f5222d",
|
|
110
|
+
font: { size: 14, family: "unifont" },
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
}),
|
|
114
|
+
],
|
|
115
|
+
}),
|
|
116
|
+
|
|
117
|
+
// 自动换行
|
|
118
|
+
Box({
|
|
119
|
+
background: "#ffffff",
|
|
120
|
+
border: { radius: 8 },
|
|
121
|
+
padding: 12,
|
|
122
|
+
shadow: { offsetY: 2, blur: 8, color: "rgba(0,0,0,0.06)" },
|
|
123
|
+
direction: "column",
|
|
124
|
+
gap: 8,
|
|
125
|
+
children: [
|
|
126
|
+
Text({
|
|
127
|
+
content: "自动换行 - 长文本",
|
|
128
|
+
font: { size: 12, family: "unifont" },
|
|
129
|
+
color: "#666",
|
|
130
|
+
}),
|
|
131
|
+
RichText({
|
|
132
|
+
spans: [
|
|
133
|
+
{
|
|
134
|
+
text: "这是一个很长很长的富文本段落,它会自动换行以适应容器的宽度。",
|
|
135
|
+
color: "#333",
|
|
136
|
+
font: { size: 13, family: "unifont" },
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
}),
|
|
140
|
+
],
|
|
141
|
+
}),
|
|
142
|
+
|
|
143
|
+
// 混合样式换行
|
|
144
|
+
Box({
|
|
145
|
+
background: "#ffffff",
|
|
146
|
+
border: { radius: 8 },
|
|
147
|
+
padding: 12,
|
|
148
|
+
shadow: { offsetY: 2, blur: 8, color: "rgba(0,0,0,0.06)" },
|
|
149
|
+
direction: "column",
|
|
150
|
+
gap: 8,
|
|
151
|
+
children: [
|
|
152
|
+
Text({
|
|
153
|
+
content: "混合样式自动换行",
|
|
154
|
+
font: { size: 12, family: "unifont" },
|
|
155
|
+
color: "#666",
|
|
156
|
+
}),
|
|
157
|
+
RichText({
|
|
158
|
+
spans: [
|
|
159
|
+
{ text: "draw-call ", color: "#333", font: { size: 13, family: "unifont" } },
|
|
160
|
+
{ text: "是一个", color: "#666", font: { size: 13, family: "unifont" } },
|
|
161
|
+
{ text: "声明式", color: "#1890ff", font: { size: 13, weight: "bold", family: "unifont" } },
|
|
162
|
+
{ text: " Canvas 绘图库,支持", color: "#333", font: { size: 13, family: "unifont" } },
|
|
163
|
+
{ text: "Flexbox 布局", color: "#52c41a", font: { size: 13, family: "unifont" }, underline: true },
|
|
164
|
+
{ text: "和", color: "#333", font: { size: 13, family: "unifont" } },
|
|
165
|
+
{ text: "富文本渲染", color: "#f5222d", font: { size: 13, weight: "bold", family: "unifont" } },
|
|
166
|
+
{ text: "。", color: "#333", font: { size: 13, family: "unifont" } },
|
|
167
|
+
],
|
|
168
|
+
}),
|
|
169
|
+
],
|
|
170
|
+
}),
|
|
171
|
+
|
|
172
|
+
// 对齐方式
|
|
173
|
+
Box({
|
|
174
|
+
background: "#ffffff",
|
|
175
|
+
border: { radius: 8 },
|
|
176
|
+
padding: 12,
|
|
177
|
+
shadow: { offsetY: 2, blur: 8, color: "rgba(0,0,0,0.06)" },
|
|
178
|
+
direction: "column",
|
|
179
|
+
gap: 8,
|
|
180
|
+
children: [
|
|
181
|
+
Text({
|
|
182
|
+
content: "文本对齐方式",
|
|
183
|
+
font: { size: 12, family: "unifont" },
|
|
184
|
+
color: "#666",
|
|
185
|
+
}),
|
|
186
|
+
Box({
|
|
187
|
+
width: "fill",
|
|
188
|
+
background: "#f5f5f5",
|
|
189
|
+
border: { radius: 4 },
|
|
190
|
+
padding: 8,
|
|
191
|
+
direction: "column",
|
|
192
|
+
gap: 4,
|
|
193
|
+
children: [
|
|
194
|
+
Text({
|
|
195
|
+
content: "左对齐:",
|
|
196
|
+
font: { size: 11, family: "unifont" },
|
|
197
|
+
color: "#999",
|
|
198
|
+
}),
|
|
199
|
+
RichText({
|
|
200
|
+
align: "left",
|
|
201
|
+
spans: [{ text: "这是一段左对齐的富文本", color: "#333", font: { size: 12, family: "unifont" } }],
|
|
202
|
+
}),
|
|
203
|
+
],
|
|
204
|
+
}),
|
|
205
|
+
Box({
|
|
206
|
+
width: "fill",
|
|
207
|
+
background: "#f5f5f5",
|
|
208
|
+
border: { radius: 4 },
|
|
209
|
+
padding: 8,
|
|
210
|
+
direction: "column",
|
|
211
|
+
gap: 4,
|
|
212
|
+
children: [
|
|
213
|
+
Text({
|
|
214
|
+
content: "居中对齐:",
|
|
215
|
+
font: { size: 11, family: "unifont" },
|
|
216
|
+
color: "#999",
|
|
217
|
+
}),
|
|
218
|
+
RichText({
|
|
219
|
+
align: "center",
|
|
220
|
+
width: "fill",
|
|
221
|
+
spans: [{ text: "这是一段居中对齐的富文本", color: "#333", font: { size: 12, family: "unifont" } }],
|
|
222
|
+
}),
|
|
223
|
+
],
|
|
224
|
+
}),
|
|
225
|
+
Box({
|
|
226
|
+
width: "fill",
|
|
227
|
+
background: "#f5f5f5",
|
|
228
|
+
border: { radius: 4 },
|
|
229
|
+
padding: 8,
|
|
230
|
+
direction: "column",
|
|
231
|
+
gap: 4,
|
|
232
|
+
children: [
|
|
233
|
+
Text({
|
|
234
|
+
content: "右对齐:",
|
|
235
|
+
font: { size: 11, family: "unifont" },
|
|
236
|
+
color: "#999",
|
|
237
|
+
}),
|
|
238
|
+
RichText({
|
|
239
|
+
align: "right",
|
|
240
|
+
width: "fill",
|
|
241
|
+
spans: [{ text: "这是一段右对齐的富文本", color: "#333", font: { size: 12, family: "unifont" } }],
|
|
242
|
+
}),
|
|
243
|
+
],
|
|
244
|
+
}),
|
|
245
|
+
],
|
|
246
|
+
}),
|
|
247
|
+
|
|
248
|
+
// 彩色标签云
|
|
249
|
+
Box({
|
|
250
|
+
background: "#ffffff",
|
|
251
|
+
border: { radius: 8 },
|
|
252
|
+
padding: 12,
|
|
253
|
+
shadow: { offsetY: 2, blur: 8, color: "rgba(0,0,0,0.06)" },
|
|
254
|
+
direction: "column",
|
|
255
|
+
gap: 8,
|
|
256
|
+
children: [
|
|
257
|
+
Text({
|
|
258
|
+
content: "彩色标签展示",
|
|
259
|
+
font: { size: 12, family: "unifont" },
|
|
260
|
+
color: "#666",
|
|
261
|
+
}),
|
|
262
|
+
RichText({
|
|
263
|
+
spans: [
|
|
264
|
+
{ text: "TypeScript", background: "#e8f4ff", color: "#1890ff", font: { size: 12, family: "unifont" } },
|
|
265
|
+
{ text: " " },
|
|
266
|
+
{ text: "Canvas", background: "#f6ffed", color: "#52c41a", font: { size: 12, family: "unifont" } },
|
|
267
|
+
{ text: " " },
|
|
268
|
+
{ text: "Flexbox", background: "#fff7e6", color: "#fa8c16", font: { size: 12, family: "unifont" } },
|
|
269
|
+
{ text: " " },
|
|
270
|
+
{ text: "声明式", background: "#ffe8e8", color: "#f5222d", font: { size: 12, family: "unifont" } },
|
|
271
|
+
{ text: " " },
|
|
272
|
+
{ text: "组件化", background: "#f0f0ff", color: "#2f54eb", font: { size: 12, family: "unifont" } },
|
|
273
|
+
],
|
|
274
|
+
}),
|
|
275
|
+
],
|
|
276
|
+
}),
|
|
277
|
+
],
|
|
278
|
+
})
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
// 保存到文件
|
|
282
|
+
const buffer = await canvas.toBuffer("image/png");
|
|
283
|
+
await Bun.write("examples/richtext.png", buffer);
|
|
284
|
+
console.log("RichText demo saved to examples/richtext.png");
|
package/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_render = require('./render.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/canvas.ts
|
|
4
4
|
/**
|
|
@@ -19,19 +19,20 @@ function createCanvas(options) {
|
|
|
19
19
|
const ctx = canvas.getContext("2d");
|
|
20
20
|
if (!ctx) throw new Error("Failed to get 2d context");
|
|
21
21
|
if (pixelRatio !== 1) ctx.scale(pixelRatio, pixelRatio);
|
|
22
|
-
const measureCtx =
|
|
22
|
+
const measureCtx = require_render.createCanvasMeasureContext(ctx);
|
|
23
23
|
return {
|
|
24
24
|
width,
|
|
25
25
|
height,
|
|
26
26
|
pixelRatio,
|
|
27
|
+
canvas,
|
|
27
28
|
render(element) {
|
|
28
|
-
const layoutTree =
|
|
29
|
+
const layoutTree = require_render.computeLayout(element, measureCtx, {
|
|
29
30
|
minWidth: 0,
|
|
30
31
|
maxWidth: width,
|
|
31
32
|
minHeight: 0,
|
|
32
33
|
maxHeight: height
|
|
33
34
|
});
|
|
34
|
-
|
|
35
|
+
require_render.renderNode(ctx, layoutTree);
|
|
35
36
|
return layoutTree;
|
|
36
37
|
},
|
|
37
38
|
clear() {
|
|
@@ -44,7 +45,7 @@ function createCanvas(options) {
|
|
|
44
45
|
if ("toDataURL" in canvas && typeof canvas.toDataURL === "function") return canvas.toDataURL(type, quality);
|
|
45
46
|
throw new Error("toDataURL not supported");
|
|
46
47
|
},
|
|
47
|
-
|
|
48
|
+
toBuffer(type = "image/png") {
|
|
48
49
|
if ("toBuffer" in canvas && typeof canvas.toBuffer === "function") return canvas.toBuffer(type);
|
|
49
50
|
throw new Error("toBuffer not supported in this environment");
|
|
50
51
|
}
|
|
@@ -60,6 +61,24 @@ function Box(props) {
|
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/components/Image.ts
|
|
66
|
+
function Image(props) {
|
|
67
|
+
return {
|
|
68
|
+
type: "image",
|
|
69
|
+
...props
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/components/RichText.ts
|
|
75
|
+
function RichText(props) {
|
|
76
|
+
return {
|
|
77
|
+
type: "richtext",
|
|
78
|
+
...props
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
63
82
|
//#endregion
|
|
64
83
|
//#region src/components/Stack.ts
|
|
65
84
|
function Stack(props) {
|
|
@@ -69,6 +88,53 @@ function Stack(props) {
|
|
|
69
88
|
};
|
|
70
89
|
}
|
|
71
90
|
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/components/Svg.ts
|
|
93
|
+
function Svg(props) {
|
|
94
|
+
return {
|
|
95
|
+
type: "svg",
|
|
96
|
+
...props
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const svg = {
|
|
100
|
+
rect: (props) => ({
|
|
101
|
+
type: "rect",
|
|
102
|
+
...props
|
|
103
|
+
}),
|
|
104
|
+
circle: (props) => ({
|
|
105
|
+
type: "circle",
|
|
106
|
+
...props
|
|
107
|
+
}),
|
|
108
|
+
ellipse: (props) => ({
|
|
109
|
+
type: "ellipse",
|
|
110
|
+
...props
|
|
111
|
+
}),
|
|
112
|
+
line: (props) => ({
|
|
113
|
+
type: "line",
|
|
114
|
+
...props
|
|
115
|
+
}),
|
|
116
|
+
polyline: (props) => ({
|
|
117
|
+
type: "polyline",
|
|
118
|
+
...props
|
|
119
|
+
}),
|
|
120
|
+
polygon: (props) => ({
|
|
121
|
+
type: "polygon",
|
|
122
|
+
...props
|
|
123
|
+
}),
|
|
124
|
+
path: (props) => ({
|
|
125
|
+
type: "path",
|
|
126
|
+
...props
|
|
127
|
+
}),
|
|
128
|
+
text: (props) => ({
|
|
129
|
+
type: "text",
|
|
130
|
+
...props
|
|
131
|
+
}),
|
|
132
|
+
g: (props) => ({
|
|
133
|
+
type: "g",
|
|
134
|
+
...props
|
|
135
|
+
})
|
|
136
|
+
};
|
|
137
|
+
|
|
72
138
|
//#endregion
|
|
73
139
|
//#region src/components/Text.ts
|
|
74
140
|
function Text(props) {
|
|
@@ -78,12 +144,76 @@ function Text(props) {
|
|
|
78
144
|
};
|
|
79
145
|
}
|
|
80
146
|
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/layout/utils/print.ts
|
|
149
|
+
/**
|
|
150
|
+
* 获取元素类型的显示名称
|
|
151
|
+
*/
|
|
152
|
+
function getElementType(element) {
|
|
153
|
+
switch (element.type) {
|
|
154
|
+
case "box": return "Box";
|
|
155
|
+
case "text": return `Text "${element.content.slice(0, 20)}${element.content.length > 20 ? "..." : ""}"`;
|
|
156
|
+
case "stack": return "Stack";
|
|
157
|
+
case "image": return "Image";
|
|
158
|
+
case "svg": return "Svg";
|
|
159
|
+
default: return element.type;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 递归打印布局树
|
|
164
|
+
*/
|
|
165
|
+
function printLayoutToString(node, prefix = "", isLast = true, depth = 0) {
|
|
166
|
+
const lines = [];
|
|
167
|
+
const connector = isLast ? "└─ " : "├─ ";
|
|
168
|
+
const type = getElementType(node.element);
|
|
169
|
+
const { x, y, width, height } = node.layout;
|
|
170
|
+
const childCount = node.children.length;
|
|
171
|
+
lines.push(`${prefix}${connector}${type} @(${Math.round(x)},${Math.round(y)}) size:${Math.round(width)}x${Math.round(height)}`);
|
|
172
|
+
if (node.element.type === "text" && node.lines) {
|
|
173
|
+
const contentPrefix = prefix + (isLast ? " " : "│ ");
|
|
174
|
+
for (let i = 0; i < node.lines.length; i++) {
|
|
175
|
+
const lineText = node.lines[i];
|
|
176
|
+
const isLastLine = i === node.lines.length - 1 && childCount === 0;
|
|
177
|
+
lines.push(`${contentPrefix}${isLastLine ? "└─ " : "├─ "}${JSON.stringify(lineText)}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
181
|
+
const child = node.children[i];
|
|
182
|
+
const isChildLast = i === node.children.length - 1;
|
|
183
|
+
const childPrefix = prefix + (isLast ? " " : "│ ");
|
|
184
|
+
lines.push(...printLayoutToString(child, childPrefix, isChildLast, depth + 1));
|
|
185
|
+
}
|
|
186
|
+
return lines;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* 打印 LayoutNode 树结构到控制台
|
|
190
|
+
*/
|
|
191
|
+
function printLayout(node) {
|
|
192
|
+
const lines = printLayoutToString(node, "", true);
|
|
193
|
+
console.log(lines.join("\n"));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 将 LayoutNode 转换为美观的字符串
|
|
197
|
+
* @param node LayoutNode 根节点
|
|
198
|
+
* @param indent 缩进字符串,默认为两个空格
|
|
199
|
+
* @returns 格式化的字符串
|
|
200
|
+
*/
|
|
201
|
+
function layoutToString(node, _indent = " ") {
|
|
202
|
+
return printLayoutToString(node, "", true).join("\n");
|
|
203
|
+
}
|
|
204
|
+
|
|
81
205
|
//#endregion
|
|
82
206
|
exports.Box = Box;
|
|
207
|
+
exports.Image = Image;
|
|
208
|
+
exports.RichText = RichText;
|
|
83
209
|
exports.Stack = Stack;
|
|
210
|
+
exports.Svg = Svg;
|
|
84
211
|
exports.Text = Text;
|
|
85
|
-
exports.computeLayout =
|
|
212
|
+
exports.computeLayout = require_render.computeLayout;
|
|
86
213
|
exports.createCanvas = createCanvas;
|
|
87
|
-
exports.createCanvasMeasureContext =
|
|
88
|
-
exports.
|
|
89
|
-
exports.
|
|
214
|
+
exports.createCanvasMeasureContext = require_render.createCanvasMeasureContext;
|
|
215
|
+
exports.layoutToString = layoutToString;
|
|
216
|
+
exports.linearGradient = require_render.linearGradient;
|
|
217
|
+
exports.printLayout = printLayout;
|
|
218
|
+
exports.radialGradient = require_render.radialGradient;
|
|
219
|
+
exports.svg = svg;
|
package/index.d.cts
CHANGED
|
@@ -1,12 +1,61 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { $ as linearGradient, A as SvgTransformProps, B as LayoutProps, C as SvgPathChild, D as SvgRectChild, E as SvgProps, F as ContainerLayoutProps, G as FontProps, H as Bounds, I as FlexDirection, J as RadialGradientDescriptor, K as GradientDescriptor, L as JustifyContent, M as TextProps, N as AlignItems, O as SvgStyleProps, P as AlignSelf, Q as StrokeProps, R as LayoutConstraints, S as SvgLineChild, T as SvgPolylineChild, U as Color, V as Border, W as ColorStop, X as Size, Y as Shadow, Z as Spacing, _ as SvgChild, a as BoxElement, b as SvgEllipseChild, c as ImageElement, d as RichTextProps, et as radialGradient, f as RichTextSpan, g as SvgAlign, h as StackProps, i as createCanvas, j as TextElement, k as SvgTextChild, l as ImageProps, m as StackElement, n as DrawCallCanvas, o as BoxProps, p as StackAlign, q as LinearGradientDescriptor, r as LayoutSize, s as Element, t as CanvasOptions, u as RichTextElement, v as SvgCircleChild, w as SvgPolygonChild, x as SvgGroupChild, y as SvgElement, z as LayoutNode } from "./canvas.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/components/Box.d.ts
|
|
4
4
|
declare function Box(props: BoxProps): BoxElement;
|
|
5
5
|
//#endregion
|
|
6
|
+
//#region src/components/Image.d.ts
|
|
7
|
+
declare function Image(props: ImageProps): ImageElement;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/components/RichText.d.ts
|
|
10
|
+
declare function RichText(props: RichTextProps): RichTextElement;
|
|
11
|
+
//#endregion
|
|
6
12
|
//#region src/components/Stack.d.ts
|
|
7
13
|
declare function Stack(props: StackProps): StackElement;
|
|
8
14
|
//#endregion
|
|
15
|
+
//#region src/components/Svg.d.ts
|
|
16
|
+
declare function Svg(props: SvgProps): SvgElement;
|
|
17
|
+
declare const svg: {
|
|
18
|
+
rect: (props: Omit<SvgRectChild, "type">) => SvgRectChild;
|
|
19
|
+
circle: (props: Omit<SvgCircleChild, "type">) => SvgCircleChild;
|
|
20
|
+
ellipse: (props: Omit<SvgEllipseChild, "type">) => SvgEllipseChild;
|
|
21
|
+
line: (props: Omit<SvgLineChild, "type">) => SvgLineChild;
|
|
22
|
+
polyline: (props: Omit<SvgPolylineChild, "type">) => SvgPolylineChild;
|
|
23
|
+
polygon: (props: Omit<SvgPolygonChild, "type">) => SvgPolygonChild;
|
|
24
|
+
path: (props: Omit<SvgPathChild, "type">) => SvgPathChild;
|
|
25
|
+
text: (props: Omit<SvgTextChild, "type">) => SvgTextChild;
|
|
26
|
+
g: (props: Omit<SvgGroupChild, "type">) => SvgGroupChild;
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
9
29
|
//#region src/components/Text.d.ts
|
|
10
30
|
declare function Text(props: TextProps): TextElement;
|
|
11
31
|
//#endregion
|
|
12
|
-
|
|
32
|
+
//#region src/layout/utils/measure.d.ts
|
|
33
|
+
interface MeasureTextResult {
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
offset: number;
|
|
37
|
+
ascent: number;
|
|
38
|
+
descent: number;
|
|
39
|
+
}
|
|
40
|
+
interface MeasureContext {
|
|
41
|
+
measureText(text: string, font: FontProps): MeasureTextResult;
|
|
42
|
+
}
|
|
43
|
+
declare function createCanvasMeasureContext(ctx: CanvasRenderingContext2D): MeasureContext;
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/layout/engine.d.ts
|
|
46
|
+
declare function computeLayout(element: Element, ctx: MeasureContext, constraints: LayoutConstraints, x?: number, y?: number): LayoutNode;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/layout/utils/print.d.ts
|
|
49
|
+
/**
|
|
50
|
+
* 打印 LayoutNode 树结构到控制台
|
|
51
|
+
*/
|
|
52
|
+
declare function printLayout(node: LayoutNode): void;
|
|
53
|
+
/**
|
|
54
|
+
* 将 LayoutNode 转换为美观的字符串
|
|
55
|
+
* @param node LayoutNode 根节点
|
|
56
|
+
* @param indent 缩进字符串,默认为两个空格
|
|
57
|
+
* @returns 格式化的字符串
|
|
58
|
+
*/
|
|
59
|
+
declare function layoutToString(node: LayoutNode, _indent?: string): string;
|
|
60
|
+
//#endregion
|
|
61
|
+
export { type AlignItems, type AlignSelf, type Border, type Bounds, Box, type BoxElement, type BoxProps, type CanvasOptions, type Color, type ColorStop, type ContainerLayoutProps, type DrawCallCanvas, type Element, type FlexDirection, type FontProps, type GradientDescriptor, Image, type JustifyContent, type LayoutNode, type LayoutProps, type LayoutSize, type LinearGradientDescriptor, type MeasureContext, type RadialGradientDescriptor, RichText, type RichTextElement, type RichTextProps, type RichTextSpan, type Shadow, type Size, type Spacing, Stack, type StackAlign, type StackElement, type StackProps, type StrokeProps, Svg, type SvgAlign, type SvgChild, type SvgCircleChild, type SvgElement, type SvgEllipseChild, type SvgGroupChild, type SvgLineChild, type SvgPathChild, type SvgPolygonChild, type SvgPolylineChild, type SvgProps, type SvgRectChild, type SvgStyleProps, type SvgTextChild, type SvgTransformProps, Text, type TextElement, type TextProps, computeLayout, createCanvas, createCanvasMeasureContext, layoutToString, linearGradient, printLayout, radialGradient, svg };
|
package/index.d.mts
CHANGED
|
@@ -1,12 +1,61 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { $ as linearGradient, A as SvgTransformProps, B as LayoutProps, C as SvgPathChild, D as SvgRectChild, E as SvgProps, F as ContainerLayoutProps, G as FontProps, H as Bounds, I as FlexDirection, J as RadialGradientDescriptor, K as GradientDescriptor, L as JustifyContent, M as TextProps, N as AlignItems, O as SvgStyleProps, P as AlignSelf, Q as StrokeProps, R as LayoutConstraints, S as SvgLineChild, T as SvgPolylineChild, U as Color, V as Border, W as ColorStop, X as Size, Y as Shadow, Z as Spacing, _ as SvgChild, a as BoxElement, b as SvgEllipseChild, c as ImageElement, d as RichTextProps, et as radialGradient, f as RichTextSpan, g as SvgAlign, h as StackProps, i as createCanvas, j as TextElement, k as SvgTextChild, l as ImageProps, m as StackElement, n as DrawCallCanvas, o as BoxProps, p as StackAlign, q as LinearGradientDescriptor, r as LayoutSize, s as Element, t as CanvasOptions, u as RichTextElement, v as SvgCircleChild, w as SvgPolygonChild, x as SvgGroupChild, y as SvgElement, z as LayoutNode } from "./canvas.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/components/Box.d.ts
|
|
4
4
|
declare function Box(props: BoxProps): BoxElement;
|
|
5
5
|
//#endregion
|
|
6
|
+
//#region src/components/Image.d.ts
|
|
7
|
+
declare function Image(props: ImageProps): ImageElement;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/components/RichText.d.ts
|
|
10
|
+
declare function RichText(props: RichTextProps): RichTextElement;
|
|
11
|
+
//#endregion
|
|
6
12
|
//#region src/components/Stack.d.ts
|
|
7
13
|
declare function Stack(props: StackProps): StackElement;
|
|
8
14
|
//#endregion
|
|
15
|
+
//#region src/components/Svg.d.ts
|
|
16
|
+
declare function Svg(props: SvgProps): SvgElement;
|
|
17
|
+
declare const svg: {
|
|
18
|
+
rect: (props: Omit<SvgRectChild, "type">) => SvgRectChild;
|
|
19
|
+
circle: (props: Omit<SvgCircleChild, "type">) => SvgCircleChild;
|
|
20
|
+
ellipse: (props: Omit<SvgEllipseChild, "type">) => SvgEllipseChild;
|
|
21
|
+
line: (props: Omit<SvgLineChild, "type">) => SvgLineChild;
|
|
22
|
+
polyline: (props: Omit<SvgPolylineChild, "type">) => SvgPolylineChild;
|
|
23
|
+
polygon: (props: Omit<SvgPolygonChild, "type">) => SvgPolygonChild;
|
|
24
|
+
path: (props: Omit<SvgPathChild, "type">) => SvgPathChild;
|
|
25
|
+
text: (props: Omit<SvgTextChild, "type">) => SvgTextChild;
|
|
26
|
+
g: (props: Omit<SvgGroupChild, "type">) => SvgGroupChild;
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
9
29
|
//#region src/components/Text.d.ts
|
|
10
30
|
declare function Text(props: TextProps): TextElement;
|
|
11
31
|
//#endregion
|
|
12
|
-
|
|
32
|
+
//#region src/layout/utils/measure.d.ts
|
|
33
|
+
interface MeasureTextResult {
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
offset: number;
|
|
37
|
+
ascent: number;
|
|
38
|
+
descent: number;
|
|
39
|
+
}
|
|
40
|
+
interface MeasureContext {
|
|
41
|
+
measureText(text: string, font: FontProps): MeasureTextResult;
|
|
42
|
+
}
|
|
43
|
+
declare function createCanvasMeasureContext(ctx: CanvasRenderingContext2D): MeasureContext;
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/layout/engine.d.ts
|
|
46
|
+
declare function computeLayout(element: Element, ctx: MeasureContext, constraints: LayoutConstraints, x?: number, y?: number): LayoutNode;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/layout/utils/print.d.ts
|
|
49
|
+
/**
|
|
50
|
+
* 打印 LayoutNode 树结构到控制台
|
|
51
|
+
*/
|
|
52
|
+
declare function printLayout(node: LayoutNode): void;
|
|
53
|
+
/**
|
|
54
|
+
* 将 LayoutNode 转换为美观的字符串
|
|
55
|
+
* @param node LayoutNode 根节点
|
|
56
|
+
* @param indent 缩进字符串,默认为两个空格
|
|
57
|
+
* @returns 格式化的字符串
|
|
58
|
+
*/
|
|
59
|
+
declare function layoutToString(node: LayoutNode, _indent?: string): string;
|
|
60
|
+
//#endregion
|
|
61
|
+
export { type AlignItems, type AlignSelf, type Border, type Bounds, Box, type BoxElement, type BoxProps, type CanvasOptions, type Color, type ColorStop, type ContainerLayoutProps, type DrawCallCanvas, type Element, type FlexDirection, type FontProps, type GradientDescriptor, Image, type JustifyContent, type LayoutNode, type LayoutProps, type LayoutSize, type LinearGradientDescriptor, type MeasureContext, type RadialGradientDescriptor, RichText, type RichTextElement, type RichTextProps, type RichTextSpan, type Shadow, type Size, type Spacing, Stack, type StackAlign, type StackElement, type StackProps, type StrokeProps, Svg, type SvgAlign, type SvgChild, type SvgCircleChild, type SvgElement, type SvgEllipseChild, type SvgGroupChild, type SvgLineChild, type SvgPathChild, type SvgPolygonChild, type SvgPolylineChild, type SvgProps, type SvgRectChild, type SvgStyleProps, type SvgTextChild, type SvgTransformProps, Text, type TextElement, type TextProps, computeLayout, createCanvas, createCanvasMeasureContext, layoutToString, linearGradient, printLayout, radialGradient, svg };
|