@sdxc/ui 2026.10.8 → 2026.10.10

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 (41) hide show
  1. package/README.md +71 -2
  2. package/dist/behaviors/announcer.d.ts +19 -1
  3. package/dist/behaviors/announcer.js +32 -4
  4. package/dist/behaviors/toaster.d.ts +1 -1
  5. package/dist/behaviors/toaster.js +1 -1
  6. package/dist/components/color-swatch.js +1 -1
  7. package/dist/components/index.d.ts +1 -0
  8. package/dist/components/index.js +1 -0
  9. package/dist/components/marker.js +1 -1
  10. package/dist/components/shortcut-list.d.ts +49 -0
  11. package/dist/components/shortcut-list.js +39 -0
  12. package/dist/components/skeleton.d.ts +1 -1
  13. package/dist/components/skeleton.js +2 -2
  14. package/dist/mixins/calendar-keys.js +5 -7
  15. package/dist/mixins/command-filter.js +9 -7
  16. package/dist/mixins/command-keys.js +6 -19
  17. package/dist/mixins/drag-reorder.js +6 -6
  18. package/dist/mixins/drop-zone.js +6 -8
  19. package/dist/mixins/grid-list-keys.js +8 -8
  20. package/dist/mixins/hotkey.d.ts +2 -1
  21. package/dist/mixins/hotkey.js +8 -54
  22. package/dist/mixins/index.d.ts +2 -0
  23. package/dist/mixins/index.js +2 -0
  24. package/dist/mixins/keymap.d.ts +61 -0
  25. package/dist/mixins/keymap.js +88 -0
  26. package/dist/mixins/message-follow.js +13 -11
  27. package/dist/mixins/range-preview.js +5 -7
  28. package/dist/mixins/resize-handle.js +9 -9
  29. package/dist/mixins/track-host-node.d.ts +8 -6
  30. package/dist/mixins/track-host-node.js +8 -6
  31. package/dist/mixins/treeKeys.js +11 -9
  32. package/dist/mixins/view-transition.js +14 -13
  33. package/dist/mixins/while-live.d.ts +24 -0
  34. package/dist/mixins/while-live.js +56 -0
  35. package/dist/utils/color-math.js +1 -1
  36. package/dist/utils/index.d.ts +1 -0
  37. package/dist/utils/index.js +1 -0
  38. package/dist/utils/key-combo.d.ts +69 -0
  39. package/dist/utils/key-combo.js +142 -0
  40. package/package.json +2 -2
  41. package/src/reset.css +18 -8
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Keyboard shortcut combos as written once and read twice: matched against a `keydown`
3
+ * and printed as the key caps a hint shows. One spelling (`"mod+k"`, `"?"`, `"J"`) serves
4
+ * both, so a binding and the hint advertising it never disagree about the platform.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ /**
10
+ * Where a reader is typing, and so where a bare letter is a letter rather than a command.
11
+ */
12
+ export declare const TYPING_TARGET_SELECTOR = "input, textarea, select, [contenteditable]:not([contenteditable=\"false\"]), [role=\"textbox\"]";
13
+ /**
14
+ * A combo split into its trigger and the modifiers held with it. A bare single character
15
+ * is a `character` combo: it names the character typed, so its case is significant and
16
+ * Shift is whatever produced it.
17
+ */
18
+ export interface KeyCombo {
19
+ /** `KeyboardEvent.key` the combo fires on; lowercased unless the combo is a bare character. */
20
+ key: string;
21
+ /** Whether the combo is one typed character with no modifier listed. */
22
+ character: boolean;
23
+ /** Whether the platform's primary modifier, Command or Control, is held. */
24
+ mod: boolean;
25
+ ctrl: boolean;
26
+ meta: boolean;
27
+ alt: boolean;
28
+ shift: boolean;
29
+ }
30
+ /**
31
+ * Splits a `+`-joined combo into its trigger key and modifiers, matching modifier names
32
+ * case-insensitively. Unknown tokens before the trigger are ignored.
33
+ *
34
+ * @param combo The combo as written, e.g. `"mod+shift+k"`, `"escape"`, `"?"`.
35
+ * @returns The trigger key and the modifier flags {@link matchesKeyCombo} compares.
36
+ * @example parseKeyCombo("J") // { key: "J", character: true, … }
37
+ */
38
+ export declare function parseKeyCombo(combo: string): KeyCombo;
39
+ /**
40
+ * Whether a keystroke strikes exactly `combo`. A character combo matches the character
41
+ * typed with Control, Alt and Meta all up; any other combo matches its key in any case
42
+ * with exactly the listed modifiers held, so it never fires on a larger chord.
43
+ *
44
+ * @param event The keystroke, or any object carrying its key and modifier flags.
45
+ * @param combo The combo, as written or already parsed.
46
+ * @returns Whether the keystroke is this combo.
47
+ * @example matchesKeyCombo(event, "mod+k") // ⌘K on a Mac, Ctrl+K elsewhere
48
+ */
49
+ export declare function matchesKeyCombo(event: Pick<KeyboardEvent, "key" | "ctrlKey" | "metaKey" | "altKey" | "shiftKey">, combo: KeyCombo | string): boolean;
50
+ /**
51
+ * The key caps a hint prints for `combo`, one per key in press order, in the glyphs of
52
+ * the keyboard in front of the reader. A bare character prints as written, since its case
53
+ * is the binding; a key inside a chord prints upper-cased, the way a key cap shows it.
54
+ *
55
+ * @param combo The combo as written, e.g. `"mod+shift+z"`.
56
+ * @param apple Whether the reader's keyboard carries the Apple modifier glyphs.
57
+ * @returns The caps to render, each already the glyph to print.
58
+ * @example keyComboGlyphs("mod+k", true) // ["⌘", "K"]
59
+ * @example keyComboGlyphs("mod+k", false) // ["Ctrl", "K"]
60
+ */
61
+ export declare function keyComboGlyphs(combo: string, apple: boolean): string[];
62
+ /**
63
+ * Whether a keystroke was aimed at a field the reader is typing in, where a bare letter
64
+ * shortcut would swallow the letter.
65
+ *
66
+ * @param target The keystroke's target.
67
+ * @returns Whether the target is, or sits inside, an editable control.
68
+ */
69
+ export declare function isTypingTarget(target: EventTarget | null): boolean;
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Keyboard shortcut combos as written once and read twice: matched against a `keydown`
3
+ * and printed as the key caps a hint shows. One spelling (`"mod+k"`, `"?"`, `"J"`) serves
4
+ * both, so a binding and the hint advertising it never disagree about the platform.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ /**
10
+ * Where a reader is typing, and so where a bare letter is a letter rather than a command.
11
+ */
12
+ export const TYPING_TARGET_SELECTOR = 'input, textarea, select, [contenteditable]:not([contenteditable="false"]), [role="textbox"]';
13
+ /** Modifier spellings meaning the platform's primary modifier: Command on Apple, Control elsewhere. */
14
+ const MOD_TOKENS = new Set(["mod"]);
15
+ /** Modifier spellings meaning the Control key itself, on every platform. */
16
+ const CTRL_TOKENS = new Set(["ctrl", "control"]);
17
+ /** Modifier spellings meaning the Command (Meta) key itself. */
18
+ const META_TOKENS = new Set(["cmd", "command", "meta"]);
19
+ /** Modifier spellings meaning Alt, which Apple keyboards print as Option. */
20
+ const ALT_TOKENS = new Set(["alt", "option"]);
21
+ /** Short spellings of a named key, mapped to the `KeyboardEvent.key` value they stand for. */
22
+ const KEY_ALIASES = { esc: "escape" };
23
+ /** The glyph an Apple keyboard prints on each modifier and named key. */
24
+ const APPLE_GLYPHS = {
25
+ mod: "⌘",
26
+ cmd: "⌘",
27
+ command: "⌘",
28
+ meta: "⌘",
29
+ shift: "⇧",
30
+ alt: "⌥",
31
+ option: "⌥",
32
+ ctrl: "⌃",
33
+ control: "⌃",
34
+ enter: "↵",
35
+ esc: "esc",
36
+ escape: "esc",
37
+ };
38
+ /** The spelled-out name every other keyboard prints on each modifier and named key. */
39
+ const OTHER_GLYPHS = {
40
+ mod: "Ctrl",
41
+ cmd: "Meta",
42
+ command: "Meta",
43
+ meta: "Meta",
44
+ shift: "Shift",
45
+ alt: "Alt",
46
+ option: "Alt",
47
+ ctrl: "Ctrl",
48
+ control: "Ctrl",
49
+ enter: "Enter",
50
+ esc: "Esc",
51
+ escape: "Esc",
52
+ };
53
+ /**
54
+ * Splits a `+`-joined combo into its trigger key and modifiers, matching modifier names
55
+ * case-insensitively. Unknown tokens before the trigger are ignored.
56
+ *
57
+ * @param combo The combo as written, e.g. `"mod+shift+k"`, `"escape"`, `"?"`.
58
+ * @returns The trigger key and the modifier flags {@link matchesKeyCombo} compares.
59
+ * @example parseKeyCombo("J") // { key: "J", character: true, … }
60
+ */
61
+ export function parseKeyCombo(combo) {
62
+ let tokens = combo
63
+ .split("+")
64
+ .map((token) => token.trim())
65
+ .filter((token) => token.length > 0);
66
+ let trigger = tokens.at(-1) ?? "";
67
+ let modifiers = tokens.slice(0, -1).map((token) => token.toLowerCase());
68
+ let character = modifiers.length === 0 && trigger.length === 1;
69
+ let named = trigger.toLowerCase();
70
+ return {
71
+ key: character ? trigger : (KEY_ALIASES[named] ?? named),
72
+ character,
73
+ mod: modifiers.some((token) => MOD_TOKENS.has(token)),
74
+ ctrl: modifiers.some((token) => CTRL_TOKENS.has(token)),
75
+ meta: modifiers.some((token) => META_TOKENS.has(token)),
76
+ alt: modifiers.some((token) => ALT_TOKENS.has(token)),
77
+ shift: modifiers.includes("shift"),
78
+ };
79
+ }
80
+ /**
81
+ * Whether a keystroke strikes exactly `combo`. A character combo matches the character
82
+ * typed with Control, Alt and Meta all up; any other combo matches its key in any case
83
+ * with exactly the listed modifiers held, so it never fires on a larger chord.
84
+ *
85
+ * @param event The keystroke, or any object carrying its key and modifier flags.
86
+ * @param combo The combo, as written or already parsed.
87
+ * @returns Whether the keystroke is this combo.
88
+ * @example matchesKeyCombo(event, "mod+k") // ⌘K on a Mac, Ctrl+K elsewhere
89
+ */
90
+ export function matchesKeyCombo(event, combo) {
91
+ let parsed = typeof combo === "string" ? parseKeyCombo(combo) : combo;
92
+ if (parsed.key === "")
93
+ return false;
94
+ if (parsed.character) {
95
+ return event.key === parsed.key && !event.ctrlKey && !event.altKey && !event.metaKey;
96
+ }
97
+ if (event.key.toLowerCase() !== parsed.key)
98
+ return false;
99
+ if (event.altKey !== parsed.alt || event.shiftKey !== parsed.shift)
100
+ return false;
101
+ if (parsed.mod) {
102
+ return (event.ctrlKey || event.metaKey) && (!parsed.ctrl || event.ctrlKey);
103
+ }
104
+ return event.ctrlKey === parsed.ctrl && event.metaKey === parsed.meta;
105
+ }
106
+ /**
107
+ * The key caps a hint prints for `combo`, one per key in press order, in the glyphs of
108
+ * the keyboard in front of the reader. A bare character prints as written, since its case
109
+ * is the binding; a key inside a chord prints upper-cased, the way a key cap shows it.
110
+ *
111
+ * @param combo The combo as written, e.g. `"mod+shift+z"`.
112
+ * @param apple Whether the reader's keyboard carries the Apple modifier glyphs.
113
+ * @returns The caps to render, each already the glyph to print.
114
+ * @example keyComboGlyphs("mod+k", true) // ["⌘", "K"]
115
+ * @example keyComboGlyphs("mod+k", false) // ["Ctrl", "K"]
116
+ */
117
+ export function keyComboGlyphs(combo, apple) {
118
+ let glyphs = apple ? APPLE_GLYPHS : OTHER_GLYPHS;
119
+ let tokens = combo
120
+ .split("+")
121
+ .map((token) => token.trim())
122
+ .filter((token) => token.length > 0);
123
+ if (tokens.length === 1 && tokens[0]?.length === 1)
124
+ return tokens;
125
+ return tokens.map((token) => {
126
+ let named = glyphs[token.toLowerCase()];
127
+ return named ?? (token.length === 1 ? token.toUpperCase() : token);
128
+ });
129
+ }
130
+ /**
131
+ * Whether a keystroke was aimed at a field the reader is typing in, where a bare letter
132
+ * shortcut would swallow the letter.
133
+ *
134
+ * @param target The keystroke's target.
135
+ * @returns Whether the target is, or sits inside, an editable control.
136
+ */
137
+ export function isTypingTarget(target) {
138
+ if (target === null || typeof Element === "undefined" || !(target instanceof Element)) {
139
+ return false;
140
+ }
141
+ return target.closest(TYPING_TARGET_SELECTOR) !== null;
142
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdxc/ui",
3
- "version": "2026.10.8",
3
+ "version": "2026.10.10",
4
4
  "description": "Styled, accessible remix/component components rendered as server HTML",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  "@sdxc/u": "2026.10.2",
22
22
  "remix": "3.0.0"
23
23
  },
