@rcarls/rc-common 0.6.0 → 0.7.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 (73) hide show
  1. package/CHANGELOG.md +295 -0
  2. package/README.md +148 -72
  3. package/dist/modules/ActiveDescendantController.js +89 -0
  4. package/dist/modules/AnchorController.js +317 -0
  5. package/dist/modules/ControllerEffects.js +60 -0
  6. package/dist/modules/DragController.js +128 -0
  7. package/dist/modules/DragGestureController.js +174 -0
  8. package/dist/modules/FlowController.js +35 -0
  9. package/dist/modules/ItemsCollectionController.js +233 -0
  10. package/dist/modules/KeyboardInteractionDirective.js +39 -0
  11. package/dist/modules/KeyboardNavigationDirective.js +88 -0
  12. package/dist/modules/LiveAnnouncer.js +36 -0
  13. package/dist/modules/MutationObserverController.js +30 -0
  14. package/dist/modules/NavigationIndicatorController.js +81 -0
  15. package/dist/modules/PopoverController.js +44 -0
  16. package/dist/modules/RafScheduler.js +83 -0
  17. package/dist/modules/ReorderController.js +361 -0
  18. package/dist/modules/ResizeController.js +425 -0
  19. package/dist/modules/RovingTabIndexMixin.js +87 -0
  20. package/dist/modules/ScrollObserverController.js +78 -0
  21. package/dist/modules/TypeaheadController.js +59 -0
  22. package/dist/modules/anchorPlacement.js +13 -0
  23. package/dist/modules/clickDelegate.js +31 -0
  24. package/dist/modules/cssText.js +6 -0
  25. package/dist/modules/cssTime.js +11 -0
  26. package/dist/modules/cssZoom.js +16 -0
  27. package/dist/modules/findNearestScrollAncestor.js +22 -0
  28. package/dist/modules/flow.js +94 -0
  29. package/dist/modules/isFocusable.js +6 -0
  30. package/dist/modules/localeFormat.js +38 -0
  31. package/dist/modules/messages.js +77 -0
  32. package/dist/modules/nativeChild.js +37 -0
  33. package/dist/modules/observeLocale.js +70 -0
  34. package/dist/modules/sliderUtils.js +14 -0
  35. package/dist/modules/snapUtils.js +25 -0
  36. package/dist/modules/softKeyboard.js +72 -0
  37. package/dist/modules/visualViewport.js +14 -0
  38. package/dist/rc-common.js +99 -1711
  39. package/dist/rc-common.umd.cjs +10 -26
  40. package/dist/types/AnchorController.d.ts +45 -22
  41. package/dist/types/ControllerEffects.d.ts +15 -0
  42. package/dist/types/DragController.d.ts +13 -0
  43. package/dist/types/DragGestureController.d.ts +31 -7
  44. package/dist/types/FlowController.d.ts +31 -0
  45. package/dist/types/ItemsCollectionController.d.ts +3 -2
  46. package/dist/types/KeyboardInteractionDirective.d.ts +1 -2
  47. package/dist/types/KeyboardNavigationDirective.d.ts +16 -7
  48. package/dist/types/LiveAnnouncer.d.ts +22 -0
  49. package/dist/types/MutationObserverController.d.ts +0 -1
  50. package/dist/types/NavigationIndicatorController.d.ts +1 -1
  51. package/dist/types/PopoverController.d.ts +21 -0
  52. package/dist/types/RafScheduler.d.ts +36 -1
  53. package/dist/types/ReorderController.d.ts +131 -0
  54. package/dist/types/ResizeController.d.ts +46 -0
  55. package/dist/types/ScrollObserverController.d.ts +13 -2
  56. package/dist/types/TypeaheadController.d.ts +8 -2
  57. package/dist/types/anchorPlacement.d.ts +24 -0
  58. package/dist/types/clickDelegate.d.ts +9 -56
  59. package/dist/types/cssText.d.ts +17 -0
  60. package/dist/types/cssTime.d.ts +14 -0
  61. package/dist/types/cssZoom.d.ts +12 -0
  62. package/dist/types/findNearestScrollAncestor.d.ts +3 -3
  63. package/dist/types/flow.d.ts +121 -0
  64. package/dist/types/index.d.ts +13 -1
  65. package/dist/types/localeFormat.d.ts +4 -0
  66. package/dist/types/messages.d.ts +105 -0
  67. package/dist/types/nativeChild.d.ts +0 -3
  68. package/dist/types/observeLocale.d.ts +23 -0
  69. package/dist/types/softKeyboard.d.ts +79 -0
  70. package/dist/types/visualViewport.d.ts +21 -0
  71. package/package.json +1 -4
  72. package/dist/css-anchor-positioning-fn-hFYJeBk4.js +0 -6371
  73. package/dist/types/MouseMoveDirective.d.ts +0 -42
