@ac-kit/ui-common 0.1.0 → 0.3.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 (231) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/README.md +383 -9
  3. package/dist/adapter/_anchor.d.ts +13 -0
  4. package/dist/adapter/_anchor.d.ts.map +1 -0
  5. package/dist/adapter/_anchor.js +39 -0
  6. package/dist/adapter/_anchor.js.map +1 -0
  7. package/dist/adapter/_dom.d.ts +14 -0
  8. package/dist/adapter/_dom.d.ts.map +1 -0
  9. package/dist/adapter/_dom.js +31 -0
  10. package/dist/adapter/_dom.js.map +1 -0
  11. package/dist/adapter/_live-announcer.d.ts +26 -0
  12. package/dist/adapter/_live-announcer.d.ts.map +1 -0
  13. package/dist/adapter/_live-announcer.js +101 -0
  14. package/dist/adapter/_live-announcer.js.map +1 -0
  15. package/dist/adapter/join-classes.d.ts.map +1 -0
  16. package/dist/adapter/join-classes.js.map +1 -0
  17. package/dist/anchored/anchored.d.ts +19 -0
  18. package/dist/anchored/anchored.d.ts.map +1 -0
  19. package/dist/anchored/anchored.js +2 -0
  20. package/dist/anchored/anchored.js.map +1 -0
  21. package/dist/bit-grid/bit-grid.d.ts +151 -0
  22. package/dist/bit-grid/bit-grid.d.ts.map +1 -0
  23. package/dist/bit-grid/bit-grid.js +201 -0
  24. package/dist/bit-grid/bit-grid.js.map +1 -0
  25. package/dist/focus/typeahead.d.ts +112 -0
  26. package/dist/focus/typeahead.d.ts.map +1 -0
  27. package/dist/focus/typeahead.js +178 -0
  28. package/dist/focus/typeahead.js.map +1 -0
  29. package/dist/index.d.ts +12 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +12 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/menu/menu.d.ts +157 -0
  34. package/dist/menu/menu.d.ts.map +1 -0
  35. package/dist/menu/menu.js +162 -0
  36. package/dist/menu/menu.js.map +1 -0
  37. package/dist/preact/bit-grid.d.ts +39 -0
  38. package/dist/preact/bit-grid.d.ts.map +1 -0
  39. package/dist/preact/bit-grid.js +72 -0
  40. package/dist/preact/bit-grid.js.map +1 -0
  41. package/dist/preact/button.d.ts.map +1 -1
  42. package/dist/preact/button.js +1 -1
  43. package/dist/preact/button.js.map +1 -1
  44. package/dist/preact/dialog.d.ts.map +1 -1
  45. package/dist/preact/dialog.js +1 -1
  46. package/dist/preact/dialog.js.map +1 -1
  47. package/dist/preact/index.d.ts +10 -1
  48. package/dist/preact/index.d.ts.map +1 -1
  49. package/dist/preact/index.js +10 -1
  50. package/dist/preact/index.js.map +1 -1
  51. package/dist/preact/knob.d.ts.map +1 -1
  52. package/dist/preact/knob.js +6 -14
  53. package/dist/preact/knob.js.map +1 -1
  54. package/dist/preact/menu-button.d.ts +117 -0
  55. package/dist/preact/menu-button.d.ts.map +1 -0
  56. package/dist/preact/menu-button.js +330 -0
  57. package/dist/preact/menu-button.js.map +1 -0
  58. package/dist/preact/meter.d.ts.map +1 -1
  59. package/dist/preact/meter.js +1 -1
  60. package/dist/preact/meter.js.map +1 -1
  61. package/dist/preact/progress-ring.d.ts +42 -0
  62. package/dist/preact/progress-ring.d.ts.map +1 -0
  63. package/dist/preact/progress-ring.js +26 -0
  64. package/dist/preact/progress-ring.js.map +1 -0
  65. package/dist/preact/radio-group.d.ts.map +1 -1
  66. package/dist/preact/radio-group.js +1 -1
  67. package/dist/preact/radio-group.js.map +1 -1
  68. package/dist/preact/readout.d.ts.map +1 -1
  69. package/dist/preact/readout.js +1 -1
  70. package/dist/preact/readout.js.map +1 -1
  71. package/dist/preact/slider.d.ts.map +1 -1
  72. package/dist/preact/slider.js +7 -5
  73. package/dist/preact/slider.js.map +1 -1
  74. package/dist/preact/spin-button.d.ts +67 -0
  75. package/dist/preact/spin-button.d.ts.map +1 -0
  76. package/dist/preact/spin-button.js +132 -0
  77. package/dist/preact/spin-button.js.map +1 -0
  78. package/dist/preact/swatch-strip.d.ts +30 -0
  79. package/dist/preact/swatch-strip.d.ts.map +1 -0
  80. package/dist/preact/swatch-strip.js +17 -0
  81. package/dist/preact/swatch-strip.js.map +1 -0
  82. package/dist/preact/switch.js +1 -1
  83. package/dist/preact/switch.js.map +1 -1
  84. package/dist/preact/tabs.d.ts +97 -0
  85. package/dist/preact/tabs.d.ts.map +1 -0
  86. package/dist/preact/tabs.js +264 -0
  87. package/dist/preact/tabs.js.map +1 -0
  88. package/dist/preact/toaster.d.ts +43 -0
  89. package/dist/preact/toaster.d.ts.map +1 -0
  90. package/dist/preact/toaster.js +356 -0
  91. package/dist/preact/toaster.js.map +1 -0
  92. package/dist/preact/toggle-button.d.ts.map +1 -1
  93. package/dist/preact/toggle-button.js +1 -1
  94. package/dist/preact/toggle-button.js.map +1 -1
  95. package/dist/preact/toolbar.d.ts.map +1 -1
  96. package/dist/preact/toolbar.js +3 -9
  97. package/dist/preact/toolbar.js.map +1 -1
  98. package/dist/preact/tooltip.d.ts +67 -0
  99. package/dist/preact/tooltip.d.ts.map +1 -0
  100. package/dist/preact/tooltip.js +165 -0
  101. package/dist/preact/tooltip.js.map +1 -0
  102. package/dist/preact/tree.d.ts +93 -0
  103. package/dist/preact/tree.d.ts.map +1 -0
  104. package/dist/preact/tree.js +399 -0
  105. package/dist/preact/tree.js.map +1 -0
  106. package/dist/progress/progress.d.ts +51 -0
  107. package/dist/progress/progress.d.ts.map +1 -0
  108. package/dist/progress/progress.js +43 -0
  109. package/dist/progress/progress.js.map +1 -0
  110. package/dist/react/_props.d.ts +22 -0
  111. package/dist/react/_props.d.ts.map +1 -0
  112. package/dist/react/_props.js +14 -0
  113. package/dist/react/_props.js.map +1 -0
  114. package/dist/react/bit-grid.d.ts +40 -0
  115. package/dist/react/bit-grid.d.ts.map +1 -0
  116. package/dist/react/bit-grid.js +71 -0
  117. package/dist/react/bit-grid.js.map +1 -0
  118. package/dist/react/button.d.ts +60 -0
  119. package/dist/react/button.d.ts.map +1 -0
  120. package/dist/react/button.js +34 -0
  121. package/dist/react/button.js.map +1 -0
  122. package/dist/react/dialog.d.ts +44 -0
  123. package/dist/react/dialog.d.ts.map +1 -0
  124. package/dist/react/dialog.js +91 -0
  125. package/dist/react/dialog.js.map +1 -0
  126. package/dist/react/index.d.ts +22 -0
  127. package/dist/react/index.d.ts.map +1 -0
  128. package/dist/react/index.js +22 -0
  129. package/dist/react/index.js.map +1 -0
  130. package/dist/react/knob.d.ts +55 -0
  131. package/dist/react/knob.d.ts.map +1 -0
  132. package/dist/react/knob.js +144 -0
  133. package/dist/react/knob.js.map +1 -0
  134. package/dist/react/menu-button.d.ts +147 -0
  135. package/dist/react/menu-button.d.ts.map +1 -0
  136. package/dist/react/menu-button.js +342 -0
  137. package/dist/react/menu-button.js.map +1 -0
  138. package/dist/react/meter.d.ts +34 -0
  139. package/dist/react/meter.d.ts.map +1 -0
  140. package/dist/react/meter.js +23 -0
  141. package/dist/react/meter.js.map +1 -0
  142. package/dist/react/progress-ring.d.ts +42 -0
  143. package/dist/react/progress-ring.d.ts.map +1 -0
  144. package/dist/react/progress-ring.js +28 -0
  145. package/dist/react/progress-ring.js.map +1 -0
  146. package/dist/react/radio-group.d.ts +52 -0
  147. package/dist/react/radio-group.d.ts.map +1 -0
  148. package/dist/react/radio-group.js +30 -0
  149. package/dist/react/radio-group.js.map +1 -0
  150. package/dist/react/readout.d.ts +23 -0
  151. package/dist/react/readout.d.ts.map +1 -0
  152. package/dist/react/readout.js +13 -0
  153. package/dist/react/readout.js.map +1 -0
  154. package/dist/react/slider.d.ts +44 -0
  155. package/dist/react/slider.d.ts.map +1 -0
  156. package/dist/react/slider.js +167 -0
  157. package/dist/react/slider.js.map +1 -0
  158. package/dist/react/spin-button.d.ts +71 -0
  159. package/dist/react/spin-button.d.ts.map +1 -0
  160. package/dist/react/spin-button.js +132 -0
  161. package/dist/react/spin-button.js.map +1 -0
  162. package/dist/react/swatch-strip.d.ts +31 -0
  163. package/dist/react/swatch-strip.d.ts.map +1 -0
  164. package/dist/react/swatch-strip.js +17 -0
  165. package/dist/react/swatch-strip.js.map +1 -0
  166. package/dist/react/switch.d.ts +26 -0
  167. package/dist/react/switch.d.ts.map +1 -0
  168. package/dist/react/switch.js +19 -0
  169. package/dist/react/switch.js.map +1 -0
  170. package/dist/react/tabs.d.ts +95 -0
  171. package/dist/react/tabs.d.ts.map +1 -0
  172. package/dist/react/tabs.js +274 -0
  173. package/dist/react/tabs.js.map +1 -0
  174. package/dist/react/toaster.d.ts +43 -0
  175. package/dist/react/toaster.d.ts.map +1 -0
  176. package/dist/react/toaster.js +368 -0
  177. package/dist/react/toaster.js.map +1 -0
  178. package/dist/react/toggle-button.d.ts +37 -0
  179. package/dist/react/toggle-button.d.ts.map +1 -0
  180. package/dist/react/toggle-button.js +22 -0
  181. package/dist/react/toggle-button.js.map +1 -0
  182. package/dist/react/toolbar.d.ts +25 -0
  183. package/dist/react/toolbar.d.ts.map +1 -0
  184. package/dist/react/toolbar.js +143 -0
  185. package/dist/react/toolbar.js.map +1 -0
  186. package/dist/react/tooltip.d.ts +68 -0
  187. package/dist/react/tooltip.d.ts.map +1 -0
  188. package/dist/react/tooltip.js +165 -0
  189. package/dist/react/tooltip.js.map +1 -0
  190. package/dist/react/tree.d.ts +94 -0
  191. package/dist/react/tree.d.ts.map +1 -0
  192. package/dist/react/tree.js +422 -0
  193. package/dist/react/tree.js.map +1 -0
  194. package/dist/react/use-element-binding.d.ts +35 -0
  195. package/dist/react/use-element-binding.d.ts.map +1 -0
  196. package/dist/react/use-element-binding.js +51 -0
  197. package/dist/react/use-element-binding.js.map +1 -0
  198. package/dist/spin-button/spin-button.d.ts +110 -0
  199. package/dist/spin-button/spin-button.d.ts.map +1 -0
  200. package/dist/spin-button/spin-button.js +179 -0
  201. package/dist/spin-button/spin-button.js.map +1 -0
  202. package/dist/swatch-strip/swatch-strip.d.ts +60 -0
  203. package/dist/swatch-strip/swatch-strip.d.ts.map +1 -0
  204. package/dist/swatch-strip/swatch-strip.js +60 -0
  205. package/dist/swatch-strip/swatch-strip.js.map +1 -0
  206. package/dist/tabs/tabs.d.ts +157 -0
  207. package/dist/tabs/tabs.d.ts.map +1 -0
  208. package/dist/tabs/tabs.js +120 -0
  209. package/dist/tabs/tabs.js.map +1 -0
  210. package/dist/toast/toast-queue.d.ts +212 -0
  211. package/dist/toast/toast-queue.d.ts.map +1 -0
  212. package/dist/toast/toast-queue.js +290 -0
  213. package/dist/toast/toast-queue.js.map +1 -0
  214. package/dist/toast/toasts-obscure.d.ts +25 -0
  215. package/dist/toast/toasts-obscure.d.ts.map +1 -0
  216. package/dist/toast/toasts-obscure.js +30 -0
  217. package/dist/toast/toasts-obscure.js.map +1 -0
  218. package/dist/tooltip/tooltip.d.ts +183 -0
  219. package/dist/tooltip/tooltip.d.ts.map +1 -0
  220. package/dist/tooltip/tooltip.js +185 -0
  221. package/dist/tooltip/tooltip.js.map +1 -0
  222. package/dist/tree/tree.d.ts +302 -0
  223. package/dist/tree/tree.d.ts.map +1 -0
  224. package/dist/tree/tree.js +439 -0
  225. package/dist/tree/tree.js.map +1 -0
  226. package/package.json +47 -14
  227. package/styles.css +1084 -3
  228. package/dist/preact/join-classes.d.ts.map +0 -1
  229. package/dist/preact/join-classes.js.map +0 -1
  230. /package/dist/{preact → adapter}/join-classes.d.ts +0 -0
  231. /package/dist/{preact → adapter}/join-classes.js +0 -0
