1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3451],{3451:(e,t,n)=>{let i;n.r(t),n.d(t,{FnDocumentationFromName:()=>tE,NumberShower:()=>b,PlaygroundToolbarItem:()=>tZ,RelativeValueCell:()=>nF,SqProject:()=>p.SqProject,SquiggleChart:()=>im,SquiggleEditor:()=>t$,SquiggleErrorAlert:()=>nA,SquigglePlayground:()=>t4,SquiggleViewer:()=>is,d3Extended:()=>ih,drawAxes:()=>nc,useCanvas:()=>tN,useCanvasCursor:()=>tk});var r={};n.r(r),n.d(r,{defaultOptions:()=>tx,languages:()=>tu,options:()=>th,parsers:()=>td,printers:()=>tm});var a=n(33251);let l="%Y-%m-%d",s="squiggle-default";function o(e){return"squiggle-default"===e||void 0===e}function c(){let e=a.OET({decimal:".",thousands:",",grouping:[3],currency:["$",""],minus:"-"}),t=e.format(".9~s"),n=e.format(".9~e"),i=e.format(".9~f");return e=>{let r=Math.abs(Number(e));if(0===r)return i(e);if(r<1e-5)return n(e);if(r<1e6)return i(e);if(r<1e9)return t(e);if(r<1e12)return i(Number(e)/1e9)+"B";else if(r<1e15)return t(e);else return n(e)}}function u(e,t,n,i){return o(i)?c():a.Vr1(e,t,n,i)}function d(e){return e.tickFormat=(t,n)=>{let i=e.domain();return u(i[0],i[i.length-1],t??10,n)},e}function m(){return d(a.m4Y())}function h(){var e;return(e=a.aX1()).tickFormat=(t,n)=>{let i=e.domain();return u(i[0],i[i.length-1],t??10,n)},e.ticks=t=>{if(0===t)return[];let[n,i]=e.domain(),r=e.constant();function l(e){return Math.sign(e)*Math.log1p(Math.abs(e/r))}function s(e,t=Math.round){if(0===e)return 0;let n=Math.pow(10,Math.floor(Math.log10(Math.abs(e)))),i=Math.abs(t(e/n));return(0==i?0:Math.pow(Math.abs(t(Math.sign(e)*Math.sqrt(i-1))),2)+1)*n*Math.sign(e)}let o=t??10;if(Math.abs(l(n)-l(i))/o<.5){let e=Math.pow(10,Math.floor(Math.log10(i-n)-1)),t=Math.ceil(n/e)*e,r=Math.floor(i/e)*e,l=r-t,s=Math.floor(Math.log10(l)),c=l/Math.pow(10,s);for(;1.5*c<o;)c*=2;return a.y17(t,r,l/c).concat([r])}let c=l(s(n,Math.ceil)),u=l(s(i,Math.floor)),d=(u-c)/o,m=u>0&&c<0?Math.ceil(c/d)*d:c+d/2,h=a.y17(m,u,d);return[s(n,Math.ceil)].concat(h.map(function(e){return Math.sign(e)*Math.expm1(Math.abs(e))*r}).map(function(e){return s(e)}),[s(i,Math.floor)])},e}function x(){return d(a.RWy())}function g(){var e=a.ZEH();let t=e.tickFormat;return e.tickFormat=(e,n)=>t(e,o(n)?c():n),e}var p=n(55980),O=n(33808);class f{constructor(e,t=2){this.number=e,this.precision=t}convert(){let e=Math.abs(this.number),t=this.evaluate(e);return this.number<0&&(t.value="-"+t.value),t}metricSystem(e,t){let n=e/Math.pow(10,t),i=this.precision;return`${function(e,t){let n=Number(e.toPrecision(t));return`${n}`}(n,i)}`}evaluate(e){if(0===e)return{value:this.metricSystem(0,0)};if(e===1/0)return{value:"Infinity"};let t=Math.floor(Math.log(e)/Math.LN10+1e-9);if(t<-2)return{value:this.metricSystem(e,t),power:t};if(t<4)return{value:this.metricSystem(e,0)};if(t<6)return{value:this.metricSystem(e,3),symbol:"K"};if(t<9)return{value:this.metricSystem(e,6),symbol:"M"};if(t<12)return{value:this.metricSystem(e,9),symbol:"B"};else if(t<15)return{value:this.metricSystem(e,12),symbol:"T"};else return{value:this.metricSystem(e,t),power:t}}}let b=({number:e,precision:t=2,unitName:n})=>{let i=function(e,t=2){return new f(e,t).convert()}(e,t);return(0,O.jsxs)("span",{children:[i.value,i.symbol,i.power?(0,O.jsxs)("span",{children:["\xb7","10",(0,O.jsx)("sup",{style:{fontSize:"0.7em"},children:i.power})]}):null,n&&(0,O.jsxs)("span",{children:[" ",p.durationUnits[n].plural]})]})};var v=n(61660),j=n(37107);function y(e){return e.isStale??!1}let S=[];
1function P(e){let[t,n]=(0,v.useState)(e.initialAutorunMode??!0),{sourceId:i,project:r,continues:a}=function(e,t,n){let i=(0,v.useMemo)(()=>e??Math.random().toString(36).slice(2),[e]),r="standalone"===t.type?S:t.continues??S;return{sourceId:i,project:(0,v.useMemo)(()=>{switch(t.type){case"standalone":return p.SqProject.create({environment:n});case"projectFromLinker":return p.SqProject.create({environment:n,linker:t.linker});case"project":return t.project;default:throw Error("Invalid setup type")}},[]),continues:r}}(e.sourceId,e.setup,e.environment),[l,{runSimulation:s}]=function(e){let[t,n]=(0,v.useState)(void 0);return[t,{runSimulation:(0,v.useCallback)(async()=>{let t=async()=>{n(e=>e?{isStale:!0,...e||{}}:void 0);let t=Date.now();e.project.setSource(e.sourceId,e.code),e.project.setContinues(e.sourceId,e.continues),await e.project.run(e.sourceId);let i=e.project.getOutput(e.sourceId),r=Date.now()-t;n(t=>({executionId:(t?.executionId||0)+1,isStale:!1,code:e.code,output:i,executionTime:r}))};if("undefined"==typeof MessageChannel)setTimeout(t,10);else{let e=new MessageChannel;e.port1.onmessage=t,requestAnimationFrame(function(){e.port2.postMessage(void 0)})}},[e.code,e.continues,e.project,e.sourceId])}]}({sourceId:i,code:e.code,project:r,continues:a,autorunMode:t});return(0,v.useEffect)(()=>{t&&s()},[s]),(0,v.useEffect)(()=>{e.environment&&r.setEnvironment(e.environment),t&&s()},[e.environment]),(0,v.useEffect)(()=>()=>{r.removeSource(i)},[r,i]),{sourceId:i,simulation:l,project:r,autorunMode:t,setAutorunMode:n,runSimulation:s}}function w(e){return e?e.output.ok?[]:[e.output.value]:[]}function Q(e){if(e.ok)return e.value;throw Error("FAILURE TO UNWRAP")}function C(){return"undefined"!=typeof window&&"MacIntel"===window.navigator.platform}let N="w-full";function k(e){return!!e.context}let $=({viewer:e,menu:t,indicator:n})=>(0,O.jsxs)("div",{className:"flex flex-col overflow-y-auto",children:[(0,O.jsxs)("div",{className:"flex justify-between items-center px-2 h-8 mb-1",children:[t,n]}),(0,O.jsx)("div",{className:"flex-1 overflow-auto px-2 pb-1","data-testid":"dynamic-viewer-result",children:e})]}),A=({simulation:e})=>{let t=y(e);return(0,O.jsx)("div",{className:"text-zinc-400 text-sm whitespace-nowrap",children:t?"simulating...":`simulation #${e.executionId} in ${(e=>e>1e3?`${(e/1e3).toFixed(2)}s`:`${e}ms`)(e.executionTime)}`})};var R=n(26401),T=n(50427),E=n(95820);let q=({heading:e="Error",backgroundColor:t,headingColor:n,bodyColor:i,icon:r,iconColor:a,children:l})=>(0,O.jsx)("div",{className:(0,E.$)("rounded-sm px-2 py-1.5",t),role:"status",children:(0,O.jsxs)("div",{className:"flex",children:[(0,O.jsx)(r,{className:(0,E.$)("h-4 w-4 flex-shrink-0 mt-1 ml-1",a),"aria-hidden":"true"}),(0,O.jsxs)("div",{className:"ml-3 grow",children:[(0,O.jsx)("header",{className:(0,E.$)("text-sm font-medium",n),children:e}),l&&v.Children.count(l)?(0,O.jsx)("div",{className:(0,E.$)("mt-1 text-sm",i),children:l}):null]})]})}),_=e=>(0,O.jsx)(q,{...e,backgroundColor:"bg-red-50",headingColor:"text-red-900",bodyColor:"text-slate-700",icon:R.A,iconColor:"text-red-400"}),V=e=>(0,O.jsx)(q,{...e,backgroundColor:"bg-slate-50",headingColor:"text-slate-700",bodyColor:"text-slate-600",icon:T.A,iconColor:"text-slate-400"});class z extends v.Component{static getDerivedStateFromError(e){return{error:e}}componentDidCatch(){}render(){return this.state.error?(0,O.jsxs)("div",{className:"m-2 p-4 bg-red-300 rounded",children:[(0,O.jsx)("header",{className:"mb-2 font-semibold",children:"Fatal Error"}),(0,O.jsx)("div",{className:"mb-2",children:this.state.error.message}),(0,O.jsx)("div",{className:"mb-2",children:"Try reloading the browser."}),(0,O.jsx)("pre",{className:"text-xs overflow-auto",children:this.state.error.stack})]}):this.props.children}constructor(){super(...arguments),this.state={}}}var W=n(14547),D=n(34856);function M(e){let t=e.method;if(!t)return m();switch(t.type){case"linear":return m();case"symlog":return h().constant(t.constant||p.SCALE_SYMLOG_DEFAULT_CONSTANT);case"power":return x().exponent(t.exponent||p.SCALE_POWER_DEFAULT_CONSTANT);case"log":return g();case"date":var n;return(n=a.m4Y()).tickFormat=(e,t)=>
1{let n=o(t)?l:t,i=a.DCK(n);return e=>i(new Date(e))},n.ticks=e=>{if(0===e)return[];let[t,i]=n.domain();return a.w7C().domain([new Date(t),new Date(i)]).ticks(e??10).map(e=>e.getTime())},n}}function X(e,t){return a.GPZ(e)(t)}function L(e,t){return a.DCK(t||l)(e)}let F={min:0,max:10,points:20};function Y(e,t,n){let i=e.xScale?.min??F.min,r=e.xScale?.max??F.max,a=M(e.xScale);a.domain([i,r]);let l=(()=>{let t=function({scale:e,count:t}){let n=e.range();e.range([0,t-1]);let i=e.clamp();e.clamp(!0);let r=[];for(let n=0;n<t;n++)r.push(e.invert(n));return e.range(n),e.clamp(i),r}({scale:a,count:n});return e.xPoints({min:i,max:r,requestedXPoints:t})})(),s=[],o=[];for(let n of l){let i=e.fn.call([e.xScale.numberToValue(n)],t);i.ok?"Number"===i.value.tag&&"numericFn"===e.tag||"Dist"===i.value.tag&&"distFn"===e.tag?s.push({x:n,y:i.value.value}):o.push({x:n,value:`This component expected outputs of type ${"numericFn"===e.tag?"Number":"Dist"}, got: ${i.value.toString()}`}):o.push({x:n,value:i.value.toString()})}return{errors:o,functionImage:s,xScale:a}}let Z=({children:e})=>(0,O.jsx)("p",{className:"text-sm text-gray-500",children:e}),U=({title:e,children:t})=>(0,O.jsxs)("div",{children:[(0,O.jsx)("header",{className:"text-md leading-4 font-medium text-slate-600",children:e}),(0,O.jsx)("div",{className:"mt-4",children:t})]}),I=D.z.object({sampleCount:D.z.number().int().gte(10).lte(1e6),xyPointLength:D.z.number().int().gte(10).lte(1e4)}),G=D.z.object({start:D.z.number().finite(),stop:D.z.number().finite(),count:D.z.number().int().finite()}),B=D.z.object({lineWrapping:D.z.boolean()}),H=D.z.union([D.z.literal("linear"),D.z.literal("log"),D.z.literal("symlog"),D.z.literal("exp")]);function J(e,t={}){switch(e){case"linear":case"log":case"symlog":return new p.SqScale({method:{type:e},...t});case"exp":return new p.SqScale({method:{type:"power"},...t});default:throw Error("Internal error")}}let K=D.z.object({xScale:H,yScale:H,minX:D.z.number().optional(),maxX:D.z.number().optional(),title:D.z.string().optional(),showSummary:D.z.boolean()}),ee=D.z.object({environment:I,distributionChartSettings:K,functionChartSettings:G,editorSettings:B,chartHeight:D.z.number().int().finite().gte(10).lte(5e3)}),et={chartHeight:100,environment:{sampleCount:1e3,xyPointLength:1e3},functionChartSettings:{start:F.min,stop:F.max,count:F.points},distributionChartSettings:{xScale:"linear",yScale:"linear",showSummary:!0},editorSettings:{lineWrapping:!0}};function en(e,t){return{xScale:J(e.xScale,{min:e.minX,max:e.maxX,tickFormat:t}),yScale:J(e.yScale),showSummary:e.showSummary,title:e.title}}let ei=()=>(0,O.jsxs)("div",{className:"space-y-4",children:[(0,O.jsx)(j.mF,{name:"environment.sampleCount",label:"Sample Count",description:"How many samples to use for Monte Carlo simulations. This can occasionally be overridden by specific Squiggle programs."}),(0,O.jsx)(j.mF,{name:"environment.xyPointLength",label:"Coordinate Count (For PointSet Shapes)",description:"When distributions are converted into PointSet shapes, we need to know how many coordinates to use."})]}),er=({metaSettings:e})=>(0,O.jsx)(U,{title:"Distribution Display Settings",children:(0,O.jsxs)("div",{className:"space-y-4",children:[(0,O.jsx)(j.Oj,{name:"distributionChartSettings.showSummary",label:"Show summary statistics"}),(0,O.jsx)(j.aB,{name:"distributionChartSettings.xScale",label:"X Scale",options:[{id:"linear",name:"Linear"},{id:"log",name:"Logarithmic",...e?.disableLogX?{disabled:!0,tooltip:"Your distribution has mass lower than or equal to 0. Log only works on strictly positive values."}:null},{id:"symlog",name:"Symlog",tooltip:"Almost logarithmic scale that supports negative values."},{id:"exp",name:"Exponential"}]}),(0,O.jsx)(j.aB,{name:"distributionChartSettings.yScale",label:"Y Scale",options:[{id:"linear",name:"Linear"},{id:"exp",name:"Exponential"}]}),(0,O.jsx)(j.mF,{name:"distributionChartSettings.minX",label:"Min X Value"}),(0,O.jsx)(j.mF,{name:"distributionChartSettings.maxX",label:"Max X Value"})]})}),ea=()=>(0,O.jsx)(U,{title:"Function Display Settings",children:(0,O.jsxs)("div",{className:"space-y-6",children:[(0,O.jsx)(Z,{children:"When dis
1playing functions of single variables that return numbers or distributions, we need to use defaults for the x-axis. We need to select a minimum and maximum value of x to sample, and a number n of the number of points to sample."}),(0,O.jsxs)("div",{className:"space-y-4",children:[(0,O.jsx)(j.mF,{name:"functionChartSettings.start",label:"Min X Value"}),(0,O.jsx)(j.mF,{name:"functionChartSettings.stop",label:"Max X Value"}),(0,O.jsx)(j.mF,{name:"functionChartSettings.count",label:"Points between X min and X max to sample"})]})]})}),el=()=>(0,O.jsx)(U,{title:"Editor Settings",children:(0,O.jsx)(j.Oj,{name:"editorSettings.lineWrapping",label:"Line Wrapping"})}),es=({withGlobalSettings:e=!0,withFunctionSettings:t=!0,metaSettings:n})=>(0,O.jsxs)("div",{className:"divide-y divide-gray-200 max-w-2xl",children:[e&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)("div",{className:"mb-6",children:(0,O.jsx)(U,{title:"Rendering Settings",children:(0,O.jsx)(ei,{})})}),(0,O.jsx)("div",{className:"pt-6 mb-6",children:(0,O.jsx)(U,{title:"General Display Settings",children:(0,O.jsx)(j.mF,{name:"chartHeight",label:"Chart Height (in pixels)"})})})]}),(0,O.jsx)("div",{className:"pt-6 mb-6",children:(0,O.jsx)(er,{metaSettings:n})}),t?(0,O.jsx)("div",{className:"pt-6 mb-6",children:(0,O.jsx)(ea,{})}):null,e?(0,O.jsx)("div",{className:"pt-6 mb-6",children:(0,O.jsx)(el,{})}):null]});class eo{constructor(e,t,n){this.root=e,this.path=t,this.traverseCalculatorEdge=n,this.isEqual=this.isEqual.bind(this)}uid(){return this.path.uid()}isEqual(e){return this.uid()===e.uid()}sqValue(){return this.root.getSubvalueByPath(this.path,this.traverseCalculatorEdge)}hasHiddenTag(){return this.sqValue()?.tags.hidden()||!1}parent(){let e=this.path.parent();return e?new eo(this.root,e,this.traverseCalculatorEdge):void 0}children(){let e=this.sqValue();return e?eP(e).map(e=>{let t=e.context?.path;return t?new eo(this.root,t,this.traverseCalculatorEdge):void 0}).filter(e=>void 0!==e).filter(e=>!e.hasHiddenTag()):[]}lastChild(){return this.children().at(-1)}siblings(){return this.parent()?.children()??[]}prevSibling(){let e=this.getParentIndex();if(-1!==e&&0!==e)return this.siblings()[e-1]}nextSibling(){let e=this.getParentIndex(),t=e===this.siblings().length-1;if(-1!==e&&!t)return this.siblings()[e+1]}getParentIndex(){return this.siblings().findIndex(this.isEqual)}}class ec{constructor(e,t){this.node=e,this.params=t,this.make=this.make.bind(this)}static make(e,t,n,i){return new ec(new eo(e,t,n),{getIsCollapsed:i})}make(e){return new ec(e,this.params)}makeU(e){return e?new ec(e,this.params):void 0}value(){return this.node.sqValue()}isRoot(){return this.node.path.isRoot()}parent(){return this.makeU(this.node.parent())}children(){return this.node.children().map(this.make)}lastChild(){return this.makeU(this.node.lastChild())}siblings(){return this.node.siblings().map(this.make)}prevSibling(){return this.makeU(this.node.prevSibling())}nextSibling(){return this.makeU(this.node.nextSibling())}isCollapsed(){return this.params.getIsCollapsed(this.node.path)}hasVisibleChildren(){return!this.isCollapsed()&&this.children().length>0}lastVisibleSubChild(){if(!this.hasVisibleChildren())return this;{let e=this.lastChild();return e?.lastVisibleSubChild()||e}}nextAvailableSibling(){return this.nextSibling()||this.parent()?.nextAvailableSibling()}next(){return this.hasVisibleChildren()?this.children()[0]:this.nextAvailableSibling()}prev(){let e=this.prevSibling();return e?e.lastVisibleSubChild():this.parent()}}let eu={collapsed:!1,settings:{}};class ed{constructor(){this.state={},this.handles={}}setState(e,t){let n=t(this.state[e.uid()]||eu);this.state[e.uid()]=n}getState(e){return this.state[e.uid()]||eu}getStateOrInitialize(e){let t=e.context.path,n=t.uid(),i=this.state[t.uid()];if(i)return i;this.state[n]=eu;let r=eP(e),a=()=>{for(let e of r){if(!e.context)continue;let t=e.context.path.uid();this.state[t]||(this.state[t]={...eu,collapsed:!0})}};return r.length>10&&a(),ek(e,t)&&(this.state[n]={...this.state[n],collapsed:!0}),this.state[n]}getCalculator(e){return this.getState(e).calculator}forceUpdate(e){this.handles[e.uid()]?.forceUpdate()}registerItemHandle(e,t){this.handles[e.uid()]=t}unregisterItemHandle(e){delete this.handles[e.uid()]}updateCalculatorState(e,t){this.setState(e,e=>({...e,calculator:e.calculator?.hashString===t.hashString?{...e.calculator,...t}:t}))}scrollViewerToPath(e){this.handles[e.uid()]?.scrollIntoView()}
1focusOnPath(e){this.handles[e.uid()]?.focusOnHeader()}}let em=(0,v.createContext)({globalSettings:et,zoomedInPath:void 0,setZoomedInPath:()=>void 0,editor:void 0,itemStore:new ed,viewerType:"normal",handle:{viewValuePath:()=>{}},initialized:!1,rootValue:void 0,findNode:()=>void 0});function eh(){return(0,v.useContext)(em)}function ex(e,t){e.setState(t,e=>({...e,collapsed:!e?.collapsed})),e.forceUpdate(t)}function eg(e){let{itemStore:t}=eh(),n=t.getState(e);return!!(n.settings.distributionChartSettings||n.settings.functionChartSettings)}function ep(){let{zoomedInPath:e,setZoomedInPath:t}=eh();return n=>{e?.isEqual(n)||(n.isRoot()?t(void 0):t(n))}}function eO(){let{setZoomedInPath:e}=eh();return()=>e(void 0)}function ef(e){let{itemStore:t,globalSettings:n}=eh(),i=t.getState(e);return(0,v.useMemo)(()=>W({},n,i.settings),[n,i.settings])}function eb(){let{viewerType:e}=eh();return e}let ev=(0,v.forwardRef)(({partialPlaygroundSettings:e,editor:t,viewerType:n="normal",rootValue:i,children:r},a)=>{let[l]=(0,v.useState)(()=>new ed),s=function(e){let t=JSON.stringify(e);return(0,v.useMemo)(()=>JSON.parse(t),[t])}(e),[o,c]=(0,v.useState)(),u=(0,v.useMemo)(()=>W({},et,s),[s]),d={viewValuePath(e){l.scrollViewerToPath(e)}};(0,v.useImperativeHandle)(a,()=>d);let m=i&&k(i)?i:void 0;return(0,O.jsx)(em.Provider,{value:{rootValue:m,globalSettings:u,editor:t,zoomedInPath:o,setZoomedInPath:c,itemStore:l,viewerType:n,handle:d,initialized:!0,findNode:e=>(function(e,t,n){if(e&&t)return ec.make(e,t,ew(n),e=>n.getState(e).collapsed)})(m,e,l)},children:r})});ev.displayName="InnerViewerProvider";let ej=(0,v.forwardRef)((e,t)=>{let{handle:n}=eh();return(0,v.useImperativeHandle)(t,()=>n),e.children});ej.displayName="ProxyViewerProvider";let ey=(0,v.forwardRef)((e,t)=>{let{initialized:n}=(0,v.useContext)(em);return n?(0,O.jsx)(ej,{ref:t,...e}):(0,O.jsx)(ev,{ref:t,...e})});function eS(e){return({result:"Result",bindings:"Variables",imports:"Imports",exports:"Exports"})[e.root]}function eP(e){switch(e.tag){case"Array":return e.value.getValues();case"Dict":return e.value.entries().map(e=>e[1]);default:return[]}}function ew(e){return t=>{let n=e.getCalculator(t),i=n?.calculatorResult;return i?.ok?i.value:void 0}}function eQ(e){let t=e.context.docstring()||e.tags.doc();return t&&t.length>0?t:void 0}ey.displayName="ViewerProvider";let eC=new Set(["Bool","Number","Void","Input"]);function eN(e){let t=eC.has(e.tag)||"String"===e.tag&&e.value.length<=25,n=eQ(e),i=!!(n&&n.length>15);return!t||i}let ek=(e,t)=>{let n=e.tags.startOpenState();if("open"===n)return!1;if("closed"===n)return!0;let i=eP(e);return t.isRoot()?i.length>30:"Dist"===e.tag||i.length>5||!eN(e)};function e$(e){return e.entries().filter(([e,t])=>!function(e){let t=e.tags.hidden(),n=e.context?.path;return!!(!0===t&&n&&1===n.edges.length)}(t))}class eA{constructor(){this.widgets=new Map}register(e,t){let n={Chart:({value:n,settings:i})=>{if(n.tag!==e)throw Error(`${e} widget used incorrectly`);return t.Chart(n,i)}};n.Chart.displayName=`${e}Chart`;let{Preview:i,Menu:r,heading:a}=t;i&&(n.Preview=({value:t})=>{if(t.tag!==e)throw Error(`${e} widget used incorrectly`);return i(t)},n.Preview.displayName=`${e}Preview`),r&&(n.Menu=({value:t})=>{if(t.tag!==e)throw Error(`${e} widget used incorrectly`);return r(t)},n.Menu.displayName=`${e}Menu`),a&&(n.heading=t=>{if(t.tag!==e)throw Error(`${e} widget used incorrectly`);return a(t)}),this.widgets.set(e,n)}}let eR=new eA,eT=({type:e,count:t})=>(0,O.jsxs)("div",{children:[e,(0,O.jsx)("span",{className:"ml-0.5",children:t})]});function eE(e){return!!e.tags.notebook()}eR.register("Array",{heading:e=>`List(${e.value.getValues().length})`,Preview:e=>eE(e)?(0,O.jsx)(j.AQ,{size:14,className:"opacity-40"}):(0,O.jsx)(eT,{type:"[]",count:e.value.getValues().length}),Chart:e=>{let t=(0,v.useMemo)(()=>e.value.getValues(),[e]);return(0,O.jsx)("div",{className:"space-y-1 pt-0.5 mt-0.5",children:t.map((t,n)=>(0,O.jsx)(it,{parentValue:e,value:t,header:eE(e)?"hide":void 0},n))})}}),eR.register("Bool",{Preview:e=>e.value.toString(),Chart:e=>(0,O.jsx)("div",{className:"text-indigo-800 text-sm font-mono font-semibold",children:e.value.toString()})});var eq=n(80105),e_=n(45662),eV=n(82681),ez=n(45528),eW=n(68788),eD=n(63820);let eM=JSON.parse('{"scopeName":"source.squiggle","patterns":[{"include":"#import"},{"include":"#statement"},{"include":"#expression"},{"include":"#comment-block"},{"include":"#comment-line"}],"repository":{"statement":{"patterns":[{"include":"#let"},{"include":"#decorator-call"},{"include":"#decorator"}]},"expression":{"patterns":[{"include":"#integer"},{"include":"#float"},{"include":"#string"},{"include":"#block"},{"include":"#function-call"},{"include":"#keywords"},{"include":"#variable"}]},"import":{"match":"^\\\\s*(import)\\\\s+(\'.*?\'|\\".*?\\")\\\\s+(as)\\\\s+(\\\\w+)","captures":{"1":{"name":"keyword.control.squiggle"},"2":{"name":"string.quoted.squiggle"},"3":{"name":"keyword.control.squiggle"},"4":{"name":"variable.other.squiggle"}}},"decorator":{"match":"^\\\\s*(@)(\\\\w+)","captures":{"1":{"name":"punctuation.decorator.squiggle"},"2":{"name":"entity.name.function.squiggle"}}},"decorator-call":{"begin":"^\\\\s*(@)(\\\\w+)\\\\s*(\\\\()","end":"(\\\\))","beginCaptures":{"1":{"name":"punctuation.decorator.squiggle"},"2":{"name":"entity.name.function.squiggle"},"3":{"name":"meta.brace.round.squiggle"}},"endCaptures":{"1":{"name":"meta.brace.round.squiggle"}},"patterns":[{"include":"#expression"},{"include":"#comma"}]},"let":{"match":"^\\\\s*(?:(export)\\\\s+)?(\\\\w+)\\\\s*=","captures":{"1":{"name":"keyword.control.squiggle"},"2":{"name":"variable.other.squiggle"}}},"function-call":{"begin":"(\\\\w+)\\\\s*(\\\\()","end":"(\\\\))","beginCaptures":{"1":{"name":"entity.name.function.squiggle"},"2":{"name":"meta.brace.round.squiggle"}},"endCaptures":{"1":{"name":"meta.brace.round.squiggle"}},"patterns":[{"include":"#expression"},{"include":"#comma"}]},"comma":{"match":",","captures":{"1":{"name":"punctuation.separator.comma.squiggle"}}},"comment-block":{"begin":"/\\\\*","end":"\\\\*/","name":"comment.block.squiggle"},"comment-line":{"patterns":[{"include":"#comment-line-double-slash"},{"include":"#comment-line-number-sign"}]},"comment-line-double-slash":{"match":"//.*","name":"comment.line.double-slash.squiggle"},"comment-line-number-sign":{"match":"#.*","name":"comment.line.number-sign.squiggle"},"block":{"begin":"{","end":"}","beginCaptures":{"0":{"name":"punctuation.definition.block.squiggle"}},"endCaptures":{"0":{"name":"punctuation.definition.block.squiggle"}},"patterns":[{"include":"$self"}]}
1,"keywords":{"match":"\\\\b(if|then|else|to)\\\\b","name":"keyword.control.squiggle"},"integer":{"match":"\\\\b\\\\d+([_a-zA-Z]+[_a-zA-Z0-9]*)?","name":"constant.numeric.integer.squiggle"},"float":{"match":"\\\\b(\\\\d+\\\\.\\\\d*|\\\\.?\\\\d+)([eE]-?\\\\d+)?([_a-zA-Z]+[_a-zA-Z0-9]*)?","name":"constant.numeric.float.squiggle"},"string":{"patterns":[{"include":"#single-quoted-string"},{"include":"#double-quoted-string"}]},"variable":{"match":"\\\\b([_a-zA-Z]+[_a-zA-Z0-9]*)","name":"variable.other.squiggle"},"single-quoted-string":{"match":"\'.*?\'","name":"string.quoted.single.squiggle"},"double-quoted-string":{"match":"\\\\\\".*?\\\\\\"","name":"string.quoted.double.squiggle"}}}');async function eX(e){return i||(i=await (0,ez.kS)({themes:["vitesse-light"],langs:[{name:"squiggle",...eM}]})),"squiggle"===e.language||i.getLoadedLanguages().includes(e.language)||(await i.loadLanguage(e.language),await i.loadLanguage(e.language)),i.codeToHtml(e.code,{theme:"vitesse-light",lang:e.language})}function eL(){return function(e){(0,eD.VG)(e,"element",function(e,t){if("code"===e.tagName){let n=t[t.length-1];e.properties||(e.properties={}),e.properties.inline=String(!(n&&"pre"===n.tagName))}})}}let eF=({children:e,language:t,...n})=>{let[i,r]=(0,v.useState)(e);return(0,v.useEffect)(()=>{(async()=>{(function(e){return"squiggle"===e||e in eW.el})(t)&&r(await eX({code:e,language:t}))})()}),(0,O.jsx)("div",{className:"*:!bg-inherit",dangerouslySetInnerHTML:{__html:i},...n})},eY=({md:e,className:t,textColor:n,textSize:i})=>(0,O.jsx)(e_.oz,{className:(0,E.A)("prose",t,n||"prose-stone","sm"===i?"text-sm":"text-xs"),rehypePlugins:[eL],remarkPlugins:[eV.A],components:{pre:({children:e})=>(0,O.jsx)("pre",{className:"rounded bg-slate-50 p-2 my-1 not-prose text-[.9em]",children:e}),code(e){let{node:t,children:n,className:i,...r}=e,a=/language-(\w+)/.exec(i||"");return"true"===(t&&t.properties.inline)?(0,O.jsx)("code",{...r,className:"not-prose border-black border border-opacity-[0.04] bg-opacity-[0.03] bg-black px-1 py-0.5 rounded-sm break-words font-mono text-[.9em]",children:n}):a?(0,O.jsx)(eF,{...r,language:a[1],children:String(n).replace(/\n$/,"")}):(0,O.jsx)("code",{...r,children:n})}},children:e}),eZ=(0,v.memo)(function({value:e,settings:t}){let n=e.tags.showAs(),i=n&&k(n)?n:e,r=eR.widgets.get(i.tag);return r?(0,O.jsx)(r.Chart,{value:i,settings:t}):i.toString()}),eU=(0,v.memo)(function({result:e,settings:t}){if(!e.ok)return(0,O.jsx)("div",{className:"text-sm text-red-800 text-opacity-70",children:e.value.toString()});{let n=e.value;return k(n)?(0,O.jsx)(eZ,{value:n,settings:t}):n.toString()}}),eI=({id:e,input:t,result:n,settings:i})=>{let{name:r,typeName:a,description:l}=t,s={name:`inputs.${e}`,label:r,description:[a,l].filter(e=>e).join("\n\n")};return(0,O.jsxs)("div",{className:"flex flex-col",children:[(0,O.jsxs)("div",{className:"flex-grow max-w-sm",children:["text"===t.tag&&(0,O.jsx)(j.uS,{...s,placeholder:`Enter code for ${r}`,size:"small"}),"textArea"===t.tag&&(0,O.jsx)(j.vE,{...s,placeholder:`Enter code for ${r}`}),"checkbox"===t.tag&&(0,O.jsx)(j.Oj,{...s}),"select"===t.tag&&(0,O.jsx)(j.OL,{...s,options:[...t.options],size:"small",required:!0})]}),n&&!n.ok&&(0,O.jsx)(eU,{result:n,settings:i})]})};function eG(e){let t=(0,v.useMemo)(()=>e.context.path,[e]),{itemStore:n}=eh(),[i]=(0,v.useState)(()=>{let i=n.getState(t);return i.calculator&&i.calculator.hashString===e.value.hashString?i.calculator:void 0});return[i,(0,v.useCallback)(e=>{n.updateCalculatorState(t,e)},[t,n])]}let eB=({valueWithContext:e,inputResults:t,environment:n,settings:i,processAllFieldCodes:r,autorun:a})=>{let[l,s]=eG(e),o=(0,v.useMemo)(()=>e.value,[e]),[c,u]=(0,v.useState)(()=>l?.calculatorResult),d=(0,v.useCallback)(()=>{a||r();let e=[];for(let n=0;n<o.inputs.length;n++){let i=t[n];if(!i||!i.ok)return void u(void 0);e.push(i.value)}u(o.run(e,n))},[o,n,t,r,a]);return(0,v.useEffect)(()=>{a&&d()},[d,a]),(0,v.useEffect)(()=>{s({hashString:o.hashString,calculatorResult:c})},[s,o,c]),(0,O.jsxs)("div",{className:"py-3 px-5",children:[!a&&(0,O.jsx)("div",{className:"mb-3",children:(0,O.jsx)(j.$n,{size:"small",onClick:d,theme:"primary",children:"Run"})}),c?(0,O.jsxs)("div",{children:[(0,O.jsx)("div",{className:"text-sm font-semibold text-gray-700 mb-2",children:"Result"}),(0,O.jsx)(eU,{result:c,settings:i})]}):null]})};async function eH(e,t){if(!e)return;let n=p.SqProject.create();t&&n.setEnvironment(t);let i="calculator";return n.setSource(i,e),await n.run(i),n.getResult(i)}function eJ(e,t){return"boolean"==typeof t?t.toString():"select"===e.tag?`"${t}"`:t}function eK(e){return{inputs:e.inputs.map(e=>e.default??"")}}let e0=({calculator:e,children:t})=>{let{sampleCount:n}=e.value;return n&&(n<10||n>1e6)?(0,O.jsx)(_,{heading:`Calculator sampleCount must be between 10 and 1000000. It is set to ${n}.`}):t},e1=({settings:e,valueWithContext:t})=>{let n=(0,v.useMemo)(()=>((e,t)=>
1({sampleCount:t.sampleCount||e.sampleCount,xyPointLength:e.xyPointLength}))(t.context.project.getEnvironment(),t.value),[t]),{calculator:i,form:r,inputResults:a,processAllFieldCodes:l}=function(e,t){let n=(0,v.useMemo)(()=>e.value,[e]),[i,r]=eG(e),a=(0,eq.mN)({defaultValues:i?.formValues??eK(n)}),[l,s]=(0,v.useState)(()=>i?.inputResults??[]),o=(0,v.useMemo)(()=>n.hashString,[n]),[c,u]=(0,v.useState)(i?.hashString),d=(0,v.useCallback)(async()=>{let e=a.getValues(),i=[];for(let[r,a]of n.inputs.entries()){let n=e.inputs?.at(r);if(void 0===n)continue;let l=await eH(eJ(a,n),t);i[r]=l}s(i)},[n,t,a,s]);(0,v.useEffect)(()=>{c!==o&&(c&&a.reset(eK(n)),u(o),d())},[n,o,c,a,d]),(0,v.useEffect)(()=>{let e=a.watch(async(e,{name:i})=>{if(void 0===i)return;let r=parseInt(i.split(".")[1]);if(Number.isNaN(r))return;let a=e.inputs?.at(r);if(void 0===a)return;let l=n.inputs[r],o=await eH(eJ(l,a),t);s(e=>e.map((e,t)=>t===r?o:e))});return()=>e.unsubscribe()},[n,t,a]);let m=(0,v.useCallback)(()=>{r({hashString:o,formValues:a.getValues(),inputResults:l})},[l,a,o,r]);return(0,v.useEffect)(()=>m(),[m]),(0,v.useEffect)(()=>{let e=a.watch(()=>m());return()=>e.unsubscribe()},[m,a]),{calculator:n,form:a,inputResults:l,processAllFieldCodes:d}}(t,n),s=(0,v.useMemo)(()=>({...e,distributionChartSettings:{...e.distributionChartSettings,showSummary:!1},chartHeight:30}),[e]),o=(0,v.useMemo)(()=>({...e,chartHeight:200}),[e]),c=!!i.title||!!i.description;return(0,O.jsx)(eq.Op,{...r,children:(0,O.jsxs)("div",{className:"border border-slate-200 rounded-sm max-w-4xl mx-auto",children:[c&&(0,O.jsxs)("div",{className:"py-3 px-5 border-b border-slate-200 bg-slate-100 max-w-4xl",children:[i.title&&(0,O.jsx)("div",{className:"text-lg text-slate-900 font-semibold mb-1",children:i.title}),i.description&&(0,O.jsx)(eY,{md:i.description,textSize:"sm",textColor:"prose-slate"})]}),!!i.inputs.length&&(0,O.jsx)("div",{className:"py-3 px-5 border-b border-slate-200 bg-gray-50 space-y-3",children:i.inputs.map((e,t)=>(0,O.jsx)(eI,{id:t,input:e,result:a[t],settings:s},t))}),(0,O.jsx)(eB,{valueWithContext:t,inputResults:a,environment:n,processAllFieldCodes:l,autorun:i.autorun,settings:o})]})})};eR.register("Calculator",{Preview:()=>(0,O.jsx)(j.o3,{size:14,className:"opacity-40"}),Chart:(e,t)=>(0,O.jsx)(e0,{calculator:e,children:(0,O.jsx)(e1,{valueWithContext:e,settings:t})})});let e5=e=>{let t=e.tags.dateFormat();return t?L(e.value.toDate(),t):e.value.toString()};eR.register("Date",{Preview:e=>e5(e),Chart:e=>e5(e)}),eR.register("Dict",{heading:e=>`Dict(${e$(e.value).length})`,Preview:e=>(0,O.jsx)(eT,{type:"{}",count:e$(e.value).length}),Chart:e=>{let t=(0,v.useMemo)(()=>e$(e.value),[e]);return(0,O.jsx)("div",{className:"space-y-1 pt-0.5 mt-0.5",children:t.map(([t,n])=>(0,O.jsx)(it,{parentValue:e,value:n},t))})}});var e2=n(47222);function e4({defaultCode:e="",onCodeChange:t}){let[n,i]=(0,v.useState)(e);return{code:n,setCode:(0,v.useCallback)(e=>{i(e),t?.(e)},[t]),defaultCode:e}}var e3=n(70518),e6=n(96903),e8=n(20266);let e7={parse:e=>{let t=(0,p.parse)(e);if(!t.ok)throw Error(`Parse failed. ${t.value}`);return t.value},astFormat:"squiggle-ast",locStart:e=>e.location?e.location.start.offset:-1,locEnd:e=>e.location?e.location.end.offset:-1},{group:e9,indent:te,softline:tt,line:tn,hardline:ti,join:tr,ifBreak:ta}=n(14813).LX;function tl(e){switch(e.type){case"Ternary":return 1;case"InfixCall":{let t={"||":2,"&&":3,"==":4,"!=":4,"<=":5,"<":5,">=":5,">":5,to:6,"+":7,"-":7,".+":7,".-":7,"*":8,"/":8,".*":8,"./":8,"^":9,".^":9,"->":10,"|>":10}[e.op];if(void 0===t)throw Error(`Unknown operator ${e.op}`);return t}case"Pipe":return 11;case"UnaryCall":return 12;case"DotLookup":case"BracketLookup":case"Call":return 13;case"Block":if(1===e.statements.length)return tl(e.statements[0]);default:return 100}}let ts=[{name:"Squiggle",parsers:["squiggle"],extensions:[".squiggle"]}],to={},tc={},{languages:tu,parsers:td,printers:tm,options:th,defaultOptions:tx}=function(e){return{languages:ts,parsers:{squiggle:e7},printers:{"squiggle-ast":{print:(t,n,i)=>{let{node:r}=t,a=(e,t,n,i=!1)=>{let r=tl(t),a=tl(n);return(i?a<=r:a<r)?["(",e,")"]:e};switch(r.type){case"Program":return e9([r.imports.map((e,n)=>["import ",t.call(i,"imports",n,0)," as ",t.call(i,"imports",n,1),ti]),tr(ti,r.statements.map((r,a)=>[t.call(i,"statements",a),e.isNextLineEmpty(n.originalText,r.location.end.offset)?ti:""])),r.statements.length&&["LetStatement","DefunStatement"].includes(r.statements[r.statements.length-1].type)?ti:""]);
1case"Block":{if(1===r.statements.length&&!r.comments&&!r.statements[0].comments)return t.call(i,"statements",0);let a=tr(ti,r.statements.map((r,a)=>[t.call(i,"statements",a),e.isNextLineEmpty(n.originalText,r.location.end.offset)?ti:""]));return r.isLambdaBody?a:e9(["{",te([tn,a]),tn,"}"])}case"DecoratedStatement":return[t.call(i,"decorator"),ti,t.call(i,"statement")];case"Decorator":return e9(["@",t.call(i,"name"),r.args.length?["(",te([tt,tr([",",tn],t.map(i,"args"))]),tt,")"]:[]]);case"LetStatement":return e9([r.exported?"export ":"",r.variable.value," = ",t.call(i,"value")]);case"DefunStatement":return e9([r.exported?"export ":"",r.variable.value,e9(["(",te([tt,tr([",",tn],t.map(i,"value","args"))]),tt,")"])," = ",t.call(i,"value","body")]);case"Boolean":return r.value?"true":"false";case"Float":{let e=null===r.fractional?"":"."+(r.fractional.replace(/0*$/,"")||"0"),t=null===r.exponent?"":`e${r.exponent}`;return`${r.integer}${e}${t}`}case"Array":return e9(["[",r.elements.length?[te([tt,tr([",",tn],t.map(i,"elements"))]),ta(",",""),tt]:"","]"]);case"Call":return e9([t.call(i,"fn"),"(",te([tt,tr([",",tn],t.map(i,"args"))]),tt,")"]);case"InfixCall":let l=[0,1].map(e=>a(t.call(i,"args",e),r,r.args[e],1===e));return e9([l[0]," ",r.op,te([tn,l[1]])]);case"UnaryCall":return e9([r.op,a(t.call(i,"arg"),r,r.arg)]);case"Pipe":{let e=r.rightArgs.length?["(",te([tt,tr([",",tn],t.map(i,"rightArgs"))]),tt,")"]:[];return e9([a(t.call(i,"leftArg"),r,r.leftArg),te([tn,"-> ",a(t.call(i,"fn"),r,r.fn),e])])}case"DotLookup":return e9([t.call(i,"arg"),".",r.key]);case"BracketLookup":return e9([t.call(i,"arg"),"[",t.call(i,"key"),"]"]);case"Identifier":return r.value;case"IdentifierWithAnnotation":return[r.variable,": ",t.call(i,"annotation")];case"KeyValue":return e9(["String"===r.key.type&&r.key.value.match(/^[\$_a-z]+[\$_a-zA-Z0-9]*$/)?r.key.value:t.call(i,"key"),": ",t.call(i,"value")]);case"Lambda":return"Block"===r.body.type&&(r.body.isLambdaBody=!0),e9(["{",te([tt,e9(["|",te([tt,tr([",",tn],t.map(i,"args"))]),tt,"| "]),tt,t.call(i,"body")]),tt,"}"]);case"Dict":{let e=1===r.elements.length&&"Identifier"===r.elements[0].type;return e9(["{",r.elements.length?[te([tn,tr([",",tn],t.map(i,"elements"))]),e?",":ta(",",""),tn]:[],"}"])}case"String":return[JSON.stringify(r.value).replaceAll("\\n","\n")];case"Ternary":return["C"===r.kind?[]:"if ",t.call(i,"condition"),"C"===r.kind?" ? ":" then ",t.call(i,"trueExpression"),"C"===r.kind?" : ":" else ",t.call(i,"falseExpression")];case"UnitValue":return[t.call(i,"value"),r.unit];case"lineComment":case"blockComment":throw Error("Didn't expect comment node in print()")}},printComment:e=>{let t=e.node;switch(t.type){case"lineComment":return["//",t.value];case"blockComment":return["/*",t.value,"*/"];default:throw Error("Unknown comment type")}},isBlockComment:e=>"blockComment"===e.type,getCommentChildNodes:e=>{if(!e)return[];switch(e.type){case"Program":case"Block":return e.statements;case"Array":case"Dict":return e.elements;case"LetStatement":return[e.variable,e.value];case"DefunStatement":return[e.value];case"Call":return[...e.args,e.fn];case"Lambda":return[...e.args,e.body];case"KeyValue":return[e.key,e.value];default:return}},canAttachComment:e=>e&&e.type}},options:to,defaultOptions:tc}}(e8.ZS);async function tg(e){if(!e)return;let t=e.state.doc.toString(),{formatted:n,cursorOffset:i}=await e6.Ej(t,{parser:"squiggle",plugins:[r],cursorOffset:e.state.selection.main.to});e.dispatch({changes:{from:0,to:e.state.doc.length,insert:n},selection:{anchor:i}})}var tp=n(98958),tO=n(67e3),tf=n(77583),tb=n(11778),tv=n(74225);function tj(e,t,n){let[{compartment:i,extension:r}]=(0,v.useState)(()=>{let e=new tv.xx,n=e.of(t());return{compartment:e,extension:n}});return(0,v.useEffect)(()=>{e?.dispatch({effects:i.reconfigure(t())})},[e,...n]),r}var ty=n(67705);let tS="#00746a",tP="#60553f",tw="#003e7b",tQ=tf.cr.define([{tag:ty._A.keyword,fontWeight:"bold",color:"#096600"},{tag:[ty._A.name,ty._A.deleted,ty._A.character,ty._A.propertyName,ty._A.macroName],color:tS},{tag:[ty._A.function(ty._A.variableName),ty._A.constant(ty._A.variableName),ty._A.labelName],color:"#822500"},{tag:[ty._A.color,ty._A.constant(ty._A.name),ty._A.standard(ty._A.name)],color:tw},{tag:[ty._A.definition(ty._A.name),ty._A.separator],color:"#2a2111"},{tag:[ty._A.typeName,ty._A.className,ty._A.number,ty._A.changed,ty._A.annotation,t
1y._A.modifier,ty._A.self,ty._A.namespace],color:"#001063"},{tag:ty._A.escape,color:"#e10303"},{tag:[ty._A.operator,ty._A.operatorKeyword,ty._A.url,ty._A.regexp,ty._A.link,ty._A.special(ty._A.string)],fontWeight:"bold",color:"#341d0e"},{tag:ty._A.comment,color:tP},{tag:ty._A.strong,fontWeight:"bold"},{tag:ty._A.emphasis,fontStyle:"italic"},{tag:ty._A.strikethrough,textDecoration:"line-through"},{tag:ty._A.link,color:tP,textDecoration:"underline"},{tag:ty._A.heading,fontWeight:"bold",color:tS},{tag:[ty._A.atom,ty._A.bool,ty._A.special(ty._A.variableName)],color:tw},{tag:[ty._A.processingInstruction,ty._A.string,ty._A.inserted],color:"#9b2d00"},{tag:ty._A.invalid,color:"#000000"}]);var tC=n(29169);function tN({height:e,init:t,draw:n}){let[i,r]=(0,v.useState)(),[a,l]=(0,v.useState)(),s="undefined"==typeof window?1:window.devicePixelRatio,o=(0,v.useRef)(null),c=(0,v.useCallback)(e=>{e[0]&&(o.current&&clearTimeout(o.current),o.current=window.setTimeout(()=>{r(e[0].contentRect.width)},30))},[]),u=(0,v.useMemo)(()=>{if("undefined"!=typeof window)return new window.ResizeObserver(c)},[c]);(0,v.useEffect)(()=>()=>{o.current&&clearTimeout(o.current),u?.disconnect()},[u]);let d=(0,v.useCallback)(e=>{if(!e)return;let n=e.getBoundingClientRect().width;r(n);let i=e.getContext("2d");if(!i)throw Error("Failed to initialize 2d context");i.resetTransform(),i.scale(s,s),l(i),t?.({context:i,width:n}),u?.disconnect(),u?.observe(e)},[t,u,s]),m=(0,v.useCallback)(()=>{if(void 0===i||void 0===a)return;let{canvas:t}=a;t.style.height=`${e}px`,t.width=i*s,t.height=e*s,a.resetTransform(),a.scale(s,s),n({width:i,context:a})},[n,i,e,a,s]);return(0,v.useLayoutEffect)(()=>{m()},[m]),{ref:d,redraw:m,width:i}}function tk(){let[e,t]=(0,v.useState)();return{cursor:e,initCursor:(0,v.useCallback)(({context:e})=>{a.Ltv(e.canvas).on("touchmove",e=>e.preventDefault()).on("pointermove",e=>{let n=a.WnM(e);t({x:n[0],y:n[1]})}).on("pointerout",()=>{t(void 0)})},[])}}let t$=({defaultCode:e,onCodeChange:t,project:n,continues:i,environment:r,editorFontSize:a,...l})=>{let{code:s,setCode:o,defaultCode:c}=e4({defaultCode:e,onCodeChange:t}),{simulation:u,project:d,sourceId:m,runSimulation:h}=P({code:s,setup:n?{type:"project",project:n,continues:i}:{type:"standalone"},environment:r}),x=(0,v.useMemo)(()=>w(u),[u]),g=(0,v.useRef)(null);return(0,O.jsxs)("div",{children:[(0,O.jsx)("div",{className:"border border-slate-300 bg-slate-50 rounded-sm p-2","data-testid":"squiggle-editor",children:(0,O.jsx)(tY,{defaultValue:c??"",onChange:o,fontSize:a,showGutter:!1,errors:x,project:d,sourceId:m,ref:g,onSubmit:h})}),u?(0,O.jsx)(id,{simulation:u,editor:g.current??void 0,playgroundSettings:l}):null]})},tA=({children:e})=>(0,O.jsx)("div",{className:(0,E.$)("py-2"),children:e}),tR=({fullName:e,def:t})=>{let n="text-slate-900",i="text-slate-400",r=t.inputs.map((e,r)=>(0,O.jsxs)("span",{children:[(0,O.jsx)("span",{className:n,children:e.display()}),(e=>void 0!==e.isOptional&&e.isOptional)(e)?(0,O.jsx)("span",{className:n,children:"?"}):"",r!==t.inputs.length-1&&(0,O.jsx)("span",{className:i,children:", "})]},r)),a=t.output.display();return(0,O.jsxs)("div",{children:[(0,O.jsx)("span",{className:"text-slate-500",children:e}),(0,O.jsx)("span",{className:i,children:"("}),(0,O.jsx)("span",{className:(0,E.$)(n,"ml-0.5 mr-0.5"),children:r}),(0,O.jsx)("span",{className:i,children:")"}),a?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)("span",{className:i,children:" => "})," ",(0,O.jsx)("span",{className:n,children:a})]}):""]})},tT=({documentation:e,showNameAndDescription:t=!0,size:n="small"})=>{let{name:i,nameSpace:r,requiresNamespace:a,isUnit:l,shorthand:s,isExperimental:o,description:c,definitions:u,examples:d,versionAdded:m}=e,h="small"===n?"text-xs":"text-sm",x=`${r?r+".":""}${i}`,g=(0,E.$)("font-medium py-0.5 rounded",h,"small"===n?"px-1.5":"px-2.5");return(0,O.jsxs)(O.Fragment,{children:[t&&(0,O.jsx)(tA,{children:(0,O.jsxs)("div",{className:"flex flex-nowrap items-end justify-between gap-2 py-0.5",children:[(0,O.jsx)("a",{href:`https://www.squiggle-language.com/docs/Api/${r}#${i}`,target:"_blank",rel:"noreferrer",className:(0,E.$)("text-blue-500 hover:underline leading-none","small"===n?"text-sm":"text-md"),children:x}),(0,O.jsx)("div",{className:(0,E.$)("italic leading-none text-slate-500",h),children:"Stdlib"})]})}),(l||s||o||!a||m)&&(0,O.jsx)(tA,{children:(0,O.jsxs)("div",{className:"flex gap-3",children:[l&&(0,O.jsx)("div",{className:(0,E.$)("bg-yellow-100 text-yellow-800",g),children:"Unit"}),s&&(0,O.jsxs)("div",{className:(0,E.$)("bg-orange-100 text-gray-500",g),children:[`${s.type}: `,(0,O.jsx)("span",{className:"font-mono ml-2 text-orange-800",children:s.symbol})]}),o&&(0,O.jsx)("div",{className:(0,E.$)("bg-red-100 text-red-800",g),children:"Experimental"}),!a&&(0,O.jsx)("div",{className:(0,E.$)("bg-purple-50 text-slate-600",g),children:"Namespace optional"}),m&&(0,O.jsxs)("div",{className:(0,E.$)("bg-purple-50 text-slate-600",g),children:["v",m]})]})}),c&&t?(0,O.jsx)(tA,{children:(0,O.jsx)(eY,{md:c,textColor:"prose-slate",textSize:"small"===n?"xs":"sm"})}):null,u?(0,O.jsxs)(tA,{children:[(0,O.jsx)("header",{className:(0,E.$)("text-slate-600 font-medium mb-2",h),children:"Signatures"}),(0,O.jsx)("div",{className:(0,E.$)("text-slate-600 font-mono p-2 bg-slate-100 rounded-md space-y-2",h),children:u.filter(e=>!e.deprecated).map((e,t)=>(0,O.jsx)(tR,{fullName:x,def:e},t))})]}):null,d?.length?(0,O.jsxs)(tA,{children:[(0,O.jsx)("header",{className:(0,E.$)("text-slate-600 font-medium mb-2",h),children:"Examples"}),d&&d.map(({text:e,isInteractive:t},i)=>t?(0,O.jsx)("div",{className:"pt-2 pb-4",children:(0,O.jsx)(t$,{defaultCode:e,editorFontSize:"small"===n?12:13,chartHeight:"small"===n?30:40})},i):(0,O.jsx)(eY,{className:"max-width-[200px]",md:`\`\`\`squiggle 2${e} 3\`\`\``,textSize:"sm"},i))]}):null]})},tE=({functionName:e,showNameAndDescription:t=!0,size:n})=>{let i=(0,p.getFunctionDocumentation)(e);return i?(0,O.jsx)(tT,{documentation:i,showNameAndDescription:t,size:n}):null};var tq=n(3060);function t_(e){let t=document.createElement("div");return(0,tq.createRoot)(t).render(e),{dom:t}}var tV=n(73520);let tz={__proto__:null,import:11,as:19,export:23,true:30,false:30,if:97,then:99,else:101,to:153},tW=tV.U1.deserialize({version:14,states:":QQ`QPOOP!dOPOOO!lOQO'#CbO!zOQO'#CbOOQO'#EW'#EWQ`QPOOO$|QPO'#ChOOQO'#Cj'#CjO&RQPO'#CmQ&`QPOOO(qQPO'#DeO'yQPO'#DfOOQO'#Er'#ErOOQO'#Eq'#EqO'yQPO'#EqO(xQPO'#CfO(}QPO'#D}O)SQPO'#EQO)XQPO'#EPOOQO'#Ep'#EpOOQO'#EZ'#EZQ)dQPOOO(iQPO'#C`O'yQPO'#D]O)_QPO'#CfP)kO`O'#C]POOO'#Ee'#EePOOO)C@W)C@WO)vOSO'#CcOOOO'#EX'#EXO){OQO,58|OOQO,58|,58|O*ZOSO'#CdOOOO'#E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!U!V!W!X!_!t!u#[#b#d#e#p#s#t#w$U$f$g$j$s$w$x$y$z${$|$}%O%P%S%T%VQwWR$Z#sR{WR#Q!PR![YR$P#b",nodeNames:"â BlockComment LineComment Program Import import String Escape Escape as LetStatement export VariableName Equals Boolean Boolean Number Block { } Dict KeyValue Field InheritEntry Field , KeyValue Field InheritEntry Field Lambda ArgsOpen LambdaArgs LambdaParameter LambdaParameterName Identifier AccessExpr . Field Call ( Argument Argument ) TernaryC LogicOp LogicOp Ter
3naryIfThenElse if then else BracketLookup [ Key ] Array UnaryCall ArithOp ArithOp ArithOp InfixCall LogicOp LogicOp LogicOp LogicOp LogicOp LogicOp LogicOp ArithOp ArithOp ArithOp ArithOp ArithOp ArithOp ArithOp ArithOp ArithOp Pipe ControlOp DefunStatement VariableName DecoratedStatement Decorator At DecoratorName Argument Argument",maxTerm:122,nodeProps:[["group",-2,1,2,"Comment",-16,6,14,16,17,20,30,35,36,39,44,47,51,55,56,60,77,"Expression",-3,10,79,81,"Statement"]],skippedNodes:[0,1,2,87],repeatNodeCount:10,tokenData:"7RnR!TYZ$bpq$iqr${rs%Sst%Ztu%`uv%Zvw&twx'Rxy'Yyz'az{'h{|'o|}'v}!O'}!O!P(^!P!Q,p!Q![-m![!]/k!]!^/t!^!_/{!_!`0[!`!a0k!a!b0z!b!c1R!c!}%`!}#O1Y#O#P1a#P#Q1h#Q#R1o#R#S%`#S#T%Z#T#U%`#U#V1v#V#Y%`#Y#Z1v#Z#b%`#b#c1v#c#f%`#f#g1v#g#h%`#h#i1v#i#j2i#j#o%`#o#p6^#p#q6e#q#r6t#r$g%Z$g;'S%`;'S;=`6{<%lO%`f$iO#`S#Wbf$pP#`S#Vbpq$sb$xP#Vbpq$sU%SO#`S![Q^%ZO#_U#cWS%`O#`Sf%gW#`S#^btu&P!Q![&P!c!}&P#R#S&P#T#o&P$g;'S&P;'S;=`&n<%lO&Pb&UW#^btu&P!Q![&P!c!}&P#R#S&P#T#o&P$g;'S&P;'S;=`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Z3`#Z#o&P$g;'S&P;'S;=`&n<%lO&Pj3eY#^btu&P!Q![4T!c!i4T!i!}&P#R#S&P#T#Z4T#Z#o&P$g;'S&P;'S;=`&n<%lO&Pj4YY#^btu&P!Q![4x!c!i4x!i!}&P#R#S&P#T#Z4x#Z#o&P$g;'S&P;'S;=`&n<%lO&Pj4}Y#^btu&P!Q![5m!c!i5m!i!}&P#R#S&P#T#Z5m#Z#o&P$g;'S&P;'S;=`&n<%lO&Pj5tW#cW#^btu&P!Q![&P!c!}&P#R#S&P#T#o&P$g;'S&P;'S;=`&n<%lO&PU6eObQ#`Sf6lP#jQ#`S#p#q6ob6tO!_bU6{OcQ#`Sf7OP;=`<%l%`",tokenizers:[1,2,3,4,new tV.uC("j~RQYZXz{^~^O#[~~aP!P!Qd~iO#]~~",25,103)],topRules:{Program:[0,3]},dynamicPrecedences:{22:1,27:1},specialized:[{term:106,get:e=>tz[e]||-1}],tokenPrec:2497}).configure({props:[(0,ty.pn)({"if then else import export as":ty._A.keyword,Equals:ty._A.definitionOperator,ArithOp:ty._A.arithmeticOperator,LogicOp:ty._A.logicOperator,ControlOp:ty._A.controlOperator,"{ }":ty._A.brace,"[ ]":ty._A.squareBracket,"( )":ty._A.paren,"|":ty._A.squareBracket,",":ty._A.separator,Syntax:ty._A.annotation,Boolean:ty._A.bool,Number:ty._A.integer,String:ty._A.string,LineComment:ty._A.lineComment,BlockComment:ty._A.blockComment,Escape:ty._A.escape,DecoratorName:ty._A.variableName,"Decorator/*/String":ty._A.comment,At:ty._A.keyword,VariableName:ty._A.constant(ty._A.variableName),Identifier:ty._A.variableName,Field:ty._A.variableName,LambdaParameterName:ty._A.variableName}),tf.b_.add({Lambda:e=>({from:e.getChild("NonEmptyProgram")?.from||0,to:e.getChild("NonEmptyProgram")?.to||0}),Block:tf.yd,Dict:tf.yd,Array:tf.yd}),tf.Oh.add({Dict:e=>e.baseIndent+("}"===e.textAfter?0:e.unit),Block:e=>e.baseIndent+("}"===e.textAfter?0:e.unit),Lambda:e=>e.baseIndent+("}"===e.textAfter?0:e.unit),Array:e=>e.baseIndent+("]"===e.textAfter?0:e.unit)})]}),tD=({view:e,children:t})=>((0,v.useEffect)(()=>{(0,e3.Pq)(e)}),(0,O.jsx)("div",{className:"border rounded-sm shadow-lg h-full overflow-y-auto",children:t})),tM=({value:e,view:t})=>{let{globalSettings:n}=eh();return k(e)?(0,O.jsx)(tD,{view:t,children:(0,O.jsx)("div",{className:"px-4 py-1",children:(0,O.jsx)(ev,{partialPlaygroundSettings:n,viewerType:"tooltip",rootValue:e,children:(0,O.jsx)(eZ,{value:e,settings:n})})})}):null},tX=({hover:e,view:t})=>(0,O.jsx)(tD,{view:t,children:(0,O.jsx)("div",{className:"min-w-[200px] max-w-[600px] px-2",children:(0,O.jsx)(tT,{documentation:e})})});
3function tL(e,t){return{pos:e.from,end:e.to,above:!0,create:()=>t_(t)}}let tF=e3.Lz.baseTheme({".cm-tooltip-hover":{backgroundColor:"white !important",border:"0 !important"},".cm-tooltip-section":{height:"100%"}}),tY=(0,v.forwardRef)(function(e,t){let{view:n,ref:i}=function({defaultValue:e,...t}){var n;let[i,r]=(0,v.useState)(),a=function(e,t){var n,i,r,a,l;let s=(0,v.useMemo)(()=>[(0,e3.N$)(),(0,tO.b6)(),(0,e3.VH)(),(0,e3.A)(),tv.$t.allowMultipleSelections.of(!0),(0,tf.WD)(),(0,tf.y9)(tQ,{fallback:!0}),(0,tf.SG)(),(0,tp.wm)(),(0,tp.yU)(),(0,tb.gN)({wholeWords:!0,highlightWordAroundCursor:!1}),e3.w4.of([...tp.Bc,...tO.pw,...tb.Eo,...tO.cL,...tf.f7,...tp.OO,tO.Yc])],[]),o=tj(e,()=>{var e;return e=n,new tf.Yy(tf.bj.define({name:"squiggle",parser:tW,languageData:{commentTokens:{line:"//"},autocomplete:function(e){let t=[],n=[],i=e=>()=>t_((0,O.jsx)(tE,{functionName:e}));for(let[r,a]of e.getStdLib().entrySeq())if(t.push({label:r,info:i(r),type:"Lambda"===a.type?"function":"variable"}),"Lambda"===a.type&&a.value.isDecorator&&r.startsWith("Tag.")){let e=r.split(".")[1];n.push({label:`@${e}`,apply:e,info:i(r),type:"function"})}return e=>{let i=(0,tf.mv)(e.state);{let t=e.tokenBefore(["ArgsOpen"]);if(t)return{from:t.from,options:[(0,tp.Gw)("|${args}| ${body}",{label:"|",detail:"lambda function",type:"text"})]}}{let n=e.tokenBefore(["AccessExpr","Identifier"]);if(n){let{from:r}=n,a=(function(e,t){let n=e.cursorAt(t,-1),i=[],r="start";for(;;){if(n.type.is("Statement")&&"sibling"===r){let e=n.node;for(;e&&e.type.is("DecoratedStatement");)e=e.getChild("Statement");let t=e?.getChild("VariableName");e&&t&&i.push({node:t,type:e?.type.is("DefunStatement")?"function":"variable"})}else if(n.type.is("DefunStatement")&&"sibling"!==r)for(let e of n.node.getChild("LambdaArgs")?.getChildren("LambdaParameter")??[]){let t=e.getChild("LambdaParameterName");t&&i.push({node:t,type:"variable"})}if(n.prevSibling())r="sibling";else if(n.parent())r="parent";else break}return i})(i,r).map(t=>({label:e.state.doc.sliceString(t.node.from,t.node.to),type:t.type}));return{from:r,options:[...a,...t]}}}{let t=e.tokenBefore(["DecoratorName"]);if(t)return{from:t.from,options:n}}return null}}(e),closeBrackets:{brackets:['"',"'","(","{"]}}}),[])},[n=t.project]),c=tj(e,()=>i?[(0,e3.$K)(),(0,e3.dz)(),(0,e3.Wu)(),(0,tf.Lv)()]:[],[i=t.showGutter??!1]),u=tj(e,()=>r?[e3.Lz.lineWrapping]:[],[r=t.lineWrapping??!0]),d=tj(e,()=>e3.w4.of([{key:"Mod-Enter",run:()=>(a?.(),!0)}]),[a=t.onSubmit]),m=tj(e,()=>e3.Lz.updateListener.of(e=>{e.docChanged&&l(e.state.doc.toString())}),[l=t.onChange]),h=function(e,{width:t,height:n}){return tj(e,()=>e3.Lz.theme({"&":{...void 0===t?{}:{width:t},...void 0===n?{}:{height:n}},".cm-selectionMatch":{backgroundColor:"#33ae661a"},".cm-content":{padding:0},":-moz-focusring.cm-content":{outline:"none"}}),[t,n])}(e,{width:t.width,height:t.height}),x=function(e,{project:t,sourceId:n,onViewValuePath:i}){let r=(0,v.useCallback)(()=>{if(!i||!e||!n)return;let r=e.state.selection.main.to;if(void 0===r)return;let a=t.findValuePathByOffset(n,r);a.ok&&i(a.value)},[i,t,n,e]);return tj(e,()=>e3.w4.of([{key:"Alt-Shift-v",run:()=>(r(),!0)}]),[r])}(e,{project:t.project,onViewValuePath:t.onViewValuePath,sourceId:t.sourceId}),g=(0,v.useMemo)(()=>e3.w4.of([{key:"Alt-Shift-f",run:e=>(tg(e),!0)}]),[]),f=function(e,t=[]){return(0,v.useEffect)(()=>{if(!e)return;let n=e.state.doc.length;e.dispatch((0,tC.LH)(e.state,t.map(e=>{if(!(e instanceof p.SqCompileError||e instanceof p.SqRuntimeError))return;let t=e.location();if(t)return{location:t,err:e}}).filter(e=>!!(e&&e.location&&e.location.end.offset<n)).map(e=>({from:e.location.start.offset,to:e.location.end.offset,severity:"error",message:e.err.toString()}))))},[e,t]),[]}(e,t.errors);return[[d],s,[c,u,m,h,x,g,f,function(e,{project:t,sourceId:n,renderImportTooltip:i}){return tj(e,()=>[function({project:e,sourceId:t,renderImportTooltip:n}){return(0,e3.Ux)((i,r,a)=>{let{doc:l}=i.state,s=(0,tf.mv)(i.state).cursorAt(r,a),o=e=>l.sliceString(e.from,e.to),c=e=>{let t=(0,p.getFunctionDocumentation)(o(e));return t?tL(e,(0,O.jsx)(tX,{hover:t,view:i})):null};switch(s.name){case"String":{let t=s.node;if(!s.parent())return null;if(s.type.is("Import")&&n){let r=o(t).slice(1,-1);return tL(t,(0,O.jsx)(tD,{view:i,children:n({project:e,importId:r})}))}break}case"Identifier":if(o(s.node).match(/^[A-Z]/))break;return c(s.node);case"Field":if(!s.parent())break;return c(s.node);case"VariableName":{let n=s.node;if(!s.parent())return null;for(;s.type.is("Statement")&&s.parent(););
3if(!s.type.is("Program"))return null;let r=o(n),a=e.getBindings(t);if(!a.ok)return null;let l=a.value.get(r);if(!l)return null;let c=l.context?.valueAst;if(!c)return null;if(("LetStatement"===c.type||"DefunStatement"===c.type)&&c.variable.location.start.offset===n.from&&c.variable.location.end.offset===n.to)return tL(n,(0,O.jsx)(tM,{value:l,view:i}))}}return null})}({project:t,sourceId:n,renderImportTooltip:i}),tF],[t,n,i])}(e,{project:t.project,sourceId:t.sourceId,renderImportTooltip:t.renderImportTooltip}),o]]}(i,t),l=(n={extensions:a,doc:e},(0,v.useEffect)(()=>{if("undefined"==typeof window)return;let e=tv.$t.create(n);return r(new e3.Lz({state:e})),()=>{i?.destroy()}},[]),(0,v.useCallback)(e=>{i&&e?.replaceChildren(i.dom)},[i]));return{view:i,ref:l}}(e),r=(e,t)=>{n&&(n.dispatch({selection:{anchor:e},scrollIntoView:!0}),t&&n.focus())};return(0,v.useImperativeHandle)(t,()=>({format:()=>tg(n),scrollTo:r})),(0,O.jsx)("div",{style:{fontSize:e.fontSize||"13px"},ref:i})}),tZ=({icon:e,iconClasses:t,iconSpin:n,className:i,onClick:r,tooltipText:a,children:l})=>{let s=l?"h-3 w-3":"h-5 w-5",o=(0,O.jsxs)("div",{className:(0,E.$)("flex items-center text-slate-600 space-x-1 text-sm px-4 h-full cursor-pointer hover:bg-slate-200 select-none whitespace-nowrap transition ",i),onClick:r,children:[e&&(0,O.jsx)(e,{className:(0,E.$)(s,"flex-shrink-0 text-slate-400",t,n&&"animate-spin")}),l&&(0,O.jsx)("div",{className:"flex",children:l})]});return a?(0,O.jsx)(j.fp,{text:a||"",placement:"bottom",offset:5,children:o}):o};function tU({renderToolbar:e,renderBody:t,renderModal:n}){let[i,r]=(0,v.useState)(),a=(0,v.useCallback)(e=>{r(e)},[]),l=(0,v.useCallback)(()=>{r(void 0)},[]),s=i?n?.(i):void 0,o=s&&(0,O.jsxs)("div",{className:"h-full flex gap-2",children:[(0,O.jsx)(tZ,{className:"flex-grow-0 flex-shrink-0 w-20",onClick:l,children:"â Back"}),(0,O.jsx)("div",{className:"flex-grow flex-shrink text-center self-center text-sm text-slate-600 font-semibold",children:s.title}),(0,O.jsx)("div",{className:"flex-grow-0 flex-shrink-0 w-20 invisible"})]});return(0,O.jsxs)("div",{className:"h-full flex flex-col",children:[(0,O.jsx)("div",{className:"h-8 bg-slate-50 border-b border-slate-200 overflow-hidden mb-1 px-4",children:s?o:(0,O.jsx)("div",{className:"h-full grid place-items-stretch",children:e({openModal:a})})}),(0,O.jsx)("div",{className:"flex-1 grid place-items-stretch overflow-auto",children:s?(0,O.jsxs)("div",{className:"px-4 py-4",children:[" ",s.body," "]}):t()})]})}let tI=({setAutorunMode:e,autorunMode:t})=>(0,O.jsx)("div",{"data-testid":"autorun-controls",className:"h-full","aria-checked":t,children:(0,O.jsx)(tZ,{tooltipText:"Triggers runs on code changes",icon:t?j.DQ:j.E$,className:(0,E.A)(!t&&"opacity-60"),onClick:()=>e(!t),children:"Autorun"})}),tG=(0,v.lazy)(()=>Promise.all([n.e(47054),n.e(82368),n.e(80392)]).then(n.bind(n,58011))),tB=({project:e})=>{let t=e.getSourceIds(),n="graph TD\n";for(let i of t)for(let t of(n+=`${i} 4`,e.getDependencies(i)))n+=`${i} --> ${t} 5`;return(0,O.jsx)("div",{className:"flex flex-col items-center",children:(0,O.jsx)(tG,{children:n})})},tH=({settings:e,onSettingsChange:t})=>{let n=(0,eq.mN)({resolver:(0,e2.u)(ee),defaultValues:e,mode:"onChange"});return(0,v.useEffect)(()=>{let e=n.handleSubmit(t),i=n.watch(()=>e());return()=>i.unsubscribe()},[n,t]),(0,O.jsx)(eq.Op,{...n,children:(0,O.jsx)(es,{})})};var tJ=n(25042);let tK=({runSimulation:e,autorunMode:t,isSimulating:n,codeHasChanged:i})=>{let r=!t&&n,a=`Run (${C()?"Cmd":"Ctrl"}+Enter)`;return(0,O.jsx)(tZ,{tooltipText:a,icon:r?tJ.A:j.ud,iconSpin:r,className:(0,E.A)(!i&&"opacity-40"),onClick:e,children:"Run"})},t0=(0,v.forwardRef)(function(e,t){let n=(0,v.useMemo)(()=>w(e.simulation),[e.simulation]),i=(0,v.useRef)(null),r=(0,v.useRef)(null);return(0,v.useImperativeHandle)(t,()=>({getEditor:()=>i.current,getLeftPanelElement:()=>r.current})),(0,O.jsx)("div",{ref:r,className:"h-full",children:(0,O.jsx)(tU,{renderBody:()=>(0,O.jsx)("div",{"data-testid":"squiggle-editor",style:{display:"contents"},children:(0,O.jsx)(tY,{ref:i,defaultValue:e.code,errors:n,height:"100%",project:e.project,sourceId:e.sourceId,showGutter:!0,lineWrapping:e.settings.editorSettings.lineWrapping,onChange:e.setCode,onSubmit:e.runSimulation,onViewValuePath:e.onViewValuePath,renderImportTooltip:e.renderImportTooltip})}),renderToolbar:({openModal:t})=>(0,O.jsxs)("div",{className:"flex",children:[(0,O.jsx)(tK,{runSimulation:e.runSimulation,autorunMode:e.autorunMode,codeHasChanged:e.code!==e.simulation?.code,isSimulating:!!e.simulation&&y(e.simulation)}
5),(0,O.jsx)(tI,{setAutorunMode:e.setAutorunMode,autorunMode:e.autorunMode}),(0,O.jsx)(tZ,{tooltipText:`Format Code (${C()?"Option":"Alt"}+Shift+f)`,icon:j.Ve,onClick:i.current?.format}),(0,O.jsx)(j.ms,{render:()=>(0,O.jsxs)(j.rI,{children:[(0,O.jsx)(j.GJ,{title:"Configuration",icon:j.S,onClick:()=>t("settings")}),(0,O.jsx)(j.GJ,{title:"Dependency Graph",icon:j.iq,onClick:()=>t("dependency-graph")}),e.renderExtraDropdownItems?.({openModal:t})]}),children:(0,O.jsx)(tZ,{icon:j.o7,iconClasses:"rotate-180",children:"Menu"})}),(0,O.jsx)("div",{className:"flex-1",children:e.renderExtraControls?.({openModal:t})})]}),renderModal:t=>{switch(t){case"settings":return{title:"Configuration",body:(0,O.jsx)(tH,{settings:e.settings,onSettingsChange:e.onSettingsChange})};case"dependency-graph":return{title:"Dependency Graph",body:(0,O.jsx)(tB,{project:e.project})};default:return e.renderExtraModal?.(t)}}})})});var t1=n(40269);let t5=({renderLeft:e,renderRight:t,height:n})=>{let[i,r]=(0,v.useState)(),a=(0,v.useRef)(null);(0,v.useEffect)(()=>{a.current&&r(a.current.offsetWidth/2)},[]);let l=(0,v.useRef)(0),s=e=>(t,{deltaX:n})=>{if(void 0===i)return;let a=(e=>{let t=e;return e+=l.current,e=Math.max(20,e),l.current=l.current+(t-e),e})(i+n);a!==i&&("persist"in t&&t.persist(),r(a)),"onResizeStop"===e&&(l.current=0)},o=(0,v.useRef)(null);return(0,O.jsxs)("div",{className:"flex items-stretch",ref:a,style:{height:n},children:[(0,O.jsxs)("div",{className:(0,E.$)("relative",!i&&"w-1/2"),style:{width:i},children:[e(),(0,O.jsx)(t1.DraggableCore,{nodeRef:o,onStop:s("onResizeStop"),onStart:s("onResizeStart"),onDrag:s("onResize"),children:(0,O.jsx)("div",{ref:o,className:"absolute top-0 h-full border-l border-slate-300 hover:border-blue-500 transition cursor-ew-resize",style:{width:5,right:-5}})})]}),(0,O.jsx)("div",{className:"flex-1 flex flex-col overflow-y-auto",children:t()})]})},t2=v.createContext({getLeftPanelElement:()=>void 0}),t4=e=>{let{defaultCode:t,linker:n,onCodeChange:i,onExportsChange:r,onSettingsChange:a,renderExtraControls:l,renderExtraDropdownItems:s,renderExtraModal:o,renderImportTooltip:c,height:u=500,...d}=e,[m,h]=(0,v.useState)(()=>W({},et,Object.fromEntries(Object.entries(d).filter(([,e])=>void 0!==e)))),x=(0,v.useCallback)(e=>{h(e),a?.(e)},[a]),{code:g,setCode:p}=e4({defaultCode:t,onCodeChange:i}),{project:f,simulation:b,sourceId:y,autorunMode:S,setAutorunMode:w,runSimulation:Q}=P({code:g,setup:{type:"projectFromLinker",linker:n},environment:m.environment});(0,v.useEffect)(()=>{let e=b?.output;if(e&&e.ok){let t=e.value.exports.entries().map(e=>({variableName:e[0],variableType:e[1].tag,title:e[1].title(),docstring:e[1].context?.docstring()||""}));r&&r(t)}else r&&r([])},[b,r]);let C=(0,v.useRef)(null),N=(0,v.useRef)(null),k=(0,v.useCallback)(()=>C.current?.getLeftPanelElement()??void 0,[]);return(0,O.jsx)(t2.Provider,{value:{getLeftPanelElement:k},children:(0,O.jsx)(t5,{height:u,renderLeft:()=>(0,O.jsx)(t0,{project:f,code:g,setCode:p,sourceId:y,simulation:b,settings:m,onSettingsChange:x,renderExtraControls:l,renderExtraDropdownItems:s,renderExtraModal:o,onViewValuePath:e=>N.current?.viewValuePath(e),renderImportTooltip:c,ref:C,autorunMode:S,setAutorunMode:w,runSimulation:Q}),renderRight:()=>b?(0,O.jsx)(id,{simulation:b,editor:C.current?.getEditor()??void 0,playgroundSettings:m,ref:N}):(0,O.jsx)("div",{className:"grid place-items-center h-full",children:(0,O.jsx)(j.fN,{className:"animate-spin text-slate-400",size:24})})})})},t3=({value:e,metaSettings:t,withFunctionSettings:n})=>{let i=(0,j.py)(),r=function(){let{itemStore:e}=eh();return(t,n)=>{e.setState(t,()=>n),e.forceUpdate(t)}}(),{path:a}=e.context,l=ef(a),s=(0,eq.mN)({resolver:(0,e2.u)(ee),defaultValues:l,mode:"onChange"});(0,v.useEffect)(()=>{let e=s.handleSubmit(e=>{r(a,{collapsed:!1,settings:e})}),t=s.watch(()=>e());return()=>t.unsubscribe()},[r,a,s]);let{getLeftPanelElement:o}=(0,v.useContext)(t2),{itemStore:c}=(0,v.useContext)(em);return(0,O.jsxs)(j.aF,{container:o(),close:i,children:[(0,O.jsxs)(j.aF.Header,{children:["Chart settings",a.edges.length?(0,O.jsxs)(O.Fragment,{children:[" for ",(0,O.jsx)("span",{title:"Scroll to item",className:"cursor-pointer",onClick:()=>{c.scrollViewerToPath(a)},children:function(e){return[eS(e),...e.edges.map(e=>e.toDisplayString())].join(".")}(a)})]}):""]}),(0,O.jsx)(j.aF.Body,{children:(0,O.jsx)(eq.Op,{...s,children:(0,O.jsx)(es,{withGlobalSettings:!1,withFunctionSettings:n,metaSettings:t})})})]})},t6=e=>{let t=(0,j.py)(),n=function(){let{itemStore:e}=eh();return t=>{e.setState(t,e=>({...e,settings:{}})),e.forceUpdate(t)}}();return(0,O.jsx)(j.GJ,{onClick:()=>{n(e.value.context.path),t()},title:"Reset Settings",icon:j.NA})},t8=e=>{let t=eg(e.value.context.path);return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(j.vr,{title:"Chart Settings",icon:j.Zb,render:()=>(0,O.jsx)(t3,{...e})}),t&&(0,O.jsx)(t6,{...e})]})},t7=e=>e.continuous.some(e=>e.x<=0)||e.discrete.some(e=>e.x<=0);var t9=n(90487);
5class ne{constructor(e){this.context=e.context,this.x0=e.x0,this.y0=e.y0,this.width=e.width,this.height=e.height}translatedPoint(e){return{x:e.x-this.x0,y:this.y0-e.y}}containsPoint(e){return e.x>=this.x0&&e.x-this.x0<=this.width&&e.y<=this.y0&&this.y0-e.y<=this.height}enter(){this.context.save(),this.context.translate(this.x0,this.y0),this.context.scale(1,-1)}exit(){this.context.restore()}fillText(e,t,n,i={}){this.context.save(),this.context.scale(1,-1),void 0!==i.textAlign&&(this.context.textAlign=i.textAlign),void 0!==i.font&&(this.context.font=i.font),void 0!==i.fillStyle&&(this.context.fillStyle=i.fillStyle),void 0!==i.textBaseline&&(this.context.textBaseline=i.textBaseline),this.context.fillText(e,t,-n),this.context.restore()}}let nt="rgba(114, 125, 147, 0.1)",nn="rgb(114, 125, 147)",ni="rgba(114, 125, 147, 0.4)",nr="#4c78a8",na="rgb(100 116 139)",nl="bold 12px ui-sans-serif, system-ui",ns="10px sans-serif",no=a.m4Y().domain([4e4,1e6]).range([3,16]).clamp(!0);function nc({context:e,xScale:t,yScale:n,suggestedPadding:i,width:r,height:a,showYAxis:l=!0,showXAxis:o=!0,showAxisLines:c=a>150&&r>150,xTickCount:u,yTickCount:d,xTickFormat:m=s,yTickFormat:h=s,xAxisTitle:x,yAxisTitle:g}){let p=u||no(r*a),O=d||no(a*r),f=t.ticks(p),b=t.tickFormat(p,m),v=n.ticks(O),j=n.tickFormat(O,h),y={...i};x&&(y.bottom=y.bottom+20),g&&(y.left=y.left+35),l&&v.forEach(t=>{let n=e.measureText(j(t));y.left=Math.max(y.left,n.actualBoundingBoxLeft+n.actualBoundingBoxRight+6)});let S=new ne({context:e,x0:y.left,y0:a-y.bottom,width:r-y.left-y.right,height:a-y.top-y.bottom});if(t.range([0,S.width]),n.range([0,S.height]),o){S.enter(),c&&(e.beginPath(),e.strokeStyle=nt,e.lineWidth=1,e.moveTo(0,0),e.lineTo(S.width,0),e.stroke()),e.fillStyle=nn,e.font=ns;let n=-y.left;for(let i=0;i<f.length;i++){let r=f[i],a=t(r);e.beginPath(),e.strokeStyle=nn,e.lineWidth=1,e.moveTo(a,0),e.lineTo(a,-2),e.stroke();let l=b(r);if(""===l)continue;let{width:s}=e.measureText(l),o=0;(o=0===i?Math.max(a-s/2,n):i===f.length-1?Math.min(a-s/2,S.width-s):a-s/2)<n||(S.fillText(l,o,-6,{textAlign:"left",textBaseline:"top"}),n=o+s)}S.exit()}if(l){S.enter(),c&&(e.beginPath(),e.strokeStyle=nt,e.lineWidth=1,e.moveTo(0,0),e.lineTo(0,S.height),e.stroke());let t=-y.bottom;for(let i=0;i<v.length;i++){let r=v[i];e.beginPath();let a=n(r),l=j(r);e.textBaseline="bottom";let{actualBoundingBoxAscent:s}=e.measureText(l);e.beginPath(),e.strokeStyle=nn,e.lineWidth=1,e.moveTo(0,a),e.lineTo(-2,a),e.stroke();let o=0;(o=0===i?Math.max(a-s/2,t):i===v.length-1?Math.min(a-s/2,S.height-s):a-s/2)<t||(S.fillText(l,-6,o-1,{textAlign:"right",textBaseline:"bottom",fillStyle:nn,font:ns}),t=o+s)}S.exit()}if(x){let t=r-y.left-y.right,n=y.left+t/2,i=a-y.bottom+33;e.textAlign="center",e.textBaseline="bottom",e.font=nl,e.fillStyle=na,e.fillText(x,n,i)}if(g){let t=a-y.top-y.bottom,n=y.top+t/2;e.save(),e.translate(0,n),e.rotate(-Math.PI/2),e.textAlign="center",e.textBaseline="top",e.font=nl,e.fillStyle=na,e.fillText(g,0,0),e.restore()}return{xScale:t,yScale:n,xTickFormat:b,padding:y,frame:S}}let nu={px:4,py:2,mx:4,my:4};function nd({scale:e,format:t,x:n,frame:i}){let r=i.context;i.enter(),r.beginPath(),r.strokeStyle=ni,r.lineWidth=1,r.setLineDash([5,5]),r.moveTo(n,0),r.lineTo(n,i.height),r.stroke(),r.setLineDash([]),r.textAlign="left",r.textBaseline="bottom";let a=e.tickFormat(1/0,t)(e.invert(n)),l=r.measureText(a),s=l.width+2*nu.px,o=l.actualBoundingBoxAscent+2*nu.py,c={x:n+nu.mx,y:nu.my},u=c.x+s>i.width&&s<=n;u&&(c.x=n-nu.mx,s=-s,r.textAlign="right"),r.globalAlpha=.7,r.fillStyle="white",r.fillRect(c.x,c.y,s,o),r.globalAlpha=1,r.fillStyle=nn,i.fillText(a,c.x+nu.px*(u?-1:1),nu.my+nu.py-1,{fillStyle:nn}),i.exit()}function nm({cursor:e,frame:t,x:n,y:i}){if(!e||!t.containsPoint(e))return;let r=t.translatedPoint(e);n&&nd({frame:t,scale:n.scale,format:n.format,x:r.x}),i&&function({scale:e,format:t,y:n,frame:i}){let r=i.context;i.enter(),r.beginPath(),r.strokeStyle=ni,r.lineWidth=1,r.setLineDash([5,5]),r.moveTo(0,n),r.lineTo(i.width,n),r.stroke(),r.setLineDash([]),r.textAlign="left",r.textBaseline="bottom";let a=e.tickFormat(1/0,t)(e.invert(n)),l=r.measureText(a),s=l.width+2*nu.px,o=l.actualBoundingBoxAscent+2*nu.py,c={x:nu.mx,y:nu.my+n},u=c.y+o>i.height;u&&(c.y=n-nu.mx,o=-o,r.textBaseline="top"),r.globalAlpha=.7,r.fillStyle="white",r.fillRect(c.x,c.y,s,o),r.globalAlpha=1,r.fillStyle=nn,i.fillText(a,nu.mx+nu.px,c.y+nu.py*(u?-1:1)-1,{fillStyle:nn}
5),i.exit()}({frame:t,scale:i.scale,format:i.format,y:r.y})}function nh({context:e,x:t,y:n,r:i}){e.beginPath(),e.arc(t,n,i,0,2*Math.PI,!0),e.fill()}let nx=({title:e})=>(0,O.jsx)("div",{className:"text-center font-semibold text-slate-700 text-sm",children:e}),{Provider:ng,useContext:np,useDispatch:nO}=(0,j.vu)({name:"Dist",reducer:(e,{type:t,payload:n})=>"SET_VERTICAL_LINE"===t?{...e,verticalLine:n}:e,defaultValue:{}});var nf=n(64489);let nb="py-0.5 px-2",nv=({children:e})=>(0,O.jsx)("th",{className:(0,E.$)(nb,"font-light"),children:e}),nj=({children:e,onMouseEnter:t,onMouseLeave:n,hoverable:i=!0,isTitle:r=!1})=>(0,O.jsx)("td",{className:(0,E.$)(nb,r?"font-medium":"font-light",i&&"hover:bg-blue-100"),onMouseEnter:i?t:void 0,onMouseLeave:i?n:void 0,children:e}),ny=({plot:e,environment:t,size:n})=>{let i=function(){let e=nO();return t=>e({type:"SET_VERTICAL_LINE",payload:t})}(),r=e.distributions.some(e=>e.name),l=e.xScale?.method?.type==="date"?"date":"number",s=e.xScale?.tickFormat,o="large"===n,c=o?[.05,.25,.5,.75,.95]:[.05,.5,.95],u=e=>e instanceof p.SqSampleSetDistribution&&e.getSamples().length,d=u(e.distributions[0].distribution),m=!!(d&&d>5)&&o,h=o?3:2,x=(e,t)=>{if("date"==l)if(t)return p.SDuration.fromMs(e).toString();else return L(new Date(e),s);return s?a.GPZ(s)(e):(0,O.jsx)(b,{number:e,precision:h})},g=(e,t)=>e.ok?x(e.value,t):(0,O.jsx)(j.fp,{text:e.value.toString(),children:(0,O.jsx)(nf.A,{className:"w-5 h-5 text-gray-500"})});return(0,O.jsx)("div",{className:"overflow-x-auto relative",children:(0,O.jsxs)("table",{className:"w-full text-left font-light",children:[(0,O.jsx)("thead",{className:(0,E.$)("font-light border-b border-slate-200 text-slate-700",o?"text-sm":"text-xs"),children:(0,O.jsxs)("tr",{children:[r&&(0,O.jsx)(nv,{children:"Name"}),(0,O.jsx)(nv,{children:"Mean"}),o&&(0,O.jsx)(nv,{children:"Stdev"}),c.map(e=>(0,O.jsxs)(nv,{children:[100*e,"%"]},e)),m&&(0,O.jsx)(nv,{children:"Samples"})]})}),(0,O.jsx)("tbody",{className:(0,E.$)("text-sm text-blue-800 opacity-90","large"===n?"text-md":"text-sm"),children:e.distributions.map((e,n)=>{let a=e.distribution,l=e.name??e.distribution.toString(),s=a.mean(t),d=a.stdev(t),h=c.map(e=>({percentile:e,inv:a.inv(t,e)}));return(0,O.jsxs)("tr",{children:[r&&(0,O.jsx)(nj,{hoverable:!1,isTitle:!0,children:l}),(0,O.jsx)(nj,{onMouseEnter:()=>i(s),onMouseLeave:()=>i(void 0),children:x(s,!1)}),o&&(0,O.jsx)(nj,{children:g(d,!0)}),h.map((e,t)=>(0,O.jsx)(nj,{hoverable:e.inv.ok,onMouseEnter:()=>i(e.inv.ok?e.inv.value:void 0),onMouseLeave:()=>i(void 0),children:g(e.inv,!1)},t)),m&&(0,O.jsx)(nj,{hoverable:!1,children:u(a)})]},n)})})]})})},nS=a.m4Y().domain([10,300]).range([2,5]).clamp(!0),nP=({shapes:e,samples:t,plot:n,height:i,isMulti:r,samplesBarSetting:l,showAxisTitles:s,showCursorLine:o,showPercentileLines:c,showXAxis:u})=>{let d=function(){let{verticalLine:e}=np();return e}(),[m,h]=(0,v.useState)(),x=e.map(({name:e,continuous:t,discrete:i,p5:r,p50:a,p95:l})=>({name:e,p5:r,p50:a,p95:l,...function({continuous:e,discrete:t},n){if(n.method?.type==="linear")return{continuous:e,discrete:t};{let i=function(e){let t=e.method,n=(e,t)=>t;if(!t)return n;switch(t.type){case"linear":case"date":return n;case"symlog":return(e,n)=>n*(Math.abs(e)+(t.constant||p.SCALE_SYMLOG_DEFAULT_CONSTANT));case"log":return(e,t)=>t*Math.abs(e);case"power":return(e,n)=>n*Math.pow(e,1-(t.exponent||p.SCALE_POWER_DEFAULT_CONSTANT))}}(n);return{discrete:t,continuous:e.map(({x:e,y:t})=>({x:e,y:i(e,t)}))}}}({discrete:i,continuous:t},n.xScale)})),g=x.flatMap(e=>e.discrete.concat(e.continuous)),f=r?16*x.length+2:0,b=14*!!u+20*("bottom"===l),y=Math.max(i+b,f+b),S=nS(y),P="behind"===l?Math.min(7,.04*i+1):7,{xScale:w,yScale:Q}=(0,v.useMemo)(()=>{let e=M(n.xScale),t=e=>Number.isFinite(e)?e:void 0;e.domain([t(n.xScale.min)??a.jkA(g,e=>e.x)??0,t(n.xScale.max)??a.T9B(g,e=>e.x)??0]);let i=M(n.yScale);return i.domain([0,Math.max(...g.map(e=>e.y))]),{xScale:e,yScale:i}},[g,n.xScale,n.yScale]),{cursor:C,initCursor:k}=tk(),$=(0,v.useCallback)(({context:e,width:i})=>{e.clearRect(0,0,i,y);let g=(e,t)=>{let n=r?a.t55[e]:"#649ece";return t?a.dJd(n,"#fff")(t):n},{padding:p,frame:O}=nc({context:e,width:i,height:y,suggestedPadding:{left:S,right:S,top:S,bottom:b},xScale:w,yScale:Q,showYAxis:!1,showXAxis:u,xTickFormat:n.xScale.tickFormat,xAxisTitle:s?n.xScale.title:void 0,showAxisLines:!1});if("none"!==l){e.save();let{yOffset:n,color:i}="behind"===l?{yOffset:b,color:g(0,.4)}:{yOffset:0,color:g(0)};e.lineWidth=.5,e.strokeStyle=i,t.forEach(t=>{e.beginPath();let i=w(t);e.beginPath(),e.moveTo(p.left+i,y-n-P),e.lineTo(p.left+i,y-n),e.stroke()}
5),e.restore()}{let t;O.enter();let n=C?O.translatedPoint(C):void 0;for(let i=0;i<x.length;i++){let l=x[i];e.fillStyle=r?g(i,0):g(i,.7),e.globalAlpha=r?.4:1,e.beginPath(),a.Wcw().x(e=>w(e.x)).y0(e=>Q(e.y)).y1(0).context(e)(l.continuous),e.fill(),e.globalAlpha=1,c&&[[l.p5,"p5"],[l.p50,"p50"],[l.p95,"p95"]].forEach(([t,n])=>{if(t.ok){let r=t.value,s=function(e,t,n){let i=null,r=null;for(let n of t)if(n.x<=e)i=n;else{r=n;break}return i&&r?a.m4Y().domain([i.x,r.x]).range([n(i.y),n(r.y)])(e):null}(r,l.continuous,Q);s&&(e.beginPath(),e.strokeStyle=g(i,"p50"===n?.4:.3),"p50"===n?e.setLineDash([6,4]):e.setLineDash([2,2]),e.lineWidth=1,e.moveTo(w(r),0),e.lineTo(w(r),s),e.stroke(),e.setLineDash([]))}}),e.strokeStyle=g(i),e.beginPath(),a.n8j().x(e=>w(e.x)).y(e=>Q(e.y)).context(e)(l.continuous),e.stroke();let s=r?.05:.1,o=g(i,-s);for(let r of(e.fillStyle=g(i,-s),e.strokeStyle=o,l.discrete)){e.beginPath(),e.lineWidth=1;let a=w(r.x),l=Q(r.y)-S;n&&function(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}({x:a,y:l},n)<=S+2&&(t={value:r.x,probability:r.y},e.fillStyle=g(i,-1),e.strokeStyle=g(i,-1)),e.moveTo(a,0),e.lineTo(a,l),e.globalAlpha=.5,e.stroke(),e.globalAlpha=1,nh({context:e,x:a,y:l,r:S})}}t9(m,t)||h(t),O.exit()}if(r)for(let t=0;t<x.length;t++)e.save(),e.translate(p.left,16*t+2),e.fillStyle=g(t),nh({context:e,x:5,y:5,r:5}),e.textAlign="left",e.textBaseline="middle",e.fillStyle="black",e.font="12px sans-serif",e.fillText(x[t].name,16,5),e.restore();o&&nm({frame:O,cursor:C,x:{scale:w,format:n.xScale.tickFormat}}),d&&nd({frame:O,scale:w,format:n.xScale.tickFormat,x:w(d)})},[y,S,x,t,n,m,C,r,w,Q,d,P,b,l,o,c,u,s]),{ref:A}=tN({height:y,init:k,draw:$});return(0,O.jsx)(j.fu,{isOpen:!!m,render:()=>m?(0,O.jsxs)("div",{className:(0,E.A)("bg-white border border-gray-300 rounded text-xs p-2 grid gap-x-2"),style:{gridTemplateColumns:"min-content min-content"},children:[(0,O.jsx)("div",{className:"text-gray-500 text-right",children:"Value:"}),(0,O.jsx)("div",{children:w.tickFormat(void 0,n.xScale.tickFormat)(m.value)}),(0,O.jsx)("div",{className:"text-gray-500 text-right",children:"Probability:"}),(0,O.jsx)("div",{children:Q.tickFormat(void 0,n.yScale.tickFormat)(m.probability)}),(0,O.jsx)("br",{})]}):null,children:(0,O.jsx)("canvas",{"data-testid":"multi-distribution-chart",className:N,ref:A,children:"Distribution plot"})})},nw=({plot:e,environment:t,height:n})=>{let i=eb(),r=e.distributions,a=(0,v.useMemo)(()=>{let e=[];for(let{distribution:t}of r)t.tag===p.SqDistributionTag.SampleSet&&e.push(t.getSamples());return[].concat(...e)},[r]),l=function e(t){if(0===t.length)return{ok:!0,value:[]};{if(!t[0].ok)return t[0];let n=e(t.splice(1));return n.ok?{ok:!0,value:[t[0].value].concat(n.value)}:n}}(r.map(e=>(0,p.resultMap)(e.distribution.pointSet(t),n=>({name:e.name??e.distribution.toString(),p5:e.distribution.inv(t,.05),p50:e.distribution.inv(t,.5),p95:e.distribution.inv(t,.95),...n.asShape()}))));if(!l.ok)return(0,O.jsx)(_,{heading:"Distribution Error",children:l.value.toString()});let s=r.map(({name:e,distribution:t})=>({name:e,isNormalized:t.isNormalized()})),o=n>30,c=o&&!!e.xScale.title,u=n>15,d=Math.max(n-20*!!u,0),m=s.some(({isNormalized:e})=>!e),h=r.length>1||!!(1===r.length&&r[0].name),x="none",g=d>150?"large":"small";x=a.length<10||a.length>1e5||h||d<=15?"none":"small"!=g||c?"bottom":"behind";let f=e.xScale.method?.type==="log"&&l.value.some(t7);return(0,O.jsxs)(ng,{generateInitialValue:()=>({}),children:[e.title&&(0,O.jsx)(nx,{title:e.title}),f&&(0,O.jsx)(_,{heading:"Log Domain Error",children:"Cannot graph distribution with negative values on logarithmic scale."}),!f&&(0,O.jsx)(O.Fragment,{children:(0,O.jsxs)("div",{className:"flex flex-col items-stretch",children:[(0,O.jsx)("div",{className:"flex-1",style:"tooltip"===i?{maxWidth:300}:void 0,children:(0,O.jsx)(nP,{isMulti:h,samples:a,shapes:l.value,plot:e,height:n,samplesBarSetting:x,showCursorLine:d>30,showPercentileLines:d>30,showXAxis:u,showAxisTitles:o})}),!m&&e.showSummary&&d>30&&(0,O.jsx)("div",{className:(0,E.A)("mt-3 self-end","large"===g&&"pt-5"),children:(0,O.jsx)(ny,{plot:e,environment:t,size:g})}),m&&n>20&&(0,O.jsxs)("div",{className:"flex-1 pt-2",children:[" ",(()=>{let e=1===r.length?`Not a valid probability distribution. Its integral is ${r[0].distribution.integralSum()}, it should be 1. Squiggle currently poorly supports these types.`:`Distributions: [${s.filter(({isNormalized:e})=>!e).map(({name:e})=>e).join(", ")}] are not valid probability distributions, because their integrals do not add up to 1.`;return(0,O.jsx)(j.fp,{text:e,placement:"top",children:(0,O.jsx)("div",{className:"font-semibold text-xs text-orange-900 bg-orange-100 rounded-md px-1.5 py-0.5 w-fit ml-2",children:"Not Normalized"})})})()]})]})})]})};eR.register("Dist",{Preview(e){let t=e.value,n=e.context.project.getEnvironment(),i=e.tags.numberFormat(),r=e=>i?X(i,e):(0,O.jsx)(b,{precision:2,number:e}),a=Q(t.inv(n,.05)),l=Q(t.inv(n,.95)),s=a===l,o=e.showAsPlot(),c=p.SqDistributionsPlot.create({distribution:e.value,showSummary:!1,xScale:o?.xScale??p.SqScale.linearDefault(),yScale:o?.yScale??p.SqScale.linearDefault()});return s?r(a):(0,O.jsxs)("div",{className:"flex flex-row space-x-2 items-center",children:[(0,O.jsxs)("div",{className:"flex",children:[r(a),(0,O.jsx)("span",{className:"mx-1 opacity-60",children:"to"}),r(l)]}),(0,O.jsx)("div",{className:"flex w-14",children:(0,O.jsx)(nw,{plot:c,environment:e.context.project.getEnvironment(),height:14})})]})},Menu(e){let t=e.value.pointSet(e.context.project.getEnvironment());return(0,O.jsx)(t8,{value:e,metaSettings:{disableLogX:t?.ok&&t7(t.value.asShape())},withFunctionSettings:!1})},Chart(e,t){let n=e.tags.numberFormat(),i=p.SqDistributionsPlot.create({distribution:e.value,...en(t.distributionChartSettings,n)});return(0,O.jsx)(nw,{plot:i,environment:e.context.project.getEnvironment(),height:.55*t.chartHeight})}});let nQ=(e,t)=>e.substring(0,t)+(e.length>t?"...":""),nC=({location:e})=>{let{editor:t}=eh();return(0,O.jsxs)("span",{className:(0,E.$)(t&&"cursor-pointer hover:underline text-blue-500"),onClick:t?()=>{t?.scrollTo(e.start.offset,!0)}
5:void 0,children:["line ",e.start.line,", column ",e.start.column]})},nN=({header:e,children:t})=>(0,O.jsxs)("div",{children:[(0,O.jsx)("div",{className:"text-sm font-medium mb-1 text-gray-700",children:e}),(0,O.jsx)("div",{className:"ml-1",children:t})]}),nk=({frame:e})=>{let t=e.location(),n=e.name();return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)("div",{className:"text-gray-500 font-mono font-medium truncate",children:n}),(0,O.jsx)("div",{children:t&&(0,O.jsx)(nC,{location:t})})]})},n$=({error:e})=>{let t=e.getFrameArray();return t.length?(0,O.jsx)(nN,{header:"Stack Trace",children:(0,O.jsx)("div",{className:"grid grid-cols-[minmax(60px,max-content),1fr] gap-x-4",children:t.map((e,t)=>(0,O.jsx)(nk,{frame:e},t))})}):null},nA=({error:e})=>(0,O.jsx)(_,{heading:e instanceof p.SqCompileError?"Compile Error":e instanceof p.SqRuntimeError?"Runtime Error":"Error",children:(0,O.jsxs)("div",{className:"space-y-4",children:[(0,O.jsx)("div",{className:"whitespace-pre-wrap",children:e.toString()}),e instanceof p.SqRuntimeError?(0,O.jsx)(n$,{error:e}):e instanceof p.SqCompileError?(0,O.jsx)(nN,{header:"Location:",children:(0,O.jsx)(nC,{location:e.location()})}):null]})});var nR=n(98641),nT=n(53711),nE=n(56849);let nq=({errors:e})=>{if(!Object.entries(e).length)return null;let t=nE(e,e=>e.value);return(0,O.jsx)("div",{className:"space-y-1",children:Object.entries(t).map(([e,t])=>(0,O.jsxs)(_,{heading:e,children:["Values:"," ",t.map((e,t)=>(0,O.jsx)(b,{number:e.x},t)).reduce((e,t)=>(0,O.jsxs)(O.Fragment,{children:[e,", ",t]}))]},e))})},n_=[{width:.2,opacity:.2},{width:.4,opacity:.2},{width:.6,opacity:.2},{width:.8,opacity:.15},{width:.9,opacity:.1},{width:.98,opacity:.05}],nV=({plot:e,environment:t,height:n,xCount:i})=>{let{ref:r,xScale:l,cursorX:s,errors:o}=function({plot:e,environment:t,height:n,xCount:i}){let r=n+30,{cursor:l,initCursor:s}=tk(),{data:o,errors:c,xScale:u}=(0,v.useMemo)(()=>(function({plot:e,environment:t,xCount:n}){let{functionImage:i,errors:r,xScale:a}=Y(e,t,n);return{data:i.map(({x:e,y:n})=>({x:e,areas:Object.fromEntries(n_.map(({width:e})=>{let i=(1-e)/2;return[e,[Q(n.inv(t,i)),Q(n.inv(t,i+e))]]})),50:Q(n.inv(t,.5))})).filter(e=>isFinite(e[50])),errors:r,xScale:a}})({plot:e,environment:t,xCount:i}),[e,t,i]),d=(0,v.useMemo)(()=>{let t=M(e.yScale);return t.domain([e.yScale.min??Math.min(...o.map(e=>Math.min(...Object.values(e.areas).map(e=>e[0]).filter(isFinite),isFinite(e[50])?e[50]:1/0))),e.yScale.max??Math.max(...o.map(e=>Math.max(...Object.values(e.areas).map(e=>e[1]).filter(isFinite),isFinite(e[50])?e[50]:-1/0)))]),t},[o,e.yScale]),m=(0,v.useCallback)(({context:t,width:n})=>{t.clearRect(0,0,n,r);let{frame:i}=nc({suggestedPadding:{left:20,right:10,top:10,bottom:20},xScale:u,yScale:d,width:n,height:r,context:t,xTickFormat:e.xScale.tickFormat,yTickFormat:e.yScale.tickFormat,xAxisTitle:e.xScale.title,yAxisTitle:e.yScale.title});for(let{width:e,opacity:n}of(g.current={frame:i,xScale:u},i.enter(),t.fillStyle=nr,n_))t.globalAlpha=n,a.Wcw().x(e=>u(e.x)).y1(t=>d(t.areas[e][0])).y0(t=>d(t.areas[e][1])).context(t)(o),t.fill();t.globalAlpha=1,t.strokeStyle=nr,t.lineWidth=2,t.imageSmoothingEnabled=!0,t.beginPath(),a.n8j().x(e=>u(e.x)).y(e=>d(e[50])).context(t)(o),t.stroke(),i.exit(),nm({frame:i,cursor:l,x:{scale:u,format:e.xScale.tickFormat}})},[l,r,o,e,u,d]),{ref:h,width:x}=tN({height:r,init:s,draw:m}),g=(0,v.useRef)();return{ref:h,cursorX:(0,v.useMemo)(()=>{if(g.current&&l&&x&&g.current.frame.containsPoint(l))return g.current.xScale.invert(l.x-g.current.frame.x0)},[l,x]),xScale:u,errors:c}}({plot:e,environment:t,height:n,xCount:i}),c=(0,v.useMemo)(()=>void 0!==s?e.fn.call([e.xScale.numberToValue(s)],t):{ok:!1,value:new p.SqOtherError("No cursor")},[e.fn,t,s,e.xScale]),u=c?.ok&&"Dist"===c.value.tag&&void 0!==s?(0,O.jsx)(nw,{plot:p.SqDistributionsPlot.create({distribution:c.value.value,xScale:e.distXScale,yScale:p.SqScale.linearDefault(),showSummary:!1,title:`f(${l.tickFormat(void 0,e.xScale.tickFormat)(s)})`}),environment:t,height:50}):null,{x:d,y:m,strategy:h,refs:x}=(0,nR.we)({open:null!==u,placement:"bottom-start",middleware:[(0,nT.cY)(4),(0,nT.UU)()]}),{selector:g}=(0,v.useContext)(j.mS);return(0,O.jsxs)("div",{className:"flex flex-col items-stretch",children:[e.title&&(0,O.jsx)(nx,{title:e.title}),(0,O.jsx)("div",{ref:x.setReference,children:(0,O.jsxs)("canvas",{ref:r,className:N,children:["Chart for ",e.toString()]})}),u&&(0,O.jsx)(nR.XF,{children:(0,O.jsx)("div",{className:g,children:(0,O.jsx)("div",{ref:x.setFloating,className:"z-30 rounded-md bg-white shadow-lg border",style:{position:h,top:m??0,left:d??0,width:x.reference.current?.getBoundingClientRect().width},children:u})})}),(0,O.jsx)(nq,{errors:o})]})},nz=({plot:e,environment:t,height:n,xCount:i})=>{let r=n+30,{cursor:l,initCursor:s}=tk(),{functionImage:o,errors:c,xScale:u}=(0,v.useMemo)(()=>Y(e,t,i),[e,t,i]),d=(0,v.useCallback)(({context:t,width:n})=>{t.clearRect(0,0,n,r);let i=M(e.yScale);i.domain(e.yScale.min&&e.yScale.max?[e.yScale.min,e.yScale.max]:a.Xxv(o.filter(e=>isFinite(e.y)),e=>e.y));let{frame:s}=nc({context:t,width:n,height:r,suggestedPadding:{left:20,right:10,top:10,bottom:20},xScale:u,yScale:i,xTickFormat:e.xScale.tickFormat,yTickFormat:e.yScale.tickFormat,xAxisTitle:e.xScale.title,yAxisTitle:e.yScale.title});if(e.xScale.method?.type==="log"&&o[0]&&o[0].x<=0){s.enter(),s.fillText("Log scale requires positive X Scale range",s.width/2,s.height/2,{textAlign:"center",textBaseline:"middle",font:"12px Arial",fillStyle:"red"}),s.exit();return}s.enter(),t.beginPath(),t.strokeStyle=nr,t.lineWidth=2,t.imageSmoothingEnabled=!0,a.n8j().x(e=>u(e.x)).y(e=>i(e.y)).context(t)(o),t.stroke(),s.exit(),nm({frame:s,cursor:l,x:{scale:u,format:e.xScale.tickFormat},y:{scale:i,format:e.yScale.tickFormat}})},[o,r,l,e,u]),{ref:m}=tN({height:r,init:s,draw:d});return(0,O.jsxs)("div",{className:"flex flex-col items-stretch",children:[e.title&&(0,O.jsx)(nx,{title:e.title}),(0,O.jsxs)("canvas",{ref:m,className:N,children:["Chart for ",e.toString()]}),(0,O.jsx)(nq,{errors:c})]})},nW=({error:e})=>{let[t,n]=(0,v.useState)(!1);
5return(0,O.jsx)(V,{heading:"Function Display Failed",children:(0,O.jsxs)("div",{className:"space-y-2",children:[(0,O.jsxs)("span",{className:"underline decoration-dashed cursor-pointer",onClick:()=>n(!t),children:[t?"Hide":"Show"," error details"]}),t?(0,O.jsx)(nA,{error:e}):null]})})},nD=({fn:e,settings:t,environment:n,height:i})=>{if(!e.parameterCounts().includes(1))return(0,O.jsx)(V,{heading:"Function Display Not Supported",children:"Only functions with one parameter are displayed."});let r=t.functionChartSettings.start,a=t.functionChartSettings.stop,l=t.functionChartSettings.count,s=e.signatures().find(e=>1===e.length)?.[0]?.domain||p.SqNumericRangeDomain.fromMinMax(r,a),o=function(e,t,n){let i=t.call([e.minValue],n);if(i.ok)return{ok:!0,value:i.value.tag};let r=t.call([e.maxValue],n);return r.ok?{ok:!0,value:r.value.tag}:{ok:!1,value:r.value}}(s,e,n);if(!o.ok)return(0,O.jsx)(nW,{error:o.value});let c=p.SqScale.linearDefault(),u=s.toDefaultScale();switch(o.value){case"Dist":{let r=p.SqDistFnPlot.create({fn:e,xScale:u,yScale:c,distXScale:en(t.distributionChartSettings).xScale});return(0,O.jsx)(nV,{plot:r,environment:n,height:i,xCount:l})}case"Number":{let t=p.SqNumericFnPlot.create({fn:e,xScale:u,yScale:p.SqScale.linearDefault()});return(0,O.jsx)(z,{children:(0,O.jsx)(nz,{plot:t,environment:n,height:i,xCount:l})})}default:return(0,O.jsxs)(V,{heading:"Function Display Not Supported",children:["There is no function visualization for this type of output:"," ",(0,O.jsx)("span",{className:"font-bold",children:o.value})]})}};eR.register("Lambda",{Preview:e=>(0,O.jsxs)("div",{children:["fn(",(0,O.jsx)("span",{className:"opacity-60",children:nQ(e.value.parameterString(),15)}),")"]}),Menu:e=>(0,O.jsx)(t8,{value:e,withFunctionSettings:!0}),Chart:(e,t)=>{let n=e.context.project.getEnvironment();if("BuiltinLambda"===e.value.type){let t=e.value._value.display(),n=(0,p.getFunctionDocumentation)(t);if(n)return(0,O.jsx)(tT,{documentation:n})}return(0,O.jsx)(nD,{fn:e.value,settings:t,height:t.chartHeight,environment:{sampleCount:n.sampleCount/10,xyPointLength:n.xyPointLength/10}})}});let nM=e=>{let t=e.tags.numberFormat();return t?X(t,e.value):(0,O.jsx)(b,{precision:4,number:e.value})};function nX(e,t){if(!t)return 1;let n=(t[1]-t[0])/5;return e<t[0]+n?1:e<t[0]+2*n?2:e<t[0]+3*n?3:e<t[0]+4*n?4:5}function nL(e,t){switch(nX(e,t)){case 1:return"text-gray-900";case 2:return"text-gray-700";case 3:return"text-yellow-700 opacity-90";case 4:return"text-orange-700 opacity-70";case 5:return"text-red-700 opacity-60"}}eR.register("Number",{Preview:e=>nM(e),Chart:e=>{let t=eb();return(0,O.jsx)("div",{className:(0,E.$)("font-semibold text-indigo-800","tooltip"===t&&"text-lg"),children:nM(e)})}});let nF=(0,v.memo)(function({item:e,uncertaintyPercentiles:t,showRange:n,showMedian:i}){return Object.values(e).some(e=>!Number.isFinite(e))?(0,O.jsx)("div",{className:"h-full pt-[1px] min-h-[2em] relative bg-gray-300 bg-opacity-30",children:(0,O.jsx)("div",{className:"text-center z-0 p-4 text-gray-500",children:"Error"})}):(0,O.jsxs)("div",{className:(0,E.$)("h-full pt-[1px] min-h-[2em] relative",function(e,t){switch(nX(e,t)){case 1:return"hover:bg-gray-100";case 2:return"bg-yellow-300 bg-opacity-5 hover:bg-opacity-30";case 3:return"bg-yellow-500 bg-opacity-10 hover:bg-opacity-30";case 4:return"bg-red-400 bg-opacity-10 hover:bg-opacity-30";case 5:return"bg-red-400 bg-opacity-20 hover:bg-opacity-40"}}(e.uncertainty,t)),children:[(0,O.jsxs)("div",{className:"text-center z-0 py-1",children:[(0,O.jsxs)("div",{children:[i&&(0,O.jsx)("span",{className:"text-slate-700 text-lg font-semibold",children:(0,O.jsx)(b,{number:e.median,precision:1})}),(0,O.jsxs)("span",{children:[i&&(0,O.jsxs)("span",{children:[" ",(0,O.jsx)("span",{style:{fontSize:"0.7em"},className:"text-gray-400 font-light",children:"\xb1"})," "]}),(0,O.jsx)("span",{className:nL(e.uncertainty,t),children:(0,O.jsx)(b,{number:e.uncertainty/2,precision:2})}),(0,O.jsx)("span",{style:{fontSize:"0.6em"},className:(0,E.$)(nL(e.uncertainty,t),"font-light"),children:"om"})]})]}),n&&(0,O.jsx)("div",{style:{fontSize:"0.7em"},className:"text-gray-400 font-light",children:e.min<0&&e.max<0?(0,O.jsxs)("span",{children:["-(",(0,O.jsx)(b,{number:-1*e.max,precision:1})," to"," ",(0,O.jsx)(b,{number:-1*e.min,precision:1}),")"]}):(0,O.jsxs)("span",{children:[(0,O.jsx)(b,{number:e.min,precision:1})," to"," ",(0,O.jsx)(b,{number:e.max,precision:1})]})})]}),(0,O.jsx)("div",{className:"h-2 absolute bottom-0 inset-x-0 -z-10"})]})}),nY=D.z.object({median:D.z.number(),mean:D.z.number(),min:D.z.number(),max:D.z.number(),uncertainty:D.z.number()}),nZ=({children:e,header:t})=>(0,O.jsx)("div",{className:(0,E.$)("border-t border-l border-gray-200 h-full",t&&"bg-gray-50 top-0 left-0 z-10"),children:e}),nU=()=>(0,O.jsx)(nZ,{children:(0,O.jsx)("div",{className:"p-2",children:"Error"})}),nI=({text:e})=>(0,O.jsx)("div",{className:"p-2 text-xs break-all",children:e}),nG=({wrapFn:e,id1:t,id2:n,environment:i})=>{let r=e.call([p.SqStringValue.create(t),p.SqStringValue.create(n)],i);if(!r.ok)return(0,O.jsx)(nU,{});let a=r.value.asJS();if(!(a instanceof Object))return(0,O.jsx)(nU,{});try{let e=nY.parse(a.value);return(0,O.jsx)(nZ,{children:(0,O.jsx)(nF,{item:e,showMedian:!0})})}catch(e){return(0,O.jsx)(nU,{})}},nB=({plot:e,environment:t})=>{let n=e.ids,i=(0,v.useMemo)(()=>p.SqLambda.createFromStdlibName("RelativeValues.wrap").call([p.SqLambdaValue.create(e.fn)],t),[e.fn,t]);if(!i.ok)return(0,O.jsx)(_,{heading:"Failed to construct wrap function"});if(!(i.value instanceof p.SqLambdaValue))return(0,O.jsx)(_,{heading:"Obtained invali
5d wrap function from RelativeValues.wrap"});let r=i.value.value;return(0,O.jsxs)("div",{children:[e.title&&(0,O.jsx)("div",{className:"mb-2",children:(0,O.jsx)(nx,{title:e.title})}),(0,O.jsxs)("div",{className:"grid w-fit border-r border-b border-gray-200",style:{gridTemplateColumns:`repeat(${n.length+1}, 140px)`},children:[(0,O.jsx)("div",{}),n.map(e=>(0,O.jsx)(nZ,{header:!0,children:(0,O.jsx)(nI,{text:e})},e)),n.map(e=>(0,O.jsxs)(v.Fragment,{children:[(0,O.jsx)(nZ,{header:!0,children:(0,O.jsx)(nI,{text:e})}),n.map(n=>(0,O.jsx)(nG,{wrapFn:r,id1:e,id2:n,environment:t},n))]},e))]})]})},nH=({plot:e,height:t})=>{let{cursor:n,initCursor:i}=tk(),{xDist:r,yDist:l}=(0,v.useMemo)(()=>({xDist:e.xDist(),yDist:e.yDist()}),[e]),s=(0,v.useCallback)(({context:i,width:s})=>{let o=p.SqScatterPlot.zipToPoints(r,l),c=e.xScale??p.SqScale.linearDefault(),u=M(c);u.domain([c.min??a.jkA(r.getSamples())??0,c.max??a.T9B(r.getSamples())??0]);let d=e.yScale??p.SqScale.linearDefault(),m=M(d);m.domain([d.min??a.jkA(l.getSamples())??0,d.max??a.T9B(l.getSamples())??0]);let{frame:h}=nc({context:i,width:s,height:t,suggestedPadding:{top:10,bottom:16,left:0,right:0},xScale:u,yScale:m,xTickFormat:e.xScale?.tickFormat,yTickFormat:e.yScale?.tickFormat,xAxisTitle:e.xScale?.title,yAxisTitle:e.yScale?.title});for(let e of(h.enter(),i.fillStyle=nr,i.globalAlpha=.15,o))nh({context:i,x:u(e.x),y:m(e.y),r:2});i.globalAlpha=1,h.exit(),nm({frame:h,cursor:n,x:{scale:u,format:c.tickFormat},y:{scale:m,format:d.tickFormat}})},[r,l,t,n,e.xScale,e.yScale]),{ref:o}=tN({height:t,init:i,draw:s});return(0,O.jsxs)("div",{className:"flex flex-col items-stretch",children:[e.title&&(0,O.jsx)(nx,{title:e.title}),(0,O.jsxs)("canvas",{ref:o,className:N,children:["Chart for ",e.toString()]})]})};eR.register("Plot",{Chart:(e,t)=>{let n=e.value,i=e.context.project.getEnvironment();switch(n.tag){case"distributions":return(0,O.jsx)(nw,{plot:n,environment:i,height:.55*t.chartHeight});case"numericFn":return(0,O.jsx)(nz,{plot:n,environment:i,height:t.chartHeight,xCount:t.functionChartSettings.count});case"distFn":return(0,O.jsx)(nV,{plot:n,environment:{sampleCount:i.sampleCount/10,xyPointLength:i.xyPointLength/10},height:t.chartHeight,xCount:t.functionChartSettings.count});case"scatter":return(0,O.jsx)(nH,{plot:n,environment:i,height:t.chartHeight});case"relativeValues":return(0,O.jsx)(nB,{plot:n,environment:i});default:return`Unsupported plot ${n}`}}}),eR.register("String",{Preview:e=>(0,O.jsx)("div",{className:"overflow-ellipsis overflow-hidden",children:nQ(e.value,25)}),Chart:e=>(0,O.jsx)("div",{className:"px-1 py-0.5 my-1 max-w-4xl",children:(0,O.jsx)(eY,{md:e.value,textColor:"prose-stone",textSize:"sm"})})}),eR.register("TableChart",{Preview:e=>(0,O.jsxs)("div",{className:"items-center flex space-x-1",children:[(0,O.jsx)(j.d4,{size:14,className:"flex opacity-60"}),(0,O.jsxs)("div",{children:[e.value.rowCount,(0,O.jsx)("span",{className:"opacity-60",children:"x"}),e.value.columnCount]})]}),Chart:(e,t)=>{let n=e.context.project.getEnvironment(),i=e.value,r=ep(),a=i.items(n),l=i.columnNames,s=l.filter(e=>!!e).length>0,o=Math.max(l?l.length:0,a[0]?.length??0),c={...t.distributionChartSettings,showSummary:!1},u={...t,distributionChartSettings:c,chartHeight:50};return(0,O.jsx)("div",{children:(0,O.jsx)("div",{className:"relative rounded-md overflow-hidden border border-stone-200 mt-0.5",children:(0,O.jsxs)("table",{className:"table-fixed w-full",style:{minWidth:100*o},children:[s&&(0,O.jsx)("thead",{className:"text-sm text-stone-500 bg-stone-50 border-b border-stone-200 break-words",children:(0,O.jsx)("tr",{children:Array.from({length:o},(e,t)=>(0,O.jsx)("th",{scope:"col",className:"px-2 py-2 text-left font-medium",children:l[t]||""},t))})}),(0,O.jsx)("tbody",{children:a.map((e,t)=>(0,O.jsx)("tr",{className:"border-b border-stone-100",children:e.map((e,t)=>(0,O.jsx)("td",{tabIndex:1,onKeyDown:t=>{if("Enter"===t.key&&e.ok){t.preventDefault();let n=e.value.context?.path;n&&r(n)}},className:(0,E.$)("px-1 overflow-hidden",0!==t&&"border-stone-100 border-l","focus:bg-blue-50"),children:((e,t)=>{if(!e.ok)return e.value.toString();{let n=e.value;return k(n)?(0,O.jsx)(eZ,{value:n,settings:t}):n.toString()}})(e,u)},t))},t))})]})})})}});let nJ=e=>{let t=e.tags.numberFormat(),{unitName:n,value:i}=e.toUnitAndNumber();return t?`${X(t,i)} ${n}s`:(0,O.jsx)(b,{precision:4,number:i,unitName:n})};eR.register("Duration",{Preview:e=>nJ(e),Chart:e=>(0,O.jsx)("div",{className:"font-semibold text-indigo-800",children:nJ(e)})}),eR.register("Void",{Preview:()=>"Empty value",Chart:()=>(0,O.jsx)("div",{className:"italic text-slate-400 text-sm",children:"Empty value"})});let nK=({className:e,...t})=>(0,O.jsx)(j.vK,{className:(0,E.$)(e),...t}),n0=({className:e,...t})=>(0,O.jsx)(j.vK,{className:(0,E.$)("rotate-90",e),...t});function n1(e){return t=>{let n=e[t.key];return!!n&&(t.preventDefault(),n(),!0)}}let n5=({value:e})=>{let{path:t}=e.context,n=function(e){let{zoomedInPath:t}=eh();return t?.isEqual(e)}(t),i=ep(),r=eO();return t.isRoot()?null:n?(0,O.jsx)(j.GJ,{title:"Zoom Out",icon:j.w4,onClick:r}):(0,O.jsx)(j.GJ,{title:"Zoom In",icon:j.w4,onClick:()=>i(t)})},n2=({value:e})=>{let t=(0,j.py)();return(0,O.jsx)(j.GJ,{title:"Log to JS Console",icon:j.nr,onClick:()=>{console.log({variable:e.context.path.uid(),value:e._value,context:e.context}),t()}})},n4=({value:e,title:t,collapsed:n})=>{let i=function(){let{itemStore:e}=eh();return(t,n,i)=>{e.setState(t,e=>({...e,collapsed:n})),i?.skipUpdate||e.forceUpdate(t)}}(),r=(0,j.py)(),{itemStore:a}=eh();if("Array"!==e.tag&&"Dict"!==e.tag)return null;let l=eP(e);return l.every(e=>{let t=e.context?.path;return t&&a.getState(t).collapsed===n})?null:(0,O.jsx)(j.GJ,{title:t,onClick:()=>{for(let e of l)e.context&&i(e.context.path,n);r()},icon:n?nK:n0})},n3=({value:e})=>{let t=eR.widgets.get(e.tag),n=(e=>{let t=eR.widgets.get(e.tag);return t?.heading?.(e)||e.publicName()})(e),i=eg(e.context.path);return(0,O.jsx)(j.ms,{render:()=>(0,O.jsxs)(j.rI,{children:[n&&(0,O.jsx)(j.GR,{children:n}),(0,O.jsx)(n5,{value:e}),(0,O.jsx)(n4,{value:e,title:"Collapse Children",collapsed:!0}),(0,O.jsx)(n4,{value:e,title:"Expand Children",collapsed:!1}),t?.Menu&&(0,O.jsx)(t.Menu,{value:e}),(0,O.jsx)(n2,{value:e})]}),children:(0,O.jsx)(j.Zb,{size:16,className:(0,E.$)("cursor-pointer transition",i?"text-indigo-300 hover:!text-indigo-500 group-hover:text-indigo-400":"opacity-0 hover:!text-stone-500 group-hover:text-stone-400 group-hover:opacity-100")})})},n6=({value:e})=>{let t=eR.widgets.get(e.tag);return t?.Preview?(0,O.jsx)(t.Preview,{value:e}):null},n8=({value:e})=>{let t=eQ(e);return t?(0,O.jsx)("div",{className:"ml-3",children:(0,O.jsx)(j.fp,{text:t,placement:"bottom",children:(0,O.jsx)("span",{children:(0,O.jsx)(j.Tw,{size:13,className:"text-purple-100 group-hover:text-purple-300"})})})}):null},n7=({value:e,children:t})=>{let n=eQ(e);if(!n)return t;let i=new Set(["Dict","Array","TableChart","Plot","String"]).has(e.tag)?"top":"bottom",r=(0,O.jsx)("div",{className:(0,E.$)("max-w-4xl","bottom"===i?"mt-1":"mb-1"),children:(0,O.jsx)(eY,{md:n,textSize:"sm"})});return(0,O.jsxs)("div",{children:["top"===i&&r,t,"bottom"===i&&r]})},n9=({value:e,size:t="normal"})=>{let{path:n}=e.context,i=ef(n),r=(0,v.useMemo)(()=>
5{let{chartHeight:e}=i;return{...i,chartHeight:"large"===t?4*e:e}},[t,i]);return(0,O.jsx)(n7,{value:e,children:(0,O.jsx)(eZ,{value:e,settings:r})})},ie=({value:e,parentValue:t,...n})=>{let{tag:i}=e,{path:r}=e.context,a=(0,v.useRef)(null),l=(0,v.useRef)(null),s=function(){let{itemStore:e}=eh();return t=>{ex(e,t)}}(),o=(0,v.useCallback)(()=>{l.current?.focus()},[]),c={scrollIntoView:()=>{a?.current?.scrollIntoView({behavior:"smooth"})},forceUpdate:function(){let[,e]=(0,v.useReducer)(e=>e+1,0);return e}(),focusOnHeader:o,toggleCollapsed:()=>s(r)};!function(e,t){let{itemStore:n}=eh();(0,v.useEffect)(()=>(n.registerItemHandle(e,t),()=>n.unregisterItemHandle(e)))}(r,c);let u=ep(),d=()=>C&&u(r),m=function(e){let{setZoomedInPath:t,itemStore:n,findNode:i}=eh();function r(){t(void 0),setTimeout(()=>{n.focusOnPath(e)},1)}return n1({ArrowDown:()=>{let n=i(e)?.nextSibling()?.node.path;n&&t(n)},ArrowUp:()=>{let n=i(e)?.prevSibling()?.node.path;n&&t(n)},ArrowLeft:()=>{let n=i(e)?.parent();n&&(n.isRoot()?r():t(n.node.path))},ArrowRight:()=>{let t=i(e)?.children()[0];t&&n.focusOnPath(t.node.path)},Enter:r})}(r),h=function(e){let{setZoomedInPath:t,itemStore:n,editor:i,findNode:r}=eh();return n1({ArrowDown:()=>{let t=r(e)?.next()?.node.path;t&&n.focusOnPath(t)},ArrowUp:()=>{let t=r(e)?.prev()?.node.path;t&&n.focusOnPath(t)},ArrowLeft:()=>{let t=r(e)?.parent();t&&!t.isRoot()&&n.focusOnPath(t.node.path)},ArrowRight:()=>{let t=r(e)?.children().at(0),i=n.state[e.uid()]?.collapsed;t&&(i?(ex(n,e),setTimeout(()=>{n.focusOnPath(t.node.path)},1)):n.focusOnPath(t.node.path))},Enter:()=>{t(e)}," ":()=>{ex(n,e)},e:()=>{let t=r(e)?.value(),n=t?.context?.findLocation();n&&i?.scrollTo(n.start.offset,!0)}})}(r),x=eb(),g=function(e){let{editor:t,findNode:n}=eh();return()=>{if(t){let i=n(e)?.value(),r=i?.tags.location()||i?.context?.findLocation();r&&t?.scrollTo(r.start.offset,!1)}}}(r),{itemStore:p,zoomedInPath:f}=eh(),b=f?.isEqual(r),j=p.getStateOrInitialize(e),y=r.isRoot(),S=e.tags.name(),P=n.header??(y?"hide":"show"),w="hide"!==P&&(n.collapsible??!0),Q=n.size??"normal",C="tooltip"!==x,N=!w||!j.collapsed,k=(0,v.useCallback)(e=>{l.current=e,b&&o()},[b,o]);return(0,O.jsx)(z,{children:(0,O.jsxs)("div",{ref:a,children:["hide"!==P&&(0,O.jsxs)("header",{ref:k,tabIndex:"tooltip"===x?void 0:0,className:(0,E.$)("flex justify-between group pr-0.5 hover:bg-stone-100 rounded-sm focus-visible:outline-none",b?"focus:bg-indigo-50 mb-2 px-0.5 py-1":"focus:bg-indigo-100"),onFocus:e=>{g()},onKeyDown:e=>{b?m(e):h(e)},children:[(0,O.jsxs)("div",{className:"inline-flex items-center",children:[w&&(()=>{let t=j.collapsed?nK:n0;return eN(e)?(0,O.jsx)("div",{className:(0,E.$)("w-4 mr-1.5 flex justify-center cursor-pointer hover:!text-stone-600",N?"text-stone-600 opacity-40":"text-stone-800 opacity-40"),onClick:c.toggleCollapsed,children:(0,O.jsx)(t,{size:13})}):(0,O.jsx)("div",{className:"w-4 mr-1.5"})})(),(()=>{let e=function(e){return e.lastItem()?.toDisplayString()||eS(e)}(r),n="large"!==P&&r.edges.length>1,i=(()=>{let e="text-orange-900";return"Array"!==t?.tag||S?r.edges.length>1&&(e="text-teal-700"):e="text-stone-400",e})();return(0,O.jsxs)("div",{className:(0,E.$)("leading-3",n||"mr-3"),children:[(0,O.jsx)("span",{className:(0,E.$)(!S&&"font-mono","large"===P?(0,E.$)("text-md font-bold",i):y?"text-sm text-stone-600 font-semibold":(0,E.$)("text-sm",C&&"cursor-pointer hover:underline",i)),onClick:d,children:S||e}),n&&(0,O.jsx)("span",{className:"text-gray-400 font-mono",children:":"})]})})(),!N&&(0,O.jsx)("div",{className:"text-sm text-blue-800 ml-2",children:(0,O.jsx)(n6,{value:e})}),!N&&(0,O.jsx)(n8,{value:e})]}),"tooltip"!==x&&(0,O.jsx)("div",{className:"inline-flex space-x-1 items-center",children:(0,O.jsx)(n3,{value:e})})]}),N&&(0,O.jsxs)("div",{className:(0,E.$)("flex w-full",!!eQ(e)&&"py-2"),children:[w&&("Dict"===i||"Array"===i?(0,O.jsx)("div",{className:"group w-4 shrink-0 flex justify-center cursor-pointer",onClick:c.toggleCollapsed,children:(0,O.jsx)("div",{className:"w-px bg-stone-100 group-hover:bg-stone-400"})}):(0,O.jsx)("div",{className:"flex w-4 min-w-[1rem]"})),(0,O.jsx)("div",{className:"grow",children:(0,O.jsx)(n9,{value:e,size:Q})})]})]})})},it=({value:e,...t})=>k(e)?(0,O.jsx)(ie,{value:e,...t},e.context.path.uid()):(0,O.jsx)(V,{heading:"Can't display pathless value"}),ii=({text:e,onClick:t})=>(0,O.jsxs)("div",{className:"flex items-center",children:[(0,O.jsx)("span",{onClick:t,className:"text-sm text-stone-500 hover:text-stone-900 hover:underline font-mono curs
5or-pointer",children:e}),(0,O.jsx)(j.vK,{className:"text-slate-300",size:24})]}),ir=({zoomedInPath:e,rootPath:t})=>{let n=eO(),i=ep();if(t&&t.isEqual(e))return null;let r=t?.edges.length?t.edges.length-1:0;return(0,O.jsxs)("div",{className:"flex items-center",children:[!t?.edges.length&&(0,O.jsx)(ii,{onClick:n,text:"Home"}),e.allPrefixPaths({includeRoot:!1}).slice(r,-1).map((e,t)=>(0,O.jsx)(ii,{onClick:()=>i(e),text:e.edges[t+r].toDisplayString()},t))]})},ia=({value:e})=>{let t,{zoomedInPath:n}=eh(),i=function(){let{itemStore:e}=eh();return(t,n)=>t.getSubvalueByPath(n,ew(e))}();return n&&(t=i(e,n)),n?(0,O.jsxs)("div",{className:"space-y-3 pl-3",children:[(0,O.jsx)(ir,{zoomedInPath:n,rootPath:e.context?.path}),t?(0,O.jsx)(it,{value:t,collapsible:!1,header:"large",size:"large"}):(0,O.jsx)(V,{heading:"ZoomedIn variable is not defined"})]}):(0,O.jsx)(it,{value:e,size:"large"})},il=(0,v.forwardRef)(function({value:e,editor:t,...n},i){return(0,O.jsx)(z,{children:(0,O.jsx)(ey,{partialPlaygroundSettings:n,editor:t,ref:i,rootValue:e,children:(0,O.jsx)(ia,{value:e})})})});il.displayName="SquiggleViewer";let is=(0,v.memo)(il),io=(0,v.forwardRef)(function({outputResult:e,viewerTab:t,isSimulating:n,editor:i,playgroundSettings:r},a){if(!e.ok)return(0,O.jsx)(nA,{error:e.value});let l=e.value;if("AST"===t)return(0,O.jsx)("pre",{className:"text-xs",children:JSON.stringify(l.bindings.asValue().context?.ast,null,2)});let s=function(e,t){if(!t.ok)return;let n=t.value;switch(e){case"Result":return n.result;case"Variables":return n.bindings.asValue();case"Imports":return n.imports.asValue();case"Exports":return n.exports.asValue();case"AST":return}if("CustomResultPath"===e.tag)return("result"===e.value.root?t.value.result:t.value.bindings.asValue()).getSubvalueByPath(e.value,()=>void 0)}(t,e);return s?(0,O.jsxs)("div",{className:"relative",children:[n&&(0,O.jsx)("div",{className:"absolute z-10 inset-0 bg-white opacity-50"}),(0,O.jsx)(is,{ref:a,value:s,editor:i,...r})]}):null}),ic=({title:e,type:t})=>{let n=null===t;return(0,O.jsxs)("div",{className:"flex justify-between",children:[(0,O.jsx)("span",{className:(0,E.A)(n&&"text-slate-400"),children:e}),n?(0,O.jsx)("span",{className:"text-slate-300",children:"Empty"}):(0,O.jsx)("span",{className:"text-blue-800",children:t})]})},iu=({viewerTab:e,setViewerTab:t,outputResult:n})=>{let i=n.ok&&"Void"!==n.value.result.tag,r=n.ok?n.value.bindings.size():0,a=n.ok?n.value.imports.size():0,l=n.ok?n.value.exports.size():0;return(0,O.jsx)(j.ms,{render:({close:e})=>(0,O.jsxs)(j.rI,{children:[!!a&&(0,O.jsx)(j.GJ,{icon:j.r$,title:(0,O.jsx)(ic,{title:"Imports",type:a?`{}${a}`:null}),onClick:()=>{t("Imports"),e()}}),!!r&&(0,O.jsx)(j.GJ,{icon:j.r$,title:(0,O.jsx)(ic,{title:"Variables",type:r?`{}${r}`:null}),onClick:()=>{t("Variables"),e()}}),!!l&&(0,O.jsx)(j.GJ,{icon:j.r$,title:(0,O.jsx)(ic,{title:"Exports",type:l?`{}${l}`:null}),onClick:()=>{t("Exports"),e()}}),(0,O.jsx)(j.GJ,{icon:j.r$,title:(0,O.jsx)(ic,{title:"Result",type:i?"":null}),onClick:()=>{t("Result"),e()}}),(0,O.jsx)(j.GR,{children:"Debugging"}),(0,O.jsx)(j.GJ,{icon:j.r$,title:(0,O.jsx)(ic,{title:"AST",type:""}),onClick:()=>{t("AST"),e()}})]}),children:(0,O.jsx)(j.$n,{size:"small",children:(0,O.jsxs)("div",{className:"flex items-center space-x-1.5",children:[(0,O.jsx)("span",{children:function(e){return"object"==typeof e&&"CustomResultPath"===e.tag?"Custom Path":e}(e)}),(0,O.jsx)(j.o7,{className:"rotate-180 text-slate-400",size:10})]})})})},id=(0,v.forwardRef)(function({simulation:e,playgroundSettings:t,showMenu:n=!0,editor:i,defaultTab:r},a){var l;let[s,o]=(0,v.useState)(r??((l=e.output)&&l.ok&&"Void"!==l.value.result.tag?"Result":"Variables")),{output:c}=e;return(0,O.jsx)($,{menu:n?(0,O.jsx)(iu,{viewerTab:s,setViewerTab:o,outputResult:c}):(0,O.jsx)("div",{}),indicator:(0,O.jsx)(A,{simulation:e}),viewer:(0,O.jsx)(io,{viewerTab:s,outputResult:c,isSimulating:y(e),playgroundSettings:t,ref:a,editor:i})})}),im=(0,v.memo)(function({code:e,project:t,continues:n,environment:i,rootPathOverride:r,...a}){let{simulation:l}=P({code:e,setup:t?{type:"project",project:t,continues:n}:{type:"standalone"},environment:i});return l?(0,O.jsx)(id,{simulation:l,playgroundSettings:a,showMenu:!r,defaultTab:r?{tag:"CustomResultPath",value:r}:void 0}):(0,O.jsx)(j.fN,{className:"animate-spin"})}),ih={scaleLinear:m,scaleLog:g,scaleSymlog:h,scalePow:x}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.