@magicx-eng/ai-autocomplete-vanilla 0.37.0 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function P(t){return t==="date"||t==="date-range"}function Y(t){return t?.type?.kind==="date"?"date":t?.type?.kind==="date_range"?"date-range":"options"}var Ee=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 Zr="https://api.ai-autocomplete.com",Pe=`${Zr}/api/suggest`,dn=new WeakMap;function ce(t){return t?.type==="accessToken"}function ei(t){if(!(!t||ce(t)))return t}function we(t){let e=dn.get(t.getAccessToken);return e||(e=new Ee(t),dn.set(t.getAccessToken,e)),e}function Te(t){return{"Content-Type":"application/json",...t?.appIdentifier&&{"X-App-Identifier":t.appIdentifier},...t?.headers}}function Ce(t){let e=ei(t),n=e?.apiKey;return n?(e?.authScheme??"Bearer")==="Basic"?`Basic ${btoa(n)}`:`Bearer ${n}`:null}function ue(t){return t.map(e=>({parameter:e.parameter,text:e.text}))}var cn="skipped";function pe(t,e){if(e.length===0)return t;let n=new Set(t.map(i=>i.parameter)),r=e.filter(i=>!n.has(i.parameter)).map(i=>({placeholder:"",parameter:i.parameter,text:cn,kind:null}));return r.length>0?[...t,...r]:t}var ti="0.37.0",mn="1.0",un=!1;function ni(t,e){return{placeholder:t.placeholder,parameter:t.parameter,...e&&{text:t.value??t.text},kind:t.kind}}function ri(t,e,n,r,i,o,s,a,l,d){let u=e.find(m=>m.parameter==="contact"&&m.metadata?.contact_account_count)?.metadata?.contact_account_count,c=typeof u=="number"?u:void 0;return{data:{raw_query:t,completed_params:pe(e.map(m=>ni(m,n)),l??[]),...s&&s.length>0&&{identified_params:ue(s)},...a&&a.length>0&&{recently_suggested:a},...c!=null&&{contact_account_count:c},...d!==void 0&&{additional_context:d}},meta:{request_id:i,request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:ti,session_id:r,source:o,schema_version:mn}}}async function pn(t,e,n,r,i){return fetch(t,{method:"POST",headers:{...e,Authorization:`Bearer ${n}`},body:r,signal:i})}async function fn(t,e,n){let r=n.apiConfig,i=!n.maskCompletedText,o=ri(t,e,i,n.sessionId,n.requestId??crypto.randomUUID(),n.source,n.identifiedParams,n.recentlySuggested,n.skippedParams,n.additionalContext),s=Te(r),a=r?.endpoint??Pe,l=JSON.stringify(o);if(ce(r)){let c=we(r),m=await c.getToken(),f=await pn(a,s,m,l,n.signal);if(f.status===401){let h=await c.getToken(!0);f=await pn(a,s,h,l,n.signal)}if(!f.ok)throw new Error(`API error: ${f.status} ${f.statusText}`);return f.json()}let d=Ce(r);!d&&!un&&(un=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),d&&(s.Authorization=d);let u=await fetch(a,{method:"POST",headers:s,body:l,signal:n.signal});if(!u.ok)throw new Error(`API error: ${u.status} ${u.statusText}`);return u.json()}var Ie=/[\p{L}\p{N}]/u,ii=/['\u2019-]/;function gn(t,e,n){let r=t[e];if(r===void 0)return!1;if(Ie.test(r))return!0;let i=t[e+n];return ii.test(r)&&i!==void 0&&Ie.test(i)}function oi(t,e,n){let r=e+n.length;return!(Ie.test(n[0])&&gn(t,e-1,-1)||Ie.test(n[n.length-1])&&gn(t,r,1))}function N(t,e,n=0,r=()=>!0){if(e.length===0)return t.indexOf(e,n);let i=-1,o=t.indexOf(e,n);for(;o!==-1;){if(r(o)){if(oi(t,o,e))return o;i===-1&&(i=o)}o=t.indexOf(e,o+1)}return i}function R(t,e){let n=t,r={},i=[],o=[],s=0;for(let a of e){let l=(r[a.parameter]??0)+1;r[a.parameter]=l;let u=`{{${a.parameter.toUpperCase().replace(/\s+/g,"_")}_${l}}}`,c=f=>N(n,a.text,f,h=>!o.some(x=>h<x.end&&h+a.text.length>x.start)),m=c(s);if(m===-1&&(m=c(0)),m!==-1){n=n.slice(0,m)+u+n.slice(m+a.text.length);let f=u.length-a.text.length;for(let h of o)h.start>=m+a.text.length&&(h.start+=f,h.end+=f);o.push({start:m,end:m+u.length}),s=m>=s?m+u.length:s+f}i.push({...a,placeholder:u})}return{rawQuery:n,completedParams:i}}function B(t,e,n){return e>0||!n?e:t.toLowerCase().startsWith(n.toLowerCase())?n.length:e}function Oe(t,e,n){return e===0&&t.length>0&&n.length>0&&n.toLowerCase().startsWith(t.toLowerCase())}function Q(t,e,n){let r=t.slice(e);if(n||e===0||t[e-1]===" ")return r;let i=r.indexOf(" ");return i===-1?"":r.slice(i+1)}function hn(t,e){let n=t.trimEnd().replace(/\s+/g," ");if(n.length===0||e.length===0)return 0;let r=n.split(" "),i=e.toLowerCase();for(let o=0;o<r.length;o++){let s=r.slice(o).join(" ");if(i.startsWith(s.toLowerCase())){let a=n.length-s.length;return t.length-a}}return 0}function X(t,e){if(!t)return[];let n=e.trimStart();if(!n)return t;let r=n.toLowerCase();return t.filter(i=>!i.is_tappable||i.text.toLowerCase().includes(r))}function te(t,e){if(!t)return null;let n=e.trim();if(!n)return null;let r=n.toLowerCase();return t.find(i=>i.is_tappable&&i.text.toLowerCase()===r)??null}function bn(t,e){return e?t.map(n=>e[n.parameter]?{...n,options:[]}:n):t}function si(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.toLowerCase())}function j(t){let e=si(t);return e.length>0?e.join(" "):t}function F(t,e){return t.parameter||e}function Sn(t,e){let n=0,r=e;for(let i of t)n+=i.value.length,i.type!=="text"&&(r=Math.max(r,n));return r}function xn(t,e){let n=0;for(let r of t){let i=n+r.value.length;if(r.type==="text"&&i>e&&r.value.slice(Math.max(e-n,0)).trim().length>0)return!1;n=i}return!0}function yn(t,e){let n=[],r=new Set;for(let i of[...t,...e])i.parameter==="placeholder"||r.has(i.parameter)||(r.add(i.parameter),n.push({parameter:i.parameter,text:i.text}));return n}function vn(t,e,n){if(t===e)return n;let r=Math.min(t.length,e.length),i=0;for(;i<r&&t[i]===e[i];)i++;if(i>=n)return n;let o=0;for(;o<r-i&&t[t.length-1-o]===e[e.length-1-o];)o++;return t.length-o<=n?n+(e.length-t.length):null}function Ae(t,e){let n=[],r=[],i=0;for(let o of e){let s=N(t,o.text,i);if(s===-1){r.push(o);continue}n.push({start:s,end:s+o.text.length,param:o}),i=s+o.text.length}return{located:n,missing:r}}function En(t,e){let{located:n}=Ae(t,e);return n.length>0?n[n.length-1].end:0}function Pn(t,e,n){let r=[],i=[],o=0;for(let s of n){let a=N(t,s.text,o,l=>!e.some(d=>l<d.end&&l+s.text.length>d.start));if(a===-1){i.push(s);continue}r.push({start:a,end:a+s.text.length,param:s}),o=a+s.text.length}return{located:r,missing:i}}function wn(t,e,n=[]){let r=Ae(t,e).located,i=Pn(t,r,n).located,o=[...r.map(d=>({start:d.start,end:d.end,segment:{type:"completed",value:d.param.text,param:d.param}})),...i.map(d=>({start:d.start,end:d.end,segment:{type:"identified",value:d.param.text,param:d.param}}))].sort((d,u)=>d.start-u.start),s=[],a=0;for(let d of o)d.start>a&&s.push({type:"text",value:t.slice(a,d.start)}),s.push(d.segment),a=d.end;let l=t.slice(a);return l&&s.push({type:"text",value:l}),s}function Tn(t,e){let{located:n,missing:r}=Ae(t,e);return{valid:n.map(i=>i.param),invalid:r}}function Le(t,e,n){let r=Ae(t,e).located,{located:i,missing:o}=Pn(t,r,n);return{valid:i.map(s=>s.param),invalid:o}}function ai(t){if(t instanceof Error)return t;try{return new Error(String(t))}catch{return new Error("Unknown error")}}var li=100,di=300,ci=2,Re=class{constructor(e,n,r,i,o,s,a,l,d={}){this.store=e;this.getApiConfig=n;this.getOptionOverrides=r;this.getMaskCompletedText=i;this.getOnError=o;this.getSessionId=s;this.getSource=a;this.getAdditionalContext=l;this.callbacks=d;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,n=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(r=>{(r.text!==e||r.completedParams!==n)&&(e=r.text,n=r.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,n){this.abortController?.abort();let r=new AbortController;this.abortController=r;let i=++this.fetchVersion,o=this.store.get().text.length;try{this.callbacks.onRequest?.({query:this.store.get().text,signal:r.signal,isCurrent:()=>i===this.fetchVersion})}catch{}try{this.store.set({isLoading:!0,error:null});let s=this.store.get(),a=s.pendingSpan?yn(s.pendingSpan.snapshot,s.actionableSuggestions):void 0,l=crypto.randomUUID(),d=await fn(e,n,{sessionId:this.getSessionId(),requestId:l,source:this.getSource(),maskCompletedText:this.getMaskCompletedText(),signal:r.signal,apiConfig:this.getApiConfig(),identifiedParams:s.identifiedParams,recentlySuggested:a,skippedParams:s.skippedParams,additionalContext:this.getAdditionalContext()});if(i!==this.fetchVersion)return;let u=(d.data.input??[]).filter(v=>v.source==="identified").map(v=>({id:crypto.randomUUID(),parameter:v.parameter,text:v.text,...v.type?{type:v.type}:{}})),c=bn(d.data.suggestions??[],this.getOptionOverrides()),m=d.data.input??[],f=m[m.length-1],h=this.store.get().text,x,y;if(f?.state==="in_progress"){y=!0;let v=h.toLowerCase().lastIndexOf(f.text.toLowerCase());x=v!==-1?v:o}else y=!1,x=o;let p=c.filter(v=>v.parameter!=="placeholder")[0],b=null;if(p&&!P(Y(p))){let v=Q(h,x,y),w=te(p.options,v);w&&(b={id:crypto.randomUUID(),placeholder:"",parameter:F(w,p.parameter),text:w.text,value:w.value,kind:w.kind,suggestionParameter:p.parameter,suggestionValueType:p.type,suggestionPlaceholder:p.text,options:p.options??[],metadata:w.metadata,icon:w.icon,icon_svg:w.icon_svg,image_url:w.image_url},c=c.filter(L=>L!==p),this.callbacks.onAutoMatch?.({active:p,matched:w,rawQuery:e}))}let S=d.data.custom_fields??null,E=this.callbacks.productsForResponse?.(S);this.store.set(v=>{let w=b?[...v.completedParams,b]:v.completedParams,L=Le(v.text,w,u).valid,T=new Set(s.skippedParams.map(M=>M.id)),I=new Set(v.skippedParams.filter(M=>!T.has(M.id)).map(M=>M.parameter));return{suggestions:I.size>0?c.filter(M=>M.parameter==="placeholder"||!I.has(M.parameter)):c,isLoading:!1,isReady:d.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:x,filterInProgress:y,identifiedParams:L,customFields:S,...E!==void 0?{products:E}:{},...b?{completedParams:w}:{}}}),this.callbacks.onResponse?.({requestId:l,funnelTelemetry:d.meta?.funnel_telemetry===!0})}catch(s){let a=ai(s);i===this.fetchVersion&&(this.store.set({error:a,isLoading:!1}),this.getOnError()?.(a))}finally{if(i===this.fetchVersion&&this.store.get().isLoading)try{this.store.set({isLoading:!1})}catch{}}}attemptNow(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}this.attemptFetch(1,!0)}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}this.debounceTimer=setTimeout(()=>{this.attemptFetch(ci)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},li),this.slowDebounceTimer=setTimeout(()=>this.attemptFetch(1),di)}attemptFetch(e,n=!1){let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let i=this.callbacks.consumerTick?.(r,e)??"no";if(i==="asked")return!0;if(i==="owns")return!1;let o=r.suggestions.filter(S=>S.parameter==="placeholder").map(S=>S.text).join(" "),s=B(r.text,r.filterBase,o),a=Q(r.text,s,r.filterInProgress),d=r.suggestions.filter(S=>S.parameter!=="placeholder")[0],u=P(r.activeFormatType),m=(d&&!u?X(d.options,a):[]).filter(S=>S.is_tappable),f=d&&!u?te(d.options,a)!==null:!1,h=a.trim().length>0;if(m.length>0&&!f&&h||Oe(r.text,r.completedParams.length,o))return!1;let{rawQuery:x,completedParams:y}=R(r.text,r.completedParams),g=x.length<r.lastRawQuery.length,p=Math.abs(x.length-r.lastRawQuery.length),b=n&&x!==r.lastRawQuery;return g||p>=e||b?(this.doFetch(x,y),!0):!1}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var ne=["January","February","March","April","May","June","July","August","September","October","November","December"],Me=["S","M","T","W","T","F","S"],On=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],An="aiaDate",Ln="aiaDay",Cn=t=>String(t).padStart(2,"0");function k(t){return`${t.getFullYear()}-${Cn(t.getMonth()+1)}-${Cn(t.getDate())}`}function ot(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate())}function ui(t){let e=ot(t).getTime()-ot(new Date).getTime();return Math.round(e/864e5)}function Rn(t){let e=ui(t);return e>=0&&e<7?On[t.getDay()]:re(t)}function re(t){return t.getFullYear()===new Date().getFullYear()?`${ne[t.getMonth()]} ${t.getDate()}`:`${ne[t.getMonth()]} ${t.getDate()} ${t.getFullYear()}`}function De(t){if(!t)return null;let e=On.findIndex(a=>a.toLowerCase()===t.trim().toLowerCase());if(e>=0){let a=ot(new Date),l=(e-a.getDay()+7)%7;return new Date(a.getFullYear(),a.getMonth(),a.getDate()+l)}let n=/^\s*([A-Za-z]+)\s+(\d{1,2})(?:\s+(\d{4}))?\s*$/.exec(t);if(!n)return null;let r=ne.findIndex(a=>a.toLowerCase()===n[1].toLowerCase());if(r<0)return null;let i=Number(n[2]),o=n[3]?Number(n[3]):new Date().getFullYear(),s=new Date(o,r,i);return s.getMonth()!==r||s.getDate()!==i?null:s}function st(t){return`${ne[t.month]} ${t.year}`}function at(){let t=new Date;return{year:t.getFullYear(),month:t.getMonth()}}function Mn(t){return{year:t.getFullYear(),month:t.getMonth()}}function lt(t,e){let n=new Date(t.year,t.month+e,1);return{year:n.getFullYear(),month:n.getMonth()}}function In(){return{text:"",is_tappable:!1,kind:null}}function dt(t){let e=new Date(t.year,t.month,1).getDay(),n=new Date(t.year,t.month+1,0).getDate(),r=[];for(let i=0;i<e;i++)r.push(In());for(let i=1;i<=n;i++){let o=new Date(t.year,t.month,i);r.push({text:Rn(o),is_tappable:!0,kind:null,metadata:{[An]:k(o),[Ln]:i}})}for(;r.length%Me.length!==0;)r.push(In());return r}function ct(t){let e=De(t);return e?k(e):null}function H(t){let e=t?.metadata?.[An];return typeof e=="string"?e:null}function ut(t){let e=t?.metadata?.[Ln];return typeof e=="number"?e:null}function pi(t){return t.nodeType===Node.DOCUMENT_NODE?!0:t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in t}function z(t){let e=typeof t.getRootNode=="function"?t.getRootNode():null;return e&&pi(e)?e:t.ownerDocument??t}function O(t){return t.ownerDocument??t}function mi(t){return t.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function Dn(t){let e=z(t);return!mi(e)||typeof e.getSelection=="function"?null:e}function kn(t){let e=Dn(t);if(!e)return null;let n=O(t).getSelection?.();return!n||typeof n.getComposedRanges!="function"?null:e}function _n(t,e){let n=t,r;try{r=n.getComposedRanges({shadowRoots:[e]})}catch{r=n.getComposedRanges(e)}return r.length>0?r[0]:null}function pt(t){let n=z(t).getSelection?.();return n||(O(t).getSelection?.()??null)}function W(t){let e=pt(t);if(!e||e.rangeCount===0)return null;let n=kn(t);if(n){let r=_n(e,n);return r?{node:r.startContainer,offset:r.startOffset,collapsed:r.startContainer===r.endContainer&&r.startOffset===r.endOffset}:null}return e.anchorNode?{node:e.anchorNode,offset:e.anchorOffset,collapsed:e.isCollapsed}:null}function ke(t){let e=pt(t);if(!e||e.rangeCount===0)return null;let n=kn(t);if(!n)return e.getRangeAt(0);let r=_n(e,n);if(!r)return null;let i=O(t).createRange();return i.setStart(r.startContainer,r.startOffset),i.setEnd(r.endContainer,r.endOffset),i}function me(t,e,n){let r=pt(t);if(!r)return null;if(Dn(t))return r.collapse(e,n),r;let i=O(t).createRange();return i.setStart(e,n),i.collapse(!0),r.removeAllRanges(),r.addRange(i),r}function _e(t,e){let n=t?z(t):typeof document<"u"?document:null;return n?typeof n.getElementById=="function"?n.getElementById(e):typeof document<"u"?document.getElementById(e):null:null}var Ne=2,fi="magicx-aia";function Nn(t){return t==="auto"||t==="scroll"||t==="hidden"||t==="overlay"}function gi(t){let e=O(t),n=e.defaultView;if(!n?.getComputedStyle)return null;let r=t;for(;r&&r!==e.body&&r!==e.documentElement;){let i=r.scrollWidth>r.clientWidth,o=r.scrollHeight>r.clientHeight;if(i||o){let s=n.getComputedStyle(r);if(i&&Nn(s.overflowX)||o&&Nn(s.overflowY))return r}if(r.classList.contains(fi))return null;r=r.parentElement}return null}function mt(t){let e=ke(t);if(!e||!e.collapsed||!t.contains(e.startContainer))return;let n=gi(t);if(!n||typeof e.getBoundingClientRect!="function")return;let r=e.getBoundingClientRect();if(r.height===0)return;let i=n.getBoundingClientRect();if(n.scrollWidth>n.clientWidth){let o=i.left+n.clientLeft,s=o+n.clientWidth;r.right>s?n.scrollLeft+=r.right-s+Ne:r.left<o&&(n.scrollLeft-=o-r.left+Ne)}if(n.scrollHeight>n.clientHeight){let o=i.top+n.clientTop,s=o+n.clientHeight;r.bottom>s?n.scrollTop+=r.bottom-s+Ne:r.top<o&&(n.scrollTop-=o-r.top+Ne)}}var Hn='[contenteditable="false"]',gt="strong[data-param-id]",ie;function hi(){if(ie!==void 0)return ie;let t=globalThis.Intl.Segmenter;if(!t)return ie=null,null;try{ie=new t(void 0,{granularity:"grapheme"})}catch{ie=null}return ie??null}function Fe(t,e){let n=t;for(;n&&n!==e;){if(n.nodeType===Node.ELEMENT_NODE&&n.matches(Hn))return!0;n=n.parentNode}return!1}function He(t){return O(t).createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(e){return Fe(e,t)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function Be(t){let e=He(t),n="",r=e.nextNode();for(;r;)n+=r.data,r=e.nextNode();return n}function ht(t){let e=He(t),n=0,r=e.nextNode();for(;r;)n+=r.data.length,r=e.nextNode();return n}function _(t){let e=W(t);if(!e)return null;let n=e.node,r=e.offset;if(!t.contains(n))return null;if(n.nodeType===Node.ELEMENT_NODE){let i=n;if(Fe(i,t)&&i!==t)return null;let o=0;for(let s=0;s<r&&s<i.childNodes.length;s++)o+=bt(i.childNodes[s],t);return o+ft(i,t)}return n.nodeType!==Node.TEXT_NODE||Fe(n,t)?null:ft(n,t)+r}function bt(t,e){if(t.nodeType===Node.TEXT_NODE)return Fe(t,e)?0:t.data.length;if(t.nodeType!==Node.ELEMENT_NODE)return 0;let n=t;if(n.matches(Hn))return 0;let r=0;for(let i of Array.from(n.childNodes))r+=bt(i,e);return r}function ft(t,e){let n=He(e),r=0,i=n.nextNode();for(;i;){if(i===t||t.nodeType===Node.ELEMENT_NODE&&t.contains(i))return r;r+=i.data.length,i=n.nextNode()}return r}function A(t,e){let n=O(t),r=Math.max(0,Math.min(e,ht(t))),i=He(t),o=0,s=null,a=0,l=i.nextNode(),d=null;for(;l;){let c=l.data.length;if(r<o+c){s=l,a=r-o;break}if(r===o+c){let m=i.nextNode();m?(s=m,a=0):(s=l,a=c);break}o+=c,d=l,l=i.nextNode()}let u=n.createRange();if(s){let c=s.parentElement?.closest('strong[data-seg="completed"]');c&&c!==t&&t.contains(c)?a===0?u.setStartBefore(c):a===s.data.length?u.setStartAfter(c):u.setStart(s,a):u.setStart(s,a)}else d?u.setStart(d,d.data.length):u.setStart(t,0);u.collapse(!0),me(t,u.startContainer,u.startOffset)&&(bi(t,u,r),mt(t))}function Fn(t,e){if(!t||!e.contains(t))return null;let r=(t.nodeType===Node.ELEMENT_NODE?t:t.parentElement)?.closest(gt)??null;return r&&e.contains(r)?r:null}function bi(t,e,n){let r=Fn(W(t)?.node??null,t);if(r&&r!==Fn(e.startContainer,t)){t.dataset.aiaCaretEscapedChip=`${n}:${r.dataset.paramId}`;return}delete t.dataset.aiaCaretEscapedChip}function Bn(t,e){let n=t.dataset.aiaCaretEscapedChip;if(!n)return!1;let r=_(t);return r!==null&&n===`${r}:${e}`}function Wn(t){return z(t).activeElement===t}function St(t,e){if(!e||e.nodeType===void 0)return null;let n=e,i=(n.nodeType===Node.ELEMENT_NODE?n:n.parentElement)?.closest(gt);if(!i||!t.contains(i))return null;let o=W(t);return o&&!o.collapsed?null:i.dataset.paramId??null}function xt(t,e){let n=null;for(let s of t.querySelectorAll(gt))if(s.dataset.paramId===e){n=s;break}if(!n)return;let r=ft(n,t),i=r+bt(n,t),o=_(t);o!=null&&o>=r&&o<=i||A(t,r)}function yt(t){let e=_(t);return e==null?!1:e>=ht(t)}function vt(t,e){if(e<=0)return 0;let n=hi();if(!n)return e-1;let r=t.slice(0,e),i=0;for(let{index:o}of n.segment(r))o<e&&(i=o);return i}function J(t,e,n=[],r={}){let{rawQuery:i,completedParams:o}=R(t,e);return{query:t.trim(),raw_query:i,completed_params:pe(o,n),identified_params:ue(r.identifiedParams??[]),is_ready:r.isReady??!1,...r.customFields?{custom_fields:r.customFields}:{}}}function Et(t,e){return t instanceof HTMLTextAreaElement||t instanceof HTMLInputElement?t.selectionStart!=null&&t.selectionStart===t.value.length:t instanceof HTMLElement&&t.hasAttribute("data-aia-input")?yt(t):e?.caretOffset!=null?e.caretOffset>=e.text.length:!1}function Pt(t){return t instanceof HTMLElement&&t.hasAttribute("data-aia-input")?_(t):null}var We=class{constructor(e,n){this.store=e;this.ctx=n}handleKeyDown(e){let n=this.store.get(),{listboxId:r,getOnSubmit:i}=this.ctx,o=e.target instanceof Node?e.target:null,s=this.getEffectiveColumns(o),a=i(),l=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 d=this.ctx.getOptionsPosition()==="above";switch(e.key){case"ArrowDown":{let u=Et(e.target,n),c=!!n.editingParam;if(!u&&!c&&n.activeDropdownIndex<0)break;if(n.activeDropdownIndex<0){if(d)break;e.preventDefault();let h=P(n.activeFormatType)?this.dateEntryIndex(n,!1):l[0]??0;if(!n.isDropdownOpen&&n.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:h});break}if(l.length===0)return;this.store.set({activeDropdownIndex:h});break}if(e.preventDefault(),l.length===0)return;if(P(n.activeFormatType)){this.stepDateWeek(n,7);break}if(n.filteredOptions.length>0){let h=Math.floor((n.filteredOptions.length-1)/s);if(Math.floor(n.activeDropdownIndex/s)===h){this.store.set({activeDropdownIndex:-1});break}}let m=l.indexOf(n.activeDropdownIndex),f=m<l.length-1?m+1:0;this.store.set({activeDropdownIndex:l[f]});break}case"ArrowUp":{if(n.activeDropdownIndex<0){if(!d)break;let m=Et(e.target,n),f=!!n.editingParam;if(!m&&!f)break;e.preventDefault();let h=P(n.activeFormatType)?this.dateEntryIndex(n,!0):this.firstTappableInBottomRow(s)??l[0]??0;if(!n.isDropdownOpen&&n.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:h});break}if(l.length===0)return;this.store.set({activeDropdownIndex:h});break}if(l.length===0)break;if(e.preventDefault(),P(n.activeFormatType)){this.stepDateWeek(n,-7);break}if(n.activeDropdownIndex<s){this.store.set({activeDropdownIndex:-1});break}let u=l.indexOf(n.activeDropdownIndex),c=u>0?u-1:l.length-1;this.store.set({activeDropdownIndex:l[c]});break}case"ArrowRight":{if(n.activeDropdownIndex>=0){if(e.preventDefault(),P(n.activeFormatType)){this.stepDateDay(n,1);break}if(n.activeDropdownIndex%s<s-1){let m=n.activeDropdownIndex+1;m<n.filteredOptions.length&&n.filteredOptions[m]?.is_tappable&&this.store.set({activeDropdownIndex:m})}break}if(n.editingParam&&e.target instanceof HTMLElement&&n.editingTail!=null){e.preventDefault();let c=e.target.closest("[data-aia-input]")??e.target,m=n.editingTail;this.ctx.exitEditMode?.(),A(c,m);break}Et(e.target,n)&&n.actionableSuggestions.length>=1&&(e.preventDefault(),this.ctx.skipActivePill());break}case"ArrowLeft":{if(n.activeDropdownIndex>=0){if(e.preventDefault(),P(n.activeFormatType)){this.stepDateDay(n,-1);break}if(n.activeDropdownIndex%s>0){let u=n.activeDropdownIndex-1;u>=0&&n.filteredOptions[u]?.is_tappable&&this.store.set({activeDropdownIndex:u});break}if(!n.editingParam&&this.ctx.startEditingParamAtCaret){let u=Pt(e.target);u!=null&&this.ctx.startEditingParamAtCaret(u)}break}if(n.editingParam&&e.target instanceof HTMLElement&&n.editingAnchor!=null){e.preventDefault();let u=e.target.closest("[data-aia-input]")??e.target,c=n.editingAnchor;this.ctx.exitEditMode?.(),A(u,c);break}if(this.ctx.startEditingParamAtCaret){let u=Pt(e.target);u!=null&&this.ctx.startEditingParamAtCaret(u)&&e.preventDefault()}break}case"Backspace":{if(n.editingParam||!this.ctx.removeParamAtCaret)break;let u=Pt(e.target);if(u==null)break;this.ctx.removeParamAtCaret(u)&&e.preventDefault();break}case"Enter":{e.preventDefault(),n.activeDropdownIndex>=0&&n.filteredOptions[n.activeDropdownIndex]?.is_tappable?this.clickOrSelect(n.activeDropdownIndex,n.filteredOptions,r,o):a&&a(J(n.text,n.completedParams,n.skippedParams,{identifiedParams:n.identifiedParams,isReady:n.isReady,customFields:n.customFields}))&&this.ctx.afterSubmit?.();break}case"Tab":{let u=n.filteredOptions.map((f,h)=>f.is_tappable?h:-1).filter(f=>f!==-1);if(u.length===0)break;if(!n.isDropdownOpen){if(n.actionableSuggestions.length===0)break;e.preventDefault();let f=e.shiftKey?u[u.length-1]:u[0];this.store.set({pillTapped:!0,activeDropdownIndex:f});break}e.preventDefault();let c=u.indexOf(n.activeDropdownIndex),m;if(c<0)m=e.shiftKey?u.length-1:0;else{let f=e.shiftKey?-1:1;m=(c+f+u.length)%u.length}this.store.set({activeDropdownIndex:u[m]});break}case"Escape":{if(n.dateRangeStart){this.store.set({pendingRangeStart:null});break}if(n.editingIdentified){this.ctx.exitEditingIdentified?.(),this.store.set({activeDropdownIndex:-1});break}if(n.editingParam&&e.target instanceof HTMLElement&&n.editingTail!=null){let u=e.target.closest("[data-aia-input]")??e.target,c=n.editingTail;this.ctx.exitEditMode?.(),A(u,c)}this.store.set({activeDropdownIndex:-1});break}}}firstTappableInBottomRow(e){let n=this.store.get();if(n.filteredOptions.length===0)return null;let i=Math.floor((n.filteredOptions.length-1)/e)*e;for(let o=i;o<n.filteredOptions.length;o++)if(n.filteredOptions[o]?.is_tappable)return o;return null}dateEntryIndex(e,n){let r=k(new Date),i=e.filteredOptions.findIndex(s=>H(s)===r);if(i>=0)return i;let o=e.filteredOptions.map((s,a)=>s.is_tappable?a:-1).filter(s=>s!==-1);return(n?o[o.length-1]:o[0])??0}stepDateDay(e,n){for(let r=e.activeDropdownIndex+n;r>=0&&r<e.filteredOptions.length;r+=n)if(e.filteredOptions[r]?.is_tappable){this.store.set({activeDropdownIndex:r});return}}stepDateWeek(e,n){let r=e.activeDropdownIndex+n;this.store.set({activeDropdownIndex:e.filteredOptions[r]?.is_tappable?r:-1})}getTappableIndices(e){let r=this.store.get().filteredOptions.map((o,s)=>o.is_tappable?s:-1).filter(o=>o!==-1),i=Array.from({length:e},()=>[]);for(let o of r)i[o%e].push(o);return i.flat()}getEffectiveColumns(e){let n=_e(e,this.ctx.listboxId);if(!n)return this.ctx.columns;let i=_e(e,`${this.ctx.listboxId}-option-0`)?.parentElement??null;for(;i;){let o=getComputedStyle(i).gridTemplateColumns;if(o&&o!=="none"){let s=o.split(" ").filter(Boolean).length;if(s>0)return s}if(i===n)break;i=i.parentElement}return this.ctx.columns}clickOrSelect(e,n,r,i){let o=_e(i,`${r}-option-${e}`);o?o.click():this.ctx.selectOption(n[e])}};var qe=class{constructor(e,n,r={}){this.store=e;this.getOverrides=n;this.callbacks=r;this.unsubscribe=null;this.current=null;this.version=0;this.lastMiss=null;this.hasLoggedError=!1}start(){this.unsubscribe=this.store.subscribe(e=>this.sync(e)),this.sync(this.store.get())}dispose(){this.unsubscribe?.(),this.unsubscribe=null,this.cancel(),this.current=null}reset(){this.cancel(),this.current=null,this.lastMiss=null}refresh(){this.reset(),this.sync(this.store.get())}hasOverride(e){return!!this.getOverrides()?.[e]}owns(e,n){return this.hasOverride(e)&&!this.missCovers(e,n)}tick(e,n){let r=this.resolveTarget(e);if(!r||this.missCovers(r.parameter,r.query))return"no";let i=this.current;if(i&&i.key===r.key){if(i.query===r.query)return"owns";let o=Math.abs(r.query.length-i.query.length),s=r.query.length<i.query.length;if(n>1&&!s&&o<n)return"owns"}return this.ask(r),"asked"}sync(e){let n=this.resolveTarget(e);if(!n){this.current&&(this.cancel(),this.current=null),e.optionSearch&&this.store.set({optionSearch:null});return}this.current&&this.current.key===n.key||this.ask(n)}resolveTarget(e){if(P(e.activeFormatType)||e.editingIdentified)return null;let n=e.editingParam;if(n&&e.editingAnchor!=null)return this.hasOverride(n.suggestionParameter)?{mode:"edit",key:n.id,parameter:n.suggestionParameter,suggestion:{parameter:n.suggestionParameter,text:n.suggestionPlaceholder,required:!0,options:n.options},query:e.optionQuery}:null;let r=e.actionableSuggestions[0];return!r||!this.hasOverride(r.parameter)?null:{mode:"pill",key:r,parameter:r.parameter,suggestion:r,query:e.optionQuery}}missCovers(e,n){return this.lastMiss!=null&&this.lastMiss.parameter===e&&this.lastMiss.query===n}ask(e){this.cancel();let n=this.getOverrides()?.[e.parameter],r=++this.version;if(!n||this.missCovers(e.parameter,e.query)){this.current={key:e.key,parameter:e.parameter,query:e.query,abort:null},this.setSearch(e,"done");return}let i=new AbortController;this.current={key:e.key,parameter:e.parameter,query:e.query,abort:i};let o;try{o=n(e.query,i.signal,e.suggestion)}catch(s){this.logOnce(s),this.commit(e,[],r);return}if(Array.isArray(o)){this.commit(e,o,r);return}this.setSearch(e,"loading"),this.await(e,o,i.signal,r)}async await(e,n,r,i){let o;try{let s=await n;if(r.aborted||i!==this.version)return;o=Array.isArray(s)?s:[]}catch(s){if(r.aborted||i!==this.version||Si(s))return;this.logOnce(s),o=[]}this.commit(e,o,i)}commit(e,n,r){if(r!==this.version)return;let i=this.resolveTarget(this.store.get());if(!i||i.key!==e.key)return;n.length===0?this.lastMiss={parameter:e.parameter,query:e.query}:this.lastMiss?.parameter===e.parameter&&(this.lastMiss=null);let o={parameter:e.parameter,query:e.query,status:"done"};if(e.mode==="edit")this.store.set(s=>({editingParam:s.editingParam&&s.editingParam.id===e.key?{...s.editingParam,options:n}:s.editingParam,optionSearch:o}));else{let s={...e.suggestion,options:n};this.current&&this.current.key===e.key&&(this.current.key=s),this.store.set(a=>({suggestions:a.suggestions.map(l=>l===e.suggestion?s:l),optionSearch:o}))}n.length===0?this.callbacks.onMiss?.(e.mode,e.query):this.callbacks.onAnswer?.(e.mode,e.query)}setSearch(e,n){let r=this.store.get().optionSearch;r&&r.parameter===e.parameter&&r.query===e.query&&r.status===n||this.store.set({optionSearch:{parameter:e.parameter,query:e.query,status:n}})}cancel(){this.current?.abort?.abort(),this.version++}logOnce(e){this.hasLoggedError||(this.hasLoggedError=!0,console.warn("[AIAutocomplete] an optionOverrides entry threw or rejected \u2014 treated as no options. Later failures on this instance are not logged.",e))}};function Si(t){return t instanceof Error&&t.name==="AbortError"}var $e=class{constructor(e,n={}){this.store=e;this.callbacks=n}setActivePill(e){let n=this.store.get(),r=n.suggestions.filter(d=>d.parameter!=="placeholder");if(e<0||e>=r.length)return;let i=r[e],o=r.filter((d,u)=>u!==e),s=n.suggestions.filter(d=>d.parameter==="placeholder");if(this.callbacks.onPillSelected){let{rawQuery:d}=R(n.text,n.completedParams);this.callbacks.onPillSelected({rawQuery:d,selectedPill:i.text,otherPills:o.map(u=>u.text)})}let a=[...s,i,...o],l=this.store.peek({suggestions:a}).filteredOptions.findIndex(d=>d.is_tappable);this.store.set({suggestions:a,pillTapped:!0,activeDropdownIndex:l})}removeLastParam(){this.store.get().completedParams.length!==0&&this.store.set(n=>({completedParams:n.completedParams.slice(0,-1),activeDropdownIndex:-1}))}};var $n="/products/",qn="https://relative.invalid";function xi(t){if(!t)return;let e;try{e=new URL(t,`${qn}/`)}catch{return}if(!(e.protocol!=="http:"&&e.protocol!=="https:"))return t.startsWith("/")?e.origin===qn?t:void 0:/^https?:\/\//i.test(t)?t:void 0}function Gn(t){let e=xi(t.item_url)??yi(t);return{id:t.source_id,title:t.title,...e&&{url:e},imageUrl:t.image_url||null,...t.price&&{price:t.price},...t.vendor&&{vendor:t.vendor},...typeof t.available=="boolean"&&{available:t.available}}}function yi(t){if(!t.handle)return;let e=`${$n}${encodeURIComponent(t.handle)}`;return t.variant_id?`${e}?variant=${encodeURIComponent(t.variant_id)}`:e}function wt(t){return(t?.items.matched??[]).map(Gn)}var Ge=class{constructor(e,n,r=()=>!0){this.store=e;this.getConfig=n;this.isEnabled=r;this.hasLoggedError=!1}forResponse(e){if(!this.isEnabled())return[];if(!this.getConfig())return wt(e)}async run(e,n,r){if(!this.isEnabled())return;let i=this.getConfig();if(!i)return;if(e.trim().length===0){this.clear(r);return}let o=()=>n.aborted||!r()||!this.owns(i);try{let s=await i.fetch(e,n);if(o())return;let a=i.transform(s),l=Array.isArray(a)?a:[],d=i.limit!=null?l.slice(0,i.limit):l;if(o())return;this.commit(d)}catch(s){if(n.aborted||vi(s)||(this.logOnce(s),o()))return;this.clear(r)}}owns(e){return this.isEnabled()&&this.getConfig()===e}resync(){let e=this.forResponse(this.store.get().customFields);this.commit(e??[])}clear(e){e()&&this.commit([])}commit(e){e.length===0&&this.store.get().products.length===0||this.store.set({products:e})}logOnce(e){this.hasLoggedError||(this.hasLoggedError=!0,console.warn("[AIAutocomplete] products.fetch/transform failed \u2014 the product strip is hidden. Later failures on this instance are not logged.",e))}};function vi(t){return t instanceof Error&&t.name==="AbortError"}function Ei(t){return t.replace(/(\d+)(?:st|nd|rd|th)\b/g,"$1")}function Vn(t){let e=t.toLowerCase().replace(/\.$/,"");return e.length<3?-1:ne.findIndex(n=>n.toLowerCase().startsWith(e))}function Pi(t,e,n){let r=new Date(n.getFullYear(),t,e);if(r.getMonth()!==t||r.getDate()!==e)return null;let i=new Date(n.getFullYear(),n.getMonth(),n.getDate());if(r>=i)return r;let o=new Date(n.getFullYear()+1,t,e);return o.getMonth()===t&&o.getDate()===e?o:null}function Un(t,e,n){let r=new Date(t,e,n);return r.getMonth()===e&&r.getDate()===n?r:null}function fe(t,e={}){if(!t)return null;let n=e.today??new Date,r=Ei(t.trim().toLowerCase()).replace(/\s+/g," "),i=/^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(r);if(i){let l=Un(Number(i[1]),Number(i[2])-1,Number(i[3]));return l?k(l):null}let o=/^([a-z]+)\.? (\d{1,2})(?:,? (\d{4}))?$/.exec(r);if(o){let l=Vn(o[1]);if(l>=0)return Ve(l,Number(o[2]),o[3],n)}let s=/^(\d{1,2}) (?:of )?([a-z]+)\.?(?:,? (\d{4}))?$/.exec(r);if(s){let l=Vn(s[2]);if(l>=0)return Ve(l,Number(s[1]),s[3],n)}let a=/^(\d{1,2})[/\-.](\d{1,2})(?:[/\-.](\d{2,4}))?$/.exec(r);if(a){let l=Number(a[1]),d=Number(a[2]);return l>12&&d<=12?Ve(d-1,l,a[3],n):d>12&&l<=12?Ve(l-1,d,a[3],n):null}return null}function Ve(t,e,n,r){if(n){if(n.length!==4)return null;let o=Un(Number(n),t,e);return o?k(o):null}let i=Pi(t,e,r);return i?k(i):null}function Tt(t,e={}){let n=t.isoDate;return typeof n=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(n)?n:fe(t.text,e)}var Yn=" - ",It="aiaDateRangeStart",Ot="aiaDateRangeEnd";function ge(t,e){return t<=e?{start:t,end:e}:{start:e,end:t}}var Ct=/^\d{4}-\d{2}-\d{2}$/;function Kn(t){if(!Ct.test(t))return null;let[e,n,r]=t.split("-").map(Number),i=new Date(e,n-1,r);return i.getMonth()===n-1&&i.getDate()===r?i:null}var wi=/\s+(?:to|through|thru|until|til|till)\s+/g,Ti=/[-–—]/g;function Ci(t){let e=[];for(let n of[wi,Ti]){n.lastIndex=0;let r=n.exec(t);for(;r!==null;)e.push([t.slice(0,r.index),t.slice(r.index+r[0].length)]),r=n.exec(t)}return e}function Ue(t,e={}){if(!t)return null;let n=new Set,r=null;for(let[i,o]of Ci(t.trim())){let s=fe(i.trim(),e);if(!s)continue;let a=fe(o.trim(),e);!a||a<s||(n.add(`${s}|${a}`),r={start:s,end:a})}return n.size===1?r:null}function Qn(t){let e=Kn(t.start),n=Kn(t.end);return!e||!n?"":t.start===t.end?re(e):`${re(e)}${Yn}${re(n)}`}function Xn(t,e){let n=ge(t,e);return{text:Qn(n),is_tappable:!0,kind:null,metadata:{[It]:n.start,[Ot]:n.end}}}function he(t,e={}){let n=t?.metadata?.[It],r=t?.metadata?.[Ot];return typeof n=="string"&&typeof r=="string"&&Ct.test(n)&&Ct.test(r)?ge(n,r):Ue(t?.text,e)}var Ke="(max-width: 768px)";var Ii="var(--aia-option-row-height, 37px)",Oi="var(--aia-grid-scroll-top, 0px) + var(--aia-grid-scroll-bottom, 0px)";function jn(t,e){return e?At(1,Math.min(t,5)):At(1,Math.min(t,4))}function At(t,e){return{cols:t,rows:e,maxHeight:`calc(${e} * ${Ii} + ${Oi})`}}function Rt(t,e){return!e&&t>=5}function Mt(t,e,n,r){if(!(!e&&t>=5&&Ai(n,r))){let s=jn(t,e);return{...s,template:Lt(s.cols),scrollHintIndices:!e&&t>s.rows?[s.rows-1]:[]}}let o=6;return{...At(2,3),template:Lt(2),scrollHintIndices:t>o?[o-2,o-1]:[]}}function Ai(t,e){return!t||t.length===0||e==null||e<=0||t.some(r=>r<=0)?!1:Math.ceil(Math.max(...t))*2<=e}function Dt(t){if(typeof document>"u")return null;let e=Array.from(t.querySelectorAll("[data-aia-option]"));if(e.length===0)return null;let n=document.createElement("div");n.style.cssText="position:absolute;visibility:hidden;left:-9999px;top:0;";for(let s of e){let a=s.cloneNode(!0);a.removeAttribute("id"),a.removeAttribute("role"),a.removeAttribute("aria-selected"),a.style.whiteSpace="nowrap",a.style.width="max-content",n.appendChild(a)}t.appendChild(n);let r=Array.from(n.children).map(s=>s.offsetWidth);n.remove();let i=getComputedStyle(t),o=t.clientWidth-(Number.parseFloat(i.paddingLeft)||0)-(Number.parseFloat(i.paddingRight)||0)-(Number.parseFloat(i.columnGap)||0);return{rowWidths:r,gridWidth:o}}function Lt(t){return Array.from({length:t},()=>"minmax(0,1fr)").join(" ")}function kt(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia(Ke).matches}function _t(t,e){return!t||t.length!==e.length?!1:t.every((n,r)=>n.text===e[r].text)}function zn(t,e){let n=e.dropdownTrigger??"auto",r=e.closeDropdownOnBlur??!0,s=t.filteredOptionsLength>0||t.activePillHasNoOptions||t.hasProducts;if(t.inEditMode){let a=r?t.isFocused:!0;return s&&a}if(n==="auto"){let a=r?t.isFocused:!0,l=t.text.replace(/\s+$/,"").length,d=t.caretOffset==null||t.caretOffset>=l;return(s||t.isLoading)&&a&&d}return n==="manual"?(s||t.isLoading)&&t.pillTapped:!1}function be(t){if(t.editingIdentified){let{parameter:n,anchor:r}=t.editingIdentified;return`identified:${n}@${r}`}return t.editingParam!=null&&t.editingAnchor!=null?`edit:${t.editingParam?.id}`:`pill:${t.actionableSuggestions[0]?.parameter??""}`}function Jn(t){if(!t)return at();let[e,n]=t.split("-").map(Number);return{year:e,month:n-1}}function Li(t){let e=De(t);return e?Mn(e):at()}function Zn(t,e){let n=wn(t.text,t.completedParams,t.identifiedParams),r=t.suggestions.filter(C=>C.parameter!=="placeholder"),i=r[0],o=t.suggestions.filter(C=>C.parameter==="placeholder").map(C=>C.text).join(" "),s=B(t.text,Math.min(t.filterBase,t.text.length),o),l=s===0&&Oe(t.text,t.completedParams.length,o)?"":Q(t.text,s,t.filterInProgress),d=i?.options??[],u=t.editingParam!=null&&t.editingAnchor!=null,c,m,f,h;if(u&&t.editingParam&&t.editingAnchor!=null){let C=t.editingParam.id,ee=t.completedParams.some(Jr=>Jr.id===C),de=t.caretOffset??t.editingAnchor,ln=ee?"":t.text.slice(t.editingAnchor,de);m=ln.trim(),f=t.editingParam.options,h=t.editingParam.suggestionParameter,c=X(t.editingParam.options,ln)}else m=l.trim(),f=d,h=i?.parameter,c=X(d,l);let x=t.optionSearch,y=x!=null&&h!=null&&x.parameter===h;y&&x.status==="done"&&x.query===m&&(c=f);let g=y&&x.status==="loading",p=e.showNonTappableOptions===!1;p&&(c=c.filter(C=>C.is_tappable));let b=t.editingIdentified,S=u?t.editingParam&&{type:t.editingParam.suggestionValueType}:i,E=b?b.format:Y(S),v=u&&E==="date-range"?he(t.editingParam):null,w=null,L=null;if(P(E)){let C=be({...t,actionableSuggestions:r}),ee=t.dateViewMonth;w=ee&&ee.key===C?{year:ee.year,month:ee.month}:b?Jn(b.iso):v?Jn(v.start):Li(t.editingParam?.text),c=dt(w);let de=t.pendingRangeStart;E==="date-range"&&de&&de.key===C&&(L=de.iso)}let T=C=>p?C.is_tappable:!0,I;if(u){let C=t.editingParam?.options??[];I=t.editingParam!=null&&C.filter(T).length===0}else I=i!=null&&d.filter(T).length===0;let K=zn({inEditMode:u||b!=null,filteredOptionsLength:c.length,isFocused:t.isFocused,text:t.text,caretOffset:t.caretOffset,isLoading:t.isLoading||g,pillTapped:t.pillTapped,activePillHasNoOptions:I,hasProducts:t.products.length>0},{dropdownTrigger:e.dropdownTrigger,closeDropdownOnBlur:e.closeDropdownOnBlur}),M=K&&t.activeDropdownIndex>=0&&!!c[t.activeDropdownIndex]?.is_tappable,D=t.skeletonOptions!==null&&t.skeletonRequested&&!t.isLoading&&!t.editingParam&&!t.inSelectionAnimation,Z=t.isLoading&&!t.editingParam&&!t.inSelectionAnimation||g||D,an=Z&&t.skeletonOptions!==null,jr=an&&t.skeletonOptions?t.skeletonOptions:c,zr=an?t.skeletonSuggestion:null;return{segments:n,actionableSuggestions:r,filteredOptions:c,dropdownLoading:Z,dropdownOptions:jr,dropdownSuggestion:zr,skeletonExiting:D,activeFormatType:E,dateView:w,dateRangeStart:L,placeholderText:o,optionQuery:m,isSearchingOptions:g,isDropdownOpen:K,isActivePillSelected:M}}function Ye(t){return t.mode==="fresh"?Ri(t):Mi(t)}function Ri(t){let{text:e,completedParams:n,suggestions:r,filterBase:i,filterInProgress:o}=t,a=r.filter(S=>S.parameter!=="placeholder")[0];if(!a?.options)return null;let l=r.filter(S=>S.parameter==="placeholder").map(S=>S.text).join(" "),d=B(e,i,l),u=Q(e,d,o),c=te(a.options,u);if(!c)return null;let m=c.text.toLowerCase(),f=e.toLowerCase().lastIndexOf(m),h=f>=0?f:Math.max(0,e.length-c.text.length),x=h+c.text.length,y=e.slice(h,x),p=x<e.length&&e[x]===" "?x+1:x,b={id:crypto.randomUUID(),placeholder:"",parameter:F(c,a.parameter),text:y,value:c.value,kind:c.kind,suggestionParameter:a.parameter,suggestionValueType:a.type,suggestionPlaceholder:a.text,options:a.options??[],metadata:c.metadata,icon:c.icon,icon_svg:c.icon_svg,image_url:c.image_url};return{patch:{text:e,completedParams:[...n,b],suggestions:r.filter(S=>S!==a),filterBase:p,newParamId:b.id,caretOffset:p,activeDropdownIndex:-1},caretPos:p}}function Mi(t){let{text:e,completedParams:n,editingParam:r,editingAnchor:i,editingTail:o}=t;if(n.some(b=>b.id===r.id))return null;let s=e.slice(i,o),a=te(r.options,s);if(!a)return null;let l=a.text.toLowerCase(),d=s.toLowerCase().lastIndexOf(l),u=i+Math.max(0,d),c=u+a.text.length,m=e.slice(u,c),f=c<e.length&&e[c]===" "?c+1:c,h=e.length,x={id:crypto.randomUUID(),placeholder:"",parameter:F(a,r.suggestionParameter),text:m,value:a.value,kind:a.kind,suggestionParameter:r.suggestionParameter,suggestionValueType:r.suggestionValueType,suggestionPlaceholder:r.suggestionPlaceholder,options:r.options,metadata:a.metadata,icon:a.icon,icon_svg:a.icon_svg,image_url:a.image_url},y=n.length,g=0;for(let b=0;b<n.length;b++){let S=N(e,n[b].text,g);if(S!==-1){if(S>=f){y=b;break}g=S+n[b].text.length}}let p=[...n];return p.splice(y,0,x),{patch:{text:e,completedParams:p,newParamId:x.id,filterBase:h,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:h,activeDropdownIndex:-1},caretPos:h}}var Di=6e4;function ki(t){return typeof TextEncoder>"u"?t.length*3:new TextEncoder().encode(t).length}function _i(t){return(t??Pe).replace(/\/suggest(\?|#|$)/,"/telemetry/events$1")}async function Ni(t){return ce(t)?`Bearer ${await we(t).getToken()}`:Ce(t)}async function er(t){try{let e=_i(t.apiConfig?.endpoint),n=Te(t.apiConfig),r=await Ni(t.apiConfig);r&&(n.Authorization=r);let i=JSON.stringify({source:t.source,session_id:t.sessionId,...t.visitorId&&{visitor_id:t.visitorId},...t.requestId&&{request_id:t.requestId},type:t.type,at:new Date().toISOString(),query_data:t.queryData});await fetch(e,{method:"POST",headers:n,body:i,...t.keepalive&&ki(i)<=Di&&{keepalive:!0}})}catch{}}function oe(t,e){let n=t.findIndex(r=>r.text===e);return n>=0?n+1:null}function tr(t,e){let n=t.actionableSuggestions[0];if(!n)return null;let r=t.filterBase,i=t.text.slice(0,r),o=i.length===0&&t.text.length===0,s=i.length===0&&t.text.length>0&&t.placeholderText.length>0&&t.placeholderText.toLowerCase().startsWith(t.text.toLowerCase());(o||s)&&t.placeholderText&&(i=`${t.placeholderText} `);let a=Math.min(En(t.text,t.completedParams),i.length),l=hn(i.slice(a),e.text);l>0&&(i=i.slice(0,i.length-l));let d=i.length>0&&i[i.length-1]!==" ",u=`${i}${d?" ":""}${e.text} `,c=(o||s)&&u.length>0?u[0].toUpperCase()+u.slice(1):u,m=c.toLowerCase().lastIndexOf(e.text.toLowerCase()),f=m>=0?c.slice(m,m+e.text.length):e.text,h={id:crypto.randomUUID(),placeholder:"",parameter:F(e,n.parameter),text:f,value:e.value,kind:e.kind,suggestionParameter:n.parameter,suggestionValueType:n.type,suggestionPlaceholder:n.text,options:n.options??[],metadata:e.metadata,icon:e.icon,icon_svg:e.icon_svg,image_url:e.image_url},x=t.actionableSuggestions.length-1;return{patch:{text:c,filterBase:c.length,completedParams:[...t.completedParams,h],newParamId:h.id,caretOffset:c.length,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:!0,inSelectionAnimation:!0,pendingSpan:null},telemetry:{selectedOption:e.text,otherOptions:t.filteredOptions.filter(y=>y.text!==e.text).map(y=>y.text),key:n.parameter,position:oe(n.options??[],e.text)},consumedSuggestion:n,remainingActionable:x}}function Qe(t){let e=P(t.activeFormatType)||t.filteredOptions.length===0?null:t.filteredOptions,n=t.editingParam,r=n?{parameter:n.suggestionParameter,text:n.suggestionPlaceholder,required:!0,options:n.options}:t.actionableSuggestions[0]??null;return{skeletonOptions:e,skeletonSuggestion:e?r:null,skeletonRequested:!1}}function Xe(t,e,n){let r=t.slice(0,e),i=t.slice(n),o=(r===""||r.endsWith(" "))&&i.startsWith(" ");return o&&(i=i.slice(1)),{text:r+i,removed:n-e+(o?1:0)}}var je=class{constructor(e){this.deps=e}start(e){let n=this.deps.store.get();if(n.editingParam?.id===e)return;let r=n.completedParams.find(s=>s.id===e);if(!r)return;let i=0,o=-1;for(let s of n.completedParams){let a=N(n.text,s.text,i);if(a!==-1){if(s.id===e){o=a;break}i=a+s.text.length}}o<0||this.deps.store.set({editingParam:r,editingAnchor:o,editingTail:o+r.text.length,caretOffset:o+r.text.length,activeDropdownIndex:-1,editingIdentified:null})}exit(){this.deps.store.get().editingParam&&this.deps.store.set({editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1})}replaceRange(e){let n=this.deps.store.get(),r=n.editingParam,i=n.editingAnchor,o=n.editingTail;if(!r||i==null||o==null||!n.completedParams.some(l=>l.id===r.id))return!1;let{text:s}=e===""?Xe(n.text,i,o):{text:n.text.slice(0,i)+e+n.text.slice(o)},a=i+e.length;return this.deps.store.set(l=>({text:s,completedParams:l.completedParams.filter(d=>d.id!==r.id),editingTail:a,caretOffset:a,activeDropdownIndex:-1})),this.deps.scheduleSetCursor(a),this.promoteIfExact(),!0}caretAfterInput(e){let n=this.deps.store.get(),r={caretOffset:e};n.editingParam&&n.editingAnchor!=null&&e!=null&&(e<n.editingAnchor?(r.editingParam=null,r.editingAnchor=null,r.editingTail=null,r.activeDropdownIndex=-1):n.editingTail!=null&&(r.editingTail=Math.max(n.editingTail,e))),this.deps.store.set(r),this.promoteIfExact()}caretMove(e){let n=this.deps.store.get();if(n.editingParam&&n.editingAnchor!=null&&n.editingTail!=null&&e!=null&&(e<n.editingAnchor||e>n.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 n=this.deps.store.get(),r=n.editingParam,i=n.editingAnchor,o=n.editingTail;if(!r||i==null||o==null)return;this.deps.fireTelemetry("option",{raw_query:R(n.text,n.completedParams).rawQuery,selected_option:e.text,other_options:r.options.filter(g=>g.text!==e.text).map(g=>g.text),key:r.suggestionParameter,position:oe(r.options,e.text)});let s=n.text.slice(0,i),a=n.text.slice(o),l=i===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,u=a.length===0||a[0]!==" "?`${l} `:l,c=s+u+a,m=c.length,f={id:crypto.randomUUID(),placeholder:"",parameter:F(e,r.suggestionParameter),text:l,value:e.value,kind:e.kind,suggestionParameter:r.suggestionParameter,suggestionValueType:r.suggestionValueType,suggestionPlaceholder:r.suggestionPlaceholder,options:r.options,metadata:e.metadata,icon:e.icon,icon_svg:e.icon_svg,image_url:e.image_url},h=n.completedParams.findIndex(g=>g.id===r.id),x=n.completedParams.filter(g=>g.id!==r.id),y=h>=0?Math.min(h,x.length):x.length;x.splice(y,0,f),this.deps.store.set({text:c,completedParams:x,newParamId:f.id,filterBase:m,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:m,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0,...Qe(n)}),this.deps.startSelectionAnimationTimer(),this.deps.scheduleSetCursor(m),this.deps.fetchNow()}promoteIfExact(){let e=this.deps.store.get();if(!e.editingParam||e.editingAnchor==null||e.editingTail==null)return;let n=Ye({mode:"edit",text:e.text,completedParams:e.completedParams,editingParam:e.editingParam,editingAnchor:e.editingAnchor,editingTail:e.editingTail});n&&(this.deps.store.set(n.patch),this.deps.scheduleSetCursor(n.caretPos))}};var Fi=33,Hi=70,Bi=120,Wi=50,se="data-aia-placeholder-leaving",ae=new WeakMap;function ze(t){t.timer!==null&&(clearTimeout(t.timer),t.timer=null)}function qi(t){return t.closest('[data-animations="off"]')?!0:!!t.ownerDocument?.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches}function rr(t,e,n){e.shown=n,t.dataset.placeholder=e.target.slice(0,n)}function ir(t,e){if(e.timer=null,!t.isConnected||e.shown>=e.target.length||(rr(t,e,e.shown+1),e.shown>=e.target.length))return;let n=e.target[e.shown-1],r=n===" "||n==="-"?70:0;e.timer=setTimeout(()=>ir(t,e),33+r)}function nr(t,e){rr(t,e,0),e.timer=setTimeout(()=>ir(t,e),33)}function or(t,e){let n=ae.get(t);if(e===""){n&&(ze(n),ae.delete(t)),t.removeAttribute(se),delete t.dataset.placeholder;return}if(n?.target===e)return;if(qi(t)){n&&ze(n),t.removeAttribute(se),ae.set(t,{target:e,shown:e.length,timer:null}),t.dataset.placeholder=e;return}let r={target:e,shown:0,timer:null},i=n&&n.shown>0?n:null;if(n&&ze(n),ae.set(t,r),i){t.setAttribute(se,""),r.timer=setTimeout(()=>{r.timer=null,t.removeAttribute(se),t.isConnected&&nr(t,r)},170);return}t.removeAttribute(se),nr(t,r)}function sr(t){let e=ae.get(t);e&&(ze(e),ae.delete(t))}var ar="https://ai-autocomplete.com";function Nt(t=ar){try{if(typeof window>"u"||!window.location)return t;let e=window.location.hostname;if(!e)return t;let n=new URL(t);return n.searchParams.set("utm_source",e),n.toString()}catch{return t}}function Ft(t,e){return t?{key:"enter",hint:"to proceed"}:e?{key:"tab",hint:"to select"}:{key:"\u2192",hint:"to skip"}}function Ht(t){let e=s=>{s.ctrlKey||lr(s.target,t,s.deltaX,s.deltaY)||s.preventDefault()},n=0,r=0,i=s=>{let a=s.touches[0];a&&(n=a.clientX,r=a.clientY)},o=s=>{if(s.touches.length!==1)return;let a=s.touches[0],l=n-a.clientX,d=r-a.clientY;n=a.clientX,r=a.clientY,s.cancelable&&!lr(s.target,t,l,d)&&s.preventDefault()};return t.addEventListener("wheel",e,{passive:!1}),t.addEventListener("touchstart",i,{passive:!0}),t.addEventListener("touchmove",o,{passive:!1}),()=>{t.removeEventListener("wheel",e),t.removeEventListener("touchstart",i),t.removeEventListener("touchmove",o)}}function lr(t,e,n,r){let i=t instanceof Element?t:null;for(;i;){if(r!==0&&$i(i,r)||n!==0&&Gi(i,n))return!0;if(i===e)break;i=i.parentElement}return!1}var dr=/^(auto|scroll|overlay)$/;function $i(t,e){return t.scrollHeight<=t.clientHeight||!dr.test(getComputedStyle(t).overflowY)?!1:e>0?t.scrollTop+t.clientHeight<t.scrollHeight-1:t.scrollTop>0}function Gi(t,e){if(t.scrollWidth<=t.clientWidth)return!1;let n=getComputedStyle(t);if(!dr.test(n.overflowX))return!1;let r=Math.abs(t.scrollLeft),i=t.scrollWidth-t.clientWidth;return(n.direction==="rtl"?e<0:e>0)?r<i-1:r>0}var cr=new WeakMap,ur=new WeakSet;function q(t,e,n){if(cr.set(t,n),ur.has(t))return;ur.add(t);let r=()=>cr.get(t),i=o=>{if(!(o instanceof Element))return null;let s=o.closest(e.itemSelector);return s&&t.contains(s)?s:null};e.onClick&&t.addEventListener("click",o=>{let s=i(o.target);s&&e.onClick?.(s,r(),o)}),e.onEnter&&t.addEventListener("mouseenter",o=>{let s=o.target;s instanceof HTMLElement&&s.matches(e.itemSelector)&&e.onEnter?.(s,r())},!0),e.onLeave&&t.addEventListener("mouseleave",o=>{let s=o.target;s instanceof HTMLElement&&s.matches(e.itemSelector)&&e.onLeave?.(s,r())},!0),e.preventMousedown&&t.addEventListener("mousedown",o=>o.preventDefault())}function $(t){return Number.parseInt(t.dataset.aiaIndex??"-1",10)}function G(t){t.offsetWidth}var Vi={selectedIso:null,selectedRange:null,rangeStart:null};function Se(t){if(!P(t.activeFormatType))return Vi;let e=t.editingIdentified;if(e){let{iso:r,isoEnd:i}=e;return{selectedIso:i?null:r,selectedRange:r&&i?ge(r,i):null,rangeStart:t.dateRangeStart}}let n=he(t.editingParam);return{selectedIso:n?null:ct(t.editingParam?.text),selectedRange:n,rangeStart:t.dateRangeStart}}function Bt(t){return t.pendingStart?ge(t.pendingStart,t.highlightedIso??t.pendingStart):t.selected}function Wt(t,e){if(t==null)return{selected:!1,inRange:!1};let{selectedIso:n,range:r}=e,i=t===n||r!=null&&(t===r.start||t===r.end),o=r!=null&&t>r.start&&t<r.end;return{selected:i,inRange:o}}var pr="data-aia-key";function V(t,e,n){let r=new Map;for(let s of Array.from(t.children)){let a=s.getAttribute(pr);a!=null&&r.set(a,s)}let i=new Set,o=[];for(let s=0;s<e.length;s++){let a=e[s],l=n.keyOf(a,s);i.add(l);let d=r.get(l);d||(d=n.create(a,s),d.setAttribute(pr,l)),n.update?.(d,a,s),t.children[s]!==d&&t.insertBefore(d,t.children[s]??null),o.push(d)}for(let[s,a]of r)i.has(s)||a.remove();return o}function mr(t,e){if(!e.interactive)return null;let n=e.options[$(t)];return n?.is_tappable?n:null}var Ui={itemSelector:"[data-aia-date-cell], [data-aia-date-prev], [data-aia-date-next]",onClick:(t,e)=>{if(t.hasAttribute("data-aia-date-prev")){e.callbacks.onPreviousMonth();return}if(t.hasAttribute("data-aia-date-next")){e.callbacks.onNextMonth();return}let n=mr(t,e);n&&(t.classList.add("magicx-aia-date-cell--pressed"),e.callbacks.onSelect(n),setTimeout(()=>t.classList.remove("magicx-aia-date-cell--pressed"),170))},onEnter:(t,e)=>{t.hasAttribute("data-aia-date-cell")&&mr(t,e)&&e.callbacks.onHighlight($(t))},onLeave:(t,e)=>{t.hasAttribute("data-aia-date-cell")&&e.callbacks.onHighlight(-1,$(t))}};function gr(t,e,n,r,i,o,s,a=!0){let l=t.querySelector(".magicx-aia-datepicker");if(!i||e.length===0){l?.remove();return}if(!l){l=Qi(),t.appendChild(l),G(l);for(let c of l.querySelectorAll(".magicx-aia-datepicker-nav"))c.disabled=!1}q(l,Ui,{options:e,callbacks:s,interactive:a});let d=l.querySelector(".magicx-aia-datepicker-month");d&&(d.textContent=st(i));let u=l.querySelector(".magicx-aia-datepicker-grid");u&&Ki(u,e,n,r,o)}function Ki(t,e,n,r,i){let o=k(new Date),s=Bt({pendingStart:i.rangeStart,highlightedIso:H(e[n]),selected:i.selectedRange});V(t,e,{keyOf:(a,l)=>H(a)??`pad-${l}`,create:a=>Yi(a),update:(a,l,d)=>{let u=H(l),c=Wt(u,{selectedIso:i.selectedIso,range:s}),m=d===n&&l.is_tappable;a.id=`${r}-option-${d}`,a.dataset.aiaIndex=String(d),a.setAttribute("aria-selected",String(m)),a.classList.toggle("magicx-aia-date-cell--past",u!=null&&u<o),a.classList.toggle("magicx-aia-date-cell--highlighted",m),a.classList.toggle("magicx-aia-date-cell--today",u!=null&&u===o),a.classList.toggle("magicx-aia-date-cell--selected",c.selected),a.classList.toggle("magicx-aia-date-cell--in-range",c.inRange)}})}function Yi(t){let e=document.createElement("div");e.setAttribute("role","option"),e.setAttribute("data-aia-option",""),e.setAttribute("data-aia-date-cell","");let n=ut(t);if(n==null)return e.className="magicx-aia-date-cell magicx-aia-date-cell--blank",e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e;e.className="magicx-aia-date-cell magicx-aia-date-cell--day",e.tabIndex=0,e.setAttribute("aria-label",t.text);let r=document.createElement("span");return r.className="magicx-aia-date-cell-number",r.textContent=String(n),e.appendChild(r),e}function Qi(){let t=document.createElement("div");t.className="magicx-aia-datepicker",t.setAttribute("data-aia-datepicker","");let e=document.createElement("div");e.className="magicx-aia-datepicker-header";let n=document.createElement("span");n.className="magicx-aia-datepicker-month",n.setAttribute("data-aia-date-month",""),n.setAttribute("aria-live","polite"),e.append(fr("prev","Previous month","\u2039"),n,fr("next","Next month","\u203A"));let r=document.createElement("div");r.className="magicx-aia-datepicker-weekdays",r.setAttribute("aria-hidden","true");for(let o of Me){let s=document.createElement("span");s.className="magicx-aia-datepicker-weekday",s.textContent=o,r.appendChild(s)}let i=document.createElement("div");return i.className="magicx-aia-datepicker-grid",i.setAttribute("data-aia-date-grid",""),t.append(e,r,i),t}function fr(t,e,n){let r=document.createElement("button");return r.type="button",r.tabIndex=-1,r.className="magicx-aia-datepicker-nav",r.setAttribute(`data-aia-date-${t}`,""),r.setAttribute("aria-label",e),r.textContent=n,r.disabled=!0,r}var Xi={itemSelector:"[data-aia-pill]",onClick:(t,e)=>{if(e.loading||t.disabled)return;let n=Number.parseInt(t.dataset.aiaPillIndex??"-1",10);n>=0&&e.onSelectPill(n)},preventMousedown:!0},hr=[125,69];function br(t,e){return e?1:t===0?.7:t===1?.4:.2}function Je(t,e,n,r,i=!1,o=!1,s=!1){let a=t.querySelector(".magicx-aia-pill-list");if(a||(a=document.createElement("span"),a.className="magicx-aia-pill-list",t.appendChild(a)),q(a,Xi,{onSelectPill:r,loading:o}),o&&e.length===0){a.setAttribute("data-aia-pill-list-loading",""),a.innerHTML="";for(let l=0;l<hr.length;l++){let d=hr[l],u=document.createElement("span");u.setAttribute("data-aia-pill-skeleton",""),u.className=`magicx-aia-pill magicx-aia-pill--skeleton${i?" magicx-aia-pill--rounded":""}`,u.style.width=`${d}px`,u.style.opacity=String(br(l,!1)),a.appendChild(u)}return}o?a.setAttribute("data-aia-pill-list-loading",""):a.removeAttribute("data-aia-pill-list-loading");for(let l of a.querySelectorAll("[data-aia-pill-skeleton]"))l.remove();V(a,e,{keyOf:l=>`${l.parameter}-${l.text}`,create:l=>{let d=document.createElement("button");return d.type="button",d.tabIndex=-1,d.setAttribute("data-aia-pill",""),d.setAttribute("contenteditable","false"),d.textContent=l.text,d.disabled=!0,d},update:(l,d,u)=>{let c=l,m=s&&u===n&&!o,f=["magicx-aia-pill"];i&&f.push("magicx-aia-pill--rounded"),o&&f.push("magicx-aia-pill--skeleton"),c.className=f.join(" "),c.style.width="",c.style.opacity=String(br(u,m)),c.dataset.aiaPillIndex=String(u),o?c.setAttribute("data-aia-loading",""):c.removeAttribute("data-aia-loading")}}),G(a);for(let l of a.querySelectorAll("[data-aia-pill]"))l.disabled=o}function qt(t){t.querySelector(".magicx-aia-pill-list")?.remove()}var ji=32;function Sr(t,e){if(e.ctrlKey)return null;let n=e.deltaY||0,r=e.deltaX||0;if(!n||Math.abs(r)>=Math.abs(n))return null;let i=t.scrollWidth-t.clientWidth;if(i<=1)return null;let o=t.scrollLeft,s=n;return e.deltaMode===1?s*=32:e.deltaMode===2&&(s*=t.clientWidth),Math.max(0,Math.min(i,o+s))}function $t(t){let e=n=>{let r=Sr(t,n);r!==null&&(n.preventDefault(),t.scrollLeft=r)};return t.addEventListener("wheel",e,{passive:!1}),()=>t.removeEventListener("wheel",e)}var xr=Intl.Segmenter,yr=xr?new xr(void 0,{granularity:"grapheme"}):null;function Gt(t){let e=t.trim().normalize("NFC").toUpperCase();if(yr)for(let n of yr.segment(e))return n.segment;return Array.from(e)[0]??"?"}var Vt=new WeakMap,vr=new WeakMap,zi="Products";function Er(t,e,n,r,i,o="row",s="image"){let a=t.querySelector(".magicx-aia-products");if(e.length===0){a?.remove();return}if(!a){a=document.createElement("section"),a.className="magicx-aia-products",a.setAttribute("data-aia-products",""),a.setAttribute("role","group"),a.setAttribute("aria-labelledby",`${n}-products-label`);let d=document.createElement("div");d.className="magicx-aia-products-label",d.id=`${n}-products-label`,d.setAttribute("data-aia-products-label",""),d.textContent=zi;let u=document.createElement("div");u.className="magicx-aia-products-row",u.setAttribute("data-aia-products-row",""),$t(u),a.append(d,u),t.appendChild(a)}a.setAttribute("data-aia-products-layout",o);let l=a.querySelector(".magicx-aia-products-row");if(l){V(l,e,{keyOf:d=>Zi(d),create:d=>eo(d,r,i,s),update:(d,u,c)=>{d.id=`${n}-product-${c}`,d.dataset.aiaIndex=String(c),vr.get(d)?.(s)}}),G(l);for(let d of l.querySelectorAll("[data-aia-product]")){let u=Vt.get(d);u&&(Vt.delete(d),u())}}}function Ut(t,e){let n=t.querySelectorAll("[data-aia-product]");for(let r of n)r.tabIndex=e?0:-1}var Ji="Sold out";function Zi(t){return[t.id,t.title,t.url,t.imageUrl,t.price,t.vendor,t.available===!1?"sold-out":""].map(e=>e??"").join("\0")}function eo(t,e,n,r){let i=document.createElement("a");i.className="magicx-aia-product",i.setAttribute("data-aia-product",""),i.setAttribute("role","option"),i.setAttribute("aria-selected","false"),i.tabIndex=0;let o=document.createElement("span");o.className="magicx-aia-product-media",o.setAttribute("aria-hidden","true");let s=t.imageUrl?.trim(),a=!!s,l=()=>{o.replaceChildren(),o.toggleAttribute("data-aia-product-placeholder",r==="image"),o.toggleAttribute("data-aia-product-initial",r==="initial"),r==="initial"&&(o.textContent=Gt(t.title))};if(vr.set(i,c=>{c!==r&&(r=c,a||l())}),s){let c=document.createElement("img");c.onerror=()=>{a=!1,l()},c.className="magicx-aia-product-image",c.src=s,c.alt="",c.loading="lazy",c.decoding="async",o.appendChild(c)}else l();i.appendChild(o);let d=document.createElement("span");if(d.className="magicx-aia-product-body",t.vendor){let c=document.createElement("span");c.className="magicx-aia-product-vendor",c.textContent=t.vendor,d.appendChild(c)}let u=document.createElement("span");if(u.className="magicx-aia-product-title",u.textContent=t.title,d.appendChild(u),t.price){let c=document.createElement("span");c.className="magicx-aia-product-price",c.textContent=t.price,d.appendChild(c)}if(t.available===!1){i.setAttribute("data-aia-product-sold-out","");let c=document.createElement("span");c.className="magicx-aia-product-badge",c.textContent=Ji,d.appendChild(c)}return i.appendChild(d),Vt.set(i,()=>{t.url&&(i.href=t.url),i.addEventListener("click",c=>{c.metaKey||c.ctrlKey||c.shiftKey||c.altKey||c.button!==0||(c.preventDefault(),e(t))})}),i.addEventListener("keydown",c=>{c.key!=="Enter"&&c.key!==" "||(c.preventDefault(),e(t))}),i.addEventListener("focus",()=>n(!0)),i.addEventListener("blur",c=>{c.relatedTarget?.closest("[data-aia-dropdown]")||n(!1)}),i}var to=80,no=150,ro=280,io=16,Kt="--aia-option-enter-delay";function Yt(t,e,n,r="below"){let i=Math.max(1,Math.floor(e)),o=Math.floor(Math.max(0,t)/i);if(r!=="above")return o*80;let s=Math.max(1,Math.ceil(Math.max(0,n)/i));return Math.max(0,s-1-o)*80}function Qt(t,e){let n=Math.max(1,Math.floor(e));return(Math.max(1,Math.ceil(Math.max(0,t)/n))-1)*80+280}function U(t){if(!t)return null;let e=t.trim();if(e==="")return null;let n;try{n=new URL(e,typeof document>"u"?void 0:document.baseURI)}catch{return null}return n.protocol!=="http:"&&n.protocol!=="https:"?null:n.href}function xe(t){return t===void 0||!Number.isInteger(t)||t<0?null:t.toLocaleString()}var Pr={one:"item",other:"items"};function oo(t,e=Pr){let n=xe(t);if(n===null)return null;let r=typeof e=="string"?e:t===1?e.one:e.other;return r===""?n:`${n} ${r}`}function so(t){return U(t.image_url)!==null}var wr="http://www.w3.org/2000/svg",ao=new Set(["svg","g","path","circle","ellipse","line","polyline","polygon","rect"]);function lo(t,e){let n=t.toLowerCase();return n.startsWith("on")||n.includes("href")||n==="style"||n==="xml:base"||n==="id"||n==="name"||/^\s*javascript:/i.test(e)||/url\s*\(\s*['"]?\s*[^#'"\s)]/i.test(e)}var co=["fill","stroke","stroke-width","stroke-linecap","stroke-linejoin","fill-rule","clip-rule","opacity","fill-opacity","stroke-opacity"],uo=/^[a-zA-Z0-9#.,%\s()-]+$/;function po(t){let e=[];for(let n of co){let r=t.getAttribute(n);r===null||!uo.test(r)||/url\s*\(/i.test(r)||e.push(`${n}: ${r.trim()}`)}e.length>0&&t.setAttribute("style",e.join("; "))}function Tr(t){for(let e of Array.from(t.attributes))lo(e.name,e.value)&&t.removeAttribute(e.name);po(t);for(let e of Array.from(t.childNodes))if(e.nodeType===Node.ELEMENT_NODE){let n=e;!ao.has(n.localName)||n.namespaceURI!==wr?n.remove():Tr(n)}else e.remove()}function ye(t){if(typeof DOMParser>"u"||typeof XMLSerializer>"u")return null;let e=new DOMParser().parseFromString(t,"image/svg+xml"),n=e.documentElement;return!n||n.localName!=="svg"||n.namespaceURI!==wr||e.getElementsByTagName("parsererror").length>0?null:(Tr(n),n.setAttribute("aria-hidden","true"),n.setAttribute("focusable","false"),new XMLSerializer().serializeToString(n))}function Xt(t){return t.text}var Cr=new WeakMap;function mo(t,e,n){let r=e.length,i=kt(),o=Cr.get(t),s=n&&o&&_t(o.options,e)?o.plan:null,a=!s&&!n&&Rt(r,i)?Dt(t):null,l=s??Mt(r,i,a?.rowWidths??null,a?.gridWidth??null);return n||Cr.set(t,{options:e,plan:l}),t.style.gridTemplateColumns=l.template,t.style.setProperty("--aia-grid-max-height",l.maxHeight),t.querySelectorAll("[data-aia-option]").forEach((d,u)=>{d.classList.toggle("magicx-aia-option--scroll-hint",!n&&l.scrollHintIndices.includes(u))}),l.cols}function Ir(t,e){if(e.loading||!e.interactive)return null;let n=e.options[$(t)];return n?.is_tappable?n:null}var fo={itemSelector:"[data-aia-option]",onClick:(t,e)=>{let n=Ir(t,e);n&&(t.classList.add("magicx-aia-option--pressed"),e.onSelect(n),setTimeout(()=>t.classList.remove("magicx-aia-option--pressed"),170))},onEnter:(t,e)=>{Ir(t,e)&&e.onHighlight($(t))},onLeave:(t,e)=>e.onHighlight(-1,$(t))};function Or(t,e,n,r,i,o,s,a="",l="below",d=!0,u=!0,c=!0,m=!0){let f=t.querySelector(".aia-grid");if(e.length===0){f?.remove();return}f||(f=document.createElement("div"),f.className="aia-grid magicx-aia-grid",f.setAttribute("data-scroll",""),f.style.setProperty("--aia-grid-min","250px"),f.style.setProperty("--aia-grid-max","1fr"),f.style.setProperty("--aia-grid-gap","0"),t.appendChild(f)),q(f,fo,{options:e,onSelect:r,onHighlight:i,loading:s,interactive:m});let h=f.dataset.aiaGroup!==a;f.dataset.aiaGroup=a,go(f,e,n,o,s,{showIcons:d,showImages:u,showCounts:c});let x=mo(f,e,s);ho(f,e.length,x,s,l),h&&(f.scrollTop=0)}function go(t,e,n,r,i,o){let s=i?"1":"0",a=t.dataset.aiaGroup??"",{showIcons:l,showImages:d,showCounts:u}=o,c=l?h=>h.icon??h.icon_svg??"":()=>"",m=d?h=>U(h.image_url)??"":()=>"",f=u?h=>xe(h.item_count)??"":()=>"";V(t,e,{keyOf:h=>`${h.text}\0${c(h)}\0${m(h)}\0${f(h)}\0${s}\0${a}`,create:(h,x)=>{let y=bo(h,i,o);return i||(y.dataset.aiaEntering=""),y},update:(h,x,y)=>{let g=y===n&&!i;h.id=`${r}-option-${y}`,h.dataset.aiaIndex=String(y),h.setAttribute("aria-selected",String(g)),h.classList.toggle("magicx-aia-option--highlighted",g)}})}function ho(t,e,n,r,i){for(let o of t.querySelectorAll("[data-aia-entering]")){if(!r){let s=Number.parseInt(o.dataset.aiaIndex??"-1",10);s>=0&&o.style.setProperty(Kt,`${Yt(s,n,e,i)}ms`)}delete o.dataset.aiaEntering}}function bo(t,e,{showIcons:n,showImages:r,showCounts:i}){let o=document.createElement("div");o.setAttribute("role","option"),o.setAttribute("data-aia-option",""),e&&o.setAttribute("data-aia-loading",""),o.tabIndex=e||!t.is_tappable?-1:0;let s=["magicx-aia-option"];t.is_tappable?s.push("magicx-aia-option--tappable"):s.push("magicx-aia-option--non-tappable"),o.className=s.join(" ");let a=document.createElement("span");a.className="magicx-aia-option-content";let l=r?U(t.image_url):null;if(l){let m=document.createElement("span");m.className="magicx-aia-option-image",m.setAttribute("aria-hidden","true");let f=document.createElement("img");f.setAttribute("alt",""),f.setAttribute("loading","lazy"),f.setAttribute("decoding","async"),f.setAttribute("referrerpolicy","no-referrer"),f.setAttribute("draggable","false"),f.onerror=()=>{f.hidden=!0},f.src=l,m.appendChild(f),a.appendChild(m),o.dataset.aiaImage=""}let d=!l&&n&&t.icon_svg?ye(t.icon_svg):null;if(d){let m=document.createElement("span");m.className="magicx-aia-option-icon",m.setAttribute("aria-hidden","true"),m.innerHTML=d,a.appendChild(m),t.icon&&(o.dataset.aiaIcon=t.icon)}let u=document.createElement("span");if(u.className="magicx-aia-option-text",u.textContent=Xt(t),a.appendChild(u),t.tag){let m=document.createElement("span");m.className="magicx-aia-option-tag",m.textContent=t.tag,a.appendChild(m)}let c=i?xe(t.item_count):null;if(c!==null){let m=document.createElement("span");m.className="magicx-aia-option-count",m.textContent=c,a.appendChild(m),o.dataset.aiaItemCount=String(t.item_count)}return o.appendChild(a),o}var Ar="magicx-aia-scroll-arrow",Lr="data-aia-scroll-arrow",le="data-aia-visible",Rr=1e3,Mr=160,Dr="--aia-scroll-arrow-bottom",kr="Scroll down for more options",So="[data-aia-products-label]",xo=4,yo=8,vo=240;function Eo(t,e,n,r){let i=t.scrollTop,o=n?.requestAnimationFrame,s=t.ownerDocument?.visibilityState==="hidden";if(!o||s||jt(t)){t.scrollTop=i+e,r();return}let a=n.performance?.now?.()??Date.now(),l=()=>n.performance?.now?.()??Date.now(),d=()=>{let u=Math.min(1,(l()-a)/vo),c=1-(1-u)*(1-u);t.scrollTop=i+e*c,u<1?o.call(n,d):r()};o.call(n,d)}function Po(t=document){let e="http://www.w3.org/2000/svg",n=t.createElementNS(e,"svg");n.setAttribute("viewBox","0 0 16 16"),n.setAttribute("width","18"),n.setAttribute("height","18"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","1.75"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),n.setAttribute("aria-hidden","true"),n.setAttribute("focusable","false");let r=t.createElementNS(e,"path");return r.setAttribute("d","M4 6.5 8 10.5l4-4"),n.appendChild(r),n}function _r(t=document){let e=t.createElement("button");return e.type="button",e.tabIndex=-1,e.className=Ar,e.setAttribute(Lr,""),e.setAttribute("aria-label",kr),e.setAttribute("aria-hidden","true"),e.disabled=!0,e.appendChild(Po(t)),e}function wo(t){let e=t.style.gridTemplateColumns.trim();return e?Math.max(1,e.split(/\s+/).length):1}function jt(t){return t.closest('[data-animations="off"]')?!0:!!t.ownerDocument?.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches}function zt({dropdown:t,grid:e,button:n}){let r=e.ownerDocument?.defaultView??(typeof window<"u"?window:null),i=!1;n.disabled=!0;let o=null,s=null,a=null,l=null,d=p=>{if(p){if(n.hasAttribute(le))return;if(n.setAttribute(le,""),n.setAttribute("aria-hidden","false"),l!==null&&clearTimeout(l),jt(e)){n.disabled=!1;return}l=setTimeout(()=>{l=null,!i&&n.hasAttribute(le)&&(n.disabled=!1)},Rr)}else n.removeAttribute(le),n.setAttribute("aria-hidden","true"),l!==null&&clearTimeout(l),l=null,n.disabled=!0},u=p=>{let b=0,S=p;for(;S&&S!==t;)b+=S.offsetTop,S=S.offsetParent instanceof HTMLElement?S.offsetParent:null;return b},c=()=>{let p=t.querySelector(So),b;if(p){let S=u(p)+p.offsetHeight/2;b=t.clientHeight-S-n.offsetHeight/2}else{let S=u(e),E=r&&Number.parseFloat(r.getComputedStyle(e).paddingBottom)||0;b=t.clientHeight-(S+e.offsetHeight)+(E>0?0:yo)}n.style.setProperty(Dr,`${Math.max(0,Math.round(b))}px`)},m=()=>{if(i||s!==null||a!==null)return;let p=e.querySelector("[data-aia-option][data-aia-loading]")!==null,b=e.scrollHeight-e.clientHeight-e.scrollTop;d(!p&&b>xo)},f=()=>{if(i)return;c();let p=e.getAttribute("data-aia-group")??"";if(p!==o){o=p,d(!1),s!==null&&clearTimeout(s);let b=e.querySelectorAll("[data-aia-option]").length,S=jt(e)?0:Qt(b,wo(e));s=setTimeout(()=>{s=null,m()},S);return}m()},h=()=>{i||s!==null||(d(!1),a!==null&&clearTimeout(a),a=setTimeout(()=>{a=null,m()},Mr))};e.addEventListener("scroll",h,{passive:!0});let x=p=>p.preventDefault(),y=()=>{let p=r?(Number.parseFloat(r.getComputedStyle(e).paddingTop)||0)+(Number.parseFloat(r.getComputedStyle(e).paddingBottom)||0):0,b=Math.max(1,e.clientHeight-p);Eo(e,b,r,h)};n.addEventListener("mousedown",x),n.addEventListener("click",y);let g=null;return r&&typeof r.ResizeObserver=="function"&&(g=new r.ResizeObserver(()=>{c(),m()}),g.observe(e)),f(),{update:f,destroy(){i||(i=!0,s!==null&&clearTimeout(s),s=null,a!==null&&clearTimeout(a),a=null,l!==null&&clearTimeout(l),l=null,n.disabled=!0,e.removeEventListener("scroll",h),n.removeEventListener("mousedown",x),n.removeEventListener("click",y),g?.disconnect(),n.removeAttribute(le),n.setAttribute("aria-hidden","true"))}}}var To=[159,119,164];function et(t){let e=document.createElement("div");return e.id=t,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",n=>n.preventDefault()),Ht(e),e}var Ze=new WeakMap;function Co(t,e){let n=Ze.get(t);if(n||(n={button:_r(t.ownerDocument),grid:null,controller:null},t.appendChild(n.button),Ze.set(t,n)),n.grid!==e&&(n.controller?.destroy(),n.controller=null,n.grid=e,e)){n.controller=zt({dropdown:t,grid:e,button:n.button});return}n.controller?.update()}function Jt(t){let e=Ze.get(t);e&&(e.controller?.destroy(),Ze.delete(t))}function tt(t,e){let{filteredOptions:n,activeIndex:r,isOpen:i,isLoading:o,pills:s,showPills:a,isActivePillSelected:l,onSelect:d,onHighlight:u,onPillClick:c,onSkip:m}=e,f=s.length>0,h=a&&f,x=n.length>0,y=e.products.length>0,g=i&&(x||h||o||y);if(g?t.classList.add("magicx-aia-dropdown--visible"):t.classList.remove("magicx-aia-dropdown--visible"),o?t.setAttribute("data-aia-loading",""):t.removeAttribute("data-aia-loading"),!g){Ut(t,!1);return}y?t.setAttribute("data-aia-has-products",""):t.removeAttribute("data-aia-has-products"),t.toggleAttribute("data-aia-skeleton-exiting",!!e.skeletonExiting);let p=t.querySelector(".aia-stack");p||(p=document.createElement("div"),p.className="aia-stack",p.style.setProperty("--aia-stack-space","8px"),t.appendChild(p));let b=e.showSkipButton&&f&&!e.isInputEmpty,S=h||o&&a||b,E=p.querySelector(".magicx-aia-pill-bar");if(S){E||(E=document.createElement("div"),E.className="magicx-aia-pill-bar aia-cluster",E.setAttribute("data-nowrap",""),E.setAttribute("data-aia-pillbar",""),p.insertBefore(E,p.firstChild));let D=E.querySelector(".magicx-aia-pill-scroll");D||(D=document.createElement("span"),D.className="magicx-aia-pill-scroll",D.setAttribute("data-aia-pill-scroll",""),E.insertBefore(D,E.firstChild)),Je(D,a?s:[],0,c,!0,o&&a,l),Ao(E,b,o||e.skipDisabled,s[0],m)}else E&&E.remove();let v=e.suggestions[0],w=v?`${v.parameter} ${v.text}`:"",L=P(e.formatType),T=L&&!o;Or(p,L?[]:n,r,d,u,e.listboxId,o,w,e.optionsPosition??"below",e.showOptionIcons??!0,e.showOptionImages??!0,e.showOptionCounts??!0,!e.skipDisabled),Co(t,p.querySelector(".aia-grid")),gr(p,T?n:[],r,e.listboxId,T?e.dateView:null,{selectedIso:e.selectedDateIso,selectedRange:e.selectedDateRange,rangeStart:e.dateRangeStart},{onSelect:d,onHighlight:u,onPreviousMonth:e.onPreviousMonth,onNextMonth:e.onNextMonth},!e.skipDisabled);let I=p.querySelector(".magicx-aia-skeleton-bars");if(o&&(!x||L)){if(!I){I=document.createElement("div"),I.className="magicx-aia-skeleton-bars",I.setAttribute("data-aia-skeleton-bars","");for(let D of To){let Z=document.createElement("span");Z.className="magicx-aia-skeleton-bar",Z.style.width=`${D}px`,I.appendChild(Z)}p.appendChild(I)}}else I&&I.remove();Er(p,e.products,e.listboxId,e.onProductSelect,e.onProductFocusChange,e.productsLayout??"row",e.productImageFallback??"image"),Ut(t,!0);let K=p.querySelector(".magicx-aia-footer")??Ro(),M=r>=0&&!!n[r]?.is_tappable;Lo(K,Ft(M,e.isInputEmpty)),K.isConnected||p.appendChild(K),Io(p,[".magicx-aia-pill-bar",".aia-grid",".magicx-aia-datepicker",".magicx-aia-skeleton-bars",".magicx-aia-products",".magicx-aia-footer"])}function Io(t,e){let n=e.map(r=>t.querySelector(`:scope > ${r}`)).filter(r=>r!==null);for(let r=0;r<n.length;r++)t.children[r]!==n[r]&&t.insertBefore(n[r],t.children[r]??null)}var Oo={itemSelector:".magicx-aia-skip",onClick:(t,e)=>{e.loading||e.onSkip()}};function Ao(t,e,n,r,i){q(t,Oo,{onSkip:i,loading:n});let o=t.querySelector(".magicx-aia-skip");if(!e){o?.remove();return}o||(o=document.createElement("button"),o.type="button",o.tabIndex=-1,o.className="magicx-aia-skip",o.setAttribute("data-aia-skip",""),o.textContent="skip",o.disabled=!0,t.appendChild(o),G(o)),o.setAttribute("aria-label",r?`Skip ${r.text}`:"Skip"),o.disabled=n}function Lo(t,{key:e,hint:n}){let r=t.querySelector(".magicx-aia-footer-key"),i=t.querySelector(".magicx-aia-footer-hint");!r||!i||(r.textContent!==e&&(r.textContent=e),i.textContent!==n&&(i.textContent=n))}function Ro(){let t=document.createElement("footer");t.className="magicx-aia-footer",t.setAttribute("data-aia-footer","");let e=document.createElement("div");e.className="aia-cluster magicx-aia-footer-row",e.setAttribute("data-align","center"),e.setAttribute("data-justify","between"),e.setAttribute("data-nowrap","");let n=document.createElement("div");n.className="aia-cluster magicx-aia-footer-hint-group",n.setAttribute("data-align","center"),n.style.setProperty("--aia-cluster-gap","5px");let r=document.createElement("kbd");r.className="magicx-aia-footer-key",r.textContent="tab";let i=document.createElement("span");i.className="magicx-aia-footer-hint",i.textContent="to select",n.append(r,i);let o=document.createElement("a");o.className="aia-cluster magicx-aia-footer-brand-link",o.setAttribute("data-align","center"),o.href=Nt(),o.target="_blank",o.rel="noopener noreferrer",o.style.setProperty("--aia-cluster-gap","2px");let s=document.createElement("span");s.className="magicx-aia-footer-brand",s.textContent="AI";let a=document.createElement("span");return a.className="magicx-aia-footer-badge",a.textContent="Autocomplete",o.append(s,a),e.append(n,o),t.append(e),t}function Nr(t,e){let n=et(e.listboxId);return t.appendChild(n),{dropdown:n}}function Zt(t,e,n){let r=Se(e);tt(t.dropdown,{suggestions:e.editingIdentified?[{parameter:e.editingIdentified.parameter,text:j(e.editingIdentified.parameter),required:!0,options:e.filteredOptions}]:e.dropdownSuggestion??e.actionableSuggestions[0]?[{...e.dropdownSuggestion??e.actionableSuggestions[0],options:e.dropdownOptions}]:[],filteredOptions:e.dropdownOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.dropdownLoading,skeletonExiting:e.skeletonExiting,listboxId:n.listboxId,pills:e.actionableSuggestions,showPills:!0,showSkipButton:n.showSkipButton&&!e.editingParam&&!e.editingIdentified,skipDisabled:e.inSelectionAnimation,showOptionIcons:n.showOptionIcons??!0,showOptionImages:n.showOptionImages??!0,showOptionCounts:n.showOptionCounts??!0,isActivePillSelected:e.isActivePillSelected,isInputEmpty:e.text.trim().length===0,products:e.products,productsLayout:n.productsLayout??"row",productImageFallback:n.productImageFallback??"image",formatType:e.activeFormatType,dateView:e.dateView,selectedDateIso:r.selectedIso,selectedDateRange:r.selectedRange,dateRangeStart:r.rangeStart,optionsPosition:n.optionsPosition??"below",onSelect:n.selectOption,onHighlight:(i,o)=>{o!==void 0&&n.store.get().activeDropdownIndex!==o||n.store.set({activeDropdownIndex:i})},onPillClick:n.setActivePill,onSkip:n.skipActivePill,onPreviousMonth:n.showPreviousMonth,onNextMonth:n.showNextMonth,onProductSelect:n.selectProduct,onProductFocusChange:i=>n.store.set({isFocused:i})})}var Mo=6,Do=.3;function Fr(t){return t<=0?"0px":`${(-Math.min(Do,2*Mo/t)).toFixed(3)}px`}function en(t){let{input:e,segments:n,newParamId:r,editingParamId:i,placeholderText:o,isFocused:s}=t,a=t.showChipIcons??!0,l=t.showChipImages??!0,d=n.length===0;e.dataset.aiaEmpty=d?"true":"false",or(e,d?o:"");let u=n.map(p=>p.type==="completed"?`${p.type}:${p.value}${a?p.param.icon??p.param.icon_svg??"":""}${l?U(p.param.image_url)??"":""}`:`${p.type}:${p.value}`).join("\0"),c=e.dataset.segKey??"",m=e.dataset.newParamId??"",f=e.dataset.editingParamId??"";if(u===c&&(r??"")===m&&(i??"")===f)return;if(u===c){e.dataset.newParamId=r??"",e.dataset.editingParamId=i??"";for(let p of e.querySelectorAll("strong[data-param-id]")){let b=p.dataset.paramId,S=p.dataset.seg==="completed"&&b===r;p.classList.toggle("magicx-aia-shimmer-revealed",S),p.classList.toggle("magicx-aia-shimmer-sweep",S),p.classList.toggle("magicx-aia-segment--editing",b===i)}return}let h=s?_(e):null;e.dataset.segKey=u,e.dataset.newParamId=r??"",e.dataset.editingParamId=i??"";let x=O(e),y=x.createDocumentFragment(),g=0;for(let p of n)if(g+=p.value.length,p.type==="completed"){let b=x.createElement("strong");b.dataset.seg="completed",b.dataset.paramId=p.param.id;let S=p.param.id===r,E=p.param.id===i,v=["magicx-aia-segment","magicx-aia-segment--completed"];S&&v.push("magicx-aia-shimmer-revealed","magicx-aia-shimmer-sweep"),E&&v.push("magicx-aia-segment--editing"),b.className=v.join(" "),b.style.letterSpacing=Fr(p.value.length);let w=l?U(p.param.image_url):null;if(w){let T=x.createElement("span");T.className="magicx-aia-segment-image",T.setAttribute("contenteditable","false"),T.setAttribute("aria-hidden","true"),T.style.setProperty("--aia-chip-image",`url("${w}")`),b.appendChild(T),b.dataset.aiaImage=""}let L=!w&&a&&p.param.icon_svg?ye(p.param.icon_svg):null;if(L){let T=x.createElement("span");T.className="magicx-aia-segment-icon",T.setAttribute("contenteditable","false"),T.setAttribute("aria-hidden","true"),T.innerHTML=L,b.appendChild(T),p.param.icon&&(b.dataset.aiaIcon=p.param.icon)}b.appendChild(x.createTextNode(p.value)),y.appendChild(b)}else if(p.type==="identified"){let b=x.createElement("strong");b.dataset.seg="identified",b.dataset.paramId=p.param.id;let S=["magicx-aia-segment","magicx-aia-segment--completed"];p.param.id===i&&S.push("magicx-aia-segment--editing"),b.className=S.join(" "),b.style.letterSpacing=Fr(p.value.length),b.textContent=p.value,y.appendChild(b)}else y.appendChild(x.createTextNode(p.value));e.replaceChildren(y),e.dataset.aiaTextLength=String(g),h!=null?A(e,Math.max(0,Math.min(h,g))):s&&Wn(e)&&A(e,g)}var ko='<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 Hr(){let t=document.createElement("button");return t.type="button",t.className="magicx-aia-submit",t.setAttribute("aria-label","Submit"),t.setAttribute("data-aia-submit",""),t.innerHTML=ko,t}function _o(){let t=document.createElement("div");return t.setAttribute("contenteditable","plaintext-only"),t.contentEditable==="plaintext-only"}function Br(t,e){let n=e.firstElementChild;if(!n){e.removeAttribute("data-aia-pill-wrapped");return}let r=n.getBoundingClientRect(),i=t.getBoundingClientRect();r.top>=i.bottom-2?e.setAttribute("data-aia-pill-wrapped",""):e.removeAttribute("data-aia-pill-wrapped")}function Wr(t,e){let{listboxId:n}=e,r=et(n);t.appendChild(r);let i=document.createElement("div");i.className="magicx-aia-input-wrapper",i.setAttribute("data-aia-input-wrapper",""),t.appendChild(i);let o=document.createElement("div");o.className="magicx-aia-editor",o.setAttribute("data-aia-editor",""),i.appendChild(o);let s=document.createElement("div");s.className="magicx-aia-input",s.setAttribute("data-aia-input",""),s.setAttribute("contenteditable",_o()?"plaintext-only":"true"),s.setAttribute("role","combobox"),s.setAttribute("aria-autocomplete","list"),s.setAttribute("aria-haspopup","listbox"),s.setAttribute("aria-controls",n),s.setAttribute("aria-expanded","false"),s.setAttribute("spellcheck","true"),s.setAttribute("enterkeyhint","send"),o.appendChild(s);let a=document.createElement("span");a.className="magicx-aia-pill-list-container",a.setAttribute("data-aia-pill-list-container",""),o.appendChild(a);let l=null,d=null;e.submitButton===void 0?(l=Hr(),i.appendChild(l),d=l):e.submitButton!==null&&(d=e.submitButton,d.hasAttribute("data-aia-submit")||d.setAttribute("data-aia-submit",""),d.setAttribute("data-aia-submit-slot",""),i.appendChild(d));let u=new AbortController,{signal:c}=u,m=!1,f=0,h=()=>{let g=Be(s),b=g.length>0&&g[0]!==g[0].toUpperCase()?g[0].toUpperCase()+g.slice(1):g;e.handleChange(b)},x=()=>{let g=W(s)?.node??null;if(!g||!s.contains(g))return null;let S=(g.nodeType===Node.ELEMENT_NODE?g:g.parentElement)?.closest("strong[data-param-id]")?.dataset.paramId??null;return S&&Bn(s,S)?null:S};if(i.addEventListener("click",g=>{g.target?.closest("[data-aia-pill]")||s.focus()},{signal:c}),s.addEventListener("input",()=>{m||(f=performance.now(),h(),e.handleCaretAfterInput(_(s)))},{signal:c}),O(s).addEventListener("selectionchange",()=>{let g=W(s);if(!g||!s.contains(g.node))return;let p=g.collapsed?x():null,b=e.store.get(),S=b.editingParam?.id??b.editingIdentified?.id??null;if(p&&p!==S){e.startEditingParam(p);return}performance.now()-f<50||e.handleCaretMove(_(s))},{signal:c}),s.addEventListener("click",g=>{let p=St(s,g.target);p&&(e.startEditingParam(p),xt(s,p))},{signal:c}),s.addEventListener("compositionstart",()=>{m=!0},{signal:c}),s.addEventListener("compositionend",()=>{m=!1,h()},{signal:c}),s.addEventListener("beforeinput",g=>{let p=g,b=p.inputType;if(b==="insertParagraph"||b==="insertLineBreak"||b==="insertFromDrop"){g.preventDefault();return}if(b.startsWith("insert")||b.startsWith("delete")){let S=b.startsWith("delete")?"":p.data??"";e.replaceEditingRange(S)&&g.preventDefault()}},{signal:c}),s.addEventListener("paste",g=>{g.preventDefault();let p=(g.clipboardData?.getData("text/plain")??"").replace(/\r?\n/g," ");if(!p)return;let b=O(s),S=ke(s);if(!S||!s.contains(S.startContainer))return;S.deleteContents();let E=b.createTextNode(p);S.insertNode(E),S.setStartAfter(E),me(s,S.startContainer,S.startOffset),h()},{signal:c}),s.addEventListener("keydown",g=>e.handleKeyDown(g),{signal:c}),s.addEventListener("focus",()=>e.store.set({isFocused:!0}),{signal:c}),s.addEventListener("blur",()=>e.store.set({isFocused:!1}),{signal:c}),d&&d.addEventListener("click",g=>{let p=e.store.get();if(!(!!p.text||p.completedParams.length>0)||!e.onSubmit)return;g.stopPropagation(),e.onSubmit(J(p.text,p.completedParams,p.skippedParams,{identifiedParams:p.identifiedParams,isReady:p.isReady,customFields:p.customFields}))&&e.afterSubmit?.()},{signal:c}),e.autoFocus!==!1){s.focus();let g=W(s);(!g||!s.contains(g.node))&&me(s,s,0)}if(typeof ResizeObserver<"u"){let g=new ResizeObserver(()=>Br(s,a));g.observe(s),u.signal.addEventListener("abort",()=>g.disconnect(),{once:!0})}return{input:s,inlinePillContainer:a,dropdown:r,submitButton:l,abort:u}}function tn(t,e,n){let{input:r,inlinePillContainer:i,dropdown:o,submitButton:s}=t,{pillPlacement:a,setActivePill:l,selectOption:d,store:u}=n;r.setAttribute("aria-expanded",String(e.isDropdownOpen));let c=e.activeDropdownIndex>=0?`${n.listboxId}-option-${e.activeDropdownIndex}`:"";if(c?r.setAttribute("aria-activedescendant",c):r.removeAttribute("aria-activedescendant"),s){let g=!!e.text||e.completedParams.length>0;s.disabled=!g}let m=r.dataset.newParamId??"",f=e.newParamId!==null&&e.newParamId!==m;if(en({input:r,segments:e.segments,newParamId:e.newParamId,editingParamId:e.editingParam?.id??null,placeholderText:e.placeholderText,isFocused:e.isFocused,showChipIcons:n.showChipIcons??!0,showChipImages:n.showChipImages??!0}),a==="inline"){let g=e.isLoading&&!e.editingParam&&!e.inSelectionAnimation;g||e.actionableSuggestions.length>0?Je(i,e.actionableSuggestions,0,l,!1,g,e.isActivePillSelected):qt(i)}else qt(i);Br(r,i),f?(r.focus(),A(r,e.caretOffset??e.text.length)):e.isFocused&&Be(r)!==e.text&&A(r,e.text.length);let h=e.editingParam?{parameter:e.editingParam.suggestionParameter,text:e.editingParam.suggestionPlaceholder,required:!0,options:e.editingParam.options}:e.editingIdentified?{parameter:e.editingIdentified.parameter,text:j(e.editingIdentified.parameter),required:!0,options:[]}:null,x=e.dropdownSuggestion??h??e.actionableSuggestions[0],y=Se(e);tt(o,{suggestions:x?[{...x,options:e.dropdownOptions}]:[],filteredOptions:e.dropdownOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.dropdownLoading,skeletonExiting:e.skeletonExiting,listboxId:n.listboxId,pills:h?[h]:e.actionableSuggestions,showPills:a==="dropdown",showSkipButton:n.showSkipButton&&!e.editingParam&&!e.editingIdentified,skipDisabled:e.inSelectionAnimation,showOptionIcons:n.showOptionIcons??!0,showOptionImages:n.showOptionImages??!0,showOptionCounts:n.showOptionCounts??!0,isActivePillSelected:e.isActivePillSelected,isInputEmpty:e.text.trim().length===0,products:e.products,productsLayout:n.productsLayout??"row",productImageFallback:n.productImageFallback??"image",formatType:e.activeFormatType,dateView:e.dateView,selectedDateIso:y.selectedIso,selectedDateRange:y.selectedRange,dateRangeStart:y.rangeStart,optionsPosition:n.optionsPosition??"below",onSelect:d,onHighlight:(g,p)=>{p!==void 0&&u.get().activeDropdownIndex!==p||u.set({activeDropdownIndex:g})},onPillClick:l,onSkip:n.skipActivePill,onPreviousMonth:n.showPreviousMonth,onNextMonth:n.showNextMonth,onProductSelect:n.selectProduct,onProductFocusChange:g=>u.set({isFocused:g})})}function nn(t){let e=t,n=new Set,r=[],i=!1;return{get:()=>e,set:o=>{let s=typeof o=="function"?o(e):o,a=e;if(e={...e,...s},r.push([e,a]),!i){i=!0;try{let l=0;for(let d=r.shift();d;d=r.shift()){if(++l>1e4)throw r.length=0,new Error("createStore: notifications did not settle after 10000 deliveries \u2014 a listener is likely calling set() on every notification");let[u,c]=d;for(let m of n)m(u,c)}}catch(l){throw r.length=0,l}finally{i=!1}}},subscribe:o=>(n.add(o),()=>{n.delete(o)})}}function qr(t,e){let n,r,i=o=>(o!==n&&(n=o,r=e(o)),r);return{get:()=>{let o=t.get();return{...o,...i(o)}},set:o=>{typeof o=="function"?t.set(s=>{let a={...s,...i(s)};return o(a)}):t.set(o)},peek:o=>{let s={...t.get(),...o};return{...s,...e(s)}},subscribe:o=>t.subscribe((s,a)=>{let l={...a,...i(a)},d={...s,...i(s)};o(d,l)})}}var rn=new WeakSet,$r=new WeakMap;function Vr(t){return t.nodeType===Node.DOCUMENT_NODE}function No(t){return Vr(t)?t:t.ownerDocument}function Fo(t){let e=$r.get(t);if(e)return e;let n=t.defaultView?.CSSStyleSheet;if(typeof n!="function")return null;try{let r=new n;return typeof r.replaceSync!="function"?null:(r.replaceSync(Kr),$r.set(t,r),r)}catch{return null}}function Gr(t,e){if(e.querySelector("style[data-magicx-aia]"))return;let n=t.createElement("style");n.setAttribute("data-magicx-aia",""),n.textContent=Kr,e.appendChild(n)}function Ur(t){if(typeof document>"u")return;let e=t??document;if(rn.has(e))return;let n=No(e);if(Vr(e)){let o=e.head??e.documentElement;if(!o)return;Gr(n,o),rn.add(e);return}let r=Fo(n),i=e.adoptedStyleSheets;r&&Array.isArray(i)?i.includes(r)||(e.adoptedStyleSheets=[...i,r]):Gr(n,e),rn.add(e)}var Kr=`.aia-stack {
|
|
1
|
+
function E(t){return t==="date"||t==="date-range"}function X(t){return t?.type?.kind==="date"?"date":t?.type?.kind==="date_range"?"date-range":"options"}var we=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 Zr="https://api.ai-autocomplete.com",Te=`${Zr}/api/suggest`,cn=new WeakMap;function ue(t){return t?.type==="accessToken"}function ei(t){if(!(!t||ue(t)))return t}function Ie(t){let e=cn.get(t.getAccessToken);return e||(e=new we(t),cn.set(t.getAccessToken,e)),e}function Ce(t){return{"Content-Type":"application/json",...t?.appIdentifier&&{"X-App-Identifier":t.appIdentifier},...t?.headers}}function Oe(t){let e=ei(t),n=e?.apiKey;return n?(e?.authScheme??"Bearer")==="Basic"?`Basic ${btoa(n)}`:`Bearer ${n}`:null}function pe(t){return t.map(e=>({parameter:e.parameter,text:e.text}))}var un="skipped";function me(t,e){if(e.length===0)return t;let n=new Set(t.map(i=>i.parameter)),r=e.filter(i=>!n.has(i.parameter)).map(i=>({placeholder:"",parameter:i.parameter,text:un,kind:null}));return r.length>0?[...t,...r]:t}var ti="0.38.0",fn="1.0",pn=!1;function ni(t,e){return{placeholder:t.placeholder,parameter:t.parameter,...e&&{text:t.value??t.text},kind:t.kind}}function ri(t,e,n,r,i,o,s,a,l,d){let c=e.find(m=>m.parameter==="contact"&&m.metadata?.contact_account_count)?.metadata?.contact_account_count,u=typeof c=="number"?c:void 0;return{data:{raw_query:t,completed_params:me(e.map(m=>ni(m,n)),l??[]),...s&&s.length>0&&{identified_params:pe(s)},...a&&a.length>0&&{recently_suggested:a},...u!=null&&{contact_account_count:u},...d!==void 0&&{additional_context:d}},meta:{request_id:i,request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:ti,session_id:r,source:o,schema_version:fn}}}async function mn(t,e,n,r,i){return fetch(t,{method:"POST",headers:{...e,Authorization:`Bearer ${n}`},body:r,signal:i})}async function gn(t,e,n){let r=n.apiConfig,i=!n.maskCompletedText,o=ri(t,e,i,n.sessionId,n.requestId??crypto.randomUUID(),n.source,n.identifiedParams,n.recentlySuggested,n.skippedParams,n.additionalContext),s=Ce(r),a=r?.endpoint??Te,l=JSON.stringify(o);if(ue(r)){let u=Ie(r),m=await u.getToken(),f=await mn(a,s,m,l,n.signal);if(f.status===401){let h=await u.getToken(!0);f=await mn(a,s,h,l,n.signal)}if(!f.ok)throw new Error(`API error: ${f.status} ${f.statusText}`);return f.json()}let d=Oe(r);!d&&!pn&&(pn=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),d&&(s.Authorization=d);let c=await fetch(a,{method:"POST",headers:s,body:l,signal:n.signal});if(!c.ok)throw new Error(`API error: ${c.status} ${c.statusText}`);return c.json()}var Ae=/[\p{L}\p{N}]/u,ii=/['\u2019-]/;function hn(t,e,n){let r=t[e];if(r===void 0)return!1;if(Ae.test(r))return!0;let i=t[e+n];return ii.test(r)&&i!==void 0&&Ae.test(i)}function oi(t,e,n){let r=e+n.length;return!(Ae.test(n[0])&&hn(t,e-1,-1)||Ae.test(n[n.length-1])&&hn(t,r,1))}function H(t,e,n=0,r=()=>!0){if(e.length===0)return t.indexOf(e,n);let i=-1,o=t.indexOf(e,n);for(;o!==-1;){if(r(o)){if(oi(t,o,e))return o;i===-1&&(i=o)}o=t.indexOf(e,o+1)}return i}function M(t,e){let n=t,r={},i=[],o=[],s=0;for(let a of e){let l=(r[a.parameter]??0)+1;r[a.parameter]=l;let c=`{{${a.parameter.toUpperCase().replace(/\s+/g,"_")}_${l}}}`,u=f=>H(n,a.text,f,h=>!o.some(x=>h<x.end&&h+a.text.length>x.start)),m=u(s);if(m===-1&&(m=u(0)),m!==-1){n=n.slice(0,m)+c+n.slice(m+a.text.length);let f=c.length-a.text.length;for(let h of o)h.start>=m+a.text.length&&(h.start+=f,h.end+=f);o.push({start:m,end:m+c.length}),s=m>=s?m+c.length:s+f}i.push({...a,placeholder:c})}return{rawQuery:n,completedParams:i}}function q(t,e,n){return e>0||!n?e:t.toLowerCase().startsWith(n.toLowerCase())?n.length:e}function Le(t,e,n){return e===0&&t.length>0&&n.length>0&&n.toLowerCase().startsWith(t.toLowerCase())}function j(t,e,n){let r=t.slice(e);if(n||e===0||t[e-1]===" ")return r;let i=r.indexOf(" ");return i===-1?"":r.slice(i+1)}function bn(t,e){let n=t.trimEnd().replace(/\s+/g," ");if(n.length===0||e.length===0)return 0;let r=n.split(" "),i=e.toLowerCase();for(let o=0;o<r.length;o++){let s=r.slice(o).join(" ");if(i.startsWith(s.toLowerCase())){let a=n.length-s.length;return t.length-a}}return 0}function z(t,e){if(!t)return[];let n=e.trimStart();if(!n)return t;let r=n.toLowerCase();return t.filter(i=>!i.is_tappable||i.text.toLowerCase().includes(r))}function ne(t,e){if(!t)return null;let n=e.trim();if(!n)return null;let r=n.toLowerCase();return t.find(i=>i.is_tappable&&i.text.toLowerCase()===r)??null}function Sn(t,e){return e?t.map(n=>e[n.parameter]?{...n,options:[]}:n):t}function si(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.toLowerCase())}function J(t){let e=si(t);return e.length>0?e.join(" "):t}function B(t,e){return t.parameter||e}function xn(t,e){let n=0,r=e;for(let i of t)n+=i.value.length,i.type!=="text"&&(r=Math.max(r,n));return r}function yn(t,e){let n=0;for(let r of t){let i=n+r.value.length;if(r.type==="text"&&i>e&&r.value.slice(Math.max(e-n,0)).trim().length>0)return!1;n=i}return!0}function vn(t,e){let n=[],r=new Set;for(let i of[...t,...e])i.parameter==="placeholder"||r.has(i.parameter)||(r.add(i.parameter),n.push({parameter:i.parameter,text:i.text}));return n}function En(t,e,n){if(t===e)return n;let r=Math.min(t.length,e.length),i=0;for(;i<r&&t[i]===e[i];)i++;if(i>=n)return n;let o=0;for(;o<r-i&&t[t.length-1-o]===e[e.length-1-o];)o++;return t.length-o<=n?n+(e.length-t.length):null}function Re(t,e){let n=[],r=[],i=0;for(let o of e){let s=H(t,o.text,i);if(s===-1){r.push(o);continue}n.push({start:s,end:s+o.text.length,param:o}),i=s+o.text.length}return{located:n,missing:r}}function Pn(t,e){let{located:n}=Re(t,e);return n.length>0?n[n.length-1].end:0}function wn(t,e,n){let r=[],i=[],o=0;for(let s of n){let a=H(t,s.text,o,l=>!e.some(d=>l<d.end&&l+s.text.length>d.start));if(a===-1){i.push(s);continue}r.push({start:a,end:a+s.text.length,param:s}),o=a+s.text.length}return{located:r,missing:i}}function Tn(t,e,n=[]){let r=Re(t,e).located,i=wn(t,r,n).located,o=[...r.map(d=>({start:d.start,end:d.end,segment:{type:"completed",value:d.param.text,param:d.param}})),...i.map(d=>({start:d.start,end:d.end,segment:{type:"identified",value:d.param.text,param:d.param}}))].sort((d,c)=>d.start-c.start),s=[],a=0;for(let d of o)d.start>a&&s.push({type:"text",value:t.slice(a,d.start)}),s.push(d.segment),a=d.end;let l=t.slice(a);return l&&s.push({type:"text",value:l}),s}function In(t,e){let{located:n,missing:r}=Re(t,e);return{valid:n.map(i=>i.param),invalid:r}}function fe(t,e,n){let r=Re(t,e).located,{located:i,missing:o}=wn(t,r,n);return{valid:i.map(s=>s.param),invalid:o}}function ai(t){if(t instanceof Error)return t;try{return new Error(String(t))}catch{return new Error("Unknown error")}}var li=100,di=300,ci=2,Me=class{constructor(e,n,r,i,o,s,a,l,d={}){this.store=e;this.getApiConfig=n;this.getOptionOverrides=r;this.getMaskCompletedText=i;this.getOnError=o;this.getSessionId=s;this.getSource=a;this.getAdditionalContext=l;this.callbacks=d;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,n=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(r=>{(r.text!==e||r.completedParams!==n)&&(e=r.text,n=r.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,n){this.abortController?.abort();let r=new AbortController;this.abortController=r;let i=++this.fetchVersion,o=this.store.get().text.length;try{this.callbacks.onRequest?.({query:this.store.get().text,signal:r.signal,isCurrent:()=>i===this.fetchVersion})}catch{}try{this.store.set({isLoading:!0,error:null});let s=this.store.get(),a=s.pendingSpan?vn(s.pendingSpan.snapshot,s.actionableSuggestions):void 0,l=crypto.randomUUID(),d=await gn(e,n,{sessionId:this.getSessionId(),requestId:l,source:this.getSource(),maskCompletedText:this.getMaskCompletedText(),signal:r.signal,apiConfig:this.getApiConfig(),identifiedParams:s.identifiedParams,recentlySuggested:a,skippedParams:s.skippedParams,additionalContext:this.getAdditionalContext()});if(i!==this.fetchVersion)return;let c=(d.data.input??[]).filter(v=>v.source==="identified").map(v=>({id:crypto.randomUUID(),parameter:v.parameter,text:v.text,...v.type?{type:v.type}:{}})),u=this.callbacks.isWordOpen?.()??!1,m=this.store.get().text.toLowerCase(),f=v=>u&&m.endsWith(v.text.toLowerCase()),h=c.filter(v=>!f(v));u&&this.callbacks.holdIdentified?.(c.filter(f));let x=Sn(d.data.suggestions??[],this.getOptionOverrides()),y=d.data.input??[],g=y[y.length-1],p=this.store.get().text,b,S;if(g?.state==="in_progress"){S=!0;let v=p.toLowerCase().lastIndexOf(g.text.toLowerCase());b=v!==-1?v:o}else S=!1,b=o;let w=x.filter(v=>v.parameter!=="placeholder")[0],O=null;if(w&&!u&&!E(X(w))){let v=j(p,b,S),I=ne(w.options,v);I&&(O={id:crypto.randomUUID(),placeholder:"",parameter:B(I,w.parameter),text:I.text,value:I.value,kind:I.kind,suggestionParameter:w.parameter,suggestionValueType:w.type,suggestionPlaceholder:w.text,options:w.options??[],metadata:I.metadata,icon:I.icon,icon_svg:I.icon_svg,image_url:I.image_url},x=x.filter(Q=>Q!==w),this.callbacks.onAutoMatch?.({active:w,matched:I,rawQuery:e}))}let k=d.data.custom_fields??null,T=this.callbacks.productsForResponse?.(k);this.store.set(v=>{let I=O?[...v.completedParams,O]:v.completedParams,Q=fe(v.text,I,h).valid,R=new Set(s.skippedParams.map(N=>N.id)),F=new Set(v.skippedParams.filter(N=>!R.has(N.id)).map(N=>N.parameter));return{suggestions:F.size>0?x.filter(N=>N.parameter==="placeholder"||!F.has(N.parameter)):x,isLoading:!1,isReady:d.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:b,filterInProgress:S,identifiedParams:Q,customFields:k,...T!==void 0?{products:T}:{},...O?{completedParams:I}:{}}}),this.callbacks.onResponse?.({requestId:l,funnelTelemetry:d.meta?.funnel_telemetry===!0})}catch(s){let a=ai(s);i===this.fetchVersion&&(this.store.set({error:a,isLoading:!1}),this.getOnError()?.(a))}finally{if(i===this.fetchVersion&&this.store.get().isLoading)try{this.store.set({isLoading:!1})}catch{}}}attemptNow(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}this.attemptFetch(1,!0)}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}this.debounceTimer=setTimeout(()=>{this.attemptFetch(ci)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},li),this.slowDebounceTimer=setTimeout(()=>this.attemptFetch(1),di)}attemptFetch(e,n=!1){let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let i=this.callbacks.consumerTick?.(r,e)??"no";if(i==="asked")return!0;if(i==="owns")return!1;let o=r.suggestions.filter(S=>S.parameter==="placeholder").map(S=>S.text).join(" "),s=q(r.text,r.filterBase,o),a=j(r.text,s,r.filterInProgress),d=r.suggestions.filter(S=>S.parameter!=="placeholder")[0],c=E(r.activeFormatType),m=(d&&!c?z(d.options,a):[]).filter(S=>S.is_tappable),f=d&&!c&&!this.callbacks.isWordOpen?.()?ne(d.options,a)!==null:!1,h=a.trim().length>0;if(m.length>0&&!f&&h||Le(r.text,r.completedParams.length,o))return!1;let{rawQuery:x,completedParams:y}=M(r.text,r.completedParams),g=x.length<r.lastRawQuery.length,p=Math.abs(x.length-r.lastRawQuery.length),b=n&&x!==r.lastRawQuery;return g||p>=e||b?(this.doFetch(x,y),!0):!1}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var re=["January","February","March","April","May","June","July","August","September","October","November","December"],ke=["S","M","T","W","T","F","S"],An=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Ln="aiaDate",Rn="aiaDay",Cn=t=>String(t).padStart(2,"0");function D(t){return`${t.getFullYear()}-${Cn(t.getMonth()+1)}-${Cn(t.getDate())}`}function at(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate())}function ui(t){let e=at(t).getTime()-at(new Date).getTime();return Math.round(e/864e5)}function Mn(t){let e=ui(t);return e>=0&&e<7?An[t.getDay()]:ie(t)}function ie(t){return t.getFullYear()===new Date().getFullYear()?`${re[t.getMonth()]} ${t.getDate()}`:`${re[t.getMonth()]} ${t.getDate()} ${t.getFullYear()}`}function De(t){if(!t)return null;let e=An.findIndex(a=>a.toLowerCase()===t.trim().toLowerCase());if(e>=0){let a=at(new Date),l=(e-a.getDay()+7)%7;return new Date(a.getFullYear(),a.getMonth(),a.getDate()+l)}let n=/^\s*([A-Za-z]+)\s+(\d{1,2})(?:\s+(\d{4}))?\s*$/.exec(t);if(!n)return null;let r=re.findIndex(a=>a.toLowerCase()===n[1].toLowerCase());if(r<0)return null;let i=Number(n[2]),o=n[3]?Number(n[3]):new Date().getFullYear(),s=new Date(o,r,i);return s.getMonth()!==r||s.getDate()!==i?null:s}function lt(t){return`${re[t.month]} ${t.year}`}function dt(){let t=new Date;return{year:t.getFullYear(),month:t.getMonth()}}function kn(t){return{year:t.getFullYear(),month:t.getMonth()}}function ct(t,e){let n=new Date(t.year,t.month+e,1);return{year:n.getFullYear(),month:n.getMonth()}}function On(){return{text:"",is_tappable:!1,kind:null}}function ut(t){let e=new Date(t.year,t.month,1).getDay(),n=new Date(t.year,t.month+1,0).getDate(),r=[];for(let i=0;i<e;i++)r.push(On());for(let i=1;i<=n;i++){let o=new Date(t.year,t.month,i);r.push({text:Mn(o),is_tappable:!0,kind:null,metadata:{[Ln]:D(o),[Rn]:i}})}for(;r.length%ke.length!==0;)r.push(On());return r}function pt(t){let e=De(t);return e?D(e):null}function W(t){let e=t?.metadata?.[Ln];return typeof e=="string"?e:null}function mt(t){let e=t?.metadata?.[Rn];return typeof e=="number"?e:null}function pi(t){return t.nodeType===Node.DOCUMENT_NODE?!0:t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in t}function Z(t){let e=typeof t.getRootNode=="function"?t.getRootNode():null;return e&&pi(e)?e:t.ownerDocument??t}function A(t){return t.ownerDocument??t}function mi(t){return t.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function Dn(t){let e=Z(t);return!mi(e)||typeof e.getSelection=="function"?null:e}function _n(t){let e=Dn(t);if(!e)return null;let n=A(t).getSelection?.();return!n||typeof n.getComposedRanges!="function"?null:e}function Nn(t,e){let n=t,r;try{r=n.getComposedRanges({shadowRoots:[e]})}catch{r=n.getComposedRanges(e)}return r.length>0?r[0]:null}function ft(t){let n=Z(t).getSelection?.();return n||(A(t).getSelection?.()??null)}function $(t){let e=ft(t);if(!e||e.rangeCount===0)return null;let n=_n(t);if(n){let r=Nn(e,n);return r?{node:r.startContainer,offset:r.startOffset,collapsed:r.startContainer===r.endContainer&&r.startOffset===r.endOffset}:null}return e.anchorNode?{node:e.anchorNode,offset:e.anchorOffset,collapsed:e.isCollapsed}:null}function _e(t){let e=ft(t);if(!e||e.rangeCount===0)return null;let n=_n(t);if(!n)return e.getRangeAt(0);let r=Nn(e,n);if(!r)return null;let i=A(t).createRange();return i.setStart(r.startContainer,r.startOffset),i.setEnd(r.endContainer,r.endOffset),i}function ge(t,e,n){let r=ft(t);if(!r)return null;if(Dn(t))return r.collapse(e,n),r;let i=A(t).createRange();return i.setStart(e,n),i.collapse(!0),r.removeAllRanges(),r.addRange(i),r}function Ne(t,e){let n=t?Z(t):typeof document<"u"?document:null;return n?typeof n.getElementById=="function"?n.getElementById(e):typeof document<"u"?document.getElementById(e):null:null}var Fe=2,fi="magicx-aia";function Fn(t){return t==="auto"||t==="scroll"||t==="hidden"||t==="overlay"}function gi(t){let e=A(t),n=e.defaultView;if(!n?.getComputedStyle)return null;let r=t;for(;r&&r!==e.body&&r!==e.documentElement;){let i=r.scrollWidth>r.clientWidth,o=r.scrollHeight>r.clientHeight;if(i||o){let s=n.getComputedStyle(r);if(i&&Fn(s.overflowX)||o&&Fn(s.overflowY))return r}if(r.classList.contains(fi))return null;r=r.parentElement}return null}function gt(t){let e=_e(t);if(!e||!e.collapsed||!t.contains(e.startContainer))return;let n=gi(t);if(!n||typeof e.getBoundingClientRect!="function")return;let r=e.getBoundingClientRect();if(r.height===0)return;let i=n.getBoundingClientRect();if(n.scrollWidth>n.clientWidth){let o=i.left+n.clientLeft,s=o+n.clientWidth;r.right>s?n.scrollLeft+=r.right-s+Fe:r.left<o&&(n.scrollLeft-=o-r.left+Fe)}if(n.scrollHeight>n.clientHeight){let o=i.top+n.clientTop,s=o+n.clientHeight;r.bottom>s?n.scrollTop+=r.bottom-s+Fe:r.top<o&&(n.scrollTop-=o-r.top+Fe)}}var Bn='[contenteditable="false"]',bt="strong[data-param-id]",oe;function hi(){if(oe!==void 0)return oe;let t=globalThis.Intl.Segmenter;if(!t)return oe=null,null;try{oe=new t(void 0,{granularity:"grapheme"})}catch{oe=null}return oe??null}function He(t,e){let n=t;for(;n&&n!==e;){if(n.nodeType===Node.ELEMENT_NODE&&n.matches(Bn))return!0;n=n.parentNode}return!1}function Be(t){return A(t).createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(e){return He(e,t)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function We(t){let e=Be(t),n="",r=e.nextNode();for(;r;)n+=r.data,r=e.nextNode();return n}function St(t){let e=Be(t),n=0,r=e.nextNode();for(;r;)n+=r.data.length,r=e.nextNode();return n}function _(t){let e=$(t);if(!e)return null;let n=e.node,r=e.offset;if(!t.contains(n))return null;if(n.nodeType===Node.ELEMENT_NODE){let i=n;if(He(i,t)&&i!==t)return null;let o=0;for(let s=0;s<r&&s<i.childNodes.length;s++)o+=xt(i.childNodes[s],t);return o+ht(i,t)}return n.nodeType!==Node.TEXT_NODE||He(n,t)?null:ht(n,t)+r}function xt(t,e){if(t.nodeType===Node.TEXT_NODE)return He(t,e)?0:t.data.length;if(t.nodeType!==Node.ELEMENT_NODE)return 0;let n=t;if(n.matches(Bn))return 0;let r=0;for(let i of Array.from(n.childNodes))r+=xt(i,e);return r}function ht(t,e){let n=Be(e),r=0,i=n.nextNode();for(;i;){if(i===t||t.nodeType===Node.ELEMENT_NODE&&t.contains(i))return r;r+=i.data.length,i=n.nextNode()}return r}function L(t,e){let n=A(t),r=Math.max(0,Math.min(e,St(t))),i=Be(t),o=0,s=null,a=0,l=i.nextNode(),d=null;for(;l;){let u=l.data.length;if(r<o+u){s=l,a=r-o;break}if(r===o+u){let m=i.nextNode();m?(s=m,a=0):(s=l,a=u);break}o+=u,d=l,l=i.nextNode()}let c=n.createRange();if(s){let u=s.parentElement?.closest('strong[data-seg="completed"]');u&&u!==t&&t.contains(u)?a===0?c.setStartBefore(u):a===s.data.length?c.setStartAfter(u):c.setStart(s,a):c.setStart(s,a)}else d?c.setStart(d,d.data.length):c.setStart(t,0);c.collapse(!0),ge(t,c.startContainer,c.startOffset)&&(bi(t,c,r),gt(t))}function Hn(t,e){if(!t||!e.contains(t))return null;let r=(t.nodeType===Node.ELEMENT_NODE?t:t.parentElement)?.closest(bt)??null;return r&&e.contains(r)?r:null}function bi(t,e,n){let r=Hn($(t)?.node??null,t);if(r&&r!==Hn(e.startContainer,t)){t.dataset.aiaCaretEscapedChip=`${n}:${r.dataset.paramId}`;return}delete t.dataset.aiaCaretEscapedChip}function Wn(t,e){let n=t.dataset.aiaCaretEscapedChip;if(!n)return!1;let r=_(t);return r!==null&&n===`${r}:${e}`}function qn(t){return Z(t).activeElement===t}function yt(t,e){if(!e||e.nodeType===void 0)return null;let n=e,i=(n.nodeType===Node.ELEMENT_NODE?n:n.parentElement)?.closest(bt);if(!i||!t.contains(i))return null;let o=$(t);return o&&!o.collapsed?null:i.dataset.paramId??null}function vt(t,e){let n=null;for(let s of t.querySelectorAll(bt))if(s.dataset.paramId===e){n=s;break}if(!n)return;let r=ht(n,t),i=r+xt(n,t),o=_(t);o!=null&&o>=r&&o<=i||L(t,r)}function Et(t){let e=_(t);return e==null?!1:e>=St(t)}function Pt(t,e){if(e<=0)return 0;let n=hi();if(!n)return e-1;let r=t.slice(0,e),i=0;for(let{index:o}of n.segment(r))o<e&&(i=o);return i}function ee(t,e,n=[],r={}){let{rawQuery:i,completedParams:o}=M(t,e);return{query:t.trim(),raw_query:i,completed_params:me(o,n),identified_params:pe(r.identifiedParams??[]),is_ready:r.isReady??!1,...r.customFields?{custom_fields:r.customFields}:{}}}function wt(t,e){return t instanceof HTMLTextAreaElement||t instanceof HTMLInputElement?t.selectionStart!=null&&t.selectionStart===t.value.length:t instanceof HTMLElement&&t.hasAttribute("data-aia-input")?Et(t):e?.caretOffset!=null?e.caretOffset>=e.text.length:!1}function Tt(t){return t instanceof HTMLElement&&t.hasAttribute("data-aia-input")?_(t):null}var qe=class{constructor(e,n){this.store=e;this.ctx=n}handleKeyDown(e){let n=this.store.get(),{listboxId:r,getOnSubmit:i}=this.ctx,o=e.target instanceof Node?e.target:null,s=this.getEffectiveColumns(o),a=i(),l=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 d=this.ctx.getOptionsPosition()==="above";switch(e.key){case"ArrowDown":{let c=wt(e.target,n),u=!!n.editingParam;if(!c&&!u&&n.activeDropdownIndex<0)break;if(n.activeDropdownIndex<0){if(d)break;e.preventDefault();let h=E(n.activeFormatType)?this.dateEntryIndex(n,!1):l[0]??0;if(!n.isDropdownOpen&&n.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:h});break}if(l.length===0)return;this.store.set({activeDropdownIndex:h});break}if(e.preventDefault(),l.length===0)return;if(E(n.activeFormatType)){this.stepDateWeek(n,7);break}if(n.filteredOptions.length>0){let h=Math.floor((n.filteredOptions.length-1)/s);if(Math.floor(n.activeDropdownIndex/s)===h){this.store.set({activeDropdownIndex:-1});break}}let m=l.indexOf(n.activeDropdownIndex),f=m<l.length-1?m+1:0;this.store.set({activeDropdownIndex:l[f]});break}case"ArrowUp":{if(n.activeDropdownIndex<0){if(!d)break;let m=wt(e.target,n),f=!!n.editingParam;if(!m&&!f)break;e.preventDefault();let h=E(n.activeFormatType)?this.dateEntryIndex(n,!0):this.firstTappableInBottomRow(s)??l[0]??0;if(!n.isDropdownOpen&&n.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:h});break}if(l.length===0)return;this.store.set({activeDropdownIndex:h});break}if(l.length===0)break;if(e.preventDefault(),E(n.activeFormatType)){this.stepDateWeek(n,-7);break}if(n.activeDropdownIndex<s){this.store.set({activeDropdownIndex:-1});break}let c=l.indexOf(n.activeDropdownIndex),u=c>0?c-1:l.length-1;this.store.set({activeDropdownIndex:l[u]});break}case"ArrowRight":{if(n.activeDropdownIndex>=0){if(e.preventDefault(),E(n.activeFormatType)){this.stepDateDay(n,1);break}if(n.activeDropdownIndex%s<s-1){let m=n.activeDropdownIndex+1;m<n.filteredOptions.length&&n.filteredOptions[m]?.is_tappable&&this.store.set({activeDropdownIndex:m})}break}if(n.editingParam&&e.target instanceof HTMLElement&&n.editingTail!=null){e.preventDefault();let u=e.target.closest("[data-aia-input]")??e.target,m=n.editingTail;this.ctx.exitEditMode?.(),L(u,m);break}wt(e.target,n)&&n.actionableSuggestions.length>=1&&(e.preventDefault(),this.ctx.skipActivePill());break}case"ArrowLeft":{if(n.activeDropdownIndex>=0){if(e.preventDefault(),E(n.activeFormatType)){this.stepDateDay(n,-1);break}if(n.activeDropdownIndex%s>0){let c=n.activeDropdownIndex-1;c>=0&&n.filteredOptions[c]?.is_tappable&&this.store.set({activeDropdownIndex:c});break}if(!n.editingParam&&this.ctx.startEditingParamAtCaret){let c=Tt(e.target);c!=null&&this.ctx.startEditingParamAtCaret(c)}break}if(n.editingParam&&e.target instanceof HTMLElement&&n.editingAnchor!=null){e.preventDefault();let c=e.target.closest("[data-aia-input]")??e.target,u=n.editingAnchor;this.ctx.exitEditMode?.(),L(c,u);break}if(this.ctx.startEditingParamAtCaret){let c=Tt(e.target);c!=null&&this.ctx.startEditingParamAtCaret(c)&&e.preventDefault()}break}case"Backspace":{if(n.editingParam||!this.ctx.removeParamAtCaret)break;let c=Tt(e.target);if(c==null)break;this.ctx.removeParamAtCaret(c)&&e.preventDefault();break}case"Enter":{if(e.preventDefault(),n.activeDropdownIndex>=0&&n.filteredOptions[n.activeDropdownIndex]?.is_tappable)this.clickOrSelect(n.activeDropdownIndex,n.filteredOptions,r,o);else if(a){this.ctx.endTypedWord?.();let c=this.store.get();a(ee(c.text,c.completedParams,c.skippedParams,{identifiedParams:c.identifiedParams,isReady:c.isReady,customFields:c.customFields}))&&this.ctx.afterSubmit?.()}break}case"Tab":{if(this.ctx.endTypedWord?.()){e.preventDefault();break}let c=n.filteredOptions.map((f,h)=>f.is_tappable?h:-1).filter(f=>f!==-1);if(c.length===0)break;if(!n.isDropdownOpen){if(n.actionableSuggestions.length===0)break;e.preventDefault();let f=e.shiftKey?c[c.length-1]:c[0];this.store.set({pillTapped:!0,activeDropdownIndex:f});break}e.preventDefault();let u=c.indexOf(n.activeDropdownIndex),m;if(u<0)m=e.shiftKey?c.length-1:0;else{let f=e.shiftKey?-1:1;m=(u+f+c.length)%c.length}this.store.set({activeDropdownIndex:c[m]});break}case"Escape":{if(n.dateRangeStart){this.store.set({pendingRangeStart:null});break}if(n.editingIdentified){this.ctx.exitEditingIdentified?.(),this.store.set({activeDropdownIndex:-1});break}if(n.editingParam&&e.target instanceof HTMLElement&&n.editingTail!=null){let c=e.target.closest("[data-aia-input]")??e.target,u=n.editingTail;this.ctx.exitEditMode?.(),L(c,u)}this.store.set({activeDropdownIndex:-1});break}}}firstTappableInBottomRow(e){let n=this.store.get();if(n.filteredOptions.length===0)return null;let i=Math.floor((n.filteredOptions.length-1)/e)*e;for(let o=i;o<n.filteredOptions.length;o++)if(n.filteredOptions[o]?.is_tappable)return o;return null}dateEntryIndex(e,n){let r=D(new Date),i=e.filteredOptions.findIndex(s=>W(s)===r);if(i>=0)return i;let o=e.filteredOptions.map((s,a)=>s.is_tappable?a:-1).filter(s=>s!==-1);return(n?o[o.length-1]:o[0])??0}stepDateDay(e,n){for(let r=e.activeDropdownIndex+n;r>=0&&r<e.filteredOptions.length;r+=n)if(e.filteredOptions[r]?.is_tappable){this.store.set({activeDropdownIndex:r});return}}stepDateWeek(e,n){let r=e.activeDropdownIndex+n;this.store.set({activeDropdownIndex:e.filteredOptions[r]?.is_tappable?r:-1})}getTappableIndices(e){let r=this.store.get().filteredOptions.map((o,s)=>o.is_tappable?s:-1).filter(o=>o!==-1),i=Array.from({length:e},()=>[]);for(let o of r)i[o%e].push(o);return i.flat()}getEffectiveColumns(e){let n=Ne(e,this.ctx.listboxId);if(!n)return this.ctx.columns;let i=Ne(e,`${this.ctx.listboxId}-option-0`)?.parentElement??null;for(;i;){let o=getComputedStyle(i).gridTemplateColumns;if(o&&o!=="none"){let s=o.split(" ").filter(Boolean).length;if(s>0)return s}if(i===n)break;i=i.parentElement}return this.ctx.columns}clickOrSelect(e,n,r,i){let o=Ne(i,`${r}-option-${e}`);o?o.click():this.ctx.selectOption(n[e])}};var $e=class{constructor(e,n,r={}){this.store=e;this.getOverrides=n;this.callbacks=r;this.unsubscribe=null;this.current=null;this.version=0;this.lastMiss=null;this.hasLoggedError=!1}start(){this.unsubscribe=this.store.subscribe(e=>this.sync(e)),this.sync(this.store.get())}dispose(){this.unsubscribe?.(),this.unsubscribe=null,this.cancel(),this.current=null}reset(){this.cancel(),this.current=null,this.lastMiss=null}refresh(){this.reset(),this.sync(this.store.get())}hasOverride(e){return!!this.getOverrides()?.[e]}owns(e,n){return this.hasOverride(e)&&!this.missCovers(e,n)}tick(e,n){let r=this.resolveTarget(e);if(!r||this.missCovers(r.parameter,r.query))return"no";let i=this.current;if(i&&i.key===r.key){if(i.query===r.query)return"owns";let o=Math.abs(r.query.length-i.query.length),s=r.query.length<i.query.length;if(n>1&&!s&&o<n)return"owns"}return this.ask(r),"asked"}sync(e){let n=this.resolveTarget(e);if(!n){this.current&&(this.cancel(),this.current=null),e.optionSearch&&this.store.set({optionSearch:null});return}this.current&&this.current.key===n.key||this.ask(n)}resolveTarget(e){if(E(e.activeFormatType)||e.editingIdentified)return null;let n=e.editingParam;if(n&&e.editingAnchor!=null)return this.hasOverride(n.suggestionParameter)?{mode:"edit",key:n.id,parameter:n.suggestionParameter,suggestion:{parameter:n.suggestionParameter,text:n.suggestionPlaceholder,required:!0,options:n.options},query:e.optionQuery}:null;let r=e.actionableSuggestions[0];return!r||!this.hasOverride(r.parameter)?null:{mode:"pill",key:r,parameter:r.parameter,suggestion:r,query:e.optionQuery}}missCovers(e,n){return this.lastMiss!=null&&this.lastMiss.parameter===e&&this.lastMiss.query===n}ask(e){this.cancel();let n=this.getOverrides()?.[e.parameter],r=++this.version;if(!n||this.missCovers(e.parameter,e.query)){this.current={key:e.key,parameter:e.parameter,query:e.query,abort:null},this.setSearch(e,"done");return}let i=new AbortController;this.current={key:e.key,parameter:e.parameter,query:e.query,abort:i};let o;try{o=n(e.query,i.signal,e.suggestion)}catch(s){this.logOnce(s),this.commit(e,[],r);return}if(Array.isArray(o)){this.commit(e,o,r);return}this.setSearch(e,"loading"),this.await(e,o,i.signal,r)}async await(e,n,r,i){let o;try{let s=await n;if(r.aborted||i!==this.version)return;o=Array.isArray(s)?s:[]}catch(s){if(r.aborted||i!==this.version||Si(s))return;this.logOnce(s),o=[]}this.commit(e,o,i)}commit(e,n,r){if(r!==this.version)return;let i=this.resolveTarget(this.store.get());if(!i||i.key!==e.key)return;n.length===0?this.lastMiss={parameter:e.parameter,query:e.query}:this.lastMiss?.parameter===e.parameter&&(this.lastMiss=null);let o={parameter:e.parameter,query:e.query,status:"done"};if(e.mode==="edit")this.store.set(s=>({editingParam:s.editingParam&&s.editingParam.id===e.key?{...s.editingParam,options:n}:s.editingParam,optionSearch:o}));else{let s={...e.suggestion,options:n};this.current&&this.current.key===e.key&&(this.current.key=s),this.store.set(a=>({suggestions:a.suggestions.map(l=>l===e.suggestion?s:l),optionSearch:o}))}n.length===0?this.callbacks.onMiss?.(e.mode,e.query):this.callbacks.onAnswer?.(e.mode,e.query)}setSearch(e,n){let r=this.store.get().optionSearch;r&&r.parameter===e.parameter&&r.query===e.query&&r.status===n||this.store.set({optionSearch:{parameter:e.parameter,query:e.query,status:n}})}cancel(){this.current?.abort?.abort(),this.version++}logOnce(e){this.hasLoggedError||(this.hasLoggedError=!0,console.warn("[AIAutocomplete] an optionOverrides entry threw or rejected \u2014 treated as no options. Later failures on this instance are not logged.",e))}};function Si(t){return t instanceof Error&&t.name==="AbortError"}var Ge=class{constructor(e,n={}){this.store=e;this.callbacks=n}setActivePill(e){let n=this.store.get(),r=n.suggestions.filter(d=>d.parameter!=="placeholder");if(e<0||e>=r.length)return;let i=r[e],o=r.filter((d,c)=>c!==e),s=n.suggestions.filter(d=>d.parameter==="placeholder");if(this.callbacks.onPillSelected){let{rawQuery:d}=M(n.text,n.completedParams);this.callbacks.onPillSelected({rawQuery:d,selectedPill:i.text,otherPills:o.map(c=>c.text)})}let a=[...s,i,...o],l=this.store.peek({suggestions:a}).filteredOptions.findIndex(d=>d.is_tappable);this.store.set({suggestions:a,pillTapped:!0,activeDropdownIndex:l})}removeLastParam(){this.store.get().completedParams.length!==0&&this.store.set(n=>({completedParams:n.completedParams.slice(0,-1),activeDropdownIndex:-1}))}};var Gn="/products/",$n="https://relative.invalid";function xi(t){if(!t)return;let e;try{e=new URL(t,`${$n}/`)}catch{return}if(!(e.protocol!=="http:"&&e.protocol!=="https:"))return t.startsWith("/")?e.origin===$n?t:void 0:/^https?:\/\//i.test(t)?t:void 0}function Vn(t){let e=xi(t.item_url)??yi(t);return{id:t.source_id,title:t.title,...e&&{url:e},imageUrl:t.image_url||null,...t.price&&{price:t.price},...t.vendor&&{vendor:t.vendor},...typeof t.available=="boolean"&&{available:t.available}}}function yi(t){if(!t.handle)return;let e=`${Gn}${encodeURIComponent(t.handle)}`;return t.variant_id?`${e}?variant=${encodeURIComponent(t.variant_id)}`:e}function It(t){return(t?.items.matched??[]).map(Vn)}var Ve=class{constructor(e,n,r=()=>!0){this.store=e;this.getConfig=n;this.isEnabled=r;this.hasLoggedError=!1}forResponse(e){if(!this.isEnabled())return[];if(!this.getConfig())return It(e)}async run(e,n,r){if(!this.isEnabled())return;let i=this.getConfig();if(!i)return;if(e.trim().length===0){this.clear(r);return}let o=()=>n.aborted||!r()||!this.owns(i);try{let s=await i.fetch(e,n);if(o())return;let a=i.transform(s),l=Array.isArray(a)?a:[],d=i.limit!=null?l.slice(0,i.limit):l;if(o())return;this.commit(d)}catch(s){if(n.aborted||vi(s)||(this.logOnce(s),o()))return;this.clear(r)}}owns(e){return this.isEnabled()&&this.getConfig()===e}resync(){let e=this.forResponse(this.store.get().customFields);this.commit(e??[])}clear(e){e()&&this.commit([])}commit(e){e.length===0&&this.store.get().products.length===0||this.store.set({products:e})}logOnce(e){this.hasLoggedError||(this.hasLoggedError=!0,console.warn("[AIAutocomplete] products.fetch/transform failed \u2014 the product strip is hidden. Later failures on this instance are not logged.",e))}};function vi(t){return t instanceof Error&&t.name==="AbortError"}function Ei(t){return t.replace(/(\d+)(?:st|nd|rd|th)\b/g,"$1")}function Un(t){let e=t.toLowerCase().replace(/\.$/,"");return e.length<3?-1:re.findIndex(n=>n.toLowerCase().startsWith(e))}function Pi(t,e,n){let r=new Date(n.getFullYear(),t,e);if(r.getMonth()!==t||r.getDate()!==e)return null;let i=new Date(n.getFullYear(),n.getMonth(),n.getDate());if(r>=i)return r;let o=new Date(n.getFullYear()+1,t,e);return o.getMonth()===t&&o.getDate()===e?o:null}function Kn(t,e,n){let r=new Date(t,e,n);return r.getMonth()===e&&r.getDate()===n?r:null}function he(t,e={}){if(!t)return null;let n=e.today??new Date,r=Ei(t.trim().toLowerCase()).replace(/\s+/g," "),i=/^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(r);if(i){let l=Kn(Number(i[1]),Number(i[2])-1,Number(i[3]));return l?D(l):null}let o=/^([a-z]+)\.? (\d{1,2})(?:,? (\d{4}))?$/.exec(r);if(o){let l=Un(o[1]);if(l>=0)return Ue(l,Number(o[2]),o[3],n)}let s=/^(\d{1,2}) (?:of )?([a-z]+)\.?(?:,? (\d{4}))?$/.exec(r);if(s){let l=Un(s[2]);if(l>=0)return Ue(l,Number(s[1]),s[3],n)}let a=/^(\d{1,2})[/\-.](\d{1,2})(?:[/\-.](\d{2,4}))?$/.exec(r);if(a){let l=Number(a[1]),d=Number(a[2]);return l>12&&d<=12?Ue(d-1,l,a[3],n):d>12&&l<=12?Ue(l-1,d,a[3],n):null}return null}function Ue(t,e,n,r){if(n){if(n.length!==4)return null;let o=Kn(Number(n),t,e);return o?D(o):null}let i=Pi(t,e,r);return i?D(i):null}function Ct(t,e={}){let n=t.isoDate;return typeof n=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(n)?n:he(t.text,e)}var Qn=" - ",At="aiaDateRangeStart",Lt="aiaDateRangeEnd";function be(t,e){return t<=e?{start:t,end:e}:{start:e,end:t}}var Ot=/^\d{4}-\d{2}-\d{2}$/;function Yn(t){if(!Ot.test(t))return null;let[e,n,r]=t.split("-").map(Number),i=new Date(e,n-1,r);return i.getMonth()===n-1&&i.getDate()===r?i:null}var wi=/\s+(?:to|through|thru|until|til|till)\s+/g,Ti=/[-–—]/g;function Ii(t){let e=[];for(let n of[wi,Ti]){n.lastIndex=0;let r=n.exec(t);for(;r!==null;)e.push([t.slice(0,r.index),t.slice(r.index+r[0].length)]),r=n.exec(t)}return e}function Ke(t,e={}){if(!t)return null;let n=new Set,r=null;for(let[i,o]of Ii(t.trim())){let s=he(i.trim(),e);if(!s)continue;let a=he(o.trim(),e);!a||a<s||(n.add(`${s}|${a}`),r={start:s,end:a})}return n.size===1?r:null}function Xn(t){let e=Yn(t.start),n=Yn(t.end);return!e||!n?"":t.start===t.end?ie(e):`${ie(e)}${Qn}${ie(n)}`}function jn(t,e){let n=be(t,e);return{text:Xn(n),is_tappable:!0,kind:null,metadata:{[At]:n.start,[Lt]:n.end}}}function Se(t,e={}){let n=t?.metadata?.[At],r=t?.metadata?.[Lt];return typeof n=="string"&&typeof r=="string"&&Ot.test(n)&&Ot.test(r)?be(n,r):Ke(t?.text,e)}var Ye="(max-width: 768px)";var Ci="var(--aia-option-row-height, 37px)",Oi="var(--aia-grid-scroll-top, 0px) + var(--aia-grid-scroll-bottom, 0px)";function zn(t,e){return e?Rt(1,Math.min(t,5)):Rt(1,Math.min(t,4))}function Rt(t,e){return{cols:t,rows:e,maxHeight:`calc(${e} * ${Ci} + ${Oi})`}}function kt(t,e){return!e&&t>=5}function Dt(t,e,n,r){if(!(!e&&t>=5&&Ai(n,r))){let s=zn(t,e);return{...s,template:Mt(s.cols),scrollHintIndices:!e&&t>s.rows?[s.rows-1]:[]}}let o=6;return{...Rt(2,3),template:Mt(2),scrollHintIndices:t>o?[o-2,o-1]:[]}}function Ai(t,e){return!t||t.length===0||e==null||e<=0||t.some(r=>r<=0)?!1:Math.ceil(Math.max(...t))*2<=e}function _t(t){if(typeof document>"u")return null;let e=Array.from(t.querySelectorAll("[data-aia-option]"));if(e.length===0)return null;let n=document.createElement("div");n.style.cssText="position:absolute;visibility:hidden;left:-9999px;top:0;";for(let s of e){let a=s.cloneNode(!0);a.removeAttribute("id"),a.removeAttribute("role"),a.removeAttribute("aria-selected"),a.style.whiteSpace="nowrap",a.style.width="max-content",n.appendChild(a)}t.appendChild(n);let r=Array.from(n.children).map(s=>s.offsetWidth);n.remove();let i=getComputedStyle(t),o=t.clientWidth-(Number.parseFloat(i.paddingLeft)||0)-(Number.parseFloat(i.paddingRight)||0)-(Number.parseFloat(i.columnGap)||0);return{rowWidths:r,gridWidth:o}}function Mt(t){return Array.from({length:t},()=>"minmax(0,1fr)").join(" ")}function Nt(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia(Ye).matches}function Ft(t,e){return!t||t.length!==e.length?!1:t.every((n,r)=>n.text===e[r].text)}function Jn(t,e){let n=e.dropdownTrigger??"auto",r=e.closeDropdownOnBlur??!0,s=t.filteredOptionsLength>0||t.activePillHasNoOptions||t.hasProducts;if(t.inEditMode){let a=r?t.isFocused:!0;return s&&a}if(n==="auto"){let a=r?t.isFocused:!0,l=t.text.replace(/\s+$/,"").length,d=t.caretOffset==null||t.caretOffset>=l;return(s||t.isLoading)&&a&&d}return n==="manual"?(s||t.isLoading)&&t.pillTapped:!1}function xe(t){if(t.editingIdentified){let{parameter:n,anchor:r}=t.editingIdentified;return`identified:${n}@${r}`}return t.editingParam!=null&&t.editingAnchor!=null?`edit:${t.editingParam?.id}`:`pill:${t.actionableSuggestions[0]?.parameter??""}`}function Zn(t){if(!t)return dt();let[e,n]=t.split("-").map(Number);return{year:e,month:n-1}}function Li(t){let e=De(t);return e?kn(e):dt()}function er(t,e){let n=Tn(t.text,t.completedParams,t.identifiedParams),r=t.suggestions.filter(C=>C.parameter!=="placeholder"),i=r[0],o=t.suggestions.filter(C=>C.parameter==="placeholder").map(C=>C.text).join(" "),s=q(t.text,Math.min(t.filterBase,t.text.length),o),l=s===0&&Le(t.text,t.completedParams.length,o)?"":j(t.text,s,t.filterInProgress),d=i?.options??[],c=t.editingParam!=null&&t.editingAnchor!=null,u,m,f,h;if(c&&t.editingParam&&t.editingAnchor!=null){let C=t.editingParam.id,te=t.completedParams.some(Jr=>Jr.id===C),ce=t.caretOffset??t.editingAnchor,dn=te?"":t.text.slice(t.editingAnchor,ce);m=dn.trim(),f=t.editingParam.options,h=t.editingParam.suggestionParameter,u=z(t.editingParam.options,dn)}else m=l.trim(),f=d,h=i?.parameter,u=z(d,l);let x=t.optionSearch,y=x!=null&&h!=null&&x.parameter===h;y&&x.status==="done"&&x.query===m&&(u=f);let g=y&&x.status==="loading",p=e.showNonTappableOptions===!1;p&&(u=u.filter(C=>C.is_tappable));let b=t.editingIdentified,S=c?t.editingParam&&{type:t.editingParam.suggestionValueType}:i,P=b?b.format:X(S),w=c&&P==="date-range"?Se(t.editingParam):null,O=null,k=null;if(E(P)){let C=xe({...t,actionableSuggestions:r}),te=t.dateViewMonth;O=te&&te.key===C?{year:te.year,month:te.month}:b?Zn(b.iso):w?Zn(w.start):Li(t.editingParam?.text),u=ut(O);let ce=t.pendingRangeStart;P==="date-range"&&ce&&ce.key===C&&(k=ce.iso)}let T=C=>p?C.is_tappable:!0,v;if(c){let C=t.editingParam?.options??[];v=t.editingParam!=null&&C.filter(T).length===0}else v=i!=null&&d.filter(T).length===0;let I=Jn({inEditMode:c||b!=null,filteredOptionsLength:u.length,isFocused:t.isFocused,text:t.text,caretOffset:t.caretOffset,isLoading:t.isLoading||g,pillTapped:t.pillTapped,activePillHasNoOptions:v,hasProducts:t.products.length>0},{dropdownTrigger:e.dropdownTrigger,closeDropdownOnBlur:e.closeDropdownOnBlur}),Q=I&&t.activeDropdownIndex>=0&&!!u[t.activeDropdownIndex]?.is_tappable,R=t.skeletonOptions!==null&&t.skeletonRequested&&!t.isLoading&&!t.editingParam&&!t.inSelectionAnimation,F=t.isLoading&&!t.editingParam&&!t.inSelectionAnimation||g||R,st=F&&t.skeletonOptions!==null,N=st&&t.skeletonOptions?t.skeletonOptions:u,zr=st?t.skeletonSuggestion:null;return{segments:n,actionableSuggestions:r,filteredOptions:u,dropdownLoading:F,dropdownOptions:N,dropdownSuggestion:zr,skeletonExiting:R,activeFormatType:P,dateView:O,dateRangeStart:k,placeholderText:o,optionQuery:m,isSearchingOptions:g,isDropdownOpen:I,isActivePillSelected:Q}}function Qe(t){return t.mode==="fresh"?Ri(t):Mi(t)}function Ri(t){let{text:e,completedParams:n,suggestions:r,filterBase:i,filterInProgress:o}=t,a=r.filter(S=>S.parameter!=="placeholder")[0];if(!a?.options)return null;let l=r.filter(S=>S.parameter==="placeholder").map(S=>S.text).join(" "),d=q(e,i,l),c=j(e,d,o),u=ne(a.options,c);if(!u)return null;let m=u.text.toLowerCase(),f=e.toLowerCase().lastIndexOf(m),h=f>=0?f:Math.max(0,e.length-u.text.length),x=h+u.text.length,y=e.slice(h,x),p=x<e.length&&e[x]===" "?x+1:x,b={id:crypto.randomUUID(),placeholder:"",parameter:B(u,a.parameter),text:y,value:u.value,kind:u.kind,suggestionParameter:a.parameter,suggestionValueType:a.type,suggestionPlaceholder:a.text,options:a.options??[],metadata:u.metadata,icon:u.icon,icon_svg:u.icon_svg,image_url:u.image_url};return{patch:{text:e,completedParams:[...n,b],suggestions:r.filter(S=>S!==a),filterBase:p,newParamId:b.id,caretOffset:p,activeDropdownIndex:-1},caretPos:p}}function Mi(t){let{text:e,completedParams:n,editingParam:r,editingAnchor:i,editingTail:o}=t;if(n.some(b=>b.id===r.id))return null;let s=e.slice(i,o),a=ne(r.options,s);if(!a)return null;let l=a.text.toLowerCase(),d=s.toLowerCase().lastIndexOf(l),c=i+Math.max(0,d),u=c+a.text.length,m=e.slice(c,u),f=u<e.length&&e[u]===" "?u+1:u,h=e.length,x={id:crypto.randomUUID(),placeholder:"",parameter:B(a,r.suggestionParameter),text:m,value:a.value,kind:a.kind,suggestionParameter:r.suggestionParameter,suggestionValueType:r.suggestionValueType,suggestionPlaceholder:r.suggestionPlaceholder,options:r.options,metadata:a.metadata,icon:a.icon,icon_svg:a.icon_svg,image_url:a.image_url},y=n.length,g=0;for(let b=0;b<n.length;b++){let S=H(e,n[b].text,g);if(S!==-1){if(S>=f){y=b;break}g=S+n[b].text.length}}let p=[...n];return p.splice(y,0,x),{patch:{text:e,completedParams:p,newParamId:x.id,filterBase:h,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:h,activeDropdownIndex:-1},caretPos:h}}var ki=6e4;function Di(t){return typeof TextEncoder>"u"?t.length*3:new TextEncoder().encode(t).length}function _i(t){return(t??Te).replace(/\/suggest(\?|#|$)/,"/telemetry/events$1")}async function Ni(t){return ue(t)?`Bearer ${await Ie(t).getToken()}`:Oe(t)}async function tr(t){try{let e=_i(t.apiConfig?.endpoint),n=Ce(t.apiConfig),r=await Ni(t.apiConfig);r&&(n.Authorization=r);let i=JSON.stringify({source:t.source,session_id:t.sessionId,...t.visitorId&&{visitor_id:t.visitorId},...t.requestId&&{request_id:t.requestId},type:t.type,at:new Date().toISOString(),query_data:t.queryData});await fetch(e,{method:"POST",headers:n,body:i,...t.keepalive&&Di(i)<=ki&&{keepalive:!0}})}catch{}}function se(t,e){let n=t.findIndex(r=>r.text===e);return n>=0?n+1:null}function nr(t,e){let n=t.actionableSuggestions[0];if(!n)return null;let r=t.filterBase,i=t.text.slice(0,r),o=i.length===0&&t.text.length===0,s=i.length===0&&t.text.length>0&&t.placeholderText.length>0&&t.placeholderText.toLowerCase().startsWith(t.text.toLowerCase());(o||s)&&t.placeholderText&&(i=`${t.placeholderText} `);let a=Math.min(Pn(t.text,t.completedParams),i.length),l=bn(i.slice(a),e.text);l>0&&(i=i.slice(0,i.length-l));let d=i.length>0&&i[i.length-1]!==" ",c=`${i}${d?" ":""}${e.text} `,u=(o||s)&&c.length>0?c[0].toUpperCase()+c.slice(1):c,m=u.toLowerCase().lastIndexOf(e.text.toLowerCase()),f=m>=0?u.slice(m,m+e.text.length):e.text,h={id:crypto.randomUUID(),placeholder:"",parameter:B(e,n.parameter),text:f,value:e.value,kind:e.kind,suggestionParameter:n.parameter,suggestionValueType:n.type,suggestionPlaceholder:n.text,options:n.options??[],metadata:e.metadata,icon:e.icon,icon_svg:e.icon_svg,image_url:e.image_url},x=t.actionableSuggestions.length-1;return{patch:{text:u,filterBase:u.length,completedParams:[...t.completedParams,h],newParamId:h.id,caretOffset:u.length,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:!0,inSelectionAnimation:!0,pendingSpan:null},telemetry:{selectedOption:e.text,otherOptions:t.filteredOptions.filter(y=>y.text!==e.text).map(y=>y.text),key:n.parameter,position:se(n.options??[],e.text)},consumedSuggestion:n,remainingActionable:x}}function Xe(t){let e=E(t.activeFormatType)||t.filteredOptions.length===0?null:t.filteredOptions,n=t.editingParam,r=n?{parameter:n.suggestionParameter,text:n.suggestionPlaceholder,required:!0,options:n.options}:t.actionableSuggestions[0]??null;return{skeletonOptions:e,skeletonSuggestion:e?r:null,skeletonRequested:!1}}function je(t,e,n){let r=t.slice(0,e),i=t.slice(n),o=(r===""||r.endsWith(" "))&&i.startsWith(" ");return o&&(i=i.slice(1)),{text:r+i,removed:n-e+(o?1:0)}}var ze=class{constructor(e){this.deps=e}start(e){let n=this.deps.store.get();if(n.editingParam?.id===e)return;let r=n.completedParams.find(s=>s.id===e);if(!r)return;let i=0,o=-1;for(let s of n.completedParams){let a=H(n.text,s.text,i);if(a!==-1){if(s.id===e){o=a;break}i=a+s.text.length}}o<0||this.deps.store.set({editingParam:r,editingAnchor:o,editingTail:o+r.text.length,caretOffset:o+r.text.length,activeDropdownIndex:-1,editingIdentified:null})}exit(){this.deps.store.get().editingParam&&this.deps.store.set({editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1})}replaceRange(e){let n=this.deps.store.get(),r=n.editingParam,i=n.editingAnchor,o=n.editingTail;if(!r||i==null||o==null||!n.completedParams.some(l=>l.id===r.id))return!1;let{text:s}=e===""?je(n.text,i,o):{text:n.text.slice(0,i)+e+n.text.slice(o)},a=i+e.length;return this.deps.store.set(l=>({text:s,completedParams:l.completedParams.filter(d=>d.id!==r.id),editingTail:a,caretOffset:a,activeDropdownIndex:-1})),this.deps.scheduleSetCursor(a),this.promoteIfExact(),!0}caretAfterInput(e){let n=this.deps.store.get(),r={caretOffset:e};n.editingParam&&n.editingAnchor!=null&&e!=null&&(e<n.editingAnchor?(r.editingParam=null,r.editingAnchor=null,r.editingTail=null,r.activeDropdownIndex=-1):n.editingTail!=null&&(r.editingTail=Math.max(n.editingTail,e))),this.deps.store.set(r),this.promoteIfExact()}caretMove(e){let n=this.deps.store.get();if(n.editingParam&&n.editingAnchor!=null&&n.editingTail!=null&&e!=null&&(e<n.editingAnchor||e>n.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 n=this.deps.store.get(),r=n.editingParam,i=n.editingAnchor,o=n.editingTail;if(!r||i==null||o==null)return;this.deps.fireTelemetry("option",{raw_query:M(n.text,n.completedParams).rawQuery,selected_option:e.text,other_options:r.options.filter(g=>g.text!==e.text).map(g=>g.text),key:r.suggestionParameter,position:se(r.options,e.text)});let s=n.text.slice(0,i),a=n.text.slice(o),l=i===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,c=a.length===0||a[0]!==" "?`${l} `:l,u=s+c+a,m=u.length,f={id:crypto.randomUUID(),placeholder:"",parameter:B(e,r.suggestionParameter),text:l,value:e.value,kind:e.kind,suggestionParameter:r.suggestionParameter,suggestionValueType:r.suggestionValueType,suggestionPlaceholder:r.suggestionPlaceholder,options:r.options,metadata:e.metadata,icon:e.icon,icon_svg:e.icon_svg,image_url:e.image_url},h=n.completedParams.findIndex(g=>g.id===r.id),x=n.completedParams.filter(g=>g.id!==r.id),y=h>=0?Math.min(h,x.length):x.length;x.splice(y,0,f),this.deps.store.set({text:u,completedParams:x,newParamId:f.id,filterBase:m,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:m,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0,...Xe(n)}),this.deps.startSelectionAnimationTimer(),this.deps.scheduleSetCursor(m),this.deps.fetchNow()}promoteIfExact(){let e=this.deps.store.get();if(!e.editingParam||e.editingAnchor==null||e.editingTail==null)return;let n=Qe({mode:"edit",text:e.text,completedParams:e.completedParams,editingParam:e.editingParam,editingAnchor:e.editingAnchor,editingTail:e.editingTail});n&&(this.deps.store.set(n.patch),this.deps.scheduleSetCursor(n.caretPos))}};var Fi=33,Hi=70,Bi=120,Wi=50,ae="data-aia-placeholder-leaving",le=new WeakMap;function Je(t){t.timer!==null&&(clearTimeout(t.timer),t.timer=null)}function qi(t){return t.closest('[data-animations="off"]')?!0:!!t.ownerDocument?.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches}function ir(t,e,n){e.shown=n,t.dataset.placeholder=e.target.slice(0,n)}function or(t,e){if(e.timer=null,!t.isConnected||e.shown>=e.target.length||(ir(t,e,e.shown+1),e.shown>=e.target.length))return;let n=e.target[e.shown-1],r=n===" "||n==="-"?70:0;e.timer=setTimeout(()=>or(t,e),33+r)}function rr(t,e){ir(t,e,0),e.timer=setTimeout(()=>or(t,e),33)}function sr(t,e){let n=le.get(t);if(e===""){n&&(Je(n),le.delete(t)),t.removeAttribute(ae),delete t.dataset.placeholder;return}if(n?.target===e)return;if(qi(t)){n&&Je(n),t.removeAttribute(ae),le.set(t,{target:e,shown:e.length,timer:null}),t.dataset.placeholder=e;return}let r={target:e,shown:0,timer:null},i=n&&n.shown>0?n:null;if(n&&Je(n),le.set(t,r),i){t.setAttribute(ae,""),r.timer=setTimeout(()=>{r.timer=null,t.removeAttribute(ae),t.isConnected&&rr(t,r)},170);return}t.removeAttribute(ae),rr(t,r)}function ar(t){let e=le.get(t);e&&(Je(e),le.delete(t))}var lr="https://ai-autocomplete.com";function Ht(t=lr){try{if(typeof window>"u"||!window.location)return t;let e=window.location.hostname;if(!e)return t;let n=new URL(t);return n.searchParams.set("utm_source",e),n.toString()}catch{return t}}function Bt(t,e){return t?{key:"enter",hint:"to proceed"}:e?{key:"tab",hint:"to select"}:{key:"\u2192",hint:"to skip"}}function Wt(t){let e=s=>{s.ctrlKey||dr(s.target,t,s.deltaX,s.deltaY)||s.preventDefault()},n=0,r=0,i=s=>{let a=s.touches[0];a&&(n=a.clientX,r=a.clientY)},o=s=>{if(s.touches.length!==1)return;let a=s.touches[0],l=n-a.clientX,d=r-a.clientY;n=a.clientX,r=a.clientY,s.cancelable&&!dr(s.target,t,l,d)&&s.preventDefault()};return t.addEventListener("wheel",e,{passive:!1}),t.addEventListener("touchstart",i,{passive:!0}),t.addEventListener("touchmove",o,{passive:!1}),()=>{t.removeEventListener("wheel",e),t.removeEventListener("touchstart",i),t.removeEventListener("touchmove",o)}}function dr(t,e,n,r){let i=t instanceof Element?t:null;for(;i;){if(r!==0&&$i(i,r)||n!==0&&Gi(i,n))return!0;if(i===e)break;i=i.parentElement}return!1}var cr=/^(auto|scroll|overlay)$/;function $i(t,e){return t.scrollHeight<=t.clientHeight||!cr.test(getComputedStyle(t).overflowY)?!1:e>0?t.scrollTop+t.clientHeight<t.scrollHeight-1:t.scrollTop>0}function Gi(t,e){if(t.scrollWidth<=t.clientWidth)return!1;let n=getComputedStyle(t);if(!cr.test(n.overflowX))return!1;let r=Math.abs(t.scrollLeft),i=t.scrollWidth-t.clientWidth;return(n.direction==="rtl"?e<0:e>0)?r<i-1:r>0}var ur=new WeakMap,pr=new WeakSet;function G(t,e,n){if(ur.set(t,n),pr.has(t))return;pr.add(t);let r=()=>ur.get(t),i=o=>{if(!(o instanceof Element))return null;let s=o.closest(e.itemSelector);return s&&t.contains(s)?s:null};e.onClick&&t.addEventListener("click",o=>{let s=i(o.target);s&&e.onClick?.(s,r(),o)}),e.onEnter&&t.addEventListener("mouseenter",o=>{let s=o.target;s instanceof HTMLElement&&s.matches(e.itemSelector)&&e.onEnter?.(s,r())},!0),e.onLeave&&t.addEventListener("mouseleave",o=>{let s=o.target;s instanceof HTMLElement&&s.matches(e.itemSelector)&&e.onLeave?.(s,r())},!0),e.preventMousedown&&t.addEventListener("mousedown",o=>o.preventDefault())}function V(t){return Number.parseInt(t.dataset.aiaIndex??"-1",10)}function U(t){t.offsetWidth}var Vi={selectedIso:null,selectedRange:null,rangeStart:null};function ye(t){if(!E(t.activeFormatType))return Vi;let e=t.editingIdentified;if(e){let{iso:r,isoEnd:i}=e;return{selectedIso:i?null:r,selectedRange:r&&i?be(r,i):null,rangeStart:t.dateRangeStart}}let n=Se(t.editingParam);return{selectedIso:n?null:pt(t.editingParam?.text),selectedRange:n,rangeStart:t.dateRangeStart}}function qt(t){return t.pendingStart?be(t.pendingStart,t.highlightedIso??t.pendingStart):t.selected}function $t(t,e){if(t==null)return{selected:!1,inRange:!1};let{selectedIso:n,range:r}=e,i=t===n||r!=null&&(t===r.start||t===r.end),o=r!=null&&t>r.start&&t<r.end;return{selected:i,inRange:o}}var mr="data-aia-key";function K(t,e,n){let r=new Map;for(let s of Array.from(t.children)){let a=s.getAttribute(mr);a!=null&&r.set(a,s)}let i=new Set,o=[];for(let s=0;s<e.length;s++){let a=e[s],l=n.keyOf(a,s);i.add(l);let d=r.get(l);d||(d=n.create(a,s),d.setAttribute(mr,l)),n.update?.(d,a,s),t.children[s]!==d&&t.insertBefore(d,t.children[s]??null),o.push(d)}for(let[s,a]of r)i.has(s)||a.remove();return o}function fr(t,e){if(!e.interactive)return null;let n=e.options[V(t)];return n?.is_tappable?n:null}var Ui={itemSelector:"[data-aia-date-cell], [data-aia-date-prev], [data-aia-date-next]",onClick:(t,e)=>{if(t.hasAttribute("data-aia-date-prev")){e.callbacks.onPreviousMonth();return}if(t.hasAttribute("data-aia-date-next")){e.callbacks.onNextMonth();return}let n=fr(t,e);n&&(t.classList.add("magicx-aia-date-cell--pressed"),e.callbacks.onSelect(n),setTimeout(()=>t.classList.remove("magicx-aia-date-cell--pressed"),170))},onEnter:(t,e)=>{t.hasAttribute("data-aia-date-cell")&&fr(t,e)&&e.callbacks.onHighlight(V(t))},onLeave:(t,e)=>{t.hasAttribute("data-aia-date-cell")&&e.callbacks.onHighlight(-1,V(t))}};function hr(t,e,n,r,i,o,s,a=!0){let l=t.querySelector(".magicx-aia-datepicker");if(!i||e.length===0){l?.remove();return}if(!l){l=Qi(),t.appendChild(l),U(l);for(let u of l.querySelectorAll(".magicx-aia-datepicker-nav"))u.disabled=!1}G(l,Ui,{options:e,callbacks:s,interactive:a});let d=l.querySelector(".magicx-aia-datepicker-month");d&&(d.textContent=lt(i));let c=l.querySelector(".magicx-aia-datepicker-grid");c&&Ki(c,e,n,r,o)}function Ki(t,e,n,r,i){let o=D(new Date),s=qt({pendingStart:i.rangeStart,highlightedIso:W(e[n]),selected:i.selectedRange});K(t,e,{keyOf:(a,l)=>W(a)??`pad-${l}`,create:a=>Yi(a),update:(a,l,d)=>{let c=W(l),u=$t(c,{selectedIso:i.selectedIso,range:s}),m=d===n&&l.is_tappable;a.id=`${r}-option-${d}`,a.dataset.aiaIndex=String(d),a.setAttribute("aria-selected",String(m)),a.classList.toggle("magicx-aia-date-cell--past",c!=null&&c<o),a.classList.toggle("magicx-aia-date-cell--highlighted",m),a.classList.toggle("magicx-aia-date-cell--today",c!=null&&c===o),a.classList.toggle("magicx-aia-date-cell--selected",u.selected),a.classList.toggle("magicx-aia-date-cell--in-range",u.inRange)}})}function Yi(t){let e=document.createElement("div");e.setAttribute("role","option"),e.setAttribute("data-aia-option",""),e.setAttribute("data-aia-date-cell","");let n=mt(t);if(n==null)return e.className="magicx-aia-date-cell magicx-aia-date-cell--blank",e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e;e.className="magicx-aia-date-cell magicx-aia-date-cell--day",e.tabIndex=0,e.setAttribute("aria-label",t.text);let r=document.createElement("span");return r.className="magicx-aia-date-cell-number",r.textContent=String(n),e.appendChild(r),e}function Qi(){let t=document.createElement("div");t.className="magicx-aia-datepicker",t.setAttribute("data-aia-datepicker","");let e=document.createElement("div");e.className="magicx-aia-datepicker-header";let n=document.createElement("span");n.className="magicx-aia-datepicker-month",n.setAttribute("data-aia-date-month",""),n.setAttribute("aria-live","polite"),e.append(gr("prev","Previous month","\u2039"),n,gr("next","Next month","\u203A"));let r=document.createElement("div");r.className="magicx-aia-datepicker-weekdays",r.setAttribute("aria-hidden","true");for(let o of ke){let s=document.createElement("span");s.className="magicx-aia-datepicker-weekday",s.textContent=o,r.appendChild(s)}let i=document.createElement("div");return i.className="magicx-aia-datepicker-grid",i.setAttribute("data-aia-date-grid",""),t.append(e,r,i),t}function gr(t,e,n){let r=document.createElement("button");return r.type="button",r.tabIndex=-1,r.className="magicx-aia-datepicker-nav",r.setAttribute(`data-aia-date-${t}`,""),r.setAttribute("aria-label",e),r.textContent=n,r.disabled=!0,r}var Xi={itemSelector:"[data-aia-pill]",onClick:(t,e)=>{if(e.loading||t.disabled)return;let n=Number.parseInt(t.dataset.aiaPillIndex??"-1",10);n>=0&&e.onSelectPill(n)},preventMousedown:!0},br=[125,69];function Sr(t,e){return e?1:t===0?.7:t===1?.4:.2}function Ze(t,e,n,r,i=!1,o=!1,s=!1){let a=t.querySelector(".magicx-aia-pill-list");if(a||(a=document.createElement("span"),a.className="magicx-aia-pill-list",t.appendChild(a)),G(a,Xi,{onSelectPill:r,loading:o}),o&&e.length===0){a.setAttribute("data-aia-pill-list-loading",""),a.innerHTML="";for(let l=0;l<br.length;l++){let d=br[l],c=document.createElement("span");c.setAttribute("data-aia-pill-skeleton",""),c.className=`magicx-aia-pill magicx-aia-pill--skeleton${i?" magicx-aia-pill--rounded":""}`,c.style.width=`${d}px`,c.style.opacity=String(Sr(l,!1)),a.appendChild(c)}return}o?a.setAttribute("data-aia-pill-list-loading",""):a.removeAttribute("data-aia-pill-list-loading");for(let l of a.querySelectorAll("[data-aia-pill-skeleton]"))l.remove();K(a,e,{keyOf:l=>`${l.parameter}-${l.text}`,create:l=>{let d=document.createElement("button");return d.type="button",d.tabIndex=-1,d.setAttribute("data-aia-pill",""),d.setAttribute("contenteditable","false"),d.textContent=l.text,d.disabled=!0,d},update:(l,d,c)=>{let u=l,m=s&&c===n&&!o,f=["magicx-aia-pill"];i&&f.push("magicx-aia-pill--rounded"),o&&f.push("magicx-aia-pill--skeleton"),u.className=f.join(" "),u.style.width="",u.style.opacity=String(Sr(c,m)),u.dataset.aiaPillIndex=String(c),o?u.setAttribute("data-aia-loading",""):u.removeAttribute("data-aia-loading")}}),U(a);for(let l of a.querySelectorAll("[data-aia-pill]"))l.disabled=o}function Gt(t){t.querySelector(".magicx-aia-pill-list")?.remove()}var ji=32;function xr(t,e){if(e.ctrlKey)return null;let n=e.deltaY||0,r=e.deltaX||0;if(!n||Math.abs(r)>=Math.abs(n))return null;let i=t.scrollWidth-t.clientWidth;if(i<=1)return null;let o=t.scrollLeft,s=n;return e.deltaMode===1?s*=32:e.deltaMode===2&&(s*=t.clientWidth),Math.max(0,Math.min(i,o+s))}function Vt(t){let e=n=>{let r=xr(t,n);r!==null&&(n.preventDefault(),t.scrollLeft=r)};return t.addEventListener("wheel",e,{passive:!1}),()=>t.removeEventListener("wheel",e)}var yr=Intl.Segmenter,vr=yr?new yr(void 0,{granularity:"grapheme"}):null;function Ut(t){let e=t.trim().normalize("NFC").toUpperCase();if(vr)for(let n of vr.segment(e))return n.segment;return Array.from(e)[0]??"?"}var Kt=new WeakMap,Er=new WeakMap,zi="Products";function Pr(t,e,n,r,i,o="row",s="image"){let a=t.querySelector(".magicx-aia-products");if(e.length===0){a?.remove();return}if(!a){a=document.createElement("section"),a.className="magicx-aia-products",a.setAttribute("data-aia-products",""),a.setAttribute("role","group"),a.setAttribute("aria-labelledby",`${n}-products-label`);let d=document.createElement("div");d.className="magicx-aia-products-label",d.id=`${n}-products-label`,d.setAttribute("data-aia-products-label",""),d.textContent=zi;let c=document.createElement("div");c.className="magicx-aia-products-row",c.setAttribute("data-aia-products-row",""),Vt(c),a.append(d,c),t.appendChild(a)}a.setAttribute("data-aia-products-layout",o);let l=a.querySelector(".magicx-aia-products-row");if(l){K(l,e,{keyOf:d=>Zi(d),create:d=>eo(d,r,i,s),update:(d,c,u)=>{d.id=`${n}-product-${u}`,d.dataset.aiaIndex=String(u),Er.get(d)?.(s)}}),U(l);for(let d of l.querySelectorAll("[data-aia-product]")){let c=Kt.get(d);c&&(Kt.delete(d),c())}}}function Yt(t,e){let n=t.querySelectorAll("[data-aia-product]");for(let r of n)r.tabIndex=e?0:-1}var Ji="Sold out";function Zi(t){return[t.id,t.title,t.url,t.imageUrl,t.price,t.vendor,t.available===!1?"sold-out":""].map(e=>e??"").join("\0")}function eo(t,e,n,r){let i=document.createElement("a");i.className="magicx-aia-product",i.setAttribute("data-aia-product",""),i.setAttribute("role","option"),i.setAttribute("aria-selected","false"),i.tabIndex=0;let o=document.createElement("span");o.className="magicx-aia-product-media",o.setAttribute("aria-hidden","true");let s=t.imageUrl?.trim(),a=!!s,l=()=>{o.replaceChildren(),o.toggleAttribute("data-aia-product-placeholder",r==="image"),o.toggleAttribute("data-aia-product-initial",r==="initial"),r==="initial"&&(o.textContent=Ut(t.title))};if(Er.set(i,u=>{u!==r&&(r=u,a||l())}),s){let u=document.createElement("img");u.onerror=()=>{a=!1,l()},u.className="magicx-aia-product-image",u.src=s,u.alt="",u.loading="lazy",u.decoding="async",o.appendChild(u)}else l();i.appendChild(o);let d=document.createElement("span");if(d.className="magicx-aia-product-body",t.vendor){let u=document.createElement("span");u.className="magicx-aia-product-vendor",u.textContent=t.vendor,d.appendChild(u)}let c=document.createElement("span");if(c.className="magicx-aia-product-title",c.textContent=t.title,d.appendChild(c),t.price){let u=document.createElement("span");u.className="magicx-aia-product-price",u.textContent=t.price,d.appendChild(u)}if(t.available===!1){i.setAttribute("data-aia-product-sold-out","");let u=document.createElement("span");u.className="magicx-aia-product-badge",u.textContent=Ji,d.appendChild(u)}return i.appendChild(d),Kt.set(i,()=>{t.url&&(i.href=t.url),i.addEventListener("click",u=>{u.metaKey||u.ctrlKey||u.shiftKey||u.altKey||u.button!==0||(u.preventDefault(),e(t))})}),i.addEventListener("keydown",u=>{u.key!=="Enter"&&u.key!==" "||(u.preventDefault(),e(t))}),i.addEventListener("focus",()=>n(!0)),i.addEventListener("blur",u=>{u.relatedTarget?.closest("[data-aia-dropdown]")||n(!1)}),i}var to=80,no=150,ro=280,io=16,Qt="--aia-option-enter-delay";function Xt(t,e,n,r="below"){let i=Math.max(1,Math.floor(e)),o=Math.floor(Math.max(0,t)/i);if(r!=="above")return o*80;let s=Math.max(1,Math.ceil(Math.max(0,n)/i));return Math.max(0,s-1-o)*80}function jt(t,e){let n=Math.max(1,Math.floor(e));return(Math.max(1,Math.ceil(Math.max(0,t)/n))-1)*80+280}function Y(t){if(!t)return null;let e=t.trim();if(e==="")return null;let n;try{n=new URL(e,typeof document>"u"?void 0:document.baseURI)}catch{return null}return n.protocol!=="http:"&&n.protocol!=="https:"?null:n.href}function ve(t){return t===void 0||!Number.isInteger(t)||t<0?null:t.toLocaleString()}var wr={one:"item",other:"items"};function oo(t,e=wr){let n=ve(t);if(n===null)return null;let r=typeof e=="string"?e:t===1?e.one:e.other;return r===""?n:`${n} ${r}`}function so(t){return Y(t.image_url)!==null}var Tr="http://www.w3.org/2000/svg",ao=new Set(["svg","g","path","circle","ellipse","line","polyline","polygon","rect"]);function lo(t,e){let n=t.toLowerCase();return n.startsWith("on")||n.includes("href")||n==="style"||n==="xml:base"||n==="id"||n==="name"||/^\s*javascript:/i.test(e)||/url\s*\(\s*['"]?\s*[^#'"\s)]/i.test(e)}var co=["fill","stroke","stroke-width","stroke-linecap","stroke-linejoin","fill-rule","clip-rule","opacity","fill-opacity","stroke-opacity"],uo=/^[a-zA-Z0-9#.,%\s()-]+$/;function po(t){let e=[];for(let n of co){let r=t.getAttribute(n);r===null||!uo.test(r)||/url\s*\(/i.test(r)||e.push(`${n}: ${r.trim()}`)}e.length>0&&t.setAttribute("style",e.join("; "))}function Ir(t){for(let e of Array.from(t.attributes))lo(e.name,e.value)&&t.removeAttribute(e.name);po(t);for(let e of Array.from(t.childNodes))if(e.nodeType===Node.ELEMENT_NODE){let n=e;!ao.has(n.localName)||n.namespaceURI!==Tr?n.remove():Ir(n)}else e.remove()}function Ee(t){if(typeof DOMParser>"u"||typeof XMLSerializer>"u")return null;let e=new DOMParser().parseFromString(t,"image/svg+xml"),n=e.documentElement;return!n||n.localName!=="svg"||n.namespaceURI!==Tr||e.getElementsByTagName("parsererror").length>0?null:(Ir(n),n.setAttribute("aria-hidden","true"),n.setAttribute("focusable","false"),new XMLSerializer().serializeToString(n))}function zt(t){return t.text}var Cr=new WeakMap;function mo(t,e,n){let r=e.length,i=Nt(),o=Cr.get(t),s=n&&o&&Ft(o.options,e)?o.plan:null,a=!s&&!n&&kt(r,i)?_t(t):null,l=s??Dt(r,i,a?.rowWidths??null,a?.gridWidth??null);return n||Cr.set(t,{options:e,plan:l}),t.style.gridTemplateColumns=l.template,t.style.setProperty("--aia-grid-max-height",l.maxHeight),t.querySelectorAll("[data-aia-option]").forEach((d,c)=>{d.classList.toggle("magicx-aia-option--scroll-hint",!n&&l.scrollHintIndices.includes(c))}),l.cols}function Or(t,e){if(e.loading||!e.interactive)return null;let n=e.options[V(t)];return n?.is_tappable?n:null}var fo={itemSelector:"[data-aia-option]",onClick:(t,e)=>{let n=Or(t,e);n&&(t.classList.add("magicx-aia-option--pressed"),e.onSelect(n),setTimeout(()=>t.classList.remove("magicx-aia-option--pressed"),170))},onEnter:(t,e)=>{Or(t,e)&&e.onHighlight(V(t))},onLeave:(t,e)=>e.onHighlight(-1,V(t))};function Ar(t,e,n,r,i,o,s,a="",l="below",d=!0,c=!0,u=!0,m=!0){let f=t.querySelector(".aia-grid");if(e.length===0){f?.remove();return}f||(f=document.createElement("div"),f.className="aia-grid magicx-aia-grid",f.setAttribute("data-scroll",""),f.style.setProperty("--aia-grid-min","250px"),f.style.setProperty("--aia-grid-max","1fr"),f.style.setProperty("--aia-grid-gap","0"),t.appendChild(f)),G(f,fo,{options:e,onSelect:r,onHighlight:i,loading:s,interactive:m});let h=f.dataset.aiaGroup!==a;f.dataset.aiaGroup=a,go(f,e,n,o,s,{showIcons:d,showImages:c,showCounts:u});let x=mo(f,e,s);ho(f,e.length,x,s,l),h&&(f.scrollTop=0)}function go(t,e,n,r,i,o){let s=i?"1":"0",a=t.dataset.aiaGroup??"",{showIcons:l,showImages:d,showCounts:c}=o,u=l?h=>h.icon??h.icon_svg??"":()=>"",m=d?h=>Y(h.image_url)??"":()=>"",f=c?h=>ve(h.item_count)??"":()=>"";K(t,e,{keyOf:h=>`${h.text}\0${u(h)}\0${m(h)}\0${f(h)}\0${s}\0${a}`,create:(h,x)=>{let y=bo(h,i,o);return i||(y.dataset.aiaEntering=""),y},update:(h,x,y)=>{let g=y===n&&!i;h.id=`${r}-option-${y}`,h.dataset.aiaIndex=String(y),h.setAttribute("aria-selected",String(g)),h.classList.toggle("magicx-aia-option--highlighted",g)}})}function ho(t,e,n,r,i){for(let o of t.querySelectorAll("[data-aia-entering]")){if(!r){let s=Number.parseInt(o.dataset.aiaIndex??"-1",10);s>=0&&o.style.setProperty(Qt,`${Xt(s,n,e,i)}ms`)}delete o.dataset.aiaEntering}}function bo(t,e,{showIcons:n,showImages:r,showCounts:i}){let o=document.createElement("div");o.setAttribute("role","option"),o.setAttribute("data-aia-option",""),e&&o.setAttribute("data-aia-loading",""),o.tabIndex=e||!t.is_tappable?-1:0;let s=["magicx-aia-option"];t.is_tappable?s.push("magicx-aia-option--tappable"):s.push("magicx-aia-option--non-tappable"),o.className=s.join(" ");let a=document.createElement("span");a.className="magicx-aia-option-content";let l=r?Y(t.image_url):null;if(l){let m=document.createElement("span");m.className="magicx-aia-option-image",m.setAttribute("aria-hidden","true");let f=document.createElement("img");f.setAttribute("alt",""),f.setAttribute("loading","lazy"),f.setAttribute("decoding","async"),f.setAttribute("referrerpolicy","no-referrer"),f.setAttribute("draggable","false"),f.onerror=()=>{f.hidden=!0},f.src=l,m.appendChild(f),a.appendChild(m),o.dataset.aiaImage=""}let d=!l&&n&&t.icon_svg?Ee(t.icon_svg):null;if(d){let m=document.createElement("span");m.className="magicx-aia-option-icon",m.setAttribute("aria-hidden","true"),m.innerHTML=d,a.appendChild(m),t.icon&&(o.dataset.aiaIcon=t.icon)}let c=document.createElement("span");if(c.className="magicx-aia-option-text",c.textContent=zt(t),a.appendChild(c),t.tag){let m=document.createElement("span");m.className="magicx-aia-option-tag",m.textContent=t.tag,a.appendChild(m)}let u=i?ve(t.item_count):null;if(u!==null){let m=document.createElement("span");m.className="magicx-aia-option-count",m.textContent=u,a.appendChild(m),o.dataset.aiaItemCount=String(t.item_count)}return o.appendChild(a),o}var Lr="magicx-aia-scroll-arrow",Rr="data-aia-scroll-arrow",de="data-aia-visible",Mr=1e3,kr=160,Dr="--aia-scroll-arrow-bottom",_r="Scroll down for more options",So="[data-aia-products-label]",xo=4,yo=8,vo=240;function Eo(t,e,n,r){let i=t.scrollTop,o=n?.requestAnimationFrame,s=t.ownerDocument?.visibilityState==="hidden";if(!o||s||Jt(t)){t.scrollTop=i+e,r();return}let a=n.performance?.now?.()??Date.now(),l=()=>n.performance?.now?.()??Date.now(),d=()=>{let c=Math.min(1,(l()-a)/vo),u=1-(1-c)*(1-c);t.scrollTop=i+e*u,c<1?o.call(n,d):r()};o.call(n,d)}function Po(t=document){let e="http://www.w3.org/2000/svg",n=t.createElementNS(e,"svg");n.setAttribute("viewBox","0 0 16 16"),n.setAttribute("width","18"),n.setAttribute("height","18"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","1.75"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),n.setAttribute("aria-hidden","true"),n.setAttribute("focusable","false");let r=t.createElementNS(e,"path");return r.setAttribute("d","M4 6.5 8 10.5l4-4"),n.appendChild(r),n}function Nr(t=document){let e=t.createElement("button");return e.type="button",e.tabIndex=-1,e.className=Lr,e.setAttribute(Rr,""),e.setAttribute("aria-label",_r),e.setAttribute("aria-hidden","true"),e.disabled=!0,e.appendChild(Po(t)),e}function wo(t){let e=t.style.gridTemplateColumns.trim();return e?Math.max(1,e.split(/\s+/).length):1}function Jt(t){return t.closest('[data-animations="off"]')?!0:!!t.ownerDocument?.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches}function Zt({dropdown:t,grid:e,button:n}){let r=e.ownerDocument?.defaultView??(typeof window<"u"?window:null),i=!1;n.disabled=!0;let o=null,s=null,a=null,l=null,d=p=>{if(p){if(n.hasAttribute(de))return;if(n.setAttribute(de,""),n.setAttribute("aria-hidden","false"),l!==null&&clearTimeout(l),Jt(e)){n.disabled=!1;return}l=setTimeout(()=>{l=null,!i&&n.hasAttribute(de)&&(n.disabled=!1)},Mr)}else n.removeAttribute(de),n.setAttribute("aria-hidden","true"),l!==null&&clearTimeout(l),l=null,n.disabled=!0},c=p=>{let b=0,S=p;for(;S&&S!==t;)b+=S.offsetTop,S=S.offsetParent instanceof HTMLElement?S.offsetParent:null;return b},u=()=>{let p=t.querySelector(So),b;if(p){let S=c(p)+p.offsetHeight/2;b=t.clientHeight-S-n.offsetHeight/2}else{let S=c(e),P=r&&Number.parseFloat(r.getComputedStyle(e).paddingBottom)||0;b=t.clientHeight-(S+e.offsetHeight)+(P>0?0:yo)}n.style.setProperty(Dr,`${Math.max(0,Math.round(b))}px`)},m=()=>{if(i||s!==null||a!==null)return;let p=e.querySelector("[data-aia-option][data-aia-loading]")!==null,b=e.scrollHeight-e.clientHeight-e.scrollTop;d(!p&&b>xo)},f=()=>{if(i)return;u();let p=e.getAttribute("data-aia-group")??"";if(p!==o){o=p,d(!1),s!==null&&clearTimeout(s);let b=e.querySelectorAll("[data-aia-option]").length,S=Jt(e)?0:jt(b,wo(e));s=setTimeout(()=>{s=null,m()},S);return}m()},h=()=>{i||s!==null||(d(!1),a!==null&&clearTimeout(a),a=setTimeout(()=>{a=null,m()},kr))};e.addEventListener("scroll",h,{passive:!0});let x=p=>p.preventDefault(),y=()=>{let p=r?(Number.parseFloat(r.getComputedStyle(e).paddingTop)||0)+(Number.parseFloat(r.getComputedStyle(e).paddingBottom)||0):0,b=Math.max(1,e.clientHeight-p);Eo(e,b,r,h)};n.addEventListener("mousedown",x),n.addEventListener("click",y);let g=null;return r&&typeof r.ResizeObserver=="function"&&(g=new r.ResizeObserver(()=>{u(),m()}),g.observe(e)),f(),{update:f,destroy(){i||(i=!0,s!==null&&clearTimeout(s),s=null,a!==null&&clearTimeout(a),a=null,l!==null&&clearTimeout(l),l=null,n.disabled=!0,e.removeEventListener("scroll",h),n.removeEventListener("mousedown",x),n.removeEventListener("click",y),g?.disconnect(),n.removeAttribute(de),n.setAttribute("aria-hidden","true"))}}}var To=[159,119,164];function tt(t){let e=document.createElement("div");return e.id=t,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",n=>n.preventDefault()),Wt(e),e}var et=new WeakMap;function Io(t,e){let n=et.get(t);if(n||(n={button:Nr(t.ownerDocument),grid:null,controller:null},t.appendChild(n.button),et.set(t,n)),n.grid!==e&&(n.controller?.destroy(),n.controller=null,n.grid=e,e)){n.controller=Zt({dropdown:t,grid:e,button:n.button});return}n.controller?.update()}function en(t){let e=et.get(t);e&&(e.controller?.destroy(),et.delete(t))}function nt(t,e){let{filteredOptions:n,activeIndex:r,isOpen:i,isLoading:o,pills:s,showPills:a,isActivePillSelected:l,onSelect:d,onHighlight:c,onPillClick:u,onSkip:m}=e,f=s.length>0,h=a&&f,x=n.length>0,y=e.products.length>0,g=i&&(x||h||o||y);if(g?t.classList.add("magicx-aia-dropdown--visible"):t.classList.remove("magicx-aia-dropdown--visible"),o?t.setAttribute("data-aia-loading",""):t.removeAttribute("data-aia-loading"),!g){Yt(t,!1);return}y?t.setAttribute("data-aia-has-products",""):t.removeAttribute("data-aia-has-products"),t.toggleAttribute("data-aia-skeleton-exiting",!!e.skeletonExiting);let p=t.querySelector(".aia-stack");p||(p=document.createElement("div"),p.className="aia-stack",p.style.setProperty("--aia-stack-space","8px"),t.appendChild(p));let b=e.showSkipButton&&f&&!e.isInputEmpty,S=h||o&&a||b,P=p.querySelector(".magicx-aia-pill-bar");if(S){P||(P=document.createElement("div"),P.className="magicx-aia-pill-bar aia-cluster",P.setAttribute("data-nowrap",""),P.setAttribute("data-aia-pillbar",""),p.insertBefore(P,p.firstChild));let R=P.querySelector(".magicx-aia-pill-scroll");R||(R=document.createElement("span"),R.className="magicx-aia-pill-scroll",R.setAttribute("data-aia-pill-scroll",""),P.insertBefore(R,P.firstChild)),Ze(R,a?s:[],0,u,!0,o&&a,l),Ao(P,b,o||e.skipDisabled,s[0],m)}else P&&P.remove();let w=e.suggestions[0],O=w?`${w.parameter} ${w.text}`:"",k=E(e.formatType),T=k&&!o;Ar(p,k?[]:n,r,d,c,e.listboxId,o,O,e.optionsPosition??"below",e.showOptionIcons??!0,e.showOptionImages??!0,e.showOptionCounts??!0,!e.skipDisabled),Io(t,p.querySelector(".aia-grid")),hr(p,T?n:[],r,e.listboxId,T?e.dateView:null,{selectedIso:e.selectedDateIso,selectedRange:e.selectedDateRange,rangeStart:e.dateRangeStart},{onSelect:d,onHighlight:c,onPreviousMonth:e.onPreviousMonth,onNextMonth:e.onNextMonth},!e.skipDisabled);let v=p.querySelector(".magicx-aia-skeleton-bars");if(o&&(!x||k)){if(!v){v=document.createElement("div"),v.className="magicx-aia-skeleton-bars",v.setAttribute("data-aia-skeleton-bars","");for(let R of To){let F=document.createElement("span");F.className="magicx-aia-skeleton-bar",F.style.width=`${R}px`,v.appendChild(F)}p.appendChild(v)}}else v&&v.remove();Pr(p,e.products,e.listboxId,e.onProductSelect,e.onProductFocusChange,e.productsLayout??"row",e.productImageFallback??"image"),Yt(t,!0);let I=p.querySelector(".magicx-aia-footer")??Ro(),Q=r>=0&&!!n[r]?.is_tappable;Lo(I,Bt(Q,e.isInputEmpty)),I.isConnected||p.appendChild(I),Co(p,[".magicx-aia-pill-bar",".aia-grid",".magicx-aia-datepicker",".magicx-aia-skeleton-bars",".magicx-aia-products",".magicx-aia-footer"])}function Co(t,e){let n=e.map(r=>t.querySelector(`:scope > ${r}`)).filter(r=>r!==null);for(let r=0;r<n.length;r++)t.children[r]!==n[r]&&t.insertBefore(n[r],t.children[r]??null)}var Oo={itemSelector:".magicx-aia-skip",onClick:(t,e)=>{e.loading||e.onSkip()}};function Ao(t,e,n,r,i){G(t,Oo,{onSkip:i,loading:n});let o=t.querySelector(".magicx-aia-skip");if(!e){o?.remove();return}o||(o=document.createElement("button"),o.type="button",o.tabIndex=-1,o.className="magicx-aia-skip",o.setAttribute("data-aia-skip",""),o.textContent="skip",o.disabled=!0,t.appendChild(o),U(o)),o.setAttribute("aria-label",r?`Skip ${r.text}`:"Skip"),o.disabled=n}function Lo(t,{key:e,hint:n}){let r=t.querySelector(".magicx-aia-footer-key"),i=t.querySelector(".magicx-aia-footer-hint");!r||!i||(r.textContent!==e&&(r.textContent=e),i.textContent!==n&&(i.textContent=n))}function Ro(){let t=document.createElement("footer");t.className="magicx-aia-footer",t.setAttribute("data-aia-footer","");let e=document.createElement("div");e.className="aia-cluster magicx-aia-footer-row",e.setAttribute("data-align","center"),e.setAttribute("data-justify","between"),e.setAttribute("data-nowrap","");let n=document.createElement("div");n.className="aia-cluster magicx-aia-footer-hint-group",n.setAttribute("data-align","center"),n.style.setProperty("--aia-cluster-gap","5px");let r=document.createElement("kbd");r.className="magicx-aia-footer-key",r.textContent="tab";let i=document.createElement("span");i.className="magicx-aia-footer-hint",i.textContent="to select",n.append(r,i);let o=document.createElement("a");o.className="aia-cluster magicx-aia-footer-brand-link",o.setAttribute("data-align","center"),o.href=Ht(),o.target="_blank",o.rel="noopener noreferrer",o.style.setProperty("--aia-cluster-gap","2px");let s=document.createElement("span");s.className="magicx-aia-footer-brand",s.textContent="AI";let a=document.createElement("span");return a.className="magicx-aia-footer-badge",a.textContent="Autocomplete",o.append(s,a),e.append(n,o),t.append(e),t}function Fr(t,e){let n=tt(e.listboxId);return t.appendChild(n),{dropdown:n}}function tn(t,e,n){let r=ye(e);nt(t.dropdown,{suggestions:e.editingIdentified?[{parameter:e.editingIdentified.parameter,text:J(e.editingIdentified.parameter),required:!0,options:e.filteredOptions}]:e.dropdownSuggestion??e.actionableSuggestions[0]?[{...e.dropdownSuggestion??e.actionableSuggestions[0],options:e.dropdownOptions}]:[],filteredOptions:e.dropdownOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.dropdownLoading,skeletonExiting:e.skeletonExiting,listboxId:n.listboxId,pills:e.actionableSuggestions,showPills:!0,showSkipButton:n.showSkipButton&&!e.editingParam&&!e.editingIdentified,skipDisabled:e.inSelectionAnimation,showOptionIcons:n.showOptionIcons??!0,showOptionImages:n.showOptionImages??!0,showOptionCounts:n.showOptionCounts??!0,isActivePillSelected:e.isActivePillSelected,isInputEmpty:e.text.trim().length===0,products:e.products,productsLayout:n.productsLayout??"row",productImageFallback:n.productImageFallback??"image",formatType:e.activeFormatType,dateView:e.dateView,selectedDateIso:r.selectedIso,selectedDateRange:r.selectedRange,dateRangeStart:r.rangeStart,optionsPosition:n.optionsPosition??"below",onSelect:n.selectOption,onHighlight:(i,o)=>{o!==void 0&&n.store.get().activeDropdownIndex!==o||n.store.set({activeDropdownIndex:i})},onPillClick:n.setActivePill,onSkip:n.skipActivePill,onPreviousMonth:n.showPreviousMonth,onNextMonth:n.showNextMonth,onProductSelect:n.selectProduct,onProductFocusChange:i=>n.store.set({isFocused:i})})}var Mo=6,ko=.3;function Hr(t){return t<=0?"0px":`${(-Math.min(ko,2*Mo/t)).toFixed(3)}px`}function nn(t){let{input:e,segments:n,newParamId:r,editingParamId:i,placeholderText:o,isFocused:s}=t,a=t.showChipIcons??!0,l=t.showChipImages??!0,d=n.length===0;e.dataset.aiaEmpty=d?"true":"false",sr(e,d?o:"");let c=n.map(p=>p.type==="completed"?`${p.type}:${p.value}${a?p.param.icon??p.param.icon_svg??"":""}${l?Y(p.param.image_url)??"":""}`:`${p.type}:${p.value}`).join("\0"),u=e.dataset.segKey??"",m=e.dataset.newParamId??"",f=e.dataset.editingParamId??"";if(c===u&&(r??"")===m&&(i??"")===f)return;if(c===u){e.dataset.newParamId=r??"",e.dataset.editingParamId=i??"";for(let p of e.querySelectorAll("strong[data-param-id]")){let b=p.dataset.paramId,S=p.dataset.seg==="completed"&&b===r;p.classList.toggle("magicx-aia-shimmer-revealed",S),p.classList.toggle("magicx-aia-shimmer-sweep",S),p.classList.toggle("magicx-aia-segment--editing",b===i)}return}let h=s?_(e):null;e.dataset.segKey=c,e.dataset.newParamId=r??"",e.dataset.editingParamId=i??"";let x=A(e),y=x.createDocumentFragment(),g=0;for(let p of n)if(g+=p.value.length,p.type==="completed"){let b=x.createElement("strong");b.dataset.seg="completed",b.dataset.paramId=p.param.id;let S=p.param.id===r,P=p.param.id===i,w=["magicx-aia-segment","magicx-aia-segment--completed"];S&&w.push("magicx-aia-shimmer-revealed","magicx-aia-shimmer-sweep"),P&&w.push("magicx-aia-segment--editing"),b.className=w.join(" "),b.style.letterSpacing=Hr(p.value.length);let O=l?Y(p.param.image_url):null;if(O){let T=x.createElement("span");T.className="magicx-aia-segment-image",T.setAttribute("contenteditable","false"),T.setAttribute("aria-hidden","true"),T.style.setProperty("--aia-chip-image",`url("${O}")`),b.appendChild(T),b.dataset.aiaImage=""}let k=!O&&a&&p.param.icon_svg?Ee(p.param.icon_svg):null;if(k){let T=x.createElement("span");T.className="magicx-aia-segment-icon",T.setAttribute("contenteditable","false"),T.setAttribute("aria-hidden","true"),T.innerHTML=k,b.appendChild(T),p.param.icon&&(b.dataset.aiaIcon=p.param.icon)}b.appendChild(x.createTextNode(p.value)),y.appendChild(b)}else if(p.type==="identified"){let b=x.createElement("strong");b.dataset.seg="identified",b.dataset.paramId=p.param.id;let S=["magicx-aia-segment","magicx-aia-segment--completed"];p.param.id===i&&S.push("magicx-aia-segment--editing"),b.className=S.join(" "),b.style.letterSpacing=Hr(p.value.length),b.textContent=p.value,y.appendChild(b)}else y.appendChild(x.createTextNode(p.value));e.replaceChildren(y),e.dataset.aiaTextLength=String(g),h!=null?L(e,Math.max(0,Math.min(h,g))):s&&qn(e)&&L(e,g)}var Do='<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 Br(){let t=document.createElement("button");return t.type="button",t.className="magicx-aia-submit",t.setAttribute("aria-label","Submit"),t.setAttribute("data-aia-submit",""),t.innerHTML=Do,t}function _o(){let t=document.createElement("div");return t.setAttribute("contenteditable","plaintext-only"),t.contentEditable==="plaintext-only"}function Wr(t,e){let n=e.firstElementChild;if(!n){e.removeAttribute("data-aia-pill-wrapped");return}let r=n.getBoundingClientRect(),i=t.getBoundingClientRect();r.top>=i.bottom-2?e.setAttribute("data-aia-pill-wrapped",""):e.removeAttribute("data-aia-pill-wrapped")}function qr(t,e){let{listboxId:n}=e,r=tt(n);t.appendChild(r);let i=document.createElement("div");i.className="magicx-aia-input-wrapper",i.setAttribute("data-aia-input-wrapper",""),t.appendChild(i);let o=document.createElement("div");o.className="magicx-aia-editor",o.setAttribute("data-aia-editor",""),i.appendChild(o);let s=document.createElement("div");s.className="magicx-aia-input",s.setAttribute("data-aia-input",""),s.setAttribute("contenteditable",_o()?"plaintext-only":"true"),s.setAttribute("role","combobox"),s.setAttribute("aria-autocomplete","list"),s.setAttribute("aria-haspopup","listbox"),s.setAttribute("aria-controls",n),s.setAttribute("aria-expanded","false"),s.setAttribute("spellcheck","true"),s.setAttribute("enterkeyhint","send"),o.appendChild(s);let a=document.createElement("span");a.className="magicx-aia-pill-list-container",a.setAttribute("data-aia-pill-list-container",""),o.appendChild(a);let l=null,d=null;e.submitButton===void 0?(l=Br(),i.appendChild(l),d=l):e.submitButton!==null&&(d=e.submitButton,d.hasAttribute("data-aia-submit")||d.setAttribute("data-aia-submit",""),d.setAttribute("data-aia-submit-slot",""),i.appendChild(d));let c=new AbortController,{signal:u}=c,m=!1,f=0,h=()=>{let g=We(s),b=g.length>0&&g[0]!==g[0].toUpperCase()?g[0].toUpperCase()+g.slice(1):g;e.handleChange(b)},x=()=>{let g=$(s)?.node??null;if(!g||!s.contains(g))return null;let S=(g.nodeType===Node.ELEMENT_NODE?g:g.parentElement)?.closest("strong[data-param-id]")?.dataset.paramId??null;return S&&Wn(s,S)?null:S};if(i.addEventListener("click",g=>{g.target?.closest("[data-aia-pill]")||s.focus()},{signal:u}),s.addEventListener("input",()=>{m||(f=performance.now(),h(),e.handleCaretAfterInput(_(s)))},{signal:u}),A(s).addEventListener("selectionchange",()=>{let g=$(s);if(!g||!s.contains(g.node))return;let p=g.collapsed?x():null,b=e.store.get(),S=b.editingParam?.id??b.editingIdentified?.id??null;if(p&&p!==S){e.startEditingParam(p);return}performance.now()-f<50||e.handleCaretMove(_(s))},{signal:u}),s.addEventListener("click",g=>{let p=yt(s,g.target);p&&(e.startEditingParam(p),vt(s,p))},{signal:u}),s.addEventListener("compositionstart",()=>{m=!0},{signal:u}),s.addEventListener("compositionend",()=>{m=!1,h()},{signal:u}),s.addEventListener("beforeinput",g=>{let p=g,b=p.inputType;if(b==="insertParagraph"||b==="insertLineBreak"||b==="insertFromDrop"){g.preventDefault();return}if(b.startsWith("insert")||b.startsWith("delete")){let S=b.startsWith("delete")?"":p.data??"";e.replaceEditingRange(S)&&g.preventDefault()}},{signal:u}),s.addEventListener("paste",g=>{g.preventDefault();let p=(g.clipboardData?.getData("text/plain")??"").replace(/\r?\n/g," ");if(!p)return;let b=A(s),S=_e(s);if(!S||!s.contains(S.startContainer))return;S.deleteContents();let P=b.createTextNode(p);S.insertNode(P),S.setStartAfter(P),ge(s,S.startContainer,S.startOffset),h()},{signal:u}),s.addEventListener("keydown",g=>e.handleKeyDown(g),{signal:u}),s.addEventListener("focus",()=>e.store.set({isFocused:!0}),{signal:u}),s.addEventListener("blur",()=>e.store.set({isFocused:!1}),{signal:u}),d&&d.addEventListener("click",g=>{let p=e.store.get();if(!(!!p.text||p.completedParams.length>0)||!e.onSubmit)return;g.stopPropagation(),e.onSubmit(ee(p.text,p.completedParams,p.skippedParams,{identifiedParams:p.identifiedParams,isReady:p.isReady,customFields:p.customFields}))&&e.afterSubmit?.()},{signal:u}),e.autoFocus!==!1){s.focus();let g=$(s);(!g||!s.contains(g.node))&&ge(s,s,0)}if(typeof ResizeObserver<"u"){let g=new ResizeObserver(()=>Wr(s,a));g.observe(s),c.signal.addEventListener("abort",()=>g.disconnect(),{once:!0})}return{input:s,inlinePillContainer:a,dropdown:r,submitButton:l,abort:c}}function rn(t,e,n){let{input:r,inlinePillContainer:i,dropdown:o,submitButton:s}=t,{pillPlacement:a,setActivePill:l,selectOption:d,store:c}=n;r.setAttribute("aria-expanded",String(e.isDropdownOpen));let u=e.activeDropdownIndex>=0?`${n.listboxId}-option-${e.activeDropdownIndex}`:"";if(u?r.setAttribute("aria-activedescendant",u):r.removeAttribute("aria-activedescendant"),s){let g=!!e.text||e.completedParams.length>0;s.disabled=!g}let m=r.dataset.newParamId??"",f=e.newParamId!==null&&e.newParamId!==m;if(nn({input:r,segments:e.segments,newParamId:e.newParamId,editingParamId:e.editingParam?.id??null,placeholderText:e.placeholderText,isFocused:e.isFocused,showChipIcons:n.showChipIcons??!0,showChipImages:n.showChipImages??!0}),a==="inline"){let g=e.isLoading&&!e.editingParam&&!e.inSelectionAnimation;g||e.actionableSuggestions.length>0?Ze(i,e.actionableSuggestions,0,l,!1,g,e.isActivePillSelected):Gt(i)}else Gt(i);Wr(r,i),f?(r.focus(),L(r,e.caretOffset??e.text.length)):e.isFocused&&We(r)!==e.text&&L(r,e.text.length);let h=e.editingParam?{parameter:e.editingParam.suggestionParameter,text:e.editingParam.suggestionPlaceholder,required:!0,options:e.editingParam.options}:e.editingIdentified?{parameter:e.editingIdentified.parameter,text:J(e.editingIdentified.parameter),required:!0,options:[]}:null,x=e.dropdownSuggestion??h??e.actionableSuggestions[0],y=ye(e);nt(o,{suggestions:x?[{...x,options:e.dropdownOptions}]:[],filteredOptions:e.dropdownOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.dropdownLoading,skeletonExiting:e.skeletonExiting,listboxId:n.listboxId,pills:h?[h]:e.actionableSuggestions,showPills:a==="dropdown",showSkipButton:n.showSkipButton&&!e.editingParam&&!e.editingIdentified,skipDisabled:e.inSelectionAnimation,showOptionIcons:n.showOptionIcons??!0,showOptionImages:n.showOptionImages??!0,showOptionCounts:n.showOptionCounts??!0,isActivePillSelected:e.isActivePillSelected,isInputEmpty:e.text.trim().length===0,products:e.products,productsLayout:n.productsLayout??"row",productImageFallback:n.productImageFallback??"image",formatType:e.activeFormatType,dateView:e.dateView,selectedDateIso:y.selectedIso,selectedDateRange:y.selectedRange,dateRangeStart:y.rangeStart,optionsPosition:n.optionsPosition??"below",onSelect:d,onHighlight:(g,p)=>{p!==void 0&&c.get().activeDropdownIndex!==p||c.set({activeDropdownIndex:g})},onPillClick:l,onSkip:n.skipActivePill,onPreviousMonth:n.showPreviousMonth,onNextMonth:n.showNextMonth,onProductSelect:n.selectProduct,onProductFocusChange:g=>c.set({isFocused:g})})}function on(t){let e=t,n=new Set,r=[],i=!1;return{get:()=>e,set:o=>{let s=typeof o=="function"?o(e):o,a=e;if(e={...e,...s},r.push([e,a]),!i){i=!0;try{let l=0;for(let d=r.shift();d;d=r.shift()){if(++l>1e4)throw r.length=0,new Error("createStore: notifications did not settle after 10000 deliveries \u2014 a listener is likely calling set() on every notification");let[c,u]=d;for(let m of n)m(c,u)}}catch(l){throw r.length=0,l}finally{i=!1}}},subscribe:o=>(n.add(o),()=>{n.delete(o)})}}function $r(t,e){let n,r,i=o=>(o!==n&&(n=o,r=e(o)),r);return{get:()=>{let o=t.get();return{...o,...i(o)}},set:o=>{typeof o=="function"?t.set(s=>{let a={...s,...i(s)};return o(a)}):t.set(o)},peek:o=>{let s={...t.get(),...o};return{...s,...e(s)}},subscribe:o=>t.subscribe((s,a)=>{let l={...a,...i(a)},d={...s,...i(s)};o(d,l)})}}var sn=new WeakSet,Gr=new WeakMap;function Ur(t){return t.nodeType===Node.DOCUMENT_NODE}function No(t){return Ur(t)?t:t.ownerDocument}function Fo(t){let e=Gr.get(t);if(e)return e;let n=t.defaultView?.CSSStyleSheet;if(typeof n!="function")return null;try{let r=new n;return typeof r.replaceSync!="function"?null:(r.replaceSync(Yr),Gr.set(t,r),r)}catch{return null}}function Vr(t,e){if(e.querySelector("style[data-magicx-aia]"))return;let n=t.createElement("style");n.setAttribute("data-magicx-aia",""),n.textContent=Yr,e.appendChild(n)}function Kr(t){if(typeof document>"u")return;let e=t??document;if(sn.has(e))return;let n=No(e);if(Ur(e)){let o=e.head??e.documentElement;if(!o)return;Vr(n,o),sn.add(e);return}let r=Fo(n),i=e.adoptedStyleSheets;r&&Array.isArray(i)?i.includes(r)||(e.adoptedStyleSheets=[...i,r]):Vr(n,e),sn.add(e)}var Yr=`.aia-stack {
|
|
2
2
|
display: flex;
|
|
3
3
|
flex-direction: column;
|
|
4
4
|
gap: var(--aia-stack-space, 0.5rem);
|
|
@@ -2256,5 +2256,5 @@ function P(t){return t==="date"||t==="date-range"}function Y(t){return t?.type?.
|
|
|
2256
2256
|
background: var(--aia-surface, #ffffff);
|
|
2257
2257
|
}
|
|
2258
2258
|
}
|
|
2259
|
-
`;var nt=class{constructor(){this.reported=new Set}run(e,n){try{return n()}catch(r){this.report(e,r,e);return}}runListener(e,n,r=e){try{return n(),!0}catch(i){return this.report(e,i,r),!1}}report(e,n,r){this.reported.has(r)||(this.reported.add(r),console.error(`[AIAutocomplete] "${e}" threw. The error is contained \u2014 SDK state is unaffected. Later failures of "${e}" on this instance are not logged.`,n))}};var rt=class{constructor(e){this.boundary=e;this.listeners={};this.keys=new WeakMap;this.registrationCount=0}on(e,n){let r=`${String(e)}#${++this.registrationCount}`,i=(...s)=>n(...s);this.keys.set(i,r);let o=this.listeners[e];return o||(o=new Set,this.listeners[e]=o),o.add(i),()=>{this.listeners[e]?.delete(i)}}emit(e,...n){let r=this.listeners[e];if(!r)return!0;let i=!0;for(let o of r)this.boundary.runListener(String(e),()=>o(...n),this.keys.get(o)??String(e))||(i=!1);return i}hasListeners(e){return(this.listeners[e]?.size??0)>0}clear(){this.listeners={}}};var it=class{constructor(){this.timers=new Map}schedule(e,n,r){this.clear(e);let i=setTimeout(()=>{this.timers.delete(e),n()},r);this.timers.set(e,i)}clear(e){let n=this.timers.get(e);n!==void 0&&(clearTimeout(n),this.timers.delete(e))}clearAll(){for(let e of this.timers.values())clearTimeout(e);this.timers.clear()}};var ve=class{constructor(e,n="auto",r){this.container=e;this.mode=n;this.onResolve=r;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)}};var Ho=50,Bo=new Set(["search_started","submit","product_click","impression"]),Wo="newParam",Yr="suggestionRemoval",qo="selectionAnimation",on="skeletonExit",$o=650,Go=0;function Vo(){return`:ac-${++Go}:`}var Qr=170,Uo=100;function Xr(){return{text:"",completedParams:[],identifiedParams:[],skippedParams:[],pendingSpan:null,suggestions:[],products:[],customFields:null,optionSearch:null,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,skeletonOptions:null,skeletonSuggestion:null,skeletonRequested:!1,dateViewMonth:null,pendingRangeStart:null,editingIdentified:null}}var sn=class{constructor(e,n={}){this.inputStore=nn(Xr());this._listboxId=Vo();this.modeController=null;this.unsubscribers=[];this.domRefs=null;this.dropdownRefs=null;this.timers=new it;this.boundary=new nt;this.subscriberCount=0;this.emitter=new rt(this.boundary);this.sessionId=crypto.randomUUID();this.lastRequestId=null;this.searchStartedSessionId=null;this.funnelTelemetry=null;this.pendingSearchStarted=!1;this.lastImpressionKey="";this.emitSubmit=e=>(this.recordSubmit(e),this.emitter.emit("submit",e));this.emitError=e=>this.emitter.emit("error",e);this.container=e,this.opts=n,this.renderMode=n.renderMode??"full",this.store=qr(this.inputStore,r=>Zn(r,this.opts)),n.onSubmit&&this.emitter.on("submit",n.onSubmit),n.onResult&&this.emitter.on("result",n.onResult),n.onError&&this.emitter.on("error",n.onError),n.onChange&&this.emitter.on("change",n.onChange),n.onParamsChange&&this.emitter.on("paramsChange",n.onParamsChange),n.onStateChange&&this.emitter.on("stateChange",n.onStateChange),n.onFocus&&this.emitter.on("focus",n.onFocus),n.onBlur&&this.emitter.on("blur",n.onBlur),n.onProductSelect&&this.emitter.on("productSelect",n.onProductSelect),n.value!==void 0&&this.store.set({text:n.value}),n.completedParams!==void 0&&this.store.set({completedParams:n.completedParams}),this.pillsController=new $e(this.store,{onPillSelected:({rawQuery:r,selectedPill:i,otherPills:o})=>{this.fireTelemetry("pill",{raw_query:r,selected_pill:i,other_pills:o})}}),this.reEdit=new je({store:this.store,scheduleSetCursor:r=>this.scheduleSetCursor(r),fireTelemetry:(r,i)=>this.fireTelemetry(r,i),startSelectionAnimationTimer:()=>this.startSelectionAnimationTimer(),fetchNow:()=>this.fetchNow()}),this.productsController=new Ge(this.store,()=>this.opts.products,()=>this.opts.showProducts!==!1),this.optionSource=new qe(this.store,()=>this.opts.optionOverrides,{onAnswer:r=>{r==="edit"?this.reEdit.promoteIfExact():this.maybePromoteExactMatch(this.store.get().text)},onMiss:(r,i)=>{r==="pill"&&i.length>0&&this.fetchController.attemptNow()}}),this.fetchController=new Re(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.emitter.hasListeners("error")?this.emitError:void 0,()=>this.sessionId,()=>this.resolveSource(),()=>this.opts.additionalContext,{onRequest:({query:r,signal:i,isCurrent:o})=>{this.productsController.run(r,i,o).catch(()=>{})},onAutoMatch:({active:r,matched:i,rawQuery:o})=>{let s=r.options??[];this.fireTelemetry("option",{raw_query:o,selected_option:i.text,other_options:s.filter(a=>a.text!==i.text).map(a=>a.text),key:r.parameter,position:oe(s,i.text)})},onResponse:({requestId:r,funnelTelemetry:i})=>{this.lastRequestId=r,this.funnelTelemetry=i,this.pendingSearchStarted&&(this.pendingSearchStarted=!1,this.fireTelemetry("search_started",{})),this.fireImpression(),this.emitter.hasListeners("result")&&this.emitter.emit("result",this.buildResult())},productsForResponse:r=>this.productsController.forResponse(r),consumerTick:(r,i)=>this.optionSource.tick(r,i)}),this.keyboardController=new We(this.store,{columns:n.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.emitter.hasListeners("submit")?this.emitSubmit:void 0,getOptionsPosition:()=>this.opts.optionsPosition??"below",afterSubmit:this.renderMode==="full"?()=>this.resetAfterSubmit():void 0,selectOption:r=>this.selectOption(r),removeParamAtCaret:r=>this.removeParamAtCaret(r),startEditingParamAtCaret:r=>this.startEditingParamAtCaret(r),exitEditMode:()=>this.exitEditMode(),exitEditingIdentified:()=>this.exitEditingIdentified(),skipActivePill:()=>this.skipActivePill()}),this.unsubscribers.push(this.store.subscribe((r,i)=>{r.text!==i.text&&this.emitter.emit("change",r.text),r.completedParams!==i.completedParams&&this.emitter.emit("paramsChange",r.completedParams),r.isFocused!==i.isFocused&&(r.isFocused?this.emitter.emit("focus"):this.emitter.emit("blur")),this.emitter.emit("stateChange",r)})),this.unsubscribers.push(this.store.subscribe(()=>this.maybeExitReEditOnNoMatch())),this.subscribeSkeletonMirror(),this.unsubscribers.push(this.store.subscribe((r,i)=>{if(r.text===i.text&&r.completedParams===i.completedParams||r.identifiedParams.length===0)return;let{valid:o,invalid:s}=Le(r.text,r.completedParams,r.identifiedParams);s.length>0&&this.store.set({identifiedParams:o})})),this.unsubscribers.push(this.store.subscribe((r,i)=>{if(r.identifiedParams===i.identifiedParams)return;let o=r.editingIdentified;if(!o||r.identifiedParams.some(l=>l.id===o.id))return;let s=0,a;for(let l of r.segments){if(l.type==="identified"&&s===o.anchor&&l.value===o.text){a=l.param;break}s+=l.value.length}if(a){this.store.set({editingIdentified:{...o,id:a.id}});return}this.store.set({editingIdentified:null,activeDropdownIndex:-1})})),this.unsubscribers.push(this.store.subscribe(r=>{let i=r.pendingRangeStart;!i||i.key===be(r)||this.store.set({pendingRangeStart:null})})),this.unsubscribers.push(this.store.subscribe((r,i)=>{let o=r.pendingSpan;if(!o||r.text===i.text&&r.completedParams===i.completedParams&&r.identifiedParams===i.identifiedParams)return;let s=o.anchor;if(r.text!==i.text){let l=vn(i.text,r.text,s);if(l===null){this.store.set({pendingSpan:null});return}s=l}r.text.slice(s).trim().length===0||xn(r.segments,s)?this.store.set({pendingSpan:null}):s!==o.anchor&&this.store.set({pendingSpan:{anchor:s,snapshot:o.snapshot}})})),this.renderMode!=="headless"&&(Ur(this.opts.styleRoot??z(this.container)),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.optionSource.start(),this.fetchController.start()}focus(){this.domRefs?.input.focus()}blur(){this.domRefs?.input.blur()}reset(){let e=this.store.get().isFocused;this.optionSource.reset(),this.store.set({...Xr(),isFocused:e,skipNextFetch:!0}),this.sessionId=crypto.randomUUID(),this.lastRequestId=null,this.lastImpressionKey="",this.pendingSearchStarted=!1,this.fetchController.doFetch("",[])}resetAfterSubmit(){this.opts.resetOnSubmit!==!1&&this.reset()}destroy(){this.fetchController.dispose(),this.optionSource.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&&(sr(this.domRefs.input),Jt(this.domRefs.dropdown)),this.dropdownRefs&&Jt(this.dropdownRefs.dropdown),this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}prefillText(e){this.applyTextChange(e,!1)}noteSearchStarted(){this.searchStartedSessionId!==this.sessionId&&(this.searchStartedSessionId=this.sessionId,this.funnelTelemetry===null?this.pendingSearchStarted=!0:this.fireTelemetry("search_started",{}))}setValue(e){let n=this.store.get();if(n.editingIdentified&&e!==n.text){this.store.set({text:e,editingIdentified:null,activeDropdownIndex:-1});return}this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e);let n=this.store.get().text.length;this.store.set({caretOffset:n,isFocused:!0}),this.scheduleSetCursor(n)}removeLastParam(){this.pillsController.removeLastParam()}findChipSpanAt(e){let n=0;for(let r of this.store.get().segments){let i=n;if(n+=r.value.length,r.type!=="text"&&e>i&&e<=n)return{kind:r.type,param:r.param,start:i,end:n}}return null}withoutChip(e,n){return n.kind==="completed"?{completedParams:e.completedParams.filter(r=>r.id!==n.param.id)}:{identifiedParams:e.identifiedParams.filter(r=>r.id!==n.param.id)}}removeParamAtCaret(e){let n=this.findChipSpanAt(e);if(!n)return!1;let{text:r}=this.store.get(),{start:i,end:o}=n;if(e===o){let{text:l,removed:d}=Xe(r,i,o);return this.store.set(u=>({text:l,filterBase:Math.min(u.filterBase>i?Math.max(i,u.filterBase-d):u.filterBase,l.length),...this.withoutChip(u,n),pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(i),!0}let s=vt(r,e),a=r.slice(0,s)+r.slice(e);return this.store.set(l=>({text:a,filterBase:Math.min(l.filterBase,a.length),...this.withoutChip(l,n),pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(s),!0}startEditingParamAtCaret(e){let n=this.findChipSpanAt(e);return!n||n.kind!=="completed"||n.end!==e?!1:(this.reEdit.start(n.param.id),this.store.get().editingParam?.id===n.param.id)}scheduleSetCursor(e){queueMicrotask(()=>{let n=this.domRefs;if(n)n.input.focus(),A(n.input,e);else{let r=this.opts.setCursor;r&&this.boundary.runListener("setCursor",()=>r(e))}})}clearNewParamId(){this.store.set({newParamId:null})}startEditingIdentified(e){let n=this.store.get();if(n.editingIdentified?.id===e)return!0;let r=n.identifiedParams.find(d=>d.id===e);if(!r)return!1;let i=Y(r);if(!P(i))return!1;let o=i==="date-range"?Ue(r.text):null,s=0,a=-1;for(let d of n.segments){if(d.type!=="text"&&d.param.id===e){a=s;break}s+=d.value.length}if(a<0)return!1;let l=a+r.text.length;return this.store.set({editingIdentified:{id:e,parameter:r.parameter,anchor:a,tail:l,text:r.text,iso:o?o.start:Tt(r),isoEnd:o?o.end:null,format:i},editingParam:null,editingAnchor:null,editingTail:null,caretOffset:l,activeDropdownIndex:-1,pillTapped:!0}),!0}exitEditingIdentified(){this.store.get().editingIdentified&&this.store.set({editingIdentified:null,activeDropdownIndex:-1})}startEditingParam(e){this.reEdit.start(e),this.store.get().editingParam?.id!==e&&this.startEditingIdentified(e)}replaceEditingRange(e){return this.reEdit.replaceRange(e)}exitEditMode(){this.reEdit.exit()}handleCaretAfterInput(e){this.reEdit.caretAfterInput(e)}handleCaretMove(e){let n=this.store.get().editingIdentified;n&&e!=null&&(e<n.anchor||e>n.tail)&&this.store.set({editingIdentified:null,activeDropdownIndex:-1}),this.reEdit.caretMove(e)}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}clearHighlight(e){this.store.get().activeDropdownIndex===e&&this.store.set({activeDropdownIndex:-1})}recordSubmit(e){this.fireTelemetry("submit",{query:e.query,completed_pills:e.completed_params.filter(n=>n.placeholder).map(n=>({key:n.parameter,value:n.text??""}))})}selectProduct(e){let n=this.store.get(),r=n.products.findIndex(o=>o.id===e.id),i=n.customFields?.items?.matched?.find(o=>o.source_id===e.id)?.origin_id;this.fireTelemetry("product_click",{query:n.text,product_id:e.id,...i&&{origin_id:i},position:r>=0?r+1:null}),this.emitter.emit("productSelect",e)}handleTextChange(e){this.applyTextChange(e,!0)}applyTextChange(e,n){this.store.get().editingIdentified&&this.store.set({editingIdentified:null,activeDropdownIndex:-1}),this.handleChange(e,n)}showPreviousMonth(){this.pageDateView(-1)}showNextMonth(){this.pageDateView(1)}pageDateView(e){let n=this.store.get();if(!P(n.activeFormatType)||!n.dateView)return;let r=lt(n.dateView,e);this.store.set({dateViewMonth:{...r,key:be(n)},activeDropdownIndex:-1})}skipActivePill(){let e=this.store.get();if(e.editingParam||e.inSelectionAnimation)return;let n=e.suggestions.filter(a=>a.parameter==="placeholder"),r=e.suggestions.filter(a=>a.parameter!=="placeholder");if(r.length===0)return;let i=r[0],o=r.slice(1),s=e.skippedParams.some(a=>a.parameter===i.parameter);this.store.set({suggestions:[...n,...o],pillTapped:o.length>0,activeDropdownIndex:-1,...s?{}:{skippedParams:[...e.skippedParams,{id:crypto.randomUUID(),parameter:i.parameter,suggestionPlaceholder:i.text}]}}),o.length===0&&this.fetchNow()}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}setFocused(e){this.store.get().isFocused!==e&&this.store.set({isFocused:e})}subscribe(e){let n=`subscribe#${++this.subscriberCount}`;return this.store.subscribe(r=>{this.boundary.runListener("subscribe",()=>e(r),n)})}getState(){return this.store.get()}getResult(){return this.buildResult()}buildResult(){let e=this.store.get();return J(e.text,e.completedParams,e.skippedParams,{identifiedParams:e.identifiedParams,isReady:e.isReady,customFields:e.customFields})}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,n){return this.emitter.on(e,n)}update(e){let n=this.opts.products,r=this.opts.showProducts,i=this.opts.optionOverrides;Object.assign(this.opts,e),"optionOverrides"in e&&e.optionOverrides!==i&&this.optionSource.refresh(),("products"in e&&e.products!==n||"showProducts"in e&&e.showProducts!==r)&&this.productsController.resync(),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||e.showSkipButton!==void 0||e.showOptionIcons!==void 0||e.showOptionImages!==void 0||e.showOptionCounts!==void 0||e.productsLayout!==void 0||e.productImageFallback!==void 0||e.showChipIcons!==void 0||e.showChipImages!==void 0)&&this.store.set({}),e.value!==void 0&&this.setValue(e.value),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let n=!this.store.get().text;this.applyOption(e),n&&this.store.get().text&&this.noteSearchStarted()}applyOption(e){let n=this.store.get();if(n.activeFormatType==="date-range"){let i=H(e);if(i){let o=n.dateRangeStart;if(!o){this.store.set({pendingRangeStart:{iso:i,key:be(n)}});return}this.store.set({pendingRangeStart:null}),this.selectOption(Xn(o,i));return}}if(n.editingIdentified){this.commitIdentifiedDate(e);return}if(n.editingParam&&n.editingAnchor!=null&&n.editingTail!=null){this.timers.clear(on),this.reEdit.selectOption(e);return}let r=tr(n,e);if(r){if(this.fireTelemetry("option",{raw_query:R(n.text,n.completedParams).rawQuery,selected_option:r.telemetry.selectedOption,other_options:P(n.activeFormatType)?[]:r.telemetry.otherOptions,key:r.telemetry.key,position:P(n.activeFormatType)?null:r.telemetry.position}),this.timers.clear(on),this.store.set({...r.patch,...Qe(n)}),this.startSelectionAnimationTimer(),this.timers.clear(Yr),r.remainingActionable>0){let i=r.consumedSuggestion;this.timers.schedule(Yr,()=>{this.store.get().suggestions.includes(i)&&this.store.set(o=>({suggestions:o.suggestions.filter(s=>s!==i)}))},Qr)}this.fetchNow()}}startSelectionAnimationTimer(){this.timers.schedule(qo,()=>this.store.set({inSelectionAnimation:!1}),Qr)}resolveVisitorId(){let e=this.opts.visitorId;if(typeof e!="function")return e;try{return e()}catch{return}}resolveSource(){return this.opts.source??(this.renderMode==="full"?"full-sdk":"headless-sdk")}fireImpression(){if(this.funnelTelemetry!==!0)return;let e=this.store.get(),n=e.suggestions.filter(o=>o.parameter!=="placeholder").map(o=>({key:o.parameter,options:(o.options??[]).slice(0,Ho).map(s=>s.text)})),r=e.products.map(o=>o.id);if(n.length===0&&r.length===0)return;let i=JSON.stringify([n,r]);i!==this.lastImpressionKey&&(this.lastImpressionKey=i,this.fireTelemetry("impression",{query:e.text,pills:n,product_ids:r}))}fireTelemetry(e,n){let r=this.funnelTelemetry===!0;if(!r&&Bo.has(e))return;if(!r&&e==="option"){let{key:o,position:s,...a}=n;n=a}let i=this.resolveSource();er({source:i,sessionId:this.sessionId,visitorId:r?this.resolveVisitorId():void 0,requestId:r?this.lastRequestId:null,keepalive:r,type:e,queryData:n,apiConfig:this.opts.apiConfig})}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"dropdown",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new ve(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,n={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"dropdown"},get showSkipButton(){return e.opts.showSkipButton??!0},get showOptionIcons(){return e.opts.showOptionIcons??!0},get showOptionImages(){return e.opts.showOptionImages??!0},get showOptionCounts(){return e.opts.showOptionCounts??!0},get productsLayout(){return e.opts.productsLayout??"row"},get productImageFallback(){return e.opts.productImageFallback??"image"},get showChipIcons(){return e.opts.showChipIcons??!0},get showChipImages(){return e.opts.showChipImages??!0},get optionsPosition(){return e.opts.optionsPosition??"below"},get onSubmit(){return e.emitter.hasListeners("submit")?e.emitSubmit:void 0},afterSubmit:()=>e.resetAfterSubmit(),submitButton:this.opts.submitButton,autoFocus:this.opts.autoFocus??!0,selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),skipActivePill:()=>this.skipActivePill(),selectProduct:i=>this.selectProduct(i),showPreviousMonth:()=>this.showPreviousMonth(),showNextMonth:()=>this.showNextMonth(),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i,!0),startEditingParam:i=>this.startEditingParam(i),handleCaretAfterInput:i=>this.handleCaretAfterInput(i),handleCaretMove:i=>this.handleCaretMove(i),replaceEditingRange:i=>this.replaceEditingRange(i)};this.domRefs=Wr(this.container,n);let r=()=>{this.domRefs&&tn(this.domRefs,this.store.get(),n)};this.subscribeBatchedRender(r),this.subscribeViewportBreakpoint(r),tn(this.domRefs,this.store.get(),n),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e=this,n={store:this.store,listboxId:this.listboxId,get showSkipButton(){return e.opts.showSkipButton??!0},get showOptionIcons(){return e.opts.showOptionIcons??!0},get showOptionImages(){return e.opts.showOptionImages??!0},get showOptionCounts(){return e.opts.showOptionCounts??!0},get productsLayout(){return e.opts.productsLayout??"row"},get productImageFallback(){return e.opts.productImageFallback??"image"},get optionsPosition(){return e.opts.optionsPosition??"below"},selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),skipActivePill:()=>this.skipActivePill(),selectProduct:i=>this.selectProduct(i),showPreviousMonth:()=>this.showPreviousMonth(),showNextMonth:()=>this.showNextMonth()};this.dropdownRefs=Nr(this.container,n);let r=()=>{this.dropdownRefs&&Zt(this.dropdownRefs,this.store.get(),n)};this.subscribeBatchedRender(r),this.subscribeViewportBreakpoint(r),Zt(this.dropdownRefs,this.store.get(),n),this.subscribeNewParamTimer()}subscribeViewportBreakpoint(e){if(typeof window>"u"||typeof window.matchMedia!="function")return;let n=window.matchMedia(Ke),r=()=>e();n.addEventListener("change",r),this.unsubscribers.push(()=>n.removeEventListener("change",r))}subscribeBatchedRender(e){let n=!1;this.unsubscribers.push(this.store.subscribe(()=>{n||(n=!0,queueMicrotask(()=>{n=!1,e()}))}))}subscribeSkeletonMirror(){this.unsubscribers.push(this.store.subscribe((e,n)=>{if(!e.skeletonOptions)return;if(!n.isLoading&&e.isLoading){e.skeletonRequested||this.store.set({skeletonRequested:!0});return}if(!n.isLoading||e.isLoading)return;let r={skeletonOptions:null,skeletonSuggestion:null,skeletonRequested:!1};if(!e.skeletonExiting){this.store.set(r);return}this.timers.schedule(on,()=>this.store.set(r),Uo)}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,n)=>{e.newParamId&&e.newParamId!==n.newParamId&&this.timers.schedule(Wo,()=>this.store.set({newParamId:null}),$o)}))}handleChange(e,n){let r=this.store.get();n&&e&&!r.text&&this.noteSearchStarted(),this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:o}=Tn(e,r.completedParams);o.length>0&&this.store.set({completedParams:i}),this.maybePromoteExactMatch(e),this.maybeOpenPendingSpan()}maybeOpenPendingSpan(){let e=this.store.get();if(e.pendingSpan||e.actionableSuggestions.length===0)return;let n=B(e.text,Math.min(e.filterBase,e.text.length),e.placeholderText),r=Sn(e.segments,n);e.text.slice(r).trim().length!==0&&this.store.set({pendingSpan:{anchor:r,snapshot:e.actionableSuggestions}})}maybeExitReEditOnNoMatch(){let e=this.store.get();if(!e.editingParam||e.editingAnchor==null||e.completedParams.some(o=>o.id===e.editingParam?.id)||this.optionSource.owns(e.editingParam.suggestionParameter,e.optionQuery))return;let n=e.caretOffset??e.editingAnchor,r=e.text.slice(e.editingAnchor,n);X(e.editingParam.options,r).some(o=>o.is_tappable)||(this.reEdit.exit(),this.fetchNow())}fetchNow(){let e=this.store.get(),{rawQuery:n,completedParams:r}=R(e.text,e.completedParams);this.fetchController.doFetch(n,r)}commitIdentifiedDate(e){let n=this.store.get(),r=n.editingIdentified;if(!r)return;if(n.text.slice(r.anchor,r.tail)!==r.text){this.store.set({editingIdentified:null,activeDropdownIndex:-1});return}let i=n.text.slice(0,r.anchor),o=n.text.slice(r.tail),s=r.anchor===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,l=o.length===0||o[0]!==" "?`${s} `:s,d=i+l+o,u=d.length,c={id:crypto.randomUUID(),placeholder:"",parameter:r.parameter,text:s,value:e.value,kind:e.kind,suggestionParameter:r.parameter,suggestionPlaceholder:j(r.parameter),options:[],metadata:e.metadata,icon:e.icon,icon_svg:e.icon_svg,image_url:e.image_url};this.fireTelemetry("option",{raw_query:R(n.text,n.completedParams).rawQuery,selected_option:e.text,other_options:[],key:r.parameter,position:null}),this.store.set({text:d,completedParams:[...n.completedParams,c],identifiedParams:n.identifiedParams.filter(m=>m.id!==r.id),newParamId:c.id,filterBase:u,caretOffset:u,editingIdentified:null,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0}),this.startSelectionAnimationTimer(),this.scheduleSetCursor(u),this.fetchNow()}maybePromoteExactMatch(e){let n=this.store.get();if(P(n.activeFormatType))return;let r=Ye({mode:"fresh",text:e,completedParams:n.completedParams,suggestions:n.suggestions,filterBase:n.filterBase,filterInProgress:n.filterInProgress});r&&this.store.set(r.patch)}};export{sn as AIAutocomplete,ar as ATTRIBUTION_URL,Ot as DATE_RANGE_META_END,It as DATE_RANGE_META_START,Pr as DEFAULT_OPTION_COUNT_UNIT,ve as ModeController,Ke as OPTIONS_GRID_MOBILE_QUERY,Kt as OPTION_ENTER_DELAY_VAR,no as OPTION_ENTER_FADE_MS,ro as OPTION_ENTER_RISE_MS,io as OPTION_ENTER_RISE_PX,to as OPTION_ENTER_STAGGER_MS,Bi as PLACEHOLDER_FADE_OUT_MS,se as PLACEHOLDER_LEAVING_ATTR,Wi as PLACEHOLDER_SWAP_GAP_MS,Fi as PLACEHOLDER_TYPE_MS,Hi as PLACEHOLDER_WORD_PAUSE_MS,$n as PRODUCT_PATH_PREFIX,ji as PRODUCT_ROW_PX_PER_LINE,Yn as RANGE_SEPARATOR,mn as SCHEMA_VERSION,Lr as SCROLL_ARROW_ATTR,Dr as SCROLL_ARROW_BOTTOM_VAR,Ar as SCROLL_ARROW_CLASS,Rr as SCROLL_ARROW_FADE_MS,kr as SCROLL_ARROW_LABEL,Mr as SCROLL_ARROW_SCROLL_IDLE_MS,le as SCROLL_ARROW_VISIBLE_ATTR,cn as SKIPPED_PARAM_TEXT,Me as WEEKDAY_LABELS,lt as addMonths,$t as attachProductRowWheel,zt as attachScrollArrow,Nt as buildAttributionUrl,dt as buildDateOptions,R as buildQuery,J as buildSubmitResult,ut as cellDay,H as cellIso,St as chipIdFromTap,jn as computeOptionsGridLayout,Ht as containScroll,nn as createStore,yt as cursorIsAtEnd,Wt as dateCellMarks,Se as dateSelectionFor,Be as extractPlainText,re as formatAbsoluteDate,Rn as formatDate,Qn as formatDateRange,xe as formatOptionCount,_ as getCursorOffset,Ft as getFooterHint,j as identifiedParamLabel,P as isCalendarFormat,kt as isOptionsGridMobileViewport,k as isoDate,xt as keepCaretOnChip,Dt as measureOptionsGrid,st as monthLabel,Rt as needsOptionsGridMeasurement,oo as optionCountLabel,Yt as optionEnterDelayMs,so as optionHasImage,U as optionImageSrc,Xt as optionLabel,Qt as optionsEntranceDurationMs,Lt as optionsGridTemplateColumns,De as parseDate,fe as parseLooseDate,Ue as parseLooseDateRange,ht as plainTextLength,Mt as planOptionsGrid,vt as previousGraphemeBoundary,Gn as productFromMatchedItem,Gt as productInitial,Sr as productRowWheelTarget,wt as productsFromCustomFields,en as renderEditableContent,Y as resolveFormatType,Tt as resolveIdentifiedDate,_t as sameOptionRows,ye as sanitizeOptionIconSvg,mt as scrollCaretIntoView,ct as selectedIsoFromText,he as selectedRangeFor,A as setCursorOffset,ue as toWireIdentifiedParams,Bt as visibleDateRange,pe as withSkippedParams};
|
|
2259
|
+
`;var rt=class{constructor(){this.reported=new Set}run(e,n){try{return n()}catch(r){this.report(e,r,e);return}}runListener(e,n,r=e){try{return n(),!0}catch(i){return this.report(e,i,r),!1}}report(e,n,r){this.reported.has(r)||(this.reported.add(r),console.error(`[AIAutocomplete] "${e}" threw. The error is contained \u2014 SDK state is unaffected. Later failures of "${e}" on this instance are not logged.`,n))}};var it=class{constructor(e){this.boundary=e;this.listeners={};this.keys=new WeakMap;this.registrationCount=0}on(e,n){let r=`${String(e)}#${++this.registrationCount}`,i=(...s)=>n(...s);this.keys.set(i,r);let o=this.listeners[e];return o||(o=new Set,this.listeners[e]=o),o.add(i),()=>{this.listeners[e]?.delete(i)}}emit(e,...n){let r=this.listeners[e];if(!r)return!0;let i=!0;for(let o of r)this.boundary.runListener(String(e),()=>o(...n),this.keys.get(o)??String(e))||(i=!1);return i}hasListeners(e){return(this.listeners[e]?.size??0)>0}clear(){this.listeners={}}};var ot=class{constructor(){this.timers=new Map}schedule(e,n,r){this.clear(e);let i=setTimeout(()=>{this.timers.delete(e),n()},r);this.timers.set(e,i)}clear(e){let n=this.timers.get(e);n!==void 0&&(clearTimeout(n),this.timers.delete(e))}clearAll(){for(let e of this.timers.values())clearTimeout(e);this.timers.clear()}};var Pe=class{constructor(e,n="auto",r){this.container=e;this.mode=n;this.onResolve=r;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)}};var Ho=50,Bo=new Set(["search_started","submit","product_click","impression"]),Wo="newParam",Qr="suggestionRemoval",qo="selectionAnimation",an="skeletonExit",$o=650,Go=0;function Vo(){return`:ac-${++Go}:`}var Xr=170,Uo=100;function jr(){return{text:"",completedParams:[],identifiedParams:[],skippedParams:[],pendingSpan:null,suggestions:[],products:[],customFields:null,optionSearch:null,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,skeletonOptions:null,skeletonSuggestion:null,skeletonRequested:!1,dateViewMonth:null,pendingRangeStart:null,editingIdentified:null}}var ln=class{constructor(e,n={}){this.inputStore=on(jr());this._listboxId=Vo();this.modeController=null;this.unsubscribers=[];this.domRefs=null;this.dropdownRefs=null;this.timers=new ot;this.boundary=new rt;this.subscriberCount=0;this.emitter=new it(this.boundary);this.sessionId=crypto.randomUUID();this.lastRequestId=null;this.searchStartedSessionId=null;this.funnelTelemetry=null;this.pendingSearchStarted=!1;this.openWordText=null;this.heldIdentified=null;this.lastImpressionKey="";this.emitSubmit=e=>(this.recordSubmit(e),this.emitter.emit("submit",e));this.emitError=e=>this.emitter.emit("error",e);this.container=e,this.opts=n,this.renderMode=n.renderMode??"full",this.store=$r(this.inputStore,r=>er(r,this.opts)),n.onSubmit&&this.emitter.on("submit",n.onSubmit),n.onResult&&this.emitter.on("result",n.onResult),n.onError&&this.emitter.on("error",n.onError),n.onChange&&this.emitter.on("change",n.onChange),n.onParamsChange&&this.emitter.on("paramsChange",n.onParamsChange),n.onStateChange&&this.emitter.on("stateChange",n.onStateChange),n.onFocus&&this.emitter.on("focus",n.onFocus),n.onBlur&&this.emitter.on("blur",n.onBlur),n.onProductSelect&&this.emitter.on("productSelect",n.onProductSelect),n.value!==void 0&&this.store.set({text:n.value}),n.completedParams!==void 0&&this.store.set({completedParams:n.completedParams}),this.pillsController=new Ge(this.store,{onPillSelected:({rawQuery:r,selectedPill:i,otherPills:o})=>{this.fireTelemetry("pill",{raw_query:r,selected_pill:i,other_pills:o})}}),this.reEdit=new ze({store:this.store,scheduleSetCursor:r=>this.scheduleSetCursor(r),fireTelemetry:(r,i)=>this.fireTelemetry(r,i),startSelectionAnimationTimer:()=>this.startSelectionAnimationTimer(),fetchNow:()=>this.fetchNow()}),this.productsController=new Ve(this.store,()=>this.opts.products,()=>this.opts.showProducts!==!1),this.optionSource=new $e(this.store,()=>this.opts.optionOverrides,{onAnswer:r=>{r==="edit"?this.reEdit.promoteIfExact():this.maybePromoteExactMatch(this.store.get().text)},onMiss:(r,i)=>{r==="pill"&&i.length>0&&this.fetchController.attemptNow()}}),this.fetchController=new Me(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.emitter.hasListeners("error")?this.emitError:void 0,()=>this.sessionId,()=>this.resolveSource(),()=>this.opts.additionalContext,{onRequest:({query:r,signal:i,isCurrent:o})=>{this.productsController.run(r,i,o).catch(()=>{})},onAutoMatch:({active:r,matched:i,rawQuery:o})=>{let s=r.options??[];this.fireTelemetry("option",{raw_query:o,selected_option:i.text,other_options:s.filter(a=>a.text!==i.text).map(a=>a.text),key:r.parameter,position:se(s,i.text)})},onResponse:({requestId:r,funnelTelemetry:i})=>{this.lastRequestId=r,this.funnelTelemetry=i,this.pendingSearchStarted&&(this.pendingSearchStarted=!1,this.fireTelemetry("search_started",{})),this.fireImpression(),this.emitter.hasListeners("result")&&this.emitter.emit("result",this.buildResult())},productsForResponse:r=>this.productsController.forResponse(r),consumerTick:(r,i)=>this.optionSource.tick(r,i),isWordOpen:()=>this.isWordOpen(),holdIdentified:r=>{this.heldIdentified={text:this.store.get().text,candidates:r}}}),this.keyboardController=new qe(this.store,{columns:n.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.emitter.hasListeners("submit")?this.emitSubmit:void 0,getOptionsPosition:()=>this.opts.optionsPosition??"below",afterSubmit:this.renderMode==="full"?()=>this.resetAfterSubmit():void 0,selectOption:r=>this.selectOption(r),removeParamAtCaret:r=>this.removeParamAtCaret(r),startEditingParamAtCaret:r=>this.startEditingParamAtCaret(r),exitEditMode:()=>this.exitEditMode(),exitEditingIdentified:()=>this.exitEditingIdentified(),skipActivePill:()=>this.skipActivePill(),endTypedWord:()=>this.endTypedWord()}),this.unsubscribers.push(this.store.subscribe((r,i)=>{r.text!==i.text&&this.emitter.emit("change",r.text),r.completedParams!==i.completedParams&&this.emitter.emit("paramsChange",r.completedParams),r.isFocused!==i.isFocused&&(r.isFocused?this.emitter.emit("focus"):this.emitter.emit("blur")),this.emitter.emit("stateChange",r)})),this.unsubscribers.push(this.store.subscribe(()=>this.maybeExitReEditOnNoMatch())),this.subscribeSkeletonMirror(),this.unsubscribers.push(this.store.subscribe((r,i)=>{if(r.text===i.text&&r.completedParams===i.completedParams||r.identifiedParams.length===0)return;let{valid:o,invalid:s}=fe(r.text,r.completedParams,r.identifiedParams);s.length>0&&this.store.set({identifiedParams:o})})),this.unsubscribers.push(this.store.subscribe((r,i)=>{if(r.identifiedParams===i.identifiedParams)return;let o=r.editingIdentified;if(!o||r.identifiedParams.some(l=>l.id===o.id))return;let s=0,a;for(let l of r.segments){if(l.type==="identified"&&s===o.anchor&&l.value===o.text){a=l.param;break}s+=l.value.length}if(a){this.store.set({editingIdentified:{...o,id:a.id}});return}this.store.set({editingIdentified:null,activeDropdownIndex:-1})})),this.unsubscribers.push(this.store.subscribe(r=>{let i=r.pendingRangeStart;!i||i.key===xe(r)||this.store.set({pendingRangeStart:null})})),this.unsubscribers.push(this.store.subscribe((r,i)=>{let o=r.pendingSpan;if(!o||r.text===i.text&&r.completedParams===i.completedParams&&r.identifiedParams===i.identifiedParams)return;let s=o.anchor;if(r.text!==i.text){let l=En(i.text,r.text,s);if(l===null){this.store.set({pendingSpan:null});return}s=l}r.text.slice(s).trim().length===0||yn(r.segments,s)?this.store.set({pendingSpan:null}):s!==o.anchor&&this.store.set({pendingSpan:{anchor:s,snapshot:o.snapshot}})})),this.renderMode!=="headless"&&(Kr(this.opts.styleRoot??Z(this.container)),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.optionSource.start(),this.fetchController.start()}focus(){this.domRefs?.input.focus()}blur(){this.domRefs?.input.blur()}reset(){let e=this.store.get().isFocused;this.optionSource.reset(),this.store.set({...jr(),isFocused:e,skipNextFetch:!0}),this.sessionId=crypto.randomUUID(),this.lastRequestId=null,this.lastImpressionKey="",this.pendingSearchStarted=!1,this.fetchController.doFetch("",[])}resetAfterSubmit(){this.opts.resetOnSubmit!==!1&&this.reset()}destroy(){this.fetchController.dispose(),this.optionSource.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&&(ar(this.domRefs.input),en(this.domRefs.dropdown)),this.dropdownRefs&&en(this.dropdownRefs.dropdown),this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}prefillText(e){this.applyTextChange(e,!1)}noteSearchStarted(){this.searchStartedSessionId!==this.sessionId&&(this.searchStartedSessionId=this.sessionId,this.funnelTelemetry===null?this.pendingSearchStarted=!0:this.fireTelemetry("search_started",{}))}setValue(e){let n=this.store.get();if(n.editingIdentified&&e!==n.text){this.store.set({text:e,editingIdentified:null,activeDropdownIndex:-1});return}this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e);let n=this.store.get().text.length;this.store.set({caretOffset:n,isFocused:!0}),this.scheduleSetCursor(n)}removeLastParam(){this.pillsController.removeLastParam()}findChipSpanAt(e){let n=0;for(let r of this.store.get().segments){let i=n;if(n+=r.value.length,r.type!=="text"&&e>i&&e<=n)return{kind:r.type,param:r.param,start:i,end:n}}return null}withoutChip(e,n){return n.kind==="completed"?{completedParams:e.completedParams.filter(r=>r.id!==n.param.id)}:{identifiedParams:e.identifiedParams.filter(r=>r.id!==n.param.id)}}removeParamAtCaret(e){let n=this.findChipSpanAt(e);if(!n)return!1;let{text:r}=this.store.get(),{start:i,end:o}=n;if(e===o){let{text:l,removed:d}=je(r,i,o);return this.store.set(c=>({text:l,filterBase:Math.min(c.filterBase>i?Math.max(i,c.filterBase-d):c.filterBase,l.length),...this.withoutChip(c,n),pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(i),!0}let s=Pt(r,e),a=r.slice(0,s)+r.slice(e);return this.store.set(l=>({text:a,filterBase:Math.min(l.filterBase,a.length),...this.withoutChip(l,n),pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(s),!0}startEditingParamAtCaret(e){let n=this.findChipSpanAt(e);return!n||n.kind!=="completed"||n.end!==e?!1:(this.reEdit.start(n.param.id),this.store.get().editingParam?.id===n.param.id)}scheduleSetCursor(e){queueMicrotask(()=>{let n=this.domRefs;if(n)n.input.focus(),L(n.input,e);else{let r=this.opts.setCursor;r&&this.boundary.runListener("setCursor",()=>r(e))}})}clearNewParamId(){this.store.set({newParamId:null})}startEditingIdentified(e){let n=this.store.get();if(n.editingIdentified?.id===e)return!0;let r=n.identifiedParams.find(d=>d.id===e);if(!r)return!1;let i=X(r);if(!E(i))return!1;let o=i==="date-range"?Ke(r.text):null,s=0,a=-1;for(let d of n.segments){if(d.type!=="text"&&d.param.id===e){a=s;break}s+=d.value.length}if(a<0)return!1;let l=a+r.text.length;return this.store.set({editingIdentified:{id:e,parameter:r.parameter,anchor:a,tail:l,text:r.text,iso:o?o.start:Ct(r),isoEnd:o?o.end:null,format:i},editingParam:null,editingAnchor:null,editingTail:null,caretOffset:l,activeDropdownIndex:-1,pillTapped:!0}),!0}exitEditingIdentified(){this.store.get().editingIdentified&&this.store.set({editingIdentified:null,activeDropdownIndex:-1})}startEditingParam(e){this.reEdit.start(e),this.store.get().editingParam?.id!==e&&this.startEditingIdentified(e)}replaceEditingRange(e){return this.reEdit.replaceRange(e)}exitEditMode(){this.reEdit.exit()}handleCaretAfterInput(e){this.reEdit.caretAfterInput(e)}handleCaretMove(e){let n=this.store.get().editingIdentified;n&&e!=null&&(e<n.anchor||e>n.tail)&&this.store.set({editingIdentified:null,activeDropdownIndex:-1}),this.reEdit.caretMove(e)}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}clearHighlight(e){this.store.get().activeDropdownIndex===e&&this.store.set({activeDropdownIndex:-1})}recordSubmit(e){this.fireTelemetry("submit",{query:e.query,completed_pills:e.completed_params.filter(n=>n.placeholder).map(n=>({key:n.parameter,value:n.text??""}))})}selectProduct(e){let n=this.store.get(),r=n.products.findIndex(o=>o.id===e.id),i=n.customFields?.items?.matched?.find(o=>o.source_id===e.id)?.origin_id;this.fireTelemetry("product_click",{query:n.text,product_id:e.id,...i&&{origin_id:i},position:r>=0?r+1:null}),this.emitter.emit("productSelect",e)}handleTextChange(e){this.applyTextChange(e,!0)}applyTextChange(e,n){this.store.get().editingIdentified&&this.store.set({editingIdentified:null,activeDropdownIndex:-1}),this.handleChange(e,n)}showPreviousMonth(){this.pageDateView(-1)}showNextMonth(){this.pageDateView(1)}pageDateView(e){let n=this.store.get();if(!E(n.activeFormatType)||!n.dateView)return;let r=ct(n.dateView,e);this.store.set({dateViewMonth:{...r,key:xe(n)},activeDropdownIndex:-1})}skipActivePill(){let e=this.store.get();if(e.editingParam||e.inSelectionAnimation)return;let n=e.suggestions.filter(a=>a.parameter==="placeholder"),r=e.suggestions.filter(a=>a.parameter!=="placeholder");if(r.length===0)return;let i=r[0],o=r.slice(1),s=e.skippedParams.some(a=>a.parameter===i.parameter);this.store.set({suggestions:[...n,...o],pillTapped:o.length>0,activeDropdownIndex:-1,...s?{}:{skippedParams:[...e.skippedParams,{id:crypto.randomUUID(),parameter:i.parameter,suggestionPlaceholder:i.text}]}}),o.length===0&&this.fetchNow()}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}setFocused(e){this.store.get().isFocused!==e&&this.store.set({isFocused:e})}subscribe(e){let n=`subscribe#${++this.subscriberCount}`;return this.store.subscribe(r=>{this.boundary.runListener("subscribe",()=>e(r),n)})}getState(){return this.store.get()}getResult(){return this.buildResult()}buildResult(){let e=this.store.get();return ee(e.text,e.completedParams,e.skippedParams,{identifiedParams:e.identifiedParams,isReady:e.isReady,customFields:e.customFields})}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,n){return this.emitter.on(e,n)}update(e){let n=this.opts.products,r=this.opts.showProducts,i=this.opts.optionOverrides;Object.assign(this.opts,e),"optionOverrides"in e&&e.optionOverrides!==i&&this.optionSource.refresh(),("products"in e&&e.products!==n||"showProducts"in e&&e.showProducts!==r)&&this.productsController.resync(),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||e.showSkipButton!==void 0||e.showOptionIcons!==void 0||e.showOptionImages!==void 0||e.showOptionCounts!==void 0||e.productsLayout!==void 0||e.productImageFallback!==void 0||e.showChipIcons!==void 0||e.showChipImages!==void 0)&&this.store.set({}),e.value!==void 0&&this.setValue(e.value),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let n=!this.store.get().text;this.applyOption(e),n&&this.store.get().text&&this.noteSearchStarted()}applyOption(e){let n=this.store.get();if(n.activeFormatType==="date-range"){let i=W(e);if(i){let o=n.dateRangeStart;if(!o){this.store.set({pendingRangeStart:{iso:i,key:xe(n)}});return}this.store.set({pendingRangeStart:null}),this.selectOption(jn(o,i));return}}if(n.editingIdentified){this.commitIdentifiedDate(e);return}if(n.editingParam&&n.editingAnchor!=null&&n.editingTail!=null){this.timers.clear(an),this.reEdit.selectOption(e);return}let r=nr(n,e);if(r){if(this.fireTelemetry("option",{raw_query:M(n.text,n.completedParams).rawQuery,selected_option:r.telemetry.selectedOption,other_options:E(n.activeFormatType)?[]:r.telemetry.otherOptions,key:r.telemetry.key,position:E(n.activeFormatType)?null:r.telemetry.position}),this.timers.clear(an),this.store.set({...r.patch,...Xe(n)}),this.startSelectionAnimationTimer(),this.timers.clear(Qr),r.remainingActionable>0){let i=r.consumedSuggestion;this.timers.schedule(Qr,()=>{this.store.get().suggestions.includes(i)&&this.store.set(o=>({suggestions:o.suggestions.filter(s=>s!==i)}))},Xr)}this.fetchNow()}}startSelectionAnimationTimer(){this.timers.schedule(qo,()=>this.store.set({inSelectionAnimation:!1}),Xr)}resolveVisitorId(){let e=this.opts.visitorId;if(typeof e!="function")return e;try{return e()}catch{return}}resolveSource(){return this.opts.source??(this.renderMode==="full"?"full-sdk":"headless-sdk")}fireImpression(){if(this.funnelTelemetry!==!0)return;let e=this.store.get(),n=e.suggestions.filter(o=>o.parameter!=="placeholder").map(o=>({key:o.parameter,options:(o.options??[]).slice(0,Ho).map(s=>s.text)})),r=e.products.map(o=>o.id);if(n.length===0&&r.length===0)return;let i=JSON.stringify([n,r]);i!==this.lastImpressionKey&&(this.lastImpressionKey=i,this.fireTelemetry("impression",{query:e.text,pills:n,product_ids:r}))}fireTelemetry(e,n){let r=this.funnelTelemetry===!0;if(!r&&Bo.has(e))return;if(!r&&e==="option"){let{key:o,position:s,...a}=n;n=a}let i=this.resolveSource();tr({source:i,sessionId:this.sessionId,visitorId:r?this.resolveVisitorId():void 0,requestId:r?this.lastRequestId:null,keepalive:r,type:e,queryData:n,apiConfig:this.opts.apiConfig})}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"dropdown",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new Pe(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,n={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"dropdown"},get showSkipButton(){return e.opts.showSkipButton??!0},get showOptionIcons(){return e.opts.showOptionIcons??!0},get showOptionImages(){return e.opts.showOptionImages??!0},get showOptionCounts(){return e.opts.showOptionCounts??!0},get productsLayout(){return e.opts.productsLayout??"row"},get productImageFallback(){return e.opts.productImageFallback??"image"},get showChipIcons(){return e.opts.showChipIcons??!0},get showChipImages(){return e.opts.showChipImages??!0},get optionsPosition(){return e.opts.optionsPosition??"below"},get onSubmit(){return e.emitter.hasListeners("submit")?e.emitSubmit:void 0},afterSubmit:()=>e.resetAfterSubmit(),submitButton:this.opts.submitButton,autoFocus:this.opts.autoFocus??!0,selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),skipActivePill:()=>this.skipActivePill(),selectProduct:i=>this.selectProduct(i),showPreviousMonth:()=>this.showPreviousMonth(),showNextMonth:()=>this.showNextMonth(),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i,!0),startEditingParam:i=>this.startEditingParam(i),handleCaretAfterInput:i=>this.handleCaretAfterInput(i),handleCaretMove:i=>this.handleCaretMove(i),replaceEditingRange:i=>this.replaceEditingRange(i)};this.domRefs=qr(this.container,n);let r=()=>{this.domRefs&&rn(this.domRefs,this.store.get(),n)};this.subscribeBatchedRender(r),this.subscribeViewportBreakpoint(r),rn(this.domRefs,this.store.get(),n),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e=this,n={store:this.store,listboxId:this.listboxId,get showSkipButton(){return e.opts.showSkipButton??!0},get showOptionIcons(){return e.opts.showOptionIcons??!0},get showOptionImages(){return e.opts.showOptionImages??!0},get showOptionCounts(){return e.opts.showOptionCounts??!0},get productsLayout(){return e.opts.productsLayout??"row"},get productImageFallback(){return e.opts.productImageFallback??"image"},get optionsPosition(){return e.opts.optionsPosition??"below"},selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),skipActivePill:()=>this.skipActivePill(),selectProduct:i=>this.selectProduct(i),showPreviousMonth:()=>this.showPreviousMonth(),showNextMonth:()=>this.showNextMonth()};this.dropdownRefs=Fr(this.container,n);let r=()=>{this.dropdownRefs&&tn(this.dropdownRefs,this.store.get(),n)};this.subscribeBatchedRender(r),this.subscribeViewportBreakpoint(r),tn(this.dropdownRefs,this.store.get(),n),this.subscribeNewParamTimer()}subscribeViewportBreakpoint(e){if(typeof window>"u"||typeof window.matchMedia!="function")return;let n=window.matchMedia(Ye),r=()=>e();n.addEventListener("change",r),this.unsubscribers.push(()=>n.removeEventListener("change",r))}subscribeBatchedRender(e){let n=!1;this.unsubscribers.push(this.store.subscribe(()=>{n||(n=!0,queueMicrotask(()=>{n=!1,e()}))}))}subscribeSkeletonMirror(){this.unsubscribers.push(this.store.subscribe((e,n)=>{if(!e.skeletonOptions)return;if(!n.isLoading&&e.isLoading){e.skeletonRequested||this.store.set({skeletonRequested:!0});return}if(!n.isLoading||e.isLoading)return;let r={skeletonOptions:null,skeletonSuggestion:null,skeletonRequested:!1};if(!e.skeletonExiting){this.store.set(r);return}this.timers.schedule(an,()=>this.store.set(r),Uo)}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,n)=>{e.newParamId&&e.newParamId!==n.newParamId&&this.timers.schedule(Wo,()=>this.store.set({newParamId:null}),$o)}))}handleChange(e,n){let r=this.store.get();n&&e&&!r.text&&this.noteSearchStarted(),this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:o}=In(e,r.completedParams);o.length>0&&this.store.set({completedParams:i});let s=this.heldIdentified;this.heldIdentified=null,this.openWordText=n&&/\S$/.test(e)?e:null,this.maybePromoteExactMatch(e),s&&/^\s+$/.test(e.slice(s.text.length))&&e.startsWith(s.text)&&this.admitIdentified(s.candidates),this.maybeOpenPendingSpan()}isWordOpen(){return this.opts.commitOnWordEnd===!0&&this.openWordText===this.store.get().text}admitIdentified(e){let n=this.store.get(),{valid:r}=fe(n.text,n.completedParams,e);r.length!==0&&this.store.set({identifiedParams:[...n.identifiedParams,...r]})}endTypedWord(){if(!this.isWordOpen())return!1;let e=this.heldIdentified;this.heldIdentified=null,this.openWordText=null;let n=this.store.get();this.maybePromoteExactMatch(n.text),e?.text===n.text&&this.admitIdentified(e.candidates);let r=this.store.get();return r.completedParams!==n.completedParams||r.identifiedParams!==n.identifiedParams}maybeOpenPendingSpan(){let e=this.store.get();if(e.pendingSpan||e.actionableSuggestions.length===0)return;let n=q(e.text,Math.min(e.filterBase,e.text.length),e.placeholderText),r=xn(e.segments,n);e.text.slice(r).trim().length!==0&&this.store.set({pendingSpan:{anchor:r,snapshot:e.actionableSuggestions}})}maybeExitReEditOnNoMatch(){let e=this.store.get();if(!e.editingParam||e.editingAnchor==null||e.completedParams.some(o=>o.id===e.editingParam?.id)||this.optionSource.owns(e.editingParam.suggestionParameter,e.optionQuery))return;let n=e.caretOffset??e.editingAnchor,r=e.text.slice(e.editingAnchor,n);z(e.editingParam.options,r).some(o=>o.is_tappable)||(this.reEdit.exit(),this.fetchNow())}fetchNow(){let e=this.store.get(),{rawQuery:n,completedParams:r}=M(e.text,e.completedParams);this.fetchController.doFetch(n,r)}commitIdentifiedDate(e){let n=this.store.get(),r=n.editingIdentified;if(!r)return;if(n.text.slice(r.anchor,r.tail)!==r.text){this.store.set({editingIdentified:null,activeDropdownIndex:-1});return}let i=n.text.slice(0,r.anchor),o=n.text.slice(r.tail),s=r.anchor===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,l=o.length===0||o[0]!==" "?`${s} `:s,d=i+l+o,c=d.length,u={id:crypto.randomUUID(),placeholder:"",parameter:r.parameter,text:s,value:e.value,kind:e.kind,suggestionParameter:r.parameter,suggestionPlaceholder:J(r.parameter),options:[],metadata:e.metadata,icon:e.icon,icon_svg:e.icon_svg,image_url:e.image_url};this.fireTelemetry("option",{raw_query:M(n.text,n.completedParams).rawQuery,selected_option:e.text,other_options:[],key:r.parameter,position:null}),this.store.set({text:d,completedParams:[...n.completedParams,u],identifiedParams:n.identifiedParams.filter(m=>m.id!==r.id),newParamId:u.id,filterBase:c,caretOffset:c,editingIdentified:null,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0}),this.startSelectionAnimationTimer(),this.scheduleSetCursor(c),this.fetchNow()}maybePromoteExactMatch(e){let n=this.store.get();if(E(n.activeFormatType)||this.isWordOpen())return;let r=Qe({mode:"fresh",text:e,completedParams:n.completedParams,suggestions:n.suggestions,filterBase:n.filterBase,filterInProgress:n.filterInProgress});r&&this.store.set(r.patch)}};export{ln as AIAutocomplete,lr as ATTRIBUTION_URL,Lt as DATE_RANGE_META_END,At as DATE_RANGE_META_START,wr as DEFAULT_OPTION_COUNT_UNIT,Pe as ModeController,Ye as OPTIONS_GRID_MOBILE_QUERY,Qt as OPTION_ENTER_DELAY_VAR,no as OPTION_ENTER_FADE_MS,ro as OPTION_ENTER_RISE_MS,io as OPTION_ENTER_RISE_PX,to as OPTION_ENTER_STAGGER_MS,Bi as PLACEHOLDER_FADE_OUT_MS,ae as PLACEHOLDER_LEAVING_ATTR,Wi as PLACEHOLDER_SWAP_GAP_MS,Fi as PLACEHOLDER_TYPE_MS,Hi as PLACEHOLDER_WORD_PAUSE_MS,Gn as PRODUCT_PATH_PREFIX,ji as PRODUCT_ROW_PX_PER_LINE,Qn as RANGE_SEPARATOR,fn as SCHEMA_VERSION,Rr as SCROLL_ARROW_ATTR,Dr as SCROLL_ARROW_BOTTOM_VAR,Lr as SCROLL_ARROW_CLASS,Mr as SCROLL_ARROW_FADE_MS,_r as SCROLL_ARROW_LABEL,kr as SCROLL_ARROW_SCROLL_IDLE_MS,de as SCROLL_ARROW_VISIBLE_ATTR,un as SKIPPED_PARAM_TEXT,ke as WEEKDAY_LABELS,ct as addMonths,Vt as attachProductRowWheel,Zt as attachScrollArrow,Ht as buildAttributionUrl,ut as buildDateOptions,M as buildQuery,ee as buildSubmitResult,mt as cellDay,W as cellIso,yt as chipIdFromTap,zn as computeOptionsGridLayout,Wt as containScroll,on as createStore,Et as cursorIsAtEnd,$t as dateCellMarks,ye as dateSelectionFor,We as extractPlainText,ie as formatAbsoluteDate,Mn as formatDate,Xn as formatDateRange,ve as formatOptionCount,_ as getCursorOffset,Bt as getFooterHint,J as identifiedParamLabel,E as isCalendarFormat,Nt as isOptionsGridMobileViewport,D as isoDate,vt as keepCaretOnChip,_t as measureOptionsGrid,lt as monthLabel,kt as needsOptionsGridMeasurement,oo as optionCountLabel,Xt as optionEnterDelayMs,so as optionHasImage,Y as optionImageSrc,zt as optionLabel,jt as optionsEntranceDurationMs,Mt as optionsGridTemplateColumns,De as parseDate,he as parseLooseDate,Ke as parseLooseDateRange,St as plainTextLength,Dt as planOptionsGrid,Pt as previousGraphemeBoundary,Vn as productFromMatchedItem,Ut as productInitial,xr as productRowWheelTarget,It as productsFromCustomFields,nn as renderEditableContent,X as resolveFormatType,Ct as resolveIdentifiedDate,Ft as sameOptionRows,Ee as sanitizeOptionIconSvg,gt as scrollCaretIntoView,pt as selectedIsoFromText,Se as selectedRangeFor,L as setCursorOffset,pe as toWireIdentifiedParams,qt as visibleDateRange,me as withSkippedParams};
|
|
2260
2260
|
//# sourceMappingURL=index.mjs.map
|