vizmatic 0.8.3 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/PROMPT.md +32 -0
  2. package/README.md +8 -3
  3. package/ROADMAP.md +4 -2
  4. package/SCIENCE.md +69 -3
  5. package/dist/chunk-6JI55YX4.js +604 -0
  6. package/dist/{chunk-LTX44BAE.js → chunk-BYKXNUX7.js} +25 -4
  7. package/dist/{chunk-4MXGLMBG.js → chunk-EPZLNABN.js} +107 -37
  8. package/dist/chunk-EWCO6ZT6.js +696 -0
  9. package/dist/{chunk-JZPMGVBP.js → chunk-G7HRSKHV.js} +1 -1
  10. package/dist/{chunk-RPAHMKAR.js → chunk-JTWC2OPN.js} +7 -5
  11. package/dist/chunk-LJZO36IR.js +124 -0
  12. package/dist/chunk-REL2BZ2B.js +88 -0
  13. package/dist/chunk-RLPEOWST.js +1 -0
  14. package/dist/chunk-VMHOWCDL.js +296 -0
  15. package/dist/chunk-YDD63HHD.js +1 -0
  16. package/dist/{chunk-I745F4QK.js → chunk-YNGDEARY.js} +1134 -643
  17. package/dist/cli.js +80 -543
  18. package/dist/gpu-selection-CDWCZH27.js +1 -0
  19. package/dist/gpu-selection-MX6NHMNA.js +635 -0
  20. package/dist/index.cjs +473 -155
  21. package/dist/index.d.cts +30 -239
  22. package/dist/index.d.ts +30 -239
  23. package/dist/index.js +410 -457
  24. package/dist/math-E7W5LFWO.js +1 -0
  25. package/dist/{math-LXB4FH4E.js → math-NEFQUPRV.js} +3 -1
  26. package/dist/scene-browser.js +17 -17
  27. package/dist/scene-cli.js +1 -1
  28. package/dist/scene-runtime.cjs +4 -2
  29. package/dist/scene-runtime.js +2 -2
  30. package/dist/stage-browser/browser.d.ts +1206 -854
  31. package/dist/stage-browser/gpu-renderer.js +138 -0
  32. package/dist/stage-browser/{math-4WFNHVV2.js → math-KYHUOK7A.js} +46 -10
  33. package/dist/stage-browser/stage.js +107 -19
  34. package/dist/stage-export.cjs +8221 -6784
  35. package/dist/stage-export.d.cts +13 -5
  36. package/dist/stage-export.d.ts +13 -5
  37. package/dist/stage-export.js +111 -601
  38. package/dist/stage.cjs +6243 -3474
  39. package/dist/stage.d.cts +1064 -765
  40. package/dist/stage.d.ts +1064 -765
  41. package/dist/stage.js +3571 -2405
  42. package/dist/{svg-import-B5BGbC1t.d.cts → svg-import-CSCFWYaB.d.cts} +21 -12
  43. package/dist/{svg-import-B5BGbC1t.d.ts → svg-import-CSCFWYaB.d.ts} +21 -12
  44. package/dist/teaching-math-DTKc0XsB.d.cts +243 -0
  45. package/dist/teaching-math-ydDBhJ2M.d.ts +243 -0
  46. package/dist/{video-CiN1MDCS.d.cts → theme-DhVdDQKO.d.cts} +4 -237
  47. package/dist/{video-CiN1MDCS.d.ts → theme-DhVdDQKO.d.ts} +4 -237
  48. package/dist/video-BYCeOz8F.d.ts +259 -0
  49. package/dist/video-CGLxJXqu.d.cts +259 -0
  50. package/examples/catalog-science-physics.tsx +6 -6
  51. package/examples/films/_boltzmann-entropy/model.ts +63 -0
  52. package/examples/films/_catalysis/model.ts +49 -0
  53. package/examples/films/_gravitational-waves/model.ts +32 -0
  54. package/examples/films/_heat-equation/model.ts +54 -0
  55. package/examples/films/_hydrogen-orbitals/model.ts +31 -0
  56. package/examples/films/_maxwell/model.ts +84 -0
  57. package/examples/films/_planetary-orbits/appearance.ts +71 -0
  58. package/examples/films/_planetary-orbits/model.ts +152 -0
  59. package/examples/films/_planetary-orbits/saturn.ts +142 -0
  60. package/examples/films/_quantum-tunneling/model.ts +58 -0
  61. package/examples/films/_reaction-diffusion/model.ts +61 -0
  62. package/examples/films/_stationary-action/model.ts +38 -0
  63. package/examples/films/attention.ts +309 -253
  64. package/examples/films/beam-search.ts +321 -49
  65. package/examples/films/boltzmann-entropy.ts +104 -0
  66. package/examples/films/cache-miss.ts +387 -394
  67. package/examples/films/catalog.json +238 -77
  68. package/examples/films/catalysis.ts +128 -0
  69. package/examples/films/central-limit.ts +27 -22
  70. package/examples/films/complex-maps.ts +70 -56
  71. package/examples/films/deck-example.ts +261 -200
  72. package/examples/films/euler-circle.ts +72 -28
  73. package/examples/films/flash-attention.ts +549 -0
  74. package/examples/films/forecast.ts +2 -2
  75. package/examples/films/fourier-epicycles.ts +21 -20
  76. package/examples/films/gradient-descent.ts +23 -49
  77. package/examples/films/gravitational-waves.ts +179 -0
  78. package/examples/films/heat-equation.ts +124 -0
  79. package/examples/films/hydrogen-orbitals.ts +135 -0
  80. package/examples/films/io-uring.ts +635 -0
  81. package/examples/films/linear-maps.ts +42 -31
  82. package/examples/films/lorenz.ts +42 -79
  83. package/examples/films/maxwell.ts +197 -0
  84. package/examples/films/pathlines.ts +85 -0
  85. package/examples/films/planetary-orbits.ts +146 -0
  86. package/examples/films/pythagoras.ts +18 -10
  87. package/examples/films/quantum-tunneling.ts +116 -0
  88. package/examples/films/rag-citations.ts +423 -0
  89. package/examples/films/reaction-diffusion.ts +70 -0
  90. package/examples/films/ring-allreduce.ts +531 -0
  91. package/examples/films/stationary-action.ts +170 -0
  92. package/examples/films/svd-3d.ts +605 -0
  93. package/examples/films/taylor-series.ts +9 -9
  94. package/examples/films/vizmatic-title.ts +1 -0
  95. package/examples/vizmatic-hero.tsx +102 -32
  96. package/package.json +3 -1
  97. package/dist/chunk-3F2VQ7NW.js +0 -1
  98. package/dist/chunk-GGFDBJ25.js +0 -88
  99. package/dist/math-QVCETQDQ.js +0 -1
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getThemeColors,
3
3
  setDensityResolver
