foldkit-mixins 0.24.0 → 0.26.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 (165) hide show
  1. package/README.md +583 -47
  2. package/dist/a11y.d.ts +127 -1
  3. package/dist/a11y.d.ts.map +1 -1
  4. package/dist/a11y.js +138 -9
  5. package/dist/a11y.js.map +1 -1
  6. package/dist/attr.d.ts +8 -0
  7. package/dist/attr.d.ts.map +1 -1
  8. package/dist/attr.js +19 -11
  9. package/dist/attr.js.map +1 -1
  10. package/dist/behavior.d.ts +40 -7
  11. package/dist/behavior.d.ts.map +1 -1
  12. package/dist/behavior.js +31 -7
  13. package/dist/behavior.js.map +1 -1
  14. package/dist/behaviors/collection.d.ts +3 -1
  15. package/dist/behaviors/collection.d.ts.map +1 -1
  16. package/dist/behaviors/collection.js +14 -16
  17. package/dist/behaviors/collection.js.map +1 -1
  18. package/dist/behaviors/disclosure.d.ts +6 -3
  19. package/dist/behaviors/disclosure.d.ts.map +1 -1
  20. package/dist/behaviors/disclosure.js +17 -10
  21. package/dist/behaviors/disclosure.js.map +1 -1
  22. package/dist/behaviors/field-association.d.ts +6 -3
  23. package/dist/behaviors/field-association.d.ts.map +1 -1
  24. package/dist/behaviors/field-association.js +28 -22
  25. package/dist/behaviors/field-association.js.map +1 -1
  26. package/dist/behaviors/id-selector.d.ts +7 -0
  27. package/dist/behaviors/id-selector.d.ts.map +1 -0
  28. package/dist/behaviors/id-selector.js +10 -0
  29. package/dist/behaviors/id-selector.js.map +1 -0
  30. package/dist/behaviors/index.d.ts +2 -1
  31. package/dist/behaviors/index.js +2 -1
  32. package/dist/behaviors/keys.d.ts +169 -0
  33. package/dist/behaviors/keys.d.ts.map +1 -0
  34. package/dist/behaviors/keys.js +347 -0
  35. package/dist/behaviors/keys.js.map +1 -0
  36. package/dist/behaviors/spin-value.d.ts +15 -3
  37. package/dist/behaviors/spin-value.d.ts.map +1 -1
  38. package/dist/behaviors/spin-value.js +46 -16
  39. package/dist/behaviors/spin-value.js.map +1 -1
  40. package/dist/behaviors/toggle-state.d.ts +7 -4
  41. package/dist/behaviors/toggle-state.d.ts.map +1 -1
  42. package/dist/behaviors/toggle-state.js +14 -7
  43. package/dist/behaviors/toggle-state.js.map +1 -1
  44. package/dist/conformance.d.ts +205 -0
  45. package/dist/conformance.d.ts.map +1 -0
  46. package/dist/conformance.js +582 -0
  47. package/dist/conformance.js.map +1 -0
  48. package/dist/conformed.d.ts +17 -0
  49. package/dist/conformed.d.ts.map +1 -0
  50. package/dist/conformed.js +21 -0
  51. package/dist/conformed.js.map +1 -0
  52. package/dist/defaults.d.ts.map +1 -1
  53. package/dist/defaults.js +3 -3
  54. package/dist/defaults.js.map +1 -1
  55. package/dist/describe.d.ts +91 -0
  56. package/dist/describe.d.ts.map +1 -0
  57. package/dist/describe.js +239 -0
  58. package/dist/describe.js.map +1 -0
  59. package/dist/diagnostics.d.ts +1 -1
  60. package/dist/diagnostics.d.ts.map +1 -1
  61. package/dist/diagnostics.js.map +1 -1
  62. package/dist/foldkitNames.d.ts +42 -0
  63. package/dist/foldkitNames.d.ts.map +1 -0
  64. package/dist/foldkitNames.js +169 -0
  65. package/dist/foldkitNames.js.map +1 -0
  66. package/dist/index.d.ts +12 -10
  67. package/dist/index.js +6 -5
  68. package/dist/layers.js +1 -1
  69. package/dist/mixin.d.ts +29 -1
  70. package/dist/mixin.d.ts.map +1 -1
  71. package/dist/mixin.js +11 -3
  72. package/dist/mixin.js.map +1 -1
  73. package/dist/pipe.d.ts +26 -1
  74. package/dist/pipe.d.ts.map +1 -1
  75. package/dist/pipe.js.map +1 -1
  76. package/dist/resolver.d.ts +8 -1
  77. package/dist/resolver.d.ts.map +1 -1
  78. package/dist/resolver.js +128 -98
  79. package/dist/resolver.js.map +1 -1
  80. package/dist/slotView.d.ts +83 -5
  81. package/dist/slotView.d.ts.map +1 -1
  82. package/dist/slotView.js +107 -20
  83. package/dist/slotView.js.map +1 -1
  84. package/dist/style.d.ts +28 -4
  85. package/dist/style.d.ts.map +1 -1
  86. package/dist/style.js +57 -11
  87. package/dist/style.js.map +1 -1
  88. package/dist/styleNames.d.ts +21 -0
  89. package/dist/styleNames.d.ts.map +1 -0
  90. package/dist/styleNames.js +116 -0
  91. package/dist/styleNames.js.map +1 -0
  92. package/dist/styleValue.d.ts.map +1 -1
  93. package/dist/styleValue.js +38 -1
  94. package/dist/styleValue.js.map +1 -1
  95. package/dist/testing.d.ts +4 -3
  96. package/dist/testing.d.ts.map +1 -1
  97. package/dist/testing.js +2 -1
  98. package/dist/testing.js.map +1 -1
  99. package/dist/theme/cssMath.d.ts +1 -1
  100. package/dist/theme/cssMath.js +1 -0
  101. package/dist/theme/cssMath.js.map +1 -1
  102. package/dist/theme/gamut.d.ts +19 -1
  103. package/dist/theme/gamut.d.ts.map +1 -1
  104. package/dist/theme/gamut.js +25 -3
  105. package/dist/theme/gamut.js.map +1 -1
  106. package/dist/theme/knob.d.ts +2 -0
  107. package/dist/theme/knob.d.ts.map +1 -1
  108. package/dist/theme/knob.js +1 -0
  109. package/dist/theme/knob.js.map +1 -1
  110. package/dist/theme/knobData.d.ts +1014 -0
  111. package/dist/theme/knobData.d.ts.map +1 -0
  112. package/dist/theme/knobData.js +583 -0
  113. package/dist/theme/knobData.js.map +1 -0
  114. package/dist/theme/knobDataType.d.ts +20 -0
  115. package/dist/theme/knobDataType.d.ts.map +1 -0
  116. package/dist/theme/knobDataType.js +1 -0
  117. package/dist/theme/knobs.d.ts +62 -62
  118. package/dist/theme/knobs.d.ts.map +1 -1
  119. package/dist/theme/knobs.js +61 -61
  120. package/dist/theme/knobs.js.map +1 -1
  121. package/dist/theme/oklch.d.ts +8 -0
  122. package/dist/theme/oklch.d.ts.map +1 -1
  123. package/dist/theme/oklch.js +20 -8
  124. package/dist/theme/oklch.js.map +1 -1
  125. package/dist/theme/raise.d.ts +2 -1
  126. package/dist/theme/raise.d.ts.map +1 -1
  127. package/dist/theme/raise.js +3 -2
  128. package/dist/theme/raise.js.map +1 -1
  129. package/dist/theme/runtime.d.ts +37 -0
  130. package/dist/theme/runtime.d.ts.map +1 -0
  131. package/dist/theme/runtime.js +54 -0
  132. package/dist/theme/runtime.js.map +1 -0
  133. package/dist/theme/scheme.d.ts +26 -1
  134. package/dist/theme/scheme.d.ts.map +1 -1
  135. package/dist/theme/scheme.js +31 -2
  136. package/dist/theme/scheme.js.map +1 -1
  137. package/dist/theme/shadows.d.ts +4 -1
  138. package/dist/theme/shadows.d.ts.map +1 -1
  139. package/dist/theme/shadows.js +8 -5
  140. package/dist/theme/shadows.js.map +1 -1
  141. package/dist/theme/storageChanges.d.ts +9 -0
  142. package/dist/theme/storageChanges.d.ts.map +1 -0
  143. package/dist/theme/storageChanges.js +29 -0
  144. package/dist/theme/storageChanges.js.map +1 -0
  145. package/dist/theme/themes.d.ts +3 -26
  146. package/dist/theme/themes.d.ts.map +1 -1
  147. package/dist/theme/themes.js +3 -32
  148. package/dist/theme/themes.js.map +1 -1
  149. package/dist/theme/tokens.d.ts +2 -0
  150. package/dist/theme/tokens.d.ts.map +1 -1
  151. package/dist/theme/tokens.js +4 -2
  152. package/dist/theme/tokens.js.map +1 -1
  153. package/dist/theme.d.ts +10 -7
  154. package/dist/theme.d.ts.map +1 -1
  155. package/dist/theme.js +7 -7
  156. package/dist/theme.js.map +1 -1
  157. package/dist/vite.d.ts +7 -4
  158. package/dist/vite.d.ts.map +1 -1
  159. package/dist/vite.js +26 -2
  160. package/dist/vite.js.map +1 -1
  161. package/dist/viteFreeze.d.ts +9 -12
  162. package/dist/viteFreeze.d.ts.map +1 -1
  163. package/dist/viteFreeze.js +94 -17
  164. package/dist/viteFreeze.js.map +1 -1
  165. package/package.json +15 -4
