vizmatic 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PROMPT.md +75 -525
- package/README.md +87 -578
- package/ROADMAP.md +49 -67
- package/SCIENCE.md +250 -0
- package/assets/THIRD_PARTY_LICENSES.md +40 -1
- package/assets/fonts/InstrumentSerif-Italic.ttf +0 -0
- package/assets/fonts/InstrumentSerif-Regular.ttf +0 -0
- package/assets/licenses/raster-codecs-MIT.txt +74 -0
- package/dist/chunk-3F2VQ7NW.js +1 -0
- package/dist/chunk-4XE64I2U.js +755 -0
- package/dist/chunk-JHHPLALU.js +79 -0
- package/dist/chunk-LTX44BAE.js +112 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-PSBF4TEK.js +1 -0
- package/dist/chunk-RPAHMKAR.js +605 -0
- package/dist/chunk-RWF4VBUL.js +3617 -0
- package/dist/chunk-WHT6HRMX.js +4201 -0
- package/dist/cli.js +371 -10
- package/dist/index.cjs +11129 -2922
- package/dist/index.d.cts +1225 -369
- package/dist/index.d.ts +1225 -369
- package/dist/index.js +6220 -3015
- package/dist/math-LXB4FH4E.js +7 -0
- package/dist/math-QVCETQDQ.js +1 -0
- package/dist/scene-browser-assets.d.ts +38 -0
- package/dist/scene-browser-assets.js +53 -0
- package/dist/scene-browser-chunks/chunk-5MVLYGXM.js +70 -0
- package/dist/scene-browser-chunks/chunk-ASXKN3NU.js +1 -0
- package/dist/scene-browser-chunks/chunk-CM5Y5LZP.js +1 -0
- package/dist/scene-browser-chunks/chunk-DP7NB4EW.js +6 -0
- package/dist/scene-browser-chunks/emscripten-module.browser-M5AEKJGE.js +1 -0
- package/dist/scene-browser-chunks/ffi-FL6ORJU3.js +1 -0
- package/dist/scene-browser-chunks/module-ES6BEMUI-JD5S5VKR.js +1 -0
- package/dist/scene-browser-chunks/module-asyncify-2EFITU5U-HWPFJFJC.js +1 -0
- package/dist/scene-browser-chunks/scene-browser-layout-M3XSXMV4.js +27 -0
- package/dist/scene-browser.d.ts +117 -0
- package/dist/scene-browser.js +220 -0
- package/dist/scene-cli.d.ts +1 -0
- package/dist/scene-cli.js +4 -0
- package/dist/scene-runtime.cjs +995 -0
- package/dist/scene-runtime.d.cts +81 -0
- package/dist/scene-runtime.d.ts +81 -0
- package/dist/scene-runtime.js +22 -0
- package/dist/server-2FYHZ4UO.js +331 -0
- package/dist/stage-browser/browser.d.ts +2482 -0
- package/dist/stage-browser/chunk-SQE76S5B.js +1 -0
- package/dist/stage-browser/chunk-VZNL6JY2.js +59 -0
- package/dist/stage-browser/dagre.esm-N2NIVIAZ.js +6 -0
- package/dist/stage-browser/math-4WFNHVV2.js +18 -0
- package/dist/stage-browser/stage.js +19 -0
- package/dist/stage-export.cjs +4950 -0
- package/dist/stage-export.d.cts +112 -0
- package/dist/stage-export.d.ts +112 -0
- package/dist/stage-export.js +544 -0
- package/dist/stage.cjs +9745 -0
- package/dist/stage.d.cts +1678 -0
- package/dist/stage.d.ts +1678 -0
- package/dist/stage.js +5404 -0
- package/dist/svg-import-Djj2q7Pc.d.cts +742 -0
- package/dist/svg-import-Djj2q7Pc.d.ts +742 -0
- package/dist/video-CcHW1qhV.d.cts +532 -0
- package/dist/video-CcHW1qhV.d.ts +532 -0
- package/examples/README.md +18 -0
- package/examples/agent-pipeline.tsx +4 -4
- package/examples/animated-pipeline.tsx +1 -5
- package/examples/attention-head.tsx +12 -12
- package/examples/aurora-incident.tsx +4 -3
- package/examples/building-blocks.tsx +8 -9
- package/examples/catalog-charts.tsx +4 -4
- package/examples/catalog-content.tsx +7 -9
- package/examples/catalog-convolution-kernel.tsx +116 -0
- package/examples/catalog-data.tsx +2 -8
- package/examples/catalog-dataflow.tsx +5 -9
- package/examples/catalog-dense.tsx +80 -0
- package/examples/catalog-deployment.tsx +5 -11
- package/examples/catalog-diagrams.tsx +13 -16
- package/examples/catalog-drawing.tsx +7 -7
- package/examples/catalog-flows.tsx +4 -4
- package/examples/catalog-foundations.tsx +11 -11
- package/examples/catalog-gaussian-blur.tsx +146 -0
- package/examples/catalog-image-tensors.tsx +115 -0
- package/examples/catalog-ml.tsx +36 -31
- package/examples/catalog-numeric-matrices.tsx +93 -0
- package/examples/catalog-photo-blur.tsx +209 -0
- package/examples/catalog-science-ai.tsx +130 -0
- package/examples/catalog-science-chemistry.tsx +103 -0
- package/examples/catalog-science-math.tsx +93 -0
- package/examples/catalog-science-physics.tsx +84 -0
- package/examples/catalog-sequence.tsx +59 -38
- package/examples/data-pipeline-lineage-presentation.tsx +5 -0
- package/examples/data-pipeline-lineage.tsx +85 -0
- package/examples/daybreak-launch.tsx +1 -0
- package/examples/desired-quadrant.tsx +7 -8
- package/examples/engineering-dashboard-presentation.tsx +13 -0
- package/examples/engineering-dashboard.tsx +160 -0
- package/examples/engineering-flow.tsx +2 -4
- package/examples/eval-dashboard.tsx +6 -6
- package/examples/films/attention.ts +278 -0
- package/examples/films/cache-miss.ts +431 -0
- package/examples/films/catalog.json +132 -0
- package/examples/films/central-limit.ts +269 -0
- package/examples/films/complex-maps.ts +273 -0
- package/examples/films/deck-example.ts +224 -0
- package/examples/films/euler-circle.ts +179 -0
- package/examples/films/fourier-epicycles.ts +265 -0
- package/examples/films/gradient-descent.ts +345 -0
- package/examples/films/linear-maps.ts +175 -0
- package/examples/films/lorenz.ts +207 -0
- package/examples/films/pythagoras.ts +185 -0
- package/examples/films/taylor-series.ts +159 -0
- package/examples/films/vizmatic-title.ts +117 -0
- package/examples/llm-serving-stack-presentation.tsx +5 -0
- package/examples/llm-serving-stack.tsx +94 -0
- package/examples/model-garden.tsx +1 -0
- package/examples/model-router.tsx +6 -6
- package/examples/nccl-all-gather.tsx +3 -3
- package/examples/nccl-all-reduce.tsx +3 -3
- package/examples/nccl-all-to-all.tsx +1 -1
- package/examples/nccl-broadcast.tsx +1 -1
- package/examples/nccl-reduce-scatter.tsx +5 -5
- package/examples/orthogonal-routing.tsx +4 -4
- package/examples/pareto-frontier.tsx +9 -10
- package/examples/presentation-frame.tsx +6 -6
- package/examples/pressure-mechanism.scene.json +14 -0
- package/examples/production-system-map-presentation.tsx +5 -0
- package/examples/production-system-map.tsx +130 -0
- package/examples/rag-graph.tsx +7 -7
- package/examples/release-card.tsx +5 -5
- package/examples/spec-anatomy.tsx +5 -5
- package/examples/system-architecture.tsx +19 -32
- package/examples/theme-system.tsx +1 -1
- package/examples/token-matrix.tsx +4 -2
- package/examples/transparent-badge.tsx +1 -2
- package/examples/videos/README.md +62 -0
- package/examples/videos/calculus-tangent.tsx +101 -0
- package/examples/videos/catalyst-pathway.tsx +56 -0
- package/examples/videos/causal-attention.tsx +91 -0
- package/examples/videos/convolution-kernel.tsx +34 -0
- package/examples/videos/gaussian-blur.tsx +32 -0
- package/examples/videos/image-to-matrix.tsx +22 -0
- package/examples/videos/matrix-multiplication.tsx +128 -0
- package/examples/videos/photo-gaussian-blur.tsx +39 -0
- package/examples/videos/request-lifecycle.tsx +99 -0
- package/examples/videos/signal-to-story.tsx +126 -0
- package/examples/videos/wave-interference.tsx +80 -0
- package/examples/vizmatic-bare.d.ts +1 -0
- package/examples/vizmatic-hero.tsx +9 -18
- package/examples/website-workflow.tsx +7 -7
- package/examples/weekend-field-notes.tsx +3 -2
- package/package.json +77 -12
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// src/math.ts
|
|
2
|
+
import parseCssColor from "parse-css-color";
|
|
3
|
+
import { liteAdaptor } from "mathjax-full/js/adaptors/liteAdaptor.js";
|
|
4
|
+
import { RegisterHTMLHandler } from "mathjax-full/js/handlers/html.js";
|
|
5
|
+
import { TeX } from "mathjax-full/js/input/tex.js";
|
|
6
|
+
import "mathjax-full/js/input/tex/ams/AmsConfiguration.js";
|
|
7
|
+
import "mathjax-full/js/input/tex/newcommand/NewcommandConfiguration.js";
|
|
8
|
+
import { mathjax } from "mathjax-full/js/mathjax.js";
|
|
9
|
+
import { SVG } from "mathjax-full/js/output/svg.js";
|
|
10
|
+
var DEFAULT_FONT_SIZE = 16;
|
|
11
|
+
var EX_FACTOR = 0.5;
|
|
12
|
+
var adaptor = liteAdaptor({ fontSize: DEFAULT_FONT_SIZE });
|
|
13
|
+
RegisterHTMLHandler(adaptor);
|
|
14
|
+
var outputJax = new SVG({ fontCache: "none", exFactor: EX_FACTOR });
|
|
15
|
+
var renderCache = /* @__PURE__ */ new Map();
|
|
16
|
+
var RENDER_CACHE_LIMIT = 128;
|
|
17
|
+
function createDocument() {
|
|
18
|
+
const inputJax = new TeX({
|
|
19
|
+
packages: ["base", "ams", "newcommand"],
|
|
20
|
+
formatError(_jax, error) {
|
|
21
|
+
throw new Error(`Invalid TeX: ${error.message}`, { cause: error });
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return mathjax.document("", { InputJax: inputJax, OutputJax: outputJax });
|
|
25
|
+
}
|
|
26
|
+
function parseEx(value, name) {
|
|
27
|
+
if (typeof value !== "string" || !value.endsWith("ex")) {
|
|
28
|
+
throw new Error(`MathJax returned an unsupported ${name} dimension`);
|
|
29
|
+
}
|
|
30
|
+
const amount = Number(value.slice(0, -2));
|
|
31
|
+
if (!Number.isFinite(amount) || amount <= 0) {
|
|
32
|
+
throw new Error(`MathJax returned an invalid ${name} dimension`);
|
|
33
|
+
}
|
|
34
|
+
return amount;
|
|
35
|
+
}
|
|
36
|
+
function parseViewBox(value) {
|
|
37
|
+
if (typeof value !== "string") throw new Error("MathJax returned an SVG without a viewBox");
|
|
38
|
+
const values = value.trim().split(/[ ,]+/).map(Number);
|
|
39
|
+
if (values.length !== 4 || values.some((part) => !Number.isFinite(part)) || values[2] <= 0 || values[3] <= 0) {
|
|
40
|
+
throw new Error("MathJax returned an invalid SVG viewBox");
|
|
41
|
+
}
|
|
42
|
+
return [values[0], values[1], values[2], values[3]];
|
|
43
|
+
}
|
|
44
|
+
function renderMathSvg(tex, options = {}) {
|
|
45
|
+
if (typeof tex !== "string" || tex.trim().length === 0) {
|
|
46
|
+
throw new Error("TeX input must be a non-empty string");
|
|
47
|
+
}
|
|
48
|
+
const fontSize = options.fontSize ?? DEFAULT_FONT_SIZE;
|
|
49
|
+
if (!Number.isFinite(fontSize) || fontSize <= 0) {
|
|
50
|
+
throw new Error("Math SVG fontSize must be a positive finite number");
|
|
51
|
+
}
|
|
52
|
+
const color = options.color ?? "#000000";
|
|
53
|
+
if (typeof color !== "string" || !parseCssColor(color.trim())) {
|
|
54
|
+
throw new Error("Math SVG color must be a valid CSS color");
|
|
55
|
+
}
|
|
56
|
+
const normalizedColor = color.trim();
|
|
57
|
+
const display = options.display ?? false;
|
|
58
|
+
const key = JSON.stringify([tex, fontSize, normalizedColor, display]);
|
|
59
|
+
const cached = renderCache.get(key);
|
|
60
|
+
if (cached) {
|
|
61
|
+
renderCache.delete(key);
|
|
62
|
+
renderCache.set(key, cached);
|
|
63
|
+
return { ...cached };
|
|
64
|
+
}
|
|
65
|
+
let container;
|
|
66
|
+
try {
|
|
67
|
+
container = createDocument().convert(tex, {
|
|
68
|
+
display,
|
|
69
|
+
em: fontSize,
|
|
70
|
+
ex: fontSize * EX_FACTOR,
|
|
71
|
+
containerWidth: fontSize * 80
|
|
72
|
+
});
|
|
73
|
+
} catch (cause) {
|
|
74
|
+
if (cause instanceof Error && cause.message.startsWith("Invalid TeX:")) throw cause;
|
|
75
|
+
const detail = cause instanceof Error ? cause.message : String(cause);
|
|
76
|
+
throw new Error(`Unable to render TeX: ${detail}`, { cause });
|
|
77
|
+
}
|
|
78
|
+
const svgElement = adaptor.tags(container, "svg")[0];
|
|
79
|
+
if (!svgElement) throw new Error("MathJax did not produce an SVG image");
|
|
80
|
+
const width = parseEx(adaptor.getAttribute(svgElement, "width"), "width") * fontSize * EX_FACTOR;
|
|
81
|
+
const height = parseEx(adaptor.getAttribute(svgElement, "height"), "height") * fontSize * EX_FACTOR;
|
|
82
|
+
if (!Number.isFinite(width) || !Number.isFinite(height)) {
|
|
83
|
+
throw new Error("MathJax returned non-finite SVG dimensions");
|
|
84
|
+
}
|
|
85
|
+
const [, viewBoxY, , viewBoxHeight] = parseViewBox(adaptor.getAttribute(svgElement, "viewBox"));
|
|
86
|
+
const baseline = -viewBoxY * height / viewBoxHeight;
|
|
87
|
+
if (!Number.isFinite(baseline)) {
|
|
88
|
+
throw new Error("MathJax returned an invalid SVG baseline");
|
|
89
|
+
}
|
|
90
|
+
const drawing = adaptor.tags(svgElement, "g")[0];
|
|
91
|
+
if (!drawing) throw new Error("MathJax returned an SVG without a drawing group");
|
|
92
|
+
adaptor.removeAttribute(svgElement, "style");
|
|
93
|
+
adaptor.setAttribute(svgElement, "width", `${width}px`);
|
|
94
|
+
adaptor.setAttribute(svgElement, "height", `${height}px`);
|
|
95
|
+
adaptor.setAttribute(drawing, "fill", normalizedColor);
|
|
96
|
+
adaptor.setAttribute(drawing, "stroke", normalizedColor);
|
|
97
|
+
const result = {
|
|
98
|
+
svg: adaptor.serializeXML(svgElement),
|
|
99
|
+
width,
|
|
100
|
+
height,
|
|
101
|
+
baseline
|
|
102
|
+
};
|
|
103
|
+
renderCache.set(key, result);
|
|
104
|
+
if (renderCache.size > RENDER_CACHE_LIMIT) {
|
|
105
|
+
renderCache.delete(renderCache.keys().next().value);
|
|
106
|
+
}
|
|
107
|
+
return { ...result };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export {
|
|
111
|
+
renderMathSvg
|
|
112
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __defProp=Object.defineProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};export{__export};
|