"use strict";(globalThis.webpackChunk=globalThis.webpackChunk||[]).push([["vendors-node_modules_github_text-expander-element_dist_index_js"],{33491:()=>{let Combobox=class Combobox{constructor(t,i,{tabInsertsSuggestions:n,defaultFirstOption:s,scrollIntoViewOptions:o}={}){this.input=t,this.list=i,this.tabInsertsSuggestions=null==n||n,this.defaultFirstOption=null!=s&&s,this.scrollIntoViewOptions=null!=o?o:{block:"nearest",inline:"nearest"},this.isComposing=!1,i.id||(i.id=`combobox-${Math.random().toString().slice(2,6)}`),this.ctrlBindings=!!navigator.userAgent.match(/Macintosh/),this.keyboardEventHandler=t=>(function(t,i){if(!t.shiftKey&&!t.metaKey&&!t.altKey&&(i.ctrlBindings||!t.ctrlKey)&&!i.isComposing)switch(t.key){case"Enter":e(i.input,i.list)&&t.preventDefault();break;case"Tab":i.tabInsertsSuggestions&&e(i.input,i.list)&&t.preventDefault();break;case"Escape":i.clearSelection();break;case"ArrowDown":i.navigate(1),t.preventDefault();break;case"ArrowUp":i.navigate(-1),t.preventDefault();break;case"n":i.ctrlBindings&&t.ctrlKey&&(i.navigate(1),t.preventDefault());break;case"p":i.ctrlBindings&&t.ctrlKey&&(i.navigate(-1),t.preventDefault());break;default:if(t.ctrlKey)break;i.clearSelection()}})(t,this),this.compositionEventHandler=t=>(function(t,e){e.isComposing="compositionstart"===t.type;let i=document.getElementById(e.input.getAttribute("aria-controls")||"");i&&e.clearSelection()})(t,this),this.inputHandler=this.clearSelection.bind(this),t.setAttribute("role","combobox"),t.setAttribute("aria-controls",i.id),t.setAttribute("aria-expanded","false"),t.setAttribute("aria-autocomplete","list"),t.setAttribute("aria-haspopup","listbox")}destroy(){this.clearSelection(),this.stop(),this.input.removeAttribute("role"),this.input.removeAttribute("aria-controls"),this.input.removeAttribute("aria-expanded"),this.input.removeAttribute("aria-autocomplete"),this.input.removeAttribute("aria-haspopup")}start(){this.input.setAttribute("aria-expanded","true"),this.input.addEventListener("compositionstart",this.compositionEventHandler),this.input.addEventListener("compositionend",this.compositionEventHandler),this.input.addEventListener("input",this.inputHandler),this.input.addEventListener("keydown",this.keyboardEventHandler),this.list.addEventListener("click",t),this.indicateDefaultOption()}stop(){this.clearSelection(),this.input.setAttribute("aria-expanded","false"),this.input.removeEventListener("compositionstart",this.compositionEventHandler),this.input.removeEventListener("compositionend",this.compositionEventHandler),this.input.removeEventListener("input",this.inputHandler),this.input.removeEventListener("keydown",this.keyboardEventHandler),this.list.removeEventListener("click",t)}indicateDefaultOption(){var t;this.defaultFirstOption&&(null===(t=Array.from(this.list.querySelectorAll('[role="option"]:not([aria-disabled="true"])')).filter(i)[0])||void 0===t||t.setAttribute("data-combobox-option-default","true"))}navigate(t=1){let e=Array.from(this.list.querySelectorAll('[aria-selected="true"]')).filter(i)[0],n=Array.from(this.list.querySelectorAll('[role="option"]')).filter(i),s=n.indexOf(e);if(s===n.length-1&&1===t||0===s&&-1===t){this.clearSelection(),this.input.focus();return}let o=1===t?0:n.length-1;if(e&&s>=0){let e=s+t;e>=0&&e0||t.offsetHeight>0)}let n=/\s|\(|\[/,s=["position:absolute;","overflow:auto;","word-wrap:break-word;","top:0px;","left:-9999px;"],o=["box-sizing","font-family","font-size","font-style","font-variant","font-weight","height","letter-spacing","line-height","max-height","min-height","padding-bottom","padding-left","padding-right","padding-top","border-bottom","border-left","border-right","border-top","text-decoration","text-indent","text-transform","width","word-spacing"],r=new WeakMap,a=new WeakMap;let TextExpander=class TextExpander{constructor(t,e){this.expander=t,this.input=e,this.combobox=null,this.menu=null,this.match=null,this.justPasted=!1,this.lookBackIndex=0,this.oninput=this.onInput.bind(this),this.onpaste=this.onPaste.bind(this),this.onkeydown=this.onKeydown.bind(this),this.oncommit=this.onCommit.bind(this),this.onmousedown=this.onMousedown.bind(this),this.onblur=this.onBlur.bind(this),this.interactingWithList=!1,e.addEventListener("paste",this.onpaste),e.addEventListener("input",this.oninput),e.addEventListener("keydown",this.onkeydown),e.addEventListener("blur",this.onblur)}destroy(){this.input.removeEventListener("paste",this.onpaste),this.input.removeEventListener("input",this.oninput),this.input.removeEventListener("keydown",this.onkeydown),this.input.removeEventListener("blur",this.onblur)}dismissMenu(){this.deactivate()&&(this.lookBackIndex=this.input.selectionEnd||this.lookBackIndex)}activate(t,e){var i,n;if(this.input!==document.activeElement&&this.input!==(null===(n=null===(i=document.activeElement)||void 0===i?void 0:i.shadowRoot)||void 0===n?void 0:n.activeElement))return;this.deactivate(),this.menu=e,e.id||(e.id=`text-expander-${Math.floor(1e5*Math.random()).toString()}`),this.expander.append(e),this.combobox=new Combobox(this.input,e),this.expander.dispatchEvent(new Event("text-expander-activate"));let{top:a,left:l}=function(t,e=t.selectionEnd){let{mirror:i,marker:n}=function(t,e){let i,n;let a=t.nodeName.toLowerCase();if("textarea"!==a&&"input"!==a)throw Error("expected textField to a textarea or input");let l=r.get(t);if(l&&l.parentElement===t.parentElement)l.innerHTML="";else{l=document.createElement("div"),r.set(t,l);let e=window.getComputedStyle(t),i=s.slice(0);"textarea"===a?i.push("white-space:pre-wrap;"):i.push("white-space:nowrap;");for(let t=0,n=o.length;t{i.remove()},5e3),{top:l.top-a.top,left:l.left-a.left}}(this.input,t.position);if(function(t){try{if(t.matches(":popover-open"))return!0}catch(t){}try{if(t.matches("dialog:modal"))return!0}catch(t){}try{if(t.matches(":fullscreen"))return!0}catch(t){}return!1}(e)){let t=this.input.getBoundingClientRect();a+=t.top,l+=t.left,"absolute"===getComputedStyle(e).position&&(a+=window.scrollY,l+=window.scrollX)}e.style.top=`${a}px`,e.style.left=`${l}px`,this.combobox.start(),e.addEventListener("combobox-commit",this.oncommit),e.addEventListener("mousedown",this.onmousedown),this.combobox.navigate(1)}deactivate(){let t=this.menu;return!!t&&!!this.combobox&&(this.expander.dispatchEvent(new Event("text-expander-deactivate")),this.menu=null,t.removeEventListener("combobox-commit",this.oncommit),t.removeEventListener("mousedown",this.onmousedown),this.combobox.destroy(),this.combobox=null,t.remove(),!0)}onCommit({target:t}){var e;if(!(t instanceof HTMLElement)||!this.combobox)return;let i=this.match;if(!i)return;let n=this.input.value.substring(0,i.position-i.key.length),s=this.input.value.substring(i.position+i.text.length),o={item:t,key:i.key,value:null,continue:!1},r=!this.expander.dispatchEvent(new CustomEvent("text-expander-value",{cancelable:!0,detail:o}));if(r||!o.value)return;let a=null!==(e=this.expander.getAttribute("suffix"))&&void 0!==e?e:" ";o.continue&&(a="");let l=`${o.value}${a}`;this.input.value=n+l+s;let u=n.length+l.length;this.deactivate(),this.input.focus({preventScroll:!0}),this.input.selectionStart=u,this.input.selectionEnd=u,o.continue||(this.lookBackIndex=u,this.match=null),this.expander.dispatchEvent(new CustomEvent("text-expander-committed",{cancelable:!1,detail:{input:this.input}}))}onBlur(){if(this.interactingWithList){this.interactingWithList=!1;return}this.deactivate()}onPaste(){this.justPasted=!0}async onInput(){if(this.justPasted){this.justPasted=!1;return}let t=this.findMatch();if(t){this.match=t;let e=await this.notifyProviders(t);if(!this.match)return;e?this.activate(t,e):this.deactivate()}else this.match=null,this.deactivate()}findMatch(){let t=this.input.selectionEnd||0,e=this.input.value;for(let{key:i,multiWord:s}of(t<=this.lookBackIndex&&(this.lookBackIndex=t-1),this.expander.keys)){let o=function(t,e,i,{multiWord:s,lookBackIndex:o,lastMatchPosition:r}={multiWord:!1,lookBackIndex:0,lastMatchPosition:null}){let a=t.lastIndexOf(e,i-1);if(-1===a||a=a+e.length+1)return;let s=t.lastIndexOf("\n",i-1);if(s>a)return;let o=t.lastIndexOf(".",i-1);if(o>a)return}else{let e=t.lastIndexOf(" ",i-1);if(e>a)return}let l=t[a-1];if(l&&!n.test(l))return;let u=t.substring(a+e.length,i);return{text:u,position:a+e.length}}(e,i,t,{multiWord:s,lookBackIndex:this.lookBackIndex,lastMatchPosition:this.match?this.match.position:null});if(o)return{text:o.text,key:i,position:o.position}}}async notifyProviders(t){let e=[],i=!this.expander.dispatchEvent(new CustomEvent("text-expander-change",{cancelable:!0,detail:{provide:t=>e.push(t),text:t.text,key:t.key}}));if(i)return;let n=await Promise.all(e),s=n.filter(t=>t.matched).map(t=>t.fragment);return s[0]}onMousedown(){this.interactingWithList=!0}onKeydown(t){"Escape"===t.key&&(this.match=null,this.deactivate()&&(this.lookBackIndex=this.input.selectionEnd||this.lookBackIndex,t.stopImmediatePropagation(),t.preventDefault()))}};let TextExpanderElement=class TextExpanderElement extends HTMLElement{get keys(){let t=this.getAttribute("keys"),e=t?t.split(" "):[],i=this.getAttribute("multiword"),n=i?i.split(" "):[],s=0===n.length&&this.hasAttribute("multiword");return e.map(t=>({key:t,multiWord:s||n.includes(t)}))}connectedCallback(){let t=this.querySelector('input[type="text"], textarea');if(!(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement))return;let e=new TextExpander(this,t);a.set(this,e)}disconnectedCallback(){let t=a.get(this);t&&(t.destroy(),a.delete(this))}dismiss(){let t=a.get(this);t&&t.dismissMenu()}};window.customElements.get("text-expander")||(window.TextExpanderElement=TextExpanderElement,window.customElements.define("text-expander",TextExpanderElement))}}]); //# sourceMappingURL=vendors-node_modules_github_text-expander-element_dist_index_js-c84e519e3296.js.map