package/dist/a11y.d.ts CHANGED
@@ -1,14 +1,36 @@
1
1
  import { Diagnostic } from "./diagnostics.js";
2
+ import * as MetadataToken from "./metadataToken.js";
3
+ import { SlotView } from "./slotView.js";
4
+ import { StaticMixin } from "./mixin.js";
5
+ import { AttrToken } from "./attr.js";
6
+ import { NamedBehavior } from "./behavior.js";
2
7
  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';
8
+ export type A11yDiagnosticCode = 'a11y:missing-slot' | 'a11y:hidden-slot' | 'a11y:capability-mismatch' | 'a11y:missing-event' | 'a11y:missing-attribute' | 'a11y:unsatisfied-obligation' | 'a11y:delegation-unmet';
4
9
  export interface A11yDiagnostic extends Diagnostic {
5
10
  readonly source: 'a11y';
6
11
  readonly code: A11yDiagnosticCode;
7
12
  }
13
+ /**
14
+ * What a pattern demands be done on a slot, beyond what its contract
15
+ * publishes: something attached must say it does it. Compared by name.
16
+ */
17
+ export type Obligation<Name extends string = string> = MetadataToken.MetadataToken<'a11y.obligation', Name>;
18
+ /** Arrow keys, Home and End move among the items. */
19
+ export declare const Navigation: Obligation<'navigation'>;
20
+ /** Each item is reachable: a roving stop, `aria-activedescendant`, or a native control. */
21
+ export declare const FocusStrategy: Obligation<'focus-strategy'>;
22
+ /** Enter, Space or a press activates it. */
23
+ export declare const Activation: Obligation<'activation'>;
24
+ /** The element has an accessible name. */
25
+ export declare const Name: Obligation<'name'>;
26
+ /** The attribute is written with a value on every draw. */
27
+ export declare const State: <const Attribute extends string>(attribute: AttrToken<Attribute>) => Obligation<`state:${Attribute}`>;
8
28
  export interface SlotRequirement {
9
29
  readonly capability?: SlotCapability;
10
30
  readonly events?: ReadonlyArray<EventName>;
11
31
  readonly attributes?: ReadonlyArray<AttributeName>;
32
+ /** What something attached must say it does on the slot; checked by `check` and `conform`. */
33
+ readonly obligations?: ReadonlyArray<Obligation>;
12
34
  /** An absent slot is expected, not a diagnostic. A present slot is still checked. */
13
35
  readonly optional?: boolean;
14
36
  }
@@ -24,4 +46,108 @@ export declare const pattern: <const Spec extends Requirements>(spec: Spec) => P
24
46
  export declare const validate: (pattern: Pattern, slots: {
25
47
  readonly [name: string]: Any;
26
48
  }) => ReadonlyArray<A11yDiagnostic>;
