@yassirbenmoussa/aicommerce-sdk 1.8.0 → 1.9.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.
@@ -1,11 +1,11 @@
1
1
  var AICommerceSDK=(function(exports){'use strict';/*! AI Commerce SDK v1.0.0 | MIT License | https://aicommerce.dev */
2
- var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var me=Object.prototype.hasOwnProperty;var B=(t,e)=>()=>(t&&(e=t(t=0)),e);var Y=(t,e)=>{for(var r in e)O(t,r,{get:e[r],enumerable:true});},le=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let g of de(e))!me.call(t,g)&&g!==r&&O(t,g,{get:()=>e[g],enumerable:!(s=ce(e,g))||s.enumerable});return t};var W=t=>le(O({},"__esModule",{value:true}),t);var D={};Y(D,{AICommerce:()=>exports.AICommerce,AICommerceError:()=>exports.AICommerceError});exports.AICommerce=void 0;exports.AICommerceError=void 0;var L=B(()=>{exports.AICommerce=class t{constructor(e){this.sessionToken=null;this.products={create:async e=>this.request("/api/v1/products",{method:"POST",body:JSON.stringify(e)}),batchUpsert:async e=>this.request("/api/v1/products",{method:"POST",body:JSON.stringify({products:e})}),list:async e=>{let r=new URLSearchParams;e?.page&&r.set("page",String(e.page)),e?.perPage&&r.set("perPage",String(e.perPage)),e?.search&&r.set("search",e.search),e?.categoryId&&r.set("categoryId",e.categoryId),e?.isActive!==void 0&&r.set("isActive",String(e.isActive));let s=r.toString();return this.request(`/api/v1/products${s?`?${s}`:""}`)},get:async e=>this.request(`/api/v1/products/${e}`),update:async(e,r)=>this.request(`/api/v1/products/${e}`,{method:"PUT",body:JSON.stringify(r)}),delete:async e=>this.request(`/api/v1/products/${e}`,{method:"DELETE"})};if(!e.apiKey)throw new Error("AICommerce: apiKey is required");this.apiKey=e.apiKey,this.storeId=e.storeId,this.baseUrl=this.normalizeUrl(e.baseUrl||this.detectBaseUrl()),this.timeout=e.timeout||3e4;}detectBaseUrl(){if(typeof window<"u"){let e=document.querySelector("script[data-aicommerce-url]");if(e)return e.getAttribute("data-aicommerce-url")||"https://api.aicommerce.dev"}return "https://api.aicommerce.dev"}normalizeUrl(e){return e.replace(/\/$/,"")}async request(e,r={}){let s=`${this.baseUrl}${e}`,g=new AbortController,a=setTimeout(()=>g.abort(),this.timeout);try{let p=await fetch(s,{...r,signal:g.signal,headers:{"Content-Type":"application/json","x-api-key":this.apiKey,...this.storeId&&{"x-store-id":this.storeId},...this.sessionToken&&{"X-Session-Token":this.sessionToken},...r.headers}});if(clearTimeout(a),!p.ok){let E=await p.json().catch(()=>({})),b={code:E.code||"UNKNOWN_ERROR",message:E.message||E.error||`HTTP ${p.status}`,status:p.status};throw new exports.AICommerceError(b.message,b.code,b.status)}return p.json()}catch(p){throw clearTimeout(a),p instanceof exports.AICommerceError?p:p instanceof Error&&p.name==="AbortError"?new exports.AICommerceError("Request timeout","TIMEOUT",408):new exports.AICommerceError(p instanceof Error?p.message:"Unknown error","NETWORK_ERROR",0)}}async chat(e,r){let s=typeof e=="string"?{message:e,context:r,sessionToken:this.sessionToken||void 0}:{...e,sessionToken:e.sessionToken||this.sessionToken||void 0},g=await this.request("/api/v1/chat",{method:"POST",body:JSON.stringify(s)});return g.sessionToken&&(this.sessionToken=g.sessionToken),g}async chatWithAudio(e,r){let s=await e.arrayBuffer(),a={audioBase64:btoa(new Uint8Array(s).reduce((E,b)=>E+String.fromCharCode(b),"")),audioMimeType:e.type||"audio/webm",context:r,sessionToken:this.sessionToken||void 0},p=await this.request("/api/v1/chat",{method:"POST",body:JSON.stringify(a)});return p.sessionToken&&(this.sessionToken=p.sessionToken),p}async createSession(){let e=await this.request("/api/v1/chat/session",{method:"POST"});return this.sessionToken=e.session.token,e.session}clearSession(){this.sessionToken=null;}getSessionToken(){return this.sessionToken}setSessionToken(e){this.sessionToken=e;}async upload(e,r){let s=new FormData;s.append("file",e),r?.folder&&s.append("folder",r.folder),r?.productId&&s.append("productId",r.productId),r?.isPrimary&&s.append("isPrimary","true");let g=`${this.baseUrl}/api/v1/upload`,a=await fetch(g,{method:"POST",headers:{"X-API-Key":this.apiKey},body:s});if(!a.ok){let p=await a.json().catch(()=>({}));throw new exports.AICommerceError(p.message||p.error||`HTTP ${a.status}`,p.code||"UPLOAD_ERROR",a.status)}return a.json()}static async quickChat(e){return new t({apiKey:e.apiKey,baseUrl:e.baseUrl}).chat(e.message,e.context)}},exports.AICommerceError=class t extends Error{constructor(e,r,s){super(e),this.name="AICommerceError",this.code=r,this.status=s,Object.setPrototypeOf(this,t.prototype);}};});function ue(t){let e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:{r:99,g:102,b:241}}function H(t){let e=t.primaryColor,r=ue(e),s=t.position==="bottom-left";return `
2
+ var B=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var H=(o,r)=>()=>(o&&(r=o(o=0)),r);var G=(o,r)=>{for(var e in r)B(o,e,{get:r[e],enumerable:true});},ue=(o,r,e,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let h of le(r))!pe.call(o,h)&&h!==e&&B(o,h,{get:()=>r[h],enumerable:!(c=me(r,h))||c.enumerable});return o};var j=o=>ue(B({},"__esModule",{value:true}),o);var W={};G(W,{AICommerce:()=>exports.AICommerce,AICommerceError:()=>exports.AICommerceError});exports.AICommerce=void 0;exports.AICommerceError=void 0;var R=H(()=>{exports.AICommerce=class o{constructor(r){this.sessionToken=null;this.products={create:async r=>this.request("/api/v1/products",{method:"POST",body:JSON.stringify(r)}),batchUpsert:async r=>this.request("/api/v1/products",{method:"POST",body:JSON.stringify({products:r})}),list:async r=>{let e=new URLSearchParams;r?.page&&e.set("page",String(r.page)),r?.perPage&&e.set("perPage",String(r.perPage)),r?.search&&e.set("search",r.search),r?.categoryId&&e.set("categoryId",r.categoryId),r?.isActive!==void 0&&e.set("isActive",String(r.isActive));let c=e.toString();return this.request(`/api/v1/products${c?`?${c}`:""}`)},get:async r=>this.request(`/api/v1/products/${r}`),update:async(r,e)=>this.request(`/api/v1/products/${r}`,{method:"PUT",body:JSON.stringify(e)}),delete:async r=>this.request(`/api/v1/products/${r}`,{method:"DELETE"})};if(!r.apiKey)throw new Error("AICommerce: apiKey is required");this.apiKey=r.apiKey,this.storeId=r.storeId,this.baseUrl=this.normalizeUrl(r.baseUrl||this.detectBaseUrl()),this.timeout=r.timeout||3e4;}detectBaseUrl(){if(typeof window<"u"){let r=document.querySelector("script[data-aicommerce-url]");if(r)return r.getAttribute("data-aicommerce-url")||"https://api.aicommerce.dev"}return "https://api.aicommerce.dev"}normalizeUrl(r){return r.replace(/\/$/,"")}async request(r,e={}){let c=`${this.baseUrl}${r}`,h=new AbortController,s=setTimeout(()=>h.abort(),this.timeout);try{let g=await fetch(c,{...e,signal:h.signal,headers:{"Content-Type":"application/json","x-api-key":this.apiKey,...this.storeId&&{"x-store-id":this.storeId},...this.sessionToken&&{"X-Session-Token":this.sessionToken},...e.headers}});if(clearTimeout(s),!g.ok){let L=await g.json().catch(()=>({})),w={code:L.code||"UNKNOWN_ERROR",message:L.message||L.error||`HTTP ${g.status}`,status:g.status};throw new exports.AICommerceError(w.message,w.code,w.status)}return g.json()}catch(g){throw clearTimeout(s),g instanceof exports.AICommerceError?g:g instanceof Error&&g.name==="AbortError"?new exports.AICommerceError("Request timeout","TIMEOUT",408):new exports.AICommerceError(g instanceof Error?g.message:"Unknown error","NETWORK_ERROR",0)}}async chat(r,e){let c=typeof r=="string"?{message:r,context:e,sessionToken:this.sessionToken||void 0}:{...r,sessionToken:r.sessionToken||this.sessionToken||void 0},h=await this.request("/api/v1/chat",{method:"POST",body:JSON.stringify(c)});return h.sessionToken&&(this.sessionToken=h.sessionToken),h}async chatWithAudio(r,e){let c=await r.arrayBuffer(),s={audioBase64:btoa(new Uint8Array(c).reduce((L,w)=>L+String.fromCharCode(w),"")),audioMimeType:r.type||"audio/webm",context:e,sessionToken:this.sessionToken||void 0},g=await this.request("/api/v1/chat",{method:"POST",body:JSON.stringify(s)});return g.sessionToken&&(this.sessionToken=g.sessionToken),g}async createSession(){let r=await this.request("/api/v1/chat/session",{method:"POST"});return this.sessionToken=r.session.token,r.session}clearSession(){this.sessionToken=null;}getSessionToken(){return this.sessionToken}setSessionToken(r){this.sessionToken=r;}async upload(r,e){let c=new FormData;c.append("file",r),e?.folder&&c.append("folder",e.folder),e?.productId&&c.append("productId",e.productId),e?.isPrimary&&c.append("isPrimary","true");let h=`${this.baseUrl}/api/v1/upload`,s=await fetch(h,{method:"POST",headers:{"X-API-Key":this.apiKey},body:c});if(!s.ok){let g=await s.json().catch(()=>({}));throw new exports.AICommerceError(g.message||g.error||`HTTP ${s.status}`,g.code||"UPLOAD_ERROR",s.status)}return s.json()}static async quickChat(r){return new o({apiKey:r.apiKey,baseUrl:r.baseUrl}).chat(r.message,r.context)}},exports.AICommerceError=class o extends Error{constructor(r,e,c){super(r),this.name="AICommerceError",this.code=e,this.status=c,Object.setPrototypeOf(this,o.prototype);}};});function ge(o){let r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o);return r?{r:parseInt(r[1],16),g:parseInt(r[2],16),b:parseInt(r[3],16)}:{r:99,g:102,b:241}}function z(o){let r=o.primaryColor,e=ge(r),c=o.position==="bottom-left";return `
3
3
  /* AI Commerce Widget Styles */
4
4
  #aicommerce-widget {
5
- --aic-primary: ${e};
6
- --aic-primary-rgb: ${r.r}, ${r.g}, ${r.b};
7
- --aic-primary-light: rgba(${r.r}, ${r.g}, ${r.b}, 0.1);
8
- --aic-primary-dark: rgba(${r.r}, ${r.g}, ${r.b}, 0.9);
5
+ --aic-primary: ${r};
6
+ --aic-primary-rgb: ${e.r}, ${e.g}, ${e.b};
7
+ --aic-primary-light: rgba(${e.r}, ${e.g}, ${e.b}, 0.1);
8
+ --aic-primary-dark: rgba(${e.r}, ${e.g}, ${e.b}, 0.9);
9
9
  --aic-bg: #ffffff;
10
10
  --aic-bg-secondary: #f8fafc;
11
11
  --aic-text: #1e293b;
@@ -13,14 +13,14 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
13
13
  --aic-border: #e2e8f0;
14
14
  --aic-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
15
15
  --aic-radius: 16px;
16
- --aic-z-index: ${t.zIndex};
16
+ --aic-z-index: ${o.zIndex};
17
17
 
18
18
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
19
19
  font-size: 14px;
20
20
  line-height: 1.5;
21
21
  position: fixed;
22
22
  bottom: 20px;
23
- ${s?"left: 20px;":"right: 20px;"}
23
+ ${c?"left: 20px;":"right: 20px;"}
24
24
  z-index: var(--aic-z-index);
25
25
  }
