@dori-ai/dori-side-widget 1.13.204 → 1.13.205

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.
@@ -0,0 +1 @@
1
+ const t="dori-ask-button";function e(t,e){const i=(t||"").trim().slice(0,30);return i?{label:i,aria:i}:{label:null,aria:(e||"").trim()||"Ask"}}function i(e,i){const n=Boolean(e.label),a=n?Math.max(32,Math.min(38,e.boxHeight)):Math.max(32,Math.min(44,e.boxHeight));"undefined"==typeof customElements||customElements.get(t)||customElements.define(t,class extends HTMLElement{});const r=document.createElement(t);r.style.cssText=`display:inline-flex;align-items:center;flex:0 0 auto;height:${Math.max(a,e.boxHeight)}px;margin:0;padding:0;border:0;background:none;box-shadow:none;float:none;min-width:0;max-width:none;width:auto;vertical-align:middle;position:relative;z-index:1;color:${e.color};`;const o=r.attachShadow({mode:"open",delegatesFocus:!0}),l=Math.max(12,Math.min(15,e.fontSize||14)),s=e.light?500:600,c=e.light?"1px":"1.5px";o.innerHTML=`<style>button{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:7px;height:${a}px;width:${n?"auto":`${a}px`};padding:${n?"0 14px 0 12px":"0"};border-radius:999px;cursor:pointer;color:inherit;font:inherit;font-size:${l}px;font-weight:${s};line-height:1.2;white-space:nowrap;border:${c} solid ${n?"currentColor":"transparent"}}button:hover{background:rgba(127,127,127,.12)}button:focus-visible{outline:2px solid currentColor;outline-offset:2px}svg{width:${e.iconSize}px;height:${e.iconSize}px;flex:0 0 auto}</style><button type="button"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M12 3.5l1.9 5.1 5.1 1.9-5.1 1.9L12 17.5l-1.9-5.1L5 10.5l5.1-1.9z"/><path d="M18.5 15.5l.8 2 2 .8-2 .8-.8 2-.8-2-2-.8 2-.8z"/></svg></button>`;const u=o.querySelector("button");if(u.setAttribute("aria-label",e.aria),e.label){const t=document.createElement("span");t.textContent=e.label,u.appendChild(t)}return u.addEventListener("click",i),r}const n=()=>({w:window.innerWidth,h:window.innerHeight}),a=t=>t.getBoundingClientRect();function r(t,e=n()){if(!t)return!1;const i=a(t);if(i.width<6||i.height<6||i.right<=0||i.left>=e.w||i.bottom<=0)return!1;const r=t;if(r.checkVisibility&&!r.checkVisibility({contentVisibilityAuto:!0,opacityProperty:!0,visibilityProperty:!0}))return!1;const o=getComputedStyle(t);return"hidden"!==o.visibility&&"none"!==o.display&&parseFloat(o.opacity)>=.05}function o(t){const e=a(t);if(e.width<2||e.height<2)return!1;const i=t;return!i.checkVisibility||i.checkVisibility({visibilityProperty:!0})}const l=['input[type="search"]','input[name="q"]','a[href$="/search"]','a[href*="/search?"]','button[aria-label*="search" i]','a[aria-label*="search" i]','summary[aria-label*="search" i]','[aria-controls*="search" i]',"details-modal.header__search summary","predictive-search","search-button",'[class*="search-toggle" i]','[class*="search-icon" i]','[class*="header__search" i]','[data-action*="search" i]'].join(","),s=['a[href$="/cart"]','a[href*="/cart?"]',"#cart-icon-bubble","[data-cart-toggle]","[data-cart-trigger]","[data-open-cart]",'[data-drawer-toggle*="cart" i]','[aria-controls*="cart" i]','button[aria-label*="cart" i]','a[aria-label*="cart" i]','button[aria-label*="bag" i]','a[aria-label*="bag" i]','[class*="cart-icon" i]','[class*="header__cart" i]',"cart-icon","cart-drawer-component button"].join(","),c=['[aria-label*="menu" i]','summary[aria-controls*="menu" i]','[class*="menu-drawer" i] summary','[class*="hamburger" i]','[class*="burger" i]','[data-drawer-toggle*="menu" i]','button[aria-controls*="menu" i]','[class*="menu-toggle" i]','[class*="nav-toggle" i]',"header-drawer summary"].join(","),u=t=>Math.min(300,.4*t.h),d=(t,e)=>r(t,e)&&a(t).top<u(e)&&!t.closest('[role="dialog"], [aria-modal="true"]'),h=(t,e)=>{const i=t.closest("a, button, summary");return i&&r(i,e)&&a(i).width<220?i:t};function m(t=n()){const e=[...document.querySelectorAll(l)].filter(e=>d(e,t)),i=[...document.querySelectorAll(s)].filter(e=>d(e,t));if(!e.length&&!i.length)return null;let o=null,m=!1;const g=e.find(t=>"INPUT"===t.tagName&&a(t).width>120);if(g){m=!0;let t=g.closest("form")||g.parentElement||g;for(let e=0;e<3&&t.parentElement&&a(t.parentElement).width<a(g).width+140;e++)t=t.parentElement;o=t}else if(e.length){const i=e.map(e=>h(e,t)).filter(e=>r(e,t)&&a(e).width<200&&a(e).height<90);i.sort((t,e)=>a(e).right-a(t).right),o=i[0]||null}let b=null;if(i.length){const e=i.map(e=>h(e,t)).filter(t=>a(t).width<260&&a(t).height<130);e.sort((t,e)=>a(e).right-a(t).right),b=e[0]||null}const p=[...document.querySelectorAll(c)].filter(e=>d(e,t)&&a(e).width<120).map(e=>h(e,t)),f="rtl"===getComputedStyle(document.documentElement).direction;p.sort((t,e)=>f?a(e).right-a(t).right:a(t).left-a(e).left);const y=p.find(e=>f?a(e).right>.65*t.w:a(e).left<.35*t.w)||null,w=o||b;let x=w.parentElement||w;for(let n=w.parentElement;n&&n!==document.body;n=n.parentElement){const e=a(n);if(e.top>u(t)||e.height>360)break;e.width>=.6*t.w&&(x=n)}return{search:o,isBar:m,cart:b,menu:y,header:x,rtl:f||"rtl"===getComputedStyle(x).direction}}function g(t){let e=t;for(let i=0;i<6;i++){const t=e.parentElement;if(!t||t===document.body||"HEADER"===t.tagName)break;if([...t.children].some(t=>t!==e&&r(t)))break;e=t}return e}function b(t){return[...t.querySelectorAll("svg, img")].find(t=>r(t))||t}function p(t){const e=getComputedStyle(t);return!(/grid/.test(e.display)||/flex/.test(e.display)&&/space-(between|around|evenly)/.test(e.justifyContent))}export{t as A,l as S,o as a,b,i as c,e as d,m as f,r as i,p,a as r,g as s,n as v};
@@ -0,0 +1 @@
1
+ import{A as e,c as t,f as n,p as i}from"../widget.js";import{r,S as s,U as o}from"./store-font-B5B6CNk6.js";import{A as a,S as l}from"./anchors-5BHu2BdH.js";function c(e,t){t.buffer+=e.replace(/\r\n?/g,"\n");const n=[];let i=t.buffer.indexOf("\n\n");for(;-1!==i;){const e=t.buffer.slice(0,i);t.buffer=t.buffer.slice(i+2);let r="message";const s=[];for(const t of e.split("\n"))t.startsWith("event:")?r=t.slice(6).trim():t.startsWith("data:")&&s.push(t.slice(5).replace(/^ /,""));s.length&&n.push({event:r,data:s.join("\n")}),i=t.buffer.indexOf("\n\n")}return n}const d=(e=window)=>e.Shopify?.routes?.root||"/";class p extends Error{constructor(e){super(`AI search unavailable (${e})`),this.status=e}}const h=t=>`${e}/ai-search/${encodeURIComponent(t)}`;let u=null;const f=e=>{u=e},g=()=>u?{"X-Dori-Preview":u}:{};async function m(e,t,n,i,r){const s=new URLSearchParams({q:t,mode:n});i.currency&&s.set("currency",i.currency),i.country&&s.set("country",i.country);const o=await fetch(`${h(e)}/suggest?${s}`,{signal:r,headers:g()});if(!o.ok)throw new p(o.status);return(await o.json()).products??[]}async function x(e,t,n){try{const i=t.endsWith("/")?t:`${t}/`,r=new URLSearchParams({q:e,"resources[type]":"collection","resources[limit]":"2"}),s=await fetch(`${i}search/suggest.json?${r}`,{signal:n});if(!s.ok)return[];const o=await s.json();return(o.resources?.results?.collections??[]).filter(e=>!!e.title&&!!e.url).map(e=>({title:e.title,url:e.url}))}catch{return[]}}const y="What are you looking for?",v="Cancel",w="AI search",b="Search all products",k="Preview: only you see AI search",$=new Set(["results","answer","not_found","fallback"]),q="dori-ai-search",S='header, [role="banner"], [id*="header" i], [class*="header" i]';function A(e,t){if(null==e)return!1;try{const n=new URL(e||"/",t);return n.origin===t&&/\/search\/?$/.test(n.pathname)}catch{return!1}}const M=e=>e.checkVisibility?e.checkVisibility({visibilityProperty:!0,opacityProperty:!0}):e.getClientRects().length>0;const z=e=>String(e??"").replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[e])),P=(e=!1,t=18)=>`<svg class="spark${e?" live":""}" width="${t}" height="${t}" viewBox="0 0 24 24" aria-hidden="true"><path class="s1" d="M10 4Q11.76 10.24 18 12Q11.76 13.76 10 20Q8.24 13.76 2 12Q8.24 10.24 10 4Z" fill="currentColor"/><path class="s2" d="M19 1.5Q19.77 4.23 22.5 5Q19.77 5.77 19 8.5Q18.23 5.77 15.5 5Q18.23 4.23 19 1.5Z" fill="currentColor"/></svg>`;function L(e,t,n){if(null==e||!Number.isFinite(e))return"";const i=(t||n.currency||"").split(" ")[0].toUpperCase(),r=Number.isInteger(e)?0:2;try{if(i)return new Intl.NumberFormat(n.locale||void 0,{style:"currency",currency:i,minimumFractionDigits:r,maximumFractionDigits:2}).format(e)}catch{}return`${e.toFixed(r)}${i?` ${i}`:""}`}function E(e,t){if(!e)return"#";if(/^https?:\/\//.test(e))return e;if(e.startsWith("//"))return"#";const n=e.startsWith("/")?e:`/${e}`,i=t.root.endsWith("/")?t.root:`${t.root}/`;return"/"===i?n:`${i.slice(0,-1)}${n}`}const C=(e,t)=>E(`/search?q=${encodeURIComponent(e)}&options%5Bprefix%5D=last`,t);function j(e,t){return e?/cdn\.shopify\.com|\/cdn\/shop\//.test(e)?`${e}${e.includes("?")?"&":"?"}width=${t}`:e:""}function F(e,t){const n=L(e.price,e.currency,t),i=e.price_unit?` / ${z(e.price_unit)}`:"",r=e.compare_at?` <s>${z(L(e.compare_at,e.currency,t))}</s>`:"";return`${z(n)}${i}${r}`}const R=(e,t)=>`<div class="grid">${e.map(e=>function(e,t){const n=e.image?`<img src="${z(j(e.image,400))}" alt="" loading="lazy">`:"";return`<a class="card" href="${z(E(e.url,t))}" data-id="${z(e.id)}"><div class="ph">${n}</div>`+(e.brand?`<div class="br">${z(e.brand)}</div>`:"")+`<div class="nm">${z(e.name)}</div><div class="pr">${F(e,t)}${e.sold_out?'<span class="so">Sold out</span>':""}</div></a>`}(e,t)).join("")}</div>`;function _(e){return`<a class="colrow" href="${z((t=e.url,t&&(/^https?:\/\//.test(t)||t.startsWith("/")&&!t.startsWith("//"))?t:"#"))}">${z(e.title)}</a>`;var t}const I=(e,t)=>`<div class="stp${t?" done":""}"><span class="ic">${t?'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12.5 4.5 4.5L19 7.5"/></svg>':""}</span><span class="tx">${z(e)}</span></div>`;function N(e,t,n){return null!=e.cursor?`<div class="loader">${t.loadingMore?'<span class="spin"></span>':""}</div>`:`<div class="end"><a class="more" href="${z(C(t.asked,n))}">${b}</a></div>`}function O(e,t,n,i){return`<div class="empty"><h2>${z(e)}</h2><a class="more" href="${z(C(t.asked,n))}">${b}</a></div>`+(i.length?`<div class="popular"><div class="sech">Popular right now</div>${R(i,n)}</div>`:"")}function T(e,t){return"typing"===e.phase?function(e,t){const n=e.q.trim();if(!n)return"";const i=e=>e===n||n.startsWith(e),r=i(e.collectionsFor)?e.collections.slice(0,2):[],s=i(e.suggestedFor)?e.suggestions.slice(0,4):[];return function(e){return`<button class="airow" data-act="enter">${P()}<span class="lab">${w}</span><span class="q">“${z(e)}”</span><span class="key"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 5v7a3 3 0 0 1-3 3H6"/><path d="m10 11-4 4 4 4"/></svg></span></button>`}(n)+(r.length?`<div class="sech">Collections</div><div class="rows">${r.map(_).join("")}</div>`:"")+(s.length?`<div class="sech">Products</div><div class="rows">${s.map((e,n)=>function(e,t,n){const i=e.image?`<img src="${z(j(e.image,120))}" alt="" loading="lazy">`:'<span class="noimg"></span>';return`<a class="row" href="${z(E(e.url,t))}" data-id="${z(e.id)}" data-i="${n}">${i}<span class="meta"><span class="nm">${z(e.name)}</span><span class="pr">${F(e,t)}</span></span></a>`}(e,t,n)).join("")}</div>`:"")}(e,t):"working"!==e.phase&&e.result?function(e,t){const n=e.result;switch(n.type){case"results":{const s=n.chips.length?`<div class="chips">${n.chips.map(e=>`<button class="chip" data-drop="${z(e.key)}" aria-label="Remove">${z(function(e,t){if("price"===e.kind){const n=e.min?L(e.min,e.currency,t):"",i=e.max?L(e.max,e.currency,t):"";return n&&i?`${n} to ${i}`:i?`Under ${i}`:`From ${n}`}return e.value??""}(e,t))}<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18"/></svg></button>`).join("")}</div>`:"",o=n.note?.currency||t.currency;return s+(n.note?`<div class="note">${z((i=L(n.note.under,o,t),r=null!=n.note.from?L(n.note.from,o,t):null,r?`Nothing under ${i}. Closest from ${r}`:`Nothing under ${i}`))}</div>`:"")+R(n.products,t)+N(n,e,t)}case"fallback":return n.products.length?R(n.products,t)+N(n,e,t):O(`Nothing found for “${e.asked}”`,e,t,[]);case"not_found":return O(`No ${n.noun} found`,e,t,n.popular);case"answer":{if("none"===n.kind)return O("No answer in the store's help pages",e,t,[]);const i=n.text&&"entry"!==n.kind?`<div class="ansh">${P(!1,13)}Answer</div><p class="anst">${z(n.text)}</p>`:"";return`<div class="ans">${i}<div class="src${i?"":" alone"}"><div class="sech">${"page"===n.entry.source?"From the store's pages":"From the store's FAQ"}</div><div class="fq">${z(n.entry.question)}</div><div class="fa">${z(n.entry.answer)}</div></div></div>`}}var i,r}(e,t):function(e){const t=`<div class="aih">${P(!0)}<span class="shim">${w}</span></div>`,n=e.plan?[I(e.plan.label,!0),I("faq"===e.plan.kind?"Checking the store's help pages":(s=e.plan.products,s?`Searching ${s.toLocaleString()} products`:"Searching the products"),!1)]:[I((r=e.asked,`Reading “${r}”`),!1)],i="faq"===e.plan?.kind?'<div class="ans"><span class="skl sk" style="width:92%"></span><span class="skl sk" style="width:70%"></span></div>':`<div class="grid">${Array.from({length:4},()=>'<div class="card skel"><div class="ph"></div><span class="skl sk" style="width:80%"></span><span class="skl sk" style="width:40%"></span></div>').join("")}</div>`;var r,s;return`<div class="aib">${t}<div class="stps">${n.join("")}</div></div>${i}`}(e)}const U="dori-ai-search-last";let D=null;class B{constructor(e){this.config=e,this.state=((e="")=>({q:e,phase:"typing",suggestions:[],collections:[],suggestedFor:"",collectionsFor:"",asked:"",rid:null,drop:[],plan:null,result:null,loadingMore:!1}))(),this.shopper=function(e=window){const t=e.Shopify;return{currency:t?.currency?.active||void 0,country:t?.country||void 0,language:t?.locale||document.documentElement.lang||void 0}}(),this.ctx={locale:navigator.language||"en",currency:this.shopper.currency||"",root:d()},this.host=document.createElement("div"),this.host.id=q,this.host.style.setProperty("display","block","important");const t=this.host.attachShadow({mode:"open"}),n=getComputedStyle(document.body).color||"#111",i=r(document.body);i&&this.host.style.setProperty(s,i),this.host.style.fontFamily=o,t.innerHTML=`<style>\n:host{all:initial}\n*{box-sizing:border-box}\n.wrap{position:fixed;inset:0;z-index:2147483647;color:var(--ink,#111);font-size:14px;line-height:1.35;-webkit-font-smoothing:antialiased}\n.scrim{position:absolute;inset:0;background:rgba(0,0,0,.32);animation:fadein .16s ease both}\n.panel{position:absolute;inset:0;background:#fff;display:flex;flex-direction:column;animation:fadein .16s ease both}\na{color:inherit;text-decoration:none}\nbutton{font:inherit;color:inherit}\n.sbar{display:flex;align-items:center;gap:10px;padding:10px 14px;border-bottom:1px solid var(--line)}\n.field{flex:1;display:flex;align-items:center;gap:8px;height:44px;border-radius:8px;background:#f5f5f5;padding:0 12px;border:1px solid #e6e6e6;min-width:0}\n.field svg{flex:none;color:#777}\n.field input{flex:1;min-width:0;border:0;outline:0;background:none;font:inherit;font-size:16px;color:var(--ink);-webkit-appearance:none;appearance:none}\n.field input::-webkit-search-cancel-button{display:none}\n.cancel{border:0;background:none;font-size:15px;cursor:pointer;padding:6px 2px}\n.cancel .x{display:none}\n.pv{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:8px 14px;font-size:13px;line-height:1.3;background:#fff6d6;color:#4d3b00;border-bottom:1px solid #f0e2a8}\n.pv a{flex:none;text-decoration:underline;white-space:nowrap}\n.body{flex:1;overflow-y:auto;overscroll-behavior:contain;min-height:120px}\n.body:empty{min-height:0}\n.spark{flex:none;display:block}\n.spark.live .s1{transform-origin:10px 12px;animation:pulse 1.3s ease-in-out infinite}\n.spark.live .s2{transform-origin:19px 5px;animation:twinkle 1.3s ease-in-out infinite}\n@keyframes pulse{50%{transform:scale(.76)}}\n@keyframes twinkle{0%,100%{opacity:.2;transform:scale(.55)}50%{opacity:1;transform:scale(1)}}\n.airow{display:flex;align-items:center;gap:10px;width:calc(100% - 24px);margin:10px 12px 2px;padding:12px;border:0;border-radius:12px;background:var(--ai);cursor:pointer;text-align:left;transition:transform .12s ease}\n.airow:active{transform:scale(.975)}\n.airow .lab{font-weight:600;white-space:nowrap;font-size:15px}\n.airow .q{min-width:0;flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:#5c5c5c;font-size:15px}\n.airow .key{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:24px;border-radius:7px;background:#fff;border:1px solid var(--line);color:#555}\n.sech{font-weight:600;font-size:11px;line-height:1;letter-spacing:.12em;text-transform:uppercase;color:#777;margin:16px 14px 6px}\n.rows{display:flex;flex-direction:column}\n.row{display:flex;align-items:center;gap:12px;padding:7px 14px}\n.row img,.row .noimg{width:46px;height:46px;object-fit:contain;background:#f6f6f6;border-radius:6px;flex:none}\n.row .meta{min-width:0;flex:1;display:flex;flex-direction:column}\n.row .nm{font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.row .pr{font-size:13px;color:#555;margin-top:2px}\n.colrow{display:block;padding:8px 14px;font-size:14px}\n.aib{padding:16px 16px 0}\n.aih{display:flex;align-items:center;gap:8px;font-weight:600;font-size:15.5px}\n.shim{background:linear-gradient(90deg,var(--ink) 0%,var(--ink) 38%,#c4c4c4 50%,var(--ink) 62%,var(--ink) 100%);background-size:260% 100%;-webkit-background-clip:text;background-clip:text;color:transparent;animation:shim 1.7s linear infinite}\n@keyframes shim{from{background-position:100% 0}to{background-position:-160% 0}}\n.stps{margin:10px 0 0 1px;display:flex;flex-direction:column;gap:8px}\n.stp{display:flex;align-items:center;gap:9px;font-size:14px;color:#6b6b6b;animation:fadein .24s ease both}\n.stp .ic{width:15px;height:15px;flex:none;border-radius:50%;border:1.7px solid #d2d2d2;border-top-color:var(--ink);animation:spin .8s linear infinite;display:flex;align-items:center;justify-content:center}\n.stp.done{color:var(--ink)}\n.stp.done .ic{border:0;animation:none}\n.stp .tx{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n@keyframes spin{to{transform:rotate(360deg)}}\n.chips{display:flex;flex-wrap:wrap;gap:6px;padding:10px 14px 0}\n.chip{display:inline-flex;align-items:center;gap:7px;font-size:13px;border:1px solid var(--ink);border-radius:999px;padding:5px 11px;cursor:pointer;background:#fff}\n.note{margin:10px 14px 0;font-size:13px;color:#6b6b6b}\n.grid{display:grid;grid-template-columns:1fr 1fr;gap:18px 10px;padding:14px 14px 20px}\n.card{min-width:0;display:block}\n.card .ph{aspect-ratio:1/1;background:#f6f6f6;border-radius:6px;overflow:hidden}\n.card .ph img{width:100%;height:100%;object-fit:contain;display:block}\n.card .br{font-size:10.5px;font-weight:500;line-height:1.2;letter-spacing:.12em;text-transform:uppercase;color:#777;margin-top:8px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.card .nm{font-size:13.5px;line-height:1.3;margin-top:3px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}\n.card .pr{font-size:13.5px;margin-top:4px}\n.card .pr s,.row .pr s{color:#8a8a8a;margin-left:4px}\n.card .so{font-size:11px;color:#a33;margin-left:6px}\n.card.skel .ph,.sk{background:linear-gradient(90deg,#f3f3f3,#e9e9e9,#f3f3f3);background-size:200% 100%;animation:sh 1.2s linear infinite}\n.skl{display:block;height:10px;border-radius:5px;margin-top:9px}\n@keyframes sh{to{background-position:-200% 0}}\n.ans{padding:18px 16px 24px}\n.ansh{display:flex;align-items:center;gap:6px;font-weight:600;font-size:11px;line-height:1;letter-spacing:.12em;text-transform:uppercase;color:#777}\n.anst{margin:10px 0 0;font-size:16.5px;line-height:1.5}\n.src{margin-top:20px;border-top:1px solid var(--line);padding-top:16px}\n.src.alone{margin-top:0;border-top:0;padding-top:0}\n.src .sech{margin:0 0 9px}\n.src .fq{font-weight:500;font-size:15px;line-height:1.3}\n.src .fa{margin-top:6px;font-size:13.5px;line-height:1.5;color:#555;white-space:pre-line}\n.empty{padding:36px 20px 20px;text-align:center}\n.empty h2{margin:0;font-weight:500;font-size:21px;line-height:1.25}\n.more{display:inline-block;margin-top:12px;font-size:13.5px;color:#6b6b6b;text-decoration:underline}\n.end{text-align:center;padding:0 14px 28px}\n.loader{display:flex;justify-content:center;padding:4px 0 28px;min-height:40px}\n.spin{width:18px;height:18px;border-radius:50%;border:2px solid #ddd;border-top-color:var(--ink);animation:spin .8s linear infinite}\n.popular{border-top:1px solid var(--line);margin:6px 14px 0;padding-top:14px}\n.popular .sech{margin:0 0 2px}\n.popular .grid{padding:12px 0 28px}\n@keyframes fadein{from{opacity:0}to{opacity:1}}\n@media (min-width:750px){\n .scrim{background:rgba(0,0,0,.18)}\n .panel{inset:auto;top:var(--top,16px);left:var(--left,16px);width:var(--w,min(760px,100vw - 32px));max-height:calc(100vh - var(--top,16px) - 16px);border-radius:12px;overflow:hidden;box-shadow:0 0 0 1px rgba(0,0,0,.06),0 14px 40px rgba(0,0,0,.16);animation:drop .14s ease-out both}\n .sbar{height:56px;padding:0 8px 0 16px;gap:6px;border-bottom:0}\n .field{height:56px;padding:0;gap:10px;border:0;border-radius:0;background:none}\n .body:not(:empty){border-top:1px solid var(--line)}\n .pv{padding:8px 16px}\n .pv + .body:not(:empty){border-top:0}\n .cancel{display:flex;align-items:center;justify-content:center;width:36px;height:36px;padding:0;border-radius:8px;color:#6b6b6b}\n .cancel:hover{background:#f2f2f2;color:var(--ink)}\n .cancel .t{display:none}\n .cancel .x{display:block}\n .grid{grid-template-columns:repeat(4,minmax(0,1fr))}\n .narrow .grid{grid-template-columns:repeat(3,minmax(0,1fr))}\n}\n@keyframes drop{from{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:none}}\n@media (prefers-reduced-motion:reduce){*{animation:none!important;transition:none!important}}\n</style><div class="wrap" style="--ink:${n};--ai:color-mix(in srgb, ${n} 6%, #fff);--line:#eaeaea" hidden><div class="scrim"></div><div class="panel" role="dialog" aria-modal="true" aria-label="${w}"><form class="sbar" role="search"><label class="field"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/></svg><input type="search" enterkeyhint="search" autocomplete="off" autocapitalize="off" spellcheck="false" placeholder="${y}"></label><button type="button" class="cancel" aria-label="${v}"><span class="t">${v}</span><svg class="x" width="18" height="18" viewBox="0 0 18 18" aria-hidden="true"><path d="M4.5 4.5l9 9M13.5 4.5l-9 9" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg></button></form>`+(e.preview?`<div class="pv"><span>${k}</span><a class="pvl" target="_blank" rel="noopener">Your usual results</a></div>`:"")+'<div class="body"></div></div></div>',this.input=t.querySelector("input"),this.setPlaceholder(e.placeholder),this.body=t.querySelector(".body"),this.syncPreviewBar(),t.querySelector("form").addEventListener("submit",e=>{e.preventDefault(),this.search()}),this.input.addEventListener("input",()=>this.typed()),t.querySelector(".cancel").addEventListener("click",()=>this.close()),t.querySelector(".scrim").addEventListener("click",()=>this.close()),this.body.addEventListener("click",e=>this.clicked(e)),this.body.addEventListener("scroll",()=>this.scrolled(),{passive:!0}),window.addEventListener("popstate",this.onPop),window.addEventListener("resize",this.onResize,{passive:!0}),document.addEventListener("keydown",this.onKey,!0),document.documentElement.appendChild(this.host)}host;input;body;state;ctx;shopper;timers=[];suggestAbort=null;searchAbort=null;moreAbort=null;pausedFor="";isOpen=!1;pushed=!1;overflow="";started=0;anchor=null;notice=null;setPlaceholder(e){this.input.placeholder=e?.trim()||y}get tag(){return this.config.preview?{preview:!0}:{}}get wrap(){return this.host.shadowRoot.querySelector(".wrap")}place(){const e=this.host.shadowRoot.querySelector(".panel");if(!window.matchMedia("(min-width: 750px)").matches)return e.removeAttribute("style"),void e.classList.remove("narrow");let t=this.anchor&&this.anchor.isConnected?this.anchor:null,n=t?.getBoundingClientRect();(!n||n.width<=0)&&(t=function(){for(const e of document.querySelectorAll(l)){if(e.closest(`#${q}`))continue;const t=e.getBoundingClientRect();if(t.width>0&&t.height>0&&t.top<window.innerHeight/3)return e}return null}(),n=t?.getBoundingClientRect());const i=function(e,t,n){const i=t-32;if(!e||e.width<=0||e.height<=0){const e=Math.min(760,i);return{top:16,left:Math.round((t-e)/2),width:e}}const r=e.width>=240,s=Math.round(Math.min(i,r?Math.max(e.width+16,560):760)),o=r?e.left-8:(t-s)/2,a=e.top+e.height/2-28;return{top:Math.round(Math.min(Math.max(a,8),Math.max(8,n-240))),left:Math.round(Math.min(Math.max(o,16),t-16-s)),width:s}}(n??null,window.innerWidth,window.innerHeight);e.style.setProperty("--top",`${i.top}px`),e.style.setProperty("--left",`${i.left}px`),e.style.setProperty("--w",`${i.width}px`),e.classList.toggle("narrow",i.width<860)}onResize=()=>{this.isOpen&&this.place()};open(e,n,i=null){if(!this.isOpen){this.isOpen=!0,this.anchor=i,this.wrap.hidden=!1,this.overflow=document.documentElement.style.overflow,document.documentElement.style.overflow="hidden",this.place();try{history.pushState({...history.state||{},doriAiSearch:!0},""),this.pushed=!0}catch{this.pushed=!1}t("ai_search_open",{run:n,...this.tag})}e&&e!==this.input.value&&(this.input.value=e,this.typed()),n||this.input.focus(),n&&e.trim()&&this.search()}restore(e){this.isOpen=!0;try{history.replaceState({...history.state||{},doriAiSearch:!1},""),history.pushState({...history.state||{},doriAiSearch:!0},""),this.pushed=!0}catch{this.pushed=!1}this.wrap.hidden=!1,this.overflow=document.documentElement.style.overflow,document.documentElement.style.overflow="hidden",this.anchor=null,this.place(),this.input.value=e.q,this.dispatch({type:"restore",q:e.q,rid:e.rid,result:e.result,drop:e.drop})}close(e=!1){this.isOpen&&(this.isOpen=!1,this.cancelAll(),this.wrap.hidden=!0,document.documentElement.style.overflow=this.overflow,this.pushed&&!e&&history.state?.doriAiSearch&&(this.pushed=!1,history.back()),this.pushed=!1)}destroy(){this.close(),window.removeEventListener("popstate",this.onPop),window.removeEventListener("resize",this.onResize),document.removeEventListener("keydown",this.onKey,!0),this.host.remove()}onKey=e=>{this.isOpen&&"Escape"===e.key&&(e.stopPropagation(),this.close())};onPop=()=>{this.isOpen&&!history.state?.doriAiSearch&&this.close(!0)};syncPreviewBar(){const e=this.host.shadowRoot,t=e.querySelector(".pvl");if(!t)return;const n=this.input.value.trim();t.setAttribute("href",function(e,t,n,i){const r=t.find(e=>A(e.action,n));if(!r)return i;const s=new URL(r.action||"/search",n);for(const[o,a]of r.hidden)"q"!==o&&s.searchParams.set(o,a);return s.searchParams.set("q",e),s.pathname+s.search}(n,[...document.querySelectorAll("form")].map(e=>({action:e.getAttribute("action"),hidden:[...e.querySelectorAll('input[type="hidden"][name]')].map(e=>[e.name,e.value])})),location.origin,C(n,this.ctx)));const i="done"===this.state.phase&&"fallback"===this.state.result?.type&&!this.notice;e.querySelector(".pv span").textContent=i?"Preview: AI didn't run for this search, so these are plain results":k}dispatch(e){this.state=function(e,t){switch(t.type){case"input":return{...e,q:t.q,phase:"typing",rid:null,plan:null,result:null,loadingMore:!1};case"suggested":return t.q!==e.q.trim()||"typing"!==e.phase?e:t.collections?{...e,suggestions:t.products,suggestedFor:t.q,collections:t.collections,collectionsFor:t.q}:{...e,suggestions:t.products,suggestedFor:t.q};case"enter":return{...e,phase:"working",asked:e.q.trim(),rid:t.rid,drop:t.drop??[],plan:null,result:null,loadingMore:!1};case"server":return t.rid!==e.rid||"working"!==e.phase?e:"plan"===t.event.type?{...e,plan:t.event}:$.has(t.event.type)?{...e,phase:"done",result:t.event}:e;case"failed":return t.rid!==e.rid||"working"!==e.phase?e:{...e,phase:"done",result:{type:"fallback",products:[],cursor:null}};case"loading_more":return t.rid!==e.rid?e:{...e,loadingMore:!0};case"more":{const n=e.result;if(t.rid!==e.rid||!n||"results"!==n.type&&"fallback"!==n.type)return e;const i=new Set(n.products.map(e=>e.id)),r=[...n.products,...t.products.filter(e=>!i.has(e.id))];return{...e,loadingMore:!1,result:{...n,products:r,cursor:t.cursor}}}case"restore":return{...e,q:t.q,asked:t.q,rid:t.rid,drop:t.drop,phase:"done",result:t.result,plan:null,loadingMore:!1}}}(this.state,e),this.syncPreviewBar();const t=this.body.scrollTop;this.body.innerHTML=this.notice&&"done"===this.state.phase?`<div class="empty"><h2>${this.notice}</h2></div>`:T(this.state,this.ctx),"done"===this.state.phase&&(this.body.scrollTop=t)}cancelAll(){this.timers.forEach(e=>clearTimeout(e)),this.timers=[];for(const e of[this.suggestAbort,this.searchAbort,this.moreAbort])e?.abort();this.suggestAbort=this.searchAbort=this.moreAbort=null}typed(){this.cancelAll(),this.body.scrollTop=0,this.dispatch({type:"input",q:this.input.value});const e=this.input.value.trim();if(!e)return;this.pausedFor="";const t=new AbortController;this.suggestAbort=t,this.timers.push(window.setTimeout(()=>{m(this.config.sharingId,e,"key",this.shopper,t.signal).then(t=>{this.pausedFor!==e&&this.dispatch({type:"suggested",q:e,products:t})}).catch(()=>{})},80)),this.timers.push(window.setTimeout(()=>{Promise.all([m(this.config.sharingId,e,"pause",this.shopper,t.signal),x(e,this.ctx.root,t.signal)]).then(([t,n])=>{this.pausedFor=e,this.dispatch({type:"suggested",q:e,products:t,collections:n})}).catch(()=>{})},350))}search(e=[]){const i=this.input.value.trim();if(!i)return;this.cancelAll();const r=function(){const e=globalThis.crypto;if(e?.randomUUID)return e.randomUUID();const t=Array.from({length:16},()=>Math.floor(256*Math.random()));t[6]=15&t[6]|64,t[8]=63&t[8]|128;const n=t.map(e=>e.toString(16).padStart(2,"0")).join("");return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}();this.notice=null,this.started=performance.now(),this.dispatch({type:"enter",rid:r,drop:e}),this.input.blur(),this.body.scrollTop=0;const s=new AbortController;this.searchAbort=s,async function(e,t,n,i){const r=await fetch(`${h(e)}/search`,{method:"POST",headers:{"Content-Type":"application/json",...g()},body:JSON.stringify(t),signal:i});if(!r.ok||!r.body)throw new p(r.status);const s=r.body.getReader(),o=new TextDecoder,a={buffer:""};for(;;){const{done:e,value:t}=await s.read(),i=e?o.decode()+"\n\n":o.decode(t,{stream:!0});for(const r of c(i,a))try{n(JSON.parse(r.data))}catch{}if(e)return}}(this.config.sharingId,{q:i,rid:r,drop:e,...this.shopper},e=>{this.dispatch({type:"server",rid:r,event:e}),"plan"!==e.type&&t("ai_search_enter",{outcome:e.type,ms:Math.round(performance.now()-this.started),count:"products"in e&&Array.isArray(e.products)?e.products.length:void 0,...this.tag})},s.signal).then(()=>this.dispatch({type:"failed",rid:r})).catch(e=>{if(!s.signal.aborted){if(e instanceof p){const s=(t=e.status,this.config.preview?404===t?{notice:'This preview link no longer works. Open "Try it on your store" in Dori again.',forget:!0}:{notice:"No more preview searches for now. Try again later.",forget:!1}:"leave");return"leave"===s?(this.close(),void location.assign(C(i,this.ctx))):(s.forget&&n(),this.notice=s.notice,void this.dispatch({type:"failed",rid:r}))}var t;this.dispatch({type:"failed",rid:r})}})}loadMore(){const e=this.state.result,t=this.state.rid;if(!t||this.state.loadingMore||!e||"results"!==e.type&&"fallback"!==e.type||null==e.cursor)return;this.dispatch({type:"loading_more",rid:t});const n=new AbortController;this.moreAbort=n,async function(e,t,n,i){const r=await fetch(`${h(e)}/more?${new URLSearchParams({rid:t,cursor:String(n)})}`,{signal:i,headers:g()});if(!r.ok)throw new p(r.status);return await r.json()}(this.config.sharingId,t,e.cursor,n.signal).then(e=>this.dispatch({type:"more",rid:t,products:e.products,cursor:e.cursor})).catch(()=>{n.signal.aborted||this.dispatch({type:"more",rid:t,products:[],cursor:null})})}scrolled(){const e=this.body;e.scrollTop+e.clientHeight>e.scrollHeight-500&&this.loadMore()}clicked(e){const n=e.target;if(n.closest("[data-act='enter']"))return e.preventDefault(),void this.search();const i=n.closest("[data-drop]");if(i)return e.preventDefault(),void this.search([...this.state.drop,i.dataset.drop]);const r=n.closest("a.card, a.row");r&&(t("ai_search_click",{phase:this.state.phase,outcome:this.state.result?.type,id:r.dataset.id,...this.tag}),this.save())}save(){const e=this.state;if("done"!==e.phase||!e.result||!e.rid)return;const t={q:e.asked,rid:e.rid,drop:e.drop,result:e.result,url:location.href,at:Date.now()};try{sessionStorage.setItem(U,JSON.stringify(t))}catch{}}}let W=null,Q=null,H=null;function K(e,t,n=null){return!(!e||!0!==e.feature_flags?.ai_search&&!n||t)}function J(e,t,n,i){return i||(n?t:e?null:t)}function V(e,t,n=null){const r=window,s=J(!0===e?.feature_flags?.ai_search,n,i(),H);if(!K(e,!0===r.Shopify?.designMode,s))return W?.(),W=null,Q=null,H=null,f(null),D?.destroy(),void(D=null);H=s,f(s);const o=e?.feature_flags?.ai_search_placeholder;Q={sharingId:t,preview:!!s,placeholder:o},function(e){D?.setPlaceholder(e)}(o),W||(W=function(e,t,n){const i=e=>{const i=e.target;if(!i||"FORM"!==i.tagName||!A(i.getAttribute("action"),n))return;e.preventDefault(),e.stopImmediatePropagation();const r=i.querySelector('input[name="q"]');t(r?.value??"",!0,r??i)},r=e=>{const i=e.target;i&&"INPUT"===i.tagName&&i.matches('input[type="search"], input[name="q"]')&&(i.form?A(i.form.getAttribute("action"),n):i.closest?.(S))&&(i.blur?.(),t(i.value??"",!1,i))},s=e=>{const i=e;if(i.defaultPrevented||0!==(i.button??0)||i.metaKey||i.ctrlKey||i.shiftKey||i.altKey)return;const r=e.target;if(!r?.closest)return;if(r.closest(a))return;const s=r.closest(l);if(!s||"INPUT"===s.tagName)return;if(s.closest(`#${q}`))return;if(function(e){const t=e.querySelectorAll?.('a[href], button, summary, select, [role="button"]');if(!t)return!1;let n=0;for(let i=0;i<t.length;i++)if(M(t[i])&&++n>1)return!0;return!1}(s))return;if("FORM"===s.tagName||r.closest("form"))return;if(!("A"===s.tagName?A(s.getAttribute("href"),n):s.closest(S)))return;e.preventDefault(),e.stopImmediatePropagation();const o="A"===s.tagName?function(e,t){if(!e)return"";try{return new URL(e,t).searchParams.get("q")??""}catch{return""}}(s.getAttribute("href"),n):"";t(o,!!o,s)};return e.addEventListener("submit",i,!0),e.addEventListener("focusin",r,!0),e.addEventListener("click",s,!0),()=>{e.removeEventListener("submit",i,!0),e.removeEventListener("focusin",r,!0),e.removeEventListener("click",s,!0)}}(window,(e,t,n)=>Q&&function(e,t,n,i=null){D||(D=new B(Q)),D.open(t,n,i)}(0,e,t,n),location.origin),function(e){let t=null;try{t=JSON.parse(sessionStorage.getItem(U)||"null")}catch{t=null}const n=history.state,i=n?.doriAiSearch?function(e,t,n){return!e||e.url!==t||n-e.at>18e5?null:e}(t,location.href,Date.now()):null;i&&(D||(D=new B(e)),D.restore(i))}(Q))}export{V as applyAiSearch,J as keyForPage,K as wantsAiSearch};
Binary file
Binary file
@@ -0,0 +1 @@
1
+ import{v as e,r as t,i as n,a as o,A as r,f as s,b as a,p as i,s as l,c,d as u}from"./anchors-5BHu2BdH.js";import{d as h}from"./report-BHr6U1PB.js";const d=(e,t)=>Math.max(0,Math.min(e.right,t.right)-Math.max(e.left,t.left))*Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top)),f=e=>/^(A|BUTTON|IMG|SVG|INPUT|SELECT|TEXTAREA|LABEL|SUMMARY|VIDEO|CANVAS)$/i.test(e.tagName)||e.hasAttribute("role")||(e=>[...e.childNodes].some(e=>e.nodeType===Node.TEXT_NODE&&""!==(e.textContent||"").trim()))(e),p=e=>e.top+e.height/2,m=e=>e.shadowRoot?.querySelector("button")??null;function w(e,t,{sideways:n=!0}={}){const o=(e,t)=>Math.abs(e-t)<=1,r=(e,t)=>e.length===t.length&&e.every((e,n)=>o(e,t[n]));return o(e.x,t.x)&&o(e.y,t.y)&&e.w===t.w&&e.h===t.h&&o(e.header,t.header)&&r(e.tops,t.tops)&&(!n||r(e.lefts,t.lefts))}function g(e,n){const o=n.map(t);return{x:window.scrollX,y:window.scrollY,w:window.innerWidth,h:window.innerHeight,header:t(e).height,tops:o.map(e=>e.top),lefts:o.map(e=>e.left)}}const _=e=>new Promise(t=>setTimeout(t,e));async function b(e,t,n){const o=performance.now();await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(()=>e()))),document.fonts&&await document.fonts.ready;const r=t-(performance.now()-o);r>0&&await _(r);let s=e();for(;performance.now()-o<n;){await _(80);const t=e();if(w(s,t))return!0;s=t}return!1}function y(e,o){return[...e.querySelectorAll("*")].filter(e=>!(e.closest("svg")&&"svg"!==e.tagName.toLowerCase())&&f(e)&&n(e,o)&&t(e).top<Math.min(300,.4*o.h)+60).slice(0,260)}function v(e,n,o){const r=e.closest("dialog[open]");if(r&&!r.contains(n))return!0;for(let s=e;s&&s!==document.body;s=s.parentElement){const e=getComputedStyle(s);if(!("fixed"!==e.position&&"sticky"!==e.position||s.contains(n)||n.contains(s))){const e=t(s);if(e.width*e.height>o.w*o.h*.4)return!0}}return!1}function k(e,n,o){for(const r of o)if(!e.contains(r)&&!r.contains(e)&&d(n,t(r))>16)return`overlaps_${r.tagName.toLowerCase()}`;return null}function M(e,n,o,r){for(let s=1;s<=5;s++)for(let a=1;a<=3;a++){const i=n.left+n.width*s/6,l=n.top+n.height*a/4,c=document.elementFromPoint(i,l);if(!(c===e||e.contains(c)||c&&v(c,o,r)))return`covered_by_${c?c.tagName.toLowerCase():"nothing"}`;const u=document.elementsFromPoint(i,l),h=u.indexOf(e);for(const n of u.slice(h+1))if(!n.contains(e)&&n!==document.body&&n!==document.documentElement&&f(n)&&t(n).width<.6*r.w)return`sits_on_${n.tagName.toLowerCase()}`}return null}function S(n,o=e()){const r=y(n,o),s=r.map(e=>t(e).top),a=r.map(e=>{const n=t(e);return n.left>=-1&&n.right<=o.w+1}),i=()=>{const e=r.map(t),n=new Set;for(let t=0;t<r.length;t++)for(let o=t+1;o<r.length;o++)r[t].contains(r[o])||r[o].contains(r[t])||d(e[t],e[o])>16&&n.add(`${t}:${o}`);return n},l=i(),c=t(n).height,u=e=>{const t=e&&m(e);return g(n,t?[...r,t]:r)},h=u();return{look:u,before:h,check(e,u){const h=m(e);if(!h)return["no_button"];const d=t(h),f=[],w=Math.round(t(n).height-c);Math.abs(w)>2&&f.push(`header_height_${w}`);const g=Math.max(0,...r.map((e,n)=>Math.abs(t(e).top-s[n])));g>3&&f.push(`item_moved_${Math.round(g)}`);const _=r.filter((n,r)=>{if(!a[r]||e.contains(n))return!1;const s=t(n);return s.left<-1||s.right>o.w+1});_.length&&f.push(`pushed_offscreen_${_.length}`),(d.left<0||d.right>o.w+1||d.top<0)&&f.push("offscreen"),(d.width<24||d.height<24)&&f.push("too_small");const b=Math.round(p(d)-p(t(u)));Math.abs(b)>4&&f.push(`not_centred_${b}`);const y=k(e,d,r);y&&f.push(y);const v=M(e,d,n,o);v&&f.push(v);const S=[...i()].filter(e=>!l.has(e));return S.length&&f.push(`theme_overlap_${S.length}`),f}}}function $(e,n){const r=t(n.header);return[m(e)??e,n.anchor,...n.controls].flatMap(e=>{if(!e.isConnected||!o(e))return[NaN,NaN,NaN,NaN];const n=t(e);return[n.left-r.left,n.top-r.top,n.width,n.height]})}function E(e,n,o,r){const s=m(e);if(!s)return null;const a=p(t(s)),i=t(o);return{header:o,size:{w:i.width,h:i.height},anchor:n,controls:r,offsets:r.map(e=>p(t(e))-a),layout:$(e,{header:o,anchor:n,controls:r})}}function C(e,n){if(!n.header.isConnected)return!0;const o=t(n.header);if(Math.abs(o.width-n.size.w)>1||Math.abs(o.height-n.size.h)>2)return!0;const r=$(e,n);return r.length!==n.layout.length||r.some((e,t)=>{const o=n.layout[t];return Number.isNaN(e)!==Number.isNaN(o)||Math.abs(e-o)>2})}function N(e){for(const t of e){const e=t.getAttribute("onclick");if(e&&/doriWidget/.test(e))return!0;const n=t.getAttribute("href");if(n&&/(#dori-chat\b|[?&]dori-chat=)/i.test(n))return!0}return!1}const x="none",z=["after_search","beside_search","before_search","before_cart","beside_cart","beside_menu"];function A(e){if(!e||"none"===e||"transparent"===e||e.startsWith("url("))return!1;const t=/^rgba?\([^)]*[,/]\s*([\d.]+%?)\s*\)$/.exec(e)?.[1];return void 0===t||parseFloat(t)>0}function L(e,t){const n=t&&/^svg$/i.test(t.tagName)?t:e.querySelector("svg");if(n){const e=function(e){for(const t of e){if(A(t.stroke)&&parseFloat(t.strokeWidth||"1")>0)return t.stroke;if(A(t.fill))return t.fill}return null}([...n.querySelectorAll("path, circle, ellipse, line, polyline, polygon, rect")].slice(0,6).map(e=>{const t=getComputedStyle(e);return{fill:t.fill,stroke:t.stroke,strokeWidth:t.strokeWidth}}));if(e)return e}return getComputedStyle(e).color}const W=(e,t)=>"phone"===t?e.spotPhone:e.spot,B=e=>e?`${e.tagName.toLowerCase()}${e.classList[0]?`.${e.classList[0]}`:""}`:"-",P=e=>new Promise(t=>setTimeout(t,e)),T=e=>`dori_ask_spot_${e}`,I=e=>`${e.spot}:${e.label?"text":"icon"}`,q=new Set;function F(e,t){if(!q.has(e)){q.add(e);try{t?window.localStorage.setItem(T(e),I(t)):window.localStorage.removeItem(T(e))}catch{}}}const O=e=>{const n=t(e);return n.top>=0&&n.bottom<=window.innerHeight};function R(e){return O(e)?Promise.resolve():new Promise(t=>{const n=()=>{O(e)&&(clearInterval(o),window.removeEventListener("scroll",n),window.removeEventListener("resize",n),t())},o=setInterval(n,250);window.addEventListener("scroll",n,{passive:!0}),window.addEventListener("resize",n,{passive:!0})})}async function H(){const t=await async function(){for(let e=0;e<32;e++){const e=s();if(e)return e;await P(250)}return null}();if(!t)return null;let n=t;for(;;){await R(n.search||n.cart||n.header);const t=S(n.header,e());if(await b(()=>t.look(),150,1500),n=s()||n,O(n.search||n.cart||n.header))return n}}function j(){window.doriWidget?.open?.({source:"header_button"})}function D(e,o,r){const s=function(e,t){for(let o=t?e.nextElementSibling:e.previousElementSibling;o;o=t?o.nextElementSibling:o.previousElementSibling)if(n(o))return o;return null}(e,"end"===o);if(!s)return;const a=t(e),i=t(s);(("end"===o?!r:r)?i.left-a.right:a.left-i.right)<6&&(e.style["end"===o?"marginInlineEnd":"marginInlineStart"]="8px")}const U=e=>[e.search,e.cart,e.menu].filter(e=>Boolean(e));function G(e,n,o){const r=n.spot.endsWith("_search")?o.search:n.spot.endsWith("_cart")?o.cart:o.menu;if(!r)return!1;const s=l(r),a=s.parentElement;if(!a)return!1;const i=parseFloat(getComputedStyle(a).columnGap)||0;if("after_search"===n.spot)return a.insertBefore(e,s.nextSibling),i||(e.style.marginInlineStart="10px",D(e,"end",o.rtl)),!0;if("before_cart"===n.spot)return a.insertBefore(e,s),i||(e.style.marginInlineEnd="10px",D(e,"start",o.rtl)),!0;const c=r.offsetParent;if(!c||c===document.body||c===document.documentElement)return!1;c.appendChild(e),e.style.position="absolute";const u=t(c),h=t(e),d=t("beside_menu"===n.spot?r:s),f="beside_search"===n.spot||"beside_menu"===n.spot,p=o.rtl?!f:f,m="beside_menu"===n.spot?4:10,w=p?d.right-u.left+m:d.left-u.left-h.width-m;return e.style.left=`${Math.round(w+c.scrollLeft)}px`,e.style.top=`${Math.round(d.top+d.height/2-u.top-h.height/2)}px`,!0}async function V(o,r,s,u){const h=e(),d=o.cart||o.search||o.menu,f=[...o.header.querySelectorAll("nav a, [class*='menu' i] a")].find(e=>n(e,h)),p=getComputedStyle(f||d),m=o.cart?a(o.cart):o.search?a(o.search):null,g=m&&/^(svg|img)$/i.test(m.tagName)?Math.max(16,Math.min(26,Math.round(t(m).height))):20,_=function(e){const t=e.desktop&&e.hasLabel?[!0,!1]:[!1],n=[];if(e.hasSearch)for(const o of t)e.searchPacked&&n.push({zone:"near_search",spot:"after_search",label:o}),n.push({zone:"near_search",spot:"beside_search",label:o}),n.push({zone:"near_search",spot:"before_search",label:o});if(e.hasCart)for(const o of t)e.cartPacked&&n.push({zone:"other_header",spot:"before_cart",label:o}),n.push({zone:"other_header",spot:"beside_cart",label:o});return e.hasMenu&&!e.desktop&&n.push({zone:"other_header",spot:"beside_menu",label:!1}),n}({desktop:"computer"===s,hasLabel:Boolean(r.label),hasSearch:Boolean(o.search),searchPacked:Boolean(o.search?.parentElement&&i(l(o.search).parentElement)),hasCart:Boolean(o.cart),cartPacked:Boolean(o.cart?.parentElement&&i(l(o.cart).parentElement)),hasMenu:Boolean(o.menu)}),y=S(o.header,h),v=r.followIcons?L(d,a(d)):getComputedStyle(d).color;for(const e of function(e,t){let n=null;try{n=window.localStorage.getItem(T(t))}catch{}const o=e.find(e=>I(e)===n);return o?[o,...e.filter(e=>e!==o)]:e}(function(e,t){return t?t===x?[]:z.includes(t)?e.filter(e=>e.spot===t):e:e}(_,W(r,s)),s)){const n=e.spot.endsWith("_search")?o.search:e.spot.endsWith("_cart")?o.cart:o.menu,i=o.isBar&&e.spot.endsWith("_search")?n:a(n),l=Math.max(28,Math.min(44,Math.round(t(i).height+16))),h=c({label:e.label?r.label:null,aria:r.aria,boxHeight:l,color:v,fontSize:parseFloat(p.fontSize),iconSize:g,light:r.light},j);if(h.style.opacity="0",!G(h,e,o)){u?.push(`${I(e)} cant_apply`);continue}h.parentElement&&getComputedStyle(h.parentElement).color===v&&h.style.removeProperty("color");const f=h.shadowRoot.querySelector("button"),m=Math.round(t(i).top+t(i).height/2-(t(f).top+t(f).height/2));Math.abs(m)>1&&Math.abs(m)<24&&(h.style.top=`${(parseFloat(h.style.top)||0)+m}px`),await b(()=>y.look(h),120,700);let _=y.check(h,i);if(!_.length){if(await b(()=>y.look(h),450,1200),_=y.check(h,i),!_.length)return F(s,e),ae=r.followIcons?d:null,se=E(h,i,o.header,U(o)),u?.push(`${I(e)} ok`),{placed:!0,zone:e.zone,spot:e.spot,label:e.label,device:s};_=_.map(e=>`${e}(confirm)`)}if(h.remove(),!w(y.before,y.look(),{sideways:!1}))return u?.push(`${I(e)} ${_.join(",")} page_moved`),"page_moved";u?.push(`${I(e)} ${_.join(",")}`)}return null}function X(){return[...document.querySelectorAll("[data-dori-ask-block]")].some(e=>{if(!o(e))return!1;const n=t(e);return n.right>0&&n.left<window.innerWidth})}async function Y(e){se=null;const t=h(),n={placed:!1,zone:"none",device:t},o=window.__doriAskTrace;if(X())return{placed:!0,zone:"block",device:t};if(W(e,t)===x)return o?.push(`${t} pinned_none`),n;for(let r=0;r<=3;r++){const r=await H();if(!r)return o?.push(`${t} no_anchors`),n;if(o?.push(`${t} search=${B(r.search)}${r.isBar?"(bar)":""} cart=${B(r.cart)} menu=${B(r.menu)} header=${B(r.header)}`),N(r.header.querySelectorAll("[onclick], a[href]")))return o?.push("own_entry"),n;const s=await V(r,e,t,o);if("page_moved"!==s){if(s)return s;break}}return F(t,null),n}function J(e){window.__doriAskResult=e,window.dispatchEvent(new CustomEvent("dori:ask-button",{detail:e}))}let K=null,Q=!0,Z=null,ee=null,te=!1,ne=0,oe=0,re=0,se=null,ae=null,ie=!1,le=!1,ce=0,ue=!1;const he=()=>document.querySelector(r),de=()=>window.__doriAskResult;function fe(e){return!!e&&!o(e.shadowRoot?.querySelector("button")??e)}function pe(){he()?.remove(),se=null,ae=null,de()?.placed&&J({placed:!1,zone:"none",device:h(),pending:!0})}async function me(){if(Z&&!Q)return K||(K=(async()=>{for(;;){const e=Z,t=window.innerWidth;let n;oe++,pe();try{n=await Y(e)}catch{he()?.remove(),n={placed:!1,zone:"none",device:h()}}if(Q)return void he()?.remove();if(e!==Z||window.innerWidth!==t)continue;const o=he();return o&&(o.style.transition="opacity .2s ease",o.style.opacity="1"),re=t,void J(n)}})().finally(()=>{K=null,be()}),K)}function we(){if(ne>=10){he()?.remove(),se=null,re=window.innerWidth;const e=de();return void((e?.placed||e?.pending)&&J({placed:!1,zone:"none",device:h()}))}ne++,me()}function ge(){if(Q||K)return;!function(){const e=he();if(!e||!e.style.color||!ae?.isConnected)return;const t=L(ae,a(ae));t!==e.style.color&&(e.style.color=t)}();const n=de();if(!n)return;const r=he(),i="block"===(l={placed:n.placed,zone:n.zone,pending:!0===n.pending,blockShown:X(),host:r?fe(r)?"lost":"drawn":"none",widthChanged:window.innerWidth!==re,headerChanged:Boolean(r&&se&&C(r,se))}).zone?l.blockShown?"keep":"redo":l.blockShown?"redo":l.placed?"drawn"!==l.host||l.widthChanged?"redo":l.headerChanged?"check_fit":"keep":l.pending||l.widthChanged?"redo":"keep";var l;"redo"===i?we():"check_fit"===i&&async function(){const n=he(),r=se;if(ie||!n||!r)return;const i=ce+1e3-performance.now();if(i>0)return void(ue||(ue=!0,setTimeout(()=>{ue=!1,be()},i)));ie=!0;const l=oe;try{await R(n);const i=()=>g(r.header,[n,...r.controls]);for(let e=0;e<3&&!(await b(i,120,1200));e++);if(l!==oe||Q||K||!n.isConnected)return;const c=function(n,r,s=e()){const a=m(n);if(!a||!r.header.isConnected)return["header_redrawn"];const i=t(a),l=[];if((i.left<0||i.right>s.w+1)&&l.push("offscreen"),(i.width<24||i.height<24)&&l.push("too_small"),r.anchor.isConnected){const e=Math.round(p(i)-p(t(r.anchor)));Math.abs(e)>4&&l.push(`not_centred_${e}`)}const c=r.controls.map(e=>e.isConnected&&o(e)),u=Math.max(0,...r.controls.map((e,n)=>c[n]?Math.abs(p(t(e))-p(i)-r.offsets[n]):0));u>3&&l.push(`item_moved_${Math.round(u)}`);const h=r.controls.filter((e,n)=>{if(!c[n])return!1;const o=t(e);return o.left<-1||o.right>s.w+1});h.length&&l.push(`pushed_offscreen_${h.length}`);const d=k(n,i,y(r.header,s));if(d&&l.push(d),i.top>=0&&i.bottom<=s.h){const e=M(n,i,r.header,s);e&&l.push(e)}return l}(n,r);window.__doriAskTrace?.push(`refit ${c.join(",")||"ok"}`);const u=c.length?null:function(e,n){if([n.anchor,...n.controls].every(e=>e.isConnected)){const o=t(n.header);return{...n,size:{w:o.width,h:o.height},layout:$(e,n)}}const o=s(),r=de()?.spot;if(!o||!r)return null;const i=r.endsWith("_search")?o.search:r.endsWith("_cart")?o.cart:o.menu;return i?E(e,o.isBar&&r.endsWith("_search")?i:a(i),o.header,U(o)):null}(n,r);if(!u)return void we();se=u}finally{ie=!1,ce=performance.now()}}()}let _e,be=()=>{};function ye(e){return!e.designMode&&(!e.enabled||e.banned||!e.askOn)}function ve(e,t){if(!e)return;const n=window,o=!1!==e.is_widget_enabled,r=!0===e.feature_flags?.ask_button,s=ye({enabled:o,banned:t,askOn:r,designMode:!0===n.Shopify?.designMode});if(document.querySelectorAll("[data-dori-ask-block]").forEach(e=>{s?(e.hidden=!0,e.style.setProperty("display","none","important"),e.dataset.doriHidden=""):void 0!==e.dataset.doriHidden&&(e.hidden=!1,e.style.removeProperty("display"),delete e.dataset.doriHidden)}),!r||!o||t||!1===n.DORI_HEADER_BUTTON)return Q=!0,oe++,se=null,ae=null,ee?.disconnect(),ee=null,void he()?.remove();!function(e){const t=!Z||Z.label!==e.label||Z.aria!==e.aria||Boolean(Z.followIcons)!==Boolean(e.followIcons)||Boolean(Z.light)!==Boolean(e.light)||(Z.spot||null)!==(e.spot||null)||(Z.spotPhone||null)!==(e.spotPhone||null);t&&(Z=e);const n=Q;if(Q=!1,!n)return void(t&&me());if(me(),be=()=>{le||Q||(le=!0,requestAnimationFrame(()=>{le=!1,ge()}))},ee=new MutationObserver(e=>{be(),se&&e.some(e=>se.header.contains(e.target))&&(clearTimeout(_e),_e=setTimeout(()=>be(),700))}),ee.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","hidden"]}),te)return;te=!0,setInterval(()=>{ne=0},6e4);const o=e=>{se&&e.target instanceof Node&&se.header.contains(e.target)&&be()};let r;document.addEventListener("transitionend",o,!0),document.addEventListener("animationend",o,!0),window.addEventListener("resize",()=>{const e=de();!K&&e?.placed&&"block"!==e.zone&&window.innerWidth!==re&&pe(),clearTimeout(r),r=setTimeout(()=>be(),200)},{passive:!0})}({...u(e.feature_flags?.ask_button_text,e.agent_name),followIcons:!0===e.feature_flags?.ask_button_follow_icons,light:!0===e.feature_flags?.ask_button_light,spot:e.feature_flags?.ask_button_spot??null,spotPhone:e.feature_flags?.ask_button_spot_phone??null})}export{ve as applyAskButton,ye as hideBlock};
Binary file
Binary file