@neurodyn/core-ar 0.2.4 → 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/dist/core-ar.embed.min.js +2 -2
- package/dist/index.js +24 -5
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(()=>{"use strict";let e,t,i;function r(e,t){let i;try{i=new URL(e)}catch{throw TypeError(`${t} must be an absolute HTTP(S) URL`)}if("http:"!==i.protocol&&"https:"!==i.protocol)throw TypeError(`${t} must be an absolute HTTP(S) URL`);return i.origin}function n(){if(!e)throw Error("Core AR widget runtime is not configured");return e}function o(){return"u"<typeof navigator?"":navigator.userAgent||navigator.vendor||""}function a(){if("u"<typeof window||"u"<typeof navigator)return!1;let e="MacIntel"===navigator.platform&&navigator.maxTouchPoints>1;return(/iPad|iPhone|iPod/.test(o())||e)&&!("MSStream"in window)}function s(){if("u"<typeof window||"u"<typeof navigator)return!1;let e=navigator.maxTouchPoints>1,t=window.matchMedia?.("(pointer: coarse)").matches??!1,i=/Android|iPhone|iPad|iPod|webOS|BlackBerry|Windows Phone|Opera Mini|IEMobile|Mobile/i.test(o());return e&&t&&(i||a())}function l(){let e=o();return[[/edg/i,"Microsoft Edge"],[/trident/i,"Microsoft Internet Explorer"],[/firefox|fxios/i,"Mozilla Firefox"],[/opr\//i,"Opera"],[/ucbrowser/i,"UC Browser"],[/samsungbrowser/i,"Samsung Browser"],[/chrome|chromium|crios/i,"Google Chrome"],[/safari/i,"Apple Safari"]].find(([t])=>t.test(e))?.[1]??"Other"}function d(){let e=function(){let e=o(),t=e.match(/\bOS (\d+)/)?.[1]??e.match(/Version\/(\d+)/)?.[1];if(!t)return null;let i=Number.parseInt(t,10);return Number.isNaN(i)?null:i}();return null!==e&&e>=17}function c(e){let t;try{t=new URL(e)}catch{throw TypeError("Native AR asset URL must be absolute HTTP(S)")}if("http:"!==t.protocol&&"https:"!==t.protocol)throw TypeError("Native AR asset URL must be absolute HTTP(S)");return t.href}function u(e,t){let i=c(e.glbUrl),r=c(e.usdzUrl),n=encodeURIComponent(i),o=`intent://arvr.google.com/scene-viewer/1.0?file=${n}&resizable=false${"wall"===t||"ceiling"===t?"&enable_vertical_placement=true":""}&mode=ar_preferred#Intent;scheme=https;package=com.google.android.googlequicksearchbox;action=android.intent.action.VIEW;end;`,s=`${r}#allowsContentScaling=0`;return a()?s:o}function g(e,t=0){let i=document.createElement("a"),r=document.createElement("img");i.rel="ar",i.href=e,i.hidden=!0,r.alt="",r.hidden=!0,i.appendChild(r),document.body.appendChild(i),window.setTimeout(()=>{i.click(),i.remove()},t)}function h(e,t,i){let r=function(e,t,i){let{brand:r}=i??n();if(a()){let i=new URL("https://appclip.apple.com/id");return i.searchParams.set("p","com.us.vizbl.Clip"),i.searchParams.set("tinuuid",e),t&&i.searchParams.set("hid",t),i.searchParams.set("region","arizo"===r?"ru":"en"),i.toString()}return`intent:/${window.location.pathname}#Intent;scheme=open;package=com.us.vizbl;end`}(e,t,i);window.self===window.top||l().toLowerCase().includes("edge")?window.location.assign(r):window.open(r,"_top")}function m(e,t,i=!1,r){let{viewerOrigin:o}=r??n(),a=new URL("/ar/index.html",o);return a.searchParams.set("tinuuid",e),t&&a.searchParams.set("hid",t),i&&a.searchParams.set("appview","true"),a.toString()}function p(){let e=new WeakMap;return function(t){let i=e.get(t);i?.cleanup?.();let r={revision:(i?.revision??0)+1};return e.set(t,r),{isCurrent:()=>e.get(t)===r,register(i){let n=!1,o=()=>{n||(n=!0,i())};return e.get(t)!==r?(o(),o):(r.cleanup=o,()=>{e.get(t)===r&&e.delete(t),o()})}}}}let f=0,v={arizo:{conjunction:"и",privacyLabel:"Политика конфиденциальности",privacyUrl:"https://arizo.ru/privacy-policy/",termsLabel:"Условия использования",termsUrl:"https://arizo.ru/terms-of-use/"},vizbl:{conjunction:"and",privacyLabel:"Privacy Policy",privacyUrl:"https://vizbl.com/legal/privacy-policy",termsLabel:"Terms of Use",termsUrl:"https://vizbl.com/legal/terms-of-use"}};function w(){return window.QRCode}function b(e,t,i){let r=document.createElement("a");return r.dataset.vizblLegalLink=e,r.href=t,r.rel="noopener noreferrer",r.target="_blank",r.textContent=i,Object.assign(r.style,{color:"inherit",textDecoration:"underline",textUnderlineOffset:"2px",whiteSpace:"nowrap"}),r}async function y(e,r="vizblQrModal",o,a){let s,l=++f;i?.(),document.querySelectorAll("[data-vizbl-qr-modal]").forEach(e=>e.remove());let d=function(e){let{brand:t,viewerOrigin:i}=e??n(),r="arizo"===t,o=document.createElement("div");o.dataset.vizblQrModal="",o.setAttribute("aria-label","View object in augmented reality"),o.setAttribute("aria-modal","true"),o.setAttribute("role","dialog"),Object.assign(o.style,{alignItems:"center",backgroundColor:"rgba(0,0,0,0.25)",display:"none",height:"100%",justifyContent:"center",left:"0",position:"fixed",top:"0",width:"100%",zIndex:"9999"});let a=document.createElement("div");Object.assign(a.style,{backgroundColor:"#fff",borderRadius:"12px",boxSizing:"border-box",color:"#000",fontFamily:"Inter, sans-serif",minHeight:"372px",padding:"48px 52px 40px",position:"relative",width:"min(460px, calc(100vw - 32px))"});let s=document.createElement("button");s.type="button",s.dataset.vizblQrClose="",s.setAttribute("aria-label","Close QR code"),s.textContent="\xd7",Object.assign(s.style,{background:"none",border:"none",color:"#AEB1B7",cursor:"pointer",fontSize:"24px",position:"absolute",right:"20px",top:"20px"});let l=document.createElement("div");l.dataset.vizblQrCode="",l.style.margin="0 auto",l.style.width="fit-content";let d=document.createElement("p");d.textContent=r?"Отсканируйте этот QR-код камерой телефона, чтобы примерить объект в интерьере":"Scan this QR code with your phone camera to view the object in Augmented Reality",Object.assign(d.style,{fontSize:"16px",fontWeight:"500",lineHeight:"24px",margin:"24px 0 0",textAlign:"center"});let c=document.createElement("p");Object.assign(c.style,{color:"#93979F",fontSize:"12px",lineHeight:"16px",margin:"12px 0 0",textAlign:"center"});let u=v[t],g=b("terms",u.termsUrl,u.termsLabel),h=b("privacy",u.privacyUrl,u.privacyLabel);c.append(r?"*Требуется устройство и браузер с поддержкой AR. Рекомендуем iOS 12 или новее с Safari либо Android 7.0 или новее с Chrome.":"*Requires an AR-compatible device and browser. We recommend iOS 12 or later with Safari, or Android 7.0 or later with Chrome.",document.createElement("br"),g,` ${u.conjunction} `,h);let m=document.createElement("p");m.textContent=`Powered by ${r?"Arizo":"Vizbl"}`,Object.assign(m.style,{color:"#93979F",fontSize:"11px",letterSpacing:"1.5px",margin:"24px 0 4px",textAlign:"center",textTransform:"uppercase"});let p=document.createElement("a");p.dataset.vizblBrandLink="",p.href=r?"https://arizo.ru":"https://vizbl.com",p.style.display="block",p.style.textAlign="center";let f=document.createElement("img");return f.alt=`${r?"Arizo":"Vizbl"} logo`,f.src=`${i}/${r?"logoArizo.svg":"logo.svg"}`,f.height=20,f.width=r?76:60,p.appendChild(f),a.append(s,l,d,c,m,p),o.appendChild(a),o}(a);d.id=r;let c=d.querySelector("[data-vizbl-qr-close]"),u=Array.from(d.querySelectorAll("button, a[href]")),g=!1,h=e=>{if("Escape"===e.key){e.preventDefault(),s();return}if("Tab"!==e.key||0===u.length)return;let t=u[0],i=u.at(-1)??t;e.shiftKey&&(document.activeElement===t||!d.contains(document.activeElement))?(e.preventDefault(),i.focus()):e.shiftKey||document.activeElement!==i||(e.preventDefault(),t.focus())};i=s=()=>{g||(g=!0,document.removeEventListener("keydown",h),d.remove(),i===s&&(i=void 0),o?.focus({preventScroll:!0}))},c?.addEventListener("click",s),d.addEventListener("click",e=>{e.target===d&&s()}),document.body.appendChild(d),document.addEventListener("keydown",h),function(){let e="https://fonts.googleapis.com/css2?family=Inter&display=swap";if(Array.from(document.querySelectorAll('link[rel="stylesheet"]')).some(t=>t.href===e||t.getAttribute("href")===e))return;let t=document.createElement("link");t.rel="stylesheet",t.href=e,document.head.appendChild(t)}();try{let i=await function(e){let i=w();if(i)return Promise.resolve(i);if(t)return t;let{qrCodeScriptUrl:r}=e??n();return t=new Promise((e,i)=>{let n,o=document.createElement("script"),a=()=>{n();let r=w();r?e(r):(o.remove(),t=void 0,i(Error("QR code runtime did not expose QRCode")))},s=()=>{n(),o.remove(),t=void 0,i(Error("Failed to load QR code runtime"))};n=()=>{o.removeEventListener("load",a),o.removeEventListener("error",s)},o.addEventListener("load",a,{once:!0}),o.addEventListener("error",s,{once:!0}),o.src=r,o.async=!0,o.dataset.vizblQrScript="true",document.head.appendChild(o)})}(a);if(l!==f||!d.isConnected)return s(),s;let r=d.querySelector("[data-vizbl-qr-code]");return r&&new i(r,{correctLevel:i.CorrectLevel.L,height:148,text:e,width:148}),d.style.display="flex",c?.focus({preventScroll:!0}),s}catch(e){throw s(),e}}class E extends Error{code;constructor(e){super(e),this.code=e,this.name="WidgetRuntimeError"}}function A(e){return e.runtimeConfig??n()}function I(e,t,i={}){let r=new URL(t,e);for(let[e,t]of Object.entries(i))t&&r.searchParams.set(e,t);return r.toString()}async function C(e,t,i){try{return await (i.fetchImpl??i.runtimeConfig?.fetchImpl??n().fetchImpl)(e,{...t,signal:i.signal})}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)throw e;throw new E("NETWORK_ERROR")}}async function S(e){try{let t=await e.json();return[t.code,t.error,t.message].flatMap(e=>Array.isArray(e)?e:[e]).filter(e=>"string"==typeof e).join(" ").toLowerCase()}catch{return""}}async function k(e,t){let i=await S(e);return new E(429===e.status?"RATE_LIMITED":e.status>=500?"API_UNAVAILABLE":404===e.status&&"object"===t?"OBJECT_NOT_FOUND":i.includes("domain")||i.includes("origin")?"DOMAIN_NOT_ALLOWED":i.includes("revoked")?"KEY_REVOKED":i.includes("expired")?"activation"===t?"KEY_EXPIRED":"SESSION_EXPIRED":i.includes("policy")||i.includes("not available for this object")?"POLICY_DENIED":401===e.status||403===e.status?"activation"===t?"INVALID_KEY":"SESSION_EXPIRED":"REQUEST_FAILED")}async function x(e){try{return await e.json()}catch{throw new E("INVALID_RESPONSE")}}function T(e){if(!e||"object"!=typeof e||"string"!=typeof e.token||!e.token.trim()||"string"!=typeof e.sid||!e.sid.trim()||"number"!=typeof e.expiresIn||!Number.isFinite(e.expiresIn)||e.expiresIn<=0)throw new E("INVALID_RESPONSE");return e}async function L(e,t={}){let{apiOrigin:i}=A(t),r=await C(I(i,"/public/widget/activate-core",{mode:t.mode}),{cache:"no-store",headers:{"x-api-key":e},method:"POST"},t);if(!r.ok)throw await k(r,"activation");let n=await x(r);if("string"!=typeof n.productType)throw new E("INVALID_RESPONSE");return{...T(n.widgetSession),productType:n.productType}}async function z(e,t,i={}){let{apiOrigin:r}=A(i),n=await C(`${r}/public/widget/token`,{body:JSON.stringify({token:t,...i.mode?{mode:i.mode}:{}}),cache:"no-store",headers:{"Content-Type":"application/json","x-api-key":e},method:"POST"},i);if(!n.ok)throw await k(n,"token");return T(await x(n))}async function O(e,t,i={}){let{apiOrigin:r}=A(i),n=await C(I(r,`/public/objects/by-tinuuid/${encodeURIComponent(e)}`,{variantId:i.variantId}),{cache:"no-store",headers:{"x-widget-session-token":t},method:"GET"},i);if(!n.ok)throw await k(n,"object");let o=await x(n);if(!o||"object"!=typeof o||Array.isArray(o))throw new E("INVALID_RESPONSE");return o}async function R(e,t,i,r={}){let{apiOrigin:n}=A(r),o=await C(`${n}/public/widget/events`,{body:JSON.stringify({event:e,...i?{objectId:i}:{},...r.variantId?{variantId:r.variantId}:{},timestamp:new Date().toISOString()}),cache:"no-store",headers:{"Content-Type":"application/json","x-widget-session-token":t},keepalive:!0,method:"POST"},r);if(!o.ok)throw await k(o,"event");let a=await x(o);if(!a||"object"!=typeof a||Array.isArray(a)||"boolean"!=typeof a.ok)throw new E("INVALID_RESPONSE")}async function N(e,t,i){let r=i??n(),{fetchImpl:o,legacyApiOrigin:a}=r,s=await C(`${a}/obj/Fetch`,{body:JSON.stringify({tinuuid:e}),headers:{"Content-Type":"application/json"},method:"POST"},{fetchImpl:o,runtimeConfig:r,signal:t});if(!s.ok)throw await k(s,"object");let l=await x(s);if(!l||"object"!=typeof l||Array.isArray(l))throw new E("INVALID_RESPONSE");return l}async function D(e,t){let{fetchImpl:i,legacyApiOrigin:r}=t??n();await i(`${r}/obj/IncrViews`,{body:JSON.stringify({tinuuid:e}),headers:{"Content-Type":"application/json"},method:"POST"})}function P(e){try{let t=e?.();t instanceof Promise&&t.catch(()=>void 0)}catch{}}let j=p();function _(e){if(e?.aborted)throw new DOMException("Aborted","AbortError")}async function U(e,t={}){let i,r,n=j(e),o=e.getAttribute("data-native-link"),c=e.dataset.objectTinuuid?.trim(),p=e.dataset.objectHid?.trim()||void 0;if(!c)throw Error("Object ID is required");_(t.signal);let f=t.loadObject??((e,i)=>N(e,i,t.runtimeConfig)),v=t.object??await f(c,t.signal);if(_(t.signal),!n.isCurrent())return()=>void 0;let w=p?v.materials.find(e=>e.hid===p):v.materials[0];if(!w?.native?.glbUrl||!w.native.usdzUrl)throw Error("Native AR assets are unavailable");let b=u(w.native,v.type),E=s(),A=!1,I=0;e.querySelector("img")||((i=document.createElement("img")).alt="",i.hidden=!0,e.appendChild(i));let C=()=>t.trackView?t.trackView():D(c,t.runtimeConfig),S=i=>{i.preventDefault();let o=++I;r?.(),r=void 0,Promise.resolve(t.getDesktopQrUrl?.()??m(c,p,!0,t.runtimeConfig)).then(i=>{if(o===I&&n.isCurrent())return P(()=>t.onAction?.("interacted")),y(i,`vizbl-${c}`,e,t.runtimeConfig)}).then(e=>{if(e){if(o!==I||!n.isCurrent())return void e();r=e}}).catch(()=>void 0)},k=async e=>{let i;if(i=l().toLowerCase(),["firefox","edge","opera"].some(e=>i.includes(e))){if(e.preventDefault(),A)return;A=!0,P(()=>t.onAction?.("ar_launched"));try{await Promise.resolve(C()).catch(()=>void 0)}finally{A=!1,a()&&d()?h(c,p,t.runtimeConfig):g(b)}return}P(()=>t.onAction?.("ar_launched")),P(C),a()&&d()?(e.preventDefault(),h(c,p,t.runtimeConfig)):g(b)};return E?(e.dataset.nativeLink=b,e.addEventListener("click",k)):e.addEventListener("click",S),n.register(()=>{I+=1,e.removeEventListener("click",S),e.removeEventListener("click",k),r?.(),i?.remove(),null===o?e.removeAttribute("data-native-link"):e.setAttribute("data-native-link",o)})}var V=!1;if("u">typeof window){var M={get passive(){V=!0;return}};window.addEventListener("testPassive",null,M),window.removeEventListener("testPassive",null,M)}var $="u">typeof window&&window.navigator&&window.navigator.platform&&(/iP(ad|hone|od)/.test(window.navigator.platform)||"MacIntel"===window.navigator.platform&&window.navigator.maxTouchPoints>1),B=[],q=!1,H=-1,W=void 0,F=void 0,K=void 0,Q=function(e){return B.some(function(t){return!!(t.options.allowTouchMove&&t.options.allowTouchMove(e))})},Y=function(e){var t=e||window.event;return!!Q(t.target)||t.touches.length>1||(t.preventDefault&&t.preventDefault(),!1)},X=function(e){if(void 0===K){var t=!!e&&!0===e.reserveScrollBarGap,i=window.innerWidth-document.documentElement.clientWidth;if(t&&i>0){var r=parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"),10);K=document.body.style.paddingRight,document.body.style.paddingRight=r+i+"px"}}void 0===W&&(W=document.body.style.overflow,document.body.style.overflow="hidden")},J=function(){void 0!==K&&(document.body.style.paddingRight=K,K=void 0),void 0!==W&&(document.body.style.overflow=W,W=void 0)},Z=function(){if(void 0!==F){var e=-parseInt(document.body.style.top,10),t=-parseInt(document.body.style.left,10);document.body.style.position=F.position,document.body.style.top=F.top,document.body.style.left=F.left,window.scrollTo(t,e),F=void 0}},G=function(e,t){var i=e.targetTouches[0].clientY-H;return!Q(e.target)&&(t&&0===t.scrollTop&&i>0?Y(e):t&&t.scrollHeight-t.scrollTop<=t.clientHeight&&i<0?Y(e):(e.stopPropagation(),!0))},ee=function(e,t){e?!B.some(function(t){return t.targetElement===e})&&(B=[].concat(function(e){if(!Array.isArray(e))return Array.from(e);for(var t=0,i=Array(e.length);t<e.length;t++)i[t]=e[t];return i}(B),[{targetElement:e,options:t||{}}]),$?window.requestAnimationFrame(function(){if(void 0===F){F={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left};var e=window,t=e.scrollY,i=e.scrollX,r=e.innerHeight;document.body.style.position="fixed",document.body.style.top=-t,document.body.style.left=-i,setTimeout(function(){return window.requestAnimationFrame(function(){var e=r-window.innerHeight;e&&t>=r&&(document.body.style.top=-(t+e))})},300)}}):X(t),$&&(e.ontouchstart=function(e){1===e.targetTouches.length&&(H=e.targetTouches[0].clientY)},e.ontouchmove=function(t){1===t.targetTouches.length&&G(t,e)},q||(document.addEventListener("touchmove",Y,V?{passive:!1}:void 0),q=!0))):console.error("disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.")},et=function(e){e?(B=B.filter(function(t){return t.targetElement!==e}),$&&(e.ontouchstart=null,e.ontouchmove=null,q&&0===B.length&&(document.removeEventListener("touchmove",Y,V?{passive:!1}:void 0),q=!1)),$?Z():J()):console.error("enableBodyScroll unsuccessful - targetElement must be provided when calling enableBodyScroll on IOS devices.")};let ei=["cm","inch"],er=["x","y","z"],en=[...er],eo="vizbl_viewer",ea=p();function es(e){return e&&ei.includes(e)?e:"inch"}function el(e){if(!e)return en;let t=Array.from(new Set(e.split(",").map(e=>e.trim().toLowerCase()).filter(e=>er.includes(e))));return t.length>0?t:en}function ed(e){let t=new URL("/model-viewer",e.modelViewerOrigin??n().modelViewerOrigin),i=e.dimensionAxes??en;t.searchParams.set("tinuuid",e.tinuuid),e.hid&&t.searchParams.set("hid",e.hid),t.searchParams.set("size-type",e.sizeType),i.length<en.length&&t.searchParams.set("dimension-axes",i.join(","));let r=new URLSearchParams;return e.apiKey&&r.set("api-key",e.apiKey),e.mode&&r.set("mode",e.mode),e.widgetSessionToken&&r.set("widget-session-token",e.widgetSessionToken),t.hash=r.toString(),t.toString()}let ec=p();function eu(e){if(e?.aborted)throw new DOMException("Aborted","AbortError")}async function eg(e,t={}){let i,r,n=ec(e),o=e.getAttribute("href"),a=e.getAttribute("rel"),l=e.dataset.objectTinuuid?.trim(),d=e.dataset.objectHid?.trim()||void 0;if(!l)throw Error("Object ID is required");eu(t.signal);let c=t.loadObject??((e,i)=>N(e,i,t.runtimeConfig)),g=t.object??await c(l,t.signal);if(eu(t.signal),!n.isCurrent())return()=>void 0;let h=d?g.materials.find(e=>e.hid===d):g.materials[0];if(!h?.native?.glbUrl||!h.native.usdzUrl)throw Error("Native AR assets are unavailable");let p=u(h.native,g.type),f=s(),v=0;e.rel="ar",e.querySelector("img")||((i=document.createElement("img")).alt="",i.hidden=!0,e.appendChild(i));let w=i=>{i.preventDefault();let o=++v;r?.(),r=void 0,Promise.resolve(t.getDesktopQrUrl?.()??m(l,d,!1,t.runtimeConfig)).then(i=>{if(o===v&&n.isCurrent())return P(()=>t.onAction?.("interacted")),y(i,`vizbl-${l}`,e,t.runtimeConfig)}).then(e=>{if(e){if(o!==v||!n.isCurrent())return void e();r=e}}).catch(()=>void 0)},b=()=>{P(t.trackView??(()=>D(l,t.runtimeConfig))),P(()=>t.onAction?.("ar_launched"))};return f?(e.href=p,e.addEventListener("click",b)):(e.href="#",e.addEventListener("click",w)),n.register(()=>{v+=1,e.removeEventListener("click",w),e.removeEventListener("click",b),r?.(),i?.remove(),null===o?e.removeAttribute("href"):e.setAttribute("href",o),null===a?e.removeAttribute("rel"):e.setAttribute("rel",a)})}let eh=["advanced-ar","ar-one-click","ar-viewer"],em={arizo:"arizo-core",vizbl:"vizbl-core"},ep=new Set(["core-ar","core-ar-shopify"]),ef={"advanced-ar":"View in advanced AR","ar-one-click":"View in AR","ar-viewer":"View in 3D & AR"},ev={"advanced-ar":"advanced-ar-view","ar-one-click":"ar-view","ar-viewer":"ar-viewer"},ew=["api-key","dev","dimension-axes","object-id","size-type","trigger-class","type","variant-id"],eb=new Set(["API_UNAVAILABLE","INVALID_RESPONSE","NETWORK_ERROR","REQUEST_FAILED","SESSION_EXPIRED"]),ey="core-ar-widget-styles";class eE extends Error{code;constructor(e){super(e),this.code=e,this.name="CoreArWidgetComponentError"}}function eA(e){return eh.includes(e)}function eI(e,t){let i=Array.isArray(e.materials)?e.materials:[],r=t?i.find(e=>e.hid===t):i[0];if(!r)throw new eE(t?"VARIANT_NOT_FOUND":"MODEL_UNAVAILABLE");return r}function eC(e,t){let i=t.policy;if(!("ar-one-click"===e?i?.instantArView!==!1:i?.appClip!==!1))throw new eE("POLICY_DENIED")}let eS="u"<typeof HTMLElement?class{}:HTMLElement;class ek extends eS{static get observedAttributes(){return[...ew]}get triggerClass(){return this.getAttribute("trigger-class")??""}set triggerClass(e){let t="string"==typeof e?e.trim():"";t?this.setAttribute("trigger-class",t):this.removeAttribute("trigger-class")}get unstyled(){return this.hasAttribute("unstyled")}set unstyled(e){this.toggleAttribute("unstyled",!!e)}abortController;actionResetTimer;cleanup;customLabelNodes=null;initializationRevision=0;object;queued=!1;session;trigger;variantId;widgetMode;connectedCallback(){!function(){if(document.getElementById(ey))return;let e=document.createElement("style");e.id=ey,e.textContent=`
|
|
1
|
+
(()=>{"use strict";let e,t,i;function r(e,t){let i;try{i=new URL(e)}catch{throw TypeError(`${t} must be an absolute HTTP(S) URL`)}if("http:"!==i.protocol&&"https:"!==i.protocol)throw TypeError(`${t} must be an absolute HTTP(S) URL`);return i.origin}function n(){if(!e)throw Error("Core AR widget runtime is not configured");return e}function o(){return"u"<typeof navigator?"":navigator.userAgent||navigator.vendor||""}function a(){if("u"<typeof window||"u"<typeof navigator)return!1;let e="MacIntel"===navigator.platform&&navigator.maxTouchPoints>1;return(/iPad|iPhone|iPod/.test(o())||e)&&!("MSStream"in window)}function s(){if("u"<typeof window||"u"<typeof navigator)return!1;let e=navigator.maxTouchPoints>1,t=window.matchMedia?.("(pointer: coarse)").matches??!1,i=/Android|iPhone|iPad|iPod|webOS|BlackBerry|Windows Phone|Opera Mini|IEMobile|Mobile/i.test(o());return e&&t&&(i||a())}function d(){let e=o();return[[/edg/i,"Microsoft Edge"],[/trident/i,"Microsoft Internet Explorer"],[/firefox|fxios/i,"Mozilla Firefox"],[/opr\//i,"Opera"],[/ucbrowser/i,"UC Browser"],[/samsungbrowser/i,"Samsung Browser"],[/chrome|chromium|crios/i,"Google Chrome"],[/safari/i,"Apple Safari"]].find(([t])=>t.test(e))?.[1]??"Other"}function l(){let e=function(){let e=o(),t=e.match(/\bOS (\d+)/)?.[1]??e.match(/Version\/(\d+)/)?.[1];if(!t)return null;let i=Number.parseInt(t,10);return Number.isNaN(i)?null:i}();return null!==e&&e>=17}function c(e){let t;try{t=new URL(e)}catch{throw TypeError("Native AR asset URL must be absolute HTTP(S)")}if("http:"!==t.protocol&&"https:"!==t.protocol)throw TypeError("Native AR asset URL must be absolute HTTP(S)");return t.href}function u(e,t){let i=c(e.glbUrl),r=c(e.usdzUrl),n=encodeURIComponent(i),o=`intent://arvr.google.com/scene-viewer/1.0?file=${n}&resizable=false${"wall"===t||"ceiling"===t?"&enable_vertical_placement=true":""}&mode=ar_preferred#Intent;scheme=https;package=com.google.android.googlequicksearchbox;action=android.intent.action.VIEW;end;`,s=`${r}#allowsContentScaling=0`;return a()?s:o}function g(e,t=0){let i=document.createElement("a"),r=document.createElement("img");i.rel="ar",i.href=e,i.hidden=!0,r.alt="",r.hidden=!0,i.appendChild(r),document.body.appendChild(i),window.setTimeout(()=>{i.click(),i.remove()},t)}function m(e,t,i){let r=function(e,t,i){let{brand:r}=i??n();if(a()){let i=new URL("https://appclip.apple.com/id");return i.searchParams.set("p","com.us.vizbl.Clip"),i.searchParams.set("tinuuid",e),t&&i.searchParams.set("hid",t),i.searchParams.set("region","arizo"===r?"ru":"en"),i.toString()}return`intent:/${window.location.pathname}#Intent;scheme=open;package=com.us.vizbl;end`}(e,t,i);window.self===window.top||d().toLowerCase().includes("edge")?window.location.assign(r):window.open(r,"_top")}function h(e,t,i=!1,r){let{viewerOrigin:o}=r??n(),a=new URL("/ar/index.html",o);return a.searchParams.set("tinuuid",e),t&&a.searchParams.set("hid",t),i&&a.searchParams.set("appview","true"),a.toString()}function p(){let e=new WeakMap;return function(t){let i=e.get(t);i?.cleanup?.();let r={revision:(i?.revision??0)+1};return e.set(t,r),{isCurrent:()=>e.get(t)===r,register(i){let n=!1,o=()=>{n||(n=!0,i())};return e.get(t)!==r?(o(),o):(r.cleanup=o,()=>{e.get(t)===r&&e.delete(t),o()})}}}}let f=0,b={arizo:{conjunction:"и",privacyLabel:"Политика конфиденциальности",privacyUrl:"https://arizo.ru/privacy-policy/",termsLabel:"Условия использования",termsUrl:"https://arizo.ru/terms-of-use/"},vizbl:{conjunction:"and",privacyLabel:"Privacy Policy",privacyUrl:"https://vizbl.com/legal/privacy-policy",termsLabel:"Terms of Use",termsUrl:"https://vizbl.com/legal/terms-of-use"}};function v(){return window.QRCode}function w(e,t,i){let r=document.createElement("a");return r.dataset.vizblLegalLink=e,r.href=t,r.rel="noopener noreferrer",r.target="_blank",r.textContent=i,Object.assign(r.style,{color:"inherit",textDecoration:"underline",textUnderlineOffset:"2px",whiteSpace:"nowrap"}),r}async function y(e,r="vizblQrModal",o,a){let s,d=++f;i?.(),document.querySelectorAll("[data-vizbl-qr-modal]").forEach(e=>e.remove());let l=function(e){let{brand:t,viewerOrigin:i}=e??n(),r="arizo"===t,o=document.createElement("div");o.dataset.vizblQrModal="",o.setAttribute("aria-label","View object in augmented reality"),o.setAttribute("aria-modal","true"),o.setAttribute("role","dialog"),Object.assign(o.style,{alignItems:"center",backgroundColor:"rgba(0,0,0,0.25)",display:"none",height:"100%",justifyContent:"center",left:"0",position:"fixed",top:"0",width:"100%",zIndex:"9999"});let a=document.createElement("div");Object.assign(a.style,{backgroundColor:"#fff",borderRadius:"12px",boxSizing:"border-box",color:"#000",fontFamily:"Inter, sans-serif",minHeight:"372px",padding:"48px 52px 40px",position:"relative",width:"min(460px, calc(100vw - 32px))"});let s=document.createElement("button");s.type="button",s.dataset.vizblQrClose="",s.setAttribute("aria-label","Close QR code"),s.textContent="\xd7",Object.assign(s.style,{background:"none",border:"none",color:"#AEB1B7",cursor:"pointer",fontSize:"24px",position:"absolute",right:"20px",top:"20px"});let d=document.createElement("div");d.dataset.vizblQrCode="",d.style.margin="0 auto",d.style.width="fit-content";let l=document.createElement("p");l.textContent=r?"Отсканируйте этот QR-код камерой телефона, чтобы примерить объект в интерьере":"Scan this QR code with your phone camera to view the object in Augmented Reality",Object.assign(l.style,{fontSize:"16px",fontWeight:"500",lineHeight:"24px",margin:"24px 0 0",textAlign:"center"});let c=document.createElement("p");Object.assign(c.style,{color:"#93979F",fontSize:"12px",lineHeight:"16px",margin:"12px 0 0",textAlign:"center"});let u=b[t],g=w("terms",u.termsUrl,u.termsLabel),m=w("privacy",u.privacyUrl,u.privacyLabel);c.append(r?"*Требуется устройство и браузер с поддержкой AR. Рекомендуем iOS 12 или новее с Safari либо Android 7.0 или новее с Chrome.":"*Requires an AR-compatible device and browser. We recommend iOS 12 or later with Safari, or Android 7.0 or later with Chrome.",document.createElement("br"),g,` ${u.conjunction} `,m);let h=document.createElement("p");h.textContent=`Powered by ${r?"Arizo":"Vizbl"}`,Object.assign(h.style,{color:"#93979F",fontSize:"11px",letterSpacing:"1.5px",margin:"24px 0 4px",textAlign:"center",textTransform:"uppercase"});let p=document.createElement("a");p.dataset.vizblBrandLink="",p.href=r?"https://arizo.ru":"https://vizbl.com",p.style.display="block",p.style.textAlign="center";let f=document.createElement("img");return f.alt=`${r?"Arizo":"Vizbl"} logo`,f.src=`${i}/${r?"logoArizo.svg":"logo.svg"}`,f.height=20,f.width=r?76:60,p.appendChild(f),a.append(s,d,l,c,h,p),o.appendChild(a),o}(a);l.id=r;let c=l.querySelector("[data-vizbl-qr-close]"),u=Array.from(l.querySelectorAll("button, a[href]")),g=!1,m=e=>{if("Escape"===e.key){e.preventDefault(),s();return}if("Tab"!==e.key||0===u.length)return;let t=u[0],i=u.at(-1)??t;e.shiftKey&&(document.activeElement===t||!l.contains(document.activeElement))?(e.preventDefault(),i.focus()):e.shiftKey||document.activeElement!==i||(e.preventDefault(),t.focus())};i=s=()=>{g||(g=!0,document.removeEventListener("keydown",m),l.remove(),i===s&&(i=void 0),o?.focus({preventScroll:!0}))},c?.addEventListener("click",s),l.addEventListener("click",e=>{e.target===l&&s()}),document.body.appendChild(l),document.addEventListener("keydown",m),function(){let e="https://fonts.googleapis.com/css2?family=Inter&display=swap";if(Array.from(document.querySelectorAll('link[rel="stylesheet"]')).some(t=>t.href===e||t.getAttribute("href")===e))return;let t=document.createElement("link");t.rel="stylesheet",t.href=e,document.head.appendChild(t)}();try{let i=await function(e){let i=v();if(i)return Promise.resolve(i);if(t)return t;let{qrCodeScriptUrl:r}=e??n();return t=new Promise((e,i)=>{let n,o=document.createElement("script"),a=()=>{n();let r=v();r?e(r):(o.remove(),t=void 0,i(Error("QR code runtime did not expose QRCode")))},s=()=>{n(),o.remove(),t=void 0,i(Error("Failed to load QR code runtime"))};n=()=>{o.removeEventListener("load",a),o.removeEventListener("error",s)},o.addEventListener("load",a,{once:!0}),o.addEventListener("error",s,{once:!0}),o.src=r,o.async=!0,o.dataset.vizblQrScript="true",document.head.appendChild(o)})}(a);if(d!==f||!l.isConnected)return s(),s;let r=l.querySelector("[data-vizbl-qr-code]");return r&&new i(r,{correctLevel:i.CorrectLevel.L,height:148,text:e,width:148}),l.style.display="flex",c?.focus({preventScroll:!0}),s}catch(e){throw s(),e}}class E extends Error{code;constructor(e){super(e),this.code=e,this.name="WidgetRuntimeError"}}function A(e){return e.runtimeConfig??n()}function C(e,t,i={}){let r=new URL(t,e);for(let[e,t]of Object.entries(i))t&&r.searchParams.set(e,t);return r.toString()}async function I(e,t,i){try{return await (i.fetchImpl??i.runtimeConfig?.fetchImpl??n().fetchImpl)(e,{...t,signal:i.signal})}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)throw e;throw new E("NETWORK_ERROR")}}async function x(e){try{let t=await e.json();return[t.code,t.error,t.message].flatMap(e=>Array.isArray(e)?e:[e]).filter(e=>"string"==typeof e).join(" ").toLowerCase()}catch{return""}}async function O(e,t){let i=await x(e);return new E(429===e.status?"RATE_LIMITED":e.status>=500?"API_UNAVAILABLE":404===e.status&&"object"===t?"OBJECT_NOT_FOUND":i.includes("domain")||i.includes("origin")?"DOMAIN_NOT_ALLOWED":i.includes("revoked")?"KEY_REVOKED":i.includes("expired")?"activation"===t?"KEY_EXPIRED":"SESSION_EXPIRED":i.includes("policy")||i.includes("not available for this object")?"POLICY_DENIED":401===e.status||403===e.status?"activation"===t?"INVALID_KEY":"SESSION_EXPIRED":"REQUEST_FAILED")}async function S(e){try{return await e.json()}catch{throw new E("INVALID_RESPONSE")}}function k(e){if(!e||"object"!=typeof e||"string"!=typeof e.token||!e.token.trim()||"string"!=typeof e.sid||!e.sid.trim()||"number"!=typeof e.expiresIn||!Number.isFinite(e.expiresIn)||e.expiresIn<=0)throw new E("INVALID_RESPONSE");return e}async function T(e,t={}){let{apiOrigin:i}=A(t),r=await I(C(i,"/public/widget/activate-core",{mode:t.mode}),{cache:"no-store",headers:{"x-api-key":e},method:"POST"},t);if(!r.ok)throw await O(r,"activation");let n=await S(r);if("string"!=typeof n.productType)throw new E("INVALID_RESPONSE");return{...k(n.widgetSession),productType:n.productType}}async function L(e,t,i={}){let{apiOrigin:r}=A(i),n=await I(`${r}/public/widget/token`,{body:JSON.stringify({token:t,...i.mode?{mode:i.mode}:{}}),cache:"no-store",headers:{"Content-Type":"application/json","x-api-key":e},method:"POST"},i);if(!n.ok)throw await O(n,"token");return k(await S(n))}async function z(e,t,i={}){let{apiOrigin:r}=A(i),n=await I(C(r,`/public/objects/by-tinuuid/${encodeURIComponent(e)}`,{variantId:i.variantId}),{cache:"no-store",headers:{"x-widget-session-token":t},method:"GET"},i);if(!n.ok)throw await O(n,"object");let o=await S(n);if(!o||"object"!=typeof o||Array.isArray(o))throw new E("INVALID_RESPONSE");return o}async function R(e,t,i,r={}){let{apiOrigin:n}=A(r),o=await I(`${n}/public/widget/events`,{body:JSON.stringify({event:e,...i?{objectId:i}:{},...r.variantId?{variantId:r.variantId}:{},timestamp:new Date().toISOString()}),cache:"no-store",headers:{"Content-Type":"application/json","x-widget-session-token":t},keepalive:!0,method:"POST"},r);if(!o.ok)throw await O(o,"event");let a=await S(o);if(!a||"object"!=typeof a||Array.isArray(a)||"boolean"!=typeof a.ok)throw new E("INVALID_RESPONSE")}async function N(e,t,i){let r=i??n(),{fetchImpl:o,legacyApiOrigin:a}=r,s=await I(`${a}/obj/Fetch`,{body:JSON.stringify({tinuuid:e}),headers:{"Content-Type":"application/json"},method:"POST"},{fetchImpl:o,runtimeConfig:r,signal:t});if(!s.ok)throw await O(s,"object");let d=await S(s);if(!d||"object"!=typeof d||Array.isArray(d))throw new E("INVALID_RESPONSE");return d}async function P(e,t){let{fetchImpl:i,legacyApiOrigin:r}=t??n();await i(`${r}/obj/IncrViews`,{body:JSON.stringify({tinuuid:e}),headers:{"Content-Type":"application/json"},method:"POST"})}function D(e){try{let t=e?.();t instanceof Promise&&t.catch(()=>void 0)}catch{}}let j=p();function _(e){if(e?.aborted)throw new DOMException("Aborted","AbortError")}async function U(e,t={}){let i,r,n=j(e),o=e.getAttribute("data-native-link"),c=e.dataset.objectTinuuid?.trim(),p=e.dataset.objectHid?.trim()||void 0;if(!c)throw Error("Object ID is required");_(t.signal);let f=t.loadObject??((e,i)=>N(e,i,t.runtimeConfig)),b=t.object??await f(c,t.signal);if(_(t.signal),!n.isCurrent())return()=>void 0;let v=p?b.materials.find(e=>e.hid===p):b.materials[0];if(!v?.native?.glbUrl||!v.native.usdzUrl)throw Error("Native AR assets are unavailable");let w=u(v.native,b.type),E=s(),A=!1,C=0;e.querySelector("img")||((i=document.createElement("img")).alt="",i.hidden=!0,e.appendChild(i));let I=()=>t.trackView?t.trackView():P(c,t.runtimeConfig),x=i=>{i.preventDefault();let o=++C;r?.(),r=void 0,Promise.resolve(t.getDesktopQrUrl?.()??h(c,p,!0,t.runtimeConfig)).then(i=>{if(o===C&&n.isCurrent())return D(()=>t.onAction?.("interacted")),y(i,`vizbl-${c}`,e,t.runtimeConfig)}).then(e=>{if(e){if(o!==C||!n.isCurrent())return void e();r=e}}).catch(()=>void 0)},O=async e=>{let i;if(i=d().toLowerCase(),["firefox","edge","opera"].some(e=>i.includes(e))){if(e.preventDefault(),A)return;A=!0,D(()=>t.onAction?.("ar_launched"));try{await Promise.resolve(I()).catch(()=>void 0)}finally{A=!1,a()&&l()?m(c,p,t.runtimeConfig):g(w)}return}D(()=>t.onAction?.("ar_launched")),D(I),a()&&l()?(e.preventDefault(),m(c,p,t.runtimeConfig)):g(w)};return E?(e.dataset.nativeLink=w,e.addEventListener("click",O)):e.addEventListener("click",x),n.register(()=>{C+=1,e.removeEventListener("click",x),e.removeEventListener("click",O),r?.(),i?.remove(),null===o?e.removeAttribute("data-native-link"):e.setAttribute("data-native-link",o)})}var V=!1;if("u">typeof window){var M={get passive(){V=!0;return}};window.addEventListener("testPassive",null,M),window.removeEventListener("testPassive",null,M)}var $="u">typeof window&&window.navigator&&window.navigator.platform&&(/iP(ad|hone|od)/.test(window.navigator.platform)||"MacIntel"===window.navigator.platform&&window.navigator.maxTouchPoints>1),B=[],q=!1,H=-1,W=void 0,F=void 0,K=void 0,Q=function(e){return B.some(function(t){return!!(t.options.allowTouchMove&&t.options.allowTouchMove(e))})},Y=function(e){var t=e||window.event;return!!Q(t.target)||t.touches.length>1||(t.preventDefault&&t.preventDefault(),!1)},X=function(e){if(void 0===K){var t=!!e&&!0===e.reserveScrollBarGap,i=window.innerWidth-document.documentElement.clientWidth;if(t&&i>0){var r=parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"),10);K=document.body.style.paddingRight,document.body.style.paddingRight=r+i+"px"}}void 0===W&&(W=document.body.style.overflow,document.body.style.overflow="hidden")},J=function(){void 0!==K&&(document.body.style.paddingRight=K,K=void 0),void 0!==W&&(document.body.style.overflow=W,W=void 0)},Z=function(){if(void 0!==F){var e=-parseInt(document.body.style.top,10),t=-parseInt(document.body.style.left,10);document.body.style.position=F.position,document.body.style.top=F.top,document.body.style.left=F.left,window.scrollTo(t,e),F=void 0}},G=function(e,t){var i=e.targetTouches[0].clientY-H;return!Q(e.target)&&(t&&0===t.scrollTop&&i>0?Y(e):t&&t.scrollHeight-t.scrollTop<=t.clientHeight&&i<0?Y(e):(e.stopPropagation(),!0))},ee=function(e,t){e?!B.some(function(t){return t.targetElement===e})&&(B=[].concat(function(e){if(!Array.isArray(e))return Array.from(e);for(var t=0,i=Array(e.length);t<e.length;t++)i[t]=e[t];return i}(B),[{targetElement:e,options:t||{}}]),$?window.requestAnimationFrame(function(){if(void 0===F){F={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left};var e=window,t=e.scrollY,i=e.scrollX,r=e.innerHeight;document.body.style.position="fixed",document.body.style.top=-t,document.body.style.left=-i,setTimeout(function(){return window.requestAnimationFrame(function(){var e=r-window.innerHeight;e&&t>=r&&(document.body.style.top=-(t+e))})},300)}}):X(t),$&&(e.ontouchstart=function(e){1===e.targetTouches.length&&(H=e.targetTouches[0].clientY)},e.ontouchmove=function(t){1===t.targetTouches.length&&G(t,e)},q||(document.addEventListener("touchmove",Y,V?{passive:!1}:void 0),q=!0))):console.error("disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.")},et=function(e){e?(B=B.filter(function(t){return t.targetElement!==e}),$&&(e.ontouchstart=null,e.ontouchmove=null,q&&0===B.length&&(document.removeEventListener("touchmove",Y,V?{passive:!1}:void 0),q=!1)),$?Z():J()):console.error("enableBodyScroll unsuccessful - targetElement must be provided when calling enableBodyScroll on IOS devices.")};let ei=["cm","inch"],er=["x","y","z"],en=[...er],eo="vizbl_viewer",ea=p();function es(e){return e&&ei.includes(e)?e:"inch"}function ed(e){if(!e)return en;let t=Array.from(new Set(e.split(",").map(e=>e.trim().toLowerCase()).filter(e=>er.includes(e))));return t.length>0?t:en}function el(e){let t=new URL("/model-viewer",e.modelViewerOrigin??n().modelViewerOrigin),i=e.dimensionAxes??en;t.searchParams.set("tinuuid",e.tinuuid),e.hid&&t.searchParams.set("hid",e.hid),t.searchParams.set("size-type",e.sizeType),i.length<en.length&&t.searchParams.set("dimension-axes",i.join(",")),e.cameraOrbit&&t.searchParams.set("camera-orbit",e.cameraOrbit),e.minCameraOrbit&&t.searchParams.set("min-camera-orbit",e.minCameraOrbit),e.maxCameraOrbit&&t.searchParams.set("max-camera-orbit",e.maxCameraOrbit);let r=new URLSearchParams;return e.apiKey&&r.set("api-key",e.apiKey),e.mode&&r.set("mode",e.mode),e.widgetSessionToken&&r.set("widget-session-token",e.widgetSessionToken),t.hash=r.toString(),t.toString()}let ec=p();function eu(e){if(e?.aborted)throw new DOMException("Aborted","AbortError")}async function eg(e,t={}){let i,r,n=ec(e),o=e.getAttribute("href"),a=e.getAttribute("rel"),d=e.dataset.objectTinuuid?.trim(),l=e.dataset.objectHid?.trim()||void 0;if(!d)throw Error("Object ID is required");eu(t.signal);let c=t.loadObject??((e,i)=>N(e,i,t.runtimeConfig)),g=t.object??await c(d,t.signal);if(eu(t.signal),!n.isCurrent())return()=>void 0;let m=l?g.materials.find(e=>e.hid===l):g.materials[0];if(!m?.native?.glbUrl||!m.native.usdzUrl)throw Error("Native AR assets are unavailable");let p=u(m.native,g.type),f=s(),b=0;e.rel="ar",e.querySelector("img")||((i=document.createElement("img")).alt="",i.hidden=!0,e.appendChild(i));let v=i=>{i.preventDefault();let o=++b;r?.(),r=void 0,Promise.resolve(t.getDesktopQrUrl?.()??h(d,l,!1,t.runtimeConfig)).then(i=>{if(o===b&&n.isCurrent())return D(()=>t.onAction?.("interacted")),y(i,`vizbl-${d}`,e,t.runtimeConfig)}).then(e=>{if(e){if(o!==b||!n.isCurrent())return void e();r=e}}).catch(()=>void 0)},w=()=>{D(t.trackView??(()=>P(d,t.runtimeConfig))),D(()=>t.onAction?.("ar_launched"))};return f?(e.href=p,e.addEventListener("click",w)):(e.href="#",e.addEventListener("click",v)),n.register(()=>{b+=1,e.removeEventListener("click",v),e.removeEventListener("click",w),r?.(),i?.remove(),null===o?e.removeAttribute("href"):e.setAttribute("href",o),null===a?e.removeAttribute("rel"):e.setAttribute("rel",a)})}let em=["advanced-ar","ar-one-click","ar-viewer"],eh={arizo:"arizo-core",vizbl:"vizbl-core"},ep=new Set(["core-ar","core-ar-shopify"]),ef={"advanced-ar":"View in advanced AR","ar-one-click":"View in AR","ar-viewer":"View in 3D & AR"},eb={"advanced-ar":"advanced-ar-view","ar-one-click":"ar-view","ar-viewer":"ar-viewer"},ev=["api-key","camera-orbit","dev","dimension-axes","max-camera-orbit","min-camera-orbit","object-id","size-type","trigger-class","type","variant-id"],ew=new Set(["API_UNAVAILABLE","INVALID_RESPONSE","NETWORK_ERROR","REQUEST_FAILED","SESSION_EXPIRED"]),ey="core-ar-widget-styles";class eE extends Error{code;constructor(e){super(e),this.code=e,this.name="CoreArWidgetComponentError"}}function eA(e){return em.includes(e)}function eC(e,t){let i=Array.isArray(e.materials)?e.materials:[],r=t?i.find(e=>e.hid===t):i[0];if(!r)throw new eE(t?"VARIANT_NOT_FOUND":"MODEL_UNAVAILABLE");return r}function eI(e,t){if("ar-one-click"===e&&t.policy?.instantArView===!1)throw new eE("POLICY_DENIED")}let ex="u"<typeof HTMLElement?class{}:HTMLElement;class eO extends ex{static get observedAttributes(){return[...ev]}get triggerClass(){return this.getAttribute("trigger-class")??""}set triggerClass(e){let t="string"==typeof e?e.trim():"";t?this.setAttribute("trigger-class",t):this.removeAttribute("trigger-class")}get unstyled(){return this.hasAttribute("unstyled")}set unstyled(e){this.toggleAttribute("unstyled",!!e)}abortController;actionResetTimer;cleanup;customLabelNodes=null;initializationRevision=0;object;queued=!1;session;trigger;variantId;widgetMode;connectedCallback(){!function(){if(document.getElementById(ey))return;let e=document.createElement("style");e.id=ey,e.textContent=`
|
|
2
2
|
:where(vizbl-core, arizo-core) {
|
|
3
3
|
display: inline-block;
|
|
4
4
|
--core-ar-widget-background: #3556f0;
|
|
@@ -65,4 +65,4 @@
|
|
|
65
65
|
:where(vizbl-core, arizo-core)[data-state="error"] [data-core-ar-widget-trigger] {
|
|
66
66
|
cursor: not-allowed;
|
|
67
67
|
}
|
|
68
|
-
`,document.head.appendChild(e)}(),this.captureCustomLabel(),this.queueInitialization()}disconnectedCallback(){this.initializationRevision+=1,this.abortController?.abort(),this.abortController=void 0,this.cleanup?.(),this.cleanup=void 0,this.clearActionResetTimer()}attributeChangedCallback(e,t,i){if(t!==i){if("trigger-class"===e)return void this.applyTriggerClass();("api-key"===e||"dev"===e)&&(this.session=void 0),this.isConnected&&(this.abortController?.abort(),this.cleanup?.(),this.cleanup=void 0,this.setState("loading"),this.queueInitialization())}}captureCustomLabel(){if(null!==this.customLabelNodes)return;let e=Array.from(this.childNodes),t=e.some(e=>e.nodeType!==Node.TEXT_NODE||!!e.textContent?.trim());this.customLabelNodes=t?e:[]}queueInitialization(){this.queued||(this.queued=!0,queueMicrotask(()=>{this.queued=!1,this.isConnected&&this.initialize()}))}async initialize(){let e=++this.initializationRevision;this.abortController?.abort(),this.cleanup?.(),this.cleanup=void 0,this.object=void 0,this.variantId=void 0,this.widgetMode=void 0,this.clearActionResetTimer();let t=new AbortController;this.abortController=t;let i=this.getAttribute("type")?.trim()??"",r=eA(i)?i:"ar-viewer",n=this.getAttribute("object-id")?.trim()??"",o=this.getAttribute("variant-id")?.trim()||void 0,a=this.getAttribute("api-key")?.trim()??"",l=this.getAttribute("size-type")?.trim()||void 0,d=this.getAttribute("dimension-axes")?.trim()||void 0;this.removeAttribute("data-error-code"),this.setState("loading"),this.renderTrigger(r);try{let r,c=this.resolveRuntimeConfig();if(!a)throw new eE("MISSING_API_KEY");if(!n)throw new eE("MISSING_OBJECT_ID");if(!eA(i))throw new eE("INVALID_TYPE");if("ar-viewer"===i&&l&&"cm"!==l&&"inch"!==l)throw new eE("INVALID_SIZE_TYPE");let u=ev[i],g=await this.ensureSession(a,c,u,t.signal);if(this.assertCurrent(e,t.signal),this.variantId=o,this.widgetMode=u,this.applyIntegrationData(n,o,l,d),"ar-viewer"===i)r=await N(n,t.signal,c),this.assertCurrent(e,t.signal),eI(r,o),eC(i,r),this.object=r;else{r=s()?await this.fetchObjectWithSession(n,a,g,c,t.signal,o):await N(n,t.signal,c),this.assertCurrent(e,t.signal);let l=eI(r,o);if(eC(i,r),!l.native?.glbUrl||!l.native.usdzUrl)throw new eE("MODEL_UNAVAILABLE");this.object=r}let h=await this.initializeTrigger(i,r,c,t.signal,a,g);try{this.assertCurrent(e,t.signal)}catch(e){throw h(),e}this.cleanup=h,this.setState("ready"),this.dispatchWidgetEvent("core-ar-ready",{objectId:n,type:i})}catch(o){if(e!==this.initializationRevision||t.signal.aborted||o instanceof DOMException&&"AbortError"===o.name)return;let r=o instanceof eE||o instanceof E?o.code:"INITIALIZATION_FAILED";this.setAttribute("data-error-code",r),this.setState("error"),this.dispatchWidgetEvent("core-ar-error",{code:r,objectId:n,type:i})}}async ensureSession(e,t,i,r,n=!1){let o=`${t.apiOrigin}|${t.viewerOrigin}|${t.modelViewerOrigin}|${i}`,a=this.session?.publicKey===e&&this.session.runtimeKey===o?this.session:void 0;if(a&&!n&&a.expiresAt-Date.now()>3e4)return a;if(a)try{let i=await z(e,a.token,{mode:a.mode,runtimeConfig:t,signal:r}),n={...a,...i,expiresAt:Date.now()+1e3*i.expiresIn};return this.session=n,n}catch(e){if(!(e instanceof E)||!eb.has(e.code))throw e;this.session=void 0}let s=await L(e,{mode:i,runtimeConfig:t,signal:r});if(!ep.has(s.productType))throw new eE("POLICY_DENIED");let l={expiresAt:Date.now()+1e3*s.expiresIn,mode:i,productType:s.productType,publicKey:e,runtimeKey:o,sid:s.sid,token:s.token};return this.session=l,l}async fetchObjectWithSession(e,t,i,r,n,o){try{return await O(e,i.token,{runtimeConfig:r,signal:n,variantId:o})}catch(a){if(!(a instanceof E)||"SESSION_EXPIRED"!==a.code)throw a;return O(e,(await this.ensureSession(t,r,i.mode,n,!0)).token,{runtimeConfig:r,signal:n,variantId:o})}}assertCurrent(e,t){if(e!==this.initializationRevision||t.aborted)throw new DOMException("Aborted","AbortError")}renderTrigger(e){let t="ar-one-click"===e?document.createElement("a"):document.createElement("button");if(t.dataset.coreArWidgetTrigger="",t.setAttribute("part","trigger"),t.addEventListener("click",e=>{"ready"!==this.dataset.state&&(e.preventDefault(),e.stopImmediatePropagation())}),t instanceof HTMLButtonElement&&(t.type="button"),t instanceof HTMLAnchorElement&&(t.href="#",t.rel="ar"),"ar-viewer"===e&&t.setAttribute("aria-haspopup","dialog"),"ar-viewer"!==e){let e=document.createElement("img");e.alt="",e.hidden=!0,t.appendChild(e)}let i=document.createElement("span");i.dataset.coreArWidgetLabel="",this.customLabelNodes?.length?i.append(...this.customLabelNodes):i.textContent=ef[e],t.appendChild(i),this.trigger=t,this.applyTriggerClass(),this.replaceChildren(t),this.updateTriggerAccessibility(this.dataset.state)}applyTriggerClass(){if(!this.trigger)return;let e=this.triggerClass.trim();e?this.trigger.className=e:this.trigger.removeAttribute("class")}applyIntegrationData(e,t,i,r){this.trigger&&(this.trigger.dataset.objectTinuuid=e,t?this.trigger.dataset.objectHid=t:delete this.trigger.dataset.objectHid,i?this.trigger.dataset.sizeType=i:delete this.trigger.dataset.sizeType,r?this.trigger.dataset.dimensionAxes=r:delete this.trigger.dataset.dimensionAxes)}async initializeTrigger(e,t,i,r,n,o){if(!this.trigger)throw new eE("INITIALIZATION_FAILED");if("ar-viewer"===e)return function(e,t={}){let i,r=ea(e),n=!1,o=async()=>{if(i||n)return;let o=e.dataset.objectTinuuid?.trim();if(!o)return;n=!0;let a=t.widgetSessionToken;try{t.getWidgetSessionToken&&(a=await t.getWidgetSessionToken())}catch{n=!1;return}if(n=!1,i||!r.isCurrent())return;let s=function(e){var t,i,r,n;let o,a,s;if(document.getElementById(eo))return null;let l=document.createElement("div"),d=document.createElement("div"),c=document.createElement("div"),u=e.containerClassName?document.getElementsByClassName(e.containerClassName)[0]:null,g=!!u,h=g?d:l,m=!1,p=e=>{"Escape"===e.key&&o()};o=()=>{m||(m=!0,document.removeEventListener("keydown",p),et(h),(g?d:l).remove(),e.onClose?.(),e.restoreFocusTo?.focus({preventScroll:!0}))},l.id=eo,Object.assign(l.style,{inset:"0",overflow:"auto",position:"fixed",zIndex:"11111"}),l.style.webkitOverflowScrolling="touch",d.setAttribute("role","dialog"),d.setAttribute("aria-modal","true"),d.setAttribute("aria-label","3D model viewer"),Object.assign(c.style,{animation:"vex-fadein 0.5s",background:"#fff",inset:"0",position:"fixed",zIndex:"11111"}),c.addEventListener("click",o),(e.width||e.height)&&(c.style.background="rgba(0, 0, 0, 0.8)",Object.assign(d.style,{borderRadius:"12px",height:e.height??"100%",left:"50%",overflow:"hidden",position:"absolute",top:"50%",transform:"translate(-50%, -50%)",width:e.width??"100%",zIndex:"11112"}));let f=(t=e.crossClassName,i=o,(a=document.createElement("button")).type="button",a.setAttribute("aria-label","Close 3D model viewer"),t&&(a.className=t),Object.assign(a.style,{alignItems:"center",background:"#fff",border:"1px solid #E3E7E7",borderRadius:"4px",boxSizing:"border-box",cursor:"pointer",display:"flex",height:"40px",inset:"24px 24px auto auto",justifyContent:"center",padding:"8px 16px",position:"absolute",width:"56px",zIndex:"11113"}),a.innerHTML='<svg aria-hidden="true" style="flex-shrink:0" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z" fill="#484D50"/></svg>',a.addEventListener("click",i),a);return d.append((r=ed(e),n=e.backgroundColor,(s=document.createElement("iframe")).src=r,s.title="3D model viewer",s.allow="fullscreen; xr-spatial-tracking",Object.assign(s.style,{backgroundColor:n??"white",border:"none",height:"100%",inset:"0",position:"absolute",width:"100%",zIndex:"11112"}),s),f),u?(d.id=eo,u.appendChild(d)):(l.append(c,d),document.body.appendChild(l)),document.addEventListener("keydown",p),ee(h),f.focus({preventScroll:!0}),o}({apiKey:t.apiKey,backgroundColor:e.dataset.background,buttonBgColor:e.dataset.buttonBgColor,buttonBorderColor:e.dataset.buttonBorderColor,buttonTextColor:e.dataset.buttonTextColor,containerClassName:e.dataset.container,crossClassName:e.dataset.crossClassName,dimensionAxes:el(e.dataset.dimensionAxes),height:e.dataset.height?.trim(),hid:e.dataset.objectHid,hidePreview:e.dataset.hidePreview,hideTitle:e.dataset.hideTitle,mode:t.mode,modelViewerOrigin:t.modelViewerOrigin,onClose:()=>{i=void 0,t.onClose?.()},restoreFocusTo:e,sizeType:es(e.dataset.sizeType),tinuuid:o,widgetSessionToken:a,width:e.dataset.width?.trim()});s&&(i=s,t.onOpen?.(),P(()=>t.onAction?.("widget_opened")))};return e.addEventListener("click",o),r.register(()=>{e.removeEventListener("click",o),i?.(),i=void 0})}(this.trigger,{apiKey:n,getWidgetSessionToken:async()=>(await this.ensureSession(n,i,o.mode)).token,mode:o.mode,modelViewerOrigin:i.modelViewerOrigin,onAction:e=>this.handleAction(e,i),onClose:()=>{this.isConnected&&this.setState("ready")},onOpen:()=>this.setState("opening"),widgetSessionToken:o.token});if(!t)throw new eE("INITIALIZATION_FAILED");let a={getDesktopQrUrl:async()=>{let e=await this.ensureSession(n,i,o.mode);return ed({apiKey:n,dimensionAxes:el(this.trigger?.dataset.dimensionAxes),hid:this.variantId,mode:e.mode,modelViewerOrigin:i.modelViewerOrigin,sizeType:es(this.trigger?.dataset.sizeType),tinuuid:this.trigger?.dataset.objectTinuuid??"",widgetSessionToken:e.token})},object:t,onAction:e=>this.handleAction(e,i),runtimeConfig:i,signal:r,trackView:()=>this.trackEvent("ar_launched",i)};if("ar-one-click"===e){if(!(this.trigger instanceof HTMLAnchorElement))throw new eE("INITIALIZATION_FAILED");return eg(this.trigger,a)}return U(this.trigger,a)}handleAction(e,t){this.setState("opening"),("interacted"===e||"widget_opened"===e)&&"ar-viewer"!==this.getAttribute("type")&&this.trackEvent(e,t),"ar-viewer"!==this.getAttribute("type")&&(this.clearActionResetTimer(),this.actionResetTimer=window.setTimeout(()=>{this.isConnected&&this.setState("ready")},300))}async trackEvent(e,t){let i=this.getAttribute("api-key")?.trim(),r=this.widgetMode;if(i&&r&&this.isConnected)try{let n=await this.ensureSession(i,t,r);await R(e,n.token,this.object?.uuid,{runtimeConfig:t,variantId:this.variantId})}catch{}}clearActionResetTimer(){void 0!==this.actionResetTimer&&(window.clearTimeout(this.actionResetTimer),this.actionResetTimer=void 0)}setState(e){this.dataset.state=e,this.updateTriggerAccessibility(e)}updateTriggerAccessibility(e){if(!this.trigger)return;let t="ready"===e;this.trigger.setAttribute("aria-busy",String("loading"===e)),this.trigger.setAttribute("aria-disabled",String(!t)),this.trigger.tabIndex=t?0:-1,this.trigger instanceof HTMLButtonElement&&(this.trigger.disabled=!t)}dispatchWidgetEvent(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}}function ex(e){if("u"<typeof customElements)return;let t=em[e],i=customElements.get(t);if(i)return i;class n extends ek{resolveRuntimeConfig(){return function(e,t="prod"){var i,n;let o,a,s,l,d,c,u,g,h="arizo"===e?"arizo.ru":"vizbl.com",m="dev"===t?"-dev":"";return o=r((i={apiOrigin:`https://api${m}.${h}`,modelViewerOrigin:`https://integrations${m}.${h}`,viewerOrigin:`https://viewer${m}.${h}`}).apiOrigin,"apiOrigin"),a=r(i.viewerOrigin,"viewerOrigin"),d=i.modelViewerOrigin?r(i.modelViewerOrigin,"modelViewerOrigin"):(l=(s=new URL(a)).hostname.match(/^viewer(-dev)?\.(vizbl\.com|arizo\.ru)$/))?`${s.protocol}//integrations${l[1]??""}.${l[2]}`:a,g=i.legacyApiOrigin?(c=r(n=i.legacyApiOrigin,"legacyApiOrigin"),(u=new URL(n).pathname.replace(/\/+$/,""))?`${c}${u}`:c):`${o}/v1`,{apiOrigin:o,brand:new URL(a).hostname.endsWith("arizo.ru")?"arizo":"vizbl",fetchImpl:i.fetchImpl??fetch,legacyApiOrigin:g,modelViewerOrigin:d,qrCodeScriptUrl:i.qrCodeScriptUrl??`${a}/vendor/qrcode.min.js`,viewerOrigin:a}}(e,this.hasAttribute("dev")?"dev":"prod")}}return customElements.define(t,n),n}ex("arizo"),ex("vizbl")})();
|
|
68
|
+
`,document.head.appendChild(e)}(),this.captureCustomLabel(),this.queueInitialization()}disconnectedCallback(){this.initializationRevision+=1,this.abortController?.abort(),this.abortController=void 0,this.cleanup?.(),this.cleanup=void 0,this.clearActionResetTimer()}attributeChangedCallback(e,t,i){if(t!==i){if("trigger-class"===e)return void this.applyTriggerClass();("api-key"===e||"dev"===e)&&(this.session=void 0),this.isConnected&&(this.abortController?.abort(),this.cleanup?.(),this.cleanup=void 0,this.setState("loading"),this.queueInitialization())}}captureCustomLabel(){if(null!==this.customLabelNodes)return;let e=Array.from(this.childNodes),t=e.some(e=>e.nodeType!==Node.TEXT_NODE||!!e.textContent?.trim());this.customLabelNodes=t?e:[]}queueInitialization(){this.queued||(this.queued=!0,queueMicrotask(()=>{this.queued=!1,this.isConnected&&this.initialize()}))}async initialize(){let e=++this.initializationRevision;this.abortController?.abort(),this.cleanup?.(),this.cleanup=void 0,this.object=void 0,this.variantId=void 0,this.widgetMode=void 0,this.clearActionResetTimer();let t=new AbortController;this.abortController=t;let i=this.getAttribute("type")?.trim()??"",r=eA(i)?i:"ar-viewer",n=this.getAttribute("object-id")?.trim()??"",o=this.getAttribute("variant-id")?.trim()||void 0,a=this.getAttribute("api-key")?.trim()??"",d=this.getAttribute("size-type")?.trim()||void 0,l=this.getAttribute("dimension-axes")?.trim()||void 0,c=this.getAttribute("camera-orbit")?.trim()||void 0,u=this.getAttribute("min-camera-orbit")?.trim()||void 0,g=this.getAttribute("max-camera-orbit")?.trim()||void 0;this.removeAttribute("data-error-code"),this.setState("loading"),this.renderTrigger(r);try{let r,m=this.resolveRuntimeConfig();if(!a)throw new eE("MISSING_API_KEY");if(!n)throw new eE("MISSING_OBJECT_ID");if(!eA(i))throw new eE("INVALID_TYPE");if("ar-viewer"===i&&d&&"cm"!==d&&"inch"!==d)throw new eE("INVALID_SIZE_TYPE");let h=eb[i],p=await this.ensureSession(a,m,h,t.signal);if(this.assertCurrent(e,t.signal),this.variantId=o,this.widgetMode=h,this.applyIntegrationData(n,o,d,l,c,u,g),"ar-viewer"===i)r=await N(n,t.signal,m),this.assertCurrent(e,t.signal),eC(r,o),eI(i,r),this.object=r;else{r=s()?await this.fetchObjectWithSession(n,a,p,m,t.signal,o):await N(n,t.signal,m),this.assertCurrent(e,t.signal);let d=eC(r,o);if(eI(i,r),!d.native?.glbUrl||!d.native.usdzUrl)throw new eE("MODEL_UNAVAILABLE");this.object=r}let f=await this.initializeTrigger(i,r,m,t.signal,a,p);try{this.assertCurrent(e,t.signal)}catch(e){throw f(),e}this.cleanup=f,this.setState("ready"),this.dispatchWidgetEvent("core-ar-ready",{objectId:n,type:i})}catch(o){if(e!==this.initializationRevision||t.signal.aborted||o instanceof DOMException&&"AbortError"===o.name)return;let r=o instanceof eE||o instanceof E?o.code:"INITIALIZATION_FAILED";this.setAttribute("data-error-code",r),this.setState("error"),this.dispatchWidgetEvent("core-ar-error",{code:r,objectId:n,type:i})}}async ensureSession(e,t,i,r,n=!1){let o=`${t.apiOrigin}|${t.viewerOrigin}|${t.modelViewerOrigin}|${i}`,a=this.session?.publicKey===e&&this.session.runtimeKey===o?this.session:void 0;if(a&&!n&&a.expiresAt-Date.now()>3e4)return a;if(a)try{let i=await L(e,a.token,{mode:a.mode,runtimeConfig:t,signal:r}),n={...a,...i,expiresAt:Date.now()+1e3*i.expiresIn};return this.session=n,n}catch(e){if(!(e instanceof E)||!ew.has(e.code))throw e;this.session=void 0}let s=await T(e,{mode:i,runtimeConfig:t,signal:r});if(!ep.has(s.productType))throw new eE("POLICY_DENIED");let d={expiresAt:Date.now()+1e3*s.expiresIn,mode:i,productType:s.productType,publicKey:e,runtimeKey:o,sid:s.sid,token:s.token};return this.session=d,d}async fetchObjectWithSession(e,t,i,r,n,o){try{return await z(e,i.token,{runtimeConfig:r,signal:n,variantId:o})}catch(a){if(!(a instanceof E)||"SESSION_EXPIRED"!==a.code)throw a;return z(e,(await this.ensureSession(t,r,i.mode,n,!0)).token,{runtimeConfig:r,signal:n,variantId:o})}}assertCurrent(e,t){if(e!==this.initializationRevision||t.aborted)throw new DOMException("Aborted","AbortError")}renderTrigger(e){let t="ar-one-click"===e?document.createElement("a"):document.createElement("button");if(t.dataset.coreArWidgetTrigger="",t.setAttribute("part","trigger"),t.addEventListener("click",e=>{"ready"!==this.dataset.state&&(e.preventDefault(),e.stopImmediatePropagation())}),t instanceof HTMLButtonElement&&(t.type="button"),t instanceof HTMLAnchorElement&&(t.href="#",t.rel="ar"),"ar-viewer"===e&&t.setAttribute("aria-haspopup","dialog"),"ar-viewer"!==e){let e=document.createElement("img");e.alt="",e.hidden=!0,t.appendChild(e)}let i=document.createElement("span");i.dataset.coreArWidgetLabel="",this.customLabelNodes?.length?i.append(...this.customLabelNodes):i.textContent=ef[e],t.appendChild(i),this.trigger=t,this.applyTriggerClass(),this.replaceChildren(t),this.updateTriggerAccessibility(this.dataset.state)}applyTriggerClass(){if(!this.trigger)return;let e=this.triggerClass.trim();e?this.trigger.className=e:this.trigger.removeAttribute("class")}applyIntegrationData(e,t,i,r,n,o,a){this.trigger&&(this.trigger.dataset.objectTinuuid=e,t?this.trigger.dataset.objectHid=t:delete this.trigger.dataset.objectHid,i?this.trigger.dataset.sizeType=i:delete this.trigger.dataset.sizeType,r?this.trigger.dataset.dimensionAxes=r:delete this.trigger.dataset.dimensionAxes,n?this.trigger.dataset.cameraOrbit=n:delete this.trigger.dataset.cameraOrbit,o?this.trigger.dataset.minCameraOrbit=o:delete this.trigger.dataset.minCameraOrbit,a?this.trigger.dataset.maxCameraOrbit=a:delete this.trigger.dataset.maxCameraOrbit)}async initializeTrigger(e,t,i,r,n,o){if(!this.trigger)throw new eE("INITIALIZATION_FAILED");if("ar-viewer"===e)return function(e,t={}){let i,r=ea(e),n=!1,o=async()=>{if(i||n)return;let o=e.dataset.objectTinuuid?.trim();if(!o)return;n=!0;let a=t.widgetSessionToken;try{t.getWidgetSessionToken&&(a=await t.getWidgetSessionToken())}catch{n=!1;return}if(n=!1,i||!r.isCurrent())return;let s=function(e){var t,i,r,n;let o,a,s;if(document.getElementById(eo))return null;let d=document.createElement("div"),l=document.createElement("div"),c=document.createElement("div"),u=e.containerClassName?document.getElementsByClassName(e.containerClassName)[0]:null,g=!!u,m=g?l:d,h=!1,p=e=>{"Escape"===e.key&&o()};o=()=>{h||(h=!0,document.removeEventListener("keydown",p),et(m),(g?l:d).remove(),e.onClose?.(),e.restoreFocusTo?.focus({preventScroll:!0}))},d.id=eo,Object.assign(d.style,{inset:"0",overflow:"auto",position:"fixed",zIndex:"11111"}),d.style.webkitOverflowScrolling="touch",l.setAttribute("role","dialog"),l.setAttribute("aria-modal","true"),l.setAttribute("aria-label","3D model viewer"),Object.assign(c.style,{animation:"vex-fadein 0.5s",background:"#fff",inset:"0",position:"fixed",zIndex:"11111"}),c.addEventListener("click",o),(e.width||e.height)&&(c.style.background="rgba(0, 0, 0, 0.8)",Object.assign(l.style,{borderRadius:"12px",height:e.height??"100%",left:"50%",overflow:"hidden",position:"absolute",top:"50%",transform:"translate(-50%, -50%)",width:e.width??"100%",zIndex:"11112"}));let f=(t=e.crossClassName,i=o,(a=document.createElement("button")).type="button",a.setAttribute("aria-label","Close 3D model viewer"),t&&(a.className=t),Object.assign(a.style,{alignItems:"center",background:"#fff",border:"1px solid #E3E7E7",borderRadius:"4px",boxSizing:"border-box",cursor:"pointer",display:"flex",height:"40px",inset:"24px 24px auto auto",justifyContent:"center",padding:"8px 16px",position:"absolute",width:"56px",zIndex:"11113"}),a.innerHTML='<svg aria-hidden="true" style="flex-shrink:0" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z" fill="#484D50"/></svg>',a.addEventListener("click",i),a);return l.append((r=el(e),n=e.backgroundColor,(s=document.createElement("iframe")).src=r,s.title="3D model viewer",s.allow="fullscreen; xr-spatial-tracking",Object.assign(s.style,{backgroundColor:n??"white",border:"none",height:"100%",inset:"0",position:"absolute",width:"100%",zIndex:"11112"}),s),f),u?(l.id=eo,u.appendChild(l)):(d.append(c,l),document.body.appendChild(d)),document.addEventListener("keydown",p),ee(m),f.focus({preventScroll:!0}),o}({apiKey:t.apiKey,backgroundColor:e.dataset.background,buttonBgColor:e.dataset.buttonBgColor,buttonBorderColor:e.dataset.buttonBorderColor,buttonTextColor:e.dataset.buttonTextColor,cameraOrbit:e.dataset.cameraOrbit,containerClassName:e.dataset.container,crossClassName:e.dataset.crossClassName,dimensionAxes:ed(e.dataset.dimensionAxes),height:e.dataset.height?.trim(),hid:e.dataset.objectHid,hidePreview:e.dataset.hidePreview,hideTitle:e.dataset.hideTitle,maxCameraOrbit:e.dataset.maxCameraOrbit,minCameraOrbit:e.dataset.minCameraOrbit,mode:t.mode,modelViewerOrigin:t.modelViewerOrigin,onClose:()=>{i=void 0,t.onClose?.()},restoreFocusTo:e,sizeType:es(e.dataset.sizeType),tinuuid:o,widgetSessionToken:a,width:e.dataset.width?.trim()});s&&(i=s,t.onOpen?.(),D(()=>t.onAction?.("widget_opened")))};return e.addEventListener("click",o),r.register(()=>{e.removeEventListener("click",o),i?.(),i=void 0})}(this.trigger,{apiKey:n,getWidgetSessionToken:async()=>(await this.ensureSession(n,i,o.mode)).token,mode:o.mode,modelViewerOrigin:i.modelViewerOrigin,onAction:e=>this.handleAction(e,i),onClose:()=>{this.isConnected&&this.setState("ready")},onOpen:()=>this.setState("opening"),widgetSessionToken:o.token});if(!t)throw new eE("INITIALIZATION_FAILED");let a={getDesktopQrUrl:async()=>{let e=await this.ensureSession(n,i,o.mode);return el({apiKey:n,cameraOrbit:this.trigger?.dataset.cameraOrbit,dimensionAxes:ed(this.trigger?.dataset.dimensionAxes),hid:this.variantId,maxCameraOrbit:this.trigger?.dataset.maxCameraOrbit,minCameraOrbit:this.trigger?.dataset.minCameraOrbit,mode:e.mode,modelViewerOrigin:i.modelViewerOrigin,sizeType:es(this.trigger?.dataset.sizeType),tinuuid:this.trigger?.dataset.objectTinuuid??"",widgetSessionToken:e.token})},object:t,onAction:e=>this.handleAction(e,i),runtimeConfig:i,signal:r,trackView:()=>this.trackEvent("ar_launched",i)};if("ar-one-click"===e){if(!(this.trigger instanceof HTMLAnchorElement))throw new eE("INITIALIZATION_FAILED");return eg(this.trigger,a)}return U(this.trigger,a)}handleAction(e,t){this.setState("opening"),("interacted"===e||"widget_opened"===e)&&"ar-viewer"!==this.getAttribute("type")&&this.trackEvent(e,t),"ar-viewer"!==this.getAttribute("type")&&(this.clearActionResetTimer(),this.actionResetTimer=window.setTimeout(()=>{this.isConnected&&this.setState("ready")},300))}async trackEvent(e,t){let i=this.getAttribute("api-key")?.trim(),r=this.widgetMode;if(i&&r&&this.isConnected)try{let n=await this.ensureSession(i,t,r);await R(e,n.token,this.object?.uuid,{runtimeConfig:t,variantId:this.variantId})}catch{}}clearActionResetTimer(){void 0!==this.actionResetTimer&&(window.clearTimeout(this.actionResetTimer),this.actionResetTimer=void 0)}setState(e){this.dataset.state=e,this.updateTriggerAccessibility(e)}updateTriggerAccessibility(e){if(!this.trigger)return;let t="ready"===e;this.trigger.setAttribute("aria-busy",String("loading"===e)),this.trigger.setAttribute("aria-disabled",String(!t)),this.trigger.tabIndex=t?0:-1,this.trigger instanceof HTMLButtonElement&&(this.trigger.disabled=!t)}dispatchWidgetEvent(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}}function eS(e){if("u"<typeof customElements)return;let t=eh[e],i=customElements.get(t);if(i)return i;class n extends eO{resolveRuntimeConfig(){return function(e,t="prod"){var i,n;let o,a,s,d,l,c,u,g,m="arizo"===e?"arizo.ru":"vizbl.com",h="dev"===t?"-dev":"";return o=r((i={apiOrigin:`https://api${h}.${m}`,modelViewerOrigin:`https://integrations${h}.${m}`,viewerOrigin:`https://viewer${h}.${m}`}).apiOrigin,"apiOrigin"),a=r(i.viewerOrigin,"viewerOrigin"),l=i.modelViewerOrigin?r(i.modelViewerOrigin,"modelViewerOrigin"):(d=(s=new URL(a)).hostname.match(/^viewer(-dev)?\.(vizbl\.com|arizo\.ru)$/))?`${s.protocol}//integrations${d[1]??""}.${d[2]}`:a,g=i.legacyApiOrigin?(c=r(n=i.legacyApiOrigin,"legacyApiOrigin"),(u=new URL(n).pathname.replace(/\/+$/,""))?`${c}${u}`:c):`${o}/v1`,{apiOrigin:o,brand:new URL(a).hostname.endsWith("arizo.ru")?"arizo":"vizbl",fetchImpl:i.fetchImpl??fetch,legacyApiOrigin:g,modelViewerOrigin:l,qrCodeScriptUrl:i.qrCodeScriptUrl??`${a}/vendor/qrcode.min.js`,viewerOrigin:a}}(e,this.hasAttribute("dev")?"dev":"prod")}}return customElements.define(t,n),n}eS("arizo"),eS("vizbl")})();
|
package/dist/index.js
CHANGED
|
@@ -763,6 +763,9 @@ function createModalViewerUrl(params) {
|
|
|
763
763
|
if (params.hid) url.searchParams.set('hid', params.hid);
|
|
764
764
|
url.searchParams.set('size-type', params.sizeType);
|
|
765
765
|
if (dimensionAxes.length < ALL_DIMENSION_AXES.length) url.searchParams.set('dimension-axes', dimensionAxes.join(','));
|
|
766
|
+
if (params.cameraOrbit) url.searchParams.set('camera-orbit', params.cameraOrbit);
|
|
767
|
+
if (params.minCameraOrbit) url.searchParams.set('min-camera-orbit', params.minCameraOrbit);
|
|
768
|
+
if (params.maxCameraOrbit) url.searchParams.set('max-camera-orbit', params.maxCameraOrbit);
|
|
766
769
|
const fragment = new URLSearchParams();
|
|
767
770
|
if (params.apiKey) fragment.set('api-key', params.apiKey);
|
|
768
771
|
if (params.mode) fragment.set('mode', params.mode);
|
|
@@ -908,6 +911,7 @@ function initializeModalTrigger(trigger, options = {}) {
|
|
|
908
911
|
buttonBgColor: trigger.dataset.buttonBgColor,
|
|
909
912
|
buttonBorderColor: trigger.dataset.buttonBorderColor,
|
|
910
913
|
buttonTextColor: trigger.dataset.buttonTextColor,
|
|
914
|
+
cameraOrbit: trigger.dataset.cameraOrbit,
|
|
911
915
|
containerClassName: trigger.dataset.container,
|
|
912
916
|
crossClassName: trigger.dataset.crossClassName,
|
|
913
917
|
dimensionAxes: resolveDimensionAxes(trigger.dataset.dimensionAxes),
|
|
@@ -915,6 +919,8 @@ function initializeModalTrigger(trigger, options = {}) {
|
|
|
915
919
|
hid: trigger.dataset.objectHid,
|
|
916
920
|
hidePreview: trigger.dataset.hidePreview,
|
|
917
921
|
hideTitle: trigger.dataset.hideTitle,
|
|
922
|
+
maxCameraOrbit: trigger.dataset.maxCameraOrbit,
|
|
923
|
+
minCameraOrbit: trigger.dataset.minCameraOrbit,
|
|
918
924
|
mode: options.mode,
|
|
919
925
|
modelViewerOrigin: options.modelViewerOrigin,
|
|
920
926
|
onClose: ()=>{
|
|
@@ -1032,8 +1038,11 @@ const BACKEND_WIDGET_MODES = {
|
|
|
1032
1038
|
};
|
|
1033
1039
|
const OBSERVED_ATTRIBUTES = [
|
|
1034
1040
|
'api-key',
|
|
1041
|
+
'camera-orbit',
|
|
1035
1042
|
'dev',
|
|
1036
1043
|
'dimension-axes',
|
|
1044
|
+
'max-camera-orbit',
|
|
1045
|
+
'min-camera-orbit',
|
|
1037
1046
|
'object-id',
|
|
1038
1047
|
'size-type',
|
|
1039
1048
|
'trigger-class',
|
|
@@ -1140,9 +1149,7 @@ function getSelectedMaterial(object, variantId) {
|
|
|
1140
1149
|
return material;
|
|
1141
1150
|
}
|
|
1142
1151
|
function assertPolicy(type, object) {
|
|
1143
|
-
|
|
1144
|
-
const allowed = 'ar-one-click' === type ? policy?.instantArView !== false : policy?.appClip !== false;
|
|
1145
|
-
if (!allowed) throw new CoreArWidgetComponentError('POLICY_DENIED');
|
|
1152
|
+
if ('ar-one-click' === type && object.policy?.instantArView === false) throw new CoreArWidgetComponentError('POLICY_DENIED');
|
|
1146
1153
|
}
|
|
1147
1154
|
function toErrorCode(error) {
|
|
1148
1155
|
if (error instanceof CoreArWidgetComponentError) return error.code;
|
|
@@ -1239,6 +1246,9 @@ class CoreArWidgetElement extends HTMLElementBase {
|
|
|
1239
1246
|
const publicKey = this.getAttribute('api-key')?.trim() ?? '';
|
|
1240
1247
|
const sizeType = this.getAttribute('size-type')?.trim() || void 0;
|
|
1241
1248
|
const dimensionAxes = this.getAttribute('dimension-axes')?.trim() || void 0;
|
|
1249
|
+
const cameraOrbit = this.getAttribute('camera-orbit')?.trim() || void 0;
|
|
1250
|
+
const minCameraOrbit = this.getAttribute('min-camera-orbit')?.trim() || void 0;
|
|
1251
|
+
const maxCameraOrbit = this.getAttribute('max-camera-orbit')?.trim() || void 0;
|
|
1242
1252
|
this.removeAttribute('data-error-code');
|
|
1243
1253
|
this.setState('loading');
|
|
1244
1254
|
this.renderTrigger(renderType);
|
|
@@ -1253,7 +1263,7 @@ class CoreArWidgetElement extends HTMLElementBase {
|
|
|
1253
1263
|
this.assertCurrent(revision, abortController.signal);
|
|
1254
1264
|
this.variantId = variantId;
|
|
1255
1265
|
this.widgetMode = mode;
|
|
1256
|
-
this.applyIntegrationData(objectId, variantId, sizeType, dimensionAxes);
|
|
1266
|
+
this.applyIntegrationData(objectId, variantId, sizeType, dimensionAxes, cameraOrbit, minCameraOrbit, maxCameraOrbit);
|
|
1257
1267
|
let object;
|
|
1258
1268
|
if ('ar-viewer' === rawType) {
|
|
1259
1269
|
object = await fetchLegacyObject(objectId, abortController.signal, runtimeConfig);
|
|
@@ -1390,7 +1400,7 @@ class CoreArWidgetElement extends HTMLElementBase {
|
|
|
1390
1400
|
if (className) this.trigger.className = className;
|
|
1391
1401
|
else this.trigger.removeAttribute('class');
|
|
1392
1402
|
}
|
|
1393
|
-
applyIntegrationData(objectId, variantId, sizeType, dimensionAxes) {
|
|
1403
|
+
applyIntegrationData(objectId, variantId, sizeType, dimensionAxes, cameraOrbit, minCameraOrbit, maxCameraOrbit) {
|
|
1394
1404
|
if (!this.trigger) return;
|
|
1395
1405
|
this.trigger.dataset.objectTinuuid = objectId;
|
|
1396
1406
|
if (variantId) this.trigger.dataset.objectHid = variantId;
|
|
@@ -1399,6 +1409,12 @@ class CoreArWidgetElement extends HTMLElementBase {
|
|
|
1399
1409
|
else delete this.trigger.dataset.sizeType;
|
|
1400
1410
|
if (dimensionAxes) this.trigger.dataset.dimensionAxes = dimensionAxes;
|
|
1401
1411
|
else delete this.trigger.dataset.dimensionAxes;
|
|
1412
|
+
if (cameraOrbit) this.trigger.dataset.cameraOrbit = cameraOrbit;
|
|
1413
|
+
else delete this.trigger.dataset.cameraOrbit;
|
|
1414
|
+
if (minCameraOrbit) this.trigger.dataset.minCameraOrbit = minCameraOrbit;
|
|
1415
|
+
else delete this.trigger.dataset.minCameraOrbit;
|
|
1416
|
+
if (maxCameraOrbit) this.trigger.dataset.maxCameraOrbit = maxCameraOrbit;
|
|
1417
|
+
else delete this.trigger.dataset.maxCameraOrbit;
|
|
1402
1418
|
}
|
|
1403
1419
|
async initializeTrigger(type, object, runtimeConfig, signal, publicKey, session) {
|
|
1404
1420
|
if (!this.trigger) throw new CoreArWidgetComponentError('INITIALIZATION_FAILED');
|
|
@@ -1423,8 +1439,11 @@ class CoreArWidgetElement extends HTMLElementBase {
|
|
|
1423
1439
|
const currentSession = await this.ensureSession(publicKey, runtimeConfig, session.mode);
|
|
1424
1440
|
return createModalViewerUrl({
|
|
1425
1441
|
apiKey: publicKey,
|
|
1442
|
+
cameraOrbit: this.trigger?.dataset.cameraOrbit,
|
|
1426
1443
|
dimensionAxes: resolveDimensionAxes(this.trigger?.dataset.dimensionAxes),
|
|
1427
1444
|
hid: this.variantId,
|
|
1445
|
+
maxCameraOrbit: this.trigger?.dataset.maxCameraOrbit,
|
|
1446
|
+
minCameraOrbit: this.trigger?.dataset.minCameraOrbit,
|
|
1428
1447
|
mode: currentSession.mode,
|
|
1429
1448
|
modelViewerOrigin: runtimeConfig.modelViewerOrigin,
|
|
1430
1449
|
sizeType: resolveSizeType(this.trigger?.dataset.sizeType),
|