@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.js
ADDED
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
"use strict";var k=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var oe=(i,e)=>{for(var t in e)k(i,t,{get:e[t],enumerable:!0})},ie=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of te(e))!ne.call(i,o)&&o!==t&&k(i,o,{get:()=>e[o],enumerable:!(n=ee(e,o))||n.enumerable});return i};var se=i=>ie(k({},"__esModule",{value:!0}),i);var Pe={};oe(Pe,{AIAutocomplete:()=>E,createStore:()=>A});module.exports=se(Pe);function y(i,e,t){let n=i.slice(e);if(t||e===0||i[e-1]===" ")return n;let o=n.indexOf(" ");return o===-1?"":n.slice(o+1)}function H(i,e){let t=i.trimEnd();if(t.length===0||e.length===0)return 0;let n=t.split(/\s+/),o=e.toLowerCase();for(let s=0;s<n.length;s++){let a=n.slice(s).join(" ");if(o.startsWith(a.toLowerCase())){let l=t.length-a.length;return i.length-l}}return 0}function C(i,e){if(!i)return[];let t=e.trimStart();if(!t)return i;let n=t.toLowerCase();return i.filter(o=>!o.is_tappable||o.text.toLowerCase().includes(n))}function L(i,e){if(!i)return null;let t=e.trim();if(!t)return null;let n=t.toLowerCase();return i.find(o=>o.is_tappable&&o.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 N(i,e){let t=[],n=0;for(let s of e){let a=i.indexOf(s.text,n);a!==-1&&(a>n&&t.push({type:"text",value:i.slice(n,a)}),t.push({type:"completed",value:s.text,param:s}),n=a+s.text.length)}let o=i.slice(n);return o&&t.push({type:"text",value:o}),t}function F(i,e){let t=[],n=[],o=0;for(let s of e){let a=i.indexOf(s.text,o);a===-1?n.push(s):(t.push(s),o=a+s.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 re="0.1.17",K=!1;function ae(){return crypto.randomUUID()}function le(i,e){return{placeholder:i.placeholder,type:i.type,...e&&{text:i.text},kind:i.kind}}function q(i){return i?.type==="accessToken"}function ce(i){if(!(!i||q(i)))return i}var B=new WeakMap;function pe(i){let e=B.get(i);return e||(e=new w(i),B.set(i,e)),e}function de(i,e,t){let n=e.find(s=>s.type==="contact"&&s.metadata?.contact_account_count)?.metadata?.contact_account_count,o=typeof n=="number"?n:void 0;return{data:{raw_query:i,completed_params:e.map(s=>le(s,t)),...o!=null&&{contact_account_count:o}},meta:{request_id:ae(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:re}}}function ue(i){return{"Content-Type":"application/json",...i?.appIdentifier&&{"X-App-Identifier":i.appIdentifier},...i?.headers}}async function $(i,e,t,n,o){return fetch(i,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:n,signal:o})}async function Q(i,e,t){let n=t?.apiConfig,o=!t?.maskCompletedText,s=de(i,e,o),a=ue(n),l=n?.endpoint??"/ac/suggest",r=JSON.stringify(s);if(q(n)){let g=pe(n),u=await g.getToken(),m=await $(l,a,u,r,t?.signal);if(m.status===401){let f=await g.getToken(!0);m=await $(l,a,f,r,t?.signal)}if(!m.ok)throw new Error(`API error: ${m.status} ${m.statusText}`);return m.json()}let c=ce(n),p=c?.apiKey??"";if(!p&&!K&&(K=!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(i,e){let t=i,n={},o=[];for(let s of e){let a=(n[s.type]??0)+1;n[s.type]=a;let r=`{{${s.type.toUpperCase().replace(/\s+/g,"_")}_${a}}}`,c=t.indexOf(s.text);c!==-1&&(t=t.slice(0,c)+r+t.slice(c+s.text.length)),o.push({...s,placeholder:r})}return{rawQuery:t,completedParams:o}}function U(i,e){return e?i.map(t=>{let n=e[t.type];if(!n)return t;let o=n("");if(o.length===0)return t;let s=new Set(o.map(l=>l.text)),a=(t.options??[]).filter(l=>!s.has(l.text));return{...t,options:[...o,...a]}}):i}var me=100,ge=300,he=2,T=class{constructor(e,t,n,o,s){this.store=e;this.getApiConfig=t;this.getOptionOverrides=n;this.getMaskCompletedText=o;this.getOnError=s;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 o=++this.fetchVersion,s=this.store.get(),a=s.text.length;s.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(o!==this.fetchVersion)return;let c=U(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],D=null;if(h){let x=y(g,u,m),v=L(h.options,x);v&&(D={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(Z=>Z!==h))}this.store.set(x=>({suggestions:c,isLoading:!1,isReady:r.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:u,filterInProgress:m,...D?{completedParams:[...x.completedParams,D]}:{}}))}catch(r){if(o===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 o=this.store.get();if(!o.text&&o.completedParams.length===0)return this.doFetch("",[]),!0;let s=y(o.text,o.filterBase,o.filterInProgress),l=o.suggestions.filter(h=>h.type!=="placeholder")[0],c=(l?C(l.options,s):[]).filter(h=>h.is_tappable),p=l?L(l.options,s)!==null:!1,d=s.trim().length>0;if(c.length>0&&!p&&d)return!1;let{rawQuery:g,completedParams:u}=b(o.text,o.completedParams),m=g.length<o.lastRawQuery.length,f=Math.abs(g.length-o.lastRawQuery.length);return m||f>=n?(this.doFetch(g,u),!0):!1};this.debounceTimer=setTimeout(()=>{t(he)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},me),this.slowDebounceTimer=setTimeout(()=>t(1),ge)}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:o,onSubmit:s}=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,o);else if(s){let{rawQuery:l,completedParams:r}=b(t.text,t.completedParams);s({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,o);else if(t.isDropdownOpen){let l=t.filteredOptions.findIndex(r=>r.is_tappable);l>=0&&(e.preventDefault(),this.clickOrSelect(l,t.filteredOptions,o))}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((s,a)=>s.is_tappable?a:-1).filter(s=>s!==-1),o=Array.from({length:t},()=>[]);for(let s of n)o[s%t].push(s);return o.flat()}clickOrSelect(e,t,n){let o=document.getElementById(`${n}-option-${e}`);o?o.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 o=n[e],s=n.filter((l,r)=>r!==e),a=t.suggestions.filter(l=>l.type==="placeholder");this.store.set({suggestions:[...a,o,...s],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 o=n[e],s=n.filter((l,r)=>r!==e),a=t.suggestions.filter(l=>l.type==="placeholder");this.store.set({suggestions:[...a,o,...s],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(o=>({completedParams:o.completedParams.slice(0,-1),suggestions:[n,...o.suggestions],activeDropdownIndex:-1}))}};function fe(i){return i===0?.4:i===1?.3:.15}function I(i,e,t,n,o=!1){let s=i.querySelector(".magicx-ac-pill-list");s||(s=document.createElement("span"),s.className="magicx-ac-pill-list",i.appendChild(s));let a=new Map;for(let r of s.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${o?" magicx-ac-pill--rounded":""}${r===t?" magicx-ac-pill--active":""}`,d.style.opacity=String(fe(r)),d.onclick=()=>n(r),s.children[r]!==d&&s.insertBefore(d,s.children[r]??null)}for(let[r,c]of a)l.has(r)||c.remove()}function V(i){let e=document.createElement("div");return e.id=i,e.setAttribute("role","listbox"),e.setAttribute("data-ac-dropdown",""),e.className="magicx-ac-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function z(i,e){let{filteredOptions:t,activeIndex:n,isOpen:o,pills:s,showPills:a,onSelect:l,onHighlight:r,onPillClick:c}=e,p=a&&s.length>0;o&&t.length>0||o&&p?i.classList.add("magicx-ac-dropdown--visible"):i.classList.remove("magicx-ac-dropdown--visible");let u=i.querySelector(".magicx-ac-pill-bar");p?(u||(u=document.createElement("div"),u.className="magicx-ac-pill-bar",i.insertBefore(u,i.firstChild)),I(u,s,0,c,!0)):u&&u.remove();let m=i.querySelector(".magicx-ac-grid");t.length>0?(m||(m=document.createElement("div"),m.className="magicx-ac-grid",i.appendChild(m)),xe(m,t,n,l,r,e.listboxId)):m&&(m.innerHTML="")}var j="";function xe(i,e,t,n,o,s){let a=e.map(r=>r.text).join("\0"),l=a!==j;if(j=a,l){let r=document.createDocumentFragment();for(let c=0;c<e.length;c++){let p=e[c],d=be(p,c,t,n,o,s);r.appendChild(d)}i.innerHTML="",i.appendChild(r)}else{let r=i.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 be(i,e,t,n,o,s){let a=document.createElement("div");a.id=`${s}-option-${e}`,a.setAttribute("role","option"),a.setAttribute("aria-selected",String(e===t)),a.tabIndex=i.is_tappable?0:-1;let l=["magicx-ac-option"];e===t&&l.push("magicx-ac-option--highlighted"),i.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=i.icon?`${i.icon} ${i.text}`:i.text,i.tag){let d=document.createElement("span");d.className="magicx-ac-option-tag",d.textContent=i.tag,p.appendChild(d)}return a.appendChild(p),i.is_tappable&&a.addEventListener("click",()=>{a.classList.add("magicx-ac-option--pressed"),n(i),setTimeout(()=>a.classList.remove("magicx-ac-option--pressed"),400)}),a.addEventListener("mouseenter",()=>o(e)),a}var M="",W=null;function G(i,e,t,n,o){let s=i.querySelector(".magicx-ac-sizer-text"),a=i.querySelector(".magicx-ac-placeholder");if(n&&o){s&&(s.style.display="none"),a||(a=document.createElement("span"),a.className="magicx-ac-placeholder",i.insertBefore(a,i.firstChild)),a.style.display="",a.textContent=`${o} `,M="";return}a&&(a.style.display="none"),s||(s=document.createElement("span"),s.className="magicx-ac-sizer-text",i.insertBefore(s,i.firstChild)),s.style.display="",s.className=`magicx-ac-sizer-text${t?" magicx-ac-sizer-text--visible":""}`;let l=e.map(r=>`${r.type}:${r.value}`).join("\0");if(!(l===M&&t===W)){M=l,W=t,s.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,s.appendChild(c)}e.length===0&&(s.textContent="\xA0")}}var ye='<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 X(i,e){let{listboxId:t}=e,n=V(t);i.appendChild(n);let o=document.createElement("div");o.className="magicx-ac-input-wrapper",i.appendChild(o);let s=document.createElement("div");s.className="magicx-ac-editor",o.appendChild(s);let a=document.createElement("div");a.className="magicx-ac-sizer",a.setAttribute("aria-hidden","true"),s.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),s.appendChild(r);let c=document.createElement("button");return c.type="button",c.className="magicx-ac-submit",c.setAttribute("aria-label","Submit"),c.innerHTML=ye,o.appendChild(c),o.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 _(i,e,t){let{textarea:n,dropdown:o,sizer:s,submitButton:a,inlinePillContainer:l}=i,{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,G(s,e.segments,e.newParamId,!e.text,e.placeholderText),r==="inline"?I(l,e.actionableSuggestions,0,c):l.innerHTML="",z(o,{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 A(i){let e=i,t=new Set;return{get:()=>e,set:n=>{let o=typeof n=="function"?n(e):n,s={...e,...o},a=e;e=s;for(let l of t)l(s,a)},subscribe:n=>(t.add(n),()=>{t.delete(n)})}}var R=!1;function Y(){if(R||typeof document>"u")return;if(document.querySelector("style[data-magicx-ac]")){R=!0;return}R=!0;let i=document.createElement("style");i.setAttribute("data-magicx-ac",""),i.textContent=Se,document.head.appendChild(i)}var Se=`/* ===================================================================
|
|
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 ve=0;function Ce(){return`:ac-${++ve}:`}function J(){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 E=class{constructor(e,t={}){this.store=A(J());this.listboxId=Ce();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,o)=>{this.recomputeDerived(n,o)})),this.unsubscribers.push(this.store.subscribe((n,o)=>{n.text!==o.text&&this.opts.onChange?.(n.text),n.completedParams!==o.completedParams&&this.opts.onParamsChange?.(n.completedParams),this.opts.onStateChange?.(n)})),Y(),this.setupContainer(),this.buildAndRender(),this.fetchController.start()}focus(){this.domRefs?.textarea.focus()}reset(){this.store.set({...J()}),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 o=t.filterBase,s=t.text.slice(0,o),a=s.length===0&&t.text.length===0;a&&t.placeholderText&&(s=`${t.placeholderText} `);let l=H(s,e.text);l>0&&(s=s.slice(0,s.length-l));let r=s.length>0&&s[s.length-1]!==" ",c=`${s}${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=N(e.text,e.completedParams),o=e.suggestions.filter(u=>u.type!=="placeholder"),s=o[0],a=s?this.opts.optionOverrides?.[s.type]:void 0,l=y(e.text,e.filterBase,e.filterInProgress),r=s?a?a(l.trim()):s.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:o,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:o=>this.selectOption(o),setActivePill:o=>this.pillsController.setActivePill(o),handleKeyDown:o=>this.keyboardController.handleKeyDown(o),handleChange:o=>this.handleChange(o)},t=this;this.domRefs=X(this.container,e);let n=!1;this.unsubscribers.push(this.store.subscribe(()=>{n||(n=!0,queueMicrotask(()=>{n=!1,this.domRefs&&_(this.domRefs,this.store.get(),e)}))})),_(this.domRefs,this.store.get(),e),this.unsubscribers.push(this.store.subscribe((o,s)=>{o.newParamId&&o.newParamId!==s.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:o}=F(e,t.completedParams);o.length>0&&this.store.set(s=>({completedParams:n,suggestions:[...o.map(a=>({type:a.suggestionType,text:a.suggestionPlaceholder,required:!0,options:a.options})),...s.suggestions]}))}};0&&(module.exports={AIAutocomplete,createStore});
|
|
619
|
+
//# sourceMappingURL=index.js.map
|