4
- } from "./chunk-RPAHMKAR.js";
4
+ } from "./chunk-JTWC2OPN.js";
5
5
 
6
6
  // src/brand.ts
7
7
  import React from "react";
@@ -1703,6 +1703,38 @@ async function loopbackPair() {
1703
1703
  }
1704
1704
  }
1705
1705
  var ffmpegOptions = /* @__PURE__ */ new Map();
1706
+ var NVENC_PRESETS = {
1707
+ ultrafast: "p1",
1708
+ superfast: "p2",
1709
+ veryfast: "p3",
1710
+ faster: "p4",
1711
+ fast: "p5",
1712
+ medium: "p6",
1713
+ slow: "p7",
1714
+ slower: "p7",
1715
+ veryslow: "p7",
1716
+ placebo: "p7"
1717
+ };
1718
+ function nvencArgs(options) {
1719
+ return [
1720
+ "-c:v",
1721
+ "h264_nvenc",
1722
+ "-preset",
1723
+ NVENC_PRESETS[options.preset ?? "fast"],
1724
+ "-tune",
1725
+ "hq",
1726
+ "-profile:v",
1727
+ "high",
1728
+ "-rc",
1729
+ "vbr",
1730
+ "-cq",
1731
+ String(options.crf ?? 18),
1732
+ "-b:v",
1733
+ "0",
1734
+ "-g",
1735
+ "250"
1736
+ ];
1737
+ }
1706
1738
  function videoToolboxArgs({ width, height, fps }) {
1707
1739
  const args = ["-c:v", "h264_videotoolbox", "-allow_sw", "0", "-profile:v", "high", "-q:v", "75", "-g", "250"];
1708
1740
  const blocks = Math.ceil(width / 16) * Math.ceil(height / 16);
@@ -1764,45 +1796,84 @@ async function verifyHardwareFrames(ffmpeg, path, count, fps, signal) {
1764
1796
  let missing = 0;
1765
1797
  while (missing < count && seen[Math.floor(missing / 8)] & 1 << missing % 8) missing++;
1766
1798
  const detail = missing < count ? `; missing frame ${missing}` : "";
1767
- throw new Error(`VideoToolbox packet timing mismatch: expected ${count} frames at ${fps} fps, found ${packets}${detail}`);
1799
+ throw new Error(`Hardware H.264 packet timing mismatch: expected ${count} frames at ${fps} fps, found ${packets}${detail}`);
1768
1800
  }
1769
1801
  }
