@codehz/draw-call 0.5.2 → 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 -41
- package/{browser → dist/browser}/index.js +1 -39
- package/{node → dist/node}/index.cjs +2 -41
- package/dist/node/index.d.cts +454 -0
- package/dist/node/index.d.mts +454 -0
- 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
- /package/{node → dist/browser}/index.d.cts +0 -0
- /package/{node/index.d.mts → dist/browser/index.d.ts} +0 -0
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value:
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _napi_rs_canvas = require("@napi-rs/canvas");
|
|
3
|
-
|
|
4
3
|
//#region src/compat/index.ts
|
|
5
4
|
function createRawCanvas(width, height) {
|
|
6
5
|
return (0, _napi_rs_canvas.createCanvas)(width, height);
|
|
7
6
|
}
|
|
8
|
-
|
|
9
7
|
//#endregion
|
|
10
8
|
//#region src/types/base.ts
|
|
11
9
|
function linearGradient(angle, ...stops) {
|
|
@@ -76,7 +74,6 @@ function normalizeBorderRadius(value) {
|
|
|
76
74
|
];
|
|
77
75
|
return value;
|
|
78
76
|
}
|
|
79
|
-
|
|
80
77
|
//#endregion
|
|
81
78
|
//#region src/layout/components/box.ts
|
|
82
79
|
/**
|
|
@@ -189,7 +186,6 @@ function measureBoxSize(element, ctx, availableWidth, measureChild) {
|
|
|
189
186
|
height: typeof element.height === "number" ? element.height : intrinsicHeight
|
|
190
187
|
};
|
|
191
188
|
}
|
|
192
|
-
|
|
193
189
|
//#endregion
|
|
194
190
|
//#region src/layout/components/customDraw.ts
|
|
195
191
|
/**
|
|
@@ -206,7 +202,6 @@ function measureCustomDrawSize(element, ctx, availableWidth, measureChild) {
|
|
|
206
202
|
height: 0
|
|
207
203
|
};
|
|
208
204
|
}
|
|
209
|
-
|
|
210
205
|
//#endregion
|
|
211
206
|
//#region src/layout/components/image.ts
|
|
212
207
|
/**
|
|
@@ -232,7 +227,6 @@ function measureImageSize(element, _ctx, _availableWidth) {
|
|
|
232
227
|
height: 0
|
|
233
228
|
};
|
|
234
229
|
}
|
|
235
|
-
|
|
236
230
|
//#endregion
|
|
237
231
|
//#region src/layout/components/richtext.ts
|
|
238
232
|
/**
|
|
@@ -400,7 +394,6 @@ function wrapRichText(ctx, spans, maxWidth, lineHeightScale = 1.2, elementStyle
|
|
|
400
394
|
}];
|
|
401
395
|
return lines;
|
|
402
396
|
}
|
|
403
|
-
|
|
404
397
|
//#endregion
|
|
405
398
|
//#region src/layout/components/stack.ts
|
|
406
399
|
/**
|
|
@@ -437,7 +430,6 @@ function measureStackSize(element, ctx, availableWidth, measureChild) {
|
|
|
437
430
|
height: typeof element.height === "number" ? element.height : intrinsicHeight
|
|
438
431
|
};
|
|
439
432
|
}
|
|
440
|
-
|
|
441
433
|
//#endregion
|
|
442
434
|
//#region src/layout/components/svg.ts
|
|
443
435
|
/**
|
|
@@ -471,7 +463,6 @@ function measureSvgSize(element, _ctx, _availableWidth) {
|
|
|
471
463
|
height: 0
|
|
472
464
|
};
|
|
473
465
|
}
|
|
474
|
-
|
|
475
466
|
//#endregion
|
|
476
467
|
//#region src/render/utils/font.ts
|
|
477
468
|
/**
|
|
@@ -482,7 +473,6 @@ function measureSvgSize(element, _ctx, _availableWidth) {
|
|
|
482
473
|
function buildFontString(font) {
|
|
483
474
|
return `${font.style ?? "normal"} ${font.weight ?? "normal"} ${font.size ?? 16}px ${font.family ?? "sans-serif"}`;
|
|
484
475
|
}
|
|
485
|
-
|
|
486
476
|
//#endregion
|
|
487
477
|
//#region src/layout/utils/measure.ts
|
|
488
478
|
function createCanvasMeasureContext(ctx) {
|
|
@@ -574,7 +564,6 @@ function truncateText(ctx, text, maxWidth, font, ellipsis = "...") {
|
|
|
574
564
|
offset
|
|
575
565
|
};
|
|
576
566
|
}
|
|
577
|
-
|
|
578
567
|
//#endregion
|
|
579
568
|
//#region src/layout/components/text.ts
|
|
580
569
|
/**
|
|
@@ -600,7 +589,6 @@ function measureTextSize(element, ctx, availableWidth) {
|
|
|
600
589
|
height: Math.max(height, lineHeightPx)
|
|
601
590
|
};
|
|
602
591
|
}
|
|
603
|
-
|
|
604
592
|
//#endregion
|
|
605
593
|
//#region src/layout/components/transform.ts
|
|
606
594
|
/**
|
|
@@ -611,7 +599,6 @@ function measureTextSize(element, ctx, availableWidth) {
|
|
|
611
599
|
function measureTransformSize(element, ctx, availableWidth, measureIntrinsicSize) {
|
|
612
600
|
return measureIntrinsicSize(element.children, ctx, availableWidth);
|
|
613
601
|
}
|
|
614
|
-
|
|
615
602
|
//#endregion
|
|
616
603
|
//#region src/layout/components/index.ts
|
|
617
604
|
/**
|
|
@@ -633,7 +620,6 @@ function measureIntrinsicSize(element, ctx, availableWidth) {
|
|
|
633
620
|
};
|
|
634
621
|
}
|
|
635
622
|
}
|
|
636
|
-
|
|
637
623
|
//#endregion
|
|
638
624
|
//#region src/layout/utils/offset.ts
|
|
639
625
|
/**
|
|
@@ -646,7 +632,6 @@ function applyOffset(node, dx, dy) {
|
|
|
646
632
|
node.layout.contentY += dy;
|
|
647
633
|
for (const child of node.children) applyOffset(child, dx, dy);
|
|
648
634
|
}
|
|
649
|
-
|
|
650
635
|
//#endregion
|
|
651
636
|
//#region src/types/layout.ts
|
|
652
637
|
function resolveSize(size, available, auto) {
|
|
@@ -661,7 +646,6 @@ function sizeNeedsParent(size) {
|
|
|
661
646
|
if (typeof size === "string" && size.endsWith("%")) return true;
|
|
662
647
|
return false;
|
|
663
648
|
}
|
|
664
|
-
|
|
665
649
|
//#endregion
|
|
666
650
|
//#region src/layout/engine.ts
|
|
667
651
|
/**
|
|
@@ -1079,7 +1063,6 @@ function computeLayoutImpl(element, ctx, constraints, x = 0, y = 0) {
|
|
|
1079
1063
|
}
|
|
1080
1064
|
return node;
|
|
1081
1065
|
}
|
|
1082
|
-
|
|
1083
1066
|
//#endregion
|
|
1084
1067
|
//#region src/render/utils/colors.ts
|
|
1085
1068
|
function isGradientDescriptor$1(color) {
|
|
@@ -1115,7 +1098,6 @@ function resolveColor$1(ctx, color, x, y, width, height) {
|
|
|
1115
1098
|
if (isGradientDescriptor$1(color)) return resolveGradient$1(ctx, color, x, y, width, height);
|
|
1116
1099
|
return color;
|
|
1117
1100
|
}
|
|
1118
|
-
|
|
1119
1101
|
//#endregion
|
|
1120
1102
|
//#region src/render/utils/shadows.ts
|
|
1121
1103
|
function applyShadow$1(ctx, shadow) {
|
|
@@ -1137,7 +1119,6 @@ function clearShadow$1(ctx) {
|
|
|
1137
1119
|
ctx.shadowBlur = 0;
|
|
1138
1120
|
ctx.shadowColor = "transparent";
|
|
1139
1121
|
}
|
|
1140
|
-
|
|
1141
1122
|
//#endregion
|
|
1142
1123
|
//#region src/render/utils/shapes.ts
|
|
1143
1124
|
function roundRectPath(ctx, x, y, width, height, radius) {
|
|
@@ -1154,7 +1135,6 @@ function roundRectPath(ctx, x, y, width, height, radius) {
|
|
|
1154
1135
|
ctx.quadraticCurveTo(x, y, x + tl, y);
|
|
1155
1136
|
ctx.closePath();
|
|
1156
1137
|
}
|
|
1157
|
-
|
|
1158
1138
|
//#endregion
|
|
1159
1139
|
//#region src/render/components/box.ts
|
|
1160
1140
|
function renderBox(ctx, node) {
|
|
@@ -1183,7 +1163,6 @@ function renderBox(ctx, node) {
|
|
|
1183
1163
|
}
|
|
1184
1164
|
if (element.opacity !== void 0 && element.opacity < 1) ctx.globalAlpha = 1;
|
|
1185
1165
|
}
|
|
1186
|
-
|
|
1187
1166
|
//#endregion
|
|
1188
1167
|
//#region src/render/components/ProxiedCanvasContext.ts
|
|
1189
1168
|
/**
|
|
@@ -1301,7 +1280,6 @@ function createProxiedCanvasContext(ctx, baseTransform) {
|
|
|
1301
1280
|
}
|
|
1302
1281
|
});
|
|
1303
1282
|
}
|
|
1304
|
-
|
|
1305
1283
|
//#endregion
|
|
1306
1284
|
//#region src/render/components/customDraw.ts
|
|
1307
1285
|
/**
|
|
@@ -1329,7 +1307,6 @@ function renderCustomDraw(ctx, node) {
|
|
|
1329
1307
|
proxyCtx.destroy();
|
|
1330
1308
|
ctx.restore();
|
|
1331
1309
|
}
|
|
1332
|
-
|
|
1333
1310
|
//#endregion
|
|
1334
1311
|
//#region src/render/components/image.ts
|
|
1335
1312
|
function renderImage(ctx, node) {
|
|
@@ -1415,7 +1392,6 @@ function renderImage(ctx, node) {
|
|
|
1415
1392
|
}
|
|
1416
1393
|
if (element.opacity !== void 0 && element.opacity < 1) ctx.globalAlpha = 1;
|
|
1417
1394
|
}
|
|
1418
|
-
|
|
1419
1395
|
//#endregion
|
|
1420
1396
|
//#region src/render/components/richtext.ts
|
|
1421
1397
|
function renderRichText(ctx, node) {
|
|
@@ -1466,7 +1442,6 @@ function renderRichText(ctx, node) {
|
|
|
1466
1442
|
currentY += line.height;
|
|
1467
1443
|
}
|
|
1468
1444
|
}
|
|
1469
|
-
|
|
1470
1445
|
//#endregion
|
|
1471
1446
|
//#region src/render/components/svg.ts
|
|
1472
1447
|
function isGradientDescriptor(color) {
|
|
@@ -1738,7 +1713,6 @@ function renderSvg(ctx, node) {
|
|
|
1738
1713
|
for (const child of element.children) renderSvgChild(ctx, child, transform, bounds, baseTransform);
|
|
1739
1714
|
ctx.restore();
|
|
1740
1715
|
}
|
|
1741
|
-
|
|
1742
1716
|
//#endregion
|
|
1743
1717
|
//#region src/render/components/text.ts
|
|
1744
1718
|
function renderText(ctx, node) {
|
|
@@ -1773,7 +1747,6 @@ function renderText(ctx, node) {
|
|
|
1773
1747
|
}
|
|
1774
1748
|
if (element.shadow) clearShadow$1(ctx);
|
|
1775
1749
|
}
|
|
1776
|
-
|
|
1777
1750
|
//#endregion
|
|
1778
1751
|
//#region src/render/components/transform.ts
|
|
1779
1752
|
/**
|
|
@@ -1849,7 +1822,6 @@ function renderTransform(ctx, node) {
|
|
|
1849
1822
|
renderNode(ctx, childNode);
|
|
1850
1823
|
ctx.restore();
|
|
1851
1824
|
}
|
|
1852
|
-
|
|
1853
1825
|
//#endregion
|
|
1854
1826
|
//#region src/render/index.ts
|
|
1855
1827
|
function renderNode(ctx, node) {
|
|
@@ -1889,7 +1861,6 @@ function renderNode(ctx, node) {
|
|
|
1889
1861
|
break;
|
|
1890
1862
|
}
|
|
1891
1863
|
}
|
|
1892
|
-
|
|
1893
1864
|
//#endregion
|
|
1894
1865
|
//#region src/canvas.ts
|
|
1895
1866
|
/**
|
|
@@ -1959,7 +1930,6 @@ function createCanvas(options) {
|
|
|
1959
1930
|
}
|
|
1960
1931
|
};
|
|
1961
1932
|
}
|
|
1962
|
-
|
|
1963
1933
|
//#endregion
|
|
1964
1934
|
//#region src/components/Box.ts
|
|
1965
1935
|
function Box(props) {
|
|
@@ -1968,7 +1938,6 @@ function Box(props) {
|
|
|
1968
1938
|
...props
|
|
1969
1939
|
};
|
|
1970
1940
|
}
|
|
1971
|
-
|
|
1972
1941
|
//#endregion
|
|
1973
1942
|
//#region src/components/CustomDraw.ts
|
|
1974
1943
|
function CustomDraw(props) {
|
|
@@ -1977,7 +1946,6 @@ function CustomDraw(props) {
|
|
|
1977
1946
|
...props
|
|
1978
1947
|
};
|
|
1979
1948
|
}
|
|
1980
|
-
|
|
1981
1949
|
//#endregion
|
|
1982
1950
|
//#region src/components/Image.ts
|
|
1983
1951
|
function Image(props) {
|
|
@@ -1986,7 +1954,6 @@ function Image(props) {
|
|
|
1986
1954
|
...props
|
|
1987
1955
|
};
|
|
1988
1956
|
}
|
|
1989
|
-
|
|
1990
1957
|
//#endregion
|
|
1991
1958
|
//#region src/components/RichText.ts
|
|
1992
1959
|
function RichText(props) {
|
|
@@ -1995,7 +1962,6 @@ function RichText(props) {
|
|
|
1995
1962
|
...props
|
|
1996
1963
|
};
|
|
1997
1964
|
}
|
|
1998
|
-
|
|
1999
1965
|
//#endregion
|
|
2000
1966
|
//#region src/components/Stack.ts
|
|
2001
1967
|
function Stack(props) {
|
|
@@ -2004,7 +1970,6 @@ function Stack(props) {
|
|
|
2004
1970
|
...props
|
|
2005
1971
|
};
|
|
2006
1972
|
}
|
|
2007
|
-
|
|
2008
1973
|
//#endregion
|
|
2009
1974
|
//#region src/components/Svg.ts
|
|
2010
1975
|
function Svg(props) {
|
|
@@ -2051,7 +2016,6 @@ const svg = {
|
|
|
2051
2016
|
...props
|
|
2052
2017
|
})
|
|
2053
2018
|
};
|
|
2054
|
-
|
|
2055
2019
|
//#endregion
|
|
2056
2020
|
//#region src/components/Text.ts
|
|
2057
2021
|
function Text(props) {
|
|
@@ -2060,7 +2024,6 @@ function Text(props) {
|
|
|
2060
2024
|
...props
|
|
2061
2025
|
};
|
|
2062
2026
|
}
|
|
2063
|
-
|
|
2064
2027
|
//#endregion
|
|
2065
2028
|
//#region src/components/Transform.ts
|
|
2066
2029
|
function Transform(props) {
|
|
@@ -2069,7 +2032,6 @@ function Transform(props) {
|
|
|
2069
2032
|
...props
|
|
2070
2033
|
};
|
|
2071
2034
|
}
|
|
2072
|
-
|
|
2073
2035
|
//#endregion
|
|
2074
2036
|
//#region src/layout/utils/print.ts
|
|
2075
2037
|
/**
|
|
@@ -2129,7 +2091,6 @@ function printLayout(node) {
|
|
|
2129
2091
|
function layoutToString(node, _indent = " ") {
|
|
2130
2092
|
return printLayoutToString(node, "", true).join("\n");
|
|
2131
2093
|
}
|
|
2132
|
-
|
|
2133
2094
|
//#endregion
|
|
2134
2095
|
exports.Box = Box;
|
|
2135
2096
|
exports.CustomDraw = CustomDraw;
|
|
@@ -2146,4 +2107,4 @@ exports.layoutToString = layoutToString;
|
|
|
2146
2107
|
exports.linearGradient = linearGradient;
|
|
2147
2108
|
exports.printLayout = printLayout;
|
|
2148
2109
|
exports.radialGradient = radialGradient;
|
|
2149
|
-
exports.svg = svg;
|
|
2110
|
+
exports.svg = svg;
|