@rcarls/rc-common 0.0.0-next-20260921045401

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,101 @@
1
+ # @rcarls/rc-common
2
+
3
+ ## 0.0.0-next-20260921045401
4
+
5
+ ### Minor Changes
6
+
7
+ - 4341311: Add reusable fullscreen dialogs and declarative dialog popup mode to `rc-select` and
8
+ `rc-combobox`. Dialog selection and creation are staged until Done, while close and Escape
9
+ discard the draft. Fullscreen surfaces follow the visual viewport under browser zoom and
10
+ software keyboards, and anchored popups now clamp to the visual viewport.
11
+
12
+ ### Patch Changes
13
+
14
+ - 50d5610: Stop anchor-positioned popups from polling layout on every animation frame while idle. Geometry
15
+ is now checked during a bounded settling window and restarted by resize, scroll, visibility, or
16
+ relevant element changes.
17
+
18
+ ## 0.6.0
19
+
20
+ ### Minor Changes
21
+
22
+ - 6683eb9: Add shared, lifecycle-safe click delegation and let interactive list items
23
+ forward plain surface clicks to same-root native action targets while
24
+ preserving nested and modified clicks.
25
+
26
+ ### Patch Changes
27
+
28
+ - ee7ba6c: Keep resize pinning, drag origins, and snapped bottom sheets correctly
29
+ positioned when a layout-containing ancestor establishes a non-viewport
30
+ containing block. Report animated snap changes only after the sheet settles so
31
+ consumers can defer discrete content and accessibility state changes until the
32
+ surface motion completes. Expose resize-start timing so content can be prepared
33
+ before an interactive expansion reveals it.
34
+ - 30eb232: Add icon-only activation-area sizing and Material icon-button variants. Align menu
35
+ selection and submenu affordances, and keep anchored popups within the viewport
36
+ across native and fallback positioning.
37
+
38
+ ## 0.5.0
39
+
40
+ ### Minor Changes
41
+
42
+ - 689340c: Remove pre-1.0 deprecated APIs: the boolean `keyNavigation` option, `rc-disclosure.fragment`,
43
+ `rc-textarea.listNumbers`, `rc-textarea.label`, and `decorationsFromHtml`.
44
+
45
+ ### Patch Changes
46
+
47
+ - 4ae2ef0: Fix `ItemsCollectionController` (used by `rc-listbox`, and transitively by
48
+ `rc-select` and `rc-combobox`) toggling an option on the first touch contact
49
+ instead of letting a scrollable options list scroll. Touch activation now
50
+ waits for `pointerup` within a 10px tap threshold; a larger move cancels the
51
+ pending activation. Mouse and pen still activate on `pointerdown`.
52
+
53
+ ## 0.4.2
54
+
55
+ ## 0.4.1
56
+
57
+ ## 0.4.0
58
+
59
+ ### Minor Changes
60
+
61
+ - ccca8e2: Add navigation bar and rail packages with shared active-indicator positioning.
62
+ - 037b1b3: Add shared drag gesture measurement and numeric snap helpers, migrate bottom
63
+ sheet settling to the shared velocity lifecycle, and add anchored settling and
64
+ swipe-to-collapse behavior to splitters.
65
+
66
+ ### Patch Changes
67
+
68
+ - e57277f: Add Material 3 search-view, fixed-pane splitter, dialog scrim, and resize enhancements.
69
+
70
+ `rc-search-bar` now supports `variant="view"`, controlled/default open state, search-view methods, a rich `suggestions` slot, and datalist-derived text suggestions. `rc-splitter` adds `mode="fixed"` for clampable pixel primary panes. `rc-common` now honors CSS max-size constraints during resize gestures, and `rc-dialog` exposes a scrim token plus resize handle/origin hooks used by themed surfaces.
71
+
72
+ ## 0.3.2
73
+
74
+ ### Patch Changes
75
+
76
+ - 88b4086: Fix Firefox for Android bug: `<label>`-wrapped multiple selects [Bugzilla 1475723](https://bugzilla.mozilla.org/show_bug.cgi?id=1475723)
77
+
78
+ ## 0.3.1
79
+
80
+ ## 0.3.0
81
+
82
+ ### Breaking
83
+
84
+ - Remove `useInteractionModeAttr` from `KeyNavigationOptions`; use `keyInteraction` with `keyNavigation` when keyboard interaction state is needed.
85
+
86
+ ### Added
87
+
88
+ - Add native-child, observer, animation-frame, typeahead, and scroll-ancestor utilities.
89
+ - Add typed listbox action option helpers and `ItemsCollectionController`.
90
+ - Add `KeyboardInteractionDirective` with `keyInteraction` and `KeyInteractionOptions` exports.
91
+
92
+ ### Changed
93
+
94
+ - Add separator-role keyboard support and large-step arrow actions to keyboard navigation.
95
+ - Update package metadata, README intro, and docs links.
96
+
97
+ ### Migration
98
+
99
+ - Pair `keyInteraction` with `keyNavigation` anywhere downstream code previously relied on `useInteractionModeAttr`.
100
+
101
+ ## 0.2.0
package/README.md ADDED
@@ -0,0 +1,329 @@
1
+ # `@rcarls/rc-common`
2
+
3
+ Shared controllers, directives, and DOM utilities for `rc-webcomponents`.
4
+
5
+ Docs: [https://richardcarls.github.io/rc-webcomponents/](https://richardcarls.github.io/rc-webcomponents/).
6
+
7
+ ---
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @rcarls/rc-common
13
+ ```
14
+
15
+ ## Import
16
+
17
+ ```js
18
+ import {
19
+ AnchorController,
20
+ DragController,
21
+ DragGestureController,
22
+ ItemsCollectionController,
23
+ NavigationIndicatorController,
24
+ ResizeController,
25
+ } from '@rcarls/rc-common';
26
+ import {
27
+ ActiveDescendantController,
28
+ ClickDelegateController,
29
+ MutationObserverController,
30
+ RafScheduler,
31
+ ScrollObserverController,
32
+ TypeaheadController,
33
+ } from '@rcarls/rc-common';
34
+ import { RovingTabIndexMixin, keyInteraction, keyNavigation, mouseMove } from '@rcarls/rc-common';
35
+ import {
36
+ delegateClickTo,
37
+ DEFAULT_INTERACTIVE_SELECTOR,
38
+ findExtremeSnapIndex,
39
+ findNearestScrollAncestor,
40
+ findNearestSnapIndex,
41
+ findNextSnapIndex,
42
+ getDirectChild,
43
+ getDirectChildren,
44
+ isEventFromInteractiveDescendant,
45
+ isFocusable,
46
+ pinElementBox,
47
+ snapToStep,
48
+ valueToPercent,
49
+ warnMissingDirectChild,
50
+ } from '@rcarls/rc-common';
51
+ ```
52
+
53
+ All exports are tree-shakeable (`sideEffects: false`).
54
+
55
+ ## Export inventory
56
+
57
+ Check this inventory before adding package-local interaction or DOM utility code.
58
+
59
+ | Export | Use for |
60
+ | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
61
+ | `ActiveDescendantController` | Managing `aria-activedescendant` virtual focus in listbox / combobox patterns |
62
+ | `AnchorController` | Positioning floating UI relative to an anchor with native CSS anchor positioning and polyfill fallback |
63
+ | `ClickDelegateController` / `delegateClickTo` | Extending plain pointer clicks on a host to a same-root native anchor or button target |
64
+ | `DragController` | Pointer and keyboard drag-to-move behavior |
65
+ | `DragGestureController` | Single-pointer activation, capture, deltas, duration, and recent velocity |
66
+ | `ItemsCollectionController` | Filtering selectable and action items while preserving their distinct option kinds |
67
+ | `KeyboardInteractionDirective` / `keyInteraction` | Tracking pointer vs keyboard interaction mode on a rendered element |
68
+ | `KeyboardNavigationDirective` / `keyNavigation` | Mapping APG arrow-key models to navigation actions |
69
+ | `MutationObserverController` | Lifecycle-safe `MutationObserver` wiring for light-DOM or shadow-DOM changes |
70
+ | `MouseMoveDirective` / `mouseMove` | Pointermove callbacks while a pointer drag is active |
71
+ | `NavigationIndicatorController` | Positioning a shared visual indicator against the current navigation item |
72
+ | `NativeChildController`, `getDirectChild`, `getDirectChildren`, `warnMissingDirectChild` | Finding, validating, and tracking consumer-provided native light-DOM children |
73
+ | `RafScheduler` | Coalescing repeated work into one animation frame and canceling on disconnect |
74
+ | `ResizeController` | Pointer and keyboard resize behavior |
75
+ | `RovingTabIndexMixin` | Roving tabindex for components whose child controls receive real DOM focus |
76
+ | `ScrollObserverController` | Scroll threshold and delta observation for scroll-driven component state |
77
+ | `TypeaheadController` | Printable-key buffering for composite widget typeahead |
78
+ | `findNearestScrollAncestor` | Locating the nearest scrollable ancestor for scroll-driven behavior |
79
+ | `findNearestSnapIndex`, `findNextSnapIndex`, `findExtremeSnapIndex` | Choosing numeric anchor indices without assigning component meaning |
80
+ | `isFocusable` | Filtering focusable items for keyboard navigation |
81
+ | `isEventFromInteractiveDescendant` | Detecting composed clicks already owned by a nested interactive control |
82
+ | `DEFAULT_INTERACTIVE_SELECTOR` | Reusing the default selector used to identify nested interactive descendants |
83
+ | `pinElementBox` | Converting an element's rendered box into explicit inline geometry for resize interactions |
84
+ | `snapToStep`, `valueToPercent` | Slider and range-slider numeric helpers |
85
+
86
+ ---
87
+
88
+ ## API
89
+
90
+ ### `DragGestureController`
91
+
92
+ A low-level `ReactiveController` for one primary pointer. Dedicated handles can
93
+ activate immediately, while scrollable surfaces can wait for axis intent and
94
+ reject movement dominated by the other axis. Lifecycle details include
95
+ coordinates, cumulative deltas, duration, pointer metadata, and velocity from a
96
+ 100 ms recent-sample window.
97
+
98
+ The controller owns pointer capture and cleanup, but leaves state changes,
99
+ thresholds, logical direction, snapping, and action confirmation to its
100
+ consumer.
101
+
102
+ ### `DragController`
103
+
104
+ A `ReactiveController` that adds pointer-driven drag-to-move to any `LitElement` host. It binds
105
+ to a configurable handle and constrains movement to the viewport, parent, or a custom bounding
106
+ element.
107
+
108
+ ```ts
109
+ import { LitElement } from 'lit';
110
+ import { DragController } from '@rcarls/rc-common';
111
+
112
+ class MyPanel extends LitElement {
113
+ private _drag = new DragController(this, {
114
+ handle: () => this.shadowRoot!.querySelector('.titlebar')!,
115
+ bounds: 'viewport', // 'viewport' | 'parent' | HTMLElement
116
+ step: 4, // px per arrow-key press; Shift = 10×
117
+ });
118
+ }
119
+ ```
120
+
121
+ The controller pins explicit `top` and `left` values on the host the first time the user drags,
122
+ clearing centering transforms that would fight manual positioning. Pointer capture provides
123
+ reliable drag-end detection across shadow boundaries.
124
+
125
+ **Keyboard:** Arrow keys move by `step` px; Shift multiplies by 10.
126
+
127
+ **Options:**
128
+
129
+ | Option | Type | Default | Description |
130
+ | -------- | --------------------------------------- | ------------ | ----------------------------- |
131
+ | `handle` | `() => HTMLElement \| null` | host element | Drag handle element or getter |
132
+ | `bounds` | `'viewport' \| 'parent' \| HTMLElement` | `'viewport'` | Movement constraint boundary |
133
+ | `step` | `number` | `4` | Arrow-key step in px |
134
+
135
+ ---
136
+
137
+ ### `ResizeController`
138
+
139
+ A `ReactiveController` that adds pointer- and keyboard-driven resizing to any `LitElement` host.
140
+ It detects the cursor relative to all eight edges and corners with a configurable threshold band.
141
+ It also injects a small keyboard-accessible handle in the bottom-right corner.
142
+
143
+ ```ts
144
+ import { LitElement } from 'lit';
145
+ import { ResizeController } from '@rcarls/rc-common';
146
+
147
+ class MyPanel extends LitElement {
148
+ private _resize = new ResizeController(this, {
149
+ threshold: 8, // edge hit-test band in px (half inside, half outside)
150
+ step: 4, // px per arrow-key press; Shift = 10×
151
+ });
152
+ }
153
+ ```
154
+
155
+ It works alongside `DragController`: `ResizeController` registers a capture-phase listener that
156
+ intercepts pointer events before the drag handler.
157
+
158
+ **Options:**
159
+
160
+ | Option | Type | Default | Description |
161
+ | ----------- | -------- | ------- | ------------------------- |
162
+ | `threshold` | `number` | `8` | Edge detection band in px |
163
+ | `step` | `number` | `4` | Arrow-key step in px |
164
+
165
+ ---
166
+
167
+ ### `AnchorController`
168
+
169
+ A `ReactiveController` that positions a floating element relative to an anchor using
170
+ [CSS Anchor Positioning](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_anchor_positioning),
171
+ with automatic fallback through
172
+ [`@oddbird/css-anchor-positioning`](https://github.com/oddbird/css-anchor-positioning).
173
+
174
+ ```ts
175
+ import { LitElement } from 'lit';
176
+ import { AnchorController } from '@rcarls/rc-common';
177
+
178
+ class MyTooltip extends LitElement {
179
+ private _anchor = new AnchorController(this, {
180
+ anchor: () => document.querySelector('#trigger')!,
181
+ floating: () => this.shadowRoot!.querySelector('#popup')!,
182
+ });
183
+ }
184
+ ```
185
+
186
+ It injects a `<style>` block into `<head>` for the `anchor-name` and `position-anchor`
187
+ declarations. It supports `@position-try` fallback blocks for automatic flip behavior in native
188
+ browsers; the polyfill does not support `position-try`.
189
+
190
+ **Options:**
191
+
192
+ | Option | Type | Description |
193
+ | -------------- | ----------------------- | ------------------------------------------------------------------ |
194
+ | `anchor` | `() => Element \| null` | The anchor element getter |
195
+ | `floating` | `() => Element \| null` | The floating element getter |
196
+ | `positionArea` | `string` | CSS `position-area` value (for example, `'block-end span-inline'`) |
197
+
198
+ ---
199
+
200
+ ### `keyNavigation` directive
201
+
202
+ An `AsyncDirective` that adds WAI-ARIA keyboard navigation to any element part. It detects the
203
+ element's `role` to choose the navigation axis and delegates action names to a callback.
204
+
205
+ ```ts
206
+ import { keyNavigation } from '@rcarls/rc-common';
207
+ import type { KeyboardNavigationAction } from '@rcarls/rc-common';
208
+
209
+ // Inside a Lit render() method:
210
+ html`
211
+ <div role="menu" ${keyNavigation(this._onNavigate, {
212
+ handleEscape: true,
213
+ handleActivate: true,
214
+ })}>
215
+ <slot></slot>
216
+ </div>
217
+ `;
218
+
219
+ private _onNavigate(action: KeyboardNavigationAction) {
220
+ switch (action) {
221
+ case 'next': this.focusNext(); break;
222
+ case 'prev': this.focusPrev(); break;
223
+ case 'start': this.focusFirst(); break;
224
+ case 'end': this.focusLast(); break;
225
+ case 'escape': this.close(); break;
226
+ case 'activate': this.activate(); break;
227
+ case 'open-to-first': this.open('first'); break;
228
+ case 'open-to-last': this.open('last'); break;
229
+ }
230
+ }
231
+ ```
232
+
233
+ Navigation axis is inferred automatically from the element's `role`:
234
+
235
+ | Role | Default axis |
236
+ | ------------------------------- | ----------------------- |
237
+ | `menu`, `listbox`, `tree` | Vertical (Up/Down) |
238
+ | `menubar`, `toolbar`, `tablist` | Horizontal (Left/Right) |
239
+ | `grid`, `treegrid` | Both |
240
+
241
+ **Options:**
242
+
243
+ | Option | Type | Default | Description |
244
+ | ---------------- | ---------------------------- | -------------- | ------------------------------------------------------------ |
245
+ | `navigationAxis` | `'horizontal' \| 'vertical'` | auto from role | Override the navigation axis |
246
+ | `handleNavAxis` | `boolean` | `true` | Respond to arrow keys on the nav axis |
247
+ | `handleOpenAxis` | `boolean` | `false` | Respond to arrow keys on the perpendicular (open/close) axis |
248
+ | `handleEscape` | `boolean` | `false` | Fire `'escape'` action on Escape key |
249
+ | `handleActivate` | `boolean` | `false` | Fire `'activate'` action on Enter/Space |
250
+
251
+ ---
252
+
253
+ ### Click delegation
254
+
255
+ `ClickDelegateController` extends plain primary clicks on a host surface to an
256
+ author-provided native anchor or button. It leaves clicks on nested interactive
257
+ content alone and rejects modifier-qualified or non-primary clicks because a
258
+ synthetic `.click()` cannot preserve alternate browser activation behavior.
259
+
260
+ ```ts
261
+ import { LitElement } from 'lit';
262
+
263
+ import { ClickDelegateController } from '@rcarls/rc-common';
264
+
265
+ class ActionRow extends LitElement {
266
+ constructor() {
267
+ super();
268
+ new ClickDelegateController(this, {
269
+ target: () => this.querySelector<HTMLElement>(':scope > a[href], :scope > button'),
270
+ disabled: () => this.hasAttribute('disabled'),
271
+ });
272
+ }
273
+ }
274
+ ```
275
+
276
+ Use `delegateClickTo()` directly for a non-Lit host. The target remains its own
277
+ keyboard tab stop; delegation extends pointer reach only.
278
+
279
+ ---
280
+
281
+ ### `mouseMove` directive
282
+
283
+ An `AsyncDirective` that fires a callback on pointer movement while a pointer drag is active. It
284
+ supports drag-to-resize handles that need continuous delta tracking while preserving the
285
+ historical `mouseMove` export name.
286
+
287
+ ```ts
288
+ import { mouseMove } from '@rcarls/rc-common';
289
+
290
+ // Inside a Lit render() method:
291
+ html`
292
+ <div id="handle" ${mouseMove(this._onDrag)}></div>
293
+ `;
294
+
295
+ private _onDrag(e: MouseEvent) {
296
+ this._resize(e.movementX, e.movementY);
297
+ }
298
+ ```
299
+
300
+ It attaches `pointerdown` to the element, captures that pointer, then listens for `pointermove`,
301
+ `pointerup`, `pointercancel`, and `lostpointercapture` on the same element for the active drag
302
+ cycle. It focuses the handle on pointerdown.
303
+
304
+ ---
305
+
306
+ ### `isFocusable`
307
+
308
+ A utility function that returns `true` if an element should participate in keyboard navigation.
309
+ It checks native element types, including `<button>`, `<input>`, and `<a href>`, plus the presence
310
+ of a `tabindex` attribute. Disabled elements are always excluded.
311
+
312
+ ```ts
313
+ import { isFocusable, type FocusableElement } from '@rcarls/rc-common';
314
+
315
+ const items = [...slot.assignedElements()].filter(isFocusable);
316
+ ```
317
+
318
+ It does **not** check whether `tabindex` is at least zero because rc-common components mutate
319
+ tabindex values during roving-tabindex management. Any `tabindex` attribute is the correct signal.
320
+
321
+ ---
322
+
323
+ ## Browser support
324
+
325
+ | Feature | Requirement |
326
+ | ------------------------------- | ------------------------------------------------------ |
327
+ | Controllers and directives | Any browser supporting Web Components + Pointer Events |
328
+ | `AnchorController` (native) | Chrome 125+, Safari 18+, Firefox (in development) |
329
+ | `AnchorController` (polyfilled) | Chrome 80+, Firefox 85+, Safari 14+ |