@silvery/examples 0.17.3 → 0.17.5
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/dist/UPNG-ShUlaTDh.mjs +5074 -0
- package/dist/__vite-browser-external-2447137e-Bopa5BFR.mjs +4 -0
- package/dist/_banner-A70_y2Vi.mjs +43 -0
- package/dist/ansi-0VXlUmNn.mjs +16397 -0
- package/dist/apng-B0gRaDVT.mjs +3 -0
- package/dist/apng-BTRDTfDW.mjs +68 -0
- package/dist/apps/aichat/index.mjs +1298 -0
- package/dist/apps/app-todo.mjs +138 -0
- package/dist/apps/async-data.mjs +203 -0
- package/dist/apps/cli-wizard.mjs +338 -0
- package/dist/apps/clipboard.mjs +197 -0
- package/dist/apps/components.mjs +863 -0
- package/dist/apps/data-explorer.mjs +482 -0
- package/dist/apps/dev-tools.mjs +396 -0
- package/dist/apps/explorer.mjs +697 -0
- package/dist/apps/gallery.mjs +765 -0
- package/dist/apps/inline-bench.mjs +115 -0
- package/dist/apps/kanban.mjs +279 -0
- package/dist/apps/layout-ref.mjs +186 -0
- package/dist/apps/outline.mjs +202 -0
- package/dist/apps/paste-demo.mjs +188 -0
- package/dist/apps/scroll.mjs +85 -0
- package/dist/apps/search-filter.mjs +286 -0
- package/dist/apps/selection.mjs +354 -0
- package/dist/apps/spatial-focus-demo.mjs +387 -0
- package/dist/apps/task-list.mjs +257 -0
- package/dist/apps/terminal-caps-demo.mjs +314 -0
- package/dist/apps/terminal.mjs +871 -0
- package/dist/apps/text-selection-demo.mjs +253 -0
- package/dist/apps/textarea.mjs +177 -0
- package/dist/apps/theme.mjs +660 -0
- package/dist/apps/transform.mjs +214 -0
- package/dist/apps/virtual-10k.mjs +421 -0
- package/dist/assets/resvgjs.darwin-arm64-BtufyGW1.node +0 -0
- package/dist/backends-Dj-11kZF.mjs +1179 -0
- package/dist/backends-U3QwStfO.mjs +3 -0
- package/dist/{cli.mjs → bin/cli.mjs} +15 -19
- package/dist/chunk-BSw8zbkd.mjs +37 -0
- package/dist/components/counter.mjs +47 -0
- package/dist/components/hello.mjs +30 -0
- package/dist/components/progress-bar.mjs +58 -0
- package/dist/components/select-list.mjs +84 -0
- package/dist/components/spinner.mjs +56 -0
- package/dist/components/text-input.mjs +61 -0
- package/dist/components/virtual-list.mjs +50 -0
- package/dist/flexily-zero-adapter-ByVzLTFP.mjs +3374 -0
- package/dist/gif-B6NGH5gs.mjs +3 -0
- package/dist/gif-CfkOF-iG.mjs +71 -0
- package/dist/gifenc-BI4ihP_T.mjs +728 -0
- package/dist/key-mapping-5oYQdAQE.mjs +3 -0
- package/dist/key-mapping-D4LR1go6.mjs +130 -0
- package/dist/layout/dashboard.mjs +1203 -0
- package/dist/layout/live-resize.mjs +302 -0
- package/dist/layout/overflow.mjs +69 -0
- package/dist/layout/text-layout.mjs +334 -0
- package/dist/node-nsrAOjH4.mjs +1083 -0
- package/dist/plugins-CT0DdV_E.mjs +3056 -0
- package/dist/resvg-js-Cnk2o49d.mjs +201 -0
- package/dist/src-9ZhfQyzD.mjs +814 -0
- package/dist/src-CUUOuRH6.mjs +5322 -0
- package/dist/src-jO3Zuzjj.mjs +23538 -0
- package/dist/usingCtx-CsEf0xO3.mjs +57 -0
- package/dist/yoga-adapter-BSQHuMV9.mjs +237 -0
- package/package.json +21 -14
- package/_banner.tsx +0 -60
- package/apps/aichat/components.tsx +0 -469
- package/apps/aichat/index.tsx +0 -220
- package/apps/aichat/script.ts +0 -460
- package/apps/aichat/state.ts +0 -325
- package/apps/aichat/types.ts +0 -19
- package/apps/app-todo.tsx +0 -201
- package/apps/async-data.tsx +0 -196
- package/apps/cli-wizard.tsx +0 -332
- package/apps/clipboard.tsx +0 -183
- package/apps/components.tsx +0 -658
- package/apps/data-explorer.tsx +0 -490
- package/apps/dev-tools.tsx +0 -395
- package/apps/explorer.tsx +0 -731
- package/apps/gallery.tsx +0 -653
- package/apps/inline-bench.tsx +0 -138
- package/apps/kanban.tsx +0 -265
- package/apps/layout-ref.tsx +0 -173
- package/apps/outline.tsx +0 -160
- package/apps/panes/index.tsx +0 -203
- package/apps/paste-demo.tsx +0 -185
- package/apps/scroll.tsx +0 -80
- package/apps/search-filter.tsx +0 -240
- package/apps/selection.tsx +0 -346
- package/apps/spatial-focus-demo.tsx +0 -372
- package/apps/task-list.tsx +0 -271
- package/apps/terminal-caps-demo.tsx +0 -317
- package/apps/terminal.tsx +0 -784
- package/apps/text-selection-demo.tsx +0 -193
- package/apps/textarea.tsx +0 -155
- package/apps/theme.tsx +0 -515
- package/apps/transform.tsx +0 -229
- package/apps/virtual-10k.tsx +0 -405
- package/apps/vterm-demo/index.tsx +0 -216
- package/components/counter.tsx +0 -49
- package/components/hello.tsx +0 -38
- package/components/progress-bar.tsx +0 -52
- package/components/select-list.tsx +0 -54
- package/components/spinner.tsx +0 -44
- package/components/text-input.tsx +0 -61
- package/components/virtual-list.tsx +0 -56
- package/dist/cli.d.mts +0 -1
- package/dist/cli.mjs.map +0 -1
- package/layout/dashboard.tsx +0 -953
- package/layout/live-resize.tsx +0 -282
- package/layout/overflow.tsx +0 -51
- package/layout/text-layout.tsx +0 -283
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { t as _usingCtx } from "../usingCtx-CsEf0xO3.mjs";
|
|
2
|
+
import { t as ExampleBanner } from "../_banner-A70_y2Vi.mjs";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Box, H1, Kbd, Muted, Small, Text, Transform, createTerm, render, useApp, useInput } from "silvery";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
//#region apps/transform.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Transform Component Demo
|
|
9
|
+
*
|
|
10
|
+
* Shows the Transform component for text post-processing. Each transform
|
|
11
|
+
* applies a string transformation to every line of rendered text output.
|
|
12
|
+
*
|
|
13
|
+
* Features:
|
|
14
|
+
* - Multiple transforms: uppercase, leetspeak, reverse, ROT13, etc.
|
|
15
|
+
* - Cycle through transforms with j/k
|
|
16
|
+
* - Shows original and transformed text side by side
|
|
17
|
+
* - Uses Transform from silvery components
|
|
18
|
+
*
|
|
19
|
+
* Run: bun vendor/silvery/examples/apps/transform.tsx
|
|
20
|
+
*/
|
|
21
|
+
const meta = {
|
|
22
|
+
name: "Transform",
|
|
23
|
+
description: "Text post-processing with the Transform component",
|
|
24
|
+
features: [
|
|
25
|
+
"Transform",
|
|
26
|
+
"transform function",
|
|
27
|
+
"side-by-side comparison"
|
|
28
|
+
]
|
|
29
|
+
};
|
|
30
|
+
const leetMap = {
|
|
31
|
+
a: "4",
|
|
32
|
+
e: "3",
|
|
33
|
+
i: "1",
|
|
34
|
+
o: "0",
|
|
35
|
+
s: "5",
|
|
36
|
+
t: "7",
|
|
37
|
+
A: "4",
|
|
38
|
+
E: "3",
|
|
39
|
+
I: "1",
|
|
40
|
+
O: "0",
|
|
41
|
+
S: "5",
|
|
42
|
+
T: "7"
|
|
43
|
+
};
|
|
44
|
+
const rot13Char = (c) => {
|
|
45
|
+
const code = c.charCodeAt(0);
|
|
46
|
+
if (code >= 65 && code <= 90) return String.fromCharCode((code - 65 + 13) % 26 + 65);
|
|
47
|
+
if (code >= 97 && code <= 122) return String.fromCharCode((code - 97 + 13) % 26 + 97);
|
|
48
|
+
return c;
|
|
49
|
+
};
|
|
50
|
+
const transforms = [
|
|
51
|
+
{
|
|
52
|
+
name: "Uppercase",
|
|
53
|
+
description: "Convert all characters to upper case",
|
|
54
|
+
fn: (s) => s.toUpperCase()
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "Lowercase",
|
|
58
|
+
description: "Convert all characters to lower case",
|
|
59
|
+
fn: (s) => s.toLowerCase()
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "Leetspeak",
|
|
63
|
+
description: "Replace letters with numbers (a=4, e=3, i=1, ...)",
|
|
64
|
+
fn: (s) => s.split("").map((c) => leetMap[c] ?? c).join("")
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "Reverse",
|
|
68
|
+
description: "Reverse each line of text",
|
|
69
|
+
fn: (s) => s.split("").reverse().join("")
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "ROT13",
|
|
73
|
+
description: "Caesar cipher — shift each letter by 13 positions",
|
|
74
|
+
fn: (s) => s.split("").map(rot13Char).join("")
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "Alternating Case",
|
|
78
|
+
description: "Alternate between upper and lower case characters",
|
|
79
|
+
fn: (s) => s.split("").map((c, i) => i % 2 === 0 ? c.toUpperCase() : c.toLowerCase()).join("")
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "Spaces to Dots",
|
|
83
|
+
description: "Replace spaces with middle dots for visibility",
|
|
84
|
+
fn: (s) => s.replace(/ /g, "·")
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
const sampleLines = [
|
|
88
|
+
"The quick brown fox jumps",
|
|
89
|
+
"over the lazy dog on a",
|
|
90
|
+
"beautiful sunny afternoon.",
|
|
91
|
+
"",
|
|
92
|
+
"Pack my box with five dozen",
|
|
93
|
+
"liquor jugs and enjoy them."
|
|
94
|
+
];
|
|
95
|
+
function TransformSelector({ current, transforms: items }) {
|
|
96
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
97
|
+
flexDirection: "column",
|
|
98
|
+
overflow: "scroll",
|
|
99
|
+
scrollTo: current,
|
|
100
|
+
height: 7,
|
|
101
|
+
children: items.map((t, index) => {
|
|
102
|
+
const isSelected = index === current;
|
|
103
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
104
|
+
paddingX: 1,
|
|
105
|
+
children: /* @__PURE__ */ jsxs(Text, {
|
|
106
|
+
color: isSelected ? "$bg" : void 0,
|
|
107
|
+
backgroundColor: isSelected ? "$primary" : void 0,
|
|
108
|
+
bold: isSelected,
|
|
109
|
+
children: [isSelected ? " > " : " ", t.name]
|
|
110
|
+
})
|
|
111
|
+
}, t.name);
|
|
112
|
+
})
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function TextPanel({ title, titleColor, children }) {
|
|
116
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
117
|
+
flexDirection: "column",
|
|
118
|
+
flexGrow: 1,
|
|
119
|
+
borderStyle: "round",
|
|
120
|
+
borderColor: "$border",
|
|
121
|
+
paddingX: 1,
|
|
122
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
123
|
+
marginBottom: 1,
|
|
124
|
+
children: /* @__PURE__ */ jsx(H1, {
|
|
125
|
+
color: titleColor,
|
|
126
|
+
children: title
|
|
127
|
+
})
|
|
128
|
+
}), children]
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function TransformDemo() {
|
|
132
|
+
const { exit } = useApp();
|
|
133
|
+
const [currentIndex, setCurrentIndex] = useState(0);
|
|
134
|
+
const current = transforms[currentIndex];
|
|
135
|
+
useInput((input, key) => {
|
|
136
|
+
if (input === "q" || key.escape) {
|
|
137
|
+
exit();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (key.upArrow || input === "k") setCurrentIndex((prev) => Math.max(0, prev - 1));
|
|
141
|
+
if (key.downArrow || input === "j") setCurrentIndex((prev) => Math.min(transforms.length - 1, prev + 1));
|
|
142
|
+
});
|
|
143
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
144
|
+
flexDirection: "column",
|
|
145
|
+
padding: 1,
|
|
146
|
+
gap: 1,
|
|
147
|
+
children: [
|
|
148
|
+
/* @__PURE__ */ jsxs(Box, {
|
|
149
|
+
flexDirection: "column",
|
|
150
|
+
borderStyle: "round",
|
|
151
|
+
borderColor: "$primary",
|
|
152
|
+
paddingX: 1,
|
|
153
|
+
children: [/* @__PURE__ */ jsxs(Box, {
|
|
154
|
+
marginBottom: 1,
|
|
155
|
+
gap: 1,
|
|
156
|
+
children: [/* @__PURE__ */ jsx(H1, { children: "Transform" }), /* @__PURE__ */ jsxs(Small, { children: [
|
|
157
|
+
"— ",
|
|
158
|
+
current.name,
|
|
159
|
+
": ",
|
|
160
|
+
current.description
|
|
161
|
+
] })]
|
|
162
|
+
}), /* @__PURE__ */ jsx(TransformSelector, {
|
|
163
|
+
current: currentIndex,
|
|
164
|
+
transforms
|
|
165
|
+
})]
|
|
166
|
+
}),
|
|
167
|
+
/* @__PURE__ */ jsxs(Box, {
|
|
168
|
+
flexDirection: "row",
|
|
169
|
+
gap: 1,
|
|
170
|
+
children: [/* @__PURE__ */ jsx(TextPanel, {
|
|
171
|
+
title: "Original",
|
|
172
|
+
titleColor: "$muted",
|
|
173
|
+
children: /* @__PURE__ */ jsx(Box, {
|
|
174
|
+
flexDirection: "column",
|
|
175
|
+
children: sampleLines.map((line, i) => /* @__PURE__ */ jsx(Text, { children: line || " " }, i))
|
|
176
|
+
})
|
|
177
|
+
}), /* @__PURE__ */ jsx(TextPanel, {
|
|
178
|
+
title: `${current.name}`,
|
|
179
|
+
titleColor: "$warning",
|
|
180
|
+
children: /* @__PURE__ */ jsx(Transform, {
|
|
181
|
+
transform: current.fn,
|
|
182
|
+
children: /* @__PURE__ */ jsx(Text, { children: sampleLines.join("\n") })
|
|
183
|
+
})
|
|
184
|
+
})]
|
|
185
|
+
}),
|
|
186
|
+
/* @__PURE__ */ jsxs(Muted, { children: [
|
|
187
|
+
" ",
|
|
188
|
+
/* @__PURE__ */ jsx(Kbd, { children: "j/k" }),
|
|
189
|
+
" select transform ",
|
|
190
|
+
/* @__PURE__ */ jsx(Kbd, { children: "Esc/q" }),
|
|
191
|
+
" quit"
|
|
192
|
+
] })
|
|
193
|
+
]
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
async function main() {
|
|
197
|
+
try {
|
|
198
|
+
var _usingCtx$1 = _usingCtx();
|
|
199
|
+
const term = _usingCtx$1.u(createTerm());
|
|
200
|
+
const { waitUntilExit } = await render(/* @__PURE__ */ jsx(ExampleBanner, {
|
|
201
|
+
meta,
|
|
202
|
+
controls: "j/k select transform Esc/q quit",
|
|
203
|
+
children: /* @__PURE__ */ jsx(TransformDemo, {})
|
|
204
|
+
}), term);
|
|
205
|
+
await waitUntilExit();
|
|
206
|
+
} catch (_) {
|
|
207
|
+
_usingCtx$1.e = _;
|
|
208
|
+
} finally {
|
|
209
|
+
_usingCtx$1.d();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (import.meta.main) await main();
|
|
213
|
+
//#endregion
|
|
214
|
+
export { TransformDemo, main, meta };
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { t as ExampleBanner } from "../_banner-A70_y2Vi.mjs";
|
|
2
|
+
import { useCallback, useMemo, useState } from "react";
|
|
3
|
+
import { Box, Divider, Kbd, ListView, Muted, Strong, Text, useBoxRect } from "silvery";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { run, useInput as useInput$1 } from "silvery/runtime";
|
|
6
|
+
//#region apps/virtual-10k.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Virtual Scroll Benchmark — 10,000 Items
|
|
9
|
+
*
|
|
10
|
+
* Demonstrates that ListView handles massive datasets with instant scrolling.
|
|
11
|
+
* Only visible items + overscan are rendered, regardless of total count.
|
|
12
|
+
*
|
|
13
|
+
* Demonstrates:
|
|
14
|
+
* - ListView with 10,000 items and variable heights
|
|
15
|
+
* - Smooth j/k navigation with position indicator
|
|
16
|
+
* - useBoxRect() for adaptive column count
|
|
17
|
+
* - Page up/down with large jumps
|
|
18
|
+
* - Visual item variety (priorities, tags, progress bars)
|
|
19
|
+
*
|
|
20
|
+
* Usage: bun run examples/apps/virtual-10k.tsx
|
|
21
|
+
*
|
|
22
|
+
* Controls:
|
|
23
|
+
* j/k or Up/Down - Navigate one item
|
|
24
|
+
* d/u - Half-page down/up
|
|
25
|
+
* g/G - Jump to first/last
|
|
26
|
+
* / - Search by number
|
|
27
|
+
* Esc/q or Ctrl+C - Quit
|
|
28
|
+
*/
|
|
29
|
+
const meta = {
|
|
30
|
+
name: "Virtual 10K",
|
|
31
|
+
description: "ListView scrolling through 10,000 items with instant navigation",
|
|
32
|
+
features: [
|
|
33
|
+
"ListView",
|
|
34
|
+
"10K items",
|
|
35
|
+
"useBoxRect()",
|
|
36
|
+
"variable estimateHeight"
|
|
37
|
+
]
|
|
38
|
+
};
|
|
39
|
+
const PRIORITIES = [
|
|
40
|
+
"P0",
|
|
41
|
+
"P1",
|
|
42
|
+
"P2",
|
|
43
|
+
"P3"
|
|
44
|
+
];
|
|
45
|
+
const STATUSES = [
|
|
46
|
+
"todo",
|
|
47
|
+
"in-progress",
|
|
48
|
+
"done",
|
|
49
|
+
"blocked"
|
|
50
|
+
];
|
|
51
|
+
const TAG_POOL = [
|
|
52
|
+
"frontend",
|
|
53
|
+
"backend",
|
|
54
|
+
"api",
|
|
55
|
+
"database",
|
|
56
|
+
"security",
|
|
57
|
+
"performance",
|
|
58
|
+
"ux",
|
|
59
|
+
"docs",
|
|
60
|
+
"testing",
|
|
61
|
+
"devops",
|
|
62
|
+
"mobile",
|
|
63
|
+
"infra"
|
|
64
|
+
];
|
|
65
|
+
const ADJECTIVES = [
|
|
66
|
+
"Implement",
|
|
67
|
+
"Fix",
|
|
68
|
+
"Refactor",
|
|
69
|
+
"Optimize",
|
|
70
|
+
"Design",
|
|
71
|
+
"Review",
|
|
72
|
+
"Update",
|
|
73
|
+
"Add",
|
|
74
|
+
"Remove",
|
|
75
|
+
"Migrate",
|
|
76
|
+
"Configure",
|
|
77
|
+
"Deploy"
|
|
78
|
+
];
|
|
79
|
+
const NOUNS = [
|
|
80
|
+
"authentication flow",
|
|
81
|
+
"database schema",
|
|
82
|
+
"API endpoint",
|
|
83
|
+
"caching layer",
|
|
84
|
+
"error handling",
|
|
85
|
+
"test suite",
|
|
86
|
+
"CI pipeline",
|
|
87
|
+
"monitoring",
|
|
88
|
+
"rate limiter",
|
|
89
|
+
"search index",
|
|
90
|
+
"notification system",
|
|
91
|
+
"user dashboard",
|
|
92
|
+
"payment processing",
|
|
93
|
+
"file upload",
|
|
94
|
+
"websocket handler",
|
|
95
|
+
"session manager"
|
|
96
|
+
];
|
|
97
|
+
function seededRandom(seed) {
|
|
98
|
+
let s = seed;
|
|
99
|
+
return () => {
|
|
100
|
+
s = s * 1664525 + 1013904223 & 2147483647;
|
|
101
|
+
return s / 2147483647;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function generateItems(count) {
|
|
105
|
+
const rng = seededRandom(42);
|
|
106
|
+
const items = [];
|
|
107
|
+
for (let i = 0; i < count; i++) {
|
|
108
|
+
const adj = ADJECTIVES[Math.floor(rng() * ADJECTIVES.length)];
|
|
109
|
+
const noun = NOUNS[Math.floor(rng() * NOUNS.length)];
|
|
110
|
+
const priority = PRIORITIES[Math.floor(rng() * PRIORITIES.length)];
|
|
111
|
+
const status = STATUSES[Math.floor(rng() * STATUSES.length)];
|
|
112
|
+
const tagCount = 1 + Math.floor(rng() * 3);
|
|
113
|
+
const tags = [];
|
|
114
|
+
for (let t = 0; t < tagCount; t++) {
|
|
115
|
+
const tag = TAG_POOL[Math.floor(rng() * TAG_POOL.length)];
|
|
116
|
+
if (!tags.includes(tag)) tags.push(tag);
|
|
117
|
+
}
|
|
118
|
+
const progress = status === "done" ? 100 : status === "todo" ? 0 : Math.floor(rng() * 90) + 5;
|
|
119
|
+
items.push({
|
|
120
|
+
id: i + 1,
|
|
121
|
+
title: `${adj} ${noun}`,
|
|
122
|
+
priority,
|
|
123
|
+
status,
|
|
124
|
+
tags,
|
|
125
|
+
progress,
|
|
126
|
+
description: `Task #${i + 1}: ${adj.toLowerCase()} the ${noun} for improved reliability.`
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return items;
|
|
130
|
+
}
|
|
131
|
+
const TOTAL_ITEMS = 1e4;
|
|
132
|
+
const ALL_ITEMS = generateItems(TOTAL_ITEMS);
|
|
133
|
+
const PRIORITY_COLORS = {
|
|
134
|
+
P0: "$error",
|
|
135
|
+
P1: "$warning",
|
|
136
|
+
P2: "$info",
|
|
137
|
+
P3: "$muted"
|
|
138
|
+
};
|
|
139
|
+
const STATUS_ICONS = {
|
|
140
|
+
todo: "○",
|
|
141
|
+
"in-progress": "◔",
|
|
142
|
+
done: "●",
|
|
143
|
+
blocked: "■"
|
|
144
|
+
};
|
|
145
|
+
const STATUS_COLORS = {
|
|
146
|
+
todo: "$muted",
|
|
147
|
+
"in-progress": "$warning",
|
|
148
|
+
done: "$success",
|
|
149
|
+
blocked: "$error"
|
|
150
|
+
};
|
|
151
|
+
function ProgressBar$1({ percent, width: barWidth }) {
|
|
152
|
+
const effectiveWidth = Math.max(5, barWidth);
|
|
153
|
+
const filled = Math.round(percent / 100 * effectiveWidth);
|
|
154
|
+
const empty = effectiveWidth - filled;
|
|
155
|
+
return /* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Text, {
|
|
156
|
+
color: "$success",
|
|
157
|
+
children: "█".repeat(filled)
|
|
158
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
159
|
+
dim: true,
|
|
160
|
+
children: "░".repeat(empty)
|
|
161
|
+
})] });
|
|
162
|
+
}
|
|
163
|
+
function ItemRow({ item, isSelected, showDetail }) {
|
|
164
|
+
const idStr = String(item.id).padStart(5, " ");
|
|
165
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
166
|
+
flexDirection: "column",
|
|
167
|
+
paddingX: 1,
|
|
168
|
+
backgroundColor: isSelected ? "$primary" : void 0,
|
|
169
|
+
children: [/* @__PURE__ */ jsxs(Box, { children: [
|
|
170
|
+
/* @__PURE__ */ jsx(Text, {
|
|
171
|
+
color: STATUS_COLORS[item.status],
|
|
172
|
+
children: STATUS_ICONS[item.status]
|
|
173
|
+
}),
|
|
174
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
175
|
+
dim: true,
|
|
176
|
+
children: [
|
|
177
|
+
" ",
|
|
178
|
+
idStr,
|
|
179
|
+
" "
|
|
180
|
+
]
|
|
181
|
+
}),
|
|
182
|
+
/* @__PURE__ */ jsx(Text, {
|
|
183
|
+
bold: true,
|
|
184
|
+
color: PRIORITY_COLORS[item.priority],
|
|
185
|
+
children: item.priority
|
|
186
|
+
}),
|
|
187
|
+
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
188
|
+
/* @__PURE__ */ jsx(Text, {
|
|
189
|
+
bold: isSelected,
|
|
190
|
+
children: item.title
|
|
191
|
+
}),
|
|
192
|
+
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
193
|
+
item.tags.map((tag) => /* @__PURE__ */ jsxs(Text, {
|
|
194
|
+
dim: true,
|
|
195
|
+
color: "$info",
|
|
196
|
+
children: [
|
|
197
|
+
" ",
|
|
198
|
+
"#",
|
|
199
|
+
tag
|
|
200
|
+
]
|
|
201
|
+
}, tag))
|
|
202
|
+
] }), showDetail && /* @__PURE__ */ jsxs(Box, {
|
|
203
|
+
paddingLeft: 8,
|
|
204
|
+
children: [
|
|
205
|
+
/* @__PURE__ */ jsx(Text, {
|
|
206
|
+
dim: true,
|
|
207
|
+
children: item.description
|
|
208
|
+
}),
|
|
209
|
+
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
210
|
+
/* @__PURE__ */ jsx(ProgressBar$1, {
|
|
211
|
+
percent: item.progress,
|
|
212
|
+
width: 10
|
|
213
|
+
}),
|
|
214
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
215
|
+
dim: true,
|
|
216
|
+
children: [
|
|
217
|
+
" ",
|
|
218
|
+
item.progress,
|
|
219
|
+
"%"
|
|
220
|
+
]
|
|
221
|
+
})
|
|
222
|
+
]
|
|
223
|
+
})]
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function ScrollIndicator({ current, total, width }) {
|
|
227
|
+
const percent = total > 0 ? Math.round((current + 1) / total * 100) : 0;
|
|
228
|
+
const barWidth = Math.max(10, Math.min(30, width - 40));
|
|
229
|
+
const filled = Math.round(percent / 100 * barWidth);
|
|
230
|
+
const empty = barWidth - filled;
|
|
231
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
232
|
+
gap: 2,
|
|
233
|
+
paddingX: 1,
|
|
234
|
+
children: [
|
|
235
|
+
/* @__PURE__ */ jsx(Strong, {
|
|
236
|
+
color: "$primary",
|
|
237
|
+
children: (current + 1).toLocaleString()
|
|
238
|
+
}),
|
|
239
|
+
/* @__PURE__ */ jsx(Text, {
|
|
240
|
+
dim: true,
|
|
241
|
+
children: "of"
|
|
242
|
+
}),
|
|
243
|
+
/* @__PURE__ */ jsx(Strong, { children: total.toLocaleString() }),
|
|
244
|
+
/* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Text, {
|
|
245
|
+
color: "$primary",
|
|
246
|
+
children: "█".repeat(filled)
|
|
247
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
248
|
+
dim: true,
|
|
249
|
+
children: "░".repeat(empty)
|
|
250
|
+
})] }),
|
|
251
|
+
/* @__PURE__ */ jsxs(Strong, {
|
|
252
|
+
color: "$primary",
|
|
253
|
+
children: [percent, "%"]
|
|
254
|
+
})
|
|
255
|
+
]
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
function StatsBar({ items }) {
|
|
259
|
+
const stats = useMemo(() => {
|
|
260
|
+
let p0 = 0, p1 = 0, p2 = 0, p3 = 0;
|
|
261
|
+
let todo = 0, inProg = 0, done = 0, blocked = 0;
|
|
262
|
+
for (const item of items) {
|
|
263
|
+
if (item.priority === "P0") p0++;
|
|
264
|
+
else if (item.priority === "P1") p1++;
|
|
265
|
+
else if (item.priority === "P2") p2++;
|
|
266
|
+
else p3++;
|
|
267
|
+
if (item.status === "todo") todo++;
|
|
268
|
+
else if (item.status === "in-progress") inProg++;
|
|
269
|
+
else if (item.status === "done") done++;
|
|
270
|
+
else blocked++;
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
p0,
|
|
274
|
+
p1,
|
|
275
|
+
p2,
|
|
276
|
+
p3,
|
|
277
|
+
todo,
|
|
278
|
+
inProg,
|
|
279
|
+
done,
|
|
280
|
+
blocked
|
|
281
|
+
};
|
|
282
|
+
}, [items]);
|
|
283
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
284
|
+
gap: 2,
|
|
285
|
+
paddingX: 1,
|
|
286
|
+
children: [
|
|
287
|
+
/* @__PURE__ */ jsxs(Strong, {
|
|
288
|
+
color: "$error",
|
|
289
|
+
children: ["P0:", stats.p0]
|
|
290
|
+
}),
|
|
291
|
+
/* @__PURE__ */ jsxs(Strong, {
|
|
292
|
+
color: "$warning",
|
|
293
|
+
children: ["P1:", stats.p1]
|
|
294
|
+
}),
|
|
295
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
296
|
+
color: "$info",
|
|
297
|
+
children: ["P2:", stats.p2]
|
|
298
|
+
}),
|
|
299
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
300
|
+
dim: true,
|
|
301
|
+
children: ["P3:", stats.p3]
|
|
302
|
+
}),
|
|
303
|
+
/* @__PURE__ */ jsx(Text, {
|
|
304
|
+
dim: true,
|
|
305
|
+
children: "|"
|
|
306
|
+
}),
|
|
307
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
308
|
+
color: "$muted",
|
|
309
|
+
children: [
|
|
310
|
+
STATUS_ICONS.todo,
|
|
311
|
+
" ",
|
|
312
|
+
stats.todo
|
|
313
|
+
]
|
|
314
|
+
}),
|
|
315
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
316
|
+
color: "$warning",
|
|
317
|
+
children: [
|
|
318
|
+
STATUS_ICONS["in-progress"],
|
|
319
|
+
" ",
|
|
320
|
+
stats.inProg
|
|
321
|
+
]
|
|
322
|
+
}),
|
|
323
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
324
|
+
color: "$success",
|
|
325
|
+
children: [
|
|
326
|
+
STATUS_ICONS.done,
|
|
327
|
+
" ",
|
|
328
|
+
stats.done
|
|
329
|
+
]
|
|
330
|
+
}),
|
|
331
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
332
|
+
color: "$error",
|
|
333
|
+
children: [
|
|
334
|
+
STATUS_ICONS.blocked,
|
|
335
|
+
" ",
|
|
336
|
+
stats.blocked
|
|
337
|
+
]
|
|
338
|
+
})
|
|
339
|
+
]
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
function VirtualBenchmark() {
|
|
343
|
+
const { width, height } = useBoxRect();
|
|
344
|
+
const [cursor, setCursor] = useState(0);
|
|
345
|
+
const [showDetail, setShowDetail] = useState(false);
|
|
346
|
+
const listHeight = Math.max(5, height - 5);
|
|
347
|
+
const halfPage = Math.max(1, Math.floor(listHeight / 2));
|
|
348
|
+
const estimateHeight = useCallback((index) => {
|
|
349
|
+
if (showDetail && index === cursor) return 2;
|
|
350
|
+
return 1;
|
|
351
|
+
}, [showDetail, cursor]);
|
|
352
|
+
useInput$1(useCallback((input, key) => {
|
|
353
|
+
if (input === "q" || key.escape || key.ctrl && input === "c") return "exit";
|
|
354
|
+
if (input === "j" || key.downArrow) setCursor((c) => Math.min(TOTAL_ITEMS - 1, c + 1));
|
|
355
|
+
if (input === "k" || key.upArrow) setCursor((c) => Math.max(0, c - 1));
|
|
356
|
+
if (input === "d" || key.pageDown) setCursor((c) => Math.min(TOTAL_ITEMS - 1, c + halfPage));
|
|
357
|
+
if (input === "u" || key.pageUp) setCursor((c) => Math.max(0, c - halfPage));
|
|
358
|
+
if (input === "g" || key.home) setCursor(0);
|
|
359
|
+
if (input === "G" || key.end) setCursor(TOTAL_ITEMS - 1);
|
|
360
|
+
if (key.return || input === " ") setShowDetail((d) => !d);
|
|
361
|
+
}, [halfPage]));
|
|
362
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
363
|
+
flexDirection: "column",
|
|
364
|
+
width: "100%",
|
|
365
|
+
height: "100%",
|
|
366
|
+
children: [
|
|
367
|
+
/* @__PURE__ */ jsx(StatsBar, { items: ALL_ITEMS }),
|
|
368
|
+
/* @__PURE__ */ jsx(Box, {
|
|
369
|
+
paddingX: 1,
|
|
370
|
+
children: /* @__PURE__ */ jsx(Divider, {})
|
|
371
|
+
}),
|
|
372
|
+
/* @__PURE__ */ jsx(Box, {
|
|
373
|
+
flexGrow: 1,
|
|
374
|
+
children: /* @__PURE__ */ jsx(ListView, {
|
|
375
|
+
items: ALL_ITEMS,
|
|
376
|
+
height: listHeight,
|
|
377
|
+
estimateHeight,
|
|
378
|
+
scrollTo: cursor,
|
|
379
|
+
overscan: 5,
|
|
380
|
+
renderItem: (item, index) => /* @__PURE__ */ jsx(ItemRow, {
|
|
381
|
+
item,
|
|
382
|
+
isSelected: index === cursor,
|
|
383
|
+
showDetail: showDetail && index === cursor
|
|
384
|
+
}, item.id)
|
|
385
|
+
})
|
|
386
|
+
}),
|
|
387
|
+
/* @__PURE__ */ jsx(ScrollIndicator, {
|
|
388
|
+
current: cursor,
|
|
389
|
+
total: TOTAL_ITEMS,
|
|
390
|
+
width
|
|
391
|
+
}),
|
|
392
|
+
/* @__PURE__ */ jsx(Box, {
|
|
393
|
+
paddingX: 1,
|
|
394
|
+
justifyContent: "center",
|
|
395
|
+
children: /* @__PURE__ */ jsxs(Muted, { children: [
|
|
396
|
+
/* @__PURE__ */ jsx(Kbd, { children: "j/k" }),
|
|
397
|
+
" navigate ",
|
|
398
|
+
/* @__PURE__ */ jsx(Kbd, { children: "d/u" }),
|
|
399
|
+
" half-page ",
|
|
400
|
+
/* @__PURE__ */ jsx(Kbd, { children: "g/G" }),
|
|
401
|
+
" start/end ",
|
|
402
|
+
/* @__PURE__ */ jsx(Kbd, { children: "Enter" }),
|
|
403
|
+
" detail",
|
|
404
|
+
" ",
|
|
405
|
+
/* @__PURE__ */ jsx(Kbd, { children: "Esc/q" }),
|
|
406
|
+
" quit"
|
|
407
|
+
] })
|
|
408
|
+
})
|
|
409
|
+
]
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
async function main() {
|
|
413
|
+
await (await run(/* @__PURE__ */ jsx(ExampleBanner, {
|
|
414
|
+
meta,
|
|
415
|
+
controls: "j/k navigate d/u half-page g/G start/end Enter detail Esc/q quit",
|
|
416
|
+
children: /* @__PURE__ */ jsx(VirtualBenchmark, {})
|
|
417
|
+
}))).waitUntilExit();
|
|
418
|
+
}
|
|
419
|
+
if (import.meta.main) await main();
|
|
420
|
+
//#endregion
|
|
421
|
+
export { main, meta };
|
|
Binary file
|