49
+ export declare const ProvidesTypeId: unique symbol;
50
+ /**
51
+ * The type checker's record of `Provides`. A function property, so the record
52
+ * is contravariant: a value that supplies more is accepted where less is
53
+ * declared (an annotated return type, a parameter typed with the default),
54
+ * which then forgets what it supplied, and one that supplies less is refused
55
+ * where more is declared, so an annotation cannot claim what its value lacks.
56
+ */
57
+ interface ProvidesRecord<Provides extends string> {
58
+ readonly provides: (names: Provides) => void;
59
+ }
60
+ /**
61
+ * What a value supplies, as `` `${slot}/${obligation}` `` names, for the type
62
+ * checker alone: nothing is stored under the key. A view's names are the union
63
+ * of what its attachments supply, and `conform` asks them to cover the
64
+ * pattern's. Run time reads each attachment's `meta` instead, so a type that
65
+ * claims more than its value supplies still fails `conform` when the module loads.
66
+ */
67
+ export interface Supplies<Provides extends string> {
68
+ readonly [ProvidesTypeId]?: ProvidesRecord<Provides>;
69
+ }
70
+ type OneOf<T, All = T> = T extends unknown ? ([All] extends [T] ? true : false) : never;
71
+ /**
72
+ * `` `${Slot}/${Obligation}` `` when `Slot` is one known slot name, for a
73
+ * factory's binder overload to state what it supplies. A slot chosen at run
74
+ * time (a union, `string`) states nothing: the type cannot say which slot the
75
+ * value will name, so only `conform`'s run-time check can judge it.
76
+ */
77
+ export type ProvidedOn<Slot extends string, Obligation extends string> = string extends Slot | Obligation ? never : OneOf<Slot> extends true ? `${Slot}/${Obligation}` : never;
78
+ type ObligationNames<Requirement> = Requirement extends {
79
+ readonly obligations: ReadonlyArray<infer Owed>;
80
+ } ? MetadataToken.NameOf<Owed> : never;
81
+ /**
82
+ * What a pattern owes on the slots of `Slots`. Nothing when the slot names
83
+ * are not known (`Record<string, …>`): such an assembly is checked when the
84
+ * module loads.
85
+ */
86
+ export type Owed<Spec, Slots> = string extends keyof Slots ? never : { [K in keyof Spec & keyof Slots & string]: `${K}/${ObligationNames<Spec[K]>}`; }[keyof Spec & keyof Slots & string];
87
+ type Conforms<Spec, Slots, Provides> = [Exclude<Owed<Spec, Slots>, Provides>] extends [never] ? unknown : {
88
+ readonly 'a11y:unsatisfied-obligation': Exclude<Owed<Spec, Slots>, Provides>;
89
+ };
90
+ type AnyView = SlotView<any, any, any, never>;
91
+ /**
92
+ * What `validate` reports of the view's contract, and every obligation of the
93
+ * pattern on a slot the view publishes that no attachment supplies: an
94
+ * attached Behavior's `provides`, `base`, `native`, or a `delegated` whose
95
+ * provider is attached and supplies it on the slot named. Pure; reads only
96
+ * the attachments' metadata, never the input or the DOM.
97
+ */
98
+ export declare const check: (pattern: Pattern, view: AnyView) => ReadonlyArray<A11yDiagnostic>;
99
+ /**
100
+ * Refuses a view that does not meet `pattern`. At the type level, a view whose
101
+ * attachments' supplied names do not cover what the pattern owes on its slots
102
+ * is an error naming each `slot/obligation` missing. At run time, where the
103
+ * module loads, `check` runs and the first finding is thrown as a
104
+ * `DiagnosticError` with every finding in `details.diagnostics`. Returns a
105
+ * new view that remembers the pattern, so `SlotView.detach` and
106
+ * `SlotView.replace` check the view they make from it again; the view given is
107
+ * unchanged.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const Results = Search.define(render).pipe(
112
+ * Behavior.attach(Keys),
113
+ * A11y.conform(Listbox),
114
+ * )
115
+ * ```
116
+ */
117
+ export declare const conform: <Spec extends Requirements>(pattern: Pattern<Spec>) => <Slots, Input, Message, Provides extends string = never>(view: SlotView<Slots, Input, Message, Provides> & Conforms<Spec, Slots, Provides>) => SlotView<Slots, Input, Message, Provides>;
118
+ /** A Mixin that contributes nothing and supplies obligations, attached with `SlotView.attach`. */
119
+ export interface Supply<Provides extends string> extends StaticMixin<never> {
120
+ readonly [ProvidesTypeId]: ProvidesRecord<Provides>;
121
+ }
122
+ /** Per slot, the obligations supplied there. */
123
+ export type SupplySpec = Readonly<Record<string, ReadonlyArray<Obligation>>>;
124
+ export type SuppliedBy<Spec> = { [K in keyof Spec & string]: Spec[K] extends ReadonlyArray<infer Supplied> ? `${K}/${MetadataToken.NameOf<Supplied>}` : never; }[keyof Spec & string];
125
+ /** Obligations the view meets with its own attributes, such as its `aria-label`: the author's word. */
126
+ export declare const base: <const Spec extends SupplySpec>(spec: Spec, options?: {
127
+ readonly name?: string;
128
+ }) => Supply<SuppliedBy<Spec>>;
129
+ /** The HTML elements that are interactive by themselves. */
130
+ export type NativeElement = 'a' | 'button' | 'details' | 'input' | 'option' | 'select' | 'summary' | 'textarea';
131
+ /**
132
+ * Obligations a native element meets by itself on the slots it is drawn as,
133
+ * such as a `<button>`'s activation and focus. Named after the element.
134
+ */
135
+ export declare const native: <const Spec extends SupplySpec>(spec: Spec, options: {
136
+ readonly element: NativeElement;
137
+ readonly name?: string;
138
+ }) => Supply<SuppliedBy<Spec>>;
139
+ type SuppliedOn<Provides, To extends string> = Provides extends `${To}/${infer Supplied}` ? Supplied : never;
140
+ /**
141
+ * Obligations met on another slot by an attached Behavior, such as a
142
+ * listbox's navigation by the `ListNavigation` on a combobox's input. Each
143
+ * obligation must be one `provider` supplies on `to`: a type error otherwise,
144
+ * and `a11y:delegation-unmet` from `check` when the view does not hold
145
+ * `provider` or it supplies no such thing there.
146
+ */
147
+ export declare const delegated: <const Spec extends Readonly<Record<string, ReadonlyArray<Obligation<SuppliedOn<Provides, To>>>>>, ProviderSlots, To extends keyof ProviderSlots & string, Provides extends string = never>(spec: Spec, options: {
148
+ readonly to: To;
149
+ readonly provider: NamedBehavior<ProviderSlots, any, any, Provides>;
150
+ readonly name?: string;
151
+ }) => Supply<SuppliedBy<Spec>>;
152
+ export {};
27
153
  //# sourceMappingURL=a11y.d.ts.map
@@ -1 +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,Q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;;;;;;;;;;;qBA+EzD,UACV,aAAa,cAAY,SAAW,QAAQ,WAC5C,OAAO,OAAO,SAAS,iCAA+B,MAC/C,SAAS,OAAO,OAAO,SAAS,YAAY,SAAS,MAAM,OAAO,cACvE,SAAS,OAAO,OAAO,SAAS;;iBAiBpB,OAAO,iCAAiC;YAC7C,iBAAiB,eAAe;;;YAIhC,aAAa,SAAS,eAAe,cAAc;YAEnD,WAAW,WACpB,WAAW,gBAAgB,KAAK,WAAW,oBAAoB,eACzD,KAAK,cAAc,OAAO,6BAE3B;;qBA0BK,aAAc,aAAa,YAAU,MAC1C,MAAI;WACW;MACpB,OAAO,WAAW;;YAGT;;;;;qBAcC,eAAgB,aAAa,YAAU,MAC5C,MAAI;WACU,SAAS;WAAwB;MACpD,OAAO,WAAW;KAEhB,WAAW,UAAU,qBAAqB,oBAAoB,YAAY,aAC3E;;;;;;;;qBAUS,kBACL,aAAa,SAAS,eAAe,cAAc,WAAW,WAAW,UAAU,SACzF,eACA,iBAAiB,wBACjB,iCAA+B,MAEzB,MAAI;WAEC,IAAI;WACJ,UAAU,cAAc,yBAAyB;WACjD;MAEV,OAAO,WAAW"}
package/dist/a11y.js CHANGED
@@ -1,14 +1,19 @@
1
1
  import * as Capability from "./capability.js";
2
+ import * as Conformed from "./conformed.js";
3
+ import { DiagnosticError } from "./diagnostics.js";
2
4
  import * as MetadataToken from "./metadataToken.js";
5
+ import * as SlotViews from "./slotView.js";
3
6
  // 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
