@prestack/thread-ui 0.1.10 → 0.1.12

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 (209) hide show
  1. package/CHANGELOG.md +375 -0
  2. package/dist/ui/attach.js +6 -7
  3. package/dist/ui/compositions.d.ts +0 -8
  4. package/dist/ui/compositions.js +3 -166
  5. package/dist/ui/generators/routes.js +1 -0
  6. package/package.json +2 -2
  7. package/dist/ui/animations/anm_appear.ts +0 -13
  8. package/dist/ui/animations/anm_blur_in.ts +0 -19
  9. package/dist/ui/animations/anm_blur_out.ts +0 -18
  10. package/dist/ui/animations/anm_dismiss.ts +0 -18
  11. package/dist/ui/animations/anm_drop.ts +0 -19
  12. package/dist/ui/animations/anm_fall.ts +0 -18
  13. package/dist/ui/animations/anm_flash.ts +0 -18
  14. package/dist/ui/animations/anm_glow.ts +0 -16
  15. package/dist/ui/animations/anm_lift.ts +0 -16
  16. package/dist/ui/animations/anm_nudge.ts +0 -16
  17. package/dist/ui/animations/anm_pop_in.ts +0 -23
  18. package/dist/ui/animations/anm_pop_out.ts +0 -22
  19. package/dist/ui/animations/anm_press.ts +0 -12
  20. package/dist/ui/animations/anm_pulse.ts +0 -13
  21. package/dist/ui/animations/anm_rise.ts +0 -19
  22. package/dist/ui/animations/anm_shake.ts +0 -13
  23. package/dist/ui/animations/anm_slide_in_left.ts +0 -19
  24. package/dist/ui/animations/anm_slide_in_right.ts +0 -19
  25. package/dist/ui/animations/anm_slide_out_left.ts +0 -18
  26. package/dist/ui/animations/anm_slide_out_right.ts +0 -18
  27. package/dist/ui/animations/anm_spin.ts +0 -12
  28. package/dist/ui/animations/anm_swell.ts +0 -16
  29. package/dist/ui/animations/anm_wobble.ts +0 -24
  30. package/dist/ui/animations/anm_zoom_in.ts +0 -19
  31. package/dist/ui/animations/anm_zoom_out.ts +0 -18
  32. package/dist/ui/animations.ts +0 -308
  33. package/dist/ui/attach.ts +0 -553
  34. package/dist/ui/charts.tsx +0 -69
  35. package/dist/ui/checked.ts +0 -32
  36. package/dist/ui/collector.ts +0 -140
  37. package/dist/ui/compositions.ts +0 -613
  38. package/dist/ui/consent.ts +0 -55
  39. package/dist/ui/content.tsx +0 -27
  40. package/dist/ui/contrast.ts +0 -27
  41. package/dist/ui/controls.tsx +0 -25
  42. package/dist/ui/disclosure.tsx +0 -20
  43. package/dist/ui/dismiss-layer.ts +0 -87
  44. package/dist/ui/door.ts +0 -140
  45. package/dist/ui/drag.ts +0 -316
  46. package/dist/ui/elements/accordion.tsx +0 -47
  47. package/dist/ui/elements/accordion.works.ts +0 -66
  48. package/dist/ui/elements/aspect-ratio.tsx +0 -31
  49. package/dist/ui/elements/aspect-ratio.works.ts +0 -5
  50. package/dist/ui/elements/avatar.tsx +0 -34
  51. package/dist/ui/elements/avatar.works.ts +0 -16
  52. package/dist/ui/elements/badge.tsx +0 -33
  53. package/dist/ui/elements/badge.works.ts +0 -9
  54. package/dist/ui/elements/bars.tsx +0 -50
  55. package/dist/ui/elements/bars.works.ts +0 -29
  56. package/dist/ui/elements/box.tsx +0 -36
  57. package/dist/ui/elements/breadcrumb.tsx +0 -38
  58. package/dist/ui/elements/breadcrumb.works.ts +0 -24
  59. package/dist/ui/elements/button.tsx +0 -46
  60. package/dist/ui/elements/button.works.tsx +0 -52
  61. package/dist/ui/elements/column.tsx +0 -29
  62. package/dist/ui/elements/consent.tsx +0 -71
  63. package/dist/ui/elements/consent.works.tsx +0 -132
  64. package/dist/ui/elements/donut.tsx +0 -45
  65. package/dist/ui/elements/donut.works.ts +0 -42
  66. package/dist/ui/elements/each.tsx +0 -34
  67. package/dist/ui/elements/each.works.tsx +0 -82
  68. package/dist/ui/elements/empty.tsx +0 -33
  69. package/dist/ui/elements/field.tsx +0 -45
  70. package/dist/ui/elements/field.works.ts +0 -65
  71. package/dist/ui/elements/funnel.tsx +0 -50
  72. package/dist/ui/elements/funnel.works.ts +0 -37
  73. package/dist/ui/elements/gauge.tsx +0 -40
  74. package/dist/ui/elements/gauge.works.ts +0 -42
  75. package/dist/ui/elements/glyph.tsx +0 -30
  76. package/dist/ui/elements/glyph.works.tsx +0 -42
  77. package/dist/ui/elements/grid.tsx +0 -29
  78. package/dist/ui/elements/heatmap.tsx +0 -48
  79. package/dist/ui/elements/heatmap.works.ts +0 -24
  80. package/dist/ui/elements/hit-box.tsx +0 -47
  81. package/dist/ui/elements/hit-box.works.tsx +0 -576
  82. package/dist/ui/elements/image.tsx +0 -29
  83. package/dist/ui/elements/line-chart.tsx +0 -45
  84. package/dist/ui/elements/line-chart.works.ts +0 -41
  85. package/dist/ui/elements/link.tsx +0 -38
  86. package/dist/ui/elements/link.works.ts +0 -25
  87. package/dist/ui/elements/media.tsx +0 -57
  88. package/dist/ui/elements/menu.tsx +0 -51
  89. package/dist/ui/elements/menu.works.tsx +0 -154
  90. package/dist/ui/elements/money.tsx +0 -36
  91. package/dist/ui/elements/money.works.ts +0 -9
  92. package/dist/ui/elements/pagination.tsx +0 -39
  93. package/dist/ui/elements/pagination.works.ts +0 -20
  94. package/dist/ui/elements/progress.tsx +0 -34
  95. package/dist/ui/elements/progress.works.ts +0 -8
  96. package/dist/ui/elements/radio-group.tsx +0 -50
  97. package/dist/ui/elements/radio-group.works.ts +0 -33
  98. package/dist/ui/elements/row.tsx +0 -29
  99. package/dist/ui/elements/scatter.tsx +0 -42
  100. package/dist/ui/elements/scatter.works.ts +0 -38
  101. package/dist/ui/elements/select.tsx +0 -43
  102. package/dist/ui/elements/select.works.ts +0 -5
  103. package/dist/ui/elements/separator.tsx +0 -31
  104. package/dist/ui/elements/skeleton.tsx +0 -31
  105. package/dist/ui/elements/slider.tsx +0 -34
  106. package/dist/ui/elements/slider.works.ts +0 -5
  107. package/dist/ui/elements/sparkline.tsx +0 -37
  108. package/dist/ui/elements/sparkline.works.ts +0 -32
  109. package/dist/ui/elements/spinner.tsx +0 -33
  110. package/dist/ui/elements/stack.tsx +0 -29
  111. package/dist/ui/elements/stat.tsx +0 -36
  112. package/dist/ui/elements/stat.works.ts +0 -14
  113. package/dist/ui/elements/surface.tsx +0 -36
  114. package/dist/ui/elements/surface.works.ts +0 -9
  115. package/dist/ui/elements/table.tsx +0 -62
  116. package/dist/ui/elements/table.works.ts +0 -30
  117. package/dist/ui/elements/tabs.tsx +0 -47
  118. package/dist/ui/elements/tabs.works.ts +0 -84
  119. package/dist/ui/elements/text.tsx +0 -33
  120. package/dist/ui/elements/textarea.tsx +0 -38
  121. package/dist/ui/elements/textarea.works.ts +0 -5
  122. package/dist/ui/elements/time.tsx +0 -40
  123. package/dist/ui/elements/time.works.ts +0 -29
  124. package/dist/ui/elements/toggle.tsx +0 -34
  125. package/dist/ui/elements/toggle.works.ts +0 -5
  126. package/dist/ui/elements/tooltip.tsx +0 -40
  127. package/dist/ui/elements/tooltip.works.ts +0 -77
  128. package/dist/ui/elements/value.tsx +0 -38
  129. package/dist/ui/elements/value.works.ts +0 -9
  130. package/dist/ui/elements.ts +0 -127
  131. package/dist/ui/focus-scope.ts +0 -121
  132. package/dist/ui/fonts.ts +0 -355
  133. package/dist/ui/generators/dev.d.ts +0 -1
  134. package/dist/ui/generators/dev.js +0 -62
  135. package/dist/ui/generators/dev.ts +0 -75
  136. package/dist/ui/generators/elements.ts +0 -796
  137. package/dist/ui/generators/i18n.ts +0 -283
  138. package/dist/ui/generators/icons.ts +0 -207
  139. package/dist/ui/generators/react.ts +0 -267
  140. package/dist/ui/generators/routes.ts +0 -847
  141. package/dist/ui/generators/show.ts +0 -261
  142. package/dist/ui/generators/styles.ts +0 -677
  143. package/dist/ui/generators/variants.ts +0 -196
  144. package/dist/ui/i18n/catalogs/en.ts +0 -191
  145. package/dist/ui/i18n/format.ts +0 -221
  146. package/dist/ui/i18n/locales.ts +0 -33
  147. package/dist/ui/i18n/parse.ts +0 -315
  148. package/dist/ui/i18n/translator.ts +0 -31
  149. package/dist/ui/i18n/types.ts +0 -96
  150. package/dist/ui/icons.ts +0 -331
  151. package/dist/ui/islands/map.ts +0 -58
  152. package/dist/ui/localizations.ts +0 -75
  153. package/dist/ui/material.ts +0 -236
  154. package/dist/ui/materials/mat_bordered.ts +0 -13
  155. package/dist/ui/materials/mat_ceramic.ts +0 -13
  156. package/dist/ui/materials/mat_clay.ts +0 -13
  157. package/dist/ui/materials/mat_elevated.ts +0 -24
  158. package/dist/ui/materials/mat_flat.ts +0 -34
  159. package/dist/ui/materials/mat_glass.ts +0 -20
  160. package/dist/ui/materials/mat_lit.ts +0 -13
  161. package/dist/ui/materials/mat_moulded.ts +0 -11
  162. package/dist/ui/materials.ts +0 -197
  163. package/dist/ui/modes.ts +0 -44
  164. package/dist/ui/navigation.tsx +0 -29
  165. package/dist/ui/positioning.ts +0 -90
  166. package/dist/ui/presented.tsx +0 -119
  167. package/dist/ui/provider.tsx +0 -184
  168. package/dist/ui/render-loop.ts +0 -133
  169. package/dist/ui/roving-focus.ts +0 -161
  170. package/dist/ui/screens.ts +0 -141
  171. package/dist/ui/scroll-lock.ts +0 -28
  172. package/dist/ui/series.ts +0 -97
  173. package/dist/ui/signals.ts +0 -386
  174. package/dist/ui/styleguide.ts +0 -231
  175. package/dist/ui/styleguides.ts +0 -374
  176. package/dist/ui/themes.ts +0 -22
  177. package/dist/ui/token.ts +0 -78
  178. package/dist/ui/tokens/shadow.ts +0 -25
  179. package/dist/ui/tokens.ts +0 -234
  180. package/dist/ui/validators.ts +0 -232
  181. package/dist/ui/variant.ts +0 -349
  182. package/dist/ui/variants/var_avatar-round.ts +0 -14
  183. package/dist/ui/variants/var_bubble-me.ts +0 -14
  184. package/dist/ui/variants/var_bubble-them.ts +0 -13
  185. package/dist/ui/variants/var_button-border.ts +0 -76
  186. package/dist/ui/variants/var_button-cta.ts +0 -76
  187. package/dist/ui/variants/var_button-destructive-ghost.ts +0 -72
  188. package/dist/ui/variants/var_button-destructive.ts +0 -76
  189. package/dist/ui/variants/var_button-fill.ts +0 -76
  190. package/dist/ui/variants/var_button-ghost.ts +0 -72
  191. package/dist/ui/variants/var_button-glass.ts +0 -55
  192. package/dist/ui/variants/var_button-normal.ts +0 -76
  193. package/dist/ui/variants/var_button-quiet.ts +0 -74
  194. package/dist/ui/variants/var_card.ts +0 -17
  195. package/dist/ui/variants/var_chip.ts +0 -13
  196. package/dist/ui/variants/var_choice.ts +0 -15
  197. package/dist/ui/variants/var_framed.ts +0 -10
  198. package/dist/ui/variants/var_glyph-plain.ts +0 -11
  199. package/dist/ui/variants/var_input.ts +0 -43
  200. package/dist/ui/variants/var_link-inline.ts +0 -29
  201. package/dist/ui/variants/var_list-row.ts +0 -34
  202. package/dist/ui/variants/var_rule.ts +0 -10
  203. package/dist/ui/variants/var_skeleton-block.ts +0 -12
  204. package/dist/ui/variants/var_spinner-turning.ts +0 -12
  205. package/dist/ui/variants/var_stat-tile.ts +0 -13
  206. package/dist/ui/variants/var_tab-bar.ts +0 -15
  207. package/dist/ui/variants/var_tap-target.ts +0 -25
  208. package/dist/ui/variants.ts +0 -64
  209. package/dist/ui/wrappers.tsx +0 -429