@@ -39,7 +39,15 @@ export interface ResizeOptions {
39
39
  onResizeStart?: (detail: ResizeLifecycleDetail) => void;
40
40
  onResize?: (detail: ResizeLifecycleDetail) => void;
41
41
  onResizeEnd?: (detail: ResizeLifecycleDetail) => void;
42
+ /** Text overrides for the injected corner grip. */
43
+ messages?: Partial<ResizeMessages>;
42
44
  }
45
+ /** Text of the corner grip injected when no `handle` is given. */
46
+ export interface ResizeMessages {
47
+ /** Accessible name of the corner grip. */
48
+ grip: string;
49
+ }
50
+ export declare const DEFAULT_RESIZE_MESSAGES: Readonly<ResizeMessages>;
43
51
  /**
44
52
  * Pins position and size as explicit border-box pixel values.
45
53
  *
@@ -72,10 +80,16 @@ export declare function pinElementBox(target: HTMLElement): DOMRect;
72
80
  export declare class ResizeController implements ReactiveController {
73
81
  private _opts;
74
82
  private _resizing;
83
+ /**
84
+ * The gesture's start size and position, in the target's own CSS pixels:
85
+ * what its style lengths take, before its effective zoom.
86
+ */
75
87
  private _startW;
76
88
  private _startH;
77
89
  private _startLeft;
78
90
  private _startTop;
91
+ /** The target's effective CSS zoom for the current gesture. */
92
+ private _zoom;
79
93
  private _lastDeltaX;
80
94
  private _lastDeltaY;
81
95
  private _velocityX;
