@yaks/visualize 0.0.0-stage → 0.2.36

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 (83) hide show
  1. package/ActivityView.tsx +370 -0
  2. package/AnatomyList.tsx +183 -0
  3. package/Atlas.tsx +490 -0
  4. package/Detail.tsx +464 -0
  5. package/LICENSE +202 -0
  6. package/README.md +180 -2
  7. package/SectionHead.tsx +18 -0
  8. package/Topology.tsx +596 -0
  9. package/_dist/activity.d.ts +15 -0
  10. package/_dist/activity.d.ts.map +1 -0
  11. package/_dist/capture.d.ts +19 -0
  12. package/_dist/capture.d.ts.map +1 -0
  13. package/_dist/cli.d.ts +6 -0
  14. package/_dist/cli.d.ts.map +1 -0
  15. package/_dist/front.d.ts +6 -0
  16. package/_dist/front.d.ts.map +1 -0
  17. package/_dist/http.d.ts +21 -0
  18. package/_dist/http.d.ts.map +1 -0
  19. package/_dist/main.d.ts +2 -0
  20. package/_dist/main.d.ts.map +1 -0
  21. package/_dist/mod.d.ts +6 -0
  22. package/_dist/mod.d.ts.map +1 -0
  23. package/_dist/model.d.ts +55 -0
  24. package/_dist/model.d.ts.map +1 -0
  25. package/_dist/parts.d.ts +19 -0
  26. package/_dist/parts.d.ts.map +1 -0
  27. package/_dist/routes.d.ts +7 -0
  28. package/_dist/routes.d.ts.map +1 -0
  29. package/_dist/snapshot.d.ts +38 -0
  30. package/_dist/snapshot.d.ts.map +1 -0
  31. package/_dist/stream.d.ts +3 -0
  32. package/_dist/stream.d.ts.map +1 -0
  33. package/_dist/tools.d.ts +10 -0
  34. package/_dist/tools.d.ts.map +1 -0
  35. package/_dist/vocab.d.ts +5 -0
  36. package/_dist/vocab.d.ts.map +1 -0
  37. package/activity.js +73 -0
  38. package/activity.js.map +1 -0
  39. package/activity.ts +104 -0
  40. package/capture.js +46 -0
  41. package/capture.js.map +1 -0
  42. package/capture.ts +68 -0
  43. package/cli.js +173 -0
  44. package/cli.js.map +1 -0
  45. package/cli.ts +200 -0
  46. package/deno.json +1 -0
  47. package/front.js +21 -0
  48. package/front.js.map +1 -0
  49. package/front.json +210 -0
  50. package/front.ts +22 -0
  51. package/http.js +290 -0
  52. package/http.js.map +1 -0
  53. package/http.ts +338 -0
  54. package/main.js +51 -0
  55. package/main.js.map +1 -0
  56. package/main.ts +50 -0
  57. package/mod.js +6 -0
  58. package/mod.js.map +1 -0
  59. package/mod.ts +15 -0
  60. package/model.js +551 -0
  61. package/model.js.map +1 -0
  62. package/model.ts +543 -0
  63. package/package.json +76 -4
  64. package/parts.js +70 -0
  65. package/parts.js.map +1 -0
  66. package/parts.ts +113 -0
  67. package/routes.js +53 -0
  68. package/routes.js.map +1 -0
  69. package/routes.ts +76 -0
  70. package/snapshot.js +117 -0
  71. package/snapshot.js.map +1 -0
  72. package/snapshot.ts +157 -0
  73. package/stream.js +73 -0
  74. package/stream.js.map +1 -0
  75. package/stream.ts +95 -0
  76. package/tools.js +64 -0
  77. package/tools.js.map +1 -0
  78. package/tools.ts +79 -0
  79. package/visualize.css +1787 -0
  80. package/vocab.js +13 -0
  81. package/vocab.js.map +1 -0
  82. package/vocab.json +97 -0
  83. package/vocab.ts +14 -0