@@ -1,64 +0,0 @@
1
- import type { Threaded } from '@prestack/thread/core/thread'
2
-
3
- interface Worn extends Threaded {
4
- readonly section: string
5
- readonly wears: readonly string[]
6
- }
7
-
8
- interface Catalogue extends Threaded {
9
- readonly files: string
10
- readonly declares: readonly Worn[]
11
- }
12
-
13
- const at = (id: string): string => `thread/ui/variants/var_${id}.ts`
14
-
15
- export const VARIANTS = {
16
- id: 'variant',
17
- at: 'thread/ui/variants.ts',
18
- files: 'ui/var_*.ts',
19
- describes:
20
- 'How a thing looks: a material plus the style guide values it names directly, never raw ones, and how that look changes under a state. It says nothing about type, because typography belongs to the role the wording states; what is left here is the look of the box and the colour of what sits in it. Each row names a file prefixed `var_`, and that file is the variant: what it looks like, what it looks like under a state, and which states it reacts to. The row states which elements accept it, and it is worn as the tag, so a variant `button-fill` is written `<Button.buttonFill>` and an element nothing declares is refused. A state is the set of signals holding at once, and two states that can both hold and both set one property must have their combination declared, or which one wins is an accident of file order. An app adds its own to this same list, and a row that goes missing breaks the build, because what the framework offers is not an app’s to withdraw.',
21
- version: 1,
22
- cites: [
23
- {
24
- on: '2026-08-24',
25
- said: 'Variants define lots of things. Including how they look in different states. Including how they look in multiple states at once. (hover, pressed) is one variant that covers both hover and pressed, so they look the same when they are simultaneous. (hover) (pressed) (hover, pressed) however have different states for the three situations.',
26
- },
27
- {
28
- on: '2026-08-25',
29
- said: 'Variants basically say: This is how I look. These are the elements that accept me. These are my behaviours under different states. These are the states I can react to.',
30
- },
31
- {
32
- on: '2026-08-28',
33
- said: 'fonts.ts as SSOT for everything related to fonts and easy to change fonts throughout the app like tokens, like....the exact same reason for existing that tokens+styleguide have is the same reason we have fonts.ts',
34
- },
35
- ],
36
- declares: [
37
- { id: 'card', section: 'surface', at: at('card'), wears: ['Accordion', 'Bars', 'Box', 'Donut', 'Empty', 'Funnel', 'Heatmap', 'LineChart', 'Media', 'Menu', 'Scatter', 'Sparkline', 'Surface', 'Table', 'Tooltip'], describes: 'A surface holding other content, and the shape every unregistered variant falls back to.' },
38
- { id: 'list-row', section: 'surface', at: at('list-row'), wears: ['Box'], describes: 'One row of a list — square, quiet, and separated by its neighbours rather than by a shadow.' },
39
- { id: 'framed', section: 'surface', at: at('framed'), wears: ['Image', 'Media', 'AspectRatio'], describes: 'A picture given the same corners as a panel, on a sunken ground so the gap before it loads is not a white hole.' },
40
- { id: 'bubble-them', section: 'surface', at: at('bubble-them'), wears: ['Box'], describes: 'A message somebody else sent. The plain half of a conversation.' },
41
- { id: 'bubble-me', section: 'surface', at: at('bubble-me'), wears: ['Box'], describes: 'A message the current person sent. Takes the accent, which is how a conversation reads as two voices without a second colour role.' },
42
- { id: 'button-fill', section: 'button', at: at('button-fill'), wears: ['Button'], describes: 'The one action a screen is asking for. The accent behind it, and the only button on a screen that should carry it.' },
43
- { id: 'button-normal', section: 'button', at: at('button-normal'), wears: ['Button'], describes: 'The ordinary button. A surface with a hairline round it — pressable, and asking for nothing in particular.' },
44
- { id: 'button-ghost', section: 'button', at: at('button-ghost'), wears: ['Button'], describes: 'Wording that acts. No ground and no line until a pointer is over it, which is what keeps a row of them from reading as a wall of boxes.' },
45
- { id: 'button-border', section: 'button', at: at('button-border'), wears: ['Button'], describes: 'An action offered beside a filled one. The accent as an edge rather than a ground, so the shape says pressable and the colour says not this one.' },
46
- { id: 'button-destructive', section: 'button', at: at('button-destructive'), wears: ['Button'], describes: 'Something that cannot be undone. The same shape as the asking button, in the colour reserved for consequence.' },
47
- { id: 'button-destructive-ghost', section: 'button', at: at('button-destructive-ghost'), wears: ['Button'], describes: 'A destructive action that is not the point of the screen — delete, sitting quietly at the end of a menu. Carries the negative as ink and gains a ground only under a pointer.' },
48
- { id: 'button-cta', section: 'button', at: at('button-cta'), wears: ['Button'], describes: 'The one thing a landing screen exists to get pressed. Taller than every other button and set in running type rather than label type, which is what makes it read from across the page.' },
49
- { id: 'button-quiet', section: 'button', at: at('button-quiet'), wears: ['Button'], describes: 'An action that is available and is not being suggested — cancel, skip, dismiss. Ink that supports rather than states, and a smaller symbol beside it.' },
50
- { id: 'button-glass', section: 'button', at: at('button-glass'), wears: ['Button'], describes: 'A button over a picture or a video, where a solid fill would hide what it is sitting on. What is behind shows through, softened.' },
51
- { id: 'input', section: 'entry', at: at('input'), wears: ['Field', 'Select', 'Slider', 'Textarea', 'Toggle'], describes: 'Anything a person types into. Tighter vertical room than a surface, so the text baseline sits where a label expects it.' },
52
- { id: 'choice', section: 'entry', at: at('choice'), wears: ['RadioGroup'], describes: 'A set of options laid out to be chosen between. A group is not a control — it cannot be focused or invalid itself, only the radios inside it can — so it takes arrangement and a ground and states nothing it cannot be in.' },
53
- { id: 'tab-bar', section: 'navigation', at: at('tab-bar'), wears: ['Breadcrumb', 'Pagination', 'Tabs'], describes: 'The strip of destinations along one edge. Rounder and less padded than a surface, because it holds pressable things rather than content.' },
54
- { id: 'link-inline', section: 'navigation', at: at('link-inline'), wears: ['Link'], describes: 'Wording that takes you somewhere. Carries the accent so it reads as reachable without an underline, and draws a real ring when a keyboard reaches it.' },
55
- { id: 'chip', section: 'marker', at: at('chip'), wears: ['Badge'], describes: 'A small token standing for a value. The tightest room in the set, and pill-shaped like the buttons.' },
56
- { id: 'glyph-plain', section: 'marker', at: at('glyph-plain'), wears: ['Glyph'], describes: 'A pictogram at the size most controls use, drawn in the ink of whatever it sits beside.' },
57
- { id: 'avatar-round', section: 'marker', at: at('avatar-round'), wears: ['Avatar'], describes: 'A person, standing for themselves. Fully round, sunken so it reads as a well rather than a card, and sized to be recognised at a glance.' },
58
- { id: 'rule', section: 'marker', at: at('rule'), wears: ['Separator'], describes: 'The line between two things. The thinnest a screen can draw, in the colour that separates without asking to be seen.' },
59
- { id: 'skeleton-block', section: 'marker', at: at('skeleton-block'), wears: ['Skeleton'], describes: 'The shape of something that has not arrived. Sunken and breathing, which is what says waiting rather than empty.' },
60
- { id: 'spinner-turning', section: 'marker', at: at('spinner-turning'), wears: ['Spinner'], describes: 'Work with no measurable end. Turns without stopping, in the accent, so it reads as the app doing something rather than the app stuck.' },
61
- { id: 'stat-tile', section: 'figure', at: at('stat-tile'), wears: ['Gauge', 'Progress', 'Stat'], describes: 'A single figure given room to be read at a glance, so its type role is the display one rather than body.' },
62
- { id: 'tap-target', section: 'gesture', at: at('tap-target'), wears: ['HitBox'], describes: 'Anything a finger acts on directly rather than through a control — the one variant a hit box wears. It is where a tap, a press and a carry are answered, because a hit box is the only thing that raises those and nothing accepted it before.' },
63
- ],
64
- } as const satisfies Catalogue
@@ -1,429 +0,0 @@
1
- 'use client'
2
-
3
- import { createContext, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
4
-
5
- import type { Collector } from './collector.ts'
6
- import type { ArrangementElement, Dispatching, VariantsFor, Wearing } from './checked.ts'
7
-
8
- import { PRESENTATION_BEHAVIOUR, type Clock, type Presentation, type Surface, type Ticker } from './door.ts'
9
- import { holds as declared, selectorOf } from './signals.ts'
10
-
11
- declare module 'react' {
12
- interface HTMLAttributes<T> {
13
- readonly at?: string
14
- }
15
- interface SVGAttributes<T> {
16
- readonly at?: string
17
- }
18
- }
19
- import { Presented } from './presented.tsx'
20
- import { useRenderLoopDetector } from './render-loop.ts'
21
-
22
- export interface Appearance {
23
- readonly mode: 'light' | 'dark'
24
-
25
- readonly reduceMotion: boolean
26
- }
27
-
28
- export interface UiConfig {
29
-
30
- readonly palette: { readonly accent: string; readonly surface: string }
31
-
32
- readonly translate: (key: string, params?: Readonly<Record<string, unknown>>) => string
33
- readonly appearance: Appearance
34
- readonly clock: Clock
35
-
36
- readonly ticker?: Ticker
37
-
38
- readonly now?: () => number
39
-
40
- readonly edgeScroll?: { readonly band?: number; readonly speed?: number }
41
-
42
- readonly collector?: Collector
43
-
44
- readonly platform?: string
45
-
46
- readonly dispatch?: (name: keyof Dispatching, input?: Readonly<Record<string, unknown>>) => Promise<unknown>
47
-
48
- readonly navigateTo?: (screen: string) => void
49
-
50
- readonly actor?: { readonly id: string | null; readonly roles: readonly string[]; readonly entitlements: readonly string[] }
51
-
52
- readonly asking?: readonly { readonly id: string; readonly selector: string }[]
53
-
54
- readonly holding?: readonly string[]
55
- }
56
-
57
- export const UiContext = createContext<UiConfig | null>(null)
58
-
59
- const MISSING =
60
- 'No UI context. Every element resolves its look, its text and its clock through the door, so it ' +
61
- 'must render inside <UiProvider>. An element rendering without one would silently have no theme ' +
62
- 'and no locale — which looks like a styling bug and is a wiring bug.'
63
-
64
- export function UiProvider({ config, children }: { config: UiConfig; children: ReactNode }): ReactNode {
65
- return <UiContext.Provider value={config}>{children}</UiContext.Provider>
66
- }
67
-
68
- export function useUi(): UiConfig {
69
- const config = useContext(UiContext)
70
- if (config === null) throw new Error(MISSING)
71
- return config
72
- }
73
-
74
- export interface SurfaceRequest {
75
-
76
- readonly className?: string
77
-
78
- readonly invokes?: { readonly dispatch?: keyof Dispatching; readonly input?: Readonly<Record<string, unknown>>; readonly on?: 'press' | 'shown' }
79
-
80
- readonly holds?: readonly ((typeof declared)[number]['id'] | (string & {}))[]
81
-
82
- readonly raises?: readonly ((typeof declared)[number]['id'] | (string & {}))[]
83
-
84
- readonly animates?: boolean
85
-
86
- readonly measures?: Readonly<Record<string, string | number>>
87
- }
88
-
89
- export function useSurface(request: SurfaceRequest = {}): Surface {
90
- const { translate, appearance, clock, asking, holding, dispatch: run } = useUi()
91
- const [t, setT] = useState(0)
92
-
93
- const animates = request.animates === true && !appearance.reduceMotion
94
-
95
- useEffect(() => {
96
- if (!animates) return undefined
97
- return clock.subscribe(setT)
98
- }, [animates, clock])
99
-
100
- const gated = (request.raises ?? []).filter((one) => (holding ?? []).includes(one))
101
- const holds = gated.length === 0 ? (request.holds ?? []) : [...new Set([...(request.holds ?? []), ...gated])]
102
-
103
- const held = new Set<string>(holds)
104
- const raised = (signal: string): boolean => held.has(signal)
105
-
106
- const a11y: Record<string, string | boolean | number> = {}
107
- if (raised('loading') || raised('pending')) a11y['aria-busy'] = true
108
-
109
- const marks: Record<string, boolean> = {}
110
- for (const one of holds) {
111
- const selector = selectorOf(one) ?? (asking ?? []).find((row) => row.id === one)?.selector
112
- if (selector === undefined || !selector.startsWith('[data-')) continue
113
- marks[selector.slice(1, -1)] = true
114
- }
115
-
116
- const [arriving, setArriving] = useState(true)
117
- if (arriving) marks['data-arriving'] = true
118
-
119
- const began = useRef(false)
120
- useEffect(() => {
121
- if (!arriving) return undefined
122
- let live = true
123
- const outer = requestAnimationFrame(() => {
124
- requestAnimationFrame(() => {
125
- if (live && !began.current) setArriving(false)
126
- })
127
- })
128
- return () => {
129
- live = false
130
- cancelAnimationFrame(outer)
131
- }
132
- }, [arriving])
133
-
134
- const measures: Record<string, string | number> = {}
135
- for (const [name, value] of Object.entries(request.measures ?? {})) measures[`--${name}`] = value
136
-
137
- const asked = request.invokes
138
- const named: keyof Dispatching | undefined = asked?.dispatch
139
- const carried = asked?.input
140
- const when = asked?.on ?? 'press'
141
-
142
- useEffect(() => {
143
- if (named === undefined || when !== 'shown') return
144
- if (asking === undefined) return
145
- void run?.(named, carried)
146
- }, [named, when, carried, run, asking])
147
-
148
- const invokes: Record<string, unknown> = {
149
-
150
- onAnimationStart: (event: { readonly target: unknown; readonly currentTarget: unknown }) => {
151
- if (event.target !== event.currentTarget) return
152
- began.current = true
153
- },
154
- onAnimationEnd: (event: { readonly target: unknown; readonly currentTarget: unknown }) => {
155
- if (event.target !== event.currentTarget) return
156
- setArriving(false)
157
- },
158
- ...(named === undefined || when === 'shown'
159
- ? {}
160
- : {
161
- onClick: () => {
162
- if (run === undefined) throw new Error(`\`${named}\` cannot be invoked from here — no dispatch is wired`)
163
- void run(named, carried)
164
- },
165
- }),
166
- }
167
-
168
- return {
169
- ...(request.className === undefined ? {} : { className: request.className }),
170
- holds,
171
- marks,
172
- measures,
173
- invokes,
174
-
175
- marked: raised,
176
- text: translate,
177
- a11y,
178
- t: animates ? t : 0,
179
- }
180
- }
181
-
182
- export type Press =
183
- | { readonly dispatch: keyof Dispatching; readonly input?: Readonly<Record<string, unknown>>; readonly navigateTo?: never; readonly onPress?: never }
184
- | { readonly navigateTo: string; readonly dispatch?: never; readonly input?: never; readonly onPress?: never }
185
- | { readonly onPress: () => void; readonly dispatch?: never; readonly navigateTo?: never; readonly input?: never }
186
- | { readonly dispatch?: never; readonly navigateTo?: never; readonly input?: never; readonly onPress?: never }
187
-
188
- export function pressOf(props: {
189
- readonly dispatch?: keyof Dispatching
190
- readonly input?: Readonly<Record<string, unknown>>
191
- readonly navigateTo?: string
192
- readonly onPress?: () => void
193
- }): Press {
194
- if (props.onPress !== undefined) return { onPress: props.onPress }
195
- if (props.navigateTo !== undefined) return { navigateTo: props.navigateTo }
196
- if (props.dispatch === undefined) return {}
197
- return props.input === undefined ? { dispatch: props.dispatch } : { dispatch: props.dispatch, input: props.input }
198
- }
199
-
200
- export interface PressOrigin {
201
-
202
- readonly element: string
203
-
204
- readonly name?: string
205
- }
206
-
207
- const NO_DISPATCH =
208
- 'No dispatch. An operation runs one way here and that way is `dispatch`, handed the name, so a thing that names ' +
209
- 'one must render inside a <UiProvider> whose config supplies it. Without it the press has nowhere to go, which ' +
210
- 'reads as a dead control and is a wiring gap.'
211
-
212
- const NO_NAVIGATE =
213
- 'No navigateTo. Moving between screens is its own thing, supplied beside dispatch rather than through it, so a ' +
214
- 'thing that names a screen must render inside a <UiProvider> whose config supplies it.'
215
-
216
- export function pressing(ui: ReturnType<typeof useUi>, press: Press, origin?: PressOrigin): (() => void) | undefined {
217
- const { collector, dispatch, navigateTo } = ui
218
- const asked: keyof Dispatching | undefined = press.dispatch
219
- const carried = press.input
220
-
221
- const reported = (run: () => void): (() => void) => {
222
- if (collector === undefined || origin === undefined) return run
223
- return () => {
224
- collector.record({
225
- property: 'interaction',
226
- element: origin.element,
227
- ...(origin.name === undefined ? {} : { name: origin.name }),
228
- action: 'pressed',
229
- })
230
- run()
231
- }
232
- }
233
-
234
- if (press.onPress !== undefined) return reported(press.onPress)
235
-
236
- if (press.navigateTo !== undefined) {
237
- const where = press.navigateTo
238
- return reported(() => {
239
- if (navigateTo === undefined) throw new Error(NO_NAVIGATE)
240
- navigateTo(where)
241
- })
242
- }
243
-
244
- if (asked !== undefined) {
245
- return reported(() => {
246
- if (dispatch === undefined) throw new Error(NO_DISPATCH)
247
- void dispatch(asked, carried)
248
- })
249
- }
250
-
251
- return undefined
252
- }
253
-
254
- export function usePress(press: Press, origin?: PressOrigin): (() => void) | undefined {
255
- return pressing(useUi(), press, origin)
256
- }
257
-
258
- export function useVisibility(active: boolean): (node: HTMLElement | null) => void {
259
- const { clock } = useUi()
260
- return useMemo(() => {
261
- return (node: HTMLElement | null): void => {
262
- if (!active || node === null || typeof IntersectionObserver !== 'function') return
263
-
264
- const observer = new IntersectionObserver(([entry]) => {
265
- clock.setVisible(entry?.isIntersecting ?? true)
266
- })
267
- observer.observe(node)
268
- }
269
- }, [active, clock])
270
- }
271
-
272
- export interface ScreenOptions {
273
- readonly as?: Presentation
274
- readonly views?: readonly (keyof Dispatching)[]
275
-
276
- readonly unreachable?: boolean
277
- }
278
-
279
- type Component<P> = (props: P) => ReactNode
280
-
281
- export type ElementBody<P> = (props: P, className?: string) => ReactNode
282
-
283
- function wearing(held: string | undefined, added: string | undefined): string | undefined {
284
- if (added === undefined) return held
285
- return held === undefined || held === '' ? added : `${held} ${added}`
286
- }
287
-
288
- type Members<N extends string, P> = {
289
- readonly [K in
290
- | VariantsFor<N>
291
- | { [W in keyof Wearing]: N extends Wearing[W] ? W : never }[keyof Wearing]]: Component<
292
- P & { readonly at?: string }
293
- >
294
- }
295
-
296
- export type Element<N extends string, P> = [keyof Members<N, P>] extends [never]
297
- ? Component<P & { readonly at?: string }>
298
- : N extends ArrangementElement
299
- ? Component<P & { readonly at?: string }> & Members<N, P>
300
- : Members<N, P>
301
-
302
- export function element<N extends string, P>(
303
- name: N,
304
- fn: ElementBody<P>,
305
- own: string,
306
- wears: Readonly<Record<string, string>>,
307
- ): Element<N, P> {
308
-
309
- const Made = (props: P & { readonly className?: string }): ReactNode => fn(props, wearing(own, props.className))
310
- named(Made, name)
311
-
312
- for (const [member, dressed] of Object.entries(wears)) {
313
- const worn = wearing(own, dressed)
314
- const Worn = (props: P & { readonly className?: string }): ReactNode =>
315
- fn(props, wearing(worn, props.className))
316
- named(Worn, `${name}.${member}`)
317
- Object.defineProperty(Made, member, { value: Worn, enumerable: false, configurable: true })
318
- }
319
-
320
- return Made as unknown as Element<N, P>
321
- }
322
-
323
- function named(component: unknown, value: string): void {
324
- Object.defineProperty(component, 'displayName', { value, enumerable: false, configurable: true })
325
- }
326
-
327
- export function composition<P>(
328
- own: string,
329
- fn: (props: P) => ReactNode,
330
- ): Component<P & { readonly at?: string; readonly className?: string }> {
331
-
332
- const Made = (props: P & { readonly className?: string }): ReactNode => (
333
- <div className={wearing(own, props.className)}>{fn(props)}</div>
334
- )
335
- named(Made, own)
336
- return Made
337
- }
338
-
339
- export interface ScreenControls {
340
-
341
- readonly open?: boolean
342
- readonly onDismiss?: () => void
343
-
344
- readonly at?: string
345
- }
346
-
347
- const ViewsContext = createContext<Readonly<Record<string, unknown>> | null>(null)
348
-
349
- const NO_SCREEN =
350
- 'No screen. A view is read for the screen that binds it, so anything reading one renders inside a screen, ' +
351
- 'and a body outside every screen has nothing to read from.'
352
-
353
- export function useView<T>(id: string): T | undefined {
354
- const held = useContext(ViewsContext)
355
- if (held === null) throw new Error(NO_SCREEN)
356
- const named = Object.keys(held)
357
- if (!named.includes(id)) {
358
- throw new Error(
359
- `"${id}" is not a view this screen shows. A screen states every read it binds in its own views list, ` +
360
- `and this one states ${named.length === 0 ? 'none' : named.join(', ')}. Name it there — nothing fetches on its own.`,
361
- )
362
- }
363
- return held[id] as T | undefined
364
- }
365
-
366
- function useViews(views: readonly (keyof Dispatching)[]): Readonly<Record<string, unknown>> {
367
- const { dispatch } = useUi()
368
- const named = views.join(' ')
369
- const [held, setHeld] = useState<Readonly<Record<string, unknown>>>({})
370
- const [wrong, setWrong] = useState<Error | undefined>(undefined)
371
-
372
- useEffect(() => {
373
- if (views.length === 0) return undefined
374
- if (dispatch === undefined) throw new Error(NO_DISPATCH)
375
- let live = true
376
- void Promise.all(views.map(async (one: keyof Dispatching) => [one, await dispatch(one)] as const))
377
- .then((all) => {
378
- if (live) setHeld(Object.fromEntries(all))
379
- })
380
- .catch((thrown: unknown) => {
381
- if (live) setWrong(thrown instanceof Error ? thrown : new Error(String(thrown)))
382
- })
383
- return () => {
384
- live = false
385
- }
386
- }, [named, dispatch])
387
-
388
- const all = useMemo(() => {
389
- const found: Record<string, unknown> = {}
390
- for (const one of views) found[one] = held[one]
391
- return found
392
- }, [named, held])
393
-
394
- if (wrong !== undefined) throw wrong
395
- return all
396
- }
397
-
398
- export function screen<P>(own: string, options: ScreenOptions, fn: Component<P>): Component<P & ScreenControls> {
399
- const Screen = (props: P & ScreenControls): ReactNode => {
400
-
401
- useRenderLoopDetector(own, props as Record<string, unknown>)
402
-
403
- const shown = useViews(options.views ?? [])
404
-
405
- const laid = (
406
- <ViewsContext.Provider value={shown}>
407
- <div className={own}>{fn(props)}</div>
408
- </ViewsContext.Provider>
409
- )
410
-
411
- if (options.as === undefined) return laid
412
-
413
- return (
414
- <Presented
415
- presentation={options.as}
416
- {...(props.open === undefined ? {} : { open: props.open })}
417
- {...(props.onDismiss === undefined ? {} : { onDismiss: props.onDismiss })}
418
- >
419
- {laid}
420
- </Presented>
421
- )
422
- }
423
- Screen.displayName = own
424
- return Screen
425
- }
426
-
427
- export function behaviourOf(presentation: Presentation): (typeof PRESENTATION_BEHAVIOUR)[Presentation] {
428
- return PRESENTATION_BEHAVIOUR[presentation]
429
- }