@aiquants/markdown 13.6.0 → 13.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ "use strict";var wi=Object.create;var mo=Object.defineProperty;var Ei=Object.getOwnPropertyDescriptor;var Si=Object.getOwnPropertyNames;var vi=Object.getPrototypeOf,ki=Object.prototype.hasOwnProperty;var Ti=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Si(t))!ki.call(e,o)&&o!==n&&mo(e,o,{get:()=>t[o],enumerable:!(r=Ei(t,o))||r.enumerable});return e};var Ri=(e,t,n)=>(n=e!=null?wi(vi(e)):{},Ti(t||!e||!e.__esModule?mo(n,"default",{value:e,enumerable:!0}):n,e));const Ns=require("@aiquants/input-method"),d=require("react"),ot=require("./linkCards-BikpIncf.cjs"),kt=require("./providers-Cx0FuVQU.cjs"),Ue=require("./viewer-settings.cjs"),Xe=require("./embeds-B4g6w7Tf.cjs"),Q=require("html-react-parser"),me=require("./code-blocks-CTESwslp.cjs"),zt=require("./source-lines.cjs"),vr=require("./simple-logger-9yf7ypyB.cjs"),kr=require("shiki"),_i=require("dompurify"),We=require("@aiquants/spreadsheet/view"),qn=require("@aiquants/spreadsheet/tsv"),Oi=require("github-slugger"),Ai=require("katex"),Qe=require("unist-util-visit"),Ni=e=>{if(e!==void 0){if(typeof e!="string")throw new TypeError(`[@aiquants/markdown] labelsLang must be a string; got ${e===null?"null":typeof e}`);try{return Intl.getCanonicalLocales(e)[0]}catch(t){throw new RangeError(`[@aiquants/markdown] labelsLang must be a BCP 47 language tag; got ${JSON.stringify(e)}`,{cause:t})}}},dt=(e,t,n)=>{const r=Ni(n),o={};for(const s of Object.keys(e)){const a=t?.[s];if(a===void 0){o[s]=e[s];continue}if(typeof a!="string")throw new TypeError(`[@aiquants/markdown] label "${s}" must be a string; got ${a===null?"null":typeof a}`);o[s]={text:a,lang:r}}return Object.freeze(o)},qt=e=>{const t={};for(const n of Object.keys(e))t[n]=e[n].text;return Object.freeze(t)},Hn=Object.freeze({copy:{text:"Copy the code",lang:"en"},copied:{text:"Copied the code.",lang:"en"},copyFailed:{text:"Could not copy the code.",lang:"en"}}),Ci=qt(Hn),fn=Object.freeze({copy:{text:"Copy the formula",lang:"en"},copied:{text:"Copied the formula.",lang:"en"},copyFailed:{text:"Could not copy the formula.",lang:"en"}}),Li=qt(fn),ji=dt(fn,void 0,void 0),Un=Object.freeze({embeddedVideo:{text:"embedded video",lang:"en"},embeddedPost:{text:"embedded post",lang:"en"},embeddedFrame:{text:"Embedded content",lang:"en"}}),Mi=qt(Un),Cs=(e,t)=>dt(Un,e,t),Ii=Cs(void 0,void 0);var wn={exports:{}},Xt={};var ho;function Di(){if(ho)return Xt;ho=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(r,o,s){var a=null;if(s!==void 0&&(a=""+s),o.key!==void 0&&(a=""+o.key),"key"in o){s={};for(var l in o)l!=="key"&&(s[l]=o[l])}else s=o;return o=s.ref,{$$typeof:e,type:r,key:a,ref:o!==void 0?o:null,props:s}}return Xt.Fragment=t,Xt.jsx=n,Xt.jsxs=n,Xt}var Zt={};var po;function Pi(){return po||(po=1,process.env.NODE_ENV!=="production"&&(function(){function e(g){if(g==null)return null;if(typeof g=="function")return g.$$typeof===F?null:g.displayName||g.name||null;if(typeof g=="string")return g;switch(g){case x:return"Fragment";case T:return"Profiler";case E:return"StrictMode";case A:return"Suspense";case P:return"SuspenseList";case $:return"Activity"}if(typeof g=="object")switch(typeof g.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),g.$$typeof){case p:return"Portal";case b:return g.displayName||"Context";case R:return(g._context.displayName||"Context")+".Consumer";case k:var v=g.render;return g=g.displayName,g||(g=v.displayName||v.name||"",g=g!==""?"ForwardRef("+g+")":"ForwardRef"),g;case L:return v=g.displayName||null,v!==null?v:e(g.type)||"Memo";case B:v=g._payload,g=g._init;try{return e(g(v))}catch{}}return null}function t(g){return""+g}function n(g){try{t(g);var v=!1}catch{v=!0}if(v){v=console;var S=v.error,j=typeof Symbol=="function"&&Symbol.toStringTag&&g[Symbol.toStringTag]||g.constructor.name||"Object";return S.call(v,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",j),t(g)}}function r(g){if(g===x)return"<>";if(typeof g=="object"&&g!==null&&g.$$typeof===B)return"<...>";try{var v=e(g);return v?"<"+v+">":"<...>"}catch{return"<...>"}}function o(){var g=q.A;return g===null?null:g.getOwner()}function s(){return Error("react-stack-top-frame")}function a(g){if(H.call(g,"key")){var v=Object.getOwnPropertyDescriptor(g,"key").get;if(v&&v.isReactWarning)return!1}return g.key!==void 0}function l(g,v){function S(){ee||(ee=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",v))}S.isReactWarning=!0,Object.defineProperty(g,"key",{get:S,configurable:!0})}function c(){var g=e(this.type);return se[g]||(se[g]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),g=this.props.ref,g!==void 0?g:null}function u(g,v,S,j,D,ae){var W=S.ref;return g={$$typeof:y,type:g,key:v,props:S,_owner:j},(W!==void 0?W:null)!==null?Object.defineProperty(g,"ref",{enumerable:!1,get:c}):Object.defineProperty(g,"ref",{enumerable:!1,value:null}),g._store={},Object.defineProperty(g._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(g,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(g,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.defineProperty(g,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:ae}),Object.freeze&&(Object.freeze(g.props),Object.freeze(g)),g}function f(g,v,S,j,D,ae){var W=v.children;if(W!==void 0)if(j)if(ce(W)){for(j=0;j<W.length;j++)m(W[j]);Object.freeze&&Object.freeze(W)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else m(W);if(H.call(v,"key")){W=e(g);var ie=Object.keys(v).filter(function(xe){return xe!=="key"});j=0<ie.length?"{key: someKey, "+ie.join(": ..., ")+": ...}":"{key: someKey}",z[W+j]||(ie=0<ie.length?"{"+ie.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
2
+ let props = %s;
3
+ <%s {...props} />
4
+ React keys must be passed directly to JSX without using spread:
5
+ let props = %s;
6
+ <%s key={someKey} {...props} />`,j,W,ie,W),z[W+j]=!0)}if(W=null,S!==void 0&&(n(S),W=""+S),a(v)&&(n(v.key),W=""+v.key),"key"in v){S={};for(var Ee in v)Ee!=="key"&&(S[Ee]=v[Ee])}else S=v;return W&&l(S,typeof g=="function"?g.displayName||g.name||"Unknown":g),u(g,W,S,o(),D,ae)}function m(g){h(g)?g._store&&(g._store.validated=1):typeof g=="object"&&g!==null&&g.$$typeof===B&&(g._payload.status==="fulfilled"?h(g._payload.value)&&g._payload.value._store&&(g._payload.value._store.validated=1):g._store&&(g._store.validated=1))}function h(g){return typeof g=="object"&&g!==null&&g.$$typeof===y}var w=d,y=Symbol.for("react.transitional.element"),p=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),E=Symbol.for("react.strict_mode"),T=Symbol.for("react.profiler"),R=Symbol.for("react.consumer"),b=Symbol.for("react.context"),k=Symbol.for("react.forward_ref"),A=Symbol.for("react.suspense"),P=Symbol.for("react.suspense_list"),L=Symbol.for("react.memo"),B=Symbol.for("react.lazy"),$=Symbol.for("react.activity"),F=Symbol.for("react.client.reference"),q=w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,H=Object.prototype.hasOwnProperty,ce=Array.isArray,oe=console.createTask?console.createTask:function(){return null};w={react_stack_bottom_frame:function(g){return g()}};var ee,se={},Re=w.react_stack_bottom_frame.bind(w,s)(),O=oe(r(s)),z={};Zt.Fragment=x,Zt.jsx=function(g,v,S){var j=1e4>q.recentlyCreatedOwnerStacks++;return f(g,v,S,!1,j?Error("react-stack-top-frame"):Re,j?oe(r(g)):O)},Zt.jsxs=function(g,v,S){var j=1e4>q.recentlyCreatedOwnerStacks++;return f(g,v,S,!0,j?Error("react-stack-top-frame"):Re,j?oe(r(g)):O)}})()),Zt}var go;function $i(){return go||(go=1,process.env.NODE_ENV==="production"?wn.exports=Di():wn.exports=Pi()),wn.exports}var i=$i();const zi=new Set("px cm mm q in pc pt em rem ex rex cap rcap ch rch ic ric lh rlh vw vh vi vb vmin vmax svw svh svi svb svmin svmax lvw lvh lvi lvb lvmin lvmax dvw dvh dvi dvb dvmin dvmax cqw cqh cqi cqb cqmin cqmax".split(" ")),Bi=/^(?:\d+(?:\.\d+)?|\.\d+)(?:[Ee][+-]?\d+)?([A-Za-z]+)$/u,Fi=/^var\([\t\n\f\r ]*--[A-Za-z0-9_-]+[\t\n\f\r ]*\)$/u,yo='a non-negative CSS length (an unsigned number directly followed by a length unit, such as "54px" or "3.5rem"; no sign, no %) or a custom property reference without a fallback (such as "var(--lane)")',qi=e=>{const t=Bi.exec(e)?.[1];return t===void 0?Fi.test(e):zi.has(t.toLowerCase())},Fr=(e,t)=>{if(typeof t=="number"){if(!Number.isFinite(t)||t<0)throw new RangeError(`[@aiquants/markdown] ${e} must be a finite number >= 0; got ${String(t)}`);return`${t}px`}if(typeof t=="string"){const n=t.trim();if(!qi(n))throw new RangeError(`[@aiquants/markdown] ${e} as a string must be ${yo}; got ${JSON.stringify(t)}`);return n}throw new RangeError(`[@aiquants/markdown] ${e} must be a finite number >= 0 or a string that is ${yo}; got ${String(t)}`)},Ls=.01,rn=e=>{const t=Number.parseFloat(e);return Number.isFinite(t)?t:0},js=e=>{const t=e.getBoundingClientRect().height;return t>0&&e.offsetHeight>0?t/e.offsetHeight:1},Hi=e=>Math.max(0,Math.ceil(e-Ls)),Ui=1/256,Wi=e=>e>Ls?e+Ui:0,xo=Object.freeze({display:"flex",flexDirection:"row",inlineSize:"100%",blockSize:"100%",minInlineSize:0,minBlockSize:0}),Gi=Object.freeze({flex:"1 1 0%",minInlineSize:0,minBlockSize:0,overflow:"clip"}),bo=Object.freeze({display:"flex",flex:"none",minBlockSize:0}),Vi=Object.freeze({position:"absolute",insetBlock:0,insetInline:0,overflowY:"scroll",visibility:"hidden",pointerEvents:"none"}),Ki=Object.freeze({scrollbarWidth:"none"}),Ln="data-aqmd-native-scrollbars-hidden",Yi=Object.freeze({[Ln]:"true"}),wo=Object.freeze({scroller:null,barInlineSize:0,nativeBarInlineSize:0}),Eo=(e,t,n)=>{const r=getComputedStyle(e),o=rn(r.width),s=e.getBoundingClientRect();if(o<=0||s.width<=0)return{barInlineSize:0,nativeBarInlineSize:0};const a=s.width/o,l=(s.width-t.getBoundingClientRect().width)/a-rn(r.borderLeftWidth)-rn(r.borderRightWidth);return{barInlineSize:n.getBoundingClientRect().width/a,nativeBarInlineSize:Wi(l)}},Xi=(e,t,n,r)=>{const o=e.style.scrollbarWidth,s=e.getAttribute(Ln);if(o===r&&s===null)return Eo(e,t,n);e.style.scrollbarWidth=r,e.removeAttribute(Ln);try{return Eo(e,t,n)}finally{e.style.scrollbarWidth=o,s!==null&&e.setAttribute(Ln,s)}},Zi=(e,t,n,r,o,s)=>{const[a,l]=d.useState(wo),c=d.useRef(o),u=d.useRef(0);return d.useLayoutEffect(()=>{c.current=o}),d.useLayoutEffect(()=>{const f=x=>{u.current!==x&&(u.current=x,c.current?.(x))},m=t.current,h=n.current,w=r.current;if(!e||m===null||h===null||w===null){l(wo),f(0);return}const y=()=>{const{barInlineSize:x,nativeBarInlineSize:E}=Xi(m,h,w,s);l(T=>T.scroller===m&&T.barInlineSize===x&&T.nativeBarInlineSize===E?T:Object.freeze({scroller:m,barInlineSize:x,nativeBarInlineSize:E})),f(x)};y();const p=new ResizeObserver(y);return p.observe(m),p.observe(h),p.observe(w),window.addEventListener("resize",y),()=>{p.disconnect(),window.removeEventListener("resize",y)}},[e,t,n,r,s]),a},Ji=(e,t)=>{if(typeof e=="function"){const n=e(t);return typeof n=="function"?n:()=>e(null)}return e!=null?(e.current=t,()=>{e.current=null}):()=>{}};function Ms({scrollerProps:e,scrollerRef:t,children:n,renderScrollBar:r,rowClassName:o,rowStyle:s,onBarInlineSizeChange:a,barInlineSize:l}){const c=d.useRef(null),u=d.useRef(null),f=d.useRef(null),m=r!==void 0,h=l===void 0?null:Fr("barInlineSize",l),w=e.style?.scrollbarWidth??"",y=Zi(m,c,u,f,a,w),p=d.useCallback(R=>{c.current=R;const b=Ji(t,R);return()=>{c.current=null,b()}},[t]),x=m?{...e.style,position:"relative",boxSizing:"border-box",overflowY:"scroll",width:`calc(100% + ${y.nativeBarInlineSize}px)`,...y.nativeBarInlineSize===0?Ki:void 0}:e.style,E=m&&y.nativeBarInlineSize===0,T=i.jsxs("div",{...e,...E?Yi:void 0,ref:p,style:x,children:[n,m&&i.jsx("span",{ref:u,"data-aqmd-scroll-bar-probe":!0,"aria-hidden":"true",style:Vi})]});return m?i.jsxs("div",{"data-aqmd-scroll-row":!0,className:o,style:s===void 0?xo:{...xo,...s},children:[i.jsx("div",{"data-aqmd-scroll-clip":!0,style:Gi,children:T}),i.jsx("div",{ref:f,"data-aqmd-scroll-bar":!0,style:h===null?bo:{...bo,inlineSize:h},children:y.scroller!==null&&r(y.scroller)})]}):T}const Qi=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),el=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,r)=>r?r.toUpperCase():n.toLowerCase()),So=e=>{const t=el(e);return t.charAt(0).toUpperCase()+t.slice(1)},Is=(...e)=>e.filter((t,n,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===n).join(" ").trim(),tl=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};var nl={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const rl=d.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:o="",children:s,iconNode:a,...l},c)=>d.createElement("svg",{ref:c,...nl,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:Is("lucide",o),...!s&&!tl(l)&&{"aria-hidden":"true"},...l},[...a.map(([u,f])=>d.createElement(u,f)),...Array.isArray(s)?s:[s]]));const re=(e,t)=>{const n=d.forwardRef(({className:r,...o},s)=>d.createElement(rl,{ref:s,iconNode:t,className:Is(`lucide-${Qi(So(e))}`,`lucide-${e}`,r),...o}));return n.displayName=So(e),n};const ol=[["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}],["path",{d:"M10.41 10.41a2 2 0 1 1-2.83-2.83",key:"1bzlo9"}],["line",{x1:"13.5",x2:"6",y1:"13.5",y2:"21",key:"1q0aeu"}],["line",{x1:"18",x2:"21",y1:"12",y2:"15",key:"5mozeu"}],["path",{d:"M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59",key:"mmje98"}],["path",{d:"M21 15V5a2 2 0 0 0-2-2H9",key:"43el77"}]],sl=re("image-off",ol);class Ds extends d.Component{constructor(t){super(t),this.state={content:t.content,failed:!1}}static getDerivedStateFromProps(t,n){return t.content===n.content?null:{content:t.content,failed:!1}}static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?i.jsxs("div",{"data-aqmd-block-failure":"",children:[i.jsx("p",{"data-aqmd-block-failure-notice":"",lang:this.props.label.lang,children:this.props.label.text}),i.jsx("pre",{"data-aqmd-block-failure-text":"",children:i.jsx("code",{children:this.props.text()})})]}):this.props.children}}const Ps=Object.freeze({blockFailed:{text:"This block could not be shown.",lang:"en"}}),al=1024,an=(e,t)=>e.fingerprint===t.fingerprint&&e.content===t.content,il=(e,t)=>{let n=0;for(;n<e.length&&n<t.length&&an(e[n],t[n]);)n+=1;let r=0;for(;r<e.length-n&&r<t.length-n&&an(e[e.length-1-r],t[t.length-1-r]);)r+=1;const o=Array.from({length:n},(l,c)=>[c,c]),s=Array.from({length:r},(l,c)=>[e.length-r+c,t.length-r+c]),a=ll(e,t,n,e.length-r,t.length-r);return[...o,...a,...s]},ll=(e,t,n,r,o)=>{const s=new Set(e.slice(n,r).map(b=>b.fingerprint)),a=new Set(t.slice(n,o).map(b=>b.fingerprint)),l=[];for(let b=n;b<r;b+=1)a.has(e[b].fingerprint)&&l.push(b);const c=[];for(let b=n;b<o;b+=1)s.has(t[b].fingerprint)&&c.push(b);const u=l.length,f=c.length;if(u===0||f===0)return[];const m=(b,k)=>an(e[l[b]],t[c[k]]),h=(b,k)=>e[l[b]].fingerprint===t[c[k]].fingerprint,w=(b,k)=>{let A=b;for(;A<u&&A+k<f&&m(A,A+k);)A+=1;return A},y=[Int32Array.of(w(0,0))],p=[Uint8Array.of(Zn)],x=f-u;let E=0;for(;!(x>=-E&&x<=E&&y[E][x+E]===u);){if(E+=1,E>al)return[];const b=y[E-1],k=L=>L>=-(E-1)&&L<=E-1?b[L+E-1]:-1,A=new Int32Array(2*E+1).fill(-1),P=new Uint8Array(2*E+1);for(let L=-E;L<=E;L+=1){if(L<-u||L>f)continue;let B=-1,$=Zn;const F=k(L);F!==-1&&F<u&&F+L<f&&h(F,F+L)&&(B=F+1,$=vo);const q=k(L+1);q!==-1&&q+1<=u&&q+1>B&&(B=q+1,$=ko);const H=k(L-1);H!==-1&&H+L<=f&&H>B&&(B=H,$=Jn),B!==-1&&(A[L+E]=w(B,L),P[L+E]=$)}y.push(A),p.push(P)}const T=[];let R=x;for(let b=E;b>=0;b-=1){const k=y[b][R+b],A=p[b][R+b],P=A===ko?R+1:A===Jn?R-1:R,L=A===Zn?0:y[b-1][P+b-1]+(A===Jn?0:1);for(let B=k-1;B>=L;B-=1)T.push([l[B],c[B+R]]);A===vo&&T.push([l[L-1],c[L-1+R]]),R=P}return T.reverse()},Zn=0,vo=1,ko=2,Jn=3,$s=(e,t,n)=>{const r=e.map(()=>null),o=new Set,s=[];for(const[u,f]of il(t,e))n.contentOnly&&!an(t[u],e[f])||(r[f]=t[u].key,o.add(u),s.push([u,f]));const a=new Map;for(const[u,f]of t.entries()){if(o.has(u))continue;const m=a.get(f.fingerprint);m===void 0?a.set(f.fingerprint,[u]):m.push(u)}const l=u=>{for(const[f,m]of e.entries()){if(r[f]!==null)continue;const h=a.get(m.fingerprint),w=h===void 0?-1:h.findIndex(y=>u(m,t[y]));if(h!==void 0&&w!==-1){const[y]=h.splice(w,1);r[f]=t[y].key,o.add(y)}}};if(l(an),n.contentOnly||l(()=>!0),n.inherit&&!n.contentOnly){let u=-1;for(const[f,m]of e.entries()){for(;u+1<s.length&&s[u+1][1]<f;)u+=1;if(r[f]!==null)continue;const[h,w]=u===-1?[-1,-1]:s[u],y=h+(f-w);y<t.length&&!o.has(y)&&t[y].root===m.root&&(r[f]=t[y].key,o.add(y))}}const c=new Set([...t.map(u=>u.key),...r.filter(u=>u!==null)]);return e.map((u,f)=>{let m=r[f];if(m===null){let h=0;for(;c.has(`${u.fingerprint}.${h}`);)h+=1;m=`${u.fingerprint}.${h}`,c.add(m)}return{...u,key:m}})},cl=/^[\t\n\f\r ]*$/u,dl=(e,t)=>{if(t.length===0){if(!cl.test(e))throw new RangeError("MarkdownRenderer: blockOffsets is empty, but htmlContent holds blocks");return}if(t[0]!==0)throw new RangeError(`MarkdownRenderer: blockOffsets must start at 0, got ${t[0]}`);for(const[n,r]of t.entries()){if(!Number.isSafeInteger(r))throw new RangeError(`MarkdownRenderer: blockOffsets[${n}] must be a safe integer, got ${r}`);if(n>0&&r<=t[n-1])throw new RangeError(`MarkdownRenderer: blockOffsets must increase, got ${r} after ${t[n-1]} at ${n}`);if(r>=e.length)throw new RangeError(`MarkdownRenderer: blockOffsets[${n}] (${r}) must lie inside htmlContent (${e.length} UTF-16 code units)`)}},ul=(e,t)=>t.map((n,r)=>e.slice(n,r+1<t.length?t[r+1]:e.length)),fl=e=>{if(!Number.isSafeInteger(e))throw new RangeError(`MarkdownRenderer: blockKeyEpoch must be a safe integer, got ${e}`)},zs=e=>e===void 0||e.trim()===""?void 0:e;const ml=[["path",{d:"M10 12h4",key:"a56b0p"}],["path",{d:"M10 8h4",key:"1sr2af"}],["path",{d:"M14 21v-3a2 2 0 0 0-4 0v3",key:"1rgiei"}],["path",{d:"M6 10H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-2",key:"secmi2"}],["path",{d:"M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16",key:"16ra0t"}]],hl=re("building-2",ml);const pl=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],To=re("globe",pl),gl=/^[a-z]{2,3}$/u,yl=e=>{const t=e.trim().split("-",1)[0]?.toLowerCase()??"";return gl.test(t)?t:null},Bs=()=>()=>{},xl=e=>{const t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]}),()=>t.disconnect()},Fs=()=>d.useSyncExternalStore(Bs,()=>window.location.origin,()=>null),bl=()=>d.useSyncExternalStore(Bs,()=>window.location.href,()=>null),wl=()=>d.useSyncExternalStore(xl,()=>yl(document.documentElement.lang),()=>null),El=/^[1-9]\d{0,4}$/u,Ro=e=>e!==void 0&&El.test(e.trim())?Number(e.trim()):null,Sl=({embed:e,label:t,insideAnchor:n,children:r})=>{const o=Fs(),s=new URL(e.src);if(o!==null&&s.origin!==o&&!n)return r;const a=Ro(e.attributes.width),l=Ro(e.attributes.height),c=a!==null&&l!==null?{width:"100%",maxWidth:`${a}px`,aspectRatio:`${a} / ${l}`}:void 0,u=e.attributes.title,f=u===void 0?t.lang:void 0;return i.jsx("span",{"data-embed-frame":o===null?"pending":"refused","data-aqmd-embed-surface":c===void 0?void 0:"",style:c,className:c===void 0?void 0:"flex items-center justify-center rounded-lg p-2 text-center",children:n?i.jsx("span",{lang:f,children:`${u??t.text}: ${s.hostname}`}):i.jsx("a",{href:s.href,target:"_blank",rel:"noreferrer",lang:f,children:u??`${t.text}: ${s.hostname}`})})},qs=(e,t)=>fetch(e,t),Hs=d.createContext(qs),vl=e=>{const t=d.useRef(e);return d.useLayoutEffect(()=>{t.current=e},[e]),d.useCallback((n,r)=>(t.current??qs)(n,r),[])},Ht=e=>new Promise(t=>t(e())),Us=({concurrency:e,capacity:t,timeoutMs:n})=>{for(const[f,m]of Object.entries({concurrency:e,capacity:t,timeoutMs:n}))if(!Number.isInteger(m)||m<=0)throw new RangeError(`[@aiquants/markdown] request queue ${f} must be a positive integer; got ${String(m)}`);const r=new Map,o=new Map,s=[];let a=0;const l=(f,m,h)=>{if(o.get(f)===m&&(o.delete(f),h!==null)){r.set(f,h);for(const w of r.keys()){if(r.size<=t)break;r.delete(w)}for(const w of m.subscriptions)w.listener(h)}},c=()=>{for(;a<e;){const f=s.shift();if(f===void 0)return;const m=o.get(f);if(m===void 0)continue;const h=new AbortController;m.controller=h,a+=1,Ht(()=>m.start(AbortSignal.any([h.signal,AbortSignal.timeout(n)]))).then(w=>l(f,m,{ok:!0,value:w}),()=>l(f,m,h.signal.aborted?null:{ok:!1})).finally(()=>{a-=1,c()})}};return Object.freeze({subscribe:(f,m,h)=>{const w=r.get(f);if(w!==void 0)return r.delete(f),r.set(f,w),h(w),()=>{};let y=o.get(f);y===void 0&&(y={start:m,subscriptions:new Set,controller:null},o.set(f,y),s.push(f));const p=y,x={listener:h};return p.subscriptions.add(x),c(),()=>{p.subscriptions.delete(x),!(p.subscriptions.size>0||o.get(f)!==p)&&(o.delete(f),p.controller===null?s.splice(s.indexOf(f),1):p.controller.abort())}}})},kl=Us({concurrency:2,capacity:256,timeoutMs:15e3}),Tl="[data-aqmd-scroll-container]",Rl=async(e,t,n)=>{let r;try{r=await e(t,{credentials:"same-origin",redirect:"error",headers:{accept:"application/json"},signal:n})}catch(a){if(n.aborted)throw a;return{kind:"error",cause:"network error"}}if(r.status===204){const a=ot.linkCardSkipReasonOf(r.headers.get(ot.LINK_CARD_SKIP_HEADER));return a===null?{kind:"error",cause:"HTTP 204 without a known skip reason"}:{kind:"skip",reason:a}}if(!r.ok)return{kind:"error",cause:`HTTP ${r.status}`};let o;try{o=await r.json()}catch(a){if(n.aborted)throw a;return{kind:"error",cause:`HTTP ${r.status}, not JSON`}}const s=ot.linkCardMetadataOf(o);return s===null?{kind:"error",cause:`HTTP ${r.status}, not a JSON object`}:{kind:"card",metadata:s}},_l=e=>e.ok?e.value.kind==="card"?null:e.value.kind==="skip"?e.value.reason:e.value.cause:"network error",_o=(e,t)=>e!==null&&new URL(e).hostname!==t?e:null,Qn=({tile:e,tileKind:t,primary:n,secondary:r})=>i.jsxs("span",{className:"flex min-w-0 flex-auto items-center gap-3 px-3",children:[i.jsx("span",{"aria-hidden":"true","data-link-card-icon":t,className:`flex size-8 shrink-0 items-center justify-center rounded-md bg-(--aqmd-link-card-bg-hover) text-(--aqmd-link-card-muted) ${t==="pending"?"motion-safe:animate-pulse":""}`,children:e}),i.jsxs("span",{className:"flex min-w-0 flex-col gap-0.5",children:[i.jsx("span",{className:"truncate font-semibold text-[0.875rem] leading-5",children:n}),i.jsx("span",{className:"truncate text-(--aqmd-link-card-muted) text-xs leading-4",children:r})]})]}),Ol=({href:e,endpoint:t,size:n,fallback:r})=>{const o=bl(),s=o===null?null:new URL(o).hostname,a=d.useContext(Hs),l=d.useRef(null),c=new URL(e),u=`${t}
7
+ ${c.href}`,[f,m]=d.useState(null);d.useEffect(()=>{const T=l.current;if(T===null||s===null)return;let R=null;const b=new IntersectionObserver(k=>{R!==null||!k.some(A=>A.isIntersecting)||(b.disconnect(),R=kl.subscribe(u,A=>Rl(a,ot.linkCardRequestOf(t,new URL(e),window.location.href),A),A=>{m({key:u,outcome:A});const P=_l(A);P!==null&&vr.linkCardLogger.info(`No link card for ${e} (${P})`)}))},{root:T.closest(Tl),rootMargin:"100% 0px"});return b.observe(T),()=>{b.disconnect(),R?.()}},[u,t,e,s,a]);const h=f!==null&&f.key===u?f.outcome:null;if(h!==null&&!h.ok)return r;const w=h===null?null:h.value;if(w!==null&&w.kind==="error")return r;if(w===null||s===null)return i.jsx("a",{ref:l,href:e,target:"_blank",rel:"noreferrer","aria-busy":"true","data-link-card":"pending","data-link-card-size":n,children:n==="compact"?i.jsx(Qn,{tile:null,tileKind:"pending",primary:c.hostname,secondary:e}):i.jsxs("span",{className:"flex min-w-0 flex-1 flex-col justify-center gap-2 px-4 py-3.5",children:[i.jsx("span",{"aria-hidden":"true",className:"block h-3.5 w-2/3 rounded bg-(--aqmd-link-card-border) motion-safe:animate-pulse"}),i.jsx("span",{className:"truncate text-(--aqmd-link-card-muted) text-[0.8125rem] leading-[1.125rem]",children:c.hostname}),i.jsx("span",{className:"truncate text-(--aqmd-link-card-muted) text-xs leading-4",children:e})]})});if(w.kind==="skip"){const{reason:T}=w,R=T==="private-network",b=R?hl:To;return i.jsx("a",{ref:l,href:e,target:"_blank",rel:"noreferrer","data-link-card":"compact","data-link-card-reason":T,"data-link-card-size":"compact",children:i.jsx(Qn,{tile:i.jsx(b,{"aria-hidden":"true",className:"size-4"}),tileKind:R?"internal":"link",primary:c.hostname,secondary:e})})}const{metadata:y}=w,p=_o(y.image,s),x=_o(y.icon,s),E=y.siteName===null?c.hostname:`${y.siteName} · ${c.hostname}`;return n==="compact"?i.jsx("a",{ref:l,href:e,target:"_blank",rel:"noreferrer","data-link-card":"ready","data-link-card-size":"compact",children:i.jsx(Qn,{tile:x===null?i.jsx(To,{"aria-hidden":"true",className:"size-4"}):i.jsx("img",{src:x,alt:"",width:16,height:16,loading:"lazy",referrerPolicy:"no-referrer",className:"size-4 rounded-[3px]"}),tileKind:x===null?"link":"favicon",primary:y.title??e,secondary:E})}):i.jsxs("a",{ref:l,href:e,target:"_blank",rel:"noreferrer","data-link-card":"ready","data-link-card-size":n,children:[i.jsxs("span",{className:"flex min-w-0 flex-1 flex-col justify-center gap-1 px-4 py-3.5",children:[i.jsx("span",{className:"wrap-anywhere line-clamp-2 font-semibold text-[0.9375rem] leading-5",children:y.title??e}),y.description===null?null:i.jsx("span",{className:`wrap-anywhere text-(--aqmd-link-card-muted) text-[0.8125rem] leading-[1.125rem] ${n==="banner"?"line-clamp-1":"line-clamp-2"}`,children:y.description}),i.jsxs("span",{className:"mt-1 flex items-center gap-1.5 text-(--aqmd-link-card-muted) text-xs leading-4",children:[x===null?null:i.jsx("img",{src:x,alt:"",width:16,height:16,loading:"lazy",referrerPolicy:"no-referrer",className:"size-4 shrink-0 rounded-[3px]"}),i.jsx("span",{className:"truncate",children:E})]})]}),p===null?null:i.jsx("img",{src:p,alt:"",loading:"lazy",referrerPolicy:"no-referrer"})]})},Ws=e=>{if(!Array.isArray(e.providers))throw new RangeError(`[@aiquants/markdown] embeds.providers must be an array of provider ids; got ${typeof e.providers}`);for(const t of e.providers)if(!kt.isEmbedProviderId(t))throw new RangeError(`[@aiquants/markdown] embeds.providers holds an unknown provider id ${JSON.stringify(t)}; known ids are ${kt.EMBED_PROVIDER_IDS.join(", ")}`);if(e.linkCardEndpoint!==null&&!ot.isLinkCardEndpoint(e.linkCardEndpoint))throw new RangeError(`[@aiquants/markdown] embeds.linkCardEndpoint must be null or an absolute path without a trailing "/" (segments of A-Z a-z 0-9 . _ ~ -, no "." or ".."); got ${JSON.stringify(e.linkCardEndpoint)}`);if(e.linkCardSize!==void 0&&!ot.isLinkCardSize(e.linkCardSize))throw new RangeError(`[@aiquants/markdown] embeds.linkCardSize must be omitted or one of ${ot.LINK_CARD_SIZES.join(", ")}; got ${JSON.stringify(e.linkCardSize)}`);if(e.frameSandbox!==void 0&&!Xe.isEmbedFrameSandbox(e.frameSandbox))throw new RangeError(`[@aiquants/markdown] embeds.frameSandbox must be omitted or a list of ${[...Xe.EMBED_FRAME_SANDBOX_TOKENS].join(", ")}; got ${JSON.stringify(e.frameSandbox)}`);return e},tn=new WeakMap;let En=0;const Oo=e=>{if(e.source===null)return;const t=tn.get(e.source);if(t===void 0||e.origin!==t.watch.origin)return;const n=t.watch.heightOf(e.data,t.watch.src);if(n===null||!Number.isFinite(n))return;const r=Math.min(kt.EMBED_FRAME_HEIGHT_LIMITS.max,Math.max(kt.EMBED_FRAME_HEIGHT_LIMITS.min,Math.ceil(n)));r!==t.last&&(t.last=r,t.watch.set(r))},Al=(e,t)=>{const n={watch:t,last:null};return tn.has(e)||(En+=1,En===1&&window.addEventListener("message",Oo)),tn.set(e,n),()=>{tn.get(e)===n&&(tn.delete(e),En-=1,En===0&&window.removeEventListener("message",Oo))}},Nl=Us({concurrency:2,capacity:256,timeoutMs:5e3}),Cl=async(e,t)=>{const n=await fetch(e,{credentials:"omit",redirect:"error",referrerPolicy:"no-referrer",headers:{accept:"application/json"},signal:t});if(!n.ok)throw new Error(`[@aiquants/markdown] embed lookup answered ${n.status}`);return await n.json()},Ll=(e,t)=>{const n=e.maxWidth===null?void 0:`${e.maxWidth}px`;switch(e.kind){case"aspect":return{width:"100%",maxWidth:n,aspectRatio:`${e.ratio[0]} / ${e.ratio[1]}`};case"fixed":return{width:"100%",maxWidth:n,height:`${e.height}px`};case"message":return{width:"100%",maxWidth:n,height:`${t??e.initialHeight}px`}}},jl=Object.freeze({marginInline:0}),er=Object.freeze({kind:"pending"}),Ml=Object.freeze({kind:"narrow"}),Il=Object.freeze({kind:"fallback"}),Dl=(e,t,n,r,o)=>{if(t===null)return er;let s;if(e.kind==="frame")s=e.srcOf(n);else{if(r===null)return er;s=r.ok?e.srcOf(r.value,n):null}if(s===null||new URL(s).origin===t)return Il;const{minWidth:a,maxWidth:l}=e.layout;if(a!==null){if(o===null)return er;if(Math.min(o,l??Number.POSITIVE_INFINITY)<a)return Ml}return{kind:"frame",src:s}},Pl=({resolution:e,caption:t,fallback:n,theme:r,labels:o,frameSandbox:s})=>{const a=Fs(),l=wl(),[c,u]=d.useState(null),[f,m]=d.useState(null),h=e.kind==="lookup"?e.request.href:null,[w,y]=d.useState(null);d.useEffect(()=>{if(h!==null)return Nl.subscribe(h,$=>Cl(new URL(h),$),$=>y({key:h,outcome:$}))},[h]);const{provider:p,layout:x}=e,E=Dl(e,a,{theme:r,lang:l},w!==null&&w.key===h?w.outcome:null,c),T=d.useCallback($=>{if($===null)return;u($.getBoundingClientRect().width);const F=new ResizeObserver(()=>u($.getBoundingClientRect().width));return F.observe($),()=>F.disconnect()},[]),R=E.kind==="frame"?E.src:null,b=f!==null&&f.src===R?f.height:null,k=d.useCallback($=>{if(!($===null||$.contentWindow===null||x.kind!=="message"||R===null))return Al($.contentWindow,{origin:p.frameOrigin,src:R,heightOf:x.heightOf,set:F=>m({src:R,height:F})})},[x,p.frameOrigin,R]);if(E.kind==="fallback")return n;const A=x.minWidth===null?null:i.jsx("span",{ref:T,"aria-hidden":"true","data-embed-measure":p.id,className:"block h-0"});if(E.kind==="narrow")return i.jsxs(i.Fragment,{children:[A,n]});const P=p.content==="video"?o.embeddedVideo:o.embeddedPost,{frame:L}=p,B=Xe.narrowFrameSandbox(L.sandbox,s);return i.jsxs(i.Fragment,{children:[A,i.jsxs("figure",{"data-embed-provider":p.id,"data-embed-state":E.kind,style:jl,children:[i.jsx("div",{"data-embed-box":"","data-aqmd-embed-surface":"",style:Ll(x,b),className:"noscript:hidden overflow-hidden rounded-lg",children:E.kind==="frame"?i.jsx("iframe",{ref:k,src:E.src,title:`${p.name}: ${P.text}`,lang:P.lang,loading:"lazy",allow:L.allow??void 0,allowFullScreen:L.allowFullScreen,sandbox:B,referrerPolicy:L.referrerPolicy,scrolling:L.scrolling??void 0,className:"block h-full w-full border-0"},`${Xe.frameSandboxKeyOf(B)} ${E.src}`):null}),i.jsx("figcaption",{className:"mt-2",children:t})]})]})},Tr=9,$l=6,zl="data-aqmd-heading-depth",Bl=/^h([1-6])$/u,Fl=e=>{if(!Number.isSafeInteger(e)||e<1||e>Tr)throw new RangeError(`MarkdownRenderer: topHeadingLevel must be an integer from 1 to ${Tr}, got ${e}`)},ql=e=>{const t=Bl.exec(e);return t===null?void 0:Number(t[1])},Hl=(e,t)=>Math.min(e+t-1,Tr),Ul={lowerCaseAttributeNames:!1},Wl="<div></div>",on=e=>{const t=Q.htmlToDOM(`${Wl}${e}`,Ul),n=t.find(s=>s instanceof Q.Element),{prev:r,next:o}=n;return r!==null&&(r.next=o),o!==null&&(o.prev=r),t.filter(s=>s!==n)},Gl=["title","width","height","allow","allowfullscreen","sandbox","referrerpolicy","loading","frameborder","scrolling"],Vl=(e,t)=>({...e,attributes:{...e.attributes,sandbox:Xe.narrowFrameSandbox(e.attributes.sandbox,t)}}),Kl=(e,t)=>Xe.allowedFrameUrlOf(e,t)!==null,Yl=(e,t)=>{const n=new Map(Object.entries(e).map(([s,a])=>[s.toLowerCase(),a])),r=Xe.allowedFrameUrlOf(n.get("src"),t);if(r===null)return null;const o={};for(const s of Gl){const a=n.get(s);if(a!==void 0)if(s==="allow"){const l=Xe.reduceFrameFeatures(a);l!==null&&(o.allow=l)}else if(s==="referrerpolicy"){const l=a.trim().toLowerCase();Xe.EMBED_FRAME_REFERRER_POLICIES.has(l)&&(o.referrerpolicy=l)}else o[s]=a}return Object.freeze({src:r.href,attributes:Object.freeze(o)})},Xl=/^[a-z][a-z0-9+.-]*:/i,Zl=/^[/\\]{2}/,Jl=/[\t\n\r]/g,Ao=32,Ql=e=>{let t=0,n=e.length;for(;t<n&&e.charCodeAt(t)<=Ao;)t+=1;for(;n>t&&e.charCodeAt(n-1)<=Ao;)n-=1;return e.slice(t,n)},Gs=e=>Ql(e).replace(Jl,""),qr=e=>{const t=Gs(e);return Xl.test(t)||Zl.test(t)},ec="text-link underline visited:text-link-visited",tc="inline-block w-fit",Hr=new Set(["img","picture","video","audio","svg","canvas","iframe","object","embed","address","article","aside","blockquote","details","dialog","dd","div","dl","dt","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","li","main","menu","nav","ol","p","pre","section","table","ul"]);[...Hr].join(",");const Vs=(e,t)=>[e,t?tc:void 0,ec].filter(n=>n!==void 0&&n.trim()!=="").join(" "),nc=new Set(["id","title","lang","dir","role"]),rc=["aria-","data-footnote-"],oc=e=>{const t={};for(const[n,r]of Object.entries(e)){const o=n.toLowerCase();(nc.has(o)||rc.some(s=>o.startsWith(s)&&o.length>s.length))&&(t[o]=r)}return Object.freeze(t)},sc=Object.freeze(["document","untrusted"]),Ur=/^[A-Za-z][A-Za-z0-9_-]*$/u,ac=(e,t)=>{if(!sc.includes(e))throw new RangeError(`MarkdownRenderer: allowlist must be "document" or "untrusted", got ${String(e)}`);if(e==="document"){if(t!==void 0)throw new RangeError('MarkdownRenderer: idPrefix needs allowlist "untrusted" (the ids of a document stay the names its links and the page use)');return{allowlist:e}}if(t===void 0)throw new RangeError('MarkdownRenderer: allowlist "untrusted" needs idPrefix (the ids of untrusted text never take the names of the page)');if(typeof t!="string"||!Ur.test(t))throw new RangeError(`MarkdownRenderer: idPrefix must be an ASCII letter followed by ASCII letters, digits, "-" and "_", got ${typeof t=="string"?JSON.stringify(t):String(t)}`);return{allowlist:e,idPrefix:t}},ic=new Set(["video","audio","source","main","nav","header","footer","section","article"]),lc=new Set(["aside"]),cc=new Set(["name","headers","hidden"]),dc=new Set(["doc-noteref","doc-backlink","doc-endnotes"]),uc=new Set(["aria-hidden"]),fc=new Set(["script","style","template","noscript","noembed","noframes","plaintext","xmp","title","head","meta","link","base","object","embed","applet","param","frame","frameset","select","datalist","track","math","foreignobject"]),mc=new Set(["id","class","title","lang","dir","role","hidden","translate","style"]),hc=new Set(["markdown-alert","markdown-alert-title","markdown-alert-note","markdown-alert-tip","markdown-alert-important","markdown-alert-warning","markdown-alert-caution","octicon","octicon-info","octicon-light-bulb","octicon-report","octicon-alert","octicon-stop","mr-2","message","message-symbol","message-content","alert","info","warning","markdown-details","markdown-details-content","footnotes","footnote-ref","footnote-backref","math","inline","display"]),No="language-",pc=/[\t\n\f\r ]+/u,gc=new Set(["h1","h2","h3","h4","h5","h6"]),Co=Object.freeze({sup:/^fnref\d*:\d+$/u,li:/^fn:\d+$/u}),Lo="user-content-",Fe=["align"],It=["width","height"],jo=["colspan","rowspan","headers","scope","abbr","align","valign","width","height"],Sn=Object.freeze({a:["href","name","hreflang","data-link-kind","data-doc-path","data-doc-exists","data-footnote-ref","data-footnote-backref"],abbr:[],address:[],article:[],aside:[],audio:["src","controls","loop","muted","preload"],b:[],bdi:[],bdo:[],blockquote:["cite"],br:[],caption:Fe,cite:[],code:[me.CODE_META_ATTRIBUTE],col:["span",...Fe,...It],colgroup:["span",...Fe,...It],dd:[],del:["cite","datetime"],details:["open"],dfn:[],div:Fe,dl:[],dt:[],em:[],figcaption:[],figure:[],footer:[],h1:Fe,h2:Fe,h3:Fe,h4:Fe,h5:Fe,h6:Fe,header:[],hgroup:[],hr:[],i:[],img:["src","alt","loading","decoding",...Fe,...It,"data-asset-src","data-asset-exists"],ins:["cite","datetime"],kbd:[],li:["value"],main:[],mark:[],nav:[],ol:["start","reversed","type"],p:Fe,pre:[me.OPEN_CODE_ATTRIBUTE],q:["cite"],rp:[],rt:[],ruby:[],s:[],samp:[],section:["data-footnotes"],small:[],source:["src","type"],span:[],strong:[],sub:[],summary:[],sup:[],table:[...Fe,"border",...It],tbody:[...Fe,"valign"],td:jo,tfoot:[...Fe,"valign"],th:jo,thead:[...Fe,"valign"],time:["datetime"],tr:[...Fe,"valign"],u:[],ul:[],var:[],video:["src","poster","controls","loop","muted","playsinline","preload",...It],wbr:[]}),tr=Object.freeze({svg:["viewbox","version","xmlns","focusable","fill",...It],g:["fill","fill-rule","clip-rule"],path:["d","fill","fill-rule","clip-rule"]}),yc=new Set(["svg","g"]),Ks=new Set(["href","src","cite","poster",Xe.EMBED_LINK_ATTRIBUTE]),xc=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/gu,bc=/^(?:(?:https?|mailto|tel):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/iu,wc=new Set(["left","right","center","justify","start","end"]),mn=e=>bc.test(e.replace(xc,"")),Ec=e=>{let t=null;for(const n of e.split(";")){const r=n.indexOf(":");if(r<0||n.slice(0,r).trim().toLowerCase()!=="text-align")continue;const o=n.slice(r+1).trim().toLowerCase();wc.has(o)&&(t=o)}return t===null?null:`text-align: ${t}`},Sc=e=>{const t=e.split(pc).filter(n=>hc.has(n)||n.startsWith(No)&&n.length>No.length);return t.length===0?null:t.join(" ")},vc=(e,t)=>gc.has(e)&&t!==""||t.startsWith(Lo)&&t.length>Lo.length||Object.hasOwn(Co,e)&&Co[e].test(t),kc=e=>{const t=new Map;for(const[n,r]of Object.entries(e)){const o=n.toLowerCase();t.has(o)||t.set(o,r)}return t},Tc=(e,t,n)=>{if(e==="id")return`${n}${t}`;if(!Ks.has(e))return t;const r=Gs(t);return r.startsWith("#")?`#${n}${r.slice(1)}`:t},jt=(e,t,n,r)=>{const{allowlist:o}=r,s={};for(const[a,l]of t){if(a===zt.SOURCE_LINES_ATTRIBUTE){zt.parseSourceLines(l)!==null&&(s[a]=l);continue}if(!(o==="untrusted"&&(cc.has(a)||a==="title"&&lc.has(e)||a==="role"&&!dc.has(l)||a.startsWith("aria-")&&!uc.has(a)))&&(mc.has(a)||n.includes(a)||a.startsWith("aria-")&&a.length>5)&&!(Ks.has(a)&&!mn(l))&&!(a==="fill"&&/url\s*\(/iu.test(l))&&!(a==="id"&&!vc(e,l))){if(a==="class"||a==="style"){const c=a==="class"?Sc(l):Ec(l);c!==null&&(s[a]=c);continue}s[a]=r.idPrefix===void 0?l:Tc(a,l,r.idPrefix)}}return s},Rc=e=>e.get("type")?.trim().toLowerCase()==="checkbox"&&e.has("disabled"),Wn=(e,t,n)=>{const r=e.toLowerCase(),o=n.parentName===null?null:n.parentName.toLowerCase(),s=kc(t),{allowlist:a}=n;if(o!==null&&yc.has(o)){const c=r!=="svg"&&Object.hasOwn(tr,r)?tr[r]:void 0;return c===void 0?{action:"remove"}:{action:"keep",attributes:jt(r,s,c,n)}}if(r==="svg")return{action:"keep",attributes:jt(r,s,tr.svg,n)};if(r==="iframe"){const c=a==="untrusted"?null:Yl(Object.fromEntries(s),n.iFrameAllowedDomains);return c===null?{action:"remove"}:{action:"embed",embed:c,pluginType:s.get("data-plugin-type")??null}}if(r==="p"){const c=jt(r,s,Sn.p,n),u=a==="untrusted"?void 0:s.get(Xe.EMBED_LINK_ATTRIBUTE);return u!==void 0&&mn(u)?{action:"placeholder",attributes:c,link:u}:{action:"keep",attributes:c}}if(r==="input")return Rc(s)?{action:"keep",attributes:jt(r,s,["type","checked","disabled"],n)}:{action:"remove"};if(fc.has(r))return{action:"remove"};if(a==="untrusted"){if(ic.has(r))return{action:"unwrap"};if(r==="img")return{action:"image",attributes:jt(r,s,Sn.img,n)}}const l=Object.hasOwn(Sn,r)?Sn[r]:void 0;return l===void 0?{action:"unwrap"}:{action:"keep",attributes:jt(r,s,l,n)}};typeof window<"u"&&(window.NodeList&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),typeof window.CustomEvent!="function"&&(window.CustomEvent=function(t,n){n=n||{bubbles:!1,cancelable:!1,detail:null};var r=document.createEvent("CustomEvent");return r.initCustomEvent(t,n.bubbles,n.cancelable,n.detail),r}));const _c=typeof document<"u"&&!!document.documentMode;let nr;function Oc(){return nr||(nr=document.createElement("div").style)}const Mo=["webkit","moz","ms"],vn={};function Wr(e){if(vn[e])return vn[e];const t=Oc();if(e in t)return vn[e]=e;const n=e[0].toUpperCase()+e.slice(1);let r=Mo.length;for(;r--;){const o=`${Mo[r]}${n}`;if(o in t)return vn[e]=o}}function kn(e,t){return parseFloat(t[Wr(e)])||0}function Tn(e,t,n=window.getComputedStyle(e)){const r=t==="border"?"Width":"";return{left:kn(`${t}Left${r}`,n),right:kn(`${t}Right${r}`,n),top:kn(`${t}Top${r}`,n),bottom:kn(`${t}Bottom${r}`,n)}}function Pt(e,t,n){e.style[Wr(t)]=n}function Ac(e,t){const n=Wr("transform");Pt(e,"transition",`${n} ${t.duration}ms ${t.easing}`)}function Nc(e,{x:t,y:n,scale:r,isSVG:o},s){if(Pt(e,"transform",`scale(${r}) translate(${t}px, ${n}px)`),o&&_c){const a=window.getComputedStyle(e).getPropertyValue("transform");e.setAttribute("transform",a)}}function rr(e){let t=e.parentNode;(!t||t.nodeType!==1)&&(t=document.documentElement);const n=window.getComputedStyle(e),r=window.getComputedStyle(t),o=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{elem:{style:n,width:o.width,height:o.height,top:o.top,bottom:o.bottom,left:o.left,right:o.right,margin:Tn(e,"margin",n),border:Tn(e,"border",n)},parent:{style:r,width:s.width,height:s.height,top:s.top,bottom:s.bottom,left:s.left,right:s.right,padding:Tn(t,"padding",r),border:Tn(t,"border",r)}}}let ln={down:"mousedown",move:"mousemove",up:"mouseup mouseleave"};typeof window<"u"&&(typeof window.PointerEvent=="function"?ln={down:"pointerdown",move:"pointermove",up:"pointerup pointerleave pointercancel"}:typeof window.TouchEvent=="function"&&(ln={down:"touchstart",move:"touchmove",up:"touchend touchcancel"}));function or(e,t,n,r){ln[e].split(" ").forEach(o=>{t.addEventListener(o,n,r)})}function sr(e,t,n){ln[e].split(" ").forEach(r=>{t.removeEventListener(r,n)})}function Ys(e,t){let n=e.length;for(;n--;)if(e[n].pointerId===t.pointerId)return n;return-1}function Rr(e,t){let n;if(t.touches){n=0;for(const r of t.touches)r.pointerId=n++,Rr(e,r);return}n=Ys(e,t),n>-1&&e.splice(n,1),e.push(t)}function Cc(e,t){if(t.touches){for(;e.length;)e.pop();return}const n=Ys(e,t);n>-1&&e.splice(n,1)}function Io(e){e=e.slice(0);let t=e.pop(),n;for(;n=e.pop();)t={clientX:(n.clientX-t.clientX)/2+t.clientX,clientY:(n.clientY-t.clientY)/2+t.clientY};return t}function ar(e){if(e.length<2)return 0;const t=e[0],n=e[1];return Math.sqrt(Math.pow(Math.abs(n.clientX-t.clientX),2)+Math.pow(Math.abs(n.clientY-t.clientY),2))}function Lc(e){let t=e;for(;t&&t.parentNode;){if(t.parentNode===document)return!0;t=t.parentNode instanceof ShadowRoot?t.parentNode.host:t.parentNode}return!1}function jc(e){return(e.getAttribute("class")||"").trim()}function Mc(e,t){return e.nodeType===1&&` ${jc(e)} `.indexOf(` ${t} `)>-1}function Ic(e,t){for(let n=e;n!=null;n=n.parentNode)if(Mc(n,t.excludeClass)||t.exclude.indexOf(n)>-1)return!0;return!1}const Dc=/^http:[\w\.\/]+svg$/;function Pc(e){return Dc.test(e.namespaceURI)&&e.nodeName.toLowerCase()!=="svg"}function $c(e){const t={};for(const n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}const Xs={animate:!1,canvas:!1,cursor:"move",disablePan:!1,disableZoom:!1,disableXAxis:!1,disableYAxis:!1,duration:200,easing:"ease-in-out",exclude:[],excludeClass:"panzoom-exclude",handleStartEvent:e=>{e.preventDefault(),e.stopPropagation()},maxScale:4,minScale:.125,overflow:"hidden",panOnlyWhenZoomed:!1,pinchAndPan:!1,relative:!1,setTransform:Nc,startX:0,startY:0,startScale:1,step:.3,touchAction:"none"};function Zs(e,t){if(!e)throw new Error("Panzoom requires an element as an argument");if(e.nodeType!==1)throw new Error("Panzoom requires an element with a nodeType of 1");if(!Lc(e))throw new Error("Panzoom should be called on elements that have been attached to the DOM");t={...Xs,...t};const n=Pc(e),r=e.parentNode;r.style.overflow=t.overflow,r.style.userSelect="none",r.style.touchAction=t.touchAction,(t.canvas?r:e).style.cursor=t.cursor,e.style.userSelect="none",e.style.touchAction=t.touchAction,Pt(e,"transformOrigin",typeof t.origin=="string"?t.origin:n?"0 0":"50% 50%");function o(){r.style.overflow="",r.style.userSelect="",r.style.touchAction="",r.style.cursor="",e.style.cursor="",e.style.userSelect="",e.style.touchAction="",Pt(e,"transformOrigin","")}function s(O={}){for(const z in O)O.hasOwnProperty(z)&&(t[z]=O[z]);(O.hasOwnProperty("cursor")||O.hasOwnProperty("canvas"))&&(r.style.cursor=e.style.cursor="",(t.canvas?r:e).style.cursor=t.cursor),O.hasOwnProperty("overflow")&&(r.style.overflow=O.overflow),O.hasOwnProperty("touchAction")&&(r.style.touchAction=O.touchAction,e.style.touchAction=O.touchAction)}let a=0,l=0,c=1,u=!1;p(t.startScale,{animate:!1,force:!0}),setTimeout(()=>{y(t.startX,t.startY,{animate:!1,force:!0})});function f(O,z,g){if(g.silent)return;const v=new CustomEvent(O,{detail:z});e.dispatchEvent(v)}function m(O,z,g){const v={x:a,y:l,scale:c,isSVG:n,originalEvent:g};return requestAnimationFrame(()=>{typeof z.animate=="boolean"&&(z.animate?Ac(e,z):Pt(e,"transition","none")),z.setTransform(e,v,z),f(O,v,z),f("panzoomchange",v,z)}),v}function h(O,z,g,v){const S={...t,...v},j={x:a,y:l,opts:S};if(!v?.force&&(S.disablePan||S.panOnlyWhenZoomed&&c===S.startScale))return j;if(O=parseFloat(O),z=parseFloat(z),S.disableXAxis||(j.x=(S.relative?a:0)+O),S.disableYAxis||(j.y=(S.relative?l:0)+z),S.contain){const D=rr(e),ae=D.elem.width/c,W=D.elem.height/c,ie=ae*g,Ee=W*g,xe=(ie-ae)/2,Se=(Ee-W)/2;if(S.contain==="inside"){const be=(-D.elem.margin.left-D.parent.padding.left+xe)/g,Oe=(D.parent.width-ie-D.parent.padding.left-D.elem.margin.left-D.parent.border.left-D.parent.border.right+xe)/g;j.x=Math.max(Math.min(j.x,Oe),be);const Ke=(-D.elem.margin.top-D.parent.padding.top+Se)/g,Ie=(D.parent.height-Ee-D.parent.padding.top-D.elem.margin.top-D.parent.border.top-D.parent.border.bottom+Se)/g;j.y=Math.max(Math.min(j.y,Ie),Ke)}else if(S.contain==="outside"){const be=(-(ie-D.parent.width)-D.parent.padding.left-D.parent.border.left-D.parent.border.right+xe)/g,Oe=(xe-D.parent.padding.left)/g;j.x=Math.max(Math.min(j.x,Oe),be);const Ke=(-(Ee-D.parent.height)-D.parent.padding.top-D.parent.border.top-D.parent.border.bottom+Se)/g,Ie=(Se-D.parent.padding.top)/g;j.y=Math.max(Math.min(j.y,Ie),Ke)}}return S.roundPixels&&(j.x=Math.round(j.x),j.y=Math.round(j.y)),j}function w(O,z){const g={...t,...z},v={scale:c,opts:g};if(!z?.force&&g.disableZoom)return v;let S=t.minScale,j=t.maxScale;if(g.contain){const D=rr(e),ae=D.elem.width/c,W=D.elem.height/c;if(ae>1&&W>1){const ie=D.parent.width-D.parent.border.left-D.parent.border.right,Ee=D.parent.height-D.parent.border.top-D.parent.border.bottom,xe=ie/ae,Se=Ee/W;t.contain==="inside"?j=Math.min(j,xe,Se):t.contain==="outside"&&(S=Math.max(S,xe,Se))}}return v.scale=Math.min(Math.max(O,S),j),v}function y(O,z,g,v){const S=h(O,z,c,g);return a!==S.x||l!==S.y?(a=S.x,l=S.y,m("panzoompan",S.opts,v)):{x:a,y:l,scale:c,isSVG:n,originalEvent:v}}function p(O,z,g){const v=w(O,z),S=v.opts;if(!z?.force&&S.disableZoom)return;O=v.scale;let j=a,D=l;if(S.focal){const W=S.focal;j=(W.x/O-W.x/c+a*O)/O,D=(W.y/O-W.y/c+l*O)/O}const ae=h(j,D,O,{relative:!1,force:!0});return a=ae.x,l=ae.y,c=O,m("panzoomzoom",S,g)}function x(O,z){const g={...t,animate:!0,...z};return p(c*Math.exp((O?1:-1)*g.step),g)}function E(O){return x(!0,O)}function T(O){return x(!1,O)}function R(O,z,g,v){const S=rr(e),j={width:S.parent.width-S.parent.padding.left-S.parent.padding.right-S.parent.border.left-S.parent.border.right,height:S.parent.height-S.parent.padding.top-S.parent.padding.bottom-S.parent.border.top-S.parent.border.bottom};let D=z.clientX-S.parent.left-S.parent.padding.left-S.parent.border.left-S.elem.margin.left,ae=z.clientY-S.parent.top-S.parent.padding.top-S.parent.border.top-S.elem.margin.top;n||(D-=S.elem.width/c/2,ae-=S.elem.height/c/2);const W={x:D/j.width*(j.width*O),y:ae/j.height*(j.height*O)};return p(O,{...g,animate:!1,focal:W},v)}function b(O,z){O.preventDefault();const g={...t,...z,animate:!1},S=(O.deltaY===0&&O.deltaX?O.deltaX:O.deltaY)<0?1:-1,j=w(c*Math.exp(S*g.step/3),g).scale;return R(j,O,g,O)}function k(O){const z={...t,animate:!0,force:!0,...O};c=w(z.startScale,z).scale;const g=h(z.startX,z.startY,c,z);return a=g.x,l=g.y,m("panzoomreset",z)}let A,P,L,B,$,F;const q=[];function H(O){if(Ic(O.target,t))return;Rr(q,O),u=!0,t.handleStartEvent(O),A=a,P=l,f("panzoomstart",{x:a,y:l,scale:c,isSVG:n,originalEvent:O},t);const z=Io(q);L=z.clientX,B=z.clientY,$=c,F=ar(q)}function ce(O){if(!u||A===void 0||P===void 0||L===void 0||B===void 0)return;Rr(q,O);const z=Io(q),g=q.length>1;let v=c;if(g){F===0&&(F=ar(q));const S=ar(q)-F;v=w(S*t.step/80+$).scale,R(v,z,{animate:!1},O)}(!g||t.pinchAndPan)&&y(A+(z.clientX-L)/v,P+(z.clientY-B)/v,{animate:!1},O)}function oe(O){q.length===1&&f("panzoomend",{x:a,y:l,scale:c,isSVG:n,originalEvent:O},t),Cc(q,O),u&&(u=!1,A=P=L=B=void 0)}let ee=!1;function se(){ee||(ee=!0,or("down",t.canvas?r:e,H),or("move",document,ce,{passive:!0}),or("up",document,oe,{passive:!0}))}function Re(){ee=!1,sr("down",t.canvas?r:e,H),sr("move",document,ce),sr("up",document,oe)}return t.noBind||se(),{bind:se,destroy:Re,eventNames:ln,getPan:()=>({x:a,y:l}),getScale:()=>c,getOptions:()=>$c(t),handleDown:H,handleMove:ce,handleUp:oe,pan:y,reset:k,resetStyle:o,setOptions:s,setStyle:(O,z)=>Pt(e,O,z),zoom:p,zoomIn:E,zoomOut:T,zoomToPoint:R,zoomWithWheel:b}}Zs.defaultOptions=Xs;const zc=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],Bc=re("arrow-down",zc);const Fc=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],qc=re("arrow-left",Fc);const Hc=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],Uc=re("arrow-right",Hc);const Wc=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Gc=re("arrow-up",Wc);const Vc=[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]],Js=re("code-xml",Vc);const Kc=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],cn=re("copy",Kc);const Yc=[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]],Qs=re("download",Yc);const Xc=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],_r=re("refresh-cw",Xc);const Zc=[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]],Jc=re("settings-2",Zc);const Qc=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],ea=re("zoom-in",Qc);const ed=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],ta=re("zoom-out",ed),na=Object.freeze({light:Object.freeze({ground:"#ffffff",text:"#454e58",surface:Object.freeze({primary:"#dcecfe",secondary:"#ffe4e0",tertiary:"#d7f0e4",note:"#f0ead4"}),line:"#7d8792",series:Object.freeze(["#045b9e","#993932","#006649","#6c4799","#765200","#006175","#933861","#396400","#3f53a3","#944001","#00645c","#7f4088"]),seriesText:"#ffffff"}),dark:Object.freeze({ground:"#0d1117",text:"#a4afba",surface:Object.freeze({primary:"#172431",secondary:"#311e1b",tertiary:"#13271e",note:"#272311"}),line:"#646e78",series:Object.freeze(["#58a2ea","#e88074","#2fb285","#b18de4","#c9952d","#00accc","#e17fa7","#7aab52","#809af0","#e28655","#00b1a3","#c985d2"]),seriesText:"#0d1117"})}),Gr=-1,Or="�",td=/[\u0000\uD800-\uDFFF]/gu,ne=Object.freeze({quotationMark:34,numberSign:35,percentSign:37,apostrophe:39,leftParenthesis:40,rightParenthesis:41,plusSign:43,hyphenMinus:45,fullStop:46,lessThanSign:60,commercialAt:64,capitalE:69,reverseSolidus:92,lowLine:95,smallE:101}),nd=new Map([["(","("],[")",")"],[",","comma"],[":","colon"],[";","semicolon"],["[","["],["]","]"],["{","{"],["}","}"]]),pt=e=>e>=48&&e<=57,Do=e=>pt(e)||e>=65&&e<=70||e>=97&&e<=102,In=e=>e>=65&&e<=90||e>=97&&e<=122||e>=128||e===ne.lowLine,ra=e=>In(e)||pt(e)||e===ne.hyphenMinus,Dn=e=>e===10||e===13||e===12,At=e=>Dn(e)||e===9||e===32,rd=e=>e>=0&&e<=8||e===11||e>=14&&e<=31||e===127,Pn=e=>e===ne.quotationMark||e===ne.apostrophe,hn=e=>e.replace(/[A-Z]/gu,t=>t.toLowerCase()),le=(e,t)=>t<e.source.length?e.source.charCodeAt(t):Gr,Bt=(e,t)=>le(e,t)===ne.reverseSolidus&&!Dn(le(e,t+1));function Ar(e,t){const n=le(e,t);if(n!==ne.hyphenMinus)return In(n)||Bt(e,t);const r=le(e,t+1);return In(r)||r===ne.hyphenMinus||Bt(e,t+1)}function od(e,t){const n=le(e,t),r=le(e,t+1);return n===ne.plusSign||n===ne.hyphenMinus?pt(r)||r===ne.fullStop&&pt(le(e,t+2)):n===ne.fullStop?pt(r):pt(n)}function Nr(e){for(;At(le(e,e.index));)e.index+=1}function oa(e){e.index+=e.source.startsWith(`\r
8
+ `,e.index)?2:1}function Rn(e){for(;pt(le(e,e.index));)e.index+=1}function Gn(e){const t=le(e,e.index);if(t===Gr)return Or;if(!Do(t))return e.index+=1,String.fromCharCode(t);const n=e.index;for(;e.index-n<6&&Do(le(e,e.index));)e.index+=1;const r=Number.parseInt(e.source.slice(n,e.index),16);return At(le(e,e.index))&&oa(e),r===0||r>=55296&&r<=57343||r>1114111?Or:String.fromCodePoint(r)}function $n(e){let t="";for(let n=le(e,e.index);ra(n)||Bt(e,e.index);n=le(e,e.index))e.index+=1,t+=n===ne.reverseSolidus?Gn(e):String.fromCharCode(n);return t}function sd(e){const t=le(e,e.index);(t===ne.plusSign||t===ne.hyphenMinus)&&(e.index+=1),Rn(e),le(e,e.index)===ne.fullStop&&pt(le(e,e.index+1))&&(e.index+=1,Rn(e));const n=le(e,e.index);if(n!==ne.capitalE&&n!==ne.smallE)return;const r=le(e,e.index+1);pt(r)?(e.index+=1,Rn(e)):(r===ne.plusSign||r===ne.hyphenMinus)&&pt(le(e,e.index+2))&&(e.index+=2,Rn(e))}function ad(e){return sd(e),Ar(e,e.index)?($n(e),{type:"dimension",value:""}):le(e,e.index)!==ne.percentSign?{type:"number",value:""}:(e.index+=1,{type:"percentage",value:""})}function Po(e){for(;e.index<e.source.length;){const t=le(e,e.index),n=Bt(e,e.index);if(e.index+=1,t===ne.rightParenthesis)break;n&&Gn(e)}return{type:"bad-url",value:""}}function id(e){let t="";for(Nr(e);e.index<e.source.length;){const n=le(e,e.index);if(At(n)){Nr(e);const r=le(e,e.index);return r!==Gr&&r!==ne.rightParenthesis?Po(e):(r===ne.rightParenthesis&&(e.index+=1),{type:"url",value:t})}if(Pn(n)||n===ne.leftParenthesis||rd(n)||n===ne.reverseSolidus&&!Bt(e,e.index))return Po(e);if(e.index+=1,n===ne.rightParenthesis)return{type:"url",value:t};t+=n===ne.reverseSolidus?Gn(e):String.fromCharCode(n)}return{type:"url",value:t}}function ld(e){const t=$n(e);if(le(e,e.index)!==ne.leftParenthesis)return{type:"ident",value:t};if(e.index+=1,hn(t)!=="url")return{type:"function",value:t};for(;At(le(e,e.index))&&At(le(e,e.index+1));)e.index+=1;const n=le(e,e.index);return Pn(n)||At(n)&&Pn(le(e,e.index+1))?{type:"function",value:t}:id(e)}function cd(e,t){let n="";for(;e.index<e.source.length;){const r=le(e,e.index);if(Dn(r))return{type:"bad-string",value:""};if(e.index+=1,r===t)return{type:"string",value:n};r!==ne.reverseSolidus?n+=String.fromCharCode(r):Dn(le(e,e.index))?oa(e):e.index<e.source.length&&(n+=Gn(e))}return{type:"string",value:n}}function dd(e){const{source:t}=e,n=le(e,e.index);if(t.startsWith("/*",e.index)){const s=t.indexOf("*/",e.index+2);return e.index=s<0?t.length:s+2,{type:"comment",value:""}}if(At(n))return Nr(e),{type:"whitespace",value:""};if(od(e,e.index))return ad(e);if(n===ne.hyphenMinus&&t.startsWith("-->",e.index))return e.index+=3,{type:"CDC",value:""};if(In(n)||(n===ne.hyphenMinus||n===ne.reverseSolidus)&&Ar(e,e.index))return ld(e);if(t.startsWith("<!--",e.index))return e.index+=4,{type:"CDO",value:""};if(e.index+=1,Pn(n))return cd(e,n);if(n===ne.numberSign&&(ra(le(e,e.index))||Bt(e,e.index)))return{type:"hash",value:$n(e)};if(n===ne.commercialAt&&Ar(e,e.index))return{type:"at-keyword",value:$n(e)};const r=String.fromCharCode(n),o=nd.get(r);return o===void 0?{type:"delim",value:r}:{type:o,value:""}}function ft(e){const t={source:e.replace(td,Or),index:0},n=[];for(;t.index<t.source.length;){const r=t.index,{type:o,value:s}=dd(t);n.push({type:o,value:s,start:r,end:t.index})}return n}const Vr=/[\\<\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F\uD800-\uDFFF]/u,sa="--mermaid-font-family",ud=new Set([sa,"-webkit-box-orient","align-items","alignment-baseline","background","background-color","border","border-bottom","border-radius","box-shadow","color","cursor","display","dominant-baseline","dy","fill","fill-opacity","filter","flex-direction","font-family","font-size","font-style","font-weight","height","justify-content","line-height","margin","max-width","mix-blend-mode","opacity","overflow","overflow-wrap","padding","paint-order","pointer-events","position","rx","ry","scale","shape-rendering","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","text-align","text-anchor","text-decoration","text-overflow","transform","vertical-align","white-space","width","word-break","z-index"]),fd=new Set(["font-family","font-size","fill","max-width"]),md=Object.freeze({root:fd,inside:ud}),hd=new Set(["rgb","rgba","hsl","hsla","hwb","lab","lch","oklab","oklch","color","color-mix","light-dark","calc","min","max","clamp","matrix","matrix3d","perspective","rotate","rotate3d","rotatex","rotatey","rotatez","scale","scale3d","scalex","scaley","scalez","skew","skewx","skewy","translate","translate3d","translatex","translatey","translatez","linear-gradient","radial-gradient","conic-gradient","repeating-linear-gradient","repeating-radial-gradient","repeating-conic-gradient","blur","brightness","contrast","drop-shadow","grayscale","hue-rotate","invert","opacity","saturate","sepia"]),Cr=new Set(["fill","stroke","filter","clip-path","marker-start","marker-end"]),pd=new Set(["whitespace","ident","number","percentage","dimension","hash","string","comma","(",")"]),gd=new Set(["+","-","*","/","."]),zn=/^#\S+$/u,yd=new Map([["function",")"],["(",")"],["[","]"],["{","}"]]),xd=new Set([">","+","~"]),bd=new Map([["data-look","="],["id","$="]]),wd=new Set(["whitespace","comment","CDO","CDC"]),ut=(e,t,n)=>e.text.slice(e.tokens[t].start,e.tokens[n-1].end);function $t(e,t,n){let r=t,o=n;for(;r<o&&e[r].type==="whitespace";)r+=1;for(;o>r&&e[o-1].type==="whitespace";)o-=1;return[r,o]}function dn(e,t,n,r){const o=[];for(let s=t;s<n;s+=1){const{type:a}=e[s];if(o.length===0&&r.includes(a))return s;if(a===o[o.length-1])o.pop();else{const l=yd.get(a);l!==void 0&&o.push(l)}}return-1}function Ed(e,t){const n=dn(e,t+1,e.length,["semicolon","{"]);if(n<0)return e.length;if(e[n].type==="semicolon")return n+1;const r=dn(e,n+1,e.length,["}"]);return r<0?e.length:r+1}function Sd(e,t,n){let r=t+1;for(;r<n&&e.tokens[r].type!=="]";)r+=1;if(r===n)return null;const o=e.tokens.slice(t+1,r).filter(f=>f.type!=="whitespace"),s=o[0],a=o[o.length-1],l=o.slice(1,-1),c=s?.type==="ident"?bd.get(s.value):void 0;return c===void 0||a.type!=="ident"&&a.type!=="string"?null:l.length===c.length&&l.every((f,m)=>f.type==="delim"&&f.value===c[m])?{text:ut(e,t,r+1),end:r+1}:null}function vd(e,t,n,r){const o=e.tokens[t],s=t+1<n?e.tokens[t+1]:void 0;if(o.type==="hash"||o.type==="ident"||o.type==="delim"&&o.value==="*")return{text:ut(e,t,t+1),end:t+1};if(o.type==="delim"&&o.value==="."&&s?.type==="ident")return{text:`.${r}${ut(e,t+1,t+2)}`,end:t+2};if(o.type==="[")return Sd(e,t,n);if(o.type!=="colon")return null;const a=s?.type==="colon"?t+2:t+1;return a<n&&e.tokens[a].type==="ident"?{text:ut(e,t,a+1),end:a+1}:null}function kd(e,t,n,r){const[o,s]=$t(e.tokens,t,n);if(o===s||e.tokens[o].type!=="hash"||e.tokens[o].value!==r.svgId)return null;let a=ut(e,o,o+1),l=!1,c=o+1;for(;c<s;){const u=vd(e,c,s,r.classPrefix);if(u!==null){a+=u.text,c=u.end;continue}let f=c;for(;f<s&&(e.tokens[f].type==="whitespace"||e.tokens[f].type==="delim"&&xd.has(e.tokens[f].value));)f+=1;if(f===c||!l&&e.tokens.slice(c,f).some(m=>m.type==="delim"&&m.value!==">"))return null;l=!0,a+=ut(e,c,f),c=f}return{text:a,target:l?"inside":"root"}}function Td(e,t,n,r){if(Vr.test(e.text.slice(e.tokens[t].start,e.tokens[n].start)))return null;const o=[];let s=t;for(let a=t;a<=n;a+=1){if(a<n&&e.tokens[a].type!=="comma")continue;const l=kd(e,s,a,r);if(l===null)return null;o.push(l),s=a+1}return{text:o.map(({text:a})=>a).join(","),target:o.some(({target:a})=>a==="root")?"root":"inside"}}function $o(e,t,n){let r=n-1;for(;r>=t&&e[r].type==="whitespace";)r-=1;return r}function Rd(e,t,n){const r=$o(e,t,n);if(r<t||e[r].type!=="ident"||hn(e[r].value)!=="important")return n;const o=$o(e,t,r);return o>=t&&e[o].type==="delim"&&e[o].value==="!"?o:n}function Vn(e,t,n){const[r,o]=$t(e,t,n);if(r===o||e[r].type!=="ident")return null;const[s]=$t(e,r+1,o);if(s===o||e[s].type!=="colon")return null;const[a,l]=$t(e,s+1,Rd(e,s+1,o));return{first:r,end:o,property:e[r],valueFirst:a,valueEnd:l}}function Kn(e,t,n){const r=[];let o=t;for(;o<n;){const s=dn(e,o,n,["semicolon"]),a=s<0?n:s;r.push([o,a]),o=a+1}return r}function Kr(e){const t=[];let n=0;for(;n<e.length;){const{type:r}=e[n];if(wd.has(r)){n+=1;continue}if(r==="at-keyword"){n=Ed(e,n);continue}const o=dn(e,n,e.length,["{"]),s=o<0?-1:dn(e,o+1,e.length,["}"]);if(s<0)break;t.push({from:n,blockStart:o,blockEnd:s}),n=s+1}return t}function aa(e,t,n){const[r]=$t(e,t+1,n),[o]=$t(e,r+1,n);return o<n&&e[o].type===")"&&e[r].type!==")"?{argument:e[r],close:o}:null}function ia(e,t,n,r){let o=t;for(;o<n;){const s=e[o],a=s.type==="function"?hn(s.value):"";if(a==="url"||a==="var"){const l=aa(e,o,n),c=a==="url"?l?.argument.type==="string"&&zn.test(l.argument.value)&&Cr.has(r):l?.argument.type==="ident"&&l.argument.value===sa;if(l===null||!c)return!1;o=l.close+1;continue}if(s.type==="url"){if(!(Cr.has(r)&&zn.test(s.value)))return!1}else if(s.type==="function"){if(!hd.has(a))return!1}else if(s.type==="delim"?!gd.has(s.value):!pd.has(s.type))return!1;o+=1}return!0}function _d(e,t,n,r){const o=Vn(e.tokens,t,n);if(o===null)return null;const s=ut(e,o.first,o.end);return Vr.test(s)||!md[r].has(o.property.value)?null:o.valueFirst<o.valueEnd&&ia(e.tokens,o.valueFirst,o.valueEnd,o.property.value)?s:null}function la(e,t,n,r){const o=Kn(e.tokens,t,n).map(([s,a])=>_d(e,s,a,r)).filter(s=>s!==null);return o.length===0?null:o.join(";")}function Od(e,t,n){const r={text:e,tokens:ft(e)},o={svgId:t,classPrefix:n},s=[];for(const{from:a,blockStart:l,blockEnd:c}of Kr(r.tokens)){const u=Td(r,a,l,o),f=u===null?null:la(r,l+1,c,u.target);u!==null&&f!==null&&s.push(`${u.text}{${f}}`)}return s.length===0?null:s.join("")}function Ad(e,t){const n={text:e,tokens:ft(e)};return la(n,0,n.tokens.length,t)}function Nd(e,t){if(Vr.test(t))return!1;const n=ft(t);return ia(n,0,n.length,e)}function ca(e,t,n){return Kn(e.tokens,t,n).flatMap(([r,o])=>{const s=Vn(e.tokens,r,o);return s===null?[]:[{property:s.property.value,value:s.valueFirst<s.valueEnd?ut(e,s.valueFirst,s.valueEnd):""}]})}function Cd(e){const t={text:e,tokens:ft(e)};return ca(t,0,t.tokens.length)}function Ld(e){const t={text:e,tokens:ft(e)};return Kr(t.tokens).flatMap(({blockStart:n,blockEnd:r})=>ca(t,n+1,r))}function jd(e,t){const n={text:e,tokens:ft(e)},r=Kn(n.tokens,0,n.tokens.length).flatMap(([o,s])=>{const a=Vn(n.tokens,o,s);return a===null||t.has(hn(a.property.value))?[]:[ut(n,a.first,a.end)]});return r.length===0?null:r.join(";")}const Lr=(e,t)=>e.startsWith("#")&&!e.includes("%")&&t.ids.has(e.slice(1)),zo=(e,t,n)=>e[t]==="#"?`${e.slice(0,t+1)}${n.prefix}${e.slice(t+1)}`:null;function da(e,t,n,r){let o="",s=t;for(;s<n;){const a=e.tokens[s],l=e.text.slice(a.start,a.end);if(a.type==="url"){const c=l.indexOf("(")+1,u=c+l.slice(c).search(/[^\t\n\f\r ]/u),f=Lr(a.value,r)?zo(l,u,r):null;if(f===null)return null;o+=f,s+=1;continue}if(a.type==="function"&&hn(a.value)==="url"){const c=aa(e.tokens,s,n);if(c===null||c.argument.type!=="string"||!Lr(c.argument.value,r))return null;const u=zo(e.text.slice(c.argument.start,c.argument.end),1,r);if(u===null)return null;o+=`${e.text.slice(a.start,c.argument.start)}${u}${e.text.slice(c.argument.end,e.tokens[c.close].end)}`,s=c.close+1;continue}o+=l,s+=1}return o}function ua(e,t,n,r){const o=Kn(e.tokens,t,n).flatMap(([s,a])=>{const l=Vn(e.tokens,s,a);if(l===null)return[];const c=l.valueFirst<l.valueEnd?da(e,l.valueFirst,l.valueEnd,r):"";if(c===null)return[];const u=l.valueEnd<l.end?ut(e,l.valueEnd,l.end):"";return[`${ut(e,l.first,l.valueFirst)}${c}${u}`]});return o.length===0?null:o.join(";")}function Md(e,t,n,r){const o=[];let s="";for(let a=t;a<=n;a+=1){if(a===n||e.tokens[a].type==="comma"){s!==null&&o.push(s),s="";continue}if(s===null)continue;const l=e.tokens[a],c=e.text.slice(l.start,l.end);l.type!=="hash"?s+=c:s=r.ids.has(l.value)?`${s}#${r.prefix}${c.slice(1)}`:null}return o.length===0?null:o.join(",")}function Id(e,t){const n={text:e,tokens:ft(e)},r=[];for(const{from:o,blockStart:s,blockEnd:a}of Kr(n.tokens)){const l=Md(n,o,s,t),c=l===null?null:ua(n,s+1,a,t);l!==null&&c!==null&&r.push(`${l}{${c}}`)}return r.length===0?null:r.join("")}function Dd(e,t){const n={text:e,tokens:ft(e)};return ua(n,0,n.tokens.length,t)}function Pd(e,t){const n={text:e,tokens:ft(e)};return da(n,0,n.tokens.length,t)}const fe=(e,t)=>Object.freeze({type:e,header:t}),fa=Object.freeze([fe("mindmap","mindmap"),fe("architecture","architecture-beta"),fe("c4","C4Context"),fe("kanban","kanban"),fe("classDiagram","classDiagram-v2"),fe("class","classDiagram"),fe("er","erDiagram"),fe("gantt","gantt"),fe("info","info"),fe("pie","pie"),fe("requirement","requirementDiagram"),fe("sequence","sequenceDiagram"),fe("swimlane","swimlane-beta"),fe("flowchart-v2","flowchart"),fe("timeline","timeline"),fe("gitGraph","gitGraph"),fe("stateDiagram","stateDiagram-v2"),fe("quadrantChart","quadrantChart"),fe("sankey","sankey"),fe("packet","packet"),fe("xychart","xychart"),fe("block","block"),fe("eventmodeling","eventmodeling"),fe("treeView","treeView-beta"),fe("ishikawa","ishikawa-beta"),fe("railroad","railroad-beta"),fe("railroadEbnf","railroad-ebnf-beta"),fe("railroadAbnf","railroad-abnf-beta"),fe("railroadPeg","railroad-peg-beta"),fe("venn","venn-beta"),fe("wardley","wardley-beta"),fe("cynefin","cynefin-beta")]),$d=new Set(fa.map(({type:e})=>e)),zd=e=>$d.has(e),st="http://www.w3.org/2000/svg",ma="http://www.w3.org/1999/xhtml",Bd=Object.freeze(["fill","stroke","color","background","background-color","border","border-bottom","box-shadow","filter","mix-blend-mode","opacity","fill-opacity","stroke-opacity","stop-color","stop-opacity","flood-color","flood-opacity","text-decoration","text-shadow"]),Fd=e=>{const{ground:t,text:n,surface:r,line:o,series:s,seriesText:a}=e;return[...new Set([t,n,r.primary,r.secondary,r.tertiary,r.note,o,...s,a])]},jr=new Set(Bd),qd=new Set(["fill","stroke","color","background-color"]),Hd=new Set(["none","transparent"]),Ud="text-decoration",Wd=new Set(["none","underline","overline","line-through","blink","spelling-error","grammar-error","solid","double","dotted","dashed","wavy"]),Gd=/^[0-9a-f]{6}$/u,Bo=["function","number","comma","number","comma","number",")"],Vd=/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/u,Kd=e=>{const t=ft(e).filter(r=>r.type!=="whitespace");if(t.length===1)return t[0].type==="hash"&&Gd.test(t[0].value)?`#${t[0].value}`:null;if(t.length!==Bo.length||t.some((r,o)=>r.type!==Bo[o])||t[0].value!=="rgb")return null;const n=[t[1],t[3],t[5]].map(r=>e.slice(r.start,r.end));return n.every(r=>Vd.test(r))?`#${n.map(r=>Number(r).toString(16).padStart(2,"0")).join("")}`:null},Yd=({property:e,value:t},n)=>{if(!jr.has(e))return!0;if(qd.has(e)){if(Hd.has(t))return!0;const o=Kd(t);return o!==null&&n.has(o)}if(e!==Ud)return!1;const r=ft(t).filter(o=>o.type!=="whitespace");return r.length>0&&r.every(o=>o.type==="ident"&&Wd.has(o.value))};function Xd(e,t){const n=new Set(Fd(t));for(const r of[e,...e.querySelectorAll("*")]){if(r.localName==="style"){const o=Ld(r.textContent).find(({property:s})=>jr.has(s));if(o!==void 0)return`${o.property} ${JSON.stringify(o.value)} in a sheet`}for(const o of Array.from(r.attributes)){const s=o.name.toLowerCase();if(s==="style"){const a=Cd(o.value).find(l=>!Yd(l,n));if(a!==void 0)return`${a.property} ${JSON.stringify(a.value)} in the style of the ${r.localName} element`}else if(jr.has(s))return`${s} ${JSON.stringify(o.value)} in an attribute of the ${r.localName} element`}}return null}const Zd="data-aqmd-mermaid-drawing-place",Jd="listening",Qd="aiquants-markdown:mermaid-frame:connect",ha="aqmd-mmd-",eu=["svg","g","defs","style","title","desc","switch","symbol","use","marker","clippath","lineargradient","stop","filter","fedropshadow","foreignobject","path","line","polygon","rect","circle","ellipse","text","tspan","image","a"],tu=["div","span","p","br","b","strong","i","em","u","s","del","ins","sub","sup","small","mark","code","kbd","ul","ol","li","table","caption","thead","tbody","tfoot","tr","th","td","img"],nu=new Set(["style","title"]),ru=["alignment-baseline","clip-path","clip-rule","colspan","cursor","cx","cy","d","display","dominant-baseline","dx","dy","fill","fill-opacity","fill-rule","filter","flood-color","flood-opacity","font-family","font-size","font-style","font-weight","gradientunits","height","lengthadjust","marker-end","marker-start","markerheight","markerunits","markerwidth","offset","opacity","orient","overflow","points","preserveaspectratio","r","refx","refy","rowspan","rx","ry","stddeviation","stop-color","stop-opacity","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","text-anchor","textlength","transform","transform-origin","viewbox","visibility","width","x","x1","x2","xml:space","y","y1","y2"],pa=new Set(["id","data-look","title","alt"]),Bn=new Set(["role","aria-roledescription","aria-labelledby","aria-describedby"]),ou=new Set(["id","class","style","width","height","viewbox","preserveaspectratio","overflow",...Bn]),ga=new Set(["href","xlink:href","src"]),Fo=/^data:image\//u,su=new Map([[`${st} use`,{attributes:new Set(["href","xlink:href"]),shape:zn,removesElement:!1}],[`${st} linearGradient`,{attributes:new Set(["href","xlink:href"]),shape:zn,removesElement:!1}],[`${st} image`,{attributes:new Set(["href","xlink:href"]),shape:Fo,removesElement:!0}],[`${ma} img`,{attributes:new Set(["src"]),shape:Fo,removesElement:!0}]]),au=/[\t\n\f\r ]+/u,iu={ALLOWED_TAGS:[...eu,...tu],ALLOWED_ATTR:[...ru,...pa,...Bn,...ga,"class","style"],ALLOW_ARIA_ATTR:!1,ALLOW_DATA_ATTR:!1,HTML_INTEGRATION_POINTS:{foreignobject:!0},RETURN_DOM_FRAGMENT:!0},lu=(e,t)=>e!==null&&e.namespaceURI===st&&e.localName==="svg"&&e.getAttribute("id")===t;function cu(e){const t=e.split(au).filter(n=>n!=="");return t.length===0?null:t.map(n=>`${ha}${n}`).join(" ")}function du(e,t,n){const r=su.get(`${e.namespaceURI} ${e.localName}`);return r?.attributes.has(n)&&r.shape.test(t.value)?!0:r?.attributes.has(n)&&r.removesElement?!1:(e.removeAttributeNode(t),!0)}function uu(e,t,n){const r=t.name.toLowerCase(),{value:o}=t;if(ga.has(r))return du(e,t,r);const s=e===n;let a=o;return(s?!ou.has(r):Bn.has(r))?a=null:r==="class"?a=cu(o):r==="style"?a=Ad(o,s?"root":"inside"):pa.has(r)||Bn.has(r)||Nd(r,o)||(a=null),a===null?e.removeAttributeNode(t):a!==o&&(t.value=a),!0}function fu(e){for(let t=e.parentElement;t!==null;t=t.parentElement)if(t.namespaceURI===st&&t.localName==="text")return!0;return!1}function mu(e){if(e.namespaceURI!==st||fu(e)){e.replaceWith(...Array.from(e.childNodes));return}const t=e.ownerDocument.createElementNS(st,"g");for(const n of Array.from(e.attributes))t.setAttributeNS(n.namespaceURI,n.name,n.value);t.append(...Array.from(e.childNodes)),e.replaceWith(t)}function hu(e,t,n){if(e.namespaceURI===ma&&nu.has(e.localName)){e.remove();return}for(const o of Array.from(e.attributes))if(!uu(e,o,t)){e.remove();return}if(e.localName==="a"){mu(e);return}if(e.namespaceURI!==st||e.localName!=="style")return;const r=Od(e.textContent,n,ha);r===null?e.remove():e.textContent=r}function pu(e){const t=_i(e);if(!t.isSupported)throw new TypeError("createMermaidSvgCleaner: DOMPurify cannot run on the given window (it has no document)");return(n,r)=>{if(typeof r!="string"||!Ur.test(r))throw new RangeError(`cleanMermaidSvg: svgId must be an ASCII letter followed by ASCII letters, digits, "-" and "_", got ${typeof r=="string"?JSON.stringify(r):String(r)}`);const o=t.sanitize(n,iu),s=o.firstElementChild;if(o.childNodes.length!==1||!lu(s,r))return null;for(const a of[s,...Array.from(s.querySelectorAll("*"))])hu(a,s,r);return s}}const gu=e=>`default-src 'none'; script-src ${e}; style-src ${e} 'unsafe-inline'; font-src ${e}; img-src data:`,yu=Object.freeze(["html-label","unsized","unlike-text"]),xu=new Set(["https:","http:"]),bu="aqmd-mermaid-",wu=[["position","fixed"],["inset-block-start","0"],["inset-inline-start","0"],["inline-size","0"],["block-size","0"],["border","0"],["visibility","hidden"]],Eu="the drawing place's script did not load, or threw before it listened",Su="the drawing place's frame loaded again, and the diagrams it held were lost",qo="the drawing place's frame left the page, and the diagrams it held were lost",vu="the page has no body to hold the drawing place's frame",ku="the drawing place answered with something other than one svg of the requested id",Tu="the drawing place answered with a paint off the diagram palette",Ru="the drawing place answered in a shape the page does not read",_u="the drawing holds a foreignObject, a label drawn as HTML, which not every reader of an image file draws",Ou="the drawing has no viewBox of a positive width and height to take its size from",Au="the drawing's text, white space aside, differs from that of the shown drawing, as when a label holds HTML or an icon the export form writes out as characters",Nu=new Set(["style","title","desc"]),Cu=/\s/gu,Lu=new Set(["max-width"]),_n=String.raw`([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?)`,ju=String.raw`(?:[\t\n\r ]*,[\t\n\r ]*|[\t\n\r ]+)`,Mu=new RegExp(String.raw`^[\t\n\r ]*${[_n,_n,_n,_n].join(ju)}[\t\n\r ]*$`,"u"),ya=new WeakMap,Yr=e=>typeof e=="object"&&e!==null,ir=e=>Number.isSafeInteger(e)&&e>=0,lr=e=>e.replaceAll("&","&amp;").replaceAll('"',"&quot;").replaceAll("<","&lt;").replaceAll(">","&gt;"),Iu=(e,t,n)=>`<!doctype html><html><head><meta http-equiv="Content-Security-Policy" content="${lr(gu(e))}">${n.map(r=>`<link rel="stylesheet" href="${lr(r)}">`).join("")}<script type="module" src="${lr(t)}"><\/script></head><body></body></html>`,Ho=(e,t)=>{if(!(t instanceof URL)&&(typeof t!="string"||t===""))throw new TypeError(`createMermaidDrawer: ${e} must be a URL or a non-empty string`);if(!URL.canParse(t,window.location.href))throw new TypeError(`createMermaidDrawer: ${e} does not parse as a URL: ${String(t)}`);const n=new URL(t,window.location.href);if(n.origin!==window.location.origin||!xu.has(n.protocol))throw new RangeError(`createMermaidDrawer: ${e} must be an https or http URL of the page's origin ${window.location.origin}, the only one the frame's content security policy takes, got ${n.href}`);return n.href},Du=e=>{if(!Yr(e))throw new TypeError("MermaidDrawer: the request must be an object");if(typeof e.source!="string")throw new TypeError("MermaidDrawer: source must be a string");if(e.theme!=="light"&&e.theme!=="dark")throw new RangeError(`MermaidDrawer: theme must be "light" or "dark", got ${String(e.theme)}`);if(e.form!=="shown"&&e.form!=="export")throw new RangeError(`MermaidDrawer: form must be "shown" or "export", got ${String(e.form)}`);if(!(Number.isFinite(e.width)&&e.width>0))throw new RangeError(`MermaidDrawer: width must be a positive finite number of CSS pixels, got ${String(e.width)}`);if(typeof e.fontFamily!="string"||e.fontFamily.trim()==="")throw new TypeError("MermaidDrawer: fontFamily must be a string that is not blank");if(typeof e.lang!="string")throw new TypeError("MermaidDrawer: lang must be a string, the slot's lang as written (empty when it has none)");for(const t of["maxChars","maxEdges"])if(!(Number.isSafeInteger(e[t])&&e[t]>0))throw new RangeError(`MermaidDrawer: ${t} must be a positive safe integer, got ${String(e[t])}`)},Pu=e=>{if(!Yr(e))return null;switch(e.kind){case"too-large":return ir(e.length)&&ir(e.limit)?{kind:"too-large",length:e.length,limit:e.limit}:null;case"too-many-edges":return ir(e.limit)?{kind:"too-many-edges",limit:e.limit}:null;case"mermaid":case"frame":return typeof e.message=="string"?{kind:e.kind,message:e.message}:null;case"unlisted-type":return typeof e.type=="string"&&e.type!==""&&!zd(e.type)?{kind:"unlisted-type",type:e.type}:null;default:return null}},Jt=e=>({failure:{kind:"frame",message:e}}),$u=e=>{const t=e===null?null:Mu.exec(e);if(t===null)return null;const[n,r,o,s]=t.slice(1).map(Number);return[n,r,o,s].every(Number.isFinite)&&o>0&&s>0?{x:n,y:r,width:o,height:s}:null},zu=(e,t)=>{if(e.getElementsByTagNameNS(st,"foreignObject").length>0)return{kind:"not-exportable",reason:"html-label",message:_u};const n=$u(e.getAttribute("viewBox"));if(n===null)return{kind:"not-exportable",reason:"unsized",message:Ou};e.setAttribute("width",String(n.width)),e.setAttribute("height",String(n.height));const r=e.getAttribute("style"),o=r===null?null:jd(r,Lu);o===null?e.removeAttribute("style"):e.setAttribute("style",o);const s=e.ownerDocument.createElementNS(st,"rect");for(const[a,l]of[["x",n.x],["y",n.y],["width",n.width],["height",n.height]])s.setAttribute(a,String(l));return s.setAttribute("style",`fill: ${t.ground};stroke: none`),e.insertBefore(s,Array.from(e.children).find(a=>a.localName!=="title"&&a.localName!=="desc")??null),null},Uo=e=>{if(e.namespaceURI!==st||e.localName!=="switch")return Array.from(e.childNodes);const t=e.firstElementChild;return t===null?[]:[t]},Wo=e=>{const t=[],n=r=>{for(const o of r)o.nodeType===o.TEXT_NODE||o.nodeType===o.CDATA_SECTION_NODE?t.push(...Array.from((o.nodeValue??"").replace(Cu,""))):o.nodeType===o.ELEMENT_NODE&&!Nu.has(o.localName)&&n(Uo(o))};return n(Uo(e)),t.sort().join("")},Go=e=>{const t=Object.freeze({length:e.outerHTML.length});return ya.set(t,e),t},xa=e=>ya.get(e);function Bu(e){if(typeof window>"u")throw new TypeError("createMermaidDrawer: it needs the page's window; create it in the browser");if(window.location.hostname.startsWith("["))throw new RangeError(`createMermaidDrawer: the page's origin ${window.location.origin} has an IPv6 address, which no content security policy takes as a source, so the frame could not load its script; serve the page under a domain name or an IPv4 address`);const t=pu(window),n=Ho("frameScriptUrl",e.frameScriptUrl);if(!Array.isArray(e.fontStylesheetUrls))throw new TypeError("createMermaidDrawer: fontStylesheetUrls must be an array");const r=Iu(window.location.origin,n,e.fontStylesheetUrls.map((p,x)=>Ho(`fontStylesheetUrls[${x}]`,p))),o=new Map;let s=null,a=0;const l=(p,x,E)=>{o.delete(p),x.resolve(E)},c=(p,x)=>{for(const[E,T]of o)T.frame===p&&l(E,T,Jt(x))},u=(p,x)=>{p.watcher.disconnect(),c(p,x),p.port?.close(),p.element.remove(),s===p&&(s=null)},f=p=>{if(!(Yr(p)&&typeof p.id=="number"))return;const x=o.get(p.id);if(x===void 0)return;if(typeof p.svg=="string"&&!("failure"in p)){const T=t(p.svg,x.svgId);if(T===null){l(p.id,x,Jt(ku));return}const R=Xd(T,x.palette);if(R!==null){l(p.id,x,Jt(`${Tu}: ${R}`));return}const b=x.form==="export"?zu(T,x.palette):null;l(p.id,x,b===null?{svg:T}:{failure:b});return}const E="svg"in p?null:Pu(p.failure);l(p.id,x,E===null?Jt(Ru):{failure:E})},m=p=>{if(s!==p)return;p.port!==null&&(c(p,Su),p.port.close(),p.port=null);const x=p.element.contentWindow;if(x?.document.documentElement.getAttribute(Zd)!==Jd){u(p,Eu);return}const E=new MessageChannel;E.port1.onmessage=T=>f(T.data),x.postMessage({type:Qd},window.location.origin,[E.port2]),p.port=E.port1;for(const T of p.queued.splice(0))E.port1.postMessage(T)},h=p=>{const x=window.document.createElement("iframe");x.setAttribute("aria-hidden","true"),x.setAttribute("inert",""),x.tabIndex=-1;for(const[R,b]of wu)x.style.setProperty(R,b);x.srcdoc=r;const E=new MutationObserver(()=>{x.isConnected||u(T,qo)}),T={element:x,port:null,queued:[],watcher:E};return x.addEventListener("load",()=>m(T)),p.append(x),E.observe(p,{childList:!0}),E.observe(window.document.documentElement,{childList:!0}),T},w=(p,x)=>{if(s!==null&&!s.element.isConnected&&u(s,qo),s===null){const{body:E}=window.document;if(E===null){x(Jt(vu));return}s=h(E)}o.set(p.id,{svgId:p.svgId,palette:na[p.theme],form:p.form,frame:s,resolve:x}),s.port===null?s.queued.push(p):s.port.postMessage(p)},y=(p,x)=>{a+=1;const E={id:a,svgId:`${bu}${a}`,source:p.source,theme:p.theme,form:x,width:p.width,fontFamily:p.fontFamily,lang:p.lang,maxChars:p.maxChars,maxEdges:p.maxEdges};return new Promise(T=>w(E,T))};return async p=>{if(Du(p),p.form==="shown"){const b=await y(p,"shown");return"failure"in b?b:{diagram:Go(b.svg)}}const x=y(p,"export"),E=y(p,"shown"),T=await x;if("failure"in T)return T;const R=await E;return"failure"in R?R:Wo(T.svg)!==Wo(R.svg)?{failure:{kind:"not-exportable",reason:"unlike-text",message:Au}}:{diagram:Go(T.svg)}}}const Fu="aqmd-mmd-",qu="data-aqmd-mermaid-drawing",Vo="drawing",Hu="scalable",Uu=8,Wu=new Set(["href","xlink:href"]),Gu=new Set(["aria-labelledby","aria-describedby"]),Vu=/[\t\n\f\r ]+/u,Ku=()=>{const e=Array.from(crypto.getRandomValues(new Uint8Array(Uu)),t=>t.toString(16).padStart(2,"0")).join("");return`${Fu}${e}-`};function Yu(e,t,n){if(e==="id")return t===""?t:`${n.prefix}${t}`;if(Wu.has(e))return t.startsWith("#")?Lr(t,n)?`#${n.prefix}${t.slice(1)}`:null:t;if(Gu.has(e)){const r=t.split(Vu).filter(o=>n.ids.has(o));return r.length===0?null:r.map(o=>`${n.prefix}${o}`).join(" ")}return e==="style"?Dd(t,n):Cr.has(e)?Pd(t,n):t}function Xu(e,t,n){if(typeof n!="string"||!Ur.test(n))throw new RangeError(`insertionCopyOf: the prefix must be an ASCII letter followed by ASCII letters, digits, "-" and "_", got ${typeof n=="string"?JSON.stringify(n):String(n)}`);const r=t.importNode(e,!0),o=[r,...r.querySelectorAll("*")],s={prefix:n,ids:new Set(o.flatMap(a=>a.getAttribute("id")||[]))};for(const a of o){for(const{name:l,value:c}of[...a.attributes]){const u=Yu(l,c,s);u===null?a.removeAttribute(l):u!==c&&a.setAttribute(l,u)}if(a.namespaceURI===st&&a.localName==="style"){const l=Id(a.textContent,s);l===null?a.remove():a.textContent=l}}return r}function Zu(e,t){const n=e.ownerDocument,r=Xu(t,n,Ku());r.setAttribute("part",r.hasAttribute("viewBox")?`${Vo} ${Hu}`:Vo);const o=n.createElement("div");return o.setAttribute(qu,""),o.attachShadow({mode:"open"}).append(r),e.replaceChildren(o),{host:o,svg:r}}const Ju=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],Qu=re("maximize-2",Ju);const ef=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],tf=re("minimize-2",ef),Et="flex size-11 items-center justify-center rounded border p-1 shadow",nf="flex h-11 min-w-11 items-center justify-center rounded border px-2 text-sm shadow",rf="absolute top-full z-20 mt-1 w-60 overflow-hidden rounded border py-1 text-sm shadow-lg",Ko="flex min-h-11 w-full items-center gap-2 px-3 py-1.5 text-start",yt="fullscreen",of=e=>{const t=e.ownerDocument.defaultView?.getComputedStyle(e).blockSize;t!==void 0&&(e.style.minBlockSize=t)},Yo=e=>{if(e.parentElement!==null)return e.parentElement;const t=e.getRootNode();return"host"in t?t.host:null},sf=e=>{const t=[];for(let n=Yo(e);n!==null;n=Yo(n))t.push({element:n,top:n.scrollTop,left:n.scrollLeft});return t},af=e=>{for(const{element:t,top:n,left:r}of e)(t.scrollTop!==n||t.scrollLeft!==r)&&t.scrollTo({top:n,left:r,behavior:"instant"})},lf=e=>{e.style.removeProperty("min-block-size"),e.getAttribute("style")===""&&e.removeAttribute("style")},Xr=(e,t)=>{const[n,r]=d.useState(!1),o=d.useRef(null),s=d.useRef(null),a=d.useRef([]),l=d.useRef(!1);d.useEffect(()=>{l.current&&(l.current=!1,o.current?.querySelector(`[${e}="${yt}"]`)?.focus())},[n,e]);const c=d.useCallback(h=>{const w=o.current;if(w===null)return;const y=s.current;h&&y!==null&&(a.current=sf(y),of(y)),w.close(),h?w.showModal():(w.show(),y!==null&&lf(y),af(a.current),a.current=[]),l.current=!0,r(h)},[]);d.useLayoutEffect(()=>{n&&!t&&c(!1)},[n,t,c]);const u=d.useCallback(()=>c(!n),[n,c]),f=d.useCallback(h=>{!n||h.key!=="Escape"||h.defaultPrevented||Ns.isInputMethodKey(h.nativeEvent)||(h.preventDefault(),h.stopPropagation(),c(!1))},[n,c]),m=d.useCallback(h=>{h.preventDefault(),c(!1)},[c]);return{fullscreen:n,toggle:u,dialogRef:o,dialogProps:{ref:o,open:!0,role:n?void 0:"group","data-aqmd-fullscreen-dialog":"",onKeyDown:f,onCancel:m},rootProps:{ref:s,"data-aqmd-fullscreen":n?"":void 0}}},Zr=({hook:e,fullscreen:t,labels:n,tabIndex:r,onToggle:o})=>{const s=t?n.exitFullscreen:n.fullscreen;return i.jsx("button",{type:"button",[e]:yt,tabIndex:r,onClick:o,className:Et,"aria-label":s.text,lang:s.lang,children:t?i.jsx(tf,{size:18}):i.jsx(Qu,{size:18})})},Jr=(e,t)=>({text:t.text,lang:t.lang,serial:e===null?1:e.serial+1}),Qr=({hook:e,notice:t})=>i.jsx("p",{...e,role:"status",children:t!==null&&i.jsx("span",{lang:t.lang,children:t.text},t.serial)}),ba=()=>{const e=d.useRef(null);return d.useEffect(()=>()=>e.current?.abort(),[]),d.useCallback(()=>{e.current?.abort();const t=new AbortController;return e.current=t,t.signal},[])},eo=(e,t)=>{const n=e.ownerDocument.defaultView?.navigator.clipboard;return n===void 0?Promise.resolve("failed"):Ht(()=>n.writeText(t)).then(()=>"copied",r=>(console.error("[@aiquants/markdown] could not copy the text",r),"failed"))},wa=(e,t,n)=>{const r=n.defaultView;if(r===null)throw new Error("[@aiquants/markdown] saving a file needs a document with a window");const o=r.URL.createObjectURL(e),s=n.createElement("a");s.href=o,s.download=t,s.hidden=!0,n.body.append(s);try{s.click()}finally{s.remove(),r.setTimeout(()=>r.URL.revokeObjectURL(o),0)}},cf=new Map([["c4","typeC4"],["flowchart","typeFlowchart"],["flowchart-v2","typeFlowchart"],["swimlane","typeSwimlane"],["er","typeEntityRelationship"],["gitGraph","typeGitGraph"],["gantt","typeGantt"],["info","typeInfo"],["pie","typePie"],["quadrantChart","typeQuadrantChart"],["xychart","typeXyChart"],["requirement","typeRequirement"],["sequence","typeSequence"],["class","typeClass"],["classDiagram","typeClass"],["state","typeState"],["stateDiagram","typeState"],["journey","typeJourney"],["flowchart-elk","typeFlowchart"],["timeline","typeTimeline"],["mindmap","typeMindmap"],["kanban","typeKanban"],["sankey","typeSankey"],["packet","typePacket"],["radar","typeRadar"],["block","typeBlock"],["treeView","typeTreeView"],["architecture","typeArchitecture"],["eventmodeling","typeEventModeling"],["ishikawa","typeIshikawa"],["venn","typeVenn"],["treemap","typeTreemap"],["wardley","typeWardley"],["cynefin","typeCynefin"],["railroad","typeRailroad"],["railroadEbnf","typeRailroad"],["railroadAbnf","typeRailroad"],["railroadPeg","typeRailroad"]]),df=Object.freeze({title:null,description:null}),uf=(e,t)=>{for(const n of e.querySelectorAll("[id]"))if(n.id===t)return n;return null},Xo=(e,t)=>{const n=e.getAttribute(t);if(n===null)return null;const r=[];for(const s of n.split(/\s+/u)){const a=s===""?null:uf(e,s);a!==null&&r.push(a.textContent)}const o=r.join(" ").replace(/\s+/gu," ").trim();return o===""?null:o},ff=e=>({title:Xo(e,"aria-labelledby"),description:Xo(e,"aria-describedby")}),mf=(e,t,n)=>{const r=t===null?void 0:cf.get(t),o=r===void 0?"":n[r].text;if(o.trim()===""){e.removeAttribute("aria-roledescription");return}e.setAttribute("aria-roledescription",o)},hf=4096*4096,Zo=32767,pf=Object.freeze({width:0,height:0}),gf=/^\s*(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?[a-zA-Z]*\s*$/u,yf=(e,t)=>{const n=new t.DOMParser().parseFromString(e,"image/svg+xml").documentElement;return n.localName==="svg"&&[n.getAttribute("width"),n.getAttribute("height")].some(r=>r!==null&&gf.test(r))},cr=e=>Number.isFinite(e.width)&&Number.isFinite(e.height)&&e.width>0&&e.height>0,Ea=e=>{if(!(Number.isFinite(e)&&e>0))throw new RangeError(`[@aiquants/markdown] the PNG's scale must be a positive finite number, got ${String(e)}`)},xf=(e,t,n)=>{Ea(n);const r=cr(e)?e:cr(t)?t:null;if(r===null)return null;const o={width:r.width*n,height:r.height*n};if(!cr(o))return null;const s=Math.min(1,Math.sqrt(hf/o.width/o.height),Zo/o.width,Zo/o.height);return{width:Math.max(1,Math.floor(o.width*s)),height:Math.max(1,Math.floor(o.height*s))}},Sa=async(e,t,n,r)=>{Ea(n);const o=r.URL.createObjectURL(new r.Blob([e],{type:"image/svg+xml;charset=utf-8"}));try{const s=new r.Image;s.src=o,await s.decode();const a=xf(yf(e,r)?{width:s.naturalWidth,height:s.naturalHeight}:pf,t,n);if(a===null)throw new Error("[@aiquants/markdown] the SVG image has no size to draw at");const l=r.document.createElement("canvas");l.width=a.width,l.height=a.height;const c=l.getContext("2d");if(c===null)throw new Error("[@aiquants/markdown] the browser gave no 2D canvas to draw the SVG image on");return c.drawImage(s,0,0,a.width,a.height),await new Promise((u,f)=>{l.toBlob(m=>m===null?f(new Error("[@aiquants/markdown] the canvas could not encode the SVG image as a PNG")):u(m),"image/png")})}finally{r.URL.revokeObjectURL(o)}},to="image/svg+xml",bf="image/png",wf=Object.freeze({width:0,height:0}),va=(e,t)=>{if(typeof e!="object"||e===null)throw new TypeError(`${t} must be an object, got ${e===null?"null":typeof e}`);if(typeof e.fileName!="function")throw new TypeError(`${t}.fileName must be a function, got ${typeof e.fileName}`);const{pngScale:n}=e;if(typeof n!="number"||!Number.isFinite(n)||n<=0)throw new RangeError(`${t}.pngScale must be a positive finite number, got ${String(n)}`)},Ef=(e,t)=>{va(e,t);const{index:n}=e;if(typeof n!="number"||!Number.isSafeInteger(n)||n<1)throw new RangeError(`${t}.index must be a positive safe integer, got ${String(n)}`)},Sf=e=>{const t=d.useRef(e);d.useLayoutEffect(()=>{t.current=e});const n=e?.pngScale;return d.useMemo(()=>{if(n!==void 0)return{fileName:r=>{const o=t.current;if(o===void 0)throw new Error("[@aiquants/markdown] the export stand-in was called after its way was removed");return o.fileName(r)},pngScale:n}},[n])};class Mr extends Error{reason;constructor(t,n){super(n),this.name="MermaidNotExportableError",this.reason=t}}const vf=e=>{switch(e.kind){case"too-large":return`too-large (${e.length} characters; the limit is ${e.limit})`;case"too-many-edges":return`too-many-edges (the limit is ${e.limit})`;case"unlisted-type":return`unlisted-type (${e.type} is not one of the types drawn)`;case"mermaid":case"frame":return`${e.kind}: ${e.message}`}},Jo=async(e,t,n,r,o)=>{const s=await Ht(()=>e({...t,theme:"light",form:"export"}));if("failure"in s)throw s.failure.kind==="not-exportable"?yu.includes(s.failure.reason)?new Mr(s.failure.reason,s.failure.message):new Error(`[@aiquants/markdown] the drawing place refused the diagram's export version for a reason the package does not know: ${String(s.failure.reason)}`):new Error(`[@aiquants/markdown] the drawing place did not draw the diagram's export version: ${vf(s.failure)}`);const a=xa(s.diagram);if(a===void 0)throw new Error("[@aiquants/markdown] the drawing place answered no drawn diagram for the export version");const l=new o.XMLSerializer().serializeToString(a);return n==="svg"?new o.Blob([l],{type:to}):Sa(l,wf,r,o)},ka="both-shift",Ir="ctrl";function dr(e,t){return t==="ctrl"?e.ctrlKey:e.shiftKey}const Qo=Object.freeze({none:Object.freeze({panTrigger:null,zoom:!1}),zoom:Object.freeze({panTrigger:null,zoom:!0}),pan:Object.freeze({panTrigger:"drag",zoom:!1}),"pan-shift":Object.freeze({panTrigger:"modifier-drag",zoom:!1}),both:Object.freeze({panTrigger:"drag",zoom:!0}),"both-shift":Object.freeze({panTrigger:"modifier-drag",zoom:!0})}),kf=Object.freeze(["none","zoom","pan","pan-shift","both","both-shift"]),Tf=Object.freeze(["none","zoom","pan","both"]),Rf=Object.freeze({none:"none",zoom:"zoom",pan:"pan","pan-shift":"pan",both:"both","both-shift":"both"}),jn=.3,_f=3,Of=2,Ot=.5,Af=1;function es(e,t){return e.panTrigger!==null&&t?e.zoom?"none":"pinch-zoom":e.zoom?"pan-x pan-y":"auto"}const Nf=0;function ur(e,t,n){return e.panTrigger===null||t.button!==Nf?!1:t.pointerType==="touch"||t.pointerType==="pen"?n:e.panTrigger==="drag"||t.modifierHeld}function Cf(e,t){return e.zoom&&t.modifierHeld}function Lf(e){if(e===null)return null;const t=e.trim().split(/[\s,]+/u),[n,r]=t.length===4?[Number(t[2]),Number(t[3])]:[Number.NaN,Number.NaN];if(!(Number.isFinite(n)&&n>0&&Number.isFinite(r)&&r>0))throw new Error(`[@aiquants/markdown] MermaidDiagram: the drawing has no usable viewBox (${JSON.stringify(e)})`);return{inline:n,block:r}}function jf(e,t){if(!(Number.isFinite(e)&&e>0&&(t===null||Number.isFinite(t)&&t>0)))throw new Error(`[@aiquants/markdown] MermaidDiagram: cannot fit a drawing ${t} px wide into a layout ${e} px wide`);return t===null?1:Math.min(1,e/t)}function Mf(e){if(!(Number.isFinite(e)&&e>0&&e<=1))throw new Error(`[@aiquants/markdown] MermaidDiagram: the fit scale must be in (0, 1], got ${e}`);return{minScale:1,maxScale:Of/e}}function fr(e,t){return Math.min(t.maxScale,Math.max(t.minScale,e))}function Qt(e,t,n,r,o){return{scale:t,x:e.x+(r.x-o.origin.x)/t-(n.x-o.origin.x)/e.scale,y:e.y+(r.y-o.origin.y)/t-(n.y-o.origin.y)/e.scale}}function If(e,t,n){const r=(o,s,a,l)=>{const c=(0-s)/e.scale,u=(l-s-e.scale*a)/e.scale;return Math.min(Math.max(c,u),Math.max(Math.min(c,u),o))};return{scale:e.scale,x:r(e.x,t.origin.x,t.inline,n.inline),y:r(e.y,t.origin.y,t.block,n.block)}}function Df(e,t,n){return e*t.inline-n.inline>Ot||e*t.block-n.block>Ot}function Pf(e,t){const n=s=>Math.hypot(s[1].x-s[0].x,s[1].y-s[0].y),r=s=>({x:(s[0].x+s[1].x)/2,y:(s[0].y+s[1].y)/2}),o=n(e);return o<Af?null:{ratio:n(t)/o,from:r(e),to:r(t)}}function ts(e){return e*(1-Math.exp(-jn))}function ns(e,t,n){const r=e<-Ot||e>Ot;return t-e>n+Ot?r?0-e:0:e<-Ot?0-e:t>n+Ot?n-t:0}const $f=Object.freeze(["tooLarge","tooManyEdges","unlistedType"]),zf=Object.freeze(["openStreaming","openCut","tooManyDiagrams"]),Bf=Object.freeze(["exportMenu","copyDiagram","copySvg","saveSvg","savePng","copiedDiagram","copyDiagramFailed","saveStarted","saveFailed","notExportableHtmlLabel","notExportableUnsized","notExportableUnlikeText"]),rs=Object.freeze({"html-label":"notExportableHtmlLabel",unsized:"notExportableUnsized","unlike-text":"notExportableUnlikeText"}),Yn=Object.freeze({interactionMode:{text:"マウス操作モード",lang:"ja"},interactionModeTouch:{text:"タッチ操作モード",lang:"ja"},modeNone:{text:"操作なし",lang:"ja"},modeZoom:{text:"拡大縮小のみ",lang:"ja"},modePan:{text:"移動のみ (左ドラッグ)",lang:"ja"},modePanShift:{text:"移動のみ (修飾キー+ドラッグ)",lang:"ja"},modeBoth:{text:"拡大縮小+移動 (左ドラッグ)",lang:"ja"},modeBothShift:{text:"拡大縮小+移動 (修飾キー+ドラッグ)",lang:"ja"},modeNoneTouch:{text:"操作なし (指はページをスクロール)",lang:"ja"},modeZoomTouch:{text:"拡大縮小のみ (2 本指)",lang:"ja"},modePanTouch:{text:"移動のみ (はみ出す図を 1 本指でドラッグ)",lang:"ja"},modeBothTouch:{text:"拡大縮小+移動 (2 本指・はみ出す図は 1 本指)",lang:"ja"},zoomIn:{text:"Zoom In",lang:"en"},zoomOut:{text:"Zoom Out",lang:"en"},resetView:{text:"Reset View",lang:"en"},panUp:{text:"Pan Up",lang:"en"},panDown:{text:"Pan Down",lang:"en"},panLeft:{text:"Pan Left",lang:"en"},panRight:{text:"Pan Right",lang:"en"},...me.FULLSCREEN_CONTROL_LABEL_CATALOGS.en,fullscreenDialog:{text:"Diagram (full screen)",lang:"en"},diagram:{text:"Diagram (arrow keys pan, + and - zoom, 0 resets)",lang:"en"},source:{text:"Source",lang:"en"},sourceRegion:{text:"Diagram source",lang:"en"},copySource:{text:"Copy the source",lang:"en"},copiedSource:{text:"Copied the source.",lang:"en"},copySourceFailed:{text:"Could not copy the source.",lang:"en"},exportMenu:{text:"Export",lang:"en"},copyDiagram:{text:"Copy the diagram",lang:"en"},copySvg:{text:"Copy as SVG",lang:"en"},saveSvg:{text:"Save as SVG",lang:"en"},savePng:{text:"Save as PNG",lang:"en"},copiedDiagram:{text:"Copied the diagram.",lang:"en"},copyDiagramFailed:{text:"Could not copy the diagram.",lang:"en"},saveStarted:{text:"Started saving {name}.",lang:"en"},saveFailed:{text:"Could not save the diagram.",lang:"en"},notExportableHtmlLabel:{text:"This diagram cannot be copied or saved as an image: some of its labels are drawn as HTML, which not every image viewer shows.",lang:"en"},notExportableUnsized:{text:"This diagram cannot be copied or saved as an image: it has no size of its own to draw the image at.",lang:"en"},notExportableUnlikeText:{text:"This diagram cannot be copied or saved as an image: the image's text would differ from the diagram shown, as when a label holds formatting or an icon.",lang:"en"},retry:{text:"再試行",lang:"ja"},loading:{text:"Loading diagram...",lang:"en"},errorPrefix:{text:"Error: ",lang:"en"},initializationFailed:{text:"Mermaid failed to initialize globally.",lang:"en"},renderFailed:{text:"An unknown error occurred while rendering the diagram.",lang:"en"},emptyDrawing:{text:"Failed to render Mermaid diagram: SVG content is empty or invalid.",lang:"en"},tooLarge:{text:"The diagram's source is too long ({length} characters; the limit is {limit}).",lang:"en"},tooManyEdges:{text:"The diagram has too many edges (the limit is {limit}).",lang:"en"},unlistedType:{text:"The diagram is not drawn: its type is not one of the types drawn here.",lang:"en"},openStreaming:{text:"The diagram is drawn once its text is complete.",lang:"en"},openCut:{text:"The diagram is not drawn: the text was cut off before its closing line.",lang:"en"},tooManyDiagrams:{text:"The diagram is not drawn: the document draws only its first {limit} diagrams.",lang:"en"},typeC4:{text:"C4 diagram",lang:"en"},typeFlowchart:{text:"Flowchart",lang:"en"},typeSwimlane:{text:"Swimlane diagram",lang:"en"},typeEntityRelationship:{text:"Entity relationship diagram",lang:"en"},typeGitGraph:{text:"Git graph",lang:"en"},typeGantt:{text:"Gantt chart",lang:"en"},typeInfo:{text:"Mermaid information",lang:"en"},typePie:{text:"Pie chart",lang:"en"},typeQuadrantChart:{text:"Quadrant chart",lang:"en"},typeXyChart:{text:"XY chart",lang:"en"},typeRequirement:{text:"Requirement diagram",lang:"en"},typeSequence:{text:"Sequence diagram",lang:"en"},typeClass:{text:"Class diagram",lang:"en"},typeState:{text:"State diagram",lang:"en"},typeJourney:{text:"User journey",lang:"en"},typeTimeline:{text:"Timeline",lang:"en"},typeMindmap:{text:"Mind map",lang:"en"},typeKanban:{text:"Kanban board",lang:"en"},typeSankey:{text:"Sankey diagram",lang:"en"},typePacket:{text:"Packet diagram",lang:"en"},typeRadar:{text:"Radar chart",lang:"en"},typeBlock:{text:"Block diagram",lang:"en"},typeTreeView:{text:"Tree view",lang:"en"},typeArchitecture:{text:"Architecture diagram",lang:"en"},typeEventModeling:{text:"Event modeling diagram",lang:"en"},typeIshikawa:{text:"Ishikawa diagram",lang:"en"},typeVenn:{text:"Venn diagram",lang:"en"},typeTreemap:{text:"Treemap",lang:"en"},typeWardley:{text:"Wardley map",lang:"en"},typeCynefin:{text:"Cynefin diagram",lang:"en"},typeRailroad:{text:"Railroad diagram",lang:"en"}}),Ff=qt(Yn),qf=Object.freeze({none:"modeNone",zoom:"modeZoom",pan:"modePan","pan-shift":"modePanShift",both:"modeBoth","both-shift":"modeBothShift"}),Hf=Object.freeze({none:"modeNoneTouch",zoom:"modeZoomTouch",pan:"modePanTouch",both:"modeBothTouch"}),Uf=e=>{let t=null;return()=>(t!==null||(t=e().then(({default:n})=>{if(typeof n?.initialize!="function")return console.error("[@aiquants/markdown] the Mermaid library or mermaid.initialize is not available"),{cause:null};try{n.initialize({startOnLoad:!1})}catch(r){return{cause:r}}return{library:n}},n=>{throw t=null,n})),t)},Wf=Uf(()=>Promise.resolve().then(()=>require("./mermaid.core-CRP55Hm1.cjs")).then(e=>e.mermaid_core)),Ta="(pointer: coarse)",Gf=e=>{const t=window.matchMedia(Ta);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)},Vf=()=>window.matchMedia(Ta).matches,Kf=()=>!1,Yf=()=>d.useSyncExternalStore(Gf,Vf,Kf),no=(e,t)=>{const[n,r]=d.useState(null),o=n!==null&&e.includes(n)?n:e[0],s=c=>c instanceof Element?c.getAttribute(t):null;return{onKeyDown:c=>{const u=s(c.target);if(u===null||c.altKey||c.ctrlKey||c.metaKey||c.shiftKey)return;const f=e.indexOf(u);if(f===-1)return;const m=c.currentTarget.ownerDocument.defaultView?.getComputedStyle(c.currentTarget).direction==="rtl",h=m?"ArrowLeft":"ArrowRight",w=m?"ArrowRight":"ArrowLeft";let y;switch(c.key){case h:y=(f+1)%e.length;break;case w:y=(f-1+e.length)%e.length;break;case"Home":y=0;break;case"End":y=e.length-1;break;default:return}c.preventDefault(),c.currentTarget.querySelector(`[${t}="${e[y]}"]`)?.focus()},onFocus:c=>{const u=s(c.target);u!==null&&e.includes(u)&&r(u)},tabIndexOf:c=>c===o?0:-1}},sn={side:"start",offset:0,maxWidth:null},Xf=(e,t,n,r)=>{const o=c=>c>=n.low&&c+t<=n.high;if(o(r?e.right-t:e.left))return sn;if(o(r?e.left:e.right-t))return{side:"end",offset:e.right-e.left-t,maxWidth:null};const s=n.high-n.low;if(s<=0)return sn;const a=Math.min(t,s),l=Math.min(Math.max(r?e.right-a:e.left,n.low),n.high-a);return{side:"inside",offset:r?e.right-l-a:l-e.left,maxWidth:a<t?a:null}},Dr=({buttonHook:e,menuHook:t,label:n,icon:r,tabIndex:o,items:s})=>{const[a,l]=d.useState(null),[c,u]=d.useState(sn),f=a!==null,m=d.useId(),h=d.useId(),w=d.useRef(null),y=d.useRef(null),p=d.useRef(null),x=()=>Array.from(p.current?.querySelectorAll('[role="menuitem"], [role="menuitemradio"]')??[]),E=b=>{l(null),u(sn),b&&y.current?.focus()};d.useLayoutEffect(()=>{const b=w.current,k=p.current;if(a===null||b===null||k===null)return;const A=k.ownerDocument.documentElement.clientWidth,P=b.closest('[role="toolbar"]')?.getBoundingClientRect(),L=P===void 0?{low:0,high:A}:{low:Math.max(0,P.left),high:Math.min(A,P.right)},B=k.ownerDocument.defaultView?.getComputedStyle(k).direction==="rtl";u(Xf(b.getBoundingClientRect(),k.getBoundingClientRect().width,L,B));const $=x(),F=$.findIndex(H=>H.getAttribute("aria-checked")==="true"),q=a==="last"?$.length-1:Math.max(F,0);$[q]?.focus()},[a]),d.useEffect(()=>{const b=w.current?.ownerDocument;if(!f||b===void 0)return;const k=A=>{A.target instanceof Node&&w.current?.contains(A.target)===!0||(l(null),u(sn))};return b.addEventListener("pointerdown",k,!0),b.addEventListener("focusin",k,!0),()=>{b.removeEventListener("pointerdown",k,!0),b.removeEventListener("focusin",k,!0)}},[f]);const T=b=>{if(b.key==="ArrowDown"||b.key==="ArrowUp"){b.preventDefault(),b.stopPropagation(),l(b.key==="ArrowUp"?"last":"chosen");return}b.key==="Escape"&&f&&(b.preventDefault(),b.stopPropagation(),E(!1))},R=b=>{const k=x(),A=k.indexOf(b.target);let P;switch(b.key){case"ArrowDown":P=(A+1)%k.length;break;case"ArrowUp":P=(A-1+k.length)%k.length;break;case"Home":P=0;break;case"End":P=k.length-1;break;case"Escape":b.preventDefault(),b.stopPropagation(),E(!0);return;default:return}b.preventDefault(),b.stopPropagation(),k[P]?.focus()};return i.jsxs("div",{ref:w,className:"relative",children:[i.jsx("button",{ref:y,id:m,type:"button",...e,tabIndex:o,onClick:()=>f?E(!1):l("chosen"),onKeyDown:T,className:Et,"aria-label":n.text,lang:n.lang,"aria-haspopup":"menu","aria-expanded":f,"aria-controls":f?h:void 0,children:r}),f&&i.jsx("div",{ref:p,id:h,role:"menu","aria-labelledby":m,...t,"data-aqmd-control-menu":c.side,style:c.maxWidth===null?{insetInlineStart:c.offset}:{insetInlineStart:c.offset,maxInlineSize:c.maxWidth},onKeyDown:R,className:rf,children:s.map(b=>{const k=()=>{E(!0),b.onSelect()};return b.checked===void 0?i.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,lang:b.label.lang,...b.hook,onClick:k,className:Ko,children:i.jsx("span",{children:b.label.text})},b.key):i.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":b.checked,tabIndex:-1,lang:b.label.lang,...b.hook,onClick:k,className:Ko,children:[i.jsx("span",{className:"w-3 shrink-0","aria-hidden":"true",children:b.checked?"✓":""}),i.jsx("span",{children:b.label.text})]},b.key)})})]})},os=new Set(["gantt"]),Zf=200,Jf=300,Qf=Object.freeze({height:0,overflow:"hidden",visibility:"hidden",contain:"strict"}),em="data-aqmd-mermaid-host",tm=e=>{const t=document.createElement("div");return t.setAttribute(em,""),t.setAttribute("aria-hidden","true"),t.style.position="absolute",t.style.insetBlockStart="0",t.style.insetInlineStart=`${-e}px`,t.style.width=`${e}px`,t.style.visibility="hidden",t.style.contain="strict",document.body.append(t),t};let ss=Promise.resolve();const nm=e=>{const t=e instanceof Error?e.message:String(e);return t.includes("dynamically imported module")||t.includes("Importing a module script failed")},as=e=>{e.resetStyle(),e.destroy()},mr=(e,t)=>t?"grabbing":e.panTrigger==="drag"?"move":"",rm=Object.freeze({visibility:"hidden"}),Rt="data-aqmd-mermaid-control",om=Object.freeze({"data-aqmd-mermaid-notice":""}),sm=Object.freeze(["copy-source","source",yt]),am=Object.freeze(["export","copy-diagram"]),hr="data-aqmd-mermaid-export-item",im=e=>typeof e.ClipboardItem=="function"&&typeof e.ClipboardItem.supports=="function"&&e.ClipboardItem.supports(to),lm="--aqmd-mermaid-ratio",On=(e,t)=>e instanceof Error&&e.message!==""?{message:e.message}:{label:t},cm=e=>{switch(e.kind){case"too-large":return{template:"tooLarge",values:{length:e.length,limit:e.limit}};case"too-many-edges":return{template:"tooManyEdges",values:{limit:e.limit}};case"unlisted-type":return{template:"unlistedType",values:{}};case"mermaid":case"frame":case"not-exportable":return e.message===""?{label:"renderFailed"}:{message:e.message}}},dm=(e,t)=>"label"in e?t[e.label]:"template"in e?{text:me.fillLabel(t[e.template].text,e.values),lang:t[e.template].lang}:{text:e.message,lang:void 0},um=e=>{if(typeof e!="object"||e===null)throw new TypeError(`MermaidDiagram: held must be an object, got ${e===null?"null":typeof e}`);const{kind:t}=e;if(t==="streaming"||t==="cut")return;if(t!=="too-many-diagrams")throw new RangeError(`MermaidDiagram: held.kind must be "streaming", "cut" or "too-many-diagrams", got ${String(t)}`);const{limit:n}=e;if(typeof n!="number"||!Number.isSafeInteger(n)||n<1)throw new RangeError(`MermaidDiagram: held.limit must be a positive safe integer, got ${String(n)}`)},fm=(e,t)=>{switch(e.kind){case"streaming":return t.openStreaming;case"cut":return t.openCut;case"too-many-diagrams":return{text:me.fillLabel(t.tooManyDiagrams.text,{limit:e.limit}),lang:t.tooManyDiagrams.lang}}},mm=e=>{let t=e;for(;t!==null;){const n=t.getAttribute("lang");if(n!==null)return n;if(t.parentElement!==null)t=t.parentElement;else{const r=t.getRootNode();t=r instanceof ShadowRoot?r.host:null}}return""},Ra=({chartContent:e,interaction:t,modifier:n,hideInteractionMenu:r=!1,labels:o,labelsLang:s,sourceLines:a,drawing:l,theme:c="light",exporting:u,held:f})=>{const m=d.useMemo(()=>dt(Yn,o,s),[o,s]);if(l!==void 0&&typeof l.drawer!="function")throw new TypeError(`MermaidDiagram: drawing.drawer must be a function (what createMermaidDrawer returns), got ${typeof l.drawer}`);if(u!==void 0&&(Ef(u,"MermaidDiagram: exporting"),l===void 0))throw new RangeError("MermaidDiagram: exporting needs drawing (only a diagram the drawing place draws is exported)");f!==void 0&&um(f);const h=f!==void 0,w=d.useMemo(()=>l?.drawer===void 0?null:{drawer:l.drawer,maxChars:l.maxChars,maxEdges:l.maxEdges,theme:c},[l?.drawer,l?.maxChars,l?.maxEdges,c]),y=d.useId(),p=d.useId(),x=d.useId(),E=d.useId(),T=d.useId(),R=d.useRef(`mermaid-chart-${Math.random().toString(36).substring(2,15)}`),b=d.useRef(0),k=d.useRef(null),A=d.useRef(null),P=d.useRef(null),L=d.useRef(null),[B,$]=d.useState(!0),[F,q]=d.useState(null),[H,ce]=d.useState(null),[oe,ee]=d.useState(null),se=oe!==null&&oe.diagram===H?oe.texts:df,Re=d.useRef(null),[O,z]=d.useState(0),g=d.useRef(!1),v=Yf(),[S,j]=d.useState(t??ka),D=d.useRef(Qo[S]),ae=d.useRef(n??Ir),W=d.useRef(!1),[ie,Ee]=d.useState(!1),[xe,Se]=d.useState(!1),[be,Oe]=d.useState(null),Ke=ba();d.useEffect(()=>{t&&j(t)},[t]),d.useEffect(()=>{D.current=Qo[S],L.current?.refresh()},[S]),d.useEffect(()=>{ae.current=n??Ir},[n]),d.useEffect(()=>{if($(!0),q(null),ce(null),h){$(!1);return}const C=e.trim();if(C===""){$(!1);return}const G=k.current;if(!G)throw new Error("[@aiquants/markdown] MermaidDiagram: the measuring element is not mounted");const X=w===null?{setup:Wf()}:{frame:w};let V=!1,_e=0,we=null,Z=G.offsetWidth,pe=null,qe,vt;const ct=()=>{ze.disconnect(),clearTimeout(qe)},Le=J=>{pe=null,ct(),q(J),ce(null),$(!1)},Ae=(J,_)=>{if(nm(J)&&!g.current){g.current=!0,vt=setTimeout(()=>z(M=>M+1),Jf);return}Le(On(J,_))},Ne=(J,_)=>{const{type:M}=J;pe=M,ce(J),$(!1),M===null||!os.has(M)?ze.disconnect():Z!==_&&Ze()},He=(J,_,M)=>{const I={source:C,theme:J.theme,form:"shown",width:_,fontFamily:getComputedStyle(G).fontFamily,lang:mm(G),maxChars:J.maxChars,maxEdges:J.maxEdges};new Promise(Y=>Y(J.drawer(I))).then(Y=>{if(!M())return;if("failure"in Y){Le(cm(Y.failure));return}const de=xa(Y.diagram);if(de===void 0){Le({label:"renderFailed"});return}Ne({cleaned:de,request:I,type:de.getAttribute("aria-roledescription")},_)}).catch(Y=>{M()&&(console.error(`[MermaidDiagram ${R.current}] Error drawing Mermaid diagram in the drawing place:`,Y),Le(On(Y,"renderFailed")))})},ke=J=>{b.current+=1;const _=b.current;_e=_,we=J;const M=()=>!V&&_===_e;if("frame"in X){He(X.frame,J,M);return}const{setup:I}=X,Y=async()=>{const de=await I.catch(()=>null);if(de===null||"cause"in de||!M())return null;const Be=tm(J);try{return await de.library.render(`${R.current}-${_}`,C,Be)}finally{Be.remove()}};ss=ss.then(()=>M()?Y().then(de=>{if(!(de===null||!M())){if(typeof de.svg!="string"||de.svg.length===0){Le({label:"emptyDrawing"});return}Ne({svg:de.svg,bindFunctions:typeof de.bindFunctions=="function"?de.bindFunctions:null,type:de.diagramType},J)}}).catch(de=>{M()&&(console.error(`[MermaidDiagram ${R.current}] Error rendering Mermaid diagram:`,de),Ae(de,"renderFailed"))}):Promise.resolve())},Ze=()=>{clearTimeout(qe),qe=setTimeout(()=>{Z>0&&Z!==we&&ke(Z)},Zf)},xt=()=>{const J=G.offsetWidth;if(J!==Z){if(Z=J,we===null){J>0&&ke(J);return}pe!==null&&os.has(pe)&&Ze()}},ze=new ResizeObserver(xt);return ze.observe(G),"setup"in X&&X.setup.then(J=>{!V&&"cause"in J&&Le(On(J.cause,"initializationFailed"))},J=>{V||(console.error(`[MermaidDiagram ${R.current}] Error loading Mermaid:`,J),Ae(J,"initializationFailed"))}),Z>0&&ke(Z),()=>{V=!0,ct(),clearTimeout(vt)}},[e,O,w,h]),d.useEffect(()=>{const C=A.current;if(!C)return;const G=()=>{Re.current=null,L.current=null,P.current&&(as(P.current),P.current=null),W.current=!1,Ee(!1)};if(!H){C.innerHTML="",G();return}let X;if("svg"in H){C.innerHTML=H.svg;const Z=C.querySelector("svg");X=Z===null?null:{svg:Z,moved:Z}}else{const{host:Z,svg:pe}=Zu(C,H.cleaned);X={svg:pe,moved:Z}}let V=!1,_e;const we=[];if(X!==null){const{svg:Z,moved:pe}=X;let qe;try{qe=Lf(Z.getAttribute("viewBox"))}catch(Le){console.error(`[MermaidDiagram ${R.current}] Cannot size the drawing:`,Le),q(On(Le,"renderFailed")),ce(null);return}Re.current=Z,ee({diagram:H,texts:ff(Z)});const vt=qe===null?null:qe.inline;qe!==null&&Z.style.setProperty(lm,String(qe.inline/qe.block));const ct=()=>{if(V)return;const Le=Z.getBBox();if(!Le||Le.width===0||Le.height===0){_e=setTimeout(ct,100);return}P.current&&as(P.current);const Ae=Zs(pe,{startScale:1,startX:0,startY:0,minScale:1,maxScale:1,origin:"0 0",step:jn,animate:!1,noBind:!0,cursor:"",overflow:"",touchAction:es(D.current,!1)});P.current=Ae;let Ne={minScale:1,maxScale:1};const He=()=>{const N=Ae.getPan();return{scale:Ae.getScale(),x:N.x,y:N.y}},ke=()=>{const N=C.getBoundingClientRect(),K=Z.getBoundingClientRect(),{scale:te,x:je,y:Me}=He();return{frameRect:N,frame:{inline:N.width,block:N.height},drawing:{origin:{x:K.left-N.left-te*je,y:K.top-N.top-te*Me},inline:K.width/te,block:K.height/te}}},Ze=()=>{if(V)return;const{frame:N,drawing:K}=ke(),te=Df(Ae.getScale(),K,N);W.current=te,Ee(te),Kt(te),Ae.setOptions({touchAction:es(D.current,te)}),C.style.cursor=mr(D.current,I?.kind==="pan"&&I.mouse)},xt=()=>{const{drawing:N}=ke();N.inline<=0||(Ne=Mf(jf(N.inline,vt)),Ae.setOptions({minScale:Ne.minScale,maxScale:Ne.maxScale}))},ze=N=>{const K=He(),{frame:te,drawing:je}=ke(),Me=If({...N,scale:fr(N.scale,Ne)},je,te);return Me.scale===K.scale&&Me.x===K.x&&Me.y===K.y?!1:(Ae.zoom(Me.scale,{animate:!1,force:!0,silent:!0}),Ae.pan(Me.x,Me.y,{animate:!1,force:!0}),Ze(),!0)},J=(N,K)=>{const{drawing:te}=ke();return ze(Qt(He(),fr(N,Ne),K,K,te))},_=N=>{const K=C.getBoundingClientRect();return{x:N.x-K.left,y:N.y-K.top}};L.current={zoomBy:N=>{const{frame:K}=ke();J(Ae.getScale()*Math.exp(N*jn),{x:K.inline/2,y:K.block/2})},panBy:(N,K)=>{const{drawing:te}=ke(),je=He();return ze(Qt(je,je.scale,{x:0,y:0},{x:N,y:K},te))},reset:()=>{ze({scale:1,x:0,y:0})},panSteps:()=>{const{frame:N}=ke();return{x:ts(N.inline),y:ts(N.block)}},refresh:Ze};const M=new Map;let I=null;const Y=N=>({x:N.clientX,y:N.clientY}),de=()=>{const N=[...M.values()];return N.length===2?[N[0],N[1]]:null},Be=N=>{if(M.has(N.pointerId)&&M.set(N.pointerId,Y(N)),I?.kind==="pinch"){const K=de();if(K===null)return;const te=Pf(I.last,K);if(I={kind:"pinch",last:K},te===null)return;const{drawing:je}=ke(),Me=He();ze(Qt(Me,fr(Me.scale*te.ratio,Ne),_(te.from),_(te.to),je));return}if(I?.kind==="pan"&&I.pointerId===N.pointerId){const K=Y(N),{drawing:te}=ke(),je=He();ze(Qt(je,je.scale,_(I.last),_(K),te)),I={...I,last:K}}},Je=()=>{window.removeEventListener("pointermove",Be),window.removeEventListener("pointerup",Tt),window.removeEventListener("pointercancel",Tt)},Wt=()=>{Je(),window.addEventListener("pointermove",Be),window.addEventListener("pointerup",Tt),window.addEventListener("pointercancel",Tt)},Tt=N=>{if(M.delete(N.pointerId),I?.kind==="pinch"){const[K]=[...M.entries()];I=K!==void 0&&ur(D.current,{button:0,modifierHeld:!1,pointerType:N.pointerType},W.current)?{kind:"pan",pointerId:K[0],last:K[1],mouse:!1}:null}else I?.kind==="pan"&&I.pointerId===N.pointerId&&(I=null);I===null&&M.size===0&&Je(),C.style.cursor=mr(D.current,I?.kind==="pan"&&I.mouse)},Gt=N=>{const K=D.current;if(N.pointerType==="touch"||N.pointerType==="pen"){M.set(N.pointerId,Y(N)),Wt();const te=de();te!==null&&K.zoom?I={kind:"pinch",last:te}:M.size>1?I?.kind==="pan"&&!I.mouse&&(I=null):ur(K,{button:N.button,modifierHeld:dr(N,ae.current),pointerType:N.pointerType},W.current)&&(I={kind:"pan",pointerId:N.pointerId,last:Y(N),mouse:!1});return}ur(K,{button:N.button,modifierHeld:dr(N,ae.current),pointerType:N.pointerType},W.current)&&(I={kind:"pan",pointerId:N.pointerId,last:Y(N),mouse:!0},C.style.cursor=mr(K,!0),Wt(),N.preventDefault())},Lt=N=>{I!==null&&!(I.kind==="pan"&&I.mouse)&&N.cancelable&&N.preventDefault()};let Vt=!1;const Kt=N=>{N!==Vt&&(Vt=N,N?C.addEventListener("touchmove",Lt,{passive:!1}):C.removeEventListener("touchmove",Lt))},gn=N=>{const[K]=N.composedPath();if(!(K instanceof Element)||K===Z||!Z.contains(K))return;const te=C.getBoundingClientRect(),je=K.getBoundingClientRect(),Me={x:ns(je.left-te.left,je.right-te.left,te.width),y:ns(je.top-te.top,je.bottom-te.top,te.height)};if(Me.x===0&&Me.y===0)return;const{drawing:xn}=ke(),ge=He();ze(Qt(ge,ge.scale,{x:0,y:0},Me,xn))},bt=N=>{if(!Cf(D.current,{modifierHeld:dr(N,ae.current)}))return;const K=N.deltaY===0?N.deltaX:N.deltaY;K!==0&&(N.preventDefault(),J(Ae.getScale()*Math.exp(Math.sign(-K)*jn/_f),_(Y(N))))},yn=new ResizeObserver(()=>{C.getBoundingClientRect().width<=0||(xt(),ze(He()),Ze())}),Yt=N=>{I?.kind==="pan"&&I.mouse&&N.preventDefault()};C.addEventListener("pointerdown",Gt),C.addEventListener("focusin",gn),C.addEventListener("wheel",bt,{passive:!1}),C.addEventListener("contextmenu",Yt),pe.addEventListener("panzoomchange",Ze),yn.observe(C),we.push(()=>{C.removeEventListener("pointerdown",Gt),C.removeEventListener("focusin",gn),Kt(!1),C.removeEventListener("wheel",bt),C.removeEventListener("contextmenu",Yt),pe.removeEventListener("panzoomchange",Ze),yn.disconnect(),Je()}),xt(),Ze()};ct()}return"svg"in H&&H.bindFunctions&&H.bindFunctions(C),()=>{V=!0,clearTimeout(_e);for(const Z of we)Z();G()}},[H]),d.useEffect(()=>{const C=Re.current;H===null||C===null||mf(C,H.type,m)},[H,m]);const Ie=d.useCallback(C=>{const G=L.current;if(G===null||C.target!==C.currentTarget||C.altKey||C.ctrlKey||C.metaKey)return;const X=G.panSteps();let V;switch(C.key){case"ArrowLeft":V=G.panBy(X.x,0);break;case"ArrowRight":V=G.panBy(-X.x,0);break;case"ArrowUp":V=G.panBy(0,X.y);break;case"ArrowDown":V=G.panBy(0,-X.y);break;case"+":case"=":G.zoomBy(1),V=!0;break;case"-":G.zoomBy(-1),V=!0;break;case"0":G.reset(),V=!0;break;default:V=!1}V&&C.preventDefault()},[]),at=!B&&F===null&&f===void 0,Ge=at&&xe,De=u!==void 0&&w!==null&&at&&!xe&&H!==null&&"cleaned"in H?{drawer:w.drawer,shown:H.request,accTitle:se.title,exporting:u}:null,Pe=De!==null,Ye=d.useMemo(()=>Ge?sm:[...ie?["pan-left","pan-up","pan-down","pan-right"]:[],...r?[]:["mode"],"zoom-in","zoom-out","reset",...Pe?am:[],"source",yt],[r,ie,Ge,Pe]),{onKeyDown:et,onFocus:St,tabIndexOf:it}=no(Ye,Rt),{fullscreen:Ve,toggle:mt,dialogProps:ye,rootProps:he}=Xr(Rt,at),U=e.trim(),ve=(C,G,X,V,_e=!1)=>i.jsx("button",{type:"button",[Rt]:C,tabIndex:it(C),onClick:X,style:_e?rm:void 0,className:Et,"aria-label":m[G].text,lang:m[G].lang,children:V},C),$e=C=>{const G=L.current;if(G===null)return;const X=G.panSteps();G.panBy(C.x*X.x,C.y*X.y)},lt=()=>{Oe(null),Se(C=>!C)},Te=C=>Oe(G=>Jr(G,C)),ht=C=>{const G=Ke();eo(C.currentTarget,U).then(X=>{G.aborted||Te(m[X==="copied"?"copiedSource":"copySourceFailed"])})},Nt=(C,G)=>{const X=Ke(),V=k.current?.ownerDocument.defaultView??null,_e=V?.navigator.clipboard;if(V===null||_e===void 0||typeof V.ClipboardItem!="function"||typeof _e.write!="function"){Te(m.copyDiagramFailed);return}let we=null;const Z=Jo(C.drawer,C.shown,G,C.exporting.pngScale,V);Z.catch(pe=>{we=pe}),Ht(()=>_e.write([new V.ClipboardItem({[G==="png"?bf:to]:Z,"text/plain":new V.Blob([U],{type:"text/plain"})})])).then(()=>{X.aborted||Te(m.copiedDiagram)},pe=>{if(!X.aborted){if(we instanceof Mr){Te(m[rs[we.reason]]);return}console.error(`[MermaidDiagram ${R.current}] Could not copy the diagram:`,we??pe),Te(m.copyDiagramFailed)}})},Ct=(C,G)=>{const X=Ke(),V=k.current?.ownerDocument,_e=V?.defaultView??null;if(V===void 0||_e===null){Te(m.saveFailed);return}let we;try{we=C.exporting.fileName({index:C.exporting.index,accTitle:C.accTitle,format:G})}catch(pe){console.error(`[MermaidDiagram ${R.current}] The naming function of the diagram's file threw:`,pe),Te(m.saveFailed);return}if(typeof we!="string"||we===""){console.error(`[MermaidDiagram ${R.current}] The naming function of the diagram's file answered no name:`,we),Te(m.saveFailed);return}const Z=we;Jo(C.drawer,C.shown,G,C.exporting.pngScale,_e).then(pe=>{X.aborted||(wa(pe,Z,V),Te({text:me.fillLabel(m.saveStarted.text,{name:Z}),lang:m.saveStarted.lang}))}).catch(pe=>{if(!X.aborted){if(pe instanceof Mr){Te(m[rs[pe.reason]]);return}console.error(`[MermaidDiagram ${R.current}] Could not save the diagram:`,pe),Te(m.saveFailed)}})},tt=C=>se.title===null?C:`${x} ${C}`;let nt;if(f!==void 0){const C=fm(f,m);nt=i.jsxs("div",{"data-aqmd-mermaid-held":f.kind,className:"flex flex-col items-start gap-2 rounded border p-4",children:[i.jsx("div",{lang:C.lang,children:C.text}),i.jsx("pre",{"data-aqmd-mermaid-source":"",children:i.jsx("code",{children:U})})]})}else if(B)nt=i.jsx("div",{"data-aqmd-mermaid-loading":"",className:"flex h-32 items-center justify-center bg-white dark:bg-gray-800 dark:text-white",children:i.jsxs("span",{lang:m.loading.lang,children:[i.jsx("span",{"aria-hidden":"true",children:"🌀"})," ",m.loading.text]})});else if(F!==null){const C=dm(F,m);nt=i.jsxs("div",{"data-aqmd-mermaid-error":"",className:"flex flex-col items-start gap-2 rounded border p-4",children:[i.jsxs("div",{children:[i.jsx("span",{lang:m.errorPrefix.lang,children:m.errorPrefix.text}),i.jsx("span",{lang:C.lang,children:C.text})]}),i.jsx("pre",{"data-aqmd-mermaid-source":"",children:i.jsx("code",{children:U})}),i.jsxs("button",{type:"button","data-aqmd-mermaid-retry":"",onClick:()=>{g.current=!1,q(null),z(G=>G+1)},lang:m.retry.lang,className:"inline-flex min-h-11 cursor-pointer items-center gap-1.5 rounded px-3 py-1 font-medium text-sm",children:[i.jsx(_r,{className:"h-4 w-4"}),m.retry.text]})]})}else{const C=m[v?"interactionModeTouch":"interactionMode"],G=v?Tf.map(V=>({value:V,label:m[Hf[V]],checked:Rf[S]===V})):kf.map(V=>({value:V,label:m[qf[V]],checked:S===V})),X=H!==null&&"cleaned"in H?H.request.theme:null;nt=i.jsxs(i.Fragment,{children:[i.jsxs("div",{"data-aqmd-mermaid-toolbar":"",role:"toolbar","aria-labelledby":tt(y),onKeyDown:et,onFocus:St,className:"mb-1 flex flex-wrap items-start justify-end gap-1",children:[!Ge&&i.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[ve("pan-left","panLeft",()=>$e({x:1,y:0}),i.jsx(qc,{size:18}),!ie),ve("pan-up","panUp",()=>$e({x:0,y:1}),i.jsx(Gc,{size:18}),!ie),ve("pan-down","panDown",()=>$e({x:0,y:-1}),i.jsx(Bc,{size:18}),!ie),ve("pan-right","panRight",()=>$e({x:-1,y:0}),i.jsx(Uc,{size:18}),!ie)]}),!Ge&&i.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[!r&&i.jsx(Dr,{buttonHook:{[Rt]:"mode"},menuHook:{"data-aqmd-mermaid-menu":""},label:C,icon:i.jsx(Jc,{size:18}),tabIndex:it("mode"),items:G.map(({value:V,label:_e,checked:we})=>({key:V,label:_e,checked:we,onSelect:()=>j(V)}))}),ve("zoom-in","zoomIn",()=>L.current?.zoomBy(1),i.jsx(ea,{size:20})),ve("zoom-out","zoomOut",()=>L.current?.zoomBy(-1),i.jsx(ta,{size:20})),ve("reset","resetView",()=>L.current?.reset(),i.jsx(_r,{size:18}))]}),i.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[De!==null&&i.jsx(Dr,{buttonHook:{[Rt]:"export"},menuHook:{"data-aqmd-mermaid-export-menu":""},label:m.exportMenu,icon:i.jsx(Qs,{size:18}),tabIndex:it("export"),items:[{key:"save-svg",label:m.saveSvg,onSelect:()=>Ct(De,"svg"),hook:{[hr]:"save-svg"}},{key:"save-png",label:m.savePng,onSelect:()=>Ct(De,"png"),hook:{[hr]:"save-png"}},...im(window)?[{key:"copy-svg",label:m.copySvg,onSelect:()=>Nt(De,"svg"),hook:{[hr]:"copy-svg"}}]:[]]}),De!==null&&ve("copy-diagram","copyDiagram",()=>Nt(De,"png"),i.jsx(cn,{size:18})),Ge&&ve("copy-source","copySource",ht,i.jsx(cn,{size:18})),i.jsx("button",{type:"button",[Rt]:"source",tabIndex:it("source"),"aria-pressed":xe,onClick:lt,className:Et,"aria-label":m.source.text,lang:m.source.lang,children:i.jsx(Js,{size:20})})]}),i.jsx(Zr,{hook:Rt,fullscreen:Ve,labels:m,tabIndex:it(yt),onToggle:mt})]}),i.jsx("div",{ref:A,"data-testid":"mermaid-diagram","data-aqmd-mermaid-frame":"","data-aqmd-mermaid-overflowing":ie?"true":"false",hidden:Ge,role:"group",tabIndex:0,"aria-labelledby":tt(y),"aria-describedby":se.description===null?void 0:E,onKeyDown:Ie,className:X===null?"mermaid mermaid-diagram-container bg-white dark:bg-gray-400":"mermaid mermaid-diagram-container",style:X===null?void 0:{backgroundColor:na[X].ground}}),Ge&&i.jsx("pre",{"data-aqmd-mermaid-source":"",tabIndex:0,role:"region","aria-labelledby":tt(T),children:i.jsx("code",{children:U})}),i.jsx(Qr,{hook:om,notice:be})]})}return i.jsxs("div",{className:"relative","data-aqmd-mermaid":"","data-aqmd-mermaid-view":at?xe?"source":"diagram":void 0,"data-source-lines":a,...he,children:[i.jsx("span",{id:y,hidden:!0,lang:m.diagram.lang,children:m.diagram.text}),i.jsx("span",{id:p,hidden:!0,lang:m.fullscreenDialog.lang,children:m.fullscreenDialog.text}),Ge&&i.jsx("span",{id:T,hidden:!0,lang:m.sourceRegion.lang,children:m.sourceRegion.text}),se.title!==null&&i.jsx("span",{id:x,hidden:!0,children:se.title}),se.description!==null&&i.jsx("span",{id:E,hidden:!0,children:se.description}),i.jsxs("dialog",{...ye,"aria-labelledby":tt(Ve?p:y),children:[i.jsx("div",{ref:k,"data-aqmd-mermaid-measure":!0,"aria-hidden":"true",style:Qf}),nt]})]})};Ra.displayName="MermaidDiagramInternal";const ro=d.memo(Ra),hm="unicodeTextInMathMode",pm="noCharacterMetrics",gm="var(--aqmd-math-error, #cc0000)",ym=/^No character metrics for '.+' in style '.+' and mode '.+'$/su,xm="consoleCommand",bm=e=>{const t=(n,r)=>o=>(r(o),e(xm,`${n} is ignored: a formula does not write to the console`),"");return{"\\message":t("\\message",n=>n.consumeArgs(1)),"\\errmessage":t("\\errmessage",n=>n.consumeArgs(1)),"\\show":t("\\show",n=>n.popToken())}},_a=(e,t)=>{const n=`${t?"display":"inline"}:${e}`,r=_t.get(n);if(r!==void 0)return _t.delete(n),_t.set(n,r),r;const o=Em(e,t);return _t.set(n,o),_t.size>wm&&_t.delete(_t.keys().next().value),o},wm=610,_t=new Map,Em=(e,t)=>{const n=[],r=(s,a)=>{n.push({code:s,message:a,formula:e,displayMode:t})},o=console.warn;console.warn=(...s)=>{const[a]=s;if(s.length===1&&typeof a=="string"&&ym.test(a)){r(pm,a);return}o.apply(console,s)};try{const s=Ai.renderToString(e,{displayMode:t,throwOnError:!1,errorColor:gm,macros:bm(r),strict:(a,l)=>(a!==hm&&r(a,l),"ignore")});return Object.freeze({innerHtml:Object.freeze({__html:s}),diagnostics:Object.freeze(n.map(a=>Object.freeze(a)))})}finally{console.warn=o}};const Sm=[["path",{d:"m12 15 2 2 4-4",key:"2c609p"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],vm=re("copy-check",Sm);const km=[["line",{x1:"12",x2:"18",y1:"12",y2:"18",key:"1rg63v"}],["line",{x1:"12",x2:"18",y1:"18",y2:"12",key:"ebkxgr"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],Tm=re("copy-x",km),Rm=2e3,Oa=d.memo(function({text:t,labels:n}){const[r,o]=d.useState(null),s=d.useRef(0);d.useEffect(()=>{if(r===null)return;const c=setTimeout(()=>o(null),Rm);return()=>clearTimeout(c)},[r]);const a=c=>{s.current+=1;const u=s.current;eo(c.currentTarget,t).then(f=>{s.current===u&&o({notice:f==="copied"?"copied":"copyFailed",press:u})})},l=r===null?cn:r.notice==="copied"?vm:Tm;return i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button","data-aqmd-code-copy":"","data-aqmd-copy-outcome":r===null?"idle":r.notice==="copied"?"copied":"failed",className:"inline-flex size-11 shrink-0 items-center justify-center rounded-md transition-colors","aria-label":n.copy.text,lang:n.copy.lang,onClick:a,children:i.jsx(l,{size:18})}),i.jsx("span",{"data-aqmd-copy-notice":"",role:"status",className:"sr-only",children:r!==null&&i.jsx("span",{lang:n[r.notice].lang,children:n[r.notice].text},r.press)})]})}),Aa=e=>{const t=e.ownerDocument.getSelection();if(t===null)return null;const{anchorNode:n,anchorOffset:r,focusNode:o,focusOffset:s}=t;return n===null||o===null||t.isCollapsed||!(e.contains(n)||e.contains(o))?null:{selection:t,anchorNode:n,anchorOffset:r,focusNode:o,focusOffset:s}},_m=e=>e.nodeType===e.TEXT_NODE,Pr=(e,t,n)=>_m(e)?Math.min(t,e.length):n;class Om extends d.Component{getSnapshotBeforeUpdate(){const t=this.props.root.current;return t===null?null:Aa(t)}componentDidUpdate(t,n,r){if(!r)return;const{selection:o}=r;if(o.anchorNode!==r.anchorNode||o.focusNode!==r.focusNode)return;const s=Pr(r.anchorNode,r.anchorOffset,o.anchorOffset),a=Pr(r.focusNode,r.focusOffset,o.focusOffset);s===o.anchorOffset&&a===o.focusOffset||o.setBaseAndExtent(r.anchorNode,s,r.focusNode,a)}render(){return null}}const is=(e,t,n)=>{if(!e.contains(t))return null;const r=e.ownerDocument.createRange();r.setStart(e,0),r.setEnd(t,n);const o=[];let s=t;for(;s!==e;)s=s.parentNode,o.push(s);return{text:r.toString().length,ancestors:o}},Am=(e,t)=>{const n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT);let r=0;for(let o=n.nextNode();o!==null;o=n.nextNode()){if(t<=r+o.length)return[o,t-r];r+=o.length}return null},ls=(e,t,n,r)=>{if(n===t.node)return[t.node,Pr(t.node,t.offset,r)];if(t.within===null||n===null||!t.within.ancestors.includes(n))return null;const o=Am(e,t.within.text);return o===null?[n,r]:o};class Nm extends d.Component{getSnapshotBeforeUpdate(){const t=this.props.root.current;if(t===null)return null;const n=Aa(t);if(n===null)return null;const{selection:r,anchorNode:o,anchorOffset:s,focusNode:a,focusOffset:l}=n;return{root:t,selection:r,text:t.textContent,anchor:{node:o,offset:s,within:is(t,o,s)},focus:{node:a,offset:l,within:is(t,a,l)}}}componentDidUpdate(t,n,r){if(!r)return;const{root:o,selection:s,text:a}=r;if(o.textContent!==a)return;const l=ls(o,r.anchor,s.anchorNode,s.anchorOffset),c=ls(o,r.focus,s.focusNode,s.focusOffset);l===null||c===null||l[0]===s.anchorNode&&l[1]===s.anchorOffset&&c[0]===s.focusNode&&c[1]===s.focusOffset||s.setBaseAndExtent(l[0],l[1],c[0],c[1])}render(){return null}}const Cm=[["rect",{width:"6",height:"10",x:"9",y:"7",rx:"2",key:"yn7j0q"}],["path",{d:"M4 22V2",key:"tsjzd3"}],["path",{d:"M20 22V2",key:"1bnhr8"}]],Lm=re("align-horizontal-space-around",Cm);const jm=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],Mm=re("chevron-down",jm);const Im=[["path",{d:"M2 12h6",key:"1wqiqv"}],["path",{d:"M22 12h-6",key:"1eg9hc"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 8v2",key:"1woqiv"}],["path",{d:"M12 14v2",key:"8jcxud"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m19 9-3 3 3 3",key:"12ol22"}],["path",{d:"m5 15 3-3-3-3",key:"1kdhjc"}]],Dm=re("fold-horizontal",Im);const Pm=[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3-3-3 3",key:"e37ymu"}],["path",{d:"m15 5-3 3-3-3",key:"19d6lf"}]],$m=re("fold-vertical",Pm);const zm=[["path",{d:"m9 11-6 6v3h9l3-3",key:"1a3l36"}],["path",{d:"m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4",key:"14a9rk"}]],Bm=re("highlighter",zm);const Fm=[["path",{d:"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z",key:"icamh8"}],["path",{d:"m14.5 12.5 2-2",key:"inckbg"}],["path",{d:"m11.5 9.5 2-2",key:"fmmyf7"}],["path",{d:"m8.5 6.5 2-2",key:"vc6u1g"}],["path",{d:"m17.5 15.5 2-2",key:"wo5hmg"}]],qm=re("ruler",Fm);const Hm=[["path",{d:"M16 12h6",key:"15xry1"}],["path",{d:"M8 12H2",key:"1jqql6"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 8v2",key:"1woqiv"}],["path",{d:"M12 14v2",key:"8jcxud"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m19 15 3-3-3-3",key:"wjy7rq"}],["path",{d:"m5 9-3 3 3 3",key:"j64kie"}]],Um=re("unfold-horizontal",Hm);const Wm=[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m15 5-3-3-3 3",key:"itvq4r"}]],Gm=re("unfold-vertical",Wm),Na=24,Vm=1,Km=1,pr=24,Ca=e=>{if(e===void 0)return pr;if(!Number.isInteger(e)||e<pr)throw new RangeError(`[@aiquants/markdown] the size of a document table's tap-scroll circle must be a whole number of at least ${pr} CSS px (WCAG 2.5.8); got ${String(e)}`);return e},Ym=Object.freeze({}),gr=e=>{const{rows:t,cols:n}=qn.measureTsv(e);return t*n},Xm=26,Zm=(e,t,n,r)=>{const o=e.length>t?Math.min(r,t-Math.min(n,t)):0,s=e.slice(0,t-o).map((l,c)=>({index:c,cells:l})),a=e.slice(e.length-o).map((l,c)=>({index:e.length-o+c,cells:l}));return[...s,...a]},Jm=(e,t)=>Math.max(1,Math.min(e.visibleRows,t)),Qm=3,eh=e=>Math.max(1,Math.min(Qm,e)),yr=(e,t,n)=>((n?We.SPREADSHEET_COLUMN_HEADER_HEIGHT_PX:0)+e*Na+We.SPREADSHEET_SCROLLBAR_SIZE_PX)*t,th=1,cs=e=>Math.ceil(e)+th,nh=(e,t)=>e>=t,Fn=e=>Math.round(e*100),ds=e=>{const t=We.SPREADSHEET_ZOOM_STEPS.find(n=>Fn(n)===e);if(t===void 0)throw new RangeError(`[@aiquants/markdown] no spreadsheet zoom step shows as ${String(e)} %`);return t},rh=(e,t,n)=>{if(t===0&&n===0)return e;const r=(e[0]?.length??0)+n,o=n===0?[...e]:e.map(s=>[...s,...Array(n).fill("")]);for(let s=0;s<t;s+=1)o.push(Array(r).fill(""));return o},oo=e=>{let t=e.length;for(;t>1&&e[t-1].every(s=>s==="");)t-=1;const n=e[0]?.length??0;let r=n;const o=s=>{for(let a=0;a<t;a+=1)if(e[a][s]!=="")return!1;return!0};for(;r>1&&o(r-1);)r-=1;return t===0||r===0?[[""]]:t===e.length&&r===n?e:e.slice(0,t).map(s=>r===n?s:s.slice(0,r))},An=e=>oo(qn.parseTsv(e)),oh=["format","hyperlink","note","comments","validation"],sh=(e,t)=>{const n=new Map;let r=!1,o=!1;for(const s of t){if(!(Number.isInteger(s.row)&&Number.isInteger(s.col))||s.row<0||s.row>=e.length||s.col<0||s.col>=e[s.row].length)throw new RangeError(`[@aiquants/markdown] spreadsheet edit outside the table: row ${s.row}, column ${s.col}`);if(oh.some(c=>s[c]!==void 0&&s[c]!==null)&&(r=!0),s.text===void 0)continue;o=!0;const a=s.text.replace(/\r\n?/gu,`
9
+ `),l=n.get(s.row);if(l!==void 0)l[s.col]=a;else if(e[s.row][s.col]!==a){const c=[...e[s.row]];c[s.col]=a,n.set(s.row,c)}}if(n.size>0){const s=[...e];for(const[a,l]of n)s[a]=l;return{kind:"applied",matrix:s}}return r&&!o?{kind:"format-only"}:{kind:"unchanged"}},ah=e=>{const t=oo(e).map(n=>{let r=n.length;for(;r>0&&n[r-1]==="";)r-=1;return r===n.length?n:n.slice(0,r)});return qn.serializeTsv(t).replaceAll(`\r
10
+ `,`
11
+ `)},ih=(e,t)=>{const n=e.indexOf(t);return n===-1?{echo:!1,pending:[]}:{echo:!0,pending:e.slice(n+1)}},lh=(e,t,n,r,o)=>{const s=o==="down"?1:o==="up"?-1:0,a=o==="right"?1:o==="left"?-1:0,l=(m,h)=>m>=0&&m<t&&h>=0&&h<n,c=(m,h)=>e(m,h)!=="";let u=r.row+s,f=r.col+a;if(!l(u,f))return{row:r.row,col:r.col};if(c(r.row,r.col)&&c(u,f)){for(;l(u+s,f+a)&&c(u+s,f+a);)u+=s,f+=a;return{row:u,col:f}}for(;l(u,f);){if(c(u,f))return{row:u,col:f};u+=s,f+=a}return{row:u-s,col:f-a}},ch=/^(?:https?:\/\/|mailto:|tel:)\S+$/iu,dh=e=>ch.test(e)?e:void 0,uh=(e,t)=>{const n=`${t(e.startCol)}${e.startRow+1}`;return e.startRow===e.endRow&&e.startCol===e.endCol?n:`${n}:${t(e.endCol)}${e.endRow+1}`},fh=Object.freeze(["decreaseColumnWidth","increaseColumnWidth","autoFitColumnWidth","decreaseRowHeight","increaseRowHeight"]),mh=()=>{let e=Object.freeze({row:0,col:0});const t=new Set;return{get:()=>e,set:n=>{if(!(n.row===e.row&&n.col===e.col)){e=Object.freeze({row:n.row,col:n.col});for(const r of[...t])r()}},subscribe:n=>(t.add(n),()=>{t.delete(n)})}},Dt="data-aqmd-spreadsheet-control",hh=Object.freeze(["zoom-in","zoom-out","reset-zoom","highlight","track-size","copy","save","save-menu",yt]),ph=({labels:e,labelledBy:t,rows:n,cols:r,canZoomIn:o,canZoomOut:s,zoom:a,onZoom:l,onResetZoom:c,highlighted:u,onToggleHighlight:f,onCopy:m,onSave:h,fullscreen:w,onToggleFullscreen:y,gridReady:p,activeCell:x,onTrackSize:E})=>{const{onKeyDown:T,onFocus:R,tabIndexOf:b}=no(hh,Dt),[k,A]=d.useState(!1),P=d.useId(),L=d.useRef(null),B=k&&p,$=(H,ce,oe,ee,se,Re,O=Et)=>i.jsx("button",{type:"button",[Dt]:H,tabIndex:b(H),onClick:se?oe:void 0,"aria-disabled":se?void 0:"true","aria-pressed":Re,className:O,"aria-label":ce.text,lang:ce.lang,children:ee}),F=Fn(a),q={text:me.fillLabel(e.resetZoom.text,{percent:F}),lang:e.resetZoom.lang};return i.jsxs(i.Fragment,{children:[i.jsxs("div",{"data-aqmd-spreadsheet-toolbar":"",role:"toolbar","aria-labelledby":t,onKeyDown:T,onFocus:R,className:"mb-1 flex flex-wrap items-center justify-end gap-1",children:[i.jsx("span",{"data-aqmd-spreadsheet-size":"",lang:e.size.lang,className:"me-auto text-sm",children:me.fillLabel(e.size.text,{rows:n,cols:r})}),i.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[$("zoom-in",e.zoomIn,()=>l(1),i.jsx(ea,{size:20}),p&&o),$("zoom-out",e.zoomOut,()=>l(-1),i.jsx(ta,{size:20}),p&&s),$("reset-zoom",q,c,i.jsxs("span",{"data-aqmd-spreadsheet-zoom":"",children:[i.jsxs("span",{"data-aqmd-spreadsheet-zoom-widest":"","aria-hidden":"true",children:[Fn(We.SPREADSHEET_ZOOM_MAX)," %"]}),i.jsxs("span",{children:[F," %"]})]}),p&&a!==1,void 0,nf)]}),i.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[$("highlight",e.highlight,f,i.jsx(Bm,{size:18}),p,u),i.jsx("button",{type:"button",ref:L,[Dt]:"track-size",tabIndex:b("track-size"),onClick:p?()=>A(H=>!H):void 0,"aria-disabled":p?void 0:"true","aria-expanded":B,"aria-controls":B?P:void 0,className:Et,"aria-label":e.trackSize.text,lang:e.trackSize.lang,children:i.jsx(qm,{size:18})})]}),i.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[$("copy",e.copyAll,m,i.jsx(cn,{size:18}),p),$("save",e.saveTsv,()=>h(!1),i.jsx(Qs,{size:18}),!0),i.jsx(Dr,{buttonHook:{[Dt]:"save-menu"},menuHook:{"data-aqmd-spreadsheet-menu":""},label:e.saveMenu,icon:i.jsx(Mm,{size:18}),tabIndex:b("save-menu"),items:[{key:"save-with-bom",label:e.saveTsvWithBom,onSelect:()=>h(!0),hook:{"data-aqmd-spreadsheet-menu-item":"save-with-bom"}}]})]}),i.jsx(Zr,{hook:Dt,fullscreen:w,labels:e,tabIndex:b(yt),onToggle:y})]}),B&&i.jsx(yh,{id:P,labels:e,activeCell:x,onTrackSize:E,onClose:()=>{A(!1),L.current?.focus()}})]})},gh=Object.freeze({decreaseColumnWidth:i.jsx(Dm,{size:18}),increaseColumnWidth:i.jsx(Um,{size:18}),autoFitColumnWidth:i.jsx(Lm,{size:18}),decreaseRowHeight:i.jsx($m,{size:18}),increaseRowHeight:i.jsx(Gm,{size:18})}),yh=({id:e,labels:t,activeCell:n,onTrackSize:r,onClose:o})=>{const s=d.useSyncExternalStore(n.subscribe,n.get,n.get),a={column:We.columnIndexToName(s.col),row:s.row+1},l=c=>{c.key!=="Escape"||c.defaultPrevented||(c.preventDefault(),c.stopPropagation(),o())};return i.jsx("div",{id:e,"data-aqmd-spreadsheet-track-size":"",role:"group","aria-label":t.trackSize.text,lang:t.trackSize.lang,onKeyDown:l,className:"mb-1 flex flex-wrap items-center justify-end gap-1",children:fh.map(c=>i.jsx("button",{type:"button","data-aqmd-spreadsheet-track-size-control":c,onClick:()=>r(c),className:Et,"aria-label":me.fillLabel(t[c].text,a),lang:t[c].lang,children:gh[c]},c))})},xh=(e,t,n)=>{const r={v:1,rows:e.length,cols:e[0]?.length??0,clipId:n,formats:[],validations:[],cells:e.map(s=>s.map(a=>({t:a}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]},o=t.serializeClipPayload(r);return{plain:t.serializeClipboardTsv(e),html:t.serializeHtmlTable(r,o)}},bh=async(e,t,n)=>{await t.write([n({"text/plain":new Blob([e.plain],{type:"text/plain"}),"text/html":new Blob([e.html],{type:"text/html"})})])},wh="\uFEFF",Eh="text/tab-separated-values;charset=utf-8",Sh=(e,t)=>`${t?wh:""}${qn.serializeTsv(e)}`,vh=(e,t)=>new Blob([Sh(e,t)],{type:Eh}),La=e=>{const t=d.useRef(e);d.useLayoutEffect(()=>{t.current=e});const n=e!==void 0,[r]=d.useState(()=>new Set);return d.useEffect(()=>e?.subscribe(()=>{for(const o of[...r])o()}),[e,r]),d.useMemo(()=>{if(!n)return;const o=()=>{const s=t.current;if(s===void 0)throw new Error("[@aiquants/markdown] the spreadsheet editor stand-in was called after its editor was removed");return s};return{write:s=>o().write(s),read:s=>o().read(s),undo:()=>o().undo(),redo:()=>o().redo(),subscribe:s=>(r.add(s),()=>{r.delete(s)})}},[n,r])};let Mn=null,xr=null;const $r=new Set,kh=e=>($r.add(e),()=>{$r.delete(e)}),us=()=>Mn!==null?Promise.resolve(Mn):(xr??=import("@aiquants/spreadsheet").then(e=>{Mn=e;for(const t of $r)t();return e},e=>{throw xr=null,e}),xr);class Mt extends Error{reason;constructor(t){super(`[@aiquants/markdown] spreadsheet edit refused: ${t}`),this.name="SpreadsheetEditRefusal",this.reason=t}}const fs=e=>{console.error("[@aiquants/markdown] could not load @aiquants/spreadsheet",e)},ms=Object.freeze({row:!0,column:!0,intersection:!1}),hs=Object.freeze({row:!1,column:!1,intersection:!1}),ps=Object.freeze([Object.freeze([""])]),Th=Object.freeze({link:!1}),Rh=Object.freeze({enabled:!1}),ja=e=>e.trim().replace(/\s+/g," ").toLowerCase(),_h=e=>{const t=[];let n="",r=null;for(let o=0;o<e.length;o++){const s=e[o];s==="\\"&&o+1<e.length?(o++,n+=e[o]):r!==null?s===r?r=null:n+=s:s==='"'||s==="'"?r=s:s===","?(t.push(n),n=""):n+=s}return t.push(n),new Set(t.map(ja))},Oh=e=>{const t=e.trim(),n=t.length>=2&&(t[0]==='"'||t[0]==="'")&&t[t.length-1]===t[0];return ja((n?t.slice(1,-1):t).replace(/\\(.)/g,"$1"))},Ah=(e,t)=>{const n=_h(t);return e.fontfaces.some(r=>n.has(Oh(r.family)))},Nh=Object.freeze({"data-aqmd-spreadsheet-notice":""}),Ch=({matrix:e,headerRows:t,footerRows:n,visibleRows:r,headings:o,autofit:s,frame:a})=>{const l=Math.min(e[0].length,Xm),c=Zm(e,r,t,n),u=Array.from({length:l},(y,p)=>p),f=c[0].index>0,m=c[c.length-1].index<e.length-1,h=e[0].length>l,w=y=>o?i.jsx("td",{"aria-hidden":"true","data-aqmd-spreadsheet-static-number":"",children:y+1}):null;return i.jsxs("table",{"data-aqmd-spreadsheet-static":"","data-aqmd-spreadsheet-static-autofit":s?"":void 0,"data-aqmd-spreadsheet-static-frame":a?"":void 0,"data-aqmd-spreadsheet-static-headings":a&&o?"":void 0,"data-aqmd-spreadsheet-static-earlier-rows":a&&f?"":void 0,"data-aqmd-spreadsheet-static-more-rows":a&&m?"":void 0,"data-aqmd-spreadsheet-static-more-columns":a&&h?"":void 0,children:[s&&i.jsxs("colgroup",{children:[o&&i.jsx("col",{"data-aqmd-spreadsheet-static-band":""}),u.map(y=>i.jsx("col",{"data-aqmd-spreadsheet-static-empty":c.every(({cells:p})=>p[y]==="")?"":void 0},y))]}),i.jsxs("thead",{children:[o&&i.jsxs("tr",{"aria-hidden":"true","data-aqmd-spreadsheet-static-letters":"",children:[i.jsx("td",{}),u.map(y=>i.jsx("td",{children:We.columnIndexToName(y)},y))]}),c.filter(({index:y})=>y<t).map(({index:y,cells:p})=>i.jsxs("tr",{children:[w(y),p.slice(0,l).map((x,E)=>i.jsx("th",{scope:"col",children:x},E))]},y))]}),i.jsx("tbody",{children:c.filter(({index:y})=>y>=t).map(({index:y,cells:p})=>i.jsxs("tr",{children:[w(y),p.slice(0,l).map((x,E)=>i.jsx("td",{children:x},E))]},y))})]})},Lh=e=>{try{return{options:me.parseSpreadsheetOptions(e),unreadWord:null}}catch(t){if(t instanceof me.SpreadsheetOptionsError)return{options:null,unreadWord:t.word};throw t}},Ma=({tsv:e,meta:t,sourceLines:n,editor:r,locale:o="en",labels:s,labelsLang:a,layout:l="inline",tapScrollCircle:c,tapScrollCircleShownBy:u="host",scrollBarControls:f})=>{if(!Object.hasOwn(me.SPREADSHEET_BLOCK_LABEL_CATALOGS,o))throw new RangeError(`[@aiquants/markdown] unsupported spreadsheet locale "${String(o)}" (en and ja are supported)`);if(l!=="inline"&&l!=="fill")throw new RangeError(`[@aiquants/markdown] unsupported spreadsheet layout "${String(l)}" (inline and fill are supported)`);if(u!=="host"&&u!=="options")throw new RangeError(`[@aiquants/markdown] unsupported spreadsheet tap-scroll circle chooser "${String(u)}" (host and options are supported)`);const m=d.useMemo(()=>dt(me.SPREADSHEET_BLOCK_LABEL_CATALOGS[o],s,a),[o,s,a]),{options:h,unreadWord:w}=d.useMemo(()=>Lh(t),[t]),y=d.useMemo(()=>gr(e),[e]),p=y>We.SPREADSHEET_MAX_OPERATION_CELLS,x=d.useMemo(()=>zt.parseSourceLines(n)?.first??null,[n]),[E,T]=d.useState(null),R=`${n??""}
12
+ ${e}`,b=E===R,k=r!==void 0&&x!==null&&!b?r:void 0,A=k!==void 0,P=A&&h!==null&&h.footerRows===0?Vm:0,L=A?Km:0,[B,$]=d.useState(()=>p?ps:An(e)),[F,q]=d.useState(0),H=d.useRef(e),ce=d.useRef([]),oe=d.useMemo(()=>rh(B,P,L),[B,P,L]),ee=d.useRef(oe);ee.current=oe;const se=d.useSyncExternalStore(kh,()=>Mn,()=>null),[Re,O]=d.useState(!1),z=Re&&se===null,g=h===null?null:h.zoomPercent,[v,S]=d.useState(()=>g===null?1:ds(g)),[j,D]=d.useState(g);g!==j&&(D(g),g!==null&&S(ds(g)));const ae=h!==null&&h.toolbar===0?hs:ms,[W,ie]=d.useState(ae),[Ee,xe]=d.useState(ae);ae!==Ee&&(xe(ae),ie(ae));const[Se,be]=d.useState(null),{fullscreen:Oe,toggle:Ke,dialogRef:Ie,dialogProps:at,rootProps:Ge}=Xr(Dt,h!==null&&!p&&h.toolbar===1),De=d.useId(),Pe=d.useCallback((_,M={})=>{be(I=>Jr(I,{text:me.fillLabel(m[_].text,M),lang:m[_].lang}))},[m]);d.useEffect(()=>{if(se!==null||h===null||p)return;let _=!0;return us().catch(M=>{_&&(fs(M),O(!0))}),()=>{_=!1}},[se,h,p]),d.useEffect(()=>{const _=ih(ce.current,e);if(_.echo){ce.current=_.pending;return}const M=k===void 0||x===null?null:k.read(x),I=M!==null&&gr(M)<=We.SPREADSHEET_MAX_OPERATION_CELLS?M:null;if(I!==null&&I===ce.current.at(-1))return;ce.current=[];const Y=I===null?e:I;Y!==H.current&&(H.current=Y,$(I===null&&p?ps:An(Y)),q(de=>de+1))},[e,p,k,x]);const Ye=d.useCallback(()=>{if(k===void 0||x===null)return;const _=k.read(x);_===null||_===H.current||gr(_)>We.SPREADSHEET_MAX_OPERATION_CELLS||(ce.current=[],H.current=_,$(An(_)),q(M=>M+1))},[k,x]);d.useEffect(()=>k?.subscribe(()=>{ce.current.length>0&&Ye()}),[k,Ye]);const et=d.useCallback(_=>{_(),Ye()},[Ye]),St=d.useMemo(()=>k===void 0?void 0:()=>et(()=>k.undo()),[k,et]),it=d.useMemo(()=>k===void 0?void 0:()=>et(()=>k.redo()),[k,et]),Ve=d.useRef(()=>{});Ve.current=_=>{if(k===void 0||x===null)throw new Mt("readOnly");const M=sh(ee.current,_);if(M.kind==="format-only")throw new Mt("formatRefused");if(M.kind==="unchanged")return;const I=oo(M.matrix),Y=ah(I),de=k.write({fenceLine:x,expected:H.current,text:Y});switch(de){case"written":{const Be=k.read(x);if(Be===null)throw new TypeError("[@aiquants/markdown] SpreadsheetEditor.write answered written, but read finds no block on its fence line");H.current=Be,ce.current=[...ce.current,Be],$(Be===Y?I:An(Be)),q(Je=>Je+1),be(null);return}case"changed":throw Ye(),new Mt("editConflict");case"closesFence":throw new Mt("fenceRefused");case"unwritable":throw T(R),new Mt("unwritable");default:throw new TypeError(`[@aiquants/markdown] SpreadsheetEditor.write answered ${JSON.stringify(de)} (written, changed, closesFence or unwritable)`)}};const[mt]=d.useState(()=>({get rowCount(){return ee.current.length},get colCount(){return ee.current[0].length},getCellText:(_,M)=>ee.current[_][M],applyEdits:(_,M)=>Ve.current(_),getCellFormat:()=>Ym,getCellHyperlink:(_,M)=>dh(ee.current[_][M]),findDataEdge:(_,M)=>lh((I,Y)=>ee.current[I][Y],ee.current.length,ee.current[0].length,_,M)})),ye=d.useCallback(_=>{if(!(_ instanceof Mt))throw _;Pe(_.reason)},[Pe]),he=d.useCallback(_=>Pe(b?"unwritable":"readOnly"),[Pe,b]),U=d.useCallback(_=>{Ie.current?.ownerDocument.defaultView?.open(_,"_blank","noopener,noreferrer")},[]),ve=d.useCallback(({row:_,displayText:M,columnName:I,readOnly:Y})=>me.fillLabel((Y===!0?m.readOnlyCellAnnouncement:m.cellAnnouncement).text,{cell:`${I}${_+1}`,value:M===""?m.emptyCell.text:M}),[m]),$e=d.useCallback(({range:_})=>me.fillLabel(m.selectionAnnouncement.text,{range:uh(_,We.columnIndexToName)}),[m]),lt=d.useCallback(({axis:_,index:M,size:I})=>_==="column"?me.fillLabel(m.columnResized.text,{column:We.columnIndexToName(M),size:I}):me.fillLabel(m.rowResized.text,{row:M+1,size:I}),[m]),Te=d.useRef(null),[ht]=d.useState(mh),Nt=d.useCallback(_=>ht.set(_.active),[ht]),Ct=d.useCallback(_=>{Te.current?.executeCommand(_)},[]),tt=Fn(v),nt=d.useRef(tt);d.useLayoutEffect(()=>{j!==null&&(nt.current=j)},[j]),d.useEffect(()=>{nt.current!==tt&&(nt.current=tt,Pe("zoomed",{percent:tt}))},[Pe,tt]);const C=d.useCallback(_=>S(M=>We.clampSpreadsheetZoom(We.stepSpreadsheetZoom(M,_))),[]),G=d.useCallback(()=>S(1),[]),X=W.row||W.column,V=d.useCallback(()=>ie(_=>_.row||_.column?hs:ms),[]),_e=d.useCallback(()=>{if(se===null)return;const _=Ie.current?.ownerDocument.defaultView;(async()=>{if(_==null)throw new Error("no window");const I=xh(B,se,_.crypto.randomUUID());await bh(I,_.navigator.clipboard,Y=>new _.ClipboardItem(Y))})().then(()=>Pe("copied"),I=>{console.error("[@aiquants/markdown] could not copy the spreadsheet",I),Pe("copyFailed")})},[Pe,B,se]),we=d.useCallback(_=>{const M=Ie.current?.ownerDocument;M!==void 0&&wa(vh(B,_),m.fileName.text,M)},[B,m]),Z=B.length,pe=B[0].length,qe=h===null?0:h.frame,vt=d.useMemo(()=>qe===0?void 0:{startRow:0,startCol:0,endRow:Z-1,endCol:pe-1},[qe,Z,pe]),ct=h===null?0:h.tapscroll,Le=d.useMemo(()=>{if(u==="host")return c;const _=Ca(c?.size);return ct===1?{...c,enabled:!0,size:_}:Rh},[c,u,ct]),Ae=h===null?0:Jm(h,oe.length),Ne=oe.length,He=h!==null&&l==="inline"&&nh(h.visibleRows,Ne),[ke,Ze]=d.useState(null),xt=d.useMemo(()=>{if(h===null)return;const _=h.headings===1,M={"--aqmd-spreadsheet-zoom":String(v)};return l==="fill"?M["--aqmd-spreadsheet-box-min-height"]=`${yr(eh(Ne),v,_)}px`:He?M["--aqmd-spreadsheet-box-height"]=`${cs(ke===null?yr(Ne,v,_):ke.height)}px`:M["--aqmd-spreadsheet-box-height"]=`${yr(Ae,v,_)}px`,ke!==null&&(M["--aqmd-spreadsheet-box-width"]=`${cs(ke.width)}px`),h.frame>0&&(M["--aqsp-frame-width"]=`${h.frame}px`),M},[h,l,He,Ne,Ae,v,ke]),ze=Oe?m.fullscreenDialog:m.table,J=se?.Spreadsheet;return d.useLayoutEffect(()=>{const _=Te.current,M=Ie.current;if(h===null||h.autofit!==1||se===null||_===null||M===null)return;const I=Array.from({length:oe[0].length},(Be,Je)=>Je);_.autoFitColumns(I);const Y=M.ownerDocument.fonts;if(Y===void 0)return;const de=Be=>{const Je=Te.current;Je!==null&&Ah(Be,getComputedStyle(M).fontFamily)&&Je.autoFitColumns(I)};return Y.addEventListener("loadingdone",de),()=>Y.removeEventListener("loadingdone",de)},[h,se,oe]),i.jsxs("div",{"data-aqmd-spreadsheet":"","data-aqmd-spreadsheet-layout":l,"data-source-lines":n,"data-aqmd-spreadsheet-editable":A?"":void 0,"data-aqmd-spreadsheet-whole":He?"":void 0,...Ge,children:[i.jsx("span",{id:De,hidden:!0,lang:ze.lang,children:ze.text}),i.jsxs("dialog",{...at,"aria-labelledby":De,children:[h===null?i.jsx("div",{"data-aqmd-spreadsheet-error":"options",role:"alert",lang:m.optionsError.lang,children:me.fillLabel(m.optionsError.text,{word:w,frozenMax:me.SPREADSHEET_OPTION_RULES.header.max,heightMax:me.SPREADSHEET_OPTION_RULES.height.max,zoomSteps:me.SPREADSHEET_ZOOM_STEP_PERCENTS.join(", "),frameMax:me.SPREADSHEET_OPTION_RULES.frame.max})}):p?i.jsx("div",{"data-aqmd-spreadsheet-error":"size",role:"alert",lang:m.tooLarge.lang,children:me.fillLabel(m.tooLarge.text,{cells:new Intl.NumberFormat(o).format(y),max:new Intl.NumberFormat(o).format(We.SPREADSHEET_MAX_OPERATION_CELLS)})}):i.jsxs(i.Fragment,{children:[h.toolbar===1&&i.jsx(ph,{labels:m,labelledBy:De,rows:Z,cols:pe,canZoomIn:v<We.SPREADSHEET_ZOOM_MAX,canZoomOut:v>We.SPREADSHEET_ZOOM_MIN,zoom:v,onZoom:C,onResetZoom:G,highlighted:X,onToggleHighlight:V,onCopy:_e,onSave:we,fullscreen:Oe,onToggleFullscreen:Ke,gridReady:J!==void 0,activeCell:ht,onTrackSize:Ct}),i.jsx("div",{"data-aqmd-spreadsheet-box":"",style:xt,children:J===void 0?i.jsx(Ch,{matrix:B,headerRows:h.headerRows,footerRows:h.footerRows,visibleRows:Ae,headings:h.headings===1,autofit:h.autofit===1,frame:h.frame>0}):i.jsx(J,{ref:Te,adapter:mt,dataVersion:F,defaultRowHeight:Na,frozenRows:h.headerRows,headerRows:h.headerRows,frozenTrailingRows:h.footerRows,frozenColumns:h.frozenColumns,enableFillHandle:A,readOnly:!A,labelledBy:De,enableResizeUI:!0,headings:h.headings===1,frame:vt,tapScrollCircleOptions:Le,scrollBarControls:f,onContentSizeChange:Ze,zoom:v,onZoomChange:S,highlight:W,onHighlightChange:ie,popovers:Th,onHyperlinkOpen:U,onEditRejected:ye,onReadOnlyRejected:he,onUndoRequest:St,onRedoRequest:it,formatCellAnnouncement:ve,formatSelectionAnnouncement:$e,formatResizeAnnouncement:lt,onSelectionChange:Nt,locale:o})})]}),z&&i.jsxs("div",{"data-aqmd-spreadsheet-error":"load",role:"alert",children:[i.jsx("span",{lang:m.loadFailed.lang,children:m.loadFailed.text}),i.jsx("button",{type:"button","data-aqmd-spreadsheet-retry":"",lang:m.retry.lang,className:"ms-2 inline-flex min-h-11 min-w-11 items-center justify-center rounded border px-3 py-1 text-sm",onClick:()=>{O(!1),us().catch(_=>{fs(_),O(!0)})},children:m.retry.text})]}),i.jsx(Qr,{hook:Nh,notice:Se})]})]})};Ma.displayName="SpreadsheetBlock";const so=d.memo(Ma),jh=Object.freeze({light:"solarized-light",dark:"github-dark-high-contrast"}),Mh=Object.freeze({"solarized-light":Object.freeze({"#657b83":"#435860","#93a1a1":"#4b5757","#2aa198":"#005f59","#dc322f":"#ae0010","#d33682":"#a70060","#268bd2":"#00588e","#859900":"#4e5a00","#586e75":"#43585f","#cb4b16":"#9a3100","#b58900":"#6c5100","#6c71c4":"#4a4c9c"}),"github-dark-high-contrast":Object.freeze({"#272b33":"#abb1bb"})});function Ih(e){const t={};for(const n in e){const r=e[n];switch(n){case"class":t.className=r;break;case"style":{const o={};for(const s of r.split(";")){const a=s.indexOf(":");if(a<=0)continue;const l=s.slice(0,a).trim(),c=s.slice(a+1).trim();l===""||c===""||(o[l.startsWith("--")?l:l.replace(/-(\w)/g,(u,f)=>f.toUpperCase())]=c)}t.style=o;break}case"tabindex":t.tabIndex=Number(r);break;default:t[n]=r}}return t}const Dh={margin:"1rem 0"},Ia={margin:"0",padding:"0.8rem 0"},Ph=({filename:e,code:t,labels:n})=>i.jsxs("div",{"data-aqmd-code-header":"",className:"flex min-h-11 items-end justify-end gap-2",children:[e&&i.jsx("div",{"data-aqmd-code-filename":"",className:"wrap-anywhere me-auto min-w-0 rounded-md px-2 py-0.5 text-sm",children:e}),i.jsx(Oa,{text:t,labels:n})]}),Da=(e,t)=>i.jsx("pre",{ref:t,style:Ia,tabIndex:0,"data-aqmd-code-pending":"",children:i.jsx("code",{children:e})}),$h=({code:e})=>Da(e),Pa=(e,t)=>{const n={replace:r=>{if(r instanceof Q.Element&&r.name==="pre"){const o=Ih(r.attribs);return o.style={...typeof o.style=="object"?o.style:{},...Ia},i.jsx("pre",{...o,ref:t,children:Q.domToReact(r.children,n)})}},htmlparser2:{lowerCaseTags:!0}};return Q(e,n)},zh=({htmlPromise:e})=>i.jsx(i.Fragment,{children:Pa(d.use(e))}),Bh=Object.freeze({__html:""}),Fh=()=>i.jsx("pre",{suppressHydrationWarning:!0,dangerouslySetInnerHTML:Bh}),qh=()=>()=>{},Hh=()=>!1,Uh=()=>!0,Wh=()=>d.useSyncExternalStore(qh,Hh,Uh)&&typeof document<"u",Gh=/^(diff)?:?(\w+):?([\w.-]*)?/,Vh=new Map([["svg","xml"]]),Kh="text",Yh=e=>{const t=Vh.get(e),n=t===void 0?e:t;return kr.isSpecialLang(n)||Object.hasOwn(kr.bundledLanguages,n)?n:Kh},Xh=()=>({code(e){for(const t of e.children){if(t.type!=="element")continue;const n=t.children[0];if(n?.type!=="element")continue;const r=n.children[0];if(r?.type!=="text")continue;const o=r.value;let s,a;if(o.startsWith("+")?(s="+",a="add"):o.startsWith("-")&&(s="-",a="remove"),s&&a){t.properties.dataAqmdDiff=a,r.value=o.substring(1).trimStart();const l={type:"element",tagName:"span",properties:{dataAqmdDiffSign:a,className:"inline-flex items-center justify-center w-4 h-4 rounded-full select-none font-bold text-[0.5rem] mr-2"},children:[{type:"text",value:s==="+"?"➕":"➖"}]};t.children.unshift(l)}}}}),Zh=(e,t,n)=>kr.codeToHtml(e,{lang:Yh(t),themes:jh,defaultColor:!1,colorReplacements:Mh,transformers:n?[Xh()]:[]}),Jh=(e,t,n)=>{let r=null,o=null;return{html:()=>(r??=Zh(e,t,n).then(s=>(o={html:s},s),s=>{throw o={error:s},s}),r),outcome:()=>o}},Qh=({highlight:e})=>{const t=Wh(),[n]=d.useState(()=>t?e:null);return n===e?i.jsx(Fh,{}):i.jsx(zh,{htmlPromise:e.html()})},ep=e=>e+1,tp=({code:e,highlight:t})=>{const n=d.useRef(null),[,r]=d.useReducer(ep,0);d.useEffect(()=>{t!==null&&t.outcome()===null&&t.html().then(r,r)},[t]);const o=t===null?null:t.outcome();if(o!==null&&"error"in o)throw o.error;return i.jsxs(i.Fragment,{children:[o===null?Da(e,n):Pa(o.html,n),i.jsx(Nm,{root:n})]})},np=e=>{const t=Gh.exec(e??"");return{isDiff:t?.[1]==="diff",lang:t?.[2]||"text",filename:t?.[3]||void 0}},ao=({lang:e,code:t,node:n,sourceLines:r,labels:o,labelsLang:s,deferHighlight:a=!1})=>{const l=e??n?.lang??void 0,c=t??n?.value??"",{isDiff:u,lang:f,filename:m}=np(l);return f===me.SPREADSHEETS_LANGUAGE?i.jsx(so,{tsv:c,meta:n?.meta??void 0,sourceLines:r,labelsLang:s,tapScrollCircleShownBy:"options"}):f==="mermaid"?i.jsx(ro,{chartContent:c,sourceLines:r,labelsLang:s}):i.jsx(rp,{code:c,lang:f,isDiff:u,filename:m,sourceLines:r,labels:o,labelsLang:s,deferHighlight:a})},rp=d.memo(function({code:t,lang:n,isDiff:r,filename:o,sourceLines:s,labels:a,labelsLang:l,deferHighlight:c}){const u=d.useMemo(()=>Jh(t,n,r),[t,n,r]),f=d.useMemo(()=>dt(Hn,a,l),[a,l]),[m,h]=d.useState(c);return c&&!m&&h(!0),i.jsxs("div",{style:Dh,"data-aqmd-code-block":"","data-source-lines":s,children:[i.jsx(Ph,{filename:o,code:t,labels:f}),m?i.jsx(tp,{code:t,highlight:c?null:u}):i.jsx(d.Suspense,{fallback:i.jsx($h,{code:t}),children:i.jsx(Qh,{highlight:u})})]})}),op=e=>{const[t,n]=d.useState(!1);return d.useEffect(()=>{if(e===null)return;let r=0;const o=()=>{cancelAnimationFrame(r),r=requestAnimationFrame(()=>n(e.scrollWidth>e.clientWidth))};o();const s=new ResizeObserver(o);s.observe(e);const a=new MutationObserver(o);a.observe(e,{childList:!0,subtree:!0,characterData:!0});const l=e.ownerDocument.fonts;return l?.addEventListener("loadingdone",o),()=>{cancelAnimationFrame(r),s.disconnect(),a.disconnect(),l?.removeEventListener("loadingdone",o)}},[e]),t},$a=({source:e,placement:t,labels:n,children:r})=>{const[o,s]=d.useState(null),a=op(o),l=t==="flow"?"span":"div";return i.jsxs(l,{"data-aqmd-math-display":t,children:[i.jsx(l,{ref:s,"data-aqmd-math-scroll":"",tabIndex:a?0:void 0,children:r}),i.jsx(l,{"data-aqmd-math-copy":"",children:i.jsx(Oa,{text:e,labels:n})})]})},za=(e,t)=>{const n=d.useMemo(()=>{try{return{kind:"rendered",innerHtml:_a(e,t).innerHtml}}catch(r){return{kind:"failed",error:r,message:`Math rendering error: ${r instanceof Error?r.message:String(r)}`}}},[e,t]);return d.useEffect(()=>{n.kind==="failed"&&console.error("An error occurred while rendering KaTeX:",n.error)},[n]),n},sp=({node:e})=>{const t=za(e.value,!0),n="rounded-md px-1.5 py-1 font-mono text-gray-800 text-sm dark:text-gray-200";return i.jsx($a,{source:e.value,placement:"block",labels:ji,children:t.kind==="rendered"?i.jsx("article",{className:n,dangerouslySetInnerHTML:t.innerHtml}):i.jsx("article",{className:n,children:t.message})})},Ba=Object.freeze({missingImage:{text:"Image not found",lang:"en"}}),rt=new vr.Logger(vr.LogLevel.INFO,"[DifyIFramePlugin]"),ap="100%",ip="600px",lp="0",cp=e=>typeof e!="object"||e===null||!("type"in e)?null:typeof e.type=="string"?e.type:null,dp=({embed:e,iFrameAllowedDomains:t})=>{const[n,r]=d.useState(!0),[o,s]=d.useState(!1),a=d.useRef(null),l=d.useRef(null),c=d.useRef(null),{src:u}=e,f=d.useCallback(E=>{E.source===null||E.source!==a.current?.contentWindow||!Kl(E.origin,t)||cp(E.data)==="dify-chatbot-iframe-ready"&&(rt.info("Dify chatbot iframe is ready"),r(T=>T&&(s(!1),l.current&&(clearTimeout(l.current),l.current=null),c.current&&(clearTimeout(c.current),c.current=null),!1)))},[t]),m=d.useCallback(()=>{const E=a.current;if(E)try{if(!E.contentDocument)throw new Error("Cannot access iframe content");r(R=>R&&(s(!1),!1))}catch{rt.info("Crossorigin error detected, showing auth prompt"),s(R=>R||(r(!1),!0))}},[]),h=d.useCallback(()=>{const E=window.open(u,"dify-oauth","width=500,height=600,scrollbars=yes,resizable=yes");if(!E){rt.error("ポップアップがブロックされました");return}const T=setInterval(()=>{if(E.closed){clearInterval(T),rt.info("ポップアップが閉じられました");try{rt.info("ポップアップURL:",E.location.href)}catch(b){rt.info("クロスオリジンのためURLにアクセスできません:",b)}const R=a.current;if(R?.src){const b=R.src;r(k=>k||!0),s(k=>k&&!1),R.src="",setTimeout(()=>{R.src=b,l.current=setTimeout(()=>{rt.warn("認証後タイムアウト: dify-chatbot-iframe-ready not received after auth"),m()},5e3)},100)}}},1e3);rt.info("ポップアップを開きました:"),rt.info("- 初期URL:",u),rt.info("- ウィンドウ名:","dify-oauth"),rt.info("- ウィンドウサイズ: 500x600")},[m,u]);d.useEffect(()=>(window.addEventListener("message",f),()=>{window.removeEventListener("message",f)}),[f]),d.useEffect(()=>{const E=setTimeout(()=>{rt.warn("Timeout: dify-chatbot-iframe-ready not received, checking iframe access"),m()},5e3);return c.current=E,()=>{c.current&&(clearTimeout(c.current),c.current=null)}},[m]),d.useEffect(()=>()=>{l.current&&(clearTimeout(l.current),l.current=null)},[]);const{width:w=ap,height:y=ip,frameborder:p=lp,...x}=e.attributes;return i.jsxs("div",{className:"dify-iframe-container",children:[n&&!o&&i.jsxs("div",{className:"flex items-center justify-center rounded-lg bg-gray-50 p-8",children:[i.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-blue-600 border-b-2"}),i.jsx("span",{className:"ml-3 text-gray-600",children:"Dify チャットボットを読み込み中..."})]}),o&&i.jsxs("div",{className:"mb-4 rounded-lg border border-blue-200 bg-blue-50 p-6",children:[i.jsx("div",{className:"flex items-center",children:i.jsxs("div",{className:"text-blue-800",children:[i.jsx("h3",{className:"font-medium",children:"認証が必要です"}),i.jsx("p",{className:"mt-1 text-sm",children:"Dify チャットボットにアクセスするには OAuth 認証が必要です。 ポップアップウィンドウで認証を完了してください。"})]})}),i.jsx("div",{className:"mt-4",children:i.jsx("button",{type:"button",onClick:h,className:"rounded-md border border-gray-700 bg-gray-900 px-4 py-2 font-medium text-sm text-white shadow-lg transition-colors hover:bg-gray-800",children:"OAuth 認証を開始"})})]}),i.jsx("div",{className:`${n||o?"hidden":"block"}`,children:i.jsx("iframe",{ref:a,...Q.attributesToProps({...x,width:w,height:y,frameborder:p},"iframe"),src:u,"data-plugin-type":"dify"})})]})},gs=Object.freeze({dify:dp}),up=e=>Object.hasOwn(gs,e)?gs[e]:null,ys=i.jsx(d.Fragment,{}),fp=(e,t,n,r,o,s)=>{const a=t===null?null:up(t),l=e.attributes.title===void 0?{title:`${r.text}: ${new URL(e.src).hostname}`,lang:r.lang}:{},c=Vl(e,s),u=Xe.frameSandboxKeyOf(c.attributes.sandbox);return i.jsx(Sl,{embed:e,label:r,insideAnchor:o,children:a!==null?i.jsx(a,{embed:c,iFrameAllowedDomains:n},u):i.jsx("iframe",{...Q.attributesToProps(c.attributes,"iframe"),...l,src:c.src},u)})},io=e=>{for(let t=e.parent;t!==null;t=t.parent)if(t instanceof Q.Element&&t.name.toLowerCase()==="a")return!0;return!1},Fa=e=>e.some(t=>t instanceof Q.Element&&(Hr.has(t.name)||Fa(t.children))),mp=(e,t,n,r)=>{const{class:o,"data-link-kind":s,"data-doc-path":a,"data-doc-exists":l,...c}=e.attribs,u=Vs(o,Fa(e.children)),f=c.href??"",m=s,h=m==="external"||qr(f),w=Q.domToReact(e.children,t),y=f!==""&&(r==="untrusted"||!h);if(y&&n)return i.jsx(n,{href:f,kind:h?"external":m,docPath:a,docExists:l===void 0?void 0:l==="true",className:u,attributes:oc(c),children:w});if(y&&r==="untrusted")return i.jsx(d.Fragment,{children:w});h&&(c.target="_blank",c.rel="noreferrer");const p={};return s!==void 0&&(p["data-link-kind"]=s),a!==void 0&&(p["data-doc-path"]=a),l!==void 0&&(p["data-doc-exists"]=l),i.jsx("a",{...Q.attributesToProps(c,"a"),className:u,...p,children:w})},qa=({iFrameAllowedDomains:e,embedLabels:t,frameSandbox:n,linkComponent:r,allowlistContext:o,renderImage:s,renderPlaceholder:a,renderKept:l})=>{const c={replace:u=>{if(!(u instanceof Q.Element))return;const f=u.parent instanceof Q.Element?u.parent.name:null,m=Wn(u.name,u.attribs,{parentName:f,iFrameAllowedDomains:e,...o});switch(m.action){case"remove":return ys;case"unwrap":return i.jsx(d.Fragment,{children:Q.domToReact(u.children,c)});case"embed":return fp(m.embed,m.pluginType,e,t.embeddedFrame,io(u),n);case"image":return u.attribs={...m.attributes},s===void 0?ys:s(u,c)}if(u.attribs={...m.attributes},m.action==="placeholder"){const w=a?.(u,m.link,c);if(w!==void 0)return w}const h=l?.(u,c);if(h!==void 0)return h;if(u.name==="a")return mp(u,c,r,o.allowlist)}};return c},hp=e=>/\.[Ss][Vv][Gg]$/u.test(e),Ha=e=>{const t=d.useRef(e);d.useLayoutEffect(()=>{t.current=e});const n=e!==void 0;return d.useMemo(()=>{if(n)return{read:(r,o)=>{const s=t.current;return s===void 0?Promise.reject(new Error("[@aiquants/markdown] the image source stand-in was called after its reader was removed")):s.read(r,o)}}},[n])},en="data-aqmd-svg-image-control",pp=Object.freeze({"data-aqmd-svg-image-notice":""}),gp=1,yp=Object.freeze(["copy","source",yt]),xp=Object.freeze(["source",yt]),bp=Object.freeze({kind:"failure",retryable:!0}),xs=(e,t,n)=>Ht(()=>e.read(t,n)),wp=({paragraph:e,image:t,path:n,name:r,reader:o,labels:s})=>{const{[zt.SOURCE_LINES_ATTRIBUTE]:a,...l}=e,[c,u]=d.useState(!1),[f,m]=d.useState(0),[h,w]=d.useState(null),[y,p]=d.useState(null),x=d.useId(),E=d.useId(),T=d.useId(),R=d.useRef(null),b=ba(),k=d.useRef(null);d.useEffect(()=>{if(!c)return;const v=new AbortController;return xs(o,n,v.signal).then(S=>{v.signal.aborted||w({read:f,answer:S})},S=>{v.signal.aborted||(console.error("[@aiquants/markdown] the image source reader failed without an abort",S),w({read:f,answer:bp}))}),()=>v.abort()},[c,f,n,o]);const A=c&&h!==null&&h.read===f?h.answer:null,P=A!==null&&A.kind==="text"&&!A.truncated?A.text:null,L=!c||P!==null,{onKeyDown:B,onFocus:$,tabIndexOf:F}=no(L?yp:xp,en),{fullscreen:q,toggle:H,dialogProps:ce,rootProps:oe}=Xr(en,!0),ee=v=>{p(S=>Jr(S,s[v]))},se=()=>{if(p(null),c){u(!1);return}m(v=>v+1),u(!0)},Re=()=>{R.current?.focus(),m(v=>v+1)},O=(v,S)=>{const j=b();eo(v.currentTarget,S).then(D=>{j.aborted||ee(D==="copied"?"copied":"copyFailed")})},z=v=>{const S=b(),j=v.currentTarget.ownerDocument.defaultView,D=j?.navigator.clipboard;if(j===null||D===void 0||typeof j.ClipboardItem!="function"||typeof D.write!="function"){ee("copyImageFailed");return}const ae=k.current,W=ae===null?null:ae.querySelector("img"),ie=W===null?null:W.getBoundingClientRect(),Ee=ie===null?{width:0,height:0}:{width:ie.width,height:ie.height};let xe=!1;const Se=xs(o,n,S).then(be=>{if(be.kind!=="text"||be.truncated)throw xe=!0,new Error("[@aiquants/markdown] the SVG image cannot be copied whole");return Sa(be.text,Ee,gp,j).catch(Oe=>{throw xe=!0,console.error("[@aiquants/markdown] could not draw the SVG image as a PNG",Oe),Oe})},be=>{throw xe=!0,S.aborted||console.error("[@aiquants/markdown] the image source reader failed without an abort",be),be});Se.catch(()=>{}),Ht(()=>D.write([new j.ClipboardItem({"image/png":Se})])).then(()=>{S.aborted||ee("copiedImage")},be=>{S.aborted||(xe||console.error("[@aiquants/markdown] could not copy the SVG image",be),ee("copyImageFailed"))})};let g;return c?A===null?g=i.jsx("p",{"data-aqmd-svg-image-loading":"",lang:s.loading.lang,children:s.loading.text}):A.kind==="failure"?g=i.jsxs("div",{"data-aqmd-svg-image-error":"",className:"flex flex-col items-start gap-2 rounded border p-4",children:[i.jsx("p",{lang:s.failed.lang,children:s.failed.text}),A.retryable&&i.jsxs("button",{type:"button","data-aqmd-svg-image-retry":"",onClick:Re,lang:s.retry.lang,className:"inline-flex min-h-11 cursor-pointer items-center gap-1.5 rounded px-3 py-1 font-medium text-sm",children:[i.jsx(_r,{className:"h-4 w-4"}),s.retry.text]})]}):g=i.jsxs(i.Fragment,{children:[i.jsx("span",{id:T,hidden:!0,lang:s.sourceRegion.lang,children:me.fillLabel(s.sourceRegion.text,{name:r})}),i.jsx("pre",{"data-aqmd-svg-image-source":"",tabIndex:0,role:"region","aria-labelledby":T,children:i.jsx("code",{children:A.text})}),A.truncated&&i.jsx("p",{"data-aqmd-svg-image-truncated":"",lang:s.truncated.lang,children:s.truncated.text})]}):g=i.jsx("p",{ref:k,...Q.attributesToProps(l,"p"),"data-aqmd-svg-image-frame":"",children:t}),i.jsxs("div",{"data-aqmd-svg-image":"","data-aqmd-svg-image-view":c?"source":"image","data-source-lines":a,...oe,children:[i.jsx("span",{id:x,hidden:!0,lang:s.toolbar.lang,children:s.toolbar.text}),i.jsx("span",{id:E,hidden:!0,lang:s.fullscreenDialog.lang,children:me.fillLabel(s.fullscreenDialog.text,{name:r})}),i.jsxs("dialog",{...ce,"aria-labelledby":q?E:x,children:[i.jsxs("div",{"data-aqmd-svg-image-toolbar":"",role:"toolbar","aria-labelledby":x,onKeyDown:B,onFocus:$,className:"mb-1 flex flex-wrap items-center justify-end gap-1",children:[L&&i.jsx("button",{type:"button",[en]:"copy",tabIndex:F("copy"),onClick:v=>P===null?z(v):O(v,P),className:Et,"aria-label":P===null?s.copyImage.text:s.copy.text,lang:P===null?s.copyImage.lang:s.copy.lang,children:i.jsx(cn,{size:18})}),i.jsx("button",{ref:R,type:"button",[en]:"source",tabIndex:F("source"),"aria-pressed":c,onClick:se,className:Et,"aria-label":s.source.text,lang:s.source.lang,children:i.jsx(Js,{size:20})}),i.jsx(Zr,{hook:en,fullscreen:q,labels:s,tabIndex:F(yt),onToggle:H})]}),g,i.jsx(Qr,{hook:pp,notice:y})]})]})},Xn=Object.freeze({toolbar:{text:"SVG image",lang:"en"},source:{text:"Source",lang:"en"},sourceRegion:{text:"Source of {name}",lang:"en"},loading:{text:"Loading the source…",lang:"en"},failed:{text:"The source could not be read.",lang:"en"},retry:{text:"Try again",lang:"en"},truncated:{text:"Only the beginning of this file is shown.",lang:"en"},copy:{text:"Copy the source",lang:"en"},copied:{text:"Copied the source.",lang:"en"},copyFailed:{text:"Could not copy the source.",lang:"en"},copyImage:{text:"Copy the image",lang:"en"},copiedImage:{text:"Copied the image.",lang:"en"},copyImageFailed:{text:"Could not copy the image.",lang:"en"},...me.FULLSCREEN_CONTROL_LABEL_CATALOGS.en,fullscreenDialog:{text:"{name} (full screen)",lang:"en"}}),Ep=qt(Xn),Sp=({alt:e,target:t,label:n})=>i.jsxs("span",{"data-testid":"markdown-missing-image","data-aqmd-missing-image":"","data-asset-src":t||void 0,role:"img","aria-label":`${e?`${n.text} (${e})`:n.text}${t?`: ${t}`:""}`,lang:n.lang,className:"my-1 inline-flex max-w-full items-center gap-2 rounded-lg border border-gray-300 border-dashed bg-gray-50 px-3 py-2 text-gray-600 text-sm dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400",children:[i.jsx(sl,{className:"h-4 w-4 shrink-0","aria-hidden":"true"}),i.jsxs("span",{className:"min-w-0",children:[i.jsx("span",{className:"font-medium",children:e?`${n.text} (${e})`:n.text}),t&&i.jsx("span",{className:"ml-2 break-all font-mono text-xs dark:text-gray-300",children:t})]})]}),vp=(e,t,n)=>{const{alt:r,"data-asset-src":o}=e.attribs;if(lo(e.attribs)===void 0||co(e.attribs))return i.jsx(Sp,{alt:r,target:o,label:t});const s=n.rendered===0;return n.rendered+=1,i.jsx("img",{alt:"",...Q.attributesToProps({loading:s?"eager":"lazy",decoding:"async",...e.attribs})})},lo=e=>{const{src:t}=e;return t===void 0||t.trim()===""?void 0:t},co=e=>e["data-asset-exists"]==="false",kp=e=>{const{alt:t,title:n,"data-asset-src":r,"data-asset-exists":o}=e.attribs,s=lo(e.attribs);return{src:s,external:s!==void 0&&qr(s),alt:t,title:n,assetPath:r,assetExists:o===void 0?void 0:!co(e.attribs),insideLink:io(e)}},Tp=(e,t,n,r)=>{const o=Hl(t,n),s=Q.attributesToProps(e.attribs),a=Q.domToReact(e.children,r),l={[zl]:String(t)};if(o<=$l)return d.createElement(`h${o}`,{...s,...l},a);const c=Object.hasOwn(s,"role")?{}:{role:"heading","aria-level":o};return d.createElement("div",{...c,...s,...l},a)},Rp=d.memo(function({source:t,innerHtml:n,labels:r}){return i.jsx($a,{source:t,placement:"flow",labels:r,children:i.jsx("span",{dangerouslySetInnerHTML:n})})}),gt=e=>e.map(t=>t instanceof Q.Text?t.data:t instanceof Q.Element?gt(t.children):"").join(""),_p=(e,t,n)=>e.map(r=>{if(r instanceof Q.Text)return{kind:"text",text:r.data};if(!(r instanceof Q.Element))return{kind:"ignored"};if(r.name.toLowerCase()!=="a")return{kind:"element"};const o=Wn(r.name,r.attribs,{parentName:"p",iFrameAllowedDomains:t,...n});return{kind:"link",href:o.action==="keep"?o.attributes.href??null:null}}),Op=(e,t,n,r)=>{const o=e.children,s=Xe.placeholderLinkOf(t,_p(o,r.iFrameAllowedDomains,r.allowlistContext));if(s===null)return;const a=Q.domToReact(o,n),l=i.jsx("p",{...Q.attributesToProps(e.attribs,"p"),children:a}),c=o.find(h=>h instanceof Q.Element),u=r.embeds.linkCardEndpoint,f=u!==null&&c!==void 0&&Xe.isBareLink(gt(c.children),s)?i.jsx(Ol,{href:t,endpoint:u,size:ot.linkCardSizeOf(r.embeds),fallback:l}):l,m=kt.resolveEmbed(s,r.embeds.providers);return m===null?f:i.jsx(Pl,{resolution:m,caption:a,fallback:f,theme:r.theme,labels:r.embedLabels,frameSandbox:ot.frameSandboxOf(r.embeds)})},Ap=(e,t,n)=>{if(io(e))return null;const r=e.children.filter(c=>!Ft(c)),[o]=r;if(r.length!==1||!(o instanceof Q.Element)||o.name.toLowerCase()!=="img")return null;const s=Wn(o.name,o.attribs,{parentName:"p",iFrameAllowedDomains:t,...n});if(s.action!=="keep")return null;const{alt:a,"data-asset-src":l}=s.attributes;return l===void 0||!hp(l)||lo(s.attributes)===void 0||co(s.attributes)?null:{node:o,path:l,name:a!==void 0&&a.trim()!==""?a:l.slice(l.lastIndexOf("/")+1)}},bs=2166136261,ws=16777619,Np=/^[\t\n\f\r ]*$/u,Ft=e=>e instanceof Q.Text&&Np.test(e.data),Cp=`language-${me.SPREADSHEETS_LANGUAGE}`,Ua=e=>e.name==="code"&&(e.attribs.class??"").split(/[\t\n\f\r ]+/u).includes(Cp),Wa=e=>{let t=bs,n=bs;const r=(l,c)=>{for(let u=0;u<l.length;u+=1){const f=l.charCodeAt(u);n=Math.imul(n^f,ws),c&&(t=Math.imul(t^f,ws))}},o=(l,c)=>{if(l instanceof Q.Text)r("",c),r(l.data,c);else if(l instanceof Q.Element){r("",c),r(l.name,c);for(const[f,m]of Object.entries(l.attribs))f!==zt.SOURCE_LINES_ATTRIBUTE&&(r("",c),r(f,c),r("",c),r(m,c));r("",c);const u=c&&!Ua(l);for(const f of l.children)o(f,u);r("",c)}else r("\x07",c),r(l.data,c)},s=e.filter(l=>!Ft(l));for(const l of s)o(l,!0);const a=s.at(0);return{fingerprint:(t>>>0).toString(36),content:(n>>>0).toString(36),root:a===void 0?"":a instanceof Q.Element?a.name:`#${a.type}`}},br=e=>{const t=e.findIndex(r=>!Ft(r));if(t===-1)return{before:e.map(r=>gt([r])),content:[],after:[]};let n=e.length-1;for(;Ft(e[n]);)n-=1;return{before:e.slice(0,t).map(r=>gt([r])),content:e.slice(t,n+1),after:e.slice(n+1).map(r=>gt([r]))}},Lp=(e,t)=>{if(e&&t)throw new RangeError("MarkdownRenderer: streaming and truncated cannot both be true (a text a stream still writes has not been cut off)");return e?"streaming":t?"truncated":"complete"},jp=e=>{if(!Number.isSafeInteger(e)||e<1)throw new RangeError(`MarkdownRenderer: maxMermaidDiagrams must be a positive safe integer, got ${String(e)}`)},Mp=Object.freeze({kind:"streaming"}),Ip=Object.freeze({kind:"cut"}),Dp=(e,t,n,r)=>{if(r!==void 0&&e>=r)return Object.freeze({kind:"too-many-diagrams",limit:r});if(t)switch(n){case"streaming":return Mp;case"truncated":return Ip;case"complete":return}},un=new Map,Pp=(e,{options:t,tally:n,previous:r,rules:o,failureLabel:s})=>{const a=[];if(n.mathReports=a,e==="")return{nodes:[],keys:[],kept:un,diagnostics:a};const l=on(e),c=$s(l.filter(f=>!Ft(f)).map(f=>Wa([f])),r,o);let u=0;return{nodes:l.map(f=>{if(Ft(f))return gt([f]);const{key:m,content:h}=c[u];return u+=1,i.jsx(Ds,{content:h,label:s,text:()=>gt([f]),children:Q.domToReact([f],t)},m)}),keys:c,kept:un,diagnostics:a}},$p=(e,t,n,{options:r,tally:o,progress:s,previous:a,rules:l,failureLabel:c})=>{if(t.length===0)return{nodes:br(on(e)).before,keys:[],kept:un,diagnostics:[]};const u=ul(e,t).map(h=>{const w=o.images.rendered,y=o.diagrams.rendered,p=n.get(h)?.find(L=>(L.images===0||L.imagesBefore===w)&&(L.diagrams===0||L.diagramsBefore===y)&&(L.openCodeProgress===null||L.openCodeProgress===s));if(p!==void 0)return o.images.rendered+=p.images,o.diagrams.rendered+=p.diagrams,[h,p];const{before:x,content:E,after:T}=br(on(h)),R=[];o.mathReports=R;const b=Wa(E),k=o.openCode.rendered,A=Q.domToReact(E,r),P=o.openCode.rendered>k?s:null;return[h,{element:A,before:x,after:T,shape:b,images:o.images.rendered-w,imagesBefore:w,diagrams:o.diagrams.rendered-y,diagramsBefore:y,diagnostics:R,openCodeProgress:P}]}),f=$s(u.map(([,h])=>h.shape),a,l),m=new Map;for(const[h,w]of u){const y=m.get(h);y===void 0?m.set(h,[w]):y.includes(w)||y.push(w)}return{nodes:u.flatMap(([h,w],y)=>{const{key:p,content:x}=f[y];return[...w.before,i.jsx(Ds,{content:x,label:c,text:()=>gt(br(on(h)).content),children:w.element},p),...w.after]}),keys:f,kept:m,diagnostics:u.flatMap(([,h])=>h.diagnostics)}},zp=Object.freeze([]),Bp={keys:[],epoch:void 0,parserOptionsFor:null,kept:un},Ga=({htmlContent:e,blockOffsets:t,blockKeyEpoch:n,streaming:r=!1,truncated:o=!1,theme:s="light",topHeadingLevel:a,iFrameAllowedDomains:l=zp,embeds:c=ot.NO_EMBEDS,embedLabels:u,documentFontFamily:f,mermaidInteraction:m,mermaidModifier:h,mermaidLabels:w,mermaidDrawing:y,mermaidExporting:p,maxMermaidDiagrams:x,codeBlockLabels:E,displayMathLabels:T,spreadsheetEditor:R,spreadsheetLocale:b,spreadsheetLabels:k,spreadsheetTapScrollCircle:A,spreadsheetScrollBarControls:P,linkComponent:L,missingImageLabel:B,blockFailedLabel:$,labelsLang:F,imageSource:q,svgImageLabels:H,onMathDiagnostics:ce,allowlist:oe="document",imageComponent:ee,idPrefix:se})=>{if(Ws(c),Ca(A?.size),t!==void 0&&dl(e,t),n!==void 0&&fl(n),a!==void 0&&Fl(a),x!==void 0&&jp(x),p!==void 0&&(va(p,"MarkdownRenderer: mermaidExporting"),y===void 0))throw new RangeError("MarkdownRenderer: mermaidExporting needs mermaidDrawing (only a diagram the drawing place draws is exported)");const Re=d.useMemo(()=>ac(oe,se),[oe,se]);if(oe==="untrusted"&&ee===void 0)throw new RangeError('MarkdownRenderer: allowlist "untrusted" needs imageComponent (the package never renders an image of untrusted text)');if(oe==="untrusted"&&L===void 0)throw new RangeError('MarkdownRenderer: allowlist "untrusted" needs linkComponent (the package never renders a link of untrusted text)');if(oe==="document"&&ee!==void 0)throw new RangeError('MarkdownRenderer: imageComponent needs allowlist "untrusted" (the images of a document render as written)');if(oe==="untrusted"&&q!==void 0)throw new RangeError('MarkdownRenderer: imageSource needs allowlist "document" (every image of untrusted text goes to imageComponent)');if(oe==="untrusted"&&(c.providers.length>0||c.linkCardEndpoint!==null))throw new RangeError('MarkdownRenderer: embeds that enable a provider or link cards need allowlist "document" (untrusted text never embeds a post or fetches a link card)');if(oe==="untrusted"&&l.length>0)throw new RangeError('MarkdownRenderer: iFrameAllowedDomains that allow a host need allowlist "document" (untrusted text never loads a frame)');if(r&&t===void 0)throw new RangeError("MarkdownRenderer: streaming needs blockOffsets (only the block offsets path holds open code blocks)");if(o&&t===void 0)throw new RangeError("MarkdownRenderer: truncated needs blockOffsets (only the block offsets path holds open code blocks)");const O=Lp(r,o),z=d.useMemo(()=>Cs(u,F),[u,F]),g=La(R),v=Ha(q),S=Sf(p),j=d.useMemo(()=>dt(Xn,H,F),[H,F]),D=d.useMemo(()=>dt(fn,T,F),[T,F]),{blockFailed:ae}=dt(Ps,{blockFailed:$},F),{missingImage:W}=d.useMemo(()=>dt(Ba,{missingImage:B},F),[B,F]),ie=d.useRef(null),Ee=d.useRef(null),xe=d.useEffectEvent(Ve=>{ce?.(Ve)}),Se=d.useCallback((Ve,mt)=>qa({iFrameAllowedDomains:l,embedLabels:z,frameSandbox:ot.frameSandboxOf(c),linkComponent:L,allowlistContext:Re,renderImage:ee===void 0?void 0:ye=>i.jsx(ee,{...kp(ye)}),renderPlaceholder:(ye,he,U)=>Op(ye,he,U,{embeds:c,theme:s,embedLabels:z,iFrameAllowedDomains:l,allowlistContext:Re}),renderKept:(ye,he)=>{if(ye.name==="p"&&v!==void 0){const U=Ap(ye,l,Re);if(U!==null)return i.jsx(wp,{paragraph:ye.attribs,image:Q.domToReact([U.node],he),path:U.path,name:U.name,reader:v,labels:j})}if(ye.name==="pre"&&ye.children.length===1){const U=ye.children[0];if(U instanceof Q.Element&&U.name==="code"){const ve=U.attribs.class??"",$e=gt(U.children),lt=ye.attribs[zt.SOURCE_LINES_ATTRIBUTE];if(Ua(U))return i.jsx(so,{tsv:$e,meta:U.attribs[me.CODE_META_ATTRIBUTE],sourceLines:lt,editor:g,locale:b,labels:k,labelsLang:F,tapScrollCircle:A,tapScrollCircleShownBy:"options",scrollBarControls:P});const Te=Object.hasOwn(ye.attribs,me.OPEN_CODE_ATTRIBUTE);if(Te&&(Ve.openCode.rendered+=1),ve.includes("language-mermaid")){const ht=Ve.diagrams.rendered;return Ve.diagrams.rendered+=1,i.jsx(ro,{chartContent:$e,interaction:m,modifier:h,labels:w,labelsLang:F,sourceLines:lt,drawing:y,theme:s,exporting:S===void 0?void 0:{...S,index:ht+1},held:Dp(ht,Te,mt,x)})}return i.jsx(ao,{lang:ve.replace("language-",""),code:$e,theme:s,sourceLines:lt,labels:E,labelsLang:F,deferHighlight:Te&&mt==="streaming"})}}if(ye.name==="img")return vp(ye,W,Ve.images);if(ye.name==="span"&&ye.attribs.class?.includes("math")){const U=ye.attribs.class.includes("display");let ve=gt(ye.children).trim();U?ve=ve.replace(/^\\\[/,"").replace(/\\\]$/,""):ve=ve.replace(/^\\\(/,"").replace(/\\\)$/,"");try{const{innerHtml:$e,diagnostics:lt}=_a(ve,U);return Ve.mathReports.push(...lt),U?i.jsx(Rp,{source:ve,innerHtml:$e,labels:D}):i.jsx("span",{dangerouslySetInnerHTML:$e})}catch($e){console.error("Failed to render math:",$e);return}}if(a!==void 0){const U=ql(ye.name);if(U!==void 0)return Tp(ye,U,a,he)}}}),[l,z,c,L,s,v,j,g,b,k,A,P,m,h,w,y,S,x,E,F,W,D,a,Re,ee]),be={images:{rendered:0},diagrams:{rendered:0},openCode:{rendered:0},mathReports:[]},Oe=Se(be,O),Ke=d.useRef(Bp),Ie=Ke.current,at=n!==Ie.epoch,Ge={options:Oe,tally:be,progress:O,previous:Ie.keys,failureLabel:ae},{nodes:De,keys:Pe,kept:Ye,diagnostics:et}=t===void 0?Pp(e,{...Ge,rules:{inherit:!1,contentOnly:at}}):$p(e,t,Ie.parserOptionsFor===Se?Ie.kept:un,{...Ge,rules:{inherit:!0,contentOnly:at}});d.useEffect(()=>{Ke.current={keys:Pe,epoch:n,parserOptionsFor:Se,kept:Ye}},[Pe,n,Se,Ye]),d.useEffect(()=>{ie.current!==e&&(ie.current=e,et.length>0&&xe(et))},[e,et]);const St=zs(f),it=St===void 0?void 0:{[Ue.DOCUMENT_FONT_FAMILY_PROPERTY]:St,fontFamily:`var(${Ue.DOCUMENT_FONT_FAMILY_PROPERTY})`};return i.jsxs("div",{ref:Ee,className:"markdown-body","data-theme":s,"data-aqmd-document":"",style:it,children:[De,t!==void 0&&i.jsx(Om,{root:Ee})]})};const Fp=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],qp=re("triangle-alert",Fp);const Hp=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 19H5",key:"vjpgq2"}]],Up=re("text-align-center",Hp);const Wp=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 19H3",key:"z6ezky"}]],Gp=re("text-align-start",Wp);const Vp=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 19H7",key:"4cu937"}]],Kp=re("text-align-end",Vp);const Yp=[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]],Xp=re("list",Yp);const Zp=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],Jp=re("palette",Zp);const Qp=[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]],eg=re("pin",Qp);const tg=[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]],ng=re("pin-off",tg),rg=new Set(["UL","OL","LI","DL","DD","BLOCKQUOTE","SECTION","DETAILS"]),Va=e=>[...e.children].flatMap(t=>rg.has(t.tagName)?[t,...Va(t)]:[t]),og=(e,t)=>{let n=null;for(const r of Va(e)){if(!r.checkVisibility())continue;const o=r.getBoundingClientRect().top-t;(n===null||Math.abs(o)<Math.abs(n.offset))&&(n={block:r,offset:o})}return n},zr=({block:e,offset:t,root:n,scroller:r})=>(e.getBoundingClientRect().top-r.getBoundingClientRect().top-t)/js(n),Es=e=>{e.scrollTop=e.scroller.scrollTop,e.moved=zr(e)},Ss=(e,t)=>{const n=e.scroller.scrollTop-e.scrollTop;return Math.abs(n)>=1&&Math.abs(t-e.moved+n)<1};class sg extends d.Component{anchor=null;getSnapshotBeforeUpdate(t){const{scroller:n,root:r,documentKey:o,style:s,measure:a,align:l,documentFontFamily:c}=this.props;if(s===t.style&&a===t.measure&&l===t.align&&c===t.documentFontFamily||o!==t.documentKey||n.scrollTop===0)return null;const f=og(r,n.getBoundingClientRect().top);return f===null?null:{...f,scroller:n,root:r,documentKey:o,listening:new AbortController,scrollTop:n.scrollTop,moved:0}}componentDidUpdate(t,n,r){r&&this.keep(r);const o=this.anchor;if(o===null)return;if(o.documentKey!==this.props.documentKey||!o.block.isConnected){this.release();return}const s=zr(o);if(Ss(o,s)){this.release();return}s!==0&&o.scroller.scrollTo({top:o.scroller.scrollTop+s,behavior:"instant"}),Es(o)}componentWillUnmount(){this.release()}render(){return null}keep(t){this.release(),this.anchor=t,t.scroller.addEventListener("scroll",()=>{Ss(t,zr(t))?this.release():Es(t)},{passive:!0,signal:t.listening.signal}),t.scroller.ownerDocument.addEventListener("click",()=>this.release(),{capture:!0,signal:t.listening.signal}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.anchor===t&&this.release()})})}release(){this.anchor?.listening.abort(),this.anchor=null}}const ag=e=>`#${e.id}`,ig=e=>{let t=Number.POSITIVE_INFINITY;for(const n of e)n.depth<t&&(t=n.depth);return t},vs="block truncate py-[max(0px,calc((2.75rem_-_1lh)_/_2))]",Ka=({headings:e,className:t="",onHeadingSelect:n,headingHref:r=ag,label:o,labelledBy:s})=>{if(e.length===0)return null;const a=ig(e);return i.jsx("nav",{className:`toc ${t}`,"aria-label":o,"aria-labelledby":s,children:i.jsx("ul",{className:"m-0 list-none p-0",children:e.map((l,c)=>{const u=l.id===""?null:r(l);return i.jsx("li",{style:{paddingLeft:`${(l.depth-a)*1}rem`},children:u===null?i.jsx("span",{className:`${vs} text-gray-600 dark:text-gray-300`,title:l.text,children:l.text}):i.jsx("a",{href:mn(u)?u:void 0,className:`${vs} text-gray-600 no-underline hover:text-blue-800 dark:text-gray-300 dark:hover:text-blue-300`,onClick:n===void 0?void 0:f=>n(l,f),title:l.text,children:l.text})},c)})})})},wr="--aqmd-toolbar-block-overlap",lg="--aqmd-toolbar-block-reach-px",cg=1/16,dg=2,ug=(e,t,n)=>{const r=dg*cg/Math.min(1,n);return t>0&&e-t<r&&t-e<1+r?t:Hi(e)},fg=({toolbar:e,content:t,scrollportTop:n,scrollportBottom:r,scale:o,reach:s})=>{if(e.width<=0||e.height<=0)return 0;const a=e.left<t.right&&e.right>t.left,l=e.top<n+e.height&&e.top<r,c=e.bottom-n;return a&&l&&c>0?ug(c/o,s,o):0},Ut=(e,t)=>`${e}${t.charAt(0).toUpperCase()}${t.slice(1)}`,Nn=(e,t)=>Object.fromEntries(Object.keys(t).map(n=>[Ut(e,n),t[n]])),mg=e=>![...$f,...Bf,...zf].includes(e),Ya=Object.keys(Yn).filter(mg),{errorPrefix:hg,...pg}=Object.fromEntries(Ya.map(e=>[e,Yn[e]])),gg=Object.keys(me.SPREADSHEET_BLOCK_LABEL_CATALOGS.en),yg=Object.keys(Xn),xg=Object.keys(Hn),bg=Object.keys(fn),Xa=Object.freeze({loading:{text:"Loading data...",lang:"en"},errorPrefix:hg,defaultErrorTitle:{text:"An error occurred",lang:"en"},...Ba,...Ps,styleTitle:{text:"Display",lang:"en"},selectStyleAria:{text:"Display options",lang:"en"},pinStyleAria:{text:"Pin display options",lang:"en"},unpinStyleAria:{text:"Unpin display options",lang:"en"},styleSectionTitle:{text:"Style",lang:"en"},measureTitle:{text:"Width",lang:"en"},colorsTitle:{text:"Colors",lang:"en"},measureFill:{text:"Full width",lang:"en"},measureReading:{text:"Reading width",lang:"en"},colorsDefault:{text:"Document colors",lang:"en"},colorsSepia:{text:"Sepia",lang:"en"},colorsDarkLowGlare:{text:"Dark, low glare",lang:"en"},colorsHighContrast:{text:"High contrast",lang:"en"},fontTitle:{text:"Font",lang:"en"},fontDefault:{text:"Default font",lang:"en"},openTocAria:{text:"目次を開く",lang:"ja"},tocTitle:{text:"目次",lang:"ja"},pinTocAria:{text:"目次をピン留め",lang:"ja"},unpinTocAria:{text:"目次のピン留めを解除",lang:"ja"},selectAlignAria:{text:"揃えを選択",lang:"ja"},alignTitle:{text:"揃え",lang:"ja"},pinAlignAria:{text:"揃え選択をピン留め",lang:"ja"},unpinAlignAria:{text:"揃え選択のピン留めを解除",lang:"ja"},alignLeft:{text:"左揃え",lang:"ja"},alignCenter:{text:"中央揃え",lang:"ja"},alignRight:{text:"右揃え",lang:"ja"},...Nn("mermaid",pg),...Nn("svgImage",Xn),...Nn("codeBlock",Hn),...Nn("displayMath",fn),...Un}),wg=qt(Xa),Eg=(e,t)=>dt(Xa,e,t),pn=(e,t,n)=>{const r={};if(e===void 0)return Object.freeze(r);for(const o of t){const s=e[n(o)];s!==void 0&&(r[o]=s)}return Object.freeze(r)},Sg=e=>pn(e,Ya,t=>t==="errorPrefix"?t:Ut("mermaid",t)),vg=e=>pn(e,gg,t=>Ut("spreadsheet",t)),kg=e=>pn(e,yg,t=>Ut("svgImage",t)),Tg=e=>pn(e,xg,t=>Ut("codeBlock",t)),Rg=e=>pn(e,bg,t=>Ut("displayMath",t)),_g=Object.keys(Un),Og=e=>{const t={};if(e===void 0)return Object.freeze(t);for(const n of _g){const r=e[n];r!==void 0&&(t[n]=r)}return Object.freeze(t)},Ag="pointer-events-auto rounded-full border border-gray-200 bg-white p-3 shadow-lg transition-colors hover:bg-gray-100 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700",Ng="h-5 w-5 text-gray-600 dark:text-gray-300",Cg="[data-aqmd-document]",ks=Object.freeze({left:{labelKey:"alignLeft",Icon:Gp},center:{labelKey:"alignCenter",Icon:Up},right:{labelKey:"alignRight",Icon:Kp}}),Lg=Object.freeze({fill:"measureFill",reading:"measureReading"}),jg=Object.freeze({default:"colorsDefault",sepia:"colorsSepia","dark-low-glare":"colorsDarkLowGlare","high-contrast":"colorsHighContrast"}),Mg=Object.freeze([]),Er="",nn=e=>e===null?"null":Array.isArray(e)?"an array":typeof e,Ig=e=>{if(!Array.isArray(e))throw new TypeError(`[@aiquants/markdown] documentFontOptions must be an array of { key, label }; got ${nn(e)}`);const t=new Set,n=new Set;for(const[r,o]of e.entries()){const s=`documentFontOptions[${String(r)}]`;if(o===null||typeof o!="object")throw new TypeError(`[@aiquants/markdown] ${s} must be an object with a key and a label; got ${nn(o)}`);const{key:a,label:l}=o;if(typeof a!="string"||typeof l!="string")throw new TypeError(`[@aiquants/markdown] ${s} needs a string key and a string label; got a key of ${nn(a)} and a label of ${nn(l)}`);if(a.trim()===""||l.trim()==="")throw new RangeError(`[@aiquants/markdown] ${s} needs a key and a label that are not blank`);if(t.has(a))throw new RangeError(`[@aiquants/markdown] the keys of documentFontOptions must be unique; ${JSON.stringify(a)} repeats at ${s}`);if(n.has(l))throw new RangeError(`[@aiquants/markdown] the labels of documentFontOptions must be unique; ${JSON.stringify(l)} repeats at ${s}`);t.add(a),n.add(l)}},Za=e=>`min-h-11 w-full rounded px-2 py-1 text-left text-sm transition-colors ${e?"bg-blue-100 font-medium text-blue-800 dark:bg-blue-900 dark:text-blue-200":"bg-transparent text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-700 dark:hover:text-gray-200"}`,Dg="--aqmd-reading-margin-inline",Pg=Object.freeze({emptyMessage:{text:"ファイルを選択してください。",lang:"ja"}}),$g="100%",Ts=e=>e==="center"?"auto":e==="right"?"auto 0":"0 auto",Br="24px",Ja=e=>Object.freeze({position:"fixed",insetBlockStart:"var(--aqmd-toolbar-inset-block-start, 0px)",insetInlineEnd:`calc(var(--aqmd-toolbar-inset-inline-end, 0px) + ${e})`,zIndex:60,display:"flex",flexDirection:"row",alignItems:"flex-start",gap:"0.5rem",pointerEvents:"none"}),zg=Ja(Br),Bg=Object.freeze({position:"absolute",insetBlockStart:0,insetInlineStart:0,blockSize:"var(--aqmd-toolbar-inset-block-start, 0px)",inlineSize:"var(--aqmd-toolbar-inset-inline-end, 0px)",visibility:"hidden",pointerEvents:"none"}),Fg=e=>`calc(100cqi - var(--aqmd-toolbar-inset-inline-end, 0px) - ${e})`,qg=8,Rs=800,Hg=16,Ug=(e,t)=>{const n=e.defaultView;let r;const o=()=>{e.removeEventListener("click",s,!0),e.removeEventListener("pointercancel",a,!0),r!==void 0&&n?.clearTimeout(r)};function s(l){o(),!(l.timeStamp-t.timeStamp>Rs||Math.hypot(l.clientX-t.clientX,l.clientY-t.clientY)>Hg)&&(l.preventDefault(),l.stopPropagation())}function a(l){l.pointerId===t.pointerId&&o()}e.addEventListener("click",s,!0),e.addEventListener("pointercancel",a,!0),r=n?.setTimeout(o,Rs)},Wg=(e,t,n)=>{const[r,o]=d.useState(null);return d.useLayoutEffect(()=>{const s=t.current;if(!e||s===null||n===null){o(null);return}const a=s.ownerDocument.defaultView;let l=0;const c=()=>{l=0;const m=s.getBoundingClientRect(),h=js(s),w=a?.visualViewport??null,y=w===null?Number.POSITIVE_INFINITY:w.offsetTop+w.height,p=Math.min(n.getBoundingClientRect().bottom,y);o(Math.max(0,Math.floor((p-m.top)/h-qg)))},u=()=>{a!==null&&l===0&&(l=a.requestAnimationFrame(c))};c();const f=new ResizeObserver(u);return f.observe(n),a?.addEventListener("resize",u),a?.visualViewport?.addEventListener("resize",u),a?.visualViewport?.addEventListener("scroll",u),s.ownerDocument.addEventListener("scroll",u,!0),()=>{a!==null&&l!==0&&a.cancelAnimationFrame(l),f.disconnect(),a?.removeEventListener("resize",u),a?.visualViewport?.removeEventListener("resize",u),a?.visualViewport?.removeEventListener("scroll",u),s.ownerDocument.removeEventListener("scroll",u,!0)}},[e,t,n]),r};function Sr({menu:e,Icon:t,buttonLabel:n,titleLabel:r,titleId:o,pinLabel:s,unpinLabel:a,isOpen:l,isPinned:c,isFront:u,onActivate:f,onToggle:m,onClose:h,onPinToggle:w,popoverClassName:y,scrollBarClearance:p,boundary:x,renderBody:E}){const T=d.useRef(null),R=d.useRef(null),b=d.useRef(null),k=Wg(l,b,x),A=d.useCallback(()=>{m(),f()},[f,m]),P=d.useCallback(()=>{if(c)return;const B=T.current?.contains(document.activeElement)===!0;h(),B&&R.current?.focus()},[c,h]);d.useEffect(()=>{if(!l||c)return;const B=T.current;if(B===null)return;const $=q=>{B.contains(q.target)||(h(),q.pointerType==="touch"&&!(q.target instanceof Element&&q.target.closest("[data-aqmd-toolbar]")!==null)&&Ug(B.ownerDocument,q))},F=q=>{q.key!=="Escape"||q.defaultPrevented||Ns.isInputMethodKey(q)||(q.preventDefault(),h(),R.current?.focus())};return document.addEventListener("pointerdown",$),B.addEventListener("keydown",F),()=>{document.removeEventListener("pointerdown",$),B.removeEventListener("keydown",F)}},[l,c,h]);const L=c?a:s;return i.jsxs("div",{ref:T,"data-aqmd-toolbar-menu":e,children:[i.jsx("button",{ref:R,type:"button","data-aqmd-toolbar-button":!0,className:Ag,onClick:A,"aria-label":n.text,lang:n.lang,"aria-expanded":l,children:i.jsx(t,{className:Ng})}),l&&i.jsxs("div",{ref:b,"data-aqmd-toolbar-popover":e,className:`pointer-events-auto absolute end-0 top-full mt-2 box-border overflow-y-auto overscroll-contain rounded-lg border border-gray-200 bg-white shadow-xl dark:border-gray-700 dark:bg-gray-800 ${y}`,style:{zIndex:u?2:1,maxInlineSize:Fg(p),maxBlockSize:k??void 0},children:[i.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[i.jsx("h3",{id:o,lang:r.lang,className:"px-2 font-bold text-gray-600 text-sm uppercase tracking-wider dark:text-gray-300",children:r.text}),i.jsx("button",{type:"button",className:"rounded bg-transparent p-3.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-200",onClick:w,"aria-label":L.text,lang:L.lang,children:c?i.jsx(eg,{className:"h-4 w-4"}):i.jsx(ng,{className:"h-4 w-4"})})]}),E(P)]})]})}function Cn({section:e,titleLabel:t,options:n,current:r,onChoose:o}){return i.jsxs("fieldset",{className:"m-0 min-w-0 border-0 p-0","data-aqmd-display-section":e,children:[i.jsx("legend",{lang:t.lang,className:"px-2 pb-1 font-medium text-gray-600 text-xs dark:text-gray-300",children:t.text}),i.jsx("div",{className:"space-y-1",children:n.map(({value:s,label:a})=>i.jsx("button",{type:"button","aria-pressed":r===s,lang:a.lang,className:Za(r===s),onClick:()=>o(s),children:a.text},s))})]})}const Gg=(e,t,n,r)=>{const[o,s]=d.useState(null),a=d.useRef(null);return d.useLayoutEffect(()=>{const l=e.current;if(n===null||l===null||t===null){a.current=null,s(null);return}const c=()=>{const w=l.getBoundingClientRect();if(w.width===0&&w.height===0)return;const y=n.getBoundingClientRect(),p=rn(getComputedStyle(n).height);if(p<=0||y.height<=0){s(0);return}const x=y.height/p,E=rn(getComputedStyle(l).getPropertyValue(lg));s(fg({toolbar:y,content:t.getBoundingClientRect(),scrollportTop:w.top+l.clientTop*x,scrollportBottom:w.bottom,scale:x,reach:E}))};a.current=c;let u=null;const f=()=>{u===null&&(u=requestAnimationFrame(()=>{u=null,c()}))};c();const m=new ResizeObserver(c);m.observe(l),m.observe(t),m.observe(n);const h=n.querySelector("[data-aqmd-toolbar-inset-probe]");return h!==null&&m.observe(h),window.addEventListener("resize",c),window.addEventListener("scroll",f,{capture:!0,passive:!0}),()=>{a.current=null,m.disconnect(),window.removeEventListener("resize",c),window.removeEventListener("scroll",f,{capture:!0}),u!==null&&cancelAnimationFrame(u)}},[e,t,n]),d.useLayoutEffect(()=>{a.current?.()},[r]),o},Vg=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,Kg=e=>{let t=null,n=e;for(;n!==null;)n.getAttribute("hidden")?.toLowerCase()==="until-found"&&(n.dispatchEvent(new Event("beforematch",{bubbles:!0})),n.removeAttribute("hidden")),n instanceof HTMLDetailsElement&&!n.open&&t!==null&&t!==Array.from(n.children).find(r=>r.localName==="summary")&&(n.open=!0),t=n,n=n.parentElement},Yg=d.memo(function({parseResult:t,theme:n,iFrameAllowedDomains:r,embeds:o,embedLabels:s,linkComponent:a,missingImageLabel:l,blockFailedLabel:c,labelsLang:u,mermaidLabels:f,mermaidModifier:m,documentFontFamily:h,codeBlockLabels:w,displayMathLabels:y,spreadsheetEditor:p,spreadsheetLocale:x,spreadsheetLabels:E,spreadsheetTapScrollCircle:T,spreadsheetScrollBarControls:R,imageSource:b,svgImageLabels:k,onMathDiagnostics:A}){return i.jsx(Ga,{htmlContent:t.htmlContent,theme:n,iFrameAllowedDomains:r,embeds:o,embedLabels:s,linkComponent:a,missingImageLabel:l,blockFailedLabel:c,labelsLang:u,mermaidLabels:f,mermaidModifier:m,documentFontFamily:h,codeBlockLabels:w,displayMathLabels:y,spreadsheetEditor:p,spreadsheetLocale:x,spreadsheetLabels:E,spreadsheetTapScrollCircle:T,spreadsheetScrollBarControls:R,imageSource:b,svgImageLabels:k,onMathDiagnostics:A})});function Qa(){const[e,t]=d.useState("toc"),[n,r]=d.useState(!1),[o,s]=d.useState(!1),[a,l]=d.useState(!1),[c,u]=d.useState(!1),[f,m]=d.useState(!1),[h,w]=d.useState(!1),y=d.useCallback(()=>t("toc"),[]),p=d.useCallback(()=>r($=>!$),[]),x=d.useCallback(()=>r(!1),[]),E=d.useCallback(()=>u($=>!$),[]),T=d.useCallback(()=>t("style"),[]),R=d.useCallback(()=>s($=>!$),[]),b=d.useCallback(()=>s(!1),[]),k=d.useCallback(()=>m($=>!$),[]),A=d.useCallback(()=>t("align"),[]),P=d.useCallback(()=>l($=>!$),[]),L=d.useCallback(()=>l(!1),[]),B=d.useCallback(()=>w($=>!$),[]);return{lastActiveMenu:e,isTocOpen:n,isStyleOpen:o,isAlignOpen:a,isTocPinned:c,isStylePinned:f,isAlignPinned:h,activateToc:y,toggleToc:p,closeToc:x,togglePinToc:E,activateStyle:T,toggleStyle:R,closeStyle:b,togglePinStyle:k,activateAlign:A,toggleAlign:P,closeAlign:L,togglePinAlign:B}}const Xg=({error:e,labels:t})=>{if(d.isValidElement(e))return i.jsx("div",{className:"p-4",children:e});if(typeof e=="object"&&e!==null&&"message"in e){const r=e,o=r.title!==void 0&&r.title!=="";return i.jsx("div",{"data-aqmd-error-display":"",className:"mx-auto my-8 max-w-lg rounded-xl border border-red-200 bg-red-50/50 p-6 shadow-sm backdrop-blur-sm dark:border-red-900/50 dark:bg-red-950/30",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("div",{className:"rounded-lg bg-red-100 p-2 text-red-600 dark:bg-red-900/50 dark:text-red-400",children:i.jsx(qp,{className:"h-5 w-5"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("h3",{lang:o?void 0:t.defaultErrorTitle.lang,className:"font-semibold text-base text-red-900 dark:text-red-200",children:o?r.title:t.defaultErrorTitle.text}),r.status&&i.jsx("span",{className:"rounded bg-red-100 px-2 py-0.5 font-medium font-mono text-red-700 text-xs dark:bg-red-900/60 dark:text-red-300",children:r.status})]}),i.jsx("p",{className:"mt-2 text-red-700 text-sm leading-relaxed dark:text-red-300/90",children:r.message})]})]})})}const n=typeof e=="string"?e:String(e);return i.jsx("div",{"data-aqmd-error-display":"",className:"mx-auto my-8 max-w-lg rounded-xl border border-red-200 bg-red-50/50 p-4 text-center dark:border-red-900/50 dark:bg-red-950/30",children:i.jsxs("p",{className:"font-medium text-red-700 text-sm dark:text-red-300",children:[i.jsx("span",{lang:t.errorPrefix.lang,children:t.errorPrefix.text}),n]})})},Zg=(e,t)=>e===null?`${t}px`:e,Jg=e=>{const t=Fr("scrollBarGutter",e);return e===0?null:t};function Qg({parseResult:e,content:t,error:n=null,isLoading:r=!1,labels:o,labelsLang:s,theme:a,style:l,onStyleChange:c,availableStyles:u=Ue.DEFAULT_MARKDOWN_STYLES,align:f=Ue.DEFAULT_CONTENT_ALIGN,onAlignChange:m,showToc:h=!0,showStyle:w=!0,showAlign:y=!0,contentLang:p,measure:x=Ue.DEFAULT_CONTENT_MEASURE,onMeasureChange:E,showMeasure:T=!0,contentColors:R=Ue.DEFAULT_CONTENT_COLORS,onContentColorsChange:b,showContentColors:k=!0,documentFontOptions:A=Mg,documentFont:P,onDocumentFontChange:L,showDocumentFont:B=!0,width:$,maxWidth:F,padding:q=16,iFrameAllowedDomains:H,embeds:ce=ot.NO_EMBEDS,fetch:oe,emptyMessage:ee,toolbar:se,linkComponent:Re,onHeadingSelect:O,headingHref:z,onMathDiagnostics:g,spreadsheetEditor:v,spreadsheetLocale:S,spreadsheetTapScrollCircle:j,spreadsheetScrollBarControls:D,mermaidModifier:ae,documentFontFamily:W,imageSource:ie,renderScrollBar:Ee,scrollBarGutter:xe=0,scrollBarInlineSize:Se}){const be=d.useRef(null),[Oe,Ke]=d.useState(null),Ie=d.useCallback(ge=>{be.current=ge,Ke(ge)},[]),[at,Ge]=d.useState(0),[De,Pe]=d.useState(null),[Ye,et]=d.useState(null),St=d.useCallback(ge=>{et(ge===null?null:ge.querySelector(Cg))},[]),[it,Ve]=d.useState(null),mt=d.useId(),ye=Qa(),he=se??ye,U=d.useMemo(()=>Eg(o,s),[o,s]),ve=d.useMemo(()=>Sg(o),[o]),$e=d.useMemo(()=>vg(o),[o]),lt=d.useMemo(()=>kg(o),[o]),Te=d.useMemo(()=>Tg(o),[o]),ht=d.useMemo(()=>Rg(o),[o]),Nt=Ha(ie),Ct=vl(oe),tt=La(v);Ws(ce);const nt=kt.EMBED_PROVIDER_IDS.filter(ge=>ce.providers.includes(ge)).join(" "),C=ce.linkCardEndpoint,G=ce.linkCardSize,X=ce.frameSandbox,V=d.useMemo(()=>{const ge=nt.split(" "),ue=Object.freeze(kt.EMBED_PROVIDER_IDS.filter(bn=>ge.includes(bn)));return Object.freeze({providers:ue,linkCardEndpoint:C,...G===void 0?void 0:{linkCardSize:G},...X===void 0?void 0:{frameSandbox:X}})},[nt,C,G,X]),_e=o?.embeddedVideo,we=o?.embeddedPost,Z=o?.embeddedFrame,pe=d.useMemo(()=>Og({embeddedVideo:_e,embeddedPost:we,embeddedFrame:Z}),[_e,we,Z]),qe=d.useRef(g);d.useLayoutEffect(()=>{qe.current=g},[g]);const vt=d.useCallback(ge=>{qe.current?.(ge)},[]),{emptyMessage:ct}=d.useMemo(()=>dt(Pg,{emptyMessage:ee},s),[ee,s]),Le=d.useMemo(()=>u.find(ue=>ue.name===l)?.className??"markdown-body",[u,l]),Ae=Gg(be,x==="reading"&&Ye!==null?Ye:De,it,`${f} ${x} ${Le}`);if(!Ue.CONTENT_ALIGNS.includes(f))throw new TypeError(`[@aiquants/markdown] align must be one of ${Ue.CONTENT_ALIGNS.join(", ")}; got ${String(f)} (normalize it with toContentAlign)`);if(!Ue.CONTENT_MEASURES.includes(x))throw new TypeError(`[@aiquants/markdown] measure must be one of ${Ue.CONTENT_MEASURES.join(", ")}; got ${String(x)} (normalize it with toContentMeasure)`);if(!Ue.CONTENT_COLORS.includes(R))throw new TypeError(`[@aiquants/markdown] contentColors must be one of ${Ue.CONTENT_COLORS.join(", ")}; got ${String(R)} (normalize it with toContentColors)`);if(Ig(A),P!==void 0){if(typeof P!="string")throw new TypeError(`[@aiquants/markdown] documentFont must be a string or undefined; got ${nn(P)}`);if(!A.some(ge=>ge.key===P))throw new RangeError(`[@aiquants/markdown] documentFont must be one of the keys of documentFontOptions; got ${JSON.stringify(P)} (pass a stored key only while it is listed)`)}const Ne=Number.isFinite(q)&&q>=0?q:16,He=Jg(xe),ke=Ee===void 0?null:He,Ze=Se===void 0?null:Fr("scrollBarInlineSize",Se),{isTocPinned:xt,closeToc:ze}=he,J=d.useCallback((ge,ue)=>{if(xt||ze(),O?.(ge,ue)===!0)return;ue.preventDefault();const wt=be.current?.querySelector(`#${CSS.escape(ge.id)}`)??document.getElementById(ge.id);wt&&(Kg(wt),wt.tabIndex<0&&!wt.hasAttribute("tabindex")&&wt.setAttribute("tabindex","-1"),wt.scrollIntoView({behavior:Vg()?"instant":"smooth",block:"start"}),wt.focus({preventScroll:!0}))},[ze,xt,O]),_=e?.headings??[],M=!(r||n),I=M&&e!==null,Y=M&&e===null&&t!==null,de=I&&h&&_.length>0,Be=I&&w,Je=I&&T&&typeof E=="function",Wt=I&&k&&typeof b=="function",Tt=I&&B&&typeof L=="function"&&A.length>0,Gt=Be||Je||Wt||Tt,Lt=I&&x==="reading",Vt=$!==void 0||F!==void 0||Lt,Kt=(I||Y)&&y&&typeof m=="function"&&Vt,gn=d.useMemo(()=>i.jsx(Ka,{headings:_,className:"text-sm",labelledBy:mt,onHeadingSelect:J,headingHref:z}),[_,mt,J,z]),bt=Ee===void 0?Br:Zg(Ze,at),yn=d.useMemo(()=>bt===Br?zg:Ja(bt),[bt]),Yt=de||Gt||Kt?i.jsxs("div",{ref:Ve,"data-aqmd-toolbar":!0,style:yn,children:[i.jsx("span",{"data-aqmd-toolbar-inset-probe":!0,"aria-hidden":"true",style:Bg}),Kt&&m&&i.jsx(Sr,{menu:"align",Icon:ks[f].Icon,buttonLabel:U.selectAlignAria,titleLabel:U.alignTitle,pinLabel:U.pinAlignAria,unpinLabel:U.unpinAlignAria,isOpen:he.isAlignOpen,isPinned:he.isAlignPinned,isFront:he.lastActiveMenu==="align",onActivate:he.activateAlign,onToggle:he.toggleAlign,onClose:he.closeAlign,onPinToggle:he.togglePinAlign,popoverClassName:"w-48 p-2",scrollBarClearance:bt,boundary:Oe,renderBody:ge=>i.jsx("div",{className:"space-y-1",children:Ue.CONTENT_ALIGNS.map(ue=>{const{labelKey:bn,Icon:wt}=ks[ue],uo=U[bn],fo=f===ue;return i.jsxs("button",{type:"button","aria-pressed":fo,lang:uo.lang,className:`flex items-center gap-2 ${Za(fo)}`,onClick:()=>{m(ue),ge()},children:[i.jsx(wt,{className:"h-4 w-4"}),uo.text]},ue)})})}),Gt&&i.jsx(Sr,{menu:"style",Icon:Jp,buttonLabel:U.selectStyleAria,titleLabel:U.styleTitle,pinLabel:U.pinStyleAria,unpinLabel:U.unpinStyleAria,isOpen:he.isStyleOpen,isPinned:he.isStylePinned,isFront:he.lastActiveMenu==="style",onActivate:he.activateStyle,onToggle:he.toggleStyle,onClose:he.closeStyle,onPinToggle:he.togglePinStyle,popoverClassName:"w-48 p-2",scrollBarClearance:bt,boundary:Oe,renderBody:ge=>i.jsxs("div",{className:"space-y-3",children:[Be&&i.jsx(Cn,{section:"style",titleLabel:U.styleSectionTitle,options:u.map(ue=>({value:ue.name,label:{text:ue.name,lang:void 0}})),current:l,onChoose:ue=>{c(ue),ge()}}),Je&&E&&i.jsx(Cn,{section:"measure",titleLabel:U.measureTitle,options:Ue.CONTENT_MEASURES.map(ue=>({value:ue,label:U[Lg[ue]]})),current:x,onChoose:ue=>{E(ue),ge()}}),Wt&&b&&i.jsx(Cn,{section:"colors",titleLabel:U.colorsTitle,options:Ue.CONTENT_COLORS.map(ue=>({value:ue,label:U[jg[ue]]})),current:R,onChoose:ue=>{b(ue),ge()}}),Tt&&L&&i.jsx(Cn,{section:"font",titleLabel:U.fontTitle,options:[{value:Er,label:U.fontDefault},...A.map(ue=>({value:ue.key,label:{text:ue.label,lang:void 0}}))],current:P??Er,onChoose:ue=>{L(ue===Er?void 0:ue),ge()}})]})}),de&&i.jsx(Sr,{menu:"toc",Icon:Xp,buttonLabel:U.openTocAria,titleLabel:U.tocTitle,titleId:mt,pinLabel:U.pinTocAria,unpinLabel:U.unpinTocAria,isOpen:he.isTocOpen,isPinned:he.isTocPinned,isFront:he.lastActiveMenu==="toc",onActivate:he.activateToc,onToggle:he.toggleToc,onClose:he.closeToc,onPinToggle:he.togglePinToc,popoverClassName:"markdown-viewer-scrollbar-thin w-64 p-4",scrollBarClearance:bt,boundary:Oe,renderBody:()=>gn})]}):null,N=()=>r?i.jsxs("p",{children:[i.jsx("span",{"aria-hidden":"true",children:"🌀"})," ",i.jsx("span",{lang:U.loading.lang,children:U.loading.text})]}):n?i.jsx(Xg,{error:n,labels:U}):e?i.jsx("div",{className:"relative w-full min-w-0",children:i.jsx("div",{className:"w-full min-w-0",children:i.jsx("div",{ref:St,className:Le,"data-theme":a,"data-aqmd-reading-box":Lt?"":void 0,style:Lt?{[Dg]:Ts(f)}:void 0,children:i.jsx(Hs,{value:Ct,children:i.jsx(Yg,{parseResult:e,theme:a,iFrameAllowedDomains:H,embeds:V,embedLabels:pe,linkComponent:Re,missingImageLabel:o?.missingImage,blockFailedLabel:o?.blockFailed,labelsLang:s,mermaidLabels:ve,mermaidModifier:ae,documentFontFamily:W,codeBlockLabels:Te,displayMathLabels:ht,spreadsheetEditor:tt,spreadsheetLocale:S,spreadsheetLabels:$e,spreadsheetTapScrollCircle:j,spreadsheetScrollBarControls:D,imageSource:Nt,svgImageLabels:lt,onMathDiagnostics:vt})})})})}):t!==null?i.jsx("pre",{className:"whitespace-pre-wrap break-all",children:t}):i.jsx("p",{lang:ct.lang,children:ct.text}),te={containerType:"inline-size",...ke===null?{paddingInline:`${Ne}px`}:{paddingInlineStart:`${Ne}px`,paddingInlineEnd:`calc(${Ne}px + ${ke})`},paddingBlockEnd:`${Ne}px`,paddingBlockStart:`calc(${Ne}px + var(${wr}, 0px))`,scrollPaddingBlockStart:`var(${wr}, 0px)`,...Ae===null?void 0:{[wr]:`${Ae}px`}},je=Yt!==null&&!Vt,Me=Y?De:Ye,xn=R===Ue.DEFAULT_CONTENT_COLORS?void 0:R;return i.jsxs(Ms,{scrollerRef:Ie,scrollerProps:{"data-testid":"viewer","data-aqmd-scroll-container":!0,"data-aqmd-colors":xn,"data-aqmd-toolbar-over-content":je?!0:void 0,className:"grid h-full w-full overflow-x-auto overflow-y-auto *:min-w-0",style:te},renderScrollBar:Ee,barInlineSize:Se,onBarInlineSizeChange:Ge,children:[Yt,i.jsx("div",{ref:Pe,"data-aqmd-content":!0,"data-aqmd-colors":xn,lang:I||Y?p:void 0,style:{width:$??$g,maxWidth:F,marginInline:Ts(f)},children:N()}),Oe!==null&&Me!==null&&i.jsx(sg,{scroller:Oe,root:Me,documentKey:Y?t:e?.htmlContent,style:l,measure:x,align:f,documentFontFamily:I?zs(W):void 0})]})}const ei=({node:e})=>i.jsx("del",{children:i.jsx(Ce,{nodes:e.children})}),ti=({node:e})=>i.jsx("em",{children:i.jsx(Ce,{nodes:e.children})}),ni=({node:e})=>i.jsx("sup",{children:i.jsxs("a",{id:`fnref-${e.identifier}`,className:"text-[#316dce] underline visited:text-[#6b46c1] dark:text-[#3182ce] dark:visited:text-[#805ad5]",href:`#fn-${e.identifier}`,children:["[",e.identifier,"]"]})}),ey=({nodes:e,theme:t="light"})=>e.length===0?null:i.jsx("section",{className:"border-[#171717] border-t pt-4 dark:border-[#464646]",children:i.jsx("ol",{className:"pl-6 text-[#686868] text-sm dark:text-[#a4a5a9]",children:e.map((n,r)=>i.jsx("li",{id:`fn-${n.identifier}`,className:r===0?"":"mt-4",children:i.jsx(Ce,{nodes:n.children,theme:t})},`mdast-node-fn-${n.identifier}-${r}`))})}),ri=({node:e})=>i.jsx("a",{href:e.url,className:"text-[#316dce] underline visited:text-[#6b46c1] dark:text-[#3182ce] dark:visited:text-[#805ad5]",children:"↩"}),ty=e=>e.replace(/<rt\b[^>]*>[\s\S]*?<\/rt>/gi,"").replace(/<rp\b[^>]*>[\s\S]*?<\/rp>/gi,"").replace(/<[^>]+>/g,"").replace(/&nbsp;/gi," ").replace(/&amp;/gi,"&").replace(/&lt;/gi,"<").replace(/&gt;/gi,">").replace(/&quot;/gi,'"').replace(/&#39;/gi,"'").replace(/&#(\d+);/g,(o,s)=>{const a=Number(s);return Number.isFinite(a)?String.fromCodePoint(a):""}).replace(/&#x([0-9a-f]+);/gi,(o,s)=>{const a=Number.parseInt(s,16);return Number.isFinite(a)?String.fromCodePoint(a):""}).replace(/\s+/g," ").trim(),oi=e=>{const t=n=>{if(!n||typeof n!="object")return"";if("type"in n&&n.type==="html"){const r=n.value;return typeof r=="string"?ty(r):""}if("value"in n){const r=n.value;if(typeof r=="string")return r}return"children"in n&&Array.isArray(n.children)?n.children.map(r=>t(r)).join(""):""};return e.map(n=>t(n)).join("").replace(/\s+/g," ").trim()},ny=e=>{switch(e){case 1:return"border-b-2 border-gray-300 pb-2 text-3xl font-bold dark:border-gray-600 dark:text-gray-100";case 2:return"border-b border-gray-300 pb-2 text-2xl font-semibold dark:border-gray-600 dark:text-gray-200";case 3:return"text-xl font-semibold dark:text-gray-300";default:return"text-lg font-medium dark:text-gray-400"}},si=({node:e})=>{const t=new Oi,n=`h${e.depth}`,r=e.data?.hProperties?.id,o=t.slug(oi(e.children));return i.jsx(n,{id:r||o,className:ny(e.depth),children:i.jsx(Ce,{nodes:e.children})})},ry=e=>Object.fromEntries(Object.entries(e).filter(([,t])=>t!==!1).map(([t,n])=>[t,n===!0?"":String(n)])),oy=({node:e,theme:t,iFrameAllowedDomains:n=[]})=>{const r=i.jsx(Ce,{nodes:e.children,theme:t,iFrameAllowedDomains:n}),o=Wn(e.data.tagName,ry(e.data.properties),{parentName:null,iFrameAllowedDomains:n,allowlist:"document"});if(o.action==="unwrap")return r;if(o.action!=="keep"&&o.action!=="placeholder")return null;const s=e.data.tagName.toLowerCase();return i.jsx(s,{...Q.attributesToProps(o.attributes,e.data.tagName.toLowerCase()),children:r})},sy=/^\s*<(address|article|aside|blockquote|details|dialog|dd|div|dl|dt|fieldset|figcaption|figure|footer|form|h[1-6]|header|hgroup|hr|li|main|nav|ol|p|pre|section|table|ul)/i,ay=({node:e,iFrameAllowedDomains:t=[]})=>{const n=Q.domToReact(on(e.value),qa({iFrameAllowedDomains:t,embedLabels:Ii,frameSandbox:kt.DEFAULT_FRAME_SANDBOX,allowlistContext:{allowlist:"document"}}));return Array.isArray(n)&&n.length===0?null:sy.test(e.value)?i.jsx("div",{children:n}):i.jsx("span",{children:n})},ai=({node:e})=>{if(!e.url||e.url.trim()===""||!mn(e.url))return null;const t=e.title??"",n=e.data?.hProperties?.width,r=e.data?.hProperties?.height;return i.jsxs("span",{style:{width:n,height:r},className:"mt-4 mb-4 inline-block w-fit max-w-full",children:[i.jsx("img",{src:e.url,alt:e.alt??"",className:"mx-auto h-full w-full",width:n,height:r}),t&&i.jsx("em",{className:"block text-center text-gray-400 text-xs",children:t})]})},ii=({node:e})=>i.jsx("code",{className:"rounded-md bg-gray-200 px-1.5 py-1 font-mono text-gray-800 text-sm dark:bg-gray-700 dark:text-gray-200",children:e.value}),iy=({node:e})=>{const t=za(e.value,!1),n="rounded-md px-1.5 py-1 font-mono text-gray-800 text-sm dark:text-gray-200";return t.kind==="rendered"?i.jsx("span",{className:n,dangerouslySetInnerHTML:t.innerHtml}):i.jsx("span",{className:n,children:t.message})},ly=new RegExp(`<(?:${[...Hr].join("|")})(?=[\\s/>])`,"i"),li=e=>e.some(t=>t.type==="image"||t.type==="imageReference"||t.type==="html"&&typeof t.value=="string"&&ly.test(t.value)||t.children!==void 0&&li(t.children)),ci=({node:e})=>{const t=mn(e.url)?e.url:void 0,n=t!==void 0&&qr(t);return i.jsx("a",{className:Vs(void 0,li(e.children)),href:t,target:n?"_blank":void 0,rel:n?"noreferrer":void 0,children:i.jsx(Ce,{nodes:e.children})})},di=({node:e})=>e.children.length===1&&e.children[0].type==="paragraph"?i.jsx("li",{children:i.jsx(Ce,{nodes:e.children[0].children})}):i.jsx("li",{children:i.jsx(Ce,{nodes:e.children})}),ui=({node:e})=>{const t=e.ordered?"ol":"ul";return i.jsx(t,{children:i.jsx(Ce,{nodes:e.children})})},cy=({node:e})=>i.jsx("mark",{children:i.jsx(Ce,{nodes:e.children})}),fi=({node:e})=>i.jsx("p",{children:i.jsx(Ce,{nodes:e.children})}),mi=({node:e})=>i.jsx("strong",{children:i.jsx(Ce,{nodes:e.children})}),dy=({node:e})=>i.jsx("sub",{children:i.jsx(Ce,{nodes:e.children})}),uy=({node:e})=>i.jsx("sup",{children:i.jsx(Ce,{nodes:e.children})}),_s=e=>{const t=e.data?.hProperties;return{merged:t?.merged??!1,colSpan:t?.colSpan,rowSpan:t?.rowSpan,textAlign:t?.textAlign}},hi=({node:e})=>{const[t,...n]=e.children;return i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full border-collapse border-none",children:[i.jsx("thead",{className:"bg-gray-100 dark:bg-gray-800",children:i.jsx("tr",{children:t.children.map((r,o)=>{const{merged:s,colSpan:a,rowSpan:l,textAlign:c}=_s(r);return s?null:i.jsx("th",{colSpan:a,rowSpan:l,style:{textAlign:c??e.align?.[o]??void 0},className:"border border-gray-300 px-4 py-2 text-left font-semibold dark:border-gray-600 dark:text-gray-200",children:i.jsx(Ce,{nodes:r.children})},`mdast-table-node-${e.type}-${o}`)})})}),i.jsx("tbody",{children:n.map((r,o)=>i.jsx("tr",{className:"border-gray-200 border-t bg-white dark:border-gray-700 dark:bg-gray-900",children:r.children.map((s,a)=>{const{merged:l,colSpan:c,rowSpan:u,textAlign:f}=_s(s);return l?null:i.jsx("td",{colSpan:c,rowSpan:u,style:{textAlign:f??e.align?.[a]??void 0},className:"border border-gray-300 px-4 py-2 dark:border-gray-600 dark:text-gray-300",children:i.jsx(Ce,{nodes:s.children})},`mdast-table-node-${e.type}-${a}`)})},`mdast-table-node-${e.type}-${o}`))})]})})},pi=({node:e})=>i.jsx(i.Fragment,{children:e.value}),gi=()=>i.jsx("hr",{className:"border-gray-300 dark:border-gray-600"}),yi=({node:e})=>{const t=e.data?.title||"";return i.jsxs("details",{className:"markdown-details",children:[i.jsx("summary",{children:t}),i.jsx("div",{className:"markdown-details-content",children:i.jsx(Ce,{nodes:e.children})})]})},xi=({node:e})=>{const n=["message",e.data?.messageType||"message"].filter(Boolean).join(" ");return i.jsxs("aside",{className:n,children:[i.jsx("span",{className:"message-symbol",style:{userSelect:"none"},children:"!"}),i.jsx("div",{className:"message-content",children:i.jsx(Ce,{nodes:e.children})})]})},Ce=({nodes:e,theme:t="light",iFrameAllowedDomains:n=[]})=>e.map((r,o)=>{switch(r.type){case"blockquote":return i.jsx(bi,{node:r},`mdast-node-${r.type}-${o}`);case"break":return i.jsx("br",{},`mdast-node-${r.type}-${o}`);case"code":return i.jsx(ao,{node:r,theme:t},`mdast-node-${r.type}-${o}`);case"delete":return i.jsx(ei,{node:r},`mdast-node-${r.type}-${o}`);case"details":return i.jsx(yi,{node:r},`mdast-node-${r.type}-${o}`);case"emphasis":return i.jsx(ti,{node:r},`mdast-node-${r.type}-${o}`);case"footnoteReference":return i.jsx(ni,{node:r},`mdast-node-${r.type}-${o}`);case"footnoteDefinition":return null;case"footnote-back-link":return i.jsx(ri,{node:r},`mdast-node-${r.type}-${o}`);case"heading":return i.jsx(si,{node:r},`mdast-node-${r.type}-${o}`);case"html":return i.jsx(ay,{node:r,iFrameAllowedDomains:n},`mdast-node-${r.type}-${o}`);case"html-block-container":{const s=r,a=`mdast-node-${s.type}-${s.position?.start?.offset??"na"}-${s.position?.end?.offset??"na"}`;return i.jsx(oy,{node:s,theme:t,iFrameAllowedDomains:n},a)}case"image":return i.jsx(ai,{node:r},`mdast-node-${r.type}-${o}`);case"inlineCode":return i.jsx(ii,{node:r},`mdast-node-${r.type}-${o}`);case"inlineMath":return i.jsx(iy,{node:r},`mdast-node-${r.type}-${o}`);case"link":return i.jsx(ci,{node:r},`mdast-node-${r.type}-${o}`);case"listItem":return i.jsx(di,{node:r},`mdast-node-${r.type}-${o}`);case"list":return i.jsx(ui,{node:r},`mdast-node-${r.type}-${o}`);case"mark":return i.jsx(cy,{node:r},`mdast-node-${r.type}-${o}`);case"math":return i.jsx(sp,{node:r},`mdast-node-${r.type}-${o}`);case"message":return i.jsx(xi,{node:r},`mdast-node-${r.type}-${o}`);case"paragraph":return i.jsx(fi,{node:r},`mdast-node-${r.type}-${o}`);case"strong":return i.jsx(mi,{node:r},`mdast-node-${r.type}-${o}`);case"subscript":return i.jsx(dy,{node:r},`mdast-node-${r.type}-${o}`);case"superscript":return i.jsx(uy,{node:r},`mdast-node-${r.type}-${o}`);case"table":return i.jsx(hi,{node:r},`mdast-node-${r.type}-${o}`);case"text":return i.jsx(pi,{node:r},`mdast-node-${r.type}-${o}`);case"thematicBreak":return i.jsx(gi,{},`mdast-node-${r.type}-${o}`);case"yaml":return null;default:{if(process.env.NODE_ENV==="development")return i.jsxs("div",{children:[i.jsxs("p",{style:{color:"red"},children:["Unknown node type: ",r.type]}),i.jsx("pre",{children:JSON.stringify(r,null,2)})]},`mdast-node-${r.type}-${o}`);throw new Error(`Unknown node type: ${r.type}`)}}}),bi=({node:e})=>i.jsx("blockquote",{className:"my-4 border-gray-300 border-l-4 bg-gray-50 p-4 italic dark:border-gray-500 dark:bg-gray-800 dark:text-gray-300",children:i.jsx(Ce,{nodes:e.children})}),fy=/\s*\{#(.+?)\}\s*$/,my=()=>e=>{Qe.visit(e,"heading",t=>{if(t.children.length===0)return;const n=t.children[t.children.length-1];if(n?.type!=="text")return;const r=n,o=r.value.match(fy);if(o){const s=o[1];t.data||(t.data={});const a=t.data,l=a.hProperties||{};l.id=s,a.hProperties=l,r.value=r.value.substring(0,o.index).trimEnd(),r.value===""&&t.children.pop()}})},hy=()=>e=>{Qe.visit(e,"footnoteDefinition",t=>{Qe.visit(t,"paragraph",n=>{n.children.push({type:"footnote-back-link",url:`#fnref-${t.identifier}`})})})},py=()=>e=>{Qe.visit(e,"html",(t,n,r)=>{if(typeof n!="number"||!r)return;const s=t.value.trim().match(/^<a\s+href="([^"]+)"[^>]*>(.*?)<\/a>$/i);if(s){const[,a,l]=s,c={type:"link",url:a,children:[{type:"text",value:l}]};r.children.splice(n,1,c)}})},gy=()=>e=>{const t=n=>{const r=n.children;if(!r)return;let o=0;for(;o<r.length;){const s=r[o];if(s.type==="html"&&s.value.startsWith("<")&&!s.value.startsWith("</")&&s.value.match(/<([a-zA-Z0-9]+)/)){let l="",c=0;const u=[];let f=!1;for(let m=o;m<r.length;m++){const h=r[m];if(h.type==="html"){l+=h.value;const w=h.value.match(/<\/?([a-zA-Z0-9]+)/g)||[];for(const y of w){const p=y.match(/<\/?([a-zA-Z0-9]+)/);if(!p)continue;const x=p[1];y.startsWith("</")?u.length>0&&u[u.length-1]===x&&u.pop():y.startsWith("<")&&u.push(x)}}else if(h.type==="text")l+=h.value;else{u.length===0&&(f=!0);break}if(c++,u.length===0){f=!0;break}}f&&r.splice(o,c,{type:"html",value:l})}o++}};Qe.visit(e,"paragraph",t),Qe.visit(e,"tableCell",t),Qe.visit(e,"heading",t),Qe.visit(e,"emphasis",t),Qe.visit(e,"strong",t),Qe.visit(e,"delete",t)},Os=/\s*=\s*(\d+)(w|h|x|y)\s*/g,yy=()=>e=>{Qe.visit(e,"image",t=>{const n=c=>{if(!c)return{updatedText:c,matches:[]};const u=[...c.matchAll(Os)];return{updatedText:c.replaceAll(Os,"").trim(),matches:u}},{updatedText:r,matches:o}=n(t.alt);t.alt=r;const{updatedText:s,matches:a}=n(t.title);t.title=s||null;const l=[...o,...a];if(l.length>0){t.data||(t.data={}),t.data.hProperties||(t.data.hProperties={});for(const c of l){const u=Number.parseInt(c[1],10),f=c[2];f==="w"||f==="x"?t.data.hProperties.width=u:(f==="h"||f==="y")&&(t.data.hProperties.height=u)}}})},xy=()=>e=>{Qe.visit(e,(t,n,r)=>{r&&Object.defineProperty(t,"parent",{value:r,writable:!0,configurable:!0,enumerable:!1})})},As=/^:::(message|details)\s*(.*)/,by=()=>e=>{function t(n){const r=[];let o=0;for(;o<n.length;){const s=n[o];if(s.type==="paragraph"&&s.children[0]?.type==="text"&&s.children[0].value.trim().startsWith(":::")){const c=s.children[0].value.trim().match(As);if(c){const u=o;let f=-1,m=1;const h=s.children.at(-1);if(s.children.length>1&&h?.type==="text"&&h.value.trim()===":::")f=u;else for(let w=u+1;w<n.length;w++){const y=n[w];if(y.type==="paragraph"&&y.children[0]?.type==="text"){const p=y.children[0].value.trim();As.test(p)?m++:p===":::"&&m--}if(m===0){f=w;break}}if(f!==-1){const w=c[1],y=c[2];let p;if(f===u){const T=s.children.slice(1,-1);T[0]?.type==="break"&&T.shift(),T.at(-1)?.type==="break"&&T.pop(),p=T.length>0?[{type:"paragraph",children:T}]:[]}else{const T=s.children.slice(1);T[0]?.type==="break"&&T.shift();const R={type:"paragraph",children:T},k=n[f].children.slice(0,-1);k.at(-1)?.type==="break"&&k.pop();const A={type:"paragraph",children:k},P=n.slice(u+1,f);p=[R,...P,A].filter(L=>!(L.type==="paragraph"&&L.children.length===0))}const x=t(p);let E;if(w==="message"?E={type:"message",data:{messageType:y.trim()},children:x}:w==="details"&&(E={type:"details",data:{title:y.trim()},children:x}),E){r.push(E),o=f+1;continue}}}}const a={...s};"children"in a&&Array.isArray(a.children)&&(a.type==="blockquote"||a.type==="footnoteDefinition"||a.type==="message"||a.type==="details"?a.children=t(a.children):a.type==="list"&&(a.children=a.children.map(l=>({...l,children:t(l.children)})))),r.push(a),o++}return r}e.children=t(e.children)},wy=e=>{const t=[];return Qe.visit(e,"heading",n=>{const r=oi(n.children),o=n.data?.hProperties?.id;o&&r&&t.push({depth:n.depth,text:r,id:o})}),t};exports.BlockquoteNode=bi;exports.CodeNode=ao;exports.DEFAULT_CODE_BLOCK_LABELS=Ci;exports.DEFAULT_DISPLAY_MATH_LABELS=Li;exports.DEFAULT_MARKDOWN_EMBED_LABELS=Mi;exports.DEFAULT_MARKDOWN_VIEWER_LABELS=wg;exports.DEFAULT_MERMAID_DIAGRAM_LABELS=Ff;exports.DEFAULT_MERMAID_INTERACTION=ka;exports.DEFAULT_PAN_ZOOM_MODIFIER=Ir;exports.DEFAULT_SVG_IMAGE_LABELS=Ep;exports.DeleteNode=ei;exports.EmphasisNode=ti;exports.FootnoteBackLinkNode=ri;exports.FootnoteReferenceNode=ni;exports.FootnotesSection=ey;exports.HeadingNode=si;exports.HostedScrollArea=Ms;exports.ImageNode=ai;exports.InlineCodeNode=ii;exports.LinkNode=ci;exports.ListItemNode=di;exports.ListNode=ui;exports.MERMAID_DRAWABLE_TYPES=fa;exports.MarkdownRenderer=Ga;exports.MarkdownViewer=Qg;exports.MermaidDiagram=ro;exports.NodesRenderer=Ce;exports.ParagraphNode=fi;exports.SpreadsheetBlock=so;exports.StrongNode=mi;exports.TableNode=hi;exports.TableOfContents=Ka;exports.TextNode=pi;exports.ThematicBreakNode=gi;exports.ZennDetailsNode=yi;exports.ZennMessageNode=xi;exports.createMermaidDrawer=Bu;exports.extractHeadings=wy;exports.remarkCustomHeadingId=my;exports.remarkFootnoteBackLink=hy;exports.remarkHtmlAnchorToLink=py;exports.remarkHtmlInHtml=gy;exports.remarkImageSize=yy;exports.remarkParentNode=xy;exports.remarkZennMessage=by;exports.useMarkdownToolbarState=Qa;