@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.
Files changed (111) hide show
  1. package/dist/UPNG-ShUlaTDh.mjs +5074 -0
  2. package/dist/__vite-browser-external-2447137e-Bopa5BFR.mjs +4 -0
  3. package/dist/_banner-A70_y2Vi.mjs +43 -0
  4. package/dist/ansi-0VXlUmNn.mjs +16397 -0
  5. package/dist/apng-B0gRaDVT.mjs +3 -0
  6. package/dist/apng-BTRDTfDW.mjs +68 -0
  7. package/dist/apps/aichat/index.mjs +1298 -0
  8. package/dist/apps/app-todo.mjs +138 -0
  9. package/dist/apps/async-data.mjs +203 -0
  10. package/dist/apps/cli-wizard.mjs +338 -0
  11. package/dist/apps/clipboard.mjs +197 -0
  12. package/dist/apps/components.mjs +863 -0
  13. package/dist/apps/data-explorer.mjs +482 -0
  14. package/dist/apps/dev-tools.mjs +396 -0
  15. package/dist/apps/explorer.mjs +697 -0
  16. package/dist/apps/gallery.mjs +765 -0
  17. package/dist/apps/inline-bench.mjs +115 -0
  18. package/dist/apps/kanban.mjs +279 -0
  19. package/dist/apps/layout-ref.mjs +186 -0
  20. package/dist/apps/outline.mjs +202 -0
  21. package/dist/apps/paste-demo.mjs +188 -0
  22. package/dist/apps/scroll.mjs +85 -0
  23. package/dist/apps/search-filter.mjs +286 -0
  24. package/dist/apps/selection.mjs +354 -0
  25. package/dist/apps/spatial-focus-demo.mjs +387 -0
  26. package/dist/apps/task-list.mjs +257 -0
  27. package/dist/apps/terminal-caps-demo.mjs +314 -0
  28. package/dist/apps/terminal.mjs +871 -0
  29. package/dist/apps/text-selection-demo.mjs +253 -0
  30. package/dist/apps/textarea.mjs +177 -0
  31. package/dist/apps/theme.mjs +660 -0
  32. package/dist/apps/transform.mjs +214 -0
  33. package/dist/apps/virtual-10k.mjs +421 -0
  34. package/dist/assets/resvgjs.darwin-arm64-BtufyGW1.node +0 -0
  35. package/dist/backends-Dj-11kZF.mjs +1179 -0
  36. package/dist/backends-U3QwStfO.mjs +3 -0
  37. package/dist/{cli.mjs → bin/cli.mjs} +15 -19
  38. package/dist/chunk-BSw8zbkd.mjs +37 -0
  39. package/dist/components/counter.mjs +47 -0
  40. package/dist/components/hello.mjs +30 -0
  41. package/dist/components/progress-bar.mjs +58 -0
  42. package/dist/components/select-list.mjs +84 -0
  43. package/dist/components/spinner.mjs +56 -0
  44. package/dist/components/text-input.mjs +61 -0
  45. package/dist/components/virtual-list.mjs +50 -0
  46. package/dist/flexily-zero-adapter-ByVzLTFP.mjs +3374 -0
  47. package/dist/gif-B6NGH5gs.mjs +3 -0
  48. package/dist/gif-CfkOF-iG.mjs +71 -0
  49. package/dist/gifenc-BI4ihP_T.mjs +728 -0
  50. package/dist/key-mapping-5oYQdAQE.mjs +3 -0
  51. package/dist/key-mapping-D4LR1go6.mjs +130 -0
  52. package/dist/layout/dashboard.mjs +1203 -0
  53. package/dist/layout/live-resize.mjs +302 -0
  54. package/dist/layout/overflow.mjs +69 -0
  55. package/dist/layout/text-layout.mjs +334 -0
  56. package/dist/node-nsrAOjH4.mjs +1083 -0
  57. package/dist/plugins-CT0DdV_E.mjs +3056 -0
  58. package/dist/resvg-js-Cnk2o49d.mjs +201 -0
  59. package/dist/src-9ZhfQyzD.mjs +814 -0
  60. package/dist/src-CUUOuRH6.mjs +5322 -0
  61. package/dist/src-jO3Zuzjj.mjs +23538 -0
  62. package/dist/usingCtx-CsEf0xO3.mjs +57 -0
  63. package/dist/yoga-adapter-BSQHuMV9.mjs +237 -0
  64. package/package.json +21 -14
  65. package/_banner.tsx +0 -60
  66. package/apps/aichat/components.tsx +0 -469
  67. package/apps/aichat/index.tsx +0 -220
  68. package/apps/aichat/script.ts +0 -460
  69. package/apps/aichat/state.ts +0 -325
  70. package/apps/aichat/types.ts +0 -19
  71. package/apps/app-todo.tsx +0 -201
  72. package/apps/async-data.tsx +0 -196
  73. package/apps/cli-wizard.tsx +0 -332
  74. package/apps/clipboard.tsx +0 -183
  75. package/apps/components.tsx +0 -658
  76. package/apps/data-explorer.tsx +0 -490
  77. package/apps/dev-tools.tsx +0 -395
  78. package/apps/explorer.tsx +0 -731
  79. package/apps/gallery.tsx +0 -653
  80. package/apps/inline-bench.tsx +0 -138
  81. package/apps/kanban.tsx +0 -265
  82. package/apps/layout-ref.tsx +0 -173
  83. package/apps/outline.tsx +0 -160
  84. package/apps/panes/index.tsx +0 -203
  85. package/apps/paste-demo.tsx +0 -185
  86. package/apps/scroll.tsx +0 -80
  87. package/apps/search-filter.tsx +0 -240
  88. package/apps/selection.tsx +0 -346
  89. package/apps/spatial-focus-demo.tsx +0 -372
  90. package/apps/task-list.tsx +0 -271
  91. package/apps/terminal-caps-demo.tsx +0 -317
  92. package/apps/terminal.tsx +0 -784
  93. package/apps/text-selection-demo.tsx +0 -193
  94. package/apps/textarea.tsx +0 -155
  95. package/apps/theme.tsx +0 -515
  96. package/apps/transform.tsx +0 -229
  97. package/apps/virtual-10k.tsx +0 -405
  98. package/apps/vterm-demo/index.tsx +0 -216
  99. package/components/counter.tsx +0 -49
  100. package/components/hello.tsx +0 -38
  101. package/components/progress-bar.tsx +0 -52
  102. package/components/select-list.tsx +0 -54
  103. package/components/spinner.tsx +0 -44
  104. package/components/text-input.tsx +0 -61
  105. package/components/virtual-list.tsx +0 -56
  106. package/dist/cli.d.mts +0 -1
  107. package/dist/cli.mjs.map +0 -1
  108. package/layout/dashboard.tsx +0 -953
  109. package/layout/live-resize.tsx +0 -282
  110. package/layout/overflow.tsx +0 -51
  111. package/layout/text-layout.tsx +0 -283