- */
7
+ /** Arrow keys, Home and End move among the items. */
8
+ const Navigation = MetadataToken.make("a11y.obligation", "navigation");
9
+ /** Each item is reachable: a roving stop, `aria-activedescendant`, or a native control. */
10
+ const FocusStrategy = MetadataToken.make("a11y.obligation", "focus-strategy");
11
+ /** Enter, Space or a press activates it. */
12
+ const Activation = MetadataToken.make("a11y.obligation", "activation");
13
+ /** The element has an accessible name. */
14
+ const Name = MetadataToken.make("a11y.obligation", "name");
15
+ /** The attribute is written with a value on every draw. */
16
+ const State = (attribute) => MetadataToken.make("a11y.obligation", `state:${attribute.name}`);
12
17
  const PatternTypeId = Symbol.for("foldkit-mixins/A11yPattern");
13
18
  const pattern = (spec) => {
14
19
  const requirements = Object.create(null);
@@ -73,6 +78,130 @@ const validate = (pattern, slots) => {
73
78
  }
74
79
  return diagnostics;
75
80
  };
76
- export { PatternTypeId, pattern, validate };
81
+ const ProvidesTypeId = Symbol.for("foldkit-mixins/Provides");
82
+ const delegations = /* @__PURE__ */ new WeakMap();
83
+ const suppliedOn = (meta, slot, obligation) => meta !== void 0 && (Object.hasOwn(meta.slots, slot) && meta.slots[slot].provides.includes(obligation) || (meta.parts ?? []).some((part) => suppliedOn(part.meta, slot, obligation)));
84
+ /**
85
+ * What `validate` reports of the view's contract, and every obligation of the
86
+ * pattern on a slot the view publishes that no attachment supplies: an
87
+ * attached Behavior's `provides`, `base`, `native`, or a `delegated` whose
88
+ * provider is attached and supplies it on the slot named. Pure; reads only
89
+ * the attachments' metadata, never the input or the DOM.
90
+ */
91
+ const check = (pattern, view) => {
92
+ const slots = view.slots;
93
+ const mixins = view.mixins;
94
+ const assembly = Conformed.assemblies.has(view.render);
95
+ const diagnostics = [...validate(pattern, slots)];
96
+ for (const name of Object.getOwnPropertyNames(pattern.requirements)) {
97
+ const obligations = pattern.requirements[name]?.obligations;
98
+ if (obligations === void 0 || !Object.hasOwn(slots, name) || slots[name].hidden) continue;
99
+ for (const obligation of obligations) {
100
+ const owed = MetadataToken.nameOf(obligation);
101
+ if (mixins.some((mixin) => suppliedOn(mixin.meta, name, owed))) continue;
102
+ const delegation = mixins.map((mixin) => delegations.get(mixin)).find((found) => found !== void 0 && Object.hasOwn(found.slots, name) && found.slots[name].includes(owed));
103
+ if (delegation === void 0) {
104
+ diagnostics.push(diagnostic("a11y:unsatisfied-obligation", `slot "${name}" owes ${owed}, which nothing attached supplies${assembly ? "; a part's own Behaviors are not read: attach the Behavior to the assembly" : ""}`, name, { obligation: owed }));
105
+ continue;
106
+ }
107
+ const held = mixins.includes(delegation.provider);
108
+ if (held && suppliedOn(delegation.provider.meta, delegation.to, owed)) continue;
109
+ diagnostics.push(diagnostic("a11y:delegation-unmet", `slot "${name}" delegates ${owed} to "${delegation.providerName}" on slot "${delegation.to}", ${held ? "which does not supply it there" : "which the view does not hold"}`, name, {
110
+ obligation: owed,
111
+ provider: delegation.providerName,
112
+ to: delegation.to
113
+ }));
114
+ }
115
+ }
116
+ return diagnostics;
117
+ };
118
+ const assertConforms = (pattern, view) => {
119
+ const diagnostics = check(pattern, view);
120
+ const first = diagnostics[0];
121
+ if (first === void 0) return;
122
+ throw new DiagnosticError({
123
+ ...first,
124
+ message: diagnostics.length === 1 ? first.message : `${first.message} (and ${diagnostics.length - 1} more)`,
125
+ details: {
126
+ ...first.details,
127
+ diagnostics
128
+ }
129
+ });
130
+ };
131
+ /**
132
+ * Refuses a view that does not meet `pattern`. At the type level, a view whose
133
+ * attachments' supplied names do not cover what the pattern owes on its slots
134
+ * is an error naming each `slot/obligation` missing. At run time, where the
135
+ * module loads, `check` runs and the first finding is thrown as a
136
+ * `DiagnosticError` with every finding in `details.diagnostics`. Returns a
137
+ * new view that remembers the pattern, so `SlotView.detach` and
138
+ * `SlotView.replace` check the view they make from it again; the view given is
139
+ * unchanged.
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * const Results = Search.define(render).pipe(
144
+ * Behavior.attach(Keys),
145
+ * A11y.conform(Listbox),
146
+ * )
147
+ * ```
148
+ */
149
+ const conform = (pattern) => (view) => {
150
+ assertConforms(pattern, view);
151
+ const conformed = view.mixins.reduce((built, mixin) => SlotViews.attach(mixin)(built), SlotViews.define(view.slots, view.render, view.name === void 0 ? {} : { name: view.name }));
152
+ Conformed.record(conformed, [...Conformed.conformancesOf(view), {
153
+ pattern,
154
+ check: (next) => assertConforms(pattern, next)
155
+ }]);
156
+ return conformed;
157
+ };
158
+ const supply = (name, spec, provides) => {
159
+ const slots = Object.create(null);
160
+ if (provides) for (const slot of Object.getOwnPropertyNames(spec)) slots[slot] = Object.freeze({
161
+ requires: Object.freeze({
162
+ events: Object.freeze([]),
163
+ attributes: Object.freeze([])
164
+ }),
165
+ provides: Object.freeze((spec[slot] ?? []).map(MetadataToken.nameOf)),
166
+ reads: "static"
167
+ });
168
+ return Object.freeze({
169
+ name,
170
+ contributions: Object.freeze(Object.create(null)),
171
+ meta: Object.freeze({
172
+ kind: "mixin",
173
+ slots: Object.freeze(slots)
174
+ }),
175
+ [ProvidesTypeId]: void 0
176
+ });
177
+ };
178
+ /** Obligations the view meets with its own attributes, such as its `aria-label`: the author's word. */
179
+ const base = (spec, options) => supply(options?.name ?? "A11y.base", spec, true);
180
+ /**
181
+ * Obligations a native element meets by itself on the slots it is drawn as,
182
+ * such as a `<button>`'s activation and focus. Named after the element.
183
+ */
184
+ const native = (spec, options) => supply(options.name ?? `A11y.native(${options.element})`, spec, true);
185
+ /**
186
+ * Obligations met on another slot by an attached Behavior, such as a
187
+ * listbox's navigation by the `ListNavigation` on a combobox's input. Each
188
+ * obligation must be one `provider` supplies on `to`: a type error otherwise,
189
+ * and `a11y:delegation-unmet` from `check` when the view does not hold
190
+ * `provider` or it supplies no such thing there.
191
+ */
192
+ const delegated = (spec, options) => {
193
+ const providerName = options.provider.name ?? "Behavior";
194
+ const made = supply(options.name ?? `A11y.delegated(${providerName})`, spec, false);
195
+ const slots = Object.create(null);
196
+ for (const slot of Object.getOwnPropertyNames(spec)) slots[slot] = Object.freeze((spec[slot] ?? []).map(MetadataToken.nameOf));
197
+ delegations.set(made, {
198
+ slots,
199
+ to: options.to,
200
+ provider: options.provider.mixin,
201
+ providerName
202
+ });
203
+ return made;
204
+ };
205
+ export { Activation, FocusStrategy, Name, Navigation, PatternTypeId, ProvidesTypeId, State, base, check, conform, delegated, native, pattern, validate };
77
206
 
