/*! For license information please see minimised.js.LICENSE.txt */ (()=>{var t={457:function(t){t.exports=function(){"use strict";function t(t,e){var i,a=Object.keys(t);return Object.getOwnPropertySymbols&&(i=Object.getOwnPropertySymbols(t),e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),a.push.apply(a,i)),a}function e(e){for(var i=1;it.length)&&(e=t.length);for(var i=0,a=new Array(e);it.width?3===i?s=t.height*o:e=t.width/o:3===i?e=t.width/o:s=t.height*o,e={aspectRatio:o,naturalWidth:a,naturalHeight:n,width:s,height:e},this.canvasData=e,this.limited=1===i||2===i,this.limitCanvas(!0,!0),e.width=Math.min(Math.max(e.width,e.minWidth),e.maxWidth),e.height=Math.min(Math.max(e.height,e.minHeight),e.maxHeight),e.left=(t.width-e.width)/2,e.top=(t.height-e.height)/2,e.oldLeft=e.left,e.oldTop=e.top,this.initialCanvasData=st({},e)},limitCanvas:function(t,e){var i,a=this.options,n=this.containerData,o=this.canvasData,s=this.cropBoxData,r=a.viewMode,l=o.aspectRatio,h=this.cropped&&s;t&&(t=Number(a.minCanvasWidth)||0,i=Number(a.minCanvasHeight)||0,1=n.width&&(o.minLeft=Math.min(0,i),o.maxLeft=Math.max(0,i)),o.height>=n.height&&(o.minTop=Math.min(0,e),o.maxTop=Math.max(0,e))))):(o.minLeft=-o.width,o.minTop=-o.height,o.maxLeft=n.width,o.maxTop=n.height))},renderCanvas:function(t,e){var i,a,n=this.canvasData,o=this.imageData;e&&(i=(a=function(t){var e=t.width,i=t.height,a=t.degree;if(90==(a=Math.abs(a)%180))return{width:i,height:e};var n=a%90*Math.PI/180,o=Math.sin(n);return n=e*(t=Math.cos(n))+i*o,t=e*o+i*t,90n.maxWidth||n.widthn.maxHeight||n.heighte.width?t.height=t.width/i:t.width=t.height*i),this.cropBoxData=t,this.limitCropBox(!0,!0),t.width=Math.min(Math.max(t.width,t.minWidth),t.maxWidth),t.height=Math.min(Math.max(t.height,t.minHeight),t.maxHeight),t.width=Math.max(t.minWidth,t.width*a),t.height=Math.max(t.minHeight,t.height*a),t.left=e.left+(e.width-t.width)/2,t.top=e.top+(e.height-t.height)/2,t.oldLeft=t.left,t.oldTop=t.top,this.initialCropBoxData=st({},t)},limitCropBox:function(t,e){var i,a,n=this.options,o=this.containerData,s=this.canvasData,r=this.cropBoxData,l=this.limited,h=n.aspectRatio;t&&(i=Number(n.minCropBoxWidth)||0,a=Number(n.minCropBoxHeight)||0,t=l?Math.min(o.width,s.width,s.width+s.left,o.width-s.left):o.width,n=l?Math.min(o.height,s.height,s.height+s.top,o.height-s.top):o.height,i=Math.min(i,o.width),a=Math.min(a,o.height),h&&(i&&a?ii.maxWidth||i.widthi.maxHeight||i.height=e.width&&i.height>=e.height?p:c),ct(this.cropBox,st({width:i.width,height:i.height},St({translateX:i.left,translateY:i.top}))),this.cropped&&this.limited&&this.limitCanvas(!0,!0),this.disabled||this.output()},output:function(){this.preview(),Ct(this.element,I,this.getData())}},_t={initPreview:function(){var t=this.element,e=this.crossOrigin,i=this.options.preview,a=e?this.crossOriginUrl:this.url,n=t.alt||"The image to preview",o=document.createElement("img");e&&(o.crossOrigin=e),o.src=a,o.alt=n,this.viewBox.appendChild(o),this.viewBoxImage=o,i&&("string"==typeof(o=i)?o=t.ownerDocument.querySelectorAll(i):i.querySelector&&(o=[i]),ot(this.previews=o,(function(t){var i=document.createElement("img");ft(t,S,{width:t.offsetWidth,height:t.offsetHeight,html:t.innerHTML}),e&&(i.crossOrigin=e),i.src=a,i.alt=n,i.style.cssText='display:block;width:100%;height:auto;min-width:0!important;min-height:0!important;max-width:none!important;max-height:none!important;image-orientation:0deg!important;"',t.innerHTML="",t.appendChild(i)})))},resetPreview:function(){ot(this.previews,(function(t){var e=vt(t,S);ct(t,{width:e.width,height:e.height}),t.innerHTML=e.html,function(t,e){if(V(t[e]))try{delete t[e]}catch(i){t[e]=void 0}else if(t.dataset)try{delete t.dataset[e]}catch(i){t.dataset[e]=void 0}else t.removeAttribute("data-".concat(gt(e)))}(t,S)}))},preview:function(){var t=this.imageData,e=this.canvasData,i=this.cropBoxData,a=i.width,n=i.height,o=t.width,s=t.height,r=i.left-e.left-t.left,l=i.top-e.top-t.top;this.cropped&&!this.disabled&&(ct(this.viewBoxImage,st({width:o,height:s},St(st({translateX:-r,translateY:-l},t)))),ot(this.previews,(function(e){var i=(p=vt(e,S)).width,h=p.height,c=i,d=h,p=1;a&&(d=n*(p=i/a)),n&&hMath.abs(a-1)?i:a)&&(t.restore&&(o=this.getCanvasData(),s=this.getCropBoxData()),this.render(),t.restore&&(this.setCanvasData(ot(o,(function(t,e){o[e]=t*n}))),this.setCropBoxData(ot(s,(function(t,e){s[e]=t*n}))))))},dblclick:function(){var t,e;this.disabled||this.options.dragMode===L||this.setDragMode((t=this.dragBox,e=M,(t.classList?t.classList.contains(e):-1S&&(A.x=S-k);break;case g:h+A.xN&&(A.y=N-$)}}!l&&t.shiftKey&&(l=D&&E?D/E:1),this.limited&&(B=o.minLeft,T=o.minTop,S=B+Math.min(n.width,a.width,a.left+a.width),N=T+Math.min(n.height,a.height,a.top+a.height));var I,H,_,W=s[Object.keys(s)[0]],A={x:W.endX-W.startX,y:W.endY-W.startY};switch(r){case c:h+=A.x,M+=A.y;break;case m:if(0<=A.x&&(S<=k||l&&(M<=T||N<=$))){O=!1;break}L(m),(D+=A.x)<0&&(r=g,h-=D=-D),l&&(M+=(o.height-(E=D/l))/2);break;case f:if(A.y<=0&&(M<=T||l&&(h<=B||S<=k))){O=!1;break}L(f),E-=A.y,M+=A.y,E<0&&(r=v,M-=E=-E),l&&(h+=(o.width-(D=E*l))/2);break;case g:if(A.x<=0&&(h<=B||l&&(M<=T||N<=$))){O=!1;break}L(g),D-=A.x,h+=A.x,D<0&&(r=m,h-=D=-D),l&&(M+=(o.height-(E=D/l))/2);break;case v:if(0<=A.y&&(N<=$||l&&(h<=B||S<=k))){O=!1;break}L(v),(E+=A.y)<0&&(r=f,M-=E=-E),l&&(h+=(o.width-(D=E*l))/2);break;case y:if(l){if(A.y<=0&&(M<=T||S<=k)){O=!1;break}L(f),E-=A.y,M+=A.y,D=E*l}else L(f),L(m),!(0<=A.x)||kMath.abs(_)&&(_=a)}))})),_),t),O=!1;break;case d:if(!A.x||!A.y){O=!1;break}I=Et(this.cropper),h=W.startX-I.left,M=W.startY-I.top,D=o.minWidth,E=o.minHeight,0 or element.");this.element=e,this.options=st({},K,et(i)&&i),this.cropped=!1,this.disabled=!1,this.pointers={},this.ready=!1,this.reloading=!1,this.replaced=!1,this.sized=!1,this.sizing=!1,this.init()}var e,i,n;return e=t,n=[{key:"noConflict",value:function(){return window.Cropper=Rt,t}},{key:"setDefaults",value:function(t){st(K,et(t)&&t)}}],(i=[{key:"init",value:function(){var t,e=this.element,i=e.tagName.toLowerCase();if(!e[h]){if(e[h]=this,"img"===i){if(this.isImg=!0,t=e.getAttribute("src")||"",!(this.originalUrl=t))return;t=e.src}else"canvas"===i&&window.HTMLCanvasElement&&(t=e.toDataURL());this.load(t)}}},{key:"load",value:function(t){var e,i,a,n,o,s,r=this;t&&(this.url=t,this.imageData={},e=this.element,(i=this.options).rotatable||i.scalable||(i.checkOrientation=!1),i.checkOrientation&&window.ArrayBuffer?U.test(t)?q.test(t)?this.read((s=(s=t).replace(It,""),a=atob(s),s=new ArrayBuffer(a.length),ot(n=new Uint8Array(s),(function(t,e){n[e]=a.charCodeAt(e)})),s)):this.clone():(o=new XMLHttpRequest,s=this.clone.bind(this),this.reloading=!0,(this.xhr=o).onabort=s,o.onerror=s,o.ontimeout=s,o.onprogress=function(){o.getResponseHeader("content-type")!==Y&&o.abort()},o.onload=function(){r.read(o.response)},o.onloadend=function(){r.reloading=!1,r.xhr=null},i.checkCrossOrigin&&Bt(t)&&e.crossOrigin&&(t=Tt(t)),o.open("GET",t,!0),o.responseType="arraybuffer",o.withCredentials="use-credentials"===e.crossOrigin,o.send()):this.clone())}},{key:"read",value:function(t){var e=this.options,i=this.imageData,a=function(t){var e,i,a,n,o,s,r,l=new DataView(t);try{if(255===l.getUint8(0)&&216===l.getUint8(1))for(var h=l.byteLength,c=2;c+1
',o=(n=l.querySelector(".".concat(h,"-container"))).querySelector(".".concat(h,"-canvas")),s=n.querySelector(".".concat(h,"-drag-box")),l=(r=n.querySelector(".".concat(h,"-crop-box"))).querySelector(".".concat(h,"-face")),this.container=a,this.cropper=n,this.canvas=o,this.dragBox=s,this.cropBox=r,this.viewBox=n.querySelector(".".concat(h,"-view-box")),this.face=l,o.appendChild(i),dt(t,C),a.insertBefore(n,t.nextSibling),this.isImg||pt(i,E),this.initPreview(),this.bind(),e.initialAspectRatio=Math.max(0,e.initialAspectRatio)||NaN,e.aspectRatio=Math.max(0,e.aspectRatio)||NaN,e.viewMode=Math.max(0,Math.min(3,Math.round(e.viewMode)))||0,dt(r,C),e.guides||dt(r.getElementsByClassName("".concat(h,"-dashed")),C),e.center||dt(r.getElementsByClassName("".concat(h,"-center")),C),e.background&&dt(n,"".concat(h,"-bg")),e.highlight||dt(l,k),e.cropBoxMovable&&(dt(l,B),ft(l,T,c)),e.cropBoxResizable||(dt(r.getElementsByClassName("".concat(h,"-line")),C),dt(r.getElementsByClassName("".concat(h,"-point")),C)),this.render(),this.ready=!0,this.setDragMode(e.dragMode),e.autoCrop&&this.crop(),this.setData(e.data),it(e.ready)&&Dt(t,"ready",e.ready,{once:!0}),Ct(t,"ready"))}},{key:"unbuild",value:function(){this.ready&&(this.ready=!1,this.unbind(),this.resetPreview(),this.cropper.parentNode.removeChild(this.cropper),pt(this.element,C))}},{key:"uncreate",value:function(){this.ready?(this.unbuild(),this.ready=!1,this.cropped=!1):this.sizing?(this.sizingImage.onload=null,this.sizing=!1,this.sized=!1):this.reloading?(this.xhr.onabort=null,this.xhr.abort()):this.image&&this.stop()}}])&&a(e.prototype,i),n&&a(e,n),t}();return st(zt.prototype,Ht,_t,l,r,Wt,At),zt}()}},e={};function i(a){var n=e[a];if(void 0!==n)return n.exports;var o=e[a]={exports:{}};return t[a].call(o.exports,o,o.exports,i),o.exports}i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},i.d=(t,e)=>{for(var a in e)i.o(e,a)&&!i.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{"use strict";const t="https://ecommerce-backend.delvify.ai",e="https://smart-tag.s3.ap-southeast-1.amazonaws.com/widget-assets",a="https://smart-tag.s3.ap-southeast-1.amazonaws.com/widget-assets/delvify-widget.min.css",n=t+"/v1/widget/get_old_config",o=t+"/v1/search/image/base64",s=t+"/v1/search/utils/url_to_base64",r="v 1.0.0",l="smart.delvify.ai",h=["development","local"].includes("production"),c=async(t,e)=>fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),d={imageUrl:void 0,forShowing:void 0,forRequesting:void 0},p=function(t,e){var i=new FileReader;i.onload=function(){var t=i.result.split(",")[1];e(t)},i.readAsDataURL(t)},u=async t=>{let e,i;if(d.imageUrl===t)e=d.forShowing,i=d.forRequesting;else{const a=document.getElementById("delvify-tag").getAttribute("api_key"),n=await((t,e)=>c(s,{apikey:t,image_url:e}))(a,t);if(200===await n.status){const a=await n.json();e="data:"+t.slice(-1)[0]+";base64, "+a.base64,i=a.base64,d.imageUrl=t,d.forShowing=e,d.forRequesting=i}else alert("Error getting image, original image likely too large.")}return{forShowing:e,forRequesting:i}},m=(t,e="font_weight",i="color")=>{let a=!1,n=t[e]||"";return n.includes("italic")&&(n=n.replace("italic",""),a=!0),!n.includes("regular")&&n||(n=400),`\n text-align: ${t.text_align};\n font-weight: ${n};\n font-size: ${t.font_size}px;\n color: ${t[i]};\n font-style: ${a?"italic":"normal"};\n `},g=(t,i)=>{const a=t.props.visual_search.search_result.results,n=a.items_per_row,o=a.thumbnail_description||[];if("object"!=typeof i){const t=[];for(let e=0;e<2*n;e++){const e=[];e.push(`\n  \n `),o.forEach((t=>{if(t.enabled){if("Product Name"===t.title)return e.push('\n
 
\n ');if("Price"===t.title)return e.push('\n
\n
 
\n
 
\n
\n ');if("Product Description"===t.title)return e.push('\n
 
\n ')}})),t.push(`\n
\n ${e.join(" ")}\n
\n `)}document.getElementById("dv-dialog-content").getElementsByClassName("dv-image-wrapper")[0].innerHTML=`\n ${t.join(" ")}\n `}else{const n=[];for(let t=0;t\n \n \n \n
\n \n
Search similar
\n
\n \n `),o.forEach((t=>{const e=m(t),i=m(t,"sales_font_weight","sales_color");if(t.enabled){if("Product Name"===t.title)return r.push(`\n \n
${n=s.name,n.replace(/\w\S*/g,(function(t){return t.charAt(0).toUpperCase()+t.substr(1).toLowerCase()}))}
\n
\n `);if("Price"===t.title){const n=t.sales_enabled?"line-through":"none",o=t.sales_enabled?"block":"none",l=(a=s.currency_code,["SGD","USD","AUD","HKD"].includes(a)?"$":"EUR"===a?"€":"GBP"===a?"£":"JPY"===a?"¥":"$");let h="flex-start";return"center"===t.text_align?h="center":"right"===t.text_align&&(h="flex-end"),r.push(`\n
\n
${l}${s.price.toFixed(2)}
\n
$80
\n
\n `)}if("Product Description"===t.title)return r.push(`\n
${s.description}
\n `)}var a,n})),n.push(`\n
\n ${r.join(" ")}\n
\n `)}const s=document.getElementById("dv-dialog-content").getElementsByClassName("dv-image-wrapper")[0];i.length?s.innerHTML=`${n.join(" ")}`:s.innerHTML="

