@yassirbenmoussa/aicommerce-sdk 1.9.3 → 1.9.10

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 me=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var B=(a,r)=>()=>(a&&(r=a(a=0)),r);var G=(a,r)=>{for(var e in r)O(a,e,{get:r[e],enumerable:true});},ue=(a,r,e,d)=>{if(r&&typeof r=="object"||typeof r=="function")for(let h of le(r))!pe.call(a,h)&&h!==e&&O(a,h,{get:()=>r[h],enumerable:!(d=me(r,h))||d.enumerable});return a};var j=a=>ue(O({},"__esModule",{value:true}),a);var W={};G(W,{AICommerce:()=>exports.AICommerce,AICommerceError:()=>exports.AICommerceError});exports.AICommerce=void 0;exports.AICommerceError=void 0;var M=B(()=>{exports.AICommerce=class a{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 d=e.toString();return this.request(`/api/v1/products${d?`?${d}`:""}`)},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 d=`${this.baseUrl}${r}`,h=new AbortController,s=setTimeout(()=>h.abort(),this.timeout);try{let g=await fetch(d,{...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 d=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(d)});return h.sessionToken&&(this.sessionToken=h.sessionToken),h}async chatWithAudio(r,e){let d=await r.arrayBuffer(),s={audioBase64:btoa(new Uint8Array(d).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 checkApiKey(){return this.request("/api/v1/api-key/check")}async getHistory(r){let e=new URLSearchParams;return e.set("sessionToken",r.sessionToken),r.page&&e.set("page",String(r.page)),r.limit&&e.set("limit",String(r.limit)),this.request(`/api/v1/chat/history?${e.toString()}`)}async upload(r,e){let d=new FormData;d.append("file",r),e?.folder&&d.append("folder",e.folder),e?.productId&&d.append("productId",e.productId),e?.isPrimary&&d.append("isPrimary","true");let h=`${this.baseUrl}/api/v1/upload`,s=await fetch(h,{method:"POST",headers:{"X-API-Key":this.apiKey},body:d});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 a({apiKey:r.apiKey,baseUrl:r.baseUrl}).chat(r.message,r.context)}},exports.AICommerceError=class a extends Error{constructor(r,e,d){super(r),this.name="AICommerceError",this.code=e,this.status=d,Object.setPrototypeOf(this,a.prototype);}};});function ge(a){let r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);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(a){let r=a.primaryColor,e=ge(r),d=a.position==="bottom-left";return `
2
+ var se=Object.defineProperty;var ct=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var dt=Object.prototype.hasOwnProperty;var pt=(r,e,t)=>e in r?se(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var ce=(r,e)=>()=>(r&&(e=r(r=0)),e);var Oe=(r,e)=>{for(var t in e)se(r,t,{get:e[t],enumerable:true});},ut=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of lt(e))!dt.call(r,n)&&n!==t&&se(r,n,{get:()=>e[n],enumerable:!(i=ct(e,n))||i.enumerable});return r};var xe=r=>ut(se({},"__esModule",{value:true}),r);var w=(r,e,t)=>pt(r,typeof e!="symbol"?e+"":e,t);var ke={};Oe(ke,{AICommerce:()=>exports.AICommerce,AICommerceError:()=>exports.AICommerceError});exports.AICommerce=void 0;exports.AICommerceError=void 0;var V=ce(()=>{exports.AICommerce=class r{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 t=new URLSearchParams;e?.page&&t.set("page",String(e.page)),e?.perPage&&t.set("perPage",String(e.perPage)),e?.search&&t.set("search",e.search),e?.categoryId&&t.set("categoryId",e.categoryId),e?.isActive!==void 0&&t.set("isActive",String(e.isActive));let i=t.toString();return this.request(`/api/v1/products${i?`?${i}`:""}`)},get:async e=>this.request(`/api/v1/products/${e}`),update:async(e,t)=>this.request(`/api/v1/products/${e}`,{method:"PUT",body:JSON.stringify(t)}),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,t={}){let i=`${this.baseUrl}${e}`,n=new AbortController,a=setTimeout(()=>n.abort(),this.timeout);try{let o=await fetch(i,{...t,signal:n.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},...t.headers}});if(clearTimeout(a),!o.ok){let s=await o.json().catch(()=>({})),l={code:s.code||"UNKNOWN_ERROR",message:s.message||s.error||`HTTP ${o.status}`,status:o.status};throw new exports.AICommerceError(l.message,l.code,l.status)}return o.json()}catch(o){throw clearTimeout(a),o instanceof exports.AICommerceError?o:o instanceof Error&&o.name==="AbortError"?new exports.AICommerceError("Request timeout","TIMEOUT",408):new exports.AICommerceError(o instanceof Error?o.message:"Unknown error","NETWORK_ERROR",0)}}async chat(e,t){let i=typeof e=="string"?{message:e,context:t,sessionToken:this.sessionToken||void 0}:{...e,sessionToken:e.sessionToken||this.sessionToken||void 0},n=await this.request("/api/v1/chat",{method:"POST",body:JSON.stringify(i)});return n.sessionToken&&(this.sessionToken=n.sessionToken),n}async chatWithAudio(e,t){let i=await e.arrayBuffer(),a={audioBase64:btoa(new Uint8Array(i).reduce((s,l)=>s+String.fromCharCode(l),"")),audioMimeType:e.type||"audio/webm",context:t,sessionToken:this.sessionToken||void 0},o=await this.request("/api/v1/chat",{method:"POST",body:JSON.stringify(a)});return o.sessionToken&&(this.sessionToken=o.sessionToken),o}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 checkApiKey(){return this.request("/api/v1/api-key/check")}async getHistory(e){let t=new URLSearchParams;return t.set("sessionToken",e.sessionToken),e.page&&t.set("page",String(e.page)),e.limit&&t.set("limit",String(e.limit)),this.request(`/api/v1/chat/history?${t.toString()}`)}async upload(e,t){let i=new FormData;i.append("file",e),t?.folder&&i.append("folder",t.folder),t?.productId&&i.append("productId",t.productId),t?.isPrimary&&i.append("isPrimary","true");let n=`${this.baseUrl}/api/v1/upload`,a=await fetch(n,{method:"POST",headers:{"X-API-Key":this.apiKey},body:i});if(!a.ok){let o=await a.json().catch(()=>({}));throw new exports.AICommerceError(o.message||o.error||`HTTP ${a.status}`,o.code||"UPLOAD_ERROR",a.status)}return a.json()}static async quickChat(e){return new r({apiKey:e.apiKey,baseUrl:e.baseUrl}).chat(e.message,e.context)}},exports.AICommerceError=class r extends Error{constructor(e,t,i){super(e),this.name="AICommerceError",this.code=t,this.status=i,Object.setPrototypeOf(this,r.prototype);}};});function mt(r){let e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(r);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:{r:99,g:102,b:241}}function ye(r){let e=r.primaryColor,t=mt(e),i=r.position==="bottom-left";return `
3
3
  /* AI Commerce Widget Styles */
4
4
  #aicommerce-widget {
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);
5
+ --aic-primary: ${e};
6
+ --aic-primary-rgb: ${t.r}, ${t.g}, ${t.b};
7
+ --aic-primary-light: rgba(${t.r}, ${t.g}, ${t.b}, 0.1);
8
+ --aic-primary-dark: rgba(${t.r}, ${t.g}, ${t.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 me=Object.getOwnPropertyDescriptor;var le=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: ${a.zIndex};
16
+ --aic-z-index: ${r.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
- ${d?"left: 20px;":"right: 20px;"}
23
+ ${i?"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 me=Object.getOwnPropertyDescriptor;var le=Object
74
74
  .aicommerce-chat {
75
75
  position: absolute;
76
76
  bottom: 0;
77
- ${d?"left: 0;":"right: 0;"}
77
+ ${i?"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 me=Object.getOwnPropertyDescriptor;var le=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 ${d?"left":"right"};
89
+ transform-origin: bottom ${i?"left":"right"};
90
90
  }
91
91
 
92
92
  .aicommerce-chat.aicommerce-closed {
@@ -382,7 +382,7 @@ var O=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object
382
382
  display: flex;
383
383
  align-items: center;
384
384
  gap: 2px;
385
- height: 24px;
385
+ height: 32px;
386
386
  cursor: pointer;
387
387
  width: 100%;
388
388
  }
@@ -390,9 +390,10 @@ var O=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object
390
390
  .aicommerce-waveform-bar {
391
391
  width: 3px;
392
392
  border-radius: 2px;
393
- min-height: 3px;
393
+ min-height: 4px;
394
394
  transition: background-color 0.1s;
395
- flex-shrink: 0;
395
+ flex: 0 0 3px;
396
+ display: block !important;
396
397
  }
397
398
 
398
399
  .aicommerce-audio-time {
@@ -515,7 +516,7 @@ var O=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object
515
516
  @media (max-width: 420px) {
516
517
  #aicommerce-widget {
517
518
  bottom: 16px;
518
- ${d?"left: 16px;":"right: 16px;"}
519
+ ${i?"left: 16px;":"right: 16px;"}
519
520
  }
520
521
 
521
522
  .aicommerce-chat {
@@ -847,6 +848,42 @@ var O=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object
847
848
  flex-shrink: 0;
848
849
  }
849
850
 
851
+ .aicommerce-product-actions {
852
+ display: flex;
853
+ flex-direction: column;
854
+ gap: 8px;
855
+ margin-top: 8px;
856
+ }
857
+
858
+ .aicommerce-product-actions .aicommerce-add-to-cart {
859
+ margin-top: 0;
860
+ flex: 1;
861
+ }
862
+
863
+ .aicommerce-buy-now {
864
+ width: 100%;
865
+ padding: 8px 12px;
866
+ background: transparent;
867
+ color: var(--aic-primary);
868
+ border: 1px solid var(--aic-primary);
869
+ border-radius: 6px;
870
+ font-size: 12px;
871
+ font-weight: 500;
872
+ cursor: pointer;
873
+ transition: all 0.2s;
874
+ display: flex;
875
+ align-items: center;
876
+ justify-content: center;
877
+ }
878
+
879
+ .aicommerce-buy-now:hover {
880
+ background: rgba(0, 0, 0, 0.05);
881
+ }
882
+
883
+ .aicommerce-buy-now:active {
884
+ transform: translateY(1px);
885
+ }
886
+
850
887
  /* Spinner animation for loading state */
851
888
  @keyframes aicommerce-spin {
852
889
  to { transform: rotate(360deg); }
@@ -855,25 +892,137 @@ var O=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object
855
892
  .aicommerce-spinner {
856
893
  animation: aicommerce-spin 1s linear infinite;
857
894
  }
858
- `}function _(a){let r=document.createElement("style");r.id="aicommerce-widget-styles",r.textContent=a;let e=document.getElementById("aicommerce-widget-styles");return e&&e.remove(),document.head.appendChild(r),r}var Q=B(()=>{});var Z={};G(Z,{AICommerceWidget:()=>exports.AICommerceWidget,createWidget:()=>D});function D(a){if(!a.apiKey)throw new Error("AICommerceWidget: apiKey is required");let r=new exports.AICommerce({apiKey:a.apiKey,storeId:a.storeId,baseUrl:a.baseUrl}),e={isOpen:false,isLoading:true,isRecording:false,messages:[],storeConfig:null},d=null,h=[],s=null,w=null,m;async function ee(){try{let o=a.baseUrl||N(),i=await fetch(`${o}/api/v1/store`,{headers:{"x-api-key":a.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 re(){e.storeConfig=await ee();let o=a.displayMode||"widget",i=o==="embedded";m={apiKey:a.apiKey,storeId:a.storeId,baseUrl:a.baseUrl||N(),displayMode:o,container:a.container,maxHeight:a.maxHeight||"600px",placeholder:a.placeholder||"Ask me anything about our products...",position:a.position||"bottom-right",theme:a.theme||"auto",primaryColor:a.primaryColor||e.storeConfig?.primaryColor||"#6366f1",welcomeMessage:a.welcomeMessage||e.storeConfig?.welcomeMessage||"Hi! How can I help you find the perfect product today?",botName:a.botName||e.storeConfig?.chatBotName||"Shopping Assistant",zIndex:a.zIndex||9999,buttonText:a.buttonText||"\u{1F4AC}",hideLauncher:a.hideLauncher||false,addToCartText:a.addToCartText,onOpen:a.onOpen,onClose:a.onClose,onProductClick:a.onProductClick,onAddToCart:a.onAddToCart,onMessage:a.onMessage};let c=z(m);if(w=_(c),i){let b=null;if(typeof a.container=="string"?b=document.querySelector(a.container):a.container instanceof HTMLElement&&(b=a.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(o,i=1){let c=o;if(o.includes("gid://")){let u=o.match(/\/(\d+)$/);u&&(c=u[1]);}if(!(await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:c,quantity:i})})).ok)throw new Error("Failed to add to cart");document.dispatchEvent(new CustomEvent("cart:refresh"));}function k(){if(!s)return;let o=m.displayMode==="embedded",i=e.messages.some(l=>l.role==="user");o&&(s.classList.remove("aicommerce-no-messages","aicommerce-has-messages"),s.classList.add(i?"aicommerce-has-messages":"aicommerce-no-messages"));let c=m.placeholder||"Ask me anything about our products...",b=`
895
+
896
+ /* ============================================
897
+ Markdown Content Styles
898
+ ============================================ */
899
+ .aicommerce-message-content p {
900
+ margin: 0 0 0.5em 0;
901
+ }
902
+ .aicommerce-message-content p:last-child {
903
+ margin-bottom: 0;
904
+ }
905
+
906
+ .aicommerce-message-content strong {
907
+ font-weight: 600;
908
+ }
909
+
910
+ .aicommerce-message-content em {
911
+ font-style: italic;
912
+ }
913
+
914
+ .aicommerce-message-content a {
915
+ text-decoration: underline;
916
+ color: inherit;
917
+ }
918
+ .aicommerce-user .aicommerce-message-content a {
919
+ color: rgba(255, 255, 255, 0.95);
920
+ }
921
+ .aicommerce-assistant .aicommerce-message-content a {
922
+ color: var(--aic-primary);
923
+ }
924
+
925
+ .aicommerce-message-content code {
926
+ background: rgba(0, 0, 0, 0.1);
927
+ padding: 0.1em 0.4em;
928
+ border-radius: 4px;
929
+ font-family: 'Courier New', Courier, monospace;
930
+ font-size: 0.9em;
931
+ }
932
+ .aicommerce-user .aicommerce-message-content code {
933
+ background: rgba(255, 255, 255, 0.2);
934
+ }
935
+
936
+ .aicommerce-message-content ul,
937
+ .aicommerce-message-content ol {
938
+ margin: 0.5em 0;
939
+ padding-left: 1.5em;
940
+ }
941
+
942
+ .aicommerce-message-content li {
943
+ margin-bottom: 0.25em;
944
+ }
945
+
946
+ .aicommerce-message-content blockquote {
947
+ border-left: 3px solid var(--aic-primary);
948
+ margin: 0.5em 0;
949
+ padding-left: 1em;
950
+ opacity: 0.9;
951
+ }
952
+ `}function He(r){let e=document.createElement("style");e.id="aicommerce-widget-styles",e.textContent=r;let t=document.getElementById("aicommerce-widget-styles");return t&&t.remove(),document.head.appendChild(e),e}var Ue=ce(()=>{});function $e(){return {async:false,breaks:false,extensions:null,gfm:true,hooks:null,pedantic:false,renderer:null,silent:false,tokenizer:null,walkTokens:null}}function Ke(r){K=r;}function k(r,e=""){let t=typeof r=="string"?r:r.source,i={replace:(n,a)=>{let o=typeof a=="string"?a:a.source;return o=o.replace(z.caret,"$1"),t=t.replace(n,o),i},getRegex:()=>new RegExp(t,e)};return i}function _(r,e){if(e){if(z.escapeTest.test(r))return r.replace(z.escapeReplace,De)}else if(z.escapeTestNoEncode.test(r))return r.replace(z.escapeReplaceNoEncode,De);return r}function je(r){try{r=encodeURI(r).replace(z.percentDecode,"%");}catch{return null}return r}function We(r,e){let t=r.replace(z.findPipe,(a,o,s)=>{let l=false,c=o;for(;--c>=0&&s[c]==="\\";)l=!l;return l?"|":" |"}),i=t.split(z.splitPipe),n=0;if(i[0].trim()||i.shift(),i.length>0&&!i.at(-1)?.trim()&&i.pop(),e)if(i.length>e)i.splice(e);else for(;i.length<e;)i.push("");for(;n<i.length;n++)i[n]=i[n].trim().replace(z.slashPipe,"|");return i}function te(r,e,t){let i=r.length;if(i===0)return "";let n=0;for(;n<i;){let a=r.charAt(i-n-1);if(a===e&&true)n++;else break}return r.slice(0,i-n)}function Zt(r,e){if(r.indexOf(e[1])===-1)return -1;let t=0;for(let i=0;i<r.length;i++)if(r[i]==="\\")i++;else if(r[i]===e[0])t++;else if(r[i]===e[1]&&(t--,t<0))return i;return t>0?-2:-1}function Fe(r,e,t,i,n){let a=e.href,o=e.title||null,s=r[1].replace(n.other.outputLinkReplace,"$1");i.state.inLink=true;let l={type:r[0].charAt(0)==="!"?"image":"link",raw:t,href:a,title:o,text:s,tokens:i.inlineTokens(s)};return i.state.inLink=false,l}function Gt(r,e,t){let i=r.match(t.other.indentCodeCompensation);if(i===null)return e;let n=i[1];return e.split(`
953
+ `).map(a=>{let o=a.match(t.other.beginningSpace);if(o===null)return a;let[s]=o;return s.length>=n.length?a.slice(n.length):a}).join(`
954
+ `)}function b(r,e){return F.parse(r,e)}var K,re,z,ht,gt,ft,ne,bt,Se,Ze,Ge,xt,Re,kt,Ae,yt,wt,he,Ee,vt,Qe,Tt,Pe,Ne,Ct,$t,St,Rt,Xe,At,ge,Le,Ye,Et,Je,Pt,Lt,It,Ve,zt,Bt,et,Mt,qt,_t,Ot,Ht,Ut,Nt,pe,Dt,tt,rt,jt,Ie,Wt,ve,Ft,le,ee,Kt,De,ue,N,me,ze,D,we,de,Qt,F,nt=ce(()=>{K=$e();re={exec:()=>null};z={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:r=>new RegExp(`^( {0,3}${r})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:r=>new RegExp(`^ {0,${Math.min(3,r-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:r=>new RegExp(`^ {0,${Math.min(3,r-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:r=>new RegExp(`^ {0,${Math.min(3,r-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:r=>new RegExp(`^ {0,${Math.min(3,r-1)}}#`),htmlBeginRegex:r=>new RegExp(`^ {0,${Math.min(3,r-1)}}<(?:[a-z].*>|!--)`,"i")},ht=/^(?:[ \t]*(?:\n|$))+/,gt=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,ft=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,ne=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,bt=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Se=/(?:[*+-]|\d{1,9}[.)])/,Ze=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Ge=k(Ze).replace(/bull/g,Se).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),xt=k(Ze).replace(/bull/g,Se).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Re=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,kt=/^[^\n]+/,Ae=/(?!\s*\])(?:\\.|[^\[\]\\])+/,yt=k(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Ae).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),wt=k(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Se).getRegex(),he="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Ee=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,vt=k("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",Ee).replace("tag",he).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Qe=k(Re).replace("hr",ne).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",he).getRegex(),Tt=k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Qe).getRegex(),Pe={blockquote:Tt,code:gt,def:yt,fences:ft,heading:bt,hr:ne,html:vt,lheading:Ge,list:wt,newline:ht,paragraph:Qe,table:re,text:kt},Ne=k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",ne).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",he).getRegex(),Ct={...Pe,lheading:xt,table:Ne,paragraph:k(Re).replace("hr",ne).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Ne).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",he).getRegex()},$t={...Pe,html:k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Ee).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:re,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:k(Re).replace("hr",ne).replace("heading",` *#{1,6} *[^
955
+ ]`).replace("lheading",Ge).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},St=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Rt=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Xe=/^( {2,}|\\)\n(?!\s*$)/,At=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,ge=/[\p{P}\p{S}]/u,Le=/[\s\p{P}\p{S}]/u,Ye=/[^\s\p{P}\p{S}]/u,Et=k(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Le).getRegex(),Je=/(?!~)[\p{P}\p{S}]/u,Pt=/(?!~)[\s\p{P}\p{S}]/u,Lt=/(?:[^\s\p{P}\p{S}]|~)/u,It=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,Ve=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,zt=k(Ve,"u").replace(/punct/g,ge).getRegex(),Bt=k(Ve,"u").replace(/punct/g,Je).getRegex(),et="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Mt=k(et,"gu").replace(/notPunctSpace/g,Ye).replace(/punctSpace/g,Le).replace(/punct/g,ge).getRegex(),qt=k(et,"gu").replace(/notPunctSpace/g,Lt).replace(/punctSpace/g,Pt).replace(/punct/g,Je).getRegex(),_t=k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Ye).replace(/punctSpace/g,Le).replace(/punct/g,ge).getRegex(),Ot=k(/\\(punct)/,"gu").replace(/punct/g,ge).getRegex(),Ht=k(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Ut=k(Ee).replace("(?:-->|$)","-->").getRegex(),Nt=k("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Ut).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),pe=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Dt=k(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",pe).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),tt=k(/^!?\[(label)\]\[(ref)\]/).replace("label",pe).replace("ref",Ae).getRegex(),rt=k(/^!?\[(ref)\](?:\[\])?/).replace("ref",Ae).getRegex(),jt=k("reflink|nolink(?!\\()","g").replace("reflink",tt).replace("nolink",rt).getRegex(),Ie={_backpedal:re,anyPunctuation:Ot,autolink:Ht,blockSkip:It,br:Xe,code:Rt,del:re,emStrongLDelim:zt,emStrongRDelimAst:Mt,emStrongRDelimUnd:_t,escape:St,link:Dt,nolink:rt,punctuation:Et,reflink:tt,reflinkSearch:jt,tag:Nt,text:At,url:re},Wt={...Ie,link:k(/^!?\[(label)\]\((.*?)\)/).replace("label",pe).getRegex(),reflink:k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",pe).getRegex()},ve={...Ie,emStrongRDelimAst:qt,emStrongLDelim:Bt,url:k(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},Ft={...ve,br:k(Xe).replace("{2,}","*").getRegex(),text:k(ve.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},le={normal:Pe,gfm:Ct,pedantic:$t},ee={normal:Ie,gfm:ve,breaks:Ft,pedantic:Wt},Kt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},De=r=>Kt[r];ue=class{constructor(r){w(this,"options");w(this,"rules");w(this,"lexer");this.options=r||K;}space(r){let e=this.rules.block.newline.exec(r);if(e&&e[0].length>0)return {type:"space",raw:e[0]}}code(r){let e=this.rules.block.code.exec(r);if(e){let t=e[0].replace(this.rules.other.codeRemoveIndent,"");return {type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?t:te(t,`
956
+ `)}}}fences(r){let e=this.rules.block.fences.exec(r);if(e){let t=e[0],i=Gt(t,e[3]||"",this.rules);return {type:"code",raw:t,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:i}}}heading(r){let e=this.rules.block.heading.exec(r);if(e){let t=e[2].trim();if(this.rules.other.endingHash.test(t)){let i=te(t,"#");(this.options.pedantic||!i||this.rules.other.endingSpaceChar.test(i))&&(t=i.trim());}return {type:"heading",raw:e[0],depth:e[1].length,text:t,tokens:this.lexer.inline(t)}}}hr(r){let e=this.rules.block.hr.exec(r);if(e)return {type:"hr",raw:te(e[0],`
957
+ `)}}blockquote(r){let e=this.rules.block.blockquote.exec(r);if(e){let t=te(e[0],`
958
+ `).split(`
959
+ `),i="",n="",a=[];for(;t.length>0;){let o=false,s=[],l;for(l=0;l<t.length;l++)if(this.rules.other.blockquoteStart.test(t[l]))s.push(t[l]),o=true;else if(!o)s.push(t[l]);else break;t=t.slice(l);let c=s.join(`
960
+ `),h=c.replace(this.rules.other.blockquoteSetextReplace,`
961
+ $1`).replace(this.rules.other.blockquoteSetextReplace2,"");i=i?`${i}
962
+ ${c}`:c,n=n?`${n}
963
+ ${h}`:h;let v=this.lexer.state.top;if(this.lexer.state.top=true,this.lexer.blockTokens(h,a,true),this.lexer.state.top=v,t.length===0)break;let f=a.at(-1);if(f?.type==="code")break;if(f?.type==="blockquote"){let L=f,T=L.raw+`
964
+ `+t.join(`
965
+ `),$=this.blockquote(T);a[a.length-1]=$,i=i.substring(0,i.length-L.raw.length)+$.raw,n=n.substring(0,n.length-L.text.length)+$.text;break}else if(f?.type==="list"){let L=f,T=L.raw+`
966
+ `+t.join(`
967
+ `),$=this.list(T);a[a.length-1]=$,i=i.substring(0,i.length-f.raw.length)+$.raw,n=n.substring(0,n.length-L.raw.length)+$.raw,t=T.substring(a.at(-1).raw.length).split(`
968
+ `);continue}}return {type:"blockquote",raw:i,tokens:a,text:n}}}list(r){let e=this.rules.block.list.exec(r);if(e){let t=e[1].trim(),i=t.length>1,n={type:"list",raw:"",ordered:i,start:i?+t.slice(0,-1):"",loose:false,items:[]};t=i?`\\d{1,9}\\${t.slice(-1)}`:`\\${t}`,this.options.pedantic&&(t=i?t:"[*+-]");let a=this.rules.other.listItemRegex(t),o=false;for(;r;){let l=false,c="",h="";if(!(e=a.exec(r))||this.rules.block.hr.test(r))break;c=e[0],r=r.substring(c.length);let v=e[2].split(`
969
+ `,1)[0].replace(this.rules.other.listReplaceTabs,Q=>" ".repeat(3*Q.length)),f=r.split(`
970
+ `,1)[0],L=!v.trim(),T=0;if(this.options.pedantic?(T=2,h=v.trimStart()):L?T=e[1].length+1:(T=e[2].search(this.rules.other.nonSpaceChar),T=T>4?1:T,h=v.slice(T),T+=e[1].length),L&&this.rules.other.blankLine.test(f)&&(c+=f+`
971
+ `,r=r.substring(f.length+1),l=true),!l){let Q=this.rules.other.nextBulletRegex(T),ie=this.rules.other.hrRegex(T),ae=this.rules.other.fencesBeginRegex(T),X=this.rules.other.headingBeginRegex(T),oe=this.rules.other.htmlBeginRegex(T);for(;r;){let Y=r.split(`
972
+ `,1)[0],O;if(f=Y,this.options.pedantic?(f=f.replace(this.rules.other.listReplaceNesting," "),O=f):O=f.replace(this.rules.other.tabCharGlobal," "),ae.test(f)||X.test(f)||oe.test(f)||Q.test(f)||ie.test(f))break;if(O.search(this.rules.other.nonSpaceChar)>=T||!f.trim())h+=`
973
+ `+O.slice(T);else {if(L||v.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||ae.test(v)||X.test(v)||ie.test(v))break;h+=`
974
+ `+f;}!L&&!f.trim()&&(L=true),c+=Y+`
975
+ `,r=r.substring(Y.length+1),v=O.slice(T);}}n.loose||(o?n.loose=true:this.rules.other.doubleBlankLine.test(c)&&(o=true));let $=null,G;this.options.gfm&&($=this.rules.other.listIsTask.exec(h),$&&(G=$[0]!=="[ ] ",h=h.replace(this.rules.other.listReplaceTask,""))),n.items.push({type:"list_item",raw:c,task:!!$,checked:G,loose:false,text:h,tokens:[]}),n.raw+=c;}let s=n.items.at(-1);if(s)s.raw=s.raw.trimEnd(),s.text=s.text.trimEnd();else return;n.raw=n.raw.trimEnd();for(let l=0;l<n.items.length;l++)if(this.lexer.state.top=false,n.items[l].tokens=this.lexer.blockTokens(n.items[l].text,[]),!n.loose){let c=n.items[l].tokens.filter(v=>v.type==="space"),h=c.length>0&&c.some(v=>this.rules.other.anyLine.test(v.raw));n.loose=h;}if(n.loose)for(let l=0;l<n.items.length;l++)n.items[l].loose=true;return n}}html(r){let e=this.rules.block.html.exec(r);if(e)return {type:"html",block:true,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(r){let e=this.rules.block.def.exec(r);if(e){let t=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),i=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",n=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return {type:"def",tag:t,raw:e[0],href:i,title:n}}}table(r){let e=this.rules.block.table.exec(r);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let t=We(e[1]),i=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),n=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
976
+ `):[],a={type:"table",raw:e[0],header:[],align:[],rows:[]};if(t.length===i.length){for(let o of i)this.rules.other.tableAlignRight.test(o)?a.align.push("right"):this.rules.other.tableAlignCenter.test(o)?a.align.push("center"):this.rules.other.tableAlignLeft.test(o)?a.align.push("left"):a.align.push(null);for(let o=0;o<t.length;o++)a.header.push({text:t[o],tokens:this.lexer.inline(t[o]),header:true,align:a.align[o]});for(let o of n)a.rows.push(We(o,a.header.length).map((s,l)=>({text:s,tokens:this.lexer.inline(s),header:false,align:a.align[l]})));return a}}lheading(r){let e=this.rules.block.lheading.exec(r);if(e)return {type:"heading",raw:e[0],depth:e[2].charAt(0)==="="?1:2,text:e[1],tokens:this.lexer.inline(e[1])}}paragraph(r){let e=this.rules.block.paragraph.exec(r);if(e){let t=e[1].charAt(e[1].length-1)===`
977
+ `?e[1].slice(0,-1):e[1];return {type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}}text(r){let e=this.rules.block.text.exec(r);if(e)return {type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(r){let e=this.rules.inline.escape.exec(r);if(e)return {type:"escape",raw:e[0],text:e[1]}}tag(r){let e=this.rules.inline.tag.exec(r);if(e)return !this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=true:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=false),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=true:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=false),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:false,text:e[0]}}link(r){let e=this.rules.inline.link.exec(r);if(e){let t=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(t)){if(!this.rules.other.endAngleBracket.test(t))return;let a=te(t.slice(0,-1),"\\");if((t.length-a.length)%2===0)return}else {let a=Zt(e[2],"()");if(a===-2)return;if(a>-1){let s=(e[0].indexOf("!")===0?5:4)+e[1].length+a;e[2]=e[2].substring(0,a),e[0]=e[0].substring(0,s).trim(),e[3]="";}}let i=e[2],n="";if(this.options.pedantic){let a=this.rules.other.pedanticHrefTitle.exec(i);a&&(i=a[1],n=a[3]);}else n=e[3]?e[3].slice(1,-1):"";return i=i.trim(),this.rules.other.startAngleBracket.test(i)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(t)?i=i.slice(1):i=i.slice(1,-1)),Fe(e,{href:i&&i.replace(this.rules.inline.anyPunctuation,"$1"),title:n&&n.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(r,e){let t;if((t=this.rules.inline.reflink.exec(r))||(t=this.rules.inline.nolink.exec(r))){let i=(t[2]||t[1]).replace(this.rules.other.multipleSpaceGlobal," "),n=e[i.toLowerCase()];if(!n){let a=t[0].charAt(0);return {type:"text",raw:a,text:a}}return Fe(t,n,t[0],this.lexer,this.rules)}}emStrong(r,e,t=""){let i=this.rules.inline.emStrongLDelim.exec(r);if(!i||i[3]&&t.match(this.rules.other.unicodeAlphaNumeric))return;if(!(i[1]||i[2]||"")||!t||this.rules.inline.punctuation.exec(t)){let a=[...i[0]].length-1,o,s,l=a,c=0,h=i[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(h.lastIndex=0,e=e.slice(-1*r.length+a);(i=h.exec(e))!=null;){if(o=i[1]||i[2]||i[3]||i[4]||i[5]||i[6],!o)continue;if(s=[...o].length,i[3]||i[4]){l+=s;continue}else if((i[5]||i[6])&&a%3&&!((a+s)%3)){c+=s;continue}if(l-=s,l>0)continue;s=Math.min(s,s+l+c);let v=[...i[0]][0].length,f=r.slice(0,a+i.index+v+s);if(Math.min(a,s)%2){let T=f.slice(1,-1);return {type:"em",raw:f,text:T,tokens:this.lexer.inlineTokens(T)}}let L=f.slice(2,-2);return {type:"strong",raw:f,text:L,tokens:this.lexer.inlineTokens(L)}}}}codespan(r){let e=this.rules.inline.code.exec(r);if(e){let t=e[2].replace(this.rules.other.newLineCharGlobal," "),i=this.rules.other.nonSpaceChar.test(t),n=this.rules.other.startingSpaceChar.test(t)&&this.rules.other.endingSpaceChar.test(t);return i&&n&&(t=t.substring(1,t.length-1)),{type:"codespan",raw:e[0],text:t}}}br(r){let e=this.rules.inline.br.exec(r);if(e)return {type:"br",raw:e[0]}}del(r){let e=this.rules.inline.del.exec(r);if(e)return {type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(r){let e=this.rules.inline.autolink.exec(r);if(e){let t,i;return e[2]==="@"?(t=e[1],i="mailto:"+t):(t=e[1],i=t),{type:"link",raw:e[0],text:t,href:i,tokens:[{type:"text",raw:t,text:t}]}}}url(r){let e;if(e=this.rules.inline.url.exec(r)){let t,i;if(e[2]==="@")t=e[0],i="mailto:"+t;else {let n;do n=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(n!==e[0]);t=e[0],e[1]==="www."?i="http://"+e[0]:i=e[0];}return {type:"link",raw:e[0],text:t,href:i,tokens:[{type:"text",raw:t,text:t}]}}}inlineText(r){let e=this.rules.inline.text.exec(r);if(e){let t=this.lexer.state.inRawBlock;return {type:"text",raw:e[0],text:e[0],escaped:t}}}},N=class Te{constructor(e){w(this,"tokens");w(this,"options");w(this,"state");w(this,"tokenizer");w(this,"inlineQueue");this.tokens=[],this.tokens.links=Object.create(null),this.options=e||K,this.options.tokenizer=this.options.tokenizer||new ue,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:false,inRawBlock:false,top:true};let t={other:z,block:le.normal,inline:ee.normal};this.options.pedantic?(t.block=le.pedantic,t.inline=ee.pedantic):this.options.gfm&&(t.block=le.gfm,this.options.breaks?t.inline=ee.breaks:t.inline=ee.gfm),this.tokenizer.rules=t;}static get rules(){return {block:le,inline:ee}}static lex(e,t){return new Te(t).lex(e)}static lexInline(e,t){return new Te(t).inlineTokens(e)}lex(e){e=e.replace(z.carriageReturn,`
978
+ `),this.blockTokens(e,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){let i=this.inlineQueue[t];this.inlineTokens(i.src,i.tokens);}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],i=false){for(this.options.pedantic&&(e=e.replace(z.tabCharGlobal," ").replace(z.spaceLine,""));e;){let n;if(this.options.extensions?.block?.some(o=>(n=o.call({lexer:this},e,t))?(e=e.substring(n.raw.length),t.push(n),true):false))continue;if(n=this.tokenizer.space(e)){e=e.substring(n.raw.length);let o=t.at(-1);n.raw.length===1&&o!==void 0?o.raw+=`
979
+ `:t.push(n);continue}if(n=this.tokenizer.code(e)){e=e.substring(n.raw.length);let o=t.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=`
980
+ `+n.raw,o.text+=`
981
+ `+n.text,this.inlineQueue.at(-1).src=o.text):t.push(n);continue}if(n=this.tokenizer.fences(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.heading(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.hr(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.blockquote(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.list(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.html(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.def(e)){e=e.substring(n.raw.length);let o=t.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=`
982
+ `+n.raw,o.text+=`
983
+ `+n.raw,this.inlineQueue.at(-1).src=o.text):this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title});continue}if(n=this.tokenizer.table(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.lheading(e)){e=e.substring(n.raw.length),t.push(n);continue}let a=e;if(this.options.extensions?.startBlock){let o=1/0,s=e.slice(1),l;this.options.extensions.startBlock.forEach(c=>{l=c.call({lexer:this},s),typeof l=="number"&&l>=0&&(o=Math.min(o,l));}),o<1/0&&o>=0&&(a=e.substring(0,o+1));}if(this.state.top&&(n=this.tokenizer.paragraph(a))){let o=t.at(-1);i&&o?.type==="paragraph"?(o.raw+=`
984
+ `+n.raw,o.text+=`
985
+ `+n.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):t.push(n),i=a.length!==e.length,e=e.substring(n.raw.length);continue}if(n=this.tokenizer.text(e)){e=e.substring(n.raw.length);let o=t.at(-1);o?.type==="text"?(o.raw+=`
986
+ `+n.raw,o.text+=`
987
+ `+n.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):t.push(n);continue}if(e){let o="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(o);break}else throw new Error(o)}}return this.state.top=true,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let i=e,n=null;if(this.tokens.links){let s=Object.keys(this.tokens.links);if(s.length>0)for(;(n=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)s.includes(n[0].slice(n[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,n.index)+"["+"a".repeat(n[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));}for(;(n=this.tokenizer.rules.inline.anyPunctuation.exec(i))!=null;)i=i.slice(0,n.index)+"++"+i.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(n=this.tokenizer.rules.inline.blockSkip.exec(i))!=null;)i=i.slice(0,n.index)+"["+"a".repeat(n[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let a=false,o="";for(;e;){a||(o=""),a=false;let s;if(this.options.extensions?.inline?.some(c=>(s=c.call({lexer:this},e,t))?(e=e.substring(s.raw.length),t.push(s),true):false))continue;if(s=this.tokenizer.escape(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.tag(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.link(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(s.raw.length);let c=t.at(-1);s.type==="text"&&c?.type==="text"?(c.raw+=s.raw,c.text+=s.text):t.push(s);continue}if(s=this.tokenizer.emStrong(e,i,o)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.codespan(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.br(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.del(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.autolink(e)){e=e.substring(s.raw.length),t.push(s);continue}if(!this.state.inLink&&(s=this.tokenizer.url(e))){e=e.substring(s.raw.length),t.push(s);continue}let l=e;if(this.options.extensions?.startInline){let c=1/0,h=e.slice(1),v;this.options.extensions.startInline.forEach(f=>{v=f.call({lexer:this},h),typeof v=="number"&&v>=0&&(c=Math.min(c,v));}),c<1/0&&c>=0&&(l=e.substring(0,c+1));}if(s=this.tokenizer.inlineText(l)){e=e.substring(s.raw.length),s.raw.slice(-1)!=="_"&&(o=s.raw.slice(-1)),a=true;let c=t.at(-1);c?.type==="text"?(c.raw+=s.raw,c.text+=s.text):t.push(s);continue}if(e){let c="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(c);break}else throw new Error(c)}}return t}},me=class{constructor(r){w(this,"options");w(this,"parser");this.options=r||K;}space(r){return ""}code({text:r,lang:e,escaped:t}){let i=(e||"").match(z.notSpaceStart)?.[0],n=r.replace(z.endingNewline,"")+`
988
+ `;return i?'<pre><code class="language-'+_(i)+'">'+(t?n:_(n,true))+`</code></pre>
989
+ `:"<pre><code>"+(t?n:_(n,true))+`</code></pre>
990
+ `}blockquote({tokens:r}){return `<blockquote>
991
+ ${this.parser.parse(r)}</blockquote>
992
+ `}html({text:r}){return r}heading({tokens:r,depth:e}){return `<h${e}>${this.parser.parseInline(r)}</h${e}>
993
+ `}hr(r){return `<hr>
994
+ `}list(r){let e=r.ordered,t=r.start,i="";for(let o=0;o<r.items.length;o++){let s=r.items[o];i+=this.listitem(s);}let n=e?"ol":"ul",a=e&&t!==1?' start="'+t+'"':"";return "<"+n+a+`>
995
+ `+i+"</"+n+`>
996
+ `}listitem(r){let e="";if(r.task){let t=this.checkbox({checked:!!r.checked});r.loose?r.tokens[0]?.type==="paragraph"?(r.tokens[0].text=t+" "+r.tokens[0].text,r.tokens[0].tokens&&r.tokens[0].tokens.length>0&&r.tokens[0].tokens[0].type==="text"&&(r.tokens[0].tokens[0].text=t+" "+_(r.tokens[0].tokens[0].text),r.tokens[0].tokens[0].escaped=true)):r.tokens.unshift({type:"text",raw:t+" ",text:t+" ",escaped:true}):e+=t+" ";}return e+=this.parser.parse(r.tokens,!!r.loose),`<li>${e}</li>
997
+ `}checkbox({checked:r}){return "<input "+(r?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:r}){return `<p>${this.parser.parseInline(r)}</p>
998
+ `}table(r){let e="",t="";for(let n=0;n<r.header.length;n++)t+=this.tablecell(r.header[n]);e+=this.tablerow({text:t});let i="";for(let n=0;n<r.rows.length;n++){let a=r.rows[n];t="";for(let o=0;o<a.length;o++)t+=this.tablecell(a[o]);i+=this.tablerow({text:t});}return i&&(i=`<tbody>${i}</tbody>`),`<table>
999
+ <thead>
1000
+ `+e+`</thead>
1001
+ `+i+`</table>
1002
+ `}tablerow({text:r}){return `<tr>
1003
+ ${r}</tr>
1004
+ `}tablecell(r){let e=this.parser.parseInline(r.tokens),t=r.header?"th":"td";return (r.align?`<${t} align="${r.align}">`:`<${t}>`)+e+`</${t}>
1005
+ `}strong({tokens:r}){return `<strong>${this.parser.parseInline(r)}</strong>`}em({tokens:r}){return `<em>${this.parser.parseInline(r)}</em>`}codespan({text:r}){return `<code>${_(r,true)}</code>`}br(r){return "<br>"}del({tokens:r}){return `<del>${this.parser.parseInline(r)}</del>`}link({href:r,title:e,tokens:t}){let i=this.parser.parseInline(t),n=je(r);if(n===null)return i;r=n;let a='<a href="'+r+'"';return e&&(a+=' title="'+_(e)+'"'),a+=">"+i+"</a>",a}image({href:r,title:e,text:t,tokens:i}){i&&(t=this.parser.parseInline(i,this.parser.textRenderer));let n=je(r);if(n===null)return _(t);r=n;let a=`<img src="${r}" alt="${t}"`;return e&&(a+=` title="${_(e)}"`),a+=">",a}text(r){return "tokens"in r&&r.tokens?this.parser.parseInline(r.tokens):"escaped"in r&&r.escaped?r.text:_(r.text)}},ze=class{strong({text:r}){return r}em({text:r}){return r}codespan({text:r}){return r}del({text:r}){return r}html({text:r}){return r}text({text:r}){return r}link({text:r}){return ""+r}image({text:r}){return ""+r}br(){return ""}},D=class Ce{constructor(e){w(this,"options");w(this,"renderer");w(this,"textRenderer");this.options=e||K,this.options.renderer=this.options.renderer||new me,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ze;}static parse(e,t){return new Ce(t).parse(e)}static parseInline(e,t){return new Ce(t).parseInline(e)}parse(e,t=true){let i="";for(let n=0;n<e.length;n++){let a=e[n];if(this.options.extensions?.renderers?.[a.type]){let s=a,l=this.options.extensions.renderers[s.type].call({parser:this},s);if(l!==false||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(s.type)){i+=l||"";continue}}let o=a;switch(o.type){case "space":{i+=this.renderer.space(o);continue}case "hr":{i+=this.renderer.hr(o);continue}case "heading":{i+=this.renderer.heading(o);continue}case "code":{i+=this.renderer.code(o);continue}case "table":{i+=this.renderer.table(o);continue}case "blockquote":{i+=this.renderer.blockquote(o);continue}case "list":{i+=this.renderer.list(o);continue}case "html":{i+=this.renderer.html(o);continue}case "paragraph":{i+=this.renderer.paragraph(o);continue}case "text":{let s=o,l=this.renderer.text(s);for(;n+1<e.length&&e[n+1].type==="text";)s=e[++n],l+=`
1006
+ `+this.renderer.text(s);t?i+=this.renderer.paragraph({type:"paragraph",raw:l,text:l,tokens:[{type:"text",raw:l,text:l,escaped:true}]}):i+=l;continue}default:{let s='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return i}parseInline(e,t=this.renderer){let i="";for(let n=0;n<e.length;n++){let a=e[n];if(this.options.extensions?.renderers?.[a.type]){let s=this.options.extensions.renderers[a.type].call({parser:this},a);if(s!==false||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(a.type)){i+=s||"";continue}}let o=a;switch(o.type){case "escape":{i+=t.text(o);break}case "html":{i+=t.html(o);break}case "link":{i+=t.link(o);break}case "image":{i+=t.image(o);break}case "strong":{i+=t.strong(o);break}case "em":{i+=t.em(o);break}case "codespan":{i+=t.codespan(o);break}case "br":{i+=t.br(o);break}case "del":{i+=t.del(o);break}case "text":{i+=t.text(o);break}default:{let s='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return i}},de=(we=class{constructor(r){w(this,"options");w(this,"block");this.options=r||K;}preprocess(r){return r}postprocess(r){return r}processAllTokens(r){return r}provideLexer(){return this.block?N.lex:N.lexInline}provideParser(){return this.block?D.parse:D.parseInline}},w(we,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"])),we),Qt=class{constructor(...r){w(this,"defaults",$e());w(this,"options",this.setOptions);w(this,"parse",this.parseMarkdown(true));w(this,"parseInline",this.parseMarkdown(false));w(this,"Parser",D);w(this,"Renderer",me);w(this,"TextRenderer",ze);w(this,"Lexer",N);w(this,"Tokenizer",ue);w(this,"Hooks",de);this.use(...r);}walkTokens(r,e){let t=[];for(let i of r)switch(t=t.concat(e.call(this,i)),i.type){case "table":{let n=i;for(let a of n.header)t=t.concat(this.walkTokens(a.tokens,e));for(let a of n.rows)for(let o of a)t=t.concat(this.walkTokens(o.tokens,e));break}case "list":{let n=i;t=t.concat(this.walkTokens(n.items,e));break}default:{let n=i;this.defaults.extensions?.childTokens?.[n.type]?this.defaults.extensions.childTokens[n.type].forEach(a=>{let o=n[a].flat(1/0);t=t.concat(this.walkTokens(o,e));}):n.tokens&&(t=t.concat(this.walkTokens(n.tokens,e)));}}return t}use(...r){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return r.forEach(t=>{let i={...t};if(i.async=this.defaults.async||i.async||false,t.extensions&&(t.extensions.forEach(n=>{if(!n.name)throw new Error("extension name required");if("renderer"in n){let a=e.renderers[n.name];a?e.renderers[n.name]=function(...o){let s=n.renderer.apply(this,o);return s===false&&(s=a.apply(this,o)),s}:e.renderers[n.name]=n.renderer;}if("tokenizer"in n){if(!n.level||n.level!=="block"&&n.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let a=e[n.level];a?a.unshift(n.tokenizer):e[n.level]=[n.tokenizer],n.start&&(n.level==="block"?e.startBlock?e.startBlock.push(n.start):e.startBlock=[n.start]:n.level==="inline"&&(e.startInline?e.startInline.push(n.start):e.startInline=[n.start]));}"childTokens"in n&&n.childTokens&&(e.childTokens[n.name]=n.childTokens);}),i.extensions=e),t.renderer){let n=this.defaults.renderer||new me(this.defaults);for(let a in t.renderer){if(!(a in n))throw new Error(`renderer '${a}' does not exist`);if(["options","parser"].includes(a))continue;let o=a,s=t.renderer[o],l=n[o];n[o]=(...c)=>{let h=s.apply(n,c);return h===false&&(h=l.apply(n,c)),h||""};}i.renderer=n;}if(t.tokenizer){let n=this.defaults.tokenizer||new ue(this.defaults);for(let a in t.tokenizer){if(!(a in n))throw new Error(`tokenizer '${a}' does not exist`);if(["options","rules","lexer"].includes(a))continue;let o=a,s=t.tokenizer[o],l=n[o];n[o]=(...c)=>{let h=s.apply(n,c);return h===false&&(h=l.apply(n,c)),h};}i.tokenizer=n;}if(t.hooks){let n=this.defaults.hooks||new de;for(let a in t.hooks){if(!(a in n))throw new Error(`hook '${a}' does not exist`);if(["options","block"].includes(a))continue;let o=a,s=t.hooks[o],l=n[o];de.passThroughHooks.has(a)?n[o]=c=>{if(this.defaults.async)return Promise.resolve(s.call(n,c)).then(v=>l.call(n,v));let h=s.call(n,c);return l.call(n,h)}:n[o]=(...c)=>{let h=s.apply(n,c);return h===false&&(h=l.apply(n,c)),h};}i.hooks=n;}if(t.walkTokens){let n=this.defaults.walkTokens,a=t.walkTokens;i.walkTokens=function(o){let s=[];return s.push(a.call(this,o)),n&&(s=s.concat(n.call(this,o))),s};}this.defaults={...this.defaults,...i};}),this}setOptions(r){return this.defaults={...this.defaults,...r},this}lexer(r,e){return N.lex(r,e??this.defaults)}parser(r,e){return D.parse(r,e??this.defaults)}parseMarkdown(r){return (t,i)=>{let n={...i},a={...this.defaults,...n},o=this.onError(!!a.silent,!!a.async);if(this.defaults.async===true&&n.async===false)return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||t===null)return o(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return o(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));a.hooks&&(a.hooks.options=a,a.hooks.block=r);let s=a.hooks?a.hooks.provideLexer():r?N.lex:N.lexInline,l=a.hooks?a.hooks.provideParser():r?D.parse:D.parseInline;if(a.async)return Promise.resolve(a.hooks?a.hooks.preprocess(t):t).then(c=>s(c,a)).then(c=>a.hooks?a.hooks.processAllTokens(c):c).then(c=>a.walkTokens?Promise.all(this.walkTokens(c,a.walkTokens)).then(()=>c):c).then(c=>l(c,a)).then(c=>a.hooks?a.hooks.postprocess(c):c).catch(o);try{a.hooks&&(t=a.hooks.preprocess(t));let c=s(t,a);a.hooks&&(c=a.hooks.processAllTokens(c)),a.walkTokens&&this.walkTokens(c,a.walkTokens);let h=l(c,a);return a.hooks&&(h=a.hooks.postprocess(h)),h}catch(c){return o(c)}}}onError(r,e){return t=>{if(t.message+=`
1007
+ Please report this to https://github.com/markedjs/marked.`,r){let i="<p>An error occurred:</p><pre>"+_(t.message+"",true)+"</pre>";return e?Promise.resolve(i):i}if(e)return Promise.reject(t);throw t}}},F=new Qt;b.options=b.setOptions=function(r){return F.setOptions(r),b.defaults=F.defaults,Ke(b.defaults),b};b.getDefaults=$e;b.defaults=K;b.use=function(...r){return F.use(...r),b.defaults=F.defaults,Ke(b.defaults),b};b.walkTokens=function(r,e){return F.walkTokens(r,e)};b.parseInline=F.parseInline;b.Parser=D;b.parser=D.parse;b.Renderer=me;b.TextRenderer=ze;b.Lexer=N;b.lexer=N.lex;b.Tokenizer=ue;b.Hooks=de;b.parse=b;b.options,b.setOptions,b.use,b.walkTokens,b.parseInline,D.parse,N.lex;});var it={};Oe(it,{AICommerceWidget:()=>exports.AICommerceWidget,createWidget:()=>Be});function Be(r){if(!r.apiKey)throw new Error("AICommerceWidget: apiKey is required");let e=new exports.AICommerce({apiKey:r.apiKey,storeId:r.storeId,baseUrl:r.baseUrl,timeout:12e4}),t={isOpen:false,isLoading:true,isRecording:false,messages:[]},i=null,n=[],a=null,l=null,c;async function h(){try{let p=r.baseUrl||v(),m=await fetch(`${p}/api/v1/store`,{headers:{"x-api-key":r.apiKey}});return m.ok?(await m.json()).store:null}catch(p){return console.error("Failed to fetch store config:",p),null}}function v(){if(typeof window<"u"){let p=document.querySelector("script[data-aicommerce-url]");if(p)return p.getAttribute("data-aicommerce-url")||""}return "https://api.aicommerce.dev"}async function f(){t.storeConfig=await h()||void 0;let p=r.displayMode||"widget",m=p==="embedded";c={apiKey:r.apiKey,storeId:r.storeId,baseUrl:r.baseUrl||v(),displayMode:p,container:r.container,maxHeight:r.maxHeight||"600px",placeholder:r.placeholder||"Ask me anything about our products...",position:r.position||"bottom-right",theme:r.theme||"auto",primaryColor:r.primaryColor||t.storeConfig?.primaryColor||"#6366f1",welcomeMessage:r.welcomeMessage||t.storeConfig?.welcomeMessage||"Hi! How can I help you find the perfect product today?",botName:r.botName||t.storeConfig?.chatBotName||"Shopping Assistant",zIndex:r.zIndex||9999,buttonText:r.buttonText||"\u{1F4AC}",hideLauncher:r.hideLauncher||false,addToCartText:r.addToCartText,onOpen:r.onOpen,onClose:r.onClose,onProductClick:r.onProductClick,onAddToCart:r.onAddToCart,showAddToCart:r.showAddToCart,onBuyNow:r.onBuyNow,showBuyNow:r.showBuyNow,onMessage:r.onMessage};let u=ye(c);if(l=He(u),m){let A=null;if(typeof r.container=="string"?A=document.querySelector(r.container):r.container instanceof HTMLElement&&(A=r.container),!A){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-${c.theme}`,a.style.setProperty("--aic-max-height",c.maxHeight),A.appendChild(a),t.isOpen=true;}else a=document.createElement("div"),a.id="aicommerce-widget",a.className=`aicommerce-widget aicommerce-${c.position} aicommerce-theme-${c.theme}`,document.body.appendChild(a);$(),m||t.messages.push({role:"assistant",content:c.welcomeMessage}),t.isLoading=false,$();}async function L(p,m=1){let u=p;if(p.includes("gid://")){let E=p.match(/\/(\d+)$/);E&&(u=E[1]);}if(!(await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:u,quantity:m})})).ok)throw new Error("Failed to add to cart");document.dispatchEvent(new CustomEvent("cart:refresh")),document.dispatchEvent(new CustomEvent("cart:change")),document.dispatchEvent(new CustomEvent("cart:add")),document.dispatchEvent(new CustomEvent("cart:updated")),document.dispatchEvent(new CustomEvent("CartJS:change"));let y=window;y.Shopify&&y.Shopify.onCartUpdate&&y.Shopify.onCartUpdate(),fetch("/cart.js").then(E=>E.json()).then(E=>{document.dispatchEvent(new CustomEvent("cart:build",{detail:{cart:E}})),document.dispatchEvent(new CustomEvent("ajaxCart.afterCartLoad",{detail:{cart:E}}));let g=E.item_count;[".cart-count","#cart-count",".site-header__cart-count","[data-cart-count]",".cart-count-bubble",".header__cart-count",".header-cart__count"].forEach(P=>{document.querySelectorAll(P).forEach(d=>{d.textContent=g.toString(),d.classList.remove("hide","hidden");});});let M=document.getElementById("cart-icon-bubble");if(M){let P=M.querySelector(".cart-count-bubble");g>0?P?(P.innerHTML=`<span aria-hidden="true">${g}</span><span class="visually-hidden">${g} item</span>`,P.classList.remove("hidden","hide")):(P=document.createElement("div"),P.className="cart-count-bubble",P.innerHTML=`<span aria-hidden="true">${g}</span><span class="visually-hidden">${g} item</span>`,M.appendChild(P)):P&&P.classList.add("hidden");}}).catch(()=>{});}function T(p){let m=p;if(p.includes("gid://")){let u=p.match(/\/(\d+)$/);u&&(m=u[1]);}window.location.href=`/cart/${m}:1`;}function $(){if(!a)return;let p=c.displayMode==="embedded",m=t.messages.some(g=>g.role==="user");p&&(a.classList.remove("aicommerce-no-messages","aicommerce-has-messages"),a.classList.add(m?"aicommerce-has-messages":"aicommerce-no-messages"));let u=c.placeholder||"Ask me anything about our products...",A=`
859
1008
  <div class="aicommerce-input-container">
860
- ${o?`
1009
+ ${p?`
861
1010
  <textarea
862
1011
  class="aicommerce-input"
863
- placeholder="${c}"
1012
+ placeholder="${u}"
864
1013
  rows="1"
865
- ${e.isLoading||e.isRecording?"disabled":""}
1014
+ ${t.isLoading||t.isRecording?"disabled":""}
866
1015
  ></textarea>
867
1016
  `:`
868
1017
  <input
869
1018
  type="text"
870
1019
  class="aicommerce-input"
871
- placeholder="${c}"
872
- ${e.isLoading||e.isRecording?"disabled":""}
1020
+ placeholder="${u}"
1021
+ ${t.isLoading||t.isRecording?"disabled":""}
873
1022
  />
874
1023
  `}
875
- <button class="aicommerce-mic ${e.isRecording?"aicommerce-recording":""}" ${e.isLoading?"disabled":""} aria-label="${e.isRecording?"Stop recording":"Voice input"}">
876
- ${e.isRecording?`
1024
+ <button class="aicommerce-mic ${t.isRecording?"aicommerce-recording":""}" ${t.isLoading?"disabled":""} aria-label="${t.isRecording?"Stop recording":"Voice input"}">
1025
+ ${t.isRecording?`
877
1026
  <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
878
1027
  <rect x="6" y="6" width="12" height="12" rx="2"/>
879
1028
  </svg>
@@ -886,28 +1035,28 @@ var O=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object
886
1035
  </svg>
887
1036
  `}
888
1037
  </button>
889
- <button class="aicommerce-send" ${e.isLoading||e.isRecording?"disabled":""} aria-label="Send message">
1038
+ <button class="aicommerce-send" ${t.isLoading||t.isRecording?"disabled":""} aria-label="Send message">
890
1039
  <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
891
1040
  <path d="M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13"/>
892
1041
  </svg>
893
1042
  </button>
894
1043
  </div>
895
- `,u=`
896
- ${!o&&!m.hideLauncher?`
897
- <button class="aicommerce-launcher ${e.isOpen?"aicommerce-hidden":""}" aria-label="Open chat">
898
- <span class="aicommerce-launcher-icon">${m.buttonText}</span>
1044
+ `,y=`
1045
+ ${!p&&!c.hideLauncher?`
1046
+ <button class="aicommerce-launcher ${t.isOpen?"aicommerce-hidden":""}" aria-label="Open chat">
1047
+ <span class="aicommerce-launcher-icon">${c.buttonText}</span>
899
1048
  </button>
900
1049
  `:""}
901
1050
 
902
- <div class="aicommerce-chat ${e.isOpen?"aicommerce-open":"aicommerce-closed"}">
903
- ${o?"":`
1051
+ <div class="aicommerce-chat ${t.isOpen?"aicommerce-open":"aicommerce-closed"}">
1052
+ ${p?"":`
904
1053
  <div class="aicommerce-header">
905
1054
  <div class="aicommerce-header-info">
906
1055
  <div class="aicommerce-avatar">
907
- ${e.storeConfig?.logo?`<img src="${e.storeConfig.logo}" alt="${m.botName}" />`:"<span>\u{1F916}</span>"}
1056
+ ${t.storeConfig?.logo?`<img src="${t.storeConfig.logo}" alt="${c.botName}" />`:"<span>\u{1F916}</span>"}
908
1057
  </div>
909
1058
  <div class="aicommerce-header-text">
910
- <span class="aicommerce-bot-name">${m.botName}</span>
1059
+ <span class="aicommerce-bot-name">${c.botName}</span>
911
1060
  <span class="aicommerce-status">Online</span>
912
1061
  </div>
913
1062
  </div>
@@ -915,33 +1064,42 @@ var O=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object
915
1064
  </div>
916
1065
  `}
917
1066
 
918
- ${o&&i?`
1067
+ ${p&&m?`
919
1068
  <div class="aicommerce-messages">
920
- ${e.messages.map((l,S)=>{let A=J(l.content),n=l.role==="user";return `
921
- <div class="aicommerce-message aicommerce-${l.role}">
922
- <div class="aicommerce-message-content ${A?"aicommerce-rtl":"aicommerce-ltr"}">
923
- ${l.audioUrl?Y(l,S,n):T(l.content)}
1069
+ ${t.messages.map((g,W)=>{let M=X(g.content),P=g.role==="user";return `
1070
+ <div class="aicommerce-message aicommerce-${g.role}">
1071
+ <div class="aicommerce-message-content ${M?"aicommerce-rtl":"aicommerce-ltr"}">
1072
+ ${g.audioUrl?G(g,W,P):b.parse(g.content)}
924
1073
  </div>
925
- ${l.products&&l.products.length>0?`
1074
+ ${g.products&&g.products.length>0?`
926
1075
  <div class="aicommerce-products">
927
- ${l.products.map(t=>`
928
- <div class="aicommerce-product-card" data-product-id="${t.id}" data-variant-id="${t.variantId||""}">
929
- ${t.image||t.imageUrl?`
930
- <img src="${t.image||t.imageUrl}" alt="${T(t.name)}" class="aicommerce-product-image" />
1076
+ ${g.products.map(d=>`
1077
+ <div class="aicommerce-product-card" data-product-id="${d.id}" data-variant-id="${d.variantId||""}">
1078
+ ${d.image||d.imageUrl?`
1079
+ <img src="${d.image||d.imageUrl}" alt="${j(d.name)}" class="aicommerce-product-image" />
931
1080
  `:`
932
1081
  <div class="aicommerce-product-placeholder">\u{1F4E6}</div>
933
1082
  `}
934
1083
  <div class="aicommerce-product-info">
935
- <span class="aicommerce-product-name" title="${T(t.name)}">${T(t.name)}</span>
936
- ${t.description?`<p class="aicommerce-product-desc">${T(t.description)}</p>`:""}
937
- <span class="aicommerce-product-price">${X(t.price,t.currency)}</span>
938
- <button class="aicommerce-add-to-cart" data-product-id="${t.id}">
939
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
940
- <circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/>
941
- <path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/>
942
- </svg>
943
- ${m.addToCartText||"Add to Cart"}
944
- </button>
1084
+ <span class="aicommerce-product-name" title="${j(d.name)}">${j(d.name)}</span>
1085
+ ${d.description?`<p class="aicommerce-product-desc">${j(d.description)}</p>`:""}
1086
+ <span class="aicommerce-product-price">${_e(d.price,d.currency)}</span>
1087
+ <div class="aicommerce-product-actions">
1088
+ ${c.showAddToCart!==false?`
1089
+ <button class="aicommerce-add-to-cart" data-product-id="${d.id}">
1090
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1091
+ <circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/>
1092
+ <path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/>
1093
+ </svg>
1094
+ ${c.addToCartText||"Add to Cart"}
1095
+ </button>
1096
+ `:""}
1097
+ ${c.showBuyNow!==false?`
1098
+ <button class="aicommerce-buy-now" data-variant-id="${d.variantId||""}">
1099
+ Buy Now
1100
+ </button>
1101
+ `:""}
1102
+ </div>
945
1103
  </div>
946
1104
  </div>
947
1105
  `).join("")}
@@ -949,7 +1107,7 @@ var O=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object
949
1107
  `:""}
950
1108
  </div>
951
1109
  `}).join("")}
952
- ${e.isLoading?`
1110
+ ${t.isLoading?`
953
1111
  <div class="aicommerce-message aicommerce-assistant">
954
1112
  <div class="aicommerce-typing">
955
1113
  <span></span><span></span><span></span>
@@ -959,33 +1117,42 @@ var O=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object
959
1117
  </div>
960
1118
  `:""}
961
1119
 
962
- ${o?"":`
1120
+ ${p?"":`
963
1121
  <div class="aicommerce-messages">
964
- ${e.messages.map((l,S)=>{let A=J(l.content),n=l.role==="user";return `
965
- <div class="aicommerce-message aicommerce-${l.role}">
966
- <div class="aicommerce-message-content ${A?"aicommerce-rtl":"aicommerce-ltr"}">
967
- ${l.audioUrl?Y(l,S,n):T(l.content)}
1122
+ ${t.messages.map((g,W)=>{let M=X(g.content),P=g.role==="user";return `
1123
+ <div class="aicommerce-message aicommerce-${g.role}">
1124
+ <div class="aicommerce-message-content ${M?"aicommerce-rtl":"aicommerce-ltr"}">
1125
+ ${g.audioUrl?G(g,W,P):b.parse(g.content)}
968
1126
  </div>
969
- ${l.products&&l.products.length>0?`
1127
+ ${g.products&&g.products.length>0?`
970
1128
  <div class="aicommerce-products">
971
- ${l.products.map(t=>`
972
- <div class="aicommerce-product-card" data-product-id="${t.id}" data-variant-id="${t.variantId||""}">
973
- ${t.image||t.imageUrl?`
974
- <img src="${t.image||t.imageUrl}" alt="${T(t.name)}" class="aicommerce-product-image" />
1129
+ ${g.products.map(d=>`
1130
+ <div class="aicommerce-product-card" data-product-id="${d.id}" data-variant-id="${d.variantId||""}">
1131
+ ${d.image||d.imageUrl?`
1132
+ <img src="${d.image||d.imageUrl}" alt="${j(d.name)}" class="aicommerce-product-image" />
975
1133
  `:`
976
1134
  <div class="aicommerce-product-placeholder">\u{1F4E6}</div>
977
1135
  `}
978
1136
  <div class="aicommerce-product-info">
979
- <span class="aicommerce-product-name" title="${T(t.name)}">${T(t.name)}</span>
980
- ${t.description?`<p class="aicommerce-product-desc">${T(t.description)}</p>`:""}
981
- <span class="aicommerce-product-price">${X(t.price,t.currency)}</span>
982
- <button class="aicommerce-add-to-cart" data-product-id="${t.id}">
983
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
984
- <circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/>
985
- <path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/>
986
- </svg>
987
- ${m.addToCartText||"Add to Cart"}
988
- </button>
1137
+ <span class="aicommerce-product-name" title="${j(d.name)}">${j(d.name)}</span>
1138
+ ${d.description?`<p class="aicommerce-product-desc">${j(d.description)}</p>`:""}
1139
+ <span class="aicommerce-product-price">${_e(d.price,d.currency)}</span>
1140
+ <div class="aicommerce-product-actions">
1141
+ ${c.showAddToCart!==false?`
1142
+ <button class="aicommerce-add-to-cart" data-product-id="${d.id}">
1143
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1144
+ <circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/>
1145
+ <path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/>
1146
+ </svg>
1147
+ ${c.addToCartText||"Add to Cart"}
1148
+ </button>
1149
+ `:""}
1150
+ ${c.showBuyNow!==false?`
1151
+ <button class="aicommerce-buy-now" data-variant-id="${d.variantId||""}">
1152
+ Buy Now
1153
+ </button>
1154
+ `:""}
1155
+ </div>
989
1156
  </div>
990
1157
  </div>
991
1158
  `).join("")}
@@ -993,7 +1160,7 @@ var O=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object
993
1160
  `:""}
994
1161
  </div>
995
1162
  `}).join("")}
996
- ${e.isLoading?`
1163
+ ${t.isLoading?`
997
1164
  <div class="aicommerce-message aicommerce-assistant">
998
1165
  <div class="aicommerce-typing">
999
1166
  <span></span><span></span><span></span>
@@ -1003,39 +1170,39 @@ var O=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object
1003
1170
  </div>
1004
1171
  `}
1005
1172
 
1006
- ${o?`
1173
+ ${p?`
1007
1174
  <div class="aicommerce-input-wrapper">
1008
- ${b}
1175
+ ${A}
1009
1176
  </div>
1010
- `:b}
1177
+ `:A}
1011
1178
  </div>
1012
- `;s.innerHTML=u,oe();let E=s.querySelector(".aicommerce-messages");E&&(E.scrollTop=E.scrollHeight);}function Y(o,i,c){return `
1013
- <div class="aicommerce-audio-player" data-message-index="${i}">
1179
+ `;a.innerHTML=y,Q();let E=a.querySelector(".aicommerce-messages");E&&(E.scrollTop=E.scrollHeight);}function G(p,m,u){return `
1180
+ <div class="aicommerce-audio-player" data-message-index="${m}">
1014
1181
  <button class="aicommerce-audio-btn">
1015
1182
  <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>
1016
1183
  </button>
1017
1184
  <div class="aicommerce-audio-waveform">
1018
1185
  <div class="aicommerce-waveform-bars">
1019
- ${(o.waveformBars||Array(40).fill(10)).map(b=>`
1020
- <div class="aicommerce-waveform-bar" style="height: ${b}%; background-color: ${c?"rgba(255,255,255,0.4)":"rgba(99,102,241,0.3)"}"></div>
1186
+ ${(p.waveformBars||Array(40).fill(10)).map(A=>`
1187
+ <div class="aicommerce-waveform-bar" style="height: ${A}%; background-color: ${u?"rgba(255,255,255,0.4)":"rgba(99,102,241,0.3)"}"></div>
1021
1188
  `).join("")}
1022
1189
  </div>
1023
1190
  <div class="aicommerce-audio-time">
1024
1191
  <span class="aicommerce-current-time">0:00</span>
1025
- <span>${V(o.audioDuration||0)}</span>
1192
+ <span>${oe(p.audioDuration||0)}</span>
1026
1193
  </div>
1027
1194
  </div>
1028
- <audio src="${o.audioUrl}" preload="metadata"></audio>
1195
+ <audio src="${p.audioUrl}" preload="metadata"></audio>
1029
1196
  </div>
1030
- `}function oe(){if(!s)return;let o=s.querySelector(".aicommerce-launcher");o&&o.addEventListener("click",()=>q());let i=s.querySelector(".aicommerce-close");i&&i.addEventListener("click",()=>H());let c=s.querySelector(".aicommerce-input"),b=s.querySelector(".aicommerce-send");c&&(c.addEventListener("keydown",n=>{let t=n;if(t.key==="Enter"){let p=c instanceof HTMLTextAreaElement;if(p&&t.shiftKey)return;n.preventDefault();let f=c.value.trim();f&&(U(f),c.value="",p&&(c.style.height="auto"));}}),c instanceof HTMLTextAreaElement&&c.addEventListener("input",()=>{c.style.height="auto",c.style.height=Math.min(c.scrollHeight,150)+"px";})),b&&c&&b.addEventListener("click",()=>{let n=c.value.trim();n&&(U(n),c.value="",c instanceof HTMLTextAreaElement&&(c.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=`
1197
+ `}function Q(){if(!a)return;let p=a.querySelector(".aicommerce-launcher");p&&p.addEventListener("click",()=>fe());let m=a.querySelector(".aicommerce-close");m&&m.addEventListener("click",()=>be());let u=a.querySelector(".aicommerce-input"),A=a.querySelector(".aicommerce-send");u&&(u.addEventListener("keydown",d=>{let x=d;if(x.key==="Enter"){let C=u instanceof HTMLTextAreaElement;if(C&&x.shiftKey)return;d.preventDefault();let R=u.value.trim();R&&(O(R),u.value="",C&&(u.style.height="auto"));}}),u instanceof HTMLTextAreaElement&&u.addEventListener("input",()=>{u.style.height="auto",u.style.height=Math.min(u.scrollHeight,150)+"px";})),A&&u&&A.addEventListener("click",()=>{let d=u.value.trim();d&&(O(d),u.value="",u instanceof HTMLTextAreaElement&&(u.style.height="auto"));});let y=a.querySelector(".aicommerce-mic");y&&y.addEventListener("click",()=>ie()),a.querySelectorAll(".aicommerce-product-card").forEach(d=>{d.addEventListener("click",x=>{if(x.target.closest(".aicommerce-add-to-cart"))return;let C=d.getAttribute("data-product-id"),R=t.messages.flatMap(S=>S.products||[]).find(S=>S.id===C);R&&(c.onProductClick?c.onProductClick(R):R.url&&window.open(R.url,"_blank","noopener,noreferrer"));});}),a.querySelectorAll(".aicommerce-add-to-cart").forEach(d=>{d.addEventListener("click",async x=>{x.stopPropagation();let C=d,R=C.closest(".aicommerce-product-card"),S=R?.getAttribute("data-product-id"),q=R?.getAttribute("data-variant-id"),I=t.messages.flatMap(H=>H.products||[]).find(H=>H.id===S);if(!I)return;let B=C.innerHTML;C.disabled=true,C.innerHTML=`
1031
1198
  <svg class="aicommerce-spinner" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1032
1199
  <circle cx="12" cy="12" r="10" stroke-dasharray="32" stroke-dashoffset="32"/>
1033
1200
  </svg>
1034
1201
  Adding...
1035
- `;try{m.onAddToCart?await m.onAddToCart(C):x&&window.Shopify?await te(x):C.url&&window.open(C.url,"_blank","noopener,noreferrer"),p.innerHTML=`
1202
+ `;try{c.onAddToCart?await c.onAddToCart(I):q&&window.Shopify?await L(q):I.url&&window.open(I.url,"_blank","noopener,noreferrer"),C.innerHTML=`
1036
1203
  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1037
1204
  <polyline points="20 6 9 17 4 12"/>
1038
1205
  </svg>
1039
1206
  Added!
1040
- `,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 I=v.closest(".aicommerce-audio-player")?.querySelector(".aicommerce-audio-btn");I&&(I.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(),I=(C.clientX-v.left)/v.width;t.duration&&(t.currentTime=I*t.duration);});});}async function ae(){if(e.isRecording)d&&d.state!=="inactive"&&d.stop();else try{let o=await navigator.mediaDevices.getUserMedia({audio:!0});h=[],d=new MediaRecorder(o,{mimeType:MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4"}),d.ondataavailable=i=>{i.data.size>0&&h.push(i.data);},d.onstop=async()=>{if(o.getTracks().forEach(i=>i.stop()),h.length>0){let i=new Blob(h,{type:d?.mimeType||"audio/webm"});await ie(i);}e.isRecording=!1,k();},d.start(),e.isRecording=!0,k();}catch(o){console.error("Failed to start recording:",o),e.messages.push({role:"assistant",content:"Unable to access microphone. Please check your permissions."}),k();}}async function ie(o){let i=URL.createObjectURL(o),c=Array(40).fill(10),b=0;try{c=await se(o);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:c}),e.isLoading=true,k();try{let u=await r.chatWithAudio(o);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(o){return /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(o)}function V(o){let i=Math.floor(o/60),c=Math.floor(o%60);return `${i}:${c.toString().padStart(2,"0")}`}async function se(o){try{let i=new(window.AudioContext||window.webkitAudioContext),c=await o.arrayBuffer(),u=(await i.decodeAudioData(c)).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(o){e.messages.push({role:"user",content:o}),e.isLoading=true,k();try{let i=await r.chat(o);return e.messages.push({role:"assistant",content:i.reply,products:i.products}),m.onMessage&&m.onMessage(o,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 H(){e.isOpen=false,k(),m.onClose?.();}function ne(){e.isOpen?H():q();}function ce(){s&&(s.remove(),s=null),w&&(w.remove(),w=null);}function de(o){if(Object.assign(m,o),o.primaryColor){let i=z(m);w&&(w.textContent=i);}k();}function T(o){let i=document.createElement("div");return i.textContent=o,i.innerHTML}function X(o,i){let b={USD:"$",EUR:"\u20AC",GBP:"\xA3",MAD:"DH",SAR:"SAR",AED:"AED",JPY:"\xA5",CNY:"\xA5"}[i||"USD"]||i||"$";return `${o.toFixed(2)} ${b}`}return re(),{open:q,close:H,toggle:ne,destroy:ce,sendMessage:U,updateConfig:de}}exports.AICommerceWidget=void 0;var F=B(()=>{M();Q();exports.AICommerceWidget={init:D,VERSION:"1.0.0"};typeof window<"u"&&(window.AICommerceWidget=exports.AICommerceWidget);});M();F();var xe="1.0.0";typeof window<"u"&&(window.AICommerce=(M(),j(W)).AICommerce,window.AICommerceError=(M(),j(W)).AICommerceError,window.AICommerceWidget=(F(),j(Z)).AICommerceWidget);exports.VERSION=xe;exports.createWidget=D;return exports;})({});//# sourceMappingURL=index.min.js.map
1207
+ `,setTimeout(()=>{C.innerHTML=B,C.disabled=!1;},2e3);}catch(H){console.error("[AI Commerce] Add to cart failed:",H),C.innerHTML=B,C.disabled=false;}});}),a.querySelectorAll(".aicommerce-buy-now").forEach(d=>{d.addEventListener("click",async x=>{x.stopPropagation();let R=d.closest(".aicommerce-product-card")?.getAttribute("data-product-id"),S=d.getAttribute("data-variant-id"),q=t.messages.flatMap(I=>I.products||[]).find(I=>I.id===R);q&&c.onBuyNow?await c.onBuyNow(q):S&&T(S);});}),a.querySelectorAll(".aicommerce-products").forEach(d=>{let x=false,C=0,R=0;d.addEventListener("mousedown",S=>{x=true,d.style.cursor="grabbing",C=S.pageX-d.offsetLeft,R=d.scrollLeft;}),d.addEventListener("mouseleave",()=>{x=false,d.style.cursor="grab";}),d.addEventListener("mouseup",()=>{x=false,d.style.cursor="grab";}),d.addEventListener("mousemove",S=>{if(!x)return;S.preventDefault();let I=(S.pageX-d.offsetLeft-C)*2;d.scrollLeft=R-I;});}),a.querySelectorAll(".aicommerce-audio-player").forEach(d=>{let x=d.querySelector("audio"),C=d.querySelector(".aicommerce-audio-btn"),R=d.querySelectorAll(".aicommerce-waveform-bar"),S=d.querySelector(".aicommerce-current-time");if(!x||!C)return;C.addEventListener("click",()=>{!x.paused?(x.pause(),C.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(B=>{if(B!==x&&!B.paused){B.pause();let J=B.closest(".aicommerce-audio-player")?.querySelector(".aicommerce-audio-btn");J&&(J.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>');}}),x.play(),C.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>');}),x.addEventListener("timeupdate",()=>{if(S&&(S.textContent=oe(x.currentTime)),x.duration){let I=x.currentTime/x.duration*100;R.forEach((B,H)=>{H/R.length*100<=I?B.style.backgroundColor=d.closest(".aicommerce-user")?"rgba(255,255,255,1)":"var(--aic-primary)":B.style.backgroundColor=d.closest(".aicommerce-user")?"rgba(255,255,255,0.4)":"rgba(99,102,241,0.3)";});}}),x.addEventListener("ended",()=>{C.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 q=d.querySelector(".aicommerce-waveform-bars");q&&q.addEventListener("click",I=>{let B=q.getBoundingClientRect(),J=(I.clientX-B.left)/B.width;x.duration&&(x.currentTime=J*x.duration);});});}async function ie(){if(t.isRecording)i&&i.state!=="inactive"&&i.stop();else try{let p=await navigator.mediaDevices.getUserMedia({audio:!0});n=[];let m=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4";i=new MediaRecorder(p,{mimeType:m}),i.ondataavailable=u=>{u.data.size>0&&n.push(u.data);},i.onstop=async()=>{t.isRecording=!1,$(),p.getTracks().forEach(u=>u.stop());try{if(n.length>0){let u=new Blob(n,{type:m});await ae(u);}}catch(u){console.error("Failed to process audio:",u);}},i.start(),t.isRecording=!0,$();}catch(p){console.error("Failed to start recording:",p),t.messages.push({role:"assistant",content:"Unable to access microphone. Please check your permissions."}),$();}}async function ae(p){let m=URL.createObjectURL(p),u=0;try{let y=new Audio(m);await new Promise(E=>{y.onloadedmetadata=()=>{u=y.duration,E();},y.onerror=()=>E();});}catch(y){console.error("Audio duration check failed",y);}let A=Array(40).fill(10);try{A=await Y(p);}catch(y){console.error("Audio analysis failed",y);}t.messages.push({role:"user",content:"Voice message",audioUrl:m,audioDuration:u,waveformBars:A}),t.isLoading=true,$();try{let y=await e.chatWithAudio(p);return t.messages.push({role:"assistant",content:y.reply,products:y.products}),c.onMessage&&c.onMessage("Voice message",y),y}catch(y){throw t.messages.push({role:"assistant",content:"Sorry, I encountered an error processing your voice message. Please try again."}),y}finally{t.isLoading=false,$();}}function X(p){return /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(p)}function oe(p){let m=Math.floor(p/60),u=Math.floor(p%60);return `${m}:${u.toString().padStart(2,"0")}`}async function Y(p){try{let m=new(window.AudioContext||window.webkitAudioContext),u=await p.arrayBuffer(),y=(await m.decodeAudioData(u)).getChannelData(0),E=40,g=Math.floor(y.length/E),W=[];for(let M=0;M<E;M++){let P=M*g,d=P+g,x=0;for(let S=P;S<d;S++)y[S]&&(x+=y[S]*y[S]);let C=Math.sqrt(x/g),R=Math.min(100,Math.max(10,C*400));W.push(R);}return W}catch(m){return console.error("Analysis error",m),Array.from({length:40},()=>20+Math.random()*60)}}async function O(p){t.messages.push({role:"user",content:p}),t.isLoading=true,$();try{let m=await e.chat(p);return t.messages.push({role:"assistant",content:m.reply,products:m.products}),c.onMessage&&c.onMessage(p,m),m}catch(m){throw t.messages.push({role:"assistant",content:"Sorry, I encountered an error. Please try again."}),m}finally{t.isLoading=false,$();}}function fe(){t.isOpen=true,$(),c.onOpen?.(),setTimeout(()=>{a?.querySelector(".aicommerce-input")?.focus();},100);}function be(){t.isOpen=false,$(),c.onClose?.();}function at(){t.isOpen?be():fe();}function ot(){a&&(a.remove(),a=null),l&&(l.remove(),l=null);}function st(p){if(Object.assign(c,p),p.primaryColor){let m=ye(c);l&&(l.textContent=m);}$();}function j(p){let m=document.createElement("div");return m.textContent=p,m.innerHTML}function _e(p,m){let A={USD:"$",EUR:"\u20AC",GBP:"\xA3",MAD:"DH",SAR:"SAR",AED:"AED",JPY:"\xA5",CNY:"\xA5"}[m||"USD"]||m||"$";return `${p.toFixed(2)} ${A}`}return f(),{open:fe,close:be,toggle:at,destroy:ot,sendMessage:O,updateConfig:st}}exports.AICommerceWidget=void 0;var qe=ce(()=>{V();Ue();nt();b.setOptions({breaks:true,gfm:true});exports.AICommerceWidget={init:Be,VERSION:"1.0.0"};typeof window<"u"&&(window.AICommerceWidget=exports.AICommerceWidget);});V();qe();var gr="1.0.0";typeof window<"u"&&(window.AICommerce=(V(),xe(ke)).AICommerce,window.AICommerceError=(V(),xe(ke)).AICommerceError,window.AICommerceWidget=(qe(),xe(it)).AICommerceWidget);exports.VERSION=gr;exports.createWidget=Be;return exports;})({});//# sourceMappingURL=index.min.js.map
1041
1208
  //# sourceMappingURL=index.min.js.map