shopar-plugin 1.2.0-alpha.3 → 1.2.0-alpha.4
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,4 +1,4 @@
|
|
|
1
|
-
const e=["AR","3D"];class t extends Error{constructor(e){super(e),this.name="PluginError"}}class n extends t{constructor(e){super(e),this.name="ValidationError"}}class i extends t{constructor(e,t){super(e),this.name="ApiError",this.status=t}}class r extends t{constructor(e){super(e),this.name="SanitizationError"}}class a extends t{constructor(e){super((null==e?void 0:e.trim())||"3D failed to launch."),this.name="Launch3DError"}}class o extends t{constructor(e){super((null==e?void 0:e.trim())||"AR failed to launch."),this.name="LaunchARError"}}class s extends o{constructor(e){super((null==e?void 0:e.trim())||"Camera permission denied."),this.name="CameraPermissionDeniedError"}}class l extends o{constructor(e){super((null==e?void 0:e.trim())||"QR failed."),this.name="QRError"}}function c(e,t,n,i){return new(n||(n=Promise))(function(r,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}l((i=i.apply(e,t||[])).next())})}function h(e){return null!=e&&"object"==typeof e&&"name"in e&&"string"==typeof e.name?e.name:"Unknown"}function A(e){return null!=e&&"object"==typeof e&&"message"in e&&"string"==typeof e.message?e.message:"Unknown error."}"function"==typeof SuppressedError&&SuppressedError;function u(e){if(null!=e&&"object"==typeof e&&"stack"in e&&"string"==typeof e.stack)return e.stack.length>1e3?e.stack.slice(0,1e3):e.stack}function d(e,n){return()=>c(this,void 0,void 0,function*(){try{return yield n()}catch(n){if(n instanceof t)throw n;throw new t(`${e} failed: ${A(n)}`)}})}const p=[Uint8Array,Uint32Array].length-2,f=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],g=[2,12,7,1],m=window[f[g[g[p]]]][f[g[g[g.length-1]]]];function v(){const e=(new TextEncoder).encode(m),t=f.map(e=>e.length);for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[f[t[2]]](String.fromCodePoint(...e))}m.charCodeAt(p);function E(e){return e*(180/Math.PI)}function b(e){return Math.round(100*e)/100}const C=["Glasses","Shoes","Watches","Bracelets","Scarves","Hats","Necklaces"],_=["Shoes"];const I="1.2.0-alpha.3";let x=`https://cdn.jsdelivr.net/npm/shopar-plugin@${I}/dist`;const y=e=>{null!=e&&(x=e.endsWith("/")?e.substring(0,e.length-1):e)},M=()=>x;function w(e,t){return c(this,void 0,void 0,function*(){if("function"!=typeof importScripts){if("function"==typeof window.define&&window.define.amd&&"function"==typeof window.require)return new Promise(n=>{window.require([e],e=>{window[t]=e,n()},()=>{n()})});{const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise(e=>{t.addEventListener("load",()=>e(),!1),t.addEventListener("error",()=>e(),!1),document.body.appendChild(t)})}}importScripts(e.toString())})}let S;function B(e,t){let n=!0;return{qrPaused:()=>n,qrDraw:(i,r)=>c(this,void 0,void 0,function*(){!function(){c(this,void 0,void 0,function*(){null==S&&(S=w(`${M()}/shopar-qr.js`,"ShopAR__QR"))})}(),yield S;const a=`https://ar.shopar.ai/${I.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:i,s:r,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(a),s=new Promise((e,n)=>{t.onload=e,t.onerror=n});t.src=o,yield s,n=!1,e.style.display=""}),qrPause:()=>c(this,void 0,void 0,function*(){n=!0,e.style.display="none"})}}const T={"loading.ar":"Loading Try On...","prompt.ar.shoes":void 0,"prompt.ar.glasses":void 0,"prompt.ar.watches":void 0,"prompt.ar.bracelets":void 0,"prompt.ar.scarves":void 0,"prompt.ar.hats":void 0,"prompt.ar.necklaces":void 0},R=Object.keys(T);const D="--shopar";function Q(e){return`var(${e.var}, ${e.default})`}const L={padding:{var:`${D}-btn-padding`,default:"0.5rem 0.75rem"},gap:{var:`${D}-btn-gap`,default:"0.25rem"},border:{var:`${D}-btn-border`,default:"1px solid #dddddd"},borderRadius:{var:`${D}-btn-border-radius`,default:"calc(infinity * 1px)"},bg:{var:`${D}-btn-bg`,default:"#ffffff"},hoverBg:{var:`${D}-btn-hover-bg`,default:"#f5f5f5"}};function U(e,t,n){const i=document.createElement("button");i.type="button",i.appendChild(n);{const t=document.createElement("span");t.textContent=e,i.appendChild(t)}i.ariaLabel=t;const r=i.style;r.display="none",r.pointerEvents="auto",r.padding=Q(L.padding),r.justifyContent="center",r.alignItems="center",r.gap=Q(L.gap),r.backgroundColor=Q(L.bg),r.border=Q(L.border),r.borderRadius=Q(L.borderRadius),r.cursor="pointer";const a=Q(L.bg),o=Q(L.hoverBg);return i.addEventListener("mouseenter",()=>{r.backgroundColor=o}),i.addEventListener("mouseleave",()=>{r.backgroundColor=a}),i}const P={paddingBottom:{var:`${D}-btn-container-padding-bottom`,default:"2rem"},gap:{var:`${D}-btn-container-gap`,default:"0.5rem"}};const F={bg:{var:`${D}-ar-prompt-bg`,default:"#1e293bb2"},gap:{var:`${D}-ar-prompt-gap`,default:"1rem"},textColor:{var:`${D}-ar-prompt-text-color`,default:"white"},imgMaxWidth:{var:`${D}-ar-prompt-img-max-width`,default:"80%"},imgMaxHeight:{var:`${D}-ar-prompt-img-max-height`,default:"50%"}};const N={containerDisplay:{var:`${D}-ar-loading-container-display`,default:"flex"},containerBg:{var:`${D}-ar-loading-container-bg`,default:"#ffffff"},containerGap:{var:`${D}-ar-loading-container-gap`,default:"1rem"},barWidth:{var:`${D}-ar-loading-bar-width`,default:"80%"},barHeight:{var:`${D}-ar-loading-bar-height`,default:"0.5rem"},barRadius:{var:`${D}-ar-loading-bar-radius`,default:"calc(infinity * 1px)"},barFg:{var:`${D}-ar-loading-bar-fg`,default:"linear-gradient(90deg, #773cd8, #5fb9ec)"},barBg:{var:`${D}-ar-loading-bar-bg`,default:"#e5e7eb"}};const O={bg:{var:`${D}-qr-bg`,default:"#ffffff"}};function k(e,t,n,i){return new(n||(n=Promise))(function(r,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}l((i=i.apply(e,t||[])).next())})}function G(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function H(e,t,n,i,r){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const z=.1,V="function"==typeof Float32Array;function W(e,t){return 1-3*t+3*e}function q(e,t){return 3*t-6*e}function j(e){return 3*e}function Y(e,t,n){return((W(t,n)*e+q(t,n))*e+j(t))*e}function X(e,t,n){return 3*W(t,n)*e*e+2*q(t,n)*e+j(t)}function K(e){return e}function J(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=function(e,t,n,i){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===i)return K;const r=V?new Float32Array(11):new Array(11);for(let t=0;t<11;++t)r[t]=Y(t*z,e,n);function a(t){let i=0,a=1;for(;10!==a&&r[a]<=t;++a)i+=z;--a;const o=i+(t-r[a])/(r[a+1]-r[a])*z,s=X(o,e,n);return s>=.001?function(e,t,n,i){for(let r=0;r<4;++r){const r=X(t,n,i);if(0===r)return t;t-=(Y(t,n,i)-e)/r}return t}(t,o,e,n):0===s?o:function(e,t,n,i,r){let a,o,s=0;do{o=t+(n-t)/2,a=Y(o,i,r)-e,a>0?n=o:t=o}while(Math.abs(a)>1e-7&&++s<10);return o}(t,i,i+z,e,n)}return function(e){return 0===e||1===e?e:Y(a(e),t,i)}}(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function Z(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort((e,t)=>e.time-t.time).map(({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:J(n)}));let i=0,r=n[0].value;const a=()=>{for(i<0&&(i=0);i>=t;)i-=t;for(let e=0;e<n.length-1;e++){const t=n[e],a=n[e+1];if(i>=t.time&&i<a.time){const e=t.interpolate((i-t.time)/(a.time-t.time));r=t.value+e*(a.value-t.value)}}};return{reset:()=>{i=0,a()},update:e=>{i+=e,a()},seek:e=>{i=e,a()},get:()=>r}}const $="time",ee="interpolation",te="pitch",ne=[$,"yaw",te,"fov",ee],ie=Math.PI/180,re="ease-in-out",ae="cubic-bezier(";function oe(e){if("string"==typeof e)return function(e){const[t,...n]=function(e){return e.split(/\r?\n/).map(e=>function(e){const t=e.indexOf("#");return(-1!==t?e.substring(0,t):e).trim()}(e)).filter(e=>""!==e)}(e);if(null==t)throw new Error("Header missing.");const i=function(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n];if(!ne.includes(i))throw new Error(`Invalid token in header: '${i}'.`);if(t.includes(i))throw new Error(`Duplicate token in header: '${i}'.`);t.push(i)}if(!t.includes($))throw new Error(`Missing required token: '${$}'.`);return t}(t.split(/\s+/)),r={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:a}=se(i,e);null!=t&&(null==r.theta&&(r.theta=[]),r.theta.push(t)),null!=n&&(null==r.phi&&(r.phi=[]),r.phi.push(n)),null!=a&&(null==r.fov&&(r.fov=[]),r.fov.push(a))}if(0===Object.values(r).length)throw new Error("At least one parameter should be animated.");return r}(e);if(Array.isArray(e))return function(e){var t;const n={};if(e.length<2)throw new Error("Expected at least two key frames.");for(const i of e){const{time:e,pitch:r,yaw:a,fov:o}=i;if(null==e)throw new Error("Time missing.");const s=ce(null!==(t=i.interpolation)&&void 0!==t?t:re);null!=a&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:a*ie,interpolation:s})),null!=r&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:r*ie,interpolation:s})),null!=o&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:o*ie,interpolation:s}))}if(0===Object.values(n).length)throw new Error("At least one parameter should be animated.");if(Object.values(n).every(t=>t.length!==e.length))throw new Error("All parameters should have the same key frame count.");return n}(e);throw new Error("Expected string or key frame config array.")}function se(e,t){const n=t.match(/[^()\s]+(\(.*?\))?/g);if(null==n||n.length<e.length)throw new Error(`Missing data for fields: '${e.filter(e=>!(null==n?void 0:n.includes(e))).join(", ")}'.`);if(n.length>e.length)throw new Error(`Excess data: '${n.filter(t=>!e.includes(t)).join(", ")}'.`);const i=e.indexOf($),r=function(e){return e.endsWith("ms")?Ae(e.substring(0,e.length-2)):e.endsWith("s")?1e3*Ae(e.substring(0,e.length-1)):Ae(e)}(n[i]),a=e.indexOf(ee),o=ce(-1===a?re:n[a]),s={};for(let t=0;t<n.length;t++){if(t===i||t===a)continue;const l=e[t],c=n[t];switch(l){case"yaw":s.theta={time:r,value:le(c),interpolation:o};break;case te:s.phi={time:r,value:le(c),interpolation:o};break;case"fov":s.fov={time:r,value:le(c),interpolation:o};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function le(e){return e.endsWith("deg")?Ae(e.substring(0,e.length-3))*ie:e.endsWith("rad")?Ae(e.substring(0,e.length-3)):Ae(e)*ie}function ce(e){if("hold"===e)return{type:"hold"};if("linear"===e)return he(0,0,1,1);if("sine"===e)return he(.37,0,.63,1);if("sine-in"===e)return he(.12,0,.39,0);if("sine-out"===e)return he(.61,1,.88,1);if("ease"===e)return he(.25,.1,.25,1);if("ease-in"===e)return he(.42,0,1,1);if("ease-out"===e)return he(0,0,.58,1);if("ease-in-out"===e)return he(.42,0,.58,1);if(e.startsWith(ae)&&e.endsWith(")")){const t=e.substring(13,e.length-1).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:Ae(t[0]),y1:Ae(t[1]),x2:Ae(t[2]),y2:Ae(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function he(e,t,n,i){return{type:"bezier",x1:e,y1:t,x2:n,y2:i}}function Ae(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}
|
|
1
|
+
const e=["AR","3D"];class t extends Error{constructor(e){super(e),this.name="PluginError"}}class n extends t{constructor(e){super(e),this.name="ValidationError"}}class i extends t{constructor(e,t){super(e),this.name="ApiError",this.status=t}}class r extends t{constructor(e){super(e),this.name="SanitizationError"}}class a extends t{constructor(e){super((null==e?void 0:e.trim())||"3D failed to launch."),this.name="Launch3DError"}}class o extends t{constructor(e){super((null==e?void 0:e.trim())||"AR failed to launch."),this.name="LaunchARError"}}class s extends o{constructor(e){super((null==e?void 0:e.trim())||"Camera permission denied."),this.name="CameraPermissionDeniedError"}}class l extends o{constructor(e){super((null==e?void 0:e.trim())||"QR failed."),this.name="QRError"}}function c(e,t,n,i){return new(n||(n=Promise))(function(r,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}l((i=i.apply(e,t||[])).next())})}function h(e){return null!=e&&"object"==typeof e&&"name"in e&&"string"==typeof e.name?e.name:"Unknown"}function A(e){return null!=e&&"object"==typeof e&&"message"in e&&"string"==typeof e.message?e.message:"Unknown error."}"function"==typeof SuppressedError&&SuppressedError;function u(e){if(null!=e&&"object"==typeof e&&"stack"in e&&"string"==typeof e.stack)return e.stack.length>1e3?e.stack.slice(0,1e3):e.stack}function d(e,n){return()=>c(this,void 0,void 0,function*(){try{return yield n()}catch(n){if(n instanceof t)throw n;throw new t(`${e} failed: ${A(n)}`)}})}const p=[Uint8Array,Uint32Array].length-2,f=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],g=[2,12,7,1],m=window[f[g[g[p]]]][f[g[g[g.length-1]]]];function v(){const e=(new TextEncoder).encode(m),t=f.map(e=>e.length);for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[f[t[2]]](String.fromCodePoint(...e))}m.charCodeAt(p);function E(e){return e*(180/Math.PI)}function b(e){return Math.round(100*e)/100}const C=["Glasses","Shoes","Watches","Bracelets","Scarves","Hats","Necklaces"],_=["Shoes"];const I="1.2.0-alpha.4";let x=`https://cdn.jsdelivr.net/npm/shopar-plugin@${I}/dist`;const y=e=>{null!=e&&(x=e.endsWith("/")?e.substring(0,e.length-1):e)},M=()=>x;function w(e,t){return c(this,void 0,void 0,function*(){if("function"!=typeof importScripts){if("function"==typeof window.define&&window.define.amd&&"function"==typeof window.require)return new Promise(n=>{window.require([e],e=>{window[t]=e,n()},()=>{n()})});{const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise(e=>{t.addEventListener("load",()=>e(),!1),t.addEventListener("error",()=>e(),!1),document.body.appendChild(t)})}}importScripts(e.toString())})}let S;function B(e,t){let n=!0;return{qrPaused:()=>n,qrDraw:(i,r)=>c(this,void 0,void 0,function*(){!function(){c(this,void 0,void 0,function*(){null==S&&(S=w(`${M()}/shopar-qr.js`,"ShopAR__QR"))})}(),yield S;const a=`https://ar.shopar.ai/${I.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:i,s:r,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(a),s=new Promise((e,n)=>{t.onload=e,t.onerror=n});t.src=o,yield s,n=!1,e.style.display=""}),qrPause:()=>c(this,void 0,void 0,function*(){n=!0,e.style.display="none"})}}const T={"loading.ar":"Loading Try On...","prompt.ar.shoes":void 0,"prompt.ar.glasses":void 0,"prompt.ar.watches":void 0,"prompt.ar.bracelets":void 0,"prompt.ar.scarves":void 0,"prompt.ar.hats":void 0,"prompt.ar.necklaces":void 0},R=Object.keys(T);const D="--shopar";function Q(e){return`var(${e.var}, ${e.default})`}const L={padding:{var:`${D}-btn-padding`,default:"0.5rem 0.75rem"},gap:{var:`${D}-btn-gap`,default:"0.25rem"},border:{var:`${D}-btn-border`,default:"1px solid #dddddd"},borderRadius:{var:`${D}-btn-border-radius`,default:"calc(infinity * 1px)"},bg:{var:`${D}-btn-bg`,default:"#ffffff"},hoverBg:{var:`${D}-btn-hover-bg`,default:"#f5f5f5"}};function U(e,t,n){const i=document.createElement("button");i.type="button",i.appendChild(n);{const t=document.createElement("span");t.textContent=e,i.appendChild(t)}i.ariaLabel=t;const r=i.style;r.display="none",r.pointerEvents="auto",r.padding=Q(L.padding),r.justifyContent="center",r.alignItems="center",r.gap=Q(L.gap),r.backgroundColor=Q(L.bg),r.border=Q(L.border),r.borderRadius=Q(L.borderRadius),r.cursor="pointer";const a=Q(L.bg),o=Q(L.hoverBg);return i.addEventListener("mouseenter",()=>{r.backgroundColor=o}),i.addEventListener("mouseleave",()=>{r.backgroundColor=a}),i}const P={paddingBottom:{var:`${D}-btn-container-padding-bottom`,default:"2rem"},gap:{var:`${D}-btn-container-gap`,default:"0.5rem"}};const F={bg:{var:`${D}-ar-prompt-bg`,default:"#1e293bb2"},gap:{var:`${D}-ar-prompt-gap`,default:"1rem"},textColor:{var:`${D}-ar-prompt-text-color`,default:"white"},imgMaxWidth:{var:`${D}-ar-prompt-img-max-width`,default:"80%"},imgMaxHeight:{var:`${D}-ar-prompt-img-max-height`,default:"50%"}};const N={containerDisplay:{var:`${D}-ar-loading-container-display`,default:"flex"},containerBg:{var:`${D}-ar-loading-container-bg`,default:"#ffffff"},containerGap:{var:`${D}-ar-loading-container-gap`,default:"1rem"},barWidth:{var:`${D}-ar-loading-bar-width`,default:"80%"},barHeight:{var:`${D}-ar-loading-bar-height`,default:"0.5rem"},barRadius:{var:`${D}-ar-loading-bar-radius`,default:"calc(infinity * 1px)"},barFg:{var:`${D}-ar-loading-bar-fg`,default:"linear-gradient(90deg, #773cd8, #5fb9ec)"},barBg:{var:`${D}-ar-loading-bar-bg`,default:"#e5e7eb"}};const O={bg:{var:`${D}-qr-bg`,default:"#ffffff"}};function k(e,t,n,i){return new(n||(n=Promise))(function(r,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}l((i=i.apply(e,t||[])).next())})}function G(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function H(e,t,n,i,r){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const z=.1,V="function"==typeof Float32Array;function W(e,t){return 1-3*t+3*e}function q(e,t){return 3*t-6*e}function j(e){return 3*e}function Y(e,t,n){return((W(t,n)*e+q(t,n))*e+j(t))*e}function X(e,t,n){return 3*W(t,n)*e*e+2*q(t,n)*e+j(t)}function K(e){return e}function J(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=function(e,t,n,i){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===i)return K;const r=V?new Float32Array(11):new Array(11);for(let t=0;t<11;++t)r[t]=Y(t*z,e,n);function a(t){let i=0,a=1;for(;10!==a&&r[a]<=t;++a)i+=z;--a;const o=i+(t-r[a])/(r[a+1]-r[a])*z,s=X(o,e,n);return s>=.001?function(e,t,n,i){for(let r=0;r<4;++r){const r=X(t,n,i);if(0===r)return t;t-=(Y(t,n,i)-e)/r}return t}(t,o,e,n):0===s?o:function(e,t,n,i,r){let a,o,s=0;do{o=t+(n-t)/2,a=Y(o,i,r)-e,a>0?n=o:t=o}while(Math.abs(a)>1e-7&&++s<10);return o}(t,i,i+z,e,n)}return function(e){return 0===e||1===e?e:Y(a(e),t,i)}}(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function Z(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort((e,t)=>e.time-t.time).map(({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:J(n)}));let i=0,r=n[0].value;const a=()=>{for(i<0&&(i=0);i>=t;)i-=t;for(let e=0;e<n.length-1;e++){const t=n[e],a=n[e+1];if(i>=t.time&&i<a.time){const e=t.interpolate((i-t.time)/(a.time-t.time));r=t.value+e*(a.value-t.value)}}};return{reset:()=>{i=0,a()},update:e=>{i+=e,a()},seek:e=>{i=e,a()},get:()=>r}}const $="time",ee="interpolation",te="pitch",ne=[$,"yaw",te,"fov",ee],ie=Math.PI/180,re="ease-in-out",ae="cubic-bezier(";function oe(e){if("string"==typeof e)return function(e){const[t,...n]=function(e){return e.split(/\r?\n/).map(e=>function(e){const t=e.indexOf("#");return(-1!==t?e.substring(0,t):e).trim()}(e)).filter(e=>""!==e)}(e);if(null==t)throw new Error("Header missing.");const i=function(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n];if(!ne.includes(i))throw new Error(`Invalid token in header: '${i}'.`);if(t.includes(i))throw new Error(`Duplicate token in header: '${i}'.`);t.push(i)}if(!t.includes($))throw new Error(`Missing required token: '${$}'.`);return t}(t.split(/\s+/)),r={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:a}=se(i,e);null!=t&&(null==r.theta&&(r.theta=[]),r.theta.push(t)),null!=n&&(null==r.phi&&(r.phi=[]),r.phi.push(n)),null!=a&&(null==r.fov&&(r.fov=[]),r.fov.push(a))}if(0===Object.values(r).length)throw new Error("At least one parameter should be animated.");return r}(e);if(Array.isArray(e))return function(e){var t;const n={};if(e.length<2)throw new Error("Expected at least two key frames.");for(const i of e){const{time:e,pitch:r,yaw:a,fov:o}=i;if(null==e)throw new Error("Time missing.");const s=ce(null!==(t=i.interpolation)&&void 0!==t?t:re);null!=a&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:a*ie,interpolation:s})),null!=r&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:r*ie,interpolation:s})),null!=o&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:o*ie,interpolation:s}))}if(0===Object.values(n).length)throw new Error("At least one parameter should be animated.");if(Object.values(n).every(t=>t.length!==e.length))throw new Error("All parameters should have the same key frame count.");return n}(e);throw new Error("Expected string or key frame config array.")}function se(e,t){const n=t.match(/[^()\s]+(\(.*?\))?/g);if(null==n||n.length<e.length)throw new Error(`Missing data for fields: '${e.filter(e=>!(null==n?void 0:n.includes(e))).join(", ")}'.`);if(n.length>e.length)throw new Error(`Excess data: '${n.filter(t=>!e.includes(t)).join(", ")}'.`);const i=e.indexOf($),r=function(e){return e.endsWith("ms")?Ae(e.substring(0,e.length-2)):e.endsWith("s")?1e3*Ae(e.substring(0,e.length-1)):Ae(e)}(n[i]),a=e.indexOf(ee),o=ce(-1===a?re:n[a]),s={};for(let t=0;t<n.length;t++){if(t===i||t===a)continue;const l=e[t],c=n[t];switch(l){case"yaw":s.theta={time:r,value:le(c),interpolation:o};break;case te:s.phi={time:r,value:le(c),interpolation:o};break;case"fov":s.fov={time:r,value:le(c),interpolation:o};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function le(e){return e.endsWith("deg")?Ae(e.substring(0,e.length-3))*ie:e.endsWith("rad")?Ae(e.substring(0,e.length-3)):Ae(e)*ie}function ce(e){if("hold"===e)return{type:"hold"};if("linear"===e)return he(0,0,1,1);if("sine"===e)return he(.37,0,.63,1);if("sine-in"===e)return he(.12,0,.39,0);if("sine-out"===e)return he(.61,1,.88,1);if("ease"===e)return he(.25,.1,.25,1);if("ease-in"===e)return he(.42,0,1,1);if("ease-out"===e)return he(0,0,.58,1);if("ease-in-out"===e)return he(.42,0,.58,1);if(e.startsWith(ae)&&e.endsWith(")")){const t=e.substring(13,e.length-1).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:Ae(t[0]),y1:Ae(t[1]),x2:Ae(t[2]),y2:Ae(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function he(e,t,n,i){return{type:"bezier",x1:e,y1:t,x2:n,y2:i}}function Ae(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2010-2024 Three.js Authors
|
package/dist/shopar-plugin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,function(e){"use strict";const t=["AR","3D"];class n extends Error{constructor(e){super(e),this.name="PluginError"}}class i extends n{constructor(e){super(e),this.name="ValidationError"}}class r extends n{constructor(e,t){super(e),this.name="ApiError",this.status=t}}class a extends n{constructor(e){super(e),this.name="SanitizationError"}}class o extends n{constructor(e){super((null==e?void 0:e.trim())||"3D failed to launch."),this.name="Launch3DError"}}class s extends n{constructor(e){super((null==e?void 0:e.trim())||"AR failed to launch."),this.name="LaunchARError"}}class l extends s{constructor(e){super((null==e?void 0:e.trim())||"Camera permission denied."),this.name="CameraPermissionDeniedError"}}class c extends s{constructor(e){super((null==e?void 0:e.trim())||"QR failed."),this.name="QRError"}}function h(e,t,n,i){return new(n||(n=Promise))(function(r,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}l((i=i.apply(e,t||[])).next())})}function A(e){return null!=e&&"object"==typeof e&&"name"in e&&"string"==typeof e.name?e.name:"Unknown"}function u(e){return null!=e&&"object"==typeof e&&"message"in e&&"string"==typeof e.message?e.message:"Unknown error."}"function"==typeof SuppressedError&&SuppressedError;function d(e){if(null!=e&&"object"==typeof e&&"stack"in e&&"string"==typeof e.stack)return e.stack.length>1e3?e.stack.slice(0,1e3):e.stack}function p(e,t){return()=>h(this,void 0,void 0,function*(){try{return yield t()}catch(t){if(t instanceof n)throw t;throw new n(`${e} failed: ${u(t)}`)}})}const f=[Uint8Array,Uint32Array].length-2,g=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],m=[2,12,7,1],v=window[g[m[m[f]]]][g[m[m[m.length-1]]]];function E(){const e=(new TextEncoder).encode(v),t=g.map(e=>e.length);for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[g[t[2]]](String.fromCodePoint(...e))}v.charCodeAt(f);function b(e){return e*(180/Math.PI)}function C(e){return Math.round(100*e)/100}const _=["Glasses","Shoes","Watches","Bracelets","Scarves","Hats","Necklaces"],I=["Shoes"];const x="1.2.0-alpha.3";let y=`https://cdn.jsdelivr.net/npm/shopar-plugin@${x}/dist`;const M=e=>{null!=e&&(y=e.endsWith("/")?e.substring(0,e.length-1):e)},w=()=>y;function S(e,t){return h(this,void 0,void 0,function*(){if("function"!=typeof importScripts){if("function"==typeof window.define&&window.define.amd&&"function"==typeof window.require)return new Promise(n=>{window.require([e],e=>{window[t]=e,n()},()=>{n()})});{const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise(e=>{t.addEventListener("load",()=>e(),!1),t.addEventListener("error",()=>e(),!1),document.body.appendChild(t)})}}importScripts(e.toString())})}let B;function T(e,t){let n=!0;return{qrPaused:()=>n,qrDraw:(i,r)=>h(this,void 0,void 0,function*(){!function(){h(this,void 0,void 0,function*(){null==B&&(B=S(`${w()}/shopar-qr.js`,"ShopAR__QR"))})}(),yield B;const a=`https://ar.shopar.ai/${x.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:i,s:r,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(a),s=new Promise((e,n)=>{t.onload=e,t.onerror=n});t.src=o,yield s,n=!1,e.style.display=""}),qrPause:()=>h(this,void 0,void 0,function*(){n=!0,e.style.display="none"})}}const R={"loading.ar":"Loading Try On...","prompt.ar.shoes":void 0,"prompt.ar.glasses":void 0,"prompt.ar.watches":void 0,"prompt.ar.bracelets":void 0,"prompt.ar.scarves":void 0,"prompt.ar.hats":void 0,"prompt.ar.necklaces":void 0},D=Object.keys(R);const Q="--shopar";function L(e){return`var(${e.var}, ${e.default})`}const U={padding:{var:`${Q}-btn-padding`,default:"0.5rem 0.75rem"},gap:{var:`${Q}-btn-gap`,default:"0.25rem"},border:{var:`${Q}-btn-border`,default:"1px solid #dddddd"},borderRadius:{var:`${Q}-btn-border-radius`,default:"calc(infinity * 1px)"},bg:{var:`${Q}-btn-bg`,default:"#ffffff"},hoverBg:{var:`${Q}-btn-hover-bg`,default:"#f5f5f5"}};function P(e,t,n){const i=document.createElement("button");i.type="button",i.appendChild(n);{const t=document.createElement("span");t.textContent=e,i.appendChild(t)}i.ariaLabel=t;const r=i.style;r.display="none",r.pointerEvents="auto",r.padding=L(U.padding),r.justifyContent="center",r.alignItems="center",r.gap=L(U.gap),r.backgroundColor=L(U.bg),r.border=L(U.border),r.borderRadius=L(U.borderRadius),r.cursor="pointer";const a=L(U.bg),o=L(U.hoverBg);return i.addEventListener("mouseenter",()=>{r.backgroundColor=o}),i.addEventListener("mouseleave",()=>{r.backgroundColor=a}),i}const F={paddingBottom:{var:`${Q}-btn-container-padding-bottom`,default:"2rem"},gap:{var:`${Q}-btn-container-gap`,default:"0.5rem"}};const N={bg:{var:`${Q}-ar-prompt-bg`,default:"#1e293bb2"},gap:{var:`${Q}-ar-prompt-gap`,default:"1rem"},textColor:{var:`${Q}-ar-prompt-text-color`,default:"white"},imgMaxWidth:{var:`${Q}-ar-prompt-img-max-width`,default:"80%"},imgMaxHeight:{var:`${Q}-ar-prompt-img-max-height`,default:"50%"}};const O={containerDisplay:{var:`${Q}-ar-loading-container-display`,default:"flex"},containerBg:{var:`${Q}-ar-loading-container-bg`,default:"#ffffff"},containerGap:{var:`${Q}-ar-loading-container-gap`,default:"1rem"},barWidth:{var:`${Q}-ar-loading-bar-width`,default:"80%"},barHeight:{var:`${Q}-ar-loading-bar-height`,default:"0.5rem"},barRadius:{var:`${Q}-ar-loading-bar-radius`,default:"calc(infinity * 1px)"},barFg:{var:`${Q}-ar-loading-bar-fg`,default:"linear-gradient(90deg, #773cd8, #5fb9ec)"},barBg:{var:`${Q}-ar-loading-bar-bg`,default:"#e5e7eb"}};const k={bg:{var:`${Q}-qr-bg`,default:"#ffffff"}};function G(e,t,n,i){return new(n||(n=Promise))(function(r,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}l((i=i.apply(e,t||[])).next())})}function H(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function z(e,t,n,i,r){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const V=.1,W="function"==typeof Float32Array;function q(e,t){return 1-3*t+3*e}function j(e,t){return 3*t-6*e}function Y(e){return 3*e}function X(e,t,n){return((q(t,n)*e+j(t,n))*e+Y(t))*e}function K(e,t,n){return 3*q(t,n)*e*e+2*j(t,n)*e+Y(t)}function J(e){return e}function Z(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=function(e,t,n,i){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===i)return J;const r=W?new Float32Array(11):new Array(11);for(let t=0;t<11;++t)r[t]=X(t*V,e,n);function a(t){let i=0,a=1;for(;10!==a&&r[a]<=t;++a)i+=V;--a;const o=i+(t-r[a])/(r[a+1]-r[a])*V,s=K(o,e,n);return s>=.001?function(e,t,n,i){for(let r=0;r<4;++r){const r=K(t,n,i);if(0===r)return t;t-=(X(t,n,i)-e)/r}return t}(t,o,e,n):0===s?o:function(e,t,n,i,r){let a,o,s=0;do{o=t+(n-t)/2,a=X(o,i,r)-e,a>0?n=o:t=o}while(Math.abs(a)>1e-7&&++s<10);return o}(t,i,i+V,e,n)}return function(e){return 0===e||1===e?e:X(a(e),t,i)}}(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function $(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort((e,t)=>e.time-t.time).map(({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:Z(n)}));let i=0,r=n[0].value;const a=()=>{for(i<0&&(i=0);i>=t;)i-=t;for(let e=0;e<n.length-1;e++){const t=n[e],a=n[e+1];if(i>=t.time&&i<a.time){const e=t.interpolate((i-t.time)/(a.time-t.time));r=t.value+e*(a.value-t.value)}}};return{reset:()=>{i=0,a()},update:e=>{i+=e,a()},seek:e=>{i=e,a()},get:()=>r}}const ee="time",te="interpolation",ne="pitch",ie=[ee,"yaw",ne,"fov",te],re=Math.PI/180,ae="ease-in-out",oe="cubic-bezier(";function se(e){if("string"==typeof e)return function(e){const[t,...n]=function(e){return e.split(/\r?\n/).map(e=>function(e){const t=e.indexOf("#");return(-1!==t?e.substring(0,t):e).trim()}(e)).filter(e=>""!==e)}(e);if(null==t)throw new Error("Header missing.");const i=function(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n];if(!ie.includes(i))throw new Error(`Invalid token in header: '${i}'.`);if(t.includes(i))throw new Error(`Duplicate token in header: '${i}'.`);t.push(i)}if(!t.includes(ee))throw new Error(`Missing required token: '${ee}'.`);return t}(t.split(/\s+/)),r={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:a}=le(i,e);null!=t&&(null==r.theta&&(r.theta=[]),r.theta.push(t)),null!=n&&(null==r.phi&&(r.phi=[]),r.phi.push(n)),null!=a&&(null==r.fov&&(r.fov=[]),r.fov.push(a))}if(0===Object.values(r).length)throw new Error("At least one parameter should be animated.");return r}(e);if(Array.isArray(e))return function(e){var t;const n={};if(e.length<2)throw new Error("Expected at least two key frames.");for(const i of e){const{time:e,pitch:r,yaw:a,fov:o}=i;if(null==e)throw new Error("Time missing.");const s=he(null!==(t=i.interpolation)&&void 0!==t?t:ae);null!=a&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:a*re,interpolation:s})),null!=r&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:r*re,interpolation:s})),null!=o&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:o*re,interpolation:s}))}if(0===Object.values(n).length)throw new Error("At least one parameter should be animated.");if(Object.values(n).every(t=>t.length!==e.length))throw new Error("All parameters should have the same key frame count.");return n}(e);throw new Error("Expected string or key frame config array.")}function le(e,t){const n=t.match(/[^()\s]+(\(.*?\))?/g);if(null==n||n.length<e.length)throw new Error(`Missing data for fields: '${e.filter(e=>!(null==n?void 0:n.includes(e))).join(", ")}'.`);if(n.length>e.length)throw new Error(`Excess data: '${n.filter(t=>!e.includes(t)).join(", ")}'.`);const i=e.indexOf(ee),r=function(e){return e.endsWith("ms")?ue(e.substring(0,e.length-2)):e.endsWith("s")?1e3*ue(e.substring(0,e.length-1)):ue(e)}(n[i]),a=e.indexOf(te),o=he(-1===a?ae:n[a]),s={};for(let t=0;t<n.length;t++){if(t===i||t===a)continue;const l=e[t],c=n[t];switch(l){case"yaw":s.theta={time:r,value:ce(c),interpolation:o};break;case ne:s.phi={time:r,value:ce(c),interpolation:o};break;case"fov":s.fov={time:r,value:ce(c),interpolation:o};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function ce(e){return e.endsWith("deg")?ue(e.substring(0,e.length-3))*re:e.endsWith("rad")?ue(e.substring(0,e.length-3)):ue(e)*re}function he(e){if("hold"===e)return{type:"hold"};if("linear"===e)return Ae(0,0,1,1);if("sine"===e)return Ae(.37,0,.63,1);if("sine-in"===e)return Ae(.12,0,.39,0);if("sine-out"===e)return Ae(.61,1,.88,1);if("ease"===e)return Ae(.25,.1,.25,1);if("ease-in"===e)return Ae(.42,0,1,1);if("ease-out"===e)return Ae(0,0,.58,1);if("ease-in-out"===e)return Ae(.42,0,.58,1);if(e.startsWith(oe)&&e.endsWith(")")){const t=e.substring(13,e.length-1).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:ue(t[0]),y1:ue(t[1]),x2:ue(t[2]),y2:ue(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function Ae(e,t,n,i){return{type:"bezier",x1:e,y1:t,x2:n,y2:i}}function ue(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ShopAR={})}(this,function(e){"use strict";const t=["AR","3D"];class n extends Error{constructor(e){super(e),this.name="PluginError"}}class i extends n{constructor(e){super(e),this.name="ValidationError"}}class r extends n{constructor(e,t){super(e),this.name="ApiError",this.status=t}}class a extends n{constructor(e){super(e),this.name="SanitizationError"}}class o extends n{constructor(e){super((null==e?void 0:e.trim())||"3D failed to launch."),this.name="Launch3DError"}}class s extends n{constructor(e){super((null==e?void 0:e.trim())||"AR failed to launch."),this.name="LaunchARError"}}class l extends s{constructor(e){super((null==e?void 0:e.trim())||"Camera permission denied."),this.name="CameraPermissionDeniedError"}}class c extends s{constructor(e){super((null==e?void 0:e.trim())||"QR failed."),this.name="QRError"}}function h(e,t,n,i){return new(n||(n=Promise))(function(r,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}l((i=i.apply(e,t||[])).next())})}function A(e){return null!=e&&"object"==typeof e&&"name"in e&&"string"==typeof e.name?e.name:"Unknown"}function u(e){return null!=e&&"object"==typeof e&&"message"in e&&"string"==typeof e.message?e.message:"Unknown error."}"function"==typeof SuppressedError&&SuppressedError;function d(e){if(null!=e&&"object"==typeof e&&"stack"in e&&"string"==typeof e.stack)return e.stack.length>1e3?e.stack.slice(0,1e3):e.stack}function p(e,t){return()=>h(this,void 0,void 0,function*(){try{return yield t()}catch(t){if(t instanceof n)throw t;throw new n(`${e} failed: ${u(t)}`)}})}const f=[Uint8Array,Uint32Array].length-2,g=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],m=[2,12,7,1],v=window[g[m[m[f]]]][g[m[m[m.length-1]]]];function E(){const e=(new TextEncoder).encode(v),t=g.map(e=>e.length);for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[g[t[2]]](String.fromCodePoint(...e))}v.charCodeAt(f);function b(e){return e*(180/Math.PI)}function C(e){return Math.round(100*e)/100}const _=["Glasses","Shoes","Watches","Bracelets","Scarves","Hats","Necklaces"],I=["Shoes"];const x="1.2.0-alpha.4";let y=`https://cdn.jsdelivr.net/npm/shopar-plugin@${x}/dist`;const M=e=>{null!=e&&(y=e.endsWith("/")?e.substring(0,e.length-1):e)},w=()=>y;function S(e,t){return h(this,void 0,void 0,function*(){if("function"!=typeof importScripts){if("function"==typeof window.define&&window.define.amd&&"function"==typeof window.require)return new Promise(n=>{window.require([e],e=>{window[t]=e,n()},()=>{n()})});{const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise(e=>{t.addEventListener("load",()=>e(),!1),t.addEventListener("error",()=>e(),!1),document.body.appendChild(t)})}}importScripts(e.toString())})}let B;function T(e,t){let n=!0;return{qrPaused:()=>n,qrDraw:(i,r)=>h(this,void 0,void 0,function*(){!function(){h(this,void 0,void 0,function*(){null==B&&(B=S(`${w()}/shopar-qr.js`,"ShopAR__QR"))})}(),yield B;const a=`https://ar.shopar.ai/${x.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:i,s:r,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(a),s=new Promise((e,n)=>{t.onload=e,t.onerror=n});t.src=o,yield s,n=!1,e.style.display=""}),qrPause:()=>h(this,void 0,void 0,function*(){n=!0,e.style.display="none"})}}const R={"loading.ar":"Loading Try On...","prompt.ar.shoes":void 0,"prompt.ar.glasses":void 0,"prompt.ar.watches":void 0,"prompt.ar.bracelets":void 0,"prompt.ar.scarves":void 0,"prompt.ar.hats":void 0,"prompt.ar.necklaces":void 0},D=Object.keys(R);const Q="--shopar";function L(e){return`var(${e.var}, ${e.default})`}const U={padding:{var:`${Q}-btn-padding`,default:"0.5rem 0.75rem"},gap:{var:`${Q}-btn-gap`,default:"0.25rem"},border:{var:`${Q}-btn-border`,default:"1px solid #dddddd"},borderRadius:{var:`${Q}-btn-border-radius`,default:"calc(infinity * 1px)"},bg:{var:`${Q}-btn-bg`,default:"#ffffff"},hoverBg:{var:`${Q}-btn-hover-bg`,default:"#f5f5f5"}};function P(e,t,n){const i=document.createElement("button");i.type="button",i.appendChild(n);{const t=document.createElement("span");t.textContent=e,i.appendChild(t)}i.ariaLabel=t;const r=i.style;r.display="none",r.pointerEvents="auto",r.padding=L(U.padding),r.justifyContent="center",r.alignItems="center",r.gap=L(U.gap),r.backgroundColor=L(U.bg),r.border=L(U.border),r.borderRadius=L(U.borderRadius),r.cursor="pointer";const a=L(U.bg),o=L(U.hoverBg);return i.addEventListener("mouseenter",()=>{r.backgroundColor=o}),i.addEventListener("mouseleave",()=>{r.backgroundColor=a}),i}const F={paddingBottom:{var:`${Q}-btn-container-padding-bottom`,default:"2rem"},gap:{var:`${Q}-btn-container-gap`,default:"0.5rem"}};const N={bg:{var:`${Q}-ar-prompt-bg`,default:"#1e293bb2"},gap:{var:`${Q}-ar-prompt-gap`,default:"1rem"},textColor:{var:`${Q}-ar-prompt-text-color`,default:"white"},imgMaxWidth:{var:`${Q}-ar-prompt-img-max-width`,default:"80%"},imgMaxHeight:{var:`${Q}-ar-prompt-img-max-height`,default:"50%"}};const O={containerDisplay:{var:`${Q}-ar-loading-container-display`,default:"flex"},containerBg:{var:`${Q}-ar-loading-container-bg`,default:"#ffffff"},containerGap:{var:`${Q}-ar-loading-container-gap`,default:"1rem"},barWidth:{var:`${Q}-ar-loading-bar-width`,default:"80%"},barHeight:{var:`${Q}-ar-loading-bar-height`,default:"0.5rem"},barRadius:{var:`${Q}-ar-loading-bar-radius`,default:"calc(infinity * 1px)"},barFg:{var:`${Q}-ar-loading-bar-fg`,default:"linear-gradient(90deg, #773cd8, #5fb9ec)"},barBg:{var:`${Q}-ar-loading-bar-bg`,default:"#e5e7eb"}};const k={bg:{var:`${Q}-qr-bg`,default:"#ffffff"}};function G(e,t,n,i){return new(n||(n=Promise))(function(r,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}l((i=i.apply(e,t||[])).next())})}function H(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function z(e,t,n,i,r){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const V=.1,W="function"==typeof Float32Array;function q(e,t){return 1-3*t+3*e}function j(e,t){return 3*t-6*e}function Y(e){return 3*e}function X(e,t,n){return((q(t,n)*e+j(t,n))*e+Y(t))*e}function K(e,t,n){return 3*q(t,n)*e*e+2*j(t,n)*e+Y(t)}function J(e){return e}function Z(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=function(e,t,n,i){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===i)return J;const r=W?new Float32Array(11):new Array(11);for(let t=0;t<11;++t)r[t]=X(t*V,e,n);function a(t){let i=0,a=1;for(;10!==a&&r[a]<=t;++a)i+=V;--a;const o=i+(t-r[a])/(r[a+1]-r[a])*V,s=K(o,e,n);return s>=.001?function(e,t,n,i){for(let r=0;r<4;++r){const r=K(t,n,i);if(0===r)return t;t-=(X(t,n,i)-e)/r}return t}(t,o,e,n):0===s?o:function(e,t,n,i,r){let a,o,s=0;do{o=t+(n-t)/2,a=X(o,i,r)-e,a>0?n=o:t=o}while(Math.abs(a)>1e-7&&++s<10);return o}(t,i,i+V,e,n)}return function(e){return 0===e||1===e?e:X(a(e),t,i)}}(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function $(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort((e,t)=>e.time-t.time).map(({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:Z(n)}));let i=0,r=n[0].value;const a=()=>{for(i<0&&(i=0);i>=t;)i-=t;for(let e=0;e<n.length-1;e++){const t=n[e],a=n[e+1];if(i>=t.time&&i<a.time){const e=t.interpolate((i-t.time)/(a.time-t.time));r=t.value+e*(a.value-t.value)}}};return{reset:()=>{i=0,a()},update:e=>{i+=e,a()},seek:e=>{i=e,a()},get:()=>r}}const ee="time",te="interpolation",ne="pitch",ie=[ee,"yaw",ne,"fov",te],re=Math.PI/180,ae="ease-in-out",oe="cubic-bezier(";function se(e){if("string"==typeof e)return function(e){const[t,...n]=function(e){return e.split(/\r?\n/).map(e=>function(e){const t=e.indexOf("#");return(-1!==t?e.substring(0,t):e).trim()}(e)).filter(e=>""!==e)}(e);if(null==t)throw new Error("Header missing.");const i=function(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n];if(!ie.includes(i))throw new Error(`Invalid token in header: '${i}'.`);if(t.includes(i))throw new Error(`Duplicate token in header: '${i}'.`);t.push(i)}if(!t.includes(ee))throw new Error(`Missing required token: '${ee}'.`);return t}(t.split(/\s+/)),r={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:a}=le(i,e);null!=t&&(null==r.theta&&(r.theta=[]),r.theta.push(t)),null!=n&&(null==r.phi&&(r.phi=[]),r.phi.push(n)),null!=a&&(null==r.fov&&(r.fov=[]),r.fov.push(a))}if(0===Object.values(r).length)throw new Error("At least one parameter should be animated.");return r}(e);if(Array.isArray(e))return function(e){var t;const n={};if(e.length<2)throw new Error("Expected at least two key frames.");for(const i of e){const{time:e,pitch:r,yaw:a,fov:o}=i;if(null==e)throw new Error("Time missing.");const s=he(null!==(t=i.interpolation)&&void 0!==t?t:ae);null!=a&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:a*re,interpolation:s})),null!=r&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:r*re,interpolation:s})),null!=o&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:o*re,interpolation:s}))}if(0===Object.values(n).length)throw new Error("At least one parameter should be animated.");if(Object.values(n).every(t=>t.length!==e.length))throw new Error("All parameters should have the same key frame count.");return n}(e);throw new Error("Expected string or key frame config array.")}function le(e,t){const n=t.match(/[^()\s]+(\(.*?\))?/g);if(null==n||n.length<e.length)throw new Error(`Missing data for fields: '${e.filter(e=>!(null==n?void 0:n.includes(e))).join(", ")}'.`);if(n.length>e.length)throw new Error(`Excess data: '${n.filter(t=>!e.includes(t)).join(", ")}'.`);const i=e.indexOf(ee),r=function(e){return e.endsWith("ms")?ue(e.substring(0,e.length-2)):e.endsWith("s")?1e3*ue(e.substring(0,e.length-1)):ue(e)}(n[i]),a=e.indexOf(te),o=he(-1===a?ae:n[a]),s={};for(let t=0;t<n.length;t++){if(t===i||t===a)continue;const l=e[t],c=n[t];switch(l){case"yaw":s.theta={time:r,value:ce(c),interpolation:o};break;case ne:s.phi={time:r,value:ce(c),interpolation:o};break;case"fov":s.fov={time:r,value:ce(c),interpolation:o};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function ce(e){return e.endsWith("deg")?ue(e.substring(0,e.length-3))*re:e.endsWith("rad")?ue(e.substring(0,e.length-3)):ue(e)*re}function he(e){if("hold"===e)return{type:"hold"};if("linear"===e)return Ae(0,0,1,1);if("sine"===e)return Ae(.37,0,.63,1);if("sine-in"===e)return Ae(.12,0,.39,0);if("sine-out"===e)return Ae(.61,1,.88,1);if("ease"===e)return Ae(.25,.1,.25,1);if("ease-in"===e)return Ae(.42,0,1,1);if("ease-out"===e)return Ae(0,0,.58,1);if("ease-in-out"===e)return Ae(.42,0,.58,1);if(e.startsWith(oe)&&e.endsWith(")")){const t=e.substring(13,e.length-1).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:ue(t[0]),y1:ue(t[1]),x2:ue(t[2]),y2:ue(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function Ae(e,t,n,i){return{type:"bezier",x1:e,y1:t,x2:n,y2:i}}function ue(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2010-2024 Three.js Authors
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shopar-plugin",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.4",
|
|
4
4
|
"description": "Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.",
|
|
5
5
|
"main": "dist/shopar-plugin.esm.js",
|
|
6
6
|
"module": "dist/shopar-plugin.esm.js",
|