26
26
 
@@ -74,7 +74,7 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
74
74
  .aicommerce-chat {
75
75
  position: absolute;
76
76
  bottom: 0;
77
- ${s?"left: 0;":"right: 0;"}
77
+ ${c?"left: 0;":"right: 0;"}
78
78
  width: 380px;
79
79
  max-width: calc(100vw - 40px);
80
80
  height: 600px;
@@ -86,7 +86,7 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
86
86
  flex-direction: column;
87
87
  overflow: hidden;
88
88
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
89
- transform-origin: bottom ${s?"left":"right"};
89
+ transform-origin: bottom ${c?"left":"right"};
90
90
  }
91
91
 
92
92
  .aicommerce-chat.aicommerce-closed {
@@ -515,7 +515,7 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
515
515
  @media (max-width: 420px) {
516
516
  #aicommerce-widget {
517
517
  bottom: 16px;
518
- ${s?"left: 16px;":"right: 16px;"}
518
+ ${c?"left: 16px;":"right: 16px;"}
519
519
  }
520
520
 
521
521
  .aicommerce-chat {
@@ -549,17 +549,21 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
549
549
  }
550
550
 
551
551
  /* ============================================
552
- Embedded Mode Styles
552
+ Embedded Mode Styles - ChatGPT Style
553
553
  ============================================ */
554
554
 
555
- /* Embedded container - position relative, inline flow */
555
+ /* Embedded container - fit content with max height */
556
556
  #aicommerce-widget.aicommerce-embedded {
557
557
  position: relative;
558
558
  bottom: auto;
559
559
  left: auto;
560
560
  right: auto;
561
561
  width: 100%;
562
- height: var(--aic-height, 500px);
562
+ height: auto;
563
+ max-height: var(--aic-max-height, 600px);
564
+ display: flex;
565
+ flex-direction: column;
566
+ background: transparent;
563
567
  }
564
568
 
565
569
  /* Embedded mode: hide launcher button */
@@ -567,17 +571,30 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
567
571
  display: none !important;
568
572
  }
569
573
 
