@magicx-eng/ai-autocomplete-vanilla 0.1.18 → 0.1.20

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/index.js DELETED
@@ -1,873 +0,0 @@
1
- "use strict";var J=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var Fe=Object.prototype.hasOwnProperty;var He=(n,e)=>{for(var t in e)J(n,t,{get:e[t],enumerable:!0})},Be=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ne(e))!Fe.call(n,r)&&r!==t&&J(n,r,{get:()=>e[r],enumerable:!(i=_e(e,r))||i.enumerable});return n};var Ke=n=>Be(J({},"__esModule",{value:!0}),n);var mt={};He(mt,{AIAutocomplete:()=>Y,createStore:()=>V});module.exports=Ke(mt);function v(n,e){let t=n,i={},r=[];for(let s of e){let o=(i[s.type]??0)+1;i[s.type]=o;let l=`{{${s.type.toUpperCase().replace(/\s+/g,"_")}_${o}}}`,c=t.indexOf(s.text);c!==-1&&(t=t.slice(0,c)+l+t.slice(c+s.text.length)),r.push({...s,placeholder:l})}return{rawQuery:t,completedParams:r}}function A(n,e,t){return e>0||!t?e:n.toLowerCase().startsWith(t.toLowerCase())?t.length:e}function E(n,e,t){let i=n.slice(e);if(t||e===0||n[e-1]===" ")return i;let r=i.indexOf(" ");return r===-1?"":i.slice(r+1)}function oe(n,e){let t=n.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let i=t.split(" "),r=e.toLowerCase();for(let s=0;s<i.length;s++){let o=i.slice(s).join(" ");if(r.startsWith(o.toLowerCase())){let a=t.length-o.length;return n.length-a}}return 0}function w(n,e){if(!n)return[];let t=e.trimStart();if(!t)return n;let i=t.toLowerCase();return n.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(i))}function I(n,e){if(!n)return null;let t=e.trim();if(!t)return null;let i=t.toLowerCase();return n.find(r=>r.is_tappable&&r.text.toLowerCase()===i)??null}var M=class{constructor(e,t="auto"){this.container=e;this.mode=t;this.mediaQuery=null;this.onSystemChange=e=>{this.container.dataset.mode=e.matches?"dark":"light"};this.apply()}setMode(e){this.detachListener(),this.mode=e,this.apply()}destroy(){this.detachListener()}apply(){this.mode==="auto"?(this.mediaQuery??(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)")),this.mediaQuery.addEventListener("change",this.onSystemChange),this.container.dataset.mode=this.mediaQuery.matches?"dark":"light"):this.container.dataset.mode=this.mode}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function se(n,e){let t=[],i=0;for(let s of e){let o=n.indexOf(s.text,i);o!==-1&&(o>i&&t.push({type:"text",value:n.slice(i,o)}),t.push({type:"completed",value:s.text,param:s}),i=o+s.text.length)}let r=n.slice(i);return r&&t.push({type:"text",value:r}),t}function ae(n,e){let t=[],i=[],r=0;for(let s of e){let o=n.indexOf(s.text,r);o===-1?i.push(s):(t.push(s),r=o+s.text.length)}return{valid:t,invalid:i}}var L=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 Qe="https://api.ai-autocomplete.com",k=`${Qe}/api/suggest`,le=new WeakMap;function D(n){return n?.type==="accessToken"}function $e(n){if(!(!n||D(n)))return n}function R(n){let e=le.get(n.getAccessToken);return e||(e=new L(n),le.set(n.getAccessToken,e)),e}function _(n){return{"Content-Type":"application/json",...n?.appIdentifier&&{"X-App-Identifier":n.appIdentifier},...n?.headers}}function N(n){let e=$e(n),t=e?.apiKey;return t?(e?.authScheme??"Bearer")==="Basic"?`Basic ${btoa(t)}`:`Bearer ${t}`:null}function Ue(n){return(n??k).replace(/\/suggest(\?|#|$)/,"/telemetry/events$1")}async function qe(n){return D(n)?`Bearer ${await R(n).getToken()}`:N(n)}async function ce(n){try{let e=Ue(n.apiConfig?.endpoint),t=_(n.apiConfig),i=await qe(n.apiConfig);i&&(t.Authorization=i);let r=JSON.stringify({source:n.source,session_id:n.sessionId,type:n.type,at:new Date().toISOString(),query_data:n.queryData});await fetch(e,{method:"POST",headers:t,body:r})}catch{}}var We="0.1.42",de=!1;function je(){return crypto.randomUUID()}function Ge(n,e){return{placeholder:n.placeholder,type:n.type,...e&&{text:n.text},kind:n.kind}}function Ve(n,e,t,i){let r=e.find(o=>o.type==="contact"&&o.metadata?.contact_account_count)?.metadata?.contact_account_count,s=typeof r=="number"?r:void 0;return{data:{raw_query:n,completed_params:e.map(o=>Ge(o,t)),...s!=null&&{contact_account_count:s}},meta:{request_id:je(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:We,session_id:i}}}async function ue(n,e,t,i,r){return fetch(n,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:i,signal:r})}async function pe(n,e,t){let i=t.apiConfig,r=!t.maskCompletedText,s=Ve(n,e,r,t.sessionId),o=_(i),a=i?.endpoint??k,l=JSON.stringify(s);if(D(i)){let d=R(i),m=await d.getToken(),b=await ue(a,o,m,l,t.signal);if(b.status===401){let g=await d.getToken(!0);b=await ue(a,o,g,l,t.signal)}if(!b.ok)throw new Error(`API error: ${b.status} ${b.statusText}`);return b.json()}let c=N(i);!c&&!de&&(de=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),c&&(o.Authorization=c);let u=await fetch(a,{method:"POST",headers:o,body:l,signal:t.signal});if(!u.ok)throw new Error(`API error: ${u.status} ${u.statusText}`);return u.json()}function me(n,e){return e?n.map(t=>{let i=e[t.type];if(!i)return t;let r=i("");if(r.length===0)return t;let s=new Set(r.map(a=>a.text)),o=(t.options??[]).filter(a=>!s.has(a.text));return{...t,options:[...r,...o]}}):n}var ze=100,Xe=300,Ye=2,F=class{constructor(e,t,i,r,s,o,a={}){this.store=e;this.getApiConfig=t;this.getOptionOverrides=i;this.getMaskCompletedText=r;this.getOnError=s;this.getSessionId=o;this.callbacks=a;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,t=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(i=>{(i.text!==e||i.completedParams!==t)&&(e=i.text,t=i.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let i=new AbortController;this.abortController=i;let r=++this.fetchVersion,s=this.store.get().text.length;this.store.set({isLoading:!0,error:null});try{let o=await pe(e,t,{sessionId:this.getSessionId(),maskCompletedText:this.getMaskCompletedText(),signal:i.signal,apiConfig:this.getApiConfig()});if(r!==this.fetchVersion)return;let a=me(o.data.suggestions??[],this.getOptionOverrides()),l=o.data.input??[],c=l[l.length-1],u=this.store.get().text,d,m;if(c?.state==="in_progress"){m=!0;let f=u.toLowerCase().lastIndexOf(c.text.toLowerCase());d=f!==-1?f:s}else m=!1,d=s;let g=a.filter(f=>f.type!=="placeholder")[0],h=null;if(g){let f=E(u,d,m),p=I(g.options,f);p&&(h={id:crypto.randomUUID(),placeholder:"",type:g.type,text:p.text,kind:p.kind,suggestionType:g.type,suggestionPlaceholder:g.text,options:g.options??[],metadata:p.metadata},a=a.filter(x=>x!==g),this.callbacks.onAutoMatch?.({active:g,matched:p,rawQuery:e}))}this.store.set(f=>({suggestions:a,isLoading:!1,isReady:o.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:d,filterInProgress:m,...h?{completedParams:[...f.completedParams,h]}:{}}))}catch(o){if(r===this.fetchVersion){let a=o instanceof Error?o:new Error(String(o));this.store.set({error:a,isLoading:!1}),this.getOnError()?.(a)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=i=>{let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let s=r.suggestions.filter(x=>x.type==="placeholder").map(x=>x.text).join(" "),o=A(r.text,r.filterBase,s),a=E(r.text,o,r.filterInProgress),c=r.suggestions.filter(x=>x.type!=="placeholder")[0],d=(c?w(c.options,a):[]).filter(x=>x.is_tappable),m=c?I(c.options,a)!==null:!1,b=a.trim().length>0;if(d.length>0&&!m&&b||r.completedParams.length===0&&r.text.length>0&&s.length>0&&s.toLowerCase().startsWith(r.text.toLowerCase()))return!1;let{rawQuery:g,completedParams:h}=v(r.text,r.completedParams),f=g.length<r.lastRawQuery.length,p=Math.abs(g.length-r.lastRawQuery.length);return f||p>=i?(this.doFetch(g,h),!0):!1};this.debounceTimer=setTimeout(()=>{t(Ye)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},ze),this.slowDebounceTimer=setTimeout(()=>t(1),Xe)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var fe='[contenteditable="false"]',O;function Je(){if(O!==void 0)return O;let n=globalThis.Intl.Segmenter;if(!n)return O=null,null;try{O=new n(void 0,{granularity:"grapheme"})}catch{O=null}return O??null}function H(n,e){let t=n;for(;t&&t!==e;){if(t.nodeType===Node.ELEMENT_NODE&&t.matches(fe))return!0;t=t.parentNode}return!1}function B(n){return(n.ownerDocument??document).createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode(e){return H(e,n)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function Z(n){let e=B(n),t="",i=e.nextNode();for(;i;)t+=i.data,i=e.nextNode();return t}function he(n){let e=B(n),t=0,i=e.nextNode();for(;i;)t+=i.data.length,i=e.nextNode();return t}function C(n){let e=(n.ownerDocument??document).getSelection();if(!e||e.rangeCount===0)return null;let t=e.anchorNode,i=e.anchorOffset;if(!t||!n.contains(t))return null;if(t.nodeType===Node.ELEMENT_NODE){let r=t;if(H(r,n)&&r!==n)return null;let s=0;for(let o=0;o<i&&o<r.childNodes.length;o++)s+=xe(r.childNodes[o],n);return s+ge(r,n)}return t.nodeType!==Node.TEXT_NODE||H(t,n)?null:ge(t,n)+i}function xe(n,e){if(n.nodeType===Node.TEXT_NODE)return H(n,e)?0:n.data.length;if(n.nodeType!==Node.ELEMENT_NODE)return 0;let t=n;if(t.matches(fe))return 0;let i=0;for(let r of Array.from(t.childNodes))i+=xe(r,e);return i}function ge(n,e){let t=B(e),i=0,r=t.nextNode();for(;r;){if(r===n||n.nodeType===Node.ELEMENT_NODE&&n.contains(r))return i;i+=r.data.length,r=t.nextNode()}return i}function P(n,e){let t=n.ownerDocument??document,i=t.getSelection();if(!i)return;let r=Math.max(0,Math.min(e,he(n))),s=B(n),o=0,a=null,l=0,c=s.nextNode(),u=null;for(;c;){let m=c.data.length;if(r<o+m){a=c,l=r-o;break}if(r===o+m){let b=s.nextNode();b?(a=b,l=0):(a=c,l=m);break}o+=m,u=c,c=s.nextNode()}let d=t.createRange();if(a){let m=a.parentElement?.closest('strong[data-seg="completed"]');m&&m!==n&&n.contains(m)?l===0?d.setStartBefore(m):l===a.data.length?d.setStartAfter(m):d.setStart(a,l):d.setStart(a,l)}else u?d.setStart(u,u.data.length):d.setStart(n,0);d.collapse(!0),i.removeAllRanges(),i.addRange(d)}function be(n){let e=C(n);return e==null?!1:e>=he(n)}function ye(n,e){if(e<=0)return 0;let t=Je();if(!t)return e-1;let i=n.slice(0,e),r=0;for(let{index:s}of t.segment(i))s<e&&(r=s);return r}function Se(n){return n instanceof HTMLTextAreaElement||n instanceof HTMLInputElement?n.selectionStart!=null&&n.selectionStart===n.value.length:n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?be(n):!1}function Ze(n){return n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?C(n):null}var K=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{listboxId:i,getOnSubmit:r}=this.ctx,s=this.getEffectiveColumns(),o=r(),a=this.getTappableIndices(s);switch(e.key){case"ArrowDown":{let l=Se(e.target),c=!!t.editingParam;if(!l&&!c&&t.activeDropdownIndex<0)break;if(e.preventDefault(),!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:a[0]??0});break}if(a.length===0)return;let u=a.indexOf(t.activeDropdownIndex),d=u<a.length-1?u+1:0;this.store.set({activeDropdownIndex:a[d]});break}case"ArrowUp":{if(a.length===0||t.activeDropdownIndex<0)break;if(e.preventDefault(),t.activeDropdownIndex<s){this.store.set({activeDropdownIndex:-1});break}let l=a.indexOf(t.activeDropdownIndex),c=l>0?l-1:a.length-1;this.store.set({activeDropdownIndex:a[c]});break}case"ArrowRight":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%s<s-1){let u=t.activeDropdownIndex+1;u<t.filteredOptions.length&&t.filteredOptions[u]?.is_tappable&&this.store.set({activeDropdownIndex:u})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){e.preventDefault();let c=e.target.closest("[data-aia-input]")??e.target,u=t.editingTail;this.ctx.exitEditMode?.(),P(c,u);break}Se(e.target)&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}case"ArrowLeft":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%s>0){let l=t.activeDropdownIndex-1;l>=0&&t.filteredOptions[l]?.is_tappable&&this.store.set({activeDropdownIndex:l})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingAnchor!=null){e.preventDefault();let l=e.target.closest("[data-aia-input]")??e.target,c=t.editingAnchor;this.ctx.exitEditMode?.(),P(l,c);break}break}case"Backspace":{if(t.editingParam||!this.ctx.removeParamAtCaret)break;let l=Ze(e.target);if(l==null)break;this.ctx.removeParamAtCaret(l)&&e.preventDefault();break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,i);else if(o){let{rawQuery:l,completedParams:c}=v(t.text,t.completedParams);o({query:t.text.trim(),raw_query:l,completed_params:c}),this.ctx.afterSubmit?.()}break}case"Tab":{let l=!t.text&&!!t.placeholderText,c=t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable;if(l&&!c){e.preventDefault();let u=t.placeholderText;if(this.store.set(d=>({text:u,filterBase:u.length,suggestions:d.suggestions.filter(m=>m.type!=="placeholder")})),e.target instanceof HTMLElement){let d=e.target.closest("[data-aia-input]")??e.target;queueMicrotask(()=>P(d,u.length))}}else if(c)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,i);else if(t.isDropdownOpen){let u=t.filteredOptions.findIndex(d=>d.is_tappable);u>=0&&(e.preventDefault(),this.clickOrSelect(u,t.filteredOptions,i))}break}case"Escape":{if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){let l=e.target.closest("[data-aia-input]")??e.target,c=t.editingTail;this.ctx.exitEditMode?.(),P(l,c)}this.store.set({activeDropdownIndex:-1});break}}}getTappableIndices(e){let i=this.store.get().filteredOptions.map((s,o)=>s.is_tappable?o:-1).filter(s=>s!==-1),r=Array.from({length:e},()=>[]);for(let s of i)r[s%e].push(s);return r.flat()}getEffectiveColumns(){let t=document.getElementById(`${this.ctx.listboxId}-option-0`)?.parentElement;if(!t)return this.ctx.columns;let i=getComputedStyle(t).gridTemplateColumns.split(" ").filter(Boolean).length;return i>0?i:this.ctx.columns}clickOrSelect(e,t,i){let r=document.getElementById(`${i}-option-${e}`);r?r.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),i=t.suggestions.filter(a=>a.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],s=i.filter((a,l)=>l!==e),o=t.suggestions.filter(a=>a.type==="placeholder");this.store.set({suggestions:[...o,r,...s],pillTapped:!0,activeDropdownIndex:-1})}};var Q=class{constructor(e,t={}){this.store=e;this.callbacks=t}setActivePill(e){let t=this.store.get(),i=t.suggestions.filter(a=>a.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],s=i.filter((a,l)=>l!==e),o=t.suggestions.filter(a=>a.type==="placeholder");if(this.callbacks.onPillSelected){let{rawQuery:a}=v(t.text,t.completedParams);this.callbacks.onPillSelected({rawQuery:a,selectedPill:r.text,otherPills:s.map(l=>l.text)})}this.store.set({suggestions:[...o,r,...s],pillTapped:!0,activeDropdownIndex:-1})}removeLastParam(){this.store.get().completedParams.length!==0&&this.store.set(t=>({completedParams:t.completedParams.slice(0,-1),activeDropdownIndex:-1}))}};function ve(n,e){let t=e.dropdownTrigger??"auto",i=e.closeDropdownOnBlur??!0,r=n.filteredOptionsLength>0;if(n.inEditMode){let s=i?n.isFocused:!0;return r&&s}if(t==="auto"){let s=i?n.isFocused:!0,o=n.text.replace(/\s+$/,"").length,a=n.caretOffset==null||n.caretOffset>=o;return(r||n.isLoading)&&s&&a}return t==="manual"?(r||n.isLoading)&&n.pillTapped:!1}function Pe(n,e){let t=se(n.text,n.completedParams),i=n.suggestions.filter(g=>g.type!=="placeholder"),r=i[0],s=r?e.optionOverrides?.[r.type]:void 0,o=n.suggestions.filter(g=>g.type==="placeholder").map(g=>g.text).join(" "),a=A(n.text,Math.min(n.filterBase,n.text.length),o),c=n.lastRawQuery!==""||a>0?E(n.text,a,n.filterInProgress):"",u=r?s?s(c.trim()):r.options??[]:[],d=n.editingParam!=null&&n.editingAnchor!=null,m;if(d&&n.editingParam&&n.editingAnchor!=null){let g=n.editingParam.id,h=n.completedParams.some(x=>x.id===g),f=n.caretOffset??n.editingAnchor,p=h?"":n.text.slice(n.editingAnchor,f);m=w(n.editingParam.options,p)}else m=w(u,c);e.showNonTappableOptions===!1&&(m=m.filter(g=>g.is_tappable));let b=ve({inEditMode:d,filteredOptionsLength:m.length,isFocused:n.isFocused,text:n.text,caretOffset:n.caretOffset,isLoading:n.isLoading,pillTapped:n.pillTapped},{dropdownTrigger:e.dropdownTrigger,closeDropdownOnBlur:e.closeDropdownOnBlur});return{segments:t,actionableSuggestions:i,filteredOptions:m,placeholderText:o,isDropdownOpen:b}}function $(n){return n.mode==="fresh"?et(n):tt(n)}function et(n){let{text:e,completedParams:t,suggestions:i,filterBase:r,filterInProgress:s}=n,a=i.filter(S=>S.type!=="placeholder")[0];if(!a?.options)return null;let l=i.filter(S=>S.type==="placeholder").map(S=>S.text).join(" "),c=A(e,r,l),u=E(e,c,s),d=I(a.options,u);if(!d)return null;let m=d.text.toLowerCase(),b=e.toLowerCase().lastIndexOf(m),g=b>=0?b:Math.max(0,e.length-d.text.length),h=g+d.text.length,f=e.slice(g,h),x=h<e.length&&e[h]===" "?h+1:h,y={id:crypto.randomUUID(),placeholder:"",type:a.type,text:f,kind:d.kind,suggestionType:a.type,suggestionPlaceholder:a.text,options:a.options??[],metadata:d.metadata};return{patch:{text:e,completedParams:[...t,y],suggestions:i.filter(S=>S!==a),filterBase:x,newParamId:y.id,caretOffset:x,activeDropdownIndex:-1},caretPos:x}}function tt(n){let{text:e,completedParams:t,editingParam:i,editingAnchor:r,editingTail:s}=n;if(t.some(y=>y.id===i.id))return null;let o=e.slice(r,s),a=I(i.options,o);if(!a)return null;let l=a.text.toLowerCase(),c=o.toLowerCase().lastIndexOf(l),u=r+Math.max(0,c),d=u+a.text.length,m=e.slice(u,d),g=d<e.length&&e[d]===" "?d+1:d,h={id:crypto.randomUUID(),placeholder:"",type:i.suggestionType,text:m,kind:a.kind,suggestionType:i.suggestionType,suggestionPlaceholder:i.suggestionPlaceholder,options:i.options,metadata:a.metadata},f=t.length,p=0;for(let y=0;y<t.length;y++){let S=e.indexOf(t[y].text,p);if(S!==-1){if(S>=g){f=y;break}p=S+t[y].text.length}}let x=[...t];return x.splice(f,0,h),{patch:{text:e,completedParams:x,newParamId:h.id,filterBase:g,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:g,activeDropdownIndex:-1},caretPos:g}}var U=class{constructor(e){this.deps=e}start(e){let t=this.deps.store.get();if(t.editingParam?.id===e)return;let i=t.completedParams.find(o=>o.id===e);if(!i)return;let r=0,s=-1;for(let o of t.completedParams){let a=t.text.indexOf(o.text,r);if(a!==-1){if(o.id===e){s=a;break}r=a+o.text.length}}s<0||this.deps.store.set({editingParam:i,editingAnchor:s,editingTail:s+i.text.length,caretOffset:s+i.text.length,activeDropdownIndex:-1})}exit(){this.deps.store.get().editingParam&&this.deps.store.set({editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1})}replaceRange(e){let t=this.deps.store.get(),i=t.editingParam,r=t.editingAnchor,s=t.editingTail;if(!i||r==null||s==null||!t.completedParams.some(l=>l.id===i.id))return!1;let o=t.text.slice(0,r)+e+t.text.slice(s),a=r+e.length;return this.deps.store.set(l=>({text:o,completedParams:l.completedParams.filter(c=>c.id!==i.id),editingTail:a,caretOffset:a,activeDropdownIndex:-1})),this.deps.scheduleSetCursor(a),this.tryPromote(),!0}caretAfterInput(e){let t=this.deps.store.get(),i={caretOffset:e};t.editingParam&&t.editingAnchor!=null&&e!=null&&(e<t.editingAnchor?(i.editingParam=null,i.editingAnchor=null,i.editingTail=null,i.activeDropdownIndex=-1):t.editingTail!=null&&(i.editingTail=Math.max(t.editingTail,e))),this.deps.store.set(i),this.tryPromote()}caretMove(e){let t=this.deps.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null&&e!=null&&(e<t.editingAnchor||e>t.editingTail)){this.deps.store.set({caretOffset:e,editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1});return}this.deps.store.set({caretOffset:e})}selectOption(e){let t=this.deps.store.get(),i=t.editingParam,r=t.editingAnchor,s=t.editingTail;if(!i||r==null||s==null)return;this.deps.fireTelemetry("option",{raw_query:v(t.text,t.completedParams).rawQuery,selected_option:e.text,other_options:i.options.filter(p=>p.text!==e.text).map(p=>p.text)});let o=t.text.slice(0,r),a=t.text.slice(s),l=r===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,c=a.length===0||a[0]!==" ",u=c?`${l} `:l,d=o+u+a,m=r+u.length+(c?0:1),b={id:crypto.randomUUID(),placeholder:"",type:i.suggestionType,text:l,kind:e.kind,suggestionType:i.suggestionType,suggestionPlaceholder:i.suggestionPlaceholder,options:i.options,metadata:e.metadata},g=t.completedParams.findIndex(p=>p.id===i.id),h=t.completedParams.filter(p=>p.id!==i.id),f=g>=0?Math.min(g,h.length):h.length;h.splice(f,0,b),this.deps.store.set({text:d,completedParams:h,newParamId:b.id,filterBase:m,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:m,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0}),this.deps.startSelectionAnimationTimer(),this.deps.scheduleSetCursor(m)}tryPromote(){let e=this.deps.store.get();if(!e.editingParam||e.editingAnchor==null||e.editingTail==null)return;let t=$({mode:"edit",text:e.text,completedParams:e.completedParams,editingParam:e.editingParam,editingAnchor:e.editingAnchor,editingTail:e.editingTail});t&&(this.deps.store.set(t.patch),this.deps.scheduleSetCursor(t.caretPos))}};var Te="data-aia-key";function q(n,e,t){let i=new Map;for(let o of Array.from(n.children)){let a=o.getAttribute(Te);a!=null&&i.set(a,o)}let r=new Set,s=[];for(let o=0;o<e.length;o++){let a=e[o],l=t.keyOf(a,o);r.add(l);let c=i.get(l);c||(c=t.create(a,o),c.setAttribute(Te,l)),t.update?.(c,a,o),n.children[o]!==c&&n.insertBefore(c,n.children[o]??null),s.push(c)}for(let[o,a]of i)r.has(o)||a.remove();return s}var Ce=[125,69];function Ee(n){return n===0?.4:n===1?.3:.15}function W(n,e,t,i,r=!1,s=!1){let o=n.querySelector(".magicx-aia-pill-list");if(o||(o=document.createElement("span"),o.className="magicx-aia-pill-list",n.appendChild(o)),s&&e.length===0){o.setAttribute("data-aia-pill-list-loading",""),o.innerHTML="";for(let a=0;a<Ce.length;a++){let l=Ce[a],c=document.createElement("span");c.setAttribute("data-aia-pill-skeleton",""),c.className=`magicx-aia-pill magicx-aia-pill--skeleton${r?" magicx-aia-pill--rounded":""}`,c.style.width=`${l}px`,c.style.opacity=String(Ee(a)),o.appendChild(c)}return}s?o.setAttribute("data-aia-pill-list-loading",""):o.removeAttribute("data-aia-pill-list-loading");for(let a of o.querySelectorAll("[data-aia-pill-skeleton]"))a.remove();q(o,e,{keyOf:a=>`${a.type}-${a.text}`,create:a=>{let l=document.createElement("button");return l.type="button",l.tabIndex=-1,l.setAttribute("data-aia-pill",""),l.setAttribute("contenteditable","false"),l.textContent=a.text,l.addEventListener("mousedown",c=>c.preventDefault()),l},update:(a,l,c)=>{let u=a,d=["magicx-aia-pill"];r&&d.push("magicx-aia-pill--rounded"),c===t&&!s&&d.push("magicx-aia-pill--active"),s&&d.push("magicx-aia-pill--skeleton"),u.className=d.join(" "),u.style.width="",u.style.opacity=String(Ee(c)),s?(u.setAttribute("data-aia-loading",""),u.disabled=!0,u.onclick=null):(u.removeAttribute("data-aia-loading"),u.disabled=!1,u.onclick=()=>i(c))}})}function ee(n){n.querySelector(".magicx-aia-pill-list")?.remove()}var nt=[159,119,164];function j(n){let e=document.createElement("div");return e.id=n,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function G(n,e){let{filteredOptions:t,activeIndex:i,isOpen:r,isLoading:s,pills:o,showPills:a,onSelect:l,onHighlight:c,onPillClick:u}=e,d=a&&o.length>0,m=t.length>0;r&&(m||d||s)?n.classList.add("magicx-aia-dropdown--visible"):n.classList.remove("magicx-aia-dropdown--visible"),s?n.setAttribute("data-aia-loading",""):n.removeAttribute("data-aia-loading");let g=d||s&&a,h=n.querySelector(".magicx-aia-pill-bar");g?(h||(h=document.createElement("div"),h.className="magicx-aia-pill-bar",h.setAttribute("data-aia-pillbar",""),n.insertBefore(h,n.firstChild)),W(h,o,0,u,!0,s)):h&&h.remove();let f=n.querySelector(".magicx-aia-grid");m?(f||(f=document.createElement("div"),f.className="magicx-aia-grid",n.appendChild(f)),it(f,t,i,l,c,e.listboxId,s)):f&&f.remove();let p=n.querySelector(".magicx-aia-skeleton-bars");if(s&&!m){if(!p){p=document.createElement("div"),p.className="magicx-aia-skeleton-bars",p.setAttribute("data-aia-skeleton-bars","");for(let x of nt){let y=document.createElement("span");y.className="magicx-aia-skeleton-bar",y.style.width=`${x}px`,p.appendChild(y)}n.appendChild(p)}}else p&&p.remove()}function it(n,e,t,i,r,s,o){let a=o?"1":"0";q(n,e,{keyOf:l=>`${l.text}\0${a}`,create:l=>rt(l,o),update:(l,c,u)=>{let d=u===t&&!o;l.id=`${s}-option-${u}`,l.dataset.aiaIndex=String(u),l.setAttribute("aria-selected",String(d)),l.classList.toggle("magicx-aia-option--highlighted",d),!o&&c.is_tappable?(l.onclick=()=>{l.classList.add("magicx-aia-option--pressed"),i(c),setTimeout(()=>l.classList.remove("magicx-aia-option--pressed"),500)},l.onmouseenter=()=>{let m=Number.parseInt(l.dataset.aiaIndex??"-1",10);m>=0&&r(m)}):(l.onclick=null,l.onmouseenter=null)}})}function rt(n,e){let t=document.createElement("div");t.setAttribute("role","option"),t.setAttribute("data-aia-option",""),e&&t.setAttribute("data-aia-loading",""),t.tabIndex=e||!n.is_tappable?-1:0;let i=["magicx-aia-option"];n.is_tappable?i.push("magicx-aia-option--tappable"):i.push("magicx-aia-option--non-tappable"),t.className=i.join(" ");let r=document.createElement("div");r.className="magicx-aia-streaks",t.appendChild(r);let s=document.createElement("div");s.className="magicx-aia-streaks-vert",t.appendChild(s);let o=document.createElement("span");if(o.className="magicx-aia-option-content",o.textContent=n.icon?`${n.icon} ${n.text}`:n.text,n.tag){let a=document.createElement("span");a.className="magicx-aia-option-tag",a.textContent=n.tag,o.appendChild(a)}return t.appendChild(o),t}function we(n,e){let t=j(e.listboxId);return n.appendChild(t),{dropdown:t}}function te(n,e,t){G(n.dropdown,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:!0,onSelect:t.selectOption,onHighlight:i=>t.store.set({activeDropdownIndex:i}),onPillClick:t.setActivePill})}function Ae(n){let{input:e,segments:t,newParamId:i,editingParamId:r,placeholderText:s,isFocused:o}=n,a=t.length===0;e.dataset.aiaEmpty=a?"true":"false",a&&s?e.dataset.placeholder=s:delete e.dataset.placeholder;let l=t.map(f=>`${f.type}:${f.value}`).join("\0"),c=e.dataset.segKey??"",u=e.dataset.newParamId??"",d=e.dataset.editingParamId??"";if(l===c&&(i??"")===u&&(r??"")===d)return;let m=o?C(e):null;e.dataset.segKey=l,e.dataset.newParamId=i??"",e.dataset.editingParamId=r??"";let b=e.ownerDocument??document,g=b.createDocumentFragment(),h=0;for(let f of t)if(h+=f.value.length,f.type==="completed"){let p=b.createElement("strong");p.dataset.seg="completed",p.dataset.paramId=f.param.id;let x=f.param.id===i,y=f.param.id===r,S=["magicx-aia-segment","magicx-aia-segment--completed"];x&&S.push("magicx-aia-shimmer-revealed","magicx-aia-shimmer-sweep"),y&&S.push("magicx-aia-segment--editing"),p.className=S.join(" "),p.textContent=f.value,g.appendChild(p)}else g.appendChild(b.createTextNode(f.value));e.replaceChildren(g),e.dataset.aiaTextLength=String(h),m!=null&&P(e,Math.max(0,Math.min(m,h)))}var ot='<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 st(){let n=document.createElement("div");return n.setAttribute("contenteditable","plaintext-only"),n.contentEditable==="plaintext-only"}function Ie(n,e){let{listboxId:t}=e,i=j(t);n.appendChild(i);let r=document.createElement("div");r.className="magicx-aia-input-wrapper",n.appendChild(r);let s=document.createElement("div");s.className="magicx-aia-editor",s.setAttribute("data-aia-editor",""),r.appendChild(s);let o=document.createElement("div");o.className="magicx-aia-input",o.setAttribute("data-aia-input",""),o.setAttribute("contenteditable",st()?"plaintext-only":"true"),o.setAttribute("role","combobox"),o.setAttribute("aria-autocomplete","list"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-controls",t),o.setAttribute("aria-expanded","false"),o.setAttribute("spellcheck","true"),o.setAttribute("enterkeyhint","send"),s.appendChild(o);let a=document.createElement("span");a.className="magicx-aia-pill-list-container",a.setAttribute("data-aia-pill-list-container",""),s.appendChild(a);let l=null,c=null;e.submitButton===void 0?(l=document.createElement("button"),l.type="button",l.className="magicx-aia-submit",l.setAttribute("aria-label","Submit"),l.setAttribute("data-aia-submit",""),l.innerHTML=ot,r.appendChild(l),c=l):e.submitButton!==null&&(c=e.submitButton,c.hasAttribute("data-aia-submit")||c.setAttribute("data-aia-submit",""),r.appendChild(c));let u=new AbortController,{signal:d}=u,m=!1,b=0,g=()=>{let p=Z(o),y=p.length>0&&p[0]!==p[0].toUpperCase()?p[0].toUpperCase()+p.slice(1):p;e.handleChange(y)},h=()=>{let p=(o.ownerDocument??document).getSelection();if(!p||p.rangeCount===0)return null;let x=p.anchorNode;return!x||!o.contains(x)?null:(x.nodeType===Node.ELEMENT_NODE?x:x.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null};r.addEventListener("click",p=>{p.target?.closest("[data-aia-pill]")||o.focus()},{signal:d}),o.addEventListener("input",()=>{m||(b=performance.now(),g(),e.handleCaretAfterInput(C(o)))},{signal:d});let f=o.ownerDocument??document;return f.addEventListener("selectionchange",()=>{let p=f.getSelection();if(!p||p.rangeCount===0||!o.contains(p.anchorNode))return;let x=h(),y=e.store.get().editingParam?.id??null;if(x&&x!==y){e.startEditingParam(x);return}performance.now()-b<50||e.handleCaretMove(C(o))},{signal:d}),o.addEventListener("compositionstart",()=>{m=!0},{signal:d}),o.addEventListener("compositionend",()=>{m=!1,g()},{signal:d}),o.addEventListener("beforeinput",p=>{let x=p,y=x.inputType;if(y==="insertParagraph"||y==="insertLineBreak"||y==="insertFromDrop"){p.preventDefault();return}if(y.startsWith("insert")||y.startsWith("delete")){let S=y.startsWith("delete")?"":x.data??"";e.replaceEditingRange(S)&&p.preventDefault()}},{signal:d}),o.addEventListener("paste",p=>{p.preventDefault();let x=(p.clipboardData?.getData("text/plain")??"").replace(/\r?\n/g," ");if(!x)return;let y=o.ownerDocument??document,S=y.getSelection();if(!S||S.rangeCount===0)return;let T=S.getRangeAt(0);if(!o.contains(T.startContainer))return;T.deleteContents();let re=y.createTextNode(x);T.insertNode(re),T.setStartAfter(re),T.collapse(!0),S.removeAllRanges(),S.addRange(T),g()},{signal:d}),o.addEventListener("keydown",p=>e.handleKeyDown(p),{signal:d}),o.addEventListener("focus",()=>e.store.set({isFocused:!0}),{signal:d}),o.addEventListener("blur",()=>e.store.set({isFocused:!1}),{signal:d}),c&&c.addEventListener("click",p=>{let x=e.store.get();if(!(!!x.text||x.completedParams.length>0)||!e.onSubmit)return;p.stopPropagation();let{rawQuery:S,completedParams:T}=v(x.text,x.completedParams);e.onSubmit({query:x.text.trim(),raw_query:S,completed_params:T}),e.afterSubmit?.()},{signal:d}),e.autoFocus!==!1&&o.focus(),{input:o,inlinePillContainer:a,dropdown:i,submitButton:l,abort:u}}function ne(n,e,t){let{input:i,inlinePillContainer:r,dropdown:s,submitButton:o}=n,{pillPlacement:a,setActivePill:l,selectOption:c,store:u}=t;i.setAttribute("aria-expanded",String(e.isDropdownOpen));let d=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";if(d?i.setAttribute("aria-activedescendant",d):i.removeAttribute("aria-activedescendant"),o){let f=!!e.text||e.completedParams.length>0;o.disabled=!f}let m=i.dataset.newParamId??"",b=e.newParamId!==null&&e.newParamId!==m;if(Ae({input:i,segments:e.segments,newParamId:e.newParamId,editingParamId:e.editingParam?.id??null,placeholderText:e.placeholderText,isFocused:e.isFocused}),a==="inline"){let f=e.isLoading&&!e.editingParam&&!e.inSelectionAnimation;f||e.actionableSuggestions.length>0?W(r,e.actionableSuggestions,0,l,!1,f):ee(r)}else ee(r);b?(i.focus(),P(i,e.caretOffset??e.text.length)):e.isFocused&&Z(i)!==e.text&&P(i,e.text.length);let g=e.editingParam?{type:e.editingParam.suggestionType,text:e.editingParam.suggestionPlaceholder,required:!0,options:e.editingParam.options}:null,h=g??e.actionableSuggestions[0];G(s,{suggestions:h?[{...h,options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:g?[g]:e.actionableSuggestions,showPills:a==="dropdown",onSelect:c,onHighlight:f=>u.set({activeDropdownIndex:f}),onPillClick:l})}function Oe(n,e){let t=n.actionableSuggestions[0];if(!t)return null;let i=n.filterBase,r=n.text.slice(0,i),s=r.length===0&&n.text.length===0,o=r.length===0&&n.text.length>0&&n.placeholderText.length>0&&n.placeholderText.toLowerCase().startsWith(n.text.toLowerCase());(s||o)&&n.placeholderText&&(r=`${n.placeholderText} `);let a=oe(r,e.text);a>0&&(r=r.slice(0,r.length-a));let l=r.length>0&&r[r.length-1]!==" ",c=`${r}${l?" ":""}${e.text} `,u=(s||o)&&c.length>0?c[0].toUpperCase()+c.slice(1):c,d=u.toLowerCase().lastIndexOf(e.text.toLowerCase()),m=d>=0?u.slice(d,d+e.text.length):e.text,b={id:crypto.randomUUID(),placeholder:"",type:t.type,text:m,kind:e.kind,suggestionType:t.type,suggestionPlaceholder:t.text,options:t.options??[],metadata:e.metadata},g=n.actionableSuggestions.length-1;return{patch:{text:u,filterBase:u.length,completedParams:[...n.completedParams,b],newParamId:b.id,caretOffset:u.length,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:g>0,inSelectionAnimation:!0},telemetry:{selectedOption:e.text,otherOptions:n.filteredOptions.filter(h=>h.text!==e.text).map(h=>h.text)},consumedSuggestion:t,remainingActionable:g}}function V(n){let e=n,t=new Set;return{get:()=>e,set:i=>{let r=typeof i=="function"?i(e):i,s={...e,...r},o=e;e=s;for(let a of t)a(s,o)},subscribe:i=>(t.add(i),()=>{t.delete(i)})}}function De(n,e){let t,i,r=s=>(s!==t&&(t=s,i=e(s)),i);return{get:()=>{let s=n.get();return{...s,...r(s)}},set:s=>{typeof s=="function"?n.set(o=>{let a={...o,...r(o)};return s(a)}):n.set(s)},subscribe:s=>n.subscribe((o,a)=>{let l={...a,...r(a)},c={...o,...r(o)};s(c,l)})}}var ie=!1;function Me(){if(ie||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){ie=!0;return}ie=!0;let n=document.createElement("style");n.setAttribute("data-magicx-aia",""),n.textContent=at,document.head.appendChild(n)}var at=`@layer layout {
2
- .aia-stack {
3
- display: flex;
4
- flex-direction: column;
5
- gap: var(--aia-stack-space, 0.5rem);
6
- }
7
- .aia-stack[data-align="start"] {
8
- align-items: start;
9
- }
10
- .aia-stack[data-align="center"] {
11
- align-items: center;
12
- }
13
- .aia-stack[data-align="end"] {
14
- align-items: end;
15
- }
16
- /* data-align="stretch" is the flex default \u2014 no rule needed. */
17
- }
18
-
19
- @layer layout {
20
- .aia-cluster {
21
- display: flex;
22
- flex-wrap: wrap;
23
- gap: var(--aia-cluster-gap, 0.5rem);
24
- }
25
- .aia-cluster[data-nowrap] {
26
- flex-wrap: nowrap;
27
- }
28
- .aia-cluster[data-align="start"] {
29
- align-items: start;
30
- }
31
- .aia-cluster[data-align="center"] {
32
- align-items: center;
33
- }
34
- .aia-cluster[data-align="end"] {
35
- align-items: end;
36
- }
37
- .aia-cluster[data-align="baseline"] {
38
- align-items: baseline;
39
- }
40
- .aia-cluster[data-justify="start"] {
41
- justify-content: start;
42
- }
43
- .aia-cluster[data-justify="center"] {
44
- justify-content: center;
45
- }
46
- .aia-cluster[data-justify="end"] {
47
- justify-content: end;
48
- }
49
- .aia-cluster[data-justify="between"] {
50
- justify-content: space-between;
51
- }
52
- .aia-cluster[data-justify="around"] {
53
- justify-content: space-around;
54
- }
55
- }
56
-
57
- @layer layout {
58
- .aia-grid {
59
- display: grid;
60
- grid-template-columns: repeat(auto-fit, minmax(min(var(--aia-grid-min), 100%), 1fr));
61
- gap: var(--aia-grid-gap, 0);
62
- }
63
- }
64
-
65
- /* ===================================================================
66
- Vanilla core styles \u2014 stable BEM class names (magicx-aia-*)
67
- Auto-injected at runtime on first instantiation.
68
- =================================================================== */
69
-
70
- /* --- Container --- */
71
- .magicx-aia {
72
- position: relative;
73
- /* Inherits the host page's font by default. Consumers can pin a specific
74
- font on the library via \`--aia-font-family: 'Custom Font'\` without
75
- affecting the surrounding page. */
76
- font-family: var(--aia-font-family, inherit);
77
- container-type: inline-size;
78
- }
79
-
80
- /* --- Input wrapper --- */
81
- .magicx-aia-input-wrapper {
82
- padding: 20px;
83
- border: 1px solid var(--aia-color-border-default, #9ea5b2);
84
- border-radius: 23px;
85
- background: transparent;
86
- overflow: hidden;
87
- display: flex;
88
- align-items: center;
89
- gap: 0px;
90
- }
91
-
92
- /* --- Editor area (wraps the editable input + inline pill list sibling) --- */
93
- .magicx-aia-editor {
94
- position: relative;
95
- flex: 1;
96
- min-width: 0;
97
- min-height: 38px;
98
- line-height: 38px;
99
- font-family: inherit;
100
- font-size: var(--aia-written-text-font-size, 19px);
101
- white-space: pre-wrap;
102
- word-break: break-word;
103
- overflow-wrap: anywhere;
104
- }
105
-
106
- /* --- Editable input (contentEditable; inline so pills flow alongside) --- */
107
- .magicx-aia-input {
108
- display: inline;
109
- outline: none;
110
- background: transparent;
111
- color: var(--aia-written-text-color, var(--aia-color-text-default, #fff));
112
- caret-color: var(
113
- --aia-caret-color,
114
- var(--aia-written-text-color, var(--aia-color-text-default, #fff))
115
- );
116
- font-weight: 200;
117
- }
118
-
119
- /* Empty inline contentEditables don't have an inline box, so the browser has
120
- nowhere to render the caret. Switching to inline-block gives it presence;
121
- the min-width is just wide enough for the caret line. */
122
- .magicx-aia-input[data-aia-empty="true"] {
123
- display: inline-block;
124
- min-width: 1px;
125
- vertical-align: top;
126
- }
127
-
128
- /* Completed params render as inline bold runs. Specificity stays at (0,2,0)
129
- so consumers can override with \`.magicx-aia-input strong\`. */
130
- :where(.magicx-aia-input) strong {
131
- font-weight: 500;
132
- letter-spacing: -0.01em;
133
- }
134
-
135
- /* Re-edit highlight \u2014 applied to the bold param being re-edited. The DOM
136
- keeps a Selection range over the strong so the browser still handles
137
- typing / backspace as a range replacement; we hide the native selection
138
- paint and the caret so the only visual cue is this outline. */
139
- :where(.magicx-aia-input) strong.magicx-aia-segment--editing {
140
- outline: 1.5px solid var(--aia-edit-outline, currentColor);
141
- outline-offset: 1px;
142
- border-radius: 4px;
143
- caret-color: transparent;
144
- }
145
-
146
- :where(.magicx-aia-input) strong.magicx-aia-segment--editing::selection {
147
- background: transparent;
148
- color: inherit;
149
- }
150
- :where(.magicx-aia-input) strong.magicx-aia-segment--editing::-moz-selection {
151
- background: transparent;
152
- color: inherit;
153
- }
154
-
155
- /* Placeholder via ::before so it doesn't enter the editable DOM. */
156
- .magicx-aia-input[data-aia-empty="true"][data-placeholder]::before {
157
- content: attr(data-placeholder);
158
- color: var(--aia-color-text-muted, #c1c4cb);
159
- opacity: 0.7;
160
- pointer-events: none;
161
- }
162
-
163
- /* Inline pill list container \u2014 a non-editable sibling of the editable that
164
- flows immediately after it on the same line. The leading margin gives the
165
- pills a visible gap from the typed text. */
166
- .magicx-aia-pill-list-container {
167
- display: inline;
168
- margin-left: 8px;
169
- }
170
-
171
- /* Hide the leading margin when there are no pills so an empty container
172
- doesn't bias the cursor's resting position to the right. */
173
- .magicx-aia-pill-list-container:empty {
174
- margin-left: 0;
175
- }
176
-
177
- /* --- Submit button --- */
178
- .magicx-aia-submit {
179
- flex-shrink: 0;
180
- width: 36px;
181
- height: 36px;
182
- border-radius: 50%;
183
- border: none;
184
- background: var(--aia-submit-bg, var(--aia-color-text-default, #fff));
185
- color: var(--aia-submit-color, var(--aia-color-bg-default, #000));
186
- cursor: pointer;
187
- display: flex;
188
- align-items: center;
189
- justify-content: center;
190
- padding: 0;
191
- transition: opacity 0.2s ease;
192
- }
193
-
194
- .magicx-aia-submit:hover {
195
- opacity: 0.85;
196
- }
197
-
198
- /* --- Dropdown (glassmorphism \u2014 matches the React build) --- */
199
- .magicx-aia-dropdown {
200
- position: absolute;
201
- left: 0;
202
- right: 0;
203
- top: 100%;
204
- max-width: 516px;
205
- margin-top: 6px;
206
- display: flex;
207
- flex-direction: column;
208
- overflow: hidden;
209
- container-type: inline-size;
210
- z-index: 10;
211
- opacity: 0;
212
- pointer-events: none;
213
- transition: opacity 400ms cubic-bezier(0.4, 0, 0.2, 1);
214
- box-shadow:
215
- hsla(0, 0%, 100%, 1) -3.2px -3.2px 3.2px -3.2px inset,
216
- hsla(0, 0%, 100%, 1) 6.4px 6.4px 1.6px -8px inset,
217
- var(--aia-dropdown-bg, transparent) -6.4px 6.4px 1.6px -8px inset,
218
- var(--aia-dropdown-bg, transparent) 6.4px -6.4px 1.6px -8px inset,
219
- hsla(0, 0%, 100%, 0.15) -1.6px 0px 0px -1.6px inset,
220
- hsla(0, 0%, 100%, 0.15) 0px -1.6px 0px -1.6px inset,
221
- hsla(0, 0%, 100%, 0.3) 0px 1.6px 0px 0px inset,
222
- hsla(0, 0%, 100%, 0.3) 1.6px 0px 0px 0px inset,
223
- inset 0 0 30px 5px hsla(0, 0%, 0%, 0.05),
224
- hsla(0, 0%, 0%, 0.08) 0px 0px 30px 2px;
225
- backdrop-filter: blur(30px);
226
- border-radius: 28px;
227
- }
228
-
229
- .magicx-aia-dropdown--visible {
230
- opacity: 1;
231
- pointer-events: auto;
232
- }
233
-
234
- /* --- Pill bar (inside dropdown) --- */
235
- .magicx-aia-pill-bar {
236
- padding: 27px 27px 0px 27px;
237
- }
238
-
239
- /* --- Fallback loading skeleton bars (only when no cached options) --- */
240
- .magicx-aia-skeleton-bars {
241
- display: flex;
242
- flex-direction: column;
243
- gap: 20px;
244
- padding: 25px;
245
- }
246
-
247
- .magicx-aia-skeleton-bar {
248
- display: block;
249
- height: 19px;
250
- border-radius: 999px;
251
- background: var(--aia-skeleton-bg, var(--aia-pill-bg, rgba(189, 189, 189, 0.51)));
252
- opacity: 0.5;
253
- animation: magicx-aia-skeleton-pulse 1.4s ease-in-out infinite;
254
- }
255
-
256
- .magicx-aia-skeleton-bar:nth-child(2) {
257
- animation-delay: 150ms;
258
- }
259
-
260
- .magicx-aia-skeleton-bar:nth-child(3) {
261
- animation-delay: 300ms;
262
- }
263
-
264
- @keyframes magicx-aia-skeleton-pulse {
265
- 0%,
266
- 100% {
267
- opacity: 0.5;
268
- }
269
- 50% {
270
- opacity: 0.25;
271
- }
272
- }
273
-
274
- /* --- Loading mask on real options (preserves layout, hides text) --- */
275
- .magicx-aia-option[data-aia-loading] {
276
- cursor: default;
277
- animation: magicx-aia-option-skeleton-pulse 1.4s ease-in-out infinite;
278
- }
279
-
280
- .magicx-aia-option[data-aia-loading] .magicx-aia-option-content {
281
- color: transparent;
282
- background: var(--aia-skeleton-bg, var(--aia-pill-bg, rgba(189, 189, 189, 0.51)));
283
- border-radius: 999px;
284
- }
285
-
286
- .magicx-aia-option[data-aia-loading] .magicx-aia-option-tag {
287
- display: none;
288
- }
289
-
290
- @keyframes magicx-aia-option-skeleton-pulse {
291
- 0%,
292
- 100% {
293
- filter: brightness(1);
294
- }
295
- 50% {
296
- filter: brightness(0.55);
297
- }
298
- }
299
-
300
- /* --- Pill list --- */
301
- .magicx-aia-pill-list {
302
- position: relative;
303
- z-index: 1;
304
- pointer-events: auto;
305
- display: inline-flex;
306
- gap: 5px;
307
- align-items: center;
308
- vertical-align: middle;
309
- transform: translateY(-3px);
310
- }
311
-
312
- /* --- Individual pill --- */
313
- .magicx-aia-pill {
314
- display: inline-flex;
315
- align-items: center;
316
- justify-content: center;
317
- height: 36px;
318
- padding: 13px 13px;
319
- border: none;
320
- border-radius: 999px;
321
- background: rgba(49, 50, 85, 0.25);
322
- background: color-mix(
323
- in srgb,
324
- var(--aia-pill-bg, var(--aia-color-background-supportive, #313255)) 25%,
325
- transparent
326
- );
327
- color: var(--aia-pill-color, var(--aia-color-text-muted, #c1c4cb));
328
- font-family: inherit;
329
- font-size: var(--aia-pill-font-size, 19px);
330
- line-height: 30px;
331
- cursor: pointer;
332
- white-space: nowrap;
333
- animation: magicx-aia-fadeIn 400ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
334
- box-shadow:
335
- hsla(0, 0%, 100%, 1) -3.2px -3.2px 3.2px -3.2px inset,
336
- hsla(0, 0%, 100%, 1) 6.4px 6.4px 1.6px -8px inset,
337
- var(--aia-dropdown-bg, transparent) -6.4px 6.4px 1.6px -8px inset,
338
- var(--aia-dropdown-bg, transparent) 6.4px -6.4px 1.6px -8px inset,
339
- hsla(0, 0%, 100%, 0.15) -1.6px 0px 0px -1.6px inset,
340
- hsla(0, 0%, 100%, 0.15) 0px -1.6px 0px -1.6px inset,
341
- hsla(0, 0%, 100%, 0.3) 0px 1.6px 0px 0px inset,
342
- hsla(0, 0%, 100%, 0.3) 1.6px 0px 0px 0px inset,
343
- inset 0 0 30px 5px hsla(0, 0%, 0%, 0.05),
344
- hsla(0, 0%, 0%, 0.08) 0px 0px 30px 2px;
345
- backdrop-filter: blur(30px);
346
- }
347
-
348
- .magicx-aia-pill--rounded {
349
- border-radius: 999px;
350
- }
351
-
352
- .magicx-aia-pill:hover {
353
- filter: brightness(1.2);
354
- }
355
-
356
- .magicx-aia-pill--active {
357
- outline: 1px solid #5a5b8a;
358
- }
359
-
360
- /* Real pill rendered as a skeleton (mirrored from cached pills during loading).
361
- Preserves the pill's full box so width/height match the previous state. */
362
- .magicx-aia-pill[data-aia-loading] {
363
- pointer-events: none;
364
- cursor: default;
365
- color: transparent;
366
- animation: magicx-aia-pill-skeleton-pulse 1.4s ease-in-out infinite;
367
- }
368
-
369
- /* Fallback placeholder pills (used when there are no cached pills yet). */
370
- .magicx-aia-pill--skeleton {
371
- pointer-events: none;
372
- cursor: default;
373
- color: transparent;
374
- background: var(--aia-skeleton-bg, var(--aia-pill-bg, rgba(189, 189, 189, 0.51)));
375
- box-shadow: none;
376
- backdrop-filter: none;
377
- animation: magicx-aia-pill-skeleton-pulse 1.4s ease-in-out infinite;
378
- }
379
-
380
- .magicx-aia-pill--skeleton:hover,
381
- .magicx-aia-pill[data-aia-loading]:hover {
382
- filter: none;
383
- }
384
-
385
- @keyframes magicx-aia-pill-skeleton-pulse {
386
- 0%,
387
- 100% {
388
- filter: brightness(1);
389
- }
390
- 50% {
391
- filter: brightness(0.55);
392
- }
393
- }
394
-
395
- @keyframes magicx-aia-fadeIn {
396
- from {
397
- opacity: 0;
398
- }
399
- }
400
-
401
- /* --- Options grid --- */
402
- .magicx-aia-grid {
403
- display: grid;
404
- grid-template-columns: minmax(0, 250px);
405
- /* Pack rows from the top instead of stretching to fill the grid container. */
406
- grid-auto-rows: min-content;
407
- align-content: start;
408
- justify-content: start;
409
- padding: 8px 8px;
410
- max-height: 192px;
411
- overflow-y: auto;
412
- scrollbar-width: thin;
413
- scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
414
- }
415
-
416
- @container (min-width: 516px) {
417
- .magicx-aia-grid {
418
- grid-template-columns: repeat(2, minmax(0, 250px));
419
- }
420
- }
421
-
422
- .magicx-aia-grid::-webkit-scrollbar {
423
- width: 6px;
424
- }
425
-
426
- .magicx-aia-grid::-webkit-scrollbar-track {
427
- background: transparent;
428
- }
429
-
430
- .magicx-aia-grid::-webkit-scrollbar-thumb {
431
- background: rgba(255, 255, 255, 0.3);
432
- border-radius: 3px;
433
- }
434
-
435
- /* --- Option item --- */
436
- .magicx-aia-option {
437
- position: relative;
438
- overflow: visible;
439
- display: flex;
440
- /* Top-align so single-line and multi-line options in the same row share
441
- the same baseline at the top edge of the cell. */
442
- align-items: flex-start;
443
- font-family: inherit;
444
- font-size: var(--aia-option-font-size, 19px);
445
- line-height: 24px;
446
- color: var(--aia-option-color, var(--aia-color-text-muted, #c1c4cb));
447
- white-space: normal;
448
- word-break: break-word;
449
- opacity: 0.4;
450
- border-radius: 12px;
451
- padding: 13px 13px;
452
- animation: magicx-aia-optionFadeIn 500ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
453
- }
454
-
455
- @keyframes magicx-aia-optionFadeIn {
456
- from {
457
- opacity: 0;
458
- }
459
- }
460
-
461
- .magicx-aia-option-content {
462
- position: relative;
463
- z-index: 2;
464
- }
465
-
466
- .magicx-aia-option--tappable {
467
- cursor: pointer;
468
- }
469
-
470
- .magicx-aia-option--tappable:hover {
471
- color: var(--aia-option-color-selected, var(--aia-color-text-default, #fff));
472
- }
473
-
474
- .magicx-aia-option--non-tappable {
475
- cursor: default;
476
- opacity: 0.3;
477
- }
478
-
479
- .magicx-aia-option--highlighted {
480
- color: var(--aia-option-color-selected, var(--aia-color-text-default, #fff));
481
- background: var(--aia-option-bg, transparent);
482
- opacity: 0.5;
483
- }
484
-
485
- .magicx-aia-option-tag {
486
- font-size: 11px;
487
- margin-left: 6px;
488
- opacity: 0.5;
489
- }
490
-
491
- .magicx-aia-option--pressed {
492
- opacity: 0.8;
493
- color: var(--aia-option-color-selected, var(--aia-color-text-default, #fff));
494
- background: rgba(var(--aia-streak-rgb, 255, 255, 255), 0.06);
495
- animation:
496
- magicx-aia-glassFade 500ms ease forwards,
497
- magicx-aia-tapDown 500ms ease forwards;
498
- }
499
-
500
- @keyframes magicx-aia-tapDown {
501
- 0% {
502
- transform: scale(1);
503
- }
504
- 30% {
505
- transform: scale(0.97);
506
- }
507
- 100% {
508
- transform: scale(1);
509
- }
510
- }
511
-
512
- @keyframes magicx-aia-glassFade {
513
- 0% {
514
- background: var(--aia-streak-glass-bg, rgba(255, 255, 255, 0.1));
515
- }
516
- 100% {
517
- background: transparent;
518
- }
519
- }
520
-
521
- /* --- Streak animations --- */
522
- .magicx-aia-streaks {
523
- position: absolute;
524
- inset: 0;
525
- z-index: 1;
526
- pointer-events: none;
527
- border-radius: inherit;
528
- overflow: hidden;
529
- }
530
-
531
- .magicx-aia-streaks::before {
532
- content: "";
533
- position: absolute;
534
- bottom: -3px;
535
- left: 60%;
536
- width: 0;
537
- height: 6px;
538
- opacity: 0;
539
- background: radial-gradient(
540
- ellipse at center,
541
- rgba(var(--aia-streak-rgb, 255, 255, 255), 0.5) 0%,
542
- rgba(var(--aia-streak-rgb, 255, 255, 255), 0.2) 40%,
543
- transparent 70%
544
- );
545
- box-shadow: 0 0 12px 4px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.2);
546
- filter: blur(1px);
547
- border-radius: 50%;
548
- }
549
-
550
- .magicx-aia-streaks::after {
551
- content: "";
552
- position: absolute;
553
- top: -3px;
554
- right: 60%;
555
- width: 0;
556
- height: 6px;
557
- opacity: 0;
558
- background: radial-gradient(
559
- ellipse at center,
560
- rgba(var(--aia-streak-rgb, 255, 255, 255), 0.5) 0%,
561
- rgba(var(--aia-streak-rgb, 255, 255, 255), 0.2) 40%,
562
- transparent 70%
563
- );
564
- box-shadow: 0 0 12px 4px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.2);
565
- filter: blur(1px);
566
- border-radius: 50%;
567
- }
568
-
569
- .magicx-aia-streaks-vert {
570
- position: absolute;
571
- inset: 0;
572
- z-index: 1;
573
- pointer-events: none;
574
- border-radius: inherit;
575
- overflow: hidden;
576
- }
577
-
578
- .magicx-aia-streaks-vert::before {
579
- content: "";
580
- position: absolute;
581
- bottom: 0;
582
- right: -3px;
583
- width: 6px;
584
- height: 0;
585
- opacity: 0;
586
- background: radial-gradient(
587
- ellipse at center,
588
- rgba(var(--aia-streak-rgb, 255, 255, 255), 0.4) 0%,
589
- rgba(var(--aia-streak-rgb, 255, 255, 255), 0.15) 40%,
590
- transparent 70%
591
- );
592
- box-shadow: 0 0 12px 4px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.15);
593
- filter: blur(1px);
594
- border-radius: 50%;
595
- }
596
-
597
- .magicx-aia-streaks-vert::after {
598
- content: "";
599
- position: absolute;
600
- top: 0;
601
- left: -3px;
602
- width: 6px;
603
- height: 0;
604
- opacity: 0;
605
- background: radial-gradient(
606
- ellipse at center,
607
- rgba(var(--aia-streak-rgb, 255, 255, 255), 0.4) 0%,
608
- rgba(var(--aia-streak-rgb, 255, 255, 255), 0.15) 40%,
609
- transparent 70%
610
- );
611
- box-shadow: 0 0 12px 4px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.15);
612
- filter: blur(1px);
613
- border-radius: 50%;
614
- }
615
-
616
- .magicx-aia-option--pressed .magicx-aia-streaks::before {
617
- animation: magicx-aia-streakHorizRight 500ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
618
- }
619
- .magicx-aia-option--pressed .magicx-aia-streaks::after {
620
- animation: magicx-aia-streakHorizLeft 500ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
621
- }
622
- .magicx-aia-option--pressed .magicx-aia-streaks-vert::before {
623
- animation: magicx-aia-streakVertUp 300ms cubic-bezier(0.3, 0, 0.2, 1) 200ms forwards;
624
- }
625
- .magicx-aia-option--pressed .magicx-aia-streaks-vert::after {
626
- animation: magicx-aia-streakVertDown 300ms cubic-bezier(0.3, 0, 0.2, 1) 200ms forwards;
627
- }
628
-
629
- @keyframes magicx-aia-streakHorizRight {
630
- 0% {
631
- width: 0;
632
- height: 4px;
633
- opacity: 0;
634
- filter: blur(1px);
635
- box-shadow: 0 0 8px 3px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.3);
636
- }
637
- 15% {
638
- height: 4px;
639
- opacity: 1;
640
- filter: blur(1px);
641
- box-shadow: 0 0 10px 4px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.3);
642
- }
643
- 80% {
644
- width: 50%;
645
- height: 10px;
646
- opacity: 0.8;
647
- filter: blur(3px);
648
- box-shadow: 0 0 16px 6px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.1);
649
- }
650
- 100% {
651
- width: 50%;
652
- height: 12px;
653
- opacity: 0;
654
- filter: blur(5px);
655
- box-shadow: 0 0 20px 8px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.03);
656
- }
657
- }
658
-
659
- @keyframes magicx-aia-streakHorizLeft {
660
- 0% {
661
- width: 0;
662
- height: 4px;
663
- opacity: 0;
664
- filter: blur(1px);
665
- box-shadow: 0 0 8px 3px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.3);
666
- }
667
- 15% {
668
- height: 4px;
669
- opacity: 1;
670
- filter: blur(1px);
671
- box-shadow: 0 0 10px 4px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.3);
672
- }
673
- 80% {
674
- width: 50%;
675
- height: 10px;
676
- opacity: 0.8;
677
- filter: blur(3px);
678
- box-shadow: 0 0 16px 6px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.1);
679
- }
680
- 100% {
681
- width: 50%;
682
- height: 12px;
683
- opacity: 0;
684
- filter: blur(5px);
685
- box-shadow: 0 0 20px 8px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.03);
686
- }
687
- }
688
-
689
- @keyframes magicx-aia-streakVertUp {
690
- 0% {
691
- height: 0;
692
- width: 6px;
693
- opacity: 0.9;
694
- filter: blur(1.8px);
695
- box-shadow: 0 0 12px 5px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.25);
696
- }
697
- 75% {
698
- height: 100%;
699
- width: 10px;
700
- opacity: 0.4;
701
- filter: blur(3px);
702
- box-shadow: 0 0 18px 8px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.06);
703
- }
704
- 100% {
705
- height: 100%;
706
- width: 14px;
707
- opacity: 0;
708
- filter: blur(5px);
709
- box-shadow: 0 0 24px 10px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.02);
710
- }
711
- }
712
-
713
- @keyframes magicx-aia-streakVertDown {
714
- 0% {
715
- height: 0;
716
- width: 6px;
717
- opacity: 0.9;
718
- filter: blur(1.8px);
719
- box-shadow: 0 0 12px 5px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.25);
720
- }
721
- 75% {
722
- height: 100%;
723
- width: 10px;
724
- opacity: 0.4;
725
- filter: blur(3px);
726
- box-shadow: 0 0 18px 8px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.06);
727
- }
728
- 100% {
729
- height: 100%;
730
- width: 14px;
731
- opacity: 0;
732
- filter: blur(5px);
733
- box-shadow: 0 0 24px 10px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.02);
734
- }
735
- }
736
-
737
- /* --- Shimmer --- */
738
- .magicx-aia-shimmer {
739
- position: relative;
740
- z-index: 2;
741
- display: inline;
742
- }
743
-
744
- .magicx-aia-shimmer-revealed {
745
- color: transparent;
746
- background: linear-gradient(
747
- 120deg,
748
- var(--aia-written-text-color, var(--aia-color-text-default, #fff)) 0%,
749
- var(--aia-written-text-color, var(--aia-color-text-default, #fff)) 44%,
750
- #b0b0b0 48%,
751
- #b0b0b0 52%,
752
- var(--aia-written-text-color, var(--aia-color-text-default, #fff)) 56%,
753
- var(--aia-written-text-color, var(--aia-color-text-default, #fff)) 100%
754
- );
755
- background-size: 200% 100%;
756
- -webkit-background-clip: text;
757
- background-clip: text;
758
- }
759
-
760
- .magicx-aia-shimmer-sweep {
761
- animation: magicx-aia-textShimmer 650ms ease-out forwards;
762
- }
763
-
764
- @keyframes magicx-aia-textShimmer {
765
- 0% {
766
- background-position: 100% 0;
767
- }
768
- 100% {
769
- background-position: -50% 0;
770
- }
771
- }
772
-
773
- .magicx-aia-shimmer-hidden {
774
- color: transparent !important;
775
- }
776
-
777
- /*
778
- * Built-in appearance defaults \u2014 zero specificity via :where().
779
- * Consumer CSS always wins without !important.
780
- *
781
- * Resolution priority (highest wins):
782
- * 1. Consumer CSS targeting new vars (--aia-pill-bg, etc.)
783
- * 2. Consumer CSS targeting legacy vars (--aia-color-*, via fallback chain)
784
- * 3. These built-in defaults
785
- */
786
-
787
- /*
788
- * Library-scoped box-sizing reset. The SDK's pill / option / wrapper styles
789
- * mix explicit dimensions with padding (e.g. .magicx-aia-pill has height:36px
790
- * + padding:13px) and were authored assuming \`border-box\`. In consumer apps
791
- * without a global \`* { box-sizing: border-box }\` reset the pill rendered
792
- * ~62px tall instead of 36px. Scoping the reset to \`.magicx-aia\` descendants
793
- * keeps the library self-contained without leaking onto consumer markup.
794
- */
795
- :where(.magicx-aia, .magicx-aia *, .magicx-aia *::before, .magicx-aia *::after) {
796
- box-sizing: border-box;
797
- }
798
-
799
- /* Light mode defaults (base) */
800
- :where(.magicx-aia),
801
- :where(.magicx-aia[data-mode="light"]) {
802
- --aia-pill-bg: #bdbdbd;
803
- --aia-pill-color: #000000;
804
- --aia-pill-font-size: 19px;
805
-
806
- --aia-option-bg: transparent;
807
- --aia-option-color: #000000;
808
- --aia-option-color-selected: #000000;
809
- --aia-option-font-size: 19px;
810
-
811
- --aia-written-text-color: #000000;
812
- --aia-written-text-font-size: 19px;
813
- --aia-caret-color: var(--aia-written-text-color, #000000);
814
-
815
- --aia-submit-bg: #000000;
816
- --aia-submit-color: #ffffff;
817
-
818
- --aia-color-text-muted: #6b7280;
819
-
820
- --aia-skeleton-bg: rgba(189, 189, 189, 0.51);
821
-
822
- --aia-streak-rgb: 99, 102, 241;
823
- --aia-streak-glass-bg: rgba(99, 102, 241, 0.1);
824
- }
825
-
826
- /* Dark mode defaults */
827
- :where(.magicx-aia[data-mode="dark"]) {
828
- --aia-pill-bg: #bdbdbd;
829
- --aia-pill-color: #ffffff;
830
- --aia-pill-font-size: 19px;
831
-
832
- --aia-option-bg: transparent;
833
- --aia-option-color: #ffffff;
834
- --aia-option-color-selected: #ffffff;
835
- --aia-option-font-size: 19px;
836
-
837
- --aia-written-text-color: #ffffff;
838
- --aia-written-text-font-size: 19px;
839
- --aia-caret-color: var(--aia-written-text-color, #ffffff);
840
-
841
- --aia-submit-bg: #ffffff;
842
- --aia-submit-color: #000000;
843
-
844
- --aia-color-text-muted: #c1c4cb;
845
-
846
- --aia-skeleton-bg: #333539;
847
-
848
- --aia-streak-rgb: 255, 255, 255;
849
- --aia-streak-glass-bg: rgba(255, 255, 255, 0.1);
850
- }
851
-
852
- /* optionsPosition: dropdown above the input */
853
- :where(.magicx-aia[data-options-position="above"]) [data-aia-dropdown] {
854
- top: auto;
855
- bottom: 100%;
856
- margin-top: 0;
857
- margin-bottom: 6px;
858
- flex-direction: column-reverse;
859
- }
860
-
861
- :where(.magicx-aia[data-options-position="above"]) [data-aia-pillbar] {
862
- padding: 0 27px 27px 27px;
863
- }
864
-
865
- /* Disable all animations when data-animations="off" */
866
- :where(.magicx-aia[data-animations="off"]) *,
867
- :where(.magicx-aia[data-animations="off"]) *::before,
868
- :where(.magicx-aia[data-animations="off"]) *::after {
869
- animation-duration: 0s !important;
870
- transition-duration: 0s !important;
871
- }
872
- `;var z=class{constructor(){this.listeners={}}on(e,t){let i=(...s)=>t(...s),r=this.listeners[e];return r||(r=new Set,this.listeners[e]=r),r.add(i),()=>{this.listeners[e]?.delete(i)}}emit(e,...t){let i=this.listeners[e];if(i)for(let r of i)r(...t)}hasListeners(e){return(this.listeners[e]?.size??0)>0}clear(){this.listeners={}}};var X=class{constructor(){this.timers=new Map}schedule(e,t,i){this.clear(e);let r=setTimeout(()=>{this.timers.delete(e),t()},i);this.timers.set(e,r)}clear(e){let t=this.timers.get(e);t!==void 0&&(clearTimeout(t),this.timers.delete(e))}clearAll(){for(let e of this.timers.values())clearTimeout(e);this.timers.clear()}};var lt="newParam",Le="suggestionRemoval",ct="selectionAnimation",dt=650,ut=0;function pt(){return`:ac-${++ut}:`}var ke=500;function Re(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1}}var Y=class{constructor(e,t={}){this.inputStore=V(Re());this._listboxId=pt();this.modeController=null;this.unsubscribers=[];this.domRefs=null;this.dropdownRefs=null;this.timers=new X;this.emitter=new z;this.sessionId=crypto.randomUUID();this.emitSubmit=e=>this.emitter.emit("submit",e);this.emitError=e=>this.emitter.emit("error",e);this.container=e,this.opts=t,this.renderMode=t.renderMode??"full",this.store=De(this.inputStore,i=>Pe(i,this.opts)),t.onSubmit&&this.emitter.on("submit",t.onSubmit),t.onError&&this.emitter.on("error",t.onError),t.onChange&&this.emitter.on("change",t.onChange),t.onParamsChange&&this.emitter.on("paramsChange",t.onParamsChange),t.onStateChange&&this.emitter.on("stateChange",t.onStateChange),t.onFocus&&this.emitter.on("focus",t.onFocus),t.onBlur&&this.emitter.on("blur",t.onBlur),t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new Q(this.store,{onPillSelected:({rawQuery:i,selectedPill:r,otherPills:s})=>{this.fireTelemetry("pill",{raw_query:i,selected_pill:r,other_pills:s})}}),this.reEdit=new U({store:this.store,scheduleSetCursor:i=>this.scheduleSetCursor(i),fireTelemetry:(i,r)=>this.fireTelemetry(i,r),startSelectionAnimationTimer:()=>this.startSelectionAnimationTimer()}),this.fetchController=new F(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.emitter.hasListeners("error")?this.emitError:void 0,()=>this.sessionId,{onAutoMatch:({active:i,matched:r,rawQuery:s})=>{this.fireTelemetry("option",{raw_query:s,selected_option:r.text,other_options:(i.options??[]).filter(o=>o.text!==r.text).map(o=>o.text)})}}),this.keyboardController=new K(this.store,{columns:t.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.emitter.hasListeners("submit")?this.emitSubmit:void 0,afterSubmit:this.renderMode==="full"?()=>this.reset():void 0,selectOption:i=>this.selectOption(i),removeParamAtCaret:i=>this.removeParamAtCaret(i),exitEditMode:()=>this.exitEditMode()}),this.unsubscribers.push(this.store.subscribe((i,r)=>{i.text!==r.text&&this.emitter.emit("change",i.text),i.completedParams!==r.completedParams&&this.emitter.emit("paramsChange",i.completedParams),i.isFocused!==r.isFocused&&(i.isFocused?this.emitter.emit("focus"):this.emitter.emit("blur")),this.emitter.emit("stateChange",i)})),this.unsubscribers.push(this.store.subscribe(()=>this.maybeExitReEditOnNoMatch())),this.renderMode!=="headless"&&(Me(),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.fetchController.start()}focus(){this.domRefs?.input.focus()}blur(){this.domRefs?.input.blur()}reset(){this.store.set({...Re(),skipNextFetch:!0}),this.sessionId=crypto.randomUUID(),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.timers.clearAll(),this.emitter.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs?.abort.abort(),this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}setValue(e){this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e);let t=this.store.get().text.length;this.store.set({caretOffset:t,isFocused:!0}),this.scheduleSetCursor(t)}removeLastParam(){this.pillsController.removeLastParam()}removeParamAtCaret(e){let t=this.store.get(),{text:i,completedParams:r}=t,s=0;for(let o=0;o<r.length;o++){let a=r[o],l=i.indexOf(a.text,s);if(l===-1)continue;let c=l,u=l+a.text.length;if(e>c&&e<=u){let d=ye(i,e),m=i.slice(0,d)+i.slice(e),b=r.filter((g,h)=>h!==o);return this.store.set(g=>({text:m,filterBase:Math.min(g.filterBase,m.length),completedParams:b,pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(d),!0}s=u}return!1}scheduleSetCursor(e){queueMicrotask(()=>{let t=this.domRefs;t?(t.input.focus(),P(t.input,e)):this.opts.setCursor?.(e)})}clearNewParamId(){this.store.set({newParamId:null})}startEditingParam(e){this.reEdit.start(e)}replaceEditingRange(e){return this.reEdit.replaceRange(e)}exitEditMode(){this.reEdit.exit()}handleCaretAfterInput(e){this.reEdit.caretAfterInput(e)}handleCaretMove(e){this.reEdit.caretMove(e)}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}handleTextChange(e){this.handleChange(e)}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}setFocused(e){this.store.get().isFocused!==e&&this.store.set({isFocused:e})}subscribe(e){return this.store.subscribe(t=>e(t))}getState(){return this.store.get()}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,t){return this.emitter.on(e,t)}update(e){Object.assign(this.opts,e),e.mode!==void 0&&this.modeController?.setMode(e.mode),e.optionsPosition!==void 0&&(this.container.dataset.optionsPosition=e.optionsPosition),e.animations!==void 0&&(this.container.dataset.animations=e.animations?"on":"off"),e.pillPlacement!==void 0&&(this.container.dataset.pillPlacement=e.pillPlacement,this.store.set({})),(e.dropdownTrigger!==void 0||e.closeDropdownOnBlur!==void 0||e.showNonTappableOptions!==void 0)&&this.store.set({}),e.value!==void 0&&this.store.set({text:e.value}),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let t=this.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null){this.reEdit.selectOption(e);return}let i=Oe(t,e);if(i&&(this.fireTelemetry("option",{raw_query:v(t.text,t.completedParams).rawQuery,selected_option:i.telemetry.selectedOption,other_options:i.telemetry.otherOptions}),this.store.set(i.patch),this.startSelectionAnimationTimer(),this.timers.clear(Le),i.remainingActionable>0)){let r=i.consumedSuggestion;this.timers.schedule(Le,()=>{this.store.set(s=>({suggestions:s.suggestions.filter(o=>o!==r)}))},ke)}}startSelectionAnimationTimer(){this.timers.schedule(ct,()=>this.store.set({inSelectionAnimation:!1}),ke)}fireTelemetry(e,t){let i=this.opts.source??(this.renderMode==="full"?"full-sdk":"headless-sdk");ce({source:i,sessionId:this.sessionId,type:e,queryData:t,apiConfig:this.opts.apiConfig})}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"inline",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new M(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,t={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"inline"},get onSubmit(){return e.emitter.hasListeners("submit")?e.emitSubmit:void 0},afterSubmit:()=>e.reset(),submitButton:this.opts.submitButton,autoFocus:this.opts.autoFocus??!0,selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i),startEditingParam:i=>this.startEditingParam(i),handleCaretAfterInput:i=>this.handleCaretAfterInput(i),handleCaretMove:i=>this.handleCaretMove(i),replaceEditingRange:i=>this.replaceEditingRange(i)};this.domRefs=Ie(this.container,t),this.subscribeBatchedRender(()=>{this.domRefs&&ne(this.domRefs,this.store.get(),t)}),ne(this.domRefs,this.store.get(),t),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e={store:this.store,listboxId:this.listboxId,selectOption:t=>this.selectOption(t),setActivePill:t=>this.pillsController.setActivePill(t)};this.dropdownRefs=we(this.container,e),this.subscribeBatchedRender(()=>{this.dropdownRefs&&te(this.dropdownRefs,this.store.get(),e)}),te(this.dropdownRefs,this.store.get(),e),this.subscribeNewParamTimer()}subscribeBatchedRender(e){let t=!1;this.unsubscribers.push(this.store.subscribe(()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,t)=>{e.newParamId&&e.newParamId!==t.newParamId&&this.timers.schedule(lt,()=>this.store.set({newParamId:null}),dt)}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:r}=ae(e,t.completedParams);r.length>0&&this.store.set({completedParams:i}),this.maybePromoteExactMatch(e)}maybeExitReEditOnNoMatch(){let e=this.store.get();if(!e.editingParam||e.editingAnchor==null||e.completedParams.some(a=>a.id===e.editingParam?.id))return;let t=e.caretOffset??e.editingAnchor,i=e.text.slice(e.editingAnchor,t);if(w(e.editingParam.options,i).some(a=>a.is_tappable))return;this.reEdit.exit();let{rawQuery:s,completedParams:o}=v(e.text,e.completedParams);this.fetchController.doFetch(s,o)}maybePromoteExactMatch(e){let t=this.store.get(),i=$({mode:"fresh",text:e,completedParams:t.completedParams,suggestions:t.suggestions,filterBase:t.filterBase,filterInProgress:t.filterInProgress});i&&this.store.set(i.patch)}};0&&(module.exports={AIAutocomplete,createStore});
873
- //# sourceMappingURL=index.js.map