shopmate-sdk 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,7 +46,12 @@ sdk.extract();
46
46
  ### 3) Plain browser script (non-module)
47
47
 
48
48
  ```html
49
- <script src="/path/to/shopmate-sdk.min.js?orgId=2&baseUrl=https://shopmate.hoshonto.com"></script>
49
+ <script
50
+ src="/path/to/shopmate-sdk.min.js"
51
+ data-org-id="2"
52
+ data-base-url="https://shopmate.hoshonto.com"
53
+ data-cart-position="right-bottom"
54
+ ></script>
50
55
  <script>
51
56
  // Available globally
52
57
  const sdk = new window.ShopMate({ orgId: 2 });
@@ -54,7 +59,12 @@ sdk.extract();
54
59
  </script>
55
60
  ```
56
61
 
57
- When loaded directly via `<script src="...">`, the SDK also auto-initializes a global `window.ShopMateInstance` using query params from the script URL.
62
+ When loaded directly via `<script src="...">`, the SDK auto-initializes a global `window.ShopMateInstance` using data attributes on the script tag.
63
+
64
+ **Data attributes (used for auto-init):**
65
+ - `data-org-id`: Organization ID (required for auto-init)
66
+ - `data-base-url`: Custom base URL (optional)
67
+ - `data-cart-position`: Cart position on screen (optional)
58
68
 
59
69
  ---
