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