@3dn-builder/builder 0.664.0 → 0.666.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
var t="tdn-open-builder";function d(e){e.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0}))}var c="tdn-status-change";var g="exportRequested",i="tdn-export-complete";function E(e,o){e.dispatchEvent(new CustomEvent(i,{bubbles:!1,composed:!1,detail:o}))}var p="tdn-product-cloned";var u="tdn-login-required";var n="tdn-login-cancelled";function f(e,o={}){e.dispatchEvent(new CustomEvent(n,{bubbles:!1,composed:!1,detail:o}))}var b="tdn-license-error";var m="tdn-design-saved";var F="tdn-images-saved";var A="tdn-images-save-failed";var T="tdn-design-save-failed";var D="tdn-license-token-required";var s="tdn-save-request";function _(e){e.dispatchEvent(new CustomEvent(s,{bubbles:!1,composed:!1}))}var C="tdn-close-requested";var r=[{name:"Grays",colors:["#FFFFFF","#F8F9FA","#E9ECEF","#DEE2E6","#CED4DA","#ADB5BD","#6C757D","#495057","#343A40","#212529","#1A1A1A","#000000"]},{name:"Reds",colors:["#FFE6E6","#FFCCCC","#FF9999","#FF6666","#FF3333","#FF0000","#E60000","#CC0000","#990000","#660000","#330000","#1A0000"]},{name:"Oranges",colors:["#FFF4E6","#FFE6CC","#FFCC99","#FFB366","#FF9933","#FF8000","#E66A00","#CC5200","#993D00","#662900","#331400","#1A0A00"]},{name:"Yellows",colors:["#FFFEF0","#FFFDE6","#FFFACC","#FFF799","#FFF266","#FFED33","#E6D100","#CCBA00","#998C00","#665D00","#332E00","#1A1700"]},{name:"Greens",colors:["#F0FFF0","#E6FFE6","#CCFFCC","#99FF99","#66FF66","#33FF33","#00E600","#00CC00","#009900","#006600","#003300","#001A00"]},{name:"Blues",colors:["#F0F8FF","#E6F3FF","#CCE7FF","#99CFFF","#66B7FF","#339FFF","#0080E6","#0066CC","#004D99","#003366","#001A33","#000D1A"]},{name:"Purples",colors:["#F8F0FF","#F0E6FF","#E0CCFF","#C199FF","#A266FF","#8333FF","#6600E6","#5200CC","#3D0099","#290066","#140033","#0A001A"]},{name:"Pinks",colors:["#FFE6F0","#FFCCE0","#FF99C1","#FF66A2","#FF3383","#FF0064","#E60057","#CC0051","#99003E","#66002A","#330015","#1A000A"]},{name:"Teals",colors:["#F0FFFF","#E0FFFF","#B2FFFF","#66FFFF","#1AFFFF","#00CCCC","#00B3B3","#009999","#006666","#003333","#001A1A","#000D0D"]},{name:"Cyans",colors:["#E0F7FA","#B2EBF2","#80DEEA","#4DD0E1","#26C6DA","#00BCD4","#00ACC1","#0097A7","#00796B","#004D40","#00251A","#00120D"]},{name:"Indigos",colors:["#E8EAF6","#C5CAE9","#9FA8DA","#7986CB","#5C6BC0","#3F51B5","#303F9F","#283593","#1A237E","#0D1442","#060A21","#030510"]},{name:"Violets",colors:["#F3E5F5","#E1BEE7","#CE93D8","#BA68C8","#AB47BC","#9C27B0","#8E24AA","#7B1FA2","#6A1B9A","#4A148C","#2E1065","#1A0D3D"]},{name:"Magentas",colors:["#FCE4EC","#F8BBD9","#F48FB1","#F06292","#EC407A","#E91E63","#D81B60","#C2185B","#AD1457","#880E4F","#4A0A2A","#2D0519"]},{name:"Limes",colors:["#F9FBE7","#F0F4C3","#E6EE9C","#DCE775","#D4E157","#CDDC39","#C0CA33","#AFB42B","#9E9D24","#827717","#4A4514","#2D2A0C"]},{name:"Ambers",colors:["#FFF8E1","#FFECB3","#FFE082","#FFD54F","#FFCA28","#FFC107","#FFB300","#FFA000","#FF8F00","#FF6F00","#994200","#5A2700"]},{name:"Deep Oranges",colors:["#FBE9E7","#FFCCBC","#FFAB91","#FF8A65","#FF7043","#FF5722","#F4511E","#E64A19","#D84315","#BF360C","#7A2408","#4A1605"]},{name:"Light Blues",colors:["#E1F5FE","#B3E5FC","#81D4FA","#4FC3F7","#29B6F6","#03A9F4","#039BE5","#0288D1","#0277BD","#01579B","#003A66","#00223D"]},{name:"Light Greens",colors:["#E8F5E8","#C8E6C9","#A5D6A7","#81C784","#66BB6A","#4CAF50","#43A047","#388E3C","#2E7D32","#1B5E20","#0F3A14","#09230C"]},{name:"Browns",colors:["#F5F5DC","#F0E68C","#D2B48C","#BC8F8F","#A0522D","#8B4513","#654321","#4A2C2A","#2F1B14","#1A0E0A","#0F0705","#090503"]},{name:"Grey-Blues",colors:["#ECEFF1","#CFD8DC","#B0BEC5","#90A4AE","#78909C","#607D8B","#546E7A","#455A64","#37474F","#263238","#1A2126","#0F1316"]}],I=r.flatMap(e=>e.colors);var x=1024*1024;var a=4096,R=600*1024;var l=["active","suspended","revoked"];var V=[...l,"expired"];var K=1440*60*1e3;var j={full:{tier:"full",texture:{maxSide:a,maxArea:a*a},maxCaptureArea:33554432,maxOversample:2},mobile:{tier:"mobile",texture:{maxSide:2048,maxArea:2048*2048},maxCaptureArea:4194304,maxOversample:1},light:{tier:"light",texture:{maxSide:1536,maxArea:1536*1536},maxCaptureArea:2359296,maxOversample:1}};export{t as a,d as b,c,g as d,i as e,E as f,p as g,u as h,n as i,f as j,b as k,m as l,F as m,A as n,T as o,D as p,s as q,_ as r,C as s};
|
|
2
|
+
//# sourceMappingURL=chunk-QKY2VACQ.js.map
|
package/events.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as E,c as _,d as D,e,g as R,h as T,i as L,k as t,l as I,m as i,n as N,o as a,p as S,q as U,s as l}from"./chunks/chunk-
|
|
1
|
+
import{a as E,c as _,d as D,e,g as R,h as T,i as L,k as t,l as I,m as i,n as N,o as a,p as S,q as U,s as l}from"./chunks/chunk-QKY2VACQ.js";export{l as THREED_BUILDER_CLOSE_REQUESTED_EVENT,I as THREED_BUILDER_DESIGN_SAVED_EVENT,a as THREED_BUILDER_DESIGN_SAVE_FAILED_EVENT,e as THREED_BUILDER_EXPORT_COMPLETE_EVENT,D as THREED_BUILDER_EXPORT_REQUESTED_EVENT,i as THREED_BUILDER_IMAGES_SAVED_EVENT,N as THREED_BUILDER_IMAGES_SAVE_FAILED_EVENT,t as THREED_BUILDER_LICENSE_ERROR_EVENT,S as THREED_BUILDER_LICENSE_TOKEN_REQUIRED_EVENT,L as THREED_BUILDER_LOGIN_CANCELLED_EVENT,T as THREED_BUILDER_LOGIN_REQUIRED_EVENT,E as THREED_BUILDER_OPEN_EVENT,R as THREED_BUILDER_PRODUCT_CLONED_EVENT,U as THREED_BUILDER_SAVE_REQUEST_EVENT,_ as THREED_BUILDER_STATUS_EVENT};
|
|
2
2
|
//# sourceMappingURL=events.js.map
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as B,c as O,d as C,e as A,f as N,g as M,h as F,j as v,k as U,l as V,m as H,n as $,o as j,p as q,r as z,s as W}from"./chunks/chunk-6WUVIHXU.js";var s=class t extends Error{constructor(e,r,n={}){var o,i;super(r),this.name="BuilderError",this.code=e,this.retryable=(o=n.retryable)!=null?o:!1,this.fatal=(i=n.fatal)!=null?i:!1,this.reason=n.reason,this.cause=n.cause,Object.setPrototypeOf(this,t.prototype)}},G={conflict:"Someone else saved this design first.",forbidden:"This shopper may not save this design.",unauthorized:"The shopper could not be signed in to save.","login-cancelled":"The design was not saved because the shopper did not log in.","installation-inactive":"This site's 3DN installation is not active.",license:"This page is not licensed to use the 3DN builder.",locked:"This design was ordered and is locked. Save a copy to make changes.",outdated:"The builder on this page is out of date. Reload the page to save the design.",error:"The design could not be saved. Check the connection and try again."};function K(t){var r;let e=(r=G[t.reason])!=null?r:G.error;return t.reason==="login-cancelled"?new s("LOGIN_CANCELLED",e,{retryable:!0,reason:t.reason,cause:t}):new s("SAVE_FAILED",e,{retryable:t.retryable,reason:t.reason,cause:t})}function X(t){let e=t==="ORIGIN_NOT_ALLOWED"?"This website is not on the 3DN license. Add its hostname to the license.":"The 3DN license token was rejected. The license may be suspended, revoked or expired.";return new s("LICENSE_ERROR",e,{fatal:!0,reason:t,cause:{code:t}})}function m(){return new s("DESTROYED","The builder was destroyed.")}function a(t){return new s("CONFIG_INVALID",t,{fatal:!0})}var de=45e3,Y=12e4,ue=new Set(["environment","version","saveTimeoutMs","session","login","customization","features","onSaved","onImagesSaved","onLicenseError","onCloseRequested","onStatusChange","debug"]),le=new Set(["download","share","save"]),ce=new Set(["target","hostProductId","mode","designId","externalExport","observabilityContext"]),he=/^\d+\.\d+\.\d+$/,fe=/^tdn_inst_/;function S(t){return he.test(t)}function l(t){return typeof t=="object"&&t!==null}function f(t){return typeof t=="function"}function J(t){return typeof t=="number"&&Number.isFinite(t)&&t>0}function Q(t,e=0){return typeof t=="string"?fe.test(t):!l(t)||e>3?!1:Object.values(t).some(r=>Q(r,e+1))}function T(t,e,r){for(let n of Object.keys(t))if(!e.has(n))throw/url|src|host|origin/i.test(n)?a(`${r}: "${n}" is not allowed. The SDK decides where the builder loads from; choose an environment and a version instead.`):a(`${r}: unknown option "${n}".`)}function Z(t){var c,h,_;if(!l(t))throw a("createBuilder() needs a configuration object.");if(Q(t))throw a("createBuilder(): an installation key was passed to the browser. Installation keys stay on your server; pass a session callback instead.");T(t,ue,"createBuilder()");let e=(c=t.environment)!=null?c:"production";if(e!=="production"&&e!=="staging")throw a(`createBuilder(): environment must be "production" or "staging", got ${JSON.stringify(e)}.`);let r=(h=t.version)!=null?h:"latest";if(typeof r!="string"||r!=="latest"&&!S(r))throw a(`createBuilder(): version must be "latest" or an exact release such as "1.2.3", got ${JSON.stringify(r)}.`);let n=(_=t.saveTimeoutMs)!=null?_:de;if(!J(n))throw a("createBuilder(): saveTimeoutMs must be a positive number of milliseconds.");let o=t.session;if(!l(o)||!f(o.get)||!f(o.refreshLicense))throw a("createBuilder(): session.get() and session.refreshLicense() are required. They call your session endpoint.");let i=t.login;if(i!==void 0){if(!l(i)||!f(i.getTokens)||!f(i.onRequired))throw a("createBuilder(): login needs getTokens() (your login-token endpoint) and onRequired() (your login UI).");if(i.onMintFailed!==void 0&&!f(i.onMintFailed))throw a("createBuilder(): login.onMintFailed must be a function.")}let d=t.customization;if(d!==void 0&&(!l(d)||!f(d.record)))throw a("createBuilder(): customization.record() is required when customization is set. It calls your customization endpoint.");let u=t.features;if(u!==void 0){if(!l(u)||Array.isArray(u))throw a("createBuilder(): features must be an object.");T(u,le,"createBuilder() features");for(let[g,P]of Object.entries(u))if(P!==void 0&&typeof P!="boolean")throw a(`createBuilder(): features.${g} must be a boolean.`)}for(let g of["onSaved","onImagesSaved","onLicenseError","onCloseRequested","onStatusChange"])if(t[g]!==void 0&&!f(t[g]))throw a(`createBuilder(): ${g} must be a function.`);return{...t,environment:e,version:r,saveTimeoutMs:n}}function ee(t){var d;if(!l(t))throw a("mount() needs an options object.");T(t,ce,"mount()");let e=t.target;if(typeof HTMLElement=="undefined"||!(e instanceof HTMLElement))throw a("mount(): target must be an HTMLElement on the page.");let r=t.hostProductId;if(typeof r!="string"||r.trim()==="")throw a("mount(): hostProductId must be your own, non-empty product reference.");let n=(d=t.mode)!=null?d:"designer";if(n!=="designer"&&n!=="viewer")throw a(`mount(): mode must be "designer" or "viewer", got ${JSON.stringify(n)}.`);let o=t.designId;if(o!==void 0&&(typeof o!="string"||o===""))throw a("mount(): designId must be a non-empty string.");t.observabilityContext!==void 0&&w(t.observabilityContext,"mount()");let i=t.externalExport;if(i!==void 0){if(!l(i)||!f(i.run))throw a("mount(): externalExport.run() is required when externalExport is set.");if(i.timeoutMs!==void 0&&!J(i.timeoutMs))throw a("mount(): externalExport.timeoutMs must be a positive number of milliseconds.")}return t}function w(t,e){let r;try{r=typeof t=="string"?JSON.parse(t):void 0}catch{r=void 0}if(!l(r)||Array.isArray(r))throw a(`${e}: observabilityContext must be a JSON object string.`);return t}function I(t){let e=o=>new s("SESSION_FAILED",`session.get() returned an invalid session: ${o}.`,{retryable:!1});if(!l(t))throw e("expected an object");if(typeof t.licenseToken!="string"||t.licenseToken==="")throw e("licenseToken is missing");if(typeof t.productId!="string"||t.productId==="")throw e("productId is missing");if(t.viewToken!=null&&typeof t.viewToken!="string")throw e("viewToken must be a string");let r=t.token!=null,n=t.refreshToken!=null;if(r!==n)throw e("token and refreshToken must be returned together");if(r&&(typeof t.token!="string"||typeof t.refreshToken!="string"))throw e("token and refreshToken must be strings");return t}function te(t){if(t===null)return null;if(!l(t)||typeof t.token!="string"||t.token===""||typeof t.refreshToken!="string"||t.refreshToken==="")throw new s("SESSION_FAILED","login.getTokens() must resolve { token, refreshToken } or null.");return t}var pe=/token|secret|key|authorization/i;function D(t,e=0){if(t===null||typeof t!="object"||e>4)return t;if(Array.isArray(t))return t.map(n=>D(n,e+1));let r={};for(let[n,o]of Object.entries(t))r[n]=pe.test(n)&&o!=null?"[redacted]":D(o,e+1);return r}function ne(t){return t?(e,r)=>{r===void 0?console.debug(`[3DN] ${e}`):console.debug(`[3DN] ${e}`,D(r))}:()=>{}}var E="threed-builder",ie={production:"https://3d-builder.3dn.app",staging:void 0},ge=3e4,re=Symbol.for("@3dn-builder/builder/loader");function me(){let t=globalThis,e=t[re];return e||(e={},t[re]=e),e}function ve(){return typeof window!="undefined"&&typeof document!="undefined"&&typeof customElements!="undefined"}function se(t){if(!ie[t])throw a(`createBuilder(): the "${t}" environment is not available in this SDK release.`)}function p(t,e){return new s("LOAD_FAILED",t,{retryable:!0,cause:e})}async function Ee(t,e){if(e!=="latest")return e;let r;try{r=await fetch(`${t}/version-info.json`,{cache:"no-store",credentials:"omit"})}catch(i){throw p("The 3DN builder could not be reached.",i)}if(!r.ok)throw p(`The 3DN builder release could not be resolved (HTTP ${r.status}).`);let n=await r.json().catch(()=>null),o=n==null?void 0:n.version;if(typeof o!="string"||!S(o))throw p("The 3DN builder release information was not valid.");return o}function ye(t){return new Promise((e,r)=>{let n=document.createElement("script");n.type="module",n.src=t,n.crossOrigin="anonymous",n.onload=()=>e(n),n.onerror=()=>{n.remove(),r(p("The 3DN builder failed to load."))},document.head.appendChild(n)})}function be(){return new Promise((t,e)=>{let r=setTimeout(()=>e(p("The 3DN builder loaded but did not start.")),ge);customElements.whenDefined(E).then(()=>{clearTimeout(r),t()},e)})}function oe(t,e,r){if(t.environment&&t.environment!==e)throw new s("VERSION_CONFLICT",`The ${t.environment} builder already runs on this page; ${e} cannot load beside it.`,{fatal:!0});if(r!=="latest"&&t.version&&t.version!==r)throw new s("VERSION_CONFLICT",`Builder ${t.version} already runs on this page; ${r} cannot load beside it.`,{fatal:!0})}async function ae(t,e){if(!ve())throw new s("NOT_IN_BROWSER","The 3DN builder can only load in a browser.");let r=me();if(r.loading){await r.loading,oe(r,t,e);return}if(customElements.get(E))return;let n=ie[t];if(!n)throw a(`The "${t}" environment is not available in this SDK release.`);r.environment=t,r.loading=(async()=>{let o=await Ee(n,e);r.version=o;let i=await ye(`${n}/builder-${o}.js`);try{await be()}catch(d){throw i.remove(),d}})();try{await r.loading}catch(o){throw r.loading=void 0,r.environment=void 0,r.version=void 0,o instanceof s?o:p("The 3DN builder failed to load.",o)}oe(r,t,e)}function L(){let t,e,r=new Promise((n,o)=>{t=n,e=o});return r.catch(()=>{}),{promise:r,resolve:t,reject:e}}var x=class{constructor(e,r){this.onExpire=r;this.startedAt=0;this.remaining=e}start(){this.handle===void 0&&(this.startedAt=Date.now(),this.handle=setTimeout(this.onExpire,this.remaining))}pause(){this.handle!==void 0&&(clearTimeout(this.handle),this.handle=void 0,this.remaining=Math.max(0,this.remaining-(Date.now()-this.startedAt)))}stop(){this.handle!==void 0&&clearTimeout(this.handle),this.handle=void 0}},y=class t{constructor(e,r,n){this.ctx=e;this.options=r;this.epoch=0;this.destroyed=!1;this.loginPending=!1;this.exports=new Set;this.listeners=[];this.currentProductId=n.productId,this.element=this.createElement(n)}static async mount(e,r){let n;try{n=await e.config.session.get({hostProductId:r.hostProductId})}catch(d){throw new s("SESSION_FAILED","The builder session could not be loaded.",{retryable:!0,cause:d})}let o=I(n),i=new t(e,r,o);return r.target.appendChild(i.element),e.log("mounted",{hostProductId:r.hostProductId,productId:o.productId}),i}get productId(){return this.currentProductId}get hostProductId(){return this.options.hostProductId}createElement(e){let r=document.createElement(E);this.attachListeners(r),r.setAttribute("product",e.productId),r.setAttribute("license-token",e.licenseToken),e.viewToken&&r.setAttribute("view-token",e.viewToken),e.token&&e.refreshToken&&R(r,{token:e.token,refreshToken:e.refreshToken}),this.options.designId&&r.setAttribute("design-id",this.options.designId),this.options.mode==="viewer"&&r.setAttribute("display-only","true"),this.options.externalExport&&r.setAttribute("external-export","true");let n=this.ctx.config.features;return(n==null?void 0:n.download)===!1&&r.setAttribute("hide-download","true"),(n==null?void 0:n.share)===!1&&r.setAttribute("hide-share","true"),(n==null?void 0:n.save)===!1&&r.setAttribute("hide-save","true"),this.options.observabilityContext&&r.setAttribute("observability-context",this.options.observabilityContext),r.style.display="block",r.style.width="100%",r.style.height="100%",r}attachListeners(e){let r=(n,o)=>{let i=d=>{d.target!==e||this.destroyed||(this.ctx.log(n,d.detail),o(d.detail))};e.addEventListener(n,i),this.listeners.push([n,i])};r(F,n=>{var o;this.answerLogin((o=n==null?void 0:n.action)!=null?o:"save")}),r(q,()=>{this.ctx.refreshLicense()}),r(U,n=>this.onLicenseError(n)),r(V,n=>{this.onDesignSaved(n)}),r(j,n=>this.finishSave(K(n))),r(H,n=>this.onImagesSettled(n,!0)),r($,n=>this.onImagesSettled(n,!1)),r(M,n=>{this.onProductCloned(n)}),r(W,n=>{var o,i;return(i=(o=this.ctx.config).onCloseRequested)==null?void 0:i.call(o,n)}),r(O,n=>{var o,i;return(i=(o=this.ctx.config).onStatusChange)==null?void 0:i.call(o,n)}),this.options.externalExport&&r(C,n=>{this.answerExport(n)})}open(){this.assertUsable(),B(this.element)}save(){if(this.destroyed)return Promise.reject(m());if(this.fatal)return Promise.reject(this.fatal);if(this.saveRun)return this.saveRun.result.promise;let e={result:L(),timer:new x(this.ctx.config.saveTimeoutMs,()=>this.finishSave(new s("SAVE_TIMEOUT","Saving the design took too long. Try again.",{retryable:!0})))};return this.saveRun=e,this.loginPending||e.timer.start(),z(this.element),e.result.promise}async refreshSession(){this.assertUsable();let e=this.epoch,r;try{r=await this.ctx.config.session.get({hostProductId:this.options.hostProductId})}catch(o){throw new s("SESSION_FAILED","The builder session could not be refreshed.",{retryable:!0,cause:o})}let n=I(r);e!==this.epoch||this.destroyed||(this.applyLicense(n.licenseToken),n.viewToken&&this.element.setAttribute("view-token",n.viewToken),n.token&&n.refreshToken&&R(this.element,{token:n.token,refreshToken:n.refreshToken}),this.fatal=void 0)}logout(){this.destroyed||(this.epoch++,this.element.removeAttribute("bearer-token"),this.element.removeAttribute("refresh-token"),this.loginPending&&(this.loginPending=!1,this.finishSave(new s("LOGIN_CANCELLED","The shopper logged out before the design was saved.",{retryable:!0}))))}destroy(){var e,r;if(!this.destroyed){this.epoch++,this.finishSave(m()),(e=this.cloneWait)==null||e.reject(m()),this.cloneWait=void 0,(r=this.imagesWait)==null||r.resolve(!1),this.imagesWait=void 0;for(let n of this.exports)n.abort();this.destroyed=!0;for(let[n,o]of this.listeners)this.element.removeEventListener(n,o);this.listeners.length=0,this.element.remove(),this.ctx.onDestroyed(this),this.ctx.log("destroyed")}}setObservabilityContext(e){this.assertUsable(),this.element.setAttribute("observability-context",w(e,"setObservabilityContext()"))}applyLicense(e){this.destroyed||this.element.setAttribute("license-token",e)}get isDestroyed(){return this.destroyed}async answerLogin(e){if(this.loginPending)return;let r=this.ctx.config.login;if(!r){v(this.element,{action:e});return}let n=this.epoch,o=()=>n!==this.epoch||this.destroyed;this.setLoginPending(!0);let i=!1;try{for(;;){let d;try{d=te(await r.getTokens())}catch(c){if(o())return;this.ctx.log("login.getTokens() failed",{cause:String(c)});let h=r.onMintFailed?await r.onMintFailed():"cancel";if(o())return;if(h==="retry")continue;v(this.element,{action:e});return}if(o())return;if(d){R(this.element,d);return}let u=await r.onRequired(e);if(o())return;if(u!=="logged-in"){if(u==="redirected"){i=!0;return}v(this.element,{action:e});return}}}finally{!i&&n===this.epoch&&this.setLoginPending(!1)}}setLoginPending(e){this.loginPending=e,this.saveRun&&(e?this.saveRun.timer.pause():this.saveRun.timer.start())}onLicenseError(e){var n,o;let r=X(e.code);this.fatal=r,this.finishSave(r),(o=(n=this.ctx.config).onLicenseError)==null||o.call(n,r)}async onDesignSaved(e){var i;e.productId!==this.currentProductId&&!this.cloneWait&&(this.cloneWait=L()),(i=this.imagesWait)==null||i.resolve(!1);let r=this.imagesWait=L();try{this.cloneWait&&await this.cloneWait.promise,this.unrecordedLink&&await this.recordLink(this.unrecordedLink)}catch(d){this.finishSave(d instanceof s?d:new s("SAVE_FAILED","The design was saved but could not be linked to this shopper.",{retryable:!0,reason:"customization",cause:d}));return}if(this.destroyed)return;let n={productId:e.productId,version:e.version};this.notify("onSaved",n);let o=await r.promise;this.destroyed||(o&&this.notify("onImagesSaved",n),this.finishSave(void 0,n))}onImagesSettled(e,r){let n=this.imagesWait;if(n){this.imagesWait=void 0,n.resolve(r);return}r&&this.notify("onImagesSaved",{productId:e.productId,version:e.version})}notify(e,r){var n,o;try{(o=(n=this.ctx.config)[e])==null||o.call(n,{hostProductId:this.options.hostProductId,...r})}catch(i){this.ctx.log(`${e} threw`,{cause:String(i)})}}async onProductCloned(e){let r={hostProductId:this.options.hostProductId,sourceProductId:e.originalProductId,savedProductId:e.newProductId,asCopy:e.asCopy===!0};this.currentProductId=e.newProductId;let n=this.cloneWait;this.cloneWait=void 0;try{await this.recordLink(r),n==null||n.resolve()}catch(o){n==null||n.reject(o)}}async recordLink(e){let r=this.ctx.config.customization;if(r)try{await r.record(e),this.unrecordedLink===e&&(this.unrecordedLink=void 0)}catch(n){throw this.unrecordedLink=e,new s("SAVE_FAILED","The design was saved but could not be linked to this shopper. Try saving again.",{retryable:!0,reason:"customization",cause:n})}}finishSave(e,r){let n=this.saveRun;n&&(this.saveRun=void 0,n.timer.stop(),e?n.result.reject(e):r&&n.result.resolve(r))}async answerExport(e){var u;let r=this.options.externalExport;if(!r)return;let n=new AbortController;this.exports.add(n);let o=!1,i=setTimeout(()=>{o=!0,n.abort()},(u=r.timeoutMs)!=null?u:Y),d=new Promise((c,h)=>n.signal.addEventListener("abort",()=>h(new Error("aborted"))));try{let c=await Promise.race([r.run(e,n.signal),d]);N(this.element,{files:c})}catch(c){let h=o?"EXPORT_TIMEOUT":"EXPORT_FAILED";this.ctx.log("export failed",{code:h,cause:String(c)}),this.replyExportFailure(h)}finally{clearTimeout(i),this.exports.delete(n)}}replyExportFailure(e){let r={files:[],error:{code:e}};this.element.dispatchEvent(new CustomEvent(A,{bubbles:!1,composed:!1,detail:r}))}assertUsable(){if(this.destroyed)throw m()}};function R(t,e){t.setAttribute("refresh-token",e.refreshToken),t.setAttribute("bearer-token",e.token)}var k=class{constructor(e){this.config=e;this.instances=[];this.log=ne(e.debug),this.context={config:e,log:this.log,refreshLicense:()=>this.refreshLicense().catch(()=>{}),onDestroyed:r=>{let n=this.instances.indexOf(r);n>=0&&this.instances.splice(n,1)}}}get current(){return this.instances[this.instances.length-1]}load(){return ae(this.config.environment,this.config.version)}async mount(e){let r=ee(e);await this.load();let n=await y.mount(this.context,r);return this.instances.push(n),n}open(){this.requireCurrent().open()}save(){let e=this.current;return e?e.save():Promise.reject(this.notMounted())}refreshSession(){let e=this.current;return e?e.refreshSession():Promise.reject(this.notMounted())}refreshLicense(){return this.licenseRefresh||(this.licenseRefresh=(async()=>{try{let e=await this.config.session.refreshLicense(),r=e==null?void 0:e.licenseToken;if(typeof r!="string"||r==="")throw new s("SESSION_FAILED","session.refreshLicense() must resolve { licenseToken }.");for(let n of this.instances)n.applyLicense(r);this.log("license refreshed")}catch(e){throw this.log("license refresh failed",{cause:String(e)}),e instanceof s?e:new s("SESSION_FAILED","A fresh license token could not be fetched.",{retryable:!0,cause:e})}finally{this.licenseRefresh=void 0}})()),this.licenseRefresh}logout(){for(let e of this.instances)e.logout();this.log("logged out")}destroy(){for(let e of[...this.instances])e.destroy()}requireCurrent(){let e=this.current;if(!e)throw this.notMounted();return e}notMounted(){return a("No builder is mounted. Call mount() first.")}};function Te(t){let e=Z(t);return se(e.environment),new k(e)}var b="tdn_resume",Se="tdn-draft-index";function we(){let t=new URL(window.location.href);return t.searchParams.set(b,"1"),t.pathname+t.search+t.hash}function Ie(t){return/^\/(?![/\\])/.test(t)}function De(){if(typeof window=="undefined")return!1;let t=new URL(window.location.href);return t.searchParams.get(b)!=="1"?!1:(t.searchParams.delete(b),window.history.replaceState(window.history.state,"",t.pathname+t.search+t.hash),!0)}function Le(t){var e;if(typeof localStorage=="undefined")return!1;try{let r=JSON.parse((e=localStorage.getItem(Se))!=null?e:"{}");return Object.values(r).some(n=>(n==null?void 0:n.productId)===t)}catch{return!1}}export{s as BuilderError,b as RESUME_PARAM,De as consumeResumeMarker,Te as createBuilder,Le as hasDraft,Ie as isSafeReturnPath,we as loginReturnPath};
|
|
1
|
+
import{b as B,c as O,d as C,e as A,f as N,g as M,h as F,j as v,k as U,l as V,m as H,n as $,o as j,p as q,r as z,s as W}from"./chunks/chunk-QKY2VACQ.js";var s=class t extends Error{constructor(e,r,n={}){var o,i;super(r),this.name="BuilderError",this.code=e,this.retryable=(o=n.retryable)!=null?o:!1,this.fatal=(i=n.fatal)!=null?i:!1,this.reason=n.reason,this.cause=n.cause,Object.setPrototypeOf(this,t.prototype)}},G={conflict:"Someone else saved this design first.",forbidden:"This shopper may not save this design.",unauthorized:"The shopper could not be signed in to save.","login-cancelled":"The design was not saved because the shopper did not log in.","installation-inactive":"This site's 3DN installation is not active.",license:"This page is not licensed to use the 3DN builder.",locked:"This design was ordered and is locked. Save a copy to make changes.",outdated:"The builder on this page is out of date. Reload the page to save the design.",error:"The design could not be saved. Check the connection and try again."};function K(t){var r;let e=(r=G[t.reason])!=null?r:G.error;return t.reason==="login-cancelled"?new s("LOGIN_CANCELLED",e,{retryable:!0,reason:t.reason,cause:t}):new s("SAVE_FAILED",e,{retryable:t.retryable,reason:t.reason,cause:t})}function X(t){let e=t==="ORIGIN_NOT_ALLOWED"?"This website is not on the 3DN license. Add its hostname to the license.":"The 3DN license token was rejected. The license may be suspended, revoked or expired.";return new s("LICENSE_ERROR",e,{fatal:!0,reason:t,cause:{code:t}})}function m(){return new s("DESTROYED","The builder was destroyed.")}function a(t){return new s("CONFIG_INVALID",t,{fatal:!0})}var de=45e3,Y=12e4,ue=new Set(["environment","version","saveTimeoutMs","session","login","customization","features","onSaved","onImagesSaved","onLicenseError","onCloseRequested","onStatusChange","debug"]),le=new Set(["download","share","save"]),ce=new Set(["target","hostProductId","mode","designId","externalExport","observabilityContext"]),he=/^\d+\.\d+\.\d+$/,fe=/^tdn_inst_/;function S(t){return he.test(t)}function l(t){return typeof t=="object"&&t!==null}function f(t){return typeof t=="function"}function J(t){return typeof t=="number"&&Number.isFinite(t)&&t>0}function Q(t,e=0){return typeof t=="string"?fe.test(t):!l(t)||e>3?!1:Object.values(t).some(r=>Q(r,e+1))}function T(t,e,r){for(let n of Object.keys(t))if(!e.has(n))throw/url|src|host|origin/i.test(n)?a(`${r}: "${n}" is not allowed. The SDK decides where the builder loads from; choose an environment and a version instead.`):a(`${r}: unknown option "${n}".`)}function Z(t){var c,h,_;if(!l(t))throw a("createBuilder() needs a configuration object.");if(Q(t))throw a("createBuilder(): an installation key was passed to the browser. Installation keys stay on your server; pass a session callback instead.");T(t,ue,"createBuilder()");let e=(c=t.environment)!=null?c:"production";if(e!=="production"&&e!=="staging")throw a(`createBuilder(): environment must be "production" or "staging", got ${JSON.stringify(e)}.`);let r=(h=t.version)!=null?h:"latest";if(typeof r!="string"||r!=="latest"&&!S(r))throw a(`createBuilder(): version must be "latest" or an exact release such as "1.2.3", got ${JSON.stringify(r)}.`);let n=(_=t.saveTimeoutMs)!=null?_:de;if(!J(n))throw a("createBuilder(): saveTimeoutMs must be a positive number of milliseconds.");let o=t.session;if(!l(o)||!f(o.get)||!f(o.refreshLicense))throw a("createBuilder(): session.get() and session.refreshLicense() are required. They call your session endpoint.");let i=t.login;if(i!==void 0){if(!l(i)||!f(i.getTokens)||!f(i.onRequired))throw a("createBuilder(): login needs getTokens() (your login-token endpoint) and onRequired() (your login UI).");if(i.onMintFailed!==void 0&&!f(i.onMintFailed))throw a("createBuilder(): login.onMintFailed must be a function.")}let d=t.customization;if(d!==void 0&&(!l(d)||!f(d.record)))throw a("createBuilder(): customization.record() is required when customization is set. It calls your customization endpoint.");let u=t.features;if(u!==void 0){if(!l(u)||Array.isArray(u))throw a("createBuilder(): features must be an object.");T(u,le,"createBuilder() features");for(let[g,P]of Object.entries(u))if(P!==void 0&&typeof P!="boolean")throw a(`createBuilder(): features.${g} must be a boolean.`)}for(let g of["onSaved","onImagesSaved","onLicenseError","onCloseRequested","onStatusChange"])if(t[g]!==void 0&&!f(t[g]))throw a(`createBuilder(): ${g} must be a function.`);return{...t,environment:e,version:r,saveTimeoutMs:n}}function ee(t){var d;if(!l(t))throw a("mount() needs an options object.");T(t,ce,"mount()");let e=t.target;if(typeof HTMLElement=="undefined"||!(e instanceof HTMLElement))throw a("mount(): target must be an HTMLElement on the page.");let r=t.hostProductId;if(typeof r!="string"||r.trim()==="")throw a("mount(): hostProductId must be your own, non-empty product reference.");let n=(d=t.mode)!=null?d:"designer";if(n!=="designer"&&n!=="viewer")throw a(`mount(): mode must be "designer" or "viewer", got ${JSON.stringify(n)}.`);let o=t.designId;if(o!==void 0&&(typeof o!="string"||o===""))throw a("mount(): designId must be a non-empty string.");t.observabilityContext!==void 0&&w(t.observabilityContext,"mount()");let i=t.externalExport;if(i!==void 0){if(!l(i)||!f(i.run))throw a("mount(): externalExport.run() is required when externalExport is set.");if(i.timeoutMs!==void 0&&!J(i.timeoutMs))throw a("mount(): externalExport.timeoutMs must be a positive number of milliseconds.")}return t}function w(t,e){let r;try{r=typeof t=="string"?JSON.parse(t):void 0}catch{r=void 0}if(!l(r)||Array.isArray(r))throw a(`${e}: observabilityContext must be a JSON object string.`);return t}function I(t){let e=o=>new s("SESSION_FAILED",`session.get() returned an invalid session: ${o}.`,{retryable:!1});if(!l(t))throw e("expected an object");if(typeof t.licenseToken!="string"||t.licenseToken==="")throw e("licenseToken is missing");if(typeof t.productId!="string"||t.productId==="")throw e("productId is missing");if(t.viewToken!=null&&typeof t.viewToken!="string")throw e("viewToken must be a string");let r=t.token!=null,n=t.refreshToken!=null;if(r!==n)throw e("token and refreshToken must be returned together");if(r&&(typeof t.token!="string"||typeof t.refreshToken!="string"))throw e("token and refreshToken must be strings");return t}function te(t){if(t===null)return null;if(!l(t)||typeof t.token!="string"||t.token===""||typeof t.refreshToken!="string"||t.refreshToken==="")throw new s("SESSION_FAILED","login.getTokens() must resolve { token, refreshToken } or null.");return t}var pe=/token|secret|key|authorization/i;function D(t,e=0){if(t===null||typeof t!="object"||e>4)return t;if(Array.isArray(t))return t.map(n=>D(n,e+1));let r={};for(let[n,o]of Object.entries(t))r[n]=pe.test(n)&&o!=null?"[redacted]":D(o,e+1);return r}function ne(t){return t?(e,r)=>{r===void 0?console.debug(`[3DN] ${e}`):console.debug(`[3DN] ${e}`,D(r))}:()=>{}}var E="threed-builder",ie={production:"https://3d-builder.3dn.app",staging:void 0},ge=3e4,re=Symbol.for("@3dn-builder/builder/loader");function me(){let t=globalThis,e=t[re];return e||(e={},t[re]=e),e}function ve(){return typeof window!="undefined"&&typeof document!="undefined"&&typeof customElements!="undefined"}function se(t){if(!ie[t])throw a(`createBuilder(): the "${t}" environment is not available in this SDK release.`)}function p(t,e){return new s("LOAD_FAILED",t,{retryable:!0,cause:e})}async function Ee(t,e){if(e!=="latest")return e;let r;try{r=await fetch(`${t}/version-info.json`,{cache:"no-store",credentials:"omit"})}catch(i){throw p("The 3DN builder could not be reached.",i)}if(!r.ok)throw p(`The 3DN builder release could not be resolved (HTTP ${r.status}).`);let n=await r.json().catch(()=>null),o=n==null?void 0:n.version;if(typeof o!="string"||!S(o))throw p("The 3DN builder release information was not valid.");return o}function ye(t){return new Promise((e,r)=>{let n=document.createElement("script");n.type="module",n.src=t,n.crossOrigin="anonymous",n.onload=()=>e(n),n.onerror=()=>{n.remove(),r(p("The 3DN builder failed to load."))},document.head.appendChild(n)})}function be(){return new Promise((t,e)=>{let r=setTimeout(()=>e(p("The 3DN builder loaded but did not start.")),ge);customElements.whenDefined(E).then(()=>{clearTimeout(r),t()},e)})}function oe(t,e,r){if(t.environment&&t.environment!==e)throw new s("VERSION_CONFLICT",`The ${t.environment} builder already runs on this page; ${e} cannot load beside it.`,{fatal:!0});if(r!=="latest"&&t.version&&t.version!==r)throw new s("VERSION_CONFLICT",`Builder ${t.version} already runs on this page; ${r} cannot load beside it.`,{fatal:!0})}async function ae(t,e){if(!ve())throw new s("NOT_IN_BROWSER","The 3DN builder can only load in a browser.");let r=me();if(r.loading){await r.loading,oe(r,t,e);return}if(customElements.get(E))return;let n=ie[t];if(!n)throw a(`The "${t}" environment is not available in this SDK release.`);r.environment=t,r.loading=(async()=>{let o=await Ee(n,e);r.version=o;let i=await ye(`${n}/builder-${o}.js`);try{await be()}catch(d){throw i.remove(),d}})();try{await r.loading}catch(o){throw r.loading=void 0,r.environment=void 0,r.version=void 0,o instanceof s?o:p("The 3DN builder failed to load.",o)}oe(r,t,e)}function L(){let t,e,r=new Promise((n,o)=>{t=n,e=o});return r.catch(()=>{}),{promise:r,resolve:t,reject:e}}var x=class{constructor(e,r){this.onExpire=r;this.startedAt=0;this.remaining=e}start(){this.handle===void 0&&(this.startedAt=Date.now(),this.handle=setTimeout(this.onExpire,this.remaining))}pause(){this.handle!==void 0&&(clearTimeout(this.handle),this.handle=void 0,this.remaining=Math.max(0,this.remaining-(Date.now()-this.startedAt)))}stop(){this.handle!==void 0&&clearTimeout(this.handle),this.handle=void 0}},y=class t{constructor(e,r,n){this.ctx=e;this.options=r;this.epoch=0;this.destroyed=!1;this.loginPending=!1;this.exports=new Set;this.listeners=[];this.currentProductId=n.productId,this.element=this.createElement(n)}static async mount(e,r){let n;try{n=await e.config.session.get({hostProductId:r.hostProductId})}catch(d){throw new s("SESSION_FAILED","The builder session could not be loaded.",{retryable:!0,cause:d})}let o=I(n),i=new t(e,r,o);return r.target.appendChild(i.element),e.log("mounted",{hostProductId:r.hostProductId,productId:o.productId}),i}get productId(){return this.currentProductId}get hostProductId(){return this.options.hostProductId}createElement(e){let r=document.createElement(E);this.attachListeners(r),r.setAttribute("product",e.productId),r.setAttribute("license-token",e.licenseToken),e.viewToken&&r.setAttribute("view-token",e.viewToken),e.token&&e.refreshToken&&R(r,{token:e.token,refreshToken:e.refreshToken}),this.options.designId&&r.setAttribute("design-id",this.options.designId),this.options.mode==="viewer"&&r.setAttribute("display-only","true"),this.options.externalExport&&r.setAttribute("external-export","true");let n=this.ctx.config.features;return(n==null?void 0:n.download)===!1&&r.setAttribute("hide-download","true"),(n==null?void 0:n.share)===!1&&r.setAttribute("hide-share","true"),(n==null?void 0:n.save)===!1&&r.setAttribute("hide-save","true"),this.options.observabilityContext&&r.setAttribute("observability-context",this.options.observabilityContext),r.style.display="block",r.style.width="100%",r.style.height="100%",r}attachListeners(e){let r=(n,o)=>{let i=d=>{d.target!==e||this.destroyed||(this.ctx.log(n,d.detail),o(d.detail))};e.addEventListener(n,i),this.listeners.push([n,i])};r(F,n=>{var o;this.answerLogin((o=n==null?void 0:n.action)!=null?o:"save")}),r(q,()=>{this.ctx.refreshLicense()}),r(U,n=>this.onLicenseError(n)),r(V,n=>{this.onDesignSaved(n)}),r(j,n=>this.finishSave(K(n))),r(H,n=>this.onImagesSettled(n,!0)),r($,n=>this.onImagesSettled(n,!1)),r(M,n=>{this.onProductCloned(n)}),r(W,n=>{var o,i;return(i=(o=this.ctx.config).onCloseRequested)==null?void 0:i.call(o,n)}),r(O,n=>{var o,i;return(i=(o=this.ctx.config).onStatusChange)==null?void 0:i.call(o,n)}),this.options.externalExport&&r(C,n=>{this.answerExport(n)})}open(){this.assertUsable(),B(this.element)}save(){if(this.destroyed)return Promise.reject(m());if(this.fatal)return Promise.reject(this.fatal);if(this.saveRun)return this.saveRun.result.promise;let e={result:L(),timer:new x(this.ctx.config.saveTimeoutMs,()=>this.finishSave(new s("SAVE_TIMEOUT","Saving the design took too long. Try again.",{retryable:!0})))};return this.saveRun=e,this.loginPending||e.timer.start(),z(this.element),e.result.promise}async refreshSession(){this.assertUsable();let e=this.epoch,r;try{r=await this.ctx.config.session.get({hostProductId:this.options.hostProductId})}catch(o){throw new s("SESSION_FAILED","The builder session could not be refreshed.",{retryable:!0,cause:o})}let n=I(r);e!==this.epoch||this.destroyed||(this.applyLicense(n.licenseToken),n.viewToken&&this.element.setAttribute("view-token",n.viewToken),n.token&&n.refreshToken&&R(this.element,{token:n.token,refreshToken:n.refreshToken}),this.fatal=void 0)}logout(){this.destroyed||(this.epoch++,this.element.removeAttribute("bearer-token"),this.element.removeAttribute("refresh-token"),this.loginPending&&(this.loginPending=!1,this.finishSave(new s("LOGIN_CANCELLED","The shopper logged out before the design was saved.",{retryable:!0}))))}destroy(){var e,r;if(!this.destroyed){this.epoch++,this.finishSave(m()),(e=this.cloneWait)==null||e.reject(m()),this.cloneWait=void 0,(r=this.imagesWait)==null||r.resolve(!1),this.imagesWait=void 0;for(let n of this.exports)n.abort();this.destroyed=!0;for(let[n,o]of this.listeners)this.element.removeEventListener(n,o);this.listeners.length=0,this.element.remove(),this.ctx.onDestroyed(this),this.ctx.log("destroyed")}}setObservabilityContext(e){this.assertUsable(),this.element.setAttribute("observability-context",w(e,"setObservabilityContext()"))}applyLicense(e){this.destroyed||this.element.setAttribute("license-token",e)}get isDestroyed(){return this.destroyed}async answerLogin(e){if(this.loginPending)return;let r=this.ctx.config.login;if(!r){v(this.element,{action:e});return}let n=this.epoch,o=()=>n!==this.epoch||this.destroyed;this.setLoginPending(!0);let i=!1;try{for(;;){let d;try{d=te(await r.getTokens())}catch(c){if(o())return;this.ctx.log("login.getTokens() failed",{cause:String(c)});let h=r.onMintFailed?await r.onMintFailed():"cancel";if(o())return;if(h==="retry")continue;v(this.element,{action:e});return}if(o())return;if(d){R(this.element,d);return}let u=await r.onRequired(e);if(o())return;if(u!=="logged-in"){if(u==="redirected"){i=!0;return}v(this.element,{action:e});return}}}finally{!i&&n===this.epoch&&this.setLoginPending(!1)}}setLoginPending(e){this.loginPending=e,this.saveRun&&(e?this.saveRun.timer.pause():this.saveRun.timer.start())}onLicenseError(e){var n,o;let r=X(e.code);this.fatal=r,this.finishSave(r),(o=(n=this.ctx.config).onLicenseError)==null||o.call(n,r)}async onDesignSaved(e){var i;e.productId!==this.currentProductId&&!this.cloneWait&&(this.cloneWait=L()),(i=this.imagesWait)==null||i.resolve(!1);let r=this.imagesWait=L();try{this.cloneWait&&await this.cloneWait.promise,this.unrecordedLink&&await this.recordLink(this.unrecordedLink)}catch(d){this.finishSave(d instanceof s?d:new s("SAVE_FAILED","The design was saved but could not be linked to this shopper.",{retryable:!0,reason:"customization",cause:d}));return}if(this.destroyed)return;let n={productId:e.productId,version:e.version};this.notify("onSaved",n);let o=await r.promise;this.destroyed||(o&&this.notify("onImagesSaved",n),this.finishSave(void 0,n))}onImagesSettled(e,r){let n=this.imagesWait;if(n){this.imagesWait=void 0,n.resolve(r);return}r&&this.notify("onImagesSaved",{productId:e.productId,version:e.version})}notify(e,r){var n,o;try{(o=(n=this.ctx.config)[e])==null||o.call(n,{hostProductId:this.options.hostProductId,...r})}catch(i){this.ctx.log(`${e} threw`,{cause:String(i)})}}async onProductCloned(e){let r={hostProductId:this.options.hostProductId,sourceProductId:e.originalProductId,savedProductId:e.newProductId,asCopy:e.asCopy===!0};this.currentProductId=e.newProductId;let n=this.cloneWait;this.cloneWait=void 0;try{await this.recordLink(r),n==null||n.resolve()}catch(o){n==null||n.reject(o)}}async recordLink(e){let r=this.ctx.config.customization;if(r)try{await r.record(e),this.unrecordedLink===e&&(this.unrecordedLink=void 0)}catch(n){throw this.unrecordedLink=e,new s("SAVE_FAILED","The design was saved but could not be linked to this shopper. Try saving again.",{retryable:!0,reason:"customization",cause:n})}}finishSave(e,r){let n=this.saveRun;n&&(this.saveRun=void 0,n.timer.stop(),e?n.result.reject(e):r&&n.result.resolve(r))}async answerExport(e){var u;let r=this.options.externalExport;if(!r)return;let n=new AbortController;this.exports.add(n);let o=!1,i=setTimeout(()=>{o=!0,n.abort()},(u=r.timeoutMs)!=null?u:Y),d=new Promise((c,h)=>n.signal.addEventListener("abort",()=>h(new Error("aborted"))));try{let c=await Promise.race([r.run(e,n.signal),d]);N(this.element,{files:c})}catch(c){let h=o?"EXPORT_TIMEOUT":"EXPORT_FAILED";this.ctx.log("export failed",{code:h,cause:String(c)}),this.replyExportFailure(h)}finally{clearTimeout(i),this.exports.delete(n)}}replyExportFailure(e){let r={files:[],error:{code:e}};this.element.dispatchEvent(new CustomEvent(A,{bubbles:!1,composed:!1,detail:r}))}assertUsable(){if(this.destroyed)throw m()}};function R(t,e){t.setAttribute("refresh-token",e.refreshToken),t.setAttribute("bearer-token",e.token)}var k=class{constructor(e){this.config=e;this.instances=[];this.log=ne(e.debug),this.context={config:e,log:this.log,refreshLicense:()=>this.refreshLicense().catch(()=>{}),onDestroyed:r=>{let n=this.instances.indexOf(r);n>=0&&this.instances.splice(n,1)}}}get current(){return this.instances[this.instances.length-1]}load(){return ae(this.config.environment,this.config.version)}async mount(e){let r=ee(e);await this.load();let n=await y.mount(this.context,r);return this.instances.push(n),n}open(){this.requireCurrent().open()}save(){let e=this.current;return e?e.save():Promise.reject(this.notMounted())}refreshSession(){let e=this.current;return e?e.refreshSession():Promise.reject(this.notMounted())}refreshLicense(){return this.licenseRefresh||(this.licenseRefresh=(async()=>{try{let e=await this.config.session.refreshLicense(),r=e==null?void 0:e.licenseToken;if(typeof r!="string"||r==="")throw new s("SESSION_FAILED","session.refreshLicense() must resolve { licenseToken }.");for(let n of this.instances)n.applyLicense(r);this.log("license refreshed")}catch(e){throw this.log("license refresh failed",{cause:String(e)}),e instanceof s?e:new s("SESSION_FAILED","A fresh license token could not be fetched.",{retryable:!0,cause:e})}finally{this.licenseRefresh=void 0}})()),this.licenseRefresh}logout(){for(let e of this.instances)e.logout();this.log("logged out")}destroy(){for(let e of[...this.instances])e.destroy()}requireCurrent(){let e=this.current;if(!e)throw this.notMounted();return e}notMounted(){return a("No builder is mounted. Call mount() first.")}};function Te(t){let e=Z(t);return se(e.environment),new k(e)}var b="tdn_resume",Se="tdn-draft-index";function we(){let t=new URL(window.location.href);return t.searchParams.set(b,"1"),t.pathname+t.search+t.hash}function Ie(t){return/^\/(?![/\\])/.test(t)}function De(){if(typeof window=="undefined")return!1;let t=new URL(window.location.href);return t.searchParams.get(b)!=="1"?!1:(t.searchParams.delete(b),window.history.replaceState(window.history.state,"",t.pathname+t.search+t.hash),!0)}function Le(t){var e;if(typeof localStorage=="undefined")return!1;try{let r=JSON.parse((e=localStorage.getItem(Se))!=null?e:"{}");return Object.values(r).some(n=>(n==null?void 0:n.productId)===t)}catch{return!1}}export{s as BuilderError,b as RESUME_PARAM,De as consumeResumeMarker,Te as createBuilder,Le as hasDraft,Ie as isSafeReturnPath,we as loginReturnPath};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
package/testing.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,c as m,d as E,e as u,g as R,h as c,i as l,k as _,l as r,m as v,n as D,o as T,p as L,q as I,s as p}from"./chunks/chunk-
|
|
1
|
+
import{a,c as m,d as E,e as u,g as R,h as c,i as l,k as _,l as r,m as v,n as D,o as T,p as L,q as I,s as p}from"./chunks/chunk-QKY2VACQ.js";var s="threed-builder",S=[a,I,l,u],h=new Set([E]);function A(){class o extends HTMLElement{constructor(){super();this.received=[];this.attributesAtConnect={};for(let e of S)this.addEventListener(e,t=>{t instanceof CustomEvent&&t.fromFake||this.received.push({type:e,detail:t.detail})})}connectedCallback(){this.attributesAtConnect=Object.fromEntries(Array.from(this.attributes,e=>[e.name,e.value])),this.emit(m,{status:"idle"})}emit(e,t){let i=!h.has(e),n=new CustomEvent(e,{bubbles:i,composed:i,detail:t});n.fromFake=!0,this.dispatchEvent(n)}emitSaved(e=1){var t;this.emit(r,{productId:(t=this.getAttribute("product"))!=null?t:"",version:e}),this.emitImagesSaved(e)}async emitSavedAsClone(e,t=1,i=!1){var d;let n=(d=this.getAttribute("product"))!=null?d:"";this.emit(r,{productId:e,version:t}),this.emitImagesSaved(t,e),await new Promise(g=>setTimeout(g,0)),this.emit(R,{originalProductId:n,newProductId:e,name:"Customized",asCopy:i})}emitSaveFailed(e,t=!1){var i;this.emit(T,{productId:(i=this.getAttribute("product"))!=null?i:void 0,reason:e,retryable:t})}emitImagesSaved(e=1,t=(i=>(i=this.getAttribute("product"))!=null?i:"")()){this.emit(v,{productId:t,version:e})}emitImagesSaveFailed(e=1,t=(i=>(i=this.getAttribute("product"))!=null?i:"")()){this.emit(D,{productId:t,version:e})}emitLoginRequired(e="save"){this.emit(c,{action:e})}emitLicenseTokenRequired(){this.emit(L)}emitLicenseError(e){this.emit(_,{code:e})}emitCloseRequested(e){var t;this.emit(p,{productId:(t=this.getAttribute("product"))!=null?t:void 0,hasUnsavedChanges:e})}emitExportRequested(e){this.emit(E,e)}}customElements.define(s,o)}function f(){let o=customElements.get(s);if(o){if("prototype"in o&&"emitSaved"in o.prototype)return;throw new Error("A real <threed-builder> is already defined on this page.")}A()}function B(o=document){return Array.from(o.querySelectorAll(s))}export{B as findFakeBuilders,f as installFakeBuilder};
|
|
2
2
|
//# sourceMappingURL=testing.js.map
|
|
File without changes
|