@tarve/core 0.3.0 → 0.5.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/CHANGELOG.md +101 -1
- package/README.md +68 -11
- package/dist/npm/build.js +830 -84
- package/dist/npm/cli.js +1094 -117
- package/dist/npm/embedded-assets.js +35 -4
- package/dist/npm/index.js +2515 -207
- package/dist/npm/native-runtime.json +3 -3
- package/dist/npm/node-build.js +865 -0
- package/dist/npm/protocol.js +1 -1
- package/dist/npm/runtime.js +5 -5
- package/dist/types/core/app-metadata.d.ts +49 -0
- package/dist/types/core/build.d.ts +21 -0
- package/dist/types/core/cli.d.ts +1 -1
- package/dist/types/core/esbuild-file-imports.d.ts +8 -0
- package/dist/types/core/node-build.d.ts +7 -0
- package/dist/types/core/node-dev.d.ts +4 -0
- package/dist/types/core/node-target.d.ts +10 -0
- package/dist/types/core/runtime-select.d.ts +8 -0
- package/dist/types/core/src/app-metadata.d.ts +16 -0
- package/dist/types/core/src/app.d.ts +87 -2
- package/dist/types/core/src/assets.d.ts +4 -0
- package/dist/types/core/src/bridge/binding.d.ts +10 -34
- package/dist/types/core/src/canvas.d.ts +161 -0
- package/dist/types/core/src/components/image.d.ts +7 -3
- package/dist/types/core/src/components/layout.d.ts +4 -3
- package/dist/types/core/src/components/pressable.d.ts +2 -2
- package/dist/types/core/src/embedded-assets.d.ts +12 -2
- package/dist/types/core/src/extra-controls.d.ts +1 -1
- package/dist/types/core/src/html-elements.d.ts +26 -0
- package/dist/types/core/src/index.d.ts +5 -2
- package/dist/types/core/src/inline-text.d.ts +21 -0
- package/dist/types/core/src/jsx-runtime.d.ts +175 -4
- package/dist/types/core/src/media-element.d.ts +71 -0
- package/dist/types/core/src/memo.d.ts +18 -0
- package/dist/types/core/src/png.d.ts +29 -0
- package/dist/types/core/src/popups.d.ts +3 -2
- package/dist/types/core/src/reconciler.d.ts +27 -3
- package/dist/types/core/src/test-renderer.d.ts +2 -0
- package/dist/types/core/src/theme.d.ts +2 -1
- package/dist/types/core/src/virtual-list.d.ts +5 -1
- package/dist/types/core/windows-executable.d.ts +16 -0
- package/dist/types/protocol/src/index.d.ts +206 -6
- package/native/linux-x64/libtarve_native.so +0 -0
- package/native/linux-x64/runtime.json +4 -4
- package/native/win32-x64/runtime.json +4 -4
- package/native/win32-x64/tarve_native.dll +0 -0
- package/package.json +11 -2
package/dist/npm/index.js
CHANGED
|
@@ -35,22 +35,7 @@ function Portal(props) {
|
|
|
35
35
|
return container("view", { ...props, portal: true });
|
|
36
36
|
}
|
|
37
37
|
// packages/core/src/css-shadow.ts
|
|
38
|
-
var NAMED = {
|
|
39
|
-
transparent: "#00000000",
|
|
40
|
-
black: "#000000",
|
|
41
|
-
white: "#ffffff",
|
|
42
|
-
red: "#ff0000",
|
|
43
|
-
green: "#008000",
|
|
44
|
-
blue: "#0000ff",
|
|
45
|
-
gray: "#808080",
|
|
46
|
-
grey: "#808080",
|
|
47
|
-
yellow: "#ffff00",
|
|
48
|
-
orange: "#ffa500",
|
|
49
|
-
purple: "#800080",
|
|
50
|
-
pink: "#ffc0cb",
|
|
51
|
-
cyan: "#00ffff",
|
|
52
|
-
magenta: "#ff00ff"
|
|
53
|
-
};
|
|
38
|
+
var NAMED = Object.fromEntries("aliceblue f0f8ff antiquewhite faebd7 aqua 00ffff aquamarine 7fffd4 azure f0ffff beige f5f5dc bisque ffe4c4 black 000000 blanchedalmond ffebcd blue 0000ff blueviolet 8a2be2 brown a52a2a burlywood deb887 cadetblue 5f9ea0 chartreuse 7fff00 chocolate d2691e coral ff7f50 cornflowerblue 6495ed cornsilk fff8dc crimson dc143c cyan 00ffff darkblue 00008b darkcyan 008b8b darkgoldenrod b8860b darkgray a9a9a9 darkgreen 006400 darkgrey a9a9a9 darkkhaki bdb76b darkmagenta 8b008b darkolivegreen 556b2f darkorange ff8c00 darkorchid 9932cc darkred 8b0000 darksalmon e9967a darkseagreen 8fbc8f darkslateblue 483d8b darkslategray 2f4f4f darkslategrey 2f4f4f darkturquoise 00ced1 darkviolet 9400d3 deeppink ff1493 deepskyblue 00bfff dimgray 696969 dimgrey 696969 dodgerblue 1e90ff firebrick b22222 floralwhite fffaf0 forestgreen 228b22 fuchsia ff00ff gainsboro dcdcdc ghostwhite f8f8ff gold ffd700 goldenrod daa520 gray 808080 green 008000 greenyellow adff2f grey 808080 honeydew f0fff0 hotpink ff69b4 indianred cd5c5c indigo 4b0082 ivory fffff0 khaki f0e68c lavender e6e6fa lavenderblush fff0f5 lawngreen 7cfc00 lemonchiffon fffacd lightblue add8e6 lightcoral f08080 lightcyan e0ffff lightgoldenrodyellow fafad2 lightgray d3d3d3 lightgreen 90ee90 lightgrey d3d3d3 lightpink ffb6c1 lightsalmon ffa07a lightseagreen 20b2aa lightskyblue 87cefa lightslategray 778899 lightslategrey 778899 lightsteelblue b0c4de lightyellow ffffe0 lime 00ff00 limegreen 32cd32 linen faf0e6 magenta ff00ff maroon 800000 mediumaquamarine 66cdaa mediumblue 0000cd mediumorchid ba55d3 mediumpurple 9370db mediumseagreen 3cb371 mediumslateblue 7b68ee mediumspringgreen 00fa9a mediumturquoise 48d1cc mediumvioletred c71585 midnightblue 191970 mintcream f5fffa mistyrose ffe4e1 moccasin ffe4b5 navajowhite ffdead navy 000080 oldlace fdf5e6 olive 808000 olivedrab 6b8e23 orange ffa500 orangered ff4500 orchid da70d6 palegoldenrod eee8aa palegreen 98fb98 paleturquoise afeeee palevioletred db7093 papayawhip ffefd5 peachpuff ffdab9 peru cd853f pink ffc0cb plum dda0dd powderblue b0e0e6 purple 800080 rebeccapurple 663399 red ff0000 rosybrown bc8f8f royalblue 4169e1 saddlebrown 8b4513 salmon fa8072 sandybrown f4a460 seagreen 2e8b57 seashell fff5ee sienna a0522d silver c0c0c0 skyblue 87ceeb slateblue 6a5acd slategray 708090 slategrey 708090 snow fffafa springgreen 00ff7f steelblue 4682b4 tan d2b48c teal 008080 thistle d8bfd8 tomato ff6347 turquoise 40e0d0 violet ee82ee wheat f5deb3 white ffffff whitesmoke f5f5f5 yellow ffff00 yellowgreen 9acd32 transparent 00000000".split(" ").flatMap((word, index, words) => index % 2 === 0 ? [[word, `#${words[index + 1]}`]] : []));
|
|
54
39
|
function hex2(value) {
|
|
55
40
|
return Math.round(Math.min(255, Math.max(0, value))).toString(16).padStart(2, "0");
|
|
56
41
|
}
|
|
@@ -228,7 +213,7 @@ function parseTransform(value) {
|
|
|
228
213
|
...scaleX === scaleY ? scaleX !== 1 ? { scale: scaleX } : {} : { scaleX, scaleY }
|
|
229
214
|
};
|
|
230
215
|
}
|
|
231
|
-
var GRADIENT = /^\s*(repeating-)?(linear|radial)-gradient\(/i;
|
|
216
|
+
var GRADIENT = /^\s*(repeating-)?(linear|radial|conic)-gradient\(/i;
|
|
232
217
|
function angle(token) {
|
|
233
218
|
const match = token.match(/^(-?(?:\d+\.?\d*|\.\d+))(deg|rad|turn|grad)$/);
|
|
234
219
|
if (!match)
|
|
@@ -326,13 +311,50 @@ function centre(tokens) {
|
|
|
326
311
|
return result;
|
|
327
312
|
}
|
|
328
313
|
var EXTENT = /^(closest|farthest)-(side|corner)$/;
|
|
314
|
+
function turn(token) {
|
|
315
|
+
if (token === "0")
|
|
316
|
+
return 0;
|
|
317
|
+
if (/^-?(?:\d+\.?\d*|\.\d+)%$/.test(token))
|
|
318
|
+
return Number(token.slice(0, -1)) / 100;
|
|
319
|
+
const degrees = angle(token);
|
|
320
|
+
if (degrees === undefined)
|
|
321
|
+
throw new TypeError(`Conic gradient positions must be angles or %: ${token}`);
|
|
322
|
+
return degrees / 360;
|
|
323
|
+
}
|
|
324
|
+
function parseConicStop(token) {
|
|
325
|
+
const [color, ...positions] = splitTopLevel(token, /\s/);
|
|
326
|
+
if (!color || positions.length > 2)
|
|
327
|
+
throw new TypeError(`Invalid colour stop: ${token}`);
|
|
328
|
+
return positions.length === 0 ? [{ color }] : positions.map((value) => ({ color, offset: turn(value) }));
|
|
329
|
+
}
|
|
330
|
+
function conicHeader(words) {
|
|
331
|
+
if (words[0] !== "from" && words[0] !== "at")
|
|
332
|
+
return;
|
|
333
|
+
const at = words.indexOf("at");
|
|
334
|
+
const before = at < 0 ? words : words.slice(0, at);
|
|
335
|
+
const header = {};
|
|
336
|
+
if (before.length > 0) {
|
|
337
|
+
const degrees = before.length === 2 && before[0] === "from" ? before[1] === "0" ? 0 : angle(before[1]) : undefined;
|
|
338
|
+
if (degrees === undefined)
|
|
339
|
+
throw new TypeError(`Invalid conic-gradient angle: ${words.join(" ")}`);
|
|
340
|
+
if (degrees !== 0)
|
|
341
|
+
header.from = degrees;
|
|
342
|
+
}
|
|
343
|
+
if (at >= 0)
|
|
344
|
+
header.at = centre(words.slice(at + 1));
|
|
345
|
+
return header;
|
|
346
|
+
}
|
|
329
347
|
function parseGradient(value) {
|
|
330
|
-
const match = value.trim().match(/^(repeating-)?(linear|radial)-gradient\(([\s\S]*)\)$/i);
|
|
348
|
+
const match = value.trim().match(/^(repeating-)?(linear|radial|conic)-gradient\(([\s\S]*)\)$/i);
|
|
331
349
|
if (!match)
|
|
332
350
|
throw new TypeError(`Unsupported gradient: ${value}`);
|
|
333
351
|
const repeating = match[1] ? { repeating: true } : {};
|
|
334
352
|
const args = splitTopLevel(match[3], /,/);
|
|
335
|
-
const first = (args[0] ?? "").toLowerCase().split(/\s+/);
|
|
353
|
+
const first = (args[0] ?? "").toLowerCase().trim().split(/\s+/);
|
|
354
|
+
if (match[2].toLowerCase() === "conic") {
|
|
355
|
+
const header = conicHeader(first);
|
|
356
|
+
return { type: "conic", ...header, ...repeating, stops: (header ? args.slice(1) : args).flatMap(parseConicStop) };
|
|
357
|
+
}
|
|
336
358
|
if (match[2].toLowerCase() === "linear") {
|
|
337
359
|
const degrees = first.length === 1 ? angle(first[0]) : undefined;
|
|
338
360
|
if (degrees !== undefined)
|
|
@@ -386,12 +408,12 @@ function parseGradient(value) {
|
|
|
386
408
|
function normalizeGradient(gradient, colour) {
|
|
387
409
|
if (gradient.stops.length === 0)
|
|
388
410
|
throw new TypeError("A gradient needs at least one colour stop");
|
|
411
|
+
const conic = gradient.type === "conic";
|
|
389
412
|
const stops = gradient.stops.map((stop) => {
|
|
390
413
|
const { color, offset } = typeof stop === "string" ? { color: stop, offset: undefined } : stop;
|
|
391
414
|
let resolved = offset;
|
|
392
415
|
if (typeof offset === "string") {
|
|
393
|
-
|
|
394
|
-
resolved = parsed;
|
|
416
|
+
resolved = conic ? turn(offset.trim()) : position(offset.trim());
|
|
395
417
|
} else if (offset !== undefined && !Number.isFinite(offset)) {
|
|
396
418
|
throw new TypeError(`Invalid gradient offset: ${offset}`);
|
|
397
419
|
}
|
|
@@ -455,6 +477,7 @@ var lightTheme = {
|
|
|
455
477
|
destructiveForeground: "#ffffff",
|
|
456
478
|
destructiveHover: "#b91c1c",
|
|
457
479
|
destructiveActive: "#991b1b",
|
|
480
|
+
destructiveText: "#dc2626",
|
|
458
481
|
ring: "#a1a1aa",
|
|
459
482
|
ringSoft: "#aeaeb6",
|
|
460
483
|
success: "#15803d",
|
|
@@ -528,6 +551,7 @@ var darkTheme = {
|
|
|
528
551
|
destructiveForeground: "#fafafa",
|
|
529
552
|
destructiveHover: "#991b1b",
|
|
530
553
|
destructiveActive: "#b91c1c",
|
|
554
|
+
destructiveText: "#f87171",
|
|
531
555
|
ring: "#d4d4d8",
|
|
532
556
|
ringSoft: "#b1b1b5",
|
|
533
557
|
success: "#4ade80",
|
|
@@ -605,10 +629,20 @@ function resolveShadowColors(style, selected) {
|
|
|
605
629
|
}
|
|
606
630
|
}
|
|
607
631
|
var COLOR_KEY = /^(background|foreground|color)$|(Color|Background|Foreground|Accent|Rule)$/;
|
|
632
|
+
var resolvedStrings = new WeakMap;
|
|
608
633
|
function resolveStyleString(key, value, selected) {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
634
|
+
let cache = resolvedStrings.get(selected);
|
|
635
|
+
if (!cache)
|
|
636
|
+
resolvedStrings.set(selected, cache = new Map);
|
|
637
|
+
const cacheKey = key + "\x00" + value;
|
|
638
|
+
let resolved = cache.get(cacheKey);
|
|
639
|
+
if (resolved === undefined) {
|
|
640
|
+
if (cache.size > 4096)
|
|
641
|
+
cache.clear();
|
|
642
|
+
resolved = PAINT_KEYS.includes(key) && GRADIENT.test(value) ? value : resolveThemeColor(COLOR_KEY.test(key) ? cssColor(value) : value, selected);
|
|
643
|
+
cache.set(cacheKey, resolved);
|
|
644
|
+
}
|
|
645
|
+
return resolved;
|
|
612
646
|
}
|
|
613
647
|
function resolveThemeStyle(style, selected) {
|
|
614
648
|
const resolved = { ...style };
|
|
@@ -682,12 +716,13 @@ function Pressable(props) {
|
|
|
682
716
|
}
|
|
683
717
|
// packages/protocol/src/index.ts
|
|
684
718
|
var NATIVE_ABI_VERSION = 5;
|
|
685
|
-
var PROTOCOL_VERSION =
|
|
719
|
+
var PROTOCOL_VERSION = 58;
|
|
686
720
|
|
|
687
721
|
// packages/core/src/bridge/binding.ts
|
|
688
|
-
import {
|
|
722
|
+
import { createRequire } from "module";
|
|
689
723
|
function openLibrary(path) {
|
|
690
|
-
|
|
724
|
+
const require2 = createRequire(import.meta.url);
|
|
725
|
+
const definitions = {
|
|
691
726
|
tarve_abi_version: { args: [], returns: "u32" },
|
|
692
727
|
tarve_start: { args: ["buffer", "u32"], returns: "i32" },
|
|
693
728
|
tarve_send: { args: ["buffer", "u32"], returns: "i32" },
|
|
@@ -696,7 +731,22 @@ function openLibrary(path) {
|
|
|
696
731
|
tarve_open_external: { args: ["buffer", "u32"], returns: "i32" },
|
|
697
732
|
tarve_last_error: { args: ["buffer", "u32"], returns: "i32" },
|
|
698
733
|
tarve_join: { args: [], returns: "i32" }
|
|
699
|
-
}
|
|
734
|
+
};
|
|
735
|
+
if (process.versions.bun) {
|
|
736
|
+
const { dlopen } = require2("bun:ffi");
|
|
737
|
+
return dlopen(path, definitions);
|
|
738
|
+
}
|
|
739
|
+
const [major = 0, minor = 0] = (process.versions.node ?? "").split(".").map(Number);
|
|
740
|
+
if (major < 26 || major === 26 && minor < 10) {
|
|
741
|
+
throw new Error(`Tarve requires Bun or Node.js 26.10+ with node:ffi (found Node.js ${process.versions.node ?? "unknown"})`);
|
|
742
|
+
}
|
|
743
|
+
const { dlopen } = require2("node:ffi");
|
|
744
|
+
const signatures = Object.fromEntries(Object.entries(definitions).map(([name, signature]) => [name, {
|
|
745
|
+
arguments: signature.args.map((type) => type === "buffer" ? "buffer" : type === "u32" ? "uint32" : "int32"),
|
|
746
|
+
return: signature.returns === "u32" ? "uint32" : "int32"
|
|
747
|
+
}]));
|
|
748
|
+
const library = dlopen(path, signatures);
|
|
749
|
+
return { symbols: library.functions, close: () => library.lib.close() };
|
|
700
750
|
}
|
|
701
751
|
|
|
702
752
|
// packages/core/src/bridge/index.ts
|
|
@@ -929,6 +979,17 @@ function canonicalizeIntrinsicStyle(style) {
|
|
|
929
979
|
result.background = result.backgroundColor;
|
|
930
980
|
if (result.foreground === undefined && result.color !== undefined)
|
|
931
981
|
result.foreground = result.color;
|
|
982
|
+
if (result.radius === undefined && result.borderRadius !== undefined)
|
|
983
|
+
result.radius = result.borderRadius;
|
|
984
|
+
delete result.borderRadius;
|
|
985
|
+
const edge = (value) => value === "flex-start" ? "start" : value === "flex-end" ? "end" : value === "space-between" ? "between" : value;
|
|
986
|
+
if (result.align === undefined && result.alignItems !== undefined)
|
|
987
|
+
result.align = edge(result.alignItems);
|
|
988
|
+
if (result.justify === undefined && result.justifyContent !== undefined)
|
|
989
|
+
result.justify = edge(result.justifyContent);
|
|
990
|
+
delete result.alignItems;
|
|
991
|
+
delete result.justifyContent;
|
|
992
|
+
delete result.objectFit;
|
|
932
993
|
delete result.flexDirection;
|
|
933
994
|
delete result.backgroundColor;
|
|
934
995
|
delete result.color;
|
|
@@ -946,11 +1007,9 @@ function Text({ size, weight, color, style, ...props }) {
|
|
|
946
1007
|
return jsx("text", {
|
|
947
1008
|
...props,
|
|
948
1009
|
style: {
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
fontWeight: weight ?? 400,
|
|
953
|
-
foreground: color ?? theme.colors.foreground,
|
|
1010
|
+
...size !== undefined ? { fontSize: size } : {},
|
|
1011
|
+
...weight !== undefined ? { fontWeight: weight } : {},
|
|
1012
|
+
...color !== undefined ? { foreground: color } : {},
|
|
954
1013
|
...canonicalStyle
|
|
955
1014
|
}
|
|
956
1015
|
});
|
|
@@ -1171,10 +1230,6 @@ function Markdown(props) {
|
|
|
1171
1230
|
...props,
|
|
1172
1231
|
onMarkdownLink: (href) => props.onLinkClick ? props.onLinkClick(href) : openExternal(href),
|
|
1173
1232
|
style: {
|
|
1174
|
-
fontFamily: theme.font.family,
|
|
1175
|
-
fontSize: theme.font.size,
|
|
1176
|
-
lineHeight: theme.font.lineHeight,
|
|
1177
|
-
foreground: theme.colors.foreground,
|
|
1178
1233
|
mutedForeground: theme.colors.mutedForeground,
|
|
1179
1234
|
taskMarkerColor: theme.colors.primary,
|
|
1180
1235
|
taskMarkerCheckColor: theme.colors.primaryForeground,
|
|
@@ -1317,7 +1372,6 @@ function composedContent(child, foreground) {
|
|
|
1317
1372
|
...props,
|
|
1318
1373
|
style: {
|
|
1319
1374
|
fontSize: 14,
|
|
1320
|
-
fontFamily: theme.font.family,
|
|
1321
1375
|
lineHeight: theme.font.lineHeight,
|
|
1322
1376
|
fontWeight: 500,
|
|
1323
1377
|
foreground,
|
|
@@ -1338,7 +1392,6 @@ function Button({ variant = "default", size = "default", style, disabled, contro
|
|
|
1338
1392
|
padding: { left: 14, right: 14 },
|
|
1339
1393
|
radius: theme.radius.sm,
|
|
1340
1394
|
fontSize: 14,
|
|
1341
|
-
fontFamily: theme.font.family,
|
|
1342
1395
|
lineHeight: theme.font.lineHeight,
|
|
1343
1396
|
fontWeight: 500,
|
|
1344
1397
|
userSelect: "none",
|
|
@@ -1447,13 +1500,22 @@ function dataUrlSource(value) {
|
|
|
1447
1500
|
validateEncodedBytes(bytes);
|
|
1448
1501
|
return { bytes, ...mediaType ? { mediaType } : {} };
|
|
1449
1502
|
}
|
|
1503
|
+
var serializedSources = new WeakMap;
|
|
1450
1504
|
function serializeImageSource(source) {
|
|
1505
|
+
if (typeof source === "object" && !(source instanceof Uint8Array)) {
|
|
1506
|
+
const cached = serializedSources.get(source);
|
|
1507
|
+
if (cached)
|
|
1508
|
+
return cached;
|
|
1509
|
+
const serialized = serializeImageSourceNow(source);
|
|
1510
|
+
serializedSources.set(source, serialized);
|
|
1511
|
+
return serialized;
|
|
1512
|
+
}
|
|
1513
|
+
return serializeImageSourceNow(source);
|
|
1514
|
+
}
|
|
1515
|
+
function serializeImageSourceNow(source) {
|
|
1451
1516
|
if (typeof source === "string") {
|
|
1452
1517
|
if (source.startsWith("data:"))
|
|
1453
|
-
return
|
|
1454
|
-
if (/^https?:\/\//i.test(source)) {
|
|
1455
|
-
throw new TypeError("HTTP(S) Image sources must be loaded with await loadImageSource(url) before rendering");
|
|
1456
|
-
}
|
|
1518
|
+
return serializeImageSourceNow(dataUrlSource(source));
|
|
1457
1519
|
if (!source)
|
|
1458
1520
|
throw new TypeError("Image src must not be empty");
|
|
1459
1521
|
return { path: source };
|
|
@@ -1639,7 +1701,6 @@ function Input({ type = "text", value, style, ...props }) {
|
|
|
1639
1701
|
placeholderColor: theme.colors.placeholder,
|
|
1640
1702
|
selectionColor: theme.colors.selection,
|
|
1641
1703
|
caretColor: theme.colors.foreground,
|
|
1642
|
-
fontFamily: theme.font.family,
|
|
1643
1704
|
lineHeight: theme.font.lineHeight,
|
|
1644
1705
|
fontSize: theme.font.size,
|
|
1645
1706
|
userSelect: "text",
|
|
@@ -1664,7 +1725,6 @@ function TextArea({ style, ...props }) {
|
|
|
1664
1725
|
placeholderColor: theme.colors.placeholder,
|
|
1665
1726
|
selectionColor: theme.colors.selection,
|
|
1666
1727
|
caretColor: theme.colors.foreground,
|
|
1667
|
-
fontFamily: theme.font.family,
|
|
1668
1728
|
lineHeight: theme.font.lineHeight,
|
|
1669
1729
|
fontSize: theme.font.size,
|
|
1670
1730
|
userSelect: "text",
|
|
@@ -1673,7 +1733,12 @@ function TextArea({ style, ...props }) {
|
|
|
1673
1733
|
});
|
|
1674
1734
|
}
|
|
1675
1735
|
// packages/core/src/components/titlebar.ts
|
|
1676
|
-
function
|
|
1736
|
+
function translucent(color, alpha) {
|
|
1737
|
+
const hex = color.trim().replace(/^#/, "");
|
|
1738
|
+
const full = hex.length === 3 ? [...hex].map((c) => c + c).join("") : hex.slice(0, 6);
|
|
1739
|
+
return /^[0-9a-f]{6}$/i.test(full) ? `#${full}${Math.round(alpha).toString(16).padStart(2, "0")}` : color;
|
|
1740
|
+
}
|
|
1741
|
+
function titleBarButton(action, child, ink) {
|
|
1677
1742
|
const close = action === "close";
|
|
1678
1743
|
const label = action === "minimize" ? "Minimize window" : action === "toggleMaximize" ? "Maximize or restore window" : "Close window";
|
|
1679
1744
|
return jsx(Pressable, {
|
|
@@ -1687,8 +1752,8 @@ function titleBarButton(action, child) {
|
|
|
1687
1752
|
align: "center",
|
|
1688
1753
|
justify: "center",
|
|
1689
1754
|
background: "#00000000",
|
|
1690
|
-
hover: { background: close ? theme.colors.windowCloseHover :
|
|
1691
|
-
active: { background: close ? theme.colors.windowCloseActive :
|
|
1755
|
+
hover: { background: close ? theme.colors.windowCloseHover : translucent(ink, 31) },
|
|
1756
|
+
active: { background: close ? theme.colors.windowCloseActive : translucent(ink, 51) }
|
|
1692
1757
|
},
|
|
1693
1758
|
children: child
|
|
1694
1759
|
});
|
|
@@ -1703,18 +1768,17 @@ function TitleBar({
|
|
|
1703
1768
|
style,
|
|
1704
1769
|
...props
|
|
1705
1770
|
}) {
|
|
1706
|
-
const
|
|
1707
|
-
|
|
1708
|
-
});
|
|
1709
|
-
const maximizeIcon =
|
|
1710
|
-
|
|
1711
|
-
});
|
|
1771
|
+
const ink = typeof style?.foreground === "string" ? style.foreground : theme.colors.foreground;
|
|
1772
|
+
const glyph = (iconNode) => jsx(Icon, { iconNode, size: 12, strokeWidth: 2, color: ink });
|
|
1773
|
+
const minimizeIcon = glyph([["path", { d: "M3 12h18" }]]);
|
|
1774
|
+
const maximizeIcon = glyph([["rect", { x: 3, y: 3, width: 18, height: 18, rx: 2 }]]);
|
|
1775
|
+
const closeIcon = glyph([["path", { d: "M4 4l16 16M20 4 4 20" }]]);
|
|
1712
1776
|
const controls = jsx(Row, {
|
|
1713
1777
|
style: { height: "100%", shrink: 0 },
|
|
1714
1778
|
children: [
|
|
1715
|
-
showMinimize ? titleBarButton("minimize", minimizeIcon) : null,
|
|
1716
|
-
showMaximize ? titleBarButton("toggleMaximize", maximizeIcon) : null,
|
|
1717
|
-
showClose ? titleBarButton("close",
|
|
1779
|
+
showMinimize ? titleBarButton("minimize", minimizeIcon, ink) : null,
|
|
1780
|
+
showMaximize ? titleBarButton("toggleMaximize", maximizeIcon, ink) : null,
|
|
1781
|
+
showClose ? titleBarButton("close", closeIcon, ink) : null
|
|
1718
1782
|
]
|
|
1719
1783
|
});
|
|
1720
1784
|
const content = children ?? (title ? jsx(Text, { size: 13, weight: 500, children: title }) : null);
|
|
@@ -1989,11 +2053,12 @@ function Separator({ orientation = "horizontal", style, ...props }) {
|
|
|
1989
2053
|
}
|
|
1990
2054
|
function Progress({ value, max = 100, label, style, ...props }) {
|
|
1991
2055
|
const ratio = Number.isFinite(value) && Number.isFinite(max) && max > 0 ? Math.max(0, Math.min(value / max, 1)) : 0;
|
|
2056
|
+
const { foreground, ...track } = style ?? {};
|
|
1992
2057
|
return jsx(View, {
|
|
1993
2058
|
...props,
|
|
1994
2059
|
control: { role: "progress", label, value: ratio * max, min: 0, max },
|
|
1995
|
-
style: { width: "100%", height: 8, radius: 4, background: c.secondary, ...
|
|
1996
|
-
children: jsx(View, { style: { width: `${ratio * 100}%`, height: "100%", radius: 4, background: c.primary } })
|
|
2060
|
+
style: { width: "100%", height: 8, radius: 4, background: c.secondary, ...track },
|
|
2061
|
+
children: jsx(View, { style: { width: `${ratio * 100}%`, height: "100%", radius: track.radius ?? 4, background: foreground ?? c.primary } })
|
|
1997
2062
|
});
|
|
1998
2063
|
}
|
|
1999
2064
|
function Tabs({ value, items, onValueChange, style, ...props }) {
|
|
@@ -2201,10 +2266,16 @@ function upperBoundPrefix(prefix, offset) {
|
|
|
2201
2266
|
}
|
|
2202
2267
|
return Math.min(low, prefix.length - 2);
|
|
2203
2268
|
}
|
|
2269
|
+
var FILL_ESTIMATE = 800;
|
|
2270
|
+
var filledHeights = new WeakMap;
|
|
2271
|
+
var filling = false;
|
|
2272
|
+
function viewportStyle(style, height) {
|
|
2273
|
+
return filling ? { flex: 1, minHeight: 0, ...style } : { ...style, height, shrink: 0 };
|
|
2274
|
+
}
|
|
2204
2275
|
function fixedVirtualList({
|
|
2205
2276
|
items,
|
|
2206
2277
|
itemHeight,
|
|
2207
|
-
height,
|
|
2278
|
+
height = FILL_ESTIMATE,
|
|
2208
2279
|
offset,
|
|
2209
2280
|
overscan = 2,
|
|
2210
2281
|
keyForItem,
|
|
@@ -2232,7 +2303,7 @@ function fixedVirtualList({
|
|
|
2232
2303
|
...props,
|
|
2233
2304
|
onScroll,
|
|
2234
2305
|
control: { role: "virtualList", value: scroll },
|
|
2235
|
-
style:
|
|
2306
|
+
style: viewportStyle(style, height),
|
|
2236
2307
|
children: jsx(Column, { style: { width: "100%" }, children: [
|
|
2237
2308
|
start > 0 ? jsx(Row, { style: { height: start * itemHeight, shrink: 0 } }, "before") : null,
|
|
2238
2309
|
...rows,
|
|
@@ -2244,7 +2315,7 @@ function variableVirtualList({
|
|
|
2244
2315
|
id,
|
|
2245
2316
|
items,
|
|
2246
2317
|
estimatedItemHeight,
|
|
2247
|
-
height,
|
|
2318
|
+
height = FILL_ESTIMATE,
|
|
2248
2319
|
offset,
|
|
2249
2320
|
overscan = 2,
|
|
2250
2321
|
keyForItem,
|
|
@@ -2291,7 +2362,7 @@ function variableVirtualList({
|
|
|
2291
2362
|
state.lastFollowTail = followTail;
|
|
2292
2363
|
const requestedIndex = state.scrollRequest && items.length > 0 ? Math.min(state.scrollRequest.index, items.length - 1) : undefined;
|
|
2293
2364
|
const requestedOffset = requestedIndex !== undefined ? Math.max(0, Math.min(prefix[requestedIndex] + state.scrollRequest.offset, max)) : undefined;
|
|
2294
|
-
if (requestedOffset !== undefined) {
|
|
2365
|
+
if (requestedOffset !== undefined && !state.scrollRequest.smooth) {
|
|
2295
2366
|
state.effectiveOffset = requestedOffset;
|
|
2296
2367
|
} else if (followTail && state.followingTail) {
|
|
2297
2368
|
state.effectiveOffset = max;
|
|
@@ -2363,14 +2434,15 @@ function variableVirtualList({
|
|
|
2363
2434
|
rememberHeight(state, measurement.key, measurement.height);
|
|
2364
2435
|
}
|
|
2365
2436
|
};
|
|
2366
|
-
const onVirtualListScrollToItem = (index, itemOffset) => {
|
|
2437
|
+
const onVirtualListScrollToItem = (index, itemOffset, smooth = false) => {
|
|
2367
2438
|
if (!Number.isInteger(index) || index < 0 || !Number.isFinite(itemOffset))
|
|
2368
2439
|
return;
|
|
2369
2440
|
state.followingTail = false;
|
|
2370
2441
|
state.scrollRequest = {
|
|
2371
2442
|
generation: ++store.nextScrollGeneration,
|
|
2372
2443
|
index,
|
|
2373
|
-
offset: itemOffset
|
|
2444
|
+
offset: itemOffset,
|
|
2445
|
+
smooth
|
|
2374
2446
|
};
|
|
2375
2447
|
};
|
|
2376
2448
|
const onVirtualListFocus = (key) => {
|
|
@@ -2400,9 +2472,9 @@ function variableVirtualList({
|
|
|
2400
2472
|
...retainedKey === undefined ? {} : { retainedKey },
|
|
2401
2473
|
alignment,
|
|
2402
2474
|
followTail,
|
|
2403
|
-
...requestedOffset !== undefined && state.scrollRequest ? { scrollRequest: { generation: state.scrollRequest.generation, offset: requestedOffset } } : {}
|
|
2475
|
+
...requestedOffset !== undefined && state.scrollRequest ? { scrollRequest: { generation: state.scrollRequest.generation, offset: requestedOffset, ...state.scrollRequest.smooth ? { smooth: true } : {} } } : {}
|
|
2404
2476
|
},
|
|
2405
|
-
style:
|
|
2477
|
+
style: viewportStyle(style, height),
|
|
2406
2478
|
children: jsx(Column, { style: { width: "100%" }, children: [
|
|
2407
2479
|
start > 0 ? jsx(Row, { style: { height: prefix[start], shrink: 0 } }, "before") : null,
|
|
2408
2480
|
...rows,
|
|
@@ -2417,7 +2489,7 @@ function windowedVariableVirtualList({
|
|
|
2417
2489
|
itemCount,
|
|
2418
2490
|
windowStart,
|
|
2419
2491
|
estimatedItemHeight,
|
|
2420
|
-
height,
|
|
2492
|
+
height = FILL_ESTIMATE,
|
|
2421
2493
|
offset,
|
|
2422
2494
|
keyForItem,
|
|
2423
2495
|
renderItem,
|
|
@@ -2498,6 +2570,8 @@ function windowedVariableVirtualList({
|
|
|
2498
2570
|
logicalTop += measured - estimatedItemHeight;
|
|
2499
2571
|
}
|
|
2500
2572
|
requestedOffset = Math.max(0, Math.min(logicalTop + state.scrollRequest.offset, max));
|
|
2573
|
+
}
|
|
2574
|
+
if (requestedOffset !== undefined && !state.scrollRequest.smooth) {
|
|
2501
2575
|
state.effectiveOffset = requestedOffset;
|
|
2502
2576
|
} else if (followTail && state.followingTail) {
|
|
2503
2577
|
state.effectiveOffset = max;
|
|
@@ -2568,14 +2642,15 @@ function windowedVariableVirtualList({
|
|
|
2568
2642
|
rememberHeight(state, measurement.key, measurement.height, windowStart + localIndex);
|
|
2569
2643
|
}
|
|
2570
2644
|
};
|
|
2571
|
-
const onVirtualListScrollToItem = (index, itemOffset) => {
|
|
2645
|
+
const onVirtualListScrollToItem = (index, itemOffset, smooth = false) => {
|
|
2572
2646
|
if (!Number.isInteger(index) || index < 0 || !Number.isFinite(itemOffset))
|
|
2573
2647
|
return;
|
|
2574
2648
|
state.followingTail = false;
|
|
2575
2649
|
state.scrollRequest = {
|
|
2576
2650
|
generation: ++store.nextScrollGeneration,
|
|
2577
2651
|
index,
|
|
2578
|
-
offset: itemOffset
|
|
2652
|
+
offset: itemOffset,
|
|
2653
|
+
smooth
|
|
2579
2654
|
};
|
|
2580
2655
|
};
|
|
2581
2656
|
const onVirtualListFocus = (key) => {
|
|
@@ -2607,9 +2682,9 @@ function windowedVariableVirtualList({
|
|
|
2607
2682
|
...retainedKey === undefined ? {} : { retainedKey },
|
|
2608
2683
|
alignment,
|
|
2609
2684
|
followTail,
|
|
2610
|
-
...requestedOffset !== undefined && state.scrollRequest ? { scrollRequest: { generation: state.scrollRequest.generation, offset: requestedOffset } } : {}
|
|
2685
|
+
...requestedOffset !== undefined && state.scrollRequest ? { scrollRequest: { generation: state.scrollRequest.generation, offset: requestedOffset, ...state.scrollRequest.smooth ? { smooth: true } : {} } } : {}
|
|
2611
2686
|
},
|
|
2612
|
-
style:
|
|
2687
|
+
style: viewportStyle(style, height),
|
|
2613
2688
|
children: jsx(Column, { style: { width: "100%" }, children: [
|
|
2614
2689
|
windowStart > 0 ? jsx(Row, { style: { height: before, shrink: 0 } }, "before") : null,
|
|
2615
2690
|
...rows,
|
|
@@ -2619,10 +2694,49 @@ function windowedVariableVirtualList({
|
|
|
2619
2694
|
});
|
|
2620
2695
|
}
|
|
2621
2696
|
function VirtualList(props) {
|
|
2697
|
+
if (props.height === undefined) {
|
|
2698
|
+
if (!props.id)
|
|
2699
|
+
throw new TypeError("VirtualList without a height needs an id to remember its measured height");
|
|
2700
|
+
let heights = filledHeights.get(currentRenderScope());
|
|
2701
|
+
if (!heights)
|
|
2702
|
+
filledHeights.set(currentRenderScope(), heights = new Map);
|
|
2703
|
+
const id = props.id;
|
|
2704
|
+
const store = heights;
|
|
2705
|
+
const onSize = props.onSize;
|
|
2706
|
+
const measured = { ...props, height: store.get(id) ?? FILL_ESTIMATE, onSize: (size) => {
|
|
2707
|
+
if (size.height > 0)
|
|
2708
|
+
store.set(id, size.height);
|
|
2709
|
+
onSize?.(size);
|
|
2710
|
+
} };
|
|
2711
|
+
filling = true;
|
|
2712
|
+
try {
|
|
2713
|
+
return VirtualList(measured);
|
|
2714
|
+
} finally {
|
|
2715
|
+
filling = false;
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2622
2718
|
if ("itemCount" in props)
|
|
2623
2719
|
return windowedVariableVirtualList(props);
|
|
2624
2720
|
return "estimatedItemHeight" in props ? variableVirtualList(props) : fixedVirtualList(props);
|
|
2625
2721
|
}
|
|
2722
|
+
// packages/core/src/memo.ts
|
|
2723
|
+
var MEMO = Symbol.for("tarve.memo");
|
|
2724
|
+
function shallowEqual(previous, next) {
|
|
2725
|
+
if (previous === next)
|
|
2726
|
+
return true;
|
|
2727
|
+
const a = previous;
|
|
2728
|
+
const b = next;
|
|
2729
|
+
const keys = Object.keys(a);
|
|
2730
|
+
if (keys.length !== Object.keys(b).length)
|
|
2731
|
+
return false;
|
|
2732
|
+
return keys.every((key) => Object.prototype.hasOwnProperty.call(b, key) && Object.is(a[key], b[key]));
|
|
2733
|
+
}
|
|
2734
|
+
function memo(render, equal = shallowEqual) {
|
|
2735
|
+
const component = (props) => render(props);
|
|
2736
|
+
component[MEMO] = { render, equal };
|
|
2737
|
+
Object.defineProperty(component, "name", { value: `memo(${render.name || "Component"})` });
|
|
2738
|
+
return component;
|
|
2739
|
+
}
|
|
2626
2740
|
// packages/core/src/motion.ts
|
|
2627
2741
|
var stores = new WeakMap;
|
|
2628
2742
|
var properties = [
|
|
@@ -3032,9 +3146,26 @@ function includesQuery(label, value, keywords, query) {
|
|
|
3032
3146
|
return true;
|
|
3033
3147
|
return [label, value, ...keywords ?? []].some((part) => part.toLocaleLowerCase().includes(needle));
|
|
3034
3148
|
}
|
|
3149
|
+
var TOOLTIP_MAX_WIDTH = 320;
|
|
3150
|
+
var hoveredTooltip = null;
|
|
3151
|
+
function tooltipLane(side) {
|
|
3152
|
+
const gap = 6;
|
|
3153
|
+
const base = { position: "absolute", zIndex: POPUP_Z_INDEX + 1, pointerEvents: "auto" };
|
|
3154
|
+
switch (side) {
|
|
3155
|
+
case "top":
|
|
3156
|
+
return { ...base, bottom: "100%", left: 0, right: -TOOLTIP_MAX_WIDTH, align: "start", margin: { bottom: gap } };
|
|
3157
|
+
case "right":
|
|
3158
|
+
return { ...base, top: 0, left: "100%", right: -TOOLTIP_MAX_WIDTH - gap, align: "start", margin: { left: gap } };
|
|
3159
|
+
case "left":
|
|
3160
|
+
return { ...base, top: 0, right: "100%", left: -TOOLTIP_MAX_WIDTH - gap, align: "end", margin: { right: gap } };
|
|
3161
|
+
case "bottom":
|
|
3162
|
+
default:
|
|
3163
|
+
return { ...base, top: "100%", left: 0, right: -TOOLTIP_MAX_WIDTH, align: "start", margin: { top: gap } };
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3035
3166
|
function Tooltip({
|
|
3036
3167
|
id,
|
|
3037
|
-
open,
|
|
3168
|
+
open: controlledOpen,
|
|
3038
3169
|
trigger,
|
|
3039
3170
|
content,
|
|
3040
3171
|
side = "top",
|
|
@@ -3043,6 +3174,7 @@ function Tooltip({
|
|
|
3043
3174
|
contentStyle,
|
|
3044
3175
|
style
|
|
3045
3176
|
}) {
|
|
3177
|
+
const open = controlledOpen ?? hoveredTooltip === id;
|
|
3046
3178
|
const tooltipContent = typeof content === "string" || typeof content === "number" ? jsx(Text, { size: 12, color: c2.background, children: content }) : content;
|
|
3047
3179
|
return jsx(View, {
|
|
3048
3180
|
id,
|
|
@@ -3052,19 +3184,36 @@ function Tooltip({
|
|
|
3052
3184
|
id: `${id}-trigger`,
|
|
3053
3185
|
focusable: false,
|
|
3054
3186
|
fallbackControl: { role: "button", label: triggerLabel(label, trigger) },
|
|
3055
|
-
onHover: (hovered) =>
|
|
3187
|
+
onHover: (hovered) => {
|
|
3188
|
+
if (controlledOpen === undefined)
|
|
3189
|
+
hoveredTooltip = hovered ? id : hoveredTooltip === id ? null : hoveredTooltip;
|
|
3190
|
+
onOpenChange?.(hovered);
|
|
3191
|
+
}
|
|
3056
3192
|
}),
|
|
3057
3193
|
open ? jsx(View, {
|
|
3058
|
-
id: `${id}-
|
|
3194
|
+
id: `${id}-lane`,
|
|
3059
3195
|
portal: true,
|
|
3060
|
-
style:
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3196
|
+
style: tooltipLane(side),
|
|
3197
|
+
children: jsx(View, {
|
|
3198
|
+
id: `${id}-content`,
|
|
3199
|
+
style: {
|
|
3200
|
+
...popupSurface(side, {
|
|
3201
|
+
minWidth: 0,
|
|
3202
|
+
maxWidth: TOOLTIP_MAX_WIDTH,
|
|
3203
|
+
padding: { left: 8, right: 8, top: 5, bottom: 5 },
|
|
3204
|
+
background: c2.foreground,
|
|
3205
|
+
foreground: c2.background,
|
|
3206
|
+
...contentStyle
|
|
3207
|
+
}),
|
|
3208
|
+
position: "relative",
|
|
3209
|
+
top: undefined,
|
|
3210
|
+
right: undefined,
|
|
3211
|
+
bottom: undefined,
|
|
3212
|
+
left: undefined,
|
|
3213
|
+
margin: undefined
|
|
3214
|
+
},
|
|
3215
|
+
children: tooltipContent
|
|
3216
|
+
})
|
|
3068
3217
|
}) : null
|
|
3069
3218
|
]
|
|
3070
3219
|
});
|
|
@@ -3343,7 +3492,14 @@ function Combobox({
|
|
|
3343
3492
|
placeholder: searchPlaceholder,
|
|
3344
3493
|
onChange: onQueryChange,
|
|
3345
3494
|
rovingGroup: true,
|
|
3346
|
-
style: {
|
|
3495
|
+
style: {
|
|
3496
|
+
flex: 1,
|
|
3497
|
+
minWidth: 0,
|
|
3498
|
+
borderWidth: 0,
|
|
3499
|
+
background: "#00000000",
|
|
3500
|
+
focus: { outlineWidth: 0 },
|
|
3501
|
+
focusVisible: { outlineWidth: 0 }
|
|
3502
|
+
}
|
|
3347
3503
|
})
|
|
3348
3504
|
]
|
|
3349
3505
|
}),
|
|
@@ -3476,7 +3632,14 @@ function Command({
|
|
|
3476
3632
|
placeholder,
|
|
3477
3633
|
onChange: onQueryChange,
|
|
3478
3634
|
rovingGroup: true,
|
|
3479
|
-
style: {
|
|
3635
|
+
style: {
|
|
3636
|
+
flex: 1,
|
|
3637
|
+
minWidth: 0,
|
|
3638
|
+
borderWidth: 0,
|
|
3639
|
+
background: "#00000000",
|
|
3640
|
+
focus: { outlineWidth: 0 },
|
|
3641
|
+
focusVisible: { outlineWidth: 0 }
|
|
3642
|
+
}
|
|
3480
3643
|
})
|
|
3481
3644
|
]
|
|
3482
3645
|
}),
|
|
@@ -3484,7 +3647,7 @@ function Command({
|
|
|
3484
3647
|
id: `${id}-results`,
|
|
3485
3648
|
gap: 2,
|
|
3486
3649
|
style: {
|
|
3487
|
-
height: visible.length === 0 ? 46 : boundedHeight(visible.length, 36, COMMAND_MAX_HEIGHT, groups.size *
|
|
3650
|
+
height: visible.length === 0 ? 46 : boundedHeight(visible.length, 36, COMMAND_MAX_HEIGHT, groups.size * 32 + 8),
|
|
3488
3651
|
padding: 4
|
|
3489
3652
|
},
|
|
3490
3653
|
children: visible.length === 0 ? jsx(Text, { id: `${id}-empty`, size: 13, color: c2.mutedForeground, style: { padding: 10 }, children: emptyText }) : resultNodes
|
|
@@ -3555,31 +3718,18 @@ function Skeleton({ width = "100%", height = 16, radius = theme.radius.sm, style
|
|
|
3555
3718
|
});
|
|
3556
3719
|
}
|
|
3557
3720
|
function Spinner({ size = 18, label = "Loading", style, ...props }) {
|
|
3558
|
-
|
|
3559
|
-
return jsx(View, {
|
|
3721
|
+
return jsx(Svg, {
|
|
3560
3722
|
...props,
|
|
3561
3723
|
control: { role: "progress", label },
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
},
|
|
3572
|
-
children: jsx(View, {
|
|
3573
|
-
style: {
|
|
3574
|
-
position: "absolute",
|
|
3575
|
-
top: -1,
|
|
3576
|
-
left: (size - dot) / 2,
|
|
3577
|
-
width: dot,
|
|
3578
|
-
height: dot,
|
|
3579
|
-
radius: dot / 2,
|
|
3580
|
-
background: c3.foreground
|
|
3581
|
-
}
|
|
3582
|
-
})
|
|
3724
|
+
size,
|
|
3725
|
+
viewBox: "0 0 24 24",
|
|
3726
|
+
strokeWidth: 2.5,
|
|
3727
|
+
color: c3.foreground,
|
|
3728
|
+
style: { spin: 800, ...style },
|
|
3729
|
+
children: [
|
|
3730
|
+
jsx(Circle, { cx: 12, cy: 12, r: 9, opacity: 0.2 }),
|
|
3731
|
+
jsx(Path, { d: "M12 3a9 9 0 0 1 9 9" })
|
|
3732
|
+
]
|
|
3583
3733
|
});
|
|
3584
3734
|
}
|
|
3585
3735
|
function Avatar({ src, fallback = "?", size = 40, fit = "cover", style, id, ...props }) {
|
|
@@ -4455,10 +4605,15 @@ function HoverCard({ open, trigger, side = "bottom", width = 280, onOpenChange,
|
|
|
4455
4605
|
// packages/core/src/form-controls.ts
|
|
4456
4606
|
var c4 = theme.colors;
|
|
4457
4607
|
var transparent2 = "#00000000";
|
|
4608
|
+
function tintIcon(icon, color) {
|
|
4609
|
+
if (!icon || typeof icon !== "object" || Array.isArray(icon) || icon.props.color !== undefined)
|
|
4610
|
+
return icon;
|
|
4611
|
+
return { ...icon, props: { ...icon.props, color } };
|
|
4612
|
+
}
|
|
4458
4613
|
function Alert({ title, description, variant = "default", icon, children, style, ...props }) {
|
|
4459
4614
|
const palette = {
|
|
4460
4615
|
default: { border: c4.border, background: c4.card, foreground: c4.foreground },
|
|
4461
|
-
destructive: { border: c4.destructive, background: c4.card, foreground: c4.
|
|
4616
|
+
destructive: { border: c4.destructive, background: c4.card, foreground: c4.destructiveText },
|
|
4462
4617
|
success: { border: c4.success, background: c4.successMuted, foreground: c4.success }
|
|
4463
4618
|
};
|
|
4464
4619
|
const selected = palette[variant];
|
|
@@ -4477,7 +4632,7 @@ function Alert({ title, description, variant = "default", icon, children, style,
|
|
|
4477
4632
|
...style
|
|
4478
4633
|
},
|
|
4479
4634
|
children: [
|
|
4480
|
-
icon,
|
|
4635
|
+
tintIcon(icon, selected.foreground),
|
|
4481
4636
|
jsx(Column, { gap: 3, flex: 1, children: [
|
|
4482
4637
|
title ? jsx(Text, { weight: 600, color: selected.foreground, children: title }) : null,
|
|
4483
4638
|
description ? jsx(Text, { size: 13, color: variant === "default" ? c4.mutedForeground : selected.foreground, children: description }) : null,
|
|
@@ -4573,10 +4728,26 @@ function Field({ label, description, error, required, disabled, children, style,
|
|
|
4573
4728
|
children: [
|
|
4574
4729
|
label ? jsx(Label, { ...id ? { id: `${id}-label` } : {}, required, disabled, children: label }) : null,
|
|
4575
4730
|
disableFormChild(children, disabled),
|
|
4576
|
-
|
|
4731
|
+
description ? jsx(Text, { ...id ? { id: `${id}-description` } : {}, size: 12, color: c4.mutedForeground, children: description }) : null,
|
|
4732
|
+
error ? jsx(Text, { ...id ? { id: `${id}-error` } : {}, control: { role: "alert", label: error }, size: 12, color: c4.destructiveText, children: error }) : null
|
|
4577
4733
|
]
|
|
4578
4734
|
});
|
|
4579
4735
|
}
|
|
4736
|
+
function groupedInput(child) {
|
|
4737
|
+
if (Array.isArray(child))
|
|
4738
|
+
return child.map(groupedInput);
|
|
4739
|
+
if (!child || typeof child !== "object" || child.type !== Input)
|
|
4740
|
+
return child;
|
|
4741
|
+
return { ...child, props: { ...child.props, style: {
|
|
4742
|
+
borderWidth: 0,
|
|
4743
|
+
background: transparent2,
|
|
4744
|
+
padding: { left: 0, right: 0 },
|
|
4745
|
+
minWidth: 0,
|
|
4746
|
+
focus: { outlineWidth: 0 },
|
|
4747
|
+
focusVisible: { outlineWidth: 0 },
|
|
4748
|
+
...child.props.style
|
|
4749
|
+
} } };
|
|
4750
|
+
}
|
|
4580
4751
|
function InputGroup({ prefix, suffix, disabled, children, style, ...props }) {
|
|
4581
4752
|
return jsx(Row, {
|
|
4582
4753
|
...props,
|
|
@@ -4591,9 +4762,12 @@ function InputGroup({ prefix, suffix, disabled, children, style, ...props }) {
|
|
|
4591
4762
|
borderColor: c4.border,
|
|
4592
4763
|
radius: theme.radius.sm,
|
|
4593
4764
|
background: disabled ? c4.disabled : c4.input,
|
|
4765
|
+
pointerEvents: "delegate",
|
|
4766
|
+
focus: { borderColor: c4.ring },
|
|
4767
|
+
focusVisible: { borderColor: c4.ring, outlineColor: c4.ring, outlineWidth: 2, outlineOffset: 2, outlineStyle: "solid" },
|
|
4594
4768
|
...style
|
|
4595
4769
|
},
|
|
4596
|
-
children: [prefix, jsx(View, { flex: 1, children: disableFormChild(children, disabled) }), suffix]
|
|
4770
|
+
children: [prefix, jsx(View, { flex: 1, children: disableFormChild(groupedInput(children), disabled) }), suffix]
|
|
4597
4771
|
});
|
|
4598
4772
|
}
|
|
4599
4773
|
function matchesInputPattern(pattern, char) {
|
|
@@ -5033,6 +5207,7 @@ function NavigationMenu({ items, value, openValue, onValueChange, onOpenValueCha
|
|
|
5033
5207
|
children: items.map((item) => {
|
|
5034
5208
|
const open = openValue === item.value;
|
|
5035
5209
|
const direct = !item.links || item.links.length === 0;
|
|
5210
|
+
const current = direct ? value === item.value : item.links.some((link) => link.value === value);
|
|
5036
5211
|
return jsx(Column, {
|
|
5037
5212
|
style: { position: "relative" },
|
|
5038
5213
|
children: [
|
|
@@ -5046,13 +5221,19 @@ function NavigationMenu({ items, value, openValue, onValueChange, onOpenValueCha
|
|
|
5046
5221
|
} : () => onOpenValueChange?.(open ? undefined : item.value),
|
|
5047
5222
|
style: {
|
|
5048
5223
|
minHeight: 36,
|
|
5049
|
-
padding: { left: 12, right: 12 },
|
|
5224
|
+
padding: { left: 12, right: direct ? 12 : 8 },
|
|
5225
|
+
direction: "row",
|
|
5226
|
+
gap: 4,
|
|
5050
5227
|
align: "center",
|
|
5051
5228
|
justify: "center",
|
|
5052
|
-
|
|
5229
|
+
radius: theme.radius.sm,
|
|
5230
|
+
background: open || current ? c5.muted : transparent3,
|
|
5053
5231
|
hover: { background: c5.muted }
|
|
5054
5232
|
},
|
|
5055
|
-
children:
|
|
5233
|
+
children: [
|
|
5234
|
+
jsx(Text, { weight: 500, color: item.disabled ? c5.disabledForeground : c5.foreground, children: item.label }),
|
|
5235
|
+
direct ? null : jsx(Icon, { name: open ? "chevron-up" : "chevron-down", size: 14, color: c5.mutedForeground })
|
|
5236
|
+
]
|
|
5056
5237
|
}),
|
|
5057
5238
|
open && !direct ? jsx(Column, {
|
|
5058
5239
|
...id ? { id: `${id}-content-${item.value}` } : {},
|
|
@@ -5065,6 +5246,7 @@ function NavigationMenu({ items, value, openValue, onValueChange, onOpenValueCha
|
|
|
5065
5246
|
position: "absolute",
|
|
5066
5247
|
top: "100%",
|
|
5067
5248
|
left: 0,
|
|
5249
|
+
margin: { top: 6 },
|
|
5068
5250
|
minWidth: 240,
|
|
5069
5251
|
padding: 6,
|
|
5070
5252
|
background: c5.card,
|
|
@@ -5082,7 +5264,13 @@ function NavigationMenu({ items, value, openValue, onValueChange, onOpenValueCha
|
|
|
5082
5264
|
onValueChange?.(link.value);
|
|
5083
5265
|
onOpenValueChange?.(undefined);
|
|
5084
5266
|
},
|
|
5085
|
-
style: {
|
|
5267
|
+
style: {
|
|
5268
|
+
minHeight: 40,
|
|
5269
|
+
padding: 8,
|
|
5270
|
+
radius: theme.radius.sm,
|
|
5271
|
+
hover: { background: c5.muted },
|
|
5272
|
+
background: value === link.value ? c5.muted : transparent3
|
|
5273
|
+
},
|
|
5086
5274
|
children: jsx(Column, { gap: 2, children: [
|
|
5087
5275
|
jsx(Text, { weight: 500, children: link.label }),
|
|
5088
5276
|
link.description ? jsx(Text, { size: 12, color: c5.mutedForeground, children: link.description }) : null
|
|
@@ -5359,16 +5547,16 @@ function Attachment({
|
|
|
5359
5547
|
...style
|
|
5360
5548
|
},
|
|
5361
5549
|
children: [
|
|
5362
|
-
jsx(Row, { gap: 8, children: [
|
|
5550
|
+
jsx(Row, { gap: 8, justify: "between", children: [
|
|
5363
5551
|
leading,
|
|
5364
|
-
jsx(Column, { gap: 2,
|
|
5552
|
+
jsx(Column, { gap: 2, style: { shrink: 1, minWidth: 0 }, children: [
|
|
5365
5553
|
jsx(Text, { weight: 500, color: statusColor, children: name }),
|
|
5366
5554
|
size ? jsx(Text, { size: 11, color: c6.mutedForeground, children: size }) : null
|
|
5367
5555
|
] }),
|
|
5368
5556
|
onRemove ? jsx(Button, { ...id ? { id: `${id}-remove` } : {}, variant: "ghost", size: "sm", onClick: onRemove, children: removeLabel }) : null
|
|
5369
5557
|
] }),
|
|
5370
5558
|
status === "uploading" ? jsx(Progress, { ...id ? { id: `${id}-progress` } : {}, value: progress, max: 100, label: `${name} upload progress` }) : null,
|
|
5371
|
-
status === "error" ? jsx(Text, { ...id ? { id: `${id}-error` } : {}, size: 11, color: c6.
|
|
5559
|
+
status === "error" ? jsx(Text, { ...id ? { id: `${id}-error` } : {}, size: 11, color: c6.destructiveText, children: "Upload failed" }) : null
|
|
5372
5560
|
]
|
|
5373
5561
|
});
|
|
5374
5562
|
}
|
|
@@ -5451,7 +5639,7 @@ function Message({
|
|
|
5451
5639
|
...props,
|
|
5452
5640
|
...id ? { id } : {},
|
|
5453
5641
|
gap: 8,
|
|
5454
|
-
align: "
|
|
5642
|
+
align: "start",
|
|
5455
5643
|
justify: side === "outgoing" ? "end" : "start",
|
|
5456
5644
|
style: { width: "100%", ...style },
|
|
5457
5645
|
children: side === "outgoing" ? [body, avatar] : [avatar, body]
|
|
@@ -5687,7 +5875,8 @@ function DataGrid({
|
|
|
5687
5875
|
typeof column.header === "string" || typeof column.header === "number" ? jsx(Text, { size: 12, weight: 600, color: c7.mutedForeground, children: column.header }) : column.header,
|
|
5688
5876
|
active ? jsx(Text, { size: 11, color: c7.mutedForeground, children: sort.direction === "asc" ? "\u2191" : "\u2193" }) : null
|
|
5689
5877
|
];
|
|
5690
|
-
const
|
|
5878
|
+
const justify = column.align === "center" || column.align === "end" ? column.align : "start";
|
|
5879
|
+
const common = { style: { width: column.width, flex: column.width === undefined ? 1 : undefined, minWidth: 0, height: "100%", padding: { left: 10, right: 10 }, direction: "row", align: "center", justify, gap: 5 } };
|
|
5691
5880
|
if (!column.sortable)
|
|
5692
5881
|
return jsx(Row, { ...common, children: content }, column.key);
|
|
5693
5882
|
return jsx(Pressable, {
|
|
@@ -5701,6 +5890,7 @@ function DataGrid({
|
|
|
5701
5890
|
...common,
|
|
5702
5891
|
style: {
|
|
5703
5892
|
...common.style,
|
|
5893
|
+
radius: 0,
|
|
5704
5894
|
background: "#00000000",
|
|
5705
5895
|
hover: { background: c7.muted },
|
|
5706
5896
|
focus: { outlineWidth: 0, outlineStyle: "none" }
|
|
@@ -5735,7 +5925,7 @@ function DataGrid({
|
|
|
5735
5925
|
toggleSelection(entry);
|
|
5736
5926
|
onRowActivate?.(entry.row, entry.sourceIndex);
|
|
5737
5927
|
},
|
|
5738
|
-
style: { width: "100%", height: rowHeight, shrink: 0, direction: "row", background: selected ? c7.muted : "#00000000", hover: { background: c7.muted }, borderWidth: { bottom: 1 }, borderColor: c7.border },
|
|
5928
|
+
style: { width: "100%", height: rowHeight, shrink: 0, direction: "row", radius: 0, background: selected ? c7.muted : "#00000000", hover: { background: c7.muted }, borderWidth: { bottom: 1 }, borderColor: c7.border },
|
|
5739
5929
|
children: columns.map((column) => jsx(View, {
|
|
5740
5930
|
style: { width: column.width, flex: column.width === undefined ? 1 : undefined, minWidth: 0, height: "100%", padding: { left: 10, right: 10 }, align: column.align ?? "start", justify: "center" },
|
|
5741
5931
|
children: gridCell(column, entry)
|
|
@@ -5915,11 +6105,1294 @@ function createTextSearchController() {
|
|
|
5915
6105
|
}
|
|
5916
6106
|
};
|
|
5917
6107
|
}
|
|
6108
|
+
// packages/core/src/app.ts
|
|
6109
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
6110
|
+
|
|
6111
|
+
// packages/core/src/media-element.ts
|
|
6112
|
+
var states = new Map;
|
|
6113
|
+
function mediaState(id) {
|
|
6114
|
+
return states.get(id) ?? { paused: true, time: 0, duration: null, ended: false };
|
|
6115
|
+
}
|
|
6116
|
+
var ACTIVE_APP = Symbol.for("tarve.activeApp");
|
|
6117
|
+
function controller(id) {
|
|
6118
|
+
return globalThis[ACTIVE_APP]?.media(id);
|
|
6119
|
+
}
|
|
6120
|
+
function clock(seconds) {
|
|
6121
|
+
if (seconds === null || !Number.isFinite(seconds))
|
|
6122
|
+
return "--:--";
|
|
6123
|
+
const total = Math.max(0, Math.floor(seconds));
|
|
6124
|
+
const h = Math.floor(total / 3600), m = Math.floor(total % 3600 / 60), s = total % 60;
|
|
6125
|
+
return h ? `${h}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}` : `${m}:${String(s).padStart(2, "0")}`;
|
|
6126
|
+
}
|
|
6127
|
+
function mediaRequest(props) {
|
|
6128
|
+
return {
|
|
6129
|
+
...props.src ? { src: props.src } : {},
|
|
6130
|
+
loop: props.loop === true,
|
|
6131
|
+
muted: props.muted === true,
|
|
6132
|
+
volume: Math.min(1, Math.max(0, props.volume ?? 1)),
|
|
6133
|
+
autoPlay: props.autoPlay === true,
|
|
6134
|
+
handlers: props
|
|
6135
|
+
};
|
|
6136
|
+
}
|
|
6137
|
+
function expandAudio(props, id) {
|
|
6138
|
+
const style = canonicalizeIntrinsicStyle(props.style);
|
|
6139
|
+
if (!props.controls)
|
|
6140
|
+
return View({ id, style: { display: "none" } });
|
|
6141
|
+
const state = mediaState(id);
|
|
6142
|
+
const label = props.ariaLabel ?? "Audio";
|
|
6143
|
+
return Row({
|
|
6144
|
+
id,
|
|
6145
|
+
gap: 8,
|
|
6146
|
+
align: "center",
|
|
6147
|
+
control: { role: "group", label },
|
|
6148
|
+
style: { width: 300, height: 54, padding: { left: 10, right: 10 }, radius: 27, background: theme.colors.muted, ...style },
|
|
6149
|
+
children: [
|
|
6150
|
+
Button({
|
|
6151
|
+
id: `${id}-play`,
|
|
6152
|
+
size: "sm",
|
|
6153
|
+
variant: "ghost",
|
|
6154
|
+
control: { role: "button", label: state.paused ? "Play" : "Pause" },
|
|
6155
|
+
onClick: () => mediaState(id).paused ? controller(id)?.play() : controller(id)?.pause(),
|
|
6156
|
+
children: state.paused ? "\u25B6" : "\u275A\u275A"
|
|
6157
|
+
}),
|
|
6158
|
+
Text({ id: `${id}-time`, size: 12, style: { fontFamily: "monospace", shrink: 0 }, children: `${clock(state.time)} / ${clock(state.duration)}` }),
|
|
6159
|
+
Slider({
|
|
6160
|
+
id: `${id}-seek`,
|
|
6161
|
+
label: `${label} position`,
|
|
6162
|
+
value: Math.min(state.time, state.duration ?? state.time),
|
|
6163
|
+
min: 0,
|
|
6164
|
+
max: Math.max(state.duration ?? 0, 0.001),
|
|
6165
|
+
step: 0.1,
|
|
6166
|
+
style: { flex: 1, minWidth: 40 },
|
|
6167
|
+
onValueChange: (value) => controller(id)?.seek(value)
|
|
6168
|
+
}),
|
|
6169
|
+
Button({
|
|
6170
|
+
id: `${id}-mute`,
|
|
6171
|
+
size: "sm",
|
|
6172
|
+
variant: "ghost",
|
|
6173
|
+
control: { role: "button", label: props.muted ? "Unmute" : "Mute" },
|
|
6174
|
+
onClick: () => controller(id)?.setMuted(!props.muted),
|
|
6175
|
+
children: props.muted ? "\uD83D\uDD07" : "\uD83D\uDD0A"
|
|
6176
|
+
})
|
|
6177
|
+
]
|
|
6178
|
+
});
|
|
6179
|
+
}
|
|
6180
|
+
function applyMediaEvent(event, request) {
|
|
6181
|
+
const previous = mediaState(event.id);
|
|
6182
|
+
const next = { ...previous, time: event.time ?? previous.time, duration: event.duration ?? previous.duration, paused: event.paused ?? previous.paused };
|
|
6183
|
+
if (event.event === "ended") {
|
|
6184
|
+
next.ended = true;
|
|
6185
|
+
next.paused = true;
|
|
6186
|
+
}
|
|
6187
|
+
if (event.event === "play")
|
|
6188
|
+
next.ended = false;
|
|
6189
|
+
if (event.event === "error")
|
|
6190
|
+
next.error = event.message;
|
|
6191
|
+
states.set(event.id, next);
|
|
6192
|
+
const info = { currentTime: next.time, duration: next.duration, paused: next.paused };
|
|
6193
|
+
const h = request?.handlers;
|
|
6194
|
+
switch (event.event) {
|
|
6195
|
+
case "loadedmetadata":
|
|
6196
|
+
return h?.onLoadedMetadata && (() => h.onLoadedMetadata(info));
|
|
6197
|
+
case "play":
|
|
6198
|
+
return h?.onPlay && (() => h.onPlay(info));
|
|
6199
|
+
case "pause":
|
|
6200
|
+
return h?.onPause && (() => h.onPause(info));
|
|
6201
|
+
case "timeupdate":
|
|
6202
|
+
return h?.onTimeUpdate && (() => h.onTimeUpdate(info));
|
|
6203
|
+
case "seeked":
|
|
6204
|
+
return h?.onSeeked && (() => h.onSeeked(info));
|
|
6205
|
+
case "ended":
|
|
6206
|
+
return h?.onEnded && (() => h.onEnded(info));
|
|
6207
|
+
case "error":
|
|
6208
|
+
return h?.onError && (() => h.onError(event.message ?? "media error"));
|
|
6209
|
+
}
|
|
6210
|
+
return;
|
|
6211
|
+
}
|
|
6212
|
+
|
|
5918
6213
|
// packages/core/src/reconciler.ts
|
|
5919
6214
|
import { nativeAssetPath } from "#tarve/assets";
|
|
6215
|
+
|
|
6216
|
+
// packages/core/src/inline-text.ts
|
|
6217
|
+
var INLINE_TAGS = {
|
|
6218
|
+
span: {},
|
|
6219
|
+
strong: { fontWeight: "bolder" },
|
|
6220
|
+
b: { fontWeight: "bolder" },
|
|
6221
|
+
em: { fontStyle: "italic" },
|
|
6222
|
+
i: { fontStyle: "italic" },
|
|
6223
|
+
cite: { fontStyle: "italic" },
|
|
6224
|
+
var: { fontStyle: "italic" },
|
|
6225
|
+
dfn: { fontStyle: "italic" },
|
|
6226
|
+
u: { textDecoration: "underline" },
|
|
6227
|
+
ins: { textDecoration: "underline" },
|
|
6228
|
+
s: { textDecoration: "line-through" },
|
|
6229
|
+
del: { textDecoration: "line-through" },
|
|
6230
|
+
code: { fontFamily: "monospace" },
|
|
6231
|
+
kbd: { fontFamily: "monospace" },
|
|
6232
|
+
samp: { fontFamily: "monospace" },
|
|
6233
|
+
mark: { background: "#ffff00", foreground: "#000000" },
|
|
6234
|
+
small: { fontSize: "smaller" },
|
|
6235
|
+
sub: { verticalAlign: "sub", fontSize: "smaller" },
|
|
6236
|
+
sup: { verticalAlign: "super", fontSize: "smaller" },
|
|
6237
|
+
a: { textDecoration: "underline" },
|
|
6238
|
+
abbr: {}
|
|
6239
|
+
};
|
|
6240
|
+
var INLINE_TAG_NAMES = new Set([...Object.keys(INLINE_TAGS), "br"]);
|
|
6241
|
+
var RUN_KEYS = ["fontWeight", "fontStyle", "fontSize", "fontFamily", "foreground", "background", "textDecoration", "letterSpacing", "wordSpacing", "fontVariantNumeric", "fontFeatureSettings", "textTransform", "baselineShift", "textDecorationStyle"];
|
|
6242
|
+
function pick(style) {
|
|
6243
|
+
const out = {};
|
|
6244
|
+
if (!style)
|
|
6245
|
+
return out;
|
|
6246
|
+
for (const key of RUN_KEYS)
|
|
6247
|
+
if (style[key] !== undefined)
|
|
6248
|
+
out[key] = style[key];
|
|
6249
|
+
return out;
|
|
6250
|
+
}
|
|
6251
|
+
function computeStyle(parent, own) {
|
|
6252
|
+
const next = { ...parent, ...own };
|
|
6253
|
+
if (own.fontWeight === "bolder") {
|
|
6254
|
+
const weight = Number(parent.fontWeight ?? 400);
|
|
6255
|
+
next.fontWeight = weight < 350 ? 400 : weight < 550 ? 700 : 900;
|
|
6256
|
+
} else if (own.fontWeight === "lighter") {
|
|
6257
|
+
const weight = Number(parent.fontWeight ?? 400);
|
|
6258
|
+
next.fontWeight = weight < 550 ? 100 : weight < 750 ? 400 : 700;
|
|
6259
|
+
}
|
|
6260
|
+
if (own.verticalAlign === "super" || own.verticalAlign === "sub") {
|
|
6261
|
+
const size = Number(parent.fontSize ?? 14);
|
|
6262
|
+
const shift = own.verticalAlign === "super" ? size / 3 + 1 : -(size / 5 + 1);
|
|
6263
|
+
next.baselineShift = Math.round((Number(parent.baselineShift ?? 0) + shift) * 100) / 100;
|
|
6264
|
+
}
|
|
6265
|
+
delete next.verticalAlign;
|
|
6266
|
+
if (own.fontSize === "smaller")
|
|
6267
|
+
next.fontSize = Number(parent.fontSize ?? 14) / 1.2;
|
|
6268
|
+
else if (own.fontSize === "larger")
|
|
6269
|
+
next.fontSize = Number(parent.fontSize ?? 14) * 1.2;
|
|
6270
|
+
if (own.textDecoration !== undefined && parent.textDecoration && parent.textDecoration !== "none" && own.textDecoration !== "none") {
|
|
6271
|
+
const lines = new Set(`${parent.textDecoration} ${own.textDecoration}`.split(/\s+/));
|
|
6272
|
+
next.textDecoration = [...lines].join(" ");
|
|
6273
|
+
}
|
|
6274
|
+
return next;
|
|
6275
|
+
}
|
|
6276
|
+
function transformText(text, transform, wordStart) {
|
|
6277
|
+
if (transform === "uppercase")
|
|
6278
|
+
return text.toUpperCase();
|
|
6279
|
+
if (transform === "lowercase")
|
|
6280
|
+
return text.toLowerCase();
|
|
6281
|
+
if (transform === "capitalize") {
|
|
6282
|
+
let start = wordStart;
|
|
6283
|
+
let out = "";
|
|
6284
|
+
for (const char of text) {
|
|
6285
|
+
out += start && /\p{L}/u.test(char) ? char.toUpperCase() : char;
|
|
6286
|
+
start = /\s/.test(char);
|
|
6287
|
+
}
|
|
6288
|
+
return out;
|
|
6289
|
+
}
|
|
6290
|
+
return text;
|
|
6291
|
+
}
|
|
6292
|
+
function utf8Length(text) {
|
|
6293
|
+
let length = 0;
|
|
6294
|
+
for (let index = 0;index < text.length; index++) {
|
|
6295
|
+
const code = text.charCodeAt(index);
|
|
6296
|
+
if (code < 128)
|
|
6297
|
+
length += 1;
|
|
6298
|
+
else if (code < 2048)
|
|
6299
|
+
length += 2;
|
|
6300
|
+
else if (code >= 55296 && code <= 56319) {
|
|
6301
|
+
length += 4;
|
|
6302
|
+
index++;
|
|
6303
|
+
} else
|
|
6304
|
+
length += 3;
|
|
6305
|
+
}
|
|
6306
|
+
return length;
|
|
6307
|
+
}
|
|
6308
|
+
function collect2(child, style, id, ctx, out) {
|
|
6309
|
+
if (child == null || typeof child === "boolean")
|
|
6310
|
+
return;
|
|
6311
|
+
if (Array.isArray(child)) {
|
|
6312
|
+
for (const item of child)
|
|
6313
|
+
collect2(item, style, id, ctx, out);
|
|
6314
|
+
return;
|
|
6315
|
+
}
|
|
6316
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
6317
|
+
out.push({ text: String(child), style, id });
|
|
6318
|
+
return;
|
|
6319
|
+
}
|
|
6320
|
+
const node = child;
|
|
6321
|
+
if (node.type === Fragment || node.type === "fragment") {
|
|
6322
|
+
collect2(node.props.children, style, id, ctx, out);
|
|
6323
|
+
return;
|
|
6324
|
+
}
|
|
6325
|
+
if (typeof node.type === "function") {
|
|
6326
|
+
collect2(node.type(node.props), style, id, ctx, out);
|
|
6327
|
+
return;
|
|
6328
|
+
}
|
|
6329
|
+
const props = node.props;
|
|
6330
|
+
if (node.type === "br") {
|
|
6331
|
+
out.push({ br: true });
|
|
6332
|
+
return;
|
|
6333
|
+
}
|
|
6334
|
+
if (node.type === "text") {
|
|
6335
|
+
collect2(props.children, computeStyle(style, pick(props.style)), id, ctx, out);
|
|
6336
|
+
return;
|
|
6337
|
+
}
|
|
6338
|
+
if (typeof node.type !== "string" || !(node.type in INLINE_TAGS) || node.type === "code" && props.code !== undefined) {
|
|
6339
|
+
throw new Error(`<${String(node.type)}> cannot be inside text; only phrasing elements (span, strong, em, a, code, br\u2026) can.`);
|
|
6340
|
+
}
|
|
6341
|
+
const own = { ...INLINE_TAGS[node.type] };
|
|
6342
|
+
if (node.type === "abbr" && props.title) {
|
|
6343
|
+
own.textDecoration = "underline";
|
|
6344
|
+
own.textDecorationStyle = "dotted";
|
|
6345
|
+
}
|
|
6346
|
+
if (node.type === "a")
|
|
6347
|
+
own.foreground = ctx.linkColor;
|
|
6348
|
+
Object.assign(own, pick(canonicalizeIntrinsicStyle(props.style)));
|
|
6349
|
+
if (props.size !== undefined)
|
|
6350
|
+
own.fontSize = props.size;
|
|
6351
|
+
if (props.weight !== undefined)
|
|
6352
|
+
own.fontWeight = props.weight;
|
|
6353
|
+
if (props.color !== undefined)
|
|
6354
|
+
own.foreground = props.color;
|
|
6355
|
+
let runId = id;
|
|
6356
|
+
const href = node.type === "a" && typeof props.href === "string" ? props.href : undefined;
|
|
6357
|
+
if (props.onClick || href) {
|
|
6358
|
+
const onClick = props.onClick;
|
|
6359
|
+
runId = ctx.register(props.id, () => {
|
|
6360
|
+
if (props.disabled)
|
|
6361
|
+
return;
|
|
6362
|
+
onClick?.();
|
|
6363
|
+
if (href)
|
|
6364
|
+
ctx.openExternal(href);
|
|
6365
|
+
});
|
|
6366
|
+
}
|
|
6367
|
+
collect2(props.children, computeStyle(style, ctx.resolve(own)), runId, ctx, out);
|
|
6368
|
+
}
|
|
6369
|
+
function compileInline(children, whiteSpace, ctx) {
|
|
6370
|
+
const pieces = [];
|
|
6371
|
+
collect2(children, ctx.base, undefined, ctx, pieces);
|
|
6372
|
+
const collapseSpaces = whiteSpace === "normal" || whiteSpace === "nowrap" || whiteSpace === "pre-line";
|
|
6373
|
+
const keepNewlines = whiteSpace !== "normal" && whiteSpace !== "nowrap";
|
|
6374
|
+
let text = "";
|
|
6375
|
+
let bytes = 0;
|
|
6376
|
+
const runs = [];
|
|
6377
|
+
let pendingSpace = false;
|
|
6378
|
+
let lineStart = true;
|
|
6379
|
+
let wordStart = true;
|
|
6380
|
+
const append = (value) => {
|
|
6381
|
+
text += value;
|
|
6382
|
+
bytes += utf8Length(value);
|
|
6383
|
+
};
|
|
6384
|
+
const trimLineEnd = () => {
|
|
6385
|
+
if (!text.endsWith(" ") || !pendingSpace)
|
|
6386
|
+
return;
|
|
6387
|
+
text = text.slice(0, -1);
|
|
6388
|
+
bytes -= 1;
|
|
6389
|
+
for (const run of runs)
|
|
6390
|
+
if (run.end > bytes)
|
|
6391
|
+
run.end = bytes;
|
|
6392
|
+
while (runs.length && runs.at(-1).end <= runs.at(-1).start)
|
|
6393
|
+
runs.pop();
|
|
6394
|
+
};
|
|
6395
|
+
for (const piece of pieces) {
|
|
6396
|
+
if ("br" in piece) {
|
|
6397
|
+
trimLineEnd();
|
|
6398
|
+
append(`
|
|
6399
|
+
`);
|
|
6400
|
+
pendingSpace = false;
|
|
6401
|
+
lineStart = true;
|
|
6402
|
+
wordStart = true;
|
|
6403
|
+
continue;
|
|
6404
|
+
}
|
|
6405
|
+
const start = bytes;
|
|
6406
|
+
const source = piece.text.replace(/\r\n?/g, `
|
|
6407
|
+
`);
|
|
6408
|
+
if (!collapseSpaces) {
|
|
6409
|
+
append(transformText(source, piece.style.textTransform, wordStart));
|
|
6410
|
+
if (source)
|
|
6411
|
+
wordStart = /\s$/.test(source);
|
|
6412
|
+
} else {
|
|
6413
|
+
for (const char of source) {
|
|
6414
|
+
if (char === `
|
|
6415
|
+
` && keepNewlines) {
|
|
6416
|
+
trimLineEnd();
|
|
6417
|
+
append(`
|
|
6418
|
+
`);
|
|
6419
|
+
pendingSpace = false;
|
|
6420
|
+
lineStart = true;
|
|
6421
|
+
wordStart = true;
|
|
6422
|
+
} else if (char === " " || char === "\t" || char === `
|
|
6423
|
+
` || char === "\f") {
|
|
6424
|
+
if (!lineStart && !pendingSpace) {
|
|
6425
|
+
append(" ");
|
|
6426
|
+
pendingSpace = true;
|
|
6427
|
+
wordStart = true;
|
|
6428
|
+
}
|
|
6429
|
+
} else {
|
|
6430
|
+
pendingSpace = false;
|
|
6431
|
+
append(transformText(char, piece.style.textTransform, wordStart));
|
|
6432
|
+
wordStart = false;
|
|
6433
|
+
lineStart = false;
|
|
6434
|
+
}
|
|
6435
|
+
}
|
|
6436
|
+
}
|
|
6437
|
+
const style = {};
|
|
6438
|
+
for (const key of RUN_KEYS) {
|
|
6439
|
+
if (key === "textTransform")
|
|
6440
|
+
continue;
|
|
6441
|
+
if (piece.style[key] !== undefined && piece.style[key] !== ctx.base[key])
|
|
6442
|
+
style[key] = piece.style[key];
|
|
6443
|
+
}
|
|
6444
|
+
if (bytes > start && (Object.keys(style).length > 0 || piece.id)) {
|
|
6445
|
+
const last = runs.at(-1);
|
|
6446
|
+
if (last && last.end === start && last.id === piece.id && JSON.stringify(last.style) === JSON.stringify(style))
|
|
6447
|
+
last.end = bytes;
|
|
6448
|
+
else
|
|
6449
|
+
runs.push({ start, end: bytes, style, ...piece.id ? { id: piece.id } : {} });
|
|
6450
|
+
}
|
|
6451
|
+
}
|
|
6452
|
+
trimLineEnd();
|
|
6453
|
+
return { text, runs };
|
|
6454
|
+
}
|
|
6455
|
+
|
|
6456
|
+
// packages/core/src/canvas.ts
|
|
6457
|
+
class CanvasGradient {
|
|
6458
|
+
id;
|
|
6459
|
+
kind;
|
|
6460
|
+
coords;
|
|
6461
|
+
stops = [];
|
|
6462
|
+
constructor(id, kind, coords) {
|
|
6463
|
+
this.id = id;
|
|
6464
|
+
this.kind = kind;
|
|
6465
|
+
this.coords = coords;
|
|
6466
|
+
}
|
|
6467
|
+
addColorStop(offset, color) {
|
|
6468
|
+
if (!(offset >= 0 && offset <= 1))
|
|
6469
|
+
throw new RangeError("addColorStop offset must be between 0 and 1");
|
|
6470
|
+
this.stops.push([offset, color]);
|
|
6471
|
+
}
|
|
6472
|
+
}
|
|
6473
|
+
var fmt = (n) => (Math.round(n * 1000) / 1000).toString();
|
|
6474
|
+
var esc = (s) => s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
6475
|
+
|
|
6476
|
+
class CanvasRenderingContext2D {
|
|
6477
|
+
width;
|
|
6478
|
+
height;
|
|
6479
|
+
state = {
|
|
6480
|
+
fillStyle: "#000000",
|
|
6481
|
+
strokeStyle: "#000000",
|
|
6482
|
+
lineWidth: 1,
|
|
6483
|
+
lineCap: "butt",
|
|
6484
|
+
lineJoin: "miter",
|
|
6485
|
+
miterLimit: 10,
|
|
6486
|
+
globalAlpha: 1,
|
|
6487
|
+
font: "10px sans-serif",
|
|
6488
|
+
textAlign: "start",
|
|
6489
|
+
textBaseline: "alphabetic",
|
|
6490
|
+
transform: [1, 0, 0, 1, 0, 0],
|
|
6491
|
+
lineDash: []
|
|
6492
|
+
};
|
|
6493
|
+
stack = [];
|
|
6494
|
+
path = "";
|
|
6495
|
+
start = null;
|
|
6496
|
+
current = null;
|
|
6497
|
+
elements = [];
|
|
6498
|
+
defs = [];
|
|
6499
|
+
texts = [];
|
|
6500
|
+
ops = [];
|
|
6501
|
+
gradients = 0;
|
|
6502
|
+
constructor(width, height) {
|
|
6503
|
+
this.width = width;
|
|
6504
|
+
this.height = height;
|
|
6505
|
+
}
|
|
6506
|
+
get fillStyle() {
|
|
6507
|
+
return this.state.fillStyle;
|
|
6508
|
+
}
|
|
6509
|
+
set fillStyle(v) {
|
|
6510
|
+
this.state.fillStyle = v;
|
|
6511
|
+
}
|
|
6512
|
+
get strokeStyle() {
|
|
6513
|
+
return this.state.strokeStyle;
|
|
6514
|
+
}
|
|
6515
|
+
set strokeStyle(v) {
|
|
6516
|
+
this.state.strokeStyle = v;
|
|
6517
|
+
}
|
|
6518
|
+
get lineWidth() {
|
|
6519
|
+
return this.state.lineWidth;
|
|
6520
|
+
}
|
|
6521
|
+
set lineWidth(v) {
|
|
6522
|
+
if (v > 0 && Number.isFinite(v))
|
|
6523
|
+
this.state.lineWidth = v;
|
|
6524
|
+
}
|
|
6525
|
+
get lineCap() {
|
|
6526
|
+
return this.state.lineCap;
|
|
6527
|
+
}
|
|
6528
|
+
set lineCap(v) {
|
|
6529
|
+
this.state.lineCap = v;
|
|
6530
|
+
}
|
|
6531
|
+
get lineJoin() {
|
|
6532
|
+
return this.state.lineJoin;
|
|
6533
|
+
}
|
|
6534
|
+
set lineJoin(v) {
|
|
6535
|
+
this.state.lineJoin = v;
|
|
6536
|
+
}
|
|
6537
|
+
get miterLimit() {
|
|
6538
|
+
return this.state.miterLimit;
|
|
6539
|
+
}
|
|
6540
|
+
set miterLimit(v) {
|
|
6541
|
+
if (v > 0)
|
|
6542
|
+
this.state.miterLimit = v;
|
|
6543
|
+
}
|
|
6544
|
+
get globalAlpha() {
|
|
6545
|
+
return this.state.globalAlpha;
|
|
6546
|
+
}
|
|
6547
|
+
set globalAlpha(v) {
|
|
6548
|
+
if (v >= 0 && v <= 1)
|
|
6549
|
+
this.state.globalAlpha = v;
|
|
6550
|
+
}
|
|
6551
|
+
get font() {
|
|
6552
|
+
return this.state.font;
|
|
6553
|
+
}
|
|
6554
|
+
set font(v) {
|
|
6555
|
+
this.state.font = v;
|
|
6556
|
+
}
|
|
6557
|
+
get textAlign() {
|
|
6558
|
+
return this.state.textAlign;
|
|
6559
|
+
}
|
|
6560
|
+
set textAlign(v) {
|
|
6561
|
+
this.state.textAlign = v;
|
|
6562
|
+
}
|
|
6563
|
+
get textBaseline() {
|
|
6564
|
+
return this.state.textBaseline;
|
|
6565
|
+
}
|
|
6566
|
+
set textBaseline(v) {
|
|
6567
|
+
this.state.textBaseline = v;
|
|
6568
|
+
}
|
|
6569
|
+
setLineDash(segments) {
|
|
6570
|
+
this.state.lineDash = segments.length % 2 ? [...segments, ...segments] : [...segments];
|
|
6571
|
+
}
|
|
6572
|
+
getLineDash() {
|
|
6573
|
+
return [...this.state.lineDash];
|
|
6574
|
+
}
|
|
6575
|
+
save() {
|
|
6576
|
+
this.stack.push({ ...this.state, transform: [...this.state.transform], lineDash: [...this.state.lineDash] });
|
|
6577
|
+
}
|
|
6578
|
+
restore() {
|
|
6579
|
+
const state = this.stack.pop();
|
|
6580
|
+
if (state)
|
|
6581
|
+
this.state = state;
|
|
6582
|
+
}
|
|
6583
|
+
setTransform(a, b, c, d, e, f) {
|
|
6584
|
+
this.state.transform = [a, b, c, d, e, f];
|
|
6585
|
+
}
|
|
6586
|
+
resetTransform() {
|
|
6587
|
+
this.state.transform = [1, 0, 0, 1, 0, 0];
|
|
6588
|
+
}
|
|
6589
|
+
transform(a, b, c, d, e, f) {
|
|
6590
|
+
const [A, B, C, D, E, F] = this.state.transform;
|
|
6591
|
+
this.state.transform = [A * a + C * b, B * a + D * b, A * c + C * d, B * c + D * d, A * e + C * f + E, B * e + D * f + F];
|
|
6592
|
+
}
|
|
6593
|
+
translate(x, y) {
|
|
6594
|
+
this.transform(1, 0, 0, 1, x, y);
|
|
6595
|
+
}
|
|
6596
|
+
scale(x, y) {
|
|
6597
|
+
this.transform(x, 0, 0, y, 0, 0);
|
|
6598
|
+
}
|
|
6599
|
+
rotate(angle) {
|
|
6600
|
+
const c = Math.cos(angle), s = Math.sin(angle);
|
|
6601
|
+
this.transform(c, s, -s, c, 0, 0);
|
|
6602
|
+
}
|
|
6603
|
+
getTransform() {
|
|
6604
|
+
return [...this.state.transform];
|
|
6605
|
+
}
|
|
6606
|
+
point(x, y) {
|
|
6607
|
+
const [a, b, c, d, e, f] = this.state.transform;
|
|
6608
|
+
return [a * x + c * y + e, b * x + d * y + f];
|
|
6609
|
+
}
|
|
6610
|
+
scaleFactor() {
|
|
6611
|
+
const [a, b, c, d] = this.state.transform;
|
|
6612
|
+
return Math.sqrt(Math.abs(a * d - b * c));
|
|
6613
|
+
}
|
|
6614
|
+
beginPath() {
|
|
6615
|
+
this.path = "";
|
|
6616
|
+
this.start = null;
|
|
6617
|
+
this.current = null;
|
|
6618
|
+
}
|
|
6619
|
+
moveTo(x, y) {
|
|
6620
|
+
const p = this.point(x, y);
|
|
6621
|
+
this.path += `M${fmt(p[0])} ${fmt(p[1])}`;
|
|
6622
|
+
this.start = p;
|
|
6623
|
+
this.current = p;
|
|
6624
|
+
}
|
|
6625
|
+
lineTo(x, y) {
|
|
6626
|
+
if (!this.current)
|
|
6627
|
+
return this.moveTo(x, y);
|
|
6628
|
+
const p = this.point(x, y);
|
|
6629
|
+
this.path += `L${fmt(p[0])} ${fmt(p[1])}`;
|
|
6630
|
+
this.current = p;
|
|
6631
|
+
}
|
|
6632
|
+
closePath() {
|
|
6633
|
+
if (this.current) {
|
|
6634
|
+
this.path += "Z";
|
|
6635
|
+
this.current = this.start;
|
|
6636
|
+
}
|
|
6637
|
+
}
|
|
6638
|
+
quadraticCurveTo(cx, cy, x, y) {
|
|
6639
|
+
if (!this.current)
|
|
6640
|
+
this.moveTo(cx, cy);
|
|
6641
|
+
const c = this.point(cx, cy), p = this.point(x, y);
|
|
6642
|
+
this.path += `Q${fmt(c[0])} ${fmt(c[1])} ${fmt(p[0])} ${fmt(p[1])}`;
|
|
6643
|
+
this.current = p;
|
|
6644
|
+
}
|
|
6645
|
+
bezierCurveTo(c1x, c1y, c2x, c2y, x, y) {
|
|
6646
|
+
if (!this.current)
|
|
6647
|
+
this.moveTo(c1x, c1y);
|
|
6648
|
+
const a = this.point(c1x, c1y), b = this.point(c2x, c2y), p = this.point(x, y);
|
|
6649
|
+
this.path += `C${fmt(a[0])} ${fmt(a[1])} ${fmt(b[0])} ${fmt(b[1])} ${fmt(p[0])} ${fmt(p[1])}`;
|
|
6650
|
+
this.current = p;
|
|
6651
|
+
}
|
|
6652
|
+
rect(x, y, w, h) {
|
|
6653
|
+
this.moveTo(x, y);
|
|
6654
|
+
this.lineTo(x + w, y);
|
|
6655
|
+
this.lineTo(x + w, y + h);
|
|
6656
|
+
this.lineTo(x, y + h);
|
|
6657
|
+
this.closePath();
|
|
6658
|
+
this.moveTo(x, y);
|
|
6659
|
+
}
|
|
6660
|
+
roundRect(x, y, w, h, radius = 0) {
|
|
6661
|
+
const r = Math.max(0, Math.min(Array.isArray(radius) ? radius[0] ?? 0 : radius, Math.abs(w) / 2, Math.abs(h) / 2));
|
|
6662
|
+
if (r === 0)
|
|
6663
|
+
return this.rect(x, y, w, h);
|
|
6664
|
+
const q = Math.PI / 2;
|
|
6665
|
+
this.moveTo(x + r, y);
|
|
6666
|
+
this.lineTo(x + w - r, y);
|
|
6667
|
+
this.arc(x + w - r, y + r, r, -q, 0);
|
|
6668
|
+
this.lineTo(x + w, y + h - r);
|
|
6669
|
+
this.arc(x + w - r, y + h - r, r, 0, q);
|
|
6670
|
+
this.lineTo(x + r, y + h);
|
|
6671
|
+
this.arc(x + r, y + h - r, r, q, 2 * q);
|
|
6672
|
+
this.lineTo(x, y + r);
|
|
6673
|
+
this.arc(x + r, y + r, r, 2 * q, 3 * q);
|
|
6674
|
+
this.closePath();
|
|
6675
|
+
this.moveTo(x, y);
|
|
6676
|
+
}
|
|
6677
|
+
ellipse(x, y, rx, ry, rotation, start, end, ccw = false) {
|
|
6678
|
+
if (rx < 0 || ry < 0)
|
|
6679
|
+
throw new RangeError("ellipse radii must be non-negative");
|
|
6680
|
+
let sweep = end - start;
|
|
6681
|
+
const full = Math.PI * 2;
|
|
6682
|
+
if (!ccw && sweep < 0)
|
|
6683
|
+
sweep = sweep % full + full;
|
|
6684
|
+
if (ccw && sweep > 0)
|
|
6685
|
+
sweep = sweep % full - full;
|
|
6686
|
+
if (Math.abs(end - start) >= full)
|
|
6687
|
+
sweep = ccw ? -full : full;
|
|
6688
|
+
const at = (t) => {
|
|
6689
|
+
const cx = Math.cos(t) * rx, cy = Math.sin(t) * ry;
|
|
6690
|
+
return [x + cx * Math.cos(rotation) - cy * Math.sin(rotation), y + cx * Math.sin(rotation) + cy * Math.cos(rotation)];
|
|
6691
|
+
};
|
|
6692
|
+
const derivative = (t) => {
|
|
6693
|
+
const dx = -Math.sin(t) * rx, dy = Math.cos(t) * ry;
|
|
6694
|
+
return [dx * Math.cos(rotation) - dy * Math.sin(rotation), dx * Math.sin(rotation) + dy * Math.cos(rotation)];
|
|
6695
|
+
};
|
|
6696
|
+
const first = at(start);
|
|
6697
|
+
if (!this.current)
|
|
6698
|
+
this.moveTo(first[0], first[1]);
|
|
6699
|
+
else {
|
|
6700
|
+
const [px, py] = this.point(first[0], first[1]);
|
|
6701
|
+
if (Math.abs(px - this.current[0]) > 0.000001 || Math.abs(py - this.current[1]) > 0.000001)
|
|
6702
|
+
this.lineTo(first[0], first[1]);
|
|
6703
|
+
}
|
|
6704
|
+
const segments = Math.max(1, Math.ceil(Math.abs(sweep) / (Math.PI / 2)));
|
|
6705
|
+
const step = sweep / segments;
|
|
6706
|
+
const k = 4 / 3 * Math.tan(step / 4);
|
|
6707
|
+
for (let i = 0;i < segments; i++) {
|
|
6708
|
+
const t0 = start + step * i, t1 = t0 + step;
|
|
6709
|
+
const p0 = at(t0), p1 = at(t1), d0 = derivative(t0), d1 = derivative(t1);
|
|
6710
|
+
this.bezierCurveTo(p0[0] + k * d0[0], p0[1] + k * d0[1], p1[0] - k * d1[0], p1[1] - k * d1[1], p1[0], p1[1]);
|
|
6711
|
+
}
|
|
6712
|
+
}
|
|
6713
|
+
arc(x, y, r, start, end, ccw = false) {
|
|
6714
|
+
this.ellipse(x, y, r, r, 0, start, end, ccw);
|
|
6715
|
+
}
|
|
6716
|
+
arcTo(x1, y1, x2, y2, r) {
|
|
6717
|
+
if (r < 0)
|
|
6718
|
+
throw new RangeError("arcTo radius must be non-negative");
|
|
6719
|
+
if (!this.current)
|
|
6720
|
+
this.moveTo(x1, y1);
|
|
6721
|
+
const [a, b, c, d, e, f] = this.state.transform;
|
|
6722
|
+
const det = a * d - b * c;
|
|
6723
|
+
const [cx, cy] = this.current;
|
|
6724
|
+
const x0 = (d * (cx - e) - c * (cy - f)) / det, y0 = (-b * (cx - e) + a * (cy - f)) / det;
|
|
6725
|
+
const l1 = Math.hypot(x0 - x1, y0 - y1), l2 = Math.hypot(x2 - x1, y2 - y1);
|
|
6726
|
+
if (r === 0 || l1 === 0 || l2 === 0)
|
|
6727
|
+
return this.lineTo(x1, y1);
|
|
6728
|
+
const u1 = [(x0 - x1) / l1, (y0 - y1) / l1], u2 = [(x2 - x1) / l2, (y2 - y1) / l2];
|
|
6729
|
+
const cross = u1[0] * u2[1] - u1[1] * u2[0];
|
|
6730
|
+
if (Math.abs(cross) < 0.000000001)
|
|
6731
|
+
return this.lineTo(x1, y1);
|
|
6732
|
+
const angle = Math.acos(Math.max(-1, Math.min(1, u1[0] * u2[0] + u1[1] * u2[1])));
|
|
6733
|
+
const tangent = r / Math.tan(angle / 2);
|
|
6734
|
+
const t1 = [x1 + u1[0] * tangent, y1 + u1[1] * tangent];
|
|
6735
|
+
const bisector = [u1[0] + u2[0], u1[1] + u2[1]];
|
|
6736
|
+
const length = Math.hypot(bisector[0], bisector[1]);
|
|
6737
|
+
const distance = r / Math.sin(angle / 2);
|
|
6738
|
+
const center = [x1 + bisector[0] / length * distance, y1 + bisector[1] / length * distance];
|
|
6739
|
+
const t2 = [x1 + u2[0] * tangent, y1 + u2[1] * tangent];
|
|
6740
|
+
const start = Math.atan2(t1[1] - center[1], t1[0] - center[0]);
|
|
6741
|
+
const end = Math.atan2(t2[1] - center[1], t2[0] - center[0]);
|
|
6742
|
+
let sweep = end - start;
|
|
6743
|
+
while (sweep > Math.PI)
|
|
6744
|
+
sweep -= 2 * Math.PI;
|
|
6745
|
+
while (sweep < -Math.PI)
|
|
6746
|
+
sweep += 2 * Math.PI;
|
|
6747
|
+
this.lineTo(t1[0], t1[1]);
|
|
6748
|
+
this.arc(center[0], center[1], r, start, start + sweep, sweep < 0);
|
|
6749
|
+
}
|
|
6750
|
+
createLinearGradient(x0, y0, x1, y1) {
|
|
6751
|
+
const a = this.point(x0, y0), b = this.point(x1, y1);
|
|
6752
|
+
return new CanvasGradient(`g${this.gradients++}`, "linear", [...a, ...b]);
|
|
6753
|
+
}
|
|
6754
|
+
createRadialGradient(x0, y0, r0, x1, y1, r1) {
|
|
6755
|
+
const a = this.point(x0, y0), b = this.point(x1, y1), s = this.scaleFactor();
|
|
6756
|
+
return new CanvasGradient(`g${this.gradients++}`, "radial", [...a, r0 * s, ...b, r1 * s]);
|
|
6757
|
+
}
|
|
6758
|
+
paint(style) {
|
|
6759
|
+
if (typeof style === "string")
|
|
6760
|
+
return esc(style);
|
|
6761
|
+
if (!this.defs.some((def) => def.includes(`id="${style.id}"`))) {
|
|
6762
|
+
const stops = [...style.stops].sort((p, q) => p[0] - q[0]).map(([o, c]) => `<stop offset="${fmt(o)}" stop-color="${esc(c)}"/>`).join("");
|
|
6763
|
+
const [p, q, r, s, t, u] = style.coords.map(fmt);
|
|
6764
|
+
this.defs.push(style.kind === "linear" ? `<linearGradient id="${style.id}" gradientUnits="userSpaceOnUse" x1="${p}" y1="${q}" x2="${r}" y2="${s}">${stops}</linearGradient>` : `<radialGradient id="${style.id}" gradientUnits="userSpaceOnUse" fx="${p}" fy="${q}" fr="${r}" cx="${s}" cy="${t}" r="${u}">${stops}</radialGradient>`);
|
|
6765
|
+
}
|
|
6766
|
+
return `url(#${style.id})`;
|
|
6767
|
+
}
|
|
6768
|
+
emit(path, fill, stroke, rule = "nonzero") {
|
|
6769
|
+
if (!path)
|
|
6770
|
+
return;
|
|
6771
|
+
const s = this.state;
|
|
6772
|
+
const attrs = [`d="${path}"`, `fill="${fill ?? "none"}"`];
|
|
6773
|
+
if (fill)
|
|
6774
|
+
attrs.push(`fill-rule="${rule}"`);
|
|
6775
|
+
if (stroke) {
|
|
6776
|
+
const width = s.lineWidth * this.scaleFactor();
|
|
6777
|
+
attrs.push(`stroke="${stroke}"`, `stroke-width="${fmt(width)}"`, `stroke-linecap="${s.lineCap}"`, `stroke-linejoin="${s.lineJoin}"`, `stroke-miterlimit="${fmt(s.miterLimit)}"`);
|
|
6778
|
+
if (s.lineDash.length)
|
|
6779
|
+
attrs.push(`stroke-dasharray="${s.lineDash.map((v) => fmt(v * this.scaleFactor())).join(" ")}"`);
|
|
6780
|
+
}
|
|
6781
|
+
if (s.globalAlpha < 1)
|
|
6782
|
+
attrs.push(`opacity="${fmt(s.globalAlpha)}"`);
|
|
6783
|
+
this.elements.push(`<path ${attrs.join(" ")}/>`);
|
|
6784
|
+
}
|
|
6785
|
+
fill(rule = "nonzero") {
|
|
6786
|
+
this.emit(this.path, this.paint(this.state.fillStyle), null, rule);
|
|
6787
|
+
}
|
|
6788
|
+
stroke() {
|
|
6789
|
+
this.emit(this.path, null, this.paint(this.state.strokeStyle));
|
|
6790
|
+
}
|
|
6791
|
+
rectPath(x, y, w, h) {
|
|
6792
|
+
const corners = [this.point(x, y), this.point(x + w, y), this.point(x + w, y + h), this.point(x, y + h)];
|
|
6793
|
+
return `M${corners.map((p) => `${fmt(p[0])} ${fmt(p[1])}`).join("L")}Z`;
|
|
6794
|
+
}
|
|
6795
|
+
fillRect(x, y, w, h) {
|
|
6796
|
+
this.emit(this.rectPath(x, y, w, h), this.paint(this.state.fillStyle), null);
|
|
6797
|
+
}
|
|
6798
|
+
strokeRect(x, y, w, h) {
|
|
6799
|
+
this.emit(this.rectPath(x, y, w, h), null, this.paint(this.state.strokeStyle));
|
|
6800
|
+
}
|
|
6801
|
+
flush() {
|
|
6802
|
+
if (this.elements.length)
|
|
6803
|
+
this.ops.push({ svg: this.elements });
|
|
6804
|
+
this.elements = [];
|
|
6805
|
+
}
|
|
6806
|
+
clearRect(x, y, w, h) {
|
|
6807
|
+
const corners = [this.point(x, y), this.point(x + w, y), this.point(x + w, y + h), this.point(x, y + h)];
|
|
6808
|
+
const inside = (px, py) => {
|
|
6809
|
+
let hit = false;
|
|
6810
|
+
for (let i = 0, j = 3;i < 4; j = i++) {
|
|
6811
|
+
const [xi, yi] = corners[i], [xj, yj] = corners[j];
|
|
6812
|
+
if (yi > py !== yj > py && px < (xj - xi) * (py - yi) / (yj - yi) + xi)
|
|
6813
|
+
hit = !hit;
|
|
6814
|
+
}
|
|
6815
|
+
return hit;
|
|
6816
|
+
};
|
|
6817
|
+
const eps = 0.000001;
|
|
6818
|
+
if ([[-eps, -eps], [this.width + eps, -eps], [this.width + eps, this.height + eps], [-eps, this.height + eps]].every(([px, py]) => inside(px, py))) {
|
|
6819
|
+
this.elements = [];
|
|
6820
|
+
this.texts.length = 0;
|
|
6821
|
+
this.ops.length = 0;
|
|
6822
|
+
return;
|
|
6823
|
+
}
|
|
6824
|
+
this.flush();
|
|
6825
|
+
this.ops.push({ clear: `M${corners.map((p) => `${fmt(p[0])} ${fmt(p[1])}`).join("L")}Z` });
|
|
6826
|
+
}
|
|
6827
|
+
text(text, x, y, stroke) {
|
|
6828
|
+
const style = this.state[stroke ? "strokeStyle" : "fillStyle"];
|
|
6829
|
+
const color = typeof style === "string" ? style : style.stops[0]?.[1] ?? "#000000";
|
|
6830
|
+
const entry = { text, x, y, matrix: [...this.state.transform], font: this.state.font, color, align: this.state.textAlign, baseline: this.state.textBaseline, alpha: this.state.globalAlpha, stroke, lineWidth: this.state.lineWidth };
|
|
6831
|
+
this.flush();
|
|
6832
|
+
this.texts.push(entry);
|
|
6833
|
+
this.ops.push({ text: entry });
|
|
6834
|
+
}
|
|
6835
|
+
drawImage(image, ...args) {
|
|
6836
|
+
const source = typeof image === "object" && image !== null && "src" in image && !("rgba" in image) ? image.src : image;
|
|
6837
|
+
const base = { source, matrix: [...this.state.transform], alpha: this.state.globalAlpha };
|
|
6838
|
+
let entry;
|
|
6839
|
+
if (args.length === 2)
|
|
6840
|
+
entry = { ...base, dx: args[0], dy: args[1] };
|
|
6841
|
+
else if (args.length === 4)
|
|
6842
|
+
entry = { ...base, dx: args[0], dy: args[1], dw: args[2], dh: args[3] };
|
|
6843
|
+
else if (args.length === 8)
|
|
6844
|
+
entry = { ...base, crop: [args[0], args[1], args[2], args[3]], dx: args[4], dy: args[5], dw: args[6], dh: args[7] };
|
|
6845
|
+
else
|
|
6846
|
+
throw new TypeError("drawImage takes 3, 5 or 9 arguments");
|
|
6847
|
+
this.flush();
|
|
6848
|
+
this.ops.push({ image: entry });
|
|
6849
|
+
}
|
|
6850
|
+
fillText(text, x, y) {
|
|
6851
|
+
this.text(text, x, y, false);
|
|
6852
|
+
}
|
|
6853
|
+
strokeText(text, x, y) {
|
|
6854
|
+
this.text(text, x, y, true);
|
|
6855
|
+
}
|
|
6856
|
+
toSvg(elements = [...this.ops.flatMap((op) => ("svg" in op) ? op.svg : []), ...this.elements]) {
|
|
6857
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${this.width}" height="${this.height}" viewBox="0 0 ${this.width} ${this.height}">${this.defs.length ? `<defs>${this.defs.join("")}</defs>` : ""}${elements.join("")}</svg>`;
|
|
6858
|
+
}
|
|
6859
|
+
layers() {
|
|
6860
|
+
return this.elements.length ? [...this.ops, { svg: this.elements }] : [...this.ops];
|
|
6861
|
+
}
|
|
6862
|
+
}
|
|
6863
|
+
function parseCanvasFont(font) {
|
|
6864
|
+
const match = /^\s*(?:(italic|oblique|normal)\s+)?(?:(small-caps|normal)\s+)?(?:(bold|bolder|lighter|normal|[1-9]00)\s+)?([\d.]+)px(?:\/[\d.]+\w*)?\s+(.+?)\s*$/i.exec(font);
|
|
6865
|
+
if (!match)
|
|
6866
|
+
return { fontSize: 10, fontFamily: "sans-serif" };
|
|
6867
|
+
const weight = match[3]?.toLowerCase();
|
|
6868
|
+
return {
|
|
6869
|
+
...match[1] && match[1] !== "normal" ? { fontStyle: "italic" } : {},
|
|
6870
|
+
...weight && weight !== "normal" ? { fontWeight: weight === "bold" || weight === "bolder" ? 700 : weight === "lighter" ? 300 : Number(weight) } : {},
|
|
6871
|
+
fontSize: Number(match[4]),
|
|
6872
|
+
fontFamily: match[5].replace(/["']/g, "").split(",")[0].trim()
|
|
6873
|
+
};
|
|
6874
|
+
}
|
|
6875
|
+
var isIdentity = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
|
|
6876
|
+
var matrixStyle = (m) => isIdentity(m) ? {} : { transformMatrix: [...m] };
|
|
6877
|
+
var layerBox = { position: "absolute", left: 0, top: 0 };
|
|
6878
|
+
function canvasText(text, index) {
|
|
6879
|
+
const font = parseCanvasFont(text.font);
|
|
6880
|
+
const top = text.baseline === "top" || text.baseline === "hanging" ? text.y : text.baseline === "middle" ? text.y - font.fontSize / 2 : text.baseline === "bottom" || text.baseline === "ideographic" ? text.y - font.fontSize : text.y - font.fontSize * 0.86;
|
|
6881
|
+
const align = text.align === "center" ? "center" : text.align === "right" || text.align === "end" ? "end" : "start";
|
|
6882
|
+
return View({ key: `t${index}`, style: { ...layerBox, width: 0, height: 0, ...matrixStyle(text.matrix) }, children: View({
|
|
6883
|
+
style: { position: "absolute", left: text.x, top, width: 0, direction: "column", align, opacity: text.alpha },
|
|
6884
|
+
children: Text({ style: { ...font, lineHeight: 1, whiteSpace: "pre", foreground: text.color }, children: text.text })
|
|
6885
|
+
}) });
|
|
6886
|
+
}
|
|
6887
|
+
function canvasImage(image, index) {
|
|
6888
|
+
const [a, b, c, d, e, f] = image.matrix;
|
|
6889
|
+
const at = (x, y, sx = 1, sy = 1) => [a * sx, b * sx, c * sy, d * sy, a * x + c * y + e, b * x + d * y + f];
|
|
6890
|
+
if (image.crop) {
|
|
6891
|
+
const [sx, sy, sw, sh] = image.crop;
|
|
6892
|
+
return View({
|
|
6893
|
+
key: `i${index}`,
|
|
6894
|
+
style: { ...layerBox, width: sw, height: sh, overflow: "hidden", opacity: image.alpha, ...matrixStyle(at(image.dx, image.dy, image.dw / sw, image.dh / sh)) },
|
|
6895
|
+
children: Image({ src: image.source, fit: "fill", style: { position: "absolute", left: -sx, top: -sy, radius: 0 } })
|
|
6896
|
+
});
|
|
6897
|
+
}
|
|
6898
|
+
return View({
|
|
6899
|
+
key: `i${index}`,
|
|
6900
|
+
style: { ...layerBox, opacity: image.alpha, ...matrixStyle(at(image.dx, image.dy)) },
|
|
6901
|
+
children: Image({ src: image.source, fit: "fill", style: { radius: 0 }, ...image.dw !== undefined ? { width: image.dw, height: image.dh } : {} })
|
|
6902
|
+
});
|
|
6903
|
+
}
|
|
6904
|
+
function expandCanvas(props, key) {
|
|
6905
|
+
const width = Number(props.width ?? 300), height = Number(props.height ?? 150);
|
|
6906
|
+
const context = new CanvasRenderingContext2D(width, height);
|
|
6907
|
+
props.onDraw?.(context);
|
|
6908
|
+
const id = String(props.id ?? key);
|
|
6909
|
+
let children = [];
|
|
6910
|
+
let layer = 0;
|
|
6911
|
+
context.layers().forEach((op, index) => {
|
|
6912
|
+
if ("svg" in op)
|
|
6913
|
+
children.push(_nativeJsx("svg", { id: layer === 0 ? `${id}-scene` : `${id}-scene-${layer}`, svg: context.toSvg(op.svg), style: { ...layerBox, width, height } }, `s${index}`));
|
|
6914
|
+
if ("svg" in op)
|
|
6915
|
+
layer++;
|
|
6916
|
+
if ("text" in op)
|
|
6917
|
+
children.push(canvasText(op.text, index));
|
|
6918
|
+
if ("image" in op)
|
|
6919
|
+
children.push(canvasImage(op.image, index));
|
|
6920
|
+
if ("clear" in op)
|
|
6921
|
+
children = [View({ key: `c${index}`, style: { ...layerBox, width, height, clipPath: `path(evenodd, "M0 0H${width}V${height}H0Z${op.clear}")` }, children })];
|
|
6922
|
+
});
|
|
6923
|
+
return View({
|
|
6924
|
+
id,
|
|
6925
|
+
...props.ariaLabel ? { control: { role: "group", label: props.ariaLabel } } : {},
|
|
6926
|
+
style: { width, height, shrink: 0, position: "relative", overflow: "hidden", ...canonicalizeIntrinsicStyle(props.style) },
|
|
6927
|
+
children
|
|
6928
|
+
});
|
|
6929
|
+
}
|
|
6930
|
+
|
|
6931
|
+
// packages/core/src/html-elements.ts
|
|
6932
|
+
var HTML_ELEMENTS = new Set(["pre", "blockquote", "meter", "form", "fieldset", "legend", "ul", "ol", "li", "dl", "dt", "dd", "table", "thead", "tbody", "tfoot", "tr", "th", "td", "caption", "details", "summary"]);
|
|
6933
|
+
var HTML_INPUT_TYPES = new Set(["checkbox", "radio", "range", "date", "file", "color", "time"]);
|
|
6934
|
+
var COLOR_PALETTE = ["#000000", "#ffffff", "#ef4444", "#f97316", "#eab308", "#22c55e", "#14b8a6", "#3b82f6", "#6366f1", "#a855f7", "#ec4899", "#78716c"];
|
|
6935
|
+
var state = new Map;
|
|
6936
|
+
function formValues(key) {
|
|
6937
|
+
const id = `form:${key}`;
|
|
6938
|
+
let values = state.get(id);
|
|
6939
|
+
if (!values)
|
|
6940
|
+
state.set(id, values = new Map);
|
|
6941
|
+
return values;
|
|
6942
|
+
}
|
|
6943
|
+
function storedValue(key, initial) {
|
|
6944
|
+
return state.has(key) ? state.get(key) : initial;
|
|
6945
|
+
}
|
|
6946
|
+
function storeValue(key, value) {
|
|
6947
|
+
state.set(key, value);
|
|
6948
|
+
}
|
|
6949
|
+
var ACTIVE_APP2 = Symbol.for("tarve.activeApp");
|
|
6950
|
+
function activeApp() {
|
|
6951
|
+
return globalThis[ACTIVE_APP2];
|
|
6952
|
+
}
|
|
6953
|
+
function uncontrolled(key, controlled, initial) {
|
|
6954
|
+
if (controlled !== undefined)
|
|
6955
|
+
return controlled;
|
|
6956
|
+
return state.has(key) ? state.get(key) : initial;
|
|
6957
|
+
}
|
|
6958
|
+
function acceptFilters(accept) {
|
|
6959
|
+
if (typeof accept !== "string" || !accept.trim())
|
|
6960
|
+
return;
|
|
6961
|
+
const extensions = accept.split(",").map((part) => part.trim()).filter((part) => part.startsWith(".")).map((part) => part.slice(1));
|
|
6962
|
+
return extensions.length ? [{ name: "Accepted files", extensions }] : undefined;
|
|
6963
|
+
}
|
|
6964
|
+
function expandInput(props, key, form) {
|
|
6965
|
+
const id = String(props.id ?? key);
|
|
6966
|
+
const name = props.name;
|
|
6967
|
+
const style = canonicalizeIntrinsicStyle(props.style);
|
|
6968
|
+
const record = (value) => {
|
|
6969
|
+
if (form && name)
|
|
6970
|
+
form.values.set(name, value);
|
|
6971
|
+
};
|
|
6972
|
+
if (form && name && props.required)
|
|
6973
|
+
form.required.add(name);
|
|
6974
|
+
switch (props.type) {
|
|
6975
|
+
case "checkbox": {
|
|
6976
|
+
const checked = uncontrolled(id, props.checked, props.defaultChecked === true);
|
|
6977
|
+
if (!form?.values.has(name ?? ""))
|
|
6978
|
+
record(checked);
|
|
6979
|
+
return Checkbox({
|
|
6980
|
+
id,
|
|
6981
|
+
style,
|
|
6982
|
+
label: props.label ?? props.ariaLabel ?? "",
|
|
6983
|
+
checked,
|
|
6984
|
+
disabled: props.disabled,
|
|
6985
|
+
onCheckedChange: (next) => {
|
|
6986
|
+
state.set(id, next);
|
|
6987
|
+
record(next);
|
|
6988
|
+
props.onCheckedChange?.(next);
|
|
6989
|
+
props.onChange?.(String(next));
|
|
6990
|
+
}
|
|
6991
|
+
});
|
|
6992
|
+
}
|
|
6993
|
+
case "radio": {
|
|
6994
|
+
const group = `radio:${name ?? id}`;
|
|
6995
|
+
const value = String(props.value ?? "on");
|
|
6996
|
+
const selected = props.checked !== undefined ? props.checked ? value : undefined : uncontrolled(group, undefined, props.defaultChecked ? value : undefined);
|
|
6997
|
+
if (props.checked === undefined && props.defaultChecked && !state.has(group))
|
|
6998
|
+
state.set(group, value);
|
|
6999
|
+
if (selected === value)
|
|
7000
|
+
record(value);
|
|
7001
|
+
return RadioGroup({
|
|
7002
|
+
id,
|
|
7003
|
+
style,
|
|
7004
|
+
value: selected === value ? value : "",
|
|
7005
|
+
disabled: props.disabled,
|
|
7006
|
+
options: [{ value, label: props.label ?? props.ariaLabel ?? "" }],
|
|
7007
|
+
onValueChange: (next) => {
|
|
7008
|
+
state.set(group, next);
|
|
7009
|
+
record(next);
|
|
7010
|
+
props.onChange?.(next);
|
|
7011
|
+
}
|
|
7012
|
+
});
|
|
7013
|
+
}
|
|
7014
|
+
case "range": {
|
|
7015
|
+
const min = Number(props.min ?? 0);
|
|
7016
|
+
const max = Number(props.max ?? 100);
|
|
7017
|
+
const fallback = max < min ? min : min + (max - min) / 2;
|
|
7018
|
+
const value = Number(uncontrolled(id, props.value, props.defaultValue ?? fallback));
|
|
7019
|
+
record(String(value));
|
|
7020
|
+
return Slider({
|
|
7021
|
+
id,
|
|
7022
|
+
style,
|
|
7023
|
+
value,
|
|
7024
|
+
min,
|
|
7025
|
+
max,
|
|
7026
|
+
step: Number(props.step ?? 1),
|
|
7027
|
+
label: props.label ?? props.ariaLabel,
|
|
7028
|
+
disabled: props.disabled,
|
|
7029
|
+
onValueChange: (next) => {
|
|
7030
|
+
state.set(id, next);
|
|
7031
|
+
record(String(next));
|
|
7032
|
+
props.onChange?.(String(next));
|
|
7033
|
+
}
|
|
7034
|
+
});
|
|
7035
|
+
}
|
|
7036
|
+
case "date": {
|
|
7037
|
+
const value = uncontrolled(id, props.value, props.defaultValue);
|
|
7038
|
+
if (value)
|
|
7039
|
+
record(value);
|
|
7040
|
+
const open = state.get(`${id}:open`) ?? false;
|
|
7041
|
+
const month = state.get(`${id}:month`) ?? (value ?? new Date().toISOString()).slice(0, 7);
|
|
7042
|
+
return DatePicker({
|
|
7043
|
+
id,
|
|
7044
|
+
style,
|
|
7045
|
+
value,
|
|
7046
|
+
open,
|
|
7047
|
+
month,
|
|
7048
|
+
min: props.min,
|
|
7049
|
+
max: props.max,
|
|
7050
|
+
disabled: props.disabled,
|
|
7051
|
+
placeholder: props.placeholder ?? "yyyy-mm-dd",
|
|
7052
|
+
onOpenChange: (next) => {
|
|
7053
|
+
state.set(`${id}:open`, next);
|
|
7054
|
+
},
|
|
7055
|
+
onMonthChange: (next) => {
|
|
7056
|
+
state.set(`${id}:month`, next);
|
|
7057
|
+
},
|
|
7058
|
+
onValueChange: (next) => {
|
|
7059
|
+
state.set(id, next);
|
|
7060
|
+
record(next);
|
|
7061
|
+
props.onChange?.(next);
|
|
7062
|
+
}
|
|
7063
|
+
});
|
|
7064
|
+
}
|
|
7065
|
+
case "color": {
|
|
7066
|
+
const value = uncontrolled(id, props.value, props.defaultValue ?? "#000000").toLowerCase();
|
|
7067
|
+
record(value);
|
|
7068
|
+
const open = state.get(`${id}:open`) ?? false;
|
|
7069
|
+
const pick = (next) => {
|
|
7070
|
+
const normalized = next.trim().toLowerCase();
|
|
7071
|
+
if (!/^#[0-9a-f]{6}$/.test(normalized))
|
|
7072
|
+
return;
|
|
7073
|
+
state.set(id, normalized);
|
|
7074
|
+
record(normalized);
|
|
7075
|
+
props.onChange?.(normalized);
|
|
7076
|
+
};
|
|
7077
|
+
return Column({ id, gap: 6, style, children: [
|
|
7078
|
+
Row({ gap: 8, align: "center", children: [
|
|
7079
|
+
Pressable({
|
|
7080
|
+
id: `${id}-swatch`,
|
|
7081
|
+
disabled: props.disabled,
|
|
7082
|
+
control: { role: "button", label: props.label ?? props.ariaLabel ?? "Choose colour", expanded: open },
|
|
7083
|
+
onClick: () => {
|
|
7084
|
+
state.set(`${id}:open`, !open);
|
|
7085
|
+
},
|
|
7086
|
+
style: { width: 44, height: 24, radius: 4, borderWidth: 1, borderColor: theme.colors.border, background: value }
|
|
7087
|
+
}),
|
|
7088
|
+
Input({ id: `${id}-hex`, value, disabled: props.disabled, onChange: pick, style: { width: 100, fontFamily: "monospace" } })
|
|
7089
|
+
] }),
|
|
7090
|
+
...open ? [Row({ gap: 4, wrap: true, style: { width: 180 }, children: COLOR_PALETTE.map((color) => Pressable({
|
|
7091
|
+
key: color,
|
|
7092
|
+
id: `${id}-${color.slice(1)}`,
|
|
7093
|
+
control: { role: "button", label: color },
|
|
7094
|
+
onClick: () => {
|
|
7095
|
+
pick(color);
|
|
7096
|
+
state.set(`${id}:open`, false);
|
|
7097
|
+
},
|
|
7098
|
+
style: { width: 24, height: 24, radius: 4, borderWidth: color === value ? 2 : 1, borderColor: color === value ? theme.colors.ring : theme.colors.border, background: color }
|
|
7099
|
+
})) })] : []
|
|
7100
|
+
] });
|
|
7101
|
+
}
|
|
7102
|
+
case "time": {
|
|
7103
|
+
const value = uncontrolled(id, props.value, props.defaultValue ?? "");
|
|
7104
|
+
const valid = /^([01]\d|2[0-3]):[0-5]\d$/.test(value);
|
|
7105
|
+
record(valid ? value : "");
|
|
7106
|
+
return Input({
|
|
7107
|
+
id,
|
|
7108
|
+
value,
|
|
7109
|
+
placeholder: props.placeholder ?? "--:--",
|
|
7110
|
+
disabled: props.disabled,
|
|
7111
|
+
style: { width: 110, fontFamily: "monospace", ...value && !valid ? { borderColor: theme.colors.destructive } : {}, ...style },
|
|
7112
|
+
onChange: (next) => {
|
|
7113
|
+
const digits = next.replace(/[^0-9]/g, "").slice(0, 4);
|
|
7114
|
+
const formatted = digits.length > 2 ? `${digits.slice(0, 2)}:${digits.slice(2)}` : digits;
|
|
7115
|
+
state.set(id, formatted);
|
|
7116
|
+
const ok = /^([01]\d|2[0-3]):[0-5]\d$/.test(formatted);
|
|
7117
|
+
record(ok ? formatted : "");
|
|
7118
|
+
if (ok)
|
|
7119
|
+
props.onChange?.(formatted);
|
|
7120
|
+
},
|
|
7121
|
+
onSubmit: () => form?.submit()
|
|
7122
|
+
});
|
|
7123
|
+
}
|
|
7124
|
+
case "file": {
|
|
7125
|
+
const files = uncontrolled(id, undefined, []);
|
|
7126
|
+
record(props.multiple ? files : files[0] ?? "");
|
|
7127
|
+
const label = files.length === 0 ? "No file chosen" : files.length === 1 ? files[0].split(/[\\/]/).pop() : `${files.length} files`;
|
|
7128
|
+
return Row({ id, gap: 8, align: "center", style, children: [
|
|
7129
|
+
Button({
|
|
7130
|
+
id: `${id}-choose`,
|
|
7131
|
+
variant: "outline",
|
|
7132
|
+
size: "sm",
|
|
7133
|
+
disabled: props.disabled,
|
|
7134
|
+
children: props.multiple ? "Choose files\u2026" : "Choose file\u2026",
|
|
7135
|
+
onClick: () => {
|
|
7136
|
+
const app = activeApp();
|
|
7137
|
+
if (!app)
|
|
7138
|
+
throw new Error('<input type="file"> needs a running app');
|
|
7139
|
+
const options = { filters: acceptFilters(props.accept) };
|
|
7140
|
+
const done = (paths) => {
|
|
7141
|
+
if (paths.length === 0)
|
|
7142
|
+
return;
|
|
7143
|
+
state.set(id, paths);
|
|
7144
|
+
record(props.multiple ? paths : paths[0]);
|
|
7145
|
+
props.onFiles?.(paths);
|
|
7146
|
+
props.onChange?.(paths[0]);
|
|
7147
|
+
app.update();
|
|
7148
|
+
};
|
|
7149
|
+
if (props.multiple)
|
|
7150
|
+
app.openFilesDialog(options).then(done);
|
|
7151
|
+
else
|
|
7152
|
+
app.openFileDialog(options).then((path) => done(path ? [path] : []));
|
|
7153
|
+
}
|
|
7154
|
+
}),
|
|
7155
|
+
Text({ id: `${id}-name`, color: theme.colors.mutedForeground, children: label })
|
|
7156
|
+
] });
|
|
7157
|
+
}
|
|
7158
|
+
}
|
|
7159
|
+
throw new Error(`Unsupported input type: ${String(props.type)}`);
|
|
7160
|
+
}
|
|
7161
|
+
function childList(children) {
|
|
7162
|
+
return (Array.isArray(children) ? children.flat(Infinity) : [children]).filter((child) => child != null && typeof child !== "boolean");
|
|
7163
|
+
}
|
|
7164
|
+
function isElement(child, type) {
|
|
7165
|
+
return typeof child === "object" && child != null && !Array.isArray(child) && child.type === type;
|
|
7166
|
+
}
|
|
7167
|
+
function isInline(child) {
|
|
7168
|
+
if (typeof child === "string" || typeof child === "number")
|
|
7169
|
+
return true;
|
|
7170
|
+
return typeof child === "object" && child != null && !Array.isArray(child) && typeof child.type === "string" && INLINE_TAG_NAMES.has(child.type);
|
|
7171
|
+
}
|
|
7172
|
+
function flow(children) {
|
|
7173
|
+
const items = childList(children);
|
|
7174
|
+
if (!items.some((child) => typeof child === "object") || items.every((child) => !isInline(child)))
|
|
7175
|
+
return children;
|
|
7176
|
+
const out = [];
|
|
7177
|
+
let run = [];
|
|
7178
|
+
const flush = () => {
|
|
7179
|
+
if (run.length)
|
|
7180
|
+
out.push(run.length === 1 && typeof run[0] !== "object" ? run[0] : Text({ children: run }));
|
|
7181
|
+
run = [];
|
|
7182
|
+
};
|
|
7183
|
+
for (const child of items) {
|
|
7184
|
+
if (isInline(child))
|
|
7185
|
+
run.push(child);
|
|
7186
|
+
else {
|
|
7187
|
+
flush();
|
|
7188
|
+
out.push(child);
|
|
7189
|
+
}
|
|
7190
|
+
}
|
|
7191
|
+
flush();
|
|
7192
|
+
return out;
|
|
7193
|
+
}
|
|
7194
|
+
function block(props, extra, children, uaMargin) {
|
|
7195
|
+
return View({ ...props.id ? { id: props.id } : {}, ...uaMargin ? { uaMargin } : {}, style: { ...extra, ...canonicalizeIntrinsicStyle(props.style) }, children });
|
|
7196
|
+
}
|
|
7197
|
+
function expandHtml(type, props, key) {
|
|
7198
|
+
const children = props.children;
|
|
7199
|
+
switch (type) {
|
|
7200
|
+
case "pre":
|
|
7201
|
+
return jsx("p", { ...props, style: { fontFamily: "monospace", whiteSpace: "pre", ...canonicalizeIntrinsicStyle(props.style) } });
|
|
7202
|
+
case "blockquote":
|
|
7203
|
+
return block(props, { direction: "column" }, children, { block: 1, inline: 40 });
|
|
7204
|
+
case "meter": {
|
|
7205
|
+
const min = Number(props.min ?? 0);
|
|
7206
|
+
const max = Number(props.max ?? 1);
|
|
7207
|
+
const value = Math.min(max, Math.max(min, Number(props.value ?? 0)));
|
|
7208
|
+
return Progress({
|
|
7209
|
+
...props.id ? { id: props.id } : {},
|
|
7210
|
+
value: value - min,
|
|
7211
|
+
max: max - min,
|
|
7212
|
+
label: props.ariaLabel ?? props.title ?? "Meter",
|
|
7213
|
+
style: { width: 80, height: 16, radius: 3, background: "#e6e6e6", foreground: "#107c10", ...canonicalizeIntrinsicStyle(props.style) }
|
|
7214
|
+
});
|
|
7215
|
+
}
|
|
7216
|
+
case "fieldset": {
|
|
7217
|
+
const items = childList(children);
|
|
7218
|
+
const legend = items.find((child) => isElement(child, "legend"));
|
|
7219
|
+
const rest = items.filter((child) => child !== legend);
|
|
7220
|
+
const legendProps = legend?.props;
|
|
7221
|
+
return block(props, {
|
|
7222
|
+
direction: "column",
|
|
7223
|
+
gap: 4,
|
|
7224
|
+
position: "relative",
|
|
7225
|
+
padding: { top: legend ? 10 : 6, right: 12, bottom: 10, left: 12 },
|
|
7226
|
+
margin: { left: 2, right: 2, top: legend ? 9 : 0 },
|
|
7227
|
+
borderWidth: 1,
|
|
7228
|
+
borderColor: "#b4b4b4"
|
|
7229
|
+
}, [
|
|
7230
|
+
legend ? View({ ...legendProps.id ? { id: legendProps.id } : {}, style: {
|
|
7231
|
+
position: "absolute",
|
|
7232
|
+
top: -10,
|
|
7233
|
+
left: 8,
|
|
7234
|
+
padding: { left: 2, right: 2 },
|
|
7235
|
+
background: theme.colors.background,
|
|
7236
|
+
...canonicalizeIntrinsicStyle(legendProps.style)
|
|
7237
|
+
}, children: Text({ children: legendProps.children }) }) : null,
|
|
7238
|
+
jsx(View, { control: { role: "group", label: textOf(legend) }, style: { direction: "column", gap: 4 }, children: rest })
|
|
7239
|
+
]);
|
|
7240
|
+
}
|
|
7241
|
+
case "legend":
|
|
7242
|
+
return Text({ ...props.id ? { id: props.id } : {}, style: canonicalizeIntrinsicStyle(props.style), children });
|
|
7243
|
+
case "ul":
|
|
7244
|
+
case "ol": {
|
|
7245
|
+
const items = childList(children);
|
|
7246
|
+
let number = Number(props.start ?? 1);
|
|
7247
|
+
return block(props, { direction: "column", padding: { left: 40 } }, items.map((item, index) => {
|
|
7248
|
+
if (!isElement(item, "li"))
|
|
7249
|
+
return item;
|
|
7250
|
+
const marker = type === "ul" ? "\u2022" : `${number++}.`;
|
|
7251
|
+
const itemProps = item.props;
|
|
7252
|
+
return Row({ key: itemProps.id ?? index, align: "start", style: { width: "100%" }, children: [
|
|
7253
|
+
View({ style: { position: "absolute", left: -40, width: 34, align: "end" }, children: Text({ children: marker }) }),
|
|
7254
|
+
View({ ...itemProps.id ? { id: itemProps.id } : {}, style: { flex: 1, direction: "column", ...canonicalizeIntrinsicStyle(itemProps.style) }, children: flow(itemProps.children) })
|
|
7255
|
+
] });
|
|
7256
|
+
}), { block: 1 });
|
|
7257
|
+
}
|
|
7258
|
+
case "li":
|
|
7259
|
+
return block(props, { direction: "column" }, flow(children));
|
|
7260
|
+
case "dl":
|
|
7261
|
+
return block(props, { direction: "column" }, children, { block: 1 });
|
|
7262
|
+
case "dt":
|
|
7263
|
+
return block(props, { direction: "column" }, flow(children));
|
|
7264
|
+
case "dd":
|
|
7265
|
+
return block(props, { direction: "column", padding: { left: 40 } }, flow(children));
|
|
7266
|
+
case "details": {
|
|
7267
|
+
const id = String(props.id ?? key);
|
|
7268
|
+
const open = uncontrolled(id, props.open, false);
|
|
7269
|
+
const items = childList(children);
|
|
7270
|
+
const summary = items.find((child) => isElement(child, "summary"));
|
|
7271
|
+
const rest = items.filter((child) => child !== summary);
|
|
7272
|
+
const toggle = () => {
|
|
7273
|
+
const next = !open;
|
|
7274
|
+
state.set(id, next);
|
|
7275
|
+
props.onToggle?.(next);
|
|
7276
|
+
};
|
|
7277
|
+
return block({ ...props, id }, { direction: "column" }, [
|
|
7278
|
+
Pressable({
|
|
7279
|
+
id: `${id}-summary`,
|
|
7280
|
+
control: { role: "button", label: textOf(summary) || "Details", expanded: open },
|
|
7281
|
+
onClick: toggle,
|
|
7282
|
+
style: { direction: "row", gap: 6, align: "center", radius: 0 },
|
|
7283
|
+
children: [
|
|
7284
|
+
Icon({ name: open ? "chevron-down" : "chevron-right", size: 12 }),
|
|
7285
|
+
...summary ? childList(summary.props.children).map((child) => typeof child === "string" ? Text({ children: child }) : child) : [Text({ children: "Details" })]
|
|
7286
|
+
]
|
|
7287
|
+
}),
|
|
7288
|
+
...open ? rest : []
|
|
7289
|
+
]);
|
|
7290
|
+
}
|
|
7291
|
+
case "summary":
|
|
7292
|
+
return Text({ children });
|
|
7293
|
+
case "table":
|
|
7294
|
+
return expandTable(props, key);
|
|
7295
|
+
case "thead":
|
|
7296
|
+
case "tbody":
|
|
7297
|
+
case "tfoot":
|
|
7298
|
+
case "tr":
|
|
7299
|
+
case "th":
|
|
7300
|
+
case "td":
|
|
7301
|
+
case "caption":
|
|
7302
|
+
throw new Error(`<${type}> must be inside a <table>`);
|
|
7303
|
+
}
|
|
7304
|
+
throw new Error(`Unknown HTML element <${type}>`);
|
|
7305
|
+
}
|
|
7306
|
+
function textOf(child) {
|
|
7307
|
+
if (child == null || typeof child === "boolean")
|
|
7308
|
+
return "";
|
|
7309
|
+
if (typeof child === "string" || typeof child === "number")
|
|
7310
|
+
return String(child);
|
|
7311
|
+
if (Array.isArray(child))
|
|
7312
|
+
return child.map(textOf).join("");
|
|
7313
|
+
return textOf(child.props?.children);
|
|
7314
|
+
}
|
|
7315
|
+
function expandTable(props, key) {
|
|
7316
|
+
const rows = [];
|
|
7317
|
+
let caption;
|
|
7318
|
+
const collect = (children, section) => {
|
|
7319
|
+
for (const child of childList(children)) {
|
|
7320
|
+
if (isElement(child, "caption"))
|
|
7321
|
+
caption = child;
|
|
7322
|
+
else if (isElement(child, "thead") || isElement(child, "tbody") || isElement(child, "tfoot"))
|
|
7323
|
+
collect(child.props.children, String(child.type));
|
|
7324
|
+
else if (isElement(child, "tr")) {
|
|
7325
|
+
const trProps = child.props;
|
|
7326
|
+
rows.push({
|
|
7327
|
+
section,
|
|
7328
|
+
style: canonicalizeIntrinsicStyle(trProps.style),
|
|
7329
|
+
cells: childList(trProps.children).filter((cell) => isElement(cell, "td") || isElement(cell, "th"))
|
|
7330
|
+
});
|
|
7331
|
+
} else
|
|
7332
|
+
throw new Error("table children must be caption, thead, tbody, tfoot or tr");
|
|
7333
|
+
}
|
|
7334
|
+
};
|
|
7335
|
+
collect(props.children, "tbody");
|
|
7336
|
+
let columns = 1;
|
|
7337
|
+
const carried = [];
|
|
7338
|
+
for (const row of rows) {
|
|
7339
|
+
let width = 0;
|
|
7340
|
+
for (const cell of row.cells)
|
|
7341
|
+
width += Number(cell.props.colSpan ?? 1);
|
|
7342
|
+
const pending = carried.filter((rowsLeft) => rowsLeft > 0).length;
|
|
7343
|
+
columns = Math.max(columns, width + pending);
|
|
7344
|
+
for (let i = 0;i < carried.length; i++)
|
|
7345
|
+
carried[i]--;
|
|
7346
|
+
for (const cell of row.cells) {
|
|
7347
|
+
const span = Number(cell.props.rowSpan ?? 1);
|
|
7348
|
+
for (let c = 0;c < Number(cell.props.colSpan ?? 1); c++)
|
|
7349
|
+
if (span > 1)
|
|
7350
|
+
carried.push(span - 1);
|
|
7351
|
+
}
|
|
7352
|
+
}
|
|
7353
|
+
const id = String(props.id ?? key);
|
|
7354
|
+
const cells = rows.flatMap((row, r) => row.cells.map((cell, c) => {
|
|
7355
|
+
const cellProps = cell.props;
|
|
7356
|
+
const header = cell.type === "th" || row.section === "thead";
|
|
7357
|
+
const { background } = row.style;
|
|
7358
|
+
const colSpan = Number(cellProps.colSpan ?? 1);
|
|
7359
|
+
const rowSpan = Number(cellProps.rowSpan ?? 1);
|
|
7360
|
+
const content = typeof cellProps.children === "object" && cellProps.children !== null && !Array.isArray(cellProps.children) && typeof cellProps.children.type !== "string" ? cellProps.children : Text({ ...header ? { weight: 700 } : {}, style: { textAlign: header ? "center" : "start" }, children: cellProps.children });
|
|
7361
|
+
return View({
|
|
7362
|
+
key: `${r}:${c}`,
|
|
7363
|
+
...cellProps.id ? { id: cellProps.id } : {},
|
|
7364
|
+
style: { padding: 1, justify: "center", ...colSpan > 1 ? { gridColumn: `span ${colSpan}` } : {}, ...rowSpan > 1 ? { gridRow: `span ${rowSpan}` } : {}, ...background ? { background } : {}, ...canonicalizeIntrinsicStyle(cellProps.style) },
|
|
7365
|
+
children: content
|
|
7366
|
+
});
|
|
7367
|
+
}));
|
|
7368
|
+
const grid = View({
|
|
7369
|
+
id,
|
|
7370
|
+
control: { role: "grid", label: textOf(caption) || "Table" },
|
|
7371
|
+
style: { display: "grid", columns: `repeat(${columns}, auto)`, gap: 2, padding: 2, justify: "start", ...canonicalizeIntrinsicStyle(props.style) },
|
|
7372
|
+
children: cells
|
|
7373
|
+
});
|
|
7374
|
+
return Column({ align: "start", children: [caption ? View({ style: { display: "grid", columns: "auto", justify: "start" }, children: [Text({ style: { textAlign: "center", width: "100%" }, children: caption.props.children }), grid] }) : grid] });
|
|
7375
|
+
}
|
|
7376
|
+
|
|
7377
|
+
// packages/core/src/reconciler.ts
|
|
7378
|
+
function luminance(color) {
|
|
7379
|
+
const hex = color.trim().replace(/^#/, "");
|
|
7380
|
+
const full = hex.length === 3 || hex.length === 4 ? [...hex.slice(0, 3)].map((c) => c + c).join("") : hex.slice(0, 6);
|
|
7381
|
+
if (!/^[0-9a-f]{6}$/i.test(full))
|
|
7382
|
+
return null;
|
|
7383
|
+
const [r, g, b] = [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16) / 255);
|
|
7384
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
7385
|
+
}
|
|
7386
|
+
function windowBorder(background, selected) {
|
|
7387
|
+
const own = luminance(background), themed = luminance(selected.colors.background);
|
|
7388
|
+
if (own === null || themed === null || own < 0.5 === themed < 0.5)
|
|
7389
|
+
return selected.colors.border;
|
|
7390
|
+
return own < 0.5 ? "#ffffff1f" : "#0000001f";
|
|
7391
|
+
}
|
|
5920
7392
|
var kinds = new Set(["window", "titlebar", "view", "row", "column", "text", "markdown", "code", "diff", "button", "image", "svg", "scroll", "input", "textarea", "pressable", "slider", "splitter"]);
|
|
5921
7393
|
var interactiveKinds = new Set(["button", "input", "textarea", "pressable", "slider", "splitter"]);
|
|
5922
7394
|
var svgIntrinsicElements = new Set(["path", "circle", "ellipse", "g", "line", "polygon", "polyline", "rect"]);
|
|
7395
|
+
var UA_HEADING_MARGIN = { h1: 0.67, h2: 0.83, h3: 1, h4: 1.33, h5: 1.67, h6: 2.33 };
|
|
5923
7396
|
var headingPreset = {
|
|
5924
7397
|
h1: { size: 32, weight: 700 },
|
|
5925
7398
|
h2: { size: 24, weight: 700 },
|
|
@@ -5943,14 +7416,140 @@ function textContent(value) {
|
|
|
5943
7416
|
throw new Error("Text/Button children must be strings or numbers.");
|
|
5944
7417
|
return String(value);
|
|
5945
7418
|
}
|
|
7419
|
+
var INHERITED_FONT = ["fontFamily", "fontStyle", "letterSpacing", "wordSpacing", "fontVariantNumeric", "fontFeatureSettings", "fontSize", "fontWeight", "lineHeight", "foreground", "textAlign", "textTransform", "whiteSpace"];
|
|
7420
|
+
var INHERITING_TEXT = new Set(["text", "markdown"]);
|
|
7421
|
+
var TEXT_KINDS = new Set(["text", "button", "input", "textarea", "markdown", "code", "diff"]);
|
|
7422
|
+
var DIV_SHORTHANDS = ["gap", "padding", "flex", "align", "justify"];
|
|
7423
|
+
var COPIED_PROPS = [
|
|
7424
|
+
"value",
|
|
7425
|
+
"placeholder",
|
|
7426
|
+
"inputType",
|
|
7427
|
+
"scrollSpeed",
|
|
7428
|
+
"scrollOrientation",
|
|
7429
|
+
"virtualList",
|
|
7430
|
+
"disabled",
|
|
7431
|
+
"modal",
|
|
7432
|
+
"portal",
|
|
7433
|
+
"dismissOnOutside",
|
|
7434
|
+
"focusable",
|
|
7435
|
+
"dragRegion",
|
|
7436
|
+
"draggable",
|
|
7437
|
+
"dropTarget",
|
|
7438
|
+
"windowAction"
|
|
7439
|
+
];
|
|
7440
|
+
var memoStores = new WeakMap;
|
|
7441
|
+
function invalidateMemos(renderScope, id) {
|
|
7442
|
+
const store = memoStores.get(renderScope);
|
|
7443
|
+
if (!store)
|
|
7444
|
+
return;
|
|
7445
|
+
for (const [path, entry] of store) {
|
|
7446
|
+
entry.idSet ??= new Set(entry.ids);
|
|
7447
|
+
if (entry.idSet.has(id))
|
|
7448
|
+
store.delete(path);
|
|
7449
|
+
}
|
|
7450
|
+
}
|
|
5946
7451
|
function compileTree(element, debug = false, renderer = "auto", componentAdapters = [], renderScope, visible = true) {
|
|
5947
7452
|
const handlers = new Map;
|
|
5948
7453
|
const ids = new Set;
|
|
7454
|
+
const idLog = [];
|
|
5949
7455
|
const nodes = new Map;
|
|
5950
7456
|
const labelAssociations = new Map;
|
|
5951
7457
|
const labelableTargets = new Map;
|
|
5952
7458
|
let windowOptions;
|
|
5953
7459
|
let selectedTheme = lightTheme;
|
|
7460
|
+
let inheritedFont = {};
|
|
7461
|
+
let currentForm;
|
|
7462
|
+
const media = new Map;
|
|
7463
|
+
let memoStore;
|
|
7464
|
+
if (renderScope) {
|
|
7465
|
+
memoStore = memoStores.get(renderScope);
|
|
7466
|
+
if (!memoStore)
|
|
7467
|
+
memoStores.set(renderScope, memoStore = new Map);
|
|
7468
|
+
}
|
|
7469
|
+
const memoSeen = new Set;
|
|
7470
|
+
function claimedSince(mark) {
|
|
7471
|
+
const own = idLog.slice(mark).filter((id) => ids.has(id));
|
|
7472
|
+
const pick = (map) => {
|
|
7473
|
+
const out = [];
|
|
7474
|
+
for (const id of own) {
|
|
7475
|
+
const value = map.get(id);
|
|
7476
|
+
if (value !== undefined)
|
|
7477
|
+
out.push([id, value]);
|
|
7478
|
+
}
|
|
7479
|
+
return out;
|
|
7480
|
+
};
|
|
7481
|
+
return { ids: own, nodes: pick(nodes), handlers: pick(handlers), media: pick(media) };
|
|
7482
|
+
}
|
|
7483
|
+
function added(set, skip) {
|
|
7484
|
+
const out = [];
|
|
7485
|
+
let index = 0;
|
|
7486
|
+
for (const value of set)
|
|
7487
|
+
if (index++ >= skip)
|
|
7488
|
+
out.push(value);
|
|
7489
|
+
return out;
|
|
7490
|
+
}
|
|
7491
|
+
function visitMemo(store, info, props, path, group) {
|
|
7492
|
+
memoSeen.add(path);
|
|
7493
|
+
const previous = store.get(path);
|
|
7494
|
+
if (previous && previous.render === info.render && previous.group === group && previous.theme === selectedTheme && previous.form === currentForm && sameValue(previous.font, inheritedFont) && info.equal(previous.props, props)) {
|
|
7495
|
+
for (const id of previous.ids) {
|
|
7496
|
+
if (ids.has(id))
|
|
7497
|
+
throw new Error(`Duplicate node id: ${id}`);
|
|
7498
|
+
ids.add(id);
|
|
7499
|
+
idLog.push(id);
|
|
7500
|
+
}
|
|
7501
|
+
for (const [id, node] of previous.nodes)
|
|
7502
|
+
nodes.set(id, node);
|
|
7503
|
+
for (const [id, handler] of previous.handlers)
|
|
7504
|
+
handlers.set(id, handler);
|
|
7505
|
+
for (const [id, request] of previous.media)
|
|
7506
|
+
media.set(id, request);
|
|
7507
|
+
for (const key of previous.nested)
|
|
7508
|
+
memoSeen.add(key);
|
|
7509
|
+
previous.props = props;
|
|
7510
|
+
return previous.result;
|
|
7511
|
+
}
|
|
7512
|
+
const seenBefore = memoSeen.size;
|
|
7513
|
+
const before = { log: idLog.length, labels: labelAssociations.size, labelable: labelableTargets.size, window: windowOptions };
|
|
7514
|
+
const font = inheritedFont;
|
|
7515
|
+
const theme2 = selectedTheme;
|
|
7516
|
+
const form = currentForm;
|
|
7517
|
+
const result = visit(info.render(props), path, group);
|
|
7518
|
+
const selfContained = labelAssociations.size === before.labels && labelableTargets.size === before.labelable && windowOptions === before.window;
|
|
7519
|
+
if (selfContained) {
|
|
7520
|
+
store.set(path, {
|
|
7521
|
+
render: info.render,
|
|
7522
|
+
props,
|
|
7523
|
+
group,
|
|
7524
|
+
theme: theme2,
|
|
7525
|
+
font,
|
|
7526
|
+
form,
|
|
7527
|
+
result,
|
|
7528
|
+
...claimedSince(before.log),
|
|
7529
|
+
nested: added(memoSeen, seenBefore)
|
|
7530
|
+
});
|
|
7531
|
+
} else
|
|
7532
|
+
store.delete(path);
|
|
7533
|
+
return result;
|
|
7534
|
+
}
|
|
7535
|
+
function inlineContext(textId, base) {
|
|
7536
|
+
let runs = 0;
|
|
7537
|
+
return {
|
|
7538
|
+
base,
|
|
7539
|
+
linkColor: resolveStyleString("foreground", theme.colors.primary, selectedTheme),
|
|
7540
|
+
resolve: (style) => resolveThemeStyle(style, selectedTheme),
|
|
7541
|
+
register(id, onClick) {
|
|
7542
|
+
const runId = id ?? `${textId}/run:${runs++}`;
|
|
7543
|
+
if (ids.has(runId))
|
|
7544
|
+
throw new Error(`Duplicate node id: ${runId}`);
|
|
7545
|
+
ids.add(runId);
|
|
7546
|
+
idLog.push(runId);
|
|
7547
|
+
handlers.set(runId, { onClick });
|
|
7548
|
+
return runId;
|
|
7549
|
+
},
|
|
7550
|
+
openExternal
|
|
7551
|
+
};
|
|
7552
|
+
}
|
|
5954
7553
|
function visit(child, path, group, adapterNative = false) {
|
|
5955
7554
|
if (child == null || typeof child === "boolean")
|
|
5956
7555
|
return [];
|
|
@@ -5963,9 +7562,9 @@ function compileTree(element, debug = false, renderer = "auto", componentAdapter
|
|
|
5963
7562
|
if (ids.has(path))
|
|
5964
7563
|
throw new Error(`Duplicate node id: ${path}`);
|
|
5965
7564
|
ids.add(path);
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
return
|
|
7565
|
+
idLog.push(path);
|
|
7566
|
+
ids.delete(path);
|
|
7567
|
+
return visit(Text({ id: path, children: String(child) }), path, group);
|
|
5969
7568
|
}
|
|
5970
7569
|
if (child.type === Fragment || child.type === "fragment")
|
|
5971
7570
|
return visit(child.props.children, path, group);
|
|
@@ -5980,38 +7579,143 @@ function compileTree(element, debug = false, renderer = "auto", componentAdapter
|
|
|
5980
7579
|
return visit(adapted, path, group, adaptedIsNative);
|
|
5981
7580
|
}
|
|
5982
7581
|
}
|
|
5983
|
-
if (typeof child.type === "function")
|
|
7582
|
+
if (typeof child.type === "function") {
|
|
7583
|
+
const info = child.type[MEMO];
|
|
7584
|
+
if (info && memoStore)
|
|
7585
|
+
return visitMemo(memoStore, info, child.props, path, group);
|
|
5984
7586
|
return visit(child.type(child.props), path, group);
|
|
7587
|
+
}
|
|
5985
7588
|
const isNativeVNode = adapterNative || _isNativeVNode(child);
|
|
5986
7589
|
if (!isNativeVNode && child.type in headingPreset) {
|
|
5987
7590
|
const props = child.props;
|
|
5988
7591
|
const preset = headingPreset[child.type];
|
|
5989
7592
|
return visit(Text({
|
|
7593
|
+
...{ uaMargin: { block: UA_HEADING_MARGIN[child.type] } },
|
|
5990
7594
|
...props,
|
|
5991
7595
|
size: props.size ?? preset.size,
|
|
5992
7596
|
weight: props.weight ?? preset.weight,
|
|
5993
7597
|
style: canonicalizeIntrinsicStyle(props.style)
|
|
5994
7598
|
}), path, group);
|
|
5995
7599
|
}
|
|
7600
|
+
if (!isNativeVNode && typeof child.type === "string" && child.type !== "span" && child.type !== "a" && INLINE_TAG_NAMES.has(child.type) && !(child.type === "code" && child.props.code !== undefined)) {
|
|
7601
|
+
return visit(Text({ id: child.props.id, children: child }), path, group);
|
|
7602
|
+
}
|
|
5996
7603
|
if (!isNativeVNode && (child.type === "span" || child.type === "p")) {
|
|
5997
7604
|
const props = child.props;
|
|
5998
|
-
return visit(Text({ ...props, style: canonicalizeIntrinsicStyle(props.style) }), path, group);
|
|
7605
|
+
return visit(Text({ ...child.type === "p" ? { uaMargin: { block: 1 } } : {}, ...props, style: canonicalizeIntrinsicStyle(props.style) }), path, group);
|
|
5999
7606
|
}
|
|
6000
7607
|
if (!isNativeVNode && child.type === "img") {
|
|
6001
7608
|
const props = child.props;
|
|
6002
|
-
|
|
7609
|
+
const objectFit = props.style?.objectFit;
|
|
7610
|
+
const fit = props.fit ?? (objectFit === "scale-down" ? "contain" : objectFit);
|
|
7611
|
+
return visit(Image({ ...props, ...fit ? { fit } : {}, style: canonicalizeIntrinsicStyle(props.style) }), path, group);
|
|
7612
|
+
}
|
|
7613
|
+
if (!isNativeVNode && child.type === "form") {
|
|
7614
|
+
const formProps = child.props;
|
|
7615
|
+
const values = formValues(String(formProps.id ?? path));
|
|
7616
|
+
const required = new Set;
|
|
7617
|
+
const form = {
|
|
7618
|
+
values,
|
|
7619
|
+
required,
|
|
7620
|
+
submit() {
|
|
7621
|
+
for (const name of required) {
|
|
7622
|
+
const value = values.get(name);
|
|
7623
|
+
if (value === undefined || value === "" || value === false || Array.isArray(value) && value.length === 0) {
|
|
7624
|
+
formProps.onInvalid?.(name);
|
|
7625
|
+
return;
|
|
7626
|
+
}
|
|
7627
|
+
}
|
|
7628
|
+
formProps.onSubmit?.(Object.fromEntries(values));
|
|
7629
|
+
}
|
|
7630
|
+
};
|
|
7631
|
+
const previous = currentForm;
|
|
7632
|
+
currentForm = form;
|
|
7633
|
+
try {
|
|
7634
|
+
return visit(jsx("div", { id: formProps.id, style: formProps.style, control: { role: "group", label: formProps.ariaLabel ?? "Form" }, children: formProps.children }), path, group);
|
|
7635
|
+
} finally {
|
|
7636
|
+
currentForm = previous;
|
|
7637
|
+
}
|
|
7638
|
+
}
|
|
7639
|
+
if (!isNativeVNode && child.type === "audio") {
|
|
7640
|
+
const props = child.props;
|
|
7641
|
+
const id = String(props.id ?? path);
|
|
7642
|
+
media.set(id, mediaRequest(props));
|
|
7643
|
+
return visit(expandAudio(props, id), path, group);
|
|
7644
|
+
}
|
|
7645
|
+
if (!isNativeVNode && child.type === "canvas") {
|
|
7646
|
+
return visit(expandCanvas(child.props, path), path, group);
|
|
7647
|
+
}
|
|
7648
|
+
if (!isNativeVNode && typeof child.type === "string" && HTML_ELEMENTS.has(child.type)) {
|
|
7649
|
+
if (child.type === "meter" && child.props.id !== undefined)
|
|
7650
|
+
labelableTargets.set(String(child.props.id), String(child.props.id));
|
|
7651
|
+
return visit(expandHtml(child.type, child.props, path), path, group);
|
|
7652
|
+
}
|
|
7653
|
+
if (!isNativeVNode && child.type === "input" && HTML_INPUT_TYPES.has(String(child.props.type))) {
|
|
7654
|
+
return visit(expandInput(child.props, path, currentForm), path, group);
|
|
6003
7655
|
}
|
|
6004
7656
|
if (!isNativeVNode && child.type === "input") {
|
|
6005
7657
|
const props = child.props;
|
|
6006
|
-
|
|
7658
|
+
const form = currentForm;
|
|
7659
|
+
const name = props.name;
|
|
7660
|
+
if (form && name) {
|
|
7661
|
+
form.values.set(name, props.value ?? form.values.get(name) ?? props.defaultValue ?? "");
|
|
7662
|
+
if (props.required)
|
|
7663
|
+
form.required.add(name);
|
|
7664
|
+
}
|
|
7665
|
+
const { name: _name, required: _required, defaultValue, ...rest } = props;
|
|
7666
|
+
return visit(Input({
|
|
7667
|
+
...rest,
|
|
7668
|
+
...rest.value === undefined && defaultValue !== undefined ? { value: defaultValue } : {},
|
|
7669
|
+
style: canonicalizeIntrinsicStyle(props.style),
|
|
7670
|
+
onChange: (value) => {
|
|
7671
|
+
if (form && name)
|
|
7672
|
+
form.values.set(name, value);
|
|
7673
|
+
props.onChange?.(value);
|
|
7674
|
+
},
|
|
7675
|
+
onSubmit: (value) => {
|
|
7676
|
+
props.onSubmit?.(value);
|
|
7677
|
+
if (form) {
|
|
7678
|
+
if (name)
|
|
7679
|
+
form.values.set(name, value);
|
|
7680
|
+
form.submit();
|
|
7681
|
+
}
|
|
7682
|
+
}
|
|
7683
|
+
}), path, group);
|
|
6007
7684
|
}
|
|
6008
7685
|
if (!isNativeVNode && child.type === "textarea") {
|
|
6009
7686
|
const props = child.props;
|
|
6010
|
-
|
|
7687
|
+
const form = currentForm;
|
|
7688
|
+
const name = props.name;
|
|
7689
|
+
if (form && name) {
|
|
7690
|
+
form.values.set(name, props.value ?? form.values.get(name) ?? props.defaultValue ?? "");
|
|
7691
|
+
if (props.required)
|
|
7692
|
+
form.required.add(name);
|
|
7693
|
+
}
|
|
7694
|
+
const { name: _name, required: _required, defaultValue, ...rest } = props;
|
|
7695
|
+
return visit(TextArea({
|
|
7696
|
+
...rest,
|
|
7697
|
+
...rest.value === undefined && defaultValue !== undefined ? { value: defaultValue } : {},
|
|
7698
|
+
style: canonicalizeIntrinsicStyle(props.style),
|
|
7699
|
+
onChange: (value) => {
|
|
7700
|
+
if (form && name)
|
|
7701
|
+
form.values.set(name, value);
|
|
7702
|
+
props.onChange?.(value);
|
|
7703
|
+
}
|
|
7704
|
+
}), path, group);
|
|
6011
7705
|
}
|
|
6012
7706
|
if (!isNativeVNode && child.type === "button") {
|
|
6013
|
-
const props = child.props;
|
|
6014
|
-
|
|
7707
|
+
const { type, ...props } = child.props;
|
|
7708
|
+
const form = currentForm;
|
|
7709
|
+
const submits = form && (type ?? "submit") === "submit";
|
|
7710
|
+
return visit(Button({
|
|
7711
|
+
...props,
|
|
7712
|
+
style: canonicalizeIntrinsicStyle(props.style),
|
|
7713
|
+
onClick: () => {
|
|
7714
|
+
props.onClick?.();
|
|
7715
|
+
if (submits)
|
|
7716
|
+
form.submit();
|
|
7717
|
+
}
|
|
7718
|
+
}), path, group);
|
|
6015
7719
|
}
|
|
6016
7720
|
if (!isNativeVNode && child.type === "a") {
|
|
6017
7721
|
const { ariaLabel, style, ...props } = child.props;
|
|
@@ -6040,7 +7744,7 @@ function compileTree(element, debug = false, renderer = "auto", componentAdapter
|
|
|
6040
7744
|
return visit(Label({ ...props, id: String(id), style: canonicalizeIntrinsicStyle(props.style) }), path, group);
|
|
6041
7745
|
}
|
|
6042
7746
|
if (!isNativeVNode && child.type === "select") {
|
|
6043
|
-
const { children, onChange, onValueChange, ...rawProps } = child.props;
|
|
7747
|
+
const { children, onChange, onValueChange, name, required, defaultValue, ...rawProps } = child.props;
|
|
6044
7748
|
const id = String(rawProps.id ?? path);
|
|
6045
7749
|
const optionNodes = Array.isArray(children) ? children.flat(Infinity) : [children];
|
|
6046
7750
|
const options = optionNodes.filter((option) => option != null && option !== false && option !== true).map((option) => {
|
|
@@ -6057,14 +7761,26 @@ function compileTree(element, debug = false, renderer = "auto", componentAdapter
|
|
|
6057
7761
|
});
|
|
6058
7762
|
labelableTargets.set(id, `${id}-trigger`);
|
|
6059
7763
|
const props = rawProps;
|
|
7764
|
+
const form = currentForm;
|
|
7765
|
+
const key = `select:${id}`;
|
|
7766
|
+
const value = props.value ?? (form && name && form.values.has(name) ? String(form.values.get(name)) : undefined) ?? storedValue(key, defaultValue ?? options.find((option) => !option.disabled)?.value);
|
|
7767
|
+
if (form && name) {
|
|
7768
|
+
form.values.set(name, value ?? "");
|
|
7769
|
+
if (required)
|
|
7770
|
+
form.required.add(name);
|
|
7771
|
+
}
|
|
6060
7772
|
return visit(Select({
|
|
6061
7773
|
...props,
|
|
6062
7774
|
id,
|
|
6063
7775
|
options,
|
|
7776
|
+
value,
|
|
6064
7777
|
style: canonicalizeIntrinsicStyle(props.style),
|
|
6065
|
-
onValueChange: (
|
|
6066
|
-
|
|
6067
|
-
|
|
7778
|
+
onValueChange: (next) => {
|
|
7779
|
+
storeValue(key, next);
|
|
7780
|
+
if (form && name)
|
|
7781
|
+
form.values.set(name, next);
|
|
7782
|
+
onValueChange?.(next);
|
|
7783
|
+
onChange?.(next);
|
|
6068
7784
|
}
|
|
6069
7785
|
}), path, group);
|
|
6070
7786
|
}
|
|
@@ -6073,12 +7789,36 @@ function compileTree(element, debug = false, renderer = "auto", componentAdapter
|
|
|
6073
7789
|
}
|
|
6074
7790
|
if (!isNativeVNode && child.type === "progress") {
|
|
6075
7791
|
const props = child.props;
|
|
6076
|
-
|
|
7792
|
+
if (props.id !== undefined)
|
|
7793
|
+
labelableTargets.set(String(props.id), String(props.id));
|
|
7794
|
+
return visit(Progress({ ...props, style: { width: 160, height: 16, radius: 3, background: "#e6e6e6", foreground: "#0075ff", ...canonicalizeIntrinsicStyle(props.style) } }), path, group);
|
|
6077
7795
|
}
|
|
6078
7796
|
if (!isNativeVNode && child.type === "hr") {
|
|
6079
7797
|
const props = child.props;
|
|
6080
7798
|
return visit(Separator({ ...props, style: canonicalizeIntrinsicStyle(props.style) }), path, group);
|
|
6081
7799
|
}
|
|
7800
|
+
if (!isNativeVNode && child.type === "div") {
|
|
7801
|
+
const { style: divStyle, ...divProps } = child.props;
|
|
7802
|
+
const { overflow, overflowX: explicitX, overflowY = overflow, ...rest } = divStyle ?? {};
|
|
7803
|
+
const scrolls = (value) => value === "auto" || value === "scroll";
|
|
7804
|
+
const overflowX = explicitX ?? (scrolls(overflow) ? "visible" : overflow);
|
|
7805
|
+
if (scrolls(overflowX) || scrolls(overflowY)) {
|
|
7806
|
+
const shorthands = {};
|
|
7807
|
+
for (const key of DIV_SHORTHANDS)
|
|
7808
|
+
if (divProps[key] !== undefined) {
|
|
7809
|
+
shorthands[key] = divProps[key];
|
|
7810
|
+
delete divProps[key];
|
|
7811
|
+
}
|
|
7812
|
+
return visit(Scroll({
|
|
7813
|
+
...divProps,
|
|
7814
|
+
orientation: scrolls(overflowX) && scrolls(overflowY) ? "both" : scrolls(overflowX) ? "horizontal" : "vertical",
|
|
7815
|
+
style: { ...shorthands, ...canonicalizeIntrinsicStyle(rest) }
|
|
7816
|
+
}), path, group);
|
|
7817
|
+
}
|
|
7818
|
+
if (explicitX !== undefined || overflowY !== overflow) {
|
|
7819
|
+
return visit(jsx("div", { ...child.props, style: { ...rest, overflow: (overflowX ?? "visible") === "visible" && (overflowY ?? "visible") === "visible" ? "visible" : "hidden" } }, child.key), path, group);
|
|
7820
|
+
}
|
|
7821
|
+
}
|
|
6082
7822
|
const isIntrinsicDiv = child.type === "div";
|
|
6083
7823
|
const nativeType = isIntrinsicDiv ? "view" : child.type;
|
|
6084
7824
|
if (!kinds.has(nativeType))
|
|
@@ -6088,6 +7828,7 @@ function compileTree(element, debug = false, renderer = "auto", componentAdapter
|
|
|
6088
7828
|
if (ids.has(id))
|
|
6089
7829
|
throw new Error(`Duplicate node id: ${id}`);
|
|
6090
7830
|
ids.add(id);
|
|
7831
|
+
idLog.push(id);
|
|
6091
7832
|
if (nativeType === "window") {
|
|
6092
7833
|
if (windowOptions)
|
|
6093
7834
|
throw new Error("This bootstrap supports one Window per app.");
|
|
@@ -6113,7 +7854,7 @@ function compileTree(element, debug = false, renderer = "auto", componentAdapter
|
|
|
6113
7854
|
else
|
|
6114
7855
|
p.onMouseLeave?.();
|
|
6115
7856
|
} : p.onHover;
|
|
6116
|
-
handlers.set(id, { onClick: p.onClick, onMarkdownLink: p.onMarkdownLink, onDiffToggleFile: p.onToggleFile, onDiffShowMore: p.onShowMore, onDiffLineClick: p.onLineClick, onHighlight: p.onHighlight, onContextMenu: p.onContextMenu, onOutsideClick: p.onOutsideClick, onHover: hoverHandler, onChange: p.onChange, onSubmit: p.onSubmit, onPaste: p.onPaste, onValueChange: p.onValueChange, onScroll: p.onScroll, onScrollPosition: p.onScrollPosition, onVirtualListLayout: p.onVirtualListLayout, onVirtualListScrollToItem: p.onVirtualListScrollToItem, onVirtualListFocus: p.onVirtualListFocus, onEscape: p.onEscape, onKeyDown: p.onKeyDown, onBlur: p.onBlur, onCloseRequest: p.onCloseRequest, onTransitionEnd: p.onTransitionEnd });
|
|
7857
|
+
handlers.set(id, { onClick: p.onClick, onMarkdownLink: p.onMarkdownLink, onDiffToggleFile: p.onToggleFile, onDiffShowMore: p.onShowMore, onDiffLineClick: p.onLineClick, onHighlight: p.onHighlight, onContextMenu: p.onContextMenu, onOutsideClick: p.onOutsideClick, onHover: hoverHandler, onChange: p.onChange, onSubmit: p.onSubmit, onPaste: p.onPaste, onValueChange: p.onValueChange, onScroll: p.onScroll, onScrollPosition: p.onScrollPosition, onVirtualListLayout: p.onVirtualListLayout, onVirtualListScrollToItem: p.onVirtualListScrollToItem, onVirtualListFocus: p.onVirtualListFocus, onEscape: p.onEscape, onKeyDown: p.onKeyDown, onBlur: p.onBlur, onCloseRequest: p.onCloseRequest, onTransitionEnd: p.onTransitionEnd, onDragStart: p.onDragStart, onDragMove: p.onDragMove, onDragEnd: p.onDragEnd, onDragEnter: p.onDragEnter, onDragLeave: p.onDragLeave, onDrop: p.onDrop, onSize: p.onSize, onPointerMove: p.onPointerMove, onPointerLeave: p.onPointerLeave });
|
|
6117
7858
|
const control = p.control ? { ...p.control } : undefined;
|
|
6118
7859
|
const childGroup = control?.role === "radiogroup" || control?.role === "tablist" || control?.role === "navigation" || control?.role === "togglegroup" || control?.role === "tree" || control?.role === "grid" ? id : group;
|
|
6119
7860
|
const semanticRoving = control && (control.role === "radio" || control.role === "tab" || control.role === "menuitem" || control.role === "toggle" || control.role === "treeitem" || control.role === "row");
|
|
@@ -6124,8 +7865,15 @@ function compileTree(element, debug = false, renderer = "auto", componentAdapter
|
|
|
6124
7865
|
const isRichLeaf = nativeType === "markdown" || nativeType === "code" || nativeType === "diff";
|
|
6125
7866
|
if (isRichLeaf && p.children != null)
|
|
6126
7867
|
throw new Error(`${nativeType} is a native leaf and cannot have children.`);
|
|
6127
|
-
const divShorthands =
|
|
7868
|
+
const divShorthands = {};
|
|
7869
|
+
if (isIntrinsicDiv) {
|
|
7870
|
+
for (const key of DIV_SHORTHANDS)
|
|
7871
|
+
if (p[key] !== undefined)
|
|
7872
|
+
divShorthands[key] = p[key];
|
|
7873
|
+
}
|
|
6128
7874
|
const rawStyle = isIntrinsicDiv ? { ...divShorthands, ...canonicalizeIntrinsicStyle(p.style) } : { ...p.style };
|
|
7875
|
+
if (isIntrinsicDiv && rawStyle.display === "flex" && rawStyle.direction === undefined)
|
|
7876
|
+
rawStyle.direction = "row";
|
|
6129
7877
|
if (interactiveKinds.has(nativeType) && p.focusable !== false || control?.role === "otpSlot") {
|
|
6130
7878
|
rawStyle.focusVisible = {
|
|
6131
7879
|
outlineColor: theme.colors.ring,
|
|
@@ -6143,51 +7891,122 @@ function compileTree(element, debug = false, renderer = "auto", componentAdapter
|
|
|
6143
7891
|
style[key] = { ...style[key] };
|
|
6144
7892
|
}
|
|
6145
7893
|
const imageSource = nativeType === "image" && p.src !== undefined ? serializeImageSource(p.src) : undefined;
|
|
6146
|
-
const
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
7894
|
+
const parentFont = inheritedFont;
|
|
7895
|
+
const fontStyle = style;
|
|
7896
|
+
if (INHERITING_TEXT.has(nativeType)) {
|
|
7897
|
+
const initial = {
|
|
7898
|
+
fontFamily: theme.font.family,
|
|
7899
|
+
fontSize: theme.font.size,
|
|
7900
|
+
fontWeight: 400,
|
|
7901
|
+
lineHeight: theme.font.lineHeight,
|
|
7902
|
+
foreground: resolveStyleString("foreground", theme.colors.foreground, selectedTheme)
|
|
7903
|
+
};
|
|
7904
|
+
for (const key of INHERITED_FONT)
|
|
7905
|
+
if (fontStyle[key] === undefined)
|
|
7906
|
+
fontStyle[key] = parentFont[key] ?? initial[key];
|
|
7907
|
+
for (const key of INHERITED_FONT)
|
|
7908
|
+
if (fontStyle[key] === undefined)
|
|
7909
|
+
delete fontStyle[key];
|
|
7910
|
+
} else if (TEXT_KINDS.has(nativeType)) {
|
|
7911
|
+
for (const key of ["fontFamily", "fontStyle", "letterSpacing", "wordSpacing", "textTransform"]) {
|
|
7912
|
+
if (fontStyle[key] === undefined && parentFont[key] !== undefined)
|
|
7913
|
+
fontStyle[key] = parentFont[key];
|
|
7914
|
+
}
|
|
7915
|
+
fontStyle.fontFamily ??= theme.font.family;
|
|
7916
|
+
}
|
|
7917
|
+
let ownFont = parentFont;
|
|
7918
|
+
for (const key of INHERITED_FONT) {
|
|
7919
|
+
if (fontStyle[key] !== undefined && fontStyle[key] !== parentFont[key]) {
|
|
7920
|
+
if (ownFont === parentFont)
|
|
7921
|
+
ownFont = { ...parentFont };
|
|
7922
|
+
ownFont[key] = fontStyle[key];
|
|
7923
|
+
}
|
|
7924
|
+
}
|
|
7925
|
+
inheritedFont = ownFont;
|
|
7926
|
+
const uaMargin = p.uaMargin;
|
|
7927
|
+
if (uaMargin && style.margin === undefined) {
|
|
7928
|
+
const size = Number(fontStyle.fontSize ?? parentFont.fontSize ?? theme.font.size);
|
|
7929
|
+
const vertical = Math.round(uaMargin.block * size * 100) / 100;
|
|
7930
|
+
style.margin = { top: vertical, bottom: vertical, left: uaMargin.inline ?? 0, right: uaMargin.inline ?? 0 };
|
|
7931
|
+
}
|
|
7932
|
+
let children;
|
|
7933
|
+
try {
|
|
7934
|
+
children = isText || isRichLeaf ? [] : visit(p.children, `${id}/children`, childGroup);
|
|
7935
|
+
} finally {
|
|
7936
|
+
inheritedFont = parentFont;
|
|
7937
|
+
}
|
|
7938
|
+
const node = { id, kind: nativeType, style, children };
|
|
7939
|
+
const optional = node;
|
|
7940
|
+
if (nativeType === "text") {
|
|
7941
|
+
const inline = compileInline(p.children, String(style.whiteSpace ?? "normal"), inlineContext(id, style));
|
|
7942
|
+
node.text = inline.text;
|
|
7943
|
+
if (inline.runs.length)
|
|
7944
|
+
node.runs = inline.runs;
|
|
7945
|
+
} else if (isText)
|
|
7946
|
+
node.text = textContent(p.children);
|
|
7947
|
+
if (nativeType === "code")
|
|
7948
|
+
node.text = p.code;
|
|
7949
|
+
if (nativeType === "markdown" || nativeType === "diff")
|
|
7950
|
+
node.source = p.source;
|
|
7951
|
+
if (p.language !== undefined)
|
|
7952
|
+
node.language = p.language;
|
|
7953
|
+
if (p.path !== undefined)
|
|
7954
|
+
node.path = p.path;
|
|
7955
|
+
if (p.dropTarget === undefined && (p.onDrop || p.onDragEnter || p.onDragLeave))
|
|
7956
|
+
node.dropTarget = true;
|
|
7957
|
+
if (p.onSize)
|
|
7958
|
+
node.reportSize = true;
|
|
7959
|
+
if (p.onPointerMove || p.onPointerLeave)
|
|
7960
|
+
node.reportPointer = true;
|
|
7961
|
+
if (p.showLineNumbers !== undefined)
|
|
7962
|
+
node.showLineNumbers = p.showLineNumbers;
|
|
7963
|
+
if (p.wordDiff !== undefined)
|
|
7964
|
+
node.wordDiff = p.wordDiff;
|
|
7965
|
+
if (p.collapsedPaths !== undefined)
|
|
7966
|
+
node.collapsedPaths = [...p.collapsedPaths];
|
|
7967
|
+
if (p.maxLines !== undefined)
|
|
7968
|
+
node.maxLines = p.maxLines;
|
|
7969
|
+
if (p.highlight !== undefined)
|
|
7970
|
+
node.highlight = p.highlight;
|
|
7971
|
+
if (isRichLeaf)
|
|
7972
|
+
node.syntaxTheme = { ...selectedTheme.syntax, ...p.syntaxTheme };
|
|
7973
|
+
if (p.oldText !== undefined)
|
|
7974
|
+
node.oldText = p.oldText;
|
|
7975
|
+
if (p.newText !== undefined)
|
|
7976
|
+
node.newText = p.newText;
|
|
7977
|
+
if (p.svg !== undefined)
|
|
7978
|
+
node.svg = p.svg;
|
|
7979
|
+
if (control)
|
|
7980
|
+
node.control = control;
|
|
7981
|
+
if (imageSource && "path" in imageSource) {
|
|
7982
|
+
node.src = nativeAssetPath(imageSource.path);
|
|
7983
|
+
node.fit = p.fit ?? "cover";
|
|
7984
|
+
} else if (imageSource) {
|
|
7985
|
+
node.image = imageSource.image;
|
|
7986
|
+
node.fit = p.fit ?? "cover";
|
|
7987
|
+
}
|
|
7988
|
+
for (const key of COPIED_PROPS)
|
|
7989
|
+
if (p[key] !== undefined)
|
|
7990
|
+
optional[key] = p[key];
|
|
7991
|
+
if (p.submitOnEnter !== undefined)
|
|
7992
|
+
node.submitOnEnter = p.submitOnEnter === true;
|
|
7993
|
+
if (rovingGroup)
|
|
7994
|
+
node.rovingGroup = rovingGroup;
|
|
7995
|
+
if (nativeType === "window" && p.onCloseRequest !== undefined)
|
|
7996
|
+
node.closeIntercept = true;
|
|
7997
|
+
if (p.motionFrom !== undefined)
|
|
7998
|
+
node.motionFrom = { ...p.motionFrom };
|
|
6185
7999
|
if (nativeType === "input" || nativeType === "textarea")
|
|
6186
8000
|
labelableTargets.set(id, id);
|
|
6187
8001
|
nodes.set(id, node);
|
|
6188
8002
|
return [node];
|
|
6189
8003
|
}
|
|
6190
8004
|
const roots = withRenderScope(renderScope, () => visit(element, "root"));
|
|
8005
|
+
if (memoStore) {
|
|
8006
|
+
for (const path of memoStore.keys())
|
|
8007
|
+
if (!memoSeen.has(path))
|
|
8008
|
+
memoStore.delete(path);
|
|
8009
|
+
}
|
|
6191
8010
|
for (const [targetId, labelIds] of labelAssociations) {
|
|
6192
8011
|
const nativeTargetId = labelableTargets.get(targetId);
|
|
6193
8012
|
if (!nativeTargetId)
|
|
@@ -6205,10 +8024,10 @@ function compileTree(element, debug = false, renderer = "auto", componentAdapter
|
|
|
6205
8024
|
if (titleBars.length === 1) {
|
|
6206
8025
|
windowOptions.decorations = false;
|
|
6207
8026
|
roots[0].style.borderWidth ??= 1;
|
|
6208
|
-
roots[0].style.borderColor ??=
|
|
8027
|
+
roots[0].style.borderColor ??= windowBorder(String(roots[0].style.background ?? ""), selectedTheme);
|
|
6209
8028
|
roots[0].style.radius ??= theme.radius.md;
|
|
6210
8029
|
}
|
|
6211
|
-
return { document: { version: PROTOCOL_VERSION, renderer, window: windowOptions, root: roots[0] }, handlers, nodes };
|
|
8030
|
+
return { document: { version: PROTOCOL_VERSION, renderer, window: windowOptions, root: roots[0] }, handlers, nodes, media };
|
|
6212
8031
|
}
|
|
6213
8032
|
function sameValue(a, b) {
|
|
6214
8033
|
if (a === b)
|
|
@@ -6235,12 +8054,12 @@ function sameChildren(a, b) {
|
|
|
6235
8054
|
return a.children.length === b.children.length && a.children.every((child, index) => child.id === b.children[index]?.id);
|
|
6236
8055
|
}
|
|
6237
8056
|
function nodePropertiesChanged(old, node) {
|
|
6238
|
-
return old.text !== node.text || old.source !== node.source || old.language !== node.language || old.path !== node.path || old.showLineNumbers !== node.showLineNumbers || !sameValue(old.syntaxTheme, node.syntaxTheme) || old.wordDiff !== node.wordDiff || !sameValue(old.collapsedPaths, node.collapsedPaths) || old.maxLines !== node.maxLines || old.oldText !== node.oldText || old.newText !== node.newText || old.src !== node.src || old.fit !== node.fit || !sameValue(old.svg, node.svg) || old.value !== node.value || old.placeholder !== node.placeholder || old.inputType !== node.inputType || old.submitOnEnter !== node.submitOnEnter || old.scrollSpeed !== node.scrollSpeed || old.scrollOrientation !== node.scrollOrientation || !sameValue(old.virtualList, node.virtualList) || old.disabled !== node.disabled || old.modal !== node.modal || old.rovingGroup !== node.rovingGroup || old.portal !== node.portal || old.dismissOnOutside !== node.dismissOnOutside || !sameValue(old.labelledBy, node.labelledBy) || old.closeIntercept !== node.closeIntercept || old.focusable !== node.focusable || old.dragRegion !== node.dragRegion || old.windowAction !== node.windowAction || !sameValue(old.motionFrom, node.motionFrom) || !sameValue(old.highlight, node.highlight) || !sameFields(old.control ?? {}, node.control ?? {}) || !sameStyle(old.style, node.style);
|
|
8057
|
+
return old.text !== node.text || old.source !== node.source || old.language !== node.language || old.path !== node.path || old.showLineNumbers !== node.showLineNumbers || !sameValue(old.syntaxTheme, node.syntaxTheme) || old.wordDiff !== node.wordDiff || !sameValue(old.collapsedPaths, node.collapsedPaths) || old.maxLines !== node.maxLines || old.oldText !== node.oldText || old.newText !== node.newText || old.src !== node.src || old.fit !== node.fit || !sameValue(old.svg, node.svg) || old.image?.key !== node.image?.key || old.image?.kind !== node.image?.kind || old.image?.data !== node.image?.data || old.value !== node.value || old.placeholder !== node.placeholder || old.inputType !== node.inputType || old.submitOnEnter !== node.submitOnEnter || old.scrollSpeed !== node.scrollSpeed || old.scrollOrientation !== node.scrollOrientation || !sameValue(old.virtualList, node.virtualList) || old.disabled !== node.disabled || old.modal !== node.modal || old.rovingGroup !== node.rovingGroup || old.portal !== node.portal || old.dismissOnOutside !== node.dismissOnOutside || !sameValue(old.labelledBy, node.labelledBy) || old.closeIntercept !== node.closeIntercept || old.focusable !== node.focusable || old.dragRegion !== node.dragRegion || old.draggable !== node.draggable || old.dropTarget !== node.dropTarget || old.reportSize !== node.reportSize || old.reportPointer !== node.reportPointer || old.windowAction !== node.windowAction || !sameValue(old.motionFrom, node.motionFrom) || !sameValue(old.highlight, node.highlight) || !sameFields(old.control ?? {}, node.control ?? {}) || !sameStyle(old.style, node.style);
|
|
6239
8058
|
}
|
|
6240
8059
|
function flatNode(node) {
|
|
6241
8060
|
return { ...node, children: [] };
|
|
6242
8061
|
}
|
|
6243
|
-
function diffTreeMutations(previous, next) {
|
|
8062
|
+
function diffTreeMutations(previous, next, unchanged) {
|
|
6244
8063
|
if (previous.document.root.id !== next.document.root.id)
|
|
6245
8064
|
return null;
|
|
6246
8065
|
const creates = [];
|
|
@@ -6256,6 +8075,8 @@ function diffTreeMutations(previous, next) {
|
|
|
6256
8075
|
}
|
|
6257
8076
|
continue;
|
|
6258
8077
|
}
|
|
8078
|
+
if (old === node || unchanged?.(old, node))
|
|
8079
|
+
continue;
|
|
6259
8080
|
if (old.kind !== node.kind)
|
|
6260
8081
|
return null;
|
|
6261
8082
|
if (nodePropertiesChanged(old, node))
|
|
@@ -6300,9 +8121,178 @@ function DevErrorOverlay(props) {
|
|
|
6300
8121
|
});
|
|
6301
8122
|
}
|
|
6302
8123
|
|
|
8124
|
+
// packages/core/src/app-metadata.ts
|
|
8125
|
+
import { createHash as createHash3 } from "crypto";
|
|
8126
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
8127
|
+
import { homedir, tmpdir as tmpdir2 } from "os";
|
|
8128
|
+
import { join as join2, resolve as resolve2 } from "path";
|
|
8129
|
+
|
|
8130
|
+
// packages/core/src/embedded-assets.ts
|
|
8131
|
+
import { createHash as createHash2, randomUUID } from "crypto";
|
|
8132
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "fs";
|
|
8133
|
+
import { tmpdir } from "os";
|
|
8134
|
+
import { basename, dirname, isAbsolute, join, resolve } from "path";
|
|
8135
|
+
import { createRequire as createRequire2 } from "module";
|
|
8136
|
+
var materialized = new Map;
|
|
8137
|
+
function nativeAssetPath2(source) {
|
|
8138
|
+
if (/^https?:\/\//i.test(source))
|
|
8139
|
+
return source;
|
|
8140
|
+
const path = isAbsolute(source) ? source : resolve(sourceRoot(source), source);
|
|
8141
|
+
const normalized = path.replaceAll("\\", "/");
|
|
8142
|
+
if (normalized.startsWith("/$bunfs/") || /^[a-z]:\/~BUN\//i.test(normalized)) {
|
|
8143
|
+
return materializeAsset(path, basename(path));
|
|
8144
|
+
}
|
|
8145
|
+
if (typeof Bun === "undefined" && path.startsWith(import.meta.dirname + (process.platform === "win32" ? "\\" : "/"))) {
|
|
8146
|
+
const { isSea } = createRequire2(import.meta.url)("node:sea");
|
|
8147
|
+
if (isSea())
|
|
8148
|
+
return materializeAsset(path, basename(path));
|
|
8149
|
+
}
|
|
8150
|
+
return path;
|
|
8151
|
+
}
|
|
8152
|
+
function materializeAsset(source, filename, digest) {
|
|
8153
|
+
if (!filename || filename === "." || filename === ".." || basename(filename) !== filename) {
|
|
8154
|
+
throw new Error("An embedded asset filename must be a simple filename");
|
|
8155
|
+
}
|
|
8156
|
+
const key = `${source}\x00${filename}`;
|
|
8157
|
+
const cached = materialized.get(key);
|
|
8158
|
+
if (cached)
|
|
8159
|
+
return cached;
|
|
8160
|
+
if (digest) {
|
|
8161
|
+
const path = join(tmpdir(), "tarve-assets", digest.sha256, filename);
|
|
8162
|
+
if (sizeOf(path) === digest.size) {
|
|
8163
|
+
materialized.set(key, path);
|
|
8164
|
+
return path;
|
|
8165
|
+
}
|
|
8166
|
+
}
|
|
8167
|
+
const bytes = readFileSync(source);
|
|
8168
|
+
const hash = createHash2("sha256").update(bytes).digest("hex");
|
|
8169
|
+
if (digest && hash !== digest.sha256) {
|
|
8170
|
+
throw new Error(`Embedded asset ${filename} does not match its build-time digest; rebuild the executable.`);
|
|
8171
|
+
}
|
|
8172
|
+
const directory = join(tmpdir(), "tarve-assets", hash);
|
|
8173
|
+
const path = join(directory, filename);
|
|
8174
|
+
mkdirSync(directory, { recursive: true });
|
|
8175
|
+
if (!existsSync(path) || digest && sizeOf(path) !== digest.size) {
|
|
8176
|
+
const temporary = join(directory, `${filename}.${randomUUID()}.tmp`);
|
|
8177
|
+
try {
|
|
8178
|
+
writeFileSync(temporary, bytes, { flag: "wx" });
|
|
8179
|
+
try {
|
|
8180
|
+
renameSync(temporary, path);
|
|
8181
|
+
} catch (error) {
|
|
8182
|
+
if (!existsSync(path))
|
|
8183
|
+
throw error;
|
|
8184
|
+
}
|
|
8185
|
+
} finally {
|
|
8186
|
+
rmSync(temporary, { force: true });
|
|
8187
|
+
}
|
|
8188
|
+
}
|
|
8189
|
+
const actual = createHash2("sha256").update(readFileSync(path)).digest("hex");
|
|
8190
|
+
if (actual !== hash)
|
|
8191
|
+
throw new Error(`Embedded asset cache is corrupt. Remove this file and retry: ${path}`);
|
|
8192
|
+
materialized.set(key, path);
|
|
8193
|
+
return path;
|
|
8194
|
+
}
|
|
8195
|
+
function sizeOf(path) {
|
|
8196
|
+
try {
|
|
8197
|
+
return statSync(path).size;
|
|
8198
|
+
} catch {
|
|
8199
|
+
return;
|
|
8200
|
+
}
|
|
8201
|
+
}
|
|
8202
|
+
function sourceRoot(source) {
|
|
8203
|
+
if (typeof Bun !== "undefined")
|
|
8204
|
+
return dirname(Bun.main);
|
|
8205
|
+
const roots = [import.meta.dirname, process.env.TARVE_ENTRY && dirname(process.env.TARVE_ENTRY), process.argv[1] && dirname(resolve(process.argv[1]))].filter((root) => !!root);
|
|
8206
|
+
return roots.find((root) => existsSync(resolve(root, source))) ?? roots[0];
|
|
8207
|
+
}
|
|
8208
|
+
|
|
8209
|
+
// packages/core/src/png.ts
|
|
8210
|
+
var SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
8211
|
+
function isPng(bytes) {
|
|
8212
|
+
return SIGNATURE.every((value, index) => bytes[index] === value);
|
|
8213
|
+
}
|
|
8214
|
+
function pngSize(bytes) {
|
|
8215
|
+
if (!isPng(bytes) || bytes.length < 24)
|
|
8216
|
+
return;
|
|
8217
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
8218
|
+
return { width: view.getUint32(16), height: view.getUint32(20) };
|
|
8219
|
+
}
|
|
8220
|
+
var CRC_TABLE = new Uint32Array(256).map((_, n) => {
|
|
8221
|
+
let c = n;
|
|
8222
|
+
for (let k = 0;k < 8; k++)
|
|
8223
|
+
c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
8224
|
+
return c >>> 0;
|
|
8225
|
+
});
|
|
8226
|
+
function encodeIco(entries) {
|
|
8227
|
+
const header = Buffer.alloc(6 + entries.length * 16);
|
|
8228
|
+
header.writeUInt16LE(0, 0);
|
|
8229
|
+
header.writeUInt16LE(1, 2);
|
|
8230
|
+
header.writeUInt16LE(entries.length, 4);
|
|
8231
|
+
let offset = header.length;
|
|
8232
|
+
entries.forEach(({ size, png }, index) => {
|
|
8233
|
+
const at = 6 + index * 16;
|
|
8234
|
+
header[at] = size >= 256 ? 0 : size;
|
|
8235
|
+
header[at + 1] = size >= 256 ? 0 : size;
|
|
8236
|
+
header.writeUInt16LE(1, at + 4);
|
|
8237
|
+
header.writeUInt16LE(32, at + 6);
|
|
8238
|
+
header.writeUInt32LE(png.length, at + 8);
|
|
8239
|
+
header.writeUInt32LE(offset, at + 12);
|
|
8240
|
+
offset += png.length;
|
|
8241
|
+
});
|
|
8242
|
+
return new Uint8Array(Buffer.concat([header, ...entries.map((entry) => Buffer.from(entry.png))]));
|
|
8243
|
+
}
|
|
8244
|
+
function isIco(bytes) {
|
|
8245
|
+
return bytes.length >= 6 && bytes[0] === 0 && bytes[1] === 0 && bytes[2] === 1 && bytes[3] === 0;
|
|
8246
|
+
}
|
|
8247
|
+
|
|
8248
|
+
// packages/core/src/app-metadata.ts
|
|
8249
|
+
var cached;
|
|
8250
|
+
function runtimeAppMetadata() {
|
|
8251
|
+
if (cached)
|
|
8252
|
+
return cached;
|
|
8253
|
+
const raw = typeof process === "undefined" ? undefined : process.env.TARVE_APP_METADATA;
|
|
8254
|
+
try {
|
|
8255
|
+
cached = raw ? JSON.parse(raw) : {};
|
|
8256
|
+
} catch {
|
|
8257
|
+
cached = {};
|
|
8258
|
+
}
|
|
8259
|
+
return cached;
|
|
8260
|
+
}
|
|
8261
|
+
function iconBytes(icon) {
|
|
8262
|
+
if (icon.startsWith("data:")) {
|
|
8263
|
+
const comma = icon.indexOf(",");
|
|
8264
|
+
if (comma < 0)
|
|
8265
|
+
throw new TypeError("Invalid icon data URL");
|
|
8266
|
+
return new Uint8Array(Buffer.from(icon.slice(comma + 1), icon.slice(0, comma).endsWith(";base64") ? "base64" : "utf8"));
|
|
8267
|
+
}
|
|
8268
|
+
return new Uint8Array(readFileSync2(nativeAssetPath2(icon)));
|
|
8269
|
+
}
|
|
8270
|
+
function iconFileForShell(icon) {
|
|
8271
|
+
if (!icon.startsWith("data:") && icon.toLowerCase().endsWith(".ico"))
|
|
8272
|
+
return resolve2(nativeAssetPath2(icon));
|
|
8273
|
+
const bytes = iconBytes(icon);
|
|
8274
|
+
if (isIco(bytes))
|
|
8275
|
+
return writeCached(bytes);
|
|
8276
|
+
const size = pngSize(bytes);
|
|
8277
|
+
if (!size)
|
|
8278
|
+
return;
|
|
8279
|
+
return writeCached(encodeIco([{ size: Math.min(256, Math.max(size.width, size.height)), png: bytes }]));
|
|
8280
|
+
}
|
|
8281
|
+
function writeCached(ico) {
|
|
8282
|
+
const base = process.env.LOCALAPPDATA ?? (homedir() ? join2(homedir(), ".cache") : tmpdir2());
|
|
8283
|
+
const directory = join2(base, "tarve", "icons");
|
|
8284
|
+
const path = join2(directory, createHash3("sha256").update(ico).digest("hex").slice(0, 32) + ".ico");
|
|
8285
|
+
if (!existsSync2(path)) {
|
|
8286
|
+
mkdirSync2(directory, { recursive: true });
|
|
8287
|
+
writeFileSync2(path, ico);
|
|
8288
|
+
}
|
|
8289
|
+
return path;
|
|
8290
|
+
}
|
|
8291
|
+
|
|
6303
8292
|
// packages/core/src/app.ts
|
|
6304
8293
|
var DEV_OVERLAY_SOURCES = new Set(["render", "event-handler", "listener", "hotkey"]);
|
|
6305
8294
|
var DEV_APP_KEY = Symbol.for("tarve.devApp");
|
|
8295
|
+
var ACTIVE_APP_KEY = Symbol.for("tarve.activeApp");
|
|
6306
8296
|
function envFlag(name) {
|
|
6307
8297
|
return typeof process !== "undefined" && process.env?.[name] === "1";
|
|
6308
8298
|
}
|
|
@@ -6327,23 +8317,37 @@ function validateFileDialogOptions(options) {
|
|
|
6327
8317
|
throw new TypeError("Invalid file dialog extension");
|
|
6328
8318
|
}
|
|
6329
8319
|
}
|
|
8320
|
+
var shadowSources = new WeakMap;
|
|
8321
|
+
var shadowEdited = false;
|
|
6330
8322
|
function nativeShadow(tree, previous) {
|
|
6331
|
-
const document = structuredClone(tree.document);
|
|
6332
8323
|
const nodes = new Map;
|
|
6333
|
-
const
|
|
8324
|
+
const reuse = !shadowEdited;
|
|
8325
|
+
shadowEdited = false;
|
|
8326
|
+
const keep = (node) => {
|
|
8327
|
+
nodes.set(node.id, node);
|
|
8328
|
+
for (const child of node.children)
|
|
8329
|
+
keep(child);
|
|
8330
|
+
};
|
|
8331
|
+
const copy = (source) => {
|
|
8332
|
+
const kept = previous?.nodes.get(source.id);
|
|
8333
|
+
if (reuse && kept && shadowSources.get(kept) === source) {
|
|
8334
|
+
keep(kept);
|
|
8335
|
+
return kept;
|
|
8336
|
+
}
|
|
8337
|
+
const node = { ...source, children: source.children.map(copy) };
|
|
8338
|
+
shadowSources.set(node, source);
|
|
6334
8339
|
const old = previous?.nodes.get(node.id);
|
|
6335
8340
|
if ((node.kind === "input" || node.kind === "textarea") && node.value === undefined && old?.kind === node.kind) {
|
|
6336
8341
|
node.value = old.value;
|
|
6337
8342
|
}
|
|
6338
8343
|
nodes.set(node.id, node);
|
|
6339
|
-
|
|
6340
|
-
index(child);
|
|
8344
|
+
return node;
|
|
6341
8345
|
};
|
|
6342
|
-
|
|
8346
|
+
const document = { ...tree.document, root: copy(tree.document.root) };
|
|
6343
8347
|
return { document, handlers: tree.handlers, nodes };
|
|
6344
8348
|
}
|
|
6345
8349
|
function reconciliationCommand(previous, next) {
|
|
6346
|
-
const mutations = diffTreeMutations(previous, next);
|
|
8350
|
+
const mutations = diffTreeMutations(previous, next, (old, node) => shadowSources.get(old) === node);
|
|
6347
8351
|
if (mutations === null)
|
|
6348
8352
|
return { type: "update", root: next.document.root };
|
|
6349
8353
|
if (mutations.length === 0)
|
|
@@ -6363,9 +8367,24 @@ function createApp(view, options = {}) {
|
|
|
6363
8367
|
let overlayCompiled = false;
|
|
6364
8368
|
const overlayScope = {};
|
|
6365
8369
|
let appWindow;
|
|
8370
|
+
let identityDocument;
|
|
8371
|
+
const appIcon = () => options.icon ?? runtimeAppMetadata().icon;
|
|
8372
|
+
function appIdentityDocument() {
|
|
8373
|
+
if (identityDocument)
|
|
8374
|
+
return identityDocument;
|
|
8375
|
+
const metadata = runtimeAppMetadata();
|
|
8376
|
+
const icon = appIcon();
|
|
8377
|
+
const identity = options.appIdentity ?? (metadata.appId ? { id: metadata.appId, name: metadata.name ?? metadata.appId, ...icon ? { icon } : {} } : undefined);
|
|
8378
|
+
const shellIcon = identity?.icon ? iconFileForShell(identity.icon) : undefined;
|
|
8379
|
+
identityDocument = {
|
|
8380
|
+
...icon ? { windowIcon: Buffer.from(iconBytes(icon)).toString("base64") } : {},
|
|
8381
|
+
...identity ? { appIdentity: { id: identity.id, name: identity.name, ...shellIcon ? { icon: shellIcon } : {} } } : {}
|
|
8382
|
+
};
|
|
8383
|
+
return identityDocument;
|
|
8384
|
+
}
|
|
6366
8385
|
function compileView() {
|
|
6367
8386
|
const scope = renderScope;
|
|
6368
|
-
const renderer = options.renderer ?? "auto";
|
|
8387
|
+
const renderer = options.renderer ?? (options.headless ? "cpu" : "auto");
|
|
6369
8388
|
const shown = devError;
|
|
6370
8389
|
const shownWindow = appWindow;
|
|
6371
8390
|
overlayCompiled = false;
|
|
@@ -6374,6 +8393,8 @@ function createApp(view, options = {}) {
|
|
|
6374
8393
|
const overlay = withRenderScope(overlayScope, () => compileTree(DevErrorOverlay({ event: shown, onDismiss: dismissDevError, decorations: shownWindow.decorations }), options.debug, renderer, undefined, overlayScope, !options.headless));
|
|
6375
8394
|
overlayCompiled = true;
|
|
6376
8395
|
overlay.document.window = shownWindow;
|
|
8396
|
+
if (options.closeBehavior === "hide")
|
|
8397
|
+
overlay.document.root.closeIntercept = true;
|
|
6377
8398
|
return overlay;
|
|
6378
8399
|
} catch (overlayError) {
|
|
6379
8400
|
devOverlayBroken = true;
|
|
@@ -6382,8 +8403,16 @@ function createApp(view, options = {}) {
|
|
|
6382
8403
|
} catch {}
|
|
6383
8404
|
}
|
|
6384
8405
|
}
|
|
8406
|
+
globalThis[ACTIVE_APP_KEY] = app;
|
|
6385
8407
|
const tree = withRenderScope(scope, () => compileTree(currentView(), options.debug, renderer, options.componentAdapters, scope, !options.headless));
|
|
6386
8408
|
appWindow = tree.document.window;
|
|
8409
|
+
if (options.closeBehavior === "hide")
|
|
8410
|
+
tree.document.root.closeIntercept = true;
|
|
8411
|
+
Object.assign(tree.document, appIdentityDocument());
|
|
8412
|
+
if (options.msaa !== undefined)
|
|
8413
|
+
tree.document.msaa = options.msaa;
|
|
8414
|
+
if (options.memoryTrimDelay !== undefined)
|
|
8415
|
+
tree.document.memoryTrimDelay = options.memoryTrimDelay === false ? -1 : options.memoryTrimDelay;
|
|
6387
8416
|
return tree;
|
|
6388
8417
|
}
|
|
6389
8418
|
function dismissDevError() {
|
|
@@ -6443,6 +8472,9 @@ function createApp(view, options = {}) {
|
|
|
6443
8472
|
readySettled = true;
|
|
6444
8473
|
started = true;
|
|
6445
8474
|
resolveReady();
|
|
8475
|
+
if (options.maxFps !== undefined) {
|
|
8476
|
+
sendInternal({ type: "frameRate", maxFps: options.maxFps }, { source: "bridge", event: "frameRate" });
|
|
8477
|
+
}
|
|
6446
8478
|
if (options.frameOverlay ?? envFlag("TARVE_FRAME_OVERLAY")) {
|
|
6447
8479
|
sendInternal({ type: "frameOverlay", enabled: true }, { source: "bridge", event: "frameOverlay" });
|
|
6448
8480
|
}
|
|
@@ -6551,6 +8583,7 @@ function createApp(view, options = {}) {
|
|
|
6551
8583
|
}
|
|
6552
8584
|
committed = next;
|
|
6553
8585
|
observed = nextObserved;
|
|
8586
|
+
syncMedia();
|
|
6554
8587
|
});
|
|
6555
8588
|
}
|
|
6556
8589
|
async function flushQueuedUpdate() {
|
|
@@ -6622,7 +8655,48 @@ function createApp(view, options = {}) {
|
|
|
6622
8655
|
}
|
|
6623
8656
|
});
|
|
6624
8657
|
}
|
|
8658
|
+
const drags = new Map;
|
|
8659
|
+
function dispatchDrag(event, handlers) {
|
|
8660
|
+
let handled = false;
|
|
8661
|
+
let succeeded = true;
|
|
8662
|
+
const call = (name, id, handler, arg) => {
|
|
8663
|
+
if (!handler)
|
|
8664
|
+
return;
|
|
8665
|
+
handled = true;
|
|
8666
|
+
succeeded = invokeHandler(name, id, handler, arg) && succeeded;
|
|
8667
|
+
};
|
|
8668
|
+
const target = (id) => committed?.handlers.get(id);
|
|
8669
|
+
const source = event.id;
|
|
8670
|
+
if (event.type === "dragStart") {
|
|
8671
|
+
drags.set(source, { x: event.x, y: event.y, over: null });
|
|
8672
|
+
call("dragStart", source, handlers?.onDragStart, { x: event.x, y: event.y });
|
|
8673
|
+
return { handled, succeeded };
|
|
8674
|
+
}
|
|
8675
|
+
const state = drags.get(source) ?? { x: 0, y: 0, over: null };
|
|
8676
|
+
if (event.type === "dragMove") {
|
|
8677
|
+
drags.set(source, { x: event.x, y: event.y, over: event.over });
|
|
8678
|
+
if (state.over !== event.over) {
|
|
8679
|
+
if (state.over)
|
|
8680
|
+
call("dragLeave", state.over, target(state.over)?.onDragLeave, source);
|
|
8681
|
+
if (event.over)
|
|
8682
|
+
call("dragEnter", event.over, target(event.over)?.onDragEnter, source);
|
|
8683
|
+
}
|
|
8684
|
+
call("dragMove", source, handlers?.onDragMove, { x: event.x, y: event.y, over: event.over });
|
|
8685
|
+
return { handled, succeeded };
|
|
8686
|
+
}
|
|
8687
|
+
drags.delete(source);
|
|
8688
|
+
const dropped = event.type === "drop" ? event.target : null;
|
|
8689
|
+
const x = event.type === "drop" ? event.x : state.x;
|
|
8690
|
+
const y = event.type === "drop" ? event.y : state.y;
|
|
8691
|
+
if (state.over && state.over !== dropped)
|
|
8692
|
+
call("dragLeave", state.over, target(state.over)?.onDragLeave, source);
|
|
8693
|
+
if (dropped)
|
|
8694
|
+
call("drop", dropped, target(dropped)?.onDrop, { source, x, y });
|
|
8695
|
+
call("dragEnd", source, handlers?.onDragEnd, { target: dropped, x, y, cancelled: event.type === "dragCancel" });
|
|
8696
|
+
return { handled, succeeded };
|
|
8697
|
+
}
|
|
6625
8698
|
function dispatchNativeEvent(event) {
|
|
8699
|
+
globalThis[ACTIVE_APP_KEY] = app;
|
|
6626
8700
|
if (event.type === "ready")
|
|
6627
8701
|
settleReadySuccess();
|
|
6628
8702
|
if (event.type === "error") {
|
|
@@ -6645,7 +8719,10 @@ function createApp(view, options = {}) {
|
|
|
6645
8719
|
const targetId = committed.document.root.id;
|
|
6646
8720
|
const handler = committed.handlers.get(targetId)?.onCloseRequest;
|
|
6647
8721
|
if (!handler) {
|
|
6648
|
-
if (
|
|
8722
|
+
if (options.closeBehavior === "hide") {
|
|
8723
|
+
sendInternal({ type: "window", action: "hide" }, { source: "bridge", event: "closeRequest:hide", targetId });
|
|
8724
|
+
sendInternal({ type: "cancelCloseRequest" }, { source: "bridge", event: "cancelCloseRequest", targetId });
|
|
8725
|
+
} else if (sendInternal({ type: "close" }, { source: "bridge", event: "closeRequest:close", targetId }))
|
|
6649
8726
|
closing = true;
|
|
6650
8727
|
} else {
|
|
6651
8728
|
let defaultPrevented = false;
|
|
@@ -6670,6 +8747,49 @@ function createApp(view, options = {}) {
|
|
|
6670
8747
|
}
|
|
6671
8748
|
}
|
|
6672
8749
|
}
|
|
8750
|
+
if (!ended && (event.type === "tray" || event.type === "trayMenu" || event.type === "notificationClick")) {
|
|
8751
|
+
const run = (name, handler) => {
|
|
8752
|
+
if (!handler)
|
|
8753
|
+
return false;
|
|
8754
|
+
try {
|
|
8755
|
+
handler();
|
|
8756
|
+
return true;
|
|
8757
|
+
} catch (error) {
|
|
8758
|
+
reportError(error, { source: "event-handler", event: name });
|
|
8759
|
+
return false;
|
|
8760
|
+
}
|
|
8761
|
+
};
|
|
8762
|
+
let ran = false;
|
|
8763
|
+
if (event.type === "tray")
|
|
8764
|
+
ran = run(event.action === "click" ? "trayClick" : "trayDoubleClick", event.action === "click" ? trayOptions?.onClick : trayOptions?.onDoubleClick);
|
|
8765
|
+
else if (event.type === "trayMenu") {
|
|
8766
|
+
ran = run("trayMenu", trayItemHandlers.get(event.id));
|
|
8767
|
+
const onMenu = trayOptions?.onMenu;
|
|
8768
|
+
if (onMenu)
|
|
8769
|
+
ran = run("trayMenu", () => onMenu(event.id)) || ran;
|
|
8770
|
+
} else
|
|
8771
|
+
ran = run("notificationClick", notificationClick);
|
|
8772
|
+
if (ran)
|
|
8773
|
+
update();
|
|
8774
|
+
}
|
|
8775
|
+
if (!ended && event.type === "systemMedia" && systemMediaAction) {
|
|
8776
|
+
try {
|
|
8777
|
+
systemMediaAction(event.action, event.time);
|
|
8778
|
+
} catch (error) {
|
|
8779
|
+
reportError(error, { source: "event-handler", event: `systemMedia:${event.action}` });
|
|
8780
|
+
}
|
|
8781
|
+
}
|
|
8782
|
+
if (!ended && event.type === "media") {
|
|
8783
|
+
const handler = applyMediaEvent(event, committed?.media?.get(event.id));
|
|
8784
|
+
if (handler) {
|
|
8785
|
+
try {
|
|
8786
|
+
handler();
|
|
8787
|
+
} catch (error) {
|
|
8788
|
+
reportError(error, { source: "event-handler", event: `media:${event.event}`, targetId: event.id });
|
|
8789
|
+
}
|
|
8790
|
+
}
|
|
8791
|
+
update();
|
|
8792
|
+
}
|
|
6673
8793
|
if (!ended && event.type === "shortcut") {
|
|
6674
8794
|
const handlers = hotkeys.get(event.shortcut);
|
|
6675
8795
|
if (handlers) {
|
|
@@ -6697,11 +8817,15 @@ function createApp(view, options = {}) {
|
|
|
6697
8817
|
}
|
|
6698
8818
|
if (!ended && committed && observed && "id" in event) {
|
|
6699
8819
|
const handlers = committed.handlers.get(event.id);
|
|
8820
|
+
if (handlers)
|
|
8821
|
+
invalidateMemos(renderScope, event.id);
|
|
6700
8822
|
let optimisticEdit = false;
|
|
6701
8823
|
if (event.type === "change") {
|
|
6702
8824
|
const node = observed.nodes.get(event.id);
|
|
6703
8825
|
if (node && (node.kind === "input" || node.kind === "textarea")) {
|
|
6704
8826
|
node.value = event.value;
|
|
8827
|
+
shadowSources.delete(node);
|
|
8828
|
+
shadowEdited = true;
|
|
6705
8829
|
optimisticEdit = true;
|
|
6706
8830
|
}
|
|
6707
8831
|
}
|
|
@@ -6709,6 +8833,8 @@ function createApp(view, options = {}) {
|
|
|
6709
8833
|
const node = observed.nodes.get(event.id);
|
|
6710
8834
|
if (node?.control) {
|
|
6711
8835
|
node.control = { ...node.control, value: event.value };
|
|
8836
|
+
shadowSources.delete(node);
|
|
8837
|
+
shadowEdited = true;
|
|
6712
8838
|
optimisticEdit = true;
|
|
6713
8839
|
}
|
|
6714
8840
|
}
|
|
@@ -6783,14 +8909,31 @@ function createApp(view, options = {}) {
|
|
|
6783
8909
|
handled = true;
|
|
6784
8910
|
succeeded = invokeHandler("virtualListLayout", event.id, handlers.onVirtualListLayout, event.items) && succeeded;
|
|
6785
8911
|
}
|
|
8912
|
+
if (event.type === "size" && handlers?.onSize) {
|
|
8913
|
+
handled = true;
|
|
8914
|
+
succeeded = invokeHandler("size", event.id, handlers.onSize, { width: event.width, height: event.height }) && succeeded;
|
|
8915
|
+
}
|
|
8916
|
+
if (event.type === "pointerMove" && handlers?.onPointerMove) {
|
|
8917
|
+
handled = true;
|
|
8918
|
+
succeeded = invokeHandler("pointerMove", event.id, handlers.onPointerMove, { x: event.x, y: event.y }) && succeeded;
|
|
8919
|
+
}
|
|
8920
|
+
if (event.type === "pointerLeave" && handlers?.onPointerLeave) {
|
|
8921
|
+
handled = true;
|
|
8922
|
+
succeeded = invokeHandler("pointerLeave", event.id, handlers.onPointerLeave) && succeeded;
|
|
8923
|
+
}
|
|
6786
8924
|
if (event.type === "virtualListScrollToItem" && handlers?.onVirtualListScrollToItem) {
|
|
6787
8925
|
handled = true;
|
|
6788
|
-
succeeded = invokeHandler("virtualListScrollToItem", event.id, handlers.onVirtualListScrollToItem, event.index, event.offset) && succeeded;
|
|
8926
|
+
succeeded = invokeHandler("virtualListScrollToItem", event.id, handlers.onVirtualListScrollToItem, event.index, event.offset, event.smooth === true) && succeeded;
|
|
6789
8927
|
}
|
|
6790
8928
|
if (event.type === "virtualListFocus" && handlers?.onVirtualListFocus) {
|
|
6791
8929
|
handled = true;
|
|
6792
8930
|
succeeded = invokeHandler("virtualListFocus", event.id, handlers.onVirtualListFocus, event.key) && succeeded;
|
|
6793
8931
|
}
|
|
8932
|
+
if (event.type === "dragStart" || event.type === "dragMove" || event.type === "drop" || event.type === "dragCancel") {
|
|
8933
|
+
const result = dispatchDrag(event, handlers);
|
|
8934
|
+
handled = result.handled;
|
|
8935
|
+
succeeded = result.succeeded && succeeded;
|
|
8936
|
+
}
|
|
6794
8937
|
if (event.type === "hover" && handlers?.onHover) {
|
|
6795
8938
|
handled = true;
|
|
6796
8939
|
succeeded = invokeHandler("hover", event.id, handlers.onHover, event.entered);
|
|
@@ -6816,6 +8959,74 @@ function createApp(view, options = {}) {
|
|
|
6816
8959
|
update();
|
|
6817
8960
|
}
|
|
6818
8961
|
}
|
|
8962
|
+
let systemMediaAction;
|
|
8963
|
+
let trayOwner;
|
|
8964
|
+
let trayOptions;
|
|
8965
|
+
let notificationClick;
|
|
8966
|
+
let trayIconPath;
|
|
8967
|
+
let trayIconData;
|
|
8968
|
+
let trayIconSent = false;
|
|
8969
|
+
const trayItemHandlers = new Map;
|
|
8970
|
+
function applyTray() {
|
|
8971
|
+
if (!trayOptions)
|
|
8972
|
+
return;
|
|
8973
|
+
trayItemHandlers.clear();
|
|
8974
|
+
const seen = new Set;
|
|
8975
|
+
const convert = (items) => items.map((item) => {
|
|
8976
|
+
if (item.type === "separator")
|
|
8977
|
+
return { separator: true };
|
|
8978
|
+
if (!item.id)
|
|
8979
|
+
throw new TypeError("tray menu items need an id");
|
|
8980
|
+
if (item.items?.length)
|
|
8981
|
+
return { label: item.label, ...item.disabled ? { disabled: true } : {}, items: convert(item.items) };
|
|
8982
|
+
if (seen.has(item.id))
|
|
8983
|
+
throw new TypeError(`duplicate tray menu id "${item.id}"`);
|
|
8984
|
+
seen.add(item.id);
|
|
8985
|
+
if (item.onSelect)
|
|
8986
|
+
trayItemHandlers.set(item.id, item.onSelect);
|
|
8987
|
+
return { id: item.id, label: item.label, ...item.checked !== undefined ? { checked: item.checked } : {}, ...item.disabled ? { disabled: true } : {} };
|
|
8988
|
+
});
|
|
8989
|
+
const menu = convert(trayOptions.menu ?? []);
|
|
8990
|
+
const trayIcon = trayOptions.icon ?? appIcon();
|
|
8991
|
+
if (trayIcon !== trayIconPath) {
|
|
8992
|
+
trayIconData = trayIcon ? Buffer.from(iconBytes(trayIcon)).toString("base64") : undefined;
|
|
8993
|
+
trayIconPath = trayIcon;
|
|
8994
|
+
trayIconSent = false;
|
|
8995
|
+
}
|
|
8996
|
+
const iconData = trayIconSent ? undefined : trayIconData;
|
|
8997
|
+
trayIconSent = true;
|
|
8998
|
+
if (!ended)
|
|
8999
|
+
sendPublic({ type: "tray", tray: { ...iconData ? { iconData } : {}, ...trayOptions.tooltip ? { tooltip: trayOptions.tooltip } : {}, menu } });
|
|
9000
|
+
}
|
|
9001
|
+
const loadedMedia = new Map;
|
|
9002
|
+
function syncMedia() {
|
|
9003
|
+
if (ended || !committed)
|
|
9004
|
+
return;
|
|
9005
|
+
const wanted = committed.media ?? new Map;
|
|
9006
|
+
for (const id of [...loadedMedia.keys()]) {
|
|
9007
|
+
if (!wanted.has(id) || !wanted.get(id).src) {
|
|
9008
|
+
loadedMedia.delete(id);
|
|
9009
|
+
sendInternal({ type: "media", id, action: "unload" }, { source: "bridge", event: "media:unload", targetId: id });
|
|
9010
|
+
}
|
|
9011
|
+
}
|
|
9012
|
+
for (const [id, request] of wanted) {
|
|
9013
|
+
if (!request.src)
|
|
9014
|
+
continue;
|
|
9015
|
+
const previous = loadedMedia.get(id);
|
|
9016
|
+
const src = resolveMediaPath(request.src);
|
|
9017
|
+
if (!previous || resolveMediaPath(previous.src) !== src) {
|
|
9018
|
+
sendInternal({ type: "media", id, action: "load", src, loop: request.loop, muted: request.muted, volume: request.volume }, { source: "bridge", event: "media:load", targetId: id });
|
|
9019
|
+
if (request.autoPlay)
|
|
9020
|
+
sendInternal({ type: "media", id, action: "play" }, { source: "bridge", event: "media:play", targetId: id });
|
|
9021
|
+
} else if (previous.loop !== request.loop || previous.muted !== request.muted || previous.volume !== request.volume) {
|
|
9022
|
+
sendInternal({ type: "media", id, action: "set", loop: request.loop, muted: request.muted, volume: request.volume }, { source: "bridge", event: "media:set", targetId: id });
|
|
9023
|
+
}
|
|
9024
|
+
loadedMedia.set(id, request);
|
|
9025
|
+
}
|
|
9026
|
+
}
|
|
9027
|
+
function resolveMediaPath(src) {
|
|
9028
|
+
return src.startsWith("file://") ? new URL(src).pathname.replace(/^\/([A-Za-z]:)/, "$1") : src;
|
|
9029
|
+
}
|
|
6819
9030
|
function onNativeEvent(event) {
|
|
6820
9031
|
try {
|
|
6821
9032
|
dispatchNativeEvent(event);
|
|
@@ -6845,7 +9056,7 @@ function createApp(view, options = {}) {
|
|
|
6845
9056
|
if (!ended)
|
|
6846
9057
|
sendPublic({ type: "focus", id });
|
|
6847
9058
|
},
|
|
6848
|
-
scrollToItem(id, index, offset = 0) {
|
|
9059
|
+
scrollToItem(id, index, offset = 0, options = {}) {
|
|
6849
9060
|
if (!id)
|
|
6850
9061
|
throw new TypeError("scrollToItem requires a list id");
|
|
6851
9062
|
if (!Number.isInteger(index) || index < 0)
|
|
@@ -6853,7 +9064,77 @@ function createApp(view, options = {}) {
|
|
|
6853
9064
|
if (!Number.isFinite(offset))
|
|
6854
9065
|
throw new RangeError("scrollToItem offset must be finite");
|
|
6855
9066
|
if (!ended)
|
|
6856
|
-
sendPublic({ type: "scrollToItem", id, index, ...offset !== 0 ? { offset } : {} });
|
|
9067
|
+
sendPublic({ type: "scrollToItem", id, index, ...offset !== 0 ? { offset } : {}, ...options.smooth ? { smooth: true } : {} });
|
|
9068
|
+
},
|
|
9069
|
+
show() {
|
|
9070
|
+
if (!ended)
|
|
9071
|
+
sendPublic({ type: "window", action: "show" });
|
|
9072
|
+
},
|
|
9073
|
+
hide() {
|
|
9074
|
+
if (!ended)
|
|
9075
|
+
sendPublic({ type: "window", action: "hide" });
|
|
9076
|
+
},
|
|
9077
|
+
minimize() {
|
|
9078
|
+
if (!ended)
|
|
9079
|
+
sendPublic({ type: "window", action: "minimize" });
|
|
9080
|
+
},
|
|
9081
|
+
tray(initial) {
|
|
9082
|
+
const token = {};
|
|
9083
|
+
trayOwner = token;
|
|
9084
|
+
trayOptions = { ...initial };
|
|
9085
|
+
trayIconSent = false;
|
|
9086
|
+
applyTray();
|
|
9087
|
+
return {
|
|
9088
|
+
update(next) {
|
|
9089
|
+
if (trayOwner !== token)
|
|
9090
|
+
return;
|
|
9091
|
+
trayOptions = { ...trayOptions, ...next };
|
|
9092
|
+
applyTray();
|
|
9093
|
+
},
|
|
9094
|
+
remove() {
|
|
9095
|
+
if (trayOwner !== token)
|
|
9096
|
+
return;
|
|
9097
|
+
trayOwner = undefined;
|
|
9098
|
+
trayOptions = undefined;
|
|
9099
|
+
trayIconPath = undefined;
|
|
9100
|
+
trayIconData = undefined;
|
|
9101
|
+
trayItemHandlers.clear();
|
|
9102
|
+
if (!ended)
|
|
9103
|
+
sendPublic({ type: "tray", tray: null });
|
|
9104
|
+
}
|
|
9105
|
+
};
|
|
9106
|
+
},
|
|
9107
|
+
systemMedia(session) {
|
|
9108
|
+
if (session) {
|
|
9109
|
+
const { onAction, ...nativeSession } = session;
|
|
9110
|
+
systemMediaAction = onAction;
|
|
9111
|
+
if (!ended)
|
|
9112
|
+
sendPublic({ type: "systemMedia", session: nativeSession });
|
|
9113
|
+
} else {
|
|
9114
|
+
systemMediaAction = undefined;
|
|
9115
|
+
if (!ended)
|
|
9116
|
+
sendPublic({ type: "systemMedia", session: null });
|
|
9117
|
+
}
|
|
9118
|
+
},
|
|
9119
|
+
notify({ title, body = "", onClick }) {
|
|
9120
|
+
if (!title)
|
|
9121
|
+
throw new TypeError("notify requires a title");
|
|
9122
|
+
notificationClick = onClick;
|
|
9123
|
+
if (!ended)
|
|
9124
|
+
sendPublic({ type: "notify", title, body });
|
|
9125
|
+
},
|
|
9126
|
+
media(id) {
|
|
9127
|
+
const send = (command) => {
|
|
9128
|
+
if (!ended)
|
|
9129
|
+
sendPublic({ type: "media", id, ...command });
|
|
9130
|
+
};
|
|
9131
|
+
return {
|
|
9132
|
+
play: () => send({ action: "play" }),
|
|
9133
|
+
pause: () => send({ action: "pause" }),
|
|
9134
|
+
seek: (seconds) => send({ action: "seek", time: Math.max(0, seconds) }),
|
|
9135
|
+
setVolume: (volume) => send({ action: "set", volume: Math.min(1, Math.max(0, volume)) }),
|
|
9136
|
+
setMuted: (muted) => send({ action: "set", muted })
|
|
9137
|
+
};
|
|
6857
9138
|
},
|
|
6858
9139
|
registerHotkey(shortcut, handler) {
|
|
6859
9140
|
const canonical = normalizeHotkey(shortcut);
|
|
@@ -6944,6 +9225,12 @@ function createApp(view, options = {}) {
|
|
|
6944
9225
|
setFrameOverlay(enabled) {
|
|
6945
9226
|
if (!ended)
|
|
6946
9227
|
sendPublic({ type: "frameOverlay", enabled });
|
|
9228
|
+
},
|
|
9229
|
+
setMaxFps(fps) {
|
|
9230
|
+
if (fps !== null && !(Number.isFinite(fps) && fps > 0))
|
|
9231
|
+
throw new RangeError("setMaxFps expects a positive number or null");
|
|
9232
|
+
if (!ended)
|
|
9233
|
+
sendPublic({ type: "frameRate", maxFps: fps });
|
|
6947
9234
|
}
|
|
6948
9235
|
};
|
|
6949
9236
|
try {
|
|
@@ -6958,7 +9245,9 @@ function createApp(view, options = {}) {
|
|
|
6958
9245
|
return app;
|
|
6959
9246
|
}
|
|
6960
9247
|
try {
|
|
6961
|
-
|
|
9248
|
+
const fonts = options.fontFaces?.map((path) => Buffer.from(readFileSync3(nativeAssetPath2(path))).toString("base64"));
|
|
9249
|
+
bridge.start(fonts?.length ? { ...committed.document, fonts } : committed.document, onNativeEvent);
|
|
9250
|
+
syncMedia();
|
|
6962
9251
|
} catch (error) {
|
|
6963
9252
|
const startupError = reportError(error, { source: "bridge", event: "start" });
|
|
6964
9253
|
terminalError = startupError;
|
|
@@ -6970,7 +9259,7 @@ function createApp(view, options = {}) {
|
|
|
6970
9259
|
return app;
|
|
6971
9260
|
}
|
|
6972
9261
|
async function render(view, options) {
|
|
6973
|
-
const hot = process.execArgv.includes("--hot");
|
|
9262
|
+
const hot = process.execArgv.includes("--hot") || process.env.TARVE_HOT === "1";
|
|
6974
9263
|
const registry = globalThis;
|
|
6975
9264
|
const existing = registry[DEV_APP_KEY];
|
|
6976
9265
|
if (existing) {
|
|
@@ -7007,6 +9296,9 @@ function pastePayload(event) {
|
|
|
7007
9296
|
return;
|
|
7008
9297
|
}
|
|
7009
9298
|
// packages/core/src/test-renderer.ts
|
|
9299
|
+
import { spawn } from "child_process";
|
|
9300
|
+
import { Readable } from "stream";
|
|
9301
|
+
import { setTimeout as sleep } from "timers/promises";
|
|
7010
9302
|
function center(node) {
|
|
7011
9303
|
return { x: node.x + node.width / 2, y: node.y + node.height / 2 };
|
|
7012
9304
|
}
|
|
@@ -7044,7 +9336,7 @@ async function waitFor(predicate, options = {}) {
|
|
|
7044
9336
|
const suffix = lastError instanceof Error ? ` Last error: ${lastError.message}` : "";
|
|
7045
9337
|
throw new Error(`waitFor timed out after ${timeout}ms.${suffix}`);
|
|
7046
9338
|
}
|
|
7047
|
-
await
|
|
9339
|
+
await sleep(interval);
|
|
7048
9340
|
}
|
|
7049
9341
|
}
|
|
7050
9342
|
|
|
@@ -7083,6 +9375,13 @@ class Locator {
|
|
|
7083
9375
|
this.renderer.app.debug({ type: "input", action: "down" });
|
|
7084
9376
|
this.renderer.app.debug({ type: "input", action: "up" });
|
|
7085
9377
|
}
|
|
9378
|
+
async hover(offset) {
|
|
9379
|
+
const node = await this.node();
|
|
9380
|
+
const point = offset ? { x: node.x + offset.x, y: node.y + offset.y } : center(node);
|
|
9381
|
+
if (![point.x, point.y].every(Number.isFinite))
|
|
9382
|
+
throw new RangeError("hover coordinates must be finite");
|
|
9383
|
+
this.renderer.app.debug({ type: "input", action: "move", ...point });
|
|
9384
|
+
}
|
|
7086
9385
|
async fill(value) {
|
|
7087
9386
|
if (typeof value !== "string")
|
|
7088
9387
|
throw new TypeError("fill value must be a string");
|
|
@@ -7152,11 +9451,12 @@ class TestRenderer {
|
|
|
7152
9451
|
getByRole(role, options = {}) {
|
|
7153
9452
|
const exact = options.exact ?? true;
|
|
7154
9453
|
return new Locator(this, (snapshot) => snapshot.nodes.filter((node) => {
|
|
7155
|
-
|
|
9454
|
+
const nodeRole = node.control?.role ?? (node.kind === "button" ? "button" : undefined);
|
|
9455
|
+
if (nodeRole !== role)
|
|
7156
9456
|
return false;
|
|
7157
9457
|
if (options.name === undefined)
|
|
7158
9458
|
return true;
|
|
7159
|
-
return textMatches(node.control
|
|
9459
|
+
return textMatches(node.control?.label ?? node.text, options.name, exact);
|
|
7160
9460
|
}), options.name === undefined ? `role ${JSON.stringify(role)}` : `role ${JSON.stringify(role)} named ${String(options.name)}`);
|
|
7161
9461
|
}
|
|
7162
9462
|
locator(predicate, description = "custom locator") {
|
|
@@ -7186,22 +9486,24 @@ async function createTestRenderer(view, options) {
|
|
|
7186
9486
|
function launchTestProcess(options) {
|
|
7187
9487
|
if (options.command.length === 0)
|
|
7188
9488
|
throw new TypeError("launchTestProcess requires a command");
|
|
7189
|
-
const child =
|
|
9489
|
+
const child = spawn(options.command[0], options.command.slice(1), {
|
|
7190
9490
|
cwd: options.cwd,
|
|
7191
9491
|
env: {
|
|
7192
9492
|
...process.env,
|
|
7193
9493
|
...options.env,
|
|
7194
9494
|
...options.renderer ? { TARVE_RENDERER: options.renderer } : {}
|
|
7195
9495
|
},
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
9496
|
+
stdio: ["ignore", options.stdout ?? "inherit", options.stderr ?? "inherit"]
|
|
9497
|
+
});
|
|
9498
|
+
const exited = new Promise((resolve, reject) => {
|
|
9499
|
+
child.once("error", reject);
|
|
9500
|
+
child.once("close", (code, signal) => resolve(code ?? (signal ? 1 : 0)));
|
|
7199
9501
|
});
|
|
7200
9502
|
return {
|
|
7201
9503
|
pid: child.pid,
|
|
7202
|
-
exited
|
|
7203
|
-
...options.stdout === "pipe" ? { stdout: child.stdout } : {},
|
|
7204
|
-
...options.stderr === "pipe" ? { stderr: child.stderr } : {},
|
|
9504
|
+
exited,
|
|
9505
|
+
...options.stdout === "pipe" ? { stdout: Readable.toWeb(child.stdout) } : {},
|
|
9506
|
+
...options.stderr === "pipe" ? { stderr: Readable.toWeb(child.stderr) } : {},
|
|
7205
9507
|
kill(signal) {
|
|
7206
9508
|
child.kill(signal);
|
|
7207
9509
|
}
|
|
@@ -7209,6 +9511,7 @@ function launchTestProcess(options) {
|
|
|
7209
9511
|
}
|
|
7210
9512
|
// packages/core/src/visual-testing.ts
|
|
7211
9513
|
import { inflateSync } from "zlib";
|
|
9514
|
+
import { readFile } from "fs/promises";
|
|
7212
9515
|
function validateRgbaImage(image, label) {
|
|
7213
9516
|
if (!Number.isInteger(image.width) || !Number.isInteger(image.height) || image.width <= 0 || image.height <= 0) {
|
|
7214
9517
|
throw new RangeError(`${label} image dimensions must be positive integers`);
|
|
@@ -7222,7 +9525,7 @@ function validateRgbaImage(image, label) {
|
|
|
7222
9525
|
}
|
|
7223
9526
|
}
|
|
7224
9527
|
async function readPngRgba(path) {
|
|
7225
|
-
const bytes =
|
|
9528
|
+
const bytes = await readFile(path);
|
|
7226
9529
|
const signature = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
7227
9530
|
if (!signature.every((value, index) => bytes[index] === value))
|
|
7228
9531
|
throw new Error(`Not a PNG capture: ${path}`);
|
|
@@ -7368,6 +9671,8 @@ export {
|
|
|
7368
9671
|
Button,
|
|
7369
9672
|
ButtonGroup,
|
|
7370
9673
|
Calendar,
|
|
9674
|
+
CanvasGradient,
|
|
9675
|
+
CanvasRenderingContext2D,
|
|
7371
9676
|
Card,
|
|
7372
9677
|
Carousel,
|
|
7373
9678
|
Chart,
|
|
@@ -7468,10 +9773,13 @@ export {
|
|
|
7468
9773
|
launchTestProcess,
|
|
7469
9774
|
lightTheme,
|
|
7470
9775
|
loadImageSource,
|
|
9776
|
+
memo,
|
|
7471
9777
|
normalizeHotkey,
|
|
7472
9778
|
openExternal,
|
|
9779
|
+
parseCanvasFont,
|
|
7473
9780
|
readPngRgba,
|
|
7474
9781
|
render,
|
|
9782
|
+
shallowEqual,
|
|
7475
9783
|
theme,
|
|
7476
9784
|
waitFor
|
|
7477
9785
|
};
|