1770
- var hardwareProbes = /* @__PURE__ */ new Map();
1771
- async function resolveH264Encoder(requested = "libx264", ffmpegPath = "ffmpeg", format = { width: 1920, height: 1080, fps: 30 }) {
1772
- if (requested === "libx264") return requested;
1773
- if (requested !== "videotoolbox") throw new Error("h264Encoder must be libx264 or videotoolbox");
1802
+ var hardwareProbes = /* @__PURE__ */ new Set();
1803
+ var pendingHardwareProbes = /* @__PURE__ */ new Map();
1804
+ async function probeH264Encoder(encoder, ffmpegPath, format, options) {
1774
1805
  const { width, height, fps } = format;
1775
- if (![width, height].every((value) => Number.isSafeInteger(value) && value > 0 && value % 2 === 0) || !Number.isInteger(fps) || fps < 1 || fps > 120) throw new Error("Invalid H.264 probe dimensions or FPS");
1776
- const key = JSON.stringify([ffmpegPath, width, height, fps]);
1777
- let probe = hardwareProbes.get(key);
1806
+ const args = [
1807
+ "-nostdin",
1808
+ "-v",
1809
+ "error",
1810
+ "-abort_on",
1811
+ "empty_output",
1812
+ "-f",
1813
+ "lavfi",
1814
+ "-i",
1815
+ `color=size=${width}x${height}:rate=${fps},format=rgba`,
1816
+ "-frames:v",
1817
+ "1",
1818
+ "-vf",
1819
+ COLOR_FILTER,
1820
+ ...encoder === "nvenc" ? nvencArgs(options) : videoToolboxArgs(format),
1821
+ "-pix_fmt",
1822
+ "yuv420p",
1823
+ ...COLOR_TAGS,
1824
+ "-f",
1825
+ "null",
1826
+ "-"
1827
+ ];
1828
+ const key = JSON.stringify([ffmpegPath, args]);
1829
+ if (hardwareProbes.has(key)) return true;
1830
+ let probe = options.signal ? void 0 : pendingHardwareProbes.get(key);
1778
1831
  if (!probe) {
1779
- probe = new Promise((done) => {
1780
- const args = [
1781
- "-nostdin",
1782
- "-v",
1783
- "error",
1784
- "-f",
1785
- "lavfi",
1786
- "-i",
1787
- `color=size=${width}x${height}:rate=${fps}`,
1788
- "-frames:v",
1789
- "1",
1790
- ...videoToolboxArgs(format),
1791
- "-pix_fmt",
1792
- "yuv420p",
1793
- "-f",
1794
- "null",
1795
- "-"
1796
- ];
1797
- const child = execFile(ffmpegPath, args, { timeout: 15e3, killSignal: "SIGKILL", maxBuffer: 65536 }, (error) => {
1798
- if (error) hardwareProbes.delete(key);
1799
- done(!error);
1832
+ probe = new Promise((done, fail) => {
1833
+ const child = execFile(ffmpegPath, args, {
1834
+ timeout: 15e3,
1835
+ killSignal: "SIGKILL",
1836
+ maxBuffer: 65536,
1837
+ signal: options.signal
1838
+ }, (error) => {
1839
+ if (options.signal?.aborted) fail(abortError());
1840
+ else {
1841
+ if (!error) hardwareProbes.add(key);
1842
+ done(!error);
1843
+ }
1800
1844
  });
1801
1845
  child.stdin?.end();
1802
1846
  });
1803
- hardwareProbes.set(key, probe);
1847
+ if (!options.signal) pendingHardwareProbes.set(key, probe);
1804
1848
  }
1805
- return await probe ? requested : "libx264";
1849
+ try {
1850
+ return await probe;
1851
+ } finally {
1852
+ if (pendingHardwareProbes.get(key) === probe) pendingHardwareProbes.delete(key);
1853
+ }
1854
+ }
1855
+ async function resolveH264Encoder(requested = "libx264", ffmpegPath = "ffmpeg", format = { width: 1920, height: 1080, fps: 30 }, options = {}) {
1856
+ if (options.signal?.aborted) throw abortError();
1857
+ if (requested === "libx264") return requested;
1858
+ if (requested !== "videotoolbox" && requested !== "nvenc" && requested !== "auto")
1859
+ throw new Error("h264Encoder must be libx264, videotoolbox, nvenc or auto");
1860
+ const { width, height, fps } = format;
1861
+ if (![width, height].every((value) => Number.isSafeInteger(value) && value > 0 && value % 2 === 0) || !Number.isInteger(fps) || fps < 1 || fps > 120) throw new Error("Invalid H.264 probe dimensions or FPS");
1862
+ const crf = options.crf ?? 18;
1863
+ const preset = options.preset ?? "fast";
1864
+ if (!Number.isInteger(crf) || crf < 0 || crf > 51) throw new Error("crf must be an integer between 0 and 51");
1865
+ if (requested === "auto" && (process.env.CI || process.env.GITHUB_ACTIONS || crf !== 18 || options.tune !== void 0 || options.x264Params !== void 0)) return "libx264";
1866
+ const candidates = requested === "auto" ? process.platform === "darwin" ? ["videotoolbox", "nvenc"] : ["nvenc"] : [requested];
1867
+ for (const encoder of candidates) {
1868
+ const supported = options.x264Params === void 0 && (encoder === "nvenc" ? options.tune === void 0 && crf > 0 && Object.hasOwn(NVENC_PRESETS, preset) : crf === 18 && (options.tune === void 0 || options.tune === "animation"));
1869
+ if (!supported) continue;
1870
+ const available = await probeH264Encoder(encoder, ffmpegPath, format, options);
1871
+ if (options.signal?.aborted) throw abortError();
1872
+ if (available) return encoder;
1873
+ }
1874
+ if (options.requireH264Encoder && requested !== "auto")
1875
+ throw new Error(`Requested H.264 encoder ${requested} is unavailable for these settings`);
1876
+ return "libx264";
1806
1877
  }
1807
1878
  function hasFfmpegOption(ffmpegPath, component, option) {
1808
1879
  const key = JSON.stringify([ffmpegPath, component, option]);
@@ -1889,10 +1960,7 @@ async function renderRgbaVideo(renderFrame, options) {
1889
1960
  if (codec !== "h264" && (options.h264Encoder !== void 0 || options.requireH264Encoder))
1890
1961
  throw new Error("h264Encoder applies only to H.264 output");
1891
1962
  const requested = options.h264Encoder ?? "libx264";
1892
- const useSoftwareSettings = crf !== 18 || options.x264Params !== void 0 || options.tune !== void 0 && options.tune !== "animation";
1893
- const h264Encoder = requested === "videotoolbox" && useSoftwareSettings ? "libx264" : await withAbort(resolveH264Encoder(requested, ffmpegPath, { width, height, fps }), options.signal);
1894
- if (options.requireH264Encoder && requested !== h264Encoder)
1895
- throw new Error(`Requested H.264 encoder ${requested} is unavailable for these settings`);
1963
+ const h264Encoder = await resolveH264Encoder(requested, ffmpegPath, { width, height, fps }, options);
1896
1964
  const outputPath = resolve(options.outputPath);
1897
1965
  const outputDirectory = dirname2(outputPath);
1898
1966
  await mkdir2(outputDirectory, { recursive: true });
@@ -1956,6 +2024,8 @@ async function renderRgbaVideo(renderFrame, options) {
1956
2024
  args.push("-c:v", "libvpx-vp9", "-crf", String(crf), "-b:v", "0", "-deadline", "good", "-cpu-used", "2", "-row-mt", "1", "-threads:v", String(threads));
1957
2025
  } else if (h264Encoder === "videotoolbox") {
1958
2026
  args.push(...videoToolboxArgs({ width, height, fps }));
2027
+ } else if (h264Encoder === "nvenc") {
2028
+ args.push(...nvencArgs(options));
1959
2029
  } else {
1960
2030
  args.push("-c:v", "libx264", "-preset", preset);
1961
2031
  if (options.tune) args.push("-tune", options.tune);
@@ -2095,7 +2165,7 @@ async function renderRgbaVideo(renderFrame, options) {
2095
2165
  const exit = await withAbort(exited, options.signal);
2096
2166
  if (exit.error) throw new Error(`Unable to start FFmpeg: ${exit.error.message}`, { cause: exit.error });
2097
2167
  if (exit.code !== 0) throw describeExit(exit.code, exit.signal, stderr);
2098
- if (h264Encoder === "videotoolbox") await verifyHardwareFrames(ffmpegPath, tempPath, schedule.count, fps, options.signal);
2168
+ if (h264Encoder !== "libx264") await verifyHardwareFrames(ffmpegPath, tempPath, schedule.count, fps, options.signal);
2099
2169
  const outputStat = await stat(tempPath);
2100
2170
  await chmod(tempPath, 420);
2101
2171
  await rename(tempPath, outputPath);