78
207
  //# sourceMappingURL=a11y.js.map
package/dist/a11y.js.map CHANGED
@@ -1 +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
+ {"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, the events and\n * attributes they must expose, and the obligations something attached must\n * meet on them. `validate` compares a `Slots` contract against a pattern;\n * `check` and `conform` compare an assembled view, its attachments included.\n * All of it is pure and DOM-independent: it checks what was declared, not a\n * rendered tree, so it says the declarations fit together and never that the\n * widget conforms to WCAG.\n */\nimport type { AttrToken } from './attr.js'\nimport * as Capability from './capability.js'\nimport * as Conformed from './conformed.js'\nimport { DiagnosticError, type Diagnostic } from './diagnostics.js'\nimport * as MetadataToken from './metadataToken.js'\nimport type { NamedBehavior } from './behavior.js'\nimport type { Mixin, MixinFor, MixinMeta, StaticMixin } from './mixin.js'\nimport type { Any as AnySlot, AttributeName, EventName, SlotCapability } from './slot.js'\nimport * as SlotViews from './slotView.js'\nimport type { SlotView } from './slotView.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 | 'a11y:unsatisfied-obligation'\n | 'a11y:delegation-unmet'\n\nexport interface A11yDiagnostic extends Diagnostic {\n readonly source: 'a11y'\n readonly code: A11yDiagnosticCode\n}\n\n/**\n * What a pattern demands be done on a slot, beyond what its contract\n * publishes: something attached must say it does it. Compared by name.\n */\nexport type Obligation<Name extends string = string> = MetadataToken.MetadataToken<\n 'a11y.obligation',\n Name\n>\n\n/** Arrow keys, Home and End move among the items. */\nexport const Navigation: Obligation<'navigation'> = MetadataToken.make(\n 'a11y.obligation',\n 'navigation',\n)\n/** Each item is reachable: a roving stop, `aria-activedescendant`, or a native control. */\nexport const FocusStrategy: Obligation<'focus-strategy'> = MetadataToken.make(\n 'a11y.obligation',\n 'focus-strategy',\n)\n/** Enter, Space or a press activates it. */\nexport const Activation: Obligation<'activation'> = MetadataToken.make(\n 'a11y.obligation',\n 'activation',\n)\n/** The element has an accessible name. */\nexport const Name: Obligation<'name'> = MetadataToken.make('a11y.obligation', 'name')\n/** The attribute is written with a value on every draw. */\nexport const State = <const Attribute extends string>(\n attribute: AttrToken<Attribute>,\n): Obligation<`state:${Attribute}`> =>\n MetadataToken.make('a11y.obligation', `state:${attribute.name}` as `state:${Attribute}`)\n\nexport interface SlotRequirement {\n readonly capability?: SlotCapability\n readonly events?: ReadonlyArray<EventName>\n readonly attributes?: ReadonlyArray<AttributeName>\n /** What something attached must say it does on the slot; checked by `check` and `conform`. */\n readonly obligations?: ReadonlyArray<Obligation>\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\nexport const ProvidesTypeId: unique symbol = Symbol.for('foldkit-mixins/Provides')\n\n/**\n * The type checker's record of `Provides`. A function property, so the record\n * is contravariant: a value that supplies more is accepted where less is\n * declared (an annotated return type, a parameter typed with the default),\n * which then forgets what it supplied, and one that supplies less is refused\n * where more is declared, so an annotation cannot claim what its value lacks.\n */\ninterface ProvidesRecord<Provides extends string> {\n readonly provides: (names: Provides) => void\n}\n\n/**\n * What a value supplies, as `` `${slot}/${obligation}` `` names, for the type\n * checker alone: nothing is stored under the key. A view's names are the union\n * of what its attachments supply, and `conform` asks them to cover the\n * pattern's. Run time reads each attachment's `meta` instead, so a type that\n * claims more than its value supplies still fails `conform` when the module loads.\n */\nexport interface Supplies<Provides extends string> {\n readonly [ProvidesTypeId]?: ProvidesRecord<Provides>\n}\n\ntype OneOf<T, All = T> = T extends unknown ? ([All] extends [T] ? true : false) : never\n\n/**\n * `` `${Slot}/${Obligation}` `` when `Slot` is one known slot name, for a\n * factory's binder overload to state what it supplies. A slot chosen at run\n * time (a union, `string`) states nothing: the type cannot say which slot the\n * value will name, so only `conform`'s run-time check can judge it.\n */\nexport type ProvidedOn<Slot extends string, Obligation extends string> = string extends\n | Slot\n | Obligation\n ? never\n : OneOf<Slot> extends true\n ? `${Slot}/${Obligation}`\n : never\n\ntype ObligationNames<Requirement> = Requirement extends {\n readonly obligations: ReadonlyArray<infer Owed>\n}\n ? MetadataToken.NameOf<Owed>\n : never\n\n/**\n * What a pattern owes on the slots of `Slots`. Nothing when the slot names\n * are not known (`Record<string, …>`): such an assembly is checked when the\n * module loads.\n */\nexport type Owed<Spec, Slots> = string extends keyof Slots\n ? never\n : {\n [K in keyof Spec & keyof Slots & string]: `${K}/${ObligationNames<Spec[K]>}`\n }[keyof Spec & keyof Slots & string]\n\ntype Conforms<Spec, Slots, Provides> = [Exclude<Owed<Spec, Slots>, Provides>] extends [never]\n ? unknown\n : { readonly 'a11y:unsatisfied-obligation': Exclude<Owed<Spec, Slots>, Provides> }\n\ntype AnyView = SlotView<any, any, any, never>\n\ninterface Delegation {\n readonly slots: Readonly<Record<string, ReadonlyArray<string>>>\n readonly to: string\n readonly provider: MixinFor<any>\n readonly providerName: string\n}\n\n// Keyed by the Mixin `delegated` made: a delegation composed into another\n// Mixin is no longer one, and supplies nothing.\nconst delegations = new WeakMap<object, Delegation>()\n\nconst suppliedOn = (meta: MixinMeta | undefined, slot: string, obligation: string): boolean =>\n meta !== undefined &&\n ((Object.hasOwn(meta.slots, slot) && meta.slots[slot]!.provides.includes(obligation)) ||\n (meta.parts ?? []).some(part => suppliedOn(part.meta, slot, obligation)))\n\n/**\n * What `validate` reports of the view's contract, and every obligation of the\n * pattern on a slot the view publishes that no attachment supplies: an\n * attached Behavior's `provides`, `base`, `native`, or a `delegated` whose\n * provider is attached and supplies it on the slot named. Pure; reads only\n * the attachments' metadata, never the input or the DOM.\n */\nexport const check = (pattern: Pattern, view: AnyView): ReadonlyArray<A11yDiagnostic> => {\n const slots = view.slots as { readonly [name: string]: AnySlot }\n const mixins: ReadonlyArray<MixinFor<any>> = view.mixins\n // A part's Behaviors are found only by drawing it, so they cannot be read here.\n const assembly = Conformed.assemblies.has(view.render)\n const diagnostics = [...validate(pattern, slots)]\n for (const name of Object.getOwnPropertyNames(pattern.requirements)) {\n const obligations = pattern.requirements[name]?.obligations\n // An absent or hidden slot is `validate`'s finding, or optional and owed nothing.\n if (obligations === undefined || !Object.hasOwn(slots, name) || slots[name]!.hidden) continue\n for (const obligation of obligations) {\n const owed = MetadataToken.nameOf(obligation)\n if (mixins.some(mixin => suppliedOn(mixin.meta, name, owed))) continue\n const delegation = mixins\n .map(mixin => delegations.get(mixin))\n .find(\n found =>\n found !== undefined &&\n Object.hasOwn(found.slots, name) &&\n found.slots[name]!.includes(owed),\n )\n if (delegation === undefined) {\n diagnostics.push(\n diagnostic(\n 'a11y:unsatisfied-obligation',\n `slot \"${name}\" owes ${owed}, which nothing attached supplies${assembly ? \"; a part's own Behaviors are not read: attach the Behavior to the assembly\" : ''}`,\n name,\n { obligation: owed },\n ),\n )\n continue\n }\n const held = mixins.includes(delegation.provider)\n if (held && suppliedOn(delegation.provider.meta, delegation.to, owed)) continue\n diagnostics.push(\n diagnostic(\n 'a11y:delegation-unmet',\n `slot \"${name}\" delegates ${owed} to \"${delegation.providerName}\" on slot \"${delegation.to}\", ${held ? 'which does not supply it there' : 'which the view does not hold'}`,\n name,\n { obligation: owed, provider: delegation.providerName, to: delegation.to },\n ),\n )\n }\n }\n return diagnostics\n}\n\nconst assertConforms = (pattern: Pattern, view: AnyView): void => {\n const diagnostics = check(pattern, view)\n const first = diagnostics[0]\n if (first === undefined) return\n throw new DiagnosticError({\n ...first,\n message:\n diagnostics.length === 1\n ? first.message\n : `${first.message} (and ${diagnostics.length - 1} more)`,\n details: { ...first.details, diagnostics },\n })\n}\n\n/**\n * Refuses a view that does not meet `pattern`. At the type level, a view whose\n * attachments' supplied names do not cover what the pattern owes on its slots\n * is an error naming each `slot/obligation` missing. At run time, where the\n * module loads, `check` runs and the first finding is thrown as a\n * `DiagnosticError` with every finding in `details.diagnostics`. Returns a\n * new view that remembers the pattern, so `SlotView.detach` and\n * `SlotView.replace` check the view they make from it again; the view given is\n * unchanged.\n *\n * @example\n * ```ts\n * const Results = Search.define(render).pipe(\n * Behavior.attach(Keys),\n * A11y.conform(Listbox),\n * )\n * ```\n */\nexport const conform =\n <Spec extends Requirements>(pattern: Pattern<Spec>) =>\n <Slots, Input, Message, Provides extends string = never>(\n view: SlotView<Slots, Input, Message, Provides> & Conforms<Spec, Slots, Provides>,\n ): SlotView<Slots, Input, Message, Provides> => {\n assertConforms(pattern, view)\n // The same view made again, so the one given stays unconformed. Each Mixin\n // already met this view's Message universe when it was first attached.\n const conformed = (view as AnyView).mixins.reduce<AnyView>(\n (built, mixin) => SlotViews.attach(mixin as Mixin<any>)(built),\n SlotViews.define(view.slots, view.render, view.name === undefined ? {} : { name: view.name }),\n )\n Conformed.record(conformed, [\n ...Conformed.conformancesOf(view),\n { pattern, check: next => assertConforms(pattern, next as AnyView) },\n ])\n // The same Mixins, so the same supplies.\n return conformed as SlotView<Slots, Input, Message, Provides>\n }\n\n/** A Mixin that contributes nothing and supplies obligations, attached with `SlotView.attach`. */\nexport interface Supply<Provides extends string> extends StaticMixin<never> {\n readonly [ProvidesTypeId]: ProvidesRecord<Provides>\n}\n\n/** Per slot, the obligations supplied there. */\nexport type SupplySpec = Readonly<Record<string, ReadonlyArray<Obligation>>>\n\nexport type SuppliedBy<Spec> = {\n [K in keyof Spec & string]: Spec[K] extends ReadonlyArray<infer Supplied>\n ? `${K}/${MetadataToken.NameOf<Supplied>}`\n : never\n}[keyof Spec & string]\n\nconst supply = <Provides extends string>(\n name: string,\n spec: SupplySpec,\n provides: boolean,\n): Supply<Provides> => {\n const slots: Record<string, MixinMeta['slots'][string]> = Object.create(null)\n if (provides) {\n for (const slot of Object.getOwnPropertyNames(spec)) {\n slots[slot] = Object.freeze({\n requires: Object.freeze({ events: Object.freeze([]), attributes: Object.freeze([]) }),\n provides: Object.freeze((spec[slot] ?? []).map(MetadataToken.nameOf)),\n reads: 'static' as const,\n })\n }\n }\n return Object.freeze({\n name,\n contributions: Object.freeze(Object.create(null)),\n meta: Object.freeze({ kind: 'mixin' as const, slots: Object.freeze(slots) }),\n [ProvidesTypeId]: undefined as unknown as ProvidesRecord<Provides>,\n })\n}\n\n/** Obligations the view meets with its own attributes, such as its `aria-label`: the author's word. */\nexport const base = <const Spec extends SupplySpec>(\n spec: Spec,\n options?: { readonly name?: string },\n): Supply<SuppliedBy<Spec>> => supply(options?.name ?? 'A11y.base', spec, true)\n\n/** The HTML elements that are interactive by themselves. */\nexport type NativeElement =\n | 'a'\n | 'button'\n | 'details'\n | 'input'\n | 'option'\n | 'select'\n | 'summary'\n | 'textarea'\n\n/**\n * Obligations a native element meets by itself on the slots it is drawn as,\n * such as a `<button>`'s activation and focus. Named after the element.\n */\nexport const native = <const Spec extends SupplySpec>(\n spec: Spec,\n options: { readonly element: NativeElement; readonly name?: string },\n): Supply<SuppliedBy<Spec>> => supply(options.name ?? `A11y.native(${options.element})`, spec, true)\n\ntype SuppliedOn<Provides, To extends string> = Provides extends `${To}/${infer Supplied}`\n ? Supplied\n : never\n\n/**\n * Obligations met on another slot by an attached Behavior, such as a\n * listbox's navigation by the `ListNavigation` on a combobox's input. Each\n * obligation must be one `provider` supplies on `to`: a type error otherwise,\n * and `a11y:delegation-unmet` from `check` when the view does not hold\n * `provider` or it supplies no such thing there.\n */\nexport const delegated = <\n const Spec extends Readonly<Record<string, ReadonlyArray<Obligation<SuppliedOn<Provides, To>>>>>,\n ProviderSlots,\n To extends keyof ProviderSlots & string,\n Provides extends string = never,\n>(\n spec: Spec,\n options: {\n readonly to: To\n readonly provider: NamedBehavior<ProviderSlots, any, any, Provides>\n readonly name?: string\n },\n): Supply<SuppliedBy<Spec>> => {\n const providerName = options.provider.name ?? 'Behavior'\n const made = supply<SuppliedBy<Spec>>(\n options.name ?? `A11y.delegated(${providerName})`,\n spec,\n false,\n )\n const slots: Record<string, ReadonlyArray<string>> = Object.create(null)\n for (const slot of Object.getOwnPropertyNames(spec)) {\n slots[slot] = Object.freeze((spec[slot] ?? []).map(MetadataToken.nameOf))\n }\n delegations.set(made, {\n slots,\n to: options.to,\n provider: options.provider.mixin,\n providerName,\n })\n return made\n}\n"],"mappings":";;;;;;;AA6CA,MAAa,aAAuC,cAAc,KAChE,mBACA,YACF;;AAEA,MAAa,gBAA8C,cAAc,KACvE,mBACA,gBACF;;AAEA,MAAa,aAAuC,cAAc,KAChE,mBACA,YACF;;AAEA,MAAa,OAA2B,cAAc,KAAK,mBAAmB,MAAM;;AAEpF,MAAa,SACX,cAEA,cAAc,KAAK,mBAAmB,SAAS,UAAU,MAA8B;AAczF,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;CAC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A,IAAI,QAAQ;EACZ,UAAU,QAAQ,SAAS;EAC3B;CACF,CAAC;CACD,OAAO;AACT"}
package/dist/attr.d.ts CHANGED
@@ -10,10 +10,18 @@ export declare const Role: AttrToken<"role">;
10
10
  export declare const AriaLabel: AttrToken<"aria-label">;
