@nvidia-elements/core 2.8.1 → 2.10.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.
- package/CHANGELOG.md +24 -0
- package/README.md +3 -7
- package/dist/accordion/accordion.d.ts +4 -4
- package/dist/accordion/accordion2.js +4 -4
- package/dist/alert/alert-group.d.ts +1 -1
- package/dist/alert/alert-group2.js +1 -1
- package/dist/alert/alert.d.ts +1 -1
- package/dist/alert/alert2.js +1 -1
- package/dist/avatar/avatar-group.d.ts +1 -1
- package/dist/avatar/avatar-group2.js +1 -1
- package/dist/avatar/avatar.d.ts +1 -1
- package/dist/avatar/avatar2.js +1 -1
- package/dist/badge/badge.d.ts +1 -1
- package/dist/badge/badge2.js +1 -1
- package/dist/breadcrumb/breadcrumb.d.ts +2 -1
- package/dist/breadcrumb/breadcrumb2.js +1 -1
- package/dist/breadcrumb/breadcrumb2.js.map +1 -1
- package/dist/bundle.d.ts +2 -0
- package/dist/bundles/index.d.ts +212 -1
- package/dist/bundles/index.js +6 -6
- package/dist/button/button.d.ts +1 -1
- package/dist/button/button2.js +1 -1
- package/dist/button-group/button-group.d.ts +1 -1
- package/dist/button-group/button-group2.js +1 -1
- package/dist/card/card.d.ts +4 -4
- package/dist/card/card2.js +4 -4
- package/dist/chat-message/chat-message.d.ts +1 -1
- package/dist/chat-message/chat-message2.js +1 -1
- package/dist/checkbox/checkbox-group2.js +1 -1
- package/dist/checkbox/checkbox2.js +1 -1
- package/dist/color/color.d.ts +1 -1
- package/dist/color/color2.js +1 -1
- package/dist/combobox/combobox.d.ts +2 -2
- package/dist/combobox/combobox2.js +1 -1
- package/dist/copy-button/copy-button.d.ts +1 -1
- package/dist/copy-button/copy-button2.js +1 -1
- package/dist/custom-elements-jsx.d.ts +125 -16
- package/dist/custom-elements-vue.d.ts +123 -16
- package/dist/custom-elements.json +3827 -1126
- package/dist/data.html.json +98 -4
- package/dist/date/date.d.ts +1 -1
- package/dist/date/date2.js +1 -1
- package/dist/datetime/datetime.d.ts +1 -1
- package/dist/datetime/datetime2.js +1 -1
- package/dist/dialog/dialog-footer.d.ts +1 -1
- package/dist/dialog/dialog-footer2.js +1 -1
- package/dist/dialog/dialog-header.d.ts +1 -1
- package/dist/dialog/dialog-header2.js +1 -1
- package/dist/dialog/dialog.d.ts +1 -1
- package/dist/dialog/dialog2.js +1 -1
- package/dist/divider/divider.d.ts +1 -1
- package/dist/divider/divider2.js +1 -1
- package/dist/dot/dot.d.ts +1 -1
- package/dist/dot/dot2.js +1 -1
- package/dist/drawer/drawer-content.d.ts +1 -1
- package/dist/drawer/drawer-content2.js +1 -1
- package/dist/drawer/drawer-footer.d.ts +1 -1
- package/dist/drawer/drawer-footer2.js +1 -1
- package/dist/drawer/drawer-header.d.ts +1 -1
- package/dist/drawer/drawer-header2.js +1 -1
- package/dist/drawer/drawer.d.ts +1 -1
- package/dist/drawer/drawer2.js +1 -1
- package/dist/dropdown/dropdown-footer.d.ts +1 -1
- package/dist/dropdown/dropdown-footer2.js +1 -1
- package/dist/dropdown/dropdown-header.d.ts +1 -1
- package/dist/dropdown/dropdown-header2.js +1 -1
- package/dist/dropdown/dropdown.d.ts +1 -1
- package/dist/dropdown/dropdown2.js +1 -1
- package/dist/dropdown-group/dropdown-group.d.ts +1 -1
- package/dist/dropdown-group/dropdown-group.js +1 -1
- package/dist/dropzone/dropzone.d.ts +1 -1
- package/dist/dropzone/dropzone2.js +1 -1
- package/dist/file/file2.js +1 -1
- package/dist/format-bytes/format-bytes.d.ts +1 -1
- package/dist/format-bytes/format-bytes2.js +1 -1
- package/dist/format-datetime/format-datetime.d.ts +1 -1
- package/dist/format-datetime/format-datetime2.js +1 -1
- package/dist/format-number/format-number.d.ts +1 -1
- package/dist/format-number/format-number2.js +1 -1
- package/dist/format-relative-time/format-relative-time.d.ts +1 -1
- package/dist/format-relative-time/format-relative-time2.js +1 -1
- package/dist/format-truncate/format-truncate2.js +1 -1
- package/dist/forms/control/control2.js +1 -1
- package/dist/forms/control-group/control-group.d.ts +3 -1
- package/dist/forms/control-group/control-group2.js +1 -1
- package/dist/forms/control-group/control-group2.js.map +1 -1
- package/dist/forms/control-message/control-message.d.ts +1 -1
- package/dist/forms/control-message/control-message2.js +1 -1
- package/dist/gauge/gauge.d.ts +1 -1
- package/dist/gauge/gauge2.js +1 -1
- package/dist/grid/cell/cell.d.ts +1 -1
- package/dist/grid/cell/cell2.js +1 -1
- package/dist/grid/column/column.d.ts +1 -1
- package/dist/grid/column/column2.js +1 -1
- package/dist/grid/footer/footer.d.ts +1 -1
- package/dist/grid/footer/footer2.js +1 -1
- package/dist/grid/grid.d.ts +3 -1
- package/dist/grid/grid2.js +1 -1
- package/dist/grid/grid2.js.map +1 -1
- package/dist/grid/header/header.d.ts +1 -1
- package/dist/grid/header/header2.js +1 -1
- package/dist/grid/placeholder/placeholder.d.ts +1 -1
- package/dist/grid/placeholder/placeholder2.js +1 -1
- package/dist/grid/row/row.d.ts +1 -1
- package/dist/grid/row/row2.js +1 -1
- package/dist/icon/icon.d.ts +1 -1
- package/dist/icon/icon2.js +2 -2
- package/dist/icon-button/icon-button.d.ts +1 -1
- package/dist/icon-button/icon-button2.js +1 -1
- package/dist/index.js +1 -1
- package/dist/input/input-group2.js +1 -1
- package/dist/input/input2.js +1 -1
- package/dist/internal/controllers/gesture.controller.d.ts +122 -42
- package/dist/internal/controllers/gesture.controller.examples.js.map +1 -1
- package/dist/internal/controllers/gesture.controller.examples.json +2 -2
- package/dist/internal/controllers/gesture.controller.js +300 -159
- package/dist/internal/controllers/gesture.controller.js.map +1 -1
- package/dist/internal/controllers/key-state.controller.d.ts +18 -0
- package/dist/internal/controllers/key-state.controller.js +84 -0
- package/dist/internal/controllers/key-state.controller.js.map +1 -0
- package/dist/internal/controllers/keynav-list.controller.js.map +1 -1
- package/dist/internal/controllers/keynav-spatial.controller.d.ts +4 -1
- package/dist/internal/controllers/keynav-spatial.controller.js +7 -6
- package/dist/internal/controllers/keynav-spatial.controller.js.map +1 -1
- package/dist/internal/index.d.ts +2 -0
- package/dist/internal/index.js +29 -27
- package/dist/internal/services/global.service.js +1 -1
- package/dist/internal/utils/dom.d.ts +4 -1
- package/dist/internal/utils/dom.js +42 -38
- package/dist/internal/utils/dom.js.map +1 -1
- package/dist/internal/utils/focus.d.ts +2 -0
- package/dist/internal/utils/focus.js +14 -7
- package/dist/internal/utils/focus.js.map +1 -1
- package/dist/internal/utils/numeric.d.ts +3 -0
- package/dist/internal/utils/numeric.js +14 -0
- package/dist/internal/utils/numeric.js.map +1 -0
- package/dist/logo/logo.d.ts +1 -1
- package/dist/logo/logo2.js +1 -1
- package/dist/menu/menu-item.d.ts +1 -1
- package/dist/menu/menu-item2.js +1 -1
- package/dist/menu/menu.d.ts +1 -1
- package/dist/menu/menu2.js +1 -1
- package/dist/month/month.d.ts +1 -1
- package/dist/month/month2.js +1 -1
- package/dist/notification/notification-group.d.ts +1 -1
- package/dist/notification/notification-group2.js +1 -1
- package/dist/notification/notification.d.ts +1 -1
- package/dist/notification/notification2.js +1 -1
- package/dist/page/page-panel/page-panel-content.d.ts +1 -1
- package/dist/page/page-panel/page-panel-content2.js +1 -1
- package/dist/page/page-panel/page-panel-footer.d.ts +1 -1
- package/dist/page/page-panel/page-panel-footer2.js +1 -1
- package/dist/page/page-panel/page-panel-header.d.ts +1 -1
- package/dist/page/page-panel/page-panel-header2.js +1 -1
- package/dist/page/page-panel/page-panel.d.ts +1 -1
- package/dist/page/page-panel/page-panel2.js +1 -1
- package/dist/page/page.d.ts +1 -1
- package/dist/page/page2.js +1 -1
- package/dist/page-header/page-header.d.ts +1 -1
- package/dist/page-header/page-header2.js +1 -1
- package/dist/page-loader/page-loader.d.ts +1 -1
- package/dist/page-loader/page-loader2.js +1 -1
- package/dist/pagination/pagination.d.ts +1 -1
- package/dist/pagination/pagination2.js +1 -1
- package/dist/panel/panel.d.ts +4 -4
- package/dist/panel/panel2.js +4 -4
- package/dist/password/password.d.ts +1 -1
- package/dist/password/password2.js +1 -1
- package/dist/preferences-input/preferences-input.d.ts +1 -1
- package/dist/preferences-input/preferences-input2.js +1 -1
- package/dist/progress-bar/progress-bar.d.ts +1 -1
- package/dist/progress-bar/progress-bar2.js +1 -1
- package/dist/progress-ring/progress-ring.d.ts +1 -1
- package/dist/progress-ring/progress-ring2.js +1 -1
- package/dist/progressive-filter-chip/progressive-filter-chip.d.ts +1 -1
- package/dist/progressive-filter-chip/progressive-filter-chip2.js +1 -1
- package/dist/pulse/pulse.d.ts +1 -1
- package/dist/pulse/pulse2.js +1 -1
- package/dist/radio/radio-group2.js +1 -1
- package/dist/radio/radio2.js +1 -1
- package/dist/range/range.d.ts +1 -1
- package/dist/range/range2.js +1 -1
- package/dist/resize-handle/resize-handle.d.ts +1 -1
- package/dist/resize-handle/resize-handle2.js +6 -10
- package/dist/resize-handle/resize-handle2.js.map +1 -1
- package/dist/search/search.d.ts +1 -1
- package/dist/search/search2.js +1 -1
- package/dist/select/select.d.ts +2 -2
- package/dist/select/select2.js +1 -1
- package/dist/skeleton/skeleton.d.ts +1 -1
- package/dist/skeleton/skeleton2.js +1 -1
- package/dist/sort-button/sort-button.d.ts +1 -1
- package/dist/sort-button/sort-button2.js +1 -1
- package/dist/sparkline/sparkline.d.ts +1 -1
- package/dist/sparkline/sparkline2.js +1 -1
- package/dist/star-rating/star-rating.d.ts +1 -1
- package/dist/star-rating/star-rating2.js +1 -1
- package/dist/steps/steps.d.ts +2 -2
- package/dist/steps/steps2.js +2 -2
- package/dist/switch/switch-group2.js +1 -1
- package/dist/switch/switch2.js +1 -1
- package/dist/tabs/tabs-group.d.ts +1 -1
- package/dist/tabs/tabs-group2.js +1 -1
- package/dist/tabs/tabs.d.ts +2 -2
- package/dist/tabs/tabs2.js +2 -2
- package/dist/tag/tag.d.ts +1 -1
- package/dist/tag/tag2.js +1 -1
- package/dist/textarea/textarea.d.ts +2 -2
- package/dist/textarea/textarea2.js +1 -1
- package/dist/time/time.d.ts +1 -1
- package/dist/time/time2.js +1 -1
- package/dist/toast/toast.d.ts +1 -1
- package/dist/toast/toast2.js +1 -1
- package/dist/toggletip/toggletip-footer.d.ts +1 -1
- package/dist/toggletip/toggletip-footer2.js +1 -1
- package/dist/toggletip/toggletip-header.d.ts +1 -1
- package/dist/toggletip/toggletip-header2.js +1 -1
- package/dist/toggletip/toggletip.d.ts +1 -1
- package/dist/toggletip/toggletip2.js +1 -1
- package/dist/toolbar/toolbar.d.ts +1 -1
- package/dist/toolbar/toolbar2.js +1 -1
- package/dist/tooltip/tooltip.d.ts +1 -1
- package/dist/tooltip/tooltip2.js +1 -1
- package/dist/tree/tree-node.d.ts +2 -2
- package/dist/tree/tree-node2.js +1 -1
- package/dist/tree/tree-node2.js.map +1 -1
- package/dist/tree/tree.d.ts +2 -1
- package/dist/tree/tree2.js +1 -1
- package/dist/tree/tree2.js.map +1 -1
- package/dist/viewport/define.d.ts +7 -0
- package/dist/viewport/define.js +7 -0
- package/dist/viewport/define.js.map +1 -0
- package/dist/viewport/index.d.ts +3 -0
- package/dist/viewport/index.js +3 -0
- package/dist/viewport/viewport-animation.controller.d.ts +21 -0
- package/dist/viewport/viewport-animation.controller.js +93 -0
- package/dist/viewport/viewport-animation.controller.js.map +1 -0
- package/dist/viewport/viewport-autofit.controller.d.ts +18 -0
- package/dist/viewport/viewport-autofit.controller.js +105 -0
- package/dist/viewport/viewport-autofit.controller.js.map +1 -0
- package/dist/viewport/viewport-fitting.utils.d.ts +36 -0
- package/dist/viewport/viewport-fitting.utils.js +35 -0
- package/dist/viewport/viewport-fitting.utils.js.map +1 -0
- package/dist/viewport/viewport-gesture-navigation.controller.d.ts +29 -0
- package/dist/viewport/viewport-gesture-navigation.controller.js +311 -0
- package/dist/viewport/viewport-gesture-navigation.controller.js.map +1 -0
- package/dist/viewport/viewport-gridlines.d.ts +38 -0
- package/dist/viewport/viewport-gridlines.js +6 -0
- package/dist/viewport/viewport-gridlines.js.map +1 -0
- package/dist/viewport/viewport-gridlines.utils.d.ts +11 -0
- package/dist/viewport/viewport-gridlines.utils.js +54 -0
- package/dist/viewport/viewport-gridlines.utils.js.map +1 -0
- package/dist/viewport/viewport-gridlines2.js +154 -0
- package/dist/viewport/viewport-gridlines2.js.map +1 -0
- package/dist/viewport/viewport-navigation.controller.d.ts +27 -0
- package/dist/viewport/viewport-navigation.controller.js +142 -0
- package/dist/viewport/viewport-navigation.controller.js.map +1 -0
- package/dist/viewport/viewport-navigation.types.d.ts +9 -0
- package/dist/viewport/viewport-projection.utils.d.ts +7 -0
- package/dist/viewport/viewport-projection.utils.js +25 -0
- package/dist/viewport/viewport-projection.utils.js.map +1 -0
- package/dist/viewport/viewport.d.ts +92 -0
- package/dist/viewport/viewport.examples.js +6 -0
- package/dist/viewport/viewport.examples.js.map +1 -0
- package/dist/viewport/viewport.examples.json +60 -0
- package/dist/viewport/viewport.js +6 -0
- package/dist/viewport/viewport.js.map +1 -0
- package/dist/viewport/viewport.types.d.ts +66 -0
- package/dist/viewport/viewport2.js +375 -0
- package/dist/viewport/viewport2.js.map +1 -0
- package/dist/week/week.d.ts +1 -1
- package/dist/week/week2.js +1 -1
- package/package.json +19 -4
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
export interface KeyStateControllerOptions {
|
|
3
|
+
readonly watchedCodes: ReadonlyArray<string>;
|
|
4
|
+
}
|
|
5
|
+
type KeyStateHost = ReactiveControllerHost & Pick<HTMLElement, 'ownerDocument'>;
|
|
6
|
+
/** Provides host-scoped access to shared raw keyboard state without assigning interaction semantics to any key. */
|
|
7
|
+
export declare class KeyStateController implements ReactiveController {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(host: KeyStateHost, { watchedCodes }: KeyStateControllerOptions);
|
|
10
|
+
/** Enables shared keyboard tracking during the host's connected lifecycle. */
|
|
11
|
+
get enabled(): boolean;
|
|
12
|
+
set enabled(value: boolean);
|
|
13
|
+
/** Returns whether a key identified by `KeyboardEvent.code` is currently held. */
|
|
14
|
+
isPressed(code: string): boolean;
|
|
15
|
+
hostConnected(): void;
|
|
16
|
+
hostDisconnected(): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
//#region src/internal/controllers/key-state.controller.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
#e;
|
|
4
|
+
#t = /* @__PURE__ */ new Set();
|
|
5
|
+
#n = /* @__PURE__ */ new Set();
|
|
6
|
+
constructor(e) {
|
|
7
|
+
this.#e = e;
|
|
8
|
+
}
|
|
9
|
+
subscribe(e) {
|
|
10
|
+
this.#n.has(e) || (this.#n.size === 0 && this.#r(), this.#n.add(e));
|
|
11
|
+
}
|
|
12
|
+
unsubscribe(e) {
|
|
13
|
+
!this.#n.delete(e) || this.#n.size > 0 || (this.#i(), this.#t.clear());
|
|
14
|
+
}
|
|
15
|
+
isPressed(e) {
|
|
16
|
+
return this.#t.has(e);
|
|
17
|
+
}
|
|
18
|
+
#r() {
|
|
19
|
+
let e = this.#e.defaultView;
|
|
20
|
+
e?.addEventListener("keydown", this.#a, !0), e?.addEventListener("keyup", this.#o, !0), e?.addEventListener("blur", this.#c), this.#e.addEventListener("visibilitychange", this.#s);
|
|
21
|
+
}
|
|
22
|
+
#i() {
|
|
23
|
+
let e = this.#e.defaultView;
|
|
24
|
+
e?.removeEventListener("keydown", this.#a, !0), e?.removeEventListener("keyup", this.#o, !0), e?.removeEventListener("blur", this.#c), this.#e.removeEventListener("visibilitychange", this.#s);
|
|
25
|
+
}
|
|
26
|
+
#a = (e) => {
|
|
27
|
+
this.#t.has(e.code) || (this.#t.add(e.code), this.#l(e.code));
|
|
28
|
+
};
|
|
29
|
+
#o = (e) => {
|
|
30
|
+
this.#t.delete(e.code) && this.#l(e.code);
|
|
31
|
+
};
|
|
32
|
+
#s = () => {
|
|
33
|
+
this.#e.visibilityState === "hidden" && this.#c();
|
|
34
|
+
};
|
|
35
|
+
#c = () => {
|
|
36
|
+
if (this.#t.size === 0) return;
|
|
37
|
+
let e = [...this.#t];
|
|
38
|
+
this.#t.clear();
|
|
39
|
+
for (let t of this.#n) e.some((e) => t.watchedCodes.has(e)) && t.requestUpdate();
|
|
40
|
+
};
|
|
41
|
+
#l(e) {
|
|
42
|
+
for (let t of this.#n) t.watchedCodes.has(e) && t.requestUpdate();
|
|
43
|
+
}
|
|
44
|
+
}, t = /* @__PURE__ */ new WeakMap();
|
|
45
|
+
function n(n) {
|
|
46
|
+
let r = t.get(n);
|
|
47
|
+
return r || (r = new e(n), t.set(n, r)), r;
|
|
48
|
+
}
|
|
49
|
+
var r = class {
|
|
50
|
+
#e;
|
|
51
|
+
#t;
|
|
52
|
+
#n = !1;
|
|
53
|
+
#r = !1;
|
|
54
|
+
#i;
|
|
55
|
+
constructor(e, { watchedCodes: t }) {
|
|
56
|
+
this.#e = e, this.#t = {
|
|
57
|
+
watchedCodes: new Set(t),
|
|
58
|
+
requestUpdate: () => e.requestUpdate()
|
|
59
|
+
}, e.addController(this);
|
|
60
|
+
}
|
|
61
|
+
get enabled() {
|
|
62
|
+
return this.#r;
|
|
63
|
+
}
|
|
64
|
+
set enabled(e) {
|
|
65
|
+
e !== this.#r && (this.#r = e, this.#a());
|
|
66
|
+
}
|
|
67
|
+
isPressed(e) {
|
|
68
|
+
return this.#i?.isPressed(e) ?? !1;
|
|
69
|
+
}
|
|
70
|
+
hostConnected() {
|
|
71
|
+
this.#n = !0, this.#a();
|
|
72
|
+
}
|
|
73
|
+
hostDisconnected() {
|
|
74
|
+
this.#n = !1, this.#a();
|
|
75
|
+
}
|
|
76
|
+
#a() {
|
|
77
|
+
let e = this.#n && this.#r ? n(this.#e.ownerDocument) : void 0;
|
|
78
|
+
e !== this.#i && (this.#i?.unsubscribe(this.#t), this.#i = e, this.#i?.subscribe(this.#t));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
export { r as KeyStateController };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=key-state.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-state.controller.js","names":[],"sources":["../../../src/internal/controllers/key-state.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ReactiveController, ReactiveControllerHost } from 'lit';\n\nexport interface KeyStateControllerOptions {\n readonly watchedCodes: ReadonlyArray<string>;\n}\n\ntype KeyStateHost = ReactiveControllerHost & Pick<HTMLElement, 'ownerDocument'>;\n\ninterface KeyStateSubscriber {\n readonly watchedCodes: ReadonlySet<string>;\n readonly requestUpdate: () => void;\n}\n\n/** Owns the keyboard state and global listeners shared by active controllers in one document. */\nclass DocumentKeyStateSource {\n readonly #document: Document;\n readonly #pressedCodes = new Set<string>();\n readonly #subscribers = new Set<KeyStateSubscriber>();\n\n constructor(document: Document) {\n this.#document = document;\n }\n\n subscribe(subscriber: KeyStateSubscriber): void {\n if (this.#subscribers.has(subscriber)) return;\n if (this.#subscribers.size === 0) this.#addListeners();\n this.#subscribers.add(subscriber);\n }\n\n unsubscribe(subscriber: KeyStateSubscriber): void {\n if (!this.#subscribers.delete(subscriber) || this.#subscribers.size > 0) return;\n this.#removeListeners();\n this.#pressedCodes.clear();\n }\n\n isPressed(code: string): boolean {\n return this.#pressedCodes.has(code);\n }\n\n #addListeners(): void {\n const view = this.#document.defaultView;\n view?.addEventListener('keydown', this.#handleKeyDown, true);\n view?.addEventListener('keyup', this.#handleKeyUp, true);\n view?.addEventListener('blur', this.#clear);\n this.#document.addEventListener('visibilitychange', this.#handleVisibilityChange);\n }\n\n #removeListeners(): void {\n const view = this.#document.defaultView;\n view?.removeEventListener('keydown', this.#handleKeyDown, true);\n view?.removeEventListener('keyup', this.#handleKeyUp, true);\n view?.removeEventListener('blur', this.#clear);\n this.#document.removeEventListener('visibilitychange', this.#handleVisibilityChange);\n }\n\n #handleKeyDown = (event: KeyboardEvent): void => {\n if (this.#pressedCodes.has(event.code)) return;\n this.#pressedCodes.add(event.code);\n this.#notifySubscribers(event.code);\n };\n\n #handleKeyUp = (event: KeyboardEvent): void => {\n if (!this.#pressedCodes.delete(event.code)) return;\n this.#notifySubscribers(event.code);\n };\n\n #handleVisibilityChange = (): void => {\n if (this.#document.visibilityState === 'hidden') this.#clear();\n };\n\n #clear = (): void => {\n if (this.#pressedCodes.size === 0) return;\n const changedCodes = [...this.#pressedCodes];\n this.#pressedCodes.clear();\n for (const subscriber of this.#subscribers) {\n if (changedCodes.some(code => subscriber.watchedCodes.has(code))) subscriber.requestUpdate();\n }\n };\n\n #notifySubscribers(code: string): void {\n for (const subscriber of this.#subscribers) {\n if (subscriber.watchedCodes.has(code)) subscriber.requestUpdate();\n }\n }\n}\n\nconst documentKeyStateSources = new WeakMap<Document, DocumentKeyStateSource>();\n\nfunction keyStateSourceFor(document: Document): DocumentKeyStateSource {\n let source = documentKeyStateSources.get(document);\n if (!source) {\n source = new DocumentKeyStateSource(document);\n documentKeyStateSources.set(document, source);\n }\n return source;\n}\n\n/** Provides host-scoped access to shared raw keyboard state without assigning interaction semantics to any key. */\nexport class KeyStateController implements ReactiveController {\n readonly #host: KeyStateHost;\n readonly #subscriber: KeyStateSubscriber;\n #connected = false;\n #enabled = false;\n #source?: DocumentKeyStateSource;\n\n constructor(host: KeyStateHost, { watchedCodes }: KeyStateControllerOptions) {\n this.#host = host;\n this.#subscriber = {\n watchedCodes: new Set(watchedCodes),\n requestUpdate: () => host.requestUpdate()\n };\n host.addController(this);\n }\n\n /** Enables shared keyboard tracking during the host's connected lifecycle. */\n get enabled(): boolean {\n return this.#enabled;\n }\n\n set enabled(value: boolean) {\n if (value === this.#enabled) return;\n this.#enabled = value;\n this.#syncSubscription();\n }\n\n /** Returns whether a key identified by `KeyboardEvent.code` is currently held. */\n isPressed(code: string): boolean {\n return this.#source?.isPressed(code) ?? false;\n }\n\n hostConnected(): void {\n this.#connected = true;\n this.#syncSubscription();\n }\n\n hostDisconnected(): void {\n this.#connected = false;\n this.#syncSubscription();\n }\n\n #syncSubscription(): void {\n const source = this.#connected && this.#enabled ? keyStateSourceFor(this.#host.ownerDocument) : undefined;\n if (source === this.#source) return;\n this.#source?.unsubscribe(this.#subscriber);\n this.#source = source;\n this.#source?.subscribe(this.#subscriber);\n }\n}\n"],"mappings":";AAiBA,IAAM,IAAN,MAA6B;CAC3B;CACA,qBAAyB,IAAI,IAAY;CACzC,qBAAwB,IAAI,IAAwB;CAEpD,YAAY,GAAoB;EAC9B,KAAK,KAAY;CACnB;CAEA,UAAU,GAAsC;EAC1C,KAAK,GAAa,IAAI,CAAU,MAChC,KAAK,GAAa,SAAS,KAAG,KAAK,GAAc,GACrD,KAAK,GAAa,IAAI,CAAU;CAClC;CAEA,YAAY,GAAsC;EAC5C,CAAC,KAAK,GAAa,OAAO,CAAU,KAAK,KAAK,GAAa,OAAO,MACtE,KAAK,GAAiB,GACtB,KAAK,GAAc,MAAM;CAC3B;CAEA,UAAU,GAAuB;EAC/B,OAAO,KAAK,GAAc,IAAI,CAAI;CACpC;CAEA,KAAsB;EACpB,IAAM,IAAO,KAAK,GAAU;EAI5B,AAHA,GAAM,iBAAiB,WAAW,KAAK,IAAgB,EAAI,GAC3D,GAAM,iBAAiB,SAAS,KAAK,IAAc,EAAI,GACvD,GAAM,iBAAiB,QAAQ,KAAK,EAAM,GAC1C,KAAK,GAAU,iBAAiB,oBAAoB,KAAK,EAAuB;CAClF;CAEA,KAAyB;EACvB,IAAM,IAAO,KAAK,GAAU;EAI5B,AAHA,GAAM,oBAAoB,WAAW,KAAK,IAAgB,EAAI,GAC9D,GAAM,oBAAoB,SAAS,KAAK,IAAc,EAAI,GAC1D,GAAM,oBAAoB,QAAQ,KAAK,EAAM,GAC7C,KAAK,GAAU,oBAAoB,oBAAoB,KAAK,EAAuB;CACrF;CAEA,MAAkB,MAA+B;EAC3C,KAAK,GAAc,IAAI,EAAM,IAAI,MACrC,KAAK,G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AClB,KAAK,GAAkB;CACzB;CAEA,mBAAyB;EAEvB,AADA,KAAK,KAAa,IAClB,KAAK,GAAkB;CACzB;CAEA,KAA0B;EACxB,IAAM,IAAS,KAAK,MAAc,KAAK,KAAW,EAAkB,KAAK,GAAM,aAAa,IAAI,KAAA;EAC5F,MAAW,KAAK,OACpB,KAAK,IAAS,YAAY,KAAK,EAAW,GAC1C,KAAK,KAAU,GACf,KAAK,IAAS,UAAU,KAAK,EAAW;CAC1C;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keynav-list.controller.js","names":[],"sources":["../../../src/internal/controllers/keynav-list.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ReactiveController, ReactiveElement } from 'lit';\nimport type { LegacyDecoratorTarget } from '../types/index.js';\nimport { focusElement, initializeKeyListItems, isFocusable, setActiveKeyListItem } from '../utils/focus.js';\nimport { KeynavCode, validKeyNavigationCode } from '../utils/dom.js';\n\nexport interface KeynavListConfig {\n items: NodeListOf<HTMLElement> | HTMLElement[];\n initialItem?: HTMLElement;\n layout?: 'both' | 'horizontal' | 'vertical';\n manageFocus?: boolean;\n manageTabindex?: boolean;\n loop?: boolean;\n dir?: string | null;\n}\n\nexport interface KeynavListElement {\n keynavListConfig: KeynavListConfig;\n}\n\n/** https://webaim.org/techniques/keyboard/ */\nexport function keyNavigationList<T extends ReactiveElement & KeynavListElement>(): ClassDecorator {\n return (target: LegacyDecoratorTarget) =>\n target.addInitializer!((instance: T) => new KeyNavigationListController(instance));\n}\n\nexport class KeyNavigationListController<T extends ReactiveElement & KeynavListElement> implements ReactiveController {\n get #config(): KeynavListConfig & { items: HTMLElement[] } {\n return {\n layout: 'horizontal',\n manageFocus: true,\n manageTabindex: true,\n loop: false,\n dir: this.host.getAttribute('rtl'),\n ...this.host.keynavListConfig,\n items: Array.from(this.host.keynavListConfig.items).filter(\n (i: HTMLElement & { disabled?: boolean }) => !i.disabled\n )\n };\n }\n\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n /** @private attr nve-keynav-disabled is an internal API for advanced use cases only */\n get #keynavDisabled() {\n return this.host.hasAttribute('nve-keynav-disabled');\n }\n\n async hostConnected() {\n await this.host.updateComplete;\n if (!this.host.isConnected) return;\n this.#initializeTabIndex();\n this.host.addEventListener('pointerup', this.#onPointerUp);\n this.host.addEventListener('keydown', this.#onKeyDown);\n }\n\n hostDisconnected() {\n this.host.removeEventListener('pointerup', this.#onPointerUp);\n this.host.removeEventListener('keydown', this.#onKeyDown);\n }\n\n #initializeTabIndex() {\n const { manageFocus, manageTabindex, items, initialItem } = this.#config;\n if (manageFocus && manageTabindex && !this.#keynavDisabled) {\n initializeKeyListItems(items);\n if (initialItem && items.includes(initialItem)) {\n setActiveKeyListItem(items, initialItem);\n }\n }\n }\n\n #clickItem(e: PointerEvent) {\n const item = this.#getPointerActiveItem(e, this.#config.items);\n if (item) {\n this.#setActiveItem(e, item);\n }\n }\n\n #focusItem(e: KeyboardEvent) {\n if (validKeyNavigationCode(e) && !this.#keynavDisabled) {\n const { loop, layout, dir, items } = this.#config;\n const activeItem = this.#getKeyboardActiveItem(e, items);\n if (activeItem) {\n const { next, previous } = getNextKeyListItem(activeItem, Array.from(items), {\n loop,\n layout,\n dir,\n code: e.code as KeynavCode\n });\n\n if (next !== previous) {\n this.#setActiveItem(e, items[next]!, items[previous]);\n }\n }\n }\n }\n\n #getKeyboardActiveItem(e: KeyboardEvent, items: HTMLElement[]) {\n const target = e.composedPath()[0];\n return target instanceof HTMLElement && items.includes(target) ? target : null;\n }\n\n #getPointerActiveItem(e: PointerEvent, items: HTMLElement[]) {\n const path = e.composedPath();\n const itemIndex = path.findIndex(item => item instanceof HTMLElement && items.includes(item));\n const item = path[itemIndex];\n\n if (!(item instanceof HTMLElement)) return null;\n\n const hasFocusableDescendant = path\n .slice(0, itemIndex)\n .some(descendant => descendant instanceof Element && isFocusable(descendant));\n return hasFocusableDescendant ? null : item;\n }\n\n #setActiveItem(e: KeyboardEvent | PointerEvent, activeItem: HTMLElement, previousItem?: HTMLElement) {\n const { manageFocus, manageTabindex, items } = this.#config;\n if (manageFocus) {\n if (manageTabindex) {\n setActiveKeyListItem(items, activeItem);\n }\n\n focusElement(activeItem);\n e.preventDefault();\n }\n\n const detail = {\n activeItem,\n previousItem,\n code: e instanceof KeyboardEvent ? e.code : null,\n metaKey: e.ctrlKey || e.metaKey,\n items\n };\n activeItem.dispatchEvent(new CustomEvent('nve-key-change', { bubbles: true, composed: true, detail }));\n }\n\n #onPointerUp = (e: PointerEvent) => this.#clickItem(e);\n\n #onKeyDown = (e: KeyboardEvent) => this.#focusItem(e);\n}\n\ninterface KeyListConfig {\n code: KeynavCode;\n loop?: boolean;\n layout?: 'horizontal' | 'vertical' | 'both';\n dir: string | null | undefined;\n}\n\nfunction resolveArrowDirection(config: KeyListConfig): 'backward' | 'forward' | null {\n const { code, layout, dir } = config;\n const start = dir === 'rtl' ? KeynavCode.ArrowRight : KeynavCode.ArrowLeft;\n const end = dir === 'rtl' ? KeynavCode.ArrowLeft : KeynavCode.ArrowRight;\n\n if (layout !== 'horizontal') {\n if (code === KeynavCode.ArrowUp) return 'backward';\n if (code === KeynavCode.ArrowDown) return 'forward';\n }\n\n if (layout !== 'vertical') {\n if (code === start) return 'backward';\n if (code === end) return 'forward';\n }\n\n return null;\n}\n\nfunction resolveSpecialKey(code: KeynavCode): 'home' | 'end' | 'pageup' | 'pagedown' | null {\n if (code === KeynavCode.End) return 'end';\n if (code === KeynavCode.Home) return 'home';\n if (code === KeynavCode.PageUp) return 'pageup';\n if (code === KeynavCode.PageDown) return 'pagedown';\n return null;\n}\n\nfunction navigateWithLoop(current: number, step: number, options: { limit: number; loop: boolean | undefined }) {\n const { limit, loop } = options;\n const next = current + step;\n if (next >= 0 && next <= limit) return next;\n return loop ? (step < 0 ? limit : 0) : current;\n}\n\nexport function getNextKeyListItem(item: HTMLElement, items: HTMLElement[], config: KeyListConfig) {\n let next = items.indexOf(item);\n const previous = next;\n const itemCount = items.length - 1;\n const direction = resolveArrowDirection(config);\n\n switch (direction ?? resolveSpecialKey(config.code)) {\n case 'backward':\n next = navigateWithLoop(next, -1, { limit: itemCount, loop: config.loop });\n break;\n case 'forward':\n next = navigateWithLoop(next, 1, { limit: itemCount, loop: config.loop });\n break;\n case 'end':\n next = itemCount;\n break;\n case 'home':\n next = 0;\n break;\n case 'pageup':\n next = Math.max(0, next - 4);\n break;\n case 'pagedown':\n next = Math.min(itemCount, next + 4);\n break;\n case null:\n break;\n }\n\n return { next, previous };\n}\n"],"mappings":";;;AAuBA,SAAgB,IAAmF;CACjG,QAAQ,MACN,EAAO,gBAAiB,MAAgB,IAAI,EAA4B,CAAQ,CAAC;AACrF;AAEA,IAAa,IAAb,MAAsH;CACpH,IAAI,KAAuD;EACzD,OAAO;GACL,QAAQ;GACR,aAAa;GACb,gBAAgB;GAChB,MAAM;GACN,KAAK,KAAK,KAAK,aAAa,KAAK;GACjC,GAAG,KAAK,KAAK;GACb,OAAO,MAAM,KAAK,KAAK,KAAK,iBAAiB,KAAK,CAAC,CAAC,QACjD,MAA4C,CAAC,EAAE,QAClD;EACF;CACF;CAEA,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAGA,IAAI,KAAkB;EACpB,OAAO,KAAK,KAAK,aAAa,qBAAqB;CACrD;CAEA,MAAM,gBAAgB;EACpB,MAAM,KAAK,KAAK,gBACX,KAAK,KAAK,gBACf,KAAK,GAAoB,GACzB,KAAK,KAAK,iBAAiB,aAAa,KAAK,EAAY,GACzD,KAAK,KAAK,iBAAiB,WAAW,KAAK,EAAU;CACvD;CAEA,mBAAmB;EAEjB,AADA,KAAK,KAAK,oBAAoB,aAAa,KAAK,EAAY,GAC5D,KAAK,KAAK,oBAAoB,WAAW,KAAK,EAAU;CAC1D;CAEA,K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C;GACzE;EACF,KAAK;GACH,IAAO,EAAiB,GAAM,GAAG;IAAE,OAAO;IAAW,MAAM,EAAO;GAAK,CAAC;GACxE;EACF,KAAK;GACH,IAAO;GACP;EACF,KAAK;GACH,IAAO;GACP;EACF,KAAK;GACH,IAAO,KAAK,IAAI,GAAG,IAAO,CAAC;GAC3B;EACF,KAAK,YACH,IAAO,KAAK,IAAI,GAAW,IAAO,CAAC;CAIvC;CAEA,OAAO;EAAE;EAAM;CAAS;AAC1B"}
|
|
1
|
+
{"version":3,"file":"keynav-list.controller.js","names":[],"sources":["../../../src/internal/controllers/keynav-list.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ReactiveController, ReactiveElement } from 'lit';\nimport type { LegacyDecoratorTarget } from '../types/index.js';\nimport { focusElement, initializeKeyListItems, isFocusable, setActiveKeyListItem } from '../utils/focus.js';\nimport { KeynavCode, validKeyNavigationCode } from '../utils/dom.js';\n\nexport interface KeynavListConfig {\n items: NodeListOf<HTMLElement> | HTMLElement[];\n initialItem?: HTMLElement;\n layout?: 'both' | 'horizontal' | 'vertical';\n manageFocus?: boolean;\n manageTabindex?: boolean;\n loop?: boolean;\n dir?: string | null;\n}\n\nexport interface KeynavListElement {\n keynavListConfig: KeynavListConfig;\n}\n\n/** https://webaim.org/techniques/keyboard/ */\nexport function keyNavigationList<T extends ReactiveElement & KeynavListElement>(): ClassDecorator {\n return (target: LegacyDecoratorTarget) =>\n target.addInitializer!((instance: T) => new KeyNavigationListController(instance));\n}\n\nexport class KeyNavigationListController<T extends ReactiveElement & KeynavListElement> implements ReactiveController {\n get #config(): KeynavListConfig & { items: HTMLElement[] } {\n return {\n layout: 'horizontal',\n manageFocus: true,\n manageTabindex: true,\n loop: false,\n dir: this.host.getAttribute('rtl'),\n ...this.host.keynavListConfig,\n items: Array.from(this.host.keynavListConfig.items).filter(\n (i: HTMLElement & { disabled?: boolean }) => !i.disabled\n )\n };\n }\n\n constructor(private host: T) {\n this.host.addController(this);\n }\n\n /** @private attr nve-keynav-disabled is an internal API for advanced use cases only */\n get #keynavDisabled() {\n return this.host.hasAttribute('nve-keynav-disabled');\n }\n\n async hostConnected() {\n await this.host.updateComplete;\n if (!this.host.isConnected) return;\n this.#initializeTabIndex();\n this.host.addEventListener('pointerup', this.#onPointerUp);\n this.host.addEventListener('keydown', this.#onKeyDown);\n }\n\n hostDisconnected() {\n this.host.removeEventListener('pointerup', this.#onPointerUp);\n this.host.removeEventListener('keydown', this.#onKeyDown);\n }\n\n #initializeTabIndex() {\n const { manageFocus, manageTabindex, items, initialItem } = this.#config;\n if (manageFocus && manageTabindex && !this.#keynavDisabled) {\n initializeKeyListItems(items);\n if (initialItem && items.includes(initialItem)) {\n setActiveKeyListItem(items, initialItem);\n }\n }\n }\n\n #clickItem(e: PointerEvent) {\n const item = this.#getPointerActiveItem(e, this.#config.items);\n if (item) {\n this.#setActiveItem(e, item);\n }\n }\n\n #focusItem(e: KeyboardEvent) {\n if (validKeyNavigationCode(e) && !this.#keynavDisabled) {\n const { loop, layout, dir, items } = this.#config;\n const activeItem = this.#getKeyboardActiveItem(e, items);\n if (activeItem) {\n const { next, previous } = getNextKeyListItem(activeItem, Array.from(items), {\n loop,\n layout,\n dir,\n code: e.code\n });\n\n if (next !== previous) {\n this.#setActiveItem(e, items[next]!, items[previous]);\n }\n }\n }\n }\n\n #getKeyboardActiveItem(e: KeyboardEvent, items: HTMLElement[]) {\n const target = e.composedPath()[0];\n return target instanceof HTMLElement && items.includes(target) ? target : null;\n }\n\n #getPointerActiveItem(e: PointerEvent, items: HTMLElement[]) {\n const path = e.composedPath();\n const itemIndex = path.findIndex(item => item instanceof HTMLElement && items.includes(item));\n const item = path[itemIndex];\n\n if (!(item instanceof HTMLElement)) return null;\n\n const hasFocusableDescendant = path\n .slice(0, itemIndex)\n .some(descendant => descendant instanceof Element && isFocusable(descendant));\n return hasFocusableDescendant ? null : item;\n }\n\n #setActiveItem(e: KeyboardEvent | PointerEvent, activeItem: HTMLElement, previousItem?: HTMLElement) {\n const { manageFocus, manageTabindex, items } = this.#config;\n if (manageFocus) {\n if (manageTabindex) {\n setActiveKeyListItem(items, activeItem);\n }\n\n focusElement(activeItem);\n e.preventDefault();\n }\n\n const detail = {\n activeItem,\n previousItem,\n code: e instanceof KeyboardEvent ? e.code : null,\n metaKey: e.ctrlKey || e.metaKey,\n items\n };\n activeItem.dispatchEvent(new CustomEvent('nve-key-change', { bubbles: true, composed: true, detail }));\n }\n\n #onPointerUp = (e: PointerEvent) => this.#clickItem(e);\n\n #onKeyDown = (e: KeyboardEvent) => this.#focusItem(e);\n}\n\ninterface KeyListConfig {\n code: KeynavCode;\n loop?: boolean;\n layout?: 'horizontal' | 'vertical' | 'both';\n dir: string | null | undefined;\n}\n\nfunction resolveArrowDirection(config: KeyListConfig): 'backward' | 'forward' | null {\n const { code, layout, dir } = config;\n const start = dir === 'rtl' ? KeynavCode.ArrowRight : KeynavCode.ArrowLeft;\n const end = dir === 'rtl' ? KeynavCode.ArrowLeft : KeynavCode.ArrowRight;\n\n if (layout !== 'horizontal') {\n if (code === KeynavCode.ArrowUp) return 'backward';\n if (code === KeynavCode.ArrowDown) return 'forward';\n }\n\n if (layout !== 'vertical') {\n if (code === start) return 'backward';\n if (code === end) return 'forward';\n }\n\n return null;\n}\n\nfunction resolveSpecialKey(code: KeynavCode): 'home' | 'end' | 'pageup' | 'pagedown' | null {\n if (code === KeynavCode.End) return 'end';\n if (code === KeynavCode.Home) return 'home';\n if (code === KeynavCode.PageUp) return 'pageup';\n if (code === KeynavCode.PageDown) return 'pagedown';\n return null;\n}\n\nfunction navigateWithLoop(current: number, step: number, options: { limit: number; loop: boolean | undefined }) {\n const { limit, loop } = options;\n const next = current + step;\n if (next >= 0 && next <= limit) return next;\n return loop ? (step < 0 ? limit : 0) : current;\n}\n\nexport function getNextKeyListItem(item: HTMLElement, items: HTMLElement[], config: KeyListConfig) {\n let next = items.indexOf(item);\n const previous = next;\n const itemCount = items.length - 1;\n const direction = resolveArrowDirection(config);\n\n switch (direction ?? resolveSpecialKey(config.code)) {\n case 'backward':\n next = navigateWithLoop(next, -1, { limit: itemCount, loop: config.loop });\n break;\n case 'forward':\n next = navigateWithLoop(next, 1, { limit: itemCount, loop: config.loop });\n break;\n case 'end':\n next = itemCount;\n break;\n case 'home':\n next = 0;\n break;\n case 'pageup':\n next = Math.max(0, next - 4);\n break;\n case 'pagedown':\n next = Math.min(itemCount, next + 4);\n break;\n case null:\n break;\n }\n\n return { next, previous };\n}\n"],"mappings":";;;AAuBA,SAAgB,IAAmF;CACjG,QAAQ,MACN,EAAO,gBAAiB,MAAgB,IAAI,EAA4B,CAAQ,CAAC;AACrF;AAEA,IAAa,IAAb,MAAsH;CACpH,IAAI,KAAuD;EACzD,OAAO;GACL,QAAQ;GACR,aAAa;GACb,gBAAgB;GAChB,MAAM;GACN,KAAK,KAAK,KAAK,aAAa,KAAK;GACjC,GAAG,KAAK,KAAK;GACb,OAAO,MAAM,KAAK,KAAK,KAAK,iBAAiB,KAAK,CAAC,CAAC,QACjD,MAA4C,CAAC,EAAE,QAClD;EACF;CACF;CAEA,YAAY,GAAiB;EAC3B,AADkB,KAAA,OAAA,GAClB,KAAK,KAAK,cAAc,IAAI;CAC9B;CAGA,IAAI,KAAkB;EACpB,OAAO,KAAK,KAAK,aAAa,qBAAqB;CACrD;CAEA,MAAM,gBAAgB;EACpB,MAAM,KAAK,KAAK,gBACX,KAAK,KAAK,gBACf,KAAK,GAAoB,GACzB,KAAK,KAAK,iBAAiB,aAAa,KAAK,EAAY,GACzD,KAAK,KAAK,iBAAiB,WAAW,KAAK,EAAU;CACvD;CAEA,mBAAmB;EAEjB,AADA,KAAK,KAAK,oBAAoB,aAAa,KAAK,EAAY,GAC5D,KAAK,KAAK,oBAAoB,WAAW,KAAK,EAAU;CAC1D;CAEA,KAAsB;EACpB,IAAM,EAAE,gB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AO,EAAiB,GAAM,GAAG;IAAE,OAAO;IAAW,MAAM,EAAO;GAAK,CAAC;GACxE;EACF,KAAK;GACH,IAAO;GACP;EACF,KAAK;GACH,IAAO;GACP;EACF,KAAK;GACH,IAAO,KAAK,IAAI,GAAG,IAAO,CAAC;GAC3B;EACF,KAAK,YACH,IAAO,KAAK,IAAI,GAAW,IAAO,CAAC;CAIvC;CAEA,OAAO;EAAE;EAAM;CAAS;AAC1B"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
2
|
type SpatialKeyHost = ReactiveControllerHost & HTMLElement;
|
|
3
3
|
export type SpatialKeyHandling = 'handled' | 'ignored';
|
|
4
|
+
export interface KeyNavigationSpatialControllerOptions {
|
|
5
|
+
readonly isEnabled?: () => boolean;
|
|
6
|
+
}
|
|
4
7
|
export type SpatialKeyCommand = {
|
|
5
8
|
readonly ctrlKey: boolean;
|
|
6
9
|
readonly event: KeyboardEvent;
|
|
@@ -17,7 +20,7 @@ export type SpatialKeyCommand = {
|
|
|
17
20
|
/** Converts direct-host keyboard input into spatial direction and zoom commands. */
|
|
18
21
|
export declare class KeyNavigationSpatialController implements ReactiveController {
|
|
19
22
|
#private;
|
|
20
|
-
constructor(host: SpatialKeyHost);
|
|
23
|
+
constructor(host: SpatialKeyHost, { isEnabled }?: KeyNavigationSpatialControllerOptions);
|
|
21
24
|
hostConnected(): void;
|
|
22
25
|
hostDisconnected(): void;
|
|
23
26
|
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
//#region src/internal/controllers/keynav-spatial.controller.ts
|
|
2
2
|
var e = class {
|
|
3
3
|
#e;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
#t;
|
|
5
|
+
constructor(e, { isEnabled: t = () => !0 } = {}) {
|
|
6
|
+
this.#e = e, this.#t = t, e.addController(this);
|
|
6
7
|
}
|
|
7
8
|
hostConnected() {
|
|
8
|
-
this.#e.addEventListener("keydown", this.#
|
|
9
|
+
this.#e.addEventListener("keydown", this.#n);
|
|
9
10
|
}
|
|
10
11
|
hostDisconnected() {
|
|
11
|
-
this.#e.removeEventListener("keydown", this.#
|
|
12
|
+
this.#e.removeEventListener("keydown", this.#n);
|
|
12
13
|
}
|
|
13
|
-
#
|
|
14
|
-
if (e.composedPath()[0] !== this.#e) return;
|
|
14
|
+
#n = (e) => {
|
|
15
|
+
if (!this.#t() || e.composedPath()[0] !== this.#e) return;
|
|
15
16
|
let n = t(e);
|
|
16
17
|
n && this.#e.dispatchEvent(new CustomEvent("nve-key", {
|
|
17
18
|
bubbles: !1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keynav-spatial.controller.js","names":[],"sources":["../../../src/internal/controllers/keynav-spatial.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ReactiveController, ReactiveControllerHost } from 'lit';\n\ntype SpatialKeyHost = ReactiveControllerHost & HTMLElement;\n\nexport type SpatialKeyHandling = 'handled' | 'ignored';\n\nexport type SpatialKeyCommand =\n | {\n readonly ctrlKey: boolean;\n readonly event: KeyboardEvent;\n readonly kind: 'direction';\n readonly horizontal: -1 | 0 | 1;\n readonly key: 'ArrowDown' | 'ArrowLeft' | 'ArrowRight' | 'ArrowUp';\n readonly shiftKey: boolean;\n readonly vertical: -1 | 0 | 1;\n }\n | {\n readonly event: KeyboardEvent;\n readonly kind: 'zoom';\n readonly key: '+' | '-' | '=';\n };\n\n/** Converts direct-host keyboard input into spatial direction and zoom commands. */\nexport class KeyNavigationSpatialController implements ReactiveController {\n readonly #host: SpatialKeyHost;\n\n constructor(host: SpatialKeyHost) {\n this.#host = host;\n host.addController(this);\n }\n\n hostConnected(): void {\n this.#host.addEventListener('keydown', this.#handleKeydown);\n }\n\n hostDisconnected(): void {\n this.#host.removeEventListener('keydown', this.#handleKeydown);\n }\n\n #handleKeydown = (event: KeyboardEvent): void => {\n if (event.composedPath()[0] !== this.#host) return;\n const command = getSpatialKeyCommand(event);\n if (!command) return;\n this.#host.dispatchEvent(\n new CustomEvent<SpatialKeyCommand>('nve-key', {\n bubbles: false,\n cancelable: false,\n composed: false,\n detail: command\n })\n );\n };\n}\n\nfunction getSpatialKeyCommand(event: KeyboardEvent): SpatialKeyCommand | undefined {\n switch (event.key) {\n case 'ArrowDown':\n return {\n ctrlKey: event.ctrlKey,\n event,\n horizontal: 0,\n key: event.key,\n kind: 'direction',\n shiftKey: event.shiftKey,\n vertical: -1\n };\n case 'ArrowLeft':\n return {\n ctrlKey: event.ctrlKey,\n event,\n horizontal: -1,\n key: event.key,\n kind: 'direction',\n shiftKey: event.shiftKey,\n vertical: 0\n };\n case 'ArrowRight':\n return {\n ctrlKey: event.ctrlKey,\n event,\n horizontal: 1,\n key: event.key,\n kind: 'direction',\n shiftKey: event.shiftKey,\n vertical: 0\n };\n case 'ArrowUp':\n return {\n ctrlKey: event.ctrlKey,\n event,\n horizontal: 0,\n key: event.key,\n kind: 'direction',\n shiftKey: event.shiftKey,\n vertical: 1\n };\n case '+':\n case '-':\n case '=':\n return { event, key: event.key, kind: 'zoom' };\n default:\n return undefined;\n }\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"keynav-spatial.controller.js","names":[],"sources":["../../../src/internal/controllers/keynav-spatial.controller.ts"],"sourcesContent":["// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ReactiveController, ReactiveControllerHost } from 'lit';\n\ntype SpatialKeyHost = ReactiveControllerHost & HTMLElement;\n\nexport type SpatialKeyHandling = 'handled' | 'ignored';\n\nexport interface KeyNavigationSpatialControllerOptions {\n readonly isEnabled?: () => boolean;\n}\n\nexport type SpatialKeyCommand =\n | {\n readonly ctrlKey: boolean;\n readonly event: KeyboardEvent;\n readonly kind: 'direction';\n readonly horizontal: -1 | 0 | 1;\n readonly key: 'ArrowDown' | 'ArrowLeft' | 'ArrowRight' | 'ArrowUp';\n readonly shiftKey: boolean;\n readonly vertical: -1 | 0 | 1;\n }\n | {\n readonly event: KeyboardEvent;\n readonly kind: 'zoom';\n readonly key: '+' | '-' | '=';\n };\n\n/** Converts direct-host keyboard input into spatial direction and zoom commands. */\nexport class KeyNavigationSpatialController implements ReactiveController {\n readonly #host: SpatialKeyHost;\n readonly #isEnabled: () => boolean;\n\n constructor(host: SpatialKeyHost, { isEnabled = () => true }: KeyNavigationSpatialControllerOptions = {}) {\n this.#host = host;\n this.#isEnabled = isEnabled;\n host.addController(this);\n }\n\n hostConnected(): void {\n this.#host.addEventListener('keydown', this.#handleKeydown);\n }\n\n hostDisconnected(): void {\n this.#host.removeEventListener('keydown', this.#handleKeydown);\n }\n\n #handleKeydown = (event: KeyboardEvent): void => {\n if (!this.#isEnabled() || event.composedPath()[0] !== this.#host) return;\n const command = getSpatialKeyCommand(event);\n if (!command) return;\n this.#host.dispatchEvent(\n new CustomEvent<SpatialKeyCommand>('nve-key', {\n bubbles: false,\n cancelable: false,\n composed: false,\n detail: command\n })\n );\n };\n}\n\nfunction getSpatialKeyCommand(event: KeyboardEvent): SpatialKeyCommand | undefined {\n switch (event.key) {\n case 'ArrowDown':\n return {\n ctrlKey: event.ctrlKey,\n event,\n horizontal: 0,\n key: event.key,\n kind: 'direction',\n shiftKey: event.shiftKey,\n vertical: -1\n };\n case 'ArrowLeft':\n return {\n ctrlKey: event.ctrlKey,\n event,\n horizontal: -1,\n key: event.key,\n kind: 'direction',\n shiftKey: event.shiftKey,\n vertical: 0\n };\n case 'ArrowRight':\n return {\n ctrlKey: event.ctrlKey,\n event,\n horizontal: 1,\n key: event.key,\n kind: 'direction',\n shiftKey: event.shiftKey,\n vertical: 0\n };\n case 'ArrowUp':\n return {\n ctrlKey: event.ctrlKey,\n event,\n horizontal: 0,\n key: event.key,\n kind: 'direction',\n shiftKey: event.shiftKey,\n vertical: 1\n };\n case '+':\n case '-':\n case '=':\n return { event, key: event.key, kind: 'zoom' };\n default:\n return undefined;\n }\n}\n"],"mappings":";AA8BA,IAAa,IAAb,MAA0E;CACxE;CACA;CAEA,YAAY,GAAsB,EAAE,qBAAkB,OAAgD,CAAC,GAAG;EAGxG,AAFA,KAAK,KAAQ,GACb,KAAK,KAAa,GAClB,EAAK,cAAc,IAAI;CACzB;CAEA,gBAAsB;EACpB,KAAK,GAAM,iBAAiB,WAAW,KAAK,EAAc;CAC5D;CAEA,mBAAyB;EACvB,KAAK,GAAM,oBAAoB,WAAW,KAAK,EAAc;CAC/D;CAEA,MAAkB,MAA+B;EAC/C,IAAI,CAAC,KAAK,GAAW,KAAK,EAAM,aAAa,CAAC,CAAC,OAAO,KAAK,IAAO;EAClE,IAAM,IAAU,EAAqB,CAAK;EACrC,KACL,KAAK,GAAM,cACT,IAAI,YAA+B,WAAW;GAC5C,SAAS;GACT,YAAY;GACZ,UAAU;GACV,QAAQ;EACV,CAAC,CACH;CACF;AACF;AAEA,SAAS,EAAqB,GAAqD;CACjF,QAAQ,EAAM,KAAd;EACE,KAAK,aACH,OAAO;GACL,SAAS,EAAM;GACf;GACA,YAAY;GACZ,KAAK,EAAM;GACX,MAAM;GACN,UAAU,EAAM;GAChB,UAAU;EACZ;EACF,KAAK,aACH,OAAO;GACL,SAAS,EAAM;GACf;GACA,YAAY;GACZ,KAAK,EAAM;GACX,MAAM;GACN,UAAU,EAAM;GAChB,UAAU;EACZ;EACF,KAAK,cACH,OAAO;GACL,SAAS,EAAM;GACf;GACA,YAAY;GACZ,KAAK,EAAM;GACX,MAAM;GACN,UAAU,EAAM;GAChB,UAAU;EACZ;EACF,KAAK,WACH,OAAO;GACL,SAAS,EAAM;GACf;GACA,YAAY;GACZ,KAAK,EAAM;GACX,MAAM;GACN,UAAU,EAAM;GAChB,UAAU;EACZ;EACF,KAAK;EACL,KAAK;EACL,KAAK,KACH,OAAO;GAAE;GAAO,KAAK,EAAM;GAAK,MAAM;EAAO;EAC/C,SACE;CACJ;AACF"}
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
export * from './controllers/audit.controller.js';
|
|
5
5
|
export * from './controllers/gesture.controller.js';
|
|
6
6
|
export * from './controllers/i18n.controller.js';
|
|
7
|
+
export * from './controllers/key-state.controller.js';
|
|
7
8
|
export * from './controllers/keynav-grid.controller.js';
|
|
8
9
|
export * from './controllers/keynav-list.controller.js';
|
|
9
10
|
export * from './controllers/keynav-spatial.controller.js';
|
|
@@ -34,4 +35,5 @@ export * from './utils/objects.js';
|
|
|
34
35
|
export * from './utils/strings.js';
|
|
35
36
|
export * from './utils/focus.js';
|
|
36
37
|
export * from './utils/keynav.js';
|
|
38
|
+
export * from './utils/numeric.js';
|
|
37
39
|
export * from './utils/supports.js';
|
package/dist/internal/index.js
CHANGED
|
@@ -6,30 +6,32 @@ import { AuditController as p, audit as m, excessiveInstanceLimit as h } from ".
|
|
|
6
6
|
import { GestureController as g } from "./controllers/gesture.controller.js";
|
|
7
7
|
import { I18nService as _, I18nService_ as v } from "./services/i18n.service.js";
|
|
8
8
|
import { I18nController as y, i18n as b } from "./controllers/i18n.controller.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
|
|
9
|
+
import { KeyStateController as x } from "./controllers/key-state.controller.js";
|
|
10
|
+
import { debounce as S, onChildListMutation as C, stopEvent as w, throttle as T } from "./utils/events.js";
|
|
11
|
+
import { LogService as E } from "./services/log.service.js";
|
|
12
|
+
import { focusElement as D, focusElementTimeout as O, getActiveElement as k, initializeKeyListItems as A, isFocusable as j, isImmediateRootActiveElement as M, isSimpleFocusable as N, onListboxActivate as P, setActiveKeyListItem as F } from "./utils/focus.js";
|
|
13
|
+
import { KeynavCode as I, appendAnchorName as L, appendRootNodeStyle as R, applySlotContentStates as z, clickOutsideElementBounds as B, createGhostElement as V, define as H, defineElement as U, endOfScrollBox as W, generateId as G, getAnchorNames as K, getAttributeChanges as q, getAttributeListChanges as J, getChildren as Y, getCustomElementRegistry as X, getDisplayValue as Z, getElementUpdate as Q, getFlattenedDOMTree as $, getFlattenedFocusableItems as ee, getPropertyChanges as te, getThemeTokens as ne, hasHorizontalScrollBar as re, hasInvalidDOMGrid as ie, hasScrollBar as ae, isContextMenuClick as oe, matchesElementName as se, openEyeDropper as ce, parseTokenNumber as le, removeAnchorName as ue, removeEmptySlotWhitespace as de, removeEmptyTextNode as fe, sameOrderedStringArray as pe, sameRenderRoot as me, scrollBarWidth as he, slotContainsOnlyWhitespace as ge, styleSheetToString as _e, supportsScopedRegistry as ve, uniqueNonEmptyStrings as ye, validKeyNavigationCode as be } from "./utils/dom.js";
|
|
14
|
+
import { KeyNavigationGridController as xe, getNextKeyGridItem as Se, keyNavigationGrid as Ce } from "./controllers/keynav-grid.controller.js";
|
|
15
|
+
import { KeyNavigationListController as we, getNextKeyListItem as Te, keyNavigationList as Ee } from "./controllers/keynav-list.controller.js";
|
|
16
|
+
import { KeyNavigationSpatialController as De } from "./controllers/keynav-spatial.controller.js";
|
|
17
|
+
import { associateAriaDescribedBy as Oe, associateAriaLabel as ke, associateControlGroup as Ae, associateDataList as je, associateLabel as Me, attachInternals as Ne } from "./utils/a11y.js";
|
|
18
|
+
import { StateExpandedController as Pe, stateExpanded as Fe } from "./controllers/state-expanded.controller.js";
|
|
19
|
+
import { StateHighlightedController as Ie, stateHighlighted as Le } from "./controllers/state-highlighted.controller.js";
|
|
20
|
+
import { StateScrollController as Re, stateScroll as ze } from "./controllers/state-scroll.controller.js";
|
|
21
|
+
import { StateSelectedController as Be, stateSelected as Ve } from "./controllers/state-selected.controller.js";
|
|
22
|
+
import { TypeAnchorController as He, typeAnchor as Ue } from "./controllers/type-anchor.controller.js";
|
|
23
|
+
import { TypeClosableController as We } from "./controllers/type-closable.controller.js";
|
|
24
|
+
import { TypeExpandableController as Ge } from "./controllers/type-expandable.controller.js";
|
|
25
|
+
import { TypeSelectableController as Ke } from "./controllers/type-selectable.controller.js";
|
|
26
|
+
import { TypeNativePopoverController as qe } from "./controllers/type-native-popover.controller.js";
|
|
27
|
+
import { TypeSSRController as Je, typeSSR as Ye } from "./controllers/type-ssr.controller.js";
|
|
28
|
+
import { hostAttr as Xe } from "./decorators/host-attr.js";
|
|
29
|
+
import { scopedRegistry as Ze } from "./decorators/scoped-registry.js";
|
|
30
|
+
import { colorStateStyles as Qe, statusStateStyles as $e, supportStateStyles as et, useStyles as tt } from "./styles/index.js";
|
|
31
|
+
import { supportsCSSLegacyInsetArea as nt, supportsCSSPositionArea as rt, supportsNativeCSSAnchorPosition as it } from "./utils/supports.js";
|
|
32
|
+
import { popoverStyles as at } from "./styles/popover2.js";
|
|
33
|
+
import { TransitionService as ot } from "./services/transition.service.js";
|
|
34
|
+
import { statusIcons as st } from "./types/index.js";
|
|
35
|
+
import { createLightDismiss as ct, onKeys as lt } from "./utils/keynav.js";
|
|
36
|
+
import { finiteOr as ut, nonnegativeFiniteOr as dt, positiveFiniteOr as ft } from "./utils/numeric.js";
|
|
37
|
+
export { p as AuditController, e as DOCS_URL, g as GestureController, l as GlobalState, u as GlobalStateService, y as I18nController, _ as I18nService, v as I18nService_, xe as KeyNavigationGridController, we as KeyNavigationListController, De as KeyNavigationSpatialController, x as KeyStateController, I as KeynavCode, E as LogService, Pe as StateExpandedController, Ie as StateHighlightedController, Re as StateScrollController, Be as StateSelectedController, ot as TransitionService, He as TypeAnchorController, We as TypeClosableController, Ge as TypeExpandableController, qe as TypeNativePopoverController, Je as TypeSSRController, Ke as TypeSelectableController, L as appendAnchorName, R as appendRootNodeStyle, z as applySlotContentStates, Oe as associateAriaDescribedBy, ke as associateAriaLabel, Ae as associateControlGroup, je as associateDataList, Me as associateLabel, Ne as attachInternals, m as audit, d as auditParentElement, f as auditSlots, B as clickOutsideElementBounds, Qe as colorStateStyles, V as createGhostElement, ct as createLightDismiss, S as debounce, r as deepMerge, H as define, U as defineElement, W as endOfScrollBox, h as excessiveInstanceLimit, ut as finiteOr, D as focusElement, O as focusElementTimeout, t as formatFileSize, i as formatStandardNumber, G as generateId, k as getActiveElement, K as getAnchorNames, q as getAttributeChanges, J as getAttributeListChanges, Y as getChildren, X as getCustomElementRegistry, a as getDifference, Z as getDisplayValue, Q as getElementUpdate, $ as getFlattenedDOMTree, ee as getFlattenedFocusableItems, Se as getNextKeyGridItem, Te as getNextKeyListItem, te as getPropertyChanges, ne as getThemeTokens, re as hasHorizontalScrollBar, ie as hasInvalidDOMGrid, ae as hasScrollBar, Xe as hostAttr, b as i18n, A as initializeKeyListItems, oe as isContextMenuClick, j as isFocusable, M as isImmediateRootActiveElement, o as isObject, s as isObjectLiteral, N as isSimpleFocusable, Ce as keyNavigationGrid, Ee as keyNavigationList, se as matchesElementName, dt as nonnegativeFiniteOr, C as onChildListMutation, lt as onKeys, P as onListboxActivate, ce as openEyeDropper, le as parseTokenNumber, c as parseVersion, at as popoverStyles, ft as positiveFiniteOr, ue as removeAnchorName, de as removeEmptySlotWhitespace, fe as removeEmptyTextNode, pe as sameOrderedStringArray, me as sameRenderRoot, Ze as scopedRegistry, he as scrollBarWidth, F as setActiveKeyListItem, n as shiftLeft, ge as slotContainsOnlyWhitespace, Fe as stateExpanded, Le as stateHighlighted, ze as stateScroll, Ve as stateSelected, st as statusIcons, $e as statusStateStyles, w as stopEvent, _e as styleSheetToString, et as supportStateStyles, nt as supportsCSSLegacyInsetArea, rt as supportsCSSPositionArea, it as supportsNativeCSSAnchorPosition, ve as supportsScopedRegistry, T as throttle, Ue as typeAnchor, Ye as typeSSR, ye as uniqueNonEmptyStrings, tt as useStyles, be as validKeyNavigationCode };
|
|
@@ -19,7 +19,7 @@ var a = class {
|
|
|
19
19
|
i18nRegistry: {},
|
|
20
20
|
audit: {}
|
|
21
21
|
}
|
|
22
|
-
}, globalThis.NVE_ELEMENTS.state.versions = Array.from(/* @__PURE__ */ new Set([...globalThis.NVE_ELEMENTS.state.versions, "2.
|
|
22
|
+
}, globalThis.NVE_ELEMENTS.state.versions = Array.from(/* @__PURE__ */ new Set([...globalThis.NVE_ELEMENTS.state.versions, "2.10.0"])), globalThis.NVE_ELEMENTS.state.scopedRegistry ??= {}, globalThis.NVE_ELEMENTS.state.scopedRegistry["2.10.0"] = i(), globalThis.NVE_ELEMENTS.state.versions.length > 1 && globalThis.NVE_ELEMENTS.state.env !== "production" && console.warn(e(), `\n\n${JSON.stringify(globalThis.NVE_ELEMENTS.state.versions, null, 2)}`);
|
|
23
23
|
}
|
|
24
24
|
get state() {
|
|
25
25
|
return globalThis.NVE_ELEMENTS.state;
|
|
@@ -16,6 +16,7 @@ export declare function getElementUpdate(element: HTMLElement, key: string, call
|
|
|
16
16
|
export declare function clickOutsideElementBounds(event: PointerEvent | MouseEvent, element: HTMLElement): boolean;
|
|
17
17
|
/** parses number out of basic calc generated by the design tokens */
|
|
18
18
|
export declare function parseTokenNumber(value: string): number;
|
|
19
|
+
export declare function getCustomElementRegistry(element: Element): CustomElementRegistry | undefined;
|
|
19
20
|
/** true if the browser supports scoped custom element registries */
|
|
20
21
|
export declare const supportsScopedRegistry: boolean;
|
|
21
22
|
/** defines an element with the given custom element registry */
|
|
@@ -31,7 +32,9 @@ export declare function getFlattenedFocusableItems(element: Node, depth?: number
|
|
|
31
32
|
* https://www.abeautifulsite.net/posts/querying-through-shadow-roots/
|
|
32
33
|
*/
|
|
33
34
|
export declare function getFlattenedDOMTree(node: Node, depth?: number): HTMLElement[];
|
|
34
|
-
export declare function validKeyNavigationCode(e: KeyboardEvent):
|
|
35
|
+
export declare function validKeyNavigationCode(e: KeyboardEvent): e is KeyboardEvent & {
|
|
36
|
+
code: KeynavCode;
|
|
37
|
+
};
|
|
35
38
|
export declare enum KeynavCode {
|
|
36
39
|
End = "End",
|
|
37
40
|
Home = "Home",
|
|
@@ -78,53 +78,57 @@ function d(e, t) {
|
|
|
78
78
|
function f(e) {
|
|
79
79
|
return parseInt(e.includes("calc") ? e.split("*")[1].replace("px)", "").trim() : e, 10) || 0;
|
|
80
80
|
}
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
function p(e) {
|
|
82
|
+
let t = e.getRootNode(), n = e.ownerDocument.defaultView?.CustomElementRegistry ?? globalThis.CustomElementRegistry;
|
|
83
|
+
return n && "customElementRegistry" in t && t.customElementRegistry instanceof n ? t.customElementRegistry : e.ownerDocument.defaultView?.customElements || (typeof customElements > "u" ? void 0 : customElements);
|
|
84
|
+
}
|
|
85
|
+
var m = globalThis.CustomElementRegistry && "initialize" in CustomElementRegistry.prototype;
|
|
86
|
+
function h(t, n) {
|
|
83
87
|
Object.entries(t.elementDefinitions ?? {}).filter(([e, t]) => !n.get(t.metadata.tag)).forEach(([e, t]) => {
|
|
84
|
-
|
|
88
|
+
h(t, n);
|
|
85
89
|
}), n.get(t.metadata.tag) || (n.define(t.metadata.tag, t), n === customElements && e.dispatch("NVE_ELEMENT_DEFINE", { elementRegistry: { [t.metadata.tag]: t.metadata.version } }));
|
|
86
90
|
}
|
|
87
|
-
function
|
|
91
|
+
function g(t) {
|
|
88
92
|
let { version: n } = t.metadata;
|
|
89
|
-
|
|
93
|
+
m && !customElements.get(t.metadata.tag) ? (customElements.define(t.metadata.tag, t), e.dispatch("NVE_ELEMENT_DEFINE", { elementRegistry: { [t.metadata.tag]: t.metadata.version } })) : h(t, customElements), e.state.elementRegistry[t.metadata.tag] !== n && globalThis?.location?.hostname === "localhost" && import("./audit-logs.js").then((e) => console.warn(e.getDuplicatePackageVersionWarning(t.metadata.tag, n)));
|
|
90
94
|
}
|
|
91
|
-
function
|
|
95
|
+
function _(e) {
|
|
92
96
|
return e.buttons === 2 && !e.ctrlKey || e.buttons === 1 && e.ctrlKey;
|
|
93
97
|
}
|
|
94
|
-
function _(e, t = 10) {
|
|
95
|
-
return v(e, t).filter((e) => n(e));
|
|
96
|
-
}
|
|
97
98
|
function v(e, t = 10) {
|
|
98
|
-
return
|
|
99
|
+
return y(e, t).filter((e) => n(e));
|
|
99
100
|
}
|
|
100
|
-
function y(e) {
|
|
101
|
-
return
|
|
101
|
+
function y(e, t = 10) {
|
|
102
|
+
return Array.from(r(e)).reduce((e, n) => [...e, [n, [...Array.from(r(n)).map((e) => [e, y(e, t)])]]], []).flat(t);
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
+
function b(e) {
|
|
105
|
+
return S.has(e.code);
|
|
106
|
+
}
|
|
107
|
+
var x = /* @__PURE__ */ function(e) {
|
|
104
108
|
return e.End = "End", e.Home = "Home", e.PageUp = "PageUp", e.PageDown = "PageDown", e.ArrowUp = "ArrowUp", e.ArrowDown = "ArrowDown", e.ArrowLeft = "ArrowLeft", e.ArrowRight = "ArrowRight", e;
|
|
105
|
-
}({}),
|
|
106
|
-
function
|
|
109
|
+
}({}), S = new Set(Object.values(x));
|
|
110
|
+
function C(e) {
|
|
107
111
|
return e.some((t) => t.children.length !== e[0].children.length);
|
|
108
112
|
}
|
|
109
|
-
function
|
|
113
|
+
function w(e) {
|
|
110
114
|
e?.wholeText?.trim() === "" && e.remove();
|
|
111
115
|
}
|
|
112
|
-
function
|
|
116
|
+
function T() {
|
|
113
117
|
let e = globalThis.document.createElement("div");
|
|
114
118
|
e.style.setProperty("width", "100px"), e.style.setProperty("height", "100px"), e.style.setProperty("overflow", "scroll"), e.style.setProperty("position", "absolute"), e.style.setProperty("top", "-9999px"), globalThis.document.body.appendChild(e);
|
|
115
119
|
let t = e.offsetWidth - e.clientWidth;
|
|
116
120
|
return globalThis.document.body.removeChild(e), t;
|
|
117
121
|
}
|
|
118
|
-
function
|
|
122
|
+
function E(e) {
|
|
119
123
|
return e.scrollHeight > e.clientHeight;
|
|
120
124
|
}
|
|
121
|
-
function
|
|
125
|
+
function D(e) {
|
|
122
126
|
return e.scrollWidth > e.clientWidth;
|
|
123
127
|
}
|
|
124
|
-
function
|
|
128
|
+
function O(e, t = 0) {
|
|
125
129
|
return e.scrollTop + e.offsetHeight + t >= e.scrollHeight;
|
|
126
130
|
}
|
|
127
|
-
async function
|
|
131
|
+
async function k() {
|
|
128
132
|
let e = globalThis.EyeDropper;
|
|
129
133
|
if (!e) return t.warn("EyeDropper API is unavailable"), "";
|
|
130
134
|
try {
|
|
@@ -133,7 +137,7 @@ async function O() {
|
|
|
133
137
|
return t.warn(`EyeDropper selection failed: ${e.message}`), "";
|
|
134
138
|
}
|
|
135
139
|
}
|
|
136
|
-
function
|
|
140
|
+
function A(e = globalThis.document.querySelector(":root")) {
|
|
137
141
|
let t = getComputedStyle(e), n = [];
|
|
138
142
|
try {
|
|
139
143
|
n = Array.from(globalThis.parent.document.styleSheets);
|
|
@@ -152,48 +156,48 @@ function k(e = globalThis.document.querySelector(":root")) {
|
|
|
152
156
|
[n[0]]: t.getPropertyValue(n[0])
|
|
153
157
|
}), {});
|
|
154
158
|
}
|
|
155
|
-
function A(e) {
|
|
156
|
-
j(e) && e.assignedNodes().forEach((e) => e.parentNode?.removeChild(e));
|
|
157
|
-
}
|
|
158
159
|
function j(e) {
|
|
160
|
+
M(e) && e.assignedNodes().forEach((e) => e.parentNode?.removeChild(e));
|
|
161
|
+
}
|
|
162
|
+
function M(e) {
|
|
159
163
|
let t = !e.assignedNodes().find((e) => e.nodeType !== Node.TEXT_NODE), n = !e.assignedNodes().find((e) => e.nodeType === Node.TEXT_NODE && (e.textContent ?? "").trim() !== "");
|
|
160
164
|
return t && n;
|
|
161
165
|
}
|
|
162
|
-
function
|
|
166
|
+
function N(e, t) {
|
|
163
167
|
let n = e.assignedNodes(), r = e.name ?? "slot";
|
|
164
168
|
n.length ? t._internals.states.add(`has-${r}`) : t._internals.states.delete(`has-${r}`);
|
|
165
169
|
}
|
|
166
|
-
function
|
|
170
|
+
function P(e) {
|
|
167
171
|
return e?.label || e?.value || "";
|
|
168
172
|
}
|
|
169
|
-
function
|
|
173
|
+
function F(e, t) {
|
|
170
174
|
return e.localName === t.metadata.tag;
|
|
171
175
|
}
|
|
172
|
-
function
|
|
176
|
+
function I(e) {
|
|
173
177
|
let t = globalThis.document.createElement("div"), { width: n } = e.getBoundingClientRect();
|
|
174
178
|
return t.setAttribute("nve-ghost", ""), t.style.minWidth = `${n}px`, t.style.maxWidth = `${n}px`, t.style.height = "1px", t.slot = e.slot, t;
|
|
175
179
|
}
|
|
176
|
-
function
|
|
180
|
+
function L(e, t) {
|
|
177
181
|
let n = e.getRootNode(), r = t.getRootNode(), i = n instanceof ShadowRoot && r instanceof ShadowRoot && n === r, a = n === globalThis.document && r === globalThis.document;
|
|
178
182
|
return i || a || n === r;
|
|
179
183
|
}
|
|
180
|
-
function
|
|
184
|
+
function R(e) {
|
|
181
185
|
return e.style.anchorName?.split(",")?.map((e) => e.trim())?.filter((e) => e !== "none" && e !== "") ?? [];
|
|
182
186
|
}
|
|
183
|
-
function R(e, t) {
|
|
184
|
-
let n = L(e);
|
|
185
|
-
e.style.anchorName = n.filter((e) => e !== t).join(",");
|
|
186
|
-
}
|
|
187
187
|
function z(e, t) {
|
|
188
|
-
|
|
188
|
+
let n = R(e);
|
|
189
|
+
e.style.anchorName = n.filter((e) => e !== t).join(",");
|
|
189
190
|
}
|
|
190
191
|
function B(e, t) {
|
|
192
|
+
e.style.anchorName = Array.from(/* @__PURE__ */ new Set([...R(e), t])).join(",");
|
|
193
|
+
}
|
|
194
|
+
function V(e, t) {
|
|
191
195
|
return e.length === t.length && e.every((e, n) => e === t[n]);
|
|
192
196
|
}
|
|
193
|
-
function
|
|
197
|
+
function H(e) {
|
|
194
198
|
return Array.from(new Set(Array.from(e).filter((e) => typeof e == "string" && e.length > 0)));
|
|
195
199
|
}
|
|
196
200
|
//#endregion
|
|
197
|
-
export {
|
|
201
|
+
export { x as KeynavCode, B as appendAnchorName, s as appendRootNodeStyle, N as applySlotContentStates, d as clickOutsideElementBounds, I as createGhostElement, g as define, h as defineElement, O as endOfScrollBox, i as generateId, R as getAnchorNames, a as getAttributeChanges, o as getAttributeListChanges, r as getChildren, p as getCustomElementRegistry, P as getDisplayValue, u as getElementUpdate, y as getFlattenedDOMTree, v as getFlattenedFocusableItems, l as getPropertyChanges, A as getThemeTokens, D as hasHorizontalScrollBar, C as hasInvalidDOMGrid, E as hasScrollBar, _ as isContextMenuClick, F as matchesElementName, k as openEyeDropper, f as parseTokenNumber, z as removeAnchorName, j as removeEmptySlotWhitespace, w as removeEmptyTextNode, V as sameOrderedStringArray, L as sameRenderRoot, T as scrollBarWidth, M as slotContainsOnlyWhitespace, c as styleSheetToString, m as supportsScopedRegistry, H as uniqueNonEmptyStrings, b as validKeyNavigationCode };
|
|
198
202
|
|
|
199
203
|
//# sourceMappingURL=dom.js.map
|