@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 AICommerceWidget=(function(exports){'use strict';/*! AI Commerce Widget v1.0.0 | MIT License | https://aicommerce.dev */
2
- var M=class i{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}`,y=new AbortController,s=setTimeout(()=>y.abort(),this.timeout);try{let g=await fetch(d,{...e,signal:y.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 A=await g.json().catch(()=>({})),w={code:A.code||"UNKNOWN_ERROR",message:A.message||A.error||`HTTP ${g.status}`,status:g.status};throw new S(w.message,w.code,w.status)}return g.json()}catch(g){throw clearTimeout(s),g instanceof S?g:g instanceof Error&&g.name==="AbortError"?new S("Request timeout","TIMEOUT",408):new S(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},y=await this.request("/api/v1/chat",{method:"POST",body:JSON.stringify(d)});return y.sessionToken&&(this.sessionToken=y.sessionToken),y}async chatWithAudio(r,e){let d=await r.arrayBuffer(),s={audioBase64:btoa(new Uint8Array(d).reduce((A,w)=>A+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 y=`${this.baseUrl}/api/v1/upload`,s=await fetch(y,{method:"POST",headers:{"X-API-Key":this.apiKey},body:d});if(!s.ok){let g=await s.json().catch(()=>({}));throw new S(g.message||g.error||`HTTP ${s.status}`,g.code||"UPLOAD_ERROR",s.status)}return s.json()}static async quickChat(r){return new i({apiKey:r.apiKey,baseUrl:r.baseUrl}).chat(r.message,r.context)}},S=class i extends Error{constructor(r,e,d){super(r),this.name="AICommerceError",this.code=e,this.status=d,Object.setPrototypeOf(this,i.prototype);}};function Z(i){let r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(i);return r?{r:parseInt(r[1],16),g:parseInt(r[2],16),b:parseInt(r[3],16)}:{r:99,g:102,b:241}}function H(i){let r=i.primaryColor,e=Z(r),d=i.position==="bottom-left";return `
2
+ var Xe=Object.defineProperty;var Ye=(r,e,t)=>e in r?Xe(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var w=(r,e,t)=>Ye(r,typeof e!="symbol"?e+"":e,t);var ae=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 F(l.message,l.code,l.status)}return o.json()}catch(o){throw clearTimeout(a),o instanceof F?o:o instanceof Error&&o.name==="AbortError"?new F("Request timeout","TIMEOUT",408):new F(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 F(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)}},F=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 Je(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 ge(r){let e=r.primaryColor,t=Je(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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
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: ${i.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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
855
892
  .aicommerce-spinner {
856
893
  animation: aicommerce-spin 1s linear infinite;
857
894
  }
858
- `}function W(i){let r=document.createElement("style");r.id="aicommerce-widget-styles",r.textContent=i;let e=document.getElementById("aicommerce-widget-styles");return e&&e.remove(),document.head.appendChild(r),r}function ee(i){if(!i.apiKey)throw new Error("AICommerceWidget: apiKey is required");let r=new M({apiKey:i.apiKey,storeId:i.storeId,baseUrl:i.baseUrl}),e={isOpen:false,isLoading:true,isRecording:false,messages:[],storeConfig:null},d=null,y=[],s=null,w=null,m;async function K(){try{let a=i.baseUrl||O(),o=await fetch(`${a}/api/v1/store`,{headers:{"x-api-key":i.apiKey}});return o.ok?(await o.json()).store:null}catch(a){return console.error("Failed to fetch store config:",a),null}}function O(){if(typeof window<"u"){let a=document.querySelector("script[data-aicommerce-url]");if(a)return a.getAttribute("data-aicommerce-url")||""}return "https://api.aicommerce.dev"}async function F(){e.storeConfig=await K();let a=i.displayMode||"widget",o=a==="embedded";m={apiKey:i.apiKey,storeId:i.storeId,baseUrl:i.baseUrl||O(),displayMode:a,container:i.container,maxHeight:i.maxHeight||"600px",placeholder:i.placeholder||"Ask me anything about our products...",position:i.position||"bottom-right",theme:i.theme||"auto",primaryColor:i.primaryColor||e.storeConfig?.primaryColor||"#6366f1",welcomeMessage:i.welcomeMessage||e.storeConfig?.welcomeMessage||"Hi! How can I help you find the perfect product today?",botName:i.botName||e.storeConfig?.chatBotName||"Shopping Assistant",zIndex:i.zIndex||9999,buttonText:i.buttonText||"\u{1F4AC}",hideLauncher:i.hideLauncher||false,addToCartText:i.addToCartText,onOpen:i.onOpen,onClose:i.onClose,onProductClick:i.onProductClick,onAddToCart:i.onAddToCart,onMessage:i.onMessage};let c=H(m);if(w=W(c),o){let h=null;if(typeof i.container=="string"?h=document.querySelector(i.container):i.container instanceof HTMLElement&&(h=i.container),!h){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),h.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(),o||e.messages.push({role:"assistant",content:m.welcomeMessage}),e.isLoading=false,k();}async function N(a,o=1){let c=a;if(a.includes("gid://")){let u=a.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:o})})).ok)throw new Error("Failed to add to cart");document.dispatchEvent(new CustomEvent("cart:refresh"));}function k(){if(!s)return;let a=m.displayMode==="embedded",o=e.messages.some(l=>l.role==="user");a&&(s.classList.remove("aicommerce-no-messages","aicommerce-has-messages"),s.classList.add(o?"aicommerce-has-messages":"aicommerce-no-messages"));let c=m.placeholder||"Ask me anything about our products...",h=`
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 Pe(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}function ye(){return {async:false,breaks:false,extensions:null,gfm:true,hooks:null,pedantic:false,renderer:null,silent:false,tokenizer:null,walkTokens:null}}var K=ye();function qe(r){K=r;}var ee={exec:()=>null};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}var 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")},Ve=/^(?:[ \t]*(?:\n|$))+/,et=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,tt=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,te=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,rt=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,we=/(?:[*+-]|\d{1,9}[.)])/,_e=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Oe=k(_e).replace(/bull/g,we).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(),nt=k(_e).replace(/bull/g,we).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(),ve=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,it=/^[^\n]+/,Te=/(?!\s*\])(?:\\.|[^\[\]\\])+/,at=k(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Te).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),ot=k(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,we).getRegex(),pe="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",$e=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,st=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",$e).replace("tag",pe).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),He=k(ve).replace("hr",te).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",pe).getRegex(),ct=k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",He).getRegex(),Ce={blockquote:ct,code:et,def:at,fences:tt,heading:rt,hr:te,html:st,lheading:Oe,list:ot,newline:Ve,paragraph:He,table:ee,text:it},Le=k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",te).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",pe).getRegex(),lt={...Ce,lheading:nt,table:Le,paragraph:k(ve).replace("hr",te).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Le).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",pe).getRegex()},dt={...Ce,html:k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",$e).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:ee,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:k(ve).replace("hr",te).replace("heading",` *#{1,6} *[^
953
+ ]`).replace("lheading",Oe).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},pt=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,ut=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Ue=/^( {2,}|\\)\n(?!\s*$)/,mt=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,ue=/[\p{P}\p{S}]/u,Se=/[\s\p{P}\p{S}]/u,Ne=/[^\s\p{P}\p{S}]/u,ht=k(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Se).getRegex(),De=/(?!~)[\p{P}\p{S}]/u,gt=/(?!~)[\s\p{P}\p{S}]/u,ft=/(?:[^\s\p{P}\p{S}]|~)/u,bt=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,je=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,xt=k(je,"u").replace(/punct/g,ue).getRegex(),kt=k(je,"u").replace(/punct/g,De).getRegex(),Fe="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",yt=k(Fe,"gu").replace(/notPunctSpace/g,Ne).replace(/punctSpace/g,Se).replace(/punct/g,ue).getRegex(),wt=k(Fe,"gu").replace(/notPunctSpace/g,ft).replace(/punctSpace/g,gt).replace(/punct/g,De).getRegex(),vt=k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Ne).replace(/punctSpace/g,Se).replace(/punct/g,ue).getRegex(),Tt=k(/\\(punct)/,"gu").replace(/punct/g,ue).getRegex(),$t=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(),Ct=k($e).replace("(?:-->|$)","-->").getRegex(),St=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",Ct).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),ce=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Rt=k(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",ce).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),We=k(/^!?\[(label)\]\[(ref)\]/).replace("label",ce).replace("ref",Te).getRegex(),Ke=k(/^!?\[(ref)\](?:\[\])?/).replace("ref",Te).getRegex(),At=k("reflink|nolink(?!\\()","g").replace("reflink",We).replace("nolink",Ke).getRegex(),Re={_backpedal:ee,anyPunctuation:Tt,autolink:$t,blockSkip:bt,br:Ue,code:ut,del:ee,emStrongLDelim:xt,emStrongRDelimAst:yt,emStrongRDelimUnd:vt,escape:pt,link:Rt,nolink:Ke,punctuation:ht,reflink:We,reflinkSearch:At,tag:St,text:mt,url:ee},Et={...Re,link:k(/^!?\[(label)\]\((.*?)\)/).replace("label",ce).getRegex(),reflink:k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ce).getRegex()},be={...Re,emStrongRDelimAst:wt,emStrongLDelim:kt,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.!#$%&'*+\/=?_`{\|}~-]+@)))/},Pt={...be,br:k(Ue).replace("{2,}","*").getRegex(),text:k(be.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},oe={normal:Ce,gfm:lt,pedantic:dt},J={normal:Re,gfm:be,breaks:Pt,pedantic:Et},Lt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Ie=r=>Lt[r];function _(r,e){if(e){if(z.escapeTest.test(r))return r.replace(z.escapeReplace,Ie)}else if(z.escapeTestNoEncode.test(r))return r.replace(z.escapeReplaceNoEncode,Ie);return r}function ze(r){try{r=encodeURI(r).replace(z.percentDecode,"%");}catch{return null}return r}function Be(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 V(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 It(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 Me(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 zt(r,e,t){let i=r.match(t.other.indentCodeCompensation);if(i===null)return e;let n=i[1];return e.split(`
954
+ `).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(`
955
+ `)}var le=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:V(t,`
956
+ `)}}}fences(r){let e=this.rules.block.fences.exec(r);if(e){let t=e[0],i=zt(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=V(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:V(e[0],`
957
+ `)}}blockquote(r){let e=this.rules.block.blockquote.exec(r);if(e){let t=V(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
+ `),C=this.blockquote(T);a[a.length-1]=C,i=i.substring(0,i.length-L.raw.length)+C.raw,n=n.substring(0,n.length-L.text.length)+C.text;break}else if(f?.type==="list"){let L=f,T=L.raw+`
966
+ `+t.join(`
967
+ `),C=this.list(T);a[a.length-1]=C,i=i.substring(0,i.length-f.raw.length)+C.raw,n=n.substring(0,n.length-L.raw.length)+C.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,G=>" ".repeat(3*G.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 G=this.rules.other.nextBulletRegex(T),re=this.rules.other.hrRegex(T),ne=this.rules.other.fencesBeginRegex(T),Q=this.rules.other.headingBeginRegex(T),ie=this.rules.other.htmlBeginRegex(T);for(;r;){let X=r.split(`
972
+ `,1)[0],O;if(f=X,this.options.pedantic?(f=f.replace(this.rules.other.listReplaceNesting," "),O=f):O=f.replace(this.rules.other.tabCharGlobal," "),ne.test(f)||Q.test(f)||ie.test(f)||G.test(f)||re.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||ne.test(v)||Q.test(v)||re.test(v))break;h+=`
974
+ `+f;}!L&&!f.trim()&&(L=true),c+=X+`
975
+ `,r=r.substring(X.length+1),v=O.slice(T);}}n.loose||(o?n.loose=true:this.rules.other.doubleBlankLine.test(c)&&(o=true));let C=null,Z;this.options.gfm&&(C=this.rules.other.listIsTask.exec(h),C&&(Z=C[0]!=="[ ] ",h=h.replace(this.rules.other.listReplaceTask,""))),n.items.push({type:"list_item",raw:c,task:!!C,checked:Z,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=Be(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(Be(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=V(t.slice(0,-1),"\\");if((t.length-a.length)%2===0)return}else {let a=It(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)),Me(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 Me(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}}}},U=class xe{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 le,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:oe.normal,inline:J.normal};this.options.pedantic?(t.block=oe.pedantic,t.inline=J.pedantic):this.options.gfm&&(t.block=oe.gfm,this.options.breaks?t.inline=J.breaks:t.inline=J.gfm),this.tokenizer.rules=t;}static get rules(){return {block:oe,inline:J}}static lex(e,t){return new xe(t).lex(e)}static lexInline(e,t){return new xe(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}},de=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=ze(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=ze(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)}},Ae=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 ""}},N=class ke{constructor(e){w(this,"options");w(this,"renderer");w(this,"textRenderer");this.options=e||K,this.options.renderer=this.options.renderer||new de,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Ae;}static parse(e,t){return new ke(t).parse(e)}static parseInline(e,t){return new ke(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}},fe,se=(fe=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?U.lex:U.lexInline}provideParser(){return this.block?N.parse:N.parseInline}},w(fe,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"])),fe),Bt=class{constructor(...r){w(this,"defaults",ye());w(this,"options",this.setOptions);w(this,"parse",this.parseMarkdown(true));w(this,"parseInline",this.parseMarkdown(false));w(this,"Parser",N);w(this,"Renderer",de);w(this,"TextRenderer",Ae);w(this,"Lexer",U);w(this,"Tokenizer",le);w(this,"Hooks",se);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 de(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 le(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 se;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];se.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 U.lex(r,e??this.defaults)}parser(r,e){return N.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?U.lex:U.lexInline,l=a.hooks?a.hooks.provideParser():r?N.parse:N.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}}},W=new Bt;function b(r,e){return W.parse(r,e)}b.options=b.setOptions=function(r){return W.setOptions(r),b.defaults=W.defaults,qe(b.defaults),b};b.getDefaults=ye;b.defaults=K;b.use=function(...r){return W.use(...r),b.defaults=W.defaults,qe(b.defaults),b};b.walkTokens=function(r,e){return W.walkTokens(r,e)};b.parseInline=W.parseInline;b.Parser=N;b.parser=N.parse;b.Renderer=de;b.TextRenderer=Ae;b.Lexer=U;b.lexer=U.lex;b.Tokenizer=le;b.Hooks=se;b.parse=b;b.options;b.setOptions;b.use;b.walkTokens;b.parseInline;N.parse;U.lex;b.setOptions({breaks:true,gfm:true});function Mt(r){if(!r.apiKey)throw new Error("AICommerceWidget: apiKey is required");let e=new ae({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=ge(c);if(l=Pe(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);C(),m||t.messages.push({role:"assistant",content:c.welcomeMessage}),t.isLoading=false,C();}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 C(){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
- ${a?`
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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
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
- ${!a&&!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
- ${a?"":`
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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
915
1064
  </div>
916
1065
  `}
917
1066
 
918
- ${a&&o?`
1067
+ ${p&&m?`
919
1068
  <div class="aicommerce-messages">
920
- ${e.messages.map((l,L)=>{let P=j(l.content),n=l.role==="user";return `
921
- <div class="aicommerce-message aicommerce-${l.role}">
922
- <div class="aicommerce-message-content ${P?"aicommerce-rtl":"aicommerce-ltr"}">
923
- ${l.audioUrl?B(l,L,n):T(l.content)}
1069
+ ${t.messages.map((g,j)=>{let M=Q(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?Z(g,j,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="${D(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">${D(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="${D(d.name)}">${D(d.name)}</span>
1085
+ ${d.description?`<p class="aicommerce-product-desc">${D(d.description)}</p>`:""}
1086
+ <span class="aicommerce-product-price">${Ee(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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
959
1117
  </div>
960
1118
  `:""}
961
1119
 
962
- ${a?"":`
1120
+ ${p?"":`
963
1121
  <div class="aicommerce-messages">
964
- ${e.messages.map((l,L)=>{let P=j(l.content),n=l.role==="user";return `
965
- <div class="aicommerce-message aicommerce-${l.role}">
966
- <div class="aicommerce-message-content ${P?"aicommerce-rtl":"aicommerce-ltr"}">
967
- ${l.audioUrl?B(l,L,n):T(l.content)}
1122
+ ${t.messages.map((g,j)=>{let M=Q(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?Z(g,j,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="${D(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">${D(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="${D(d.name)}">${D(d.name)}</span>
1138
+ ${d.description?`<p class="aicommerce-product-desc">${D(d.description)}</p>`:""}
1139
+ <span class="aicommerce-product-price">${Ee(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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
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 M=class i{constructor(r){this.sessionToken=null;this.products={create:async
1003
1170
  </div>
1004
1171
  `}
1005
1172
 
1006
- ${a?`
1173
+ ${p?`
1007
1174
  <div class="aicommerce-input-wrapper">
1008
- ${h}
1175
+ ${A}
1009
1176
  </div>
1010
- `:h}
1177
+ `:A}
1011
1178
  </div>
1012
- `;s.innerHTML=u,Y();let $=s.querySelector(".aicommerce-messages");$&&($.scrollTop=$.scrollHeight);}function B(a,o,c){return `
1013
- <div class="aicommerce-audio-player" data-message-index="${o}">
1179
+ `;a.innerHTML=y,G();let E=a.querySelector(".aicommerce-messages");E&&(E.scrollTop=E.scrollHeight);}function Z(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
- ${(a.waveformBars||Array(40).fill(10)).map(h=>`
1020
- <div class="aicommerce-waveform-bar" style="height: ${h}%; 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>${z(a.audioDuration||0)}</span>
1192
+ <span>${ie(p.audioDuration||0)}</span>
1026
1193
  </div>
1027
1194
  </div>
1028
- <audio src="${a.audioUrl}" preload="metadata"></audio>
1195
+ <audio src="${p.audioUrl}" preload="metadata"></audio>
1029
1196
  </div>
1030
- `}function Y(){if(!s)return;let a=s.querySelector(".aicommerce-launcher");a&&a.addEventListener("click",()=>U());let o=s.querySelector(".aicommerce-close");o&&o.addEventListener("click",()=>q());let c=s.querySelector(".aicommerce-input"),h=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 b=c.value.trim();b&&(I(b),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";})),h&&c&&h.addEventListener("click",()=>{let n=c.value.trim();n&&(I(n),c.value="",c instanceof HTMLTextAreaElement&&(c.style.height="auto"));});let u=s.querySelector(".aicommerce-mic");u&&u.addEventListener("click",()=>J()),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"),b=e.messages.flatMap(f=>f.products||[]).find(f=>f.id===p);b&&(m.onProductClick?m.onProductClick(b):b.url&&window.open(b.url,"_blank","noopener,noreferrer"));});}),s.querySelectorAll(".aicommerce-add-to-cart").forEach(n=>{n.addEventListener("click",async t=>{t.stopPropagation();let p=n,b=p.closest(".aicommerce-product-card"),f=b?.getAttribute("data-product-id"),x=b?.getAttribute("data-variant-id"),C=e.messages.flatMap(E=>E.products||[]).find(E=>E.id===f);if(!C)return;let v=p.innerHTML;p.disabled=true,p.innerHTML=`
1197
+ `}function G(){if(!a)return;let p=a.querySelector(".aicommerce-launcher");p&&p.addEventListener("click",()=>me());let m=a.querySelector(".aicommerce-close");m&&m.addEventListener("click",()=>he());let u=a.querySelector(".aicommerce-input"),A=a.querySelector(".aicommerce-send");u&&(u.addEventListener("keydown",d=>{let x=d;if(x.key==="Enter"){let $=u instanceof HTMLTextAreaElement;if($&&x.shiftKey)return;d.preventDefault();let R=u.value.trim();R&&(O(R),u.value="",$&&(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",()=>re()),a.querySelectorAll(".aicommerce-product-card").forEach(d=>{d.addEventListener("click",x=>{if(x.target.closest(".aicommerce-add-to-cart"))return;let $=d.getAttribute("data-product-id"),R=t.messages.flatMap(S=>S.products||[]).find(S=>S.id===$);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 $=d,R=$.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=$.innerHTML;$.disabled=true,$.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 N(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"),$.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(E){console.error("[AI Commerce] Add to cart failed:",E),p.innerHTML=v,p.disabled=false;}});}),s.querySelectorAll(".aicommerce-products").forEach(n=>{let t=false,p=0,b=0;n.addEventListener("mousedown",f=>{t=true,n.style.cursor="grabbing",p=f.pageX-n.offsetLeft,b=n.scrollLeft;}),n.addEventListener("mouseleave",()=>{t=false,n.style.cursor="grab";}),n.addEventListener("mouseup",()=>{t=false,n.style.cursor="grab";}),n.addEventListener("mousemove",f=>{if(!t)return;f.preventDefault();let C=(f.pageX-n.offsetLeft-p)*2;n.scrollLeft=b-C;});}),s.querySelectorAll(".aicommerce-audio-player").forEach(n=>{let t=n.querySelector("audio"),p=n.querySelector(".aicommerce-audio-btn"),b=n.querySelectorAll(".aicommerce-waveform-bar"),f=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 R=v.closest(".aicommerce-audio-player")?.querySelector(".aicommerce-audio-btn");R&&(R.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(f&&(f.textContent=z(t.currentTime)),t.duration){let C=t.currentTime/t.duration*100;b.forEach((v,E)=>{E/b.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(),R=(C.clientX-v.left)/v.width;t.duration&&(t.currentTime=R*t.duration);});});}async function J(){if(e.isRecording)d&&d.state!=="inactive"&&d.stop();else try{let a=await navigator.mediaDevices.getUserMedia({audio:!0});y=[],d=new MediaRecorder(a,{mimeType:MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4"}),d.ondataavailable=o=>{o.data.size>0&&y.push(o.data);},d.onstop=async()=>{if(a.getTracks().forEach(o=>o.stop()),y.length>0){let o=new Blob(y,{type:d?.mimeType||"audio/webm"});await V(o);}e.isRecording=!1,k();},d.start(),e.isRecording=!0,k();}catch(a){console.error("Failed to start recording:",a),e.messages.push({role:"assistant",content:"Unable to access microphone. Please check your permissions."}),k();}}async function V(a){let o=URL.createObjectURL(a),c=Array(40).fill(10),h=0;try{c=await X(a);let u=new Audio(o);await new Promise($=>{u.onloadedmetadata=()=>{h=u.duration,$();},u.onerror=()=>$();});}catch(u){console.error("Audio analysis failed",u);}e.messages.push({role:"user",content:"Voice message",audioUrl:o,audioDuration:h,waveformBars:c}),e.isLoading=true,k();try{let u=await r.chatWithAudio(a);return e.messages.push({role:"assistant",content:u.reply,products:u.products}),m.onMessage&&m.onMessage("Voice message",u),u}catch(u){throw e.messages.push({role:"assistant",content:"Sorry, I encountered an error processing your voice message. Please try again."}),u}finally{e.isLoading=false,k();}}function j(a){return /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(a)}function z(a){let o=Math.floor(a/60),c=Math.floor(a%60);return `${o}:${c.toString().padStart(2,"0")}`}async function X(a){try{let o=new(window.AudioContext||window.webkitAudioContext),c=await a.arrayBuffer(),u=(await o.decodeAudioData(c)).getChannelData(0),$=40,l=Math.floor(u.length/$),L=[];for(let P=0;P<$;P++){let n=P*l,t=n+l,p=0;for(let x=n;x<t;x++)u[x]&&(p+=u[x]*u[x]);let b=Math.sqrt(p/l),f=Math.min(100,Math.max(10,b*400));L.push(f);}return L}catch(o){return console.error("Analysis error",o),Array.from({length:40},()=>20+Math.random()*60)}}async function I(a){e.messages.push({role:"user",content:a}),e.isLoading=true,k();try{let o=await r.chat(a);return e.messages.push({role:"assistant",content:o.reply,products:o.products}),m.onMessage&&m.onMessage(a,o),o}catch(o){throw e.messages.push({role:"assistant",content:"Sorry, I encountered an error. Please try again."}),o}finally{e.isLoading=false,k();}}function U(){e.isOpen=true,k(),m.onOpen?.(),setTimeout(()=>{s?.querySelector(".aicommerce-input")?.focus();},100);}function q(){e.isOpen=false,k(),m.onClose?.();}function G(){e.isOpen?q():U();}function _(){s&&(s.remove(),s=null),w&&(w.remove(),w=null);}function Q(a){if(Object.assign(m,a),a.primaryColor){let o=H(m);w&&(w.textContent=o);}k();}function T(a){let o=document.createElement("div");return o.textContent=a,o.innerHTML}function D(a,o){let h={USD:"$",EUR:"\u20AC",GBP:"\xA3",MAD:"DH",SAR:"SAR",AED:"AED",JPY:"\xA5",CNY:"\xA5"}[o||"USD"]||o||"$";return `${a.toFixed(2)} ${h}`}return F(),{open:U,close:q,toggle:G,destroy:_,sendMessage:I,updateConfig:Q}}var re={init:ee,VERSION:"1.0.0"};typeof window<"u"&&(window.AICommerceWidget=re);exports.AICommerceWidget=re;exports.createWidget=ee;return exports;})({});//# sourceMappingURL=widget.min.js.map
1207
+ `,setTimeout(()=>{$.innerHTML=B,$.disabled=!1;},2e3);}catch(H){console.error("[AI Commerce] Add to cart failed:",H),$.innerHTML=B,$.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,$=0,R=0;d.addEventListener("mousedown",S=>{x=true,d.style.cursor="grabbing",$=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-$)*2;d.scrollLeft=R-I;});}),a.querySelectorAll(".aicommerce-audio-player").forEach(d=>{let x=d.querySelector("audio"),$=d.querySelector(".aicommerce-audio-btn"),R=d.querySelectorAll(".aicommerce-waveform-bar"),S=d.querySelector(".aicommerce-current-time");if(!x||!$)return;$.addEventListener("click",()=>{!x.paused?(x.pause(),$.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 Y=B.closest(".aicommerce-audio-player")?.querySelector(".aicommerce-audio-btn");Y&&(Y.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(),$.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=ie(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",()=>{$.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(),Y=(I.clientX-B.left)/B.width;x.duration&&(x.currentTime=Y*x.duration);});});}async function re(){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,C(),p.getTracks().forEach(u=>u.stop());try{if(n.length>0){let u=new Blob(n,{type:m});await ne(u);}}catch(u){console.error("Failed to process audio:",u);}},i.start(),t.isRecording=!0,C();}catch(p){console.error("Failed to start recording:",p),t.messages.push({role:"assistant",content:"Unable to access microphone. Please check your permissions."}),C();}}async function ne(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 X(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,C();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,C();}}function Q(p){return /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(p)}function ie(p){let m=Math.floor(p/60),u=Math.floor(p%60);return `${m}:${u.toString().padStart(2,"0")}`}async function X(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),j=[];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 $=Math.sqrt(x/g),R=Math.min(100,Math.max(10,$*400));j.push(R);}return j}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,C();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,C();}}function me(){t.isOpen=true,C(),c.onOpen?.(),setTimeout(()=>{a?.querySelector(".aicommerce-input")?.focus();},100);}function he(){t.isOpen=false,C(),c.onClose?.();}function Ze(){t.isOpen?he():me();}function Ge(){a&&(a.remove(),a=null),l&&(l.remove(),l=null);}function Qe(p){if(Object.assign(c,p),p.primaryColor){let m=ge(c);l&&(l.textContent=m);}C();}function D(p){let m=document.createElement("div");return m.textContent=p,m.innerHTML}function Ee(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:me,close:he,toggle:Ze,destroy:Ge,sendMessage:O,updateConfig:Qe}}var qt={init:Mt,VERSION:"1.0.0"};typeof window<"u"&&(window.AICommerceWidget=qt);exports.AICommerceWidget=qt;exports.createWidget=Mt;return exports;})({});//# sourceMappingURL=widget.min.js.map
1041
1208
  //# sourceMappingURL=widget.min.js.map