keystra 0.0.0-stage → 0.1.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +21 -0
  3. package/README.md +78 -2
  4. package/dist/chunk-2BLQUBG7.js +816 -0
  5. package/dist/chunk-77GGU3AX.js +135 -0
  6. package/dist/chunk-KDOJARJD.js +29 -0
  7. package/dist/chunk-LYYUOTBP.js +125 -0
  8. package/dist/chunk-S5YVXIMA.js +61 -0
  9. package/dist/chunk-SSIKGDD4.js +255 -0
  10. package/dist/chunk-U7YK6PPT.js +1729 -0
  11. package/dist/chunk-XFNYIPOW.js +253 -0
  12. package/dist/chunk-ZOJRXXQN.js +308 -0
  13. package/dist/core.cjs +2861 -0
  14. package/dist/core.d.cts +41 -0
  15. package/dist/core.d.ts +41 -0
  16. package/dist/core.js +7 -0
  17. package/dist/engine-COPfXXTp.d.ts +229 -0
  18. package/dist/engine-DcbkGRgz.d.cts +229 -0
  19. package/dist/focus.cjs +374 -0
  20. package/dist/focus.d.cts +74 -0
  21. package/dist/focus.d.ts +74 -0
  22. package/dist/focus.js +2 -0
  23. package/dist/index-IZkcWAXP.d.cts +395 -0
  24. package/dist/index-IZkcWAXP.d.ts +395 -0
  25. package/dist/index.cjs +3745 -0
  26. package/dist/index.d.cts +9 -0
  27. package/dist/index.d.ts +9 -0
  28. package/dist/index.global.js +1 -0
  29. package/dist/index.js +9 -0
  30. package/dist/layout-C2-n8aUI.d.ts +17 -0
  31. package/dist/layout-CBzD-87D.d.cts +17 -0
  32. package/dist/navigation.cjs +293 -0
  33. package/dist/navigation.d.cts +33 -0
  34. package/dist/navigation.d.ts +33 -0
  35. package/dist/navigation.js +2 -0
  36. package/dist/patterns.cjs +3505 -0
  37. package/dist/patterns.d.cts +12 -0
  38. package/dist/patterns.d.ts +12 -0
  39. package/dist/patterns.js +7 -0
  40. package/dist/roving-focus-CT7Dm6di.d.ts +63 -0
  41. package/dist/roving-focus-ZQ0v7hLe.d.cts +63 -0
  42. package/dist/selection.cjs +266 -0
  43. package/dist/selection.d.cts +43 -0
  44. package/dist/selection.d.ts +43 -0
  45. package/dist/selection.js +2 -0
  46. package/dist/utils-CkveVeIJ.d.cts +18 -0
  47. package/dist/utils-JmPZTlys.d.ts +18 -0
  48. package/dist/utils.cjs +195 -0
  49. package/dist/utils.d.cts +3 -0
  50. package/dist/utils.d.ts +3 -0
  51. package/dist/utils.js +2 -0
  52. package/package.json +147 -4
