"use strict";(globalThis.webpackChunk=globalThis.webpackChunk||[]).push([["vendors-node_modules_github_text-expander-element_dist_index_js"],{81028:()=>{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,document.getElementById(e.input.getAttribute("aria-controls")||"")&&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|\(|\[/;let CustomHTMLElement=class CustomHTMLElement extends HTMLElement{};let InputStyleCloneUpdateEvent=class InputStyleCloneUpdateEvent extends Event{constructor(){super("update")}};let s=new WeakMap;let InputStyleCloneElement=class InputStyleCloneElement extends CustomHTMLElement{#t=new MutationObserver(()=>this.#e());#i=new ResizeObserver(()=>this.#n());#s;#o;static for(t){let e=s.get(t);return e||((e=new InputStyleCloneElement).connect(t),s.set(t,e)),e}connect(t){this.#s=new WeakRef(t),this.#o=document.createElement("div"),this.#o.style.position="absolute",this.#o.style.pointerEvents="none",t.after(this.#o),this.#o.appendChild(this)}forceUpdate(){this.#e(),this.#r()}connectedCallback(){this.#a(t=>{this.style.pointerEvents="none",this.style.userSelect="none",this.style.overflow="hidden",this.style.display="block",this.style.visibility="hidden",t instanceof HTMLTextAreaElement?(this.style.whiteSpace="pre-wrap",this.style.wordWrap="break-word"):(this.style.whiteSpace="nowrap",this.style.display="table-cell",this.style.verticalAlign="middle"),this.setAttribute("aria-hidden","true"),this.#e(),this.#r(),this.#t.observe(t,{attributeFilter:["style","dir"]}),this.#i.observe(t),document.addEventListener("scroll",this.#l,{capture:!0}),window.addEventListener("resize",this.#l,{capture:!0}),t.addEventListener("input",this.#h,{capture:!0})})}disconnectedCallback(){this.#o?.remove(),this.#t.disconnect(),this.#i.disconnect(),document.removeEventListener("scroll",this.#l,{capture:!0}),window.removeEventListener("resize",this.#l,{capture:!0});let t=this.#u;t&&(t.removeEventListener("input",this.#h,{capture:!0}),s.delete(t))}get #u(){return this.#s?.deref()}#a(t){let e=this.#u;return e?t(e):this.remove()}#d=0;#c=0;#p(){this.#a(t=>{let e=window.getComputedStyle(t);this.style.height=e.height,this.style.width=e.width,t.clientHeight!==this.clientHeight&&(this.style.height=`calc(${e.height} + ${t.clientHeight-this.clientHeight}px)`),t.clientWidth!==this.clientWidth&&(this.style.width=`calc(${e.width} + ${t.clientWidth-this.clientWidth}px)`);let i=t.getBoundingClientRect(),n=this.getBoundingClientRect();this.#d=this.#d+i.left-n.left,this.#c=this.#c+i.top-n.top,this.style.transform=`translate(${this.#d}px, ${this.#c}px)`,this.scrollTop=t.scrollTop,this.scrollLeft=t.scrollLeft,this.dispatchEvent(new InputStyleCloneUpdateEvent)})}#f=!1;#n(){this.#f||(this.#f=!0,requestAnimationFrame(()=>{this.#p(),this.#f=!1}))}#e(){this.#a(t=>{let e=window.getComputedStyle(t);for(let t of o)this.style[t]=e[t];this.#n()})}#r(){this.#a(t=>{this.textContent=t.value,this.#p()})}#h=()=>this.#r();#l=t=>{this.#a(e=>{(t.target===document||t.target===window||t.target instanceof Node&&t.target.contains(e))&&this.#n()})}};let o=["direction","writingMode","unicodeBidi","textOrientation","boxSizing","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStyle","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","tabSize","MozTabSize"];try{customElements.define("input-style-clone",InputStyleCloneElement)}catch(t){if(!(t instanceof DOMException&&"NotSupportedError"===t.name))throw t}let InputRange=class InputRange{#m;#v;#b;constructor(t,e=0,i=e){this.#m=t,this.#v=e,this.#b=i}static fromSelection(t){let{selectionStart:e,selectionEnd:i}=t;return new InputRange(t,e??void 0,i??void 0)}get collapsed(){return this.startOffset===this.endOffset}get commonAncestorContainer(){return this.#m}get endContainer(){return this.#m}get startContainer(){return this.#m}get startOffset(){return this.#v}get endOffset(){return this.#b}setStartOffset(t){this.#v=this.#g(t)}setEndOffset(t){this.#b=this.#g(t)}collapse(t=!1){t?this.setEndOffset(this.startOffset):this.setStartOffset(this.endOffset)}cloneContents(){return this.#x().cloneContents()}cloneRange(){return new InputRange(this.#m,this.startOffset,this.endOffset)}getBoundingClientRect(){return this.#x().getBoundingClientRect()}getClientRects(){return this.#x().getClientRects()}toString(){return this.#x().toString()}getStyleClone(){return this.#y}get #y(){return InputStyleCloneElement.for(this.#m)}get #E(){return this.#y}#g(t){return Math.max(0,Math.min(t,this.#m.value.length))}#x(){let t=document.createRange(),e=this.#E.childNodes[0];return e&&(t.setStart(e,this.startOffset),t.setEnd(e,this.endOffset)),t}};let r=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;(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))&&(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")),this.positionMenu(e,t.position),this.combobox.start(),e.addEventListener("combobox-commit",this.oncommit),e.addEventListener("mousedown",this.onmousedown),this.combobox.navigate(1))}positionMenu(t,e){let i=new InputRange(this.input,e).getBoundingClientRect(),n={left:i.left,top:i.top+i.height},s=t.getBoundingClientRect(),o={left:n.left-s.left,top:n.top-s.top};if(0!==o.left||0!==o.top){let e=getComputedStyle(t);t.style.left=e.left?`calc(${e.left} + ${o.left}px)`:`${o.left}px`,t.style.top=e.top?`calc(${e.top} + ${o.top}px)`:`${o.top}px`}}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};if(!this.expander.dispatchEvent(new CustomEvent("text-expander-value",{cancelable:!0,detail:o}))||!o.value)return;let r=null!==(e=this.expander.getAttribute("suffix"))&&void 0!==e?e:" ";o.continue&&(r="");let a=`${o.value}${r}`;this.input.value=n+a+s;let l=n.length+a.length;this.deactivate(),this.input.focus({preventScroll:!0}),this.input.selectionStart=l,this.input.selectionEnd=l,o.continue||(this.lookBackIndex=l,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||t.lastIndexOf("\n",i-1)>a||t.lastIndexOf(".",i-1)>a)return}else if(t.lastIndexOf(" ",i-1)>a)return;let l=t[a-1];if(!l||n.test(l))return{text:t.substring(a+e.length,i),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=[];if(this.expander.dispatchEvent(new CustomEvent("text-expander-change",{cancelable:!0,detail:{provide:t=>e.push(t),text:t.text,key:t.key}})))return(await Promise.all(e)).filter(t=>t.matched).map(t=>t.fragment)[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)}))}set keys(t){this.setAttribute("keys",t)}connectedCallback(){let t=this.querySelector('input[type="text"], textarea');if(!(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement))return;let e=new TextExpander(this,t);r.set(this,e)}disconnectedCallback(){let t=r.get(this);t&&(t.destroy(),r.delete(this))}dismiss(){let t=r.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-22f7acea4ffd.js.map