@ac-kit/ui-common 0.0.0-stage → 0.1.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 (125) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/LICENSE +28 -0
  3. package/README.md +315 -2
  4. package/dist/button/button.d.ts +35 -0
  5. package/dist/button/button.d.ts.map +1 -0
  6. package/dist/button/button.js +22 -0
  7. package/dist/button/button.js.map +1 -0
  8. package/dist/dialog/dialog.d.ts +33 -0
  9. package/dist/dialog/dialog.d.ts.map +1 -0
  10. package/dist/dialog/dialog.js +23 -0
  11. package/dist/dialog/dialog.js.map +1 -0
  12. package/dist/focus/owns-arrow-keys.d.ts +31 -0
  13. package/dist/focus/owns-arrow-keys.d.ts.map +1 -0
  14. package/dist/focus/owns-arrow-keys.js +64 -0
  15. package/dist/focus/owns-arrow-keys.js.map +1 -0
  16. package/dist/focus/roving-focus.d.ts +34 -0
  17. package/dist/focus/roving-focus.d.ts.map +1 -0
  18. package/dist/focus/roving-focus.js +72 -0
  19. package/dist/focus/roving-focus.js.map +1 -0
  20. package/dist/index.d.ts +16 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +16 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/knob/knob.d.ts +106 -0
  25. package/dist/knob/knob.d.ts.map +1 -0
  26. package/dist/knob/knob.js +116 -0
  27. package/dist/knob/knob.js.map +1 -0
  28. package/dist/meter/meter.d.ts +63 -0
  29. package/dist/meter/meter.d.ts.map +1 -0
  30. package/dist/meter/meter.js +57 -0
  31. package/dist/meter/meter.js.map +1 -0
  32. package/dist/preact/button.d.ts +40 -0
  33. package/dist/preact/button.d.ts.map +1 -0
  34. package/dist/preact/button.js +22 -0
  35. package/dist/preact/button.js.map +1 -0
  36. package/dist/preact/dialog.d.ts +43 -0
  37. package/dist/preact/dialog.d.ts.map +1 -0
  38. package/dist/preact/dialog.js +89 -0
  39. package/dist/preact/dialog.js.map +1 -0
  40. package/dist/preact/index.d.ts +13 -0
  41. package/dist/preact/index.d.ts.map +1 -0
  42. package/dist/preact/index.js +13 -0
  43. package/dist/preact/index.js.map +1 -0
  44. package/dist/preact/join-classes.d.ts +10 -0
  45. package/dist/preact/join-classes.d.ts.map +1 -0
  46. package/dist/preact/join-classes.js +12 -0
  47. package/dist/preact/join-classes.js.map +1 -0
  48. package/dist/preact/knob.d.ts +51 -0
  49. package/dist/preact/knob.d.ts.map +1 -0
  50. package/dist/preact/knob.js +152 -0
  51. package/dist/preact/knob.js.map +1 -0
  52. package/dist/preact/meter.d.ts +34 -0
  53. package/dist/preact/meter.d.ts.map +1 -0
  54. package/dist/preact/meter.js +21 -0
  55. package/dist/preact/meter.js.map +1 -0
  56. package/dist/preact/radio-group.d.ts +50 -0
  57. package/dist/preact/radio-group.d.ts.map +1 -0
  58. package/dist/preact/radio-group.js +42 -0
  59. package/dist/preact/radio-group.js.map +1 -0
  60. package/dist/preact/readout.d.ts +22 -0
  61. package/dist/preact/readout.d.ts.map +1 -0
  62. package/dist/preact/readout.js +13 -0
  63. package/dist/preact/readout.js.map +1 -0
  64. package/dist/preact/slider.d.ts +40 -0
  65. package/dist/preact/slider.d.ts.map +1 -0
  66. package/dist/preact/slider.js +162 -0
  67. package/dist/preact/slider.js.map +1 -0
  68. package/dist/preact/switch.d.ts +25 -0
  69. package/dist/preact/switch.d.ts.map +1 -0
  70. package/dist/preact/switch.js +19 -0
  71. package/dist/preact/switch.js.map +1 -0
  72. package/dist/preact/toggle-button.d.ts +26 -0
  73. package/dist/preact/toggle-button.d.ts.map +1 -0
  74. package/dist/preact/toggle-button.js +16 -0
  75. package/dist/preact/toggle-button.js.map +1 -0
  76. package/dist/preact/toolbar.d.ts +24 -0
  77. package/dist/preact/toolbar.d.ts.map +1 -0
  78. package/dist/preact/toolbar.js +148 -0
  79. package/dist/preact/toolbar.js.map +1 -0
  80. package/dist/preact/use-element-binding.d.ts +32 -0
  81. package/dist/preact/use-element-binding.d.ts.map +1 -0
  82. package/dist/preact/use-element-binding.js +51 -0
  83. package/dist/preact/use-element-binding.js.map +1 -0
  84. package/dist/readout/readout.d.ts +41 -0
  85. package/dist/readout/readout.d.ts.map +1 -0
  86. package/dist/readout/readout.js +26 -0
  87. package/dist/readout/readout.js.map +1 -0
  88. package/dist/slider/_clamped-value.d.ts +7 -0
  89. package/dist/slider/_clamped-value.d.ts.map +1 -0
  90. package/dist/slider/_clamped-value.js +9 -0
  91. package/dist/slider/_clamped-value.js.map +1 -0
  92. package/dist/slider/slider-attributes.d.ts +50 -0
  93. package/dist/slider/slider-attributes.d.ts.map +1 -0
  94. package/dist/slider/slider-attributes.js +38 -0
  95. package/dist/slider/slider-attributes.js.map +1 -0
  96. package/dist/slider/slider-range.d.ts +59 -0
  97. package/dist/slider/slider-range.d.ts.map +1 -0
  98. package/dist/slider/slider-range.js +73 -0
  99. package/dist/slider/slider-range.js.map +1 -0
  100. package/dist/slider/slider-track.d.ts +37 -0
  101. package/dist/slider/slider-track.d.ts.map +1 -0
  102. package/dist/slider/slider-track.js +35 -0
  103. package/dist/slider/slider-track.js.map +1 -0
  104. package/dist/slider/stepped-value.d.ts +31 -0
  105. package/dist/slider/stepped-value.d.ts.map +1 -0
  106. package/dist/slider/stepped-value.js +55 -0
  107. package/dist/slider/stepped-value.js.map +1 -0
  108. package/dist/switch/switch.d.ts +30 -0
  109. package/dist/switch/switch.d.ts.map +1 -0
  110. package/dist/switch/switch.js +26 -0
  111. package/dist/switch/switch.js.map +1 -0
  112. package/dist/toggle-button/toggle-button.d.ts +44 -0
  113. package/dist/toggle-button/toggle-button.d.ts.map +1 -0
  114. package/dist/toggle-button/toggle-button.js +31 -0
  115. package/dist/toggle-button/toggle-button.js.map +1 -0
  116. package/dist/tone.d.ts +8 -0
  117. package/dist/tone.d.ts.map +1 -0
  118. package/dist/tone.js +2 -0
  119. package/dist/tone.js.map +1 -0
  120. package/dist/toolbar/toolbar.d.ts +35 -0
  121. package/dist/toolbar/toolbar.d.ts.map +1 -0
  122. package/dist/toolbar/toolbar.js +23 -0
  123. package/dist/toolbar/toolbar.js.map +1 -0
  124. package/package.json +100 -3
  125. package/styles.css +992 -0
