@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 +101 -0
- package/README.md +329 -0
- package/dist/css-anchor-positioning-fn-hFYJeBk4.js +6371 -0
- package/dist/rc-common.js +1760 -0
- package/dist/rc-common.umd.cjs +31 -0
- package/dist/types/ActiveDescendantController.d.ts +86 -0
- package/dist/types/AnchorController.d.ts +113 -0
- package/dist/types/DragController.d.ts +46 -0
- package/dist/types/DragGestureController.d.ts +110 -0
- package/dist/types/ItemsCollectionController.d.ts +119 -0
- package/dist/types/KeyboardInteractionDirective.d.ts +32 -0
- package/dist/types/KeyboardNavigationDirective.d.ts +67 -0
- package/dist/types/MouseMoveDirective.d.ts +42 -0
- package/dist/types/MutationObserverController.d.ts +30 -0
- package/dist/types/NavigationIndicatorController.d.ts +33 -0
- package/dist/types/RafScheduler.d.ts +16 -0
- package/dist/types/ResizeController.d.ts +134 -0
- package/dist/types/RovingTabIndexMixin.d.ts +58 -0
- package/dist/types/ScrollObserverController.d.ts +61 -0
- package/dist/types/TypeaheadController.d.ts +31 -0
- package/dist/types/clickDelegate.d.ts +116 -0
- package/dist/types/findNearestScrollAncestor.d.ts +9 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/isFocusable.d.ts +10 -0
- package/dist/types/nativeChild.d.ts +54 -0
- package/dist/types/sliderUtils.d.ts +12 -0
- package/dist/types/snapUtils.d.ts +10 -0
- package/dist/types/visualViewport.d.ts +21 -0
- package/package.json +60 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
export type ResizeDirection = 'none' | 'both' | 'horizontal' | 'vertical';
|
|
3
|
+
type ResizeEdge = 'n' | 's' | 'e' | 'w' | 'ne' | 'nw' | 'se' | 'sw';
|
|
4
|
+
export type ResizeOrigin = '' | 'top' | 'right' | 'bottom' | 'left' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
5
|
+
export interface ResizeLifecycleDetail {
|
|
6
|
+
edge: ResizeEdge;
|
|
7
|
+
inputType: 'pointer' | 'keyboard';
|
|
8
|
+
startWidth: number;
|
|
9
|
+
startHeight: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
deltaX: number;
|
|
13
|
+
deltaY: number;
|
|
14
|
+
/** Recent horizontal pointer velocity in pixels per second. */
|
|
15
|
+
velocityX: number;
|
|
16
|
+
/** Recent vertical pointer velocity in pixels per second. */
|
|
17
|
+
velocityY: number;
|
|
18
|
+
}
|
|
19
|
+
export interface ResizeOptions {
|
|
20
|
+
/** The element to resize. Its `width` / `height` (and `left` / `top` for opposite edges) styles are updated. */
|
|
21
|
+
target: Element;
|
|
22
|
+
/** Which edges are resizable, mirroring CSS `resize` values. Defaults to `'none'`. */
|
|
23
|
+
direction?: ResizeDirection;
|
|
24
|
+
/** Custom resize handle element. If omitted, edge detection on `target` is used. */
|
|
25
|
+
handle?: Element | null;
|
|
26
|
+
/** Origin used for an explicit handle, or to constrain edge hit-testing. Empty preserves free edge detection. */
|
|
27
|
+
origin?: ResizeOrigin;
|
|
28
|
+
/** Edge hit-test thickness in px (straddles the edge, inside + outside). Defaults to `8`. */
|
|
29
|
+
threshold?: number;
|
|
30
|
+
/** Bounds constraint. Defaults to `'viewport'`. */
|
|
31
|
+
bounds?: 'viewport' | 'parent' | Element;
|
|
32
|
+
minWidth?: number;
|
|
33
|
+
maxWidth?: number;
|
|
34
|
+
minHeight?: number;
|
|
35
|
+
maxHeight?: number;
|
|
36
|
+
/** Keyboard arrow-key step in px. Shift multiplies by 10. Defaults to `4`. */
|
|
37
|
+
step?: number;
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
onResizeStart?: (detail: ResizeLifecycleDetail) => void;
|
|
40
|
+
onResize?: (detail: ResizeLifecycleDetail) => void;
|
|
41
|
+
onResizeEnd?: (detail: ResizeLifecycleDetail) => void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Pins position and size as explicit border-box pixel values.
|
|
45
|
+
*
|
|
46
|
+
* Useful before any programmatic or drag-driven layout change so that:
|
|
47
|
+
* - UA centering styles (`inset:0; margin:auto` on `<dialog>`) don't fight
|
|
48
|
+
* explicit left/top changes.
|
|
49
|
+
* - Changing width/height alone doesn't redistribute auto-margins and shift
|
|
50
|
+
* the element.
|
|
51
|
+
* - box-sizing is known, so a subsequent `style.width = rect.width` is a
|
|
52
|
+
* no-op visually.
|
|
53
|
+
*
|
|
54
|
+
* `ResizeController` calls this once per gesture; callers that mutate an
|
|
55
|
+
* element's position/size outside of an active resize gesture (e.g. a
|
|
56
|
+
* bottom sheet snapping to a point before the user has ever dragged it)
|
|
57
|
+
* should call it too, so the same box-model assumptions hold either way.
|
|
58
|
+
*/
|
|
59
|
+
export declare function pinElementBox(target: HTMLElement): DOMRect;
|
|
60
|
+
/**
|
|
61
|
+
* Makes an element resizable via pointer (edge detection) and keyboard.
|
|
62
|
+
*
|
|
63
|
+
* Supports all 8 resize handles (n, s, e, w, ne, nw, se, sw) depending on
|
|
64
|
+
* the configured `direction`. Opposite-edge resizes (w / n / nw / ne / sw)
|
|
65
|
+
* anchor the far corner and mutate `left` / `top` accordingly, mirroring
|
|
66
|
+
* OS-windowed resize semantics.
|
|
67
|
+
*
|
|
68
|
+
* On resize start the element's position and size are pinned as explicit
|
|
69
|
+
* `border-box` pixel values so UA centering styles (e.g. `inset:0; margin:auto`
|
|
70
|
+
* on `<dialog>`) cannot fight the resize calculations.
|
|
71
|
+
*/
|
|
72
|
+
export declare class ResizeController implements ReactiveController {
|
|
73
|
+
private _opts;
|
|
74
|
+
private _resizing;
|
|
75
|
+
private _startW;
|
|
76
|
+
private _startH;
|
|
77
|
+
private _startLeft;
|
|
78
|
+
private _startTop;
|
|
79
|
+
private _lastDeltaX;
|
|
80
|
+
private _lastDeltaY;
|
|
81
|
+
private _velocityX;
|
|
82
|
+
private _velocityY;
|
|
83
|
+
private _pendingEdge;
|
|
84
|
+
private _effectiveMinW;
|
|
85
|
+
private _effectiveMinH;
|
|
86
|
+
private _effectiveMaxW;
|
|
87
|
+
private _effectiveMaxH;
|
|
88
|
+
private _cornerBtn;
|
|
89
|
+
private readonly _onPointerMove;
|
|
90
|
+
private readonly _gesture;
|
|
91
|
+
private readonly _onPointerLeave;
|
|
92
|
+
private readonly _onKeyDown;
|
|
93
|
+
constructor(host: ReactiveControllerHost, options: ResizeOptions);
|
|
94
|
+
setOptions(next: Partial<ResizeOptions>): void;
|
|
95
|
+
hostConnected(): void;
|
|
96
|
+
hostDisconnected(): void;
|
|
97
|
+
private _target;
|
|
98
|
+
private _handle;
|
|
99
|
+
private _attachToHandle;
|
|
100
|
+
private _detachFromHandle;
|
|
101
|
+
private _injectCornerButton;
|
|
102
|
+
private _removeCornerButton;
|
|
103
|
+
private _cornerCursor;
|
|
104
|
+
private _edgeCursor;
|
|
105
|
+
private _handleEdge;
|
|
106
|
+
private _defaultHandleEdge;
|
|
107
|
+
private _edgeForOrigin;
|
|
108
|
+
private _edgeAllowsPointer;
|
|
109
|
+
private _detectEdge;
|
|
110
|
+
private _pinPosition;
|
|
111
|
+
private _canStartGesture;
|
|
112
|
+
private _startGestureResize;
|
|
113
|
+
private _moveGestureResize;
|
|
114
|
+
private _endGestureResize;
|
|
115
|
+
private _startResize;
|
|
116
|
+
/**
|
|
117
|
+
* Computed once per resize gesture (pointer-down or keyboard step) so the
|
|
118
|
+
* browser's enforcement of CSS min/max-width/height doesn't fight the JS
|
|
119
|
+
* math — otherwise a CSS-only max (e.g. a themed `max-block-size`) clips
|
|
120
|
+
* the rendered box while the pinned edge keeps moving, making the whole
|
|
121
|
+
* element appear to slide once dragged past its extent.
|
|
122
|
+
*/
|
|
123
|
+
private _computeEffectiveExtents;
|
|
124
|
+
private _lifecycleDetail;
|
|
125
|
+
private _handlePointerMove;
|
|
126
|
+
private _finishResize;
|
|
127
|
+
private _cancelResize;
|
|
128
|
+
private _handlePointerLeave;
|
|
129
|
+
private _handleKeyDown;
|
|
130
|
+
private _keyboardEdge;
|
|
131
|
+
private _applyDelta;
|
|
132
|
+
private _boundsRect;
|
|
133
|
+
}
|
|
134
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import { FocusableElement } from './isFocusable.js';
|
|
3
|
+
type Constructor<T = object> = new (...args: any[]) => T;
|
|
4
|
+
/**
|
|
5
|
+
* Ambient class declaration exposing the public + protected shape added by
|
|
6
|
+
* RovingTabIndexMixin. The `declare class` form (rather than an interface) is
|
|
7
|
+
* required so TypeScript can express protected members — subclasses need access
|
|
8
|
+
* to `_lastFocused` and the hook methods inside their own `_initItems` overrides.
|
|
9
|
+
*/
|
|
10
|
+
export declare class RovingTabIndexMixinBase {
|
|
11
|
+
protected _lastFocused: FocusableElement | undefined;
|
|
12
|
+
get items(): FocusableElement[];
|
|
13
|
+
get firstItem(): FocusableElement | undefined;
|
|
14
|
+
get lastItem(): FocusableElement | undefined;
|
|
15
|
+
get nextItem(): FocusableElement | undefined;
|
|
16
|
+
get previousItem(): FocusableElement | undefined;
|
|
17
|
+
focusItem(item?: FocusableElement | null): void;
|
|
18
|
+
focusItemAt(index: number): void;
|
|
19
|
+
focusFirst(): void;
|
|
20
|
+
focusLast(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the elements to register from a slot. The default collects ALL
|
|
23
|
+
* direct assigned elements; focusability is checked dynamically by the
|
|
24
|
+
* `items` getter so that elements toggling `disabled` are included or
|
|
25
|
+
* excluded without requiring a new `slotchange`.
|
|
26
|
+
*/
|
|
27
|
+
protected _collectItems(slot: HTMLSlotElement): Element[];
|
|
28
|
+
protected _handleItemFocus(e: FocusEvent): void;
|
|
29
|
+
protected _onSlotChange(e: Event): void;
|
|
30
|
+
protected _initItems(): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Mixin that adds WAI-ARIA roving-tabindex focus management to a LitElement.
|
|
34
|
+
*
|
|
35
|
+
* Provides item registration from a named slot, focus navigation helpers,
|
|
36
|
+
* tabindex synchronisation on focusin, and hook methods for subclass-specific
|
|
37
|
+
* item configuration (setting roles, collecting items from group containers, etc.).
|
|
38
|
+
*
|
|
39
|
+
* Wire the two event handlers in the subclass `render()`:
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* html`
|
|
43
|
+
* <div id="slot-wrap" @focusin=${this._handleItemFocus}>
|
|
44
|
+
* <slot @slotchange=${this._onSlotChange}></slot>
|
|
45
|
+
* </div>
|
|
46
|
+
* `
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* class MyList extends RovingTabIndexMixin(LitElement) {
|
|
51
|
+
* protected override _initItems() {
|
|
52
|
+
* super._initItems(); // sets tabindex
|
|
53
|
+
* this.items.forEach(el => el.setAttribute('role', 'option'));
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
*/
|
|
57
|
+
export declare function RovingTabIndexMixin<T extends Constructor<LitElement>>(Base: T): T & Constructor<RovingTabIndexMixinBase>;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
export type ScrollObserverTarget = Element | Document | Window;
|
|
3
|
+
/**
|
|
4
|
+
* @callback ScrollObserverChangeCB
|
|
5
|
+
* @param scrolled - whether the target is scrolled past the threshold
|
|
6
|
+
* @param scrollTop - the scroll offset read on the last evaluated frame
|
|
7
|
+
*/
|
|
8
|
+
export type ScrollObserverChangeCB = (scrolled: boolean, scrollTop: number) => void;
|
|
9
|
+
/**
|
|
10
|
+
* @callback ScrollObserverScrollCB
|
|
11
|
+
* @param scrollTop - current scroll offset
|
|
12
|
+
* @param delta - change from the previously evaluated scroll offset
|
|
13
|
+
*/
|
|
14
|
+
export type ScrollObserverScrollCB = (scrollTop: number, delta: number) => void;
|
|
15
|
+
export interface ScrollObserverOptions {
|
|
16
|
+
/** The scroll container to observe. Accepts an element reference or getter. */
|
|
17
|
+
target: ScrollObserverTarget | (() => ScrollObserverTarget | null) | null;
|
|
18
|
+
/** Scroll offset in px past which `scrolled` becomes true (strict `>`). Defaults to `4`. */
|
|
19
|
+
threshold?: number;
|
|
20
|
+
/** Invoked only when the boolean state crosses the threshold. */
|
|
21
|
+
onChange?: ScrollObserverChangeCB;
|
|
22
|
+
/** Invoked on every evaluated scroll event, including the initial attach. */
|
|
23
|
+
onScroll?: ScrollObserverScrollCB;
|
|
24
|
+
/** When true, detaches the listener entirely (e.g. host-controlled state). */
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Observes a scroll container and tracks whether it is scrolled past a
|
|
29
|
+
* threshold, for scroll-driven UI state such as app-bar elevation.
|
|
30
|
+
*
|
|
31
|
+
* Uses a single passive scroll listener evaluated synchronously per event;
|
|
32
|
+
* browsers already coalesce scroll events to one per frame per target, and
|
|
33
|
+
* the evaluation is a scroll-offset read plus a boolean compare. `onChange`
|
|
34
|
+
* fires only when the boolean state flips, including immediately on attach
|
|
35
|
+
* when the target mounts already scrolled (bfcache restore, fragment
|
|
36
|
+
* navigation).
|
|
37
|
+
*
|
|
38
|
+
* A null or missing target is silently inert; the controller never throws.
|
|
39
|
+
*/
|
|
40
|
+
export declare class ScrollObserverController implements ReactiveController {
|
|
41
|
+
private _host;
|
|
42
|
+
private _opts;
|
|
43
|
+
/** Target resolved at attach time, so detach unsubscribes the right node. */
|
|
44
|
+
private _attached;
|
|
45
|
+
private _scrolled;
|
|
46
|
+
private _lastScrollTop;
|
|
47
|
+
private readonly _onScroll;
|
|
48
|
+
constructor(host: ReactiveControllerHost, options: ScrollObserverOptions);
|
|
49
|
+
/** Whether the observed target is currently scrolled past the threshold. */
|
|
50
|
+
get scrolled(): boolean;
|
|
51
|
+
/** Reconfigure the controller: detaches, merges options, and reattaches. */
|
|
52
|
+
setOptions(next: Partial<ScrollObserverOptions>): void;
|
|
53
|
+
hostConnected(): void;
|
|
54
|
+
hostDisconnected(): void;
|
|
55
|
+
private _resolveTarget;
|
|
56
|
+
private _attach;
|
|
57
|
+
private _detach;
|
|
58
|
+
private _scrollTop;
|
|
59
|
+
private _evaluate;
|
|
60
|
+
}
|
|
61
|
+
export default ScrollObserverController;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface TypeaheadControllerOptions<T> {
|
|
2
|
+
/** Items searched by typeahead. */
|
|
3
|
+
items: () => readonly T[];
|
|
4
|
+
/** Text used for matching each item. */
|
|
5
|
+
text: (item: T) => string;
|
|
6
|
+
/** Called with the matched item and index. */
|
|
7
|
+
onMatch: (item: T, index: number) => void;
|
|
8
|
+
/** Search start index for the next key. Defaults to `0`. */
|
|
9
|
+
startIndex?: () => number;
|
|
10
|
+
/** Buffer clear delay in milliseconds. Defaults to `500`. */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Small APG-style typeahead buffer for composite widgets.
|
|
15
|
+
*
|
|
16
|
+
* It handles printable-key buffering and timeout reset; consumers keep control
|
|
17
|
+
* of focus, active descendant, and selection behavior.
|
|
18
|
+
*/
|
|
19
|
+
export declare class TypeaheadController<T> {
|
|
20
|
+
private _buffer;
|
|
21
|
+
private _timer;
|
|
22
|
+
private readonly _options;
|
|
23
|
+
constructor(options: TypeaheadControllerOptions<T>);
|
|
24
|
+
get buffer(): string;
|
|
25
|
+
reset(): void;
|
|
26
|
+
handleKeydown(event: KeyboardEvent): boolean;
|
|
27
|
+
search(char: string): T | null;
|
|
28
|
+
private _scheduleReset;
|
|
29
|
+
private _clearTimer;
|
|
30
|
+
}
|
|
31
|
+
export default TypeaheadController;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Descendants a click delegate treats as already self-sufficiently
|
|
4
|
+
* interactive. A click that lands on, or inside, one of these is left
|
|
5
|
+
* alone — the descendant already handles its own click (natively, or via
|
|
6
|
+
* its own listener), so forwarding it too would double-handle it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_INTERACTIVE_SELECTOR: string;
|
|
9
|
+
export interface InteractiveDescendantOptions {
|
|
10
|
+
/** Selector for descendants that already handle their own clicks. */
|
|
11
|
+
interactiveSelector?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* True when `event`'s composed path already passes through an interactive
|
|
15
|
+
* descendant of `host` before reaching `host` itself.
|
|
16
|
+
*
|
|
17
|
+
* Walking `composedPath()` (rather than `event.target`) is what makes this
|
|
18
|
+
* shadow-DOM-safe: a click inside a slotted control composes back through
|
|
19
|
+
* the light tree the same way regardless of which shadow boundaries it
|
|
20
|
+
* crosses, so this works whether `host` renders the descendant directly or
|
|
21
|
+
* receives it through a slot.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* host.addEventListener('click', (event) => {
|
|
26
|
+
* if (!isEventFromInteractiveDescendant(event, host)) {
|
|
27
|
+
* openDetails();
|
|
28
|
+
* }
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function isEventFromInteractiveDescendant(event: Event, host: HTMLElement, options?: InteractiveDescendantOptions): boolean;
|
|
33
|
+
export interface DelegateClickOptions extends InteractiveDescendantOptions {
|
|
34
|
+
/** Skip delegation entirely, e.g. while the host is disabled. */
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Forwards `event` to `target` via a genuine `.click()` call — but only for
|
|
39
|
+
* a plain, primary-button click on `host` that hasn't already landed on one
|
|
40
|
+
* of its own interactive descendants. Returns whether it delegated.
|
|
41
|
+
*
|
|
42
|
+
* This is the "stretched link" / "block link" pattern's click-anywhere-in-
|
|
43
|
+
* the-container half, implemented at the JS layer rather than via a CSS
|
|
44
|
+
* `::after` overlay on the target itself. Reach for the CSS technique first
|
|
45
|
+
* where it's available — it keeps the container's enhancement layer
|
|
46
|
+
* entirely CSS (no JS dependency at all) and, for an anchor target,
|
|
47
|
+
* preserves modified clicks (the browser's own click lands on the real
|
|
48
|
+
* anchor). It doesn't fit every shadow-DOM host, though: an overlay
|
|
49
|
+
* anchored to a slotted element's own containing block can end up scoped to
|
|
50
|
+
* whatever shadow-internal wrapper establishes that block (not the host you
|
|
51
|
+
* meant to fill), and clipped by any `overflow` on an ancestor between the
|
|
52
|
+
* two — both true of `rc-list-item`'s content region, which needs its own
|
|
53
|
+
* `overflow: hidden` for label truncation. This function is for exactly
|
|
54
|
+
* that case: a host that can't offer a working CSS overlay for its slotted
|
|
55
|
+
* content.
|
|
56
|
+
*
|
|
57
|
+
* Two things it deliberately can never do, both for the same underlying
|
|
58
|
+
* reason: `.click()` and dispatched events are untrusted
|
|
59
|
+
* (`Event.isTrusted === false`), and browsers restrict trusted-only
|
|
60
|
+
* behavior to genuine, direct clicks.
|
|
61
|
+
* - Forward a modified click. Ctrl/Cmd/Shift/Alt or non-primary clicks may
|
|
62
|
+
* invoke alternate browser or application behavior that cannot survive a
|
|
63
|
+
* synthetic `.click()`. They are excluded rather than silently degraded
|
|
64
|
+
* into an unintended plain activation. A modifier-clicking user gets
|
|
65
|
+
* nothing from the host's dead space and full native behavior from
|
|
66
|
+
* clicking the target directly — the honest degradation, not a broken one.
|
|
67
|
+
* - Make `target` itself keyboard-reachable. `target` needs its own
|
|
68
|
+
* tab stop regardless (a native `<a>`/`<button>`) — this only extends
|
|
69
|
+
* *pointer* reach, the same as the CSS technique would.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* host.addEventListener('click', (event) => {
|
|
74
|
+
* delegateClickTo(event, host, host.querySelector(':scope > a[href]'));
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function delegateClickTo(event: MouseEvent, host: HTMLElement, target: HTMLElement | null | undefined, options?: DelegateClickOptions): boolean;
|
|
79
|
+
export interface ClickDelegateControllerOptions extends InteractiveDescendantOptions {
|
|
80
|
+
/** Resolves the element to forward qualifying host clicks to. */
|
|
81
|
+
target: () => HTMLElement | null | undefined;
|
|
82
|
+
/** Skip delegation entirely, e.g. while the host is disabled. */
|
|
83
|
+
disabled?: () => boolean;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Wires {@link delegateClickTo} to a host's own clicks for the lifetime of
|
|
87
|
+
* its connection — the ergonomic entry point for a `LitElement` host; call
|
|
88
|
+
* {@link delegateClickTo} directly outside a `ReactiveController` context.
|
|
89
|
+
*
|
|
90
|
+
* `target` and `disabled` are getters, not static values, so a host can
|
|
91
|
+
* resolve its target dynamically (an `action-target` id-ref looked up by
|
|
92
|
+
* attribute, a structural query for a designated child, one that only
|
|
93
|
+
* matters once some other condition is met) without re-constructing the
|
|
94
|
+
* controller.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* class ActionRow extends LitElement {
|
|
99
|
+
* constructor() {
|
|
100
|
+
* super();
|
|
101
|
+
* new ClickDelegateController(this, {
|
|
102
|
+
* target: () => this.querySelector<HTMLElement>(':scope > a[href]'),
|
|
103
|
+
* });
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare class ClickDelegateController implements ReactiveController {
|
|
109
|
+
private readonly _host;
|
|
110
|
+
private readonly _options;
|
|
111
|
+
constructor(host: ReactiveControllerHost & HTMLElement, options: ClickDelegateControllerOptions);
|
|
112
|
+
hostConnected(): void;
|
|
113
|
+
hostDisconnected(): void;
|
|
114
|
+
private readonly _handleClick;
|
|
115
|
+
}
|
|
116
|
+
export default ClickDelegateController;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walks up the DOM from `el` and returns the first ancestor whose computed
|
|
3
|
+
* `overflow` or `overflow-y` is `auto` or `scroll`. Falls back to
|
|
4
|
+
* `document.scrollingElement` (the root scroller) when no ancestor qualifies.
|
|
5
|
+
*
|
|
6
|
+
* Start the walk from `el.parentElement` when the element itself should not
|
|
7
|
+
* be considered (e.g. a FAB looking for its containing scroll context).
|
|
8
|
+
*/
|
|
9
|
+
export declare function findNearestScrollAncestor(el: Element): Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from './ActiveDescendantController.js';
|
|
2
|
+
export * from './clickDelegate.js';
|
|
3
|
+
export * from './ItemsCollectionController.js';
|
|
4
|
+
export * from './KeyboardInteractionDirective.js';
|
|
5
|
+
export * from './KeyboardNavigationDirective.js';
|
|
6
|
+
export * from './MouseMoveDirective.js';
|
|
7
|
+
export * from './DragController.js';
|
|
8
|
+
export * from './DragGestureController.js';
|
|
9
|
+
export * from './ResizeController.js';
|
|
10
|
+
export * from './AnchorController.js';
|
|
11
|
+
export * from './ScrollObserverController.js';
|
|
12
|
+
export * from './MutationObserverController.js';
|
|
13
|
+
export * from './NavigationIndicatorController.js';
|
|
14
|
+
export * from './RafScheduler.js';
|
|
15
|
+
export * from './TypeaheadController.js';
|
|
16
|
+
export * from './visualViewport.js';
|
|
17
|
+
export * from './findNearestScrollAncestor.js';
|
|
18
|
+
export * from './isFocusable.js';
|
|
19
|
+
export * from './nativeChild.js';
|
|
20
|
+
export * from './RovingTabIndexMixin.js';
|
|
21
|
+
export * from './sliderUtils.js';
|
|
22
|
+
export * from './snapUtils.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type FocusableElement = HTMLAnchorElement | HTMLAreaElement | HTMLButtonElement | HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if `el` is a natively focusable element or a custom element
|
|
4
|
+
* that opts in to keyboard navigation via `tabindex`.
|
|
5
|
+
*
|
|
6
|
+
* Note: does not check `tabindex >= 0` because rc-common components mutate
|
|
7
|
+
* tabindex values during roving-tabindex management — any `tabindex` attribute
|
|
8
|
+
* presence is sufficient signal.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isFocusable(el?: Element | null): el is FocusableElement;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
export type NativeChildHost = ReactiveControllerHost & Element;
|
|
3
|
+
export interface MissingDirectChildWarningOptions {
|
|
4
|
+
/** Selector scoped to direct children, such as `:scope > button`. */
|
|
5
|
+
selector: string;
|
|
6
|
+
/** Minimum matching child count required before no warning is emitted. Defaults to `1`. */
|
|
7
|
+
minimum?: number;
|
|
8
|
+
/** Human-readable child description used by the default warning text. */
|
|
9
|
+
childDescription?: string;
|
|
10
|
+
/** Component name used by the default warning text. Defaults to `host.localName`. */
|
|
11
|
+
hostName?: string;
|
|
12
|
+
/** Full warning message. Overrides the generated message. */
|
|
13
|
+
message?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface NativeChildControllerOptions<E extends Element> {
|
|
16
|
+
/** Selector scoped to the host's light DOM. Prefer `:scope > ...`. */
|
|
17
|
+
selector: string;
|
|
18
|
+
/** Called when the matched child changes. */
|
|
19
|
+
onChange?: (child: E | null, previous: E | null) => void;
|
|
20
|
+
/** Called when no child is found during a sync pass. */
|
|
21
|
+
onMissing?: (host: NativeChildHost) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Observe light-DOM child changes and re-sync automatically. Defaults to
|
|
24
|
+
* `false`; leave off for static direct-child checks.
|
|
25
|
+
*/
|
|
26
|
+
observe?: boolean | MutationObserverInit;
|
|
27
|
+
}
|
|
28
|
+
/** Returns the first matching child under `host`, or `null` when absent. */
|
|
29
|
+
export declare function getDirectChild<E extends Element = Element>(host: ParentNode, selector: string): E | null;
|
|
30
|
+
/** Returns all matching children under `host`. */
|
|
31
|
+
export declare function getDirectChildren<E extends Element = Element>(host: ParentNode, selector: string): E[];
|
|
32
|
+
/**
|
|
33
|
+
* Emits a standard direct-child warning when the expected child is absent.
|
|
34
|
+
* Call this from a DEV-guarded component lifecycle hook.
|
|
35
|
+
*/
|
|
36
|
+
export declare function warnMissingDirectChild(host: Element, options: MissingDirectChildWarningOptions): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Tracks a native light-DOM child and re-runs setup when it is replaced.
|
|
39
|
+
* Useful for progressive-enhancement wrappers that wire listeners to a
|
|
40
|
+
* consumer-provided native control.
|
|
41
|
+
*/
|
|
42
|
+
export declare class NativeChildController<E extends Element = Element> implements ReactiveController {
|
|
43
|
+
private _observer;
|
|
44
|
+
private _child;
|
|
45
|
+
private readonly _host;
|
|
46
|
+
private readonly _options;
|
|
47
|
+
constructor(host: NativeChildHost, options: NativeChildControllerOptions<E>);
|
|
48
|
+
get child(): E | null;
|
|
49
|
+
hostConnected(): void;
|
|
50
|
+
hostDisconnected(): void;
|
|
51
|
+
/** Re-read the child from the host and invoke `onChange` when it changes. */
|
|
52
|
+
sync(): E | null;
|
|
53
|
+
}
|
|
54
|
+
export default NativeChildController;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamps `value` to [min, max] and rounds to the nearest `step` boundary.
|
|
3
|
+
*
|
|
4
|
+
* A step of 0 or less disables snapping and returns the clamped value as-is.
|
|
5
|
+
*/
|
|
6
|
+
export declare function snapToStep(value: number, min: number, max: number, step: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* Returns `value`'s position within [min, max] as a fraction in [0, 1].
|
|
9
|
+
*
|
|
10
|
+
* Returns 0 when min === max to avoid division by zero.
|
|
11
|
+
*/
|
|
12
|
+
export declare function valueToPercent(value: number, min: number, max: number): number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Returns the index of the point nearest to a value, or -1 for an empty list. */
|
|
2
|
+
export declare function findNearestSnapIndex(points: readonly number[], value: number): number;
|
|
3
|
+
/**
|
|
4
|
+
* Returns the next point index in a direction relative to a value.
|
|
5
|
+
*
|
|
6
|
+
* Falls back to the nearest endpoint when no point remains in that direction.
|
|
7
|
+
*/
|
|
8
|
+
export declare function findNextSnapIndex(points: readonly number[], value: number, direction: -1 | 1): number;
|
|
9
|
+
/** Returns the first or last point index for a direction, or -1 when empty. */
|
|
10
|
+
export declare function findExtremeSnapIndex(points: readonly number[], direction: -1 | 1): number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Bounds of the portion of a top-level document currently visible to the user. */
|
|
2
|
+
export interface VisualViewportBounds {
|
|
3
|
+
/** Inline-start offset from the layout viewport in CSS pixels. */
|
|
4
|
+
left: number;
|
|
5
|
+
/** Block-start offset from the layout viewport in CSS pixels. */
|
|
6
|
+
top: number;
|
|
7
|
+
/** Visible inline size in CSS pixels. */
|
|
8
|
+
width: number;
|
|
9
|
+
/** Visible block size in CSS pixels. */
|
|
10
|
+
height: number;
|
|
11
|
+
/** Inline-end coordinate in layout-viewport CSS pixels. */
|
|
12
|
+
right: number;
|
|
13
|
+
/** Block-end coordinate in layout-viewport CSS pixels. */
|
|
14
|
+
bottom: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns visual-viewport bounds in layout-viewport coordinates.
|
|
18
|
+
*
|
|
19
|
+
* Falls back to the layout viewport when `VisualViewport` is unavailable.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getVisualViewportBounds($window: Window): VisualViewportBounds;
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rcarls/rc-common",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.0.0-next-20260921045401",
|
|
7
|
+
"description": "Shared controllers, directives, and DOM utilities for rc-webcomponents.",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/richardcarls/rc-webcomponents.git",
|
|
11
|
+
"directory": "packages/rc-common"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://richardcarls.github.io/rc-webcomponents/",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist/rc-common.umd.cjs",
|
|
20
|
+
"module": "./dist/rc-common.js",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/types/index.d.ts",
|
|
25
|
+
"default": "./dist/rc-common.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/types/index.d.ts",
|
|
29
|
+
"default": "./dist/rc-common.umd.cjs"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"types": "./dist/types/index.d.ts",
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc && vite build",
|
|
37
|
+
"preview": "vite preview",
|
|
38
|
+
"test:browser": "vitest --run",
|
|
39
|
+
"test:browser:chrome": "vitest --run --project=chromium",
|
|
40
|
+
"test:browser:firefox": "vitest --run --project=firefox"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@oddbird/css-anchor-positioning": "^0.7.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^25.6.0",
|
|
47
|
+
"@vitest/browser-playwright": "4.1.5",
|
|
48
|
+
"lit": "^3.0.0",
|
|
49
|
+
"playwright": "^1.56.0",
|
|
50
|
+
"rollup": "^4.60.2",
|
|
51
|
+
"typescript": "~5.9.3",
|
|
52
|
+
"vite": "^7.1.7",
|
|
53
|
+
"vite-plugin-dts": "^4.5.4",
|
|
54
|
+
"vitest": "^4.0.6",
|
|
55
|
+
"vitest-browser-lit": "^1.0.1"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"lit": "^3.0.0"
|
|
59
|
+
}
|
|
60
|
+
}
|