60
70
 
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)s(i,e,{get:t[e],enumerable:!0})},p=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of h(t))!f.call(i,n)&&n!==e&&s(i,n,{get:()=>t[n],enumerable:!(o=d(t,n))||o.enumerable});return i};var u=i=>p(s({},"__esModule",{value:!0}),i);var b={};m(b,{default:()=>g});module.exports=u(b);var r=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.s()}t(){return document.body||document.documentElement}r(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}e(t){let e=t?"hidden":"",o=t?"none":"";document.body&&(document.body.style.overflow=e,document.body.style.touchAction=o),document.documentElement.style.overflow=e,document.documentElement.style.touchAction=o}o(t,e){t&&(t.style.pointerEvents=e?"none":"",t.style.opacity=e?"0.6":"")}n(t,e=1.15,o=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:o,easing:"ease-in-out"})}l(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},o=this.cartPosition,n=o.indexOf("top")!==-1,a=o.indexOf("bottom")!==-1,c=o.indexOf("left")!==-1,l=o.indexOf("right")!==-1;return n?e.top=t:a?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),c?e.left=t:l?e.right=t:(e.left="50%",e.transform=e.transform==="none"?"translateX(-50%)":"translate(-50%, -50%)"),e}d(t){if(this.floatingCartButton)return;let e=t||this.t();if(!e)return;let o=document.createElement("button");o.type="button";let n={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, opacity 0.2s ease"};Object.assign(o.style,n,this.l()),o.textContent="🛒";let a=document.createElement("span");Object.assign(a.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"}),o.appendChild(a),o.addEventListener("click",()=>this.openCheckout(o)),e.appendChild(o),this.floatingCartButton=o,this.floatingCartBadge=a}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,o)=>e+o.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}s(){window.addEventListener("message",t=>{var e,o;try{if(t.origin!==new URL(this.baseUrl).origin)return;(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((o=t.data)==null?void 0:o.type)==="shopmate:close")&&this.closeCheckout()}catch(n){}})}addToCart(t,e,o){let n=this.cart.i.find(a=>a.i===t);n?n.q=e:this.cart.i.push({i:t,q:e}),o&&(this.n(o,1.15,300),this.h(o)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),o=this.floatingCartButton.getBoundingClientRect(),n=document.createElement("div");Object.assign(n.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(n),requestAnimationFrame(()=>{n.style.transform=`translate(${o.left-e.left}px, ${o.top-e.top}px) scale(0.5)`,n.style.opacity="0"}),setTimeout(()=>{n.remove(),this.n(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.o(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.style.display="block",this.iframeShown=!0,this.e(!0),this.o(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.src="about:blank",this.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let o=e,n=parseInt(o.getAttribute("data-shopmate-product-id")||"",10);isNaN(n)||o.addEventListener("click",a=>{a.preventDefault(),this.addToCart(n,parseInt(o.getAttribute("data-shopmate-quantity")||"1",10),o)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",o=>{o.preventDefault(),this.openCheckout(e)})}),this.r(()=>{this.d(t),this.a()})}};try{Object.defineProperty(r,"name",{value:"ShopMate"})}catch(i){}if(typeof window!="undefined"&&typeof document!="undefined"){window.ShopMate=r;let i=document.currentScript;if(i instanceof HTMLScriptElement&&i.src){let t=new URL(i.src||window.location.href),e=new r({orgId:parseInt(t.searchParams.get("orgId")||"2",10),baseUrl:t.searchParams.get("baseUrl")||void 0,cartPosition:t.searchParams.get("cartPosition")||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=e,e.extract()})}}var g=r;
1
+ "use strict";var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)s(i,e,{get:t[e],enumerable:!0})},p=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of h(t))!f.call(i,n)&&n!==e&&s(i,n,{get:()=>t[n],enumerable:!(o=d(t,n))||o.enumerable});return i};var u=i=>p(s({},"__esModule",{value:!0}),i);var b={};m(b,{default:()=>g});module.exports=u(b);var r=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.s()}t(){return document.body||document.documentElement}r(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}e(t){let e=t?"hidden":"",o=t?"none":"";document.body&&(document.body.style.overflow=e,document.body.style.touchAction=o),document.documentElement.style.overflow=e,document.documentElement.style.touchAction=o}o(t,e){t&&(t.style.pointerEvents=e?"none":"",t.style.opacity=e?"0.6":"")}n(t,e=1.15,o=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:o,easing:"ease-in-out"})}l(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},o=this.cartPosition,n=o.indexOf("top")!==-1,a=o.indexOf("bottom")!==-1,l=o.indexOf("left")!==-1,c=o.indexOf("right")!==-1;return n?e.top=t:a?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),l?e.left=t:c?e.right=t:(e.left="50%",e.transform=e.transform==="none"?"translateX(-50%)":"translate(-50%, -50%)"),e}d(t){if(this.floatingCartButton)return;let e=t||this.t();if(!e)return;let o=document.createElement("button");o.type="button";let n={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, opacity 0.2s ease"};Object.assign(o.style,n,this.l()),o.textContent="🛒";let a=document.createElement("span");Object.assign(a.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"}),o.appendChild(a),o.addEventListener("click",()=>this.openCheckout(o)),e.appendChild(o),this.floatingCartButton=o,this.floatingCartBadge=a}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,o)=>e+o.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}s(){window.addEventListener("message",t=>{var e,o;try{if(console.log("Received message from iframe:",t.data),t.origin!==new URL(this.baseUrl).origin)return;console.log("Message origin verified:",t.origin),(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((o=t.data)==null?void 0:o.type)==="shopmate:close")&&(console.log("Received closeCheckout message from iframe"),this.closeCheckout())}catch(n){}})}addToCart(t,e,o){let n=this.cart.i.find(a=>a.i===t);n?n.q=e:this.cart.i.push({i:t,q:e}),o&&(this.n(o,1.15,300),this.h(o)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),o=this.floatingCartButton.getBoundingClientRect(),n=document.createElement("div");Object.assign(n.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(n),requestAnimationFrame(()=>{n.style.transform=`translate(${o.left-e.left}px, ${o.top-e.top}px) scale(0.5)`,n.style.opacity="0"}),setTimeout(()=>{n.remove(),this.n(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.o(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.style.display="block",this.iframeShown=!0,this.e(!0),this.o(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.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let o=e,n=parseInt(o.getAttribute("data-shopmate-product-id")||"",10);isNaN(n)||o.addEventListener("click",a=>{a.preventDefault(),this.addToCart(n,parseInt(o.getAttribute("data-shopmate-quantity")||"1",10),o)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",o=>{o.preventDefault(),this.openCheckout(e)})}),this.r(()=>{this.d(t),this.a()})}};try{Object.defineProperty(r,"name",{value:"ShopMate"})}catch(i){}if(typeof window!="undefined"&&typeof document!="undefined"){window.ShopMate=r;let i=document.currentScript;if(i instanceof HTMLScriptElement&&i.src){let t=new r({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 g=r;
@@ -1 +1 @@
1
- "use strict";var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)s(i,e,{get:t[e],enumerable:!0})},p=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of h(t))!f.call(i,n)&&n!==e&&s(i,n,{get:()=>t[n],enumerable:!(o=d(t,n))||o.enumerable});return i};var u=i=>p(s({},"__esModule",{value:!0}),i);var b={};m(b,{default:()=>g});module.exports=u(b);var r=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.s()}t(){return document.body||document.documentElement}r(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}e(t){let e=t?"hidden":"",o=t?"none":"";document.body&&(document.body.style.overflow=e,document.body.style.touchAction=o),document.documentElement.style.overflow=e,document.documentElement.style.touchAction=o}o(t,e){t&&(t.style.pointerEvents=e?"none":"",t.style.opacity=e?"0.6":"")}n(t,e=1.15,o=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:o,easing:"ease-in-out"})}l(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},o=this.cartPosition,n=o.indexOf("top")!==-1,a=o.indexOf("bottom")!==-1,c=o.indexOf("left")!==-1,l=o.indexOf("right")!==-1;return n?e.top=t:a?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),c?e.left=t:l?e.right=t:(e.left="50%",e.transform=e.transform==="none"?"translateX(-50%)":"translate(-50%, -50%)"),e}d(t){if(this.floatingCartButton)return;let e=t||this.t();if(!e)return;let o=document.createElement("button");o.type="button";let n={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, opacity 0.2s ease"};Object.assign(o.style,n,this.l()),o.textContent="🛒";let a=document.createElement("span");Object.assign(a.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"}),o.appendChild(a),o.addEventListener("click",()=>this.openCheckout(o)),e.appendChild(o),this.floatingCartButton=o,this.floatingCartBadge=a}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,o)=>e+o.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}s(){window.addEventListener("message",t=>{var e,o;try{if(t.origin!==new URL(this.baseUrl).origin)return;(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((o=t.data)==null?void 0:o.type)==="shopmate:close")&&this.closeCheckout()}catch(n){}})}addToCart(t,e,o){let n=this.cart.i.find(a=>a.i===t);n?n.q=e:this.cart.i.push({i:t,q:e}),o&&(this.n(o,1.15,300),this.h(o)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),o=this.floatingCartButton.getBoundingClientRect(),n=document.createElement("div");Object.assign(n.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(n),requestAnimationFrame(()=>{n.style.transform=`translate(${o.left-e.left}px, ${o.top-e.top}px) scale(0.5)`,n.style.opacity="0"}),setTimeout(()=>{n.remove(),this.n(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.o(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.style.display="block",this.iframeShown=!0,this.e(!0),this.o(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.src="about:blank",this.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let o=e,n=parseInt(o.getAttribute("data-shopmate-product-id")||"",10);isNaN(n)||o.addEventListener("click",a=>{a.preventDefault(),this.addToCart(n,parseInt(o.getAttribute("data-shopmate-quantity")||"1",10),o)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",o=>{o.preventDefault(),this.openCheckout(e)})}),this.r(()=>{this.d(t),this.a()})}};try{Object.defineProperty(r,"name",{value:"ShopMate"})}catch(i){}if(typeof window!="undefined"&&typeof document!="undefined"){window.ShopMate=r;let i=document.currentScript;if(i instanceof HTMLScriptElement&&i.src){let t=new URL(i.src||window.location.href),e=new r({orgId:parseInt(t.searchParams.get("orgId")||"2",10),baseUrl:t.searchParams.get("baseUrl")||void 0,cartPosition:t.searchParams.get("cartPosition")||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=e,e.extract()})}}var g=r;
1
+ "use strict";var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)s(i,e,{get:t[e],enumerable:!0})},p=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of h(t))!f.call(i,n)&&n!==e&&s(i,n,{get:()=>t[n],enumerable:!(o=d(t,n))||o.enumerable});return i};var u=i=>p(s({},"__esModule",{value:!0}),i);var b={};m(b,{default:()=>g});module.exports=u(b);var r=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.s()}t(){return document.body||document.documentElement}r(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}e(t){let e=t?"hidden":"",o=t?"none":"";document.body&&(document.body.style.overflow=e,document.body.style.touchAction=o),document.documentElement.style.overflow=e,document.documentElement.style.touchAction=o}o(t,e){t&&(t.style.pointerEvents=e?"none":"",t.style.opacity=e?"0.6":"")}n(t,e=1.15,o=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:o,easing:"ease-in-out"})}l(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},o=this.cartPosition,n=o.indexOf("top")!==-1,a=o.indexOf("bottom")!==-1,l=o.indexOf("left")!==-1,c=o.indexOf("right")!==-1;return n?e.top=t:a?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),l?e.left=t:c?e.right=t:(e.left="50%",e.transform=e.transform==="none"?"translateX(-50%)":"translate(-50%, -50%)"),e}d(t){if(this.floatingCartButton)return;let e=t||this.t();if(!e)return;let o=document.createElement("button");o.type="button";let n={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, opacity 0.2s ease"};Object.assign(o.style,n,this.l()),o.textContent="🛒";let a=document.createElement("span");Object.assign(a.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"}),o.appendChild(a),o.addEventListener("click",()=>this.openCheckout(o)),e.appendChild(o),this.floatingCartButton=o,this.floatingCartBadge=a}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,o)=>e+o.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}s(){window.addEventListener("message",t=>{var e,o;try{if(console.log("Received message from iframe:",t.data),t.origin!==new URL(this.baseUrl).origin)return;console.log("Message origin verified:",t.origin),(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((o=t.data)==null?void 0:o.type)==="shopmate:close")&&(console.log("Received closeCheckout message from iframe"),this.closeCheckout())}catch(n){}})}addToCart(t,e,o){let n=this.cart.i.find(a=>a.i===t);n?n.q=e:this.cart.i.push({i:t,q:e}),o&&(this.n(o,1.15,300),this.h(o)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),o=this.floatingCartButton.getBoundingClientRect(),n=document.createElement("div");Object.assign(n.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(n),requestAnimationFrame(()=>{n.style.transform=`translate(${o.left-e.left}px, ${o.top-e.top}px) scale(0.5)`,n.style.opacity="0"}),setTimeout(()=>{n.remove(),this.n(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.o(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.style.display="block",this.iframeShown=!0,this.e(!0),this.o(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.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let o=e,n=parseInt(o.getAttribute("data-shopmate-product-id")||"",10);isNaN(n)||o.addEventListener("click",a=>{a.preventDefault(),this.addToCart(n,parseInt(o.getAttribute("data-shopmate-quantity")||"1",10),o)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",o=>{o.preventDefault(),this.openCheckout(e)})}),this.r(()=>{this.d(t),this.a()})}};try{Object.defineProperty(r,"name",{value:"ShopMate"})}catch(i){}if(typeof window!="undefined"&&typeof document!="undefined"){window.ShopMate=r;let i=document.currentScript;if(i instanceof HTMLScriptElement&&i.src){let t=new r({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 g=r;
@@ -1 +1 @@
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.s()}t(){return document.body||document.documentElement}r(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}e(t){let e=t?"hidden":"",o=t?"none":"";document.body&&(document.body.style.overflow=e,document.body.style.touchAction=o),document.documentElement.style.overflow=e,document.documentElement.style.touchAction=o}o(t,e){t&&(t.style.pointerEvents=e?"none":"",t.style.opacity=e?"0.6":"")}n(t,e=1.15,o=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:o,easing:"ease-in-out"})}l(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},o=this.cartPosition,n=o.indexOf("top")!==-1,i=o.indexOf("bottom")!==-1,s=o.indexOf("left")!==-1,c=o.indexOf("right")!==-1;return n?e.top=t:i?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),s?e.left=t:c?e.right=t:(e.left="50%",e.transform=e.transform==="none"?"translateX(-50%)":"translate(-50%, -50%)"),e}d(t){if(this.floatingCartButton)return;let e=t||this.t();if(!e)return;let o=document.createElement("button");o.type="button";let n={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, opacity 0.2s ease"};Object.assign(o.style,n,this.l()),o.textContent="🛒";let i=document.createElement("span");Object.assign(i.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"}),o.appendChild(i),o.addEventListener("click",()=>this.openCheckout(o)),e.appendChild(o),this.floatingCartButton=o,this.floatingCartBadge=i}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,o)=>e+o.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}s(){window.addEventListener("message",t=>{var e,o;try{if(t.origin!==new URL(this.baseUrl).origin)return;(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((o=t.data)==null?void 0:o.type)==="shopmate:close")&&this.closeCheckout()}catch(n){}})}addToCart(t,e,o){let n=this.cart.i.find(i=>i.i===t);n?n.q=e:this.cart.i.push({i:t,q:e}),o&&(this.n(o,1.15,300),this.h(o)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),o=this.floatingCartButton.getBoundingClientRect(),n=document.createElement("div");Object.assign(n.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(n),requestAnimationFrame(()=>{n.style.transform=`translate(${o.left-e.left}px, ${o.top-e.top}px) scale(0.5)`,n.style.opacity="0"}),setTimeout(()=>{n.remove(),this.n(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.o(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.style.display="block",this.iframeShown=!0,this.e(!0),this.o(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.src="about:blank",this.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let o=e,n=parseInt(o.getAttribute("data-shopmate-product-id")||"",10);isNaN(n)||o.addEventListener("click",i=>{i.preventDefault(),this.addToCart(n,parseInt(o.getAttribute("data-shopmate-quantity")||"1",10),o)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",o=>{o.preventDefault(),this.openCheckout(e)})}),this.r(()=>{this.d(t),this.a()})}};try{Object.defineProperty(a,"name",{value:"ShopMate"})}catch(r){}if(typeof window!="undefined"&&typeof document!="undefined"){window.ShopMate=a;let r=document.currentScript;if(r instanceof HTMLScriptElement&&r.src){let t=new URL(r.src||window.location.href),e=new a({orgId:parseInt(t.searchParams.get("orgId")||"2",10),baseUrl:t.searchParams.get("baseUrl")||void 0,cartPosition:t.searchParams.get("cartPosition")||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=e,e.extract()})}}var l=a;export{l as default};
1
+ var r=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.s()}t(){return document.body||document.documentElement}r(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}e(t){let e=t?"hidden":"",o=t?"none":"";document.body&&(document.body.style.overflow=e,document.body.style.touchAction=o),document.documentElement.style.overflow=e,document.documentElement.style.touchAction=o}o(t,e){t&&(t.style.pointerEvents=e?"none":"",t.style.opacity=e?"0.6":"")}n(t,e=1.15,o=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:o,easing:"ease-in-out"})}l(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},o=this.cartPosition,n=o.indexOf("top")!==-1,i=o.indexOf("bottom")!==-1,s=o.indexOf("left")!==-1,l=o.indexOf("right")!==-1;return n?e.top=t:i?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),s?e.left=t:l?e.right=t:(e.left="50%",e.transform=e.transform==="none"?"translateX(-50%)":"translate(-50%, -50%)"),e}d(t){if(this.floatingCartButton)return;let e=t||this.t();if(!e)return;let o=document.createElement("button");o.type="button";let n={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, opacity 0.2s ease"};Object.assign(o.style,n,this.l()),o.textContent="🛒";let i=document.createElement("span");Object.assign(i.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"}),o.appendChild(i),o.addEventListener("click",()=>this.openCheckout(o)),e.appendChild(o),this.floatingCartButton=o,this.floatingCartBadge=i}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,o)=>e+o.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}s(){window.addEventListener("message",t=>{var e,o;try{if(console.log("Received message from iframe:",t.data),t.origin!==new URL(this.baseUrl).origin)return;console.log("Message origin verified:",t.origin),(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((o=t.data)==null?void 0:o.type)==="shopmate:close")&&(console.log("Received closeCheckout message from iframe"),this.closeCheckout())}catch(n){}})}addToCart(t,e,o){let n=this.cart.i.find(i=>i.i===t);n?n.q=e:this.cart.i.push({i:t,q:e}),o&&(this.n(o,1.15,300),this.h(o)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),o=this.floatingCartButton.getBoundingClientRect(),n=document.createElement("div");Object.assign(n.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(n),requestAnimationFrame(()=>{n.style.transform=`translate(${o.left-e.left}px, ${o.top-e.top}px) scale(0.5)`,n.style.opacity="0"}),setTimeout(()=>{n.remove(),this.n(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.o(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.style.display="block",this.iframeShown=!0,this.e(!0),this.o(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.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let o=e,n=parseInt(o.getAttribute("data-shopmate-product-id")||"",10);isNaN(n)||o.addEventListener("click",i=>{i.preventDefault(),this.addToCart(n,parseInt(o.getAttribute("data-shopmate-quantity")||"1",10),o)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",o=>{o.preventDefault(),this.openCheckout(e)})}),this.r(()=>{this.d(t),this.a()})}};try{Object.defineProperty(r,"name",{value:"ShopMate"})}catch(a){}if(typeof window!="undefined"&&typeof document!="undefined"){window.ShopMate=r;let a=document.currentScript;if(a instanceof HTMLScriptElement&&a.src){let t=new r({orgId:parseInt(a.dataset.orgId||"2",10),baseUrl:a.dataset.baseUrl||void 0,cartPosition:a.dataset.cartPosition||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=t,t.extract()})}}var c=r;export{c as default};
package/dist/index.mjs CHANGED
@@ -1 +1 @@
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.s()}t(){return document.body||document.documentElement}r(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}e(t){let e=t?"hidden":"",o=t?"none":"";document.body&&(document.body.style.overflow=e,document.body.style.touchAction=o),document.documentElement.style.overflow=e,document.documentElement.style.touchAction=o}o(t,e){t&&(t.style.pointerEvents=e?"none":"",t.style.opacity=e?"0.6":"")}n(t,e=1.15,o=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:o,easing:"ease-in-out"})}l(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},o=this.cartPosition,n=o.indexOf("top")!==-1,i=o.indexOf("bottom")!==-1,s=o.indexOf("left")!==-1,c=o.indexOf("right")!==-1;return n?e.top=t:i?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),s?e.left=t:c?e.right=t:(e.left="50%",e.transform=e.transform==="none"?"translateX(-50%)":"translate(-50%, -50%)"),e}d(t){if(this.floatingCartButton)return;let e=t||this.t();if(!e)return;let o=document.createElement("button");o.type="button";let n={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, opacity 0.2s ease"};Object.assign(o.style,n,this.l()),o.textContent="🛒";let i=document.createElement("span");Object.assign(i.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"}),o.appendChild(i),o.addEventListener("click",()=>this.openCheckout(o)),e.appendChild(o),this.floatingCartButton=o,this.floatingCartBadge=i}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,o)=>e+o.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}s(){window.addEventListener("message",t=>{var e,o;try{if(t.origin!==new URL(this.baseUrl).origin)return;(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((o=t.data)==null?void 0:o.type)==="shopmate:close")&&this.closeCheckout()}catch(n){}})}addToCart(t,e,o){let n=this.cart.i.find(i=>i.i===t);n?n.q=e:this.cart.i.push({i:t,q:e}),o&&(this.n(o,1.15,300),this.h(o)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),o=this.floatingCartButton.getBoundingClientRect(),n=document.createElement("div");Object.assign(n.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(n),requestAnimationFrame(()=>{n.style.transform=`translate(${o.left-e.left}px, ${o.top-e.top}px) scale(0.5)`,n.style.opacity="0"}),setTimeout(()=>{n.remove(),this.n(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.o(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.style.display="block",this.iframeShown=!0,this.e(!0),this.o(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.src="about:blank",this.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let o=e,n=parseInt(o.getAttribute("data-shopmate-product-id")||"",10);isNaN(n)||o.addEventListener("click",i=>{i.preventDefault(),this.addToCart(n,parseInt(o.getAttribute("data-shopmate-quantity")||"1",10),o)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",o=>{o.preventDefault(),this.openCheckout(e)})}),this.r(()=>{this.d(t),this.a()})}};try{Object.defineProperty(a,"name",{value:"ShopMate"})}catch(r){}if(typeof window!="undefined"&&typeof document!="undefined"){window.ShopMate=a;let r=document.currentScript;if(r instanceof HTMLScriptElement&&r.src){let t=new URL(r.src||window.location.href),e=new a({orgId:parseInt(t.searchParams.get("orgId")||"2",10),baseUrl:t.searchParams.get("baseUrl")||void 0,cartPosition:t.searchParams.get("cartPosition")||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=e,e.extract()})}}var l=a;export{l as default};
1
+ var r=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.s()}t(){return document.body||document.documentElement}r(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}e(t){let e=t?"hidden":"",o=t?"none":"";document.body&&(document.body.style.overflow=e,document.body.style.touchAction=o),document.documentElement.style.overflow=e,document.documentElement.style.touchAction=o}o(t,e){t&&(t.style.pointerEvents=e?"none":"",t.style.opacity=e?"0.6":"")}n(t,e=1.15,o=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:o,easing:"ease-in-out"})}l(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},o=this.cartPosition,n=o.indexOf("top")!==-1,i=o.indexOf("bottom")!==-1,s=o.indexOf("left")!==-1,l=o.indexOf("right")!==-1;return n?e.top=t:i?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),s?e.left=t:l?e.right=t:(e.left="50%",e.transform=e.transform==="none"?"translateX(-50%)":"translate(-50%, -50%)"),e}d(t){if(this.floatingCartButton)return;let e=t||this.t();if(!e)return;let o=document.createElement("button");o.type="button";let n={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, opacity 0.2s ease"};Object.assign(o.style,n,this.l()),o.textContent="🛒";let i=document.createElement("span");Object.assign(i.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"}),o.appendChild(i),o.addEventListener("click",()=>this.openCheckout(o)),e.appendChild(o),this.floatingCartButton=o,this.floatingCartBadge=i}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,o)=>e+o.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}s(){window.addEventListener("message",t=>{var e,o;try{if(console.log("Received message from iframe:",t.data),t.origin!==new URL(this.baseUrl).origin)return;console.log("Message origin verified:",t.origin),(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((o=t.data)==null?void 0:o.type)==="shopmate:close")&&(console.log("Received closeCheckout message from iframe"),this.closeCheckout())}catch(n){}})}addToCart(t,e,o){let n=this.cart.i.find(i=>i.i===t);n?n.q=e:this.cart.i.push({i:t,q:e}),o&&(this.n(o,1.15,300),this.h(o)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),o=this.floatingCartButton.getBoundingClientRect(),n=document.createElement("div");Object.assign(n.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(n),requestAnimationFrame(()=>{n.style.transform=`translate(${o.left-e.left}px, ${o.top-e.top}px) scale(0.5)`,n.style.opacity="0"}),setTimeout(()=>{n.remove(),this.n(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.o(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.style.display="block",this.iframeShown=!0,this.e(!0),this.o(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.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let o=e,n=parseInt(o.getAttribute("data-shopmate-product-id")||"",10);isNaN(n)||o.addEventListener("click",i=>{i.preventDefault(),this.addToCart(n,parseInt(o.getAttribute("data-shopmate-quantity")||"1",10),o)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",o=>{o.preventDefault(),this.openCheckout(e)})}),this.r(()=>{this.d(t),this.a()})}};try{Object.defineProperty(r,"name",{value:"ShopMate"})}catch(a){}if(typeof window!="undefined"&&typeof document!="undefined"){window.ShopMate=r;let a=document.currentScript;if(a instanceof HTMLScriptElement&&a.src){let t=new r({orgId:parseInt(a.dataset.orgId||"2",10),baseUrl:a.dataset.baseUrl||void 0,cartPosition:a.dataset.cartPosition||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=t,t.extract()})}}var c=r;export{c as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shopmate-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "private": false,
5
5
  "description": "Shopmate browser SDK",
6
6
  "license": "MIT",
@@ -61,4 +61,4 @@
61
61
  "rimraf": "^6.0.1",
62
62
  "typescript": "^5.8.3"
63
63
  }
64
- }
64
+ }
package/shopmate-sdk.js CHANGED
@@ -1 +1 @@
1
- "use strict";var ShopmateExtractor=(()=>{var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)s(i,e,{get:t[e],enumerable:!0})},p=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of h(t))!f.call(i,n)&&n!==e&&s(i,n,{get:()=>t[n],enumerable:!(o=d(t,n))||o.enumerable});return i};var u=i=>p(s({},"__esModule",{value:!0}),i);var b={};m(b,{default:()=>g});var r=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.s()}t(){return document.body||document.documentElement}r(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}e(t){let e=t?"hidden":"",o=t?"none":"";document.body&&(document.body.style.overflow=e,document.body.style.touchAction=o),document.documentElement.style.overflow=e,document.documentElement.style.touchAction=o}o(t,e){t&&(t.style.pointerEvents=e?"none":"",t.style.opacity=e?"0.6":"")}n(t,e=1.15,o=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:o,easing:"ease-in-out"})}l(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},o=this.cartPosition,n=o.indexOf("top")!==-1,a=o.indexOf("bottom")!==-1,c=o.indexOf("left")!==-1,l=o.indexOf("right")!==-1;return n?e.top=t:a?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),c?e.left=t:l?e.right=t:(e.left="50%",e.transform=e.transform==="none"?"translateX(-50%)":"translate(-50%, -50%)"),e}d(t){if(this.floatingCartButton)return;let e=t||this.t();if(!e)return;let o=document.createElement("button");o.type="button";let n={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, opacity 0.2s ease"};Object.assign(o.style,n,this.l()),o.textContent="🛒";let a=document.createElement("span");Object.assign(a.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"}),o.appendChild(a),o.addEventListener("click",()=>this.openCheckout(o)),e.appendChild(o),this.floatingCartButton=o,this.floatingCartBadge=a}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,o)=>e+o.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}s(){window.addEventListener("message",t=>{var e,o;try{if(t.origin!==new URL(this.baseUrl).origin)return;(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((o=t.data)==null?void 0:o.type)==="shopmate:close")&&this.closeCheckout()}catch(n){}})}addToCart(t,e,o){let n=this.cart.i.find(a=>a.i===t);n?n.q=e:this.cart.i.push({i:t,q:e}),o&&(this.n(o,1.15,300),this.h(o)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),o=this.floatingCartButton.getBoundingClientRect(),n=document.createElement("div");Object.assign(n.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(n),requestAnimationFrame(()=>{n.style.transform=`translate(${o.left-e.left}px, ${o.top-e.top}px) scale(0.5)`,n.style.opacity="0"}),setTimeout(()=>{n.remove(),this.n(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.o(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.style.display="block",this.iframeShown=!0,this.e(!0),this.o(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.src="about:blank",this.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let o=e,n=parseInt(o.getAttribute("data-shopmate-product-id")||"",10);isNaN(n)||o.addEventListener("click",a=>{a.preventDefault(),this.addToCart(n,parseInt(o.getAttribute("data-shopmate-quantity")||"1",10),o)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",o=>{o.preventDefault(),this.openCheckout(e)})}),this.r(()=>{this.d(t),this.a()})}};try{Object.defineProperty(r,"name",{value:"ShopMate"})}catch(i){}if(typeof window!="undefined"&&typeof document!="undefined"){window.ShopMate=r;let i=document.currentScript;if(i instanceof HTMLScriptElement&&i.src){let t=new URL(i.src||window.location.href),e=new r({orgId:parseInt(t.searchParams.get("orgId")||"2",10),baseUrl:t.searchParams.get("baseUrl")||void 0,cartPosition:t.searchParams.get("cartPosition")||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=e,e.extract()})}}var g=r;return u(b);})();
1
+ "use strict";var ShopmateExtractor=(()=>{var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)s(i,e,{get:t[e],enumerable:!0})},p=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of h(t))!f.call(i,n)&&n!==e&&s(i,n,{get:()=>t[n],enumerable:!(o=d(t,n))||o.enumerable});return i};var u=i=>p(s({},"__esModule",{value:!0}),i);var b={};m(b,{default:()=>g});var r=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.s()}t(){return document.body||document.documentElement}r(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}e(t){let e=t?"hidden":"",o=t?"none":"";document.body&&(document.body.style.overflow=e,document.body.style.touchAction=o),document.documentElement.style.overflow=e,document.documentElement.style.touchAction=o}o(t,e){t&&(t.style.pointerEvents=e?"none":"",t.style.opacity=e?"0.6":"")}n(t,e=1.15,o=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:o,easing:"ease-in-out"})}l(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},o=this.cartPosition,n=o.indexOf("top")!==-1,a=o.indexOf("bottom")!==-1,l=o.indexOf("left")!==-1,c=o.indexOf("right")!==-1;return n?e.top=t:a?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),l?e.left=t:c?e.right=t:(e.left="50%",e.transform=e.transform==="none"?"translateX(-50%)":"translate(-50%, -50%)"),e}d(t){if(this.floatingCartButton)return;let e=t||this.t();if(!e)return;let o=document.createElement("button");o.type="button";let n={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, opacity 0.2s ease"};Object.assign(o.style,n,this.l()),o.textContent="🛒";let a=document.createElement("span");Object.assign(a.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"}),o.appendChild(a),o.addEventListener("click",()=>this.openCheckout(o)),e.appendChild(o),this.floatingCartButton=o,this.floatingCartBadge=a}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,o)=>e+o.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}s(){window.addEventListener("message",t=>{var e,o;try{if(console.log("Received message from iframe:",t.data),t.origin!==new URL(this.baseUrl).origin)return;console.log("Message origin verified:",t.origin),(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((o=t.data)==null?void 0:o.type)==="shopmate:close")&&(console.log("Received closeCheckout message from iframe"),this.closeCheckout())}catch(n){}})}addToCart(t,e,o){let n=this.cart.i.find(a=>a.i===t);n?n.q=e:this.cart.i.push({i:t,q:e}),o&&(this.n(o,1.15,300),this.h(o)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),o=this.floatingCartButton.getBoundingClientRect(),n=document.createElement("div");Object.assign(n.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(n),requestAnimationFrame(()=>{n.style.transform=`translate(${o.left-e.left}px, ${o.top-e.top}px) scale(0.5)`,n.style.opacity="0"}),setTimeout(()=>{n.remove(),this.n(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.o(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.style.display="block",this.iframeShown=!0,this.e(!0),this.o(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.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let o=e,n=parseInt(o.getAttribute("data-shopmate-product-id")||"",10);isNaN(n)||o.addEventListener("click",a=>{a.preventDefault(),this.addToCart(n,parseInt(o.getAttribute("data-shopmate-quantity")||"1",10),o)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",o=>{o.preventDefault(),this.openCheckout(e)})}),this.r(()=>{this.d(t),this.a()})}};try{Object.defineProperty(r,"name",{value:"ShopMate"})}catch(i){}if(typeof window!="undefined"&&typeof document!="undefined"){window.ShopMate=r;let i=document.currentScript;if(i instanceof HTMLScriptElement&&i.src){let t=new r({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 g=r;return u(b);})();
@@ -1 +1 @@
1
- "use strict";var ShopmateExtractor=(()=>{var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)s(i,e,{get:t[e],enumerable:!0})},p=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of h(t))!f.call(i,n)&&n!==e&&s(i,n,{get:()=>t[n],enumerable:!(o=d(t,n))||o.enumerable});return i};var u=i=>p(s({},"__esModule",{value:!0}),i);var b={};m(b,{default:()=>g});var r=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.s()}t(){return document.body||document.documentElement}r(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}e(t){let e=t?"hidden":"",o=t?"none":"";document.body&&(document.body.style.overflow=e,document.body.style.touchAction=o),document.documentElement.style.overflow=e,document.documentElement.style.touchAction=o}o(t,e){t&&(t.style.pointerEvents=e?"none":"",t.style.opacity=e?"0.6":"")}n(t,e=1.15,o=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:o,easing:"ease-in-out"})}l(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},o=this.cartPosition,n=o.indexOf("top")!==-1,a=o.indexOf("bottom")!==-1,c=o.indexOf("left")!==-1,l=o.indexOf("right")!==-1;return n?e.top=t:a?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),c?e.left=t:l?e.right=t:(e.left="50%",e.transform=e.transform==="none"?"translateX(-50%)":"translate(-50%, -50%)"),e}d(t){if(this.floatingCartButton)return;let e=t||this.t();if(!e)return;let o=document.createElement("button");o.type="button";let n={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, opacity 0.2s ease"};Object.assign(o.style,n,this.l()),o.textContent="🛒";let a=document.createElement("span");Object.assign(a.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"}),o.appendChild(a),o.addEventListener("click",()=>this.openCheckout(o)),e.appendChild(o),this.floatingCartButton=o,this.floatingCartBadge=a}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,o)=>e+o.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}s(){window.addEventListener("message",t=>{var e,o;try{if(t.origin!==new URL(this.baseUrl).origin)return;(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((o=t.data)==null?void 0:o.type)==="shopmate:close")&&this.closeCheckout()}catch(n){}})}addToCart(t,e,o){let n=this.cart.i.find(a=>a.i===t);n?n.q=e:this.cart.i.push({i:t,q:e}),o&&(this.n(o,1.15,300),this.h(o)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),o=this.floatingCartButton.getBoundingClientRect(),n=document.createElement("div");Object.assign(n.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(n),requestAnimationFrame(()=>{n.style.transform=`translate(${o.left-e.left}px, ${o.top-e.top}px) scale(0.5)`,n.style.opacity="0"}),setTimeout(()=>{n.remove(),this.n(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.o(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.style.display="block",this.iframeShown=!0,this.e(!0),this.o(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.src="about:blank",this.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let o=e,n=parseInt(o.getAttribute("data-shopmate-product-id")||"",10);isNaN(n)||o.addEventListener("click",a=>{a.preventDefault(),this.addToCart(n,parseInt(o.getAttribute("data-shopmate-quantity")||"1",10),o)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",o=>{o.preventDefault(),this.openCheckout(e)})}),this.r(()=>{this.d(t),this.a()})}};try{Object.defineProperty(r,"name",{value:"ShopMate"})}catch(i){}if(typeof window!="undefined"&&typeof document!="undefined"){window.ShopMate=r;let i=document.currentScript;if(i instanceof HTMLScriptElement&&i.src){let t=new URL(i.src||window.location.href),e=new r({orgId:parseInt(t.searchParams.get("orgId")||"2",10),baseUrl:t.searchParams.get("baseUrl")||void 0,cartPosition:t.searchParams.get("cartPosition")||void 0});window.addEventListener("load",()=>{window.ShopMateInstance=e,e.extract()})}}var g=r;return u(b);})();
1
+ "use strict";var ShopmateExtractor=(()=>{var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)s(i,e,{get:t[e],enumerable:!0})},p=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of h(t))!f.call(i,n)&&n!==e&&s(i,n,{get:()=>t[n],enumerable:!(o=d(t,n))||o.enumerable});return i};var u=i=>p(s({},"__esModule",{value:!0}),i);var b={};m(b,{default:()=>g});var r=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.s()}t(){return document.body||document.documentElement}r(t){if(document.body){t();return}let e=()=>{document.removeEventListener("DOMContentLoaded",e),t()};document.addEventListener("DOMContentLoaded",e)}e(t){let e=t?"hidden":"",o=t?"none":"";document.body&&(document.body.style.overflow=e,document.body.style.touchAction=o),document.documentElement.style.overflow=e,document.documentElement.style.touchAction=o}o(t,e){t&&(t.style.pointerEvents=e?"none":"",t.style.opacity=e?"0.6":"")}n(t,e=1.15,o=260){!t||typeof t.animate!="function"||t.animate([{transform:"scale(1)"},{transform:`scale(${e})`},{transform:"scale(1)"}],{duration:o,easing:"ease-in-out"})}l(){let t="20px",e={position:"fixed",top:"auto",right:"auto",bottom:"auto",left:"auto",transform:"none"},o=this.cartPosition,n=o.indexOf("top")!==-1,a=o.indexOf("bottom")!==-1,l=o.indexOf("left")!==-1,c=o.indexOf("right")!==-1;return n?e.top=t:a?e.bottom=t:(e.top="50%",e.transform="translateY(-50%)"),l?e.left=t:c?e.right=t:(e.left="50%",e.transform=e.transform==="none"?"translateX(-50%)":"translate(-50%, -50%)"),e}d(t){if(this.floatingCartButton)return;let e=t||this.t();if(!e)return;let o=document.createElement("button");o.type="button";let n={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, opacity 0.2s ease"};Object.assign(o.style,n,this.l()),o.textContent="🛒";let a=document.createElement("span");Object.assign(a.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"}),o.appendChild(a),o.addEventListener("click",()=>this.openCheckout(o)),e.appendChild(o),this.floatingCartButton=o,this.floatingCartBadge=a}a(){if(!this.floatingCartBadge)return;let t=this.cart.i.reduce((e,o)=>e+o.q,0);this.floatingCartBadge.style.display=t>0?"flex":"none",this.floatingCartBadge.textContent=t>99?"99+":String(t)}s(){window.addEventListener("message",t=>{var e,o;try{if(console.log("Received message from iframe:",t.data),t.origin!==new URL(this.baseUrl).origin)return;console.log("Message origin verified:",t.origin),(((e=t.data)==null?void 0:e.type)==="closeCheckout"||((o=t.data)==null?void 0:o.type)==="shopmate:close")&&(console.log("Received closeCheckout message from iframe"),this.closeCheckout())}catch(n){}})}addToCart(t,e,o){let n=this.cart.i.find(a=>a.i===t);n?n.q=e:this.cart.i.push({i:t,q:e}),o&&(this.n(o,1.15,300),this.h(o)),this.a()}h(t){if(!this.floatingCartButton)return;let e=t.getBoundingClientRect(),o=this.floatingCartButton.getBoundingClientRect(),n=document.createElement("div");Object.assign(n.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(n),requestAnimationFrame(()=>{n.style.transform=`translate(${o.left-e.left}px, ${o.top-e.top}px) scale(0.5)`,n.style.opacity="0"}),setTimeout(()=>{n.remove(),this.n(this.floatingCartButton,1.2,300)},600)}openCheckout(t){this.o(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.style.display="block",this.iframeShown=!0,this.e(!0),this.o(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.e(!1))}extract(t=document.body){t.querySelectorAll("[data-shopmate-product-id]").forEach(e=>{let o=e,n=parseInt(o.getAttribute("data-shopmate-product-id")||"",10);isNaN(n)||o.addEventListener("click",a=>{a.preventDefault(),this.addToCart(n,parseInt(o.getAttribute("data-shopmate-quantity")||"1",10),o)})}),t.querySelectorAll('[data-shopmate-checkout="true"]').forEach(e=>{e.addEventListener("click",o=>{o.preventDefault(),this.openCheckout(e)})}),this.r(()=>{this.d(t),this.a()})}};try{Object.defineProperty(r,"name",{value:"ShopMate"})}catch(i){}if(typeof window!="undefined"&&typeof document!="undefined"){window.ShopMate=r;let i=document.currentScript;if(i instanceof HTMLScriptElement&&i.src){let t=new r({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 g=r;return u(b);})();