shopmate-sdk 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ShopMate Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # ShopMate SDK
2
+
3
+ Lightweight checkout/cart SDK for browser storefronts.
4
+
5
+ It supports:
6
+
7
+ - **ES module import** (`import`)
8
+ - **CommonJS require** (`require`)
9
+ - **Plain script tag usage** (no module system)
10
+
11
+ ---
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install shopmate-sdk
17
+ ```
18
+
19
+ ---
20
+
21
+ ## Usage
22
+
23
+ ### 1) ES Module (import)
24
+
25
+ ```js
26
+ import ShopMate from 'shopmate-sdk';
27
+
28
+ const sdk = new ShopMate({
29
+ orgId: 2,
30
+ baseUrl: 'https://shopmate.hoshonto.com',
31
+ cartPosition: 'right-bottom'
32
+ });
33
+
34
+ sdk.extract();
35
+ ```
36
+
37
+ ### 2) CommonJS (require)
38
+
39
+ ```js
40
+ const ShopMate = require('shopmate-sdk').default;
41
+
42
+ const sdk = new ShopMate({ orgId: 2 });
43
+ sdk.extract();
44
+ ```
45
+
46
+ ### 3) Plain browser script (non-module)
47
+
48
+ ```html
49
+ <script src="/path/to/shopmate-sdk.min.js?orgId=2&baseUrl=https://shopmate.hoshonto.com"></script>
50
+ <script>
51
+ // Available globally
52
+ const sdk = new window.ShopMate({ orgId: 2 });
53
+ sdk.extract();
54
+ </script>
55
+ ```
56
+
57
+ When loaded directly via `<script src="...">`, the SDK also auto-initializes a global `window.ShopMateInstance` using query params from the script URL.
58
+
59
+ ---
60
+
61
+ ## Configuration
62
+
63
+ `new ShopMate(config)` accepts:
64
+
65
+ - `orgId` **(number, required)**: Organization ID.
66
+ - `baseUrl` *(string, optional)*: Backend base URL. Default: `https://shopmate.hoshonto.com`.
67
+ - `cartPosition` *(optional)*: Floating cart position.
68
+
69
+ Allowed `cartPosition` values:
70
+
71
+ - `left-top`, `top`, `right-top`
72
+ - `left-center`, `center`, `right-center`
73
+ - `left-bottom`, `bottom`, `right-bottom`
74
+
75
+ ---
76
+
77
+ ## Public API
78
+
79
+ ### `extract(rootElement?: HTMLElement)`
80
+
81
+ Scans DOM and wires click handlers:
82
+
83
+ - `[data-shopmate-product-id]` → add/update cart items
84
+ - `[data-shopmate-checkout="true"]` → open checkout popup
85
+
86
+ ### `addToCart(itemId: number, quantity: number, element?: HTMLElement)`
87
+
88
+ Adds/updates an item in the local cart and updates floating badge.
89
+
90
+ ### `openCheckout(buttonElement?: HTMLElement)`
91
+
92
+ Opens full-screen checkout iframe.
93
+
94
+ ### `closeCheckout()`
95
+
96
+ Closes checkout iframe and restores page scroll.
97
+
98
+ ### `createCheckoutIframe()`
99
+
100
+ Creates and returns the iframe element used for checkout.
101
+
102
+ ---
103
+
104
+ ## Data attributes supported
105
+
106
+ ### Product triggers
107
+
108
+ ```html
109
+ <button data-shopmate-product-id="101" data-shopmate-quantity="1">Add</button>
110
+ ```
111
+
112
+ ### Checkout trigger
113
+
114
+ ```html
115
+ <button data-shopmate-checkout="true">Checkout</button>
116
+ ```
117
+
118
+ ---
119
+
120
+ ## Build outputs
121
+
122
+ `npm run build` generates:
123
+
124
+ - `shopmate-sdk.js` (IIFE global bundle)
125
+ - `shopmate-sdk.min.js` (IIFE global minified bundle)
126
+ - `dist/index.mjs` (ESM)
127
+ - `dist/index.min.mjs` (ESM minified)
128
+ - `dist/index.cjs` (CJS)
129
+ - `dist/index.min.cjs` (CJS minified)
130
+ - `dist/index.d.ts` (TypeScript declarations)
131
+
132
+ ---
133
+
134
+ ## NPM scripts
135
+
136
+ - `npm run build` — build all artifacts
137
+ - `npm run watch` — watch mode build
138
+ - `npm run typecheck` — TS type-check only
139
+ - `npm test` — build + verify ESM/CJS/browser bundle loading
140
+
141
+ ---
142
+
143
+ ## Package export map
144
+
145
+ - `shopmate-sdk` → default export (`ShopMate` class)
146
+ - `shopmate-sdk/min` → minified module build
147
+ - `shopmate-sdk/browser` → browser bundle path
148
+
149
+ ---
150
+
151
+ ## Local demo
152
+
153
+ Use `examples/storefront-demo.html` after building.
154
+ # shopmate-sdk
package/dist/index.cjs ADDED
@@ -0,0 +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;
@@ -0,0 +1,41 @@
1
+ type ShopMateCartPosition = 'left-top' | 'top' | 'right-top' | 'left-center' | 'center' | 'right-center' | 'left-bottom' | 'bottom' | 'right-bottom';
2
+ type ShopMateConfig = {
3
+ orgId: number;
4
+ baseUrl?: string;
5
+ cartPosition?: ShopMateCartPosition;
6
+ };
7
+ type ShopMateCart = {
8
+ i: Array<{
9
+ i: number;
10
+ q: number;
11
+ }>;
12
+ couponId?: string;
13
+ };
14
+ declare class ShopMate {
15
+ baseUrl: string;
16
+ checkoutUrl: string;
17
+ orgId: number;
18
+ cartPosition: ShopMateCartPosition;
19
+ iframeElement?: HTMLIFrameElement;
20
+ floatingCartButton?: HTMLButtonElement;
21
+ floatingCartBadge?: HTMLSpanElement;
22
+ iframeShown: boolean;
23
+ cart: ShopMateCart;
24
+ private _getMountRoot;
25
+ private _runWhenBodyReady;
26
+ constructor(config: ShopMateConfig);
27
+ private _setScrollLocked;
28
+ private _pulseButton;
29
+ private _pop;
30
+ private _getPositionStyles;
31
+ private _ensureFloatingCart;
32
+ private _updateFloatingCartBadge;
33
+ private _setupMessageListener;
34
+ addToCart(itemId: number, quantity: number, element?: HTMLElement): void;
35
+ private _animateFlyToCart;
36
+ openCheckout(buttonElement?: HTMLElement): void;
37
+ createCheckoutIframe(): HTMLIFrameElement;
38
+ closeCheckout(): void;
39
+ extract(rootElement?: HTMLElement): void;
40
+ }
41
+ export default ShopMate;
@@ -0,0 +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;
@@ -0,0 +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};
package/dist/index.mjs ADDED
@@ -0,0 +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};
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "shopmate-sdk",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "description": "Shopmate browser SDK",
6
+ "license": "MIT",
7
+ "author": "ShopMate Team",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/nokibsarkar/ShopMate2.git",
11
+ "directory": "SDK"
12
+ },
13
+ "homepage": "https://github.com/nokibsarkar/ShopMate2/tree/main/SDK",
14
+ "bugs": {
15
+ "url": "https://github.com/nokibsarkar/ShopMate2/issues"
16
+ },
17
+ "keywords": [
18
+ "shopmate",
19
+ "sdk",
20
+ "checkout",
21
+ "cart",
22
+ "ecommerce",
23
+ "browser"
24
+ ],
25
+ "type": "module",
26
+ "main": "dist/index.cjs",
27
+ "module": "dist/index.mjs",
28
+ "browser": "shopmate-sdk.min.js",
29
+ "unpkg": "shopmate-sdk.min.js",
30
+ "jsdelivr": "shopmate-sdk.min.js",
31
+ "types": "dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "require": "./dist/index.cjs",
36
+ "import": "./dist/index.mjs",
37
+ "default": "./dist/index.mjs"
38
+ },
39
+ "./min": {
40
+ "require": "./dist/index.min.cjs",
41
+ "import": "./dist/index.min.mjs",
42
+ "default": "./dist/index.min.mjs"
43
+ },
44
+ "./browser": "./shopmate-sdk.min.js",
45
+ "./package.json": "./package.json"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "scripts": {
51
+ "clean": "rimraf dist shopmate-sdk.js shopmate-sdk.min.js",
52
+ "build": "node ./scripts/build.mjs",
53
+ "prepublish": "npm run build",
54
+ "prepublishOnly": "npm test",
55
+ "test": "node ./scripts/build.mjs && node ./scripts/verify-imports.mjs",
56
+ "typecheck": "tsc -p tsconfig.json --noEmit",
57
+ "watch": "node ./scripts/build.mjs --watch"
58
+ },
59
+ "devDependencies": {
60
+ "esbuild": "^0.25.2",
61
+ "rimraf": "^6.0.1",
62
+ "typescript": "^5.8.3"
63
+ }
64
+ }
@@ -0,0 +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);})();
@@ -0,0 +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);})();