foldkit-mixins 0.19.1 → 0.21.0

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 (285) hide show
  1. package/README.md +38 -4
  2. package/dist/a11y.d.ts +27 -0
  3. package/dist/a11y.d.ts.map +1 -0
  4. package/dist/a11y.js +78 -0
  5. package/dist/a11y.js.map +1 -0
  6. package/dist/{app.d.mts → app.d.ts} +14 -13
  7. package/dist/app.d.ts.map +1 -0
  8. package/dist/{app.mjs → app.js} +9 -9
  9. package/dist/app.js.map +1 -0
  10. package/dist/attr.d.ts +19 -0
  11. package/dist/attr.d.ts.map +1 -0
  12. package/dist/attr.js +23 -0
  13. package/dist/attr.js.map +1 -0
  14. package/dist/attribute.d.ts +18 -0
  15. package/dist/attribute.d.ts.map +1 -0
  16. package/dist/attribute.js +21 -0
  17. package/dist/attribute.js.map +1 -0
  18. package/dist/attributes.d.ts +15 -0
  19. package/dist/attributes.d.ts.map +1 -0
  20. package/dist/attributes.js +12 -0
  21. package/dist/attributes.js.map +1 -0
  22. package/dist/behavior.d.ts +50 -0
  23. package/dist/behavior.d.ts.map +1 -0
  24. package/dist/behavior.js +71 -0
  25. package/dist/behavior.js.map +1 -0
  26. package/dist/behaviors/collection.d.ts +40 -0
  27. package/dist/behaviors/collection.d.ts.map +1 -0
  28. package/dist/behaviors/collection.js +63 -0
  29. package/dist/behaviors/collection.js.map +1 -0
  30. package/dist/behaviors/disclosure.d.ts +10 -0
  31. package/dist/behaviors/disclosure.d.ts.map +1 -0
  32. package/dist/behaviors/disclosure.js +16 -0
  33. package/dist/behaviors/disclosure.js.map +1 -0
  34. package/dist/behaviors/field-association.d.ts +20 -0
  35. package/dist/behaviors/field-association.d.ts.map +1 -0
  36. package/dist/behaviors/field-association.js +36 -0
  37. package/dist/behaviors/field-association.js.map +1 -0
  38. package/dist/behaviors/index.d.ts +6 -0
  39. package/dist/behaviors/index.js +6 -0
  40. package/dist/behaviors/spin-value.d.ts +21 -0
  41. package/dist/behaviors/spin-value.d.ts.map +1 -0
  42. package/dist/behaviors/spin-value.js +49 -0
  43. package/dist/behaviors/spin-value.js.map +1 -0
  44. package/dist/behaviors/toggle-state.d.ts +11 -0
  45. package/dist/behaviors/toggle-state.d.ts.map +1 -0
  46. package/dist/behaviors/toggle-state.js +13 -0
  47. package/dist/behaviors/toggle-state.js.map +1 -0
  48. package/dist/capability.d.ts +33 -0
  49. package/dist/capability.d.ts.map +1 -0
  50. package/dist/capability.js +70 -0
  51. package/dist/capability.js.map +1 -0
  52. package/dist/contribution.d.ts +38 -0
  53. package/dist/contribution.d.ts.map +1 -0
  54. package/dist/contribution.js +1 -0
  55. package/dist/cssBlocks.d.ts +24 -0
  56. package/dist/cssBlocks.d.ts.map +1 -0
  57. package/dist/cssBlocks.js +66 -0
  58. package/dist/cssBlocks.js.map +1 -0
  59. package/dist/{defaults.d.mts → defaults.d.ts} +2 -4
  60. package/dist/defaults.d.ts.map +1 -0
  61. package/dist/{defaults.mjs → defaults.js} +3 -4
  62. package/dist/defaults.js.map +1 -0
  63. package/dist/devOverlay.d.ts +18 -0
  64. package/dist/devOverlay.d.ts.map +1 -0
  65. package/dist/devOverlay.js +96 -0
  66. package/dist/devOverlay.js.map +1 -0
  67. package/dist/diagnostics.d.ts +20 -0
  68. package/dist/diagnostics.d.ts.map +1 -0
  69. package/dist/diagnostics.js +12 -0
  70. package/dist/diagnostics.js.map +1 -0
  71. package/dist/event.d.ts +21 -0
  72. package/dist/event.d.ts.map +1 -0
  73. package/dist/event.js +25 -0
  74. package/dist/event.js.map +1 -0
  75. package/dist/{foundations.d.mts → foundations.d.ts} +2 -4
  76. package/dist/foundations.d.ts.map +1 -0
  77. package/dist/{foundations.mjs → foundations.js} +24 -19
  78. package/dist/foundations.js.map +1 -0
  79. package/dist/index.d.ts +37 -0
  80. package/dist/index.js +21 -0
  81. package/dist/inject.d.ts +24 -0
  82. package/dist/inject.d.ts.map +1 -0
  83. package/dist/{slotMark-y-RLAuTU.mjs → inject.js} +49 -44
  84. package/dist/inject.js.map +1 -0
  85. package/dist/{layers.d.mts → layers.d.ts} +2 -4
  86. package/dist/layers.d.ts.map +1 -0
  87. package/dist/{layers-DxWvuCJL.mjs → layers.js} +6 -69
  88. package/dist/layers.js.map +1 -0
  89. package/dist/{layout.d.mts → layout.d.ts} +3 -5
  90. package/dist/layout.d.ts.map +1 -0
  91. package/dist/{layout.mjs → layout.js} +7 -6
  92. package/dist/layout.js.map +1 -0
  93. package/dist/metadataToken.d.ts +22 -0
  94. package/dist/metadataToken.d.ts.map +1 -0
  95. package/dist/metadataToken.js +23 -0
  96. package/dist/metadataToken.js.map +1 -0
  97. package/dist/mixin.d.ts +24 -0
  98. package/dist/mixin.d.ts.map +1 -0
  99. package/dist/mixin.js +46 -0
  100. package/dist/mixin.js.map +1 -0
  101. package/dist/mountFailed.d.ts +14 -0
  102. package/dist/mountFailed.d.ts.map +1 -0
  103. package/dist/mountFailed.js +23 -0
  104. package/dist/mountFailed.js.map +1 -0
  105. package/dist/{pipe-DrDyEhoj.d.mts → pipe.d.ts} +4 -5
  106. package/dist/pipe.d.ts.map +1 -0
  107. package/dist/pipe.js +6 -0
  108. package/dist/pipe.js.map +1 -0
  109. package/dist/{prose.d.mts → prose.d.ts} +2 -4
  110. package/dist/prose.d.ts.map +1 -0
  111. package/dist/{prose.mjs → prose.js} +3 -4
  112. package/dist/prose.js.map +1 -0
  113. package/dist/record.d.ts +9 -0
  114. package/dist/record.d.ts.map +1 -0
  115. package/dist/record.js +12 -0
  116. package/dist/record.js.map +1 -0
  117. package/dist/requirement.d.ts +11 -0
  118. package/dist/requirement.d.ts.map +1 -0
  119. package/dist/requirement.js +15 -0
  120. package/dist/requirement.js.map +1 -0
  121. package/dist/resolver.d.ts +17 -0
  122. package/dist/resolver.d.ts.map +1 -0
  123. package/dist/resolver.js +195 -0
  124. package/dist/resolver.js.map +1 -0
  125. package/dist/selector.d.ts +20 -0
  126. package/dist/selector.d.ts.map +1 -0
  127. package/dist/selector.js +23 -0
  128. package/dist/selector.js.map +1 -0
  129. package/dist/slot.d.ts +108 -0
  130. package/dist/slot.d.ts.map +1 -0
  131. package/dist/slot.js +124 -0
  132. package/dist/slot.js.map +1 -0
  133. package/dist/{slotItem-D6_m6IqP.d.mts → slotItem.d.ts} +2 -5
  134. package/dist/slotItem.d.ts.map +1 -0
  135. package/dist/slotItem.js +1 -0
  136. package/dist/slotMark.d.ts +12 -0
  137. package/dist/slotMark.d.ts.map +1 -0
  138. package/dist/slotMark.js +23 -0
  139. package/dist/slotMark.js.map +1 -0
  140. package/dist/slotView.d.ts +134 -0
  141. package/dist/slotView.d.ts.map +1 -0
  142. package/dist/slotView.js +286 -0
  143. package/dist/slotView.js.map +1 -0
  144. package/dist/slots.d.ts +31 -0
  145. package/dist/slots.d.ts.map +1 -0
  146. package/dist/slots.js +61 -0
  147. package/dist/slots.js.map +1 -0
  148. package/dist/{style-Cs-aMa_a.d.mts → style.d.ts} +60 -89
  149. package/dist/style.d.ts.map +1 -0
  150. package/dist/style.js +421 -0
  151. package/dist/style.js.map +1 -0
  152. package/dist/styleRules.d.ts +40 -0
  153. package/dist/styleRules.d.ts.map +1 -0
  154. package/dist/styleRules.js +138 -0
  155. package/dist/styleRules.js.map +1 -0
  156. package/dist/{styleValue-DEsUAC4v.d.mts → styleValue.d.ts} +36 -46
  157. package/dist/styleValue.d.ts.map +1 -0
  158. package/dist/{styleValue-6hpAYYfg.mjs → styleValue.js} +16 -163
  159. package/dist/styleValue.js.map +1 -0
  160. package/dist/{testing.d.mts → testing.d.ts} +3 -5
  161. package/dist/testing.d.ts.map +1 -0
  162. package/dist/{testing.mjs → testing.js} +4 -4
  163. package/dist/testing.js.map +1 -0
  164. package/dist/{core-Cq9PThXv.d.mts → theme/core.d.ts} +13 -15
  165. package/dist/theme/core.d.ts.map +1 -0
  166. package/dist/{core-BrR6UPbk.mjs → theme/core.js} +5 -10
  167. package/dist/theme/core.js.map +1 -0
  168. package/dist/theme/cssMath.d.ts +15 -0
  169. package/dist/theme/cssMath.d.ts.map +1 -0
  170. package/dist/theme/cssMath.js +81 -0
  171. package/dist/theme/cssMath.js.map +1 -0
  172. package/dist/theme/fluid.d.ts +43 -0
  173. package/dist/theme/fluid.d.ts.map +1 -0
  174. package/dist/theme/fluid.js +67 -0
  175. package/dist/theme/fluid.js.map +1 -0
  176. package/dist/theme/fonts.d.ts +15 -0
  177. package/dist/theme/fonts.d.ts.map +1 -0
  178. package/dist/theme/fonts.js +18 -0
  179. package/dist/theme/fonts.js.map +1 -0
  180. package/dist/theme/gamut.d.ts +78 -0
  181. package/dist/theme/gamut.d.ts.map +1 -0
  182. package/dist/theme/gamut.js +205 -0
  183. package/dist/theme/gamut.js.map +1 -0
  184. package/dist/theme/iconMasks.d.ts +3 -0
  185. package/dist/theme/iconMasks.d.ts.map +1 -0
  186. package/dist/theme/iconMasks.js +18 -0
  187. package/dist/theme/iconMasks.js.map +1 -0
  188. package/dist/theme/knob.d.ts +97 -0
  189. package/dist/theme/knob.d.ts.map +1 -0
  190. package/dist/theme/knob.js +102 -0
  191. package/dist/theme/knob.js.map +1 -0
  192. package/dist/theme/knobs.d.ts +317 -0
  193. package/dist/theme/knobs.d.ts.map +1 -0
  194. package/dist/theme/knobs.js +725 -0
  195. package/dist/theme/knobs.js.map +1 -0
  196. package/dist/theme/knobsKept.d.ts +41 -0
  197. package/dist/theme/knobsKept.d.ts.map +1 -0
  198. package/dist/theme/knobsKept.js +67 -0
  199. package/dist/theme/knobsKept.js.map +1 -0
  200. package/dist/theme/oklch.d.ts +335 -0
  201. package/dist/theme/oklch.d.ts.map +1 -0
  202. package/dist/theme/oklch.js +258 -0
  203. package/dist/theme/oklch.js.map +1 -0
  204. package/dist/theme/raise.d.ts +16 -0
  205. package/dist/theme/raise.d.ts.map +1 -0
  206. package/dist/theme/raise.js +51 -0
  207. package/dist/theme/raise.js.map +1 -0
  208. package/dist/theme/root.d.ts +26 -0
  209. package/dist/theme/root.d.ts.map +1 -0
  210. package/dist/theme/root.js +42 -0
  211. package/dist/theme/root.js.map +1 -0
  212. package/dist/theme/scheme.d.ts +21 -0
  213. package/dist/theme/scheme.d.ts.map +1 -0
  214. package/dist/theme/scheme.js +42 -0
  215. package/dist/theme/scheme.js.map +1 -0
  216. package/dist/theme/scriptLiteral.d.ts +6 -0
  217. package/dist/theme/scriptLiteral.d.ts.map +1 -0
  218. package/dist/theme/scriptLiteral.js +9 -0
  219. package/dist/theme/scriptLiteral.js.map +1 -0
  220. package/dist/theme/shadows.d.ts +69 -0
  221. package/dist/theme/shadows.d.ts.map +1 -0
  222. package/dist/theme/shadows.js +99 -0
  223. package/dist/theme/shadows.js.map +1 -0
  224. package/dist/theme/themes.d.ts +66 -0
  225. package/dist/theme/themes.d.ts.map +1 -0
  226. package/dist/theme/themes.js +87 -0
  227. package/dist/theme/themes.js.map +1 -0
  228. package/dist/{tokens-eAYuf574.d.mts → theme/tokens.d.ts} +17 -354
  229. package/dist/theme/tokens.d.ts.map +1 -0
  230. package/dist/theme/tokens.js +321 -0
  231. package/dist/theme/tokens.js.map +1 -0
  232. package/dist/theme.d.ts +524 -0
  233. package/dist/theme.d.ts.map +1 -0
  234. package/dist/theme.js +78 -0
  235. package/dist/theme.js.map +1 -0
  236. package/dist/{utilities.d.mts → utilities.d.ts} +6 -7
  237. package/dist/utilities.d.ts.map +1 -0
  238. package/dist/{utilities.mjs → utilities.js} +5 -6
  239. package/dist/utilities.js.map +1 -0
  240. package/package.json +28 -27
  241. package/dist/app.d.mts.map +0 -1
  242. package/dist/app.mjs.map +0 -1
  243. package/dist/core-BrR6UPbk.mjs.map +0 -1
  244. package/dist/core-Cq9PThXv.d.mts.map +0 -1
  245. package/dist/defaults.d.mts.map +0 -1
  246. package/dist/defaults.mjs.map +0 -1
  247. package/dist/foundations.d.mts.map +0 -1
  248. package/dist/foundations.mjs.map +0 -1
  249. package/dist/index.d.mts +0 -204
  250. package/dist/index.d.mts.map +0 -1
  251. package/dist/index.mjs +0 -477
  252. package/dist/index.mjs.map +0 -1
  253. package/dist/layers-DxWvuCJL.mjs.map +0 -1
  254. package/dist/layers.d.mts.map +0 -1
  255. package/dist/layers.mjs +0 -1
  256. package/dist/layout.d.mts.map +0 -1
  257. package/dist/layout.mjs.map +0 -1
  258. package/dist/pipe-DrDyEhoj.d.mts.map +0 -1
  259. package/dist/prose.d.mts.map +0 -1
  260. package/dist/prose.mjs.map +0 -1
  261. package/dist/rolldown-runtime-D7D4PA-g.mjs +0 -13
  262. package/dist/root-DdIhpyqg.mjs +0 -374
  263. package/dist/root-DdIhpyqg.mjs.map +0 -1
  264. package/dist/slotItem-D6_m6IqP.d.mts.map +0 -1
  265. package/dist/slotMark-y-RLAuTU.mjs.map +0 -1
  266. package/dist/slotView-BfOwXpGw.d.mts +0 -466
  267. package/dist/slotView-BfOwXpGw.d.mts.map +0 -1
  268. package/dist/style-COMT0F2e.mjs +0 -1266
  269. package/dist/style-COMT0F2e.mjs.map +0 -1
  270. package/dist/style-Cs-aMa_a.d.mts.map +0 -1
  271. package/dist/styleValue-6hpAYYfg.mjs.map +0 -1
  272. package/dist/styleValue-DEsUAC4v.d.mts.map +0 -1
  273. package/dist/testing.d.mts.map +0 -1
  274. package/dist/testing.mjs.map +0 -1
  275. package/dist/theme.d.mts +0 -629
  276. package/dist/theme.d.mts.map +0 -1
  277. package/dist/theme.mjs +0 -233
  278. package/dist/theme.mjs.map +0 -1
  279. package/dist/themes-Dum5GN0v.d.mts +0 -499
  280. package/dist/themes-Dum5GN0v.d.mts.map +0 -1
  281. package/dist/tokens-BFpuo-sA.mjs +0 -1292
  282. package/dist/tokens-BFpuo-sA.mjs.map +0 -1
  283. package/dist/tokens-eAYuf574.d.mts.map +0 -1
  284. package/dist/utilities.d.mts.map +0 -1
  285. package/dist/utilities.mjs.map +0 -1
