@rcarls/rc-common 0.3.2 → 0.4.1

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.
@@ -25,15 +25,9 @@ export interface DragOptions {
25
25
  export declare class DragController implements ReactiveController {
26
26
  private _opts;
27
27
  private _dragging;
28
- private _startX;
29
- private _startY;
30
28
  private _startLeft;
31
29
  private _startTop;
32
- private readonly _onPointerDown;
33
- private readonly _onPointerMove;
34
- private readonly _onPointerUp;
35
- private readonly _onPointerCancel;
36
- private readonly _onLostPointerCapture;
30
+ private readonly _gesture;
37
31
  private readonly _onKeyDown;
38
32
  constructor(host: ReactiveControllerHost, options: DragOptions);
39
33
  setOptions(next: Partial<DragOptions>): void;
@@ -43,11 +37,10 @@ export declare class DragController implements ReactiveController {
43
37
  private _target;
44
38
  private _attachTo;
45
39
  private _detachFrom;
46
- private _handlePointerDown;
47
- private _handlePointerMove;
48
- private _handlePointerUp;
49
- private _handleLostPointerCapture;
50
- private _cancelDrag;
40
+ private _canStartGesture;
41
+ private _startDrag;
42
+ private _moveDrag;
43
+ private _finishDrag;
51
44
  private _handleKeyDown;
52
45
  private _boundsRect;
53
46
  }
@@ -0,0 +1,110 @@
1
+ import { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ export type DragGestureAxis = 'both' | 'x' | 'y';
3
+ export type DragGestureActivation = 'axis' | 'immediate';
4
+ export interface DragGestureDetail {
5
+ /** Pointer event that produced this lifecycle update. */
6
+ event: PointerEvent;
7
+ /** Pointer identifier for the active gesture. */
8
+ pointerId: number;
9
+ /** Pointer device type reported by Pointer Events. */
10
+ pointerType: string;
11
+ /** Horizontal coordinate where the gesture began. */
12
+ startX: number;
13
+ /** Vertical coordinate where the gesture began. */
14
+ startY: number;
15
+ /** Current horizontal coordinate. */
16
+ x: number;
17
+ /** Current vertical coordinate. */
18
+ y: number;
19
+ /** Horizontal distance from the starting coordinate. */
20
+ deltaX: number;
21
+ /** Vertical distance from the starting coordinate. */
22
+ deltaY: number;
23
+ /** Elapsed gesture duration in milliseconds. */
24
+ duration: number;
25
+ /** Recent horizontal velocity in pixels per second. */
26
+ velocityX: number;
27
+ /** Recent vertical velocity in pixels per second. */
28
+ velocityY: number;
29
+ }
30
+ export type DragGestureTarget = Element | null | (() => Element | null);
31
+ export interface DragGestureOptions {
32
+ /** Element that receives pointer input, or a resolver for a rendered element. */
33
+ target: DragGestureTarget;
34
+ /** Allowed drag axis. Defaults to both axes. */
35
+ axis?: DragGestureAxis;
36
+ /**
37
+ * Whether to activate immediately or wait for dominant-axis intent.
38
+ * Delayed axis activation preserves cross-axis scrolling.
39
+ */
40
+ activation?: DragGestureActivation;
41
+ /** Distance required before delayed axis activation. Defaults to 8 pixels. */
42
+ activationDistance?: number;
43
+ /** Required allowed-axis dominance over the cross axis. Defaults to 1.25. */
44
+ axisLockRatio?: number;
45
+ /** Recent sample window used for velocity. Defaults to 100 milliseconds. */
46
+ velocityWindow?: number;
47
+ /** Minimum sample duration used for velocity. Defaults to 8 milliseconds. */
48
+ minVelocityDuration?: number;
49
+ /** Whether pointerdown listeners run during capture. */
50
+ capture?: boolean;
51
+ /** Whether activation stops pointer event propagation. */
52
+ stopPropagation?: boolean;
53
+ /** Whether active gesture events prevent their browser default. */
54
+ preventDefault?: boolean;
55
+ /** Whether activation focuses the target element. */
56
+ focusOnStart?: boolean;
57
+ /** Rejects pointerdown before the controller starts tracking it. */
58
+ canStart?: (event: PointerEvent) => boolean;
59
+ /** Called once when the gesture activates. */
60
+ onStart?: (detail: DragGestureDetail) => void;
61
+ /** Called for each active pointer move. */
62
+ onMove?: (detail: DragGestureDetail) => void;
63
+ /** Called when the active pointer is released. */
64
+ onEnd?: (detail: DragGestureDetail) => void;
65
+ /** Called when the active gesture is cancelled or loses pointer capture. */
66
+ onCancel?: (detail: DragGestureDetail) => void;
67
+ }
68
+ /**
69
+ * Tracks a single-pointer drag gesture without assigning component meaning.
70
+ *
71
+ * The controller owns pointer capture, intent activation, lifecycle cleanup,
72
+ * deltas, and recent velocity. Consumers remain responsible for geometry,
73
+ * snapping, dismissal, and other semantic actions.
74
+ */
75
+ export declare class DragGestureController implements ReactiveController {
76
+ private _options;
77
+ private _$target;
78
+ private _pointerId;
79
+ private _startX;
80
+ private _startY;
81
+ private _startTime;
82
+ private _samples;
83
+ private _activated;
84
+ private _rejected;
85
+ constructor(host: ReactiveControllerHost, options: DragGestureOptions);
86
+ /** Updates behavior or the target resolver and safely rebinds listeners. */
87
+ setOptions(options: Partial<DragGestureOptions>): void;
88
+ hostConnected(): void;
89
+ hostUpdated(): void;
90
+ hostDisconnected(): void;
91
+ private _resolveTarget;
92
+ private _bindTarget;
93
+ private _unbindTarget;
94
+ private _onPointerDown;
95
+ private _onPointerMove;
96
+ private _onPointerUp;
97
+ private _onPointerCancel;
98
+ private _onLostPointerCapture;
99
+ private _resolveIntent;
100
+ private _activate;
101
+ private _cancel;
102
+ private _finish;
103
+ private _removeCycleListeners;
104
+ private _recordSample;
105
+ private _detail;
106
+ private _capturePointer;
107
+ private _releasePointer;
108
+ private _reset;
109
+ }
110
+ export default DragGestureController;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ import { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ export interface NavigationIndicatorControllerOptions {
3
+ slot: () => HTMLSlotElement | null;
4
+ container: () => HTMLElement | null;
5
+ indicator: () => HTMLElement | null;
6
+ activeSelector: () => string;
7
+ indicatorTargetSelector: () => string;
8
+ }
9
+ /**
10
+ * Tracks slotted navigation links and positions an owned active indicator.
11
+ *
12
+ * The controller never moves or mutates consumer links. It only observes link
13
+ * state and writes geometry styles to the component-owned indicator element.
14
+ */
15
+ export declare class NavigationIndicatorController implements ReactiveController {
16
+ private readonly _host;
17
+ private readonly _options;
18
+ private _mutationObserver?;
19
+ private _resizeObserver?;
20
+ private _frame;
21
+ private _links;
22
+ constructor(host: ReactiveControllerHost & HTMLElement, options: NavigationIndicatorControllerOptions);
23
+ hostConnected(): void;
24
+ hostDisconnected(): void;
25
+ sync(): void;
26
+ update(): void;
27
+ private _collectLinks;
28
+ private _observeLinks;
29
+ private _activeLink;
30
+ private _targetFor;
31
+ private _positionIndicator;
32
+ }
33
+ export default NavigationIndicatorController;
@@ -1,5 +1,21 @@
1
1
  import { ReactiveController, ReactiveControllerHost } from 'lit';
2
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
+ }
3
19
  export interface ResizeOptions {
4
20
  /** The element to resize. Its `width` / `height` (and `left` / `top` for opposite edges) styles are updated. */
5
21
  target: Element;
@@ -7,6 +23,8 @@ export interface ResizeOptions {
7
23
  direction?: ResizeDirection;
8
24
  /** Custom resize handle element. If omitted, edge detection on `target` is used. */
9
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;
10
28
  /** Edge hit-test thickness in px (straddles the edge, inside + outside). Defaults to `8`. */
11
29
  threshold?: number;
12
30
  /** Bounds constraint. Defaults to `'viewport'`. */
@@ -18,7 +36,27 @@ export interface ResizeOptions {
18
36
  /** Keyboard arrow-key step in px. Shift multiplies by 10. Defaults to `4`. */
19
37
  step?: number;
20
38
  disabled?: boolean;
39
+ onResizeStart?: (detail: ResizeLifecycleDetail) => void;
40
+ onResize?: (detail: ResizeLifecycleDetail) => void;
41
+ onResizeEnd?: (detail: ResizeLifecycleDetail) => void;
21
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;
22
60
  /**
23
61
  * Makes an element resizable via pointer (edge detection) and keyboard.
24
62
  *
@@ -34,18 +72,22 @@ export interface ResizeOptions {
34
72
  export declare class ResizeController implements ReactiveController {
35
73
  private _opts;
36
74
  private _resizing;
37
- private _startX;
38
- private _startY;
39
75
  private _startW;
40
76
  private _startH;
41
77
  private _startLeft;
42
78
  private _startTop;
79
+ private _lastDeltaX;
80
+ private _lastDeltaY;
81
+ private _velocityX;
82
+ private _velocityY;
83
+ private _pendingEdge;
43
84
  private _effectiveMinW;
44
85
  private _effectiveMinH;
86
+ private _effectiveMaxW;
87
+ private _effectiveMaxH;
45
88
  private _cornerBtn;
46
89
  private readonly _onPointerMove;
47
- private readonly _onPointerDown;
48
- private readonly _onPointerUp;
90
+ private readonly _gesture;
49
91
  private readonly _onPointerLeave;
50
92
  private readonly _onKeyDown;
51
93
  constructor(host: ReactiveControllerHost, options: ResizeOptions);
@@ -53,26 +95,40 @@ export declare class ResizeController implements ReactiveController {
53
95
  hostConnected(): void;
54
96
  hostDisconnected(): void;
55
97
  private _target;
98
+ private _handle;
99
+ private _attachToHandle;
100
+ private _detachFromHandle;
56
101
  private _injectCornerButton;
57
102
  private _removeCornerButton;
58
103
  private _cornerCursor;
59
104
  private _edgeCursor;
105
+ private _handleEdge;
106
+ private _defaultHandleEdge;
107
+ private _edgeForOrigin;
108
+ private _edgeAllowsPointer;
60
109
  private _detectEdge;
110
+ private _pinPosition;
111
+ private _canStartGesture;
112
+ private _startGestureResize;
113
+ private _moveGestureResize;
114
+ private _endGestureResize;
115
+ private _startResize;
61
116
  /**
62
- * Pins position and size as explicit border-box pixel values.
63
- *
64
- * Required before any resize so that:
65
- * - UA centering styles (`inset:0; margin:auto` on `<dialog>`) don't fight
66
- * explicit left/top changes on n/w edges.
67
- * - Changing width/height alone doesn't redistribute auto-margins and shift
68
- * the element for e/s edges.
69
- * - box-sizing is known, so `style.width = rect.width` is a no-op visually.
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.
70
122
  */
71
- private _pinPosition;
72
- private _handlePointerDown;
123
+ private _computeEffectiveExtents;
124
+ private _lifecycleDetail;
73
125
  private _handlePointerMove;
74
- private _handlePointerUp;
126
+ private _finishResize;
127
+ private _cancelResize;
75
128
  private _handlePointerLeave;
76
129
  private _handleKeyDown;
130
+ private _keyboardEdge;
131
+ private _applyDelta;
77
132
  private _boundsRect;
78
133
  }
134
+ export {};
@@ -4,10 +4,12 @@ export * from './KeyboardInteractionDirective';
4
4
  export * from './KeyboardNavigationDirective';
5
5
  export * from './MouseMoveDirective';
6
6
  export * from './DragController';
7
+ export * from './DragGestureController';
7
8
  export * from './ResizeController';
8
9
  export * from './AnchorController';
9
10
  export * from './ScrollObserverController';
10
11
  export * from './MutationObserverController';
12
+ export * from './NavigationIndicatorController';
11
13
  export * from './RafScheduler';
12
14
  export * from './TypeaheadController';
13
15
  export * from './findNearestScrollAncestor';
@@ -15,3 +17,4 @@ export * from './isFocusable';
15
17
  export * from './nativeChild';
16
18
  export * from './RovingTabIndexMixin';
17
19
  export * from './sliderUtils';
20
+ export * from './snapUtils';
@@ -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 @@
1
+ export {};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.2",
6
+ "version": "0.4.1",
7
7
  "description": "Shared controllers, directives, and DOM utilities for rc-webcomponents.",
8
8
  "repository": {
9
9
  "type": "git",
@@ -57,4 +57,4 @@
57
57
  "peerDependencies": {
58
58
  "lit": "^3.0.0"
59
59
  }
60
- }
60
+ }