@aiquants/markdown 13.0.0 → 13.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +282 -18
  2. package/dist/components/MarkdownRenderer.d.ts +6 -2
  3. package/dist/components/MermaidDiagram.d.ts +20 -0
  4. package/dist/components/blockNotice.d.ts +15 -0
  5. package/dist/components/fileSave.d.ts +1 -0
  6. package/dist/components/mermaidAccessibility.d.ts +11 -0
  7. package/dist/components/mermaidExport.d.ts +24 -0
  8. package/dist/components/mermaidLabels.d.ts +84 -0
  9. package/dist/components/spreadsheetClipboard.d.ts +1 -1
  10. package/dist/components/svgRaster.d.ts +2 -2
  11. package/dist/components/viewerLabels.d.ts +3 -2
  12. package/dist/extractHeadings-BfYlTVvN.js +6773 -0
  13. package/dist/extractHeadings-CZPJi4gM.cjs +12 -0
  14. package/dist/index.cjs +1 -1
  15. package/dist/index.client.cjs +1 -1
  16. package/dist/index.client.d.ts +4 -1
  17. package/dist/index.client.js +50 -48
  18. package/dist/index.js +50 -48
  19. package/dist/mermaidFrame/NOTICES.md +1 -1
  20. package/dist/mermaidFrame/browserPaintView.d.ts +3 -0
  21. package/dist/mermaidFrame/cssCleaner.d.ts +16 -0
  22. package/dist/mermaidFrame/diagramPalette.d.ts +24 -0
  23. package/dist/mermaidFrame/diagramTheme.d.ts +7 -0
  24. package/dist/mermaidFrame/drawableTypes.d.ts +6 -0
  25. package/dist/mermaidFrame/drawer.d.ts +15 -2
  26. package/dist/mermaidFrame/frame.js +379 -378
  27. package/dist/mermaidFrame/insertion.d.ts +11 -0
  28. package/dist/mermaidFrame/namespaces.d.ts +3 -0
  29. package/dist/mermaidFrame/paintCheck.d.ts +2 -0
  30. package/dist/mermaidFrame/paintContract.d.ts +3 -0
  31. package/dist/mermaidFrame/paintDiagram.d.ts +3 -0
  32. package/dist/mermaidFrame/paintMap.d.ts +103 -0
  33. package/dist/mermaidFrame/paintRules.d.ts +18 -0
  34. package/dist/mermaidFrame/protocol.d.ts +5 -0
  35. package/dist/mermaidFrame/serve.d.ts +10 -5
  36. package/dist/styles/markdown.css +1 -1
  37. package/dist/styles/markdown.standalone.css +1 -1
  38. package/package.json +7 -5
  39. package/dist/extractHeadings-BAhmauKo.js +0 -5296
  40. package/dist/extractHeadings-qiJXegCx.cjs +0 -11
