@ac-kit/ui-common 0.0.0-stage → 0.2.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 (205) hide show
  1. package/CHANGELOG.md +244 -0
  2. package/LICENSE +28 -0
  3. package/README.md +633 -2
  4. package/dist/anchored/anchored.d.ts +19 -0
  5. package/dist/anchored/anchored.d.ts.map +1 -0
  6. package/dist/anchored/anchored.js +2 -0
  7. package/dist/anchored/anchored.js.map +1 -0
  8. package/dist/button/button.d.ts +35 -0
  9. package/dist/button/button.d.ts.map +1 -0
  10. package/dist/button/button.js +22 -0
  11. package/dist/button/button.js.map +1 -0
  12. package/dist/dialog/dialog.d.ts +33 -0
  13. package/dist/dialog/dialog.d.ts.map +1 -0
  14. package/dist/dialog/dialog.js +23 -0
  15. package/dist/dialog/dialog.js.map +1 -0
  16. package/dist/focus/owns-arrow-keys.d.ts +31 -0
  17. package/dist/focus/owns-arrow-keys.d.ts.map +1 -0
  18. package/dist/focus/owns-arrow-keys.js +64 -0
  19. package/dist/focus/owns-arrow-keys.js.map +1 -0
  20. package/dist/focus/roving-focus.d.ts +34 -0
  21. package/dist/focus/roving-focus.d.ts.map +1 -0
  22. package/dist/focus/roving-focus.js +72 -0
  23. package/dist/focus/roving-focus.js.map +1 -0
  24. package/dist/focus/typeahead.d.ts +112 -0
  25. package/dist/focus/typeahead.d.ts.map +1 -0
  26. package/dist/focus/typeahead.js +178 -0
  27. package/dist/focus/typeahead.js.map +1 -0
  28. package/dist/index.d.ts +26 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +26 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/knob/knob.d.ts +106 -0
  33. package/dist/knob/knob.d.ts.map +1 -0
  34. package/dist/knob/knob.js +116 -0
  35. package/dist/knob/knob.js.map +1 -0
  36. package/dist/menu/menu.d.ts +157 -0
  37. package/dist/menu/menu.d.ts.map +1 -0
  38. package/dist/menu/menu.js +162 -0
  39. package/dist/menu/menu.js.map +1 -0
  40. package/dist/meter/meter.d.ts +63 -0
  41. package/dist/meter/meter.d.ts.map +1 -0
  42. package/dist/meter/meter.js +57 -0
  43. package/dist/meter/meter.js.map +1 -0
  44. package/dist/preact/_anchor.d.ts +13 -0
  45. package/dist/preact/_anchor.d.ts.map +1 -0
  46. package/dist/preact/_anchor.js +39 -0
  47. package/dist/preact/_anchor.js.map +1 -0
  48. package/dist/preact/_dom.d.ts +14 -0
  49. package/dist/preact/_dom.d.ts.map +1 -0
  50. package/dist/preact/_dom.js +31 -0
  51. package/dist/preact/_dom.js.map +1 -0
  52. package/dist/preact/_live-announcer.d.ts +26 -0
  53. package/dist/preact/_live-announcer.d.ts.map +1 -0
  54. package/dist/preact/_live-announcer.js +101 -0
  55. package/dist/preact/_live-announcer.js.map +1 -0
  56. package/dist/preact/button.d.ts +40 -0
  57. package/dist/preact/button.d.ts.map +1 -0
  58. package/dist/preact/button.js +22 -0
  59. package/dist/preact/button.js.map +1 -0
  60. package/dist/preact/dialog.d.ts +43 -0
  61. package/dist/preact/dialog.d.ts.map +1 -0
  62. package/dist/preact/dialog.js +89 -0
  63. package/dist/preact/dialog.js.map +1 -0
  64. package/dist/preact/index.d.ts +20 -0
  65. package/dist/preact/index.d.ts.map +1 -0
  66. package/dist/preact/index.js +20 -0
  67. package/dist/preact/index.js.map +1 -0
  68. package/dist/preact/join-classes.d.ts +10 -0
  69. package/dist/preact/join-classes.d.ts.map +1 -0
  70. package/dist/preact/join-classes.js +12 -0
  71. package/dist/preact/join-classes.js.map +1 -0
  72. package/dist/preact/knob.d.ts +51 -0
  73. package/dist/preact/knob.d.ts.map +1 -0
  74. package/dist/preact/knob.js +144 -0
  75. package/dist/preact/knob.js.map +1 -0
  76. package/dist/preact/menu-button.d.ts +117 -0
  77. package/dist/preact/menu-button.d.ts.map +1 -0
  78. package/dist/preact/menu-button.js +330 -0
  79. package/dist/preact/menu-button.js.map +1 -0
  80. package/dist/preact/meter.d.ts +34 -0
  81. package/dist/preact/meter.d.ts.map +1 -0
  82. package/dist/preact/meter.js +21 -0
  83. package/dist/preact/meter.js.map +1 -0
  84. package/dist/preact/progress-ring.d.ts +42 -0
  85. package/dist/preact/progress-ring.d.ts.map +1 -0
  86. package/dist/preact/progress-ring.js +26 -0
  87. package/dist/preact/progress-ring.js.map +1 -0
  88. package/dist/preact/radio-group.d.ts +50 -0
  89. package/dist/preact/radio-group.d.ts.map +1 -0
  90. package/dist/preact/radio-group.js +42 -0
  91. package/dist/preact/radio-group.js.map +1 -0
  92. package/dist/preact/readout.d.ts +22 -0
  93. package/dist/preact/readout.d.ts.map +1 -0
  94. package/dist/preact/readout.js +13 -0
  95. package/dist/preact/readout.js.map +1 -0
  96. package/dist/preact/slider.d.ts +40 -0
  97. package/dist/preact/slider.d.ts.map +1 -0
  98. package/dist/preact/slider.js +164 -0
  99. package/dist/preact/slider.js.map +1 -0
  100. package/dist/preact/spin-button.d.ts +67 -0
  101. package/dist/preact/spin-button.d.ts.map +1 -0
  102. package/dist/preact/spin-button.js +132 -0
  103. package/dist/preact/spin-button.js.map +1 -0
  104. package/dist/preact/switch.d.ts +25 -0
  105. package/dist/preact/switch.d.ts.map +1 -0
  106. package/dist/preact/switch.js +19 -0
  107. package/dist/preact/switch.js.map +1 -0
  108. package/dist/preact/tabs.d.ts +97 -0
  109. package/dist/preact/tabs.d.ts.map +1 -0
  110. package/dist/preact/tabs.js +264 -0
  111. package/dist/preact/tabs.js.map +1 -0
  112. package/dist/preact/toaster.d.ts +43 -0
  113. package/dist/preact/toaster.d.ts.map +1 -0
  114. package/dist/preact/toaster.js +356 -0
  115. package/dist/preact/toaster.js.map +1 -0
  116. package/dist/preact/toggle-button.d.ts +26 -0
  117. package/dist/preact/toggle-button.d.ts.map +1 -0
  118. package/dist/preact/toggle-button.js +16 -0
  119. package/dist/preact/toggle-button.js.map +1 -0
  120. package/dist/preact/toolbar.d.ts +24 -0
  121. package/dist/preact/toolbar.d.ts.map +1 -0
  122. package/dist/preact/toolbar.js +142 -0
  123. package/dist/preact/toolbar.js.map +1 -0
  124. package/dist/preact/tooltip.d.ts +67 -0
  125. package/dist/preact/tooltip.d.ts.map +1 -0
  126. package/dist/preact/tooltip.js +165 -0
  127. package/dist/preact/tooltip.js.map +1 -0
  128. package/dist/preact/tree.d.ts +93 -0
  129. package/dist/preact/tree.d.ts.map +1 -0
  130. package/dist/preact/tree.js +399 -0
  131. package/dist/preact/tree.js.map +1 -0
  132. package/dist/preact/use-element-binding.d.ts +32 -0
  133. package/dist/preact/use-element-binding.d.ts.map +1 -0
  134. package/dist/preact/use-element-binding.js +51 -0
  135. package/dist/preact/use-element-binding.js.map +1 -0
  136. package/dist/progress/progress.d.ts +51 -0
  137. package/dist/progress/progress.d.ts.map +1 -0
  138. package/dist/progress/progress.js +43 -0
  139. package/dist/progress/progress.js.map +1 -0
  140. package/dist/readout/readout.d.ts +41 -0
  141. package/dist/readout/readout.d.ts.map +1 -0
  142. package/dist/readout/readout.js +26 -0
  143. package/dist/readout/readout.js.map +1 -0
  144. package/dist/slider/_clamped-value.d.ts +7 -0
  145. package/dist/slider/_clamped-value.d.ts.map +1 -0
  146. package/dist/slider/_clamped-value.js +9 -0
  147. package/dist/slider/_clamped-value.js.map +1 -0
  148. package/dist/slider/slider-attributes.d.ts +50 -0
  149. package/dist/slider/slider-attributes.d.ts.map +1 -0
  150. package/dist/slider/slider-attributes.js +38 -0
  151. package/dist/slider/slider-attributes.js.map +1 -0
  152. package/dist/slider/slider-range.d.ts +59 -0
  153. package/dist/slider/slider-range.d.ts.map +1 -0
  154. package/dist/slider/slider-range.js +73 -0
  155. package/dist/slider/slider-range.js.map +1 -0
  156. package/dist/slider/slider-track.d.ts +37 -0
  157. package/dist/slider/slider-track.d.ts.map +1 -0
  158. package/dist/slider/slider-track.js +35 -0
  159. package/dist/slider/slider-track.js.map +1 -0
  160. package/dist/slider/stepped-value.d.ts +31 -0
  161. package/dist/slider/stepped-value.d.ts.map +1 -0
  162. package/dist/slider/stepped-value.js +55 -0
  163. package/dist/slider/stepped-value.js.map +1 -0
  164. package/dist/spin-button/spin-button.d.ts +110 -0
  165. package/dist/spin-button/spin-button.d.ts.map +1 -0
  166. package/dist/spin-button/spin-button.js +179 -0
  167. package/dist/spin-button/spin-button.js.map +1 -0
  168. package/dist/switch/switch.d.ts +30 -0
  169. package/dist/switch/switch.d.ts.map +1 -0
  170. package/dist/switch/switch.js +26 -0
  171. package/dist/switch/switch.js.map +1 -0
  172. package/dist/tabs/tabs.d.ts +157 -0
  173. package/dist/tabs/tabs.d.ts.map +1 -0
  174. package/dist/tabs/tabs.js +120 -0
  175. package/dist/tabs/tabs.js.map +1 -0
  176. package/dist/toast/toast-queue.d.ts +212 -0
  177. package/dist/toast/toast-queue.d.ts.map +1 -0
  178. package/dist/toast/toast-queue.js +290 -0
  179. package/dist/toast/toast-queue.js.map +1 -0
  180. package/dist/toast/toasts-obscure.d.ts +25 -0
  181. package/dist/toast/toasts-obscure.d.ts.map +1 -0
  182. package/dist/toast/toasts-obscure.js +30 -0
  183. package/dist/toast/toasts-obscure.js.map +1 -0
  184. package/dist/toggle-button/toggle-button.d.ts +44 -0
  185. package/dist/toggle-button/toggle-button.d.ts.map +1 -0
  186. package/dist/toggle-button/toggle-button.js +31 -0
  187. package/dist/toggle-button/toggle-button.js.map +1 -0
  188. package/dist/tone.d.ts +8 -0
  189. package/dist/tone.d.ts.map +1 -0
  190. package/dist/tone.js +2 -0
  191. package/dist/tone.js.map +1 -0
  192. package/dist/toolbar/toolbar.d.ts +35 -0
  193. package/dist/toolbar/toolbar.d.ts.map +1 -0
  194. package/dist/toolbar/toolbar.js +23 -0
  195. package/dist/toolbar/toolbar.js.map +1 -0
  196. package/dist/tooltip/tooltip.d.ts +183 -0
  197. package/dist/tooltip/tooltip.d.ts.map +1 -0
  198. package/dist/tooltip/tooltip.js +185 -0
  199. package/dist/tooltip/tooltip.js.map +1 -0
  200. package/dist/tree/tree.d.ts +302 -0
  201. package/dist/tree/tree.d.ts.map +1 -0
  202. package/dist/tree/tree.js +439 -0
  203. package/dist/tree/tree.js.map +1 -0
  204. package/package.json +110 -3
  205. package/styles.css +1883 -0