570
- /* Embedded mode: chat is always visible and fills container */
574
+ /* Embedded mode: hide the header completely */
575
+ .aicommerce-embedded .aicommerce-header {
576
+ display: none !important;
577
+ }
578
+
579
+ /* Embedded mode: hide close button */
580
+ .aicommerce-embedded .aicommerce-close {
581
+ display: none !important;
582
+ }
583
+
584
+ /* Embedded mode: chat fills container with transparent background */
571
585
  .aicommerce-embedded .aicommerce-chat {
572
586
  position: relative;
573
587
  width: 100%;
574
- height: 100%;
588
+ height: auto;
575
589
  max-width: 100%;
576
- max-height: 100%;
577
- border-radius: var(--aic-radius);
590
+ border-radius: 0;
591
+ background: transparent;
592
+ box-shadow: none;
578
593
  transform: none !important;
579
594
  opacity: 1 !important;
580
595
  pointer-events: auto !important;
596
+ display: flex;
597
+ flex-direction: column;
581
598
  }
582
599
 
583
600
  /* Embedded mode: no open/close animations */
@@ -587,62 +604,324 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
587
604
  pointer-events: auto !important;
588
605
  }
589
606
 
590
- /* Embedded mode: messages area adjusts to container */
607
+ /* Embedded mode: messages area - messages start from bottom, grow upward */
591
608
  .aicommerce-embedded .aicommerce-messages {
609
+ display: flex;
610
+ flex-direction: column;
611
+ justify-content: flex-end;
612
+ overflow-y: auto;
613
+ max-height: calc(var(--aic-max-height, 600px) - 100px);
614
+ padding: 16px;
615
+ max-width: 700px;
616
+ margin: 0 auto;
617
+ width: 100%;
618
+ background: transparent;
619
+ gap: 12px;
620
+ scrollbar-width: thin;
621
+ scrollbar-color: var(--aic-border) transparent;
622
+ }
623
+
624
+ /* Embedded mode: custom scrollbar for webkit browsers */
625
+ .aicommerce-embedded .aicommerce-messages::-webkit-scrollbar {
626
+ width: 6px;
627
+ }
628
+
629
+ .aicommerce-embedded .aicommerce-messages::-webkit-scrollbar-track {
630
+ background: transparent;
631
+ }
632
+
633
+ .aicommerce-embedded .aicommerce-messages::-webkit-scrollbar-thumb {
634
+ background-color: var(--aic-border);
635
+ border-radius: 3px;
636
+ }
637
+
638
+ .aicommerce-embedded .aicommerce-messages::-webkit-scrollbar-thumb:hover {
639
+ background-color: var(--aic-text-secondary);
640
+ }
641
+
642
+ /* Embedded mode: messages have different styling */
643
+ .aicommerce-embedded .aicommerce-message {
644
+ max-width: 100%;
645
+ }
646
+
647
+ .aicommerce-embedded .aicommerce-message-content {
648
+ background: var(--aic-bg);
649
+ border: 1px solid var(--aic-border);
650
+ border-radius: 12px;
651
+ padding: 12px 16px;
652
+ }
653
+
654
+ .aicommerce-embedded .aicommerce-user .aicommerce-message-content {
655
+ background: var(--aic-primary);
656
+ color: white;
657
+ border-color: var(--aic-primary);
658
+ }
659
+
660
+ /* Embedded mode: input container wrapper - always at bottom */
661
+ .aicommerce-embedded .aicommerce-input-wrapper {
662
+ width: 100%;
663
+ display: flex;
664
+ flex-direction: column;
665
+ align-items: center;
666
+ padding: 16px;
667
+ flex-shrink: 0;
668
+ }
669
+
670
+ /* Embedded mode: input container styled like ChatGPT */
671
+ .aicommerce-embedded .aicommerce-input-container {
672
+ width: 100%;
673
+ max-width: 700px;
674
+ background: var(--aic-bg);
675
+ border: 1px solid var(--aic-border);
676
+ border-radius: 24px;
677
+ padding: 8px 12px;
678
+ display: flex;
679
+ align-items: flex-end;
680
+ gap: 8px;
681
+ }
682
+
683
+ /* Embedded mode: textarea field styling - auto-grow */
684
+ .aicommerce-embedded .aicommerce-input {
592
685
  flex: 1;
593
- min-height: 0;
686
+ min-width: 0;
687
+ border: none;
688
+ background: transparent;
689
+ padding: 8px 4px;
690
+ font-size: 16px;
691
+ font-family: inherit;
692
+ color: var(--aic-text);
693
+ outline: none;
694
+ resize: none;
695
+ min-height: 24px;
696
+ max-height: 150px;
697
+ line-height: 1.5;
698
+ overflow-y: auto;
594
699
  }
595
700
 
