@magicx-eng/ai-autocomplete-vanilla 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -418,12 +418,14 @@ declare function buildQuery(text: string, completedParams: CompletedParamState[]
418
418
  declare class ModeController {
419
419
  private container;
420
420
  private mode;
421
+ private onResolve?;
421
422
  private mediaQuery;
422
- constructor(container: HTMLElement, mode?: AppearanceMode);
423
+ constructor(container: HTMLElement, mode?: AppearanceMode, onResolve?: ((resolved: "light" | "dark") => void) | undefined);
423
424
  setMode(mode: AppearanceMode): void;
424
425
  destroy(): void;
425
426
  private apply;
426
427
  private onSystemChange;
428
+ private setResolved;
427
429
  private detachListener;
428
430
  }
429
431
 
package/dist/index.d.ts CHANGED
@@ -418,12 +418,14 @@ declare function buildQuery(text: string, completedParams: CompletedParamState[]
418
418
  declare class ModeController {
419
419
  private container;
420
420
  private mode;
421
+ private onResolve?;
421
422
  private mediaQuery;
422
- constructor(container: HTMLElement, mode?: AppearanceMode);
423
+ constructor(container: HTMLElement, mode?: AppearanceMode, onResolve?: ((resolved: "light" | "dark") => void) | undefined);
423
424
  setMode(mode: AppearanceMode): void;
424
425
  destroy(): void;
425
426
  private apply;
426
427
  private onSystemChange;
428
+ private setResolved;
427
429
  private detachListener;
428
430
  }
429
431
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var ie=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var Be=(n,e)=>{for(var t in e)ie(n,t,{get:e[t],enumerable:!0})},Ke=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Fe(e))!He.call(n,r)&&r!==t&&ie(n,r,{get:()=>e[r],enumerable:!(i=Ne(e,r))||i.enumerable});return n};var Qe=n=>Ke(ie({},"__esModule",{value:!0}),n);var gt={};Be(gt,{AIAutocomplete:()=>ne,ModeController:()=>D,buildQuery:()=>v,createStore:()=>Z,cursorIsAtEnd:()=>$,extractPlainText:()=>L,getCursorOffset:()=>T,plainTextLength:()=>Q,previousGraphemeBoundary:()=>U,renderEditableContent:()=>J,setCursorOffset:()=>P});module.exports=Qe(gt);var k=class{constructor(e){this.config=e;this.current=null;this.expiresAt=null;this.inFlightRefresh=null;e.accessToken&&(this.current=e.accessToken)}async getToken(e=!1){if(!e&&this.current&&!this.isExpired())return this.current;if(!e&&this.inFlightRefresh)return this.inFlightRefresh;this.inFlightRefresh=this.refresh();try{return await this.inFlightRefresh}finally{this.inFlightRefresh=null}}async refresh(){let e=await this.config.getAccessToken();return this.current=e.accessToken,this.expiresAt=e.expiresAt??null,this.current}isExpired(){return this.expiresAt==null?!1:Date.now()>=this.expiresAt-3e4}};var $e="https://api.ai-autocomplete.com",R=`${$e}/api/suggest`,ce=new WeakMap;function M(n){return n?.type==="accessToken"}function Ue(n){if(!(!n||M(n)))return n}function _(n){let e=ce.get(n.getAccessToken);return e||(e=new k(n),ce.set(n.getAccessToken,e)),e}function N(n){return{"Content-Type":"application/json",...n?.appIdentifier&&{"X-App-Identifier":n.appIdentifier},...n?.headers}}function F(n){let e=Ue(n),t=e?.apiKey;return t?(e?.authScheme??"Bearer")==="Basic"?`Basic ${btoa(t)}`:`Bearer ${t}`:null}var qe="0.2.0",pe=!1;function We(){return crypto.randomUUID()}function Ge(n,e){return{placeholder:n.placeholder,type:n.type,...e&&{text:n.text},kind:n.kind}}function je(n,e,t,i){let r=e.find(o=>o.type==="contact"&&o.metadata?.contact_account_count)?.metadata?.contact_account_count,s=typeof r=="number"?r:void 0;return{data:{raw_query:n,completed_params:e.map(o=>Ge(o,t)),...s!=null&&{contact_account_count:s}},meta:{request_id:We(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:qe,session_id:i}}}async function ue(n,e,t,i,r){return fetch(n,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:i,signal:r})}async function me(n,e,t){let i=t.apiConfig,r=!t.maskCompletedText,s=je(n,e,r,t.sessionId),o=N(i),a=i?.endpoint??R,l=JSON.stringify(s);if(M(i)){let c=_(i),m=await c.getToken(),b=await ue(a,o,m,l,t.signal);if(b.status===401){let g=await c.getToken(!0);b=await ue(a,o,g,l,t.signal)}if(!b.ok)throw new Error(`API error: ${b.status} ${b.statusText}`);return b.json()}let d=F(i);!d&&!pe&&(pe=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),d&&(o.Authorization=d);let p=await fetch(a,{method:"POST",headers:o,body:l,signal:t.signal});if(!p.ok)throw new Error(`API error: ${p.status} ${p.statusText}`);return p.json()}function v(n,e){let t=n,i={},r=[];for(let s of e){let o=(i[s.type]??0)+1;i[s.type]=o;let l=`{{${s.type.toUpperCase().replace(/\s+/g,"_")}_${o}}}`,d=t.indexOf(s.text);d!==-1&&(t=t.slice(0,d)+l+t.slice(d+s.text.length)),r.push({...s,placeholder:l})}return{rawQuery:t,completedParams:r}}function A(n,e,t){return e>0||!t?e:n.toLowerCase().startsWith(t.toLowerCase())?t.length:e}function w(n,e,t){let i=n.slice(e);if(t||e===0||n[e-1]===" ")return i;let r=i.indexOf(" ");return r===-1?"":i.slice(r+1)}function ge(n,e){let t=n.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let i=t.split(" "),r=e.toLowerCase();for(let s=0;s<i.length;s++){let o=i.slice(s).join(" ");if(r.startsWith(o.toLowerCase())){let a=t.length-o.length;return n.length-a}}return 0}function E(n,e){if(!n)return[];let t=e.trimStart();if(!t)return n;let i=t.toLowerCase();return n.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(i))}function I(n,e){if(!n)return null;let t=e.trim();if(!t)return null;let i=t.toLowerCase();return n.find(r=>r.is_tappable&&r.text.toLowerCase()===i)??null}function fe(n,e){return e?n.map(t=>{let i=e[t.type];if(!i)return t;let r=i("");if(r.length===0)return t;let s=new Set(r.map(a=>a.text)),o=(t.options??[]).filter(a=>!s.has(a.text));return{...t,options:[...r,...o]}}):n}var Ve=100,ze=300,Xe=2,H=class{constructor(e,t,i,r,s,o,a={}){this.store=e;this.getApiConfig=t;this.getOptionOverrides=i;this.getMaskCompletedText=r;this.getOnError=s;this.getSessionId=o;this.callbacks=a;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,t=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(i=>{(i.text!==e||i.completedParams!==t)&&(e=i.text,t=i.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let i=new AbortController;this.abortController=i;let r=++this.fetchVersion,s=this.store.get().text.length;this.store.set({isLoading:!0,error:null});try{let o=await me(e,t,{sessionId:this.getSessionId(),maskCompletedText:this.getMaskCompletedText(),signal:i.signal,apiConfig:this.getApiConfig()});if(r!==this.fetchVersion)return;let a=fe(o.data.suggestions??[],this.getOptionOverrides()),l=o.data.input??[],d=l[l.length-1],p=this.store.get().text,c,m;if(d?.state==="in_progress"){m=!0;let f=p.toLowerCase().lastIndexOf(d.text.toLowerCase());c=f!==-1?f:s}else m=!1,c=s;let g=a.filter(f=>f.type!=="placeholder")[0],h=null;if(g){let f=w(p,c,m),u=I(g.options,f);u&&(h={id:crypto.randomUUID(),placeholder:"",type:g.type,text:u.text,kind:u.kind,suggestionType:g.type,suggestionPlaceholder:g.text,options:g.options??[],metadata:u.metadata},a=a.filter(x=>x!==g),this.callbacks.onAutoMatch?.({active:g,matched:u,rawQuery:e}))}this.store.set(f=>({suggestions:a,isLoading:!1,isReady:o.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:c,filterInProgress:m,...h?{completedParams:[...f.completedParams,h]}:{}}))}catch(o){if(r===this.fetchVersion){let a=o instanceof Error?o:new Error(String(o));this.store.set({error:a,isLoading:!1}),this.getOnError()?.(a)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=i=>{let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let s=r.suggestions.filter(x=>x.type==="placeholder").map(x=>x.text).join(" "),o=A(r.text,r.filterBase,s),a=w(r.text,o,r.filterInProgress),d=r.suggestions.filter(x=>x.type!=="placeholder")[0],c=(d?E(d.options,a):[]).filter(x=>x.is_tappable),m=d?I(d.options,a)!==null:!1,b=a.trim().length>0;if(c.length>0&&!m&&b||r.completedParams.length===0&&r.text.length>0&&s.length>0&&s.toLowerCase().startsWith(r.text.toLowerCase()))return!1;let{rawQuery:g,completedParams:h}=v(r.text,r.completedParams),f=g.length<r.lastRawQuery.length,u=Math.abs(g.length-r.lastRawQuery.length);return f||u>=i?(this.doFetch(g,h),!0):!1};this.debounceTimer=setTimeout(()=>{t(Xe)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},Ve),this.slowDebounceTimer=setTimeout(()=>t(1),ze)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var xe='[contenteditable="false"]',O;function Ye(){if(O!==void 0)return O;let n=globalThis.Intl.Segmenter;if(!n)return O=null,null;try{O=new n(void 0,{granularity:"grapheme"})}catch{O=null}return O??null}function B(n,e){let t=n;for(;t&&t!==e;){if(t.nodeType===Node.ELEMENT_NODE&&t.matches(xe))return!0;t=t.parentNode}return!1}function K(n){return(n.ownerDocument??document).createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode(e){return B(e,n)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function L(n){let e=K(n),t="",i=e.nextNode();for(;i;)t+=i.data,i=e.nextNode();return t}function Q(n){let e=K(n),t=0,i=e.nextNode();for(;i;)t+=i.data.length,i=e.nextNode();return t}function T(n){let e=(n.ownerDocument??document).getSelection();if(!e||e.rangeCount===0)return null;let t=e.anchorNode,i=e.anchorOffset;if(!t||!n.contains(t))return null;if(t.nodeType===Node.ELEMENT_NODE){let r=t;if(B(r,n)&&r!==n)return null;let s=0;for(let o=0;o<i&&o<r.childNodes.length;o++)s+=be(r.childNodes[o],n);return s+he(r,n)}return t.nodeType!==Node.TEXT_NODE||B(t,n)?null:he(t,n)+i}function be(n,e){if(n.nodeType===Node.TEXT_NODE)return B(n,e)?0:n.data.length;if(n.nodeType!==Node.ELEMENT_NODE)return 0;let t=n;if(t.matches(xe))return 0;let i=0;for(let r of Array.from(t.childNodes))i+=be(r,e);return i}function he(n,e){let t=K(e),i=0,r=t.nextNode();for(;r;){if(r===n||n.nodeType===Node.ELEMENT_NODE&&n.contains(r))return i;i+=r.data.length,r=t.nextNode()}return i}function P(n,e){let t=n.ownerDocument??document,i=t.getSelection();if(!i)return;let r=Math.max(0,Math.min(e,Q(n))),s=K(n),o=0,a=null,l=0,d=s.nextNode(),p=null;for(;d;){let m=d.data.length;if(r<o+m){a=d,l=r-o;break}if(r===o+m){let b=s.nextNode();b?(a=b,l=0):(a=d,l=m);break}o+=m,p=d,d=s.nextNode()}let c=t.createRange();if(a){let m=a.parentElement?.closest('strong[data-seg="completed"]');m&&m!==n&&n.contains(m)?l===0?c.setStartBefore(m):l===a.data.length?c.setStartAfter(m):c.setStart(a,l):c.setStart(a,l)}else p?c.setStart(p,p.data.length):c.setStart(n,0);c.collapse(!0),i.removeAllRanges(),i.addRange(c)}function $(n){let e=T(n);return e==null?!1:e>=Q(n)}function U(n,e){if(e<=0)return 0;let t=Ye();if(!t)return e-1;let i=n.slice(0,e),r=0;for(let{index:s}of t.segment(i))s<e&&(r=s);return r}function re(n){return n instanceof HTMLTextAreaElement||n instanceof HTMLInputElement?n.selectionStart!=null&&n.selectionStart===n.value.length:n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?$(n):!1}function Je(n){return n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?T(n):null}var q=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{listboxId:i,getOnSubmit:r}=this.ctx,s=this.getEffectiveColumns(),o=r(),a=this.getTappableIndices(s);if((e.shiftKey||e.metaKey||e.ctrlKey||e.altKey)&&(e.key==="ArrowDown"||e.key==="ArrowUp"||e.key==="ArrowLeft"||e.key==="ArrowRight"))return;let l=this.ctx.getOptionsPosition()==="above";switch(e.key){case"ArrowDown":{let d=re(e.target),p=!!t.editingParam;if(!d&&!p&&t.activeDropdownIndex<0)break;if(t.activeDropdownIndex<0){if(l)break;if(e.preventDefault(),!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:a[0]??0});break}if(a.length===0)return;this.store.set({activeDropdownIndex:a[0]});break}if(e.preventDefault(),a.length===0)return;if(t.filteredOptions.length>0){let b=Math.floor((t.filteredOptions.length-1)/s);if(Math.floor(t.activeDropdownIndex/s)===b){this.store.set({activeDropdownIndex:-1});break}}let c=a.indexOf(t.activeDropdownIndex),m=c<a.length-1?c+1:0;this.store.set({activeDropdownIndex:a[m]});break}case"ArrowUp":{if(t.activeDropdownIndex<0){if(!l)break;let c=re(e.target),m=!!t.editingParam;if(!c&&!m)break;e.preventDefault();let b=this.firstTappableInBottomRow(s)??a[0]??0;if(!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:b});break}if(a.length===0)return;this.store.set({activeDropdownIndex:b});break}if(a.length===0)break;if(e.preventDefault(),t.activeDropdownIndex<s){this.store.set({activeDropdownIndex:-1});break}let d=a.indexOf(t.activeDropdownIndex),p=d>0?d-1:a.length-1;this.store.set({activeDropdownIndex:a[p]});break}case"ArrowRight":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%s<s-1){let c=t.activeDropdownIndex+1;c<t.filteredOptions.length&&t.filteredOptions[c]?.is_tappable&&this.store.set({activeDropdownIndex:c})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){e.preventDefault();let p=e.target.closest("[data-aia-input]")??e.target,c=t.editingTail;this.ctx.exitEditMode?.(),P(p,c);break}re(e.target)&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}case"ArrowLeft":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%s>0){let d=t.activeDropdownIndex-1;d>=0&&t.filteredOptions[d]?.is_tappable&&this.store.set({activeDropdownIndex:d})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingAnchor!=null){e.preventDefault();let d=e.target.closest("[data-aia-input]")??e.target,p=t.editingAnchor;this.ctx.exitEditMode?.(),P(d,p);break}break}case"Backspace":{if(t.editingParam||!this.ctx.removeParamAtCaret)break;let d=Je(e.target);if(d==null)break;this.ctx.removeParamAtCaret(d)&&e.preventDefault();break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,i);else if(o){let{rawQuery:d,completedParams:p}=v(t.text,t.completedParams);o({query:t.text.trim(),raw_query:d,completed_params:p}),this.ctx.afterSubmit?.()}break}case"Tab":{let d=!t.text&&!!t.placeholderText,p=t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable;if(d&&!p){e.preventDefault();let c=t.placeholderText;if(this.store.set(m=>({text:c,filterBase:c.length,suggestions:m.suggestions.filter(b=>b.type!=="placeholder")})),e.target instanceof HTMLElement){let m=e.target.closest("[data-aia-input]")??e.target;queueMicrotask(()=>P(m,c.length))}}else if(p)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,i);else if(t.isDropdownOpen){let c=t.filteredOptions.findIndex(m=>m.is_tappable);c>=0&&(e.preventDefault(),this.clickOrSelect(c,t.filteredOptions,i))}break}case"Escape":{if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){let d=e.target.closest("[data-aia-input]")??e.target,p=t.editingTail;this.ctx.exitEditMode?.(),P(d,p)}this.store.set({activeDropdownIndex:-1});break}}}firstTappableInBottomRow(e){let t=this.store.get();if(t.filteredOptions.length===0)return null;let r=Math.floor((t.filteredOptions.length-1)/e)*e;for(let s=r;s<t.filteredOptions.length;s++)if(t.filteredOptions[s]?.is_tappable)return s;return null}getTappableIndices(e){let i=this.store.get().filteredOptions.map((s,o)=>s.is_tappable?o:-1).filter(s=>s!==-1),r=Array.from({length:e},()=>[]);for(let s of i)r[s%e].push(s);return r.flat()}getEffectiveColumns(){let t=document.getElementById(`${this.ctx.listboxId}-option-0`)?.parentElement;if(!t)return this.ctx.columns;let i=getComputedStyle(t).gridTemplateColumns.split(" ").filter(Boolean).length;return i>0?i:this.ctx.columns}clickOrSelect(e,t,i){let r=document.getElementById(`${i}-option-${e}`);r?r.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),i=t.suggestions.filter(a=>a.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],s=i.filter((a,l)=>l!==e),o=t.suggestions.filter(a=>a.type==="placeholder");this.store.set({suggestions:[...o,r,...s],pillTapped:!0,activeDropdownIndex:-1})}};var W=class{constructor(e,t={}){this.store=e;this.callbacks=t}setActivePill(e){let t=this.store.get(),i=t.suggestions.filter(a=>a.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],s=i.filter((a,l)=>l!==e),o=t.suggestions.filter(a=>a.type==="placeholder");if(this.callbacks.onPillSelected){let{rawQuery:a}=v(t.text,t.completedParams);this.callbacks.onPillSelected({rawQuery:a,selectedPill:r.text,otherPills:s.map(l=>l.text)})}this.store.set({suggestions:[...o,r,...s],pillTapped:!0,activeDropdownIndex:-1})}removeLastParam(){this.store.get().completedParams.length!==0&&this.store.set(t=>({completedParams:t.completedParams.slice(0,-1),activeDropdownIndex:-1}))}};function ye(n,e){let t=[],i=0;for(let s of e){let o=n.indexOf(s.text,i);o!==-1&&(o>i&&t.push({type:"text",value:n.slice(i,o)}),t.push({type:"completed",value:s.text,param:s}),i=o+s.text.length)}let r=n.slice(i);return r&&t.push({type:"text",value:r}),t}function Se(n,e){let t=[],i=[],r=0;for(let s of e){let o=n.indexOf(s.text,r);o===-1?i.push(s):(t.push(s),r=o+s.text.length)}return{valid:t,invalid:i}}function ve(n,e){let t=e.dropdownTrigger??"auto",i=e.closeDropdownOnBlur??!0,r=n.filteredOptionsLength>0;if(n.inEditMode){let s=i?n.isFocused:!0;return r&&s}if(t==="auto"){let s=i?n.isFocused:!0,o=n.text.replace(/\s+$/,"").length,a=n.caretOffset==null||n.caretOffset>=o;return(r||n.isLoading)&&s&&a}return t==="manual"?(r||n.isLoading)&&n.pillTapped:!1}function Pe(n,e){let t=ye(n.text,n.completedParams),i=n.suggestions.filter(g=>g.type!=="placeholder"),r=i[0],s=r?e.optionOverrides?.[r.type]:void 0,o=n.suggestions.filter(g=>g.type==="placeholder").map(g=>g.text).join(" "),a=A(n.text,Math.min(n.filterBase,n.text.length),o),d=n.lastRawQuery!==""||a>0?w(n.text,a,n.filterInProgress):"",p=r?s?s(d.trim()):r.options??[]:[],c=n.editingParam!=null&&n.editingAnchor!=null,m;if(c&&n.editingParam&&n.editingAnchor!=null){let g=n.editingParam.id,h=n.completedParams.some(x=>x.id===g),f=n.caretOffset??n.editingAnchor,u=h?"":n.text.slice(n.editingAnchor,f);m=E(n.editingParam.options,u)}else m=E(p,d);e.showNonTappableOptions===!1&&(m=m.filter(g=>g.is_tappable));let b=ve({inEditMode:c,filteredOptionsLength:m.length,isFocused:n.isFocused,text:n.text,caretOffset:n.caretOffset,isLoading:n.isLoading,pillTapped:n.pillTapped},{dropdownTrigger:e.dropdownTrigger,closeDropdownOnBlur:e.closeDropdownOnBlur});return{segments:t,actionableSuggestions:i,filteredOptions:m,placeholderText:o,isDropdownOpen:b}}function G(n){return n.mode==="fresh"?Ze(n):et(n)}function Ze(n){let{text:e,completedParams:t,suggestions:i,filterBase:r,filterInProgress:s}=n,a=i.filter(S=>S.type!=="placeholder")[0];if(!a?.options)return null;let l=i.filter(S=>S.type==="placeholder").map(S=>S.text).join(" "),d=A(e,r,l),p=w(e,d,s),c=I(a.options,p);if(!c)return null;let m=c.text.toLowerCase(),b=e.toLowerCase().lastIndexOf(m),g=b>=0?b:Math.max(0,e.length-c.text.length),h=g+c.text.length,f=e.slice(g,h),x=h<e.length&&e[h]===" "?h+1:h,y={id:crypto.randomUUID(),placeholder:"",type:a.type,text:f,kind:c.kind,suggestionType:a.type,suggestionPlaceholder:a.text,options:a.options??[],metadata:c.metadata};return{patch:{text:e,completedParams:[...t,y],suggestions:i.filter(S=>S!==a),filterBase:x,newParamId:y.id,caretOffset:x,activeDropdownIndex:-1},caretPos:x}}function et(n){let{text:e,completedParams:t,editingParam:i,editingAnchor:r,editingTail:s}=n;if(t.some(y=>y.id===i.id))return null;let o=e.slice(r,s),a=I(i.options,o);if(!a)return null;let l=a.text.toLowerCase(),d=o.toLowerCase().lastIndexOf(l),p=r+Math.max(0,d),c=p+a.text.length,m=e.slice(p,c),g=c<e.length&&e[c]===" "?c+1:c,h={id:crypto.randomUUID(),placeholder:"",type:i.suggestionType,text:m,kind:a.kind,suggestionType:i.suggestionType,suggestionPlaceholder:i.suggestionPlaceholder,options:i.options,metadata:a.metadata},f=t.length,u=0;for(let y=0;y<t.length;y++){let S=e.indexOf(t[y].text,u);if(S!==-1){if(S>=g){f=y;break}u=S+t[y].text.length}}let x=[...t];return x.splice(f,0,h),{patch:{text:e,completedParams:x,newParamId:h.id,filterBase:g,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:g,activeDropdownIndex:-1},caretPos:g}}var j=class{constructor(e){this.deps=e}start(e){let t=this.deps.store.get();if(t.editingParam?.id===e)return;let i=t.completedParams.find(o=>o.id===e);if(!i)return;let r=0,s=-1;for(let o of t.completedParams){let a=t.text.indexOf(o.text,r);if(a!==-1){if(o.id===e){s=a;break}r=a+o.text.length}}s<0||this.deps.store.set({editingParam:i,editingAnchor:s,editingTail:s+i.text.length,caretOffset:s+i.text.length,activeDropdownIndex:-1})}exit(){this.deps.store.get().editingParam&&this.deps.store.set({editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1})}replaceRange(e){let t=this.deps.store.get(),i=t.editingParam,r=t.editingAnchor,s=t.editingTail;if(!i||r==null||s==null||!t.completedParams.some(l=>l.id===i.id))return!1;let o=t.text.slice(0,r)+e+t.text.slice(s),a=r+e.length;return this.deps.store.set(l=>({text:o,completedParams:l.completedParams.filter(d=>d.id!==i.id),editingTail:a,caretOffset:a,activeDropdownIndex:-1})),this.deps.scheduleSetCursor(a),this.tryPromote(),!0}caretAfterInput(e){let t=this.deps.store.get(),i={caretOffset:e};t.editingParam&&t.editingAnchor!=null&&e!=null&&(e<t.editingAnchor?(i.editingParam=null,i.editingAnchor=null,i.editingTail=null,i.activeDropdownIndex=-1):t.editingTail!=null&&(i.editingTail=Math.max(t.editingTail,e))),this.deps.store.set(i),this.tryPromote()}caretMove(e){let t=this.deps.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null&&e!=null&&(e<t.editingAnchor||e>t.editingTail)){this.deps.store.set({caretOffset:e,editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1});return}this.deps.store.set({caretOffset:e})}selectOption(e){let t=this.deps.store.get(),i=t.editingParam,r=t.editingAnchor,s=t.editingTail;if(!i||r==null||s==null)return;this.deps.fireTelemetry("option",{raw_query:v(t.text,t.completedParams).rawQuery,selected_option:e.text,other_options:i.options.filter(u=>u.text!==e.text).map(u=>u.text)});let o=t.text.slice(0,r),a=t.text.slice(s),l=r===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,d=a.length===0||a[0]!==" ",p=d?`${l} `:l,c=o+p+a,m=r+p.length+(d?0:1),b={id:crypto.randomUUID(),placeholder:"",type:i.suggestionType,text:l,kind:e.kind,suggestionType:i.suggestionType,suggestionPlaceholder:i.suggestionPlaceholder,options:i.options,metadata:e.metadata},g=t.completedParams.findIndex(u=>u.id===i.id),h=t.completedParams.filter(u=>u.id!==i.id),f=g>=0?Math.min(g,h.length):h.length;h.splice(f,0,b),this.deps.store.set({text:c,completedParams:h,newParamId:b.id,filterBase:m,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:m,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0}),this.deps.startSelectionAnimationTimer(),this.deps.scheduleSetCursor(m)}tryPromote(){let e=this.deps.store.get();if(!e.editingParam||e.editingAnchor==null||e.editingTail==null)return;let t=G({mode:"edit",text:e.text,completedParams:e.completedParams,editingParam:e.editingParam,editingAnchor:e.editingAnchor,editingTail:e.editingTail});t&&(this.deps.store.set(t.patch),this.deps.scheduleSetCursor(t.caretPos))}};var Te="data-aia-key";function V(n,e,t){let i=new Map;for(let o of Array.from(n.children)){let a=o.getAttribute(Te);a!=null&&i.set(a,o)}let r=new Set,s=[];for(let o=0;o<e.length;o++){let a=e[o],l=t.keyOf(a,o);r.add(l);let d=i.get(l);d||(d=t.create(a,o),d.setAttribute(Te,l)),t.update?.(d,a,o),n.children[o]!==d&&n.insertBefore(d,n.children[o]??null),s.push(d)}for(let[o,a]of i)r.has(o)||a.remove();return s}var Ce=[125,69];function we(n){return n===0?.4:n===1?.3:.15}function z(n,e,t,i,r=!1,s=!1){let o=n.querySelector(".magicx-aia-pill-list");if(o||(o=document.createElement("span"),o.className="magicx-aia-pill-list",n.appendChild(o)),s&&e.length===0){o.setAttribute("data-aia-pill-list-loading",""),o.innerHTML="";for(let a=0;a<Ce.length;a++){let l=Ce[a],d=document.createElement("span");d.setAttribute("data-aia-pill-skeleton",""),d.className=`magicx-aia-pill magicx-aia-pill--skeleton${r?" magicx-aia-pill--rounded":""}`,d.style.width=`${l}px`,d.style.opacity=String(we(a)),o.appendChild(d)}return}s?o.setAttribute("data-aia-pill-list-loading",""):o.removeAttribute("data-aia-pill-list-loading");for(let a of o.querySelectorAll("[data-aia-pill-skeleton]"))a.remove();V(o,e,{keyOf:a=>`${a.type}-${a.text}`,create:a=>{let l=document.createElement("button");return l.type="button",l.tabIndex=-1,l.setAttribute("data-aia-pill",""),l.setAttribute("contenteditable","false"),l.textContent=a.text,l.addEventListener("mousedown",d=>d.preventDefault()),l},update:(a,l,d)=>{let p=a,c=["magicx-aia-pill"];r&&c.push("magicx-aia-pill--rounded"),d===t&&!s&&c.push("magicx-aia-pill--active"),s&&c.push("magicx-aia-pill--skeleton"),p.className=c.join(" "),p.style.width="",p.style.opacity=String(we(d)),s?(p.setAttribute("data-aia-loading",""),p.disabled=!0,p.onclick=null):(p.removeAttribute("data-aia-loading"),p.disabled=!1,p.onclick=()=>i(d))}})}function oe(n){n.querySelector(".magicx-aia-pill-list")?.remove()}var tt=[159,119,164];function X(n){let e=document.createElement("div");return e.id=n,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function Y(n,e){let{filteredOptions:t,activeIndex:i,isOpen:r,isLoading:s,pills:o,showPills:a,onSelect:l,onHighlight:d,onPillClick:p}=e,c=a&&o.length>0,m=t.length>0;r&&(m||c||s)?n.classList.add("magicx-aia-dropdown--visible"):n.classList.remove("magicx-aia-dropdown--visible"),s?n.setAttribute("data-aia-loading",""):n.removeAttribute("data-aia-loading");let g=c||s&&a,h=n.querySelector(".magicx-aia-pill-bar");g?(h||(h=document.createElement("div"),h.className="magicx-aia-pill-bar",h.setAttribute("data-aia-pillbar",""),n.insertBefore(h,n.firstChild)),z(h,o,0,p,!0,s)):h&&h.remove();let f=n.querySelector(".magicx-aia-grid");m?(f||(f=document.createElement("div"),f.className="magicx-aia-grid",n.appendChild(f)),nt(f,t,i,l,d,e.listboxId,s)):f&&f.remove();let u=n.querySelector(".magicx-aia-skeleton-bars");if(s&&!m){if(!u){u=document.createElement("div"),u.className="magicx-aia-skeleton-bars",u.setAttribute("data-aia-skeleton-bars","");for(let x of tt){let y=document.createElement("span");y.className="magicx-aia-skeleton-bar",y.style.width=`${x}px`,u.appendChild(y)}n.appendChild(u)}}else u&&u.remove()}function nt(n,e,t,i,r,s,o){let a=o?"1":"0";V(n,e,{keyOf:l=>`${l.text}\0${a}`,create:l=>it(l,o),update:(l,d,p)=>{let c=p===t&&!o;l.id=`${s}-option-${p}`,l.dataset.aiaIndex=String(p),l.setAttribute("aria-selected",String(c)),l.classList.toggle("magicx-aia-option--highlighted",c),!o&&d.is_tappable?(l.onclick=()=>{l.classList.add("magicx-aia-option--pressed"),i(d),setTimeout(()=>l.classList.remove("magicx-aia-option--pressed"),500)},l.onmouseenter=()=>{let m=Number.parseInt(l.dataset.aiaIndex??"-1",10);m>=0&&r(m)}):(l.onclick=null,l.onmouseenter=null)}})}function it(n,e){let t=document.createElement("div");t.setAttribute("role","option"),t.setAttribute("data-aia-option",""),e&&t.setAttribute("data-aia-loading",""),t.tabIndex=e||!n.is_tappable?-1:0;let i=["magicx-aia-option"];n.is_tappable?i.push("magicx-aia-option--tappable"):i.push("magicx-aia-option--non-tappable"),t.className=i.join(" ");let r=document.createElement("div");r.className="magicx-aia-streaks",t.appendChild(r);let s=document.createElement("div");s.className="magicx-aia-streaks-vert",t.appendChild(s);let o=document.createElement("span");o.className="magicx-aia-option-content";let a=document.createElement("span");if(a.className="magicx-aia-option-text",a.textContent=n.icon?`${n.icon} ${n.text}`:n.text,o.appendChild(a),n.tag){let l=document.createElement("span");l.className="magicx-aia-option-tag",l.textContent=n.tag,o.appendChild(l)}return t.appendChild(o),t}function Ee(n,e){let t=X(e.listboxId);return n.appendChild(t),{dropdown:t}}function se(n,e,t){Y(n.dropdown,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:!0,onSelect:t.selectOption,onHighlight:i=>t.store.set({activeDropdownIndex:i}),onPillClick:t.setActivePill})}function J(n){let{input:e,segments:t,newParamId:i,editingParamId:r,placeholderText:s,isFocused:o}=n,a=t.length===0;e.dataset.aiaEmpty=a?"true":"false",a&&s?e.dataset.placeholder=s:delete e.dataset.placeholder;let l=t.map(f=>`${f.type}:${f.value}`).join("\0"),d=e.dataset.segKey??"",p=e.dataset.newParamId??"",c=e.dataset.editingParamId??"";if(l===d&&(i??"")===p&&(r??"")===c)return;let m=o?T(e):null;e.dataset.segKey=l,e.dataset.newParamId=i??"",e.dataset.editingParamId=r??"";let b=e.ownerDocument??document,g=b.createDocumentFragment(),h=0;for(let f of t)if(h+=f.value.length,f.type==="completed"){let u=b.createElement("strong");u.dataset.seg="completed",u.dataset.paramId=f.param.id;let x=f.param.id===i,y=f.param.id===r,S=["magicx-aia-segment","magicx-aia-segment--completed"];x&&S.push("magicx-aia-shimmer-revealed","magicx-aia-shimmer-sweep"),y&&S.push("magicx-aia-segment--editing"),u.className=S.join(" "),u.textContent=f.value,g.appendChild(u)}else g.appendChild(b.createTextNode(f.value));e.replaceChildren(g),e.dataset.aiaTextLength=String(h),m!=null&&P(e,Math.max(0,Math.min(m,h)))}var rt='<svg width="18" height="18" viewBox="0 0 18 18" fill="none" role="img" aria-label="Submit"><path d="M9 14V4M9 4L4 9M9 4L14 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function ot(){let n=document.createElement("div");return n.setAttribute("contenteditable","plaintext-only"),n.contentEditable==="plaintext-only"}function Ae(n,e){let t=e.firstElementChild;if(!t){e.removeAttribute("data-aia-pill-wrapped");return}if(n.dataset.aiaEmpty==="true"){e.setAttribute("data-aia-pill-wrapped","");return}let i=t.getBoundingClientRect(),r=n.getBoundingClientRect();i.top>=r.bottom-2?e.setAttribute("data-aia-pill-wrapped",""):e.removeAttribute("data-aia-pill-wrapped")}function Ie(n,e){let{listboxId:t}=e,i=X(t);n.appendChild(i);let r=document.createElement("div");r.className="magicx-aia-input-wrapper",n.appendChild(r);let s=document.createElement("div");s.className="magicx-aia-editor",s.setAttribute("data-aia-editor",""),r.appendChild(s);let o=document.createElement("div");o.className="magicx-aia-input",o.setAttribute("data-aia-input",""),o.setAttribute("contenteditable",ot()?"plaintext-only":"true"),o.setAttribute("role","combobox"),o.setAttribute("aria-autocomplete","list"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-controls",t),o.setAttribute("aria-expanded","false"),o.setAttribute("spellcheck","true"),o.setAttribute("enterkeyhint","send"),s.appendChild(o);let a=document.createElement("span");a.className="magicx-aia-pill-list-container",a.setAttribute("data-aia-pill-list-container",""),s.appendChild(a);let l=null,d=null;e.submitButton===void 0?(l=document.createElement("button"),l.type="button",l.className="magicx-aia-submit",l.setAttribute("aria-label","Submit"),l.setAttribute("data-aia-submit",""),l.innerHTML=rt,r.appendChild(l),d=l):e.submitButton!==null&&(d=e.submitButton,d.hasAttribute("data-aia-submit")||d.setAttribute("data-aia-submit",""),r.appendChild(d));let p=new AbortController,{signal:c}=p,m=!1,b=0,g=()=>{let u=L(o),y=u.length>0&&u[0]!==u[0].toUpperCase()?u[0].toUpperCase()+u.slice(1):u;e.handleChange(y)},h=()=>{let u=(o.ownerDocument??document).getSelection();if(!u||u.rangeCount===0)return null;let x=u.anchorNode;return!x||!o.contains(x)?null:(x.nodeType===Node.ELEMENT_NODE?x:x.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null};r.addEventListener("click",u=>{u.target?.closest("[data-aia-pill]")||o.focus()},{signal:c}),o.addEventListener("input",()=>{m||(b=performance.now(),g(),e.handleCaretAfterInput(T(o)))},{signal:c});let f=o.ownerDocument??document;if(f.addEventListener("selectionchange",()=>{let u=f.getSelection();if(!u||u.rangeCount===0||!o.contains(u.anchorNode))return;let x=h(),y=e.store.get().editingParam?.id??null;if(x&&x!==y){e.startEditingParam(x);return}performance.now()-b<50||e.handleCaretMove(T(o))},{signal:c}),o.addEventListener("compositionstart",()=>{m=!0},{signal:c}),o.addEventListener("compositionend",()=>{m=!1,g()},{signal:c}),o.addEventListener("beforeinput",u=>{let x=u,y=x.inputType;if(y==="insertParagraph"||y==="insertLineBreak"||y==="insertFromDrop"){u.preventDefault();return}if(y.startsWith("insert")||y.startsWith("delete")){let S=y.startsWith("delete")?"":x.data??"";e.replaceEditingRange(S)&&u.preventDefault()}},{signal:c}),o.addEventListener("paste",u=>{u.preventDefault();let x=(u.clipboardData?.getData("text/plain")??"").replace(/\r?\n/g," ");if(!x)return;let y=o.ownerDocument??document,S=y.getSelection();if(!S||S.rangeCount===0)return;let C=S.getRangeAt(0);if(!o.contains(C.startContainer))return;C.deleteContents();let de=y.createTextNode(x);C.insertNode(de),C.setStartAfter(de),C.collapse(!0),S.removeAllRanges(),S.addRange(C),g()},{signal:c}),o.addEventListener("keydown",u=>e.handleKeyDown(u),{signal:c}),o.addEventListener("focus",()=>e.store.set({isFocused:!0}),{signal:c}),o.addEventListener("blur",()=>e.store.set({isFocused:!1}),{signal:c}),d&&d.addEventListener("click",u=>{let x=e.store.get();if(!(!!x.text||x.completedParams.length>0)||!e.onSubmit)return;u.stopPropagation();let{rawQuery:S,completedParams:C}=v(x.text,x.completedParams);e.onSubmit({query:x.text.trim(),raw_query:S,completed_params:C}),e.afterSubmit?.()},{signal:c}),e.autoFocus!==!1&&o.focus(),typeof ResizeObserver<"u"){let u=new ResizeObserver(()=>Ae(o,a));u.observe(o),p.signal.addEventListener("abort",()=>u.disconnect(),{once:!0})}return{input:o,inlinePillContainer:a,dropdown:i,submitButton:l,abort:p}}function ae(n,e,t){let{input:i,inlinePillContainer:r,dropdown:s,submitButton:o}=n,{pillPlacement:a,setActivePill:l,selectOption:d,store:p}=t;i.setAttribute("aria-expanded",String(e.isDropdownOpen));let c=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";if(c?i.setAttribute("aria-activedescendant",c):i.removeAttribute("aria-activedescendant"),o){let f=!!e.text||e.completedParams.length>0;o.disabled=!f}let m=i.dataset.newParamId??"",b=e.newParamId!==null&&e.newParamId!==m;if(J({input:i,segments:e.segments,newParamId:e.newParamId,editingParamId:e.editingParam?.id??null,placeholderText:e.placeholderText,isFocused:e.isFocused}),a==="inline"){let f=e.isLoading&&!e.editingParam&&!e.inSelectionAnimation;f||e.actionableSuggestions.length>0?z(r,e.actionableSuggestions,0,l,!1,f):oe(r)}else oe(r);Ae(i,r),b?(i.focus(),P(i,e.caretOffset??e.text.length)):e.isFocused&&L(i)!==e.text&&P(i,e.text.length);let g=e.editingParam?{type:e.editingParam.suggestionType,text:e.editingParam.suggestionPlaceholder,required:!0,options:e.editingParam.options}:null,h=g??e.actionableSuggestions[0];Y(s,{suggestions:h?[{...h,options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:g?[g]:e.actionableSuggestions,showPills:a==="dropdown",onSelect:d,onHighlight:f=>p.set({activeDropdownIndex:f}),onPillClick:l})}function Oe(n,e){let t=n.actionableSuggestions[0];if(!t)return null;let i=n.filterBase,r=n.text.slice(0,i),s=r.length===0&&n.text.length===0,o=r.length===0&&n.text.length>0&&n.placeholderText.length>0&&n.placeholderText.toLowerCase().startsWith(n.text.toLowerCase());(s||o)&&n.placeholderText&&(r=`${n.placeholderText} `);let a=ge(r,e.text);a>0&&(r=r.slice(0,r.length-a));let l=r.length>0&&r[r.length-1]!==" ",d=`${r}${l?" ":""}${e.text} `,p=(s||o)&&d.length>0?d[0].toUpperCase()+d.slice(1):d,c=p.toLowerCase().lastIndexOf(e.text.toLowerCase()),m=c>=0?p.slice(c,c+e.text.length):e.text,b={id:crypto.randomUUID(),placeholder:"",type:t.type,text:m,kind:e.kind,suggestionType:t.type,suggestionPlaceholder:t.text,options:t.options??[],metadata:e.metadata},g=n.actionableSuggestions.length-1;return{patch:{text:p,filterBase:p.length,completedParams:[...n.completedParams,b],newParamId:b.id,caretOffset:p.length,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:g>0,inSelectionAnimation:!0},telemetry:{selectedOption:e.text,otherOptions:n.filteredOptions.filter(h=>h.text!==e.text).map(h=>h.text)},consumedSuggestion:t,remainingActionable:g}}function Z(n){let e=n,t=new Set;return{get:()=>e,set:i=>{let r=typeof i=="function"?i(e):i,s={...e,...r},o=e;e=s;for(let a of t)a(s,o)},subscribe:i=>(t.add(i),()=>{t.delete(i)})}}function De(n,e){let t,i,r=s=>(s!==t&&(t=s,i=e(s)),i);return{get:()=>{let s=n.get();return{...s,...r(s)}},set:s=>{typeof s=="function"?n.set(o=>{let a={...o,...r(o)};return s(a)}):n.set(s)},subscribe:s=>n.subscribe((o,a)=>{let l={...a,...r(a)},d={...o,...r(o)};s(d,l)})}}var le=!1;function Me(){if(le||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){le=!0;return}le=!0;let n=document.createElement("style");n.setAttribute("data-magicx-aia",""),n.textContent=st,document.head.appendChild(n)}var st=`@layer layout {
1
+ "use strict";var ie=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var Be=(n,e)=>{for(var t in e)ie(n,t,{get:e[t],enumerable:!0})},Ke=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Fe(e))!He.call(n,r)&&r!==t&&ie(n,r,{get:()=>e[r],enumerable:!(i=Ne(e,r))||i.enumerable});return n};var Qe=n=>Ke(ie({},"__esModule",{value:!0}),n);var gt={};Be(gt,{AIAutocomplete:()=>ne,ModeController:()=>D,buildQuery:()=>S,createStore:()=>Z,cursorIsAtEnd:()=>$,extractPlainText:()=>L,getCursorOffset:()=>T,plainTextLength:()=>Q,previousGraphemeBoundary:()=>U,renderEditableContent:()=>J,setCursorOffset:()=>P});module.exports=Qe(gt);var k=class{constructor(e){this.config=e;this.current=null;this.expiresAt=null;this.inFlightRefresh=null;e.accessToken&&(this.current=e.accessToken)}async getToken(e=!1){if(!e&&this.current&&!this.isExpired())return this.current;if(!e&&this.inFlightRefresh)return this.inFlightRefresh;this.inFlightRefresh=this.refresh();try{return await this.inFlightRefresh}finally{this.inFlightRefresh=null}}async refresh(){let e=await this.config.getAccessToken();return this.current=e.accessToken,this.expiresAt=e.expiresAt??null,this.current}isExpired(){return this.expiresAt==null?!1:Date.now()>=this.expiresAt-3e4}};var $e="https://api.ai-autocomplete.com",R=`${$e}/api/suggest`,ce=new WeakMap;function M(n){return n?.type==="accessToken"}function Ue(n){if(!(!n||M(n)))return n}function _(n){let e=ce.get(n.getAccessToken);return e||(e=new k(n),ce.set(n.getAccessToken,e)),e}function N(n){return{"Content-Type":"application/json",...n?.appIdentifier&&{"X-App-Identifier":n.appIdentifier},...n?.headers}}function F(n){let e=Ue(n),t=e?.apiKey;return t?(e?.authScheme??"Bearer")==="Basic"?`Basic ${btoa(t)}`:`Bearer ${t}`:null}var qe="0.2.1",pe=!1;function We(){return crypto.randomUUID()}function Ge(n,e){return{placeholder:n.placeholder,type:n.type,...e&&{text:n.text},kind:n.kind}}function je(n,e,t,i){let r=e.find(o=>o.type==="contact"&&o.metadata?.contact_account_count)?.metadata?.contact_account_count,s=typeof r=="number"?r:void 0;return{data:{raw_query:n,completed_params:e.map(o=>Ge(o,t)),...s!=null&&{contact_account_count:s}},meta:{request_id:We(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:qe,session_id:i}}}async function ue(n,e,t,i,r){return fetch(n,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:i,signal:r})}async function me(n,e,t){let i=t.apiConfig,r=!t.maskCompletedText,s=je(n,e,r,t.sessionId),o=N(i),a=i?.endpoint??R,l=JSON.stringify(s);if(M(i)){let c=_(i),m=await c.getToken(),b=await ue(a,o,m,l,t.signal);if(b.status===401){let g=await c.getToken(!0);b=await ue(a,o,g,l,t.signal)}if(!b.ok)throw new Error(`API error: ${b.status} ${b.statusText}`);return b.json()}let d=F(i);!d&&!pe&&(pe=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),d&&(o.Authorization=d);let p=await fetch(a,{method:"POST",headers:o,body:l,signal:t.signal});if(!p.ok)throw new Error(`API error: ${p.status} ${p.statusText}`);return p.json()}function S(n,e){let t=n,i={},r=[];for(let s of e){let o=(i[s.type]??0)+1;i[s.type]=o;let l=`{{${s.type.toUpperCase().replace(/\s+/g,"_")}_${o}}}`,d=t.indexOf(s.text);d!==-1&&(t=t.slice(0,d)+l+t.slice(d+s.text.length)),r.push({...s,placeholder:l})}return{rawQuery:t,completedParams:r}}function I(n,e,t){return e>0||!t?e:n.toLowerCase().startsWith(t.toLowerCase())?t.length:e}function w(n,e,t){let i=n.slice(e);if(t||e===0||n[e-1]===" ")return i;let r=i.indexOf(" ");return r===-1?"":i.slice(r+1)}function ge(n,e){let t=n.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let i=t.split(" "),r=e.toLowerCase();for(let s=0;s<i.length;s++){let o=i.slice(s).join(" ");if(r.startsWith(o.toLowerCase())){let a=t.length-o.length;return n.length-a}}return 0}function E(n,e){if(!n)return[];let t=e.trimStart();if(!t)return n;let i=t.toLowerCase();return n.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(i))}function A(n,e){if(!n)return null;let t=e.trim();if(!t)return null;let i=t.toLowerCase();return n.find(r=>r.is_tappable&&r.text.toLowerCase()===i)??null}function fe(n,e){return e?n.map(t=>{let i=e[t.type];if(!i)return t;let r=i("");if(r.length===0)return t;let s=new Set(r.map(a=>a.text)),o=(t.options??[]).filter(a=>!s.has(a.text));return{...t,options:[...r,...o]}}):n}var Ve=100,ze=300,Xe=2,H=class{constructor(e,t,i,r,s,o,a={}){this.store=e;this.getApiConfig=t;this.getOptionOverrides=i;this.getMaskCompletedText=r;this.getOnError=s;this.getSessionId=o;this.callbacks=a;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,t=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(i=>{(i.text!==e||i.completedParams!==t)&&(e=i.text,t=i.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let i=new AbortController;this.abortController=i;let r=++this.fetchVersion,s=this.store.get().text.length;this.store.set({isLoading:!0,error:null});try{let o=await me(e,t,{sessionId:this.getSessionId(),maskCompletedText:this.getMaskCompletedText(),signal:i.signal,apiConfig:this.getApiConfig()});if(r!==this.fetchVersion)return;let a=fe(o.data.suggestions??[],this.getOptionOverrides()),l=o.data.input??[],d=l[l.length-1],p=this.store.get().text,c,m;if(d?.state==="in_progress"){m=!0;let f=p.toLowerCase().lastIndexOf(d.text.toLowerCase());c=f!==-1?f:s}else m=!1,c=s;let g=a.filter(f=>f.type!=="placeholder")[0],h=null;if(g){let f=w(p,c,m),u=A(g.options,f);u&&(h={id:crypto.randomUUID(),placeholder:"",type:g.type,text:u.text,kind:u.kind,suggestionType:g.type,suggestionPlaceholder:g.text,options:g.options??[],metadata:u.metadata},a=a.filter(x=>x!==g),this.callbacks.onAutoMatch?.({active:g,matched:u,rawQuery:e}))}this.store.set(f=>({suggestions:a,isLoading:!1,isReady:o.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:c,filterInProgress:m,...h?{completedParams:[...f.completedParams,h]}:{}}))}catch(o){if(r===this.fetchVersion){let a=o instanceof Error?o:new Error(String(o));this.store.set({error:a,isLoading:!1}),this.getOnError()?.(a)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=i=>{let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let s=r.suggestions.filter(x=>x.type==="placeholder").map(x=>x.text).join(" "),o=I(r.text,r.filterBase,s),a=w(r.text,o,r.filterInProgress),d=r.suggestions.filter(x=>x.type!=="placeholder")[0],c=(d?E(d.options,a):[]).filter(x=>x.is_tappable),m=d?A(d.options,a)!==null:!1,b=a.trim().length>0;if(c.length>0&&!m&&b||r.completedParams.length===0&&r.text.length>0&&s.length>0&&s.toLowerCase().startsWith(r.text.toLowerCase()))return!1;let{rawQuery:g,completedParams:h}=S(r.text,r.completedParams),f=g.length<r.lastRawQuery.length,u=Math.abs(g.length-r.lastRawQuery.length);return f||u>=i?(this.doFetch(g,h),!0):!1};this.debounceTimer=setTimeout(()=>{t(Xe)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},Ve),this.slowDebounceTimer=setTimeout(()=>t(1),ze)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var xe='[contenteditable="false"]',O;function Ye(){if(O!==void 0)return O;let n=globalThis.Intl.Segmenter;if(!n)return O=null,null;try{O=new n(void 0,{granularity:"grapheme"})}catch{O=null}return O??null}function B(n,e){let t=n;for(;t&&t!==e;){if(t.nodeType===Node.ELEMENT_NODE&&t.matches(xe))return!0;t=t.parentNode}return!1}function K(n){return(n.ownerDocument??document).createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode(e){return B(e,n)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function L(n){let e=K(n),t="",i=e.nextNode();for(;i;)t+=i.data,i=e.nextNode();return t}function Q(n){let e=K(n),t=0,i=e.nextNode();for(;i;)t+=i.data.length,i=e.nextNode();return t}function T(n){let e=(n.ownerDocument??document).getSelection();if(!e||e.rangeCount===0)return null;let t=e.anchorNode,i=e.anchorOffset;if(!t||!n.contains(t))return null;if(t.nodeType===Node.ELEMENT_NODE){let r=t;if(B(r,n)&&r!==n)return null;let s=0;for(let o=0;o<i&&o<r.childNodes.length;o++)s+=be(r.childNodes[o],n);return s+he(r,n)}return t.nodeType!==Node.TEXT_NODE||B(t,n)?null:he(t,n)+i}function be(n,e){if(n.nodeType===Node.TEXT_NODE)return B(n,e)?0:n.data.length;if(n.nodeType!==Node.ELEMENT_NODE)return 0;let t=n;if(t.matches(xe))return 0;let i=0;for(let r of Array.from(t.childNodes))i+=be(r,e);return i}function he(n,e){let t=K(e),i=0,r=t.nextNode();for(;r;){if(r===n||n.nodeType===Node.ELEMENT_NODE&&n.contains(r))return i;i+=r.data.length,r=t.nextNode()}return i}function P(n,e){let t=n.ownerDocument??document,i=t.getSelection();if(!i)return;let r=Math.max(0,Math.min(e,Q(n))),s=K(n),o=0,a=null,l=0,d=s.nextNode(),p=null;for(;d;){let m=d.data.length;if(r<o+m){a=d,l=r-o;break}if(r===o+m){let b=s.nextNode();b?(a=b,l=0):(a=d,l=m);break}o+=m,p=d,d=s.nextNode()}let c=t.createRange();if(a){let m=a.parentElement?.closest('strong[data-seg="completed"]');m&&m!==n&&n.contains(m)?l===0?c.setStartBefore(m):l===a.data.length?c.setStartAfter(m):c.setStart(a,l):c.setStart(a,l)}else p?c.setStart(p,p.data.length):c.setStart(n,0);c.collapse(!0),i.removeAllRanges(),i.addRange(c)}function $(n){let e=T(n);return e==null?!1:e>=Q(n)}function U(n,e){if(e<=0)return 0;let t=Ye();if(!t)return e-1;let i=n.slice(0,e),r=0;for(let{index:s}of t.segment(i))s<e&&(r=s);return r}function re(n){return n instanceof HTMLTextAreaElement||n instanceof HTMLInputElement?n.selectionStart!=null&&n.selectionStart===n.value.length:n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?$(n):!1}function Je(n){return n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?T(n):null}var q=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{listboxId:i,getOnSubmit:r}=this.ctx,s=this.getEffectiveColumns(),o=r(),a=this.getTappableIndices(s);if((e.shiftKey||e.metaKey||e.ctrlKey||e.altKey)&&(e.key==="ArrowDown"||e.key==="ArrowUp"||e.key==="ArrowLeft"||e.key==="ArrowRight"))return;let l=this.ctx.getOptionsPosition()==="above";switch(e.key){case"ArrowDown":{let d=re(e.target),p=!!t.editingParam;if(!d&&!p&&t.activeDropdownIndex<0)break;if(t.activeDropdownIndex<0){if(l)break;if(e.preventDefault(),!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:a[0]??0});break}if(a.length===0)return;this.store.set({activeDropdownIndex:a[0]});break}if(e.preventDefault(),a.length===0)return;if(t.filteredOptions.length>0){let b=Math.floor((t.filteredOptions.length-1)/s);if(Math.floor(t.activeDropdownIndex/s)===b){this.store.set({activeDropdownIndex:-1});break}}let c=a.indexOf(t.activeDropdownIndex),m=c<a.length-1?c+1:0;this.store.set({activeDropdownIndex:a[m]});break}case"ArrowUp":{if(t.activeDropdownIndex<0){if(!l)break;let c=re(e.target),m=!!t.editingParam;if(!c&&!m)break;e.preventDefault();let b=this.firstTappableInBottomRow(s)??a[0]??0;if(!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:b});break}if(a.length===0)return;this.store.set({activeDropdownIndex:b});break}if(a.length===0)break;if(e.preventDefault(),t.activeDropdownIndex<s){this.store.set({activeDropdownIndex:-1});break}let d=a.indexOf(t.activeDropdownIndex),p=d>0?d-1:a.length-1;this.store.set({activeDropdownIndex:a[p]});break}case"ArrowRight":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%s<s-1){let c=t.activeDropdownIndex+1;c<t.filteredOptions.length&&t.filteredOptions[c]?.is_tappable&&this.store.set({activeDropdownIndex:c})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){e.preventDefault();let p=e.target.closest("[data-aia-input]")??e.target,c=t.editingTail;this.ctx.exitEditMode?.(),P(p,c);break}re(e.target)&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}case"ArrowLeft":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%s>0){let d=t.activeDropdownIndex-1;d>=0&&t.filteredOptions[d]?.is_tappable&&this.store.set({activeDropdownIndex:d})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingAnchor!=null){e.preventDefault();let d=e.target.closest("[data-aia-input]")??e.target,p=t.editingAnchor;this.ctx.exitEditMode?.(),P(d,p);break}break}case"Backspace":{if(t.editingParam||!this.ctx.removeParamAtCaret)break;let d=Je(e.target);if(d==null)break;this.ctx.removeParamAtCaret(d)&&e.preventDefault();break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,i);else if(o){let{rawQuery:d,completedParams:p}=S(t.text,t.completedParams);o({query:t.text.trim(),raw_query:d,completed_params:p}),this.ctx.afterSubmit?.()}break}case"Tab":{let d=!t.text&&!!t.placeholderText,p=t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable;if(d&&!p){e.preventDefault();let c=t.placeholderText;if(this.store.set(m=>({text:c,filterBase:c.length,suggestions:m.suggestions.filter(b=>b.type!=="placeholder")})),e.target instanceof HTMLElement){let m=e.target.closest("[data-aia-input]")??e.target;queueMicrotask(()=>P(m,c.length))}}else if(p)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,i);else if(t.isDropdownOpen){let c=t.filteredOptions.findIndex(m=>m.is_tappable);c>=0&&(e.preventDefault(),this.clickOrSelect(c,t.filteredOptions,i))}break}case"Escape":{if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){let d=e.target.closest("[data-aia-input]")??e.target,p=t.editingTail;this.ctx.exitEditMode?.(),P(d,p)}this.store.set({activeDropdownIndex:-1});break}}}firstTappableInBottomRow(e){let t=this.store.get();if(t.filteredOptions.length===0)return null;let r=Math.floor((t.filteredOptions.length-1)/e)*e;for(let s=r;s<t.filteredOptions.length;s++)if(t.filteredOptions[s]?.is_tappable)return s;return null}getTappableIndices(e){let i=this.store.get().filteredOptions.map((s,o)=>s.is_tappable?o:-1).filter(s=>s!==-1),r=Array.from({length:e},()=>[]);for(let s of i)r[s%e].push(s);return r.flat()}getEffectiveColumns(){let e=document.getElementById(this.ctx.listboxId);if(!e)return this.ctx.columns;let i=document.getElementById(`${this.ctx.listboxId}-option-0`)?.parentElement??null;for(;i;){let r=getComputedStyle(i).gridTemplateColumns;if(r&&r!=="none"){let s=r.split(" ").filter(Boolean).length;if(s>0)return s}if(i===e)break;i=i.parentElement}return this.ctx.columns}clickOrSelect(e,t,i){let r=document.getElementById(`${i}-option-${e}`);r?r.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),i=t.suggestions.filter(a=>a.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],s=i.filter((a,l)=>l!==e),o=t.suggestions.filter(a=>a.type==="placeholder");this.store.set({suggestions:[...o,r,...s],pillTapped:!0,activeDropdownIndex:-1})}};var W=class{constructor(e,t={}){this.store=e;this.callbacks=t}setActivePill(e){let t=this.store.get(),i=t.suggestions.filter(a=>a.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],s=i.filter((a,l)=>l!==e),o=t.suggestions.filter(a=>a.type==="placeholder");if(this.callbacks.onPillSelected){let{rawQuery:a}=S(t.text,t.completedParams);this.callbacks.onPillSelected({rawQuery:a,selectedPill:r.text,otherPills:s.map(l=>l.text)})}this.store.set({suggestions:[...o,r,...s],pillTapped:!0,activeDropdownIndex:-1})}removeLastParam(){this.store.get().completedParams.length!==0&&this.store.set(t=>({completedParams:t.completedParams.slice(0,-1),activeDropdownIndex:-1}))}};function ye(n,e){let t=[],i=0;for(let s of e){let o=n.indexOf(s.text,i);o!==-1&&(o>i&&t.push({type:"text",value:n.slice(i,o)}),t.push({type:"completed",value:s.text,param:s}),i=o+s.text.length)}let r=n.slice(i);return r&&t.push({type:"text",value:r}),t}function ve(n,e){let t=[],i=[],r=0;for(let s of e){let o=n.indexOf(s.text,r);o===-1?i.push(s):(t.push(s),r=o+s.text.length)}return{valid:t,invalid:i}}function Se(n,e){let t=e.dropdownTrigger??"auto",i=e.closeDropdownOnBlur??!0,r=n.filteredOptionsLength>0;if(n.inEditMode){let s=i?n.isFocused:!0;return r&&s}if(t==="auto"){let s=i?n.isFocused:!0,o=n.text.replace(/\s+$/,"").length,a=n.caretOffset==null||n.caretOffset>=o;return(r||n.isLoading)&&s&&a}return t==="manual"?(r||n.isLoading)&&n.pillTapped:!1}function Pe(n,e){let t=ye(n.text,n.completedParams),i=n.suggestions.filter(g=>g.type!=="placeholder"),r=i[0],s=r?e.optionOverrides?.[r.type]:void 0,o=n.suggestions.filter(g=>g.type==="placeholder").map(g=>g.text).join(" "),a=I(n.text,Math.min(n.filterBase,n.text.length),o),d=n.lastRawQuery!==""||a>0?w(n.text,a,n.filterInProgress):"",p=r?s?s(d.trim()):r.options??[]:[],c=n.editingParam!=null&&n.editingAnchor!=null,m;if(c&&n.editingParam&&n.editingAnchor!=null){let g=n.editingParam.id,h=n.completedParams.some(x=>x.id===g),f=n.caretOffset??n.editingAnchor,u=h?"":n.text.slice(n.editingAnchor,f);m=E(n.editingParam.options,u)}else m=E(p,d);e.showNonTappableOptions===!1&&(m=m.filter(g=>g.is_tappable));let b=Se({inEditMode:c,filteredOptionsLength:m.length,isFocused:n.isFocused,text:n.text,caretOffset:n.caretOffset,isLoading:n.isLoading,pillTapped:n.pillTapped},{dropdownTrigger:e.dropdownTrigger,closeDropdownOnBlur:e.closeDropdownOnBlur});return{segments:t,actionableSuggestions:i,filteredOptions:m,placeholderText:o,isDropdownOpen:b}}function G(n){return n.mode==="fresh"?Ze(n):et(n)}function Ze(n){let{text:e,completedParams:t,suggestions:i,filterBase:r,filterInProgress:s}=n,a=i.filter(v=>v.type!=="placeholder")[0];if(!a?.options)return null;let l=i.filter(v=>v.type==="placeholder").map(v=>v.text).join(" "),d=I(e,r,l),p=w(e,d,s),c=A(a.options,p);if(!c)return null;let m=c.text.toLowerCase(),b=e.toLowerCase().lastIndexOf(m),g=b>=0?b:Math.max(0,e.length-c.text.length),h=g+c.text.length,f=e.slice(g,h),x=h<e.length&&e[h]===" "?h+1:h,y={id:crypto.randomUUID(),placeholder:"",type:a.type,text:f,kind:c.kind,suggestionType:a.type,suggestionPlaceholder:a.text,options:a.options??[],metadata:c.metadata};return{patch:{text:e,completedParams:[...t,y],suggestions:i.filter(v=>v!==a),filterBase:x,newParamId:y.id,caretOffset:x,activeDropdownIndex:-1},caretPos:x}}function et(n){let{text:e,completedParams:t,editingParam:i,editingAnchor:r,editingTail:s}=n;if(t.some(y=>y.id===i.id))return null;let o=e.slice(r,s),a=A(i.options,o);if(!a)return null;let l=a.text.toLowerCase(),d=o.toLowerCase().lastIndexOf(l),p=r+Math.max(0,d),c=p+a.text.length,m=e.slice(p,c),g=c<e.length&&e[c]===" "?c+1:c,h={id:crypto.randomUUID(),placeholder:"",type:i.suggestionType,text:m,kind:a.kind,suggestionType:i.suggestionType,suggestionPlaceholder:i.suggestionPlaceholder,options:i.options,metadata:a.metadata},f=t.length,u=0;for(let y=0;y<t.length;y++){let v=e.indexOf(t[y].text,u);if(v!==-1){if(v>=g){f=y;break}u=v+t[y].text.length}}let x=[...t];return x.splice(f,0,h),{patch:{text:e,completedParams:x,newParamId:h.id,filterBase:g,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:g,activeDropdownIndex:-1},caretPos:g}}var j=class{constructor(e){this.deps=e}start(e){let t=this.deps.store.get();if(t.editingParam?.id===e)return;let i=t.completedParams.find(o=>o.id===e);if(!i)return;let r=0,s=-1;for(let o of t.completedParams){let a=t.text.indexOf(o.text,r);if(a!==-1){if(o.id===e){s=a;break}r=a+o.text.length}}s<0||this.deps.store.set({editingParam:i,editingAnchor:s,editingTail:s+i.text.length,caretOffset:s+i.text.length,activeDropdownIndex:-1})}exit(){this.deps.store.get().editingParam&&this.deps.store.set({editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1})}replaceRange(e){let t=this.deps.store.get(),i=t.editingParam,r=t.editingAnchor,s=t.editingTail;if(!i||r==null||s==null||!t.completedParams.some(l=>l.id===i.id))return!1;let o=t.text.slice(0,r)+e+t.text.slice(s),a=r+e.length;return this.deps.store.set(l=>({text:o,completedParams:l.completedParams.filter(d=>d.id!==i.id),editingTail:a,caretOffset:a,activeDropdownIndex:-1})),this.deps.scheduleSetCursor(a),this.tryPromote(),!0}caretAfterInput(e){let t=this.deps.store.get(),i={caretOffset:e};t.editingParam&&t.editingAnchor!=null&&e!=null&&(e<t.editingAnchor?(i.editingParam=null,i.editingAnchor=null,i.editingTail=null,i.activeDropdownIndex=-1):t.editingTail!=null&&(i.editingTail=Math.max(t.editingTail,e))),this.deps.store.set(i),this.tryPromote()}caretMove(e){let t=this.deps.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null&&e!=null&&(e<t.editingAnchor||e>t.editingTail)){this.deps.store.set({caretOffset:e,editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1});return}this.deps.store.set({caretOffset:e})}selectOption(e){let t=this.deps.store.get(),i=t.editingParam,r=t.editingAnchor,s=t.editingTail;if(!i||r==null||s==null)return;this.deps.fireTelemetry("option",{raw_query:S(t.text,t.completedParams).rawQuery,selected_option:e.text,other_options:i.options.filter(u=>u.text!==e.text).map(u=>u.text)});let o=t.text.slice(0,r),a=t.text.slice(s),l=r===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,d=a.length===0||a[0]!==" ",p=d?`${l} `:l,c=o+p+a,m=r+p.length+(d?0:1),b={id:crypto.randomUUID(),placeholder:"",type:i.suggestionType,text:l,kind:e.kind,suggestionType:i.suggestionType,suggestionPlaceholder:i.suggestionPlaceholder,options:i.options,metadata:e.metadata},g=t.completedParams.findIndex(u=>u.id===i.id),h=t.completedParams.filter(u=>u.id!==i.id),f=g>=0?Math.min(g,h.length):h.length;h.splice(f,0,b),this.deps.store.set({text:c,completedParams:h,newParamId:b.id,filterBase:m,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:m,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0}),this.deps.startSelectionAnimationTimer(),this.deps.scheduleSetCursor(m)}tryPromote(){let e=this.deps.store.get();if(!e.editingParam||e.editingAnchor==null||e.editingTail==null)return;let t=G({mode:"edit",text:e.text,completedParams:e.completedParams,editingParam:e.editingParam,editingAnchor:e.editingAnchor,editingTail:e.editingTail});t&&(this.deps.store.set(t.patch),this.deps.scheduleSetCursor(t.caretPos))}};var Te="data-aia-key";function V(n,e,t){let i=new Map;for(let o of Array.from(n.children)){let a=o.getAttribute(Te);a!=null&&i.set(a,o)}let r=new Set,s=[];for(let o=0;o<e.length;o++){let a=e[o],l=t.keyOf(a,o);r.add(l);let d=i.get(l);d||(d=t.create(a,o),d.setAttribute(Te,l)),t.update?.(d,a,o),n.children[o]!==d&&n.insertBefore(d,n.children[o]??null),s.push(d)}for(let[o,a]of i)r.has(o)||a.remove();return s}var Ce=[125,69];function we(n){return n===0?.4:n===1?.3:.15}function z(n,e,t,i,r=!1,s=!1){let o=n.querySelector(".magicx-aia-pill-list");if(o||(o=document.createElement("span"),o.className="magicx-aia-pill-list",n.appendChild(o)),s&&e.length===0){o.setAttribute("data-aia-pill-list-loading",""),o.innerHTML="";for(let a=0;a<Ce.length;a++){let l=Ce[a],d=document.createElement("span");d.setAttribute("data-aia-pill-skeleton",""),d.className=`magicx-aia-pill magicx-aia-pill--skeleton${r?" magicx-aia-pill--rounded":""}`,d.style.width=`${l}px`,d.style.opacity=String(we(a)),o.appendChild(d)}return}s?o.setAttribute("data-aia-pill-list-loading",""):o.removeAttribute("data-aia-pill-list-loading");for(let a of o.querySelectorAll("[data-aia-pill-skeleton]"))a.remove();V(o,e,{keyOf:a=>`${a.type}-${a.text}`,create:a=>{let l=document.createElement("button");return l.type="button",l.tabIndex=-1,l.setAttribute("data-aia-pill",""),l.setAttribute("contenteditable","false"),l.textContent=a.text,l.addEventListener("mousedown",d=>d.preventDefault()),l},update:(a,l,d)=>{let p=a,c=["magicx-aia-pill"];r&&c.push("magicx-aia-pill--rounded"),d===t&&!s&&c.push("magicx-aia-pill--active"),s&&c.push("magicx-aia-pill--skeleton"),p.className=c.join(" "),p.style.width="",p.style.opacity=String(we(d)),s?(p.setAttribute("data-aia-loading",""),p.disabled=!0,p.onclick=null):(p.removeAttribute("data-aia-loading"),p.disabled=!1,p.onclick=()=>i(d))}})}function oe(n){n.querySelector(".magicx-aia-pill-list")?.remove()}var tt=[159,119,164];function X(n){let e=document.createElement("div");return e.id=n,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function Y(n,e){let{filteredOptions:t,activeIndex:i,isOpen:r,isLoading:s,pills:o,showPills:a,onSelect:l,onHighlight:d,onPillClick:p}=e,c=a&&o.length>0,m=t.length>0;r&&(m||c||s)?n.classList.add("magicx-aia-dropdown--visible"):n.classList.remove("magicx-aia-dropdown--visible"),s?n.setAttribute("data-aia-loading",""):n.removeAttribute("data-aia-loading");let g=c||s&&a,h=n.querySelector(".magicx-aia-pill-bar");g?(h||(h=document.createElement("div"),h.className="magicx-aia-pill-bar",h.setAttribute("data-aia-pillbar",""),n.insertBefore(h,n.firstChild)),z(h,o,0,p,!0,s)):h&&h.remove();let f=n.querySelector(".magicx-aia-grid");m?(f||(f=document.createElement("div"),f.className="magicx-aia-grid",n.appendChild(f)),nt(f,t,i,l,d,e.listboxId,s)):f&&f.remove();let u=n.querySelector(".magicx-aia-skeleton-bars");if(s&&!m){if(!u){u=document.createElement("div"),u.className="magicx-aia-skeleton-bars",u.setAttribute("data-aia-skeleton-bars","");for(let x of tt){let y=document.createElement("span");y.className="magicx-aia-skeleton-bar",y.style.width=`${x}px`,u.appendChild(y)}n.appendChild(u)}}else u&&u.remove()}function nt(n,e,t,i,r,s,o){let a=o?"1":"0";V(n,e,{keyOf:l=>`${l.text}\0${a}`,create:l=>it(l,o),update:(l,d,p)=>{let c=p===t&&!o;l.id=`${s}-option-${p}`,l.dataset.aiaIndex=String(p),l.setAttribute("aria-selected",String(c)),l.classList.toggle("magicx-aia-option--highlighted",c),!o&&d.is_tappable?(l.onclick=()=>{l.classList.add("magicx-aia-option--pressed"),i(d),setTimeout(()=>l.classList.remove("magicx-aia-option--pressed"),500)},l.onmouseenter=()=>{let m=Number.parseInt(l.dataset.aiaIndex??"-1",10);m>=0&&r(m)}):(l.onclick=null,l.onmouseenter=null)}})}function it(n,e){let t=document.createElement("div");t.setAttribute("role","option"),t.setAttribute("data-aia-option",""),e&&t.setAttribute("data-aia-loading",""),t.tabIndex=e||!n.is_tappable?-1:0;let i=["magicx-aia-option"];n.is_tappable?i.push("magicx-aia-option--tappable"):i.push("magicx-aia-option--non-tappable"),t.className=i.join(" ");let r=document.createElement("div");r.className="magicx-aia-streaks",t.appendChild(r);let s=document.createElement("div");s.className="magicx-aia-streaks-vert",t.appendChild(s);let o=document.createElement("span");o.className="magicx-aia-option-content";let a=document.createElement("span");if(a.className="magicx-aia-option-text",a.textContent=n.icon?`${n.icon} ${n.text}`:n.text,o.appendChild(a),n.tag){let l=document.createElement("span");l.className="magicx-aia-option-tag",l.textContent=n.tag,o.appendChild(l)}return t.appendChild(o),t}function Ee(n,e){let t=X(e.listboxId);return n.appendChild(t),{dropdown:t}}function se(n,e,t){Y(n.dropdown,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:!0,onSelect:t.selectOption,onHighlight:i=>t.store.set({activeDropdownIndex:i}),onPillClick:t.setActivePill})}function J(n){let{input:e,segments:t,newParamId:i,editingParamId:r,placeholderText:s,isFocused:o}=n,a=t.length===0;e.dataset.aiaEmpty=a?"true":"false",a&&s?e.dataset.placeholder=s:delete e.dataset.placeholder;let l=t.map(f=>`${f.type}:${f.value}`).join("\0"),d=e.dataset.segKey??"",p=e.dataset.newParamId??"",c=e.dataset.editingParamId??"";if(l===d&&(i??"")===p&&(r??"")===c)return;let m=o?T(e):null;e.dataset.segKey=l,e.dataset.newParamId=i??"",e.dataset.editingParamId=r??"";let b=e.ownerDocument??document,g=b.createDocumentFragment(),h=0;for(let f of t)if(h+=f.value.length,f.type==="completed"){let u=b.createElement("strong");u.dataset.seg="completed",u.dataset.paramId=f.param.id;let x=f.param.id===i,y=f.param.id===r,v=["magicx-aia-segment","magicx-aia-segment--completed"];x&&v.push("magicx-aia-shimmer-revealed","magicx-aia-shimmer-sweep"),y&&v.push("magicx-aia-segment--editing"),u.className=v.join(" "),u.textContent=f.value,g.appendChild(u)}else g.appendChild(b.createTextNode(f.value));e.replaceChildren(g),e.dataset.aiaTextLength=String(h),m!=null&&P(e,Math.max(0,Math.min(m,h)))}var rt='<svg width="18" height="18" viewBox="0 0 18 18" fill="none" role="img" aria-label="Submit"><path d="M9 14V4M9 4L4 9M9 4L14 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function ot(){let n=document.createElement("div");return n.setAttribute("contenteditable","plaintext-only"),n.contentEditable==="plaintext-only"}function Ie(n,e){let t=e.firstElementChild;if(!t){e.removeAttribute("data-aia-pill-wrapped");return}let i=t.getBoundingClientRect(),r=n.getBoundingClientRect();i.top>=r.bottom-2?e.setAttribute("data-aia-pill-wrapped",""):e.removeAttribute("data-aia-pill-wrapped")}function Ae(n,e){let{listboxId:t}=e,i=X(t);n.appendChild(i);let r=document.createElement("div");r.className="magicx-aia-input-wrapper",n.appendChild(r);let s=document.createElement("div");s.className="magicx-aia-editor",s.setAttribute("data-aia-editor",""),r.appendChild(s);let o=document.createElement("div");o.className="magicx-aia-input",o.setAttribute("data-aia-input",""),o.setAttribute("contenteditable",ot()?"plaintext-only":"true"),o.setAttribute("role","combobox"),o.setAttribute("aria-autocomplete","list"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-controls",t),o.setAttribute("aria-expanded","false"),o.setAttribute("spellcheck","true"),o.setAttribute("enterkeyhint","send"),s.appendChild(o);let a=document.createElement("span");a.className="magicx-aia-pill-list-container",a.setAttribute("data-aia-pill-list-container",""),s.appendChild(a);let l=null,d=null;e.submitButton===void 0?(l=document.createElement("button"),l.type="button",l.className="magicx-aia-submit",l.setAttribute("aria-label","Submit"),l.setAttribute("data-aia-submit",""),l.innerHTML=rt,r.appendChild(l),d=l):e.submitButton!==null&&(d=e.submitButton,d.hasAttribute("data-aia-submit")||d.setAttribute("data-aia-submit",""),r.appendChild(d));let p=new AbortController,{signal:c}=p,m=!1,b=0,g=()=>{let u=L(o),y=u.length>0&&u[0]!==u[0].toUpperCase()?u[0].toUpperCase()+u.slice(1):u;e.handleChange(y)},h=()=>{let u=(o.ownerDocument??document).getSelection();if(!u||u.rangeCount===0)return null;let x=u.anchorNode;return!x||!o.contains(x)?null:(x.nodeType===Node.ELEMENT_NODE?x:x.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null};r.addEventListener("click",u=>{u.target?.closest("[data-aia-pill]")||o.focus()},{signal:c}),o.addEventListener("input",()=>{m||(b=performance.now(),g(),e.handleCaretAfterInput(T(o)))},{signal:c});let f=o.ownerDocument??document;if(f.addEventListener("selectionchange",()=>{let u=f.getSelection();if(!u||u.rangeCount===0||!o.contains(u.anchorNode))return;let x=h(),y=e.store.get().editingParam?.id??null;if(x&&x!==y){e.startEditingParam(x);return}performance.now()-b<50||e.handleCaretMove(T(o))},{signal:c}),o.addEventListener("compositionstart",()=>{m=!0},{signal:c}),o.addEventListener("compositionend",()=>{m=!1,g()},{signal:c}),o.addEventListener("beforeinput",u=>{let x=u,y=x.inputType;if(y==="insertParagraph"||y==="insertLineBreak"||y==="insertFromDrop"){u.preventDefault();return}if(y.startsWith("insert")||y.startsWith("delete")){let v=y.startsWith("delete")?"":x.data??"";e.replaceEditingRange(v)&&u.preventDefault()}},{signal:c}),o.addEventListener("paste",u=>{u.preventDefault();let x=(u.clipboardData?.getData("text/plain")??"").replace(/\r?\n/g," ");if(!x)return;let y=o.ownerDocument??document,v=y.getSelection();if(!v||v.rangeCount===0)return;let C=v.getRangeAt(0);if(!o.contains(C.startContainer))return;C.deleteContents();let de=y.createTextNode(x);C.insertNode(de),C.setStartAfter(de),C.collapse(!0),v.removeAllRanges(),v.addRange(C),g()},{signal:c}),o.addEventListener("keydown",u=>e.handleKeyDown(u),{signal:c}),o.addEventListener("focus",()=>e.store.set({isFocused:!0}),{signal:c}),o.addEventListener("blur",()=>e.store.set({isFocused:!1}),{signal:c}),d&&d.addEventListener("click",u=>{let x=e.store.get();if(!(!!x.text||x.completedParams.length>0)||!e.onSubmit)return;u.stopPropagation();let{rawQuery:v,completedParams:C}=S(x.text,x.completedParams);e.onSubmit({query:x.text.trim(),raw_query:v,completed_params:C}),e.afterSubmit?.()},{signal:c}),e.autoFocus!==!1&&o.focus(),typeof ResizeObserver<"u"){let u=new ResizeObserver(()=>Ie(o,a));u.observe(o),p.signal.addEventListener("abort",()=>u.disconnect(),{once:!0})}return{input:o,inlinePillContainer:a,dropdown:i,submitButton:l,abort:p}}function ae(n,e,t){let{input:i,inlinePillContainer:r,dropdown:s,submitButton:o}=n,{pillPlacement:a,setActivePill:l,selectOption:d,store:p}=t;i.setAttribute("aria-expanded",String(e.isDropdownOpen));let c=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";if(c?i.setAttribute("aria-activedescendant",c):i.removeAttribute("aria-activedescendant"),o){let f=!!e.text||e.completedParams.length>0;o.disabled=!f}let m=i.dataset.newParamId??"",b=e.newParamId!==null&&e.newParamId!==m;if(J({input:i,segments:e.segments,newParamId:e.newParamId,editingParamId:e.editingParam?.id??null,placeholderText:e.placeholderText,isFocused:e.isFocused}),a==="inline"){let f=e.isLoading&&!e.editingParam&&!e.inSelectionAnimation;f||e.actionableSuggestions.length>0?z(r,e.actionableSuggestions,0,l,!1,f):oe(r)}else oe(r);Ie(i,r),b?(i.focus(),P(i,e.caretOffset??e.text.length)):e.isFocused&&L(i)!==e.text&&P(i,e.text.length);let g=e.editingParam?{type:e.editingParam.suggestionType,text:e.editingParam.suggestionPlaceholder,required:!0,options:e.editingParam.options}:null,h=g??e.actionableSuggestions[0];Y(s,{suggestions:h?[{...h,options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:g?[g]:e.actionableSuggestions,showPills:a==="dropdown",onSelect:d,onHighlight:f=>p.set({activeDropdownIndex:f}),onPillClick:l})}function Oe(n,e){let t=n.actionableSuggestions[0];if(!t)return null;let i=n.filterBase,r=n.text.slice(0,i),s=r.length===0&&n.text.length===0,o=r.length===0&&n.text.length>0&&n.placeholderText.length>0&&n.placeholderText.toLowerCase().startsWith(n.text.toLowerCase());(s||o)&&n.placeholderText&&(r=`${n.placeholderText} `);let a=ge(r,e.text);a>0&&(r=r.slice(0,r.length-a));let l=r.length>0&&r[r.length-1]!==" ",d=`${r}${l?" ":""}${e.text} `,p=(s||o)&&d.length>0?d[0].toUpperCase()+d.slice(1):d,c=p.toLowerCase().lastIndexOf(e.text.toLowerCase()),m=c>=0?p.slice(c,c+e.text.length):e.text,b={id:crypto.randomUUID(),placeholder:"",type:t.type,text:m,kind:e.kind,suggestionType:t.type,suggestionPlaceholder:t.text,options:t.options??[],metadata:e.metadata},g=n.actionableSuggestions.length-1;return{patch:{text:p,filterBase:p.length,completedParams:[...n.completedParams,b],newParamId:b.id,caretOffset:p.length,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:g>0,inSelectionAnimation:!0},telemetry:{selectedOption:e.text,otherOptions:n.filteredOptions.filter(h=>h.text!==e.text).map(h=>h.text)},consumedSuggestion:t,remainingActionable:g}}function Z(n){let e=n,t=new Set;return{get:()=>e,set:i=>{let r=typeof i=="function"?i(e):i,s={...e,...r},o=e;e=s;for(let a of t)a(s,o)},subscribe:i=>(t.add(i),()=>{t.delete(i)})}}function De(n,e){let t,i,r=s=>(s!==t&&(t=s,i=e(s)),i);return{get:()=>{let s=n.get();return{...s,...r(s)}},set:s=>{typeof s=="function"?n.set(o=>{let a={...o,...r(o)};return s(a)}):n.set(s)},subscribe:s=>n.subscribe((o,a)=>{let l={...a,...r(a)},d={...o,...r(o)};s(d,l)})}}var le=!1;function Me(){if(le||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){le=!0;return}le=!0;let n=document.createElement("style");n.setAttribute("data-magicx-aia",""),n.textContent=st,document.head.appendChild(n)}var st=`@layer layout {
2
2
  .aia-stack {
3
3
  display: flex;
4
4
  flex-direction: column;
@@ -125,7 +125,6 @@
125
125
  .magicx-aia-input[data-aia-empty="true"] {
126
126
  display: inline-block;
127
127
  min-width: 1px;
128
- vertical-align: top;
129
128
  }
130
129
 
131
130
  /* Completed params render as inline bold runs. Specificity stays at (0,2,0)
@@ -250,7 +249,7 @@
250
249
 
251
250
  /* --- Pill bar (inside dropdown) --- */
252
251
  .magicx-aia-pill-bar {
253
- padding: 27px 27px 0px 27px;
252
+ padding: 27px 27px 3px 27px;
254
253
  }
255
254
 
256
255
  /* --- Fallback loading skeleton bars (only when no cached options) --- */
@@ -330,7 +329,6 @@
330
329
  gap: 5px;
331
330
  align-items: center;
332
331
  vertical-align: middle;
333
- transform: translateY(-3px);
334
332
  }
