@prestack/thread-ui 0.1.9 → 0.1.11

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 (210) hide show
  1. package/CHANGELOG.md +366 -0
  2. package/dist/ui/attach.js +6 -7
  3. package/dist/ui/compositions.d.ts +0 -2
  4. package/dist/ui/compositions.js +2 -112
  5. package/dist/ui/generators/routes.js +1 -0
  6. package/dist/ui/variant.d.ts +1 -3
  7. package/package.json +2 -2
  8. package/dist/ui/animations/anm_appear.ts +0 -13
  9. package/dist/ui/animations/anm_blur_in.ts +0 -19
  10. package/dist/ui/animations/anm_blur_out.ts +0 -18
  11. package/dist/ui/animations/anm_dismiss.ts +0 -18
  12. package/dist/ui/animations/anm_drop.ts +0 -19
  13. package/dist/ui/animations/anm_fall.ts +0 -18
  14. package/dist/ui/animations/anm_flash.ts +0 -18
  15. package/dist/ui/animations/anm_glow.ts +0 -16
  16. package/dist/ui/animations/anm_lift.ts +0 -16
  17. package/dist/ui/animations/anm_nudge.ts +0 -16
  18. package/dist/ui/animations/anm_pop_in.ts +0 -23
  19. package/dist/ui/animations/anm_pop_out.ts +0 -22
  20. package/dist/ui/animations/anm_press.ts +0 -12
  21. package/dist/ui/animations/anm_pulse.ts +0 -13
  22. package/dist/ui/animations/anm_rise.ts +0 -19
  23. package/dist/ui/animations/anm_shake.ts +0 -13
  24. package/dist/ui/animations/anm_slide_in_left.ts +0 -19
  25. package/dist/ui/animations/anm_slide_in_right.ts +0 -19
  26. package/dist/ui/animations/anm_slide_out_left.ts +0 -18
  27. package/dist/ui/animations/anm_slide_out_right.ts +0 -18
  28. package/dist/ui/animations/anm_spin.ts +0 -12
  29. package/dist/ui/animations/anm_swell.ts +0 -16
  30. package/dist/ui/animations/anm_wobble.ts +0 -24
  31. package/dist/ui/animations/anm_zoom_in.ts +0 -19
  32. package/dist/ui/animations/anm_zoom_out.ts +0 -18
  33. package/dist/ui/animations.ts +0 -308
  34. package/dist/ui/attach.ts +0 -553
  35. package/dist/ui/charts.tsx +0 -69
  36. package/dist/ui/checked.ts +0 -32
  37. package/dist/ui/collector.ts +0 -140
  38. package/dist/ui/compositions.ts +0 -555
  39. package/dist/ui/consent.ts +0 -55
  40. package/dist/ui/content.tsx +0 -27
  41. package/dist/ui/contrast.ts +0 -27
  42. package/dist/ui/controls.tsx +0 -25
  43. package/dist/ui/disclosure.tsx +0 -20
  44. package/dist/ui/dismiss-layer.ts +0 -87
  45. package/dist/ui/door.ts +0 -140
  46. package/dist/ui/drag.ts +0 -316
  47. package/dist/ui/elements/accordion.tsx +0 -47
  48. package/dist/ui/elements/accordion.works.ts +0 -66
  49. package/dist/ui/elements/aspect-ratio.tsx +0 -31
  50. package/dist/ui/elements/aspect-ratio.works.ts +0 -5
  51. package/dist/ui/elements/avatar.tsx +0 -34
  52. package/dist/ui/elements/avatar.works.ts +0 -16
  53. package/dist/ui/elements/badge.tsx +0 -33
  54. package/dist/ui/elements/badge.works.ts +0 -9
  55. package/dist/ui/elements/bars.tsx +0 -50
  56. package/dist/ui/elements/bars.works.ts +0 -29
  57. package/dist/ui/elements/box.tsx +0 -36
  58. package/dist/ui/elements/breadcrumb.tsx +0 -38
  59. package/dist/ui/elements/breadcrumb.works.ts +0 -24
  60. package/dist/ui/elements/button.tsx +0 -46
  61. package/dist/ui/elements/button.works.tsx +0 -52
  62. package/dist/ui/elements/column.tsx +0 -29
  63. package/dist/ui/elements/consent.tsx +0 -71
  64. package/dist/ui/elements/consent.works.tsx +0 -132
  65. package/dist/ui/elements/donut.tsx +0 -45
  66. package/dist/ui/elements/donut.works.ts +0 -42
  67. package/dist/ui/elements/each.tsx +0 -34
  68. package/dist/ui/elements/each.works.tsx +0 -82
  69. package/dist/ui/elements/empty.tsx +0 -33
  70. package/dist/ui/elements/field.tsx +0 -45
  71. package/dist/ui/elements/field.works.ts +0 -65
  72. package/dist/ui/elements/funnel.tsx +0 -50
  73. package/dist/ui/elements/funnel.works.ts +0 -37
  74. package/dist/ui/elements/gauge.tsx +0 -40
  75. package/dist/ui/elements/gauge.works.ts +0 -42
  76. package/dist/ui/elements/glyph.tsx +0 -30
  77. package/dist/ui/elements/glyph.works.tsx +0 -42
  78. package/dist/ui/elements/grid.tsx +0 -29
  79. package/dist/ui/elements/heatmap.tsx +0 -48
  80. package/dist/ui/elements/heatmap.works.ts +0 -24
  81. package/dist/ui/elements/hit-box.tsx +0 -47
  82. package/dist/ui/elements/hit-box.works.tsx +0 -576
  83. package/dist/ui/elements/image.tsx +0 -29
  84. package/dist/ui/elements/line-chart.tsx +0 -45
  85. package/dist/ui/elements/line-chart.works.ts +0 -41
  86. package/dist/ui/elements/link.tsx +0 -38
  87. package/dist/ui/elements/link.works.ts +0 -25
  88. package/dist/ui/elements/media.tsx +0 -57
  89. package/dist/ui/elements/menu.tsx +0 -51
  90. package/dist/ui/elements/menu.works.tsx +0 -154
  91. package/dist/ui/elements/money.tsx +0 -36
  92. package/dist/ui/elements/money.works.ts +0 -9
  93. package/dist/ui/elements/pagination.tsx +0 -39
  94. package/dist/ui/elements/pagination.works.ts +0 -20
  95. package/dist/ui/elements/progress.tsx +0 -34
  96. package/dist/ui/elements/progress.works.ts +0 -8
  97. package/dist/ui/elements/radio-group.tsx +0 -50
  98. package/dist/ui/elements/radio-group.works.ts +0 -33
  99. package/dist/ui/elements/row.tsx +0 -29
  100. package/dist/ui/elements/scatter.tsx +0 -42
  101. package/dist/ui/elements/scatter.works.ts +0 -38
  102. package/dist/ui/elements/select.tsx +0 -43
  103. package/dist/ui/elements/select.works.ts +0 -5
  104. package/dist/ui/elements/separator.tsx +0 -31
  105. package/dist/ui/elements/skeleton.tsx +0 -31
  106. package/dist/ui/elements/slider.tsx +0 -34
  107. package/dist/ui/elements/slider.works.ts +0 -5
  108. package/dist/ui/elements/sparkline.tsx +0 -37
  109. package/dist/ui/elements/sparkline.works.ts +0 -32
  110. package/dist/ui/elements/spinner.tsx +0 -33
  111. package/dist/ui/elements/stack.tsx +0 -29
  112. package/dist/ui/elements/stat.tsx +0 -36
  113. package/dist/ui/elements/stat.works.ts +0 -14
  114. package/dist/ui/elements/surface.tsx +0 -36
  115. package/dist/ui/elements/surface.works.ts +0 -9
  116. package/dist/ui/elements/table.tsx +0 -62
  117. package/dist/ui/elements/table.works.ts +0 -30
  118. package/dist/ui/elements/tabs.tsx +0 -47
  119. package/dist/ui/elements/tabs.works.ts +0 -84
  120. package/dist/ui/elements/text.tsx +0 -33
  121. package/dist/ui/elements/textarea.tsx +0 -38
  122. package/dist/ui/elements/textarea.works.ts +0 -5
  123. package/dist/ui/elements/time.tsx +0 -40
  124. package/dist/ui/elements/time.works.ts +0 -29
  125. package/dist/ui/elements/toggle.tsx +0 -34
  126. package/dist/ui/elements/toggle.works.ts +0 -5
  127. package/dist/ui/elements/tooltip.tsx +0 -40
  128. package/dist/ui/elements/tooltip.works.ts +0 -77
  129. package/dist/ui/elements/value.tsx +0 -38
  130. package/dist/ui/elements/value.works.ts +0 -9
  131. package/dist/ui/elements.ts +0 -127
  132. package/dist/ui/focus-scope.ts +0 -121
  133. package/dist/ui/fonts.ts +0 -355
  134. package/dist/ui/generators/dev.d.ts +0 -1
  135. package/dist/ui/generators/dev.js +0 -61
  136. package/dist/ui/generators/dev.ts +0 -74
  137. package/dist/ui/generators/elements.ts +0 -796
  138. package/dist/ui/generators/i18n.ts +0 -283
  139. package/dist/ui/generators/icons.ts +0 -207
  140. package/dist/ui/generators/react.ts +0 -267
  141. package/dist/ui/generators/routes.ts +0 -847
  142. package/dist/ui/generators/show.ts +0 -261
  143. package/dist/ui/generators/styles.ts +0 -677
  144. package/dist/ui/generators/variants.ts +0 -196
  145. package/dist/ui/i18n/catalogs/en.ts +0 -191
  146. package/dist/ui/i18n/format.ts +0 -221
  147. package/dist/ui/i18n/locales.ts +0 -33
  148. package/dist/ui/i18n/parse.ts +0 -315
  149. package/dist/ui/i18n/translator.ts +0 -31
  150. package/dist/ui/i18n/types.ts +0 -96
  151. package/dist/ui/icons.ts +0 -331
  152. package/dist/ui/islands/map.ts +0 -58
  153. package/dist/ui/localizations.ts +0 -75
  154. package/dist/ui/material.ts +0 -236
  155. package/dist/ui/materials/mat_bordered.ts +0 -13
  156. package/dist/ui/materials/mat_ceramic.ts +0 -13
  157. package/dist/ui/materials/mat_clay.ts +0 -13
  158. package/dist/ui/materials/mat_elevated.ts +0 -24
  159. package/dist/ui/materials/mat_flat.ts +0 -34
  160. package/dist/ui/materials/mat_glass.ts +0 -20
  161. package/dist/ui/materials/mat_lit.ts +0 -13
  162. package/dist/ui/materials/mat_moulded.ts +0 -11
  163. package/dist/ui/materials.ts +0 -197
  164. package/dist/ui/modes.ts +0 -44
  165. package/dist/ui/navigation.tsx +0 -29
  166. package/dist/ui/positioning.ts +0 -90
  167. package/dist/ui/presented.tsx +0 -119
  168. package/dist/ui/provider.tsx +0 -184
  169. package/dist/ui/render-loop.ts +0 -133
  170. package/dist/ui/roving-focus.ts +0 -161
  171. package/dist/ui/screens.ts +0 -141
  172. package/dist/ui/scroll-lock.ts +0 -28
  173. package/dist/ui/series.ts +0 -97
  174. package/dist/ui/signals.ts +0 -386
  175. package/dist/ui/styleguide.ts +0 -231
  176. package/dist/ui/styleguides.ts +0 -374
  177. package/dist/ui/themes.ts +0 -22
  178. package/dist/ui/token.ts +0 -78
  179. package/dist/ui/tokens/shadow.ts +0 -25
  180. package/dist/ui/tokens.ts +0 -234
  181. package/dist/ui/validators.ts +0 -232
  182. package/dist/ui/variant.ts +0 -352
  183. package/dist/ui/variants/var_avatar-round.ts +0 -14
  184. package/dist/ui/variants/var_bubble-me.ts +0 -14
  185. package/dist/ui/variants/var_bubble-them.ts +0 -13
  186. package/dist/ui/variants/var_button-border.ts +0 -76
  187. package/dist/ui/variants/var_button-cta.ts +0 -76
  188. package/dist/ui/variants/var_button-destructive-ghost.ts +0 -72
  189. package/dist/ui/variants/var_button-destructive.ts +0 -76
  190. package/dist/ui/variants/var_button-fill.ts +0 -76
  191. package/dist/ui/variants/var_button-ghost.ts +0 -72
  192. package/dist/ui/variants/var_button-glass.ts +0 -55
  193. package/dist/ui/variants/var_button-normal.ts +0 -76
  194. package/dist/ui/variants/var_button-quiet.ts +0 -74
  195. package/dist/ui/variants/var_card.ts +0 -17
  196. package/dist/ui/variants/var_chip.ts +0 -13
  197. package/dist/ui/variants/var_choice.ts +0 -15
  198. package/dist/ui/variants/var_framed.ts +0 -10
  199. package/dist/ui/variants/var_glyph-plain.ts +0 -11
  200. package/dist/ui/variants/var_input.ts +0 -43
  201. package/dist/ui/variants/var_link-inline.ts +0 -29
  202. package/dist/ui/variants/var_list-row.ts +0 -34
  203. package/dist/ui/variants/var_rule.ts +0 -10
  204. package/dist/ui/variants/var_skeleton-block.ts +0 -12
  205. package/dist/ui/variants/var_spinner-turning.ts +0 -12
  206. package/dist/ui/variants/var_stat-tile.ts +0 -13
  207. package/dist/ui/variants/var_tab-bar.ts +0 -15
  208. package/dist/ui/variants/var_tap-target.ts +0 -25
  209. package/dist/ui/variants.ts +0 -64
  210. package/dist/ui/wrappers.tsx +0 -429
