@vitraun/webar 0.1.7 → 0.1.8

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.
@@ -1 +1 @@
1
- (function(){"use strict";var w="VITRAUN_CONFIG",_="vtrn-vto-session",b=18e5,c=1e4,f="en-US",d=80;function o(t,e,i){var r=t.getAttribute(e);return r!=null&&r!==""?r:i}function h(t,e){if(t==null||t==="")return e;var i=String(t).toLowerCase();return i==="true"||i==="1"||i==="yes"}function p(t){if(t==null||t==="")return null;var e=parseFloat(String(t));return Number.isFinite(e)?e:null}function N(t){return!t||typeof t!="string"?[]:t.split(",").map(function(e){return e.trim()}).filter(Boolean)}function O(t,e){var i=o(t,e,"");if(!i||typeof i!="string")return null;try{return JSON.parse(i)}catch{return null}}function A(t){try{return JSON.parse(t)}catch{return null}}var g={"en-US":{INVALID_PUBLIC_API_KEY:"We could not open the virtual try-on. If the problem persists, contact the store.",PUBLIC_API_KEY_REQUIRED:"The virtual try-on is not available right now. Please try again later.",TRYON_EMBED_SESSION_TOKEN_MISSING:"We could not verify this session. Please refresh the page or contact the store.",TRYON_EMBED_SESSION_TOKEN_INVALID:"This session is no longer valid. Please refresh the page or start again.",TRYON_EMBED_SESSION_JWT_SECRET_NOT_CONFIGURED:"The virtual try-on is temporarily unavailable. Please try again later.",INVALID_OR_MISSING_MERCHANT_ID:"This integration is missing valid store credentials. Please contact the store.",INVALID_OR_MISSING_WIDGET_ID:"This integration is missing valid widget credentials. Please contact the store.",EMBED_INIT_MERCHANT_MISMATCH:"The store information does not match this widget. Please contact the store.",WIDGET_KEY_OR_CHANNEL_NOT_FOUND:"This widget could not be found or is no longer active. Please contact the store.",EMBED_PARENT_ORIGIN_REQUIRED:"We could not verify where this page is embedded. Please contact the store.",EMBED_PARENT_ORIGIN_NOT_ALLOWED:"This page is not allowed to use the virtual try-on. Please contact the store.",UNIQUE_CONSTRAINT_VIOLATION:"This value conflicts with an existing record. Change it and try again.",FOREIGN_KEY_VIOLATION:"This action references data that does not exist or cannot be linked. Check related records.",VALUE_OUT_OF_RANGE:"One of the values is invalid or too large for the server. Adjust the data and try again.",RECORD_NOT_FOUND:"The record was not found. It may have been removed \u2014 refresh the page and try again.",NULL_CONSTRAINT_VIOLATION:"A required field was empty. Fill in all required fields and try again.",MISSING_REQUIRED_VALUE:"Some required information is missing. Review the form and try again.",RELATION_CONSTRAINT_VIOLATION:"This change is not allowed because of how records are linked. Adjust relationships and try again.",TRANSACTION_CONFLICT:"The operation conflicted with another change. Please try again.",INVALID_DATABASE_INPUT:"The request could not be processed. Check the data format and try again.",UNEXPECTED_DATABASE_ERROR:"Something went wrong while saving. Try again or contact support if it continues."},"pt-BR":{INVALID_PUBLIC_API_KEY:"N\xE3o foi poss\xEDvel abrir o provador virtual. Se o problema continuar, fale com a loja.",PUBLIC_API_KEY_REQUIRED:"O provador virtual n\xE3o est\xE1 dispon\xEDvel no momento. Tente novamente mais tarde.",TRYON_EMBED_SESSION_TOKEN_MISSING:"N\xE3o foi poss\xEDvel verificar esta sess\xE3o. Atualize a p\xE1gina ou fale com a loja.",TRYON_EMBED_SESSION_TOKEN_INVALID:"Esta sess\xE3o n\xE3o \xE9 mais v\xE1lida. Atualize a p\xE1gina ou comece de novo.",TRYON_EMBED_SESSION_JWT_SECRET_NOT_CONFIGURED:"O provador virtual est\xE1 temporariamente indispon\xEDvel. Tente novamente mais tarde.",INVALID_OR_MISSING_MERCHANT_ID:"Esta integra\xE7\xE3o n\xE3o tem credenciais v\xE1lidas da loja. Fale com a loja.",INVALID_OR_MISSING_WIDGET_ID:"Esta integra\xE7\xE3o n\xE3o tem credenciais v\xE1lidas do widget. Fale com a loja.",EMBED_INIT_MERCHANT_MISMATCH:"As informa\xE7\xF5es da loja n\xE3o correspondem a este widget. Fale com a loja.",WIDGET_KEY_OR_CHANNEL_NOT_FOUND:"Este widget n\xE3o foi encontrado ou n\xE3o est\xE1 mais ativo. Fale com a loja.",EMBED_PARENT_ORIGIN_REQUIRED:"N\xE3o foi poss\xEDvel verificar onde esta p\xE1gina est\xE1 incorporada. Fale com a loja.",EMBED_PARENT_ORIGIN_NOT_ALLOWED:"Esta p\xE1gina n\xE3o tem permiss\xE3o para usar o provador virtual. Fale com a loja.",UNIQUE_CONSTRAINT_VIOLATION:"Este valor conflita com um registro j\xE1 existente. Altere e tente novamente.",FOREIGN_KEY_VIOLATION:"Esta a\xE7\xE3o referencia dados inexistentes ou que n\xE3o podem ser vinculados. Verifique os registros relacionados.",VALUE_OUT_OF_RANGE:"Um dos valores \xE9 inv\xE1lido ou muito grande para o servidor. Ajuste os dados e tente novamente.",RECORD_NOT_FOUND:"O registro n\xE3o foi encontrado. Pode ter sido removido \u2014 atualize a p\xE1gina e tente novamente.",NULL_CONSTRAINT_VIOLATION:"Um campo obrigat\xF3rio ficou vazio. Preencha todos os campos obrigat\xF3rios e tente novamente.",MISSING_REQUIRED_VALUE:"Falta informa\xE7\xE3o obrigat\xF3ria. Revise o formul\xE1rio e tente novamente.",RELATION_CONSTRAINT_VIOLATION:"Esta altera\xE7\xE3o n\xE3o \xE9 permitida por causa de como os registros est\xE3o vinculados. Ajuste as rela\xE7\xF5es e tente novamente.",TRANSACTION_CONFLICT:"A opera\xE7\xE3o conflitou com outra altera\xE7\xE3o. Tente novamente.",INVALID_DATABASE_INPUT:"A solicita\xE7\xE3o n\xE3o p\xF4de ser processada. Verifique o formato dos dados e tente novamente.",UNEXPECTED_DATABASE_ERROR:"Algo deu errado ao salvar. Tente novamente ou entre em contato com o suporte se continuar."}};function R(t,e,i){var r=m(i),s=g[r]||g["en-US"],a=t&&typeof t.errorCode=="string"?t.errorCode:null;if(a&&Object.prototype.hasOwnProperty.call(s,a))return s[a];var l=t&&typeof t.message=="string"?t.message.trim():"";if(l)return l;if(a)return r==="pt-BR"?"N\xE3o foi poss\xEDvel iniciar o provador virtual. Tente novamente ou fale com a loja.":"Could not start the virtual try-on. Please try again or contact the store.";if(e&&String(e).length>0&&String(e).length<600){var n=String(e).trim();return n.charAt(0)==="{"&&n.indexOf("errorCode")!==-1?r==="pt-BR"?"N\xE3o foi poss\xEDvel iniciar o provador virtual. Tente novamente.":"Could not start the virtual try-on. Please try again.":n}return r==="pt-BR"?"N\xE3o foi poss\xEDvel iniciar o provador virtual. Tente novamente.":"Could not start the virtual try-on. Please try again."}var I={"en-US":"We couldn't connect to the virtual try-on service. If you're developing locally, make sure the API is running, then try again.","pt-BR":"N\xE3o foi poss\xEDvel conectar ao servi\xE7o do provador virtual. Se estiver em ambiente de desenvolvimento, confirme se a API est\xE1 em execu\xE7\xE3o e tente de novo."};function m(t){var e=String(t||"").trim().toLowerCase();return e.indexOf("pt")===0?"pt-BR":"en-US"}function P(t){if(!t||typeof t.message!="string")return!1;var e=t.name,i=t.message.toLowerCase();return e==="TypeError"&&(i.indexOf("failed to fetch")!==-1||i.indexOf("load failed")!==-1)||i.indexOf("networkerror when attempting to fetch")!==-1||e==="NetworkError"||i.indexOf("network request failed")!==-1}function v(t,e){if(P(t)){var i=m(e);return I[i]||I["en-US"]}return t&&typeof t.message=="string"&&t.message.trim()?t.message.trim():m(e)==="pt-BR"?"N\xE3o foi poss\xEDvel iniciar o provador virtual. Tente novamente.":"Could not start the virtual try-on. Please try again."}function T(){return typeof window>"u"||!window.location||!window.location.origin?null:window.location.origin}function y(){return typeof window>"u"||!window.location||!window.location.href?null:window.location.href}function C(t){if(!t||typeof t!="string")return null;try{return new URL(t).origin}catch{return null}}function k(t){var e=String(t||"").trim().toLowerCase();if(!e)throw new Error("The env attribute is required.");if(!/^[a-z0-9-]+$/.test(e))throw new Error("The env attribute contains an invalid value.");return e}function U(t){return t?String(t).trim().toLowerCase():"web"}function S(t,e){if(t==null||t==="")return e;var i=parseInt(String(t),10);return!Number.isInteger(i)||i<=0||i>65535?e:i}function D(t,e){return"https://app."+t+".vitraun.com:"+e+"/v1/public/virtual-tryon-embed-init"}function L(t,e){return{merchantId:t.merchantId,widgetId:t.widgetId,tryonSessionId:e,app:{appId:t.appId,platform:t.platform,bundleId:t.bundleId,packageName:t.packageName,appVersion:t.appVersion,attestationToken:t.attestationToken},context:{origin:T(),pageUrl:y(),userAgent:typeof navigator<"u"&&navigator.userAgent?navigator.userAgent:null,referrer:typeof document<"u"&&document.referrer?document.referrer:null,timezone:typeof Intl<"u"&&Intl.DateTimeFormat?Intl.DateTimeFormat().resolvedOptions().timeZone:null}}}function M(t,e,i,r){var s=e||f,a="https://app."+t+".vitraun.com:"+r+"/"+encodeURIComponent(s)+"/virtual-tryon";return i&&(a+="?simulation=1"),a}function V(t,e,i,r){return!e||e<=0?t:new Promise(function(s,a){var l=!1,n=setTimeout(function(){if(!l){l=!0;try{r&&typeof r.abort=="function"&&r.abort()}catch{}a(new Error(i||"The operation timed out."))}},e);t.then(function(u){l||(l=!0,clearTimeout(n),s(u))}).catch(function(u){l||(l=!0,clearTimeout(n),a(u))})})}function E(){if(typeof window>"u"||!window.crypto||!window.crypto.randomUUID)return"00000000-0000-4000-8000-000000000000";try{var t=sessionStorage.getItem(_);if(t){var e=JSON.parse(t);if(e&&typeof e.id=="string"&&typeof e.exp=="number"&&Date.now()<e.exp)return e.id}}catch{}var i=window.crypto.randomUUID(),r=Date.now()+b;try{sessionStorage.setItem(_,JSON.stringify({id:i,exp:r}))}catch{}return i}class F extends HTMLElement{static get observedAttributes(){return["merchant-id","widget-id","env","api-port","app-port","lang","isolated-sku","apply-skus","flow","basket-opens-in","checkout-opens-in","use-simple-page","show-details","show-product-price","price-from","price-to","currency-symbol","is-simulation-mode","simulation-inline-config","container-min-height","app-id","platform","bundle-id","package-name","app-version","attestation-token","debug","init-timeout-ms"]}constructor(){super(),this.attachShadow({mode:"open"}),this._state={merchantId:"",widgetId:"",env:"",apiPort:d,appPort:d,lang:f,isolatedSku:null,applySkus:[],iframeOrigin:null,flow:"checkout",basketOpensIn:"event",checkoutOpensIn:"event",useSimplePage:!0,showDetails:!0,showProductPrice:!1,priceFrom:null,priceTo:null,currencySymbol:null,isSimulationMode:!1,simulationInlineConfig:null,appId:null,platform:"web",bundleId:null,packageName:null,appVersion:null,attestationToken:null,debug:!1,sessionToken:null,tryonSessionId:null,resolvedInitUrl:null,resolvedIframeUrl:null,initTimeoutMs:c},this._boundHandleMessage=this._handleMessage.bind(this),this._initPromise=null,this._initStateKey=null,this._activeInitRequestId=0,this._renderVersion=0,this._abortController=null}connectedCallback(){this._readAttributes(),this._render(),typeof window<"u"&&window.addEventListener("message",this._boundHandleMessage)}disconnectedCallback(){if(typeof window<"u"&&window.removeEventListener("message",this._boundHandleMessage),this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch{}}attributeChangedCallback(e,i,r){i!==r&&(this._readAttributes(),this._render())}_log(){if(!(!this._state.debug||typeof console>"u"||!console.log)){var e=Array.prototype.slice.call(arguments);e.unshift("[vitraun-vto]"),console.log.apply(console,e)}}_readAttributes(){var e=O(this,"simulation-inline-config"),i=!1;e&&e.features&&typeof e.features.showProductPrice=="boolean"&&(i=e.features.showProductPrice);var r=!0;e&&e.features&&typeof e.features.useSimplePage=="boolean"&&(r=e.features.useSimplePage);var s="checkout";e&&e.features&&(e.features.flow==="catalog"||e.features.flow==="checkout")&&(s=e.features.flow);var a=!0;e&&e.features&&typeof e.features.showDetails=="boolean"&&(a=e.features.showDetails);var l="";try{l=k(o(this,"env",""))}catch{l=""}var n=parseInt(o(this,"init-timeout-ms",String(c)),10);(!Number.isFinite(n)||n<0)&&(n=c),this._state={merchantId:o(this,"merchant-id",""),widgetId:o(this,"widget-id",""),env:l,apiPort:S(o(this,"api-port",String(d)),d),appPort:S(o(this,"app-port",String(d)),d),lang:o(this,"lang",f),isolatedSku:o(this,"isolated-sku",null)||null,applySkus:N(o(this,"apply-skus","")),iframeOrigin:this._state&&this._state.iframeOrigin?this._state.iframeOrigin:null,flow:o(this,"flow",s),basketOpensIn:o(this,"basket-opens-in","event"),checkoutOpensIn:o(this,"checkout-opens-in","event"),useSimplePage:h(o(this,"use-simple-page",""),r),showDetails:h(o(this,"show-details",""),a),showProductPrice:h(o(this,"show-product-price",""),i),priceFrom:p(o(this,"price-from",null)),priceTo:p(o(this,"price-to",null)),currencySymbol:o(this,"currency-symbol",null)||null,isSimulationMode:h(o(this,"is-simulation-mode","false"),!1),simulationInlineConfig:e,appId:o(this,"app-id",null)||null,platform:U(o(this,"platform",null)),bundleId:o(this,"bundle-id",null)||null,packageName:o(this,"package-name",null)||null,appVersion:o(this,"app-version",null)||null,attestationToken:o(this,"attestation-token",null)||null,debug:h(o(this,"debug","false"),!1),sessionToken:this._state&&this._state.sessionToken?this._state.sessionToken:null,tryonSessionId:this._state&&this._state.tryonSessionId?this._state.tryonSessionId:null,resolvedInitUrl:this._state&&this._state.resolvedInitUrl?this._state.resolvedInitUrl:null,resolvedIframeUrl:this._state&&this._state.resolvedIframeUrl?this._state.resolvedIframeUrl:null,initTimeoutMs:n}}_emit(e,i){this.dispatchEvent(new CustomEvent(e,{detail:i??null,bubbles:!0,composed:!0}))}_setStatus(e,i){this.setAttribute("data-status",e),this._emit("statusChange",{status:e,detail:i||null})}_getIframeElement(){return this.shadowRoot?this.shadowRoot.querySelector("iframe"):null}_handleMessage(e){var i=e.data;if(!(!i||typeof i!="object")){var r=this._getIframeElement();if(!(!r||!r.contentWindow)&&e.source===r.contentWindow&&!(!this._state.iframeOrigin||e.origin!==this._state.iframeOrigin)){var s=i.type,a=i.detail;if(s==="VTO_USAGE"){this._emit("vtoUsage",a);return}var l=["addToCart","removeFromCart","redirectToCart","analysisFinished"];l.indexOf(s)!==-1&&this._emit(s,a)}}}_getInitStateKey(){return JSON.stringify({merchantId:this._state.merchantId,widgetId:this._state.widgetId,env:this._state.env,apiPort:this._state.apiPort,appPort:this._state.appPort,lang:this._state.lang,isolatedSku:this._state.isolatedSku,applySkus:this._state.applySkus,flow:this._state.flow,basketOpensIn:this._state.basketOpensIn,checkoutOpensIn:this._state.checkoutOpensIn,useSimplePage:this._state.useSimplePage,showDetails:this._state.showDetails,showProductPrice:this._state.showProductPrice,priceFrom:this._state.priceFrom,priceTo:this._state.priceTo,currencySymbol:this._state.currencySymbol,isSimulationMode:this._state.isSimulationMode,simulationInlineConfig:this._state.simulationInlineConfig,appId:this._state.appId,platform:this._state.platform,bundleId:this._state.bundleId,packageName:this._state.packageName,appVersion:this._state.appVersion,attestationToken:this._state.attestationToken})}_buildResolvedUrls(){if(!this._state.env)throw new Error("The env attribute is required.");var e=M(this._state.env,this._state.lang,this._state.isSimulationMode,this._state.appPort);return{initUrl:D(this._state.env,this._state.apiPort),iframeUrl:e,iframeOrigin:C(e)}}_buildInitPayload(){var e=E();return{tryonSessionId:e,initRequestBody:L(this._state,e)}}_normalizeInitResponse(e,i,r){if(!e||typeof e!="object")throw new Error("Invalid init response.");var s=typeof e.sessionToken=="string"&&e.sessionToken?e.sessionToken:null,a=typeof e.tryonSessionId=="string"&&e.tryonSessionId?e.tryonSessionId:r;if(!s)throw new Error("The init API did not return sessionToken.");return{sessionToken:s,tryonSessionId:a,initUrl:i.initUrl,iframeUrl:i.iframeUrl,iframeOrigin:i.iframeOrigin}}_initializeSessionIfNeeded(){var e=this;if(!this._state.merchantId)return Promise.reject(new Error("The merchant-id attribute is required."));if(!this._state.widgetId)return Promise.reject(new Error("The widget-id attribute is required."));if(!this._state.env)return Promise.reject(new Error("The env attribute is required."));var i=this._getInitStateKey();if(this._initPromise&&this._initStateKey===i)return this._initPromise;if(this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch{}this._initStateKey=i,this._activeInitRequestId+=1;var r=this._activeInitRequestId;this._setStatus("loading");var s;try{s=this._buildResolvedUrls()}catch(n){return Promise.reject(n)}var a=this._buildInitPayload();this._state.tryonSessionId=a.tryonSessionId,this._abortController=typeof AbortController<"u"?new AbortController:null;var l=fetch(s.initUrl,{method:"POST",headers:{"Content-Type":"application/json","X-Merchant-Id":this._state.merchantId,"X-Widget-Id":this._state.widgetId},body:JSON.stringify(a.initRequestBody),signal:this._abortController?this._abortController.signal:void 0}).then(function(n){return n.ok?n.json():n.text().then(function(u){var x=A(u),B=R(x,u,e._state.lang);throw new Error(B)})}).then(function(n){return e._normalizeInitResponse(n,s,a.tryonSessionId)});return this._initPromise=V(l,this._state.initTimeoutMs,"Timed out while initializing the Vitraun session.",this._abortController).then(function(n){return r!==e._activeInitRequestId||(e._state.sessionToken=n.sessionToken,e._state.tryonSessionId=n.tryonSessionId,e._state.resolvedInitUrl=n.initUrl,e._state.resolvedIframeUrl=n.iframeUrl,e._state.iframeOrigin=n.iframeOrigin,e._setStatus("ready")),n}).catch(function(n){if(r!==e._activeInitRequestId)throw n;var u=v(n,e._state.lang);throw e._state.sessionToken=null,e._state.resolvedInitUrl=null,e._state.resolvedIframeUrl=null,e._state.iframeOrigin=null,e._setStatus("error",{message:u}),new Error(u)}).finally(function(){r===e._activeInitRequestId&&(e._initPromise=null)}),this._initPromise}_sendConfigToIframe(){var e=this._getIframeElement();if(!(!e||!e.contentWindow)){var i=this._state.iframeOrigin;if(!i){this._log("Config not sent: iframeOrigin is missing.");return}var r={merchantId:this._state.merchantId,widgetId:this._state.widgetId,sessionToken:this._state.sessionToken,tryonSessionId:this._state.tryonSessionId||E(),lang:this._state.lang,isolatedSku:this._state.isolatedSku,applySkus:this._state.applySkus,flow:this._state.flow,basketOpensIn:this._state.basketOpensIn,checkoutOpensIn:this._state.checkoutOpensIn,useSimplePage:this._state.useSimplePage,showDetails:this._state.showDetails,showProductPrice:this._state.showProductPrice,priceFrom:this._state.priceFrom,priceTo:this._state.priceTo,currencySymbol:this._state.currencySymbol,isSimulationMode:this._state.isSimulationMode,app:{appId:this._state.appId,platform:this._state.platform,bundleId:this._state.bundleId,packageName:this._state.packageName,appVersion:this._state.appVersion,attestationToken:this._state.attestationToken},hostPageOrigin:T(),hostPageUrl:y()};this._state.isSimulationMode&&this._state.simulationInlineConfig&&typeof this._state.simulationInlineConfig=="object"&&(r.inlineVirtualTryonConfig=this._state.simulationInlineConfig),e.contentWindow.postMessage({type:w,payload:r},i)}}_renderLoading(){if(this.shadowRoot){var e=o(this,"container-min-height","80vh");this.shadowRoot.innerHTML="";var i=document.createElement("style");i.textContent=":host { display:block; width:100%; min-height:"+e+"; box-sizing:border-box; }.vitraun-loading {min-height:"+e+";display:flex;align-items:center;justify-content:center;border:1px solid #ececec;background:#fafafa;color:#333;font:14px/1.4 Arial, sans-serif;padding:16px;box-sizing:border-box;border-radius:8px;text-align:center;}";var r=document.createElement("div");r.className="vitraun-loading",r.textContent="Loading Vitraun...",this.shadowRoot.appendChild(i),this.shadowRoot.appendChild(r)}}_renderError(e){if(this.shadowRoot){var i=o(this,"container-min-height","80vh");this.shadowRoot.innerHTML="";var r=document.createElement("style");r.textContent=":host { display:block; width:100%; min-height:"+i+"; box-sizing:border-box; }.vitraun-error {min-height:"+i+";display:flex;align-items:center;justify-content:center;border:1px solid #f1d5d5;background:#fff7f7;color:#7a1f1f;font:14px/1.4 Arial, sans-serif;padding:16px;box-sizing:border-box;border-radius:8px;text-align:center;}";var s=document.createElement("div");s.className="vitraun-error",s.textContent=e||"Failed to load Vitraun.",this.shadowRoot.appendChild(r),this.shadowRoot.appendChild(s)}}_renderIframe(e,i){if(this.shadowRoot){var r=this,s=o(this,"container-min-height","80vh");this.shadowRoot.innerHTML="";var a=document.createElement("style");a.textContent=":host { display:block; width:100%; min-height:"+s+"; box-sizing:border-box; }";var l=document.createElement("iframe");l.src=e,l.title="Vitraun VTO",l.style.cssText="width:100%;height:100%;border:0;min-height:"+s,l.setAttribute("allow","camera"),l.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),l.onload=function(){i===r._renderVersion&&[0,50,150,400,1e3].forEach(function(n){setTimeout(function(){i===r._renderVersion&&r._sendConfigToIframe()},n)})},this.shadowRoot.appendChild(a),this.shadowRoot.appendChild(l)}}_render(){if(this.shadowRoot){this._renderVersion+=1;var e=this._renderVersion;if(!this._state.merchantId){this._setStatus("error",{message:"The merchant-id attribute is required."}),this._renderError("The merchant-id attribute is required.");return}if(!this._state.widgetId){this._setStatus("error",{message:"The widget-id attribute is required."}),this._renderError("The widget-id attribute is required.");return}if(!this._state.env){this._setStatus("error",{message:"The env attribute is required."}),this._renderError("The env attribute is required.");return}this._renderLoading(),this._initializeSessionIfNeeded().then(function(i){e===this._renderVersion&&this._renderIframe(i.iframeUrl,e)}.bind(this)).catch(function(i){if(e===this._renderVersion){var r=v(i instanceof Error?i:new Error(String(i)),this._state.lang);this._renderError(r)}}.bind(this))}}open(){return this.style.display="",Promise.resolve()}close(){return this.style.display="none",Promise.resolve()}}typeof customElements<"u"&&!customElements.get("vitraun-vto")&&customElements.define("vitraun-vto",F)})();
1
+ (function(){"use strict";var b="VITRAUN_CONFIG",N="vtrn-vto-session",M=18e5,E=1e4,T="en-US",h="Vitraun",S="vitraun",f="https://",L="app.",G="app.",A="."+S+".com",k="/v1/public/virtual-tryon-embed-init",V="/virtual-tryon",F="Content-Type",H="X-Origin",W="X-Tryon-Session-Id",K="X-Merchant-Id",B="X-Widget-Id",x="application/json",Y="00000000-0000-0000-0000-000000000000",q=["addToCart","removeFromCart","redirectToCart","analysisFinished"],g="vitraun-vto",Q="["+g+"]",O=S+"-loading",R=S+"-error",X=h+" VTO",z="Loading "+h+"...",J="Failed to load "+h+".",j="Timed out while initializing the "+h+" session.",r={MERCHANT_ID:"merchant-id",WIDGET_ID:"widget-id",ENV:"env",API_PORT:"api-port",APP_PORT:"app-port",LANG:"lang",ISOLATED_SKU:"isolated-sku",APPLY_SKUS:"apply-skus",FLOW:"flow",BASKET_OPENS_IN:"basket-opens-in",CHECKOUT_OPENS_IN:"checkout-opens-in",USE_SIMPLE_PAGE:"use-simple-page",SHOW_DETAILS:"show-details",SHOW_PRODUCT_PRICE:"show-product-price",PRICE_FROM:"price-from",PRICE_TO:"price-to",CURRENCY_SYMBOL:"currency-symbol",IS_SIMULATION_MODE:"is-simulation-mode",SIMULATION_INLINE_CONFIG:"simulation-inline-config",CONTAINER_MIN_HEIGHT:"container-min-height",APP_ID:"app-id",PLATFORM:"platform",BUNDLE_ID:"bundle-id",PACKAGE_NAME:"package-name",APP_VERSION:"app-version",ATTESTATION_TOKEN:"attestation-token",DEBUG:"debug",INIT_TIMEOUT_MS:"init-timeout-ms"},Z=[r.MERCHANT_ID,r.WIDGET_ID,r.ENV,r.API_PORT,r.APP_PORT,r.LANG,r.ISOLATED_SKU,r.APPLY_SKUS,r.FLOW,r.BASKET_OPENS_IN,r.CHECKOUT_OPENS_IN,r.USE_SIMPLE_PAGE,r.SHOW_DETAILS,r.SHOW_PRODUCT_PRICE,r.PRICE_FROM,r.PRICE_TO,r.CURRENCY_SYMBOL,r.IS_SIMULATION_MODE,r.SIMULATION_INLINE_CONFIG,r.CONTAINER_MIN_HEIGHT,r.APP_ID,r.PLATFORM,r.BUNDLE_ID,r.PACKAGE_NAME,r.APP_VERSION,r.ATTESTATION_TOKEN,r.DEBUG,r.INIT_TIMEOUT_MS],u={ENV_REQUIRED:"The env attribute is required.",ENV_INVALID:"The env attribute contains an invalid value.",MERCHANT_ID_REQUIRED:"The merchant-id attribute is required.",WIDGET_ID_REQUIRED:"The widget-id attribute is required.",INIT_INVALID_RESPONSE:"Invalid init response.",INIT_SESSION_TOKEN_MISSING:"The init API did not return sessionToken."},$="The operation timed out.",tt={CONFIG_SKIPPED_NO_IFRAME_ORIGIN:"Config not sent: iframeOrigin is missing."},c={GENERIC_TRY_AGAIN_OR_STORE:"Could not start the virtual try-on. Please try again or contact the store.",GENERIC_TRY_AGAIN:"Could not start the virtual try-on. Please try again."},et="We couldn't connect to the virtual try-on service. If you are developing locally, make sure the API is running, then try again.",v={INVALID_PUBLIC_API_KEY:"We could not open the virtual try-on. If the problem persists, contact the store.",PUBLIC_API_KEY_REQUIRED:"The virtual try-on is not available right now. Please try again later.",TRYON_EMBED_SESSION_TOKEN_MISSING:"We could not verify this session. Please refresh the page or contact the store.",TRYON_EMBED_SESSION_TOKEN_INVALID:"This session is no longer valid. Please refresh the page or start again.",TRYON_EMBED_SESSION_JWT_SECRET_NOT_CONFIGURED:"The virtual try-on is temporarily unavailable. Please try again later.",INVALID_OR_MISSING_MERCHANT_ID:"This integration is missing valid store credentials. Please contact the store.",INVALID_OR_MISSING_WIDGET_ID:"This integration is missing valid widget credentials. Please contact the store.",EMBED_INIT_MERCHANT_MISMATCH:"The store information does not match this widget. Please contact the store.",WIDGET_KEY_OR_CHANNEL_NOT_FOUND:"This widget could not be found or is no longer active. Please contact the store.",EMBED_PARENT_ORIGIN_REQUIRED:"We could not verify where this page is embedded. Please contact the store.",EMBED_PARENT_ORIGIN_NOT_ALLOWED:"This page is not allowed to use the virtual try-on. Please contact the store.",UNIQUE_CONSTRAINT_VIOLATION:"This value conflicts with an existing record. Change it and try again.",FOREIGN_KEY_VIOLATION:"This action references data that does not exist or cannot be linked. Check related records.",VALUE_OUT_OF_RANGE:"One of the values is invalid or too large for the server. Adjust the data and try again.",RECORD_NOT_FOUND:"The record was not found. It may have been removed. Refresh the page and try again.",NULL_CONSTRAINT_VIOLATION:"A required field was empty. Fill in all required fields and try again.",MISSING_REQUIRED_VALUE:"Some required information is missing. Review the form and try again.",RELATION_CONSTRAINT_VIOLATION:"This change is not allowed because of how records are linked. Adjust relationships and try again.",TRANSACTION_CONFLICT:"The operation conflicted with another change. Please try again.",INVALID_DATABASE_INPUT:"The request could not be processed. Check the data format and try again.",UNEXPECTED_DATABASE_ERROR:"Something went wrong while saving. Try again or contact support if it continues."};function m(e){return":host { display:block; width:100%; min-height:"+e+"; box-sizing:border-box; }"}function it(e,t){return m(e)+"."+t+" {min-height:"+e+";display:flex;align-items:center;justify-content:center;border:1px solid #ececec;background:#fafafa;color:#333;font:14px/1.4 Arial, sans-serif;padding:16px;box-sizing:border-box;border-radius:8px;text-align:center;}"}function rt(e,t){return m(e)+"."+t+" {min-height:"+e+";display:flex;align-items:center;justify-content:center;border:1px solid #f1d5d5;background:#fff7f7;color:#7a1f1f;font:14px/1.4 Arial, sans-serif;padding:16px;box-sizing:border-box;border-radius:8px;text-align:center;}"}function o(e,t,i){var n=e.getAttribute(t);return n!=null&&n!==""?n:i}function d(e,t){if(e==null||e==="")return t;var i=String(e).toLowerCase();return i==="true"||i==="1"||i==="yes"}function P(e){if(e==null||e==="")return null;var t=parseFloat(String(e));return Number.isFinite(t)?t:null}function nt(e){return!e||typeof e!="string"?[]:e.split(",").map(function(t){return t.trim()}).filter(Boolean)}function st(e,t){var i=o(e,t,"");if(!i||typeof i!="string")return null;try{return JSON.parse(i)}catch{return null}}function ot(e){try{return JSON.parse(e)}catch{return null}}function p(){return typeof window>"u"||!window.location||!window.location.origin?null:window.location.origin}function y(){return typeof window>"u"||!window.location||!window.location.href?null:window.location.href}function at(e){if(!e||typeof e!="string")return null;try{return new URL(e).origin}catch{return null}}function lt(e){var t=String(e||"").trim().toLowerCase();if(!t)throw new Error(u.ENV_REQUIRED);if(!/^[a-z0-9-]+$/.test(t))throw new Error(u.ENV_INVALID);return t}function _t(e){return e?String(e).trim().toLowerCase():"web"}function w(e){if(e==null||e==="")return null;var t=parseInt(String(e),10);return!Number.isInteger(t)||t<=0||t>65535?null:t}function C(e,t){if(e==null||e==="")return"";var i=parseInt(String(e),10);return!Number.isInteger(i)||i<=0||i>65535||t==="https://"&&i===443||t==="http://"&&i===80?"":":"+i}function ut(e,t){var i=e&&typeof e.errorCode=="string"?e.errorCode:null;if(i&&Object.prototype.hasOwnProperty.call(v,i))return v[i];var n=e&&typeof e.message=="string"?e.message.trim():"";if(n)return n;if(i)return c.GENERIC_TRY_AGAIN_OR_STORE;if(t&&String(t).length>0&&String(t).length<600){var s=String(t).trim();return s.charAt(0)==="{"&&s.indexOf("errorCode")!==-1?c.GENERIC_TRY_AGAIN:s}return c.GENERIC_TRY_AGAIN}function It(e){if(!e||typeof e.message!="string")return!1;var t=e.name,i=e.message.toLowerCase();return t==="TypeError"&&(i.indexOf("failed to fetch")!==-1||i.indexOf("load failed")!==-1)||i.indexOf("networkerror when attempting to fetch")!==-1||t==="NetworkError"||i.indexOf("network request failed")!==-1}function U(e){return It(e)?et:e&&typeof e.message=="string"&&e.message.trim()?e.message.trim():c.GENERIC_TRY_AGAIN}function dt(e,t){return f+L+e+A+C(t,f)+k}function ht(e,t,i,n){var s=t||T,l=f+G+e+A+C(n,f)+"/"+encodeURIComponent(s)+V;return i&&(l+="?simulation=1"),l}function ft(e){var t=e.merchantId!=null?String(e.merchantId):"",i=e.widgetId!=null?String(e.widgetId):"",n=e.tryonSessionId!=null?String(e.tryonSessionId):"",s=e.origin!==void 0&&e.origin!==null&&e.origin!==""?String(e.origin):p()||"",l={};return l[H]=s,l[W]=n,l[K]=t,l[B]=i,e.contentType&&(l[F]=e.contentType),l}function ct(e,t){return{merchantId:e.merchantId,widgetId:e.widgetId,tryonSessionId:t,app:{appId:e.appId,platform:e.platform,bundleId:e.bundleId,packageName:e.packageName,appVersion:e.appVersion,attestationToken:e.attestationToken},context:{hostPageOrigin:p(),hostPageUrl:y(),userAgent:typeof navigator<"u"&&navigator.userAgent?navigator.userAgent:null,referrer:typeof document<"u"&&document.referrer?document.referrer:null,timezone:typeof Intl<"u"&&Intl.DateTimeFormat?Intl.DateTimeFormat().resolvedOptions().timeZone:null}}}function Et(e,t,i,n){return!t||t<=0?e:new Promise(function(s,l){var _=!1,a=setTimeout(function(){if(!_){_=!0;try{n&&typeof n.abort=="function"&&n.abort()}catch{}l(new Error(i||$))}},t);e.then(function(I){_||(_=!0,clearTimeout(a),s(I))}).catch(function(I){_||(_=!0,clearTimeout(a),l(I))})})}function D(){if(typeof window>"u"||!window.crypto||!window.crypto.randomUUID)return Y;try{var e=sessionStorage.getItem(N);if(e){var t=JSON.parse(e);if(t&&typeof t.id=="string"&&typeof t.exp=="number"&&Date.now()<t.exp)return t.id}}catch{}var i=window.crypto.randomUUID(),n=Date.now()+M;try{sessionStorage.setItem(N,JSON.stringify({id:i,exp:n}))}catch{}return i}class Tt extends HTMLElement{static get observedAttributes(){return Z.slice()}constructor(){super(),this.attachShadow({mode:"open"}),this._state={merchantId:"",widgetId:"",env:"",apiPort:null,appPort:null,lang:T,isolatedSku:null,applySkus:[],iframeOrigin:null,flow:"checkout",basketOpensIn:"event",checkoutOpensIn:"event",useSimplePage:!0,showDetails:!0,showProductPrice:!1,priceFrom:null,priceTo:null,currencySymbol:null,isSimulationMode:!1,simulationInlineConfig:null,appId:null,platform:"web",bundleId:null,packageName:null,appVersion:null,attestationToken:null,debug:!1,sessionToken:null,tryonSessionId:null,resolvedInitUrl:null,resolvedIframeUrl:null,initTimeoutMs:E},this._boundHandleMessage=this._handleMessage.bind(this),this._initPromise=null,this._initStateKey=null,this._activeInitRequestId=0,this._renderVersion=0,this._abortController=null}connectedCallback(){this._readAttributes(),this._render(),typeof window<"u"&&window.addEventListener("message",this._boundHandleMessage)}disconnectedCallback(){if(typeof window<"u"&&window.removeEventListener("message",this._boundHandleMessage),this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch{}}attributeChangedCallback(t,i,n){i!==n&&(this._readAttributes(),this._render())}_log(){if(!(!this._state.debug||typeof console>"u"||!console.log)){var t=Array.prototype.slice.call(arguments);t.unshift(Q),console.log.apply(console,t)}}_readAttributes(){var t=st(this,r.SIMULATION_INLINE_CONFIG),i=!1;t&&t.features&&typeof t.features.showProductPrice=="boolean"&&(i=t.features.showProductPrice);var n=!0;t&&t.features&&typeof t.features.useSimplePage=="boolean"&&(n=t.features.useSimplePage);var s="checkout";t&&t.features&&(t.features.flow==="catalog"||t.features.flow==="checkout")&&(s=t.features.flow);var l=!0;t&&t.features&&typeof t.features.showDetails=="boolean"&&(l=t.features.showDetails);var _="";try{_=lt(o(this,r.ENV,""))}catch{_=""}var a=parseInt(o(this,r.INIT_TIMEOUT_MS,String(E)),10);(!Number.isFinite(a)||a<0)&&(a=E),this._state={merchantId:o(this,r.MERCHANT_ID,""),widgetId:o(this,r.WIDGET_ID,""),env:_,apiPort:w(o(this,r.API_PORT,null)),appPort:w(o(this,r.APP_PORT,null)),lang:o(this,r.LANG,T),isolatedSku:o(this,r.ISOLATED_SKU,null)||null,applySkus:nt(o(this,r.APPLY_SKUS,"")),iframeOrigin:this._state&&this._state.iframeOrigin?this._state.iframeOrigin:null,flow:o(this,r.FLOW,s),basketOpensIn:o(this,r.BASKET_OPENS_IN,"event"),checkoutOpensIn:o(this,r.CHECKOUT_OPENS_IN,"event"),useSimplePage:d(o(this,r.USE_SIMPLE_PAGE,""),n),showDetails:d(o(this,r.SHOW_DETAILS,""),l),showProductPrice:d(o(this,r.SHOW_PRODUCT_PRICE,""),i),priceFrom:P(o(this,r.PRICE_FROM,null)),priceTo:P(o(this,r.PRICE_TO,null)),currencySymbol:o(this,r.CURRENCY_SYMBOL,null)||null,isSimulationMode:d(o(this,r.IS_SIMULATION_MODE,"false"),!1),simulationInlineConfig:t,appId:o(this,r.APP_ID,null)||null,platform:_t(o(this,r.PLATFORM,null)),bundleId:o(this,r.BUNDLE_ID,null)||null,packageName:o(this,r.PACKAGE_NAME,null)||null,appVersion:o(this,r.APP_VERSION,null)||null,attestationToken:o(this,r.ATTESTATION_TOKEN,null)||null,debug:d(o(this,r.DEBUG,"false"),!1),sessionToken:this._state&&this._state.sessionToken?this._state.sessionToken:null,tryonSessionId:this._state&&this._state.tryonSessionId?this._state.tryonSessionId:null,resolvedInitUrl:this._state&&this._state.resolvedInitUrl?this._state.resolvedInitUrl:null,resolvedIframeUrl:this._state&&this._state.resolvedIframeUrl?this._state.resolvedIframeUrl:null,initTimeoutMs:a}}_emit(t,i){this.dispatchEvent(new CustomEvent(t,{detail:i??null,bubbles:!0,composed:!0}))}_setStatus(t,i){this.setAttribute("data-status",t),this._emit("statusChange",{status:t,detail:i||null})}_getIframeElement(){return this.shadowRoot?this.shadowRoot.querySelector("iframe"):null}_handleMessage(t){var i=t.data;if(!(!i||typeof i!="object")){var n=this._getIframeElement();if(!(!n||!n.contentWindow)&&t.source===n.contentWindow&&!(!this._state.iframeOrigin||t.origin!==this._state.iframeOrigin)){var s=i.type,l=i.detail;if(s==="VTO_USAGE"){this._emit("vtoUsage",l);return}q.indexOf(s)!==-1&&this._emit(s,l)}}}_getInitStateKey(){return JSON.stringify({merchantId:this._state.merchantId,widgetId:this._state.widgetId,env:this._state.env,apiPort:this._state.apiPort,appPort:this._state.appPort,lang:this._state.lang,isolatedSku:this._state.isolatedSku,applySkus:this._state.applySkus,flow:this._state.flow,basketOpensIn:this._state.basketOpensIn,checkoutOpensIn:this._state.checkoutOpensIn,useSimplePage:this._state.useSimplePage,showDetails:this._state.showDetails,showProductPrice:this._state.showProductPrice,priceFrom:this._state.priceFrom,priceTo:this._state.priceTo,currencySymbol:this._state.currencySymbol,isSimulationMode:this._state.isSimulationMode,simulationInlineConfig:this._state.simulationInlineConfig,appId:this._state.appId,platform:this._state.platform,bundleId:this._state.bundleId,packageName:this._state.packageName,appVersion:this._state.appVersion,attestationToken:this._state.attestationToken})}_buildResolvedUrls(){if(!this._state.env)throw new Error(u.ENV_REQUIRED);var t=ht(this._state.env,this._state.lang,this._state.isSimulationMode,this._state.appPort);return{initUrl:dt(this._state.env,this._state.apiPort),iframeUrl:t,iframeOrigin:at(t)}}_buildInitPayload(){var t=D();return{tryonSessionId:t,initRequestBody:ct(this._state,t)}}_normalizeInitResponse(t,i,n){if(!t||typeof t!="object")throw new Error(u.INIT_INVALID_RESPONSE);var s=typeof t.sessionToken=="string"&&t.sessionToken?t.sessionToken:null,l=typeof t.tryonSessionId=="string"&&t.tryonSessionId?t.tryonSessionId:n;if(!s)throw new Error(u.INIT_SESSION_TOKEN_MISSING);return{sessionToken:s,tryonSessionId:l,initUrl:i.initUrl,iframeUrl:i.iframeUrl,iframeOrigin:i.iframeOrigin}}_initializeSessionIfNeeded(){var t=this;if(!this._state.merchantId)return Promise.reject(new Error(u.MERCHANT_ID_REQUIRED));if(!this._state.widgetId)return Promise.reject(new Error(u.WIDGET_ID_REQUIRED));if(!this._state.env)return Promise.reject(new Error(u.ENV_REQUIRED));var i=this._getInitStateKey();if(this._initPromise&&this._initStateKey===i)return this._initPromise;if(this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch{}this._initStateKey=i,this._activeInitRequestId+=1;var n=this._activeInitRequestId;this._setStatus("loading");var s;try{s=this._buildResolvedUrls()}catch(a){return Promise.reject(a)}var l=this._buildInitPayload();this._state.tryonSessionId=l.tryonSessionId,this._abortController=typeof AbortController<"u"?new AbortController:null;var _=fetch(s.initUrl,{method:"POST",headers:ft({merchantId:this._state.merchantId,widgetId:this._state.widgetId,tryonSessionId:l.tryonSessionId,contentType:x}),body:JSON.stringify(l.initRequestBody),signal:this._abortController?this._abortController.signal:void 0}).then(function(a){return a.ok?a.json():a.text().then(function(I){var St=ot(I),gt=ut(St,I);throw new Error(gt)})}).then(function(a){return t._normalizeInitResponse(a,s,l.tryonSessionId)});return this._initPromise=Et(_,this._state.initTimeoutMs,j,this._abortController).then(function(a){return n!==t._activeInitRequestId||(t._state.sessionToken=a.sessionToken,t._state.tryonSessionId=a.tryonSessionId,t._state.resolvedInitUrl=a.initUrl,t._state.resolvedIframeUrl=a.iframeUrl,t._state.iframeOrigin=a.iframeOrigin,t._setStatus("ready")),a}).catch(function(a){if(n!==t._activeInitRequestId)throw a;var I=U(a);throw t._state.sessionToken=null,t._state.resolvedInitUrl=null,t._state.resolvedIframeUrl=null,t._state.iframeOrigin=null,t._setStatus("error",{message:I}),new Error(I)}).finally(function(){n===t._activeInitRequestId&&(t._initPromise=null)}),this._initPromise}_sendConfigToIframe(){var t=this._getIframeElement();if(!(!t||!t.contentWindow)){var i=this._state.iframeOrigin;if(!i){this._log(tt.CONFIG_SKIPPED_NO_IFRAME_ORIGIN);return}var n={merchantId:this._state.merchantId,widgetId:this._state.widgetId,sessionToken:this._state.sessionToken,tryonSessionId:this._state.tryonSessionId||D(),lang:this._state.lang,isolatedSku:this._state.isolatedSku,applySkus:this._state.applySkus,flow:this._state.flow,basketOpensIn:this._state.basketOpensIn,checkoutOpensIn:this._state.checkoutOpensIn,useSimplePage:this._state.useSimplePage,showDetails:this._state.showDetails,showProductPrice:this._state.showProductPrice,priceFrom:this._state.priceFrom,priceTo:this._state.priceTo,currencySymbol:this._state.currencySymbol,isSimulationMode:this._state.isSimulationMode,app:{appId:this._state.appId,platform:this._state.platform,bundleId:this._state.bundleId,packageName:this._state.packageName,appVersion:this._state.appVersion,attestationToken:this._state.attestationToken},hostPageOrigin:p(),hostPageUrl:y()};this._state.isSimulationMode&&this._state.simulationInlineConfig&&typeof this._state.simulationInlineConfig=="object"&&(n.inlineVirtualTryonConfig=this._state.simulationInlineConfig),t.contentWindow.postMessage({type:b,payload:n},i)}}_renderLoading(){if(this.shadowRoot){var t=o(this,r.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var i=document.createElement("style");i.textContent=it(t,O);var n=document.createElement("div");n.className=O,n.textContent=z,this.shadowRoot.appendChild(i),this.shadowRoot.appendChild(n)}}_renderError(t){if(this.shadowRoot){var i=o(this,r.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var n=document.createElement("style");n.textContent=rt(i,R);var s=document.createElement("div");s.className=R,s.textContent=t||J,this.shadowRoot.appendChild(n),this.shadowRoot.appendChild(s)}}_renderIframe(t,i){if(this.shadowRoot){var n=this,s=o(this,r.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var l=document.createElement("style");l.textContent=m(s);var _=document.createElement("iframe");_.src=t,_.title=X,_.style.cssText="width:100%;height:100%;border:0;min-height:"+s,_.setAttribute("allow","camera"),_.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),_.onload=function(){i===n._renderVersion&&[0,50,150,400,1e3].forEach(function(a){setTimeout(function(){i===n._renderVersion&&n._sendConfigToIframe()},a)})},this.shadowRoot.appendChild(l),this.shadowRoot.appendChild(_)}}_render(){if(this.shadowRoot){this._renderVersion+=1;var t=this._renderVersion;if(!this._state.merchantId){this._setStatus("error",{message:u.MERCHANT_ID_REQUIRED}),this._renderError(u.MERCHANT_ID_REQUIRED);return}if(!this._state.widgetId){this._setStatus("error",{message:u.WIDGET_ID_REQUIRED}),this._renderError(u.WIDGET_ID_REQUIRED);return}if(!this._state.env){this._setStatus("error",{message:u.ENV_REQUIRED}),this._renderError(u.ENV_REQUIRED);return}this._renderLoading(),this._initializeSessionIfNeeded().then(function(i){t===this._renderVersion&&this._renderIframe(i.iframeUrl,t)}.bind(this)).catch(function(i){if(t===this._renderVersion){var n=U(i instanceof Error?i:new Error(String(i)));this._renderError(n)}}.bind(this))}}open(){return this.style.display="",Promise.resolve()}close(){return this.style.display="none",Promise.resolve()}}typeof customElements<"u"&&!customElements.get(g)&&customElements.define(g,Tt)})();
@@ -1 +1 @@
1
- "use strict";var VitraunWebAR=(()=>{(function(){"use strict";var w="VITRAUN_CONFIG",_="vtrn-vto-session",b=18e5,c=1e4,f="en-US",d=80;function o(t,e,i){var r=t.getAttribute(e);return r!=null&&r!==""?r:i}function h(t,e){if(t==null||t==="")return e;var i=String(t).toLowerCase();return i==="true"||i==="1"||i==="yes"}function p(t){if(t==null||t==="")return null;var e=parseFloat(String(t));return Number.isFinite(e)?e:null}function N(t){return!t||typeof t!="string"?[]:t.split(",").map(function(e){return e.trim()}).filter(Boolean)}function O(t,e){var i=o(t,e,"");if(!i||typeof i!="string")return null;try{return JSON.parse(i)}catch(r){return null}}function A(t){try{return JSON.parse(t)}catch(e){return null}}var g={"en-US":{INVALID_PUBLIC_API_KEY:"We could not open the virtual try-on. If the problem persists, contact the store.",PUBLIC_API_KEY_REQUIRED:"The virtual try-on is not available right now. Please try again later.",TRYON_EMBED_SESSION_TOKEN_MISSING:"We could not verify this session. Please refresh the page or contact the store.",TRYON_EMBED_SESSION_TOKEN_INVALID:"This session is no longer valid. Please refresh the page or start again.",TRYON_EMBED_SESSION_JWT_SECRET_NOT_CONFIGURED:"The virtual try-on is temporarily unavailable. Please try again later.",INVALID_OR_MISSING_MERCHANT_ID:"This integration is missing valid store credentials. Please contact the store.",INVALID_OR_MISSING_WIDGET_ID:"This integration is missing valid widget credentials. Please contact the store.",EMBED_INIT_MERCHANT_MISMATCH:"The store information does not match this widget. Please contact the store.",WIDGET_KEY_OR_CHANNEL_NOT_FOUND:"This widget could not be found or is no longer active. Please contact the store.",EMBED_PARENT_ORIGIN_REQUIRED:"We could not verify where this page is embedded. Please contact the store.",EMBED_PARENT_ORIGIN_NOT_ALLOWED:"This page is not allowed to use the virtual try-on. Please contact the store.",UNIQUE_CONSTRAINT_VIOLATION:"This value conflicts with an existing record. Change it and try again.",FOREIGN_KEY_VIOLATION:"This action references data that does not exist or cannot be linked. Check related records.",VALUE_OUT_OF_RANGE:"One of the values is invalid or too large for the server. Adjust the data and try again.",RECORD_NOT_FOUND:"The record was not found. It may have been removed \u2014 refresh the page and try again.",NULL_CONSTRAINT_VIOLATION:"A required field was empty. Fill in all required fields and try again.",MISSING_REQUIRED_VALUE:"Some required information is missing. Review the form and try again.",RELATION_CONSTRAINT_VIOLATION:"This change is not allowed because of how records are linked. Adjust relationships and try again.",TRANSACTION_CONFLICT:"The operation conflicted with another change. Please try again.",INVALID_DATABASE_INPUT:"The request could not be processed. Check the data format and try again.",UNEXPECTED_DATABASE_ERROR:"Something went wrong while saving. Try again or contact support if it continues."},"pt-BR":{INVALID_PUBLIC_API_KEY:"N\xE3o foi poss\xEDvel abrir o provador virtual. Se o problema continuar, fale com a loja.",PUBLIC_API_KEY_REQUIRED:"O provador virtual n\xE3o est\xE1 dispon\xEDvel no momento. Tente novamente mais tarde.",TRYON_EMBED_SESSION_TOKEN_MISSING:"N\xE3o foi poss\xEDvel verificar esta sess\xE3o. Atualize a p\xE1gina ou fale com a loja.",TRYON_EMBED_SESSION_TOKEN_INVALID:"Esta sess\xE3o n\xE3o \xE9 mais v\xE1lida. Atualize a p\xE1gina ou comece de novo.",TRYON_EMBED_SESSION_JWT_SECRET_NOT_CONFIGURED:"O provador virtual est\xE1 temporariamente indispon\xEDvel. Tente novamente mais tarde.",INVALID_OR_MISSING_MERCHANT_ID:"Esta integra\xE7\xE3o n\xE3o tem credenciais v\xE1lidas da loja. Fale com a loja.",INVALID_OR_MISSING_WIDGET_ID:"Esta integra\xE7\xE3o n\xE3o tem credenciais v\xE1lidas do widget. Fale com a loja.",EMBED_INIT_MERCHANT_MISMATCH:"As informa\xE7\xF5es da loja n\xE3o correspondem a este widget. Fale com a loja.",WIDGET_KEY_OR_CHANNEL_NOT_FOUND:"Este widget n\xE3o foi encontrado ou n\xE3o est\xE1 mais ativo. Fale com a loja.",EMBED_PARENT_ORIGIN_REQUIRED:"N\xE3o foi poss\xEDvel verificar onde esta p\xE1gina est\xE1 incorporada. Fale com a loja.",EMBED_PARENT_ORIGIN_NOT_ALLOWED:"Esta p\xE1gina n\xE3o tem permiss\xE3o para usar o provador virtual. Fale com a loja.",UNIQUE_CONSTRAINT_VIOLATION:"Este valor conflita com um registro j\xE1 existente. Altere e tente novamente.",FOREIGN_KEY_VIOLATION:"Esta a\xE7\xE3o referencia dados inexistentes ou que n\xE3o podem ser vinculados. Verifique os registros relacionados.",VALUE_OUT_OF_RANGE:"Um dos valores \xE9 inv\xE1lido ou muito grande para o servidor. Ajuste os dados e tente novamente.",RECORD_NOT_FOUND:"O registro n\xE3o foi encontrado. Pode ter sido removido \u2014 atualize a p\xE1gina e tente novamente.",NULL_CONSTRAINT_VIOLATION:"Um campo obrigat\xF3rio ficou vazio. Preencha todos os campos obrigat\xF3rios e tente novamente.",MISSING_REQUIRED_VALUE:"Falta informa\xE7\xE3o obrigat\xF3ria. Revise o formul\xE1rio e tente novamente.",RELATION_CONSTRAINT_VIOLATION:"Esta altera\xE7\xE3o n\xE3o \xE9 permitida por causa de como os registros est\xE3o vinculados. Ajuste as rela\xE7\xF5es e tente novamente.",TRANSACTION_CONFLICT:"A opera\xE7\xE3o conflitou com outra altera\xE7\xE3o. Tente novamente.",INVALID_DATABASE_INPUT:"A solicita\xE7\xE3o n\xE3o p\xF4de ser processada. Verifique o formato dos dados e tente novamente.",UNEXPECTED_DATABASE_ERROR:"Algo deu errado ao salvar. Tente novamente ou entre em contato com o suporte se continuar."}};function R(t,e,i){var r=m(i),s=g[r]||g["en-US"],a=t&&typeof t.errorCode=="string"?t.errorCode:null;if(a&&Object.prototype.hasOwnProperty.call(s,a))return s[a];var l=t&&typeof t.message=="string"?t.message.trim():"";if(l)return l;if(a)return r==="pt-BR"?"N\xE3o foi poss\xEDvel iniciar o provador virtual. Tente novamente ou fale com a loja.":"Could not start the virtual try-on. Please try again or contact the store.";if(e&&String(e).length>0&&String(e).length<600){var n=String(e).trim();return n.charAt(0)==="{"&&n.indexOf("errorCode")!==-1?r==="pt-BR"?"N\xE3o foi poss\xEDvel iniciar o provador virtual. Tente novamente.":"Could not start the virtual try-on. Please try again.":n}return r==="pt-BR"?"N\xE3o foi poss\xEDvel iniciar o provador virtual. Tente novamente.":"Could not start the virtual try-on. Please try again."}var I={"en-US":"We couldn't connect to the virtual try-on service. If you're developing locally, make sure the API is running, then try again.","pt-BR":"N\xE3o foi poss\xEDvel conectar ao servi\xE7o do provador virtual. Se estiver em ambiente de desenvolvimento, confirme se a API est\xE1 em execu\xE7\xE3o e tente de novo."};function m(t){var e=String(t||"").trim().toLowerCase();return e.indexOf("pt")===0?"pt-BR":"en-US"}function P(t){if(!t||typeof t.message!="string")return!1;var e=t.name,i=t.message.toLowerCase();return e==="TypeError"&&(i.indexOf("failed to fetch")!==-1||i.indexOf("load failed")!==-1)||i.indexOf("networkerror when attempting to fetch")!==-1||e==="NetworkError"||i.indexOf("network request failed")!==-1}function v(t,e){if(P(t)){var i=m(e);return I[i]||I["en-US"]}return t&&typeof t.message=="string"&&t.message.trim()?t.message.trim():m(e)==="pt-BR"?"N\xE3o foi poss\xEDvel iniciar o provador virtual. Tente novamente.":"Could not start the virtual try-on. Please try again."}function T(){return typeof window=="undefined"||!window.location||!window.location.origin?null:window.location.origin}function y(){return typeof window=="undefined"||!window.location||!window.location.href?null:window.location.href}function C(t){if(!t||typeof t!="string")return null;try{return new URL(t).origin}catch(e){return null}}function k(t){var e=String(t||"").trim().toLowerCase();if(!e)throw new Error("The env attribute is required.");if(!/^[a-z0-9-]+$/.test(e))throw new Error("The env attribute contains an invalid value.");return e}function U(t){return t?String(t).trim().toLowerCase():"web"}function S(t,e){if(t==null||t==="")return e;var i=parseInt(String(t),10);return!Number.isInteger(i)||i<=0||i>65535?e:i}function D(t,e){return"https://app."+t+".vitraun.com:"+e+"/v1/public/virtual-tryon-embed-init"}function L(t,e){return{merchantId:t.merchantId,widgetId:t.widgetId,tryonSessionId:e,app:{appId:t.appId,platform:t.platform,bundleId:t.bundleId,packageName:t.packageName,appVersion:t.appVersion,attestationToken:t.attestationToken},context:{origin:T(),pageUrl:y(),userAgent:typeof navigator!="undefined"&&navigator.userAgent?navigator.userAgent:null,referrer:typeof document!="undefined"&&document.referrer?document.referrer:null,timezone:typeof Intl!="undefined"&&Intl.DateTimeFormat?Intl.DateTimeFormat().resolvedOptions().timeZone:null}}}function M(t,e,i,r){var s=e||f,a="https://app."+t+".vitraun.com:"+r+"/"+encodeURIComponent(s)+"/virtual-tryon";return i&&(a+="?simulation=1"),a}function V(t,e,i,r){return!e||e<=0?t:new Promise(function(s,a){var l=!1,n=setTimeout(function(){if(!l){l=!0;try{r&&typeof r.abort=="function"&&r.abort()}catch(u){}a(new Error(i||"The operation timed out."))}},e);t.then(function(u){l||(l=!0,clearTimeout(n),s(u))}).catch(function(u){l||(l=!0,clearTimeout(n),a(u))})})}function E(){if(typeof window=="undefined"||!window.crypto||!window.crypto.randomUUID)return"00000000-0000-4000-8000-000000000000";try{var t=sessionStorage.getItem(_);if(t){var e=JSON.parse(t);if(e&&typeof e.id=="string"&&typeof e.exp=="number"&&Date.now()<e.exp)return e.id}}catch(s){}var i=window.crypto.randomUUID(),r=Date.now()+b;try{sessionStorage.setItem(_,JSON.stringify({id:i,exp:r}))}catch(s){}return i}class F extends HTMLElement{static get observedAttributes(){return["merchant-id","widget-id","env","api-port","app-port","lang","isolated-sku","apply-skus","flow","basket-opens-in","checkout-opens-in","use-simple-page","show-details","show-product-price","price-from","price-to","currency-symbol","is-simulation-mode","simulation-inline-config","container-min-height","app-id","platform","bundle-id","package-name","app-version","attestation-token","debug","init-timeout-ms"]}constructor(){super(),this.attachShadow({mode:"open"}),this._state={merchantId:"",widgetId:"",env:"",apiPort:d,appPort:d,lang:f,isolatedSku:null,applySkus:[],iframeOrigin:null,flow:"checkout",basketOpensIn:"event",checkoutOpensIn:"event",useSimplePage:!0,showDetails:!0,showProductPrice:!1,priceFrom:null,priceTo:null,currencySymbol:null,isSimulationMode:!1,simulationInlineConfig:null,appId:null,platform:"web",bundleId:null,packageName:null,appVersion:null,attestationToken:null,debug:!1,sessionToken:null,tryonSessionId:null,resolvedInitUrl:null,resolvedIframeUrl:null,initTimeoutMs:c},this._boundHandleMessage=this._handleMessage.bind(this),this._initPromise=null,this._initStateKey=null,this._activeInitRequestId=0,this._renderVersion=0,this._abortController=null}connectedCallback(){this._readAttributes(),this._render(),typeof window!="undefined"&&window.addEventListener("message",this._boundHandleMessage)}disconnectedCallback(){if(typeof window!="undefined"&&window.removeEventListener("message",this._boundHandleMessage),this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch(e){}}attributeChangedCallback(e,i,r){i!==r&&(this._readAttributes(),this._render())}_log(){if(!(!this._state.debug||typeof console=="undefined"||!console.log)){var e=Array.prototype.slice.call(arguments);e.unshift("[vitraun-vto]"),console.log.apply(console,e)}}_readAttributes(){var e=O(this,"simulation-inline-config"),i=!1;e&&e.features&&typeof e.features.showProductPrice=="boolean"&&(i=e.features.showProductPrice);var r=!0;e&&e.features&&typeof e.features.useSimplePage=="boolean"&&(r=e.features.useSimplePage);var s="checkout";e&&e.features&&(e.features.flow==="catalog"||e.features.flow==="checkout")&&(s=e.features.flow);var a=!0;e&&e.features&&typeof e.features.showDetails=="boolean"&&(a=e.features.showDetails);var l="";try{l=k(o(this,"env",""))}catch(u){l=""}var n=parseInt(o(this,"init-timeout-ms",String(c)),10);(!Number.isFinite(n)||n<0)&&(n=c),this._state={merchantId:o(this,"merchant-id",""),widgetId:o(this,"widget-id",""),env:l,apiPort:S(o(this,"api-port",String(d)),d),appPort:S(o(this,"app-port",String(d)),d),lang:o(this,"lang",f),isolatedSku:o(this,"isolated-sku",null)||null,applySkus:N(o(this,"apply-skus","")),iframeOrigin:this._state&&this._state.iframeOrigin?this._state.iframeOrigin:null,flow:o(this,"flow",s),basketOpensIn:o(this,"basket-opens-in","event"),checkoutOpensIn:o(this,"checkout-opens-in","event"),useSimplePage:h(o(this,"use-simple-page",""),r),showDetails:h(o(this,"show-details",""),a),showProductPrice:h(o(this,"show-product-price",""),i),priceFrom:p(o(this,"price-from",null)),priceTo:p(o(this,"price-to",null)),currencySymbol:o(this,"currency-symbol",null)||null,isSimulationMode:h(o(this,"is-simulation-mode","false"),!1),simulationInlineConfig:e,appId:o(this,"app-id",null)||null,platform:U(o(this,"platform",null)),bundleId:o(this,"bundle-id",null)||null,packageName:o(this,"package-name",null)||null,appVersion:o(this,"app-version",null)||null,attestationToken:o(this,"attestation-token",null)||null,debug:h(o(this,"debug","false"),!1),sessionToken:this._state&&this._state.sessionToken?this._state.sessionToken:null,tryonSessionId:this._state&&this._state.tryonSessionId?this._state.tryonSessionId:null,resolvedInitUrl:this._state&&this._state.resolvedInitUrl?this._state.resolvedInitUrl:null,resolvedIframeUrl:this._state&&this._state.resolvedIframeUrl?this._state.resolvedIframeUrl:null,initTimeoutMs:n}}_emit(e,i){this.dispatchEvent(new CustomEvent(e,{detail:i!=null?i:null,bubbles:!0,composed:!0}))}_setStatus(e,i){this.setAttribute("data-status",e),this._emit("statusChange",{status:e,detail:i||null})}_getIframeElement(){return this.shadowRoot?this.shadowRoot.querySelector("iframe"):null}_handleMessage(e){var i=e.data;if(!(!i||typeof i!="object")){var r=this._getIframeElement();if(!(!r||!r.contentWindow)&&e.source===r.contentWindow&&!(!this._state.iframeOrigin||e.origin!==this._state.iframeOrigin)){var s=i.type,a=i.detail;if(s==="VTO_USAGE"){this._emit("vtoUsage",a);return}var l=["addToCart","removeFromCart","redirectToCart","analysisFinished"];l.indexOf(s)!==-1&&this._emit(s,a)}}}_getInitStateKey(){return JSON.stringify({merchantId:this._state.merchantId,widgetId:this._state.widgetId,env:this._state.env,apiPort:this._state.apiPort,appPort:this._state.appPort,lang:this._state.lang,isolatedSku:this._state.isolatedSku,applySkus:this._state.applySkus,flow:this._state.flow,basketOpensIn:this._state.basketOpensIn,checkoutOpensIn:this._state.checkoutOpensIn,useSimplePage:this._state.useSimplePage,showDetails:this._state.showDetails,showProductPrice:this._state.showProductPrice,priceFrom:this._state.priceFrom,priceTo:this._state.priceTo,currencySymbol:this._state.currencySymbol,isSimulationMode:this._state.isSimulationMode,simulationInlineConfig:this._state.simulationInlineConfig,appId:this._state.appId,platform:this._state.platform,bundleId:this._state.bundleId,packageName:this._state.packageName,appVersion:this._state.appVersion,attestationToken:this._state.attestationToken})}_buildResolvedUrls(){if(!this._state.env)throw new Error("The env attribute is required.");var e=M(this._state.env,this._state.lang,this._state.isSimulationMode,this._state.appPort);return{initUrl:D(this._state.env,this._state.apiPort),iframeUrl:e,iframeOrigin:C(e)}}_buildInitPayload(){var e=E();return{tryonSessionId:e,initRequestBody:L(this._state,e)}}_normalizeInitResponse(e,i,r){if(!e||typeof e!="object")throw new Error("Invalid init response.");var s=typeof e.sessionToken=="string"&&e.sessionToken?e.sessionToken:null,a=typeof e.tryonSessionId=="string"&&e.tryonSessionId?e.tryonSessionId:r;if(!s)throw new Error("The init API did not return sessionToken.");return{sessionToken:s,tryonSessionId:a,initUrl:i.initUrl,iframeUrl:i.iframeUrl,iframeOrigin:i.iframeOrigin}}_initializeSessionIfNeeded(){var e=this;if(!this._state.merchantId)return Promise.reject(new Error("The merchant-id attribute is required."));if(!this._state.widgetId)return Promise.reject(new Error("The widget-id attribute is required."));if(!this._state.env)return Promise.reject(new Error("The env attribute is required."));var i=this._getInitStateKey();if(this._initPromise&&this._initStateKey===i)return this._initPromise;if(this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch(n){}this._initStateKey=i,this._activeInitRequestId+=1;var r=this._activeInitRequestId;this._setStatus("loading");var s;try{s=this._buildResolvedUrls()}catch(n){return Promise.reject(n)}var a=this._buildInitPayload();this._state.tryonSessionId=a.tryonSessionId,this._abortController=typeof AbortController!="undefined"?new AbortController:null;var l=fetch(s.initUrl,{method:"POST",headers:{"Content-Type":"application/json","X-Merchant-Id":this._state.merchantId,"X-Widget-Id":this._state.widgetId},body:JSON.stringify(a.initRequestBody),signal:this._abortController?this._abortController.signal:void 0}).then(function(n){return n.ok?n.json():n.text().then(function(u){var x=A(u),B=R(x,u,e._state.lang);throw new Error(B)})}).then(function(n){return e._normalizeInitResponse(n,s,a.tryonSessionId)});return this._initPromise=V(l,this._state.initTimeoutMs,"Timed out while initializing the Vitraun session.",this._abortController).then(function(n){return r!==e._activeInitRequestId||(e._state.sessionToken=n.sessionToken,e._state.tryonSessionId=n.tryonSessionId,e._state.resolvedInitUrl=n.initUrl,e._state.resolvedIframeUrl=n.iframeUrl,e._state.iframeOrigin=n.iframeOrigin,e._setStatus("ready")),n}).catch(function(n){if(r!==e._activeInitRequestId)throw n;var u=v(n,e._state.lang);throw e._state.sessionToken=null,e._state.resolvedInitUrl=null,e._state.resolvedIframeUrl=null,e._state.iframeOrigin=null,e._setStatus("error",{message:u}),new Error(u)}).finally(function(){r===e._activeInitRequestId&&(e._initPromise=null)}),this._initPromise}_sendConfigToIframe(){var e=this._getIframeElement();if(!(!e||!e.contentWindow)){var i=this._state.iframeOrigin;if(!i){this._log("Config not sent: iframeOrigin is missing.");return}var r={merchantId:this._state.merchantId,widgetId:this._state.widgetId,sessionToken:this._state.sessionToken,tryonSessionId:this._state.tryonSessionId||E(),lang:this._state.lang,isolatedSku:this._state.isolatedSku,applySkus:this._state.applySkus,flow:this._state.flow,basketOpensIn:this._state.basketOpensIn,checkoutOpensIn:this._state.checkoutOpensIn,useSimplePage:this._state.useSimplePage,showDetails:this._state.showDetails,showProductPrice:this._state.showProductPrice,priceFrom:this._state.priceFrom,priceTo:this._state.priceTo,currencySymbol:this._state.currencySymbol,isSimulationMode:this._state.isSimulationMode,app:{appId:this._state.appId,platform:this._state.platform,bundleId:this._state.bundleId,packageName:this._state.packageName,appVersion:this._state.appVersion,attestationToken:this._state.attestationToken},hostPageOrigin:T(),hostPageUrl:y()};this._state.isSimulationMode&&this._state.simulationInlineConfig&&typeof this._state.simulationInlineConfig=="object"&&(r.inlineVirtualTryonConfig=this._state.simulationInlineConfig),e.contentWindow.postMessage({type:w,payload:r},i)}}_renderLoading(){if(this.shadowRoot){var e=o(this,"container-min-height","80vh");this.shadowRoot.innerHTML="";var i=document.createElement("style");i.textContent=":host { display:block; width:100%; min-height:"+e+"; box-sizing:border-box; }.vitraun-loading {min-height:"+e+";display:flex;align-items:center;justify-content:center;border:1px solid #ececec;background:#fafafa;color:#333;font:14px/1.4 Arial, sans-serif;padding:16px;box-sizing:border-box;border-radius:8px;text-align:center;}";var r=document.createElement("div");r.className="vitraun-loading",r.textContent="Loading Vitraun...",this.shadowRoot.appendChild(i),this.shadowRoot.appendChild(r)}}_renderError(e){if(this.shadowRoot){var i=o(this,"container-min-height","80vh");this.shadowRoot.innerHTML="";var r=document.createElement("style");r.textContent=":host { display:block; width:100%; min-height:"+i+"; box-sizing:border-box; }.vitraun-error {min-height:"+i+";display:flex;align-items:center;justify-content:center;border:1px solid #f1d5d5;background:#fff7f7;color:#7a1f1f;font:14px/1.4 Arial, sans-serif;padding:16px;box-sizing:border-box;border-radius:8px;text-align:center;}";var s=document.createElement("div");s.className="vitraun-error",s.textContent=e||"Failed to load Vitraun.",this.shadowRoot.appendChild(r),this.shadowRoot.appendChild(s)}}_renderIframe(e,i){if(this.shadowRoot){var r=this,s=o(this,"container-min-height","80vh");this.shadowRoot.innerHTML="";var a=document.createElement("style");a.textContent=":host { display:block; width:100%; min-height:"+s+"; box-sizing:border-box; }";var l=document.createElement("iframe");l.src=e,l.title="Vitraun VTO",l.style.cssText="width:100%;height:100%;border:0;min-height:"+s,l.setAttribute("allow","camera"),l.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),l.onload=function(){i===r._renderVersion&&[0,50,150,400,1e3].forEach(function(n){setTimeout(function(){i===r._renderVersion&&r._sendConfigToIframe()},n)})},this.shadowRoot.appendChild(a),this.shadowRoot.appendChild(l)}}_render(){if(this.shadowRoot){this._renderVersion+=1;var e=this._renderVersion;if(!this._state.merchantId){this._setStatus("error",{message:"The merchant-id attribute is required."}),this._renderError("The merchant-id attribute is required.");return}if(!this._state.widgetId){this._setStatus("error",{message:"The widget-id attribute is required."}),this._renderError("The widget-id attribute is required.");return}if(!this._state.env){this._setStatus("error",{message:"The env attribute is required."}),this._renderError("The env attribute is required.");return}this._renderLoading(),this._initializeSessionIfNeeded().then(function(i){e===this._renderVersion&&this._renderIframe(i.iframeUrl,e)}.bind(this)).catch(function(i){if(e===this._renderVersion){var r=v(i instanceof Error?i:new Error(String(i)),this._state.lang);this._renderError(r)}}.bind(this))}}open(){return this.style.display="",Promise.resolve()}close(){return this.style.display="none",Promise.resolve()}}typeof customElements!="undefined"&&!customElements.get("vitraun-vto")&&customElements.define("vitraun-vto",F)})();})();
1
+ "use strict";var VitraunWebAR=(()=>{(function(){"use strict";var b="VITRAUN_CONFIG",N="vtrn-vto-session",M=18e5,E=1e4,T="en-US",h="Vitraun",S="vitraun",f="https://",L="app.",G="app.",A="."+S+".com",k="/v1/public/virtual-tryon-embed-init",V="/virtual-tryon",F="Content-Type",H="X-Origin",W="X-Tryon-Session-Id",K="X-Merchant-Id",B="X-Widget-Id",x="application/json",Y="00000000-0000-0000-0000-000000000000",q=["addToCart","removeFromCart","redirectToCart","analysisFinished"],g="vitraun-vto",Q="["+g+"]",O=S+"-loading",R=S+"-error",X=h+" VTO",z="Loading "+h+"...",J="Failed to load "+h+".",j="Timed out while initializing the "+h+" session.",r={MERCHANT_ID:"merchant-id",WIDGET_ID:"widget-id",ENV:"env",API_PORT:"api-port",APP_PORT:"app-port",LANG:"lang",ISOLATED_SKU:"isolated-sku",APPLY_SKUS:"apply-skus",FLOW:"flow",BASKET_OPENS_IN:"basket-opens-in",CHECKOUT_OPENS_IN:"checkout-opens-in",USE_SIMPLE_PAGE:"use-simple-page",SHOW_DETAILS:"show-details",SHOW_PRODUCT_PRICE:"show-product-price",PRICE_FROM:"price-from",PRICE_TO:"price-to",CURRENCY_SYMBOL:"currency-symbol",IS_SIMULATION_MODE:"is-simulation-mode",SIMULATION_INLINE_CONFIG:"simulation-inline-config",CONTAINER_MIN_HEIGHT:"container-min-height",APP_ID:"app-id",PLATFORM:"platform",BUNDLE_ID:"bundle-id",PACKAGE_NAME:"package-name",APP_VERSION:"app-version",ATTESTATION_TOKEN:"attestation-token",DEBUG:"debug",INIT_TIMEOUT_MS:"init-timeout-ms"},Z=[r.MERCHANT_ID,r.WIDGET_ID,r.ENV,r.API_PORT,r.APP_PORT,r.LANG,r.ISOLATED_SKU,r.APPLY_SKUS,r.FLOW,r.BASKET_OPENS_IN,r.CHECKOUT_OPENS_IN,r.USE_SIMPLE_PAGE,r.SHOW_DETAILS,r.SHOW_PRODUCT_PRICE,r.PRICE_FROM,r.PRICE_TO,r.CURRENCY_SYMBOL,r.IS_SIMULATION_MODE,r.SIMULATION_INLINE_CONFIG,r.CONTAINER_MIN_HEIGHT,r.APP_ID,r.PLATFORM,r.BUNDLE_ID,r.PACKAGE_NAME,r.APP_VERSION,r.ATTESTATION_TOKEN,r.DEBUG,r.INIT_TIMEOUT_MS],u={ENV_REQUIRED:"The env attribute is required.",ENV_INVALID:"The env attribute contains an invalid value.",MERCHANT_ID_REQUIRED:"The merchant-id attribute is required.",WIDGET_ID_REQUIRED:"The widget-id attribute is required.",INIT_INVALID_RESPONSE:"Invalid init response.",INIT_SESSION_TOKEN_MISSING:"The init API did not return sessionToken."},$="The operation timed out.",tt={CONFIG_SKIPPED_NO_IFRAME_ORIGIN:"Config not sent: iframeOrigin is missing."},c={GENERIC_TRY_AGAIN_OR_STORE:"Could not start the virtual try-on. Please try again or contact the store.",GENERIC_TRY_AGAIN:"Could not start the virtual try-on. Please try again."},et="We couldn't connect to the virtual try-on service. If you are developing locally, make sure the API is running, then try again.",v={INVALID_PUBLIC_API_KEY:"We could not open the virtual try-on. If the problem persists, contact the store.",PUBLIC_API_KEY_REQUIRED:"The virtual try-on is not available right now. Please try again later.",TRYON_EMBED_SESSION_TOKEN_MISSING:"We could not verify this session. Please refresh the page or contact the store.",TRYON_EMBED_SESSION_TOKEN_INVALID:"This session is no longer valid. Please refresh the page or start again.",TRYON_EMBED_SESSION_JWT_SECRET_NOT_CONFIGURED:"The virtual try-on is temporarily unavailable. Please try again later.",INVALID_OR_MISSING_MERCHANT_ID:"This integration is missing valid store credentials. Please contact the store.",INVALID_OR_MISSING_WIDGET_ID:"This integration is missing valid widget credentials. Please contact the store.",EMBED_INIT_MERCHANT_MISMATCH:"The store information does not match this widget. Please contact the store.",WIDGET_KEY_OR_CHANNEL_NOT_FOUND:"This widget could not be found or is no longer active. Please contact the store.",EMBED_PARENT_ORIGIN_REQUIRED:"We could not verify where this page is embedded. Please contact the store.",EMBED_PARENT_ORIGIN_NOT_ALLOWED:"This page is not allowed to use the virtual try-on. Please contact the store.",UNIQUE_CONSTRAINT_VIOLATION:"This value conflicts with an existing record. Change it and try again.",FOREIGN_KEY_VIOLATION:"This action references data that does not exist or cannot be linked. Check related records.",VALUE_OUT_OF_RANGE:"One of the values is invalid or too large for the server. Adjust the data and try again.",RECORD_NOT_FOUND:"The record was not found. It may have been removed. Refresh the page and try again.",NULL_CONSTRAINT_VIOLATION:"A required field was empty. Fill in all required fields and try again.",MISSING_REQUIRED_VALUE:"Some required information is missing. Review the form and try again.",RELATION_CONSTRAINT_VIOLATION:"This change is not allowed because of how records are linked. Adjust relationships and try again.",TRANSACTION_CONFLICT:"The operation conflicted with another change. Please try again.",INVALID_DATABASE_INPUT:"The request could not be processed. Check the data format and try again.",UNEXPECTED_DATABASE_ERROR:"Something went wrong while saving. Try again or contact support if it continues."};function m(e){return":host { display:block; width:100%; min-height:"+e+"; box-sizing:border-box; }"}function it(e,t){return m(e)+"."+t+" {min-height:"+e+";display:flex;align-items:center;justify-content:center;border:1px solid #ececec;background:#fafafa;color:#333;font:14px/1.4 Arial, sans-serif;padding:16px;box-sizing:border-box;border-radius:8px;text-align:center;}"}function rt(e,t){return m(e)+"."+t+" {min-height:"+e+";display:flex;align-items:center;justify-content:center;border:1px solid #f1d5d5;background:#fff7f7;color:#7a1f1f;font:14px/1.4 Arial, sans-serif;padding:16px;box-sizing:border-box;border-radius:8px;text-align:center;}"}function o(e,t,i){var n=e.getAttribute(t);return n!=null&&n!==""?n:i}function d(e,t){if(e==null||e==="")return t;var i=String(e).toLowerCase();return i==="true"||i==="1"||i==="yes"}function P(e){if(e==null||e==="")return null;var t=parseFloat(String(e));return Number.isFinite(t)?t:null}function nt(e){return!e||typeof e!="string"?[]:e.split(",").map(function(t){return t.trim()}).filter(Boolean)}function st(e,t){var i=o(e,t,"");if(!i||typeof i!="string")return null;try{return JSON.parse(i)}catch(n){return null}}function ot(e){try{return JSON.parse(e)}catch(t){return null}}function p(){return typeof window=="undefined"||!window.location||!window.location.origin?null:window.location.origin}function y(){return typeof window=="undefined"||!window.location||!window.location.href?null:window.location.href}function at(e){if(!e||typeof e!="string")return null;try{return new URL(e).origin}catch(t){return null}}function lt(e){var t=String(e||"").trim().toLowerCase();if(!t)throw new Error(u.ENV_REQUIRED);if(!/^[a-z0-9-]+$/.test(t))throw new Error(u.ENV_INVALID);return t}function _t(e){return e?String(e).trim().toLowerCase():"web"}function w(e){if(e==null||e==="")return null;var t=parseInt(String(e),10);return!Number.isInteger(t)||t<=0||t>65535?null:t}function C(e,t){if(e==null||e==="")return"";var i=parseInt(String(e),10);return!Number.isInteger(i)||i<=0||i>65535||t==="https://"&&i===443||t==="http://"&&i===80?"":":"+i}function ut(e,t){var i=e&&typeof e.errorCode=="string"?e.errorCode:null;if(i&&Object.prototype.hasOwnProperty.call(v,i))return v[i];var n=e&&typeof e.message=="string"?e.message.trim():"";if(n)return n;if(i)return c.GENERIC_TRY_AGAIN_OR_STORE;if(t&&String(t).length>0&&String(t).length<600){var s=String(t).trim();return s.charAt(0)==="{"&&s.indexOf("errorCode")!==-1?c.GENERIC_TRY_AGAIN:s}return c.GENERIC_TRY_AGAIN}function It(e){if(!e||typeof e.message!="string")return!1;var t=e.name,i=e.message.toLowerCase();return t==="TypeError"&&(i.indexOf("failed to fetch")!==-1||i.indexOf("load failed")!==-1)||i.indexOf("networkerror when attempting to fetch")!==-1||t==="NetworkError"||i.indexOf("network request failed")!==-1}function U(e){return It(e)?et:e&&typeof e.message=="string"&&e.message.trim()?e.message.trim():c.GENERIC_TRY_AGAIN}function dt(e,t){return f+L+e+A+C(t,f)+k}function ht(e,t,i,n){var s=t||T,l=f+G+e+A+C(n,f)+"/"+encodeURIComponent(s)+V;return i&&(l+="?simulation=1"),l}function ft(e){var t=e.merchantId!=null?String(e.merchantId):"",i=e.widgetId!=null?String(e.widgetId):"",n=e.tryonSessionId!=null?String(e.tryonSessionId):"",s=e.origin!==void 0&&e.origin!==null&&e.origin!==""?String(e.origin):p()||"",l={};return l[H]=s,l[W]=n,l[K]=t,l[B]=i,e.contentType&&(l[F]=e.contentType),l}function ct(e,t){return{merchantId:e.merchantId,widgetId:e.widgetId,tryonSessionId:t,app:{appId:e.appId,platform:e.platform,bundleId:e.bundleId,packageName:e.packageName,appVersion:e.appVersion,attestationToken:e.attestationToken},context:{hostPageOrigin:p(),hostPageUrl:y(),userAgent:typeof navigator!="undefined"&&navigator.userAgent?navigator.userAgent:null,referrer:typeof document!="undefined"&&document.referrer?document.referrer:null,timezone:typeof Intl!="undefined"&&Intl.DateTimeFormat?Intl.DateTimeFormat().resolvedOptions().timeZone:null}}}function Et(e,t,i,n){return!t||t<=0?e:new Promise(function(s,l){var _=!1,a=setTimeout(function(){if(!_){_=!0;try{n&&typeof n.abort=="function"&&n.abort()}catch(I){}l(new Error(i||$))}},t);e.then(function(I){_||(_=!0,clearTimeout(a),s(I))}).catch(function(I){_||(_=!0,clearTimeout(a),l(I))})})}function D(){if(typeof window=="undefined"||!window.crypto||!window.crypto.randomUUID)return Y;try{var e=sessionStorage.getItem(N);if(e){var t=JSON.parse(e);if(t&&typeof t.id=="string"&&typeof t.exp=="number"&&Date.now()<t.exp)return t.id}}catch(s){}var i=window.crypto.randomUUID(),n=Date.now()+M;try{sessionStorage.setItem(N,JSON.stringify({id:i,exp:n}))}catch(s){}return i}class Tt extends HTMLElement{static get observedAttributes(){return Z.slice()}constructor(){super(),this.attachShadow({mode:"open"}),this._state={merchantId:"",widgetId:"",env:"",apiPort:null,appPort:null,lang:T,isolatedSku:null,applySkus:[],iframeOrigin:null,flow:"checkout",basketOpensIn:"event",checkoutOpensIn:"event",useSimplePage:!0,showDetails:!0,showProductPrice:!1,priceFrom:null,priceTo:null,currencySymbol:null,isSimulationMode:!1,simulationInlineConfig:null,appId:null,platform:"web",bundleId:null,packageName:null,appVersion:null,attestationToken:null,debug:!1,sessionToken:null,tryonSessionId:null,resolvedInitUrl:null,resolvedIframeUrl:null,initTimeoutMs:E},this._boundHandleMessage=this._handleMessage.bind(this),this._initPromise=null,this._initStateKey=null,this._activeInitRequestId=0,this._renderVersion=0,this._abortController=null}connectedCallback(){this._readAttributes(),this._render(),typeof window!="undefined"&&window.addEventListener("message",this._boundHandleMessage)}disconnectedCallback(){if(typeof window!="undefined"&&window.removeEventListener("message",this._boundHandleMessage),this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch(t){}}attributeChangedCallback(t,i,n){i!==n&&(this._readAttributes(),this._render())}_log(){if(!(!this._state.debug||typeof console=="undefined"||!console.log)){var t=Array.prototype.slice.call(arguments);t.unshift(Q),console.log.apply(console,t)}}_readAttributes(){var t=st(this,r.SIMULATION_INLINE_CONFIG),i=!1;t&&t.features&&typeof t.features.showProductPrice=="boolean"&&(i=t.features.showProductPrice);var n=!0;t&&t.features&&typeof t.features.useSimplePage=="boolean"&&(n=t.features.useSimplePage);var s="checkout";t&&t.features&&(t.features.flow==="catalog"||t.features.flow==="checkout")&&(s=t.features.flow);var l=!0;t&&t.features&&typeof t.features.showDetails=="boolean"&&(l=t.features.showDetails);var _="";try{_=lt(o(this,r.ENV,""))}catch(I){_=""}var a=parseInt(o(this,r.INIT_TIMEOUT_MS,String(E)),10);(!Number.isFinite(a)||a<0)&&(a=E),this._state={merchantId:o(this,r.MERCHANT_ID,""),widgetId:o(this,r.WIDGET_ID,""),env:_,apiPort:w(o(this,r.API_PORT,null)),appPort:w(o(this,r.APP_PORT,null)),lang:o(this,r.LANG,T),isolatedSku:o(this,r.ISOLATED_SKU,null)||null,applySkus:nt(o(this,r.APPLY_SKUS,"")),iframeOrigin:this._state&&this._state.iframeOrigin?this._state.iframeOrigin:null,flow:o(this,r.FLOW,s),basketOpensIn:o(this,r.BASKET_OPENS_IN,"event"),checkoutOpensIn:o(this,r.CHECKOUT_OPENS_IN,"event"),useSimplePage:d(o(this,r.USE_SIMPLE_PAGE,""),n),showDetails:d(o(this,r.SHOW_DETAILS,""),l),showProductPrice:d(o(this,r.SHOW_PRODUCT_PRICE,""),i),priceFrom:P(o(this,r.PRICE_FROM,null)),priceTo:P(o(this,r.PRICE_TO,null)),currencySymbol:o(this,r.CURRENCY_SYMBOL,null)||null,isSimulationMode:d(o(this,r.IS_SIMULATION_MODE,"false"),!1),simulationInlineConfig:t,appId:o(this,r.APP_ID,null)||null,platform:_t(o(this,r.PLATFORM,null)),bundleId:o(this,r.BUNDLE_ID,null)||null,packageName:o(this,r.PACKAGE_NAME,null)||null,appVersion:o(this,r.APP_VERSION,null)||null,attestationToken:o(this,r.ATTESTATION_TOKEN,null)||null,debug:d(o(this,r.DEBUG,"false"),!1),sessionToken:this._state&&this._state.sessionToken?this._state.sessionToken:null,tryonSessionId:this._state&&this._state.tryonSessionId?this._state.tryonSessionId:null,resolvedInitUrl:this._state&&this._state.resolvedInitUrl?this._state.resolvedInitUrl:null,resolvedIframeUrl:this._state&&this._state.resolvedIframeUrl?this._state.resolvedIframeUrl:null,initTimeoutMs:a}}_emit(t,i){this.dispatchEvent(new CustomEvent(t,{detail:i!=null?i:null,bubbles:!0,composed:!0}))}_setStatus(t,i){this.setAttribute("data-status",t),this._emit("statusChange",{status:t,detail:i||null})}_getIframeElement(){return this.shadowRoot?this.shadowRoot.querySelector("iframe"):null}_handleMessage(t){var i=t.data;if(!(!i||typeof i!="object")){var n=this._getIframeElement();if(!(!n||!n.contentWindow)&&t.source===n.contentWindow&&!(!this._state.iframeOrigin||t.origin!==this._state.iframeOrigin)){var s=i.type,l=i.detail;if(s==="VTO_USAGE"){this._emit("vtoUsage",l);return}q.indexOf(s)!==-1&&this._emit(s,l)}}}_getInitStateKey(){return JSON.stringify({merchantId:this._state.merchantId,widgetId:this._state.widgetId,env:this._state.env,apiPort:this._state.apiPort,appPort:this._state.appPort,lang:this._state.lang,isolatedSku:this._state.isolatedSku,applySkus:this._state.applySkus,flow:this._state.flow,basketOpensIn:this._state.basketOpensIn,checkoutOpensIn:this._state.checkoutOpensIn,useSimplePage:this._state.useSimplePage,showDetails:this._state.showDetails,showProductPrice:this._state.showProductPrice,priceFrom:this._state.priceFrom,priceTo:this._state.priceTo,currencySymbol:this._state.currencySymbol,isSimulationMode:this._state.isSimulationMode,simulationInlineConfig:this._state.simulationInlineConfig,appId:this._state.appId,platform:this._state.platform,bundleId:this._state.bundleId,packageName:this._state.packageName,appVersion:this._state.appVersion,attestationToken:this._state.attestationToken})}_buildResolvedUrls(){if(!this._state.env)throw new Error(u.ENV_REQUIRED);var t=ht(this._state.env,this._state.lang,this._state.isSimulationMode,this._state.appPort);return{initUrl:dt(this._state.env,this._state.apiPort),iframeUrl:t,iframeOrigin:at(t)}}_buildInitPayload(){var t=D();return{tryonSessionId:t,initRequestBody:ct(this._state,t)}}_normalizeInitResponse(t,i,n){if(!t||typeof t!="object")throw new Error(u.INIT_INVALID_RESPONSE);var s=typeof t.sessionToken=="string"&&t.sessionToken?t.sessionToken:null,l=typeof t.tryonSessionId=="string"&&t.tryonSessionId?t.tryonSessionId:n;if(!s)throw new Error(u.INIT_SESSION_TOKEN_MISSING);return{sessionToken:s,tryonSessionId:l,initUrl:i.initUrl,iframeUrl:i.iframeUrl,iframeOrigin:i.iframeOrigin}}_initializeSessionIfNeeded(){var t=this;if(!this._state.merchantId)return Promise.reject(new Error(u.MERCHANT_ID_REQUIRED));if(!this._state.widgetId)return Promise.reject(new Error(u.WIDGET_ID_REQUIRED));if(!this._state.env)return Promise.reject(new Error(u.ENV_REQUIRED));var i=this._getInitStateKey();if(this._initPromise&&this._initStateKey===i)return this._initPromise;if(this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch(a){}this._initStateKey=i,this._activeInitRequestId+=1;var n=this._activeInitRequestId;this._setStatus("loading");var s;try{s=this._buildResolvedUrls()}catch(a){return Promise.reject(a)}var l=this._buildInitPayload();this._state.tryonSessionId=l.tryonSessionId,this._abortController=typeof AbortController!="undefined"?new AbortController:null;var _=fetch(s.initUrl,{method:"POST",headers:ft({merchantId:this._state.merchantId,widgetId:this._state.widgetId,tryonSessionId:l.tryonSessionId,contentType:x}),body:JSON.stringify(l.initRequestBody),signal:this._abortController?this._abortController.signal:void 0}).then(function(a){return a.ok?a.json():a.text().then(function(I){var St=ot(I),gt=ut(St,I);throw new Error(gt)})}).then(function(a){return t._normalizeInitResponse(a,s,l.tryonSessionId)});return this._initPromise=Et(_,this._state.initTimeoutMs,j,this._abortController).then(function(a){return n!==t._activeInitRequestId||(t._state.sessionToken=a.sessionToken,t._state.tryonSessionId=a.tryonSessionId,t._state.resolvedInitUrl=a.initUrl,t._state.resolvedIframeUrl=a.iframeUrl,t._state.iframeOrigin=a.iframeOrigin,t._setStatus("ready")),a}).catch(function(a){if(n!==t._activeInitRequestId)throw a;var I=U(a);throw t._state.sessionToken=null,t._state.resolvedInitUrl=null,t._state.resolvedIframeUrl=null,t._state.iframeOrigin=null,t._setStatus("error",{message:I}),new Error(I)}).finally(function(){n===t._activeInitRequestId&&(t._initPromise=null)}),this._initPromise}_sendConfigToIframe(){var t=this._getIframeElement();if(!(!t||!t.contentWindow)){var i=this._state.iframeOrigin;if(!i){this._log(tt.CONFIG_SKIPPED_NO_IFRAME_ORIGIN);return}var n={merchantId:this._state.merchantId,widgetId:this._state.widgetId,sessionToken:this._state.sessionToken,tryonSessionId:this._state.tryonSessionId||D(),lang:this._state.lang,isolatedSku:this._state.isolatedSku,applySkus:this._state.applySkus,flow:this._state.flow,basketOpensIn:this._state.basketOpensIn,checkoutOpensIn:this._state.checkoutOpensIn,useSimplePage:this._state.useSimplePage,showDetails:this._state.showDetails,showProductPrice:this._state.showProductPrice,priceFrom:this._state.priceFrom,priceTo:this._state.priceTo,currencySymbol:this._state.currencySymbol,isSimulationMode:this._state.isSimulationMode,app:{appId:this._state.appId,platform:this._state.platform,bundleId:this._state.bundleId,packageName:this._state.packageName,appVersion:this._state.appVersion,attestationToken:this._state.attestationToken},hostPageOrigin:p(),hostPageUrl:y()};this._state.isSimulationMode&&this._state.simulationInlineConfig&&typeof this._state.simulationInlineConfig=="object"&&(n.inlineVirtualTryonConfig=this._state.simulationInlineConfig),t.contentWindow.postMessage({type:b,payload:n},i)}}_renderLoading(){if(this.shadowRoot){var t=o(this,r.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var i=document.createElement("style");i.textContent=it(t,O);var n=document.createElement("div");n.className=O,n.textContent=z,this.shadowRoot.appendChild(i),this.shadowRoot.appendChild(n)}}_renderError(t){if(this.shadowRoot){var i=o(this,r.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var n=document.createElement("style");n.textContent=rt(i,R);var s=document.createElement("div");s.className=R,s.textContent=t||J,this.shadowRoot.appendChild(n),this.shadowRoot.appendChild(s)}}_renderIframe(t,i){if(this.shadowRoot){var n=this,s=o(this,r.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var l=document.createElement("style");l.textContent=m(s);var _=document.createElement("iframe");_.src=t,_.title=X,_.style.cssText="width:100%;height:100%;border:0;min-height:"+s,_.setAttribute("allow","camera"),_.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),_.onload=function(){i===n._renderVersion&&[0,50,150,400,1e3].forEach(function(a){setTimeout(function(){i===n._renderVersion&&n._sendConfigToIframe()},a)})},this.shadowRoot.appendChild(l),this.shadowRoot.appendChild(_)}}_render(){if(this.shadowRoot){this._renderVersion+=1;var t=this._renderVersion;if(!this._state.merchantId){this._setStatus("error",{message:u.MERCHANT_ID_REQUIRED}),this._renderError(u.MERCHANT_ID_REQUIRED);return}if(!this._state.widgetId){this._setStatus("error",{message:u.WIDGET_ID_REQUIRED}),this._renderError(u.WIDGET_ID_REQUIRED);return}if(!this._state.env){this._setStatus("error",{message:u.ENV_REQUIRED}),this._renderError(u.ENV_REQUIRED);return}this._renderLoading(),this._initializeSessionIfNeeded().then(function(i){t===this._renderVersion&&this._renderIframe(i.iframeUrl,t)}.bind(this)).catch(function(i){if(t===this._renderVersion){var n=U(i instanceof Error?i:new Error(String(i)));this._renderError(n)}}.bind(this))}}open(){return this.style.display="",Promise.resolve()}close(){return this.style.display="none",Promise.resolve()}}typeof customElements!="undefined"&&!customElements.get(g)&&customElements.define(g,Tt)})();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitraun/webar",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Vitraun WebAR widget as Web Component",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "publishConfig": {