@@ -0,0 +1,9 @@
1
+ export { E as EventManager, I as ItemCollection, a as ItemCollectionOptions, K as KeyMatcher, M as MatchResult, N as NavigationController, R as ResolvedOptions, T as TypeaheadController, c as createKeyMatcher, b as createKeystra, d as createRafThrottle, e as createRectOf, f as createTypeahead, k as keyEquals, p as parseKeyBinding } from './engine-DcbkGRgz.cjs';
2
+ export { KeyBindingHandler, KeyBindingInfo, codeToKey, createKeyBinding, defaultKeysFor, describeEvent, formatKeyCombo, isModifierKey, isPrintableKey, mergeKeys, normalizeKeyEvent, normalizeKeyName, useKeystra } from './core.cjs';
3
+ export { CustomStrategyHooks, DirectionalOptions, GridStrategyOptions, actionDelta, actionToDirection, composeStrategies, createCustomStrategy, createDirectionalStrategy, createGridStrategy, createSequentialStrategy, directionFromAction, findNextIndex, horizontalStrategy, verticalStrategy } from './navigation.cjs';
4
+ export { FocusManager, FocusManagerOptions, RovingTabindex, RovingTabindexOptions } from './focus.cjs';
5
+ export { SelectionDiffHandler, SelectionManager } from './selection.cjs';
6
+ export { c as createCommandPalette, a as createDropdown, b as createGrid, d as createList, e as createMenu, f as createRovingFocus, g as createTabs, h as createTree } from './roving-focus-ZQ0v7hLe.cjs';
7
+ export { c as contains, f as focusElement, g as getText, h as hasDom, i as isDisabled, a as isEditableTarget, b as isFocusable, d as isHidden, q as queryItems, r as resolveElement, s as setAttribute, t as toggleClass } from './utils-CkveVeIJ.cjs';
8
+ export { E as Emitter, L as LayoutCache } from './layout-CBzD-87D.cjs';
9
+ export { A as AutoFocusOptions, B as BaseOptions, C as CommandPaletteInstance, a as CommandPaletteOptions, D as DefaultKeyMap, b as Direction, c as DropdownInstance, d as DropdownOptions, E as ElementTarget, e as EventHandler, f as EventName, g as EventPayload, G as GridInstance, h as GridOptions, H as HookOptions, I as ItemSelector, K as KeyAction, i as KeyBinding, j as KeyBindingHandle, k as KeyBindingInput, l as KeyBindingObject, m as KeyBindingOptions, n as KeyMap, o as KeySequenceBinding, p as KeySequenceInput, q as KeySequenceOptions, r as KeystraEventMap, s as KeystraHandle, t as KeystraInstance, u as KeystraOptions, L as ListOptions, M as MenuInstance, v as MenuOptions, N as NavigationMode, w as NavigationStrategy, x as NavigationStrategyContext, y as NormalizedKeyEvent, P as ParsedKeyBinding, R as RovingFocusOptions, z as RovingOptions, S as SelectionController, F as SelectionMode, J as SelectionOptions, T as TabsInstance, O as TabsOptions, Q as TreeInstance, U as TreeOptions, V as TypeaheadOptions, W as Unsubscribe } from './index-IZkcWAXP.cjs';
@@ -0,0 +1,9 @@
1
+ export { E as EventManager, I as ItemCollection, a as ItemCollectionOptions, K as KeyMatcher, M as MatchResult, N as NavigationController, R as ResolvedOptions, T as TypeaheadController, c as createKeyMatcher, b as createKeystra, d as createRafThrottle, e as createRectOf, f as createTypeahead, k as keyEquals, p as parseKeyBinding } from './engine-COPfXXTp.js';
2
+ export { KeyBindingHandler, KeyBindingInfo, codeToKey, createKeyBinding, defaultKeysFor, describeEvent, formatKeyCombo, isModifierKey, isPrintableKey, mergeKeys, normalizeKeyEvent, normalizeKeyName, useKeystra } from './core.js';
3
+ export { CustomStrategyHooks, DirectionalOptions, GridStrategyOptions, actionDelta, actionToDirection, composeStrategies, createCustomStrategy, createDirectionalStrategy, createGridStrategy, createSequentialStrategy, directionFromAction, findNextIndex, horizontalStrategy, verticalStrategy } from './navigation.js';
4
+ export { FocusManager, FocusManagerOptions, RovingTabindex, RovingTabindexOptions } from './focus.js';
5
+ export { SelectionDiffHandler, SelectionManager } from './selection.js';
6
+ export { c as createCommandPalette, a as createDropdown, b as createGrid, d as createList, e as createMenu, f as createRovingFocus, g as createTabs, h as createTree } from './roving-focus-CT7Dm6di.js';
7
+ export { c as contains, f as focusElement, g as getText, h as hasDom, i as isDisabled, a as isEditableTarget, b as isFocusable, d as isHidden, q as queryItems, r as resolveElement, s as setAttribute, t as toggleClass } from './utils-JmPZTlys.js';
8
+ export { E as Emitter, L as LayoutCache } from './layout-C2-n8aUI.js';
9
+ export { A as AutoFocusOptions, B as BaseOptions, C as CommandPaletteInstance, a as CommandPaletteOptions, D as DefaultKeyMap, b as Direction, c as DropdownInstance, d as DropdownOptions, E as ElementTarget, e as EventHandler, f as EventName, g as EventPayload, G as GridInstance, h as GridOptions, H as HookOptions, I as ItemSelector, K as KeyAction, i as KeyBinding, j as KeyBindingHandle, k as KeyBindingInput, l as KeyBindingObject, m as KeyBindingOptions, n as KeyMap, o as KeySequenceBinding, p as KeySequenceInput, q as KeySequenceOptions, r as KeystraEventMap, s as KeystraHandle, t as KeystraInstance, u as KeystraOptions, L as ListOptions, M as MenuInstance, v as MenuOptions, N as NavigationMode, w as NavigationStrategy, x as NavigationStrategyContext, y as NormalizedKeyEvent, P as ParsedKeyBinding, R as RovingFocusOptions, z as RovingOptions, S as SelectionController, F as SelectionMode, J as SelectionOptions, T as TabsInstance, O as TabsOptions, Q as TreeInstance, U as TreeOptions, V as TypeaheadOptions, W as Unsubscribe } from './index-IZkcWAXP.js';
@@ -0,0 +1 @@
1
+ var Keystra=(function(exports){'use strict';function Ke(){return typeof globalThis<"u"&&typeof globalThis.document<"u"}function b(i,e=null){if(i==null)return null;if(typeof i=="function")return b(i(),e);if(typeof i=="string"){let t=e??(Ke()?document:null);if(!t)return null;try{return t.querySelector(i)}catch{return null}}return i}function P(i,e){if(!i)return [];if(typeof e=="function"){let t=e(i);return Array.from(t)}if(!e)return [];try{return Array.from(i.querySelectorAll(e))}catch{return []}}var Ie="[disabled],[aria-disabled='true']";function R(i,e=Ie){if(!e)return false;if(i.disabled===true||i.getAttribute("aria-disabled")==="true")return true;if(e===Ie)return i.hasAttribute("disabled");try{return i.matches(e)}catch{return false}}function F(i){let e=i,t=e;if(typeof t.checkVisibility=="function")try{return !t.checkVisibility.call(e,{checkOpacity:!1,checkVisibilityCSS:!0})}catch{}let n=e;for(;n&&n.nodeType===1;){if(n.hidden===true||n.style&&n.style.display==="none")return true;n=n.parentElement;}return false}function Je(i){return typeof i.focus!="function"||R(i)?false:!F(i)}var Se="input:not([type='hidden']):not([readonly]),textarea:not([readonly]),select,[contenteditable=''],[contenteditable='true'],[iscontenteditable]";function z(i,e){if(!i||typeof i.matches!="function")return false;let t=i,n=e?`${Se},${e}`:Se;try{if(t.matches(n))return !0}catch{}return t.isContentEditable===true}function se(i){return (i.getAttribute("aria-label")??i.textContent??"").replace(/\s+/g," ").trim()}function q(i,e,t){t===null?i.removeAttribute(e):i.getAttribute(e)!==t&&i.setAttribute(e,t);}function te(i,e,t){if(!e)return;let n=i;typeof n.classList?.toggle=="function"&&n.classList.toggle(e,t);}function L(i,e=true){if(typeof i.focus!="function")return false;try{i.focus({preventScroll:e});}catch{try{i.focus();}catch{return false}}return true}function T(i,e){if(!i||!e)return false;if(i===e)return true;if(typeof i.contains=="function")return i.contains(e);let t=e;for(;t;){if(t===i)return true;t=t.parentNode;}return false}function U(i){return i==null?null:typeof i=="string"?b(i):typeof i=="function"?U(i()):i}var Oe=0;function H(i,e){let t=i.id;if(t)return t;Oe+=1;let n=`${e}-${Oe}`;return i.id=n,n}var _=class{constructor(e={}){this.current=new WeakMap;this.originals=new Map;this.active=null;this.respectNegative=e.respectNegative!==false,this.disabled=e.disabled===true;}get activeElement(){return this.active}sync(e,t){if(this.disabled)return;let n=e?this.desiredFor(e):null;for(let r=0;r<t.length;r++){let s=t[r];s!==e&&this.write(s,"-1");}this.active=e,e&&n!==null&&this.write(e,n),this.forgetDetached(t.length);}move(e){if(this.disabled)return;let t=this.desiredFor(e);this.active&&this.active!==e&&this.write(this.active,"-1"),this.active=e,this.write(e,t);}forgetDetached(e){if(!(this.originals.size<=e))for(let t of this.originals.keys())t.isConnected||this.originals.delete(t);}authoredTabStop(e){for(let t=0;t<e.length;t++){let n=e[t];if((this.originals.has(n)?this.originals.get(n):n.getAttribute("tabindex"))==="0")return n}return null}apply(e){this.disabled||(this.active=e,e&&this.write(e,this.desiredFor(e)));}desiredFor(e){return this.respectNegative&&(this.originals.has(e)?this.originals.get(e):e.getAttribute("tabindex"))==="-1"?"-1":"0"}write(e,t){this.current.get(e)!==t&&(this.originals.has(e)||this.originals.set(e,e.getAttribute("tabindex")),e.setAttribute("tabindex",t),this.current.set(e,t));}restore(){for(let[e,t]of this.originals)t===null?e.removeAttribute("tabindex"):e.setAttribute("tabindex",t),this.current.delete(e);this.originals.clear(),this.active=null;}get touched(){return this.originals.size}};var j=class{constructor(e={}){this.items=[];this.activeElement=null;this.activeIndex=-1;this.outsideElement=null;this.lastInsideElement=null;this.lastKnownIndex=0;this.cleared=false;this.started=false;this.container=null;this.markedOption=null;this.options=e,this.virtual=e.virtual===true;let t=e.roving;this.rovingEnabled=t!==false&&(typeof t!="object"||t.enabled!==false),this.roving=new _({disabled:!this.rovingEnabled,respectNegative:typeof t=="object"?t.force!==true:true});}get element(){return this.activeElement}get index(){return this.activeIndex}get focusedIndex(){if(this.activeIndex<0)return -1;if(this.virtual)return this.activeIndex;if(typeof document>"u")return this.activeIndex;let e=document.activeElement,t=this.activeElement;return t?e===t?this.activeIndex:e&&T(t,e)?this.activeIndex:-1:-1}get previousElement(){return this.outsideElement}get lastFocused(){return this.lastInsideElement}sync(e,t){let n=this.activeElement;if(this.activeIndex>=0&&(this.lastKnownIndex=this.activeIndex),this.items=e,t!==void 0&&(this.container=t),n){let o=e.indexOf(n);if(o!==-1&&this.isUsable(n))return this.activeIndex=o,this.promote(n,e),o}let r=n||!this.cleared?this.readActiveFromDocument(t):-1;if(r>=0){let o=e[r];return this.activeElement=o,this.activeIndex=r,this.lastInsideElement=o,this.lastKnownIndex=r,this.promote(o,e),r}this.activeElement=null,this.activeIndex=-1;let s=null;if(n&&e.length>0){let o=this.lastKnownIndex;s=e[Math.min(o,e.length-1)]??e[0]??null;}else if(!this.started&&e.length>0){s=this.roving.authoredTabStop(e)??e[0]??null;let o=s?e.indexOf(s):-1;o>0&&s&&this.isUsable(s)&&(this.activeElement=s,this.activeIndex=o,this.lastInsideElement=s,this.lastKnownIndex=o);}else s=e[0]??null;return this.started=true,this.promote(s,e),this.activeIndex}promote(e,t){this.roving.sync(this.virtual?null:e,t),this.writeActiveDescendant(this.virtual?e:null);}writeActiveDescendant(e){if(!this.virtual)return;this.markOption(e);let t=this.options.descendantOwner?.()??null;if(!t)return;if(!e){t.hasAttribute("aria-activedescendant")&&t.removeAttribute("aria-activedescendant");return}let n=H(e,"keystra-item");t.getAttribute("aria-activedescendant")!==n&&t.setAttribute("aria-activedescendant",n);}markOption(e){this.markedOption!==e&&(this.markedOption&&this.markedOption.setAttribute("aria-selected","false"),this.markedOption=e?.getAttribute("role")==="option"?e:null,this.markedOption&&this.markedOption.setAttribute("aria-selected","true"));}observe(e,t){if(!e||t&&!T(t,e))return;let n=this.items.indexOf(e);if(n===-1)return;let r=this.items[n];this.activeElement=r,this.activeIndex=n,this.lastInsideElement=r,this.lastKnownIndex=n,this.virtual||this.roving.apply(r),this.writeActiveDescendant(r);}focusIndex(e,t=null,n,r=true){let s=this.items;if(e<0||e>=s.length)return null;let o=s[e];if(!this.isUsable(o))return null;let l=this.activeElement;if(l&&l!==o){let a=s.indexOf(l);a!==-1&&this.options.onBlur?.(l,a);}return this.captureOutside(l),this.activeElement=o,this.activeIndex=e,this.cleared=false,this.lastInsideElement=o,this.lastKnownIndex=e,this.virtual?this.writeActiveDescendant(o):this.roving.move(o),r&&!this.virtual&&L(o,n??this.options.preventScroll!==false),this.options.onFocus?.(o,e,t),o}setActiveIndex(e){let t=e>=0?this.items[e]??null:null;this.activeElement=t,this.activeIndex=t?e:-1,t?(this.cleared=false,this.lastInsideElement=t,this.lastKnownIndex=e):this.cleared=e<0,this.promote(t??this.items[0]??null,this.items);}focusElement(e,t=null){if(!e)return false;let n=this.items.indexOf(e);return n===-1?false:this.focusIndex(n,t)!==null}restore(){let e=this.outsideElement;return e&&typeof e.focus=="function"&&!F(e)&&!R(e)?(L(e,this.options.preventScroll!==false),true):this.virtual?false:this.lastInsideElement&&this.items.indexOf(this.lastInsideElement)!==-1?this.focusElement(this.lastInsideElement):this.focusIndex(this.activeIndex)!==null}remember(e){e&&(this.outsideElement=e);}clear(){this.activeElement=null,this.activeIndex=-1,this.items=[],this.lastInsideElement=null,this.lastKnownIndex=0;}dispose(){this.writeActiveDescendant(null),this.roving.restore(),this.clear(),this.outsideElement=null;}isUsable(e){return !(!e||R(e,this.options.disabledSelector??null)||this.options.skipHidden!==false&&F(e))}captureOutside(e){if(typeof document>"u")return;let t=document.activeElement;!t||t===document.body||t===document.documentElement||e&&t===e||this.items.indexOf(t)===-1&&(this.container&&T(this.container,t)||(this.outsideElement=t));}readActiveFromDocument(e){if(typeof document>"u")return -1;let t=document.activeElement;if(!t||t===document.body)return -1;let n=this.items.indexOf(t);if(n!==-1)return n;if(e){for(let r=0;r<this.items.length;r++)if(T(this.items[r],t))return r}return -1}};var G=class{constructor(e={}){this.selectedItems=[];this.itemsValue=[];this.provider=null;this.anchorElement=null;this.touched=new Set;this.onDiff=null;this.needsInitial=true;this.options=e,this.modeValue=e.mode??"single",this.attribute=e.attribute??null,this.selectedClass=e.selectedClass,this.aria=e.aria===true;}get mode(){return this.modeValue}get selected(){return this.selectedItems}get items(){return this.provider?this.provider():this.itemsValue}get selectedIndexes(){let e=[];for(let t=0;t<this.selectedItems.length;t++){let n=this.items.indexOf(this.selectedItems[t]);n!==-1&&e.push(n);}return e.sort((t,n)=>t-n)}get anchor(){return this.anchorElement}get size(){return this.selectedItems.length}bindItems(e){this.provider=e;}setDiffHandler(e){this.onDiff=e;}sync(e){if(this.itemsValue===e&&!this.needsInitial)return;this.itemsValue=e;let t=this.items;if(this.needsInitial&&(this.needsInitial=false,this.applyInitial(this.options.initial)),this.aria||this.attribute||this.selectedClass)for(let s=0;s<t.length;s++){let o=t[s];this.paint(o,this.selectedItems.indexOf(o)!==-1);}if(this.touched.size>t.length)for(let s of this.touched)!s.isConnected&&this.selectedItems.indexOf(s)===-1&&this.touched.delete(s);if(this.selectedItems.length===0&&this.anchorElement===null)return;let n=false,r=[];for(let s of this.selectedItems)t.indexOf(s)!==-1?r.push(s):(this.paint(s,false),n=true);if(this.anchorElement&&t.indexOf(this.anchorElement)===-1&&(this.anchorElement=r[0]??null,n=true),n){let s=this.selectedItems;this.selectedItems=r,this.options.onChange?.(this.selectedItems),this.onDiff?.(this.selectedItems,[],s.filter(o=>r.indexOf(o)===-1));}}applyInitial(e){if(e==null)return;let t=this.items;if(typeof e=="number"){let r=t[e];r&&this.select(r);return}let n=Array.isArray(e)?e:[e];for(let r of n)r&&this.select(r,this.modeValue!=="single");}select(e,t=false){if(this.modeValue==="none")return;let n=this.resolve(e);if(n){if(this.modeValue==="single"||!t&&this.modeValue!=="multiple"){if(this.selectedItems.length===1&&this.selectedItems[0]===n){this.anchorElement=n;return}let r=this.selectedItems.slice();this.selectedItems=[n],this.anchorElement=n;for(let s of r)this.paint(s,false);this.paint(n,true),this.emit(r);return}if(this.modeValue==="range"&&t&&this.anchorElement){this.selectRange(this.anchorElement,n);return}if(this.selectedItems.indexOf(n)===-1){let r=this.selectedItems.slice();this.selectedItems.push(n),this.paint(n,true),this.emit(r);}this.anchorElement||(this.anchorElement=n);}}toggle(e){if(this.modeValue==="none")return;let t=this.resolve(e);if(!t)return;if(this.modeValue==="single"){this.selectedItems[0]===t?this.clear():this.select(t);return}let n=this.selectedItems.slice(),r=n.indexOf(t);r===-1?(this.selectedItems.push(t),this.paint(t,true)):(this.selectedItems.splice(r,1),this.paint(t,false),this.anchorElement===t&&(this.anchorElement=this.selectedItems[0]??null)),this.emit(n),!this.anchorElement&&r===-1&&(this.anchorElement=t);}deselect(e){let t=this.resolve(e);if(!t)return;let n=this.selectedItems.indexOf(t);if(n===-1)return;let r=this.selectedItems.slice();this.selectedItems.splice(n,1),this.paint(t,false),this.anchorElement===t&&(this.anchorElement=this.selectedItems[0]??null),this.emit(r);}selectRange(e,t){if(this.modeValue==="none")return;let n=this.resolve(e),r=this.resolve(t);if(!n||!r)return;let s=this.items.indexOf(n),o=this.items.indexOf(r);if(s===-1||o===-1)return;if(s>o){let u=s;s=o,o=u;}let l=this.selectedItems.slice(),a=[];for(let u=s;u<=o;u++){let c=this.items[u];c&&a.push(c);}this.selectedItems=a,this.anchorElement=n;for(let u of l)a.indexOf(u)===-1&&this.paint(u,false);for(let u of a)this.paint(u,true);this.emit(l);}selectAll(){if(this.modeValue==="none"||this.modeValue==="single"){this.modeValue==="single"&&this.items[0]&&this.select(this.items[0]);return}let e=this.selectedItems.slice();this.selectedItems=this.items.slice();for(let t of this.selectedItems)this.paint(t,true);this.anchorElement=this.items[0]??null,this.emit(e);}clear(){if(this.selectedItems.length===0&&!this.anchorElement)return;let e=this.selectedItems.slice();this.selectedItems=[],this.anchorElement=null;for(let t of e)this.paint(t,false);this.emit(e);}isSelected(e){let t=this.resolve(e);return t!==null&&this.selectedItems.indexOf(t)!==-1}indexOfSelected(e){return this.selectedItems.indexOf(e)}setMode(e){if(e!==this.modeValue){if(this.modeValue=e,e==="single"&&this.selectedItems.length>1){let t=this.selectedItems.slice();this.selectedItems=t.slice(0,1);for(let n of t)this.selectedItems.indexOf(n)===-1&&this.paint(n,false);this.emit(t);}e==="none"&&this.clear();}}dispose(){this.provider=null;for(let e of this.touched)this.aria&&q(e,"aria-selected",null),this.attribute&&e.removeAttribute(this.attribute),te(e,this.selectedClass,false);this.touched.clear(),this.selectedItems=[],this.anchorElement=null,this.itemsValue=[];}resolve(e){return e==null?null:typeof e=="number"?this.items[e]??null:e}paint(e,t){this.touched.add(e),this.aria&&q(e,"aria-selected",t?"true":"false"),this.attribute&&q(e,this.attribute,t?"true":null),te(e,this.selectedClass,t);}emit(e){let t=this.selectedItems.filter(r=>e.indexOf(r)===-1),n=e.filter(r=>this.selectedItems.indexOf(r)===-1);t.length===0&&n.length===0||(this.options.onChange?.(this.selectedItems),this.onDiff?.(this.selectedItems,t,n));}};function Me(i){switch(i){case "up":return "up";case "down":return "down";case "left":return "left";case "right":return "right";default:return null}}function oe(i={}){let e=i.crossAxisWeight??2;return t=>{let n=t.direction??Me(t.action);if(!n)return null;let r=t.items,s=r.length;if(s===0)return -1;let o=t.index;if(o<0||o>=s)return n==="down"||n==="right"?0:s-1;let l=r[o];if(!l)return null;let a=t.rectOf(l),u=a.left+a.width/2,c=a.top+a.height/2,d=n==="left"||n==="right",m=n==="right"||n==="down"?1:-1,g=-1,f=1/0,v=-1,h=1/0;for(let y=0;y<s;y++){if(y===o)continue;let A=r[y],S=t.rectOf(A);if(S.width===0&&S.height===0)continue;let K=S.left+S.width/2-u,C=S.top+S.height/2-c,p=Math.hypot(K,C);p<h&&(h=p,v=y);let N=(d?K:C)*m;if(N<=0)continue;let ee=Math.abs(d?C:K);if(ee>N)continue;let we=N+ee*e;we<f&&(f=we,g=y);}return g!==-1?g:i.wrapFallback??t.loop?v:null}}function Xe(i){let e=i.items,t=e.length;if(t===0)return {starts:[0],columns:1};let n=[0],r=i.rectOf(e[0]).top,s=1,o=1;for(let l=1;l<t;l++){let a=i.rectOf(e[l]);if(Math.abs(a.top-r)<2){s++;continue}o=Math.max(o,s),s=1,r=a.top,n.push(l);}return {starts:n,columns:Math.max(o,s)}}function et(i,e){let t=[];for(let n=0;n<i;n+=e)t.push(n);return t.length===0&&t.push(0),{starts:t,columns:e}}function le(i,e){let t=i.starts,n=0;for(let r=0;r<t.length&&t[r]<=e;r++)n=r;return n}function ae(i,e){return i.starts[e]??0}function ue(i,e,t){return e+1<i.starts.length?i.starts[e+1]-1:t-1}function W(i={}){let e=i.maintainColumn!==false,t=i.rowHomeEnd===true,n=i.columns&&i.columns>0?i.columns:0,r=-1,s=null,o={starts:[0],columns:1};return l=>{let a=l.items,u=a.length;if(u===0)return -1;let c=n||l.columns,d=l.index,m=l.direction??De(l.action);if(!m){if(l.action==="first"){if(!t||d<0)return 0;let p=C(l,c,u);return ae(p,le(p,d))}if(l.action==="last"){if(!t||d<0)return u-1;let p=C(l,c,u);return ue(p,le(p,d),u)}return null}if(d<0||d>=u)return m==="down"||m==="right"?0:u-1;let g=C(l,c,u),f=le(g,d),v=ae(g,f),h=ue(g,f,u);if(m==="left"||m==="right"){let p=d+(m==="right"?1:-1);return p>=v&&p<=h?p:l.loop?m==="right"?v:h:d}let y=f+(m==="down"?1:-1);if(y<0||y>=g.starts.length){if(!l.loop)return d;y=y<0?g.starts.length-1:0;}let A=ae(g,y),S=ue(g,y,u);if(c>0&&!e)return A;if(c>0){let p=d-v,N=A+p;return N<=S?N:S}let K=l.rectOf(a[d]);return tt(l,A,S,K.left+K.width/2);function C(p,N,ee){return N>0?et(ee,N):(r===p.version&&s===p.items||(o=Xe(p),r=p.version,s=p.items),o)}}}function tt(i,e,t,n){let r=e,s=1/0;for(let o=e;o<=t;o++){let l=i.items[o];if(!l)continue;let a=i.rectOf(l),u=Math.abs(a.left+a.width/2-n);u<s&&(s=u,r=o);}return r}function De(i){switch(i){case "up":case "previous":return "up";case "down":case "next":return "down";case "left":return "left";case "right":return "right";default:return null}}function Ce(i,e,t,n,r=true){if(i===0||t===0)return -1;if(e<0||e>=i)return t>0?0:i-1;let s=e+t;return n?(s%i+i)%i:s<0?r?0:-1:s>=i?r?i-1:-1:s}function Le(i,e){if(e)return e==="down"||e==="right"?1:e==="up"||e==="left"?-1:0;switch(i){case "next":case "down":case "right":return 1;case "previous":case "up":case "left":return -1;default:return 0}}function V(i="both"){return e=>{let{action:t,direction:n,index:r,items:s,loop:o}=e,l=Le(t,n);if(l===0)return null;let a=n!==null?n==="up"||n==="down":t==="up"||t==="down";return i==="vertical"&&!a&&n!==null||i==="horizontal"&&a?null:Ce(s.length,r,l,o)}}var nt=V("vertical"),it=V("horizontal");var Y=class{constructor(){this.handlers=null;}on(e,t){this.handlers||(this.handlers=new Map);let n=this.handlers.get(e);n||(n=new Set,this.handlers.set(e,n)),n.add(t);let r=false;return ()=>{r||(r=true,this.off(e,t));}}off(e,t){let n=this.handlers?.get(e);n&&(t?n.delete(t):n.clear(),n.size===0&&this.handlers?.delete(e));}emit(e,t){let n=this.handlers?.get(e);if(!(!n||n.size===0))for(let r of Array.from(n))r(t);}clear(){this.handlers?.clear(),this.handlers=null;}get size(){if(!this.handlers)return 0;let e=0;for(let t of this.handlers.values())e+=t.size;return e}};var ce={first:["Home"],last:["End"],pageUp:["PageUp"],pageDown:["PageDown"],escape:["Escape"],selectAll:["Ctrl+A","Meta+A"]},rt={up:["ArrowUp"],down:["ArrowDown"],next:["ArrowDown"],previous:["ArrowUp"],toggle:["Space"],select:["Enter","Space"],...ce},st={left:["ArrowLeft"],right:["ArrowRight"],next:["ArrowRight"],previous:["ArrowLeft"],toggle:["Space"],select:["Enter","Space"],...ce},He={up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"],next:["ArrowDown","ArrowRight"],previous:["ArrowUp","ArrowLeft"],toggle:["Space"],select:["Enter","Space"],...ce},Ne={left:["ArrowLeft"],right:["ArrowRight"],next:["ArrowRight"],previous:["ArrowLeft"],first:["Home"],last:["End"],select:["Enter","Space"],escape:["Escape"]},ke={up:["ArrowUp"],down:["ArrowDown"],next:["ArrowDown"],previous:["ArrowUp"],first:["Home"],last:["End"],select:["Enter","Space"],escape:["Escape"]},ot={up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"],next:["ArrowDown"],previous:["ArrowUp"],first:["Home"],last:["End"],pageUp:["PageUp"],pageDown:["PageDown"],select:["Enter","Space"],escape:["Escape"]},Re={up:["ArrowUp"],down:["ArrowDown"],next:["ArrowDown"],previous:["ArrowUp"],first:["Home"],last:["End"],select:["Enter","Space"],escape:["Escape"]},Fe={up:["ArrowUp"],down:["ArrowDown"],next:["ArrowDown"],previous:["ArrowUp"],expand:["ArrowRight"],collapse:["ArrowLeft"],first:["Home"],last:["End"],select:["Enter","Space"],escape:["Escape"]},qe={up:["ArrowUp"],down:["ArrowDown"],next:["ArrowDown"],previous:["ArrowUp"],first:["Home"],last:["End"],pageUp:["PageUp"],pageDown:["PageDown"],toggle:["Space"],select:["Enter"],selectAll:["Ctrl+A","Meta+A"],escape:["Escape"]},Pe={up:["ArrowUp"],down:["ArrowDown"],next:["ArrowDown"],previous:["ArrowUp"],pageUp:["PageUp"],pageDown:["PageDown"],select:["Enter"],escape:["Escape"]};function ne(i){switch(i){case "horizontal":return st;case "grid":case "directional":return ot;default:return rt}}function ie(i,e,t){if(!t)return {...e??{}};let n={...i};if(e)for(let r of Object.keys(e)){let s=e[r];s!==void 0&&(s===false||s===null?delete n[r]:n[r]=s);}return n}var M=class{constructor(){this.records=[];}add(e,t,n,r){if(!e||typeof e.addEventListener!="function")return ()=>{};e.addEventListener(t,n,r);let s={target:e,type:t,listener:n,options:r??false};return this.records.push(s),()=>this.removeRecord(s)}removeRecord(e){let t=this.records.indexOf(e);t!==-1&&(this.records.splice(t,1),e.target.removeEventListener(e.type,e.listener,e.options));}dispose(){for(let e=this.records.length-1;e>=0;e--){let t=this.records[e];t.target.removeEventListener(t.type,t.listener,t.options);}this.records.length=0;}get count(){return this.records.length}};function lt(i){let e=false,t=typeof globalThis.requestAnimationFrame=="function"?globalThis.requestAnimationFrame.bind(globalThis):s=>setTimeout(s,16),n=typeof globalThis.cancelAnimationFrame=="function"?globalThis.cancelAnimationFrame.bind(globalThis):s=>clearTimeout(s),r=null;return {schedule(){e||(e=true,r=t(()=>{e=false,r=null,i();}));},cancel(){r!==null&&n(r),r=null,e=false;}}}var $=class{constructor(){this.rects=new WeakMap;}rect(e,t){let n=this.rects.get(e);if(n&&n.version===t)return n.rect;let r=e.getBoundingClientRect();return this.rects.set(e,{version:t,rect:r}),r}};var B=new Map;function Ve(i){i&&B.set(i,(B.get(i)??0)+1);}function Be(i){if(!i)return;let e=B.get(i)??0;e<=1?B.delete(i):B.set(i,e-1);}function at(i){let e=[];if(!i)return e;for(let t of B.keys())t!==i&&i.contains(t)&&e.push(t);return e}var Q=class{constructor(e,t,n){this.container=e;this.options=t;this.onInvalidate=n;this.list=[];this.extra=[];this.removed=new WeakSet;this.explicit=null;this.built=false;this.observer=null;this.observerKey="";this.layout=new $;this._version=0;Ve(e);}get version(){return this._version}get items(){return this.built||this.build(),this.list}get size(){return this.items.length}setContainer(e){this.container!==e&&(Be(this.container),Ve(e),this.container=e,this.invalidate());}setItems(e){this.explicit=e?e.slice():null,this.invalidate();}add(e){let t=Array.isArray(e)?e:[e];for(let n of t)!n||this.extra.includes(n)||(this.removed.delete(n),this.extra.push(n));this.invalidate();}remove(e){let t=Array.isArray(e)?e:[e];for(let n of t){let r=this.extra.indexOf(n);r!==-1&&this.extra.splice(r,1),this.removed.add(n);}this.invalidate();}invalidate(){this.built=false,this.onInvalidate?.();}refresh(){return this.build(),this.list}revalidate(){if(this.observer)return;let e=this.list;this.build(),this.list!==e&&this.onInvalidate?.();}indexOf(e){return e?this.items.indexOf(e):-1}at(e){return this.items[e]??null}startObserving(){if(!this.options.observe){this.stopObserving();return}let e=`${this.container?"c":"n"}:${JSON.stringify(this.options.observe)}`;if(this.observer&&this.observerKey===e||(this.stopObserving(),!this.container||typeof MutationObserver!="function"))return;let t=typeof this.options.observe=="object"?this.options.observe:{childList:true,subtree:true,attributes:true,attributeFilter:["disabled","aria-disabled","hidden","style","class"]};this.observer=new MutationObserver(()=>this.invalidate()),this.observer.observe(this.container,t),this.observerKey=e;}stopObserving(){this.observer&&(this.observer.disconnect(),this.observer=null,this.observerKey="");}dispose(){this.stopObserving(),Be(this.container),this.list=[],this.extra=[],this.removed=new WeakSet,this.explicit=null,this.built=false,this.container=null,this.onInvalidate=void 0;}build(){let{selector:e,disabledSelector:t,skipHidden:n,filter:r}=this.options,s,o=[];if(this.explicit)s=this.explicit.slice();else if(s=P(this.container,e),o=at(this.container),this.extra.length>0){let a=s.slice();for(let u of this.extra)a.includes(u)||a.push(u);s=ct(a);}let l=[];for(let a=0;a<s.length;a++){let u=s[a];!u||this.removed.has(u)||o.length>0&&o.some(c=>c!==u&&c.contains(u))||t&&R(u,t)||n&&F(u)||r&&!r(u,l.length)||l.push(u);}if(ut(this.list,l)){this.built=true,this.startObserving();return}this._version++,this.list=l,this.built=true,this.startObserving();}};function ut(i,e){if(i.length!==e.length)return false;for(let t=0;t<i.length;t++)if(i[t]!==e[t])return false;return true}function ct(i){return i.length<2||typeof document>"u"||i[0]?.compareDocumentPosition==null?i:i.slice().sort((e,t)=>{if(e===t)return 0;let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0})}function de(i){return e=>i.layout.rect(e,i.version)}var dt={spacebar:"Space"," ":"Space",esc:"Escape",del:"Delete",left:"ArrowLeft",right:"ArrowRight",up:"ArrowUp",down:"ArrowDown",multiply:"*",add:"+",subtract:"-",divide:"/",decimal:".",windows:"Meta",cmd:"Meta",command:"Meta",option:"Alt",control:"Control",return:"Enter",cr:"Enter",pageup:"PageUp",pagedown:"PageDown","page up":"PageUp","page down":"PageDown"},ht=new Set(["arrowup","arrowdown","arrowleft","arrowright","enter","escape","tab","space","home","end","pageup","pagedown","backspace","delete","insert","shift","control","alt","meta","capslock","contextmenu","f1","f2","f3","f4","f5","f6","f7","f8","f9","f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20","f21","f22","f23","f24","printscreen","scrolllock","pause","unidentified"]);function Z(i){if(!i)return "";let e=i.toLowerCase(),t=dt[e];return t!==void 0?t:i.length===1?i:ht.has(e)?ft(e):i}function ft(i){switch(i){case "arrowup":return "ArrowUp";case "arrowdown":return "ArrowDown";case "arrowleft":return "ArrowLeft";case "arrowright":return "ArrowRight";case "pageup":return "PageUp";case "pagedown":return "PageDown";case "capslock":return "CapsLock";case "contextmenu":return "ContextMenu";case "printscreen":return "PrintScreen";case "scrolllock":return "ScrollLock";case "unidentified":return "Unidentified";default:return i.charAt(0).toUpperCase()+i.slice(1)}}var mt=new Set(["Shift","Control","Alt","Meta","CapsLock","Tab","Enter","Escape","Backspace","Delete","Insert","Home","End","PageUp","PageDown","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","ContextMenu","PrintScreen","ScrollLock","Pause","Unidentified"]);function ze(i){return i?i.length===1?true:(mt.has(i)||/^F\d{1,2}$/.test(i)||/^(Numpad|NumLock)/.test(i),false):false}function he(i){return i==="Shift"||i==="Control"||i==="Alt"||i==="Meta"}function D(i){let e=Z(i.key??"");if(e==="Unidentified"||e===""){let o=Ue(i.code);o&&(e=o);}let t=i.ctrlKey===true,n=i.altKey===true,r=i.shiftKey===true,s=i.metaKey===true;return {key:e,code:i.code??"",ctrl:t,alt:n,shift:r,meta:s,isPlain:!t&&!n&&!s,isPrintable:ze(e)&&!t&&!n&&!s,repeat:i.repeat===true,shiftKey:r,originalEvent:i}}function Ue(i){if(!i)return "";if(i.startsWith("Key"))return i.slice(3);if(i.startsWith("Digit"))return i.slice(5);if(i.startsWith("Arrow"))return i;if(i==="NumpadEnter")return "Enter";if(i.startsWith("Numpad")){let e=i.slice(6);return /^\d$/.test(e)?e:e==="Add"?"+":e==="Subtract"?"-":e==="Multiply"?"*":e==="Divide"?"/":e==="Decimal"?".":`Numpad${e}`}switch(i){case "Space":return "Space";case "Enter":case "NumpadEnter":return "Enter";case "Escape":return "Escape";case "Tab":return "Tab";case "Backspace":return "Backspace";case "Delete":return "Delete";case "Minus":return "-";case "Equal":return "=";case "Comma":return ",";case "Period":return ".";case "Slash":return "/";case "Backslash":return "\\";case "Semicolon":return ";";case "Quote":return "'";case "BracketLeft":return "[";case "BracketRight":return "]";case "Backquote":return "`";default:return ""}}function _e(i,e={}){let t=[];return e.ctrl&&t.push("Ctrl"),e.alt&&t.push("Alt"),e.shift&&t.push("Shift"),e.meta&&t.push("Meta"),i&&t.push(i),t.join("+")}function pt(i){let e=D(i);return _e(e.key,e)}var gt={ctrl:"ctrl",ctl:"ctrl",control:"ctrl",alt:"alt",option:"alt",opt:"alt",shift:"shift",meta:"meta",cmd:"meta",command:"meta",super:"meta",win:"meta",windows:"meta"};function vt(i){let e=[],t="",n=false;for(let r=0;r<i.length;r++){let s=i[r];if(s==='"'||s==="'"){n=!n;continue}if(s==="+"&&!n){if(r===i.length-1){e.push("+"),t="";continue}t!==""&&e.push(t),t="";continue}t+=s;}return t!==""&&e.push(t),e}function me(i){if(i==null)return null;let e=null,t=null,n=false,r=false,s=false,o=false,l=false;if(typeof i=="object"){if(i.key&&(e=Z(String(i.key))),i.code&&(t=String(i.code)),n=i.ctrl===true,r=i.alt===true,s=i.shift===true,o=i.meta===true,l=i.allowWithoutModifiers===true,!e&&!t)return null}else {let a=String(i),u=a.trim();if(u===""&&a!==" ")return null;let c=a===" "?" ":u;if(!c)return null;let d=vt(c);if(d.length===0)return null;for(let m=0;m<d.length;m++){let g=d[m],f=gt[g.toLowerCase()];if(f&&m<d.length-1){f==="ctrl"?n=true:f==="alt"?r=true:f==="shift"?s=true:o=true;continue}e=Z(g);}if(!e)return null;s&&e.length===1&&(e=e.toLowerCase());}return {key:e,code:t,ctrl:n,alt:r,shift:s,meta:o,allowWithoutModifiers:l,id:yt(e,t,n,r,s,o)}}function yt(i,e,t,n,r,s){let o=(t?"c":"")+(n?"a":"")+(r?"s":"")+(s?"m":""),l=e?`#${e.toLowerCase()}`:(i??"").toLowerCase();return o?`${o}:${l}`:l}function bt(i){return i==null||i===false?[]:Array.isArray(i)?i:[i]}var O=class{constructor(e={},t=[]){this.byId=new Map;this.loose=[];this.actions=new Set;this.sequences=[];this.sequenceIndex=0;this.sequenceOwner=null;this.sequenceTimer=null;this.sequenceCandidates=[];this.loadMap(e),this.loadSequences(t);}loadMap(e){this.byId.clear(),this.loose.length=0,this.actions.clear();for(let t of Object.keys(e))for(let n of bt(e[t])){let r=me(n);if(!r)continue;this.actions.add(t);let s=this.byId.get(r.id);(!s||s.binding.id!==r.id)&&(s={actions:[],binding:r},this.byId.set(r.id,s),(r.allowWithoutModifiers||r.code)&&this.loose.push(s)),s.actions.indexOf(t)===-1&&s.actions.push(t);}}loadSequences(e){this.resetSequence(),this.sequences.length=0;for(let t of e){let n=xt(t);if(!n)continue;let r=[],s=true;for(let o of n.binding){let l=me(o);if(!l){s=false;break}r.push(l);}s&&this.sequences.push({steps:r,action:n.action,timeout:n.timeout??1e3,preventDefault:n.preventDefault!==false});}}has(e){return this.actions.has(e)}get boundActions(){return Array.from(this.actions)}get size(){return this.byId.size+this.sequences.length}match(e,t){if(this.sequences.length>0){let r=this.matchSequence(e,t);if(r)return r}let n=Et(e);for(let r=0;r<n.length;r++){let s=this.byId.get(n[r]);if(s&&fe(s.binding,e))return {actions:s.actions,binding:s.binding,fromSequence:false,complete:true,preventDefault:true}}for(let r=0;r<this.loose.length;r++){let s=this.loose[r];if(fe(s.binding,e))return {actions:s.actions,binding:s.binding,fromSequence:false,complete:true,preventDefault:true}}return null}resetSequence(){this.sequenceIndex=0,this.sequenceCandidates=[],this.clearSequenceTimer();}dispose(){this.resetSequence(),this.byId.clear(),this.loose.length=0,this.actions.clear(),this.sequences.length=0;}matchSequence(e,t){t&&this.sequenceOwner&&this.sequenceOwner!==t&&this.resetSequence(),t&&(this.sequenceOwner=t);let n=this.sequenceCandidates.length>0,r=this.sequenceIndex,o=(n?this.sequenceCandidates:this.sequences).filter(c=>{let d=c.steps[r];return d!==void 0&&fe(d,e)});if(o.length===0)return n?(this.resetSequence(),this.matchSequence(e,t)):null;let l=o.find(c=>c.steps.length===r+1),a=l??o[0],u={actions:[a.action],binding:a.steps[r],fromSequence:true,complete:l!==void 0,preventDefault:a.preventDefault};return l?this.resetSequence():(this.sequenceCandidates=o,this.sequenceIndex=r+1,this.armSequenceTimer(a.timeout)),u}armSequenceTimer(e){this.clearSequenceTimer(),typeof setTimeout=="function"&&(this.sequenceTimer=setTimeout(()=>this.resetSequence(),e));}clearSequenceTimer(){this.sequenceTimer!==null&&(clearTimeout(this.sequenceTimer),this.sequenceTimer=null);}},Tt=new Set(["tab"]);function je(i){return Tt.has(i.toLowerCase())}function re(i,e,t,n,r){let s=(e?"c":"")+(t?"a":"")+(n?"s":"")+(r?"m":"");return s?`${s}:${i}`:i}function Et(i){let{ctrl:e,alt:t,shift:n,meta:r}=i,s=i.key,o=s.toLowerCase(),l=[re(o,e,t,n,r)],a=s.length===1,u=n&&(a||!je(o))?re(o,e,t,false,r):null;return u&&l.push(u),a&&o!==s&&(l.push(re(s,e,t,n,r)),u&&l.push(re(s,e,t,false,r))),l}function fe(i,e){if(i.code){if(i.code.toLowerCase()!==e.code.toLowerCase())return false}else if(i.key){if(!Ge(i.key,e.key))return false}else return false;if(i.allowWithoutModifiers&&!e.ctrl&&!e.alt&&!e.meta)return true;if(i.ctrl!==e.ctrl||i.alt!==e.alt||i.meta!==e.meta)return false;if(i.shift!==e.shift){let t=i.key??"",n=t.length===1;if(e.shift&&!i.shift){if(je(t)||/^[a-z]$/i.test(t)&&(e.ctrl||e.alt||e.meta))return false}else if(!n)return false}return true}function Ge(i,e){return i===e?true:i.toLowerCase()===e.toLowerCase()}function xt(i){return !i||!i.binding||i.binding.length<2||!i.action?null:i}function At(i={},e=[]){return new O(i,e)}function pe(i={}){let e=i.resetDelay??600,t=i.getText??(a=>se(a)),n="",r=null,s=-1;function o(){r!==null&&(clearTimeout(r),r=null);}function l(){n="",s=-1,o();}return {get query(){return n},reset:l,dispose:l,handle(a,u,c){if(!a)return null;let d=u.length;if(d===0)return null;let m=n;n+=a.toLowerCase(),n.length>12&&(n=n.slice(-12)),o(),typeof setTimeout=="function"&&(r=setTimeout(l,e));let g=n.length>1&&m.length===1&&n===m+m,f=g?m:n,v=A=>{let S=[];for(let K=0;K<d;K++){let C=t(u[K]);C&&C.toLowerCase().startsWith(A)&&S.push(K);}return S},h=v(f);if(h.length===0&&f.length>1&&(f=a.toLowerCase(),n=f,h=v(f)),h.length===0)return i.onMatch?.(null,f),null;let E;if(g){let A=h.indexOf(s);E=h[(A+1)%h.length];}else if(f===m&&m.length>0){let A=h.indexOf(s);E=h[(A+1)%h.length];}else {E=h[0];for(let A=0;A<h.length;A++)if(h[A]>c){E=h[A];break}}s=E;let y=u[E]??null;return i.onMatch?.(y,f),y}}}var wt="[data-keystra-item]",It="[disabled],[aria-disabled='true']",We=10,St=new Set(["next","previous","up","down","left","right","first","last","pageUp","pageDown"]);function Ot(i={},e={}){let t=e.mode??i.mode??"vertical",n=e.container??b(i.container)??null,r=e.keys??ie(e.defaultKeys??ne(t),i.keys,i.useDefaultKeys!==false),s=i.strategy??null,o=e.listenTarget??U(i.target)??n??(typeof document<"u"?document:null);return {container:n,pinnedTarget:i.target!==void 0&&i.target!==null,listenTarget:o,selector:i.items??i.itemSelector??wt,disabledSelector:i.disabledSelector===false||i.disabledSelector===null?null:i.disabledSelector??It,skipHidden:i.skipHidden!==false,filter:i.filter??null,mode:t,loop:e.loop??i.loop===true,columns:e.columns??i.columns??0,pageSize:i.pageSize??We,strategy:s??e.strategy??Ye(t),userStrategy:s,onBeforeNavigate:i.onBeforeNavigate??null,keys:r,defaultKeys:e.defaultKeys??null,userKeys:i.keys??null,useDefaultKeys:i.useDefaultKeys!==false,sequences:i.sequences??[],typeahead:Kt(i.typeahead),roving:Dt(i.roving),activeDescendant:i.activeDescendant===true||i.activeDescendant!==void 0&&i.activeDescendant!==false&&i.activeDescendant!==null,descendantOwner:i.activeDescendant===void 0||i.activeDescendant===false||i.activeDescendant===null?null:i.activeDescendant===true?()=>Mt(n,o):()=>b(i.activeDescendant,n?.ownerDocument??null),autoFocus:Ct(i.autoFocus),selectionOptions:Lt(i.selection),observe:i.observe??false,onlyWhenFocusedInside:i.onlyWhenFocusedInside!==false,when:i.when??null,ignoreEditable:i.ignoreEditable!==false,editableSelector:i.editableSelector??null,stopPropagation:i.stopPropagation!==false,preventDefault:i.preventDefault!==false,capture:i.capture===true,pointerSync:i.pointerSync===true,handlers:{onFocus:i.onFocus,onBlur:i.onBlur,onSelect:i.onSelect,onAction:i.onAction,onEscape:i.onEscape,onRefresh:i.onRefresh}}}function Ye(i){switch(i){case "horizontal":return V("horizontal");case "grid":return W();case "directional":return oe();case "custom":return ()=>null;default:return V("vertical")}}function Kt(i){return i?i===true?{enabled:true}:i.enabled===false?null:{...i,enabled:true}:null}function Mt(i,e){if(e&&typeof e.nodeType=="number"){let n=e;if(!i||T(i,n)||n===i)return n}if(typeof document>"u")return null;let t=document.activeElement;return t&&i&&T(i,t)?t:null}function Dt(i){return i===false?{enabled:false}:i===true||i===void 0?{enabled:true}:i}function Ct(i){return i?i===true?{enabled:true}:i:{enabled:false}}function Lt(i){return i?i===true?{enabled:true,mode:"single"}:i.enabled===false?null:{enabled:true,...i}:null}var w=class{constructor(e={},t={}){this.events=new M;this.emitter=new Y;this.keydownDisposer=null;this.auxDisposers=[];this.syncPending=true;this.destroyed=false;this.resolved=Ot(e,t),this.collection=new Q(this.resolved.container,{selector:this.resolved.selector,disabledSelector:this.resolved.disabledSelector,skipHidden:this.resolved.skipHidden,filter:this.resolved.filter,observe:this.resolved.observe},()=>{this.syncPending=true;}),this.focus=new j({roving:this.resolved.roving,virtual:this.resolved.activeDescendant,descendantOwner:this.resolved.descendantOwner,disabledSelector:this.resolved.disabledSelector,skipHidden:this.resolved.skipHidden,onFocus:(n,r,s)=>{let o=this.resolved.selectionOptions;o?.followFocus&&o.mode!=="multiple"&&this.selectionManager?.select(r),this.resolved.handlers.onFocus?.(n,r),this.emitter.emit("focus",{element:n,index:r,action:s});},onBlur:(n,r)=>{this.resolved.handlers.onBlur?.(n,r),this.emitter.emit("blur",{element:n,index:r});}}),e.elements&&this.collection.setItems(e.elements),this.matcher=new O(this.resolved.keys,this.resolved.sequences??[]),this.typeaheadController=this.resolved.typeahead?pe(this.resolved.typeahead):null,this.selectionManager=this.resolved.selectionOptions?new G(this.resolved.selectionOptions):null,this.selectionManager?.setDiffHandler((n,r,s)=>{this.emitter.emit("selectionchange",{selected:n,added:r,removed:s});}),this.selectionManager?.bindItems(()=>this.collection.items),e.enabled!==false&&this.attach(),this.resolved.autoFocus.enabled&&this.applyAutoFocus();}get container(){return this.resolved.container}get items(){return this.sync(),this.collection.items}get activeElement(){return this.sync(),this.focus.element}get activeIndex(){return this.sync(),this.focus.focusedIndex}get currentIndex(){return this.sync(),this.focus.index}get mode(){return this.resolved.mode}get loop(){return this.resolved.loop}get enabled(){return this.keydownDisposer!==null}get selection(){return this.sync(),this.selectionManager}next(e=1){return this.step(e,"next")}previous(e=1){return this.step(-e,"previous")}up(){return this.move("up")}down(){return this.move("down")}left(){return this.move("left")}right(){return this.move("right")}move(e){this.collection.revalidate(),this.sync();let t=this.resolveNavigation(e,e,null);if(t===null)return null;let n=this.focus.focusIndex(t,e);return n&&this.afterMove(t,e,null),n}first(){if(this.collection.revalidate(),this.sync(),this.collection.items.length===0)return null;let e=this.focus.focusIndex(0,"first");return e&&this.afterMove(0,"first",null),e}last(){this.collection.revalidate(),this.sync();let e=this.collection.items.length;if(e===0)return null;let t=this.focus.focusIndex(e-1,"last");return t&&this.afterMove(e-1,"last",null),t}focusFirst(){return this.first()}focusLast(){return this.last()}pageUp(){return this.step(-this.resolved.pageSize,"pageUp")}pageDown(){return this.step(this.resolved.pageSize,"pageDown")}focusIndex(e){return this.collection.revalidate(),this.sync(),this.focus.focusIndex(e,null)}setActiveIndex(e,t={}){return this.collection.revalidate(),this.sync(),t.focus===false?(this.focus.setActiveIndex(e),this.collection.items[e]??null):this.focus.focusIndex(e,null)}focusElement(e){return this.sync(),this.focus.focusElement(e??null)}restoreFocus(){return this.focus.restore()}rememberFocus(){if(typeof document>"u")return;let e=document.activeElement;!e||e===document.body||e===document.documentElement||this.resolved.container&&T(this.resolved.container,e)||this.focus.remember(e);}select(e){this.sync();let t=this.resolveIndex(e),n=t>=0?this.collection.items[t]:void 0;n&&(this.applySelection(t,false),this.resolved.handlers.onSelect?.(n,t),this.emitter.emit("select",{element:n,index:t}),this.emitAction("select",null,n,t));}perform(e,t=null){return this.destroyed?false:this.runAction(e,t,null)}setContainer(e){let t=b(e,this.resolved.container?.ownerDocument??null);if(t===this.resolved.container)return;let n=this.keydownDisposer!==null;n&&this.detach(),this.resolved.container=t,this.resolved.pinnedTarget||(this.resolved.listenTarget=t??(typeof document<"u"?document:null)),this.collection.setContainer(t),n&&this.attach(),this.syncPending=true,this.emitter.emit("refresh",{items:this.collection.items});}refresh(){let e=this.collection.refresh();return this.sync(true),this.resolved.handlers.onRefresh?.(e),this.emitter.emit("refresh",{items:e}),e}add(e){this.collection.add(e);}remove(e){this.collection.remove(e);}setItems(e){this.collection.setItems(e);}enable(){this.destroyed||this.enabled||this.attach();}disable(){this.detach(),this.matcher.resetSequence(),this.typeaheadController?.reset();}update(e){this.destroyed||(e.container!==void 0&&this.setContainer(e.container),e.mode!==void 0&&e.mode!==this.resolved.mode&&(this.resolved.mode=e.mode,this.resolved.userStrategy||(this.resolved.strategy=Ye(e.mode))),e.loop!==void 0&&(this.resolved.loop=e.loop===true),e.columns!==void 0&&(this.resolved.columns=e.columns??0),e.pageSize!==void 0&&(this.resolved.pageSize=e.pageSize??We),e.keys!==void 0&&(this.resolved.userKeys=e.keys),(e.keys!==void 0||e.mode!==void 0)&&(this.resolved.keys=ie(this.resolved.defaultKeys??ne(this.resolved.mode),this.resolved.userKeys,this.resolved.useDefaultKeys),this.matcher.loadMap(this.resolved.keys)),e.enabled===true?this.enable():e.enabled===false&&this.disable(),this.syncPending=true);}on(e,t){return this.emitter.on(e,t)}off(e,t){this.emitter.off(e,t);}destroy(){this.destroyed||(this.destroyed=true,this.detach(),this.events.dispose(),this.collection.dispose(),this.matcher.dispose(),this.typeaheadController?.dispose(),this.typeaheadController=null,this.selectionManager?.dispose(),this.selectionManager=null,this.focus.dispose(),this.emitter.emit("destroy",{}),this.emitter.clear());}attach(){let e=this.resolved.listenTarget;if(!e||this.keydownDisposer)return;let t={capture:this.resolved.capture,passive:false};this.keydownDisposer=this.events.add(e,"keydown",n=>this.onKeydown(n),t),this.auxDisposers.push(this.events.add(e,"focusin",n=>{this.focus.observe(n.target,this.resolved.container);})),this.resolved.pointerSync&&this.resolved.container&&this.auxDisposers.push(this.events.add(this.resolved.container,"click",n=>this.onPointer(n)),this.events.add(this.resolved.container,"pointerover",n=>this.onPointerOver(n))),this.resolved.observe&&this.collection.startObserving();}detach(){this.keydownDisposer&&(this.keydownDisposer(),this.keydownDisposer=null);for(let e of this.auxDisposers)e();this.auxDisposers.length=0,this.collection.stopObserving();}applyAutoFocus(){let{target:e}=this.resolved.autoFocus;this.sync(true);let t=this.collection.items;if(t.length===0)return;let n=0;e==="last"?n=t.length-1:typeof e=="function"&&(n=e(t)),this.focus.focusIndex(ge(n,t.length,false),null);}onKeydown(e){if(this.destroyed||this.resolved.when&&!this.resolved.when())return;this.collection.revalidate();let t=D(e),n=this.matcher.match(t,this);if(this.reservedTarget(e)&&!(n?.complete??false))return;if(!n){if(this.handleTypeahead(t,e))return;he(t.key)||this.emitter.emit("keydown",{event:e,handled:false});return}if(!n.complete){n.preventDefault&&this.resolved.preventDefault&&e.preventDefault();return}if(this.reservedTarget(e)||this.resolved.onlyWhenFocusedInside&&!this.focusIsInside())return;let r=n.actions;for(let s=0;s<r.length;s++)if(this.runAction(r[s],e,n)){this.resolved.preventDefault&&e.preventDefault(),this.resolved.stopPropagation&&e.stopPropagation(),this.emitter.emit("keydown",{event:e,handled:true});return}this.emitter.emit("keydown",{event:e,handled:false});}reservedTarget(e){return !this.resolved.ignoreEditable||e.target===this.resolved.listenTarget?false:z(e.target,this.resolved.editableSelector)}focusIsInside(){if(typeof document>"u")return true;let e=document.activeElement,t=this.resolved.container;return !e||e===document.body||e===document.documentElement?this.focus.element!==null||t===null:!t||T(t,e)?true:this.focus.element!==null&&T(t,this.focus.element)}handleTypeahead(e,t){let n=this.typeaheadController;if(!n||!e.isPrintable||e.key.length!==1||e.repeat)return false;this.sync();let r=this.collection.items;if(r.length===0)return false;let s=n.handle(e.key,r,this.focus.index);if(!s)return false;let o=r.indexOf(s);return o===-1||!this.focus.focusIndex(o,"typeahead")?false:(this.afterMove(o,"typeahead",t),this.resolved.preventDefault&&t.preventDefault(),this.resolved.stopPropagation&&t.stopPropagation(),this.emitter.emit("keydown",{event:t,handled:true}),true)}runAction(e,t,n){let r=n?.fromSequence===true;this.sync();let s=this.collection.items,o=this.focus.index,l=o>=0?s[o]??null:null;if(St.has(e))return s.length===0?false:this.runMovement(e,t,s,r);switch(e){case "select":{if(o<0)return false;let a=s[o];return this.resolved.selectionOptions?.selectOnActivate!==false&&this.applySelection(o,false),this.resolved.handlers.onSelect?.(a,o),this.emitter.emit("select",{element:a,index:o}),this.emitAction(e,t,a,o,r),this.selectionManager!==null||this.isHeard(e)||!Ht(a)}case "toggle":{let a=this.selectionManager?.mode;return !this.selectionManager||a==="single"||a==="none"||o<0?false:(this.selectionManager.toggle(o),this.emitAction(e,t,s[o],o,r),true)}case "selectAll":return this.selectionManager?(this.selectionManager.selectAll(),this.emitAction(e,t,l,o,r),true):false;case "escape":return this.typeaheadController?.reset(),this.matcher.resetSequence(),this.emitAction(e,t,l,o,r),this.resolved.handlers.onEscape?.(t),this.isHeard(e);default:return this.emitAction(e,t,l,o,r),true}}runMovement(e,t,n,r=false){let s=e==="up"||e==="down"||e==="left"||e==="right"?e:null,o;switch(e){case "first":o=this.resolveNavigation(e,null,t)??0;break;case "last":o=this.resolveNavigation(e,null,t)??n.length-1;break;case "pageUp":case "pageDown":{let a=(e==="pageDown"?1:-1)*this.resolved.pageSize,u=this.focus.index,c=u<0?a>0?0:n.length-1:u+a;o=ge(c,n.length,this.resolved.loop);break}default:{let a=this.resolveNavigation(e,s,t);if(a===null)return false;o=a;}}return this.focus.focusIndex(o,e)?(this.afterMove(o,e,t,r),true):false}isHeard(e){let{onSelect:t,onEscape:n,onAction:r}=this.resolved.handlers;return r||this.ownsAction(e)?true:e==="escape"?n!==void 0:t!==void 0}ownsAction(e){return false}emitAction(e,t,n,r,s=false){this.resolved.handlers.onAction?.(e,t,n,r),this.emitter.emit("action",{action:e,event:t,element:n,index:r,fromSequence:s});}afterMove(e,t,n,r=false){this.emitAction(t,n,this.collection.items[e]??null,e,r);let s=this.resolved.selectionOptions;s&&!s.followFocus&&s.mode==="range"&&s.shiftExtendsRange!==false&&n?.shiftKey&&this.extendRangeTo(e);}resolveNavigation(e,t,n){let r=this.collection.items;if(r.length===0)return null;let s=this.createContext(e,t,n);if(this.resolved.onBeforeNavigate){let l=this.resolved.onBeforeNavigate(s);if(typeof l=="number"&&l>=0&&l<r.length)return l}let o=this.resolved.strategy(s);return typeof o!="number"||o<0?null:o>=r.length?r.length-1:o}createContext(e,t,n){return {items:this.collection.items,container:this.resolved.container,index:this.focus.index,direction:t,action:e,event:n,shiftKey:n?.shiftKey===true,altKey:n?.altKey===true,ctrlKey:n?.ctrlKey===true,metaKey:n?.metaKey===true,columns:this.resolved.columns,loop:this.resolved.loop,version:this.collection.version,rectOf:de(this.collection)}}step(e,t){this.collection.revalidate(),this.focus.sync(this.collection.items,this.resolved.container),this.sync();let n=this.collection.items.length;if(n===0||e===0)return null;let r=this.focus.index,s=r<0?e>0?0:n-1:r+e,o=ge(s,n,this.resolved.loop),l=this.focus.focusIndex(o,t);return l&&t&&this.afterMove(o,t,null),l}resolveIndex(e){return e===void 0?this.focus.index:typeof e=="number"?e:this.collection.indexOf(e)}applySelection(e,t=false){let n=this.selectionManager;n&&n.select(e,t);}extendRangeTo(e){let t=this.selectionManager;if(!t)return;let n=this.collection.items,r=t.anchor,s=r?n.indexOf(r):e;s<0||t.selectRange(s,e);}onPointer(e){let t=this.itemFromEvent(e);if(!t)return;let n=this.collection.indexOf(t);if(n===-1)return;this.focus.focusIndex(n,"select");let r=this.selectionManager;if(!r)return;let s=r.mode;if(s!=="none"){if(s==="multiple"){e.ctrlKey||e.metaKey?r.toggle(n):r.select(n);return}if(s==="range"&&e.shiftKey){this.extendRangeTo(n);return}this.applySelection(n,false);}}onPointerOver(e){let t=this.itemFromEvent(e);t&&this.focus.observe(t,this.resolved.container);}itemFromEvent(e){let t=e.target;if(!t)return null;this.collection.revalidate(),this.sync();let n=this.collection.items,r=this.resolved.selector;if(typeof r=="string"&&typeof t.closest=="function")try{let o=t.closest(r);if(o&&n.indexOf(o)!==-1)return o}catch{}let s=t;for(;s;){if(n.indexOf(s)!==-1)return s;s=s.parentElement;}return null}sync(e=false){if(this.destroyed||!e&&!this.syncPending)return;this.syncPending=false;let t=this.collection.items;this.focus.sync(t,this.resolved.container),this.selectionManager?.sync(t);}};function Ht(i){return i.matches("a[href],button,summary,input,select,textarea")}function ge(i,e,t){return e===0?-1:t?(i%e+e)%e:i<0?0:i>=e?e-1:i}function J(i={}){return new w(i)}function $e(i){return b(i,typeof document<"u"?document:null)}function Nt(i={}){let e={...i},t=null,n=$e(e.container),r=false,s=false,o=false,l={get instance(){return t},get container(){return n},attach(a){if(o)return null;let u=$e(a);return u?t?(u!==n&&(n=u,t.update({container:u})),r&&(r=false,s&&t.enable(),s=false),t):(n=u,t=J({...e,container:u}),t):t},detach(){!t||r||(s=t.enabled,r=true,t.disable(),n=null);},destroy(){o=true,t?.destroy(),t=null,n=null,r=false,s=false;}};return n&&l.attach(n),l}var Qe="shortcut";function Ze(i){let e=i.binding;return e.ctrl===true||e.alt===true||e.meta===true}function kt(i,e,t={}){let n=new O({[Qe]:i},t.sequences??[]),r=new M,s=t.capture===true,o=t.preventDefault!==false,l=t.stopPropagation===true,a=t.allowInEditable===true,u=t.editableSelector??null,c=null,d=false;function m(){let v=U(t.target);return v||(typeof document<"u"?document:null)}function g(v){if(d||t.when&&!t.when())return;let h=v,E=n.match(D(h),f),y=!a&&z(h.target,u);if(E){if(!E.complete){E.preventDefault&&o&&!(y&&!Ze(E))&&h.preventDefault();return}y&&!Ze(E)||(o&&E.preventDefault!==false&&h.preventDefault(),l&&h.stopPropagation(),e(h,{action:E.actions[0]??Qe,fromSequence:E.fromSequence}));}}let f={enable(){if(d||c)return;let v=m();v&&(c=r.add(v,"keydown",g,{capture:s,passive:false}));},disable(){c&&(c(),c=null,n.resetSequence());},destroy(){d=true,f.disable(),n.dispose(),r.dispose();},matches(v){let h=n.match(D(v),f);return h!==null&&h.complete}};return t.enabled!==false&&f.enable(),f}function Rt(i){let e=typeof i=="function"?{onNavigate:i}:i;return t=>{if(t.direction||qt(t.action)){let r=e.onNavigate?.(t);return typeof r=="number"?r:e.fallback?e.fallback(t):null}let n=e.onAction?.(t);return typeof n=="number"?n:e.onNavigate?.(t)??null}}function Ft(...i){let e=i.filter(Boolean);return t=>{for(let n=0;n<e.length;n++){let r=e[n](t);if(typeof r=="number"&&r>=0)return r}return null}}function qt(i){return i==="next"||i==="previous"||i==="first"||i==="last"||i==="pageUp"||i==="pageDown"}var Pt=new Set(["NAV","MAIN","ASIDE","HEADER","FOOTER","FORM","SECTION","ARTICLE","DIALOG"]);function ve(i){return !i.hasAttribute("role")&&!Pt.has(i.tagName)}function x(i,e,t){t&&ve(i)&&i.setAttribute("role",e);}function k(i,e,t,n,r){if(!(!r||!i)&&i.getAttribute("role")===t)for(let s=0;s<e.length;s++)x(e[s],n,true);}function I(i,e,t,n){!n||!i||q(i,e,t);}var ye=class extends w{constructor(t){let n=t.orientation??"horizontal";super(t,{mode:t.mode??(n==="vertical"?"vertical":"horizontal"),loop:t.loop??true,defaultKeys:n==="vertical"?ke:Ne});this.panels=[];this.activeValue=-1;this.applying=false;this.initializing=true;this.orientationValue=n,this.activationValue=t.activation??"automatic",this.manageAria=t.aria!==false,this.activeAttribute=t.activeAttribute??"aria-selected",this.panelActiveAttribute=t.panelActiveAttribute??"hidden",this.panelSelector=t.panels,this.userOnActivate=t.onActivate,this.manageAria&&this.container&&(x(this.container,"tablist",true),this.container.getAttribute("role")==="tablist"&&I(this.container,"aria-orientation",this.orientationValue,true)),this.on("focus",({index:s})=>{this.activationValue==="automatic"&&this.activate(s);}),this.on("action",({action:s,index:o})=>{this.activationValue==="manual"&&s==="select"&&o>=0&&this.activate(o);}),this.on("refresh",()=>this.refreshPanels()),this.refreshPanels(),this.decorate();let r=this.detectInitialIndex();this.applyActive(r),this.initializing=false;}get activeTab(){return this.activeValue>=0?this.items[this.activeValue]??null:null}get activeIndex(){return this.activeValue}get orientation(){return this.orientationValue}get activation(){return this.activationValue}activate(t){if(t===null){this.applyActive(-1);return}let n=typeof t=="number"?t:this.items.indexOf(t);n<0||n>=this.items.length||this.applyActive(n,true);}refresh(){let t=super.refresh();return this.refreshPanels(),this.decorate(),this.activeValue>=t.length?this.applyActive(t.length>0?0:-1):this.applyActive(this.activeValue),t}ownsAction(t){return t==="select"}refreshPanels(){if(!this.panelSelector||!this.container){this.panels=[];return}let t=P(this.container,this.panelSelector);if(t.length===0){let n=this.container.parentElement;n&&n!==this.container.ownerDocument?.documentElement&&(t=P(n,this.panelSelector));}this.panels=t;}decorate(){let t=this.items;for(let n=0;n<t.length;n++){let r=t[n];if(x(r,"tab",this.manageAria),!this.manageAria)continue;let s=H(r,"keystra-tab"),o=this.panels[n];if(!o)continue;let l=H(o,"keystra-panel");x(o,"tabpanel",true),I(r,"aria-controls",l,true),I(o,"aria-labelledby",s,true);}}detectInitialIndex(){let t=this.items;for(let n=0;n<t.length;n++)if(t[n].getAttribute(this.activeAttribute)==="true")return n;return t.length>0?0:-1}applyActive(t,n=false){if(!this.applying){this.applying=true;try{this.applyActiveNow(t,n);}finally{this.applying=false;}}}applyActiveNow(t,n){let r=this.items,s=this.activeValue;this.activeValue=t;let o=this.manageAria||this.activeAttribute!=="aria-selected",l=this.manageAria;for(let a=0;a<r.length;a++){let u=r[a],c=a===t;if(o&&u.getAttribute(this.activeAttribute)!==(c?"true":"false")&&u.setAttribute(this.activeAttribute,c?"true":"false"),this.manageAria&&this.activeAttribute!=="aria-selected"&&I(u,"aria-selected",c?"true":"false",true),!l)continue;let d=this.panels[a];d&&(this.panelActiveAttribute==="hidden"?d.hasAttribute("hidden")===c&&d.toggleAttribute("hidden",!c):d.setAttribute(this.panelActiveAttribute,c?"true":"false"));}if(t>=0&&(n&&r[t]!==this.activeElement?this.focusIndex(t):n||this.setActiveIndex(t,{focus:false})),s!==t&&t>=0&&!this.initializing){let a=r[t];a&&this.userOnActivate?.(a,t);}}};function Vt(i={}){return new ye(i)}var X=class extends w{constructor(t){super({typeahead:true,...t,enabled:false},{mode:t.mode??"vertical",loop:t.loop??true,defaultKeys:Re});this.openValue=false;this.unhidden=false;this.closeOnSelect=t.closeOnSelect!==false,this.returnFocusTarget=t.returnFocusTo,this.manageAria=t.aria!==false,this.toggleHiddenValue=t.toggleHidden!==false,this.userOnOpen=t.onOpen,this.userOnClose=t.onClose,this.manageAria&&this.container&&x(this.container,"menu",true),this.decorateItems(),this.on("select",()=>{this.closeOnSelect&&this.close();}),this.on("action",({action:n})=>{n==="escape"&&this.close();}),this.on("refresh",()=>this.decorateItems());}decorateItems(){k(this.container,this.items,"menu","menuitem",this.manageAria);}get isOpen(){return this.openValue}open(t={}){if(this.openValue)return;this.openValue=true,this.enable(),this.rememberFocus(),this.toggleHiddenValue&&this.container?.hasAttribute("hidden")&&(this.container.removeAttribute("hidden"),this.unhidden=true),this.refresh(),this.manageAria&&this.container&&this.container.setAttribute("data-keystra-open","true");let n=t.focus??"first",r=this.items;if(r.length===0){this.userOnOpen?.(this);return}n==="current"&&this.currentIndex>=0?this.focusIndex(this.currentIndex):n==="last"?this.focusIndex(r.length-1):typeof n=="number"?this.focusIndex(Math.max(0,Math.min(n,r.length-1))):this.focusIndex(0),this.userOnOpen?.(this);}close(t={}){if(this.openValue){if(this.openValue=false,this.disable(),this.manageAria&&this.container&&this.container.removeAttribute("data-keystra-open"),t.restoreFocus!==false){let n=b(this.returnFocusTarget,this.container?.ownerDocument??null);n?L(n):this.restoreFocus();}this.unhidden&&(this.container?.setAttribute("hidden",""),this.unhidden=false),this.userOnClose?.(this);}}toggle(){this.openValue?this.close():this.open();}destroy(){this.openValue=false,super.destroy();}ownsAction(t){return t==="select"||t==="escape"}};function Bt(i={}){return new X(i)}var zt=["Enter","Space","ArrowDown","ArrowUp"],be=class extends X{constructor(t){super({typeahead:true,...t});this.extra=new M;let n=this.container?.ownerDocument??(typeof document<"u"?document:null);this.triggerElement=b(t.trigger,n),this.manageTriggerAria=t.aria!==false,this.closeOnBlurValue=t.closeOnBlur===true,this.closeOnOutsidePointerValue=t.closeOnOutsidePointer!==false;let r=t.openKeys===void 0||t.openKeys===null?zt:Array.isArray(t.openKeys)?t.openKeys:[t.openKeys];this.openMatcher=new O({open:r}),this.menuId=this.container?H(this.container,"keystra-menu"):null,this.decorateTrigger(),this.wireTrigger(),this.on("action",({action:s,event:o})=>{s==="escape"&&(o?.preventDefault(),this.close());});}get trigger(){return this.triggerElement}open(t={}){let n=this.isOpen;super.open(t),!n&&this.isOpen&&this.syncTriggerState();}close(t={}){let n=this.isOpen;super.close({restoreFocus:false}),n&&t.restoreFocus!==false&&this.triggerElement&&L(this.triggerElement),n&&this.syncTriggerState();}destroy(){this.extra.dispose(),this.openMatcher.dispose(),this.triggerElement&&this.manageTriggerAria&&(this.triggerElement.removeAttribute("aria-expanded"),this.menuId&&this.triggerElement.removeAttribute("aria-controls")),super.destroy();}decorateTrigger(){let t=this.triggerElement;!t||!this.manageTriggerAria||(t.hasAttribute("aria-haspopup")||t.setAttribute("aria-haspopup","menu"),I(t,"aria-controls",this.menuId,true),this.syncTriggerState());}syncTriggerState(){!this.triggerElement||!this.manageTriggerAria||this.triggerElement.setAttribute("aria-expanded",this.isOpen?"true":"false");}wireTrigger(){let t=this.triggerElement;t&&(this.extra.add(t,"click",()=>{this.toggle();}),this.extra.add(t,"keydown",n=>{let r=n;if(this.isOpen){r.key==="Tab"&&this.close({restoreFocus:false});return}let s=D(r);this.openMatcher.match(s,this)?.complete&&(r.preventDefault(),this.open({focus:s.key==="ArrowUp"?"last":"first"}));}),typeof document<"u"&&this.extra.add(document,"keydown",n=>{let r=n;r.key!=="Tab"||r.defaultPrevented||!this.isOpen||T(this.container,r.target)&&this.close();}),this.closeOnOutsidePointerValue&&typeof document<"u"&&this.extra.add(document,"pointerdown",n=>{if(!this.isOpen)return;let r=n.target;T(this.container,r)||T(this.triggerElement,r)||this.close({restoreFocus:false});}),this.closeOnBlurValue&&typeof document<"u"&&this.extra.add(document,"focusin",n=>{if(!this.isOpen)return;let r=n.target;T(this.container,r)||T(this.triggerElement,r)||this.close({restoreFocus:false});}));}};function Ut(i={}){return new be(i)}var Te=class extends w{constructor(e){if(super(e,{mode:e.mode??"vertical",loop:e.loop??false,defaultKeys:qe}),this.manageAria=e.aria!==false,this.manageAria&&this.container&&(x(this.container,"listbox",true),this.container.getAttribute("role")==="listbox"&&this.selectionManager)){let t=this.selectionManager.mode==="multiple"||this.selectionManager.mode==="range";I(this.container,"aria-multiselectable",t?"true":null,true);}this.decorateItems(),this.on("refresh",()=>this.decorateItems());}decorateItems(){k(this.container,this.items,"listbox","option",this.manageAria);}};function _t(i={}){let e=b(i.container),t=i.aria!==false&&e!==null&&(e.getAttribute("role")==="listbox"||ve(e)),n=i.selection??{enabled:true,mode:"single",followFocus:true};return new Te({typeahead:true,...i,selection:typeof n=="object"?{aria:t,...n}:n&&{mode:"single",aria:t}})}var Ee=class extends w{constructor(e){super(e,{mode:"grid",loop:e.loop??false,columns:e.columns??0,strategy:W({maintainColumn:e.maintainColumn,rowHomeEnd:e.rowHomeEnd})}),this.manageAria=e.aria!==false,this.decorateRoles(),this.on("refresh",()=>this.decorateRoles());}decorateRoles(){let e=this.container;if(!this.manageAria||!e||e.querySelector("[role='row']")===null)return;x(e,"grid",true);let t=this.items;for(let n=0;n<t.length;n++){let r=t[n];r.parentElement?.getAttribute("role")==="row"&&x(r,"gridcell",true);}}get columns(){if(this.resolved.columns>0)return this.resolved.columns;let e=this.items;if(e.length===0)return 0;let t=1,n=e[0],r=this.rectOf(n).top;for(let s=1;s<e.length&&Math.abs(this.rectOf(e[s]).top-r)<2;s++)t++;return t}get rows(){let e=this.columns;return e<=0?0:Math.ceil(this.items.length/e)}get position(){let e=this.activeIndex,t=this.columns;return e<0||t<=0?{row:-1,column:-1}:{row:Math.floor(e/t),column:e%t}}focusCell(e,t){let n=this.columns;if(n<=0)return null;let r=e*n+t;return r<0||r>=this.items.length?null:this.focusIndex(r)}rectOf(e){return this.collection.layout.rect(e,this.collection.version)}};function jt(i={}){return new Ee(i)}var Gt="[role='treeitem']",Wt="[role='group']",xe=class extends w{constructor(e){let t=e.hiddenClass;super({typeahead:true,items:e.items??Gt,...e,filter:t?(n,r)=>e.filter&&!e.filter(n,r)?false:!n.parentElement?.closest(`.${t}`):e.filter},{mode:e.mode??"vertical",loop:e.loop??false,defaultKeys:Fe}),this.groupSelector=e.groupSelector??Wt,this.manageAria=e.aria!==false,this.collapseBehavior=e.collapseBehavior??"attribute",this.toggleHiddenValue=e.toggleHidden===true||this.collapseBehavior==="hidden",this.hiddenClassValue=e.hiddenClass,this.userOnExpand=e.onExpand,this.userOnCollapse=e.onCollapse,this.manageAria&&this.container&&x(this.container,"tree",true),this.decorateItems(),this.on("action",({action:n,element:r})=>{r&&(n==="expand"?this.handleExpandKey(r):n==="collapse"&&this.handleCollapseKey(r));});}decorateItems(){k(this.container,this.items,"tree","treeitem",this.manageAria),this.on("refresh",()=>{k(this.container,this.items,"tree","treeitem",this.manageAria);});}isExpandable(e){return e.hasAttribute("aria-expanded")||e.hasAttribute("data-expandable")?true:e.querySelector(this.groupSelector)!==null}isExpanded(e){let t=e.getAttribute("aria-expanded");if(t!==null)return t==="true";let n=e.querySelector(this.groupSelector);return n?this.hiddenClassValue?!n.classList.contains(this.hiddenClassValue):!n.hasAttribute("hidden"):false}expand(e){let t=this.elementOf(e);!t||!this.isExpandable(t)||this.isExpanded(t)||this.setExpanded(t,true);}collapse(e){let t=this.elementOf(e);!t||!this.isExpandable(t)||this.isExpanded(t)&&this.setExpanded(t,false);}toggleExpanded(e){let t=this.elementOf(e);!t||!this.isExpandable(t)||this.setExpanded(t,!this.isExpanded(t));}expandAll(){let e=new Set;for(let t=true;t;){t=false;for(let n of this.items)e.has(n)||(e.add(n),!(!this.isExpandable(n)||this.isExpanded(n))&&(this.setExpanded(n,true),t=true));}}collapseAll(){for(let e of this.items)this.isExpandable(e)&&this.setExpanded(e,false);}level(e){let t=0,n=e.parentElement;for(;n&&n!==this.container;)this.matchesGroup(n)&&t++,n=n.parentElement;return t}parent(e){let t=this.items,n=e.parentElement;for(;n&&n!==this.container;){if(t.indexOf(n)!==-1)return n;n=n.parentElement;}return null}elementOf(e){return e===void 0?this.activeElement:typeof e=="number"?this.items[e]??null:e}matchesGroup(e){if(typeof e.matches=="function")try{return e.matches(this.groupSelector)}catch{return false}return false}setExpanded(e,t){this.collapseBehavior!=="none"&&I(e,"aria-expanded",t?"true":"false",this.manageAria);let n=e.querySelector(this.groupSelector);n&&(this.toggleHiddenValue&&n.hasAttribute("hidden")===t&&n.toggleAttribute("hidden",!t),this.hiddenClassValue&&n.classList.toggle(this.hiddenClassValue,!t)),this.refresh(),t?this.userOnExpand?.(e,this.items.indexOf(e)):this.userOnCollapse?.(e,this.items.indexOf(e));}handleExpandKey(e){if(!this.isExpandable(e))return;if(!this.isExpanded(e)){this.setExpanded(e,true);return}let t=this.items.indexOf(e);t!==-1&&t+1<this.items.length&&this.focusIndex(t+1);}handleCollapseKey(e){if(this.isExpandable(e)&&this.isExpanded(e)){this.setExpanded(e,false);return}let t=this.parent(e);t&&this.focusElement(t);}};function Yt(i={}){return new xe(i)}var Ae=class extends w{constructor(t){let n=typeof document<"u"?document:null,r=b(t.container,n),s=b(t.input,n)??r?.querySelector("input:not([type='hidden']), textarea")??null;super({activeDescendant:s??true,...t},{mode:t.mode??"vertical",loop:t.loop??true,defaultKeys:Pe,listenTarget:s??r??n});this.extra=new M;this.openValue=false;this.listId=null;this.listElement=null;if(this.inputElement=s,this.manageAria=t.aria!==false,this.toggleHiddenValue=t.toggleHidden!==false,this.userOnQuery=t.onQuery,this.userOnSubmit=t.onSubmit,this.userOnCancel=t.onCancel,t.openKeys&&typeof document<"u"){let o=Array.isArray(t.openKeys)?t.openKeys:[t.openKeys];this.openMatcher=new O({open:o}),this.extra.add(document,"keydown",l=>{let a=l;this.openMatcher.match(D(a),this)?.complete&&(a.preventDefault(),this.toggle());});}else this.openMatcher=null;this.listElement=b(t.list,n)??this.container,this.manageAria&&this.listElement&&(x(this.listElement,"listbox",true),this.listId=H(this.listElement,"keystra-palette")),this.manageAria&&this.inputElement&&(x(this.inputElement,"combobox",true),I(this.inputElement,"aria-controls",this.listId,true),I(this.inputElement,"aria-expanded","false",true),this.inputElement.hasAttribute("aria-autocomplete")||this.inputElement.setAttribute("aria-autocomplete","list"),t.placeholder&&!this.inputElement.hasAttribute("placeholder")&&this.inputElement.setAttribute("placeholder",t.placeholder)),this.wireInput(),this.decorateItems(),this.on("refresh",()=>this.decorateItems()),this.on("select",({element:o})=>{this.userOnSubmit?.(o??null,this.query);}),this.on("action",({action:o,event:l})=>{o==="escape"&&(l?.preventDefault(),this.userOnCancel?.(),this.close());});}get isOpen(){return this.openValue}get query(){return this.inputElement?.value??""}get input(){return this.inputElement}open(){this.openValue||(this.openValue=true,this.enable(),this.rememberFocus(),this.container&&this.toggleHiddenValue&&this.container.hasAttribute("hidden")&&this.container.removeAttribute("hidden"),this.inputElement&&(L(this.inputElement),typeof this.inputElement.select=="function"&&this.inputElement.select()),this.refresh(),this.setActiveIndex(0,{focus:false}),I(this.inputElement,"aria-expanded","true",this.manageAria));}close(t={}){this.openValue&&(this.openValue=false,this.disable(),this.container&&this.toggleHiddenValue&&!this.container.hasAttribute("hidden")&&this.container.setAttribute("hidden",""),I(this.inputElement,"aria-expanded","false",this.manageAria),t.restoreFocus!==false&&this.restoreFocus());}toggle(){this.openValue?this.close():this.open();}setQuery(t){this.inputElement&&this.inputElement.value!==t&&(this.inputElement.value=t,this.userOnQuery?.(t));}destroy(){this.extra.dispose(),this.openMatcher?.dispose(),this.inputElement&&this.manageAria&&(this.inputElement.removeAttribute("aria-expanded"),this.listId&&this.inputElement.removeAttribute("aria-controls")),super.destroy();}ownsAction(t){return t==="select"||t==="escape"}runAction(t,n,r){return super.runAction(t,n,r)?true:t!=="select"?false:(this.userOnSubmit?.(null,this.query),true)}decorateItems(){k(this.listElement,this.items,"listbox","option",this.manageAria);}wireInput(){let t=this.inputElement;t&&this.extra.add(t,"input",()=>{this.userOnQuery?.(t.value),this.refresh(),this.setActiveIndex(0,{focus:false});});}};function $t(i={}){return new Ae(i)}function Qt(i={}){let e=J({keys:i.mode===void 0?He:void 0,loop:true,roving:true,...i}),t=e.items;if(t.length===0)return e;let n=i.initialIndex??-1;if(n<0){for(let r=0;r<t.length;r++)if(t[r].getAttribute("tabindex")==="0"){n=r;break}}return n>0&&e.setActiveIndex(n,{focus:false}),e}exports.Emitter=Y;exports.EventManager=M;exports.FocusManager=j;exports.ItemCollection=Q;exports.KeyMatcher=O;exports.LayoutCache=$;exports.NavigationController=w;exports.RovingTabindex=_;exports.SelectionManager=G;exports.actionDelta=Le;exports.actionToDirection=Me;exports.codeToKey=Ue;exports.composeStrategies=Ft;exports.contains=T;exports.createCommandPalette=$t;exports.createCustomStrategy=Rt;exports.createDirectionalStrategy=oe;exports.createDropdown=Ut;exports.createGrid=jt;exports.createGridStrategy=W;exports.createKeyBinding=kt;exports.createKeyMatcher=At;exports.createKeystra=J;exports.createList=_t;exports.createMenu=Bt;exports.createRafThrottle=lt;exports.createRectOf=de;exports.createRovingFocus=Qt;exports.createSequentialStrategy=V;exports.createTabs=Vt;exports.createTree=Yt;exports.createTypeahead=pe;exports.defaultKeysFor=ne;exports.describeEvent=pt;exports.directionFromAction=De;exports.findNextIndex=Ce;exports.focusElement=L;exports.formatKeyCombo=_e;exports.getText=se;exports.hasDom=Ke;exports.horizontalStrategy=it;exports.isDisabled=R;exports.isEditableTarget=z;exports.isFocusable=Je;exports.isHidden=F;exports.isModifierKey=he;exports.isPrintableKey=ze;exports.keyEquals=Ge;exports.mergeKeys=ie;exports.normalizeKeyEvent=D;exports.normalizeKeyName=Z;exports.parseKeyBinding=me;exports.queryItems=P;exports.resolveElement=b;exports.setAttribute=q;exports.toggleClass=te;exports.useKeystra=Nt;exports.verticalStrategy=nt;return exports;})({});
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { createKeyBinding, useKeystra } from './chunk-LYYUOTBP.js';
2
+ export { composeStrategies, createCustomStrategy } from './chunk-KDOJARJD.js';
3
+ export { createCommandPalette, createDropdown, createGrid, createList, createMenu, createRovingFocus, createTabs, createTree } from './chunk-2BLQUBG7.js';
4
+ export { EventManager, ItemCollection, KeyMatcher, NavigationController, codeToKey, createKeyMatcher, createKeystra, createRafThrottle, createRectOf, createTypeahead, defaultKeysFor, describeEvent, formatKeyCombo, isModifierKey, isPrintableKey, keyEquals, mergeKeys, normalizeKeyEvent, normalizeKeyName, parseKeyBinding } from './chunk-U7YK6PPT.js';
5
+ export { actionDelta, actionToDirection, createDirectionalStrategy, createGridStrategy, createSequentialStrategy, directionFromAction, findNextIndex, horizontalStrategy, verticalStrategy } from './chunk-XFNYIPOW.js';
6
+ export { FocusManager, RovingTabindex } from './chunk-ZOJRXXQN.js';
7
+ export { SelectionManager } from './chunk-SSIKGDD4.js';
8
+ export { Emitter, LayoutCache } from './chunk-S5YVXIMA.js';
9
+ export { contains, focusElement, getText, hasDom, isDisabled, isEditableTarget, isFocusable, isHidden, queryItems, resolveElement, setAttribute, toggleClass } from './chunk-77GGU3AX.js';
@@ -0,0 +1,17 @@
1
+ import { f as EventName, e as EventHandler, r as KeystraEventMap } from './index-IZkcWAXP.js';
2
+
3
+ declare class Emitter<T extends Element = HTMLElement> {
4
+ private handlers;
5
+ on<E extends EventName>(event: E, handler: EventHandler<E, T>): () => void;
6
+ off<E extends EventName>(event: E, handler?: EventHandler<E, T>): void;
7
+ emit<E extends EventName>(event: E, payload: KeystraEventMap<T>[E]): void;
8
+ clear(): void;
9
+ get size(): number;
10
+ }
11
+
12
+ declare class LayoutCache {
13
+ private rects;
14
+ rect(element: Element, version: number): DOMRect;
15
+ }
16
+
17
+ export { Emitter as E, LayoutCache as L };
@@ -0,0 +1,17 @@
1
+ import { f as EventName, e as EventHandler, r as KeystraEventMap } from './index-IZkcWAXP.cjs';
2
+
3
+ declare class Emitter<T extends Element = HTMLElement> {
4
+ private handlers;
5
+ on<E extends EventName>(event: E, handler: EventHandler<E, T>): () => void;
6
+ off<E extends EventName>(event: E, handler?: EventHandler<E, T>): void;
7
+ emit<E extends EventName>(event: E, payload: KeystraEventMap<T>[E]): void;
8
+ clear(): void;
9
+ get size(): number;
10
+ }
11
+
12
+ declare class LayoutCache {
13
+ private rects;
14
+ rect(element: Element, version: number): DOMRect;
15
+ }
16
+
17
+ export { Emitter as E, LayoutCache as L };
@@ -0,0 +1,293 @@
1
+ 'use strict';
2
+
3
+ // src/navigation/sequential.ts
4
+ function findNextIndex(total, from, step, loop, clamp = true) {
5
+ if (total === 0 || step === 0) return -1;
6
+ if (from < 0 || from >= total) {
7
+ return step > 0 ? 0 : total - 1;
8
+ }
9
+ const next = from + step;
10
+ if (loop) return (next % total + total) % total;
11
+ if (next < 0) return clamp ? 0 : -1;
12
+ if (next >= total) return clamp ? total - 1 : -1;
13
+ return next;
14
+ }
15
+ function actionDelta(action, direction) {
16
+ if (direction) {
17
+ if (direction === "down" || direction === "right") return 1;
18
+ if (direction === "up" || direction === "left") return -1;
19
+ return 0;
20
+ }
21
+ switch (action) {
22
+ case "next":
23
+ case "down":
24
+ case "right":
25
+ return 1;
26
+ case "previous":
27
+ case "up":
28
+ case "left":
29
+ return -1;
30
+ default:
31
+ return 0;
32
+ }
33
+ }
34
+ function createSequentialStrategy(axis = "both") {
35
+ return (context) => {
36
+ const { action, direction, index, items, loop } = context;
37
+ const delta = actionDelta(action, direction);
38
+ if (delta === 0) return null;
39
+ const isVerticalAction = direction !== null ? direction === "up" || direction === "down" : action === "up" || action === "down";
40
+ if (axis === "vertical" && !isVerticalAction && direction !== null) return null;
41
+ if (axis === "horizontal" && isVerticalAction) return null;
42
+ return findNextIndex(items.length, index, delta, loop);
43
+ };
44
+ }
45
+ var verticalStrategy = /* @__PURE__ */ createSequentialStrategy("vertical");
46
+ var horizontalStrategy = /* @__PURE__ */ createSequentialStrategy("horizontal");
47
+
48
+ // src/navigation/directional.ts
49
+ function actionToDirection(action) {
50
+ switch (action) {
51
+ case "up":
52
+ return "up";
53
+ case "down":
54
+ return "down";
55
+ case "left":
56
+ return "left";
57
+ case "right":
58
+ return "right";
59
+ default:
60
+ return null;
61
+ }
62
+ }
63
+ function createDirectionalStrategy(options = {}) {
64
+ const crossWeight = options.crossAxisWeight ?? 2;
65
+ return (context) => {
66
+ const direction = context.direction ?? actionToDirection(context.action);
67
+ if (!direction) return null;
68
+ const items = context.items;
69
+ const total = items.length;
70
+ if (total === 0) return -1;
71
+ const from = context.index;
72
+ if (from < 0 || from >= total) {
73
+ return direction === "down" || direction === "right" ? 0 : total - 1;
74
+ }
75
+ const current = items[from];
76
+ if (!current) return null;
77
+ const origin = context.rectOf(current);
78
+ const ox = origin.left + origin.width / 2;
79
+ const oy = origin.top + origin.height / 2;
80
+ const horizontal = direction === "left" || direction === "right";
81
+ const sign = direction === "right" || direction === "down" ? 1 : -1;
82
+ let bestIndex = -1;
83
+ let bestScore = Infinity;
84
+ let nearestIndex = -1;
85
+ let nearestDistance = Infinity;
86
+ for (let i = 0; i < total; i++) {
87
+ if (i === from) continue;
88
+ const element = items[i];
89
+ const rect = context.rectOf(element);
90
+ if (rect.width === 0 && rect.height === 0) continue;
91
+ const dx = rect.left + rect.width / 2 - ox;
92
+ const dy = rect.top + rect.height / 2 - oy;
93
+ const distance = Math.hypot(dx, dy);
94
+ if (distance < nearestDistance) {
95
+ nearestDistance = distance;
96
+ nearestIndex = i;
97
+ }
98
+ const primary = (horizontal ? dx : dy) * sign;
99
+ if (primary <= 0) continue;
100
+ const cross = Math.abs(horizontal ? dy : dx);
101
+ if (cross > primary) continue;
102
+ const score = primary + cross * crossWeight;
103
+ if (score < bestScore) {
104
+ bestScore = score;
105
+ bestIndex = i;
106
+ }
107
+ }
108
+ if (bestIndex !== -1) return bestIndex;
109
+ const allowFallback = options.wrapFallback ?? context.loop;
110
+ return allowFallback ? nearestIndex : null;
111
+ };
112
+ }
113
+
114
+ // src/navigation/grid.ts
115
+ function computeGridInfo(context) {
116
+ const items = context.items;
117
+ const total = items.length;
118
+ if (total === 0) return { starts: [0], columns: 1 };
119
+ const starts = [0];
120
+ let rowTop = context.rectOf(items[0]).top;
121
+ let currentColumns = 1;
122
+ let maxColumns = 1;
123
+ for (let i = 1; i < total; i++) {
124
+ const rect = context.rectOf(items[i]);
125
+ if (Math.abs(rect.top - rowTop) < 2) {
126
+ currentColumns++;
127
+ continue;
128
+ }
129
+ maxColumns = Math.max(maxColumns, currentColumns);
130
+ currentColumns = 1;
131
+ rowTop = rect.top;
132
+ starts.push(i);
133
+ }
134
+ return { starts, columns: Math.max(maxColumns, currentColumns) };
135
+ }
136
+ function declaredInfo(total, columns) {
137
+ const starts = [];
138
+ for (let start = 0; start < total; start += columns) starts.push(start);
139
+ if (starts.length === 0) starts.push(0);
140
+ return { starts, columns };
141
+ }
142
+ function rowOf(info, index) {
143
+ const starts = info.starts;
144
+ let row = 0;
145
+ for (let i = 0; i < starts.length; i++) {
146
+ if (starts[i] <= index) row = i;
147
+ else break;
148
+ }
149
+ return row;
150
+ }
151
+ function rowStart(info, row) {
152
+ return info.starts[row] ?? 0;
153
+ }
154
+ function rowEnd(info, row, total) {
155
+ return row + 1 < info.starts.length ? info.starts[row + 1] - 1 : total - 1;
156
+ }
157
+ function createGridStrategy(options = {}) {
158
+ const maintainColumn = options.maintainColumn !== false;
159
+ const rowHomeEnd = options.rowHomeEnd === true;
160
+ const declared = options.columns && options.columns > 0 ? options.columns : 0;
161
+ let cachedVersion = -1;
162
+ let cachedItems = null;
163
+ let cached = { starts: [0], columns: 1 };
164
+ return (context) => {
165
+ const items = context.items;
166
+ const total = items.length;
167
+ if (total === 0) return -1;
168
+ const columns = declared || context.columns;
169
+ const index = context.index;
170
+ const direction = context.direction ?? directionFromAction(context.action);
171
+ if (!direction) {
172
+ if (context.action === "first") {
173
+ if (!rowHomeEnd || index < 0) return 0;
174
+ const info2 = infoFor(context, columns, total);
175
+ return rowStart(info2, rowOf(info2, index));
176
+ }
177
+ if (context.action === "last") {
178
+ if (!rowHomeEnd || index < 0) return total - 1;
179
+ const info2 = infoFor(context, columns, total);
180
+ return rowEnd(info2, rowOf(info2, index), total);
181
+ }
182
+ return null;
183
+ }
184
+ if (index < 0 || index >= total) {
185
+ return direction === "down" || direction === "right" ? 0 : total - 1;
186
+ }
187
+ const info = infoFor(context, columns, total);
188
+ const row = rowOf(info, index);
189
+ const start = rowStart(info, row);
190
+ const end = rowEnd(info, row, total);
191
+ if (direction === "left" || direction === "right") {
192
+ const next = index + (direction === "right" ? 1 : -1);
193
+ if (next >= start && next <= end) return next;
194
+ if (!context.loop) return index;
195
+ return direction === "right" ? start : end;
196
+ }
197
+ const rowDelta = direction === "down" ? 1 : -1;
198
+ let targetRow = row + rowDelta;
199
+ if (targetRow < 0 || targetRow >= info.starts.length) {
200
+ if (!context.loop) return index;
201
+ targetRow = targetRow < 0 ? info.starts.length - 1 : 0;
202
+ }
203
+ const targetStart = rowStart(info, targetRow);
204
+ const targetEnd = rowEnd(info, targetRow, total);
205
+ if (columns > 0 && !maintainColumn) return targetStart;
206
+ if (columns > 0) {
207
+ const column = index - start;
208
+ const candidate = targetStart + column;
209
+ return candidate <= targetEnd ? candidate : targetEnd;
210
+ }
211
+ const current = context.rectOf(items[index]);
212
+ return nearestInRow(context, targetStart, targetEnd, current.left + current.width / 2);
213
+ function infoFor(ctx, cols, count) {
214
+ if (cols > 0) return declaredInfo(count, cols);
215
+ if (cachedVersion === ctx.version && cachedItems === ctx.items) return cached;
216
+ cached = computeGridInfo(ctx);
217
+ cachedVersion = ctx.version;
218
+ cachedItems = ctx.items;
219
+ return cached;
220
+ }
221
+ };
222
+ }
223
+ function nearestInRow(context, start, end, targetX) {
224
+ let best = start;
225
+ let bestDistance = Infinity;
226
+ for (let i = start; i <= end; i++) {
227
+ const element = context.items[i];
228
+ if (!element) continue;
229
+ const rect = context.rectOf(element);
230
+ const distance = Math.abs(rect.left + rect.width / 2 - targetX);
231
+ if (distance < bestDistance) {
232
+ bestDistance = distance;
233
+ best = i;
234
+ }
235
+ }
236
+ return best;
237
+ }
238
+ function directionFromAction(action) {
239
+ switch (action) {
240
+ case "up":
241
+ case "previous":
242
+ return "up";
243
+ case "down":
244
+ case "next":
245
+ return "down";
246
+ case "left":
247
+ return "left";
248
+ case "right":
249
+ return "right";
250
+ default:
251
+ return null;
252
+ }
253
+ }
254
+
255
+ // src/navigation/custom.ts
256
+ function createCustomStrategy(hooks) {
257
+ const resolved = typeof hooks === "function" ? { onNavigate: hooks } : hooks;
258
+ return (context) => {
259
+ if (context.direction || isMovementAction(context.action)) {
260
+ const result2 = resolved.onNavigate?.(context);
261
+ if (typeof result2 === "number") return result2;
262
+ return resolved.fallback ? resolved.fallback(context) : null;
263
+ }
264
+ const result = resolved.onAction?.(context);
265
+ if (typeof result === "number") return result;
266
+ return resolved.onNavigate?.(context) ?? null;
267
+ };
268
+ }
269
+ function composeStrategies(...strategies) {
270
+ const list = strategies.filter(Boolean);
271
+ return (context) => {
272
+ for (let i = 0; i < list.length; i++) {
273
+ const result = list[i](context);
274
+ if (typeof result === "number" && result >= 0) return result;
275
+ }
276
+ return null;
277
+ };
278
+ }
279
+ function isMovementAction(action) {
280
+ return action === "next" || action === "previous" || action === "first" || action === "last" || action === "pageUp" || action === "pageDown";
281
+ }
282
+
283
+ exports.actionDelta = actionDelta;
284
+ exports.actionToDirection = actionToDirection;
285
+ exports.composeStrategies = composeStrategies;
286
+ exports.createCustomStrategy = createCustomStrategy;
287
+ exports.createDirectionalStrategy = createDirectionalStrategy;
288
+ exports.createGridStrategy = createGridStrategy;
289
+ exports.createSequentialStrategy = createSequentialStrategy;
290
+ exports.directionFromAction = directionFromAction;
291
+ exports.findNextIndex = findNextIndex;
292
+ exports.horizontalStrategy = horizontalStrategy;
293
+ exports.verticalStrategy = verticalStrategy;
@@ -0,0 +1,33 @@
1
+ import { K as KeyAction, b as Direction, w as NavigationStrategy, x as NavigationStrategyContext } from './index-IZkcWAXP.cjs';
2
+ export { N as NavigationMode } from './index-IZkcWAXP.cjs';
3
+
4
+ declare function findNextIndex(total: number, from: number, step: number, loop: boolean, clamp?: boolean): number;
5
+ declare function actionDelta(action: KeyAction, direction: Direction | null): number;
6
+ declare function createSequentialStrategy<T extends Element = HTMLElement>(axis?: "vertical" | "horizontal" | "both"): NavigationStrategy<T>;
7
+ declare const verticalStrategy: NavigationStrategy<HTMLElement>;
8
+ declare const horizontalStrategy: NavigationStrategy<HTMLElement>;
9
+
10
+ interface DirectionalOptions {
11
+ readonly crossAxisWeight?: number;
12
+ readonly wrapFallback?: boolean;
13
+ }
14
+ declare function actionToDirection(action: KeyAction): Direction | null;
15
+ declare function createDirectionalStrategy<T extends Element = HTMLElement>(options?: DirectionalOptions): NavigationStrategy<T>;
16
+
17
+ interface GridStrategyOptions {
18
+ readonly columns?: number;
19
+ readonly maintainColumn?: boolean;
20
+ readonly rowHomeEnd?: boolean;
21
+ }
22
+ declare function createGridStrategy<T extends Element = HTMLElement>(options?: GridStrategyOptions): NavigationStrategy<T>;
23
+ declare function directionFromAction(action: KeyAction): Direction | null;
24
+
25
+ interface CustomStrategyHooks<T extends Element = HTMLElement> {
26
+ readonly onNavigate?: (context: NavigationStrategyContext<T>) => number | null | undefined;
27
+ readonly fallback?: NavigationStrategy<T> | null;
28
+ readonly onAction?: (context: NavigationStrategyContext<T>) => number | null | undefined;
29
+ }
30
+ declare function createCustomStrategy<T extends Element = HTMLElement>(hooks: CustomStrategyHooks<T> | ((context: NavigationStrategyContext<T>) => number | null | undefined)): NavigationStrategy<T>;
31
+ declare function composeStrategies<T extends Element = HTMLElement>(...strategies: (NavigationStrategy<T> | null | undefined)[]): NavigationStrategy<T>;
32
+
33
+ export { type CustomStrategyHooks, Direction, type DirectionalOptions, type GridStrategyOptions, NavigationStrategy, NavigationStrategyContext, actionDelta, actionToDirection, composeStrategies, createCustomStrategy, createDirectionalStrategy, createGridStrategy, createSequentialStrategy, directionFromAction, findNextIndex, horizontalStrategy, verticalStrategy };
@@ -0,0 +1,33 @@
1
+ import { K as KeyAction, b as Direction, w as NavigationStrategy, x as NavigationStrategyContext } from './index-IZkcWAXP.js';
2
+ export { N as NavigationMode } from './index-IZkcWAXP.js';
3
+
4
+ declare function findNextIndex(total: number, from: number, step: number, loop: boolean, clamp?: boolean): number;
5
+ declare function actionDelta(action: KeyAction, direction: Direction | null): number;
6
+ declare function createSequentialStrategy<T extends Element = HTMLElement>(axis?: "vertical" | "horizontal" | "both"): NavigationStrategy<T>;
7
+ declare const verticalStrategy: NavigationStrategy<HTMLElement>;
8
+ declare const horizontalStrategy: NavigationStrategy<HTMLElement>;
9
+
10
+ interface DirectionalOptions {
11
+ readonly crossAxisWeight?: number;
12
+ readonly wrapFallback?: boolean;
13
+ }
14
+ declare function actionToDirection(action: KeyAction): Direction | null;
15
+ declare function createDirectionalStrategy<T extends Element = HTMLElement>(options?: DirectionalOptions): NavigationStrategy<T>;
16
+
17
+ interface GridStrategyOptions {
18
+ readonly columns?: number;
19
+ readonly maintainColumn?: boolean;
20
+ readonly rowHomeEnd?: boolean;
21
+ }
22
+ declare function createGridStrategy<T extends Element = HTMLElement>(options?: GridStrategyOptions): NavigationStrategy<T>;
23
+ declare function directionFromAction(action: KeyAction): Direction | null;
24
+
25
+ interface CustomStrategyHooks<T extends Element = HTMLElement> {
26
+ readonly onNavigate?: (context: NavigationStrategyContext<T>) => number | null | undefined;
27
+ readonly fallback?: NavigationStrategy<T> | null;
28
+ readonly onAction?: (context: NavigationStrategyContext<T>) => number | null | undefined;
29
+ }
30
+ declare function createCustomStrategy<T extends Element = HTMLElement>(hooks: CustomStrategyHooks<T> | ((context: NavigationStrategyContext<T>) => number | null | undefined)): NavigationStrategy<T>;
31
+ declare function composeStrategies<T extends Element = HTMLElement>(...strategies: (NavigationStrategy<T> | null | undefined)[]): NavigationStrategy<T>;
32
+
33
+ export { type CustomStrategyHooks, Direction, type DirectionalOptions, type GridStrategyOptions, NavigationStrategy, NavigationStrategyContext, actionDelta, actionToDirection, composeStrategies, createCustomStrategy, createDirectionalStrategy, createGridStrategy, createSequentialStrategy, directionFromAction, findNextIndex, horizontalStrategy, verticalStrategy };
@@ -0,0 +1,2 @@
1
+ export { composeStrategies, createCustomStrategy } from './chunk-KDOJARJD.js';
2
+ export { actionDelta, actionToDirection, createDirectionalStrategy, createGridStrategy, createSequentialStrategy, directionFromAction, findNextIndex, horizontalStrategy, verticalStrategy } from './chunk-XFNYIPOW.js';