24
- "gitHead": "7641f481daf6aab5fecfd486c9478ec95aa532c5",
24
+ "gitHead": "b61f19c59866708a2d89a5a8f4655ebbc16941b0",
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
package/src/reset.css CHANGED
@@ -2,19 +2,21 @@
2
2
  * Base reset: border-box sizing, zeroed margins/padding,
3
3
  * borders reset to "0 solid" so bare border-widths work later, the theme's
4
4
  * sans font stack applied once at the document root for every element to
5
- * inherit, form controls that inherit font/color/line-height, transparent
6
- * button/input backgrounds with a sensible cursor, block-level media, the theme's
7
- * focus ring for keyboard focus, and the rest of the usual list/table/[hidden]
8
- * normalizations.
5
+ * inherit, MathML drawn in the system's math font, form controls that inherit
6
+ * font/color/line-height, transparent button/input backgrounds with a sensible
7
+ * cursor, block-level media, the theme's focus ring for keyboard focus, and the
8
+ * rest of the usual list/table/[hidden] normalizations.
9
9
  *
10
10
  * Every selector is wrapped in :where(...) so the whole file carries zero
11
11
  * specificity and can never beat a component's own css() rules.
12
12
  *
13
13
  * Deliberate exemption: this reset does NOT touch the user-agent styles that