package/README.md CHANGED
@@ -188,7 +188,8 @@ Classes a stylesheet already on the page carries are left out, so
188
188
  installing `Style.stylesheet(...)` yourself (for the first paint, or on the
189
189
  server) never duplicates them. Outside a browser nothing is injected: a server
190
190
  puts `Style.usedIn(html)`, the CSS of every compiled class the page's markup
191
- uses, in the page's head (with `foldkit-ssr`, through its `head` option).
191
+ uses and the global rules of the Styles behind them (keyframes, `raise`'s depth
192
+ rules), in the page's head (with `foldkit-ssr`, through its `head` option).
192
193
 
193
194
  ## What the resolver guarantees
194
195
 
@@ -208,6 +209,39 @@ Conflicts throw `Diagnostics.DiagnosticError` with stable codes such as
208
209
  DevTools and editor tooling can all speak the same diagnostic language. The style rule exists
209
210
  because a positioning Behavior that writes `top` and a Style that also sets `top` would otherwise
210
211
  fight silently, last writer winning.
212
+ A theme refuses its values the same way: `Theme.make` with a value out of a knob's range throws
213
+ `theme:knob-value`, naming the call and the knob (`Theme.make: surface.lightness refuses its
214
+ value: …`), and an unknown knob `theme:unknown-knob`.
215
+
216
+ Those are definition errors, thrown. One thing goes wrong only at runtime: a Mount composed
217
+ beside others that fails. It ends alone, so the slot's other Mounts go on, and it is reported as
218
+ a `MountFailed` diagnostic (`{ mount, slot, cause }`, level `error`) through `foldkit-surface`'s
219
+ `Diagnostics` channel, which by default is Effect's log (the console). A Mount that ends
220
+ interrupted is being torn down with its element and reports nothing. Foldkit runs a Mount in the
221
+ runtime's own context, not its `resources`, so the resolver dispatches the diagnostic at the
222
+ Mount's element (`Diagnostics.dispatch`), and a reporter given with `Diagnostics.layer(reporter)`
223
+ in the resources claims it; without one it goes to the log. A test runs the Mount's stream with
224
+ `Effect.provideService(Diagnostics.Reporter, collected.report)`, where `collected` is
225
+ `Diagnostics.collect()` (both from `foldkit-surface`), and asserts on `collected.reported`.
226
+
227
+ In development, `DevOverlay` lists on the page what the application's reporter heard, Mount
228
+ failures included:
229
+
230
+ ```ts
231
+ import { Diagnostics } from 'foldkit-surface'
232
+ import { DevOverlay } from 'foldkit-mixins'
233
+
234
+ const overlay = DevOverlay.make() // the newest 50; each passed on to Diagnostics.log
235
+ const resources = Diagnostics.layer(overlay.report)
236
+ // In the view, behind the application's development flag:
237
+ // h.div([h.OnMount(overlay.mount)], [])
238
+ ```
239
+
240
+ The panel is drawn in its element's shadow root, fixed in the bottom corner, with a Clear button,
241
+ and nothing while the list is empty. It sends no Message, so draw it only in development: a
242
+ Scene test of a page that draws it cannot resolve it.
243
+ The resolver's thrown `Diagnostics` namespace here is a different thing: import one of the two
244
+ under another name.
211
245
 
212
246
  ## Slots: the public contract
213
247
 
@@ -278,7 +312,7 @@ one.
278
312
  | `Theme.schemeScript(key?)` / `Theme.chooseScheme(scheme, key?)` / `Theme.currentScheme()` | from `foldkit-mixins/theme`: a head script applying a kept `light` or `dark` before the first paint; a Command's Effect that applies and keeps a choice; the scheme applied now |
279
313
  | `Theme.knobScript({ key?, selector? })` / `Theme.chooseKnobs(theme, { base, key?, selector? })` | from `foldkit-mixins/theme`: a head script applying kept knob variables before the first paint; a Command's Effect that applies `theme`'s knobs that differ from `base` and keeps them |
280
314
  | `Theme.make(values)` / `Theme.standard(theme?)` / `Theme.fluidType({ min, max })` | from `foldkit-mixins/theme`: a theme, the typed knob values it changes (`Knobs.standard`); every shipped token with a theme's knobs, for `Theme.root`; one size blended between two lengths by the theme's fluid range |