package/Atlas.tsx ADDED
@@ -0,0 +1,490 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ /** A process-local system MRI. The model owns navigation, filters, camera and
3
+ * playback; this surface owns only layout, focus and display-only kit parts.
4
+ */
5
+
6
+ /* @ts-types="npm:@types/react@19.3.0" */ import { type KeyboardEvent, useRef } from 'npm:react@19.3.0'
7
+ import { AppShell, Button, Chip, Field, Select } from 'jsr:@yaks/ui@0.2.36'
8
+ import { useObserved } from 'jsr:@yaks/ux@0.2.36'
9
+ import type { AtlasModel } from './model.ts'
10
+ import { ActivityView } from './ActivityView.tsx'
11
+ import { AnatomyList, matchingEdges, PAGE_SIZE } from './AnatomyList.tsx'
12
+ import { Detail } from './Detail.tsx'
13
+ import {
14
+ filtered,
15
+ groupName,
16
+ mapParts,
17
+ sections,
18
+ Spine,
19
+ Topology,
20
+ zoomed,
21
+ } from './Topology.tsx'
22
+
23
+ let connectionNames: Record<string, string> = {
24
+ connecting: 'Connecting',
25
+ live: 'Live',
26
+ reconnecting: 'Reconnecting',
27
+ paused: 'Paused',
28
+ offline: 'Offline',
29
+ }
30
+
31
+ let Mark = () => (
32
+ <svg className='Atlas_Mark' viewBox='0 0 40 40' aria-hidden='true'>
33
+ <rect
34
+ className='Atlas_Mark_Frame'
35
+ x='3'
36
+ y='3'
37
+ width='34'
38
+ height='34'
39
+ rx='9'
40
+ />
41
+ <path className='Atlas_Mark_Path' d='M7 20h7l3-7 5 15 4-8h7' />
42
+ <circle className='Atlas_Mark_Circle' cx='20' cy='20' r='13' />
43
+ </svg>
44
+ )
45
+
46
+ let Shortcuts = () => (
47
+ <details className='Atlas_Shortcuts'>
48
+ <summary className='Atlas_Summary Atlas_Shortcuts_Summary'>
49
+ Keyboard <kbd className='Atlas_Key'>?</kbd>
50
+ </summary>
51
+ <dl className='Atlas_Reset Atlas_Shortcuts_List'>
52
+ {[
53
+ ['/', 'Focus search'],
54
+ ['↑ / ↓', 'Select a part'],
55
+ ['Enter', 'Focus selected detail'],
56
+ ['+ / −', 'Zoom map'],
57
+ ['0', 'Fit map'],
58
+ ['P', 'Pause / resume'],
59
+ ['L / M', 'List / map'],
60
+ ['Esc', 'Clear selection'],
61
+ ].map(([keys, action]) => (
62
+ <div className='Atlas_Shortcuts_List_Row' key={keys}>
63
+ <dt>
64
+ <kbd className='Atlas_Key'>{keys}</kbd>
65
+ </dt>
66
+ <dd className='Atlas_Shortcuts_Value'>{action}</dd>
67
+ </div>
68
+ ))}
69
+ </dl>
70
+ </details>
71
+ )
72
+
73
+ export let Atlas = ({ model }: { model: AtlasModel }) => {
74
+ useObserved(model.snapshot)
75
+ let state = model.state
76
+ let search = useRef<HTMLInputElement>(null)
77
+ let root = useRef<HTMLDivElement>(null)
78
+ let groups = sections.flatMap((section) => section.groups)
79
+ let counts = new Map(
80
+ groups.map((group) => [
81
+ group,
82
+ model.nodes.filter((node) => node.group == group).length,
83
+ ]),
84
+ )
85
+ let parts = model.nodes.filter((node) => node.group != 'phases')
86
+ let loaded = parts.filter((node) => node.loaded).length
87
+ let bound = parts.filter((node) => node.bound).length
88
+ let unattempted =
89
+ parts.filter((node) =>
90
+ node.group == 'facets' && node.detail.attempted === false
91
+ ).length
92
+ let unobserved = Object.entries(model.coverage)
93
+ .filter(([, observed]) => !observed).map(([group]) => groupName(group))
94
+ let shown = state.group == 'relations'
95
+ ? matchingEdges(model).length
96
+ : state.view == 'map'
97
+ ? mapParts(model).length
98
+ : filtered(model).length
99
+ let connection = state.paused ? 'paused' : state.connected
100
+ let changeGroup = (group: string) =>
101
+ model.set({
102
+ group,
103
+ listPage: 0,
104
+ ...(['relations', 'phases'].includes(group) &&
105
+ { view: 'list' as const }),
106
+ })
107
+ let map = () =>
108
+ model.set({
109
+ view: 'map',
110
+ ...(['relations', 'phases'].includes(state.group) &&
111
+ { group: 'all' }),
112
+ })
113
+ let press = (event: KeyboardEvent<HTMLDivElement>) => {
114
+ let target = event.target as Element
115
+ if (
116
+ event.altKey || event.ctrlKey || event.metaKey ||
117
+ target.closest('input,textarea,select,[contenteditable="true"]')
118
+ ) return
119
+ let key = event.key.toLocaleLowerCase()
120
+ if (key == '/') {
121
+ event.preventDefault()
122
+ search.current?.focus()
123
+ return
124
+ }
125
+ if (key == 'arrowdown' || key == 'arrowup') {
126
+ event.preventDefault()
127
+ let ids = state.group == 'relations'
128
+ ? matchingEdges(model).map((e) => e.id)
129
+ : (state.view == 'map' ? mapParts(model) : filtered(model))
130
+ .map((node) => node.id)
131
+ if (!ids.length) return
132
+ let at = ids.indexOf(state.selected)
133
+ let index = at < 0 ? key == 'arrowdown' ? 0 : ids.length - 1 : Math.max(
134
+ 0,
135
+ Math.min(ids.length - 1, at + (key == 'arrowdown' ? 1 : -1)),
136
+ )
137
+ model.select(ids[index])
138
+ model.set({ listPage: Math.floor(index / PAGE_SIZE) })
139
+ return
140
+ }
141
+ if (key == 'enter' && !target.closest('button,a,summary,[role="button"]')) {
142
+ event.preventDefault()
143
+ root.current?.querySelector<HTMLElement>('#atlas-detail')?.focus()
144
+ return
145
+ }
146
+ if (key == 'escape') {
147
+ model.select('')
148
+ model.choose('')
149
+ } else if (key == '+' || key == '=') zoomed(model, .2)
150
+ else if (key == '-') zoomed(model, -.2)
151
+ else if (key == '0') model.reset()
152
+ else if (key == 'p') model.set({ paused: !state.paused })
153
+ else if (key == 'l') model.set({ view: 'list' })
154
+ else if (key == 'm') map()
155
+ else if (key == '?') {
156
+ let shortcuts = root.current?.querySelector<HTMLDetailsElement>(
157
+ '.Atlas_Shortcuts',
158
+ )
159
+ if (shortcuts) shortcuts.open = !shortcuts.open
160
+ }
161
+ }
162
+ return (
163
+ <div
164
+ className='Atlas'
165
+ ref={root}
166
+ onKeyDown={press}
167
+ data-paused={state.paused}
168
+ data-theme={state.theme}
169
+ data-scheme={state.scheme}
170
+ style={{ colorScheme: state.scheme }}
171
+ >
172
+ <a href='#atlas-workspace' className='Atlas_Skip Atlas_Link'>
173
+ Skip to anatomy
174
+ </a>
175
+ <AppShell.Bar className='Atlas_Header' data-ready={Boolean(state.host)}>
176
+ <div className='Atlas_Brand'>
177
+ <Mark />
178
+ <div>
179
+ <AppShell.Label as='strong'>visualize</AppShell.Label>
180
+ <span className='Atlas_Brand_Text'>@yaks / system MRI</span>
181
+ </div>
182
+ </div>
183
+ <div className='Atlas_Host'>
184
+ <span className='Atlas_Eyebrow Atlas_Host_Text'>
185
+ Connected process
186
+ </span>
187
+ <span
188
+ className='Atlas_Host_Text'
189
+ title={state.host || 'Waiting for host anatomy'}
190
+ >
191
+ {state.host || 'Awaiting anatomy…'}
192
+ </span>
193
+ </div>
194
+ <div className='Atlas_HeaderControls'>
195
+ <span
196
+ className='Atlas_Connection'
197
+ data-connection={connection}
198
+ role='status'
199
+ >
200
+ <i className='Atlas_Connection_Indicator' aria-hidden='true' />
201
+ {connectionNames[connection] ?? connection}
202
+ </span>
203
+ <Button
204
+ type='button'
205
+ className='Atlas_Pause Atlas_Button'
206
+ aria-pressed={state.paused}
207
+ title='Pause or resume recording (P)'
208
+ onClick={() => model.set({ paused: !state.paused })}
209
+ >
210
+ <span aria-hidden='true'>{state.paused ? '▷' : 'Ⅱ'}</span>
211
+ {state.paused ? 'Resume' : 'Pause'}
212
+ </Button>
213
+ <label className='Atlas_Theme'>
214
+ <span className='Atlas_VisuallyHidden'>Color theme</span>
215
+ <Select
216
+ className='Atlas_Select Atlas_Theme_Select'
217
+ value={state.theme}
218
+ aria-label='Color theme'
219
+ onChange={(event: Event) =>
220
+ model.set({
221
+ theme: (event.currentTarget as HTMLSelectElement).value as
222
+ | 'everforest'
223
+ | 'rosepine',
224
+ })}
225
+ >
226
+ <option value='everforest'>Everforest</option>
227
+ <option value='rosepine'>Rosé Pine</option>
228
+ </Select>
229
+ </label>
230
+ <Button
231
+ type='button'
232
+ className='Atlas_Scheme Atlas_Button'
233
+ aria-label={`Switch to ${
234
+ state.scheme == 'dark' ? 'light' : 'dark'
235
+ } mode`}
236
+ title={`Switch to ${
237
+ state.scheme == 'dark' ? 'light' : 'dark'
238
+ } mode`}
239
+ onClick={() =>
240
+ model.set({ scheme: state.scheme == 'dark' ? 'light' : 'dark' })}
241
+ >
242
+ <span aria-hidden='true'>{state.scheme == 'dark' ? '☼' : '◐'}</span>
243
+ </Button>
244
+ </div>
245
+ </AppShell.Bar>
246
+ <main className='Atlas_Main'>
247
+ <section className='Atlas_Intro' aria-labelledby='atlas-title'>
248
+ <div className='Atlas_Heading'>
249
+ <span className='Atlas_Eyebrow'>Structure × causality</span>
250
+ <h1 className='Atlas_Reset Atlas_Heading_Title' id='atlas-title'>
251
+ The platform,{' '}
252
+ <em className='Atlas_Heading_Emphasis'>in focus.</em>
253
+ </h1>
254
+ <p className='Atlas_Reset Atlas_Heading_Description'>
255
+ Its parts. Their connections. The work moving through them.
256
+ </p>
257
+ </div>
258
+ <dl
259
+ className='Atlas_Metrics Atlas_Reset'
260
+ aria-label='Anatomy snapshot summary'
261
+ >
262
+ {[
263
+ [parts.length, 'reported parts'],
264
+ [loaded, 'loaded'],
265
+ [bound, 'bound'],
266
+ [model.edges.length, 'relationships'],
267
+ ].map(([number, label]) => (
268
+ <div className='Atlas_Metrics_Row' key={label}>
269
+ <dt className='Atlas_Metrics_Term'>{label}</dt>
270
+ <dd className='Atlas_Metrics_Value'>{number}</dd>
271
+ </div>
272
+ ))}
273
+ </dl>
274
+ </section>
275
+ <div className='Atlas_Coverage' role='note'>
276
+ <Chip className='Atlas_Scope' style={{ '--hue': 'var(--info)' }}>
277
+ Process-local
278
+ </Chip>
279
+ <p className='Atlas_Reset Atlas_Coverage_Description'>
280
+ Composition and activity of this host only. Recording exists while
281
+ subscribed; other processes and unobserved intervals are not
282
+ represented.
283
+ </p>
284
+ <span className='Atlas_Safety'>
285
+ Names & contracts. No entity or secret values.
286
+ </span>
287
+ </div>
288
+ {unobserved.length > 0 && (
289
+ <details className='Atlas_Unobserved'>
290
+ <summary className='Atlas_Summary Atlas_Unobserved_Summary'>
291
+ {unobserved.length} categories unobserved here
292
+ </summary>
293
+ <p className='Atlas_Reset Atlas_Unobserved_Description'>
294
+ {unobserved.join(' · ')}
295
+ </p>
296
+ <p className='Atlas_Reset Atlas_Unobserved_Description'>
297
+ An empty unobserved category is not evidence that its parts are
298
+ absent.
299
+ </p>
300
+ </details>
301
+ )}
302
+ {(state.error || state.gap > 0 || state.paused) && (
303
+ <section
304
+ className='Atlas_Notices'
305
+ aria-label='Connection and recording notices'
306
+ >
307
+ {state.error && (
308
+ <div className='Atlas_Notice' data-tone='negative' role='alert'>
309
+ <strong className='Atlas_Notice_Strong'>
310
+ Connection needs attention.
311
+ </strong>
312
+ <span className='Atlas_Notice_Text'>{state.error}</span>
313
+ <Button
314
+ className='Atlas_Button'
315
+ type='button'
316
+ onClick={() =>
317
+ void model.refresh()}
318
+ >
319
+ Retry anatomy
320
+ </Button>
321
+ </div>
322
+ )}
323
+ {state.gap > 0 && (
324
+ <div className='Atlas_Notice' data-tone='caution' role='status'>
325
+ <strong className='Atlas_Notice_Strong'>
326
+ Observation gaps ({state.gap})
327
+ </strong>
328
+ <span className='Atlas_Notice_Text'>
329
+ Pauses, epoch changes or known omissions broke continuity.
330
+ This counts episodes, not missed records. Disconnection alone
331
+ does not prove record loss.
332
+ </span>
333
+ </div>
334
+ )}
335
+ {state.paused && (
336
+ <div className='Atlas_Notice' data-tone='muted' role='status'>
337
+ <strong className='Atlas_Notice_Strong'>
338
+ Recording paused.
339
+ </strong>
340
+ <span className='Atlas_Notice_Text'>
341
+ Retained observations and anatomy remain available. New work
342
+ during the pause is not reconstructed.
343
+ </span>
344
+ </div>
345
+ )}
346
+ </section>
347
+ )}
348
+ <Spine model={model} />
349
+ <section
350
+ className='Atlas_Workspace Atlas_Focusable'
351
+ id='atlas-workspace'
352
+ tabIndex={-1}
353
+ aria-label='Explore system anatomy'
354
+ >
355
+ <div className='Atlas_Toolbar'>
356
+ <div className='Atlas_Search'>
357
+ <svg
358
+ className='Atlas_Search_Icon'
359
+ viewBox='0 0 20 20'
360
+ aria-hidden='true'
361
+ >
362
+ <circle cx='8' cy='8' r='5' />
363
+ <path d='m12 12 5 5' />
364
+ </svg>
365
+ <Field
366
+ className='Atlas_SearchField Atlas_Input'
367
+ elRef={search}
368
+ type='search'
369
+ aria-label='Search anatomy by name, package or description'
370
+ placeholder='Find a part, package or mechanism…'
371
+ value={state.filter}
372
+ autoComplete='off'
373
+ spellCheck={false}
374
+ onInput={(event: Event) => {
375
+ model.search((event.currentTarget as HTMLInputElement).value)
376
+ model.set({ listPage: 0 })
377
+ }}
378
+ />
379
+ {state.filter
380
+ ? (
381
+ <Button
382
+ className='Atlas_Button'
383
+ type='button'
384
+ mod='quiet'
385
+ aria-label='Clear anatomy search'
386
+ onClick={() => {
387
+ model.search('')
388
+ model.set({ listPage: 0 })
389
+ search.current?.focus()
390
+ }}
391
+ >
392
+ ×
393
+ </Button>
394
+ )
395
+ : <kbd className='Atlas_Key'>/</kbd>}
396
+ </div>
397
+ <label className='Atlas_Group'>
398
+ <span className='Atlas_VisuallyHidden'>Anatomy group</span>
399
+ <Select
400
+ className='Atlas_Select Atlas_Group_Select'
401
+ value={state.group || 'all'}
402
+ aria-label='Filter anatomy group'
403
+ onChange={(event: Event) =>
404
+ changeGroup((event.currentTarget as HTMLSelectElement).value)}
405
+ >
406
+ <option value='all'>All anatomy</option>
407
+ {sections.map((section) => (
408
+ <optgroup key={section.id} label={section.name}>
409
+ {section.groups.map((group) => (
410
+ <option key={group} value={group}>
411
+ {groupName(group)} ({counts.get(group) ?? 0})
412
+ {model.coverage[group] === false && ' · unobserved'}
413
+ </option>
414
+ ))}
415
+ </optgroup>
416
+ ))}
417
+ <option value='relations'>
418
+ Relationships ({model.edges.length})
419
+ </option>
420
+ </Select>
421
+ </label>
422
+ <div className='Atlas_Views' role='group' aria-label='Anatomy view'>
423
+ <Button
424
+ className='Atlas_Button Atlas_Views_Button'
425
+ type='button'
426
+ aria-pressed={state.view == 'map'}
427
+ onClick={map}
428
+ >
429
+ <span aria-hidden='true'>⌘</span> Map
430
+ </Button>
431
+ <Button
432
+ className='Atlas_Button Atlas_Views_Button'
433
+ type='button'
434
+ aria-pressed={state.view == 'list'}
435
+ onClick={() => model.set({ view: 'list' })}
436
+ >
437
+ <span aria-hidden='true'>☷</span> List
438
+ </Button>
439
+ </div>
440
+ <Button
441
+ type='button'
442
+ className='Atlas_Refresh Atlas_Button'
443
+ mod='quiet'
444
+ aria-label='Refresh host anatomy'
445
+ title='Refresh host anatomy'
446
+ onClick={() => void model.refresh()}
447
+ >
448
+ ↻
449
+ </Button>
450
+ </div>
451
+ <div className='Atlas_FilterSummary'>
452
+ <span>
453
+ {shown} matching{' '}
454
+ {state.group == 'relations' ? 'relationships' : 'parts'}
455
+ {state.filter && (
456
+ <>
457
+ for{' '}
458
+ <strong className='Atlas_FilterSummary_Strong'>
459
+ “{state.filter}”
460
+ </strong>
461
+ </>
462
+ )}
463
+ </span>
464
+ {unattempted > 0 && (
465
+ <span>{unattempted} unattempted facets ≠ absent</span>
466
+ )}
467
+ <Shortcuts />
468
+ </div>
469
+ <div className='Atlas_Anatomy'>
470
+ {state.view == 'list' || state.group == 'relations'
471
+ ? <AnatomyList model={model} />
472
+ : <Topology model={model} />}
473
+ <Detail model={model} />
474
+ </div>
475
+ </section>
476
+ <ActivityView model={model} />
477
+ <footer className='Atlas_Footer'>
478
+ <span>
479
+ <strong className='Atlas_Footer_Strong'>@yaks/visualize</strong>
480
+ {' '}
481
+ · Anatomy is declaration, not execution.
482
+ </span>
483
+ <span>
484
+ Actual observations only · no polling clock · bounded history
485
+ </span>
486
+ </footer>
487
+ </main>
488
+ </div>
489
+ )
490
+ }