@@ -0,0 +1,64 @@
1
+ const ARROW_INPUT_TYPES_ = new Set([
2
+ "text",
3
+ "search",
4
+ "email",
5
+ "url",
6
+ "tel",
7
+ "password",
8
+ "number",
9
+ "date",
10
+ "datetime-local",
11
+ "month",
12
+ "time",
13
+ "week",
14
+ "range",
15
+ "radio",
16
+ ]);
17
+ const ARROW_ROLES_ = new Set([
18
+ "slider",
19
+ "spinbutton",
20
+ "radio",
21
+ "radiogroup",
22
+ "combobox",
23
+ "listbox",
24
+ "menu",
25
+ "menubar",
26
+ "tablist",
27
+ "tree",
28
+ "treegrid",
29
+ "grid",
30
+ "textbox",
31
+ ]);
32
+ /**
33
+ * Whether an element uses the arrow keys itself, so a container's roving focus
34
+ * must leave them to it: text-entry inputs (`text`, `search`, `email`, `url`,
35
+ * `tel`, `password`, `number`, the date and time types), `range`, `radio`,
36
+ * `<textarea>`, `<select>`, editable content, and the roles `slider`,
37
+ * `spinbutton`, `radio`, `radiogroup`, `combobox`, `listbox`, `menu`,
38
+ * `menubar`, `tablist`, `tree`, `treegrid`, `grid`, `textbox`. An `<input>`
39
+ * with no `type` is a text input.
40
+ *
41
+ * Time complexity: O(1). Memory: O(1).
42
+ *
43
+ * @example
44
+ * ownsArrowKeys({ tagName: "input", type: "range" }); // true
45
+ * ownsArrowKeys({ tagName: "button" }); // false
46
+ * ownsArrowKeys({ tagName: "div", role: "slider" }); // true
47
+ */
48
+ export function ownsArrowKeys(input) {
49
+ if (input.isContentEditable === true) {
50
+ return true;
51
+ }
52
+ if (input.role !== undefined && ARROW_ROLES_.has(input.role.toLowerCase())) {
53
+ return true;
54
+ }
55
+ const tagName = input.tagName.toLowerCase();
56
+ if (tagName === "textarea" || tagName === "select") {
57
+ return true;
58
+ }
59
+ return (tagName === "input" &&
60
+ (input.type === undefined ||
61
+ input.type === "" ||
62
+ ARROW_INPUT_TYPES_.has(input.type.toLowerCase())));
63
+ }
64
+ //# sourceMappingURL=owns-arrow-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owns-arrow-keys.js","sourceRoot":"","sources":["../../src/focus/owns-arrow-keys.ts"],"names":[],"mappings":"AAcA,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC;IACvD,MAAM;IACN,QAAQ;IACR,OAAO;IACP,KAAK;IACL,KAAK;IACL,UAAU;IACV,QAAQ;IACR,MAAM;IACN,gBAAgB;IAChB,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;CACP,CAAC,CAAC;AAEH,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC;IACjD,QAAQ;IACR,YAAY;IACZ,OAAO;IACP,YAAY;IACZ,UAAU;IACV,SAAS;IACT,MAAM;IACN,SAAS;IACT,SAAS;IACT,MAAM;IACN,UAAU;IACV,MAAM;IACN,SAAS;CACT,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,aAAa,CAAC,KAAyB;IACtD,IAAI,KAAK,CAAC,iBAAiB,KAAK,IAAI,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;QAC5E,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;IAC5C,IAAI,OAAO,KAAK,UAAU,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;QACpD,OAAO,IAAI,CAAC;IACb,CAAC;IAED,OAAO,CACN,OAAO,KAAK,OAAO;QACnB,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS;YACxB,KAAK,CAAC,IAAI,KAAK,EAAE;YACjB,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAClD,CAAC;AACH,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { type Predicate } from "@ac-kit/core";
2
+ /** Options of {@link rovingFocusIndex}. */
3
+ export type RovingFocusOptions = {
4
+ /**
5
+ * Which arrows move: Left and Right, Up and Down, or all four. Defaults to
6
+ * `horizontal`.
7
+ */
8
+ readonly orientation?: "horizontal" | "vertical" | "both";
9
+ /** Past an end, go round. Defaults to true. */
10
+ readonly wrap?: boolean;
11
+ /** `rtl` swaps Left and Right. Defaults to `ltr`. */
12
+ readonly direction?: "ltr" | "rtl";
13
+ /** Items focus skips. Defaults to none. */
14
+ readonly isDisabled?: Predicate<[index: number]>;
15
+ };
16
+ /**
17
+ * The item a key moves focus to among `count` items, per the WAI-ARIA
18
+ * roving-tabindex practice: arrows to the previous or next enabled item, Home
19
+ * and End to the first and last enabled one. `undefined` for another key, when
20
+ * no item is enabled, or when `wrap` is false and no enabled item lies that
21
+ * way.
22
+ *
23
+ * Time complexity: O(count) at worst, skipping disabled items. Memory: O(1).
24
+ *
25
+ * @example
26
+ * rovingFocusIndex(2, "ArrowRight", 3); // 0
27
+ * rovingFocusIndex(0, "End", 3); // 2
28
+ * rovingFocusIndex(0, "ArrowDown", 3); // undefined: not a horizontal key
29
+ *
30
+ * @throws {RangeError} When `count` is not a non-negative safe integer or
31
+ * `current` is outside [0, count).
32
+ */
33
+ export declare function rovingFocusIndex(current: number, key: string, count: number, options?: RovingFocusOptions): number | undefined;
34
+ //# sourceMappingURL=roving-focus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roving-focus.d.ts","sourceRoot":"","sources":["../../src/focus/roving-focus.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,SAAS,EACd,MAAM,cAAc,CAAC;AAEtB,2CAA2C;AAC3C,MAAM,MAAM,kBAAkB,GAAG;IAChC;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,CAAC;IAC1D,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,qDAAqD;IACrD,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACnC,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,kBAAuB,GAC9B,MAAM,GAAG,SAAS,CAgEpB"}
@@ -0,0 +1,72 @@
1
+ import { describeValue, isIntegerInRange, modEuclid, } from "@ac-kit/core";
2
+ /**
3
+ * The item a key moves focus to among `count` items, per the WAI-ARIA
4
+ * roving-tabindex practice: arrows to the previous or next enabled item, Home
5
+ * and End to the first and last enabled one. `undefined` for another key, when
6
+ * no item is enabled, or when `wrap` is false and no enabled item lies that
7
+ * way.
8
+ *
9
+ * Time complexity: O(count) at worst, skipping disabled items. Memory: O(1).
10
+ *
11
+ * @example
12
+ * rovingFocusIndex(2, "ArrowRight", 3); // 0
13
+ * rovingFocusIndex(0, "End", 3); // 2
14
+ * rovingFocusIndex(0, "ArrowDown", 3); // undefined: not a horizontal key
15
+ *
16
+ * @throws {RangeError} When `count` is not a non-negative safe integer or
17
+ * `current` is outside [0, count).
18
+ */
19
+ export function rovingFocusIndex(current, key, count, options = {}) {
20
+ if (!isIntegerInRange(count, 0, Number.MAX_SAFE_INTEGER + 1)) {
21
+ throw new RangeError(`count must be a non-negative safe integer, got ${describeValue(count)}`);
22
+ }
23
+ if (!isIntegerInRange(current, 0, count)) {
24
+ throw new RangeError(`current must be an integer in [0, ${String(count)}), got ${describeValue(current)}`);
25
+ }
26
+ const { orientation = "horizontal", wrap = true, direction = "ltr", isDisabled, } = options;
27
+ let step;
28
+ let from;
29
+ switch (key) {
30
+ case "Home":
31
+ step = 1;
32
+ from = -1;
33
+ break;
34
+ case "End":
35
+ step = -1;
36
+ from = count;
37
+ break;
38
+ case "ArrowLeft":
39
+ case "ArrowRight": {
40
+ if (orientation === "vertical") {
41
+ return undefined;
42
+ }
43
+ const isForward = (key === "ArrowRight") === (direction === "ltr");
44
+ step = isForward ? 1 : -1;
45
+ from = current;
46
+ break;
47
+ }
48
+ case "ArrowUp":
49
+ case "ArrowDown":
50
+ if (orientation === "horizontal") {
51
+ return undefined;
52
+ }
53
+ step = key === "ArrowDown" ? 1 : -1;
54
+ from = current;
55
+ break;
56
+ default:
57
+ return undefined;
58
+ }
59
+ const isEdgeKey = key === "Home" || key === "End";
60
+ for (let visited = 0; visited < count; visited += 1) {
61
+ const next = modEuclid(from + step, count);
62
+ if (!wrap && !isEdgeKey && (from + step < 0 || from + step >= count)) {
63
+ return undefined;
64
+ }
65
+ if (isDisabled?.(next) !== true) {
66
+ return next;
67
+ }
68
+ from = next;
69
+ }
70
+ return undefined;
71
+ }
72
+ //# sourceMappingURL=roving-focus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roving-focus.js","sourceRoot":"","sources":["../../src/focus/roving-focus.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,gBAAgB,EAChB,SAAS,GAET,MAAM,cAAc,CAAC;AAiBtB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAC/B,OAAe,EACf,GAAW,EACX,KAAa,EACb,OAAO,GAAuB,EAAE;IAEhC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,CAAC,gBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,UAAU,CACnB,kDAAkD,aAAa,CAAC,KAAK,CAAC,EAAE,CACxE,CAAC;IACH,CAAC;IACD,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AC;IAED,MAAM,SAAS,GAAG,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,KAAK,CAAC;IAClD,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,KAAK,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;YACtE,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,IAAI,UAAU,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IAAI,GAAG,IAAI,CAAC;IACb,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC"}
@@ -0,0 +1,16 @@
1
+ export * from "./button/button.js";
2
+ export * from "./dialog/dialog.js";
3
+ export * from "./focus/owns-arrow-keys.js";
4
+ export * from "./focus/roving-focus.js";
5
+ export * from "./knob/knob.js";
6
+ export * from "./meter/meter.js";
7
+ export * from "./readout/readout.js";
8
+ export * from "./slider/slider-attributes.js";
9
+ export * from "./slider/slider-range.js";
10
+ export * from "./slider/slider-track.js";
11
+ export * from "./slider/stepped-value.js";
12
+ export * from "./switch/switch.js";
13
+ export * from "./toggle-button/toggle-button.js";
14
+ export * from "./tone.js";
15
+ export * from "./toolbar/toolbar.js";
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ export * from "./button/button.js";
2
+ export * from "./dialog/dialog.js";
3
+ export * from "./focus/owns-arrow-keys.js";
4
+ export * from "./focus/roving-focus.js";
5
+ export * from "./knob/knob.js";
6
+ export * from "./meter/meter.js";
7
+ export * from "./readout/readout.js";
8
+ export * from "./slider/slider-attributes.js";
9
+ export * from "./slider/slider-range.js";
10
+ export * from "./slider/slider-track.js";
11
+ export * from "./slider/stepped-value.js";
12
+ export * from "./switch/switch.js";
13
+ export * from "./toggle-button/toggle-button.js";
14
+ export * from "./tone.js";
15
+ export * from "./toolbar/toolbar.js";
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,106 @@
1
+ import { type SliderRange } from "../slider/slider-range.js";
2
+ /**
3
+ * Where a knob's travel starts and how far it turns, in degrees clockwise from
4
+ * twelve o'clock.
5
+ */
6
+ export type KnobArc = {
7
+ startDegrees: number;
8
+ /** Above zero and below 360. */
9
+ sweepDegrees: number;
10
+ };
11
+ /** The usual knob travel: 270°, from 7:30 to 4:30 clockwise. */
12
+ export declare const KNOB_ARC: {
13
+ readonly startDegrees: -135;
14
+ readonly sweepDegrees: 270;
15
+ };
16
+ /** The angles a knob draws, in degrees clockwise from twelve o'clock. */
17
+ export type KnobAngles = {
18
+ /** Where the pointer points: the value. */
19
+ pointer: number;
20
+ /** The lower end of the lit arc. */
21
+ arcFrom: number;
22
+ /** The higher end of the lit arc; equal to `arcFrom` when nothing is lit. */
23
+ arcTo: number;
24
+ };
25
+ /** Options of {@link knobAngles}. */
26
+ export type KnobAnglesOptions = {
27
+ /**
28
+ * The value the lit arc grows from. Defaults to `range.min`; a bipolar knob
29
+ * (pan, detune) gives its centre, and lights from there to either side.
30
+ */
31
+ origin?: number;
32
+ /** Defaults to {@link KNOB_ARC}. */
33
+ arc?: KnobArc;
34
+ };
35
+ /**
36
+ * The pointer angle of `value` and the span of the lit arc, for drawing a knob.
37
+ * Values outside the range are clamped to its ends.
38
+ *
39
+ * Time complexity: O(1). Memory: O(1).
40
+ *
41
+ * @example
42
+ * knobAngles(75, { min: 50, max: 100, step: 1 });
43
+ * // { pointer: 0, arcFrom: -135, arcTo: 0 }
44
+ * knobAngles(25, { min: 0, max: 100, step: 1 }, { origin: 50 });
45
+ * // { pointer: -67.5, arcFrom: -67.5, arcTo: 0 }
46
+ *
47
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
48
+ * zero.
49
+ */
50
+ export declare function knobAngles(value: number, range: SliderRange, options?: KnobAnglesOptions): KnobAngles;
51
+ /**
52
+ * A knob's dial in SVG user units, y down: its centre and radius. Plain
53
+ * numbers, so the API does not follow the math types.
54
+ */
55
+ export type KnobDial = {
56
+ readonly centerX: number;
57
+ readonly centerY: number;
58
+ readonly radius: number;
59
+ };
60
+ /**
61
+ * The SVG path data of the clockwise arc of `dial` from `fromDegrees` to
62
+ * `toDegrees`, both on the knob's clock face (degrees clockwise from twelve
63
+ * o'clock) in SVG's y-down user space, coordinates to two decimals. Stroke it
64
+ * for a knob's track or its lit arc.
65
+ *
66
+ * Time complexity: O(1). Memory: O(1).
67
+ *
68
+ * @example
69
+ * knobArcPath({ centerX: 26, centerY: 26, radius: 22 }, -90, 0);
70
+ * // "M4 26 A22 22 0 0 1 26 4"
71
+ *
72
+ * @throws {RangeError} When the arc is not between 0° and 360°: `toDegrees`
73
+ * below `fromDegrees`, or a full turn or more, which one SVG arc cannot
74
+ * draw.
75
+ */
76
+ export declare function knobArcPath(dial: KnobDial, fromDegrees: number, toDegrees: number): string;
77
+ /** Options of {@link knobDragValue}. */
78
+ export type KnobDragOptions = {
79
+ /** How many pixels of vertical travel cross the whole range. Defaults to 160. */
80
+ travel?: number;
81
+ /**
82
+ * Fine mode, usually while Shift is held: the travel is divided by
83
+ * `fineScale`.
84
+ */
85
+ isFine?: boolean;
86
+ /** How much finer fine mode is. Defaults to 0.25: four times the travel. */
87
+ fineScale?: number;
88
+ };
89
+ /**
90
+ * The value of a knob dragged vertically: up turns it up, down turns it down,
91
+ * as on hardware controllers' touch surfaces, where turning around the knob
92
+ * would hide it under the finger. `rise` is how far the pointer has moved up
93
+ * since the press, in pixels (`pressY - currentY`). The result is snapped
94
+ * ({@link snapSliderValue}).
95
+ *
96
+ * Time complexity: O(1). Memory: O(1).
97
+ *
98
+ * @example
99
+ * knobDragValue(80, 32, { min: 50, max: 100, step: 1 }); // 90
100
+ * knobDragValue(80, 32, { min: 50, max: 100, step: 1 }, { isFine: true }); // 83
101
+ *
102
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
103
+ * zero.
104
+ */
105
+ export declare function knobDragValue(startValue: number, rise: number, range: SliderRange, options?: KnobDragOptions): number;
106
+ //# sourceMappingURL=knob.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knob.d.ts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AC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAOF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAC5B,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE,eAAe,GACvB,MAAM,CASR"}
@@ -0,0 +1,116 @@
1
+ import { describeValue } from "@ac-kit/core";
2
+ import { printPathData } from "@ac-kit/format-svg";
3
+ import { circle2Create, circle2PointAt, circle2Set, } from "@ac-kit/math-geometry";
4
+ import { vec2Create } from "@ac-kit/math-linear";
5
+ import { DEG_TO_RAD, lerp } from "@ac-kit/math-scalar";
6
+ import { sliderFraction, snapSliderValue, } from "../slider/slider-range.js";
7
+ /** The usual knob travel: 270°, from 7:30 to 4:30 clockwise. */
8
+ export const KNOB_ARC = {
9
+ startDegrees: -135,
10
+ sweepDegrees: 270,
11
+ };
12
+ /**
13
+ * The pointer angle of `value` and the span of the lit arc, for drawing a knob.
14
+ * Values outside the range are clamped to its ends.
15
+ *
16
+ * Time complexity: O(1). Memory: O(1).
17
+ *
18
+ * @example
19
+ * knobAngles(75, { min: 50, max: 100, step: 1 });
20
+ * // { pointer: 0, arcFrom: -135, arcTo: 0 }
21
+ * knobAngles(25, { min: 0, max: 100, step: 1 }, { origin: 50 });
22
+ * // { pointer: -67.5, arcFrom: -67.5, arcTo: 0 }
23
+ *
24
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
25
+ * zero.
26
+ */
27
+ export function knobAngles(value, range, options) {
28
+ const { startDegrees, sweepDegrees } = options?.arc ?? KNOB_ARC;
29
+ const endDegrees = startDegrees + sweepDegrees;
30
+ const pointer = lerp(startDegrees, endDegrees, sliderFraction(value, range));
31
+ const origin = lerp(startDegrees, endDegrees, sliderFraction(options?.origin ?? range.min, range));
32
+ return pointer < origin
33
+ ? { pointer, arcFrom: pointer, arcTo: origin }
34
+ : { pointer, arcFrom: origin, arcTo: pointer };
35
+ }
36
+ /**
37
+ * The SVG path data of the clockwise arc of `dial` from `fromDegrees` to
38
+ * `toDegrees`, both on the knob's clock face (degrees clockwise from twelve
39
+ * o'clock) in SVG's y-down user space, coordinates to two decimals. Stroke it
40
+ * for a knob's track or its lit arc.
41
+ *
42
+ * Time complexity: O(1). Memory: O(1).
43
+ *
44
+ * @example
45
+ * knobArcPath({ centerX: 26, centerY: 26, radius: 22 }, -90, 0);
46
+ * // "M4 26 A22 22 0 0 1 26 4"
47
+ *
48
+ * @throws {RangeError} When the arc is not between 0° and 360°: `toDegrees`
49
+ * below `fromDegrees`, or a full turn or more, which one SVG arc cannot
50
+ * draw.
51
+ */
52
+ export function knobArcPath(dial, fromDegrees, toDegrees) {
53
+ const sweep = toDegrees - fromDegrees;
54
+ if (!(sweep >= 0 && sweep < 360)) {
55
+ throw new RangeError(`A knob arc runs clockwise less than a full turn, got ${describeValue(fromDegrees)}° to ${describeValue(toDegrees)}°.`);
56
+ }
57
+ const circle = circle2Set(CIRCLE_, dial.centerX, dial.centerY, dial.radius);
58
+ const start = dialPoint_(START_, circle, fromDegrees);
59
+ const end = dialPoint_(END_, circle, toDegrees);
60
+ return printPathData([
61
+ { kind: "moveto", x: start[0], y: start[1] },
62
+ {
63
+ kind: "elliptical-arc",
64
+ rx: dial.radius,
65
+ ry: dial.radius,
66
+ xAxisRotation: 0,
67
+ largeArc: sweep > 180,
68
+ // Positive-angle direction, which is clockwise with y down.
69
+ sweep: true,
70
+ x: end[0],
71
+ y: end[1],
72
+ },
73
+ ], { fractionDigits: 2 });
74
+ }
75
+ /**
76
+ * Scratch circle and points of {@link knobArcPath}; they never leave this
77
+ * module.
78
+ */
79
+ const CIRCLE_ = circle2Create();
80
+ const START_ = vec2Create();
81
+ const END_ = vec2Create();
82
+ /**
83
+ * Writes the point of `dial` at a clock-face angle into `out`. `math-geometry`
84
+ * measures from the positive x axis towards positive y; with SVG's y pointing
85
+ * down that turns clockwise, as a clock does, so only twelve o'clock's offset
86
+ * of a quarter turn is left to convert.
87
+ */
88
+ function dialPoint_(out, dial, clockDegrees) {
89
+ return circle2PointAt(out, dial, (clockDegrees - 90) * DEG_TO_RAD);
90
+ }
91
+ // Tall enough to aim at one step of a hundred with a finger, short enough to
92
+ // cross the range without lifting it.
93
+ const DEFAULT_KNOB_TRAVEL_ = 160;
94
+ const DEFAULT_FINE_SCALE_ = 0.25;
95
+ /**
96
+ * The value of a knob dragged vertically: up turns it up, down turns it down,
97
+ * as on hardware controllers' touch surfaces, where turning around the knob
98
+ * would hide it under the finger. `rise` is how far the pointer has moved up
99
+ * since the press, in pixels (`pressY - currentY`). The result is snapped
100
+ * ({@link snapSliderValue}).
101
+ *
102
+ * Time complexity: O(1). Memory: O(1).
103
+ *
104
+ * @example
105
+ * knobDragValue(80, 32, { min: 50, max: 100, step: 1 }); // 90
106
+ * knobDragValue(80, 32, { min: 50, max: 100, step: 1 }, { isFine: true }); // 83
107
+ *
108
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
109
+ * zero.
110
+ */
111
+ export function knobDragValue(startValue, rise, range, options) {
112
+ const travel = options?.travel ?? DEFAULT_KNOB_TRAVEL_;
113
+ const scale = options?.isFine === true ? (options.fineScale ?? DEFAULT_FINE_SCALE_) : 1;
114
+ return snapSliderValue(startValue + (rise / travel) * (range.max - range.min) * scale, range);
115
+ }
116
+ //# sourceMappingURL=knob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knob.js","sourceRoot":"","sources":["../../src/knob/knob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAEN,aAAa,EACb,cAAc,EACd,UAAU,GACV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAa,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC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MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,aAAa,CAC5B,UAAkB,EAClB,IAAY,EACZ,KAAkB,EAClB,OAAyB;IAEzB,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,oBAAoB,CAAC;IACvD,MAAM,KAAK,GACV,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,IAAI,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3E,OAAO,eAAe,CACrB,UAAU,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,EAC9D,KAAK,CACL,CAAC;AACH,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,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;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