@sigma-studio/viewer 0.188.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +117 -0
  3. package/THIRD_PARTY_NOTICES.md +23 -0
  4. package/dist/SigmaDocViewer.d.ts +39 -0
  5. package/dist/assets/KaTeX_AMS-Regular-CYEKBG2K.woff +0 -0
  6. package/dist/assets/KaTeX_AMS-Regular-JKX5W2C4.ttf +0 -0
  7. package/dist/assets/KaTeX_AMS-Regular-U6PRYMIZ.woff2 +0 -0
  8. package/dist/assets/KaTeX_Caligraphic-Bold-5QL5CMTE.woff2 +0 -0
  9. package/dist/assets/KaTeX_Caligraphic-Bold-WZ3QSGD3.woff +0 -0
  10. package/dist/assets/KaTeX_Caligraphic-Bold-ZTS3R3HK.ttf +0 -0
  11. package/dist/assets/KaTeX_Caligraphic-Regular-3LKEU76G.woff +0 -0
  12. package/dist/assets/KaTeX_Caligraphic-Regular-A7XRTZ5Q.ttf +0 -0
  13. package/dist/assets/KaTeX_Caligraphic-Regular-KX5MEWCF.woff2 +0 -0
  14. package/dist/assets/KaTeX_Fraktur-Bold-2QVFK6NQ.woff2 +0 -0
  15. package/dist/assets/KaTeX_Fraktur-Bold-T4SWXBMT.woff +0 -0
  16. package/dist/assets/KaTeX_Fraktur-Bold-WGHVTYOR.ttf +0 -0
  17. package/dist/assets/KaTeX_Fraktur-Regular-2PEIFJSJ.woff2 +0 -0
  18. package/dist/assets/KaTeX_Fraktur-Regular-5U4OPH2X.ttf +0 -0
  19. package/dist/assets/KaTeX_Fraktur-Regular-PQMHCIK6.woff +0 -0
  20. package/dist/assets/KaTeX_Main-Bold-2GA4IZIN.woff +0 -0
  21. package/dist/assets/KaTeX_Main-Bold-W5FBVCZM.ttf +0 -0
  22. package/dist/assets/KaTeX_Main-Bold-YP5VVQRP.woff2 +0 -0
  23. package/dist/assets/KaTeX_Main-BoldItalic-4P4C7HJH.woff +0 -0
  24. package/dist/assets/KaTeX_Main-BoldItalic-N4V3DX7S.woff2 +0 -0
  25. package/dist/assets/KaTeX_Main-BoldItalic-ODMLBJJQ.ttf +0 -0
  26. package/dist/assets/KaTeX_Main-Italic-I43T2HSR.ttf +0 -0
  27. package/dist/assets/KaTeX_Main-Italic-RELBIK7M.woff2 +0 -0
  28. package/dist/assets/KaTeX_Main-Italic-SASNQFN2.woff +0 -0
  29. package/dist/assets/KaTeX_Main-Regular-ARRPAO67.woff2 +0 -0
  30. package/dist/assets/KaTeX_Main-Regular-P5I74A2A.woff +0 -0
  31. package/dist/assets/KaTeX_Main-Regular-W74P5G27.ttf +0 -0
  32. package/dist/assets/KaTeX_Math-BoldItalic-6EBV3DK5.woff +0 -0
  33. package/dist/assets/KaTeX_Math-BoldItalic-K4WTGH3J.woff2 +0 -0
  34. package/dist/assets/KaTeX_Math-BoldItalic-VB447A4D.ttf +0 -0
  35. package/dist/assets/KaTeX_Math-Italic-6KGCHLFN.woff2 +0 -0
  36. package/dist/assets/KaTeX_Math-Italic-KKK3USB2.woff +0 -0
  37. package/dist/assets/KaTeX_Math-Italic-SON4MRCA.ttf +0 -0
  38. package/dist/assets/KaTeX_SansSerif-Bold-RRNVJFFW.woff2 +0 -0
  39. package/dist/assets/KaTeX_SansSerif-Bold-STQ6RXC7.ttf +0 -0
  40. package/dist/assets/KaTeX_SansSerif-Bold-X5M5EMOD.woff +0 -0
  41. package/dist/assets/KaTeX_SansSerif-Italic-HMPFTM52.woff2 +0 -0
  42. package/dist/assets/KaTeX_SansSerif-Italic-PSN4QKYX.woff +0 -0
  43. package/dist/assets/KaTeX_SansSerif-Italic-WTBAZBGY.ttf +0 -0
  44. package/dist/assets/KaTeX_SansSerif-Regular-2TL3USAE.ttf +0 -0
  45. package/dist/assets/KaTeX_SansSerif-Regular-OQCII6EP.woff +0 -0
  46. package/dist/assets/KaTeX_SansSerif-Regular-XIQ62X4E.woff2 +0 -0
  47. package/dist/assets/KaTeX_Script-Regular-72OLXYNA.ttf +0 -0
  48. package/dist/assets/KaTeX_Script-Regular-A5IFOEBS.woff +0 -0
  49. package/dist/assets/KaTeX_Script-Regular-APUWIHLP.woff2 +0 -0
  50. package/dist/assets/KaTeX_Size1-Regular-4HRHTS65.woff +0 -0
  51. package/dist/assets/KaTeX_Size1-Regular-5LRUTBFT.woff2 +0 -0
  52. package/dist/assets/KaTeX_Size1-Regular-7K6AASVL.ttf +0 -0
  53. package/dist/assets/KaTeX_Size2-Regular-222HN3GT.ttf +0 -0
  54. package/dist/assets/KaTeX_Size2-Regular-K5ZHAIS6.woff +0 -0
  55. package/dist/assets/KaTeX_Size2-Regular-LELKET5D.woff2 +0 -0
  56. package/dist/assets/KaTeX_Size3-Regular-TLFPAHDE.woff +0 -0
  57. package/dist/assets/KaTeX_Size3-Regular-UFCO6WCA.ttf +0 -0
  58. package/dist/assets/KaTeX_Size3-Regular-WQRQ47UD.woff2 +0 -0
  59. package/dist/assets/KaTeX_Size4-Regular-7PGNVPQK.ttf +0 -0
  60. package/dist/assets/KaTeX_Size4-Regular-CDMV7U5C.woff2 +0 -0
  61. package/dist/assets/KaTeX_Size4-Regular-PKMWZHNC.woff +0 -0
  62. package/dist/assets/KaTeX_Typewriter-Regular-3F5K6SQ6.ttf +0 -0
  63. package/dist/assets/KaTeX_Typewriter-Regular-MJMFSK64.woff +0 -0
  64. package/dist/assets/KaTeX_Typewriter-Regular-VBYJ4NRC.woff2 +0 -0
  65. package/dist/index.d.ts +3 -0
  66. package/dist/index.js +14 -0
  67. package/dist/overlay-types.d.ts +371 -0
  68. package/dist/styles.css +1 -0
  69. package/dist/types.d.ts +461 -0
  70. package/dist/viewer-safety.d.ts +19 -0
  71. package/package.json +66 -0
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ import{Component as jh,useEffect as vr,useId as Kh,useLayoutEffect as fi,useMemo as Fc,useRef as zc,useState as Jt}from"react";var bx=Math.PI/12;function Qe(e){let t=Math.PI*2;return(e%t+t)%t}function nn(e,t,n){return Math.min(Math.max(e,t),n)}var Cr="plot",He={left:46,top:18,right:18,bottom:34},Kc={left:34,top:20,right:28,bottom:30};function oe(e){return e.kind==="numberLine"?Kc:He}function ki(e){if(e.props.boundsMode!==Cr)return e.props.preserveSpecSize===!0?e.props.spec:{...e.props.spec,width:e.props.w,height:e.props.h};if(e.props.preserveSpecSize===!0)return e.props.spec;let t=oe(e.props.spec);return{...e.props.spec,width:e.props.w+t.left+t.right,height:e.props.h+t.top+t.bottom}}function Rt(e){let t=ki(e),n=oe(t),r=Math.max(1,t.width-n.left-n.right),o=Math.max(1,t.height-n.top-n.bottom);if(e.props.boundsMode!==Cr)return{spec:t,plotBox:n,renderBounds:{x:e.x,y:e.y,w:e.props.w,h:e.props.h},scaleX:e.props.w/Math.max(1,t.width),scaleY:e.props.h/Math.max(1,t.height)};let i=e.props.w/r,a=e.props.h/o;return{spec:t,plotBox:n,renderBounds:{x:e.x-n.left*i,y:e.y-n.top*a,w:t.width*i,h:t.height*a},scaleX:i,scaleY:a}}var Ti=1.3333333333333333,Me=1,Er=8,Be=12;function Bi(e){return Ai(e.type==="text"?e.props.scale:1)}function rn(e){return(typeof e.props.fontSize=="number"&&Number.isFinite(e.props.fontSize)&&e.props.fontSize>0?e.props.fontSize:Zc(qc(e.props.size)))*Bi(e)}function Re(e){return Jc(rn(e))}function Ri(e){return Math.ceil(Re(e)*Me)}function Ai(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(.25,Math.min(8,e))}function qc(e){return e==="s"?13:e==="l"?20:e==="xl"?24:16}function Zc(e){return Qc(e/Ti)}function Jc(e){return e*Ti}function Qc(e){return Math.round(e*1e3)/1e3}var Ci=null;function Ei(e){Ci=e}var on=.8,an=.2,Li=/\\begin\{[^}]*\}([\s\S]*?)\\end\{[^}]*\}/,eu=/\\(?:frac|dfrac|tfrac|cfrac|sqrt|int|oint|iint|iiint|sum|prod|coprod|lim|begin|binom|dbinom|tbinom|overbrace|underbrace)\b/,tu=1.6,nu=1;function Lr(e){let t=cu(e.fontSizePx,1),n=e.mathMetrics??Ci,r=ru(e,n),o=uu(e.maxWidthPx),i=Math.ceil(t*Me);if(o===void 0){let c=Math.max(0,...r.map(au)),p=r.reduce((m,g)=>m+su(g,t),0);return{w:Math.ceil(c*t),h:Math.max(i,p),wrapped:!1}}let a=o/t,s=!1,l=0,u=0;for(let c of r){let p=lu(c,a,t);s||=p.wrapped,u=Math.max(u,p.widestMathAtomUnits),l+=p.heightPx}return{w:Math.max(o,Math.ceil(u*t)),h:Math.max(i,l),wrapped:s}}function ru(e,t){if(e.inlineContent){let n=[[]];for(let r of e.inlineContent)r.type==="text"?Nr(n,r.text):Ni(n,r.tex,t);return n}if(e.richText){let n=[[]];return e.richText.blocks.forEach((r,o)=>{o>0&&n.push([]);for(let i of r.children)ou(n,i,t)}),n}if(e.lines&&e.lines.length>0){let n=[];for(let r of e.lines)for(let o of $i(r))n.push(o.length>0?[{kind:"text",text:o}]:[]);return n}return[[]]}function ou(e,t,n){if(t.type==="text"){Nr(e,t.text??"");return}t.type==="mathInline"&&Ni(e,t.tex,n)}function Nr(e,t){$i(t).forEach((r,o)=>{o>0&&e.push([]),r.length>0&&e[e.length-1].push({kind:"text",text:r})})}function Ni(e,t,n){if(n){let r=n.measureTexEm(t)??Ii(t);e[e.length-1].push({kind:"math",tex:t,metrics:r});return}if(iu(t)){e[e.length-1].push({kind:"math",tex:t,metrics:Ii(t)});return}Nr(e,_i(t))}function iu(e){let t=Li.exec(e);return t!==null&&Fi(t[1])>0}function Fi(e){return(e.match(/\\\\/g)??[]).length}function Ii(e){let t=Li.exec(e),n=t?Fi(t[1])+1:1,r=eu.test(e)?tu:nu,o=_i(e),i=Math.max(0,...o.split(`
2
+ `).map(Gi));return{ascentEm:n*r,descentEm:0,widthEm:i}}function _i(e){return e.replace(/\\\\(?:\[[^\]]*\])?/g,`
3
+ `).replace(/\\(?:begin|end)\s*\{[^}]*\}/g,"").replace(/\\(?:left|right|displaystyle|textstyle|scriptstyle|scriptscriptstyle)\b/g,"").replace(/\\(?:mathrm|mathbf|mathit|mathsf|mathtt|text|textrm|textbf|textit|operatorname|frac|dfrac|tfrac|sqrt|overline|underline|vec|hat|bar|dot|ddot)\b/g,"").replace(/\\(sin|cos|tan|cot|sec|csc|log|ln|exp|max|min|lim)\b/g,"$1").replace(/\\(?:quad|qquad|,|;|:|!)/g," ").replace(/\\([{}_%&#$])/g,"$1").replace(/\\[a-zA-Z]+/g,"M").replace(/[{}^_]/g,"").split(`
4
+ `).map(t=>t.replace(/\s+/g,"")).join(`
5
+ `)}function $i(e){return e.split(/\r\n|\r|\n/)}function au(e){return e.reduce((t,n)=>t+(n.kind==="text"?Gi(n.text):n.metrics.widthEm),0)}function su(e,t){let n=on,r=an;for(let o of e)o.kind==="math"&&(n=Math.max(n,o.metrics.ascentEm),r=Math.max(r,o.metrics.descentEm));return Math.ceil(t*Math.max(Me,n+r))}function lu(e,t,n){let r=e.flatMap(p=>p.kind==="math"?[{widthEm:p.metrics.widthEm,ascentEm:p.metrics.ascentEm,descentEm:p.metrics.descentEm,isMathAtom:!0}]:Array.from(p.text).map(m=>({widthEm:Di(m),ascentEm:on,descentEm:an,isMathAtom:!1})));if(r.length===0)return{heightPx:Math.ceil(n*Me),wrapped:!1,widestMathAtomUnits:0};let o=0,i=!1,a=0,s=0,l=on,u=an,c=()=>{o+=Math.ceil(n*Math.max(Me,l+u))};for(let p of r)p.isMathAtom&&(a=Math.max(a,p.widthEm)),s>0&&s+p.widthEm>t?(c(),i=!0,s=p.widthEm,l=Math.max(on,p.ascentEm),u=Math.max(an,p.descentEm)):(s+=p.widthEm,l=Math.max(l,p.ascentEm),u=Math.max(u,p.descentEm));return c(),{heightPx:o,wrapped:i,widestMathAtomUnits:a}}function Gi(e){let t=0;for(let n of e)t+=Di(n);return t}function Di(e){if(/\s/u.test(e))return .35;let t=e.codePointAt(0)??0;return t>=4352&&t<=4607||t>=11904&&t<=42191||t>=44032&&t<=55215||t>=63744&&t<=64255||t>=65280&&t<=65519?1:/[+\-*/=<>()[\]{}^_,.;:|]/u.test(e)?.45:.58}function cu(e,t){return Number.isFinite(e)&&e>0?e:t}function uu(e){return e!==void 0&&Number.isFinite(e)&&e>0?e:void 0}var zi=new WeakMap;function Fr(e,t,n){let r=zi.get(e);r||(r=new Map,zi.set(e,r));let o=r.get(t);if(o)return o;let i=n();return r.set(t,i),i}function Hi(e,t){let n=Re(e),r=`content|${n}|${t??""}`;return Fr(e.props.richText,r,()=>{let o=Lr({richText:e.props.richText,fontSizePx:n,maxWidthPx:t});return{w:o.w,h:o.h}})}function _r(e){let t=Re(e),n=e.props.w,r=typeof e.props.h=="number"&&Number.isFinite(e.props.h)?e.props.h:void 0,o=e.props.autoSize,i=e.props.maxWidth,a=o?i:Math.max(Er,n),s=`effective|${o?"auto":"fixed"}|${t}|${a??""}|${n}|${r??""}`;return Fr(e.props.richText,s,()=>{let l=Hi(e,a),u=du(e),c=o&&i!==void 0?i:Math.max(Er,n),p=Math.max(r??0,u,l.h);return{w:c,h:p}})}function ve(e){let t=Math.max(1,e.props.w),n=Re(e),r=`calloutBody|${t}|${e.props.h}|${n}`;return Fr(e.props.richText,r,()=>{let o=Math.max(1,t-2*Be),i=Hi(e,o),a=Math.max(e.props.h,i.h+2*Be);return{w:t,h:a}})}function Vi(e){let t=ve(e);return{x:Be,y:Be,w:Math.max(1,t.w-2*Be),h:Math.max(1,t.h-2*Be)}}function du(e){let t=Ri(e);return Math.max(t,pu(e.props.richText)*t)}function pu(e){return e.blocks.length===0?1:Math.max(1,e.blocks.reduce((t,n)=>t+mu(n.children),0))}function mu(e){return 1+e.reduce((t,n)=>t+fu(n),0)}function fu(e){return e.type==="text"?Math.max(0,e.text.split(`
6
+ `).length-1):0}var $r=1,yu=12;var Ax=1-Math.SQRT1_2,gu=18;function Zi(e){let{w:t,h:n}=ve(e),r=Dr(e),{baseStart:o,baseEnd:i,tip:a,radius:s}=r,l=Xi(i,o,t,n),u=Xi(o,i,t,n);return l>=u?[`M ${Ae(o)}`,`L ${Ae(a)}`,`L ${Ae(i)}`,...Wi(i,o,t,n,s),"Z"].join(" "):[`M ${Ae(i)}`,`L ${Ae(a)}`,`L ${Ae(o)}`,...Wi(o,i,t,n,s),"Z"].join(" ")}function Ui(e,t,n){return t<=0||n===t||e<=0?e:e>=t?e+(n-t):e*n/t}function sn(e,t){let n=e.props.w,r=e.props.h,{w:o,h:i}=ve(e);return{x:Ui(t.x,n,o),y:Ui(t.y,r,i)}}function Gr(e,t,n){let{w:r,h:o}=ve(e),i=bu(t,n,r,o);return hu(e,i,t,n)}function hu(e,t,n,r){let{w:o,h:i}=ve(e),a=Ji(e);return t==="top"?{x:At(n,a,o-a),y:0,side:t}:t==="right"?{x:o,y:At(r,a,i-a),side:t}:t==="bottom"?{x:At(n,a,o-a),y:i,side:t}:{x:0,y:At(r,a,i-a),side:t}}function Dr(e){let{tail:t}=e.props,{w:n,h:r}=ve(e),o=Ji(e),i=sn(e,t.baseStart),a=sn(e,t.baseEnd),s=sn(e,t.tip),l=Gr(e,i.x,i.y),u=Gr(e,a.x,a.y),c={x:qi(s.x,n*.14),y:qi(s.y,r+28)},p=Math.min(0,l.x,u.x,c.x),m=Math.min(0,l.y,u.y,c.y),g=Math.max(n,l.x,u.x,c.x),h=Math.max(r,l.y,u.y,c.y);return{body:{left:0,top:0,right:n,bottom:r},radius:o,baseStart:l,baseEnd:u,tip:c,bounds:{x:p,y:m,w:Math.max($r,g-p),h:Math.max($r,h-m)}}}function Ji(e){let{w:t,h:n}=ve(e);return xu(e.props.radius,t,n)}function xu(e,t,n){let r=Math.max(0,(Math.min(t,n)-yu)/2);return At(Number.isFinite(e)?e:gu,0,r)}function bu(e,t,n,r){return[["top",Math.abs(t)],["right",Math.abs(n-e)],["bottom",Math.abs(r-t)],["left",Math.abs(e)]].reduce((i,a)=>a[1]<i[1]?a:i)[0]}function Wi(e,t,n,r,o){let i=["top","right","bottom","left"],a=i.indexOf(e.side),s=[];for(let l=0;l<5;l+=1){let u=i[a];if(u===t.side&&Yi(t,n,r)>=Yi(l===0?e:Su(u,n,r,o),n,r))return s.push(`L ${Ae(t)}`),s;s.push(...Pu(u,n,r,o)),a=(a+1)%i.length}return s.push(`L ${Ae(t)}`),s}function Su(e,t,n,r){return e==="top"?{x:r,y:0,side:e}:e==="right"?{x:t,y:r,side:e}:e==="bottom"?{x:t-r,y:n,side:e}:{x:0,y:n-r,side:e}}function Yi(e,t,n){return e.side==="top"?e.x:e.side==="right"?e.y:e.side==="bottom"?t-e.x:n-e.y}function Pu(e,t,n,r){return e==="top"?[`L ${t-r} 0`,`Q ${t} 0 ${t} ${r}`]:e==="right"?[`L ${t} ${n-r}`,`Q ${t} ${n} ${t-r} ${n}`]:e==="bottom"?[`L ${r} ${n}`,`Q 0 ${n} 0 ${n-r}`]:[`L 0 ${r}`,`Q 0 0 ${r} 0`]}function Xi(e,t,n,r){let o=Math.max($r,(n+r)*2),a=((ji(t,n,r)-ji(e,n,r))%o+o)%o;return a===0?o:a}function ji(e,t,n){return e.side==="top"?e.x:e.side==="right"?t+e.y:e.side==="bottom"?t+n+(t-e.x):t*2+n+(n-e.y)}function Ae(e){return`${Ki(e.x)} ${Ki(e.y)}`}function Ki(e){return Math.round(e*1e3)/1e3}function qi(e,t){return Number.isFinite(e)?e:t}function At(e,t,n){return n<t?(t+n)/2:Math.min(n,Math.max(t,e))}var Qi=10,ln=.5;function ge(e){if(e.type==="graph2dShape"){if(e.props.boundsMode==="plot")return{x:e.x,y:e.y,w:e.props.w,h:e.props.h};let t=Rt(e);return{x:t.renderBounds.x+t.plotBox.left*t.scaleX,y:t.renderBounds.y+t.plotBox.top*t.scaleY,w:Math.max(1,e.props.w-(t.plotBox.left+t.plotBox.right)*t.scaleX),h:Math.max(1,e.props.h-(t.plotBox.top+t.plotBox.bottom)*t.scaleY)}}if(e.type==="group"||e.type==="geo"||e.type==="image"||e.type==="tableShape")return{x:e.x,y:e.y,w:e.props.w,h:e.props.h};if(e.type==="callout"){let t=Dr(e).bounds;return{x:e.x+t.x,y:e.y+t.y,w:t.w,h:t.h}}if(e.type==="arc"){let{rx:t,ry:n}=Ie(e);return{x:e.x,y:e.y,w:t*2,h:n*2}}if(e.type==="text"){let t=_r(e);return{x:e.x,y:e.y,w:t.w,h:t.h}}return e.type==="arrow"?ea(e.x,e.y,[e.props.start,e.props.end],Qi):e.type==="line"?ea(e.x,e.y,e.props.points,Qi):{x:0,y:0,w:1,h:1}}function It(e){return e.type==="tableShape"||e.type==="group"?0:typeof e.rotation=="number"&&Number.isFinite(e.rotation)?e.rotation:0}function Ie(e){let t=Math.max(ln,e.props.r),n=typeof e.props.rx=="number"&&Number.isFinite(e.props.rx)?Math.max(ln,e.props.rx):t,r=typeof e.props.ry=="number"&&Number.isFinite(e.props.ry)?Math.max(ln,e.props.ry):t;return{rx:n,ry:r}}function ea(e,t,n,r){if(n.length===0)return{x:e,y:t,w:1,h:1};let o=n.map(c=>e+c.x),i=n.map(c=>t+c.y),a=Math.min(...o),s=Math.min(...i),l=Math.max(...o),u=Math.max(...i);return{x:a-r,y:s-r,w:Math.max(1,l-a+r*2),h:Math.max(1,u-s+r*2)}}var Ou=1122.5196850393702,wu=36,cn=Ou+wu;function Hr(e,t,n={}){let r=Iu(Array.from(t.values())),o=e.map(i=>ku(i,t,r,n));return un(o)}function un(e){let t=new Map(e.map(s=>[s.id,s])),n=new Map,r=new Set,o=s=>{let l=n.get(s.id);if(l)return l;if(s.anchor?.type!=="shape")return n.set(s.id,s),s;let u=t.get(s.anchor.shapeId);if(!u||u.id===s.id||r.has(s.id))return n.set(s.id,s),s;r.add(s.id);let c=o(u);r.delete(s.id);let p=Ru(s.anchor,c),m=p.x===s.x&&p.y===s.y?s:{...s,x:p.x,y:p.y};return n.set(s.id,m),m},i=!1,a=e.map(s=>{let l=o(s);return i||=l!==s,l});return i?a:e}function ku(e,t,n,r){if(e.anchor?.type!=="block")return e;let o=t.get(e.anchor.blockId);if(!o)return e;let i=Bu(e.anchor,o,n),a=i?.block??o,s=Tu(e.anchor,r),l=typeof e.anchor.dx=="number"&&typeof a.left=="number"?a.left+e.anchor.dx:e.x,u=i===void 0||!e.anchor.line?o.top-s+e.anchor.dy:i.line.top-s+e.anchor.line.dy;return l===e.x&&u===e.y?e:{...e,x:l,y:u}}function Tu(e,t){if(e.reserveSpace!==!0)return 0;let n=t[e.blockId];return typeof n=="number"&&Number.isFinite(n)?Math.max(0,n):0}function Bu(e,t,n){if(!e.line||!t.lines?.length)return;let r=t.lines.find(a=>a.index===e.line?.index);if(r)return{block:t,line:r};let o=e.line.index-t.lines.length;if(o<0)return;let i=n.findIndex(a=>a.id===t.id);if(!(i<0))for(let a of n.slice(i+1)){if(!ra(t,a))continue;let s=a.lines??[];if(o<s.length)return{block:a,line:s[o]};o-=s.length}}function Ru(e,t){let n=Au(t),r=typeof e.rx=="number"?n.x+n.w*e.rx:t.x,o=typeof e.ry=="number"?n.y+n.h*e.ry:t.y;return{x:r+e.dx,y:o+e.dy}}function Au(e){if(e.type==="group"||e.type==="geo"||e.type==="image"||e.type==="callout"||e.type==="graph2dShape"||e.type==="tableShape")return{x:e.x,y:e.y,w:e.props.w,h:e.props.h};if(e.type==="arc"){let t=Math.max(.5,e.props.r),n=typeof e.props.rx=="number"&&Number.isFinite(e.props.rx)?Math.max(.5,e.props.rx):t,r=typeof e.props.ry=="number"&&Number.isFinite(e.props.ry)?Math.max(.5,e.props.ry):t;return{x:e.x,y:e.y,w:n*2,h:r*2}}if(e.type==="text"){let t=typeof e.props.h=="number"&&Number.isFinite(e.props.h)?Math.max(1,e.props.h):1;return{x:e.x,y:e.y,w:Math.max(8,e.props.w),h:t}}return e.type==="arrow"?ta(e.x,e.y,[e.props.start,e.props.end],10):ta(e.x,e.y,e.props.points,10)}function ta(e,t,n,r){if(n.length===0)return{x:e,y:t,w:1,h:1};let o=n.map(c=>e+c.x),i=n.map(c=>t+c.y),a=Math.min(...o),s=Math.min(...i),l=Math.max(...o),u=Math.max(...i);return{x:a-r,y:s-r,w:Math.max(1,l-a+r*2),h:Math.max(1,u-s+r*2)}}function ra(e,t){if(e.left===void 0||t.left===void 0)return!0;let n=e.width??0,r=t.width??0,o=Math.max(4,Math.min(n||0,r||0)*.08);return Math.abs(e.left-t.left)<=o}function Iu(e,t=Lu(e)){return t.length<=1?[...e].sort((n,r)=>n.top-r.top):e.map((n,r)=>({block:n,index:r})).sort((n,r)=>Cu(na(n.block,n.index,t),na(r.block,r.index,t))).map(n=>n.block)}function na(e,t,n){let r=Eu(e.top);return{page:r.page,column:Nu(e,n)??0,localY:r.localY,top:e.top,index:t}}function Cu(e,t){return e.page-t.page||e.column-t.column||e.localY-t.localY||e.top-t.top||e.index-t.index}function Eu(e){let t=Math.max(0,Math.floor((e+.5)/cn));return{page:t,localY:e-t*cn}}function Lu(e){let t=[];for(let n of e){if(typeof n.left!="number"||typeof n.width!="number")continue;let r=t.find(o=>ra(o.representative,n));if(r){r.left=Math.min(r.left,n.left),r.right=Math.max(r.right,n.left+n.width),r.blockIds.add(n.id);continue}t.push({representative:n,left:n.left,right:n.left+n.width,blockIds:new Set([n.id])})}return t.sort((n,r)=>n.left-r.left).map((n,r)=>({index:r,left:n.left,right:n.right,center:(n.left+n.right)/2,blockIds:n.blockIds}))}function Nu(e,t){return t.find(n=>n.blockIds.has(e.id))?.index}function pn(e,t,n,r,o=0){let i=o,a=Math.max(i+1,e-o),s=o,l=Math.max(s+1,t-o),u=Math.max(1,a-i),c=Math.max(1,l-s),p=s+c/2,m=u*Fu(n),g=dn(a-m,i+Math.min(8,u*.25),a-1),h=c*_u(r)/2,b=dn(p-h,s,p),S=dn(p+h,p,l);return[{x:i,y:b},{x:g,y:b},{x:g,y:s},{x:a,y:p},{x:g,y:l},{x:g,y:S},{x:i,y:S}]}function Fu(e){return oa(e,.32,.18,.75)}function _u(e){return oa(e,.42,.12,.9)}function oa(e,t,n,r){let o=typeof e=="number"?e:Number.parseFloat(String(e));return dn(Number.isFinite(o)?o:t,n,r)}function dn(e,t,n){return Math.min(n,Math.max(t,e))}function $u(e){if(!e)return null;let t=mn(Math.min(e.topLeft.x,e.bottomRight.x)),n=mn(Math.min(e.topLeft.y,e.bottomRight.y)),r=mn(Math.max(e.topLeft.x,e.bottomRight.x)),o=mn(Math.max(e.topLeft.y,e.bottomRight.y));return r-t<.02||o-n<.02?null:{topLeft:{x:t,y:n},bottomRight:{x:r,y:o}}}function Vr(e,t){let n=$u(e.props.crop);if(n)return n;let r=Math.max(1,t?.props.w||e.props.w||1),o=Math.max(1,t?.props.h||e.props.h||1),i=Math.max(1,e.props.w),a=Math.max(1,e.props.h),s=r/o,l=i/a;if(s>l){let p=l/s,m=(1-p)/2;return{topLeft:{x:m,y:0},bottomRight:{x:m+p,y:1}}}let u=s/l,c=(1-u)/2;return{topLeft:{x:0,y:c},bottomRight:{x:1,y:c+u}}}function ia(e,t,n=Vr(e,t)){let r=Math.max(1,t?.props.w||e.props.w||1),o=Math.max(1,t?.props.h||e.props.h||1);return Gu({w:e.props.w,h:e.props.h},{w:r,h:o},n)}function Gu(e,t,n){let r=Math.max(1,t.w),o=Math.max(1,t.h),i=Math.max(.02,n.bottomRight.x-n.topLeft.x),a=Math.max(.02,n.bottomRight.y-n.topLeft.y),s=Math.max(e.w/(r*i),e.h/(o*a)),l=r*s,u=o*s;return{x:-n.topLeft.x*l+(e.w-i*l)/2,y:-n.topLeft.y*u+(e.h-a*u)/2,width:l,height:u}}function mn(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function fn(e){return e??"polyline"}function Ur(e,t,n){return fn(e)==="polyline"&&n===!0&&t.length>=3}function sa(e,t){return e.length===0?"":fn(t)==="polyline"?ca(e):Du(e)}function Wr(e){return e.map(t=>`${t.x},${t.y}`).join(" ")}function la(e){return e.length===0?null:e[Math.floor(e.length/2)]}function ca(e){let[t,...n]=e;return[`M ${Oe(t)}`,...n.map(r=>`L ${Oe(r)}`)].join(" ")}function Du(e){if(e.length<3)return ca(e);if(e.length===3)return`M ${Oe(e[0])} Q ${Oe(e[1])} ${Oe(e[2])}`;let[t]=e,n=[`M ${Oe(t)}`];for(let r=1;r<e.length-1;r+=1){let o=e[r],i=e[r+1],a={x:(o.x+i.x)/2,y:(o.y+i.y)/2};n.push(`Q ${Oe(o)} ${Oe(a)}`)}return n.push(`L ${Oe(e[e.length-1])}`),n.join(" ")}function Oe(e){return`${aa(e.x)} ${aa(e.y)}`}function aa(e){return Number(e.toFixed(2)).toString()}function yn(e){let t=typeof e=="number"?e:Number.parseInt(String(e),10),n=Math.round(Number.isFinite(t)?t:5);return Math.min(12,Math.max(5,n))}function gn(e,t,n,r=0){let o=Math.max(0,e),i=Math.max(0,t),a=Math.min(Math.max(0,r),o/2),s=Math.min(Math.max(0,r),i/2),l=Math.max(0,o-a*2),u=Math.max(0,i-s*2),c=Array.from({length:n},(w,B)=>{let Y=-Math.PI/2+B*Math.PI*2/n;return{x:Math.cos(Y),y:Math.sin(Y)}}),p=c.map(w=>w.x),m=c.map(w=>w.y),g=Math.min(...p),h=Math.max(...p),b=Math.min(...m),S=Math.max(...m),M=Math.max(Number.EPSILON,h-g),L=Math.max(Number.EPSILON,S-b);return c.map(w=>({x:a+(w.x-g)/M*l,y:s+(w.y-b)/L*u}))}var wb=Math.sqrt(3)/2;var Eb=Math.PI*2;var da="plot";function Hu(e){return e.kind==="numberLine"?{left:34,top:20,right:28,bottom:30}:{left:46,top:18,right:18,bottom:34}}function hn(e){if(e.props.boundsMode===da)return e;let t=e.props.preserveSpecSize===!0?e.props.spec:{...e.props.spec,width:e.props.w,height:e.props.h},n=Hu(t),r=e.props.w/Math.max(1,t.width),o=e.props.h/Math.max(1,t.height),i=n.left*r,a=n.top*o,s=n.right*r,l=n.bottom*o,u=e.anchor?.type==="block"?{...e.anchor,dy:e.anchor.dy+a,...e.anchor.dx===void 0?{}:{dx:e.anchor.dx+i},...e.anchor.line?{line:{...e.anchor.line,dy:e.anchor.line.dy+a}}:{}}:e.anchor;return{...e,x:e.x+i,y:e.y+a,...u?{anchor:u}:{},props:{...e.props,boundsMode:da,w:Math.max(1,e.props.w-i-s),h:Math.max(1,e.props.h-a-l),spec:e.props.preserveSpecSize===!0?e.props.spec:t}}}function pa(e){return e==="s"?13:e==="l"?20:e==="xl"?24:16}var Yr=.5,Vu=8,Uu=.25,Wu=8,xn=10,Yu=96/72;function Xr(e){let t=Xu(e);for(let n=0;n<4;n+=1){let r=Zu(qu(Ku(ju(t))));if(sd(t,r))return r;t=r}return t}function Xu(e){let t=new Map;for(let a of e)a.type==="group"||!a.groupId||t.set(a.groupId,[...t.get(a.groupId)??[],a]);if(t.size===0)return e.map(ma);let n=new Set(e.map(a=>a.id)),r=new Map,o=new Map;for(let[a,s]of t){if(s.length<2)continue;let l=ya(s);if(!l)continue;let u=ed(()=>a,n);r.set(a,u);let c=Math.max(0,e.findIndex(m=>m.groupId===a)),p={id:u,type:"group",x:l.x,y:l.y,props:{w:l.w,h:l.h}};o.set(c,[...o.get(c)??[],p])}let i=[];return e.forEach((a,s)=>{let l=o.get(s);l&&i.push(...l);let u=a.groupId,c=ma(a),p=u?r.get(u):void 0;i.push(p?{...c,parentId:p}:c)}),i}function ju(e){let t=new Map(e.map(o=>[o.id,o])),n=!1,r=e.map(o=>{if(!o.parentId)return o;let i=t.get(o.parentId);if(!i||i.type!=="group"||i.id===o.id||Qu(o,t)){let a={...o};return delete a.parentId,n=!0,a}return o});return n?r:e}function Ku(e){let t=jr(e),n=new Set(e.filter(o=>o.type==="group").filter(o=>(t.get(o.id)?.length??0)<=1).map(o=>o.id));if(n.size===0)return e;let r=new Map(e.filter(o=>o.type==="group"&&n.has(o.id)).map(o=>[o.id,o.parentId]));return e.flatMap(o=>{if(n.has(o.id))return[];if(o.parentId&&n.has(o.parentId)){let i=r.get(o.parentId),a={...o};return i?a.parentId=i:delete a.parentId,[a]}return[o]})}function qu(e){let t=jr(e),n=new Map(e.map(a=>[a.id,Ju(a,e)])),r=e.filter(a=>a.type==="group").sort((a,s)=>(n.get(s.id)??0)-(n.get(a.id)??0));if(r.length===0)return e;let o=new Map(e.map(a=>[a.id,a])),i=!1;for(let a of r){let s=(t.get(a.id)??[]).map(u=>o.get(u.id)??u),l=ya(s);l&&(ad(l,{x:a.x,y:a.y,w:a.props.w,h:a.props.h})||(o.set(a.id,{...a,x:l.x,y:l.y,props:{...a.props,w:l.w,h:l.h}}),i=!0))}return i?e.map(a=>o.get(a.id)??a):e}function Zu(e){let t=jr(e),n=[],r=new Set,o=i=>{if(!r.has(i.id)&&(r.add(i.id),n.push(i),i.type==="group"))for(let a of t.get(i.id)??[])o(a)};for(let i of e)i.parentId||o(i);for(let i of e)o(i);return n}function jr(e){let t=new Map;for(let n of e)n.parentId&&t.set(n.parentId,[...t.get(n.parentId)??[],n]);return t}function Ju(e,t){let n=0,r=e.parentId,o=new Set([e.id]);for(;r;){let i=t.find(a=>a.id===r);if(!i||o.has(i.id))break;o.add(i.id),n+=1,r=i.parentId}return n}function Qu(e,t){let n=new Set([e.id]),r=e.parentId;for(;r;){if(n.has(r))return!0;n.add(r),r=t.get(r)?.parentId}return!1}function ma(e){if(!e.groupId)return e;let t={...e};return delete t.groupId,t}function ed(e,t){let n=e(),r=1;for(;t.has(n);)n=`${e()}_${r}`,r+=1;return t.add(n),n}function ya(e){return e.length===0?null:e.map(td).reduce((t,n)=>id(t,n))}function td(e){if(e.type==="graph2dShape"){let t=hn(e);return{x:t.x,y:t.y,w:t.props.w,h:t.props.h}}if(e.type==="group"||e.type==="geo"||e.type==="image"||e.type==="callout"||e.type==="tableShape")return{x:e.x,y:e.y,w:e.props.w,h:e.props.h};if(e.type==="arc"){let t=Math.max(Yr,e.props.r),n=typeof e.props.rx=="number"&&Number.isFinite(e.props.rx)?Math.max(Yr,e.props.rx):t,r=typeof e.props.ry=="number"&&Number.isFinite(e.props.ry)?Math.max(Yr,e.props.ry):t;return{x:e.x,y:e.y,w:n*2,h:r*2}}if(e.type==="text"){let t=nd(e.props.richText,e.props.size,e.props.fontSize,e.props.scale),n=typeof e.props.h=="number"&&Number.isFinite(e.props.h)?Math.max(t,e.props.h):t;return{x:e.x,y:e.y,w:Math.max(Vu,e.props.w),h:n}}return e.type==="arrow"?fa(e.x,e.y,[e.props.start,e.props.end]):e.type==="line"?fa(e.x,e.y,e.props.points):{x:0,y:0,w:1,h:1}}function nd(e,t,n,r){let o=typeof r=="number"&&Number.isFinite(r)?Math.max(Uu,Math.min(Wu,r)):1,i=(typeof n=="number"&&Number.isFinite(n)&&n>0?n*Yu:pa(t))*o,a=Math.ceil(i);return Math.max(a,rd(e)*a)}function rd(e){return e.blocks.length===0?1:Math.max(1,e.blocks.reduce((t,n)=>t+od(n.children),0))}function od(e){return 1+e.reduce((t,n)=>n.type==="text"?t+Math.max(0,n.text.split(`
7
+ `).length-1):t,0)}function fa(e,t,n){if(n.length===0)return{x:e,y:t,w:1,h:1};let r=n.map(u=>e+u.x),o=n.map(u=>t+u.y),i=Math.min(...r),a=Math.min(...o),s=Math.max(...r),l=Math.max(...o);return{x:i-xn,y:a-xn,w:Math.max(1,s-i+xn*2),h:Math.max(1,l-a+xn*2)}}function id(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y),o=Math.max(e.x+e.w,t.x+t.w),i=Math.max(e.y+e.h,t.y+t.h);return{x:n,y:r,w:o-n,h:i-r}}function ad(e,t){return Math.abs(e.x-t.x)<.01&&Math.abs(e.y-t.y)<.01&&Math.abs(e.w-t.w)<.01&&Math.abs(e.h-t.h)<.01}function sd(e,t){return e.length===t.length&&e.every((n,r)=>n===t[r])}var ld=/^(?:\d+(?:\.\d{1,2})?|\.\d{1,2})$/;function Ce(e){let t=typeof e=="number"?String(e):String(e??"").trim();if(!ld.test(t))return;let n=Number(t);if(!(!Number.isFinite(n)||n<.8||n>3))return cd(n)}function cd(e){return e.toFixed(2).replace(/\.?0+$/,"")}var Kr="#9ca3af";var ga="solid",ha=[{label:"\u30D9\u30BF",value:"solid"},{label:"\u53F3\u4E0A\u659C\u7DDA",value:"diagonal"},{label:"\u53F3\u4E0B\u659C\u7DDA",value:"diagonalBack"},{label:"\u683C\u5B50\u659C\u7DDA",value:"cross"},{label:"\u6A2A\u7DDA",value:"horizontal"},{label:"\u7E26\u7DDA",value:"vertical"},{label:"\u70B9\u3005",value:"dots"}];function bn(e){return ha.some(t=>t.value===e)}function qr(e){return bn(e)?e:ga}function Zr(e){return typeof e!="number"||!Number.isFinite(e)?.28:Math.min(1,Math.max(0,e))}function eo(e){return rt(e)?e.shapes.every(ot)&&Object.values(e.assets).every(Ue)&&(e.extensions===void 0||Et(e.extensions)):!1}function rt(e){return F(e)&&e.version===1&&Array.isArray(e.shapes)&&F(e.assets)}function Et(e){return F(e)&&Object.keys(e).every(ud)&&Object.values(e).every(Jr)}function nt(e){return F(e)&&Array.isArray(e.blocks)&&e.blocks.every(Ma)}function ot(e){if(!F(e)||typeof e.id!="string"||!k(e.x)||!k(e.y)||e.rotation!==void 0&&!k(e.rotation)||e.parentId!==void 0&&typeof e.parentId!="string"||e.groupId!==void 0&&typeof e.groupId!="string"||e.stackLayer!==void 0&&!fd(e.stackLayer)||e.locked!==void 0&&typeof e.locked!="boolean"||e.hidden!==void 0&&typeof e.hidden!="boolean"||e.opacity!==void 0&&(!k(e.opacity)||e.opacity<0||e.opacity>1)||e.anchor!==void 0&&!gd(e.anchor)||!F(e.props))return!1;switch(e.type){case"group":return et(e.props)&&(e.props.name===void 0||typeof e.props.name=="string");case"geo":return et(e.props)&&(e.props.geo==="rectangle"||e.props.geo==="ellipse"||e.props.geo==="triangle"||e.props.geo==="diamond"||e.props.geo==="pentagon"||e.props.geo==="regularPolygon"||e.props.geo==="blockArrow")&&(e.props.geo!=="regularPolygon"||k(e.props.polygonSides)&&Number.isInteger(e.props.polygonSides)&&e.props.polygonSides>=5&&e.props.polygonSides<=12)&&(e.props.apexX===void 0||k(e.props.apexX))&&(e.props.headLengthRatio===void 0||k(e.props.headLengthRatio)&&e.props.headLengthRatio>0&&e.props.headLengthRatio<1)&&(e.props.shaftRatio===void 0||k(e.props.shaftRatio)&&e.props.shaftRatio>0&&e.props.shaftRatio<=1)&&(e.props.radius===void 0||k(e.props.radius)&&e.props.radius>=0)&&(e.props.fill==="none"||e.props.fill==="solid")&&typeof e.props.color=="string"&&(e.props.fillColor===void 0||typeof e.props.fillColor=="string")&&(e.props.strokeOpacity===void 0||k(e.props.strokeOpacity)&&e.props.strokeOpacity>=0&&e.props.strokeOpacity<=1)&&(e.props.fillOpacity===void 0||k(e.props.fillOpacity)&&e.props.fillOpacity>=0&&e.props.fillOpacity<=1)&&typeof e.props.labelColor=="string"&&Ct(e.props.dash)&&Ve(e.props.size)&&(e.props.label===void 0||typeof e.props.label=="string");case"arc":return(e.props.kind===void 0||e.props.kind==="arc"||e.props.kind==="sector")&&k(e.props.r)&&e.props.r>0&&(e.props.rx===void 0||k(e.props.rx)&&e.props.rx>0)&&(e.props.ry===void 0||k(e.props.ry)&&e.props.ry>0)&&k(e.props.startAngle)&&k(e.props.endAngle)&&(e.props.arrowheadStart===void 0||tt(e.props.arrowheadStart))&&(e.props.arrowheadEnd===void 0||tt(e.props.arrowheadEnd))&&(e.props.fill===void 0||e.props.fill==="none"||e.props.fill==="solid")&&(e.props.fillColor===void 0||typeof e.props.fillColor=="string")&&(e.props.fillOpacity===void 0||k(e.props.fillOpacity)&&e.props.fillOpacity>=0&&e.props.fillOpacity<=1)&&(e.props.fillPattern===void 0||e.props.fillPattern==="diagonalHatch")&&typeof e.props.color=="string"&&(e.props.strokeOpacity===void 0||k(e.props.strokeOpacity)&&e.props.strokeOpacity>=0&&e.props.strokeOpacity<=1)&&Ct(e.props.dash)&&Ve(e.props.size);case"arrow":return Ee(e.props.start)&&Ee(e.props.end)&&(e.props.arrowheadStart===void 0||tt(e.props.arrowheadStart))&&tt(e.props.arrowheadEnd)&&e.props.fill==="none"&&typeof e.props.color=="string"&&(e.props.strokeOpacity===void 0||k(e.props.strokeOpacity)&&e.props.strokeOpacity>=0&&e.props.strokeOpacity<=1)&&typeof e.props.labelColor=="string"&&Ct(e.props.dash)&&Ve(e.props.size)&&(e.props.label===void 0||typeof e.props.label=="string");case"line":return Array.isArray(e.props.points)&&e.props.points.length>0&&e.props.points.every(Ee)&&(e.props.kind===void 0||yd(e.props.kind))&&typeof e.props.closed=="boolean"&&(e.props.arrowheadStart===void 0||tt(e.props.arrowheadStart))&&(e.props.arrowheadEnd===void 0||tt(e.props.arrowheadEnd))&&(e.props.fill===void 0||e.props.fill==="none"||e.props.fill==="solid")&&(e.props.fillColor===void 0||typeof e.props.fillColor=="string")&&(e.props.fillOpacity===void 0||k(e.props.fillOpacity)&&e.props.fillOpacity>=0&&e.props.fillOpacity<=1)&&typeof e.props.color=="string"&&(e.props.strokeOpacity===void 0||k(e.props.strokeOpacity)&&e.props.strokeOpacity>=0&&e.props.strokeOpacity<=1)&&Ct(e.props.dash)&&Ve(e.props.size)&&(e.props.labelColor===void 0||typeof e.props.labelColor=="string")&&(e.props.label===void 0||typeof e.props.label=="string");case"text":return k(e.props.w)&&(e.props.h===void 0||k(e.props.h)&&e.props.h>0)&&(e.props.maxWidth===void 0||k(e.props.maxWidth)&&e.props.maxWidth>0)&&(e.props.scale===void 0||k(e.props.scale)&&e.props.scale>0)&&nt(e.props.richText)&&typeof e.props.autoSize=="boolean"&&typeof e.props.color=="string"&&(e.props.fontSize===void 0||k(e.props.fontSize)&&e.props.fontSize>0)&&Ve(e.props.size);case"image":return typeof e.props.assetId=="string"&&et(e.props)&&(e.props.crop===void 0||md(e.props.crop));case"callout":return et(e.props)&&k(e.props.radius)&&e.props.radius>=0&&F(e.props.tail)&&Ee(e.props.tail.baseStart)&&Ee(e.props.tail.baseEnd)&&Ee(e.props.tail.tip)&&nt(e.props.richText)&&typeof e.props.color=="string"&&(e.props.fontSize===void 0||k(e.props.fontSize)&&e.props.fontSize>0)&&Ve(e.props.size)&&Ct(e.props.dash)&&Ve(e.props.strokeWidth);case"graph2dShape":return et(e.props)&&bd(e.props.spec)&&(e.props.boundsMode===void 0||e.props.boundsMode==="plot")&&(e.props.preserveSpecSize===void 0||typeof e.props.preserveSpecSize=="boolean")&&(e.props.axisLabelTextShapeIds===void 0||F(e.props.axisLabelTextShapeIds)&&Object.entries(e.props.axisLabelTextShapeIds).every(([t,n])=>xd(t)&&typeof n=="string"))&&(e.props.pointLabelTextShapeIdsByPointId===void 0||F(e.props.pointLabelTextShapeIdsByPointId)&&Object.values(e.props.pointLabelTextShapeIdsByPointId).every(t=>typeof t=="string"))&&(e.props.annotationTextShapeIdsByAnnotationId===void 0||F(e.props.annotationTextShapeIdsByAnnotationId)&&Object.values(e.props.annotationTextShapeIdsByAnnotationId).every(t=>typeof t=="string"))&&(e.props.labelTextShapeIds===void 0||Array.isArray(e.props.labelTextShapeIds)&&e.props.labelTextShapeIds.every(t=>typeof t=="string"))&&(e.props.labelTextShapeIdsByCurveId===void 0||F(e.props.labelTextShapeIdsByCurveId)&&Object.values(e.props.labelTextShapeIdsByCurveId).every(t=>typeof t=="string"));case"tableShape":return et(e.props)&&vd(e.props.table);default:return!1}}function Ue(e){return F(e)&&typeof e.id=="string"&&e.type==="image"&&F(e.props)&&k(e.props.w)&&k(e.props.h)&&typeof e.props.name=="string"&&e.props.isAnimated===!1&&(typeof e.props.mimeType=="string"||e.props.mimeType===null)&&typeof e.props.src=="string"&&k(e.props.fileSize)&&(e.props.storage===void 0||dd(e.props.storage))}function ud(e){return/^[a-z][a-z0-9]*(?:[.-][a-z][a-z0-9]*)+$/.test(e)}function Jr(e){return e===null||typeof e=="string"||typeof e=="boolean"?!0:typeof e=="number"?Number.isFinite(e):Array.isArray(e)?e.every(Jr):F(e)&&Object.values(e).every(Jr)}function dd(e){return F(e)&&e.kind==="remote-asset"&&typeof e.storageKey=="string"&&typeof e.assetId=="string"}function F(e){return typeof e=="object"&&e!==null}function Ma(e){return!F(e)||e.type!=="paragraph"&&e.type!=="heading"||!Array.isArray(e.children)||!e.children.every(Qr)||e.align!==void 0&&!to(e.align)||e.lineHeight!==void 0&&!pd(e.lineHeight)?!1:e.type!=="heading"||e.level===1||e.level===2||e.level===3}function pd(e){if(typeof e!="string"||!/^(?:\d+(?:\.\d{1,2})?|\.\d{1,2})$/u.test(e))return!1;let t=Number(e);return Number.isFinite(t)&&t>=.8&&t<=3}function k(e){return typeof e=="number"&&Number.isFinite(e)}function et(e){return k(e.w)&&k(e.h)}function Ee(e){return F(e)&&k(e.x)&&k(e.y)}function md(e){return F(e)&&Ee(e.topLeft)&&Ee(e.bottomRight)&&e.topLeft.x>=0&&e.topLeft.x<=1&&e.topLeft.y>=0&&e.topLeft.y<=1&&e.bottomRight.x>=0&&e.bottomRight.x<=1&&e.bottomRight.y>=0&&e.bottomRight.y<=1&&e.bottomRight.x>e.topLeft.x&&e.bottomRight.y>e.topLeft.y}function Ve(e){return e==="s"||e==="m"||e==="l"||e==="xl"}function fd(e){return e==="foreground"||e==="background"}function Ct(e){return e==="solid"||e==="dashed"||e==="dotted"}function tt(e){return e==="none"||e==="arrow"||e==="bar"||e==="dot"}function yd(e){return e==="polyline"||e==="curve"||e==="freehand"}function gd(e){return F(e)?e.type==="page"?!0:e.type==="shape"?typeof e.shapeId=="string"&&k(e.dx)&&k(e.dy)&&(e.rx===void 0||k(e.rx))&&(e.ry===void 0||k(e.ry)):e.type==="block"&&typeof e.blockId=="string"&&k(e.dy)&&(e.dx===void 0||k(e.dx))&&(e.reserveSpace===void 0||typeof e.reserveSpace=="boolean")&&(e.line===void 0||hd(e.line)):!1}function hd(e){return F(e)&&typeof e.index=="number"&&Number.isInteger(e.index)&&e.index>=0&&k(e.dy)}function xd(e){return e==="x"||e==="y"||e==="origin"}function bd(e){return!F(e)||e.kind!=="cartesian"&&e.kind!=="numberLine"?!1:typeof e.title=="string"&&k(e.width)&&k(e.height)&&xa(e.viewBox)&&(e.graphViewBox===void 0||xa(e.graphViewBox))&&F(e.axes)&&typeof e.axes.grid=="boolean"&&Array.isArray(e.curves)&&e.curves.every(Sd)&&(e.points===void 0||Array.isArray(e.points)&&e.points.every(Pd))&&(e.annotations===void 0||Array.isArray(e.annotations))&&(e.fills===void 0||Array.isArray(e.fills)&&e.fills.every(Md))&&(e.showFormulaLabels===void 0||typeof e.showFormulaLabels=="boolean")}function Sd(e){return F(e)&&typeof e.id=="string"&&typeof e.expr=="string"&&(e.yExpr===void 0||typeof e.yExpr=="string")&&typeof e.color=="string"&&(e.label===void 0||typeof e.label=="string")&&(e.mode===void 0||e.mode==="yOfX"||e.mode==="xOfY"||e.mode==="parametric"||e.mode==="implicit")&&(e.dash===void 0||e.dash==="solid"||e.dash==="dashed"||e.dash==="dotted")&&(e.strokeWidth===void 0||k(e.strokeWidth))&&(e.domain===void 0||F(e.domain)&&(e.domain.min===void 0||typeof e.domain.min=="string")&&(e.domain.max===void 0||typeof e.domain.max=="string"))}function xa(e){return F(e)&&typeof e.xMin=="string"&&typeof e.xMax=="string"&&typeof e.yMin=="string"&&typeof e.yMax=="string"}function Pd(e){return F(e)&&typeof e.id=="string"&&typeof e.x=="string"&&typeof e.y=="string"&&(e.color===void 0||typeof e.color=="string")&&(e.fill===void 0||e.fill==="solid"||e.fill==="none")&&(e.radius===void 0||k(e.radius))&&(e.label===void 0||typeof e.label=="string")&&(e.showXProjection===void 0||typeof e.showXProjection=="boolean")&&(e.showYProjection===void 0||typeof e.showYProjection=="boolean")}function Md(e){return F(e)&&typeof e.id=="string"&&typeof e.x=="string"&&typeof e.y=="string"&&(e.color===void 0||typeof e.color=="string")&&(e.pattern===void 0||bn(e.pattern))&&(e.opacity===void 0||k(e.opacity)&&e.opacity>=0&&e.opacity<=1)}function vd(e){if(!F(e)||e.version!==1||e.kind!=="plain"&&e.kind!=="variation"||!Array.isArray(e.columns)||!Array.isArray(e.rows)||!Array.isArray(e.cells)||!F(e.grid)||!Oa(e.defaultCellStyle)||e.columns.length===0||e.rows.length===0)return!1;let t=new Set;for(let r of e.columns){if(!Od(r)||t.has(r.id))return!1;t.add(r.id)}let n=new Set;for(let r of e.rows){if(!wd(r)||n.has(r.id))return!1;n.add(r.id)}return Ad(e.grid,n,t)?e.cells.every(r=>kd(r,n,t)):!1}function Od(e){return F(e)&&typeof e.id=="string"&&va(e.width)&&(e.role===void 0||e.role==="label"||e.role==="point"||e.role==="interval"||e.role==="value")}function wd(e){return F(e)&&typeof e.id=="string"&&va(e.height)&&(e.role===void 0||e.role==="header"||e.role==="body"||e.role==="variable"||e.role==="derivative"||e.role==="variation"||e.role==="note")}function va(e){return F(e)?e.mode==="fixed"?k(e.value)&&e.value>0:e.mode==="auto"?Sn(e.min)&&Sn(e.max):e.mode==="fr"&&k(e.value)&&e.value>0&&Sn(e.min)&&Sn(e.max):!1}function kd(e,t,n){return F(e)&&typeof e.id=="string"&&typeof e.rowId=="string"&&typeof e.columnId=="string"&&t.has(e.rowId)&&n.has(e.columnId)&&(e.rowSpan===void 0||Sa(e.rowSpan))&&(e.colSpan===void 0||Sa(e.colSpan))&&Array.isArray(e.content)&&e.content.every(Td)&&(e.style===void 0||Ed(e.style))}function Td(e){return!F(e)||typeof e.id!="string"?!1:e.type==="paragraph"?Array.isArray(e.children)&&e.children.every(Qr)&&(e.align===void 0||to(e.align)):e.type==="trend"&&(e.direction==="up"||e.direction==="down"||e.direction==="flat")&&(e.label===void 0||Array.isArray(e.label)&&e.label.every(Qr))}function Qr(e){return F(e)?e.type==="text"?typeof e.text=="string"&&(e.marks===void 0||Array.isArray(e.marks)&&e.marks.every(Bd))&&(e.color===void 0||typeof e.color=="string")&&(e.backgroundColor===void 0||typeof e.backgroundColor=="string")&&(e.fontFamily===void 0||typeof e.fontFamily=="string")&&(e.fontSize===void 0||k(e.fontSize)&&e.fontSize>0)&&(e.boxedPaddingY===void 0||k(e.boxedPaddingY)&&e.boxedPaddingY>=0)&&ba(e):e.type==="mathInline"&&typeof e.id=="string"&&e.id.length>0&&typeof e.tex=="string"&&e.display==="inline"&&(e.marks===void 0||Array.isArray(e.marks)&&e.marks.every(Rd))&&(e.color===void 0||typeof e.color=="string")&&(e.backgroundColor===void 0||typeof e.backgroundColor=="string")&&(e.fontFamily===void 0||typeof e.fontFamily=="string")&&(e.fontSize===void 0||k(e.fontSize)&&e.fontSize>0)&&(e.boxedPaddingY===void 0||k(e.boxedPaddingY)&&e.boxedPaddingY>=0)&&(e.semanticRole===void 0||e.semanticRole==="expression"||e.semanticRole==="equation"||e.semanticRole==="variable")&&(e.altText===void 0||typeof e.altText=="string")&&ba(e):!1}function Bd(e){return e==="bold"||e==="italic"||e==="underline"||e==="boxed"}function Rd(e){return e==="underline"||e==="boxed"}function ba(e){return(e.boxedVariant===void 0||e.boxedVariant==="frame"||e.boxedVariant==="thick"||e.boxedVariant==="double"||e.boxedVariant==="oval"||e.boxedVariant==="shade")&&(e.boxedTone===void 0||e.boxedTone==="gray"||e.boxedTone==="blue"||e.boxedTone==="green"||e.boxedTone==="red"||e.boxedTone==="yellow")}function Ad(e,t,n){return F(e)&&typeof e.borderColor=="string"&&k(e.borderWidth)&&e.borderWidth>=0&&(e.borderStyle===void 0||e.borderStyle==="solid"||e.borderStyle==="dashed"||e.borderStyle==="dotted"||e.borderStyle==="double")&&(e.showOuterBorder===void 0||typeof e.showOuterBorder=="boolean")&&(e.showInnerBorders===void 0||typeof e.showInnerBorders=="boolean")&&(e.lineOverrides===void 0||Array.isArray(e.lineOverrides)&&e.lineOverrides.every(r=>Id(r,t,n)))}function Id(e,t,n){if(!F(e)||!Cd(e.style))return!1;if(e.axis==="vertical"){let r="edge"in e,o="beforeColumnId"in e;return r===o?!1:r?e.edge==="left"||e.edge==="right":typeof e.beforeColumnId=="string"&&n.has(e.beforeColumnId)}if(e.axis==="horizontal"){let r="edge"in e,o="beforeRowId"in e;return r===o?!1:r?e.edge==="top"||e.edge==="bottom":typeof e.beforeRowId=="string"&&t.has(e.beforeRowId)}return!1}function Cd(e){return F(e)&&(e.visible===void 0||typeof e.visible=="boolean")&&(e.borderColor===void 0||typeof e.borderColor=="string")&&(e.borderWidth===void 0||k(e.borderWidth)&&e.borderWidth>=0)&&(e.borderStyle===void 0||e.borderStyle==="solid"||e.borderStyle==="dashed"||e.borderStyle==="dotted"||e.borderStyle==="double")}function Oa(e){return F(e)&&(e.align===void 0||to(e.align))&&(e.verticalAlign===void 0||e.verticalAlign==="top"||e.verticalAlign==="middle"||e.verticalAlign==="bottom")&&Pa(e.paddingX)&&Pa(e.paddingY)&&(e.color===void 0||typeof e.color=="string")&&(e.backgroundColor===void 0||typeof e.backgroundColor=="string")&&(e.fontFamily===void 0||typeof e.fontFamily=="string")&&(e.fontSize===void 0||k(e.fontSize)&&e.fontSize>0)&&(e.fontWeight===void 0||e.fontWeight==="normal"||e.fontWeight==="bold")}function Ed(e){return Oa(e)}function to(e){return e==="left"||e==="center"||e==="right"||e==="justify"}function Sa(e){return Number.isInteger(e)&&Number(e)>0}function Sn(e){return e===void 0||k(e)&&e>0}function Pa(e){return e===void 0||k(e)&&e>=0}function Ld(e){if(nt(e)||!le(e)||e.type!=="doc"||!Array.isArray(e.content))return e;let t=Nd(e.content);if(!t)return e;let n=[];for(let r of t){let o=Fd(r);if(!o)return e;n.push(o)}return{blocks:n}}function Pn(e){if(!le(e)||!Array.isArray(e.shapes))return e;let t=!1,n=e.shapes.map(r=>{if(!le(r)||r.type!=="text"&&r.type!=="callout"||!le(r.props))return r;let o=Ld(r.props.richText);return o===r.props.richText?r:(t=!0,{...r,props:{...r.props,richText:o}})});return t?{...e,shapes:n}:e}function Nd(e){let t=[];for(let n of e){if(!le(n))return null;if(n.type==="paragraph"||n.type==="heading"){t.push(n);continue}if(!Ba(n))return null;let r=t[t.length-1];r?.type==="paragraph"||r?.type==="heading"?t[t.length-1]={...r,content:[...Array.isArray(r.content)?r.content:[],n]}:t.push({type:"paragraph",content:[n]})}return t}function Fd(e){if(e.type!=="paragraph"&&e.type!=="heading"||e.content!==void 0&&!Array.isArray(e.content)||e.attrs!==void 0&&!le(e.attrs))return null;let t=_d(Array.isArray(e.content)?e.content:[]);if(!t)return null;let n=le(e.attrs)?e.attrs:{},r=Dd(n.textAlign),o=Ce(n.lineHeight);return e.type==="heading"?{type:"heading",level:n.level===1||n.level===2||n.level===3?n.level:2,children:t,...r?{align:r}:{},...o?{lineHeight:o}:{}}:{type:"paragraph",children:t,...r?{align:r}:{},...o?{lineHeight:o}:{}}}function _d(e){let t=[];for(let n of e){if(!Ba(n))return null;if(n.type==="hardBreak"){wa(t,`
8
+ `,t[t.length-1]?.type==="text"?t[t.length-1]:{});continue}let r=Array.isArray(n.marks)?n.marks:[],o=ka(r);if(n.type==="text"){wa(t,n.text,o);continue}let i=n.attrs,a=$d(r);t.push({type:"mathInline",id:typeof i.id=="string"&&i.id?i.id:`m_inline_${t.length}`,tex:i.tex,display:"inline",...a.length?{marks:a}:{},...Ta(o,a.includes("boxed")),semanticRole:"expression"})}return t}function ka(e){let t=new Set,n,r,o,i,a,s,l;for(let u of e){if(!le(u)||typeof u.type!="string")continue;if(u.type==="bold"||u.type==="italic"||u.type==="underline"){t.add(u.type);continue}let c=le(u.attrs)?u.attrs:{};if(u.type==="boxed"){t.add("boxed"),a=Hd(c.paddingY),s=Vd(c.variant),l=Ud(c.tone);continue}u.type==="styledText"&&(n=no(c.color),r=no(c.backgroundColor),o=no(c.fontFamily),i=zd(c.fontSize),(c.fontWeight==="bold"||Number(c.fontWeight)>=600)&&t.add("bold"),c.fontStyle==="italic"&&t.add("italic"),typeof c.textDecoration=="string"&&c.textDecoration.includes("underline")&&t.add("underline"))}return{...t.size?{marks:[...t]}:{},...n?{color:n}:{},...r?{backgroundColor:r}:{},...o?{fontFamily:o}:{},...i?{fontSize:i}:{},...a!==void 0?{boxedPaddingY:a}:{},...s?{boxedVariant:s}:{},...l?{boxedTone:l}:{}}}function $d(e){return(ka(e).marks??[]).filter(n=>n==="underline"||n==="boxed")}function wa(e,t,n){let r=e[e.length-1];if(r?.type==="text"&&JSON.stringify(r.marks??[])===JSON.stringify(n.marks??[])&&r.color===n.color&&r.backgroundColor===n.backgroundColor&&r.fontFamily===n.fontFamily&&r.fontSize===n.fontSize&&r.boxedPaddingY===n.boxedPaddingY&&r.boxedVariant===n.boxedVariant&&r.boxedTone===n.boxedTone){r.text+=t;return}e.push({type:"text",text:t,...Ta(n,n.marks?.includes("boxed")??!1),...n.marks?.length?{marks:n.marks}:{}})}function Ta(e,t){return{...e.color?{color:e.color}:{},...e.backgroundColor?{backgroundColor:e.backgroundColor}:{},...e.fontFamily?{fontFamily:e.fontFamily}:{},...e.fontSize?{fontSize:e.fontSize}:{},...t&&e.boxedPaddingY!==void 0?{boxedPaddingY:e.boxedPaddingY}:{},...t&&e.boxedVariant?{boxedVariant:e.boxedVariant}:{},...t&&e.boxedTone?{boxedTone:e.boxedTone}:{}}}function Ba(e){return!le(e)||e.marks!==void 0&&(!Array.isArray(e.marks)||!e.marks.every(Gd))?!1:e.type==="text"?typeof e.text=="string":e.type==="hardBreak"?!0:e.type==="mathInline"&&le(e.attrs)&&typeof e.attrs.tex=="string"}function Gd(e){return le(e)&&(e.type==="bold"||e.type==="italic"||e.type==="underline"||e.type==="boxed"||e.type==="styledText")&&(e.attrs===void 0||le(e.attrs))}function Dd(e){return e==="left"||e==="center"||e==="right"||e==="justify"?e:void 0}function zd(e){let t=typeof e=="number"?e:Number.parseFloat(String(e));if(!Number.isFinite(t)||t<=0)return;let n=typeof e=="string"&&/px$/iu.test(e.trim())?t/(96/72):t;return Math.round(n*100)/100}function Hd(e){let t=typeof e=="number"?e:Number.parseFloat(String(e));return Number.isFinite(t)&&t>=0?Math.min(12,Math.round(t*10)/10):void 0}function no(e){return typeof e=="string"&&e.length>0?e:void 0}function Vd(e){return e==="frame"||e==="thick"||e==="double"||e==="oval"||e==="shade"?e:void 0}function Ud(e){return e==="gray"||e==="blue"||e==="green"||e==="red"||e==="yellow"?e:void 0}function le(e){return typeof e=="object"&&e!==null}var Wd="sigma.legacy.metadata",Yd=["id","type","x","y","rotation","parentId","groupId","stackLayer","locked","hidden","opacity","anchor","props"],Xd={group:["w","h","name"],geo:["w","h","geo","polygonSides","apexX","headLengthRatio","shaftRatio","radius","fill","color","fillColor","strokeOpacity","fillOpacity","labelColor","dash","size","label"],arc:["kind","r","rx","ry","startAngle","endAngle","arrowheadStart","arrowheadEnd","fill","fillColor","fillOpacity","fillPattern","color","strokeOpacity","dash","size"],arrow:["start","end","arrowheadStart","arrowheadEnd","fill","color","strokeOpacity","labelColor","dash","size","label"],line:["kind","points","closed","arrowheadStart","arrowheadEnd","fill","fillColor","fillOpacity","fillPattern","color","strokeOpacity","labelColor","dash","size","label"],text:["w","h","maxWidth","scale","richText","autoSize","color","fontSize","size"],image:["assetId","w","h","crop"],callout:["w","h","radius","tail","richText","color","fontSize","size","dash","strokeWidth"],graph2dShape:["boundsMode","w","h","spec","preserveSpecSize","axisLabelTextShapeIds","pointLabelTextShapeIdsByPointId","annotationTextShapeIdsByAnnotationId","labelTextShapeIds","labelTextShapeIdsByCurveId"],tableShape:["w","h","table"]};function Ia(){return{version:1,shapes:[],assets:{}}}var Ra=new WeakMap;function ue(e){let t=typeof e=="object"&&e!==null?e:null,n=t?Ra.get(t):void 0;if(n)return n;let r=Pn(e);if(!rt(r))return Ia();let o=ao(r),i=r.shapes.filter(ot).map(oo),a={version:1,shapes:Xr(Ea(i)),assets:Object.fromEntries(Object.entries(r.assets).filter(s=>Ue(s[1])).map(([s,l])=>[s,io(l)])),...o?{extensions:o}:{}};return t&&Ra.set(t,a),a}function ro(e){let t=Pn(e);if(!rt(t))return{snapshot:Ia(),issues:[{kind:"snapshot"}]};let n=[],r=t.shapes.flatMap((a,s)=>ot(a)?[oo(a)]:(n.push({kind:"shape",index:s,id:it(a)&&typeof a.id=="string"?a.id:void 0,type:it(a)&&typeof a.type=="string"?a.type:void 0}),[])),o=Object.entries(t.assets).flatMap(([a,s])=>Ue(s)?[[a,io(s)]]:(n.push({kind:"asset",key:a}),[])),i=ao(t);return{snapshot:{version:1,shapes:Xr(Ea(r)),assets:Object.fromEntries(o),...i?{extensions:i}:{}},issues:n}}function Ca(e){let t=Pn(e);if(!rt(t)||!t.shapes.every(ot)||!Object.values(t.assets).every(Ue)||t.extensions!==void 0&&!Et(t.extensions))return t;let n=ao(t);return{version:1,shapes:t.shapes.map(oo),assets:Object.fromEntries(Object.entries(t.assets).filter(r=>Ue(r[1])).map(([r,o])=>[r,io(o)])),...n?{extensions:n}:{}}}function jd(e){let t={...e};for(let n of["parentId","groupId","stackLayer","locked","hidden","opacity","anchor"])t[n]===void 0&&delete t[n];return t}function oo(e){let n=Lt(e,Yd);n.props=Lt(e.props,Xd[e.type]),e.anchor&&(n.anchor=Zd(e.anchor));let r=n.props;return(e.type==="text"||e.type==="callout")&&(r.richText=Kd(e.props.richText)),e.type==="arrow"?(r.start=Le(e.props.start),r.end=Le(e.props.end)):e.type==="line"?r.points=e.props.points.map(Le):e.type==="image"&&e.props.crop?r.crop={topLeft:Le(e.props.crop.topLeft),bottomRight:Le(e.props.crop.bottomRight)}:e.type==="callout"&&(r.tail={baseStart:Le(e.props.tail.baseStart),baseEnd:Le(e.props.tail.baseEnd),tip:Le(e.props.tail.tip)}),jd(n)}function io(e){let t=Lt(e.props,["w","h","name","isAnimated","mimeType","src","fileSize","storage"]);return e.props.storage&&(t.storage={kind:"remote-asset",storageKey:e.props.storage.storageKey,assetId:e.props.storage.assetId}),{id:e.id,type:"image",props:t}}function Kd(e){return{blocks:e.blocks.map(t=>({...Lt(t,["type","level","align","lineHeight"]),children:t.children.map(qd)}))}}function qd(e){let t=e.type==="text"?["type","text","marks","color","backgroundColor","fontFamily","fontSize","boxedPaddingY","boxedVariant","boxedTone"]:["type","id","tex","display","marks","color","backgroundColor","fontFamily","fontSize","boxedPaddingY","boxedVariant","boxedTone","semanticRole","altText"];return Lt(e,t)}function Zd(e){return e.type==="block"?{type:"block",blockId:e.blockId,dy:e.dy,...e.dx===void 0?{}:{dx:e.dx},...e.line===void 0?{}:{line:{index:e.line.index,dy:e.line.dy}},...e.reserveSpace===void 0?{}:{reserveSpace:e.reserveSpace}}:e.type==="shape"?{type:"shape",shapeId:e.shapeId,dx:e.dx,dy:e.dy,...e.rx===void 0?{}:{rx:e.rx},...e.ry===void 0?{}:{ry:e.ry}}:{type:"page"}}function Le(e){return{x:e.x,y:e.y}}function ao(e){let t=Et(e.extensions)?{...e.extensions}:{},n=Object.fromEntries(e.shapes.flatMap(o=>it(o)&&Mn(o.meta)&&Aa(o.meta)?[[typeof o.id=="string"?o.id:`index:${e.shapes.indexOf(o)}`,o.meta]]:[])),r=Object.fromEntries(Object.entries(e.assets).flatMap(([o,i])=>it(i)&&Mn(i.meta)&&Aa(i.meta)?[[o,i.meta]]:[]));return(Object.keys(n).length>0||Object.keys(r).length>0)&&(t[Wd]={...Object.keys(n).length>0?{shapes:n}:{},...Object.keys(r).length>0?{assets:r}:{}}),Object.keys(t).length>0?t:void 0}function Lt(e,t){return Object.fromEntries(t.flatMap(n=>e[n]===void 0?[]:[[n,e[n]]]))}function Mn(e){return e===null||typeof e=="string"||typeof e=="boolean"?!0:typeof e=="number"?Number.isFinite(e):Array.isArray(e)?e.every(Mn):it(e)&&Object.values(e).every(Mn)}function Aa(e){return!it(e)||Object.keys(e).length>0}function it(e){return typeof e=="object"&&e!==null}function Ea(e){let t=new Map,n=e.map(r=>{if(r.type!=="graph2dShape"||r.props.boundsMode==="plot")return r;let o=hn(r);return t.set(r.id,{previous:r,next:o,dx:o.x-r.x,dy:o.y-r.y}),o});return t.size===0?n:n.map(r=>{let o=r.anchor;if(o?.type!=="shape")return r;let i=t.get(r.id),a=t.get(o.shapeId);if(!i&&!a)return r;if(!a)return{...r,anchor:{...o,dx:o.dx+(i?.dx??0),dy:o.dy+(i?.dy??0)}};let s=a.previous,l=a.next,u=o.rx===void 0?s.x:s.x+s.props.w*o.rx,c=o.ry===void 0?s.y:s.y+s.props.h*o.ry,p=o.rx===void 0?l.x:l.x+l.props.w*o.rx,m=o.ry===void 0?l.y:l.y+l.props.h*o.ry;return{...r,anchor:{...o,dx:u+o.dx+(i?.dx??0)-p,dy:c+o.dy+(i?.dy??0)-m}}})}var st=96/25.4,vn={A4:{widthMm:210,heightMm:297},A3:{widthMm:297,heightMm:420},B5:{widthMm:182,heightMm:257},B4:{widthMm:257,heightMm:364}},On=vn.A4,at={top:18,right:17,bottom:18,left:17},Jd={type:"columns",columnCount:1,columnGapMm:8},wn=30,Ga={enabled:!1,heightMm:8,offsetMm:5,showOnFirstPage:!0,blocks:[{type:"paragraph",id:"page_header_running_body",children:[{type:"text",text:"{title}"}]}]},Da={enabled:!1,heightMm:8,offsetMm:5,showOnFirstPage:!0,blocks:[{type:"paragraph",id:"page_footer_running_body",children:[{type:"text",text:"{page}"}],align:"center"}]},Tn={width:J(On.widthMm),height:J(On.heightMm)},JS={width:J(On.widthMm-at.left-at.right),height:J(On.heightMm-at.top-at.bottom)},co=36;function J(e){return e*st}function za(e,t,n){let r=e==="custom"?{widthMm:Nt(n?.widthMm,vn.A4.widthMm),heightMm:Nt(n?.heightMm,vn.A4.heightMm)}:vn[e];return t==="landscape"?{widthMm:Math.max(r.widthMm,r.heightMm),heightMm:Math.min(r.widthMm,r.heightMm)}:{widthMm:Math.min(r.widthMm,r.heightMm),heightMm:Math.max(r.widthMm,r.heightMm)}}function Ha(){return{preset:"A4",orientation:"portrait",pageSize:za("A4","portrait"),marginsMm:{...at},flow:{...Jd},header:_a(Ga),footer:_a(Da)}}function lt(e){let t=Ha(),n=tp(e?.preset)?e.preset:t.preset,r=np(e?.orientation)?e.orientation:t.orientation,o=n==="custom"?e?.pageSize:void 0,i=za(n,r,o),a=rp(e?.flow?.columnCount,1,4,t.flow.columnCount),s=he(e?.flow?.columnGapMm,t.flow.columnGapMm);return{preset:n,orientation:r,pageSize:i,marginsMm:{top:he(e?.marginsMm?.top,t.marginsMm.top),right:he(e?.marginsMm?.right,t.marginsMm.right),bottom:he(e?.marginsMm?.bottom,t.marginsMm.bottom),left:he(e?.marginsMm?.left,t.marginsMm.left)},flow:{type:"columns",columnCount:a,columnGapMm:s},header:La(e?.header,Ga),footer:La(e?.footer,Da),overlay:Ja(e?.overlay)}}function Bn(e=Ha()){let t=lt(e),n=Math.max(0,t.pageSize.widthMm-t.marginsMm.left-t.marginsMm.right),r=Math.max(0,t.pageSize.heightMm-t.marginsMm.top-t.marginsMm.bottom),o=t.flow.columnGapMm*Math.max(0,t.flow.columnCount-1),i=t.flow.columnCount>0?Math.max(0,(n-o)/t.flow.columnCount):n;return{page:{widthMm:t.pageSize.widthMm,heightMm:t.pageSize.heightMm,widthPx:J(t.pageSize.widthMm),heightPx:J(t.pageSize.heightMm)},margins:{topPx:J(t.marginsMm.top),rightPx:J(t.marginsMm.right),bottomPx:J(t.marginsMm.bottom),leftPx:J(t.marginsMm.left)},content:{widthMm:n,heightMm:r,widthPx:J(n),heightPx:J(r)},flow:{columnCount:t.flow.columnCount,columnGapMm:t.flow.columnGapMm,columnGapPx:J(t.flow.columnGapMm),columnWidthMm:i,columnWidthPx:J(i)}}}function uo(e){let t=lt(e),n={...t.marginsMm};return t.header?.enabled&&(n.top=Math.max(n.top,t.header.offsetMm+t.header.heightMm)),t.footer?.enabled&&(n.bottom=Math.max(n.bottom,t.footer.offsetMm+t.footer.heightMm)),{...t,marginsMm:n}}function Va(e){let t=[],n=Bn(e);return(!Number.isFinite(e.pageSize.widthMm)||!Number.isFinite(e.pageSize.heightMm)||e.pageSize.widthMm<=0||e.pageSize.heightMm<=0)&&t.push("\u7528\u7D19\u30B5\u30A4\u30BA\u306F0\u3088\u308A\u5927\u304D\u3044\u5024\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002"),(!Number.isFinite(e.marginsMm.top)||!Number.isFinite(e.marginsMm.right)||!Number.isFinite(e.marginsMm.bottom)||!Number.isFinite(e.marginsMm.left)||e.marginsMm.top<0||e.marginsMm.right<0||e.marginsMm.bottom<0||e.marginsMm.left<0)&&t.push("\u4F59\u767D\u306F0\u4EE5\u4E0A\u306E\u5024\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002"),e.marginsMm.left+e.marginsMm.right>=e.pageSize.widthMm&&t.push("\u5DE6\u53F3\u306E\u4F59\u767D\u304C\u7528\u7D19\u5E45\u4EE5\u4E0A\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u3002"),e.marginsMm.top+e.marginsMm.bottom>e.pageSize.heightMm-wn&&t.push(`\u4E0A\u4E0B\u306E\u4F59\u767D\u306F\u672C\u6587\u3092${wn}mm\u4EE5\u4E0A\u6B8B\u3059\u3088\u3046\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002`),(!Number.isInteger(e.flow.columnCount)||e.flow.columnCount<1||e.flow.columnCount>4)&&t.push("\u6BB5\u6570\u306F1\u304B\u30894\u306E\u6574\u6570\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002"),(!Number.isFinite(e.flow.columnGapMm)||e.flow.columnGapMm<0)&&t.push("\u6BB5\u9593\u306F0\u4EE5\u4E0A\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002"),e.flow.columnGapMm*Math.max(0,e.flow.columnCount-1)>=n.content.widthMm&&t.push("\u6BB5\u9593\u304C\u672C\u6587\u5E45\u4EE5\u4E0A\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u3002"),t}function Ua(e){return!!(e?.blocks.some(ts)||ap(e?.overlay))}function Ne(e,t=54){if(e.type==="section")return 64;if(e.type==="heading")return 48+Math.max(0,e.level-1)*4+kn(e.children,t)*10;if(e.type==="paragraph")return 18+kn(e.children,t)*qa(e.lineHeight);if(e.type==="list")return 12+Ka(e,t);if(e.type==="boxBlock"){let n=e.frame?.paddingPx;return(n?.top??12)+(n?.bottom??12)+Wa(e,t)+Math.max(24,ep(e.blocks,Ya(t)))}if(e.type==="layoutSection"){let n=Number.isInteger(e.layout.columnCount)?Math.min(4,Math.max(1,e.layout.columnCount)):2,r=Math.max(12,Math.floor(t/n)),o=e.children.reduce((i,a)=>i+Ne(a,r),0);return Math.max(32,Math.ceil(o/n))}return e.type==="problem"?Xa.reduce((n,r)=>n+ja(e,r,t),0):48}function Wa(e,t){return e.title&&e.title.length>0?kn(e.title,t)*18:0}function Ya(e){return Math.max(12,e-4)}var Xa=["lead","prompt","solution","hints"];function ja(e,t,n){return Math.max(Qd(e[t],n),J(e.areaLayout?.[t]?.minHeightMm??0))}function Qd(e,t){return e.reduce((n,r)=>n+Ne(r,t),0)}function ep(e,t){return e.reduce((n,r)=>n+Ne(r,t),0)}function Ka(e,t,n=0){let r=Math.max(8,t-n*4-3);return e.items.reduce((o,i)=>{let a=kn(i.children,r)*qa(void 0),s=(i.nested??[]).reduce((l,u)=>l+Ka(u,t,n+1),0);return o+a+s},0)}function kn(e,t){let n=e.reduce((r,o)=>o.type==="text"?r+o.text.length:r+Math.max(4,o.tex.length),0);return Math.max(1,Math.ceil(n/t))}function qa(e){let t=Number(e??"1.75");return 16*(Number.isFinite(t)?t:1.75)}function tp(e){return e==="A4"||e==="A3"||e==="B5"||e==="B4"||e==="custom"}function np(e){return e==="portrait"||e==="landscape"}function Nt(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:t}function he(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:t}function rp(e,t,n,r){return typeof e!="number"||!Number.isFinite(e)?r:Math.min(n,Math.max(t,Math.round(e)))}function La(e,t){let n=Za(e?.blocks);return{enabled:typeof e?.enabled=="boolean"?e.enabled:t.enabled,heightMm:Nt(e?.heightMm,t.heightMm),offsetMm:he(e?.offsetMm,t.offsetMm),showOnFirstPage:typeof e?.showOnFirstPage=="boolean"?e.showOnFirstPage:t.showOnFirstPage,blocks:n??t.blocks.map(Qa),overlay:Ja(e?.overlay)}}function Za(e){return Array.isArray(e)?e.flatMap(n=>{if(!n||typeof n!="object"||!("type"in n))return[];if(n.type==="heading"&&Array.isArray(n.children)){let r=n.level===1||n.level===2||n.level===3?n.level:2;return[{type:"heading",id:typeof n.id=="string"&&n.id?n.id:"running_heading",level:r,children:so(n.children),align:$a(n.align),lineHeight:Ce(n.lineHeight)}]}if(n.type==="paragraph"&&Array.isArray(n.children))return[{type:"paragraph",id:typeof n.id=="string"&&n.id?n.id:"running_paragraph",children:so(n.children),align:$a(n.align),lineHeight:Ce(n.lineHeight)}];if(n.type==="list"&&(n.listType==="bullet"||n.listType==="ordered")&&Array.isArray(n.items)){let r=op(n.items);return r.length===0?[]:[{type:"list",id:typeof n.id=="string"&&n.id?n.id:"running_list",listType:n.listType,start:Nt(n.start,0)||void 0,items:r}]}return[]}):void 0}function op(e){return e.flatMap(t=>{if(!ip(t)||t.type!=="listItem"||!Array.isArray(t.children))return[];let n=Array.isArray(t.nested)?Za(t.nested)?.filter(r=>r.type==="list"):void 0;return[{type:"listItem",id:typeof t.id=="string"&&t.id?t.id:"running_list_item",children:so(t.children),...n&&n.length>0?{nested:n}:{}}]})}function ip(e){return typeof e=="object"&&e!==null}function Ja(e){if(!e||typeof e!="object")return;let t=e,n=t.overlaySnapshot?ue(t.overlaySnapshot):void 0,r=typeof t.previewSvg=="string"?t.previewSvg:void 0,o=typeof t.updatedAt=="string"?t.updatedAt:void 0;if(!(!n&&!r))return{...n?{overlaySnapshot:n}:{},...!n&&r?{previewSvg:r}:{},...o?{updatedAt:o}:{}}}function ap(e){return e?e.overlaySnapshot?ue(e.overlaySnapshot).shapes.some(t=>!t.hidden):typeof e.previewSvg=="string"&&e.previewSvg.trim().length>0:!1}function so(e){return e.flatMap(t=>{if(!t||typeof t!="object"||!("type"in t))return[];let n=t;if(t.type==="text"){let r=Na(n.boxedVariant),o=Fa(n.boxedTone);return[{type:"text",text:typeof n.text=="string"?n.text:"",marks:sp(n.marks),color:typeof n.color=="string"?n.color:void 0,backgroundColor:typeof n.backgroundColor=="string"?n.backgroundColor:void 0,fontFamily:typeof n.fontFamily=="string"?n.fontFamily:void 0,fontSize:Nt(n.fontSize,0)||void 0,boxedPaddingY:he(n.boxedPaddingY,-1)>=0?he(n.boxedPaddingY,0):void 0,...r?{boxedVariant:r}:{},...o?{boxedTone:o}:{}}]}if(t.type==="mathInline"){let r=lp(n.marks),o=Na(n.boxedVariant),i=Fa(n.boxedTone);return[{type:"mathInline",id:typeof n.id=="string"&&n.id?n.id:"running_math",tex:typeof n.tex=="string"?n.tex:"",display:"inline",...r?{marks:r}:{},...r?.includes("boxed")&&he(n.boxedPaddingY,-1)>=0?{boxedPaddingY:he(n.boxedPaddingY,0)}:{},...o?{boxedVariant:o}:{},...i?{boxedTone:i}:{},semanticRole:n.semanticRole==="equation"||n.semanticRole==="variable"?n.semanticRole:"expression"}]}return[]})}function sp(e){if(!Array.isArray(e))return;let t=e.filter(n=>n==="bold"||n==="italic"||n==="underline"||n==="boxed");return t.length>0?Array.from(new Set(t)):void 0}function lp(e){if(!Array.isArray(e))return;let t=e.filter(n=>n==="underline"||n==="boxed");return t.length>0?Array.from(new Set(t)):void 0}function Na(e){return e==="frame"||e==="thick"||e==="double"||e==="oval"||e==="shade"?e:void 0}function Fa(e){return e==="gray"||e==="blue"||e==="green"||e==="red"||e==="yellow"?e:void 0}function _a(e){return{...e,blocks:e.blocks?.map(Qa),overlay:cp(e.overlay)}}function cp(e){if(e)return{...e,overlaySnapshot:e.overlaySnapshot?ue(e.overlaySnapshot):void 0}}function Qa(e){return e.type==="heading"?{...e,children:e.children.map(lo)}:e.type==="paragraph"?{...e,children:e.children.map(lo)}:es(e)}function es(e){return{...e,items:e.items.map(t=>({...t,children:t.children.map(lo),nested:t.nested?.map(es)}))}}function lo(e){return e.type==="mathInline"?{...e,...e.marks?{marks:[...e.marks]}:{}}:{...e,marks:e.marks?[...e.marks]:void 0}}function ts(e){return e.type==="list"?e.items.some(t=>t.children.some(n=>n.type==="mathInline"?n.tex.trim():n.text.trim())||(t.nested??[]).some(ts)):e.children.some(t=>t.type==="mathInline"?t.tex.trim():t.text.trim())}function $a(e){return e==="left"||e==="center"||e==="right"||e==="justify"?e:void 0}var Rn=["lead","prompt","hints","solution"];function ct(e){return e.map(t=>t.type==="text"?t.text:`$${t.tex}$`).join("")}var up=2;function ns(e,t,n,r){let o=dp(e);return pp(o.length>0?o:[e.getBoundingClientRect()]).map((a,s)=>({index:s,top:(a.top-t.top)*r,left:(a.left-t.left)*n,width:Math.max(0,(a.right-a.left)*n),height:Math.max(0,(a.bottom-a.top)*r)}))}function dp(e){let t=e.ownerDocument.createRange();try{return t.selectNodeContents(e),Array.from(t.getClientRects()).filter(n=>n.width>0&&n.height>0)}finally{t.detach()}}function pp(e){let t=[],n=[...e].sort((r,o)=>r.top-o.top||r.left-o.left);for(let r of n){let o=t.find(i=>mp(r,i));if(!o){t.push({top:r.top,right:r.right,bottom:r.bottom,left:r.left});continue}o.top=Math.min(o.top,r.top),o.right=Math.max(o.right,r.right),o.bottom=Math.max(o.bottom,r.bottom),o.left=Math.min(o.left,r.left)}return t.sort((r,o)=>r.top-o.top||r.left-o.left)}function mp(e,t){let n=(e.top+e.bottom)/2,r=(t.top+t.bottom)/2;if(Math.abs(n-r)<=up)return!0;let o=Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top),i=Math.min(e.height,t.bottom-t.top);return o>Math.max(1,i*.45)}import Ap from"katex";import Ip from"katex/src/fontMetricsData.js";import fp from"katex";import{convertLatexToMarkup as yp,validateLatex as gp}from"mathlive";var rs=/\\begin\{(aligned|alignedat|array|cases|displaylines|matrix|pmatrix|bmatrix|Bmatrix|vmatrix|Vmatrix|smallmatrix)\}([\s\S]*?)\\end\{\1\}/g,ls="\\\\";var hp=new Set(["mbox","text"]),xp=/[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}\u3000-\u303f\uff01-\uff60\uffe0-\uffee]/u,bp={maxExpand:1e3,maxSize:100,output:"html",strict:"ignore",throwOnError:!0,trust:!1},Sp=new Set(["bar","boldsymbol","boxed","ddot","dot","hat","mathbb","mathbf","mathcal","mathfrak","mathit","mathrm","mathscr","mathsf","mathtt","mbox","operatorname","overline","text","textbf","textit","textrm","tilde","underline","vec","widehat","widetilde"]),Pp=new Set(["overset","stackrel","underset"]);function cs(e,t){return t!=="uniform"||!e.includes("\\frac")?e:us(e,0,e.length,!1).text}function us(e,t,n,r,o){let i=t,a="";for(;i<n;){let s=e[i];if(s===o)break;if(s==="%"){let l=e.indexOf(`
9
+ `,i),u=l===-1||l>=n?n:l;a+=e.slice(i,u),i=u;continue}if(s==="{"){let l=po(e,i,n,"{","}",r);a+=l.text,i=l.end;continue}if(s==="^"||s==="_"){for(a+=s,i+=1;i<n&&/\s/.test(e[i]);)a+=e[i],i+=1;let l=ds(e,i,n);a+=l.text,i=l.end;continue}if(s==="\\"){let l=ps(e,i,n);a+=l.name==="frac"&&!r?"\\dfrac":e.slice(i,l.end),i=l.end;continue}a+=s,i+=1}return{end:i,text:a}}function ds(e,t,n){if(t>=n)return{end:t,text:""};if(e[t]==="{")return po(e,t,n,"{","}",!0);if(e[t]!=="\\")return{end:t+1,text:e[t]};let r=ps(e,t,n),o=r.end,i=e.slice(t,o),a=r.name==="frac"||r.name==="dfrac"||r.name==="tfrac"||r.name==="cfrac"||Pp.has(r.name)?2:Sp.has(r.name)||r.name==="sqrt"?1:0;if(r.name==="operatorname"&&e[o]==="*"&&(i+="*",o+=1),r.name==="sqrt"){let s=os(e,o,n);if(i+=e.slice(o,s),o=s,e[o]==="["){let l=po(e,o,n,"[","]",!0);i+=l.text,o=l.end}}for(let s=0;s<a;s+=1){let l=os(e,o,n);i+=e.slice(o,l),o=l;let u=ds(e,o,n);if(u.end===o)break;i+=u.text,o=u.end}return{end:o,text:i}}function po(e,t,n,r,o,i){let a=us(e,t+1,n,i,o),s=a.end,l=r+a.text;return s<n&&e[s]===o&&(l+=o,s+=1),{end:s,text:l}}function os(e,t,n){let r=t;for(;r<n&&/\s/.test(e[r]);)r+=1;return r}function ps(e,t,n){let r=t+1;if(r>=n)return{end:r,name:""};if(!/[A-Za-z@]/.test(e[r]))return{end:r+1,name:e[r]};let o=r;for(;r<n&&/[A-Za-z@]/.test(e[r]);)r+=1;return{end:r,name:e.slice(o,r)}}var Ft=new Map;var Mp=5e3;function An(e){let t=Ft.get(e);if(t!==void 0)return t;let n=vp(e)||"\\square",i=(gp(n).length>0?Rp(mo(e)||"\\square"):null)??yp(n,{defaultMode:"math"});if(Ft.size>=Mp){let a=Ft.keys().next().value;a!==void 0&&Ft.delete(a)}return Ft.set(e,i),i}function vp(e){return fs(ms(e)).replace(/\\placeholder(?:\[([^\]]*)\])?\{\s*\}/g,(t,n)=>`\\placeholder[${n||"?"}]{\\square}`).replace(/\\placeholder\{([^{}]+)\}/g,(t,n)=>`\\placeholder[?]{${n}}`)}function mo(e){return fs(ms(e)).replace(/\\placeholder(?:\[[^\]]*\])?\{([^{}]*)\}/g,(t,n)=>n.trim()?`{${n}}`:"\\square")}function ms(e){if(!e.includes(ls)||/^\s*\\displaylines\{/.test(e))return e;let t="",n=0,r;for(rs.lastIndex=0;(r=rs.exec(e))!==null;)t+=is(e.slice(n,r.index)),t+=r[0],n=r.index+r[0].length;return t+=is(e.slice(n)),t}function fs(e){let t="",n=0;for(;n<e.length;){if(e[n]==="\\"){let o=Tp(e,n),i=o.name&&hp.has(o.name)?Bp(e,o.end):-1;if(i>=0){t+=e.slice(n,i+1),n=i+1;continue}t+=e.slice(n,o.end),n=o.end;continue}if(as(e,n)){let o=n;do n+=ss(e,n);while(n<e.length&&as(e,n));t+=`\\text{${e.slice(o,n)}}`;continue}let r=ss(e,n);t+=e.slice(n,n+r),n+=r}return t}function is(e){let t=Op(e.trim()).map(o=>o.trim()).filter(Boolean);if(t.length<2)return e;let n=e.match(/^\s*/)?.[0]??"",r=e.match(/\s*$/)?.[0]??"";return`${n}\\begin{aligned}${t.map(kp).join(ls)}\\end{aligned}${r}`}function Op(e){let t=[],n=0;for(let r=0;r<e.length-1;r+=1)wp(e,r)&&(t.push(e.slice(n,r)),r+=1,n=r+1);return t.push(e.slice(n)),t}function wp(e,t){return e[t]==="\\"&&e[t+1]==="\\"&&e[t-1]!=="\\"&&e[t+2]!=="\\"}function kp(e){return e.includes("&")?e:e.replace(/\s*(=|<|>|\\leq{0,2}\b|\\geq{0,2}\b|\\neq?\b|\\approx\b|\\equiv\b|\\iff\b|\\to\b|\\Rightarrow\b|\\Leftarrow\b)/,"&$1")}function Tp(e,t){let n=t+1;for(;n<e.length&&/[a-zA-Z]/.test(e[n]??"");)n+=1;return n>t+1?{end:n,name:e.slice(t+1,n)}:{end:Math.min(t+2,e.length),name:null}}function Bp(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]??"");)n+=1;if(e[n]!=="{")return-1;let r=0;for(;n<e.length;n+=1){let o=e[n];if(o==="\\"){n+=1;continue}if(o==="{")r+=1;else if(o==="}"&&(r-=1,r===0))return n}return-1}function as(e,t){let n=e.codePointAt(t);return n===void 0?!1:xp.test(String.fromCodePoint(n))}function ss(e,t){let n=e.codePointAt(t);return n!==void 0&&n>65535?2:1}function Rp(e){try{return fp.renderToString(e,bp)}catch{return null}}var fo=Ip,Cp=Ap.__renderToHTMLTree,Ep=/class="ML__strut" style="height:([0-9.]+)em"/,Lp=/class="ML__strut--bottom" style="height:([0-9.]+)em;vertical-align:-([0-9.]+)em"/,Np={maxExpand:1e3,maxSize:100,output:"html",strict:"ignore",throwOnError:!0,trust:!1},Fp=/\\(?:frac|dfrac|tfrac|cfrac|sqrt|int|oint|iint|iiint|sum|prod|coprod|lim|begin|binom|dbinom|tbinom|overbrace|underbrace)\b/,ys=[.5,.6,.7,.8,.9,1,1.2,1.44,1.728,2.074,2.488],_p=/^reset-size(\d+)$/,$p=/^size(\d+)$/,Gp=.12,Dp=1,xs=.6,zp=1e-4,gs=1.05,hs=1.25,Hp=1.05,Vp=1.6,Up=1,_t=new Map,Wp=5e3;function Cn(e){let t=_t.get(e);if(t!==void 0)return t;let n=Yp(e);if(_t.size>=Wp){let r=_t.keys().next().value;r!==void 0&&_t.delete(r)}return _t.set(e,n),n}function Yp(e){let t=Xp(e),n=jp(e),r=(n?n.widthEm:em(e))*Hp;if(t){let o=n?Math.max(t.ascentEm,n.ascentEm):t.ascentEm,i=n?Math.max(t.descentEm,n.descentEm):t.descentEm;return{ascentEm:o*gs,descentEm:i*gs,widthEm:r,source:"mathlive"}}return n?{ascentEm:n.ascentEm*hs,descentEm:n.descentEm*hs,widthEm:r,source:"katex"}:{ascentEm:Fp.test(e)?Vp:Up,descentEm:0,widthEm:r,source:"heuristic"}}function Xp(e){let t;try{t=An(e)}catch{return null}let n=t.match(Ep);if(!n)return null;let r=t.match(Lp),o=Number.parseFloat(n[1]),i=r?Number.parseFloat(r[2]):0;return!Number.isFinite(o)||!Number.isFinite(i)?null:{ascentEm:o,descentEm:i}}function jp(e){try{let t=`\\displaystyle ${mo(e)||"\\square"}`,n=Cp(t,Np),r=typeof n.height=="number"?n.height:0,o=typeof n.depth=="number"?n.depth:0;return{ascentEm:r,descentEm:o,widthEm:yo(n,1)}}catch{return null}}function yo(e,t){let n=e.classes??[];if(n.includes("strut")||n.includes("pstrut"))return 0;if(n.includes("nulldelimiter"))return Gp*t;if(e.text!==void 0)return qp(e)*t;let r=t*Kp(n),o=e.children??[],a=n.includes("vlist")||n.includes("vlist-r")||n.includes("vlist-t")||n.includes("vlist-t2")?Math.max(0,...o.map(p=>yo(p,r))):o.reduce((p,m)=>p+yo(m,r),0),s=e.style??{},l=((ut(s.marginLeft)??0)+(ut(s.marginRight)??0)+(ut(s.paddingLeft)??0)+(ut(s.paddingRight)??0))*t,u=a+l,c=ut(s.width)??ut(s.minWidth);return c!==void 0&&(u=Math.max(u,c*t)),typeof e.width=="number"&&(u=Math.max(u,e.width*t)),u}function Kp(e){let t,n;for(let i of e){let a=_p.exec(i);a&&(t=Number(a[1]));let s=$p.exec(i);s&&(n=Number(s[1]))}if(t===void 0||n===void 0)return 1;let r=ys[t-1],o=ys[n-1];return r&&o?o/r:1}function ut(e){if(!e)return;let t=/^(-?[0-9.]+)em$/.exec(e.trim());if(!t)return;let n=Number.parseFloat(t[1]);return Number.isFinite(n)?n:void 0}function qp(e){let t=e.text??"",n=Array.from(t);if(n.length===0)return 0;if(n.length===1)return typeof e.width=="number"?e.width:In(n[0]);let r=n[0].codePointAt(0),o=typeof e.width=="number"&&r!==void 0?Zp(r,e.width):[];if(o.length===0)return n.reduce((a,s)=>a+In(s),0);let i=o.map(a=>n.reduce((s,l)=>s+Jp(l,a),0));return Math.max(...i)}function Zp(e,t){let n=[];for(let r of Object.keys(fo)){let o=fo[r][String(e)];o&&Math.abs(o[4]-t)<zp&&n.push(r)}return n}function Jp(e,t){let n=e.codePointAt(0);if(n===void 0)return 0;let r=fo[t][String(n)];return r?r[4]:In(e)}function In(e){return Qp(e)?Dp:xs}function Qp(e){let t=e.codePointAt(0)??0;return t>=4352&&t<=4607||t>=11904&&t<=42191||t>=44032&&t<=55215||t>=63744&&t<=64255||t>=65280&&t<=65519}function em(e){let t=e.replace(/\\(?:begin|end)\s*\{[^}]*\}/g,"").replace(/\\[a-zA-Z]+/g,"M").replace(/[{}^_\\]/g,""),n=0;for(let r of t)n+=In(r);return Math.max(n,xs)}function tm(){return{measureTexEm(e){return Cn(e)}}}function bs(){Ei(tm())}bs();import lf from"katex";import{useState as Ao,useRef as ft,useEffect as cf,useId as uf,useMemo as jn}from"react";var dt=[{label:"\u9ED2",value:"#0d0d0d"},{label:"\u30B0\u30EC\u30FC",value:"#6b7280"},{label:"\u8584\u30B0\u30EC\u30FC",value:"#9ca3af"},{label:"\u8D64",value:"#dc2626"},{label:"\u9752",value:"#2563eb"}];var nm=dt[0].value,rm=/^#[0-9a-f]{6}$/i,om=800,im=32,am=220,sm=32,lm=120,En=1e-12,cm="yOfX",um="solid",dm=2.4,Ss={min:"0",max:"2*pi"};function Ye(e){return Is(e.viewBox)}function Xe(e){return Is(e.graphViewBox??e.viewBox)}function xo(e,t=He){let n=Ye(e),r=Xe(e),o=wm(n,r);if(!o)return{x:t.left,y:t.top,width:0,height:0};let i=U(o.xMin,o.yMax,n,e,t),a=U(o.xMax,o.yMin,n,e,t);return{x:i.x,y:i.y,width:Math.max(0,a.x-i.x),height:Math.max(0,a.y-i.y)}}function ws(e,t,n={}){try{let r=oe(e),o=Ye(e),i=Xe(e),a=Ps(t.left,t.top+t.height,o,e,r),s=Ps(t.left+t.width,t.top,o,e,r),l={xMin:a.x,xMax:s.x,yMin:a.y,yMax:s.y};if(!Ms(l))return null;let u=e.graphViewBox!==void 0&&!km(o,i),c=u?{xMin:l.xMin+(o.xMin-i.xMin),xMax:l.xMax+(o.xMax-i.xMax),yMin:l.yMin+(o.yMin-i.yMin),yMax:l.yMax+(o.yMax-i.yMax)}:l;if(!Ms(c))return null;let p=oe(e),m={...e,width:n.resizeToCrop?Math.max(1,t.width+p.left+p.right):e.width,height:n.resizeToCrop?Math.max(1,t.height+p.top+p.bottom):e.height,viewBox:vs(c),curves:e.curves.map(g=>Tm(g,i,l))};return u?m.graphViewBox=vs(l):delete m.graphViewBox,m}catch{return null}}function We(e){return de(e,0)}function fe(e,t){if(e===void 0||e.trim()==="")return t;try{return We(e)}catch{return null}}function de(e,t,n="x"){return Fn(e,{[n]:t})}function pm(e,t,n){let r=Cm(e);return r?Fn(r.left,{x:t,y:n})-Fn(r.right,{x:t,y:n}):Fn(e,{x:t,y:n})}function Fn(e,t){let r=new ho(e,t).parse();if(!Number.isFinite(r))throw new Error("Expression produced a non-finite value");return r}function ks(e,t,n=He){try{let r=Ye(t),o=Xe(t),i=je(e.mode),a=t.width-n.left-n.right,s=t.height-n.top-n.bottom;if(a<=0||s<=0)return"";if(i==="implicit")return mm(e,t,r,o,n);let l=_n(e,i,o);if(!l)return"";let u=Es(e.samples??180,im,om),c=o.yMax-o.yMin,p=o.xMax-o.xMin,m=o.xMin-p*8,g=o.xMax+p*8,h=o.yMin-c*8,b=o.yMax+c*8,S=[],M=!1;for(let L=0;L<=u;L+=1){let w=l.min+(l.max-l.min)*L/u,B;try{if(i==="parametric"){let f=e.yExpr?.trim();if(!f){M=!1;continue}B={x:de(e.expr,w,"t"),y:de(f,w,"t")}}else{let f=de(e.expr,w,l.variableName);B=i==="xOfY"?{x:f,y:w}:{x:w,y:f}}}catch{M=!1;continue}if(!Number.isFinite(B.x)||!Number.isFinite(B.y)||B.x<m||B.x>g||B.y<h||B.y>b){M=!1;continue}let Y=U(B.x,B.y,r,t,n);S.push(`${M?"L":"M"}${mt(Y.x)} ${mt(Y.y)}`),M=!0}return S.join(" ")}catch{return""}}function mm(e,t,n,r,o){let i=_n(e,"implicit",r);if(!i)return"";let a=Es(e.samples??lm,sm,am),s=[];for(let u=0;u<=a;u+=1){let c=r.yMin+(r.yMax-r.yMin)*u/a,p=[];for(let m=0;m<=a;m+=1){let g=i.min+(i.max-i.min)*m/a;p.push({x:g,y:c,value:fm(e.expr,g,c)})}s.push(p)}let l=[];for(let u=0;u<a;u+=1)for(let c=0;c<a;c+=1){let p=s[u][c],m=s[u][c+1],g=s[u+1][c+1],h=s[u+1][c],b=ym([Ln(p,m),Ln(m,g),Ln(g,h),Ln(h,p)]);for(let S=0;S+1<b.length;S+=2){let M=U(b[S].x,b[S].y,n,t,o),L=U(b[S+1].x,b[S+1].y,n,t,o);Em(M,L)<=.001||l.push(`M${mt(M.x)} ${mt(M.y)} L${mt(L.x)} ${mt(L.y)}`)}}return l.join(" ")}function fm(e,t,n){try{return pm(e,t,n)}catch{return Number.NaN}}function Ln(e,t){if(!Number.isFinite(e.value)||!Number.isFinite(t.value))return null;let n=Math.abs(e.value)<=En,r=Math.abs(t.value)<=En;if(n&&r)return null;if(n)return{x:e.x,y:e.y};if(r)return{x:t.x,y:t.y};if(e.value>0==t.value>0)return null;let o=e.value/(e.value-t.value);if(!Number.isFinite(o)||o<-En||o>1+En)return null;let i=Math.min(1,Math.max(0,o));return{x:e.x+(t.x-e.x)*i,y:e.y+(t.y-e.y)*i}}function ym(e){let t=[];for(let n of e)n&&(t.some(r=>Math.abs(r.x-n.x)<1e-9&&Math.abs(r.y-n.y)<1e-9)||t.push(n));return t}function U(e,t,n,r,o=He){let i=r.width-o.left-o.right,a=r.height-o.top-o.bottom;return{x:o.left+(e-n.xMin)/(n.xMax-n.xMin)*i,y:o.top+(n.yMax-t)/(n.yMax-n.yMin)*a}}function Ps(e,t,n,r,o=He){let i=r.width-o.left-o.right,a=r.height-o.top-o.bottom,s=i<=0?1:i,l=a<=0?1:a;return{x:n.xMin+(e-o.left)/s*(n.xMax-n.xMin),y:n.yMax-(t-o.top)/l*(n.yMax-n.yMin)}}function Ts(e,t,n,r=12){let o=t-e;if(!Number.isFinite(o)||o<=0)return[];let i=fe(n,null);(i===null||i<=0||!Number.isFinite(i))&&(i=bm(o/Math.max(2,r-1)));let a=[],s=Math.ceil((e-1e-10)/i)*i,l=Math.min(r*5,80);for(let u=0;u<l;u+=1){let c=s+i*u;if(c>t+i*1e-6)break;c>=e-i*1e-6&&a.push(Rm(c))}return a}function bo(e,t="number",n){if(t==="pi")return Bm(e);let r=Am(n);return r!==null?Im(e,r):Mo(e)}function $t(e,t=nm){return e&&rm.test(e)?e:t}function je(e){return e==="xOfY"||e==="parametric"||e==="implicit"?e:cm}function gm(e){return e==="dashed"||e==="dotted"?e:um}function So(e){return!Number.isFinite(e)||e===void 0||e<.5||e>8?dm:e}function hm(e){let t=je(e.mode);if(t==="parametric"){let r=Pm(e);return As(r.xExpr,r.yExpr)}let n=e.label?.trim();return n||xm(t,e.expr)}function xm(e,t,n){let r=je(e);return r==="parametric"?As(t,n??""):r==="implicit"?t.includes("=")?t:`${t} = 0`:`${Sm(r)}${t}`}function Bs(e){let t=gm(e.dash);if(t==="solid")return;let n=So(e.strokeWidth);return t==="dashed"?`${go(n*3)} ${go(n*2)}`:`0 ${go(n*2.2)}`}var fM=[{color:dt[0].value,dash:"solid"},{color:dt[0].value,dash:"dashed"},{color:dt[1].value,dash:"solid"},{color:dt[0].value,dash:"dotted"},{color:dt[1].value,dash:"dashed"}];function Po(e){let t=fe(e.x,null),n=fe(e.y,null);return t===null||n===null?null:{x:t,y:n}}function Rs(e){let t=e.showFormulaLabels===!1?[]:e.curves.map(r=>hm(r)),n=(e.points??[]).map(r=>r.label).filter(Boolean);return[e.title,...t,...n].filter(Boolean).join(" ")}function bm(e){if(!Number.isFinite(e)||e<=0)return 1;let n=10**Math.floor(Math.log10(e)),r=e/n;return r<=1?n:r<=2?2*n:r<=5?5*n:10*n}function Sm(e){return e==="xOfY"?"x = ":"y = "}function As(e,t){return`\\begin{cases} x = ${e} \\\\ y = ${t} \\end{cases}`}function Pm(e){return Mm(e.label?.trim()??"")??{xExpr:e.expr,yExpr:e.yExpr??""}}function Mm(e){if(!e)return null;let t=e.match(/^\\begin\{cases\}\s*x\s*=\s*(.*?)\s*\\\\\s*y\s*=\s*(.*?)\s*\\end\{cases\}$/);if(t)return{xExpr:t[1].trim(),yExpr:t[2].trim()};let n=e.match(/^x\s*=\s*(.*?)\s*,\s*y\s*=\s*(.*?)$/);return n?{xExpr:n[1].trim(),yExpr:n[2].trim()}:null}function vm(e){return e==="parametric"?"t":e==="xOfY"?"y":"x"}function Om(e,t){return e==="xOfY"?{min:t.yMin,max:t.yMax}:e==="parametric"?{min:We(Ss.min),max:We(Ss.max)}:{min:t.xMin,max:t.xMax}}function _n(e,t,n){let r=vm(t),o=Om(t,n),i=fe(e.domain?.min,o.min),a=fe(e.domain?.max,o.max);if(i===null||a===null)return null;let s=t==="parametric"?i:Math.max(o.min,i),l=t==="parametric"?a:Math.min(o.max,a);return s>=l?null:{min:s,max:l,variableName:r}}function Is(e){let t=We(e.xMin),n=We(e.xMax),r=We(e.yMin),o=We(e.yMax);if(t>=n)throw new Error("xMin must be smaller than xMax");if(r>=o)throw new Error("yMin must be smaller than yMax");return{xMin:t,xMax:n,yMin:r,yMax:o}}function wm(e,t){let n=Math.max(e.xMin,t.xMin),r=Math.min(e.xMax,t.xMax),o=Math.max(e.yMin,t.yMin),i=Math.min(e.yMax,t.yMax);return n>=r||o>=i?null:{xMin:n,xMax:r,yMin:o,yMax:i}}function Ms(e){return Number.isFinite(e.xMin)&&Number.isFinite(e.xMax)&&Number.isFinite(e.yMin)&&Number.isFinite(e.yMax)&&e.xMin<e.xMax&&e.yMin<e.yMax}function km(e,t){return Nn(e.xMin,t.xMin)&&Nn(e.xMax,t.xMax)&&Nn(e.yMin,t.yMin)&&Nn(e.yMax,t.yMax)}function Nn(e,t){return Math.abs(e-t)<1e-9}function vs(e){return{xMin:pt(e.xMin),xMax:pt(e.xMax),yMin:pt(e.yMin),yMax:pt(e.yMax)}}function Tm(e,t,n){if(!e.domain)return e;let r=je(e.mode);if(r==="parametric")return e;let o=r==="xOfY"?t.yMin:t.xMin,i=r==="xOfY"?t.yMax:t.xMax,a=r==="xOfY"?n.yMin:n.xMin,s=r==="xOfY"?n.yMax:n.xMax,l=Os(e.domain.min,o,a),u=Os(e.domain.max,i,s);if(l===e.domain.min&&u===e.domain.max)return e;let c={...e.domain??{},...l===void 0?{}:{min:l},...u===void 0?{}:{max:u}};return{...e,domain:c}}function Os(e,t,n){if(e===void 0||e.trim()==="")return e;let r=fe(e,null);return r===null?e:pt(n+(r-t))}function pt(e){return Math.abs(e)<1e-10?"0":Number(e.toFixed(4)).toString()}function Mo(e){return Math.abs(e)<1e-9?"0":Number.isInteger(e)?String(e):Number(e.toFixed(3)).toString()}function Bm(e){if(Math.abs(e)<1e-9)return"0";let t=Math.PI/2,n=Math.round(e/t);if(Math.abs(e-n*t)>1e-5)return Mo(e);let r=n<0?"-":"",o=Math.abs(n);if(o===1)return`${r}\\dfrac{\\pi}{2}`;if(o===2)return`${r}\\pi`;if(o%2===0){let i=o/2;return`${r}${i}\\pi`}return`${r}\\dfrac{${o}\\pi}{2}`}function Rm(e){return Math.abs(e)<1e-10?0:Number(e.toFixed(10))}function Am(e){if(!e)return null;let t=e.trim().match(/^-?(\d+)\s*\/\s*(\d+)$/);if(!t)return null;let n=Number.parseInt(t[1],10),r=Number.parseInt(t[2],10);if(!Number.isFinite(n)||!Number.isFinite(r)||r<=1||n===0)return null;let o=Cs(n,r),i=r/o;return i>1?i:null}function Im(e,t){if(Math.abs(e)<1e-9)return"0";let n=e*t,r=Math.round(n);if(Math.abs(n-r)>1e-6)return Mo(e);let o=r<0?"-":"",i=Math.abs(r),a=Cs(i,t),s=i/a,l=t/a;return l===1?`${o}${s}`:`${o}\\dfrac{${s}}{${l}}`}function Cs(e,t){let n=Math.abs(Math.round(e)),r=Math.abs(Math.round(t));for(;r>0;){let o=n%r;n=r,r=o}return n||1}function mt(e){return Number(e.toFixed(3))}function go(e){return Number(e.toFixed(2))}function Cm(e){let t=e.split("=");if(t.length!==2)return null;let n=t[0].trim(),r=t[1].trim();return n&&r?{left:n,right:r}:null}function Em(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function Es(e,t,n){return Number.isFinite(e)?Math.min(n,Math.max(t,Math.round(e))):t}var ho=class{constructor(t,n){this.input=t;this.variables=n;this.index=0}parse(){let t=this.parseAdditive();if(this.skipWhitespace(),this.index!==this.input.length)throw new Error(`Unexpected token at ${this.index}`);return t}parseAdditive(){let t=this.parseMultiplicative();for(;;)if(this.skipWhitespace(),this.consume("+"))t+=this.parseMultiplicative();else if(this.consume("-"))t-=this.parseMultiplicative();else return t}parseMultiplicative(){let t=this.parsePower();for(;;)if(this.skipWhitespace(),this.consume("*"))t*=this.parsePower();else if(this.consume("/"))t/=this.parsePower();else if(this.startsImplicitFactor())t*=this.parsePower();else return t}parsePower(){let t=this.parseUnary();return this.skipWhitespace(),this.consume("^")&&(t=t**this.parsePower()),t}parseUnary(){return this.skipWhitespace(),this.consume("+")?this.parseUnary():this.consume("-")?-this.parseUnary():this.parsePrimary()}parsePrimary(){if(this.skipWhitespace(),this.consume("(")){let r=this.parseAdditive();if(this.skipWhitespace(),!this.consume(")"))throw new Error("Expected closing parenthesis");return r}let t=this.parseNumber();if(t!==null)return t;let n=this.parseIdentifier();if(n)return this.resolveIdentifier(n);throw new Error(`Expected value at ${this.index}`)}resolveIdentifier(t){let n=t.toLowerCase();if(this.skipWhitespace(),this.consume("(")){let o=this.parseAdditive();if(this.skipWhitespace(),!this.consume(")"))throw new Error("Expected closing parenthesis");return Lm(n,o)}let r=this.variables[n];if(r!==void 0)return r;if(n==="pi")return Math.PI;if(n==="e")return Math.E;throw new Error(`Unknown identifier ${t}`)}parseNumber(){let t=/^(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/i.exec(this.input.slice(this.index));return t?(this.index+=t[0].length,Number(t[0])):null}parseIdentifier(){let t=/^[a-zA-Z_][a-zA-Z0-9_]*/.exec(this.input.slice(this.index));return t?(this.index+=t[0].length,t[0]):null}consume(t){return this.input.startsWith(t,this.index)?(this.index+=t.length,!0):!1}skipWhitespace(){for(;/\s/.test(this.input[this.index]??"");)this.index+=1}startsImplicitFactor(){this.skipWhitespace();let t=this.input[this.index]??"";return t==="("||t==="."||/\d|[a-zA-Z_]/.test(t)}};function Lm(e,t){switch(e){case"abs":return Math.abs(t);case"acos":return Math.acos(t);case"asin":return Math.asin(t);case"atan":return Math.atan(t);case"cos":return Math.cos(t);case"exp":return Math.exp(t);case"ln":case"log":return Math.log(t);case"sin":return Math.sin(t);case"sqrt":return Math.sqrt(t);case"tan":return Math.tan(t);default:throw new Error(`Unknown function ${e}`)}}var ko=32,Hn=360,To=220,Ke=1e3,j=1e-6,Nm=.08,Wn=2,Fm=.08,_m=.35,vo=2.4,Gt=1e-5,$m=1/Ke;function zs(e,t,n=oe(e)){let r=Jm(t);return r?Gm(e,r,n)?.path??"":""}function Gm(e,t,n=oe(e)){if(e.kind!=="cartesian")return null;let r,o;try{r=Ye(e),o=Xe(e)}catch{return null}let i=ef(r,o);if(!i||!Qm(i,t))return null;let a=U(t.x,t.y,r,e,n),s=Dm(e,r,i,n);if(s.length<4)return null;let l=Xm(s),u=Km(l),c=Hm(e,t,r,i,n),p=Fs(a,s,_m);if(p.length>0)return p.length>1||p.some(b=>b.kind!=="axis"&&Vs(a,b)<=Fm)?null:Dn([Ns(a,u,vo),c]);let m=Dn([Oo(a,u),c]);return m||(Fs(a,s,vo).filter(h=>h.kind==="axis").length===1?Dn([Ns(a,u,vo*2),c]):null)}function Dm(e,t,n,r){let o=U(n.xMin,n.yMax,t,e,r),i=U(n.xMax,n.yMax,t,e,r),a=U(n.xMax,n.yMin,t,e,r),s=U(n.xMin,n.yMin,t,e,r),l=[{a:o,b:i,kind:"frame"},{a:i,b:a,kind:"frame"},{a,b:s,kind:"frame"},{a:s,b:o,kind:"frame"}];e.axes.showX!==!1&&n.yMin<0&&n.yMax>0&&l.push({a:U(n.xMin,0,t,e,r),b:U(n.xMax,0,t,e,r),kind:"axis"}),e.axes.showY!==!1&&n.xMin<0&&n.xMax>0&&l.push({a:U(0,n.yMin,t,e,r),b:U(0,n.yMax,t,e,r),kind:"axis"});for(let u of e.curves)l.push(...zm(u,e,t,n,r));return l}function zm(e,t,n,r,o){let i=je(e.mode);if(i==="implicit")return[];let a=_n(e,i,r);if(!a)return[];let s=Un(e.samples??To,ko,Hn),l=r.xMax-r.xMin,u=r.yMax-r.yMin,c=r.xMin-l*8,p=r.xMax+l*8,m=r.yMin-u*8,g=r.yMax+u*8,h=[],b=null;for(let S=0;S<=s;S+=1){let M=a.min+(a.max-a.min)*S/s,L;try{if(i==="parametric"){let w=e.yExpr?.trim();if(!w){b=null;continue}L={x:de(e.expr,M,"t"),y:de(w,M,"t")}}else{let w=de(e.expr,M,a.variableName);L=i==="xOfY"?{x:w,y:M}:{x:M,y:w}}}catch{b=null;continue}if(!Number.isFinite(L.x)||!Number.isFinite(L.y)||L.x<c||L.x>p||L.y<m||L.y>g){b=null;continue}if(b){let w=Ym(b,L,r);w&&h.push({a:U(w.a.x,w.a.y,n,t,o),b:U(w.b.x,w.b.y,n,t,o),kind:"curve"})}b=L}return h}function Hm(e,t,n,r,o){let i=[];for(let a of e.curves){let s=je(a.mode);if(s==="parametric"||s==="implicit")continue;if(s==="xOfY"){let u=[r.xMin,r.xMax];e.axes.showY!==!1&&r.xMin<0&&r.xMax>0&&u.push(0);for(let c of u){let p=Ls(a,s,c,t,n,r,e,o);p&&i.push(p)}continue}let l=[r.yMin,r.yMax];e.axes.showX!==!1&&r.yMin<0&&r.yMax>0&&l.push(0);for(let u of l){let c=Ls(a,s,u,t,n,r,e,o);c&&i.push(c)}}return Dn(i)}function Ls(e,t,n,r,o,i,a,s){let l=Wm(e,t,i);if(!l)return null;let u=t==="xOfY"?r.y:r.x;if(u<=l.min+j||u>=l.max-j)return null;let c;try{c=de(e.expr,u,l.variableName)}catch{return null}if(!Number.isFinite(c)||t==="xOfY"&&(c<i.xMin-j||c>i.xMax+j)||t==="yOfX"&&(c<i.yMin-j||c>i.yMax+j)||!af(t==="xOfY"?r.x:r.y,n,c))return null;let p=Vm(e,t,n,l,u);for(let m=0;m<p.length-1;m+=1){let g=p[m],h=p[m+1];if(u<=g+Gt||u>=h-Gt)continue;let b=Um(e,t,n,g,h,l,o,i,a,s);if(b.length<3)continue;let S=Math.abs(Ws(b)),M=U(r.x,r.y,o,a,s);if(S>Wn&&Hs(M,b))return{polygon:b,area:S,path:Us(b)}}return null}function Vm(e,t,n,r,o){let i=Un(e.samples??To,ko,Hn),a=Gs([r.min,r.max,o,...Array.from({length:i+1},(u,c)=>r.min+(r.max-r.min)*c/i)]),s=[],l=null;for(let u of a){let c;try{c=de(e.expr,u,r.variableName)}catch{l=null;continue}if(!Number.isFinite(c)){l=null;continue}let p=c-n;if(Math.abs(p)<=j&&s.push(u),l&&l.delta*p<0){let m=l.delta/(l.delta-p);s.push(l.independent+(u-l.independent)*m)}l={independent:u,delta:p}}return Gs(s).filter(u=>u>=r.min-Gt&&u<=r.max+Gt)}function Um(e,t,n,r,o,i,a,s,l,u){let c=Un(e.samples??To,ko,Hn),p=(o-r)/Math.max(i.max-i.min,j),m=Un(Math.ceil(c*p),8,Hn),g=[];t==="xOfY"?g.push({x:n,y:r},{x:n,y:o}):g.push({x:r,y:n},{x:o,y:n});for(let h=m;h>=0;h-=1){let b=r+(o-r)*h/m,S;try{S=de(e.expr,b,i.variableName)}catch{continue}if(!Number.isFinite(S))continue;let M=t==="xOfY"?{x:Ds(S,s.xMin,s.xMax),y:b}:{x:b,y:Ds(S,s.yMin,s.yMax)};(h===m||h===0)&&(t==="xOfY"?M.x=n:M.y=n),g.push(M)}return g.map(h=>U(h.x,h.y,a,l,u))}function Wm(e,t,n){let r=t==="xOfY"?"y":"x",o=t==="xOfY"?{min:n.yMin,max:n.yMax}:{min:n.xMin,max:n.xMax},i=fe(e.domain?.min,o.min)??o.min,a=fe(e.domain?.max,o.max)??o.max,s=Math.max(o.min,i),l=Math.min(o.max,a);return s>=l?null:{min:s,max:l,variableName:r}}function Ym(e,t,n){let r=0,o=1,i=t.x-e.x,a=t.y-e.y,s=(l,u)=>{if(Math.abs(l)<j)return u>=-j;let c=u/l;if(l<0){if(c>o)return!1;c>r&&(r=c)}else{if(c<r)return!1;c<o&&(o=c)}return!0};return!s(-i,e.x-n.xMin)||!s(i,n.xMax-e.x)||!s(-a,e.y-n.yMin)||!s(a,n.yMax-e.y)||o-r<=j?null:{a:{x:e.x+i*r,y:e.y+a*r},b:{x:e.x+i*o,y:e.y+a*o}}}function Xm(e){let t=e.map(()=>[{t:0},{t:1}]);for(let s=0;s<e.length;s+=1)for(let l=s+1;l<e.length;l+=1){let u=e[s],c=e[l],p=Zm(u,c);p&&(t[s].push({t:p.t,point:p.point}),t[l].push({t:p.u,point:p.point})),jm(u,c,t[s],t[l])}let n=new Map,r=new Map,o=new Set,i=s=>{let l=rf(s),u=of(l),c=n.get(u);if(c)return c;let p={key:u,point:l};return n.set(u,p),r.set(u,[]),p},a=(s,l)=>{if(s.key===l.key||wo(s.point,l.point)<Nm)return;let u=s.key<l.key?`${s.key}|${l.key}`:`${l.key}|${s.key}`;o.has(u)||(o.add(u),r.get(s.key)?.push({key:l.key,angle:Math.atan2(l.point.y-s.point.y,l.point.x-s.point.x)}),r.get(l.key)?.push({key:s.key,angle:Math.atan2(s.point.y-l.point.y,s.point.x-l.point.x)}))};e.forEach((s,l)=>{let u=tf(t[l]);for(let c=0;c<u.length-1;c+=1){let p=_s(s,u[c]),m=_s(s,u[c+1]);a(i(p),i(m))}});for(let s of r.values())s.sort((l,u)=>l.angle-u.angle);return{vertices:n,adjacency:r,edgeCount:o.size}}function jm(e,t,n,r){let o=$n(e.a,t),i=$n(e.b,t),a=$n(t.a,e),s=$n(t.b,e);o!==null&&r.push({t:o,point:e.a}),i!==null&&r.push({t:i,point:e.b}),a!==null&&n.push({t:a,point:t.a}),s!==null&&n.push({t:s,point:t.b})}function Km(e){let t=[],n=new Set,r=e.edgeCount*2+8;for(let[o,i]of e.adjacency)for(let a of i){let s=o,l=a.key,u=$s(s,l);if(n.has(u))continue;let c=[],p=s,m=l,g=!1;for(let h=0;h<r;h+=1){let b=$s(p,m);if(n.has(b))break;n.add(b),c.push(p);let S=e.adjacency.get(m);if(!S||S.length===0)break;let M=S.findIndex(B=>B.key===p);if(M===-1)break;let L=(M-1+S.length)%S.length,w=S[L].key;if(p=m,m=w,p===s&&m===l){g=!0;break}}if(!(!g||c.length<3))for(let h of qm(c)){let b=h.map(M=>e.vertices.get(M)?.point).filter(M=>!!M),S=Math.abs(Ws(b));S<=Wn||t.push({polygon:b,area:S,path:Us(b)})}}return t}function qm(e){let t=[],n=new Map,r=[];for(let o of e){let i=n.get(o);if(i===void 0){n.set(o,t.length),t.push(o);continue}let a=t.slice(i);a.length>=3&&r.push(a);let s=t.splice(i+1);for(let l of s)n.delete(l)}return r.length===0&&t.length>=3&&r.push(t),r}function Oo(e,t){return t.filter(r=>r.area>Wn&&Hs(e,r.polygon)).sort((r,o)=>r.area-o.area)[0]??null}function Ns(e,t,n){let r=Oo(e,t),o=[e,{x:e.x+n,y:e.y},{x:e.x-n,y:e.y},{x:e.x,y:e.y+n},{x:e.x,y:e.y-n},{x:e.x+n,y:e.y+n},{x:e.x+n,y:e.y-n},{x:e.x-n,y:e.y+n},{x:e.x-n,y:e.y-n}],i=new Map;r&&i.set(r.path,r);for(let a of o){let s=Oo(a,t);s&&i.set(s.path,s)}return[...i.values()].sort((a,s)=>a.area-s.area)[0]??null}function Dn(e){return e.filter(t=>t!=null&&t.area>Wn).sort((t,n)=>t.area-n.area)[0]??null}function Fs(e,t,n){return t.filter(r=>Vs(e,r)<=n)}function Zm(e,t){let n=e.b.x-e.a.x,r=e.b.y-e.a.y,o=t.b.x-t.a.x,i=t.b.y-t.a.y,a=zn({x:n,y:r},{x:o,y:i});if(Math.abs(a)<j)return null;let s=t.a.x-e.a.x,l=t.a.y-e.a.y,u=zn({x:s,y:l},{x:o,y:i})/a,c=zn({x:s,y:l},{x:n,y:r})/a;return!Vn(u)||!Vn(c)?null:{point:{x:e.a.x+n*u,y:e.a.y+r*u},t:u,u:c}}function $n(e,t){let n=t.b.x-t.a.x,r=t.b.y-t.a.y,o=n*n+r*r;if(o<j)return null;let i=zn({x:n,y:r},{x:e.x-t.a.x,y:e.y-t.a.y});if(Math.abs(i)/Math.sqrt(o)>$m)return null;let a=((e.x-t.a.x)*n+(e.y-t.a.y)*r)/o;return Vn(a)?a:null}function Hs(e,t){let n=!1;for(let r=0,o=t.length-1;r<t.length;o=r,r+=1){let i=t[r],a=t[o];if(!(i.y>e.y!=a.y>e.y))continue;let l=(a.x-i.x)*(e.y-i.y)/(a.y-i.y)+i.x;e.x<l&&(n=!n)}return n}function Vs(e,t){let n=t.b.x-t.a.x,r=t.b.y-t.a.y,o=n*n+r*r;if(o<=j)return wo(e,t.a);let i=Math.max(0,Math.min(1,((e.x-t.a.x)*n+(e.y-t.a.y)*r)/o));return wo(e,{x:t.a.x+n*i,y:t.a.y+r*i})}function Jm(e){let t=fe(e.x,null),n=fe(e.y,null);return t===null||n===null?null:{x:t,y:n}}function Qm(e,t){return t.x>e.xMin+j&&t.x<e.xMax-j&&t.y>e.yMin+j&&t.y<e.yMax-j}function ef(e,t){let n=Math.max(e.xMin,t.xMin),r=Math.min(e.xMax,t.xMax),o=Math.max(e.yMin,t.yMin),i=Math.min(e.yMax,t.yMax);return n<r&&o<i?{xMin:n,xMax:r,yMin:o,yMax:i}:null}function tf(e){let t=e.filter(r=>Vn(r.t)).map(r=>({...r,t:Math.min(1,Math.max(0,r.t))})).sort((r,o)=>r.t-o.t),n=[];for(let r of t){let o=n[n.length-1];!o||Math.abs(r.t-o.t)>j?n.push(r):!o.point&&r.point&&(o.point=r.point)}return n}function Vn(e){return Number.isFinite(e)&&e>=-j&&e<=1+j}function nf(e,t,n){return{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}}function _s(e,t){return t.point??nf(e.a,e.b,t.t)}function rf(e){return{x:Math.round(e.x*Ke)/Ke,y:Math.round(e.y*Ke)/Ke}}function of(e){return`${Math.round(e.x*Ke)}:${Math.round(e.y*Ke)}`}function $s(e,t){return`${e}->${t}`}function Us(e){let[t,...n]=e;return[`M${Gn(t.x)} ${Gn(t.y)}`,...n.map(r=>`L${Gn(r.x)} ${Gn(r.y)}`),"Z"].join(" ")}function Ws(e){let t=0;for(let n=0;n<e.length;n+=1){let r=e[n],o=e[(n+1)%e.length];t+=r.x*o.y-o.x*r.y}return t/2}function zn(e,t){return e.x*t.y-e.y*t.x}function wo(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function af(e,t,n){return e>Math.min(t,n)+j&&e<Math.max(t,n)-j}function Gs(e){let t=e.filter(r=>Number.isFinite(r)).sort((r,o)=>r-o),n=[];for(let r of t){let o=n[n.length-1];(o===void 0||Math.abs(r-o)>Gt)&&n.push(r)}return n}function Ds(e,t,n){return Math.max(t,Math.min(n,e))}function Gn(e){return Number(e.toFixed(3))}function Un(e,t,n){return Number.isFinite(e)?Math.round(Math.max(t,Math.min(n,e))):t}function Ys(){return null}function Yn(e){let t=Ys();t&&(t.counters[e]=(t.counters[e]??0)+1)}function Bo(e,t){return t();try{return t()}finally{let r=performance.now()-n,o=Ys();o&&(o.measures.push({name:e,duration:r,at:Date.now()}),o.measures.length>2e3&&o.measures.splice(0,o.measures.length-2e3))}}var Xn="pt",Xs=1.3333333333333333;function js(e){return sf(e/Xs)}function Ro(e){return e*Xs}function sf(e){return Math.round(e*1e3)/1e3}import{Fragment as Ef,jsx as E,jsxs as pe}from"react/jsx-runtime";var df=300,Ks=9,pf=new Map,mf=new Map,ff=new Map;function yf(e){return lf.renderToString(e||"\\square",{throwOnError:!1,strict:"ignore",output:"html"})}var gf={"\\pi":"\u03C0","\\theta":"\u03B8","\\alpha":"\u03B1","\\beta":"\u03B2","\\gamma":"\u03B3","\\delta":"\u03B4","\\epsilon":"\u03B5","\\varepsilon":"\u03B5","\\lambda":"\u03BB","\\mu":"\u03BC","\\sigma":"\u03C3","\\phi":"\u03C6","\\varphi":"\u03C6","\\omega":"\u03C9","\\sin":"sin","\\cos":"cos","\\tan":"tan","\\log":"log","\\ln":"ln","\\exp":"exp","\\sqrt":"\u221A","\\cdot":"\xB7","\\times":"\xD7","\\div":"\xF7","\\pm":"\xB1","\\mp":"\u2213","\\infty":"\u221E","\\leq":"\u2264","\\leqq":"\u2264","\\geq":"\u2265","\\geqq":"\u2265","\\neq":"\u2260","\\approx":"\u2248","\\to":"\u2192"};function hf(e){if(!e)return"";let t=e;for(let n=0;n<4;n+=1){let r=t.replace(/\\d?frac\s*\{([^{}]*)\}\s*\{([^{}]*)\}/g,"$1/$2");if(r===t)break;t=r}for(let[n,r]of Object.entries(gf))t.includes(n)&&(t=t.split(n).join(r));return t=t.replace(/\\([a-zA-Z]+)/g,"$1"),t=t.replace(/[{}]/g,""),t=t.replace(/-/g,"\u2212"),t}function qs(e,t){return t==="start"?0:t==="end"?e:e/2}function Zs(e){return e==="start"?"flex-start":e==="end"?"flex-end":"center"}function xf(e){return e==="start"?"start":e==="end"?"end":"middle"}function bf(e){return e==="start"?"hanging":e==="end"?"alphabetic":"middle"}var Sf=12,Pf=12;function Js(e,t){let n=Cn(e||"\\square"),r=Ro(t);return{width:Math.max(Sf,Math.ceil(n.widthEm*r)),height:Math.max(Pf,Math.ceil((n.ascentEm+n.descentEm)*r))}}function Qs({cx:e,cy:t,width:n,height:r,align:o,vAlign:i,tex:a,className:s,fontSize:l,staticMode:u}){if(u)return E("text",{x:e,y:t,textAnchor:xf(o),dominantBaseline:bf(i),className:s,style:l!==void 0?{fontSize:`${l}pt`}:void 0,children:hf(a)});let c=e-qs(n,o),p=t-qs(r,i);return E("foreignObject",{x:c,y:p,width:n,height:r,className:s,children:E("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{width:"100%",height:"100%",display:"flex",justifyContent:Zs(o),alignItems:Zs(i),fontSize:l!==void 0?`${l}pt`:void 0,lineHeight:1,pointerEvents:"none",overflow:"visible"},dangerouslySetInnerHTML:{__html:yf(a)}})})}function Io({spec:e,className:t="",idSeed:n,staticMode:r,onSpecChange:o,autoStartCrop:i,disableCropInteraction:a,onCropEnd:s}){Yn("Graph2DPreview.render");let[l,u]=Ao(!1),[c,p]=Ao(null),[m,g]=Ao(null),h=ft(null),b=ft(null),S=ft(null),M=ft(null),L=ft(null),w=ft(!1),B=Kn(uf()),Y=n?Kn(n):B,f=l&&m?m:e,P=jn(()=>oe(f),[f.kind,f.axes.renderStyle]),Q=jn(()=>Kn([Y,f.title,f.kind,f.width,f.height,f.viewBox.xMin,f.viewBox.xMax,f.viewBox.yMin,f.viewBox.yMax,f.graphViewBox?.xMin??"",f.graphViewBox?.xMax??"",f.graphViewBox?.yMin??"",f.graphViewBox?.yMax??""].join("-")),[Y,f.title,f.kind,f.width,f.height,f.viewBox,f.graphViewBox]),te=jn(()=>Bo("Graph2DPreview.curvePaths",()=>f.curves.map(y=>({curve:y,path:vf(y,f,P)}))),[f.curves,f.viewBox,f.graphViewBox,f.width,f.height,P]),K=jn(()=>Bo("Graph2DPreview.fillPaths",()=>(f.fills??[]).map(y=>({fill:y,path:Of(f,y,P),color:$t(y.color,Kr),opacity:Zr(y.opacity),pattern:qr(y.pattern),patternId:`graph2d-fill-pattern-${Q}-${Kn(y.id)}`})).filter(y=>y.path)),[f.fills,f.curves,f.viewBox,f.graphViewBox,f.width,f.height,f.kind,P,Q]),x=Mf(f),I=kf(f),O=Rs(f)||"\u30B0\u30E9\u30D5",T=y=>{let v=oe(y);try{let G=xo(y,v);if(G.width>0&&G.height>0)return{left:G.x,top:G.y,width:G.width,height:G.height}}catch{}return{left:v.left,top:v.top,width:y.width-v.left-v.right,height:y.height-v.top-v.bottom}},C=y=>{let v=T(y);w.current=!1,b.current=v,S.current=y,p(v),g(y),u(!0)},R=()=>{let y=b.current??c;y&&V(y),b.current=null,S.current=null,u(!1),p(null),g(null),s?.()},$=y=>{r||a||!o||(y.preventDefault(),y.stopPropagation(),l?R():C(e))},N=(y,v={})=>{let G=S.current??m;if(!o||!G)return;let q=ws(G,y,v);q&&o(q,{source:"crop",cropBox:y,resizeToCrop:v.resizeToCrop===!0})},V=y=>{w.current||(w.current=!0,N(y,{resizeToCrop:!0}))};cf(()=>{if(i&&!l&&o&&!r){let y=T(e);w.current=!1,b.current=y,S.current=e,p(y),g(e),u(!0)}else if(!i&&l){let y=b.current??c;y&&V(y),b.current=null,S.current=null,u(!1),p(null),g(null)}},[i]);let D=(y,v)=>{!l||!c||(y.preventDefault(),y.stopPropagation(),y.target.setPointerCapture(y.pointerId),h.current={x:y.clientX,y:y.clientY,box:{...c},handle:v})},X=y=>{if(!l||!c||!h.current)return;y.preventDefault(),y.stopPropagation();let v=h.current;if(!M.current)return;let G=M.current.getBoundingClientRect();if(G.width<=0||G.height<=0)return;let q=f.width/G.width,ae=f.height/G.height,Pe=(y.clientX-v.x)*q,Ir=(y.clientY-v.y)*ae,Mi=P.left,vi=f.width-P.right,Oi=P.top,wi=f.height-P.bottom,se={...v.box},tn=30;if(v.handle==="center")se.left=Math.max(Mi,Math.min(vi-se.width,v.box.left+Pe)),se.top=Math.max(Oi,Math.min(wi-se.height,v.box.top+Ir));else{if(v.handle.includes("l")){let ze=v.box.left+Pe,Bt=Math.max(Mi,Math.min(v.box.left+v.box.width-tn,ze));se.width=v.box.left+v.box.width-Bt,se.left=Bt}if(v.handle.includes("r")){let ze=v.box.width+Pe;se.width=Math.max(tn,Math.min(vi-v.box.left,ze))}if(v.handle.includes("t")){let ze=v.box.top+Ir,Bt=Math.max(Oi,Math.min(v.box.top+v.box.height-tn,ze));se.height=v.box.top+v.box.height-Bt,se.top=Bt}if(v.handle.includes("b")){let ze=v.box.height+Ir;se.height=Math.max(tn,Math.min(wi-v.box.top,ze))}}b.current=se,p(se),N(se)},z=y=>{!l||!h.current||(y.preventDefault(),y.stopPropagation(),y.target.releasePointerCapture(y.pointerId),h.current=null)};if(!x||!I)return E("div",{className:`graph2d-container ${t}`,style:{position:"relative"},children:pe("svg",{className:"graph2d-svg","data-testid":"graph2d-svg",role:"img","aria-label":`${O} \u7BC4\u56F2\u30A8\u30E9\u30FC`,viewBox:`0 0 ${f.width} ${f.height}`,children:[E("rect",{width:f.width,height:f.height,rx:"6",className:"graph2d-error-bg"}),E("text",{x:f.width/2,y:f.height/2,textAnchor:"middle",className:"graph2d-error-text",children:"\u30B0\u30E9\u30D5\u3092\u63CF\u753B\u3067\u304D\u307E\u305B\u3093"})]})});let W=Tf(x,I),ce=W?el(W.xMin,W.xMax,f.axes.xTickStep,f.kind==="numberLine"?8:12):[],Z=W&&f.kind!=="numberLine"?el(W.yMin,W.yMax,f.axes.yTickStep,9):[],ne=f.axes.showX!==!1,De=f.kind==="cartesian"&&f.axes.showY!==!1,me=f.axes.showTicks!==!1,wr=W!==null&&W.yMin<=0&&W.yMax>=0,Wc=W!==null&&W.xMin<=0&&W.xMax>=0,kr=ne&&wr,Tr=De&&Wc,en=Bf(x,f,P),wt=De?Rf(x,f,P):null,Br=`axis-arrow-${Q}`,kt=f.axes.axisColor??(f.axes.renderStyle==="studyaid"?"#0d0d0d":void 0),Rr=f.axes.axisStrokeWidth??(f.axes.renderStyle==="studyaid"?.85:void 0),Ar=wf(f.axes.axisDash??(f.axes.renderStyle==="studyaid"?"dashed":void 0)),bi=kt||Rr!==void 0||Ar?{...kt?{stroke:kt}:{},...Rr!==void 0?{strokeWidth:Rr}:{},...Ar?{strokeDasharray:Ar}:{}}:void 0,Yc=`graph2d-plot-clip-${Q}`,Tt=`graph2d-graph-clip-${Q}`,Si=Math.max(0,f.width-P.left-P.right),Pi=Math.max(0,f.height-P.top-P.bottom),re=xo(f,P),Xc=te.some(y=>y.path),jc=c?[{name:"tl",x:c.left,y:c.top,cursor:"nwse-resize"},{name:"tr",x:c.left+c.width,y:c.top,cursor:"nesw-resize"},{name:"bl",x:c.left,y:c.top+c.height,cursor:"nesw-resize"},{name:"br",x:c.left+c.width,y:c.top+c.height,cursor:"nwse-resize"},{name:"t",x:c.left+c.width/2,y:c.top,cursor:"ns-resize"},{name:"b",x:c.left+c.width/2,y:c.top+c.height,cursor:"ns-resize"},{name:"l",x:c.left,y:c.top+c.height/2,cursor:"ew-resize"},{name:"r",x:c.left+c.width,y:c.top+c.height/2,cursor:"ew-resize"}]:[];return E("div",{ref:L,className:`graph2d-container ${t} ${l?"cropping":""}`,style:{position:"relative",width:"100%",height:"100%"},onDoubleClick:$,onPointerDown:y=>{l&&(y.stopPropagation(),R())},children:pe("svg",{ref:M,className:"graph2d-svg","data-testid":"graph2d-svg",role:"img","aria-label":O,viewBox:`0 0 ${f.width} ${f.height}`,onPointerMove:X,onPointerUp:z,style:{touchAction:l?"none":"auto"},children:[E("title",{children:O}),pe("defs",{children:[E("marker",{id:Br,markerWidth:"8",markerHeight:"8",refX:"6",refY:"4",orient:"auto",markerUnits:"strokeWidth",children:E("path",{d:"M0 0 L7 4 L0 8 Z",className:"graph2d-axis-arrow",style:kt?{fill:kt}:void 0})}),E("clipPath",{id:Yc,children:E("rect",{x:P.left,y:P.top,width:Si,height:Pi})}),E("clipPath",{id:Tt,children:E("rect",{x:re.x,y:re.y,width:re.width,height:re.height})}),K.map(({pattern:y,patternId:v,color:G,opacity:q})=>y==="solid"?null:E(If,{id:v,pattern:y,color:G,opacity:q},v))]}),E("rect",{x:P.left,y:P.top,width:Si,height:Pi,rx:"4",className:"graph2d-plot-bg"}),K.length>0&&E("g",{className:"graph2d-fills",clipPath:`url(#${Tt})`,children:K.map(({fill:y,path:v,color:G,opacity:q,pattern:ae,patternId:Pe})=>E("path",{className:"graph2d-fill-region","data-testid":"graph2d-fill-region",d:v,fill:ae==="solid"?G:`url(#${Pe})`,fillOpacity:ae==="solid"?q:void 0,fillRule:"evenodd"},y.id))}),f.axes.grid&&f.kind==="cartesian"&&pe("g",{className:"graph2d-grid",children:[ce.map(y=>{let v=U(y,0,x,f,P);return E("line",{x1:v.x,x2:v.x,y1:re.y,y2:re.y+re.height},`x-grid-${y}`)}),Z.map(y=>{let v=U(0,y,x,f,P);return E("line",{x1:re.x,x2:re.x+re.width,y1:v.y,y2:v.y},`y-grid-${y}`)})]}),pe("g",{className:"graph2d-axes",children:[kr&&E("line",{x1:re.x,x2:re.x+re.width,y1:en,y2:en,markerEnd:`url(#${Br})`,style:bi}),Tr&&wt!==null&&E("line",{x1:wt,x2:wt,y1:re.y+re.height,y2:re.y,markerEnd:`url(#${Br})`,style:bi})]}),me&&pe("g",{className:"graph2d-ticks",children:[kr&&ce.map(y=>{let v=U(y,0,x,f,P),G=bo(y,f.axes.xTickMode,f.axes.xTickStep),q=f.axes.tickFontSize??Ks,ae=Js(G,q);return E(Qs,{cx:v.x,cy:en+18,width:ae.width,height:ae.height,align:"middle",vAlign:"middle",tex:G,className:"graph2d-tex-label",fontSize:q,staticMode:r},`x-tick-${y}`)}),Tr&&Z.map(y=>{let v=U(0,y,x,f,P),G=bo(y,f.axes.yTickMode,f.axes.yTickStep),q=f.axes.tickFontSize??Ks,ae=Js(G,q);return E(Qs,{cx:P.left-8,cy:v.y,width:ae.width,height:ae.height,align:"end",vAlign:"middle",tex:G,className:"graph2d-tex-label",fontSize:q,staticMode:r},`y-tick-${y}`)})]}),E("g",{className:"graph2d-curves",clipPath:`url(#${Tt})`,children:te.map(({curve:y,path:v})=>v?E("path",{"data-testid":"graph2d-curve",d:v,fill:"none",stroke:$t(y.color),strokeWidth:So(y.strokeWidth),strokeDasharray:Bs(y),strokeLinecap:"butt",vectorEffect:"non-scaling-stroke"},y.id):null)}),E("g",{className:"graph2d-point-guides",clipPath:`url(#${Tt})`,children:(f.points??[]).map(y=>{let v=Po(y);if(!v)return null;let G=U(v.x,v.y,x,f,P),q=$t(y.color,"#dc2626");return pe("g",{children:[y.showXProjection&&kr&&E("line",{"data-testid":"graph2d-point-guide-x",x1:G.x,x2:G.x,y1:G.y,y2:en,stroke:q,strokeOpacity:.65,strokeDasharray:"4 3",vectorEffect:"non-scaling-stroke"}),y.showYProjection&&Tr&&wt!==null&&E("line",{"data-testid":"graph2d-point-guide-y",x1:G.x,x2:wt,y1:G.y,y2:G.y,stroke:q,strokeOpacity:.65,strokeDasharray:"4 3",vectorEffect:"non-scaling-stroke"})]},`point-guides-${y.id}`)})}),E("g",{className:"graph2d-points",clipPath:`url(#${Tt})`,children:(f.points??[]).map(y=>{let v=Po(y);if(!v)return null;let G=U(v.x,v.y,x,f,P),q=$t(y.color,"#dc2626"),ae=Af(y.radius),Pe=y.fill==="none";return pe("g",{children:[Pe&&E("circle",{className:"graph2d-point-open-halo",cx:G.x,cy:G.y,r:ae+1.4,fill:"#ffffff",stroke:"none"}),E("circle",{className:"graph2d-point",cx:G.x,cy:G.y,r:ae,fill:Pe?"#ffffff":q,stroke:q,strokeWidth:Pe?2.4:0,vectorEffect:"non-scaling-stroke"})]},y.id)})}),!Xc&&f.curves.length>0&&E("text",{x:f.width/2,y:f.height/2,textAnchor:"middle",className:"graph2d-error-text",children:"\u5F0F\u3092\u8A55\u4FA1\u3067\u304D\u307E\u305B\u3093"}),l&&c&&pe(Ef,{children:[E("rect",{x:P.left,y:P.top,width:Math.max(0,c.left-P.left),height:f.height-P.top-P.bottom,fill:"#0f172a80",style:{pointerEvents:"none"}}),E("rect",{x:c.left+c.width,y:P.top,width:Math.max(0,f.width-P.right-(c.left+c.width)),height:f.height-P.top-P.bottom,fill:"#0f172a80",style:{pointerEvents:"none"}}),E("rect",{x:c.left,y:P.top,width:c.width,height:Math.max(0,c.top-P.top),fill:"#0f172a80",style:{pointerEvents:"none"}}),E("rect",{x:c.left,y:c.top+c.height,width:c.width,height:Math.max(0,f.height-P.bottom-(c.top+c.height)),fill:"#0f172a80",style:{pointerEvents:"none"}}),E("rect",{x:c.left,y:c.top,width:c.width,height:c.height,fill:"none",stroke:"#2563eb",strokeWidth:"2",strokeDasharray:"4 3",style:{cursor:"move",pointerEvents:"all"},onPointerDown:y=>D(y,"center")}),jc.map(y=>pe("g",{children:[E("circle",{cx:y.x,cy:y.y,r:5,fill:"#2563eb",stroke:"#ffffff",strokeWidth:"1.5",style:{pointerEvents:"none"}}),E("circle",{cx:y.x,cy:y.y,r:14,fill:"transparent",style:{cursor:y.cursor,pointerEvents:"all"},onPointerDown:v=>D(v,y.name)})]},y.name))]})]})})}function Mf(e){try{return Ye(e)}catch{return null}}function vf(e,t,n){let r=tl({curve:e,graphViewBox:t.graphViewBox,height:t.height,kind:t.kind,plotBox:n,viewBox:t.viewBox,width:t.width});return Co(pf,r,()=>ks(e,t,n))}function Of(e,t,n){let r=tl({curves:e.curves,fill:t,graphViewBox:e.graphViewBox,height:e.height,kind:e.kind,plotBox:n,viewBox:e.viewBox,width:e.width});return Co(mf,r,()=>zs(e,t,n)??"")}function el(e,t,n,r){let o=`${e}:${t}:${n??""}:${r}`;return Co(ff,o,()=>Ts(e,t,n,r))}function wf(e){if(e==="dashed")return"3 3";if(e==="dotted")return"1.2 3"}function Co(e,t,n){let r=e.get(t);if(r!==void 0)return e.delete(t),e.set(t,r),r;let o=n();if(e.set(t,o),e.size>df){let i=e.keys().next().value;i!==void 0&&e.delete(i)}return o}function tl(e){return JSON.stringify(e)}function kf(e){try{return Xe(e)}catch{return null}}function Tf(e,t){let n=Math.max(e.xMin,t.xMin),r=Math.min(e.xMax,t.xMax),o=Math.max(e.yMin,t.yMin),i=Math.min(e.yMax,t.yMax);return n>=r||o>=i?null:{xMin:n,xMax:r,yMin:o,yMax:i}}function Bf(e,t,n){return e.yMin<=0&&e.yMax>=0?U(0,0,{...e,xMin:0,xMax:1},t,n).y:t.height-n.bottom}function Rf(e,t,n){return e.xMin<=0&&e.xMax>=0?U(0,0,e,t,n).x:n.left}function Af(e){return Number.isFinite(e)&&e!==void 0?Math.min(12,Math.max(1.5,e)):4.3}function Kn(e){return e.replace(/[^a-zA-Z0-9_-]/g,"")||"graph"}function If({id:e,pattern:t,color:n,opacity:r}){let o=Math.min(.22,r*.45),i=Math.min(.95,Math.max(.36,r+.28)),a={stroke:n,strokeWidth:t==="cross"?1:1.25,strokeOpacity:i,strokeLinecap:"butt"};if(t==="dots")return pe("pattern",{id:e,width:"12",height:"12",patternUnits:"userSpaceOnUse",children:[E("rect",{width:"12",height:"12",fill:n,opacity:o}),E("circle",{cx:"3",cy:"3",r:"1.15",fill:n,opacity:i}),E("circle",{cx:"9",cy:"9",r:"1.15",fill:n,opacity:i})]});let s=Cf(t);return pe("pattern",{id:e,width:"10",height:"10",patternUnits:"userSpaceOnUse",children:[E("rect",{width:"10",height:"10",fill:n,opacity:o}),E("path",{d:s,...a})]})}function Cf(e){switch(e){case"diagonal":return"M -5 10 L 10 -5 M 0 10 L 10 0 M 5 10 L 10 5";case"diagonalBack":return"M 0 5 L 5 10 M 0 0 L 10 10 M 5 0 L 10 5";case"cross":return["M -5 10 L 10 -5","M 0 10 L 10 0","M 5 10 L 10 5","M 0 5 L 5 10","M 0 0 L 10 10","M 5 0 L 10 5"].join(" ");case"horizontal":return"M 0 3.2 H 10 M 0 8.2 H 10";case"vertical":return"M 3.2 0 V 10 M 8.2 0 V 10";case"dots":return""}}import{Fragment as ry,memo as oy,useEffect as iy,useLayoutEffect as ay,useMemo as sy,useRef as ly,useState as cy}from"react";var Lf=/[\u200B-\u200D\uFEFF]/g;function qn(e,t){return!Number.isFinite(t)||t===1||t<=0?e:e.map(n=>({...n,top:n.top/t,bottom:n.bottom/t,height:n.height/t}))}function rl(e,t={}){return Nf(e,Df,t).map(n=>({boxedRun:n.boxedRun,index:n.index,node:n.item}))}function Nf(e,t,n={}){let r=e.map((l,u)=>({index:u,item:l})),o=n.runIdPrefix?`${Hf(n.runIdPrefix)}-`:"",i=0,a=[],s=()=>{if(a.length===0)return;let l=`${o}boxed-run-${i}`,u=a.length;a.forEach((c,p)=>{r[c.index].boxedRun={connectLeft:p>0,connectRight:p<u-1,runId:l,segmentCount:u,segmentId:`${l}-segment-${p}-${c.index}`,segmentIndex:p,styleKey:c.styleKey}}),a=[],i+=1};return e.forEach((l,u)=>{let c=t(l);if(c.kind!=="ignored"){if(c.kind==="break"){s();return}a.length>0&&a[0].styleKey!==c.styleKey&&s(),a.push({index:u,styleKey:c.styleKey})}}),s(),r}function Eo(e){return e.map(t=>t.type==="text"?["text",t.text,t.marks?.join(",")??"",t.boxedPaddingY??"",t.boxedVariant??"",t.boxedTone??"",t.color??"",t.backgroundColor??"",t.fontFamily??"",t.fontSize??""].join(":"):["math",t.id,t.tex,t.marks?.join(",")??"",t.boxedPaddingY??"",t.boxedVariant??"",t.boxedTone??""].join(":")).join("|")}function Ff(e){let t=Zn(e),n=t.paddingY??0,r=t.variant??"frame",o=t.tone??"";return`${n}|${r}|${o}`}function Zn(e){return{paddingY:zf(e.boxedPaddingY,e.paddingY),variant:nl(e.boxedVariant,e.variant),tone:nl(e.boxedTone,e.tone)}}function Jn(e){return e.replace(Lf,"").length>0}function _f(e){let t=[];for(let n of e){if(!Number.isFinite(n.top)||!Number.isFinite(n.bottom)||n.height<=0)continue;let r=t[t.length-1];if(!r||n.top>r.bottom-1||n.bottom<r.top+1){t.push({top:n.top,bottom:n.bottom,rects:[n]});continue}r.top=Math.min(r.top,n.top),r.bottom=Math.max(r.bottom,n.bottom),r.rects.push(n)}return t.map(n=>n.rects)}function $f(e,t){return Math.max(0,e-t)}function Gf(e,t){return Math.max(0,t-e)}function ol(e){let t=new Map;for(let n of _f(e)){let r=Math.min(...n.map(a=>a.top)),o=Math.max(...n.map(a=>a.bottom)),i=o-r;if(!(!Number.isFinite(i)||i<=0))for(let a of n){if(a.boxedTarget===void 0)continue;let s=t.get(a.boxedTarget);t.set(a.boxedTarget,{targetHeight:Math.max(s?.targetHeight??0,i),ownHeight:Math.max(s?.ownHeight??0,a.height),extraPaddingTop:Math.max(s?.extraPaddingTop??0,$f(a.top,r)),extraPaddingBottom:Math.max(s?.extraPaddingBottom??0,Gf(a.bottom,o))})}}return t}function Df(e){return e.type==="text"&&!Jn(e.text)?{kind:"ignored"}:e.marks?.includes("boxed")?{kind:"boxed",styleKey:Ff(e)}:{kind:"break"}}function zf(...e){for(let t of e){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"&&t.trim()!==""){let n=Number.parseFloat(t);if(Number.isFinite(n))return n}}}function nl(...e){for(let t of e)if(typeof t=="string"&&t.length>0)return t}function Hf(e){return e.replace(/[^a-zA-Z0-9_-]+/g,"-").replace(/^-+|-+$/g,"")||"inline"}function yt(e,t={}){return{kind:"fragment",children:(t.annotateBoxedRuns?rl(e,{runIdPrefix:t.runIdPrefix}):e.map((r,o)=>({index:o,node:r}))).map(({boxedRun:r,index:o,node:i})=>Vf(i,o,r))}}function il(e,t,n,r,o){let i=Wf(e);return{type:"box",...i!==void 0?{paddingY:i}:{},math:t,connectLeft:n?.connectLeft,connectRight:n?.connectRight,run:n,variant:typeof r=="string"?r:void 0,tone:typeof o=="string"?o:void 0}}function Vf(e,t,n){let r=Uf(e);if(e.type==="mathInline"){let i=[];return r&&i.push({type:"style",style:r}),e.marks?.includes("underline")&&i.push({type:"underline"}),e.marks?.includes("boxed")&&i.push(il(e.boxedPaddingY,!0,n,e.boxedVariant,e.boxedTone)),{kind:"math",id:e.id,tex:e.tex,decorations:i,sourceIndex:t}}let o=(e.marks??[]).flatMap(i=>i==="bold"||i==="italic"||i==="underline"?[{type:i}]:i==="boxed"?[il(e.boxedPaddingY,!1,n,e.boxedVariant,e.boxedTone)]:[]);return r&&o.push({type:"style",style:r}),{kind:"text",text:e.text,decorations:o,sourceIndex:t}}function Uf(e){let t=typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)?e.fontSize:void 0,n={backgroundColor:e.backgroundColor,color:e.color,fontFamily:e.fontFamily,fontSizePt:t};return Object.values(n).some(r=>r!==void 0)?n:void 0}function Wf(e){let t=typeof e=="number"?e:Number.parseFloat(String(e));return Number.isFinite(t)&&t>=0?t:void 0}function al(e){return{kind:"fragment",children:e.blocks.map((t,n)=>({kind:"block",blockType:t.type,headingLevel:t.type==="heading"?t.level:void 0,textAlign:t.align,lineHeight:sl(t.lineHeight),children:yt(t.children,{annotateBoxedRuns:!0,runIdPrefix:`overlay-${n}`}).children}))}}function sl(e){let t=typeof e=="number"?String(e):String(e??"").trim();if(!/^(?:\d+(?:\.\d{1,2})?|\.\d{1,2})$/u.test(t))return;let n=Number(t);if(!(!Number.isFinite(n)||n<.8||n>3))return n.toFixed(2).replace(/\.?0+$/u,"")}function gt(e){return e==="s"?1.25:e==="l"?3:e==="xl"?5:2}function Lo(e){return e==="s"?14:e==="l"?22:e==="xl"?28:18}function ll(e,t){return dl(e.columns.map(n=>n.width),t)}function cl(e,t){return dl(e.rows.map(n=>n.height),t)}function ht(e,t){return t<0||t>e.columns.length?null:t===0?{axis:"vertical",edge:"left"}:t===e.columns.length?{axis:"vertical",edge:"right"}:{axis:"vertical",beforeColumnId:e.columns[t].id}}function xt(e,t){return t<0||t>e.rows.length?null:t===0?{axis:"horizontal",edge:"top"}:t===e.rows.length?{axis:"horizontal",edge:"bottom"}:{axis:"horizontal",beforeRowId:e.rows[t].id}}function Yf(e,t){let n=e.grid.lineOverrides??[];for(let r=n.length-1;r>=0;r-=1){let o=n[r];if(Xf(o,t))return o}}function xe(e,t){let r="edge"in t?e.grid.showOuterBorder!==!1:e.grid.showInnerBorders!==!1,o=Yf(e,t)?.style,i=o?.borderWidth??e.grid.borderWidth;return{visible:o?.visible??r,borderColor:o?.borderColor??e.grid.borderColor,borderWidth:Number.isFinite(i)?Math.max(0,i):0,borderStyle:o?.borderStyle??e.grid.borderStyle??"solid"}}function bt(e){return!e.visible||e.borderWidth<=0?"0":`${e.borderWidth}px ${e.borderStyle} ${e.borderColor}`}function ul(e,t,n,r=1,o=1){return{borderTop:Qn(e,"horizontal",t),borderRight:Qn(e,"vertical",n+o),borderBottom:Qn(e,"horizontal",t+r),borderLeft:Qn(e,"vertical",n)}}function Xf(e,t){return e.axis!==t.axis?!1:"edge"in e||"edge"in t?"edge"in e&&"edge"in t&&e.edge===t.edge:e.axis==="vertical"&&t.axis==="vertical"?e.beforeColumnId===t.beforeColumnId:e.axis==="horizontal"&&t.axis==="horizontal"?e.beforeRowId===t.beforeRowId:!1}function Qn(e,t,n){let r=t==="vertical"?ht(e,n):xt(e,n);if(!r)return"0";let o=xe(e,r);return o.visible&&o.borderWidth>0&&o.borderStyle==="double"?"0":bt(o)}function dl(e,t){let n=Math.max(1,t),r=e.map(jf),o=e.reduce((s,l)=>s+(l.mode==="fr"?Math.max(0,l.value):0),0),i=r.reduce((s,l)=>s+l,0),a=Math.max(0,n-i);if(i>n){let s=n/i;return r.map(l=>l*s)}return o<=0||a<=0?r:e.map((s,l)=>{if(s.mode!=="fr")return r[l];let u=r[l]+a*(Math.max(0,s.value)/o);return pl(u,s.min,s.max)})}function jf(e){return e.mode==="fixed"?Math.max(1,e.value):pl(e.min??1,e.min,e.max)}function pl(e,t,n){return Math.max(t??1,Math.min(e,n??Number.POSITIVE_INFINITY))}function Kf(e){return e.type==="group"}function fl(e){return e.filter(t=>!Kf(t)&&!qf(e,t))}function ml(e,t){return t.stackLayer==="background"||er(e,t).some(n=>n.stackLayer==="background")}function yl(e,t){if(t==="foreground")return e.filter(r=>!ml(e,r));let n=new Set;for(let r of e)if(ml(e,r)){n.add(r.id);for(let o of er(e,r))n.add(o.id)}return e.filter(r=>n.has(r.id))}function gl(e,t){let n=t.opacity??1;for(let r of er(e,t))n*=r.opacity??1;return n===1?void 0:n}function qf(e,t){return t.hidden?!0:er(e,t).some(n=>n.hidden)}function er(e,t){let n=[],r=t.parentId,o=new Set([t.id]);for(;r;){let i=e.find(a=>a.id===r);if(!i||o.has(i.id))break;n.push(i),o.add(i.id),r=i.parentId}return n}function tr(e){return e.some((t,n)=>n>0&&t.pageBreak?.breakBefore==="always")}function hl({isFullSpan:e,isFramedArea:t,blocks:n}){return!(e||t)||tr(n)}function xl(e){let t=Zn({paddingY:e}).paddingY;return t!==void 0?{"--boxed-text-padding-y":`${t}px`,"--boxed-text-line-height":`calc(1.78em + ${t*2+2}px)`}:void 0}function bl(e,t,n={}){let r={};n.boxedText&&(r["data-sigma-doc-boxed-text"]="true");let{paddingY:o,tone:i,variant:a}=Zn(e);return o!==void 0&&(r["data-sigma-doc-boxed-padding-y"]=String(o)),a&&a!=="frame"&&(r["data-sigma-doc-boxed-variant"]=a),i&&(r["data-sigma-doc-boxed-tone"]=i),n.math&&(r["data-sigma-doc-boxed-math"]="true"),t&&(r["data-boxed-run-height-target"]="true",r["data-boxed-run-id"]=t.runId,r["data-boxed-run-segment-id"]=t.segmentId,r["data-boxed-run-segment-index"]=String(t.segmentIndex),r["data-boxed-run-segment-count"]=String(t.segmentCount),r["data-boxed-run-style-key"]=t.styleKey,t.connectLeft&&(r["data-boxed-run-connect-left"]="true"),t.connectRight&&(r["data-boxed-run-connect-right"]="true")),r}function Sl(e){if(typeof window>"u")return 1;let t=1;for(let n=e;n;n=n.parentElement){let r=Number.parseFloat(window.getComputedStyle(n).zoom);Number.isFinite(r)&&r>0&&(t*=r)}return t>0?t:1}function St(e,t){return An(cs(e,t))}function No(e,t){return nr(al(e),{...t,mathFrame:"editor"})}function Fo(e,t){return nr(yt(e),{...t,mathFrame:"sigma-doc"})}function nr(e,t){if(e.kind==="fragment")return e.children.map(r=>nr(r,t)).join("");if(e.kind==="block"){let r=["margin:0",e.textAlign?`text-align:${e.textAlign}`:"",e.lineHeight?`line-height:${e.lineHeight}`:""].filter(Boolean).join(";"),o=e.children.map(a=>nr(a,t)).join(""),i=e.blockType==="heading"?"h3":"p";return`<${i} style="${r}">${o}</${i}>`}if(e.kind==="lineBreak")return"<br />";let n=e.kind==="text"?Dt(e.text):Zf(e,t);return Jf(n,e.decorations)}function Dt(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function _(e){return Dt(e).replace(/"/g,"&quot;")}function Zf(e,t){let n=_(e.id),r=_(e.tex),o=t.renderMathHtml(e.tex);return t.mathFrame==="sigma-doc"?`<span data-sigma-doc-math-inline="" data-id="${n}" data-tex="${r}">${o}</span>`:[`<span class="inline-math-node" style="margin:0" data-sigma-doc-math-inline="" data-id="${n}" data-tex="${r}" title="${r}" contenteditable="false">`,`<span class="math-preview math-preview-inline" data-empty="${e.tex?"false":"true"}">`,o,"</span>","</span>"].join("")}function Jf(e,t){let n=e;for(let r of t)if(r.type==="bold")n=`<strong>${n}</strong>`;else if(r.type==="italic")n=`<em>${n}</em>`;else if(r.type==="underline")n=`<span style="${ty()}">${n}</span>`;else if(r.type==="box")n=`<span style="${ey(r)}">${n}</span>`;else{let o=Qf(r.style);o&&(n=`<span style="${o}">${n}</span>`)}return n}function Qf(e){return[e.color?`color:${_(e.color)}`:"",e.backgroundColor?`background-color:${_(e.backgroundColor)}`:"",e.fontFamily?`font-family:${_(e.fontFamily)}`:"",e.fontWeight?`font-weight:${_(e.fontWeight)}`:"",e.fontStyle?`font-style:${_(e.fontStyle)}`:"",e.textDecoration?`text-decoration:${_(e.textDecoration)}`:"",e.fontSizePt!==void 0?`font-size:${e.fontSizePt}pt`:""].filter(Boolean).join(";")}function ey(e){let t=e.math?"display:inline-flex;align-items:center;vertical-align:baseline;line-height:normal;":"display:inline-flex;align-items:center;vertical-align:baseline;line-height:1;",n=[e.connectLeft?"border-left-width:0;border-top-left-radius:0;border-bottom-left-radius:0;":"",e.connectRight?"border-right-width:0;border-top-right-radius:0;border-bottom-right-radius:0;":""].join("");return`border:1px solid currentColor;padding:${e.paddingY??0}px 0.18em;${t}border-radius:2px;box-decoration-break:clone;-webkit-box-decoration-break:clone;${n}`}function ty(){return"text-decoration-line:underline;text-decoration-thickness:1px;text-decoration-color:currentColor;text-underline-offset:0.12em;"}import{memo as ny}from"react";import{jsx as _o}from"react/jsx-runtime";var Ml=ny(function({tex:t,displayMode:n=!1,className:r,mathFractionSizing:o}){Yn("MathPreview.render");let i=St(t,o),a=["math-preview",n?"math-preview-display":"math-preview-inline",r].filter(Boolean).join(" ");return _o("span",{className:a,dangerouslySetInnerHTML:{__html:i},"data-empty":t?"false":"true"})});function vl({className:e,displayMode:t=!1,editing:n=!1,selected:r=!1,textSelected:o=!1}={}){return["inline-math-node",t?"display-math-node":"",r?"selected":"",o?"text-selected":"",n?"editing":"",e].filter(Boolean).join(" ")}function Ol({id:e,tex:t,title:n=t}){return{"data-sigma-doc-math-inline":"",...e?{"data-id":e}:{},"data-tex":t,title:n}}function $o({children:e,className:t,displayMode:n=!1,editing:r=!1,id:o,mathClassName:i,mathFractionSizing:a,renderFrame:s,selected:l=!1,tex:u,textSelected:c=!1,title:p}){let g={children:e??_o(Ml,{tex:u,displayMode:n,className:i,mathFractionSizing:a}),className:vl({className:t,displayMode:n,editing:r,selected:l,textSelected:c}),dataAttributes:Ol({id:o,tex:u,title:p})};return s?s(g):_o("span",{className:g.className,...g.dataAttributes,children:g.children})}import{jsx as ie}from"react/jsx-runtime";var zo='[data-boxed-run-height-target="true"][data-boxed-run-segment-id]',uy=.5,wl=100,dy=typeof window>"u"?iy:ay;function Il(e){return xl(e)}function Ho(e){return Eo(e)}function Pt(e){let t=ly(null),[n,r]=cy({});return dy(()=>{let o=t.current;if(!o||typeof window>"u")return;let i=!1,a=!1,s=null,l=null,u=null,c=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>h()),p=typeof MutationObserver>"u"?null:new MutationObserver(()=>h()),m=()=>{c?.disconnect(),c?.observe(o),o.querySelectorAll(zo).forEach(b=>{c?.observe(b)})},g=()=>{a=!0,o.classList.add("boxed-inline-run-measuring");try{let b=yy(o);r(S=>Sy(S,b)?S:b)}finally{o.classList.remove("boxed-inline-run-measuring"),m(),l=window.requestAnimationFrame(()=>{l=null,u=window.requestAnimationFrame(()=>{u=null,a=!1})})}};function h(){i||a||s!==null||(s=window.requestAnimationFrame(()=>{s=null,g()}))}return m(),p?.observe(o,{attributes:!0,attributeFilter:["class","data-sigma-doc-boxed-padding-y","data-sigma-doc-boxed-variant","data-sigma-doc-boxed-tone"],childList:!0,characterData:!0,subtree:!0}),window.addEventListener("resize",h),h(),()=>{i=!0,s!==null&&window.cancelAnimationFrame(s),l!==null&&window.cancelAnimationFrame(l),u!==null&&window.cancelAnimationFrame(u),c?.disconnect(),p?.disconnect(),window.removeEventListener("resize",h)}},[e]),{aligned:Object.keys(n).length>0,alignmentStyles:n,ref:t}}function py(e,t){return e.split(`
10
+ `).flatMap((n,r)=>{let o=[];return r>0&&o.push(ie("br",{},`${t}-br-${r}`)),n.length>0&&o.push(ie(ry,{children:n},`${t}-text-${r}`)),o})}function Mt(e,t={}){let n=t.keyPrefix??"inline",r=t.resolveText??(o=>o);return my(yt(e,{annotateBoxedRuns:!0,runIdPrefix:n}).children,{...t,keyPrefix:n,resolveText:r})}function my(e,t){let n=[],r=[],o=()=>{if(r.length!==0){if(r.length===1&&kl(r[0],t.resolveText))n.push(Go(r[0],t));else{let i=r[0],a=r[r.length-1];n.push(ie("span",{className:"sigma-underline-run",children:r.map(s=>Go(s,t,{suppressUnderline:!0}))},`${t.keyPrefix}-underline-run-${i.sourceIndex}-${a.sourceIndex}`))}r=[]}};for(let i of e){if(fy(i)&&!kl(i,t.resolveText)){r.push(i);continue}o(),n.push(Go(i,t))}return o(),n}function Go(e,t,n={}){let r=e.sourceIndex??0,o=Do(e.decorations,"box");if(e.kind==="text"){let s=py(t.resolveText(e.text),`${t.keyPrefix}-${r}`);return zt(e.decorations,"bold")&&(s=ie("strong",{children:s})),zt(e.decorations,"italic")&&(s=ie("em",{children:s})),zt(e.decorations,"underline")&&!n.suppressUnderline&&(s=ie("u",{children:s})),o&&(s=ie("span",{className:"print-boxed-text",style:Bl(o,t.alignmentStyles),...Rl(o),children:s})),ie("span",{style:Tl(Do(e.decorations,"style")?.style),children:s},`${t.keyPrefix}-${r}-${e.text}`)}let i=Tl(Do(e.decorations,"style")?.style),a=ie($o,{id:e.id,tex:e.tex,mathFractionSizing:t.mathFractionSizing});return zt(e.decorations,"underline")&&!n.suppressUnderline&&(a=ie("u",{children:a})),o?ie("span",{className:"print-boxed-text boxed-inline-math",style:Cl(i,Bl(o,t.alignmentStyles)),...Rl(o),children:a},`${t.keyPrefix}-${e.id}`):i?ie("span",{style:i,children:a},`${t.keyPrefix}-${e.id}`):ie("span",{children:a},`${t.keyPrefix}-${e.id}`)}function fy(e){return zt(e.decorations,"underline")}function kl(e,t){return e.kind==="text"&&t(e.text).includes(`
11
+ `)}function Tl(e){if(!e)return;let t={color:e.color,backgroundColor:e.backgroundColor,fontFamily:e.fontFamily,fontSize:e.fontSizePt?`${e.fontSizePt}pt`:void 0};return Object.values(t).some(n=>n!==void 0)?t:void 0}function Bl(e,t){return Cl(Il(e.paddingY),e.run?t?.[e.run.segmentId]:void 0)}function Rl(e){return bl({boxedPaddingY:e.paddingY,boxedTone:e.tone,boxedVariant:e.variant},e.run)}function zt(e,t){return e.some(n=>n.type===t)}function Do(e,t){return e.find(n=>n.type===t)}function Cl(...e){let t={};for(let n of e)n&&Object.assign(t,n);return Object.keys(t).length>0?t:void 0}function yy(e){let t=gy(e),n=ol(t),r={};for(let[o,i]of n)r[o.segmentId]={"--boxed-run-extra-padding-bottom":`${or(i.extraPaddingBottom)}px`,"--boxed-run-extra-padding-top":`${or(i.extraPaddingTop)}px`,"--boxed-run-own-height":`${or(i.ownHeight)}px`,"--boxed-run-target-height":`${or(i.targetHeight)}px`};return r}function gy(e){let t=[],n=Sl(e),r=o=>{for(let i of Array.from(o.childNodes)){if(i.nodeType===Node.TEXT_NODE){Jn(i.textContent??"")&&i instanceof Text&&t.push(...qn(hy(i),n));continue}if(!(!(i instanceof HTMLElement)||xy(i))){if(i.matches(zo)){let a=i.getAttribute("data-boxed-run-segment-id");a&&t.push(...qn(Al(i),n).map(s=>({...s,boxedTarget:{segmentId:a}})));continue}if(i.tagName!=="BR"){if(i.querySelector(zo)){r(i);continue}by(i)&&t.push(...qn(Al(i),n))}}}};return r(e),t}function hy(e){let t=e.ownerDocument.createRange();t.selectNodeContents(e);let n=El(t);return t.detach(),n}function Al(e){let t=El(e);return t.length>0?t:Ll(e.getBoundingClientRect())}function El(e){return Array.from(e.getClientRects()).flatMap(Ll)}function Ll(e){return!Number.isFinite(e.top)||!Number.isFinite(e.bottom)||!Number.isFinite(e.height)||e.height<=0?[]:[{top:e.top,bottom:e.bottom,height:e.height}]}function xy(e){return e.getAttribute("aria-hidden")==="true"||e.hidden}function by(e){return Jn(e.textContent??"")||e.getBoundingClientRect().width>0||e.getBoundingClientRect().height>0}function Sy(e,t){let n=Object.keys(e),r=Object.keys(t);return n.length!==r.length||!n.every(o=>t[o]!==void 0)?!1:n.every(o=>rr(Fe(e[o],"--boxed-run-extra-padding-bottom"),Fe(t[o],"--boxed-run-extra-padding-bottom"))&&rr(Fe(e[o],"--boxed-run-extra-padding-top"),Fe(t[o],"--boxed-run-extra-padding-top"))&&rr(Fe(e[o],"--boxed-run-own-height"),Fe(t[o],"--boxed-run-own-height"))&&rr(Fe(e[o],"--boxed-run-target-height"),Fe(t[o],"--boxed-run-target-height")))}function Fe(e,t){let n=e[t];if(typeof n=="number")return n;if(typeof n=="string"){let r=Number.parseFloat(n);return Number.isFinite(r)?r:0}return 0}function rr(e,t){return Math.abs(e-t)<=uy}function or(e){return Math.round(e*wl)/wl}var Nl=oy(function({nodes:t,className:n,keyPrefix:r,mathFractionSizing:o}){let i=["rich-inline-content",n].filter(Boolean).join(" "),a=sy(()=>Eo(t),[t]),{aligned:s,alignmentStyles:l,ref:u}=Pt(a);return ie("span",{ref:u,className:i,"data-boxed-run-aligned":s?"true":void 0,children:Mt(t,{alignmentStyles:l,keyPrefix:r,mathFractionSizing:o})})});import{Fragment as Cv,jsx as Ev}from"react/jsx-runtime";import{useMemo as Py}from"react";import{jsx as be,jsxs as _l}from"react/jsx-runtime";var My=e=>e;function _e({block:e,mathFractionSizing:t,resolveText:n=My}){return e.type==="heading"?be(vy,{block:e,mathFractionSizing:t,resolveText:n}):e.type==="list"?be(Fl,{block:e,mathFractionSizing:t,resolveText:n}):be(Oy,{block:e,mathFractionSizing:t,resolveText:n})}function vy({block:e,mathFractionSizing:t,resolveText:n}){let r=`h${e.level}`,o=Vo(e.children),{aligned:i,alignmentStyles:a,ref:s}=Pt(o);return be(r,{ref:s,"data-boxed-run-aligned":i?"true":void 0,"data-sigma-doc-id":e.id,className:"print-heading",style:{textAlign:e.align??"left",lineHeight:e.lineHeight},children:Mt(e.children,{alignmentStyles:a,keyPrefix:e.id,mathFractionSizing:t,resolveText:n})})}function Oy({block:e,mathFractionSizing:t,resolveText:n}){let r=Vo(e.children),{aligned:o,alignmentStyles:i,ref:a}=Pt(r);return _l("p",{ref:a,"data-boxed-run-aligned":o?"true":void 0,"data-sigma-doc-id":e.id,className:"print-paragraph",style:{textAlign:e.align??"left",lineHeight:e.lineHeight},children:[Mt(e.children,{alignmentStyles:i,keyPrefix:e.id,mathFractionSizing:t,resolveText:n}),!ky(e.children)&&be("br",{},"trailing-break")]})}function Fl({block:e,mathFractionSizing:t,resolveText:n}){let r=e.items.map(o=>_l("li",{"data-sigma-doc-id":o.id,children:[be(wy,{item:o,mathFractionSizing:t,resolveText:n}),(o.nested??[]).map(i=>be(Fl,{block:i,mathFractionSizing:t,resolveText:n},i.id))]},o.id));return e.listType==="ordered"?be("ol",{"data-sigma-doc-id":e.id,className:"print-list",start:e.start,children:r}):be("ul",{"data-sigma-doc-id":e.id,className:"print-list",children:r})}function wy({item:e,mathFractionSizing:t,resolveText:n}){let r=Vo(e.children),{aligned:o,alignmentStyles:i,ref:a}=Pt(r);return be("span",{ref:a,"data-boxed-run-aligned":o?"true":void 0,children:Mt(e.children,{alignmentStyles:i,keyPrefix:e.id,mathFractionSizing:t,resolveText:n})})}function ky(e){return e.some(t=>t.type==="text"?t.text.length>0:!0)}function Vo(e){return Py(()=>Ho(e),[e])}var Ty=64,we='stroke-linecap="butt" stroke-linejoin="miter"',By=.6;function $l(e){return Math.ceil(e*By)}function sr(e,t,n,r,o={}){if(e.length===0)return;let i=un(ue({version:1,shapes:e,assets:t}).shapes),a=o.stackLayer?yl(i,o.stackLayer):i,l=fl(a).filter(m=>Ry(m,n,o.viewportPaddingPx));if(l.length===0)return;let u=n.offsetX??0,c=n.offsetY??0,p=l.map(m=>Ay(Cy(m,gl(a,m)),t,r)).join("");return[`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${u} ${c} ${n.width} ${n.height}" width="${n.width}" height="${n.height}">`,"<defs>","</defs>",p,"</svg>"].join("")}function Ry(e,t,n=Ty){let r=t.offsetX??0,o=t.offsetY??0,i=r-n,a=o-n,s=r+t.width+n,l=o+t.height+n,u=ge(e);return u.x+u.w>=i&&u.x<=s&&u.y+u.h>=a&&u.y<=l}function Yo(e,t,n,r={}){if(e){if(e.overlaySnapshot){let o=ue(e.overlaySnapshot);return sr(o.shapes,o.assets,t,n,r)}return r.stackLayer==="background"?void 0:e.previewSvg}}function Ay(e,t,n){let r="";if(e.type==="group")return"";if(e.type==="geo"){let o=_(e.props.color||"#111111"),i=gt(e.props.size),a=Ht(e.props.dash),s=e.props.fill==="solid"?_(e.props.fillColor||e.props.color||"#111111"):"transparent",l=$e("stroke-opacity",e.props.strokeOpacity),u=$e("fill-opacity",e.props.fillOpacity);if(e.props.geo==="ellipse")return r=`<ellipse cx="${e.x+e.props.w/2}" cy="${e.y+e.props.h/2}" rx="${e.props.w/2}" ry="${e.props.h/2}" fill="${s}" stroke="${o}" stroke-width="${i}" ${we}${a}${l}${u} />`,ye(e,Se(e,Uo(e,r)));if(e.props.geo==="triangle"||e.props.geo==="diamond"||e.props.geo==="pentagon"||e.props.geo==="regularPolygon"||e.props.geo==="blockArrow")return r=`<polygon points="${_y(Ly(e.props.geo,e.props.w,e.props.h,e.props.apexX,e.props.headLengthRatio,e.props.shaftRatio,e.props.polygonSides),e.x,e.y)}" fill="${s}" stroke="${o}" stroke-width="${i}" ${we}${a}${l}${u} />`,ye(e,Se(e,Uo(e,r)));let c=typeof e.props.radius=="number"&&e.props.radius>0?Math.max(0,Math.min(e.props.radius,e.props.w/2,e.props.h/2)):0,p=c>0?` rx="${c}" ry="${c}"`:"";return r=`<rect x="${e.x}" y="${e.y}" width="${e.props.w}" height="${e.props.h}"${p} fill="${s}" stroke="${o}" stroke-width="${i}" ${we}${a}${l}${u} />`,ye(e,Se(e,Uo(e,r)))}if(e.type==="arrow"){let o={x:e.x+e.props.start.x,y:e.y+e.props.start.y},i={x:e.x+e.props.end.x,y:e.y+e.props.end.y},a=Wo(e.id,e.props.color,e.props.strokeOpacity),s=vt("marker-start",e.id,"start",e.props.arrowheadStart),l=vt("marker-end",e.id,"end",e.props.arrowheadEnd);return r=`<defs>${a}</defs><line x1="${o.x}" y1="${o.y}" x2="${i.x}" y2="${i.y}" stroke="${_(e.props.color)}" stroke-width="${gt(e.props.size)}" ${we}${Ht(e.props.dash)}${$e("stroke-opacity",e.props.strokeOpacity)}${s}${l} />`,ye(e,Se(e,Gl(e,r,[o,i])))}if(e.type==="line"){let o=fn(e.props.kind),i=e.props.points.map(h=>({x:e.x+h.x,y:e.y+h.y})),a=Ur(o,i,e.props.closed),s=Wo(e.id,e.props.color,e.props.strokeOpacity),l=a?"":vt("marker-start",e.id,"start",e.props.arrowheadStart),u=a?"":vt("marker-end",e.id,"end",e.props.arrowheadEnd),c=Ey(e),p=a&&e.props.fill==="solid"?e.props.fillPattern==="diagonalHatch"?`url(#${_(Hl(e.id))})`:_(e.props.fillColor||e.props.color||"#111111"):"none",m=a?$e("fill-opacity",e.props.fillOpacity):"",g=`fill="${p}" stroke="${_(e.props.color)}" stroke-width="${gt(e.props.size)}" ${we}${Ht(e.props.dash)}${$e("stroke-opacity",e.props.strokeOpacity)}${m}${l}${u}`;return r=a?`<defs>${s}${c}</defs><polygon points="${Wr(i)}" ${g} />`:o==="polyline"?`<defs>${s}${c}</defs><polyline points="${Wr(i)}" ${g} />`:`<defs>${s}${c}</defs><path d="${_(sa(i,o))}" ${g} />`,ye(e,Se(e,Gl(e,r,i)))}if(e.type==="arc"){let o=Fy(e),i=e.props.kind==="sector"?$e("fill-opacity",e.props.fillOpacity):"",a=Wo(e.id,e.props.color,e.props.strokeOpacity),s=e.props.kind==="sector"?"":vt("marker-start",e.id,"start",e.props.arrowheadStart),l=e.props.kind==="sector"?"":vt("marker-end",e.id,"end",e.props.arrowheadEnd);return r=`<defs>${a}</defs><path d="${_(Ny(e))}" fill="${o}" stroke="${_(e.props.color)}" stroke-width="${gt(e.props.size)}" ${we}${Ht(e.props.dash)}${$e("stroke-opacity",e.props.strokeOpacity)}${i}${s}${l} />`,ye(e,Se(e,r))}if(e.type==="image"){let o=t[e.props.assetId],i=o?Iy(o):null;if(!i)return"";let a=Vr(e,o),s=ia(e,o,a),l=e.x+s.x,u=e.y+s.y,c=`clip-${_(e.id)}`;return r=[`<clipPath id="${c}"><rect x="${e.x}" y="${e.y}" width="${e.props.w}" height="${e.props.h}" /></clipPath>`,`<image x="${l}" y="${u}" width="${s.width}" height="${s.height}" href="${_(i)}" preserveAspectRatio="none" clip-path="url(#${c})" />`].join(""),ye(e,Se(e,r))}if(e.type==="callout"){let o=Vi(e),i=rn(e),a=$l(Re(e)),s=No(e.props.richText,{renderMathHtml:n.renderMathHtml}),l=`<path transform="translate(${e.x} ${e.y})" d="${_(Zi(e))}" fill="transparent" stroke="#111111" stroke-width="${gt(e.props.strokeWidth)}" ${we}${Ht(e.props.dash)} />`,u=ir(e.x+o.x-a,e.y+o.y-a,o.w+a*2,o.h+a*2,[`<div xmlns="http://www.w3.org/1999/xhtml" style="box-sizing:border-box;display:flex;align-items:center;justify-content:center;width:${o.w}px;height:${o.h}px;margin:${a}px;color:${_(e.props.color)};font-size:${i}pt;line-height:${Me};overflow:visible;overflow-wrap:anywhere;white-space:pre-wrap;text-align:center;">`,`<div style="width:100%;min-width:0;">${s}</div>`,"</div>"].join(""),{overflowVisible:!0});return r=`${l}${u}`,ye(e,Se(e,r))}if(e.type==="graph2dShape"){let o=Rt(e),i=n.renderGraphHtml(o.spec,e.id);return r=ir(o.renderBounds.x,o.renderBounds.y,o.renderBounds.w,o.renderBounds.h,[`<div xmlns="http://www.w3.org/1999/xhtml" style="width:${o.renderBounds.w}px;height:${o.renderBounds.h}px;overflow:hidden;background:transparent;">`,i,"</div>"].join("")),ye(e,Se(e,r))}if(e.type==="text"){let o=ge(e),i=rn(e),a=$l(Re(e)),s=No(e.props.richText,{renderMathHtml:n.renderMathHtml}),l=e.props.autoSize?e.props.maxWidth!==void 0?"white-space:pre-wrap;overflow-wrap:anywhere;":"white-space:pre;":"white-space:pre-wrap;";return r=ir(e.x-a,e.y-a,o.w+a*2,o.h+a*2,[`<div xmlns="http://www.w3.org/1999/xhtml" style="box-sizing:border-box;width:${o.w}px;min-height:${o.h}px;margin:${a}px;color:${_(e.props.color)};font-size:${i}pt;line-height:${Me};overflow:visible;${l}">`,s,"</div>"].join(""),{overflowVisible:!0}),ye(e,Se(e,r))}if(e.type==="tableShape"){let o=Hy(e.props.table);return r=ir(e.x-o,e.y-o,e.props.w+o*2,e.props.h+o*2,Gy(e.props.table,e.props.w,e.props.h,o,n.renderMathHtml)),ye(e,r)}return""}function Iy(e){return e.props.storage&&e.props.src.startsWith("sigma-doc-storage://")?null:e.props.src.trim()?e.props.src:null}function Cy(e,t){return t===void 0?e:{...e,opacity:t}}function Se(e,t){let n=It(e);if(!n)return t;let r=ge(e),o=r.x+r.w/2,i=r.y+r.h/2;return`<g transform="rotate(${$y(n)} ${o} ${i})">${t}</g>`}function ye(e,t){return e.opacity===void 0||e.opacity>=1?t:`<g opacity="${e.opacity}">${t}</g>`}function Uo(e,t){return e.props.label?[t,`<text x="${e.x+e.props.w/2}" y="${e.y+e.props.h/2}" fill="${_(e.props.labelColor)}" stroke="none" text-anchor="middle" dominant-baseline="middle" font-size="${Lo(e.props.size)}">${Dt(e.props.label)}</text>`].join(""):t}function Gl(e,t,n){if(!e.props.label)return t;let r=la(n);return r?[t,`<text x="${r.x}" y="${r.y-8}" fill="${_(e.props.labelColor??e.props.color)}" stroke="none" text-anchor="middle" font-size="${Lo(e.props.size)}">${Dt(e.props.label)}</text>`].join(""):t}function Wo(e,t,n){let r=_(e),o=_(t),i=$e("opacity",n);return[`<marker id="arrowhead-${r}-start" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto-start-reverse" markerUnits="strokeWidth"><path d="M 1.5 1.5 L 7 4 L 1.5 6.5" fill="none" stroke="${o}" stroke-width="1.2" ${we}${i} /></marker>`,`<marker id="arrowhead-${r}-end" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto" markerUnits="strokeWidth"><path d="M 1.5 1.5 L 7 4 L 1.5 6.5" fill="none" stroke="${o}" stroke-width="1.2" ${we}${i} /></marker>`,`<marker id="bar-${r}-start" markerWidth="8" markerHeight="12" refX="4" refY="6" orient="auto" markerUnits="strokeWidth"><path d="M 4 0 L 4 12" fill="none" stroke="${o}" stroke-width="2"${i} /></marker>`,`<marker id="bar-${r}-end" markerWidth="8" markerHeight="12" refX="4" refY="6" orient="auto" markerUnits="strokeWidth"><path d="M 4 0 L 4 12" fill="none" stroke="${o}" stroke-width="2"${i} /></marker>`,`<marker id="dot-${r}-start" markerWidth="8" markerHeight="8" refX="4" refY="4" orient="auto" markerUnits="strokeWidth"><circle cx="4" cy="4" r="3" fill="${o}"${i} /></marker>`,`<marker id="dot-${r}-end" markerWidth="8" markerHeight="8" refX="4" refY="4" orient="auto" markerUnits="strokeWidth"><circle cx="4" cy="4" r="3" fill="${o}"${i} /></marker>`].join("")}function Hl(e){return`fill-${e}`}function Ey(e){if(e.props.fillPattern!=="diagonalHatch")return"";let t=_(Hl(e.id)),n=_(e.props.fillColor??"#ffffff"),r=_(e.props.color);return`<pattern id="${t}" patternUnits="userSpaceOnUse" width="6" height="6"><rect width="6" height="6" fill="${n}" /><path d="M -1 7 L 7 -1" stroke="${r}" stroke-width="1" /></pattern>`}function vt(e,t,n,r){return!r||r==="none"?"":` ${e}="url(#${r==="arrow"?"arrowhead":r}-${_(t)}-${n})"`}function Ht(e){return e==="dashed"?' stroke-dasharray="8 6"':e==="dotted"?' stroke-dasharray="1 6"':""}function $e(e,t){return t===void 0||t>=1?"":` ${e}="${Math.max(0,t)}"`}function Ly(e,t,n,r,o,i,a){return e==="blockArrow"?pn(t,n,o,i):e==="triangle"?[{x:nn(r??t/2,0,t),y:0},{x:t,y:n},{x:0,y:n}]:e==="diamond"?[{x:t/2,y:0},{x:t,y:n/2},{x:t/2,y:n},{x:0,y:n/2}]:gn(t,n,e==="pentagon"?5:yn(a))}function Ny(e){let{rx:t,ry:n}=Ie(e),r=Dl(e,e.props.startAngle),o=Dl(e,e.props.endAngle),a=Qe(e.props.endAngle-e.props.startAngle)>Math.PI?1:0;return e.props.kind==="sector"?`M ${e.x+t} ${e.y+n} L ${e.x+r.x} ${e.y+r.y} A ${t} ${n} 0 ${a} 1 ${e.x+o.x} ${e.y+o.y} Z`:`M ${e.x+r.x} ${e.y+r.y} A ${t} ${n} 0 ${a} 1 ${e.x+o.x} ${e.y+o.y}`}function Fy(e){return e.props.kind!=="sector"||e.props.fill==="none"?"none":_(e.props.fillColor??e.props.color)}function Dl(e,t){let{rx:n,ry:r}=Ie(e);return{x:n+Math.cos(t)*n,y:r+Math.sin(t)*r}}function _y(e,t,n){return e.map(r=>`${t+r.x},${n+r.y}`).join(" ")}function $y(e){return e*180/Math.PI}function ir(e,t,n,r,o,i={}){let a=i.overflowVisible?' overflow="visible"':"";return`<foreignObject x="${e}" y="${t}" width="${n}" height="${r}"${a}>${o}</foreignObject>`}function Gy(e,t,n,r,o){let i=ll(e,t),a=cl(e,n),s=zl(i),l=zl(a),u=new Map(e.cells.map(g=>[`${g.rowId}:${g.columnId}`,g])),c=new Set,p=e.columns.map((g,h)=>`<col style="width:${i[h]}px" />`).join(""),m=e.rows.map((g,h)=>{let b=e.columns.map((S,M)=>{let L=`${h}:${M}`;if(c.has(L))return"";let w=u.get(`${g.id}:${S.id}`),B=w?.rowSpan??1,Y=w?.colSpan??1;for(let P=h;P<h+B;P+=1)for(let Q=M;Q<M+Y;Q+=1)(P!==h||Q!==M)&&c.add(`${P}:${Q}`);return[`<td ${[B>1?`rowspan="${B}"`:"",Y>1?`colspan="${Y}"`:""].filter(Boolean).join(" ")} style="${Wy(e,w,h,M,B,Y)}">`,`<div style="${Yy(e,w)}">`,w?.content.map(P=>Vy(P,w,o)).join("")??"","</div>","</td>"].join("")}).join("");return`<tr style="height:${a[h]}px">${b}</tr>`}).join("");return[`<div xmlns="http://www.w3.org/1999/xhtml" style="box-sizing:border-box;width:${t+r*2}px;height:${n+r*2}px;overflow:visible;padding:${r}px;">`,`<div style="position:relative;width:${t}px;height:${n}px;">`,`<table style="width:${t}px;height:${n}px;border-collapse:collapse;table-layout:fixed;background:transparent;border:0">`,`<colgroup>${p}</colgroup>`,`<tbody>${m}</tbody>`,"</table>",Dy(e,s,l),"</div>","</div>"].join("")}function Dy(e,t,n){let r=t.map((a,s)=>{let l=ht(e,s);if(!l)return"";let u=xe(e,l);return ar(u)?`<div style="position:absolute;top:0;bottom:0;left:${a-u.borderWidth/2}px;width:0;border-left:${bt(u)};pointer-events:none;"></div>`:""}).join(""),o=n.map((a,s)=>{let l=xt(e,s);if(!l)return"";let u=xe(e,l);return ar(u)?`<div style="position:absolute;right:0;left:0;top:${a-u.borderWidth/2}px;height:0;border-top:${bt(u)};pointer-events:none;"></div>`:""}).join(""),i=zy(e,t,n);return!r&&!o&&!i?"":`<div style="position:absolute;inset:0;z-index:2;pointer-events:none;">${r}${o}${i}</div>`}function zy(e,t,n){let r=t.map((i,a)=>{let s=ht(e,a);if(!s)return"";let l=xe(e,s);return ar(l)?n.map((u,c)=>{let p=xt(e,c);if(!p)return"";let m=xe(e,p);if(!m.visible||m.borderWidth<=0)return"";let g=i-l.borderWidth/2,h=u-m.borderWidth/2;return`<div style="position:absolute;z-index:3;left:${g}px;top:${h}px;width:${l.borderWidth}px;height:0;border-top:${bt(m)};pointer-events:none;"></div>`}).join(""):""}).join(""),o=n.map((i,a)=>{let s=xt(e,a);if(!s)return"";let l=xe(e,s);return ar(l)?t.map((u,c)=>{let p=ht(e,c);if(!p)return"";let m=xe(e,p);if(!m.visible||m.borderWidth<=0)return"";let g=u-m.borderWidth/2,h=i-l.borderWidth/2;return`<div style="position:absolute;z-index:3;left:${g}px;top:${h}px;width:0;height:${l.borderWidth}px;border-left:${bt(m)};pointer-events:none;"></div>`}).join(""):""}).join("");return r+o}function ar(e){return e.visible&&e.borderWidth>0&&e.borderStyle==="double"}function zl(e){let t=[0];for(let n of e)t.push(t[t.length-1]+n);return t}function Hy(e){let t=0;for(let n=0;n<=e.columns.length;n+=1){let r=ht(e,n);if(!r)continue;let o=xe(e,r);o.visible&&(t=Math.max(t,o.borderWidth))}for(let n=0;n<=e.rows.length;n+=1){let r=xt(e,n);if(!r)continue;let o=xe(e,r);o.visible&&(t=Math.max(t,o.borderWidth))}return Math.ceil(t)}function Vy(e,t,n){if(e.type==="trend"){let o=e.label?.length?`<span>${Fo(e.label,{renderMathHtml:n})}</span>`:"";return`<div style="display:flex;align-items:center;justify-content:center;gap:4px;width:100%;min-height:1.75em">${Uy(e.direction,t?.colSpan??1)}${o}</div>`}return`<p style="margin:0;${e.align?`text-align:${e.align}`:""}">${Fo(e.children,{renderMathHtml:n})}</p>`}function Uy(e,t){let n=Math.max(42,t>1?38*t:44),r=24,o=e==="up"?18:e==="down"?6:12,i=e==="up"?6:e==="down"?18:12,a=e==="up"?`${n-6},${i} ${n-12},${i-1.5} ${n-9},${i+4}`:e==="down"?`${n-6},${i} ${n-12},${i+1.5} ${n-9},${i-4}`:`${n-6},${i} ${n-12},${i-3} ${n-12},${i+3}`;return[`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${r}" viewBox="0 0 ${n} ${r}" style="display:block;overflow:visible;">`,`<line x1="6" y1="${o}" x2="${n-7}" y2="${i}" stroke="#111827" stroke-width="1" />`,`<polygon points="${a}" fill="#111827" />`,"</svg>"].join("")}function Wy(e,t,n,r,o,i){let a={...e.defaultCellStyle,...t?.style??{}},s=ul(e,n,r,o,i);return["box-sizing:border-box","position:relative","overflow:hidden",`text-align:${a.align??"center"}`,`vertical-align:${a.verticalAlign??"middle"}`,"padding:0",a.color?`color:${_(a.color)}`:"",a.backgroundColor?`background:${_(a.backgroundColor)}`:"",a.fontFamily?`font-family:${_(a.fontFamily)}`:"",a.fontSize?`font-size:${a.fontSize}pt`:"",a.fontWeight?`font-weight:${a.fontWeight}`:"",`border-top:${_(s.borderTop)}`,`border-right:${_(s.borderRight)}`,`border-bottom:${_(s.borderBottom)}`,`border-left:${_(s.borderLeft)}`].filter(Boolean).join(";")}function Yy(e,t){let n={...e.defaultCellStyle,...t?.style??{}};return["position:absolute","inset:0","display:flex","min-width:0","min-height:0","flex-direction:column","overflow:hidden",`justify-content:${Xy(n.verticalAlign??"middle")}`,`padding:${n.paddingY??5}px ${n.paddingX??8}px`].join(";")}function Xy(e){return e==="top"?"flex-start":e==="bottom"?"flex-end":"center"}import{renderToStaticMarkup as jy}from"react-dom/server";import{jsx as Ky}from"react/jsx-runtime";var Vl={renderGraphHtml:(e,t)=>jy(Ky(Io,{idSeed:t,spec:e,staticMode:!0})),renderMathHtml:St};function lr(e,t,n=Tn,r={}){return sr(e,t,n,Vl,r)}function Xo(e,t=Tn,n={}){return Yo(e,t,Vl,n)}import{jsx as Vt,jsxs as Jy}from"react/jsx-runtime";function jo({region:e,kind:t,variant:n="editor",title:r,pageNumber:o,totalPages:i,metrics:a,mathFractionSizing:s}){if(!e?.enabled||!Ua(e)||o===1&&!e.showOnFirstPage)return null;let l={left:`${a.margins.leftPx}px`,right:`${a.margins.rightPx}px`,height:`${J(e.heightMm)}px`,[t==="header"?"top":"bottom"]:`${J(e.offsetMm)}px`},u=Xo(e.overlay,{width:a.content.widthPx,height:J(e.heightMm)}),c=["page-running-text-layer","text-flow-shell",n==="print"?"print-running-text-layer page-running-print-flow-shell":""].filter(Boolean).join(" "),p=["text-flow-editor",n==="print"?"print-running-text page-running-print-flow-editor":""].filter(Boolean).join(" "),m=g=>Zy(g,r,o,i);return Jy("div",{className:`page-running-region ${t} free`,style:l,children:[Vt(qy,{svg:u}),Vt("div",{className:c,children:Vt("div",{className:p,children:e.blocks.map(g=>Vt(_e,{block:g,mathFractionSizing:s,resolveText:m},g.id))})})]})}function qy({svg:e}){return e?Vt("div",{className:"page-running-overlay-preview","aria-hidden":"true",dangerouslySetInnerHTML:{__html:e}}):null}function Zy(e,t,n,r){return e.split(/(\{title\}|\{page\}|\{total\}|\/\s*title|\/\s*page|\/\s*total)/g).map(o=>{let i=o.replace(/\s+/g,"");return i==="{title}"||i==="/title"?t:i==="{page}"||i==="/page"?String(n):i==="{total}"||i==="/total"?String(r):o}).join("")}function Qy(e){return e.numbering?.enabled!==!1}function Ul(e){let t=new Map,n=1;for(let r of e){if(r.type!=="problem"||!Qy(r))continue;let o=eg(r)??n;t.set(r.id,o),n=o+1}return t}function eg(e){let t=e.numbering?.value;return typeof t=="number"&&Number.isInteger(t)&&t>0?t:void 0}function Wl(e){return String(e)}var Yl='"Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Times New Roman", serif',ng=32,rg=21,qo=57.35,ql=1,og=9,ig=18,ag=.15,sg=.62,lg=.6,cg=.25,ug=4,dg=8,pg={cornerSquares:"box-frame--corner-squares",doubleRule:"box-frame--double-rule",titleDoubleRule:"box-frame--title-double-rule",titleBand:"box-frame--title-band",titlePlate:"box-frame--title-plate",leftBar:"box-frame--left-bar",shadow:"box-frame--shadow",horizontalRules:"box-frame--horizontal-rules",notebookRules:"box-frame--notebook-rules"},mg={cornerSquares:"data-box-corner-squares",doubleRule:"data-box-double-rule",titleDoubleRule:"data-box-title-double-rule",titleBand:"data-box-title-band",titlePlate:"data-box-title-plate",leftBar:"data-box-left-bar",shadow:"data-box-shadow",horizontalRules:"data-box-horizontal-rules",notebookRules:"data-box-notebook-rules"},Ko="#1f2937",Ut="#cbd5e1",fg="#e2e8f0",Xl="#e2e8f0",yg="#eef2f7",gg="#f1f5f9",hg="#f8fafc",xg="rgba(15, 23, 42, 0.14)",bg="#9ca3af",Sg="#b9b3a1",Pg="#706b5a",Mg=[{id:"fancybox",commandName:"fancybox",displayName:"fancybox",description:"\u672C\u6587\u3092\u6BB5\u5E45\u3044\u3063\u3071\u3044\u306E\u67A0\u3067\u56F2\u3080",aliases:["framed","framebox","fbox","box","\u67A0","\u56F2\u307F"],frame:{borderWidthPx:1.4,borderColor:"#111111",borderStyle:"solid",backgroundColor:"#ffffff",cornerStyle:"sharp",paddingPx:{top:12,right:14,bottom:12,left:14}}},{id:"itembox",commandName:"itembox",displayName:"itembox",description:"\u898B\u51FA\u3057\u30E9\u30D9\u30EB\u4ED8\u304D\u306E\u7BB1",aliases:["item","\u898B\u51FA\u3057","\u30DD\u30A4\u30F3\u30C8","\u8981\u70B9"],defaultTitle:"\u30DD\u30A4\u30F3\u30C8",frame:{borderWidthPx:1,borderColor:Ut,borderStyle:"solid",backgroundColor:"#ffffff",titleBackgroundColor:yg,titleAlign:"left",titleFontWeight:"bold",cornerStyle:"sharp",paddingPx:{top:16,right:14,bottom:12,left:14},decorations:[{type:"titlePlate",borderColor:Ut,radiusPx:3,paddingPx:{top:2,right:10,bottom:2,left:10}}]}},{id:"tcolorbox",commandName:"tcolorbox",displayName:"tcolorbox",description:"\u5E2F\u898B\u51FA\u3057\u4ED8\u304D\u306E\u7BB1",aliases:["tcbox","\u5B9A\u7406","\u5B9A\u7FA9","\u5E2F"],defaultTitle:"\u5B9A\u7406",frame:{borderWidthPx:1,borderColor:Ut,borderStyle:"solid",backgroundColor:"#ffffff",titleBackgroundColor:Xl,titleAlign:"left",titleFontWeight:"bold",cornerStyle:"sharp",paddingPx:{top:42,right:14,bottom:12,left:14},decorations:[{type:"titleBand",heightPx:32,backgroundColor:Xl}]}},{id:"tcolorbox-note",commandName:"tcolorbox-note",displayName:"tcolorbox \u30CE\u30FC\u30C8\u7F6B",description:"\u5DE6\u30EA\u30F3\u30B0\u4ED8\u304D\u306E\u30CE\u30FC\u30C8\u7BB1",aliases:["note","notebox","\u30CE\u30FC\u30C8","\u30CE\u30FC\u30C8\u7F6B","\u30EA\u30F3\u30B0","\u7F6B\u7DDA","\u672C\u6587"],frame:{borderWidthPx:1,borderColor:bg,borderStyle:"solid",backgroundColor:"#ffffff",bodyAlign:"justify",bodyFontSizePx:15,bodyLineHeight:"23.35px",cornerStyle:"sharp",paddingPx:{top:18,right:18,bottom:16,left:56},decorations:[{type:"notebookRules",baseBodyWidthPx:660,frameLeftPx:20,frameHeightPx:qo,frameStrokeOpacity:.85,bindingColor:Sg,bindingWidthPx:1,bindingXPx:20,bindingStrokeOpacity:.75,ringColor:Pg,ringWidthPx:38,ringHeightPx:12,ringStrokePx:1.2,ringGapPx:23.35,ringTopPx:8,ringCount:ql,ringLeftOverhangPx:14,minHeightPx:qo}]}},{id:"doublebox",commandName:"doublebox",displayName:"doublebox",description:"\u4E8C\u91CD\u7F6B\u7DDA\u306E\u7BB1\u3092\u633F\u5165",aliases:["double","\u4E8C\u91CD"],frame:{borderWidthPx:1.1,borderColor:"#111111",borderStyle:"solid",backgroundColor:"#ffffff",cornerStyle:"sharp",paddingPx:{top:14,right:16,bottom:14,left:16},decorations:[{type:"doubleRule",offsetPx:4,widthPx:1,color:"#111111"}]}},{id:"shadebox",commandName:"shadebox",displayName:"shadebox",description:"\u8584\u3044\u5730\u8272\u306E\u7BB1",aliases:["shade","\u80CC\u666F","\u88DC\u8DB3","\u30B3\u30E9\u30E0"],frame:{borderWidthPx:1,borderColor:Ut,borderStyle:"solid",backgroundColor:gg,cornerStyle:"round",radiusPx:3,paddingPx:{top:12,right:14,bottom:12,left:14}}},{id:"leftbar",commandName:"leftbar",displayName:"leftbar",description:"\u5DE6\u7F6B\u3067\u5F37\u8ABF\u3059\u308B\u7BB1",aliases:["\u5DE6\u7F6B","\u5F15\u7528","\u6CE8\u610F"],frame:{borderWidthPx:1,borderColor:fg,borderStyle:"solid",backgroundColor:hg,cornerStyle:"sharp",paddingPx:{top:12,right:14,bottom:12,left:18},decorations:[{type:"leftBar",widthPx:5,color:Ko}]}},{id:"dashedbox",commandName:"dashedbox",displayName:"dashedbox",description:"\u7834\u7DDA\u306E\u7BB1",aliases:["dashed","\u7834\u7DDA","\u8A18\u5165","\u30E1\u30E2"],frame:{borderWidthPx:1.2,borderColor:"#475569",borderStyle:"dashed",backgroundColor:"#ffffff",cornerStyle:"sharp",paddingPx:{top:12,right:14,bottom:12,left:14}}},{id:"ruledbox",commandName:"ruledbox",displayName:"ruledbox",description:"\u4E0A\u4E0B\u7F6B\u3060\u3051\u3067\u533A\u5207\u308B\u7BB1",aliases:["rule","\u4E0A\u4E0B\u7F6B","\u307E\u3068\u3081"],defaultTitle:"\u5B9A\u7FA9",frame:{borderWidthPx:0,borderColor:"transparent",borderStyle:"none",backgroundColor:"#ffffff",titleAlign:"left",titleFontWeight:"bold",cornerStyle:"sharp",paddingPx:{top:12,right:0,bottom:12,left:0},decorations:[{type:"horizontalRules",widthPx:1.2,color:Ko}]}},{id:"screenbox",commandName:"screenbox",displayName:"screenbox",description:"\u5F71\u4ED8\u304D\u30AB\u30FC\u30C9\u98A8\u306E\u7BB1",aliases:["screen","\u30AB\u30FC\u30C9","\u5F71","\u4F8B\u984C"],defaultTitle:"\u4F8B\u984C",frame:{borderWidthPx:1,borderColor:Ut,borderStyle:"solid",backgroundColor:"#ffffff",titleAlign:"left",titleFontWeight:"bold",cornerStyle:"round",radiusPx:3,paddingPx:{top:12,right:14,bottom:12,left:14},decorations:[{type:"shadow",offsetXPx:5,offsetYPx:5,blurPx:0,spreadPx:0,color:xg}]}},{id:"ovalbox",commandName:"ovalbox",displayName:"ovalbox",description:"\u89D2\u4E38\u306E\u7BB1",aliases:["oval","\u89D2\u4E38","\u30E9\u30D9\u30EB"],frame:{borderWidthPx:1.2,borderColor:Ko,borderStyle:"solid",backgroundColor:"#ffffff",cornerStyle:"round",radiusPx:18,paddingPx:{top:8,right:16,bottom:8,left:16}}},{id:"cornerbox",commandName:"cornerbox",displayName:"cornerbox",description:"\u56DB\u9685\u306E\u9ED2\u56DB\u89D2\u3068\u4E8C\u91CD\u30AC\u30A4\u30C9\u7F6B\u306E\u7BB1",aliases:["corner","\u89D2"],frame:{borderWidthPx:0,borderColor:"transparent",borderStyle:"none",backgroundColor:"#ffffff",titleAlign:"left",titleFontFamily:Yl,titleFontWeight:"normal",titleLineHeight:"1",bodyAlign:"left",bodyFontFamily:Yl,bodyLineHeight:"1",cornerStyle:"sharp",paddingPx:{top:24,right:24,bottom:24,left:24},decorations:[{type:"titleDoubleRule",ruleWidthPx:1,ruleColor:"#111111",guideColor:"#b8b8b8"},{type:"cornerSquares",sizePx:8,color:"#000000"}]}}];function vg(e){return Mg.find(t=>t.id===e||t.commandName===e)}function cr(e){let t=Bg(vg(e.styleId)?.frame,e.frame);return e.styleId==="cornerbox"?Og(t):t}function Og(e){let{titleFontSizePx:t,bodyFontSizePx:n,...r}=e;return{...r,...t===void 0||t===ng?{}:{titleFontSizePx:t},...n===void 0||n===rg?{}:{bodyFontSizePx:n}}}function ur(e){return e.title?ct(e.title).trim():""}function ke(e,t){return e?.decorations?.find(n=>n.type===t)}function wg(e,t){return e?.decorations?.some(n=>n.type===t)??!1}function Zl(e,t,n){let r=[e,"box-frame"];for(let o of t.decorations??[]){let i=pg[o.type];i&&r.push(i)}return Tg(n,t)&&r.push("box-frame--corner","corner-frame"),r.join(" ")}function Jl(e){let t={};for(let n of e?.decorations??[]){let r=mg[n.type];r&&(t[r]="true")}return t}function Ql(e){let t=e.paddingPx??{top:12,right:14,bottom:12,left:14},n=ke(e,"cornerSquares"),r=ke(e,"doubleRule"),o=ke(e,"titleDoubleRule"),i=ke(e,"titleBand"),a=ke(e,"titlePlate"),s=ke(e,"leftBar"),l=ke(e,"shadow"),u=ke(e,"horizontalRules"),c=ke(e,"notebookRules"),p=a?.paddingPx??{top:2,right:10,bottom:2,left:10},m=c?.frameHeightPx??c?.minHeightPx??qo,g=c?.ringLeftOverhangPx??14;return{"--sigma-doc-box-border-width":`${e.borderWidthPx??1.2}px`,"--sigma-doc-box-border-color":e.borderColor??"#111111","--sigma-doc-box-border-style":e.borderStyle??"solid","--sigma-doc-box-background":e.backgroundColor??"#ffffff","--sigma-doc-box-title-background":e.titleBackgroundColor??i?.backgroundColor??e.backgroundColor??"#ffffff",...e.titleColor?{"--sigma-doc-box-title-color":e.titleColor}:{},...e.titleAlign?{"--sigma-doc-box-title-align":e.titleAlign}:{},...e.titleFontWeight?{"--sigma-doc-box-title-weight":e.titleFontWeight==="bold"?"700":"400"}:{},...e.titleFontFamily?{"--sigma-doc-box-title-font-family":e.titleFontFamily}:{},...e.titleFontSizePx?{"--sigma-doc-box-title-font-size":`${e.titleFontSizePx}px`}:{},...e.titleLineHeight?{"--sigma-doc-box-title-line-height":e.titleLineHeight}:{},...e.bodyColor?{"--sigma-doc-box-body-color":e.bodyColor}:{},...e.bodyAlign?{"--sigma-doc-box-body-align":e.bodyAlign}:{},...e.bodyFontFamily?{"--sigma-doc-box-body-font-family":e.bodyFontFamily}:{},...e.bodyFontSizePx?{"--sigma-doc-box-body-font-size":`${e.bodyFontSizePx}px`}:{},...e.bodyLineHeight?{"--sigma-doc-box-body-line-height":e.bodyLineHeight}:{},"--sigma-doc-box-radius":`${e.cornerStyle==="round"?e.radiusPx??8:0}px`,"--sigma-doc-box-padding-top":`${t.top}px`,"--sigma-doc-box-padding-right":`${t.right}px`,"--sigma-doc-box-padding-bottom":`${t.bottom}px`,"--sigma-doc-box-padding-left":`${t.left}px`,"--sigma-doc-box-corner-size":`${n?.sizePx??0}px`,"--sigma-doc-box-corner-color":n?.color??"#000000","--sigma-doc-box-double-offset":`${r?.offsetPx??0}px`,"--sigma-doc-box-double-width":`${r?.widthPx??1}px`,"--sigma-doc-box-double-color":r?.color??e.borderColor??"#111111","--sigma-doc-box-title-rule-width":`${o?.ruleWidthPx??1}px`,"--sigma-doc-box-title-rule-color":o?.ruleColor??"#111111","--sigma-doc-box-title-guide-color":o?.guideColor??"#b8b8b8","--sigma-doc-box-title-band-height":`${i?.heightPx??32}px`,"--sigma-doc-box-title-plate-border-color":a?.borderColor??e.borderColor??"#111111","--sigma-doc-box-title-plate-radius":`${a?.radiusPx??3}px`,"--sigma-doc-box-title-plate-padding-top":`${p.top}px`,"--sigma-doc-box-title-plate-padding-right":`${p.right}px`,"--sigma-doc-box-title-plate-padding-bottom":`${p.bottom}px`,"--sigma-doc-box-title-plate-padding-left":`${p.left}px`,"--sigma-doc-box-left-bar-width":`${s?.widthPx??0}px`,"--sigma-doc-box-left-bar-color":s?.color??"#111111","--sigma-doc-box-shadow":l?`${l.offsetXPx}px ${l.offsetYPx}px ${l.blurPx??0}px ${l.spreadPx??0}px ${l.color}`:"none","--sigma-doc-box-horizontal-rule-width":`${u?.widthPx??1}px`,"--sigma-doc-box-horizontal-rule-color":u?.color??e.borderColor??"#111111","--sigma-doc-box-notebook-base-body-width":`${c?.baseBodyWidthPx??660}px`,"--sigma-doc-box-notebook-frame-left":`${c?.frameLeftPx??c?.bindingXPx??20}px`,"--sigma-doc-box-notebook-frame-height":`${m}px`,"--sigma-doc-box-notebook-frame-border-color":jl(e.borderColor??"#9ca3af",c?.frameStrokeOpacity),"--sigma-doc-box-notebook-binding-color":jl(c?.bindingColor??"#b9b3a1",c?.bindingStrokeOpacity),"--sigma-doc-box-notebook-binding-width":`${c?.bindingWidthPx??1}px`,"--sigma-doc-box-notebook-binding-x":`${c?.bindingXPx??20}px`,"--sigma-doc-box-notebook-ring-color":c?.ringColor??"#706b5a","--sigma-doc-box-notebook-ring-width":`${c?.ringWidthPx??38}px`,"--sigma-doc-box-notebook-ring-height":`${c?.ringHeightPx??12}px`,"--sigma-doc-box-notebook-ring-left-overhang":`${g}px`,"--sigma-doc-box-notebook-ring-stroke":`${c?.ringStrokePx??1.2}px`,"--sigma-doc-box-notebook-ring-gap":`${c?.ringGapPx??23.35}px`,"--sigma-doc-box-notebook-ring-top":`${c?.ringTopPx??8}px`,"--sigma-doc-box-notebook-ring-count":String(c?.ringCount??ql),"--sigma-doc-box-notebook-min-height":`${c?.minHeightPx??m}px`}}function kg(e){let t=Number.isFinite(e)?Math.max(0,e):0;return Math.min(ig,Math.max(og,t*ag))}function Zo(e){if(typeof e!="number"||!Number.isFinite(e)||e<=0)return{};let t=Ot(e),n=Ot(kg(t)),r=Ot(Math.min(dg,Math.max(ug,n*lg))),o=Ot(Math.max(r,n*sg)),i=Ot(r*cg),a=Ot(Math.max(0,o-r/2-i));return{"--corner-frame-reference-height":`${t}px`,"--corner-frame-fold-size":`${n}px`,"--corner-frame-corner-size":`${r}px`,"--corner-frame-guide-inset-x":`${n}px`,"--corner-frame-guide-side-y":`${n}px`,"--corner-frame-rule-x":`${o}px`,"--corner-frame-rule-side-x":`${o}px`,"--corner-frame-rule-y":`${o}px`,"--corner-frame-rule-side-y":`${o}px`,"--corner-frame-corner-x":`${a}px`,"--corner-frame-corner-y":`${a}px`}}function ec(e,t){let n=new Set,r=new Map,o=e instanceof Document?e:e.ownerDocument;if(!o?.head)return()=>{};let i=o.createElement("style");i.setAttribute("data-cornerbox-reference-heights","true"),o.head.appendChild(i);let a=()=>{i.textContent=Array.from(r,([p,m])=>`${p}{${m}}`).join(`
12
+ `)},s=p=>{let m=Rg(p);if(!m)return;let g=Object.entries(Zo(p.getBoundingClientRect().height)).map(([h,b])=>`${h}:${b}`).join(";");!g||r.get(m)===g||(r.set(m,g),a())},l=typeof ResizeObserver>"u"?null:new ResizeObserver(p=>{for(let m of p)m.target instanceof HTMLElement&&m.target.getAttribute("data-corner-reference-height")!=="explicit"&&s(m.target)}),u=()=>{for(let p of Array.from(n))o.contains(p)||(l?.unobserve(p),n.delete(p));e.querySelectorAll(t).forEach(p=>{p.getAttribute("data-corner-reference-height")==="explicit"||n.has(p)||(n.add(p),s(p),l?.observe(p))})};u();let c=typeof MutationObserver>"u"?null:new MutationObserver(u);return c?.observe(e,{childList:!0,subtree:!0}),()=>{c?.disconnect(),l?.disconnect(),i.remove(),n.clear(),r.clear()}}function Tg(e,t){return e==="cornerbox"&&wg(t,"titleDoubleRule")}function Bg(e,t){return{...e??{},...t??{},paddingPx:{...e?.paddingPx??{top:12,right:14,bottom:12,left:14},...t?.paddingPx??{}},decorations:t?.decorations??e?.decorations}}function jl(e,t){if(t===void 0)return e;let n=Math.min(1,Math.max(0,t)),r=Ag(e);return r?`rgb(${r.r} ${r.g} ${r.b} / ${n})`:e}function Ot(e){return Math.round(e*100)/100}function Rg(e){let t=e.getAttribute("data-sigma-doc-id");if(t)return`[data-sigma-doc-id="${Kl(t)}"]`;let n=e.getAttribute("data-box-source-id");return n?`[data-box-source-id="${Kl(n)}"]`:null}function Kl(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function Ag(e){let t=e.trim(),n=/^#([0-9a-fA-F]{3})$/.exec(t);if(n){let i=n[1]??"";return{r:Number.parseInt(`${i[0]}${i[0]}`,16),g:Number.parseInt(`${i[1]}${i[1]}`,16),b:Number.parseInt(`${i[2]}${i[2]}`,16)}}let r=/^#([0-9a-fA-F]{6})$/.exec(t);if(!r)return null;let o=r[1]??"";return{r:Number.parseInt(o.slice(0,2),16),g:Number.parseInt(o.slice(2,4),16),b:Number.parseInt(o.slice(4,6),16)}}var Ig="fancybox",Cg=[{id:"fancybox",commandName:"fancybox",label:"\u6A19\u6E96",description:"\u7D30\u3044\u4E00\u91CD\u67A0"},{id:"doublebox",commandName:"doublebox",label:"\u4E8C\u91CD",description:"\u4E8C\u91CD\u7F6B\u7DDA"},{id:"cornerbox",commandName:"cornerbox",label:"\u89D2\u4ED8\u304D",description:"\u9ED2\u3044\u89D2\u3068\u4E8C\u91CD\u30AC\u30A4\u30C9"}],Eg=new Set(Cg.map(e=>e.id));function Jo(e){return Eg.has(e??"")?e:Ig}function tc(e){return Jo(e.frame?.styleId)}function nc(e,t){let n=Jo(t);return[e,"box-frame",n==="doublebox"?"box-frame--double-rule":"",n==="cornerbox"?"box-frame--corner corner-frame":""].filter(Boolean).join(" ")}function rc(e){let t=Jo(e);return t==="doublebox"?{x:3.4,y:3}:t==="cornerbox"?{x:8,y:6.4}:{x:3,y:2.5}}import{useCallback as XO,useEffect as jO,useState as KO}from"react";import{useCallback as mw,useLayoutEffect as Qo,useMemo as Ge,useRef as oc,useState as ic}from"react";import{jsx as A,jsxs as Yt}from"react/jsx-runtime";var Lg=12,Ng=".print-box-block.box-frame--corner[data-box-style='cornerbox']",ac=12;function dc({document:e,displayMode:t="vertical",includePrintPageStyle:n=!0,maxPages:r,stackClassName:o,renderPageFrame:i}){let a=e.metadata.mathFractionSizing??"uniform",s=e.pageLayout,l=Bn(s),u=l.page.heightPx+co,c=Ge(()=>Fg(e.content),[e.content]),p=oc(null),m=oc(null),g=Ge(()=>c.map(T=>$g(T)),[c]),h=Ge(()=>ni(c,g,g,l.flow.columnCount,l.content.heightPx,0,new Map,l.flow.columnGapMm),[g,l.content.heightPx,l.flow.columnCount,l.flow.columnGapMm,c]),b=Ge(()=>JSON.stringify(c),[c]),S=Ge(()=>JSON.stringify(s),[s]),M=`${b}
13
+ ${S}`,L=Ge(()=>new Map,[]),[w,B]=ic(null),[Y,f]=ic(0),P=w?.key===M?w:null,Q=P?.pages??h,te=P?.blockRects??L,K=Ge(()=>Kg(s.overlay,te),[s.overlay,te]),x=Ge(()=>qg(Q,K,l.flow.columnCount,l.page.heightPx,u),[Q,l.flow.columnCount,l.page.heightPx,u,K]),I=typeof r=="number"?x.slice(0,Math.max(1,r)):x,O={"--print-page-width":`${l.page.widthMm}mm`,"--print-page-height":`${l.page.heightMm}mm`,"--print-margin-top":`${l.margins.topPx}px`,"--print-margin-right":`${l.margins.rightPx}px`,"--print-margin-bottom":`${l.margins.bottomPx}px`,"--print-margin-left":`${l.margins.leftPx}px`,"--print-column-count":String(l.flow.columnCount),"--print-column-gap":`${l.flow.columnGapMm}mm`,"--print-measure-column-width":`${l.flow.columnWidthPx}px`,"--print-measure-content-width":`${l.content.widthPx}px`};return Qo(()=>{let T=p.current;if(T)return ec(T,Ng)},[b,S]),Qo(()=>{let T=m.current;if(!T)return;let C=!0,R=null,$=()=>{if(!C||R!==null)return;R=(typeof window<"u"&&typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame.bind(window):D=>window.setTimeout(D,0))(()=>{R=null,C&&f(D=>D+1)})},N=typeof ResizeObserver=="function"?new ResizeObserver($):null;return N?.observe(T),typeof document<"u"&&document.fonts&&document.fonts.ready.then($),()=>{C=!1,N?.disconnect(),R!==null&&typeof window<"u"&&(window.cancelAnimationFrame?.(R),window.clearTimeout(R))}},[b,S]),Qo(()=>{let T=m.current;if(!T)return;let C=Wg(T,c),R=C.map(z=>z.height),$=C.map(z=>z.flowHeight),N=C.map(z=>z.descendantRects),V=Hg(N),D=ni(c,R,$,l.flow.columnCount,l.content.heightPx,0,V,l.flow.columnGapMm),X=Vg(D,c,R,$,l.margins.topPx,l.margins.leftPx,l.flow.columnWidthPx,l.flow.columnGapPx,u,0,N,V);B(z=>z?.key===M&&Jg(z.blockRects,X)&&Zg(z.pages,D)?z:{key:M,pages:D,blockRects:X})},[b,S,M,Y,l.content.heightPx,l.flow.columnCount,l.flow.columnGapPx,l.flow.columnGapMm,l.flow.columnWidthPx,l.margins.leftPx,l.margins.topPx,u,c]),Yt("article",{ref:p,className:["print-page-stack",`layout-${t}`,o].filter(Boolean).join(" "),"data-print-preview-layout":t,"data-print-preview-max-pages":typeof r=="number"?String(r):void 0,"data-print-preview-page-count":String(x.length),style:O,children:[n?A("style",{children:`@media print { @page { size: ${l.page.widthMm}mm ${l.page.heightMm}mm; margin: 0; } }`}):null,I.map(T=>{let C=K?.overlaySnapshot?lr(K.overlaySnapshot.shapes,K.overlaySnapshot.assets,{width:l.page.widthPx,height:l.page.heightPx,offsetY:(T.number-1)*u},{stackLayer:"background",viewportPaddingPx:0}):void 0,R=K?.overlaySnapshot?lr(K.overlaySnapshot.shapes,K.overlaySnapshot.assets,{width:l.page.widthPx,height:l.page.heightPx,offsetY:(T.number-1)*u},{stackLayer:"foreground",viewportPaddingPx:0}):void 0,$=Yt("section",{className:"print-a4-page",style:O,children:[A(jo,{region:s.header,kind:"header",variant:"print",title:e.metadata.title,pageNumber:T.number,totalPages:x.length,metrics:l,mathFractionSizing:a}),A(jo,{region:s.footer,kind:"footer",variant:"print",title:e.metadata.title,pageNumber:T.number,totalPages:x.length,metrics:l,mathFractionSizing:a}),C&&A("div",{className:"print-page-overlay-layer background",dangerouslySetInnerHTML:{__html:C}}),Yt("div",{className:"print-page-content-layer",children:[mc(T).map((N,V)=>A("div",{className:"print-page-full-span-block",children:A(Te,{unit:N,columnGapMm:l.flow.columnGapMm,mathFractionSizing:a})},`${T.id}-full-${N.id}-${V}`)),A("div",{className:"print-page-columns",children:T.columns.map(N=>A("div",{className:"print-page-column",children:ri(N).map((V,D)=>A(Te,{unit:V,columnGapMm:l.flow.columnGapMm,mathFractionSizing:a},`${V.id}-${D}`))},`${T.id}-${N.id}`))})]}),R&&A("div",{className:"print-page-overlay-layer foreground",dangerouslySetInnerHTML:{__html:R}})]},T.id);return i?i({page:T,totalPages:x.length,pageNode:$}):$}),A("div",{className:"print-measure-layer",ref:m,style:O,"aria-hidden":"true",children:A("div",{className:"print-measure-column",children:c.map((T,C)=>A("div",{"data-print-measure-index":C,style:qe(T)?{width:"var(--print-measure-content-width)"}:void 0,children:A(Te,{unit:T,columnGapMm:l.flow.columnGapMm,mathFractionSizing:a})},`${T.id}-${C}`))})})]})}function Fg(e){let t=Ul(e);return e.flatMap(n=>{if(n.type!=="problem")return[{type:"block",id:n.id,block:n,pageBreak:n.pageBreak}];let r=t.get(n.id),o=Rn.map(l=>({area:l,blocks:n[l],minHeightMm:n.areaLayout?.[l]?.minHeightMm,columnSpan:n.areaLayout?.[l]?.columnSpan})).filter(({area:l,blocks:u,minHeightMm:c})=>l==="lead"?typeof r=="number"||u.length>0||!!c:l==="prompt"||u.length>0||!!c),i=o.filter(({area:l})=>ei(l)),a=i[0]?.area,s=i.at(-1)?.area;return o.map((l,u)=>({type:"problemArea",id:`${n.id}:${l.area}`,problemId:n.id,area:l.area,blocks:l.blocks,minHeightMm:l.minHeightMm,problemNumber:r,numberFontSize:th(n),hasFrame:n.frame?.enabled===!0&&ei(l.area),frameStyleId:n.frame?.enabled===!0&&ei(l.area)?tc(n):void 0,isFirstProblemArea:u===0,isLastProblemArea:u===o.length-1,isFirstProblemFrameArea:l.area===a,isLastProblemFrameArea:l.area===s,columnSpan:l.columnSpan,pageBreak:_g(n.pageBreak,u,o.length)}))})}function _g(e,t,n){if(!e)return;let r={...e};return t>0&&delete r.breakBefore,t<n-1&&delete r.breakAfter,Object.keys(r).length>0?r:void 0}function ei(e){return e==="prompt"}function sc(e){return e.type==="problemArea"&&hl({isFullSpan:e.columnSpan==="full",isFramedArea:e.hasFrame,blocks:e.blocks})}function $g(e){return e.type==="block"?Ne(e.block):e.type==="boxFragment"||e.type==="layoutSectionFragment"?e.estimatedHeightPx:e.type==="blockSlice"?e.sliceHeight:e.type==="problemAreaFragment"?e.estimatedHeightPx:Math.max(e.blocks.reduce((t,n)=>t+Ne(n),0),(e.minHeightMm??0)*st)}function ni(e,t,n,r,o,i,a,s){let l=[],u=1,c=dr(u,r).columns,p=0,m=()=>c.some(x=>x.blocks.length>0),g=()=>c.some(x=>x.blocks.some(I=>!qe(I))),h=()=>c[p],b=()=>Math.max(0,o-(u===1?i:0)),S=(x=!1)=>{!x&&!m()||(l.push({id:`page_${u}`,number:u,blocks:c.flatMap(I=>I.blocks),columns:c,estimatedContentHeightPx:c.reduce((I,O)=>I+O.estimatedContentHeightPx,0),oversizedBlockIds:c.flatMap(I=>I.oversizedBlockIds)}),u+=1,c=dr(u,r).columns,p=0)},M=()=>{if(p<r-1){p+=1;return}S()},L=()=>{M()},w=x=>x.blocks.some(I=>!qe(I)),B=()=>Math.max(0,b()-h().estimatedContentHeightPx),Y=(x,I,O=I)=>{let T=h();T.blocks.push(x),T.estimatedContentHeightPx+=Math.max(I,O),I>b()&&T.oversizedBlockIds.push(x.id)},f=x=>{let I=e[x];if(sc(I)||I.type!=="problemArea"||!I.isFirstProblemArea||!w(h()))return;let O=0;for(let C=x;C<e.length;C+=1){let R=e[C];if(R.type!=="problemArea"||R.problemId!==I.problemId)break;if(qe(R)||C>x&&R.pageBreak?.breakBefore==="always")return;O+=Math.max(t[C]||0,n[C]??0)}let T=p<r-1?b():o;O>B()+.5&&O<=T+.5&&M()},P=(x,I)=>{let O=x.block;if(O.type!=="boxBlock"||O.blocks.length===0||!tr(O.blocks)&&I<=B()+.5)return!1;let T=[],C=pc(O),R=O.blocks.map(V=>Wt(V,a)),$=0,N=0;for(;$<O.blocks.length;){w(h())&&B()<Math.min(72,b()*.22)&&M();let V=R[$]??0;w(h())&&C+V>B()+.5&&C+V<=b()+.5&&M();let D=[],X=C;for(;$<O.blocks.length&&!(D.length>0&&O.blocks[$].pageBreak?.breakBefore==="always");){let W=R[$]??0;if(!(D.length===0||X+W<=Math.max(C+W,B()+.5))||(D.push(O.blocks[$]),X+=W,$+=1,X>=B()-.5))break}D.length===0&&(D.push(O.blocks[$]),X+=R[$]??0,$+=1);let z={type:"boxFragment",id:`${O.id}:fragment:${N}`,sourceId:O.id,block:O,blocks:D,fragmentRole:"middle",estimatedHeightPx:X,totalHeight:I,includeTitle:N===0,pageBreak:N===0?x.pageBreak:void 0};T.push(z),Y(z,X),N+=1,$<O.blocks.length&&M()}return T.forEach((V,D)=>{V.fragmentRole=T.length===1?"single":D===0?"first":D===T.length-1?"last":"middle"}),x.pageBreak?.breakAfter==="always"&&L(),!0},Q=(x,I)=>{let O=Dg(x.block,I,a),T=[],C=0,R=0;for(let $=0;C<I-.5&&$<400;$+=1){w(h())&&B()<Math.min(48,b()*.2)&&M();let N=Math.max(1,B()),V=I-C,D=V<=N+.5?V:zg(N,O,C,I),X={type:"blockSlice",id:`${x.id}:slice:${R}`,sourceId:x.id,block:x.block,sliceTop:C,sliceHeight:D,totalHeight:I,fragmentRole:"middle",pageBreak:R===0?x.pageBreak:void 0};T.push(X),Y(X,D),C+=D,R+=1,C<I-.5&&M()}T.forEach(($,N)=>{$.fragmentRole=T.length===1?"single":N===0?"first":N===T.length-1?"last":"middle"}),x.pageBreak?.breakAfter==="always"&&L()},te=x=>{if(!sc(x)||x.blocks.length===0)return!1;let I=x.columnSpan==="full",O=()=>{I?S():M()},T=rc(x.frameStyleId),C=x.hasFrame?T.y*2*st:0,R=h(),$=R.estimatedContentHeightPx,N=[],V=[],D=[],X=C,z=!1,W=(Z,ne)=>{let De=N.length,me={type:"problemAreaFragment",id:`${x.id}:area-fragment:${De}`,sourceId:x.id,problemId:x.problemId,area:x.area,blocks:Z,fragmentRole:"middle",estimatedHeightPx:ne,minHeightMm:x.minHeightMm,problemNumber:x.problemNumber,numberFontSize:x.numberFontSize,hasFrame:x.hasFrame,frameStyleId:x.frameStyleId,columnSpan:x.columnSpan,isFirstProblemArea:x.isFirstProblemArea,isLastProblemArea:x.isLastProblemArea,pageBreak:De===0?x.pageBreak:void 0};if(N.push(me),I){g()&&S(),m()&&h().estimatedContentHeightPx+ne>b()+.5&&S(),c[0].blocks.push(me);for(let wr of c)wr.estimatedContentHeightPx+=ne;V.push(c[0])}else V.push(h()),Y(me,ne)},ce=()=>{D.length!==0&&(W(D,X),D=[],X=C)};for(let Z of x.blocks){if(Z.pageBreak?.breakBefore==="always"){let me=N.length>0||D.length>0||!I&&(w(h())||p>0);ce(),me&&O()}let ne=Wt(Z,a);if(Z.type==="layoutSection"){ce();let me=ne+C;me>B()+.5&&me<=o+.5&&O(),W([Z],me),Z.pageBreak?.breakAfter==="always"&&O();continue}if(ne>o+.5){ce(),N.length===0&&(z=!0),Q({type:"block",id:Z.id,block:Z,pageBreak:Z.pageBreak},ne);continue}let De=Math.max(0,B()-X);(w(h())||D.length>0)&&ne>De+.5&&ne+C<=o+.5&&(ce(),O()),D.push(Z),X+=ne,Z.pageBreak?.breakAfter==="always"&&(ce(),O())}return ce(),N.forEach((Z,ne)=>{Z.fragmentRole=z?ne===N.length-1?"last":"middle":N.length===1?"single":ne===0?"first":ne===N.length-1?"last":"middle"}),(x.minHeightMm??0)>0&&N.length>0&&V.every(Z=>Z===R)&&h()===R&&(R.estimatedContentHeightPx=Math.max(R.estimatedContentHeightPx,$+(x.minHeightMm??0)*st)),x.pageBreak?.breakAfter==="always"&&L(),!0},K=(x,I)=>{let O=x.block;if(O.type!=="layoutSection"||O.children.length===0)return!1;let T=O.children.some(z=>z.type==="boxBlock"),C=tr(O.children);if(!T&&!C&&I<=b()+.5)return!1;let R=yc(O.layout.columnCount),$=s,N=O.children.map(z=>({type:"block",id:z.id,block:z,pageBreak:z.pageBreak})),V=O.children.map(z=>Wt(z,a,Math.max(12,Math.floor(54/R)))),X=ni(N,V,V,R,b(),0,a,$).map((z,W)=>({type:"layoutSectionFragment",id:`${O.id}:layout-fragment:${W}`,sourceId:O.id,block:O,columns:z.columns,fragmentRole:"middle",estimatedHeightPx:Math.max(32,...z.columns.map(ce=>ce.estimatedContentHeightPx)),columnGapMm:$,pageBreak:W===0?x.pageBreak:void 0}));return X.forEach((z,W)=>{z.fragmentRole=X.length===1?"single":W===0?"first":W===X.length-1?"last":"middle",w(h())&&h().estimatedContentHeightPx+z.estimatedHeightPx>b()+.5&&M(),Y(z,z.estimatedHeightPx),W<X.length-1&&M()}),x.pageBreak?.breakAfter==="always"&&L(),!0};return e.forEach((x,I)=>{let O=t[I]||0,T=n[I]??O;if(m()&&x.pageBreak?.breakBefore==="always"&&L(),f(I),x.type==="problemArea"&&te(x))return;if(qe(x)){g()&&S(),m()&&h().estimatedContentHeightPx+O>b()&&S(),c[0].blocks.push(x);for(let $ of c)$.estimatedContentHeightPx+=Math.max(O,T),O>b()&&$.oversizedBlockIds.push(x.id);x.pageBreak?.breakAfter==="always"&&L();return}let C=x.type==="block"&&x.block.type==="boxBlock"&&x.block.blocks.length>0,R=x.type==="block"&&(x.block.type==="boxBlock"?Gg(x.block,o,a):x.block.type!=="layoutSection"&&O>o+.5);if(C||R||(O>b()+.5&&m()?S():w(h())&&h().estimatedContentHeightPx+O>b()?M():!w(h())&&h().estimatedContentHeightPx>.5&&h().estimatedContentHeightPx+O>b()&&S()),R&&x.type==="block"){Q(x,O);return}x.type==="block"&&P(x,O)||x.type==="block"&&K(x,O)||(Y(x,O,T),x.pageBreak?.breakAfter==="always"&&L())}),S(),l.length>0?l:[dr(1,r)]}function pc(e){let n=cr(e).paddingPx??{top:12,right:14,bottom:12,left:14},o=ur(e)?24:0;return n.top+n.bottom+o}function Gg(e,t,n){let r=pc(e);return e.blocks.some(o=>r+Wt(o,n)>t+.5)}function Dg(e,t,n){if(e.type!=="boxBlock")return[];let o=cr(e).paddingPx??{top:12,right:14,bottom:12,left:14},i=ur(e),a=o.top+(i?24:0),s=[];for(let l of e.blocks)a+=Wt(l,n),a>.5&&a<t-.5&&s.push(Math.round(a));return s}function zg(e,t,n,r){let o=Math.min(Math.max(1,e),r-n),i=n+o,a=n+Math.min(24,Math.max(8,o*.25)),s=t.filter(l=>l>a+.5&&l<=i-.5).at(-1);return s?Math.max(1,s-n):o}function Wt(e,t,n){return t.get(e.id)??Ne(e,n)}function Hg(e){let t=new Map;return e.forEach(n=>{n.forEach(r=>{t.set(r.id,r.height??0)})}),t}function Vg(e,t,n,r,o,i,a,s,l,u,c,p){let m=new Map(t.map((S,M)=>[S.id,n[M]||0])),g=new Map(t.map((S,M)=>[S.id,r[M]??n[M]??0])),h=new Map(t.map((S,M)=>[S.id,c[M]??[]])),b=new Map;for(let S of e){let M=(S.number-1)*l,w=S.number===1?u:0;for(let B of mc(S)){let Y=pr(B,m,p),f={id:B.id,top:M+o+w,left:i,width:a*Math.max(1,S.columns.length)+s*Math.max(0,S.columns.length-1),height:Y};b.set(B.id,f);for(let P of h.get(B.id)??[])b.set(P.id,ti(P,f.top,f.left));w+=lc(B,m,g,p)}for(let B of S.columns){let Y=i+(B.number-1)*(a+s),f=w;for(let P of ri(B)){let Q=pr(P,m,p),te={id:P.id,top:M+o+f,left:Y,width:a,height:Q};if(b.set(P.id,te),P.type==="blockSlice"&&(P.fragmentRole==="first"||P.fragmentRole==="single")&&b.set(P.sourceId,{...te,id:P.sourceId,height:P.totalHeight}),P.type==="problemAreaFragment"){let K=h.get(P.sourceId)??[];if(P.fragmentRole==="first"||P.fragmentRole==="single"){let R=m.get(P.sourceId)??te.height;if(b.set(P.sourceId,{...te,id:P.sourceId,height:R}),P.isFirstProblemArea){let $=K.find(N=>N.id===P.problemId);b.set(P.problemId,{...te,id:P.problemId,height:$?.height??R})}}let x=Ug(P.blocks),I=K.find(R=>R.id===P.blocks[0]?.id),O=I?.top??0,C=P.area==="lead"&&typeof P.problemNumber=="number"&&(P.fragmentRole==="first"||P.fragmentRole==="single")?0:I?.left??0;for(let R of K)x.has(R.id)&&b.set(R.id,ti(R,te.top-O,te.left,C))}else for(let K of h.get(P.id)??[])b.set(K.id,ti(K,te.top,te.left));f+=lc(P,m,g,p)}}}return b}function ti(e,t,n,r=0){return{...e,top:t+e.top,left:n+(e.left??0)-r,lines:e.lines?.map(o=>({...o,top:t+o.top,left:typeof o.left=="number"?n+o.left-r:o.left}))}}function Ug(e){let t=new Set,n=r=>{if(t.add(r.id),r.type==="list"){for(let o of r.items)t.add(o.id),o.nested?.forEach(n);return}if(r.type==="layoutSection"){r.children.forEach(n);return}if(r.type==="boxBlock"){r.blocks.forEach(n);return}r.type==="problem"&&(r.lead.forEach(n),r.prompt.forEach(n),r.hints.forEach(n),r.solution.forEach(n))};return e.forEach(n),t}function pr(e,t,n){return e.type==="boxFragment"||e.type==="layoutSectionFragment"||e.type==="problemAreaFragment"?e.estimatedHeightPx:e.type==="blockSlice"?e.sliceHeight:t.get(e.id)??n.get(e.id)??0}function lc(e,t,n,r){return e.type==="boxFragment"||e.type==="layoutSectionFragment"||e.type==="blockSlice"||e.type==="problemAreaFragment"?pr(e,t,r):Math.max(pr(e,t,r),n.get(e.id)??0)}function Wg(e,t){let n=t.map((r,o)=>{let i=e.querySelector(`[data-print-measure-index="${o}"]`);if(!i)return null;let a=i.getBoundingClientRect();return{element:i,height:a.height,top:a.top,descendantRects:jg(i,r.id)}});return n.map((r,o)=>{if(!r)return{height:0,flowHeight:0,descendantRects:[]};let i=n.slice(o+1).find(s=>s!==null),a=i?Math.max(r.height,i.top-r.top):Yg(r.element,r.height);return{height:r.height,flowHeight:a,descendantRects:r.descendantRects}})}function Yg(e,t){let n=Xg(getComputedStyle(e).marginBottom);return t+n}function Xg(e){let t=Number.parseFloat(e);return Number.isFinite(t)?t:0}function qe(e){return(e.type==="problemArea"||e.type==="problemAreaFragment")&&e.columnSpan==="full"}function mc(e){return e.columns[0]?.blocks.filter(qe)??[]}function ri(e){return e.blocks.filter(t=>!qe(t))}function jg(e,t){let n=e.getBoundingClientRect(),r=new Set([t]),o=[];return e.querySelectorAll("[data-sigma-doc-id]").forEach(i=>{let a=i.getAttribute("data-sigma-doc-id");if(!a||r.has(a))return;r.add(a);let s=i.getBoundingClientRect();o.push({id:a,top:s.top-n.top,left:s.left-n.left,width:s.width,height:s.height,lines:ns(i,n,1,1)})}),o}function Kg(e,t){if(!e?.overlaySnapshot)return e;let n=ue(e.overlaySnapshot),r=Hr(n.shapes,t);return{...e,overlaySnapshot:{...n,shapes:r}}}function qg(e,t,n,r,o){let i=t?.overlaySnapshot?ue(t.overlaySnapshot):null;if(!i)return e;let a=i.shapes.reduce((l,u)=>{if(u.hidden)return l;let c=ge(u);return Math.max(l,c.y+c.h)},0),s=a>r+ac?Math.ceil((a-r-ac)/o)+1:1;return s<=e.length?e:[...e,...Array.from({length:s-e.length},(l,u)=>{let c=e.length+u+1;return dr(c,n)})]}function dr(e,t){return{id:`page_${e}`,number:e,blocks:[],columns:Array.from({length:Math.max(1,t)},(n,r)=>({id:`column_${r+1}`,number:r+1,blocks:[],estimatedContentHeightPx:0,oversizedBlockIds:[]})),estimatedContentHeightPx:0,oversizedBlockIds:[]}}function Zg(e,t){return!e||e.length!==t.length?!1:e.every((n,r)=>{let o=t[r];return n.columns.length===o.columns.length&&n.columns.every((i,a)=>{let s=o.columns[a];return i.blocks.length===s.blocks.length&&i.blocks.every((l,u)=>fc(l,s.blocks[u]))})})}function fc(e,t){return e.id!==t.id||e.type!==t.type?!1:e.type==="boxFragment"&&t.type==="boxFragment"?e.fragmentRole===t.fragmentRole&&Math.abs(e.estimatedHeightPx-t.estimatedHeightPx)<.5&&Math.abs(e.totalHeight-t.totalHeight)<.5&&e.blocks.length===t.blocks.length&&e.blocks.every((n,r)=>n.id===t.blocks[r].id):e.type==="layoutSectionFragment"&&t.type==="layoutSectionFragment"?e.fragmentRole===t.fragmentRole&&e.columns.length===t.columns.length&&e.columns.every((n,r)=>{let o=t.columns[r];return n.blocks.length===o.blocks.length&&n.blocks.every((i,a)=>fc(i,o.blocks[a]))}):e.type==="blockSlice"&&t.type==="blockSlice"?e.fragmentRole===t.fragmentRole&&Math.abs(e.sliceTop-t.sliceTop)<.5&&Math.abs(e.sliceHeight-t.sliceHeight)<.5:e.type==="problemAreaFragment"&&t.type==="problemAreaFragment"?e.fragmentRole===t.fragmentRole&&Math.abs(e.estimatedHeightPx-t.estimatedHeightPx)<.5&&e.blocks.length===t.blocks.length&&e.blocks.every((n,r)=>n.id===t.blocks[r].id):!0}function Jg(e,t){if(e.size!==t.size)return!1;for(let[n,r]of t){let o=e.get(n);if(!o||Math.abs(o.top-r.top)>.5||Math.abs((o.left??0)-(r.left??0))>.5||Math.abs((o.width??0)-(r.width??0))>.5||Math.abs((o.height??0)-(r.height??0))>.5)return!1}return!0}function Te({unit:e,columnGapMm:t,mathFractionSizing:n}){if(e.type==="problemArea")return A(uc,{problemId:e.problemId,area:e.area,minHeightMm:e.minHeightMm,problemNumber:e.problemNumber,numberFontSize:e.numberFontSize,hasFrame:e.hasFrame,frameStyleId:e.frameStyleId,isFirstProblemArea:e.isFirstProblemArea,isFirstProblemFrameArea:e.isFirstProblemFrameArea,isLastProblemFrameArea:e.isLastProblemFrameArea,columnGapMm:t,mathFractionSizing:n,blocks:e.blocks});if(e.type==="problemAreaFragment"){let o=e.fragmentRole==="single"||e.fragmentRole==="first",i=e.fragmentRole==="single"||e.fragmentRole==="last";return A(uc,{problemId:e.problemId,area:e.area,minHeightMm:e.fragmentRole==="single"?e.minHeightMm:void 0,problemNumber:e.problemNumber,numberFontSize:e.numberFontSize,hasFrame:e.hasFrame,frameStyleId:e.frameStyleId,isFirstProblemArea:e.isFirstProblemArea,isFirstProblemFrameArea:e.hasFrame&&o,isLastProblemFrameArea:e.hasFrame&&i,columnGapMm:t,mathFractionSizing:n,blocks:e.blocks,fragmentRole:e.fragmentRole,sourceId:e.sourceId})}if(e.type==="boxFragment")return A(cc,{block:e.block,columnGapMm:t,fragmentBlocks:e.blocks,fragmentRole:e.fragmentRole,includeTitle:e.includeTitle,cornerReferenceHeightPx:e.totalHeight,mathFractionSizing:n});if(e.type==="layoutSectionFragment")return A(Qg,{unit:e,mathFractionSizing:n});if(e.type==="blockSlice")return A("div",{className:`print-block-slice print-block-slice-${e.fragmentRole}`,"data-block-slice":e.fragmentRole,"data-block-source-id":e.sourceId,style:{height:`${Math.round(e.sliceHeight)}px`,overflow:"hidden"},children:A("div",{className:"print-block-slice-inner",style:{marginTop:`${-Math.round(e.sliceTop)}px`},children:A(Te,{unit:{type:"block",id:e.sourceId,block:e.block},columnGapMm:t,mathFractionSizing:n})})});let{block:r}=e;if(r.type==="section")return A("h1",{"data-sigma-doc-id":r.id,className:"print-section",style:{textAlign:r.align??"left",lineHeight:r.lineHeight},children:r.title});if(r.type==="heading")return A(_e,{block:r,mathFractionSizing:n});if(r.type==="paragraph")return A(_e,{block:r,mathFractionSizing:n});if(r.type==="list")return A(_e,{block:r,mathFractionSizing:n});if(r.type==="boxBlock")return A(cc,{block:r,columnGapMm:t,mathFractionSizing:n});if(r.type==="layoutSection"){let o=yc(r.layout.columnCount),i=t;return A("section",{"data-sigma-doc-id":r.id,className:"print-layout-section",style:{"--print-layout-section-column-count":String(o),"--print-layout-section-column-gap":`${i}mm`},children:r.children.map(a=>A(Te,{unit:{type:"block",id:a.id,block:a,pageBreak:a.pageBreak},columnGapMm:i,mathFractionSizing:n},a.id))})}}function Qg({unit:e,mathFractionSizing:t}){let n=e.columns.length,r={"--print-layout-section-column-count":String(n),"--print-layout-section-column-gap":`${e.columnGapMm}mm`,display:"grid",gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`,columnGap:`${e.columnGapMm}mm`};return A("section",{"data-sigma-doc-id":e.fragmentRole==="single"||e.fragmentRole==="first"?e.sourceId:void 0,"data-layout-section-source-id":e.sourceId,"data-layout-section-fragment":e.fragmentRole,className:`print-layout-section print-layout-section-fragment print-layout-section-fragment-${e.fragmentRole}`,style:r,children:e.columns.map(o=>A("div",{className:"print-layout-section-column",style:{minWidth:0},children:ri(o).map((i,a)=>A(Te,{unit:i,columnGapMm:e.columnGapMm,mathFractionSizing:t},`${i.id}-${a}`))},`${e.id}-${o.id}`))})}function cc({block:e,columnGapMm:t,mathFractionSizing:n,fragmentBlocks:r,fragmentRole:o,includeTitle:i=!0,cornerReferenceHeightPx:a}){let s=cr(e),l=ur(e),u=r??e.blocks,c=o?` print-box-fragment print-box-fragment-${o}`:"",p={...Ql(s),...Zo(a)};return Yt("section",{"data-sigma-doc-id":!o||o==="single"||o==="first"?e.id:void 0,"data-box-source-id":o?e.id:void 0,"data-box-fragment":o,"data-corner-reference-height":a?"explicit":void 0,className:`${Zl("print-box-block",s,e.styleId)}${c}`,"data-box-style":e.styleId,...Jl(s),style:p,children:[A("span",{className:"print-box-corner top-left","aria-hidden":"true"}),A("span",{className:"print-box-corner top-right","aria-hidden":"true"}),A("span",{className:"print-box-corner bottom-left","aria-hidden":"true"}),A("span",{className:"print-box-corner bottom-right","aria-hidden":"true"}),i&&l&&A("div",{className:"print-box-title",children:l}),A("div",{className:"print-box-body",children:u.map(m=>A(eh,{block:m,columnGapMm:t,mathFractionSizing:n},m.id))})]})}function eh({block:e,columnGapMm:t,mathFractionSizing:n}){return e.type==="layoutSection"?A(Te,{unit:{type:"block",id:e.id,block:e,pageBreak:e.pageBreak},columnGapMm:t,mathFractionSizing:n}):e.type==="section"||e.type==="boxBlock"?A(Te,{unit:{type:"block",id:e.id,block:e,pageBreak:e.pageBreak},columnGapMm:t,mathFractionSizing:n}):A(_e,{block:e,mathFractionSizing:n})}function uc({problemId:e,area:t,blocks:n,minHeightMm:r,problemNumber:o,numberFontSize:i,hasFrame:a,frameStyleId:s,isFirstProblemArea:l,isFirstProblemFrameArea:u,isLastProblemFrameArea:c,columnGapMm:p,mathFractionSizing:m,fragmentRole:g,sourceId:h}){let b=!g||g==="single"||g==="first",S=t==="lead"&&typeof o=="number"&&b;if(n.length===0&&!r&&!S)return null;let M=S&&n.length===0,L=a?nc("print-problem-area with-frame",s):"print-problem-area",w=g?` print-problem-area-fragment print-problem-area-fragment-${g}`:"";return A("section",{className:`${L}${w} ${a&&u?"first-frame-area":""} ${a&&c?"last-frame-area":""}`,"data-sigma-doc-id":l&&b?e:void 0,"data-problem-area":t,"data-problem-area-fragment":g,"data-problem-source-id":h,"data-problem-frame-style":a?s:void 0,style:r?{minHeight:`${r}mm`}:void 0,children:Yt("div",{className:`print-problem-area-content ${S?"with-number":""}`,children:[S&&A("span",{className:"print-problem-number",style:{fontSize:`${i}pt`},children:Wl(o)}),A("div",{className:`print-problem-area-body ${M?"empty-lead-placeholder":""}`,children:M?A("div",{className:"print-empty-lead-shell","aria-hidden":"true"}):n.map(B=>B.type==="layoutSection"?A(Te,{unit:{type:"block",id:B.id,block:B,pageBreak:B.pageBreak},columnGapMm:p,mathFractionSizing:m},B.id):A(_e,{block:B,mathFractionSizing:m},B.id))})]})})}function yc(e){return Number.isInteger(e)?Math.min(4,Math.max(1,e)):2}function th(e){let t=e.numbering?.fontSize;return typeof t=="number"&&Number.isFinite(t)&&t>0?t:Lg}import{z as d}from"zod";var nh=d.object({avoidInside:d.boolean().optional(),keepWithNext:d.boolean().optional(),breakBefore:d.enum(["auto","always"]).optional(),breakAfter:d.enum(["auto","always"]).optional()}).optional(),Je=d.object({id:d.string().min(1),pageBreak:nh}),ii=d.enum(["left","center","right","justify"]).optional(),ai=d.string().transform((e,t)=>{let n=Ce(e);return n||(t.addIssue({code:d.ZodIssueCode.custom,message:"lineHeight must be a unitless number between 0.8 and 3"}),d.NEVER)}).optional(),xc=d.enum(["frame","thick","double","oval","shade"]).optional(),bc=d.enum(["gray","blue","green","red","yellow"]).optional(),rh=d.object({type:d.literal("text"),text:d.string(),marks:d.array(d.enum(["bold","italic","underline","boxed"])).optional(),color:d.string().optional(),backgroundColor:d.string().optional(),fontFamily:d.string().optional(),fontSize:d.number().positive().optional(),boxedPaddingY:d.number().min(0).optional(),boxedVariant:xc,boxedTone:bc}),oh=d.object({type:d.literal("mathInline"),id:d.string().min(1),tex:d.string(),display:d.literal("inline"),marks:d.array(d.enum(["underline","boxed"])).optional(),color:d.string().optional(),backgroundColor:d.string().optional(),fontFamily:d.string().optional(),fontSize:d.number().positive().optional(),boxedPaddingY:d.number().min(0).optional(),boxedVariant:xc,boxedTone:bc,semanticRole:d.enum(["expression","equation","variable"]).optional(),altText:d.string().optional()}),Xt=d.discriminatedUnion("type",[rh,oh]),gc=d.object({blockId:d.string().min(1),offset:d.number().int().min(0)}),ih=d.discriminatedUnion("type",[d.object({type:d.literal("textRange"),start:gc,end:gc,quote:d.string(),mathInlineIds:d.array(d.string().min(1)).optional(),mathTex:d.array(d.string()).optional()}),d.object({type:d.literal("inlineMath"),blockId:d.string().min(1),mathInlineId:d.string().min(1),quote:d.string().optional(),tex:d.string().optional()}),d.object({type:d.literal("block"),blockId:d.string().min(1),quote:d.string().optional()}),d.object({type:d.literal("overlayShape"),shapeIds:d.array(d.string().min(1)).min(1),quote:d.string().optional()}),d.object({type:d.literal("overlayMath"),shapeId:d.string().min(1).optional(),mathInlineId:d.string().min(1).optional(),quote:d.string().optional(),tex:d.string().optional()})]),Sc=d.object({id:d.string().min(1),emoji:d.string().min(1),authorName:d.string().optional(),createdAt:d.string()}),ah=d.object({id:d.string().min(1),authorName:d.string().optional(),body:d.array(Xt),reactions:d.array(Sc).optional(),createdAt:d.string(),updatedAt:d.string().optional()}),sh=d.object({id:d.string().min(1),anchor:ih,messages:d.array(ah).min(1),reactions:d.array(Sc).optional(),resolved:d.boolean().optional(),color:d.string().optional(),createdAt:d.string(),updatedAt:d.string().optional()}),si=Je.extend({type:d.literal("section"),title:d.string(),align:ii,lineHeight:ai}),yr=Je.extend({type:d.literal("heading"),level:d.union([d.literal(1),d.literal(2),d.literal(3)]),children:d.array(Xt),align:ii,lineHeight:ai}),gr=Je.extend({type:d.literal("paragraph"),children:d.array(Xt),align:ii,lineHeight:ai}),jt=d.lazy(()=>Je.extend({type:d.literal("list"),listType:d.enum(["bullet","ordered"]),start:d.number().int().positive().optional(),items:d.array(lh).min(1)})),lh=d.lazy(()=>d.object({type:d.literal("listItem"),id:d.string().min(1),children:d.array(Xt),nested:d.array(jt).optional()})),Pc=d.union([yr,gr,jt]),Mc=d.object({top:d.number().nonnegative(),right:d.number().nonnegative(),bottom:d.number().nonnegative(),left:d.number().nonnegative()}),ch=d.discriminatedUnion("type",[d.object({type:d.literal("cornerSquares"),sizePx:d.number().positive(),color:d.string()}),d.object({type:d.literal("doubleRule"),offsetPx:d.number().nonnegative(),widthPx:d.number().positive().optional(),color:d.string().optional()}),d.object({type:d.literal("titleDoubleRule"),ruleWidthPx:d.number().positive().optional(),ruleColor:d.string().optional(),guideColor:d.string().optional()}),d.object({type:d.literal("titleBand"),heightPx:d.number().positive().optional(),backgroundColor:d.string().optional()}),d.object({type:d.literal("titlePlate"),borderColor:d.string().optional(),radiusPx:d.number().nonnegative().optional(),paddingPx:Mc.optional()}),d.object({type:d.literal("leftBar"),widthPx:d.number().positive(),color:d.string()}),d.object({type:d.literal("shadow"),offsetXPx:d.number(),offsetYPx:d.number(),blurPx:d.number().nonnegative().optional(),spreadPx:d.number().optional(),color:d.string()}),d.object({type:d.literal("horizontalRules"),widthPx:d.number().positive().optional(),color:d.string().optional()}),d.object({type:d.literal("notebookRules"),baseBodyWidthPx:d.number().positive().optional(),frameLeftPx:d.number().nonnegative().optional(),frameHeightPx:d.number().positive().optional(),frameStrokeOpacity:d.number().min(0).max(1).optional(),lineColor:d.string().optional(),lineGapPx:d.number().positive().optional(),lineWidthPx:d.number().positive().optional(),lineOffsetPx:d.number().nonnegative().optional(),bindingColor:d.string().optional(),bindingWidthPx:d.number().positive().optional(),bindingXPx:d.number().nonnegative().optional(),bindingStrokeOpacity:d.number().min(0).max(1).optional(),ringColor:d.string().optional(),ringWidthPx:d.number().positive().optional(),ringHeightPx:d.number().positive().optional(),ringStrokePx:d.number().positive().optional(),ringGapPx:d.number().positive().optional(),ringTopPx:d.number().nonnegative().optional(),ringCount:d.number().int().positive().optional(),ringLeftOverhangPx:d.number().nonnegative().optional(),minHeightPx:d.number().positive().optional()})]),uh=d.object({borderWidthPx:d.number().nonnegative().optional(),borderColor:d.string().optional(),borderStyle:d.enum(["solid","dashed","dotted","double","none"]).optional(),backgroundColor:d.string().optional(),titleBackgroundColor:d.string().optional(),titleColor:d.string().optional(),titleAlign:d.enum(["left","center","right","justify"]).optional(),titleFontWeight:d.enum(["normal","bold"]).optional(),titleFontFamily:d.string().optional(),titleFontSizePx:d.number().positive().optional(),titleLineHeight:d.string().optional(),bodyColor:d.string().optional(),bodyAlign:d.enum(["left","center","right","justify"]).optional(),bodyFontFamily:d.string().optional(),bodyFontSizePx:d.number().positive().optional(),bodyLineHeight:d.string().optional(),cornerStyle:d.enum(["sharp","round"]).optional(),radiusPx:d.number().nonnegative().optional(),paddingPx:Mc.optional(),decorations:d.array(ch).optional()}).optional(),dh=d.lazy(()=>d.union([si,yr,gr,jt,li,ci])),li=d.lazy(()=>Je.extend({type:d.literal("boxBlock"),styleId:d.string().min(1),title:d.array(Xt).optional(),blocks:d.array(dh).min(1),frame:uh})),ph=d.lazy(()=>d.union([si,yr,gr,jt,li])),mr=d.object({minHeightMm:d.number().nonnegative().optional(),columnSpan:d.enum(["column","full"]).optional()}),fr=d.lazy(()=>d.union([Pc,ci])),mh=Je.extend({type:d.literal("problem"),tags:d.array(d.string()),lead:d.array(fr).max(1).optional().default([]),prompt:d.array(fr),answer:d.object({type:d.enum(["math","text"]),expected:d.string()}).optional(),solution:d.array(fr),hints:d.array(fr),areaLayout:d.object({lead:mr.optional(),prompt:mr.optional(),solution:mr.optional(),hints:mr.optional()}).optional(),numbering:d.object({enabled:d.boolean().optional(),fontSize:d.number().positive().optional(),value:d.number().int().positive().optional()}).optional(),frame:d.object({enabled:d.boolean().optional(),styleId:d.string().min(1).optional()}).optional()}),ci=d.lazy(()=>Je.extend({type:d.literal("layoutSection"),layout:d.object({columnCount:d.number().int().min(1).max(4),columnGapMm:d.number().nonnegative().optional()}),children:d.array(ph).min(1)})),fh=d.union([si,yr,gr,jt,mh,ci,li]),yh=d.preprocess(Ca,d.custom(eo)),vc=d.object({overlaySnapshot:yh.optional(),previewSvg:d.string().optional(),updatedAt:d.string().optional()}),gh=d.object({type:d.literal("columns").optional(),columnCount:d.number().int().min(1).max(4).optional(),columnGapMm:d.number().nonnegative().optional()}),hc=d.object({enabled:d.boolean().optional(),heightMm:d.number().positive().optional(),offsetMm:d.number().nonnegative().optional(),showOnFirstPage:d.boolean().optional(),blocks:d.array(Pc).optional(),overlay:vc.optional()}),hh=d.object({preset:d.enum(["A4","A3","B5","B4","custom"]).optional(),orientation:d.enum(["portrait","landscape"]).optional(),pageSize:d.object({widthMm:d.number().positive().optional(),heightMm:d.number().positive().optional()}).optional(),marginsMm:d.object({top:d.number().nonnegative().optional(),right:d.number().nonnegative().optional(),bottom:d.number().nonnegative().optional(),left:d.number().nonnegative().optional()}).optional(),flow:gh.optional(),header:hc.optional(),footer:hc.optional(),overlay:vc.optional()}).transform(e=>uo(lt(e))).superRefine((e,t)=>{for(let n of Va(e))t.addIssue({code:"custom",message:n})}),xh=d.object({version:d.literal("2.0"),docId:d.string().min(1),metadata:d.object({title:d.string(),source:d.object({format:d.literal("studyaid-prt").optional(),layoutMode:d.literal("fixedOverlay").optional(),printFlowContent:d.boolean().optional()}).optional(),styleUnits:d.object({fontSize:d.literal("pt").optional()}).optional(),mathFractionSizing:d.enum(["uniform","texDefault"]).optional()}),content:d.array(fh),outputProfiles:d.object({student:d.object({showSolutions:d.boolean().optional(),showHints:d.boolean().optional(),includeAnswers:d.boolean().optional(),onlySolutions:d.boolean().optional(),includeComments:d.boolean().optional()}),teacher:d.object({showSolutions:d.boolean().optional(),showHints:d.boolean().optional(),includeAnswers:d.boolean().optional(),onlySolutions:d.boolean().optional(),includeComments:d.boolean().optional()}),answerBook:d.object({showSolutions:d.boolean().optional(),showHints:d.boolean().optional(),includeAnswers:d.boolean().optional(),onlySolutions:d.boolean().optional(),includeComments:d.boolean().optional()})}),comments:d.array(sh).optional(),pageLayout:hh.optional(),updatedAt:d.string().optional()}),bh=xh.transform(e=>({...e,version:"2.0",metadata:{...e.metadata,styleUnits:{...e.metadata.styleUnits,fontSize:Xn}},pageLayout:lt(e.pageLayout)}));function Sh(e){if(typeof e!="object"||e===null||Array.isArray(e.content)||!Array.isArray(e.chapters))return e;let{chapters:t,...n}=e,r=t.flatMap(o=>o&&typeof o=="object"&&Array.isArray(o.content)?o.content:[]);return{...n,content:r}}function Oc(e){return bh.parse(Ph(Sh(e)))}function Ph(e){if(!Ze(e)||e.version!=="2.0")return e;let t=Ze(e.metadata)?e.metadata:{};if((Ze(t.styleUnits)?t.styleUnits:{}).fontSize===Xn)return e;let r=oi(e);if(!Ze(r))return r;let o=Ze(r.metadata)?r.metadata:{},i=Ze(o.styleUnits)?o.styleUnits:{};return{...r,metadata:{...o,styleUnits:{...i,fontSize:Xn}}}}function oi(e){if(Array.isArray(e))return e.map(oi);if(!Ze(e))return e;let t={};for(let[n,r]of Object.entries(e))n==="fontSize"&&typeof r=="number"&&Number.isFinite(r)&&r>0?t[n]=js(r):t[n]=oi(r);return t}function Ze(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var Ic=/[\u0000-\u001f\u007f-\u009f]/u,wc=/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]/u,Mh=/[\\;{}<>]/u,vh=/(?:url\s*\(|@import\b|expression\s*\(|javascript\s*:|vbscript\s*:|data\s*:|\/\*)/iu,Oh=/^(?:rgb|rgba|hsl|hsla)\(\s*[-+.\d%\s,/]+\)$/iu,wh=/^[\p{L}\p{N}\s,"'_.-]+$/u,kh=/^(?:\d+(?:\.\d+)?|\.\d+)(?:px)?$/u,Th=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u,mi=class extends Error{constructor(t){super("Viewer\u3067\u5B89\u5168\u306B\u63CF\u753B\u3067\u304D\u306A\u3044\u30B9\u30BF\u30A4\u30EB\u5024\u304C\u3042\u308A\u307E\u3059\u3002"),this.name="ViewerSafetyValidationError",this.issues=t}};function Cc(e){let t=Bh(e);if(t.length>0)throw new mi(t)}function Bh(e){let t=[],n=(r,o)=>{t.length<100&&t.push(`${r}: ${o}`)};return e.content.forEach((r,o)=>Rh(r,`content.${o}`,n)),kc(e.pageLayout?.header?.blocks,"pageLayout.header.blocks",n),kc(e.pageLayout?.footer?.blocks,"pageLayout.footer.blocks",n),ui(e.pageLayout?.overlay,"pageLayout.overlay",n),ui(e.pageLayout?.header?.overlay,"pageLayout.header.overlay",n),ui(e.pageLayout?.footer?.overlay,"pageLayout.footer.overlay",n),t}function Ec(e){let t=e.trim();if(!t)return{ok:!1,reason:"\u753B\u50CFsource\u304C\u7A7A\u3067\u3059\u3002"};if(Ic.test(t))return{ok:!1,reason:"\u753B\u50CFdata URL\u306B\u5236\u5FA1\u6587\u5B57\u304C\u3042\u308A\u307E\u3059\u3002"};let n=t.indexOf(",");if(n<0)return{ok:!1,reason:"\u753B\u50CFsource\u306Fdata URL\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002"};let r=t.slice(0,n).toLowerCase(),o=t.slice(n+1);if(r==="data:image/png;base64")return di(t,o,"image/png",Hh);if(r==="data:image/jpeg;base64")return di(t,o,"image/jpeg",Vh);if(r==="data:image/webp;base64")return di(t,o,"image/webp",Uh);let i=r==="data:image/svg+xml;base64"||r==="data:image/svg+xml;charset=utf-8;base64"||r==="data:image/svg+xml;charset=us-ascii;base64";if(!i&&!(r==="data:image/svg+xml"||r==="data:image/svg+xml;charset=utf-8"||r==="data:image/svg+xml;charset=us-ascii"))return{ok:!1,reason:"\u753B\u50CF\u306FPNG\u30FBJPEG\u30FBWebP\u30FBSVG\u306Edata URL\u306E\u307F\u8868\u793A\u3067\u304D\u307E\u3059\u3002"};let s;try{if(i){let u=Nc(o);if(!u)return{ok:!1,reason:"SVG\u753B\u50CF\u306Ebase64 payload\u304C\u4E0D\u6B63\u3067\u3059\u3002"};s=new TextDecoder("utf-8",{fatal:!0}).decode(u)}else s=decodeURIComponent(o)}catch{return{ok:!1,reason:"SVG\u753B\u50CF\u306Epayload\u3092UTF-8\u3068\u3057\u3066\u8AAD\u307F\u53D6\u308C\u307E\u305B\u3093\u3002"}}let l=Wh(s);return l?{ok:!1,reason:l}:{ok:!0,value:{src:t,mimeType:"image/svg+xml"}}}function kc(e,t,n){e?.forEach((r,o)=>qt(r,`${t}.${o}`,n))}function Rh(e,t,n){if(e.type==="section"){Pr(e.lineHeight,`${t}.lineHeight`,n);return}if(e.type==="heading"||e.type==="paragraph"||e.type==="list"){qt(e,t,n);return}if(e.type==="problem"){["lead","prompt","hints","solution"].forEach(r=>{e[r].forEach((o,i)=>Ah(o,`${t}.${r}.${i}`,n))});return}if(e.type==="layoutSection"){e.children.forEach((r,o)=>br(r,`${t}.children.${o}`,n));return}Lc(e,t,n)}function Ah(e,t,n){if(e.type==="layoutSection"){e.children.forEach((r,o)=>br(r,`${t}.children.${o}`,n));return}qt(e,t,n)}function br(e,t,n){e.type==="section"?Pr(e.lineHeight,`${t}.lineHeight`,n):e.type==="boxBlock"?Lc(e,t,n):qt(e,t,n)}function Ih(e,t,n){e.type==="layoutSection"?e.children.forEach((r,o)=>br(r,`${t}.children.${o}`,n)):br(e,t,n)}function Lc(e,t,n){e.title?.forEach((r,o)=>Sr(r,`${t}.title.${o}`,n)),e.blocks.forEach((r,o)=>Ih(r,`${t}.blocks.${o}`,n)),Ch(e.frame,`${t}.frame`,n)}function qt(e,t,n){if(e.type==="heading"||e.type==="paragraph"){Pr(e.lineHeight,`${t}.lineHeight`,n),e.children.forEach((r,o)=>Sr(r,`${t}.children.${o}`,n));return}e.items.forEach((r,o)=>{r.children.forEach((i,a)=>Sr(i,`${t}.items.${o}.children.${a}`,n)),r.nested?.forEach((i,a)=>qt(i,`${t}.items.${o}.nested.${a}`,n))})}function Sr(e,t,n){H(e.color,`${t}.color`,n),H(e.backgroundColor,`${t}.backgroundColor`,n),Kt(e.fontFamily,`${t}.fontFamily`,n)}function Ch(e,t,n){if(e){for(let r of["borderColor","backgroundColor","titleBackgroundColor","titleColor","bodyColor"])H(e[r],`${t}.${r}`,n);Kt(e.titleFontFamily,`${t}.titleFontFamily`,n),Kt(e.bodyFontFamily,`${t}.bodyFontFamily`,n),Bc(e.titleLineHeight,`${t}.titleLineHeight`,n),Bc(e.bodyLineHeight,`${t}.bodyLineHeight`,n),e.decorations?.forEach((r,o)=>Eh(r,`${t}.decorations.${o}`,n))}}function Eh(e,t,n){"color"in e&&H(e.color,`${t}.color`,n),"borderColor"in e&&H(e.borderColor,`${t}.borderColor`,n),"backgroundColor"in e&&H(e.backgroundColor,`${t}.backgroundColor`,n),"ruleColor"in e&&H(e.ruleColor,`${t}.ruleColor`,n),"guideColor"in e&&H(e.guideColor,`${t}.guideColor`,n),"lineColor"in e&&H(e.lineColor,`${t}.lineColor`,n),"bindingColor"in e&&H(e.bindingColor,`${t}.bindingColor`,n),"ringColor"in e&&H(e.ringColor,`${t}.ringColor`,n)}function ui(e,t,n){e?.overlaySnapshot&&Lh(e.overlaySnapshot,`${t}.overlaySnapshot`,n)}function Lh(e,t,n){e.shapes.forEach((r,o)=>Nh(r,`${t}.shapes.${o}`,n))}function Nh(e,t,n){switch(e.type){case"geo":H(e.props.color,`${t}.props.color`,n),H(e.props.fillColor,`${t}.props.fillColor`,n),H(e.props.labelColor,`${t}.props.labelColor`,n);break;case"arc":H(e.props.color,`${t}.props.color`,n),H(e.props.fillColor,`${t}.props.fillColor`,n);break;case"arrow":H(e.props.color,`${t}.props.color`,n),H(e.props.labelColor,`${t}.props.labelColor`,n);break;case"line":H(e.props.color,`${t}.props.color`,n),H(e.props.fillColor,`${t}.props.fillColor`,n),H(e.props.labelColor,`${t}.props.labelColor`,n);break;case"text":H(e.props.color,`${t}.props.color`,n),Fh(e.props.richText,`${t}.props.richText`,n);break;case"graph2dShape":$h(e.props.spec,`${t}.props.spec`,n);break;case"tableShape":Gh(e.props.table,`${t}.props.table`,n);break;default:break}}function Fh(e,t,n){let r=new WeakSet;if(r.has(e)){n(t,"richText\u306B\u5FAA\u74B0\u53C2\u7167\u304C\u3042\u308A\u307E\u3059\u3002");return}r.add(e),e.blocks.forEach((o,i)=>{let a=`${t}.blocks.${i}`;if(r.has(o)){n(a,"richText\u306B\u5FAA\u74B0\u53C2\u7167\u304C\u3042\u308A\u307E\u3059\u3002");return}r.add(o),Pr(o.lineHeight,`${a}.lineHeight`,n),o.align!==void 0&&!["left","center","right","justify"].includes(o.align)&&n(`${a}.align`,"\u8A31\u53EF\u3055\u308C\u3066\u3044\u306A\u3044text-align\u3067\u3059\u3002"),o.children.forEach((s,l)=>{_h(s,`${a}.children.${l}`,n)}),r.delete(o)}),r.delete(e)}function _h(e,t,n){H(e.color,`${t}.color`,n),H(e.backgroundColor,`${t}.backgroundColor`,n),Kt(e.fontFamily,`${t}.fontFamily`,n),e.fontSize!==void 0&&!Rc(e.fontSize,512)&&n(`${t}.fontSize`,"font-size\u304C\u4E0D\u6B63\u3067\u3059\u3002"),e.boxedPaddingY!==void 0&&!Rc(e.boxedPaddingY,100,!0)&&n(`${t}.boxedPaddingY`,"padding\u304C\u4E0D\u6B63\u3067\u3059\u3002")}function $h(e,t,n){H(e.axes.axisColor,`${t}.axes.axisColor`,n),e.curves.forEach((r,o)=>H(r.color,`${t}.curves.${o}.color`,n)),e.points?.forEach((r,o)=>H(r.color,`${t}.points.${o}.color`,n)),e.fills?.forEach((r,o)=>H(r.color,`${t}.fills.${o}.color`,n))}function Gh(e,t,n){H(e.grid.borderColor,`${t}.grid.borderColor`,n),e.grid.lineOverrides?.forEach((r,o)=>Dh(r.style,`${t}.grid.lineOverrides.${o}.style`,n)),Tc(e.defaultCellStyle,`${t}.defaultCellStyle`,n),e.cells.forEach((r,o)=>{Tc(r.style,`${t}.cells.${o}.style`,n),r.content.forEach((i,a)=>zh(i,`${t}.cells.${o}.content.${a}`,n))})}function Dh(e,t,n){H(e.borderColor,`${t}.borderColor`,n)}function Tc(e,t,n){e&&(H(e.color,`${t}.color`,n),H(e.backgroundColor,`${t}.backgroundColor`,n),Kt(e.fontFamily,`${t}.fontFamily`,n))}function zh(e,t,n){(e.type==="paragraph"?e.children:e.label)?.forEach((o,i)=>Sr(o,`${t}.children.${i}`,n))}function H(e,t,n){if(!Mr(e))return;if(!Zt(e)){n(t,"CSS\u6CE8\u5165\u306B\u3064\u306A\u304C\u308B\u6587\u5B57\u5217\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002");return}let r=e.trim();!/^#[\da-f]{3,8}$/iu.test(r)&&!/^[a-z]+$/iu.test(r)&&!Oh.test(r)&&n(t,"\u8A31\u53EF\u3055\u308C\u3066\u3044\u306A\u3044\u8272\u8868\u73FE\u3067\u3059\u3002")}function Kt(e,t,n){if(!Mr(e))return;let r=e.trim();(!Zt(e)||r.length>200||!wh.test(r))&&n(t,"font-family\u306B\u5B89\u5168\u3067\u306A\u3044\u5024\u304C\u3042\u308A\u307E\u3059\u3002")}function Pr(e,t,n){if(!Mr(e))return;if(!Zt(e)||!/^(?:\d+(?:\.\d+)?|\.\d+)$/u.test(e.trim())){n(t,"line-height\u306F\u5358\u4F4D\u306A\u3057\u6570\u5024\u3060\u3051\u6307\u5B9A\u3067\u304D\u307E\u3059\u3002");return}let r=Number(e);(!Number.isFinite(r)||r<.5||r>5)&&n(t,"line-height\u304C\u8A31\u53EF\u7BC4\u56F2\u5916\u3067\u3059\u3002")}function Bc(e,t,n){if(!Mr(e))return;let r=e.trim();if(!Zt(e)||!kh.test(r)){n(t,"line-height\u306F\u6570\u5024\u307E\u305F\u306Fpx\u5358\u4F4D\u306E\u9577\u3055\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");return}let o=Number.parseFloat(r);(!Number.isFinite(o)||o<0||o>999)&&n(t,"line-height\u304C\u8A31\u53EF\u7BC4\u56F2\u5916\u3067\u3059\u3002")}function Mr(e){return e!=null}function Zt(e){let t=e.trim();return t.length>0&&t.length<=512&&!Ic.test(e)&&!Mh.test(e)&&!vh.test(e)}function Rc(e,t,n=!1){if(typeof e=="string"&&(!Zt(e)||!/^(?:\d+(?:\.\d+)?|\.\d+)$/u.test(e.trim())))return!1;let r=typeof e=="number"?e:Number(e);return Number.isFinite(r)&&(n?r>=0:r>0)&&r<=t}function di(e,t,n,r){let o=Nc(t);return!o||!r(o)?{ok:!1,reason:`${n}\u753B\u50CF\u306Epayload\u304C\u4E0D\u6B63\u3067\u3059\u3002`}:{ok:!0,value:{src:e,mimeType:n}}}function Nc(e){if(!e||e.length%4!==0||e.length>Math.ceil(33554432/3)*4||!Th.test(e))return null;let t=e.endsWith("==")?2:e.endsWith("=")?1:0,n=e.length/4*3-t;if(n<=0||n>33554432)return null;let r=new Uint8Array(n),o=0;for(let i=0;i<e.length;i+=4){let a=hr(e.charCodeAt(i)),s=hr(e.charCodeAt(i+1)),l=e[i+2]==="="?0:hr(e.charCodeAt(i+2)),u=e[i+3]==="="?0:hr(e.charCodeAt(i+3));if(a<0||s<0||l<0||u<0)return null;let c=a<<18|s<<12|l<<6|u;o<n&&(r[o++]=c>>>16&255),o<n&&(r[o++]=c>>>8&255),o<n&&(r[o++]=c&255)}return r}function hr(e){return e>=65&&e<=90?e-65:e>=97&&e<=122?e-71:e>=48&&e<=57?e+4:e===43?62:e===47?63:-1}function Hh(e){let t=[137,80,78,71,13,10,26,10];if(e.length<45||!t.every((o,i)=>e[i]===o))return!1;let n=8,r=!1;for(;n+12<=e.length;){let o=pi(e,n),i=xr(e,n+4,4),a=n+12+o;if(a>e.length)return!1;if(!r){if(i!=="IHDR"||o!==13||pi(e,n+8)===0||pi(e,n+12)===0)return!1;r=!0}if(i==="IEND")return o===0&&a===e.length;n=a}return!1}function Vh(e){if(e.length<12||e[0]!==255||e[1]!==216||e[e.length-2]!==255||e[e.length-1]!==217)return!1;for(let t=2;t+1<e.length-2;t+=1){if(e[t]!==255)continue;let n=e[t+1];if(n>=192&&n<=195||n>=197&&n<=199||n>=201&&n<=203||n>=205&&n<=207)return!0}return!1}function Uh(e){if(e.length<20||xr(e,0,4)!=="RIFF"||xr(e,8,4)!=="WEBP"||Ac(e,4)+8!==e.length)return!1;let t=xr(e,12,4),n=Ac(e,16);return(t==="VP8 "||t==="VP8L"||t==="VP8X")&&20+n<=e.length}function Wh(e){let t=e.trim();if(!t||t.length>33554432||wc.test(e))return"SVG\u753B\u50CF\u304C\u7A7A\u3001\u904E\u5927\u3001\u307E\u305F\u306F\u5236\u5FA1\u6587\u5B57\u3092\u542B\u3093\u3067\u3044\u307E\u3059\u3002";let n=Yh(t);if(n===null||wc.test(n))return"SVG\u753B\u50CF\u306B\u4E0D\u6B63\u306A\u6587\u5B57\u53C2\u7167\u307E\u305F\u306F\u5236\u5FA1\u6587\u5B57\u304C\u3042\u308A\u307E\u3059\u3002";if(!/^(?:<\?xml\s[^>]*>\s*)?<svg(?:\s|>)[\s\S]*<\/svg>\s*$/iu.test(n))return"SVG\u753B\u50CF\u306B\u6709\u52B9\u306Asvg\u30EB\u30FC\u30C8\u8981\u7D20\u304C\u3042\u308A\u307E\u305B\u3093\u3002";if(/<!doctype\b|<!entity\b|<\?xml-stylesheet\b|<(?:script|foreignObject|iframe|object|embed)\b/iu.test(n))return"SVG\u753B\u50CF\u306B\u8A31\u53EF\u3055\u308C\u3066\u3044\u306A\u3044\u8981\u7D20\u304C\u3042\u308A\u307E\u3059\u3002";if(/\son[a-z][\w:-]*\s*=/iu.test(n))return"SVG\u753B\u50CF\u306B\u30A4\u30D9\u30F3\u30C8\u5C5E\u6027\u304C\u3042\u308A\u307E\u3059\u3002";if(/(?:@import\b|expression\s*\(|javascript\s*:|vbscript\s*:|data\s*:|\/\*)/iu.test(n))return"SVG\u753B\u50CF\u306B@import\u307E\u305F\u306F\u5371\u967A\u306ACSS\u304C\u3042\u308A\u307E\u3059\u3002";let r=n.replace(/url\s*\(\s*([^)]*?)\s*\)/giu,(i,a)=>{let s=a.trim(),l=s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'")?s.slice(1,-1).trim():s;return/^#[A-Za-z_][\w:.-]*$/u.test(l)?"":i});if(/url\s*\(/iu.test(r))return"SVG\u753B\u50CF\u306Eurl()\u306F\u540C\u4E00SVG\u5185\u306E\u8981\u7D20\u3060\u3051\u53C2\u7167\u3067\u304D\u307E\u3059\u3002";let o=/\s(?:href|xlink:href)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/giu;for(let i of n.matchAll(o))if(!(i[1]??i[2]??i[3]??"").trim().startsWith("#"))return"SVG\u753B\u50CF\u304B\u3089\u5916\u90E8resource\u3092\u53C2\u7167\u3067\u304D\u307E\u305B\u3093\u3002";return null}function Yh(e){let t=!0,n=e.replace(/&(?:#(\d+)|#x([\da-f]+)|amp|lt|gt|quot|apos);/giu,(r,o,i)=>{if(o||i){let a=o?Number(o):Number.parseInt(i,16);return Xh(a)?String.fromCodePoint(a):(t=!1,"")}return{"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&apos;":"'"}[r.toLowerCase()]??r});return t?n:null}function Xh(e){return Number.isSafeInteger(e)&&(e===9||e===10||e===13||e>=32&&e<=55295||e>=57344&&e<=65533||e>=65536&&e<=1114111)}function pi(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function Ac(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function xr(e,t,n){let r="";for(let o=0;o<n;o+=1)r+=String.fromCharCode(e[t+o]);return r}import{jsx as ee,jsxs as hi}from"react/jsx-runtime";var _c=96/25.4,qh=["problem","solution","comments"],Qt=class extends Error{constructor(t,n){super("SigmaDoc\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F\u3002"),this.name="SigmaDocParseError",this.issues=t,n&&"cause"in n&&Object.defineProperty(this,"cause",{configurable:!0,value:n.cause})}};function Hc(e){try{let t=Zh(e),n=Oc(t);return Cc(n),n}catch(t){throw new Qt(Uc(t),{cause:t})}}function Zh(e){if(!Or(e)||!Or(e.pageLayout))return e;let t=e.pageLayout,n=!1,r={...t},o=$c(t.overlay);o.changed&&(r.overlay=o.value,n=!0);for(let i of["header","footer"]){if(!Or(t[i]))continue;let a=t[i],s=$c(a.overlay);s.changed&&(r[i]={...a,overlay:s.value},n=!0)}return n?{...e,pageLayout:r}:e}function $c(e){if(!Or(e)||e.overlaySnapshot===void 0)return{value:e,changed:!1};let t=ro(e.overlaySnapshot);return t.issues.length===0?{value:e,changed:!1}:{value:{...e,overlaySnapshot:t.snapshot},changed:!0}}function Or(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Jh({document:e,visibleParts:t,hideProblemNumbers:n=!1,maxHeightPx:r,className:o,style:i,onError:a}){let[s,l]=Jt(!1),[u,c]=Jt(0),p=Fc(()=>yx(t),[t]),m=Fc(()=>nx(e,p,n),[e,p,n]);vr(()=>{l(!0)},[]),vr(()=>{if(!(!s||m.kind!=="ready"||!a))for(let M of m.errors)xi(a,M)},[s,a,m]),vr(()=>{if(!s||typeof globalThis.document>"u")return;let M=globalThis.document.fonts;if(!M)return;let L=!1;return M.ready.then(()=>{L||c(w=>w+1)}),()=>{L=!0}},[s,m.key]);let g=["sigma-viewer",o].filter(Boolean).join(" ");if(!s)return ee("section",{className:g,"data-sigma-viewer":"true","data-sigma-viewer-state":"loading","aria-busy":"true",style:i,children:ee("span",{className:"sigma-viewer__status",children:"\u6587\u66F8\u3092\u6E96\u5099\u3057\u3066\u3044\u307E\u3059\u3002"})});if(m.kind==="error")return a?hi("section",{className:g,"data-sigma-viewer":"true","data-sigma-viewer-state":"error",style:i,children:[ee(ex,{callback:a,error:m.error}),ee(yi,{message:m.error.message})]}):ee("section",{className:g,"data-sigma-viewer":"true","data-sigma-viewer-state":"error",style:i,children:ee(yi,{message:m.error.message})});let h=m.document.pageLayout.pageSize.widthMm*_c,b=m.document.pageLayout.pageSize.heightMm*_c,S=`${m.key}:${u}`;return ee("section",{className:g,"data-sigma-viewer":"true","data-sigma-viewer-state":"ready",style:i,children:ee(Qh,{maxHeightPx:r,resetKey:S,children:hi(gi,{onError:a,children:[ee(dc,{document:m.document,displayMode:"vertical",includePrintPageStyle:!1,stackClassName:"sigma-viewer__pages",renderPageFrame:({page:M,pageNode:L})=>ee(tx,{pageNumber:M.number,pageWidthPx:h,pageHeightPx:b,children:L},M.id)}),m.placeholderAssetIds.map(M=>ee("span",{className:"sigma-viewer__asset-placeholder-marker","data-sigma-viewer-asset-placeholder":M,"aria-hidden":"true"},M))]},S)})})}function Qh({maxHeightPx:e,resetKey:t,children:n}){let r=Kh(),o=zc(null),[i,a]=Jt(!1),[s,l]=Jt(!1),u=gx(e);fi(()=>{a(!1)},[t,u]),fi(()=>{let p=o.current;if(!p||u===void 0){l(!1);return}let m=()=>{l(p.scrollHeight>u+.5)};if(m(),typeof ResizeObserver<"u"){let g=new ResizeObserver(m);return g.observe(p),()=>g.disconnect()}return globalThis.addEventListener?.("resize",m),()=>globalThis.removeEventListener?.("resize",m)},[t,u]);let c=u!==void 0&&!i;return hi("div",{className:`sigma-viewer__viewport ${c?"is-constrained":""}`,"data-sigma-viewer-height-limited":c?"true":"false","data-sigma-viewer-overflow":s?"true":"false",style:c?{maxHeight:`${u}px`}:void 0,children:[ee("div",{className:"sigma-viewer__viewport-content",id:r,ref:o,children:n}),c&&s?ee("div",{className:"sigma-viewer__overflow-control",children:ee("button",{type:"button",className:"sigma-viewer__expand-button","aria-controls":r,"aria-expanded":"false",onClick:()=>a(!0),children:"\u3059\u3079\u3066\u8868\u793A"})}):null]})}function ex({callback:e,error:t}){return vr(()=>{xi(e,t)},[e,t]),null}function yi({message:e}){return ee("div",{className:"sigma-viewer__error",role:"alert",children:e})}var gi=class extends jh{constructor(){super(...arguments);this.state={error:null}}static getDerivedStateFromError(n){return{error:{code:"render-failed",message:n instanceof Error&&n.message?`SigmaDoc\u306E\u63CF\u753B\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${n.message}`:"SigmaDoc\u306E\u63CF\u753B\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002"}}}componentDidCatch(n,r){this.state.error&&this.props.onError&&xi(this.props.onError,this.state.error)}render(){return this.state.error?ee(yi,{message:this.state.error.message}):this.props.children}};function tx({pageNumber:e,pageWidthPx:t,pageHeightPx:n,children:r}){let o=zc(null),[i,a]=Jt(1);return fi(()=>{let s=o.current;if(!s||!(t>0))return;let l=()=>{let c=s.getBoundingClientRect().width;if(!(c>0))return;let p=c/t,m=p>=.999?1:Math.min(1,p);a(g=>Math.abs(g-m)<.001?g:m)};if(l(),typeof ResizeObserver>"u")return globalThis.addEventListener?.("resize",l),()=>globalThis.removeEventListener?.("resize",l);let u=new ResizeObserver(l);return u.observe(s),()=>u.disconnect()},[t]),ee("div",{ref:o,className:"sigma-viewer__page","data-sigma-viewer-page":e,style:{width:"100%",maxWidth:`${t}px`,height:`${n*i}px`},children:ee("div",{className:"sigma-viewer__page-scaler",style:{width:`${t}px`,height:`${n}px`,transform:`scale(${i})`},children:r})})}function nx(e,t,n){let r;try{r=Hc(e)}catch(a){let s=a instanceof Qt?a.issues:Uc(a);return{kind:"error",error:{code:"invalid-document",message:"SigmaDoc\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F\u3002",issues:s},key:`invalid:${Dc(s.join(`
14
+ `))}`}}let o=t===void 0?rx(r,n):ix(r,t,n),i=dx(o);return{kind:"ready",document:i.document,errors:i.errors,placeholderAssetIds:i.placeholderAssetIds,key:Dc(JSON.stringify(i.document))}}function rx(e,t){return{...e,comments:void 0,content:e.content.map(n=>ox(n,t))}}function ox(e,t){if(e.type!=="problem")return e;let n=t?{...e.numbering,enabled:!1}:e.numbering;return e.answer?{...e,numbering:n,prompt:[...e.prompt,ux(e.id,e.answer)]}:n===e.numbering?e:{...e,numbering:n}}function ix(e,t,n){let r=new Set(t),i=e.content.filter(s=>s.type==="problem").map(s=>ax(s,r,n)),a=sx(i);return{...e,comments:void 0,content:i,pageLayout:lx(e.pageLayout,a)}}function ax(e,t,n){let r=t.has("problem"),o=t.has("solution"),i=t.has("comments"),a=new Set([...r?["lead","prompt"]:[],...o?["solution"]:[],...i?["hints"]:[]]),s=Object.entries(e.areaLayout??{}).filter(([l])=>a.has(l));return{...e,lead:r?e.lead:[],prompt:r?e.prompt:[],answer:void 0,solution:o?e.solution:[],hints:i?e.hints:[],areaLayout:s.length>0?Object.fromEntries(s):void 0,numbering:n||!r?{...e.numbering,enabled:!1}:e.numbering}}function sx(e){let t=new Set,n=r=>{if(t.add(r.id),r.type==="layoutSection")r.children.forEach(n);else if(r.type==="boxBlock")r.blocks.forEach(n);else if(r.type==="list")for(let o of r.items)t.add(o.id),o.nested?.forEach(n)};for(let r of e)t.add(r.id),r.lead.forEach(n),r.prompt.forEach(n),r.solution.forEach(n),r.hints.forEach(n);return t}function lx(e,t){if(!e)return e;let n=e.overlay?.overlaySnapshot;return{...e,header:void 0,footer:void 0,overlay:n?{...e.overlay,previewSvg:void 0,overlaySnapshot:{...n,shapes:cx(n.shapes,t)}}:void 0}}function cx(e,t){let n=new Map(e.map(s=>[s.id,s])),r=new Map,o=(s,l=new Set)=>{let u=r.get(s.id);if(u!==void 0)return u;if(l.has(s.id))return r.set(s.id,!1),!1;l.add(s.id);let c=!1;if(s.anchor?.type==="block")c=t.has(s.anchor.blockId);else if(s.anchor?.type==="shape"){let p=n.get(s.anchor.shapeId);c=p?o(p,l):!1}else if(s.parentId){let p=n.get(s.parentId);c=p?o(p,l):!1}return l.delete(s.id),r.set(s.id,c),c},i=new Set(e.filter(s=>o(s)).map(s=>s.id)),a=(s,l=new Set)=>{if(!s.parentId||l.has(s.id))return;let u=n.get(s.parentId);u&&(l.add(s.id),i.add(u.id),a(u,l))};for(let s of e)i.has(s.id)&&a(s);return e.filter(s=>i.has(s.id))}function ux(e,t){return{type:"paragraph",id:`${e}__viewer_answer`,children:t.type==="math"?[{type:"text",text:"\u7B54\u3000",marks:["bold"]},{type:"mathInline",id:`${e}__viewer_answer_math`,tex:t.expected,display:"inline",semanticRole:"expression"}]:[{type:"text",text:"\u7B54\u3000",marks:["bold"]},{type:"text",text:t.expected}]}}function dx(e){let t=[],n=new Set,r=new Set,o=(a,s)=>{if(!a)return a;if(!a.overlaySnapshot){if(a.previewSvg){let u=`${s}:previewSvg`;Vc(u,"\u57CB\u3081\u8FBC\u307FSVG\u306FRead\u5C02\u7528Viewer\u3067\u306F\u8868\u793A\u3067\u304D\u307E\u305B\u3093\u3002",t,r)}return{...a,previewSvg:void 0}}let l=px(a.overlaySnapshot,t,n,r);return{...a,previewSvg:void 0,overlaySnapshot:l}},i=e.pageLayout;return{document:{...e,pageLayout:{...i,overlay:o(i.overlay,"page"),header:i.header?{...i.header,overlay:o(i.header.overlay,"header")}:void 0,footer:i.footer?{...i.footer,overlay:o(i.footer.overlay,"footer")}:void 0}},errors:t,placeholderAssetIds:[...n]}}function px(e,t,n,r){let o={...e.assets};for(let i of e.shapes){if(i.type!=="image")continue;let a=i.props.assetId,s=o[a],l=s?Ec(s.props.src):null;if(s&&l?.ok){let{storage:c,...p}=s.props;o[a]={...s,props:{...p,src:l.value.src,mimeType:l.value.mimeType}};continue}n.add(a);let u=s?l&&!l.ok?l.reason:"\u753B\u50CF\u306FPNG\u30FBJPEG\u30FBWebP\u30FBSVG\u306Edata URL\u306E\u307F\u8868\u793A\u3067\u304D\u307E\u3059\u3002":"\u753B\u50CF\u30A2\u30BB\u30C3\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002";Vc(a,u,t,r),o[a]=mx(a,s,i.props.w,i.props.h)}return{...e,assets:o}}function mx(e,t,n,r){let o=Gc(t?.props.w,n),i=Gc(t?.props.h,r);return{id:e,type:"image",props:{w:o,h:i,name:t?.props.name||"unsupported-image",isAnimated:!1,mimeType:"image/svg+xml",src:fx(e,o,i),fileSize:0}}}function fx(e,t,n){let r=Math.max(1,Math.round(t)),o=Math.max(1,Math.round(n)),i=hx(e.length>28?`${e.slice(0,25)}\u2026`:e),a=[`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${o}" viewBox="0 0 ${r} ${o}">`,'<rect width="100%" height="100%" fill="#f8fafc"/>',`<path d="M0 0L${r} ${o}M${r} 0L0 ${o}" stroke="#cbd5e1" stroke-width="2"/>`,`<rect x="1" y="1" width="${Math.max(0,r-2)}" height="${Math.max(0,o-2)}" fill="none" stroke="#94a3b8"/>`,`<text x="50%" y="50%" text-anchor="middle" dominant-baseline="middle" fill="#475569" font-family="sans-serif" font-size="12">${i}</text>`,"</svg>"].join("");return`data:image/svg+xml,${encodeURIComponent(a)}`}function Vc(e,t,n,r){r.has(e)||(r.add(e),n.push({code:"unsupported-asset",assetId:e,message:`${t} (${e})`}))}function Gc(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:Math.max(1,t)}function Uc(e){if(e&&typeof e=="object"&&"issues"in e&&Array.isArray(e.issues)){let t=e.issues.map(n=>n&&typeof n=="object"&&"message"in n?`${"path"in n&&Array.isArray(n.path)&&n.path.length?`${n.path.join(".")}: `:""}${String(n.message)}`:String(n));if(t.length)return t}return[e instanceof Error&&e.message?e.message:"\u4E0D\u6B63\u306ASigmaDoc\u3067\u3059\u3002"]}function xi(e,t){try{e(t)}catch{}}function yx(e){if(e===void 0)return;let t=new Set(e);return qh.filter(n=>t.has(n))}function gx(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0}function Dc(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function hx(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}export{Qt as SigmaDocParseError,Jh as SigmaDocViewer,Hc as parseSigmaDocument};