shopar-plugin 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/shopar-plugin.esm.js +1 -1
- package/dist/shopar-plugin.js +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -32,10 +32,10 @@ There are two distinct ways of integrating the plugin: via Script tag and via NP
|
|
|
32
32
|
Add the following script to your HTML.
|
|
33
33
|
|
|
34
34
|
```html
|
|
35
|
-
<script src="https://cdn.jsdelivr.net/npm/shopar-plugin/shopar-plugin.js"></script>
|
|
35
|
+
<script src="https://cdn.jsdelivr.net/npm/shopar-plugin@0.0.2/dist/shopar-plugin.js"></script>
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
It is possible to use a different CDN instead of [jsDelivr](https://www.jsdelivr.com/) (e.g. [cdnjs](https://cdnjs.com/), [unpkg](https://www.unpkg.com/)), or even a relative path if the plugin is distributed as a static asset to your app. Just make sure to set the `baseUrl` parameter accordingly (see [
|
|
38
|
+
It is possible to use a different CDN instead of [jsDelivr](https://www.jsdelivr.com/) (e.g. [cdnjs](https://cdnjs.com/), [unpkg](https://www.unpkg.com/)), or even a relative path if the plugin is distributed as a static asset to your app. Just make sure to set the `baseUrl` parameter accordingly (see [setup options](#shoparpluginsetupoptions) for more details).
|
|
39
39
|
|
|
40
40
|
### via NPM
|
|
41
41
|
|
|
@@ -99,7 +99,7 @@ Options used for the plugin setup:
|
|
|
99
99
|
- `baseUrl` (optional)
|
|
100
100
|
- Type: `string`
|
|
101
101
|
- If provided, defines where the additional ShopAR plugin files are fetched from.
|
|
102
|
-
- Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin
|
|
102
|
+
- Default value: `https://cdn.jsdelivr.net/npm/shopar-plugin@0.0.2/dist`
|
|
103
103
|
|
|
104
104
|
## License
|
|
105
105
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{d(o.next(e))}catch(e){r(e)}}function a(e){try{d(o.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}d((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=[1e3,2e3,4e3],n=t.length;function o(i,r=0){return e(this,void 0,void 0,(function*(){try{return yield i()}catch(e){if(r>=n)throw e;return yield new Promise((e=>setTimeout(e,t[r]))),o(i,r+1)}}))}let i;const r=()=>i,s=()=>{const t=document.createElement("div"),n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.zIndex="1",n.display="none";const o=window.ShopAR__DeepAR;let i,r;let s;let a=!0;return{domElement:t,init:()=>e(void 0,void 0,void 0,(function*(){return null==r&&(r=e(void 0,void 0,void 0,(function*(){i=yield o.deepar.initialize({licenseKey:"your_license_key_goes_here",previewElement:t,additionalOptions:{hint:"rigidFaceTrackingInit"}})}))),r})),parse:t=>e(void 0,void 0,void 0,(function*(){return null==s&&(s=i.switchEffect(t)),s})),isPaused:()=>a,resume:()=>{a=!1,i.setPaused(a),n.display=""},pause:()=>{a=!0,i.setPaused(a),n.display="none"}}};let a;const d=()=>a,c=()=>{const t=document.createElement("canvas"),n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.zIndex="1";const o=window.ShopAR__THREE,i=o.THREE,r=new i.WebGLRenderer({canvas:t,antialias:!0});r.outputEncoding=i.sRGBEncoding,r.toneMapping=i.LinearToneMapping,r.toneMappingExposure=Math.pow(1.2,5),r.setPixelRatio(2*window.devicePixelRatio),r.setClearColor(new i.Color(16777215)),r.useLegacyLights=!1;const s=new i.PerspectiveCamera(60,1,2,100);s.position.set(8,6,14);const a=new i.Scene,d=new o.OrbitControls(s,r.domElement);d.target.set(0,.03,0),d.dampingFactor=.3;{const e=new i.AmbientLight(new i.Color(16777215),.3),t=new i.DirectionalLight(new i.Color(16777215),.1);t.position.set(10,0,10);const n=new i.DirectionalLight(new i.Color(16777215),.1);n.position.set(-10,0,10),a.add(e,t,n)}const c=()=>{const e=t.clientWidth,n=t.clientHeight;t.width===e&&t.height===n||(r.setSize(e,n,!1),s.aspect=e/n,s.updateProjectionMatrix())};let l;let u=!1;const p=()=>{u||(requestAnimationFrame(p),c(),d.update(),r.render(a,s))};return{domElement:t,updateSize:c,parse:(t,n)=>e(void 0,void 0,void 0,(function*(){return null==l&&(l=e(void 0,void 0,void 0,(function*(){const e=new o.RGBELoader,s=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(o,e.parse(n));s.mapping=i.EquirectangularReflectionMapping,s.encoding=i.LinearEncoding,a.environment=s;const d=(new o.GLTFLoader).setDRACOLoader((new o.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${i.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new o.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${i.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(r)).setMeshoptDecoder("function"==typeof o.MeshoptDecoder?o.MeshoptDecoder():o.MeshoptDecoder),c=yield d.parseAsync(t.buffer,"");a.add(c.scene),a.traverse((e=>{if(e instanceof i.Mesh){const t=e.material;t.depthWrite=!0,t instanceof i.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))),l})),isPaused:()=>u,resume:()=>{u=!1,p(),n.display=""},pause:()=>{u=!0,n.display="none"}}};function l(e,t,n){const o=document.createElement("button");return o.id=e,o.type="button",o.className="shopar-btn",o.textContent=t,o.ariaLabel=n,o.style.zIndex="2",o}const u="0.0.
|
|
1
|
+
function e(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{d(o.next(e))}catch(e){r(e)}}function a(e){try{d(o.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}d((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=[1e3,2e3,4e3],n=t.length;function o(i,r=0){return e(this,void 0,void 0,(function*(){try{return yield i()}catch(e){if(r>=n)throw e;return yield new Promise((e=>setTimeout(e,t[r]))),o(i,r+1)}}))}let i;const r=()=>i,s=()=>{const t=document.createElement("div"),n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.zIndex="1",n.display="none";const o=window.ShopAR__DeepAR;let i,r;let s;let a=!0;return{domElement:t,init:()=>e(void 0,void 0,void 0,(function*(){return null==r&&(r=e(void 0,void 0,void 0,(function*(){i=yield o.deepar.initialize({licenseKey:"your_license_key_goes_here",previewElement:t,additionalOptions:{hint:"rigidFaceTrackingInit"}})}))),r})),parse:t=>e(void 0,void 0,void 0,(function*(){return null==s&&(s=i.switchEffect(t)),s})),isPaused:()=>a,resume:()=>{a=!1,i.setPaused(a),n.display=""},pause:()=>{a=!0,i.setPaused(a),n.display="none"}}};let a;const d=()=>a,c=()=>{const t=document.createElement("canvas"),n=t.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.zIndex="1";const o=window.ShopAR__THREE,i=o.THREE,r=new i.WebGLRenderer({canvas:t,antialias:!0});r.outputEncoding=i.sRGBEncoding,r.toneMapping=i.LinearToneMapping,r.toneMappingExposure=Math.pow(1.2,5),r.setPixelRatio(2*window.devicePixelRatio),r.setClearColor(new i.Color(16777215)),r.useLegacyLights=!1;const s=new i.PerspectiveCamera(60,1,2,100);s.position.set(8,6,14);const a=new i.Scene,d=new o.OrbitControls(s,r.domElement);d.target.set(0,.03,0),d.dampingFactor=.3;{const e=new i.AmbientLight(new i.Color(16777215),.3),t=new i.DirectionalLight(new i.Color(16777215),.1);t.position.set(10,0,10);const n=new i.DirectionalLight(new i.Color(16777215),.1);n.position.set(-10,0,10),a.add(e,t,n)}const c=()=>{const e=t.clientWidth,n=t.clientHeight;t.width===e&&t.height===n||(r.setSize(e,n,!1),s.aspect=e/n,s.updateProjectionMatrix())};let l;let u=!1;const p=()=>{u||(requestAnimationFrame(p),c(),d.update(),r.render(a,s))};return{domElement:t,updateSize:c,parse:(t,n)=>e(void 0,void 0,void 0,(function*(){return null==l&&(l=e(void 0,void 0,void 0,(function*(){const e=new o.RGBELoader,s=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(o,e.parse(n));s.mapping=i.EquirectangularReflectionMapping,s.encoding=i.LinearEncoding,a.environment=s;const d=(new o.GLTFLoader).setDRACOLoader((new o.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${i.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new o.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${i.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(r)).setMeshoptDecoder("function"==typeof o.MeshoptDecoder?o.MeshoptDecoder():o.MeshoptDecoder),c=yield d.parseAsync(t.buffer,"");a.add(c.scene),a.traverse((e=>{if(e instanceof i.Mesh){const t=e.material;t.depthWrite=!0,t instanceof i.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))),l})),isPaused:()=>u,resume:()=>{u=!1,p(),n.display=""},pause:()=>{u=!0,n.display="none"}}};function l(e,t,n){const o=document.createElement("button");return o.id=e,o.type="button",o.className="shopar-btn",o.textContent=t,o.ariaLabel=n,o.style.zIndex="2",o}const u="0.0.2";let p=`https://cdn.jsdelivr.net/npm/shopar-plugin@${u}/dist`;const h={update:e=>{null!=e&&(p=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>p};function f(t){return e(this,void 0,void 0,(function*(){const n=yield o((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(t).catch((e=>{throw console.error(e),new Error("Resource unavailable.")}));if(!e.ok)throw new Error(`Resource download failed with status ${e.status}.`);return e}))));try{return yield(yield n.blob()).arrayBuffer()}catch(e){throw console.error(e),new Error("Resource has invalid body.")}}))}function w(t){return e(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){const e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise((t=>{e.addEventListener("load",(()=>t()),!1),e.addEventListener("error",(()=>t()),!1),document.body.appendChild(e)}))}importScripts(t.toString())}))}const v=[Uint8Array,Uint32Array],m=v.length-2,y=window.location.hostname.charCodeAt(m),g=y^y,E=new v[1]([g]);function b(t,n,i){return e(this,void 0,void 0,(function*(){let r="glb".charCodeAt(0),s="3d".charCodeAt(0);r>>=1,r+=s;const a=String.fromCharCode(r+14);s>>=2,r^=s+2;const d=String.fromCharCode(r-3);r^=5;const c=String.fromCharCode(r-7);r^=2;const l=String.fromCharCode(r-7),u=window[`${c}${d+a+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${l}`],p=yield o((()=>e(this,void 0,void 0,(function*(){const e=yield u(`${t}`).catch((()=>{throw new Error("Unknown error.")}));if(!e.ok)throw new Error("Unknown error.");return e})))),h=new v[0](yield(yield p.blob().catch((()=>{throw new Error("Unknown error.")}))).arrayBuffer().catch((()=>{throw new Error("Unknown error.")})));i+=s;const f=h.byteLength;if(E[g]=Math.min(76,n)*((r>>5)-1),152===E[g]&&(E[g]=f),i==g)return h;i=g,i^=g;for(let e=0,t=h.length;e<t;e++)E[g]^=E[i]<<13,E[g]^=E[i]>>17,E[g]^=E[i]<<5,h[e]=h[e]^E[g];return i^=E[0],i^=E[1],i^=E[2],h}))}function C(e,t){if(null==e)throw new Error(`'${t}' not specified.`)}function P(e,t){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`)}function L(e){const{apiKey:t,sku:n,targetElement:o,baseUrl:i}=e;C(t,"apiKey"),P(t,"apiKey"),C(n,"sku"),P(n,"sku"),C(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new Error(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&P(i,"baseUrl")}var R;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(R||(R={}));let A=R.None,S=0;const x=[];function $(){if(A===R.AR){const e=r();null==e||e.isPaused()||e.pause()}else if(A===R.Preview){const e=d();null==e||e.isPaused()||e.pause()}}function M(e){var t;A=e,x.forEach((e=>null==e?void 0:e.classList.remove("active"))),null===(t=x[A])||void 0===t||t.classList.add("active")}function k(t){return e(this,void 0,void 0,(function*(){L(t);const{apiKey:n,sku:r,targetElement:d}=t;h.update(t.baseUrl);const u=yield function(t,n){return e(this,void 0,void 0,(function*(){const i=yield o((()=>e(this,void 0,void 0,(function*(){const e=yield fetch(`https://dashboard.spexx.ai/plugin?${new URLSearchParams({apiKey:t,sku:n})}`).catch((e=>{throw console.error(e),new Error("API unavailable.")}));if(!e.ok)throw new Error(`API call failed with status ${e.status}.`);return e}))));try{return yield i.json()}catch(e){throw console.error(e),new Error("API returned invalid body.")}}))}(n,r);!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new Error(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(d),d.style.position="relative";const p=function(){const e=document.createElement("div"),t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}();d.appendChild(p);const v=function(){const e=document.createElement("div");return e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e}();p.appendChild(v);const m=function(){const e=document.createElement("div"),t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=document.createElement("div");return i.textContent="Loading...",n.appendChild(i),{container:e,show:()=>{t.display=""},hide:()=>{t.display="none"}}}();p.appendChild(m.container);const{arUrl:y,previewUrl:g}=u;if(null!=y){const t=Promise.all([w(`${h}/shopar-deepar.js`),f(y)]);x[R.AR]=l("shopar-btn-vto","AR","Launch virtual try-on"),v.appendChild(x[R.AR]),x[R.AR].onclick=()=>e(this,void 0,void 0,(function*(){const e=++S,n=R.AR,o=A===n?R.None:n;if($(),M(o),A===R.None)return;m.show();const[,r]=yield t;if(S!==e)return;const a=(null==i&&(i=s()),i);p.contains(a.domElement)||p.appendChild(a.domElement),yield a.init(),S===e&&(yield a.parse(r),S===e&&(a.resume(),m.hide()))}))}if(null!=g){const t=255,n=Promise.all([w(`${h}/shopar-three.js`),b(g,(new Date).getTime()+t,Math.random()*t),f(`${h}/env/studio2.hdr`)]);x[R.Preview]=l("shopar-btn-3d","3D","Launch 3D preview"),v.appendChild(x[R.Preview]),x[R.Preview].onclick=()=>e(this,void 0,void 0,(function*(){const e=++S,t=R.Preview,o=A===t?R.None:t;if($(),M(o),A===R.None)return;m.show();const[,i,r]=yield n;if(S!==e)return;const s=(null==a&&(a=c()),a);p.contains(s.domElement)||(p.appendChild(s.domElement),s.updateSize()),yield s.parse(i,r),S===e&&(s.resume(),m.hide())}))}}))}const T={setup:function(t){return e(this,void 0,void 0,(function*(){!function(t,n){e(this,void 0,void 0,(function*(){try{yield n()}catch(e){throw e instanceof Error?new T.PluginError(`${t} failed: ${e.message}`):(console.error(e),new T.PluginError(`${t} failed.`))}}))}("setup",(()=>k(t)))}))},version:u,PluginError:class extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}};export{T as plugin};
|
package/dist/shopar-plugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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";function t(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{d(o.next(e))}catch(e){r(e)}}function a(e){try{d(o.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}d((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n=[1e3,2e3,4e3],o=n.length;function i(e,r=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(r>=o)throw t;return yield new Promise((e=>setTimeout(e,n[r]))),i(e,r+1)}}))}let r;const s=()=>r,a=()=>{const e=document.createElement("div"),n=e.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.zIndex="1",n.display="none";const o=window.ShopAR__DeepAR;let i,r;let s;let a=!0;return{domElement:e,init:()=>t(void 0,void 0,void 0,(function*(){return null==r&&(r=t(void 0,void 0,void 0,(function*(){i=yield o.deepar.initialize({licenseKey:"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:"rigidFaceTrackingInit"}})}))),r})),parse:e=>t(void 0,void 0,void 0,(function*(){return null==s&&(s=i.switchEffect(e)),s})),isPaused:()=>a,resume:()=>{a=!1,i.setPaused(a),n.display=""},pause:()=>{a=!0,i.setPaused(a),n.display="none"}}};let d;const c=()=>d,l=()=>{const e=document.createElement("canvas"),n=e.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.zIndex="1";const o=window.ShopAR__THREE,i=o.THREE,r=new i.WebGLRenderer({canvas:e,antialias:!0});r.outputEncoding=i.sRGBEncoding,r.toneMapping=i.LinearToneMapping,r.toneMappingExposure=Math.pow(1.2,5),r.setPixelRatio(2*window.devicePixelRatio),r.setClearColor(new i.Color(16777215)),r.useLegacyLights=!1;const s=new i.PerspectiveCamera(60,1,2,100);s.position.set(8,6,14);const a=new i.Scene,d=new o.OrbitControls(s,r.domElement);d.target.set(0,.03,0),d.dampingFactor=.3;{const e=new i.AmbientLight(new i.Color(16777215),.3),t=new i.DirectionalLight(new i.Color(16777215),.1);t.position.set(10,0,10);const n=new i.DirectionalLight(new i.Color(16777215),.1);n.position.set(-10,0,10),a.add(e,t,n)}const c=()=>{const t=e.clientWidth,n=e.clientHeight;e.width===t&&e.height===n||(r.setSize(t,n,!1),s.aspect=t/n,s.updateProjectionMatrix())};let l;let u=!1;const p=()=>{u||(requestAnimationFrame(p),c(),d.update(),r.render(a,s))};return{domElement:e,updateSize:c,parse:(e,n)=>t(void 0,void 0,void 0,(function*(){return null==l&&(l=t(void 0,void 0,void 0,(function*(){const t=new o.RGBELoader,s=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(o,t.parse(n));s.mapping=i.EquirectangularReflectionMapping,s.encoding=i.LinearEncoding,a.environment=s;const d=(new o.GLTFLoader).setDRACOLoader((new o.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${i.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new o.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${i.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(r)).setMeshoptDecoder("function"==typeof o.MeshoptDecoder?o.MeshoptDecoder():o.MeshoptDecoder),c=yield d.parseAsync(e.buffer,"");a.add(c.scene),a.traverse((e=>{if(e instanceof i.Mesh){const t=e.material;t.depthWrite=!0,t instanceof i.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))),l})),isPaused:()=>u,resume:()=>{u=!1,p(),n.display=""},pause:()=>{u=!0,n.display="none"}}};function u(e,t,n){const o=document.createElement("button");return o.id=e,o.type="button",o.className="shopar-btn",o.textContent=t,o.ariaLabel=n,o.style.zIndex="2",o}const p="0.0.
|
|
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";function t(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{d(o.next(e))}catch(e){r(e)}}function a(e){try{d(o.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}d((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n=[1e3,2e3,4e3],o=n.length;function i(e,r=0){return t(this,void 0,void 0,(function*(){try{return yield e()}catch(t){if(r>=o)throw t;return yield new Promise((e=>setTimeout(e,n[r]))),i(e,r+1)}}))}let r;const s=()=>r,a=()=>{const e=document.createElement("div"),n=e.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.zIndex="1",n.display="none";const o=window.ShopAR__DeepAR;let i,r;let s;let a=!0;return{domElement:e,init:()=>t(void 0,void 0,void 0,(function*(){return null==r&&(r=t(void 0,void 0,void 0,(function*(){i=yield o.deepar.initialize({licenseKey:"your_license_key_goes_here",previewElement:e,additionalOptions:{hint:"rigidFaceTrackingInit"}})}))),r})),parse:e=>t(void 0,void 0,void 0,(function*(){return null==s&&(s=i.switchEffect(e)),s})),isPaused:()=>a,resume:()=>{a=!1,i.setPaused(a),n.display=""},pause:()=>{a=!0,i.setPaused(a),n.display="none"}}};let d;const c=()=>d,l=()=>{const e=document.createElement("canvas"),n=e.style;n.position="absolute",n.top="0",n.left="0",n.width="100%",n.height="100%",n.zIndex="1";const o=window.ShopAR__THREE,i=o.THREE,r=new i.WebGLRenderer({canvas:e,antialias:!0});r.outputEncoding=i.sRGBEncoding,r.toneMapping=i.LinearToneMapping,r.toneMappingExposure=Math.pow(1.2,5),r.setPixelRatio(2*window.devicePixelRatio),r.setClearColor(new i.Color(16777215)),r.useLegacyLights=!1;const s=new i.PerspectiveCamera(60,1,2,100);s.position.set(8,6,14);const a=new i.Scene,d=new o.OrbitControls(s,r.domElement);d.target.set(0,.03,0),d.dampingFactor=.3;{const e=new i.AmbientLight(new i.Color(16777215),.3),t=new i.DirectionalLight(new i.Color(16777215),.1);t.position.set(10,0,10);const n=new i.DirectionalLight(new i.Color(16777215),.1);n.position.set(-10,0,10),a.add(e,t,n)}const c=()=>{const t=e.clientWidth,n=e.clientHeight;e.width===t&&e.height===n||(r.setSize(t,n,!1),s.aspect=t/n,s.updateProjectionMatrix())};let l;let u=!1;const p=()=>{u||(requestAnimationFrame(p),c(),d.update(),r.render(a,s))};return{domElement:e,updateSize:c,parse:(e,n)=>t(void 0,void 0,void 0,(function*(){return null==l&&(l=t(void 0,void 0,void 0,(function*(){const t=new o.RGBELoader,s=function(e,t){const n=e.THREE,o=new n.DataTexture(t.data,t.width,t.height,void 0,t.type,void 0,n.ClampToEdgeWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter,1,n.LinearEncoding);return o.flipY=!0,o.generateMipmaps=!1,o.needsUpdate=!0,o}(o,t.parse(n));s.mapping=i.EquirectangularReflectionMapping,s.encoding=i.LinearEncoding,a.environment=s;const d=(new o.GLTFLoader).setDRACOLoader((new o.DRACOLoader).setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${i.REVISION}.0/examples/jsm/libs/draco/gltf/`)).setKTX2Loader((new o.KTX2Loader).setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${i.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(r)).setMeshoptDecoder("function"==typeof o.MeshoptDecoder?o.MeshoptDecoder():o.MeshoptDecoder),c=yield d.parseAsync(e.buffer,"");a.add(c.scene),a.traverse((e=>{if(e instanceof i.Mesh){const t=e.material;t.depthWrite=!0,t instanceof i.MeshPhysicalMaterial&&t.transmissionMap&&(t.transmission=1,t.toneMapped=!1,t.fog=!1,t.needsUpdate=!0)}}))}))),l})),isPaused:()=>u,resume:()=>{u=!1,p(),n.display=""},pause:()=>{u=!0,n.display="none"}}};function u(e,t,n){const o=document.createElement("button");return o.id=e,o.type="button",o.className="shopar-btn",o.textContent=t,o.ariaLabel=n,o.style.zIndex="2",o}const p="0.0.2";let h=`https://cdn.jsdelivr.net/npm/shopar-plugin@${p}/dist`;const f={update:e=>{null!=e&&(h=e.endsWith("/")?e.substring(0,e.length-1):e)},toString:()=>h};function w(e){return t(this,void 0,void 0,(function*(){const n=yield i((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(e).catch((e=>{throw console.error(e),new Error("Resource unavailable.")}));if(!t.ok)throw new Error(`Resource download failed with status ${t.status}.`);return t}))));try{return yield(yield n.blob()).arrayBuffer()}catch(e){throw console.error(e),new Error("Resource has invalid body.")}}))}function m(e){return t(this,void 0,void 0,(function*(){if("function"!=typeof importScripts){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())}))}const v=[Uint8Array,Uint32Array],y=v.length-2,g=window.location.hostname.charCodeAt(y),E=g^g,b=new v[1]([E]);function C(e,n,o){return t(this,void 0,void 0,(function*(){let r="glb".charCodeAt(0),s="3d".charCodeAt(0);r>>=1,r+=s;const a=String.fromCharCode(r+14);s>>=2,r^=s+2;const d=String.fromCharCode(r-3);r^=5;const c=String.fromCharCode(r-7);r^=2;const l=String.fromCharCode(r-7),u=window[`${c}${d+a+(typeof[])[(+!+[]+ +!+[])*(+!+[]+ +!+[])]}${l}`],p=yield i((()=>t(this,void 0,void 0,(function*(){const t=yield u(`${e}`).catch((()=>{throw new Error("Unknown error.")}));if(!t.ok)throw new Error("Unknown error.");return t})))),h=new v[0](yield(yield p.blob().catch((()=>{throw new Error("Unknown error.")}))).arrayBuffer().catch((()=>{throw new Error("Unknown error.")})));o+=s;const f=h.byteLength;if(b[E]=Math.min(76,n)*((r>>5)-1),152===b[E]&&(b[E]=f),o==E)return h;o=E,o^=E;for(let e=0,t=h.length;e<t;e++)b[E]^=b[o]<<13,b[E]^=b[o]>>17,b[E]^=b[o]<<5,h[e]=h[e]^b[E];return o^=b[0],o^=b[1],o^=b[2],h}))}function P(e,t){if(null==e)throw new Error(`'${t}' not specified.`)}function L(e,t){if("string"!=typeof e)throw new Error(`'${t}' must be a string.`)}function R(e){const{apiKey:t,sku:n,targetElement:o,baseUrl:i}=e;P(t,"apiKey"),L(t,"apiKey"),P(n,"sku"),L(n,"sku"),P(o,"targetElement"),function(e,t){if(!(e instanceof HTMLElement))throw new Error(`'${t}' must be an HTMLElement.`)}(o,"targetElement"),null!=i&&L(i,"baseUrl")}var A;!function(e){e[e.None=0]="None",e[e.AR=1]="AR",e[e.Preview=2]="Preview"}(A||(A={}));let x=A.None,S=0;const $=[];function M(){if(x===A.AR){const e=s();null==e||e.isPaused()||e.pause()}else if(x===A.Preview){const e=c();null==e||e.isPaused()||e.pause()}}function T(e){var t;x=e,$.forEach((e=>null==e?void 0:e.classList.remove("active"))),null===(t=$[x])||void 0===t||t.classList.add("active")}function k(e){return t(this,void 0,void 0,(function*(){R(e);const{apiKey:n,sku:o,targetElement:s}=e;f.update(e.baseUrl);const c=yield function(e,n){return t(this,void 0,void 0,(function*(){const o=yield i((()=>t(this,void 0,void 0,(function*(){const t=yield fetch(`https://dashboard.spexx.ai/plugin?${new URLSearchParams({apiKey:e,sku:n})}`).catch((e=>{throw console.error(e),new Error("API unavailable.")}));if(!t.ok)throw new Error(`API call failed with status ${t.status}.`);return t}))));try{return yield o.json()}catch(e){throw console.error(e),new Error("API returned invalid body.")}}))}(n,o);!function(e){const t=getComputedStyle(e);if(!["static","relative"].includes(t.position))throw new Error(`Invalid targetElement's position. Expected 'static' or 'relative', but found '${t.position}'.`)}(s),s.style.position="relative";const p=function(){const e=document.createElement("div"),t=e.style;return t.position="absolute",t.top="0",t.bottom="0",t.left="0",t.right="0",e}();s.appendChild(p);const h=function(){const e=document.createElement("div");return e.role="group",e.ariaLabel="Preview type chooser",e.className="shopar-btn-container",e}();p.appendChild(h);const v=function(){const e=document.createElement("div"),t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.zIndex="1",t.display="none";const n=document.createElement("div"),o=n.style;o.position="absolute",o.width="100%",o.height="100%",o.backgroundColor="#ffffff",o.display="flex",o.justifyContent="center",o.alignItems="center",e.appendChild(n);const i=document.createElement("div");return i.textContent="Loading...",n.appendChild(i),{container:e,show:()=>{t.display=""},hide:()=>{t.display="none"}}}();p.appendChild(v.container);const{arUrl:y,previewUrl:g}=c;if(null!=y){const e=Promise.all([m(`${f}/shopar-deepar.js`),w(y)]);$[A.AR]=u("shopar-btn-vto","AR","Launch virtual try-on"),h.appendChild($[A.AR]),$[A.AR].onclick=()=>t(this,void 0,void 0,(function*(){const t=++S,n=A.AR,o=x===n?A.None:n;if(M(),T(o),x===A.None)return;v.show();const[,i]=yield e;if(S!==t)return;const s=(null==r&&(r=a()),r);p.contains(s.domElement)||p.appendChild(s.domElement),yield s.init(),S===t&&(yield s.parse(i),S===t&&(s.resume(),v.hide()))}))}if(null!=g){const e=255,n=Promise.all([m(`${f}/shopar-three.js`),C(g,(new Date).getTime()+e,Math.random()*e),w(`${f}/env/studio2.hdr`)]);$[A.Preview]=u("shopar-btn-3d","3D","Launch 3D preview"),h.appendChild($[A.Preview]),$[A.Preview].onclick=()=>t(this,void 0,void 0,(function*(){const e=++S,t=A.Preview,o=x===t?A.None:t;if(M(),T(o),x===A.None)return;v.show();const[,i,r]=yield n;if(S!==e)return;const s=(null==d&&(d=l()),d);p.contains(s.domElement)||(p.appendChild(s.domElement),s.updateSize()),yield s.parse(i,r),S===e&&(s.resume(),v.hide())}))}}))}const D={setup:function(e){return t(this,void 0,void 0,(function*(){!function(e,n){t(this,void 0,void 0,(function*(){try{yield n()}catch(t){throw t instanceof Error?new D.PluginError(`${e} failed: ${t.message}`):(console.error(t),new D.PluginError(`${e} failed.`))}}))}("setup",(()=>k(e)))}))},version:p,PluginError:class extends Error{constructor(e){super(`ShopAR Plugin: ${e}`)}}};e.plugin=D}));
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shopar-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
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
|
"scripts": {
|
|
6
6
|
"clean": "rm -rf dist",
|
|
7
7
|
"build": "yarn run clean && rollup -c --environment BUILD_PRODUCTION",
|
|
8
8
|
"build-dev": "yarn run clean && rollup -c",
|
|
9
9
|
"generate-version": "node ci/generate-version.js",
|
|
10
|
+
"prepare-release": "node ci/prepare-release.js",
|
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
12
|
"lint": "eslint"
|
|
12
13
|
},
|