@@ -1,555 +0,0 @@
1
- import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync } from '@prestack/thread/integrations/disk'
2
- import { basename, dirname, join, relative } from 'node:path'
3
- import { argv, stdout } from 'node:process'
4
-
5
- import { SHAPED } from '@prestack/thread/core/init'
6
- import { exit, invoked } from '@prestack/thread/core/invoked'
7
- import { quoted, valuesIn } from '@prestack/thread/core/rows'
8
- import type { Threaded } from '@prestack/thread/core/thread'
9
- import { named as packageOf } from '@prestack/thread/core/scope'
10
- import type { Tree } from '@prestack/thread/core/tree'
11
- import { findTree, inTree } from '@prestack/thread/core/tree'
12
- import { COMPILED } from '@prestack/thread/operations/capabilities'
13
-
14
- import { compiled } from './generators/react.ts'
15
-
16
- export const REACHES = /\buseUi\s*\(/
17
-
18
- const here = 'thread/ui/compositions.ts'
19
-
20
- const said = [
21
- {
22
- on: '2026-08-25',
23
- said: 'Compositions is basically a mix of elements+variants, arranged with arrangement elements, with ways to invoke functions (navigateTo, dispatch).',
24
- },
25
- {
26
- on: '2026-08-25',
27
- said: 'The compositions.ts just says what the thing is, and describes it. Then the file itself, seeded, is a cmp_ file, where we build the actual UI from. And the UI file is plain react, just with our system.',
28
- },
29
- {
30
- on: '2026-08-25',
31
- said: 'Variants themselves declare what elements they relate to, in their declarations. Then the composition says button.primary and if that matches the combination of variant and element it is acceptable. And make sure the composition can only dispatch existing operations.',
32
- },
33
- ]
34
-
35
- export const declares: readonly Threaded[] = []
36
-
37
- export const COMPOSITIONS: Threaded & { readonly files: string } = {
38
- id: 'composition',
39
- at: here,
40
- files: 'compositions/cmp_*.tsx',
41
- describes:
42
- 'A React component made through this system: elements wearing variants, arranged, and able to reach a declared operation. Each row names a file prefixed `cmp_`, and that file is plain React a person writes, because the arrangement, the conditions and the content are theirs. A call site states only what is left over: what a thing does comes from its element, and how it looks and which states it answers to come from its variant, so `Button.primary` is legal only where a variant `primary` says it is worn by `Button`. Text in it is a message key, a look is a variant, and a value names a style guide row, never a raw one. The framework ships none, because what an app is made of is the app’s, and this row says what a composition is, never what is inside it.',
43
- version: 1,
44
- cites: said,
45
- declares,
46
- }
47
-
48
- export const PASCAL = (id: string): string =>
49
- id
50
- .split('-')
51
- .map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`)
52
- .join('')
53
-
54
- export function nameOf(at: string): string {
55
- const file = at.split('\\').join('/').split('/').at(-1) ?? at
56
- return PASCAL(file.replace(/^cmp_/, '').replace(/\.[^.]+$/, ''))
57
- }
58
-
59
- export type Listed = {
60
- readonly id: string
61
- readonly at?: string
62
- readonly describes?: string
63
- readonly wears?: readonly string[]
64
- readonly arranges?: boolean
65
- }
66
-
67
- export function sheetOf(tree: Tree, file: string, ...named: readonly string[]): readonly Listed[] {
68
- const at = inTree(tree, file)
69
- if (!existsSync(at)) return []
70
- const held = valuesIn(readFileSync(at)) as Readonly<
71
- Record<string, { readonly derives?: readonly Listed[]; readonly declares?: readonly Listed[] } | undefined>
72
- >
73
- for (const one of named) {
74
- const found = held[one]?.derives ?? held[one]?.declares
75
- if (found !== undefined) return found
76
- }
77
- return []
78
- }
79
-
80
- const TAG = /<([A-Z][A-Za-z0-9]*)/g
81
-
82
- export function composed(
83
- body: string,
84
- rows: readonly { readonly id: string; readonly at?: string }[],
85
- from: 'screens' | 'compositions',
86
- except?: string,
87
- ): readonly string[] {
88
- const named = new Map<string, string>()
89
- for (const row of rows) {
90
- const at = row.at
91
- if (typeof at !== 'string' || at === '' || at === except) continue
92
- named.set(PASCAL(row.id), at)
93
- }
94
- const found = new Set<string>()
95
- for (const [, tag] of body.matchAll(TAG)) if (tag !== undefined && named.has(tag)) found.add(tag)
96
- return [...found].sort().map((one) => {
97
- const at = named.get(one) ?? ''
98
- const file = (at.split('\\').join('/').split('/').at(-1) ?? at).replace(/\.[^.]+$/, '')
99
- return `import { ${one} } from '${from === 'screens' ? '../compositions' : '.'}/${file}.tsx'`
100
- })
101
- }
102
-
103
- const IMPORTS = /^import\s[\s\S]*?from\s*['"]([^'"]+)['"]/gm
104
-
105
- const FRAMEWORK = 'thread/'
106
-
107
- export const HOME = `${packageOf('ui')}/${here.slice(FRAMEWORK.length).split('/').slice(0, -1).join('/')}`
108
-
109
- export const DOORS: ReadonlySet<string> = new Set(['react', `${HOME}/wrappers`, `${HOME}/drag`])
110
-
111
- const SHIPPED = new RegExp(`^${HOME}/elements/([a-z0-9-]+)$`)
112
-
113
- const slashed = (path: string): string => path.split('\\').join('/')
114
-
115
- export function reaching(
116
- at: string,
117
- text: string,
118
- elements: ReadonlySet<string>,
119
- declared: ReadonlySet<string>,
120
- ): readonly string[] {
121
- const here = slashed(at).split('/').slice(0, -1).join('/')
122
- const found = new Set<string>()
123
- for (const one of text.matchAll(IMPORTS)) {
124
- const from = one[1]
125
- if (from === undefined || DOORS.has(from)) continue
126
- const shipped = SHIPPED.exec(from)?.[1]
127
- if (shipped !== undefined && elements.has(shipped)) continue
128
- if (from.startsWith('.') && declared.has(slashed(join(here, from)))) continue
129
- found.add(from)
130
- }
131
- return [...found].sort()
132
- }
133
-
134
- const CLAUSE = /^import\s+(?!type\s)([\s\S]*?)\s*from\s*['"][^'"]+['"]/gm
135
-
136
- const WORD = /(?:^|[,{]|\s)(?:[A-Za-z_$][\w$]*\s+as\s+)?([A-Za-z_$][\w$]*)/g
137
-
138
- const NOT_A_NAME = new Set(['type', 'as', 'from', 'import'])
139
-
140
- const KEPT = 'a composition keeps no state of its own. State belongs to the element that raises the signal, in the works file beside it'
141
-
142
- const RUNS = 'nothing here runs on its own. A read is bound by the screen in its own views list, and a press is answered by dispatch'
143
-
144
- const REFUSED: Readonly<Record<string, string>> = {
145
- useState: KEPT,
146
- useReducer: KEPT,
147
- useSyncExternalStore: KEPT,
148
- useEffect: RUNS,
149
- useLayoutEffect: RUNS,
150
- element: 'only the compiler writes an element, and a file that calls it turns off the checks that keep this one declared',
151
- }
152
-
153
- export function compiledAt(at: string): string {
154
- return `${COMPILED}/${slashed(at)}`
155
- }
156
-
157
- const ENDINGS = ['.tsx', '.ts'] as const
158
-
159
- function beside(root: string, where: string, said: string): string | undefined {
160
- if (!said.startsWith(`${HOME}/`)) return undefined
161
- const tail = said.slice(HOME.length + 1)
162
- for (const ending of ENDINGS) {
163
- const at = `${COMPILED}/ui/${tail}${ending}`
164
- if (!existsSync(join(root, at))) continue
165
- const out = slashed(relative(dirname(where), at))
166
- return out.startsWith('.') ? out : `./${out}`
167
- }
168
- return undefined
169
- }
170
-
171
- const NAMED_IMPORT = /(['"])(@[^'"]+)\1/g
172
-
173
- export function settled(
174
- root: string,
175
- rows: readonly Threaded[],
176
- checking: boolean,
177
- by: string,
178
- kept: Set<string>,
179
- ): readonly string[] {
180
- const said: string[] = []
181
- for (const row of rows) {
182
- const file = join(root, row.at)
183
- if (!existsSync(file)) continue
184
- const held = compiled(readFileSync(file, 'utf8'), row.at)
185
- if (held.because !== undefined) {
186
- said.push(held.because)
187
- continue
188
- }
189
- const where = compiledAt(row.at)
190
- kept.add(where)
191
- const text = (held.text ?? '').replace(NAMED_IMPORT, (whole: string, quote: string, said: string) => {
192
- const found = beside(root, where, said)
193
- return found === undefined ? whole : `${quote}${found}${quote}`
194
- })
195
- const at = join(root, where)
196
- if (!checking) {
197
- writeFileSync(at, text, 'utf8')
198
- continue
199
- }
200
- if (existsSync(at) && readFileSync(at, 'utf8') === text) continue
201
- said.push(
202
- `${where} is not what the compiler writes from ${row.at}. A compiled file that differs from its ` +
203
- `source is a hand edit wearing a generated name. Run \`${by}\` and commit what it writes.`,
204
- )
205
- }
206
- return said
207
- }
208
-
209
- const ORG = packageOf('ui').split('/')[0] ?? ''
210
-
211
- const REACHED = /^(?:import|export)\s+(type\s+)?(?:(?:[^\n]|\n(?=[ \t}]))*?\s)?from\s*['"]([^'"]+)['"]/gm
212
-
213
- export const RUNTIME: readonly string[] = ['wrappers.tsx', 'drag.ts', 'provider.tsx', 'islands/map.ts']
214
-
215
- const NODE = /^node:/
216
-
217
- function installs(root: string): ReadonlySet<string> {
218
- try {
219
- const held = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as {
220
- readonly dependencies?: Readonly<Record<string, string>>
221
- readonly devDependencies?: Readonly<Record<string, string>>
222
- }
223
- return new Set([...Object.keys(held.dependencies ?? {}), ...Object.keys(held.devDependencies ?? {})])
224
- } catch {
225
- return new Set()
226
- }
227
- }
228
-
229
- function packaging(said: string): string {
230
- return said.startsWith('@') ? said.split('/').slice(0, 2).join('/') : (said.split('/')[0] ?? said)
231
- }
232
-
233
- export function emitting(
234
- root: string,
235
- entries: readonly string[],
236
- checking: boolean,
237
- kept: Set<string>,
238
- ): readonly string[] {
239
- const has = installs(root)
240
- const from = join(root, 'node_modules', packageOf('ui'), 'dist', 'ui')
241
- const said: string[] = []
242
- if (!existsSync(from)) {
243
- return [
244
- `this app declares an interface and ${packageOf('ui')} is not installed, so there is nothing to emit it from. ` +
245
- `Install it and run \`thread attach ${packageOf('ui')}\` again.`,
246
- ]
247
- }
248
- const seen = new Set<string>()
249
- const walk = (at: string): void => {
250
- if (seen.has(at)) return
251
- seen.add(at)
252
- const file = join(from, at)
253
- if (!existsSync(file)) {
254
- said.push(
255
- `${at} is part of the interface this app emits, and the installed ${packageOf('ui')} does not hold it. ` +
256
- 'Upgrade the framework packages and run this again.',
257
- )
258
- return
259
- }
260
- const text = readFileSync(file, 'utf8')
261
- const where = `${COMPILED}/ui/${at}`
262
- kept.add(where)
263
- const to = join(root, where)
264
- if (checking) {
265
- if (!existsSync(to) || readFileSync(to, 'utf8') !== text) {
266
- said.push(
267
- `${where} is not what this app emits from ${packageOf('ui')}. An emitted file that differs from ` +
268
- 'its source is a hand edit wearing a generated name. Run `thread compositions` and commit what it writes.',
269
- )
270
- }
271
- } else {
272
- writeFileSync(to, text, 'utf8')
273
- }
274
- for (const one of text.matchAll(REACHED)) {
275
- const named = one[2] ?? ''
276
- if (named.startsWith('.')) {
277
- const next = slashed(join(dirname(at), named))
278
- if (next.startsWith('..')) {
279
- said.push(`${at} reaches \`${named}\`, which is outside the interface this app emits.`)
280
- continue
281
- }
282
- walk(next)
283
- continue
284
- }
285
- if (one[1] !== undefined) continue
286
- if (!named.startsWith(`${ORG}/`)) {
287
- const held = packaging(named)
288
- if (NODE.test(named) || has.has(held)) continue
289
- said.push(
290
- `${at} reaches ${held}, and this app installs nothing by that name. An emitted interface brings ` +
291
- `what it reaches with it, so ${held} has to arrive when ` +
292
- `thread attach ${packageOf('ui')} runs.`,
293
- )
294
- continue
295
- }
296
- said.push(
297
- `${at} reaches \`${named}\`, so emitting it would leave this app importing the framework while it runs. ` +
298
- 'It reaches what is emitted beside it, or nothing of this framework at all.',
299
- )
300
- }
301
- }
302
- for (const one of entries) walk(one)
303
- return said
304
- }
305
-
306
- export function stale(root: string, kept: ReadonlySet<string>, checking: boolean): readonly string[] {
307
- const said: string[] = []
308
- const walk = (at: string): void => {
309
- const where = join(root, at)
310
- if (!existsSync(where)) return
311
- for (const each of readdirSync(where, { withFileTypes: true })) {
312
- const path = `${at}/${each.name}`
313
- if (each.isDirectory()) {
314
- walk(path)
315
- continue
316
- }
317
- if (kept.has(path)) continue
318
- if (checking) {
319
- said.push(
320
- `${path} sits under ${COMPILED} and nothing declares what it was written from any more. ` +
321
- 'Run `thread compositions` and it goes.',
322
- )
323
- continue
324
- }
325
- rmSync(join(root, path), { force: true })
326
- }
327
- }
328
- walk(COMPILED)
329
- return said
330
- }
331
-
332
- const SHEET = 'compiled.ts'
333
-
334
- const EMITS = 'thread compositions'
335
-
336
- export const SCREENED_BY = 'thread screens'
337
-
338
- const SHIPS = `${COMPILED}/ui/`
339
-
340
- const idFor = (at: string): string => `compiled-${at.slice(COMPILED.length + 1).replace(/\.[^./]+$/, '').split('/').join('-')}`
341
-
342
- function meaning(at: string, by: string): string {
343
- if (at.startsWith(SHIPS)) {
344
- return (
345
- '`' + at.slice(SHIPS.length) + '` from ' + packageOf('ui') + ', copied into this app so a page runs it with nothing of ' +
346
- 'the framework installed. `' + by + '` writes it, so an edit made here is refused.'
347
- )
348
- }
349
- return (
350
- '`' + at.slice(COMPILED.length + 1) + '` as React runs it, compiled from the file a person wrote: a variant worn as a ' +
351
- 'tag has become its class, and a named place the class its arrangement declares. `' + by + '` writes it, so an ' +
352
- 'edit made here is refused.'
353
- )
354
- }
355
-
356
- type Sheeted = { readonly text: string } | { readonly because: string }
357
-
358
- function sheeted(tree: Tree, written: readonly string[], screened: ReadonlySet<string>): Sheeted {
359
- const at = relative(tree.at, inTree(tree, SHEET))
360
- const ui = inTree(tree, 'ui.ts')
361
- const held = (existsSync(ui) ? valuesIn(readFileSync(ui)) : {}) as { readonly GENERATORS?: readonly Threaded[] }
362
- const row = (held.GENERATORS ?? []).flatMap((one) => one.derives ?? []).find((one) => one.at === at)
363
- if (row === undefined) {
364
- return {
365
- because:
366
- tree.name + '/ui.ts names no ' + at + ', so every file this command emits would be one nothing declares. ' +
367
- 'Run `thread attach ' + packageOf('ui') + '`: that sheet is written by the package, never by hand.',
368
- }
369
- }
370
- const rows = [...written].sort().map((one) => {
371
- const by = screened.has(one) ? SCREENED_BY : EMITS
372
- return [
373
- ' {',
374
- ` id: ${quoted(idFor(one))},`,
375
- ` at: ${quoted(one)},`,
376
- ` describes: ${quoted(meaning(one, by))},`,
377
- ' version: 1,',
378
- ` by: ${quoted(by)},`,
379
- ` runs: ${quoted(`${by} --check`)},`,
380
- ' },',
381
- ].join('\n')
382
- })
383
- return {
384
- text: [
385
- `import type { Threaded } from '${SHAPED}'`,
386
- '',
387
- 'export const COMPILED: Threaded = {',
388
- ` id: ${quoted(row.id)},`,
389
- ` at: ${quoted(at)},`,
390
- ` describes: ${quoted(row.describes)},`,
391
- ' version: 1,',
392
- ' derives: [',
393
- ...rows,
394
- ' ],',
395
- '}',
396
- '',
397
- ].join('\n'),
398
- }
399
- }
400
-
401
- function declaring(tree: Tree, written: readonly string[], checking: boolean, screened: ReadonlySet<string>): readonly string[] {
402
- const made = sheeted(tree, written, screened)
403
- if ('because' in made) return [made.because]
404
- const at = inTree(tree, SHEET)
405
- if (!checking) {
406
- writeFileSync(at, made.text, 'utf8')
407
- return []
408
- }
409
- if (existsSync(at) && readFileSync(at, 'utf8') === made.text) return []
410
- return [
411
- relative(tree.at, at) + ' is not what this command writes. A sheet that differs from the files it ' +
412
- 'declares is a hand edit wearing a generated name. Run `' + EMITS + '` and commit what it writes.',
413
- ]
414
- }
415
-
416
- export function handing(at: string, text: string): readonly string[] {
417
- const found: string[] = []
418
- for (const one of text.matchAll(CLAUSE)) {
419
- for (const name of (one[1] ?? '').matchAll(WORD)) {
420
- const held = name[1]
421
- if (held === undefined || NOT_A_NAME.has(held)) continue
422
- const why = REFUSED[held]
423
- if (why === undefined) continue
424
- found.push(`${at} imports \`${held}\`, and ${why}.`)
425
- }
426
- }
427
- if (/\bfetch\s*\(/.test(text)) {
428
- found.push(
429
- `${at} calls \`fetch\`, and nothing here reaches the network by hand. A screen names the reads it ` +
430
- 'binds in its own views list, and the framework runs each one.',
431
- )
432
- }
433
- return found
434
- }
435
-
436
- export function undeclared(
437
- tree: Tree,
438
- rows: readonly Threaded[],
439
- ): readonly string[] {
440
- const elements = new Set<string>()
441
- const declared = new Set<string>()
442
-
443
- for (const [file, exported] of [
444
- ['elements.ts', 'ELEMENT'],
445
- ['compositions.ts', 'COMPOSITION'],
446
- ['screens.ts', 'SCREEN'],
447
- ] as const) {
448
- const where = inTree(tree, file)
449
- if (!existsSync(where)) continue
450
- const sheet = valuesIn(readFileSync(where)) as Readonly<
451
- Record<string, { readonly declares?: readonly Threaded[] } | undefined>
452
- >
453
- for (const row of sheet[exported]?.declares ?? []) {
454
- if (exported === 'ELEMENT') elements.add(row.id)
455
- if (row.at !== '') declared.add(slashed(row.at))
456
- }
457
- }
458
-
459
- const found: string[] = []
460
- for (const row of rows) {
461
- const file = join(tree.at, row.at)
462
- if (!existsSync(file)) continue
463
- const text = readFileSync(file, 'utf8')
464
- found.push(...handing(row.at, text))
465
- for (const one of reaching(row.at, text, elements, declared)) {
466
- found.push(
467
- `${row.at} imports \`${one}\`, which this app declares nothing by. A composition reaches ` +
468
- 'declared elements, other declared compositions, and the door — everything else is a thing ' +
469
- 'nothing wrote down. Declare it, or take it out and write the body through `thread create`.',
470
- )
471
- }
472
- }
473
- return found
474
- }
475
-
476
- function starter(row: Threaded): string {
477
- const name = nameOf(row.at)
478
- return `'use client'
479
-
480
- import { Box } from '${HOME}/elements/box'
481
- import { composition } from '${HOME}/wrappers'
482
-
483
- export const ${name} = composition('${name}', () => <Box.card />)
484
- `
485
- }
486
-
487
- export function seeds(rows: readonly Threaded[], held: (at: string) => boolean): readonly { readonly path: string; readonly content: string }[] {
488
- return rows.filter((row) => !held(row.at)).map((row) => ({ path: row.at, content: starter(row) }))
489
- }
490
-
491
- function run(): number {
492
- const tree = findTree()
493
- const at = inTree(tree, 'compositions.ts')
494
- if (!existsSync(at)) {
495
- stdout.write(`thread: this tree has no ${tree.name}/${basename(at)}, so it declares no composition and there is nothing to seed or check.\n`)
496
- return 0
497
- }
498
- const held = valuesIn(readFileSync(at)) as { COMPOSITION?: { readonly declares?: readonly Threaded[] } }
499
-
500
- if (held.COMPOSITION === undefined) {
501
- stdout.write(`thread: ${tree.name}/compositions.ts exports no \`COMPOSITION\`, so nothing declares a composition here.\n`)
502
- return 1
503
- }
504
-
505
- const rows = held.COMPOSITION.declares ?? []
506
- const checking = argv.includes('--check')
507
- const made = seeds(rows, (where) => existsSync(join(tree.at, where)))
508
-
509
- const unseeded = made[0]
510
- if (checking && unseeded !== undefined) {
511
- stdout.write(
512
- `thread: ${unseeded.path} is declared and the file is not there yet. A row names a file, and ` +
513
- '`--check` never writes one — run `thread compositions` and commit what it seeds.\n',
514
- )
515
- return 1
516
- }
517
-
518
- if (!checking) {
519
- for (const one of made) {
520
- writeFileSync(join(tree.at, one.path), one.content, 'utf8')
521
- stdout.write(`thread: seeded ${one.path}\n`)
522
- }
523
- }
524
-
525
- const parts = sheetOf(tree, 'elements.ts', 'ELEMENT', 'ELEMENTS')
526
- const shipped = `node_modules/${packageOf('ui')}/dist/ui/`
527
- const entries = [
528
- ...RUNTIME,
529
- ...parts.flatMap((one) =>
530
- (one.at ?? '').startsWith(shipped) ? [(one.at ?? '').slice(shipped.length).replace(/\.js$/, '.tsx')] : [],
531
- ),
532
- ]
533
- const screened = new Set<string>()
534
- for (const one of sheetOf(tree, 'screens.ts', 'SCREEN', 'SCREENS')) {
535
- if (one.at !== undefined && one.at !== '') screened.add(compiledAt(one.at))
536
- }
537
- const kept = new Set<string>(screened)
538
- const found = [
539
- ...undeclared(tree, rows),
540
- ...emitting(tree.at, entries, checking, kept),
541
- ...settled(tree.at, rows, checking, EMITS, kept),
542
- ]
543
- found.push(...declaring(tree, [...kept], checking, screened))
544
- const loose = [...found, ...(found.length === 0 ? stale(tree.at, kept, checking) : [])]
545
- for (const one of loose) stdout.write(`thread: ${one}\n`)
546
-
547
- stdout.write(
548
- `thread: ${String(rows.length)} composition(s) declared, ${String(made.length)} seeded, ` +
549
- `${String(rows.length - made.length)} already written, ` +
550
- `${loose.length === 0 ? 'none reaching anything undeclared' : `${String(loose.length)} reaching something undeclared`}\n`,
551
- )
552
- return loose.length === 0 ? 0 : 1
553
- }
554
-
555
- if (invoked(import.meta.url)) exit(run())
@@ -1,55 +0,0 @@
1
- import { z } from 'zod'
2
-
3
- export const ConsentCategorySchema = z
4
- .strictObject({
5
- id: z
6
- .string()
7
- .regex(/^[a-z][a-z0-9_]*$/, 'a consent category id is lower_snake_case')
8
- .describe('The id recorded in `thread.consent.categories`.'),
9
- labelKey: z.string().min(1).describe('The category’s name, as a message key. Never a sentence.'),
10
- describeKey: z.string().min(1).describe('What is collected under it, as a message key.'),
11
-
12
- required: z.boolean().default(false).describe('True where the app cannot function without it.'),
13
- })
14
- .describe('One thing an app may ask permission to collect.')
15
-
16
- export type ConsentCategory = z.infer<typeof ConsentCategorySchema>
17
-
18
- const TELEMETRY: ConsentCategory = ConsentCategorySchema.parse({
19
- id: 'telemetry',
20
- labelKey: 'consent.telemetry.label',
21
- describeKey: 'consent.telemetry.describe',
22
- })
23
-
24
- const REGISTRY = new Map<string, ConsentCategory>([[TELEMETRY.id, TELEMETRY]])
25
-
26
- export function defineConsentCategory(category: ConsentCategory): void {
27
- const parsed = ConsentCategorySchema.parse(category)
28
- if (REGISTRY.has(parsed.id)) throw new Error(`consent category "${parsed.id}" is already registered`)
29
- REGISTRY.set(parsed.id, parsed)
30
- }
31
-
32
- export function consentCategories(): readonly ConsentCategory[] {
33
- return [...REGISTRY.values()].sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
34
- }
35
-
36
- export function consentCategory(id: string): ConsentCategory | undefined {
37
- return REGISTRY.get(id)
38
- }
39
-
40
- export const ConsentDecisionSchema = z
41
- .strictObject({
42
- decision: z.enum(['accepted', 'declined', 'withdrawn']).describe('Withdrawal is a decision and is recorded like any other.'),
43
-
44
- accepted: z.array(z.string()).describe('The category ids accepted.'),
45
- offered: z.array(z.string()).describe('Every category shown at that moment, accepted or not.'),
46
- })
47
- .describe('One consent decision, with the choice set as it stood when it was made.')
48
-
49
- export type ConsentDecision = z.infer<typeof ConsentDecisionSchema>
50
-
51
- export function consentAllows(decision: ConsentDecision | undefined, categoryId: string): boolean {
52
- if (consentCategory(categoryId)?.required === true) return true
53
- if (decision === undefined || decision.decision !== 'accepted') return false
54
- return decision.accepted.includes(categoryId)
55
- }
@@ -1,27 +0,0 @@
1
- 'use client'
2
-
3
- import type { ReactNode } from 'react'
4
- import { formatValue, runValidator } from './validators.ts'
5
-
6
- import { useSurface } from './wrappers.tsx'
7
-
8
- export type MessageKey = string
9
-
10
- export interface ValueProps {
11
- readonly validator: string
12
- readonly value: unknown
13
-
14
- readonly context?: Readonly<Record<string, unknown>>
15
- }
16
-
17
- export function renderValue(
18
- { validator, value, context }: ValueProps,
19
- surface: ReturnType<typeof useSurface>,
20
- ): ReactNode {
21
- const result = runValidator(validator, value, context ?? {})
22
-
23
- if (!result.ok) return surface.text(result.errorKey)
24
-
25
- return formatValue(validator, result.value, context ?? {})
26
- }
27
-
@@ -1,27 +0,0 @@
1
- export const CONTRAST_LARGE = 3
2
-
3
- function channel(value: number): number {
4
- const c = value / 255
5
- return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4
6
- }
7
-
8
- export function luminance(hex: string): number {
9
- const clean = hex.replace('#', '')
10
- const full =
11
- clean.length === 3
12
- ? clean
13
- .split('')
14
- .map((c) => c + c)
15
- .join('')
16
- : clean.slice(0, 6)
17
- const num = Number.parseInt(full, 16)
18
- const r = channel((num >> 16) & 255)
19
- const g = channel((num >> 8) & 255)
20
- const b = channel(num & 255)
21
- return 0.2126 * r + 0.7152 * g + 0.0722 * b
22
- }
23
-
24
- export function contrast(a: string, b: string): number {
25
- const [light, dark] = [luminance(a), luminance(b)].sort((x, y) => y - x) as [number, number]
26
- return (light + 0.05) / (dark + 0.05)
27
- }
@@ -1,25 +0,0 @@
1
- 'use client'
2
-
3
- import type { MessageKey } from './content.tsx'
4
- import type { Dispatching } from './checked.ts'
5
-
6
- export interface PressProps {
7
-
8
- readonly dispatch?: [keyof Dispatching] extends [never] ? string : keyof Dispatching & string
9
-
10
- readonly input?: Readonly<Record<string, unknown>>
11
-
12
- readonly navigateTo?: string
13
-
14
- readonly onPress?: () => void
15
- }
16
-
17
- export interface Option {
18
- readonly value: string
19
- readonly labelKey: MessageKey
20
- }
21
-
22
- export { Menu, type MenuProps } from './elements/menu.tsx'
23
-
24
- export { type MenuItem } from './elements/menu.works.tsx'
25
-