335
333
 
336
334
  /* --- Individual pill --- */
@@ -891,5 +889,5 @@
891
889
  animation-duration: 0s !important;
892
890
  transition-duration: 0s !important;
893
891
  }
894
- `;var ee=class{constructor(){this.listeners={}}on(e,t){let i=(...s)=>t(...s),r=this.listeners[e];return r||(r=new Set,this.listeners[e]=r),r.add(i),()=>{this.listeners[e]?.delete(i)}}emit(e,...t){let i=this.listeners[e];if(i)for(let r of i)r(...t)}hasListeners(e){return(this.listeners[e]?.size??0)>0}clear(){this.listeners={}}};var te=class{constructor(){this.timers=new Map}schedule(e,t,i){this.clear(e);let r=setTimeout(()=>{this.timers.delete(e),t()},i);this.timers.set(e,r)}clear(e){let t=this.timers.get(e);t!==void 0&&(clearTimeout(t),this.timers.delete(e))}clearAll(){for(let e of this.timers.values())clearTimeout(e);this.timers.clear()}};var D=class{constructor(e,t="auto"){this.container=e;this.mode=t;this.mediaQuery=null;this.onSystemChange=e=>{this.container.dataset.mode=e.matches?"dark":"light"};this.apply()}setMode(e){this.detachListener(),this.mode=e,this.apply()}destroy(){this.detachListener()}apply(){this.mode==="auto"?(this.mediaQuery??(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)")),this.mediaQuery.addEventListener("change",this.onSystemChange),this.container.dataset.mode=this.mediaQuery.matches?"dark":"light"):this.container.dataset.mode=this.mode}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function at(n){return(n??R).replace(/\/suggest(\?|#|$)/,"/telemetry/events$1")}async function lt(n){return M(n)?`Bearer ${await _(n).getToken()}`:F(n)}async function Le(n){try{let e=at(n.apiConfig?.endpoint),t=N(n.apiConfig),i=await lt(n.apiConfig);i&&(t.Authorization=i);let r=JSON.stringify({source:n.source,session_id:n.sessionId,type:n.type,at:new Date().toISOString(),query_data:n.queryData});await fetch(e,{method:"POST",headers:t,body:r})}catch{}}var dt="newParam",ke="suggestionRemoval",ct="selectionAnimation",pt=650,ut=0;function mt(){return`:ac-${++ut}:`}var Re=500;function _e(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1}}var ne=class{constructor(e,t={}){this.inputStore=Z(_e());this._listboxId=mt();this.modeController=null;this.unsubscribers=[];this.domRefs=null;this.dropdownRefs=null;this.timers=new te;this.emitter=new ee;this.sessionId=crypto.randomUUID();this.emitSubmit=e=>this.emitter.emit("submit",e);this.emitError=e=>this.emitter.emit("error",e);this.container=e,this.opts=t,this.renderMode=t.renderMode??"full",this.store=De(this.inputStore,i=>Pe(i,this.opts)),t.onSubmit&&this.emitter.on("submit",t.onSubmit),t.onError&&this.emitter.on("error",t.onError),t.onChange&&this.emitter.on("change",t.onChange),t.onParamsChange&&this.emitter.on("paramsChange",t.onParamsChange),t.onStateChange&&this.emitter.on("stateChange",t.onStateChange),t.onFocus&&this.emitter.on("focus",t.onFocus),t.onBlur&&this.emitter.on("blur",t.onBlur),t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new W(this.store,{onPillSelected:({rawQuery:i,selectedPill:r,otherPills:s})=>{this.fireTelemetry("pill",{raw_query:i,selected_pill:r,other_pills:s})}}),this.reEdit=new j({store:this.store,scheduleSetCursor:i=>this.scheduleSetCursor(i),fireTelemetry:(i,r)=>this.fireTelemetry(i,r),startSelectionAnimationTimer:()=>this.startSelectionAnimationTimer()}),this.fetchController=new H(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.emitter.hasListeners("error")?this.emitError:void 0,()=>this.sessionId,{onAutoMatch:({active:i,matched:r,rawQuery:s})=>{this.fireTelemetry("option",{raw_query:s,selected_option:r.text,other_options:(i.options??[]).filter(o=>o.text!==r.text).map(o=>o.text)})}}),this.keyboardController=new q(this.store,{columns:t.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.emitter.hasListeners("submit")?this.emitSubmit:void 0,getOptionsPosition:()=>this.opts.optionsPosition??"below",afterSubmit:this.renderMode==="full"?()=>this.reset():void 0,selectOption:i=>this.selectOption(i),removeParamAtCaret:i=>this.removeParamAtCaret(i),exitEditMode:()=>this.exitEditMode()}),this.unsubscribers.push(this.store.subscribe((i,r)=>{i.text!==r.text&&this.emitter.emit("change",i.text),i.completedParams!==r.completedParams&&this.emitter.emit("paramsChange",i.completedParams),i.isFocused!==r.isFocused&&(i.isFocused?this.emitter.emit("focus"):this.emitter.emit("blur")),this.emitter.emit("stateChange",i)})),this.unsubscribers.push(this.store.subscribe(()=>this.maybeExitReEditOnNoMatch())),this.renderMode!=="headless"&&(Me(),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.fetchController.start()}focus(){this.domRefs?.input.focus()}blur(){this.domRefs?.input.blur()}reset(){let e=this.store.get().isFocused;this.store.set({..._e(),isFocused:e,skipNextFetch:!0}),this.sessionId=crypto.randomUUID(),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.timers.clearAll(),this.emitter.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs?.abort.abort(),this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}setValue(e){this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e);let t=this.store.get().text.length;this.store.set({caretOffset:t,isFocused:!0}),this.scheduleSetCursor(t)}removeLastParam(){this.pillsController.removeLastParam()}removeParamAtCaret(e){let t=this.store.get(),{text:i,completedParams:r}=t,s=0;for(let o=0;o<r.length;o++){let a=r[o],l=i.indexOf(a.text,s);if(l===-1)continue;let d=l,p=l+a.text.length;if(e>d&&e<=p){let c=U(i,e),m=i.slice(0,c)+i.slice(e),b=r.filter((g,h)=>h!==o);return this.store.set(g=>({text:m,filterBase:Math.min(g.filterBase,m.length),completedParams:b,pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(c),!0}s=p}return!1}scheduleSetCursor(e){queueMicrotask(()=>{let t=this.domRefs;t?(t.input.focus(),P(t.input,e)):this.opts.setCursor?.(e)})}clearNewParamId(){this.store.set({newParamId:null})}startEditingParam(e){this.reEdit.start(e)}replaceEditingRange(e){return this.reEdit.replaceRange(e)}exitEditMode(){this.reEdit.exit()}handleCaretAfterInput(e){this.reEdit.caretAfterInput(e)}handleCaretMove(e){this.reEdit.caretMove(e)}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}handleTextChange(e){this.handleChange(e)}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}setFocused(e){this.store.get().isFocused!==e&&this.store.set({isFocused:e})}subscribe(e){return this.store.subscribe(t=>e(t))}getState(){return this.store.get()}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,t){return this.emitter.on(e,t)}update(e){Object.assign(this.opts,e),e.mode!==void 0&&this.modeController?.setMode(e.mode),e.optionsPosition!==void 0&&(this.container.dataset.optionsPosition=e.optionsPosition),e.animations!==void 0&&(this.container.dataset.animations=e.animations?"on":"off"),e.pillPlacement!==void 0&&(this.container.dataset.pillPlacement=e.pillPlacement,this.store.set({})),(e.dropdownTrigger!==void 0||e.closeDropdownOnBlur!==void 0||e.showNonTappableOptions!==void 0)&&this.store.set({}),e.value!==void 0&&this.store.set({text:e.value}),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let t=this.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null){this.reEdit.selectOption(e);return}let i=Oe(t,e);if(i&&(this.fireTelemetry("option",{raw_query:v(t.text,t.completedParams).rawQuery,selected_option:i.telemetry.selectedOption,other_options:i.telemetry.otherOptions}),this.store.set(i.patch),this.startSelectionAnimationTimer(),this.timers.clear(ke),i.remainingActionable>0)){let r=i.consumedSuggestion;this.timers.schedule(ke,()=>{this.store.set(s=>({suggestions:s.suggestions.filter(o=>o!==r)}))},Re)}}startSelectionAnimationTimer(){this.timers.schedule(ct,()=>this.store.set({inSelectionAnimation:!1}),Re)}fireTelemetry(e,t){let i=this.opts.source??(this.renderMode==="full"?"full-sdk":"headless-sdk");Le({source:i,sessionId:this.sessionId,type:e,queryData:t,apiConfig:this.opts.apiConfig})}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"inline",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new D(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,t={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"inline"},get onSubmit(){return e.emitter.hasListeners("submit")?e.emitSubmit:void 0},afterSubmit:()=>e.reset(),submitButton:this.opts.submitButton,autoFocus:this.opts.autoFocus??!0,selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i),startEditingParam:i=>this.startEditingParam(i),handleCaretAfterInput:i=>this.handleCaretAfterInput(i),handleCaretMove:i=>this.handleCaretMove(i),replaceEditingRange:i=>this.replaceEditingRange(i)};this.domRefs=Ie(this.container,t),this.subscribeBatchedRender(()=>{this.domRefs&&ae(this.domRefs,this.store.get(),t)}),ae(this.domRefs,this.store.get(),t),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e={store:this.store,listboxId:this.listboxId,selectOption:t=>this.selectOption(t),setActivePill:t=>this.pillsController.setActivePill(t)};this.dropdownRefs=Ee(this.container,e),this.subscribeBatchedRender(()=>{this.dropdownRefs&&se(this.dropdownRefs,this.store.get(),e)}),se(this.dropdownRefs,this.store.get(),e),this.subscribeNewParamTimer()}subscribeBatchedRender(e){let t=!1;this.unsubscribers.push(this.store.subscribe(()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,t)=>{e.newParamId&&e.newParamId!==t.newParamId&&this.timers.schedule(dt,()=>this.store.set({newParamId:null}),pt)}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:r}=Se(e,t.completedParams);r.length>0&&this.store.set({completedParams:i}),this.maybePromoteExactMatch(e)}maybeExitReEditOnNoMatch(){let e=this.store.get();if(!e.editingParam||e.editingAnchor==null||e.completedParams.some(a=>a.id===e.editingParam?.id))return;let t=e.caretOffset??e.editingAnchor,i=e.text.slice(e.editingAnchor,t);if(E(e.editingParam.options,i).some(a=>a.is_tappable))return;this.reEdit.exit();let{rawQuery:s,completedParams:o}=v(e.text,e.completedParams);this.fetchController.doFetch(s,o)}maybePromoteExactMatch(e){let t=this.store.get(),i=G({mode:"fresh",text:e,completedParams:t.completedParams,suggestions:t.suggestions,filterBase:t.filterBase,filterInProgress:t.filterInProgress});i&&this.store.set(i.patch)}};0&&(module.exports={AIAutocomplete,ModeController,buildQuery,createStore,cursorIsAtEnd,extractPlainText,getCursorOffset,plainTextLength,previousGraphemeBoundary,renderEditableContent,setCursorOffset});
892
+ `;var ee=class{constructor(){this.listeners={}}on(e,t){let i=(...s)=>t(...s),r=this.listeners[e];return r||(r=new Set,this.listeners[e]=r),r.add(i),()=>{this.listeners[e]?.delete(i)}}emit(e,...t){let i=this.listeners[e];if(i)for(let r of i)r(...t)}hasListeners(e){return(this.listeners[e]?.size??0)>0}clear(){this.listeners={}}};var te=class{constructor(){this.timers=new Map}schedule(e,t,i){this.clear(e);let r=setTimeout(()=>{this.timers.delete(e),t()},i);this.timers.set(e,r)}clear(e){let t=this.timers.get(e);t!==void 0&&(clearTimeout(t),this.timers.delete(e))}clearAll(){for(let e of this.timers.values())clearTimeout(e);this.timers.clear()}};var D=class{constructor(e,t="auto",i){this.container=e;this.mode=t;this.onResolve=i;this.mediaQuery=null;this.onSystemChange=e=>{this.setResolved(e.matches?"dark":"light")};this.apply()}setMode(e){this.detachListener(),this.mode=e,this.apply()}destroy(){this.detachListener()}apply(){this.mode==="auto"?(this.mediaQuery??(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)")),this.mediaQuery.addEventListener("change",this.onSystemChange),this.setResolved(this.mediaQuery.matches?"dark":"light")):this.setResolved(this.mode)}setResolved(e){this.container.dataset.mode=e,this.onResolve?.(e)}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function at(n){return(n??R).replace(/\/suggest(\?|#|$)/,"/telemetry/events$1")}async function lt(n){return M(n)?`Bearer ${await _(n).getToken()}`:F(n)}async function Le(n){try{let e=at(n.apiConfig?.endpoint),t=N(n.apiConfig),i=await lt(n.apiConfig);i&&(t.Authorization=i);let r=JSON.stringify({source:n.source,session_id:n.sessionId,type:n.type,at:new Date().toISOString(),query_data:n.queryData});await fetch(e,{method:"POST",headers:t,body:r})}catch{}}var dt="newParam",ke="suggestionRemoval",ct="selectionAnimation",pt=650,ut=0;function mt(){return`:ac-${++ut}:`}var Re=500;function _e(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1}}var ne=class{constructor(e,t={}){this.inputStore=Z(_e());this._listboxId=mt();this.modeController=null;this.unsubscribers=[];this.domRefs=null;this.dropdownRefs=null;this.timers=new te;this.emitter=new ee;this.sessionId=crypto.randomUUID();this.emitSubmit=e=>this.emitter.emit("submit",e);this.emitError=e=>this.emitter.emit("error",e);this.container=e,this.opts=t,this.renderMode=t.renderMode??"full",this.store=De(this.inputStore,i=>Pe(i,this.opts)),t.onSubmit&&this.emitter.on("submit",t.onSubmit),t.onError&&this.emitter.on("error",t.onError),t.onChange&&this.emitter.on("change",t.onChange),t.onParamsChange&&this.emitter.on("paramsChange",t.onParamsChange),t.onStateChange&&this.emitter.on("stateChange",t.onStateChange),t.onFocus&&this.emitter.on("focus",t.onFocus),t.onBlur&&this.emitter.on("blur",t.onBlur),t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new W(this.store,{onPillSelected:({rawQuery:i,selectedPill:r,otherPills:s})=>{this.fireTelemetry("pill",{raw_query:i,selected_pill:r,other_pills:s})}}),this.reEdit=new j({store:this.store,scheduleSetCursor:i=>this.scheduleSetCursor(i),fireTelemetry:(i,r)=>this.fireTelemetry(i,r),startSelectionAnimationTimer:()=>this.startSelectionAnimationTimer()}),this.fetchController=new H(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.emitter.hasListeners("error")?this.emitError:void 0,()=>this.sessionId,{onAutoMatch:({active:i,matched:r,rawQuery:s})=>{this.fireTelemetry("option",{raw_query:s,selected_option:r.text,other_options:(i.options??[]).filter(o=>o.text!==r.text).map(o=>o.text)})}}),this.keyboardController=new q(this.store,{columns:t.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.emitter.hasListeners("submit")?this.emitSubmit:void 0,getOptionsPosition:()=>this.opts.optionsPosition??"below",afterSubmit:this.renderMode==="full"?()=>this.reset():void 0,selectOption:i=>this.selectOption(i),removeParamAtCaret:i=>this.removeParamAtCaret(i),exitEditMode:()=>this.exitEditMode()}),this.unsubscribers.push(this.store.subscribe((i,r)=>{i.text!==r.text&&this.emitter.emit("change",i.text),i.completedParams!==r.completedParams&&this.emitter.emit("paramsChange",i.completedParams),i.isFocused!==r.isFocused&&(i.isFocused?this.emitter.emit("focus"):this.emitter.emit("blur")),this.emitter.emit("stateChange",i)})),this.unsubscribers.push(this.store.subscribe(()=>this.maybeExitReEditOnNoMatch())),this.renderMode!=="headless"&&(Me(),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.fetchController.start()}focus(){this.domRefs?.input.focus()}blur(){this.domRefs?.input.blur()}reset(){let e=this.store.get().isFocused;this.store.set({..._e(),isFocused:e,skipNextFetch:!0}),this.sessionId=crypto.randomUUID(),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.timers.clearAll(),this.emitter.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs?.abort.abort(),this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}setValue(e){this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e);let t=this.store.get().text.length;this.store.set({caretOffset:t,isFocused:!0}),this.scheduleSetCursor(t)}removeLastParam(){this.pillsController.removeLastParam()}removeParamAtCaret(e){let t=this.store.get(),{text:i,completedParams:r}=t,s=0;for(let o=0;o<r.length;o++){let a=r[o],l=i.indexOf(a.text,s);if(l===-1)continue;let d=l,p=l+a.text.length;if(e>d&&e<=p){let c=U(i,e),m=i.slice(0,c)+i.slice(e),b=r.filter((g,h)=>h!==o);return this.store.set(g=>({text:m,filterBase:Math.min(g.filterBase,m.length),completedParams:b,pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(c),!0}s=p}return!1}scheduleSetCursor(e){queueMicrotask(()=>{let t=this.domRefs;t?(t.input.focus(),P(t.input,e)):this.opts.setCursor?.(e)})}clearNewParamId(){this.store.set({newParamId:null})}startEditingParam(e){this.reEdit.start(e)}replaceEditingRange(e){return this.reEdit.replaceRange(e)}exitEditMode(){this.reEdit.exit()}handleCaretAfterInput(e){this.reEdit.caretAfterInput(e)}handleCaretMove(e){this.reEdit.caretMove(e)}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}handleTextChange(e){this.handleChange(e)}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}setFocused(e){this.store.get().isFocused!==e&&this.store.set({isFocused:e})}subscribe(e){return this.store.subscribe(t=>e(t))}getState(){return this.store.get()}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,t){return this.emitter.on(e,t)}update(e){Object.assign(this.opts,e),e.mode!==void 0&&this.modeController?.setMode(e.mode),e.optionsPosition!==void 0&&(this.container.dataset.optionsPosition=e.optionsPosition),e.animations!==void 0&&(this.container.dataset.animations=e.animations?"on":"off"),e.pillPlacement!==void 0&&(this.container.dataset.pillPlacement=e.pillPlacement,this.store.set({})),(e.dropdownTrigger!==void 0||e.closeDropdownOnBlur!==void 0||e.showNonTappableOptions!==void 0)&&this.store.set({}),e.value!==void 0&&this.store.set({text:e.value}),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let t=this.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null){this.reEdit.selectOption(e);return}let i=Oe(t,e);if(i&&(this.fireTelemetry("option",{raw_query:S(t.text,t.completedParams).rawQuery,selected_option:i.telemetry.selectedOption,other_options:i.telemetry.otherOptions}),this.store.set(i.patch),this.startSelectionAnimationTimer(),this.timers.clear(ke),i.remainingActionable>0)){let r=i.consumedSuggestion;this.timers.schedule(ke,()=>{this.store.set(s=>({suggestions:s.suggestions.filter(o=>o!==r)}))},Re)}}startSelectionAnimationTimer(){this.timers.schedule(ct,()=>this.store.set({inSelectionAnimation:!1}),Re)}fireTelemetry(e,t){let i=this.opts.source??(this.renderMode==="full"?"full-sdk":"headless-sdk");Le({source:i,sessionId:this.sessionId,type:e,queryData:t,apiConfig:this.opts.apiConfig})}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"inline",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new D(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,t={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"inline"},get onSubmit(){return e.emitter.hasListeners("submit")?e.emitSubmit:void 0},afterSubmit:()=>e.reset(),submitButton:this.opts.submitButton,autoFocus:this.opts.autoFocus??!0,selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i),startEditingParam:i=>this.startEditingParam(i),handleCaretAfterInput:i=>this.handleCaretAfterInput(i),handleCaretMove:i=>this.handleCaretMove(i),replaceEditingRange:i=>this.replaceEditingRange(i)};this.domRefs=Ae(this.container,t),this.subscribeBatchedRender(()=>{this.domRefs&&ae(this.domRefs,this.store.get(),t)}),ae(this.domRefs,this.store.get(),t),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e={store:this.store,listboxId:this.listboxId,selectOption:t=>this.selectOption(t),setActivePill:t=>this.pillsController.setActivePill(t)};this.dropdownRefs=Ee(this.container,e),this.subscribeBatchedRender(()=>{this.dropdownRefs&&se(this.dropdownRefs,this.store.get(),e)}),se(this.dropdownRefs,this.store.get(),e),this.subscribeNewParamTimer()}subscribeBatchedRender(e){let t=!1;this.unsubscribers.push(this.store.subscribe(()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,t)=>{e.newParamId&&e.newParamId!==t.newParamId&&this.timers.schedule(dt,()=>this.store.set({newParamId:null}),pt)}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:r}=ve(e,t.completedParams);r.length>0&&this.store.set({completedParams:i}),this.maybePromoteExactMatch(e)}maybeExitReEditOnNoMatch(){let e=this.store.get();if(!e.editingParam||e.editingAnchor==null||e.completedParams.some(a=>a.id===e.editingParam?.id))return;let t=e.caretOffset??e.editingAnchor,i=e.text.slice(e.editingAnchor,t);if(E(e.editingParam.options,i).some(a=>a.is_tappable))return;this.reEdit.exit();let{rawQuery:s,completedParams:o}=S(e.text,e.completedParams);this.fetchController.doFetch(s,o)}maybePromoteExactMatch(e){let t=this.store.get(),i=G({mode:"fresh",text:e,completedParams:t.completedParams,suggestions:t.suggestions,filterBase:t.filterBase,filterInProgress:t.filterInProgress});i&&this.store.set(i.patch)}};0&&(module.exports={AIAutocomplete,ModeController,buildQuery,createStore,cursorIsAtEnd,extractPlainText,getCursorOffset,plainTextLength,previousGraphemeBoundary,renderEditableContent,setCursorOffset});
895
893
  //# sourceMappingURL=index.js.map