From 0007704f3c6e08ec9e72a8361ecad2ac1461a690 Mon Sep 17 00:00:00 2001 From: Akiva Berger Date: Wed, 14 Jan 2026 22:35:25 +0200 Subject: [PATCH 01/21] feat: event to load webpages in memory --- static/js/ReaderApp.jsx | 175 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) diff --git a/static/js/ReaderApp.jsx b/static/js/ReaderApp.jsx index ad3d69e102..d27652010d 100644 --- a/static/js/ReaderApp.jsx +++ b/static/js/ReaderApp.jsx @@ -209,6 +209,7 @@ class ReaderApp extends Component { // (because its set to capture, or the event going down the dom stage, and the listener is the document element- it should fire before other handlers. Specifically // handleInAppLinkClick that disables modifier keys such as cmd, alt, shift) document.addEventListener('click', this.handleInAppClickWithModifiers, {capture: true}); + document.addEventListener('sefaria:bootstrap-url', this.handleBootstrapUrlEvent); // Save all initial panels to recently viewed this.state.panels.map(this.saveLastPlace); if (Sefaria._uid) { @@ -238,6 +239,7 @@ class ReaderApp extends Component { window.removeEventListener("resize", this.setPanelCap); window.removeEventListener("beforeprint", this.handlePrint); document.removeEventListener('copy', this.handleCopyEvent); + document.removeEventListener('sefaria:bootstrap-url', this.handleBootstrapUrlEvent); } componentDidUpdate(prevProps, prevState) { $(".content").off("scroll.scrollPosition").on("scroll.scrollPosition", this.setScrollPositionInHistory); // when .content may have rerendered @@ -1133,6 +1135,179 @@ toggleSignUpModal(modalContentKind = SignUpModalKind.Default) { e.preventDefault(); } } + handleBootstrapUrlEvent(event) { + if (!event || !event.detail) { return; } + const detail = event.detail; + const url = (typeof detail === "string") ? detail : detail.url; + if (!url) { return; } + const replaceHistory = (typeof detail === "object") ? detail.replaceHistory : false; + this.bootstrapUrl(url, {replaceHistory: replaceHistory}); + } + bootstrapUrl(href, options) { + if (this.shouldAlertBeforeCloseEditor()) { + if (!this.alertUnsavedChangesConfirmed()) { + return true; + } + } + let url; + try { + url = new URL(href, window.location.href); + } catch { + return false; + } + const hostname = url.hostname || ""; + if (hostname && hostname !== window.location.hostname && hostname.indexOf("sefaria.org") === -1) { + return false; + } + const path = decodeURI(url.pathname); + const params = url.searchParams; + const ref = path.slice(1).replace(/%3F/g, '?'); + if (Sefaria.isRef(ref)) { + return this.bootstrapTextUrl(ref, params, options); + } + return this.openURL(path + url.search, true); + } + bootstrapTextUrl(ref, params, options) { + const opts = options || {}; + const lang = this._normalizePanelLanguage(params.get("lang"), true); + const withParam = params.get("with"); + const filter = this._parseWithParam(withParam); + const hasConnections = withParam !== null; + const {connectionsMode, connectionsCategory, webPagesFilter, filter: normalizedFilter} = + this._getConnectionsModeFromFilter(filter || []); + + const currVersions = { + en: this._parseVersionParam(params.get("ven")), + he: this._parseVersionParam(params.get("vhe")), + }; + const versionFilterParam = params.get("vside"); + const versionFilter = versionFilterParam ? [Sefaria.util.decodeVtitle(versionFilterParam)] : []; + + let settings = lang ? {language: lang} : null; + const aliyotParam = params.get("aliyot"); + if (aliyotParam !== null) { + settings = settings || {}; + settings.aliyotTorah = (parseInt(aliyotParam, 10) === 1) ? "aliyotOn" : "aliyotOff"; + } + settings = this._mergePanelSettings(settings); + + const humanRef = Sefaria.humanRef(ref); + const highlightedRefs = hasConnections ? [Sefaria.normRef(ref)] : []; + const showHighlight = hasConnections; + const basePanelProps = { + mode: (!this.props.multiPanel && hasConnections) ? "TextAndConnections" : "Text", + refs: [humanRef], + currVersions: currVersions, + filter: normalizedFilter || [], + recentFilters: normalizedFilter || [], + connectionsMode: connectionsMode || null, + connectionsCategory: connectionsCategory, + webPagesFilter: webPagesFilter, + versionFilter: versionFilter, + highlightedRefs: highlightedRefs, + showHighlight: showHighlight, + settings: settings, + selectedWords: params.get("lookup"), + sidebarSearchQuery: params.get("sbsq"), + selectedNamedEntity: params.get("namedEntity"), + selectedNamedEntityText: params.get("namedEntityText"), + }; + const basePanel = this.makePanelState(basePanelProps); + basePanel.currentlyVisibleRef = humanRef; + + const panels = [basePanel]; + if (hasConnections && this.props.multiPanel) { + const connectionsLang = this._getConnectionsPanelLanguage(params.get("lang2"), lang); + const connectionsSettings = this._mergePanelSettings({language: connectionsLang}); + const connectionsPanelProps = { + ...basePanelProps, + mode: "Connections", + settings: connectionsSettings, + connectionsMode: connectionsMode || (filter && filter.length ? "TextList" : null), + }; + const connectionsPanel = this.makePanelState(connectionsPanelProps); + panels.push(connectionsPanel); + } + + if (opts.replaceHistory) { + this.replaceHistory = true; + } + this.setState({panels: panels}); + if (opts.saveLastPlace !== false) { + this.saveLastPlace(basePanel, 1, hasConnections && this.props.multiPanel); + } + return true; + } + _normalizePanelLanguage(langParam, allowBilingual) { + if (!langParam) { return null; } + const normalized = langParam.toLowerCase(); + if (normalized === "bi" || normalized === "bilingual") { + return allowBilingual ? "bilingual" : null; + } else if (normalized === "en" || normalized === "english") { + return "english"; + } else if (normalized === "he" || normalized === "hebrew") { + return "hebrew"; + } + return null; + } + _getConnectionsPanelLanguage(lang2Param, baseLang) { + const lang2 = this._normalizePanelLanguage(lang2Param, false); + if (lang2) { return lang2; } + if (baseLang === "english" || baseLang === "hebrew") { return baseLang; } + return (Sefaria.interfaceLang === "hebrew") ? "hebrew" : "english"; + } + _parseWithParam(param) { + if (param === null || typeof param === "undefined") { return null; } + const normalized = param.replace(/_/g, " "); + let filter = normalized.split("+").map(x => x.trim()).filter(Boolean); + if (filter.length === 1 && filter[0] === "all") { + filter = []; + } + return filter; + } + _parseVersionParam(param) { + if (!param) { return null; } + const parts = param.split("|"); + return { + languageFamilyName: parts[0] || null, + versionTitle: parts[1] ? Sefaria.util.decodeVtitle(parts[1]) : null, + }; + } + _getConnectionsModeFromFilter(filter) { + if (!filter || !filter.length) { + return {connectionsMode: null, connectionsCategory: null, webPagesFilter: null, filter: filter}; + } + const sidebarModes = [ + "Sheets", "Notes", "About", "AboutSheet", "Navigation", "Translations", "Translation Open", "Version Open", + "WebPages", "extended notes", "Topics", "Torah Readings", "manuscripts", "Lexicon", "SidebarSearch", "Guide", + ]; + const first = filter[0]; + if (sidebarModes.includes(first)) { + return {connectionsMode: first, connectionsCategory: null, webPagesFilter: null, filter: []}; + } + if (first.endsWith(" ConnectionsList")) { + const cleaned = filter.map(x => x.replace(" ConnectionsList", "")); + return { + connectionsMode: "ConnectionsList", + connectionsCategory: cleaned.length === 1 ? cleaned[0] : null, + webPagesFilter: null, + filter: cleaned, + }; + } + if (first.startsWith("WebPage:")) { + return { + connectionsMode: "WebPagesList", + connectionsCategory: null, + webPagesFilter: first.replace("WebPage:", ""), + filter: filter, + }; + } + return {connectionsMode: "TextList", connectionsCategory: null, webPagesFilter: null, filter: filter}; + } + _mergePanelSettings(settings) { + if (!settings) { return null; } + return extend(Sefaria.util.clone(this.getDefaultPanelSettings()), settings); + } openURL(href, replace=true, overrideContentLang=false) { if (this.shouldAlertBeforeCloseEditor()) { if (!this.alertUnsavedChangesConfirmed()) { From 2da72718888c862175ccdbe590c33f7838c0eb64 Mon Sep 17 00:00:00 2001 From: Akiva Berger Date: Wed, 21 Jan 2026 10:14:54 +0200 Subject: [PATCH 02/21] feat: add user_id secret handler --- .../configmap/local-settings-file.yaml | 1 + requirements.txt | 1 + sefaria/local_settings_example.py | 1 + sefaria/settings.py | 2 + sefaria/system/context_processors.py | 11 ++ sefaria/utils/chatbot.py | 37 ++++++ static/js/chat/lc-chatbot.umd.cjs | 112 ++++++++++++++++++ 7 files changed, 165 insertions(+) create mode 100644 sefaria/utils/chatbot.py create mode 100644 static/js/chat/lc-chatbot.umd.cjs diff --git a/helm-chart/sefaria/templates/configmap/local-settings-file.yaml b/helm-chart/sefaria/templates/configmap/local-settings-file.yaml index 0e244a44c3..47310e8ced 100644 --- a/helm-chart/sefaria/templates/configmap/local-settings-file.yaml +++ b/helm-chart/sefaria/templates/configmap/local-settings-file.yaml @@ -129,6 +129,7 @@ data: SESSION_CACHE_ALIAS = "default" SECRET_KEY = os.getenv("SECRET_KEY") + CHATBOT_USER_ID_SECRET = os.getenv("CHATBOT_USER_ID_SECRET") EMAIL_BACKEND = 'anymail.backends.mandrill.EmailBackend' DEFAULT_FROM_EMAIL = os.getenv("DEFAULT_FROM_EMAIL") diff --git a/requirements.txt b/requirements.txt index dd9c620798..7621453e96 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ Appium-Python-Client==1.2.0 Cerberus +cryptography==42.0.7 PyJWT==1.7.1 # pinned b/c current version 2.0.0 breaks simplejwt. waiting for 2.0.1 babel django-admin-sortable==2.1.13 diff --git a/sefaria/local_settings_example.py b/sefaria/local_settings_example.py index 927756fe0d..dfb51c4c89 100644 --- a/sefaria/local_settings_example.py +++ b/sefaria/local_settings_example.py @@ -143,6 +143,7 @@ MANAGERS = ADMINS SECRET_KEY = 'insert your long random secret key here !' +CHATBOT_USER_ID_SECRET = 'insert your chatbot user id secret here' EMAIL_HOST = 'localhost' diff --git a/sefaria/settings.py b/sefaria/settings.py index b785f4be9e..eb8ec49e85 100644 --- a/sefaria/settings.py +++ b/sefaria/settings.py @@ -69,6 +69,7 @@ # Make this unique, and don't share it with anybody. SECRET_KEY = '' +CHATBOT_USER_ID_SECRET = 'secret' TEMPLATES = [ { @@ -95,6 +96,7 @@ "sefaria.system.context_processors.header_html", "sefaria.system.context_processors.footer_html", "sefaria.system.context_processors.base_props", + "sefaria.system.context_processors.chatbot_user_token", ], 'loaders': [ #'django_mobile.loader.Loader', diff --git a/sefaria/system/context_processors.py b/sefaria/system/context_processors.py index d4268c6d6e..6a58d6f7a6 100644 --- a/sefaria/system/context_processors.py +++ b/sefaria/system/context_processors.py @@ -15,6 +15,7 @@ from sefaria.model.user_profile import UserProfile, UserHistorySet, UserWrapper from sefaria.utils import calendars from sefaria.utils.util import short_to_long_lang_code +from sefaria.utils.chatbot import build_chatbot_user_token from sefaria.utils.hebrew import hebrew_parasha_name from reader.views import render_react_component, _get_user_calendar_params @@ -195,3 +196,13 @@ def footer_html(request): @user_only def body_flags(request): return {"EMBED": "embed" in request.GET} + + +@user_only +def chatbot_user_token(request): + if not request.user.is_authenticated: + return {"chatbot_user_token": None} + if not CHATBOT_USER_ID_SECRET: + return {"chatbot_user_token": None} + token = build_chatbot_user_token(request.user.id, CHATBOT_USER_ID_SECRET) + return {"chatbot_user_token": token} diff --git a/sefaria/utils/chatbot.py b/sefaria/utils/chatbot.py new file mode 100644 index 0000000000..5fb1ad86e2 --- /dev/null +++ b/sefaria/utils/chatbot.py @@ -0,0 +1,37 @@ +import base64 +import hashlib +import json +import os +from datetime import timedelta + +from cryptography.hazmat.primitives.ciphers.aead import AESGCM +from django.utils import timezone + +DEFAULT_TTL_HOURS = 72 +NONCE_SIZE_BYTES = 12 + + +def _hash_user_id(user_id): + return hashlib.sha256(str(user_id).encode("utf-8")).hexdigest() + + +def _derive_key(secret): + return hashlib.sha256(secret.encode("utf-8")).digest() + + +def build_chatbot_user_token(user_id, secret, now=None, ttl_hours=DEFAULT_TTL_HOURS): + if not user_id or not secret: + return None + + expires_at = (now or timezone.now()) + timedelta(hours=ttl_hours) + payload = { + "id": _hash_user_id(user_id), + "expiration": expires_at.replace(microsecond=0).isoformat(), + } + payload_bytes = json.dumps(payload, separators=(",", ":"), sort_keys=True).encode("utf-8") + key = _derive_key(secret) + aesgcm = AESGCM(key) + nonce = os.urandom(NONCE_SIZE_BYTES) + encrypted = aesgcm.encrypt(nonce, payload_bytes, None) + token_bytes = nonce + encrypted + return base64.urlsafe_b64encode(token_bytes).decode("ascii") diff --git a/static/js/chat/lc-chatbot.umd.cjs b/static/js/chat/lc-chatbot.umd.cjs new file mode 100644 index 0000000000..9961c16313 --- /dev/null +++ b/static/js/chat/lc-chatbot.umd.cjs @@ -0,0 +1,112 @@ +(function(j,Z){typeof exports=="object"&&typeof module<"u"?module.exports=Z():typeof define=="function"&&define.amd?define(Z):(j=typeof globalThis<"u"?globalThis:j||self,j.LCChatbot=Z())})(this,function(){"use strict";var zf=Object.defineProperty;var bl=j=>{throw TypeError(j)};var Rf=(j,Z,ue)=>Z in j?zf(j,Z,{enumerable:!0,configurable:!0,writable:!0,value:ue}):j[Z]=ue;var E=(j,Z,ue)=>Rf(j,typeof Z!="symbol"?Z+"":Z,ue),ki=(j,Z,ue)=>Z.has(j)||bl("Cannot "+ue);var h=(j,Z,ue)=>(ki(j,Z,"read from private field"),ue?ue.call(j):Z.get(j)),D=(j,Z,ue)=>Z.has(j)?bl("Cannot add the same private member more than once"):Z instanceof WeakSet?Z.add(j):Z.set(j,ue),S=(j,Z,ue,dr)=>(ki(j,Z,"write to private field"),dr?dr.call(j,ue):Z.set(j,ue),ue),ie=(j,Z,ue)=>(ki(j,Z,"access private method"),ue);var gl,rr,sr,Dn,Mn,Dr,ir,ar,be,yi,Gr,Ti,wl,xl,ot,Qe,Mr,Ct,Nn,Lt,ct,je,Ot,Kt,pn,Pn,dn,Fn,gn,xs,le,kl,yl,Ei,Rs,$s,Si,kt,Dt,Je,Un,Nr,Pr,ks,Qt,ft,_i;const j="5";typeof window<"u"&&((gl=window.__svelte??(window.__svelte={})).v??(gl.v=new Set)).add(j);const Z=1,ue=2,dr=4,Tl=8,El=16,Sl=2,Ri="[",Wr="[!",Is="]",xn={},ye=Symbol(),Cs=!1;var $i=Array.isArray,Al=Array.prototype.indexOf,qr=Array.from,jr=Object.keys,Yr=Object.defineProperty,qn=Object.getOwnPropertyDescriptor,zl=Object.prototype,Rl=Array.prototype,$l=Object.getPrototypeOf,Ii=Object.isExtensible;function Il(t){for(var e=0;e{t=r,e=s});return{promise:n,resolve:t,reject:e}}const _e=2,Ls=4,Os=8,Cl=1<<24,Bt=16,Gt=32,ln=64,Zr=128,mt=512,Te=1024,Ge=2048,Et=4096,Ve=8192,Wt=16384,Vr=32768,jn=65536,Li=1<<17,Oi=1<<18,kn=1<<19,Ll=1<<20,qt=1<<25,yn=32768,Ds=1<<21,Ms=1<<22,on=1<<23,Xr=Symbol("$state"),Ol=Symbol("legacy props"),Yn=new class extends Error{constructor(){super(...arguments);E(this,"name","StaleReactionError");E(this,"message","The reaction that called `getAbortSignal()` was re-run or destroyed")}},Kr=3,Tn=8;function Dl(){throw new Error("https://svelte.dev/e/async_derived_orphan")}function Ml(t){throw new Error("https://svelte.dev/e/effect_in_teardown")}function Nl(){throw new Error("https://svelte.dev/e/effect_in_unowned_derived")}function Pl(t){throw new Error("https://svelte.dev/e/effect_orphan")}function Fl(){throw new Error("https://svelte.dev/e/effect_update_depth_exceeded")}function Ul(){throw new Error("https://svelte.dev/e/hydration_failed")}function Hl(){throw new Error("https://svelte.dev/e/state_descriptors_fixed")}function Bl(){throw new Error("https://svelte.dev/e/state_prototype_fixed")}function Gl(){throw new Error("https://svelte.dev/e/state_unsafe_mutation")}function Wl(){throw new Error("https://svelte.dev/e/svelte_boundary_reset_onerror")}function gr(t){console.warn("https://svelte.dev/e/hydration_mismatch")}function ql(){console.warn("https://svelte.dev/e/svelte_boundary_reset_noop")}let C=!1;function jt(t){C=t}let L;function Ee(t){if(t===null)throw gr(),xn;return L=t}function Zn(){return Ee(_t(L))}function X(t){if(C){if(_t(L)!==null)throw gr(),xn;L=t}}function Ns(t=1){if(C){for(var e=t,n=L;e--;)n=_t(n);L=n}}function Qr(t=!0){for(var e=0,n=L;;){if(n.nodeType===Tn){var r=n.data;if(r===Is){if(e===0)return n;e-=1}else(r===Ri||r===Wr)&&(e+=1)}var s=_t(n);t&&n.remove(),n=s}}function Di(t){if(!t||t.nodeType!==Tn)throw gr(),xn;return t.data}function Mi(t){return t===this.v}function jl(t,e){return t!=t?e==e:t!==e||t!==null&&typeof t=="object"||typeof t=="function"}function Ni(t){return!jl(t,this.v)}let Yl=!1,nt=null;function Vn(t){nt=t}function Pi(t,e=!1,n){nt={p:nt,i:!1,c:null,e:null,s:t,x:null,l:null}}function Fi(t){var e=nt,n=e.e;if(n!==null){e.e=null;for(var r of n)aa(r)}return t!==void 0&&(e.x=t),e.i=!0,nt=e.p,t??{}}function Ui(){return!0}let En=[];function Hi(){var t=En;En=[],Il(t)}function Xn(t){if(En.length===0&&!vr){var e=En;queueMicrotask(()=>{e===En&&Hi()})}En.push(t)}function Zl(){for(;En.length>0;)Hi()}function Bi(t){var e=P;if(e===null)return O.f|=on,t;if(e.f&Vr)Kn(t,e);else{if(!(e.f&Zr))throw t;e.b.error(t)}}function Kn(t,e){for(;e!==null;){if(e.f&Zr)try{e.b.error(t);return}catch(n){t=n}e=e.parent}throw t}const Jr=new Set;let Y=null,es=null,rt=null,st=[],ts=null,Ps=!1,vr=!1;const ws=class ws{constructor(){D(this,be);E(this,"committed",!1);E(this,"current",new Map);E(this,"previous",new Map);D(this,rr,new Set);D(this,sr,new Set);D(this,Dn,0);D(this,Mn,0);D(this,Dr,null);D(this,ir,new Set);D(this,ar,new Set);E(this,"skipped_effects",new Set);E(this,"is_fork",!1)}is_deferred(){return this.is_fork||h(this,Mn)>0}process(e){st=[],es=null,this.apply();var n={parent:null,effect:null,effects:[],render_effects:[]};for(const r of e)ie(this,be,yi).call(this,r,n);this.is_fork||ie(this,be,wl).call(this),this.is_deferred()?(ie(this,be,Gr).call(this,n.effects),ie(this,be,Gr).call(this,n.render_effects)):(es=this,Y=null,Wi(n.render_effects),Wi(n.effects),es=null,h(this,Dr)?.resolve()),rt=null}capture(e,n){this.previous.has(e)||this.previous.set(e,n),e.f&on||(this.current.set(e,e.v),rt?.set(e,e.v))}activate(){Y=this,this.apply()}deactivate(){Y===this&&(Y=null,rt=null)}flush(){if(this.activate(),st.length>0){if(Gi(),Y!==null&&Y!==this)return}else h(this,Dn)===0&&this.process([]);this.deactivate()}discard(){for(const e of h(this,sr))e(this);h(this,sr).clear()}increment(e){S(this,Dn,h(this,Dn)+1),e&&S(this,Mn,h(this,Mn)+1)}decrement(e){S(this,Dn,h(this,Dn)-1),e&&S(this,Mn,h(this,Mn)-1),this.revive()}revive(){for(const e of h(this,ir))h(this,ar).delete(e),Se(e,Ge),Sn(e);for(const e of h(this,ar))Se(e,Et),Sn(e);this.flush()}oncommit(e){h(this,rr).add(e)}ondiscard(e){h(this,sr).add(e)}settled(){return(h(this,Dr)??S(this,Dr,Ci())).promise}static ensure(){if(Y===null){const e=Y=new ws;Jr.add(Y),vr||ws.enqueue(()=>{Y===e&&e.flush()})}return Y}static enqueue(e){Xn(e)}apply(){}};rr=new WeakMap,sr=new WeakMap,Dn=new WeakMap,Mn=new WeakMap,Dr=new WeakMap,ir=new WeakMap,ar=new WeakMap,be=new WeakSet,yi=function(e,n){e.f^=Te;for(var r=e.first;r!==null;){var s=r.f,i=(s&(Gt|ln))!==0,a=i&&(s&Te)!==0,l=a||(s&Ve)!==0||this.skipped_effects.has(r);if(r.f&Zr&&r.b?.is_pending()&&(n={parent:n,effect:r,effects:[],render_effects:[]}),!l&&r.fn!==null){i?r.f^=Te:s&Ls?n.effects.push(r):wr(r)&&(r.f&Bt&&h(this,ir).add(r),xr(r));var o=r.first;if(o!==null){r=o;continue}}var c=r.parent;for(r=r.next;r===null&&c!==null;)c===n.effect&&(ie(this,be,Gr).call(this,n.effects),ie(this,be,Gr).call(this,n.render_effects),n=n.parent),r=c.next,c=c.parent}},Gr=function(e){for(const n of e)n.f&Ge?h(this,ir).add(n):n.f&Et&&h(this,ar).add(n),ie(this,be,Ti).call(this,n.deps),Se(n,Te)},Ti=function(e){if(e!==null)for(const n of e)!(n.f&_e)||!(n.f&yn)||(n.f^=yn,ie(this,be,Ti).call(this,n.deps))},wl=function(){if(h(this,Mn)===0){for(const e of h(this,rr))e();h(this,rr).clear()}h(this,Dn)===0&&ie(this,be,xl).call(this)},xl=function(){var i;if(Jr.size>1){this.previous.clear();var e=rt,n=!0,r={parent:null,effect:null,effects:[],render_effects:[]};for(const a of Jr){if(a===this){n=!1;continue}const l=[];for(const[c,u]of this.current){if(a.current.has(c))if(n&&u!==a.current.get(c))a.current.set(c,u);else continue;l.push(c)}if(l.length===0)continue;const o=[...a.current.keys()].filter(c=>!this.current.has(c));if(o.length>0){var s=st;st=[];const c=new Set,u=new Map;for(const g of l)qi(g,o,c,u);if(st.length>0){Y=a,a.apply();for(const g of st)ie(i=a,be,yi).call(i,g,r);a.deactivate()}st=s}}Y=null,rt=e}this.committed=!0,Jr.delete(this)};let St=ws;function Qn(t){var e=vr;vr=!0;try{for(var n;;){if(Zl(),st.length===0&&(Y?.flush(),st.length===0))return ts=null,n;Gi()}}finally{vr=e}}function Gi(){var t=$n;Ps=!0;var e=null;try{var n=0;for(as(!0);st.length>0;){var r=St.ensure();if(n++>1e3){var s,i;Vl()}r.process(st),cn.clear()}}finally{Ps=!1,as(t),ts=null}}function Vl(){try{Fl()}catch(t){Kn(t,ts)}}let Yt=null;function Wi(t){var e=t.length;if(e!==0){for(var n=0;n0)){cn.clear();for(const s of Yt){if(s.f&(Wt|Ve))continue;const i=[s];let a=s.parent;for(;a!==null;)Yt.has(a)&&(Yt.delete(a),i.push(a)),a=a.parent;for(let l=i.length-1;l>=0;l--){const o=i[l];o.f&(Wt|Ve)||xr(o)}}Yt.clear()}}Yt=null}}function qi(t,e,n,r){if(!n.has(t)&&(n.add(t),t.reactions!==null))for(const s of t.reactions){const i=s.f;i&_e?qi(s,e,n,r):i&(Ms|Bt)&&!(i&Ge)&&ji(s,e,r)&&(Se(s,Ge),Sn(s))}}function ji(t,e,n){const r=n.get(t);if(r!==void 0)return r;if(t.deps!==null)for(const s of t.deps){if(e.includes(s))return!0;if(s.f&_e&&ji(s,e,n))return n.set(s,!0),!0}return n.set(t,!1),!1}function Sn(t){for(var e=ts=t;e.parent!==null;){e=e.parent;var n=e.f;if(Ps&&e===P&&n&Bt&&!(n&Oi))return;if(n&(ln|Gt)){if(!(n&Te))return;e.f^=Te}}st.push(e)}function Xl(t){let e=0,n=An(0),r;return()=>{_r()&&(d(n),is(()=>(e===0&&(r=qs(()=>t(()=>mr(n)))),e+=1,()=>{Xn(()=>{e-=1,e===0&&(r?.(),r=void 0,mr(n))})})))}}var Kl=jn|kn|Zr;function Ql(t,e,n){new Jl(t,e,n)}class Jl{constructor(e,n,r){D(this,le);E(this,"parent");D(this,ot,!1);D(this,Qe);D(this,Mr,C?L:null);D(this,Ct);D(this,Nn);D(this,Lt);D(this,ct,null);D(this,je,null);D(this,Ot,null);D(this,Kt,null);D(this,pn,null);D(this,Pn,0);D(this,dn,0);D(this,Fn,!1);D(this,gn,null);D(this,xs,Xl(()=>(S(this,gn,An(h(this,Pn))),()=>{S(this,gn,null)})));S(this,Qe,e),S(this,Ct,n),S(this,Nn,r),this.parent=P.b,S(this,ot,!!h(this,Ct).pending),S(this,Lt,Gs(()=>{if(P.b=this,C){const i=h(this,Mr);Zn(),i.nodeType===Tn&&i.data===Wr?ie(this,le,yl).call(this):ie(this,le,kl).call(this)}else{var s=ie(this,le,Ei).call(this);try{S(this,ct,it(()=>r(s)))}catch(i){this.error(i)}h(this,dn)>0?ie(this,le,$s).call(this):S(this,ot,!1)}return()=>{h(this,pn)?.remove()}},Kl)),C&&S(this,Qe,L)}is_pending(){return h(this,ot)||!!this.parent&&this.parent.is_pending()}has_pending_snippet(){return!!h(this,Ct).pending}update_pending_count(e){ie(this,le,Si).call(this,e),S(this,Pn,h(this,Pn)+e),h(this,gn)&&Jn(h(this,gn),h(this,Pn))}get_effect_pending(){return h(this,xs).call(this),d(h(this,gn))}error(e){var n=h(this,Ct).onerror;let r=h(this,Ct).failed;if(h(this,Fn)||!n&&!r)throw e;h(this,ct)&&(Oe(h(this,ct)),S(this,ct,null)),h(this,je)&&(Oe(h(this,je)),S(this,je,null)),h(this,Ot)&&(Oe(h(this,Ot)),S(this,Ot,null)),C&&(Ee(h(this,Mr)),Ns(),Ee(Qr()));var s=!1,i=!1;const a=()=>{if(s){ql();return}s=!0,i&&Wl(),St.ensure(),S(this,Pn,0),h(this,Ot)!==null&&Rn(h(this,Ot),()=>{S(this,Ot,null)}),S(this,ot,this.has_pending_snippet()),S(this,ct,ie(this,le,Rs).call(this,()=>(S(this,Fn,!1),it(()=>h(this,Nn).call(this,h(this,Qe)))))),h(this,dn)>0?ie(this,le,$s).call(this):S(this,ot,!1)};var l=O;try{qe(null),i=!0,n?.(e,a),i=!1}catch(o){Kn(o,h(this,Lt)&&h(this,Lt).parent)}finally{qe(l)}r&&Xn(()=>{S(this,Ot,ie(this,le,Rs).call(this,()=>{St.ensure(),S(this,Fn,!0);try{return it(()=>{r(h(this,Qe),()=>e,()=>a)})}catch(o){return Kn(o,h(this,Lt).parent),null}finally{S(this,Fn,!1)}}))})}}ot=new WeakMap,Qe=new WeakMap,Mr=new WeakMap,Ct=new WeakMap,Nn=new WeakMap,Lt=new WeakMap,ct=new WeakMap,je=new WeakMap,Ot=new WeakMap,Kt=new WeakMap,pn=new WeakMap,Pn=new WeakMap,dn=new WeakMap,Fn=new WeakMap,gn=new WeakMap,xs=new WeakMap,le=new WeakSet,kl=function(){try{S(this,ct,it(()=>h(this,Nn).call(this,h(this,Qe))))}catch(e){this.error(e)}S(this,ot,!1)},yl=function(){const e=h(this,Ct).pending;e&&(S(this,je,it(()=>e(h(this,Qe)))),St.enqueue(()=>{var n=ie(this,le,Ei).call(this);S(this,ct,ie(this,le,Rs).call(this,()=>(St.ensure(),it(()=>h(this,Nn).call(this,n))))),h(this,dn)>0?ie(this,le,$s).call(this):(Rn(h(this,je),()=>{S(this,je,null)}),S(this,ot,!1))}))},Ei=function(){var e=h(this,Qe);return h(this,ot)&&(S(this,pn,We()),h(this,Qe).before(h(this,pn)),e=h(this,pn)),e},Rs=function(e){var n=P,r=O,s=nt;Rt(h(this,Lt)),qe(h(this,Lt)),Vn(h(this,Lt).ctx);try{return e()}catch(i){return Bi(i),null}finally{Rt(n),qe(r),Vn(s)}},$s=function(){const e=h(this,Ct).pending;h(this,ct)!==null&&(S(this,Kt,document.createDocumentFragment()),h(this,Kt).append(h(this,pn)),da(h(this,ct),h(this,Kt))),h(this,je)===null&&S(this,je,it(()=>e(h(this,Qe))))},Si=function(e){var n;if(!this.has_pending_snippet()){this.parent&&ie(n=this.parent,le,Si).call(n,e);return}S(this,dn,h(this,dn)+e),h(this,dn)===0&&(S(this,ot,!1),h(this,je)&&Rn(h(this,je),()=>{S(this,je,null)}),h(this,Kt)&&(h(this,Qe).before(h(this,Kt)),S(this,Kt,null)))};function eo(t,e,n,r){const s=rs;if(n.length===0&&t.length===0){r(e.map(s));return}var i=Y,a=P,l=to();function o(){Promise.all(n.map(c=>no(c))).then(c=>{l();try{r([...e.map(s),...c])}catch(u){a.f&Wt||Kn(u,a)}i?.deactivate(),ns()}).catch(c=>{Kn(c,a)})}t.length>0?Promise.all(t).then(()=>{l();try{return o()}finally{i?.deactivate(),ns()}}):o()}function to(){var t=P,e=O,n=nt,r=Y;return function(i=!0){Rt(t),qe(e),Vn(n),i&&r?.activate()}}function ns(){Rt(null),qe(null),Vn(null)}function rs(t){var e=_e|Ge,n=O!==null&&O.f&_e?O:null;return P!==null&&(P.f|=kn),{ctx:nt,deps:null,effects:null,equals:Mi,f:e,fn:t,reactions:null,rv:0,v:ye,wv:0,parent:n??P,ac:null}}function no(t,e){let n=P;n===null&&Dl();var r=n.b,s=void 0,i=An(ye),a=!O,l=new Map;return go(()=>{var o=Ci();s=o.promise;try{Promise.resolve(t()).then(o.resolve,o.reject).then(()=>{c===Y&&c.committed&&c.deactivate(),ns()})}catch(p){o.reject(p),ns()}var c=Y;if(a){var u=!r.is_pending();r.update_pending_count(1),c.increment(u),l.get(c)?.reject(Yn),l.delete(c),l.set(c,o)}const g=(p,v=void 0)=>{if(c.activate(),v)v!==Yn&&(i.f|=on,Jn(i,v));else{i.f&on&&(i.f^=on),Jn(i,p);for(const[b,R]of l){if(l.delete(b),b===c)break;R.reject(Yn)}}a&&(r.update_pending_count(-1),c.decrement(u))};o.promise.then(g,p=>g(null,p||"unknown"))}),sa(()=>{for(const o of l.values())o.reject(Yn)}),new Promise(o=>{function c(u){function g(){u===s?o(i):c(s)}u.then(g,g)}c(s)})}function ro(t){const e=rs(t);return va(e),e}function so(t){const e=rs(t);return e.equals=Ni,e}function Yi(t){var e=t.effects;if(e!==null){t.effects=null;for(var n=0;n0&&!Vi&&ao()}return e}function ao(){Vi=!1;var t=$n;as(!0);const e=Array.from(Us);try{for(const n of e)n.f&Te&&Se(n,Et),wr(n)&&xr(n)}finally{as(t)}Us.clear()}function mr(t){T(t,t.v+1)}function Ki(t,e){var n=t.reactions;if(n!==null)for(var r=n.length,s=0;s{if(Cn===i)return l();var o=O,c=Cn;qe(null),_a(i);var u=l();return qe(o),_a(c),u};return r&&n.set("length",re(t.length)),new Proxy(t,{defineProperty(l,o,c){(!("value"in c)||c.configurable===!1||c.enumerable===!1||c.writable===!1)&&Hl();var u=n.get(o);return u===void 0?u=a(()=>{var g=re(c.value);return n.set(o,g),g}):T(u,c.value,!0),!0},deleteProperty(l,o){var c=n.get(o);if(c===void 0){if(o in l){const u=a(()=>re(ye));n.set(o,u),mr(s)}}else T(c,ye),mr(s);return!0},get(l,o,c){if(o===Xr)return t;var u=n.get(o),g=o in l;if(u===void 0&&(!g||qn(l,o)?.writable)&&(u=a(()=>{var v=zn(g?l[o]:ye),b=re(v);return b}),n.set(o,u)),u!==void 0){var p=d(u);return p===ye?void 0:p}return Reflect.get(l,o,c)},getOwnPropertyDescriptor(l,o){var c=Reflect.getOwnPropertyDescriptor(l,o);if(c&&"value"in c){var u=n.get(o);u&&(c.value=d(u))}else if(c===void 0){var g=n.get(o),p=g?.v;if(g!==void 0&&p!==ye)return{enumerable:!0,configurable:!0,value:p,writable:!0}}return c},has(l,o){if(o===Xr)return!0;var c=n.get(o),u=c!==void 0&&c.v!==ye||Reflect.has(l,o);if(c!==void 0||P!==null&&(!u||qn(l,o)?.writable)){c===void 0&&(c=a(()=>{var p=u?zn(l[o]):ye,v=re(p);return v}),n.set(o,c));var g=d(c);if(g===ye)return!1}return u},set(l,o,c,u){var g=n.get(o),p=o in l;if(r&&o==="length")for(var v=c;vre(ye)),n.set(v+"",b))}if(g===void 0)(!p||qn(l,o)?.writable)&&(g=a(()=>re(void 0)),T(g,zn(c)),n.set(o,g));else{p=g.v!==ye;var R=a(()=>zn(c));T(g,R)}var _=Reflect.getOwnPropertyDescriptor(l,o);if(_?.set&&_.set.call(u,c),!p){if(r&&typeof o=="string"){var x=n.get("length"),U=Number(o);Number.isInteger(U)&&U>=x.v&&T(x,U+1)}mr(s)}return!0},ownKeys(l){d(s);var o=Reflect.ownKeys(l).filter(g=>{var p=n.get(g);return p===void 0||p.v!==ye});for(var[c,u]of n)u.v!==ye&&!(c in l)&&o.push(c);return o},setPrototypeOf(){Bl()}})}var Qi,Ji,ea,ta;function Hs(){if(Qi===void 0){Qi=window,Ji=/Firefox/.test(navigator.userAgent);var t=Element.prototype,e=Node.prototype,n=Text.prototype;ea=qn(e,"firstChild").get,ta=qn(e,"nextSibling").get,Ii(t)&&(t.__click=void 0,t.__className=void 0,t.__attributes=null,t.__style=void 0,t.__e=void 0),Ii(n)&&(n.__t=void 0)}}function We(t=""){return document.createTextNode(t)}function Le(t){return ea.call(t)}function _t(t){return ta.call(t)}function K(t,e){if(!C)return Le(t);var n=Le(L);if(n===null)n=L.appendChild(We());else if(e&&n.nodeType!==Kr){var r=We();return n?.before(r),Ee(r),r}return Ee(n),n}function er(t,e=!1){if(!C){var n=Le(t);return n instanceof Comment&&n.data===""?_t(n):n}if(e&&L?.nodeType!==Kr){var r=We();return L?.before(r),Ee(r),r}return L}function se(t,e=1,n=!1){let r=C?L:t;for(var s;e--;)s=r,r=_t(r);if(!C)return r;if(n&&r?.nodeType!==Kr){var i=We();return r===null?s?.after(i):r.before(i),Ee(i),i}return Ee(r),r}function Bs(t){t.textContent=""}function na(){return!1}function lo(t){C&&Le(t)!==null&&Bs(t)}let ra=!1;function oo(){ra||(ra=!0,document.addEventListener("reset",t=>{Promise.resolve().then(()=>{if(!t.defaultPrevented)for(const e of t.target.elements)e.__on_r?.()})},{capture:!0}))}function ss(t){var e=O,n=P;qe(null),Rt(null);try{return t()}finally{qe(e),Rt(n)}}function co(t,e,n,r=n){t.addEventListener(e,()=>ss(n));const s=t.__on_r;s?t.__on_r=()=>{s(),r(!0)}:t.__on_r=()=>r(!0),oo()}function fo(t){P===null&&(O===null&&Pl(),Nl()),In&&Ml()}function uo(t,e){var n=e.last;n===null?e.last=e.first=t:(n.next=t,t.prev=n,e.last=t)}function At(t,e,n){var r=P;r!==null&&r.f&Ve&&(t|=Ve);var s={ctx:nt,deps:null,nodes:null,f:t|Ge|mt,first:null,fn:e,last:null,next:null,parent:r,b:r&&r.b,prev:null,teardown:null,wv:0,ac:null};if(n)try{xr(s),s.f|=Vr}catch(l){throw Oe(s),l}else e!==null&&Sn(s);var i=s;if(n&&i.deps===null&&i.teardown===null&&i.nodes===null&&i.first===i.last&&!(i.f&kn)&&(i=i.first,t&Bt&&t&jn&&i!==null&&(i.f|=jn)),i!==null&&(i.parent=r,r!==null&&uo(i,r),O!==null&&O.f&_e&&!(t&ln))){var a=O;(a.effects??(a.effects=[])).push(i)}return s}function _r(){return O!==null&&!zt}function sa(t){const e=At(Os,null,!1);return Se(e,Te),e.teardown=t,e}function ia(t){fo();var e=P.f,n=!O&&(e&Gt)!==0&&(e&Vr)===0;if(n){var r=nt;(r.e??(r.e=[])).push(t)}else return aa(t)}function aa(t){return At(Ls|Ll,t,!1)}function ho(t){St.ensure();const e=At(ln|kn,t,!0);return()=>{Oe(e)}}function po(t){St.ensure();const e=At(ln|kn,t,!0);return(n={})=>new Promise(r=>{n.outro?Rn(e,()=>{Oe(e),r(void 0)}):(Oe(e),r(void 0))})}function la(t){return At(Ls,t,!1)}function go(t){return At(Ms|kn,t,!0)}function is(t,e=0){return At(Os|e,t,!0)}function bt(t,e=[],n=[],r=[]){eo(r,e,n,s=>{At(Os,()=>t(...s.map(d)),!0)})}function Gs(t,e=0){var n=At(Bt|e,t,!0);return n}function it(t){return At(Gt|kn,t,!0)}function oa(t){var e=t.teardown;if(e!==null){const n=In,r=O;ga(!0),qe(null);try{e.call(null)}finally{ga(n),qe(r)}}}function ca(t,e=!1){var n=t.first;for(t.first=t.last=null;n!==null;){const s=n.ac;s!==null&&ss(()=>{s.abort(Yn)});var r=n.next;n.f&ln?n.parent=null:Oe(n,e),n=r}}function vo(t){for(var e=t.first;e!==null;){var n=e.next;e.f&Gt||Oe(e),e=n}}function Oe(t,e=!0){var n=!1;(e||t.f&Oi)&&t.nodes!==null&&t.nodes.end!==null&&(fa(t.nodes.start,t.nodes.end),n=!0),ca(t,e&&!n),ls(t,0),Se(t,Wt);var r=t.nodes&&t.nodes.t;if(r!==null)for(const i of r)i.stop();oa(t);var s=t.parent;s!==null&&s.first!==null&&ua(t),t.next=t.prev=t.teardown=t.ctx=t.deps=t.fn=t.nodes=t.ac=null}function fa(t,e){for(;t!==null;){var n=t===e?null:_t(t);t.remove(),t=n}}function ua(t){var e=t.parent,n=t.prev,r=t.next;n!==null&&(n.next=r),r!==null&&(r.prev=n),e!==null&&(e.first===t&&(e.first=r),e.last===t&&(e.last=n))}function Rn(t,e,n=!0){var r=[];ha(t,r,!0);var s=()=>{n&&Oe(t),e&&e()},i=r.length;if(i>0){var a=()=>--i||s();for(var l of r)l.out(a)}else s()}function ha(t,e,n){if(!(t.f&Ve)){t.f^=Ve;var r=t.nodes&&t.nodes.t;if(r!==null)for(const l of r)(l.is_global||n)&&e.push(l);for(var s=t.first;s!==null;){var i=s.next,a=(s.f&jn)!==0||(s.f&Gt)!==0&&(t.f&Bt)!==0;ha(s,e,a?n:!1),s=i}}}function Ws(t){pa(t,!0)}function pa(t,e){if(t.f&Ve){t.f^=Ve,t.f&Te||(Se(t,Ge),Sn(t));for(var n=t.first;n!==null;){var r=n.next,s=(n.f&jn)!==0||(n.f&Gt)!==0;pa(n,s?e:!1),n=r}var i=t.nodes&&t.nodes.t;if(i!==null)for(const a of i)(a.is_global||e)&&a.in()}}function da(t,e){if(t.nodes)for(var n=t.nodes.start,r=t.nodes.end;n!==null;){var s=n===r?null:_t(n);e.append(n),n=s}}let $n=!1;function as(t){$n=t}let In=!1;function ga(t){In=t}let O=null,zt=!1;function qe(t){O=t}let P=null;function Rt(t){P=t}let Zt=null;function va(t){O!==null&&(Zt===null?Zt=[t]:Zt.push(t))}let De=null,Xe=0,at=null;function mo(t){at=t}let ma=1,br=0,Cn=br;function _a(t){Cn=t}function ba(){return++ma}function wr(t){var e=t.f;if(e&Ge)return!0;if(e&_e&&(t.f&=~yn),e&Et){var n=t.deps;if(n!==null)for(var r=n.length,s=0;st.wv)return!0}e&mt&&rt===null&&Se(t,Te)}return!1}function wa(t,e,n=!0){var r=t.reactions;if(r!==null&&!Zt?.includes(t))for(var s=0;s{t.ac.abort(Yn)}),t.ac=null);try{t.f|=Ds;var u=t.fn,g=u(),p=t.deps;if(De!==null){var v;if(ls(t,Xe),p!==null&&Xe>0)for(p.length=Xe+De.length,v=0;vn?.call(this,i))}return t.startsWith("pointer")||t.startsWith("touch")||t==="wheel"?Xn(()=>{e.addEventListener(t,s,r)}):e.addEventListener(t,s,r),s}function ko(t,e,n,r,s){var i={capture:r,passive:s},a=xo(t,e,n,i);(e===document.body||e===window||e===document||e instanceof HTMLMediaElement)&&sa(()=>{e.removeEventListener(t,a,i)})}function yo(t){for(var e=0;e{throw _});throw p}}finally{t.__root=e,delete t.currentTarget,qe(u),Rt(g)}}}function Ys(t){var e=document.createElement("template");return e.innerHTML=t.replaceAll("",""),e.content}function wt(t,e){var n=P;n.nodes===null&&(n.nodes={start:t,end:e,a:null,t:null})}function he(t,e){var n=(e&Sl)!==0,r,s=!t.startsWith("");return()=>{if(C)return wt(L,null),L;r===void 0&&(r=Ys(s?t:""+t),r=Le(r));var i=n||Ji?document.importNode(r,!0):r.cloneNode(!0);return wt(i,i),i}}function To(t,e,n="svg"){var r=!t.startsWith(""),s=`<${n}>${r?t:""+t}`,i;return()=>{if(C)return wt(L,null),L;if(!i){var a=Ys(s),l=Le(a);for(i=document.createDocumentFragment();Le(l);)i.appendChild(Le(l))}var o=i.cloneNode(!0);{var c=Le(o),u=o.lastChild;wt(c,u)}return o}}function Sa(t,e){return To(t,e,"svg")}function Aa(t=""){if(!C){var e=We(t+"");return wt(e,e),e}var n=L;return n.nodeType!==Kr&&(n.before(n=We()),Ee(n)),wt(n,n),n}function tr(){if(C)return wt(L,null),L;var t=document.createDocumentFragment(),e=document.createComment(""),n=We();return t.append(e,n),wt(e,n),t}function G(t,e){if(C){var n=P;(!(n.f&Vr)||n.nodes.end===null)&&(n.nodes.end=L),Zn();return}t!==null&&t.before(e)}const Eo=["touchstart","touchmove"];function So(t){return Eo.includes(t)}function fn(t,e){var n=e==null?"":typeof e=="object"?e+"":e;n!==(t.__t??(t.__t=t.nodeValue))&&(t.__t=n,t.nodeValue=n+"")}function za(t,e){return Ra(t,e)}function Ao(t,e){Hs(),e.intro=e.intro??!1;const n=e.target,r=C,s=L;try{for(var i=Le(n);i&&(i.nodeType!==Tn||i.data!==Ri);)i=_t(i);if(!i)throw xn;jt(!0),Ee(i);const a=Ra(t,{...e,anchor:i});return jt(!1),a}catch(a){if(a instanceof Error&&a.message.split(` +`).some(l=>l.startsWith("https://svelte.dev/e/")))throw a;return a!==xn&&console.warn("Failed to hydrate: ",a),e.recover===!1&&Ul(),Hs(),Bs(n),jt(!1),za(t,e)}finally{jt(r),Ee(s)}}const nr=new Map;function Ra(t,{target:e,anchor:n,props:r={},events:s,context:i,intro:a=!0}){Hs();var l=new Set,o=g=>{for(var p=0;p{var g=n??e.appendChild(We());return Ql(g,{pending:()=>{}},p=>{if(i){Pi({});var v=nt;v.c=i}if(s&&(r.$$events=s),C&&wt(p,null),c=t(p,r)||{},C&&(P.nodes.end=L,L===null||L.nodeType!==Tn||L.data!==Is))throw gr(),xn;i&&Fi()}),()=>{for(var p of l){e.removeEventListener(p,kr);var v=nr.get(p);--v===0?(document.removeEventListener(p,kr),nr.delete(p)):nr.set(p,v)}js.delete(o),g!==n&&g.parentNode?.removeChild(g)}});return Zs.set(c,u),c}let Zs=new WeakMap;function zo(t,e){const n=Zs.get(t);return n?(Zs.delete(t),n(e)):Promise.resolve()}class Ro{constructor(e,n=!0){E(this,"anchor");D(this,kt,new Map);D(this,Dt,new Map);D(this,Je,new Map);D(this,Un,new Set);D(this,Nr,!0);D(this,Pr,()=>{var e=Y;if(h(this,kt).has(e)){var n=h(this,kt).get(e),r=h(this,Dt).get(n);if(r)Ws(r),h(this,Un).delete(n);else{var s=h(this,Je).get(n);s&&(h(this,Dt).set(n,s.effect),h(this,Je).delete(n),s.fragment.lastChild.remove(),this.anchor.before(s.fragment),r=s.effect)}for(const[i,a]of h(this,kt)){if(h(this,kt).delete(i),i===e)break;const l=h(this,Je).get(a);l&&(Oe(l.effect),h(this,Je).delete(a))}for(const[i,a]of h(this,Dt)){if(i===n||h(this,Un).has(i))continue;const l=()=>{if(Array.from(h(this,kt).values()).includes(i)){var c=document.createDocumentFragment();da(a,c),c.append(We()),h(this,Je).set(i,{effect:a,fragment:c})}else Oe(a);h(this,Un).delete(i),h(this,Dt).delete(i)};h(this,Nr)||!r?(h(this,Un).add(i),Rn(a,l,!1)):l()}}});D(this,ks,e=>{h(this,kt).delete(e);const n=Array.from(h(this,kt).values());for(const[r,s]of h(this,Je))n.includes(r)||(Oe(s.effect),h(this,Je).delete(r))});this.anchor=e,S(this,Nr,n)}ensure(e,n){var r=Y,s=na();if(n&&!h(this,Dt).has(e)&&!h(this,Je).has(e))if(s){var i=document.createDocumentFragment(),a=We();i.append(a),h(this,Je).set(e,{effect:it(()=>n(a)),fragment:i})}else h(this,Dt).set(e,it(()=>n(this.anchor)));if(h(this,kt).set(r,e),s){for(const[l,o]of h(this,Dt))l===e?r.skipped_effects.delete(o):r.skipped_effects.add(o);for(const[l,o]of h(this,Je))l===e?r.skipped_effects.delete(o.effect):r.skipped_effects.add(o.effect);r.oncommit(h(this,Pr)),r.ondiscard(h(this,ks))}else C&&(this.anchor=L),h(this,Pr).call(this)}}kt=new WeakMap,Dt=new WeakMap,Je=new WeakMap,Un=new WeakMap,Nr=new WeakMap,Pr=new WeakMap,ks=new WeakMap;function Ae(t,e,n=!1){C&&Zn();var r=new Ro(t),s=n?jn:0;function i(a,l){if(C){const c=Di(t)===Wr;if(a===c){var o=Qr();Ee(o),r.anchor=o,jt(!1),r.ensure(a,l),jt(!0);return}}r.ensure(a,l)}Gs(()=>{var a=!1;e((l,o=!0)=>{a=!0,i(o,l)}),a||i(!1,null)},s)}function $o(t,e){return e}function Io(t,e,n){for(var r=[],s=e.length,i,a=e.length,l=0;l{if(i){if(i.pending.delete(g),i.done.add(g),i.pending.size===0){var p=t.outrogroups;Vs(qr(i.done)),p.delete(i),p.size===0&&(t.outrogroups=null)}}else a-=1},!1)}if(a===0){var o=r.length===0&&n!==null;if(o){var c=n,u=c.parentNode;Bs(u),u.append(c),t.items.clear()}Vs(e,!o)}else i={pending:new Set(e),done:new Set},(t.outrogroups??(t.outrogroups=new Set)).add(i)}function Vs(t,e=!0){for(var n=0;n{var x=n();return $i(x)?x:x==null?[]:qr(x)}),p,v=!0;function b(){_.fallback=u,Co(_,p,a,e,r),u!==null&&(p.length===0?u.f&qt?(u.f^=qt,yr(u,null,a)):Ws(u):Rn(u,()=>{u=null}))}var R=Gs(()=>{p=d(g);var x=p.length;let U=!1;if(C){var H=Di(a)===Wr;H!==(x===0)&&(a=Qr(),Ee(a),jt(!1),U=!0)}for(var M=new Set,ve=Y,we=na(),ee=0;eei(a)):(u=it(()=>i($a??($a=We()))),u.f|=qt)),C&&x>0&&Ee(Qr()),!v)if(we){for(const[pe,Hn]of l)M.has(pe)||ve.skipped_effects.add(Hn.e);ve.oncommit(b),ve.ondiscard(()=>{})}else b();U&&jt(!0),d(g)}),_={effect:R,items:l,outrogroups:null,fallback:u};v=!1,C&&(a=L)}function Co(t,e,n,r,s){var i=(r&Tl)!==0,a=e.length,l=t.items,o=t.effect.first,c,u=null,g,p=[],v=[],b,R,_,x;if(i)for(x=0;x0){var et=r&dr&&a===0?n:null;if(i){for(x=0;x{if(g!==void 0)for(_ of g)_.nodes?.a?.apply()})}function Lo(t,e,n,r,s,i,a,l){var o=a&Z?a&El?An(n):Xi(n,!1,!1):null,c=a&ue?An(s):null;return{v:o,i:c,e:it(()=>(i(e,o??n,c??s,l),()=>{t.delete(r)}))}}function yr(t,e,n){if(t.nodes)for(var r=t.nodes.start,s=t.nodes.end,i=e&&!(e.f&qt)?e.nodes.start:n;r!==null;){var a=_t(r);if(i.before(r),r===s)return;r=a}}function un(t,e,n){e===null?t.effect.first=n:e.next=n,n===null?t.effect.last=e:n.prev=e}function Oo(t,e,n=!1,r=!1,s=!1){var i=t,a="";bt(()=>{var l=P;if(a===(a=e()??"")){C&&Zn();return}if(l.nodes!==null&&(fa(l.nodes.start,l.nodes.end),l.nodes=null),a!==""){if(C){L.data;for(var o=Zn(),c=o;o!==null&&(o.nodeType!==Tn||o.data!=="");)c=o,o=_t(o);if(o===null)throw gr(),xn;wt(L,c),i=Ee(o);return}var u=a+"";n?u=`${u}`:r&&(u=`${u}`);var g=Ys(u);if((n||r)&&(g=Le(g)),wt(Le(g),g.lastChild),n||r)for(;Le(g);)i.before(Le(g));else i.before(g)}})}function Do(t,e){la(()=>{var n=t.getRootNode(),r=n.host?n:n.head??n.ownerDocument.head;if(!r.querySelector("#"+e.hash)){const s=document.createElement("style");s.id=e.hash,s.textContent=e.code,r.appendChild(s)}})}const Ca=[...` +\r\f \v\uFEFF`];function Mo(t,e,n){var r=t==null?"":""+t;if(n){for(var s in n)if(n[s])r=r?r+" "+s:s;else if(r.length)for(var i=s.length,a=0;(a=r.indexOf(s,a))>=0;){var l=a+i;(a===0||Ca.includes(r[a-1]))&&(l===r.length||Ca.includes(r[l]))?r=(a===0?"":r.substring(0,a))+r.substring(l+1):a=l}}return r===""?null:r}function No(t,e){return t==null?null:String(t)}function Tr(t,e,n,r,s,i){var a=t.__className;if(C||a!==n||a===void 0){var l=Mo(n,r,i);(!C||l!==t.getAttribute("class"))&&(l==null?t.removeAttribute("class"):t.className=l),t.__className=n}else if(i&&s!==i)for(var o in i){var c=!!i[o];(s==null||c!==!!s[o])&&t.classList.toggle(o,c)}return i}function Po(t,e,n,r){var s=t.__style;if(C||s!==e){var i=No(e);(!C||i!==t.getAttribute("style"))&&(i==null?t.removeAttribute("style"):t.style.cssText=i),t.__style=e}return r}function Fo(t,e,n=e){var r=new WeakSet;co(t,"input",async s=>{var i=s?t.defaultValue:t.value;if(i=Xs(t)?Ks(i):i,n(i),Y!==null&&r.add(Y),await bo(),i!==(i=e())){var a=t.selectionStart,l=t.selectionEnd,o=t.value.length;if(t.value=i??"",l!==null){var c=t.value.length;a===l&&l===o&&c>o?(t.selectionStart=c,t.selectionEnd=c):(t.selectionStart=a,t.selectionEnd=Math.min(l,c))}}}),(C&&t.defaultValue!==t.value||qs(e)==null&&t.value)&&(n(Xs(t)?Ks(t.value):t.value),Y!==null&&r.add(Y)),is(()=>{var s=e();if(t===document.activeElement){var i=es??Y;if(r.has(i))return}Xs(t)&&s===Ks(t.value)||t.type==="date"&&!s&&!t.value||s!==t.value&&(t.value=s??"")})}function Xs(t){var e=t.type;return e==="number"||e==="range"}function Ks(t){return t===""?null:+t}function La(t,e){return t===e||t?.[Xr]===e}function Oa(t={},e,n,r){return la(()=>{var s,i;return is(()=>{s=i,i=[],qs(()=>{t!==n(...i)&&(e(t,...i),s&&La(n(...s),t)&&e(null,...s))})}),()=>{Xn(()=>{i&&La(n(...i),t)&&e(null,...i)})}}),t}function os(t,e,n,r){var s=r,i=!0,a=()=>(i&&(i=!1,s=r),s),l;l=t[e],l===void 0&&r!==void 0&&(l=a());var o;o=()=>{var p=t[e];return p===void 0?a():(i=!0,p)};var c=!1,u=rs(()=>(c=!1,o())),g=P;return function(p,v){if(arguments.length>0){const b=v?d(u):p;return T(u,b),c=!0,s!==void 0&&(s=b),p}return In&&c||g.f&Wt?u.v:d(u)}}function Uo(t){return new Ho(t)}class Ho{constructor(e){D(this,Qt);D(this,ft);var n=new Map,r=(i,a)=>{var l=Xi(a,!1,!1);return n.set(i,l),l};const s=new Proxy({...e.props||{},$$events:{}},{get(i,a){return d(n.get(a)??r(a,Reflect.get(i,a)))},has(i,a){return a===Ol?!0:(d(n.get(a)??r(a,Reflect.get(i,a))),Reflect.has(i,a))},set(i,a,l){return T(n.get(a)??r(a,l),l),Reflect.set(i,a,l)}});S(this,ft,(e.hydrate?Ao:za)(e.component,{target:e.target,anchor:e.anchor,props:s,context:e.context,intro:e.intro??!1,recover:e.recover})),(!e?.props?.$$host||e.sync===!1)&&Qn(),S(this,Qt,s.$$events);for(const i of Object.keys(h(this,ft)))i==="$set"||i==="$destroy"||i==="$on"||Yr(this,i,{get(){return h(this,ft)[i]},set(a){h(this,ft)[i]=a},enumerable:!0});h(this,ft).$set=i=>{Object.assign(s,i)},h(this,ft).$destroy=()=>{zo(h(this,ft))}}$set(e){h(this,ft).$set(e)}$on(e,n){h(this,Qt)[e]=h(this,Qt)[e]||[];const r=(...s)=>n.call(this,...s);return h(this,Qt)[e].push(r),()=>{h(this,Qt)[e]=h(this,Qt)[e].filter(s=>s!==r)}}$destroy(){h(this,ft).$destroy()}}Qt=new WeakMap,ft=new WeakMap;let Da;typeof HTMLElement=="function"&&(Da=class extends HTMLElement{constructor(e,n,r){super();E(this,"$$ctor");E(this,"$$s");E(this,"$$c");E(this,"$$cn",!1);E(this,"$$d",{});E(this,"$$r",!1);E(this,"$$p_d",{});E(this,"$$l",{});E(this,"$$l_u",new Map);E(this,"$$me");this.$$ctor=e,this.$$s=n,r&&this.attachShadow({mode:"open"})}addEventListener(e,n,r){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const s=this.$$c.$on(e,n);this.$$l_u.set(n,s)}super.addEventListener(e,n,r)}removeEventListener(e,n,r){if(super.removeEventListener(e,n,r),this.$$c){const s=this.$$l_u.get(n);s&&(s(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(s){return i=>{const a=document.createElement("slot");s!=="default"&&(a.name=s),G(i,a)}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},r=Bo(this);for(const s of this.$$s)s in r&&(s==="default"&&!this.$$d.children?(this.$$d.children=e(s),n.default=!0):n[s]=e(s));for(const s of this.attributes){const i=this.$$g_p(s.name);i in this.$$d||(this.$$d[i]=cs(i,s.value,this.$$p_d,"toProp"))}for(const s in this.$$p_d)!(s in this.$$d)&&this[s]!==void 0&&(this.$$d[s]=this[s],delete this[s]);this.$$c=Uo({component:this.$$ctor,target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$host:this}}),this.$$me=ho(()=>{is(()=>{this.$$r=!0;for(const s of jr(this.$$c)){if(!this.$$p_d[s]?.reflect)continue;this.$$d[s]=this.$$c[s];const i=cs(s,this.$$d[s],this.$$p_d,"toAttribute");i==null?this.removeAttribute(this.$$p_d[s].attribute||s):this.setAttribute(this.$$p_d[s].attribute||s,i)}this.$$r=!1})});for(const s in this.$$l)for(const i of this.$$l[s]){const a=this.$$c.$on(s,i);this.$$l_u.set(i,a)}this.$$l={}}}attributeChangedCallback(e,n,r){this.$$r||(e=this.$$g_p(e),this.$$d[e]=cs(e,r,this.$$p_d,"toProp"),this.$$c?.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{!this.$$cn&&this.$$c&&(this.$$c.$destroy(),this.$$me(),this.$$c=void 0)})}$$g_p(e){return jr(this.$$p_d).find(n=>this.$$p_d[n].attribute===e||!this.$$p_d[n].attribute&&n.toLowerCase()===e)||e}});function cs(t,e,n,r){const s=n[t]?.type;if(e=s==="Boolean"&&typeof e!="boolean"?e!=null:e,!r||!n[t])return e;if(r==="toAttribute")switch(s){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(s){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function Bo(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}function Go(t,e,n,r,s,i){let a=class extends Da{constructor(){super(t,n,s),this.$$p_d=e}static get observedAttributes(){return jr(e).map(l=>(e[l].attribute||l).toLowerCase())}};return jr(e).forEach(l=>{Yr(a.prototype,l,{get(){return this.$$c&&l in this.$$c?this.$$c[l]:this.$$d[l]},set(o){o=cs(l,o,e),this.$$d[l]=o;var c=this.$$c;if(c){var u=qn(c,l)?.get;u?c[l]=o:c.$set({[l]:o})}}})}),r.forEach(l=>{Yr(a.prototype,l,{get(){return this.$$c?.[l]}})}),t.element=a,a}const Ma="lc_chatbot:";function Er(t,e=null){try{const n=localStorage.getItem(Ma+t);return n?JSON.parse(n):e}catch(n){return console.warn(`[lc-chatbot] Failed to read ${t} from storage:`,n),e}}function hn(t,e){try{localStorage.setItem(Ma+t,JSON.stringify(e))}catch(n){console.warn(`[lc-chatbot] Failed to write ${t} to storage:`,n)}}const Ke={SIZE:"size",SESSION:"session",DRAFT:"draft",UI:"ui",MESSAGES:"messages"},Wo=30;function qo(){return"sess_"+crypto.randomUUID()}function Na(){return"msg_"+crypto.randomUUID()}function jo(t){if(!t)return!0;const e=new Date(t).getTime();return(Date.now()-e)/(1e3*60)>Wo}function Yo(t=!1){const e=Er(Ke.SESSION,null);if(t||!e||jo(e.lastActivity)){const n=qo(),r={sessionId:n,lastActivity:new Date().toISOString()};return hn(Ke.SESSION,r),{sessionId:n,isNew:!0}}return{sessionId:e.sessionId,isNew:!1}}function Zo(t){hn(Ke.SESSION,{sessionId:t,lastActivity:new Date().toISOString()})}const Vo="1.0.0";async function Xo(t,e,n,r,s={}){const i=Na(),a=new Date().toISOString(),l={userId:e,sessionId:n,messageId:i,timestamp:a,text:r,context:{pageUrl:window.location.href,locale:navigator.language||"en",clientVersion:Vo}},o=await fetch(`${t}/chat/stream`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!o.ok){const v=new Error(`Chat request failed: ${o.status}`);throw v.status=o.status,v}const c=o.body.getReader(),u=new TextDecoder;let g="",p=null;for(;;){const{done:v,value:b}=await c.read();if(v)break;g+=u.decode(b,{stream:!0});const R=g.split(` +`);g=R.pop()||"";let _=null,x="";for(const U of R)if(U.startsWith("event: "))_=U.slice(7).trim();else if(U.startsWith("data: ")){if(x=U.slice(6),_&&x)try{const H=JSON.parse(x);_==="progress"&&s.onProgress?s.onProgress(H):_==="message"?(p={messageId:H.messageId,sessionId:H.sessionId,timestamp:H.timestamp,markdown:H.markdown,toolCalls:H.toolCalls,stats:H.stats},s.onMessage&&s.onMessage(p)):_==="error"&&s.onError&&s.onError(H.error)}catch(H){console.warn("[lc-chatbot] Failed to parse SSE data:",H)}_=null,x=""}else U.startsWith(":")||U===""&&(_=null,x="")}if(!p)throw new Error("Stream ended without message");return p}async function Pa(t,e,n,r=null,s=20){const i=new URLSearchParams({userId:e,sessionId:n,limit:String(s)});r&&i.set("before",r);const a=await fetch(`${t}/history?${i}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!a.ok){const o=new Error(`History request failed: ${a.status}`);throw o.status=a.status,o}const l=await a.json();return{messages:l.messages||[],hasMore:l.hasMore??!1}}function Qs(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Ln=Qs();function Fa(t){Ln=t}var Sr={exec:()=>null};function W(t,e=""){let n=typeof t=="string"?t:t.source;const r={replace:(s,i)=>{let a=typeof i=="string"?i:i.source;return a=a.replace(Me.caret,"$1"),n=n.replace(s,a),r},getRegex:()=>new RegExp(n,e)};return r}var Me={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:/^/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^$/,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:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i")},Ko=/^(?:[ \t]*(?:\n|$))+/,Qo=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Jo=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Ar=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,ec=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Js=/(?:[*+-]|\d{1,9}[.)])/,Ua=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Ha=W(Ua).replace(/bull/g,Js).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(),tc=W(Ua).replace(/bull/g,Js).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(),ei=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,nc=/^[^\n]+/,ti=/(?!\s*\])(?:\\.|[^\[\]\\])+/,rc=W(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ti).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),sc=W(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Js).getRegex(),fs="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",ni=/|$))/,ic=W("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|\\n*|$)|\\n*|$)|)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",ni).replace("tag",fs).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ba=W(ei).replace("hr",Ar).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",")|<(?:script|pre|style|textarea|!--)").replace("tag",fs).getRegex(),ac=W(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ba).getRegex(),ri={blockquote:ac,code:Qo,def:rc,fences:Jo,heading:ec,hr:Ar,html:ic,lheading:Ha,list:sc,newline:Ko,paragraph:Ba,table:Sr,text:nc},Ga=W("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Ar).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",")|<(?:script|pre|style|textarea|!--)").replace("tag",fs).getRegex(),lc={...ri,lheading:tc,table:Ga,paragraph:W(ei).replace("hr",Ar).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Ga).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",fs).getRegex()},oc={...ri,html:W(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ni).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:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Sr,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:W(ei).replace("hr",Ar).replace("heading",` *#{1,6} *[^ +]`).replace("lheading",Ha).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},cc=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,fc=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Wa=/^( {2,}|\\)\n(?!\s*$)/,uc=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\]*?>/g,Ya=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,vc=W(Ya,"u").replace(/punct/g,us).getRegex(),mc=W(Ya,"u").replace(/punct/g,ja).getRegex(),Za="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",_c=W(Za,"gu").replace(/notPunctSpace/g,qa).replace(/punctSpace/g,si).replace(/punct/g,us).getRegex(),bc=W(Za,"gu").replace(/notPunctSpace/g,dc).replace(/punctSpace/g,pc).replace(/punct/g,ja).getRegex(),wc=W("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,qa).replace(/punctSpace/g,si).replace(/punct/g,us).getRegex(),xc=W(/\\(punct)/,"gu").replace(/punct/g,us).getRegex(),kc=W(/^<(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(),yc=W(ni).replace("(?:-->|$)","-->").getRegex(),Tc=W("^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^").replace("comment",yc).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),hs=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Ec=W(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",hs).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Va=W(/^!?\[(label)\]\[(ref)\]/).replace("label",hs).replace("ref",ti).getRegex(),Xa=W(/^!?\[(ref)\](?:\[\])?/).replace("ref",ti).getRegex(),Sc=W("reflink|nolink(?!\\()","g").replace("reflink",Va).replace("nolink",Xa).getRegex(),ii={_backpedal:Sr,anyPunctuation:xc,autolink:kc,blockSkip:gc,br:Wa,code:fc,del:Sr,emStrongLDelim:vc,emStrongRDelimAst:_c,emStrongRDelimUnd:wc,escape:cc,link:Ec,nolink:Xa,punctuation:hc,reflink:Va,reflinkSearch:Sc,tag:Tc,text:uc,url:Sr},Ac={...ii,link:W(/^!?\[(label)\]\((.*?)\)/).replace("label",hs).getRegex(),reflink:W(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",hs).getRegex()},ai={...ii,emStrongRDelimAst:bc,emStrongLDelim:mc,url:W(/^((?: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]*?(?:(?=[\\":">",'"':""","'":"'"},Ka=t=>Rc[t];function $t(t,e){if(e){if(Me.escapeTest.test(t))return t.replace(Me.escapeReplace,Ka)}else if(Me.escapeTestNoEncode.test(t))return t.replace(Me.escapeReplaceNoEncode,Ka);return t}function Qa(t){try{t=encodeURI(t).replace(Me.percentDecode,"%")}catch{return null}return t}function Ja(t,e){const n=t.replace(Me.findPipe,(i,a,l)=>{let o=!1,c=a;for(;--c>=0&&l[c]==="\\";)o=!o;return o?"|":" |"}),r=n.split(Me.splitPipe);let s=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),e)if(r.length>e)r.splice(e);else for(;r.length0?-2:-1}function el(t,e,n,r,s){const i=e.href,a=e.title||null,l=t[1].replace(s.other.outputLinkReplace,"$1");r.state.inLink=!0;const o={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:a,text:l,tokens:r.inlineTokens(l)};return r.state.inLink=!1,o}function Ic(t,e,n){const r=t.match(n.other.indentCodeCompensation);if(r===null)return e;const s=r[1];return e.split(` +`).map(i=>{const a=i.match(n.other.beginningSpace);if(a===null)return i;const[l]=a;return l.length>=s.length?i.slice(s.length):i}).join(` +`)}var ds=class{constructor(t){E(this,"options");E(this,"rules");E(this,"lexer");this.options=t||Ln}space(t){const e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){const e=this.rules.block.code.exec(t);if(e){const n=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?n:Rr(n,` +`)}}}fences(t){const e=this.rules.block.fences.exec(t);if(e){const n=e[0],r=Ic(n,e[3]||"",this.rules);return{type:"code",raw:n,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:r}}}heading(t){const e=this.rules.block.heading.exec(t);if(e){let n=e[2].trim();if(this.rules.other.endingHash.test(n)){const r=Rr(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(t){const e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:Rr(e[0],` +`)}}blockquote(t){const e=this.rules.block.blockquote.exec(t);if(e){let n=Rr(e[0],` +`).split(` +`),r="",s="";const i=[];for(;n.length>0;){let a=!1;const l=[];let o;for(o=0;o1,s={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");const i=this.rules.other.listItemRegex(n);let a=!1;for(;t;){let o=!1,c="",u="";if(!(e=i.exec(t))||this.rules.block.hr.test(t))break;c=e[0],t=t.substring(c.length);let g=e[2].split(` +`,1)[0].replace(this.rules.other.listReplaceTabs,x=>" ".repeat(3*x.length)),p=t.split(` +`,1)[0],v=!g.trim(),b=0;if(this.options.pedantic?(b=2,u=g.trimStart()):v?b=e[1].length+1:(b=e[2].search(this.rules.other.nonSpaceChar),b=b>4?1:b,u=g.slice(b),b+=e[1].length),v&&this.rules.other.blankLine.test(p)&&(c+=p+` +`,t=t.substring(p.length+1),o=!0),!o){const x=this.rules.other.nextBulletRegex(b),U=this.rules.other.hrRegex(b),H=this.rules.other.fencesBeginRegex(b),M=this.rules.other.headingBeginRegex(b),ve=this.rules.other.htmlBeginRegex(b);for(;t;){const we=t.split(` +`,1)[0];let ee;if(p=we,this.options.pedantic?(p=p.replace(this.rules.other.listReplaceNesting," "),ee=p):ee=p.replace(this.rules.other.tabCharGlobal," "),H.test(p)||M.test(p)||ve.test(p)||x.test(p)||U.test(p))break;if(ee.search(this.rules.other.nonSpaceChar)>=b||!p.trim())u+=` +`+ee.slice(b);else{if(v||g.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||H.test(g)||M.test(g)||U.test(g))break;u+=` +`+p}!v&&!p.trim()&&(v=!0),c+=we+` +`,t=t.substring(we.length+1),g=ee.slice(b)}}s.loose||(a?s.loose=!0:this.rules.other.doubleBlankLine.test(c)&&(a=!0));let R=null,_;this.options.gfm&&(R=this.rules.other.listIsTask.exec(u),R&&(_=R[0]!=="[ ] ",u=u.replace(this.rules.other.listReplaceTask,""))),s.items.push({type:"list_item",raw:c,task:!!R,checked:_,loose:!1,text:u,tokens:[]}),s.raw+=c}const l=s.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;s.raw=s.raw.trimEnd();for(let o=0;og.type==="space"),u=c.length>0&&c.some(g=>this.rules.other.anyLine.test(g.raw));s.loose=u}if(s.loose)for(let o=0;o({text:l,tokens:this.lexer.inline(l),header:!1,align:i.align[o]})));return i}}lheading(t){const e=this.rules.block.lheading.exec(t);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(t){const e=this.rules.block.paragraph.exec(t);if(e){const n=e[1].charAt(e[1].length-1)===` +`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){const e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){const e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){const e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){const e=this.rules.inline.link.exec(t);if(e){const n=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;const i=Rr(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{const i=$c(e[2],"()");if(i===-2)return;if(i>-1){const l=(e[0].indexOf("!")===0?5:4)+e[1].length+i;e[2]=e[2].substring(0,i),e[0]=e[0].substring(0,l).trim(),e[3]=""}}let r=e[2],s="";if(this.options.pedantic){const i=this.rules.other.pedanticHrefTitle.exec(r);i&&(r=i[1],s=i[3])}else s=e[3]?e[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?r=r.slice(1):r=r.slice(1,-1)),el(e,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(t,e){let n;if((n=this.rules.inline.reflink.exec(t))||(n=this.rules.inline.nolink.exec(t))){const r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),s=e[r.toLowerCase()];if(!s){const i=n[0].charAt(0);return{type:"text",raw:i,text:i}}return el(n,s,n[0],this.lexer,this.rules)}}emStrong(t,e,n=""){let r=this.rules.inline.emStrongLDelim.exec(t);if(!r||r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))return;if(!(r[1]||r[2]||"")||!n||this.rules.inline.punctuation.exec(n)){const i=[...r[0]].length-1;let a,l,o=i,c=0;const u=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(u.lastIndex=0,e=e.slice(-1*t.length+i);(r=u.exec(e))!=null;){if(a=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!a)continue;if(l=[...a].length,r[3]||r[4]){o+=l;continue}else if((r[5]||r[6])&&i%3&&!((i+l)%3)){c+=l;continue}if(o-=l,o>0)continue;l=Math.min(l,l+o+c);const g=[...r[0]][0].length,p=t.slice(0,i+r.index+g+l);if(Math.min(i,l)%2){const b=p.slice(1,-1);return{type:"em",raw:p,text:b,tokens:this.lexer.inlineTokens(b)}}const v=p.slice(2,-2);return{type:"strong",raw:p,text:v,tokens:this.lexer.inlineTokens(v)}}}}codespan(t){const e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(this.rules.other.newLineCharGlobal," ");const r=this.rules.other.nonSpaceChar.test(n),s=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&s&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:e[0],text:n}}}br(t){const e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t){const e=this.rules.inline.del.exec(t);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(t){const e=this.rules.inline.autolink.exec(t);if(e){let n,r;return e[2]==="@"?(n=e[1],r="mailto:"+n):(n=e[1],r=n),{type:"link",raw:e[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let n,r;if(e[2]==="@")n=e[0],r="mailto:"+n;else{let s;do s=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(s!==e[0]);n=e[0],e[1]==="www."?r="http://"+e[0]:r=e[0]}return{type:"link",raw:e[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(t){const e=this.rules.inline.text.exec(t);if(e){const n=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:n}}}},Vt=class Ai{constructor(e){E(this,"tokens");E(this,"options");E(this,"state");E(this,"tokenizer");E(this,"inlineQueue");this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Ln,this.options.tokenizer=this.options.tokenizer||new ds,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={other:Me,block:ps.normal,inline:zr.normal};this.options.pedantic?(n.block=ps.pedantic,n.inline=zr.pedantic):this.options.gfm&&(n.block=ps.gfm,this.options.breaks?n.inline=zr.breaks:n.inline=zr.gfm),this.tokenizer.rules=n}static get rules(){return{block:ps,inline:zr}}static lex(e,n){return new Ai(n).lex(e)}static lexInline(e,n){return new Ai(n).inlineTokens(e)}lex(e){e=e.replace(Me.carriageReturn,` +`),this.blockTokens(e,this.tokens);for(let n=0;n(s=a.call({lexer:this},e,n))?(e=e.substring(s.raw.length),n.push(s),!0):!1))continue;if(s=this.tokenizer.space(e)){e=e.substring(s.raw.length);const a=n.at(-1);s.raw.length===1&&a!==void 0?a.raw+=` +`:n.push(s);continue}if(s=this.tokenizer.code(e)){e=e.substring(s.raw.length);const a=n.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=` +`+s.raw,a.text+=` +`+s.text,this.inlineQueue.at(-1).src=a.text):n.push(s);continue}if(s=this.tokenizer.fences(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.heading(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.hr(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.blockquote(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.list(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.html(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.def(e)){e=e.substring(s.raw.length);const a=n.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=` +`+s.raw,a.text+=` +`+s.raw,this.inlineQueue.at(-1).src=a.text):this.tokens.links[s.tag]||(this.tokens.links[s.tag]={href:s.href,title:s.title});continue}if(s=this.tokenizer.table(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.lheading(e)){e=e.substring(s.raw.length),n.push(s);continue}let i=e;if(this.options.extensions?.startBlock){let a=1/0;const l=e.slice(1);let o;this.options.extensions.startBlock.forEach(c=>{o=c.call({lexer:this},l),typeof o=="number"&&o>=0&&(a=Math.min(a,o))}),a<1/0&&a>=0&&(i=e.substring(0,a+1))}if(this.state.top&&(s=this.tokenizer.paragraph(i))){const a=n.at(-1);r&&a?.type==="paragraph"?(a.raw+=` +`+s.raw,a.text+=` +`+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):n.push(s),r=i.length!==e.length,e=e.substring(s.raw.length);continue}if(s=this.tokenizer.text(e)){e=e.substring(s.raw.length);const a=n.at(-1);a?.type==="text"?(a.raw+=` +`+s.raw,a.text+=` +`+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):n.push(s);continue}if(e){const a="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}inlineTokens(e,n=[]){let r=e,s=null;if(this.tokens.links){const l=Object.keys(this.tokens.links);if(l.length>0)for(;(s=this.tokenizer.rules.inline.reflinkSearch.exec(r))!=null;)l.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(s=this.tokenizer.rules.inline.anyPunctuation.exec(r))!=null;)r=r.slice(0,s.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(s=this.tokenizer.rules.inline.blockSkip.exec(r))!=null;)r=r.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let i=!1,a="";for(;e;){i||(a=""),i=!1;let l;if(this.options.extensions?.inline?.some(c=>(l=c.call({lexer:this},e,n))?(e=e.substring(l.raw.length),n.push(l),!0):!1))continue;if(l=this.tokenizer.escape(e)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.tag(e)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.link(e)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(l.raw.length);const c=n.at(-1);l.type==="text"&&c?.type==="text"?(c.raw+=l.raw,c.text+=l.text):n.push(l);continue}if(l=this.tokenizer.emStrong(e,r,a)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.codespan(e)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.br(e)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.del(e)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.autolink(e)){e=e.substring(l.raw.length),n.push(l);continue}if(!this.state.inLink&&(l=this.tokenizer.url(e))){e=e.substring(l.raw.length),n.push(l);continue}let o=e;if(this.options.extensions?.startInline){let c=1/0;const u=e.slice(1);let g;this.options.extensions.startInline.forEach(p=>{g=p.call({lexer:this},u),typeof g=="number"&&g>=0&&(c=Math.min(c,g))}),c<1/0&&c>=0&&(o=e.substring(0,c+1))}if(l=this.tokenizer.inlineText(o)){e=e.substring(l.raw.length),l.raw.slice(-1)!=="_"&&(a=l.raw.slice(-1)),i=!0;const c=n.at(-1);c?.type==="text"?(c.raw+=l.raw,c.text+=l.text):n.push(l);continue}if(e){const c="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(c);break}else throw new Error(c)}}return n}},gs=class{constructor(t){E(this,"options");E(this,"parser");this.options=t||Ln}space(t){return""}code({text:t,lang:e,escaped:n}){const r=(e||"").match(Me.notSpaceStart)?.[0],s=t.replace(Me.endingNewline,"")+` +`;return r?'
'+(n?s:$t(s,!0))+`
+`:"
"+(n?s:$t(s,!0))+`
+`}blockquote({tokens:t}){return`
+${this.parser.parse(t)}
+`}html({text:t}){return t}heading({tokens:t,depth:e}){return`${this.parser.parseInline(t)} +`}hr(t){return`
+`}list(t){const e=t.ordered,n=t.start;let r="";for(let a=0;a +`+r+" +`}listitem(t){let e="";if(t.task){const n=this.checkbox({checked:!!t.checked});t.loose?t.tokens[0]?.type==="paragraph"?(t.tokens[0].text=n+" "+t.tokens[0].text,t.tokens[0].tokens&&t.tokens[0].tokens.length>0&&t.tokens[0].tokens[0].type==="text"&&(t.tokens[0].tokens[0].text=n+" "+$t(t.tokens[0].tokens[0].text),t.tokens[0].tokens[0].escaped=!0)):t.tokens.unshift({type:"text",raw:n+" ",text:n+" ",escaped:!0}):e+=n+" "}return e+=this.parser.parse(t.tokens,!!t.loose),`
  • ${e}
  • +`}checkbox({checked:t}){return"'}paragraph({tokens:t}){return`

    ${this.parser.parseInline(t)}

    +`}table(t){let e="",n="";for(let s=0;s${r}`),` + +`+e+` +`+r+`
    +`}tablerow({text:t}){return` +${t} +`}tablecell(t){const e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+` +`}strong({tokens:t}){return`${this.parser.parseInline(t)}`}em({tokens:t}){return`${this.parser.parseInline(t)}`}codespan({text:t}){return`${$t(t,!0)}`}br(t){return"
    "}del({tokens:t}){return`${this.parser.parseInline(t)}`}link({href:t,title:e,tokens:n}){const r=this.parser.parseInline(n),s=Qa(t);if(s===null)return r;t=s;let i='
    ",i}image({href:t,title:e,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));const s=Qa(t);if(s===null)return $t(n);t=s;let i=`${n}{const a=s[i].flat(1/0);n=n.concat(this.walkTokens(a,e))}):s.tokens&&(n=n.concat(this.walkTokens(s.tokens,e)))}}return n}use(...t){const e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{const r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s){const i=e.renderers[s.name];i?e.renderers[s.name]=function(...a){let l=s.renderer.apply(this,a);return l===!1&&(l=i.apply(this,a)),l}:e.renderers[s.name]=s.renderer}if("tokenizer"in s){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const i=e[s.level];i?i.unshift(s.tokenizer):e[s.level]=[s.tokenizer],s.start&&(s.level==="block"?e.startBlock?e.startBlock.push(s.start):e.startBlock=[s.start]:s.level==="inline"&&(e.startInline?e.startInline.push(s.start):e.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(e.childTokens[s.name]=s.childTokens)}),r.extensions=e),n.renderer){const s=this.defaults.renderer||new gs(this.defaults);for(const i in n.renderer){if(!(i in s))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;const a=i,l=n.renderer[a],o=s[a];s[a]=(...c)=>{let u=l.apply(s,c);return u===!1&&(u=o.apply(s,c)),u||""}}r.renderer=s}if(n.tokenizer){const s=this.defaults.tokenizer||new ds(this.defaults);for(const i in n.tokenizer){if(!(i in s))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;const a=i,l=n.tokenizer[a],o=s[a];s[a]=(...c)=>{let u=l.apply(s,c);return u===!1&&(u=o.apply(s,c)),u}}r.tokenizer=s}if(n.hooks){const s=this.defaults.hooks||new vs;for(const i in n.hooks){if(!(i in s))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;const a=i,l=n.hooks[a],o=s[a];vs.passThroughHooks.has(i)?s[a]=c=>{if(this.defaults.async)return Promise.resolve(l.call(s,c)).then(g=>o.call(s,g));const u=l.call(s,c);return o.call(s,u)}:s[a]=(...c)=>{let u=l.apply(s,c);return u===!1&&(u=o.apply(s,c)),u}}r.hooks=s}if(n.walkTokens){const s=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(a){let l=[];return l.push(i.call(this,a)),s&&(l=l.concat(s.call(this,a))),l}}this.defaults={...this.defaults,...r}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return Vt.lex(t,e??this.defaults)}parser(t,e){return Xt.parse(t,e??this.defaults)}parseMarkdown(t){return(n,r)=>{const s={...r},i={...this.defaults,...s},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&s.async===!1)return a(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 n>"u"||n===null)return a(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return a(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));i.hooks&&(i.hooks.options=i,i.hooks.block=t);const l=i.hooks?i.hooks.provideLexer():t?Vt.lex:Vt.lexInline,o=i.hooks?i.hooks.provideParser():t?Xt.parse:Xt.parseInline;if(i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(n):n).then(c=>l(c,i)).then(c=>i.hooks?i.hooks.processAllTokens(c):c).then(c=>i.walkTokens?Promise.all(this.walkTokens(c,i.walkTokens)).then(()=>c):c).then(c=>o(c,i)).then(c=>i.hooks?i.hooks.postprocess(c):c).catch(a);try{i.hooks&&(n=i.hooks.preprocess(n));let c=l(n,i);i.hooks&&(c=i.hooks.processAllTokens(c)),i.walkTokens&&this.walkTokens(c,i.walkTokens);let u=o(c,i);return i.hooks&&(u=i.hooks.postprocess(u)),u}catch(c){return a(c)}}}onError(t,e){return n=>{if(n.message+=` +Please report this to https://github.com/markedjs/marked.`,t){const r="

    An error occurred:

    "+$t(n.message+"",!0)+"
    ";return e?Promise.resolve(r):r}if(e)return Promise.reject(n);throw n}}},On=new Cc;function F(t,e){return On.parse(t,e)}F.options=F.setOptions=function(t){return On.setOptions(t),F.defaults=On.defaults,Fa(F.defaults),F},F.getDefaults=Qs,F.defaults=Ln,F.use=function(...t){return On.use(...t),F.defaults=On.defaults,Fa(F.defaults),F},F.walkTokens=function(t,e){return On.walkTokens(t,e)},F.parseInline=On.parseInline,F.Parser=Xt,F.parser=Xt.parse,F.Renderer=gs,F.TextRenderer=li,F.Lexer=Vt,F.lexer=Vt.lex,F.Tokenizer=ds,F.Hooks=vs,F.parse=F,F.options,F.setOptions,F.use,F.walkTokens,F.parseInline,Xt.parse,Vt.lex;/*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE */const{entries:tl,setPrototypeOf:nl,isFrozen:Lc,getPrototypeOf:Oc,getOwnPropertyDescriptor:Dc}=Object;let{freeze:Ne,seal:lt,create:oi}=Object,{apply:ci,construct:fi}=typeof Reflect<"u"&&Reflect;Ne||(Ne=function(e){return e}),lt||(lt=function(e){return e}),ci||(ci=function(e,n){for(var r=arguments.length,s=new Array(r>2?r-2:0),i=2;i1?n-1:0),s=1;s1?n-1:0),s=1;s2&&arguments[2]!==void 0?arguments[2]:_s;nl&&nl(t,null);let r=e.length;for(;r--;){let s=e[r];if(typeof s=="string"){const i=n(s);i!==s&&(Lc(e)||(e[r]=i),s=i)}t[s]=!0}return t}function Hc(t){for(let e=0;e/gm),jc=lt(/\$\{[\w\W]*/gm),Yc=lt(/^data-[\-\w.\u00B7-\uFFFF]+$/),Zc=lt(/^aria-[\-\w]+$/),ol=lt(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Vc=lt(/^(?:\w+script|data):/i),Xc=lt(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),cl=lt(/^html$/i),Kc=lt(/^[a-z][.\w]*(-[.\w]+)+$/i);var fl=Object.freeze({__proto__:null,ARIA_ATTR:Zc,ATTR_WHITESPACE:Xc,CUSTOM_ELEMENT:Kc,DATA_ATTR:Yc,DOCTYPE_NAME:cl,ERB_EXPR:qc,IS_ALLOWED_URI:ol,IS_SCRIPT_OR_DATA:Vc,MUSTACHE_EXPR:Wc,TMPLIT_EXPR:jc});const Or={element:1,text:3,progressingInstruction:7,comment:8,document:9},Qc=function(){return typeof window>"u"?null:window},Jc=function(e,n){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let r=null;const s="data-tt-policy-suffix";n&&n.hasAttribute(s)&&(r=n.getAttribute(s));const i="dompurify"+(r?"#"+r:"");try{return e.createPolicy(i,{createHTML(a){return a},createScriptURL(a){return a}})}catch{return console.warn("TrustedTypes policy "+i+" could not be created."),null}},ul=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function hl(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Qc();const e=k=>hl(k);if(e.version="3.3.1",e.removed=[],!t||!t.document||t.document.nodeType!==Or.document||!t.Element)return e.isSupported=!1,e;let{document:n}=t;const r=n,s=r.currentScript,{DocumentFragment:i,HTMLTemplateElement:a,Node:l,Element:o,NodeFilter:c,NamedNodeMap:u=t.NamedNodeMap||t.MozNamedAttrMap,HTMLFormElement:g,DOMParser:p,trustedTypes:v}=t,b=o.prototype,R=Lr(b,"cloneNode"),_=Lr(b,"remove"),x=Lr(b,"nextSibling"),U=Lr(b,"childNodes"),H=Lr(b,"parentNode");if(typeof a=="function"){const k=n.createElement("template");k.content&&k.content.ownerDocument&&(n=k.content.ownerDocument)}let M,ve="";const{implementation:we,createNodeIterator:ee,createDocumentFragment:ut,getElementsByTagName:et}=n,{importNode:oe}=r;let pe=ul();e.isSupported=typeof tl=="function"&&typeof H=="function"&&we&&we.createHTMLDocument!==void 0;const{MUSTACHE_EXPR:Hn,ERB_EXPR:Fr,TMPLIT_EXPR:Jt,DATA_ATTR:lr,ARIA_ATTR:Ur,IS_SCRIPT_OR_DATA:bi,ATTR_WHITESPACE:ys,CUSTOM_ELEMENT:wi}=fl;let{IS_ALLOWED_URI:yt}=fl,ce=null;const Ts=$({},[...sl,...pi,...di,...gi,...il]);let de=null;const Es=$({},[...al,...vi,...ll,...bs]);let Q=Object.seal(oi(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),vn=null,Hr=null;const mn=Object.seal(oi(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let Ss=!0,y=!0,z=!1,I=!0,J=!1,te=!0,ze=!1,Tt=!1,en=!1,ht=!1,Mt=!1,Nt=!1,_n=!0,or=!1;const pt="user-content-";let cr=!0,Bn=!1,tn={},dt=null;const fr=$({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let As=null;const zs=$({},["audio","video","img","source","image","track"]);let ur=null;const nn=$({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Gn="http://www.w3.org/1998/Math/MathML",A="http://www.w3.org/2000/svg",q="http://www.w3.org/1999/xhtml";let gt=q,rn=!1,Wn=null;const Br=$({},[Gn,A,q],ui);let tt=$({},["mi","mo","mn","ms","mtext"]),Ue=$({},["annotation-xml"]);const sn=$({},["title","style","font","a","script"]);let ae=null;const Ye=["application/xhtml+xml","text/html"],Pt="text/html";let N=null,Re=null;const He=n.createElement("form"),Be=function(f){return f instanceof RegExp||f instanceof Function},vt=function(){let f=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(Re&&Re===f)){if((!f||typeof f!="object")&&(f={}),f=It(f),ae=Ye.indexOf(f.PARSER_MEDIA_TYPE)===-1?Pt:f.PARSER_MEDIA_TYPE,N=ae==="application/xhtml+xml"?ui:_s,ce=xt(f,"ALLOWED_TAGS")?$({},f.ALLOWED_TAGS,N):Ts,de=xt(f,"ALLOWED_ATTR")?$({},f.ALLOWED_ATTR,N):Es,Wn=xt(f,"ALLOWED_NAMESPACES")?$({},f.ALLOWED_NAMESPACES,ui):Br,ur=xt(f,"ADD_URI_SAFE_ATTR")?$(It(nn),f.ADD_URI_SAFE_ATTR,N):nn,As=xt(f,"ADD_DATA_URI_TAGS")?$(It(zs),f.ADD_DATA_URI_TAGS,N):zs,dt=xt(f,"FORBID_CONTENTS")?$({},f.FORBID_CONTENTS,N):fr,vn=xt(f,"FORBID_TAGS")?$({},f.FORBID_TAGS,N):It({}),Hr=xt(f,"FORBID_ATTR")?$({},f.FORBID_ATTR,N):It({}),tn=xt(f,"USE_PROFILES")?f.USE_PROFILES:!1,Ss=f.ALLOW_ARIA_ATTR!==!1,y=f.ALLOW_DATA_ATTR!==!1,z=f.ALLOW_UNKNOWN_PROTOCOLS||!1,I=f.ALLOW_SELF_CLOSE_IN_ATTR!==!1,J=f.SAFE_FOR_TEMPLATES||!1,te=f.SAFE_FOR_XML!==!1,ze=f.WHOLE_DOCUMENT||!1,ht=f.RETURN_DOM||!1,Mt=f.RETURN_DOM_FRAGMENT||!1,Nt=f.RETURN_TRUSTED_TYPE||!1,en=f.FORCE_BODY||!1,_n=f.SANITIZE_DOM!==!1,or=f.SANITIZE_NAMED_PROPS||!1,cr=f.KEEP_CONTENT!==!1,Bn=f.IN_PLACE||!1,yt=f.ALLOWED_URI_REGEXP||ol,gt=f.NAMESPACE||q,tt=f.MATHML_TEXT_INTEGRATION_POINTS||tt,Ue=f.HTML_INTEGRATION_POINTS||Ue,Q=f.CUSTOM_ELEMENT_HANDLING||{},f.CUSTOM_ELEMENT_HANDLING&&Be(f.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Q.tagNameCheck=f.CUSTOM_ELEMENT_HANDLING.tagNameCheck),f.CUSTOM_ELEMENT_HANDLING&&Be(f.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Q.attributeNameCheck=f.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),f.CUSTOM_ELEMENT_HANDLING&&typeof f.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(Q.allowCustomizedBuiltInElements=f.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),J&&(y=!1),Mt&&(ht=!0),tn&&(ce=$({},il),de=[],tn.html===!0&&($(ce,sl),$(de,al)),tn.svg===!0&&($(ce,pi),$(de,vi),$(de,bs)),tn.svgFilters===!0&&($(ce,di),$(de,vi),$(de,bs)),tn.mathMl===!0&&($(ce,gi),$(de,ll),$(de,bs))),f.ADD_TAGS&&(typeof f.ADD_TAGS=="function"?mn.tagCheck=f.ADD_TAGS:(ce===Ts&&(ce=It(ce)),$(ce,f.ADD_TAGS,N))),f.ADD_ATTR&&(typeof f.ADD_ATTR=="function"?mn.attributeCheck=f.ADD_ATTR:(de===Es&&(de=It(de)),$(de,f.ADD_ATTR,N))),f.ADD_URI_SAFE_ATTR&&$(ur,f.ADD_URI_SAFE_ATTR,N),f.FORBID_CONTENTS&&(dt===fr&&(dt=It(dt)),$(dt,f.FORBID_CONTENTS,N)),f.ADD_FORBID_CONTENTS&&(dt===fr&&(dt=It(dt)),$(dt,f.ADD_FORBID_CONTENTS,N)),cr&&(ce["#text"]=!0),ze&&$(ce,["html","head","body"]),ce.table&&($(ce,["tbody"]),delete vn.tbody),f.TRUSTED_TYPES_POLICY){if(typeof f.TRUSTED_TYPES_POLICY.createHTML!="function")throw Cr('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof f.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Cr('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');M=f.TRUSTED_TYPES_POLICY,ve=M.createHTML("")}else M===void 0&&(M=Jc(v,s)),M!==null&&typeof ve=="string"&&(ve=M.createHTML(""));Ne&&Ne(f),Re=f}},Ft=$({},[...pi,...di,...Bc]),bn=$({},[...gi,...Gc]),V=function(f){let m=H(f);(!m||!m.tagName)&&(m={namespaceURI:gt,tagName:"template"});const w=_s(f.tagName),ne=_s(m.tagName);return Wn[f.namespaceURI]?f.namespaceURI===A?m.namespaceURI===q?w==="svg":m.namespaceURI===Gn?w==="svg"&&(ne==="annotation-xml"||tt[ne]):!!Ft[w]:f.namespaceURI===Gn?m.namespaceURI===q?w==="math":m.namespaceURI===A?w==="math"&&Ue[ne]:!!bn[w]:f.namespaceURI===q?m.namespaceURI===A&&!Ue[ne]||m.namespaceURI===Gn&&!tt[ne]?!1:!bn[w]&&(sn[w]||!Ft[w]):!!(ae==="application/xhtml+xml"&&Wn[f.namespaceURI]):!1},B=function(f){$r(e.removed,{element:f});try{H(f).removeChild(f)}catch{_(f)}},me=function(f,m){try{$r(e.removed,{attribute:m.getAttributeNode(f),from:m})}catch{$r(e.removed,{attribute:null,from:m})}if(m.removeAttribute(f),f==="is")if(ht||Mt)try{B(m)}catch{}else try{m.setAttribute(f,"")}catch{}},Ut=function(f){let m=null,w=null;if(en)f=""+f;else{const fe=hi(f,/^[\r\n\t ]+/);w=fe&&fe[0]}ae==="application/xhtml+xml"&>===q&&(f=''+f+"");const ne=M?M.createHTML(f):f;if(gt===q)try{m=new p().parseFromString(ne,ae)}catch{}if(!m||!m.documentElement){m=we.createDocument(gt,"template",null);try{m.documentElement.innerHTML=rn?ve:ne}catch{}}const Ce=m.body||m.documentElement;return f&&w&&Ce.insertBefore(n.createTextNode(w),Ce.childNodes[0]||null),gt===q?et.call(m,ze?"html":"body")[0]:ze?m.documentElement:Ce},ge=function(f){return ee.call(f.ownerDocument||f,f,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},xe=function(f){return f instanceof g&&(typeof f.nodeName!="string"||typeof f.textContent!="string"||typeof f.removeChild!="function"||!(f.attributes instanceof u)||typeof f.removeAttribute!="function"||typeof f.setAttribute!="function"||typeof f.namespaceURI!="string"||typeof f.insertBefore!="function"||typeof f.hasChildNodes!="function")},wn=function(f){return typeof l=="function"&&f instanceof l};function $e(k,f,m){ms(k,w=>{w.call(e,f,m,Re)})}const hr=function(f){let m=null;if($e(pe.beforeSanitizeElements,f,null),xe(f))return B(f),!0;const w=N(f.nodeName);if($e(pe.uponSanitizeElement,f,{tagName:w,allowedTags:ce}),te&&f.hasChildNodes()&&!wn(f.firstElementChild)&&Pe(/<[/\w!]/g,f.innerHTML)&&Pe(/<[/\w!]/g,f.textContent)||f.nodeType===Or.progressingInstruction||te&&f.nodeType===Or.comment&&Pe(/<[/\w]/g,f.data))return B(f),!0;if(!(mn.tagCheck instanceof Function&&mn.tagCheck(w))&&(!ce[w]||vn[w])){if(!vn[w]&&Ht(w)&&(Q.tagNameCheck instanceof RegExp&&Pe(Q.tagNameCheck,w)||Q.tagNameCheck instanceof Function&&Q.tagNameCheck(w)))return!1;if(cr&&!dt[w]){const ne=H(f)||f.parentNode,Ce=U(f)||f.childNodes;if(Ce&&ne){const fe=Ce.length;for(let Ze=fe-1;Ze>=0;--Ze){const an=R(Ce[Ze],!0);an.__removalCount=(f.__removalCount||0)+1,ne.insertBefore(an,x(f))}}}return B(f),!0}return f instanceof o&&!V(f)||(w==="noscript"||w==="noembed"||w==="noframes")&&Pe(/<\/no(script|embed|frames)/i,f.innerHTML)?(B(f),!0):(J&&f.nodeType===Or.text&&(m=f.textContent,ms([Hn,Fr,Jt],ne=>{m=Ir(m,ne," ")}),f.textContent!==m&&($r(e.removed,{element:f.cloneNode()}),f.textContent=m)),$e(pe.afterSanitizeElements,f,null),!1)},Ie=function(f,m,w){if(_n&&(m==="id"||m==="name")&&(w in n||w in He))return!1;if(!(y&&!Hr[m]&&Pe(lr,m))){if(!(Ss&&Pe(Ur,m))){if(!(mn.attributeCheck instanceof Function&&mn.attributeCheck(m,f))){if(!de[m]||Hr[m]){if(!(Ht(f)&&(Q.tagNameCheck instanceof RegExp&&Pe(Q.tagNameCheck,f)||Q.tagNameCheck instanceof Function&&Q.tagNameCheck(f))&&(Q.attributeNameCheck instanceof RegExp&&Pe(Q.attributeNameCheck,m)||Q.attributeNameCheck instanceof Function&&Q.attributeNameCheck(m,f))||m==="is"&&Q.allowCustomizedBuiltInElements&&(Q.tagNameCheck instanceof RegExp&&Pe(Q.tagNameCheck,w)||Q.tagNameCheck instanceof Function&&Q.tagNameCheck(w))))return!1}else if(!ur[m]){if(!Pe(yt,Ir(w,ys,""))){if(!((m==="src"||m==="xlink:href"||m==="href")&&f!=="script"&&Pc(w,"data:")===0&&As[f])){if(!(z&&!Pe(bi,Ir(w,ys,"")))){if(w)return!1}}}}}}}return!0},Ht=function(f){return f!=="annotation-xml"&&hi(f,wi)},vl=function(f){$e(pe.beforeSanitizeAttributes,f,null);const{attributes:m}=f;if(!m||xe(f))return;const w={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:de,forceKeepAttr:void 0};let ne=m.length;for(;ne--;){const Ce=m[ne],{name:fe,namespaceURI:Ze,value:an}=Ce,pr=N(fe),xi=an;let ke=fe==="value"?xi:Fc(xi);if(w.attrName=pr,w.attrValue=ke,w.keepAttr=!0,w.forceKeepAttr=void 0,$e(pe.uponSanitizeAttribute,f,w),ke=w.attrValue,or&&(pr==="id"||pr==="name")&&(me(fe,f),ke=pt+ke),te&&Pe(/((--!?|])>)|<\/(style|title|textarea)/i,ke)){me(fe,f);continue}if(pr==="attributename"&&hi(ke,"href")){me(fe,f);continue}if(w.forceKeepAttr)continue;if(!w.keepAttr){me(fe,f);continue}if(!I&&Pe(/\/>/i,ke)){me(fe,f);continue}J&&ms([Hn,Fr,Jt],_l=>{ke=Ir(ke,_l," ")});const ml=N(f.nodeName);if(!Ie(ml,pr,ke)){me(fe,f);continue}if(M&&typeof v=="object"&&typeof v.getAttributeType=="function"&&!Ze)switch(v.getAttributeType(ml,pr)){case"TrustedHTML":{ke=M.createHTML(ke);break}case"TrustedScriptURL":{ke=M.createScriptURL(ke);break}}if(ke!==xi)try{Ze?f.setAttributeNS(Ze,fe,ke):f.setAttribute(fe,ke),xe(f)?B(f):rl(e.removed)}catch{me(fe,f)}}$e(pe.afterSanitizeAttributes,f,null)},Af=function k(f){let m=null;const w=ge(f);for($e(pe.beforeSanitizeShadowDOM,f,null);m=w.nextNode();)$e(pe.uponSanitizeShadowNode,m,null),hr(m),vl(m),m.content instanceof i&&k(m.content);$e(pe.afterSanitizeShadowDOM,f,null)};return e.sanitize=function(k){let f=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},m=null,w=null,ne=null,Ce=null;if(rn=!k,rn&&(k=""),typeof k!="string"&&!wn(k))if(typeof k.toString=="function"){if(k=k.toString(),typeof k!="string")throw Cr("dirty is not a string, aborting")}else throw Cr("toString is not a function");if(!e.isSupported)return k;if(Tt||vt(f),e.removed=[],typeof k=="string"&&(Bn=!1),Bn){if(k.nodeName){const an=N(k.nodeName);if(!ce[an]||vn[an])throw Cr("root node is forbidden and cannot be sanitized in-place")}}else if(k instanceof l)m=Ut(""),w=m.ownerDocument.importNode(k,!0),w.nodeType===Or.element&&w.nodeName==="BODY"||w.nodeName==="HTML"?m=w:m.appendChild(w);else{if(!ht&&!J&&!ze&&k.indexOf("<")===-1)return M&&Nt?M.createHTML(k):k;if(m=Ut(k),!m)return ht?null:Nt?ve:""}m&&en&&B(m.firstChild);const fe=ge(Bn?k:m);for(;ne=fe.nextNode();)hr(ne),vl(ne),ne.content instanceof i&&Af(ne.content);if(Bn)return k;if(ht){if(Mt)for(Ce=ut.call(m.ownerDocument);m.firstChild;)Ce.appendChild(m.firstChild);else Ce=m;return(de.shadowroot||de.shadowrootmode)&&(Ce=oe.call(r,Ce,!0)),Ce}let Ze=ze?m.outerHTML:m.innerHTML;return ze&&ce["!doctype"]&&m.ownerDocument&&m.ownerDocument.doctype&&m.ownerDocument.doctype.name&&Pe(cl,m.ownerDocument.doctype.name)&&(Ze=" +`+Ze),J&&ms([Hn,Fr,Jt],an=>{Ze=Ir(Ze,an," ")}),M&&Nt?M.createHTML(Ze):Ze},e.setConfig=function(){let k=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};vt(k),Tt=!0},e.clearConfig=function(){Re=null,Tt=!1},e.isValidAttribute=function(k,f,m){Re||vt({});const w=N(k),ne=N(f);return Ie(w,ne,m)},e.addHook=function(k,f){typeof f=="function"&&$r(pe[k],f)},e.removeHook=function(k,f){if(f!==void 0){const m=Mc(pe[k],f);return m===-1?void 0:Nc(pe[k],m,1)[0]}return rl(pe[k])},e.removeHooks=function(k){pe[k]=[]},e.removeAllHooks=function(){pe=ul()},e}var mi=hl();F.setOptions({breaks:!0,gfm:!0});const pl=new F.Renderer;pl.link=function({href:t,title:e,text:n}){const r=e?` title="${e}"`:"";return`
    ${n}`},F.use({renderer:pl}),mi.addHook("afterSanitizeAttributes",function(t){t.tagName==="A"&&(t.setAttribute("target","_blank"),t.setAttribute("rel","noopener noreferrer"))});function ef(t){if(!t)return"";try{const e=t.replace(/<([^|>\s]+)\|([^>]+)>/g,"[$2]($1)"),n=F.parse(e);return mi.sanitize(n,{ALLOWED_TAGS:["h1","h2","h3","h4","h5","h6","p","br","hr","strong","em","b","i","u","s","del","ul","ol","li","a","code","pre","blockquote","table","thead","tbody","tr","th","td"],ALLOWED_ATTR:["href","title","target","rel","class"]})}catch(e){return console.warn("[lc-chatbot] Markdown render error:",e),mi.sanitize(t)}}function tf(t){return t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function nf(t){return new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0})}function rf(t){const e=new Date(t);return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}var sf=he(''),af=he('
    Loading messages...
    '),lf=he('

    Start a conversation

    '),of=he('
    '),cf=he('

    '),ff=he('Sending...'),uf=he(''),hf=he('
    '),pf=he('
    '),df=he('
    '),gf=Sa('',1),vf=Sa('',1),mf=he('
    '),_f=he('
    Thinking...
    '),bf=he('
    '),wf=he(' '),xf=he('
    '),kf=he('
    '),yf=he('
    '),Tf=he('

    Chat

    '),Ef=he("
    ");const Sf={hash:"svelte-z9t1fg",code:` + /* CSS Custom Properties for theming */:host {--lc-primary: #6366f1;--lc-primary-hover: #4f46e5;--lc-bg: #ffffff;--lc-bg-secondary: #f8fafc;--lc-bg-tertiary: #f1f5f9;--lc-text: #1e293b;--lc-text-secondary: #64748b;--lc-text-muted: #94a3b8;--lc-border: #e2e8f0;--lc-user-bg: #6366f1;--lc-user-text: #ffffff;--lc-assistant-bg: #f1f5f9;--lc-assistant-text: #1e293b;--lc-error: #ef4444;--lc-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);--lc-radius: 16px;--lc-radius-sm: 8px;--lc-font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;display:block;font-family:var(--lc-font);}.svelte-z9t1fg {box-sizing:border-box;margin:0;padding:0;}.lc-chatbot-container.svelte-z9t1fg {position:fixed;bottom:24px;right:24px;z-index:9999;}.lc-chatbot-container.placement-left.svelte-z9t1fg {right:auto;left:24px;} + + /* Trigger Button */.lc-chatbot-trigger.svelte-z9t1fg {display:flex;align-items:center;gap:8px;padding:12px 20px;background:var(--lc-primary);color:white;border:none;border-radius:9999px;cursor:pointer;font-family:var(--lc-font);font-size:14px;font-weight:500;box-shadow:var(--lc-shadow);transition:all 0.2s ease;}.lc-chatbot-trigger.svelte-z9t1fg:hover {background:var(--lc-primary-hover);transform:scale(1.02);}.lc-chatbot-trigger.svelte-z9t1fg:active {transform:scale(0.98);}.trigger-label.svelte-z9t1fg {font-weight:600;} + + /* Chat Panel */.lc-chatbot-panel.svelte-z9t1fg {display:flex;flex-direction:column;background:var(--lc-bg);border-radius:var(--lc-radius);box-shadow:var(--lc-shadow);overflow:hidden;position:relative;}.lc-chatbot-panel.resizing.svelte-z9t1fg {user-select:none;} + + /* Resize Handles */.resize-handle.svelte-z9t1fg {position:absolute;background:transparent;z-index:10;}.resize-n.svelte-z9t1fg, .resize-s.svelte-z9t1fg {height:8px;left:8px;right:8px;cursor:ns-resize;}.resize-e.svelte-z9t1fg, .resize-w.svelte-z9t1fg {width:8px;top:8px;bottom:8px;cursor:ew-resize;}.resize-n.svelte-z9t1fg {top:0;}.resize-s.svelte-z9t1fg {bottom:0;}.resize-e.svelte-z9t1fg {right:0;}.resize-w.svelte-z9t1fg {left:0;}.resize-ne.svelte-z9t1fg, .resize-nw.svelte-z9t1fg, .resize-se.svelte-z9t1fg, .resize-sw.svelte-z9t1fg {width:16px;height:16px;}.resize-ne.svelte-z9t1fg {top:0;right:0;cursor:nesw-resize;}.resize-nw.svelte-z9t1fg {top:0;left:0;cursor:nwse-resize;}.resize-se.svelte-z9t1fg {bottom:0;right:0;cursor:nwse-resize;}.resize-sw.svelte-z9t1fg {bottom:0;left:0;cursor:nesw-resize;} + + /* Header */.lc-chatbot-header.svelte-z9t1fg {display:flex;align-items:center;justify-content:space-between;padding:16px 20px;background:var(--lc-bg);border-bottom:1px solid var(--lc-border);}.lc-chatbot-header.svelte-z9t1fg h2:where(.svelte-z9t1fg) {font-size:16px;font-weight:600;color:var(--lc-text);}.close-btn.svelte-z9t1fg {display:flex;align-items:center;justify-content:center;width:32px;height:32px;background:transparent;border:none;border-radius:var(--lc-radius-sm);cursor:pointer;color:var(--lc-text-secondary);transition:all 0.15s ease;}.close-btn.svelte-z9t1fg:hover {background:var(--lc-bg-tertiary);color:var(--lc-text);} + + /* Message List */.lc-chatbot-messages.svelte-z9t1fg {flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:12px;background:var(--lc-bg-secondary);} + + /* Date Markers */.date-marker.svelte-z9t1fg {display:flex;align-items:center;justify-content:center;padding:8px 0;}.date-marker.svelte-z9t1fg span:where(.svelte-z9t1fg) {font-size:12px;color:var(--lc-text-muted);background:var(--lc-bg);padding:4px 12px;border-radius:9999px;border:1px solid var(--lc-border);} + + /* Messages */.message.svelte-z9t1fg {display:flex;flex-direction:column;max-width:85%; + animation: svelte-z9t1fg-fadeInUp 0.2s ease;} + + @keyframes svelte-z9t1fg-fadeInUp { + from { + opacity: 0; + transform: translateY(8px); + } + to { + opacity: 1; + transform: translateY(0); + } + }.message.user.svelte-z9t1fg {align-self:flex-end;}.message.assistant.svelte-z9t1fg {align-self:flex-start;}.message-content.svelte-z9t1fg {padding:12px 16px;border-radius:var(--lc-radius);word-wrap:break-word;}.message.user.svelte-z9t1fg .message-content:where(.svelte-z9t1fg) {background:var(--lc-user-bg);color:var(--lc-user-text);border-bottom-right-radius:4px;}.message.assistant.svelte-z9t1fg .message-content:where(.svelte-z9t1fg) {background:var(--lc-bg);color:var(--lc-assistant-text);border-bottom-left-radius:4px;border:1px solid var(--lc-border);}.message.failed.svelte-z9t1fg .message-content:where(.svelte-z9t1fg) {border:1px solid var(--lc-error);background:#fef2f2;}.message-content.svelte-z9t1fg p:where(.svelte-z9t1fg) {margin:0;line-height:1.5;} + + /* Markdown Styles */.message-content.svelte-z9t1fg h1, + .message-content.svelte-z9t1fg h2, + .message-content.svelte-z9t1fg h3, + .message-content.svelte-z9t1fg h4, + .message-content.svelte-z9t1fg h5, + .message-content.svelte-z9t1fg h6 {margin-top:12px;margin-bottom:8px;font-weight:600;line-height:1.3;}.message-content.svelte-z9t1fg h1 {font-size:1.25em;}.message-content.svelte-z9t1fg h2 {font-size:1.15em;}.message-content.svelte-z9t1fg h3 {font-size:1.05em;}.message-content.svelte-z9t1fg p {margin-bottom:8px;}.message-content.svelte-z9t1fg p:last-child {margin-bottom:0;}.message-content.svelte-z9t1fg a {color:var(--lc-primary);text-decoration:underline;}.message-content.svelte-z9t1fg ul, + .message-content.svelte-z9t1fg ol {margin:8px 0;padding-left:20px;}.message-content.svelte-z9t1fg li {margin-bottom:4px;}.message-content.svelte-z9t1fg code {font-family:'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;font-size:0.9em;background:var(--lc-bg-tertiary);padding:2px 6px;border-radius:4px;}.message-content.svelte-z9t1fg pre {margin:8px 0;padding:12px;background:#1e293b;border-radius:var(--lc-radius-sm);overflow-x:auto;}.message-content.svelte-z9t1fg pre code {background:transparent;padding:0;color:#e2e8f0;}.message-content.svelte-z9t1fg blockquote {margin:8px 0;padding-left:12px;border-left:3px solid var(--lc-primary);color:var(--lc-text-secondary);font-style:italic;}.message-meta.svelte-z9t1fg {display:flex;align-items:center;gap:8px;margin-top:4px;padding:0 4px;}.message-time.svelte-z9t1fg {font-size:11px;color:var(--lc-text-muted);}.message-status.svelte-z9t1fg {font-size:11px;color:var(--lc-text-muted);}.message-status.sending.svelte-z9t1fg {color:var(--lc-primary);}.retry-btn.svelte-z9t1fg {font-size:11px;color:var(--lc-error);background:none;border:none;cursor:pointer;text-decoration:underline;font-family:var(--lc-font);}.retry-btn.svelte-z9t1fg:hover {color:#dc2626;} + + /* Thinking/Progress Indicator */.thinking-content.svelte-z9t1fg {min-width:200px;padding:12px 16px !important;}.thinking-status.svelte-z9t1fg {margin-bottom:8px;}.status-text.svelte-z9t1fg {display:flex;align-items:center;gap:8px;font-size:13px;color:var(--lc-text-secondary);}.status-text.tool-running.svelte-z9t1fg {color:var(--lc-primary);}.status-text.tool-error.svelte-z9t1fg {color:var(--lc-error);}.thinking-spinner.svelte-z9t1fg {width:14px;height:14px;border:2px solid var(--lc-border);border-top-color:var(--lc-primary);border-radius:50%; + animation: svelte-z9t1fg-spin 0.8s linear infinite;} + + /* Tool History */.tool-history.svelte-z9t1fg {display:flex;flex-direction:column;gap:4px;border-top:1px solid var(--lc-border);padding-top:8px;margin-top:4px;}.tool-item.svelte-z9t1fg {display:flex;align-items:center;gap:6px;font-size:12px;color:var(--lc-text-muted);padding:4px 0;}.tool-item.running.svelte-z9t1fg {color:var(--lc-primary);}.tool-item.error.svelte-z9t1fg {color:var(--lc-error);}.tool-icon.svelte-z9t1fg {display:flex;align-items:center;justify-content:center;width:16px;height:16px;flex-shrink:0;}.tool-item.svelte-z9t1fg:not(.running):not(.error) .tool-icon:where(.svelte-z9t1fg) {color:#22c55e;}.mini-spinner.svelte-z9t1fg {width:12px;height:12px;border:1.5px solid var(--lc-border);border-top-color:var(--lc-primary);border-radius:50%; + animation: svelte-z9t1fg-spin 0.8s linear infinite;}.tool-desc.svelte-z9t1fg {flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}.tool-duration.svelte-z9t1fg {font-size:11px;color:var(--lc-text-muted);opacity:0.7;} + + /* Empty State */.empty-state.svelte-z9t1fg {display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;color:var(--lc-text-muted);gap:12px;}.empty-state.svelte-z9t1fg p:where(.svelte-z9t1fg) {font-size:14px;} + + /* Loading Indicator */.loading-indicator.svelte-z9t1fg {display:flex;align-items:center;justify-content:center;gap:8px;padding:12px;color:var(--lc-text-muted);font-size:13px;}.loading-spinner.svelte-z9t1fg {width:16px;height:16px;border:2px solid var(--lc-border);border-top-color:var(--lc-primary);border-radius:50%; + animation: svelte-z9t1fg-spin 0.8s linear infinite;} + + @keyframes svelte-z9t1fg-spin { + to { transform: rotate(360deg); } + } + + /* Input Footer */.lc-chatbot-input.svelte-z9t1fg {display:flex;align-items:flex-end;gap:8px;padding:12px 16px;background:var(--lc-bg);border-top:1px solid var(--lc-border);}.lc-chatbot-input.svelte-z9t1fg textarea:where(.svelte-z9t1fg) {flex:1;min-height:40px;max-height:120px;padding:10px 14px;border:1px solid var(--lc-border);border-radius:var(--lc-radius-sm);font-family:var(--lc-font);font-size:14px;resize:none;outline:none;transition:border-color 0.15s ease;line-height:1.4;}.lc-chatbot-input.svelte-z9t1fg textarea:where(.svelte-z9t1fg):focus {border-color:var(--lc-primary);}.lc-chatbot-input.svelte-z9t1fg textarea:where(.svelte-z9t1fg)::placeholder {color:var(--lc-text-muted);}.lc-chatbot-input.svelte-z9t1fg textarea:where(.svelte-z9t1fg):disabled {background:var(--lc-bg-secondary);cursor:not-allowed;}.send-btn.svelte-z9t1fg {display:flex;align-items:center;justify-content:center;width:40px;height:40px;background:var(--lc-primary);color:white;border:none;border-radius:var(--lc-radius-sm);cursor:pointer;transition:all 0.15s ease;}.send-btn.svelte-z9t1fg:hover:not(:disabled) {background:var(--lc-primary-hover);}.send-btn.svelte-z9t1fg:disabled {opacity:0.5;cursor:not-allowed;}.send-btn.svelte-z9t1fg:active:not(:disabled) {transform:scale(0.95);}`};function dl(t,e){Pi(e,!0),Do(t,Sf);let n=os(e,"user-id",7,""),r=os(e,"api-base-url",7,""),s=os(e,"default-open",7,!1),i=os(e,"placement",7,"right"),a=re(!1),l=re(zn([])),o=re(""),c=re(!1),u=re(!1),g=re(!0),p=re(""),v=re(380),b=re(520),R=re(!1),_=re(null),x=re(null),U=re(zn([])),H=re(null),M=re(null);const ve=320,we=420,ee=.9,ut=.9;ia(()=>{const{sessionId:y}=Yo();T(p,y,!0);const z=Er(Ke.UI,null);z?.isOpen!==void 0&&s()===!1?T(a,z.isOpen,!0):s()&&T(a,!0);const I=Er(Ke.SIZE,null);I&&(T(v,Math.max(ve,Math.min(I.width,window.innerWidth*ee)),!0),T(b,Math.max(we,Math.min(I.height,window.innerHeight*ut)),!0));const J=Er(Ke.DRAFT,null);J?.text&&T(o,J.text,!0);const te=Er(Ke.MESSAGES+":"+y,[]);T(l,te,!0)}),ia(()=>{d(o)&&hn(Ke.DRAFT,{text:d(o)})});function et(y,z={}){const I=new CustomEvent(`chatbot:${y}`,{bubbles:!0,composed:!0,detail:z});document.dispatchEvent(I)}function oe(){T(a,!0),hn(Ke.UI,{isOpen:!0,placement:i()}),et("opened"),setTimeout(()=>{d(M)?.focus()},100),d(l).length===0&&d(p)&&r()&&Hn()}function pe(){T(a,!1),hn(Ke.UI,{isOpen:!1,placement:i()}),et("closed")}async function Hn(){if(!(!n()||!d(p)||!r())){T(u,!0);try{const y=await Pa(r(),n(),d(p),null,20);T(l,y.messages,!0),T(g,y.hasMore,!0),Jt(),lr()}catch(y){console.warn("[lc-chatbot] Failed to load history:",y)}finally{T(u,!1)}}}async function Fr(){if(d(u)||!d(g)||d(l).length===0)return;const y=d(l)[0];if(y){T(u,!0);try{const z=await Pa(r(),n(),d(p),y.timestamp,20);T(l,[...z.messages,...d(l)],!0),T(g,z.hasMore,!0),Jt()}catch(z){console.warn("[lc-chatbot] Failed to load more history:",z)}finally{T(u,!1)}}}function Jt(){hn(Ke.MESSAGES+":"+d(p),d(l))}function lr(){setTimeout(()=>{d(H)&&(d(H).scrollTop=d(H).scrollHeight)},50)}async function Ur(){const y=d(o).trim();if(!y||d(c)||!n()||!r())return;T(o,""),hn(Ke.DRAFT,{text:""});const z={messageId:Na(),sessionId:d(p),userId:n(),role:"user",content:y,timestamp:new Date().toISOString(),status:"sending"};T(l,[...d(l),z],!0),Jt(),lr(),T(c,!0),T(x,null),T(U,[],!0),Zo(d(p));try{const I=await Xo(r(),n(),d(p),y,{onProgress:te=>{T(x,te,!0),te.type==="tool_start"?T(U,[...d(U),{toolName:te.toolName,description:te.description,status:"running",startTime:Date.now()}],!0):te.type==="tool_end"&&T(U,d(U).map((ze,Tt)=>Tt===d(U).length-1?{...ze,status:te.isError?"error":"complete",duration:Date.now()-ze.startTime}:ze),!0),lr()},onError:te=>{console.error("[lc-chatbot] Stream error:",te)}});T(l,d(l).map(te=>te.messageId===z.messageId?{...te,status:"sent"}:te),!0);const J={messageId:I.messageId,sessionId:I.sessionId,userId:n(),role:"assistant",content:I.markdown,timestamp:I.timestamp,status:"sent",toolCalls:I.toolCalls,stats:I.stats};T(l,[...d(l),J],!0),Jt(),lr(),et("message_sent",{messageId:z.messageId,sessionId:d(p),toolCalls:I.toolCalls,stats:I.stats})}catch(I){console.error("[lc-chatbot] Send failed:",I),T(l,d(l).map(J=>J.messageId===z.messageId?{...J,status:"failed"}:J),!0),Jt(),et("error",{type:"send_failed",messageId:z.messageId,error:I.message})}finally{T(c,!1),T(x,null),T(U,[],!0)}}function bi(y){y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),Ur())}function ys(y){y.target.scrollTop<50&&d(g)&&!d(u)&&Fr()}async function wi(y){const z=d(l).find(I=>I.messageId===y&&I.status==="failed");z&&(T(l,d(l).filter(I=>I.messageId!==y),!0),T(o,z.content,!0),await Ur())}function yt(y,z){z.preventDefault(),T(R,!0),T(_,y,!0);const I=z.clientX,J=z.clientY,te=d(v),ze=d(b);function Tt(ht){const Mt=ht.clientX-I,Nt=ht.clientY-J,_n=window.innerWidth*ee,or=window.innerHeight*ut;if(d(_).includes("w")||d(_).includes("e")){const pt=d(_).includes("w")?-Mt:Mt;T(v,Math.max(ve,Math.min(te+pt,_n)),!0)}if(d(_).includes("n")||d(_).includes("s")){const pt=d(_).includes("n")?-Nt:Nt;T(b,Math.max(we,Math.min(ze+pt,or)),!0)}}function en(){T(R,!1),T(_,null),hn(Ke.SIZE,{width:d(v),height:d(b)}),document.removeEventListener("mousemove",Tt),document.removeEventListener("mouseup",en)}document.addEventListener("mousemove",Tt),document.addEventListener("mouseup",en)}function ce(){const y=[];let z=null;for(const I of d(l)){const J=rf(I.timestamp);J!==z&&(y.push({type:"date-marker",date:tf(new Date(I.timestamp)),key:"date-"+J}),z=J),y.push({type:"message",...I,key:I.messageId})}return y}let Ts=ro(ce);function de(y){const z=y.target?.closest?.("a");if(!z)return;const I=z.getAttribute("href");if(!I)return;y.preventDefault(),y.stopPropagation();const J=I;console.log("[lc-chatbot] Link clicked:",z.getAttribute("href")),document.dispatchEvent(new CustomEvent("sefaria:bootstrap-url",{detail:{url:J,replaceHistory:!0}}))}var Es={get"user-id"(){return n()},set"user-id"(y=""){n(y),Qn()},get"api-base-url"(){return r()},set"api-base-url"(y=""){r(y),Qn()},get"default-open"(){return s()},set"default-open"(y=!1){s(y),Qn()},get placement(){return i()},set placement(y="right"){i(y),Qn()}},Q=Ef();let vn;var Hr=K(Q);{var mn=y=>{var z=sf();z.__click=oe,G(y,z)},Ss=y=>{var z=Tf();let I;var J=K(z);J.__mousedown=A=>yt("n",A);var te=se(J,2);te.__mousedown=A=>yt("s",A);var ze=se(te,2);ze.__mousedown=A=>yt("e",A);var Tt=se(ze,2);Tt.__mousedown=A=>yt("w",A);var en=se(Tt,2);en.__mousedown=A=>yt("ne",A);var ht=se(en,2);ht.__mousedown=A=>yt("nw",A);var Mt=se(ht,2);Mt.__mousedown=A=>yt("se",A);var Nt=se(Mt,2);Nt.__mousedown=A=>yt("sw",A);var _n=se(Nt,2),or=se(K(_n),2);or.__click=pe,X(_n);var pt=se(_n,2);pt.__click=de;var cr=K(pt);{var Bn=A=>{var q=af();G(A,q)};Ae(cr,A=>{d(u)&&A(Bn)})}var tn=se(cr,2);{var dt=A=>{var q=lf();G(A,q)};Ae(tn,A=>{d(l).length===0&&!d(u)&&A(dt)})}var fr=se(tn,2);Ia(fr,17,()=>d(Ts),A=>A.key,(A,q)=>{var gt=tr(),rn=er(gt);{var Wn=tt=>{var Ue=of(),sn=K(Ue),ae=K(sn,!0);X(sn),X(Ue),bt(()=>fn(ae,d(q).date)),G(tt,Ue)},Br=tt=>{var Ue=hf();let sn;var ae=K(Ue),Ye=K(ae);{var Pt=V=>{var B=tr(),me=er(B);Oo(me,()=>ef(d(q).content)),G(V,B)},N=V=>{var B=cf(),me=K(B,!0);X(B),bt(()=>fn(me,d(q).content)),G(V,B)};Ae(Ye,V=>{d(q).role==="assistant"?V(Pt):V(N,!1)})}X(ae);var Re=se(ae,2),He=K(Re),Be=K(He,!0);X(He);var vt=se(He,2);{var Ft=V=>{var B=ff();G(V,B)},bn=V=>{var B=tr(),me=er(B);{var Ut=ge=>{var xe=uf();xe.__click=()=>wi(d(q).messageId),G(ge,xe)};Ae(me,ge=>{d(q).status==="failed"&&ge(Ut)},!0)}G(V,B)};Ae(vt,V=>{d(q).status==="sending"?V(Ft):V(bn,!1)})}X(Re),X(Ue),bt(V=>{sn=Tr(Ue,1,"message svelte-z9t1fg",null,sn,{user:d(q).role==="user",assistant:d(q).role==="assistant",failed:d(q).status==="failed"}),fn(Be,V)},[()=>nf(d(q).timestamp)]),G(tt,Ue)};Ae(rn,tt=>{d(q).type==="date-marker"?tt(Wn):tt(Br,!1)})}G(A,gt)});var As=se(fr,2);{var zs=A=>{var q=yf(),gt=K(q),rn=K(gt),Wn=K(rn);{var Br=ae=>{var Ye=pf(),Pt=se(K(Ye),2),N=K(Pt,!0);X(Pt),X(Ye),bt(()=>fn(N,d(x).text)),G(ae,Ye)},tt=ae=>{var Ye=tr(),Pt=er(Ye);{var N=He=>{var Be=df(),vt=se(K(Be),2),Ft=K(vt,!0);X(vt),X(Be),bt(()=>fn(Ft,d(x).description||`Running ${d(x).toolName}...`)),G(He,Be)},Re=He=>{var Be=tr(),vt=er(Be);{var Ft=V=>{var B=mf();let me;var Ut=K(B),ge=K(Ut);{var xe=Ie=>{var Ht=gf();Ns(2),G(Ie,Ht)},wn=Ie=>{var Ht=vf();Ns(),G(Ie,Ht)};Ae(ge,Ie=>{d(x).isError?Ie(xe):Ie(wn,!1)})}X(Ut);var $e=se(Ut,2),hr=K($e,!0);X($e),X(B),bt(()=>{me=Tr(B,1,"status-text svelte-z9t1fg",null,me,{"tool-error":d(x).isError}),fn(hr,d(x).isError?"Tool error":"Done")}),G(V,B)},bn=V=>{var B=_f();G(V,B)};Ae(vt,V=>{d(x)?.type==="tool_end"?V(Ft):V(bn,!1)},!0)}G(He,Be)};Ae(Pt,He=>{d(x)?.type==="tool_start"?He(N):He(Re,!1)},!0)}G(ae,Ye)};Ae(Wn,ae=>{d(x)?.type==="status"?ae(Br):ae(tt,!1)})}X(rn);var Ue=se(rn,2);{var sn=ae=>{var Ye=kf();Ia(Ye,21,()=>d(U),$o,(Pt,N)=>{var Re=xf();let He;var Be=K(Re),vt=K(Be);{var Ft=ge=>{var xe=bf();G(ge,xe)},bn=ge=>{var xe=tr(),wn=er(xe);{var $e=Ie=>{var Ht=Aa("✗");G(Ie,Ht)},hr=Ie=>{var Ht=Aa("✓");G(Ie,Ht)};Ae(wn,Ie=>{d(N).status==="error"?Ie($e):Ie(hr,!1)},!0)}G(ge,xe)};Ae(vt,ge=>{d(N).status==="running"?ge(Ft):ge(bn,!1)})}X(Be);var V=se(Be,2),B=K(V,!0);X(V);var me=se(V,2);{var Ut=ge=>{var xe=wf(),wn=K(xe);X(xe),bt($e=>fn(wn,`${$e??""}s`),[()=>(d(N).duration/1e3).toFixed(1)]),G(ge,xe)};Ae(me,ge=>{d(N).duration&&ge(Ut)})}X(Re),bt(()=>{He=Tr(Re,1,"tool-item svelte-z9t1fg",null,He,{running:d(N).status==="running",error:d(N).status==="error"}),fn(B,d(N).description||d(N).toolName)}),G(Pt,Re)}),X(Ye),G(ae,Ye)};Ae(Ue,ae=>{d(U).length>0&&ae(sn)})}X(gt),X(q),G(A,q)};Ae(As,A=>{d(c)&&A(zs)})}X(pt),Oa(pt,A=>T(H,A),()=>d(H));var ur=se(pt,2),nn=K(ur);lo(nn),nn.__keydown=bi,Oa(nn,A=>T(M,A),()=>d(M));var Gn=se(nn,2);Gn.__click=Ur,X(ur),X(z),bt(A=>{I=Tr(z,1,"lc-chatbot-panel svelte-z9t1fg",null,I,{resizing:d(R)}),Po(z,`width: ${d(v)??""}px; height: ${d(b)??""}px;`),nn.disabled=d(c),Gn.disabled=A},[()=>!d(o).trim()||d(c)]),ko("scroll",pt,ys),Fo(nn,()=>d(o),A=>T(o,A)),G(y,z)};Ae(Hr,y=>{d(a)?y(Ss,!1):y(mn)})}return X(Q),bt(()=>vn=Tr(Q,1,"lc-chatbot-container svelte-z9t1fg",null,vn,{"placement-left":i()==="left"})),G(t,Q),Fi(Es)}return yo(["click","mousedown","keydown"]),customElements.define("lc-chatbot",Go(dl,{"user-id":{},"api-base-url":{},"default-open":{},placement:{}},[],[],!0)),dl}); From 20170a8cf49aab8948bf78dc6a4f18008e225a0c Mon Sep 17 00:00:00 2001 From: Akiva Berger Date: Wed, 21 Jan 2026 11:03:56 +0200 Subject: [PATCH 03/21] feat: add chatbot --- static/js/ReaderApp.jsx | 1 - templates/base.html | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/static/js/ReaderApp.jsx b/static/js/ReaderApp.jsx index 6c87b3480a..fcdc7131e9 100644 --- a/static/js/ReaderApp.jsx +++ b/static/js/ReaderApp.jsx @@ -1333,7 +1333,6 @@ toggleSignUpModal(modalContentKind = SignUpModalKind.Default) { if (!settings) { return null; } return extend(Sefaria.util.clone(this.getDefaultPanelSettings()), settings); } - openURL(href, replace=true, overrideContentLang=false) { handleModuleLinkRightClick(e) { /* diff --git a/templates/base.html b/templates/base.html index 96033b7269..2cb4f3eacf 100644 --- a/templates/base.html +++ b/templates/base.html @@ -75,6 +75,9 @@ {% block head %}{% endblock %} + + + From 1b03e5ce62f72545139df14570cb7d1eb610a77f Mon Sep 17 00:00:00 2001 From: Akiva Berger Date: Wed, 21 Jan 2026 11:14:52 +0200 Subject: [PATCH 04/21] feat: add live base url --- templates/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/base.html b/templates/base.html index 2cb4f3eacf..55d42926b0 100644 --- a/templates/base.html +++ b/templates/base.html @@ -228,7 +228,7 @@ From 96cb0598e77665c726c4491e84fe4602b2464ef3 Mon Sep 17 00:00:00 2001 From: Akiva Berger Date: Mon, 26 Jan 2026 00:27:10 +0200 Subject: [PATCH 05/21] feat: make remote update instant and allow copy --- static/js/ReaderApp.jsx | 2 +- static/js/chat/lc-chatbot.umd.cjs | 112 ------------------------------ templates/base.html | 2 +- 3 files changed, 2 insertions(+), 114 deletions(-) delete mode 100644 static/js/chat/lc-chatbot.umd.cjs diff --git a/static/js/ReaderApp.jsx b/static/js/ReaderApp.jsx index fcdc7131e9..7ea827fe57 100644 --- a/static/js/ReaderApp.jsx +++ b/static/js/ReaderApp.jsx @@ -2220,7 +2220,7 @@ toggleSignUpModal(modalContentKind = SignUpModalKind.Default) { handleCopyEvent(e) { // Custom processing of Copy/Paste - const tagsToIgnore = ["INPUT", "TEXTAREA"]; + const tagsToIgnore = ["INPUT", "TEXTAREA", "LC-CHATBOT"]; if (tagsToIgnore.includes(e.srcElement.tagName)) { // If the selection is from an input or textarea tag, don't do anything special return diff --git a/static/js/chat/lc-chatbot.umd.cjs b/static/js/chat/lc-chatbot.umd.cjs deleted file mode 100644 index 9961c16313..0000000000 --- a/static/js/chat/lc-chatbot.umd.cjs +++ /dev/null @@ -1,112 +0,0 @@ -(function(j,Z){typeof exports=="object"&&typeof module<"u"?module.exports=Z():typeof define=="function"&&define.amd?define(Z):(j=typeof globalThis<"u"?globalThis:j||self,j.LCChatbot=Z())})(this,function(){"use strict";var zf=Object.defineProperty;var bl=j=>{throw TypeError(j)};var Rf=(j,Z,ue)=>Z in j?zf(j,Z,{enumerable:!0,configurable:!0,writable:!0,value:ue}):j[Z]=ue;var E=(j,Z,ue)=>Rf(j,typeof Z!="symbol"?Z+"":Z,ue),ki=(j,Z,ue)=>Z.has(j)||bl("Cannot "+ue);var h=(j,Z,ue)=>(ki(j,Z,"read from private field"),ue?ue.call(j):Z.get(j)),D=(j,Z,ue)=>Z.has(j)?bl("Cannot add the same private member more than once"):Z instanceof WeakSet?Z.add(j):Z.set(j,ue),S=(j,Z,ue,dr)=>(ki(j,Z,"write to private field"),dr?dr.call(j,ue):Z.set(j,ue),ue),ie=(j,Z,ue)=>(ki(j,Z,"access private method"),ue);var gl,rr,sr,Dn,Mn,Dr,ir,ar,be,yi,Gr,Ti,wl,xl,ot,Qe,Mr,Ct,Nn,Lt,ct,je,Ot,Kt,pn,Pn,dn,Fn,gn,xs,le,kl,yl,Ei,Rs,$s,Si,kt,Dt,Je,Un,Nr,Pr,ks,Qt,ft,_i;const j="5";typeof window<"u"&&((gl=window.__svelte??(window.__svelte={})).v??(gl.v=new Set)).add(j);const Z=1,ue=2,dr=4,Tl=8,El=16,Sl=2,Ri="[",Wr="[!",Is="]",xn={},ye=Symbol(),Cs=!1;var $i=Array.isArray,Al=Array.prototype.indexOf,qr=Array.from,jr=Object.keys,Yr=Object.defineProperty,qn=Object.getOwnPropertyDescriptor,zl=Object.prototype,Rl=Array.prototype,$l=Object.getPrototypeOf,Ii=Object.isExtensible;function Il(t){for(var e=0;e{t=r,e=s});return{promise:n,resolve:t,reject:e}}const _e=2,Ls=4,Os=8,Cl=1<<24,Bt=16,Gt=32,ln=64,Zr=128,mt=512,Te=1024,Ge=2048,Et=4096,Ve=8192,Wt=16384,Vr=32768,jn=65536,Li=1<<17,Oi=1<<18,kn=1<<19,Ll=1<<20,qt=1<<25,yn=32768,Ds=1<<21,Ms=1<<22,on=1<<23,Xr=Symbol("$state"),Ol=Symbol("legacy props"),Yn=new class extends Error{constructor(){super(...arguments);E(this,"name","StaleReactionError");E(this,"message","The reaction that called `getAbortSignal()` was re-run or destroyed")}},Kr=3,Tn=8;function Dl(){throw new Error("https://svelte.dev/e/async_derived_orphan")}function Ml(t){throw new Error("https://svelte.dev/e/effect_in_teardown")}function Nl(){throw new Error("https://svelte.dev/e/effect_in_unowned_derived")}function Pl(t){throw new Error("https://svelte.dev/e/effect_orphan")}function Fl(){throw new Error("https://svelte.dev/e/effect_update_depth_exceeded")}function Ul(){throw new Error("https://svelte.dev/e/hydration_failed")}function Hl(){throw new Error("https://svelte.dev/e/state_descriptors_fixed")}function Bl(){throw new Error("https://svelte.dev/e/state_prototype_fixed")}function Gl(){throw new Error("https://svelte.dev/e/state_unsafe_mutation")}function Wl(){throw new Error("https://svelte.dev/e/svelte_boundary_reset_onerror")}function gr(t){console.warn("https://svelte.dev/e/hydration_mismatch")}function ql(){console.warn("https://svelte.dev/e/svelte_boundary_reset_noop")}let C=!1;function jt(t){C=t}let L;function Ee(t){if(t===null)throw gr(),xn;return L=t}function Zn(){return Ee(_t(L))}function X(t){if(C){if(_t(L)!==null)throw gr(),xn;L=t}}function Ns(t=1){if(C){for(var e=t,n=L;e--;)n=_t(n);L=n}}function Qr(t=!0){for(var e=0,n=L;;){if(n.nodeType===Tn){var r=n.data;if(r===Is){if(e===0)return n;e-=1}else(r===Ri||r===Wr)&&(e+=1)}var s=_t(n);t&&n.remove(),n=s}}function Di(t){if(!t||t.nodeType!==Tn)throw gr(),xn;return t.data}function Mi(t){return t===this.v}function jl(t,e){return t!=t?e==e:t!==e||t!==null&&typeof t=="object"||typeof t=="function"}function Ni(t){return!jl(t,this.v)}let Yl=!1,nt=null;function Vn(t){nt=t}function Pi(t,e=!1,n){nt={p:nt,i:!1,c:null,e:null,s:t,x:null,l:null}}function Fi(t){var e=nt,n=e.e;if(n!==null){e.e=null;for(var r of n)aa(r)}return t!==void 0&&(e.x=t),e.i=!0,nt=e.p,t??{}}function Ui(){return!0}let En=[];function Hi(){var t=En;En=[],Il(t)}function Xn(t){if(En.length===0&&!vr){var e=En;queueMicrotask(()=>{e===En&&Hi()})}En.push(t)}function Zl(){for(;En.length>0;)Hi()}function Bi(t){var e=P;if(e===null)return O.f|=on,t;if(e.f&Vr)Kn(t,e);else{if(!(e.f&Zr))throw t;e.b.error(t)}}function Kn(t,e){for(;e!==null;){if(e.f&Zr)try{e.b.error(t);return}catch(n){t=n}e=e.parent}throw t}const Jr=new Set;let Y=null,es=null,rt=null,st=[],ts=null,Ps=!1,vr=!1;const ws=class ws{constructor(){D(this,be);E(this,"committed",!1);E(this,"current",new Map);E(this,"previous",new Map);D(this,rr,new Set);D(this,sr,new Set);D(this,Dn,0);D(this,Mn,0);D(this,Dr,null);D(this,ir,new Set);D(this,ar,new Set);E(this,"skipped_effects",new Set);E(this,"is_fork",!1)}is_deferred(){return this.is_fork||h(this,Mn)>0}process(e){st=[],es=null,this.apply();var n={parent:null,effect:null,effects:[],render_effects:[]};for(const r of e)ie(this,be,yi).call(this,r,n);this.is_fork||ie(this,be,wl).call(this),this.is_deferred()?(ie(this,be,Gr).call(this,n.effects),ie(this,be,Gr).call(this,n.render_effects)):(es=this,Y=null,Wi(n.render_effects),Wi(n.effects),es=null,h(this,Dr)?.resolve()),rt=null}capture(e,n){this.previous.has(e)||this.previous.set(e,n),e.f&on||(this.current.set(e,e.v),rt?.set(e,e.v))}activate(){Y=this,this.apply()}deactivate(){Y===this&&(Y=null,rt=null)}flush(){if(this.activate(),st.length>0){if(Gi(),Y!==null&&Y!==this)return}else h(this,Dn)===0&&this.process([]);this.deactivate()}discard(){for(const e of h(this,sr))e(this);h(this,sr).clear()}increment(e){S(this,Dn,h(this,Dn)+1),e&&S(this,Mn,h(this,Mn)+1)}decrement(e){S(this,Dn,h(this,Dn)-1),e&&S(this,Mn,h(this,Mn)-1),this.revive()}revive(){for(const e of h(this,ir))h(this,ar).delete(e),Se(e,Ge),Sn(e);for(const e of h(this,ar))Se(e,Et),Sn(e);this.flush()}oncommit(e){h(this,rr).add(e)}ondiscard(e){h(this,sr).add(e)}settled(){return(h(this,Dr)??S(this,Dr,Ci())).promise}static ensure(){if(Y===null){const e=Y=new ws;Jr.add(Y),vr||ws.enqueue(()=>{Y===e&&e.flush()})}return Y}static enqueue(e){Xn(e)}apply(){}};rr=new WeakMap,sr=new WeakMap,Dn=new WeakMap,Mn=new WeakMap,Dr=new WeakMap,ir=new WeakMap,ar=new WeakMap,be=new WeakSet,yi=function(e,n){e.f^=Te;for(var r=e.first;r!==null;){var s=r.f,i=(s&(Gt|ln))!==0,a=i&&(s&Te)!==0,l=a||(s&Ve)!==0||this.skipped_effects.has(r);if(r.f&Zr&&r.b?.is_pending()&&(n={parent:n,effect:r,effects:[],render_effects:[]}),!l&&r.fn!==null){i?r.f^=Te:s&Ls?n.effects.push(r):wr(r)&&(r.f&Bt&&h(this,ir).add(r),xr(r));var o=r.first;if(o!==null){r=o;continue}}var c=r.parent;for(r=r.next;r===null&&c!==null;)c===n.effect&&(ie(this,be,Gr).call(this,n.effects),ie(this,be,Gr).call(this,n.render_effects),n=n.parent),r=c.next,c=c.parent}},Gr=function(e){for(const n of e)n.f&Ge?h(this,ir).add(n):n.f&Et&&h(this,ar).add(n),ie(this,be,Ti).call(this,n.deps),Se(n,Te)},Ti=function(e){if(e!==null)for(const n of e)!(n.f&_e)||!(n.f&yn)||(n.f^=yn,ie(this,be,Ti).call(this,n.deps))},wl=function(){if(h(this,Mn)===0){for(const e of h(this,rr))e();h(this,rr).clear()}h(this,Dn)===0&&ie(this,be,xl).call(this)},xl=function(){var i;if(Jr.size>1){this.previous.clear();var e=rt,n=!0,r={parent:null,effect:null,effects:[],render_effects:[]};for(const a of Jr){if(a===this){n=!1;continue}const l=[];for(const[c,u]of this.current){if(a.current.has(c))if(n&&u!==a.current.get(c))a.current.set(c,u);else continue;l.push(c)}if(l.length===0)continue;const o=[...a.current.keys()].filter(c=>!this.current.has(c));if(o.length>0){var s=st;st=[];const c=new Set,u=new Map;for(const g of l)qi(g,o,c,u);if(st.length>0){Y=a,a.apply();for(const g of st)ie(i=a,be,yi).call(i,g,r);a.deactivate()}st=s}}Y=null,rt=e}this.committed=!0,Jr.delete(this)};let St=ws;function Qn(t){var e=vr;vr=!0;try{for(var n;;){if(Zl(),st.length===0&&(Y?.flush(),st.length===0))return ts=null,n;Gi()}}finally{vr=e}}function Gi(){var t=$n;Ps=!0;var e=null;try{var n=0;for(as(!0);st.length>0;){var r=St.ensure();if(n++>1e3){var s,i;Vl()}r.process(st),cn.clear()}}finally{Ps=!1,as(t),ts=null}}function Vl(){try{Fl()}catch(t){Kn(t,ts)}}let Yt=null;function Wi(t){var e=t.length;if(e!==0){for(var n=0;n0)){cn.clear();for(const s of Yt){if(s.f&(Wt|Ve))continue;const i=[s];let a=s.parent;for(;a!==null;)Yt.has(a)&&(Yt.delete(a),i.push(a)),a=a.parent;for(let l=i.length-1;l>=0;l--){const o=i[l];o.f&(Wt|Ve)||xr(o)}}Yt.clear()}}Yt=null}}function qi(t,e,n,r){if(!n.has(t)&&(n.add(t),t.reactions!==null))for(const s of t.reactions){const i=s.f;i&_e?qi(s,e,n,r):i&(Ms|Bt)&&!(i&Ge)&&ji(s,e,r)&&(Se(s,Ge),Sn(s))}}function ji(t,e,n){const r=n.get(t);if(r!==void 0)return r;if(t.deps!==null)for(const s of t.deps){if(e.includes(s))return!0;if(s.f&_e&&ji(s,e,n))return n.set(s,!0),!0}return n.set(t,!1),!1}function Sn(t){for(var e=ts=t;e.parent!==null;){e=e.parent;var n=e.f;if(Ps&&e===P&&n&Bt&&!(n&Oi))return;if(n&(ln|Gt)){if(!(n&Te))return;e.f^=Te}}st.push(e)}function Xl(t){let e=0,n=An(0),r;return()=>{_r()&&(d(n),is(()=>(e===0&&(r=qs(()=>t(()=>mr(n)))),e+=1,()=>{Xn(()=>{e-=1,e===0&&(r?.(),r=void 0,mr(n))})})))}}var Kl=jn|kn|Zr;function Ql(t,e,n){new Jl(t,e,n)}class Jl{constructor(e,n,r){D(this,le);E(this,"parent");D(this,ot,!1);D(this,Qe);D(this,Mr,C?L:null);D(this,Ct);D(this,Nn);D(this,Lt);D(this,ct,null);D(this,je,null);D(this,Ot,null);D(this,Kt,null);D(this,pn,null);D(this,Pn,0);D(this,dn,0);D(this,Fn,!1);D(this,gn,null);D(this,xs,Xl(()=>(S(this,gn,An(h(this,Pn))),()=>{S(this,gn,null)})));S(this,Qe,e),S(this,Ct,n),S(this,Nn,r),this.parent=P.b,S(this,ot,!!h(this,Ct).pending),S(this,Lt,Gs(()=>{if(P.b=this,C){const i=h(this,Mr);Zn(),i.nodeType===Tn&&i.data===Wr?ie(this,le,yl).call(this):ie(this,le,kl).call(this)}else{var s=ie(this,le,Ei).call(this);try{S(this,ct,it(()=>r(s)))}catch(i){this.error(i)}h(this,dn)>0?ie(this,le,$s).call(this):S(this,ot,!1)}return()=>{h(this,pn)?.remove()}},Kl)),C&&S(this,Qe,L)}is_pending(){return h(this,ot)||!!this.parent&&this.parent.is_pending()}has_pending_snippet(){return!!h(this,Ct).pending}update_pending_count(e){ie(this,le,Si).call(this,e),S(this,Pn,h(this,Pn)+e),h(this,gn)&&Jn(h(this,gn),h(this,Pn))}get_effect_pending(){return h(this,xs).call(this),d(h(this,gn))}error(e){var n=h(this,Ct).onerror;let r=h(this,Ct).failed;if(h(this,Fn)||!n&&!r)throw e;h(this,ct)&&(Oe(h(this,ct)),S(this,ct,null)),h(this,je)&&(Oe(h(this,je)),S(this,je,null)),h(this,Ot)&&(Oe(h(this,Ot)),S(this,Ot,null)),C&&(Ee(h(this,Mr)),Ns(),Ee(Qr()));var s=!1,i=!1;const a=()=>{if(s){ql();return}s=!0,i&&Wl(),St.ensure(),S(this,Pn,0),h(this,Ot)!==null&&Rn(h(this,Ot),()=>{S(this,Ot,null)}),S(this,ot,this.has_pending_snippet()),S(this,ct,ie(this,le,Rs).call(this,()=>(S(this,Fn,!1),it(()=>h(this,Nn).call(this,h(this,Qe)))))),h(this,dn)>0?ie(this,le,$s).call(this):S(this,ot,!1)};var l=O;try{qe(null),i=!0,n?.(e,a),i=!1}catch(o){Kn(o,h(this,Lt)&&h(this,Lt).parent)}finally{qe(l)}r&&Xn(()=>{S(this,Ot,ie(this,le,Rs).call(this,()=>{St.ensure(),S(this,Fn,!0);try{return it(()=>{r(h(this,Qe),()=>e,()=>a)})}catch(o){return Kn(o,h(this,Lt).parent),null}finally{S(this,Fn,!1)}}))})}}ot=new WeakMap,Qe=new WeakMap,Mr=new WeakMap,Ct=new WeakMap,Nn=new WeakMap,Lt=new WeakMap,ct=new WeakMap,je=new WeakMap,Ot=new WeakMap,Kt=new WeakMap,pn=new WeakMap,Pn=new WeakMap,dn=new WeakMap,Fn=new WeakMap,gn=new WeakMap,xs=new WeakMap,le=new WeakSet,kl=function(){try{S(this,ct,it(()=>h(this,Nn).call(this,h(this,Qe))))}catch(e){this.error(e)}S(this,ot,!1)},yl=function(){const e=h(this,Ct).pending;e&&(S(this,je,it(()=>e(h(this,Qe)))),St.enqueue(()=>{var n=ie(this,le,Ei).call(this);S(this,ct,ie(this,le,Rs).call(this,()=>(St.ensure(),it(()=>h(this,Nn).call(this,n))))),h(this,dn)>0?ie(this,le,$s).call(this):(Rn(h(this,je),()=>{S(this,je,null)}),S(this,ot,!1))}))},Ei=function(){var e=h(this,Qe);return h(this,ot)&&(S(this,pn,We()),h(this,Qe).before(h(this,pn)),e=h(this,pn)),e},Rs=function(e){var n=P,r=O,s=nt;Rt(h(this,Lt)),qe(h(this,Lt)),Vn(h(this,Lt).ctx);try{return e()}catch(i){return Bi(i),null}finally{Rt(n),qe(r),Vn(s)}},$s=function(){const e=h(this,Ct).pending;h(this,ct)!==null&&(S(this,Kt,document.createDocumentFragment()),h(this,Kt).append(h(this,pn)),da(h(this,ct),h(this,Kt))),h(this,je)===null&&S(this,je,it(()=>e(h(this,Qe))))},Si=function(e){var n;if(!this.has_pending_snippet()){this.parent&&ie(n=this.parent,le,Si).call(n,e);return}S(this,dn,h(this,dn)+e),h(this,dn)===0&&(S(this,ot,!1),h(this,je)&&Rn(h(this,je),()=>{S(this,je,null)}),h(this,Kt)&&(h(this,Qe).before(h(this,Kt)),S(this,Kt,null)))};function eo(t,e,n,r){const s=rs;if(n.length===0&&t.length===0){r(e.map(s));return}var i=Y,a=P,l=to();function o(){Promise.all(n.map(c=>no(c))).then(c=>{l();try{r([...e.map(s),...c])}catch(u){a.f&Wt||Kn(u,a)}i?.deactivate(),ns()}).catch(c=>{Kn(c,a)})}t.length>0?Promise.all(t).then(()=>{l();try{return o()}finally{i?.deactivate(),ns()}}):o()}function to(){var t=P,e=O,n=nt,r=Y;return function(i=!0){Rt(t),qe(e),Vn(n),i&&r?.activate()}}function ns(){Rt(null),qe(null),Vn(null)}function rs(t){var e=_e|Ge,n=O!==null&&O.f&_e?O:null;return P!==null&&(P.f|=kn),{ctx:nt,deps:null,effects:null,equals:Mi,f:e,fn:t,reactions:null,rv:0,v:ye,wv:0,parent:n??P,ac:null}}function no(t,e){let n=P;n===null&&Dl();var r=n.b,s=void 0,i=An(ye),a=!O,l=new Map;return go(()=>{var o=Ci();s=o.promise;try{Promise.resolve(t()).then(o.resolve,o.reject).then(()=>{c===Y&&c.committed&&c.deactivate(),ns()})}catch(p){o.reject(p),ns()}var c=Y;if(a){var u=!r.is_pending();r.update_pending_count(1),c.increment(u),l.get(c)?.reject(Yn),l.delete(c),l.set(c,o)}const g=(p,v=void 0)=>{if(c.activate(),v)v!==Yn&&(i.f|=on,Jn(i,v));else{i.f&on&&(i.f^=on),Jn(i,p);for(const[b,R]of l){if(l.delete(b),b===c)break;R.reject(Yn)}}a&&(r.update_pending_count(-1),c.decrement(u))};o.promise.then(g,p=>g(null,p||"unknown"))}),sa(()=>{for(const o of l.values())o.reject(Yn)}),new Promise(o=>{function c(u){function g(){u===s?o(i):c(s)}u.then(g,g)}c(s)})}function ro(t){const e=rs(t);return va(e),e}function so(t){const e=rs(t);return e.equals=Ni,e}function Yi(t){var e=t.effects;if(e!==null){t.effects=null;for(var n=0;n0&&!Vi&&ao()}return e}function ao(){Vi=!1;var t=$n;as(!0);const e=Array.from(Us);try{for(const n of e)n.f&Te&&Se(n,Et),wr(n)&&xr(n)}finally{as(t)}Us.clear()}function mr(t){T(t,t.v+1)}function Ki(t,e){var n=t.reactions;if(n!==null)for(var r=n.length,s=0;s{if(Cn===i)return l();var o=O,c=Cn;qe(null),_a(i);var u=l();return qe(o),_a(c),u};return r&&n.set("length",re(t.length)),new Proxy(t,{defineProperty(l,o,c){(!("value"in c)||c.configurable===!1||c.enumerable===!1||c.writable===!1)&&Hl();var u=n.get(o);return u===void 0?u=a(()=>{var g=re(c.value);return n.set(o,g),g}):T(u,c.value,!0),!0},deleteProperty(l,o){var c=n.get(o);if(c===void 0){if(o in l){const u=a(()=>re(ye));n.set(o,u),mr(s)}}else T(c,ye),mr(s);return!0},get(l,o,c){if(o===Xr)return t;var u=n.get(o),g=o in l;if(u===void 0&&(!g||qn(l,o)?.writable)&&(u=a(()=>{var v=zn(g?l[o]:ye),b=re(v);return b}),n.set(o,u)),u!==void 0){var p=d(u);return p===ye?void 0:p}return Reflect.get(l,o,c)},getOwnPropertyDescriptor(l,o){var c=Reflect.getOwnPropertyDescriptor(l,o);if(c&&"value"in c){var u=n.get(o);u&&(c.value=d(u))}else if(c===void 0){var g=n.get(o),p=g?.v;if(g!==void 0&&p!==ye)return{enumerable:!0,configurable:!0,value:p,writable:!0}}return c},has(l,o){if(o===Xr)return!0;var c=n.get(o),u=c!==void 0&&c.v!==ye||Reflect.has(l,o);if(c!==void 0||P!==null&&(!u||qn(l,o)?.writable)){c===void 0&&(c=a(()=>{var p=u?zn(l[o]):ye,v=re(p);return v}),n.set(o,c));var g=d(c);if(g===ye)return!1}return u},set(l,o,c,u){var g=n.get(o),p=o in l;if(r&&o==="length")for(var v=c;vre(ye)),n.set(v+"",b))}if(g===void 0)(!p||qn(l,o)?.writable)&&(g=a(()=>re(void 0)),T(g,zn(c)),n.set(o,g));else{p=g.v!==ye;var R=a(()=>zn(c));T(g,R)}var _=Reflect.getOwnPropertyDescriptor(l,o);if(_?.set&&_.set.call(u,c),!p){if(r&&typeof o=="string"){var x=n.get("length"),U=Number(o);Number.isInteger(U)&&U>=x.v&&T(x,U+1)}mr(s)}return!0},ownKeys(l){d(s);var o=Reflect.ownKeys(l).filter(g=>{var p=n.get(g);return p===void 0||p.v!==ye});for(var[c,u]of n)u.v!==ye&&!(c in l)&&o.push(c);return o},setPrototypeOf(){Bl()}})}var Qi,Ji,ea,ta;function Hs(){if(Qi===void 0){Qi=window,Ji=/Firefox/.test(navigator.userAgent);var t=Element.prototype,e=Node.prototype,n=Text.prototype;ea=qn(e,"firstChild").get,ta=qn(e,"nextSibling").get,Ii(t)&&(t.__click=void 0,t.__className=void 0,t.__attributes=null,t.__style=void 0,t.__e=void 0),Ii(n)&&(n.__t=void 0)}}function We(t=""){return document.createTextNode(t)}function Le(t){return ea.call(t)}function _t(t){return ta.call(t)}function K(t,e){if(!C)return Le(t);var n=Le(L);if(n===null)n=L.appendChild(We());else if(e&&n.nodeType!==Kr){var r=We();return n?.before(r),Ee(r),r}return Ee(n),n}function er(t,e=!1){if(!C){var n=Le(t);return n instanceof Comment&&n.data===""?_t(n):n}if(e&&L?.nodeType!==Kr){var r=We();return L?.before(r),Ee(r),r}return L}function se(t,e=1,n=!1){let r=C?L:t;for(var s;e--;)s=r,r=_t(r);if(!C)return r;if(n&&r?.nodeType!==Kr){var i=We();return r===null?s?.after(i):r.before(i),Ee(i),i}return Ee(r),r}function Bs(t){t.textContent=""}function na(){return!1}function lo(t){C&&Le(t)!==null&&Bs(t)}let ra=!1;function oo(){ra||(ra=!0,document.addEventListener("reset",t=>{Promise.resolve().then(()=>{if(!t.defaultPrevented)for(const e of t.target.elements)e.__on_r?.()})},{capture:!0}))}function ss(t){var e=O,n=P;qe(null),Rt(null);try{return t()}finally{qe(e),Rt(n)}}function co(t,e,n,r=n){t.addEventListener(e,()=>ss(n));const s=t.__on_r;s?t.__on_r=()=>{s(),r(!0)}:t.__on_r=()=>r(!0),oo()}function fo(t){P===null&&(O===null&&Pl(),Nl()),In&&Ml()}function uo(t,e){var n=e.last;n===null?e.last=e.first=t:(n.next=t,t.prev=n,e.last=t)}function At(t,e,n){var r=P;r!==null&&r.f&Ve&&(t|=Ve);var s={ctx:nt,deps:null,nodes:null,f:t|Ge|mt,first:null,fn:e,last:null,next:null,parent:r,b:r&&r.b,prev:null,teardown:null,wv:0,ac:null};if(n)try{xr(s),s.f|=Vr}catch(l){throw Oe(s),l}else e!==null&&Sn(s);var i=s;if(n&&i.deps===null&&i.teardown===null&&i.nodes===null&&i.first===i.last&&!(i.f&kn)&&(i=i.first,t&Bt&&t&jn&&i!==null&&(i.f|=jn)),i!==null&&(i.parent=r,r!==null&&uo(i,r),O!==null&&O.f&_e&&!(t&ln))){var a=O;(a.effects??(a.effects=[])).push(i)}return s}function _r(){return O!==null&&!zt}function sa(t){const e=At(Os,null,!1);return Se(e,Te),e.teardown=t,e}function ia(t){fo();var e=P.f,n=!O&&(e&Gt)!==0&&(e&Vr)===0;if(n){var r=nt;(r.e??(r.e=[])).push(t)}else return aa(t)}function aa(t){return At(Ls|Ll,t,!1)}function ho(t){St.ensure();const e=At(ln|kn,t,!0);return()=>{Oe(e)}}function po(t){St.ensure();const e=At(ln|kn,t,!0);return(n={})=>new Promise(r=>{n.outro?Rn(e,()=>{Oe(e),r(void 0)}):(Oe(e),r(void 0))})}function la(t){return At(Ls,t,!1)}function go(t){return At(Ms|kn,t,!0)}function is(t,e=0){return At(Os|e,t,!0)}function bt(t,e=[],n=[],r=[]){eo(r,e,n,s=>{At(Os,()=>t(...s.map(d)),!0)})}function Gs(t,e=0){var n=At(Bt|e,t,!0);return n}function it(t){return At(Gt|kn,t,!0)}function oa(t){var e=t.teardown;if(e!==null){const n=In,r=O;ga(!0),qe(null);try{e.call(null)}finally{ga(n),qe(r)}}}function ca(t,e=!1){var n=t.first;for(t.first=t.last=null;n!==null;){const s=n.ac;s!==null&&ss(()=>{s.abort(Yn)});var r=n.next;n.f&ln?n.parent=null:Oe(n,e),n=r}}function vo(t){for(var e=t.first;e!==null;){var n=e.next;e.f&Gt||Oe(e),e=n}}function Oe(t,e=!0){var n=!1;(e||t.f&Oi)&&t.nodes!==null&&t.nodes.end!==null&&(fa(t.nodes.start,t.nodes.end),n=!0),ca(t,e&&!n),ls(t,0),Se(t,Wt);var r=t.nodes&&t.nodes.t;if(r!==null)for(const i of r)i.stop();oa(t);var s=t.parent;s!==null&&s.first!==null&&ua(t),t.next=t.prev=t.teardown=t.ctx=t.deps=t.fn=t.nodes=t.ac=null}function fa(t,e){for(;t!==null;){var n=t===e?null:_t(t);t.remove(),t=n}}function ua(t){var e=t.parent,n=t.prev,r=t.next;n!==null&&(n.next=r),r!==null&&(r.prev=n),e!==null&&(e.first===t&&(e.first=r),e.last===t&&(e.last=n))}function Rn(t,e,n=!0){var r=[];ha(t,r,!0);var s=()=>{n&&Oe(t),e&&e()},i=r.length;if(i>0){var a=()=>--i||s();for(var l of r)l.out(a)}else s()}function ha(t,e,n){if(!(t.f&Ve)){t.f^=Ve;var r=t.nodes&&t.nodes.t;if(r!==null)for(const l of r)(l.is_global||n)&&e.push(l);for(var s=t.first;s!==null;){var i=s.next,a=(s.f&jn)!==0||(s.f&Gt)!==0&&(t.f&Bt)!==0;ha(s,e,a?n:!1),s=i}}}function Ws(t){pa(t,!0)}function pa(t,e){if(t.f&Ve){t.f^=Ve,t.f&Te||(Se(t,Ge),Sn(t));for(var n=t.first;n!==null;){var r=n.next,s=(n.f&jn)!==0||(n.f&Gt)!==0;pa(n,s?e:!1),n=r}var i=t.nodes&&t.nodes.t;if(i!==null)for(const a of i)(a.is_global||e)&&a.in()}}function da(t,e){if(t.nodes)for(var n=t.nodes.start,r=t.nodes.end;n!==null;){var s=n===r?null:_t(n);e.append(n),n=s}}let $n=!1;function as(t){$n=t}let In=!1;function ga(t){In=t}let O=null,zt=!1;function qe(t){O=t}let P=null;function Rt(t){P=t}let Zt=null;function va(t){O!==null&&(Zt===null?Zt=[t]:Zt.push(t))}let De=null,Xe=0,at=null;function mo(t){at=t}let ma=1,br=0,Cn=br;function _a(t){Cn=t}function ba(){return++ma}function wr(t){var e=t.f;if(e&Ge)return!0;if(e&_e&&(t.f&=~yn),e&Et){var n=t.deps;if(n!==null)for(var r=n.length,s=0;st.wv)return!0}e&mt&&rt===null&&Se(t,Te)}return!1}function wa(t,e,n=!0){var r=t.reactions;if(r!==null&&!Zt?.includes(t))for(var s=0;s{t.ac.abort(Yn)}),t.ac=null);try{t.f|=Ds;var u=t.fn,g=u(),p=t.deps;if(De!==null){var v;if(ls(t,Xe),p!==null&&Xe>0)for(p.length=Xe+De.length,v=0;vn?.call(this,i))}return t.startsWith("pointer")||t.startsWith("touch")||t==="wheel"?Xn(()=>{e.addEventListener(t,s,r)}):e.addEventListener(t,s,r),s}function ko(t,e,n,r,s){var i={capture:r,passive:s},a=xo(t,e,n,i);(e===document.body||e===window||e===document||e instanceof HTMLMediaElement)&&sa(()=>{e.removeEventListener(t,a,i)})}function yo(t){for(var e=0;e{throw _});throw p}}finally{t.__root=e,delete t.currentTarget,qe(u),Rt(g)}}}function Ys(t){var e=document.createElement("template");return e.innerHTML=t.replaceAll("",""),e.content}function wt(t,e){var n=P;n.nodes===null&&(n.nodes={start:t,end:e,a:null,t:null})}function he(t,e){var n=(e&Sl)!==0,r,s=!t.startsWith("");return()=>{if(C)return wt(L,null),L;r===void 0&&(r=Ys(s?t:""+t),r=Le(r));var i=n||Ji?document.importNode(r,!0):r.cloneNode(!0);return wt(i,i),i}}function To(t,e,n="svg"){var r=!t.startsWith(""),s=`<${n}>${r?t:""+t}`,i;return()=>{if(C)return wt(L,null),L;if(!i){var a=Ys(s),l=Le(a);for(i=document.createDocumentFragment();Le(l);)i.appendChild(Le(l))}var o=i.cloneNode(!0);{var c=Le(o),u=o.lastChild;wt(c,u)}return o}}function Sa(t,e){return To(t,e,"svg")}function Aa(t=""){if(!C){var e=We(t+"");return wt(e,e),e}var n=L;return n.nodeType!==Kr&&(n.before(n=We()),Ee(n)),wt(n,n),n}function tr(){if(C)return wt(L,null),L;var t=document.createDocumentFragment(),e=document.createComment(""),n=We();return t.append(e,n),wt(e,n),t}function G(t,e){if(C){var n=P;(!(n.f&Vr)||n.nodes.end===null)&&(n.nodes.end=L),Zn();return}t!==null&&t.before(e)}const Eo=["touchstart","touchmove"];function So(t){return Eo.includes(t)}function fn(t,e){var n=e==null?"":typeof e=="object"?e+"":e;n!==(t.__t??(t.__t=t.nodeValue))&&(t.__t=n,t.nodeValue=n+"")}function za(t,e){return Ra(t,e)}function Ao(t,e){Hs(),e.intro=e.intro??!1;const n=e.target,r=C,s=L;try{for(var i=Le(n);i&&(i.nodeType!==Tn||i.data!==Ri);)i=_t(i);if(!i)throw xn;jt(!0),Ee(i);const a=Ra(t,{...e,anchor:i});return jt(!1),a}catch(a){if(a instanceof Error&&a.message.split(` -`).some(l=>l.startsWith("https://svelte.dev/e/")))throw a;return a!==xn&&console.warn("Failed to hydrate: ",a),e.recover===!1&&Ul(),Hs(),Bs(n),jt(!1),za(t,e)}finally{jt(r),Ee(s)}}const nr=new Map;function Ra(t,{target:e,anchor:n,props:r={},events:s,context:i,intro:a=!0}){Hs();var l=new Set,o=g=>{for(var p=0;p{var g=n??e.appendChild(We());return Ql(g,{pending:()=>{}},p=>{if(i){Pi({});var v=nt;v.c=i}if(s&&(r.$$events=s),C&&wt(p,null),c=t(p,r)||{},C&&(P.nodes.end=L,L===null||L.nodeType!==Tn||L.data!==Is))throw gr(),xn;i&&Fi()}),()=>{for(var p of l){e.removeEventListener(p,kr);var v=nr.get(p);--v===0?(document.removeEventListener(p,kr),nr.delete(p)):nr.set(p,v)}js.delete(o),g!==n&&g.parentNode?.removeChild(g)}});return Zs.set(c,u),c}let Zs=new WeakMap;function zo(t,e){const n=Zs.get(t);return n?(Zs.delete(t),n(e)):Promise.resolve()}class Ro{constructor(e,n=!0){E(this,"anchor");D(this,kt,new Map);D(this,Dt,new Map);D(this,Je,new Map);D(this,Un,new Set);D(this,Nr,!0);D(this,Pr,()=>{var e=Y;if(h(this,kt).has(e)){var n=h(this,kt).get(e),r=h(this,Dt).get(n);if(r)Ws(r),h(this,Un).delete(n);else{var s=h(this,Je).get(n);s&&(h(this,Dt).set(n,s.effect),h(this,Je).delete(n),s.fragment.lastChild.remove(),this.anchor.before(s.fragment),r=s.effect)}for(const[i,a]of h(this,kt)){if(h(this,kt).delete(i),i===e)break;const l=h(this,Je).get(a);l&&(Oe(l.effect),h(this,Je).delete(a))}for(const[i,a]of h(this,Dt)){if(i===n||h(this,Un).has(i))continue;const l=()=>{if(Array.from(h(this,kt).values()).includes(i)){var c=document.createDocumentFragment();da(a,c),c.append(We()),h(this,Je).set(i,{effect:a,fragment:c})}else Oe(a);h(this,Un).delete(i),h(this,Dt).delete(i)};h(this,Nr)||!r?(h(this,Un).add(i),Rn(a,l,!1)):l()}}});D(this,ks,e=>{h(this,kt).delete(e);const n=Array.from(h(this,kt).values());for(const[r,s]of h(this,Je))n.includes(r)||(Oe(s.effect),h(this,Je).delete(r))});this.anchor=e,S(this,Nr,n)}ensure(e,n){var r=Y,s=na();if(n&&!h(this,Dt).has(e)&&!h(this,Je).has(e))if(s){var i=document.createDocumentFragment(),a=We();i.append(a),h(this,Je).set(e,{effect:it(()=>n(a)),fragment:i})}else h(this,Dt).set(e,it(()=>n(this.anchor)));if(h(this,kt).set(r,e),s){for(const[l,o]of h(this,Dt))l===e?r.skipped_effects.delete(o):r.skipped_effects.add(o);for(const[l,o]of h(this,Je))l===e?r.skipped_effects.delete(o.effect):r.skipped_effects.add(o.effect);r.oncommit(h(this,Pr)),r.ondiscard(h(this,ks))}else C&&(this.anchor=L),h(this,Pr).call(this)}}kt=new WeakMap,Dt=new WeakMap,Je=new WeakMap,Un=new WeakMap,Nr=new WeakMap,Pr=new WeakMap,ks=new WeakMap;function Ae(t,e,n=!1){C&&Zn();var r=new Ro(t),s=n?jn:0;function i(a,l){if(C){const c=Di(t)===Wr;if(a===c){var o=Qr();Ee(o),r.anchor=o,jt(!1),r.ensure(a,l),jt(!0);return}}r.ensure(a,l)}Gs(()=>{var a=!1;e((l,o=!0)=>{a=!0,i(o,l)}),a||i(!1,null)},s)}function $o(t,e){return e}function Io(t,e,n){for(var r=[],s=e.length,i,a=e.length,l=0;l{if(i){if(i.pending.delete(g),i.done.add(g),i.pending.size===0){var p=t.outrogroups;Vs(qr(i.done)),p.delete(i),p.size===0&&(t.outrogroups=null)}}else a-=1},!1)}if(a===0){var o=r.length===0&&n!==null;if(o){var c=n,u=c.parentNode;Bs(u),u.append(c),t.items.clear()}Vs(e,!o)}else i={pending:new Set(e),done:new Set},(t.outrogroups??(t.outrogroups=new Set)).add(i)}function Vs(t,e=!0){for(var n=0;n{var x=n();return $i(x)?x:x==null?[]:qr(x)}),p,v=!0;function b(){_.fallback=u,Co(_,p,a,e,r),u!==null&&(p.length===0?u.f&qt?(u.f^=qt,yr(u,null,a)):Ws(u):Rn(u,()=>{u=null}))}var R=Gs(()=>{p=d(g);var x=p.length;let U=!1;if(C){var H=Di(a)===Wr;H!==(x===0)&&(a=Qr(),Ee(a),jt(!1),U=!0)}for(var M=new Set,ve=Y,we=na(),ee=0;eei(a)):(u=it(()=>i($a??($a=We()))),u.f|=qt)),C&&x>0&&Ee(Qr()),!v)if(we){for(const[pe,Hn]of l)M.has(pe)||ve.skipped_effects.add(Hn.e);ve.oncommit(b),ve.ondiscard(()=>{})}else b();U&&jt(!0),d(g)}),_={effect:R,items:l,outrogroups:null,fallback:u};v=!1,C&&(a=L)}function Co(t,e,n,r,s){var i=(r&Tl)!==0,a=e.length,l=t.items,o=t.effect.first,c,u=null,g,p=[],v=[],b,R,_,x;if(i)for(x=0;x0){var et=r&dr&&a===0?n:null;if(i){for(x=0;x{if(g!==void 0)for(_ of g)_.nodes?.a?.apply()})}function Lo(t,e,n,r,s,i,a,l){var o=a&Z?a&El?An(n):Xi(n,!1,!1):null,c=a&ue?An(s):null;return{v:o,i:c,e:it(()=>(i(e,o??n,c??s,l),()=>{t.delete(r)}))}}function yr(t,e,n){if(t.nodes)for(var r=t.nodes.start,s=t.nodes.end,i=e&&!(e.f&qt)?e.nodes.start:n;r!==null;){var a=_t(r);if(i.before(r),r===s)return;r=a}}function un(t,e,n){e===null?t.effect.first=n:e.next=n,n===null?t.effect.last=e:n.prev=e}function Oo(t,e,n=!1,r=!1,s=!1){var i=t,a="";bt(()=>{var l=P;if(a===(a=e()??"")){C&&Zn();return}if(l.nodes!==null&&(fa(l.nodes.start,l.nodes.end),l.nodes=null),a!==""){if(C){L.data;for(var o=Zn(),c=o;o!==null&&(o.nodeType!==Tn||o.data!=="");)c=o,o=_t(o);if(o===null)throw gr(),xn;wt(L,c),i=Ee(o);return}var u=a+"";n?u=`${u}`:r&&(u=`${u}`);var g=Ys(u);if((n||r)&&(g=Le(g)),wt(Le(g),g.lastChild),n||r)for(;Le(g);)i.before(Le(g));else i.before(g)}})}function Do(t,e){la(()=>{var n=t.getRootNode(),r=n.host?n:n.head??n.ownerDocument.head;if(!r.querySelector("#"+e.hash)){const s=document.createElement("style");s.id=e.hash,s.textContent=e.code,r.appendChild(s)}})}const Ca=[...` -\r\f \v\uFEFF`];function Mo(t,e,n){var r=t==null?"":""+t;if(n){for(var s in n)if(n[s])r=r?r+" "+s:s;else if(r.length)for(var i=s.length,a=0;(a=r.indexOf(s,a))>=0;){var l=a+i;(a===0||Ca.includes(r[a-1]))&&(l===r.length||Ca.includes(r[l]))?r=(a===0?"":r.substring(0,a))+r.substring(l+1):a=l}}return r===""?null:r}function No(t,e){return t==null?null:String(t)}function Tr(t,e,n,r,s,i){var a=t.__className;if(C||a!==n||a===void 0){var l=Mo(n,r,i);(!C||l!==t.getAttribute("class"))&&(l==null?t.removeAttribute("class"):t.className=l),t.__className=n}else if(i&&s!==i)for(var o in i){var c=!!i[o];(s==null||c!==!!s[o])&&t.classList.toggle(o,c)}return i}function Po(t,e,n,r){var s=t.__style;if(C||s!==e){var i=No(e);(!C||i!==t.getAttribute("style"))&&(i==null?t.removeAttribute("style"):t.style.cssText=i),t.__style=e}return r}function Fo(t,e,n=e){var r=new WeakSet;co(t,"input",async s=>{var i=s?t.defaultValue:t.value;if(i=Xs(t)?Ks(i):i,n(i),Y!==null&&r.add(Y),await bo(),i!==(i=e())){var a=t.selectionStart,l=t.selectionEnd,o=t.value.length;if(t.value=i??"",l!==null){var c=t.value.length;a===l&&l===o&&c>o?(t.selectionStart=c,t.selectionEnd=c):(t.selectionStart=a,t.selectionEnd=Math.min(l,c))}}}),(C&&t.defaultValue!==t.value||qs(e)==null&&t.value)&&(n(Xs(t)?Ks(t.value):t.value),Y!==null&&r.add(Y)),is(()=>{var s=e();if(t===document.activeElement){var i=es??Y;if(r.has(i))return}Xs(t)&&s===Ks(t.value)||t.type==="date"&&!s&&!t.value||s!==t.value&&(t.value=s??"")})}function Xs(t){var e=t.type;return e==="number"||e==="range"}function Ks(t){return t===""?null:+t}function La(t,e){return t===e||t?.[Xr]===e}function Oa(t={},e,n,r){return la(()=>{var s,i;return is(()=>{s=i,i=[],qs(()=>{t!==n(...i)&&(e(t,...i),s&&La(n(...s),t)&&e(null,...s))})}),()=>{Xn(()=>{i&&La(n(...i),t)&&e(null,...i)})}}),t}function os(t,e,n,r){var s=r,i=!0,a=()=>(i&&(i=!1,s=r),s),l;l=t[e],l===void 0&&r!==void 0&&(l=a());var o;o=()=>{var p=t[e];return p===void 0?a():(i=!0,p)};var c=!1,u=rs(()=>(c=!1,o())),g=P;return function(p,v){if(arguments.length>0){const b=v?d(u):p;return T(u,b),c=!0,s!==void 0&&(s=b),p}return In&&c||g.f&Wt?u.v:d(u)}}function Uo(t){return new Ho(t)}class Ho{constructor(e){D(this,Qt);D(this,ft);var n=new Map,r=(i,a)=>{var l=Xi(a,!1,!1);return n.set(i,l),l};const s=new Proxy({...e.props||{},$$events:{}},{get(i,a){return d(n.get(a)??r(a,Reflect.get(i,a)))},has(i,a){return a===Ol?!0:(d(n.get(a)??r(a,Reflect.get(i,a))),Reflect.has(i,a))},set(i,a,l){return T(n.get(a)??r(a,l),l),Reflect.set(i,a,l)}});S(this,ft,(e.hydrate?Ao:za)(e.component,{target:e.target,anchor:e.anchor,props:s,context:e.context,intro:e.intro??!1,recover:e.recover})),(!e?.props?.$$host||e.sync===!1)&&Qn(),S(this,Qt,s.$$events);for(const i of Object.keys(h(this,ft)))i==="$set"||i==="$destroy"||i==="$on"||Yr(this,i,{get(){return h(this,ft)[i]},set(a){h(this,ft)[i]=a},enumerable:!0});h(this,ft).$set=i=>{Object.assign(s,i)},h(this,ft).$destroy=()=>{zo(h(this,ft))}}$set(e){h(this,ft).$set(e)}$on(e,n){h(this,Qt)[e]=h(this,Qt)[e]||[];const r=(...s)=>n.call(this,...s);return h(this,Qt)[e].push(r),()=>{h(this,Qt)[e]=h(this,Qt)[e].filter(s=>s!==r)}}$destroy(){h(this,ft).$destroy()}}Qt=new WeakMap,ft=new WeakMap;let Da;typeof HTMLElement=="function"&&(Da=class extends HTMLElement{constructor(e,n,r){super();E(this,"$$ctor");E(this,"$$s");E(this,"$$c");E(this,"$$cn",!1);E(this,"$$d",{});E(this,"$$r",!1);E(this,"$$p_d",{});E(this,"$$l",{});E(this,"$$l_u",new Map);E(this,"$$me");this.$$ctor=e,this.$$s=n,r&&this.attachShadow({mode:"open"})}addEventListener(e,n,r){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const s=this.$$c.$on(e,n);this.$$l_u.set(n,s)}super.addEventListener(e,n,r)}removeEventListener(e,n,r){if(super.removeEventListener(e,n,r),this.$$c){const s=this.$$l_u.get(n);s&&(s(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(s){return i=>{const a=document.createElement("slot");s!=="default"&&(a.name=s),G(i,a)}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},r=Bo(this);for(const s of this.$$s)s in r&&(s==="default"&&!this.$$d.children?(this.$$d.children=e(s),n.default=!0):n[s]=e(s));for(const s of this.attributes){const i=this.$$g_p(s.name);i in this.$$d||(this.$$d[i]=cs(i,s.value,this.$$p_d,"toProp"))}for(const s in this.$$p_d)!(s in this.$$d)&&this[s]!==void 0&&(this.$$d[s]=this[s],delete this[s]);this.$$c=Uo({component:this.$$ctor,target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$host:this}}),this.$$me=ho(()=>{is(()=>{this.$$r=!0;for(const s of jr(this.$$c)){if(!this.$$p_d[s]?.reflect)continue;this.$$d[s]=this.$$c[s];const i=cs(s,this.$$d[s],this.$$p_d,"toAttribute");i==null?this.removeAttribute(this.$$p_d[s].attribute||s):this.setAttribute(this.$$p_d[s].attribute||s,i)}this.$$r=!1})});for(const s in this.$$l)for(const i of this.$$l[s]){const a=this.$$c.$on(s,i);this.$$l_u.set(i,a)}this.$$l={}}}attributeChangedCallback(e,n,r){this.$$r||(e=this.$$g_p(e),this.$$d[e]=cs(e,r,this.$$p_d,"toProp"),this.$$c?.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{!this.$$cn&&this.$$c&&(this.$$c.$destroy(),this.$$me(),this.$$c=void 0)})}$$g_p(e){return jr(this.$$p_d).find(n=>this.$$p_d[n].attribute===e||!this.$$p_d[n].attribute&&n.toLowerCase()===e)||e}});function cs(t,e,n,r){const s=n[t]?.type;if(e=s==="Boolean"&&typeof e!="boolean"?e!=null:e,!r||!n[t])return e;if(r==="toAttribute")switch(s){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(s){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function Bo(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}function Go(t,e,n,r,s,i){let a=class extends Da{constructor(){super(t,n,s),this.$$p_d=e}static get observedAttributes(){return jr(e).map(l=>(e[l].attribute||l).toLowerCase())}};return jr(e).forEach(l=>{Yr(a.prototype,l,{get(){return this.$$c&&l in this.$$c?this.$$c[l]:this.$$d[l]},set(o){o=cs(l,o,e),this.$$d[l]=o;var c=this.$$c;if(c){var u=qn(c,l)?.get;u?c[l]=o:c.$set({[l]:o})}}})}),r.forEach(l=>{Yr(a.prototype,l,{get(){return this.$$c?.[l]}})}),t.element=a,a}const Ma="lc_chatbot:";function Er(t,e=null){try{const n=localStorage.getItem(Ma+t);return n?JSON.parse(n):e}catch(n){return console.warn(`[lc-chatbot] Failed to read ${t} from storage:`,n),e}}function hn(t,e){try{localStorage.setItem(Ma+t,JSON.stringify(e))}catch(n){console.warn(`[lc-chatbot] Failed to write ${t} to storage:`,n)}}const Ke={SIZE:"size",SESSION:"session",DRAFT:"draft",UI:"ui",MESSAGES:"messages"},Wo=30;function qo(){return"sess_"+crypto.randomUUID()}function Na(){return"msg_"+crypto.randomUUID()}function jo(t){if(!t)return!0;const e=new Date(t).getTime();return(Date.now()-e)/(1e3*60)>Wo}function Yo(t=!1){const e=Er(Ke.SESSION,null);if(t||!e||jo(e.lastActivity)){const n=qo(),r={sessionId:n,lastActivity:new Date().toISOString()};return hn(Ke.SESSION,r),{sessionId:n,isNew:!0}}return{sessionId:e.sessionId,isNew:!1}}function Zo(t){hn(Ke.SESSION,{sessionId:t,lastActivity:new Date().toISOString()})}const Vo="1.0.0";async function Xo(t,e,n,r,s={}){const i=Na(),a=new Date().toISOString(),l={userId:e,sessionId:n,messageId:i,timestamp:a,text:r,context:{pageUrl:window.location.href,locale:navigator.language||"en",clientVersion:Vo}},o=await fetch(`${t}/chat/stream`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!o.ok){const v=new Error(`Chat request failed: ${o.status}`);throw v.status=o.status,v}const c=o.body.getReader(),u=new TextDecoder;let g="",p=null;for(;;){const{done:v,value:b}=await c.read();if(v)break;g+=u.decode(b,{stream:!0});const R=g.split(` -`);g=R.pop()||"";let _=null,x="";for(const U of R)if(U.startsWith("event: "))_=U.slice(7).trim();else if(U.startsWith("data: ")){if(x=U.slice(6),_&&x)try{const H=JSON.parse(x);_==="progress"&&s.onProgress?s.onProgress(H):_==="message"?(p={messageId:H.messageId,sessionId:H.sessionId,timestamp:H.timestamp,markdown:H.markdown,toolCalls:H.toolCalls,stats:H.stats},s.onMessage&&s.onMessage(p)):_==="error"&&s.onError&&s.onError(H.error)}catch(H){console.warn("[lc-chatbot] Failed to parse SSE data:",H)}_=null,x=""}else U.startsWith(":")||U===""&&(_=null,x="")}if(!p)throw new Error("Stream ended without message");return p}async function Pa(t,e,n,r=null,s=20){const i=new URLSearchParams({userId:e,sessionId:n,limit:String(s)});r&&i.set("before",r);const a=await fetch(`${t}/history?${i}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!a.ok){const o=new Error(`History request failed: ${a.status}`);throw o.status=a.status,o}const l=await a.json();return{messages:l.messages||[],hasMore:l.hasMore??!1}}function Qs(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Ln=Qs();function Fa(t){Ln=t}var Sr={exec:()=>null};function W(t,e=""){let n=typeof t=="string"?t:t.source;const r={replace:(s,i)=>{let a=typeof i=="string"?i:i.source;return a=a.replace(Me.caret,"$1"),n=n.replace(s,a),r},getRegex:()=>new RegExp(n,e)};return r}var Me={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:/^/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^$/,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:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i")},Ko=/^(?:[ \t]*(?:\n|$))+/,Qo=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Jo=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Ar=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,ec=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Js=/(?:[*+-]|\d{1,9}[.)])/,Ua=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Ha=W(Ua).replace(/bull/g,Js).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(),tc=W(Ua).replace(/bull/g,Js).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(),ei=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,nc=/^[^\n]+/,ti=/(?!\s*\])(?:\\.|[^\[\]\\])+/,rc=W(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ti).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),sc=W(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Js).getRegex(),fs="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",ni=/|$))/,ic=W("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|\\n*|$)|\\n*|$)|)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",ni).replace("tag",fs).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ba=W(ei).replace("hr",Ar).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",")|<(?:script|pre|style|textarea|!--)").replace("tag",fs).getRegex(),ac=W(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ba).getRegex(),ri={blockquote:ac,code:Qo,def:rc,fences:Jo,heading:ec,hr:Ar,html:ic,lheading:Ha,list:sc,newline:Ko,paragraph:Ba,table:Sr,text:nc},Ga=W("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Ar).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",")|<(?:script|pre|style|textarea|!--)").replace("tag",fs).getRegex(),lc={...ri,lheading:tc,table:Ga,paragraph:W(ei).replace("hr",Ar).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Ga).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",fs).getRegex()},oc={...ri,html:W(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ni).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:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Sr,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:W(ei).replace("hr",Ar).replace("heading",` *#{1,6} *[^ -]`).replace("lheading",Ha).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},cc=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,fc=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Wa=/^( {2,}|\\)\n(?!\s*$)/,uc=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\]*?>/g,Ya=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,vc=W(Ya,"u").replace(/punct/g,us).getRegex(),mc=W(Ya,"u").replace(/punct/g,ja).getRegex(),Za="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",_c=W(Za,"gu").replace(/notPunctSpace/g,qa).replace(/punctSpace/g,si).replace(/punct/g,us).getRegex(),bc=W(Za,"gu").replace(/notPunctSpace/g,dc).replace(/punctSpace/g,pc).replace(/punct/g,ja).getRegex(),wc=W("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,qa).replace(/punctSpace/g,si).replace(/punct/g,us).getRegex(),xc=W(/\\(punct)/,"gu").replace(/punct/g,us).getRegex(),kc=W(/^<(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(),yc=W(ni).replace("(?:-->|$)","-->").getRegex(),Tc=W("^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^").replace("comment",yc).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),hs=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Ec=W(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",hs).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Va=W(/^!?\[(label)\]\[(ref)\]/).replace("label",hs).replace("ref",ti).getRegex(),Xa=W(/^!?\[(ref)\](?:\[\])?/).replace("ref",ti).getRegex(),Sc=W("reflink|nolink(?!\\()","g").replace("reflink",Va).replace("nolink",Xa).getRegex(),ii={_backpedal:Sr,anyPunctuation:xc,autolink:kc,blockSkip:gc,br:Wa,code:fc,del:Sr,emStrongLDelim:vc,emStrongRDelimAst:_c,emStrongRDelimUnd:wc,escape:cc,link:Ec,nolink:Xa,punctuation:hc,reflink:Va,reflinkSearch:Sc,tag:Tc,text:uc,url:Sr},Ac={...ii,link:W(/^!?\[(label)\]\((.*?)\)/).replace("label",hs).getRegex(),reflink:W(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",hs).getRegex()},ai={...ii,emStrongRDelimAst:bc,emStrongLDelim:mc,url:W(/^((?: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]*?(?:(?=[\\":">",'"':""","'":"'"},Ka=t=>Rc[t];function $t(t,e){if(e){if(Me.escapeTest.test(t))return t.replace(Me.escapeReplace,Ka)}else if(Me.escapeTestNoEncode.test(t))return t.replace(Me.escapeReplaceNoEncode,Ka);return t}function Qa(t){try{t=encodeURI(t).replace(Me.percentDecode,"%")}catch{return null}return t}function Ja(t,e){const n=t.replace(Me.findPipe,(i,a,l)=>{let o=!1,c=a;for(;--c>=0&&l[c]==="\\";)o=!o;return o?"|":" |"}),r=n.split(Me.splitPipe);let s=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),e)if(r.length>e)r.splice(e);else for(;r.length0?-2:-1}function el(t,e,n,r,s){const i=e.href,a=e.title||null,l=t[1].replace(s.other.outputLinkReplace,"$1");r.state.inLink=!0;const o={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:a,text:l,tokens:r.inlineTokens(l)};return r.state.inLink=!1,o}function Ic(t,e,n){const r=t.match(n.other.indentCodeCompensation);if(r===null)return e;const s=r[1];return e.split(` -`).map(i=>{const a=i.match(n.other.beginningSpace);if(a===null)return i;const[l]=a;return l.length>=s.length?i.slice(s.length):i}).join(` -`)}var ds=class{constructor(t){E(this,"options");E(this,"rules");E(this,"lexer");this.options=t||Ln}space(t){const e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){const e=this.rules.block.code.exec(t);if(e){const n=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?n:Rr(n,` -`)}}}fences(t){const e=this.rules.block.fences.exec(t);if(e){const n=e[0],r=Ic(n,e[3]||"",this.rules);return{type:"code",raw:n,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:r}}}heading(t){const e=this.rules.block.heading.exec(t);if(e){let n=e[2].trim();if(this.rules.other.endingHash.test(n)){const r=Rr(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(t){const e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:Rr(e[0],` -`)}}blockquote(t){const e=this.rules.block.blockquote.exec(t);if(e){let n=Rr(e[0],` -`).split(` -`),r="",s="";const i=[];for(;n.length>0;){let a=!1;const l=[];let o;for(o=0;o1,s={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");const i=this.rules.other.listItemRegex(n);let a=!1;for(;t;){let o=!1,c="",u="";if(!(e=i.exec(t))||this.rules.block.hr.test(t))break;c=e[0],t=t.substring(c.length);let g=e[2].split(` -`,1)[0].replace(this.rules.other.listReplaceTabs,x=>" ".repeat(3*x.length)),p=t.split(` -`,1)[0],v=!g.trim(),b=0;if(this.options.pedantic?(b=2,u=g.trimStart()):v?b=e[1].length+1:(b=e[2].search(this.rules.other.nonSpaceChar),b=b>4?1:b,u=g.slice(b),b+=e[1].length),v&&this.rules.other.blankLine.test(p)&&(c+=p+` -`,t=t.substring(p.length+1),o=!0),!o){const x=this.rules.other.nextBulletRegex(b),U=this.rules.other.hrRegex(b),H=this.rules.other.fencesBeginRegex(b),M=this.rules.other.headingBeginRegex(b),ve=this.rules.other.htmlBeginRegex(b);for(;t;){const we=t.split(` -`,1)[0];let ee;if(p=we,this.options.pedantic?(p=p.replace(this.rules.other.listReplaceNesting," "),ee=p):ee=p.replace(this.rules.other.tabCharGlobal," "),H.test(p)||M.test(p)||ve.test(p)||x.test(p)||U.test(p))break;if(ee.search(this.rules.other.nonSpaceChar)>=b||!p.trim())u+=` -`+ee.slice(b);else{if(v||g.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||H.test(g)||M.test(g)||U.test(g))break;u+=` -`+p}!v&&!p.trim()&&(v=!0),c+=we+` -`,t=t.substring(we.length+1),g=ee.slice(b)}}s.loose||(a?s.loose=!0:this.rules.other.doubleBlankLine.test(c)&&(a=!0));let R=null,_;this.options.gfm&&(R=this.rules.other.listIsTask.exec(u),R&&(_=R[0]!=="[ ] ",u=u.replace(this.rules.other.listReplaceTask,""))),s.items.push({type:"list_item",raw:c,task:!!R,checked:_,loose:!1,text:u,tokens:[]}),s.raw+=c}const l=s.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;s.raw=s.raw.trimEnd();for(let o=0;og.type==="space"),u=c.length>0&&c.some(g=>this.rules.other.anyLine.test(g.raw));s.loose=u}if(s.loose)for(let o=0;o({text:l,tokens:this.lexer.inline(l),header:!1,align:i.align[o]})));return i}}lheading(t){const e=this.rules.block.lheading.exec(t);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(t){const e=this.rules.block.paragraph.exec(t);if(e){const n=e[1].charAt(e[1].length-1)===` -`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){const e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){const e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){const e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){const e=this.rules.inline.link.exec(t);if(e){const n=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;const i=Rr(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{const i=$c(e[2],"()");if(i===-2)return;if(i>-1){const l=(e[0].indexOf("!")===0?5:4)+e[1].length+i;e[2]=e[2].substring(0,i),e[0]=e[0].substring(0,l).trim(),e[3]=""}}let r=e[2],s="";if(this.options.pedantic){const i=this.rules.other.pedanticHrefTitle.exec(r);i&&(r=i[1],s=i[3])}else s=e[3]?e[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?r=r.slice(1):r=r.slice(1,-1)),el(e,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(t,e){let n;if((n=this.rules.inline.reflink.exec(t))||(n=this.rules.inline.nolink.exec(t))){const r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),s=e[r.toLowerCase()];if(!s){const i=n[0].charAt(0);return{type:"text",raw:i,text:i}}return el(n,s,n[0],this.lexer,this.rules)}}emStrong(t,e,n=""){let r=this.rules.inline.emStrongLDelim.exec(t);if(!r||r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))return;if(!(r[1]||r[2]||"")||!n||this.rules.inline.punctuation.exec(n)){const i=[...r[0]].length-1;let a,l,o=i,c=0;const u=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(u.lastIndex=0,e=e.slice(-1*t.length+i);(r=u.exec(e))!=null;){if(a=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!a)continue;if(l=[...a].length,r[3]||r[4]){o+=l;continue}else if((r[5]||r[6])&&i%3&&!((i+l)%3)){c+=l;continue}if(o-=l,o>0)continue;l=Math.min(l,l+o+c);const g=[...r[0]][0].length,p=t.slice(0,i+r.index+g+l);if(Math.min(i,l)%2){const b=p.slice(1,-1);return{type:"em",raw:p,text:b,tokens:this.lexer.inlineTokens(b)}}const v=p.slice(2,-2);return{type:"strong",raw:p,text:v,tokens:this.lexer.inlineTokens(v)}}}}codespan(t){const e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(this.rules.other.newLineCharGlobal," ");const r=this.rules.other.nonSpaceChar.test(n),s=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&s&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:e[0],text:n}}}br(t){const e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t){const e=this.rules.inline.del.exec(t);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(t){const e=this.rules.inline.autolink.exec(t);if(e){let n,r;return e[2]==="@"?(n=e[1],r="mailto:"+n):(n=e[1],r=n),{type:"link",raw:e[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let n,r;if(e[2]==="@")n=e[0],r="mailto:"+n;else{let s;do s=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(s!==e[0]);n=e[0],e[1]==="www."?r="http://"+e[0]:r=e[0]}return{type:"link",raw:e[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(t){const e=this.rules.inline.text.exec(t);if(e){const n=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:n}}}},Vt=class Ai{constructor(e){E(this,"tokens");E(this,"options");E(this,"state");E(this,"tokenizer");E(this,"inlineQueue");this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Ln,this.options.tokenizer=this.options.tokenizer||new ds,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={other:Me,block:ps.normal,inline:zr.normal};this.options.pedantic?(n.block=ps.pedantic,n.inline=zr.pedantic):this.options.gfm&&(n.block=ps.gfm,this.options.breaks?n.inline=zr.breaks:n.inline=zr.gfm),this.tokenizer.rules=n}static get rules(){return{block:ps,inline:zr}}static lex(e,n){return new Ai(n).lex(e)}static lexInline(e,n){return new Ai(n).inlineTokens(e)}lex(e){e=e.replace(Me.carriageReturn,` -`),this.blockTokens(e,this.tokens);for(let n=0;n(s=a.call({lexer:this},e,n))?(e=e.substring(s.raw.length),n.push(s),!0):!1))continue;if(s=this.tokenizer.space(e)){e=e.substring(s.raw.length);const a=n.at(-1);s.raw.length===1&&a!==void 0?a.raw+=` -`:n.push(s);continue}if(s=this.tokenizer.code(e)){e=e.substring(s.raw.length);const a=n.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=` -`+s.raw,a.text+=` -`+s.text,this.inlineQueue.at(-1).src=a.text):n.push(s);continue}if(s=this.tokenizer.fences(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.heading(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.hr(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.blockquote(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.list(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.html(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.def(e)){e=e.substring(s.raw.length);const a=n.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=` -`+s.raw,a.text+=` -`+s.raw,this.inlineQueue.at(-1).src=a.text):this.tokens.links[s.tag]||(this.tokens.links[s.tag]={href:s.href,title:s.title});continue}if(s=this.tokenizer.table(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.lheading(e)){e=e.substring(s.raw.length),n.push(s);continue}let i=e;if(this.options.extensions?.startBlock){let a=1/0;const l=e.slice(1);let o;this.options.extensions.startBlock.forEach(c=>{o=c.call({lexer:this},l),typeof o=="number"&&o>=0&&(a=Math.min(a,o))}),a<1/0&&a>=0&&(i=e.substring(0,a+1))}if(this.state.top&&(s=this.tokenizer.paragraph(i))){const a=n.at(-1);r&&a?.type==="paragraph"?(a.raw+=` -`+s.raw,a.text+=` -`+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):n.push(s),r=i.length!==e.length,e=e.substring(s.raw.length);continue}if(s=this.tokenizer.text(e)){e=e.substring(s.raw.length);const a=n.at(-1);a?.type==="text"?(a.raw+=` -`+s.raw,a.text+=` -`+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):n.push(s);continue}if(e){const a="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}inlineTokens(e,n=[]){let r=e,s=null;if(this.tokens.links){const l=Object.keys(this.tokens.links);if(l.length>0)for(;(s=this.tokenizer.rules.inline.reflinkSearch.exec(r))!=null;)l.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(s=this.tokenizer.rules.inline.anyPunctuation.exec(r))!=null;)r=r.slice(0,s.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(s=this.tokenizer.rules.inline.blockSkip.exec(r))!=null;)r=r.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let i=!1,a="";for(;e;){i||(a=""),i=!1;let l;if(this.options.extensions?.inline?.some(c=>(l=c.call({lexer:this},e,n))?(e=e.substring(l.raw.length),n.push(l),!0):!1))continue;if(l=this.tokenizer.escape(e)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.tag(e)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.link(e)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(l.raw.length);const c=n.at(-1);l.type==="text"&&c?.type==="text"?(c.raw+=l.raw,c.text+=l.text):n.push(l);continue}if(l=this.tokenizer.emStrong(e,r,a)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.codespan(e)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.br(e)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.del(e)){e=e.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.autolink(e)){e=e.substring(l.raw.length),n.push(l);continue}if(!this.state.inLink&&(l=this.tokenizer.url(e))){e=e.substring(l.raw.length),n.push(l);continue}let o=e;if(this.options.extensions?.startInline){let c=1/0;const u=e.slice(1);let g;this.options.extensions.startInline.forEach(p=>{g=p.call({lexer:this},u),typeof g=="number"&&g>=0&&(c=Math.min(c,g))}),c<1/0&&c>=0&&(o=e.substring(0,c+1))}if(l=this.tokenizer.inlineText(o)){e=e.substring(l.raw.length),l.raw.slice(-1)!=="_"&&(a=l.raw.slice(-1)),i=!0;const c=n.at(-1);c?.type==="text"?(c.raw+=l.raw,c.text+=l.text):n.push(l);continue}if(e){const c="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(c);break}else throw new Error(c)}}return n}},gs=class{constructor(t){E(this,"options");E(this,"parser");this.options=t||Ln}space(t){return""}code({text:t,lang:e,escaped:n}){const r=(e||"").match(Me.notSpaceStart)?.[0],s=t.replace(Me.endingNewline,"")+` -`;return r?'
    '+(n?s:$t(s,!0))+`
    -`:"
    "+(n?s:$t(s,!0))+`
    -`}blockquote({tokens:t}){return`
    -${this.parser.parse(t)}
    -`}html({text:t}){return t}heading({tokens:t,depth:e}){return`${this.parser.parseInline(t)} -`}hr(t){return`
    -`}list(t){const e=t.ordered,n=t.start;let r="";for(let a=0;a -`+r+" -`}listitem(t){let e="";if(t.task){const n=this.checkbox({checked:!!t.checked});t.loose?t.tokens[0]?.type==="paragraph"?(t.tokens[0].text=n+" "+t.tokens[0].text,t.tokens[0].tokens&&t.tokens[0].tokens.length>0&&t.tokens[0].tokens[0].type==="text"&&(t.tokens[0].tokens[0].text=n+" "+$t(t.tokens[0].tokens[0].text),t.tokens[0].tokens[0].escaped=!0)):t.tokens.unshift({type:"text",raw:n+" ",text:n+" ",escaped:!0}):e+=n+" "}return e+=this.parser.parse(t.tokens,!!t.loose),`
  • ${e}
  • -`}checkbox({checked:t}){return"'}paragraph({tokens:t}){return`

    ${this.parser.parseInline(t)}

    -`}table(t){let e="",n="";for(let s=0;s${r}`),` - -`+e+` -`+r+`
    -`}tablerow({text:t}){return` -${t} -`}tablecell(t){const e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+` -`}strong({tokens:t}){return`${this.parser.parseInline(t)}`}em({tokens:t}){return`${this.parser.parseInline(t)}`}codespan({text:t}){return`${$t(t,!0)}`}br(t){return"
    "}del({tokens:t}){return`${this.parser.parseInline(t)}`}link({href:t,title:e,tokens:n}){const r=this.parser.parseInline(n),s=Qa(t);if(s===null)return r;t=s;let i='
    ",i}image({href:t,title:e,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));const s=Qa(t);if(s===null)return $t(n);t=s;let i=`${n}{const a=s[i].flat(1/0);n=n.concat(this.walkTokens(a,e))}):s.tokens&&(n=n.concat(this.walkTokens(s.tokens,e)))}}return n}use(...t){const e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{const r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s){const i=e.renderers[s.name];i?e.renderers[s.name]=function(...a){let l=s.renderer.apply(this,a);return l===!1&&(l=i.apply(this,a)),l}:e.renderers[s.name]=s.renderer}if("tokenizer"in s){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const i=e[s.level];i?i.unshift(s.tokenizer):e[s.level]=[s.tokenizer],s.start&&(s.level==="block"?e.startBlock?e.startBlock.push(s.start):e.startBlock=[s.start]:s.level==="inline"&&(e.startInline?e.startInline.push(s.start):e.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(e.childTokens[s.name]=s.childTokens)}),r.extensions=e),n.renderer){const s=this.defaults.renderer||new gs(this.defaults);for(const i in n.renderer){if(!(i in s))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;const a=i,l=n.renderer[a],o=s[a];s[a]=(...c)=>{let u=l.apply(s,c);return u===!1&&(u=o.apply(s,c)),u||""}}r.renderer=s}if(n.tokenizer){const s=this.defaults.tokenizer||new ds(this.defaults);for(const i in n.tokenizer){if(!(i in s))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;const a=i,l=n.tokenizer[a],o=s[a];s[a]=(...c)=>{let u=l.apply(s,c);return u===!1&&(u=o.apply(s,c)),u}}r.tokenizer=s}if(n.hooks){const s=this.defaults.hooks||new vs;for(const i in n.hooks){if(!(i in s))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;const a=i,l=n.hooks[a],o=s[a];vs.passThroughHooks.has(i)?s[a]=c=>{if(this.defaults.async)return Promise.resolve(l.call(s,c)).then(g=>o.call(s,g));const u=l.call(s,c);return o.call(s,u)}:s[a]=(...c)=>{let u=l.apply(s,c);return u===!1&&(u=o.apply(s,c)),u}}r.hooks=s}if(n.walkTokens){const s=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(a){let l=[];return l.push(i.call(this,a)),s&&(l=l.concat(s.call(this,a))),l}}this.defaults={...this.defaults,...r}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return Vt.lex(t,e??this.defaults)}parser(t,e){return Xt.parse(t,e??this.defaults)}parseMarkdown(t){return(n,r)=>{const s={...r},i={...this.defaults,...s},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&s.async===!1)return a(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 n>"u"||n===null)return a(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return a(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));i.hooks&&(i.hooks.options=i,i.hooks.block=t);const l=i.hooks?i.hooks.provideLexer():t?Vt.lex:Vt.lexInline,o=i.hooks?i.hooks.provideParser():t?Xt.parse:Xt.parseInline;if(i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(n):n).then(c=>l(c,i)).then(c=>i.hooks?i.hooks.processAllTokens(c):c).then(c=>i.walkTokens?Promise.all(this.walkTokens(c,i.walkTokens)).then(()=>c):c).then(c=>o(c,i)).then(c=>i.hooks?i.hooks.postprocess(c):c).catch(a);try{i.hooks&&(n=i.hooks.preprocess(n));let c=l(n,i);i.hooks&&(c=i.hooks.processAllTokens(c)),i.walkTokens&&this.walkTokens(c,i.walkTokens);let u=o(c,i);return i.hooks&&(u=i.hooks.postprocess(u)),u}catch(c){return a(c)}}}onError(t,e){return n=>{if(n.message+=` -Please report this to https://github.com/markedjs/marked.`,t){const r="

    An error occurred:

    "+$t(n.message+"",!0)+"
    ";return e?Promise.resolve(r):r}if(e)return Promise.reject(n);throw n}}},On=new Cc;function F(t,e){return On.parse(t,e)}F.options=F.setOptions=function(t){return On.setOptions(t),F.defaults=On.defaults,Fa(F.defaults),F},F.getDefaults=Qs,F.defaults=Ln,F.use=function(...t){return On.use(...t),F.defaults=On.defaults,Fa(F.defaults),F},F.walkTokens=function(t,e){return On.walkTokens(t,e)},F.parseInline=On.parseInline,F.Parser=Xt,F.parser=Xt.parse,F.Renderer=gs,F.TextRenderer=li,F.Lexer=Vt,F.lexer=Vt.lex,F.Tokenizer=ds,F.Hooks=vs,F.parse=F,F.options,F.setOptions,F.use,F.walkTokens,F.parseInline,Xt.parse,Vt.lex;/*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE */const{entries:tl,setPrototypeOf:nl,isFrozen:Lc,getPrototypeOf:Oc,getOwnPropertyDescriptor:Dc}=Object;let{freeze:Ne,seal:lt,create:oi}=Object,{apply:ci,construct:fi}=typeof Reflect<"u"&&Reflect;Ne||(Ne=function(e){return e}),lt||(lt=function(e){return e}),ci||(ci=function(e,n){for(var r=arguments.length,s=new Array(r>2?r-2:0),i=2;i1?n-1:0),s=1;s1?n-1:0),s=1;s2&&arguments[2]!==void 0?arguments[2]:_s;nl&&nl(t,null);let r=e.length;for(;r--;){let s=e[r];if(typeof s=="string"){const i=n(s);i!==s&&(Lc(e)||(e[r]=i),s=i)}t[s]=!0}return t}function Hc(t){for(let e=0;e/gm),jc=lt(/\$\{[\w\W]*/gm),Yc=lt(/^data-[\-\w.\u00B7-\uFFFF]+$/),Zc=lt(/^aria-[\-\w]+$/),ol=lt(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Vc=lt(/^(?:\w+script|data):/i),Xc=lt(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),cl=lt(/^html$/i),Kc=lt(/^[a-z][.\w]*(-[.\w]+)+$/i);var fl=Object.freeze({__proto__:null,ARIA_ATTR:Zc,ATTR_WHITESPACE:Xc,CUSTOM_ELEMENT:Kc,DATA_ATTR:Yc,DOCTYPE_NAME:cl,ERB_EXPR:qc,IS_ALLOWED_URI:ol,IS_SCRIPT_OR_DATA:Vc,MUSTACHE_EXPR:Wc,TMPLIT_EXPR:jc});const Or={element:1,text:3,progressingInstruction:7,comment:8,document:9},Qc=function(){return typeof window>"u"?null:window},Jc=function(e,n){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let r=null;const s="data-tt-policy-suffix";n&&n.hasAttribute(s)&&(r=n.getAttribute(s));const i="dompurify"+(r?"#"+r:"");try{return e.createPolicy(i,{createHTML(a){return a},createScriptURL(a){return a}})}catch{return console.warn("TrustedTypes policy "+i+" could not be created."),null}},ul=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function hl(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Qc();const e=k=>hl(k);if(e.version="3.3.1",e.removed=[],!t||!t.document||t.document.nodeType!==Or.document||!t.Element)return e.isSupported=!1,e;let{document:n}=t;const r=n,s=r.currentScript,{DocumentFragment:i,HTMLTemplateElement:a,Node:l,Element:o,NodeFilter:c,NamedNodeMap:u=t.NamedNodeMap||t.MozNamedAttrMap,HTMLFormElement:g,DOMParser:p,trustedTypes:v}=t,b=o.prototype,R=Lr(b,"cloneNode"),_=Lr(b,"remove"),x=Lr(b,"nextSibling"),U=Lr(b,"childNodes"),H=Lr(b,"parentNode");if(typeof a=="function"){const k=n.createElement("template");k.content&&k.content.ownerDocument&&(n=k.content.ownerDocument)}let M,ve="";const{implementation:we,createNodeIterator:ee,createDocumentFragment:ut,getElementsByTagName:et}=n,{importNode:oe}=r;let pe=ul();e.isSupported=typeof tl=="function"&&typeof H=="function"&&we&&we.createHTMLDocument!==void 0;const{MUSTACHE_EXPR:Hn,ERB_EXPR:Fr,TMPLIT_EXPR:Jt,DATA_ATTR:lr,ARIA_ATTR:Ur,IS_SCRIPT_OR_DATA:bi,ATTR_WHITESPACE:ys,CUSTOM_ELEMENT:wi}=fl;let{IS_ALLOWED_URI:yt}=fl,ce=null;const Ts=$({},[...sl,...pi,...di,...gi,...il]);let de=null;const Es=$({},[...al,...vi,...ll,...bs]);let Q=Object.seal(oi(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),vn=null,Hr=null;const mn=Object.seal(oi(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let Ss=!0,y=!0,z=!1,I=!0,J=!1,te=!0,ze=!1,Tt=!1,en=!1,ht=!1,Mt=!1,Nt=!1,_n=!0,or=!1;const pt="user-content-";let cr=!0,Bn=!1,tn={},dt=null;const fr=$({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let As=null;const zs=$({},["audio","video","img","source","image","track"]);let ur=null;const nn=$({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Gn="http://www.w3.org/1998/Math/MathML",A="http://www.w3.org/2000/svg",q="http://www.w3.org/1999/xhtml";let gt=q,rn=!1,Wn=null;const Br=$({},[Gn,A,q],ui);let tt=$({},["mi","mo","mn","ms","mtext"]),Ue=$({},["annotation-xml"]);const sn=$({},["title","style","font","a","script"]);let ae=null;const Ye=["application/xhtml+xml","text/html"],Pt="text/html";let N=null,Re=null;const He=n.createElement("form"),Be=function(f){return f instanceof RegExp||f instanceof Function},vt=function(){let f=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(Re&&Re===f)){if((!f||typeof f!="object")&&(f={}),f=It(f),ae=Ye.indexOf(f.PARSER_MEDIA_TYPE)===-1?Pt:f.PARSER_MEDIA_TYPE,N=ae==="application/xhtml+xml"?ui:_s,ce=xt(f,"ALLOWED_TAGS")?$({},f.ALLOWED_TAGS,N):Ts,de=xt(f,"ALLOWED_ATTR")?$({},f.ALLOWED_ATTR,N):Es,Wn=xt(f,"ALLOWED_NAMESPACES")?$({},f.ALLOWED_NAMESPACES,ui):Br,ur=xt(f,"ADD_URI_SAFE_ATTR")?$(It(nn),f.ADD_URI_SAFE_ATTR,N):nn,As=xt(f,"ADD_DATA_URI_TAGS")?$(It(zs),f.ADD_DATA_URI_TAGS,N):zs,dt=xt(f,"FORBID_CONTENTS")?$({},f.FORBID_CONTENTS,N):fr,vn=xt(f,"FORBID_TAGS")?$({},f.FORBID_TAGS,N):It({}),Hr=xt(f,"FORBID_ATTR")?$({},f.FORBID_ATTR,N):It({}),tn=xt(f,"USE_PROFILES")?f.USE_PROFILES:!1,Ss=f.ALLOW_ARIA_ATTR!==!1,y=f.ALLOW_DATA_ATTR!==!1,z=f.ALLOW_UNKNOWN_PROTOCOLS||!1,I=f.ALLOW_SELF_CLOSE_IN_ATTR!==!1,J=f.SAFE_FOR_TEMPLATES||!1,te=f.SAFE_FOR_XML!==!1,ze=f.WHOLE_DOCUMENT||!1,ht=f.RETURN_DOM||!1,Mt=f.RETURN_DOM_FRAGMENT||!1,Nt=f.RETURN_TRUSTED_TYPE||!1,en=f.FORCE_BODY||!1,_n=f.SANITIZE_DOM!==!1,or=f.SANITIZE_NAMED_PROPS||!1,cr=f.KEEP_CONTENT!==!1,Bn=f.IN_PLACE||!1,yt=f.ALLOWED_URI_REGEXP||ol,gt=f.NAMESPACE||q,tt=f.MATHML_TEXT_INTEGRATION_POINTS||tt,Ue=f.HTML_INTEGRATION_POINTS||Ue,Q=f.CUSTOM_ELEMENT_HANDLING||{},f.CUSTOM_ELEMENT_HANDLING&&Be(f.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Q.tagNameCheck=f.CUSTOM_ELEMENT_HANDLING.tagNameCheck),f.CUSTOM_ELEMENT_HANDLING&&Be(f.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Q.attributeNameCheck=f.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),f.CUSTOM_ELEMENT_HANDLING&&typeof f.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(Q.allowCustomizedBuiltInElements=f.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),J&&(y=!1),Mt&&(ht=!0),tn&&(ce=$({},il),de=[],tn.html===!0&&($(ce,sl),$(de,al)),tn.svg===!0&&($(ce,pi),$(de,vi),$(de,bs)),tn.svgFilters===!0&&($(ce,di),$(de,vi),$(de,bs)),tn.mathMl===!0&&($(ce,gi),$(de,ll),$(de,bs))),f.ADD_TAGS&&(typeof f.ADD_TAGS=="function"?mn.tagCheck=f.ADD_TAGS:(ce===Ts&&(ce=It(ce)),$(ce,f.ADD_TAGS,N))),f.ADD_ATTR&&(typeof f.ADD_ATTR=="function"?mn.attributeCheck=f.ADD_ATTR:(de===Es&&(de=It(de)),$(de,f.ADD_ATTR,N))),f.ADD_URI_SAFE_ATTR&&$(ur,f.ADD_URI_SAFE_ATTR,N),f.FORBID_CONTENTS&&(dt===fr&&(dt=It(dt)),$(dt,f.FORBID_CONTENTS,N)),f.ADD_FORBID_CONTENTS&&(dt===fr&&(dt=It(dt)),$(dt,f.ADD_FORBID_CONTENTS,N)),cr&&(ce["#text"]=!0),ze&&$(ce,["html","head","body"]),ce.table&&($(ce,["tbody"]),delete vn.tbody),f.TRUSTED_TYPES_POLICY){if(typeof f.TRUSTED_TYPES_POLICY.createHTML!="function")throw Cr('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof f.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Cr('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');M=f.TRUSTED_TYPES_POLICY,ve=M.createHTML("")}else M===void 0&&(M=Jc(v,s)),M!==null&&typeof ve=="string"&&(ve=M.createHTML(""));Ne&&Ne(f),Re=f}},Ft=$({},[...pi,...di,...Bc]),bn=$({},[...gi,...Gc]),V=function(f){let m=H(f);(!m||!m.tagName)&&(m={namespaceURI:gt,tagName:"template"});const w=_s(f.tagName),ne=_s(m.tagName);return Wn[f.namespaceURI]?f.namespaceURI===A?m.namespaceURI===q?w==="svg":m.namespaceURI===Gn?w==="svg"&&(ne==="annotation-xml"||tt[ne]):!!Ft[w]:f.namespaceURI===Gn?m.namespaceURI===q?w==="math":m.namespaceURI===A?w==="math"&&Ue[ne]:!!bn[w]:f.namespaceURI===q?m.namespaceURI===A&&!Ue[ne]||m.namespaceURI===Gn&&!tt[ne]?!1:!bn[w]&&(sn[w]||!Ft[w]):!!(ae==="application/xhtml+xml"&&Wn[f.namespaceURI]):!1},B=function(f){$r(e.removed,{element:f});try{H(f).removeChild(f)}catch{_(f)}},me=function(f,m){try{$r(e.removed,{attribute:m.getAttributeNode(f),from:m})}catch{$r(e.removed,{attribute:null,from:m})}if(m.removeAttribute(f),f==="is")if(ht||Mt)try{B(m)}catch{}else try{m.setAttribute(f,"")}catch{}},Ut=function(f){let m=null,w=null;if(en)f=""+f;else{const fe=hi(f,/^[\r\n\t ]+/);w=fe&&fe[0]}ae==="application/xhtml+xml"&>===q&&(f=''+f+"");const ne=M?M.createHTML(f):f;if(gt===q)try{m=new p().parseFromString(ne,ae)}catch{}if(!m||!m.documentElement){m=we.createDocument(gt,"template",null);try{m.documentElement.innerHTML=rn?ve:ne}catch{}}const Ce=m.body||m.documentElement;return f&&w&&Ce.insertBefore(n.createTextNode(w),Ce.childNodes[0]||null),gt===q?et.call(m,ze?"html":"body")[0]:ze?m.documentElement:Ce},ge=function(f){return ee.call(f.ownerDocument||f,f,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},xe=function(f){return f instanceof g&&(typeof f.nodeName!="string"||typeof f.textContent!="string"||typeof f.removeChild!="function"||!(f.attributes instanceof u)||typeof f.removeAttribute!="function"||typeof f.setAttribute!="function"||typeof f.namespaceURI!="string"||typeof f.insertBefore!="function"||typeof f.hasChildNodes!="function")},wn=function(f){return typeof l=="function"&&f instanceof l};function $e(k,f,m){ms(k,w=>{w.call(e,f,m,Re)})}const hr=function(f){let m=null;if($e(pe.beforeSanitizeElements,f,null),xe(f))return B(f),!0;const w=N(f.nodeName);if($e(pe.uponSanitizeElement,f,{tagName:w,allowedTags:ce}),te&&f.hasChildNodes()&&!wn(f.firstElementChild)&&Pe(/<[/\w!]/g,f.innerHTML)&&Pe(/<[/\w!]/g,f.textContent)||f.nodeType===Or.progressingInstruction||te&&f.nodeType===Or.comment&&Pe(/<[/\w]/g,f.data))return B(f),!0;if(!(mn.tagCheck instanceof Function&&mn.tagCheck(w))&&(!ce[w]||vn[w])){if(!vn[w]&&Ht(w)&&(Q.tagNameCheck instanceof RegExp&&Pe(Q.tagNameCheck,w)||Q.tagNameCheck instanceof Function&&Q.tagNameCheck(w)))return!1;if(cr&&!dt[w]){const ne=H(f)||f.parentNode,Ce=U(f)||f.childNodes;if(Ce&&ne){const fe=Ce.length;for(let Ze=fe-1;Ze>=0;--Ze){const an=R(Ce[Ze],!0);an.__removalCount=(f.__removalCount||0)+1,ne.insertBefore(an,x(f))}}}return B(f),!0}return f instanceof o&&!V(f)||(w==="noscript"||w==="noembed"||w==="noframes")&&Pe(/<\/no(script|embed|frames)/i,f.innerHTML)?(B(f),!0):(J&&f.nodeType===Or.text&&(m=f.textContent,ms([Hn,Fr,Jt],ne=>{m=Ir(m,ne," ")}),f.textContent!==m&&($r(e.removed,{element:f.cloneNode()}),f.textContent=m)),$e(pe.afterSanitizeElements,f,null),!1)},Ie=function(f,m,w){if(_n&&(m==="id"||m==="name")&&(w in n||w in He))return!1;if(!(y&&!Hr[m]&&Pe(lr,m))){if(!(Ss&&Pe(Ur,m))){if(!(mn.attributeCheck instanceof Function&&mn.attributeCheck(m,f))){if(!de[m]||Hr[m]){if(!(Ht(f)&&(Q.tagNameCheck instanceof RegExp&&Pe(Q.tagNameCheck,f)||Q.tagNameCheck instanceof Function&&Q.tagNameCheck(f))&&(Q.attributeNameCheck instanceof RegExp&&Pe(Q.attributeNameCheck,m)||Q.attributeNameCheck instanceof Function&&Q.attributeNameCheck(m,f))||m==="is"&&Q.allowCustomizedBuiltInElements&&(Q.tagNameCheck instanceof RegExp&&Pe(Q.tagNameCheck,w)||Q.tagNameCheck instanceof Function&&Q.tagNameCheck(w))))return!1}else if(!ur[m]){if(!Pe(yt,Ir(w,ys,""))){if(!((m==="src"||m==="xlink:href"||m==="href")&&f!=="script"&&Pc(w,"data:")===0&&As[f])){if(!(z&&!Pe(bi,Ir(w,ys,"")))){if(w)return!1}}}}}}}return!0},Ht=function(f){return f!=="annotation-xml"&&hi(f,wi)},vl=function(f){$e(pe.beforeSanitizeAttributes,f,null);const{attributes:m}=f;if(!m||xe(f))return;const w={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:de,forceKeepAttr:void 0};let ne=m.length;for(;ne--;){const Ce=m[ne],{name:fe,namespaceURI:Ze,value:an}=Ce,pr=N(fe),xi=an;let ke=fe==="value"?xi:Fc(xi);if(w.attrName=pr,w.attrValue=ke,w.keepAttr=!0,w.forceKeepAttr=void 0,$e(pe.uponSanitizeAttribute,f,w),ke=w.attrValue,or&&(pr==="id"||pr==="name")&&(me(fe,f),ke=pt+ke),te&&Pe(/((--!?|])>)|<\/(style|title|textarea)/i,ke)){me(fe,f);continue}if(pr==="attributename"&&hi(ke,"href")){me(fe,f);continue}if(w.forceKeepAttr)continue;if(!w.keepAttr){me(fe,f);continue}if(!I&&Pe(/\/>/i,ke)){me(fe,f);continue}J&&ms([Hn,Fr,Jt],_l=>{ke=Ir(ke,_l," ")});const ml=N(f.nodeName);if(!Ie(ml,pr,ke)){me(fe,f);continue}if(M&&typeof v=="object"&&typeof v.getAttributeType=="function"&&!Ze)switch(v.getAttributeType(ml,pr)){case"TrustedHTML":{ke=M.createHTML(ke);break}case"TrustedScriptURL":{ke=M.createScriptURL(ke);break}}if(ke!==xi)try{Ze?f.setAttributeNS(Ze,fe,ke):f.setAttribute(fe,ke),xe(f)?B(f):rl(e.removed)}catch{me(fe,f)}}$e(pe.afterSanitizeAttributes,f,null)},Af=function k(f){let m=null;const w=ge(f);for($e(pe.beforeSanitizeShadowDOM,f,null);m=w.nextNode();)$e(pe.uponSanitizeShadowNode,m,null),hr(m),vl(m),m.content instanceof i&&k(m.content);$e(pe.afterSanitizeShadowDOM,f,null)};return e.sanitize=function(k){let f=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},m=null,w=null,ne=null,Ce=null;if(rn=!k,rn&&(k=""),typeof k!="string"&&!wn(k))if(typeof k.toString=="function"){if(k=k.toString(),typeof k!="string")throw Cr("dirty is not a string, aborting")}else throw Cr("toString is not a function");if(!e.isSupported)return k;if(Tt||vt(f),e.removed=[],typeof k=="string"&&(Bn=!1),Bn){if(k.nodeName){const an=N(k.nodeName);if(!ce[an]||vn[an])throw Cr("root node is forbidden and cannot be sanitized in-place")}}else if(k instanceof l)m=Ut(""),w=m.ownerDocument.importNode(k,!0),w.nodeType===Or.element&&w.nodeName==="BODY"||w.nodeName==="HTML"?m=w:m.appendChild(w);else{if(!ht&&!J&&!ze&&k.indexOf("<")===-1)return M&&Nt?M.createHTML(k):k;if(m=Ut(k),!m)return ht?null:Nt?ve:""}m&&en&&B(m.firstChild);const fe=ge(Bn?k:m);for(;ne=fe.nextNode();)hr(ne),vl(ne),ne.content instanceof i&&Af(ne.content);if(Bn)return k;if(ht){if(Mt)for(Ce=ut.call(m.ownerDocument);m.firstChild;)Ce.appendChild(m.firstChild);else Ce=m;return(de.shadowroot||de.shadowrootmode)&&(Ce=oe.call(r,Ce,!0)),Ce}let Ze=ze?m.outerHTML:m.innerHTML;return ze&&ce["!doctype"]&&m.ownerDocument&&m.ownerDocument.doctype&&m.ownerDocument.doctype.name&&Pe(cl,m.ownerDocument.doctype.name)&&(Ze=" -`+Ze),J&&ms([Hn,Fr,Jt],an=>{Ze=Ir(Ze,an," ")}),M&&Nt?M.createHTML(Ze):Ze},e.setConfig=function(){let k=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};vt(k),Tt=!0},e.clearConfig=function(){Re=null,Tt=!1},e.isValidAttribute=function(k,f,m){Re||vt({});const w=N(k),ne=N(f);return Ie(w,ne,m)},e.addHook=function(k,f){typeof f=="function"&&$r(pe[k],f)},e.removeHook=function(k,f){if(f!==void 0){const m=Mc(pe[k],f);return m===-1?void 0:Nc(pe[k],m,1)[0]}return rl(pe[k])},e.removeHooks=function(k){pe[k]=[]},e.removeAllHooks=function(){pe=ul()},e}var mi=hl();F.setOptions({breaks:!0,gfm:!0});const pl=new F.Renderer;pl.link=function({href:t,title:e,text:n}){const r=e?` title="${e}"`:"";return`
    ${n}`},F.use({renderer:pl}),mi.addHook("afterSanitizeAttributes",function(t){t.tagName==="A"&&(t.setAttribute("target","_blank"),t.setAttribute("rel","noopener noreferrer"))});function ef(t){if(!t)return"";try{const e=t.replace(/<([^|>\s]+)\|([^>]+)>/g,"[$2]($1)"),n=F.parse(e);return mi.sanitize(n,{ALLOWED_TAGS:["h1","h2","h3","h4","h5","h6","p","br","hr","strong","em","b","i","u","s","del","ul","ol","li","a","code","pre","blockquote","table","thead","tbody","tr","th","td"],ALLOWED_ATTR:["href","title","target","rel","class"]})}catch(e){return console.warn("[lc-chatbot] Markdown render error:",e),mi.sanitize(t)}}function tf(t){return t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function nf(t){return new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0})}function rf(t){const e=new Date(t);return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}var sf=he(''),af=he('
    Loading messages...
    '),lf=he('

    Start a conversation

    '),of=he('
    '),cf=he('

    '),ff=he('Sending...'),uf=he(''),hf=he('
    '),pf=he('
    '),df=he('
    '),gf=Sa('',1),vf=Sa('',1),mf=he('
    '),_f=he('
    Thinking...
    '),bf=he('
    '),wf=he(' '),xf=he('
    '),kf=he('
    '),yf=he('
    '),Tf=he('

    Chat

    '),Ef=he("
    ");const Sf={hash:"svelte-z9t1fg",code:` - /* CSS Custom Properties for theming */:host {--lc-primary: #6366f1;--lc-primary-hover: #4f46e5;--lc-bg: #ffffff;--lc-bg-secondary: #f8fafc;--lc-bg-tertiary: #f1f5f9;--lc-text: #1e293b;--lc-text-secondary: #64748b;--lc-text-muted: #94a3b8;--lc-border: #e2e8f0;--lc-user-bg: #6366f1;--lc-user-text: #ffffff;--lc-assistant-bg: #f1f5f9;--lc-assistant-text: #1e293b;--lc-error: #ef4444;--lc-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);--lc-radius: 16px;--lc-radius-sm: 8px;--lc-font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;display:block;font-family:var(--lc-font);}.svelte-z9t1fg {box-sizing:border-box;margin:0;padding:0;}.lc-chatbot-container.svelte-z9t1fg {position:fixed;bottom:24px;right:24px;z-index:9999;}.lc-chatbot-container.placement-left.svelte-z9t1fg {right:auto;left:24px;} - - /* Trigger Button */.lc-chatbot-trigger.svelte-z9t1fg {display:flex;align-items:center;gap:8px;padding:12px 20px;background:var(--lc-primary);color:white;border:none;border-radius:9999px;cursor:pointer;font-family:var(--lc-font);font-size:14px;font-weight:500;box-shadow:var(--lc-shadow);transition:all 0.2s ease;}.lc-chatbot-trigger.svelte-z9t1fg:hover {background:var(--lc-primary-hover);transform:scale(1.02);}.lc-chatbot-trigger.svelte-z9t1fg:active {transform:scale(0.98);}.trigger-label.svelte-z9t1fg {font-weight:600;} - - /* Chat Panel */.lc-chatbot-panel.svelte-z9t1fg {display:flex;flex-direction:column;background:var(--lc-bg);border-radius:var(--lc-radius);box-shadow:var(--lc-shadow);overflow:hidden;position:relative;}.lc-chatbot-panel.resizing.svelte-z9t1fg {user-select:none;} - - /* Resize Handles */.resize-handle.svelte-z9t1fg {position:absolute;background:transparent;z-index:10;}.resize-n.svelte-z9t1fg, .resize-s.svelte-z9t1fg {height:8px;left:8px;right:8px;cursor:ns-resize;}.resize-e.svelte-z9t1fg, .resize-w.svelte-z9t1fg {width:8px;top:8px;bottom:8px;cursor:ew-resize;}.resize-n.svelte-z9t1fg {top:0;}.resize-s.svelte-z9t1fg {bottom:0;}.resize-e.svelte-z9t1fg {right:0;}.resize-w.svelte-z9t1fg {left:0;}.resize-ne.svelte-z9t1fg, .resize-nw.svelte-z9t1fg, .resize-se.svelte-z9t1fg, .resize-sw.svelte-z9t1fg {width:16px;height:16px;}.resize-ne.svelte-z9t1fg {top:0;right:0;cursor:nesw-resize;}.resize-nw.svelte-z9t1fg {top:0;left:0;cursor:nwse-resize;}.resize-se.svelte-z9t1fg {bottom:0;right:0;cursor:nwse-resize;}.resize-sw.svelte-z9t1fg {bottom:0;left:0;cursor:nesw-resize;} - - /* Header */.lc-chatbot-header.svelte-z9t1fg {display:flex;align-items:center;justify-content:space-between;padding:16px 20px;background:var(--lc-bg);border-bottom:1px solid var(--lc-border);}.lc-chatbot-header.svelte-z9t1fg h2:where(.svelte-z9t1fg) {font-size:16px;font-weight:600;color:var(--lc-text);}.close-btn.svelte-z9t1fg {display:flex;align-items:center;justify-content:center;width:32px;height:32px;background:transparent;border:none;border-radius:var(--lc-radius-sm);cursor:pointer;color:var(--lc-text-secondary);transition:all 0.15s ease;}.close-btn.svelte-z9t1fg:hover {background:var(--lc-bg-tertiary);color:var(--lc-text);} - - /* Message List */.lc-chatbot-messages.svelte-z9t1fg {flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:12px;background:var(--lc-bg-secondary);} - - /* Date Markers */.date-marker.svelte-z9t1fg {display:flex;align-items:center;justify-content:center;padding:8px 0;}.date-marker.svelte-z9t1fg span:where(.svelte-z9t1fg) {font-size:12px;color:var(--lc-text-muted);background:var(--lc-bg);padding:4px 12px;border-radius:9999px;border:1px solid var(--lc-border);} - - /* Messages */.message.svelte-z9t1fg {display:flex;flex-direction:column;max-width:85%; - animation: svelte-z9t1fg-fadeInUp 0.2s ease;} - - @keyframes svelte-z9t1fg-fadeInUp { - from { - opacity: 0; - transform: translateY(8px); - } - to { - opacity: 1; - transform: translateY(0); - } - }.message.user.svelte-z9t1fg {align-self:flex-end;}.message.assistant.svelte-z9t1fg {align-self:flex-start;}.message-content.svelte-z9t1fg {padding:12px 16px;border-radius:var(--lc-radius);word-wrap:break-word;}.message.user.svelte-z9t1fg .message-content:where(.svelte-z9t1fg) {background:var(--lc-user-bg);color:var(--lc-user-text);border-bottom-right-radius:4px;}.message.assistant.svelte-z9t1fg .message-content:where(.svelte-z9t1fg) {background:var(--lc-bg);color:var(--lc-assistant-text);border-bottom-left-radius:4px;border:1px solid var(--lc-border);}.message.failed.svelte-z9t1fg .message-content:where(.svelte-z9t1fg) {border:1px solid var(--lc-error);background:#fef2f2;}.message-content.svelte-z9t1fg p:where(.svelte-z9t1fg) {margin:0;line-height:1.5;} - - /* Markdown Styles */.message-content.svelte-z9t1fg h1, - .message-content.svelte-z9t1fg h2, - .message-content.svelte-z9t1fg h3, - .message-content.svelte-z9t1fg h4, - .message-content.svelte-z9t1fg h5, - .message-content.svelte-z9t1fg h6 {margin-top:12px;margin-bottom:8px;font-weight:600;line-height:1.3;}.message-content.svelte-z9t1fg h1 {font-size:1.25em;}.message-content.svelte-z9t1fg h2 {font-size:1.15em;}.message-content.svelte-z9t1fg h3 {font-size:1.05em;}.message-content.svelte-z9t1fg p {margin-bottom:8px;}.message-content.svelte-z9t1fg p:last-child {margin-bottom:0;}.message-content.svelte-z9t1fg a {color:var(--lc-primary);text-decoration:underline;}.message-content.svelte-z9t1fg ul, - .message-content.svelte-z9t1fg ol {margin:8px 0;padding-left:20px;}.message-content.svelte-z9t1fg li {margin-bottom:4px;}.message-content.svelte-z9t1fg code {font-family:'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;font-size:0.9em;background:var(--lc-bg-tertiary);padding:2px 6px;border-radius:4px;}.message-content.svelte-z9t1fg pre {margin:8px 0;padding:12px;background:#1e293b;border-radius:var(--lc-radius-sm);overflow-x:auto;}.message-content.svelte-z9t1fg pre code {background:transparent;padding:0;color:#e2e8f0;}.message-content.svelte-z9t1fg blockquote {margin:8px 0;padding-left:12px;border-left:3px solid var(--lc-primary);color:var(--lc-text-secondary);font-style:italic;}.message-meta.svelte-z9t1fg {display:flex;align-items:center;gap:8px;margin-top:4px;padding:0 4px;}.message-time.svelte-z9t1fg {font-size:11px;color:var(--lc-text-muted);}.message-status.svelte-z9t1fg {font-size:11px;color:var(--lc-text-muted);}.message-status.sending.svelte-z9t1fg {color:var(--lc-primary);}.retry-btn.svelte-z9t1fg {font-size:11px;color:var(--lc-error);background:none;border:none;cursor:pointer;text-decoration:underline;font-family:var(--lc-font);}.retry-btn.svelte-z9t1fg:hover {color:#dc2626;} - - /* Thinking/Progress Indicator */.thinking-content.svelte-z9t1fg {min-width:200px;padding:12px 16px !important;}.thinking-status.svelte-z9t1fg {margin-bottom:8px;}.status-text.svelte-z9t1fg {display:flex;align-items:center;gap:8px;font-size:13px;color:var(--lc-text-secondary);}.status-text.tool-running.svelte-z9t1fg {color:var(--lc-primary);}.status-text.tool-error.svelte-z9t1fg {color:var(--lc-error);}.thinking-spinner.svelte-z9t1fg {width:14px;height:14px;border:2px solid var(--lc-border);border-top-color:var(--lc-primary);border-radius:50%; - animation: svelte-z9t1fg-spin 0.8s linear infinite;} - - /* Tool History */.tool-history.svelte-z9t1fg {display:flex;flex-direction:column;gap:4px;border-top:1px solid var(--lc-border);padding-top:8px;margin-top:4px;}.tool-item.svelte-z9t1fg {display:flex;align-items:center;gap:6px;font-size:12px;color:var(--lc-text-muted);padding:4px 0;}.tool-item.running.svelte-z9t1fg {color:var(--lc-primary);}.tool-item.error.svelte-z9t1fg {color:var(--lc-error);}.tool-icon.svelte-z9t1fg {display:flex;align-items:center;justify-content:center;width:16px;height:16px;flex-shrink:0;}.tool-item.svelte-z9t1fg:not(.running):not(.error) .tool-icon:where(.svelte-z9t1fg) {color:#22c55e;}.mini-spinner.svelte-z9t1fg {width:12px;height:12px;border:1.5px solid var(--lc-border);border-top-color:var(--lc-primary);border-radius:50%; - animation: svelte-z9t1fg-spin 0.8s linear infinite;}.tool-desc.svelte-z9t1fg {flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}.tool-duration.svelte-z9t1fg {font-size:11px;color:var(--lc-text-muted);opacity:0.7;} - - /* Empty State */.empty-state.svelte-z9t1fg {display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;color:var(--lc-text-muted);gap:12px;}.empty-state.svelte-z9t1fg p:where(.svelte-z9t1fg) {font-size:14px;} - - /* Loading Indicator */.loading-indicator.svelte-z9t1fg {display:flex;align-items:center;justify-content:center;gap:8px;padding:12px;color:var(--lc-text-muted);font-size:13px;}.loading-spinner.svelte-z9t1fg {width:16px;height:16px;border:2px solid var(--lc-border);border-top-color:var(--lc-primary);border-radius:50%; - animation: svelte-z9t1fg-spin 0.8s linear infinite;} - - @keyframes svelte-z9t1fg-spin { - to { transform: rotate(360deg); } - } - - /* Input Footer */.lc-chatbot-input.svelte-z9t1fg {display:flex;align-items:flex-end;gap:8px;padding:12px 16px;background:var(--lc-bg);border-top:1px solid var(--lc-border);}.lc-chatbot-input.svelte-z9t1fg textarea:where(.svelte-z9t1fg) {flex:1;min-height:40px;max-height:120px;padding:10px 14px;border:1px solid var(--lc-border);border-radius:var(--lc-radius-sm);font-family:var(--lc-font);font-size:14px;resize:none;outline:none;transition:border-color 0.15s ease;line-height:1.4;}.lc-chatbot-input.svelte-z9t1fg textarea:where(.svelte-z9t1fg):focus {border-color:var(--lc-primary);}.lc-chatbot-input.svelte-z9t1fg textarea:where(.svelte-z9t1fg)::placeholder {color:var(--lc-text-muted);}.lc-chatbot-input.svelte-z9t1fg textarea:where(.svelte-z9t1fg):disabled {background:var(--lc-bg-secondary);cursor:not-allowed;}.send-btn.svelte-z9t1fg {display:flex;align-items:center;justify-content:center;width:40px;height:40px;background:var(--lc-primary);color:white;border:none;border-radius:var(--lc-radius-sm);cursor:pointer;transition:all 0.15s ease;}.send-btn.svelte-z9t1fg:hover:not(:disabled) {background:var(--lc-primary-hover);}.send-btn.svelte-z9t1fg:disabled {opacity:0.5;cursor:not-allowed;}.send-btn.svelte-z9t1fg:active:not(:disabled) {transform:scale(0.95);}`};function dl(t,e){Pi(e,!0),Do(t,Sf);let n=os(e,"user-id",7,""),r=os(e,"api-base-url",7,""),s=os(e,"default-open",7,!1),i=os(e,"placement",7,"right"),a=re(!1),l=re(zn([])),o=re(""),c=re(!1),u=re(!1),g=re(!0),p=re(""),v=re(380),b=re(520),R=re(!1),_=re(null),x=re(null),U=re(zn([])),H=re(null),M=re(null);const ve=320,we=420,ee=.9,ut=.9;ia(()=>{const{sessionId:y}=Yo();T(p,y,!0);const z=Er(Ke.UI,null);z?.isOpen!==void 0&&s()===!1?T(a,z.isOpen,!0):s()&&T(a,!0);const I=Er(Ke.SIZE,null);I&&(T(v,Math.max(ve,Math.min(I.width,window.innerWidth*ee)),!0),T(b,Math.max(we,Math.min(I.height,window.innerHeight*ut)),!0));const J=Er(Ke.DRAFT,null);J?.text&&T(o,J.text,!0);const te=Er(Ke.MESSAGES+":"+y,[]);T(l,te,!0)}),ia(()=>{d(o)&&hn(Ke.DRAFT,{text:d(o)})});function et(y,z={}){const I=new CustomEvent(`chatbot:${y}`,{bubbles:!0,composed:!0,detail:z});document.dispatchEvent(I)}function oe(){T(a,!0),hn(Ke.UI,{isOpen:!0,placement:i()}),et("opened"),setTimeout(()=>{d(M)?.focus()},100),d(l).length===0&&d(p)&&r()&&Hn()}function pe(){T(a,!1),hn(Ke.UI,{isOpen:!1,placement:i()}),et("closed")}async function Hn(){if(!(!n()||!d(p)||!r())){T(u,!0);try{const y=await Pa(r(),n(),d(p),null,20);T(l,y.messages,!0),T(g,y.hasMore,!0),Jt(),lr()}catch(y){console.warn("[lc-chatbot] Failed to load history:",y)}finally{T(u,!1)}}}async function Fr(){if(d(u)||!d(g)||d(l).length===0)return;const y=d(l)[0];if(y){T(u,!0);try{const z=await Pa(r(),n(),d(p),y.timestamp,20);T(l,[...z.messages,...d(l)],!0),T(g,z.hasMore,!0),Jt()}catch(z){console.warn("[lc-chatbot] Failed to load more history:",z)}finally{T(u,!1)}}}function Jt(){hn(Ke.MESSAGES+":"+d(p),d(l))}function lr(){setTimeout(()=>{d(H)&&(d(H).scrollTop=d(H).scrollHeight)},50)}async function Ur(){const y=d(o).trim();if(!y||d(c)||!n()||!r())return;T(o,""),hn(Ke.DRAFT,{text:""});const z={messageId:Na(),sessionId:d(p),userId:n(),role:"user",content:y,timestamp:new Date().toISOString(),status:"sending"};T(l,[...d(l),z],!0),Jt(),lr(),T(c,!0),T(x,null),T(U,[],!0),Zo(d(p));try{const I=await Xo(r(),n(),d(p),y,{onProgress:te=>{T(x,te,!0),te.type==="tool_start"?T(U,[...d(U),{toolName:te.toolName,description:te.description,status:"running",startTime:Date.now()}],!0):te.type==="tool_end"&&T(U,d(U).map((ze,Tt)=>Tt===d(U).length-1?{...ze,status:te.isError?"error":"complete",duration:Date.now()-ze.startTime}:ze),!0),lr()},onError:te=>{console.error("[lc-chatbot] Stream error:",te)}});T(l,d(l).map(te=>te.messageId===z.messageId?{...te,status:"sent"}:te),!0);const J={messageId:I.messageId,sessionId:I.sessionId,userId:n(),role:"assistant",content:I.markdown,timestamp:I.timestamp,status:"sent",toolCalls:I.toolCalls,stats:I.stats};T(l,[...d(l),J],!0),Jt(),lr(),et("message_sent",{messageId:z.messageId,sessionId:d(p),toolCalls:I.toolCalls,stats:I.stats})}catch(I){console.error("[lc-chatbot] Send failed:",I),T(l,d(l).map(J=>J.messageId===z.messageId?{...J,status:"failed"}:J),!0),Jt(),et("error",{type:"send_failed",messageId:z.messageId,error:I.message})}finally{T(c,!1),T(x,null),T(U,[],!0)}}function bi(y){y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),Ur())}function ys(y){y.target.scrollTop<50&&d(g)&&!d(u)&&Fr()}async function wi(y){const z=d(l).find(I=>I.messageId===y&&I.status==="failed");z&&(T(l,d(l).filter(I=>I.messageId!==y),!0),T(o,z.content,!0),await Ur())}function yt(y,z){z.preventDefault(),T(R,!0),T(_,y,!0);const I=z.clientX,J=z.clientY,te=d(v),ze=d(b);function Tt(ht){const Mt=ht.clientX-I,Nt=ht.clientY-J,_n=window.innerWidth*ee,or=window.innerHeight*ut;if(d(_).includes("w")||d(_).includes("e")){const pt=d(_).includes("w")?-Mt:Mt;T(v,Math.max(ve,Math.min(te+pt,_n)),!0)}if(d(_).includes("n")||d(_).includes("s")){const pt=d(_).includes("n")?-Nt:Nt;T(b,Math.max(we,Math.min(ze+pt,or)),!0)}}function en(){T(R,!1),T(_,null),hn(Ke.SIZE,{width:d(v),height:d(b)}),document.removeEventListener("mousemove",Tt),document.removeEventListener("mouseup",en)}document.addEventListener("mousemove",Tt),document.addEventListener("mouseup",en)}function ce(){const y=[];let z=null;for(const I of d(l)){const J=rf(I.timestamp);J!==z&&(y.push({type:"date-marker",date:tf(new Date(I.timestamp)),key:"date-"+J}),z=J),y.push({type:"message",...I,key:I.messageId})}return y}let Ts=ro(ce);function de(y){const z=y.target?.closest?.("a");if(!z)return;const I=z.getAttribute("href");if(!I)return;y.preventDefault(),y.stopPropagation();const J=I;console.log("[lc-chatbot] Link clicked:",z.getAttribute("href")),document.dispatchEvent(new CustomEvent("sefaria:bootstrap-url",{detail:{url:J,replaceHistory:!0}}))}var Es={get"user-id"(){return n()},set"user-id"(y=""){n(y),Qn()},get"api-base-url"(){return r()},set"api-base-url"(y=""){r(y),Qn()},get"default-open"(){return s()},set"default-open"(y=!1){s(y),Qn()},get placement(){return i()},set placement(y="right"){i(y),Qn()}},Q=Ef();let vn;var Hr=K(Q);{var mn=y=>{var z=sf();z.__click=oe,G(y,z)},Ss=y=>{var z=Tf();let I;var J=K(z);J.__mousedown=A=>yt("n",A);var te=se(J,2);te.__mousedown=A=>yt("s",A);var ze=se(te,2);ze.__mousedown=A=>yt("e",A);var Tt=se(ze,2);Tt.__mousedown=A=>yt("w",A);var en=se(Tt,2);en.__mousedown=A=>yt("ne",A);var ht=se(en,2);ht.__mousedown=A=>yt("nw",A);var Mt=se(ht,2);Mt.__mousedown=A=>yt("se",A);var Nt=se(Mt,2);Nt.__mousedown=A=>yt("sw",A);var _n=se(Nt,2),or=se(K(_n),2);or.__click=pe,X(_n);var pt=se(_n,2);pt.__click=de;var cr=K(pt);{var Bn=A=>{var q=af();G(A,q)};Ae(cr,A=>{d(u)&&A(Bn)})}var tn=se(cr,2);{var dt=A=>{var q=lf();G(A,q)};Ae(tn,A=>{d(l).length===0&&!d(u)&&A(dt)})}var fr=se(tn,2);Ia(fr,17,()=>d(Ts),A=>A.key,(A,q)=>{var gt=tr(),rn=er(gt);{var Wn=tt=>{var Ue=of(),sn=K(Ue),ae=K(sn,!0);X(sn),X(Ue),bt(()=>fn(ae,d(q).date)),G(tt,Ue)},Br=tt=>{var Ue=hf();let sn;var ae=K(Ue),Ye=K(ae);{var Pt=V=>{var B=tr(),me=er(B);Oo(me,()=>ef(d(q).content)),G(V,B)},N=V=>{var B=cf(),me=K(B,!0);X(B),bt(()=>fn(me,d(q).content)),G(V,B)};Ae(Ye,V=>{d(q).role==="assistant"?V(Pt):V(N,!1)})}X(ae);var Re=se(ae,2),He=K(Re),Be=K(He,!0);X(He);var vt=se(He,2);{var Ft=V=>{var B=ff();G(V,B)},bn=V=>{var B=tr(),me=er(B);{var Ut=ge=>{var xe=uf();xe.__click=()=>wi(d(q).messageId),G(ge,xe)};Ae(me,ge=>{d(q).status==="failed"&&ge(Ut)},!0)}G(V,B)};Ae(vt,V=>{d(q).status==="sending"?V(Ft):V(bn,!1)})}X(Re),X(Ue),bt(V=>{sn=Tr(Ue,1,"message svelte-z9t1fg",null,sn,{user:d(q).role==="user",assistant:d(q).role==="assistant",failed:d(q).status==="failed"}),fn(Be,V)},[()=>nf(d(q).timestamp)]),G(tt,Ue)};Ae(rn,tt=>{d(q).type==="date-marker"?tt(Wn):tt(Br,!1)})}G(A,gt)});var As=se(fr,2);{var zs=A=>{var q=yf(),gt=K(q),rn=K(gt),Wn=K(rn);{var Br=ae=>{var Ye=pf(),Pt=se(K(Ye),2),N=K(Pt,!0);X(Pt),X(Ye),bt(()=>fn(N,d(x).text)),G(ae,Ye)},tt=ae=>{var Ye=tr(),Pt=er(Ye);{var N=He=>{var Be=df(),vt=se(K(Be),2),Ft=K(vt,!0);X(vt),X(Be),bt(()=>fn(Ft,d(x).description||`Running ${d(x).toolName}...`)),G(He,Be)},Re=He=>{var Be=tr(),vt=er(Be);{var Ft=V=>{var B=mf();let me;var Ut=K(B),ge=K(Ut);{var xe=Ie=>{var Ht=gf();Ns(2),G(Ie,Ht)},wn=Ie=>{var Ht=vf();Ns(),G(Ie,Ht)};Ae(ge,Ie=>{d(x).isError?Ie(xe):Ie(wn,!1)})}X(Ut);var $e=se(Ut,2),hr=K($e,!0);X($e),X(B),bt(()=>{me=Tr(B,1,"status-text svelte-z9t1fg",null,me,{"tool-error":d(x).isError}),fn(hr,d(x).isError?"Tool error":"Done")}),G(V,B)},bn=V=>{var B=_f();G(V,B)};Ae(vt,V=>{d(x)?.type==="tool_end"?V(Ft):V(bn,!1)},!0)}G(He,Be)};Ae(Pt,He=>{d(x)?.type==="tool_start"?He(N):He(Re,!1)},!0)}G(ae,Ye)};Ae(Wn,ae=>{d(x)?.type==="status"?ae(Br):ae(tt,!1)})}X(rn);var Ue=se(rn,2);{var sn=ae=>{var Ye=kf();Ia(Ye,21,()=>d(U),$o,(Pt,N)=>{var Re=xf();let He;var Be=K(Re),vt=K(Be);{var Ft=ge=>{var xe=bf();G(ge,xe)},bn=ge=>{var xe=tr(),wn=er(xe);{var $e=Ie=>{var Ht=Aa("✗");G(Ie,Ht)},hr=Ie=>{var Ht=Aa("✓");G(Ie,Ht)};Ae(wn,Ie=>{d(N).status==="error"?Ie($e):Ie(hr,!1)},!0)}G(ge,xe)};Ae(vt,ge=>{d(N).status==="running"?ge(Ft):ge(bn,!1)})}X(Be);var V=se(Be,2),B=K(V,!0);X(V);var me=se(V,2);{var Ut=ge=>{var xe=wf(),wn=K(xe);X(xe),bt($e=>fn(wn,`${$e??""}s`),[()=>(d(N).duration/1e3).toFixed(1)]),G(ge,xe)};Ae(me,ge=>{d(N).duration&&ge(Ut)})}X(Re),bt(()=>{He=Tr(Re,1,"tool-item svelte-z9t1fg",null,He,{running:d(N).status==="running",error:d(N).status==="error"}),fn(B,d(N).description||d(N).toolName)}),G(Pt,Re)}),X(Ye),G(ae,Ye)};Ae(Ue,ae=>{d(U).length>0&&ae(sn)})}X(gt),X(q),G(A,q)};Ae(As,A=>{d(c)&&A(zs)})}X(pt),Oa(pt,A=>T(H,A),()=>d(H));var ur=se(pt,2),nn=K(ur);lo(nn),nn.__keydown=bi,Oa(nn,A=>T(M,A),()=>d(M));var Gn=se(nn,2);Gn.__click=Ur,X(ur),X(z),bt(A=>{I=Tr(z,1,"lc-chatbot-panel svelte-z9t1fg",null,I,{resizing:d(R)}),Po(z,`width: ${d(v)??""}px; height: ${d(b)??""}px;`),nn.disabled=d(c),Gn.disabled=A},[()=>!d(o).trim()||d(c)]),ko("scroll",pt,ys),Fo(nn,()=>d(o),A=>T(o,A)),G(y,z)};Ae(Hr,y=>{d(a)?y(Ss,!1):y(mn)})}return X(Q),bt(()=>vn=Tr(Q,1,"lc-chatbot-container svelte-z9t1fg",null,vn,{"placement-left":i()==="left"})),G(t,Q),Fi(Es)}return yo(["click","mousedown","keydown"]),customElements.define("lc-chatbot",Go(dl,{"user-id":{},"api-base-url":{},"default-open":{},placement:{}},[],[],!0)),dl}); diff --git a/templates/base.html b/templates/base.html index 55d42926b0..6e966449b1 100644 --- a/templates/base.html +++ b/templates/base.html @@ -75,7 +75,7 @@ {% block head %}{% endblock %} - + From c40324a4e0c0dddc4a22fc29aa9dc3435540af22 Mon Sep 17 00:00:00 2001 From: Akiva Berger Date: Tue, 27 Jan 2026 12:16:48 +0200 Subject: [PATCH 06/21] feat: add user IDs --- templates/base.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/base.html b/templates/base.html index 6e966449b1..053de3683f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -226,12 +226,14 @@ {% endif %} + {% if chatbot_user_token %} + {% endif %}
    From 1083d18927abc062c0868caaa72decc24f2be6ca Mon Sep 17 00:00:00 2001 From: Akiva Berger Date: Sun, 1 Feb 2026 09:29:33 +0200 Subject: [PATCH 07/21] feat: chatbot user hashing and encryption, whitelisting for experiments --- reader/admin.py | 63 +++++++++++++++++++ .../0001_user_experiment_settings.py | 21 +++++++ .../0002_experiments_default_true.py | 16 +++++ reader/migrations/__init__.py | 1 + reader/models.py | 51 ++++++++++++++- reader/views.py | 5 ++ sefaria/local_settings_example.py | 2 + sefaria/model/user_profile.py | 3 + sefaria/system/context_processors.py | 13 +++- templates/account_settings.html | 22 +++++++ templates/base.html | 8 +-- 11 files changed, 197 insertions(+), 8 deletions(-) create mode 100644 reader/admin.py create mode 100644 reader/migrations/0001_user_experiment_settings.py create mode 100644 reader/migrations/0002_experiments_default_true.py create mode 100644 reader/migrations/__init__.py diff --git a/reader/admin.py b/reader/admin.py new file mode 100644 index 0000000000..a4ef05faf5 --- /dev/null +++ b/reader/admin.py @@ -0,0 +1,63 @@ +from django import forms +from django.contrib import admin +from django.contrib.auth.admin import UserAdmin +from django.contrib.auth.forms import UserChangeForm +from django.contrib.auth.models import User + +from reader.models import UserExperimentSettings, _set_user_experiments + + +@admin.register(UserExperimentSettings) +class UserExperimentSettingsAdmin(admin.ModelAdmin): + list_display = ("user_email", "experiments") + list_display_links = ("user_email",) + raw_id_fields = ("user",) + search_fields = ("user__email", "user__username", "user__first_name", "user__last_name") + list_filter = ("experiments",) + + def user_email(self, obj): + return obj.user.email + user_email.short_description = "Email" + user_email.admin_order_field = "user__email" + + +class UserExperimentsChangeForm(UserChangeForm): + experiments = forms.BooleanField(required=False, label="Experiments") + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + if self.instance and self.instance.pk: + settings = UserExperimentSettings.objects.filter(user=self.instance).first() + self.fields["experiments"].initial = bool(settings and settings.experiments) + + def save(self, commit=True): + user = super().save(commit=commit) + if commit: + _set_user_experiments(user, self.cleaned_data.get("experiments", False)) + else: + # Store the value to be set after the user is saved + self._experiments_value = self.cleaned_data.get("experiments", False) + return user + + def _save_m2m(self): + super()._save_m2m() + # Set experiments after the user and all related objects are saved + if hasattr(self, '_experiments_value'): + _set_user_experiments(self.instance, self._experiments_value) + delattr(self, '_experiments_value') + + +class UserAdminWithExperiments(UserAdmin): + form = UserExperimentsChangeForm + fieldsets = UserAdmin.fieldsets + (("Experiments", {"fields": ("experiments",)}),) + + +def register_user_admin(): + try: + admin.site.unregister(User) + except admin.sites.NotRegistered: + pass + admin.site.register(User, UserAdminWithExperiments) + + +register_user_admin() diff --git a/reader/migrations/0001_user_experiment_settings.py b/reader/migrations/0001_user_experiment_settings.py new file mode 100644 index 0000000000..1fc510a14d --- /dev/null +++ b/reader/migrations/0001_user_experiment_settings.py @@ -0,0 +1,21 @@ +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name="UserExperimentSettings", + fields=[ + ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), + ("experiments", models.BooleanField(default=False)), + ("user", models.OneToOneField(on_delete=models.deletion.CASCADE, related_name="experiment_settings", to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/reader/migrations/0002_experiments_default_true.py b/reader/migrations/0002_experiments_default_true.py new file mode 100644 index 0000000000..0661f3a336 --- /dev/null +++ b/reader/migrations/0002_experiments_default_true.py @@ -0,0 +1,16 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("reader", "0001_user_experiment_settings"), + ] + + operations = [ + migrations.AlterField( + model_name="userexperimentsettings", + name="experiments", + field=models.BooleanField(default=True), + ), + ] diff --git a/reader/migrations/__init__.py b/reader/migrations/__init__.py new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/reader/migrations/__init__.py @@ -0,0 +1 @@ + diff --git a/reader/models.py b/reader/models.py index 71a8362390..2a7fd24828 100644 --- a/reader/models.py +++ b/reader/models.py @@ -1,3 +1,52 @@ +from django.contrib.auth.models import User +from django.core.exceptions import ObjectDoesNotExist from django.db import models -# Create your models here. + +class UserExperimentSettings(models.Model): + user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="experiment_settings") + experiments = models.BooleanField(default=True) + + class Meta: + verbose_name = "User experiment settings" + verbose_name_plural = "User experiment settings" + + def __str__(self): + return f"Experiments for user {self.user_id}" + + +def _get_user_experiments(user): + try: + return bool(user.experiment_settings.experiments) + except ObjectDoesNotExist: + return False + + +def _set_user_experiments(user, value): + settings, _ = UserExperimentSettings.objects.get_or_create(user=user) + settings.experiments = bool(value) + settings.save(update_fields=["experiments"]) + + +if not hasattr(User, "experiments"): + User.add_to_class("experiments", property(_get_user_experiments, _set_user_experiments)) + + +def user_has_experiments(user): + if not user or not getattr(user, "is_authenticated", False): + return False + if not user_can_manage_experiments(user): + return False + return UserExperimentSettings.objects.filter(user=user, experiments=True).exists() + + +def user_can_manage_experiments(user): + if not user or not getattr(user, "is_authenticated", False): + return False + return bool( + user.is_superuser + or user.has_perm("reader.change_userexperimentsettings") + or user.has_perm("reader.add_userexperimentsettings") + or user.has_perm("reader.delete_userexperimentsettings") + ) + diff --git a/reader/views.py b/reader/views.py index 1df63450e2..437b5d110c 100644 --- a/reader/views.py +++ b/reader/views.py @@ -68,6 +68,7 @@ from sefaria.system.decorators import catch_error_as_json, sanitize_get_params, json_response_decorator from sefaria.system.exceptions import InputError, PartialRefInputError, BookNameError, NoVersionFoundError, DictionaryEntryNotFoundError from sefaria.system.cache import django_cache +from reader.models import user_has_experiments from sefaria.system.database import db from sefaria.helper.search import get_query_obj from sefaria.helper.crm.crm_mediator import CrmMediator @@ -3826,6 +3827,8 @@ def profile_api(request, slug=None): if not profileJSON: return jsonResponse({"error": "No post JSON."}) profileUpdate = json.loads(profileJSON) + if "experiments" in profileUpdate and not user_has_experiments(request.user): + profileUpdate.pop("experiments", None) profile = UserProfile(id=request.user.id) profile.update(profileUpdate) @@ -4160,9 +4163,11 @@ def account_settings(request): Page for managing a user's account settings. """ profile = UserProfile(id=request.user.id) + experiments_available = user_has_experiments(request.user) return render_template(request,'account_settings.html', {"headerMode": True}, { 'user': request.user, 'profile': profile, + 'experiments_available': experiments_available, 'lang_names_and_codes': zip([Locale(lang).languages[lang].capitalize() for lang in SITE_SETTINGS['SUPPORTED_TRANSLATION_LANGUAGES']], SITE_SETTINGS['SUPPORTED_TRANSLATION_LANGUAGES']), 'translation_language_preference': (profile is not None and profile.settings.get("translation_language_preference", None)) or request.COOKIES.get("translation_language_preference", None), "renderStatic": True diff --git a/sefaria/local_settings_example.py b/sefaria/local_settings_example.py index 6c0f8c8006..7b69e47414 100644 --- a/sefaria/local_settings_example.py +++ b/sefaria/local_settings_example.py @@ -353,3 +353,5 @@ CSRF_COOKIE_SECURE = True # Set to True if using HTTPS CSRF_COOKIE_HTTPONLY = False # Must be False for CSRF tokens to work with JavaScript CSRF_COOKIE_SAMESITE = 'Lax' # Modern browsers require this + +CHATBOT_API_BASE_URL = os.getenv("CHATBOT_API_BASE_URL", "https://chat-dev.sefaria.org/api") diff --git a/sefaria/model/user_profile.py b/sefaria/model/user_profile.py index 378f26ef61..ea7361c5bd 100644 --- a/sefaria/model/user_profile.py +++ b/sefaria/model/user_profile.py @@ -396,6 +396,7 @@ def __init__(self, user_obj=None, id=None, slug=None, email=None, user_registrat # Fundraising self.is_sustainer = False + self.experiments = False # Update with saved profile doc in MongoDB profile = db.profiles.find_one({"id": id}) @@ -665,6 +666,7 @@ def to_mongo_dict(self): "version_preferences_by_corpus": self.version_preferences_by_corpus, "attr_time_stamps": self.attr_time_stamps, "is_sustainer": self.is_sustainer, + "experiments": self.experiments, "tag_order": getattr(self, "tag_order", None), "last_sync_web": self.last_sync_web, "profile_pic_url": self.profile_pic_url, @@ -705,6 +707,7 @@ def to_api_dict(self, basic=False): other_info = { "pinned_sheets": self.pinned_sheets, "is_sustainer": self.is_sustainer, + "experiments": self.experiments, } dictionary.update(other_info) return dictionary diff --git a/sefaria/system/context_processors.py b/sefaria/system/context_processors.py index c91515e16e..769edbd003 100644 --- a/sefaria/system/context_processors.py +++ b/sefaria/system/context_processors.py @@ -118,8 +118,15 @@ def body_flags(request): @user_only def chatbot_user_token(request): if not request.user.is_authenticated: - return {"chatbot_user_token": None} + return {"chatbot_user_token": None, "chatbot_enabled": False} if not CHATBOT_USER_ID_SECRET: - return {"chatbot_user_token": None} + return {"chatbot_user_token": None, "chatbot_enabled": False} + profile = UserProfile(user_obj=request.user) + if not getattr(profile, "experiments", False): + return {"chatbot_user_token": None, "chatbot_enabled": False} token = build_chatbot_user_token(request.user.id, CHATBOT_USER_ID_SECRET) - return {"chatbot_user_token": token} + return { + "chatbot_user_token": token, + "chatbot_enabled": True, + "chatbot_api_base_url": CHATBOT_API_BASE_URL, + } diff --git a/templates/account_settings.html b/templates/account_settings.html index 5a903bbd98..fc9f7c57d2 100644 --- a/templates/account_settings.html +++ b/templates/account_settings.html @@ -105,6 +105,24 @@

    {% endif %} + {% if experiments_available %} +
    + +
    + + +
    +
    + {% endif %}