foldkit-mixins 0.3.0 → 0.4.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.
- package/README.md +244 -10
- package/dist/core-B86QnDhB.d.mts +40 -0
- package/dist/core-B86QnDhB.d.mts.map +1 -0
- package/dist/core-izIY2GSX.mjs +53 -0
- package/dist/core-izIY2GSX.mjs.map +1 -0
- package/dist/defaults.d.mts +27 -0
- package/dist/defaults.d.mts.map +1 -0
- package/dist/defaults.mjs +71 -0
- package/dist/defaults.mjs.map +1 -0
- package/dist/diagnostics-YJ7991-A.mjs +15 -0
- package/dist/diagnostics-YJ7991-A.mjs.map +1 -0
- package/dist/index.d.mts +232 -76
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +486 -229
- package/dist/index.mjs.map +1 -1
- package/dist/layers-CJS5d1i7.mjs +197 -0
- package/dist/layers-CJS5d1i7.mjs.map +1 -0
- package/dist/layers.d.mts +47 -0
- package/dist/layers.d.mts.map +1 -0
- package/dist/layers.mjs +2 -0
- package/dist/layout.d.mts +114 -0
- package/dist/layout.d.mts.map +1 -0
- package/dist/layout.mjs +154 -0
- package/dist/layout.mjs.map +1 -0
- package/dist/prose.d.mts +24 -0
- package/dist/prose.d.mts.map +1 -0
- package/dist/prose.mjs +57 -0
- package/dist/prose.mjs.map +1 -0
- package/dist/styleValue--iQMTcPn.mjs +242 -0
- package/dist/styleValue--iQMTcPn.mjs.map +1 -0
- package/dist/styleValue-C9vAKt7A.d.mts +77 -0
- package/dist/styleValue-C9vAKt7A.d.mts.map +1 -0
- package/dist/theme.d.mts +412 -0
- package/dist/theme.d.mts.map +1 -0
- package/dist/theme.mjs +278 -0
- package/dist/theme.mjs.map +1 -0
- package/package.json +32 -7
package/README.md
CHANGED
|
@@ -102,6 +102,10 @@ pnpm add foldkit-mixins
|
|
|
102
102
|
`foldkit` and `effect` are peer dependencies. `foldkit-mixins-surface` bridges a Surface
|
|
103
103
|
projection, and `foldkit-mixins-ui` adapts `@foldkit/ui` components.
|
|
104
104
|
|
|
105
|
+
The design-system pieces are subpaths, so an application that only attaches classes pays for
|
|
106
|
+
none of them: `foldkit-mixins/layers`, `/theme`, `/layout`, `/defaults`, and `/prose` (see
|
|
107
|
+
[styleImprovements-DESIGN.md](../../docs/design/styleImprovements-DESIGN.md)).
|
|
108
|
+
|
|
105
109
|
## Quick start
|
|
106
110
|
|
|
107
111
|
The component author publishes the extension points. Style and Behavior can then be authored
|
|
@@ -161,20 +165,41 @@ const Field = SlotView.forMessages<Message>()
|
|
|
161
165
|
Base attributes, event Messages and any `ChildAttribute` survive. The caller did not copy the
|
|
162
166
|
markup or add a `validationBehavior` prop to the component.
|
|
163
167
|
|
|
168
|
+
### Render it and interpret the result
|
|
169
|
+
|
|
170
|
+
`Field` is a view function. From a parent view with a compatible builder, call
|
|
171
|
+
`Field({ value: model.value, invalid: model.invalid }, h)`. The input's value
|
|
172
|
+
comes from the parent; typing emits `ChangedValue`; the parent update must
|
|
173
|
+
store that value before the next render. Mixins owns none of that state.
|
|
174
|
+
|
|
175
|
+
In this example, `FieldStyle` supplies classes and a grid layout, while
|
|
176
|
+
`Validation` supplies `aria-invalid`. The input's `OnInput` remains owned by
|
|
177
|
+
the base view. Adding another `OnInput` attachment is a conflict, not a way to
|
|
178
|
+
chain a second application update. Compose the action in the existing Message
|
|
179
|
+
handler instead.
|
|
180
|
+
|
|
181
|
+
For `Style.pseudo`, `Style.media`, or other compiled rules, also install the
|
|
182
|
+
text returned by `Style.stylesheet(style)` in the page. Calling a SlotView
|
|
183
|
+
returns HTML; it does not inject a stylesheet for you.
|
|
184
|
+
|
|
164
185
|
## What the resolver guarantees
|
|
165
186
|
|
|
166
187
|
Attachments are not concatenated and left to renderer order. The resolver applies explicit rules:
|
|
167
188
|
|
|
168
189
|
- classes are additive and deduplicated into one `Class`;
|
|
169
|
-
- inline styles merge per property,
|
|
190
|
+
- inline styles from Style pieces merge per property, later attachments winning, over the
|
|
191
|
+
view's base; a property a Behavior sets (through `h.Style` in its attributes) has exactly one
|
|
192
|
+
owner, so a Style piece, the base, or a second Behavior setting the same property is an error;
|
|
170
193
|
- an event or scalar attribute has exactly one owner — a second owner is an error;
|
|
171
194
|
- a `ChildAttribute` (a Submodel's published handler) is preserved by identity;
|
|
172
195
|
- `Key` and `InnerHTML` are structural and cannot be overridden;
|
|
173
196
|
- multiple mount contributions compose into exactly one `OnMount`.
|
|
174
197
|
|
|
175
198
|
Conflicts throw `Diagnostics.DiagnosticError` with stable codes such as
|
|
176
|
-
`mixins:event-conflict` and `mixins:protected-attribute`, so tests,
|
|
177
|
-
all speak the same diagnostic language.
|
|
199
|
+
`mixins:event-conflict`, `mixins:style-property-conflict` and `mixins:protected-attribute`, so tests,
|
|
200
|
+
DevTools and editor tooling can all speak the same diagnostic language. The style rule exists
|
|
201
|
+
because a positioning Behavior that writes `top` and a Style that also sets `top` would otherwise
|
|
202
|
+
fight silently, last writer winning.
|
|
178
203
|
|
|
179
204
|
## Slots: the public contract
|
|
180
205
|
|
|
@@ -209,6 +234,12 @@ Names come from the keys passed to `Slots.define`; they are never repeated insid
|
|
|
209
234
|
|
|
210
235
|
Style is pure data. It never touches the DOM.
|
|
211
236
|
|
|
237
|
+
Every piece takes `Declarations`: camelCase CSS properties (typed by
|
|
238
|
+
[`csstype`](https://github.com/frenic/csstype)) and custom properties, each a
|
|
239
|
+
string. A misspelled or kebab-case property in an object literal is a type
|
|
240
|
+
error; the compiler writes the kebab-case name. Values are not checked, so
|
|
241
|
+
`var(...)` and `light-dark(...)` pass through.
|
|
242
|
+
|
|
212
243
|
| Primitive | Meaning |
|
|
213
244
|
| --- | --- |
|
|
214
245
|
| `Style.class(...)` | class tokens |
|
|
@@ -216,10 +247,18 @@ Style is pure data. It never touches the DOM.
|
|
|
216
247
|
| `Style.compose(...)` | concatenate classes; later declarations win per property |
|
|
217
248
|
| `Style.when(condition, piece)` | a boolean known at authoring time |
|
|
218
249
|
| `Style.whenInput(predicate, piece)` | a condition read from the view input at render time |
|
|
219
|
-
| `Style.recipe({ base, variants, defaults, compound })` | returns `selection => StyleValue` |
|
|
220
|
-
| `Style.
|
|
250
|
+
| `Style.recipe({ base, variants, defaults, compound })` | one slot: returns `selection => StyleValue` |
|
|
251
|
+
| `Style.recipeFor(Slots)({ base, variants, defaults, compound })` | every slot: returns `selection => StylePieces`; `null` unsets a defaulted axis; `.extend(patch)` merges per slot and refuses a slot the contract lacks |
|
|
252
|
+
| `Style.perItem(item => piece)` / `Style.stagger({ stepMs })` | a piece from the item the slot is rendered for (`attrs(base, item)`); stagger writes `--fk-index` and a `calc` delay |
|
|
253
|
+
| `Style.forCapability(Slots)(capability, piece)` | one piece for every public slot whose capability satisfies it |
|
|
254
|
+
| `Style.self` / `pseudo` / `media` / `supports` / `container` / `nest` | rule-based appearance; `self` is a rule on the element's own class (`&{…}`), for declarations a layer must hold |
|
|
221
255
|
| `Style.keyframes` / `global` | class-independent CSS |
|
|
222
|
-
| `Theme.define` / `
|
|
256
|
+
| `Theme.define` / `Theme.ref(theme)` / `variables` | typed tokens; every token as a typed `var(--fk-group-name)` reference (`Theme.ref(theme).surface.base`), built once per theme; the tokens as inline custom properties |
|
|
257
|
+
| `Theme.lightDark(light, dark)` / `Theme.compose(base, over)` | a token that follows the color scheme with CSS `light-dark()`; themes merged at definition time |
|
|
258
|
+
| `Theme.root(theme, { omit?, colorScheme? })` / `Theme.scoped(theme, selector, overrides)` | from `foldkit-mixins/theme`: tokens as `:root` custom properties, or as overrides under a selector; unlayered global pieces for `Style.stylesheet` |
|
|
259
|
+
| `Theme.tokens` / `Theme.oklch(knobs)` / `Theme.breakpointWidths(theme)` | from `foldkit-mixins/theme`: the shipped spacing, type, radius, motion, border and breakpoint scales; a whole palette derived from an accent and a few knobs; the breakpoints as pixel widths for `foldkit-primitives/media` |
|
|
260
|
+
| `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` |
|
|
261
|
+
| `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 |
|
|
223
262
|
|
|
224
263
|
Rule-based Style compiles to one deterministic class (an FNV-1a hash of canonical rule text) plus
|
|
225
264
|
CSS as data:
|
|
@@ -237,15 +276,143 @@ CardStyle.css
|
|
|
237
276
|
Style.stylesheet(FieldStyle, CardStyle)
|
|
238
277
|
```
|
|
239
278
|
|
|
240
|
-
Equal rules share a class, so server and client derive the same class and CSS.
|
|
241
|
-
`Style.whenInput`
|
|
242
|
-
|
|
279
|
+
Equal rules share a class, so server and client derive the same class and CSS. A rule piece
|
|
280
|
+
inside `Style.whenInput` compiles to its class like any other; the class is static and only its
|
|
281
|
+
presence follows the input, and its CSS is in `Style.stylesheet` whether or not the condition
|
|
282
|
+
ever holds.
|
|
283
|
+
|
|
284
|
+
Beyond `self`, `pseudo`, `media`, `supports`, `container` and `nest`, the rule pieces are:
|
|
285
|
+
|
|
286
|
+
- `Style.states({ open: { opacity: '1' } })` compiles to `&[data-state="open"]`, for Behaviors that
|
|
287
|
+
write `data-state`; `whenInput` when the view knows, `states` when the DOM does;
|
|
288
|
+
- `Style.responsive(breakpoints, { md: { display: 'flex' } })`, named breakpoints from the record
|
|
289
|
+
you pass, so a misspelled one is a type error;
|
|
290
|
+
- `Style.enter({ opacity: '0' })`, a `@starting-style` rule the element animates from, with
|
|
291
|
+
`Style.allowDiscrete` when `display` takes part;
|
|
292
|
+
- `Style.vars({ '--gap': '1rem' })` and `Style.viewTransitionName('hero')`, declarations;
|
|
293
|
+
- `Style.grid({ areas: [['header', 'header'], ['nav', 'main']], columns, rows, gap })`, a grid
|
|
294
|
+
template with typed areas: `.style` for the container and `.area('main')` for a child, where
|
|
295
|
+
a name the template lacks is a type error and a ragged template raises
|
|
296
|
+
`mixins:ragged-grid-areas`;
|
|
297
|
+
- `Selector.attr`, `not`, `is`, `child`, `descendant`, `sibling`, `siblings` build the selector
|
|
298
|
+
strings `pseudo` and `nest` take. Each takes a selector list: every top-level selector is
|
|
299
|
+
scoped to the class (`:is(a, b)` is not split), and a selector that writes `&` places the class
|
|
300
|
+
itself (`nest('[data-open] &')`).
|
|
301
|
+
|
|
302
|
+
### Theme from a few knobs
|
|
303
|
+
|
|
304
|
+
`foldkit-mixins/theme` extends the root `Theme` with the pieces a page ships. `Theme.oklch` takes
|
|
305
|
+
an accent color and a few knobs (hue shifts, surface saturation and contrast, a contrast factor,
|
|
306
|
+
feedback hues) and returns typed tokens for surfaces, text, outlines, and the accent, secondary,
|
|
307
|
+
tertiary and feedback families. Only the `knob` group holds literals; every other value is a CSS
|
|
308
|
+
expression over other tokens (`oklch(from …)`, `color-mix()`, `light-dark()`), so the browser does
|
|
309
|
+
the derivation and one knob override recolors everything below it. `Theme.tokens` is the
|
|
310
|
+
non-color scales, with `space` and `radius` multiplied by the `density` and `radius-factor` knobs.
|
|
311
|
+
|
|
312
|
+
A theme reaches the page as pieces, and the page chooses the layers:
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
import { Layers, Slot, Slots, Capability, Style } from 'foldkit-mixins'
|
|
316
|
+
import { Theme } from 'foldkit-mixins/theme'
|
|
317
|
+
|
|
318
|
+
const L = Layers.standard
|
|
319
|
+
const theme = Theme.compose(Theme.tokens, Theme.oklch({ accent: { h: 280, c: 0.15, l: '60%' } }))
|
|
320
|
+
const t = Theme.ref(theme) // t.surface.base is 'var(--fk-surface-base)'; a missing name is a type error
|
|
321
|
+
|
|
322
|
+
const PageSlots = Slots.define({ root: Slot.make({ capability: Capability.Container }) })
|
|
323
|
+
// Born in the app layer: the view attaches this same value, so its classes are the sheet's.
|
|
324
|
+
const PageStyle = Style.forSlots(PageSlots)(
|
|
325
|
+
{ root: Style.self({ background: t.surface.base, color: t.text.default }) },
|
|
326
|
+
{ layer: L.layer('app') },
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
export const sheet = Style.stylesheet(
|
|
330
|
+
L.declare,
|
|
331
|
+
L.in('tokens', Theme.root(Theme.tokens)),
|
|
332
|
+
L.in('theme', Theme.root(theme, { omit: Theme.tokens })),
|
|
333
|
+
L.in('theme', Theme.scoped(theme, ':root[data-theme="ocean"]', { knob: { 'accent-h': '215' } })),
|
|
334
|
+
PageStyle,
|
|
335
|
+
)
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Once the sheet declares an order, every rule in it must sit in one of its layers: an unlayered
|
|
339
|
+
rule would beat all of them, `app` included, so `Style.stylesheet` refuses it with
|
|
340
|
+
`style:unlayered-rule`. A slot style takes its layer when it is compiled, with the `layer`
|
|
341
|
+
option; a layout or recipe it composes keeps the layer it was already given. `L.in` takes only
|
|
342
|
+
bare pieces: a layer is part of a rule's identity, so layering a finished style would copy it
|
|
343
|
+
under new class names that no view attaches.
|
|
344
|
+
|
|
345
|
+
`omit` leaves out the tokens another theme already declared, so the scales go out once in
|
|
346
|
+
`tokens` and the palette once in `theme`. Which theme is active is a Model fact: the view writes
|
|
347
|
+
`data-theme` on the root, and `Theme.scoped` only says what the value means. A scheme the user
|
|
348
|
+
picks works the same way with a `data-color-scheme` selector and a `color-scheme` override; a
|
|
349
|
+
scheme the browser picks needs nothing, because the `light-dark()` values follow it. The palette
|
|
350
|
+
needs relative color syntax and `light-dark()` (Chrome 123, Firefox 128, Safari 17.5).
|
|
351
|
+
|
|
352
|
+
`Style.responsive(Theme.tokens.breakpoint, { md: { … } })` and
|
|
353
|
+
`Theme.breakpointWidths(Theme.tokens)` (for the `Breakpoints` bundle) name the same breakpoints;
|
|
354
|
+
a query that is not a plain `min-width` raises `theme:unparseable-breakpoint`.
|
|
355
|
+
|
|
356
|
+
### Layout
|
|
357
|
+
|
|
358
|
+
`foldkit-mixins/layout` ships the common arrangements as pieces: `Layout.stack`, `cluster`,
|
|
359
|
+
`split`, `sidebar`, `switcher`, `reel`, `center`, `frame`, `pad`, and `autoGrid`, plus
|
|
360
|
+
`Layout.intrinsic` (a stack child that keeps its own width) and `Layout.aside` (the sidebar
|
|
361
|
+
child). Each compiles to rule text that is the same for every caller and reads `--fk-l-*`
|
|
362
|
+
variables with token fallbacks; the options only write those variables inline, so ten stacks
|
|
363
|
+
with ten gaps are one rule and ten inline declarations. The pieces are unlayered; put them in
|
|
364
|
+
`layouts`:
|
|
365
|
+
|
|
366
|
+
```ts
|
|
367
|
+
import { Layers, Style } from 'foldkit-mixins'
|
|
368
|
+
import { Layout } from 'foldkit-mixins/layout'
|
|
369
|
+
|
|
370
|
+
const L = Layers.standard
|
|
371
|
+
|
|
372
|
+
const CardStyle = Style.forSlots(CardSlots)({
|
|
373
|
+
root: L.in('layouts', Layout.stack({ gap: 'var(--fk-space-sm)' })),
|
|
374
|
+
actions: L.in('layouts', Layout.cluster({ justify: 'end' })),
|
|
375
|
+
})
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
`split` adapts to its container by default (`container-type: inline-size` and a `@container`
|
|
379
|
+
query); `{ contain: false }` uses `@media` on the viewport instead. Its breakpoint and
|
|
380
|
+
`stack`'s `split` index are in the rule text, because a query cannot read a variable, so each
|
|
381
|
+
distinct value is its own class. `sidebar` and `switcher` are flex math and need no query.
|
|
382
|
+
|
|
383
|
+
### Defaults and prose
|
|
384
|
+
|
|
385
|
+
`foldkit-mixins/defaults` is the baseline plain HTML gets before any slot is styled: `Defaults.reset`
|
|
386
|
+
(box model, media, form-control fonts, reduced motion) and `body`, `headings`, `links`, `code`,
|
|
387
|
+
`controls`, composed as `Defaults.all` (everything except `reset`). Each is element-selector CSS
|
|
388
|
+
under `:where()` over `--fk-*` tokens with a fallback, so a class rule always beats it and it reads
|
|
389
|
+
with or without a theme. `foldkit-mixins/prose` is the longform contract: `Prose.style({ measure?,
|
|
390
|
+
rhythm? })` is one class for every caller (the rhythm between unlike elements: heading to
|
|
391
|
+
paragraph, list to paragraph, around figures) whose options are `--fk-prose-*` variables on the
|
|
392
|
+
element. Both are unlayered; the page places them:
|
|
393
|
+
|
|
394
|
+
```ts
|
|
395
|
+
import { Layers, Style } from 'foldkit-mixins'
|
|
396
|
+
import { Defaults } from 'foldkit-mixins/defaults'
|
|
397
|
+
import { Prose } from 'foldkit-mixins/prose'
|
|
398
|
+
|
|
399
|
+
const L = Layers.standard
|
|
400
|
+
const Article = Style.forSlots(ArticleSlots)({ body: L.in('components', Prose.style({ measure: '60ch' })) })
|
|
401
|
+
|
|
402
|
+
export const sheet = Style.stylesheet(
|
|
403
|
+
L.declare,
|
|
404
|
+
L.in('reset', Defaults.reset),
|
|
405
|
+
L.in('defaults', Defaults.all),
|
|
406
|
+
Article,
|
|
407
|
+
)
|
|
408
|
+
```
|
|
243
409
|
|
|
244
410
|
## Behavior: reusable element-level interaction
|
|
245
411
|
|
|
246
412
|
A Behavior is a reusable bundle of element-level interaction that does **not** own application
|
|
247
413
|
state. Its attributes are built while resolving from the view's `input` and `h`, so it can only
|
|
248
|
-
emit Messages from the view's own Message universe.
|
|
414
|
+
emit Messages from the view's own Message universe. Like an agent capability,
|
|
415
|
+
a Behavior points one way — toward a Message — and never gets a Model setter.
|
|
249
416
|
|
|
250
417
|
```ts
|
|
251
418
|
const Focus = Behavior.forSlots(FieldSlots)<FieldInput, Message>({
|
|
@@ -261,6 +428,73 @@ const Focus = Behavior.forSlots(FieldSlots)<FieldInput, Message>({
|
|
|
261
428
|
`Event.Click` cannot attach to a slot that did not publish click. Multiple mount contributions
|
|
262
429
|
compose into one `OnMount` per element.
|
|
263
430
|
|
|
431
|
+
A slot rendered once per item (rows, tabs, options) tells the Behavior which repetition it is
|
|
432
|
+
resolving through the second argument of `attrs`:
|
|
433
|
+
|
|
434
|
+
```ts
|
|
435
|
+
h.ul(slots.list.attrs(), items.map((item, index) =>
|
|
436
|
+
h.li(slots.row.attrs([h.Key(item.id)], { index, id: item.id, count: items.length }), [item.label]),
|
|
437
|
+
))
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
The Behavior receives it as `item` (`{ index, id?, count? }`) in `attributes` and as the second
|
|
441
|
+
argument of `mount`, so one Behavior can write `tabindex="0"` on the current row and `-1` on the
|
|
442
|
+
rest, or `aria-posinset` and `aria-setsize` on each. Without an item argument, `item` is
|
|
443
|
+
`undefined` and the Behavior decorates the slot as a single element.
|
|
444
|
+
|
|
445
|
+
### Ready-made Behaviors
|
|
446
|
+
|
|
447
|
+
`Behaviors` holds Behaviors that own no state. The first is `Collection`: describe the parent's
|
|
448
|
+
array once, and a view and the Behaviors on it agree about identity, order, and disabled items.
|
|
449
|
+
|
|
450
|
+
```ts
|
|
451
|
+
import { Behaviors } from 'foldkit-mixins'
|
|
452
|
+
|
|
453
|
+
const items = Behaviors.Collection.of(input.tools, {
|
|
454
|
+
id: tool => tool.id,
|
|
455
|
+
disabled: tool => tool.disabled,
|
|
456
|
+
}) // ids, size, at, indexOf, isDisabled, enabled, slotItem
|
|
457
|
+
|
|
458
|
+
const Ids = Behaviors.Collection.behavior(ToolbarSlots)<ToolbarInput, Message>({
|
|
459
|
+
item: 'tool',
|
|
460
|
+
items: input => Behaviors.Collection.of(input.tools, { id: tool => tool.id }),
|
|
461
|
+
posInSet: true,
|
|
462
|
+
})
|
|
463
|
+
|
|
464
|
+
// in the view: slots.tool.attrs([h.Key(tool.id)], items.slotItem(index))
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
`of` is pure and refuses two items with one id (`mixins:duplicate-item-id`), since an id is what
|
|
468
|
+
`aria-activedescendant` and `aria-controls` rely on. The Behavior writes `id`, `aria-disabled`,
|
|
469
|
+
and with `posInSet` `aria-posinset` and `aria-setsize`, reading the item context the view passes;
|
|
470
|
+
it contributes nothing to a slot resolved without one. Behaviors that need state, such as a
|
|
471
|
+
roving tab stop or a press, live in `foldkit-primitives` as a Bundle plus its Behavior.
|
|
472
|
+
|
|
473
|
+
Four more stateless Behaviors say a parent's state in ARIA, so a custom view
|
|
474
|
+
gets it right without hand-writing it. Each takes slot names and functions of
|
|
475
|
+
the view's input; none owns anything.
|
|
476
|
+
|
|
477
|
+
- `Behaviors.Disclosure.behavior(Slots)<Input, Message>({ trigger, content, open, id })`
|
|
478
|
+
writes `aria-expanded` and `aria-controls` on the trigger, `id` and `hidden`
|
|
479
|
+
on the content. The floor is `<details>`.
|
|
480
|
+
- `Behaviors.ToggleState.behavior(Slots)({ control, state, as: 'checked' | 'pressed' })`
|
|
481
|
+
writes `aria-checked` (checkbox, switch, radio, option) or `aria-pressed` (a
|
|
482
|
+
toggle button) from a `boolean | 'mixed'`.
|
|
483
|
+
- `Behaviors.FieldAssociation.behavior(Slots)({ control, label, description?, error?, id, invalid?, required? })`
|
|
484
|
+
derives `<id>`, `<id>-label`, `<id>-description`, `<id>-error` from one base
|
|
485
|
+
id (`FieldAssociation.ids(id)` for a view that renders them itself) and
|
|
486
|
+
writes `id`, `for`, `aria-labelledby`, `aria-describedby` (the error joins
|
|
487
|
+
while `invalid`), `aria-invalid`, `aria-required`. Derived, not minted, so a
|
|
488
|
+
resumed page and a test agree.
|
|
489
|
+
- `Behaviors.SpinValue.behavior(Slots)({ control, value, onChange, min?, max?, step?, page?, text? })`
|
|
490
|
+
writes the `spinbutton` role and `aria-value*`, and steps the parent's number
|
|
491
|
+
with ArrowUp and ArrowDown by `step`, PageUp and PageDown by `page` (default
|
|
492
|
+
ten steps), Home and End to the bounds, clamped and default-prevented;
|
|
493
|
+
`SpinValue.spin(value, key, modifiers, bounds)` is the pure step. A
|
|
494
|
+
press-and-hold repeat and the wheel are not handled: Foldkit's wheel
|
|
495
|
+
attribute carries no delta, and a repeat is a timer the Model would own.
|
|
496
|
+
|
|
497
|
+
|
|
264
498
|
## SlotView
|
|
265
499
|
|
|
266
500
|
`SlotView.define(slots, render)` is a pure view that publishes slots. Attach with
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { a as StyleValue } from "./styleValue-C9vAKt7A.mjs";
|
|
2
|
+
declare namespace core_d_exports {
|
|
3
|
+
export { Refs, Theme, ThemeTokens, VAR_PREFIX, compose, define, lightDark, ref, variables };
|
|
4
|
+
}
|
|
5
|
+
type ThemeTokens = {
|
|
6
|
+
readonly [group: string]: {
|
|
7
|
+
readonly [name: string]: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
type Theme<T extends ThemeTokens = ThemeTokens> = T;
|
|
11
|
+
declare const VAR_PREFIX = "--fk";
|
|
12
|
+
declare const define: <T extends ThemeTokens>(tokens: T) => Readonly<T>;
|
|
13
|
+
/** `var(--fk-group-name)` for every token, by the theme's own group and token names. */
|
|
14
|
+
type Refs<T extends ThemeTokens> = { readonly [G in keyof T & string]: { readonly [N in keyof T[G] & string]: string; }; };
|
|
15
|
+
/**
|
|
16
|
+
* The theme's tokens as references: `Theme.ref(theme).surface.overt` is
|
|
17
|
+
* `var(--fk-surface-overt)`, and a group or name the theme lacks is a type
|
|
18
|
+
* error. Only the names are read, never the values. Built once per theme.
|
|
19
|
+
*/
|
|
20
|
+
declare const ref: <T extends ThemeTokens>(theme: T) => Refs<T>;
|
|
21
|
+
declare const variables: <T extends ThemeTokens>(theme: T) => StyleValue;
|
|
22
|
+
/**
|
|
23
|
+
* A token that follows the user's color scheme with CSS `light-dark()`: no
|
|
24
|
+
* JavaScript and no Model field. A theme the user chooses is the other case,
|
|
25
|
+
* and belongs in the Model as a class on the root; `variables` compiles both.
|
|
26
|
+
*/
|
|
27
|
+
declare const lightDark: (light: string, dark: string) => string;
|
|
28
|
+
type Merge<A, B> = { readonly [G in keyof A | keyof B]: G extends keyof B ? G extends keyof A ? A[G] & B[G] : B[G] : G extends keyof A ? A[G] : never; };
|
|
29
|
+
/** Themes merged at definition time, later tokens winning within a group. */
|
|
30
|
+
declare const compose: <A extends ThemeTokens, B extends ThemeTokens>(base: A, over: B) => Readonly<Merge<A, B>>;
|
|
31
|
+
declare const Theme: {
|
|
32
|
+
readonly define: <T extends ThemeTokens>(tokens: T) => Readonly<T>;
|
|
33
|
+
readonly ref: <T extends ThemeTokens>(theme: T) => Refs<T>;
|
|
34
|
+
readonly variables: <T extends ThemeTokens>(theme: T) => StyleValue;
|
|
35
|
+
readonly lightDark: (light: string, dark: string) => string;
|
|
36
|
+
readonly compose: <A extends ThemeTokens, B extends ThemeTokens>(base: A, over: B) => Readonly<Merge<A, B>>;
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { compose as a, lightDark as c, VAR_PREFIX as i, ref as l, Theme as n, core_d_exports as o, ThemeTokens as r, define as s, Refs as t, variables as u };
|
|
40
|
+
//# sourceMappingURL=core-B86QnDhB.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-B86QnDhB.d.mts","names":[],"sources":["../src/theme/core.ts"],"mappings":";;;;KAOY;YACA;cAA4B;;;KAG5B,MAAM,UAAU,cAAc,eAAe;cAE5C;cAEA,SAAU,UAAU,aAAa,QAAQ,MAAI,SAAS;;KAQvD,KAAK,UAAU,2BACf,WAAW,yBAAyB,WAAW,EAAE;;;;;;cAUhD,MAAO,UAAU,aAAa,OAAO,MAAI,KAAK;cAmB9C,YAAa,UAAU,aAAa,OAAO,MAAI;;;;;;cAe/C,YAAa,eAAe;KAEpC,MAAM,GAAG,iBACF,WAAW,UAAU,IAAI,gBAAgB,IAC/C,gBAAgB,IACd,EAAE,KAAK,EAAE,KACT,EAAE,KACJ,gBAAgB,IACd,EAAE;;cAKG,UAAW,UAAU,aAAa,UAAU,aACvD,MAAM,GACN,MAAM,MACL,SAAS,MAAM,GAAG;cAUR;WA/EU,SAAA,UAAU,aAAW,QAAU,MAAI,SAAS;WAmB/C,MAAA,UAAU,aAAW,OAAS,MAAI,KAAK;WAmBjC,YAAA,UAAU,aAAW,OAAS,MAAI;WAe3B,YAAA,eAAM;WAaf,UAAA,UAAU,aAAa,UAAU,aAAW,MAC5D,GAAC,MACD,MACL,SAAS,MAAM,GAAG"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { l as inline } from "./styleValue--iQMTcPn.mjs";
|
|
2
|
+
//#region src/theme/core.ts
|
|
3
|
+
/**
|
|
4
|
+
* `Theme` is typed token data, not a service. Dynamic theme state (light/dark)
|
|
5
|
+
* belongs in the Foldkit Model; `variables` compiles the tokens to CSS custom
|
|
6
|
+
* properties so switching a class or a root style is cheap and SSR-safe.
|
|
7
|
+
*/
|
|
8
|
+
const VAR_PREFIX = "--fk";
|
|
9
|
+
const define = (tokens) => Object.freeze(Object.fromEntries(Object.entries(tokens).map(([group, names]) => [group, Object.freeze({ ...names })])));
|
|
10
|
+
const refsByTheme = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
/**
|
|
12
|
+
* The theme's tokens as references: `Theme.ref(theme).surface.overt` is
|
|
13
|
+
* `var(--fk-surface-overt)`, and a group or name the theme lacks is a type
|
|
14
|
+
* error. Only the names are read, never the values. Built once per theme.
|
|
15
|
+
*/
|
|
16
|
+
const ref = (theme) => {
|
|
17
|
+
const cached = refsByTheme.get(theme);
|
|
18
|
+
if (cached !== void 0) return cached;
|
|
19
|
+
const built = Object.freeze(Object.fromEntries(Object.entries(theme).map(([group, names]) => [group, Object.freeze(Object.fromEntries(Object.keys(names).map((name) => [name, `var(${VAR_PREFIX}-${group}-${name})`])))])));
|
|
20
|
+
refsByTheme.set(theme, built);
|
|
21
|
+
return built;
|
|
22
|
+
};
|
|
23
|
+
const variables = (theme) => {
|
|
24
|
+
const style = {};
|
|
25
|
+
for (const [group, names] of Object.entries(theme)) for (const [name, value] of Object.entries(names)) style[`${VAR_PREFIX}-${group}-${name}`] = value;
|
|
26
|
+
return inline(style);
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A token that follows the user's color scheme with CSS `light-dark()`: no
|
|
30
|
+
* JavaScript and no Model field. A theme the user chooses is the other case,
|
|
31
|
+
* and belongs in the Model as a class on the root; `variables` compiles both.
|
|
32
|
+
*/
|
|
33
|
+
const lightDark = (light, dark) => `light-dark(${light}, ${dark})`;
|
|
34
|
+
/** Themes merged at definition time, later tokens winning within a group. */
|
|
35
|
+
const compose = (base, over) => {
|
|
36
|
+
const merged = {};
|
|
37
|
+
for (const source of [base, over]) for (const [group, names] of Object.entries(source)) merged[group] = {
|
|
38
|
+
...merged[group],
|
|
39
|
+
...names
|
|
40
|
+
};
|
|
41
|
+
return define(merged);
|
|
42
|
+
};
|
|
43
|
+
const Theme = {
|
|
44
|
+
define,
|
|
45
|
+
ref,
|
|
46
|
+
variables,
|
|
47
|
+
lightDark,
|
|
48
|
+
compose
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { lightDark as a, define as i, VAR_PREFIX as n, ref as o, compose as r, variables as s, Theme as t };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=core-izIY2GSX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-izIY2GSX.mjs","names":[],"sources":["../src/theme/core.ts"],"sourcesContent":["/**\n * `Theme` is typed token data, not a service. Dynamic theme state (light/dark)\n * belongs in the Foldkit Model; `variables` compiles the tokens to CSS custom\n * properties so switching a class or a root style is cheap and SSR-safe.\n */\nimport { inline, type StyleValue } from '../styleValue.js'\n\nexport type ThemeTokens = {\n readonly [group: string]: { readonly [name: string]: string }\n}\n\nexport type Theme<T extends ThemeTokens = ThemeTokens> = T\n\nexport const VAR_PREFIX = '--fk'\n\nexport const define = <T extends ThemeTokens>(tokens: T): Readonly<T> =>\n Object.freeze(\n Object.fromEntries(\n Object.entries(tokens).map(([group, names]) => [group, Object.freeze({ ...names })]),\n ),\n ) as Readonly<T>\n\n/** `var(--fk-group-name)` for every token, by the theme's own group and token names. */\nexport type Refs<T extends ThemeTokens> = {\n readonly [G in keyof T & string]: { readonly [N in keyof T[G] & string]: string }\n}\n\nconst refsByTheme = new WeakMap<ThemeTokens, Refs<ThemeTokens>>()\n\n/**\n * The theme's tokens as references: `Theme.ref(theme).surface.overt` is\n * `var(--fk-surface-overt)`, and a group or name the theme lacks is a type\n * error. Only the names are read, never the values. Built once per theme.\n */\nexport const ref = <T extends ThemeTokens>(theme: T): Refs<T> => {\n const cached = refsByTheme.get(theme)\n if (cached !== undefined) return cached as Refs<T>\n const built = Object.freeze(\n Object.fromEntries(\n Object.entries(theme).map(([group, names]) => [\n group,\n Object.freeze(\n Object.fromEntries(\n Object.keys(names).map(name => [name, `var(${VAR_PREFIX}-${group}-${name})`]),\n ),\n ),\n ]),\n ),\n )\n refsByTheme.set(theme, built)\n return built as Refs<T>\n}\n\nexport const variables = <T extends ThemeTokens>(theme: T): StyleValue => {\n const style: Record<`--${string}`, string> = {}\n for (const [group, names] of Object.entries(theme)) {\n for (const [name, value] of Object.entries(names as Record<string, string>)) {\n style[`${VAR_PREFIX}-${group}-${name}`] = value\n }\n }\n return inline(style)\n}\n\n/**\n * A token that follows the user's color scheme with CSS `light-dark()`: no\n * JavaScript and no Model field. A theme the user chooses is the other case,\n * and belongs in the Model as a class on the root; `variables` compiles both.\n */\nexport const lightDark = (light: string, dark: string): string => `light-dark(${light}, ${dark})`\n\ntype Merge<A, B> = {\n readonly [G in keyof A | keyof B]: G extends keyof B\n ? G extends keyof A\n ? A[G] & B[G]\n : B[G]\n : G extends keyof A\n ? A[G]\n : never\n}\n\n/** Themes merged at definition time, later tokens winning within a group. */\nexport const compose = <A extends ThemeTokens, B extends ThemeTokens>(\n base: A,\n over: B,\n): Readonly<Merge<A, B>> => {\n const merged: Record<string, Record<string, string>> = {}\n for (const source of [base, over]) {\n for (const [group, names] of Object.entries(source)) {\n merged[group] = { ...merged[group], ...(names as Record<string, string>) }\n }\n }\n return define(merged) as unknown as Readonly<Merge<A, B>>\n}\n\nexport const Theme = { define, ref, variables, lightDark, compose } as const\n"],"mappings":";;;;;;;AAaA,MAAa,aAAa;AAE1B,MAAa,UAAiC,WAC5C,OAAO,OACL,OAAO,YACL,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,OAAO,OAAO,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CACrF,CACF;AAOF,MAAM,8BAAc,IAAI,QAAwC;;;;;;AAOhE,MAAa,OAA8B,UAAsB;CAC/D,MAAM,SAAS,YAAY,IAAI,KAAK;CACpC,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,MAAM,QAAQ,OAAO,OACnB,OAAO,YACL,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAC5C,OACA,OAAO,OACL,OAAO,YACL,OAAO,KAAK,KAAK,CAAC,CAAC,KAAI,SAAQ,CAAC,MAAM,OAAO,WAAW,GAAG,MAAM,GAAG,KAAK,EAAE,CAAC,CAC9E,CACF,CACF,CAAC,CACH,CACF;CACA,YAAY,IAAI,OAAO,KAAK;CAC5B,OAAO;AACT;AAEA,MAAa,aAAoC,UAAyB;CACxE,MAAM,QAAuC,CAAC;CAC9C,KAAK,MAAM,CAAC,OAAO,UAAU,OAAO,QAAQ,KAAK,GAC/C,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAA+B,GACxE,MAAM,GAAG,WAAW,GAAG,MAAM,GAAG,UAAU;CAG9C,OAAO,OAAO,KAAK;AACrB;;;;;;AAOA,MAAa,aAAa,OAAe,SAAyB,cAAc,MAAM,IAAI,KAAK;;AAa/F,MAAa,WACX,MACA,SAC0B;CAC1B,MAAM,SAAiD,CAAC;CACxD,KAAK,MAAM,UAAU,CAAC,MAAM,IAAI,GAC9B,KAAK,MAAM,CAAC,OAAO,UAAU,OAAO,QAAQ,MAAM,GAChD,OAAO,SAAS;EAAE,GAAG,OAAO;EAAQ,GAAI;CAAiC;CAG7E,OAAO,OAAO,MAAM;AACtB;AAEA,MAAa,QAAQ;CAAE;CAAQ;CAAK;CAAW;CAAW;AAAQ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { a as StyleValue } from "./styleValue-C9vAKt7A.mjs";
|
|
2
|
+
//#region src/defaults.d.ts
|
|
3
|
+
/** Box model, margins, media, form-control fonts: what every page assumes. */
|
|
4
|
+
export declare const reset: StyleValue;
|
|
5
|
+
/** The page's font, color, background, and color scheme. */
|
|
6
|
+
export declare const body: StyleValue;
|
|
7
|
+
/** A type hierarchy for h1 to h6 from the size scale. */
|
|
8
|
+
export declare const headings: StyleValue;
|
|
9
|
+
/** Link color, hover, and a visible focus ring. */
|
|
10
|
+
export declare const links: StyleValue;
|
|
11
|
+
/** Inline code and code blocks on the subtle surface. */
|
|
12
|
+
export declare const code: StyleValue;
|
|
13
|
+
/** Text inputs, selects, textareas, and buttons: one radius, one border, one focus. */
|
|
14
|
+
export declare const controls: StyleValue;
|
|
15
|
+
/** Every default except `reset`, which belongs in its own layer. */
|
|
16
|
+
export declare const all: StyleValue;
|
|
17
|
+
export declare const Defaults: {
|
|
18
|
+
readonly reset: StyleValue;
|
|
19
|
+
readonly body: StyleValue;
|
|
20
|
+
readonly headings: StyleValue;
|
|
21
|
+
readonly links: StyleValue;
|
|
22
|
+
readonly code: StyleValue;
|
|
23
|
+
readonly controls: StyleValue;
|
|
24
|
+
readonly all: StyleValue;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
//# sourceMappingURL=defaults.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.mts","names":[],"sources":["../src/defaults.ts"],"mappings":";;;qBAca,OAAO;;qBAcP,MAAM;;qBAKN,UAAU;;qBAaV,OAAO;;qBASP,MAAM;;qBASN,UAAU;;qBAaV,KAAK;qBAEL"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { r as compose, s as global } from "./styleValue--iQMTcPn.mjs";
|
|
2
|
+
//#region src/defaults.ts
|
|
3
|
+
/**
|
|
4
|
+
* `foldkit-mixins/defaults`: the baseline plain HTML gets before any slot is
|
|
5
|
+
* styled. Every member is element-selector CSS over `--fk-*` tokens with a
|
|
6
|
+
* fallback, so it re-themes with the tokens and still reads without them.
|
|
7
|
+
* The pieces are unlayered; a page puts `reset` in `reset` and the rest in
|
|
8
|
+
* `defaults` with `Layers.standard.in`. Selectors use `:where()` so any
|
|
9
|
+
* class rule beats them.
|
|
10
|
+
*/
|
|
11
|
+
const v = (name, fallback) => `var(--fk-${name}, ${fallback})`;
|
|
12
|
+
/** Box model, margins, media, form-control fonts: what every page assumes. */
|
|
13
|
+
const reset = global([
|
|
14
|
+
"*,*::before,*::after{box-sizing:border-box;margin:0;min-width:0}",
|
|
15
|
+
":where(html){text-size-adjust:none;-webkit-text-size-adjust:none;tab-size:4;font-synthesis:none;text-rendering:optimizeLegibility}",
|
|
16
|
+
":where(:is(img,picture,video,canvas,svg)){display:block;max-inline-size:100%;block-size:auto}",
|
|
17
|
+
":where(:is(input,button,textarea,select)){font:inherit;color:inherit}",
|
|
18
|
+
":where(textarea){field-sizing:content;min-block-size:2lh}",
|
|
19
|
+
":where(:is(h1,h2,h3,h4,h5,h6)){text-wrap:balance}",
|
|
20
|
+
":where(p){text-wrap:pretty;overflow-wrap:break-word}",
|
|
21
|
+
`@media (prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:0.01ms!important;transition-duration:0.01ms!important;scroll-behavior:auto!important}}`
|
|
22
|
+
].join(""));
|
|
23
|
+
/** The page's font, color, background, and color scheme. */
|
|
24
|
+
const body = global(`:where(body){font-family:${v("font-body", "system-ui, sans-serif")};font-size:${v("size-md", "1rem")};line-height:${v("leading-normal", "1.5")};font-weight:${v("weight-normal", "400")};color:${v("text-default", "CanvasText")};background:${v("surface-base", "Canvas")};-webkit-font-smoothing:antialiased}`);
|
|
25
|
+
/** A type hierarchy for h1 to h6 from the size scale. */
|
|
26
|
+
const headings = global([
|
|
27
|
+
`:where(:is(h1,h2,h3,h4,h5,h6)){font-family:${v("font-heading", "inherit")};font-weight:${v("weight-bold", "700")};line-height:${v("leading-tight", "1.2")};color:${v("text-overt", "inherit")};letter-spacing:-0.01em}`,
|
|
28
|
+
`:where(h1){font-size:${v("size-4xl", "2.25rem")}}`,
|
|
29
|
+
`:where(h2){font-size:${v("size-3xl", "1.875rem")}}`,
|
|
30
|
+
`:where(h3){font-size:${v("size-2xl", "1.5rem")}}`,
|
|
31
|
+
`:where(h4){font-size:${v("size-xl", "1.25rem")}}`,
|
|
32
|
+
`:where(h5){font-size:${v("size-lg", "1.125rem")}}`,
|
|
33
|
+
`:where(h6){font-size:${v("size-md", "1rem")}}`
|
|
34
|
+
].join(""));
|
|
35
|
+
/** Link color, hover, and a visible focus ring. */
|
|
36
|
+
const links = global([
|
|
37
|
+
`:where(a){color:${v("text-link", "LinkText")};text-decoration-thickness:from-font;text-underline-offset:0.15em}`,
|
|
38
|
+
`:where(a:hover){color:${v("text-link-hover", "LinkText")}}`,
|
|
39
|
+
`:where(:is(a,button,input,select,textarea,summary,[tabindex]):focus-visible){outline:${v("border-thick", "2px")} solid ${v("outline-focus", "Highlight")};outline-offset:2px}`
|
|
40
|
+
].join(""));
|
|
41
|
+
/** Inline code and code blocks on the subtle surface. */
|
|
42
|
+
const code = global([
|
|
43
|
+
`:where(:is(code,kbd,samp,pre)){font-family:${v("font-mono", "ui-monospace, monospace")};font-size:${v("size-sm", "0.875rem")}}`,
|
|
44
|
+
`:where(:not(pre)>code){padding:0.1em 0.35em;border-radius:${v("radius-sm", "3px")};background:${v("surface-subtle", "transparent")};overflow-wrap:anywhere}`,
|
|
45
|
+
`:where(pre){padding:${v("space-md", "1rem")};border:${v("border-thin", "1px")} solid ${v("outline-subtle", "transparent")};border-radius:${v("radius-md", "6px")};background:${v("surface-subtle", "transparent")};overflow-x:auto;line-height:${v("leading-snug", "1.375")}}`
|
|
46
|
+
].join(""));
|
|
47
|
+
/** Text inputs, selects, textareas, and buttons: one radius, one border, one focus. */
|
|
48
|
+
const controls = global([
|
|
49
|
+
`:where(:is(input:not([type=checkbox],[type=radio],[type=range],[type=color],[type=file]),select,textarea)){padding:${v("space-xs", "0.5rem")} ${v("space-sm", "0.75rem")};border:${v("border-thin", "1px")} solid ${v("outline-default", "ButtonBorder")};border-radius:${v("radius-md", "6px")};background:${v("surface-base", "Field")};color:${v("text-default", "FieldText")};transition:border-color ${v("motion-fast", "150ms")} ${v("motion-ease", "ease-out")}}`,
|
|
50
|
+
`:where(:is(input,select,textarea):focus-visible){border-color:${v("accent-default", "Highlight")}}`,
|
|
51
|
+
`:where(:is(input,select,textarea)[aria-invalid=true]){border-color:${v("error-default", "red")}}`,
|
|
52
|
+
`:where(button,[type=button],[type=submit],[type=reset]){padding:${v("space-xs", "0.5rem")} ${v("space-md", "1rem")};border:${v("border-thin", "1px")} solid ${v("outline-default", "ButtonBorder")};border-radius:${v("radius-md", "6px")};background:${v("surface-subtle", "ButtonFace")};color:${v("text-default", "ButtonText")};cursor:pointer;transition:background ${v("motion-fast", "150ms")} ${v("motion-ease", "ease-out")}}`,
|
|
53
|
+
`:where(button,[type=button],[type=submit],[type=reset]):hover{background:${v("surface-muted", "ButtonFace")}}`,
|
|
54
|
+
`:where(:is(button,input,select,textarea):disabled){opacity:0.5;cursor:not-allowed}`,
|
|
55
|
+
`:where(:is(input,select,textarea,button)::placeholder){color:${v("text-muted", "GrayText")}}`
|
|
56
|
+
].join(""));
|
|
57
|
+
/** Every default except `reset`, which belongs in its own layer. */
|
|
58
|
+
const all = compose(body, headings, links, code, controls);
|
|
59
|
+
const Defaults = {
|
|
60
|
+
reset,
|
|
61
|
+
body,
|
|
62
|
+
headings,
|
|
63
|
+
links,
|
|
64
|
+
code,
|
|
65
|
+
controls,
|
|
66
|
+
all
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { Defaults, all, body, code, controls, headings, links, reset };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=defaults.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.mjs","names":[],"sources":["../src/defaults.ts"],"sourcesContent":["/**\n * `foldkit-mixins/defaults`: the baseline plain HTML gets before any slot is\n * styled. Every member is element-selector CSS over `--fk-*` tokens with a\n * fallback, so it re-themes with the tokens and still reads without them.\n * The pieces are unlayered; a page puts `reset` in `reset` and the rest in\n * `defaults` with `Layers.standard.in`. Selectors use `:where()` so any\n * class rule beats them.\n */\nimport { compose, global } from './styleValue.js'\nimport type { StyleValue } from './styleValue.js'\n\nconst v = (name: string, fallback: string): string => `var(--fk-${name}, ${fallback})`\n\n/** Box model, margins, media, form-control fonts: what every page assumes. */\nexport const reset: StyleValue = global(\n [\n '*,*::before,*::after{box-sizing:border-box;margin:0;min-width:0}',\n ':where(html){text-size-adjust:none;-webkit-text-size-adjust:none;tab-size:4;font-synthesis:none;text-rendering:optimizeLegibility}',\n ':where(:is(img,picture,video,canvas,svg)){display:block;max-inline-size:100%;block-size:auto}',\n ':where(:is(input,button,textarea,select)){font:inherit;color:inherit}',\n ':where(textarea){field-sizing:content;min-block-size:2lh}',\n ':where(:is(h1,h2,h3,h4,h5,h6)){text-wrap:balance}',\n ':where(p){text-wrap:pretty;overflow-wrap:break-word}',\n `@media (prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:0.01ms!important;transition-duration:0.01ms!important;scroll-behavior:auto!important}}`,\n ].join(''),\n)\n\n/** The page's font, color, background, and color scheme. */\nexport const body: StyleValue = global(\n `:where(body){font-family:${v('font-body', 'system-ui, sans-serif')};font-size:${v('size-md', '1rem')};line-height:${v('leading-normal', '1.5')};font-weight:${v('weight-normal', '400')};color:${v('text-default', 'CanvasText')};background:${v('surface-base', 'Canvas')};-webkit-font-smoothing:antialiased}`,\n)\n\n/** A type hierarchy for h1 to h6 from the size scale. */\nexport const headings: StyleValue = global(\n [\n `:where(:is(h1,h2,h3,h4,h5,h6)){font-family:${v('font-heading', 'inherit')};font-weight:${v('weight-bold', '700')};line-height:${v('leading-tight', '1.2')};color:${v('text-overt', 'inherit')};letter-spacing:-0.01em}`,\n `:where(h1){font-size:${v('size-4xl', '2.25rem')}}`,\n `:where(h2){font-size:${v('size-3xl', '1.875rem')}}`,\n `:where(h3){font-size:${v('size-2xl', '1.5rem')}}`,\n `:where(h4){font-size:${v('size-xl', '1.25rem')}}`,\n `:where(h5){font-size:${v('size-lg', '1.125rem')}}`,\n `:where(h6){font-size:${v('size-md', '1rem')}}`,\n ].join(''),\n)\n\n/** Link color, hover, and a visible focus ring. */\nexport const links: StyleValue = global(\n [\n `:where(a){color:${v('text-link', 'LinkText')};text-decoration-thickness:from-font;text-underline-offset:0.15em}`,\n `:where(a:hover){color:${v('text-link-hover', 'LinkText')}}`,\n `:where(:is(a,button,input,select,textarea,summary,[tabindex]):focus-visible){outline:${v('border-thick', '2px')} solid ${v('outline-focus', 'Highlight')};outline-offset:2px}`,\n ].join(''),\n)\n\n/** Inline code and code blocks on the subtle surface. */\nexport const code: StyleValue = global(\n [\n `:where(:is(code,kbd,samp,pre)){font-family:${v('font-mono', 'ui-monospace, monospace')};font-size:${v('size-sm', '0.875rem')}}`,\n `:where(:not(pre)>code){padding:0.1em 0.35em;border-radius:${v('radius-sm', '3px')};background:${v('surface-subtle', 'transparent')};overflow-wrap:anywhere}`,\n `:where(pre){padding:${v('space-md', '1rem')};border:${v('border-thin', '1px')} solid ${v('outline-subtle', 'transparent')};border-radius:${v('radius-md', '6px')};background:${v('surface-subtle', 'transparent')};overflow-x:auto;line-height:${v('leading-snug', '1.375')}}`,\n ].join(''),\n)\n\n/** Text inputs, selects, textareas, and buttons: one radius, one border, one focus. */\nexport const controls: StyleValue = global(\n [\n `:where(:is(input:not([type=checkbox],[type=radio],[type=range],[type=color],[type=file]),select,textarea)){padding:${v('space-xs', '0.5rem')} ${v('space-sm', '0.75rem')};border:${v('border-thin', '1px')} solid ${v('outline-default', 'ButtonBorder')};border-radius:${v('radius-md', '6px')};background:${v('surface-base', 'Field')};color:${v('text-default', 'FieldText')};transition:border-color ${v('motion-fast', '150ms')} ${v('motion-ease', 'ease-out')}}`,\n `:where(:is(input,select,textarea):focus-visible){border-color:${v('accent-default', 'Highlight')}}`,\n `:where(:is(input,select,textarea)[aria-invalid=true]){border-color:${v('error-default', 'red')}}`,\n `:where(button,[type=button],[type=submit],[type=reset]){padding:${v('space-xs', '0.5rem')} ${v('space-md', '1rem')};border:${v('border-thin', '1px')} solid ${v('outline-default', 'ButtonBorder')};border-radius:${v('radius-md', '6px')};background:${v('surface-subtle', 'ButtonFace')};color:${v('text-default', 'ButtonText')};cursor:pointer;transition:background ${v('motion-fast', '150ms')} ${v('motion-ease', 'ease-out')}}`,\n `:where(button,[type=button],[type=submit],[type=reset]):hover{background:${v('surface-muted', 'ButtonFace')}}`,\n `:where(:is(button,input,select,textarea):disabled){opacity:0.5;cursor:not-allowed}`,\n `:where(:is(input,select,textarea,button)::placeholder){color:${v('text-muted', 'GrayText')}}`,\n ].join(''),\n)\n\n/** Every default except `reset`, which belongs in its own layer. */\nexport const all: StyleValue = compose(body, headings, links, code, controls)\n\nexport const Defaults = { reset, body, headings, links, code, controls, all } as const\n"],"mappings":";;;;;;;;;;AAWA,MAAM,KAAK,MAAc,aAA6B,YAAY,KAAK,IAAI,SAAS;;AAGpF,MAAa,QAAoB,OAC/B;CACE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,EAAE,CACX;;AAGA,MAAa,OAAmB,OAC9B,4BAA4B,EAAE,aAAa,uBAAuB,EAAE,aAAa,EAAE,WAAW,MAAM,EAAE,eAAe,EAAE,kBAAkB,KAAK,EAAE,eAAe,EAAE,iBAAiB,KAAK,EAAE,SAAS,EAAE,gBAAgB,YAAY,EAAE,cAAc,EAAE,gBAAgB,QAAQ,EAAE,qCAC9Q;;AAGA,MAAa,WAAuB,OAClC;CACE,8CAA8C,EAAE,gBAAgB,SAAS,EAAE,eAAe,EAAE,eAAe,KAAK,EAAE,eAAe,EAAE,iBAAiB,KAAK,EAAE,SAAS,EAAE,cAAc,SAAS,EAAE;CAC/L,wBAAwB,EAAE,YAAY,SAAS,EAAE;CACjD,wBAAwB,EAAE,YAAY,UAAU,EAAE;CAClD,wBAAwB,EAAE,YAAY,QAAQ,EAAE;CAChD,wBAAwB,EAAE,WAAW,SAAS,EAAE;CAChD,wBAAwB,EAAE,WAAW,UAAU,EAAE;CACjD,wBAAwB,EAAE,WAAW,MAAM,EAAE;AAC/C,CAAC,CAAC,KAAK,EAAE,CACX;;AAGA,MAAa,QAAoB,OAC/B;CACE,mBAAmB,EAAE,aAAa,UAAU,EAAE;CAC9C,yBAAyB,EAAE,mBAAmB,UAAU,EAAE;CAC1D,wFAAwF,EAAE,gBAAgB,KAAK,EAAE,SAAS,EAAE,iBAAiB,WAAW,EAAE;AAC5J,CAAC,CAAC,KAAK,EAAE,CACX;;AAGA,MAAa,OAAmB,OAC9B;CACE,8CAA8C,EAAE,aAAa,yBAAyB,EAAE,aAAa,EAAE,WAAW,UAAU,EAAE;CAC9H,6DAA6D,EAAE,aAAa,KAAK,EAAE,cAAc,EAAE,kBAAkB,aAAa,EAAE;CACpI,uBAAuB,EAAE,YAAY,MAAM,EAAE,UAAU,EAAE,eAAe,KAAK,EAAE,SAAS,EAAE,kBAAkB,aAAa,EAAE,iBAAiB,EAAE,aAAa,KAAK,EAAE,cAAc,EAAE,kBAAkB,aAAa,EAAE,+BAA+B,EAAE,gBAAgB,OAAO,EAAE;AAC/Q,CAAC,CAAC,KAAK,EAAE,CACX;;AAGA,MAAa,WAAuB,OAClC;CACE,sHAAsH,EAAE,YAAY,QAAQ,EAAE,GAAG,EAAE,YAAY,SAAS,EAAE,UAAU,EAAE,eAAe,KAAK,EAAE,SAAS,EAAE,mBAAmB,cAAc,EAAE,iBAAiB,EAAE,aAAa,KAAK,EAAE,cAAc,EAAE,gBAAgB,OAAO,EAAE,SAAS,EAAE,gBAAgB,WAAW,EAAE,2BAA2B,EAAE,eAAe,OAAO,EAAE,GAAG,EAAE,eAAe,UAAU,EAAE;CACvc,iEAAiE,EAAE,kBAAkB,WAAW,EAAE;CAClG,sEAAsE,EAAE,iBAAiB,KAAK,EAAE;CAChG,mEAAmE,EAAE,YAAY,QAAQ,EAAE,GAAG,EAAE,YAAY,MAAM,EAAE,UAAU,EAAE,eAAe,KAAK,EAAE,SAAS,EAAE,mBAAmB,cAAc,EAAE,iBAAiB,EAAE,aAAa,KAAK,EAAE,cAAc,EAAE,kBAAkB,YAAY,EAAE,SAAS,EAAE,gBAAgB,YAAY,EAAE,wCAAwC,EAAE,eAAe,OAAO,EAAE,GAAG,EAAE,eAAe,UAAU,EAAE;CACta,4EAA4E,EAAE,iBAAiB,YAAY,EAAE;CAC7G;CACA,gEAAgE,EAAE,cAAc,UAAU,EAAE;AAC9F,CAAC,CAAC,KAAK,EAAE,CACX;;AAGA,MAAa,MAAkB,QAAQ,MAAM,UAAU,OAAO,MAAM,QAAQ;AAE5E,MAAa,WAAW;CAAE;CAAO;CAAM;CAAU;CAAO;CAAM;CAAU;AAAI"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
//#region src/diagnostics.ts
|
|
3
|
+
var diagnostics_exports = /* @__PURE__ */ __exportAll({ DiagnosticError: () => DiagnosticError });
|
|
4
|
+
var DiagnosticError = class extends Error {
|
|
5
|
+
diagnostic;
|
|
6
|
+
constructor(diagnostic) {
|
|
7
|
+
super(diagnostic.message);
|
|
8
|
+
this.name = "DiagnosticError";
|
|
9
|
+
this.diagnostic = diagnostic;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { diagnostics_exports as n, DiagnosticError as t };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=diagnostics-YJ7991-A.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics-YJ7991-A.mjs","names":[],"sources":["../src/diagnostics.ts"],"sourcesContent":["/**\n * Structured diagnostics for attachment conflicts. Codes are stable so tests,\n * DevTools, and editor tooling can share them. Resolution failures are\n * programming errors (a definition attaches something a slot does not allow),\n * so `resolve` throws a `DiagnosticError` carrying one.\n */\nexport type DiagnosticCode =\n | 'mixins:unknown-slot'\n | 'mixins:hidden-slot'\n | 'mixins:capability-mismatch'\n | 'mixins:unsupported-event'\n | 'mixins:unsupported-attribute'\n | 'mixins:protected-event'\n | 'mixins:protected-attribute'\n | 'mixins:protected-style-property'\n | 'mixins:style-property-conflict'\n | 'mixins:event-conflict'\n | 'mixins:attribute-conflict'\n | 'mixins:structural-override'\n | 'mixins:duplicate-mount-name'\n | 'mixins:duplicate-item-id'\n | 'mixins:ragged-grid-areas'\n | 'style:duplicate-layer'\n | 'style:conflicting-layer-order'\n | 'style:unlayered-rule'\n | 'style:relayered'\n | 'theme:unparseable-breakpoint'\n | 'a11y:missing-slot'\n | 'a11y:hidden-slot'\n | 'a11y:capability-mismatch'\n | 'a11y:missing-event'\n | 'a11y:missing-attribute'\n\nexport interface Diagnostic {\n readonly source: 'mixins' | 'a11y' | 'style' | 'theme'\n readonly code: DiagnosticCode\n readonly severity: 'error'\n readonly message: string\n readonly slot?: string\n readonly details?: Readonly<Record<string, unknown>>\n}\n\nexport class DiagnosticError extends Error {\n readonly diagnostic: Diagnostic\n\n constructor(diagnostic: Diagnostic) {\n super(diagnostic.message)\n this.name = 'DiagnosticError'\n this.diagnostic = diagnostic\n }\n}\n"],"mappings":";;;AA0CA,IAAa,kBAAb,cAAqC,MAAM;CACzC;CAEA,YAAY,YAAwB;EAClC,MAAM,WAAW,OAAO;EACxB,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;AACF"}
|