No results.

",setTimeout((()=>{C(t)}),500)}},v=t=>{document.getElementsByClassName("dv-total-items")[0].innerHTML=`Total Items: ${t}`},f={base64:void 0,results:void 0},y=async t=>{if(f.base64===t)return new Promise((t=>t(f.results)));let e=t;e.includes(", ")&&(e=e.split(", ")[1]);const i=document.getElementById("delvify-tag").getAttribute("api_key"),a=await((t,e)=>c(o,{apikey:t,image_base64:e}))(i,e),n=await a.json();let s={success:!1,products:[]};return n.success&&(s=n),f.base64=t,f.results=s,new Promise((t=>t(s)))},b=()=>{document.getElementById("file-upload-label").innerHTML='
'},w=(t,e,i)=>{const a=JSON.parse(localStorage.products),n={};let o=[];for(let t in e)n[t]=new Set([]),a.forEach((i=>{e[t][i[t]]&&n[t].add(i)}));for(let t in n)0===o.length&&0!==n[t].size&&o.push(...n[t]);for(let t in n){const i=Object.values(e[t]).some((t=>!0===t));(0!==n[t].size||i)&&(o=o.filter((e=>n[t].has(e))))}0===o.length&&(o=a);const s=o.filter((t=>t.price>=i[0]&&t.price<=i[1]));g(t,s),v(s.length||0)},x=t=>{const e=[];for(let i in t){const a=t[i],n=[];switch(i){case"price":n.push(`Min \n Max `);break;case"brand":for(let t of a)t=t.charAt(0).toUpperCase()+t.slice(1),n.push(`\n
`);break;case"color":for(let t of a)n.push(`\n
`);break;default:for(let t of a)n.push(`${t.replace(/---/g," ")}
`)}i=i.charAt(0).toUpperCase()+i.slice(1),e.push(`
${i}˅
${n.join("")}
`)}e.push(''),document.getElementById("dv-lowerSide").innerHTML=`${e.join("")}`},M=t=>{const e={},i=((t,e)=>{const i={};return["color","brand","price"].forEach((e=>{if("price"===e){let e=0,a=0;t.forEach((t=>{t.price&&(t.pricea&&(a=t.price))})),i.price={min:e,max:a}}else{const a=new Set([]);t.forEach((t=>{t[e]&&a.add(t[e].replace(/\s/g,"---"))})),i[e]=[...a]}})),i})(JSON.parse(localStorage.products));x(i);const a=document.getElementById("filter-option-price-min"),n=document.getElementById("filter-option-price-max"),o=document.getElementById("btn-reset-filter"),s=document.querySelectorAll("input[type=checkbox]");o.addEventListener("click",(()=>{a.valueAsNumber=Math.floor(i.price.min),n.valueAsNumber=Math.ceil(i.price.max),s.forEach((t=>t.checked=!1));for(const t in e)for(const i in e[t])e[t][i]=!1;w(t,{},[a.valueAsNumber,n.valueAsNumber])}));for(let o in i){const s=i[o];if(e[o]||"price"===o||(e[o]={}),"price"===o)a.addEventListener("input",(()=>w(t,e,[a.valueAsNumber,n.valueAsNumber]))),n.addEventListener("input",(()=>w(t,e,[a.valueAsNumber,n.valueAsNumber])));else for(let i of s)document.getElementById(`filter-option-${o}-${i}`).addEventListener("change",(i=>{e[o][i.target.name.replace(/---/g," ")]?e[o][i.target.name.replace(/---/g," ")]=!1:e[o][i.target.name.replace(/---/g," ")]=!0,w(t,e,[a.valueAsNumber,n.valueAsNumber])}))}},D=t=>{const e=document.getElementsByClassName("dv-close");for(let i of e)i&&i.addEventListener("click",(()=>t.hideDialog()))},C=t=>{document.getElementById("dv-dialog-content").scrollTop=0;const e=document.getElementsByClassName("dv-similar-button");for(let i of e)i.addEventListener("click",(async e=>{e.stopPropagation(),localStorage.removeItem("products");const i=e.composedPath();for(let e=0;e{let e;g(t,!0);const i=document.getElementById("dv-crop-button"),a=document.getElementById("dv-crop-cancel-button");i.addEventListener("click",(()=>{localStorage.removeItem("products"),i.style.visibility="hidden",a.style.visibility="visible";const n=document.getElementById("cropper");if(!n)return;const o=e=>{e.cropper.getCroppedCanvas().toBlob((async e=>{p(e,(async e=>{const i=await y(e);localStorage.setItem("products",JSON.stringify(i.products)),M(t),g(t,i.products),v(i.products.length||0)}))}))};e=new(k())(n,{checkCrossOrigin:!0,checkOrientation:!1,autoCropArea:.6,minContainerWidth:172,restore:!1,guides:!1,ready(){g(t,!0),o(this)},cropend(){g(t,!0),o(this)}})})),a.addEventListener("click",(async()=>{g(t,!0),i.style.visibility="visible",a.style.visibility="hidden",e.destroy();const n=document.getElementById("cropper").src,o=await y(n);g(t,o.products),v(o.products.length||0)}))},B=t=>!(t.size>=511e4&&(alert("Image must be smaller than 5.1 MB"),1)),T=(t,e)=>{localStorage.removeItem("products"),document.getElementById("dv-dialog-content").scrollTop=0;const i=document.getElementById("file-upload"),a=document.getElementById("file-upload-label"),n=e=>{p(e,(async i=>{const a="data:"+e.type+";base64, "+i;t.previewMode?(L(t,"result",a),window.navigateToSearchResult?window.navigateToSearchResult():console.error("[Delvify] navigateToSearchResult not defined.")):O(t,"result",a);const n=await y(i);localStorage.setItem("products",JSON.stringify(n.products)),M(t),g(t,n.products),v(n.products.length||0)}))};a.ondragover=a.ondragenter=function(t){t.preventDefault()},a.ondrop=async t=>{t.preventDefault();const e=t.dataTransfer.files[0];B(e)&&e&&e.type.includes("image/")&&n(e)},i.addEventListener("change",(i=>{const a=i.target.files||i.dataTransfer.files;if(1!==a.length)return alert("One image only");if(!B(a[0]))return;e?b():(g(t,!0),document.getElementById("file-upload-label").innerHTML='
');const o=a[0];n(o)}))},S=(t,i)=>{const a=t.props.visual_search.search_result.header,n=m(a),o=t.props.visual_search.search_result.results,s=o.items_per_row,r=`repeat(${s}, calc(${100/s}% - 6px))`;return`\n
\n
\n
\n
\n
\n close\n
\n
\n ${a.text||""}\n
\n
\n \n \n \n
\n \n \n
\n
\n
\n \n \n
\n
\n
\n
\n
\n
\n
\n close\n
\n
\n
\n Total Items: Loading items\n
\n
\n
\n
\n
\n
\n
\n
\n `},N=t=>{const i=t.props.visual_search.image_upload.header,a=m(i),n=t.props.visual_search.image_upload.description,o=m(n),s=t.props.visual_search.gallery,r=s.enabled,l=s.header,h=m(l),c=s.background_color,d=s.photos_to_show,p=s.photos,u=[];for(let i=1;i<=d;i++){const a=p.find((t=>t.position_on_widget===i));a?u.push(`\n
\n \n
\n `):u.push(`placeholder`)}return`\n
\n
\n
\n close\n
\n
\n
\n ${i.text||""}\n
\n
\n ${n.text||""}\n
\n
\n \n \n
\n
\n
\n ${r?`\n \n
\n close\n
\n
\n \n ${l.text}\n
\n
\n ${u.join("")}\n
\n
\n\n \n `:""}\n\n \n `},O=(t,i,a)=>{const n=document.getElementById("delvify-dialog");if("upload"===i)return n.innerHTML=N(t),D(t),T(t,!0),void(t=>{document.getElementById("dv-dialog-content").scrollTop=0;const i=document.getElementsByClassName("dv-sample-image");for(let a of i)a.addEventListener("click",(async i=>{localStorage.removeItem("products"),b();const a=i.target.src,{forRequesting:n,forShowing:o}=await u(a);if(!o)return void(document.getElementById("file-upload-label").innerHTML=`close\n
Drop your image here or
\n
browse
\n camera_icon\n