281
- | `Theme.tokens` / `Theme.breakpointWidths(theme)` | from `foldkit-mixins/theme`: the shipped spacing, type, reading, radius, motion, width, border, shadow and breakpoint scales, `icon` (the masks the components draw their own icons with, Lucide's by default; an application's pack is `foldkit-mixins-ui`'s `Icons.tokens(pack)`, passed as its own tokens), and `safe` (what a notch or the home indicator takes from each screen edge, `env(safe-area-inset-*)`, 0 unless the viewport meta says `viewport-fit=cover`); the breakpoints as pixel widths for `foldkit-primitives/media` |
315
+ | `Theme.tokens` / `Theme.breakpointWidths(theme)` | from `foldkit-mixins/theme`: the shipped spacing, type, reading, radius, motion, width, border, shadow and breakpoint scales, `icon` (the masks the components draw their own icons with, Heroicons' outline set at 2px by default; an application's pack is `foldkit-mixins-ui`'s `Icons.tokens(pack)`, passed as its own tokens), and `safe` (what a notch or the home indicator takes from each screen edge, `env(safe-area-inset-*)`, 0 unless the viewport meta says `viewport-fit=cover`); the breakpoints as pixel widths for `foldkit-primitives/media` |
282
316
  | `Layers.define(names)` / `Layers.standard` | cascade layers as a value: `names`, `declare` (the `@layer …;` statement as a global piece), `in(name, piece)` (a piece's unlayered rules and global CSS inside that layer; what is already layered keeps its layer; a piece wholly in another layer is `style:relayered`) and `layer(name)` (the placement `Style.forSlots(S)(pieces, { layer })` takes, so a slot style is compiled in that layer). A name outside the order is a type error. `standard` is `reset, tokens, theme, defaults, components, layouts, variants, utilities, app`; also under `foldkit-mixins/layers` |
283
317
  | `Style.stylesheet(...)` | one `<style>` block from `NamedStyle`s and bare `StyleValue`s: the layer order hoisted first (two different orders is `style:conflicting-layer-order`), then global chunks, then scoped classes, deduplicated. Once an order is declared, a rule outside it is `style:unlayered-rule`, since it would beat every layer; keyframes, font faces and `@property` pass |
284
318
 
@@ -577,8 +611,8 @@ pieces: `unfilledHover`, `pressedHover`, `hover()`, `focusRing` and `disabled`.
577
611
 
578
612
  `foldkit-mixins/layout` ships the common arrangements as pieces: `Layout.stack`, `cluster`,
579
613
  `split`, `sidebar`, `switcher`, `reel`, `center`, `frame`, `pad`, and `autoGrid`, plus
580
- `Layout.intrinsic` (a stack child that keeps its own width) and `Layout.aside` (the sidebar
581
- child). Each compiles to rule text that is the same for every caller and reads `--fk-l-*`
614
+ `Layout.intrinsic` (a stack child as wide as its content; one that sets a width keeps it
615
+ anyway) and `Layout.aside` (the sidebar child). Each compiles to rule text that is the same for every caller and reads `--fk-l-*`
582
616
  variables with token fallbacks; the options only write those variables inline, so ten stacks
583
617
  with ten gaps are one rule and ten inline declarations. The pieces are unlayered; put them in
584
618
  `layouts`:
package/dist/a11y.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { Diagnostic } from "./diagnostics.js";
2
+ import { Any, AttributeName, EventName, SlotCapability } from "./slot.js";
3
+ export type A11yDiagnosticCode = 'a11y:missing-slot' | 'a11y:hidden-slot' | 'a11y:capability-mismatch' | 'a11y:missing-event' | 'a11y:missing-attribute';
4
+ export interface A11yDiagnostic extends Diagnostic {
5
+ readonly source: 'a11y';
6
+ readonly code: A11yDiagnosticCode;
7
+ }
8
+ export interface SlotRequirement {
9
+ readonly capability?: SlotCapability;
10
+ readonly events?: ReadonlyArray<EventName>;
11
+ readonly attributes?: ReadonlyArray<AttributeName>;
12
+ /** An absent slot is expected, not a diagnostic. A present slot is still checked. */
13
+ readonly optional?: boolean;
14
+ }
15
+ export type Requirements = Readonly<Record<string, SlotRequirement>>;
16
+ export declare const PatternTypeId: unique symbol;
17
+ export interface Pattern<Spec extends Requirements = Requirements> {
18
+ readonly [PatternTypeId]: {
19
+ readonly Requirements: Spec;
20
+ };
21
+ readonly requirements: Spec;
22
+ }
23
+ export declare const pattern: <const Spec extends Requirements>(spec: Spec) => Pattern<Spec>;
24
+ export declare const validate: (pattern: Pattern, slots: {
25
+ readonly [name: string]: Any;
26
+ }) => ReadonlyArray<A11yDiagnostic>;
27
+ //# sourceMappingURL=a11y.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a11y.d.ts","names":["AnySlot"],"sources":["../src/a11y.ts"],"mappings":";;YAaY;iBAOK,uBAAuB;WAC7B;WACA,MAAM;;iBAGA;WACN,aAAa;WACb,SAAS,cAAc;WACvB,aAAa,cAAc;;WAE3B;;YAGC,eAAe,SAAS,eAAe;qBAEtC;iBAEI,QAAQ,aAAa,eAAe;YACzC;aAA2B,cAAc;;WAC1C,cAAc;;qBAGZ,gBAAiB,aAAa,cAAY,MAAQ,SAAO,QAAQ;qBAyCjE,WAAQ,SACV,SAAO;YACG,eAAeA;MACjC,cAAc"}
package/dist/a11y.js ADDED
@@ -0,0 +1,78 @@
1
+ import * as Capability from "./capability.js";
2
+ import * as MetadataToken from "./metadataToken.js";
3
+ // src/a11y.ts
4
+ /**
5
+ * Structural accessibility validation. A `Pattern` names the Slots a widget
6
+ * must publish, the capabilities those Slots must satisfy, and the events and
7
+ * attributes they must expose. `validate` compares a `Slots` contract against a
8
+ * pattern and reports every mismatch as a `Diagnostic`. It is pure and
9
+ * DOM-independent: it checks the declared contract, not a rendered tree, so it
10
+ * verifies only the contract it is given and does not certify WCAG conformance.
11
+ */
12
+ const PatternTypeId = Symbol.for("foldkit-mixins/A11yPattern");
13
+ const pattern = (spec) => {
14
+ const requirements = Object.create(null);
15
+ for (const name of Object.getOwnPropertyNames(spec)) {
16
+ const requirement = spec[name];
17
+ if (requirement === void 0) continue;
18
+ Object.defineProperty(requirements, name, {
19
+ value: Object.freeze({ ...requirement }),
20
+ enumerable: true,
21
+ configurable: false,
22
+ writable: false
23
+ });
24
+ }
25
+ Object.freeze(requirements);
26
+ return Object.freeze({
27
+ [PatternTypeId]: { Requirements: void 0 },
28
+ requirements
29
+ });
30
+ };
31
+ const publishes = (names, required) => {
32
+ const requiredName = MetadataToken.nameOf(required);
33
+ return names.some((name) => MetadataToken.nameOf(name) === requiredName);
34
+ };
35
+ const diagnostic = (code, message, slot, details) => ({
36
+ source: "a11y",
37
+ code,
38
+ severity: "error",
39
+ message,
40
+ slot,
41
+ ...details === void 0 ? {} : { details }
42
+ });
43
+ const validate = (pattern, slots) => {
44
+ const diagnostics = [];
45
+ for (const name of Object.getOwnPropertyNames(pattern.requirements)) {
46
+ const requirement = pattern.requirements[name];
47
+ if (requirement === void 0) continue;
48
+ if (!Object.hasOwn(slots, name)) {
49
+ if (requirement.optional === true) continue;
50
+ diagnostics.push(diagnostic("a11y:missing-slot", `A11y pattern requires slot "${name}", which the contract does not publish`, name));
51
+ continue;
52
+ }
53
+ const slot = slots[name];
54
+ if (slot === void 0) continue;
55
+ if (slot.hidden) {
56
+ diagnostics.push(diagnostic("a11y:hidden-slot", `A11y pattern requires slot "${name}", which is hidden`, name));
57
+ continue;
58
+ }
59
+ if (requirement.capability !== void 0 && !Capability.extendsCapability(slot.capability, requirement.capability)) diagnostics.push(diagnostic("a11y:capability-mismatch", `A11y pattern requires capability "${MetadataToken.nameOf(requirement.capability)}" on slot "${name}", which has "${MetadataToken.nameOf(slot.capability)}"`, name, {
60
+ required: MetadataToken.nameOf(requirement.capability),
61
+ actual: MetadataToken.nameOf(slot.capability)
62
+ }));
63
+ for (const event of requirement.events ?? []) {
64
+ const eventName = MetadataToken.nameOf(event);
65
+ if (publishes(slot.events, event)) continue;
66
+ diagnostics.push(diagnostic("a11y:missing-event", `A11y pattern requires event "${eventName}" on slot "${name}", which does not publish it`, name, { event: eventName }));
67
+ }
68
+ for (const attribute of requirement.attributes ?? []) {
69
+ const attributeName = MetadataToken.nameOf(attribute);
70
+ if (publishes(slot.attributes, attribute)) continue;
71
+ diagnostics.push(diagnostic("a11y:missing-attribute", `A11y pattern requires attribute "${attributeName}" on slot "${name}", which does not publish it`, name, { attribute: attributeName }));
72
+ }
73
+ }
74
+ return diagnostics;
75
+ };
76
+ export { PatternTypeId, pattern, validate };
77
+
78
+ //# sourceMappingURL=a11y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a11y.js","names":[],"sources":["../src/a11y.ts"],"sourcesContent":["/**\n * Structural accessibility validation. A `Pattern` names the Slots a widget\n * must publish, the capabilities those Slots must satisfy, and the events and\n * attributes they must expose. `validate` compares a `Slots` contract against a\n * pattern and reports every mismatch as a `Diagnostic`. It is pure and\n * DOM-independent: it checks the declared contract, not a rendered tree, so it\n * verifies only the contract it is given and does not certify WCAG conformance.\n */\nimport * as Capability from './capability.js'\nimport type { Diagnostic } from './diagnostics.js'\nimport * as MetadataToken from './metadataToken.js'\nimport type { Any as AnySlot, AttributeName, EventName, SlotCapability } from './slot.js'\n\nexport type A11yDiagnosticCode =\n | 'a11y:missing-slot'\n | 'a11y:hidden-slot'\n | 'a11y:capability-mismatch'\n | 'a11y:missing-event'\n | 'a11y:missing-attribute'\n\nexport interface A11yDiagnostic extends Diagnostic {\n readonly source: 'a11y'\n readonly code: A11yDiagnosticCode\n}\n\nexport interface SlotRequirement {\n readonly capability?: SlotCapability\n readonly events?: ReadonlyArray<EventName>\n readonly attributes?: ReadonlyArray<AttributeName>\n /** An absent slot is expected, not a diagnostic. A present slot is still checked. */\n readonly optional?: boolean\n}\n\nexport type Requirements = Readonly<Record<string, SlotRequirement>>\n\nexport const PatternTypeId: unique symbol = Symbol.for('foldkit-mixins/A11yPattern')\n\nexport interface Pattern<Spec extends Requirements = Requirements> {\n readonly [PatternTypeId]: { readonly Requirements: Spec }\n readonly requirements: Spec\n}\n\nexport const pattern = <const Spec extends Requirements>(spec: Spec): Pattern<Spec> => {\n const requirements = Object.create(null) as Record<string, SlotRequirement>\n for (const name of Object.getOwnPropertyNames(spec)) {\n const requirement = spec[name]\n if (requirement === undefined) continue\n Object.defineProperty(requirements, name, {\n value: Object.freeze({ ...requirement }),\n enumerable: true,\n configurable: false,\n writable: false,\n })\n }\n Object.freeze(requirements)\n return Object.freeze({\n [PatternTypeId]: { Requirements: undefined as unknown as Spec },\n requirements: requirements as Spec,\n }) as Pattern<Spec>\n}\n\nconst publishes = (\n names: ReadonlyArray<string | MetadataToken.Any>,\n required: string | MetadataToken.Any,\n): boolean => {\n const requiredName = MetadataToken.nameOf(required)\n return names.some(name => MetadataToken.nameOf(name) === requiredName)\n}\n\nconst diagnostic = (\n code: A11yDiagnosticCode,\n message: string,\n slot: string,\n details?: Readonly<Record<string, unknown>>,\n): A11yDiagnostic => ({\n source: 'a11y',\n code,\n severity: 'error',\n message,\n slot,\n ...(details === undefined ? {} : { details }),\n})\n\nexport const validate = (\n pattern: Pattern,\n slots: { readonly [name: string]: AnySlot },\n): ReadonlyArray<A11yDiagnostic> => {\n const diagnostics: Array<A11yDiagnostic> = []\n for (const name of Object.getOwnPropertyNames(pattern.requirements)) {\n const requirement = pattern.requirements[name]\n if (requirement === undefined) continue\n if (!Object.hasOwn(slots, name)) {\n if (requirement.optional === true) continue\n diagnostics.push(\n diagnostic(\n 'a11y:missing-slot',\n `A11y pattern requires slot \"${name}\", which the contract does not publish`,\n name,\n ),\n )\n continue\n }\n const slot = slots[name]\n if (slot === undefined) continue\n if (slot.hidden) {\n diagnostics.push(\n diagnostic(\n 'a11y:hidden-slot',\n `A11y pattern requires slot \"${name}\", which is hidden`,\n name,\n ),\n )\n continue\n }\n if (\n requirement.capability !== undefined &&\n !Capability.extendsCapability(slot.capability, requirement.capability)\n ) {\n diagnostics.push(\n diagnostic(\n 'a11y:capability-mismatch',\n `A11y pattern requires capability \"${MetadataToken.nameOf(requirement.capability)}\" on slot \"${name}\", which has \"${MetadataToken.nameOf(slot.capability)}\"`,\n name,\n {\n required: MetadataToken.nameOf(requirement.capability),\n actual: MetadataToken.nameOf(slot.capability),\n },\n ),\n )\n }\n for (const event of requirement.events ?? []) {\n const eventName = MetadataToken.nameOf(event)\n if (publishes(slot.events, event)) continue\n diagnostics.push(\n diagnostic(\n 'a11y:missing-event',\n `A11y pattern requires event \"${eventName}\" on slot \"${name}\", which does not publish it`,\n name,\n { event: eventName },\n ),\n )\n }\n for (const attribute of requirement.attributes ?? []) {\n const attributeName = MetadataToken.nameOf(attribute)\n if (publishes(slot.attributes, attribute)) continue\n diagnostics.push(\n diagnostic(\n 'a11y:missing-attribute',\n `A11y pattern requires attribute \"${attributeName}\" on slot \"${name}\", which does not publish it`,\n name,\n { attribute: attributeName },\n ),\n )\n }\n }\n return diagnostics\n}\n"],"mappings":";;;;;;;;;;;AAmCA,MAAa,gBAA+B,OAAO,IAAI,4BAA4B;AAOnF,MAAa,WAA4C,SAA8B;CACrF,MAAM,eAAe,OAAO,OAAO,IAAI;CACvC,KAAK,MAAM,QAAQ,OAAO,oBAAoB,IAAI,GAAG;EACnD,MAAM,cAAc,KAAK;EACzB,IAAI,gBAAgB,KAAA,GAAW;EAC/B,OAAO,eAAe,cAAc,MAAM;GACxC,OAAO,OAAO,OAAO,EAAE,GAAG,YAAY,CAAC;GACvC,YAAY;GACZ,cAAc;GACd,UAAU;EACZ,CAAC;CACH;CACA,OAAO,OAAO,YAAY;CAC1B,OAAO,OAAO,OAAO;GAClB,gBAAgB,EAAE,cAAc,KAAA,EAA6B;EAChD;CAChB,CAAC;AACH;AAEA,MAAM,aACJ,OACA,aACY;CACZ,MAAM,eAAe,cAAc,OAAO,QAAQ;CAClD,OAAO,MAAM,MAAK,SAAQ,cAAc,OAAO,IAAI,MAAM,YAAY;AACvE;AAEA,MAAM,cACJ,MACA,SACA,MACA,aACoB;CACpB,QAAQ;CACR;CACA,UAAU;CACV;CACA;CACA,GAAI,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ;AAC7C;AAEA,MAAa,YACX,SACA,UACkC;CAClC,MAAM,cAAqC,CAAC;CAC5C,KAAK,MAAM,QAAQ,OAAO,oBAAoB,QAAQ,YAAY,GAAG;EACnE,MAAM,cAAc,QAAQ,aAAa;EACzC,IAAI,gBAAgB,KAAA,GAAW;EAC/B,IAAI,CAAC,OAAO,OAAO,OAAO,IAAI,GAAG;GAC/B,IAAI,YAAY,aAAa,MAAM;GACnC,YAAY,KACV,WACE,qBACA,+BAA+B,KAAK,yCACpC,IACF,CACF;GACA;EACF;EACA,MAAM,OAAO,MAAM;EACnB,IAAI,SAAS,KAAA,GAAW;EACxB,IAAI,KAAK,QAAQ;GACf,YAAY,KACV,WACE,oBACA,+BAA+B,KAAK,qBACpC,IACF,CACF;GACA;EACF;EACA,IACE,YAAY,eAAe,KAAA,KAC3B,CAAC,WAAW,kBAAkB,KAAK,YAAY,YAAY,UAAU,GAErE,YAAY,KACV,WACE,4BACA,qCAAqC,cAAc,OAAO,YAAY,UAAU,EAAE,aAAa,KAAK,gBAAgB,cAAc,OAAO,KAAK,UAAU,EAAE,IAC1J,MACA;GACE,UAAU,cAAc,OAAO,YAAY,UAAU;GACrD,QAAQ,cAAc,OAAO,KAAK,UAAU;EAC9C,CACF,CACF;EAEF,KAAK,MAAM,SAAS,YAAY,UAAU,CAAC,GAAG;GAC5C,MAAM,YAAY,cAAc,OAAO,KAAK;GAC5C,IAAI,UAAU,KAAK,QAAQ,KAAK,GAAG;GACnC,YAAY,KACV,WACE,sBACA,gCAAgC,UAAU,aAAa,KAAK,+BAC5D,MACA,EAAE,OAAO,UAAU,CACrB,CACF;EACF;EACA,KAAK,MAAM,aAAa,YAAY,cAAc,CAAC,GAAG;GACpD,MAAM,gBAAgB,cAAc,OAAO,SAAS;GACpD,IAAI,UAAU,KAAK,YAAY,SAAS,GAAG;GAC3C,YAAY,KACV,WACE,0BACA,oCAAoC,cAAc,aAAa,KAAK,+BACpE,MACA,EAAE,WAAW,cAAc,CAC7B,CACF;EACF;CACF;CACA,OAAO;AACT"}
@@ -1,9 +1,10 @@
1
- import { i as StyleValue } from "./styleValue-DEsUAC4v.mjs";
2
- import { standard } from "./layers.mjs";
3
- import { a as NamedStyle, l as StyleOptions, n as Declared, r as DeclaredPieces, u as StylePieces } from "./style-Cs-aMa_a.mjs";
4
- import { a as compose, r as ThemeTokens, t as Refs } from "./core-Cq9PThXv.mjs";
5
- import { d as RootOptions, g as KnobTheme, r as Themes, t as StandardTokens, v as Standard } from "./themes-Dum5GN0v.mjs";
6
- //#region src/app.d.ts
1
+ import { standard } from "./layers.js";
2
+ import { Declared, DeclaredPieces, NamedStyle, StyleOptions, StylePieces } from "./style.js";
3
+ import { StyleValue } from "./styleValue.js";
4
+ import { Refs, ThemeTokens, compose as compose$1 } from "./theme/core.js";
5
+ import { RootOptions } from "./theme/root.js";
6
+ import { StandardTokens, Themes } from "./theme/themes.js";
7
+ import { KnobTheme, Standard } from "./theme/knobs.js";
7
8
  interface Common<Own extends ThemeTokens> {
8
9
  /**
9
10
  * Tokens of the application's own, laid over the shipped ones:
@@ -19,8 +20,8 @@ interface Common<Own extends ThemeTokens> {
19
20
  readonly global?: ReadonlyArray<StyleValue>;
20
21
  }
21
22
  export interface AppStyleOptions<Own extends ThemeTokens> extends Common<Own> {
22
- /** The application's one theme: `Theme.make({ … })`. */
23
- readonly theme: KnobTheme<Standard>;
23
+ /** The application's one theme: `Theme.make({ … })`. Default the shipped one, `Theme.make({})`. */
24
+ readonly theme?: KnobTheme<Standard>;
24
25
  }
25
26
  /**
26
27
  * The options with a set of named themes in place of one: the root declares
@@ -34,9 +35,9 @@ export interface AppStyleThemesOptions<Name extends string, Own extends ThemeTok
34
35
  export type AppStyleOptionsFor = Omit<StyleOptions, 'layer'>;
35
36
  export interface AppStyle<Own extends ThemeTokens> {
36
37
  /** Every shipped token with the theme's knobs, and the application's own over them. */
37
- readonly theme: ReturnType<typeof compose<StandardTokens, Own>>;
38
+ readonly theme: ReturnType<typeof compose$1<StandardTokens, Own>>;
38
39
  /** Every token of `theme` as a typed `var(--fk-…)` reference. */
39
- readonly t: Refs<ReturnType<typeof compose<StandardTokens, Own>>>;
40
+ readonly t: Refs<ReturnType<typeof compose$1<StandardTokens, Own>>>;
40
41
  /** The layer order the stylesheet declares, for placing a layout or recipe (`L.in('layouts', …)`). */
41
42
  readonly L: typeof standard;
42
43
  /** `Style.slots` in the `app` layer: the application's own Slots, declared by their style. */
@@ -48,7 +49,8 @@ export interface AppStyle<Own extends ThemeTokens> {
48
49
  }
49
50
  /**
50
51
  * The application's tokens, layer and page stylesheet:
51
- * `const { t, slots, stylesheet } = AppStyle.make({ theme: Theme.make({ … }) })`.
52
+ * `const { t, slots, stylesheet } = AppStyle.make({ theme: Theme.make({ … }) })`,
53
+ * or `AppStyle.make({})` on the shipped theme.
52
54
  * Slot styles are no longer in the stylesheet: a Slot injects its classes' CSS
53
55
  * when it first draws them.
54
56
  */
@@ -57,6 +59,5 @@ export declare function make<Own extends ThemeTokens = Record<never, never>>(opt
57
59
  export declare const AppStyle: {
58
60
  readonly make: typeof make;
59
61
  };
60
- //#endregion
61
62
  export {};
62
- //# sourceMappingURL=app.d.mts.map
63
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","names":["composeThemes"],"sources":["../src/app.ts"],"mappings":";;;;;;;UAyBU,OAAO,YAAY;;;;;WAKlB,SAAS;;WAET,cAAc,YAAY;;;;;WAK1B,SAAS,cAAc;;iBAGjB,gBAAgB,YAAY,qBAAqB,OAAO;;WAE9D,QAAQ,UAAU;;;;;;;iBAQZ,sBACf,qBACA,YAAY,qBACJ,OAAO;WACN,QAAQ,OAAO;;;YAId,qBAAqB,KAAK;iBAErB,SAAS,YAAY;;WAE3B,OAAO,kBAAkBA,UAAc,gBAAgB;;WAEvD,GAAG,KAAK,kBAAkBA,UAAc,gBAAgB;;WAExD,UAAU;;WAEV,QAAQ,GAAG,QAAQ,eAAe,IAAI,UAAU,uBAAuB,SAAS;;WAEhF,WAAW,OAClB,UAAU,WACN,QAAQ,YAAY,QAAQ,UAAU,uBAAuB,WAAW;;WAErE;;;;;;;;;wBAYK,KAAK,qBAAqB,YAAY,cAAc,sBAClE,SAAS,sBAAsB,MAAM,OACpC,SAAS;wBACI,KAAK,YAAY,cAAc,sBAC7C,SAAS,gBAAgB,OACxB,SAAS;qBA2BC"}
@@ -1,10 +1,11 @@
1
- import { i as stylesheet, n as forSlots, r as slots } from "./style-COMT0F2e.mjs";
2
- import { i as compose } from "./styleValue-6hpAYYfg.mjs";
3
- import { r as standard } from "./layers-DxWvuCJL.mjs";
4
- import { o as ref, r as compose$1 } from "./core-BrR6UPbk.mjs";
5
- import { l as standardOf, t as root } from "./root-DdIhpyqg.mjs";
6
- import { body, reset } from "./defaults.mjs";
7
- //#region src/app.ts
1
+ import { body, reset } from "./defaults.js";
2
+ import { standard } from "./layers.js";
3
+ import { forSlots, slots, stylesheet } from "./style.js";
4
+ import { compose } from "./styleValue.js";
5
+ import { compose as compose$1, ref } from "./theme/core.js";
6
+ import { root } from "./theme/root.js";
7
+ import { standardOf } from "./theme/themes.js";
8
+ // src/app.ts
8
9
  /**
9
10
  * `foldkit-mixins/app`: an application's style setup, fixed once. Every
10
11
  * application on the standard layers writes the same preamble: its theme's
@@ -33,7 +34,6 @@ function make(options) {
33
34
  });
34
35
  }
35
36
  const AppStyle = { make };
36
- //#endregion
37
37
  export { AppStyle, make };
38
38
 
39
- //# sourceMappingURL=app.mjs.map
39
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","names":["composeThemes"],"sources":["../src/app.ts"],"sourcesContent":["/**\n * `foldkit-mixins/app`: an application's style setup, fixed once. Every\n * application on the standard layers writes the same preamble: its theme's\n * tokens, their references, the `app` layer passed to each style, and a page\n * stylesheet of the layer order, the reset, the tokens and the body defaults.\n * `AppStyle.make` is that preamble as a value.\n */\nimport { body, reset } from './defaults.js'\nimport { standard } from './layers.js'\nimport {\n forSlots,\n slots,\n stylesheet,\n type Declared,\n type DeclaredPieces,\n type NamedStyle,\n type StyleOptions,\n type StylePieces,\n} from './style.js'\nimport { compose, type StyleValue } from './styleValue.js'\nimport { compose as composeThemes, ref, type Refs, type ThemeTokens } from './theme/core.js'\nimport type { KnobTheme, Standard } from './theme/knobs.js'\nimport { root, type RootOptions } from './theme/root.js'\nimport { standardOf, type StandardTokens, type Themes } from './theme/themes.js'\n\ninterface Common<Own extends ThemeTokens> {\n /**\n * Tokens of the application's own, laid over the shipped ones:\n * `Theme.define({ game: { … } })`, read through `t` beside them.\n */\n readonly tokens?: Own\n /** The page's `color-scheme`; `'light'` keeps a light page light in a dark browser. Default `'light dark'`. */\n readonly colorScheme?: NonNullable<RootOptions['colorScheme']>\n /**\n * More page-wide pieces after `Defaults.body`, such as `Defaults.headings`,\n * keyframes or a font face, placed in the `defaults` layer.\n */\n readonly global?: ReadonlyArray<StyleValue>\n}\n\nexport interface AppStyleOptions<Own extends ThemeTokens> extends Common<Own> {\n /** The application's one theme: `Theme.make({ … })`. Default the shipped one, `Theme.make({})`. */\n readonly theme?: KnobTheme<Standard>\n}\n\n/**\n * The options with a set of named themes in place of one: the root declares\n * the initial theme, and each other is drawn where the Model names it\n * (`Themes.apply`).\n */\nexport interface AppStyleThemesOptions<\n Name extends string,\n Own extends ThemeTokens,\n> extends Common<Own> {\n readonly themes: Themes<Name>\n}\n\n/** A style's options with its layer fixed to the application's. */\nexport type AppStyleOptionsFor = Omit<StyleOptions, 'layer'>\n\nexport interface AppStyle<Own extends ThemeTokens> {\n /** Every shipped token with the theme's knobs, and the application's own over them. */\n readonly theme: ReturnType<typeof composeThemes<StandardTokens, Own>>\n /** Every token of `theme` as a typed `var(--fk-…)` reference. */\n readonly t: Refs<ReturnType<typeof composeThemes<StandardTokens, Own>>>\n /** The layer order the stylesheet declares, for placing a layout or recipe (`L.in('layouts', …)`). */\n readonly L: typeof standard\n /** `Style.slots` in the `app` layer: the application's own Slots, declared by their style. */\n readonly slots: <S>(pieces: DeclaredPieces<S>, options?: AppStyleOptionsFor) => Declared<S>\n /** `Style.forSlots` in the `app` layer: a published contract (`ButtonSlots`) styled for this application. */\n readonly forSlots: <Slots>(\n contract: Slots,\n ) => (pieces: StylePieces<Slots>, options?: AppStyleOptionsFor) => NamedStyle<Slots>\n /** The page sheet: the layer order, reset, tokens, `Defaults.body` and `global`. */\n readonly stylesheet: string\n}\n\nconst app = standard.layer('app')\n\n/**\n * The application's tokens, layer and page stylesheet:\n * `const { t, slots, stylesheet } = AppStyle.make({ theme: Theme.make({ … }) })`,\n * or `AppStyle.make({})` on the shipped theme.\n * Slot styles are no longer in the stylesheet: a Slot injects its classes' CSS\n * when it first draws them.\n */\nexport function make<Name extends string, Own extends ThemeTokens = Record<never, never>>(\n options: AppStyleThemesOptions<Name, Own>,\n): AppStyle<Own>\nexport function make<Own extends ThemeTokens = Record<never, never>>(\n options: AppStyleOptions<Own>,\n): AppStyle<Own>\nexport function make(\n options: AppStyleOptions<ThemeTokens> | AppStyleThemesOptions<string, ThemeTokens>,\n): AppStyle<ThemeTokens> {\n const shipped = 'themes' in options ? options.themes.root : standardOf(options.theme)\n const theme = composeThemes(shipped, options.tokens ?? {})\n const scheme = options.colorScheme === undefined ? {} : { colorScheme: options.colorScheme }\n return Object.freeze({\n theme,\n t: ref(theme),\n L: standard,\n slots: <S>(pieces: DeclaredPieces<S>, styleOptions?: AppStyleOptionsFor) =>\n slots(pieces, { ...styleOptions, layer: app }),\n forSlots:\n <Slots>(contract: Slots) =>\n (pieces: StylePieces<Slots>, styleOptions?: AppStyleOptionsFor) =>\n forSlots(contract)(pieces, { ...styleOptions, layer: app }),\n stylesheet: stylesheet(\n standard.declare,\n standard.in('reset', reset),\n standard.in('theme', root(theme, scheme)),\n ...('themes' in options ? [standard.in('theme', options.themes.scoped)] : []),\n standard.in('defaults', compose(body, ...(options.global ?? []))),\n ),\n })\n}\n\nexport const AppStyle = { make } as const\n"],"mappings":";;;;;;;;;;;;;;;AA6EA,MAAM,MAAM,SAAS,MAAM,KAAK;AAehC,SAAgB,KACd,SACuB;CACvB,MAAM,UAAU,YAAY,UAAU,QAAQ,OAAO,OAAO,WAAW,QAAQ,KAAK;CACpF,MAAM,QAAQA,UAAc,SAAS,QAAQ,UAAU,CAAC,CAAC;CACzD,MAAM,SAAS,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;CAC3F,OAAO,OAAO,OAAO;EACnB;EACA,GAAG,IAAI,KAAK;EACZ,GAAG;EACH,QAAW,QAA2B,iBACpC,MAAM,QAAQ;GAAE,GAAG;GAAc,OAAO;EAAI,CAAC;EAC/C,WACU,cACP,QAA4B,iBAC3B,SAAS,QAAQ,CAAC,CAAC,QAAQ;GAAE,GAAG;GAAc,OAAO;EAAI,CAAC;EAC9D,YAAY,WACV,SAAS,SACT,SAAS,GAAG,SAAS,KAAK,GAC1B,SAAS,GAAG,SAAS,KAAK,OAAO,MAAM,CAAC,GACxC,GAAI,YAAY,UAAU,CAAC,SAAS,GAAG,SAAS,QAAQ,OAAO,MAAM,CAAC,IAAI,CAAC,GAC3E,SAAS,GAAG,YAAY,QAAQ,MAAM,GAAI,QAAQ,UAAU,CAAC,CAAE,CAAC,CAClE;CACF,CAAC;AACH;AAEA,MAAa,WAAW,EAAE,KAAK"}
package/dist/attr.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import * as MetadataToken from "./metadataToken.js";
2
+ export type AttrToken<Name extends string = string> = MetadataToken.MetadataToken<'view.attribute', Name>;
3
+ export declare const is: (value: unknown) => value is AttrToken;
4
+ export declare const make: <const Name extends string>(name: Name) => AttrToken<Name>;
5
+ export declare const equals: (left: AttrToken, right: AttrToken) => boolean;
6
+ export declare const describe: (attr: AttrToken) => {
7
+ readonly name: string;
8
+ };
9
+ export declare const Role: AttrToken<"role">;
10
+ export declare const AriaLabel: AttrToken<"aria-label">;
11
+ export declare const AriaDescribedby: AttrToken<"aria-describedby">;
12
+ export declare const AriaExpanded: AttrToken<"aria-expanded">;
13
+ export declare const AriaSelected: AttrToken<"aria-selected">;
14
+ export declare const AriaInvalid: AttrToken<"aria-invalid">;
15
+ export declare const AriaPressed: AttrToken<"aria-pressed">;
16
+ export declare const AriaDisabled: AttrToken<"aria-disabled">;
17
+ export declare const Disabled: AttrToken<"disabled">;
18
+ export declare const Value: AttrToken<"value">;
19
+ //# sourceMappingURL=attr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attr.d.ts","names":[],"sources":["../src/attr.ts"],"mappings":";YAMY,UAAU,gCAAgC,cAAc,gCAElE;qBAGW,KAAE,mBAAqB,SAAS;qBAGhC,aAAc,qBAAmB,MAAQ,SAAO,UAAU;qBAG1D,SAAM,MAAU,WAAS,OAAS;qBAElC,WAAQ,MAAU;WAAuB;;qBAIzC,MAAI;qBACJ,WAAS;qBACT,iBAAe;qBACf,cAAY;qBACZ,cAAY;qBACZ,aAAW;qBACX,aAAW;qBACX,cAAY;qBACZ,UAAQ;qBACR,OAAK"}
package/dist/attr.js ADDED
@@ -0,0 +1,23 @@
1
+ import * as MetadataToken from "./metadataToken.js";
2
+ // src/attr.ts
3
+ /**
4
+ * Slot attribute tokens. Ported from `effect-atom-jsx/src/View.ts` `Attribute`,
5
+ * plus ARIA names the Foldkit plan lists.
6
+ */
7
+ const is = (value) => MetadataToken.is(value) && value.kind === "view.attribute";
8
+ const make = (name) => MetadataToken.make("view.attribute", name);
9
+ const equals = (left, right) => left.name === right.name;
10
+ const describe = (attr) => ({ name: attr.name });
11
+ const Role = make("role");
12
+ const AriaLabel = make("aria-label");
13
+ const AriaDescribedby = make("aria-describedby");
14
+ const AriaExpanded = make("aria-expanded");
15
+ const AriaSelected = make("aria-selected");
16
+ const AriaInvalid = make("aria-invalid");
17
+ const AriaPressed = make("aria-pressed");
18
+ const AriaDisabled = make("aria-disabled");
19
+ const Disabled = make("disabled");
20
+ const Value = make("value");
21
+ export { AriaDescribedby, AriaDisabled, AriaExpanded, AriaInvalid, AriaLabel, AriaPressed, AriaSelected, Disabled, Role, Value, describe, equals, is, make };
22
+
23
+ //# sourceMappingURL=attr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attr.js","names":[],"sources":["../src/attr.ts"],"sourcesContent":["/**\n * Slot attribute tokens. Ported from `effect-atom-jsx/src/View.ts` `Attribute`,\n * plus ARIA names the Foldkit plan lists.\n */\nimport * as MetadataToken from './metadataToken.js'\n\nexport type AttrToken<Name extends string = string> = MetadataToken.MetadataToken<\n 'view.attribute',\n Name\n>\n\nexport const is = (value: unknown): value is AttrToken =>\n MetadataToken.is(value) && value.kind === 'view.attribute'\n\nexport const make = <const Name extends string>(name: Name): AttrToken<Name> =>\n MetadataToken.make('view.attribute', name)\n\nexport const equals = (left: AttrToken, right: AttrToken): boolean => left.name === right.name\n\nexport const describe = (attr: AttrToken): { readonly name: string } => ({\n name: attr.name,\n})\n\nexport const Role = make('role')\nexport const AriaLabel = make('aria-label')\nexport const AriaDescribedby = make('aria-describedby')\nexport const AriaExpanded = make('aria-expanded')\nexport const AriaSelected = make('aria-selected')\nexport const AriaInvalid = make('aria-invalid')\nexport const AriaPressed = make('aria-pressed')\nexport const AriaDisabled = make('aria-disabled')\nexport const Disabled = make('disabled')\nexport const Value = make('value')\n"],"mappings":";;;;;;AAWA,MAAa,MAAM,UACjB,cAAc,GAAG,KAAK,KAAK,MAAM,SAAS;AAE5C,MAAa,QAAmC,SAC9C,cAAc,KAAK,kBAAkB,IAAI;AAE3C,MAAa,UAAU,MAAiB,UAA8B,KAAK,SAAS,MAAM;AAE1F,MAAa,YAAY,UAAgD,EACvE,MAAM,KAAK,KACb;AAEA,MAAa,OAAO,KAAK,MAAM;AAC/B,MAAa,YAAY,KAAK,YAAY;AAC1C,MAAa,kBAAkB,KAAK,kBAAkB;AACtD,MAAa,eAAe,KAAK,eAAe;AAChD,MAAa,eAAe,KAAK,eAAe;AAChD,MAAa,cAAc,KAAK,cAAc;AAC9C,MAAa,cAAc,KAAK,cAAc;AAC9C,MAAa,eAAe,KAAK,eAAe;AAChD,MAAa,WAAW,KAAK,UAAU;AACvC,MAAa,QAAQ,KAAK,OAAO"}
@@ -0,0 +1,18 @@
1
+ import { Attribute, ChildAttribute } from "foldkit/html";
2
+ import { MountAction } from "foldkit/mount";
3
+ export declare const isChildAttribute: (value: unknown) => value is ChildAttribute;
4
+ interface Tagged {
5
+ readonly _tag: string;
6
+ }
7
+ export declare const isTagged: (value: unknown) => value is Tagged;
8
+ /** `Class` carries no Message, so the inert builder is the honest constructor. */
9
+ export declare const classAttribute: (value: string) => Attribute<never>;
10
+ export declare const styleAttribute: (value: Record<string, string>) => Attribute<never>;
11
+ /**
12
+ * `inertHtml.OnMount` only accepts `MountAction<never>`, so a Message-bearing
13
+ * mount is built directly. The shape is the same tagged value `h.OnMount`
14
+ * produces (`{ _tag: 'OnMount', action }`).
15
+ */
16
+ export declare const mountAttribute: <Message>(action: MountAction<Message, any>) => Attribute<Message>;
17
+ export {};
18
+ //# sourceMappingURL=attribute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attribute.d.ts","names":[],"sources":["../src/attribute.ts"],"mappings":";;qBAYa,mBAAgB,mBAAqB,SAAS;UAGjD;WACC;;qBAGE,WAAQ,mBAAqB,SAAS;;qBAStC,iBAAc,kBAAoB;qBAElC,iBAAc,OAAW,2BAAyB;;;;;;qBAOlD,iBAAkB,SAAO,QAAU,YAAY,kBAAgB,UAAU"}
@@ -0,0 +1,21 @@
1
+ import { inertHtml } from "foldkit/html";
2
+ // src/attribute.ts
3
+ /** The brand `childAttribute.d.ts` stamps; Foldkit's guard is not exported. */
4
+ const CHILD_ATTRIBUTE_BRAND = "__childAttribute";
5
+ const isChildAttribute = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, CHILD_ATTRIBUTE_BRAND);
6
+ const isTagged = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, "_tag") && "_tag" in value && typeof value._tag === "string";
7
+ /** `Class` carries no Message, so the inert builder is the honest constructor. */
8
+ const classAttribute = (value) => inertHtml.Class(value);
9
+ const styleAttribute = (value) => inertHtml.Style(value);
10
+ /**
11
+ * `inertHtml.OnMount` only accepts `MountAction<never>`, so a Message-bearing
12
+ * mount is built directly. The shape is the same tagged value `h.OnMount`
13
+ * produces (`{ _tag: 'OnMount', action }`).
14
+ */
15
+ const mountAttribute = (action) => ({
16
+ _tag: "OnMount",
17
+ action
18
+ });
19
+ export { classAttribute, isChildAttribute, isTagged, mountAttribute, styleAttribute };
20
+
21
+ //# sourceMappingURL=attribute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attribute.js","names":["ih"],"sources":["../src/attribute.ts"],"sourcesContent":["/**\n * Internal attribute helpers. Foldkit's `isChildAttribute` and the tagged\n * attribute shape are not public, so this module reads them in one place.\n * Probed against foldkit 0.158.2; see docs/design/mixins-DESIGN.md.\n */\nimport type { Attribute, ChildAttribute } from 'foldkit/html'\nimport { inertHtml as ih } from 'foldkit/html'\nimport type { MountAction } from 'foldkit/mount'\n\n/** The brand `childAttribute.d.ts` stamps; Foldkit's guard is not exported. */\nconst CHILD_ATTRIBUTE_BRAND = '__childAttribute'\n\nexport const isChildAttribute = (value: unknown): value is ChildAttribute =>\n typeof value === 'object' && value !== null && Object.hasOwn(value, CHILD_ATTRIBUTE_BRAND)\n\ninterface Tagged {\n readonly _tag: string\n}\n\nexport const isTagged = (value: unknown): value is Tagged =>\n typeof value === 'object' &&\n value !== null &&\n // `hasOwn` refuses an inherited tag; `in` is what narrows the type.\n Object.hasOwn(value, '_tag') &&\n '_tag' in value &&\n typeof value._tag === 'string'\n\n/** `Class` carries no Message, so the inert builder is the honest constructor. */\nexport const classAttribute = (value: string): Attribute<never> => ih.Class(value)\n\nexport const styleAttribute = (value: Record<string, string>): Attribute<never> => ih.Style(value)\n\n/**\n * `inertHtml.OnMount` only accepts `MountAction<never>`, so a Message-bearing\n * mount is built directly. The shape is the same tagged value `h.OnMount`\n * produces (`{ _tag: 'OnMount', action }`).\n */\nexport const mountAttribute = <Message>(action: MountAction<Message, any>): Attribute<Message> =>\n ({ _tag: 'OnMount', action }) as Attribute<Message>\n"],"mappings":";;;AAUA,MAAM,wBAAwB;AAE9B,MAAa,oBAAoB,UAC/B,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO,OAAO,OAAO,qBAAqB;AAM3F,MAAa,YAAY,UACvB,OAAO,UAAU,YACjB,UAAU,QAEV,OAAO,OAAO,OAAO,MAAM,KAC3B,UAAU,SACV,OAAO,MAAM,SAAS;;AAGxB,MAAa,kBAAkB,UAAoCA,UAAG,MAAM,KAAK;AAEjF,MAAa,kBAAkB,UAAoDA,UAAG,MAAM,KAAK;;;;;;AAOjG,MAAa,kBAA2B,YACrC;CAAE,MAAM;CAAW;AAAO"}
@@ -0,0 +1,15 @@
1
+ import { Attribute } from "foldkit/html";
2
+ import { SlotAttributes } from "./resolver.js";
3
+ /** Every Foldkit attribute tag: `'Class'`, `'OnClick'`, `'DataAttribute'`, … */
4
+ export type Tag = Attribute<never>['_tag'];
5
+ /** The attribute variant carrying `T`. */
6
+ export type Of<Message, T extends Tag> = Extract<Attribute<Message>, {
7
+ readonly _tag: T;
8
+ }>;
9
+ /** The tag of one bundle entry; `undefined` for an opaque `ChildAttribute`. */
10
+ export declare const tagOf: <Message>(attribute: SlotAttributes<Message>[number]) => Tag | undefined;
11
+ /** The first attribute with `tag`, typed as that variant. */
12
+ export declare const find: <Message, T extends Tag>(attributes: SlotAttributes<Message>, tag: T) => Of<Message, T> | undefined;
13
+ /** Every attribute with `tag`, in bundle order. */
14
+ export declare const filter: <Message, T extends Tag>(attributes: SlotAttributes<Message>, tag: T) => ReadonlyArray<Of<Message, T>>;
15
+ //# sourceMappingURL=attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.d.ts","names":[],"sources":["../src/attributes.ts"],"mappings":";;;YAUY,MAAM;;YAGN,GAAG,SAAS,UAAU,OAAO,QAAQ,UAAU;WAAqB,MAAM;;;qBAGzE,QAAS,SAAO,WAAa,eAAe,qBAAmB;;qBAS/D,OAAQ,SAAS,UAAU,KAAG,YAC7B,eAAe,UAAQ,KAC9B,MACJ,GAAG,SAAS;;qBAGF,SAAU,SAAS,UAAU,KAAG,YAC/B,eAAe,UAAQ,KAC9B,MACJ,cAAc,GAAG,SAAS"}
@@ -0,0 +1,12 @@
1
+ import { isTagged } from "./attribute.js";
2
+ // src/attributes.ts
3
+ /** The tag of one bundle entry; `undefined` for an opaque `ChildAttribute`. */
4
+ const tagOf = (attribute) => isTagged(attribute) ? attribute._tag : void 0;
5
+ const hasTag = (tag) => (attribute) => tagOf(attribute) === tag;
6
+ /** The first attribute with `tag`, typed as that variant. */
7
+ const find = (attributes, tag) => attributes.find(hasTag(tag));
8
+ /** Every attribute with `tag`, in bundle order. */
9
+ const filter = (attributes, tag) => attributes.filter(hasTag(tag));
10
+ export { filter, find, tagOf };
11
+
12
+ //# sourceMappingURL=attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.js","names":[],"sources":["../src/attributes.ts"],"sourcesContent":["/**\n * Typed reads over a resolved `SlotAttributes` bundle. Foldkit's tagged\n * attribute union narrows on `_tag`, so a lookup by tag returns that variant's\n * own fields (`value`, `message`, `key`, `action`) without a cast.\n */\nimport type { Attribute } from 'foldkit/html'\nimport { isTagged } from './attribute.js'\nimport type { SlotAttributes } from './resolver.js'\n\n/** Every Foldkit attribute tag: `'Class'`, `'OnClick'`, `'DataAttribute'`, … */\nexport type Tag = Attribute<never>['_tag']\n\n/** The attribute variant carrying `T`. */\nexport type Of<Message, T extends Tag> = Extract<Attribute<Message>, { readonly _tag: T }>\n\n/** The tag of one bundle entry; `undefined` for an opaque `ChildAttribute`. */\nexport const tagOf = <Message>(attribute: SlotAttributes<Message>[number]): Tag | undefined =>\n isTagged(attribute) ? attribute._tag : undefined\n\nconst hasTag =\n <Message, T extends Tag>(tag: T) =>\n (attribute: SlotAttributes<Message>[number]): attribute is Of<Message, T> =>\n tagOf(attribute) === tag\n\n/** The first attribute with `tag`, typed as that variant. */\nexport const find = <Message, T extends Tag>(\n attributes: SlotAttributes<Message>,\n tag: T,\n): Of<Message, T> | undefined => attributes.find(hasTag<Message, T>(tag))\n\n/** Every attribute with `tag`, in bundle order. */\nexport const filter = <Message, T extends Tag>(\n attributes: SlotAttributes<Message>,\n tag: T,\n): ReadonlyArray<Of<Message, T>> => attributes.filter(hasTag<Message, T>(tag))\n"],"mappings":";;;AAgBA,MAAa,SAAkB,cAC7B,SAAS,SAAS,IAAI,UAAU,OAAO,KAAA;AAEzC,MAAM,UACqB,SACxB,cACC,MAAM,SAAS,MAAM;;AAGzB,MAAa,QACX,YACA,QAC+B,WAAW,KAAK,OAAmB,GAAG,CAAC;;AAGxE,MAAa,UACX,YACA,QACkC,WAAW,OAAO,OAAmB,GAAG,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { Attribute, ChildAttribute, HtmlBuilder } from "foldkit/html";
2
+ import { Mixin } from "./mixin.js";
3
+ import * as SlotView from "./slotView.js";
4
+ import { AttributeName, EventName, HiddenOf, SlotCapability } from "./slot.js";
5
+ import { MountAction } from "foldkit/mount";
6
+ import { SlotItem } from "./contribution.js";
7
+ export interface SlotRequirements {
8
+ readonly capability?: SlotCapability;
9
+ readonly events?: ReadonlyArray<EventName>;
10
+ readonly attributes?: ReadonlyArray<AttributeName>;
11
+ }
12
+ export interface BehaviorSlotOptions<Input, Message> {
13
+ readonly requires?: SlotRequirements;
14
+ /**
15
+ * Attributes for one resolution of the slot. `item` is present when the view
16
+ * passed one to `slots.x.attrs(base, item)`, that is, when the slot is
17
+ * rendered once per item.
18
+ */
19
+ readonly attributes?: (context: {
20
+ readonly input: Input;
21
+ readonly h: HtmlBuilder<Message>;
22
+ readonly item?: SlotItem;
23
+ }) => ReadonlyArray<Attribute<Message> | ChildAttribute>;
24
+ readonly mount?: (input: Input, item?: SlotItem) => MountAction<Message, any>;
25
+ }
26
+ export type BehaviorSpec<Slots, Input, Message> = { readonly [K in keyof Slots as HiddenOf<Slots[K]> extends true ? never : K]?: BehaviorSlotOptions<Input, Message>; };
27
+ export interface NamedBehavior<Slots, Input, Message> {
28
+ readonly name?: string;
29
+ readonly spec: BehaviorSpec<Slots, Input, Message>;
30
+ readonly mixin: Mixin<Message>;
31
+ }
32
+ /** Identity helper; `forSlots` supplies the contextual `Input`/`Message`. */
33
+ export declare const slot: <Options extends BehaviorSlotOptions<any, any>>(options: Options) => Options;
34
+ export declare const forSlots: <Slots>(slots: Slots) => <Input, Message>(spec: BehaviorSpec<Slots, Input, Message>, options?: {
35
+ readonly name?: string;
36
+ }) => NamedBehavior<Slots, Input, Message>;
37
+ /**
38
+ * Attaches a Behavior to a view. The behavior's `Input` becomes the attached
39
+ * view's `Input`: a behavior declared over only the fields it reads is rejected
40
+ * even though those fields are a subset, and one declared over extra fields
41
+ * widens what the view must be called with. Declare `Input` as the view's own
42
+ * input type.
43
+ */
44
+ export declare const attach: <BehaviorSlots, Message, Input>(behavior: NamedBehavior<BehaviorSlots, Input, Message>) => <ViewSlots>(view: SlotView.SlotView<ViewSlots, Input, Message>) => SlotView.SlotView<ViewSlots, Input, Message>;
45
+ export declare const Behavior: {
46
+ readonly slot: typeof slot;
47
+ readonly forSlots: typeof forSlots;
48
+ readonly attach: typeof attach;
49
+ };
50
+ //# sourceMappingURL=behavior.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"behavior.d.ts","names":["MixinValue"],"sources":["../src/behavior.ts"],"mappings":";;;;;;iBAkBiB;WACN,aAAa;WACb,SAAS,cAAc;WACvB,aAAa,cAAc;;iBAGrB,oBAAoB,OAAO;WACjC,WAAW;;;;;;WAMX,cAAc;aACZ,OAAO;aACP,GAAG,YAAY;aACf,OAAO;QACZ,cAAc,UAAU,WAAW;WAChC,SAAS,OAAO,OAAO,OAAO,aAAa,YAAY;;YAGtD,aAAa,OAAO,OAAO,uBAC3B,WAAW,SAAS,SAAS,MAAM,2BAA2B,KAAK,oBAC3E,OACA;iBAIa,cAAc,OAAO,OAAO;WAClC;WACA,MAAM,aAAa,OAAO,OAAO;WACjC,OAAOA,MAAW;;;qBAIhB,OAAQ,gBAAgB,+BAA6B,SAAW,YAAU;qBA2D1E,WACV,OAAK,OAAS,WACd,OAAO,SAAO,MACP,aAAa,OAAO,OAAO,UAAQ;WACpB;MACpB,cAAc,OAAO,OAAO;;;;;;;;qBA8CpB,SACV,eAAe,SAAS,OAAK,UAAY,cAAc,eAAe,OAAO,cAC7E,WAAS,MACF,SAAS,SAAS,WAAW,OAAO,aACzC,SAAS,SAAS,WAAW,OAAO;qBAG5B"}
@@ -0,0 +1,71 @@
1
+ import * as Capability from "./capability.js";
2
+ import * as MetadataToken from "./metadataToken.js";
3
+ import { DiagnosticError } from "./diagnostics.js";
4
+ import * as Mixin$1 from "./mixin.js";
5
+ import * as SlotView from "./slotView.js";
6
+ // src/behavior.ts
7
+ /** Identity helper; `forSlots` supplies the contextual `Input`/`Message`. */
8
+ const slot = (options) => options;
9
+ function fail(code, message, slotName, details) {
10
+ throw new DiagnosticError({
11
+ source: "mixins",
12
+ code,
13
+ severity: "error",
14
+ message,
15
+ slot: slotName,
16
+ ...details === void 0 ? {} : { details }
17
+ });
18
+ }
19
+ const validateRequirements = (name, slot, requirements) => {
20
+ if (requirements.capability !== void 0 && !Capability.extendsCapability(slot.capability, requirements.capability)) fail("mixins:capability-mismatch", `Behavior requires capability "${MetadataToken.nameOf(requirements.capability)}" on slot "${name}", which has "${MetadataToken.nameOf(slot.capability)}"`, name, { required: MetadataToken.nameOf(requirements.capability) });
21
+ for (const event of requirements.events ?? []) {
22
+ const eventName = MetadataToken.nameOf(event);
23
+ if (!slot.events.some((allowed) => MetadataToken.nameOf(allowed) === eventName)) fail("mixins:unsupported-event", `Behavior requires event "${eventName}" on slot "${name}", which does not publish it`, name, { event: eventName });
24
+ }
25
+ for (const attribute of requirements.attributes ?? []) {
26
+ const attributeName = MetadataToken.nameOf(attribute);
27
+ if (!slot.attributes.some((allowed) => MetadataToken.nameOf(allowed) === attributeName)) fail("mixins:unsupported-attribute", `Behavior requires attribute "${attributeName}" on slot "${name}", which does not publish it`, name, { attribute: attributeName });
28
+ }
29
+ };
30
+ const forSlots = (slots) => (spec, options) => {
31
+ const source = slots;
32
+ const contributions = Object.create(null);
33
+ for (const [name, slotOptions] of Object.entries(spec)) {
34
+ const target = source[name];
35
+ if (target === void 0) fail("mixins:unknown-slot", `Behavior targets unknown slot "${name}"`, name);
36
+ if (target.hidden) fail("mixins:hidden-slot", `Behavior targets hidden slot "${name}"`, name);
37
+ if (slotOptions?.requires !== void 0) validateRequirements(name, target, slotOptions.requires);
38
+ const attributes = slotOptions?.attributes;
39
+ const mount = slotOptions?.mount;
40
+ if (attributes === void 0 && mount === void 0) continue;
41
+ contributions[name] = (context) => ({
42
+ ...attributes === void 0 ? {} : { attributes: attributes({
43
+ input: context.input,
44
+ h: context.h,
45
+ ...context.item === void 0 ? {} : { item: context.item }
46
+ }) },
47
+ ...mount === void 0 ? {} : { mounts: [mount(context.input, context.item)] }
48
+ });
49
+ }
50
+ return Object.freeze({
51
+ ...options?.name === void 0 ? {} : { name: options.name },
52
+ spec,
53
+ mixin: Mixin$1.dynamic(options?.name ?? "Behavior", contributions)
54
+ });
55
+ };
56
+ /**
57
+ * Attaches a Behavior to a view. The behavior's `Input` becomes the attached
58
+ * view's `Input`: a behavior declared over only the fields it reads is rejected
59
+ * even though those fields are a subset, and one declared over extra fields
60
+ * widens what the view must be called with. Declare `Input` as the view's own
61
+ * input type.
62
+ */
63
+ const attach = (behavior) => (view) => SlotView.attach(behavior.mixin)(view);
64
+ const Behavior = {
65
+ slot,
66
+ forSlots,
67
+ attach
68
+ };
69
+ export { Behavior, attach, forSlots, slot };
70
+
71
+ //# sourceMappingURL=behavior.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"behavior.js","names":["Mixin"],"sources":["../src/behavior.ts"],"sourcesContent":["/**\n * `Behavior` is a named set of interaction contributions attached to declared\n * Slots. It owns no state: attributes are built from the view's `input` and `h`\n * while resolving, so the Message universe is the view's. A stateful widget is\n * a Foldkit Submodel; a continuous element listener is a Mount; a network call\n * is Message -> update -> Command.\n */\nimport type { Attribute, ChildAttribute, HtmlBuilder } from 'foldkit/html'\nimport type { MountAction } from 'foldkit/mount'\nimport * as Capability from './capability.js'\nimport type { SlotContribution, SlotItem } from './contribution.js'\nimport { DiagnosticError, type DiagnosticCode } from './diagnostics.js'\nimport * as MetadataToken from './metadataToken.js'\nimport * as Mixin from './mixin.js'\nimport type { Mixin as MixinValue } from './mixin.js'\nimport type { Any as AnySlot, AttributeName, EventName, HiddenOf, SlotCapability } from './slot.js'\nimport * as SlotView from './slotView.js'\n\nexport interface SlotRequirements {\n readonly capability?: SlotCapability\n readonly events?: ReadonlyArray<EventName>\n readonly attributes?: ReadonlyArray<AttributeName>\n}\n\nexport interface BehaviorSlotOptions<Input, Message> {\n readonly requires?: SlotRequirements\n /**\n * Attributes for one resolution of the slot. `item` is present when the view\n * passed one to `slots.x.attrs(base, item)`, that is, when the slot is\n * rendered once per item.\n */\n readonly attributes?: (context: {\n readonly input: Input\n readonly h: HtmlBuilder<Message>\n readonly item?: SlotItem\n }) => ReadonlyArray<Attribute<Message> | ChildAttribute>\n readonly mount?: (input: Input, item?: SlotItem) => MountAction<Message, any>\n}\n\nexport type BehaviorSpec<Slots, Input, Message> = {\n readonly [K in keyof Slots as HiddenOf<Slots[K]> extends true ? never : K]?: BehaviorSlotOptions<\n Input,\n Message\n >\n}\n\nexport interface NamedBehavior<Slots, Input, Message> {\n readonly name?: string\n readonly spec: BehaviorSpec<Slots, Input, Message>\n readonly mixin: MixinValue<Message>\n}\n\n/** Identity helper; `forSlots` supplies the contextual `Input`/`Message`. */\nexport const slot = <Options extends BehaviorSlotOptions<any, any>>(options: Options): Options =>\n options\n\nfunction fail(\n code: DiagnosticCode,\n message: string,\n slotName: string,\n details?: Readonly<Record<string, unknown>>,\n): never {\n throw new DiagnosticError({\n source: 'mixins',\n code,\n severity: 'error',\n message,\n slot: slotName,\n ...(details === undefined ? {} : { details }),\n })\n}\n\nconst validateRequirements = (\n name: string,\n slot: AnySlot,\n requirements: SlotRequirements,\n): void => {\n if (\n requirements.capability !== undefined &&\n !Capability.extendsCapability(slot.capability, requirements.capability)\n ) {\n fail(\n 'mixins:capability-mismatch',\n `Behavior requires capability \"${MetadataToken.nameOf(requirements.capability)}\" on slot \"${name}\", which has \"${MetadataToken.nameOf(slot.capability)}\"`,\n name,\n { required: MetadataToken.nameOf(requirements.capability) },\n )\n }\n for (const event of requirements.events ?? []) {\n const eventName = MetadataToken.nameOf(event)\n if (!slot.events.some(allowed => MetadataToken.nameOf(allowed) === eventName)) {\n fail(\n 'mixins:unsupported-event',\n `Behavior requires event \"${eventName}\" on slot \"${name}\", which does not publish it`,\n name,\n { event: eventName },\n )\n }\n }\n for (const attribute of requirements.attributes ?? []) {\n const attributeName = MetadataToken.nameOf(attribute)\n if (!slot.attributes.some(allowed => MetadataToken.nameOf(allowed) === attributeName)) {\n fail(\n 'mixins:unsupported-attribute',\n `Behavior requires attribute \"${attributeName}\" on slot \"${name}\", which does not publish it`,\n name,\n { attribute: attributeName },\n )\n }\n }\n}\n\nexport const forSlots =\n <Slots>(slots: Slots) =>\n <Input, Message>(\n spec: BehaviorSpec<Slots, Input, Message>,\n options?: { readonly name?: string },\n ): NamedBehavior<Slots, Input, Message> => {\n const source = slots as unknown as Record<string, AnySlot>\n const contributions: Record<string, SlotContribution<Message>> = Object.create(null)\n for (const [name, slotOptions] of Object.entries(\n spec as Record<string, BehaviorSlotOptions<Input, Message> | undefined>,\n )) {\n const target = source[name]\n if (target === undefined) {\n fail('mixins:unknown-slot', `Behavior targets unknown slot \"${name}\"`, name)\n }\n if (target.hidden) {\n fail('mixins:hidden-slot', `Behavior targets hidden slot \"${name}\"`, name)\n }\n if (slotOptions?.requires !== undefined) {\n validateRequirements(name, target, slotOptions.requires)\n }\n const attributes = slotOptions?.attributes\n const mount = slotOptions?.mount\n if (attributes === undefined && mount === undefined) continue\n contributions[name] = context => ({\n ...(attributes === undefined\n ? {}\n : {\n attributes: attributes({\n input: context.input as Input,\n h: context.h,\n ...(context.item === undefined ? {} : { item: context.item }),\n }),\n }),\n ...(mount === undefined ? {} : { mounts: [mount(context.input as Input, context.item)] }),\n })\n }\n return Object.freeze({\n ...(options?.name === undefined ? {} : { name: options.name }),\n spec,\n mixin: Mixin.dynamic<Message>(options?.name ?? 'Behavior', contributions),\n })\n }\n\n/**\n * Attaches a Behavior to a view. The behavior's `Input` becomes the attached\n * view's `Input`: a behavior declared over only the fields it reads is rejected\n * even though those fields are a subset, and one declared over extra fields\n * widens what the view must be called with. Declare `Input` as the view's own\n * input type.\n */\nexport const attach =\n <BehaviorSlots, Message, Input>(behavior: NamedBehavior<BehaviorSlots, Input, Message>) =>\n <ViewSlots>(\n view: SlotView.SlotView<ViewSlots, Input, Message>,\n ): SlotView.SlotView<ViewSlots, Input, Message> =>\n SlotView.attach(behavior.mixin)(view)\n\nexport const Behavior = { slot, forSlots, attach } as const\n"],"mappings":";;;;;;;AAqDA,MAAa,QAAuD,YAClE;AAEF,SAAS,KACP,MACA,SACA,UACA,SACO;CACP,MAAM,IAAI,gBAAgB;EACxB,QAAQ;EACR;EACA,UAAU;EACV;EACA,MAAM;EACN,GAAI,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ;CAC7C,CAAC;AACH;AAEA,MAAM,wBACJ,MACA,MACA,iBACS;CACT,IACE,aAAa,eAAe,KAAA,KAC5B,CAAC,WAAW,kBAAkB,KAAK,YAAY,aAAa,UAAU,GAEtE,KACE,8BACA,iCAAiC,cAAc,OAAO,aAAa,UAAU,EAAE,aAAa,KAAK,gBAAgB,cAAc,OAAO,KAAK,UAAU,EAAE,IACvJ,MACA,EAAE,UAAU,cAAc,OAAO,aAAa,UAAU,EAAE,CAC5D;CAEF,KAAK,MAAM,SAAS,aAAa,UAAU,CAAC,GAAG;EAC7C,MAAM,YAAY,cAAc,OAAO,KAAK;EAC5C,IAAI,CAAC,KAAK,OAAO,MAAK,YAAW,cAAc,OAAO,OAAO,MAAM,SAAS,GAC1E,KACE,4BACA,4BAA4B,UAAU,aAAa,KAAK,+BACxD,MACA,EAAE,OAAO,UAAU,CACrB;CAEJ;CACA,KAAK,MAAM,aAAa,aAAa,cAAc,CAAC,GAAG;EACrD,MAAM,gBAAgB,cAAc,OAAO,SAAS;EACpD,IAAI,CAAC,KAAK,WAAW,MAAK,YAAW,cAAc,OAAO,OAAO,MAAM,aAAa,GAClF,KACE,gCACA,gCAAgC,cAAc,aAAa,KAAK,+BAChE,MACA,EAAE,WAAW,cAAc,CAC7B;CAEJ;AACF;AAEA,MAAa,YACH,WAEN,MACA,YACyC;CACzC,MAAM,SAAS;CACf,MAAM,gBAA2D,OAAO,OAAO,IAAI;CACnF,KAAK,MAAM,CAAC,MAAM,gBAAgB,OAAO,QACvC,IACF,GAAG;EACD,MAAM,SAAS,OAAO;EACtB,IAAI,WAAW,KAAA,GACb,KAAK,uBAAuB,kCAAkC,KAAK,IAAI,IAAI;EAE7E,IAAI,OAAO,QACT,KAAK,sBAAsB,iCAAiC,KAAK,IAAI,IAAI;EAE3E,IAAI,aAAa,aAAa,KAAA,GAC5B,qBAAqB,MAAM,QAAQ,YAAY,QAAQ;EAEzD,MAAM,aAAa,aAAa;EAChC,MAAM,QAAQ,aAAa;EAC3B,IAAI,eAAe,KAAA,KAAa,UAAU,KAAA,GAAW;EACrD,cAAc,SAAQ,aAAY;GAChC,GAAI,eAAe,KAAA,IACf,CAAC,IACD,EACE,YAAY,WAAW;IACrB,OAAO,QAAQ;IACf,GAAG,QAAQ;IACX,GAAI,QAAQ,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,QAAQ,KAAK;GAC7D,CAAC,EACH;GACJ,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,QAAQ,OAAgB,QAAQ,IAAI,CAAC,EAAE;EACzF;CACF;CACA,OAAO,OAAO,OAAO;EACnB,GAAI,SAAS,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,QAAQ,KAAK;EAC5D;EACA,OAAOA,QAAM,QAAiB,SAAS,QAAQ,YAAY,aAAa;CAC1E,CAAC;AACH;;;;;;;;AASF,MAAa,UACqB,cAE9B,SAEA,SAAS,OAAO,SAAS,KAAK,CAAC,CAAC,IAAI;AAExC,MAAa,WAAW;CAAE;CAAM;CAAU;AAAO"}