596
- /* Embedded mode responsive */
597
- @media (max-width: 420px) {
598
- #aicommerce-widget.aicommerce-embedded {
599
- height: var(--aic-height, 400px);
701
+ .aicommerce-embedded .aicommerce-input::placeholder {
702
+ color: var(--aic-text-secondary);
703
+ }
704
+
705
+ /* Embedded mode: buttons styling - smaller, no overflow */
706
+ .aicommerce-embedded .aicommerce-mic,
707
+ .aicommerce-embedded .aicommerce-send {
708
+ flex-shrink: 0;
709
+ width: 36px;
710
+ height: 36px;
711
+ min-width: 36px;
712
+ border-radius: 50%;
713
+ background: var(--aic-primary);
714
+ color: white;
715
+ border: none;
716
+ display: flex;
717
+ align-items: center;
718
+ justify-content: center;
719
+ cursor: pointer;
720
+ transition: all 0.2s ease;
721
+ }
722
+
723
+ .aicommerce-embedded .aicommerce-mic:hover,
724
+ .aicommerce-embedded .aicommerce-send:hover {
725
+ opacity: 0.9;
726
+ }
727
+
728
+ .aicommerce-embedded .aicommerce-mic {
729
+ background: transparent;
730
+ color: var(--aic-text-secondary);
731
+ }
732
+
733
+ .aicommerce-embedded .aicommerce-mic:hover {
734
+ background: rgba(0, 0, 0, 0.05);
735
+ color: var(--aic-text);
736
+ }
737
+
738
+ /* Embedded mode: product cards styling */
739
+ .aicommerce-embedded .aicommerce-products {
740
+ display: flex;
741
+ flex-wrap: wrap;
742
+ gap: 12px;
743
+ margin-top: 12px;
744
+ }
745
+
746
+ .aicommerce-embedded .aicommerce-product-card {
747
+ background: var(--aic-bg);
748
+ border: 1px solid var(--aic-border);
749
+ border-radius: 12px;
750
+ max-width: 180px;
751
+ }
752
+
753
+ /* Embedded mode: typing indicator */
754
+ .aicommerce-embedded .aicommerce-typing {
755
+ background: var(--aic-bg);
756
+ border: 1px solid var(--aic-border);
757
+ border-radius: 12px;
758
+ padding: 12px 16px;
759
+ }
760
+
761
+ /* Embedded mode responsive - mobile fixes */
762
+ @media (max-width: 640px) {
763
+ .aicommerce-embedded .aicommerce-input-container {
764
+ padding: 6px 10px;
765
+ gap: 6px;
766
+ border-radius: 20px;
600
767
  }
601
768
 
602
- .aicommerce-embedded .aicommerce-chat {
603
- border-radius: 12px;
769
+ .aicommerce-embedded .aicommerce-mic,
770
+ .aicommerce-embedded .aicommerce-send {
771
+ width: 32px;
772
+ height: 32px;
773
+ min-width: 32px;
604
774
  }
775
+
776
+ .aicommerce-embedded .aicommerce-mic svg,
777
+ .aicommerce-embedded .aicommerce-send svg {
778
+ width: 16px;
779
+ height: 16px;
780
+ }
781
+
782
+ .aicommerce-embedded .aicommerce-input {
783
+ font-size: 16px;
784
+ padding: 6px 4px;
785
+ }
786
+
787
+ .aicommerce-embedded .aicommerce-messages {
788
+ padding: 12px;
789
+ }
790
+
791
+ .aicommerce-embedded .aicommerce-input-wrapper {
792
+ padding: 12px;
793
+ }
794
+ }
795
+
796
+ /* ============================================
797
+ Add to Cart Button Styles
798
+ ============================================ */
799
+
800
+ .aicommerce-add-to-cart {
801
+ width: 100%;
802
+ padding: 8px 12px;
803
+ background: var(--aic-primary);
804
+ color: white;
805
+ border: none;
806
+ border-radius: 6px;
807
+ font-size: 12px;
808
+ font-weight: 500;
809
+ cursor: pointer;
810
+ margin-top: 8px;
811
+ transition: all 0.2s;
812
+ display: flex;
813
+ align-items: center;
814
+ justify-content: center;
815
+ gap: 6px;
816
+ }
817
+
818
+ .aicommerce-add-to-cart:hover {
819
+ opacity: 0.9;
820
+ transform: translateY(-1px);
821
+ }
822
+
823
+ .aicommerce-add-to-cart:active {
824
+ transform: translateY(0);
825
+ }
826
+
827
+ .aicommerce-add-to-cart:disabled {
828
+ opacity: 0.7;
829
+ cursor: not-allowed;
830
+ transform: none;
605
831
  }
606
- `}function J(t){let e=document.createElement("style");e.id="aicommerce-widget-styles",e.textContent=t;let r=document.getElementById("aicommerce-widget-styles");return r&&r.remove(),document.head.appendChild(e),e}var V=B(()=>{});var X={};Y(X,{AICommerceWidget:()=>exports.AICommerceWidget,createWidget:()=>j});function j(t){if(!t.apiKey)throw new Error("AICommerceWidget: apiKey is required");let e=new exports.AICommerce({apiKey:t.apiKey,storeId:t.storeId,baseUrl:t.baseUrl}),r={isOpen:false,isLoading:true,isRecording:false,messages:[],storeConfig:null},s=null,g=[],a=null,b=null,l;async function _(){try{let o=t.baseUrl||N(),i=await fetch(`${o}/api/v1/store`,{headers:{"x-api-key":t.apiKey}});return i.ok?(await i.json()).store:null}catch(o){return console.error("Failed to fetch store config:",o),null}}function N(){if(typeof window<"u"){let o=document.querySelector("script[data-aicommerce-url]");if(o)return o.getAttribute("data-aicommerce-url")||""}return "https://api.aicommerce.dev"}async function G(){r.storeConfig=await _();let o=t.displayMode||"widget",i=o==="embedded";l={apiKey:t.apiKey,storeId:t.storeId,baseUrl:t.baseUrl||N(),displayMode:o,container:t.container,height:t.height||"500px",position:t.position||"bottom-right",theme:t.theme||"auto",primaryColor:t.primaryColor||r.storeConfig?.primaryColor||"#6366f1",welcomeMessage:t.welcomeMessage||r.storeConfig?.welcomeMessage||"Hi! How can I help you find the perfect product today?",botName:t.botName||r.storeConfig?.chatBotName||"Shopping Assistant",zIndex:t.zIndex||9999,buttonText:t.buttonText||"\u{1F4AC}",hideLauncher:t.hideLauncher||false,onOpen:t.onOpen,onClose:t.onClose,onProductClick:t.onProductClick,onMessage:t.onMessage};let c=H(l);if(b=J(c),i){let d=null;if(typeof t.container=="string"?d=document.querySelector(t.container):t.container instanceof HTMLElement&&(d=t.container),!d){console.error("[AI Commerce] Embedded mode requires a valid container element or selector");return}a=document.createElement("div"),a.id="aicommerce-widget",a.className=`aicommerce-widget aicommerce-embedded aicommerce-theme-${l.theme}`,a.style.setProperty("--aic-height",l.height),d.appendChild(a),r.isOpen=true;}else a=document.createElement("div"),a.id="aicommerce-widget",a.className=`aicommerce-widget aicommerce-${l.position} aicommerce-theme-${l.theme}`,document.body.appendChild(a);y(),r.messages.push({role:"assistant",content:l.welcomeMessage}),r.isLoading=false,y();}function y(){if(!a)return;let o=l.displayMode==="embedded",i=`
607
- ${!o&&!l.hideLauncher?`
608
- <button class="aicommerce-launcher ${r.isOpen?"aicommerce-hidden":""}" aria-label="Open chat">
609
- <span class="aicommerce-launcher-icon">${l.buttonText}</span>
832
+
833
+ .aicommerce-add-to-cart svg {
834
+ flex-shrink: 0;
835
+ }
836
+
837
+ /* Spinner animation for loading state */
838
+ @keyframes aicommerce-spin {
839
+ to { transform: rotate(360deg); }
840
+ }
841
+
842
+ .aicommerce-spinner {
843
+ animation: aicommerce-spin 1s linear infinite;
844
+ }
845
+ `}function _(o){let r=document.createElement("style");r.id="aicommerce-widget-styles",r.textContent=o;let e=document.getElementById("aicommerce-widget-styles");return e&&e.remove(),document.head.appendChild(r),r}var Q=H(()=>{});var Z={};G(Z,{AICommerceWidget:()=>exports.AICommerceWidget,createWidget:()=>D});function D(o){if(!o.apiKey)throw new Error("AICommerceWidget: apiKey is required");let r=new exports.AICommerce({apiKey:o.apiKey,storeId:o.storeId,baseUrl:o.baseUrl}),e={isOpen:false,isLoading:true,isRecording:false,messages:[],storeConfig:null},c=null,h=[],s=null,w=null,m;async function ee(){try{let a=o.baseUrl||N(),i=await fetch(`${a}/api/v1/store`,{headers:{"x-api-key":o.apiKey}});return i.ok?(await i.json()).store:null}catch(a){return console.error("Failed to fetch store config:",a),null}}function N(){if(typeof window<"u"){let a=document.querySelector("script[data-aicommerce-url]");if(a)return a.getAttribute("data-aicommerce-url")||""}return "https://api.aicommerce.dev"}async function re(){e.storeConfig=await ee();let a=o.displayMode||"widget",i=a==="embedded";m={apiKey:o.apiKey,storeId:o.storeId,baseUrl:o.baseUrl||N(),displayMode:a,container:o.container,maxHeight:o.maxHeight||"600px",placeholder:o.placeholder||"Ask me anything about our products...",position:o.position||"bottom-right",theme:o.theme||"auto",primaryColor:o.primaryColor||e.storeConfig?.primaryColor||"#6366f1",welcomeMessage:o.welcomeMessage||e.storeConfig?.welcomeMessage||"Hi! How can I help you find the perfect product today?",botName:o.botName||e.storeConfig?.chatBotName||"Shopping Assistant",zIndex:o.zIndex||9999,buttonText:o.buttonText||"\u{1F4AC}",hideLauncher:o.hideLauncher||false,addToCartText:o.addToCartText,onOpen:o.onOpen,onClose:o.onClose,onProductClick:o.onProductClick,onAddToCart:o.onAddToCart,onMessage:o.onMessage};let d=z(m);if(w=_(d),i){let b=null;if(typeof o.container=="string"?b=document.querySelector(o.container):o.container instanceof HTMLElement&&(b=o.container),!b){console.error("[AI Commerce] Embedded mode requires a valid container element or selector");return}s=document.createElement("div"),s.id="aicommerce-widget",s.className=`aicommerce-widget aicommerce-embedded aicommerce-theme-${m.theme}`,s.style.setProperty("--aic-max-height",m.maxHeight),b.appendChild(s),e.isOpen=true;}else s=document.createElement("div"),s.id="aicommerce-widget",s.className=`aicommerce-widget aicommerce-${m.position} aicommerce-theme-${m.theme}`,document.body.appendChild(s);k(),i||e.messages.push({role:"assistant",content:m.welcomeMessage}),e.isLoading=false,k();}async function te(a,i=1){if(!(await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a,quantity:i})})).ok)throw new Error("Failed to add to cart");document.dispatchEvent(new CustomEvent("cart:refresh"));}function k(){if(!s)return;let a=m.displayMode==="embedded",i=e.messages.some(l=>l.role==="user");a&&(s.classList.remove("aicommerce-no-messages","aicommerce-has-messages"),s.classList.add(i?"aicommerce-has-messages":"aicommerce-no-messages"));let d=m.placeholder||"Ask me anything about our products...",b=`
846
+ <div class="aicommerce-input-container">
847
+ ${a?`
848
+ <textarea
849
+ class="aicommerce-input"
850
+ placeholder="${d}"
851
+ rows="1"
852
+ ${e.isLoading||e.isRecording?"disabled":""}
853
+ ></textarea>
854
+ `:`
855
+ <input
856
+ type="text"
857
+ class="aicommerce-input"
858
+ placeholder="${d}"
859
+ ${e.isLoading||e.isRecording?"disabled":""}
860
+ />
861
+ `}
862
+ <button class="aicommerce-mic ${e.isRecording?"aicommerce-recording":""}" ${e.isLoading?"disabled":""} aria-label="${e.isRecording?"Stop recording":"Voice input"}">
863
+ ${e.isRecording?`
864
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
865
+ <rect x="6" y="6" width="12" height="12" rx="2"/>
866
+ </svg>
867
+ `:`
868
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
869
+ <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/>
870
+ <path d="M19 10v2a7 7 0 0 1-14 0v-2"/>
871
+ <line x1="12" y1="19" x2="12" y2="23"/>
872
+ <line x1="8" y1="23" x2="16" y2="23"/>
873
+ </svg>
874
+ `}
875
+ </button>
876
+ <button class="aicommerce-send" ${e.isLoading||e.isRecording?"disabled":""} aria-label="Send message">
877
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
878
+ <path d="M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13"/>
879
+ </svg>
880
+ </button>
881
+ </div>
882
+ `,u=`
883
+ ${!a&&!m.hideLauncher?`
884
+ <button class="aicommerce-launcher ${e.isOpen?"aicommerce-hidden":""}" aria-label="Open chat">
885
+ <span class="aicommerce-launcher-icon">${m.buttonText}</span>
610
886
  </button>
611
887
  `:""}
612
888
 
613
- <div class="aicommerce-chat ${r.isOpen?"aicommerce-open":"aicommerce-closed"}">
889
+ <div class="aicommerce-chat ${e.isOpen?"aicommerce-open":"aicommerce-closed"}">
890
+ ${a?"":`
614
891
  <div class="aicommerce-header">
615
892
  <div class="aicommerce-header-info">
616
893
  <div class="aicommerce-avatar">
617
- ${r.storeConfig?.logo?`<img src="${r.storeConfig.logo}" alt="${l.botName}" />`:"<span>\u{1F916}</span>"}
894
+ ${e.storeConfig?.logo?`<img src="${e.storeConfig.logo}" alt="${m.botName}" />`:"<span>\u{1F916}</span>"}
618
895
  </div>
619
896
  <div class="aicommerce-header-text">
620
- <span class="aicommerce-bot-name">${l.botName}</span>
897
+ <span class="aicommerce-bot-name">${m.botName}</span>
621
898
  <span class="aicommerce-status">Online</span>
622
899
  </div>
623
900
  </div>
624
- ${o?"":'<button class="aicommerce-close" aria-label="Close chat">\u2715</button>'}
901
+ <button class="aicommerce-close" aria-label="Close chat">\u2715</button>
625
902
  </div>
903
+ `}
626
904
 
905
+ ${a&&i?`
627
906
  <div class="aicommerce-messages">
628
- ${r.messages.map((d,u)=>{let P=te(d.content),T=d.role==="user";return `
629
- <div class="aicommerce-message aicommerce-${d.role}">
630
- <div class="aicommerce-message-content ${P?"aicommerce-rtl":"aicommerce-ltr"}">
631
- ${d.audioUrl?Q(d,u,T):R(d.content)}
907
+ ${e.messages.map((l,S)=>{let A=J(l.content),n=l.role==="user";return `
908
+ <div class="aicommerce-message aicommerce-${l.role}">
909
+ <div class="aicommerce-message-content ${A?"aicommerce-rtl":"aicommerce-ltr"}">
910
+ ${l.audioUrl?Y(l,S,n):T(l.content)}
632
911
  </div>
633
- ${d.products&&d.products.length>0?`
912
+ ${l.products&&l.products.length>0?`
634
913
  <div class="aicommerce-products">
635
- ${d.products.map(h=>`
636
- <div class="aicommerce-product-card" data-product-id="${h.id}">
637
- ${h.image||h.imageUrl?`
638
- <img src="${h.image||h.imageUrl}" alt="${R(h.name)}" class="aicommerce-product-image" />
914
+ ${l.products.map(t=>`
915
+ <div class="aicommerce-product-card" data-product-id="${t.id}">
916
+ ${t.image||t.imageUrl?`
917
+ <img src="${t.image||t.imageUrl}" alt="${T(t.name)}" class="aicommerce-product-image" />
639
918
  `:`
640
919
  <div class="aicommerce-product-placeholder">\u{1F4E6}</div>
641
920
  `}
642
921
  <div class="aicommerce-product-info">
643
- <span class="aicommerce-product-name" title="${R(h.name)}">${R(h.name)}</span>
644
- ${h.description?`<p class="aicommerce-product-desc">${R(h.description)}</p>`:""}
645
- <span class="aicommerce-product-price">${ne(h.price,h.currency)}</span>
922
+ <span class="aicommerce-product-name" title="${T(t.name)}">${T(t.name)}</span>
923
+ ${t.description?`<p class="aicommerce-product-desc">${T(t.description)}</p>`:""}
924
+ <span class="aicommerce-product-price">${X(t.price,t.currency)}</span>
646
925
  </div>
647
926
  </div>
648
927
  `).join("")}
@@ -650,7 +929,7 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
650
929
  `:""}
651
930
  </div>
652
931
  `}).join("")}
653
- ${r.isLoading?`
932
+ ${e.isLoading?`
654
933
  <div class="aicommerce-message aicommerce-assistant">
655
934
  <div class="aicommerce-typing">
656
935
  <span></span><span></span><span></span>
@@ -658,52 +937,85 @@ var O=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var de=Object
658
937
  </div>
659
938
  `:""}
660
939
  </div>
940
+ `:""}
661
941
 
662
- <div class="aicommerce-input-container">
663
- <input
664
- type="text"
665
- class="aicommerce-input"
666
- placeholder="Type your message..."
667
- ${r.isLoading||r.isRecording?"disabled":""}
668
- />
669
- <button class="aicommerce-mic ${r.isRecording?"aicommerce-recording":""}" ${r.isLoading?"disabled":""} aria-label="${r.isRecording?"Stop recording":"Voice input"}">
670
- ${r.isRecording?`
671
- <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
672
- <rect x="6" y="6" width="12" height="12" rx="2"/>
673
- </svg>
674
- `:`
675
- <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
676
- <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/>
677
- <path d="M19 10v2a7 7 0 0 1-14 0v-2"/>
678
- <line x1="12" y1="19" x2="12" y2="23"/>
679
- <line x1="8" y1="23" x2="16" y2="23"/>
680
- </svg>
681
- `}
682
- </button>
683
- <button class="aicommerce-send" ${r.isLoading||r.isRecording?"disabled":""} aria-label="Send message">
684
- <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
685
- <path d="M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13"/>
686
- </svg>
687
- </button>
942
+ ${a?"":`
943
+ <div class="aicommerce-messages">
944
+ ${e.messages.map((l,S)=>{let A=J(l.content),n=l.role==="user";return `
945
+ <div class="aicommerce-message aicommerce-${l.role}">
946
+ <div class="aicommerce-message-content ${A?"aicommerce-rtl":"aicommerce-ltr"}">
947
+ ${l.audioUrl?Y(l,S,n):T(l.content)}
948
+ </div>
949
+ ${l.products&&l.products.length>0?`
950
+ <div class="aicommerce-products">
951
+ ${l.products.map(t=>`
952
+ <div class="aicommerce-product-card" data-product-id="${t.id}" data-variant-id="${t.variantId||""}">
953
+ ${t.image||t.imageUrl?`
954
+ <img src="${t.image||t.imageUrl}" alt="${T(t.name)}" class="aicommerce-product-image" />
955
+ `:`
956
+ <div class="aicommerce-product-placeholder">\u{1F4E6}</div>
957
+ `}
958
+ <div class="aicommerce-product-info">
959
+ <span class="aicommerce-product-name" title="${T(t.name)}">${T(t.name)}</span>
960
+ ${t.description?`<p class="aicommerce-product-desc">${T(t.description)}</p>`:""}
961
+ <span class="aicommerce-product-price">${X(t.price,t.currency)}</span>
962
+ <button class="aicommerce-add-to-cart" data-product-id="${t.id}">
963
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
964
+ <circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/>
965
+ <path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/>
966
+ </svg>
967
+ ${m.addToCartText||"Add to Cart"}
968
+ </button>
969
+ </div>
970
+ </div>
971
+ `).join("")}
972
+ </div>
973
+ `:""}
974
+ </div>
975
+ `}).join("")}
976
+ ${e.isLoading?`
977
+ <div class="aicommerce-message aicommerce-assistant">
978
+ <div class="aicommerce-typing">
979
+ <span></span><span></span><span></span>
980
+ </div>
981
+ </div>
982
+ `:""}
688
983
  </div>
984
+ `}
985
+
986
+ ${a?`
987
+ <div class="aicommerce-input-wrapper">
988
+ ${b}
989
+ </div>
990
+ `:b}
689
991
  </div>
690
- `;a.innerHTML=i,Z();let c=a.querySelector(".aicommerce-messages");c&&(c.scrollTop=c.scrollHeight);}function Q(o,i,c){return `
992
+ `;s.innerHTML=u,oe();let E=s.querySelector(".aicommerce-messages");E&&(E.scrollTop=E.scrollHeight);}function Y(a,i,d){return `
691
993
  <div class="aicommerce-audio-player" data-message-index="${i}">
692
994
  <button class="aicommerce-audio-btn">
693
995
  <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>
694
996
  </button>
695
997
  <div class="aicommerce-audio-waveform">
696
998
  <div class="aicommerce-waveform-bars">
697
- ${(o.waveformBars||Array(40).fill(10)).map(d=>`
698
- <div class="aicommerce-waveform-bar" style="height: ${d}%; background-color: ${c?"rgba(255,255,255,0.4)":"rgba(99,102,241,0.3)"}"></div>
999
+ ${(a.waveformBars||Array(40).fill(10)).map(b=>`
1000
+ <div class="aicommerce-waveform-bar" style="height: ${b}%; background-color: ${d?"rgba(255,255,255,0.4)":"rgba(99,102,241,0.3)"}"></div>
699
1001
  `).join("")}
700
1002
  </div>
701
1003
  <div class="aicommerce-audio-time">
702
1004
  <span class="aicommerce-current-time">0:00</span>
703
- <span>${K(o.audioDuration||0)}</span>
1005
+ <span>${V(a.audioDuration||0)}</span>
704
1006
  </div>
705
1007
  </div>
706
- <audio src="${o.audioUrl}" preload="metadata"></audio>
1008
+ <audio src="${a.audioUrl}" preload="metadata"></audio>
707
1009
  </div>
708
- `}function Z(){if(!a)return;let o=a.querySelector(".aicommerce-launcher");o&&o.addEventListener("click",()=>M());let i=a.querySelector(".aicommerce-close");i&&i.addEventListener("click",()=>q());let c=a.querySelector(".aicommerce-input"),d=a.querySelector(".aicommerce-send");c&&c.addEventListener("keypress",n=>{n.key==="Enter"&&c.value.trim()&&(A(c.value.trim()),c.value="");}),d&&c&&d.addEventListener("click",()=>{c.value.trim()&&(A(c.value.trim()),c.value="");});let u=a.querySelector(".aicommerce-mic");u&&u.addEventListener("click",()=>ee()),a.querySelectorAll(".aicommerce-product-card").forEach(n=>{n.addEventListener("click",()=>{let m=n.getAttribute("data-product-id"),f=r.messages.flatMap(x=>x.products||[]).find(x=>x.id===m);f&&(l.onProductClick?l.onProductClick(f):f.url&&window.open(f.url,"_blank","noopener,noreferrer"));});}),a.querySelectorAll(".aicommerce-products").forEach(n=>{let m=false,f=0,x=0;n.addEventListener("mousedown",k=>{m=true,n.style.cursor="grabbing",f=k.pageX-n.offsetLeft,x=n.scrollLeft;}),n.addEventListener("mouseleave",()=>{m=false,n.style.cursor="grab";}),n.addEventListener("mouseup",()=>{m=false,n.style.cursor="grab";}),n.addEventListener("mousemove",k=>{if(!m)return;k.preventDefault();let v=(k.pageX-n.offsetLeft-f)*2;n.scrollLeft=x-v;});}),a.querySelectorAll(".aicommerce-audio-player").forEach(n=>{let m=n.querySelector("audio"),f=n.querySelector(".aicommerce-audio-btn"),x=n.querySelectorAll(".aicommerce-waveform-bar"),k=n.querySelector(".aicommerce-current-time");if(!m||!f)return;f.addEventListener("click",()=>{!m.paused?(m.pause(),f.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>'):(a?.querySelectorAll("audio").forEach(w=>{if(w!==m&&!w.paused){w.pause();let $=w.closest(".aicommerce-audio-player")?.querySelector(".aicommerce-audio-btn");$&&($.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>');}}),m.play(),f.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><rect x="6" y="4" width="4" height="16"></rect><rect x="14" y="4" width="4" height="16"></rect></svg>');}),m.addEventListener("timeupdate",()=>{if(k&&(k.textContent=K(m.currentTime)),m.duration){let v=m.currentTime/m.duration*100;x.forEach((w,U)=>{U/x.length*100<=v?w.style.backgroundColor=n.closest(".aicommerce-user")?"rgba(255,255,255,1)":"var(--aic-primary)":w.style.backgroundColor=n.closest(".aicommerce-user")?"rgba(255,255,255,0.4)":"rgba(99,102,241,0.3)";});}}),m.addEventListener("ended",()=>{f.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>';});let S=n.querySelector(".aicommerce-waveform-bars");S&&S.addEventListener("click",v=>{let w=S.getBoundingClientRect(),$=(v.clientX-w.left)/w.width;m.duration&&(m.currentTime=$*m.duration);});});}async function ee(){if(r.isRecording)s&&s.state!=="inactive"&&s.stop();else try{let o=await navigator.mediaDevices.getUserMedia({audio:!0});g=[],s=new MediaRecorder(o,{mimeType:MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4"}),s.ondataavailable=i=>{i.data.size>0&&g.push(i.data);},s.onstop=async()=>{if(o.getTracks().forEach(i=>i.stop()),g.length>0){let i=new Blob(g,{type:s?.mimeType||"audio/webm"});await re(i);}r.isRecording=!1,y();},s.start(),r.isRecording=!0,y();}catch(o){console.error("Failed to start recording:",o),r.messages.push({role:"assistant",content:"Unable to access microphone. Please check your permissions."}),y();}}async function re(o){let i=URL.createObjectURL(o),c=Array(40).fill(10),d=0;try{c=await oe(o);let u=new Audio(i);await new Promise(P=>{u.onloadedmetadata=()=>{d=u.duration,P();},u.onerror=()=>P();});}catch(u){console.error("Audio analysis failed",u);}r.messages.push({role:"user",content:"Voice message",audioUrl:i,audioDuration:d,waveformBars:c}),r.isLoading=true,y();try{let u=await e.chatWithAudio(o);return r.messages.push({role:"assistant",content:u.reply,products:u.products}),l.onMessage&&l.onMessage("Voice message",u),u}catch(u){throw r.messages.push({role:"assistant",content:"Sorry, I encountered an error processing your voice message. Please try again."}),u}finally{r.isLoading=false,y();}}function te(o){return /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(o)}function K(o){let i=Math.floor(o/60),c=Math.floor(o%60);return `${i}:${c.toString().padStart(2,"0")}`}async function oe(o){try{let i=new(window.AudioContext||window.webkitAudioContext),c=await o.arrayBuffer(),u=(await i.decodeAudioData(c)).getChannelData(0),P=40,T=Math.floor(u.length/P),h=[];for(let n=0;n<P;n++){let m=n*T,f=m+T,x=0;for(let v=m;v<f;v++)u[v]&&(x+=u[v]*u[v]);let k=Math.sqrt(x/T),S=Math.min(100,Math.max(10,k*400));h.push(S);}return h}catch(i){return console.error("Analysis error",i),Array.from({length:40},()=>20+Math.random()*60)}}async function A(o){r.messages.push({role:"user",content:o}),r.isLoading=true,y();try{let i=await e.chat(o);return r.messages.push({role:"assistant",content:i.reply,products:i.products}),l.onMessage&&l.onMessage(o,i),i}catch(i){throw r.messages.push({role:"assistant",content:"Sorry, I encountered an error. Please try again."}),i}finally{r.isLoading=false,y();}}function M(){r.isOpen=true,y(),l.onOpen?.(),setTimeout(()=>{a?.querySelector(".aicommerce-input")?.focus();},100);}function q(){r.isOpen=false,y(),l.onClose?.();}function ie(){r.isOpen?q():M();}function ae(){a&&(a.remove(),a=null),b&&(b.remove(),b=null);}function se(o){if(Object.assign(l,o),o.primaryColor){let i=H(l);b&&(b.textContent=i);}y();}function R(o){let i=document.createElement("div");return i.textContent=o,i.innerHTML}function ne(o,i){let d={USD:"$",EUR:"\u20AC",GBP:"\xA3",MAD:"DH",SAR:"SAR",AED:"AED",JPY:"\xA5",CNY:"\xA5"}[i||"USD"]||i||"$";return `${o.toFixed(2)} ${d}`}return G(),{open:M,close:q,toggle:ie,destroy:ae,sendMessage:A,updateConfig:se}}exports.AICommerceWidget=void 0;var F=B(()=>{L();V();exports.AICommerceWidget={init:j,VERSION:"1.0.0"};typeof window<"u"&&(window.AICommerceWidget=exports.AICommerceWidget);});L();F();var be="1.0.0";typeof window<"u"&&(window.AICommerce=(L(),W(D)).AICommerce,window.AICommerceError=(L(),W(D)).AICommerceError,window.AICommerceWidget=(F(),W(X)).AICommerceWidget);exports.VERSION=be;exports.createWidget=j;return exports;})({});//# sourceMappingURL=index.min.js.map
1010
+ `}function oe(){if(!s)return;let a=s.querySelector(".aicommerce-launcher");a&&a.addEventListener("click",()=>q());let i=s.querySelector(".aicommerce-close");i&&i.addEventListener("click",()=>O());let d=s.querySelector(".aicommerce-input"),b=s.querySelector(".aicommerce-send");d&&(d.addEventListener("keydown",n=>{let t=n;if(t.key==="Enter"){let p=d instanceof HTMLTextAreaElement;if(p&&t.shiftKey)return;n.preventDefault();let f=d.value.trim();f&&(U(f),d.value="",p&&(d.style.height="auto"));}}),d instanceof HTMLTextAreaElement&&d.addEventListener("input",()=>{d.style.height="auto",d.style.height=Math.min(d.scrollHeight,150)+"px";})),b&&d&&b.addEventListener("click",()=>{let n=d.value.trim();n&&(U(n),d.value="",d instanceof HTMLTextAreaElement&&(d.style.height="auto"));});let u=s.querySelector(".aicommerce-mic");u&&u.addEventListener("click",()=>ae()),s.querySelectorAll(".aicommerce-product-card").forEach(n=>{n.addEventListener("click",t=>{if(t.target.closest(".aicommerce-add-to-cart"))return;let p=n.getAttribute("data-product-id"),f=e.messages.flatMap(y=>y.products||[]).find(y=>y.id===p);f&&(m.onProductClick?m.onProductClick(f):f.url&&window.open(f.url,"_blank","noopener,noreferrer"));});}),s.querySelectorAll(".aicommerce-add-to-cart").forEach(n=>{n.addEventListener("click",async t=>{t.stopPropagation();let p=n,f=p.closest(".aicommerce-product-card"),y=f?.getAttribute("data-product-id"),x=f?.getAttribute("data-variant-id"),C=e.messages.flatMap(P=>P.products||[]).find(P=>P.id===y);if(!C)return;let v=p.innerHTML;p.disabled=true,p.innerHTML=`
1011
+ <svg class="aicommerce-spinner" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1012
+ <circle cx="12" cy="12" r="10" stroke-dasharray="32" stroke-dashoffset="32"/>
1013
+ </svg>
1014
+ Adding...
1015
+ `;try{m.onAddToCart?await m.onAddToCart(C):x&&window.Shopify?await te(x):C.url&&window.open(C.url,"_blank","noopener,noreferrer"),p.innerHTML=`
1016
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1017
+ <polyline points="20 6 9 17 4 12"/>
1018
+ </svg>
1019
+ Added!
1020
+ `,setTimeout(()=>{p.innerHTML=v,p.disabled=!1;},2e3);}catch(P){console.error("[AI Commerce] Add to cart failed:",P),p.innerHTML=v,p.disabled=false;}});}),s.querySelectorAll(".aicommerce-products").forEach(n=>{let t=false,p=0,f=0;n.addEventListener("mousedown",y=>{t=true,n.style.cursor="grabbing",p=y.pageX-n.offsetLeft,f=n.scrollLeft;}),n.addEventListener("mouseleave",()=>{t=false,n.style.cursor="grab";}),n.addEventListener("mouseup",()=>{t=false,n.style.cursor="grab";}),n.addEventListener("mousemove",y=>{if(!t)return;y.preventDefault();let C=(y.pageX-n.offsetLeft-p)*2;n.scrollLeft=f-C;});}),s.querySelectorAll(".aicommerce-audio-player").forEach(n=>{let t=n.querySelector("audio"),p=n.querySelector(".aicommerce-audio-btn"),f=n.querySelectorAll(".aicommerce-waveform-bar"),y=n.querySelector(".aicommerce-current-time");if(!t||!p)return;p.addEventListener("click",()=>{!t.paused?(t.pause(),p.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>'):(s?.querySelectorAll("audio").forEach(v=>{if(v!==t&&!v.paused){v.pause();let M=v.closest(".aicommerce-audio-player")?.querySelector(".aicommerce-audio-btn");M&&(M.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>');}}),t.play(),p.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><rect x="6" y="4" width="4" height="16"></rect><rect x="14" y="4" width="4" height="16"></rect></svg>');}),t.addEventListener("timeupdate",()=>{if(y&&(y.textContent=V(t.currentTime)),t.duration){let C=t.currentTime/t.duration*100;f.forEach((v,P)=>{P/f.length*100<=C?v.style.backgroundColor=n.closest(".aicommerce-user")?"rgba(255,255,255,1)":"var(--aic-primary)":v.style.backgroundColor=n.closest(".aicommerce-user")?"rgba(255,255,255,0.4)":"rgba(99,102,241,0.3)";});}}),t.addEventListener("ended",()=>{p.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>';});let x=n.querySelector(".aicommerce-waveform-bars");x&&x.addEventListener("click",C=>{let v=x.getBoundingClientRect(),M=(C.clientX-v.left)/v.width;t.duration&&(t.currentTime=M*t.duration);});});}async function ae(){if(e.isRecording)c&&c.state!=="inactive"&&c.stop();else try{let a=await navigator.mediaDevices.getUserMedia({audio:!0});h=[],c=new MediaRecorder(a,{mimeType:MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4"}),c.ondataavailable=i=>{i.data.size>0&&h.push(i.data);},c.onstop=async()=>{if(a.getTracks().forEach(i=>i.stop()),h.length>0){let i=new Blob(h,{type:c?.mimeType||"audio/webm"});await ie(i);}e.isRecording=!1,k();},c.start(),e.isRecording=!0,k();}catch(a){console.error("Failed to start recording:",a),e.messages.push({role:"assistant",content:"Unable to access microphone. Please check your permissions."}),k();}}async function ie(a){let i=URL.createObjectURL(a),d=Array(40).fill(10),b=0;try{d=await se(a);let u=new Audio(i);await new Promise(E=>{u.onloadedmetadata=()=>{b=u.duration,E();},u.onerror=()=>E();});}catch(u){console.error("Audio analysis failed",u);}e.messages.push({role:"user",content:"Voice message",audioUrl:i,audioDuration:b,waveformBars:d}),e.isLoading=true,k();try{let u=await r.chatWithAudio(a);return e.messages.push({role:"assistant",content:u.reply,products:u.products}),m.onMessage&&m.onMessage("Voice message",u),u}catch(u){throw e.messages.push({role:"assistant",content:"Sorry, I encountered an error processing your voice message. Please try again."}),u}finally{e.isLoading=false,k();}}function J(a){return /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(a)}function V(a){let i=Math.floor(a/60),d=Math.floor(a%60);return `${i}:${d.toString().padStart(2,"0")}`}async function se(a){try{let i=new(window.AudioContext||window.webkitAudioContext),d=await a.arrayBuffer(),u=(await i.decodeAudioData(d)).getChannelData(0),E=40,l=Math.floor(u.length/E),S=[];for(let A=0;A<E;A++){let n=A*l,t=n+l,p=0;for(let x=n;x<t;x++)u[x]&&(p+=u[x]*u[x]);let f=Math.sqrt(p/l),y=Math.min(100,Math.max(10,f*400));S.push(y);}return S}catch(i){return console.error("Analysis error",i),Array.from({length:40},()=>20+Math.random()*60)}}async function U(a){e.messages.push({role:"user",content:a}),e.isLoading=true,k();try{let i=await r.chat(a);return e.messages.push({role:"assistant",content:i.reply,products:i.products}),m.onMessage&&m.onMessage(a,i),i}catch(i){throw e.messages.push({role:"assistant",content:"Sorry, I encountered an error. Please try again."}),i}finally{e.isLoading=false,k();}}function q(){e.isOpen=true,k(),m.onOpen?.(),setTimeout(()=>{s?.querySelector(".aicommerce-input")?.focus();},100);}function O(){e.isOpen=false,k(),m.onClose?.();}function ne(){e.isOpen?O():q();}function ce(){s&&(s.remove(),s=null),w&&(w.remove(),w=null);}function de(a){if(Object.assign(m,a),a.primaryColor){let i=z(m);w&&(w.textContent=i);}k();}function T(a){let i=document.createElement("div");return i.textContent=a,i.innerHTML}function X(a,i){let b={USD:"$",EUR:"\u20AC",GBP:"\xA3",MAD:"DH",SAR:"SAR",AED:"AED",JPY:"\xA5",CNY:"\xA5"}[i||"USD"]||i||"$";return `${a.toFixed(2)} ${b}`}return re(),{open:q,close:O,toggle:ne,destroy:ce,sendMessage:U,updateConfig:de}}exports.AICommerceWidget=void 0;var K=H(()=>{R();Q();exports.AICommerceWidget={init:D,VERSION:"1.0.0"};typeof window<"u"&&(window.AICommerceWidget=exports.AICommerceWidget);});R();K();var xe="1.0.0";typeof window<"u"&&(window.AICommerce=(R(),j(W)).AICommerce,window.AICommerceError=(R(),j(W)).AICommerceError,window.AICommerceWidget=(K(),j(Z)).AICommerceWidget);exports.VERSION=xe;exports.createWidget=D;return exports;})({});//# sourceMappingURL=index.min.js.map
709
1021
  //# sourceMappingURL=index.min.js.map