Select a Photo

`);const s=await y(n);t.previewMode?(L(t,"result",o),window.navigateToSearchResult?window.navigateToSearchResult():console.error("[Delvify] navigateToSearchResult not defined.")):O(t,"result",o),localStorage.setItem("products",JSON.stringify(s.products)),M(t),g(t,s.products),v(s.products.length||0)}))})(t);"result"===i&&(n.innerHTML=S(t,a),D(t),T(t,!1),$(t))},L=(t,e,i)=>{const a=document.getElementById("delvify-dialog-preview");return a.style.opacity=1,a.style.position="relative",a.style.top="auto",a.style.left="auto",a.style.transform="none",a.style.transition="none","upload"===e?(a.style.visibility="visible",a.innerHTML=N(t),void T(t,!0)):"result"===e?(a.style.visibility="visible",a.innerHTML=S(t,i),T(t,!1),void $(t)):(a.style.visibility="hidden",void(a.innerHTML=""))},I=class{constructor(t,e){const i=document.createElement("div"),a=document.createElement("div");this.previewMode=e,this.shadow=i,this.dialog=a,this.props=t,e||(this.initDialog(),D(this))}initDialog(){this.shadow.id="delvify-shadow",this.shadow.className="dv-shadow",this.shadow.onclick=()=>this.hideDialog(),document.body.appendChild(this.shadow),this.dialog.id="delvify-dialog",this.dialog.className="dv-dialog",this.dialog.style.opacity=0,document.body.appendChild(this.dialog),O(this,"upload")}showDialog(){localStorage.removeItem("products"),this.shadow.style.visibility="visible",this.shadow.style.opacity="0.5",this.dialog.style.visibility="visible",this.dialog.style.opacity="1",this.dialog.style.transform="translate(-50%, -50%) scale(1)"}hideDialog(){localStorage.removeItem("products"),this.shadow.style.opacity="0",setTimeout((()=>{this.shadow.style.visibility="hidden"}),200),this.dialog.style.opacity="0",this.dialog.style.transform="translate(-50%, -50%) scale(0.1)",setTimeout((()=>{this.dialog.style.visibility="hidden",O(this,"upload")}),200)}async renderDialog(t,e,i){if(e&&(this.props=e),i){let e,a;if(i.startsWith("http")){const{forRequesting:t,forShowing:n}=await u(i);if(!n)return;e=n,a=t}else e=i,a=i.split(";base64, ")[1];L(this,t,e);const n=await y(a);x(),g(this,n.products),v(n.products.length||0)}else L(this,t)}},H=function(){const t=document.createElement("script");t.type="text/javascript",t.id="delvify-cropperjs",t.src=e+"/cropper.min.js",document.head.appendChild(t);const i=document.createElement("link");i.rel="stylesheet",i.id="delvify-croppercss",i.href=e+"/cropper.min.css",document.head.appendChild(i)},_=function(t){const e=document.createElement("link");if(e.setAttribute("href",a),e.setAttribute("rel","stylesheet"),document.head.appendChild(e),!t)return window.DelvifyPreview=new I(t,!0),H(),console.log(`[Delvify Preview Mode] ${r} Widget Editor.`);!function(t){const e=t.visual_search.font_family,i=e.family||"",a=e.files||[],n=e.variants||[];a.forEach(((t,e)=>{const a=document.createElement("style");let o=n[e],s=!1;o.includes("italic")&&(o=o.replace("italic",""),s=!0),!o.includes("regular")&&o||(o="400");const r=`\n @font-face {\n font-family: '${i}';\n src: url('${t}') format("opentype");\n font-weight: ${o};\n font-style: ${s?"italic":"normal"};\n font-display: swap;\n }\n `;a.appendChild(document.createTextNode(r)),document.head.appendChild(a)}));const o=document.getElementById("dv-overwrite-style"),s=`\n .dv-dialog, .dv-dialog * {\n font-family: ${i} !important;\n }\n `;if(o)o.innerHTML=s;else{const t=document.createElement("style");t.id="dv-overwrite-style",t.innerHTML=s,document.head.appendChild(t)}}(t);const i=document.getElementById("delvify-tag");let n=t.visual_search.searchbar_dom,o=t.visual_search.searchbar_dom_mobile,s=t.visual_search.camera_position,l=t.visual_search.icon,c=-35,d=-35,p=0,u=0,m=10,g=!1;try{const e=t.camera_position;c=e.xOffset||c,d=e.xOffsetMobile||d,p=e.yOffset||p,u=e.yOffsetMobile||u,m=e.mobileThreshold||m,g=e.relativeFlag||g,screen.width`,e}(l),w=b.cloneNode(!0),x=getComputedStyle(f),M=parseInt(x.height,10)||0,D=parseInt(x.paddingTop,10)||0,C=2*parseInt(x.borderBlockWidth,10)||0;let E=parseFloat((C+M)/2)-(12+D)+p;if(b.style.marginTop=E+"px",y){const t=getComputedStyle(y)||0,e=parseInt(t.height,10)||0,i=parseInt(t.paddingTop,10)||0,a=2*parseInt(t.borderBlockWidth,10)||0,n=parseFloat((a+e)/2)-(12+i)+u;w.style.marginTop=n+"px"}const k=document.createElement("div");k.id="delvify-container",k.style.padding="0px",k.style.margin="0px",g&&(k.style.position="relative"),k.style.display="flex";const $=k.cloneNode(!0);k.appendChild(b),$.appendChild(w),$.id="delvify-container-mobile","left"===s?(f.prepend(k),b.style.left=c+"px",y&&y.prepend($),w.style.left=d+"px"):(f.append(k),b.style.right=c+"px",y&&y.append($),w.style.right=d+"px"),H();const B=new I(t),T=document.getElementsByClassName("delvify-camera");for(let t=0;tB.showDialog()));console.log(`[Delvify] ${r} Widget has been Activated.`)};async function W(){let t,e;if(!l.includes(window.location.hostname)){const a=document.getElementById("delvify-tag");if(!a)return console.error("[Delvify] No delvify-tag script ID is found.");if(t=a.getAttribute("api_key"),!t)return console.error("[Delvify] No API KEY is found.");const o=await(i=t,c(n,{apikey:i}));if(404===o.status)return console.error(`[Delvify] ${r} Invalid API KEY`);if(500===o.status)return console.log(`[Delvify] ${r} Waiting for initial configuration.`);e=await o.json()}var i;console.log("[Delvify] Initializing widget."),_(e)}"loading"!==document.readyState?W():document.addEventListener("DOMContentLoaded",(function(){W()}))})()})();