@@ -0,0 +1,12 @@
1
+ "use strict";var ii=Object.create;var to=Object.defineProperty;var li=Object.getOwnPropertyDescriptor;var ci=Object.getOwnPropertyNames;var di=Object.getPrototypeOf,ui=Object.prototype.hasOwnProperty;var fi=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ci(t))!ui.call(e,o)&&o!==n&&to(e,o,{get:()=>t[o],enumerable:!(r=li(t,o))||r.enumerable});return e};var mi=(e,t,n)=>(n=e!=null?ii(di(e)):{},fi(t||!e||!e.__esModule?to(n,"default",{value:e,enumerable:!0}):n,e));const d=require("react"),rt=require("./linkCards-BikpIncf.cjs"),vt=require("./providers-Cx0FuVQU.cjs"),Ye=require("./viewer-settings.cjs"),Xe=require("./embeds-B4g6w7Tf.cjs"),re=require("html-react-parser"),le=require("./code-blocks-CTESwslp.cjs"),It=require("./source-lines.cjs"),hr=require("./simple-logger-9yf7ypyB.cjs"),pr=require("shiki"),hi=require("dompurify"),qe=require("@aiquants/spreadsheet/view"),jn=require("@aiquants/spreadsheet/tsv"),pi=require("github-slugger"),gi=require("katex"),et=require("unist-util-visit"),yi=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})}}},it=(e,t,n)=>{const r=yi(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)},zt=e=>{const t={};for(const n of Object.keys(e))t[n]=e[n].text;return Object.freeze(t)},Mn=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"}}),xi=zt(Mn),rn=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"}}),bi=zt(rn),wi=it(rn,void 0,void 0),In=Object.freeze({embeddedVideo:{text:"embedded video",lang:"en"},embeddedPost:{text:"embedded post",lang:"en"},embeddedFrame:{text:"Embedded content",lang:"en"}}),Ei=zt(In),bs=(e,t)=>it(In,e,t),Si=bs(void 0,void 0);var fn={exports:{}},Ut={};var no;function vi(){if(no)return Ut;no=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 Ut.Fragment=t,Ut.jsx=n,Ut.jsxs=n,Ut}var Ht={};var ro;function ki(){return ro||(ro=1,process.env.NODE_ENV!=="production"&&(function(){function e(g){if(g==null)return null;if(typeof g=="function")return g.$$typeof===X?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 B:return"SuspenseList";case I: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 O:return(g._context.displayName||"Context")+".Consumer";case R:var S=g.render;return g=g.displayName,g||(g=S.displayName||S.name||"",g=g!==""?"ForwardRef("+g+")":"ForwardRef"),g;case M:return S=g.displayName||null,S!==null?S:e(g.type)||"Memo";case j:S=g._payload,g=g._init;try{return e(g(S))}catch{}}return null}function t(g){return""+g}function n(g){try{t(g);var S=!1}catch{S=!0}if(S){S=console;var v=S.error,C=typeof Symbol=="function"&&Symbol.toStringTag&&g[Symbol.toStringTag]||g.constructor.name||"Object";return v.call(S,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",C),t(g)}}function r(g){if(g===x)return"<>";if(typeof g=="object"&&g!==null&&g.$$typeof===j)return"<...>";try{var S=e(g);return S?"<"+S+">":"<...>"}catch{return"<...>"}}function o(){var g=P.A;return g===null?null:g.getOwner()}function s(){return Error("react-stack-top-frame")}function a(g){if(K.call(g,"key")){var S=Object.getOwnPropertyDescriptor(g,"key").get;if(S&&S.isReactWarning)return!1}return g.key!==void 0}function l(g,S){function v(){Z||(Z=!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)",S))}v.isReactWarning=!0,Object.defineProperty(g,"key",{get:v,configurable:!0})}function c(){var g=e(this.type);return de[g]||(de[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 f(g,S,v,C,D,J){var q=v.ref;return g={$$typeof:y,type:g,key:S,props:v,_owner:C},(q!==void 0?q: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:J}),Object.freeze&&(Object.freeze(g.props),Object.freeze(g)),g}function u(g,S,v,C,D,J){var q=S.children;if(q!==void 0)if(C)if(ce(q)){for(C=0;C<q.length;C++)h(q[C]);Object.freeze&&Object.freeze(q)}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 h(q);if(K.call(S,"key")){q=e(g);var fe=Object.keys(S).filter(function(xe){return xe!=="key"});C=0<fe.length?"{key: someKey, "+fe.join(": ..., ")+": ...}":"{key: someKey}",z[q+C]||(fe=0<fe.length?"{"+fe.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} />`,C,q,fe,q),z[q+C]=!0)}if(q=null,v!==void 0&&(n(v),q=""+v),a(S)&&(n(S.key),q=""+S.key),"key"in S){v={};for(var we in S)we!=="key"&&(v[we]=S[we])}else v=S;return q&&l(v,typeof g=="function"?g.displayName||g.name||"Unknown":g),f(g,q,v,o(),D,J)}function h(g){m(g)?g._store&&(g._store.validated=1):typeof g=="object"&&g!==null&&g.$$typeof===j&&(g._payload.status==="fulfilled"?m(g._payload.value)&&g._payload.value._store&&(g._payload.value._store.validated=1):g._store&&(g._store.validated=1))}function m(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"),O=Symbol.for("react.consumer"),b=Symbol.for("react.context"),R=Symbol.for("react.forward_ref"),A=Symbol.for("react.suspense"),B=Symbol.for("react.suspense_list"),M=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),I=Symbol.for("react.activity"),X=Symbol.for("react.client.reference"),P=w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,K=Object.prototype.hasOwnProperty,ce=Array.isArray,pe=console.createTask?console.createTask:function(){return null};w={react_stack_bottom_frame:function(g){return g()}};var Z,de={},Ce=w.react_stack_bottom_frame.bind(w,s)(),_=pe(r(s)),z={};Ht.Fragment=x,Ht.jsx=function(g,S,v){var C=1e4>P.recentlyCreatedOwnerStacks++;return u(g,S,v,!1,C?Error("react-stack-top-frame"):Ce,C?pe(r(g)):_)},Ht.jsxs=function(g,S,v){var C=1e4>P.recentlyCreatedOwnerStacks++;return u(g,S,v,!0,C?Error("react-stack-top-frame"):Ce,C?pe(r(g)):_)}})()),Ht}var oo;function Ti(){return oo||(oo=1,process.env.NODE_ENV==="production"?fn.exports=vi():fn.exports=ki()),fn.exports}var i=Ti();const Ri=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(" ")),_i=/^(?:\d+(?:\.\d+)?|\.\d+)(?:[Ee][+-]?\d+)?([A-Za-z]+)$/u,Oi=/^var\([\t\n\f\r ]*--[A-Za-z0-9_-]+[\t\n\f\r ]*\)$/u,so='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)")',Ai=e=>{const t=_i.exec(e)?.[1];return t===void 0?Oi.test(e):Ri.has(t.toLowerCase())},Cr=(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(!Ai(n))throw new RangeError(`[@aiquants/markdown] ${e} as a string must be ${so}; got ${JSON.stringify(t)}`);return n}throw new RangeError(`[@aiquants/markdown] ${e} must be a finite number >= 0 or a string that is ${so}; got ${String(t)}`)},ws=.01,Yt=e=>{const t=Number.parseFloat(e);return Number.isFinite(t)?t:0},Es=e=>{const t=e.getBoundingClientRect().height;return t>0&&e.offsetHeight>0?t/e.offsetHeight:1},Ni=e=>Math.max(0,Math.ceil(e-ws)),Ci=1/256,Li=e=>e>ws?e+Ci:0,ao=Object.freeze({display:"flex",flexDirection:"row",inlineSize:"100%",blockSize:"100%",minInlineSize:0,minBlockSize:0}),ji=Object.freeze({flex:"1 1 0%",minInlineSize:0,minBlockSize:0,overflow:"clip"}),io=Object.freeze({display:"flex",flex:"none",minBlockSize:0}),Mi=Object.freeze({position:"absolute",insetBlock:0,insetInline:0,overflowY:"scroll",visibility:"hidden",pointerEvents:"none"}),Ii=Object.freeze({scrollbarWidth:"none"}),vn="data-aqmd-native-scrollbars-hidden",Di=Object.freeze({[vn]:"true"}),lo=Object.freeze({scroller:null,barInlineSize:0,nativeBarInlineSize:0}),co=(e,t,n)=>{const r=getComputedStyle(e),o=Yt(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-Yt(r.borderLeftWidth)-Yt(r.borderRightWidth);return{barInlineSize:n.getBoundingClientRect().width/a,nativeBarInlineSize:Li(l)}},Pi=(e,t,n,r)=>{const o=e.style.scrollbarWidth,s=e.getAttribute(vn);if(o===r&&s===null)return co(e,t,n);e.style.scrollbarWidth=r,e.removeAttribute(vn);try{return co(e,t,n)}finally{e.style.scrollbarWidth=o,s!==null&&e.setAttribute(vn,s)}},zi=(e,t,n,r,o,s)=>{const[a,l]=d.useState(lo),c=d.useRef(o),f=d.useRef(0);return d.useLayoutEffect(()=>{c.current=o}),d.useLayoutEffect(()=>{const u=x=>{f.current!==x&&(f.current=x,c.current?.(x))},h=t.current,m=n.current,w=r.current;if(!e||h===null||m===null||w===null){l(lo),u(0);return}const y=()=>{const{barInlineSize:x,nativeBarInlineSize:E}=Pi(h,m,w,s);l(T=>T.scroller===h&&T.barInlineSize===x&&T.nativeBarInlineSize===E?T:Object.freeze({scroller:h,barInlineSize:x,nativeBarInlineSize:E})),u(x)};y();const p=new ResizeObserver(y);return p.observe(h),p.observe(m),p.observe(w),window.addEventListener("resize",y),()=>{p.disconnect(),window.removeEventListener("resize",y)}},[e,t,n,r,s]),a},$i=(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 Ss({scrollerProps:e,scrollerRef:t,children:n,renderScrollBar:r,rowClassName:o,rowStyle:s,onBarInlineSizeChange:a,barInlineSize:l}){const c=d.useRef(null),f=d.useRef(null),u=d.useRef(null),h=r!==void 0,m=l===void 0?null:Cr("barInlineSize",l),w=e.style?.scrollbarWidth??"",y=zi(h,c,f,u,a,w),p=d.useCallback(O=>{c.current=O;const b=$i(t,O);return()=>{c.current=null,b()}},[t]),x=h?{...e.style,position:"relative",boxSizing:"border-box",overflowY:"scroll",width:`calc(100% + ${y.nativeBarInlineSize}px)`,...y.nativeBarInlineSize===0?Ii:void 0}:e.style,E=h&&y.nativeBarInlineSize===0,T=i.jsxs("div",{...e,...E?Di:void 0,ref:p,style:x,children:[n,h&&i.jsx("span",{ref:f,"data-aqmd-scroll-bar-probe":!0,"aria-hidden":"true",style:Mi})]});return h?i.jsxs("div",{"data-aqmd-scroll-row":!0,className:o,style:s===void 0?ao:{...ao,...s},children:[i.jsx("div",{"data-aqmd-scroll-clip":!0,style:ji,children:T}),i.jsx("div",{ref:u,"data-aqmd-scroll-bar":!0,style:m===null?io:{...io,inlineSize:m},children:y.scroller!==null&&r(y.scroller)})]}):T}const Bi=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Fi=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,r)=>r?r.toUpperCase():n.toLowerCase()),uo=e=>{const t=Fi(e);return t.charAt(0).toUpperCase()+t.slice(1)},vs=(...e)=>e.filter((t,n,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===n).join(" ").trim(),qi=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};var Ui={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 Hi=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,...Ui,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:vs("lucide",o),...!s&&!qi(l)&&{"aria-hidden":"true"},...l},[...a.map(([f,u])=>d.createElement(f,u)),...Array.isArray(s)?s:[s]]));const se=(e,t)=>{const n=d.forwardRef(({className:r,...o},s)=>d.createElement(Hi,{ref:s,iconNode:t,className:vs(`lucide-${Bi(uo(e))}`,`lucide-${e}`,r),...o}));return n.displayName=uo(e),n};const Wi=[["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"}]],Gi=se("image-off",Wi);class ks 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 Ts=Object.freeze({blockFailed:{text:"This block could not be shown.",lang:"en"}}),Vi=1024,Jt=(e,t)=>e.fingerprint===t.fingerprint&&e.content===t.content,Ki=(e,t)=>{let n=0;for(;n<e.length&&n<t.length&&Jt(e[n],t[n]);)n+=1;let r=0;for(;r<e.length-n&&r<t.length-n&&Jt(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=Yi(e,t,n,e.length-r,t.length-r);return[...o,...a,...s]},Yi=(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 f=l.length,u=c.length;if(f===0||u===0)return[];const h=(b,R)=>Jt(e[l[b]],t[c[R]]),m=(b,R)=>e[l[b]].fingerprint===t[c[R]].fingerprint,w=(b,R)=>{let A=b;for(;A<f&&A+R<u&&h(A,A+R);)A+=1;return A},y=[Int32Array.of(w(0,0))],p=[Uint8Array.of(Un)],x=u-f;let E=0;for(;!(x>=-E&&x<=E&&y[E][x+E]===f);){if(E+=1,E>Vi)return[];const b=y[E-1],R=M=>M>=-(E-1)&&M<=E-1?b[M+E-1]:-1,A=new Int32Array(2*E+1).fill(-1),B=new Uint8Array(2*E+1);for(let M=-E;M<=E;M+=1){if(M<-f||M>u)continue;let j=-1,I=Un;const X=R(M);X!==-1&&X<f&&X+M<u&&m(X,X+M)&&(j=X+1,I=fo);const P=R(M+1);P!==-1&&P+1<=f&&P+1>j&&(j=P+1,I=mo);const K=R(M-1);K!==-1&&K+M<=u&&K>j&&(j=K,I=Hn),j!==-1&&(A[M+E]=w(j,M),B[M+E]=I)}y.push(A),p.push(B)}const T=[];let O=x;for(let b=E;b>=0;b-=1){const R=y[b][O+b],A=p[b][O+b],B=A===mo?O+1:A===Hn?O-1:O,M=A===Un?0:y[b-1][B+b-1]+(A===Hn?0:1);for(let j=R-1;j>=M;j-=1)T.push([l[j],c[j+O]]);A===fo&&T.push([l[M-1],c[M-1+O]]),O=B}return T.reverse()},Un=0,fo=1,mo=2,Hn=3,Rs=(e,t,n)=>{const r=e.map(()=>null),o=new Set,s=[];for(const[f,u]of Ki(t,e))n.contentOnly&&!Jt(t[f],e[u])||(r[u]=t[f].key,o.add(f),s.push([f,u]));const a=new Map;for(const[f,u]of t.entries()){if(o.has(f))continue;const h=a.get(u.fingerprint);h===void 0?a.set(u.fingerprint,[f]):h.push(f)}const l=f=>{for(const[u,h]of e.entries()){if(r[u]!==null)continue;const m=a.get(h.fingerprint),w=m===void 0?-1:m.findIndex(y=>f(h,t[y]));if(m!==void 0&&w!==-1){const[y]=m.splice(w,1);r[u]=t[y].key,o.add(y)}}};if(l(Jt),n.contentOnly||l(()=>!0),n.inherit&&!n.contentOnly){let f=-1;for(const[u,h]of e.entries()){for(;f+1<s.length&&s[f+1][1]<u;)f+=1;if(r[u]!==null)continue;const[m,w]=f===-1?[-1,-1]:s[f],y=m+(u-w);y<t.length&&!o.has(y)&&t[y].root===h.root&&(r[u]=t[y].key,o.add(y))}}const c=new Set([...t.map(f=>f.key),...r.filter(f=>f!==null)]);return e.map((f,u)=>{let h=r[u];if(h===null){let m=0;for(;c.has(`${f.fingerprint}.${m}`);)m+=1;h=`${f.fingerprint}.${m}`,c.add(h)}return{...f,key:h}})},Xi=/^[\t\n\f\r ]*$/u,Zi=(e,t)=>{if(t.length===0){if(!Xi.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)`)}},Ji=(e,t)=>t.map((n,r)=>e.slice(n,r+1<t.length?t[r+1]:e.length)),Qi=e=>{if(!Number.isSafeInteger(e))throw new RangeError(`MarkdownRenderer: blockKeyEpoch must be a safe integer, got ${e}`)};const el=[["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"}]],tl=se("building-2",el);const nl=[["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"}]],ho=se("globe",nl),rl=/^[a-z]{2,3}$/u,ol=e=>{const t=e.trim().split("-",1)[0]?.toLowerCase()??"";return rl.test(t)?t:null},_s=()=>()=>{},sl=e=>{const t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]}),()=>t.disconnect()},Os=()=>d.useSyncExternalStore(_s,()=>window.location.origin,()=>null),al=()=>d.useSyncExternalStore(_s,()=>window.location.href,()=>null),il=()=>d.useSyncExternalStore(sl,()=>ol(document.documentElement.lang),()=>null),ll=/^[1-9]\d{0,4}$/u,po=e=>e!==void 0&&ll.test(e.trim())?Number(e.trim()):null,cl=({embed:e,label:t,insideAnchor:n,children:r})=>{const o=Os(),s=new URL(e.src);if(o!==null&&s.origin!==o&&!n)return r;const a=po(e.attributes.width),l=po(e.attributes.height),c=a!==null&&l!==null?{width:"100%",maxWidth:`${a}px`,aspectRatio:`${a} / ${l}`}:void 0,f=e.attributes.title,u=f===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:u,children:`${f??t.text}: ${s.hostname}`}):i.jsx("a",{href:s.href,target:"_blank",rel:"noreferrer",lang:u,children:f??`${t.text}: ${s.hostname}`})})},As=(e,t)=>fetch(e,t),Ns=d.createContext(As),dl=e=>{const t=d.useRef(e);return d.useLayoutEffect(()=>{t.current=e},[e]),d.useCallback((n,r)=>(t.current??As)(n,r),[])},$t=e=>new Promise(t=>t(e())),Cs=({concurrency:e,capacity:t,timeoutMs:n})=>{for(const[u,h]of Object.entries({concurrency:e,capacity:t,timeoutMs:n}))if(!Number.isInteger(h)||h<=0)throw new RangeError(`[@aiquants/markdown] request queue ${u} must be a positive integer; got ${String(h)}`);const r=new Map,o=new Map,s=[];let a=0;const l=(u,h,m)=>{if(o.get(u)===h&&(o.delete(u),m!==null)){r.set(u,m);for(const w of r.keys()){if(r.size<=t)break;r.delete(w)}for(const w of h.subscriptions)w.listener(m)}},c=()=>{for(;a<e;){const u=s.shift();if(u===void 0)return;const h=o.get(u);if(h===void 0)continue;const m=new AbortController;h.controller=m,a+=1,$t(()=>h.start(AbortSignal.any([m.signal,AbortSignal.timeout(n)]))).then(w=>l(u,h,{ok:!0,value:w}),()=>l(u,h,m.signal.aborted?null:{ok:!1})).finally(()=>{a-=1,c()})}};return Object.freeze({subscribe:(u,h,m)=>{const w=r.get(u);if(w!==void 0)return r.delete(u),r.set(u,w),m(w),()=>{};let y=o.get(u);y===void 0&&(y={start:h,subscriptions:new Set,controller:null},o.set(u,y),s.push(u));const p=y,x={listener:m};return p.subscriptions.add(x),c(),()=>{p.subscriptions.delete(x),!(p.subscriptions.size>0||o.get(u)!==p)&&(o.delete(u),p.controller===null?s.splice(s.indexOf(u),1):p.controller.abort())}}})},ul=Cs({concurrency:2,capacity:256,timeoutMs:15e3}),fl="[data-aqmd-scroll-container]",ml=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=rt.linkCardSkipReasonOf(r.headers.get(rt.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=rt.linkCardMetadataOf(o);return s===null?{kind:"error",cause:`HTTP ${r.status}, not a JSON object`}:{kind:"card",metadata:s}},hl=e=>e.ok?e.value.kind==="card"?null:e.value.kind==="skip"?e.value.reason:e.value.cause:"network error",go=(e,t)=>e!==null&&new URL(e).hostname!==t?e:null,Wn=({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})]})]}),pl=({href:e,endpoint:t,size:n,fallback:r})=>{const o=al(),s=o===null?null:new URL(o).hostname,a=d.useContext(Ns),l=d.useRef(null),c=new URL(e),f=`${t}
7
+ ${c.href}`,[u,h]=d.useState(null);d.useEffect(()=>{const T=l.current;if(T===null||s===null)return;let O=null;const b=new IntersectionObserver(R=>{O!==null||!R.some(A=>A.isIntersecting)||(b.disconnect(),O=ul.subscribe(f,A=>ml(a,rt.linkCardRequestOf(t,new URL(e),window.location.href),A),A=>{h({key:f,outcome:A});const B=hl(A);B!==null&&hr.linkCardLogger.info(`No link card for ${e} (${B})`)}))},{root:T.closest(fl),rootMargin:"100% 0px"});return b.observe(T),()=>{b.disconnect(),O?.()}},[f,t,e,s,a]);const m=u!==null&&u.key===f?u.outcome:null;if(m!==null&&!m.ok)return r;const w=m===null?null:m.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(Wn,{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,O=T==="private-network",b=O?tl:ho;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(Wn,{tile:i.jsx(b,{"aria-hidden":"true",className:"size-4"}),tileKind:O?"internal":"link",primary:c.hostname,secondary:e})})}const{metadata:y}=w,p=go(y.image,s),x=go(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(Wn,{tile:x===null?i.jsx(ho,{"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"})]})},Ls=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(!vt.isEmbedProviderId(t))throw new RangeError(`[@aiquants/markdown] embeds.providers holds an unknown provider id ${JSON.stringify(t)}; known ids are ${vt.EMBED_PROVIDER_IDS.join(", ")}`);if(e.linkCardEndpoint!==null&&!rt.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&&!rt.isLinkCardSize(e.linkCardSize))throw new RangeError(`[@aiquants/markdown] embeds.linkCardSize must be omitted or one of ${rt.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},Kt=new WeakMap;let mn=0;const yo=e=>{if(e.source===null)return;const t=Kt.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(vt.EMBED_FRAME_HEIGHT_LIMITS.max,Math.max(vt.EMBED_FRAME_HEIGHT_LIMITS.min,Math.ceil(n)));r!==t.last&&(t.last=r,t.watch.set(r))},gl=(e,t)=>{const n={watch:t,last:null};return Kt.has(e)||(mn+=1,mn===1&&window.addEventListener("message",yo)),Kt.set(e,n),()=>{Kt.get(e)===n&&(Kt.delete(e),mn-=1,mn===0&&window.removeEventListener("message",yo))}},yl=Cs({concurrency:2,capacity:256,timeoutMs:5e3}),xl=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()},bl=(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`}}},wl=Object.freeze({marginInline:0}),Gn=Object.freeze({kind:"pending"}),El=Object.freeze({kind:"narrow"}),Sl=Object.freeze({kind:"fallback"}),vl=(e,t,n,r,o)=>{if(t===null)return Gn;let s;if(e.kind==="frame")s=e.srcOf(n);else{if(r===null)return Gn;s=r.ok?e.srcOf(r.value,n):null}if(s===null||new URL(s).origin===t)return Sl;const{minWidth:a,maxWidth:l}=e.layout;if(a!==null){if(o===null)return Gn;if(Math.min(o,l??Number.POSITIVE_INFINITY)<a)return El}return{kind:"frame",src:s}},kl=({resolution:e,caption:t,fallback:n,theme:r,labels:o,frameSandbox:s})=>{const a=Os(),l=il(),[c,f]=d.useState(null),[u,h]=d.useState(null),m=e.kind==="lookup"?e.request.href:null,[w,y]=d.useState(null);d.useEffect(()=>{if(m!==null)return yl.subscribe(m,I=>xl(new URL(m),I),I=>y({key:m,outcome:I}))},[m]);const{provider:p,layout:x}=e,E=vl(e,a,{theme:r,lang:l},w!==null&&w.key===m?w.outcome:null,c),T=d.useCallback(I=>{if(I===null)return;f(I.getBoundingClientRect().width);const X=new ResizeObserver(()=>f(I.getBoundingClientRect().width));return X.observe(I),()=>X.disconnect()},[]),O=E.kind==="frame"?E.src:null,b=u!==null&&u.src===O?u.height:null,R=d.useCallback(I=>{if(!(I===null||I.contentWindow===null||x.kind!=="message"||O===null))return gl(I.contentWindow,{origin:p.frameOrigin,src:O,heightOf:x.heightOf,set:X=>h({src:O,height:X})})},[x,p.frameOrigin,O]);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 B=p.content==="video"?o.embeddedVideo:o.embeddedPost,{frame:M}=p,j=Xe.narrowFrameSandbox(M.sandbox,s);return i.jsxs(i.Fragment,{children:[A,i.jsxs("figure",{"data-embed-provider":p.id,"data-embed-state":E.kind,style:wl,children:[i.jsx("div",{"data-embed-box":"","data-aqmd-embed-surface":"",style:bl(x,b),className:"noscript:hidden overflow-hidden rounded-lg",children:E.kind==="frame"?i.jsx("iframe",{ref:R,src:E.src,title:`${p.name}: ${B.text}`,lang:B.lang,loading:"lazy",allow:M.allow??void 0,allowFullScreen:M.allowFullScreen,sandbox:j,referrerPolicy:M.referrerPolicy,scrolling:M.scrolling??void 0,className:"block h-full w-full border-0"},`${Xe.frameSandboxKeyOf(j)} ${E.src}`):null}),i.jsx("figcaption",{className:"mt-2",children:t})]})]})},gr=9,Tl=6,Rl="data-aqmd-heading-depth",_l=/^h([1-6])$/u,Ol=e=>{if(!Number.isSafeInteger(e)||e<1||e>gr)throw new RangeError(`MarkdownRenderer: topHeadingLevel must be an integer from 1 to ${gr}, got ${e}`)},Al=e=>{const t=_l.exec(e);return t===null?void 0:Number(t[1])},Nl=(e,t)=>Math.min(e+t-1,gr),Cl={lowerCaseAttributeNames:!1},Ll="<div></div>",Xt=e=>{const t=re.htmlToDOM(`${Ll}${e}`,Cl),n=t.find(s=>s instanceof re.Element),{prev:r,next:o}=n;return r!==null&&(r.next=o),o!==null&&(o.prev=r),t.filter(s=>s!==n)},jl=["title","width","height","allow","allowfullscreen","sandbox","referrerpolicy","loading","frameborder","scrolling"],Ml=(e,t)=>({...e,attributes:{...e.attributes,sandbox:Xe.narrowFrameSandbox(e.attributes.sandbox,t)}}),Il=(e,t)=>Xe.allowedFrameUrlOf(e,t)!==null,Dl=(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 jl){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)})},Pl=/^[a-z][a-z0-9+.-]*:/i,zl=/^[/\\]{2}/,$l=/[\t\n\r]/g,xo=32,Bl=e=>{let t=0,n=e.length;for(;t<n&&e.charCodeAt(t)<=xo;)t+=1;for(;n>t&&e.charCodeAt(n-1)<=xo;)n-=1;return e.slice(t,n)},js=e=>Bl(e).replace($l,""),Lr=e=>{const t=js(e);return Pl.test(t)||zl.test(t)},Fl="text-link underline visited:text-link-visited",ql="inline-block w-fit",jr=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"]);[...jr].join(",");const Ms=(e,t)=>[e,t?ql:void 0,Fl].filter(n=>n!==void 0&&n.trim()!=="").join(" "),Ul=new Set(["id","title","lang","dir","role"]),Hl=["aria-","data-footnote-"],Wl=e=>{const t={};for(const[n,r]of Object.entries(e)){const o=n.toLowerCase();(Ul.has(o)||Hl.some(s=>o.startsWith(s)&&o.length>s.length))&&(t[o]=r)}return Object.freeze(t)},Gl=Object.freeze(["document","untrusted"]),Mr=/^[A-Za-z][A-Za-z0-9_-]*$/u,Vl=(e,t)=>{if(!Gl.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"||!Mr.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}},Kl=new Set(["video","audio","source","main","nav","header","footer","section","article"]),Yl=new Set(["aside"]),Xl=new Set(["name","headers","hidden"]),Zl=new Set(["doc-noteref","doc-backlink","doc-endnotes"]),Jl=new Set(["aria-hidden"]),Ql=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"]),ec=new Set(["id","class","title","lang","dir","role","hidden","translate","style"]),tc=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"]),bo="language-",nc=/[\t\n\f\r ]+/u,rc=new Set(["h1","h2","h3","h4","h5","h6"]),wo=Object.freeze({sup:/^fnref\d*:\d+$/u,li:/^fn:\d+$/u}),Eo="user-content-",Fe=["align"],Ct=["width","height"],So=["colspan","rowspan","headers","scope","abbr","align","valign","width","height"],hn=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:[le.CODE_META_ATTRIBUTE],col:["span",...Fe,...Ct],colgroup:["span",...Fe,...Ct],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,...Ct,"data-asset-src","data-asset-exists"],ins:["cite","datetime"],kbd:[],li:["value"],main:[],mark:[],nav:[],ol:["start","reversed","type"],p:Fe,pre:[le.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",...Ct],tbody:[...Fe,"valign"],td:So,tfoot:[...Fe,"valign"],th:So,thead:[...Fe,"valign"],time:["datetime"],tr:[...Fe,"valign"],u:[],ul:[],var:[],video:["src","poster","controls","loop","muted","playsinline","preload",...Ct],wbr:[]}),Vn=Object.freeze({svg:["viewbox","version","xmlns","focusable","fill",...Ct],g:["fill","fill-rule","clip-rule"],path:["d","fill","fill-rule","clip-rule"]}),oc=new Set(["svg","g"]),Is=new Set(["href","src","cite","poster",Xe.EMBED_LINK_ATTRIBUTE]),sc=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/gu,ac=/^(?:(?:https?|mailto|tel):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/iu,ic=new Set(["left","right","center","justify","start","end"]),on=e=>ac.test(e.replace(sc,"")),lc=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();ic.has(o)&&(t=o)}return t===null?null:`text-align: ${t}`},cc=e=>{const t=e.split(nc).filter(n=>tc.has(n)||n.startsWith(bo)&&n.length>bo.length);return t.length===0?null:t.join(" ")},dc=(e,t)=>rc.has(e)&&t!==""||t.startsWith(Eo)&&t.length>Eo.length||Object.hasOwn(wo,e)&&wo[e].test(t),uc=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},fc=(e,t,n)=>{if(e==="id")return`${n}${t}`;if(!Is.has(e))return t;const r=js(t);return r.startsWith("#")?`#${n}${r.slice(1)}`:t},At=(e,t,n,r)=>{const{allowlist:o}=r,s={};for(const[a,l]of t){if(a===It.SOURCE_LINES_ATTRIBUTE){It.parseSourceLines(l)!==null&&(s[a]=l);continue}if(!(o==="untrusted"&&(Xl.has(a)||a==="title"&&Yl.has(e)||a==="role"&&!Zl.has(l)||a.startsWith("aria-")&&!Jl.has(a)))&&(ec.has(a)||n.includes(a)||a.startsWith("aria-")&&a.length>5)&&!(Is.has(a)&&!on(l))&&!(a==="fill"&&/url\s*\(/iu.test(l))&&!(a==="id"&&!dc(e,l))){if(a==="class"||a==="style"){const c=a==="class"?cc(l):lc(l);c!==null&&(s[a]=c);continue}s[a]=r.idPrefix===void 0?l:fc(a,l,r.idPrefix)}}return s},mc=e=>e.get("type")?.trim().toLowerCase()==="checkbox"&&e.has("disabled"),Dn=(e,t,n)=>{const r=e.toLowerCase(),o=n.parentName===null?null:n.parentName.toLowerCase(),s=uc(t),{allowlist:a}=n;if(o!==null&&oc.has(o)){const c=r!=="svg"&&Object.hasOwn(Vn,r)?Vn[r]:void 0;return c===void 0?{action:"remove"}:{action:"keep",attributes:At(r,s,c,n)}}if(r==="svg")return{action:"keep",attributes:At(r,s,Vn.svg,n)};if(r==="iframe"){const c=a==="untrusted"?null:Dl(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=At(r,s,hn.p,n),f=a==="untrusted"?void 0:s.get(Xe.EMBED_LINK_ATTRIBUTE);return f!==void 0&&on(f)?{action:"placeholder",attributes:c,link:f}:{action:"keep",attributes:c}}if(r==="input")return mc(s)?{action:"keep",attributes:At(r,s,["type","checked","disabled"],n)}:{action:"remove"};if(Ql.has(r))return{action:"remove"};if(a==="untrusted"){if(Kl.has(r))return{action:"unwrap"};if(r==="img")return{action:"image",attributes:At(r,s,hn.img,n)}}const l=Object.hasOwn(hn,r)?hn[r]:void 0;return l===void 0?{action:"unwrap"}:{action:"keep",attributes:At(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 hc=typeof document<"u"&&!!document.documentMode;let Kn;function pc(){return Kn||(Kn=document.createElement("div").style)}const vo=["webkit","moz","ms"],pn={};function Ir(e){if(pn[e])return pn[e];const t=pc();if(e in t)return pn[e]=e;const n=e[0].toUpperCase()+e.slice(1);let r=vo.length;for(;r--;){const o=`${vo[r]}${n}`;if(o in t)return pn[e]=o}}function gn(e,t){return parseFloat(t[Ir(e)])||0}function yn(e,t,n=window.getComputedStyle(e)){const r=t==="border"?"Width":"";return{left:gn(`${t}Left${r}`,n),right:gn(`${t}Right${r}`,n),top:gn(`${t}Top${r}`,n),bottom:gn(`${t}Bottom${r}`,n)}}function jt(e,t,n){e.style[Ir(t)]=n}function gc(e,t){const n=Ir("transform");jt(e,"transition",`${n} ${t.duration}ms ${t.easing}`)}function yc(e,{x:t,y:n,scale:r,isSVG:o},s){if(jt(e,"transform",`scale(${r}) translate(${t}px, ${n}px)`),o&&hc){const a=window.getComputedStyle(e).getPropertyValue("transform");e.setAttribute("transform",a)}}function Yn(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:yn(e,"margin",n),border:yn(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:yn(t,"padding",r),border:yn(t,"border",r)}}}let Qt={down:"mousedown",move:"mousemove",up:"mouseup mouseleave"};typeof window<"u"&&(typeof window.PointerEvent=="function"?Qt={down:"pointerdown",move:"pointermove",up:"pointerup pointerleave pointercancel"}:typeof window.TouchEvent=="function"&&(Qt={down:"touchstart",move:"touchmove",up:"touchend touchcancel"}));function Xn(e,t,n,r){Qt[e].split(" ").forEach(o=>{t.addEventListener(o,n,r)})}function Zn(e,t,n){Qt[e].split(" ").forEach(r=>{t.removeEventListener(r,n)})}function Ds(e,t){let n=e.length;for(;n--;)if(e[n].pointerId===t.pointerId)return n;return-1}function yr(e,t){let n;if(t.touches){n=0;for(const r of t.touches)r.pointerId=n++,yr(e,r);return}n=Ds(e,t),n>-1&&e.splice(n,1),e.push(t)}function xc(e,t){if(t.touches){for(;e.length;)e.pop();return}const n=Ds(e,t);n>-1&&e.splice(n,1)}function ko(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 Jn(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 bc(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 wc(e){return(e.getAttribute("class")||"").trim()}function Ec(e,t){return e.nodeType===1&&` ${wc(e)} `.indexOf(` ${t} `)>-1}function Sc(e,t){for(let n=e;n!=null;n=n.parentNode)if(Ec(n,t.excludeClass)||t.exclude.indexOf(n)>-1)return!0;return!1}const vc=/^http:[\w\.\/]+svg$/;function kc(e){return vc.test(e.namespaceURI)&&e.nodeName.toLowerCase()!=="svg"}function Tc(e){const t={};for(const n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}const Ps={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:yc,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(!bc(e))throw new Error("Panzoom should be called on elements that have been attached to the DOM");t={...Ps,...t};const n=kc(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,jt(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="",jt(e,"transformOrigin","")}function s(_={}){for(const z in _)_.hasOwnProperty(z)&&(t[z]=_[z]);(_.hasOwnProperty("cursor")||_.hasOwnProperty("canvas"))&&(r.style.cursor=e.style.cursor="",(t.canvas?r:e).style.cursor=t.cursor),_.hasOwnProperty("overflow")&&(r.style.overflow=_.overflow),_.hasOwnProperty("touchAction")&&(r.style.touchAction=_.touchAction,e.style.touchAction=_.touchAction)}let a=0,l=0,c=1,f=!1;p(t.startScale,{animate:!1,force:!0}),setTimeout(()=>{y(t.startX,t.startY,{animate:!1,force:!0})});function u(_,z,g){if(g.silent)return;const S=new CustomEvent(_,{detail:z});e.dispatchEvent(S)}function h(_,z,g){const S={x:a,y:l,scale:c,isSVG:n,originalEvent:g};return requestAnimationFrame(()=>{typeof z.animate=="boolean"&&(z.animate?gc(e,z):jt(e,"transition","none")),z.setTransform(e,S,z),u(_,S,z),u("panzoomchange",S,z)}),S}function m(_,z,g,S){const v={...t,...S},C={x:a,y:l,opts:v};if(!S?.force&&(v.disablePan||v.panOnlyWhenZoomed&&c===v.startScale))return C;if(_=parseFloat(_),z=parseFloat(z),v.disableXAxis||(C.x=(v.relative?a:0)+_),v.disableYAxis||(C.y=(v.relative?l:0)+z),v.contain){const D=Yn(e),J=D.elem.width/c,q=D.elem.height/c,fe=J*g,we=q*g,xe=(fe-J)/2,Oe=(we-q)/2;if(v.contain==="inside"){const ye=(-D.elem.margin.left-D.parent.padding.left+xe)/g,Le=(D.parent.width-fe-D.parent.padding.left-D.elem.margin.left-D.parent.border.left-D.parent.border.right+xe)/g;C.x=Math.max(Math.min(C.x,Le),ye);const De=(-D.elem.margin.top-D.parent.padding.top+Oe)/g,Ee=(D.parent.height-we-D.parent.padding.top-D.elem.margin.top-D.parent.border.top-D.parent.border.bottom+Oe)/g;C.y=Math.max(Math.min(C.y,Ee),De)}else if(v.contain==="outside"){const ye=(-(fe-D.parent.width)-D.parent.padding.left-D.parent.border.left-D.parent.border.right+xe)/g,Le=(xe-D.parent.padding.left)/g;C.x=Math.max(Math.min(C.x,Le),ye);const De=(-(we-D.parent.height)-D.parent.padding.top-D.parent.border.top-D.parent.border.bottom+Oe)/g,Ee=(Oe-D.parent.padding.top)/g;C.y=Math.max(Math.min(C.y,Ee),De)}}return v.roundPixels&&(C.x=Math.round(C.x),C.y=Math.round(C.y)),C}function w(_,z){const g={...t,...z},S={scale:c,opts:g};if(!z?.force&&g.disableZoom)return S;let v=t.minScale,C=t.maxScale;if(g.contain){const D=Yn(e),J=D.elem.width/c,q=D.elem.height/c;if(J>1&&q>1){const fe=D.parent.width-D.parent.border.left-D.parent.border.right,we=D.parent.height-D.parent.border.top-D.parent.border.bottom,xe=fe/J,Oe=we/q;t.contain==="inside"?C=Math.min(C,xe,Oe):t.contain==="outside"&&(v=Math.max(v,xe,Oe))}}return S.scale=Math.min(Math.max(_,v),C),S}function y(_,z,g,S){const v=m(_,z,c,g);return a!==v.x||l!==v.y?(a=v.x,l=v.y,h("panzoompan",v.opts,S)):{x:a,y:l,scale:c,isSVG:n,originalEvent:S}}function p(_,z,g){const S=w(_,z),v=S.opts;if(!z?.force&&v.disableZoom)return;_=S.scale;let C=a,D=l;if(v.focal){const q=v.focal;C=(q.x/_-q.x/c+a*_)/_,D=(q.y/_-q.y/c+l*_)/_}const J=m(C,D,_,{relative:!1,force:!0});return a=J.x,l=J.y,c=_,h("panzoomzoom",v,g)}function x(_,z){const g={...t,animate:!0,...z};return p(c*Math.exp((_?1:-1)*g.step),g)}function E(_){return x(!0,_)}function T(_){return x(!1,_)}function O(_,z,g,S){const v=Yn(e),C={width:v.parent.width-v.parent.padding.left-v.parent.padding.right-v.parent.border.left-v.parent.border.right,height:v.parent.height-v.parent.padding.top-v.parent.padding.bottom-v.parent.border.top-v.parent.border.bottom};let D=z.clientX-v.parent.left-v.parent.padding.left-v.parent.border.left-v.elem.margin.left,J=z.clientY-v.parent.top-v.parent.padding.top-v.parent.border.top-v.elem.margin.top;n||(D-=v.elem.width/c/2,J-=v.elem.height/c/2);const q={x:D/C.width*(C.width*_),y:J/C.height*(C.height*_)};return p(_,{...g,animate:!1,focal:q},S)}function b(_,z){_.preventDefault();const g={...t,...z,animate:!1},v=(_.deltaY===0&&_.deltaX?_.deltaX:_.deltaY)<0?1:-1,C=w(c*Math.exp(v*g.step/3),g).scale;return O(C,_,g,_)}function R(_){const z={...t,animate:!0,force:!0,..._};c=w(z.startScale,z).scale;const g=m(z.startX,z.startY,c,z);return a=g.x,l=g.y,h("panzoomreset",z)}let A,B,M,j,I,X;const P=[];function K(_){if(Sc(_.target,t))return;yr(P,_),f=!0,t.handleStartEvent(_),A=a,B=l,u("panzoomstart",{x:a,y:l,scale:c,isSVG:n,originalEvent:_},t);const z=ko(P);M=z.clientX,j=z.clientY,I=c,X=Jn(P)}function ce(_){if(!f||A===void 0||B===void 0||M===void 0||j===void 0)return;yr(P,_);const z=ko(P),g=P.length>1;let S=c;if(g){X===0&&(X=Jn(P));const v=Jn(P)-X;S=w(v*t.step/80+I).scale,O(S,z,{animate:!1},_)}(!g||t.pinchAndPan)&&y(A+(z.clientX-M)/S,B+(z.clientY-j)/S,{animate:!1},_)}function pe(_){P.length===1&&u("panzoomend",{x:a,y:l,scale:c,isSVG:n,originalEvent:_},t),xc(P,_),f&&(f=!1,A=B=M=j=void 0)}let Z=!1;function de(){Z||(Z=!0,Xn("down",t.canvas?r:e,K),Xn("move",document,ce,{passive:!0}),Xn("up",document,pe,{passive:!0}))}function Ce(){Z=!1,Zn("down",t.canvas?r:e,K),Zn("move",document,ce),Zn("up",document,pe)}return t.noBind||de(),{bind:de,destroy:Ce,eventNames:Qt,getPan:()=>({x:a,y:l}),getScale:()=>c,getOptions:()=>Tc(t),handleDown:K,handleMove:ce,handleUp:pe,pan:y,reset:R,resetStyle:o,setOptions:s,setStyle:(_,z)=>jt(e,_,z),zoom:p,zoomIn:E,zoomOut:T,zoomToPoint:O,zoomWithWheel:b}}zs.defaultOptions=Ps;const Rc=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],_c=se("arrow-down",Rc);const Oc=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],Ac=se("arrow-left",Oc);const Nc=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],Cc=se("arrow-right",Nc);const Lc=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],jc=se("arrow-up",Lc);const Mc=[["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"}]],$s=se("code-xml",Mc);const Ic=[["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"}]],en=se("copy",Ic);const Dc=[["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"}]],Bs=se("download",Dc);const Pc=[["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"}]],xr=se("refresh-cw",Pc);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"}]],$c=se("settings-2",zc);const Bc=[["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"}]],Fs=se("zoom-in",Bc);const Fc=[["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"}]],qs=se("zoom-out",Fc),Us=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"})}),Dr=-1,br="�",qc=/[\u0000\uD800-\uDFFF]/gu,oe=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}),Uc=new Map([["(","("],[")",")"],[",","comma"],[":","colon"],[";","semicolon"],["[","["],["]","]"],["{","{"],["}","}"]]),pt=e=>e>=48&&e<=57,To=e=>pt(e)||e>=65&&e<=70||e>=97&&e<=102,Rn=e=>e>=65&&e<=90||e>=97&&e<=122||e>=128||e===oe.lowLine,Hs=e=>Rn(e)||pt(e)||e===oe.hyphenMinus,_n=e=>e===10||e===13||e===12,_t=e=>_n(e)||e===9||e===32,Hc=e=>e>=0&&e<=8||e===11||e>=14&&e<=31||e===127,On=e=>e===oe.quotationMark||e===oe.apostrophe,sn=e=>e.replace(/[A-Z]/gu,t=>t.toLowerCase()),ae=(e,t)=>t<e.source.length?e.source.charCodeAt(t):Dr,Dt=(e,t)=>ae(e,t)===oe.reverseSolidus&&!_n(ae(e,t+1));function wr(e,t){const n=ae(e,t);if(n!==oe.hyphenMinus)return Rn(n)||Dt(e,t);const r=ae(e,t+1);return Rn(r)||r===oe.hyphenMinus||Dt(e,t+1)}function Wc(e,t){const n=ae(e,t),r=ae(e,t+1);return n===oe.plusSign||n===oe.hyphenMinus?pt(r)||r===oe.fullStop&&pt(ae(e,t+2)):n===oe.fullStop?pt(r):pt(n)}function Er(e){for(;_t(ae(e,e.index));)e.index+=1}function Ws(e){e.index+=e.source.startsWith(`\r
8
+ `,e.index)?2:1}function xn(e){for(;pt(ae(e,e.index));)e.index+=1}function Pn(e){const t=ae(e,e.index);if(t===Dr)return br;if(!To(t))return e.index+=1,String.fromCharCode(t);const n=e.index;for(;e.index-n<6&&To(ae(e,e.index));)e.index+=1;const r=Number.parseInt(e.source.slice(n,e.index),16);return _t(ae(e,e.index))&&Ws(e),r===0||r>=55296&&r<=57343||r>1114111?br:String.fromCodePoint(r)}function An(e){let t="";for(let n=ae(e,e.index);Hs(n)||Dt(e,e.index);n=ae(e,e.index))e.index+=1,t+=n===oe.reverseSolidus?Pn(e):String.fromCharCode(n);return t}function Gc(e){const t=ae(e,e.index);(t===oe.plusSign||t===oe.hyphenMinus)&&(e.index+=1),xn(e),ae(e,e.index)===oe.fullStop&&pt(ae(e,e.index+1))&&(e.index+=1,xn(e));const n=ae(e,e.index);if(n!==oe.capitalE&&n!==oe.smallE)return;const r=ae(e,e.index+1);pt(r)?(e.index+=1,xn(e)):(r===oe.plusSign||r===oe.hyphenMinus)&&pt(ae(e,e.index+2))&&(e.index+=2,xn(e))}function Vc(e){return Gc(e),wr(e,e.index)?(An(e),{type:"dimension",value:""}):ae(e,e.index)!==oe.percentSign?{type:"number",value:""}:(e.index+=1,{type:"percentage",value:""})}function Ro(e){for(;e.index<e.source.length;){const t=ae(e,e.index),n=Dt(e,e.index);if(e.index+=1,t===oe.rightParenthesis)break;n&&Pn(e)}return{type:"bad-url",value:""}}function Kc(e){let t="";for(Er(e);e.index<e.source.length;){const n=ae(e,e.index);if(_t(n)){Er(e);const r=ae(e,e.index);return r!==Dr&&r!==oe.rightParenthesis?Ro(e):(r===oe.rightParenthesis&&(e.index+=1),{type:"url",value:t})}if(On(n)||n===oe.leftParenthesis||Hc(n)||n===oe.reverseSolidus&&!Dt(e,e.index))return Ro(e);if(e.index+=1,n===oe.rightParenthesis)return{type:"url",value:t};t+=n===oe.reverseSolidus?Pn(e):String.fromCharCode(n)}return{type:"url",value:t}}function Yc(e){const t=An(e);if(ae(e,e.index)!==oe.leftParenthesis)return{type:"ident",value:t};if(e.index+=1,sn(t)!=="url")return{type:"function",value:t};for(;_t(ae(e,e.index))&&_t(ae(e,e.index+1));)e.index+=1;const n=ae(e,e.index);return On(n)||_t(n)&&On(ae(e,e.index+1))?{type:"function",value:t}:Kc(e)}function Xc(e,t){let n="";for(;e.index<e.source.length;){const r=ae(e,e.index);if(_n(r))return{type:"bad-string",value:""};if(e.index+=1,r===t)return{type:"string",value:n};r!==oe.reverseSolidus?n+=String.fromCharCode(r):_n(ae(e,e.index))?Ws(e):e.index<e.source.length&&(n+=Pn(e))}return{type:"string",value:n}}function Zc(e){const{source:t}=e,n=ae(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(_t(n))return Er(e),{type:"whitespace",value:""};if(Wc(e,e.index))return Vc(e);if(n===oe.hyphenMinus&&t.startsWith("-->",e.index))return e.index+=3,{type:"CDC",value:""};if(Rn(n)||(n===oe.hyphenMinus||n===oe.reverseSolidus)&&wr(e,e.index))return Yc(e);if(t.startsWith("<!--",e.index))return e.index+=4,{type:"CDO",value:""};if(e.index+=1,On(n))return Xc(e,n);if(n===oe.numberSign&&(Hs(ae(e,e.index))||Dt(e,e.index)))return{type:"hash",value:An(e)};if(n===oe.commercialAt&&wr(e,e.index))return{type:"at-keyword",value:An(e)};const r=String.fromCharCode(n),o=Uc.get(r);return o===void 0?{type:"delim",value:r}:{type:o,value:""}}function ct(e){const t={source:e.replace(qc,br),index:0},n=[];for(;t.index<t.source.length;){const r=t.index,{type:o,value:s}=Zc(t);n.push({type:o,value:s,start:r,end:t.index})}return n}const Pr=/[\\<\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F\uD800-\uDFFF]/u,Gs="--mermaid-font-family",Jc=new Set([Gs,"-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"]),Qc=new Set(["font-family","font-size","fill","max-width"]),ed=Object.freeze({root:Qc,inside:Jc}),td=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"]),Sr=new Set(["fill","stroke","filter","clip-path","marker-start","marker-end"]),nd=new Set(["whitespace","ident","number","percentage","dimension","hash","string","comma","(",")"]),rd=new Set(["+","-","*","/","."]),Nn=/^#\S+$/u,od=new Map([["function",")"],["(",")"],["[","]"],["{","}"]]),sd=new Set([">","+","~"]),ad=new Map([["data-look","="],["id","$="]]),id=new Set(["whitespace","comment","CDO","CDC"]),lt=(e,t,n)=>e.text.slice(e.tokens[t].start,e.tokens[n-1].end);function Mt(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 tn(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=od.get(a);l!==void 0&&o.push(l)}}return-1}function ld(e,t){const n=tn(e,t+1,e.length,["semicolon","{"]);if(n<0)return e.length;if(e[n].type==="semicolon")return n+1;const r=tn(e,n+1,e.length,["}"]);return r<0?e.length:r+1}function cd(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(u=>u.type!=="whitespace"),s=o[0],a=o[o.length-1],l=o.slice(1,-1),c=s?.type==="ident"?ad.get(s.value):void 0;return c===void 0||a.type!=="ident"&&a.type!=="string"?null:l.length===c.length&&l.every((u,h)=>u.type==="delim"&&u.value===c[h])?{text:lt(e,t,r+1),end:r+1}:null}function dd(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:lt(e,t,t+1),end:t+1};if(o.type==="delim"&&o.value==="."&&s?.type==="ident")return{text:`.${r}${lt(e,t+1,t+2)}`,end:t+2};if(o.type==="[")return cd(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:lt(e,t,a+1),end:a+1}:null}function ud(e,t,n,r){const[o,s]=Mt(e.tokens,t,n);if(o===s||e.tokens[o].type!=="hash"||e.tokens[o].value!==r.svgId)return null;let a=lt(e,o,o+1),l=!1,c=o+1;for(;c<s;){const f=dd(e,c,s,r.classPrefix);if(f!==null){a+=f.text,c=f.end;continue}let u=c;for(;u<s&&(e.tokens[u].type==="whitespace"||e.tokens[u].type==="delim"&&sd.has(e.tokens[u].value));)u+=1;if(u===c||!l&&e.tokens.slice(c,u).some(h=>h.type==="delim"&&h.value!==">"))return null;l=!0,a+=lt(e,c,u),c=u}return{text:a,target:l?"inside":"root"}}function fd(e,t,n,r){if(Pr.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=ud(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 md(e,t,n){const r=_o(e,t,n);if(r<t||e[r].type!=="ident"||sn(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 zn(e,t,n){const[r,o]=Mt(e,t,n);if(r===o||e[r].type!=="ident")return null;const[s]=Mt(e,r+1,o);if(s===o||e[s].type!=="colon")return null;const[a,l]=Mt(e,s+1,md(e,s+1,o));return{first:r,end:o,property:e[r],valueFirst:a,valueEnd:l}}function $n(e,t,n){const r=[];let o=t;for(;o<n;){const s=tn(e,o,n,["semicolon"]),a=s<0?n:s;r.push([o,a]),o=a+1}return r}function zr(e){const t=[];let n=0;for(;n<e.length;){const{type:r}=e[n];if(id.has(r)){n+=1;continue}if(r==="at-keyword"){n=ld(e,n);continue}const o=tn(e,n,e.length,["{"]),s=o<0?-1:tn(e,o+1,e.length,["}"]);if(s<0)break;t.push({from:n,blockStart:o,blockEnd:s}),n=s+1}return t}function Vs(e,t,n){const[r]=Mt(e,t+1,n),[o]=Mt(e,r+1,n);return o<n&&e[o].type===")"&&e[r].type!==")"?{argument:e[r],close:o}:null}function Ks(e,t,n,r){let o=t;for(;o<n;){const s=e[o],a=s.type==="function"?sn(s.value):"";if(a==="url"||a==="var"){const l=Vs(e,o,n),c=a==="url"?l?.argument.type==="string"&&Nn.test(l.argument.value)&&Sr.has(r):l?.argument.type==="ident"&&l.argument.value===Gs;if(l===null||!c)return!1;o=l.close+1;continue}if(s.type==="url"){if(!(Sr.has(r)&&Nn.test(s.value)))return!1}else if(s.type==="function"){if(!td.has(a))return!1}else if(s.type==="delim"?!rd.has(s.value):!nd.has(s.type))return!1;o+=1}return!0}function hd(e,t,n,r){const o=zn(e.tokens,t,n);if(o===null)return null;const s=lt(e,o.first,o.end);return Pr.test(s)||!ed[r].has(o.property.value)?null:o.valueFirst<o.valueEnd&&Ks(e.tokens,o.valueFirst,o.valueEnd,o.property.value)?s:null}function Ys(e,t,n,r){const o=$n(e.tokens,t,n).map(([s,a])=>hd(e,s,a,r)).filter(s=>s!==null);return o.length===0?null:o.join(";")}function pd(e,t,n){const r={text:e,tokens:ct(e)},o={svgId:t,classPrefix:n},s=[];for(const{from:a,blockStart:l,blockEnd:c}of zr(r.tokens)){const f=fd(r,a,l,o),u=f===null?null:Ys(r,l+1,c,f.target);f!==null&&u!==null&&s.push(`${f.text}{${u}}`)}return s.length===0?null:s.join("")}function gd(e,t){const n={text:e,tokens:ct(e)};return Ys(n,0,n.tokens.length,t)}function yd(e,t){if(Pr.test(t))return!1;const n=ct(t);return Ks(n,0,n.length,e)}function Xs(e,t,n){return $n(e.tokens,t,n).flatMap(([r,o])=>{const s=zn(e.tokens,r,o);return s===null?[]:[{property:s.property.value,value:s.valueFirst<s.valueEnd?lt(e,s.valueFirst,s.valueEnd):""}]})}function xd(e){const t={text:e,tokens:ct(e)};return Xs(t,0,t.tokens.length)}function bd(e){const t={text:e,tokens:ct(e)};return zr(t.tokens).flatMap(({blockStart:n,blockEnd:r})=>Xs(t,n+1,r))}function wd(e,t){const n={text:e,tokens:ct(e)},r=$n(n.tokens,0,n.tokens.length).flatMap(([o,s])=>{const a=zn(n.tokens,o,s);return a===null||t.has(sn(a.property.value))?[]:[lt(n,a.first,a.end)]});return r.length===0?null:r.join(";")}const vr=(e,t)=>e.startsWith("#")&&!e.includes("%")&&t.ids.has(e.slice(1)),Oo=(e,t,n)=>e[t]==="#"?`${e.slice(0,t+1)}${n.prefix}${e.slice(t+1)}`:null;function Zs(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,f=c+l.slice(c).search(/[^\t\n\f\r ]/u),u=vr(a.value,r)?Oo(l,f,r):null;if(u===null)return null;o+=u,s+=1;continue}if(a.type==="function"&&sn(a.value)==="url"){const c=Vs(e.tokens,s,n);if(c===null||c.argument.type!=="string"||!vr(c.argument.value,r))return null;const f=Oo(e.text.slice(c.argument.start,c.argument.end),1,r);if(f===null)return null;o+=`${e.text.slice(a.start,c.argument.start)}${f}${e.text.slice(c.argument.end,e.tokens[c.close].end)}`,s=c.close+1;continue}o+=l,s+=1}return o}function Js(e,t,n,r){const o=$n(e.tokens,t,n).flatMap(([s,a])=>{const l=zn(e.tokens,s,a);if(l===null)return[];const c=l.valueFirst<l.valueEnd?Zs(e,l.valueFirst,l.valueEnd,r):"";if(c===null)return[];const f=l.valueEnd<l.end?lt(e,l.valueEnd,l.end):"";return[`${lt(e,l.first,l.valueFirst)}${c}${f}`]});return o.length===0?null:o.join(";")}function Ed(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 Sd(e,t){const n={text:e,tokens:ct(e)},r=[];for(const{from:o,blockStart:s,blockEnd:a}of zr(n.tokens)){const l=Ed(n,o,s,t),c=l===null?null:Js(n,s+1,a,t);l!==null&&c!==null&&r.push(`${l}{${c}}`)}return r.length===0?null:r.join("")}function vd(e,t){const n={text:e,tokens:ct(e)};return Js(n,0,n.tokens.length,t)}function kd(e,t){const n={text:e,tokens:ct(e)};return Zs(n,0,n.tokens.length,t)}const ie=(e,t)=>Object.freeze({type:e,header:t}),Qs=Object.freeze([ie("mindmap","mindmap"),ie("architecture","architecture-beta"),ie("c4","C4Context"),ie("kanban","kanban"),ie("classDiagram","classDiagram-v2"),ie("class","classDiagram"),ie("er","erDiagram"),ie("gantt","gantt"),ie("info","info"),ie("pie","pie"),ie("requirement","requirementDiagram"),ie("sequence","sequenceDiagram"),ie("swimlane","swimlane-beta"),ie("flowchart-v2","flowchart"),ie("timeline","timeline"),ie("gitGraph","gitGraph"),ie("stateDiagram","stateDiagram-v2"),ie("quadrantChart","quadrantChart"),ie("sankey","sankey"),ie("packet","packet"),ie("xychart","xychart"),ie("block","block"),ie("eventmodeling","eventmodeling"),ie("treeView","treeView-beta"),ie("ishikawa","ishikawa-beta"),ie("railroad","railroad-beta"),ie("railroadEbnf","railroad-ebnf-beta"),ie("railroadAbnf","railroad-abnf-beta"),ie("railroadPeg","railroad-peg-beta"),ie("venn","venn-beta"),ie("wardley","wardley-beta"),ie("cynefin","cynefin-beta")]),Td=new Set(Qs.map(({type:e})=>e)),Rd=e=>Td.has(e),ot="http://www.w3.org/2000/svg",ea="http://www.w3.org/1999/xhtml",_d=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"]),Od=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])]},kr=new Set(_d),Ad=new Set(["fill","stroke","color","background-color"]),Nd=new Set(["none","transparent"]),Cd="text-decoration",Ld=new Set(["none","underline","overline","line-through","blink","spelling-error","grammar-error","solid","double","dotted","dashed","wavy"]),jd=/^[0-9a-f]{6}$/u,Ao=["function","number","comma","number","comma","number",")"],Md=/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/u,Id=e=>{const t=ct(e).filter(r=>r.type!=="whitespace");if(t.length===1)return t[0].type==="hash"&&jd.test(t[0].value)?`#${t[0].value}`:null;if(t.length!==Ao.length||t.some((r,o)=>r.type!==Ao[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=>Md.test(r))?`#${n.map(r=>Number(r).toString(16).padStart(2,"0")).join("")}`:null},Dd=({property:e,value:t},n)=>{if(!kr.has(e))return!0;if(Ad.has(e)){if(Nd.has(t))return!0;const o=Id(t);return o!==null&&n.has(o)}if(e!==Cd)return!1;const r=ct(t).filter(o=>o.type!=="whitespace");return r.length>0&&r.every(o=>o.type==="ident"&&Ld.has(o.value))};function Pd(e,t){const n=new Set(Od(t));for(const r of[e,...e.querySelectorAll("*")]){if(r.localName==="style"){const o=bd(r.textContent).find(({property:s})=>kr.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=xd(o.value).find(l=>!Dd(l,n));if(a!==void 0)return`${a.property} ${JSON.stringify(a.value)} in the style of the ${r.localName} element`}else if(kr.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",$d="listening",Bd="aiquants-markdown:mermaid-frame:connect",ta="aqmd-mmd-",Fd=["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"],qd=["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"],Ud=new Set(["style","title"]),Hd=["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"],na=new Set(["id","data-look","title","alt"]),Cn=new Set(["role","aria-roledescription","aria-labelledby","aria-describedby"]),Wd=new Set(["id","class","style","width","height","viewbox","preserveaspectratio","overflow",...Cn]),ra=new Set(["href","xlink:href","src"]),No=/^data:image\//u,Gd=new Map([[`${ot} use`,{attributes:new Set(["href","xlink:href"]),shape:Nn,removesElement:!1}],[`${ot} linearGradient`,{attributes:new Set(["href","xlink:href"]),shape:Nn,removesElement:!1}],[`${ot} image`,{attributes:new Set(["href","xlink:href"]),shape:No,removesElement:!0}],[`${ea} img`,{attributes:new Set(["src"]),shape:No,removesElement:!0}]]),Vd=/[\t\n\f\r ]+/u,Kd={ALLOWED_TAGS:[...Fd,...qd],ALLOWED_ATTR:[...Hd,...na,...Cn,...ra,"class","style"],ALLOW_ARIA_ATTR:!1,ALLOW_DATA_ATTR:!1,HTML_INTEGRATION_POINTS:{foreignobject:!0},RETURN_DOM_FRAGMENT:!0},Yd=(e,t)=>e!==null&&e.namespaceURI===ot&&e.localName==="svg"&&e.getAttribute("id")===t;function Xd(e){const t=e.split(Vd).filter(n=>n!=="");return t.length===0?null:t.map(n=>`${ta}${n}`).join(" ")}function Zd(e,t,n){const r=Gd.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 Jd(e,t,n){const r=t.name.toLowerCase(),{value:o}=t;if(ra.has(r))return Zd(e,t,r);const s=e===n;let a=o;return(s?!Wd.has(r):Cn.has(r))?a=null:r==="class"?a=Xd(o):r==="style"?a=gd(o,s?"root":"inside"):na.has(r)||Cn.has(r)||yd(r,o)||(a=null),a===null?e.removeAttributeNode(t):a!==o&&(t.value=a),!0}function Qd(e){for(let t=e.parentElement;t!==null;t=t.parentElement)if(t.namespaceURI===ot&&t.localName==="text")return!0;return!1}function eu(e){if(e.namespaceURI!==ot||Qd(e)){e.replaceWith(...Array.from(e.childNodes));return}const t=e.ownerDocument.createElementNS(ot,"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 tu(e,t,n){if(e.namespaceURI===ea&&Ud.has(e.localName)){e.remove();return}for(const o of Array.from(e.attributes))if(!Jd(e,o,t)){e.remove();return}if(e.localName==="a"){eu(e);return}if(e.namespaceURI!==ot||e.localName!=="style")return;const r=pd(e.textContent,n,ta);r===null?e.remove():e.textContent=r}function nu(e){const t=hi(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"||!Mr.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,Kd),s=o.firstElementChild;if(o.childNodes.length!==1||!Yd(s,r))return null;for(const a of[s,...Array.from(s.querySelectorAll("*"))])tu(a,s,r);return s}}const ru=e=>`default-src 'none'; script-src ${e}; style-src ${e} 'unsafe-inline'; font-src ${e}; img-src data:`,ou=Object.freeze(["html-label","unsized","unlike-text"]),su=new Set(["https:","http:"]),au="aqmd-mermaid-",iu=[["position","fixed"],["inset-block-start","0"],["inset-inline-start","0"],["inline-size","0"],["block-size","0"],["border","0"],["visibility","hidden"]],lu="the drawing place's script did not load, or threw before it listened",cu="the drawing place's frame loaded again, and the diagrams it held were lost",Co="the drawing place's frame left the page, and the diagrams it held were lost",du="the page has no body to hold the drawing place's frame",uu="the drawing place answered with something other than one svg of the requested id",fu="the drawing place answered with a paint off the diagram palette",mu="the drawing place answered in a shape the page does not read",hu="the drawing holds a foreignObject, a label drawn as HTML, which not every reader of an image file draws",pu="the drawing has no viewBox of a positive width and height to take its size from",gu="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",yu=new Set(["style","title","desc"]),xu=/\s/gu,bu=new Set(["max-width"]),bn=String.raw`([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?)`,wu=String.raw`(?:[\t\n\r ]*,[\t\n\r ]*|[\t\n\r ]+)`,Eu=new RegExp(String.raw`^[\t\n\r ]*${[bn,bn,bn,bn].join(wu)}[\t\n\r ]*$`,"u"),oa=new WeakMap,$r=e=>typeof e=="object"&&e!==null,Qn=e=>Number.isSafeInteger(e)&&e>=0,er=e=>e.replaceAll("&","&amp;").replaceAll('"',"&quot;").replaceAll("<","&lt;").replaceAll(">","&gt;"),Su=(e,t,n)=>`<!doctype html><html><head><meta http-equiv="Content-Security-Policy" content="${er(ru(e))}">${n.map(r=>`<link rel="stylesheet" href="${er(r)}">`).join("")}<script type="module" src="${er(t)}"><\/script></head><body></body></html>`,Lo=(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||!su.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},vu=e=>{if(!$r(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])}`)},ku=e=>{if(!$r(e))return null;switch(e.kind){case"too-large":return Qn(e.length)&&Qn(e.limit)?{kind:"too-large",length:e.length,limit:e.limit}:null;case"too-many-edges":return Qn(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!==""&&!Rd(e.type)?{kind:"unlisted-type",type:e.type}:null;default:return null}},Wt=e=>({failure:{kind:"frame",message:e}}),Tu=e=>{const t=e===null?null:Eu.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},Ru=(e,t)=>{if(e.getElementsByTagNameNS(ot,"foreignObject").length>0)return{kind:"not-exportable",reason:"html-label",message:hu};const n=Tu(e.getAttribute("viewBox"));if(n===null)return{kind:"not-exportable",reason:"unsized",message:pu};e.setAttribute("width",String(n.width)),e.setAttribute("height",String(n.height));const r=e.getAttribute("style"),o=r===null?null:wd(r,bu);o===null?e.removeAttribute("style"):e.setAttribute("style",o);const s=e.ownerDocument.createElementNS(ot,"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},jo=e=>{if(e.namespaceURI!==ot||e.localName!=="switch")return Array.from(e.childNodes);const t=e.firstElementChild;return t===null?[]:[t]},Mo=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(xu,""))):o.nodeType===o.ELEMENT_NODE&&!yu.has(o.localName)&&n(jo(o))};return n(jo(e)),t.sort().join("")},Io=e=>{const t=Object.freeze({length:e.outerHTML.length});return oa.set(t,e),t},sa=e=>oa.get(e);function _u(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=nu(window),n=Lo("frameScriptUrl",e.frameScriptUrl);if(!Array.isArray(e.fontStylesheetUrls))throw new TypeError("createMermaidDrawer: fontStylesheetUrls must be an array");const r=Su(window.location.origin,n,e.fontStylesheetUrls.map((p,x)=>Lo(`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,Wt(x))},f=(p,x)=>{p.watcher.disconnect(),c(p,x),p.port?.close(),p.element.remove(),s===p&&(s=null)},u=p=>{if(!($r(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,Wt(uu));return}const O=Pd(T,x.palette);if(O!==null){l(p.id,x,Wt(`${fu}: ${O}`));return}const b=x.form==="export"?Ru(T,x.palette):null;l(p.id,x,b===null?{svg:T}:{failure:b});return}const E="svg"in p?null:ku(p.failure);l(p.id,x,E===null?Wt(mu):{failure:E})},h=p=>{if(s!==p)return;p.port!==null&&(c(p,cu),p.port.close(),p.port=null);const x=p.element.contentWindow;if(x?.document.documentElement.getAttribute(zd)!==$d){f(p,lu);return}const E=new MessageChannel;E.port1.onmessage=T=>u(T.data),x.postMessage({type:Bd},window.location.origin,[E.port2]),p.port=E.port1;for(const T of p.queued.splice(0))E.port1.postMessage(T)},m=p=>{const x=window.document.createElement("iframe");x.setAttribute("aria-hidden","true"),x.setAttribute("inert",""),x.tabIndex=-1;for(const[O,b]of iu)x.style.setProperty(O,b);x.srcdoc=r;const E=new MutationObserver(()=>{x.isConnected||f(T,Co)}),T={element:x,port:null,queued:[],watcher:E};return x.addEventListener("load",()=>h(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&&f(s,Co),s===null){const{body:E}=window.document;if(E===null){x(Wt(du));return}s=m(E)}o.set(p.id,{svgId:p.svgId,palette:Us[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:`${au}${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(vu(p),p.form==="shown"){const b=await y(p,"shown");return"failure"in b?b:{diagram:Io(b.svg)}}const x=y(p,"export"),E=y(p,"shown"),T=await x;if("failure"in T)return T;const O=await E;return"failure"in O?O:Mo(T.svg)!==Mo(O.svg)?{failure:{kind:"not-exportable",reason:"unlike-text",message:gu}}:{diagram:Io(T.svg)}}}const Ou="aqmd-mmd-",Au="data-aqmd-mermaid-drawing",Do="drawing",Nu="scalable",Cu=8,Lu=new Set(["href","xlink:href"]),ju=new Set(["aria-labelledby","aria-describedby"]),Mu=/[\t\n\f\r ]+/u,Iu=()=>{const e=Array.from(crypto.getRandomValues(new Uint8Array(Cu)),t=>t.toString(16).padStart(2,"0")).join("");return`${Ou}${e}-`};function Du(e,t,n){if(e==="id")return t===""?t:`${n.prefix}${t}`;if(Lu.has(e))return t.startsWith("#")?vr(t,n)?`#${n.prefix}${t.slice(1)}`:null:t;if(ju.has(e)){const r=t.split(Mu).filter(o=>n.ids.has(o));return r.length===0?null:r.map(o=>`${n.prefix}${o}`).join(" ")}return e==="style"?vd(t,n):Sr.has(e)?kd(t,n):t}function Pu(e,t,n){if(typeof n!="string"||!Mr.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 f=Du(l,c,s);f===null?a.removeAttribute(l):f!==c&&a.setAttribute(l,f)}if(a.namespaceURI===ot&&a.localName==="style"){const l=Sd(a.textContent,s);l===null?a.remove():a.textContent=l}}return r}function zu(e,t){const n=e.ownerDocument,r=Pu(t,n,Iu());r.setAttribute("part",r.hasAttribute("viewBox")?`${Do} ${Nu}`:Do);const o=n.createElement("div");return o.setAttribute(Au,""),o.attachShadow({mode:"open"}).append(r),e.replaceChildren(o),{host:o,svg:r}}const $u=[["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"}]],Bu=se("maximize-2",$u);const Fu=[["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"}]],qu=se("minimize-2",Fu),Et="flex size-11 items-center justify-center rounded border p-1 shadow",Uu="flex h-11 min-w-11 items-center justify-center rounded border px-2 text-sm shadow",Hu="absolute top-full z-20 mt-1 w-60 overflow-hidden rounded border py-1 text-sm shadow-lg",Po="flex min-h-11 w-full items-center gap-2 px-3 py-1.5 text-start",yt="fullscreen",Wu=229,Gu=e=>{const t=e.ownerDocument.defaultView?.getComputedStyle(e).blockSize;t!==void 0&&(e.style.minBlockSize=t)},zo=e=>{if(e.parentElement!==null)return e.parentElement;const t=e.getRootNode();return"host"in t?t.host:null},Vu=e=>{const t=[];for(let n=zo(e);n!==null;n=zo(n))t.push({element:n,top:n.scrollTop,left:n.scrollLeft});return t},Ku=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"})},Yu=e=>{e.style.removeProperty("min-block-size"),e.getAttribute("style")===""&&e.removeAttribute("style")},Br=(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(m=>{const w=o.current;if(w===null)return;const y=s.current;m&&y!==null&&(a.current=Vu(y),Gu(y)),w.close(),m?w.showModal():(w.show(),y!==null&&Yu(y),Ku(a.current),a.current=[]),l.current=!0,r(m)},[]);d.useLayoutEffect(()=>{n&&!t&&c(!1)},[n,t,c]);const f=d.useCallback(()=>c(!n),[n,c]),u=d.useCallback(m=>{!n||m.key!=="Escape"||m.defaultPrevented||m.nativeEvent.isComposing||m.keyCode===Wu||(m.preventDefault(),m.stopPropagation(),c(!1))},[n,c]),h=d.useCallback(m=>{m.preventDefault(),c(!1)},[c]);return{fullscreen:n,toggle:f,dialogRef:o,dialogProps:{ref:o,open:!0,role:n?void 0:"group","data-aqmd-fullscreen-dialog":"",onKeyDown:u,onCancel:h},rootProps:{ref:s,"data-aqmd-fullscreen":n?"":void 0}}},Fr=({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(qu,{size:18}):i.jsx(Bu,{size:18})})},qr=(e,t)=>({text:t.text,lang:t.lang,serial:e===null?1:e.serial+1}),Ur=({hook:e,notice:t})=>i.jsx("p",{...e,role:"status",children:t!==null&&i.jsx("span",{lang:t.lang,children:t.text},t.serial)}),aa=()=>{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},[])},Hr=(e,t)=>{const n=e.ownerDocument.defaultView?.navigator.clipboard;return n===void 0?Promise.resolve("failed"):$t(()=>n.writeText(t)).then(()=>"copied",r=>(console.error("[@aiquants/markdown] could not copy the text",r),"failed"))},ia=(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)}},Xu=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"]]),Zu=Object.freeze({title:null,description:null}),Ju=(e,t)=>{for(const n of e.querySelectorAll("[id]"))if(n.id===t)return n;return null},$o=(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:Ju(e,s);a!==null&&r.push(a.textContent)}const o=r.join(" ").replace(/\s+/gu," ").trim();return o===""?null:o},Qu=e=>({title:$o(e,"aria-labelledby"),description:$o(e,"aria-describedby")}),ef=(e,t,n)=>{const r=t===null?void 0:Xu.get(t),o=r===void 0?"":n[r].text;if(o.trim()===""){e.removeAttribute("aria-roledescription");return}e.setAttribute("aria-roledescription",o)},tf=4096*4096,Bo=32767,nf=Object.freeze({width:0,height:0}),rf=/^\s*(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?[a-zA-Z]*\s*$/u,of=(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&&rf.test(r))},tr=e=>Number.isFinite(e.width)&&Number.isFinite(e.height)&&e.width>0&&e.height>0,la=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)}`)},sf=(e,t,n)=>{la(n);const r=tr(e)?e:tr(t)?t:null;if(r===null)return null;const o={width:r.width*n,height:r.height*n};if(!tr(o))return null;const s=Math.min(1,Math.sqrt(tf/o.width/o.height),Bo/o.width,Bo/o.height);return{width:Math.max(1,Math.floor(o.width*s)),height:Math.max(1,Math.floor(o.height*s))}},ca=async(e,t,n,r)=>{la(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=sf(of(e,r)?{width:s.naturalWidth,height:s.naturalHeight}:nf,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((f,u)=>{l.toBlob(h=>h===null?u(new Error("[@aiquants/markdown] the canvas could not encode the SVG image as a PNG")):f(h),"image/png")})}finally{r.URL.revokeObjectURL(o)}},Wr="image/svg+xml",af="image/png",lf=Object.freeze({width:0,height:0}),da=(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)}`)},cf=(e,t)=>{da(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)}`)},df=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 Tr extends Error{reason;constructor(t,n){super(n),this.name="MermaidNotExportableError",this.reason=t}}const uf=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}`}},Fo=async(e,t,n,r,o)=>{const s=await $t(()=>e({...t,theme:"light",form:"export"}));if("failure"in s)throw s.failure.kind==="not-exportable"?ou.includes(s.failure.reason)?new Tr(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: ${uf(s.failure)}`);const a=sa(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:Wr}):ca(l,lf,r,o)},ua="both-shift",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:"shift-drag",zoom:!1}),both:Object.freeze({panTrigger:"drag",zoom:!0}),"both-shift":Object.freeze({panTrigger:"shift-drag",zoom:!0})}),ff=Object.freeze(["none","zoom","pan","pan-shift","both","both-shift"]),mf=Object.freeze(["none","zoom","pan","both"]),hf=Object.freeze({none:"none",zoom:"zoom",pan:"pan","pan-shift":"pan",both:"both","both-shift":"both"}),kn=.3,pf=3,gf=2,Rt=.5,yf=1;function Uo(e,t){return e.panTrigger!==null&&t?e.zoom?"none":"pinch-zoom":e.zoom?"pan-x pan-y":"auto"}const xf=0;function nr(e,t,n){return e.panTrigger===null||t.button!==xf?!1:t.pointerType==="touch"||t.pointerType==="pen"?n:e.panTrigger==="drag"||t.shiftKey}function bf(e,t){return e.zoom&&t.shiftKey}function wf(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 Ef(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 Sf(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:gf/e}}function rr(e,t){return Math.min(t.maxScale,Math.max(t.minScale,e))}function Gt(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 vf(e,t,n){const r=(o,s,a,l)=>{const c=(0-s)/e.scale,f=(l-s-e.scale*a)/e.scale;return Math.min(Math.max(c,f),Math.max(Math.min(c,f),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 kf(e,t,n){return e*t.inline-n.inline>Rt||e*t.block-n.block>Rt}function Tf(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<yf?null:{ratio:n(t)/o,from:r(e),to:r(t)}}function Ho(e){return e*(1-Math.exp(-kn))}function Wo(e,t,n){const r=e<-Rt||e>Rt;return t-e>n+Rt?r?0-e:0:e<-Rt?0-e:t>n+Rt?n-t:0}const Rf=Object.freeze(["tooLarge","tooManyEdges","unlistedType"]),_f=Object.freeze(["openStreaming","openCut","tooManyDiagrams"]),Of=Object.freeze(["exportMenu","copyDiagram","copySvg","saveSvg","savePng","copiedDiagram","copyDiagramFailed","saveStarted","saveFailed","notExportableHtmlLabel","notExportableUnsized","notExportableUnlikeText"]),Go=Object.freeze({"html-label":"notExportableHtmlLabel",unsized:"notExportableUnsized","unlike-text":"notExportableUnlikeText"}),Bn=Object.freeze({interactionMode:{text:"マウス操作モード",lang:"ja"},interactionModeTouch:{text:"タッチ操作モード",lang:"ja"},modeNone:{text:"操作なし",lang:"ja"},modeZoom:{text:"拡大縮小のみ",lang:"ja"},modePan:{text:"移動のみ (左ドラッグ)",lang:"ja"},modePanShift:{text:"移動のみ (Shift+ドラッグ)",lang:"ja"},modeBoth:{text:"拡大縮小+移動 (左ドラッグ)",lang:"ja"},modeBothShift:{text:"拡大縮小+移動 (Shift+ドラッグ)",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"},...le.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"}}),Af=zt(Bn),Nf=Object.freeze({none:"modeNone",zoom:"modeZoom",pan:"modePan","pan-shift":"modePanShift",both:"modeBoth","both-shift":"modeBothShift"}),Cf=Object.freeze({none:"modeNoneTouch",zoom:"modeZoomTouch",pan:"modePanTouch",both:"modeBothTouch"}),Lf=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)},jf=Lf(()=>Promise.resolve().then(()=>require("./mermaid.core-CRP55Hm1.cjs")).then(e=>e.mermaid_core)),fa="(pointer: coarse)",Mf=e=>{const t=window.matchMedia(fa);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)},If=()=>window.matchMedia(fa).matches,Df=()=>!1,Pf=()=>d.useSyncExternalStore(Mf,If,Df),Gr=(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 f=s(c.target);if(f===null||c.altKey||c.ctrlKey||c.metaKey||c.shiftKey)return;const u=e.indexOf(f);if(u===-1)return;const h=c.currentTarget.ownerDocument.defaultView?.getComputedStyle(c.currentTarget).direction==="rtl",m=h?"ArrowLeft":"ArrowRight",w=h?"ArrowRight":"ArrowLeft";let y;switch(c.key){case m:y=(u+1)%e.length;break;case w:y=(u-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 f=s(c.target);f!==null&&e.includes(f)&&r(f)},tabIndexOf:c=>c===o?0:-1}},Zt={side:"start",offset:0,maxWidth:null},zf=(e,t,n,r)=>{const o=c=>c>=n.low&&c+t<=n.high;if(o(r?e.right-t:e.left))return Zt;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 Zt;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}},Rr=({buttonHook:e,menuHook:t,label:n,icon:r,tabIndex:o,items:s})=>{const[a,l]=d.useState(null),[c,f]=d.useState(Zt),u=a!==null,h=d.useId(),m=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),f(Zt),b&&y.current?.focus()};d.useLayoutEffect(()=>{const b=w.current,R=p.current;if(a===null||b===null||R===null)return;const A=R.ownerDocument.documentElement.clientWidth,B=b.closest('[role="toolbar"]')?.getBoundingClientRect(),M=B===void 0?{low:0,high:A}:{low:Math.max(0,B.left),high:Math.min(A,B.right)},j=R.ownerDocument.defaultView?.getComputedStyle(R).direction==="rtl";f(zf(b.getBoundingClientRect(),R.getBoundingClientRect().width,M,j));const I=x(),X=I.findIndex(K=>K.getAttribute("aria-checked")==="true"),P=a==="last"?I.length-1:Math.max(X,0);I[P]?.focus()},[a]),d.useEffect(()=>{const b=w.current?.ownerDocument;if(!u||b===void 0)return;const R=A=>{A.target instanceof Node&&w.current?.contains(A.target)===!0||(l(null),f(Zt))};return b.addEventListener("pointerdown",R,!0),b.addEventListener("focusin",R,!0),()=>{b.removeEventListener("pointerdown",R,!0),b.removeEventListener("focusin",R,!0)}},[u]);const T=b=>{if(b.key==="ArrowDown"||b.key==="ArrowUp"){b.preventDefault(),b.stopPropagation(),l(b.key==="ArrowUp"?"last":"chosen");return}b.key==="Escape"&&u&&(b.preventDefault(),b.stopPropagation(),E(!1))},O=b=>{const R=x(),A=R.indexOf(b.target);let B;switch(b.key){case"ArrowDown":B=(A+1)%R.length;break;case"ArrowUp":B=(A-1+R.length)%R.length;break;case"Home":B=0;break;case"End":B=R.length-1;break;case"Escape":b.preventDefault(),b.stopPropagation(),E(!0);return;default:return}b.preventDefault(),b.stopPropagation(),R[B]?.focus()};return i.jsxs("div",{ref:w,className:"relative",children:[i.jsx("button",{ref:y,id:h,type:"button",...e,tabIndex:o,onClick:()=>u?E(!1):l("chosen"),onKeyDown:T,className:Et,"aria-label":n.text,lang:n.lang,"aria-haspopup":"menu","aria-expanded":u,"aria-controls":u?m:void 0,children:r}),u&&i.jsx("div",{ref:p,id:m,role:"menu","aria-labelledby":h,...t,"data-aqmd-control-menu":c.side,style:c.maxWidth===null?{insetInlineStart:c.offset}:{insetInlineStart:c.offset,maxInlineSize:c.maxWidth},onKeyDown:O,className:Hu,children:s.map(b=>{const R=()=>{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:R,className:Po,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:R,className:Po,children:[i.jsx("span",{className:"w-3 shrink-0","aria-hidden":"true",children:b.checked?"✓":""}),i.jsx("span",{children:b.label.text})]},b.key)})})]})},Vo=new Set(["gantt"]),$f=200,Bf=300,Ff=Object.freeze({height:0,overflow:"hidden",visibility:"hidden",contain:"strict"}),qf="data-aqmd-mermaid-host",Uf=e=>{const t=document.createElement("div");return t.setAttribute(qf,""),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 Ko=Promise.resolve();const Hf=e=>{const t=e instanceof Error?e.message:String(e);return t.includes("dynamically imported module")||t.includes("Importing a module script failed")},Yo=e=>{e.resetStyle(),e.destroy()},or=(e,t)=>t?"grabbing":e.panTrigger==="drag"?"move":"",Wf=Object.freeze({visibility:"hidden"}),kt="data-aqmd-mermaid-control",Gf=Object.freeze({"data-aqmd-mermaid-notice":""}),Vf=Object.freeze(["copy-source","source",yt]),Kf=Object.freeze(["export","copy-diagram"]),sr="data-aqmd-mermaid-export-item",Yf=e=>typeof e.ClipboardItem=="function"&&typeof e.ClipboardItem.supports=="function"&&e.ClipboardItem.supports(Wr),Xf="--aqmd-mermaid-ratio",wn=(e,t)=>e instanceof Error&&e.message!==""?{message:e.message}:{label:t},Zf=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}}},Jf=(e,t)=>"label"in e?t[e.label]:"template"in e?{text:le.fillLabel(t[e.template].text,e.values),lang:t[e.template].lang}:{text:e.message,lang:void 0},Qf=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)}`)},em=(e,t)=>{switch(e.kind){case"streaming":return t.openStreaming;case"cut":return t.openCut;case"too-many-diagrams":return{text:le.fillLabel(t.tooManyDiagrams.text,{limit:e.limit}),lang:t.tooManyDiagrams.lang}}},tm=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""},ma=({chartContent:e,interaction:t,hideInteractionMenu:n=!1,labels:r,labelsLang:o,sourceLines:s,drawing:a,theme:l="light",exporting:c,held:f})=>{const u=d.useMemo(()=>it(Bn,r,o),[r,o]);if(a!==void 0&&typeof a.drawer!="function")throw new TypeError(`MermaidDiagram: drawing.drawer must be a function (what createMermaidDrawer returns), got ${typeof a.drawer}`);if(c!==void 0&&(cf(c,"MermaidDiagram: exporting"),a===void 0))throw new RangeError("MermaidDiagram: exporting needs drawing (only a diagram the drawing place draws is exported)");f!==void 0&&Qf(f);const h=f!==void 0,m=d.useMemo(()=>a?.drawer===void 0?null:{drawer:a.drawer,maxChars:a.maxChars,maxEdges:a.maxEdges,theme:l},[a?.drawer,a?.maxChars,a?.maxEdges,l]),w=d.useId(),y=d.useId(),p=d.useId(),x=d.useId(),E=d.useId(),T=d.useRef(`mermaid-chart-${Math.random().toString(36).substring(2,15)}`),O=d.useRef(0),b=d.useRef(null),R=d.useRef(null),A=d.useRef(null),B=d.useRef(null),[M,j]=d.useState(!0),[I,X]=d.useState(null),[P,K]=d.useState(null),[ce,pe]=d.useState(null),Z=ce!==null&&ce.diagram===P?ce.texts:Zu,de=d.useRef(null),[Ce,_]=d.useState(0),z=d.useRef(!1),g=Pf(),[S,v]=d.useState(t??ua),C=d.useRef(qo[S]),D=d.useRef(!1),[J,q]=d.useState(!1),[fe,we]=d.useState(!1),[xe,Oe]=d.useState(null),ye=aa();d.useEffect(()=>{t&&v(t)},[t]),d.useEffect(()=>{C.current=qo[S],B.current?.refresh()},[S]),d.useEffect(()=>{if(j(!0),X(null),K(null),h){j(!1);return}const N=e.trim();if(N===""){j(!1);return}const G=b.current;if(!G)throw new Error("[@aiquants/markdown] MermaidDiagram: the measuring element is not mounted");const ee=m===null?{setup:jf()}:{frame:m};let V=!1,ke=0,be=null,ne=G.offsetWidth,he=null,ze,We;const ht=()=>{Te.disconnect(),clearTimeout(ze)},Me=Q=>{he=null,ht(),X(Q),K(null),j(!1)},Ie=(Q,ve)=>{if(Hf(Q)&&!z.current){z.current=!0,We=setTimeout(()=>_(ue=>ue+1),Bf);return}Me(wn(Q,ve))},Ge=(Q,ve)=>{const{type:ue}=Q;he=ue,K(Q),j(!1),ue===null||!Vo.has(ue)?Te.disconnect():ne!==ve&&Be()},$e=(Q,ve,ue)=>{const k={source:N,theme:Q.theme,form:"shown",width:ve,fontFamily:getComputedStyle(G).fontFamily,lang:tm(G),maxChars:Q.maxChars,maxEdges:Q.maxEdges};new Promise($=>$(Q.drawer(k))).then($=>{if(!ue())return;if("failure"in $){Me(Zf($.failure));return}const U=sa($.diagram);if(U===void 0){Me({label:"renderFailed"});return}Ge({cleaned:U,request:k,type:U.getAttribute("aria-roledescription")},ve)}).catch($=>{ue()&&(console.error(`[MermaidDiagram ${T.current}] Error drawing Mermaid diagram in the drawing place:`,$),Me(wn($,"renderFailed")))})},Se=Q=>{O.current+=1;const ve=O.current;ke=ve,be=Q;const ue=()=>!V&&ve===ke;if("frame"in ee){$e(ee.frame,Q,ue);return}const{setup:k}=ee,$=async()=>{const U=await k.catch(()=>null);if(U===null||"cause"in U||!ue())return null;const ge=Uf(Q);try{return await U.library.render(`${T.current}-${ve}`,N,ge)}finally{ge.remove()}};Ko=Ko.then(()=>ue()?$().then(U=>{if(!(U===null||!ue())){if(typeof U.svg!="string"||U.svg.length===0){Me({label:"emptyDrawing"});return}Ge({svg:U.svg,bindFunctions:typeof U.bindFunctions=="function"?U.bindFunctions:null,type:U.diagramType},Q)}}).catch(U=>{ue()&&(console.error(`[MermaidDiagram ${T.current}] Error rendering Mermaid diagram:`,U),Ie(U,"renderFailed"))}):Promise.resolve())},Be=()=>{clearTimeout(ze),ze=setTimeout(()=>{ne>0&&ne!==be&&Se(ne)},$f)},Je=()=>{const Q=G.offsetWidth;if(Q!==ne){if(ne=Q,be===null){Q>0&&Se(Q);return}he!==null&&Vo.has(he)&&Be()}},Te=new ResizeObserver(Je);return Te.observe(G),"setup"in ee&&ee.setup.then(Q=>{!V&&"cause"in Q&&Me(wn(Q.cause,"initializationFailed"))},Q=>{V||(console.error(`[MermaidDiagram ${T.current}] Error loading Mermaid:`,Q),Ie(Q,"initializationFailed"))}),ne>0&&Se(ne),()=>{V=!0,ht(),clearTimeout(We)}},[e,Ce,m,h]),d.useEffect(()=>{const N=R.current;if(!N)return;const G=()=>{de.current=null,B.current=null,A.current&&(Yo(A.current),A.current=null),D.current=!1,q(!1)};if(!P){N.innerHTML="",G();return}let ee;if("svg"in P){N.innerHTML=P.svg;const ne=N.querySelector("svg");ee=ne===null?null:{svg:ne,moved:ne}}else{const{host:ne,svg:he}=zu(N,P.cleaned);ee={svg:he,moved:ne}}let V=!1,ke;const be=[];if(ee!==null){const{svg:ne,moved:he}=ee;let ze;try{ze=wf(ne.getAttribute("viewBox"))}catch(Me){console.error(`[MermaidDiagram ${T.current}] Cannot size the drawing:`,Me),X(wn(Me,"renderFailed")),K(null);return}de.current=ne,pe({diagram:P,texts:Qu(ne)});const We=ze===null?null:ze.inline;ze!==null&&ne.style.setProperty(Xf,String(ze.inline/ze.block));const ht=()=>{if(V)return;const Me=ne.getBBox();if(!Me||Me.width===0||Me.height===0){ke=setTimeout(ht,100);return}A.current&&Yo(A.current);const Ie=zs(he,{startScale:1,startX:0,startY:0,minScale:1,maxScale:1,origin:"0 0",step:kn,animate:!1,noBind:!0,cursor:"",overflow:"",touchAction:Uo(C.current,!1)});A.current=Ie;let Ge={minScale:1,maxScale:1};const $e=()=>{const L=Ie.getPan();return{scale:Ie.getScale(),x:L.x,y:L.y}},Se=()=>{const L=N.getBoundingClientRect(),H=ne.getBoundingClientRect(),{scale:F,x:Y,y:Re}=$e();return{frameRect:L,frame:{inline:L.width,block:L.height},drawing:{origin:{x:H.left-L.left-F*Y,y:H.top-L.top-F*Re},inline:H.width/F,block:H.height/F}}},Be=()=>{if(V)return;const{frame:L,drawing:H}=Se(),F=kf(Ie.getScale(),H,L);D.current=F,q(F),cn(F),Ie.setOptions({touchAction:Uo(C.current,F)}),N.style.cursor=or(C.current,k?.kind==="pan"&&k.mouse)},Je=()=>{const{drawing:L}=Se();L.inline<=0||(Ge=Sf(Ef(L.inline,We)),Ie.setOptions({minScale:Ge.minScale,maxScale:Ge.maxScale}))},Te=L=>{const H=$e(),{frame:F,drawing:Y}=Se(),Re=vf({...L,scale:rr(L.scale,Ge)},Y,F);return Re.scale===H.scale&&Re.x===H.x&&Re.y===H.y?!1:(Ie.zoom(Re.scale,{animate:!1,force:!0,silent:!0}),Ie.pan(Re.x,Re.y,{animate:!1,force:!0}),Be(),!0)},Q=(L,H)=>{const{drawing:F}=Se();return Te(Gt($e(),rr(L,Ge),H,H,F))},ve=L=>{const H=N.getBoundingClientRect();return{x:L.x-H.left,y:L.y-H.top}};B.current={zoomBy:L=>{const{frame:H}=Se();Q(Ie.getScale()*Math.exp(L*kn),{x:H.inline/2,y:H.block/2})},panBy:(L,H)=>{const{drawing:F}=Se(),Y=$e();return Te(Gt(Y,Y.scale,{x:0,y:0},{x:L,y:H},F))},reset:()=>{Te({scale:1,x:0,y:0})},panSteps:()=>{const{frame:L}=Se();return{x:Ho(L.inline),y:Ho(L.block)}},refresh:Be};const ue=new Map;let k=null;const $=L=>({x:L.clientX,y:L.clientY}),U=()=>{const L=[...ue.values()];return L.length===2?[L[0],L[1]]:null},ge=L=>{if(ue.has(L.pointerId)&&ue.set(L.pointerId,$(L)),k?.kind==="pinch"){const H=U();if(H===null)return;const F=Tf(k.last,H);if(k={kind:"pinch",last:H},F===null)return;const{drawing:Y}=Se(),Re=$e();Te(Gt(Re,rr(Re.scale*F.ratio,Ge),ve(F.from),ve(F.to),Y));return}if(k?.kind==="pan"&&k.pointerId===L.pointerId){const H=$(L),{drawing:F}=Se(),Y=$e();Te(Gt(Y,Y.scale,ve(k.last),ve(H),F)),k={...k,last:H}}},Ve=()=>{window.removeEventListener("pointermove",ge),window.removeEventListener("pointerup",Qe),window.removeEventListener("pointercancel",Qe)},Ke=()=>{Ve(),window.addEventListener("pointermove",ge),window.addEventListener("pointerup",Qe),window.addEventListener("pointercancel",Qe)},Qe=L=>{if(ue.delete(L.pointerId),k?.kind==="pinch"){const[H]=[...ue.entries()];k=H!==void 0&&nr(C.current,{button:0,shiftKey:!1,pointerType:L.pointerType},D.current)?{kind:"pan",pointerId:H[0],last:H[1],mouse:!1}:null}else k?.kind==="pan"&&k.pointerId===L.pointerId&&(k=null);k===null&&ue.size===0&&Ve(),N.style.cursor=or(C.current,k?.kind==="pan"&&k.mouse)},wt=L=>{const H=C.current;if(L.pointerType==="touch"||L.pointerType==="pen"){ue.set(L.pointerId,$(L)),Ke();const F=U();F!==null&&H.zoom?k={kind:"pinch",last:F}:ue.size>1?k?.kind==="pan"&&!k.mouse&&(k=null):nr(H,L,D.current)&&(k={kind:"pan",pointerId:L.pointerId,last:$(L),mouse:!1});return}nr(H,L,D.current)&&(k={kind:"pan",pointerId:L.pointerId,last:$(L),mouse:!0},N.style.cursor=or(H,!0),Ke(),L.preventDefault())},ln=L=>{k!==null&&!(k.kind==="pan"&&k.mouse)&&L.cancelable&&L.preventDefault()};let Ft=!1;const cn=L=>{L!==Ft&&(Ft=L,L?N.addEventListener("touchmove",ln,{passive:!1}):N.removeEventListener("touchmove",ln))},qn=L=>{const[H]=L.composedPath();if(!(H instanceof Element)||H===ne||!ne.contains(H))return;const F=N.getBoundingClientRect(),Y=H.getBoundingClientRect(),Re={x:Wo(Y.left-F.left,Y.right-F.left,F.width),y:Wo(Y.top-F.top,Y.bottom-F.top,F.height)};if(Re.x===0&&Re.y===0)return;const{drawing:at}=Se(),qt=$e();Te(Gt(qt,qt.scale,{x:0,y:0},Re,at))},dn=L=>{if(!bf(C.current,L))return;const H=L.deltaY===0?L.deltaX:L.deltaY;H!==0&&(L.preventDefault(),Q(Ie.getScale()*Math.exp(Math.sign(-H)*kn/pf),ve($(L))))},un=new ResizeObserver(()=>{N.getBoundingClientRect().width<=0||(Je(),Te($e()),Be())});N.addEventListener("pointerdown",wt),N.addEventListener("focusin",qn),N.addEventListener("wheel",dn,{passive:!1}),he.addEventListener("panzoomchange",Be),un.observe(N),be.push(()=>{N.removeEventListener("pointerdown",wt),N.removeEventListener("focusin",qn),cn(!1),N.removeEventListener("wheel",dn),he.removeEventListener("panzoomchange",Be),un.disconnect(),Ve()}),Je(),Be()};ht()}return"svg"in P&&P.bindFunctions&&P.bindFunctions(N),()=>{V=!0,clearTimeout(ke);for(const ne of be)ne();G()}},[P]),d.useEffect(()=>{const N=de.current;P===null||N===null||ef(N,P.type,u)},[P,u]);const Le=d.useCallback(N=>{const G=B.current;if(G===null||N.target!==N.currentTarget||N.altKey||N.ctrlKey||N.metaKey)return;const ee=G.panSteps();let V;switch(N.key){case"ArrowLeft":V=G.panBy(ee.x,0);break;case"ArrowRight":V=G.panBy(-ee.x,0);break;case"ArrowUp":V=G.panBy(0,ee.y);break;case"ArrowDown":V=G.panBy(0,-ee.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&&N.preventDefault()},[]),De=!M&&I===null&&f===void 0,Ee=De&&fe,Ze=c!==void 0&&m!==null&&De&&!fe&&P!==null&&"cleaned"in P?{drawer:m.drawer,shown:P.request,accTitle:Z.title,exporting:c}:null,xt=Ze!==null,st=d.useMemo(()=>Ee?Vf:[...J?["pan-left","pan-up","pan-down","pan-right"]:[],...n?[]:["mode"],"zoom-in","zoom-out","reset",...xt?Kf:[],"source",yt],[n,J,Ee,xt]),{onKeyDown:Ae,onFocus:Pe,tabIndexOf:te}=Gr(st,kt),{fullscreen:W,toggle:dt,dialogProps:me,rootProps:Ue}=Br(kt,De),je=e.trim(),Ne=(N,G,ee,V,ke=!1)=>i.jsx("button",{type:"button",[kt]:N,tabIndex:te(N),onClick:ee,style:ke?Wf:void 0,className:Et,"aria-label":u[G].text,lang:u[G].lang,children:V},N),tt=N=>{const G=B.current;if(G===null)return;const ee=G.panSteps();G.panBy(N.x*ee.x,N.y*ee.y)},St=()=>{Oe(null),we(N=>!N)},He=N=>Oe(G=>qr(G,N)),Ot=N=>{const G=ye();Hr(N.currentTarget,je).then(ee=>{G.aborted||He(u[ee==="copied"?"copiedSource":"copySourceFailed"])})},ut=(N,G)=>{const ee=ye(),V=b.current?.ownerDocument.defaultView??null,ke=V?.navigator.clipboard;if(V===null||ke===void 0||typeof V.ClipboardItem!="function"||typeof ke.write!="function"){He(u.copyDiagramFailed);return}let be=null;const ne=Fo(N.drawer,N.shown,G,N.exporting.pngScale,V);ne.catch(he=>{be=he}),$t(()=>ke.write([new V.ClipboardItem({[G==="png"?af:Wr]:ne,"text/plain":new V.Blob([je],{type:"text/plain"})})])).then(()=>{ee.aborted||He(u.copiedDiagram)},he=>{if(!ee.aborted){if(be instanceof Tr){He(u[Go[be.reason]]);return}console.error(`[MermaidDiagram ${T.current}] Could not copy the diagram:`,be??he),He(u.copyDiagramFailed)}})},ft=(N,G)=>{const ee=ye(),V=b.current?.ownerDocument,ke=V?.defaultView??null;if(V===void 0||ke===null){He(u.saveFailed);return}let be;try{be=N.exporting.fileName({index:N.exporting.index,accTitle:N.accTitle,format:G})}catch(he){console.error(`[MermaidDiagram ${T.current}] The naming function of the diagram's file threw:`,he),He(u.saveFailed);return}if(typeof be!="string"||be===""){console.error(`[MermaidDiagram ${T.current}] The naming function of the diagram's file answered no name:`,be),He(u.saveFailed);return}const ne=be;Fo(N.drawer,N.shown,G,N.exporting.pngScale,ke).then(he=>{ee.aborted||(ia(he,ne,V),He({text:le.fillLabel(u.saveStarted.text,{name:ne}),lang:u.saveStarted.lang}))}).catch(he=>{if(!ee.aborted){if(he instanceof Tr){He(u[Go[he.reason]]);return}console.error(`[MermaidDiagram ${T.current}] Could not save the diagram:`,he),He(u.saveFailed)}})},mt=N=>Z.title===null?N:`${p} ${N}`;let bt;if(f!==void 0){const N=em(f,u);bt=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:N.lang,children:N.text}),i.jsx("pre",{"data-aqmd-mermaid-source":"",children:i.jsx("code",{children:je})})]})}else if(M)bt=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:u.loading.lang,children:[i.jsx("span",{"aria-hidden":"true",children:"🌀"})," ",u.loading.text]})});else if(I!==null){const N=Jf(I,u);bt=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:u.errorPrefix.lang,children:u.errorPrefix.text}),i.jsx("span",{lang:N.lang,children:N.text})]}),i.jsx("pre",{"data-aqmd-mermaid-source":"",children:i.jsx("code",{children:je})}),i.jsxs("button",{type:"button","data-aqmd-mermaid-retry":"",onClick:()=>{z.current=!1,X(null),_(G=>G+1)},lang:u.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(xr,{className:"h-4 w-4"}),u.retry.text]})]})}else{const N=u[g?"interactionModeTouch":"interactionMode"],G=g?mf.map(V=>({value:V,label:u[Cf[V]],checked:hf[S]===V})):ff.map(V=>({value:V,label:u[Nf[V]],checked:S===V})),ee=P!==null&&"cleaned"in P?P.request.theme:null;bt=i.jsxs(i.Fragment,{children:[i.jsxs("div",{"data-aqmd-mermaid-toolbar":"",role:"toolbar","aria-labelledby":mt(w),onKeyDown:Ae,onFocus:Pe,className:"mb-1 flex flex-wrap items-start justify-end gap-1",children:[!Ee&&i.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[Ne("pan-left","panLeft",()=>tt({x:1,y:0}),i.jsx(Ac,{size:18}),!J),Ne("pan-up","panUp",()=>tt({x:0,y:1}),i.jsx(jc,{size:18}),!J),Ne("pan-down","panDown",()=>tt({x:0,y:-1}),i.jsx(_c,{size:18}),!J),Ne("pan-right","panRight",()=>tt({x:-1,y:0}),i.jsx(Cc,{size:18}),!J)]}),!Ee&&i.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[!n&&i.jsx(Rr,{buttonHook:{[kt]:"mode"},menuHook:{"data-aqmd-mermaid-menu":""},label:N,icon:i.jsx($c,{size:18}),tabIndex:te("mode"),items:G.map(({value:V,label:ke,checked:be})=>({key:V,label:ke,checked:be,onSelect:()=>v(V)}))}),Ne("zoom-in","zoomIn",()=>B.current?.zoomBy(1),i.jsx(Fs,{size:20})),Ne("zoom-out","zoomOut",()=>B.current?.zoomBy(-1),i.jsx(qs,{size:20})),Ne("reset","resetView",()=>B.current?.reset(),i.jsx(xr,{size:18}))]}),i.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[Ze!==null&&i.jsx(Rr,{buttonHook:{[kt]:"export"},menuHook:{"data-aqmd-mermaid-export-menu":""},label:u.exportMenu,icon:i.jsx(Bs,{size:18}),tabIndex:te("export"),items:[{key:"save-svg",label:u.saveSvg,onSelect:()=>ft(Ze,"svg"),hook:{[sr]:"save-svg"}},{key:"save-png",label:u.savePng,onSelect:()=>ft(Ze,"png"),hook:{[sr]:"save-png"}},...Yf(window)?[{key:"copy-svg",label:u.copySvg,onSelect:()=>ut(Ze,"svg"),hook:{[sr]:"copy-svg"}}]:[]]}),Ze!==null&&Ne("copy-diagram","copyDiagram",()=>ut(Ze,"png"),i.jsx(en,{size:18})),Ee&&Ne("copy-source","copySource",Ot,i.jsx(en,{size:18})),i.jsx("button",{type:"button",[kt]:"source",tabIndex:te("source"),"aria-pressed":fe,onClick:St,className:Et,"aria-label":u.source.text,lang:u.source.lang,children:i.jsx($s,{size:20})})]}),i.jsx(Fr,{hook:kt,fullscreen:W,labels:u,tabIndex:te(yt),onToggle:dt})]}),i.jsx("div",{ref:R,"data-testid":"mermaid-diagram","data-aqmd-mermaid-frame":"","data-aqmd-mermaid-overflowing":J?"true":"false",hidden:Ee,role:"group",tabIndex:0,"aria-labelledby":mt(w),"aria-describedby":Z.description===null?void 0:x,onKeyDown:Le,className:ee===null?"mermaid mermaid-diagram-container bg-white dark:bg-gray-400":"mermaid mermaid-diagram-container",style:ee===null?void 0:{backgroundColor:Us[ee].ground}}),Ee&&i.jsx("pre",{"data-aqmd-mermaid-source":"",tabIndex:0,role:"region","aria-labelledby":mt(E),children:i.jsx("code",{children:je})}),i.jsx(Ur,{hook:Gf,notice:xe})]})}return i.jsxs("div",{className:"relative","data-aqmd-mermaid":"","data-aqmd-mermaid-view":De?fe?"source":"diagram":void 0,"data-source-lines":s,...Ue,children:[i.jsx("span",{id:w,hidden:!0,lang:u.diagram.lang,children:u.diagram.text}),i.jsx("span",{id:y,hidden:!0,lang:u.fullscreenDialog.lang,children:u.fullscreenDialog.text}),Ee&&i.jsx("span",{id:E,hidden:!0,lang:u.sourceRegion.lang,children:u.sourceRegion.text}),Z.title!==null&&i.jsx("span",{id:p,hidden:!0,children:Z.title}),Z.description!==null&&i.jsx("span",{id:x,hidden:!0,children:Z.description}),i.jsxs("dialog",{...me,"aria-labelledby":mt(W?y:w),children:[i.jsx("div",{ref:b,"data-aqmd-mermaid-measure":!0,"aria-hidden":"true",style:Ff}),bt]})]})};ma.displayName="MermaidDiagramInternal";const Vr=d.memo(ma),nm="unicodeTextInMathMode",rm="noCharacterMetrics",om="var(--aqmd-math-error, #cc0000)",sm=/^No character metrics for '.+' in style '.+' and mode '.+'$/su,am="consoleCommand",im=e=>{const t=(n,r)=>o=>(r(o),e(am,`${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())}},ha=(e,t)=>{const n=`${t?"display":"inline"}:${e}`,r=Tt.get(n);if(r!==void 0)return Tt.delete(n),Tt.set(n,r),r;const o=cm(e,t);return Tt.set(n,o),Tt.size>lm&&Tt.delete(Tt.keys().next().value),o},lm=610,Tt=new Map,cm=(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"&&sm.test(a)){r(rm,a);return}o.apply(console,s)};try{const s=gi.renderToString(e,{displayMode:t,throwOnError:!1,errorColor:om,macros:im(r),strict:(a,l)=>(a!==nm&&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 dm=[["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"}]],um=se("copy-check",dm);const fm=[["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"}]],mm=se("copy-x",fm),hm=2e3,pa=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),hm);return()=>clearTimeout(c)},[r]);const a=c=>{s.current+=1;const f=s.current;Hr(c.currentTarget,t).then(u=>{s.current===f&&o({notice:u==="copied"?"copied":"copyFailed",press:f})})},l=r===null?en:r.notice==="copied"?um:mm;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)})]})}),ga=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}},pm=e=>e.nodeType===e.TEXT_NODE,_r=(e,t,n)=>pm(e)?Math.min(t,e.length):n;class gm extends d.Component{getSnapshotBeforeUpdate(){const t=this.props.root.current;return t===null?null:ga(t)}componentDidUpdate(t,n,r){if(!r)return;const{selection:o}=r;if(o.anchorNode!==r.anchorNode||o.focusNode!==r.focusNode)return;const s=_r(r.anchorNode,r.anchorOffset,o.anchorOffset),a=_r(r.focusNode,r.focusOffset,o.focusOffset);s===o.anchorOffset&&a===o.focusOffset||o.setBaseAndExtent(r.anchorNode,s,r.focusNode,a)}render(){return null}}const Xo=(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}},ym=(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},Zo=(e,t,n,r)=>{if(n===t.node)return[t.node,_r(t.node,t.offset,r)];if(t.within===null||n===null||!t.within.ancestors.includes(n))return null;const o=ym(e,t.within.text);return o===null?[n,r]:o};class xm extends d.Component{getSnapshotBeforeUpdate(){const t=this.props.root.current;if(t===null)return null;const n=ga(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:Xo(t,o,s)},focus:{node:a,offset:l,within:Xo(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=Zo(o,r.anchor,s.anchorNode,s.anchorOffset),c=Zo(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 bm=[["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"}]],wm=se("align-horizontal-space-around",bm);const Em=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],Sm=se("chevron-down",Em);const vm=[["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"}]],km=se("fold-horizontal",vm);const Tm=[["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"}]],Rm=se("fold-vertical",Tm);const _m=[["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"}]],Om=se("highlighter",_m);const Am=[["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"}]],Nm=se("ruler",Am);const Cm=[["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"}]],Lm=se("unfold-horizontal",Cm);const jm=[["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"}]],Mm=se("unfold-vertical",jm),ya=24,Im=1,Dm=1,ar=24,xa=e=>{if(e===void 0)return ar;if(!Number.isInteger(e)||e<ar)throw new RangeError(`[@aiquants/markdown] the size of a document table's tap-scroll circle must be a whole number of at least ${ar} CSS px (WCAG 2.5.8); got ${String(e)}`);return e},Pm=Object.freeze({}),ir=e=>{const{rows:t,cols:n}=jn.measureTsv(e);return t*n},zm=26,$m=(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]},Bm=(e,t)=>Math.max(1,Math.min(e.visibleRows,t)),Fm=3,qm=e=>Math.max(1,Math.min(Fm,e)),lr=(e,t,n)=>((n?qe.SPREADSHEET_COLUMN_HEADER_HEIGHT_PX:0)+e*ya+qe.SPREADSHEET_SCROLLBAR_SIZE_PX)*t,Um=1,Jo=e=>Math.ceil(e)+Um,Hm=(e,t)=>e>=t,Ln=e=>Math.round(e*100),Qo=e=>{const t=qe.SPREADSHEET_ZOOM_STEPS.find(n=>Ln(n)===e);if(t===void 0)throw new RangeError(`[@aiquants/markdown] no spreadsheet zoom step shows as ${String(e)} %`);return t},Wm=(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},Kr=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))},En=e=>Kr(jn.parseTsv(e)),Gm=["format","hyperlink","note","comments","validation"],Vm=(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(Gm.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"}},Km=e=>{const t=Kr(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 jn.serializeTsv(t).replaceAll(`\r
10
+ `,`
11
+ `)},Ym=(e,t)=>{const n=e.indexOf(t);return n===-1?{echo:!1,pending:[]}:{echo:!0,pending:e.slice(n+1)}},Xm=(e,t,n,r,o)=>{const s=o==="down"?1:o==="up"?-1:0,a=o==="right"?1:o==="left"?-1:0,l=(h,m)=>h>=0&&h<t&&m>=0&&m<n,c=(h,m)=>e(h,m)!=="";let f=r.row+s,u=r.col+a;if(!l(f,u))return{row:r.row,col:r.col};if(c(r.row,r.col)&&c(f,u)){for(;l(f+s,u+a)&&c(f+s,u+a);)f+=s,u+=a;return{row:f,col:u}}for(;l(f,u);){if(c(f,u))return{row:f,col:u};f+=s,u+=a}return{row:f-s,col:u-a}},Zm=/^(?:https?:\/\/|mailto:|tel:)\S+$/iu,Jm=e=>Zm.test(e)?e:void 0,Qm=(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}`},eh=Object.freeze(["decreaseColumnWidth","increaseColumnWidth","autoFitColumnWidth","decreaseRowHeight","increaseRowHeight"]),th=()=>{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)})}},Lt="data-aqmd-spreadsheet-control",nh=Object.freeze(["zoom-in","zoom-out","reset-zoom","highlight","track-size","copy","save","save-menu",yt]),rh=({labels:e,labelledBy:t,rows:n,cols:r,canZoomIn:o,canZoomOut:s,zoom:a,onZoom:l,onResetZoom:c,highlighted:f,onToggleHighlight:u,onCopy:h,onSave:m,fullscreen:w,onToggleFullscreen:y,gridReady:p,activeCell:x,onTrackSize:E})=>{const{onKeyDown:T,onFocus:O,tabIndexOf:b}=Gr(nh,Lt),[R,A]=d.useState(!1),B=d.useId(),M=d.useRef(null),j=R&&p,I=(K,ce,pe,Z,de,Ce,_=Et)=>i.jsx("button",{type:"button",[Lt]:K,tabIndex:b(K),onClick:de?pe:void 0,"aria-disabled":de?void 0:"true","aria-pressed":Ce,className:_,"aria-label":ce.text,lang:ce.lang,children:Z}),X=Ln(a),P={text:le.fillLabel(e.resetZoom.text,{percent:X}),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:O,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:le.fillLabel(e.size.text,{rows:n,cols:r})}),i.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[I("zoom-in",e.zoomIn,()=>l(1),i.jsx(Fs,{size:20}),p&&o),I("zoom-out",e.zoomOut,()=>l(-1),i.jsx(qs,{size:20}),p&&s),I("reset-zoom",P,c,i.jsxs("span",{"data-aqmd-spreadsheet-zoom":"",children:[i.jsxs("span",{"data-aqmd-spreadsheet-zoom-widest":"","aria-hidden":"true",children:[Ln(qe.SPREADSHEET_ZOOM_MAX)," %"]}),i.jsxs("span",{children:[X," %"]})]}),p&&a!==1,void 0,Uu)]}),i.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[I("highlight",e.highlight,u,i.jsx(Om,{size:18}),p,f),i.jsx("button",{type:"button",ref:M,[Lt]:"track-size",tabIndex:b("track-size"),onClick:p?()=>A(K=>!K):void 0,"aria-disabled":p?void 0:"true","aria-expanded":j,"aria-controls":j?B:void 0,className:Et,"aria-label":e.trackSize.text,lang:e.trackSize.lang,children:i.jsx(Nm,{size:18})})]}),i.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[I("copy",e.copyAll,h,i.jsx(en,{size:18}),p),I("save",e.saveTsv,()=>m(!1),i.jsx(Bs,{size:18}),!0),i.jsx(Rr,{buttonHook:{[Lt]:"save-menu"},menuHook:{"data-aqmd-spreadsheet-menu":""},label:e.saveMenu,icon:i.jsx(Sm,{size:18}),tabIndex:b("save-menu"),items:[{key:"save-with-bom",label:e.saveTsvWithBom,onSelect:()=>m(!0),hook:{"data-aqmd-spreadsheet-menu-item":"save-with-bom"}}]})]}),i.jsx(Fr,{hook:Lt,fullscreen:w,labels:e,tabIndex:b(yt),onToggle:y})]}),j&&i.jsx(sh,{id:B,labels:e,activeCell:x,onTrackSize:E,onClose:()=>{A(!1),M.current?.focus()}})]})},oh=Object.freeze({decreaseColumnWidth:i.jsx(km,{size:18}),increaseColumnWidth:i.jsx(Lm,{size:18}),autoFitColumnWidth:i.jsx(wm,{size:18}),decreaseRowHeight:i.jsx(Rm,{size:18}),increaseRowHeight:i.jsx(Mm,{size:18})}),sh=({id:e,labels:t,activeCell:n,onTrackSize:r,onClose:o})=>{const s=d.useSyncExternalStore(n.subscribe,n.get,n.get),a={column:qe.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:eh.map(c=>i.jsx("button",{type:"button","data-aqmd-spreadsheet-track-size-control":c,onClick:()=>r(c),className:Et,"aria-label":le.fillLabel(t[c].text,a),lang:t[c].lang,children:oh[c]},c))})},ah=(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)}},ih=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"})})])},lh="\uFEFF",ch="text/tab-separated-values;charset=utf-8",dh=(e,t)=>`${t?lh:""}${jn.serializeTsv(e)}`,uh=(e,t)=>new Blob([dh(e,t)],{type:ch}),ba=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 Tn=null,cr=null;const Or=new Set,fh=e=>(Or.add(e),()=>{Or.delete(e)}),es=()=>Tn!==null?Promise.resolve(Tn):(cr??=import("@aiquants/spreadsheet").then(e=>{Tn=e;for(const t of Or)t();return e},e=>{throw cr=null,e}),cr);class Nt extends Error{reason;constructor(t){super(`[@aiquants/markdown] spreadsheet edit refused: ${t}`),this.name="SpreadsheetEditRefusal",this.reason=t}}const ts=e=>{console.error("[@aiquants/markdown] could not load @aiquants/spreadsheet",e)},ns=Object.freeze({row:!0,column:!0,intersection:!1}),rs=Object.freeze({row:!1,column:!1,intersection:!1}),os=Object.freeze([Object.freeze([""])]),mh=Object.freeze({link:!1}),hh=Object.freeze({enabled:!1}),wa=e=>e.trim().replace(/\s+/g," ").toLowerCase(),ph=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(wa))},gh=e=>{const t=e.trim(),n=t.length>=2&&(t[0]==='"'||t[0]==="'")&&t[t.length-1]===t[0];return wa((n?t.slice(1,-1):t).replace(/\\(.)/g,"$1"))},yh=(e,t)=>{const n=ph(t);return e.fontfaces.some(r=>n.has(gh(r.family)))},xh=Object.freeze({"data-aqmd-spreadsheet-notice":""}),bh=({matrix:e,headerRows:t,footerRows:n,visibleRows:r,headings:o,autofit:s,frame:a})=>{const l=Math.min(e[0].length,zm),c=$m(e,r,t,n),f=Array.from({length:l},(y,p)=>p),u=c[0].index>0,h=c[c.length-1].index<e.length-1,m=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&&u?"":void 0,"data-aqmd-spreadsheet-static-more-rows":a&&h?"":void 0,"data-aqmd-spreadsheet-static-more-columns":a&&m?"":void 0,children:[s&&i.jsxs("colgroup",{children:[o&&i.jsx("col",{"data-aqmd-spreadsheet-static-band":""}),f.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",{}),f.map(y=>i.jsx("td",{children:qe.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))})]})},wh=e=>{try{return{options:le.parseSpreadsheetOptions(e),unreadWord:null}}catch(t){if(t instanceof le.SpreadsheetOptionsError)return{options:null,unreadWord:t.word};throw t}},Ea=({tsv:e,meta:t,sourceLines:n,editor:r,locale:o="en",labels:s,labelsLang:a,layout:l="inline",tapScrollCircle:c,tapScrollCircleShownBy:f="host",scrollBarControls:u})=>{if(!Object.hasOwn(le.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(f!=="host"&&f!=="options")throw new RangeError(`[@aiquants/markdown] unsupported spreadsheet tap-scroll circle chooser "${String(f)}" (host and options are supported)`);const h=d.useMemo(()=>it(le.SPREADSHEET_BLOCK_LABEL_CATALOGS[o],s,a),[o,s,a]),{options:m,unreadWord:w}=d.useMemo(()=>wh(t),[t]),y=d.useMemo(()=>ir(e),[e]),p=y>qe.SPREADSHEET_MAX_OPERATION_CELLS,x=d.useMemo(()=>It.parseSourceLines(n)?.first??null,[n]),[E,T]=d.useState(null),O=`${n??""}
12
+ ${e}`,b=E===O,R=r!==void 0&&x!==null&&!b?r:void 0,A=R!==void 0,B=A&&m!==null&&m.footerRows===0?Im:0,M=A?Dm:0,[j,I]=d.useState(()=>p?os:En(e)),[X,P]=d.useState(0),K=d.useRef(e),ce=d.useRef([]),pe=d.useMemo(()=>Wm(j,B,M),[j,B,M]),Z=d.useRef(pe);Z.current=pe;const de=d.useSyncExternalStore(fh,()=>Tn,()=>null),[Ce,_]=d.useState(!1),z=Ce&&de===null,g=m===null?null:m.zoomPercent,[S,v]=d.useState(()=>g===null?1:Qo(g)),[C,D]=d.useState(g);g!==C&&(D(g),g!==null&&v(Qo(g)));const J=m!==null&&m.toolbar===0?rs:ns,[q,fe]=d.useState(J),[we,xe]=d.useState(J);J!==we&&(xe(J),fe(J));const[Oe,ye]=d.useState(null),{fullscreen:Le,toggle:De,dialogRef:Ee,dialogProps:Ze,rootProps:xt}=Br(Lt,m!==null&&!p&&m.toolbar===1),st=d.useId(),Ae=d.useCallback((k,$={})=>{ye(U=>qr(U,{text:le.fillLabel(h[k].text,$),lang:h[k].lang}))},[h]);d.useEffect(()=>{if(de!==null||m===null||p)return;let k=!0;return es().catch($=>{k&&(ts($),_(!0))}),()=>{k=!1}},[de,m,p]),d.useEffect(()=>{const k=Ym(ce.current,e);if(k.echo){ce.current=k.pending;return}const $=R===void 0||x===null?null:R.read(x),U=$!==null&&ir($)<=qe.SPREADSHEET_MAX_OPERATION_CELLS?$:null;if(U!==null&&U===ce.current.at(-1))return;ce.current=[];const ge=U===null?e:U;ge!==K.current&&(K.current=ge,I(U===null&&p?os:En(ge)),P(Ve=>Ve+1))},[e,p,R,x]);const Pe=d.useCallback(()=>{if(R===void 0||x===null)return;const k=R.read(x);k===null||k===K.current||ir(k)>qe.SPREADSHEET_MAX_OPERATION_CELLS||(ce.current=[],K.current=k,I(En(k)),P($=>$+1))},[R,x]);d.useEffect(()=>R?.subscribe(()=>{ce.current.length>0&&Pe()}),[R,Pe]);const te=d.useCallback(k=>{k(),Pe()},[Pe]),W=d.useMemo(()=>R===void 0?void 0:()=>te(()=>R.undo()),[R,te]),dt=d.useMemo(()=>R===void 0?void 0:()=>te(()=>R.redo()),[R,te]),me=d.useRef(()=>{});me.current=k=>{if(R===void 0||x===null)throw new Nt("readOnly");const $=Vm(Z.current,k);if($.kind==="format-only")throw new Nt("formatRefused");if($.kind==="unchanged")return;const U=Kr($.matrix),ge=Km(U),Ve=R.write({fenceLine:x,expected:K.current,text:ge});switch(Ve){case"written":{const Ke=R.read(x);if(Ke===null)throw new TypeError("[@aiquants/markdown] SpreadsheetEditor.write answered written, but read finds no block on its fence line");K.current=Ke,ce.current=[...ce.current,Ke],I(Ke===ge?U:En(Ke)),P(Qe=>Qe+1),ye(null);return}case"changed":throw Pe(),new Nt("editConflict");case"closesFence":throw new Nt("fenceRefused");case"unwritable":throw T(O),new Nt("unwritable");default:throw new TypeError(`[@aiquants/markdown] SpreadsheetEditor.write answered ${JSON.stringify(Ve)} (written, changed, closesFence or unwritable)`)}};const[Ue]=d.useState(()=>({get rowCount(){return Z.current.length},get colCount(){return Z.current[0].length},getCellText:(k,$)=>Z.current[k][$],applyEdits:(k,$)=>me.current(k),getCellFormat:()=>Pm,getCellHyperlink:(k,$)=>Jm(Z.current[k][$]),findDataEdge:(k,$)=>Xm((U,ge)=>Z.current[U][ge],Z.current.length,Z.current[0].length,k,$)})),je=d.useCallback(k=>{if(!(k instanceof Nt))throw k;Ae(k.reason)},[Ae]),Ne=d.useCallback(k=>Ae(b?"unwritable":"readOnly"),[Ae,b]),tt=d.useCallback(k=>{Ee.current?.ownerDocument.defaultView?.open(k,"_blank","noopener,noreferrer")},[]),St=d.useCallback(({row:k,displayText:$,columnName:U,readOnly:ge})=>le.fillLabel((ge===!0?h.readOnlyCellAnnouncement:h.cellAnnouncement).text,{cell:`${U}${k+1}`,value:$===""?h.emptyCell.text:$}),[h]),He=d.useCallback(({range:k})=>le.fillLabel(h.selectionAnnouncement.text,{range:Qm(k,qe.columnIndexToName)}),[h]),Ot=d.useCallback(({axis:k,index:$,size:U})=>k==="column"?le.fillLabel(h.columnResized.text,{column:qe.columnIndexToName($),size:U}):le.fillLabel(h.rowResized.text,{row:$+1,size:U}),[h]),ut=d.useRef(null),[ft]=d.useState(th),mt=d.useCallback(k=>ft.set(k.active),[ft]),bt=d.useCallback(k=>{ut.current?.executeCommand(k)},[]),N=Ln(S),G=d.useRef(N);d.useLayoutEffect(()=>{C!==null&&(G.current=C)},[C]),d.useEffect(()=>{G.current!==N&&(G.current=N,Ae("zoomed",{percent:N}))},[Ae,N]);const ee=d.useCallback(k=>v($=>qe.clampSpreadsheetZoom(qe.stepSpreadsheetZoom($,k))),[]),V=d.useCallback(()=>v(1),[]),ke=q.row||q.column,be=d.useCallback(()=>fe(k=>k.row||k.column?rs:ns),[]),ne=d.useCallback(()=>{if(de===null)return;const k=Ee.current?.ownerDocument.defaultView;(async()=>{if(k==null)throw new Error("no window");const U=ah(j,de,k.crypto.randomUUID());await ih(U,k.navigator.clipboard,ge=>new k.ClipboardItem(ge))})().then(()=>Ae("copied"),U=>{console.error("[@aiquants/markdown] could not copy the spreadsheet",U),Ae("copyFailed")})},[Ae,j,de]),he=d.useCallback(k=>{const $=Ee.current?.ownerDocument;$!==void 0&&ia(uh(j,k),h.fileName.text,$)},[j,h]),ze=j.length,We=j[0].length,ht=m===null?0:m.frame,Me=d.useMemo(()=>ht===0?void 0:{startRow:0,startCol:0,endRow:ze-1,endCol:We-1},[ht,ze,We]),Ie=m===null?0:m.tapscroll,Ge=d.useMemo(()=>{if(f==="host")return c;const k=xa(c?.size);return Ie===1?{...c,enabled:!0,size:k}:hh},[c,f,Ie]),$e=m===null?0:Bm(m,pe.length),Se=pe.length,Be=m!==null&&l==="inline"&&Hm(m.visibleRows,Se),[Je,Te]=d.useState(null),Q=d.useMemo(()=>{if(m===null)return;const k=m.headings===1,$={"--aqmd-spreadsheet-zoom":String(S)};return l==="fill"?$["--aqmd-spreadsheet-box-min-height"]=`${lr(qm(Se),S,k)}px`:Be?$["--aqmd-spreadsheet-box-height"]=`${Jo(Je===null?lr(Se,S,k):Je.height)}px`:$["--aqmd-spreadsheet-box-height"]=`${lr($e,S,k)}px`,Je!==null&&($["--aqmd-spreadsheet-box-width"]=`${Jo(Je.width)}px`),m.frame>0&&($["--aqsp-frame-width"]=`${m.frame}px`),$},[m,l,Be,Se,$e,S,Je]),ve=Le?h.fullscreenDialog:h.table,ue=de?.Spreadsheet;return d.useLayoutEffect(()=>{const k=ut.current,$=Ee.current;if(m===null||m.autofit!==1||de===null||k===null||$===null)return;const U=Array.from({length:pe[0].length},(Ke,Qe)=>Qe);k.autoFitColumns(U);const ge=$.ownerDocument.fonts;if(ge===void 0)return;const Ve=Ke=>{const Qe=ut.current;Qe!==null&&yh(Ke,getComputedStyle($).fontFamily)&&Qe.autoFitColumns(U)};return ge.addEventListener("loadingdone",Ve),()=>ge.removeEventListener("loadingdone",Ve)},[m,de,pe]),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":Be?"":void 0,...xt,children:[i.jsx("span",{id:st,hidden:!0,lang:ve.lang,children:ve.text}),i.jsxs("dialog",{...Ze,"aria-labelledby":st,children:[m===null?i.jsx("div",{"data-aqmd-spreadsheet-error":"options",role:"alert",lang:h.optionsError.lang,children:le.fillLabel(h.optionsError.text,{word:w,frozenMax:le.SPREADSHEET_OPTION_RULES.header.max,heightMax:le.SPREADSHEET_OPTION_RULES.height.max,zoomSteps:le.SPREADSHEET_ZOOM_STEP_PERCENTS.join(", "),frameMax:le.SPREADSHEET_OPTION_RULES.frame.max})}):p?i.jsx("div",{"data-aqmd-spreadsheet-error":"size",role:"alert",lang:h.tooLarge.lang,children:le.fillLabel(h.tooLarge.text,{cells:new Intl.NumberFormat(o).format(y),max:new Intl.NumberFormat(o).format(qe.SPREADSHEET_MAX_OPERATION_CELLS)})}):i.jsxs(i.Fragment,{children:[m.toolbar===1&&i.jsx(rh,{labels:h,labelledBy:st,rows:ze,cols:We,canZoomIn:S<qe.SPREADSHEET_ZOOM_MAX,canZoomOut:S>qe.SPREADSHEET_ZOOM_MIN,zoom:S,onZoom:ee,onResetZoom:V,highlighted:ke,onToggleHighlight:be,onCopy:ne,onSave:he,fullscreen:Le,onToggleFullscreen:De,gridReady:ue!==void 0,activeCell:ft,onTrackSize:bt}),i.jsx("div",{"data-aqmd-spreadsheet-box":"",style:Q,children:ue===void 0?i.jsx(bh,{matrix:j,headerRows:m.headerRows,footerRows:m.footerRows,visibleRows:$e,headings:m.headings===1,autofit:m.autofit===1,frame:m.frame>0}):i.jsx(ue,{ref:ut,adapter:Ue,dataVersion:X,defaultRowHeight:ya,frozenRows:m.headerRows,headerRows:m.headerRows,frozenTrailingRows:m.footerRows,frozenColumns:m.frozenColumns,enableFillHandle:A,readOnly:!A,labelledBy:st,enableResizeUI:!0,headings:m.headings===1,frame:Me,tapScrollCircleOptions:Ge,scrollBarControls:u,onContentSizeChange:Te,zoom:S,onZoomChange:v,highlight:q,onHighlightChange:fe,popovers:mh,onHyperlinkOpen:tt,onEditRejected:je,onReadOnlyRejected:Ne,onUndoRequest:W,onRedoRequest:dt,formatCellAnnouncement:St,formatSelectionAnnouncement:He,formatResizeAnnouncement:Ot,onSelectionChange:mt,locale:o})})]}),z&&i.jsxs("div",{"data-aqmd-spreadsheet-error":"load",role:"alert",children:[i.jsx("span",{lang:h.loadFailed.lang,children:h.loadFailed.text}),i.jsx("button",{type:"button","data-aqmd-spreadsheet-retry":"",lang:h.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:()=>{_(!1),es().catch(k=>{ts(k),_(!0)})},children:h.retry.text})]}),i.jsx(Ur,{hook:xh,notice:Oe})]})]})};Ea.displayName="SpreadsheetBlock";const Yr=d.memo(Ea),Eh=Object.freeze({light:"solarized-light",dark:"github-dark-high-contrast"}),Sh=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 vh(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,(f,u)=>u.toUpperCase())]=c)}t.style=o;break}case"tabindex":t.tabIndex=Number(r);break;default:t[n]=r}}return t}const kh={margin:"1rem 0"},Sa={margin:"0",padding:"0.8rem 0"},Th=({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(pa,{text:t,labels:n})]}),va=(e,t)=>i.jsx("pre",{ref:t,style:Sa,tabIndex:0,"data-aqmd-code-pending":"",children:i.jsx("code",{children:e})}),Rh=({code:e})=>va(e),ka=(e,t)=>{const n={replace:r=>{if(r instanceof re.Element&&r.name==="pre"){const o=vh(r.attribs);return o.style={...typeof o.style=="object"?o.style:{},...Sa},i.jsx("pre",{...o,ref:t,children:re.domToReact(r.children,n)})}},htmlparser2:{lowerCaseTags:!0}};return re(e,n)},_h=({htmlPromise:e})=>i.jsx(i.Fragment,{children:ka(d.use(e))}),Oh=Object.freeze({__html:""}),Ah=()=>i.jsx("pre",{suppressHydrationWarning:!0,dangerouslySetInnerHTML:Oh}),Nh=()=>()=>{},Ch=()=>!1,Lh=()=>!0,jh=()=>d.useSyncExternalStore(Nh,Ch,Lh)&&typeof document<"u",Mh=/^(diff)?:?(\w+):?([\w.-]*)?/,Ih=new Map([["svg","xml"]]),Dh="text",Ph=e=>{const t=Ih.get(e),n=t===void 0?e:t;return pr.isSpecialLang(n)||Object.hasOwn(pr.bundledLanguages,n)?n:Dh},zh=()=>({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)}}}}),$h=(e,t,n)=>pr.codeToHtml(e,{lang:Ph(t),themes:Eh,defaultColor:!1,colorReplacements:Sh,transformers:n?[zh()]:[]}),Bh=(e,t,n)=>{let r=null,o=null;return{html:()=>(r??=$h(e,t,n).then(s=>(o={html:s},s),s=>{throw o={error:s},s}),r),outcome:()=>o}},Fh=({highlight:e})=>{const t=jh(),[n]=d.useState(()=>t?e:null);return n===e?i.jsx(Ah,{}):i.jsx(_h,{htmlPromise:e.html()})},qh=e=>e+1,Uh=({code:e,highlight:t})=>{const n=d.useRef(null),[,r]=d.useReducer(qh,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?va(e,n):ka(o.html,n),i.jsx(xm,{root:n})]})},Hh=e=>{const t=Mh.exec(e??"");return{isDiff:t?.[1]==="diff",lang:t?.[2]||"text",filename:t?.[3]||void 0}},Xr=({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:f,lang:u,filename:h}=Hh(l);return u===le.SPREADSHEETS_LANGUAGE?i.jsx(Yr,{tsv:c,meta:n?.meta??void 0,sourceLines:r,labelsLang:s,tapScrollCircleShownBy:"options"}):u==="mermaid"?i.jsx(Vr,{chartContent:c,sourceLines:r,labelsLang:s}):i.jsx(Wh,{code:c,lang:u,isDiff:f,filename:h,sourceLines:r,labels:o,labelsLang:s,deferHighlight:a})},Wh=d.memo(function({code:t,lang:n,isDiff:r,filename:o,sourceLines:s,labels:a,labelsLang:l,deferHighlight:c}){const f=d.useMemo(()=>Bh(t,n,r),[t,n,r]),u=d.useMemo(()=>it(Mn,a,l),[a,l]),[h,m]=d.useState(c);return c&&!h&&m(!0),i.jsxs("div",{style:kh,"data-aqmd-code-block":"","data-source-lines":s,children:[i.jsx(Th,{filename:o,code:t,labels:u}),h?i.jsx(Uh,{code:t,highlight:c?null:f}):i.jsx(d.Suspense,{fallback:i.jsx(Rh,{code:t}),children:i.jsx(Fh,{highlight:f})})]})}),Gh=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},Ta=({source:e,placement:t,labels:n,children:r})=>{const[o,s]=d.useState(null),a=Gh(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(pa,{text:e,labels:n})})]})},Ra=(e,t)=>{const n=d.useMemo(()=>{try{return{kind:"rendered",innerHtml:ha(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},Vh=({node:e})=>{const t=Ra(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(Ta,{source:e.value,placement:"block",labels:wi,children:t.kind==="rendered"?i.jsx("article",{className:n,dangerouslySetInnerHTML:t.innerHtml}):i.jsx("article",{className:n,children:t.message})})},_a=Object.freeze({missingImage:{text:"Image not found",lang:"en"}}),nt=new hr.Logger(hr.LogLevel.INFO,"[DifyIFramePlugin]"),Kh="100%",Yh="600px",Xh="0",Zh=e=>typeof e!="object"||e===null||!("type"in e)?null:typeof e.type=="string"?e.type:null,Jh=({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:f}=e,u=d.useCallback(E=>{E.source===null||E.source!==a.current?.contentWindow||!Il(E.origin,t)||Zh(E.data)==="dify-chatbot-iframe-ready"&&(nt.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]),h=d.useCallback(()=>{const E=a.current;if(E)try{if(!E.contentDocument)throw new Error("Cannot access iframe content");r(O=>O&&(s(!1),!1))}catch{nt.info("Crossorigin error detected, showing auth prompt"),s(O=>O||(r(!1),!0))}},[]),m=d.useCallback(()=>{const E=window.open(f,"dify-oauth","width=500,height=600,scrollbars=yes,resizable=yes");if(!E){nt.error("ポップアップがブロックされました");return}const T=setInterval(()=>{if(E.closed){clearInterval(T),nt.info("ポップアップが閉じられました");try{nt.info("ポップアップURL:",E.location.href)}catch(b){nt.info("クロスオリジンのためURLにアクセスできません:",b)}const O=a.current;if(O?.src){const b=O.src;r(R=>R||!0),s(R=>R&&!1),O.src="",setTimeout(()=>{O.src=b,l.current=setTimeout(()=>{nt.warn("認証後タイムアウト: dify-chatbot-iframe-ready not received after auth"),h()},5e3)},100)}}},1e3);nt.info("ポップアップを開きました:"),nt.info("- 初期URL:",f),nt.info("- ウィンドウ名:","dify-oauth"),nt.info("- ウィンドウサイズ: 500x600")},[h,f]);d.useEffect(()=>(window.addEventListener("message",u),()=>{window.removeEventListener("message",u)}),[u]),d.useEffect(()=>{const E=setTimeout(()=>{nt.warn("Timeout: dify-chatbot-iframe-ready not received, checking iframe access"),h()},5e3);return c.current=E,()=>{c.current&&(clearTimeout(c.current),c.current=null)}},[h]),d.useEffect(()=>()=>{l.current&&(clearTimeout(l.current),l.current=null)},[]);const{width:w=Kh,height:y=Yh,frameborder:p=Xh,...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:m,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,...re.attributesToProps({...x,width:w,height:y,frameborder:p},"iframe"),src:f,"data-plugin-type":"dify"})})]})},ss=Object.freeze({dify:Jh}),Qh=e=>Object.hasOwn(ss,e)?ss[e]:null,as=i.jsx(d.Fragment,{}),ep=(e,t,n,r,o,s)=>{const a=t===null?null:Qh(t),l=e.attributes.title===void 0?{title:`${r.text}: ${new URL(e.src).hostname}`,lang:r.lang}:{},c=Ml(e,s),f=Xe.frameSandboxKeyOf(c.attributes.sandbox);return i.jsx(cl,{embed:e,label:r,insideAnchor:o,children:a!==null?i.jsx(a,{embed:c,iFrameAllowedDomains:n},f):i.jsx("iframe",{...re.attributesToProps(c.attributes,"iframe"),...l,src:c.src},f)})},Zr=e=>{for(let t=e.parent;t!==null;t=t.parent)if(t instanceof re.Element&&t.name.toLowerCase()==="a")return!0;return!1},Oa=e=>e.some(t=>t instanceof re.Element&&(jr.has(t.name)||Oa(t.children))),tp=(e,t,n,r)=>{const{class:o,"data-link-kind":s,"data-doc-path":a,"data-doc-exists":l,...c}=e.attribs,f=Ms(o,Oa(e.children)),u=c.href??"",h=s,m=h==="external"||Lr(u),w=re.domToReact(e.children,t),y=u!==""&&(r==="untrusted"||!m);if(y&&n)return i.jsx(n,{href:u,kind:m?"external":h,docPath:a,docExists:l===void 0?void 0:l==="true",className:f,attributes:Wl(c),children:w});if(y&&r==="untrusted")return i.jsx(d.Fragment,{children:w});m&&(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",{...re.attributesToProps(c,"a"),className:f,...p,children:w})},Aa=({iFrameAllowedDomains:e,embedLabels:t,frameSandbox:n,linkComponent:r,allowlistContext:o,renderImage:s,renderPlaceholder:a,renderKept:l})=>{const c={replace:f=>{if(!(f instanceof re.Element))return;const u=f.parent instanceof re.Element?f.parent.name:null,h=Dn(f.name,f.attribs,{parentName:u,iFrameAllowedDomains:e,...o});switch(h.action){case"remove":return as;case"unwrap":return i.jsx(d.Fragment,{children:re.domToReact(f.children,c)});case"embed":return ep(h.embed,h.pluginType,e,t.embeddedFrame,Zr(f),n);case"image":return f.attribs={...h.attributes},s===void 0?as:s(f,c)}if(f.attribs={...h.attributes},h.action==="placeholder"){const w=a?.(f,h.link,c);if(w!==void 0)return w}const m=l?.(f,c);if(m!==void 0)return m;if(f.name==="a")return tp(f,c,r,o.allowlist)}};return c},np=e=>/\.[Ss][Vv][Gg]$/u.test(e),Na=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])},Vt="data-aqmd-svg-image-control",rp=Object.freeze({"data-aqmd-svg-image-notice":""}),op=1,sp=Object.freeze(["copy","source",yt]),ap=Object.freeze(["source",yt]),ip=Object.freeze({kind:"failure",retryable:!0}),is=(e,t,n)=>$t(()=>e.read(t,n)),lp=({paragraph:e,image:t,path:n,name:r,reader:o,labels:s})=>{const{[It.SOURCE_LINES_ATTRIBUTE]:a,...l}=e,[c,f]=d.useState(!1),[u,h]=d.useState(0),[m,w]=d.useState(null),[y,p]=d.useState(null),x=d.useId(),E=d.useId(),T=d.useId(),O=d.useRef(null),b=aa(),R=d.useRef(null);d.useEffect(()=>{if(!c)return;const S=new AbortController;return is(o,n,S.signal).then(v=>{S.signal.aborted||w({read:u,answer:v})},v=>{S.signal.aborted||(console.error("[@aiquants/markdown] the image source reader failed without an abort",v),w({read:u,answer:ip}))}),()=>S.abort()},[c,u,n,o]);const A=c&&m!==null&&m.read===u?m.answer:null,B=A!==null&&A.kind==="text"&&!A.truncated?A.text:null,M=!c||B!==null,{onKeyDown:j,onFocus:I,tabIndexOf:X}=Gr(M?sp:ap,Vt),{fullscreen:P,toggle:K,dialogProps:ce,rootProps:pe}=Br(Vt,!0),Z=S=>{p(v=>qr(v,s[S]))},de=()=>{if(p(null),c){f(!1);return}h(S=>S+1),f(!0)},Ce=()=>{O.current?.focus(),h(S=>S+1)},_=(S,v)=>{const C=b();Hr(S.currentTarget,v).then(D=>{C.aborted||Z(D==="copied"?"copied":"copyFailed")})},z=S=>{const v=b(),C=S.currentTarget.ownerDocument.defaultView,D=C?.navigator.clipboard;if(C===null||D===void 0||typeof C.ClipboardItem!="function"||typeof D.write!="function"){Z("copyImageFailed");return}const J=R.current,q=J===null?null:J.querySelector("img"),fe=q===null?null:q.getBoundingClientRect(),we=fe===null?{width:0,height:0}:{width:fe.width,height:fe.height};let xe=!1;const Oe=is(o,n,v).then(ye=>{if(ye.kind!=="text"||ye.truncated)throw xe=!0,new Error("[@aiquants/markdown] the SVG image cannot be copied whole");return ca(ye.text,we,op,C).catch(Le=>{throw xe=!0,console.error("[@aiquants/markdown] could not draw the SVG image as a PNG",Le),Le})},ye=>{throw xe=!0,v.aborted||console.error("[@aiquants/markdown] the image source reader failed without an abort",ye),ye});Oe.catch(()=>{}),$t(()=>D.write([new C.ClipboardItem({"image/png":Oe})])).then(()=>{v.aborted||Z("copiedImage")},ye=>{v.aborted||(xe||console.error("[@aiquants/markdown] could not copy the SVG image",ye),Z("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:Ce,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(xr,{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:le.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:R,...re.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,...pe,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:le.fillLabel(s.fullscreenDialog.text,{name:r})}),i.jsxs("dialog",{...ce,"aria-labelledby":P?E:x,children:[i.jsxs("div",{"data-aqmd-svg-image-toolbar":"",role:"toolbar","aria-labelledby":x,onKeyDown:j,onFocus:I,className:"mb-1 flex flex-wrap items-center justify-end gap-1",children:[M&&i.jsx("button",{type:"button",[Vt]:"copy",tabIndex:X("copy"),onClick:S=>B===null?z(S):_(S,B),className:Et,"aria-label":B===null?s.copyImage.text:s.copy.text,lang:B===null?s.copyImage.lang:s.copy.lang,children:i.jsx(en,{size:18})}),i.jsx("button",{ref:O,type:"button",[Vt]:"source",tabIndex:X("source"),"aria-pressed":c,onClick:de,className:Et,"aria-label":s.source.text,lang:s.source.lang,children:i.jsx($s,{size:20})}),i.jsx(Fr,{hook:Vt,fullscreen:P,labels:s,tabIndex:X(yt),onToggle:K})]}),g,i.jsx(Ur,{hook:rp,notice:y})]})]})},Fn=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"},...le.FULLSCREEN_CONTROL_LABEL_CATALOGS.en,fullscreenDialog:{text:"{name} (full screen)",lang:"en"}}),cp=zt(Fn),dp=({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(Gi,{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})]})]}),up=(e,t,n)=>{const{alt:r,"data-asset-src":o}=e.attribs;if(Jr(e.attribs)===void 0||Qr(e.attribs))return i.jsx(dp,{alt:r,target:o,label:t});const s=n.rendered===0;return n.rendered+=1,i.jsx("img",{alt:"",...re.attributesToProps({loading:s?"eager":"lazy",decoding:"async",...e.attribs})})},Jr=e=>{const{src:t}=e;return t===void 0||t.trim()===""?void 0:t},Qr=e=>e["data-asset-exists"]==="false",fp=e=>{const{alt:t,title:n,"data-asset-src":r,"data-asset-exists":o}=e.attribs,s=Jr(e.attribs);return{src:s,external:s!==void 0&&Lr(s),alt:t,title:n,assetPath:r,assetExists:o===void 0?void 0:!Qr(e.attribs),insideLink:Zr(e)}},mp=(e,t,n,r)=>{const o=Nl(t,n),s=re.attributesToProps(e.attribs),a=re.domToReact(e.children,r),l={[Rl]:String(t)};if(o<=Tl)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)},hp=d.memo(function({source:t,innerHtml:n,labels:r}){return i.jsx(Ta,{source:t,placement:"flow",labels:r,children:i.jsx("span",{dangerouslySetInnerHTML:n})})}),gt=e=>e.map(t=>t instanceof re.Text?t.data:t instanceof re.Element?gt(t.children):"").join(""),pp=(e,t,n)=>e.map(r=>{if(r instanceof re.Text)return{kind:"text",text:r.data};if(!(r instanceof re.Element))return{kind:"ignored"};if(r.name.toLowerCase()!=="a")return{kind:"element"};const o=Dn(r.name,r.attribs,{parentName:"p",iFrameAllowedDomains:t,...n});return{kind:"link",href:o.action==="keep"?o.attributes.href??null:null}}),gp=(e,t,n,r)=>{const o=e.children,s=Xe.placeholderLinkOf(t,pp(o,r.iFrameAllowedDomains,r.allowlistContext));if(s===null)return;const a=re.domToReact(o,n),l=i.jsx("p",{...re.attributesToProps(e.attribs,"p"),children:a}),c=o.find(m=>m instanceof re.Element),f=r.embeds.linkCardEndpoint,u=f!==null&&c!==void 0&&Xe.isBareLink(gt(c.children),s)?i.jsx(pl,{href:t,endpoint:f,size:rt.linkCardSizeOf(r.embeds),fallback:l}):l,h=vt.resolveEmbed(s,r.embeds.providers);return h===null?u:i.jsx(kl,{resolution:h,caption:a,fallback:u,theme:r.theme,labels:r.embedLabels,frameSandbox:rt.frameSandboxOf(r.embeds)})},yp=(e,t,n)=>{if(Zr(e))return null;const r=e.children.filter(c=>!Pt(c)),[o]=r;if(r.length!==1||!(o instanceof re.Element)||o.name.toLowerCase()!=="img")return null;const s=Dn(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||!np(l)||Jr(s.attributes)===void 0||Qr(s.attributes)?null:{node:o,path:l,name:a!==void 0&&a.trim()!==""?a:l.slice(l.lastIndexOf("/")+1)}},ls=2166136261,cs=16777619,xp=/^[\t\n\f\r ]*$/u,Pt=e=>e instanceof re.Text&&xp.test(e.data),bp=`language-${le.SPREADSHEETS_LANGUAGE}`,Ca=e=>e.name==="code"&&(e.attribs.class??"").split(/[\t\n\f\r ]+/u).includes(bp),La=e=>{let t=ls,n=ls;const r=(l,c)=>{for(let f=0;f<l.length;f+=1){const u=l.charCodeAt(f);n=Math.imul(n^u,cs),c&&(t=Math.imul(t^u,cs))}},o=(l,c)=>{if(l instanceof re.Text)r("",c),r(l.data,c);else if(l instanceof re.Element){r("",c),r(l.name,c);for(const[u,h]of Object.entries(l.attribs))u!==It.SOURCE_LINES_ATTRIBUTE&&(r("",c),r(u,c),r("",c),r(h,c));r("",c);const f=c&&!Ca(l);for(const u of l.children)o(u,f);r("",c)}else r("\x07",c),r(l.data,c)},s=e.filter(l=>!Pt(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 re.Element?a.name:`#${a.type}`}},dr=e=>{const t=e.findIndex(r=>!Pt(r));if(t===-1)return{before:e.map(r=>gt([r])),content:[],after:[]};let n=e.length-1;for(;Pt(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]))}},wp=(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"},Ep=e=>{if(!Number.isSafeInteger(e)||e<1)throw new RangeError(`MarkdownRenderer: maxMermaidDiagrams must be a positive safe integer, got ${String(e)}`)},Sp=Object.freeze({kind:"streaming"}),vp=Object.freeze({kind:"cut"}),kp=(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 Sp;case"truncated":return vp;case"complete":return}},nn=new Map,Tp=(e,{options:t,tally:n,previous:r,rules:o,failureLabel:s})=>{const a=[];if(n.mathReports=a,e==="")return{nodes:[],keys:[],kept:nn,diagnostics:a};const l=Xt(e),c=Rs(l.filter(u=>!Pt(u)).map(u=>La([u])),r,o);let f=0;return{nodes:l.map(u=>{if(Pt(u))return gt([u]);const{key:h,content:m}=c[f];return f+=1,i.jsx(ks,{content:m,label:s,text:()=>gt([u]),children:re.domToReact([u],t)},h)}),keys:c,kept:nn,diagnostics:a}},Rp=(e,t,n,{options:r,tally:o,progress:s,previous:a,rules:l,failureLabel:c})=>{if(t.length===0)return{nodes:dr(Xt(e)).before,keys:[],kept:nn,diagnostics:[]};const f=Ji(e,t).map(m=>{const w=o.images.rendered,y=o.diagrams.rendered,p=n.get(m)?.find(M=>(M.images===0||M.imagesBefore===w)&&(M.diagrams===0||M.diagramsBefore===y)&&(M.openCodeProgress===null||M.openCodeProgress===s));if(p!==void 0)return o.images.rendered+=p.images,o.diagrams.rendered+=p.diagrams,[m,p];const{before:x,content:E,after:T}=dr(Xt(m)),O=[];o.mathReports=O;const b=La(E),R=o.openCode.rendered,A=re.domToReact(E,r),B=o.openCode.rendered>R?s:null;return[m,{element:A,before:x,after:T,shape:b,images:o.images.rendered-w,imagesBefore:w,diagrams:o.diagrams.rendered-y,diagramsBefore:y,diagnostics:O,openCodeProgress:B}]}),u=Rs(f.map(([,m])=>m.shape),a,l),h=new Map;for(const[m,w]of f){const y=h.get(m);y===void 0?h.set(m,[w]):y.includes(w)||y.push(w)}return{nodes:f.flatMap(([m,w],y)=>{const{key:p,content:x}=u[y];return[...w.before,i.jsx(ks,{content:x,label:c,text:()=>gt(dr(Xt(m)).content),children:w.element},p),...w.after]}),keys:u,kept:h,diagnostics:f.flatMap(([,m])=>m.diagnostics)}},_p=Object.freeze([]),Op={keys:[],epoch:void 0,parserOptionsFor:null,kept:nn},ja=({htmlContent:e,blockOffsets:t,blockKeyEpoch:n,streaming:r=!1,truncated:o=!1,theme:s="light",topHeadingLevel:a,iFrameAllowedDomains:l=_p,embeds:c=rt.NO_EMBEDS,embedLabels:f,mermaidInteraction:u,mermaidLabels:h,mermaidDrawing:m,mermaidExporting:w,maxMermaidDiagrams:y,codeBlockLabels:p,displayMathLabels:x,spreadsheetEditor:E,spreadsheetLocale:T,spreadsheetLabels:O,spreadsheetTapScrollCircle:b,spreadsheetScrollBarControls:R,linkComponent:A,missingImageLabel:B,blockFailedLabel:M,labelsLang:j,imageSource:I,svgImageLabels:X,onMathDiagnostics:P,allowlist:K="document",imageComponent:ce,idPrefix:pe})=>{if(Ls(c),xa(b?.size),t!==void 0&&Zi(e,t),n!==void 0&&Qi(n),a!==void 0&&Ol(a),y!==void 0&&Ep(y),w!==void 0&&(da(w,"MarkdownRenderer: mermaidExporting"),m===void 0))throw new RangeError("MarkdownRenderer: mermaidExporting needs mermaidDrawing (only a diagram the drawing place draws is exported)");const Z=d.useMemo(()=>Vl(K,pe),[K,pe]);if(K==="untrusted"&&ce===void 0)throw new RangeError('MarkdownRenderer: allowlist "untrusted" needs imageComponent (the package never renders an image of untrusted text)');if(K==="untrusted"&&A===void 0)throw new RangeError('MarkdownRenderer: allowlist "untrusted" needs linkComponent (the package never renders a link of untrusted text)');if(K==="document"&&ce!==void 0)throw new RangeError('MarkdownRenderer: imageComponent needs allowlist "untrusted" (the images of a document render as written)');if(K==="untrusted"&&I!==void 0)throw new RangeError('MarkdownRenderer: imageSource needs allowlist "document" (every image of untrusted text goes to imageComponent)');if(K==="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(K==="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 de=wp(r,o),Ce=d.useMemo(()=>bs(f,j),[f,j]),_=ba(E),z=Na(I),g=df(w),S=d.useMemo(()=>it(Fn,X,j),[X,j]),v=d.useMemo(()=>it(rn,x,j),[x,j]),{blockFailed:C}=it(Ts,{blockFailed:M},j),{missingImage:D}=d.useMemo(()=>it(_a,{missingImage:B},j),[B,j]),J=d.useRef(null),q=d.useRef(null),fe=d.useEffectEvent(Pe=>{P?.(Pe)}),we=d.useCallback((Pe,te)=>Aa({iFrameAllowedDomains:l,embedLabels:Ce,frameSandbox:rt.frameSandboxOf(c),linkComponent:A,allowlistContext:Z,renderImage:ce===void 0?void 0:W=>i.jsx(ce,{...fp(W)}),renderPlaceholder:(W,dt,me)=>gp(W,dt,me,{embeds:c,theme:s,embedLabels:Ce,iFrameAllowedDomains:l,allowlistContext:Z}),renderKept:(W,dt)=>{if(W.name==="p"&&z!==void 0){const me=yp(W,l,Z);if(me!==null)return i.jsx(lp,{paragraph:W.attribs,image:re.domToReact([me.node],dt),path:me.path,name:me.name,reader:z,labels:S})}if(W.name==="pre"&&W.children.length===1){const me=W.children[0];if(me instanceof re.Element&&me.name==="code"){const Ue=me.attribs.class??"",je=gt(me.children),Ne=W.attribs[It.SOURCE_LINES_ATTRIBUTE];if(Ca(me))return i.jsx(Yr,{tsv:je,meta:me.attribs[le.CODE_META_ATTRIBUTE],sourceLines:Ne,editor:_,locale:T,labels:O,labelsLang:j,tapScrollCircle:b,tapScrollCircleShownBy:"options",scrollBarControls:R});const tt=Object.hasOwn(W.attribs,le.OPEN_CODE_ATTRIBUTE);if(tt&&(Pe.openCode.rendered+=1),Ue.includes("language-mermaid")){const St=Pe.diagrams.rendered;return Pe.diagrams.rendered+=1,i.jsx(Vr,{chartContent:je,interaction:u,labels:h,labelsLang:j,sourceLines:Ne,drawing:m,theme:s,exporting:g===void 0?void 0:{...g,index:St+1},held:kp(St,tt,te,y)})}return i.jsx(Xr,{lang:Ue.replace("language-",""),code:je,theme:s,sourceLines:Ne,labels:p,labelsLang:j,deferHighlight:tt&&te==="streaming"})}}if(W.name==="img")return up(W,D,Pe.images);if(W.name==="span"&&W.attribs.class?.includes("math")){const me=W.attribs.class.includes("display");let Ue=gt(W.children).trim();me?Ue=Ue.replace(/^\\\[/,"").replace(/\\\]$/,""):Ue=Ue.replace(/^\\\(/,"").replace(/\\\)$/,"");try{const{innerHtml:je,diagnostics:Ne}=ha(Ue,me);return Pe.mathReports.push(...Ne),me?i.jsx(hp,{source:Ue,innerHtml:je,labels:v}):i.jsx("span",{dangerouslySetInnerHTML:je})}catch(je){console.error("Failed to render math:",je);return}}if(a!==void 0){const me=Al(W.name);if(me!==void 0)return mp(W,me,a,dt)}}}),[l,Ce,c,A,s,z,S,_,T,O,b,R,u,h,m,g,y,p,j,D,v,a,Z,ce]),xe={images:{rendered:0},diagrams:{rendered:0},openCode:{rendered:0},mathReports:[]},Oe=we(xe,de),ye=d.useRef(Op),Le=ye.current,De=n!==Le.epoch,Ee={options:Oe,tally:xe,progress:de,previous:Le.keys,failureLabel:C},{nodes:Ze,keys:xt,kept:st,diagnostics:Ae}=t===void 0?Tp(e,{...Ee,rules:{inherit:!1,contentOnly:De}}):Rp(e,t,Le.parserOptionsFor===we?Le.kept:nn,{...Ee,rules:{inherit:!0,contentOnly:De}});return d.useEffect(()=>{ye.current={keys:xt,epoch:n,parserOptionsFor:we,kept:st}},[xt,n,we,st]),d.useEffect(()=>{J.current!==e&&(J.current=e,Ae.length>0&&fe(Ae))},[e,Ae]),i.jsxs("div",{ref:q,className:"markdown-body","data-theme":s,"data-aqmd-document":"",children:[Ze,t!==void 0&&i.jsx(gm,{root:q})]})};const Ap=[["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"}]],Np=se("triangle-alert",Ap);const Cp=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 19H5",key:"vjpgq2"}]],Lp=se("text-align-center",Cp);const jp=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 19H3",key:"z6ezky"}]],Mp=se("text-align-start",jp);const Ip=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 19H7",key:"4cu937"}]],Dp=se("text-align-end",Ip);const Pp=[["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"}]],zp=se("list",Pp);const $p=[["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"}]],Bp=se("palette",$p);const Fp=[["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"}]],qp=se("pin",Fp);const Up=[["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"}]],Hp=se("pin-off",Up),Wp=new Set(["UL","OL","LI","DL","DD","BLOCKQUOTE","SECTION","DETAILS"]),Ma=e=>[...e.children].flatMap(t=>Wp.has(t.tagName)?[t,...Ma(t)]:[t]),Gp=(e,t)=>{let n=null;for(const r of Ma(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},Ar=({block:e,offset:t,root:n,scroller:r})=>(e.getBoundingClientRect().top-r.getBoundingClientRect().top-t)/Es(n),ds=e=>{e.scrollTop=e.scroller.scrollTop,e.moved=Ar(e)},us=(e,t)=>{const n=e.scroller.scrollTop-e.scrollTop;return Math.abs(n)>=1&&Math.abs(t-e.moved+n)<1};class Vp extends d.Component{anchor=null;getSnapshotBeforeUpdate(t){const{scroller:n,root:r,documentKey:o,style:s,measure:a,align:l}=this.props;if(s===t.style&&a===t.measure&&l===t.align||o!==t.documentKey||n.scrollTop===0)return null;const f=Gp(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=Ar(o);if(us(o,s)){this.release();return}s!==0&&o.scroller.scrollTo({top:o.scroller.scrollTop+s,behavior:"instant"}),ds(o)}componentWillUnmount(){this.release()}render(){return null}keep(t){this.release(),this.anchor=t,t.scroller.addEventListener("scroll",()=>{us(t,Ar(t))?this.release():ds(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 Kp=e=>`#${e.id}`,Yp=e=>{let t=Number.POSITIVE_INFINITY;for(const n of e)n.depth<t&&(t=n.depth);return t},fs="block truncate py-[max(0px,calc((2.75rem_-_1lh)_/_2))]",Ia=({headings:e,className:t="",onHeadingSelect:n,headingHref:r=Kp,label:o,labelledBy:s})=>{if(e.length===0)return null;const a=Yp(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 f=l.id===""?null:r(l);return i.jsx("li",{style:{paddingLeft:`${(l.depth-a)*1}rem`},children:f===null?i.jsx("span",{className:`${fs} text-gray-600 dark:text-gray-300`,title:l.text,children:l.text}):i.jsx("a",{href:on(f)?f:void 0,className:`${fs} text-gray-600 no-underline hover:text-blue-800 dark:text-gray-300 dark:hover:text-blue-300`,onClick:n===void 0?void 0:u=>n(l,u),title:l.text,children:l.text})},c)})})})},ur="--aqmd-toolbar-block-overlap",Xp="--aqmd-toolbar-block-reach-px",Zp=1/16,Jp=2,Qp=(e,t,n)=>{const r=Jp*Zp/Math.min(1,n);return t>0&&e-t<r&&t-e<1+r?t:Ni(e)},eg=({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?Qp(c/o,s,o):0},Bt=(e,t)=>`${e}${t.charAt(0).toUpperCase()}${t.slice(1)}`,Sn=(e,t)=>Object.fromEntries(Object.keys(t).map(n=>[Bt(e,n),t[n]])),tg=e=>![...Rf,...Of,..._f].includes(e),Da=Object.keys(Bn).filter(tg),{errorPrefix:ng,...rg}=Object.fromEntries(Da.map(e=>[e,Bn[e]])),og=Object.keys(le.SPREADSHEET_BLOCK_LABEL_CATALOGS.en),sg=Object.keys(Fn),ag=Object.keys(Mn),ig=Object.keys(rn),Pa=Object.freeze({loading:{text:"Loading data...",lang:"en"},errorPrefix:ng,defaultErrorTitle:{text:"An error occurred",lang:"en"},..._a,...Ts,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"},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"},...Sn("mermaid",rg),...Sn("svgImage",Fn),...Sn("codeBlock",Mn),...Sn("displayMath",rn),...In}),lg=zt(Pa),cg=(e,t)=>it(Pa,e,t),an=(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)},dg=e=>an(e,Da,t=>t==="errorPrefix"?t:Bt("mermaid",t)),ug=e=>an(e,og,t=>Bt("spreadsheet",t)),fg=e=>an(e,sg,t=>Bt("svgImage",t)),mg=e=>an(e,ag,t=>Bt("codeBlock",t)),hg=e=>an(e,ig,t=>Bt("displayMath",t)),pg=Object.keys(In),gg=e=>{const t={};if(e===void 0)return Object.freeze(t);for(const n of pg){const r=e[n];r!==void 0&&(t[n]=r)}return Object.freeze(t)},yg="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",xg="h-5 w-5 text-gray-600 dark:text-gray-300",bg="[data-aqmd-document]",ms=Object.freeze({left:{labelKey:"alignLeft",Icon:Mp},center:{labelKey:"alignCenter",Icon:Lp},right:{labelKey:"alignRight",Icon:Dp}}),wg=Object.freeze({fill:"measureFill",reading:"measureReading"}),Eg=Object.freeze({default:"colorsDefault",sepia:"colorsSepia","dark-low-glare":"colorsDarkLowGlare","high-contrast":"colorsHighContrast"}),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"}`,Sg="--aqmd-reading-margin-inline",vg=Object.freeze({emptyMessage:{text:"ファイルを選択してください。",lang:"ja"}}),kg="100%",hs=e=>e==="center"?"auto":e==="right"?"auto 0":"0 auto",Nr="24px",$a=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"}),Tg=$a(Nr),Rg=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"}),_g=e=>`calc(100cqi - var(--aqmd-toolbar-inset-inline-end, 0px) - ${e})`,Og=8,ps=800,Ag=16,Ng=(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>ps||Math.hypot(l.clientX-t.clientX,l.clientY-t.clientY)>Ag)&&(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,ps)},Cg=(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 h=s.getBoundingClientRect(),m=Es(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-h.top)/m-Og)))},f=()=>{a!==null&&l===0&&(l=a.requestAnimationFrame(c))};c();const u=new ResizeObserver(f);return u.observe(n),a?.addEventListener("resize",f),a?.visualViewport?.addEventListener("resize",f),a?.visualViewport?.addEventListener("scroll",f),s.ownerDocument.addEventListener("scroll",f,!0),()=>{a!==null&&l!==0&&a.cancelAnimationFrame(l),u.disconnect(),a?.removeEventListener("resize",f),a?.visualViewport?.removeEventListener("resize",f),a?.visualViewport?.removeEventListener("scroll",f),s.ownerDocument.removeEventListener("scroll",f,!0)}},[e,t,n]),r};function fr({menu:e,Icon:t,buttonLabel:n,titleLabel:r,titleId:o,pinLabel:s,unpinLabel:a,isOpen:l,isPinned:c,isFront:f,onActivate:u,onToggle:h,onClose:m,onPinToggle:w,popoverClassName:y,scrollBarClearance:p,boundary:x,renderBody:E}){const T=d.useRef(null),O=d.useRef(null),b=d.useRef(null),R=Cg(l,b,x),A=d.useCallback(()=>{h(),u()},[u,h]),B=d.useCallback(()=>{if(c)return;const j=T.current?.contains(document.activeElement)===!0;m(),j&&O.current?.focus()},[c,m]);d.useEffect(()=>{if(!l||c)return;const j=T.current;if(j===null)return;const I=P=>{j.contains(P.target)||(m(),P.pointerType==="touch"&&!(P.target instanceof Element&&P.target.closest("[data-aqmd-toolbar]")!==null)&&Ng(j.ownerDocument,P))},X=P=>{P.key!=="Escape"||P.defaultPrevented||P.isComposing||(P.preventDefault(),m(),O.current?.focus())};return document.addEventListener("pointerdown",I),j.addEventListener("keydown",X),()=>{document.removeEventListener("pointerdown",I),j.removeEventListener("keydown",X)}},[l,c,m]);const M=c?a:s;return i.jsxs("div",{ref:T,"data-aqmd-toolbar-menu":e,children:[i.jsx("button",{ref:O,type:"button","data-aqmd-toolbar-button":!0,className:yg,onClick:A,"aria-label":n.text,lang:n.lang,"aria-expanded":l,children:i.jsx(t,{className:xg})}),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:f?2:1,maxInlineSize:_g(p),maxBlockSize:R??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":M.text,lang:M.lang,children:c?i.jsx(qp,{className:"h-4 w-4"}):i.jsx(Hp,{className:"h-4 w-4"})})]}),E(B)]})]})}function mr({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 Lg=(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=Yt(getComputedStyle(n).height);if(p<=0||y.height<=0){s(0);return}const x=y.height/p,E=Yt(getComputedStyle(l).getPropertyValue(Xp));s(eg({toolbar:y,content:t.getBoundingClientRect(),scrollportTop:w.top+l.clientTop*x,scrollportBottom:w.bottom,scale:x,reach:E}))};a.current=c;let f=null;const u=()=>{f===null&&(f=requestAnimationFrame(()=>{f=null,c()}))};c();const h=new ResizeObserver(c);h.observe(l),h.observe(t),h.observe(n);const m=n.querySelector("[data-aqmd-toolbar-inset-probe]");return m!==null&&h.observe(m),window.addEventListener("resize",c),window.addEventListener("scroll",u,{capture:!0,passive:!0}),()=>{a.current=null,h.disconnect(),window.removeEventListener("resize",c),window.removeEventListener("scroll",u,{capture:!0}),f!==null&&cancelAnimationFrame(f)}},[e,t,n]),d.useLayoutEffect(()=>{a.current?.()},[r]),o},jg=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,Mg=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},Ig=d.memo(function({parseResult:t,theme:n,iFrameAllowedDomains:r,embeds:o,embedLabels:s,linkComponent:a,missingImageLabel:l,blockFailedLabel:c,labelsLang:f,mermaidLabels:u,codeBlockLabels:h,displayMathLabels:m,spreadsheetEditor:w,spreadsheetLocale:y,spreadsheetLabels:p,spreadsheetTapScrollCircle:x,spreadsheetScrollBarControls:E,imageSource:T,svgImageLabels:O,onMathDiagnostics:b}){return i.jsx(ja,{htmlContent:t.htmlContent,theme:n,iFrameAllowedDomains:r,embeds:o,embedLabels:s,linkComponent:a,missingImageLabel:l,blockFailedLabel:c,labelsLang:f,mermaidLabels:u,codeBlockLabels:h,displayMathLabels:m,spreadsheetEditor:w,spreadsheetLocale:y,spreadsheetLabels:p,spreadsheetTapScrollCircle:x,spreadsheetScrollBarControls:E,imageSource:T,svgImageLabels:O,onMathDiagnostics:b})});function Ba(){const[e,t]=d.useState("toc"),[n,r]=d.useState(!1),[o,s]=d.useState(!1),[a,l]=d.useState(!1),[c,f]=d.useState(!1),[u,h]=d.useState(!1),[m,w]=d.useState(!1),y=d.useCallback(()=>t("toc"),[]),p=d.useCallback(()=>r(I=>!I),[]),x=d.useCallback(()=>r(!1),[]),E=d.useCallback(()=>f(I=>!I),[]),T=d.useCallback(()=>t("style"),[]),O=d.useCallback(()=>s(I=>!I),[]),b=d.useCallback(()=>s(!1),[]),R=d.useCallback(()=>h(I=>!I),[]),A=d.useCallback(()=>t("align"),[]),B=d.useCallback(()=>l(I=>!I),[]),M=d.useCallback(()=>l(!1),[]),j=d.useCallback(()=>w(I=>!I),[]);return{lastActiveMenu:e,isTocOpen:n,isStyleOpen:o,isAlignOpen:a,isTocPinned:c,isStylePinned:u,isAlignPinned:m,activateToc:y,toggleToc:p,closeToc:x,togglePinToc:E,activateStyle:T,toggleStyle:O,closeStyle:b,togglePinStyle:R,activateAlign:A,toggleAlign:B,closeAlign:M,togglePinAlign:j}}const Dg=({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(Np,{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]})})},Pg=(e,t)=>e===null?`${t}px`:e,zg=e=>{const t=Cr("scrollBarGutter",e);return e===0?null:t};function $g({parseResult:e,content:t,error:n=null,isLoading:r=!1,labels:o,labelsLang:s,theme:a,style:l,onStyleChange:c,availableStyles:f=Ye.DEFAULT_MARKDOWN_STYLES,align:u=Ye.DEFAULT_CONTENT_ALIGN,onAlignChange:h,showToc:m=!0,showStyle:w=!0,showAlign:y=!0,contentLang:p,measure:x=Ye.DEFAULT_CONTENT_MEASURE,onMeasureChange:E,showMeasure:T=!0,contentColors:O=Ye.DEFAULT_CONTENT_COLORS,onContentColorsChange:b,showContentColors:R=!0,width:A,maxWidth:B,padding:M=16,iFrameAllowedDomains:j,embeds:I=rt.NO_EMBEDS,fetch:X,emptyMessage:P,toolbar:K,linkComponent:ce,onHeadingSelect:pe,headingHref:Z,onMathDiagnostics:de,spreadsheetEditor:Ce,spreadsheetLocale:_,spreadsheetTapScrollCircle:z,spreadsheetScrollBarControls:g,imageSource:S,renderScrollBar:v,scrollBarGutter:C=0,scrollBarInlineSize:D}){const J=d.useRef(null),[q,fe]=d.useState(null),we=d.useCallback(F=>{J.current=F,fe(F)},[]),[xe,Oe]=d.useState(0),[ye,Le]=d.useState(null),[De,Ee]=d.useState(null),Ze=d.useCallback(F=>{Ee(F===null?null:F.querySelector(bg))},[]),[xt,st]=d.useState(null),Ae=d.useId(),Pe=Ba(),te=K??Pe,W=d.useMemo(()=>cg(o,s),[o,s]),dt=d.useMemo(()=>dg(o),[o]),me=d.useMemo(()=>ug(o),[o]),Ue=d.useMemo(()=>fg(o),[o]),je=d.useMemo(()=>mg(o),[o]),Ne=d.useMemo(()=>hg(o),[o]),tt=Na(S),St=dl(X),He=ba(Ce);Ls(I);const Ot=vt.EMBED_PROVIDER_IDS.filter(F=>I.providers.includes(F)).join(" "),ut=I.linkCardEndpoint,ft=I.linkCardSize,mt=I.frameSandbox,bt=d.useMemo(()=>{const F=Ot.split(" "),Y=Object.freeze(vt.EMBED_PROVIDER_IDS.filter(Re=>F.includes(Re)));return Object.freeze({providers:Y,linkCardEndpoint:ut,...ft===void 0?void 0:{linkCardSize:ft},...mt===void 0?void 0:{frameSandbox:mt}})},[Ot,ut,ft,mt]),N=o?.embeddedVideo,G=o?.embeddedPost,ee=o?.embeddedFrame,V=d.useMemo(()=>gg({embeddedVideo:N,embeddedPost:G,embeddedFrame:ee}),[N,G,ee]),ke=d.useRef(de);d.useLayoutEffect(()=>{ke.current=de},[de]);const be=d.useCallback(F=>{ke.current?.(F)},[]),{emptyMessage:ne}=d.useMemo(()=>it(vg,{emptyMessage:P},s),[P,s]),he=d.useMemo(()=>f.find(Y=>Y.name===l)?.className??"markdown-body",[f,l]),ze=Lg(J,x==="reading"&&De!==null?De:ye,xt,`${u} ${x} ${he}`);if(!Ye.CONTENT_ALIGNS.includes(u))throw new TypeError(`[@aiquants/markdown] align must be one of ${Ye.CONTENT_ALIGNS.join(", ")}; got ${String(u)} (normalize it with toContentAlign)`);if(!Ye.CONTENT_MEASURES.includes(x))throw new TypeError(`[@aiquants/markdown] measure must be one of ${Ye.CONTENT_MEASURES.join(", ")}; got ${String(x)} (normalize it with toContentMeasure)`);if(!Ye.CONTENT_COLORS.includes(O))throw new TypeError(`[@aiquants/markdown] contentColors must be one of ${Ye.CONTENT_COLORS.join(", ")}; got ${String(O)} (normalize it with toContentColors)`);const We=Number.isFinite(M)&&M>=0?M:16,ht=zg(C),Me=v===void 0?null:ht,Ie=D===void 0?null:Cr("scrollBarInlineSize",D),{isTocPinned:Ge,closeToc:$e}=te,Se=d.useCallback((F,Y)=>{if(Ge||$e(),pe?.(F,Y)===!0)return;Y.preventDefault();const at=J.current?.querySelector(`#${CSS.escape(F.id)}`)??document.getElementById(F.id);at&&(Mg(at),at.tabIndex<0&&!at.hasAttribute("tabindex")&&at.setAttribute("tabindex","-1"),at.scrollIntoView({behavior:jg()?"instant":"smooth",block:"start"}),at.focus({preventScroll:!0}))},[$e,Ge,pe]),Be=e?.headings??[],Je=!(r||n),Te=Je&&e!==null,Q=Je&&e===null&&t!==null,ve=Te&&m&&Be.length>0,ue=Te&&w,k=Te&&T&&typeof E=="function",$=Te&&R&&typeof b=="function",U=ue||k||$,ge=Te&&x==="reading",Ve=A!==void 0||B!==void 0||ge,Ke=(Te||Q)&&y&&typeof h=="function"&&Ve,Qe=d.useMemo(()=>i.jsx(Ia,{headings:Be,className:"text-sm",labelledBy:Ae,onHeadingSelect:Se,headingHref:Z}),[Be,Ae,Se,Z]),wt=v===void 0?Nr:Pg(Ie,xe),ln=d.useMemo(()=>wt===Nr?Tg:$a(wt),[wt]),Ft=ve||U||Ke?i.jsxs("div",{ref:st,"data-aqmd-toolbar":!0,style:ln,children:[i.jsx("span",{"data-aqmd-toolbar-inset-probe":!0,"aria-hidden":"true",style:Rg}),Ke&&h&&i.jsx(fr,{menu:"align",Icon:ms[u].Icon,buttonLabel:W.selectAlignAria,titleLabel:W.alignTitle,pinLabel:W.pinAlignAria,unpinLabel:W.unpinAlignAria,isOpen:te.isAlignOpen,isPinned:te.isAlignPinned,isFront:te.lastActiveMenu==="align",onActivate:te.activateAlign,onToggle:te.toggleAlign,onClose:te.closeAlign,onPinToggle:te.togglePinAlign,popoverClassName:"w-48 p-2",scrollBarClearance:wt,boundary:q,renderBody:F=>i.jsx("div",{className:"space-y-1",children:Ye.CONTENT_ALIGNS.map(Y=>{const{labelKey:Re,Icon:at}=ms[Y],qt=W[Re],eo=u===Y;return i.jsxs("button",{type:"button","aria-pressed":eo,lang:qt.lang,className:`flex items-center gap-2 ${za(eo)}`,onClick:()=>{h(Y),F()},children:[i.jsx(at,{className:"h-4 w-4"}),qt.text]},Y)})})}),U&&i.jsx(fr,{menu:"style",Icon:Bp,buttonLabel:W.selectStyleAria,titleLabel:W.styleTitle,pinLabel:W.pinStyleAria,unpinLabel:W.unpinStyleAria,isOpen:te.isStyleOpen,isPinned:te.isStylePinned,isFront:te.lastActiveMenu==="style",onActivate:te.activateStyle,onToggle:te.toggleStyle,onClose:te.closeStyle,onPinToggle:te.togglePinStyle,popoverClassName:"w-48 p-2",scrollBarClearance:wt,boundary:q,renderBody:F=>i.jsxs("div",{className:"space-y-3",children:[ue&&i.jsx(mr,{section:"style",titleLabel:W.styleSectionTitle,options:f.map(Y=>({value:Y.name,label:{text:Y.name,lang:void 0}})),current:l,onChoose:Y=>{c(Y),F()}}),k&&E&&i.jsx(mr,{section:"measure",titleLabel:W.measureTitle,options:Ye.CONTENT_MEASURES.map(Y=>({value:Y,label:W[wg[Y]]})),current:x,onChoose:Y=>{E(Y),F()}}),$&&b&&i.jsx(mr,{section:"colors",titleLabel:W.colorsTitle,options:Ye.CONTENT_COLORS.map(Y=>({value:Y,label:W[Eg[Y]]})),current:O,onChoose:Y=>{b(Y),F()}})]})}),ve&&i.jsx(fr,{menu:"toc",Icon:zp,buttonLabel:W.openTocAria,titleLabel:W.tocTitle,titleId:Ae,pinLabel:W.pinTocAria,unpinLabel:W.unpinTocAria,isOpen:te.isTocOpen,isPinned:te.isTocPinned,isFront:te.lastActiveMenu==="toc",onActivate:te.activateToc,onToggle:te.toggleToc,onClose:te.closeToc,onPinToggle:te.togglePinToc,popoverClassName:"markdown-viewer-scrollbar-thin w-64 p-4",scrollBarClearance:wt,boundary:q,renderBody:()=>Qe})]}):null,cn=()=>r?i.jsxs("p",{children:[i.jsx("span",{"aria-hidden":"true",children:"🌀"})," ",i.jsx("span",{lang:W.loading.lang,children:W.loading.text})]}):n?i.jsx(Dg,{error:n,labels:W}):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:Ze,className:he,"data-theme":a,"data-aqmd-reading-box":ge?"":void 0,style:ge?{[Sg]:hs(u)}:void 0,children:i.jsx(Ns,{value:St,children:i.jsx(Ig,{parseResult:e,theme:a,iFrameAllowedDomains:j,embeds:bt,embedLabels:V,linkComponent:ce,missingImageLabel:o?.missingImage,blockFailedLabel:o?.blockFailed,labelsLang:s,mermaidLabels:dt,codeBlockLabels:je,displayMathLabels:Ne,spreadsheetEditor:He,spreadsheetLocale:_,spreadsheetLabels:me,spreadsheetTapScrollCircle:z,spreadsheetScrollBarControls:g,imageSource:tt,svgImageLabels:Ue,onMathDiagnostics:be})})})})}):t!==null?i.jsx("pre",{className:"whitespace-pre-wrap break-all",children:t}):i.jsx("p",{lang:ne.lang,children:ne.text}),dn={containerType:"inline-size",...Me===null?{paddingInline:`${We}px`}:{paddingInlineStart:`${We}px`,paddingInlineEnd:`calc(${We}px + ${Me})`},paddingBlockEnd:`${We}px`,paddingBlockStart:`calc(${We}px + var(${ur}, 0px))`,scrollPaddingBlockStart:`var(${ur}, 0px)`,...ze===null?void 0:{[ur]:`${ze}px`}},un=Ft!==null&&!Ve,L=Q?ye:De,H=O===Ye.DEFAULT_CONTENT_COLORS?void 0:O;return i.jsxs(Ss,{scrollerRef:we,scrollerProps:{"data-testid":"viewer","data-aqmd-scroll-container":!0,"data-aqmd-colors":H,"data-aqmd-toolbar-over-content":un?!0:void 0,className:"grid h-full w-full overflow-x-auto overflow-y-auto *:min-w-0",style:dn},renderScrollBar:v,barInlineSize:D,onBarInlineSizeChange:Oe,children:[Ft,i.jsx("div",{ref:Le,"data-aqmd-content":!0,"data-aqmd-colors":H,lang:Te||Q?p:void 0,style:{width:A??kg,maxWidth:B,marginInline:hs(u)},children:cn()}),q!==null&&L!==null&&i.jsx(Vp,{scroller:q,root:L,documentKey:Q?t:e?.htmlContent,style:l,measure:x,align:u})]})}const Fa=({node:e})=>i.jsx("del",{children:i.jsx(_e,{nodes:e.children})}),qa=({node:e})=>i.jsx("em",{children:i.jsx(_e,{nodes:e.children})}),Ua=({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,"]"]})}),Bg=({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(_e,{nodes:n.children,theme:t})},`mdast-node-fn-${n.identifier}-${r}`))})}),Ha=({node:e})=>i.jsx("a",{href:e.url,className:"text-[#316dce] underline visited:text-[#6b46c1] dark:text-[#3182ce] dark:visited:text-[#805ad5]",children:"↩"}),Fg=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(),Wa=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"?Fg(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()},qg=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"}},Ga=({node:e})=>{const t=new pi,n=`h${e.depth}`,r=e.data?.hProperties?.id,o=t.slug(Wa(e.children));return i.jsx(n,{id:r||o,className:qg(e.depth),children:i.jsx(_e,{nodes:e.children})})},Ug=e=>Object.fromEntries(Object.entries(e).filter(([,t])=>t!==!1).map(([t,n])=>[t,n===!0?"":String(n)])),Hg=({node:e,theme:t,iFrameAllowedDomains:n=[]})=>{const r=i.jsx(_e,{nodes:e.children,theme:t,iFrameAllowedDomains:n}),o=Dn(e.data.tagName,Ug(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,{...re.attributesToProps(o.attributes,e.data.tagName.toLowerCase()),children:r})},Wg=/^\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,Gg=({node:e,iFrameAllowedDomains:t=[]})=>{const n=re.domToReact(Xt(e.value),Aa({iFrameAllowedDomains:t,embedLabels:Si,frameSandbox:vt.DEFAULT_FRAME_SANDBOX,allowlistContext:{allowlist:"document"}}));return Array.isArray(n)&&n.length===0?null:Wg.test(e.value)?i.jsx("div",{children:n}):i.jsx("span",{children:n})},Va=({node:e})=>{if(!e.url||e.url.trim()===""||!on(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})]})},Ka=({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}),Vg=({node:e})=>{const t=Ra(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})},Kg=new RegExp(`<(?:${[...jr].join("|")})(?=[\\s/>])`,"i"),Ya=e=>e.some(t=>t.type==="image"||t.type==="imageReference"||t.type==="html"&&typeof t.value=="string"&&Kg.test(t.value)||t.children!==void 0&&Ya(t.children)),Xa=({node:e})=>{const t=on(e.url)?e.url:void 0,n=t!==void 0&&Lr(t);return i.jsx("a",{className:Ms(void 0,Ya(e.children)),href:t,target:n?"_blank":void 0,rel:n?"noreferrer":void 0,children:i.jsx(_e,{nodes:e.children})})},Za=({node:e})=>e.children.length===1&&e.children[0].type==="paragraph"?i.jsx("li",{children:i.jsx(_e,{nodes:e.children[0].children})}):i.jsx("li",{children:i.jsx(_e,{nodes:e.children})}),Ja=({node:e})=>{const t=e.ordered?"ol":"ul";return i.jsx(t,{children:i.jsx(_e,{nodes:e.children})})},Yg=({node:e})=>i.jsx("mark",{children:i.jsx(_e,{nodes:e.children})}),Qa=({node:e})=>i.jsx("p",{children:i.jsx(_e,{nodes:e.children})}),ei=({node:e})=>i.jsx("strong",{children:i.jsx(_e,{nodes:e.children})}),Xg=({node:e})=>i.jsx("sub",{children:i.jsx(_e,{nodes:e.children})}),Zg=({node:e})=>i.jsx("sup",{children:i.jsx(_e,{nodes:e.children})}),gs=e=>{const t=e.data?.hProperties;return{merged:t?.merged??!1,colSpan:t?.colSpan,rowSpan:t?.rowSpan,textAlign:t?.textAlign}},ti=({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}=gs(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(_e,{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:f,textAlign:u}=gs(s);return l?null:i.jsx("td",{colSpan:c,rowSpan:f,style:{textAlign:u??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(_e,{nodes:s.children})},`mdast-table-node-${e.type}-${a}`)})},`mdast-table-node-${e.type}-${o}`))})]})})},ni=({node:e})=>i.jsx(i.Fragment,{children:e.value}),ri=()=>i.jsx("hr",{className:"border-gray-300 dark:border-gray-600"}),oi=({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(_e,{nodes:e.children})})]})},si=({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(_e,{nodes:e.children})})]})},_e=({nodes:e,theme:t="light",iFrameAllowedDomains:n=[]})=>e.map((r,o)=>{switch(r.type){case"blockquote":return i.jsx(ai,{node:r},`mdast-node-${r.type}-${o}`);case"break":return i.jsx("br",{},`mdast-node-${r.type}-${o}`);case"code":return i.jsx(Xr,{node:r,theme:t},`mdast-node-${r.type}-${o}`);case"delete":return i.jsx(Fa,{node:r},`mdast-node-${r.type}-${o}`);case"details":return i.jsx(oi,{node:r},`mdast-node-${r.type}-${o}`);case"emphasis":return i.jsx(qa,{node:r},`mdast-node-${r.type}-${o}`);case"footnoteReference":return i.jsx(Ua,{node:r},`mdast-node-${r.type}-${o}`);case"footnoteDefinition":return null;case"footnote-back-link":return i.jsx(Ha,{node:r},`mdast-node-${r.type}-${o}`);case"heading":return i.jsx(Ga,{node:r},`mdast-node-${r.type}-${o}`);case"html":return i.jsx(Gg,{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(Hg,{node:s,theme:t,iFrameAllowedDomains:n},a)}case"image":return i.jsx(Va,{node:r},`mdast-node-${r.type}-${o}`);case"inlineCode":return i.jsx(Ka,{node:r},`mdast-node-${r.type}-${o}`);case"inlineMath":return i.jsx(Vg,{node:r},`mdast-node-${r.type}-${o}`);case"link":return i.jsx(Xa,{node:r},`mdast-node-${r.type}-${o}`);case"listItem":return i.jsx(Za,{node:r},`mdast-node-${r.type}-${o}`);case"list":return i.jsx(Ja,{node:r},`mdast-node-${r.type}-${o}`);case"mark":return i.jsx(Yg,{node:r},`mdast-node-${r.type}-${o}`);case"math":return i.jsx(Vh,{node:r},`mdast-node-${r.type}-${o}`);case"message":return i.jsx(si,{node:r},`mdast-node-${r.type}-${o}`);case"paragraph":return i.jsx(Qa,{node:r},`mdast-node-${r.type}-${o}`);case"strong":return i.jsx(ei,{node:r},`mdast-node-${r.type}-${o}`);case"subscript":return i.jsx(Xg,{node:r},`mdast-node-${r.type}-${o}`);case"superscript":return i.jsx(Zg,{node:r},`mdast-node-${r.type}-${o}`);case"table":return i.jsx(ti,{node:r},`mdast-node-${r.type}-${o}`);case"text":return i.jsx(ni,{node:r},`mdast-node-${r.type}-${o}`);case"thematicBreak":return i.jsx(ri,{},`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}`)}}}),ai=({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(_e,{nodes:e.children})}),Jg=/\s*\{#(.+?)\}\s*$/,Qg=()=>e=>{et.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(Jg);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()}})},ey=()=>e=>{et.visit(e,"footnoteDefinition",t=>{et.visit(t,"paragraph",n=>{n.children.push({type:"footnote-back-link",url:`#fnref-${t.identifier}`})})})},ty=()=>e=>{et.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)}})},ny=()=>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 f=[];let u=!1;for(let h=o;h<r.length;h++){const m=r[h];if(m.type==="html"){l+=m.value;const w=m.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("</")?f.length>0&&f[f.length-1]===x&&f.pop():y.startsWith("<")&&f.push(x)}}else if(m.type==="text")l+=m.value;else{f.length===0&&(u=!0);break}if(c++,f.length===0){u=!0;break}}u&&r.splice(o,c,{type:"html",value:l})}o++}};et.visit(e,"paragraph",t),et.visit(e,"tableCell",t),et.visit(e,"heading",t),et.visit(e,"emphasis",t),et.visit(e,"strong",t),et.visit(e,"delete",t)},ys=/\s*=\s*(\d+)(w|h|x|y)\s*/g,ry=()=>e=>{et.visit(e,"image",t=>{const n=c=>{if(!c)return{updatedText:c,matches:[]};const f=[...c.matchAll(ys)];return{updatedText:c.replaceAll(ys,"").trim(),matches:f}},{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 f=Number.parseInt(c[1],10),u=c[2];u==="w"||u==="x"?t.data.hProperties.width=f:(u==="h"||u==="y")&&(t.data.hProperties.height=f)}}})},oy=()=>e=>{et.visit(e,(t,n,r)=>{r&&Object.defineProperty(t,"parent",{value:r,writable:!0,configurable:!0,enumerable:!1})})},xs=/^:::(message|details)\s*(.*)/,sy=()=>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(xs);if(c){const f=o;let u=-1,h=1;const m=s.children.at(-1);if(s.children.length>1&&m?.type==="text"&&m.value.trim()===":::")u=f;else for(let w=f+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();xs.test(p)?h++:p===":::"&&h--}if(h===0){u=w;break}}if(u!==-1){const w=c[1],y=c[2];let p;if(u===f){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 O={type:"paragraph",children:T},R=n[u].children.slice(0,-1);R.at(-1)?.type==="break"&&R.pop();const A={type:"paragraph",children:R},B=n.slice(f+1,u);p=[O,...B,A].filter(M=>!(M.type==="paragraph"&&M.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=u+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)},ay=e=>{const t=[];return et.visit(e,"heading",n=>{const r=Wa(n.children),o=n.data?.hProperties?.id;o&&r&&t.push({depth:n.depth,text:r,id:o})}),t};exports.BlockquoteNode=ai;exports.CodeNode=Xr;exports.DEFAULT_CODE_BLOCK_LABELS=xi;exports.DEFAULT_DISPLAY_MATH_LABELS=bi;exports.DEFAULT_MARKDOWN_EMBED_LABELS=Ei;exports.DEFAULT_MARKDOWN_VIEWER_LABELS=lg;exports.DEFAULT_MERMAID_DIAGRAM_LABELS=Af;exports.DEFAULT_MERMAID_INTERACTION=ua;exports.DEFAULT_SVG_IMAGE_LABELS=cp;exports.DeleteNode=Fa;exports.EmphasisNode=qa;exports.FootnoteBackLinkNode=Ha;exports.FootnoteReferenceNode=Ua;exports.FootnotesSection=Bg;exports.HeadingNode=Ga;exports.HostedScrollArea=Ss;exports.ImageNode=Va;exports.InlineCodeNode=Ka;exports.LinkNode=Xa;exports.ListItemNode=Za;exports.ListNode=Ja;exports.MERMAID_DRAWABLE_TYPES=Qs;exports.MarkdownRenderer=ja;exports.MarkdownViewer=$g;exports.MermaidDiagram=Vr;exports.NodesRenderer=_e;exports.ParagraphNode=Qa;exports.SpreadsheetBlock=Yr;exports.StrongNode=ei;exports.TableNode=ti;exports.TableOfContents=Ia;exports.TextNode=ni;exports.ThematicBreakNode=ri;exports.ZennDetailsNode=oi;exports.ZennMessageNode=si;exports.createMermaidDrawer=_u;exports.extractHeadings=ay;exports.remarkCustomHeadingId=Qg;exports.remarkFootnoteBackLink=ey;exports.remarkHtmlAnchorToLink=ty;exports.remarkHtmlInHtml=ny;exports.remarkImageSize=ry;exports.remarkParentNode=oy;exports.remarkZennMessage=sy;exports.useMarkdownToolbarState=Ba;