ts-spatial-navigation 1.0.0-beta.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.
- package/LICENSE +362 -0
- package/README.md +284 -0
- package/dist/constants.d.ts +101 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +98 -0
- package/dist/constants.js.map +1 -0
- package/dist/core.d.ts +40 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +245 -0
- package/dist/core.js.map +1 -0
- package/dist/factory.d.ts +87 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +44 -0
- package/dist/factory.js.map +1 -0
- package/dist/geometry.d.ts +43 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +161 -0
- package/dist/geometry.js.map +1 -0
- package/dist/spatial-navigation.d.ts +84 -0
- package/dist/spatial-navigation.d.ts.map +1 -0
- package/dist/spatial-navigation.js +683 -0
- package/dist/spatial-navigation.js.map +1 -0
- package/dist/state.d.ts +82 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +179 -0
- package/dist/state.js.map +1 -0
- package/dist/strategies.d.ts +70 -0
- package/dist/strategies.d.ts.map +1 -0
- package/dist/strategies.js +147 -0
- package/dist/strategies.js.map +1 -0
- package/dist/types.d.ts +298 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for Spatial Navigation
|
|
3
|
+
* Replaces magic numbers with named constants
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Keyboard key codes for navigation
|
|
7
|
+
*/
|
|
8
|
+
export declare const KeyCode: {
|
|
9
|
+
readonly ENTER: 13;
|
|
10
|
+
readonly LEFT: 37;
|
|
11
|
+
readonly UP: 38;
|
|
12
|
+
readonly RIGHT: 39;
|
|
13
|
+
readonly DOWN: 40;
|
|
14
|
+
};
|
|
15
|
+
export type KeyCodeValue = (typeof KeyCode)[keyof typeof KeyCode];
|
|
16
|
+
/**
|
|
17
|
+
* Key code to direction mapping
|
|
18
|
+
*/
|
|
19
|
+
export declare const KEY_TO_DIRECTION: {
|
|
20
|
+
readonly 37: "left";
|
|
21
|
+
readonly 38: "up";
|
|
22
|
+
readonly 39: "right";
|
|
23
|
+
readonly 40: "down";
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Reverse direction mapping
|
|
27
|
+
*/
|
|
28
|
+
export declare const REVERSE_DIRECTION: {
|
|
29
|
+
readonly left: "right";
|
|
30
|
+
readonly up: "down";
|
|
31
|
+
readonly right: "left";
|
|
32
|
+
readonly down: "up";
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Grid configuration for spatial partitioning
|
|
36
|
+
* The navigation algorithm divides space into a 3x3 grid
|
|
37
|
+
*
|
|
38
|
+
* 0 | 1 | 2
|
|
39
|
+
* ---------
|
|
40
|
+
* 3 | 4 | 5
|
|
41
|
+
* ---------
|
|
42
|
+
* 6 | 7 | 8
|
|
43
|
+
*/
|
|
44
|
+
export declare const Grid: {
|
|
45
|
+
readonly SIZE: 3;
|
|
46
|
+
readonly TOTAL_CELLS: 9;
|
|
47
|
+
readonly TOP_LEFT: 0;
|
|
48
|
+
readonly TOP_CENTER: 1;
|
|
49
|
+
readonly TOP_RIGHT: 2;
|
|
50
|
+
readonly MIDDLE_LEFT: 3;
|
|
51
|
+
readonly MIDDLE_CENTER: 4;
|
|
52
|
+
readonly MIDDLE_RIGHT: 5;
|
|
53
|
+
readonly BOTTOM_LEFT: 6;
|
|
54
|
+
readonly BOTTOM_CENTER: 7;
|
|
55
|
+
readonly BOTTOM_RIGHT: 8;
|
|
56
|
+
readonly CORNERS: readonly [0, 2, 6, 8];
|
|
57
|
+
};
|
|
58
|
+
export type GridPosition = (typeof Grid)['TOP_LEFT' | 'TOP_CENTER' | 'TOP_RIGHT' | 'MIDDLE_LEFT' | 'MIDDLE_CENTER' | 'MIDDLE_RIGHT' | 'BOTTOM_LEFT' | 'BOTTOM_CENTER' | 'BOTTOM_RIGHT'];
|
|
59
|
+
/**
|
|
60
|
+
* Default configuration values
|
|
61
|
+
*/
|
|
62
|
+
export declare const Defaults: {
|
|
63
|
+
readonly SECTION_PREFIX: "section-";
|
|
64
|
+
readonly EVENT_PREFIX: "sn:";
|
|
65
|
+
readonly STRAIGHT_OVERLAP_THRESHOLD: 0.5;
|
|
66
|
+
readonly RESTRICT_MODE: "self-first";
|
|
67
|
+
readonly TAB_INDEX_IGNORE_LIST: "a, input, select, textarea, button, iframe, [contentEditable=true]";
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Event names (without prefix)
|
|
71
|
+
*/
|
|
72
|
+
export declare const EventName: {
|
|
73
|
+
readonly WILL_MOVE: "willmove";
|
|
74
|
+
readonly WILL_FOCUS: "willfocus";
|
|
75
|
+
readonly WILL_UNFOCUS: "willunfocus";
|
|
76
|
+
readonly FOCUSED: "focused";
|
|
77
|
+
readonly UNFOCUSED: "unfocused";
|
|
78
|
+
readonly ENTER_DOWN: "enter-down";
|
|
79
|
+
readonly ENTER_UP: "enter-up";
|
|
80
|
+
readonly NAVIGATE_FAILED: "navigatefailed";
|
|
81
|
+
};
|
|
82
|
+
export type EventNameValue = (typeof EventName)[keyof typeof EventName];
|
|
83
|
+
/**
|
|
84
|
+
* Restriction modes for section navigation
|
|
85
|
+
*/
|
|
86
|
+
export declare const RestrictMode: {
|
|
87
|
+
readonly SELF_FIRST: "self-first";
|
|
88
|
+
readonly SELF_ONLY: "self-only";
|
|
89
|
+
readonly NONE: "none";
|
|
90
|
+
};
|
|
91
|
+
export type RestrictModeValue = (typeof RestrictMode)[keyof typeof RestrictMode];
|
|
92
|
+
/**
|
|
93
|
+
* Enter behavior options
|
|
94
|
+
*/
|
|
95
|
+
export declare const EnterTo: {
|
|
96
|
+
readonly LAST_FOCUSED: "last-focused";
|
|
97
|
+
readonly DEFAULT_ELEMENT: "default-element";
|
|
98
|
+
readonly NONE: "";
|
|
99
|
+
};
|
|
100
|
+
export type EnterToValue = (typeof EnterTo)[keyof typeof EnterTo];
|
|
101
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,eAAO,MAAM,OAAO;;;;;;CAMV,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;CAKnB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;CAKpB,CAAC;AAEX;;;;;;;;;GASG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;CAiBP,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,IAAI,CAAC,CACpC,UAAU,GACV,YAAY,GACZ,WAAW,GACX,aAAa,GACb,eAAe,GACf,cAAc,GACd,aAAa,GACb,eAAe,GACf,cAAc,CAAC,CAAC;AAEpB;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;;;CAMX,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;CASZ,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAExE;;GAEG;AACH,eAAO,MAAM,YAAY;;;;CAIf,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAEjF;;GAEG;AACH,eAAO,MAAM,OAAO;;;;CAIV,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for Spatial Navigation
|
|
3
|
+
* Replaces magic numbers with named constants
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Keyboard key codes for navigation
|
|
7
|
+
*/
|
|
8
|
+
export const KeyCode = {
|
|
9
|
+
ENTER: 13,
|
|
10
|
+
LEFT: 37,
|
|
11
|
+
UP: 38,
|
|
12
|
+
RIGHT: 39,
|
|
13
|
+
DOWN: 40,
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Key code to direction mapping
|
|
17
|
+
*/
|
|
18
|
+
export const KEY_TO_DIRECTION = {
|
|
19
|
+
[KeyCode.LEFT]: 'left',
|
|
20
|
+
[KeyCode.UP]: 'up',
|
|
21
|
+
[KeyCode.RIGHT]: 'right',
|
|
22
|
+
[KeyCode.DOWN]: 'down',
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Reverse direction mapping
|
|
26
|
+
*/
|
|
27
|
+
export const REVERSE_DIRECTION = {
|
|
28
|
+
left: 'right',
|
|
29
|
+
up: 'down',
|
|
30
|
+
right: 'left',
|
|
31
|
+
down: 'up',
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Grid configuration for spatial partitioning
|
|
35
|
+
* The navigation algorithm divides space into a 3x3 grid
|
|
36
|
+
*
|
|
37
|
+
* 0 | 1 | 2
|
|
38
|
+
* ---------
|
|
39
|
+
* 3 | 4 | 5
|
|
40
|
+
* ---------
|
|
41
|
+
* 6 | 7 | 8
|
|
42
|
+
*/
|
|
43
|
+
export const Grid = {
|
|
44
|
+
SIZE: 3,
|
|
45
|
+
TOTAL_CELLS: 9,
|
|
46
|
+
// Named positions
|
|
47
|
+
TOP_LEFT: 0,
|
|
48
|
+
TOP_CENTER: 1,
|
|
49
|
+
TOP_RIGHT: 2,
|
|
50
|
+
MIDDLE_LEFT: 3,
|
|
51
|
+
MIDDLE_CENTER: 4,
|
|
52
|
+
MIDDLE_RIGHT: 5,
|
|
53
|
+
BOTTOM_LEFT: 6,
|
|
54
|
+
BOTTOM_CENTER: 7,
|
|
55
|
+
BOTTOM_RIGHT: 8,
|
|
56
|
+
// Corner positions (used for overlap calculations)
|
|
57
|
+
CORNERS: [0, 2, 6, 8],
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Default configuration values
|
|
61
|
+
*/
|
|
62
|
+
export const Defaults = {
|
|
63
|
+
SECTION_PREFIX: 'section-',
|
|
64
|
+
EVENT_PREFIX: 'sn:',
|
|
65
|
+
STRAIGHT_OVERLAP_THRESHOLD: 0.5,
|
|
66
|
+
RESTRICT_MODE: 'self-first',
|
|
67
|
+
TAB_INDEX_IGNORE_LIST: 'a, input, select, textarea, button, iframe, [contentEditable=true]',
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Event names (without prefix)
|
|
71
|
+
*/
|
|
72
|
+
export const EventName = {
|
|
73
|
+
WILL_MOVE: 'willmove',
|
|
74
|
+
WILL_FOCUS: 'willfocus',
|
|
75
|
+
WILL_UNFOCUS: 'willunfocus',
|
|
76
|
+
FOCUSED: 'focused',
|
|
77
|
+
UNFOCUSED: 'unfocused',
|
|
78
|
+
ENTER_DOWN: 'enter-down',
|
|
79
|
+
ENTER_UP: 'enter-up',
|
|
80
|
+
NAVIGATE_FAILED: 'navigatefailed',
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Restriction modes for section navigation
|
|
84
|
+
*/
|
|
85
|
+
export const RestrictMode = {
|
|
86
|
+
SELF_FIRST: 'self-first',
|
|
87
|
+
SELF_ONLY: 'self-only',
|
|
88
|
+
NONE: 'none',
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Enter behavior options
|
|
92
|
+
*/
|
|
93
|
+
export const EnterTo = {
|
|
94
|
+
LAST_FOCUSED: 'last-focused',
|
|
95
|
+
DEFAULT_ELEMENT: 'default-element',
|
|
96
|
+
NONE: '',
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,EAAE;IACR,EAAE,EAAE,EAAE;IACN,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,EAAE;CACA,CAAC;AAIX;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM;IACtB,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,IAAI;IAClB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO;IACxB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM;CACd,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,OAAO;IACb,EAAE,EAAE,MAAM;IACV,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,IAAI;CACF,CAAC;AAEX;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,IAAI,EAAE,CAAC;IACP,WAAW,EAAE,CAAC;IAEd,kBAAkB;IAClB,QAAQ,EAAE,CAAC;IACX,UAAU,EAAE,CAAC;IACb,SAAS,EAAE,CAAC;IACZ,WAAW,EAAE,CAAC;IACd,aAAa,EAAE,CAAC;IAChB,YAAY,EAAE,CAAC;IACf,WAAW,EAAE,CAAC;IACd,aAAa,EAAE,CAAC;IAChB,YAAY,EAAE,CAAC;IAEf,mDAAmD;IACnD,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAU;CACtB,CAAC;AAaX;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,cAAc,EAAE,UAAU;IAC1B,YAAY,EAAE,KAAK;IACnB,0BAA0B,EAAE,GAAG;IAC/B,aAAa,EAAE,YAAqB;IACpC,qBAAqB,EAAE,oEAAoE;CACnF,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,SAAS,EAAE,UAAU;IACrB,UAAU,EAAE,WAAW;IACvB,YAAY,EAAE,aAAa;IAC3B,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,eAAe,EAAE,gBAAgB;CACzB,CAAC;AAIX;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,UAAU,EAAE,YAAY;IACxB,SAAS,EAAE,WAAW;IACtB,IAAI,EAAE,MAAM;CACJ,CAAC;AAIX;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,YAAY,EAAE,cAAc;IAC5B,eAAe,EAAE,iBAAiB;IAClC,IAAI,EAAE,EAAE;CACA,CAAC"}
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Config, Direction, Priorities, Rect, SpatialEventDetail } from './types';
|
|
2
|
+
export { getRect, partition, distanceBuilder } from './geometry';
|
|
3
|
+
/**
|
|
4
|
+
* Sets the event prefix for custom events dispatched by the library.
|
|
5
|
+
* @param prefix The new prefix to use (e.g., 'spatial:')
|
|
6
|
+
*/
|
|
7
|
+
export declare const setEventPrefix: (prefix: string) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Gets the current event prefix.
|
|
10
|
+
* @returns The current event prefix
|
|
11
|
+
*/
|
|
12
|
+
export declare const getEventPrefix: () => string;
|
|
13
|
+
export declare const prioritize: (priorities: Priorities) => Rect[] | null;
|
|
14
|
+
export declare const navigate: (target: HTMLElement, direction: Direction, candidates: HTMLElement[], config: Config) => HTMLElement;
|
|
15
|
+
export declare const parseSelector: (selector: string | NodeList | HTMLElement) => HTMLElement[];
|
|
16
|
+
export declare const matchSelector: (elem: HTMLElement | null | undefined, selector: string | HTMLElement[] | HTMLElement) => boolean;
|
|
17
|
+
export declare const getCurrentFocusedElement: () => HTMLElement | null;
|
|
18
|
+
/**
|
|
19
|
+
* Merges multiple source objects into a new object.
|
|
20
|
+
* Properties from later sources override earlier ones.
|
|
21
|
+
* Undefined values are ignored.
|
|
22
|
+
*
|
|
23
|
+
* @param out - Base object to extend
|
|
24
|
+
* @param sources - Source objects to merge from
|
|
25
|
+
* @returns New merged object (does not mutate inputs)
|
|
26
|
+
*/
|
|
27
|
+
export declare function extend<T extends object>(out: object, source: T): T;
|
|
28
|
+
export declare function extend<T extends object, U extends object>(out: object, source1: T, source2: U): T & U;
|
|
29
|
+
export declare function extend<T extends object>(out: T, ...sources: object[]): T;
|
|
30
|
+
/**
|
|
31
|
+
* Returns a new array with excluded elements removed.
|
|
32
|
+
* Does not mutate the original array.
|
|
33
|
+
*
|
|
34
|
+
* @param elemList - Array of elements to filter
|
|
35
|
+
* @param excludedElem - Element(s) to exclude
|
|
36
|
+
* @returns New filtered array
|
|
37
|
+
*/
|
|
38
|
+
export declare const exclude: <T>(elemList: T[], excludedElem: T | T[]) => T[];
|
|
39
|
+
export declare const dispatch: (elem: HTMLElement, type: string, details?: SpatialEventDetail, cancelable?: boolean) => boolean;
|
|
40
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,SAAS,EACT,UAAU,EAEV,IAAI,EACJ,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAQjE;;;GAGG;AACH,eAAO,MAAM,cAAc,WAAY,MAAM,KAAG,IAE/C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,QAAO,MAEjC,CAAC;AAEF,eAAO,MAAM,UAAU,8BAA6B,IAAI,EAAE,GAAG,IA8B5D,CAAC;AAEF,eAAO,MAAM,QAAQ,WACX,WAAW,aACR,SAAS,cACR,WAAW,EAAE,UACjB,MAAM,gBAoIf,CAAC;AAEF,eAAO,MAAM,aAAa,aAAc,MAAM,GAAG,QAAQ,GAAG,WAAW,KAAG,WAAW,EAgBpF,CAAC;AAEF,eAAO,MAAM,aAAa,SAClB,WAAW,GAAG,IAAI,GAAG,SAAS,YAC1B,MAAM,GAAG,WAAW,EAAE,GAAG,WAAW,KAC7C,OAUF,CAAC;AAEF,eAAO,MAAM,wBAAwB,QAAO,WAAW,GAAG,IAOzD,CAAC;AAEF;;;;;;;;GAQG;AAEH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;AAEpE,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEvG,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;AAiB1E;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,kDAQnB,CAAC;AAEF,eAAO,MAAM,QAAQ,SACb,WAAW,QACX,MAAM,YACF,kBAAkB,2BAE3B,OAGF,CAAC"}
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// Re-export geometry functions for backwards compatibility
|
|
2
|
+
export { getRect, partition, distanceBuilder } from './geometry';
|
|
3
|
+
import { getRect, partition, distanceBuilder } from './geometry';
|
|
4
|
+
/*****************/
|
|
5
|
+
/* Core Function */
|
|
6
|
+
/*****************/
|
|
7
|
+
let EVENT_PREFIX = 'sn:';
|
|
8
|
+
/**
|
|
9
|
+
* Sets the event prefix for custom events dispatched by the library.
|
|
10
|
+
* @param prefix The new prefix to use (e.g., 'spatial:')
|
|
11
|
+
*/
|
|
12
|
+
export const setEventPrefix = (prefix) => {
|
|
13
|
+
EVENT_PREFIX = prefix;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Gets the current event prefix.
|
|
17
|
+
* @returns The current event prefix
|
|
18
|
+
*/
|
|
19
|
+
export const getEventPrefix = () => {
|
|
20
|
+
return EVENT_PREFIX;
|
|
21
|
+
};
|
|
22
|
+
export const prioritize = (priorities) => {
|
|
23
|
+
let destPriority = null;
|
|
24
|
+
for (let i = 0; i < priorities.length; i++) {
|
|
25
|
+
if (priorities[i].group.length) {
|
|
26
|
+
destPriority = priorities[i];
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!destPriority) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const destDistance = destPriority.distance;
|
|
34
|
+
destPriority.group.sort((a, b) => {
|
|
35
|
+
for (let i = 0; i < destDistance.length; i++) {
|
|
36
|
+
const distance = destDistance[i];
|
|
37
|
+
const delta = distance(a) - distance(b);
|
|
38
|
+
if (delta) {
|
|
39
|
+
return delta;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return 0;
|
|
43
|
+
});
|
|
44
|
+
return destPriority.group;
|
|
45
|
+
};
|
|
46
|
+
export const navigate = (target, direction, candidates, config) => {
|
|
47
|
+
if (!target || !direction || !candidates || !candidates.length) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const rects = [];
|
|
51
|
+
const targetRect = getRect(target);
|
|
52
|
+
if (!targetRect)
|
|
53
|
+
return null;
|
|
54
|
+
for (var i = 0; i < candidates.length; i++) {
|
|
55
|
+
var rect = getRect(candidates[i]);
|
|
56
|
+
if (rect)
|
|
57
|
+
rects.push(rect);
|
|
58
|
+
}
|
|
59
|
+
if (!rects.length)
|
|
60
|
+
return null;
|
|
61
|
+
const distanceFunction = distanceBuilder(targetRect);
|
|
62
|
+
const groups = partition(rects, targetRect, config.straightOverlapThreshold || 0.5);
|
|
63
|
+
const internalGroups = partition(groups[4], targetRect, config.straightOverlapThreshold || 0.5);
|
|
64
|
+
let priorities;
|
|
65
|
+
switch (direction) {
|
|
66
|
+
case 'left':
|
|
67
|
+
priorities = [
|
|
68
|
+
{
|
|
69
|
+
group: internalGroups[0].concat(internalGroups[3]).concat(internalGroups[6]),
|
|
70
|
+
distance: [distanceFunction.nearPlumbLineIsBetter, distanceFunction.topIsBetter]
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
group: groups[3],
|
|
74
|
+
distance: [distanceFunction.nearPlumbLineIsBetter, distanceFunction.topIsBetter]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
group: groups[0].concat(groups[6]),
|
|
78
|
+
distance: [
|
|
79
|
+
distanceFunction.nearHorizonIsBetter,
|
|
80
|
+
distanceFunction.rightIsBetter,
|
|
81
|
+
distanceFunction.nearTargetTopIsBetter
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
];
|
|
85
|
+
break;
|
|
86
|
+
case 'right':
|
|
87
|
+
priorities = [
|
|
88
|
+
{
|
|
89
|
+
group: internalGroups[2].concat(internalGroups[5]).concat(internalGroups[8]),
|
|
90
|
+
distance: [distanceFunction.nearPlumbLineIsBetter, distanceFunction.topIsBetter]
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
group: groups[5],
|
|
94
|
+
distance: [distanceFunction.nearPlumbLineIsBetter, distanceFunction.topIsBetter]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
group: groups[2].concat(groups[8]),
|
|
98
|
+
distance: [
|
|
99
|
+
distanceFunction.nearHorizonIsBetter,
|
|
100
|
+
distanceFunction.leftIsBetter,
|
|
101
|
+
distanceFunction.nearTargetTopIsBetter
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
];
|
|
105
|
+
break;
|
|
106
|
+
case 'up':
|
|
107
|
+
priorities = [
|
|
108
|
+
{
|
|
109
|
+
group: internalGroups[0].concat(internalGroups[1]).concat(internalGroups[2]),
|
|
110
|
+
distance: [distanceFunction.nearHorizonIsBetter, distanceFunction.leftIsBetter]
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
group: groups[1],
|
|
114
|
+
distance: [distanceFunction.nearHorizonIsBetter, distanceFunction.leftIsBetter]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
group: groups[0].concat(groups[2]),
|
|
118
|
+
distance: [
|
|
119
|
+
distanceFunction.nearPlumbLineIsBetter,
|
|
120
|
+
distanceFunction.bottomIsBetter,
|
|
121
|
+
distanceFunction.nearTargetLeftIsBetter
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
];
|
|
125
|
+
break;
|
|
126
|
+
case 'down':
|
|
127
|
+
priorities = [
|
|
128
|
+
{
|
|
129
|
+
group: internalGroups[6].concat(internalGroups[7]).concat(internalGroups[8]),
|
|
130
|
+
distance: [distanceFunction.nearHorizonIsBetter, distanceFunction.leftIsBetter]
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
group: groups[7],
|
|
134
|
+
distance: [distanceFunction.nearHorizonIsBetter, distanceFunction.leftIsBetter]
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
group: groups[6].concat(groups[8]),
|
|
138
|
+
distance: [
|
|
139
|
+
distanceFunction.nearPlumbLineIsBetter,
|
|
140
|
+
distanceFunction.topIsBetter,
|
|
141
|
+
distanceFunction.nearTargetLeftIsBetter
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
];
|
|
145
|
+
break;
|
|
146
|
+
default:
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
if (config.straightOnly)
|
|
150
|
+
priorities.pop();
|
|
151
|
+
const destGroup = prioritize(priorities);
|
|
152
|
+
if (!destGroup)
|
|
153
|
+
return null;
|
|
154
|
+
let dest = null;
|
|
155
|
+
if (config.rememberSource &&
|
|
156
|
+
config.previous &&
|
|
157
|
+
config.previous.destination === target &&
|
|
158
|
+
config.previous.reverse === direction) {
|
|
159
|
+
for (let j = 0; j < destGroup.length; j++) {
|
|
160
|
+
if (destGroup[j].element === config.previous.target) {
|
|
161
|
+
dest = destGroup[j].element;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (!dest) {
|
|
167
|
+
dest = destGroup[0].element;
|
|
168
|
+
}
|
|
169
|
+
return dest;
|
|
170
|
+
};
|
|
171
|
+
export const parseSelector = (selector) => {
|
|
172
|
+
let result = [];
|
|
173
|
+
try {
|
|
174
|
+
if (selector) {
|
|
175
|
+
if (typeof selector === 'string') {
|
|
176
|
+
result = [].slice.call(document.querySelectorAll(selector));
|
|
177
|
+
}
|
|
178
|
+
else if (selector instanceof NodeList) {
|
|
179
|
+
result = [].slice.call(selector);
|
|
180
|
+
}
|
|
181
|
+
else if (selector instanceof HTMLElement) {
|
|
182
|
+
result = [selector];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
console.error(err);
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
};
|
|
191
|
+
export const matchSelector = (elem, selector) => {
|
|
192
|
+
if (!elem)
|
|
193
|
+
return false;
|
|
194
|
+
if (typeof selector === 'string') {
|
|
195
|
+
return elem.matches(selector);
|
|
196
|
+
}
|
|
197
|
+
else if (Array.isArray(selector)) {
|
|
198
|
+
return selector.includes(elem);
|
|
199
|
+
}
|
|
200
|
+
else if (selector instanceof HTMLElement) {
|
|
201
|
+
return elem === selector;
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
};
|
|
205
|
+
export const getCurrentFocusedElement = () => {
|
|
206
|
+
const activeElement = document.activeElement;
|
|
207
|
+
if (activeElement && activeElement !== document.body) {
|
|
208
|
+
return activeElement;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
// Implementation
|
|
215
|
+
export function extend(out, ...sources) {
|
|
216
|
+
const result = { ...out };
|
|
217
|
+
for (const source of sources) {
|
|
218
|
+
if (source) {
|
|
219
|
+
for (const key of Object.keys(source)) {
|
|
220
|
+
const value = source[key];
|
|
221
|
+
if (value !== undefined) {
|
|
222
|
+
result[key] = value;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Returns a new array with excluded elements removed.
|
|
231
|
+
* Does not mutate the original array.
|
|
232
|
+
*
|
|
233
|
+
* @param elemList - Array of elements to filter
|
|
234
|
+
* @param excludedElem - Element(s) to exclude
|
|
235
|
+
* @returns New filtered array
|
|
236
|
+
*/
|
|
237
|
+
export const exclude = (elemList, excludedElem) => {
|
|
238
|
+
const excludedSet = new Set(Array.isArray(excludedElem) ? excludedElem : [excludedElem]);
|
|
239
|
+
return elemList.filter((elem) => !excludedSet.has(elem));
|
|
240
|
+
};
|
|
241
|
+
export const dispatch = (elem, type, details, cancelable = true) => {
|
|
242
|
+
const evt = new CustomEvent(EVENT_PREFIX + type, { bubbles: true, cancelable, detail: details });
|
|
243
|
+
return elem.dispatchEvent(evt);
|
|
244
|
+
};
|
|
245
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AASA,2DAA2D;AAC3D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;A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;SACF;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,QAAa,EACb,YAAqB,EAChB,EAAE;IACP,MAAM,WAAW,GAAG,IAAI,GAAG,CACzB,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAC5D,CAAC;IACF,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,IAAiB,EACjB,IAAY,EACZ,OAA4B,EAC5B,UAAU,GAAG,IAAI,EACR,EAAE;IACX,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,YAAY,GAAG,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IACjG,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory Module
|
|
3
|
+
* Creates isolated instances of spatial navigation.
|
|
4
|
+
* Enables multiple independent navigation contexts.
|
|
5
|
+
*/
|
|
6
|
+
import type { Direction, GlobalConfig, SectionConfig, AddSectionConfig } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Options for creating a spatial navigation instance.
|
|
9
|
+
*/
|
|
10
|
+
export interface CreateSpatialNavigationOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Initial global configuration.
|
|
13
|
+
*/
|
|
14
|
+
config?: Partial<GlobalConfig>;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to auto-initialize on creation.
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
autoInit?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Public API interface for spatial navigation.
|
|
23
|
+
* This interface documents all public methods available on the navigation instance.
|
|
24
|
+
*/
|
|
25
|
+
export interface SpatialNavigationAPI {
|
|
26
|
+
init(): void;
|
|
27
|
+
uninit(): void;
|
|
28
|
+
clear(): void;
|
|
29
|
+
setConfig(config: Partial<GlobalConfig>): void;
|
|
30
|
+
getConfig(): GlobalConfig;
|
|
31
|
+
add(config: AddSectionConfig): string;
|
|
32
|
+
add(id: string, config?: Partial<SectionConfig>): string;
|
|
33
|
+
remove(id: string): boolean;
|
|
34
|
+
disable(id: string): boolean;
|
|
35
|
+
enable(id: string): boolean;
|
|
36
|
+
set(id: string, config: Partial<SectionConfig>): boolean;
|
|
37
|
+
get(id: string): SectionConfig | undefined;
|
|
38
|
+
focus(target?: string | HTMLElement, silent?: boolean): boolean;
|
|
39
|
+
move(direction: Direction, selector?: string): boolean;
|
|
40
|
+
pause(): void;
|
|
41
|
+
resume(): void;
|
|
42
|
+
isPaused(): boolean;
|
|
43
|
+
makeFocusable(sectionId?: string): void;
|
|
44
|
+
setDefaultSection(id: string): void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new spatial navigation instance.
|
|
48
|
+
*
|
|
49
|
+
* This factory function allows creating isolated navigation contexts,
|
|
50
|
+
* useful for:
|
|
51
|
+
* - Multiple independent navigation areas
|
|
52
|
+
* - Testing with isolated state
|
|
53
|
+
* - Micro-frontends or iframe scenarios
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // Create an instance with custom config
|
|
58
|
+
* const nav = createSpatialNavigation({
|
|
59
|
+
* config: {
|
|
60
|
+
* straightOnly: true,
|
|
61
|
+
* eventPrefix: 'custom:'
|
|
62
|
+
* },
|
|
63
|
+
* autoInit: true
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Add sections
|
|
67
|
+
* nav.add({ selector: '.nav-item' });
|
|
68
|
+
*
|
|
69
|
+
* // Navigate
|
|
70
|
+
* nav.move('right');
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @param options - Configuration options for the instance
|
|
74
|
+
* @returns A spatial navigation instance with the full API
|
|
75
|
+
*/
|
|
76
|
+
export declare function createSpatialNavigation(_options?: CreateSpatialNavigationOptions): SpatialNavigationAPI;
|
|
77
|
+
/**
|
|
78
|
+
* Type for the default singleton instance.
|
|
79
|
+
* Includes all public API methods plus legacy compatibility.
|
|
80
|
+
*/
|
|
81
|
+
export type SpatialNavigationInstance = SpatialNavigationAPI & {
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated Use getConfig() instead
|
|
84
|
+
*/
|
|
85
|
+
globalConfig: GlobalConfig;
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAE/B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IAEnC,IAAI,IAAI,IAAI,CAAC;IACb,MAAM,IAAI,IAAI,CAAC;IACf,KAAK,IAAI,IAAI,CAAC;IAGd,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;IAC/C,SAAS,IAAI,YAAY,CAAC;IAG1B,GAAG,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAC;IACtC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;IACzD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAC7B,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC;IACzD,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IAG3C,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IAChE,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAGvD,KAAK,IAAI,IAAI,CAAC;IACd,MAAM,IAAI,IAAI,CAAC;IACf,QAAQ,IAAI,OAAO,CAAC;IAGpB,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,CAAC,EAAE,8BAA8B,GACxC,oBAAoB,CAStB;AAED;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG,oBAAoB,GAAG;IAC7D;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC"}
|
package/dist/factory.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory Module
|
|
3
|
+
* Creates isolated instances of spatial navigation.
|
|
4
|
+
* Enables multiple independent navigation contexts.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new spatial navigation instance.
|
|
8
|
+
*
|
|
9
|
+
* This factory function allows creating isolated navigation contexts,
|
|
10
|
+
* useful for:
|
|
11
|
+
* - Multiple independent navigation areas
|
|
12
|
+
* - Testing with isolated state
|
|
13
|
+
* - Micro-frontends or iframe scenarios
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Create an instance with custom config
|
|
18
|
+
* const nav = createSpatialNavigation({
|
|
19
|
+
* config: {
|
|
20
|
+
* straightOnly: true,
|
|
21
|
+
* eventPrefix: 'custom:'
|
|
22
|
+
* },
|
|
23
|
+
* autoInit: true
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Add sections
|
|
27
|
+
* nav.add({ selector: '.nav-item' });
|
|
28
|
+
*
|
|
29
|
+
* // Navigate
|
|
30
|
+
* nav.move('right');
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param options - Configuration options for the instance
|
|
34
|
+
* @returns A spatial navigation instance with the full API
|
|
35
|
+
*/
|
|
36
|
+
export function createSpatialNavigation(_options) {
|
|
37
|
+
// TODO: Implement full isolated instance
|
|
38
|
+
// For now, this is a placeholder that documents the intended API.
|
|
39
|
+
// Full implementation requires refactoring spatial-navigation.ts
|
|
40
|
+
// to support dependency injection of state.
|
|
41
|
+
throw new Error('createSpatialNavigation() is not yet fully implemented. ' +
|
|
42
|
+
'Use the default export from spatial-navigation.ts for now.');
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAyDH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,uBAAuB,CACrC,QAAyC;IAEzC,yCAAyC;IACzC,kEAAkE;IAClE,iEAAiE;IACjE,4CAA4C;IAC5C,MAAM,IAAI,KAAK,CACb,0DAA0D;QAC1D,4DAA4D,CAC7D,CAAC;AACJ,CAAC"}
|