@neurodyn/core-ar 0.2.8 → 0.2.9
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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -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()??"",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[this.resolveRuntimeConfig().brand][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;let r,n;if(document.getElementById(eo))return null;let o=document.createElement("div"),a=document.createElement("div"),s=document.createElement("div"),d=e.containerClassName?document.getElementsByClassName(e.containerClassName)[0]:null,l=!!d,c=l?a:o,u=!1,g=e=>{"Escape"===e.key&&r()};r=()=>{u||(u=!0,document.removeEventListener("keydown",g),et(c),(l?a:o).remove(),e.onClose?.(),e.restoreFocusTo?.focus({preventScroll:!0}))},o.id=eo,Object.assign(o.style,{inset:"0",overflow:"auto",position:"fixed",zIndex:"11111"}),o.style.webkitOverflowScrolling="touch",a.setAttribute("role","dialog"),a.setAttribute("aria-modal","true"),a.setAttribute("aria-label","ru"===e.lang?"Просмотр 3D-модели":"3D model viewer"),Object.assign(s.style,{animation:"vex-fadein 0.5s",background:"#fff",inset:"0",position:"fixed",zIndex:"11111"}),s.addEventListener("click",r),(e.width||e.height)&&(s.style.background="rgba(0, 0, 0, 0.8)",Object.assign(a.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 m=function(e,t,i="en"){let r=document.createElement("button");return r.type="button",r.setAttribute("aria-label","ru"===i?"Закрыть просмотр 3D-модели":"Close 3D model viewer"),e&&(r.className=e),Object.assign(r.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"}),r.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>',r.addEventListener("click",t),r}(e.crossClassName,r,e.lang);return a.append((t=el(e),i=e.backgroundColor,(n=document.createElement("iframe")).src=t,n.title="3D model viewer",n.allow="fullscreen; xr-spatial-tracking",Object.assign(n.style,{backgroundColor:i??"white",border:"none",height:"100%",inset:"0",position:"absolute",width:"100%",zIndex:"11112"}),n),m),d?(a.id=eo,d.appendChild(a)):(o.append(s,a),document.body.appendChild(o)),document.addEventListener("keydown",g),ee(c),m.focus({preventScroll:!0}),r}({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,lang:t.lang,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,lang:"arizo"===i.brand?"ru":"en",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,lang:"arizo"===i.brand?"ru":"en",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")})();
|
|
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[this.resolveRuntimeConfig().brand][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;let r,n;if(document.getElementById(eo))return null;let o=document.createElement("div"),a=document.createElement("div"),s=document.createElement("div"),d=e.containerClassName?document.getElementsByClassName(e.containerClassName)[0]:null,l=!!d,c=l?a:o,u=!1,g=e=>{"Escape"===e.key&&r()};r=()=>{u||(u=!0,document.removeEventListener("keydown",g),et(c),(l?a:o).remove(),e.onClose?.(),e.restoreFocusTo?.focus({preventScroll:!0}))},o.id=eo,Object.assign(o.style,{inset:"0",overflow:"auto",position:"fixed",zIndex:"2147483647"}),o.style.webkitOverflowScrolling="touch",a.setAttribute("role","dialog"),a.setAttribute("aria-modal","true"),a.setAttribute("aria-label","ru"===e.lang?"Просмотр 3D-модели":"3D model viewer"),Object.assign(s.style,{animation:"vex-fadein 0.5s",background:"#fff",inset:"0",position:"fixed",zIndex:"11111"}),s.addEventListener("click",r),(e.width||e.height)&&(s.style.background="rgba(0, 0, 0, 0.8)",Object.assign(a.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 m=function(e,t,i="en"){let r=document.createElement("button");return r.type="button",r.setAttribute("aria-label","ru"===i?"Закрыть просмотр 3D-модели":"Close 3D model viewer"),e&&(r.className=e),Object.assign(r.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"}),r.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>',r.addEventListener("click",t),r}(e.crossClassName,r,e.lang);return a.append((t=el(e),i=e.backgroundColor,(n=document.createElement("iframe")).src=t,n.title="3D model viewer",n.allow="fullscreen; xr-spatial-tracking",Object.assign(n.style,{backgroundColor:i??"white",border:"none",height:"100%",inset:"0",position:"absolute",width:"100%",zIndex:"11112"}),n),m),d?(a.id=eo,d.appendChild(a)):(o.append(s,a),document.body.appendChild(o)),document.addEventListener("keydown",g),ee(c),m.focus({preventScroll:!0}),r}({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,lang:t.lang,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,lang:"arizo"===i.brand?"ru":"en",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,lang:"arizo"===i.brand?"ru":"en",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