11
11
  export declare const AriaDescribedby: AttrToken<"aria-describedby">;
12
12
  export declare const AriaExpanded: AttrToken<"aria-expanded">;
13
+ export declare const AriaSort: AttrToken<"aria-sort">;
13
14
  export declare const AriaSelected: AttrToken<"aria-selected">;
14
15
  export declare const AriaInvalid: AttrToken<"aria-invalid">;
15
16
  export declare const AriaPressed: AttrToken<"aria-pressed">;
17
+ export declare const AriaChecked: AttrToken<"aria-checked">;
16
18
  export declare const AriaDisabled: AttrToken<"aria-disabled">;
17
19
  export declare const Disabled: AttrToken<"disabled">;
18
20
  export declare const Value: AttrToken<"value">;
21
+ export declare const AriaLabelledby: AttrToken<"aria-labelledby">;
22
+ export declare const AriaControls: AttrToken<"aria-controls">;
23
+ export declare const AriaReadonly: AttrToken<"aria-readonly">;
24
+ export declare const AriaRequired: AttrToken<"aria-required">;
25
+ export declare const AriaCurrent: AttrToken<"aria-current">;
26
+ export declare const AriaValuenow: AttrToken<"aria-valuenow">;
19
27
  //# sourceMappingURL=attr.d.ts.map
