@vitraun/webar 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -55
- package/dist/events.min.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.min.js +1 -1
- package/dist/react.min.js +1 -1
- package/dist/widget-runtime.min.js +2 -2
- package/dist/widget.min.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,78 +1,123 @@
|
|
|
1
1
|
# @vitraun/webar
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official Vitraun Virtual Try-On package for **web** storefronts.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Embeds try-on via the `<vitraun-vto>` Web Component (npm or CDN). The integrator **does not** hardcode the try-on URL — the widget calls **embed-init**, receives **`vtoUrl`**, and loads the session inside Shadow DOM.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Install
|
|
6
9
|
|
|
7
10
|
```bash
|
|
8
|
-
npm
|
|
11
|
+
npm install @vitraun/webar
|
|
9
12
|
```
|
|
10
13
|
|
|
14
|
+
Peer dependency for the React hook: `react` (≥18).
|
|
15
|
+
|
|
16
|
+
## Quick start
|
|
17
|
+
|
|
11
18
|
```ts
|
|
12
19
|
import '@vitraun/webar'
|
|
20
|
+
```
|
|
13
21
|
|
|
14
|
-
|
|
22
|
+
```html
|
|
23
|
+
<vitraun-vto
|
|
24
|
+
merchant-id="vtrn-mch-key-00000000-0000-4000-8000-000000000001"
|
|
25
|
+
widget-id="vtrn-wdg-key-00000000-0000-4000-8000-000000000002"
|
|
26
|
+
lang="en-US"
|
|
27
|
+
auto-open
|
|
28
|
+
></vitraun-vto>
|
|
15
29
|
```
|
|
16
30
|
|
|
31
|
+
Plain HTML via jsDelivr:
|
|
32
|
+
|
|
17
33
|
```html
|
|
34
|
+
<script src="https://cdn.jsdelivr.net/npm/@vitraun/webar@<version>/dist/widget.min.js"></script>
|
|
18
35
|
<vitraun-vto
|
|
19
36
|
merchant-id="vtrn-mch-key-..."
|
|
20
37
|
widget-id="vtrn-wdg-key-..."
|
|
21
|
-
lang="en"
|
|
22
|
-
auto-open
|
|
38
|
+
lang="en-US"
|
|
23
39
|
></vitraun-vto>
|
|
40
|
+
<script>
|
|
41
|
+
document.querySelector('vitraun-vto')?.open()
|
|
42
|
+
</script>
|
|
24
43
|
```
|
|
25
44
|
|
|
26
|
-
|
|
45
|
+
Replace `<version>` with the published semver (for example `0.2.5`).
|
|
27
46
|
|
|
28
|
-
|
|
47
|
+
## How it works
|
|
29
48
|
|
|
30
|
-
|
|
49
|
+
1. The host page loads `@vitraun/webar` (or `widget.min.js` from CDN).
|
|
50
|
+
2. The user triggers try-on (`open()`, or `auto-open` on connect).
|
|
51
|
+
3. The try-on runs in an internal iframe; events reach the host as **`CustomEvent`s** on `<vitraun-vto>`.
|
|
31
52
|
|
|
32
|
-
|
|
53
|
+
Shared embed-init logic lives in [`@vitraun/core`](../core).
|
|
33
54
|
|
|
34
|
-
|
|
35
|
-
https://cdn.jsdelivr.net/npm/@vitraun/webar@<version>/dist/widget.min.js
|
|
36
|
-
https://cdn.jsdelivr.net/npm/@vitraun/webar@<version>/dist/events.min.js
|
|
37
|
-
```
|
|
55
|
+
## Panel prerequisites
|
|
38
56
|
|
|
39
|
-
|
|
57
|
+
- Register **merchant ID** and **widget ID** in the Vitraun panel
|
|
58
|
+
- Configure **allowed embed hosts** on the channel (when origin enforcement is enabled)
|
|
59
|
+
- Serve the host page over **HTTPS**
|
|
40
60
|
|
|
41
|
-
|
|
42
|
-
<script src="https://cdn.jsdelivr.net/npm/@vitraun/webar@0.1.2/dist/widget.min.js"></script>
|
|
43
|
-
<script type="module">
|
|
44
|
-
import { subscribeVitraunVTOEvents } from 'https://cdn.jsdelivr.net/npm/@vitraun/webar@0.1.2/dist/events.min.js'
|
|
45
|
-
</script>
|
|
46
|
-
```
|
|
61
|
+
## Configuration
|
|
47
62
|
|
|
48
|
-
|
|
63
|
+
| Option | Required | Description |
|
|
64
|
+
|--------|----------|-------------|
|
|
65
|
+
| `merchant-id` | Yes | Public merchant key (`vtrn-mch-key-…`) |
|
|
66
|
+
| `widget-id` | Yes | Public widget key (`vtrn-wdg-key-…`) |
|
|
67
|
+
| `lang` | No | Locale (default `en-US`) |
|
|
68
|
+
| `env` | No | Environment segment (empty = production; e.g. `staging`) |
|
|
69
|
+
| `isolated-sku` | No | Single-product (PDP) mode |
|
|
70
|
+
| `apply-skus` | No | Comma-separated SKUs pre-applied on open |
|
|
71
|
+
| `basket-opens-in` | No | `blank`, `self`, or `event` |
|
|
72
|
+
| `checkout-opens-in` | No | `blank`, `self`, or `event` |
|
|
73
|
+
| `auto-open` | No | Calls `open()` when the element connects |
|
|
74
|
+
| `console` | No | When `true`, shows an in-widget Events debug console |
|
|
49
75
|
|
|
50
|
-
|
|
76
|
+
Try-On app origin is baked into the published bundle. Override with `data-base-url` only for staging or self-hosted apps. Rebuild with `VITRAUN_WIDGET_EMBEDDED_BASE_URL=<origin>` when needed.
|
|
51
77
|
|
|
52
|
-
|
|
78
|
+
## Staging
|
|
53
79
|
|
|
54
|
-
|
|
80
|
+
```html
|
|
81
|
+
<vitraun-vto
|
|
82
|
+
env="staging"
|
|
83
|
+
merchant-id="vtrn-mch-key-..."
|
|
84
|
+
widget-id="vtrn-wdg-key-..."
|
|
85
|
+
lang="en-US"
|
|
86
|
+
></vitraun-vto>
|
|
87
|
+
```
|
|
55
88
|
|
|
56
|
-
|
|
89
|
+
## Events
|
|
90
|
+
|
|
91
|
+
| Event | Typical use |
|
|
92
|
+
|-------|-------------|
|
|
93
|
+
| `addToCart` | Add SKU to cart |
|
|
94
|
+
| `removeFromCart` | Remove line item |
|
|
95
|
+
| `redirectToCart` | Open checkout |
|
|
96
|
+
| `analysisFinished` | Camera / analysis ready |
|
|
97
|
+
|
|
98
|
+
Optional: `statusChange`, `vtoUsage`.
|
|
57
99
|
|
|
58
100
|
```ts
|
|
59
|
-
import {
|
|
60
|
-
VITRAUN_VTO_DEFAULT_EVENT_TYPES,
|
|
61
|
-
subscribeVitraunVTOEvents,
|
|
62
|
-
} from '@vitraun/webar'
|
|
101
|
+
import { subscribeVitraunVTOEvents } from '@vitraun/webar'
|
|
63
102
|
|
|
64
|
-
const dispose = subscribeVitraunVTOEvents(
|
|
65
|
-
console.log(entry.type, entry.
|
|
103
|
+
const dispose = subscribeVitraunVTOEvents(widgetElement, (entry) => {
|
|
104
|
+
console.log(entry.type, entry.detail)
|
|
66
105
|
})
|
|
67
106
|
|
|
68
|
-
// later:
|
|
69
107
|
dispose()
|
|
70
108
|
```
|
|
71
109
|
|
|
72
|
-
|
|
73
|
-
|
|
110
|
+
## Advanced usage
|
|
111
|
+
|
|
112
|
+
Programmatic control:
|
|
74
113
|
|
|
75
|
-
|
|
114
|
+
```ts
|
|
115
|
+
const widget = document.querySelector('vitraun-vto')
|
|
116
|
+
widget?.open()
|
|
117
|
+
widget?.close()
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
React event log hook:
|
|
76
121
|
|
|
77
122
|
```ts
|
|
78
123
|
import { useVitraunVTOEventLogs } from '@vitraun/webar/react'
|
|
@@ -80,28 +125,24 @@ import { useVitraunVTOEventLogs } from '@vitraun/webar/react'
|
|
|
80
125
|
const { events, clearEvents } = useVitraunVTOEventLogs(containerRef.current)
|
|
81
126
|
```
|
|
82
127
|
|
|
83
|
-
|
|
128
|
+
Embed-init is handled internally by the widget — no separate init call is required on web.
|
|
84
129
|
|
|
85
|
-
|
|
130
|
+
## Distribution
|
|
86
131
|
|
|
87
|
-
|
|
88
|
-
npm run build
|
|
89
|
-
export VITRAUN_CDN_UPLOAD=1
|
|
90
|
-
export VITRAUN_CDN_S3_BUCKET=your-bucket-name
|
|
91
|
-
npm run deploy:cdn
|
|
92
|
-
```
|
|
132
|
+
Load the widget from npm, **jsDelivr**, or your own CDN — not from the Try-On Next.js app origin.
|
|
93
133
|
|
|
94
|
-
|
|
134
|
+
**jsDelivr** (after `npm publish`):
|
|
95
135
|
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
merchant-id="vtrn-mch-key-..."
|
|
100
|
-
widget-id="vtrn-wdg-key-..."
|
|
101
|
-
lang="en"
|
|
102
|
-
></vitraun-vto>
|
|
103
|
-
<script>
|
|
104
|
-
document.querySelector('vitraun-vto')?.open()
|
|
105
|
-
</script>
|
|
136
|
+
```text
|
|
137
|
+
https://cdn.jsdelivr.net/npm/@vitraun/webar@<version>/dist/widget.min.js
|
|
138
|
+
https://cdn.jsdelivr.net/npm/@vitraun/webar@<version>/dist/events.min.js
|
|
106
139
|
```
|
|
107
140
|
|
|
141
|
+
## Package exports
|
|
142
|
+
|
|
143
|
+
| Export | Description |
|
|
144
|
+
|--------|-------------|
|
|
145
|
+
| `@vitraun/webar` | Registers `<vitraun-vto>` + event helpers |
|
|
146
|
+
| `@vitraun/webar/react` | `useVitraunVTOEventLogs` |
|
|
147
|
+
| `@vitraun/webar/widget.min.js` | Script-tag IIFE bundle |
|
|
148
|
+
| `@vitraun/webar/events` | Event helpers only |
|
package/dist/events.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var s=["addToCart","removeFromCart","redirectToCart","analysisFinished"],u=["statusChange","vtoUsage"],l=t=>Array.isArray(t)?t:[],I=(t={})=>{let r=l(t.eventTypes).filter(e=>typeof e=="string"&&e.trim());if(r.length>0)return[...new Set(r)];let o=t.includeStatusChange===!0,i=t.includeVtoUsage===!0,n=[...s];return o&&n.push("statusChange"),i&&n.push("vtoUsage"),[...new Set(n)]},a=t=>{let r=t;return{type:t.type,detail:r.detail,timestamp:new Date().toISOString(),nativeEvent:t}},c=(t,r,o={})=>{if(!t||typeof t.addEventListener!="function")return()=>{};if(typeof r!="function")return()=>{};let i=I(o);if(i.length===0)return()=>{};let n=e=>{r(a(e))};return i.forEach(e=>{t.addEventListener(e,n)}),()=>{i.forEach(e=>{t.removeEventListener(e,n)})}};var E=1800*1e3;export{s as VITRAUN_VTO_DEFAULT_EVENT_TYPES,u as VITRAUN_VTO_EXTRA_EVENT_TYPES,a as createVitraunEventLogEntry,c as subscribeVitraunVTOEvents};
|
package/dist/index.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ export interface VitraunVTOAttributes {
|
|
|
49
49
|
'basket-opens-in'?: 'event' | 'blank' | 'self'
|
|
50
50
|
'checkout-opens-in'?: 'event' | 'blank' | 'self'
|
|
51
51
|
'use-simple-page'?: string
|
|
52
|
+
'use-qr-code'?: string
|
|
52
53
|
'show-details'?: string
|
|
53
54
|
'show-product-price'?: string
|
|
54
55
|
'price-from'?: string
|
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var u=(
|
|
1
|
+
var u=(t=globalThis)=>t==null?!1:typeof t.window<"u"&&typeof t.HTMLElement<"u"&&typeof t.customElements<"u";var s=["addToCart","removeFromCart","redirectToCart","analysisFinished"],l=["statusChange","vtoUsage"],c=t=>Array.isArray(t)?t:[],E=(t={})=>{let r=c(t.eventTypes).filter(e=>typeof e=="string"&&e.trim());if(r.length>0)return[...new Set(r)];let o=t.includeStatusChange===!0,i=t.includeVtoUsage===!0,n=[...s];return o&&n.push("statusChange"),i&&n.push("vtoUsage"),[...new Set(n)]},a=t=>{let r=t;return{type:t.type,detail:r.detail,timestamp:new Date().toISOString(),nativeEvent:t}},I=(t,r,o={})=>{if(!t||typeof t.addEventListener!="function")return()=>{};if(typeof r!="function")return()=>{};let i=E(o);if(i.length===0)return()=>{};let n=e=>{r(a(e))};return i.forEach(e=>{t.addEventListener(e,n)}),()=>{i.forEach(e=>{t.removeEventListener(e,n)})}};var d=1800*1e3;u()&&import("./widget-runtime.min.js");export{s as VITRAUN_VTO_DEFAULT_EVENT_TYPES,l as VITRAUN_VTO_EXTRA_EVENT_TYPES,a as createVitraunEventLogEntry,I as subscribeVitraunVTOEvents};
|
package/dist/react.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEffect as
|
|
1
|
+
import{useEffect as _,useState as c}from"react";var u=["addToCart","removeFromCart","redirectToCart","analysisFinished"];var d=t=>Array.isArray(t)?t:[],T=(t={})=>{let e=d(t.eventTypes).filter(r=>typeof r=="string"&&r.trim());if(e.length>0)return[...new Set(e)];let o=t.includeStatusChange===!0,n=t.includeVtoUsage===!0,i=[...u];return o&&i.push("statusChange"),n&&i.push("vtoUsage"),[...new Set(i)]},l=t=>{let e=t;return{type:t.type,detail:e.detail,timestamp:new Date().toISOString(),nativeEvent:t}},a=(t,e,o={})=>{if(!t||typeof t.addEventListener!="function")return()=>{};if(typeof e!="function")return()=>{};let n=T(o);if(n.length===0)return()=>{};let i=r=>{e(l(r))};return n.forEach(r=>{t.addEventListener(r,i)}),()=>{n.forEach(r=>{t.removeEventListener(r,i)})}};var g=1800*1e3;var f=t=>({type:t.type,detail:t.detail,timestamp:t.timestamp}),A=(t,e={})=>{let[o,n]=c([]),[i,r]=c(0);return _(()=>{if(!t)return;let s=a(t,I=>{n(E=>[...E,f(I)])},e);return()=>{s()}},[t,i,e.includeStatusChange,e.includeVtoUsage,Array.isArray(e.eventTypes)?e.eventTypes.join("|"):""]),{events:o,clearEvents:()=>{n([]),r(s=>s+1)}}};export{A as useVitraunVTOEventLogs};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){"use strict";var F="VITRAUN_CONFIG",A="vtrn-vto-session",K=18e5,m=1e4,y="en-US",p="Vitraun",T="vitraun",C="https://",B="app.",W="app",b="."+T+".com",Y="/v1/public/virtual-tryon-embed-init",q="Content-Type",z="X-Origin",X="X-Tryon-Session-Id",Q="X-Merchant-Id",J="X-Widget-Id",j="application/json",Z="00000000-0000-0000-0000-000000000000",w=["addToCart","removeFromCart","redirectToCart","analysisFinished"],$=w.concat(["statusChange","vtoUsage"]),ee=150,g="vitraun-vto",te="["+g+"]",P=T+"-loading",L=T+"-error",ne=p+" VTO",re="Loading "+p+"...",ie="Failed to load "+p+".",oe="Timed out while initializing the "+p+" session.",i={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",CONSOLE:"console",INIT_TIMEOUT_MS:"init-timeout-ms"},se=[i.MERCHANT_ID,i.WIDGET_ID,i.ENV,i.API_PORT,i.APP_PORT,i.LANG,i.ISOLATED_SKU,i.APPLY_SKUS,i.FLOW,i.BASKET_OPENS_IN,i.CHECKOUT_OPENS_IN,i.USE_SIMPLE_PAGE,i.SHOW_DETAILS,i.SHOW_PRODUCT_PRICE,i.PRICE_FROM,i.PRICE_TO,i.CURRENCY_SYMBOL,i.IS_SIMULATION_MODE,i.SIMULATION_INLINE_CONFIG,i.CONTAINER_MIN_HEIGHT,i.APP_ID,i.PLATFORM,i.BUNDLE_ID,i.PACKAGE_NAME,i.APP_VERSION,i.ATTESTATION_TOKEN,i.DEBUG,i.CONSOLE,i.INIT_TIMEOUT_MS],_={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.",INIT_VTO_URL_MISSING:"The server did not return a virtual try-on URL (vtoUrl). Please contact the store.",INIT_VTO_URL_INVALID:"The virtual try-on URL returned by the server is invalid. Please contact the store."},ae="The operation timed out.",le={CONFIG_SKIPPED_NO_IFRAME_ORIGIN:"Config not sent: Origin is missing."},h={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.",GENERIC_SERVER_OR_CLIENT_MISMATCH:"Could not start the virtual try-on. Please refresh the page or contact the store."},ue="We couldn't connect to the virtual try-on service. Please try again or contact the store.",M={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_TOKEN_EXPIRED:"This embed session has expired. 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 S(t){return":host { display:block; width:100%; min-height:"+t+"; box-sizing:border-box; }.vitraun-host { position:relative; width:100%; min-height:"+t+"; box-sizing:border-box; }.vitraun-host > iframe { display:block; width:100%; border:0; min-height:"+t+"; }"}function de(){return'.vitraun-console-fab {position:absolute; bottom:12px; right:12px; z-index:5;padding:8px 12px; border:0; border-radius:8px;background:#0f172a; color:#f8fafc; font:600 12px/1.2 system-ui, sans-serif;cursor:pointer; box-shadow:0 4px 12px rgba(15,23,42,0.35);}.vitraun-console-fab:hover { background:#1e293b; }.vitraun-console-backdrop {position:absolute; inset:0; z-index:6; background:rgba(15,23,42,0.45);display:none; align-items:center; justify-content:center; padding:16px; box-sizing:border-box;}.vitraun-console-backdrop[data-open="true"] { display:flex; }.vitraun-console-modal {width:min(100%, 520px); max-height:min(70vh, 420px); display:flex; flex-direction:column;background:#fff; border-radius:12px; box-shadow:0 16px 40px rgba(15,23,42,0.25); overflow:hidden;}.vitraun-console-header {display:flex; align-items:center; justify-content:space-between; gap:8px;padding:12px 14px; border-bottom:1px solid #e2e8f0; background:#f8fafc;}.vitraun-console-title { font:600 14px/1.2 system-ui, sans-serif; color:#0f172a; margin:0; }.vitraun-console-actions { display:flex; gap:8px; }.vitraun-console-actions button {padding:6px 10px; border:1px solid #cbd5e1; border-radius:6px; background:#fff;font:500 12px/1 system-ui, sans-serif; color:#334155; cursor:pointer;}.vitraun-console-body {margin:0; padding:12px 14px; overflow:auto; flex:1; min-height:120px;font:12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color:#0f172a;white-space:pre-wrap; word-break:break-word; background:#fff;}.vitraun-console-empty { color:#64748b; font-style:italic; }'}function _e(t,e){return S(t)+"."+e+" {min-height:"+t+";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 he(t,e){return S(t)+"."+e+" {min-height:"+t+";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 u(t,e,n){var r=t.getAttribute(e);return r!=null&&r!==""?r:n}function I(t,e){if(t==null||t==="")return e;var n=String(t).toLowerCase();return n==="true"||n==="1"||n==="yes"}function U(t){if(t==null||t==="")return null;var e=parseFloat(String(t));return Number.isFinite(e)?e:null}function ce(t){return!t||typeof t!="string"?[]:t.split(",").map(function(e){return e.trim()}).filter(Boolean)}function Ie(t,e){var n=u(t,e,"");if(!n||typeof n!="string")return null;try{return JSON.parse(n)}catch{return null}}function D(t){try{return JSON.parse(t)}catch{return null}}function N(){return typeof window>"u"||!window.location||!window.location.origin?null:window.location.origin}function fe(){return typeof window>"u"||!window.location||!window.location.href?null:window.location.href}function pe(t){if(!t||typeof t!="string")return null;try{return new URL(t).origin}catch{return null}}function Ee(t){var e=String(t||"").trim().toLowerCase();if(!e)return"";if(!/^[a-z0-9-]+$/.test(e))throw new Error(_.ENV_INVALID);return e}function me(t){return t?String(t).trim().toLowerCase():"web"}function k(t){if(t==null||t==="")return null;var e=parseInt(String(t),10);return!Number.isInteger(e)||e<=0||e>65535?null:e}function Te(t,e){if(t==null||t==="")return"";var n=parseInt(String(t),10);return!Number.isInteger(n)||n<=0||n>65535||e==="https://"&&n===443||e==="http://"&&n===80?"":":"+n}function x(t){return!t||typeof t!="object"?!1:!!Array.isArray(t.message)}function G(t){if(!t||typeof t!="string")return!1;var e=t.toLowerCase();return e.indexOf("should not exist")!==-1||e.indexOf("should not be empty")!==-1||e.indexOf("forbidnonwhitelisted")!==-1||e.indexOf("whitelist")!==-1&&e.indexOf("property")!==-1||e.indexOf("property")!==-1&&e.indexOf("should not")!==-1}function V(t){if(!t||typeof t!="string")return!1;var e=t.trim();if(e.charAt(0)!=="{"||e.indexOf('"message"')===-1||e.indexOf('"statusCode"')===-1)return!1;var n=D(e);return x(n)}function ge(t,e){if(x(t))return h.GENERIC_SERVER_OR_CLIENT_MISMATCH;var n=t&&typeof t.errorCode=="string"?t.errorCode:null;if(n&&Object.prototype.hasOwnProperty.call(M,n))return M[n];var r=t&&typeof t.message=="string"?t.message.trim():"";if(r)return G(r)?h.GENERIC_SERVER_OR_CLIENT_MISMATCH:r;if(n)return h.GENERIC_TRY_AGAIN_OR_STORE;if(e&&String(e).length>0&&String(e).length<600){var o=String(e).trim();return V(o)?h.GENERIC_SERVER_OR_CLIENT_MISMATCH:o.charAt(0)==="{"&&o.indexOf("errorCode")!==-1?h.GENERIC_TRY_AGAIN:o.charAt(0)==="{"?h.GENERIC_SERVER_OR_CLIENT_MISMATCH:o}return h.GENERIC_TRY_AGAIN}function Se(t){if(!t||typeof t.message!="string")return!1;var e=t.name,n=t.message.toLowerCase();return e==="TypeError"&&(n.indexOf("failed to fetch")!==-1||n.indexOf("load failed")!==-1)||n.indexOf("networkerror when attempting to fetch")!==-1||e==="NetworkError"||n.indexOf("network request failed")!==-1}function H(t){if(Se(t))return ue;if(t&&typeof t.message=="string"&&t.message.trim()){var e=t.message.trim();return G(e)||V(e)||e.charAt(0)==="{"&&e.indexOf('"message"')!==-1&&e.indexOf('"statusCode"')!==-1?h.GENERIC_SERVER_OR_CLIENT_MISMATCH:e}return h.GENERIC_TRY_AGAIN}function Ne(t,e){var n=t&&String(t).trim()?B+String(t).trim().toLowerCase()+b:W+b;return C+n+Te(e,C)+Y}function ve(t){var e=t.merchantId!=null?String(t.merchantId):"",n=t.widgetId!=null?String(t.widgetId):"",r=t.tryonSessionId!=null?String(t.tryonSessionId):"",o=t.origin!==void 0&&t.origin!==null&&t.origin!==""?String(t.origin):N()||"",s={};return s[z]=o,s[X]=r,s[Q]=e,s[J]=n,t.contentType&&(s[q]=t.contentType),s}function Oe(t,e){return{merchantId:t.merchantId,widgetId:t.widgetId,tryonSessionId:e,env:t.env,lang:t.lang,isSimulationMode:t.isSimulationMode===!0,appPort:t.appPort,app:{appId:t.appId,platform:t.platform,bundleId:t.bundleId,packageName:t.packageName,appVersion:t.appVersion,attestationToken:t.attestationToken},context:{origin:N(),pageUrl:fe(),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 Re(t,e,n,r){return!e||e<=0?t:new Promise(function(o,s){var l=!1,a=setTimeout(function(){if(!l){l=!0;try{r&&typeof r.abort=="function"&&r.abort()}catch{}s(new Error(n||ae))}},e);t.then(function(d){l||(l=!0,clearTimeout(a),o(d))}).catch(function(d){l||(l=!0,clearTimeout(a),s(d))})})}function Ae(t){var e=t!=null?String(t).trim():"";return e?A+":"+e:A}function v(t){if(typeof window>"u"||!window.crypto||!window.crypto.randomUUID)return Z;var e=Ae(t);try{var n=sessionStorage.getItem(e);if(n){var r=JSON.parse(n);if(r&&typeof r.id=="string"&&typeof r.exp=="number"&&Date.now()<r.exp)return r.id}}catch{}var o=window.crypto.randomUUID(),s=Date.now()+K;try{sessionStorage.setItem(e,JSON.stringify({id:o,exp:s}))}catch{}return o}function ye(t,e,n){var r=e.merchantId!=null?String(e.merchantId).trim():"",o=e.widgetId!=null?String(e.widgetId).trim():"";if(!r||!o)return t;var s;try{s=new URL(t)}catch{return t}s.searchParams.set("merchantId",r),s.searchParams.set("widgetId",o),s.searchParams.set("embed","1");var l=e.tryonSessionId!=null?String(e.tryonSessionId).trim():"";l||(l=v(n)),l&&s.searchParams.set("tryonSessionId",l);var a=e.sessionToken!=null?String(e.sessionToken).trim():"";return a&&s.searchParams.set("embedSessionToken",a),s.toString()}class Ce extends HTMLElement{static get observedAttributes(){return se.slice()}constructor(){super(),this.attachShadow({mode:"open"}),this._state={merchantId:"",widgetId:"",env:"",apiPort:null,appPort:null,lang:y,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,console:!1,sessionToken:null,tryonSessionId:null,resolvedInitUrl:null,resolvedIframeUrl:null,initTimeoutMs:m},this._consoleLog=[],this._consoleModalOpen=!1,this._consoleCaptureTeardown=null,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._setupConsoleCapture(),this._render(),typeof window<"u"&&window.addEventListener("message",this._boundHandleMessage)}disconnectedCallback(){if(typeof window<"u"&&window.removeEventListener("message",this._boundHandleMessage),this._teardownConsoleCapture(),this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch{}}attributeChangedCallback(e,n,r){n!==r&&(this._readAttributes(),this._setupConsoleCapture(),this._render())}_log(){if(!(!this._state.debug||typeof console>"u"||!console.log)){var e=Array.prototype.slice.call(arguments);e.unshift(te),console.log.apply(console,e)}}_readAttributes(){var e=Ie(this,i.SIMULATION_INLINE_CONFIG),n=!1;e&&e.features&&typeof e.features.showProductPrice=="boolean"&&(n=e.features.showProductPrice);var r=!0;e&&e.features&&typeof e.features.useSimplePage=="boolean"&&(r=e.features.useSimplePage);var o="checkout";e&&e.features&&(e.features.flow==="catalog"||e.features.flow==="checkout")&&(o=e.features.flow);var s=!0;e&&e.features&&typeof e.features.showDetails=="boolean"&&(s=e.features.showDetails);var l="";try{l=Ee(u(this,i.ENV,""))}catch{l=""}var a=parseInt(u(this,i.INIT_TIMEOUT_MS,String(m)),10);(!Number.isFinite(a)||a<0)&&(a=m),this._state={merchantId:u(this,i.MERCHANT_ID,""),widgetId:u(this,i.WIDGET_ID,""),env:l,apiPort:k(u(this,i.API_PORT,null)),appPort:k(u(this,i.APP_PORT,null)),lang:u(this,i.LANG,y),isolatedSku:u(this,i.ISOLATED_SKU,null)||null,applySkus:ce(u(this,i.APPLY_SKUS,"")),iframeOrigin:this._state&&this._state.iframeOrigin?this._state.iframeOrigin:null,flow:u(this,i.FLOW,o),basketOpensIn:u(this,i.BASKET_OPENS_IN,"event"),checkoutOpensIn:u(this,i.CHECKOUT_OPENS_IN,"event"),useSimplePage:I(u(this,i.USE_SIMPLE_PAGE,""),r),showDetails:I(u(this,i.SHOW_DETAILS,""),s),showProductPrice:I(u(this,i.SHOW_PRODUCT_PRICE,""),n),priceFrom:U(u(this,i.PRICE_FROM,null)),priceTo:U(u(this,i.PRICE_TO,null)),currencySymbol:u(this,i.CURRENCY_SYMBOL,null)||null,isSimulationMode:I(u(this,i.IS_SIMULATION_MODE,"false"),!1),simulationInlineConfig:e,appId:u(this,i.APP_ID,null)||null,platform:me(u(this,i.PLATFORM,null)),bundleId:u(this,i.BUNDLE_ID,null)||null,packageName:u(this,i.PACKAGE_NAME,null)||null,appVersion:u(this,i.APP_VERSION,null)||null,attestationToken:u(this,i.ATTESTATION_TOKEN,null)||null,debug:I(u(this,i.DEBUG,"false"),!1),console:I(u(this,i.CONSOLE,"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(e,n){this.dispatchEvent(new CustomEvent(e,{detail:n??null,bubbles:!0,composed:!0}))}_teardownConsoleCapture(){typeof this._consoleCaptureTeardown=="function"&&(this._consoleCaptureTeardown(),this._consoleCaptureTeardown=null)}_setupConsoleCapture(){if(this._teardownConsoleCapture(),!!this._state.console){var e=this,n=[];$.forEach(function(r){var o=function(s){e._appendConsoleLog(r,s.detail)};e.addEventListener(r,o),n.push({eventType:r,handler:o})}),this._consoleCaptureTeardown=function(){n.forEach(function(r){e.removeEventListener(r.eventType,r.handler)})}}}_appendConsoleLog(e,n){this._state.console&&(Array.isArray(this._consoleLog)||(this._consoleLog=[]),this._consoleLog.push({type:e,timestamp:new Date().toISOString(),detail:n??null}),this._consoleLog.length>ee&&this._consoleLog.shift(),this._refreshConsoleChrome())}_formatConsoleLogText(){return!this._consoleLog||this._consoleLog.length===0?"":this._consoleLog.map(function(e){var n="";try{n=JSON.stringify(e.detail,null,2)}catch{n=String(e.detail)}return"["+e.timestamp+"] "+e.type+`
|
|
1
|
+
(function(){"use strict";var F="VITRAUN_CONFIG",R="vtrn-vto-session",K=18e5,m=1e4,A="en-US",E="Vitraun",T="vitraun",y="https://",B="app.",W="app",b="."+T+".com",Y="/v1/public/virtual-tryon-embed-init",Q="Content-Type",q="X-Origin",z="X-Tryon-Session-Id",X="X-Merchant-Id",J="X-Widget-Id",Z="application/json",$="00000000-0000-0000-0000-000000000000",P=["addToCart","removeFromCart","redirectToCart","analysisFinished"],j=P.concat(["statusChange","vtoUsage"]),ee=150,g="vitraun-vto",te="["+g+"]",w=T+"-loading",L=T+"-error",ne=E+" VTO",re="Loading "+E+"...",ie="Failed to load "+E+".",oe="Timed out while initializing the "+E+" session.",i={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",USE_QR_CODE:"use-qr-code",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",CONSOLE:"console",INIT_TIMEOUT_MS:"init-timeout-ms"},se=[i.MERCHANT_ID,i.WIDGET_ID,i.ENV,i.API_PORT,i.APP_PORT,i.LANG,i.ISOLATED_SKU,i.APPLY_SKUS,i.FLOW,i.BASKET_OPENS_IN,i.CHECKOUT_OPENS_IN,i.USE_SIMPLE_PAGE,i.USE_QR_CODE,i.SHOW_DETAILS,i.SHOW_PRODUCT_PRICE,i.PRICE_FROM,i.PRICE_TO,i.CURRENCY_SYMBOL,i.IS_SIMULATION_MODE,i.SIMULATION_INLINE_CONFIG,i.CONTAINER_MIN_HEIGHT,i.APP_ID,i.PLATFORM,i.BUNDLE_ID,i.PACKAGE_NAME,i.APP_VERSION,i.ATTESTATION_TOKEN,i.DEBUG,i.CONSOLE,i.INIT_TIMEOUT_MS],h={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.",INIT_VTO_URL_MISSING:"The server did not return a virtual try-on URL (vtoUrl). Please contact the store.",INIT_VTO_URL_INVALID:"The virtual try-on URL returned by the server is invalid. Please contact the store."},ae="The operation timed out.",le={CONFIG_SKIPPED_NO_IFRAME_ORIGIN:"Config not sent: Origin 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.",GENERIC_SERVER_OR_CLIENT_MISMATCH:"Could not start the virtual try-on. Please refresh the page or contact the store."},de="We couldn't connect to the virtual try-on service. Please try again or contact the store.",U={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_TOKEN_EXPIRED:"This embed session has expired. 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 S(t){return":host { display:block; width:100%; min-height:"+t+"; box-sizing:border-box; }.vitraun-host { position:relative; width:100%; min-height:"+t+"; box-sizing:border-box; }.vitraun-host > iframe { display:block; width:100%; border:0; min-height:"+t+"; }"}function ue(){return'.vitraun-console-fab {position:absolute; bottom:12px; right:12px; z-index:5;padding:8px 12px; border:0; border-radius:8px;background:#0f172a; color:#f8fafc; font:600 12px/1.2 system-ui, sans-serif;cursor:pointer; box-shadow:0 4px 12px rgba(15,23,42,0.35);}.vitraun-console-fab:hover { background:#1e293b; }.vitraun-console-backdrop {position:absolute; inset:0; z-index:6; background:rgba(15,23,42,0.45);display:none; align-items:center; justify-content:center; padding:16px; box-sizing:border-box;}.vitraun-console-backdrop[data-open="true"] { display:flex; }.vitraun-console-modal {width:min(100%, 520px); max-height:min(70vh, 420px); display:flex; flex-direction:column;background:#fff; border-radius:12px; box-shadow:0 16px 40px rgba(15,23,42,0.25); overflow:hidden;}.vitraun-console-header {display:flex; align-items:center; justify-content:space-between; gap:8px;padding:12px 14px; border-bottom:1px solid #e2e8f0; background:#f8fafc;}.vitraun-console-title { font:600 14px/1.2 system-ui, sans-serif; color:#0f172a; margin:0; }.vitraun-console-actions { display:flex; gap:8px; }.vitraun-console-actions button {padding:6px 10px; border:1px solid #cbd5e1; border-radius:6px; background:#fff;font:500 12px/1 system-ui, sans-serif; color:#334155; cursor:pointer;}.vitraun-console-body {margin:0; padding:12px 14px; overflow:auto; flex:1; min-height:120px;font:12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color:#0f172a;white-space:pre-wrap; word-break:break-word; background:#fff;}.vitraun-console-empty { color:#64748b; font-style:italic; }'}function _e(t,e){return S(t)+"."+e+" {min-height:"+t+";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 he(t,e){return S(t)+"."+e+" {min-height:"+t+";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 d(t,e,n){var r=t.getAttribute(e);return r!=null&&r!==""?r:n}function I(t,e){if(t==null||t==="")return e;var n=String(t).toLowerCase();return n==="true"||n==="1"||n==="yes"}function ce(t,e){var n=t.getAttribute(e);if(!(n==null||n===""))return I(n,!1)}function M(t){if(t==null||t==="")return null;var e=parseFloat(String(t));return Number.isFinite(e)?e:null}function fe(t){return!t||typeof t!="string"?[]:t.split(",").map(function(e){return e.trim()}).filter(Boolean)}function Ie(t,e){var n=d(t,e,"");if(!n||typeof n!="string")return null;try{return JSON.parse(n)}catch{return null}}function D(t){try{return JSON.parse(t)}catch{return null}}function N(){return typeof window>"u"||!window.location||!window.location.origin?null:window.location.origin}function pe(){return typeof window>"u"||!window.location||!window.location.href?null:window.location.href}function Ee(t){if(!t||typeof t!="string")return null;try{return new URL(t).origin}catch{return null}}function me(t){var e=String(t||"").trim().toLowerCase();if(!e)return"";if(!/^[a-z0-9-]+$/.test(e))throw new Error(h.ENV_INVALID);return e}function Te(t){return t?String(t).trim().toLowerCase():"web"}function k(t){if(t==null||t==="")return null;var e=parseInt(String(t),10);return!Number.isInteger(e)||e<=0||e>65535?null:e}function ge(t,e){if(t==null||t==="")return"";var n=parseInt(String(t),10);return!Number.isInteger(n)||n<=0||n>65535||e==="https://"&&n===443||e==="http://"&&n===80?"":":"+n}function x(t){return!t||typeof t!="object"?!1:!!Array.isArray(t.message)}function G(t){if(!t||typeof t!="string")return!1;var e=t.toLowerCase();return e.indexOf("should not exist")!==-1||e.indexOf("should not be empty")!==-1||e.indexOf("forbidnonwhitelisted")!==-1||e.indexOf("whitelist")!==-1&&e.indexOf("property")!==-1||e.indexOf("property")!==-1&&e.indexOf("should not")!==-1}function V(t){if(!t||typeof t!="string")return!1;var e=t.trim();if(e.charAt(0)!=="{"||e.indexOf('"message"')===-1||e.indexOf('"statusCode"')===-1)return!1;var n=D(e);return x(n)}function Se(t,e){if(x(t))return c.GENERIC_SERVER_OR_CLIENT_MISMATCH;var n=t&&typeof t.errorCode=="string"?t.errorCode:null;if(n&&Object.prototype.hasOwnProperty.call(U,n))return U[n];var r=t&&typeof t.message=="string"?t.message.trim():"";if(r)return G(r)?c.GENERIC_SERVER_OR_CLIENT_MISMATCH:r;if(n)return c.GENERIC_TRY_AGAIN_OR_STORE;if(e&&String(e).length>0&&String(e).length<600){var o=String(e).trim();return V(o)?c.GENERIC_SERVER_OR_CLIENT_MISMATCH:o.charAt(0)==="{"&&o.indexOf("errorCode")!==-1?c.GENERIC_TRY_AGAIN:o.charAt(0)==="{"?c.GENERIC_SERVER_OR_CLIENT_MISMATCH:o}return c.GENERIC_TRY_AGAIN}function Ne(t){if(!t||typeof t.message!="string")return!1;var e=t.name,n=t.message.toLowerCase();return e==="TypeError"&&(n.indexOf("failed to fetch")!==-1||n.indexOf("load failed")!==-1)||n.indexOf("networkerror when attempting to fetch")!==-1||e==="NetworkError"||n.indexOf("network request failed")!==-1}function H(t){if(Ne(t))return de;if(t&&typeof t.message=="string"&&t.message.trim()){var e=t.message.trim();return G(e)||V(e)||e.charAt(0)==="{"&&e.indexOf('"message"')!==-1&&e.indexOf('"statusCode"')!==-1?c.GENERIC_SERVER_OR_CLIENT_MISMATCH:e}return c.GENERIC_TRY_AGAIN}function ve(t,e){var n=t&&String(t).trim()?B+String(t).trim().toLowerCase()+b:W+b;return y+n+ge(e,y)+Y}function Oe(t){var e=t.merchantId!=null?String(t.merchantId):"",n=t.widgetId!=null?String(t.widgetId):"",r=t.tryonSessionId!=null?String(t.tryonSessionId):"",o=t.origin!==void 0&&t.origin!==null&&t.origin!==""?String(t.origin):N()||"",s={};return s[q]=o,s[z]=r,s[X]=e,s[J]=n,t.contentType&&(s[Q]=t.contentType),s}function Ce(t,e){return{merchantId:t.merchantId,widgetId:t.widgetId,tryonSessionId:e,env:t.env,lang:t.lang,isSimulationMode:t.isSimulationMode===!0,appPort:t.appPort,app:{appId:t.appId,platform:t.platform,bundleId:t.bundleId,packageName:t.packageName,appVersion:t.appVersion,attestationToken:t.attestationToken},context:{origin:N(),pageUrl:pe(),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 Re(t,e,n,r){return!e||e<=0?t:new Promise(function(o,s){var l=!1,a=setTimeout(function(){if(!l){l=!0;try{r&&typeof r.abort=="function"&&r.abort()}catch{}s(new Error(n||ae))}},e);t.then(function(u){l||(l=!0,clearTimeout(a),o(u))}).catch(function(u){l||(l=!0,clearTimeout(a),s(u))})})}function Ae(t){var e=t!=null?String(t).trim():"";return e?R+":"+e:R}function v(t){if(typeof window>"u"||!window.crypto||!window.crypto.randomUUID)return $;var e=Ae(t);try{var n=sessionStorage.getItem(e);if(n){var r=JSON.parse(n);if(r&&typeof r.id=="string"&&typeof r.exp=="number"&&Date.now()<r.exp)return r.id}}catch{}var o=window.crypto.randomUUID(),s=Date.now()+K;try{sessionStorage.setItem(e,JSON.stringify({id:o,exp:s}))}catch{}return o}function ye(t,e,n){var r=e.merchantId!=null?String(e.merchantId).trim():"",o=e.widgetId!=null?String(e.widgetId).trim():"";if(!r||!o)return t;var s;try{s=new URL(t)}catch{return t}s.searchParams.set("merchantId",r),s.searchParams.set("widgetId",o),s.searchParams.set("embed","1");var l=e.tryonSessionId!=null?String(e.tryonSessionId).trim():"";l||(l=v(n)),l&&s.searchParams.set("tryonSessionId",l);var a=e.sessionToken!=null?String(e.sessionToken).trim():"";return a&&s.searchParams.set("embedSessionToken",a),s.toString()}class be extends HTMLElement{static get observedAttributes(){return se.slice()}constructor(){super(),this.attachShadow({mode:"open"}),this._state={merchantId:"",widgetId:"",env:"",apiPort:null,appPort:null,lang:A,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,console:!1,sessionToken:null,handoffToken:null,embedParentOrigin:null,tryonSessionId:null,resolvedInitUrl:null,resolvedIframeUrl:null,initTimeoutMs:m},this._consoleLog=[],this._consoleModalOpen=!1,this._consoleCaptureTeardown=null,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._setupConsoleCapture(),this._render(),typeof window<"u"&&window.addEventListener("message",this._boundHandleMessage)}disconnectedCallback(){if(typeof window<"u"&&window.removeEventListener("message",this._boundHandleMessage),this._teardownConsoleCapture(),this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch{}}attributeChangedCallback(e,n,r){n!==r&&(this._readAttributes(),this._setupConsoleCapture(),this._render())}_log(){if(!(!this._state.debug||typeof console>"u"||!console.log)){var e=Array.prototype.slice.call(arguments);e.unshift(te),console.log.apply(console,e)}}_readAttributes(){var e=Ie(this,i.SIMULATION_INLINE_CONFIG),n=!1;e&&e.features&&typeof e.features.showProductPrice=="boolean"&&(n=e.features.showProductPrice);var r=!0;e&&e.features&&typeof e.features.useSimplePage=="boolean"&&(r=e.features.useSimplePage);var o="checkout";e&&e.features&&(e.features.flow==="catalog"||e.features.flow==="checkout")&&(o=e.features.flow);var s=!0;e&&e.features&&typeof e.features.showDetails=="boolean"&&(s=e.features.showDetails);var l=e&&e.features&&typeof e.features.useQrCode=="boolean"?e.features.useQrCode:void 0,a=ce(this,i.USE_QR_CODE),u=a!==void 0?a:l,_="";try{_=me(d(this,i.ENV,""))}catch{_=""}var f=parseInt(d(this,i.INIT_TIMEOUT_MS,String(m)),10);(!Number.isFinite(f)||f<0)&&(f=m),this._state={merchantId:d(this,i.MERCHANT_ID,""),widgetId:d(this,i.WIDGET_ID,""),env:_,apiPort:k(d(this,i.API_PORT,null)),appPort:k(d(this,i.APP_PORT,null)),lang:d(this,i.LANG,A),isolatedSku:d(this,i.ISOLATED_SKU,null)||null,applySkus:fe(d(this,i.APPLY_SKUS,"")),iframeOrigin:this._state&&this._state.iframeOrigin?this._state.iframeOrigin:null,flow:d(this,i.FLOW,o),basketOpensIn:d(this,i.BASKET_OPENS_IN,"event"),checkoutOpensIn:d(this,i.CHECKOUT_OPENS_IN,"event"),useSimplePage:I(d(this,i.USE_SIMPLE_PAGE,""),r),useQrCode:u,showDetails:I(d(this,i.SHOW_DETAILS,""),s),showProductPrice:I(d(this,i.SHOW_PRODUCT_PRICE,""),n),priceFrom:M(d(this,i.PRICE_FROM,null)),priceTo:M(d(this,i.PRICE_TO,null)),currencySymbol:d(this,i.CURRENCY_SYMBOL,null)||null,isSimulationMode:I(d(this,i.IS_SIMULATION_MODE,"false"),!1),simulationInlineConfig:e,appId:d(this,i.APP_ID,null)||null,platform:Te(d(this,i.PLATFORM,null)),bundleId:d(this,i.BUNDLE_ID,null)||null,packageName:d(this,i.PACKAGE_NAME,null)||null,appVersion:d(this,i.APP_VERSION,null)||null,attestationToken:d(this,i.ATTESTATION_TOKEN,null)||null,debug:I(d(this,i.DEBUG,"false"),!1),console:I(d(this,i.CONSOLE,"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:f}}_emit(e,n){this.dispatchEvent(new CustomEvent(e,{detail:n??null,bubbles:!0,composed:!0}))}_teardownConsoleCapture(){typeof this._consoleCaptureTeardown=="function"&&(this._consoleCaptureTeardown(),this._consoleCaptureTeardown=null)}_setupConsoleCapture(){if(this._teardownConsoleCapture(),!!this._state.console){var e=this,n=[];j.forEach(function(r){var o=function(s){e._appendConsoleLog(r,s.detail)};e.addEventListener(r,o),n.push({eventType:r,handler:o})}),this._consoleCaptureTeardown=function(){n.forEach(function(r){e.removeEventListener(r.eventType,r.handler)})}}}_appendConsoleLog(e,n){this._state.console&&(Array.isArray(this._consoleLog)||(this._consoleLog=[]),this._consoleLog.push({type:e,timestamp:new Date().toISOString(),detail:n??null}),this._consoleLog.length>ee&&this._consoleLog.shift(),this._refreshConsoleChrome())}_formatConsoleLogText(){return!this._consoleLog||this._consoleLog.length===0?"":this._consoleLog.map(function(e){var n="";try{n=JSON.stringify(e.detail,null,2)}catch{n=String(e.detail)}return"["+e.timestamp+"] "+e.type+`
|
|
2
2
|
`+n}).join(`
|
|
3
3
|
|
|
4
|
-
`)}_refreshConsoleChrome(){if(!(!this.shadowRoot||!this._state.console)){var e=this.shadowRoot.querySelector(".vitraun-console-fab");if(e){var n=this._consoleLog?this._consoleLog.length:0;e.textContent=n>0?"Events ("+n+")":"Events"}var r=this.shadowRoot.querySelector(".vitraun-console-body");if(r&&this._consoleModalOpen){var o=this._formatConsoleLogText();o?(r.textContent=o,r.classList.remove("vitraun-console-empty")):(r.textContent="No events yet. Interact with the try-on to see activity.",r.classList.add("vitraun-console-empty")),r.scrollTop=r.scrollHeight}}}_setConsoleModalOpen(e){if(this._consoleModalOpen=e===!0,!!this.shadowRoot){var n=this.shadowRoot.querySelector(".vitraun-console-backdrop");n&&n.setAttribute("data-open",this._consoleModalOpen?"true":"false"),this._refreshConsoleChrome()}}_mountConsoleChrome(e){if(!(!e||!this._state.console)){var n=e.querySelector(".vitraun-console-fab");if(n){this._refreshConsoleChrome();return}var r=this,o=document.createElement("button");o.type="button",o.className="vitraun-console-fab",o.setAttribute("aria-label","Open Try-On events console"),o.textContent="Events",o.addEventListener("click",function(){r._setConsoleModalOpen(!0)});var s=document.createElement("div");s.className="vitraun-console-backdrop",s.setAttribute("data-open","false"),s.setAttribute("role","presentation"),s.addEventListener("click",function(R){R.target===s&&r._setConsoleModalOpen(!1)});var l=document.createElement("div");l.className="vitraun-console-modal",l.setAttribute("role","dialog"),l.setAttribute("aria-modal","true"),l.setAttribute("aria-label","Try-On events console"),l.addEventListener("click",function(R){R.stopPropagation()});var a=document.createElement("div");a.className="vitraun-console-header";var d=document.createElement("h2");d.className="vitraun-console-title",d.textContent="Try-On events";var c=document.createElement("div");c.className="vitraun-console-actions";var f=document.createElement("button");f.type="button",f.textContent="Clear",f.addEventListener("click",function(){r._consoleLog=[],r._refreshConsoleChrome()});var E=document.createElement("button");E.type="button",E.textContent="Close",E.addEventListener("click",function(){r._setConsoleModalOpen(!1)}),c.appendChild(f),c.appendChild(E),a.appendChild(d),a.appendChild(c);var O=document.createElement("pre");O.className="vitraun-console-body vitraun-console-empty",O.textContent="No events yet. Interact with the try-on to see activity.",l.appendChild(a),l.appendChild(O),s.appendChild(l),e.appendChild(o),e.appendChild(s),this._refreshConsoleChrome()}}_setStatus(e,n){this.setAttribute("data-status",e),this._emit("statusChange",{status:e,detail:n||null})}_getIframeElement(){return this.shadowRoot?this.shadowRoot.querySelector("iframe"):null}_getInstanceSessionKey(){return this.id==null?"":String(this.id).trim()}_handleMessage(e){var n=e.data;if(!(!n||typeof n!="object")){var r=this._getIframeElement();if(!(!r||!r.contentWindow)&&e.source===r.contentWindow&&!(!this._state.iframeOrigin||e.origin!==this._state.iframeOrigin)){var o=n.type,s=n.detail;if(o==="VTO_USAGE"){this._emit("vtoUsage",s);return}w.indexOf(o)!==-1&&this._emit(o,s)}}}_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})}_buildEmbedInitUrl(){return Ne(this._state.env,this._state.apiPort)}_buildInitPayload(){var e=v(this._getInstanceSessionKey());return{tryonSessionId:e,initRequestBody:Oe(this._state,e)}}_normalizeInitResponse(e,n,r){if(!e||typeof e!="object")throw new Error(_.INIT_INVALID_RESPONSE);var o=typeof e.sessionToken=="string"&&e.sessionToken?e.sessionToken:null,s=typeof e.tryonSessionId=="string"&&e.tryonSessionId?e.tryonSessionId:r;if(!o)throw new Error(_.INIT_SESSION_TOKEN_MISSING);var l=typeof e.vtoUrl=="string"&&e.vtoUrl.trim()?e.vtoUrl.trim():null;if(!l&&typeof e.iframeUrl=="string"&&e.iframeUrl.trim()&&(l=e.iframeUrl.trim()),!l)throw new Error(_.INIT_VTO_URL_MISSING);var a=pe(l);if(!a)throw new Error(_.INIT_VTO_URL_INVALID);return{sessionToken:o,tryonSessionId:s,initUrl:n,iframeUrl:l,iframeOrigin:a}}_initializeSessionIfNeeded(){var e=this;if(!this._state.merchantId)return Promise.reject(new Error(_.MERCHANT_ID_REQUIRED));if(!this._state.widgetId)return Promise.reject(new Error(_.WIDGET_ID_REQUIRED));var n=this._getInitStateKey();if(this._initPromise&&this._initStateKey===n)return this._initPromise;if(this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch{}this._initStateKey=n,this._activeInitRequestId+=1;var r=this._activeInitRequestId;this._setStatus("loading");var o;try{o=this._buildEmbedInitUrl()}catch(a){return Promise.reject(a)}var s=this._buildInitPayload();this._state.tryonSessionId=s.tryonSessionId,this._abortController=typeof AbortController<"u"?new AbortController:null;var l=fetch(o,{method:"POST",headers:ve({merchantId:this._state.merchantId,widgetId:this._state.widgetId,tryonSessionId:s.tryonSessionId,contentType:j}),body:JSON.stringify(s.initRequestBody),signal:this._abortController?this._abortController.signal:void 0}).then(function(a){return a.ok?a.json():a.text().then(function(d){var c=D(d),f=ge(c,d);throw new Error(f)})}).then(function(a){return e._normalizeInitResponse(a,o,s.tryonSessionId)});return this._initPromise=Re(l,this._state.initTimeoutMs,oe,this._abortController).then(function(a){return r!==e._activeInitRequestId||(e._state.sessionToken=a.sessionToken,e._state.tryonSessionId=a.tryonSessionId,e._state.resolvedInitUrl=a.initUrl,e._state.resolvedIframeUrl=a.iframeUrl,e._state.iframeOrigin=a.iframeOrigin,e._setStatus("ready")),a}).catch(function(a){if(r!==e._activeInitRequestId)throw a;var d=H(a);throw e._state.sessionToken=null,e._state.resolvedInitUrl=null,e._state.resolvedIframeUrl=null,e._state.iframeOrigin=null,e._setStatus("error",{message:d}),new Error(d)}).finally(function(){r===e._activeInitRequestId&&(e._initPromise=null)}),this._initPromise}_sendConfigToIframe(){var e=this._getIframeElement();if(!(!e||!e.contentWindow)){var n=this._state.iframeOrigin;if(!n){this._log(le.CONFIG_SKIPPED_NO_IFRAME_ORIGIN);return}var r={merchantId:this._state.merchantId,widgetId:this._state.widgetId,sessionToken:this._state.sessionToken,tryonSessionId:this._state.tryonSessionId||v(this._getInstanceSessionKey()),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},embedParentOrigin:N()};this._state.isSimulationMode&&this._state.simulationInlineConfig&&typeof this._state.simulationInlineConfig=="object"&&(r.inlineVirtualTryonConfig=this._state.simulationInlineConfig),e.contentWindow.postMessage({type:F,payload:r},n)}}_renderLoading(){if(this.shadowRoot){var e=u(this,i.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var n=document.createElement("style");n.textContent=_e(e,P);var r=document.createElement("div");r.className=P,r.textContent=re,this.shadowRoot.appendChild(n),this.shadowRoot.appendChild(r)}}_renderError(e){if(this.shadowRoot){var n=u(this,i.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var r=document.createElement("style");r.textContent=he(n,L);var o=document.createElement("div");o.className=L,o.textContent=e||ie,this.shadowRoot.appendChild(r),this.shadowRoot.appendChild(o)}}_renderIframe(e,n){if(this.shadowRoot&&!(!e||typeof e!="string"||!e.trim())){var r=this,o=u(this,i.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="",this._consoleModalOpen=!1;var s=document.createElement("style"),l=S(o);this._state.console&&(l+=de()),s.textContent=l;var a=document.createElement("div");a.className="vitraun-host";var d=document.createElement("iframe");d.src=ye(e.trim(),this._state,this._getInstanceSessionKey()),d.title=ne,d.setAttribute("allow","camera"),d.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),d.onload=function(){n===r._renderVersion&&[0,50,150,400,1e3].forEach(function(c){setTimeout(function(){n===r._renderVersion&&r._sendConfigToIframe()},c)})},a.appendChild(d),this._state.console&&this._mountConsoleChrome(a),this.shadowRoot.appendChild(s),this.shadowRoot.appendChild(a)}}_render(){if(this.shadowRoot){this._renderVersion+=1;var e=this._renderVersion;if(!this._state.merchantId){this._setStatus("error",{message:_.MERCHANT_ID_REQUIRED}),this._renderError(_.MERCHANT_ID_REQUIRED);return}if(!this._state.widgetId){this._setStatus("error",{message:_.WIDGET_ID_REQUIRED}),this._renderError(_.WIDGET_ID_REQUIRED);return}this._renderLoading(),this._initializeSessionIfNeeded().then(function(n){e===this._renderVersion&&this._renderIframe(n.iframeUrl,e)}.bind(this)).catch(function(n){if(e===this._renderVersion){var r=H(n instanceof Error?n:new Error(String(n)));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(g)&&customElements.define(g,Ce)})();
|
|
4
|
+
`)}_refreshConsoleChrome(){if(!(!this.shadowRoot||!this._state.console)){var e=this.shadowRoot.querySelector(".vitraun-console-fab");if(e){var n=this._consoleLog?this._consoleLog.length:0;e.textContent=n>0?"Events ("+n+")":"Events"}var r=this.shadowRoot.querySelector(".vitraun-console-body");if(r&&this._consoleModalOpen){var o=this._formatConsoleLogText();o?(r.textContent=o,r.classList.remove("vitraun-console-empty")):(r.textContent="No events yet. Interact with the try-on to see activity.",r.classList.add("vitraun-console-empty")),r.scrollTop=r.scrollHeight}}}_setConsoleModalOpen(e){if(this._consoleModalOpen=e===!0,!!this.shadowRoot){var n=this.shadowRoot.querySelector(".vitraun-console-backdrop");n&&n.setAttribute("data-open",this._consoleModalOpen?"true":"false"),this._refreshConsoleChrome()}}_mountConsoleChrome(e){if(!(!e||!this._state.console)){var n=e.querySelector(".vitraun-console-fab");if(n){this._refreshConsoleChrome();return}var r=this,o=document.createElement("button");o.type="button",o.className="vitraun-console-fab",o.setAttribute("aria-label","Open Try-On events console"),o.textContent="Events",o.addEventListener("click",function(){r._setConsoleModalOpen(!0)});var s=document.createElement("div");s.className="vitraun-console-backdrop",s.setAttribute("data-open","false"),s.setAttribute("role","presentation"),s.addEventListener("click",function(C){C.target===s&&r._setConsoleModalOpen(!1)});var l=document.createElement("div");l.className="vitraun-console-modal",l.setAttribute("role","dialog"),l.setAttribute("aria-modal","true"),l.setAttribute("aria-label","Try-On events console"),l.addEventListener("click",function(C){C.stopPropagation()});var a=document.createElement("div");a.className="vitraun-console-header";var u=document.createElement("h2");u.className="vitraun-console-title",u.textContent="Try-On events";var _=document.createElement("div");_.className="vitraun-console-actions";var f=document.createElement("button");f.type="button",f.textContent="Clear",f.addEventListener("click",function(){r._consoleLog=[],r._refreshConsoleChrome()});var p=document.createElement("button");p.type="button",p.textContent="Close",p.addEventListener("click",function(){r._setConsoleModalOpen(!1)}),_.appendChild(f),_.appendChild(p),a.appendChild(u),a.appendChild(_);var O=document.createElement("pre");O.className="vitraun-console-body vitraun-console-empty",O.textContent="No events yet. Interact with the try-on to see activity.",l.appendChild(a),l.appendChild(O),s.appendChild(l),e.appendChild(o),e.appendChild(s),this._refreshConsoleChrome()}}_setStatus(e,n){this.setAttribute("data-status",e),this._emit("statusChange",{status:e,detail:n||null})}_getIframeElement(){return this.shadowRoot?this.shadowRoot.querySelector("iframe"):null}_getInstanceSessionKey(){return this.id==null?"":String(this.id).trim()}_handleMessage(e){var n=e.data;if(!(!n||typeof n!="object")){var r=this._getIframeElement();if(!(!r||!r.contentWindow)&&e.source===r.contentWindow&&!(!this._state.iframeOrigin||e.origin!==this._state.iframeOrigin)){var o=n.type,s=n.detail;if(o==="VTO_USAGE"){this._emit("vtoUsage",s);return}P.indexOf(o)!==-1&&this._emit(o,s)}}}_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,useQrCode:this._state.useQrCode})}_buildEmbedInitUrl(){return ve(this._state.env,this._state.apiPort)}_buildInitPayload(){var e=v(this._getInstanceSessionKey());return{tryonSessionId:e,initRequestBody:Ce(this._state,e)}}_normalizeInitResponse(e,n,r){if(!e||typeof e!="object")throw new Error(h.INIT_INVALID_RESPONSE);var o=typeof e.sessionToken=="string"&&e.sessionToken?e.sessionToken:null,s=typeof e.tryonSessionId=="string"&&e.tryonSessionId?e.tryonSessionId:r;if(!o)throw new Error(h.INIT_SESSION_TOKEN_MISSING);var l=typeof e.vtoUrl=="string"&&e.vtoUrl.trim()?e.vtoUrl.trim():null;if(!l&&typeof e.iframeUrl=="string"&&e.iframeUrl.trim()&&(l=e.iframeUrl.trim()),!l)throw new Error(h.INIT_VTO_URL_MISSING);var a=Ee(l);if(!a)throw new Error(h.INIT_VTO_URL_INVALID);var u=typeof e.handoffToken=="string"&&e.handoffToken.trim()?e.handoffToken.trim():null,_=typeof e.embedParentOrigin=="string"&&e.embedParentOrigin.trim()?e.embedParentOrigin.trim():null;return{sessionToken:o,handoffToken:u,embedParentOrigin:_,tryonSessionId:s,initUrl:n,iframeUrl:l,iframeOrigin:a}}_initializeSessionIfNeeded(){var e=this;if(!this._state.merchantId)return Promise.reject(new Error(h.MERCHANT_ID_REQUIRED));if(!this._state.widgetId)return Promise.reject(new Error(h.WIDGET_ID_REQUIRED));var n=this._getInitStateKey();if(this._initPromise&&this._initStateKey===n)return this._initPromise;if(this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch{}this._initStateKey=n,this._activeInitRequestId+=1;var r=this._activeInitRequestId;this._setStatus("loading");var o;try{o=this._buildEmbedInitUrl()}catch(a){return Promise.reject(a)}var s=this._buildInitPayload();this._state.tryonSessionId=s.tryonSessionId,this._abortController=typeof AbortController<"u"?new AbortController:null;var l=fetch(o,{method:"POST",headers:Oe({merchantId:this._state.merchantId,widgetId:this._state.widgetId,tryonSessionId:s.tryonSessionId,contentType:Z}),body:JSON.stringify(s.initRequestBody),signal:this._abortController?this._abortController.signal:void 0}).then(function(a){return a.ok?a.json():a.text().then(function(u){var _=D(u),f=Se(_,u);throw new Error(f)})}).then(function(a){return e._normalizeInitResponse(a,o,s.tryonSessionId)});return this._initPromise=Re(l,this._state.initTimeoutMs,oe,this._abortController).then(function(a){return r!==e._activeInitRequestId||(e._state.sessionToken=a.sessionToken,e._state.handoffToken=a.handoffToken,e._state.embedParentOrigin=a.embedParentOrigin,e._state.tryonSessionId=a.tryonSessionId,e._state.resolvedInitUrl=a.initUrl,e._state.resolvedIframeUrl=a.iframeUrl,e._state.iframeOrigin=a.iframeOrigin,e._setStatus("ready")),a}).catch(function(a){if(r!==e._activeInitRequestId)throw a;var u=H(a);throw e._state.sessionToken=null,e._state.handoffToken=null,e._state.embedParentOrigin=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 n=this._state.iframeOrigin;if(!n){this._log(le.CONFIG_SKIPPED_NO_IFRAME_ORIGIN);return}var r={merchantId:this._state.merchantId,widgetId:this._state.widgetId,sessionToken:this._state.sessionToken,handoffToken:this._state.handoffToken,tryonSessionId:this._state.tryonSessionId||v(this._getInstanceSessionKey()),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},embedParentOrigin:N()};this._state.useQrCode!==void 0&&(r.useQrCode=this._state.useQrCode),this._state.isSimulationMode&&this._state.simulationInlineConfig&&typeof this._state.simulationInlineConfig=="object"&&(r.inlineVirtualTryonConfig=this._state.simulationInlineConfig),e.contentWindow.postMessage({type:F,payload:r},n)}}_renderLoading(){if(this.shadowRoot){var e=d(this,i.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var n=document.createElement("style");n.textContent=_e(e,w);var r=document.createElement("div");r.className=w,r.textContent=re,this.shadowRoot.appendChild(n),this.shadowRoot.appendChild(r)}}_renderError(e){if(this.shadowRoot){var n=d(this,i.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var r=document.createElement("style");r.textContent=he(n,L);var o=document.createElement("div");o.className=L,o.textContent=e||ie,this.shadowRoot.appendChild(r),this.shadowRoot.appendChild(o)}}_renderIframe(e,n){if(this.shadowRoot&&!(!e||typeof e!="string"||!e.trim())){var r=this,o=d(this,i.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="",this._consoleModalOpen=!1;var s=document.createElement("style"),l=S(o);this._state.console&&(l+=ue()),s.textContent=l;var a=document.createElement("div");a.className="vitraun-host";var u=document.createElement("iframe");u.src=ye(e.trim(),this._state,this._getInstanceSessionKey()),u.title=ne,u.setAttribute("allow","camera"),u.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),u.onload=function(){n===r._renderVersion&&[0,50,150,400,1e3].forEach(function(_){setTimeout(function(){n===r._renderVersion&&r._sendConfigToIframe()},_)})},a.appendChild(u),this._state.console&&this._mountConsoleChrome(a),this.shadowRoot.appendChild(s),this.shadowRoot.appendChild(a)}}_render(){if(this.shadowRoot){this._renderVersion+=1;var e=this._renderVersion;if(!this._state.merchantId){this._setStatus("error",{message:h.MERCHANT_ID_REQUIRED}),this._renderError(h.MERCHANT_ID_REQUIRED);return}if(!this._state.widgetId){this._setStatus("error",{message:h.WIDGET_ID_REQUIRED}),this._renderError(h.WIDGET_ID_REQUIRED);return}this._renderLoading(),this._initializeSessionIfNeeded().then(function(n){e===this._renderVersion&&this._renderIframe(n.iframeUrl,e)}.bind(this)).catch(function(n){if(e===this._renderVersion){var r=H(n instanceof Error?n:new Error(String(n)));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(g)&&customElements.define(g,be)})();
|
package/dist/widget.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var VitraunWebAR=(()=>{(function(){"use strict";var F="VITRAUN_CONFIG",A="vtrn-vto-session",K=18e5,m=1e4,y="en-US",p="Vitraun",T="vitraun",C="https://",B="app.",W="app",b="."+T+".com",Y="/v1/public/virtual-tryon-embed-init",q="Content-Type",z="X-Origin",X="X-Tryon-Session-Id",Q="X-Merchant-Id",J="X-Widget-Id",j="application/json",Z="00000000-0000-0000-0000-000000000000",w=["addToCart","removeFromCart","redirectToCart","analysisFinished"],$=w.concat(["statusChange","vtoUsage"]),ee=150,g="vitraun-vto",te="["+g+"]",P=T+"-loading",L=T+"-error",ne=p+" VTO",re="Loading "+p+"...",ie="Failed to load "+p+".",oe="Timed out while initializing the "+p+" session.",i={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",CONSOLE:"console",INIT_TIMEOUT_MS:"init-timeout-ms"},se=[i.MERCHANT_ID,i.WIDGET_ID,i.ENV,i.API_PORT,i.APP_PORT,i.LANG,i.ISOLATED_SKU,i.APPLY_SKUS,i.FLOW,i.BASKET_OPENS_IN,i.CHECKOUT_OPENS_IN,i.USE_SIMPLE_PAGE,i.SHOW_DETAILS,i.SHOW_PRODUCT_PRICE,i.PRICE_FROM,i.PRICE_TO,i.CURRENCY_SYMBOL,i.IS_SIMULATION_MODE,i.SIMULATION_INLINE_CONFIG,i.CONTAINER_MIN_HEIGHT,i.APP_ID,i.PLATFORM,i.BUNDLE_ID,i.PACKAGE_NAME,i.APP_VERSION,i.ATTESTATION_TOKEN,i.DEBUG,i.CONSOLE,i.INIT_TIMEOUT_MS],_={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.",INIT_VTO_URL_MISSING:"The server did not return a virtual try-on URL (vtoUrl). Please contact the store.",INIT_VTO_URL_INVALID:"The virtual try-on URL returned by the server is invalid. Please contact the store."},ae="The operation timed out.",le={CONFIG_SKIPPED_NO_IFRAME_ORIGIN:"Config not sent: Origin is missing."},h={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.",GENERIC_SERVER_OR_CLIENT_MISMATCH:"Could not start the virtual try-on. Please refresh the page or contact the store."},ue="We couldn't connect to the virtual try-on service. Please try again or contact the store.",M={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_TOKEN_EXPIRED:"This embed session has expired. 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 S(t){return":host { display:block; width:100%; min-height:"+t+"; box-sizing:border-box; }.vitraun-host { position:relative; width:100%; min-height:"+t+"; box-sizing:border-box; }.vitraun-host > iframe { display:block; width:100%; border:0; min-height:"+t+"; }"}function de(){return'.vitraun-console-fab {position:absolute; bottom:12px; right:12px; z-index:5;padding:8px 12px; border:0; border-radius:8px;background:#0f172a; color:#f8fafc; font:600 12px/1.2 system-ui, sans-serif;cursor:pointer; box-shadow:0 4px 12px rgba(15,23,42,0.35);}.vitraun-console-fab:hover { background:#1e293b; }.vitraun-console-backdrop {position:absolute; inset:0; z-index:6; background:rgba(15,23,42,0.45);display:none; align-items:center; justify-content:center; padding:16px; box-sizing:border-box;}.vitraun-console-backdrop[data-open="true"] { display:flex; }.vitraun-console-modal {width:min(100%, 520px); max-height:min(70vh, 420px); display:flex; flex-direction:column;background:#fff; border-radius:12px; box-shadow:0 16px 40px rgba(15,23,42,0.25); overflow:hidden;}.vitraun-console-header {display:flex; align-items:center; justify-content:space-between; gap:8px;padding:12px 14px; border-bottom:1px solid #e2e8f0; background:#f8fafc;}.vitraun-console-title { font:600 14px/1.2 system-ui, sans-serif; color:#0f172a; margin:0; }.vitraun-console-actions { display:flex; gap:8px; }.vitraun-console-actions button {padding:6px 10px; border:1px solid #cbd5e1; border-radius:6px; background:#fff;font:500 12px/1 system-ui, sans-serif; color:#334155; cursor:pointer;}.vitraun-console-body {margin:0; padding:12px 14px; overflow:auto; flex:1; min-height:120px;font:12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color:#0f172a;white-space:pre-wrap; word-break:break-word; background:#fff;}.vitraun-console-empty { color:#64748b; font-style:italic; }'}function _e(t,e){return S(t)+"."+e+" {min-height:"+t+";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 he(t,e){return S(t)+"."+e+" {min-height:"+t+";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 u(t,e,n){var r=t.getAttribute(e);return r!=null&&r!==""?r:n}function I(t,e){if(t==null||t==="")return e;var n=String(t).toLowerCase();return n==="true"||n==="1"||n==="yes"}function U(t){if(t==null||t==="")return null;var e=parseFloat(String(t));return Number.isFinite(e)?e:null}function ce(t){return!t||typeof t!="string"?[]:t.split(",").map(function(e){return e.trim()}).filter(Boolean)}function Ie(t,e){var n=u(t,e,"");if(!n||typeof n!="string")return null;try{return JSON.parse(n)}catch(r){return null}}function D(t){try{return JSON.parse(t)}catch(e){return null}}function N(){return typeof window=="undefined"||!window.location||!window.location.origin?null:window.location.origin}function fe(){return typeof window=="undefined"||!window.location||!window.location.href?null:window.location.href}function pe(t){if(!t||typeof t!="string")return null;try{return new URL(t).origin}catch(e){return null}}function Ee(t){var e=String(t||"").trim().toLowerCase();if(!e)return"";if(!/^[a-z0-9-]+$/.test(e))throw new Error(_.ENV_INVALID);return e}function me(t){return t?String(t).trim().toLowerCase():"web"}function k(t){if(t==null||t==="")return null;var e=parseInt(String(t),10);return!Number.isInteger(e)||e<=0||e>65535?null:e}function Te(t,e){if(t==null||t==="")return"";var n=parseInt(String(t),10);return!Number.isInteger(n)||n<=0||n>65535||e==="https://"&&n===443||e==="http://"&&n===80?"":":"+n}function x(t){return!t||typeof t!="object"?!1:!!Array.isArray(t.message)}function G(t){if(!t||typeof t!="string")return!1;var e=t.toLowerCase();return e.indexOf("should not exist")!==-1||e.indexOf("should not be empty")!==-1||e.indexOf("forbidnonwhitelisted")!==-1||e.indexOf("whitelist")!==-1&&e.indexOf("property")!==-1||e.indexOf("property")!==-1&&e.indexOf("should not")!==-1}function V(t){if(!t||typeof t!="string")return!1;var e=t.trim();if(e.charAt(0)!=="{"||e.indexOf('"message"')===-1||e.indexOf('"statusCode"')===-1)return!1;var n=D(e);return x(n)}function ge(t,e){if(x(t))return h.GENERIC_SERVER_OR_CLIENT_MISMATCH;var n=t&&typeof t.errorCode=="string"?t.errorCode:null;if(n&&Object.prototype.hasOwnProperty.call(M,n))return M[n];var r=t&&typeof t.message=="string"?t.message.trim():"";if(r)return G(r)?h.GENERIC_SERVER_OR_CLIENT_MISMATCH:r;if(n)return h.GENERIC_TRY_AGAIN_OR_STORE;if(e&&String(e).length>0&&String(e).length<600){var o=String(e).trim();return V(o)?h.GENERIC_SERVER_OR_CLIENT_MISMATCH:o.charAt(0)==="{"&&o.indexOf("errorCode")!==-1?h.GENERIC_TRY_AGAIN:o.charAt(0)==="{"?h.GENERIC_SERVER_OR_CLIENT_MISMATCH:o}return h.GENERIC_TRY_AGAIN}function Se(t){if(!t||typeof t.message!="string")return!1;var e=t.name,n=t.message.toLowerCase();return e==="TypeError"&&(n.indexOf("failed to fetch")!==-1||n.indexOf("load failed")!==-1)||n.indexOf("networkerror when attempting to fetch")!==-1||e==="NetworkError"||n.indexOf("network request failed")!==-1}function H(t){if(Se(t))return ue;if(t&&typeof t.message=="string"&&t.message.trim()){var e=t.message.trim();return G(e)||V(e)||e.charAt(0)==="{"&&e.indexOf('"message"')!==-1&&e.indexOf('"statusCode"')!==-1?h.GENERIC_SERVER_OR_CLIENT_MISMATCH:e}return h.GENERIC_TRY_AGAIN}function Ne(t,e){var n=t&&String(t).trim()?B+String(t).trim().toLowerCase()+b:W+b;return C+n+Te(e,C)+Y}function ve(t){var e=t.merchantId!=null?String(t.merchantId):"",n=t.widgetId!=null?String(t.widgetId):"",r=t.tryonSessionId!=null?String(t.tryonSessionId):"",o=t.origin!==void 0&&t.origin!==null&&t.origin!==""?String(t.origin):N()||"",s={};return s[z]=o,s[X]=r,s[Q]=e,s[J]=n,t.contentType&&(s[q]=t.contentType),s}function Oe(t,e){return{merchantId:t.merchantId,widgetId:t.widgetId,tryonSessionId:e,env:t.env,lang:t.lang,isSimulationMode:t.isSimulationMode===!0,appPort:t.appPort,app:{appId:t.appId,platform:t.platform,bundleId:t.bundleId,packageName:t.packageName,appVersion:t.appVersion,attestationToken:t.attestationToken},context:{origin:N(),pageUrl:fe(),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 Re(t,e,n,r){return!e||e<=0?t:new Promise(function(o,s){var l=!1,a=setTimeout(function(){if(!l){l=!0;try{r&&typeof r.abort=="function"&&r.abort()}catch(d){}s(new Error(n||ae))}},e);t.then(function(d){l||(l=!0,clearTimeout(a),o(d))}).catch(function(d){l||(l=!0,clearTimeout(a),s(d))})})}function Ae(t){var e=t!=null?String(t).trim():"";return e?A+":"+e:A}function v(t){if(typeof window=="undefined"||!window.crypto||!window.crypto.randomUUID)return Z;var e=Ae(t);try{var n=sessionStorage.getItem(e);if(n){var r=JSON.parse(n);if(r&&typeof r.id=="string"&&typeof r.exp=="number"&&Date.now()<r.exp)return r.id}}catch(l){}var o=window.crypto.randomUUID(),s=Date.now()+K;try{sessionStorage.setItem(e,JSON.stringify({id:o,exp:s}))}catch(l){}return o}function ye(t,e,n){var r=e.merchantId!=null?String(e.merchantId).trim():"",o=e.widgetId!=null?String(e.widgetId).trim():"";if(!r||!o)return t;var s;try{s=new URL(t)}catch(d){return t}s.searchParams.set("merchantId",r),s.searchParams.set("widgetId",o),s.searchParams.set("embed","1");var l=e.tryonSessionId!=null?String(e.tryonSessionId).trim():"";l||(l=v(n)),l&&s.searchParams.set("tryonSessionId",l);var a=e.sessionToken!=null?String(e.sessionToken).trim():"";return a&&s.searchParams.set("embedSessionToken",a),s.toString()}class Ce extends HTMLElement{static get observedAttributes(){return se.slice()}constructor(){super(),this.attachShadow({mode:"open"}),this._state={merchantId:"",widgetId:"",env:"",apiPort:null,appPort:null,lang:y,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,console:!1,sessionToken:null,tryonSessionId:null,resolvedInitUrl:null,resolvedIframeUrl:null,initTimeoutMs:m},this._consoleLog=[],this._consoleModalOpen=!1,this._consoleCaptureTeardown=null,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._setupConsoleCapture(),this._render(),typeof window!="undefined"&&window.addEventListener("message",this._boundHandleMessage)}disconnectedCallback(){if(typeof window!="undefined"&&window.removeEventListener("message",this._boundHandleMessage),this._teardownConsoleCapture(),this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch(e){}}attributeChangedCallback(e,n,r){n!==r&&(this._readAttributes(),this._setupConsoleCapture(),this._render())}_log(){if(!(!this._state.debug||typeof console=="undefined"||!console.log)){var e=Array.prototype.slice.call(arguments);e.unshift(te),console.log.apply(console,e)}}_readAttributes(){var e=Ie(this,i.SIMULATION_INLINE_CONFIG),n=!1;e&&e.features&&typeof e.features.showProductPrice=="boolean"&&(n=e.features.showProductPrice);var r=!0;e&&e.features&&typeof e.features.useSimplePage=="boolean"&&(r=e.features.useSimplePage);var o="checkout";e&&e.features&&(e.features.flow==="catalog"||e.features.flow==="checkout")&&(o=e.features.flow);var s=!0;e&&e.features&&typeof e.features.showDetails=="boolean"&&(s=e.features.showDetails);var l="";try{l=Ee(u(this,i.ENV,""))}catch(d){l=""}var a=parseInt(u(this,i.INIT_TIMEOUT_MS,String(m)),10);(!Number.isFinite(a)||a<0)&&(a=m),this._state={merchantId:u(this,i.MERCHANT_ID,""),widgetId:u(this,i.WIDGET_ID,""),env:l,apiPort:k(u(this,i.API_PORT,null)),appPort:k(u(this,i.APP_PORT,null)),lang:u(this,i.LANG,y),isolatedSku:u(this,i.ISOLATED_SKU,null)||null,applySkus:ce(u(this,i.APPLY_SKUS,"")),iframeOrigin:this._state&&this._state.iframeOrigin?this._state.iframeOrigin:null,flow:u(this,i.FLOW,o),basketOpensIn:u(this,i.BASKET_OPENS_IN,"event"),checkoutOpensIn:u(this,i.CHECKOUT_OPENS_IN,"event"),useSimplePage:I(u(this,i.USE_SIMPLE_PAGE,""),r),showDetails:I(u(this,i.SHOW_DETAILS,""),s),showProductPrice:I(u(this,i.SHOW_PRODUCT_PRICE,""),n),priceFrom:U(u(this,i.PRICE_FROM,null)),priceTo:U(u(this,i.PRICE_TO,null)),currencySymbol:u(this,i.CURRENCY_SYMBOL,null)||null,isSimulationMode:I(u(this,i.IS_SIMULATION_MODE,"false"),!1),simulationInlineConfig:e,appId:u(this,i.APP_ID,null)||null,platform:me(u(this,i.PLATFORM,null)),bundleId:u(this,i.BUNDLE_ID,null)||null,packageName:u(this,i.PACKAGE_NAME,null)||null,appVersion:u(this,i.APP_VERSION,null)||null,attestationToken:u(this,i.ATTESTATION_TOKEN,null)||null,debug:I(u(this,i.DEBUG,"false"),!1),console:I(u(this,i.CONSOLE,"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(e,n){this.dispatchEvent(new CustomEvent(e,{detail:n!=null?n:null,bubbles:!0,composed:!0}))}_teardownConsoleCapture(){typeof this._consoleCaptureTeardown=="function"&&(this._consoleCaptureTeardown(),this._consoleCaptureTeardown=null)}_setupConsoleCapture(){if(this._teardownConsoleCapture(),!!this._state.console){var e=this,n=[];$.forEach(function(r){var o=function(s){e._appendConsoleLog(r,s.detail)};e.addEventListener(r,o),n.push({eventType:r,handler:o})}),this._consoleCaptureTeardown=function(){n.forEach(function(r){e.removeEventListener(r.eventType,r.handler)})}}}_appendConsoleLog(e,n){this._state.console&&(Array.isArray(this._consoleLog)||(this._consoleLog=[]),this._consoleLog.push({type:e,timestamp:new Date().toISOString(),detail:n!=null?n:null}),this._consoleLog.length>ee&&this._consoleLog.shift(),this._refreshConsoleChrome())}_formatConsoleLogText(){return!this._consoleLog||this._consoleLog.length===0?"":this._consoleLog.map(function(e){var n="";try{n=JSON.stringify(e.detail,null,2)}catch(r){n=String(e.detail)}return"["+e.timestamp+"] "+e.type+`
|
|
1
|
+
"use strict";var VitraunWebAR=(()=>{(function(){"use strict";var F="VITRAUN_CONFIG",R="vtrn-vto-session",K=18e5,m=1e4,A="en-US",E="Vitraun",T="vitraun",y="https://",B="app.",W="app",b="."+T+".com",Y="/v1/public/virtual-tryon-embed-init",Q="Content-Type",q="X-Origin",z="X-Tryon-Session-Id",X="X-Merchant-Id",J="X-Widget-Id",Z="application/json",$="00000000-0000-0000-0000-000000000000",P=["addToCart","removeFromCart","redirectToCart","analysisFinished"],j=P.concat(["statusChange","vtoUsage"]),ee=150,g="vitraun-vto",te="["+g+"]",w=T+"-loading",L=T+"-error",ne=E+" VTO",re="Loading "+E+"...",ie="Failed to load "+E+".",oe="Timed out while initializing the "+E+" session.",i={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",USE_QR_CODE:"use-qr-code",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",CONSOLE:"console",INIT_TIMEOUT_MS:"init-timeout-ms"},se=[i.MERCHANT_ID,i.WIDGET_ID,i.ENV,i.API_PORT,i.APP_PORT,i.LANG,i.ISOLATED_SKU,i.APPLY_SKUS,i.FLOW,i.BASKET_OPENS_IN,i.CHECKOUT_OPENS_IN,i.USE_SIMPLE_PAGE,i.USE_QR_CODE,i.SHOW_DETAILS,i.SHOW_PRODUCT_PRICE,i.PRICE_FROM,i.PRICE_TO,i.CURRENCY_SYMBOL,i.IS_SIMULATION_MODE,i.SIMULATION_INLINE_CONFIG,i.CONTAINER_MIN_HEIGHT,i.APP_ID,i.PLATFORM,i.BUNDLE_ID,i.PACKAGE_NAME,i.APP_VERSION,i.ATTESTATION_TOKEN,i.DEBUG,i.CONSOLE,i.INIT_TIMEOUT_MS],h={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.",INIT_VTO_URL_MISSING:"The server did not return a virtual try-on URL (vtoUrl). Please contact the store.",INIT_VTO_URL_INVALID:"The virtual try-on URL returned by the server is invalid. Please contact the store."},ae="The operation timed out.",le={CONFIG_SKIPPED_NO_IFRAME_ORIGIN:"Config not sent: Origin 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.",GENERIC_SERVER_OR_CLIENT_MISMATCH:"Could not start the virtual try-on. Please refresh the page or contact the store."},de="We couldn't connect to the virtual try-on service. Please try again or contact the store.",U={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_TOKEN_EXPIRED:"This embed session has expired. 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 S(t){return":host { display:block; width:100%; min-height:"+t+"; box-sizing:border-box; }.vitraun-host { position:relative; width:100%; min-height:"+t+"; box-sizing:border-box; }.vitraun-host > iframe { display:block; width:100%; border:0; min-height:"+t+"; }"}function ue(){return'.vitraun-console-fab {position:absolute; bottom:12px; right:12px; z-index:5;padding:8px 12px; border:0; border-radius:8px;background:#0f172a; color:#f8fafc; font:600 12px/1.2 system-ui, sans-serif;cursor:pointer; box-shadow:0 4px 12px rgba(15,23,42,0.35);}.vitraun-console-fab:hover { background:#1e293b; }.vitraun-console-backdrop {position:absolute; inset:0; z-index:6; background:rgba(15,23,42,0.45);display:none; align-items:center; justify-content:center; padding:16px; box-sizing:border-box;}.vitraun-console-backdrop[data-open="true"] { display:flex; }.vitraun-console-modal {width:min(100%, 520px); max-height:min(70vh, 420px); display:flex; flex-direction:column;background:#fff; border-radius:12px; box-shadow:0 16px 40px rgba(15,23,42,0.25); overflow:hidden;}.vitraun-console-header {display:flex; align-items:center; justify-content:space-between; gap:8px;padding:12px 14px; border-bottom:1px solid #e2e8f0; background:#f8fafc;}.vitraun-console-title { font:600 14px/1.2 system-ui, sans-serif; color:#0f172a; margin:0; }.vitraun-console-actions { display:flex; gap:8px; }.vitraun-console-actions button {padding:6px 10px; border:1px solid #cbd5e1; border-radius:6px; background:#fff;font:500 12px/1 system-ui, sans-serif; color:#334155; cursor:pointer;}.vitraun-console-body {margin:0; padding:12px 14px; overflow:auto; flex:1; min-height:120px;font:12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color:#0f172a;white-space:pre-wrap; word-break:break-word; background:#fff;}.vitraun-console-empty { color:#64748b; font-style:italic; }'}function _e(t,e){return S(t)+"."+e+" {min-height:"+t+";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 he(t,e){return S(t)+"."+e+" {min-height:"+t+";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 d(t,e,n){var r=t.getAttribute(e);return r!=null&&r!==""?r:n}function I(t,e){if(t==null||t==="")return e;var n=String(t).toLowerCase();return n==="true"||n==="1"||n==="yes"}function ce(t,e){var n=t.getAttribute(e);if(!(n==null||n===""))return I(n,!1)}function M(t){if(t==null||t==="")return null;var e=parseFloat(String(t));return Number.isFinite(e)?e:null}function fe(t){return!t||typeof t!="string"?[]:t.split(",").map(function(e){return e.trim()}).filter(Boolean)}function Ie(t,e){var n=d(t,e,"");if(!n||typeof n!="string")return null;try{return JSON.parse(n)}catch(r){return null}}function D(t){try{return JSON.parse(t)}catch(e){return null}}function N(){return typeof window=="undefined"||!window.location||!window.location.origin?null:window.location.origin}function pe(){return typeof window=="undefined"||!window.location||!window.location.href?null:window.location.href}function Ee(t){if(!t||typeof t!="string")return null;try{return new URL(t).origin}catch(e){return null}}function me(t){var e=String(t||"").trim().toLowerCase();if(!e)return"";if(!/^[a-z0-9-]+$/.test(e))throw new Error(h.ENV_INVALID);return e}function Te(t){return t?String(t).trim().toLowerCase():"web"}function k(t){if(t==null||t==="")return null;var e=parseInt(String(t),10);return!Number.isInteger(e)||e<=0||e>65535?null:e}function ge(t,e){if(t==null||t==="")return"";var n=parseInt(String(t),10);return!Number.isInteger(n)||n<=0||n>65535||e==="https://"&&n===443||e==="http://"&&n===80?"":":"+n}function x(t){return!t||typeof t!="object"?!1:!!Array.isArray(t.message)}function G(t){if(!t||typeof t!="string")return!1;var e=t.toLowerCase();return e.indexOf("should not exist")!==-1||e.indexOf("should not be empty")!==-1||e.indexOf("forbidnonwhitelisted")!==-1||e.indexOf("whitelist")!==-1&&e.indexOf("property")!==-1||e.indexOf("property")!==-1&&e.indexOf("should not")!==-1}function V(t){if(!t||typeof t!="string")return!1;var e=t.trim();if(e.charAt(0)!=="{"||e.indexOf('"message"')===-1||e.indexOf('"statusCode"')===-1)return!1;var n=D(e);return x(n)}function Se(t,e){if(x(t))return c.GENERIC_SERVER_OR_CLIENT_MISMATCH;var n=t&&typeof t.errorCode=="string"?t.errorCode:null;if(n&&Object.prototype.hasOwnProperty.call(U,n))return U[n];var r=t&&typeof t.message=="string"?t.message.trim():"";if(r)return G(r)?c.GENERIC_SERVER_OR_CLIENT_MISMATCH:r;if(n)return c.GENERIC_TRY_AGAIN_OR_STORE;if(e&&String(e).length>0&&String(e).length<600){var o=String(e).trim();return V(o)?c.GENERIC_SERVER_OR_CLIENT_MISMATCH:o.charAt(0)==="{"&&o.indexOf("errorCode")!==-1?c.GENERIC_TRY_AGAIN:o.charAt(0)==="{"?c.GENERIC_SERVER_OR_CLIENT_MISMATCH:o}return c.GENERIC_TRY_AGAIN}function Ne(t){if(!t||typeof t.message!="string")return!1;var e=t.name,n=t.message.toLowerCase();return e==="TypeError"&&(n.indexOf("failed to fetch")!==-1||n.indexOf("load failed")!==-1)||n.indexOf("networkerror when attempting to fetch")!==-1||e==="NetworkError"||n.indexOf("network request failed")!==-1}function H(t){if(Ne(t))return de;if(t&&typeof t.message=="string"&&t.message.trim()){var e=t.message.trim();return G(e)||V(e)||e.charAt(0)==="{"&&e.indexOf('"message"')!==-1&&e.indexOf('"statusCode"')!==-1?c.GENERIC_SERVER_OR_CLIENT_MISMATCH:e}return c.GENERIC_TRY_AGAIN}function ve(t,e){var n=t&&String(t).trim()?B+String(t).trim().toLowerCase()+b:W+b;return y+n+ge(e,y)+Y}function Oe(t){var e=t.merchantId!=null?String(t.merchantId):"",n=t.widgetId!=null?String(t.widgetId):"",r=t.tryonSessionId!=null?String(t.tryonSessionId):"",o=t.origin!==void 0&&t.origin!==null&&t.origin!==""?String(t.origin):N()||"",s={};return s[q]=o,s[z]=r,s[X]=e,s[J]=n,t.contentType&&(s[Q]=t.contentType),s}function Ce(t,e){return{merchantId:t.merchantId,widgetId:t.widgetId,tryonSessionId:e,env:t.env,lang:t.lang,isSimulationMode:t.isSimulationMode===!0,appPort:t.appPort,app:{appId:t.appId,platform:t.platform,bundleId:t.bundleId,packageName:t.packageName,appVersion:t.appVersion,attestationToken:t.attestationToken},context:{origin:N(),pageUrl:pe(),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 Re(t,e,n,r){return!e||e<=0?t:new Promise(function(o,s){var l=!1,a=setTimeout(function(){if(!l){l=!0;try{r&&typeof r.abort=="function"&&r.abort()}catch(u){}s(new Error(n||ae))}},e);t.then(function(u){l||(l=!0,clearTimeout(a),o(u))}).catch(function(u){l||(l=!0,clearTimeout(a),s(u))})})}function Ae(t){var e=t!=null?String(t).trim():"";return e?R+":"+e:R}function v(t){if(typeof window=="undefined"||!window.crypto||!window.crypto.randomUUID)return $;var e=Ae(t);try{var n=sessionStorage.getItem(e);if(n){var r=JSON.parse(n);if(r&&typeof r.id=="string"&&typeof r.exp=="number"&&Date.now()<r.exp)return r.id}}catch(l){}var o=window.crypto.randomUUID(),s=Date.now()+K;try{sessionStorage.setItem(e,JSON.stringify({id:o,exp:s}))}catch(l){}return o}function ye(t,e,n){var r=e.merchantId!=null?String(e.merchantId).trim():"",o=e.widgetId!=null?String(e.widgetId).trim():"";if(!r||!o)return t;var s;try{s=new URL(t)}catch(u){return t}s.searchParams.set("merchantId",r),s.searchParams.set("widgetId",o),s.searchParams.set("embed","1");var l=e.tryonSessionId!=null?String(e.tryonSessionId).trim():"";l||(l=v(n)),l&&s.searchParams.set("tryonSessionId",l);var a=e.sessionToken!=null?String(e.sessionToken).trim():"";return a&&s.searchParams.set("embedSessionToken",a),s.toString()}class be extends HTMLElement{static get observedAttributes(){return se.slice()}constructor(){super(),this.attachShadow({mode:"open"}),this._state={merchantId:"",widgetId:"",env:"",apiPort:null,appPort:null,lang:A,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,console:!1,sessionToken:null,handoffToken:null,embedParentOrigin:null,tryonSessionId:null,resolvedInitUrl:null,resolvedIframeUrl:null,initTimeoutMs:m},this._consoleLog=[],this._consoleModalOpen=!1,this._consoleCaptureTeardown=null,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._setupConsoleCapture(),this._render(),typeof window!="undefined"&&window.addEventListener("message",this._boundHandleMessage)}disconnectedCallback(){if(typeof window!="undefined"&&window.removeEventListener("message",this._boundHandleMessage),this._teardownConsoleCapture(),this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch(e){}}attributeChangedCallback(e,n,r){n!==r&&(this._readAttributes(),this._setupConsoleCapture(),this._render())}_log(){if(!(!this._state.debug||typeof console=="undefined"||!console.log)){var e=Array.prototype.slice.call(arguments);e.unshift(te),console.log.apply(console,e)}}_readAttributes(){var e=Ie(this,i.SIMULATION_INLINE_CONFIG),n=!1;e&&e.features&&typeof e.features.showProductPrice=="boolean"&&(n=e.features.showProductPrice);var r=!0;e&&e.features&&typeof e.features.useSimplePage=="boolean"&&(r=e.features.useSimplePage);var o="checkout";e&&e.features&&(e.features.flow==="catalog"||e.features.flow==="checkout")&&(o=e.features.flow);var s=!0;e&&e.features&&typeof e.features.showDetails=="boolean"&&(s=e.features.showDetails);var l=e&&e.features&&typeof e.features.useQrCode=="boolean"?e.features.useQrCode:void 0,a=ce(this,i.USE_QR_CODE),u=a!==void 0?a:l,_="";try{_=me(d(this,i.ENV,""))}catch(p){_=""}var f=parseInt(d(this,i.INIT_TIMEOUT_MS,String(m)),10);(!Number.isFinite(f)||f<0)&&(f=m),this._state={merchantId:d(this,i.MERCHANT_ID,""),widgetId:d(this,i.WIDGET_ID,""),env:_,apiPort:k(d(this,i.API_PORT,null)),appPort:k(d(this,i.APP_PORT,null)),lang:d(this,i.LANG,A),isolatedSku:d(this,i.ISOLATED_SKU,null)||null,applySkus:fe(d(this,i.APPLY_SKUS,"")),iframeOrigin:this._state&&this._state.iframeOrigin?this._state.iframeOrigin:null,flow:d(this,i.FLOW,o),basketOpensIn:d(this,i.BASKET_OPENS_IN,"event"),checkoutOpensIn:d(this,i.CHECKOUT_OPENS_IN,"event"),useSimplePage:I(d(this,i.USE_SIMPLE_PAGE,""),r),useQrCode:u,showDetails:I(d(this,i.SHOW_DETAILS,""),s),showProductPrice:I(d(this,i.SHOW_PRODUCT_PRICE,""),n),priceFrom:M(d(this,i.PRICE_FROM,null)),priceTo:M(d(this,i.PRICE_TO,null)),currencySymbol:d(this,i.CURRENCY_SYMBOL,null)||null,isSimulationMode:I(d(this,i.IS_SIMULATION_MODE,"false"),!1),simulationInlineConfig:e,appId:d(this,i.APP_ID,null)||null,platform:Te(d(this,i.PLATFORM,null)),bundleId:d(this,i.BUNDLE_ID,null)||null,packageName:d(this,i.PACKAGE_NAME,null)||null,appVersion:d(this,i.APP_VERSION,null)||null,attestationToken:d(this,i.ATTESTATION_TOKEN,null)||null,debug:I(d(this,i.DEBUG,"false"),!1),console:I(d(this,i.CONSOLE,"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:f}}_emit(e,n){this.dispatchEvent(new CustomEvent(e,{detail:n!=null?n:null,bubbles:!0,composed:!0}))}_teardownConsoleCapture(){typeof this._consoleCaptureTeardown=="function"&&(this._consoleCaptureTeardown(),this._consoleCaptureTeardown=null)}_setupConsoleCapture(){if(this._teardownConsoleCapture(),!!this._state.console){var e=this,n=[];j.forEach(function(r){var o=function(s){e._appendConsoleLog(r,s.detail)};e.addEventListener(r,o),n.push({eventType:r,handler:o})}),this._consoleCaptureTeardown=function(){n.forEach(function(r){e.removeEventListener(r.eventType,r.handler)})}}}_appendConsoleLog(e,n){this._state.console&&(Array.isArray(this._consoleLog)||(this._consoleLog=[]),this._consoleLog.push({type:e,timestamp:new Date().toISOString(),detail:n!=null?n:null}),this._consoleLog.length>ee&&this._consoleLog.shift(),this._refreshConsoleChrome())}_formatConsoleLogText(){return!this._consoleLog||this._consoleLog.length===0?"":this._consoleLog.map(function(e){var n="";try{n=JSON.stringify(e.detail,null,2)}catch(r){n=String(e.detail)}return"["+e.timestamp+"] "+e.type+`
|
|
2
2
|
`+n}).join(`
|
|
3
3
|
|
|
4
|
-
`)}_refreshConsoleChrome(){if(!(!this.shadowRoot||!this._state.console)){var e=this.shadowRoot.querySelector(".vitraun-console-fab");if(e){var n=this._consoleLog?this._consoleLog.length:0;e.textContent=n>0?"Events ("+n+")":"Events"}var r=this.shadowRoot.querySelector(".vitraun-console-body");if(r&&this._consoleModalOpen){var o=this._formatConsoleLogText();o?(r.textContent=o,r.classList.remove("vitraun-console-empty")):(r.textContent="No events yet. Interact with the try-on to see activity.",r.classList.add("vitraun-console-empty")),r.scrollTop=r.scrollHeight}}}_setConsoleModalOpen(e){if(this._consoleModalOpen=e===!0,!!this.shadowRoot){var n=this.shadowRoot.querySelector(".vitraun-console-backdrop");n&&n.setAttribute("data-open",this._consoleModalOpen?"true":"false"),this._refreshConsoleChrome()}}_mountConsoleChrome(e){if(!(!e||!this._state.console)){var n=e.querySelector(".vitraun-console-fab");if(n){this._refreshConsoleChrome();return}var r=this,o=document.createElement("button");o.type="button",o.className="vitraun-console-fab",o.setAttribute("aria-label","Open Try-On events console"),o.textContent="Events",o.addEventListener("click",function(){r._setConsoleModalOpen(!0)});var s=document.createElement("div");s.className="vitraun-console-backdrop",s.setAttribute("data-open","false"),s.setAttribute("role","presentation"),s.addEventListener("click",function(R){R.target===s&&r._setConsoleModalOpen(!1)});var l=document.createElement("div");l.className="vitraun-console-modal",l.setAttribute("role","dialog"),l.setAttribute("aria-modal","true"),l.setAttribute("aria-label","Try-On events console"),l.addEventListener("click",function(R){R.stopPropagation()});var a=document.createElement("div");a.className="vitraun-console-header";var d=document.createElement("h2");d.className="vitraun-console-title",d.textContent="Try-On events";var c=document.createElement("div");c.className="vitraun-console-actions";var f=document.createElement("button");f.type="button",f.textContent="Clear",f.addEventListener("click",function(){r._consoleLog=[],r._refreshConsoleChrome()});var E=document.createElement("button");E.type="button",E.textContent="Close",E.addEventListener("click",function(){r._setConsoleModalOpen(!1)}),c.appendChild(f),c.appendChild(E),a.appendChild(d),a.appendChild(c);var O=document.createElement("pre");O.className="vitraun-console-body vitraun-console-empty",O.textContent="No events yet. Interact with the try-on to see activity.",l.appendChild(a),l.appendChild(O),s.appendChild(l),e.appendChild(o),e.appendChild(s),this._refreshConsoleChrome()}}_setStatus(e,n){this.setAttribute("data-status",e),this._emit("statusChange",{status:e,detail:n||null})}_getIframeElement(){return this.shadowRoot?this.shadowRoot.querySelector("iframe"):null}_getInstanceSessionKey(){return this.id==null?"":String(this.id).trim()}_handleMessage(e){var n=e.data;if(!(!n||typeof n!="object")){var r=this._getIframeElement();if(!(!r||!r.contentWindow)&&e.source===r.contentWindow&&!(!this._state.iframeOrigin||e.origin!==this._state.iframeOrigin)){var o=n.type,s=n.detail;if(o==="VTO_USAGE"){this._emit("vtoUsage",s);return}w.indexOf(o)!==-1&&this._emit(o,s)}}}_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})}_buildEmbedInitUrl(){return Ne(this._state.env,this._state.apiPort)}_buildInitPayload(){var e=v(this._getInstanceSessionKey());return{tryonSessionId:e,initRequestBody:Oe(this._state,e)}}_normalizeInitResponse(e,n,r){if(!e||typeof e!="object")throw new Error(_.INIT_INVALID_RESPONSE);var o=typeof e.sessionToken=="string"&&e.sessionToken?e.sessionToken:null,s=typeof e.tryonSessionId=="string"&&e.tryonSessionId?e.tryonSessionId:r;if(!o)throw new Error(_.INIT_SESSION_TOKEN_MISSING);var l=typeof e.vtoUrl=="string"&&e.vtoUrl.trim()?e.vtoUrl.trim():null;if(!l&&typeof e.iframeUrl=="string"&&e.iframeUrl.trim()&&(l=e.iframeUrl.trim()),!l)throw new Error(_.INIT_VTO_URL_MISSING);var a=pe(l);if(!a)throw new Error(_.INIT_VTO_URL_INVALID);return{sessionToken:o,tryonSessionId:s,initUrl:n,iframeUrl:l,iframeOrigin:a}}_initializeSessionIfNeeded(){var e=this;if(!this._state.merchantId)return Promise.reject(new Error(_.MERCHANT_ID_REQUIRED));if(!this._state.widgetId)return Promise.reject(new Error(_.WIDGET_ID_REQUIRED));var n=this._getInitStateKey();if(this._initPromise&&this._initStateKey===n)return this._initPromise;if(this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch(a){}this._initStateKey=n,this._activeInitRequestId+=1;var r=this._activeInitRequestId;this._setStatus("loading");var o;try{o=this._buildEmbedInitUrl()}catch(a){return Promise.reject(a)}var s=this._buildInitPayload();this._state.tryonSessionId=s.tryonSessionId,this._abortController=typeof AbortController!="undefined"?new AbortController:null;var l=fetch(o,{method:"POST",headers:ve({merchantId:this._state.merchantId,widgetId:this._state.widgetId,tryonSessionId:s.tryonSessionId,contentType:j}),body:JSON.stringify(s.initRequestBody),signal:this._abortController?this._abortController.signal:void 0}).then(function(a){return a.ok?a.json():a.text().then(function(d){var c=D(d),f=ge(c,d);throw new Error(f)})}).then(function(a){return e._normalizeInitResponse(a,o,s.tryonSessionId)});return this._initPromise=Re(l,this._state.initTimeoutMs,oe,this._abortController).then(function(a){return r!==e._activeInitRequestId||(e._state.sessionToken=a.sessionToken,e._state.tryonSessionId=a.tryonSessionId,e._state.resolvedInitUrl=a.initUrl,e._state.resolvedIframeUrl=a.iframeUrl,e._state.iframeOrigin=a.iframeOrigin,e._setStatus("ready")),a}).catch(function(a){if(r!==e._activeInitRequestId)throw a;var d=H(a);throw e._state.sessionToken=null,e._state.resolvedInitUrl=null,e._state.resolvedIframeUrl=null,e._state.iframeOrigin=null,e._setStatus("error",{message:d}),new Error(d)}).finally(function(){r===e._activeInitRequestId&&(e._initPromise=null)}),this._initPromise}_sendConfigToIframe(){var e=this._getIframeElement();if(!(!e||!e.contentWindow)){var n=this._state.iframeOrigin;if(!n){this._log(le.CONFIG_SKIPPED_NO_IFRAME_ORIGIN);return}var r={merchantId:this._state.merchantId,widgetId:this._state.widgetId,sessionToken:this._state.sessionToken,tryonSessionId:this._state.tryonSessionId||v(this._getInstanceSessionKey()),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},embedParentOrigin:N()};this._state.isSimulationMode&&this._state.simulationInlineConfig&&typeof this._state.simulationInlineConfig=="object"&&(r.inlineVirtualTryonConfig=this._state.simulationInlineConfig),e.contentWindow.postMessage({type:F,payload:r},n)}}_renderLoading(){if(this.shadowRoot){var e=u(this,i.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var n=document.createElement("style");n.textContent=_e(e,P);var r=document.createElement("div");r.className=P,r.textContent=re,this.shadowRoot.appendChild(n),this.shadowRoot.appendChild(r)}}_renderError(e){if(this.shadowRoot){var n=u(this,i.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var r=document.createElement("style");r.textContent=he(n,L);var o=document.createElement("div");o.className=L,o.textContent=e||ie,this.shadowRoot.appendChild(r),this.shadowRoot.appendChild(o)}}_renderIframe(e,n){if(this.shadowRoot&&!(!e||typeof e!="string"||!e.trim())){var r=this,o=u(this,i.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="",this._consoleModalOpen=!1;var s=document.createElement("style"),l=S(o);this._state.console&&(l+=de()),s.textContent=l;var a=document.createElement("div");a.className="vitraun-host";var d=document.createElement("iframe");d.src=ye(e.trim(),this._state,this._getInstanceSessionKey()),d.title=ne,d.setAttribute("allow","camera"),d.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),d.onload=function(){n===r._renderVersion&&[0,50,150,400,1e3].forEach(function(c){setTimeout(function(){n===r._renderVersion&&r._sendConfigToIframe()},c)})},a.appendChild(d),this._state.console&&this._mountConsoleChrome(a),this.shadowRoot.appendChild(s),this.shadowRoot.appendChild(a)}}_render(){if(this.shadowRoot){this._renderVersion+=1;var e=this._renderVersion;if(!this._state.merchantId){this._setStatus("error",{message:_.MERCHANT_ID_REQUIRED}),this._renderError(_.MERCHANT_ID_REQUIRED);return}if(!this._state.widgetId){this._setStatus("error",{message:_.WIDGET_ID_REQUIRED}),this._renderError(_.WIDGET_ID_REQUIRED);return}this._renderLoading(),this._initializeSessionIfNeeded().then(function(n){e===this._renderVersion&&this._renderIframe(n.iframeUrl,e)}.bind(this)).catch(function(n){if(e===this._renderVersion){var r=H(n instanceof Error?n:new Error(String(n)));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(g)&&customElements.define(g,Ce)})();})();
|
|
4
|
+
`)}_refreshConsoleChrome(){if(!(!this.shadowRoot||!this._state.console)){var e=this.shadowRoot.querySelector(".vitraun-console-fab");if(e){var n=this._consoleLog?this._consoleLog.length:0;e.textContent=n>0?"Events ("+n+")":"Events"}var r=this.shadowRoot.querySelector(".vitraun-console-body");if(r&&this._consoleModalOpen){var o=this._formatConsoleLogText();o?(r.textContent=o,r.classList.remove("vitraun-console-empty")):(r.textContent="No events yet. Interact with the try-on to see activity.",r.classList.add("vitraun-console-empty")),r.scrollTop=r.scrollHeight}}}_setConsoleModalOpen(e){if(this._consoleModalOpen=e===!0,!!this.shadowRoot){var n=this.shadowRoot.querySelector(".vitraun-console-backdrop");n&&n.setAttribute("data-open",this._consoleModalOpen?"true":"false"),this._refreshConsoleChrome()}}_mountConsoleChrome(e){if(!(!e||!this._state.console)){var n=e.querySelector(".vitraun-console-fab");if(n){this._refreshConsoleChrome();return}var r=this,o=document.createElement("button");o.type="button",o.className="vitraun-console-fab",o.setAttribute("aria-label","Open Try-On events console"),o.textContent="Events",o.addEventListener("click",function(){r._setConsoleModalOpen(!0)});var s=document.createElement("div");s.className="vitraun-console-backdrop",s.setAttribute("data-open","false"),s.setAttribute("role","presentation"),s.addEventListener("click",function(C){C.target===s&&r._setConsoleModalOpen(!1)});var l=document.createElement("div");l.className="vitraun-console-modal",l.setAttribute("role","dialog"),l.setAttribute("aria-modal","true"),l.setAttribute("aria-label","Try-On events console"),l.addEventListener("click",function(C){C.stopPropagation()});var a=document.createElement("div");a.className="vitraun-console-header";var u=document.createElement("h2");u.className="vitraun-console-title",u.textContent="Try-On events";var _=document.createElement("div");_.className="vitraun-console-actions";var f=document.createElement("button");f.type="button",f.textContent="Clear",f.addEventListener("click",function(){r._consoleLog=[],r._refreshConsoleChrome()});var p=document.createElement("button");p.type="button",p.textContent="Close",p.addEventListener("click",function(){r._setConsoleModalOpen(!1)}),_.appendChild(f),_.appendChild(p),a.appendChild(u),a.appendChild(_);var O=document.createElement("pre");O.className="vitraun-console-body vitraun-console-empty",O.textContent="No events yet. Interact with the try-on to see activity.",l.appendChild(a),l.appendChild(O),s.appendChild(l),e.appendChild(o),e.appendChild(s),this._refreshConsoleChrome()}}_setStatus(e,n){this.setAttribute("data-status",e),this._emit("statusChange",{status:e,detail:n||null})}_getIframeElement(){return this.shadowRoot?this.shadowRoot.querySelector("iframe"):null}_getInstanceSessionKey(){return this.id==null?"":String(this.id).trim()}_handleMessage(e){var n=e.data;if(!(!n||typeof n!="object")){var r=this._getIframeElement();if(!(!r||!r.contentWindow)&&e.source===r.contentWindow&&!(!this._state.iframeOrigin||e.origin!==this._state.iframeOrigin)){var o=n.type,s=n.detail;if(o==="VTO_USAGE"){this._emit("vtoUsage",s);return}P.indexOf(o)!==-1&&this._emit(o,s)}}}_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,useQrCode:this._state.useQrCode})}_buildEmbedInitUrl(){return ve(this._state.env,this._state.apiPort)}_buildInitPayload(){var e=v(this._getInstanceSessionKey());return{tryonSessionId:e,initRequestBody:Ce(this._state,e)}}_normalizeInitResponse(e,n,r){if(!e||typeof e!="object")throw new Error(h.INIT_INVALID_RESPONSE);var o=typeof e.sessionToken=="string"&&e.sessionToken?e.sessionToken:null,s=typeof e.tryonSessionId=="string"&&e.tryonSessionId?e.tryonSessionId:r;if(!o)throw new Error(h.INIT_SESSION_TOKEN_MISSING);var l=typeof e.vtoUrl=="string"&&e.vtoUrl.trim()?e.vtoUrl.trim():null;if(!l&&typeof e.iframeUrl=="string"&&e.iframeUrl.trim()&&(l=e.iframeUrl.trim()),!l)throw new Error(h.INIT_VTO_URL_MISSING);var a=Ee(l);if(!a)throw new Error(h.INIT_VTO_URL_INVALID);var u=typeof e.handoffToken=="string"&&e.handoffToken.trim()?e.handoffToken.trim():null,_=typeof e.embedParentOrigin=="string"&&e.embedParentOrigin.trim()?e.embedParentOrigin.trim():null;return{sessionToken:o,handoffToken:u,embedParentOrigin:_,tryonSessionId:s,initUrl:n,iframeUrl:l,iframeOrigin:a}}_initializeSessionIfNeeded(){var e=this;if(!this._state.merchantId)return Promise.reject(new Error(h.MERCHANT_ID_REQUIRED));if(!this._state.widgetId)return Promise.reject(new Error(h.WIDGET_ID_REQUIRED));var n=this._getInitStateKey();if(this._initPromise&&this._initStateKey===n)return this._initPromise;if(this._abortController&&typeof this._abortController.abort=="function")try{this._abortController.abort()}catch(a){}this._initStateKey=n,this._activeInitRequestId+=1;var r=this._activeInitRequestId;this._setStatus("loading");var o;try{o=this._buildEmbedInitUrl()}catch(a){return Promise.reject(a)}var s=this._buildInitPayload();this._state.tryonSessionId=s.tryonSessionId,this._abortController=typeof AbortController!="undefined"?new AbortController:null;var l=fetch(o,{method:"POST",headers:Oe({merchantId:this._state.merchantId,widgetId:this._state.widgetId,tryonSessionId:s.tryonSessionId,contentType:Z}),body:JSON.stringify(s.initRequestBody),signal:this._abortController?this._abortController.signal:void 0}).then(function(a){return a.ok?a.json():a.text().then(function(u){var _=D(u),f=Se(_,u);throw new Error(f)})}).then(function(a){return e._normalizeInitResponse(a,o,s.tryonSessionId)});return this._initPromise=Re(l,this._state.initTimeoutMs,oe,this._abortController).then(function(a){return r!==e._activeInitRequestId||(e._state.sessionToken=a.sessionToken,e._state.handoffToken=a.handoffToken,e._state.embedParentOrigin=a.embedParentOrigin,e._state.tryonSessionId=a.tryonSessionId,e._state.resolvedInitUrl=a.initUrl,e._state.resolvedIframeUrl=a.iframeUrl,e._state.iframeOrigin=a.iframeOrigin,e._setStatus("ready")),a}).catch(function(a){if(r!==e._activeInitRequestId)throw a;var u=H(a);throw e._state.sessionToken=null,e._state.handoffToken=null,e._state.embedParentOrigin=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 n=this._state.iframeOrigin;if(!n){this._log(le.CONFIG_SKIPPED_NO_IFRAME_ORIGIN);return}var r={merchantId:this._state.merchantId,widgetId:this._state.widgetId,sessionToken:this._state.sessionToken,handoffToken:this._state.handoffToken,tryonSessionId:this._state.tryonSessionId||v(this._getInstanceSessionKey()),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},embedParentOrigin:N()};this._state.useQrCode!==void 0&&(r.useQrCode=this._state.useQrCode),this._state.isSimulationMode&&this._state.simulationInlineConfig&&typeof this._state.simulationInlineConfig=="object"&&(r.inlineVirtualTryonConfig=this._state.simulationInlineConfig),e.contentWindow.postMessage({type:F,payload:r},n)}}_renderLoading(){if(this.shadowRoot){var e=d(this,i.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var n=document.createElement("style");n.textContent=_e(e,w);var r=document.createElement("div");r.className=w,r.textContent=re,this.shadowRoot.appendChild(n),this.shadowRoot.appendChild(r)}}_renderError(e){if(this.shadowRoot){var n=d(this,i.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="";var r=document.createElement("style");r.textContent=he(n,L);var o=document.createElement("div");o.className=L,o.textContent=e||ie,this.shadowRoot.appendChild(r),this.shadowRoot.appendChild(o)}}_renderIframe(e,n){if(this.shadowRoot&&!(!e||typeof e!="string"||!e.trim())){var r=this,o=d(this,i.CONTAINER_MIN_HEIGHT,"80vh");this.shadowRoot.innerHTML="",this._consoleModalOpen=!1;var s=document.createElement("style"),l=S(o);this._state.console&&(l+=ue()),s.textContent=l;var a=document.createElement("div");a.className="vitraun-host";var u=document.createElement("iframe");u.src=ye(e.trim(),this._state,this._getInstanceSessionKey()),u.title=ne,u.setAttribute("allow","camera"),u.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),u.onload=function(){n===r._renderVersion&&[0,50,150,400,1e3].forEach(function(_){setTimeout(function(){n===r._renderVersion&&r._sendConfigToIframe()},_)})},a.appendChild(u),this._state.console&&this._mountConsoleChrome(a),this.shadowRoot.appendChild(s),this.shadowRoot.appendChild(a)}}_render(){if(this.shadowRoot){this._renderVersion+=1;var e=this._renderVersion;if(!this._state.merchantId){this._setStatus("error",{message:h.MERCHANT_ID_REQUIRED}),this._renderError(h.MERCHANT_ID_REQUIRED);return}if(!this._state.widgetId){this._setStatus("error",{message:h.WIDGET_ID_REQUIRED}),this._renderError(h.WIDGET_ID_REQUIRED);return}this._renderLoading(),this._initializeSessionIfNeeded().then(function(n){e===this._renderVersion&&this._renderIframe(n.iframeUrl,e)}.bind(this)).catch(function(n){if(e===this._renderVersion){var r=H(n instanceof Error?n:new Error(String(n)));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(g)&&customElements.define(g,be)})();})();
|