@rokkit/actions 1.0.2 → 1.0.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jerry Thomas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Svelte action function for forwarding keyboard events from a parent element to a child.
3
+ * The child is selected using a CSS selector passed in the options object.
4
+ * Optionally, you can specify which keyboard events you want to forward: "keydown", "keyup", and/or "keypress".
5
+ * By default, all three events are forwarded.
6
+ *
7
+ * @param {HTMLElement} element - The parent element from which keyboard events will be forwarded.
8
+ * @param {import('./types').PushDownOptions} options - The options object.
9
+ * @returns {{destroy: Function}}
10
+ */
11
+ export function delegateKeyboardEvents(element: HTMLElement, { selector, events }: import("./types").PushDownOptions): {
12
+ destroy: Function;
13
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A svelte action function that captures clicks outside the element or escape keypress
3
+ * emits a `dismiss` event. This is useful for closing a modal or dropdown.
4
+ *
5
+ * @param {HTMLElement} node
6
+ */
7
+ export function dismissable(node: HTMLElement): void;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Action for filling a <del>?</del> element in html block.
3
+ *
4
+ * @param {HTMLElement} node
5
+ * @param {import('./types').FillOptions} options
6
+ * @returns
7
+ */
8
+ export function fillable(node: HTMLElement, data: any): void;
@@ -0,0 +1,19 @@
1
+ export function hoverLift(node: any, options?: {}): void;
2
+ /**
3
+ * Hover lift action — adds translateY + elevated shadow on hover.
4
+ * Sets transition on mount, applies transform + box-shadow on mouseenter, resets on mouseleave.
5
+ */
6
+ export type HoverLiftOptions = {
7
+ /**
8
+ * Translate distance on hover (negative = up)
9
+ */
10
+ distance?: string | undefined;
11
+ /**
12
+ * Box shadow on hover
13
+ */
14
+ shadow?: string | undefined;
15
+ /**
16
+ * Transition duration (ms)
17
+ */
18
+ duration?: number | undefined;
19
+ };
@@ -0,0 +1,19 @@
1
+ export * from "./types.js";
2
+ export { Navigator } from "./navigator.js";
3
+ export { Trigger } from "./trigger.js";
4
+ export { keyboard } from "./keyboard.svelte.js";
5
+ export { pannable } from "./pannable.svelte.js";
6
+ export { swipeable } from "./swipeable.svelte.js";
7
+ export { navigator } from "./navigator.svelte.js";
8
+ export { themable } from "./themable.svelte.js";
9
+ export { skinnable } from "./skinnable.svelte.js";
10
+ export { dismissable } from "./dismissable.svelte.js";
11
+ export { navigable } from "./navigable.svelte.js";
12
+ export { fillable } from "./fillable.svelte.js";
13
+ export { delegateKeyboardEvents } from "./delegate.svelte.js";
14
+ export { reveal } from "./reveal.svelte.js";
15
+ export { hoverLift } from "./hover-lift.svelte.js";
16
+ export { magnetic } from "./magnetic.svelte.js";
17
+ export { ripple } from "./ripple.svelte.js";
18
+ export { tooltip } from "./tooltip.svelte.js";
19
+ export { buildKeymap, resolveAction, ACTIONS } from "./keymap.js";
package/dist/kbd.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Gets keyboard action handlers based on orientation and direction
3
+ * @param {Object} options - Configuration options
4
+ * @param {Object} handlers - Event handler functions
5
+ * @returns {Object} Object mapping key presses to handler functions
6
+ */
7
+ export function getKeyboardActions(options: Object, handlers: Object): Object;
8
+ /**
9
+ * Creates a keyboard action mapping based on navigation options
10
+ *
11
+ * @param {Object} options - Navigation options
12
+ * @param {string} options.orientation - Whether navigation is horizontal or vertical
13
+ * @param {string} options.dir - Text direction ('ltr' or 'rtl')
14
+ * @param {boolean} options.nested - Whether navigation is nested
15
+ * @returns {Object} Mapping of keys to actions
16
+ */
17
+ export function createKeyboardActionMap(options: {
18
+ orientation: string;
19
+ dir: string;
20
+ nested: boolean;
21
+ }): Object;
22
+ /**
23
+ * Creates a keyboard action mapping for modifier keys based on navigation options
24
+ *
25
+ * @param {Object} options - Navigation options
26
+ * @param {string} options.orientation - Whether navigation is horizontal or vertical
27
+ * @returns {Object} Mapping of keys to actions
28
+ */
29
+ export function createModifierKeyboardActionMap(options: {
30
+ orientation: string;
31
+ }): Object;
32
+ /**
33
+ * Creates a keyboard action mapping for shift key combinations
34
+ *
35
+ * @returns {Object} Mapping of keys to actions
36
+ */
37
+ export function createShiftKeyboardActionMap(): Object;
38
+ /**
39
+ * Gets the keyboard action for a key event
40
+ * @param {KeyboardEvent} event - The keyboard event
41
+ * @param {Object} options - Configuration options
42
+ * @returns {string|null} The action to perform, or null if no action is defined
43
+ */
44
+ export function getKeyboardAction(event: KeyboardEvent, options?: Object): string | null;
45
+ export namespace defaultNavigationOptions {
46
+ let orientation: string;
47
+ let dir: string;
48
+ let nested: boolean;
49
+ let enabled: boolean;
50
+ let typeahead: boolean;
51
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Handle keyboard events
3
+ *
4
+ * @param {HTMLElement} root
5
+ * @param {import('./types.js').KeyboardConfig} options - Custom key mappings
6
+ */
7
+ export function keyboard(root: HTMLElement, options?: import("./types.js").KeyboardConfig): void;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Build a complete keymap for the given options.
3
+ *
4
+ * Returns three layers — plain, shift, ctrl — each mapping key name → action name.
5
+ * Call resolveAction(event, keymap) to look up the action for a keyboard event.
6
+ *
7
+ * @param {Object} [options]
8
+ * @param {'vertical'|'horizontal'} [options.orientation='vertical']
9
+ * @param {'ltr'|'rtl'} [options.dir='ltr']
10
+ * @param {boolean} [options.collapsible=false]
11
+ * @returns {{ plain: Record<string, string>, shift: Record<string, string>, ctrl: Record<string, string> }}
12
+ */
13
+ export function buildKeymap({ orientation, dir, collapsible }?: {
14
+ orientation?: "vertical" | "horizontal" | undefined;
15
+ dir?: "ltr" | "rtl" | undefined;
16
+ collapsible?: boolean | undefined;
17
+ }): {
18
+ plain: Record<string, string>;
19
+ shift: Record<string, string>;
20
+ ctrl: Record<string, string>;
21
+ };
22
+ /**
23
+ * Resolve the action for a keyboard event given a pre-built keymap.
24
+ * Returns null if the key has no binding.
25
+ *
26
+ * @param {KeyboardEvent} event
27
+ * @param {{ plain: Record<string, string>, shift: Record<string, string>, ctrl: Record<string, string> }} keymap
28
+ * @returns {string|null}
29
+ */
30
+ export function resolveAction(event: KeyboardEvent, keymap: {
31
+ plain: Record<string, string>;
32
+ shift: Record<string, string>;
33
+ ctrl: Record<string, string>;
34
+ }): string | null;
35
+ export { ACTIONS } from "./nav-constants.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * EventManager class to manage event listeners on an element.
3
+ *
4
+ * @param {HTMLElement} element - The element to listen for events on.
5
+ * @param {Object} handlers - An object with event names as keys and event handlers as values.
6
+ * @returns {Object} - An object with methods to activate, reset, and update the event listeners.
7
+ */
8
+ export function EventManager(element: HTMLElement, handlers?: Object, enabled?: boolean): Object;
@@ -0,0 +1,2 @@
1
+ export * from "./internal";
2
+ export { EventManager } from "./event-manager";
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Sets up event handlers based on the given options.
3
+ * Returns whether or not the event handlers are listening.
4
+ *
5
+ * @param {HTMLElement} element
6
+ * @param {import('../types').EventHandlers} listeners
7
+ * @param {import('../types').TraversableOptions} options
8
+ * @returns {void}
9
+ */
10
+ export function setupListeners(element: HTMLElement, listeners: import("../types").EventHandlers, options: import("../types").TraversableOptions): void;
11
+ /**
12
+ * Removes event handlers based on the given options.
13
+ * Returns whether or not the event handlers are listening.
14
+ *
15
+ * @param {HTMLElement} element
16
+ * @param {import('../types').EventHandlers} listeners
17
+ * @returns {void}
18
+ */
19
+ export function removeListeners(element: HTMLElement, listeners: import("../types").EventHandlers): void;
@@ -0,0 +1,15 @@
1
+ export function magnetic(node: any, options?: {}): void;
2
+ /**
3
+ * Magnetic action — element shifts subtly toward the cursor on hover.
4
+ * Calculates cursor offset from element center and translates proportionally.
5
+ */
6
+ export type MagneticOptions = {
7
+ /**
8
+ * Maximum displacement as fraction of element size (0–1)
9
+ */
10
+ strength?: number | undefined;
11
+ /**
12
+ * Transition duration for return to center (ms)
13
+ */
14
+ duration?: number | undefined;
15
+ };
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Navigator constants — keyboard actions, key bindings, and typeahead config.
3
+ * These are used by the Navigator class and keymap builder.
4
+ */
5
+ export const ACTIONS: Readonly<{
6
+ next: "next";
7
+ prev: "prev";
8
+ first: "first";
9
+ last: "last";
10
+ expand: "expand";
11
+ collapse: "collapse";
12
+ select: "select";
13
+ extend: "extend";
14
+ range: "range";
15
+ cancel: "cancel";
16
+ }>;
17
+ export const PLAIN_FIXED: {
18
+ Enter: "select";
19
+ ' ': "select";
20
+ Home: "first";
21
+ End: "last";
22
+ Escape: "cancel";
23
+ };
24
+ export const CTRL_FIXED: {
25
+ ' ': "extend";
26
+ Home: "first";
27
+ End: "last";
28
+ };
29
+ export const SHIFT_FIXED: {
30
+ ' ': "range";
31
+ };
32
+ export const ARROWS: {
33
+ 'vertical-ltr': {
34
+ move: {
35
+ ArrowUp: "prev";
36
+ ArrowDown: "next";
37
+ };
38
+ nested: {
39
+ ArrowLeft: "collapse";
40
+ ArrowRight: "expand";
41
+ };
42
+ };
43
+ 'vertical-rtl': {
44
+ move: {
45
+ ArrowUp: "prev";
46
+ ArrowDown: "next";
47
+ };
48
+ nested: {
49
+ ArrowRight: "collapse";
50
+ ArrowLeft: "expand";
51
+ };
52
+ };
53
+ horizontal: {
54
+ move: {
55
+ ArrowLeft: "prev";
56
+ ArrowRight: "next";
57
+ };
58
+ nested: {
59
+ ArrowUp: "collapse";
60
+ ArrowDown: "expand";
61
+ };
62
+ };
63
+ };
64
+ /** Milliseconds of inactivity before the typeahead buffer resets. */
65
+ export const TYPEAHEAD_RESET_MS: 500;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A svelte action function that captures keyboard evvents and emits event for corresponding movements.
3
+ *
4
+ * @param {HTMLElement} node
5
+ * @param {import('./types').NavigableOptions} options
6
+ * @returns {import('./types').SvelteActionReturn}
7
+ */
8
+ export function navigable(node: HTMLElement, options: import("./types").NavigableOptions): import("./types").SvelteActionReturn;
@@ -0,0 +1,15 @@
1
+ export class Navigator {
2
+ /**
3
+ * @param {HTMLElement} root
4
+ * @param {import('@rokkit/states').Wrapper} wrapper
5
+ * @param {{ orientation?: string, dir?: string, collapsible?: boolean, containScroll?: boolean }} [options]
6
+ */
7
+ constructor(root: HTMLElement, wrapper: import("@rokkit/states").Wrapper, options?: {
8
+ orientation?: string;
9
+ dir?: string;
10
+ collapsible?: boolean;
11
+ containScroll?: boolean;
12
+ });
13
+ destroy(): void;
14
+ #private;
15
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The last only indicates that if there is an array only the last event is fired.
3
+ * This is crucial because a click event needs to fire both move and select,
4
+ * however the keyboard should only fire the select event because we are already
5
+ * on the current item
6
+ *
7
+ * @param {HTMLElement} root
8
+ * @param {*} controller
9
+ * @param {*} name
10
+ */
11
+ export function emitAction(root: HTMLElement, controller: any, name: any, lastOnly?: boolean): void;
12
+ export function handleAction(event: any, handler: any, path: any): any;
13
+ /**
14
+ * A svelte action function that captures keyboard evvents and emits event for corresponding movements.
15
+ *
16
+ * @param {HTMLElement} node
17
+ * @param {import('./types').NavigableOptions} options
18
+ * @returns {import('./types').SvelteActionReturn}
19
+ */
20
+ export function navigator(node: HTMLElement, options: import("./types").NavigableOptions): import("./types").SvelteActionReturn;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Makes an element pannable with mouse or touch events.
3
+ *
4
+ * @param {HTMLElement} node The DOM element to apply the panning action.
5
+ */
6
+ export function pannable(node: HTMLElement): void;
@@ -0,0 +1,40 @@
1
+ export function reveal(node: any, options?: {}): void;
2
+ /**
3
+ * Scroll-triggered reveal action using IntersectionObserver.
4
+ * Applies CSS transitions (opacity + translate) when element enters viewport.
5
+ * When stagger > 0, applies reveal to each child element independently.
6
+ */
7
+ export type RevealOptions = {
8
+ /**
9
+ * Slide direction
10
+ */
11
+ direction?: "none" | "left" | "right" | "up" | "down" | undefined;
12
+ /**
13
+ * Slide distance (CSS unit)
14
+ */
15
+ distance?: string | undefined;
16
+ /**
17
+ * Animation duration (ms)
18
+ */
19
+ duration?: number | undefined;
20
+ /**
21
+ * Delay before animation starts (ms)
22
+ */
23
+ delay?: number | undefined;
24
+ /**
25
+ * Delay increment per child in ms (0 = disabled)
26
+ */
27
+ stagger?: number | undefined;
28
+ /**
29
+ * Only animate once
30
+ */
31
+ once?: boolean | undefined;
32
+ /**
33
+ * IntersectionObserver threshold (0–1)
34
+ */
35
+ threshold?: number | undefined;
36
+ /**
37
+ * CSS easing function
38
+ */
39
+ easing?: string | undefined;
40
+ };
@@ -0,0 +1,19 @@
1
+ export function ripple(node: any, options?: {}): void;
2
+ /**
3
+ * Ripple action — material-design inspired click ripple effect.
4
+ * Appends a circular expanding span at click coordinates that scales and fades out.
5
+ */
6
+ export type RippleOptions = {
7
+ /**
8
+ * Ripple color
9
+ */
10
+ color?: string | undefined;
11
+ /**
12
+ * Ripple opacity
13
+ */
14
+ opacity?: number | undefined;
15
+ /**
16
+ * Ripple animation duration (ms)
17
+ */
18
+ duration?: number | undefined;
19
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Applies theme variables to an element
3
+ * @param {HTMLElement} node - Element to apply variables to
4
+ * @param {Object.<string, string>} variables - CSS variables and their values
5
+ */
6
+ export function skinnable(node: HTMLElement, variables: {
7
+ [x: string]: string;
8
+ }): void;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A svelte action function that captures swipe actions and emits event for corresponding movements.
3
+ *
4
+ * @param {HTMLElement} node
5
+ * @param {import(./types).SwipeableOptions} options
6
+ * @returns {import('./types').SvelteActionReturn}
7
+ */
8
+ export function swipeable(node: HTMLElement, options?: {
9
+ horizontal: boolean;
10
+ vertical: boolean;
11
+ threshold: number;
12
+ enabled: boolean;
13
+ minSpeed: number;
14
+ }): import("./types").SvelteActionReturn;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Update the theme attributes when the state changes.
3
+ *
4
+ * @param {HTMLElement} root
5
+ * @param {import('./types.js').ThemableConfig} options - Custom key mappings
6
+ */
7
+ export function themable(root: HTMLElement, options: import("./types.js").ThemableConfig): void;
@@ -0,0 +1 @@
1
+ export function tooltip(node: any, options?: {}): void;
@@ -0,0 +1,18 @@
1
+ export class Trigger {
2
+ /**
3
+ * @param {HTMLElement} trigger — the trigger button element
4
+ * @param {HTMLElement} container — the menu root (for click-outside detection)
5
+ * @param {{ onopen: () => void, onclose: () => void, onlast?: () => void, isOpen: () => boolean }} callbacks
6
+ */
7
+ constructor(trigger: HTMLElement, container: HTMLElement, { onopen, onclose, onlast, isOpen }: {
8
+ onopen: () => void;
9
+ onclose: () => void;
10
+ onlast?: () => void;
11
+ isOpen: () => boolean;
12
+ });
13
+ get isOpen(): boolean;
14
+ open(): void;
15
+ close(): void;
16
+ destroy(): void;
17
+ #private;
18
+ }
@@ -0,0 +1,72 @@
1
+ export type EventMapping = {
2
+ /**
3
+ * - The event name
4
+ */
5
+ event: string;
6
+ /**
7
+ * - The keys that trigger the event
8
+ */
9
+ keys?: string[] | undefined;
10
+ /**
11
+ * - The pattern that triggers the event
12
+ */
13
+ pattern?: RegExp | undefined;
14
+ };
15
+ export type KeyboardConfig = {
16
+ [x: string]: RegExp | string[];
17
+ };
18
+ export type Direction = "vertical" | "horizontal";
19
+ export type NavigatorOptions = {
20
+ /**
21
+ * - Whether the navigator is enabled
22
+ */
23
+ enabled: boolean;
24
+ /**
25
+ * - Whether the navigator is vertical or horizontal
26
+ */
27
+ direction: Direction;
28
+ /**
29
+ * - Whether the navigator supports multiple selections
30
+ */
31
+ multiselect: boolean;
32
+ };
33
+ export type DataWrapper = {
34
+ moveNext: Function;
35
+ movePrev: Function;
36
+ moveFirst: Function;
37
+ moveLast: Function;
38
+ expand: Function;
39
+ collapse: Function;
40
+ select: Function;
41
+ toggleExpansion: Function;
42
+ };
43
+ export type NavigatorActions = {
44
+ next: Function;
45
+ prev: Function;
46
+ first: Function;
47
+ last: Function;
48
+ expand: Function;
49
+ collapse: Function;
50
+ select: Function;
51
+ };
52
+ export type NavigatorConfig = {
53
+ /**
54
+ * - Whether the navigator is enabled
55
+ */
56
+ wrapper: Navigator;
57
+ /**
58
+ * - Whether the navigator is vertical or horizontal
59
+ */
60
+ options: NavigatorOptions;
61
+ };
62
+ export type Controller = {
63
+ moveNext: Function;
64
+ movePrev: Function;
65
+ moveFirst: Function;
66
+ moveLast: Function;
67
+ expand?: Function | undefined;
68
+ collapse?: Function | undefined;
69
+ select: Function;
70
+ extendSelection: Function;
71
+ toggleExpansion?: Function | undefined;
72
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Finds the closest ancestor of the given element that has the given attribute.
3
+ *
4
+ * @param {HTMLElement} element
5
+ * @param {string} attribute
6
+ * @returns {HTMLElement|null}
7
+ */
8
+ export function getClosestAncestorWithAttribute(element: HTMLElement, attribute: string): HTMLElement | null;
9
+ export function handleAction(actions: any, event: any): void;
10
+ /**
11
+ * Finds and returns an index path based on data-path attribute
12
+ *
13
+ * @param {MouseEvent} event
14
+ * @returns {number[]|null} null or index path array
15
+ */
16
+ export function getPathFromEvent(event: MouseEvent): number[] | null;
17
+ export function getEventForKey(keyMapping: import("./types.js").KeyboardConfig, key: string): string | null;
18
+ export function getClickAction(event: MouseEvent): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/actions",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Contains generic actions that can be used in various components.",
5
5
  "repository": {
6
6
  "type": "git",