@@ -1 +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"}
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;;qBAMzC,MAAI;qBACJ,WAAS;qBACT,iBAAe;qBACf,cAAY;qBACZ,UAAQ;qBACR,cAAY;qBACZ,aAAW;qBACX,aAAW;qBACX,aAAW;qBACX,cAAY;qBACZ,UAAQ;qBACR,OAAK;qBACL,gBAAc;qBACd,cAAY;qBACZ,cAAY;qBACZ,cAAY;qBACZ,aAAW;qBACX,cAAY"}
package/dist/attr.js CHANGED
@@ -8,16 +8,24 @@ const is = (value) => MetadataToken.is(value) && value.kind === "view.attribute"
8
8
  const make = (name) => MetadataToken.make("view.attribute", name);
9
9
  const equals = (left, right) => left.name === right.name;
10
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 };
11
+ const Role = /* @__PURE__ */ make("role");
12
+ const AriaLabel = /* @__PURE__ */ make("aria-label");
13
+ const AriaDescribedby = /* @__PURE__ */ make("aria-describedby");
14
+ const AriaExpanded = /* @__PURE__ */ make("aria-expanded");
15
+ const AriaSort = /* @__PURE__ */ make("aria-sort");
16
+ const AriaSelected = /* @__PURE__ */ make("aria-selected");
17
+ const AriaInvalid = /* @__PURE__ */ make("aria-invalid");
18
+ const AriaPressed = /* @__PURE__ */ make("aria-pressed");
19
+ const AriaChecked = /* @__PURE__ */ make("aria-checked");
20
+ const AriaDisabled = /* @__PURE__ */ make("aria-disabled");
21
+ const Disabled = /* @__PURE__ */ make("disabled");
22
+ const Value = /* @__PURE__ */ make("value");
23
+ const AriaLabelledby = /* @__PURE__ */ make("aria-labelledby");
24
+ const AriaControls = /* @__PURE__ */ make("aria-controls");
25
+ const AriaReadonly = /* @__PURE__ */ make("aria-readonly");
26
+ const AriaRequired = /* @__PURE__ */ make("aria-required");
27
+ const AriaCurrent = /* @__PURE__ */ make("aria-current");
28
+ const AriaValuenow = /* @__PURE__ */ make("aria-valuenow");
29
+ export { AriaChecked, AriaControls, AriaCurrent, AriaDescribedby, AriaDisabled, AriaExpanded, AriaInvalid, AriaLabel, AriaLabelledby, AriaPressed, AriaReadonly, AriaRequired, AriaSelected, AriaSort, AriaValuenow, Disabled, Role, Value, describe, equals, is, make };
22
30
 
23
31
  //# sourceMappingURL=attr.js.map
