@magicx-eng/ai-autocomplete-vanilla 0.1.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/index.d.mts +168 -0
- package/index.d.ts +168 -0
- package/index.js +619 -0
- package/index.js.map +1 -0
- package/index.mjs +619 -0
- package/index.mjs.map +1 -0
- package/package.json +18 -0
package/index.mjs
ADDED
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
function y(s,e,t){let n=s.slice(e);if(t||e===0||s[e-1]===" ")return n;let i=n.indexOf(" ");return i===-1?"":n.slice(i+1)}function R(s,e){let t=s.trimEnd();if(t.length===0||e.length===0)return 0;let n=t.split(/\s+/),i=e.toLowerCase();for(let o=0;o<n.length;o++){let a=n.slice(o).join(" ");if(i.startsWith(a.toLowerCase())){let l=t.length-a.length;return s.length-l}}return 0}function C(s,e){if(!s)return[];let t=e.trimStart();if(!t)return s;let n=t.toLowerCase();return s.filter(i=>!i.is_tappable||i.text.toLowerCase().includes(n))}function E(s,e){if(!s)return null;let t=e.trim();if(!t)return null;let n=t.toLowerCase();return s.find(i=>i.is_tappable&&i.text.toLowerCase()===n)??null}var P=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 H(s,e){let t=[],n=0;for(let o of e){let a=s.indexOf(o.text,n);a!==-1&&(a>n&&t.push({type:"text",value:s.slice(n,a)}),t.push({type:"completed",value:o.text,param:o}),n=a+o.text.length)}let i=s.slice(n);return i&&t.push({type:"text",value:i}),t}function N(s,e){let t=[],n=[],i=0;for(let o of e){let a=s.indexOf(o.text,i);a===-1?n.push(o):(t.push(o),i=a+o.text.length)}return{valid:t,invalid:n}}var w=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(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 Z="0.1.17",F=!1;function ee(){return crypto.randomUUID()}function te(s,e){return{placeholder:s.placeholder,type:s.type,...e&&{text:s.text},kind:s.kind}}function $(s){return s?.type==="accessToken"}function ne(s){if(!(!s||$(s)))return s}var K=new WeakMap;function oe(s){let e=K.get(s);return e||(e=new w(s),K.set(s,e)),e}function ie(s,e,t){let n=e.find(o=>o.type==="contact"&&o.metadata?.contact_account_count)?.metadata?.contact_account_count,i=typeof n=="number"?n:void 0;return{data:{raw_query:s,completed_params:e.map(o=>te(o,t)),...i!=null&&{contact_account_count:i}},meta:{request_id:ee(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:Z}}}function se(s){return{"Content-Type":"application/json",...s?.appIdentifier&&{"X-App-Identifier":s.appIdentifier},...s?.headers}}async function B(s,e,t,n,i){return fetch(s,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:n,signal:i})}async function q(s,e,t){let n=t?.apiConfig,i=!t?.maskCompletedText,o=ie(s,e,i),a=se(n),l=n?.endpoint??"/ac/suggest",r=JSON.stringify(o);if($(n)){let g=oe(n),u=await g.getToken(),m=await B(l,a,u,r,t?.signal);if(m.status===401){let f=await g.getToken(!0);m=await B(l,a,f,r,t?.signal)}if(!m.ok)throw new Error(`API error: ${m.status} ${m.statusText}`);return m.json()}let c=ne(n),p=c?.apiKey??"";if(!p&&!F&&(F=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),p){let g=c?.authScheme??"Bearer";a.Authorization=g==="Basic"?`Basic ${btoa(p)}`:`Bearer ${p}`}let d=await fetch(l,{method:"POST",headers:a,body:r,signal:t?.signal});if(!d.ok)throw new Error(`API error: ${d.status} ${d.statusText}`);return d.json()}function b(s,e){let t=s,n={},i=[];for(let o of e){let a=(n[o.type]??0)+1;n[o.type]=a;let r=`{{${o.type.toUpperCase().replace(/\s+/g,"_")}_${a}}}`,c=t.indexOf(o.text);c!==-1&&(t=t.slice(0,c)+r+t.slice(c+o.text.length)),i.push({...o,placeholder:r})}return{rawQuery:t,completedParams:i}}function Q(s,e){return e?s.map(t=>{let n=e[t.type];if(!n)return t;let i=n("");if(i.length===0)return t;let o=new Set(i.map(l=>l.text)),a=(t.options??[]).filter(l=>!o.has(l.text));return{...t,options:[...i,...a]}}):s}var re=100,ae=300,le=2,T=class{constructor(e,t,n,i,o){this.store=e;this.getApiConfig=t;this.getOptionOverrides=n;this.getMaskCompletedText=i;this.getOnError=o;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(n=>{(n.text!==e||n.completedParams!==t)&&(e=n.text,t=n.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let n=new AbortController;this.abortController=n;let i=++this.fetchVersion,o=this.store.get(),a=o.text.length;o.suggestions.some(r=>r.type!=="placeholder")||this.store.set({isLoading:!0}),this.store.set({error:null});try{let r=await q(e,t,{maskCompletedText:this.getMaskCompletedText(),signal:n.signal,apiConfig:this.getApiConfig()});if(i!==this.fetchVersion)return;let c=Q(r.data.suggestions??[],this.getOptionOverrides()),p=r.data.input??[],d=p[p.length-1],g=this.store.get().text,u,m;if(d?.state==="in_progress"){m=!0;let x=g.toLowerCase().lastIndexOf(d.text.toLowerCase());u=x!==-1?x:a}else m=!1,u=a;let h=c.filter(x=>x.type!=="placeholder")[0],A=null;if(h){let x=y(g,u,m),v=E(h.options,x);v&&(A={id:crypto.randomUUID(),placeholder:"",type:h.type,text:v.text,kind:v.kind,suggestionType:h.type,suggestionPlaceholder:h.text,options:h.options??[],metadata:v.metadata},c=c.filter(J=>J!==h))}this.store.set(x=>({suggestions:c,isLoading:!1,isReady:r.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:u,filterInProgress:m,...A?{completedParams:[...x.completedParams,A]}:{}}))}catch(r){if(i===this.fetchVersion){let c=r instanceof Error?r:new Error(String(r));this.store.set({error:c,isLoading:!1}),this.getOnError()?.(c)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=n=>{let i=this.store.get();if(!i.text&&i.completedParams.length===0)return this.doFetch("",[]),!0;let o=y(i.text,i.filterBase,i.filterInProgress),l=i.suggestions.filter(h=>h.type!=="placeholder")[0],c=(l?C(l.options,o):[]).filter(h=>h.is_tappable),p=l?E(l.options,o)!==null:!1,d=o.trim().length>0;if(c.length>0&&!p&&d)return!1;let{rawQuery:g,completedParams:u}=b(i.text,i.completedParams),m=g.length<i.lastRawQuery.length,f=Math.abs(g.length-i.lastRawQuery.length);return m||f>=n?(this.doFetch(g,u),!0):!1};this.debounceTimer=setTimeout(()=>{t(le)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},re),this.slowDebounceTimer=setTimeout(()=>t(1),ae)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var S=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{columns:n,listboxId:i,onSubmit:o}=this.ctx,a=this.getTappableIndices();switch(e.key){case"ArrowDown":{let l=e.target;if(!(l.selectionStart!=null&&l.selectionStart===l.value.length)&&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 c=a.indexOf(t.activeDropdownIndex),p=c<a.length-1?c+1:0;this.store.set({activeDropdownIndex:a[p]});break}case"ArrowUp":{if(a.length===0||t.activeDropdownIndex<0)break;if(e.preventDefault(),t.activeDropdownIndex<n){this.store.set({activeDropdownIndex:-1});break}let l=a.indexOf(t.activeDropdownIndex),r=l>0?l-1:a.length-1;this.store.set({activeDropdownIndex:a[r]});break}case"ArrowRight":{if(t.activeDropdownIndex<0){let r=e.target;r.selectionStart!=null&&r.selectionStart===r.value.length&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}if(t.activeDropdownIndex%n<n-1){let r=t.activeDropdownIndex+1;r<t.filteredOptions.length&&t.filteredOptions[r]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:r}))}break}case"ArrowLeft":{if(t.activeDropdownIndex<0)break;if(t.activeDropdownIndex%n>0){let l=t.activeDropdownIndex-1;l>=0&&t.filteredOptions[l]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:l}))}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:r}=b(t.text,t.completedParams);o({query:t.text.trim(),raw_query:l,completed_params:r})}break}case"Tab":{if(t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,i);else if(t.isDropdownOpen){let l=t.filteredOptions.findIndex(r=>r.is_tappable);l>=0&&(e.preventDefault(),this.clickOrSelect(l,t.filteredOptions,i))}else if(!t.text&&t.placeholderText){e.preventDefault();let l=t.suggestions.find(r=>r.type==="placeholder");l?this.store.set(r=>({text:t.placeholderText,filterBase:t.placeholderText.length,completedParams:[...r.completedParams,{id:crypto.randomUUID(),placeholder:"",type:l.type,text:t.placeholderText,kind:null,suggestionType:l.type,suggestionPlaceholder:l.text,options:l.options??[]}],suggestions:r.suggestions.filter(c=>c!==l)})):this.store.set({text:t.placeholderText,filterBase:t.placeholderText.length})}break}case"Escape":this.store.set({activeDropdownIndex:-1});break}}getTappableIndices(){let e=this.store.get(),{columns:t}=this.ctx,n=e.filteredOptions.map((o,a)=>o.is_tappable?a:-1).filter(o=>o!==-1),i=Array.from({length:t},()=>[]);for(let o of n)i[o%t].push(o);return i.flat()}clickOrSelect(e,t,n){let i=document.getElementById(`${n}-option-${e}`);i?i.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),n=t.suggestions.filter(l=>l.type!=="placeholder");if(e<0||e>=n.length)return;let i=n[e],o=n.filter((l,r)=>r!==e),a=t.suggestions.filter(l=>l.type==="placeholder");this.store.set({suggestions:[...a,i,...o],pillTapped:!0,activeDropdownIndex:-1})}};var O=class{constructor(e){this.store=e}setActivePill(e){let t=this.store.get(),n=t.suggestions.filter(l=>l.type!=="placeholder");if(e<0||e>=n.length)return;let i=n[e],o=n.filter((l,r)=>r!==e),a=t.suggestions.filter(l=>l.type==="placeholder");this.store.set({suggestions:[...a,i,...o],pillTapped:!0,activeDropdownIndex:-1})}removeLastParam(){let e=this.store.get();if(e.completedParams.length===0)return;let t=e.completedParams[e.completedParams.length-1],n={type:t.suggestionType,text:t.suggestionPlaceholder,required:!0,options:t.options};this.store.set(i=>({completedParams:i.completedParams.slice(0,-1),suggestions:[n,...i.suggestions],activeDropdownIndex:-1}))}};function ce(s){return s===0?.4:s===1?.3:.15}function I(s,e,t,n,i=!1){let o=s.querySelector(".magicx-ac-pill-list");o||(o=document.createElement("span"),o.className="magicx-ac-pill-list",s.appendChild(o));let a=new Map;for(let r of o.querySelectorAll(".magicx-ac-pill"))a.set(r.dataset.pillKey??"",r);let l=new Set;for(let r=0;r<e.length;r++){let c=e[r],p=`${c.type}-${c.text}`;l.add(p);let d=a.get(p);d||(d=document.createElement("button"),d.type="button",d.dataset.pillKey=p,d.textContent=c.text),d.className=`magicx-ac-pill${i?" magicx-ac-pill--rounded":""}${r===t?" magicx-ac-pill--active":""}`,d.style.opacity=String(ce(r)),d.onclick=()=>n(r),o.children[r]!==d&&o.insertBefore(d,o.children[r]??null)}for(let[r,c]of a)l.has(r)||c.remove()}function j(s){let e=document.createElement("div");return e.id=s,e.setAttribute("role","listbox"),e.setAttribute("data-ac-dropdown",""),e.className="magicx-ac-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function V(s,e){let{filteredOptions:t,activeIndex:n,isOpen:i,pills:o,showPills:a,onSelect:l,onHighlight:r,onPillClick:c}=e,p=a&&o.length>0;i&&t.length>0||i&&p?s.classList.add("magicx-ac-dropdown--visible"):s.classList.remove("magicx-ac-dropdown--visible");let u=s.querySelector(".magicx-ac-pill-bar");p?(u||(u=document.createElement("div"),u.className="magicx-ac-pill-bar",s.insertBefore(u,s.firstChild)),I(u,o,0,c,!0)):u&&u.remove();let m=s.querySelector(".magicx-ac-grid");t.length>0?(m||(m=document.createElement("div"),m.className="magicx-ac-grid",s.appendChild(m)),pe(m,t,n,l,r,e.listboxId)):m&&(m.innerHTML="")}var U="";function pe(s,e,t,n,i,o){let a=e.map(r=>r.text).join("\0"),l=a!==U;if(U=a,l){let r=document.createDocumentFragment();for(let c=0;c<e.length;c++){let p=e[c],d=de(p,c,t,n,i,o);r.appendChild(d)}s.innerHTML="",s.appendChild(r)}else{let r=s.querySelectorAll(".magicx-ac-option");for(let c=0;c<r.length;c++){let p=r[c],d=c===t;p.setAttribute("aria-selected",String(d)),d?p.classList.add("magicx-ac-option--highlighted"):p.classList.remove("magicx-ac-option--highlighted")}}}function de(s,e,t,n,i,o){let a=document.createElement("div");a.id=`${o}-option-${e}`,a.setAttribute("role","option"),a.setAttribute("aria-selected",String(e===t)),a.tabIndex=s.is_tappable?0:-1;let l=["magicx-ac-option"];e===t&&l.push("magicx-ac-option--highlighted"),s.is_tappable?l.push("magicx-ac-option--tappable"):l.push("magicx-ac-option--non-tappable"),a.className=l.join(" ");let r=document.createElement("div");r.className="magicx-ac-streaks",a.appendChild(r);let c=document.createElement("div");c.className="magicx-ac-streaks-vert",a.appendChild(c);let p=document.createElement("span");if(p.className="magicx-ac-option-content",p.textContent=s.icon?`${s.icon} ${s.text}`:s.text,s.tag){let d=document.createElement("span");d.className="magicx-ac-option-tag",d.textContent=s.tag,p.appendChild(d)}return a.appendChild(p),s.is_tappable&&a.addEventListener("click",()=>{a.classList.add("magicx-ac-option--pressed"),n(s),setTimeout(()=>a.classList.remove("magicx-ac-option--pressed"),400)}),a.addEventListener("mouseenter",()=>i(e)),a}var D="",z=null;function W(s,e,t,n,i){let o=s.querySelector(".magicx-ac-sizer-text"),a=s.querySelector(".magicx-ac-placeholder");if(n&&i){o&&(o.style.display="none"),a||(a=document.createElement("span"),a.className="magicx-ac-placeholder",s.insertBefore(a,s.firstChild)),a.style.display="",a.textContent=`${i} `,D="";return}a&&(a.style.display="none"),o||(o=document.createElement("span"),o.className="magicx-ac-sizer-text",s.insertBefore(o,s.firstChild)),o.style.display="",o.className=`magicx-ac-sizer-text${t?" magicx-ac-sizer-text--visible":""}`;let l=e.map(r=>`${r.type}:${r.value}`).join("\0");if(!(l===D&&t===z)){D=l,z=t,o.innerHTML="";for(let r of e){let c=document.createElement("span");r.type==="completed"&&(r.param.id===t?c.className="magicx-ac-shimmer-revealed magicx-ac-shimmer-sweep":c.className="magicx-ac-segment magicx-ac-segment--completed"),c.textContent=r.value,o.appendChild(c)}e.length===0&&(o.textContent="\xA0")}}var ue='<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 G(s,e){let{listboxId:t}=e,n=j(t);s.appendChild(n);let i=document.createElement("div");i.className="magicx-ac-input-wrapper",s.appendChild(i);let o=document.createElement("div");o.className="magicx-ac-editor",i.appendChild(o);let a=document.createElement("div");a.className="magicx-ac-sizer",a.setAttribute("aria-hidden","true"),o.appendChild(a);let l=document.createElement("span");a.appendChild(document.createTextNode(" ")),a.appendChild(l);let r=document.createElement("textarea");r.className="magicx-ac-textarea",r.rows=1,r.setAttribute("role","combobox"),r.setAttribute("aria-autocomplete","list"),r.setAttribute("aria-controls",t),o.appendChild(r);let c=document.createElement("button");return c.type="button",c.className="magicx-ac-submit",c.setAttribute("aria-label","Submit"),c.innerHTML=ue,i.appendChild(c),i.addEventListener("click",()=>r.focus()),r.addEventListener("input",()=>{let p=r.value,g=p.length>0&&p[0]!==p[0].toUpperCase()?p[0].toUpperCase()+p.slice(1):p;e.handleChange(g)}),r.addEventListener("keydown",p=>e.handleKeyDown(p)),c.addEventListener("click",p=>{p.stopPropagation();let d=e.store.get();if(!(!!d.text||d.completedParams.length>0)||!e.onSubmit)return;let{rawQuery:u,completedParams:m}=b(d.text,d.completedParams);e.onSubmit({query:d.text.trim(),raw_query:u,completed_params:m})}),r.focus(),{textarea:r,dropdown:n,sizer:a,submitButton:c,inlinePillContainer:l}}function k(s,e,t){let{textarea:n,dropdown:i,sizer:o,submitButton:a,inlinePillContainer:l}=s,{pillPlacement:r,setActivePill:c,selectOption:p,store:d}=t;n.value!==e.text&&(n.value=e.text),e.placeholderText?n.placeholder=e.placeholderText:n.removeAttribute("placeholder"),n.setAttribute("aria-expanded",String(e.isDropdownOpen));let g=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";g?n.setAttribute("aria-activedescendant",g):n.removeAttribute("aria-activedescendant"),e.newParamId?n.classList.add("magicx-ac-textarea--hidden"):n.classList.remove("magicx-ac-textarea--hidden");let u=!!e.text||e.completedParams.length>0;a.disabled=!u,W(o,e.segments,e.newParamId,!e.text,e.placeholderText),r==="inline"?I(l,e.actionableSuggestions,0,c):l.innerHTML="",V(i,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:r==="dropdown",onSelect:p,onHighlight:m=>d.set({activeDropdownIndex:m}),onPillClick:c})}function L(s){let e=s,t=new Set;return{get:()=>e,set:n=>{let i=typeof n=="function"?n(e):n,o={...e,...i},a=e;e=o;for(let l of t)l(o,a)},subscribe:n=>(t.add(n),()=>{t.delete(n)})}}var M=!1;function X(){if(M||typeof document>"u")return;if(document.querySelector("style[data-magicx-ac]")){M=!0;return}M=!0;let s=document.createElement("style");s.setAttribute("data-magicx-ac",""),s.textContent=me,document.head.appendChild(s)}var me=`/* ===================================================================
|
|
2
|
+
Vanilla core styles \u2014 stable BEM class names (magicx-ac-*)
|
|
3
|
+
Auto-injected at runtime on first instantiation.
|
|
4
|
+
=================================================================== */
|
|
5
|
+
|
|
6
|
+
/* --- Container --- */
|
|
7
|
+
.magicx-ac {
|
|
8
|
+
position: relative;
|
|
9
|
+
font-family: "IBM Plex Sans", sans-serif;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/* --- Input wrapper --- */
|
|
13
|
+
.magicx-ac-input-wrapper {
|
|
14
|
+
min-height: 60px;
|
|
15
|
+
padding: 24px;
|
|
16
|
+
border: 1px solid var(--ac-color-border-default, #9ea5b2);
|
|
17
|
+
border-radius: 23px;
|
|
18
|
+
background: transparent;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
gap: 12px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* --- Editor area (overlay + textarea) --- */
|
|
26
|
+
.magicx-ac-editor {
|
|
27
|
+
position: relative;
|
|
28
|
+
flex: 1;
|
|
29
|
+
min-width: 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* --- Sizer (overlay for sizing + segment display) --- */
|
|
33
|
+
.magicx-ac-sizer {
|
|
34
|
+
position: relative;
|
|
35
|
+
z-index: 1;
|
|
36
|
+
pointer-events: none;
|
|
37
|
+
min-height: 60px;
|
|
38
|
+
white-space: pre-wrap;
|
|
39
|
+
word-break: break-word;
|
|
40
|
+
font-family: inherit;
|
|
41
|
+
font-size: var(--ac-written-text-font-size, 19px);
|
|
42
|
+
line-height: 38px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.magicx-ac-sizer-text {
|
|
46
|
+
color: transparent;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.magicx-ac-sizer-text--visible {
|
|
50
|
+
color: var(--ac-written-text-color, var(--ac-color-text-default, #fff));
|
|
51
|
+
font-size: var(--ac-written-text-font-size, inherit);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* --- Placeholder --- */
|
|
55
|
+
.magicx-ac-placeholder {
|
|
56
|
+
color: var(--ac-color-text-muted, #c1c4cb);
|
|
57
|
+
opacity: 0.7;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* --- Textarea --- */
|
|
61
|
+
.magicx-ac-textarea {
|
|
62
|
+
position: absolute;
|
|
63
|
+
top: 0;
|
|
64
|
+
left: 0;
|
|
65
|
+
width: 100%;
|
|
66
|
+
height: 100%;
|
|
67
|
+
padding: 0;
|
|
68
|
+
border: none;
|
|
69
|
+
background: transparent;
|
|
70
|
+
color: var(--ac-written-text-color, var(--ac-color-text-default, #fff));
|
|
71
|
+
caret-color: var(--ac-written-text-color, var(--ac-color-text-default, #fff));
|
|
72
|
+
font-family: inherit;
|
|
73
|
+
font-size: var(--ac-written-text-font-size, 19px);
|
|
74
|
+
line-height: 38px;
|
|
75
|
+
white-space: pre-wrap;
|
|
76
|
+
word-break: break-word;
|
|
77
|
+
outline: none;
|
|
78
|
+
resize: none;
|
|
79
|
+
overflow: hidden;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.magicx-ac-textarea::placeholder {
|
|
83
|
+
color: var(--ac-color-text-muted, #c1c4cb);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.magicx-ac-textarea--hidden {
|
|
87
|
+
color: transparent !important;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* --- Submit button --- */
|
|
91
|
+
.magicx-ac-submit {
|
|
92
|
+
flex-shrink: 0;
|
|
93
|
+
width: 36px;
|
|
94
|
+
height: 36px;
|
|
95
|
+
border-radius: 50%;
|
|
96
|
+
border: none;
|
|
97
|
+
background: var(--ac-color-text-default, #fff);
|
|
98
|
+
color: var(--ac-color-bg-default, #000);
|
|
99
|
+
cursor: pointer;
|
|
100
|
+
display: flex;
|
|
101
|
+
align-items: center;
|
|
102
|
+
justify-content: center;
|
|
103
|
+
padding: 0;
|
|
104
|
+
transition: opacity 0.2s ease;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.magicx-ac-submit:hover {
|
|
108
|
+
opacity: 0.85;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* --- Dropdown --- */
|
|
112
|
+
.magicx-ac-dropdown {
|
|
113
|
+
--border-width: 1px;
|
|
114
|
+
position: absolute;
|
|
115
|
+
left: 0;
|
|
116
|
+
right: 0;
|
|
117
|
+
top: 100%;
|
|
118
|
+
margin-top: 6px;
|
|
119
|
+
border-radius: 1rem;
|
|
120
|
+
overflow: hidden;
|
|
121
|
+
z-index: 10;
|
|
122
|
+
opacity: 0;
|
|
123
|
+
pointer-events: none;
|
|
124
|
+
transition: opacity 400ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
125
|
+
background: hsl(243 26% 15% / 0.25);
|
|
126
|
+
backdrop-filter: blur(12px);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.magicx-ac-dropdown::before {
|
|
130
|
+
content: "";
|
|
131
|
+
position: absolute;
|
|
132
|
+
z-index: -1;
|
|
133
|
+
inset: 0;
|
|
134
|
+
border-radius: inherit;
|
|
135
|
+
border: var(--border-width) solid transparent;
|
|
136
|
+
background: linear-gradient(hsl(259, 13%, 28%), hsl(252, 9%, 22%)) border-box;
|
|
137
|
+
mask:
|
|
138
|
+
linear-gradient(black, black) border-box,
|
|
139
|
+
linear-gradient(black, black) padding-box;
|
|
140
|
+
mask-composite: subtract;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.magicx-ac-dropdown--visible {
|
|
144
|
+
opacity: 1;
|
|
145
|
+
pointer-events: auto;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* --- Pill bar (inside dropdown) --- */
|
|
149
|
+
.magicx-ac-pill-bar {
|
|
150
|
+
padding: 27px 27px 0px 27px;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* --- Pill list --- */
|
|
154
|
+
.magicx-ac-pill-list {
|
|
155
|
+
position: relative;
|
|
156
|
+
z-index: 1;
|
|
157
|
+
pointer-events: auto;
|
|
158
|
+
display: inline-flex;
|
|
159
|
+
gap: 5px;
|
|
160
|
+
align-items: center;
|
|
161
|
+
vertical-align: middle;
|
|
162
|
+
transform: translateY(-3px);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/* --- Individual pill --- */
|
|
166
|
+
.magicx-ac-pill {
|
|
167
|
+
display: inline-flex;
|
|
168
|
+
align-items: center;
|
|
169
|
+
justify-content: center;
|
|
170
|
+
height: 36px;
|
|
171
|
+
padding: 13px 13px;
|
|
172
|
+
border: none;
|
|
173
|
+
border-radius: 6px;
|
|
174
|
+
background: var(--ac-pill-bg, var(--ac-color-background-supportive, #313255));
|
|
175
|
+
color: var(--ac-pill-color, var(--ac-color-text-muted, #c1c4cb));
|
|
176
|
+
font-family: "IBM Plex Sans", sans-serif;
|
|
177
|
+
font-size: var(--ac-pill-font-size, 19px);
|
|
178
|
+
line-height: 30px;
|
|
179
|
+
cursor: pointer;
|
|
180
|
+
white-space: nowrap;
|
|
181
|
+
animation: magicx-ac-fadeIn 400ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.magicx-ac-pill--rounded {
|
|
185
|
+
border-radius: 999px;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.magicx-ac-pill:hover {
|
|
189
|
+
filter: brightness(1.2);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.magicx-ac-pill--active {
|
|
193
|
+
outline: 1px solid #5a5b8a;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
@keyframes magicx-ac-fadeIn {
|
|
197
|
+
from {
|
|
198
|
+
opacity: 0;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/* --- Options grid --- */
|
|
203
|
+
.magicx-ac-grid {
|
|
204
|
+
display: grid;
|
|
205
|
+
grid-template-columns: 1fr 1fr;
|
|
206
|
+
padding: 13px 13px;
|
|
207
|
+
max-height: 192px;
|
|
208
|
+
overflow-y: auto;
|
|
209
|
+
scrollbar-width: thin;
|
|
210
|
+
scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.magicx-ac-grid::-webkit-scrollbar {
|
|
214
|
+
width: 6px;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.magicx-ac-grid::-webkit-scrollbar-track {
|
|
218
|
+
background: transparent;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.magicx-ac-grid::-webkit-scrollbar-thumb {
|
|
222
|
+
background: rgba(255, 255, 255, 0.3);
|
|
223
|
+
border-radius: 3px;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/* --- Option item --- */
|
|
227
|
+
.magicx-ac-option {
|
|
228
|
+
position: relative;
|
|
229
|
+
overflow: visible;
|
|
230
|
+
display: flex;
|
|
231
|
+
align-items: center;
|
|
232
|
+
font-family: "IBM Plex Sans", sans-serif;
|
|
233
|
+
font-size: var(--ac-option-font-size, 19px);
|
|
234
|
+
line-height: 30px;
|
|
235
|
+
color: var(--ac-option-color, var(--ac-color-text-muted, #c1c4cb));
|
|
236
|
+
white-space: normal;
|
|
237
|
+
word-break: break-word;
|
|
238
|
+
opacity: 0.35;
|
|
239
|
+
border-radius: 12px;
|
|
240
|
+
padding: 13px 13px;
|
|
241
|
+
animation: magicx-ac-optionFadeIn 500ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
@keyframes magicx-ac-optionFadeIn {
|
|
245
|
+
from {
|
|
246
|
+
opacity: 0;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.magicx-ac-option-content {
|
|
251
|
+
position: relative;
|
|
252
|
+
z-index: 2;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.magicx-ac-option--tappable {
|
|
256
|
+
cursor: pointer;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.magicx-ac-option--tappable:hover {
|
|
260
|
+
color: var(--ac-option-color-selected, var(--ac-color-text-default, #fff));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.magicx-ac-option--non-tappable {
|
|
264
|
+
cursor: default;
|
|
265
|
+
opacity: 0.3;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.magicx-ac-option--highlighted {
|
|
269
|
+
color: var(--ac-option-color-selected, var(--ac-color-text-default, #fff));
|
|
270
|
+
background: var(--ac-option-bg, transparent);
|
|
271
|
+
opacity: 0.5;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.magicx-ac-option-tag {
|
|
275
|
+
font-size: 11px;
|
|
276
|
+
margin-left: 6px;
|
|
277
|
+
opacity: 0.5;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
.magicx-ac-option--pressed {
|
|
281
|
+
opacity: 0.8;
|
|
282
|
+
color: var(--ac-option-color-selected, var(--ac-color-text-default, #fff));
|
|
283
|
+
background: rgba(255, 255, 255, 0.06);
|
|
284
|
+
animation:
|
|
285
|
+
magicx-ac-glassFade 500ms ease forwards,
|
|
286
|
+
magicx-ac-tapDown 500ms ease forwards;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
@keyframes magicx-ac-tapDown {
|
|
290
|
+
0% {
|
|
291
|
+
transform: scale(1);
|
|
292
|
+
}
|
|
293
|
+
30% {
|
|
294
|
+
transform: scale(0.97);
|
|
295
|
+
}
|
|
296
|
+
100% {
|
|
297
|
+
transform: scale(1);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
@keyframes magicx-ac-glassFade {
|
|
302
|
+
0% {
|
|
303
|
+
background: rgba(255, 255, 255, 0.1);
|
|
304
|
+
}
|
|
305
|
+
100% {
|
|
306
|
+
background: transparent;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/* --- Streak animations --- */
|
|
311
|
+
.magicx-ac-streaks {
|
|
312
|
+
position: absolute;
|
|
313
|
+
inset: 0;
|
|
314
|
+
z-index: 1;
|
|
315
|
+
pointer-events: none;
|
|
316
|
+
border-radius: inherit;
|
|
317
|
+
overflow: hidden;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.magicx-ac-streaks::before {
|
|
321
|
+
content: "";
|
|
322
|
+
position: absolute;
|
|
323
|
+
bottom: -3px;
|
|
324
|
+
left: 60%;
|
|
325
|
+
width: 0;
|
|
326
|
+
height: 6px;
|
|
327
|
+
background: radial-gradient(
|
|
328
|
+
ellipse at center,
|
|
329
|
+
rgba(255, 255, 255, 0.5) 0%,
|
|
330
|
+
rgba(255, 255, 255, 0.2) 40%,
|
|
331
|
+
transparent 70%
|
|
332
|
+
);
|
|
333
|
+
box-shadow: 0 0 12px 4px rgba(255, 255, 255, 0.2);
|
|
334
|
+
filter: blur(1px);
|
|
335
|
+
border-radius: 50%;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.magicx-ac-streaks::after {
|
|
339
|
+
content: "";
|
|
340
|
+
position: absolute;
|
|
341
|
+
top: -3px;
|
|
342
|
+
right: 60%;
|
|
343
|
+
width: 0;
|
|
344
|
+
height: 6px;
|
|
345
|
+
background: radial-gradient(
|
|
346
|
+
ellipse at center,
|
|
347
|
+
rgba(255, 255, 255, 0.5) 0%,
|
|
348
|
+
rgba(255, 255, 255, 0.2) 40%,
|
|
349
|
+
transparent 70%
|
|
350
|
+
);
|
|
351
|
+
box-shadow: 0 0 12px 4px rgba(255, 255, 255, 0.2);
|
|
352
|
+
filter: blur(1px);
|
|
353
|
+
border-radius: 50%;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
.magicx-ac-streaks-vert {
|
|
357
|
+
position: absolute;
|
|
358
|
+
inset: 0;
|
|
359
|
+
z-index: 1;
|
|
360
|
+
pointer-events: none;
|
|
361
|
+
border-radius: inherit;
|
|
362
|
+
overflow: hidden;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
.magicx-ac-streaks-vert::before {
|
|
366
|
+
content: "";
|
|
367
|
+
position: absolute;
|
|
368
|
+
bottom: 0;
|
|
369
|
+
right: -3px;
|
|
370
|
+
width: 6px;
|
|
371
|
+
height: 0;
|
|
372
|
+
background: radial-gradient(
|
|
373
|
+
ellipse at center,
|
|
374
|
+
rgba(255, 255, 255, 0.4) 0%,
|
|
375
|
+
rgba(255, 255, 255, 0.15) 40%,
|
|
376
|
+
transparent 70%
|
|
377
|
+
);
|
|
378
|
+
box-shadow: 0 0 12px 4px rgba(255, 255, 255, 0.15);
|
|
379
|
+
filter: blur(1px);
|
|
380
|
+
border-radius: 50%;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
.magicx-ac-streaks-vert::after {
|
|
384
|
+
content: "";
|
|
385
|
+
position: absolute;
|
|
386
|
+
top: 0;
|
|
387
|
+
left: -3px;
|
|
388
|
+
width: 6px;
|
|
389
|
+
height: 0;
|
|
390
|
+
background: radial-gradient(
|
|
391
|
+
ellipse at center,
|
|
392
|
+
rgba(255, 255, 255, 0.4) 0%,
|
|
393
|
+
rgba(255, 255, 255, 0.15) 40%,
|
|
394
|
+
transparent 70%
|
|
395
|
+
);
|
|
396
|
+
box-shadow: 0 0 12px 4px rgba(255, 255, 255, 0.15);
|
|
397
|
+
filter: blur(1px);
|
|
398
|
+
border-radius: 50%;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.magicx-ac-option--pressed .magicx-ac-streaks::before {
|
|
402
|
+
animation: magicx-ac-streakHorizRight 500ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
403
|
+
}
|
|
404
|
+
.magicx-ac-option--pressed .magicx-ac-streaks::after {
|
|
405
|
+
animation: magicx-ac-streakHorizLeft 500ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
406
|
+
}
|
|
407
|
+
.magicx-ac-option--pressed .magicx-ac-streaks-vert::before {
|
|
408
|
+
animation: magicx-ac-streakVertUp 300ms cubic-bezier(0.3, 0, 0.2, 1) 200ms forwards;
|
|
409
|
+
}
|
|
410
|
+
.magicx-ac-option--pressed .magicx-ac-streaks-vert::after {
|
|
411
|
+
animation: magicx-ac-streakVertDown 300ms cubic-bezier(0.3, 0, 0.2, 1) 200ms forwards;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
@keyframes magicx-ac-streakHorizRight {
|
|
415
|
+
0% {
|
|
416
|
+
width: 0;
|
|
417
|
+
height: 4px;
|
|
418
|
+
opacity: 0;
|
|
419
|
+
filter: blur(1px);
|
|
420
|
+
box-shadow: 0 0 8px 3px rgba(255, 255, 255, 0.3);
|
|
421
|
+
}
|
|
422
|
+
15% {
|
|
423
|
+
height: 4px;
|
|
424
|
+
opacity: 1;
|
|
425
|
+
filter: blur(1px);
|
|
426
|
+
box-shadow: 0 0 10px 4px rgba(255, 255, 255, 0.3);
|
|
427
|
+
}
|
|
428
|
+
80% {
|
|
429
|
+
width: 50%;
|
|
430
|
+
height: 10px;
|
|
431
|
+
opacity: 0.8;
|
|
432
|
+
filter: blur(3px);
|
|
433
|
+
box-shadow: 0 0 16px 6px rgba(255, 255, 255, 0.1);
|
|
434
|
+
}
|
|
435
|
+
100% {
|
|
436
|
+
width: 50%;
|
|
437
|
+
height: 12px;
|
|
438
|
+
opacity: 0;
|
|
439
|
+
filter: blur(5px);
|
|
440
|
+
box-shadow: 0 0 20px 8px rgba(255, 255, 255, 0.03);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
@keyframes magicx-ac-streakHorizLeft {
|
|
445
|
+
0% {
|
|
446
|
+
width: 0;
|
|
447
|
+
height: 4px;
|
|
448
|
+
opacity: 0;
|
|
449
|
+
filter: blur(1px);
|
|
450
|
+
box-shadow: 0 0 8px 3px rgba(255, 255, 255, 0.3);
|
|
451
|
+
}
|
|
452
|
+
15% {
|
|
453
|
+
height: 4px;
|
|
454
|
+
opacity: 1;
|
|
455
|
+
filter: blur(1px);
|
|
456
|
+
box-shadow: 0 0 10px 4px rgba(255, 255, 255, 0.3);
|
|
457
|
+
}
|
|
458
|
+
80% {
|
|
459
|
+
width: 50%;
|
|
460
|
+
height: 10px;
|
|
461
|
+
opacity: 0.8;
|
|
462
|
+
filter: blur(3px);
|
|
463
|
+
box-shadow: 0 0 16px 6px rgba(255, 255, 255, 0.1);
|
|
464
|
+
}
|
|
465
|
+
100% {
|
|
466
|
+
width: 50%;
|
|
467
|
+
height: 12px;
|
|
468
|
+
opacity: 0;
|
|
469
|
+
filter: blur(5px);
|
|
470
|
+
box-shadow: 0 0 20px 8px rgba(255, 255, 255, 0.03);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
@keyframes magicx-ac-streakVertUp {
|
|
475
|
+
0% {
|
|
476
|
+
height: 0;
|
|
477
|
+
width: 6px;
|
|
478
|
+
opacity: 0.9;
|
|
479
|
+
filter: blur(1.8px);
|
|
480
|
+
box-shadow: 0 0 12px 5px rgba(255, 255, 255, 0.25);
|
|
481
|
+
}
|
|
482
|
+
75% {
|
|
483
|
+
height: 100%;
|
|
484
|
+
width: 10px;
|
|
485
|
+
opacity: 0.4;
|
|
486
|
+
filter: blur(3px);
|
|
487
|
+
box-shadow: 0 0 18px 8px rgba(255, 255, 255, 0.06);
|
|
488
|
+
}
|
|
489
|
+
100% {
|
|
490
|
+
height: 100%;
|
|
491
|
+
width: 14px;
|
|
492
|
+
opacity: 0;
|
|
493
|
+
filter: blur(5px);
|
|
494
|
+
box-shadow: 0 0 24px 10px rgba(255, 255, 255, 0.02);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
@keyframes magicx-ac-streakVertDown {
|
|
499
|
+
0% {
|
|
500
|
+
height: 0;
|
|
501
|
+
width: 6px;
|
|
502
|
+
opacity: 0.9;
|
|
503
|
+
filter: blur(1.8px);
|
|
504
|
+
box-shadow: 0 0 12px 5px rgba(255, 255, 255, 0.25);
|
|
505
|
+
}
|
|
506
|
+
75% {
|
|
507
|
+
height: 100%;
|
|
508
|
+
width: 10px;
|
|
509
|
+
opacity: 0.4;
|
|
510
|
+
filter: blur(3px);
|
|
511
|
+
box-shadow: 0 0 18px 8px rgba(255, 255, 255, 0.06);
|
|
512
|
+
}
|
|
513
|
+
100% {
|
|
514
|
+
height: 100%;
|
|
515
|
+
width: 14px;
|
|
516
|
+
opacity: 0;
|
|
517
|
+
filter: blur(5px);
|
|
518
|
+
box-shadow: 0 0 24px 10px rgba(255, 255, 255, 0.02);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/* --- Shimmer --- */
|
|
523
|
+
.magicx-ac-shimmer {
|
|
524
|
+
position: relative;
|
|
525
|
+
z-index: 2;
|
|
526
|
+
display: inline;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
.magicx-ac-shimmer-revealed {
|
|
530
|
+
color: transparent;
|
|
531
|
+
background: linear-gradient(
|
|
532
|
+
120deg,
|
|
533
|
+
var(--ac-written-text-color, var(--ac-color-text-default, #fff)) 0%,
|
|
534
|
+
var(--ac-written-text-color, var(--ac-color-text-default, #fff)) 44%,
|
|
535
|
+
#b0b0b0 48%,
|
|
536
|
+
#b0b0b0 52%,
|
|
537
|
+
var(--ac-written-text-color, var(--ac-color-text-default, #fff)) 56%,
|
|
538
|
+
var(--ac-written-text-color, var(--ac-color-text-default, #fff)) 100%
|
|
539
|
+
);
|
|
540
|
+
background-size: 200% 100%;
|
|
541
|
+
-webkit-background-clip: text;
|
|
542
|
+
background-clip: text;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
.magicx-ac-shimmer-sweep {
|
|
546
|
+
animation: magicx-ac-textShimmer 650ms ease-out forwards;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
@keyframes magicx-ac-textShimmer {
|
|
550
|
+
0% {
|
|
551
|
+
background-position: 100% 0;
|
|
552
|
+
}
|
|
553
|
+
100% {
|
|
554
|
+
background-position: -50% 0;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
.magicx-ac-shimmer-hidden {
|
|
559
|
+
color: transparent !important;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/*
|
|
563
|
+
* Built-in appearance defaults \u2014 zero specificity via :where().
|
|
564
|
+
* Consumer CSS always wins without !important.
|
|
565
|
+
*
|
|
566
|
+
* Resolution priority (highest wins):
|
|
567
|
+
* 1. Consumer CSS targeting new vars (--ac-pill-bg, etc.)
|
|
568
|
+
* 2. Consumer CSS targeting legacy vars (--ac-color-*, via fallback chain)
|
|
569
|
+
* 3. These built-in defaults
|
|
570
|
+
*/
|
|
571
|
+
|
|
572
|
+
/* Light mode defaults (base) */
|
|
573
|
+
:where(.magicx-ac),
|
|
574
|
+
:where(.magicx-ac[data-mode="light"]) {
|
|
575
|
+
--ac-pill-bg: #f1f5f9;
|
|
576
|
+
--ac-pill-color: #475569;
|
|
577
|
+
--ac-pill-font-size: 19px;
|
|
578
|
+
|
|
579
|
+
--ac-option-bg: transparent;
|
|
580
|
+
--ac-option-color: #475569;
|
|
581
|
+
--ac-option-color-selected: #0f172a;
|
|
582
|
+
--ac-option-font-size: 19px;
|
|
583
|
+
|
|
584
|
+
--ac-written-text-color: #0f172a;
|
|
585
|
+
--ac-written-text-font-size: 19px;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/* Dark mode defaults */
|
|
589
|
+
:where(.magicx-ac[data-mode="dark"]) {
|
|
590
|
+
--ac-pill-bg: #1e293b;
|
|
591
|
+
--ac-pill-color: #cbd5e1;
|
|
592
|
+
--ac-pill-font-size: 19px;
|
|
593
|
+
|
|
594
|
+
--ac-option-bg: transparent;
|
|
595
|
+
--ac-option-color: #cbd5e1;
|
|
596
|
+
--ac-option-color-selected: #f8fafc;
|
|
597
|
+
--ac-option-font-size: 19px;
|
|
598
|
+
|
|
599
|
+
--ac-written-text-color: #f1f5f9;
|
|
600
|
+
--ac-written-text-font-size: 19px;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/* optionsPosition: dropdown above the input */
|
|
604
|
+
:where(.magicx-ac[data-options-position="above"]) [data-ac-dropdown] {
|
|
605
|
+
top: auto;
|
|
606
|
+
bottom: 100%;
|
|
607
|
+
margin-top: 0;
|
|
608
|
+
margin-bottom: 6px;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/* Disable all animations when data-animations="off" */
|
|
612
|
+
:where(.magicx-ac[data-animations="off"]) *,
|
|
613
|
+
:where(.magicx-ac[data-animations="off"]) *::before,
|
|
614
|
+
:where(.magicx-ac[data-animations="off"]) *::after {
|
|
615
|
+
animation-duration: 0s !important;
|
|
616
|
+
transition-duration: 0s !important;
|
|
617
|
+
}
|
|
618
|
+
`;var ge=0;function he(){return`:ac-${++ge}:`}function Y(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],placeholderText:"",isDropdownOpen:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:""}}var _=class{constructor(e,t={}){this.store=L(Y());this.listboxId=he();this.modeController=null;this.unsubscribers=[];this.derivedInProgress=!1;this.domRefs=null;this.container=e,this.opts=t,t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new O(this.store),this.fetchController=new T(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.opts.onError),this.keyboardController=new S(this.store,{columns:t.columns??2,listboxId:this.listboxId,onSubmit:t.onSubmit,selectOption:n=>this.selectOption(n)}),this.unsubscribers.push(this.store.subscribe((n,i)=>{this.recomputeDerived(n,i)})),this.unsubscribers.push(this.store.subscribe((n,i)=>{n.text!==i.text&&this.opts.onChange?.(n.text),n.completedParams!==i.completedParams&&this.opts.onParamsChange?.(n.completedParams),this.opts.onStateChange?.(n)})),X(),this.setupContainer(),this.buildAndRender(),this.fetchController.start()}focus(){this.domRefs?.textarea.focus()}reset(){this.store.set({...Y()}),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.newParamTimer&&clearTimeout(this.newParamTimer);for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs=null,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)}removeLastParam(){this.pillsController.removeLastParam()}clearNewParamId(){this.store.set({newParamId:null})}getState(){return this.store.get()}get isReady(){return this.store.get().isReady}on(e,t){switch(e){case"submit":return this.opts.onSubmit=t,this.keyboardController=new S(this.store,{columns:this.opts.columns??2,listboxId:this.listboxId,onSubmit:this.opts.onSubmit,selectOption:n=>this.selectOption(n)}),()=>{this.opts.onSubmit=void 0};case"error":return this.opts.onError=t,()=>{this.opts.onError=void 0};case"change":return this.opts.onChange=t,()=>{this.opts.onChange=void 0};case"paramsChange":return this.opts.onParamsChange=t,()=>{this.opts.onParamsChange=void 0};case"stateChange":return this.opts.onStateChange=t,()=>{this.opts.onStateChange=void 0};default:return()=>{}}}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.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(),n=t.actionableSuggestions[0];if(!n)return;let i=t.filterBase,o=t.text.slice(0,i),a=o.length===0&&t.text.length===0;a&&t.placeholderText&&(o=`${t.placeholderText} `);let l=R(o,e.text);l>0&&(o=o.slice(0,o.length-l));let r=o.length>0&&o[o.length-1]!==" ",c=`${o}${r?" ":""}${e.text} `,p=a&&c.length>0?c[0].toUpperCase()+c.slice(1):c,d=p.toLowerCase().lastIndexOf(e.text.toLowerCase()),g=d>=0?p.slice(d,d+e.text.length):e.text,u={id:crypto.randomUUID(),placeholder:"",type:n.type,text:g,kind:e.kind,suggestionType:n.type,suggestionPlaceholder:n.text,options:n.options??[],metadata:e.metadata},m=t.actionableSuggestions.length-1;this.store.set(f=>({text:p,filterBase:p.length,completedParams:[...f.completedParams,u],newParamId:u.id,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:m>0})),setTimeout(()=>{this.store.set(f=>({suggestions:f.suggestions.filter(h=>h!==n)}))},400)}recomputeDerived(e,t){if(this.derivedInProgress)return;this.derivedInProgress=!0;let n=H(e.text,e.completedParams),i=e.suggestions.filter(u=>u.type!=="placeholder"),o=i[0],a=o?this.opts.optionOverrides?.[o.type]:void 0,l=y(e.text,e.filterBase,e.filterInProgress),r=o?a?a(l.trim()):o.options??[]:[],c=C(r,l),p=e.suggestions.filter(u=>u.type==="placeholder").map(u=>u.text).join(" ")||this.opts.placeholder||"",d=p.length>0,g=!e.isLoading&&c.length>0&&(!!e.text||e.pillTapped||!d);this.store.set({segments:n,actionableSuggestions:i,filteredOptions:c,placeholderText:p,isDropdownOpen:g}),this.derivedInProgress=!1}setupContainer(){this.container.classList.add("magicx-ac"),this.container.dataset.pillPlacement=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 P(this.container,this.opts.mode??"auto")}buildAndRender(){let e={store:this.store,listboxId:this.listboxId,get pillPlacement(){return t.opts.pillPlacement??"inline"},get onSubmit(){return t.opts.onSubmit},selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i)},t=this;this.domRefs=G(this.container,e);let n=!1;this.unsubscribers.push(this.store.subscribe(()=>{n||(n=!0,queueMicrotask(()=>{n=!1,this.domRefs&&k(this.domRefs,this.store.get(),e)}))})),k(this.domRefs,this.store.get(),e),this.unsubscribers.push(this.store.subscribe((i,o)=>{i.newParamId&&i.newParamId!==o.newParamId&&(this.newParamTimer&&clearTimeout(this.newParamTimer),this.newParamTimer=window.setTimeout(()=>{this.store.set({newParamId:null})},650))}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:n,invalid:i}=N(e,t.completedParams);i.length>0&&this.store.set(o=>({completedParams:n,suggestions:[...i.map(a=>({type:a.suggestionType,text:a.suggestionPlaceholder,required:!0,options:a.options})),...o.suggestions]}))}};export{_ as AIAutocomplete,L as createStore};
|
|
619
|
+
//# sourceMappingURL=index.mjs.map
|