@@ -0,0 +1,179 @@
1
+ import { assertFinite, assertPositive, clamp, describeValue, } from "@ac-kit/core";
2
+ import { quantize } from "@ac-kit/math-scalar";
3
+ import { snapSliderValue } from "../slider/slider-range.js";
4
+ import { steppedValue } from "../slider/stepped-value.js";
5
+ /** @throws {RangeError} When the range has no step or inverted bounds. */
6
+ function assertSpinButtonRange_(range) {
7
+ const { min, max, step } = range;
8
+ assertPositive(step, "step");
9
+ if (min !== undefined) {
10
+ assertFinite(min, "min");
11
+ }
12
+ if (max !== undefined) {
13
+ assertFinite(max, "max");
14
+ }
15
+ if (min !== undefined && max !== undefined && !(max > min)) {
16
+ throw new RangeError(`A spin button range needs max > min, got [${describeValue(min)}, ${describeValue(max)}].`);
17
+ }
18
+ }
19
+ function sliderRangeOf_(range) {
20
+ const { min, max, step } = range;
21
+ return min === undefined || max === undefined
22
+ ? undefined
23
+ : { min, max, step };
24
+ }
25
+ /**
26
+ * The value a spin button settles on for `value`, typed or stepped to: the
27
+ * nearest step, kept within the bounds it has. A value at or past a bound gives
28
+ * that bound, so a bound off the grid of steps stays reachable. With both
29
+ * bounds, this is {@link snapSliderValue}.
30
+ *
31
+ * `NaN` gives the origin of the steps (`min`, else `max`, else 0).
32
+ *
33
+ * Time complexity: O(1). Memory: O(1).
34
+ *
35
+ * @example
36
+ * snapSpinButtonValue(7.4, { min: 0, step: 0.5 }); // 7.5
37
+ * snapSpinButtonValue(-3, { min: 0, step: 1 }); // 0
38
+ * snapSpinButtonValue(1e6, { min: 0, step: 1 }); // 1000000: no maximum
39
+ *
40
+ * @throws {RangeError} When `step` is not above zero, a bound is not finite,
41
+ * `max` is not above `min`, or `value` is infinite towards a side with no
42
+ * bound.
43
+ */
44
+ export function snapSpinButtonValue(value, range) {
45
+ assertSpinButtonRange_(range);
46
+ const bounded = sliderRangeOf_(range);
47
+ if (bounded !== undefined) {
48
+ return snapSliderValue(value, bounded);
49
+ }
50
+ const { min, max, step } = range;
51
+ const origin = min ?? max ?? 0;
52
+ if (Number.isNaN(value)) {
53
+ return origin;
54
+ }
55
+ if (min !== undefined && value <= min) {
56
+ return min;
57
+ }
58
+ if (max !== undefined && value >= max) {
59
+ return max;
60
+ }
61
+ assertFinite(value, "value");
62
+ const snapped = quantize(value, step, origin);
63
+ // The nearest step may lie past the largest finite number: take the one
64
+ // before it, towards the origin.
65
+ const finite = Number.isFinite(snapped)
66
+ ? snapped
67
+ : quantize(value - Math.sign(value - origin) * step, step, origin);
68
+ return clamp(finite, min ?? Number.NEGATIVE_INFINITY, max ?? Number.POSITIVE_INFINITY);
69
+ }
70
+ /**
71
+ * The value a key moves a spin button to (WAI-ARIA spinbutton pattern): Arrow
72
+ * Up one step up, Arrow Down one down, Page Up and Page Down a large step, Home
73
+ * to `min` and End to `max` when the range has them. The result is snapped
74
+ * ({@link snapSpinButtonValue}), so stepping past a bound gives that bound;
75
+ * with both bounds, this is {@link steppedValue}'s, without Arrow Left and Arrow
76
+ * Right, which move the caret in an editable field.
77
+ *
78
+ * `undefined` for any other key, Home without `min` and End without `max`:
79
+ * leave those to the browser. A result equal to `value` means the key was a
80
+ * step key but the value cannot move that way (at a bound, or a step that would
81
+ * overflow): consume the key, report no change.
82
+ *
83
+ * Time complexity: O(1). Memory: O(1).
84
+ *
85
+ * @example
86
+ * spinButtonValue(4, "ArrowUp", { min: 1, step: 1 }); // 5
87
+ * spinButtonValue(4, "PageDown", { min: 1, step: 1 }); // 1
88
+ * spinButtonValue(4, "End", { min: 1, step: 1 }); // undefined: no maximum
89
+ *
90
+ * @throws {RangeError} When the range is invalid ({@link snapSpinButtonValue})
91
+ * or `largeStep` is not above zero.
92
+ */
93
+ export function spinButtonValue(value, key, range, options = {}) {
94
+ assertSpinButtonRange_(range);
95
+ const { min, max, step } = range;
96
+ const { largeStep = Math.min(step * 10, Number.MAX_VALUE) } = options;
97
+ assertPositive(largeStep, "largeStep");
98
+ let next;
99
+ switch (key) {
100
+ case "ArrowUp":
101
+ next = value + step;
102
+ break;
103
+ case "ArrowDown":
104
+ next = value - step;
105
+ break;
106
+ case "PageUp":
107
+ next = value + largeStep;
108
+ break;
109
+ case "PageDown":
110
+ next = value - largeStep;
111
+ break;
112
+ case "Home":
113
+ if (min === undefined) {
114
+ return undefined;
115
+ }
116
+ next = min;
117
+ break;
118
+ case "End":
119
+ if (max === undefined) {
120
+ return undefined;
121
+ }
122
+ next = max;
123
+ break;
124
+ default:
125
+ return undefined;
126
+ }
127
+ const bounded = sliderRangeOf_(range);
128
+ if (bounded !== undefined) {
129
+ return steppedValue(value, key, bounded, { largeStep });
130
+ }
131
+ if (!Number.isFinite(next) && Number.isFinite(value)) {
132
+ return snapSpinButtonValue(value, range);
133
+ }
134
+ return snapSpinButtonValue(next, range);
135
+ }
136
+ /**
137
+ * The `spinbutton` role and its value attributes: what assistive technology
138
+ * announces, and what every adapter renders the same way.
139
+ *
140
+ * Time complexity: O(1). Memory: O(1).
141
+ *
142
+ * @example
143
+ * spinButtonAttributes({
144
+ * label: "Copies",
145
+ * value: 4,
146
+ * range: { min: 1, step: 1 },
147
+ * valueText: "4",
148
+ * });
149
+ * // { role: "spinbutton", "aria-label": "Copies", "aria-valuemin": 1,
150
+ * // "aria-valuenow": 4, "aria-valuetext": "4" }
151
+ *
152
+ * @throws {RangeError} When the range is invalid ({@link snapSpinButtonValue}).
153
+ */
154
+ export function spinButtonAttributes(input) {
155
+ const { label, value, range, valueText, disabled } = input;
156
+ assertSpinButtonRange_(range);
157
+ const { min, max } = range;
158
+ const attributes = {
159
+ role: "spinbutton",
160
+ "aria-valuenow": Number.isNaN(value)
161
+ ? (min ?? max ?? 0)
162
+ : clamp(value, min ?? Number.NEGATIVE_INFINITY, max ?? Number.POSITIVE_INFINITY),
163
+ "aria-valuetext": valueText,
164
+ };
165
+ if (label !== undefined) {
166
+ attributes["aria-label"] = label;
167
+ }
168
+ if (min !== undefined) {
169
+ attributes["aria-valuemin"] = min;
170
+ }
171
+ if (max !== undefined) {
172
+ attributes["aria-valuemax"] = max;
173
+ }
174
+ if (disabled === true) {
175
+ attributes["aria-disabled"] = "true";
176
+ }
177
+ return attributes;
178
+ }
179
+ //# sourceMappingURL=spin-button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spin-button.js","sourceRoot":"","sources":["../../src/spin-button/spin-button.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,cAAc,EACd,KAAK,EACL,aAAa,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,EAAoB,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE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,KAAgC;IAEhC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3D,sBAAsB,CAAC,KAAK,CAAC,CAAC;IAC9B,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;IAC3B,MAAM,UAAU,GAAyB;QACxC,IAAI,EAAE,YAAY;QAClB,eAAe,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;YACnC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;YACnB,CAAC,CAAC,KAAK,CACL,KAAK,EACL,GAAG,IAAI,MAAM,CAAC,iBAAiB,EAC/B,GAAG,IAAI,MAAM,CAAC,iBAAiB,CAC/B;QACH,gBAAgB,EAAE,SAAS;KAC3B,CAAC;IACF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,UAAU,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;IAClC,CAAC;IACD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACvB,UAAU,CAAC,eAAe,CAAC,GAAG,GAAG,CAAC;IACnC,CAAC;IACD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACvB,UAAU,CAAC,eAAe,CAAC,GAAG,GAAG,CAAC;IACnC,CAAC;IACD,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACvB,UAAU,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC;IACtC,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}
@@ -0,0 +1,60 @@
1
+ /** One colour of a swatch strip. */
2
+ export type SwatchStripItem = {
3
+ /** Any CSS colour: `#3b82f6`, `oklch(70% 0.1 200)`. */
4
+ readonly color: string;
5
+ /** Drawn under the swatch: a name, a step, a value. */
6
+ readonly label?: string;
7
+ /**
8
+ * What a screen reader says for the swatch, when the label alone does not say
9
+ * it: `"step 3, OKLab lightness 0.62"`.
10
+ */
11
+ readonly description?: string;
12
+ };
13
+ /** Options of {@link swatchStripGradient}. */
14
+ export type SwatchStripGradientOptions = {
15
+ /**
16
+ * The CSS colour space the browser blends adjacent colours in (`oklab`,
17
+ * `srgb`, `oklch longer hue`). Omitted, the strip has hard stops: every
18
+ * colour gets an equal band and the browser blends nothing, so what is drawn
19
+ * is exactly the colours given.
20
+ */
21
+ interpolation?: string;
22
+ };
23
+ /**
24
+ * The CSS `linear-gradient()` that draws `colors` left to right as one strip:
25
+ * equal bands with hard edges by default, or a smooth blend in the given colour
26
+ * space.
27
+ *
28
+ * Time complexity: O(n). Memory: O(n).
29
+ *
30
+ * @example
31
+ * swatchStripGradient(["red", "blue"]);
32
+ * // "linear-gradient(to right, red 0% 50%, blue 50% 100%)"
33
+ * swatchStripGradient(["red", "blue"], { interpolation: "oklab" });
34
+ * // "linear-gradient(in oklab to right, red 0%, blue 100%)"
35
+ *
36
+ * @throws {RangeError} When `colors` is empty.
37
+ */
38
+ export declare function swatchStripGradient(colors: readonly string[], options?: SwatchStripGradientOptions): string;
39
+ /**
40
+ * What a screen reader says for one swatch: its description, else its label
41
+ * with its colour, else its colour.
42
+ *
43
+ * Time complexity: O(1). Memory: O(1).
44
+ *
45
+ * @example
46
+ * swatchStripItemLabel({ color: "#ff0000", label: "red" }); // "red, #ff0000"
47
+ */
48
+ export declare function swatchStripItemLabel(item: SwatchStripItem): string;
49
+ /**
50
+ * What a screen reader says for a whole strip drawn as one gradient: its name
51
+ * and its colours in order, each with its label.
52
+ *
53
+ * Time complexity: O(n). Memory: O(n).
54
+ *
55
+ * @example
56
+ * swatchStripSummary("Red to blue", [{ color: "red" }, { color: "blue" }]);
57
+ * // "Red to blue: red; blue"
58
+ */
59
+ export declare function swatchStripSummary(label: string, items: readonly SwatchStripItem[]): string;
60
+ //# sourceMappingURL=swatch-strip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swatch-strip.d.ts","sourceRoot":"","sources":["../../src/swatch-strip/swatch-strip.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,MAAM,MAAM,eAAe,GAAG;IAC7B,uDAAuD;IACvD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,8CAA8C;AAC9C,MAAM,MAAM,0BAA0B,GAAG;IACxC;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,GAAE,0BAA+B,GACtC,MAAM,CAsBR;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAKlE;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,SAAS,eAAe,EAAE,GAC/B,MAAM,CAER"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The CSS `linear-gradient()` that draws `colors` left to right as one strip:
3
+ * equal bands with hard edges by default, or a smooth blend in the given colour
4
+ * space.
5
+ *
6
+ * Time complexity: O(n). Memory: O(n).
7
+ *
8
+ * @example
9
+ * swatchStripGradient(["red", "blue"]);
10
+ * // "linear-gradient(to right, red 0% 50%, blue 50% 100%)"
11
+ * swatchStripGradient(["red", "blue"], { interpolation: "oklab" });
12
+ * // "linear-gradient(in oklab to right, red 0%, blue 100%)"
13
+ *
14
+ * @throws {RangeError} When `colors` is empty.
15
+ */
16
+ export function swatchStripGradient(colors, options = {}) {
17
+ const count = colors.length;
18
+ if (count === 0) {
19
+ throw new RangeError("A swatch strip needs at least one colour.");
20
+ }
21
+ const { interpolation } = options;
22
+ const percent = (index, of) => `${Number(((100 * index) / of).toFixed(4))}%`;
23
+ if (interpolation === undefined) {
24
+ const stops = colors.map((color, index) => `${color} ${percent(index, count)} ${percent(index + 1, count)}`);
25
+ return `linear-gradient(to right, ${stops.join(", ")})`;
26
+ }
27
+ const stops = count === 1
28
+ ? [`${colors[0]} 0%`, `${colors[0]} 100%`]
29
+ : colors.map((color, index) => `${color} ${percent(index, count - 1)}`);
30
+ return `linear-gradient(in ${interpolation} to right, ${stops.join(", ")})`;
31
+ }
32
+ /**
33
+ * What a screen reader says for one swatch: its description, else its label
34
+ * with its colour, else its colour.
35
+ *
36
+ * Time complexity: O(1). Memory: O(1).
37
+ *
38
+ * @example
39
+ * swatchStripItemLabel({ color: "#ff0000", label: "red" }); // "red, #ff0000"
40
+ */
41
+ export function swatchStripItemLabel(item) {
42
+ if (item.description !== undefined) {
43
+ return item.description;
44
+ }
45
+ return item.label === undefined ? item.color : `${item.label}, ${item.color}`;
46
+ }
47
+ /**
48
+ * What a screen reader says for a whole strip drawn as one gradient: its name
49
+ * and its colours in order, each with its label.
50
+ *
51
+ * Time complexity: O(n). Memory: O(n).
52
+ *
53
+ * @example
54
+ * swatchStripSummary("Red to blue", [{ color: "red" }, { color: "blue" }]);
55
+ * // "Red to blue: red; blue"
56
+ */
57
+ export function swatchStripSummary(label, items) {
58
+ return `${label}: ${items.map(swatchStripItemLabel).join("; ")}`;
59
+ }
60
+ //# sourceMappingURL=swatch-strip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swatch-strip.js","sourceRoot":"","sources":["../../src/swatch-strip/swatch-strip.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CAClC,MAAyB,EACzB,OAAO,GAA+B,EAAE;IAExC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5B,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,UAAU,CAAC,2CAA2C,CAAC,CAAC;IACnE,CAAC;IACD,MAAM,EAAE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AAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;AAC/E,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAa,EACb,KAAiC;IAEjC,OAAO,GAAG,KAAK,KAAK,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClE,CAAC"}
@@ -0,0 +1,157 @@
1
+ import { type Predicate } from "@ac-kit/core";
2
+ import type { KeyInput } from "@ac-kit/ui-gesture";
3
+ /** Which way a tab list lays out its tabs, and so which arrows move along it. */
4
+ export type TabsOrientation = "horizontal" | "vertical";
5
+ /**
6
+ * When a tab shows its panel: as soon as it takes focus (`automatic`, for
7
+ * panels that show at once), or only once Enter, Space or a click chooses it
8
+ * (`manual`, for panels slow to show).
9
+ */
10
+ export type TabsActivation = "automatic" | "manual";
11
+ /**
12
+ * The attributes of a tab list, keyed by their HTML attribute names.
13
+ * `aria-orientation` is present for `vertical` only, the role's default being
14
+ * horizontal.
15
+ */
16
+ export type TabListAttributes = {
17
+ role: "tablist";
18
+ "aria-label"?: string;
19
+ "aria-labelledby"?: string;
20
+ "aria-orientation"?: "vertical";
21
+ };
22
+ /**
23
+ * Input of {@link tabListAttributes}: its accessible name, given as text or as
24
+ * the id of the element naming it.
25
+ */
26
+ export type TabListAttributesInput = ({
27
+ label: string;
28
+ labelledBy?: undefined;
29
+ } | {
30
+ label?: undefined;
31
+ labelledBy: string;
32
+ }) & {
33
+ /** Defaults to `horizontal`. */
34
+ orientation?: TabsOrientation;
35
+ };
36
+ /**
37
+ * The attributes of a tab list (WAI-ARIA tabs pattern): a named row or column
38
+ * of tabs with one tab stop.
39
+ *
40
+ * Time complexity: O(1). Memory: O(1).
41
+ *
42
+ * @example
43
+ * tabListAttributes({ label: "Settings" });
44
+ * // { role: "tablist", "aria-label": "Settings" }
45
+ */
46
+ export declare function tabListAttributes(input: TabListAttributesInput): TabListAttributes;
47
+ /** The attributes of a tab, keyed by their HTML attribute names. */
48
+ export type TabAttributes = {
49
+ role: "tab";
50
+ "aria-selected": "true" | "false";
51
+ "aria-controls": string;
52
+ tabindex: 0 | -1;
53
+ "aria-disabled"?: "true";
54
+ };
55
+ /** Input of {@link tabAttributes}. */
56
+ export type TabAttributesInput = {
57
+ /** The id of the panel it shows. */
58
+ panelId: string;
59
+ isSelected: boolean;
60
+ /**
61
+ * Whether Tab reaches it: the selected tab, or the first enabled one while
62
+ * none is selected.
63
+ */
64
+ isTabStop: boolean;
65
+ isDisabled?: boolean;
66
+ };
67
+ /**
68
+ * The attributes of a tab: selected or not, the panel it controls, and in the
69
+ * tab order only as the tab list's single stop. A disabled tab stays focusable,
70
+ * as the WAI-ARIA practices advise for the items of a composite widget, so it
71
+ * can be found and read; it is never selected.
72
+ *
73
+ * Time complexity: O(1). Memory: O(1).
74
+ *
75
+ * @example
76
+ * tabAttributes({ panelId: "p", isSelected: true, isTabStop: true });
77
+ * // { role: "tab", "aria-selected": "true", "aria-controls": "p",
78
+ * // tabindex: 0 }
79
+ */
80
+ export declare function tabAttributes(input: TabAttributesInput): TabAttributes;
81
+ /** The attributes of a tab panel, keyed by their HTML attribute names. */
82
+ export type TabPanelAttributes = {
83
+ role: "tabpanel";
84
+ "aria-labelledby": string;
85
+ tabindex?: 0;
86
+ };
87
+ /** Input of {@link tabPanelAttributes}. */
88
+ export type TabPanelAttributesInput = {
89
+ /** The id of the tab naming it. */
90
+ tabId: string;
91
+ /**
92
+ * Whether Tab must reach the panel itself: when nothing inside it takes
93
+ * focus, so its content is reached from its tab.
94
+ */
95
+ isFocusable: boolean;
96
+ };
97
+ /**
98
+ * The attributes of a tab panel: named by its tab, and in the tab order itself
99
+ * when nothing inside it is.
100
+ *
101
+ * Time complexity: O(1). Memory: O(1).
102
+ *
103
+ * @example
104
+ * tabPanelAttributes({ tabId: "t", isFocusable: true });
105
+ * // { role: "tabpanel", "aria-labelledby": "t", tabindex: 0 }
106
+ */
107
+ export declare function tabPanelAttributes(input: TabPanelAttributesInput): TabPanelAttributes;
108
+ /** Input of {@link tabsKeyAction}: the key and the tab list around focus. */
109
+ export type TabsKeyInput = KeyInput & {
110
+ /** The focused tab's index. */
111
+ current: number;
112
+ /** How many tabs the list has. */
113
+ count: number;
114
+ /** Defaults to `horizontal`. */
115
+ orientation?: TabsOrientation;
116
+ /** `rtl` swaps Left and Right. Defaults to `ltr`. */
117
+ direction?: "ltr" | "rtl";
118
+ /** Defaults to `automatic`. */
119
+ activation?: TabsActivation;
120
+ /** Tabs that take focus but are never selected. Defaults to none. */
121
+ isDisabled?: Predicate<[index: number]>;
122
+ /** Whether Delete closes a tab. Defaults to false. */
123
+ isDeletable?: boolean;
124
+ };
125
+ /**
126
+ * What a key does in a tab list (WAI-ARIA tabs pattern):
127
+ *
128
+ * - `focus` a tab: the arrows along the list to the previous or next tab, going
129
+ * round, Home and End to the first and last; `selects` when activation is
130
+ * automatic and the tab is enabled;
131
+ * - `select` the focused tab: Enter or Space, when activation is manual;
132
+ * - `delete` the focused tab: Delete, when tabs are deletable.
133
+ */
134
+ export type TabsKeyAction = {
135
+ readonly kind: "focus";
136
+ readonly index: number;
137
+ readonly selects: boolean;
138
+ } | {
139
+ readonly kind: "select";
140
+ } | {
141
+ readonly kind: "delete";
142
+ };
143
+ /**
144
+ * The action of a key on a focused tab, {@link TabsKeyAction}. `undefined` for a
145
+ * key the list does not use, or with Ctrl, Alt or Meta held (a shortcut).
146
+ *
147
+ * Time complexity: O(count) at worst. Memory: O(1).
148
+ *
149
+ * @example
150
+ * tabsKeyAction({ key: "ArrowRight", current: 2, count: 3 });
151
+ * // { kind: "focus", index: 0, selects: true }
152
+ *
153
+ * @throws {RangeError} When `count` is not a positive safe integer or `current`
154
+ * is outside [0, count).
155
+ */
156
+ export declare function tabsKeyAction(input: TabsKeyInput): TabsKeyAction | undefined;
157
+ //# sourceMappingURL=tabs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tabs.d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AO,CAAC;CACzB,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAE/B;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,aAAa,GAAG,SAAS,CAkD5E"}
@@ -0,0 +1,120 @@
1
+ import { describeValue, isIntegerInRange } from "@ac-kit/core";
2
+ import { rovingFocusIndex } from "../focus/roving-focus.js";
3
+ /**
4
+ * The attributes of a tab list (WAI-ARIA tabs pattern): a named row or column
5
+ * of tabs with one tab stop.
6
+ *
7
+ * Time complexity: O(1). Memory: O(1).
8
+ *
9
+ * @example
10
+ * tabListAttributes({ label: "Settings" });
11
+ * // { role: "tablist", "aria-label": "Settings" }
12
+ */
13
+ export function tabListAttributes(input) {
14
+ const { label, labelledBy, orientation = "horizontal" } = input;
15
+ const attributes = { role: "tablist" };
16
+ if (label !== undefined) {
17
+ attributes["aria-label"] = label;
18
+ }
19
+ if (labelledBy !== undefined) {
20
+ attributes["aria-labelledby"] = labelledBy;
21
+ }
22
+ if (orientation === "vertical") {
23
+ attributes["aria-orientation"] = "vertical";
24
+ }
25
+ return attributes;
26
+ }
27
+ /**
28
+ * The attributes of a tab: selected or not, the panel it controls, and in the
29
+ * tab order only as the tab list's single stop. A disabled tab stays focusable,
30
+ * as the WAI-ARIA practices advise for the items of a composite widget, so it
31
+ * can be found and read; it is never selected.
32
+ *
33
+ * Time complexity: O(1). Memory: O(1).
34
+ *
35
+ * @example
36
+ * tabAttributes({ panelId: "p", isSelected: true, isTabStop: true });
37
+ * // { role: "tab", "aria-selected": "true", "aria-controls": "p",
38
+ * // tabindex: 0 }
39
+ */
40
+ export function tabAttributes(input) {
41
+ const attributes = {
42
+ role: "tab",
43
+ "aria-selected": input.isSelected ? "true" : "false",
44
+ "aria-controls": input.panelId,
45
+ tabindex: input.isTabStop ? 0 : -1,
46
+ };
47
+ if (input.isDisabled === true) {
48
+ attributes["aria-disabled"] = "true";
49
+ }
50
+ return attributes;
51
+ }
52
+ /**
53
+ * The attributes of a tab panel: named by its tab, and in the tab order itself
54
+ * when nothing inside it is.
55
+ *
56
+ * Time complexity: O(1). Memory: O(1).
57
+ *
58
+ * @example
59
+ * tabPanelAttributes({ tabId: "t", isFocusable: true });
60
+ * // { role: "tabpanel", "aria-labelledby": "t", tabindex: 0 }
61
+ */
62
+ export function tabPanelAttributes(input) {
63
+ const attributes = {
64
+ role: "tabpanel",
65
+ "aria-labelledby": input.tabId,
66
+ };
67
+ if (input.isFocusable) {
68
+ attributes.tabindex = 0;
69
+ }
70
+ return attributes;
71
+ }
72
+ /**
73
+ * The action of a key on a focused tab, {@link TabsKeyAction}. `undefined` for a
74
+ * key the list does not use, or with Ctrl, Alt or Meta held (a shortcut).
75
+ *
76
+ * Time complexity: O(count) at worst. Memory: O(1).
77
+ *
78
+ * @example
79
+ * tabsKeyAction({ key: "ArrowRight", current: 2, count: 3 });
80
+ * // { kind: "focus", index: 0, selects: true }
81
+ *
82
+ * @throws {RangeError} When `count` is not a positive safe integer or `current`
83
+ * is outside [0, count).
84
+ */
85
+ export function tabsKeyAction(input) {
86
+ const { key, current, count, orientation = "horizontal", direction = "ltr", activation = "automatic", isDisabled, isDeletable = false, } = input;
87
+ if (!isIntegerInRange(count, 1, Number.MAX_SAFE_INTEGER + 1)) {
88
+ throw new RangeError(`count must be a positive safe integer, got ${describeValue(count)}`);
89
+ }
90
+ if (!isIntegerInRange(current, 0, count)) {
91
+ throw new RangeError(`current must be an integer in [0, ${String(count)}), got ${describeValue(current)}`);
92
+ }
93
+ if (input.ctrlKey === true ||
94
+ input.altKey === true ||
95
+ input.metaKey === true) {
96
+ return undefined;
97
+ }
98
+ switch (key) {
99
+ case "Enter":
100
+ case " ":
101
+ return activation === "manual" ? { kind: "select" } : undefined;
102
+ case "Delete":
103
+ return isDeletable ? { kind: "delete" } : undefined;
104
+ default: {
105
+ const index = rovingFocusIndex(current, key, count, {
106
+ orientation,
107
+ direction,
108
+ });
109
+ if (index === undefined) {
110
+ return undefined;
111
+ }
112
+ return {
113
+ kind: "focus",
114
+ index,
115
+ selects: activation === "automatic" && isDisabled?.(index) !== true,
116
+ };
117
+ }
118
+ }
119
+ }
120
+ //# sourceMappingURL=tabs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tabs.js","sourceRoot":"","sources":["../../src/tabs/tabs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAkB,MAAM,cAAc,CAAC;AAG/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAoC5D;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAChC,KAA6B;IAE7B,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC;IAChE,MAAM,UAAU,GAAsB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAC1D,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,UAAU,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;IAClC,CAAC;IACD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC9B,UAAU,CAAC,iBAAiB,CAAC,GAAG,UAAU,CAAC;IAC5C,CAAC;IACD,IAAI,WAAW,KAAK,UAAU,EAAE,CAAC;QAChC,UAAU,CAAC,kBAAkB,CAAC,GAAG,UAAU,CAAC;IAC7C,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC;AAwBD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,KAAyB;IACtD,MAAM,UAAU,GAAkB;QACjC,IAAI,EAAE,KAAK;QACX,eAAe,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;QACpD,eAAe,EAAE,KAAK,CAAC,OAAO;QAC9B,QAAQ,EAAE,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