14
- * <dialog> and [popover] depend on. ::backdrop is left alone entirely, and
14
+ * <dialog>, [popover] and MathML depend on. ::backdrop is left alone entirely,
15
15
  * dialog/[popover] are excluded from the margin reset so their default
16
- * `margin: auto` centering survives untouched. Overlay components own the
17
- * rest of their presentation explicitly instead of fighting the reset.
16
+ * `margin: auto` centering survives untouched, and everything inside <math>
17
+ * keeps the padding that spaces matrix cells and fraction bars. Overlay
18
+ * components own the rest of their presentation explicitly instead of
19
+ * fighting the reset.
18
20
  */
19
21
 
20
22
  @layer base, rmx;
@@ -27,7 +29,7 @@
27
29
  border: 0 solid;
28
30
  }
29
31
 
30
- :where(:not(dialog, [popover])),
32
+ :where(:not(dialog, [popover], math *)),
31
33
  :where(*)::before,
32
34
  :where(*)::after {
33
35
  margin: 0;
@@ -42,6 +44,14 @@
42
44
  -webkit-tap-highlight-color: transparent;
43
45
  }
44
46
 
47
+ /*
48
+ * Stretchy fences and big operators need a font with an OpenType MATH table;
49
+ * the operating systems ship one each, named ahead of the generic family.
50
+ */
51
+ :where(math) {
52
+ font-family: "STIX Two Math", "Cambria Math", math;
53
+ }
54
+
45
55
  :where(hr) {
46
56
  height: 0;
47
57
  color: inherit;