shopmate-sdk 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.min.cjs +4 -1
- package/dist/index.min.mjs +4 -1
- package/dist/index.mjs +4 -1
- package/package.json +2 -2
- package/shopmate-sdk.js +4 -1
- package/shopmate-sdk.min.js +4 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)r(i,e,{get:t[e],enumerable:!0})},h=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of d(t))!c.call(i,o)&&o!==e&&r(i,o,{get:()=>t[o],enumerable:!(n=l(t,o))||n.enumerable});return i};var p=i=>h(r({},"__esModule",{value:!0}),i);var u={};m(u,{default:()=>f});module.exports=p(u);var a=class{constructor(t){this.baseUrl="https://shopmate.hoshonto.com";this.cartPosition="right-bottom";this.iframeShown=!1;this.cart={i:[]};this.orgId=t.orgId,t.baseUrl&&(this.baseUrl=t.baseUrl.replace(/\/$/,"")),t.cartPosition&&(this.cartPosition=t.cartPosition),this.checkoutUrl=`${this.baseUrl}/api/v1/pub/checkout`,this.r(),this.l()}t(){return document.body||document.documentElement}s(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}r(){if(document.getElementById("shopmate-global-styles"))return;let t=document.createElement("style");t.id="shopmate-global-styles",t.innerHTML="@keyframes sm-spin{from{transform:rotate(0)}to{transform:rotate(360deg)}}.sm-loading-spinner{display:none;width:24px;height:24px;border:3px solid rgba(255,255,255,.3);border-radius:50%;border-top-color:#fff;animation:.8s linear infinite sm-spin}.sm-btn-loading .sm-loading-spinner{display:block}.sm-btn-loading .sm-cart-icon{display:none}.sm-btn-loading .sm-badge{display:none!important}.sm-no-scroll{overflow:hidden!important;touch-action:none;-ms-touch-action:none}",document.head.appendChild(t)}e(t){let e=t?"add":"remove";document.body.classList[e]("sm-no-scroll"),document.documentElement.classList[e]("sm-no-scroll")}n(t,e){t&&(t.style.pointerEvents=e?"none":"",e?t.classList.add("sm-btn-loading"):t.classList.remove("sm-btn-loading"))}o(t,e=1.15,n=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:n,easing:"ease-in-out"})}d(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},n=this.cartPosition;if(n.includes("top")?e.top=t:n.includes("bottom")?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),n.includes("left"))e.left=t;else if(n.includes("right"))e.right=t;else{e.left="50%";let o=e.transform!=="none"?"translateY(-50%)":"";e.transform=`translateX(-50%) ${o}`.trim()}return e}m(t){if(this.floatingCartButton)return;let e=t||this.t(),n=document.createElement("button");n.type="button",Object.assign(n.style,{width:"60px",height:"60px",borderRadius:"50%",border:"none",background:"#1d4ed8",color:"#ffffff",fontSize:"24px",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 10px 25px rgba(0,0,0,0.2)",cursor:"pointer",zIndex:"2147483646",transition:"transform 0.2s ease"},this.d()),n.innerHTML=`
|
|
2
|
+
<span class="sm-cart-icon">🛒</span>
|
|
3
|
+
<div class="sm-loading-spinner"></div>
|
|
4
|
+
`;let o=document.createElement("span");o.className="sm-badge",Object.assign(o.style,{position:"absolute",top:"0",right:"0",minWidth:"20px",height:"20px",borderRadius:"10px",background:"#ef4444",color:"white",fontSize:"11px",fontWeight:"bold",display:"none",alignItems:"center",justifyContent:"center",border:"2px solid #ffffff",padding:"0 4px"}),n.appendChild(o),n.addEventListener("click",()=>this.openCheckout(n)),e.appendChild(n),this.floatingCartButton=n,this.floatingCartBadge=o}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,n)=>e+n.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}l(){window.addEventListener("message",t=>{var e,n;try{let o=new URL(this.baseUrl).origin;if(t.origin!==o)return;(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((n=t.data)==null?void 0:n.type)==="shopmate:close")&&this.closeCheckout()}catch(o){}})}addToCart(t,e,n){let o=this.cart.i.find(s=>s.i===t);o?o.q=e:this.cart.i.push({i:t,q:e}),n&&(this.o(n,1.15,300),this.h(n)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),n=this.floatingCartButton.getBoundingClientRect(),o=document.createElement("div");Object.assign(o.style,{position:"fixed",left:`${e.left+e.width/2}px`,top:`${e.top+e.height/2}px`,width:"12px",height:"12px",borderRadius:"50%",background:"#1d4ed8",zIndex:"2147483645",pointerEvents:"none",transition:"all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275)"}),this.t().appendChild(o),requestAnimationFrame(()=>{o.style.transform=`translate(${n.left-e.left}px, ${n.top-e.top}px) scale(0.5)`,o.style.opacity="0"}),setTimeout(()=>{o.remove(),this.o(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.n(t,!0),this.iframeElement||(this.iframeElement=this.createCheckoutIframe(),this.t().appendChild(this.iframeElement));let e=new URLSearchParams({orgId:this.orgId.toString(),c:JSON.stringify(this.cart),next:window.location.href});this.iframeElement.src=`${this.checkoutUrl}?${e.toString()}`,this.iframeElement.onload=()=>{this.iframeElement&&this.iframeElement.hasAttribute("src")&&(this.iframeElement.style.display="block",this.iframeShown=!0,this.e(!0),this.n(t,!1))}}createCheckoutIframe(){let t=document.createElement("iframe");return t.setAttribute("sandbox","allow-scripts allow-same-origin allow-popups allow-forms"),t.setAttribute("allow","payment *; fullscreen *;"),Object.assign(t.style,{width:"100vw",height:"100dvh",position:"fixed",top:"0",left:"0",right:"0",bottom:"0",border:"0",zIndex:"2147483647",background:"#ffffff",display:"none"}),t}closeCheckout(){this.iframeElement&&(this.iframeElement.style.display="none",this.iframeShown=!1,this.iframeElement.removeAttribute("src"),this.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let n=e,o=parseInt(n.getAttribute("data-shopmate-product-id")||"",10);isNaN(o)||n.addEventListener("click",s=>{s.preventDefault(),this.addToCart(o,parseInt(n.getAttribute("data-shopmate-quantity")||"1",10),n)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",n=>{n.preventDefault(),this.openCheckout(e)})}),this.s(()=>{this.m(t),this.a()})}};if(typeof window!="undefined"){window.ShopMate=a;let i=document.currentScript;if(i&&i.src){let t=new a({orgId:parseInt(i.dataset.orgId||"2",10),baseUrl:i.dataset.baseUrl||void 0,cartPosition:i.dataset.cartPosition||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=t,t.extract()})}}var f=a;
|
package/dist/index.d.ts
CHANGED
|
@@ -24,8 +24,9 @@ declare class ShopMate {
|
|
|
24
24
|
private _getMountRoot;
|
|
25
25
|
private _runWhenBodyReady;
|
|
26
26
|
constructor(config: ShopMateConfig);
|
|
27
|
+
private _injectGlobalStyles;
|
|
27
28
|
private _setScrollLocked;
|
|
28
|
-
private
|
|
29
|
+
private _toggleLoading;
|
|
29
30
|
private _pop;
|
|
30
31
|
private _getPositionStyles;
|
|
31
32
|
private _ensureFloatingCart;
|
package/dist/index.min.cjs
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)r(i,e,{get:t[e],enumerable:!0})},h=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of d(t))!c.call(i,o)&&o!==e&&r(i,o,{get:()=>t[o],enumerable:!(n=l(t,o))||n.enumerable});return i};var p=i=>h(r({},"__esModule",{value:!0}),i);var u={};m(u,{default:()=>f});module.exports=p(u);var a=class{constructor(t){this.baseUrl="https://shopmate.hoshonto.com";this.cartPosition="right-bottom";this.iframeShown=!1;this.cart={i:[]};this.orgId=t.orgId,t.baseUrl&&(this.baseUrl=t.baseUrl.replace(/\/$/,"")),t.cartPosition&&(this.cartPosition=t.cartPosition),this.checkoutUrl=`${this.baseUrl}/api/v1/pub/checkout`,this.r(),this.l()}t(){return document.body||document.documentElement}s(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}r(){if(document.getElementById("shopmate-global-styles"))return;let t=document.createElement("style");t.id="shopmate-global-styles",t.innerHTML="@keyframes sm-spin{from{transform:rotate(0)}to{transform:rotate(360deg)}}.sm-loading-spinner{display:none;width:24px;height:24px;border:3px solid rgba(255,255,255,.3);border-radius:50%;border-top-color:#fff;animation:.8s linear infinite sm-spin}.sm-btn-loading .sm-loading-spinner{display:block}.sm-btn-loading .sm-cart-icon{display:none}.sm-btn-loading .sm-badge{display:none!important}.sm-no-scroll{overflow:hidden!important;touch-action:none;-ms-touch-action:none}",document.head.appendChild(t)}e(t){let e=t?"add":"remove";document.body.classList[e]("sm-no-scroll"),document.documentElement.classList[e]("sm-no-scroll")}n(t,e){t&&(t.style.pointerEvents=e?"none":"",e?t.classList.add("sm-btn-loading"):t.classList.remove("sm-btn-loading"))}o(t,e=1.15,n=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:n,easing:"ease-in-out"})}d(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},n=this.cartPosition;if(n.includes("top")?e.top=t:n.includes("bottom")?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),n.includes("left"))e.left=t;else if(n.includes("right"))e.right=t;else{e.left="50%";let o=e.transform!=="none"?"translateY(-50%)":"";e.transform=`translateX(-50%) ${o}`.trim()}return e}m(t){if(this.floatingCartButton)return;let e=t||this.t(),n=document.createElement("button");n.type="button",Object.assign(n.style,{width:"60px",height:"60px",borderRadius:"50%",border:"none",background:"#1d4ed8",color:"#ffffff",fontSize:"24px",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 10px 25px rgba(0,0,0,0.2)",cursor:"pointer",zIndex:"2147483646",transition:"transform 0.2s ease"},this.d()),n.innerHTML=`
|
|
2
|
+
<span class="sm-cart-icon">🛒</span>
|
|
3
|
+
<div class="sm-loading-spinner"></div>
|
|
4
|
+
`;let o=document.createElement("span");o.className="sm-badge",Object.assign(o.style,{position:"absolute",top:"0",right:"0",minWidth:"20px",height:"20px",borderRadius:"10px",background:"#ef4444",color:"white",fontSize:"11px",fontWeight:"bold",display:"none",alignItems:"center",justifyContent:"center",border:"2px solid #ffffff",padding:"0 4px"}),n.appendChild(o),n.addEventListener("click",()=>this.openCheckout(n)),e.appendChild(n),this.floatingCartButton=n,this.floatingCartBadge=o}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,n)=>e+n.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}l(){window.addEventListener("message",t=>{var e,n;try{let o=new URL(this.baseUrl).origin;if(t.origin!==o)return;(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((n=t.data)==null?void 0:n.type)==="shopmate:close")&&this.closeCheckout()}catch(o){}})}addToCart(t,e,n){let o=this.cart.i.find(s=>s.i===t);o?o.q=e:this.cart.i.push({i:t,q:e}),n&&(this.o(n,1.15,300),this.h(n)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),n=this.floatingCartButton.getBoundingClientRect(),o=document.createElement("div");Object.assign(o.style,{position:"fixed",left:`${e.left+e.width/2}px`,top:`${e.top+e.height/2}px`,width:"12px",height:"12px",borderRadius:"50%",background:"#1d4ed8",zIndex:"2147483645",pointerEvents:"none",transition:"all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275)"}),this.t().appendChild(o),requestAnimationFrame(()=>{o.style.transform=`translate(${n.left-e.left}px, ${n.top-e.top}px) scale(0.5)`,o.style.opacity="0"}),setTimeout(()=>{o.remove(),this.o(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.n(t,!0),this.iframeElement||(this.iframeElement=this.createCheckoutIframe(),this.t().appendChild(this.iframeElement));let e=new URLSearchParams({orgId:this.orgId.toString(),c:JSON.stringify(this.cart),next:window.location.href});this.iframeElement.src=`${this.checkoutUrl}?${e.toString()}`,this.iframeElement.onload=()=>{this.iframeElement&&this.iframeElement.hasAttribute("src")&&(this.iframeElement.style.display="block",this.iframeShown=!0,this.e(!0),this.n(t,!1))}}createCheckoutIframe(){let t=document.createElement("iframe");return t.setAttribute("sandbox","allow-scripts allow-same-origin allow-popups allow-forms"),t.setAttribute("allow","payment *; fullscreen *;"),Object.assign(t.style,{width:"100vw",height:"100dvh",position:"fixed",top:"0",left:"0",right:"0",bottom:"0",border:"0",zIndex:"2147483647",background:"#ffffff",display:"none"}),t}closeCheckout(){this.iframeElement&&(this.iframeElement.style.display="none",this.iframeShown=!1,this.iframeElement.removeAttribute("src"),this.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let n=e,o=parseInt(n.getAttribute("data-shopmate-product-id")||"",10);isNaN(o)||n.addEventListener("click",s=>{s.preventDefault(),this.addToCart(o,parseInt(n.getAttribute("data-shopmate-quantity")||"1",10),n)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",n=>{n.preventDefault(),this.openCheckout(e)})}),this.s(()=>{this.m(t),this.a()})}};if(typeof window!="undefined"){window.ShopMate=a;let i=document.currentScript;if(i&&i.src){let t=new a({orgId:parseInt(i.dataset.orgId||"2",10),baseUrl:i.dataset.baseUrl||void 0,cartPosition:i.dataset.cartPosition||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=t,t.extract()})}}var f=a;
|
package/dist/index.min.mjs
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=class{constructor(t){this.baseUrl="https://shopmate.hoshonto.com";this.cartPosition="right-bottom";this.iframeShown=!1;this.cart={i:[]};this.orgId=t.orgId,t.baseUrl&&(this.baseUrl=t.baseUrl.replace(/\/$/,"")),t.cartPosition&&(this.cartPosition=t.cartPosition),this.checkoutUrl=`${this.baseUrl}/api/v1/pub/checkout`,this.r(),this.l()}t(){return document.body||document.documentElement}s(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}r(){if(document.getElementById("shopmate-global-styles"))return;let t=document.createElement("style");t.id="shopmate-global-styles",t.innerHTML="@keyframes sm-spin{from{transform:rotate(0)}to{transform:rotate(360deg)}}.sm-loading-spinner{display:none;width:24px;height:24px;border:3px solid rgba(255,255,255,.3);border-radius:50%;border-top-color:#fff;animation:.8s linear infinite sm-spin}.sm-btn-loading .sm-loading-spinner{display:block}.sm-btn-loading .sm-cart-icon{display:none}.sm-btn-loading .sm-badge{display:none!important}.sm-no-scroll{overflow:hidden!important;touch-action:none;-ms-touch-action:none}",document.head.appendChild(t)}e(t){let e=t?"add":"remove";document.body.classList[e]("sm-no-scroll"),document.documentElement.classList[e]("sm-no-scroll")}n(t,e){t&&(t.style.pointerEvents=e?"none":"",e?t.classList.add("sm-btn-loading"):t.classList.remove("sm-btn-loading"))}o(t,e=1.15,n=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:n,easing:"ease-in-out"})}d(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},n=this.cartPosition;if(n.includes("top")?e.top=t:n.includes("bottom")?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),n.includes("left"))e.left=t;else if(n.includes("right"))e.right=t;else{e.left="50%";let o=e.transform!=="none"?"translateY(-50%)":"";e.transform=`translateX(-50%) ${o}`.trim()}return e}m(t){if(this.floatingCartButton)return;let e=t||this.t(),n=document.createElement("button");n.type="button",Object.assign(n.style,{width:"60px",height:"60px",borderRadius:"50%",border:"none",background:"#1d4ed8",color:"#ffffff",fontSize:"24px",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 10px 25px rgba(0,0,0,0.2)",cursor:"pointer",zIndex:"2147483646",transition:"transform 0.2s ease"},this.d()),n.innerHTML=`
|
|
2
|
+
<span class="sm-cart-icon">🛒</span>
|
|
3
|
+
<div class="sm-loading-spinner"></div>
|
|
4
|
+
`;let o=document.createElement("span");o.className="sm-badge",Object.assign(o.style,{position:"absolute",top:"0",right:"0",minWidth:"20px",height:"20px",borderRadius:"10px",background:"#ef4444",color:"white",fontSize:"11px",fontWeight:"bold",display:"none",alignItems:"center",justifyContent:"center",border:"2px solid #ffffff",padding:"0 4px"}),n.appendChild(o),n.addEventListener("click",()=>this.openCheckout(n)),e.appendChild(n),this.floatingCartButton=n,this.floatingCartBadge=o}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,n)=>e+n.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}l(){window.addEventListener("message",t=>{var e,n;try{let o=new URL(this.baseUrl).origin;if(t.origin!==o)return;(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((n=t.data)==null?void 0:n.type)==="shopmate:close")&&this.closeCheckout()}catch(o){}})}addToCart(t,e,n){let o=this.cart.i.find(s=>s.i===t);o?o.q=e:this.cart.i.push({i:t,q:e}),n&&(this.o(n,1.15,300),this.h(n)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),n=this.floatingCartButton.getBoundingClientRect(),o=document.createElement("div");Object.assign(o.style,{position:"fixed",left:`${e.left+e.width/2}px`,top:`${e.top+e.height/2}px`,width:"12px",height:"12px",borderRadius:"50%",background:"#1d4ed8",zIndex:"2147483645",pointerEvents:"none",transition:"all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275)"}),this.t().appendChild(o),requestAnimationFrame(()=>{o.style.transform=`translate(${n.left-e.left}px, ${n.top-e.top}px) scale(0.5)`,o.style.opacity="0"}),setTimeout(()=>{o.remove(),this.o(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.n(t,!0),this.iframeElement||(this.iframeElement=this.createCheckoutIframe(),this.t().appendChild(this.iframeElement));let e=new URLSearchParams({orgId:this.orgId.toString(),c:JSON.stringify(this.cart),next:window.location.href});this.iframeElement.src=`${this.checkoutUrl}?${e.toString()}`,this.iframeElement.onload=()=>{this.iframeElement&&this.iframeElement.hasAttribute("src")&&(this.iframeElement.style.display="block",this.iframeShown=!0,this.e(!0),this.n(t,!1))}}createCheckoutIframe(){let t=document.createElement("iframe");return t.setAttribute("sandbox","allow-scripts allow-same-origin allow-popups allow-forms"),t.setAttribute("allow","payment *; fullscreen *;"),Object.assign(t.style,{width:"100vw",height:"100dvh",position:"fixed",top:"0",left:"0",right:"0",bottom:"0",border:"0",zIndex:"2147483647",background:"#ffffff",display:"none"}),t}closeCheckout(){this.iframeElement&&(this.iframeElement.style.display="none",this.iframeShown=!1,this.iframeElement.removeAttribute("src"),this.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let n=e,o=parseInt(n.getAttribute("data-shopmate-product-id")||"",10);isNaN(o)||n.addEventListener("click",s=>{s.preventDefault(),this.addToCart(o,parseInt(n.getAttribute("data-shopmate-quantity")||"1",10),n)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",n=>{n.preventDefault(),this.openCheckout(e)})}),this.s(()=>{this.m(t),this.a()})}};if(typeof window!="undefined"){window.ShopMate=a;let i=document.currentScript;if(i&&i.src){let t=new a({orgId:parseInt(i.dataset.orgId||"2",10),baseUrl:i.dataset.baseUrl||void 0,cartPosition:i.dataset.cartPosition||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=t,t.extract()})}}var r=a;export{r as default};
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=class{constructor(t){this.baseUrl="https://shopmate.hoshonto.com";this.cartPosition="right-bottom";this.iframeShown=!1;this.cart={i:[]};this.orgId=t.orgId,t.baseUrl&&(this.baseUrl=t.baseUrl.replace(/\/$/,"")),t.cartPosition&&(this.cartPosition=t.cartPosition),this.checkoutUrl=`${this.baseUrl}/api/v1/pub/checkout`,this.r(),this.l()}t(){return document.body||document.documentElement}s(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}r(){if(document.getElementById("shopmate-global-styles"))return;let t=document.createElement("style");t.id="shopmate-global-styles",t.innerHTML="@keyframes sm-spin{from{transform:rotate(0)}to{transform:rotate(360deg)}}.sm-loading-spinner{display:none;width:24px;height:24px;border:3px solid rgba(255,255,255,.3);border-radius:50%;border-top-color:#fff;animation:.8s linear infinite sm-spin}.sm-btn-loading .sm-loading-spinner{display:block}.sm-btn-loading .sm-cart-icon{display:none}.sm-btn-loading .sm-badge{display:none!important}.sm-no-scroll{overflow:hidden!important;touch-action:none;-ms-touch-action:none}",document.head.appendChild(t)}e(t){let e=t?"add":"remove";document.body.classList[e]("sm-no-scroll"),document.documentElement.classList[e]("sm-no-scroll")}n(t,e){t&&(t.style.pointerEvents=e?"none":"",e?t.classList.add("sm-btn-loading"):t.classList.remove("sm-btn-loading"))}o(t,e=1.15,n=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:n,easing:"ease-in-out"})}d(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},n=this.cartPosition;if(n.includes("top")?e.top=t:n.includes("bottom")?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),n.includes("left"))e.left=t;else if(n.includes("right"))e.right=t;else{e.left="50%";let o=e.transform!=="none"?"translateY(-50%)":"";e.transform=`translateX(-50%) ${o}`.trim()}return e}m(t){if(this.floatingCartButton)return;let e=t||this.t(),n=document.createElement("button");n.type="button",Object.assign(n.style,{width:"60px",height:"60px",borderRadius:"50%",border:"none",background:"#1d4ed8",color:"#ffffff",fontSize:"24px",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 10px 25px rgba(0,0,0,0.2)",cursor:"pointer",zIndex:"2147483646",transition:"transform 0.2s ease"},this.d()),n.innerHTML=`
|
|
2
|
+
<span class="sm-cart-icon">🛒</span>
|
|
3
|
+
<div class="sm-loading-spinner"></div>
|
|
4
|
+
`;let o=document.createElement("span");o.className="sm-badge",Object.assign(o.style,{position:"absolute",top:"0",right:"0",minWidth:"20px",height:"20px",borderRadius:"10px",background:"#ef4444",color:"white",fontSize:"11px",fontWeight:"bold",display:"none",alignItems:"center",justifyContent:"center",border:"2px solid #ffffff",padding:"0 4px"}),n.appendChild(o),n.addEventListener("click",()=>this.openCheckout(n)),e.appendChild(n),this.floatingCartButton=n,this.floatingCartBadge=o}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,n)=>e+n.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}l(){window.addEventListener("message",t=>{var e,n;try{let o=new URL(this.baseUrl).origin;if(t.origin!==o)return;(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((n=t.data)==null?void 0:n.type)==="shopmate:close")&&this.closeCheckout()}catch(o){}})}addToCart(t,e,n){let o=this.cart.i.find(s=>s.i===t);o?o.q=e:this.cart.i.push({i:t,q:e}),n&&(this.o(n,1.15,300),this.h(n)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),n=this.floatingCartButton.getBoundingClientRect(),o=document.createElement("div");Object.assign(o.style,{position:"fixed",left:`${e.left+e.width/2}px`,top:`${e.top+e.height/2}px`,width:"12px",height:"12px",borderRadius:"50%",background:"#1d4ed8",zIndex:"2147483645",pointerEvents:"none",transition:"all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275)"}),this.t().appendChild(o),requestAnimationFrame(()=>{o.style.transform=`translate(${n.left-e.left}px, ${n.top-e.top}px) scale(0.5)`,o.style.opacity="0"}),setTimeout(()=>{o.remove(),this.o(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.n(t,!0),this.iframeElement||(this.iframeElement=this.createCheckoutIframe(),this.t().appendChild(this.iframeElement));let e=new URLSearchParams({orgId:this.orgId.toString(),c:JSON.stringify(this.cart),next:window.location.href});this.iframeElement.src=`${this.checkoutUrl}?${e.toString()}`,this.iframeElement.onload=()=>{this.iframeElement&&this.iframeElement.hasAttribute("src")&&(this.iframeElement.style.display="block",this.iframeShown=!0,this.e(!0),this.n(t,!1))}}createCheckoutIframe(){let t=document.createElement("iframe");return t.setAttribute("sandbox","allow-scripts allow-same-origin allow-popups allow-forms"),t.setAttribute("allow","payment *; fullscreen *;"),Object.assign(t.style,{width:"100vw",height:"100dvh",position:"fixed",top:"0",left:"0",right:"0",bottom:"0",border:"0",zIndex:"2147483647",background:"#ffffff",display:"none"}),t}closeCheckout(){this.iframeElement&&(this.iframeElement.style.display="none",this.iframeShown=!1,this.iframeElement.removeAttribute("src"),this.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let n=e,o=parseInt(n.getAttribute("data-shopmate-product-id")||"",10);isNaN(o)||n.addEventListener("click",s=>{s.preventDefault(),this.addToCart(o,parseInt(n.getAttribute("data-shopmate-quantity")||"1",10),n)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",n=>{n.preventDefault(),this.openCheckout(e)})}),this.s(()=>{this.m(t),this.a()})}};if(typeof window!="undefined"){window.ShopMate=a;let i=document.currentScript;if(i&&i.src){let t=new a({orgId:parseInt(i.dataset.orgId||"2",10),baseUrl:i.dataset.baseUrl||void 0,cartPosition:i.dataset.cartPosition||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=t,t.extract()})}}var r=a;export{r as default};
|
package/package.json
CHANGED
package/shopmate-sdk.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
"use strict";var ShopmateExtractor=(()=>{var
|
|
1
|
+
"use strict";var ShopmateExtractor=(()=>{var r=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)r(i,e,{get:t[e],enumerable:!0})},h=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of d(t))!c.call(i,o)&&o!==e&&r(i,o,{get:()=>t[o],enumerable:!(n=l(t,o))||n.enumerable});return i};var p=i=>h(r({},"__esModule",{value:!0}),i);var u={};m(u,{default:()=>f});var a=class{constructor(t){this.baseUrl="https://shopmate.hoshonto.com";this.cartPosition="right-bottom";this.iframeShown=!1;this.cart={i:[]};this.orgId=t.orgId,t.baseUrl&&(this.baseUrl=t.baseUrl.replace(/\/$/,"")),t.cartPosition&&(this.cartPosition=t.cartPosition),this.checkoutUrl=`${this.baseUrl}/api/v1/pub/checkout`,this.r(),this.l()}t(){return document.body||document.documentElement}s(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}r(){if(document.getElementById("shopmate-global-styles"))return;let t=document.createElement("style");t.id="shopmate-global-styles",t.innerHTML="@keyframes sm-spin{from{transform:rotate(0)}to{transform:rotate(360deg)}}.sm-loading-spinner{display:none;width:24px;height:24px;border:3px solid rgba(255,255,255,.3);border-radius:50%;border-top-color:#fff;animation:.8s linear infinite sm-spin}.sm-btn-loading .sm-loading-spinner{display:block}.sm-btn-loading .sm-cart-icon{display:none}.sm-btn-loading .sm-badge{display:none!important}.sm-no-scroll{overflow:hidden!important;touch-action:none;-ms-touch-action:none}",document.head.appendChild(t)}e(t){let e=t?"add":"remove";document.body.classList[e]("sm-no-scroll"),document.documentElement.classList[e]("sm-no-scroll")}n(t,e){t&&(t.style.pointerEvents=e?"none":"",e?t.classList.add("sm-btn-loading"):t.classList.remove("sm-btn-loading"))}o(t,e=1.15,n=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:n,easing:"ease-in-out"})}d(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},n=this.cartPosition;if(n.includes("top")?e.top=t:n.includes("bottom")?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),n.includes("left"))e.left=t;else if(n.includes("right"))e.right=t;else{e.left="50%";let o=e.transform!=="none"?"translateY(-50%)":"";e.transform=`translateX(-50%) ${o}`.trim()}return e}m(t){if(this.floatingCartButton)return;let e=t||this.t(),n=document.createElement("button");n.type="button",Object.assign(n.style,{width:"60px",height:"60px",borderRadius:"50%",border:"none",background:"#1d4ed8",color:"#ffffff",fontSize:"24px",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 10px 25px rgba(0,0,0,0.2)",cursor:"pointer",zIndex:"2147483646",transition:"transform 0.2s ease"},this.d()),n.innerHTML=`
|
|
2
|
+
<span class="sm-cart-icon">🛒</span>
|
|
3
|
+
<div class="sm-loading-spinner"></div>
|
|
4
|
+
`;let o=document.createElement("span");o.className="sm-badge",Object.assign(o.style,{position:"absolute",top:"0",right:"0",minWidth:"20px",height:"20px",borderRadius:"10px",background:"#ef4444",color:"white",fontSize:"11px",fontWeight:"bold",display:"none",alignItems:"center",justifyContent:"center",border:"2px solid #ffffff",padding:"0 4px"}),n.appendChild(o),n.addEventListener("click",()=>this.openCheckout(n)),e.appendChild(n),this.floatingCartButton=n,this.floatingCartBadge=o}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,n)=>e+n.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}l(){window.addEventListener("message",t=>{var e,n;try{let o=new URL(this.baseUrl).origin;if(t.origin!==o)return;(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((n=t.data)==null?void 0:n.type)==="shopmate:close")&&this.closeCheckout()}catch(o){}})}addToCart(t,e,n){let o=this.cart.i.find(s=>s.i===t);o?o.q=e:this.cart.i.push({i:t,q:e}),n&&(this.o(n,1.15,300),this.h(n)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),n=this.floatingCartButton.getBoundingClientRect(),o=document.createElement("div");Object.assign(o.style,{position:"fixed",left:`${e.left+e.width/2}px`,top:`${e.top+e.height/2}px`,width:"12px",height:"12px",borderRadius:"50%",background:"#1d4ed8",zIndex:"2147483645",pointerEvents:"none",transition:"all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275)"}),this.t().appendChild(o),requestAnimationFrame(()=>{o.style.transform=`translate(${n.left-e.left}px, ${n.top-e.top}px) scale(0.5)`,o.style.opacity="0"}),setTimeout(()=>{o.remove(),this.o(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.n(t,!0),this.iframeElement||(this.iframeElement=this.createCheckoutIframe(),this.t().appendChild(this.iframeElement));let e=new URLSearchParams({orgId:this.orgId.toString(),c:JSON.stringify(this.cart),next:window.location.href});this.iframeElement.src=`${this.checkoutUrl}?${e.toString()}`,this.iframeElement.onload=()=>{this.iframeElement&&this.iframeElement.hasAttribute("src")&&(this.iframeElement.style.display="block",this.iframeShown=!0,this.e(!0),this.n(t,!1))}}createCheckoutIframe(){let t=document.createElement("iframe");return t.setAttribute("sandbox","allow-scripts allow-same-origin allow-popups allow-forms"),t.setAttribute("allow","payment *; fullscreen *;"),Object.assign(t.style,{width:"100vw",height:"100dvh",position:"fixed",top:"0",left:"0",right:"0",bottom:"0",border:"0",zIndex:"2147483647",background:"#ffffff",display:"none"}),t}closeCheckout(){this.iframeElement&&(this.iframeElement.style.display="none",this.iframeShown=!1,this.iframeElement.removeAttribute("src"),this.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let n=e,o=parseInt(n.getAttribute("data-shopmate-product-id")||"",10);isNaN(o)||n.addEventListener("click",s=>{s.preventDefault(),this.addToCart(o,parseInt(n.getAttribute("data-shopmate-quantity")||"1",10),n)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",n=>{n.preventDefault(),this.openCheckout(e)})}),this.s(()=>{this.m(t),this.a()})}};if(typeof window!="undefined"){window.ShopMate=a;let i=document.currentScript;if(i&&i.src){let t=new a({orgId:parseInt(i.dataset.orgId||"2",10),baseUrl:i.dataset.baseUrl||void 0,cartPosition:i.dataset.cartPosition||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=t,t.extract()})}}var f=a;return p(u);})();
|
package/shopmate-sdk.min.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
"use strict";var ShopmateExtractor=(()=>{var
|
|
1
|
+
"use strict";var ShopmateExtractor=(()=>{var r=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)r(i,e,{get:t[e],enumerable:!0})},h=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of d(t))!c.call(i,o)&&o!==e&&r(i,o,{get:()=>t[o],enumerable:!(n=l(t,o))||n.enumerable});return i};var p=i=>h(r({},"__esModule",{value:!0}),i);var u={};m(u,{default:()=>f});var a=class{constructor(t){this.baseUrl="https://shopmate.hoshonto.com";this.cartPosition="right-bottom";this.iframeShown=!1;this.cart={i:[]};this.orgId=t.orgId,t.baseUrl&&(this.baseUrl=t.baseUrl.replace(/\/$/,"")),t.cartPosition&&(this.cartPosition=t.cartPosition),this.checkoutUrl=`${this.baseUrl}/api/v1/pub/checkout`,this.r(),this.l()}t(){return document.body||document.documentElement}s(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}r(){if(document.getElementById("shopmate-global-styles"))return;let t=document.createElement("style");t.id="shopmate-global-styles",t.innerHTML="@keyframes sm-spin{from{transform:rotate(0)}to{transform:rotate(360deg)}}.sm-loading-spinner{display:none;width:24px;height:24px;border:3px solid rgba(255,255,255,.3);border-radius:50%;border-top-color:#fff;animation:.8s linear infinite sm-spin}.sm-btn-loading .sm-loading-spinner{display:block}.sm-btn-loading .sm-cart-icon{display:none}.sm-btn-loading .sm-badge{display:none!important}.sm-no-scroll{overflow:hidden!important;touch-action:none;-ms-touch-action:none}",document.head.appendChild(t)}e(t){let e=t?"add":"remove";document.body.classList[e]("sm-no-scroll"),document.documentElement.classList[e]("sm-no-scroll")}n(t,e){t&&(t.style.pointerEvents=e?"none":"",e?t.classList.add("sm-btn-loading"):t.classList.remove("sm-btn-loading"))}o(t,e=1.15,n=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:n,easing:"ease-in-out"})}d(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},n=this.cartPosition;if(n.includes("top")?e.top=t:n.includes("bottom")?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),n.includes("left"))e.left=t;else if(n.includes("right"))e.right=t;else{e.left="50%";let o=e.transform!=="none"?"translateY(-50%)":"";e.transform=`translateX(-50%) ${o}`.trim()}return e}m(t){if(this.floatingCartButton)return;let e=t||this.t(),n=document.createElement("button");n.type="button",Object.assign(n.style,{width:"60px",height:"60px",borderRadius:"50%",border:"none",background:"#1d4ed8",color:"#ffffff",fontSize:"24px",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 10px 25px rgba(0,0,0,0.2)",cursor:"pointer",zIndex:"2147483646",transition:"transform 0.2s ease"},this.d()),n.innerHTML=`
|
|
2
|
+
<span class="sm-cart-icon">🛒</span>
|
|
3
|
+
<div class="sm-loading-spinner"></div>
|
|
4
|
+
`;let o=document.createElement("span");o.className="sm-badge",Object.assign(o.style,{position:"absolute",top:"0",right:"0",minWidth:"20px",height:"20px",borderRadius:"10px",background:"#ef4444",color:"white",fontSize:"11px",fontWeight:"bold",display:"none",alignItems:"center",justifyContent:"center",border:"2px solid #ffffff",padding:"0 4px"}),n.appendChild(o),n.addEventListener("click",()=>this.openCheckout(n)),e.appendChild(n),this.floatingCartButton=n,this.floatingCartBadge=o}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,n)=>e+n.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}l(){window.addEventListener("message",t=>{var e,n;try{let o=new URL(this.baseUrl).origin;if(t.origin!==o)return;(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((n=t.data)==null?void 0:n.type)==="shopmate:close")&&this.closeCheckout()}catch(o){}})}addToCart(t,e,n){let o=this.cart.i.find(s=>s.i===t);o?o.q=e:this.cart.i.push({i:t,q:e}),n&&(this.o(n,1.15,300),this.h(n)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),n=this.floatingCartButton.getBoundingClientRect(),o=document.createElement("div");Object.assign(o.style,{position:"fixed",left:`${e.left+e.width/2}px`,top:`${e.top+e.height/2}px`,width:"12px",height:"12px",borderRadius:"50%",background:"#1d4ed8",zIndex:"2147483645",pointerEvents:"none",transition:"all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275)"}),this.t().appendChild(o),requestAnimationFrame(()=>{o.style.transform=`translate(${n.left-e.left}px, ${n.top-e.top}px) scale(0.5)`,o.style.opacity="0"}),setTimeout(()=>{o.remove(),this.o(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.n(t,!0),this.iframeElement||(this.iframeElement=this.createCheckoutIframe(),this.t().appendChild(this.iframeElement));let e=new URLSearchParams({orgId:this.orgId.toString(),c:JSON.stringify(this.cart),next:window.location.href});this.iframeElement.src=`${this.checkoutUrl}?${e.toString()}`,this.iframeElement.onload=()=>{this.iframeElement&&this.iframeElement.hasAttribute("src")&&(this.iframeElement.style.display="block",this.iframeShown=!0,this.e(!0),this.n(t,!1))}}createCheckoutIframe(){let t=document.createElement("iframe");return t.setAttribute("sandbox","allow-scripts allow-same-origin allow-popups allow-forms"),t.setAttribute("allow","payment *; fullscreen *;"),Object.assign(t.style,{width:"100vw",height:"100dvh",position:"fixed",top:"0",left:"0",right:"0",bottom:"0",border:"0",zIndex:"2147483647",background:"#ffffff",display:"none"}),t}closeCheckout(){this.iframeElement&&(this.iframeElement.style.display="none",this.iframeShown=!1,this.iframeElement.removeAttribute("src"),this.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let n=e,o=parseInt(n.getAttribute("data-shopmate-product-id")||"",10);isNaN(o)||n.addEventListener("click",s=>{s.preventDefault(),this.addToCart(o,parseInt(n.getAttribute("data-shopmate-quantity")||"1",10),n)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",n=>{n.preventDefault(),this.openCheckout(e)})}),this.s(()=>{this.m(t),this.a()})}};if(typeof window!="undefined"){window.ShopMate=a;let i=document.currentScript;if(i&&i.src){let t=new a({orgId:parseInt(i.dataset.orgId||"2",10),baseUrl:i.dataset.baseUrl||void 0,cartPosition:i.dataset.cartPosition||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=t,t.extract()})}}var f=a;return p(u);})();
|