@motionscript/math 0.1.0-alpha.7 → 0.1.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +49 -48
  4. package/README.md +390 -391
  5. package/dist/annotate/angle-mark.d.ts +6 -6
  6. package/dist/annotate/angle-mark.js.map +1 -1
  7. package/dist/annotate/curly-brace.d.ts +9 -9
  8. package/dist/annotate/curly-brace.js.map +1 -1
  9. package/dist/annotate/emphasis-mark.d.ts +9 -9
  10. package/dist/annotate/emphasis-mark.js.map +1 -1
  11. package/dist/browser/chunks/{chunk-ABYBW64J.js → chunk-IRZCG6PM.js} +2 -2
  12. package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
  13. package/dist/browser/chunks/{chunk-K77KLQX4.js → chunk-WMVW6ZIV.js} +2 -2
  14. package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
  15. package/dist/browser/chunks/{mathjax-DNP3YRES.js → mathjax-WV55AC2P.js} +1 -1
  16. package/dist/browser/chunks/{mathjax-DNP3YRES.js.map → mathjax-WV55AC2P.js.map} +1 -1
  17. package/dist/browser/index.js +1 -1
  18. package/dist/browser/index.js.map +3 -3
  19. package/dist/browser/kit.js +1 -1
  20. package/dist/browser/manifest.json +1 -1
  21. package/dist/browser/tex.js +1 -1
  22. package/dist/browser/tex.js.map +1 -1
  23. package/dist/engine.d.ts +1 -1
  24. package/dist/engine.js +1 -1
  25. package/dist/engine.js.map +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/kit/brace.js.map +1 -1
  28. package/dist/kit/cache.js.map +1 -1
  29. package/dist/kit/component.d.ts.map +1 -1
  30. package/dist/kit/component.js.map +1 -1
  31. package/dist/kit/contour.js.map +1 -1
  32. package/dist/kit/coords.js.map +1 -1
  33. package/dist/kit/curve.js.map +1 -1
  34. package/dist/kit/equation.js.map +1 -1
  35. package/dist/kit/equation3d.js.map +1 -1
  36. package/dist/kit/expression.js.map +1 -1
  37. package/dist/kit/field-mark.d.ts.map +1 -1
  38. package/dist/kit/field-mark.js.map +1 -1
  39. package/dist/kit/field.js.map +1 -1
  40. package/dist/kit/follow.d.ts +2 -2
  41. package/dist/kit/follow.d.ts.map +1 -1
  42. package/dist/kit/follow.js.map +1 -1
  43. package/dist/kit/furniture.js.map +1 -1
  44. package/dist/kit/geometry.js.map +1 -1
  45. package/dist/kit/graph.js.map +1 -1
  46. package/dist/kit/mark.js.map +1 -1
  47. package/dist/kit/part-fills.js.map +1 -1
  48. package/dist/kit/place.js.map +1 -1
  49. package/dist/kit/sampler.js +1 -1
  50. package/dist/kit/sampler.js.map +1 -1
  51. package/dist/kit/scale.js.map +1 -1
  52. package/dist/kit/source.js.map +1 -1
  53. package/dist/kit/system.js.map +1 -1
  54. package/dist/kit/ticks.js.map +1 -1
  55. package/dist/kit/withdrawn.js.map +1 -1
  56. package/dist/marks/curve-area.js.map +1 -1
  57. package/dist/marks/drop-lines.d.ts +6 -6
  58. package/dist/marks/drop-lines.js.map +1 -1
  59. package/dist/marks/plot-point.d.ts +3 -3
  60. package/dist/marks/plot-point.js.map +1 -1
  61. package/dist/marks/riemann-sum.d.ts +3 -3
  62. package/dist/marks/riemann-sum.js.map +1 -1
  63. package/dist/marks/tangent-line.d.ts +6 -6
  64. package/dist/marks/tangent-line.js.map +1 -1
  65. package/dist/marks/vector-arrow.d.ts +6 -6
  66. package/dist/marks/vector-arrow.js.map +1 -1
  67. package/dist/nodes.js.map +1 -1
  68. package/dist/plots/function-plot.d.ts +8 -8
  69. package/dist/plots/function-plot.d.ts.map +1 -1
  70. package/dist/plots/function-plot.js.map +1 -1
  71. package/dist/plots/points-plot.js.map +1 -1
  72. package/dist/plots/stream-lines.js.map +1 -1
  73. package/dist/plots/traced-path.js.map +1 -1
  74. package/dist/plots/vector-field.js.map +1 -1
  75. package/dist/structures/graph-layout.js.map +1 -1
  76. package/dist/structures/network-graph.js.map +1 -1
  77. package/dist/structures/sample-space.js.map +1 -1
  78. package/dist/systems/axes2d.d.ts.map +1 -1
  79. package/dist/systems/axes2d.js.map +1 -1
  80. package/dist/systems/number-line.js.map +1 -1
  81. package/dist/systems/number-plane.js.map +1 -1
  82. package/dist/systems/polar-plane.js.map +1 -1
  83. package/dist/tex/geometry.js.map +1 -1
  84. package/dist/tex/index.js.map +1 -1
  85. package/dist/tex/mathjax.js.map +1 -1
  86. package/dist/tex/matrix.d.ts +2 -2
  87. package/dist/tex/matrix.js.map +1 -1
  88. package/dist/tex/node.d.ts +2 -2
  89. package/dist/tex/node.js.map +1 -1
  90. package/dist/tex/tween.js.map +1 -1
  91. package/dist/tex/typeset.d.ts +4 -4
  92. package/dist/tex/typeset.d.ts.map +1 -1
  93. package/dist/tex/typeset.js.map +1 -1
  94. package/dist/three/axes3d.js.map +1 -1
  95. package/dist/three/curve-plot3d.d.ts +27 -27
  96. package/dist/three/curve-plot3d.d.ts.map +1 -1
  97. package/dist/three/curve-plot3d.js +3 -2
  98. package/dist/three/curve-plot3d.js.map +1 -1
  99. package/dist/three/entries.js.map +1 -1
  100. package/dist/three/label3d.d.ts.map +1 -1
  101. package/dist/three/label3d.js +3 -1
  102. package/dist/three/label3d.js.map +1 -1
  103. package/dist/three/plot-point3d.d.ts +27 -27
  104. package/dist/three/plot-point3d.js.map +1 -1
  105. package/dist/three/space.js.map +1 -1
  106. package/dist/three/surface-plot3d.d.ts +36 -36
  107. package/dist/three/surface-plot3d.js +6 -1
  108. package/dist/three/surface-plot3d.js.map +1 -1
  109. package/dist/three/vector-arrow3d.d.ts +27 -27
  110. package/dist/three/vector-arrow3d.js.map +1 -1
  111. package/package.json +5 -4
  112. package/registry.json +251 -251
  113. package/src/annotate/angle-mark.ts +137 -137
  114. package/src/annotate/curly-brace.ts +148 -148
  115. package/src/annotate/emphasis-mark.ts +118 -118
  116. package/src/engine.ts +86 -86
  117. package/src/index.ts +29 -29
  118. package/src/kit/brace.ts +37 -37
  119. package/src/kit/cache.ts +61 -61
  120. package/src/kit/component.ts +57 -57
  121. package/src/kit/contour.ts +94 -94
  122. package/src/kit/coords.ts +278 -278
  123. package/src/kit/curve.ts +47 -47
  124. package/src/kit/equation.ts +181 -181
  125. package/src/kit/equation3d.ts +137 -137
  126. package/src/kit/expression.ts +159 -159
  127. package/src/kit/field-mark.ts +171 -171
  128. package/src/kit/field.ts +50 -50
  129. package/src/kit/follow.ts +229 -229
  130. package/src/kit/furniture.ts +113 -113
  131. package/src/kit/geometry.ts +49 -49
  132. package/src/kit/graph.ts +116 -116
  133. package/src/kit/mark.ts +152 -152
  134. package/src/kit/part-fills.ts +61 -61
  135. package/src/kit/place.ts +77 -77
  136. package/src/kit/sampler.ts +281 -281
  137. package/src/kit/scale.ts +39 -39
  138. package/src/kit/source.ts +57 -57
  139. package/src/kit/system.ts +105 -105
  140. package/src/kit/ticks.ts +85 -85
  141. package/src/kit/withdrawn.ts +8 -8
  142. package/src/marks/curve-area.ts +89 -89
  143. package/src/marks/drop-lines.ts +71 -71
  144. package/src/marks/plot-point.ts +102 -102
  145. package/src/marks/riemann-sum.ts +99 -99
  146. package/src/marks/tangent-line.ts +119 -119
  147. package/src/marks/vector-arrow.ts +98 -98
  148. package/src/nodes.ts +99 -99
  149. package/src/plots/function-plot.ts +220 -220
  150. package/src/plots/points-plot.ts +103 -103
  151. package/src/plots/stream-lines.ts +160 -160
  152. package/src/plots/traced-path.ts +70 -70
  153. package/src/plots/vector-field.ts +107 -107
  154. package/src/structures/graph-layout.ts +145 -145
  155. package/src/structures/network-graph.ts +291 -291
  156. package/src/structures/sample-space.ts +210 -210
  157. package/src/systems/axes2d.ts +226 -226
  158. package/src/systems/number-line.ts +130 -130
  159. package/src/systems/number-plane.ts +232 -232
  160. package/src/systems/polar-plane.ts +177 -177
  161. package/src/tex/geometry.ts +703 -703
  162. package/src/tex/index.ts +15 -15
  163. package/src/tex/mathjax.ts +82 -82
  164. package/src/tex/matrix.ts +97 -97
  165. package/src/tex/node.ts +74 -74
  166. package/src/tex/tween.ts +308 -308
  167. package/src/tex/typeset.ts +461 -461
  168. package/src/three/axes3d.ts +267 -267
  169. package/src/three/curve-plot3d.ts +146 -144
  170. package/src/three/entries.ts +42 -42
  171. package/src/three/label3d.ts +52 -50
  172. package/src/three/plot-point3d.ts +63 -63
  173. package/src/three/space.ts +92 -92
  174. package/src/three/surface-plot3d.ts +318 -312
  175. package/src/three/vector-arrow3d.ts +88 -88
  176. package/dist/browser/chunks/chunk-ABYBW64J.js.map +0 -7
  177. package/dist/browser/chunks/chunk-K77KLQX4.js.map +0 -7
  178. package/dist/kit/placement.d.ts +0 -8
  179. package/dist/kit/placement.d.ts.map +0 -1
  180. package/dist/kit/placement.js +0 -8
  181. package/dist/kit/placement.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import{$ as Ka,$a as Kb,A as ja,Aa as jb,Ab as jc,B as ka,Ba as kb,Bb as kc,C as la,Ca as lb,Cb as lc,D as ma,Da as mb,Db as mc,E as na,Ea as nb,Eb as nc,F as oa,Fa as ob,G as pa,Ga as pb,H as qa,Ha as qb,I as ra,Ia as rb,J as sa,Ja as sb,K as ta,Ka as tb,L as ua,La as ub,M as va,Ma as vb,N as wa,Na as wb,O as xa,Oa as xb,P as ya,Pa as yb,Q as za,Qa as zb,R as Aa,Ra as Ab,S as Ba,Sa as Bb,T as Ca,Ta as Cb,U as Da,Ua as Db,V as Ea,Va as Eb,W as Fa,Wa as Fb,X as Ga,Xa as Gb,Y as Ha,Ya as Hb,Z as Ia,Za as Ib,_ as Ja,_a as Jb,a as L,aa as La,ab as Lb,b as M,ba as Ma,bb as Mb,c as N,ca as Na,cb as Nb,d as O,da as Oa,db as Ob,e as P,ea as Pa,eb as Pb,f as Q,fa as Qa,fb as Qb,g as R,ga as Ra,gb as Rb,h as S,ha as Sa,hb as Sb,i as T,ia as Ta,ib as Tb,j as U,ja as Ua,jb as Ub,k as V,ka as Va,kb as Vb,l as W,la as Wa,lb as Wb,m as X,ma as Xa,mb as Xb,n as Y,na as Ya,nb as Yb,o as Z,oa as Za,ob as Zb,p as _,pa as _a,pb as _b,q as $,qa as $a,qb as $b,r as aa,ra as ab,rb as ac,s as ba,sa as bb,sb as bc,t as ca,ta as cb,tb as cc,u as da,ua as db,ub as dc,v as ea,va as eb,vb as ec,w as fa,wa as fb,wb as fc,x as ga,xa as gb,xb as gc,y as ha,ya as hb,yb as hc,z as ia,za as ib,zb as ic}from"./chunks/chunk-ABYBW64J.js";import{A,B,C,D,E,F,G,H,I,J,K,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunks/chunk-K77KLQX4.js";export{gb as AXES,hb as AXES_COMMANDS,W as AXIS_COLOR,mb as Axes2d,ta as CURVE_KEYS,Yb as EQUATION_KINDS,ia as EQUATION_VARIABLES,Rb as EQUATION_VARIABLES_3D,gc as FIELD_COMMANDS,fc as FIELD_STATE,nb as FIELD_VARIABLES,lc as FILL_PAINT,zb as FOLLOW_COMMANDS,yb as FOLLOW_STATE,wb as FunctionPlot,Mb as GRAPH_3D,jc as GRAPH_LAYOUTS,P as IDENTITY_MATRIX,K as Latex,g as LatexError,f as LatexNotLoaded,b as MATHJAX_LOADER,ea as MATH_DIALECT,u as Morph,nc as OUTLINE_TRIM,Eb as OWN_FRAME,l as PAINT,m as PAINT_COMMANDS,O as PIXEL_MAP,za as PLANE_ENTRY,xa as PLOT,X as PLOT_COLOR,ub as PLOT_COMMANDS,Aa as PLOT_REF,tb as PLOT_STATE,vb as PLOT_STROKE,mc as STROKE_PAINT,wa as SYSTEM,ya as SYSTEM_ENTRY,y as TYPESET,z as TYPESET_COMMANDS,pa as UNSET_PARAM,Fb as add,Qb as aim,ba as along,Wa as anchored,lb as axesFurniture,jb as axesMap,kb as axesOf,M as axisScale,Gb as between,e as blankLatex,Ha as boundsOfRuns,Jb as braceOutline,h as buildLatexPath,N as cartesianMap,Va as castsShadow,Ja as clamp,$b as colorAt,ga as compileExpression,ha as compileExpressionCached,Ab as container,a as createBoundedCache,Ea as curveFor,ua as curveValue,Z as declareFormulas,k as defaultLatexMorph,ec as domainEntry,ic as drawField,E as drawFormula,Kb as drawLabel3D,$ as drawLabels,Ta as drawMark,db as drawSystem,aa as drawn,ka as equationError,la as equationParams,fa as expressionVocabulary,qb as fieldError,ob as fieldParams,cc as fillAt,j as findLatexParts,Cb as followedQuad,fb as formatTick,G as formula,A as formulaFrame,I as formulaOf,Nb as graphEntry,Ob as graphOf,Ra as graphPoint,Lb as graphSpace,Ib as grown,Hb as heading,Ia as inflate,Pa as inkCentre,Oa as inkSize,va as isCurve,H as isFormula,S as isIdentityMatrix,J as latexPartBounds,i as latexPartNames,kc as layOut,C as layoutFormula,oa as lerpDomain,bc as lerpFillScale,ca as lerpInterval,R as lerpMatrix,w as lerpMorph,qa as lerpParams,r as lerpPartFills,_b as lerpScale,na as lerpSource,V as lineThrough,n as listed,ib as loadAxes,D as loadFormula,_ as loadFormulas,c as loadMathJax,Ma as markRuns,Sa as markShape,d as mathJaxLoaded,B as measureFormula,dc as meshEntries,x as morphOf,o as omit,Ya as openPlane,Db as outlineBounds,Qa as ownPoint,p as painted,ja as parseEquation,pb as parseField,Vb as parseSpaceCurve,Ub as parseSurface,F as partBoundsIn,t as partPaint,Xa as placeOnMap,Za as plotArea,Da as plotPlane,ac as readFillScale,da as readInterval,Q as readMatrix,q as readPartFills,Zb as readScale,ma as readSource,Na as reading,Fa as refId,L as resolveInterval,Bb as resting,sa as revisionOf,Ga as runsToPath,sb as sampleCurve,ra as scopeFor,Ca as settle,v as settled,Xb as spaceCurveError,Tb as spaceCurveParams,Pb as spaceOf,Ka as stated,Ua as strokeShape,Wb as surfaceError,Sb as surfaceParams,bb as systemLayout,_a as systemMap,cb as systemOpenPlane,Ba as systemPlane,ab as systemProvides,$a as systemSize,eb as ticksFor,rb as traceContour,hc as traceField,xb as tracePlot,La as traced,T as transformedMap,U as warpedMap,s as withPartFill,Y as withoutTips};
1
+ import{$ as Ka,$a as Kb,A as ja,Aa as jb,Ab as jc,B as ka,Ba as kb,Bb as kc,C as la,Ca as lb,Cb as lc,D as ma,Da as mb,Db as mc,E as na,Ea as nb,Eb as nc,F as oa,Fa as ob,G as pa,Ga as pb,H as qa,Ha as qb,I as ra,Ia as rb,J as sa,Ja as sb,K as ta,Ka as tb,L as ua,La as ub,M as va,Ma as vb,N as wa,Na as wb,O as xa,Oa as xb,P as ya,Pa as yb,Q as za,Qa as zb,R as Aa,Ra as Ab,S as Ba,Sa as Bb,T as Ca,Ta as Cb,U as Da,Ua as Db,V as Ea,Va as Eb,W as Fa,Wa as Fb,X as Ga,Xa as Gb,Y as Ha,Ya as Hb,Z as Ia,Za as Ib,_ as Ja,_a as Jb,a as L,aa as La,ab as Lb,b as M,ba as Ma,bb as Mb,c as N,ca as Na,cb as Nb,d as O,da as Oa,db as Ob,e as P,ea as Pa,eb as Pb,f as Q,fa as Qa,fb as Qb,g as R,ga as Ra,gb as Rb,h as S,ha as Sa,hb as Sb,i as T,ia as Ta,ib as Tb,j as U,ja as Ua,jb as Ub,k as V,ka as Va,kb as Vb,l as W,la as Wa,lb as Wb,m as X,ma as Xa,mb as Xb,n as Y,na as Ya,nb as Yb,o as Z,oa as Za,ob as Zb,p as _,pa as _a,pb as _b,q as $,qa as $a,qb as $b,r as aa,ra as ab,rb as ac,s as ba,sa as bb,sb as bc,t as ca,ta as cb,tb as cc,u as da,ua as db,ub as dc,v as ea,va as eb,vb as ec,w as fa,wa as fb,wb as fc,x as ga,xa as gb,xb as gc,y as ha,ya as hb,yb as hc,z as ia,za as ib,zb as ic}from"./chunks/chunk-IRZCG6PM.js";import{A,B,C,D,E,F,G,H,I,J,K,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunks/chunk-WMVW6ZIV.js";export{gb as AXES,hb as AXES_COMMANDS,W as AXIS_COLOR,mb as Axes2d,ta as CURVE_KEYS,Yb as EQUATION_KINDS,ia as EQUATION_VARIABLES,Rb as EQUATION_VARIABLES_3D,gc as FIELD_COMMANDS,fc as FIELD_STATE,nb as FIELD_VARIABLES,lc as FILL_PAINT,zb as FOLLOW_COMMANDS,yb as FOLLOW_STATE,wb as FunctionPlot,Mb as GRAPH_3D,jc as GRAPH_LAYOUTS,P as IDENTITY_MATRIX,K as Latex,g as LatexError,f as LatexNotLoaded,b as MATHJAX_LOADER,ea as MATH_DIALECT,u as Morph,nc as OUTLINE_TRIM,Eb as OWN_FRAME,l as PAINT,m as PAINT_COMMANDS,O as PIXEL_MAP,za as PLANE_ENTRY,xa as PLOT,X as PLOT_COLOR,ub as PLOT_COMMANDS,Aa as PLOT_REF,tb as PLOT_STATE,vb as PLOT_STROKE,mc as STROKE_PAINT,wa as SYSTEM,ya as SYSTEM_ENTRY,y as TYPESET,z as TYPESET_COMMANDS,pa as UNSET_PARAM,Fb as add,Qb as aim,ba as along,Wa as anchored,lb as axesFurniture,jb as axesMap,kb as axesOf,M as axisScale,Gb as between,e as blankLatex,Ha as boundsOfRuns,Jb as braceOutline,h as buildLatexPath,N as cartesianMap,Va as castsShadow,Ja as clamp,$b as colorAt,ga as compileExpression,ha as compileExpressionCached,Ab as container,a as createBoundedCache,Ea as curveFor,ua as curveValue,Z as declareFormulas,k as defaultLatexMorph,ec as domainEntry,ic as drawField,E as drawFormula,Kb as drawLabel3D,$ as drawLabels,Ta as drawMark,db as drawSystem,aa as drawn,ka as equationError,la as equationParams,fa as expressionVocabulary,qb as fieldError,ob as fieldParams,cc as fillAt,j as findLatexParts,Cb as followedQuad,fb as formatTick,G as formula,A as formulaFrame,I as formulaOf,Nb as graphEntry,Ob as graphOf,Ra as graphPoint,Lb as graphSpace,Ib as grown,Hb as heading,Ia as inflate,Pa as inkCentre,Oa as inkSize,va as isCurve,H as isFormula,S as isIdentityMatrix,J as latexPartBounds,i as latexPartNames,kc as layOut,C as layoutFormula,oa as lerpDomain,bc as lerpFillScale,ca as lerpInterval,R as lerpMatrix,w as lerpMorph,qa as lerpParams,r as lerpPartFills,_b as lerpScale,na as lerpSource,V as lineThrough,n as listed,ib as loadAxes,D as loadFormula,_ as loadFormulas,c as loadMathJax,Ma as markRuns,Sa as markShape,d as mathJaxLoaded,B as measureFormula,dc as meshEntries,x as morphOf,o as omit,Ya as openPlane,Db as outlineBounds,Qa as ownPoint,p as painted,ja as parseEquation,pb as parseField,Vb as parseSpaceCurve,Ub as parseSurface,F as partBoundsIn,t as partPaint,Xa as placeOnMap,Za as plotArea,Da as plotPlane,ac as readFillScale,da as readInterval,Q as readMatrix,q as readPartFills,Zb as readScale,ma as readSource,Na as reading,Fa as refId,L as resolveInterval,Bb as resting,sa as revisionOf,Ga as runsToPath,sb as sampleCurve,ra as scopeFor,Ca as settle,v as settled,Xb as spaceCurveError,Tb as spaceCurveParams,Pb as spaceOf,Ka as stated,Ua as strokeShape,Wb as surfaceError,Sb as surfaceParams,bb as systemLayout,_a as systemMap,cb as systemOpenPlane,Ba as systemPlane,ab as systemProvides,$a as systemSize,eb as ticksFor,rb as traceContour,hc as traceField,xb as tracePlot,La as traced,T as transformedMap,U as warpedMap,s as withPartFill,Y as withoutTips};
2
2
  //# sourceMappingURL=kit.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motionscript/math",
3
- "version": "0.1.0-alpha.7",
3
+ "version": "0.1.0-alpha.8",
4
4
  "exports": {
5
5
  ".": "dist/browser/index.js",
6
6
  "./kit": "dist/browser/kit.js",
@@ -1,2 +1,2 @@
1
- import{K as t,L as l,M as a,b as o,c as r,d as e,e as x,f as L,g as m,h as d,i as f,j as p,k as i}from"./chunks/chunk-K77KLQX4.js";var M=[t,a];export{t as Latex,m as LatexError,a as LatexMatrix,L as LatexNotLoaded,o as MATHJAX_LOADER,M as TEX_NODES,x as blankLatex,d as buildLatexPath,i as defaultLatexMorph,p as findLatexParts,f as latexPartNames,r as loadMathJax,e as mathJaxLoaded,l as matrixSource};
1
+ import{K as t,L as l,M as a,b as o,c as r,d as e,e as x,f as L,g as m,h as d,i as f,j as p,k as i}from"./chunks/chunk-WMVW6ZIV.js";var M=[t,a];export{t as Latex,m as LatexError,a as LatexMatrix,L as LatexNotLoaded,o as MATHJAX_LOADER,M as TEX_NODES,x as blankLatex,d as buildLatexPath,i as defaultLatexMorph,p as findLatexParts,f as latexPartNames,r as loadMathJax,e as mathJaxLoaded,l as matrixSource};
2
2
  //# sourceMappingURL=tex.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/tex/index.ts"],
4
- "sourcesContent": ["import { LatexMatrix } from './matrix';\r\nimport { Latex } from './node';\r\n\r\nexport * from './node';\r\nexport * from './matrix';\r\nexport {\r\n blankLatex, buildLatexPath, findLatexParts, latexPartNames, LatexError, LatexNotLoaded, loadMathJax, mathJaxLoaded, MATHJAX_LOADER,\r\n} from './geometry';\r\nexport type { LatexPart, LatexToken, LatexPathResult } from './geometry';\r\nexport { defaultLatexMorph } from './tween';\r\nexport type { AnimatedToken, LatexMorphStrategy } from './tween';\r\n\r\n/** The typeset-math node types, for a host that registers only these. */\r\n// Typed by name, so the declaration names each component rather than spelling out its type through core.\r\nexport const TEX_NODES: (typeof Latex | typeof LatexMatrix)[] = [Latex, LatexMatrix];\r\n"],
4
+ "sourcesContent": ["import { LatexMatrix } from './matrix';\nimport { Latex } from './node';\n\nexport * from './node';\nexport * from './matrix';\nexport {\n blankLatex, buildLatexPath, findLatexParts, latexPartNames, LatexError, LatexNotLoaded, loadMathJax, mathJaxLoaded, MATHJAX_LOADER,\n} from './geometry';\nexport type { LatexPart, LatexToken, LatexPathResult } from './geometry';\nexport { defaultLatexMorph } from './tween';\nexport type { AnimatedToken, LatexMorphStrategy } from './tween';\n\n/** The typeset-math node types, for a host that registers only these. */\n// Typed by name, so the declaration names each component rather than spelling out its type through core.\nexport const TEX_NODES: (typeof Latex | typeof LatexMatrix)[] = [Latex, LatexMatrix];\n"],
5
5
  "mappings": "mIAcO,IAAMA,EAAmD,CAACC,EAAOC,CAAW",
6
6
  "names": ["TEX_NODES", "Latex", "LatexMatrix"]
7
7
  }
package/dist/engine.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The math **kit**: what the nodes share, and what a copied one does not copy.
3
3
  *
4
- * `ms add` writes a node's own files into a project and rewrites its reach for
4
+ * A copy takes a node's own files into a project and rewrites its reach for
5
5
  * these to `@motionscript/math`, so MathJax, the morph and every shared module
6
6
  * stay a real dependency with one identity.
7
7
  */
package/dist/engine.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The math **kit**: what the nodes share, and what a copied one does not copy.
3
3
  *
4
- * `ms add` writes a node's own files into a project and rewrites its reach for
4
+ * A copy takes a node's own files into a project and rewrites its reach for
5
5
  * these to `@motionscript/math`, so MathJax, the morph and every shared module
6
6
  * stay a real dependency with one identity.
7
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACH,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,GACrI,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EACH,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAChJ,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,GACnD,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEzF,OAAO,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EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnF,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAClG,OAAO,EACH,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,GACpG,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["/**\r\n * The math **kit**: what the nodes share, and what a copied one does not copy.\r\n *\r\n * `ms add` writes a node's own files into a project and rewrites its reach for\r\n * these to `@motionscript/math`, so MathJax, the morph and every shared module\r\n * stay a real dependency with one identity.\r\n */\r\nexport {\r\n blankLatex, buildLatexPath, findLatexParts, latexPartNames, LatexError, LatexNotLoaded, loadMathJax, mathJaxLoaded, MATHJAX_LOADER,\r\n} from './tex/geometry';\r\nexport type { LatexPart, LatexToken, LatexPathResult } from './tex/geometry';\r\nexport { defaultLatexMorph } from './tex/tween';\r\nexport type { AnimatedToken, LatexMorphStrategy } from './tex/tween';\r\nexport { Latex } from './tex/node';\r\nexport type { LatexProps, LatexStrategies } from './tex/node';\r\nexport {\r\n drawFormula, formula, formulaFrame, formulaOf, isFormula, latexPartBounds, layoutFormula, lerpMorph, loadFormula, measureFormula, Morph, morphOf,\r\n partBoundsIn, settled, TYPESET, TYPESET_COMMANDS,\r\n} from './tex/typeset';\r\nexport type { FormulaFrame, Morphing, TypesetValues } from './tex/typeset';\r\nexport { lerpPartFills, partPaint, readPartFills, withPartFill } from './kit/part-fills';\r\nexport type { PartFill, PartFillResolved } from './kit/part-fills';\r\nexport { FILL_PAINT, OUTLINE_TRIM, STROKE_PAINT } from './kit/withdrawn';\r\nexport { createBoundedCache } from './kit/cache';\r\nexport { listed, omit, PAINT, PAINT_COMMANDS, painted } from './kit/component';\r\nexport type { BoundedCache } from './kit/cache';\r\n\r\nexport { drawSystem, plotArea, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from './kit/system';\r\nexport type { MapFor, SystemState } from './kit/system';\r\n// A number plane is axes with a grid, so a copied one builds on these rather than a copy of them.\r\nexport { Axes2d, AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes } from './systems/axes2d';\r\nexport type { Axes2dProps, AxesValues, AxisLayout } from './systems/axes2d';\r\nexport type { Anchor } from './kit/place';\r\nexport { anchored, openPlane, placeOnMap } from './kit/place';\r\nexport {\r\n castsShadow, drawMark, graphPoint, inkCentre, inkSize, markRuns, markShape, ownPoint, reading, strokeShape, traced,\r\n} from './kit/mark';\r\nexport type { MarkOptions, MarkPaint, MarkReading, MarkState, Tracer } from './kit/mark';\r\nexport { curveFor, PLANE_ENTRY, PLOT, PLOT_REF, plotPlane, refId, settle, SYSTEM, SYSTEM_ENTRY, systemPlane } from './kit/graph';\r\nexport type { GraphPlane } from './kit/graph';\r\nexport { axisScale, cartesianMap, resolveInterval, PIXEL_MAP } from './kit/coords';\r\nexport type { AxisScale, AxisScaling, CartesianOptions, CoordinateMap, Interval } from './kit/coords';\r\nexport { compileExpression, compileExpressionCached, expressionVocabulary, MATH_DIALECT } from './kit/expression';\r\nexport type { CompiledExpression, ExpressionScope, ExpressionVocabulary } from './kit/expression';\r\nexport { equationError, equationParams, parseEquation, EQUATION_VARIABLES } from './kit/equation';\r\nexport type { Equation } from './kit/equation';\r\nexport { lerpDomain, lerpParams, lerpSource, readSource, revisionOf, scopeFor, UNSET_PARAM } from './kit/source';\r\nexport type { PlotSource } from './kit/source';\r\nexport { sampleCurve } from './kit/sampler';\r\nexport type { CurveProjection, SampleOptions } from './kit/sampler';\r\nexport { formatTick, ticksFor } from './kit/ticks';\r\nexport type { Ticks } from './kit/ticks';\r\nexport { boundsOfRuns, clamp, inflate, runsToPath, stated } from './kit/geometry';\r\nexport { CURVE_KEYS, curveValue, isCurve } from './kit/curve';\r\nexport type { CurveValues } from './kit/curve';\r\nexport { along, AXIS_COLOR, declareFormulas, drawLabels, drawn, lerpInterval, loadFormulas, PLOT_COLOR, readInterval, withoutTips } from './kit/furniture';\r\nexport type { Label, LabelStyle } from './kit/furniture';\r\nexport {\r\n add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, grown, heading, outlineBounds, OWN_FRAME, resting,\r\n} from './kit/follow';\r\nexport type { FollowProps, FollowValues, Parted, Quad, Retarget, Target } from './kit/follow';\r\nexport {\r\n parseSpaceCurve, parseSurface, spaceCurveError, spaceCurveParams, surfaceError, surfaceParams, EQUATION_KINDS, EQUATION_VARIABLES_3D,\r\n} from './kit/equation3d';\r\nexport type { EquationLanguage, SpaceCurveEquation, SurfaceEquation } from './kit/equation3d';\r\nexport { aim, graphEntry, graphOf, graphSpace, spaceOf, GRAPH_3D } from './three/space';\r\nexport type { Graph3D, GraphSpace } from './three/space';\r\nexport { domainEntry, meshEntries } from './three/entries';\r\nexport { drawLabel3D } from './three/label3d';\r\nexport type { LabelStyle3D } from './three/label3d';\r\n// A traced path is a plot whose span follows a value, so a copied one builds on these rather than a copy of them.\r\nexport { FunctionPlot, PLOT_COMMANDS, PLOT_STATE, PLOT_STROKE, tracePlot } from './plots/function-plot';\r\nexport type { FunctionPlotProps, PlotValues } from './plots/function-plot';\r\nexport { drawField, FIELD_COMMANDS, FIELD_STATE, traceField } from './kit/field-mark';\r\nexport type { FieldDrawing, FieldProps, FieldSampler, FieldStroke, FieldValues } from './kit/field-mark';\r\nexport { fieldError, fieldParams, parseField, FIELD_VARIABLES } from './kit/field';\r\nexport type { FieldEquation } from './kit/field';\r\nexport { traceContour } from './kit/contour';\r\nexport { colorAt, fillAt, lerpFillScale, lerpScale, readFillScale, readScale } from './kit/scale';\r\nexport {\r\n IDENTITY_MATRIX, isIdentityMatrix, lerpMatrix, lineThrough, readMatrix, transformedMap, warpedMap,\r\n} from './kit/coords';\r\nexport type { Matrix2, Warp } from './kit/coords';\r\nexport { braceOutline } from './kit/brace';\r\nexport { GRAPH_LAYOUTS, layOut } from './structures/graph-layout';\r\nexport type { GraphEdge, GraphLayout } from './structures/graph-layout';\r\n"]}
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACH,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,GACrI,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EACH,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAChJ,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,GACnD,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEzF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/E,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1H,kGAAkG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AC;AAEtB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["/**\n * The math **kit**: what the nodes share, and what a copied one does not copy.\n *\n * A copy takes a node's own files into a project and rewrites its reach for\n * these to `@motionscript/math`, so MathJax, the morph and every shared module\n * stay a real dependency with one identity.\n */\nexport {\n blankLatex, buildLatexPath, findLatexParts, latexPartNames, LatexError, LatexNotLoaded, loadMathJax, mathJaxLoaded, MATHJAX_LOADER,\n} from './tex/geometry';\nexport type { LatexPart, LatexToken, LatexPathResult } from './tex/geometry';\nexport { defaultLatexMorph } from './tex/tween';\nexport type { AnimatedToken, LatexMorphStrategy } from './tex/tween';\nexport { Latex } from './tex/node';\nexport type { LatexProps, LatexStrategies } from './tex/node';\nexport {\n drawFormula, formula, formulaFrame, formulaOf, isFormula, latexPartBounds, layoutFormula, lerpMorph, loadFormula, measureFormula, Morph, morphOf,\n partBoundsIn, settled, TYPESET, TYPESET_COMMANDS,\n} from './tex/typeset';\nexport type { FormulaFrame, Morphing, TypesetValues } from './tex/typeset';\nexport { lerpPartFills, partPaint, readPartFills, withPartFill } from './kit/part-fills';\nexport type { PartFill, PartFillResolved } from './kit/part-fills';\nexport { FILL_PAINT, OUTLINE_TRIM, STROKE_PAINT } from './kit/withdrawn';\nexport { createBoundedCache } from './kit/cache';\nexport { listed, omit, PAINT, PAINT_COMMANDS, painted } from './kit/component';\nexport type { BoundedCache } from './kit/cache';\n\nexport { drawSystem, plotArea, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from './kit/system';\nexport type { MapFor, SystemState } from './kit/system';\n// A number plane is axes with a grid, so a copied one builds on these rather than a copy of them.\nexport { Axes2d, AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes } from './systems/axes2d';\nexport type { Axes2dProps, AxesValues, AxisLayout } from './systems/axes2d';\nexport type { Anchor } from './kit/place';\nexport { anchored, openPlane, placeOnMap } from './kit/place';\nexport {\n castsShadow, drawMark, graphPoint, inkCentre, inkSize, markRuns, markShape, ownPoint, reading, strokeShape, traced,\n} from './kit/mark';\nexport type { MarkOptions, MarkPaint, MarkReading, MarkState, Tracer } from './kit/mark';\nexport { curveFor, PLANE_ENTRY, PLOT, PLOT_REF, plotPlane, refId, settle, SYSTEM, SYSTEM_ENTRY, systemPlane } from './kit/graph';\nexport type { GraphPlane } from './kit/graph';\nexport { axisScale, cartesianMap, resolveInterval, PIXEL_MAP } from './kit/coords';\nexport type { AxisScale, AxisScaling, CartesianOptions, CoordinateMap, Interval } from './kit/coords';\nexport { compileExpression, compileExpressionCached, expressionVocabulary, MATH_DIALECT } from './kit/expression';\nexport type { CompiledExpression, ExpressionScope, ExpressionVocabulary } from './kit/expression';\nexport { equationError, equationParams, parseEquation, EQUATION_VARIABLES } from './kit/equation';\nexport type { Equation } from './kit/equation';\nexport { lerpDomain, lerpParams, lerpSource, readSource, revisionOf, scopeFor, UNSET_PARAM } from './kit/source';\nexport type { PlotSource } from './kit/source';\nexport { sampleCurve } from './kit/sampler';\nexport type { CurveProjection, SampleOptions } from './kit/sampler';\nexport { formatTick, ticksFor } from './kit/ticks';\nexport type { Ticks } from './kit/ticks';\nexport { boundsOfRuns, clamp, inflate, runsToPath, stated } from './kit/geometry';\nexport { CURVE_KEYS, curveValue, isCurve } from './kit/curve';\nexport type { CurveValues } from './kit/curve';\nexport { along, AXIS_COLOR, declareFormulas, drawLabels, drawn, lerpInterval, loadFormulas, PLOT_COLOR, readInterval, withoutTips } from './kit/furniture';\nexport type { Label, LabelStyle } from './kit/furniture';\nexport {\n add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, grown, heading, outlineBounds, OWN_FRAME, resting,\n} from './kit/follow';\nexport type { FollowProps, FollowValues, Parted, Quad, Retarget, Target } from './kit/follow';\nexport {\n parseSpaceCurve, parseSurface, spaceCurveError, spaceCurveParams, surfaceError, surfaceParams, EQUATION_KINDS, EQUATION_VARIABLES_3D,\n} from './kit/equation3d';\nexport type { EquationLanguage, SpaceCurveEquation, SurfaceEquation } from './kit/equation3d';\nexport { aim, graphEntry, graphOf, graphSpace, spaceOf, GRAPH_3D } from './three/space';\nexport type { Graph3D, GraphSpace } from './three/space';\nexport { domainEntry, meshEntries } from './three/entries';\nexport { drawLabel3D } from './three/label3d';\nexport type { LabelStyle3D } from './three/label3d';\n// A traced path is a plot whose span follows a value, so a copied one builds on these rather than a copy of them.\nexport { FunctionPlot, PLOT_COMMANDS, PLOT_STATE, PLOT_STROKE, tracePlot } from './plots/function-plot';\nexport type { FunctionPlotProps, PlotValues } from './plots/function-plot';\nexport { drawField, FIELD_COMMANDS, FIELD_STATE, traceField } from './kit/field-mark';\nexport type { FieldDrawing, FieldProps, FieldSampler, FieldStroke, FieldValues } from './kit/field-mark';\nexport { fieldError, fieldParams, parseField, FIELD_VARIABLES } from './kit/field';\nexport type { FieldEquation } from './kit/field';\nexport { traceContour } from './kit/contour';\nexport { colorAt, fillAt, lerpFillScale, lerpScale, readFillScale, readScale } from './kit/scale';\nexport {\n IDENTITY_MATRIX, isIdentityMatrix, lerpMatrix, lineThrough, readMatrix, transformedMap, warpedMap,\n} from './kit/coords';\nexport type { Matrix2, Warp } from './kit/coords';\nexport { braceOutline } from './kit/brace';\nexport { GRAPH_LAYOUTS, layOut } from './structures/graph-layout';\nexport type { GraphEdge, GraphLayout } from './structures/graph-layout';\n"]}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC","sourcesContent":["export * from './tex/node';\r\nexport * from './tex/matrix';\r\nexport * from './systems/number-line';\r\nexport * from './systems/axes2d';\r\nexport * from './systems/number-plane';\r\nexport * from './plots/function-plot';\r\nexport * from './plots/points-plot';\r\nexport * from './marks/plot-point';\r\nexport * from './marks/vector-arrow';\r\nexport * from './marks/curve-area';\r\nexport * from './marks/riemann-sum';\r\nexport * from './marks/tangent-line';\r\nexport * from './marks/drop-lines';\r\nexport * from './annotate/curly-brace';\r\nexport * from './annotate/angle-mark';\r\nexport * from './annotate/emphasis-mark';\r\nexport * from './three/axes3d';\r\nexport * from './three/surface-plot3d';\r\nexport * from './three/curve-plot3d';\r\nexport * from './three/plot-point3d';\r\nexport * from './three/vector-arrow3d';\r\nexport * from './systems/polar-plane';\r\nexport * from './plots/vector-field';\r\nexport * from './plots/stream-lines';\r\nexport * from './plots/traced-path';\r\nexport * from './structures/network-graph';\r\nexport * from './structures/sample-space';\r\nexport * from './engine';\r\nexport { NODES } from \"./nodes\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC","sourcesContent":["export * from './tex/node';\nexport * from './tex/matrix';\nexport * from './systems/number-line';\nexport * from './systems/axes2d';\nexport * from './systems/number-plane';\nexport * from './plots/function-plot';\nexport * from './plots/points-plot';\nexport * from './marks/plot-point';\nexport * from './marks/vector-arrow';\nexport * from './marks/curve-area';\nexport * from './marks/riemann-sum';\nexport * from './marks/tangent-line';\nexport * from './marks/drop-lines';\nexport * from './annotate/curly-brace';\nexport * from './annotate/angle-mark';\nexport * from './annotate/emphasis-mark';\nexport * from './three/axes3d';\nexport * from './three/surface-plot3d';\nexport * from './three/curve-plot3d';\nexport * from './three/plot-point3d';\nexport * from './three/vector-arrow3d';\nexport * from './systems/polar-plane';\nexport * from './plots/vector-field';\nexport * from './plots/stream-lines';\nexport * from './plots/traced-path';\nexport * from './structures/network-graph';\nexport * from './structures/sample-space';\nexport * from './engine';\nexport { NODES } from \"./nodes\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"brace.js","sourceRoot":"","sources":["../../src/kit/brace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEjD,kGAAkG;AAClG,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAa,EAAE,EAAW,EAAE,GAAY,EAAE,KAAa;IAChF,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC3C,IAAI,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;IAC1C,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC9B,MAAM,IAAI,GAAG,CAAC,CAAU,EAAE,CAAS,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAG,CAAC,CAAU,EAAE,CAAS,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,MAAM,CAAC,GAAG,OAAO,CAAC;IAClB,MAAM,KAAK,GAAG,CAAC,EAAW,EAAE,EAAW,EAAE,GAAY,EAAe,EAAE,CAAC,CAAC;QACpE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,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IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACtD,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;QAC7B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;KACrD,CAAC;AACN,CAAC","sourcesContent":["import type { PathCommand, Vector2 } from \"@motionscript/sdk\";\r\nimport { add, between, heading } from \"./follow\";\r\n\r\n/** How far a quarter circle's control points sit along its tangents, as a share of its radius. */\r\nconst QUARTER = 0.5523;\r\n\r\n/**\r\n * A curly brace from `from` to `to`, bulging toward `out` (a unit vector) and\r\n * `reach` deep at its tip: what a brace node draws, and a sample space beside\r\n * its parts. Path commands, y-up.\r\n */\r\nexport function braceOutline(from: Vector2, to: Vector2, out: Vector2, reach: number): PathCommand[] {\r\n const { unit, length } = heading(from, to);\r\n if (length === 0) return [];\r\n const r = Math.min(reach / 2, length / 4);\r\n const mid = between(from, to);\r\n const lift = (p: Vector2, k: number) => add(p, out, k * r);\r\n const along = (p: Vector2, k: number) => add(p, unit, k * r);\r\n const h = QUARTER;\r\n const curve = (c1: Vector2, c2: Vector2, end: Vector2): PathCommand => ({\r\n type: \"C\", x1: c1.x, y1: c1.y, x2: c2.x, y2: c2.y, x: end.x, y: end.y,\r\n });\r\n const a = lift(along(from, 1), 1);\r\n const b = lift(along(mid, -1), 1);\r\n const tip = lift(mid, 2);\r\n const c = lift(along(mid, 1), 1);\r\n const d = lift(along(to, -1), 1);\r\n return [\r\n { type: \"M\", x: from.x, y: from.y },\r\n curve(lift(from, h), lift(along(from, 1 - h), 1), a),\r\n { type: \"L\", x: b.x, y: b.y },\r\n curve(lift(along(mid, -1 + h), 1), lift(mid, 2 - h), tip),\r\n curve(lift(mid, 2 - h), lift(along(mid, 1 - h), 1), c),\r\n { type: \"L\", x: d.x, y: d.y },\r\n curve(lift(along(to, -1 + h), 1), lift(to, h), to),\r\n ];\r\n}\r\n"]}
1
+ {"version":3,"file":"brace.js","sourceRoot":"","sources":["../../src/kit/brace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEjD,kGAAkG;AAClG,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAa,EAAE,EAAW,EAAE,GAAY,EAAE,KAAa;IAChF,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC3C,IAAI,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;IAC1C,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC9B,MAAM,IAAI,GAAG,CAAC,CAAU,EAAE,CAAS,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAG,CAAC,CAAU,EAAE,CAAS,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,MAAM,CAAC,GAAG,OAAO,CAAC;IAClB,MAAM,KAAK,GAAG,CAAC,EAAW,EAAE,EAAW,EAAE,GAAY,EAAe,EAAE,CAAC,CAAC;QACpE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EA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AC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACtD,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;QAC7B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;KACrD,CAAC;AACN,CAAC","sourcesContent":["import type { PathCommand, Vector2 } from \"@motionscript/sdk\";\nimport { add, between, heading } from \"./follow\";\n\n/** How far a quarter circle's control points sit along its tangents, as a share of its radius. */\nconst QUARTER = 0.5523;\n\n/**\n * A curly brace from `from` to `to`, bulging toward `out` (a unit vector) and\n * `reach` deep at its tip: what a brace node draws, and a sample space beside\n * its parts. Path commands, y-up.\n */\nexport function braceOutline(from: Vector2, to: Vector2, out: Vector2, reach: number): PathCommand[] {\n const { unit, length } = heading(from, to);\n if (length === 0) return [];\n const r = Math.min(reach / 2, length / 4);\n const mid = between(from, to);\n const lift = (p: Vector2, k: number) => add(p, out, k * r);\n const along = (p: Vector2, k: number) => add(p, unit, k * r);\n const h = QUARTER;\n const curve = (c1: Vector2, c2: Vector2, end: Vector2): PathCommand => ({\n type: \"C\", x1: c1.x, y1: c1.y, x2: c2.x, y2: c2.y, x: end.x, y: end.y,\n });\n const a = lift(along(from, 1), 1);\n const b = lift(along(mid, -1), 1);\n const tip = lift(mid, 2);\n const c = lift(along(mid, 1), 1);\n const d = lift(along(to, -1), 1);\n return [\n { type: \"M\", x: from.x, y: from.y },\n curve(lift(from, h), lift(along(from, 1 - h), 1), a),\n { type: \"L\", x: b.x, y: b.y },\n curve(lift(along(mid, -1 + h), 1), lift(mid, 2 - h), tip),\n curve(lift(mid, 2 - h), lift(along(mid, 1 - h), 1), c),\n { type: \"L\", x: d.x, y: d.y },\n curve(lift(along(to, -1 + h), 1), lift(to, h), to),\n ];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/kit/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AASH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAI,KAAa;IAC/C,2EAA2E;IAC3E,2CAA2C;IAC3C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAa,CAAC;IAErC,OAAO;QACH,GAAG,CAAC,GAAG;YACH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,OAAO,SAAS,CAAC;YACxC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAM,CAAC;YACpC,iEAAiE;YACjE,gEAAgE;YAChE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACxB,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,GAAG,CAAC,GAAG,EAAE,KAAK;YACV,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACxB,OAAO,OAAO,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;gBAC1B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;gBAC5C,IAAI,OAAO,KAAK,SAAS;oBAAE,MAAM;gBACjC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;QACL,CAAC;QAED,IAAI,IAAI;YACJ,OAAO,OAAO,CAAC,IAAI,CAAC;QACxB,CAAC;KACJ,CAAC;AACN,CAAC","sourcesContent":["/**\r\n * A bounded, least-recently-used memo.\r\n *\r\n * Sits under `geometry.ts`, and imports nothing, so it is testable in bare Node:\r\n * everything else in this package reaches MathJax's browser adaptor at module\r\n * scope, which means a test that touches it needs a DOM. The one piece of logic\r\n * here worth being sure about — what gets thrown away when the memo is full —\r\n * is exactly the piece that does not need one.\r\n *\r\n * Least-recently-used rather than oldest-first, and that matters for the shape\r\n * of work this sees. A `Latex` node re-resolves its formula whenever `fontSize`\r\n * changes, so animating the size of one formula inserts a fresh key every frame\r\n * and would, under a first-in-first-out rule, walk the whole memo out of it in a\r\n * couple of seconds — including the entries for every *other* formula in the\r\n * scene, none of which had done anything wrong. Touching an entry on read keeps\r\n * the formulas that are actually being asked for ahead of the ones streaming\r\n * past.\r\n */\r\n\r\nexport interface BoundedCache<T> {\r\n get(key: string): T | undefined;\r\n set(key: string, value: T): void;\r\n /** Entries held. For tests and for anyone measuring. */\r\n readonly size: number;\r\n}\r\n\r\n/**\r\n * @param limit Most entries to hold. One more arriving evicts the least\r\n * recently read or written.\r\n */\r\nexport function createBoundedCache<T>(limit: number): BoundedCache<T> {\r\n // Insertion order is the eviction order, which is what makes a plain `Map`\r\n // an LRU as long as every read re-inserts.\r\n const entries = new Map<string, T>();\r\n\r\n return {\r\n get(key) {\r\n if (!entries.has(key)) return undefined;\r\n const value = entries.get(key) as T;\r\n // Delete-then-set moves the key to the end, so the next eviction\r\n // takes the genuinely coldest entry rather than the oldest one.\r\n entries.delete(key);\r\n entries.set(key, value);\r\n return value;\r\n },\r\n\r\n set(key, value) {\r\n entries.delete(key);\r\n entries.set(key, value);\r\n while (entries.size > limit) {\r\n const coldest = entries.keys().next().value;\r\n if (coldest === undefined) break;\r\n entries.delete(coldest);\r\n }\r\n },\r\n\r\n get size() {\r\n return entries.size;\r\n },\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/kit/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AASH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAI,KAAa;IAC/C,2EAA2E;IAC3E,2CAA2C;IAC3C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAa,CAAC;IAErC,OAAO;QACH,GAAG,CAAC,GAAG;YACH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,OAAO,SAAS,CAAC;YACxC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAM,CAAC;YACpC,iEAAiE;YACjE,gEAAgE;YAChE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACxB,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,GAAG,CAAC,GAAG,EAAE,KAAK;YACV,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACxB,OAAO,OAAO,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;gBAC1B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;gBAC5C,IAAI,OAAO,KAAK,SAAS;oBAAE,MAAM;gBACjC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;QACL,CAAC;QAED,IAAI,IAAI;YACJ,OAAO,OAAO,CAAC,IAAI,CAAC;QACxB,CAAC;KACJ,CAAC;AACN,CAAC","sourcesContent":["/**\n * A bounded, least-recently-used memo.\n *\n * Sits under `geometry.ts`, and imports nothing, so it is testable in bare Node:\n * everything else in this package reaches MathJax's browser adaptor at module\n * scope, which means a test that touches it needs a DOM. The one piece of logic\n * here worth being sure about — what gets thrown away when the memo is full —\n * is exactly the piece that does not need one.\n *\n * Least-recently-used rather than oldest-first, and that matters for the shape\n * of work this sees. A `Latex` node re-resolves its formula whenever `fontSize`\n * changes, so animating the size of one formula inserts a fresh key every frame\n * and would, under a first-in-first-out rule, walk the whole memo out of it in a\n * couple of seconds — including the entries for every *other* formula in the\n * scene, none of which had done anything wrong. Touching an entry on read keeps\n * the formulas that are actually being asked for ahead of the ones streaming\n * past.\n */\n\nexport interface BoundedCache<T> {\n get(key: string): T | undefined;\n set(key: string, value: T): void;\n /** Entries held. For tests and for anyone measuring. */\n readonly size: number;\n}\n\n/**\n * @param limit Most entries to hold. One more arriving evicts the least\n * recently read or written.\n */\nexport function createBoundedCache<T>(limit: number): BoundedCache<T> {\n // Insertion order is the eviction order, which is what makes a plain `Map`\n // an LRU as long as every read re-inserts.\n const entries = new Map<string, T>();\n\n return {\n get(key) {\n if (!entries.has(key)) return undefined;\n const value = entries.get(key) as T;\n // Delete-then-set moves the key to the end, so the next eviction\n // takes the genuinely coldest entry rather than the oldest one.\n entries.delete(key);\n entries.set(key, value);\n return value;\n },\n\n set(key, value) {\n entries.delete(key);\n entries.set(key, value);\n while (entries.size > limit) {\n const coldest = entries.keys().next().value;\n if (coldest === undefined) break;\n entries.delete(coldest);\n }\n },\n\n get size() {\n return entries.size;\n },\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/kit/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,aAAa,EAClB,KAAK,IAAI,EAET,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAU3B,wFAAwF;AACxF,eAAO,MAAM,KAAK;;;;;;CAAQ,CAAC;AAC3B,eAAO,MAAM,cAAc;;;oBAQkC,CAAC;;;;oBAC5B,CAAC;;;;oBAA6G,CAAC;;;;oBAQ3E,CAAC;;;;;;;;CAjB5B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EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC;AACpD,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,aAAa,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC;AAEnE,wFAAwF;AACxF,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC;AAC3B,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAC;AAQ5C,MAAM,UAAU,MAAM,CAAC,MAAyB,EAAE,OAA2B,EAAE,UAAyB,EAAE;IACtG,OAAO,KAAK,CAAC,MAAM,CAAiG,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AAClK,CAAC;AAMD,iEAAiE;AACjE,MAAM,UAAU,IAAI,CAA4C,MAAS,EAAE,GAAG,IAAS;IACnF,MAAM,GAAG,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAC1B,KAAK,MAAM,GAAG,IAAI,IAAI;QAAE,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IACxC,OAAO,GAAG,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,GAAkB,EAAE,GAAe,EAAE,OAAmB,GAAG,EAAE,GAAG,CAAC;IACrF,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjB,GAAG,CAAC,QAAQ,EAAE,CAAC;IACf,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC","sourcesContent":["import {\r\n Paint,\r\n Types,\r\n type EntryOptions,\r\n type RenderContext,\r\n type Type,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Fill as _Fill,\r\n type FillResolved as _FillResolved,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\n\r\n/**\r\n * What a component in this kit shares beyond the factory: the paints a math\r\n * node draws with, listed choices, and the order a node paints in.\r\n */\r\n\r\nconst { overlay: _overlay, ...paint } = Paint.state;\r\nconst { overlayTo: _overlayTo, ...paintCommands } = Paint.commands;\r\n\r\n/** A math node's paints: fill, stroke, shadow and the outline trim, with no overlay. */\r\nexport const PAINT = paint;\r\nexport const PAINT_COMMANDS = paintCommands;\r\n\r\n/**\r\n * One of `values`, held as text with its choices listed (no `kind: \"enum\"`).\r\n */\r\nexport function listed<const V extends readonly string[]>(values: V, initial: V[number], options?: ListedOptions): Type<V[number]>;\r\n/** With no default: an arg left out is one the command was not given. */\r\nexport function listed<const V extends readonly string[]>(values: V, initial: undefined, options?: ListedOptions): Type<V[number] | undefined>;\r\nexport function listed(values: readonly string[], initial: string | undefined, options: ListedOptions = {}): Type<string | undefined> {\r\n return Types.custom<string | undefined, string | undefined, EntryOptions & { readonly options: readonly string[] }>(initial, { ...options, options: values });\r\n}\r\n\r\ninterface ListedOptions {\r\n readonly animatable?: boolean;\r\n}\r\n\r\n/** `record` without `keys`: the paints a node has no use for. */\r\nexport function omit<T extends object, const K extends keyof T>(record: T, ...keys: K[]): Omit<T, K> {\r\n const out = { ...record };\r\n for (const key of keys) delete out[key];\r\n return out;\r\n}\r\n\r\n/**\r\n * A node's paint order: its own paint under its children, then what it lays\r\n * over them, each cut at the near plane of a space it crosses.\r\n */\r\nexport function painted(ctx: RenderContext, own: () => void, over: () => void = () => { }): void {\r\n ctx.inFront(own);\r\n ctx.children();\r\n ctx.inFront(over);\r\n}\r\n"]}
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/kit/component.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EACL,KAAK,GAWR,MAAM,mBAAmB,CAAC;AAE3B;;;GAGG;AAEH,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC;AACpD,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,aAAa,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC;AAEnE,wFAAwF;AACxF,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC;AAC3B,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAC;AAQ5C,MAAM,UAAU,MAAM,CAAC,MAAyB,EAAE,OAA2B,EAAE,UAAyB,EAAE;IACtG,OAAO,KAAK,CAAC,MAAM,CAAiG,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AAClK,CAAC;AAMD,iEAAiE;AACjE,MAAM,UAAU,IAAI,CAA4C,MAAS,EAAE,GAAG,IAAS;IACnF,MAAM,GAAG,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAC1B,KAAK,MAAM,GAAG,IAAI,IAAI;QAAE,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IACxC,OAAO,GAAG,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,GAAkB,EAAE,GAAe,EAAE,OAAmB,GAAG,EAAE,GAAG,CAAC;IACrF,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjB,GAAG,CAAC,QAAQ,EAAE,CAAC;IACf,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC","sourcesContent":["import {\n Paint,\n Types,\n type EntryOptions,\n type RenderContext,\n type Type,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\n\n/**\n * What a component in this kit shares beyond the factory: the paints a math\n * node draws with, listed choices, and the order a node paints in.\n */\n\nconst { overlay: _overlay, ...paint } = Paint.state;\nconst { overlayTo: _overlayTo, ...paintCommands } = Paint.commands;\n\n/** A math node's paints: fill, stroke, shadow and the outline trim, with no overlay. */\nexport const PAINT = paint;\nexport const PAINT_COMMANDS = paintCommands;\n\n/**\n * One of `values`, held as text with its choices listed (no `kind: \"enum\"`).\n */\nexport function listed<const V extends readonly string[]>(values: V, initial: V[number], options?: ListedOptions): Type<V[number]>;\n/** With no default: an arg left out is one the command was not given. */\nexport function listed<const V extends readonly string[]>(values: V, initial: undefined, options?: ListedOptions): Type<V[number] | undefined>;\nexport function listed(values: readonly string[], initial: string | undefined, options: ListedOptions = {}): Type<string | undefined> {\n return Types.custom<string | undefined, string | undefined, EntryOptions & { readonly options: readonly string[] }>(initial, { ...options, options: values });\n}\n\ninterface ListedOptions {\n readonly animatable?: boolean;\n}\n\n/** `record` without `keys`: the paints a node has no use for. */\nexport function omit<T extends object, const K extends keyof T>(record: T, ...keys: K[]): Omit<T, K> {\n const out = { ...record };\n for (const key of keys) delete out[key];\n return out;\n}\n\n/**\n * A node's paint order: its own paint under its children, then what it lays\n * over them, each cut at the near plane of a space it crosses.\n */\nexport function painted(ctx: RenderContext, own: () => void, over: () => void = () => { }): void {\n ctx.inFront(own);\n ctx.children();\n ctx.inFront(over);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"contour.js","sourceRoot":"","sources":["../../src/kit/contour.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,YAAY,CACxB,CAAmC,EACnC,CAAC,EAAE,EAAE,EAAE,CAA4B,EACnC,CAAC,EAAE,EAAE,EAAE,CAA4B,EACnC,OAAe,EACf,IAAY;IAEZ,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC;IACnE,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC;IAC/B,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC;IA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CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACtB,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACjB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { Vector2 } from \"@motionscript/sdk\";\r\n\r\n/**\r\n * The lines along which a function of two variables is zero, over a box of\r\n * graph values: marching squares, its crossings placed by linear interpolation\r\n * and joined end to end into runs. Points are graph coordinates.\r\n */\r\nexport function traceContour(\r\n f: (x: number, y: number) => number,\r\n [x0, x1]: readonly [number, number],\r\n [y0, y1]: readonly [number, number],\r\n columns: number,\r\n rows: number,\r\n): Vector2[][] {\r\n if (!(x1 > x0) || !(y1 > y0) || columns < 1 || rows < 1) return [];\r\n const dx = (x1 - x0) / columns;\r\n const dy = (y1 - y0) / rows;\r\n const stride = columns + 1;\r\n const values = new Float64Array(stride * (rows + 1));\r\n for (let j = 0; j <= rows; j++) {\r\n for (let i = 0; i <= columns; i++) values[j * stride + i] = f(x0 + i * dx, y0 + j * dy);\r\n }\r\n\r\n // A crossing lives on a grid edge, which is its name: two cells sharing the edge share the point.\r\n const points = new Map<number, Vector2>();\r\n const edgeCount = stride * (rows + 1);\r\n const crossing = (i: number, j: number, vertical: boolean): number | null => {\r\n const a = values[j * stride + i];\r\n const b = vertical ? values[(j + 1) * stride + i] : values[j * stride + i + 1];\r\n if (!Number.isFinite(a) || !Number.isFinite(b) || a < 0 === b < 0) return null;\r\n const key = (vertical ? edgeCount : 0) + j * stride + i;\r\n if (!points.has(key)) {\r\n const t = a / (a - b);\r\n points.set(key, vertical ? { x: x0 + i * dx, y: y0 + (j + t) * dy } : { x: x0 + (i + t) * dx, y: y0 + j * dy });\r\n }\r\n return key;\r\n };\r\n\r\n const next = new Map<number, number[]>();\r\n const join = (a: number | null, b: number | null): void => {\r\n if (a === null || b === null) return;\r\n (next.get(a) ?? next.set(a, []).get(a)!).push(b);\r\n (next.get(b) ?? next.set(b, []).get(b)!).push(a);\r\n };\r\n for (let j = 0; j < rows; j++) {\r\n for (let i = 0; i < columns; i++) {\r\n const bottom = crossing(i, j, false);\r\n const top = crossing(i, j + 1, false);\r\n const left = crossing(i, j, true);\r\n const right = crossing(i + 1, j, true);\r\n const found = [bottom, right, top, left].filter((edge) => edge !== null);\r\n if (found.length === 2) join(found[0], found[1]);\r\n else if (found.length === 4) {\r\n // A saddle: the centre's sign says which pairs of edges the curve joins.\r\n const centre = f(x0 + (i + 0.5) * dx, y0 + (j + 0.5) * dy);\r\n const corner = values[j * stride + i];\r\n if (centre < 0 === corner < 0) {\r\n join(bottom, right);\r\n join(top, left);\r\n } else {\r\n join(bottom, left);\r\n join(top, right);\r\n }\r\n }\r\n }\r\n }\r\n\r\n const runs: Vector2[][] = [];\r\n const used = new Set<number>();\r\n const walk = (from: number): Vector2[] => {\r\n const run: Vector2[] = [points.get(from)!];\r\n used.add(from);\r\n let at = from;\r\n for (;;) {\r\n const onward = (next.get(at) ?? []).find((key) => !used.has(key));\r\n if (onward === undefined) break;\r\n used.add(onward);\r\n run.push(points.get(onward)!);\r\n at = onward;\r\n }\r\n return run;\r\n };\r\n // Open runs first, from their ends, so each is one run and not two halves.\r\n for (const [key, links] of next) {\r\n if (links.length === 1 && !used.has(key)) runs.push(walk(key));\r\n }\r\n for (const key of next.keys()) {\r\n if (used.has(key)) continue;\r\n const run = walk(key);\r\n run.push(run[0]);\r\n runs.push(run);\r\n }\r\n return runs.filter((run) => run.length > 1);\r\n}\r\n"]}
1
+ {"version":3,"file":"contour.js","sourceRoot":"","sources":["../../src/kit/contour.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC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9B,EAAE,GAAG,MAAM,CAAC;QAChB,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC,CAAC;IACF,2EAA2E;IAC3E,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACnE,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QAC5B,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACtB,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACjB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { Vector2 } from \"@motionscript/sdk\";\n\n/**\n * The lines along which a function of two variables is zero, over a box of\n * graph values: marching squares, its crossings placed by linear interpolation\n * and joined end to end into runs. Points are graph coordinates.\n */\nexport function traceContour(\n f: (x: number, y: number) => number,\n [x0, x1]: readonly [number, number],\n [y0, y1]: readonly [number, number],\n columns: number,\n rows: number,\n): Vector2[][] {\n if (!(x1 > x0) || !(y1 > y0) || columns < 1 || rows < 1) return [];\n const dx = (x1 - x0) / columns;\n const dy = (y1 - y0) / rows;\n const stride = columns + 1;\n const values = new Float64Array(stride * (rows + 1));\n for (let j = 0; j <= rows; j++) {\n for (let i = 0; i <= columns; i++) values[j * stride + i] = f(x0 + i * dx, y0 + j * dy);\n }\n\n // A crossing lives on a grid edge, which is its name: two cells sharing the edge share the point.\n const points = new Map<number, Vector2>();\n const edgeCount = stride * (rows + 1);\n const crossing = (i: number, j: number, vertical: boolean): number | null => {\n const a = values[j * stride + i];\n const b = vertical ? values[(j + 1) * stride + i] : values[j * stride + i + 1];\n if (!Number.isFinite(a) || !Number.isFinite(b) || a < 0 === b < 0) return null;\n const key = (vertical ? edgeCount : 0) + j * stride + i;\n if (!points.has(key)) {\n const t = a / (a - b);\n points.set(key, vertical ? { x: x0 + i * dx, y: y0 + (j + t) * dy } : { x: x0 + (i + t) * dx, y: y0 + j * dy });\n }\n return key;\n };\n\n const next = new Map<number, number[]>();\n const join = (a: number | null, b: number | null): void => {\n if (a === null || b === null) return;\n (next.get(a) ?? next.set(a, []).get(a)!).push(b);\n (next.get(b) ?? next.set(b, []).get(b)!).push(a);\n };\n for (let j = 0; j < rows; j++) {\n for (let i = 0; i < columns; i++) {\n const bottom = crossing(i, j, false);\n const top = crossing(i, j + 1, false);\n const left = crossing(i, j, true);\n const right = crossing(i + 1, j, true);\n const found = [bottom, right, top, left].filter((edge) => edge !== null);\n if (found.length === 2) join(found[0], found[1]);\n else if (found.length === 4) {\n // A saddle: the centre's sign says which pairs of edges the curve joins.\n const centre = f(x0 + (i + 0.5) * dx, y0 + (j + 0.5) * dy);\n const corner = values[j * stride + i];\n if (centre < 0 === corner < 0) {\n join(bottom, right);\n join(top, left);\n } else {\n join(bottom, left);\n join(top, right);\n }\n }\n }\n }\n\n const runs: Vector2[][] = [];\n const used = new Set<number>();\n const walk = (from: number): Vector2[] => {\n const run: Vector2[] = [points.get(from)!];\n used.add(from);\n let at = from;\n for (;;) {\n const onward = (next.get(at) ?? []).find((key) => !used.has(key));\n if (onward === undefined) break;\n used.add(onward);\n run.push(points.get(onward)!);\n at = onward;\n }\n return run;\n };\n // Open runs first, from their ends, so each is one run and not two halves.\n for (const [key, links] of next) {\n if (links.length === 1 && !used.has(key)) runs.push(walk(key));\n }\n for (const key of next.keys()) {\n if (used.has(key)) continue;\n const run = walk(key);\n run.push(run[0]);\n runs.push(run);\n }\n return runs.filter((run) => run.length > 1);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"coords.js","sourceRoot":"","sources":["../../src/kit/coords.ts"],"names":[],"mappings":"AAkCA,oFAAoF;AACpF,MAAM,UAAU,eAAe,CAAC,KAA2B,EAAE,UAAuB,QAAQ;IACxF,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACjC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE,IAAI,GAAG,GAAG,GAAG;QAAE,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACvC,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;YAAE,GAAG,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;YAAE,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,SAAS,CAAC,KAAe,EAAE,EAAU,EAAE,EAAU,EAAE,UAAuB,QAAQ;IAC9F,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC;IACzB,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;QACpB,MAAM,IAAI,GAAG,IAAI,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IAC1F,IAAI,CAAC,GAAG,CAAC,MAAM;QAAE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACnE,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,YAAY,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;QAC3B,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import type { Extents, Vector2 } from \"@motionscript/sdk\";\r\n\r\n/** A closed span of graph values, low to high. */\r\nexport type Interval = readonly [number, number];\r\n\r\nexport type AxisScaling = \"linear\" | \"log\";\r\n\r\n/**\r\n * How a coordinate system's graph values land on its pixels. Pixels are y-up\r\n * from the centre of the system's own box, which is the frame a `Graphics2D` op\r\n * is written in.\r\n */\r\nexport interface CoordinateMap {\r\n /** Graph to pixels. Writes into `out` when given, so a sampler allocates nothing. */\r\n toPoint(x: number, y: number, out?: Vector2): Vector2;\r\n toCoords(x: number, y: number, out?: Vector2): Vector2;\r\n /** The plot area. */\r\n readonly area: Extents;\r\n readonly xRange: Interval;\r\n readonly yRange: Interval;\r\n /** Equal for two maps that place every point alike: what a geometry cache keys on. */\r\n readonly revision: string;\r\n /** Set where a straight run of graph values is not a straight run of pixels, so a line through the map is sampled. */\r\n readonly curved?: boolean;\r\n /** Set where what is ruled over the ranges can leave the plot area, so the system keeps it in. */\r\n readonly spills?: boolean;\r\n}\r\n\r\n/** One axis: a graph value to a pixel and back. */\r\nexport interface AxisScale {\r\n to(value: number): number;\r\n from(pixel: number): number;\r\n}\r\n\r\n/** `range`, made usable: finite, ordered, non-empty, and positive on a log axis. */\r\nexport function resolveInterval(range: Interval | undefined, scaling: AxisScaling = \"linear\"): Interval {\r\n let [min, max] = range ?? [0, 1];\r\n if (!Number.isFinite(min) || !Number.isFinite(max)) [min, max] = [0, 1];\r\n if (min > max) [min, max] = [max, min];\r\n if (scaling === \"log\") {\r\n if (!(max > 0)) max = 10;\r\n if (!(min > 0)) min = max / 1000;\r\n }\r\n return max > min ? [min, max] : [min, min + 1];\r\n}\r\n\r\n/** `range` spread over the pixels from `lo` to `hi`. */\r\nexport function axisScale(range: Interval, lo: number, hi: number, scaling: AxisScaling = \"linear\"): AxisScale {\r\n const [min, max] = range;\r\n if (scaling === \"log\") {\r\n const from = Math.log10(min);\r\n const k = (hi - lo) / (Math.log10(max) - from);\r\n return { to: (v) => lo + (Math.log10(v) - from) * k, from: (p) => 10 ** (from + (p - lo) / k) };\r\n }\r\n const k = (hi - lo) / (max - min);\r\n return { to: (v) => lo + (v - min) * k, from: (p) => min + (p - lo) / k };\r\n}\r\n\r\nexport interface CartesianOptions {\r\n xRange: Interval;\r\n yRange: Interval;\r\n area: Extents;\r\n xScaling?: AxisScaling;\r\n yScaling?: AxisScaling;\r\n}\r\n\r\n/** Two independent axes at right angles: what a number line, axes and a number plane share. */\r\nexport function cartesianMap({ xRange, yRange, area, xScaling = \"linear\", yScaling = \"linear\" }: CartesianOptions): CoordinateMap {\r\n const x = axisScale(xRange, area.minX, area.maxX, xScaling);\r\n const y = axisScale(yRange, area.minY, area.maxY, yScaling);\r\n return {\r\n toPoint: (gx, gy, out = { x: 0, y: 0 }) => {\r\n out.x = x.to(gx);\r\n out.y = y.to(gy);\r\n return out;\r\n },\r\n toCoords: (px, py, out = { x: 0, y: 0 }) => {\r\n out.x = x.from(px);\r\n out.y = y.from(py);\r\n return out;\r\n },\r\n area,\r\n xRange,\r\n yRange,\r\n revision: [xRange, yRange, area.minX, area.minY, area.maxX, area.maxY, xScaling, yScaling].join(\"|\"),\r\n };\r\n}\r\n\r\nconst UNBOUNDED: Extents = { minX: -Infinity, minY: -Infinity, maxX: Infinity, maxY: Infinity };\r\n\r\n/** One graph unit is one pixel: what a mark outside any system is drawn through. */\r\nexport const PIXEL_MAP: CoordinateMap = {\r\n toPoint: (x, y, out = { x: 0, y: 0 }) => {\r\n out.x = x;\r\n out.y = y;\r\n return out;\r\n },\r\n toCoords: (x, y, out = { x: 0, y: 0 }) => {\r\n out.x = x;\r\n out.y = y;\r\n return out;\r\n },\r\n area: UNBOUNDED,\r\n xRange: [-Infinity, Infinity],\r\n yRange: [-Infinity, Infinity],\r\n revision: \"pixels\",\r\n};\r\n\r\n/** A 2 × 2 matrix, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */\r\nexport type Matrix2 = readonly [number, number, number, number];\r\n\r\nexport const IDENTITY_MATRIX: Matrix2 = [1, 0, 0, 1];\r\n\r\n/** A matrix from its rows, or flat; anything else is the identity. */\r\nexport function readMatrix(value: unknown, previous: Matrix2 = IDENTITY_MATRIX): Matrix2 {\r\n const flat = Array.isArray(value) ? value.flat() : [];\r\n if (flat.length !== 4 || flat.some((entry) => typeof entry !== \"number\" || !Number.isFinite(entry))) return previous;\r\n return [flat[0], flat[1], flat[2], flat[3]];\r\n}\r\n\r\nexport function lerpMatrix(from: Matrix2, to: Matrix2, t: number): Matrix2 {\r\n return [0, 1, 2, 3].map((i) => from[i] + (to[i] - from[i]) * t) as unknown as Matrix2;\r\n}\r\n\r\nexport function isIdentityMatrix([a, b, c, d]: Matrix2): boolean {\r\n return a === 1 && b === 0 && c === 0 && d === 1;\r\n}\r\n\r\n/**\r\n * How far a transformed plane reaches, in half-widths of its own ranges about\r\n * their middle. Finite on purpose: a plane squeezed towards a line shows the\r\n * pre-image of its box growing as 1/det, and ruling all of it packs the box\r\n * with lines, a solid wash just before the plane goes flat.\r\n */\r\nconst REACH = 4;\r\n\r\nfunction reach([min, max]: Interval): Interval {\r\n const middle = (min + max) / 2;\r\n const half = ((max - min) / 2) * REACH;\r\n return [middle - half, middle + half];\r\n}\r\n\r\n/**\r\n * `base` with every graph point sent through `matrix` first: a plane sheared,\r\n * turned or squeezed about its origin. Its ranges are what the plot area then\r\n * shows, up to {@link REACH}, so a grid ruled over them fills the box under a\r\n * turn, a shear or a fourfold shrink, and folds into a band as it goes flat.\r\n */\r\nexport function transformedMap(base: CoordinateMap, matrix: Matrix2): CoordinateMap {\r\n const [a, b, c, d] = matrix;\r\n const det = a * d - b * c;\r\n // A plane squeezed onto a line has no way back: a point is read as the untransformed plane has it.\r\n const flat = Math.abs(det) < 1e-9;\r\n const back = (u: number, v: number, out: Vector2): Vector2 => {\r\n if (flat) {\r\n out.x = u;\r\n out.y = v;\r\n } else {\r\n out.x = (d * u - b * v) / det;\r\n out.y = (a * v - c * u) / det;\r\n }\r\n return out;\r\n };\r\n const xReach = reach(base.xRange);\r\n const yReach = reach(base.yRange);\r\n let xRange = xReach;\r\n let yRange = yReach;\r\n if (!flat) {\r\n const corner: Vector2 = { x: 0, y: 0 };\r\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\r\n for (const u of base.xRange) {\r\n for (const v of base.yRange) {\r\n back(u, v, corner);\r\n minX = Math.min(minX, corner.x);\r\n maxX = Math.max(maxX, corner.x);\r\n minY = Math.min(minY, corner.y);\r\n maxY = Math.max(maxY, corner.y);\r\n }\r\n }\r\n xRange = [Math.max(minX, xReach[0]), Math.min(maxX, xReach[1])];\r\n yRange = [Math.max(minY, yReach[0]), Math.min(maxY, yReach[1])];\r\n }\r\n return {\r\n toPoint: (x, y, out = { x: 0, y: 0 }) => base.toPoint(a * x + b * y, c * x + d * y, out),\r\n toCoords: (px, py, out = { x: 0, y: 0 }) => {\r\n base.toCoords(px, py, out);\r\n return back(out.x, out.y, out);\r\n },\r\n area: base.area,\r\n xRange,\r\n yRange,\r\n revision: `${base.revision}|m${matrix.join(\",\")}`,\r\n spills: true,\r\n };\r\n}\r\n\r\n/** Where a warp sends a graph point, written into `out`; `false` where it has no value. */\r\nexport type Warp = (x: number, y: number, out: Vector2) => boolean;\r\n\r\n/**\r\n * `base` with every graph point sent to where `warp` sends it: a plane bent by\r\n * a function of its own points. `key` names the warp for the revision, since a\r\n * function has no text of its own.\r\n */\r\nexport function warpedMap(base: CoordinateMap, warp: Warp, key: string): CoordinateMap {\r\n const bend = (x: number, y: number, out: Vector2): Vector2 => {\r\n // A point the warp has no value at stays where it is, so a pole does not tear the grid.\r\n if (!warp(x, y, out)) {\r\n out.x = x;\r\n out.y = y;\r\n }\r\n return out;\r\n };\r\n const at: Vector2 = { x: 0, y: 0 };\r\n const dx: Vector2 = { x: 0, y: 0 };\r\n const dy: Vector2 = { x: 0, y: 0 };\r\n const H = 1e-4;\r\n return {\r\n toPoint: (x, y, out = { x: 0, y: 0 }) => {\r\n bend(x, y, out);\r\n return base.toPoint(out.x, out.y, out);\r\n },\r\n // No closed form: a few Newton steps from where the unbent plane has the point.\r\n toCoords: (px, py, out = { x: 0, y: 0 }) => {\r\n const target = base.toCoords(px, py);\r\n let gx = target.x;\r\n let gy = target.y;\r\n for (let i = 0; i < 8; i++) {\r\n bend(gx, gy, at);\r\n const ex = at.x - target.x;\r\n const ey = at.y - target.y;\r\n if (Math.abs(ex) + Math.abs(ey) < 1e-9) break;\r\n bend(gx + H, gy, dx);\r\n bend(gx, gy + H, dy);\r\n const j00 = (dx.x - at.x) / H;\r\n const j10 = (dx.y - at.y) / H;\r\n const j01 = (dy.x - at.x) / H;\r\n const j11 = (dy.y - at.y) / H;\r\n const det = j00 * j11 - j01 * j10;\r\n if (!(Math.abs(det) > 1e-12)) break;\r\n gx -= (j11 * ex - j01 * ey) / det;\r\n gy -= (j00 * ey - j10 * ex) / det;\r\n }\r\n out.x = Number.isFinite(gx) ? gx : target.x;\r\n out.y = Number.isFinite(gy) ? gy : target.y;\r\n return out;\r\n },\r\n area: base.area,\r\n // A bent plane pulls its edges in somewhere: it is ruled a little past them so the box stays full.\r\n xRange: widened(base.xRange),\r\n yRange: widened(base.yRange),\r\n revision: `${base.revision}|w${key}`,\r\n curved: true,\r\n spills: true,\r\n };\r\n}\r\n\r\n/** How much further than its range, as a share of it, a warped plane is ruled each way. */\r\nconst WARP_MARGIN = 0.3;\r\n\r\nfunction widened([min, max]: Interval): Interval {\r\n const margin = (max - min) * WARP_MARGIN;\r\n return Number.isFinite(margin) ? [min - margin, max + margin] : [min, max];\r\n}\r\n\r\n/** How many pieces a line through a curved map is drawn in. */\r\nconst CURVED_STEPS = 48;\r\n\r\n/** The pixel points that draw the straight run of graph values from one point to another. */\r\nexport function lineThrough(map: CoordinateMap, x0: number, y0: number, x1: number, y1: number): Vector2[] {\r\n if (!map.curved) return [map.toPoint(x0, y0), map.toPoint(x1, y1)];\r\n const run: Vector2[] = [];\r\n for (let i = 0; i <= CURVED_STEPS; i++) {\r\n const t = i / CURVED_STEPS;\r\n run.push(map.toPoint(x0 + (x1 - x0) * t, y0 + (y1 - y0) * t));\r\n }\r\n return run;\r\n}\r\n"]}
1
+ {"version":3,"file":"coords.js","sourceRoot":"","sources":["../../src/kit/coords.ts"],"names":[],"mappings":"AAkCA,oFAAoF;AACpF,MAAM,UAAU,eAAe,CAAC,KAA2B,EAAE,UAAuB,QAAQ;IACxF,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACjC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE,IAAI,GAAG,GAAG,GAAG;QAAE,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACv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ed span of graph values, low to high. */\nexport type Interval = readonly [number, number];\n\nexport type AxisScaling = \"linear\" | \"log\";\n\n/**\n * How a coordinate system's graph values land on its pixels. Pixels are y-up\n * from the centre of the system's own box, which is the frame a `Graphics2D` op\n * is written in.\n */\nexport interface CoordinateMap {\n /** Graph to pixels. Writes into `out` when given, so a sampler allocates nothing. */\n toPoint(x: number, y: number, out?: Vector2): Vector2;\n toCoords(x: number, y: number, out?: Vector2): Vector2;\n /** The plot area. */\n readonly area: Extents;\n readonly xRange: Interval;\n readonly yRange: Interval;\n /** Equal for two maps that place every point alike: what a geometry cache keys on. */\n readonly revision: string;\n /** Set where a straight run of graph values is not a straight run of pixels, so a line through the map is sampled. */\n readonly curved?: boolean;\n /** Set where what is ruled over the ranges can leave the plot area, so the system keeps it in. */\n readonly spills?: boolean;\n}\n\n/** One axis: a graph value to a pixel and back. */\nexport interface AxisScale {\n to(value: number): number;\n from(pixel: number): number;\n}\n\n/** `range`, made usable: finite, ordered, non-empty, and positive on a log axis. */\nexport function resolveInterval(range: Interval | undefined, scaling: AxisScaling = \"linear\"): Interval {\n let [min, max] = range ?? [0, 1];\n if (!Number.isFinite(min) || !Number.isFinite(max)) [min, max] = [0, 1];\n if (min > max) [min, max] = [max, min];\n if (scaling === \"log\") {\n if (!(max > 0)) max = 10;\n if (!(min > 0)) min = max / 1000;\n }\n return max > min ? [min, max] : [min, min + 1];\n}\n\n/** `range` spread over the pixels from `lo` to `hi`. */\nexport function axisScale(range: Interval, lo: number, hi: number, scaling: AxisScaling = \"linear\"): AxisScale {\n const [min, max] = range;\n if (scaling === \"log\") {\n const from = Math.log10(min);\n const k = (hi - lo) / (Math.log10(max) - from);\n return { to: (v) => lo + (Math.log10(v) - from) * k, from: (p) => 10 ** (from + (p - lo) / k) };\n }\n const k = (hi - lo) / (max - min);\n return { to: (v) => lo + (v - min) * k, from: (p) => min + (p - lo) / k };\n}\n\nexport interface CartesianOptions {\n xRange: Interval;\n yRange: Interval;\n area: Extents;\n xScaling?: AxisScaling;\n yScaling?: AxisScaling;\n}\n\n/** Two independent axes at right angles: what a number line, axes and a number plane share. */\nexport function cartesianMap({ xRange, yRange, area, xScaling = \"linear\", yScaling = \"linear\" }: CartesianOptions): CoordinateMap {\n const x = axisScale(xRange, area.minX, area.maxX, xScaling);\n const y = axisScale(yRange, area.minY, area.maxY, yScaling);\n return {\n toPoint: (gx, gy, out = { x: 0, y: 0 }) => {\n out.x = x.to(gx);\n out.y = y.to(gy);\n return out;\n },\n toCoords: (px, py, out = { x: 0, y: 0 }) => {\n out.x = x.from(px);\n out.y = y.from(py);\n return out;\n },\n area,\n xRange,\n yRange,\n revision: [xRange, yRange, area.minX, area.minY, area.maxX, area.maxY, xScaling, yScaling].join(\"|\"),\n };\n}\n\nconst UNBOUNDED: Extents = { minX: -Infinity, minY: -Infinity, maxX: Infinity, maxY: Infinity };\n\n/** One graph unit is one pixel: what a mark outside any system is drawn through. */\nexport const PIXEL_MAP: CoordinateMap = {\n toPoint: (x, y, out = { x: 0, y: 0 }) => {\n out.x = x;\n out.y = y;\n return out;\n },\n toCoords: (x, y, out = { x: 0, y: 0 }) => {\n out.x = x;\n out.y = y;\n return out;\n },\n area: UNBOUNDED,\n xRange: [-Infinity, Infinity],\n yRange: [-Infinity, Infinity],\n revision: \"pixels\",\n};\n\n/** A 2 × 2 matrix, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */\nexport type Matrix2 = readonly [number, number, number, number];\n\nexport const IDENTITY_MATRIX: Matrix2 = [1, 0, 0, 1];\n\n/** A matrix from its rows, or flat; anything else is the identity. */\nexport function readMatrix(value: unknown, previous: Matrix2 = IDENTITY_MATRIX): Matrix2 {\n const flat = Array.isArray(value) ? value.flat() : [];\n if (flat.length !== 4 || flat.some((entry) => typeof entry !== \"number\" || !Number.isFinite(entry))) return previous;\n return [flat[0], flat[1], flat[2], flat[3]];\n}\n\nexport function lerpMatrix(from: Matrix2, to: Matrix2, t: number): Matrix2 {\n return [0, 1, 2, 3].map((i) => from[i] + (to[i] - from[i]) * t) as unknown as Matrix2;\n}\n\nexport function isIdentityMatrix([a, b, c, d]: Matrix2): boolean {\n return a === 1 && b === 0 && c === 0 && d === 1;\n}\n\n/**\n * How far a transformed plane reaches, in half-widths of its own ranges about\n * their middle. Finite on purpose: a plane squeezed towards a line shows the\n * pre-image of its box growing as 1/det, and ruling all of it packs the box\n * with lines, a solid wash just before the plane goes flat.\n */\nconst REACH = 4;\n\nfunction reach([min, max]: Interval): Interval {\n const middle = (min + max) / 2;\n const half = ((max - min) / 2) * REACH;\n return [middle - half, middle + half];\n}\n\n/**\n * `base` with every graph point sent through `matrix` first: a plane sheared,\n * turned or squeezed about its origin. Its ranges are what the plot area then\n * shows, up to {@link REACH}, so a grid ruled over them fills the box under a\n * turn, a shear or a fourfold shrink, and folds into a band as it goes flat.\n */\nexport function transformedMap(base: CoordinateMap, matrix: Matrix2): CoordinateMap {\n const [a, b, c, d] = matrix;\n const det = a * d - b * c;\n // A plane squeezed onto a line has no way back: a point is read as the untransformed plane has it.\n const flat = Math.abs(det) < 1e-9;\n const back = (u: number, v: number, out: Vector2): Vector2 => {\n if (flat) {\n out.x = u;\n out.y = v;\n } else {\n out.x = (d * u - b * v) / det;\n out.y = (a * v - c * u) / det;\n }\n return out;\n };\n const xReach = reach(base.xRange);\n const yReach = reach(base.yRange);\n let xRange = xReach;\n let yRange = yReach;\n if (!flat) {\n const corner: Vector2 = { x: 0, y: 0 };\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const u of base.xRange) {\n for (const v of base.yRange) {\n back(u, v, corner);\n minX = Math.min(minX, corner.x);\n maxX = Math.max(maxX, corner.x);\n minY = Math.min(minY, corner.y);\n maxY = Math.max(maxY, corner.y);\n }\n }\n xRange = [Math.max(minX, xReach[0]), Math.min(maxX, xReach[1])];\n yRange = [Math.max(minY, yReach[0]), Math.min(maxY, yReach[1])];\n }\n return {\n toPoint: (x, y, out = { x: 0, y: 0 }) => base.toPoint(a * x + b * y, c * x + d * y, out),\n toCoords: (px, py, out = { x: 0, y: 0 }) => {\n base.toCoords(px, py, out);\n return back(out.x, out.y, out);\n },\n area: base.area,\n xRange,\n yRange,\n revision: `${base.revision}|m${matrix.join(\",\")}`,\n spills: true,\n };\n}\n\n/** Where a warp sends a graph point, written into `out`; `false` where it has no value. */\nexport type Warp = (x: number, y: number, out: Vector2) => boolean;\n\n/**\n * `base` with every graph point sent to where `warp` sends it: a plane bent by\n * a function of its own points. `key` names the warp for the revision, since a\n * function has no text of its own.\n */\nexport function warpedMap(base: CoordinateMap, warp: Warp, key: string): CoordinateMap {\n const bend = (x: number, y: number, out: Vector2): Vector2 => {\n // A point the warp has no value at stays where it is, so a pole does not tear the grid.\n if (!warp(x, y, out)) {\n out.x = x;\n out.y = y;\n }\n return out;\n };\n const at: Vector2 = { x: 0, y: 0 };\n const dx: Vector2 = { x: 0, y: 0 };\n const dy: Vector2 = { x: 0, y: 0 };\n const H = 1e-4;\n return {\n toPoint: (x, y, out = { x: 0, y: 0 }) => {\n bend(x, y, out);\n return base.toPoint(out.x, out.y, out);\n },\n // No closed form: a few Newton steps from where the unbent plane has the point.\n toCoords: (px, py, out = { x: 0, y: 0 }) => {\n const target = base.toCoords(px, py);\n let gx = target.x;\n let gy = target.y;\n for (let i = 0; i < 8; i++) {\n bend(gx, gy, at);\n const ex = at.x - target.x;\n const ey = at.y - target.y;\n if (Math.abs(ex) + Math.abs(ey) < 1e-9) break;\n bend(gx + H, gy, dx);\n bend(gx, gy + H, dy);\n const j00 = (dx.x - at.x) / H;\n const j10 = (dx.y - at.y) / H;\n const j01 = (dy.x - at.x) / H;\n const j11 = (dy.y - at.y) / H;\n const det = j00 * j11 - j01 * j10;\n if (!(Math.abs(det) > 1e-12)) break;\n gx -= (j11 * ex - j01 * ey) / det;\n gy -= (j00 * ey - j10 * ex) / det;\n }\n out.x = Number.isFinite(gx) ? gx : target.x;\n out.y = Number.isFinite(gy) ? gy : target.y;\n return out;\n },\n area: base.area,\n // A bent plane pulls its edges in somewhere: it is ruled a little past them so the box stays full.\n xRange: widened(base.xRange),\n yRange: widened(base.yRange),\n revision: `${base.revision}|w${key}`,\n curved: true,\n spills: true,\n };\n}\n\n/** How much further than its range, as a share of it, a warped plane is ruled each way. */\nconst WARP_MARGIN = 0.3;\n\nfunction widened([min, max]: Interval): Interval {\n const margin = (max - min) * WARP_MARGIN;\n return Number.isFinite(margin) ? [min - margin, max + margin] : [min, max];\n}\n\n/** How many pieces a line through a curved map is drawn in. */\nconst CURVED_STEPS = 48;\n\n/** The pixel points that draw the straight run of graph values from one point to another. */\nexport function lineThrough(map: CoordinateMap, x0: number, y0: number, x1: number, y1: number): Vector2[] {\n if (!map.curved) return [map.toPoint(x0, y0), map.toPoint(x1, y1)];\n const run: Vector2[] = [];\n for (let i = 0; i <= CURVED_STEPS; i++) {\n const t = i / CURVED_STEPS;\n run.push(map.toPoint(x0 + (x1 - x0) * t, y0 + (y1 - y0) * t));\n }\n return run;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"curve.js","sourceRoot":"","sources":["../../src/kit/curve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAmB,MAAM,UAAU,CAAC;AAgBrD,6FAA6F;AAC7F,MAAM,CAAC,MAAM,UAAU,GAAsB,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;AAE5E;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAkB,EAAE,CAAS;IACpD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC;IAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC7C,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IACpE,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IACvE,OAAO,IAAI,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,OAAO,CAAC,IAAa;IACjC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,UAAU,CAAC,QAAQ,CAAE,IAAyB,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;AAClH,CAAC;AAED,MAAM,QAAQ,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAEhC,SAAS,QAAQ,CAAC,MAAc,EAAE,MAAuB,EAAE,CAAS;IAChE,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/D,IAAI,QAAQ,YAAY,KAAK,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,IAAI,QAAQ,CAAC,EAAE,KAAK,GAAG;QAAE,OAAO,GAAG,CAAC;IACjG,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import type { NodeView } from \"@motionscript/sdk\";\r\nimport { equationParams, parseEquation } from \"./equation\";\r\nimport type { ExpressionScope } from \"./expression\";\r\nimport { scopeFor, type PlotSource } from \"./source\";\r\n\r\n/**\r\n * A curve as a mark reads it: what a plot is drawn from, its own `x`/`y`, and\r\n * whether a system laid it out, which is when those are a shift in graph units.\r\n * Data rather than a class, so a copied plot is ridden like the kit's own.\r\n */\r\nexport interface CurveValues {\r\n readonly expression: PlotSource;\r\n readonly params: ExpressionScope;\r\n readonly x: number;\r\n readonly y: number;\r\n /** The plane the plot was laid out on; `null` outside any system. */\r\n readonly graph?: object | null;\r\n}\r\n\r\n/** The node types a point, a tangent or an area can ride: they have a height at each `x`. */\r\nexport const CURVE_KEYS: readonly string[] = [\"functionPlot\", \"tracedPath\"];\r\n\r\n/**\r\n * The curve's height at graph `x`, or `NaN` where it has none or is not a\r\n * function of `x`. What a point, a tangent or an area riding a plot reads.\r\n */\r\nexport function curveValue(curve: CurveValues, x: number): number {\r\n const { source, blend } = curve.expression;\r\n const shift = curve.graph ? curve : NO_SHIFT;\r\n const value = heightOf(source, curve.params, x - shift.x) + shift.y;\r\n if (!blend) return value;\r\n const from = heightOf(blend.from, curve.params, x - shift.x) + shift.y;\r\n return from + (value - from) * blend.t;\r\n}\r\n\r\n/** Whether `view` is a node a mark can ride. */\r\nexport function isCurve(view: unknown): view is NodeView & { readonly state: CurveValues } {\r\n return typeof view === \"object\" && view !== null && CURVE_KEYS.includes((view as { key?: string }).key ?? \"\");\r\n}\r\n\r\nconst NO_SHIFT = { x: 0, y: 0 };\r\n\r\nfunction heightOf(source: string, params: ExpressionScope, x: number): number {\r\n const equation = parseEquation(source, equationParams(source));\r\n if (equation instanceof Error || equation.kind !== \"function\" || equation.of !== \"x\") return NaN;\r\n return equation.f(x, 0, scopeFor(equationParams(source), params));\r\n}\r\n"]}
1
+ {"version":3,"file":"curve.js","sourceRoot":"","sources":["../../src/kit/curve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAmB,MAAM,UAAU,CAAC;AAgBrD,6FAA6F;AAC7F,MAAM,CAAC,MAAM,UAAU,GAAsB,CAAC,cAAc,EAAE,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O,GAAG,CAAC;IACjG,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import type { NodeView } from \"@motionscript/sdk\";\nimport { equationParams, parseEquation } from \"./equation\";\nimport type { ExpressionScope } from \"./expression\";\nimport { scopeFor, type PlotSource } from \"./source\";\n\n/**\n * A curve as a mark reads it: what a plot is drawn from, its own `x`/`y`, and\n * whether a system laid it out, which is when those are a shift in graph units.\n * Data rather than a class, so a copied plot is ridden like the kit's own.\n */\nexport interface CurveValues {\n readonly expression: PlotSource;\n readonly params: ExpressionScope;\n readonly x: number;\n readonly y: number;\n /** The plane the plot was laid out on; `null` outside any system. */\n readonly graph?: object | null;\n}\n\n/** The node types a point, a tangent or an area can ride: they have a height at each `x`. */\nexport const CURVE_KEYS: readonly string[] = [\"functionPlot\", \"tracedPath\"];\n\n/**\n * The curve's height at graph `x`, or `NaN` where it has none or is not a\n * function of `x`. What a point, a tangent or an area riding a plot reads.\n */\nexport function curveValue(curve: CurveValues, x: number): number {\n const { source, blend } = curve.expression;\n const shift = curve.graph ? curve : NO_SHIFT;\n const value = heightOf(source, curve.params, x - shift.x) + shift.y;\n if (!blend) return value;\n const from = heightOf(blend.from, curve.params, x - shift.x) + shift.y;\n return from + (value - from) * blend.t;\n}\n\n/** Whether `view` is a node a mark can ride. */\nexport function isCurve(view: unknown): view is NodeView & { readonly state: CurveValues } {\n return typeof view === \"object\" && view !== null && CURVE_KEYS.includes((view as { key?: string }).key ?? \"\");\n}\n\nconst NO_SHIFT = { x: 0, y: 0 };\n\nfunction heightOf(source: string, params: ExpressionScope, x: number): number {\n const equation = parseEquation(source, equationParams(source));\n if (equation instanceof Error || equation.kind !== \"function\" || equation.of !== \"x\") return NaN;\n return equation.f(x, 0, scopeFor(equationParams(source), params));\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"equ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C,EAAE,GAAG,CAAC,CAAC;IACtD,OAAO,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,SAAiB;IAC3D,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG;YAAE,KAAK,EAAE,CAAC;aAClB,IAAI,CAAC,KAAK,GAAG;YAAE,KAAK,EAAE,CAAC;aACvB,IAAI,CAAC,KAAK,SAAS,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YACtC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAClC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACL,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { expressionOps, type ExpressionNode } from \"@motionscript/sdk\";\r\nimport { createBoundedCache } from \"./cache\";\r\nimport { compileExpressionCached, MATH_DIALECT, type CompiledExpression } from \"./expression\";\r\n\r\n/**\r\n * A plotted equation, read the way it is written rather than by a `kind` prop:\r\n *\r\n * | Written as | Is |\r\n * |---|---|\r\n * | `sin(x)`, `y = sin(x)` | a function of `x` |\r\n * | `x = y^2` | a function of `y` |\r\n * | `r = 1 + cos(theta)` | polar, in `theta` |\r\n * | `(cos(t), sin(t))` | parametric, in `t` |\r\n * | `x^2 + y^2 = 4` | implicit, in `x` and `y` |\r\n */\r\nexport type Equation =\r\n | { kind: \"function\"; of: \"x\" | \"y\"; f: CompiledExpression }\r\n | { kind: \"polar\"; f: CompiledExpression }\r\n | { kind: \"parametric\"; x: CompiledExpression; y: CompiledExpression }\r\n /** Drawn where `f(x, y)` is zero. */\r\n | { kind: \"implicit\"; f: CompiledExpression };\r\n\r\n/** The free variable each kind is sampled over, for a host's help text. */\r\nexport const EQUATION_VARIABLES = {\r\n function: [\"x\"],\r\n polar: [\"theta\"],\r\n parametric: [\"t\"],\r\n implicit: [\"x\", \"y\"],\r\n} as const satisfies Record<Equation[\"kind\"], readonly string[]>;\r\n\r\nconst parsed = createBoundedCache<Equation | Error>(256);\r\n\r\n/**\r\n * `source` as an {@link Equation}, or the reason it is not one. Memoised, so an\r\n * unchanged equation is the identical object and a geometry cache can key on it.\r\n */\r\nexport function parseEquation(source: string, params: readonly string[] = []): Equation | Error {\r\n const key = `${params.join(\",\")}|${source}`;\r\n const hit = parsed.get(key);\r\n if (hit !== undefined) return hit;\r\n let result: Equation | Error;\r\n try {\r\n result = read(source.trim(), params);\r\n } catch (error) {\r\n result = error instanceof Error ? error : new Error(String(error));\r\n }\r\n parsed.set(key, result);\r\n return result;\r\n}\r\n\r\n/**\r\n * Why `source` will not plot, or `null` when it will. An empty one is not an\r\n * error (nobody has written it yet), and neither is a name it does not know:\r\n * that is a named value, see {@link equationParams}.\r\n */\r\nexport function equationError(source: string): string | null {\r\n if (source.trim() === \"\") return null;\r\n const equation = parseEquation(source, equationParams(source));\r\n return equation instanceof Error ? equation.message : null;\r\n}\r\n\r\n/** A name that is always a variable of some kind of equation, so never a named value. */\r\nconst VARIABLE_NAMES: ReadonlySet<string> = new Set([\"r\", ...Object.values(EQUATION_VARIABLES).flat()]);\r\n\r\nconst named = createBoundedCache<readonly string[]>(256);\r\n\r\n/**\r\n * Every name `source` reads, in the order it first names them, variables\r\n * included. Empty for text that does not parse.\r\n */\r\nexport function equationNames(source: string): readonly string[] {\r\n const hit = named.get(source);\r\n if (hit !== undefined) return hit;\r\n const names = new Set<string>();\r\n const text = source.trim();\r\n try {\r\n for (const part of splitTuple(text) ?? splitTopLevel(text, \"=\")) {\r\n collectNames(expressionOps.parse(part.trim(), MATH_DIALECT).root, names);\r\n }\r\n } catch {\r\n names.clear();\r\n }\r\n const result = [...names];\r\n named.set(source, result);\r\n return result;\r\n}\r\n\r\n/**\r\n * The named values `source` reads: every name that is not a variable, a\r\n * function or a constant.\r\n */\r\nexport function equationParams(source: string): readonly string[] {\r\n return equationNames(source).filter((name) => !VARIABLE_NAMES.has(name));\r\n}\r\n\r\nfunction collectNames(node: ExpressionNode, into: Set<string>): void {\r\n switch (node.kind) {\r\n case \"ref\":\r\n into.add(node.name);\r\n return;\r\n case \"unary\":\r\n collectNames(node.operand, into);\r\n return;\r\n case \"binary\":\r\n collectNames(node.left, into);\r\n collectNames(node.right, into);\r\n return;\r\n case \"call\":\r\n for (const arg of node.args) collectNames(arg, into);\r\n return;\r\n default:\r\n }\r\n}\r\n\r\nfunction read(source: string, params: readonly string[]): Equation {\r\n if (source === \"\") throw new Error(\"Empty equation\");\r\n const compile = (text: string, variables: readonly string[]): CompiledExpression => {\r\n const result = compileExpressionCached(text.trim(), variables, params);\r\n if (result instanceof Error) throw result;\r\n return result;\r\n };\r\n\r\n const pair = splitTuple(source);\r\n if (pair?.length === 2) return { kind: \"parametric\", x: compile(pair[0], [\"t\"]), y: compile(pair[1], [\"t\"]) };\r\n\r\n const sides = splitTopLevel(source, \"=\");\r\n if (sides.length > 2) throw new Error(\"An equation has one '='\");\r\n if (sides.length === 1) return { kind: \"function\", of: \"x\", f: compile(source, [\"x\"]) };\r\n\r\n const [left, right] = sides;\r\n const subject = left.trim();\r\n const implicit = (): Equation => {\r\n const l = compile(left, [\"x\", \"y\"]);\r\n const r = compile(right, [\"x\", \"y\"]);\r\n return { kind: \"implicit\", f: (x, y, scope) => l(x, y, scope) - r(x, y, scope) };\r\n };\r\n if (subject === \"r\") return { kind: \"polar\", f: compile(right, [\"theta\"]) };\r\n if (subject === \"y\" || subject === \"x\") {\r\n const of = subject === \"y\" ? \"x\" : \"y\";\r\n // `y = x + y` names its own subject on the right, so it is not a function of one variable.\r\n try {\r\n return { kind: \"function\", of, f: compile(right, [of]) };\r\n } catch (error) {\r\n try {\r\n return implicit();\r\n } catch {\r\n throw error;\r\n }\r\n }\r\n }\r\n return implicit();\r\n}\r\n\r\n/** `(a, b, …)` as its parts, or `null` when `source` is not one parenthesised list of two or more. */\r\nexport function splitTuple(source: string): string[] | null {\r\n if (!source.startsWith(\"(\") || !source.endsWith(\")\")) return null;\r\n let depth = 0;\r\n for (let i = 0; i < source.length - 1; i++) {\r\n if (source[i] === \"(\") depth++;\r\n else if (source[i] === \")\" && --depth === 0) return null;\r\n }\r\n const parts = splitTopLevel(source.slice(1, -1), \",\");\r\n return parts.length >= 2 ? parts : null;\r\n}\r\n\r\nexport function splitTopLevel(source: string, separator: string): string[] {\r\n const parts: string[] = [];\r\n let depth = 0;\r\n let from = 0;\r\n for (let i = 0; i < source.length; i++) {\r\n const c = source[i];\r\n if (c === \"(\") depth++;\r\n else if (c === \")\") depth--;\r\n else if (c === separator && depth === 0) {\r\n parts.push(source.slice(from, i));\r\n from = i + 1;\r\n }\r\n }\r\n parts.push(source.slice(from));\r\n return parts;\r\n}\r\n"]}
1
+ {"version":3,"file":"equation.js","sourceRoot":"","sources":["../../src/kit/equation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAA2B,MAAM,cAAc,CAAC;AAoB9F,2EAA2E;AAC3E,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAC9B,QAAQ,EAAE,CAAC,GAAG,CAAC;IACf,KAAK,EAAE,CAAC,OAAO,CAAC;I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AM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG;YAAE,KAAK,EAAE,CAAC;aAClB,IAAI,CAAC,KAAK,GAAG;YAAE,KAAK,EAAE,CAAC;aACvB,IAAI,CAAC,KAAK,SAAS,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YACtC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAClC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACL,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { expressionOps, type ExpressionNode } from \"@motionscript/sdk\";\nimport { createBoundedCache } from \"./cache\";\nimport { compileExpressionCached, MATH_DIALECT, type CompiledExpression } from \"./expression\";\n\n/**\n * A plotted equation, read the way it is written rather than by a `kind` prop:\n *\n * | Written as | Is |\n * |---|---|\n * | `sin(x)`, `y = sin(x)` | a function of `x` |\n * | `x = y^2` | a function of `y` |\n * | `r = 1 + cos(theta)` | polar, in `theta` |\n * | `(cos(t), sin(t))` | parametric, in `t` |\n * | `x^2 + y^2 = 4` | implicit, in `x` and `y` |\n */\nexport type Equation =\n | { kind: \"function\"; of: \"x\" | \"y\"; f: CompiledExpression }\n | { kind: \"polar\"; f: CompiledExpression }\n | { kind: \"parametric\"; x: CompiledExpression; y: CompiledExpression }\n /** Drawn where `f(x, y)` is zero. */\n | { kind: \"implicit\"; f: CompiledExpression };\n\n/** The free variable each kind is sampled over, for a host's help text. */\nexport const EQUATION_VARIABLES = {\n function: [\"x\"],\n polar: [\"theta\"],\n parametric: [\"t\"],\n implicit: [\"x\", \"y\"],\n} as const satisfies Record<Equation[\"kind\"], readonly string[]>;\n\nconst parsed = createBoundedCache<Equation | Error>(256);\n\n/**\n * `source` as an {@link Equation}, or the reason it is not one. Memoised, so an\n * unchanged equation is the identical object and a geometry cache can key on it.\n */\nexport function parseEquation(source: string, params: readonly string[] = []): Equation | Error {\n const key = `${params.join(\",\")}|${source}`;\n const hit = parsed.get(key);\n if (hit !== undefined) return hit;\n let result: Equation | Error;\n try {\n result = read(source.trim(), params);\n } catch (error) {\n result = error instanceof Error ? error : new Error(String(error));\n }\n parsed.set(key, result);\n return result;\n}\n\n/**\n * Why `source` will not plot, or `null` when it will. An empty one is not an\n * error (nobody has written it yet), and neither is a name it does not know:\n * that is a named value, see {@link equationParams}.\n */\nexport function equationError(source: string): string | null {\n if (source.trim() === \"\") return null;\n const equation = parseEquation(source, equationParams(source));\n return equation instanceof Error ? equation.message : null;\n}\n\n/** A name that is always a variable of some kind of equation, so never a named value. */\nconst VARIABLE_NAMES: ReadonlySet<string> = new Set([\"r\", ...Object.values(EQUATION_VARIABLES).flat()]);\n\nconst named = createBoundedCache<readonly string[]>(256);\n\n/**\n * Every name `source` reads, in the order it first names them, variables\n * included. Empty for text that does not parse.\n */\nexport function equationNames(source: string): readonly string[] {\n const hit = named.get(source);\n if (hit !== undefined) return hit;\n const names = new Set<string>();\n const text = source.trim();\n try {\n for (const part of splitTuple(text) ?? splitTopLevel(text, \"=\")) {\n collectNames(expressionOps.parse(part.trim(), MATH_DIALECT).root, names);\n }\n } catch {\n names.clear();\n }\n const result = [...names];\n named.set(source, result);\n return result;\n}\n\n/**\n * The named values `source` reads: every name that is not a variable, a\n * function or a constant.\n */\nexport function equationParams(source: string): readonly string[] {\n return equationNames(source).filter((name) => !VARIABLE_NAMES.has(name));\n}\n\nfunction collectNames(node: ExpressionNode, into: Set<string>): void {\n switch (node.kind) {\n case \"ref\":\n into.add(node.name);\n return;\n case \"unary\":\n collectNames(node.operand, into);\n return;\n case \"binary\":\n collectNames(node.left, into);\n collectNames(node.right, into);\n return;\n case \"call\":\n for (const arg of node.args) collectNames(arg, into);\n return;\n default:\n }\n}\n\nfunction read(source: string, params: readonly string[]): Equation {\n if (source === \"\") throw new Error(\"Empty equation\");\n const compile = (text: string, variables: readonly string[]): CompiledExpression => {\n const result = compileExpressionCached(text.trim(), variables, params);\n if (result instanceof Error) throw result;\n return result;\n };\n\n const pair = splitTuple(source);\n if (pair?.length === 2) return { kind: \"parametric\", x: compile(pair[0], [\"t\"]), y: compile(pair[1], [\"t\"]) };\n\n const sides = splitTopLevel(source, \"=\");\n if (sides.length > 2) throw new Error(\"An equation has one '='\");\n if (sides.length === 1) return { kind: \"function\", of: \"x\", f: compile(source, [\"x\"]) };\n\n const [left, right] = sides;\n const subject = left.trim();\n const implicit = (): Equation => {\n const l = compile(left, [\"x\", \"y\"]);\n const r = compile(right, [\"x\", \"y\"]);\n return { kind: \"implicit\", f: (x, y, scope) => l(x, y, scope) - r(x, y, scope) };\n };\n if (subject === \"r\") return { kind: \"polar\", f: compile(right, [\"theta\"]) };\n if (subject === \"y\" || subject === \"x\") {\n const of = subject === \"y\" ? \"x\" : \"y\";\n // `y = x + y` names its own subject on the right, so it is not a function of one variable.\n try {\n return { kind: \"function\", of, f: compile(right, [of]) };\n } catch (error) {\n try {\n return implicit();\n } catch {\n throw error;\n }\n }\n }\n return implicit();\n}\n\n/** `(a, b, …)` as its parts, or `null` when `source` is not one parenthesised list of two or more. */\nexport function splitTuple(source: string): string[] | null {\n if (!source.startsWith(\"(\") || !source.endsWith(\")\")) return null;\n let depth = 0;\n for (let i = 0; i < source.length - 1; i++) {\n if (source[i] === \"(\") depth++;\n else if (source[i] === \")\" && --depth === 0) return null;\n }\n const parts = splitTopLevel(source.slice(1, -1), \",\");\n return parts.length >= 2 ? parts : null;\n}\n\nexport function splitTopLevel(source: string, separator: string): string[] {\n const parts: string[] = [];\n let depth = 0;\n let from = 0;\n for (let i = 0; i < source.length; i++) {\n const c = source[i];\n if (c === \"(\") depth++;\n else if (c === \")\") depth--;\n else if (c === separator && depth === 0) {\n parts.push(source.slice(from, i));\n from = i + 1;\n }\n }\n parts.push(source.slice(from));\n return parts;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"equation3d.js","sourceRoot":"","sources":["../../src/kit/equation3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACzH,OAAO,EAAE,uBAAuB,EAA2B,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAqBnE,iEAAiE;AACjE,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACjC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IACnB,UAAU,EAAE,CAAC,GAAG,CAAC;CACX,CAAC;AAEX,MAAM,aAAa,GAAwB,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC9E,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAE9D,MAAM,QAAQ,GAAG,kBAAkB,CAA0B,GAAG,CAAC,CAAC;AAClE,MAAM,MAAM,GAAG,kBAAkB,CAA6B,GAAG,CAAC,CAAC;AAEnE,gGAAgG;AAChG,MAAM,UAAU,aAAa,CAAC,MAAc;IACxC,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC3C,O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AEvB;IACA,QAAQ,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE;IAC7H,eAAe,EAAE;QACb,KAAK,EAAE,YAAY;QACnB,MAAM,EAAE,aAAa;QACrB,SAAS,EAAE,CAAC,GAAG,qBAAqB,CAAC,MAAM,EAAE,GAAG,qBAAqB,CAAC,OAAO,CAAC;KACjF;IACD,kBAAkB,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAgB,EAAE,SAAS,EAAE,qBAAqB,CAAC,UAAU,EAAE;IACrH,aAAa,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE;CACxF,CAAC","sourcesContent":["import { createBoundedCache } from \"./cache\";\r\nimport { equationError, equationNames, equationParams, EQUATION_VARIABLES, splitTopLevel, splitTuple } from \"./equation\";\r\nimport { compileExpressionCached, type CompiledExpression } from \"./expression\";\r\nimport { fieldError, fieldParams, FIELD_VARIABLES } from \"./field\";\r\n\r\n/**\r\n * A surface's equation, read the way it is written:\r\n *\r\n * | Written as | Is |\r\n * |---|---|\r\n * | `sin(x) * cos(y)`, `z = x^2 - y^2` | a height over `x` and `y` |\r\n * | `(cos(u) sin(v), sin(u) sin(v), cos(v))` | parametric, in `u` and `v` |\r\n */\r\nexport type SurfaceEquation =\r\n | { kind: \"height\"; f: CompiledExpression }\r\n | { kind: \"parametric\"; x: CompiledExpression; y: CompiledExpression; z: CompiledExpression };\r\n\r\n/** A curve through space, three parts in `t`: `(cos(t), sin(t), t / 4)`. */\r\nexport interface SpaceCurveEquation {\r\n x: CompiledExpression;\r\n y: CompiledExpression;\r\n z: CompiledExpression;\r\n}\r\n\r\n/** What each 3D form is written over, for a host's help text. */\r\nexport const EQUATION_VARIABLES_3D = {\r\n height: [\"x\", \"y\"],\r\n surface: [\"u\", \"v\"],\r\n spaceCurve: [\"t\"],\r\n} as const;\r\n\r\nconst SURFACE_NAMES: ReadonlySet<string> = new Set([\"x\", \"y\", \"z\", \"u\", \"v\"]);\r\nconst SPACE_CURVE_NAMES: ReadonlySet<string> = new Set([\"t\"]);\r\n\r\nconst surfaces = createBoundedCache<SurfaceEquation | Error>(128);\r\nconst curves = createBoundedCache<SpaceCurveEquation | Error>(128);\r\n\r\n/** The named values a surface's equation reads: every name that is not one of its variables. */\r\nexport function surfaceParams(source: string): readonly string[] {\r\n return equationNames(source).filter((name) => !SURFACE_NAMES.has(name));\r\n}\r\n\r\n/** The named values a space curve's equation reads. */\r\nexport function spaceCurveParams(source: string): readonly string[] {\r\n return equationNames(source).filter((name) => !SPACE_CURVE_NAMES.has(name));\r\n}\r\n\r\n/** `source` as a surface, or the reason it is not one. Memoised, so an unchanged equation is the identical object. */\r\nexport function parseSurface(source: string, params: readonly string[] = []): SurfaceEquation | Error {\r\n return memo(surfaces, source, params, (text) => {\r\n const compile = compiler(params);\r\n const parts = splitTuple(text);\r\n if (parts) {\r\n if (parts.length !== 3) throw new Error(\"A parametric surface has three parts: (x, y, z)\");\r\n const [x, y, z] = parts.map((part) => compile(part, EQUATION_VARIABLES_3D.surface));\r\n return { kind: \"parametric\", x, y, z };\r\n }\r\n const sides = splitTopLevel(text, \"=\");\r\n if (sides.length > 2) throw new Error(\"An equation has one '='\");\r\n if (sides.length === 2 && sides[0].trim() !== \"z\") throw new Error(\"A surface is written z = …, or as three parts (x, y, z)\");\r\n return { kind: \"height\", f: compile(sides[sides.length - 1], EQUATION_VARIABLES_3D.height) };\r\n });\r\n}\r\n\r\n/** `source` as a space curve, or the reason it is not one. */\r\nexport function parseSpaceCurve(source: string, params: readonly string[] = []): SpaceCurveEquation | Error {\r\n return memo(curves, source, params, (text) => {\r\n const compile = compiler(params);\r\n const parts = splitTuple(text);\r\n if (parts?.length !== 3) throw new Error(\"A space curve has three parts: (x, y, z)\");\r\n const [x, y, z] = parts.map((part) => compile(part, EQUATION_VARIABLES_3D.spaceCurve));\r\n return { x, y, z };\r\n });\r\n}\r\n\r\n/** Why `source` will not draw as a surface, or `null`; empty text is not an error. */\r\nexport function surfaceError(source: string): string | null {\r\n if (source.trim() === \"\") return null;\r\n const equation = parseSurface(source, surfaceParams(source));\r\n return equation instanceof Error ? equation.message : null;\r\n}\r\n\r\n/** Why `source` will not draw as a space curve, or `null`. */\r\nexport function spaceCurveError(source: string): string | null {\r\n if (source.trim() === \"\") return null;\r\n const equation = parseSpaceCurve(source, spaceCurveParams(source));\r\n return equation instanceof Error ? equation.message : null;\r\n}\r\n\r\nfunction compiler(params: readonly string[]) {\r\n return (text: string, variables: readonly string[]): CompiledExpression => {\r\n const result = compileExpressionCached(text.trim(), variables, params);\r\n if (result instanceof Error) throw result;\r\n return result;\r\n };\r\n}\r\n\r\nfunction memo<T extends object>(\r\n cache: ReturnType<typeof createBoundedCache<T | Error>>,\r\n source: string,\r\n params: readonly string[],\r\n read: (text: string) => T,\r\n): T | Error {\r\n const key = `${params.join(\",\")}|${source}`;\r\n const hit = cache.get(key);\r\n if (hit !== undefined) return hit;\r\n let result: T | Error;\r\n try {\r\n const text = source.trim();\r\n if (text === \"\") throw new Error(\"Empty equation\");\r\n result = read(text);\r\n } catch (error) {\r\n result = error instanceof Error ? error : new Error(String(error));\r\n }\r\n cache.set(key, result);\r\n return result;\r\n}\r\n\r\n/** How a host checks an equation as it is typed, and finds its named values, by the `kind` its property declares. */\r\nexport interface EquationLanguage {\r\n error(source: string): string | null;\r\n params(source: string): readonly string[];\r\n variables: readonly string[];\r\n}\r\n\r\nexport const EQUATION_KINDS: Readonly<\r\n Record<\"equation\" | \"surfaceEquation\" | \"spaceCurveEquation\" | \"fieldEquation\", EquationLanguage>\r\n> = {\r\n equation: { error: equationError, params: equationParams, variables: [...new Set(Object.values(EQUATION_VARIABLES).flat())] },\r\n surfaceEquation: {\r\n error: surfaceError,\r\n params: surfaceParams,\r\n variables: [...EQUATION_VARIABLES_3D.height, ...EQUATION_VARIABLES_3D.surface],\r\n },\r\n spaceCurveEquation: { error: spaceCurveError, params: spaceCurveParams, variables: EQUATION_VARIABLES_3D.spaceCurve },\r\n fieldEquation: { error: fieldError, params: fieldParams, variables: FIELD_VARIABLES },\r\n};\r\n"]}
1
+ {"version":3,"file":"equation3d.js","sourceRoot":"","sources":["../../src/kit/equation3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACzH,OAAO,EAAE,uBAAuB,EAA2B,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAqBnE,iEAAiE;AACjE,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACjC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IACnB,UAAU,EAAE,CAAC,GAAG,CAAC;CACX,CAAC;AAEX,MAAM,aAAa,GAAwB,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC9E,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAE9D,MAAM,QAAQ,GAAG,kBAAkB,CAA0B,GAAG,CAAC,CAAC;AAClE,MAAM,MAAM,GAAG,kBAAkB,CAA6B,GAAG,CAAC,CAAC;AAEnE,gGAAgG;AAChG,MAAM,UAAU,aAAa,CAAC,MAAc;IACxC,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAA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AAC;IACvE,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACvB,OAAO,MAAM,CAAC;AAClB,CAAC;AASD,MAAM,CAAC,MAAM,cAAc,GAEvB;IACA,QAAQ,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE;IAC7H,eAAe,EAAE;QACb,KAAK,EAAE,YAAY;QACnB,MAAM,EAAE,aAAa;QACrB,SAAS,EAAE,CAAC,GAAG,qBAAqB,CAAC,MAAM,EAAE,GAAG,qBAAqB,CAAC,OAAO,CAAC;KACjF;IACD,kBAAkB,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAgB,EAAE,SAAS,EAAE,qBAAqB,CAAC,UAAU,EAAE;IACrH,aAAa,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE;CACxF,CAAC","sourcesContent":["import { createBoundedCache } from \"./cache\";\nimport { equationError, equationNames, equationParams, EQUATION_VARIABLES, splitTopLevel, splitTuple } from \"./equation\";\nimport { compileExpressionCached, type CompiledExpression } from \"./expression\";\nimport { fieldError, fieldParams, FIELD_VARIABLES } from \"./field\";\n\n/**\n * A surface's equation, read the way it is written:\n *\n * | Written as | Is |\n * |---|---|\n * | `sin(x) * cos(y)`, `z = x^2 - y^2` | a height over `x` and `y` |\n * | `(cos(u) sin(v), sin(u) sin(v), cos(v))` | parametric, in `u` and `v` |\n */\nexport type SurfaceEquation =\n | { kind: \"height\"; f: CompiledExpression }\n | { kind: \"parametric\"; x: CompiledExpression; y: CompiledExpression; z: CompiledExpression };\n\n/** A curve through space, three parts in `t`: `(cos(t), sin(t), t / 4)`. */\nexport interface SpaceCurveEquation {\n x: CompiledExpression;\n y: CompiledExpression;\n z: CompiledExpression;\n}\n\n/** What each 3D form is written over, for a host's help text. */\nexport const EQUATION_VARIABLES_3D = {\n height: [\"x\", \"y\"],\n surface: [\"u\", \"v\"],\n spaceCurve: [\"t\"],\n} as const;\n\nconst SURFACE_NAMES: ReadonlySet<string> = new Set([\"x\", \"y\", \"z\", \"u\", \"v\"]);\nconst SPACE_CURVE_NAMES: ReadonlySet<string> = new Set([\"t\"]);\n\nconst surfaces = createBoundedCache<SurfaceEquation | Error>(128);\nconst curves = createBoundedCache<SpaceCurveEquation | Error>(128);\n\n/** The named values a surface's equation reads: every name that is not one of its variables. */\nexport function surfaceParams(source: string): readonly string[] {\n return equationNames(source).filter((name) => !SURFACE_NAMES.has(name));\n}\n\n/** The named values a space curve's equation reads. */\nexport function spaceCurveParams(source: string): readonly string[] {\n return equationNames(source).filter((name) => !SPACE_CURVE_NAMES.has(name));\n}\n\n/** `source` as a surface, or the reason it is not one. Memoised, so an unchanged equation is the identical object. */\nexport function parseSurface(source: string, params: readonly string[] = []): SurfaceEquation | Error {\n return memo(surfaces, source, params, (text) => {\n const compile = compiler(params);\n const parts = splitTuple(text);\n if (parts) {\n if (parts.length !== 3) throw new Error(\"A parametric surface has three parts: (x, y, z)\");\n const [x, y, z] = parts.map((part) => compile(part, EQUATION_VARIABLES_3D.surface));\n return { kind: \"parametric\", x, y, z };\n }\n const sides = splitTopLevel(text, \"=\");\n if (sides.length > 2) throw new Error(\"An equation has one '='\");\n if (sides.length === 2 && sides[0].trim() !== \"z\") throw new Error(\"A surface is written z = …, or as three parts (x, y, z)\");\n return { kind: \"height\", f: compile(sides[sides.length - 1], EQUATION_VARIABLES_3D.height) };\n });\n}\n\n/** `source` as a space curve, or the reason it is not one. */\nexport function parseSpaceCurve(source: string, params: readonly string[] = []): SpaceCurveEquation | Error {\n return memo(curves, source, params, (text) => {\n const compile = compiler(params);\n const parts = splitTuple(text);\n if (parts?.length !== 3) throw new Error(\"A space curve has three parts: (x, y, z)\");\n const [x, y, z] = parts.map((part) => compile(part, EQUATION_VARIABLES_3D.spaceCurve));\n return { x, y, z };\n });\n}\n\n/** Why `source` will not draw as a surface, or `null`; empty text is not an error. */\nexport function surfaceError(source: string): string | null {\n if (source.trim() === \"\") return null;\n const equation = parseSurface(source, surfaceParams(source));\n return equation instanceof Error ? equation.message : null;\n}\n\n/** Why `source` will not draw as a space curve, or `null`. */\nexport function spaceCurveError(source: string): string | null {\n if (source.trim() === \"\") return null;\n const equation = parseSpaceCurve(source, spaceCurveParams(source));\n return equation instanceof Error ? equation.message : null;\n}\n\nfunction compiler(params: readonly string[]) {\n return (text: string, variables: readonly string[]): CompiledExpression => {\n const result = compileExpressionCached(text.trim(), variables, params);\n if (result instanceof Error) throw result;\n return result;\n };\n}\n\nfunction memo<T extends object>(\n cache: ReturnType<typeof createBoundedCache<T | Error>>,\n source: string,\n params: readonly string[],\n read: (text: string) => T,\n): T | Error {\n const key = `${params.join(\",\")}|${source}`;\n const hit = cache.get(key);\n if (hit !== undefined) return hit;\n let result: T | Error;\n try {\n const text = source.trim();\n if (text === \"\") throw new Error(\"Empty equation\");\n result = read(text);\n } catch (error) {\n result = error instanceof Error ? error : new Error(String(error));\n }\n cache.set(key, result);\n return result;\n}\n\n/** How a host checks an equation as it is typed, and finds its named values, by the `kind` its property declares. */\nexport interface EquationLanguage {\n error(source: string): string | null;\n params(source: string): readonly string[];\n variables: readonly string[];\n}\n\nexport const EQUATION_KINDS: Readonly<\n Record<\"equation\" | \"surfaceEquation\" | \"spaceCurveEquation\" | \"fieldEquation\", EquationLanguage>\n> = {\n equation: { error: equationError, params: equationParams, variables: [...new Set(Object.values(EQUATION_VARIABLES).flat())] },\n surfaceEquation: {\n error: surfaceError,\n params: surfaceParams,\n variables: [...EQUATION_VARIABLES_3D.height, ...EQUATION_VARIABLES_3D.surface],\n },\n spaceCurveEquation: { error: spaceCurveError, params: spaceCurveParams, variables: EQUATION_VARIABLES_3D.spaceCurve },\n fieldEquation: { error: fieldError, params: fieldParams, variables: FIELD_VARIABLES },\n};\n"]}