package/dist/attr.js.map CHANGED
@@ -1 +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"}
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\n// Each `make` is marked pure so a page that reads none of these drops it: an unmarked call\n// runs at load and stays in every bundle (seven tokens cost the counter 144 bytes brotli).\nexport const Role = /* @__PURE__ */ make('role')\nexport const AriaLabel = /* @__PURE__ */ make('aria-label')\nexport const AriaDescribedby = /* @__PURE__ */ make('aria-describedby')\nexport const AriaExpanded = /* @__PURE__ */ make('aria-expanded')\nexport const AriaSort = /* @__PURE__ */ make('aria-sort')\nexport const AriaSelected = /* @__PURE__ */ make('aria-selected')\nexport const AriaInvalid = /* @__PURE__ */ make('aria-invalid')\nexport const AriaPressed = /* @__PURE__ */ make('aria-pressed')\nexport const AriaChecked = /* @__PURE__ */ make('aria-checked')\nexport const AriaDisabled = /* @__PURE__ */ make('aria-disabled')\nexport const Disabled = /* @__PURE__ */ make('disabled')\nexport const Value = /* @__PURE__ */ make('value')\nexport const AriaLabelledby = /* @__PURE__ */ make('aria-labelledby')\nexport const AriaControls = /* @__PURE__ */ make('aria-controls')\nexport const AriaReadonly = /* @__PURE__ */ make('aria-readonly')\nexport const AriaRequired = /* @__PURE__ */ make('aria-required')\nexport const AriaCurrent = /* @__PURE__ */ make('aria-current')\nexport const AriaValuenow = /* @__PURE__ */ make('aria-valuenow')\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;AAIA,MAAa,OAAuB,qBAAK,MAAM;AAC/C,MAAa,YAA4B,qBAAK,YAAY;AAC1D,MAAa,kBAAkC,qBAAK,kBAAkB;AACtE,MAAa,eAA+B,qBAAK,eAAe;AAChE,MAAa,WAA2B,qBAAK,WAAW;AACxD,MAAa,eAA+B,qBAAK,eAAe;AAChE,MAAa,cAA8B,qBAAK,cAAc;AAC9D,MAAa,cAA8B,qBAAK,cAAc;AAC9D,MAAa,cAA8B,qBAAK,cAAc;AAC9D,MAAa,eAA+B,qBAAK,eAAe;AAChE,MAAa,WAA2B,qBAAK,UAAU;AACvD,MAAa,QAAwB,qBAAK,OAAO;AACjD,MAAa,iBAAiC,qBAAK,iBAAiB;AACpE,MAAa,eAA+B,qBAAK,eAAe;AAChE,MAAa,eAA+B,qBAAK,eAAe;AAChE,MAAa,eAA+B,qBAAK,eAAe;AAChE,MAAa,cAA8B,qBAAK,cAAc;AAC9D,MAAa,eAA+B,qBAAK,eAAe"}
@@ -1,6 +1,8 @@
1
+ import * as MetadataToken from "./metadataToken.js";
2
+ import * as SlotView$1 from "./slotView.js";
1
3
  import { Attribute, ChildAttribute, HtmlBuilder } from "foldkit/html";
2
4
  import { Mixin } from "./mixin.js";
3
- import * as SlotView from "./slotView.js";
5
+ import { Obligation, ProvidedOn, Supplies } from "./a11y.js";
4
6
  import { AttributeName, EventName, HiddenOf, SlotCapability } from "./slot.js";
5
7
  import { MountAction } from "foldkit/mount";
6
8
  import { SlotItem } from "./contribution.js";
@@ -11,6 +13,11 @@ export interface SlotRequirements {
11
13
  }
12
14
  export interface BehaviorSlotOptions<Input, Message> {
13
15
  readonly requires?: SlotRequirements;
16
+ /**
17
+ * The obligations (`A11y.Navigation`, …) this slot's contributions meet,
18
+ * which `A11y.conform` reads. Declared, not inferred from the attributes.
19
+ */
20
+ readonly provides?: ReadonlyArray<Obligation>;
14
21
  /**
15
22
  * Attributes for one resolution of the slot. `item` is present when the view
16
23
  * passed one to `slots.x.attrs(base, item)`, that is, when the slot is
@@ -24,16 +31,32 @@ export interface BehaviorSlotOptions<Input, Message> {
24
31
  readonly mount?: (input: Input, item?: SlotItem) => MountAction<Message, any>;
25
32
  }
26
33
  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> {
34
+ /**
35
+ * What a spec's slots say they supply, as `` `${slot}/${obligation}` ``: each
36
+ * slot's `provides`, when its obligations' names are known.
37
+ */
38
+ export type ProvidesOf<Spec> = { [K in keyof Spec & string]-?: NonNullable<Spec[K]> extends {
39
+ readonly provides: ReadonlyArray<infer Supplied>;
40
+ } ? ProvidedOn<K, MetadataToken.NameOf<Supplied>> : never; }[keyof Spec & string];
41
+ /**
42
+ * A Behavior. `Provides` names, as `` `${slot}/${obligation}` ``, what it
43
+ * supplies for `A11y.conform` at the type level: `forSlots` and a binder's
44
+ * `behavior` read it from each slot's `provides`, and a factory given a
45
+ * `SlotView.over` binder states it from the slot names it was given.
46
+ */
47
+ export interface NamedBehavior<Slots, Input, Message, Provides extends string = never> extends Supplies<Provides> {
28
48
  readonly name?: string;
29
49
  readonly spec: BehaviorSpec<Slots, Input, Message>;
30
50
  readonly mixin: Mixin<Message>;
31
51
  }
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?: {
52
+ /**
53
+ * Identity helper; `forSlots` supplies the contextual `Input`/`Message`, and
54
+ * reads what the slot supplies from its `provides`.
55
+ */
56
+ export declare const slot: <const Options extends BehaviorSlotOptions<any, any>>(options: Options) => Options;
57
+ export declare const forSlots: <Slots>(slots: Slots) => <Input, Message, const Spec extends BehaviorSpec<Slots, Input, Message> = BehaviorSpec<Slots, Input, Message>>(spec: Spec, options?: {
35
58
  readonly name?: string;
36
- }) => NamedBehavior<Slots, Input, Message>;
59
+ }) => NamedBehavior<Slots, Input, Message, ProvidesOf<Spec>>;
37
60
  /**
38
61
  * Attaches a Behavior to a view. The behavior's `Input` becomes the attached
39
62
  * view's `Input`: a behavior declared over only the fields it reads is rejected
@@ -41,10 +64,20 @@ export declare const forSlots: <Slots>(slots: Slots) => <Input, Message>(spec: B
41
64
  * widens what the view must be called with. Declare `Input` as the view's own
42
65
  * input type.
43
66
  */
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>;
67
+ export declare const attach: <BehaviorSlots, Message, Input, Provides extends string = never>(behavior: NamedBehavior<BehaviorSlots, Input, Message, Provides>) => <ViewSlots, ViewProvides extends string = never>(view: SlotView$1.SlotView<ViewSlots, Input, Message, ViewProvides>) => SlotView$1.SlotView<ViewSlots, Input, Message, ViewProvides | Provides>;
68
+ /** What each Behavior of a list supplies, as one union. */
69
+ type ProvidesOfAll<Behaviors> = Behaviors extends NamedBehavior<any, any, any, infer Provides> ? Provides : never;
70
+ /**
71
+ * Attaches a list of Behaviors in one step, in order, and the view supplies
72
+ * what each of them does: for a factory that hands back several
73
+ * (`Overlay.behaviors`), so a pipe that then calls `A11y.conform` stays typed.
74
+ */
75
+ export declare const attachAll: <BehaviorSlots, Message, Input, const Behaviors extends ReadonlyArray<NamedBehavior<BehaviorSlots, Input, Message, never>>>(behaviors: Behaviors & ReadonlyArray<NamedBehavior<BehaviorSlots, Input, Message, never>>) => <ViewSlots, ViewProvides extends string = never>(view: SlotView$1.SlotView<ViewSlots, Input, Message, ViewProvides>) => SlotView$1.SlotView<ViewSlots, Input, Message, ViewProvides | ProvidesOfAll<Behaviors[number]>>;
45
76
  export declare const Behavior: {
46
77
  readonly slot: typeof slot;
47
78
  readonly forSlots: typeof forSlots;
48
79
  readonly attach: typeof attach;
80
+ readonly attachAll: typeof attachAll;
49
81
  };
82
+ export {};
50
83
  //# sourceMappingURL=behavior.d.ts.map
@@ -1 +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,KAA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