@@ -0,0 +1,396 @@
1
+ import { t as _usingCtx } from "../usingCtx-CsEf0xO3.mjs";
2
+ import { t as ExampleBanner } from "../_banner-A70_y2Vi.mjs";
3
+ import { useCallback, useMemo, useState } from "react";
4
+ import { Box, Divider, ListView, Muted, Strong, Text, createTerm, render, useApp, useBoxRect, useInput } from "silvery";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ //#region apps/dev-tools.tsx
7
+ /**
8
+ * Dev Tools — Log Viewer Example
9
+ *
10
+ * A live log viewer demonstrating:
11
+ * - ListView for efficient rendering of thousands of log entries
12
+ * - Keyboard shortcuts to add log entries at different severity levels
13
+ * - Color-coded severity levels (DEBUG, INFO, WARN, ERROR)
14
+ * - j/k navigation through log history
15
+ * - Auto-scroll to latest entry
16
+ *
17
+ * Usage: bun run examples/apps/dev-tools.tsx
18
+ *
19
+ * Controls:
20
+ * j/k or Up/Down - Navigate through log entries
21
+ * g/G - Jump to first/last entry
22
+ * d - Add DEBUG entry
23
+ * i - Add INFO entry
24
+ * w - Add WARN entry
25
+ * e - Add ERROR entry
26
+ * c - Clear all logs
27
+ * q or Esc - Quit
28
+ */
29
+ const meta = {
30
+ name: "Dev Tools",
31
+ description: "Log viewer with severity levels, ListView, and keyboard-driven log injection",
32
+ features: [
33
+ "ListView",
34
+ "useInput()",
35
+ "useBoxRect()",
36
+ "keyboard navigation"
37
+ ]
38
+ };
39
+ const SOURCES = [
40
+ "http",
41
+ "db",
42
+ "auth",
43
+ "cache",
44
+ "worker",
45
+ "api",
46
+ "scheduler",
47
+ "queue",
48
+ "metrics",
49
+ "ws"
50
+ ];
51
+ const LOG_TEMPLATES = {
52
+ DEBUG: [
53
+ "Cache miss for key user:session:{{id}}",
54
+ "Query plan: sequential scan on events ({{n}} rows)",
55
+ "WebSocket frame received: {{n}} bytes",
56
+ "GC pause: {{n}}ms (minor collection)",
57
+ "Connection pool stats: {{n}} active, {{n}} idle",
58
+ "Route matched: GET /api/v2/resources/{{id}}"
59
+ ],
60
+ INFO: [
61
+ "Request completed: 200 OK ({{n}}ms)",
62
+ "User {{id}} authenticated via OAuth",
63
+ "Background job processed: email_dispatch #{{id}}",
64
+ "Server listening on port {{n}}",
65
+ "Database migration applied: v{{n}}",
66
+ "Health check passed (latency: {{n}}ms)"
67
+ ],
68
+ WARN: [
69
+ "Slow query detected: {{n}}ms (threshold: 200ms)",
70
+ "Rate limit approaching: {{n}}/1000 requests",
71
+ "Memory usage: {{n}}% of allocated heap",
72
+ "Retry attempt {{n}}/3 for external API call",
73
+ "Certificate expires in {{n}} days",
74
+ "Connection pool near capacity: {{n}}/100"
75
+ ],
76
+ ERROR: [
77
+ "Unhandled exception in request handler: TypeError",
78
+ "Database connection refused: ECONNREFUSED",
79
+ "Authentication failed for user {{id}}: invalid token",
80
+ "Timeout after {{n}}ms waiting for upstream service",
81
+ "Disk usage critical: {{n}}% on /var/data",
82
+ "Failed to process message from queue: malformed payload"
83
+ ]
84
+ };
85
+ let nextLogId = 1;
86
+ function seededRandom(seed) {
87
+ let s = seed;
88
+ return () => {
89
+ s = s * 1664525 + 1013904223 & 2147483647;
90
+ return s / 2147483647;
91
+ };
92
+ }
93
+ function generateMessage(level, rng) {
94
+ const templates = LOG_TEMPLATES[level];
95
+ return templates[Math.floor(rng() * templates.length)].replace(/\{\{id\}\}/g, () => String(Math.floor(rng() * 99999))).replace(/\{\{n\}\}/g, () => String(Math.floor(rng() * 999)));
96
+ }
97
+ function createLogEntry(level, rng) {
98
+ return {
99
+ id: nextLogId++,
100
+ timestamp: /* @__PURE__ */ new Date(),
101
+ level,
102
+ source: SOURCES[Math.floor(rng() * SOURCES.length)],
103
+ message: generateMessage(level, rng)
104
+ };
105
+ }
106
+ function generateInitialLogs(count) {
107
+ const rng = seededRandom(42);
108
+ const levels = [
109
+ "DEBUG",
110
+ "INFO",
111
+ "INFO",
112
+ "INFO",
113
+ "WARN",
114
+ "ERROR"
115
+ ];
116
+ const entries = [];
117
+ const now = Date.now();
118
+ for (let i = 0; i < count; i++) {
119
+ const level = levels[Math.floor(rng() * levels.length)];
120
+ const entry = createLogEntry(level, rng);
121
+ entry.timestamp = /* @__PURE__ */ new Date(now - (count - i) * 1200);
122
+ entries.push(entry);
123
+ }
124
+ return entries;
125
+ }
126
+ const LEVEL_COLORS = {
127
+ DEBUG: "$muted",
128
+ INFO: "$primary",
129
+ WARN: "$warning",
130
+ ERROR: "$error"
131
+ };
132
+ const LEVEL_BADGES = {
133
+ DEBUG: "DBG",
134
+ INFO: "INF",
135
+ WARN: "WRN",
136
+ ERROR: "ERR"
137
+ };
138
+ function formatTime(date) {
139
+ return date.toLocaleTimeString("en-US", {
140
+ hour: "2-digit",
141
+ minute: "2-digit",
142
+ second: "2-digit",
143
+ hour12: false
144
+ });
145
+ }
146
+ function LogRow({ entry, isSelected }) {
147
+ const badge = LEVEL_BADGES[entry.level];
148
+ const color = LEVEL_COLORS[entry.level];
149
+ if (isSelected) return /* @__PURE__ */ jsxs(Box, {
150
+ paddingX: 1,
151
+ backgroundColor: "$primary",
152
+ children: [
153
+ /* @__PURE__ */ jsxs(Text, {
154
+ color: "$primary-fg",
155
+ children: [formatTime(entry.timestamp), " "]
156
+ }),
157
+ /* @__PURE__ */ jsx(Text, {
158
+ color: "$primary-fg",
159
+ bold: true,
160
+ children: badge
161
+ }),
162
+ /* @__PURE__ */ jsxs(Text, {
163
+ color: "$primary-fg",
164
+ children: [
165
+ " [",
166
+ entry.source.padEnd(9),
167
+ "] "
168
+ ]
169
+ }),
170
+ /* @__PURE__ */ jsx(Text, {
171
+ color: "$primary-fg",
172
+ bold: true,
173
+ children: entry.message
174
+ })
175
+ ]
176
+ });
177
+ return /* @__PURE__ */ jsxs(Box, {
178
+ paddingX: 1,
179
+ children: [
180
+ /* @__PURE__ */ jsxs(Muted, { children: [formatTime(entry.timestamp), " "] }),
181
+ /* @__PURE__ */ jsx(Strong, {
182
+ color,
183
+ children: badge
184
+ }),
185
+ /* @__PURE__ */ jsxs(Muted, { children: [
186
+ " [",
187
+ entry.source.padEnd(9),
188
+ "] "
189
+ ] }),
190
+ /* @__PURE__ */ jsx(Text, { children: entry.message })
191
+ ]
192
+ });
193
+ }
194
+ function LevelCounts({ entries }) {
195
+ const counts = useMemo(() => {
196
+ const c = {
197
+ DEBUG: 0,
198
+ INFO: 0,
199
+ WARN: 0,
200
+ ERROR: 0
201
+ };
202
+ for (const e of entries) c[e.level]++;
203
+ return c;
204
+ }, [entries]);
205
+ return /* @__PURE__ */ jsxs(Box, {
206
+ gap: 2,
207
+ children: [
208
+ /* @__PURE__ */ jsxs(Strong, {
209
+ color: "$muted",
210
+ children: [
211
+ LEVEL_BADGES.DEBUG,
212
+ ":",
213
+ counts.DEBUG
214
+ ]
215
+ }),
216
+ /* @__PURE__ */ jsxs(Strong, {
217
+ color: "$primary",
218
+ children: [
219
+ LEVEL_BADGES.INFO,
220
+ ":",
221
+ counts.INFO
222
+ ]
223
+ }),
224
+ /* @__PURE__ */ jsxs(Strong, {
225
+ color: "$warning",
226
+ children: [
227
+ LEVEL_BADGES.WARN,
228
+ ":",
229
+ counts.WARN
230
+ ]
231
+ }),
232
+ /* @__PURE__ */ jsxs(Strong, {
233
+ color: "$error",
234
+ children: [
235
+ LEVEL_BADGES.ERROR,
236
+ ":",
237
+ counts.ERROR
238
+ ]
239
+ })
240
+ ]
241
+ });
242
+ }
243
+ /** Inner component that reads the flex container's height via useBoxRect */
244
+ function LogListArea({ entries, cursor }) {
245
+ const { height } = useBoxRect();
246
+ return /* @__PURE__ */ jsx(ListView, {
247
+ items: entries,
248
+ height,
249
+ estimateHeight: 1,
250
+ scrollTo: cursor,
251
+ overscan: 5,
252
+ renderItem: (entry, index) => /* @__PURE__ */ jsx(LogRow, {
253
+ entry,
254
+ isSelected: index === cursor
255
+ }, entry.id)
256
+ });
257
+ }
258
+ const INITIAL_COUNT = 200;
259
+ const rng = seededRandom(12345);
260
+ function DevTools() {
261
+ const { exit } = useApp();
262
+ const [entries, setEntries] = useState(() => generateInitialLogs(INITIAL_COUNT));
263
+ const [cursor, setCursor] = useState(INITIAL_COUNT - 1);
264
+ const [autoScroll, setAutoScroll] = useState(true);
265
+ const addEntry = useCallback((level) => {
266
+ const entry = createLogEntry(level, rng);
267
+ setEntries((prev) => [...prev, entry]);
268
+ if (autoScroll) setCursor((prev) => prev + 1);
269
+ }, [autoScroll]);
270
+ useInput(useCallback((input, key) => {
271
+ if (input === "q" || key.escape) {
272
+ exit();
273
+ return;
274
+ }
275
+ if (input === "j" || key.downArrow) {
276
+ setCursor((c) => Math.min(entries.length - 1, c + 1));
277
+ setAutoScroll(false);
278
+ return;
279
+ }
280
+ if (input === "k" || key.upArrow) {
281
+ setCursor((c) => Math.max(0, c - 1));
282
+ setAutoScroll(false);
283
+ return;
284
+ }
285
+ if (input === "g" || key.home) {
286
+ setCursor(0);
287
+ setAutoScroll(false);
288
+ return;
289
+ }
290
+ if (input === "G" || key.end) {
291
+ setCursor(entries.length - 1);
292
+ setAutoScroll(true);
293
+ return;
294
+ }
295
+ if (input === "d") {
296
+ addEntry("DEBUG");
297
+ return;
298
+ }
299
+ if (input === "i") {
300
+ addEntry("INFO");
301
+ return;
302
+ }
303
+ if (input === "w") {
304
+ addEntry("WARN");
305
+ return;
306
+ }
307
+ if (input === "e") {
308
+ addEntry("ERROR");
309
+ return;
310
+ }
311
+ if (input === "c") {
312
+ setEntries([]);
313
+ setCursor(0);
314
+ setAutoScroll(true);
315
+ return;
316
+ }
317
+ }, [
318
+ entries.length,
319
+ exit,
320
+ addEntry
321
+ ]));
322
+ return /* @__PURE__ */ jsxs(Box, {
323
+ flexDirection: "column",
324
+ flexGrow: 1,
325
+ padding: 1,
326
+ children: [
327
+ /* @__PURE__ */ jsxs(Box, {
328
+ justifyContent: "space-between",
329
+ backgroundColor: "$surfacebg",
330
+ children: [/* @__PURE__ */ jsxs(Box, {
331
+ gap: 2,
332
+ children: [/* @__PURE__ */ jsxs(Text, {
333
+ bold: true,
334
+ color: "$primary",
335
+ children: ["▸", " Log Viewer"]
336
+ }), /* @__PURE__ */ jsx(LevelCounts, { entries })]
337
+ }), /* @__PURE__ */ jsxs(Box, {
338
+ gap: 1,
339
+ children: [
340
+ autoScroll && /* @__PURE__ */ jsx(Text, {
341
+ backgroundColor: "$success",
342
+ color: "$success-fg",
343
+ bold: true,
344
+ children: " LIVE "
345
+ }),
346
+ /* @__PURE__ */ jsx(Strong, {
347
+ color: "$primary",
348
+ children: cursor + 1
349
+ }),
350
+ /* @__PURE__ */ jsxs(Muted, { children: ["/ ", entries.length] })
351
+ ]
352
+ })]
353
+ }),
354
+ /* @__PURE__ */ jsxs(Box, {
355
+ paddingX: 1,
356
+ children: [
357
+ /* @__PURE__ */ jsxs(Muted, { children: ["Time ", " "] }),
358
+ /* @__PURE__ */ jsxs(Muted, { children: ["Lvl", " "] }),
359
+ /* @__PURE__ */ jsxs(Muted, { children: ["[Source ]", " "] }),
360
+ /* @__PURE__ */ jsx(Muted, { children: "Message" })
361
+ ]
362
+ }),
363
+ /* @__PURE__ */ jsx(Box, {
364
+ paddingX: 1,
365
+ children: /* @__PURE__ */ jsx(Divider, {})
366
+ }),
367
+ /* @__PURE__ */ jsx(Box, {
368
+ flexGrow: 1,
369
+ flexDirection: "column",
370
+ children: /* @__PURE__ */ jsx(LogListArea, {
371
+ entries,
372
+ cursor
373
+ })
374
+ })
375
+ ]
376
+ });
377
+ }
378
+ async function main() {
379
+ try {
380
+ var _usingCtx$1 = _usingCtx();
381
+ const term = _usingCtx$1.u(createTerm());
382
+ const { waitUntilExit } = await render(/* @__PURE__ */ jsx(ExampleBanner, {
383
+ meta,
384
+ controls: "j/k navigate g/G start/end d/i/w/e add log c clear Esc/q quit",
385
+ children: /* @__PURE__ */ jsx(DevTools, {})
386
+ }), term);
387
+ await waitUntilExit();
388
+ } catch (_) {
389
+ _usingCtx$1.e = _;
390
+ } finally {
391
+ _usingCtx$1.d();
392
+ }
393
+ }
394
+ if (import.meta.main) await main();
395
+ //#endregion
396
+ export { DevTools, main, meta };