@@ -0,0 +1,162 @@
1
+ import { describeValue, isIntegerInRange } from "@ac-kit/core";
2
+ import { rovingFocusIndex } from "../focus/roving-focus.js";
3
+ import { typeaheadCharacter } from "../focus/typeahead.js";
4
+ /**
5
+ * The attributes of the button that opens a menu (WAI-ARIA menu button
6
+ * pattern): it has a menu popup, says whether it is open, and which element the
7
+ * menu is.
8
+ *
9
+ * Time complexity: O(1). Memory: O(1).
10
+ *
11
+ * @example
12
+ * menuButtonAttributes({ menuId: "m", isOpen: false });
13
+ * // { "aria-haspopup": "menu", "aria-expanded": "false", "aria-controls": "m" }
14
+ */
15
+ export function menuButtonAttributes(input) {
16
+ return {
17
+ "aria-haspopup": "menu",
18
+ "aria-expanded": input.isOpen ? "true" : "false",
19
+ "aria-controls": input.menuId,
20
+ };
21
+ }
22
+ /**
23
+ * The attributes of a menu (WAI-ARIA menu pattern): named by its button,
24
+ * focusable itself only as a fallback (its items take focus), and placed
25
+ * against the button by the stylesheet.
26
+ *
27
+ * Time complexity: O(1). Memory: O(1).
28
+ *
29
+ * @example
30
+ * menuAttributes({ labelledBy: "b" });
31
+ * // { role: "menu", "aria-labelledby": "b", tabindex: -1,
32
+ * // "data-side": "block-end", "data-align": "start" }
33
+ */
34
+ export function menuAttributes(input) {
35
+ const { labelledBy, side = "block-end", align = "start" } = input;
36
+ return {
37
+ role: "menu",
38
+ "aria-labelledby": labelledBy,
39
+ tabindex: -1,
40
+ "data-side": side,
41
+ "data-align": align,
42
+ };
43
+ }
44
+ const ITEM_ROLES_ = {
45
+ item: "menuitem",
46
+ checkbox: "menuitemcheckbox",
47
+ radio: "menuitemradio",
48
+ };
49
+ /**
50
+ * The attributes of a menu item: its role by kind, its checked state for a
51
+ * checkbox or radio item, out of the tab order (the menu moves focus to it). A
52
+ * disabled item stays focusable, as the WAI-ARIA practices advise, so it can be
53
+ * found and read; it is not activated.
54
+ *
55
+ * Time complexity: O(1). Memory: O(1).
56
+ *
57
+ * @example
58
+ * menuItemAttributes({ kind: "checkbox", isChecked: true });
59
+ * // { role: "menuitemcheckbox", tabindex: -1, "aria-checked": "true",
60
+ * // "data-kind": "checkbox" }
61
+ */
62
+ export function menuItemAttributes(input) {
63
+ const attributes = {
64
+ role: ITEM_ROLES_[input.kind],
65
+ tabindex: -1,
66
+ "data-kind": input.kind,
67
+ };
68
+ if (input.kind !== "item") {
69
+ attributes["aria-checked"] = input.isChecked ? "true" : "false";
70
+ }
71
+ if (input.isDisabled === true) {
72
+ attributes["aria-disabled"] = "true";
73
+ }
74
+ return attributes;
75
+ }
76
+ function hasShortcutModifier_(input) {
77
+ return (input.ctrlKey === true || input.altKey === true || input.metaKey === true);
78
+ }
79
+ /**
80
+ * The item a key on a menu button opens its menu on (WAI-ARIA menu button
81
+ * pattern): Enter, Space and Arrow Down the first, Arrow Up the last.
82
+ * `undefined` for another key, or with Ctrl, Alt or Meta held.
83
+ *
84
+ * Time complexity: O(1). Memory: O(1).
85
+ *
86
+ * @example
87
+ * menuButtonKeyAction({ key: "ArrowUp" }); // "last"
88
+ */
89
+ export function menuButtonKeyAction(input) {
90
+ if (hasShortcutModifier_(input)) {
91
+ return undefined;
92
+ }
93
+ switch (input.key) {
94
+ case "Enter":
95
+ case " ":
96
+ case "ArrowDown":
97
+ return "first";
98
+ case "ArrowUp":
99
+ return "last";
100
+ default:
101
+ return undefined;
102
+ }
103
+ }
104
+ /**
105
+ * The action of a key in an open menu, {@link MenuKeyAction}. `undefined` for a
106
+ * key the menu does not use, or with Ctrl, Alt or Meta held (a shortcut).
107
+ * Disabled items take focus like the others, so the caller checks them before
108
+ * activating one.
109
+ *
110
+ * Time complexity: O(count) at worst. Memory: O(1).
111
+ *
112
+ * @example
113
+ * menuKeyAction({ key: "ArrowDown", current: 2, count: 3, itemKind: "item",
114
+ * isTypingAhead: false }); // { kind: "focus", index: 0 }
115
+ *
116
+ * @throws {RangeError} When `count` is not a non-negative safe integer or
117
+ * `current` is outside [0, count).
118
+ */
119
+ export function menuKeyAction(input) {
120
+ const { key, current, count, itemKind, isTypingAhead } = input;
121
+ if (!isIntegerInRange(count, 0, Number.MAX_SAFE_INTEGER + 1)) {
122
+ throw new RangeError(`count must be a non-negative safe integer, got ${describeValue(count)}`);
123
+ }
124
+ if (current !== undefined && !isIntegerInRange(current, 0, count)) {
125
+ throw new RangeError(`current must be an integer in [0, ${String(count)}), got ${describeValue(current)}`);
126
+ }
127
+ if (hasShortcutModifier_(input)) {
128
+ return undefined;
129
+ }
130
+ switch (key) {
131
+ case "ArrowDown":
132
+ case "ArrowUp":
133
+ case "Home":
134
+ case "End": {
135
+ if (count === 0) {
136
+ return undefined;
137
+ }
138
+ const index = current === undefined
139
+ ? rovingFocusIndex(0, key === "ArrowUp" || key === "End" ? "End" : "Home", count)
140
+ : rovingFocusIndex(current, key, count, { orientation: "vertical" });
141
+ return index === undefined ? undefined : { kind: "focus", index };
142
+ }
143
+ case "Escape":
144
+ return { kind: "close" };
145
+ case "Tab":
146
+ return { kind: "leave" };
147
+ case "Enter":
148
+ return itemKind === undefined
149
+ ? undefined
150
+ : { kind: "activate", keepsOpen: false };
151
+ default: {
152
+ const character = typeaheadCharacter(input, isTypingAhead);
153
+ if (character !== undefined) {
154
+ return { kind: "typeahead", character };
155
+ }
156
+ return key === " " && itemKind !== undefined
157
+ ? { kind: "activate", keepsOpen: itemKind !== "item" }
158
+ : undefined;
159
+ }
160
+ }
161
+ }
162
+ //# sourceMappingURL=menu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"menu.js","sourceRoot":"","sources":["../../src/menu/menu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAQ/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM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AAE,SAAS,EAAE,QAAQ,KAAK,MAAM,EAAE;gBACtD,CAAC,CAAC,SAAS,CAAC;QACd,CAAC;IACF,CAAC;AACF,CAAC"}
@@ -0,0 +1,63 @@
1
+ import type { ControlTone } from "../tone.js";
2
+ /** One segment of a segmented level meter. */
3
+ export type MeterSegment = {
4
+ /** The level at or above which the segment lights. */
5
+ readonly threshold: number;
6
+ /** Its colour role. */
7
+ readonly tone: ControlTone;
8
+ };
9
+ /**
10
+ * How many segments of a meter a level lights, counted from the bottom: the
11
+ * segments whose threshold is at or below `level`. `segments` runs bottom to
12
+ * top, thresholds ascending. `-Infinity` and `NaN` light none.
13
+ *
14
+ * Time complexity: O(log n) in `segments.length`. Memory: O(1).
15
+ *
16
+ * @example
17
+ * const segments = [
18
+ * { threshold: 0, tone: "positive" },
19
+ * { threshold: 0.5, tone: "warning" },
20
+ * { threshold: 0.9, tone: "negative" },
21
+ * ];
22
+ * meterLitCount(0.6, segments); // 2
23
+ * meterLitCount(-1, segments); // 0
24
+ */
25
+ export declare function meterLitCount(level: number, segments: readonly MeterSegment[]): number;
26
+ /** The ARIA attributes of a meter (WAI-ARIA 1.2 `meter` role). */
27
+ export type MeterAttributes = {
28
+ role: "meter";
29
+ "aria-label"?: string;
30
+ "aria-valuemin": number;
31
+ "aria-valuemax": number;
32
+ "aria-valuenow": number;
33
+ "aria-valuetext"?: string;
34
+ };
35
+ /** Input of {@link meterAttributes}. */
36
+ export type MeterAttributesInput = {
37
+ label?: string;
38
+ /**
39
+ * Clamped to [min, max] for `aria-valuenow`, as the role requires; `NaN`
40
+ * reads as `min`.
41
+ */
42
+ value: number;
43
+ min: number;
44
+ max: number;
45
+ valueText?: string;
46
+ };
47
+ /**
48
+ * The attributes of a read-only level meter: the `meter` role with its range,
49
+ * its current value kept inside the range, and an optional text for what a
50
+ * person reads (`"-12 dB"`).
51
+ *
52
+ * Time complexity: O(1). Memory: O(1).
53
+ *
54
+ * @example
55
+ * meterAttributes({ label: "Input", value: 3, min: 0, max: 2 });
56
+ * // { role: "meter", "aria-label": "Input", "aria-valuemin": 0,
57
+ * // "aria-valuemax": 2, "aria-valuenow": 2 }
58
+ *
59
+ * @throws {RangeError} When `min` or `max` is not finite (a fraction cannot be
60
+ * drawn from an infinite range), or `max` is not above `min`.
61
+ */
62
+ export declare function meterAttributes(input: MeterAttributesInput): MeterAttributes;
63
+ //# sourceMappingURL=meter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meter.d.ts","sourceRoot":"","sources":["../../src/meter/meter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,8CAA8C;AAC9C,MAAM,MAAM,YAAY,GAAG;IAC1B,sDAAsD;IACtD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,uBAAuB;IACvB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,SAAS,YAAY,EAAE,GAC/B,MAAM,CAOR;AAED,kEAAkE;AAClE,MAAM,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,wCAAwC;AACxC,MAAM,MAAM,oBAAoB,GAAG;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,eAAe,CAqB5E"}
@@ -0,0 +1,57 @@
1
+ import { bisectRight } from "@ac-kit/algo";
2
+ import { clamp, describeValue } from "@ac-kit/core";
3
+ /**
4
+ * How many segments of a meter a level lights, counted from the bottom: the
5
+ * segments whose threshold is at or below `level`. `segments` runs bottom to
6
+ * top, thresholds ascending. `-Infinity` and `NaN` light none.
7
+ *
8
+ * Time complexity: O(log n) in `segments.length`. Memory: O(1).
9
+ *
10
+ * @example
11
+ * const segments = [
12
+ * { threshold: 0, tone: "positive" },
13
+ * { threshold: 0.5, tone: "warning" },
14
+ * { threshold: 0.9, tone: "negative" },
15
+ * ];
16
+ * meterLitCount(0.6, segments); // 2
17
+ * meterLitCount(-1, segments); // 0
18
+ */
19
+ export function meterLitCount(level, segments) {
20
+ // `NaN` compares false against every threshold, and so lights none.
21
+ return bisectRight(segments, level, (segment, value) => segment.threshold - value);
22
+ }
23
+ /**
24
+ * The attributes of a read-only level meter: the `meter` role with its range,
25
+ * its current value kept inside the range, and an optional text for what a
26
+ * person reads (`"-12 dB"`).
27
+ *
28
+ * Time complexity: O(1). Memory: O(1).
29
+ *
30
+ * @example
31
+ * meterAttributes({ label: "Input", value: 3, min: 0, max: 2 });
32
+ * // { role: "meter", "aria-label": "Input", "aria-valuemin": 0,
33
+ * // "aria-valuemax": 2, "aria-valuenow": 2 }
34
+ *
35
+ * @throws {RangeError} When `min` or `max` is not finite (a fraction cannot be
36
+ * drawn from an infinite range), or `max` is not above `min`.
37
+ */
38
+ export function meterAttributes(input) {
39
+ const { label, value, min, max, valueText } = input;
40
+ if (!(Number.isFinite(min) && Number.isFinite(max) && max > min)) {
41
+ throw new RangeError(`A meter's bounds must be finite with max above min, got min ${describeValue(min)} and max ${describeValue(max)}.`);
42
+ }
43
+ const attributes = {
44
+ role: "meter",
45
+ "aria-valuemin": min,
46
+ "aria-valuemax": max,
47
+ "aria-valuenow": Number.isNaN(value) ? min : clamp(value, min, max),
48
+ };
49
+ if (label !== undefined) {
50
+ attributes["aria-label"] = label;
51
+ }
52
+ if (valueText !== undefined) {
53
+ attributes["aria-valuetext"] = valueText;
54
+ }
55
+ return attributes;
56
+ }
57
+ //# sourceMappingURL=meter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meter.js","sourceRoot":"","sources":["../../src/meter/meter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAYpD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,aAAa,CAC5B,KAAa,EACb,QAAiC;IAEjC,oEAAoE;IACpE,OAAO,WAAW,CACjB,QAAQ,EACR,KAAK,EACL,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAC7C,CAAC;AACH,CAAC;AAyBD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,eAAe,CAAC,KAA2B;IAC1D,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IACpD,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC;QAClE,MAAM,IAAI,UAAU,CACnB,+DAA+D,aAAa,CAAC,GAAG,CAAC,YAAY,aAAa,CAAC,GAAG,CAAC,GAAG,CAClH,CAAC;IACH,CAAC;IACD,MAAM,UAAU,GAAoB;QACnC,IAAI,EAAE,OAAO;QACb,eAAe,EAAE,GAAG;QACpB,eAAe,EAAE,GAAG;QACpB,eAAe,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC;KACnE,CAAC;IACF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,UAAU,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;IAClC,CAAC;IACD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7B,UAAU,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAC;IAC1C,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The anchor name of the popover with this id: a dashed ident unique to it, so
3
+ * a trigger can anchor several popovers (a menu and a tooltip) and one page
4
+ * many triggers.
5
+ */
6
+ export declare function anchorNameOf_(popoverId: string): string;
7
+ /**
8
+ * Adds `name` to the element's inline `anchor-name` list, keeping the names
9
+ * already there, until the returned handle is disposed. A browser without
10
+ * anchor positioning ignores the property.
11
+ */
12
+ export declare function addAnchorName_(element: HTMLElement, name: string): Disposable;
13
+ //# sourceMappingURL=_anchor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_anchor.d.ts","sourceRoot":"","sources":["../../src/preact/_anchor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEvD;AAkBD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAc7E"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The anchor name of the popover with this id: a dashed ident unique to it, so
3
+ * a trigger can anchor several popovers (a menu and a tooltip) and one page
4
+ * many triggers.
5
+ */
6
+ export function anchorNameOf_(popoverId) {
7
+ return `--ack-anchor-${CSS.escape(popoverId)}`;
8
+ }
9
+ function anchorNames_(element) {
10
+ const value = element.style.getPropertyValue("anchor-name").trim();
11
+ return value === "" || value === "none"
12
+ ? []
13
+ : value.split(",").map((name) => name.trim());
14
+ }
15
+ function setAnchorNames_(element, names) {
16
+ if (names.length === 0) {
17
+ element.style.removeProperty("anchor-name");
18
+ }
19
+ else {
20
+ element.style.setProperty("anchor-name", names.join(", "));
21
+ }
22
+ }
23
+ /**
24
+ * Adds `name` to the element's inline `anchor-name` list, keeping the names
25
+ * already there, until the returned handle is disposed. A browser without
26
+ * anchor positioning ignores the property.
27
+ */
28
+ export function addAnchorName_(element, name) {
29
+ const names = anchorNames_(element);
30
+ if (!names.includes(name)) {
31
+ setAnchorNames_(element, [...names, name]);
32
+ }
33
+ return {
34
+ [Symbol.dispose]() {
35
+ setAnchorNames_(element, anchorNames_(element).filter((candidate) => candidate !== name));
36
+ },
37
+ };
38
+ }
39
+ //# sourceMappingURL=_anchor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_anchor.js","sourceRoot":"","sources":["../../src/preact/_anchor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,SAAiB;IAC9C,OAAO,gBAAgB,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;AAChD,CAAC;AAED,SAAS,YAAY,CAAC,OAAoB;IACzC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,CAAC;IAEnE,OAAO,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,MAAM;QACtC,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,eAAe,CAAC,OAAoB,EAAE,KAAwB;IACtE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IAC7C,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5D,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAoB,EAAE,IAAY;IAChE,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,eAAe,CAAC,OAAO,EAAE,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO;QACN,CAAC,MAAM,CAAC,OAAO,CAAC;YACf,eAAe,CACd,OAAO,EACP,YAAY,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,IAAI,CAAC,CAC/D,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ /** The elements that may take focus, before the checks of {@link isFocusable_}. */
2
+ export declare const FOCUSABLE_SELECTOR_ = "button, a[href], input:not([type=\"hidden\"]), select, textarea, [tabindex], [contenteditable]:not([contenteditable=\"false\"])";
3
+ /** Whether an element matching {@link FOCUSABLE_SELECTOR_} can take focus now. */
4
+ export declare function isFocusable_(element: HTMLElement): boolean;
5
+ /** Whether Tab reaches an element inside `container`. */
6
+ export declare function hasTabbable_(container: HTMLElement): boolean;
7
+ /** The reading direction an element is laid out in. */
8
+ export declare function directionOf_(element: Element): "ltr" | "rtl";
9
+ /**
10
+ * The language of an element's text, from the closest `lang` attribute; for the
11
+ * collation typeahead compares names with. `undefined` for the runtime's.
12
+ */
13
+ export declare function localesOf_(element: Element): string | undefined;
14
+ //# sourceMappingURL=_dom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dom.d.ts","sourceRoot":"","sources":["../../src/preact/_dom.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,eAAO,MAAM,mBAAmB,oIAC8F,CAAC;AAE/H,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAO1D;AAED,yDAAyD;AACzD,wBAAgB,YAAY,CAAC,SAAS,EAAE,WAAW,GAAG,OAAO,CAU5D;AAED,uDAAuD;AACvD,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,KAAK,GAAG,KAAK,CAE5D;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAI/D"}
@@ -0,0 +1,31 @@
1
+ /** The elements that may take focus, before the checks of {@link isFocusable_}. */
2
+ export const FOCUSABLE_SELECTOR_ = 'button, a[href], input:not([type="hidden"]), select, textarea, [tabindex], [contenteditable]:not([contenteditable="false"])';
3
+ /** Whether an element matching {@link FOCUSABLE_SELECTOR_} can take focus now. */
4
+ export function isFocusable_(element) {
5
+ return (!element.matches(":disabled") &&
6
+ element.getAttribute("aria-disabled") !== "true" &&
7
+ element.closest("[inert]") === null &&
8
+ element.checkVisibility({ visibilityProperty: true }));
9
+ }
10
+ /** Whether Tab reaches an element inside `container`. */
11
+ export function hasTabbable_(container) {
12
+ for (const element of container.querySelectorAll(FOCUSABLE_SELECTOR_)) {
13
+ if (element.tabIndex >= 0 && isFocusable_(element)) {
14
+ return true;
15
+ }
16
+ }
17
+ return false;
18
+ }
19
+ /** The reading direction an element is laid out in. */
20
+ export function directionOf_(element) {
21
+ return getComputedStyle(element).direction === "rtl" ? "rtl" : "ltr";
22
+ }
23
+ /**
24
+ * The language of an element's text, from the closest `lang` attribute; for the
25
+ * collation typeahead compares names with. `undefined` for the runtime's.
26
+ */
27
+ export function localesOf_(element) {
28
+ const lang = element.closest("[lang]")?.lang;
29
+ return lang === "" ? undefined : lang;
30
+ }
31
+ //# sourceMappingURL=_dom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dom.js","sourceRoot":"","sources":["../../src/preact/_dom.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,CAAC,MAAM,mBAAmB,GAC/B,6HAA6H,CAAC;AAE/H,kFAAkF;AAClF,MAAM,UAAU,YAAY,CAAC,OAAoB;IAChD,OAAO,CACN,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;QAC7B,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,KAAK,MAAM;QAChD,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,IAAI;QACnC,OAAO,CAAC,eAAe,CAAC,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CACrD,CAAC;AACH,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,YAAY,CAAC,SAAsB;IAClD,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,gBAAgB,CAC/C,mBAAmB,CACnB,EAAE,CAAC;QACH,IAAI,OAAO,CAAC,QAAQ,IAAI,CAAC,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;YACpD,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC5C,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,OAAgB;IAC1C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAc,QAAQ,CAAC,EAAE,IAAI,CAAC;IAE1D,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AACvC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { ToastUrgency } from "../toast/toast-queue.js";
2
+ /**
3
+ * Announces text to screen readers through visually hidden live regions, a
4
+ * polite `status` and an assertive `alert`. Each announcement is a node added
5
+ * to its region, so the same text twice is read twice, and a quick second one
6
+ * does not replace the first.
7
+ *
8
+ * While a modal dialog is open, the rest of the page is inert and hidden from
9
+ * assistive technology, live regions included: the announcement then goes to a
10
+ * region inside the open dialog that holds focus.
11
+ *
12
+ * Framework-free; it belongs in `@ac-kit/browser/dom` (`TODO.md`).
13
+ */
14
+ export declare class LiveAnnouncer_ implements Disposable {
15
+ private readonly document_;
16
+ private readonly regions_;
17
+ private readonly timers_;
18
+ constructor(document: Document);
19
+ announce(lines: readonly string[], urgency: ToastUrgency): void;
20
+ [Symbol.dispose](): void;
21
+ /** The open dialog holding focus, or else the body. */
22
+ private host_;
23
+ private createRegions_;
24
+ private later_;
25
+ }
26
+ //# sourceMappingURL=_live-announcer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_live-announcer.d.ts","sourceRoot":"","sources":["../../src/preact/_live-announcer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAiB5D;;;;;;;;;;;GAWG;AACH,qBAAa,cAAe,YAAW,UAAU;IAChD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgC;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4C;IAEpE,YAAY,QAAQ,EAAE,QAAQ,EAE7B;IAED,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAsB9D;IAED,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAUvB;IAED,uDAAuD;IACvD,OAAO,CAAC,KAAK;IAab,OAAO,CAAC,cAAc;IAoBtB,OAAO,CAAC,MAAM;CAOd"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * A live region a newly made region waits this long before its first
3
+ * announcement, so assistive technology has registered it: one added and filled
4
+ * at once is not reliably read.
5
+ */
6
+ const REGISTER_DELAY_MS_ = 100;
7
+ /** How long an announcement stays in the region before it is removed. */
8
+ const CLEAR_DELAY_MS_ = 7000;
9
+ const VISUALLY_HIDDEN_ = "position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap";
10
+ /**
11
+ * Announces text to screen readers through visually hidden live regions, a
12
+ * polite `status` and an assertive `alert`. Each announcement is a node added
13
+ * to its region, so the same text twice is read twice, and a quick second one
14
+ * does not replace the first.
15
+ *
16
+ * While a modal dialog is open, the rest of the page is inert and hidden from
17
+ * assistive technology, live regions included: the announcement then goes to a
18
+ * region inside the open dialog that holds focus.
19
+ *
20
+ * Framework-free; it belongs in `@ac-kit/browser/dom` (`TODO.md`).
21
+ */
22
+ export class LiveAnnouncer_ {
23
+ document_;
24
+ regions_ = new Map();
25
+ timers_ = new Set();
26
+ constructor(document) {
27
+ this.document_ = document;
28
+ }
29
+ announce(lines, urgency) {
30
+ const host = this.host_();
31
+ const existing = this.regions_.get(host);
32
+ const regions = existing ?? this.createRegions_(host);
33
+ const region = regions[urgency];
34
+ const entry = this.document_.createElement("div");
35
+ for (const line of lines) {
36
+ const paragraph = this.document_.createElement("p");
37
+ paragraph.textContent = line;
38
+ entry.append(paragraph);
39
+ }
40
+ const add = () => {
41
+ region.append(entry);
42
+ this.later_(() => {
43
+ entry.remove();
44
+ }, CLEAR_DELAY_MS_);
45
+ };
46
+ if (existing === undefined) {
47
+ this.later_(add, REGISTER_DELAY_MS_);
48
+ }
49
+ else {
50
+ add();
51
+ }
52
+ }
53
+ [Symbol.dispose]() {
54
+ for (const timer of this.timers_) {
55
+ clearTimeout(timer);
56
+ }
57
+ this.timers_.clear();
58
+ for (const { polite, assertive } of this.regions_.values()) {
59
+ polite.remove();
60
+ assertive.remove();
61
+ }
62
+ this.regions_.clear();
63
+ }
64
+ /** The open dialog holding focus, or else the body. */
65
+ host_() {
66
+ for (const [host, regions] of this.regions_) {
67
+ if (!host.isConnected) {
68
+ regions.polite.remove();
69
+ regions.assertive.remove();
70
+ this.regions_.delete(host);
71
+ }
72
+ }
73
+ const dialog = this.document_.activeElement?.closest("dialog[open]");
74
+ return dialog ?? this.document_.body;
75
+ }
76
+ createRegions_(host) {
77
+ const create = (urgency) => {
78
+ const region = this.document_.createElement("div");
79
+ region.setAttribute("role", urgency === "polite" ? "status" : "alert");
80
+ region.setAttribute("aria-live", urgency);
81
+ region.setAttribute("style", VISUALLY_HIDDEN_);
82
+ region.dataset["ackLiveRegion"] = urgency;
83
+ host.append(region);
84
+ return region;
85
+ };
86
+ const regions = {
87
+ polite: create("polite"),
88
+ assertive: create("assertive"),
89
+ };
90
+ this.regions_.set(host, regions);
91
+ return regions;
92
+ }
93
+ later_(action, delayMs) {
94
+ const timer = setTimeout(() => {
95
+ this.timers_.delete(timer);
96
+ action();
97
+ }, delayMs);
98
+ this.timers_.add(timer);
99
+ }
100
+ }
101
+ //# sourceMappingURL=_live-announcer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_live-announcer.js","sourceRoot":"","sources":["../../src/preact/_live-announcer.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B,yEAAyE;AACzE,MAAM,eAAe,GAAG,IAAI,CAAC;AAI7B,MAAM,gBAAgB,GACrB,+HAA+H,CAAC;AAEjI;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,cAAc;IACT,SAAS,CAAW;IACpB,QAAQ,GAAG,IAAI,GAAG,EAAqB,CAAC;IACxC,OAAO,GAAG,IAAI,GAAG,EAAiC,CAAC;IAEpE,YAAY,QAAkB;QAC7B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,QAAQ,CAAC,KAAwB,EAAE,OAAqB;QACvD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CA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I,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAEjC,OAAO,OAAO,CAAC;IAChB,CAAC;IAEO,MAAM,CAAC,MAAsB,EAAE,OAAe;QACrD,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC3B,MAAM,EAAE,CAAC;QACV,CAAC,EAAE,OAAO,CAAC,CAAC;QACZ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;CACD"}
@@ -0,0 +1,40 @@
1
+ import type { ButtonHTMLAttributes, ComponentChildren, JSX } from "preact";
2
+ import { type ButtonSize, type ButtonVariant } from "../button/button.js";
3
+ import type { ControlTone } from "../tone.js";
4
+ /** Props of {@link Button}: its own, then any other `<button>` attribute. */
5
+ export type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "class" | "className"> & {
6
+ /** Defaults to `secondary`. */
7
+ variant?: ButtonVariant;
8
+ /** Defaults to `regular`. */
9
+ size?: ButtonSize;
10
+ tone?: ControlTone;
11
+ /** Drawn before the text, hidden from assistive technology. */
12
+ icon?: ComponentChildren;
13
+ /** Its label. */
14
+ children: ComponentChildren;
15
+ class?: string;
16
+ };
17
+ /**
18
+ * A push button for an action: `primary` for the one main action of a view,
19
+ * `secondary` for the others, `ghost` for a bare one. A native button, so it
20
+ * takes focus and activates with Space and Enter; `type` defaults to `button`,
21
+ * so inside a form only `type="submit"` submits it.
22
+ */
23
+ export declare function Button(props: ButtonProps): JSX.Element;
24
+ /** Props of {@link IconButton}: its own, then any other `<button>` attribute. */
25
+ export type IconButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "class" | "className" | "aria-label" | "children"> & {
26
+ /** Its accessible name, also its tooltip. */
27
+ label: string;
28
+ /** Defaults to `secondary`. */
29
+ variant?: ButtonVariant;
30
+ tone?: ControlTone;
31
+ /** The icon, hidden from assistive technology: `label` names the button. */
32
+ children: ComponentChildren;
33
+ class?: string;
34
+ };
35
+ /**
36
+ * A button drawn as an icon alone, named by `label`: transport controls, a
37
+ * close button. Takes the touch target's full size around a small icon.
38
+ */
39
+ export declare function IconButton(props: IconButtonProps): JSX.Element;
40
+ //# sourceMappingURL=button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../src/preact/button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE3E,OAAO,EACN,KAAK,UAAU,EACf,KAAK,aAAa,EAElB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,6EAA6E;AAC7E,MAAM,MAAM,WAAW,GAAG,IAAI,CAC7B,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,OAAO,GAAG,WAAW,CACrB,GAAG;IACH,+BAA+B;IAC/B,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,+DAA+D;IAC/D,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,iBAAiB;IACjB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CA2BtD;AAED,iFAAiF;AACjF,MAAM,MAAM,eAAe,GAAG,IAAI,CACjC,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,OAAO,GAAG,WAAW,GAAG,YAAY,GAAG,UAAU,CACjD,GAAG;IACH,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,4EAA4E;IAC5E,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,GAAG,CAAC,OAAO,CAyB9D"}
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
+ import { buttonAttributes, } from "../button/button.js";
3
+ import { joinClasses } from "./join-classes.js";
4
+ /**
5
+ * A push button for an action: `primary` for the one main action of a view,
6
+ * `secondary` for the others, `ghost` for a bare one. A native button, so it
7
+ * takes focus and activates with Space and Enter; `type` defaults to `button`,
8
+ * so inside a form only `type="submit"` submits it.
9
+ */
10
+ export function Button(props) {
11
+ const { variant, size, tone, icon, children, class: extra, type = "button", ...rest } = props;
12
+ return (_jsxs("button", { ...rest, ...buttonAttributes({ variant, size, tone }), type: type, class: joinClasses("ack-control ack-button", extra), children: [icon !== undefined && (_jsx("span", { class: "ack-button-icon", "aria-hidden": "true", children: icon })), children] }));
13
+ }
14
+ /**
15
+ * A button drawn as an icon alone, named by `label`: transport controls, a
16
+ * close button. Takes the touch target's full size around a small icon.
17
+ */
18
+ export function IconButton(props) {
19
+ const { label, variant, tone, children, class: extra, type = "button", ...rest } = props;
20
+ return (_jsx("button", { title: label, ...rest, ...buttonAttributes({ variant, tone }), type: type, "aria-label": label, class: joinClasses("ack-control ack-button ack-icon-button", extra), children: _jsx("span", { class: "ack-button-icon", "aria-hidden": "true", children: children }) }));
21
+ }
22
+ //# sourceMappingURL=button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"button.js","sourceRoot":"","sources":["../../src/preact/button.tsx"],"names":[],"mappings":";AAEA,OAAO,EAGN,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAmBhD;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,KAAkB;IACxC,MAAM,EACL,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,KAAK,EAAE,KAAK,EACZ,IAAI,GAAG,QAAQ,EACf,GAAG,IAAI,EACP,GAAG,KAAK,CAAC;IAEV,OAAO,CACN,qBACK,IAAI,KACJ,gBAAgB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAC7C,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,WAAW,CAAC,wBAAwB,EAAE,KAAK,CAAC,aAElD,IAAI,KAAK,SAAS,IAAI,CACtB,eAAM,KAAK,EAAC,iBAAiB,iBAAa,MAAM,YAC9C,IAAI,GACC,CACP,EACA,QAAQ,IACD,CACT,CAAC;AACH,CAAC;AAiBD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAsB;IAChD,MAAM,EACL,KAAK,EACL,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,KAAK,EAAE,KAAK,EACZ,IAAI,GAAG,QAAQ,EACf,GAAG,IAAI,EACP,GAAG,KAAK,CAAC;IAEV,OAAO,CACN,iBACC,KAAK,EAAE,KAAK,KACR,IAAI,KACJ,gBAAgB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EACvC,IAAI,EAAE,IAAI,gBACE,KAAK,EACjB,KAAK,EAAE,WAAW,CAAC,wCAAwC,EAAE,KAAK,CAAC,YAEnE,eAAM,KAAK,EAAC,iBAAiB,iBAAa,MAAM,YAC9C,QAAQ,GACH,GACC,CACT,CAAC;AACH,CAAC"}