@@ -86,23 +100,55 @@ export declare class ResizeController implements ReactiveController {
86
100
  private _effectiveMaxW;
87
101
  private _effectiveMaxH;
88
102
  private _cornerBtn;
103
+ private readonly _handleEffects;
104
+ private _targetEffects;
105
+ private _positionEffects;
106
+ private _flowEffects;
107
+ private _connected;
108
+ private _disposed;
109
+ private readonly _onFlowInteraction;
89
110
  private readonly _onPointerMove;
90
111
  private readonly _gesture;
91
112
  private readonly _onPointerLeave;
92
113
  private readonly _onKeyDown;
114
+ private readonly _host;
93
115
  constructor(host: ReactiveControllerHost, options: ResizeOptions);
116
+ /** Reconfigures resize behavior, replacing bindings when the handle or target changes. */
94
117
  setOptions(next: Partial<ResizeOptions>): void;
95
118
  hostConnected(): void;
96
119
  hostDisconnected(): void;
120
+ /**
121
+ * Detaches every listener, injected grip, and handle style, then removes
122
+ * the controller (and its gesture) from the host for good. Use it to
123
+ * replace a controller when resize options change after setup.
124
+ */
125
+ dispose(): void;
97
126
  private _target;
98
127
  private _handle;
99
128
  private _attachToHandle;
129
+ private _observeFlow;
130
+ private _unobserveFlow;
131
+ /** Re-places the corner grip and re-derives handle cursors from the current flow. */
132
+ private _syncFlowStyles;
100
133
  private _detachFromHandle;
101
134
  private _injectCornerButton;
135
+ /**
136
+ * Puts the grip at the end corner, where browsers put the native resize
137
+ * grip: bottom-left in RTL and in vertical-rl.
138
+ */
139
+ private _placeCornerButton;
140
+ /** Names the grip in the target's locale; the flow observer re-runs it when `lang` changes. */
141
+ private _labelCornerButton;
102
142
  private _removeCornerButton;
103
143
  private _cornerCursor;
104
144
  private _edgeCursor;
105
145
  private _handleEdge;
146
+ /**
147
+ * The physical edges at the target's end corner, where a resize grip and
148
+ * keyboard resizing act by default: right and bottom in LTR, left in RTL
149
+ * and in vertical-rl, top where the inline axis runs bottom to top.
150
+ */
151
+ private _endEdges;
106
152
  private _defaultHandleEdge;
107
153
  private _edgeForOrigin;
108
154
  private _edgeAllowsPointer;
@@ -12,6 +12,7 @@ export type ScrollObserverChangeCB = (scrolled: boolean, scrollTop: number) => v
12
12
  * @param delta - change from the previously evaluated scroll offset
13
13
  */
14
14
  export type ScrollObserverScrollCB = (scrollTop: number, delta: number) => void;
15
+ export type ScrollObserverInitialEvaluation = 'sync' | 'frame';
15
16
  export interface ScrollObserverOptions {
16
17
  /** The scroll container to observe. Accepts an element reference or getter. */
17
18
  target: ScrollObserverTarget | (() => ScrollObserverTarget | null) | null;
@@ -21,6 +22,8 @@ export interface ScrollObserverOptions {
21
22
  onChange?: ScrollObserverChangeCB;
22
23
  /** Invoked on every evaluated scroll event, including the initial attach. */
23
24
  onScroll?: ScrollObserverScrollCB;
25
+ /** When to resolve and read the initial target. Defaults to `'sync'`. */
26
+ initialEvaluation?: ScrollObserverInitialEvaluation;
24
27
  /** When true, detaches the listener entirely (e.g. host-controlled state). */
25
28
  disabled?: boolean;
26
29
  }
@@ -33,7 +36,9 @@ export interface ScrollObserverOptions {
33
36
  * the evaluation is a scroll-offset read plus a boolean compare. `onChange`
34
37
  * fires only when the boolean state flips, including immediately on attach
35
38
  * when the target mounts already scrolled (bfcache restore, fragment
36
- * navigation).
39
+ * navigation). Set `initialEvaluation: 'frame'` to move target resolution and
40
+ * the initial scroll-offset read out of a DOM insertion task; callbacks then
41
+ * run in the next animation frame before paint.
37
42
  *
38
43
  * A null or missing target is silently inert; the controller never throws.
39
44
  */
@@ -44,7 +49,9 @@ export declare class ScrollObserverController implements ReactiveController {
44
49
  private _attached;
45
50
  private _scrolled;
46
51
  private _lastScrollTop;
52
+ private readonly _initialFrame;
47
53
  private readonly _onScroll;
54
+ private _disposed;
48
55
  constructor(host: ReactiveControllerHost, options: ScrollObserverOptions);
49
56
  /** Whether the observed target is currently scrolled past the threshold. */
50
57
  get scrolled(): boolean;
@@ -52,10 +59,14 @@ export declare class ScrollObserverController implements ReactiveController {
52
59
  setOptions(next: Partial<ScrollObserverOptions>): void;
53
60
  hostConnected(): void;
54
61
  hostDisconnected(): void;
62
+ /** Detaches the listener or pending frame and removes the controller permanently. */
63
+ dispose(): void;
55
64
  private _resolveTarget;
56
65
  private _attach;
66
+ private _attachNow;
67
+ private _queueAttach;
57
68
  private _detach;
58
69
  private _scrollTop;
59
70
  private _evaluate;
71
+ private _applyScrollTop;
60
72
  }
61
- export default ScrollObserverController;
@@ -9,12 +9,19 @@ export interface TypeaheadControllerOptions<T> {
9
9
  startIndex?: () => number;
10
10
  /** Buffer clear delay in milliseconds. Defaults to `500`. */
11
11
  timeout?: number;
12
+ /**
13
+ * Locale whose collation decides a match, such as `messagesLocale(host)`.
14
+ * Defaults to the runtime locale.
15
+ */
16
+ locale?: () => string | undefined;
12
17
  }
13
18
  /**
14
19
  * Small APG-style typeahead buffer for composite widgets.
15
20
  *
16
21
  * It handles printable-key buffering and timeout reset; consumers keep control
17
- * of focus, active descendant, and selection behavior.
22
+ * of focus, active descendant, and selection behavior. Prefixes match with an
23
+ * `Intl.Collator` at base sensitivity, so case and accents are ignored the way
24
+ * the locale ignores them: typing `e` finds `Éclair`.
18
25
  */
19
26
  export declare class TypeaheadController<T> {
20
27
  private _buffer;
@@ -28,4 +35,3 @@ export declare class TypeaheadController<T> {
28
35
  private _scheduleReset;
29
36
  private _clearTimer;
30
37
  }
31
- export default TypeaheadController;
@@ -0,0 +1,24 @@
1
+ import { Flow } from './flow.js';
2
+ /**
3
+ * A placement on a fixed physical side: what {@link resolveAnchorPlacement}
4
+ * returns after resolving an {@link AnchorPlacement} against the flow. It is
5
+ * an output only; placements are always given logically.
6
+ */
7
+ export type PhysicalAnchorPlacement = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'right' | 'right-start' | 'right-end';
8
+ /**
9
+ * Where to place the floating element relative to its anchor, in logical
10
+ * terms that follow the writing mode and direction.
11
+ *
12
+ * The side is `block-start`/`block-end` (above/below a row in horizontal text,
13
+ * to its sides in vertical text) or `inline-start`/`inline-end` (beside it
14
+ * along the reading direction, so `inline-end` opens to the left in RTL). The
15
+ * optional `-start`/`-end` suffix aligns to the start or end edge along the
16
+ * other axis, so `block-end-start` aligns right edges in RTL.
17
+ */
18
+ export type AnchorPlacement = 'block-start' | 'block-start-start' | 'block-start-end' | 'block-end' | 'block-end-start' | 'block-end-end' | 'inline-start' | 'inline-start-start' | 'inline-start-end' | 'inline-end' | 'inline-end-start' | 'inline-end-end';
19
+ /**
20
+ * Resolves a placement to a physical side and alignment for a given flow.
21
+ * The side maps through its logical axis; alignment suffixes flip where the
22
+ * cross axis runs right to left or bottom to top.
23
+ */
24
+ export declare function resolveAnchorPlacement(placement: AnchorPlacement, flow: Flow): PhysicalAnchorPlacement;
@@ -1,43 +1,16 @@
1
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 {
2
+ export interface ClickDelegateControllerOptions {
3
+ /** Resolves the element to forward qualifying host clicks to. */
4
+ target: () => HTMLElement | null | undefined;
5
+ /** Skip delegation entirely, e.g. while the host is disabled. */
6
+ disabled?: () => boolean;
10
7
  /** Selector for descendants that already handle their own clicks. */
11
8
  interactiveSelector?: string;
12
9
  }
13
10
  /**
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.
11
+ * Forwards a host's plain, primary-button clicks to a target via a genuine
12
+ * `.click()` call, for the lifetime of the host's connection, unless the
13
+ * click already landed on one of the host's own interactive descendants.
41
14
  *
42
15
  * This is the "stretched link" / "block link" pattern's click-anywhere-in-
43
16
  * the-container half, implemented at the JS layer rather than via a CSS
@@ -50,7 +23,7 @@ export interface DelegateClickOptions extends InteractiveDescendantOptions {
50
23
  * whatever shadow-internal wrapper establishes that block (not the host you
51
24
  * meant to fill), and clipped by any `overflow` on an ancestor between the
52
25
  * 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
26
+ * `overflow: hidden` for label truncation. This controller is for exactly
54
27
  * that case: a host that can't offer a working CSS overlay for its slotted
55
28
  * content.
56
29
  *
@@ -68,25 +41,6 @@ export interface DelegateClickOptions extends InteractiveDescendantOptions {
68
41
  * tab stop regardless (a native `<a>`/`<button>`) — this only extends
69
42
  * *pointer* reach, the same as the CSS technique would.
70
43
  *
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
44
  * `target` and `disabled` are getters, not static values, so a host can
91
45
  * resolve its target dynamically (an `action-target` id-ref looked up by
92
46
  * attribute, a structural query for a designated child, one that only
@@ -113,4 +67,3 @@ export declare class ClickDelegateController implements ReactiveController {
113
67
  hostDisconnected(): void;
114
68
  private readonly _handleClick;
115
69
  }
116
- export default ClickDelegateController;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Identity tag for CSS written as a plain string, such as light-DOM structural
3
+ * styles installed through a `<style>` element. It returns the same text an
4
+ * untagged template would, with interpolations joined in place and escapes
5
+ * cooked as usual. The tag marks the literal as CSS so the package build can
6
+ * minify it.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const LIGHT_DOM_CSS = cssText`
11
+ * @layer rc-base {
12
+ * rc-example > button { inline-size: 100%; }
13
+ * }
14
+ * `;
15
+ * ```
16
+ */
17
+ export declare function cssText(strings: TemplateStringsArray, ...values: unknown[]): string;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Parses a CSS `<time>` value read from a custom property into milliseconds.
3
+ *
4
+ * Accepts `ms` and `s` units in any case, such as `300ms` or `.3s`, the form a
5
+ * theme's motion token often resolves to. A unitless number is read as
6
+ * milliseconds. Returns `undefined` for an empty, negative, non-finite, or
7
+ * otherwise unparsable value (including `calc()` and other functions), so a
8
+ * caller can fall back to its own default.
9
+ *
10
+ * @example
11
+ * const raw = getComputedStyle(el).getPropertyValue('--rc-bottom-sheet-snap-duration');
12
+ * const duration = parseCssTime(raw) ?? 300;
13
+ */
14
+ export declare function parseCssTime(value: string): number | undefined;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Returns the element's effective CSS zoom: the product of its own `zoom` and
3
+ * every ancestor's, such as an app-wide interface size set on the root.
4
+ *
5
+ * Geometry APIs (`getBoundingClientRect()`, pointer `clientX`/`clientY`,
6
+ * `innerWidth`/`innerHeight`) report viewport pixels, while a length written to
7
+ * the element's own style is multiplied by this factor. Divide viewport values
8
+ * by it before writing them as the element's `left`, `top`, `width`, or
9
+ * `height`. Where `currentCSSZoom` is unsupported, multiplies the computed
10
+ * zoom of the element and its ancestors, including shadow hosts.
11
+ */
12
+ export declare function cssZoom(element: Element): number;
@@ -1,9 +1,9 @@
1
1
  /**
2
- * Walks up the DOM from `el` and returns the first ancestor whose computed
2
+ * Walks up composed ancestry from `el` and returns the first ancestor whose computed
3
3
  * `overflow` or `overflow-y` is `auto` or `scroll`. Falls back to
4
4
  * `document.scrollingElement` (the root scroller) when no ancestor qualifies.
5
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).
6
+ * Starts outside `el`, follows assigned slots and shadow hosts, and uses the
7
+ * element's owner document for the root-scroller fallback.
8
8
  */
9
9
  export declare function findNearestScrollAncestor(el: Element): Element;
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Writing-mode and direction aware geometry.
3
+ *
4
+ * Components describe layout in logical terms (the block axis lines stack
5
+ * along, the inline axis text runs along, a start and an end on each), but the
6
+ * DOM reports everything physically: `scrollLeft`, `clientX`, `rect.left`,
7
+ * `ArrowRight`. This module is the single place that translates between the
8
+ * two, so no component compares `direction` or `writing-mode` by hand.
9
+ *
10
+ * Resolve a {@link Flow} with {@link resolveFlow} at interaction or measure
11
+ * time rather than caching it for the element's lifetime: a `dir` change on an
12
+ * ancestor fires no event.
13
+ */
14
+ export type LogicalAxis = 'block' | 'inline';
15
+ export type PhysicalAxis = 'x' | 'y';
16
+ export type ArrowKey = 'ArrowUp' | 'ArrowDown' | 'ArrowLeft' | 'ArrowRight';
17
+ export interface Flow {
18
+ /** Physical axis text runs along. */
19
+ inline: PhysicalAxis;
20
+ /** Physical axis lines stack along. */
21
+ block: PhysicalAxis;
22
+ /** The inline start is on the right (x) or the bottom (y). */
23
+ inlineReversed: boolean;
24
+ /** The block start is on the right (vertical-rl, sideways-rl). */
25
+ blockReversed: boolean;
26
+ /** Computed `direction` is `rtl`. */
27
+ rtl: boolean;
28
+ }
29
+ export interface LogicalRect {
30
+ inlineStart: number;
31
+ blockStart: number;
32
+ inlineSize: number;
33
+ blockSize: number;
34
+ }
35
+ export interface ArrowKeyMap {
36
+ /** Moves to the next item along the orientation. */
37
+ next: ArrowKey;
38
+ /** Moves to the previous item along the orientation. */
39
+ prev: ArrowKey;
40
+ /** Crosses the orientation toward the flow's end, e.g. opening a submenu. */
41
+ openFirst: ArrowKey;
42
+ /** Crosses the orientation toward the flow's start. */
43
+ openLast: ArrowKey;
44
+ }
45
+ /** The ordinary left-to-right, top-to-bottom flow, for callers with no element yet. */
46
+ export declare const HORIZONTAL_LTR_FLOW: Readonly<Flow>;
47
+ /** Reads the computed writing mode and direction of `el`. */
48
+ export declare function resolveFlow(el: Element): Flow;
49
+ /** The physical axis a logical axis runs along. */
50
+ export declare function physicalAxis(axis: LogicalAxis, flow: Flow): PhysicalAxis;
51
+ /** Whether a logical axis starts on the right (x) or the bottom (y). */
52
+ export declare function isReversed(axis: LogicalAxis, flow: Flow): boolean;
53
+ /** Whether a physical axis runs right to left (x) or bottom to top (y) in this flow. */
54
+ export declare function isPhysicalReversed(axis: PhysicalAxis, flow: Flow): boolean;
55
+ /**
56
+ * Distance scrolled from the logical start of `axis`, never negative.
57
+ *
58
+ * Scroll offsets on an axis that starts on the right or bottom run from 0
59
+ * toward negative values (CSSOM View). `flow` must be the scroll container's
60
+ * own flow, since that is what decides where its scroll origin is.
61
+ */
62
+ export declare function getScrollOffset(el: Element, axis: LogicalAxis, flow: Flow): number;
63
+ /** Scrolls `el` so that it is `offset` pixels from the logical start of `axis`. */
64
+ export declare function setScrollOffset(el: Element, axis: LogicalAxis, offset: number, flow: Flow, behavior?: ScrollBehavior): void;
65
+ /** Visible size of `el` along `axis`. */
66
+ export declare function clientSize(el: Element, axis: LogicalAxis, flow: Flow): number;
67
+ /** Scrollable content size of `el` along `axis`. */
68
+ export declare function scrollSize(el: Element, axis: LogicalAxis, flow: Flow): number;
69
+ /** `rect` expressed as logical offsets from the start edges of `container`. */
70
+ export declare function logicalRect(rect: DOMRectReadOnly, container: DOMRectReadOnly, flow: Flow): LogicalRect;
71
+ /**
72
+ * The physical translation for a logical offset from the start corner, the
73
+ * inverse of {@link logicalRect}. An element anchored with
74
+ * `inset-inline-start: 0; inset-block-start: 0` reaches `offset` with
75
+ * `translate(x, y)`; in RTL that means a negative `x`.
76
+ */
77
+ export declare function physicalOffset(offset: {
78
+ inline: number;
79
+ block: number;
80
+ }, flow: Flow): {
81
+ x: number;
82
+ y: number;
83
+ };
84
+ /** A physical pointer delta projected onto `axis`, positive toward its end. */
85
+ export declare function logicalDelta(delta: {
86
+ dx: number;
87
+ dy: number;
88
+ }, axis: LogicalAxis, flow: Flow): number;
89
+ /**
90
+ * Arrow keys for an ARIA `orientation`.
91
+ *
92
+ * `aria-orientation` is physical, so `horizontal` always means the Left and
93
+ * Right keys. Which of them means "next" follows the flow along that physical
94
+ * axis: in RTL, and in `vertical-rl` where lines stack right to left, next is
95
+ * ArrowLeft. The cross axis follows the same rule, so a vertical menu in RTL
96
+ * opens its submenu with ArrowLeft, as the APG describes.
97
+ */
98
+ export declare function arrowKeys(orientation: 'horizontal' | 'vertical', flow: Flow): ArrowKeyMap;
99
+ /**
100
+ * Arrow keys for content that runs along the inline axis, such as a row of
101
+ * chips or the characters in a text field: `next` points toward the inline
102
+ * end and `prev` toward the inline start. That is Right/Left in LTR,
103
+ * Left/Right in RTL, and Down/Up in vertical text.
104
+ */
105
+ export declare function inlineArrowKeys(flow: Flow): ArrowKeyMap;
106
+ /**
107
+ * The physical orientation a layout actually renders in. A `horizontal`
108
+ * layout runs along the inline axis and a `vertical` one along the block
109
+ * axis, so both turn over in vertical writing modes, the same way a native
110
+ * `<input type="range">` becomes vertical there. Use the result for
111
+ * `aria-orientation` and for arrow keys; keep the layout value for styling.
112
+ */
113
+ export declare function renderedOrientation(layout: 'horizontal' | 'vertical', flow: Flow): 'horizontal' | 'vertical';
114
+ /**
115
+ * The layout behind a rendered orientation: the inverse of
116
+ * {@link renderedOrientation}. Use it when all you can read is
117
+ * `aria-orientation`, which reports how a widget renders, and you need the
118
+ * layout to feed back into anything that renders it again. In vertical text a
119
+ * menubar row reports `vertical`, and its layout is `horizontal`.
120
+ */
121
+ export declare function layoutOrientation(rendered: 'horizontal' | 'vertical', flow: Flow): 'horizontal' | 'vertical';
@@ -3,19 +3,31 @@ export * from './clickDelegate.js';
3
3
  export * from './ItemsCollectionController.js';
4
4
  export * from './KeyboardInteractionDirective.js';
5
5
  export * from './KeyboardNavigationDirective.js';
6
- export * from './MouseMoveDirective.js';
7
6
  export * from './DragController.js';
8
7
  export * from './DragGestureController.js';
9
8
  export * from './ResizeController.js';
10
9
  export * from './AnchorController.js';
10
+ export * from './PopoverController.js';
11
11
  export * from './ScrollObserverController.js';
12
12
  export * from './MutationObserverController.js';
13
13
  export * from './NavigationIndicatorController.js';
14
14
  export * from './RafScheduler.js';
15
15
  export * from './TypeaheadController.js';
16
+ export * from './visualViewport.js';
17
+ export * from './softKeyboard.js';
18
+ export * from './cssText.js';
19
+ export * from './cssZoom.js';
16
20
  export * from './findNearestScrollAncestor.js';
21
+ export * from './flow.js';
22
+ export * from './FlowController.js';
23
+ export * from './observeLocale.js';
24
+ export * from './messages.js';
25
+ export * from './localeFormat.js';
17
26
  export * from './isFocusable.js';
18
27
  export * from './nativeChild.js';
19
28
  export * from './RovingTabIndexMixin.js';
20
29
  export * from './sliderUtils.js';
21
30
  export * from './snapUtils.js';
31
+ export * from './cssTime.js';
32
+ export * from './LiveAnnouncer.js';
33
+ export * from './ReorderController.js';
@@ -0,0 +1,4 @@
1
+ /** A shared `Intl.NumberFormat`. An unset or invalid locale uses the runtime default. */
2
+ export declare function numberFormat(locale: string | undefined, options?: Intl.NumberFormatOptions): Intl.NumberFormat;
3
+ /** A shared `Intl.Collator`. An unset or invalid locale uses the runtime default. */
4
+ export declare function collator(locale: string | undefined, options?: Intl.CollatorOptions): Intl.Collator;
@@ -0,0 +1,105 @@
1
+ import { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ import { ReorderMessages } from './ReorderController.js';
3
+ import { ResizeMessages } from './ResizeController.js';
4
+ /**
5
+ * The built-in text of every component and controller, keyed by element tag
6
+ * or controller name. Each package adds its own entry by augmenting this
7
+ * interface, so `registerMessages()` type-checks every key it is given.
8
+ *
9
+ * ```ts
10
+ * declare module '@rcarls/rc-common' {
11
+ * interface RcMessageCatalog {
12
+ * 'rc-carousel': RCCarouselMessages;
13
+ * }
14
+ * }
15
+ * ```
16
+ */
17
+ export interface RcMessageCatalog {
18
+ reorder: ReorderMessages;
19
+ resize: ResizeMessages;
20
+ }
21
+ /** Message overrides for some scopes of {@link RcMessageCatalog}. */
22
+ export type RcMessageCatalogInput = {
23
+ [K in keyof RcMessageCatalog]?: Partial<RcMessageCatalog[K]>;
24
+ };
25
+ /**
26
+ * Registers translated text for `locale`, such as `de` or `pt-BR`. Later
27
+ * calls for the same locale merge into earlier ones, key by key. Components
28
+ * already on the page re-render with the new text.
29
+ *
30
+ * Only English ships built in. Call this before components connect, or at
31
+ * least before the first paint, so the defaults never flash.
32
+ */
33
+ export declare function registerMessages(locale: string, catalog: RcMessageCatalogInput): void;
34
+ /**
35
+ * The UI locale of `host`: its own `lang` attribute, else `<html lang>`.
36
+ *
37
+ * An ancestor's `lang` is deliberately skipped. It usually marks the
38
+ * language of content, such as a German recipe, while component chrome
39
+ * stays in the language of the interface around it.
40
+ */
41
+ export declare function messagesLocale(host: Element): string;
42
+ /** Isolates an unknown-direction phrase inside a plain-text message. */
43
+ export declare function bidiIsolate(text: string): string;
44
+ export interface ResolveMessagesOptions {
45
+ /**
46
+ * A scope whose registered text this one falls back to, such as
47
+ * `rc-select` for `rc-combobox`. Only keys the scope's defaults name are
48
+ * taken from it. Within each locale the scope's own text wins; a more
49
+ * specific locale wins over a less specific one either way.
50
+ */
51
+ inherit?: keyof RcMessageCatalog;
52
+ }
53
+ /**
54
+ * Resolves the text for one scope. Each key comes from `overrides`, else
55
+ * the registry for the host's locale (exact tag, then its base language),
56
+ * else `defaults`.
57
+ */
58
+ export declare function resolveMessages<K extends keyof RcMessageCatalog>(host: Element, scope: K, defaults: Readonly<RcMessageCatalog[K]>, overrides?: Partial<RcMessageCatalog[K]>, options?: ResolveMessagesOptions): RcMessageCatalog[K];
59
+ export interface LocaleControllerOptions {
60
+ /** Called when the host's locale or the registered text changes. Defaults to `host.requestUpdate()`. */
61
+ onChange?: () => void;
62
+ }
63
+ /**
64
+ * Tracks a host's UI locale, as {@link messagesLocale} resolves it, and
65
+ * requests an update when it or the registered text changes. Use it for
66
+ * `Intl` formatting; {@link MessagesController} adds the text itself.
67
+ */
68
+ export declare class LocaleController implements ReactiveController {
69
+ protected readonly _host: ReactiveControllerHost & Element;
70
+ private readonly _onChange;
71
+ private _unobserveLocale;
72
+ private _key;
73
+ constructor(host: ReactiveControllerHost & Element, options?: LocaleControllerOptions);
74
+ /** The host's UI locale, or `undefined` for the runtime default. Read it while rendering. */
75
+ get locale(): string | undefined;
76
+ hostConnected(): void;
77
+ hostDisconnected(): void;
78
+ private _currentKey;
79
+ }
80
+ export interface MessagesControllerOptions<K extends keyof RcMessageCatalog> extends LocaleControllerOptions {
81
+ /** Per-element overrides, usually the element's `messages` property. */
82
+ overrides?: () => Partial<RcMessageCatalog[K]> | undefined;
83
+ /** See {@link ResolveMessagesOptions.inherit}. */
84
+ inherit?: keyof RcMessageCatalog;
85
+ }
86
+ /**
87
+ * Resolves a host's text for one scope of {@link RcMessageCatalog} and
88
+ * requests an update when its locale or the registered text changes.
89
+ */
90
+ export declare class MessagesController<K extends keyof RcMessageCatalog> extends LocaleController {
91
+ private readonly _scope;
92
+ private readonly _defaults;
93
+ private readonly _overrides;
94
+ private readonly _inherit;
95
+ constructor(host: ReactiveControllerHost & Element, scope: K, defaults: Readonly<RcMessageCatalog[K]>, options?: MessagesControllerOptions<K>);
96
+ /** The resolved text. Read it while rendering. */
97
+ get value(): RcMessageCatalog[K];
98
+ }
99
+ /**
100
+ * Writes a default attribute the component owns, such as an
101
+ * `aria-roledescription` in the current locale: only when the attribute is
102
+ * absent or still holds the value the component last wrote, so an authored
103
+ * value is never replaced. Pass the previous return value as `written`.
104
+ */
105
+ export declare function syncDefaultAttribute(el: Element, name: string, value: string, written: string | null): string | null;
@@ -25,8 +25,6 @@ export interface NativeChildControllerOptions<E extends Element> {
25
25
  */
26
26
  observe?: boolean | MutationObserverInit;
27
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
28
  /** Returns all matching children under `host`. */
31
29
  export declare function getDirectChildren<E extends Element = Element>(host: ParentNode, selector: string): E[];
32
30
  /**
@@ -51,4 +49,3 @@ export declare class NativeChildController<E extends Element = Element> implemen
51
49
  /** Re-read the child from the host and invoke `onChange` when it changes. */
52
50
  sync(): E | null;
53
51
  }
54
- export default NativeChildController;
@@ -0,0 +1,23 @@
1
+ type LocaleListener = () => void;
2
+ /** The elements whose locale a listener follows; none means any change. */
3
+ type LocaleScope = () => ReadonlyArray<Element | null | undefined>;
4
+ /**
5
+ * Calls `listener` when a `dir` or `lang` attribute changes on `host`, one of
6
+ * its ancestors in its document or any shadow tree containing it, or inside
7
+ * its subtree, or when messages are registered. A change elsewhere, such as a
8
+ * `lang` on unrelated content, cannot change the host's locale or flow and
9
+ * notifies nothing. Without a host, any change in the current document
10
+ * notifies, for compatibility.
11
+ *
12
+ * `scope` names the elements whose locale matters when it isn't only the
13
+ * host's, such as a popup positioned in its anchor's direction. Observe each
14
+ * scope element's containing shadow trees as well as the host's own shadow tree.
15
+ *
16
+ * Each tree shares one observer. A stylesheet changing `direction` or
17
+ * `writing-mode` does not create a mutation; geometry owners must also refresh
18
+ * at interaction or measurement time.
19
+ */
20
+ export declare function observeLocale(listener: LocaleListener, host?: Element, scope?: LocaleScope | undefined): () => void;
21
+ /** Notifies every {@link observeLocale} subscriber, as a `lang` change would. */
22
+ export declare function notifyLocaleChange(): void;
23
+ export {};