vizmatic 0.7.3 → 0.8.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/dist/index.js CHANGED
@@ -22,15 +22,12 @@ import {
22
22
  chapterMetadata,
23
23
  chartAccessibilityAttributes,
24
24
  chartDescription,
25
- convertIndexedToRgb,
26
25
  cropPixels,
27
- decodePng,
28
26
  defineAnimation,
29
27
  detectBackgroundColor,
30
28
  detectContentBounds,
31
29
  detectLayoutOverflow,
32
30
  detectOverflow,
33
- encodePng,
34
31
  getFonts,
35
32
  getRenderBackground,
36
33
  hold,
@@ -55,7 +52,7 @@ import {
55
52
  withRenderContext,
56
53
  wrapWithBrand,
57
54
  wrapWithWatermark
58
- } from "./chunk-F6QI6QJY.js";
55
+ } from "./chunk-ZB3HK7RM.js";
59
56
  import {
60
57
  DEFAULT_DENSITY,
61
58
  DENSITY_NAMES,
@@ -88,6 +85,11 @@ import {
88
85
  withColorAlpha,
89
86
  withDensity
90
87
  } from "./chunk-RPAHMKAR.js";
88
+ import {
89
+ convertIndexedToRgb,
90
+ decodePng,
91
+ encodePng
92
+ } from "./chunk-YOP55T6W.js";
91
93
  import {
92
94
  renderMathSvg
93
95
  } from "./chunk-LTX44BAE.js";
package/dist/scene-cli.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import{SCENE_LIMITS,renderSceneFrame,renderSceneVideo}from"./chunk-QVYHYC7T.js";import"./chunk-PSBF4TEK.js";import{readFile,stat}from"fs/promises";import{extname}from"path";async function main(){const args=process.argv.slice(2);if(args.length===1&&["--help","-h"].includes(args[0])){process.stdout.write("Usage: vizmatic-scene --input request.json --output scene.png|scene.mp4\nAll request time values are in seconds. Source is bare TSX, never a Node module.\nOptional JSON outputScale (0.25 to 1) reduces raster resolution; previewFps (MP4 only) reduces output fps while preserving logical scene globals. Metadata reports effective output dimensions and fps.\n");return}if(args.length!==4||args[0]!=="--input"||args[2]!=="--output"){throw new Error("Usage: vizmatic-scene --input request.json --output scene.png|scene.mp4")}const input=args[1],outputPath=args[3];const extension=extname(outputPath).toLowerCase();if(extension!==".png"&&extension!==".mp4")throw new Error("Scene output must be a PNG or MP4 file.");if((await stat(input)).size>SCENE_LIMITS.sourceBytes*6+32768)throw new Error("Scene request file exceeds its size limit.");const request=JSON.parse(await readFile(input,"utf8"));if(!request||typeof request!=="object"||Array.isArray(request))throw new Error("Scene request must be a JSON object.");const allowed=new Set(["source","width","height","duration","time","fps","theme","cues","seed","outputScale",...extension===".mp4"?["previewFps"]:[]]);if(Object.keys(request).some(name=>!allowed.has(name)))throw new Error("Scene request contains an unsupported field.");const options={...request,outputPath};const metadata=extension===".png"?await renderSceneFrame(options):await renderSceneVideo(options);process.stdout.write(`${JSON.stringify(metadata)}
2
+ import{SCENE_LIMITS,renderSceneFrame,renderSceneVideo}from"./chunk-6N6P2GJG.js";import"./chunk-PSBF4TEK.js";import{readFile,stat}from"fs/promises";import{extname}from"path";async function main(){const args=process.argv.slice(2);if(args.length===1&&["--help","-h"].includes(args[0])){process.stdout.write("Usage: vizmatic-scene --input request.json --output scene.png|scene.mp4\nAll request time values are in seconds. Source is bare TSX, never a Node module.\nOptional JSON outputScale (0.25 to 1) reduces raster resolution; previewFps (MP4 only) reduces output fps while preserving logical scene globals. Metadata reports effective output dimensions and fps.\n");return}if(args.length!==4||args[0]!=="--input"||args[2]!=="--output"){throw new Error("Usage: vizmatic-scene --input request.json --output scene.png|scene.mp4")}const input=args[1],outputPath=args[3];const extension=extname(outputPath).toLowerCase();if(extension!==".png"&&extension!==".mp4")throw new Error("Scene output must be a PNG or MP4 file.");if((await stat(input)).size>SCENE_LIMITS.sourceBytes*6+32768)throw new Error("Scene request file exceeds its size limit.");const request=JSON.parse(await readFile(input,"utf8"));if(!request||typeof request!=="object"||Array.isArray(request))throw new Error("Scene request must be a JSON object.");const allowed=new Set(["source","width","height","duration","time","fps","theme","cues","seed","outputScale",...extension===".mp4"?["previewFps"]:[]]);if(Object.keys(request).some(name=>!allowed.has(name)))throw new Error("Scene request contains an unsupported field.");const options={...request,outputPath};const metadata=extension===".png"?await renderSceneFrame(options):await renderSceneVideo(options);process.stdout.write(`${JSON.stringify(metadata)}
3
3
  `)}main().catch(error=>{process.stderr.write(`${error instanceof Error?error.message:"Scene rendering failed."}
4
4
  `.slice(0,4096));process.exitCode=1});
@@ -237,6 +237,7 @@ interface ImageOp {
237
237
  readonly image: StageImage;
238
238
  readonly matrix: Mat;
239
239
  readonly alpha: number;
240
+ readonly node?: Node;
240
241
  }
241
242
  type DrawOp = PathOp | ImageOp;
242
243
  interface Frame {
@@ -273,6 +274,44 @@ declare function frameInkBounds(frame: Frame): {
273
274
  height: number;
274
275
  } | null;
275
276
 
277
+ /** Encoded bytes and intrinsic dimensions, validated before a film uses them. */
278
+ interface ImageAsset {
279
+ readonly id?: string;
280
+ readonly src: string;
281
+ readonly mediaType: 'image/png' | 'image/jpeg' | 'image/gif';
282
+ readonly width: number;
283
+ readonly height: number;
284
+ readonly sha256: string;
285
+ }
286
+ interface ImageAssetOptions {
287
+ id?: string;
288
+ mediaType?: string;
289
+ sha256?: string;
290
+ /** Resolve a local filename relative to this directory in Node. */
291
+ baseDir?: string;
292
+ /** Expected intrinsic dimensions, such as those declared in an asset manifest. */
293
+ width?: number;
294
+ height?: number;
295
+ }
296
+ interface ImageCrop {
297
+ x: number;
298
+ y: number;
299
+ width: number;
300
+ height: number;
301
+ }
302
+ interface ImageFitOptions {
303
+ width?: number;
304
+ height?: number;
305
+ fit?: 'contain' | 'cover';
306
+ /** A region in intrinsic image pixels, before fitting the destination box. */
307
+ crop?: ImageCrop;
308
+ }
309
+ declare class ImageAssetError extends Error {
310
+ constructor(message: string);
311
+ }
312
+ /** Load once before authoring. No network request or file read occurs while painting. */
313
+ declare function resolveImageAsset(source: string | Uint8Array, options?: ImageAssetOptions): Promise<ImageAsset>;
314
+
276
315
  type BlendMode = 'normal' | 'screen' | 'multiply' | 'overlay';
277
316
  type Edge = 'left' | 'right' | 'top' | 'bottom';
278
317
  type Side = Edge | 'up' | 'down' | Vec;
@@ -308,10 +347,12 @@ interface NodeProps {
308
347
  image: StageImage | null;
309
348
  }
310
349
  interface StageImage {
311
- /** Browser-usable URL or data URL. */
350
+ /** Embedded raster, local filename or legacy URL, resolved before the film is rendered. */
312
351
  readonly src: string;
313
352
  readonly width: number;
314
353
  readonly height: number;
354
+ readonly crop?: Readonly<ImageCrop>;
355
+ readonly asset?: ImageAsset;
315
356
  }
316
357
  type PropName = keyof NodeProps;
317
358
  /**
@@ -410,6 +451,8 @@ declare function dynamic(build: (time: number) => Node | readonly Node[] | null)
410
451
 
411
452
  type Aspect = '16:9' | '9:16' | '1:1' | '4:3' | '21:9';
412
453
  interface FilmOptions {
454
+ /** Legacy URL images are allowed by default. Prepared image assets never use the network. */
455
+ imageNetwork?: 'allow' | 'deny';
413
456
  /** Lines and shapes run past the frame edges on purpose, as a warped grid does. Text is still checked. */
414
457
  bleed?: boolean;
415
458
  title?: string;
@@ -521,6 +564,7 @@ declare class Suspend {
521
564
  /** True for a Suspend thrown by any copy of the engine. */
522
565
  declare function isSuspend(error: unknown): error is Suspend;
523
566
  interface CompileOverrides {
567
+ imageNetwork?: 'allow' | 'deny';
524
568
  look?: LookName | Look;
525
569
  fps?: number;
526
570
  bloom?: number;
@@ -528,6 +572,9 @@ interface CompileOverrides {
528
572
  }
529
573
  /** A film ready to sample. `frame(t)` is pure: seek to any time, in any order. */
530
574
  declare class CompiledFilm {
575
+ private readonly allowImageNetwork;
576
+ private readonly imageAssets;
577
+ private readonly imageLoads;
531
578
  readonly width: number;
532
579
  readonly height: number;
533
580
  readonly fps: number;
@@ -546,6 +593,9 @@ declare class CompiledFilm {
546
593
  readonly stage: Stage;
547
594
  constructor(stage: Stage, options: FilmOptions, overrides: CompileOverrides);
548
595
  get frameCount(): number;
596
+ private prepareImage;
597
+ /** Preload static and keyed images, including those not visible in the first frame. */
598
+ preloadImages(): Promise<void>;
549
599
  /** The draw list at a time in seconds. May throw Suspend if a drawing needs a new asset. */
550
600
  frame(time: number): Frame;
551
601
  /** Standalone SVG for a time. */
@@ -815,7 +865,7 @@ declare function rect(width: number, height: number, style?: ShapeStyle & {
815
865
  }): Node;
816
866
  declare function polygon(points: readonly Vec[], style?: ShapeStyle): Node;
817
867
  declare function regularPolygon(sides: number, radius: number, style?: ShapeStyle): Node;
818
- interface ImageOptions {
868
+ interface ImageOptions extends ImageFitOptions {
819
869
  /** Width on the stage. With only one of width and height, the other keeps the picture's proportions. */
820
870
  width?: number;
821
871
  height?: number;
@@ -826,7 +876,7 @@ interface ImageOptions {
826
876
  * data URL. A data URL keeps a film in one file and renders the same in every tool.
827
877
  * It fades, moves, and scales like any node. Give `width`, `height`, or both.
828
878
  */
829
- declare function image(src: string, options?: ImageOptions): Node;
879
+ declare function image(src: string | ImageAsset, options?: ImageOptions): Node;
830
880
  /** A filled point. */
831
881
  declare function dot(radius?: number, color?: ColorInput, style?: ShapeStyle): Node;
832
882
  interface ArrowStyle extends ShapeStyle {
@@ -944,7 +994,7 @@ interface DecimalOptions {
944
994
  /** A number readout that follows a function of the timeline, drawn fresh each frame. */
945
995
  declare function decimal(read: () => number, options?: DecimalOptions): Node;
946
996
 
947
- type FilmDiagnosticCode = 'film.off_canvas' | 'film.text_overlap' | 'film.text_crossed' | 'film.missing_glyph' | 'film.blank';
997
+ type FilmDiagnosticCode = 'film.off_canvas' | 'film.text_overlap' | 'film.text_crossed' | 'film.missing_glyph' | 'film.blank' | 'film.image_asset';
948
998
  interface FilmDiagnostic {
949
999
  code: FilmDiagnosticCode;
950
1000
  severity: 'error' | 'warning';
@@ -2575,7 +2625,6 @@ declare class FilmPlayer {
2575
2625
  private currentTime;
2576
2626
  private playing;
2577
2627
  private scale;
2578
- private readonly images;
2579
2628
  private bloomLayers;
2580
2629
  private observer;
2581
2630
  speed: number;
@@ -2618,5 +2667,5 @@ declare function defineFilmElement(load: (src: string, options?: FilmLoadOptions
2618
2667
  /** Load a film module by URL and compile it once per look and background. */
2619
2668
  declare function loadFilm(src: string, options?: FilmLoadOptions): Promise<CompiledFilm>;
2620
2669
 
2621
- export { ArrayCells, Axes, Axes3D, BarChart, Callout, CodeBlock, CompiledFilm, ComplexPlane, Connector, Counter, Curve3D, EMPTY_BOUNDS, Epicycles, FilmPlayer, Graph, GraphEdge, GraphNode, GridPlane3D, Heatmap, Histogram, IDENTITY, InfoBox, LOOKS, Label3D, LabeledDot, Line3D, LineChart, MatrixNode, Narration, NeuralNet, Node, NumberLine, NumberPlane, Object3D, PieChart, Points3D, Scatter, Scene3D, SceneClock, Stage, StreamLines, Surface3D, Suspend, SvgNode, TexNode, TextNode, TokenRow, Trail3D, TreeGraph, Value, Vector3D, VectorField, View3D, along, angleMark, appear, apply, applyComplex, applyMatrix, arc, arcPath, areaUnder, arrayCells, arrow, attentionMatrix, axes, axes3d, barChart, blueprint, bounce, brace, braceLabel, buildOps, call, callout, captionLines, chalk, checkFilm, circle, circlePath, circumscribe, codeBlock, along$1 as colorAlong, compileFilm, complex, complexPlane, compose, concat, connector, countUp, counter, css, cubicBezier, curve, curve3d, curveThrough, dashedGuides, decimal, defineFilmElement, delay, donut, dot, draw, during, dynamic, easeInCubic, easeInExpo, easeInOutCubic, easeInOutQuint, easeInQuad, easeOutCubic, easeOutExpo, easeOutQuad, easeOutQuint, ellipse, epicycles, erase, fade, fadeIn, fadeOut, film, flash, fontFor, fourier, fourierPoint, frameInkBounds, frameToSvg, fromSvg, glyphPath, graph, gridPlane3d, group, grow, heatmap, highlightSweep, histogram, image, indicate, infoBox, invert, isFilm, isSuspend, label3d, labeledDot, lagged, legend, line, line3d, lineChart, linePath, linear, linearGradient, lingering, loadFilm, matScale, matrix, midnight, mixColor, morph, morphCode, morphMatching, moveTo, mul, narration, neon, neuralNet, notQuiteThere, numberLine, overshoot, paintFrame, paper, par, parametric, parametricPath, parametricSurface, parseColor, parseFont, parseSvgPath, pathBounds, pathLength, pathToD, pie, plane, point3d, pointAt, points3d, polyPath, polygon, polyline, pulse, radialGradient, ramp, recolor, rect, rectPath, regularPolygon, resolveLook, retime, reverseRing, riemann, rightAngle, ring, ringCenter, ringLength, ringThrough, ripple, rotate, runningStart, rushFrom, rushInto, samplePath, scaleBy, scatter, scene3d, secantLine, segmentCount, seq, setAssetBase, shake, shape, shift, signedArea, slowInto, smooth, smoothBy, smoothPath, smoother, sparkline, sphere, spin, spring, streamLines, subdivideEach, surface, surroundingBox, svgPath, swap, tangentAt, tangentLine, tex, text, thereAndBack, thereAndBackWithPause, to, toPaint, tokenize, tokens, traced, trail3d, transformPath, tree, trimPath, trimRing, typewriter, unionBounds, vanish, vector3d, vectorField, warp, warpPath, wiggle, wipe, write };
2622
- export type { AngleOptions, Anim, AnimContext, AnimOptions, AreaOptions, ArrayCellsOptions, ArrowStyle, Aspect, AttentionMatrixOptions, Axes3DOptions, AxesOptions, BarChartOptions, BarDatum, BlendMode, Bounds, BraceLabelOptions, CalloutOptions, Canvas2D, Caption, Chapter, ChartOptions, Clip, CodeBlockOptions, CodeToken, ColorInput, CompileOverrides, ComplexPlaneOptions, ConnectorEnd, ConnectorOptions, CounterOptions, DecimalOptions, DrawOp, Ease, Edge, EpicyclesOptions, FadeOptions, FieldFn, FilmCheckOptions, FilmCheckReport, FilmDefinition, FilmDiagnostic, FilmDiagnosticCode, FilmLoadOptions, FilmOptions, FontFamily, FontWeight, FourierTerm, Frame, FromSvgOptions, Gradient, GraphEdgeSpec, GraphNodeSpec, GraphOptions, GridPlaneOptions, HeatmapOptions, HighlightOptions, HistogramOptions, ImageOp, ImageOptions, InfoBoxOptions, InfoRow, LabeledDotOptions, LegendItem, LegendOptions, Line3DStyle, LineChartOptions, LineSeries, LoadedFont, Look, LookName, LookToken, Mat, MatrixOptions, NarrationBeat, NarrationOptions, NarrationScene, NarrationTiming, NarrationWord, NeuralNetOptions, NodeProps, NumberLineOptions, Paint, ParametricFn, Path, PathOp, PieDatum, PieOptions, PlacedBeat, PlaneOptions, PlayOptions, PlayerOptions, Points3DStyle, PropName, Rgba, RiemannOptions, Ring, ScatterOptions, ScatterPoint, Scene3DOptions, SecantOptions, ShapeStyle, Side, SparklineOptions, StageImage, StreamLinesOptions, SurfaceOptions, SurroundOptions, TangentOptions, Target, TexOptions, TextOptions, TokenKind, TokenSpec, TokensOptions, TracedOptions, TreeOptions, TreeSpec, TypewriterOptions, Vec, Vec3, VectorFieldOptions, WipeOptions };
2670
+ export { ArrayCells, Axes, Axes3D, BarChart, Callout, CodeBlock, CompiledFilm, ComplexPlane, Connector, Counter, Curve3D, EMPTY_BOUNDS, Epicycles, FilmPlayer, Graph, GraphEdge, GraphNode, GridPlane3D, Heatmap, Histogram, IDENTITY, ImageAssetError, InfoBox, LOOKS, Label3D, LabeledDot, Line3D, LineChart, MatrixNode, Narration, NeuralNet, Node, NumberLine, NumberPlane, Object3D, PieChart, Points3D, Scatter, Scene3D, SceneClock, Stage, StreamLines, Surface3D, Suspend, SvgNode, TexNode, TextNode, TokenRow, Trail3D, TreeGraph, Value, Vector3D, VectorField, View3D, along, angleMark, appear, apply, applyComplex, applyMatrix, arc, arcPath, areaUnder, arrayCells, arrow, attentionMatrix, axes, axes3d, barChart, blueprint, bounce, brace, braceLabel, buildOps, call, callout, captionLines, chalk, checkFilm, circle, circlePath, circumscribe, codeBlock, along$1 as colorAlong, compileFilm, complex, complexPlane, compose, concat, connector, countUp, counter, css, cubicBezier, curve, curve3d, curveThrough, dashedGuides, decimal, defineFilmElement, delay, donut, dot, draw, during, dynamic, easeInCubic, easeInExpo, easeInOutCubic, easeInOutQuint, easeInQuad, easeOutCubic, easeOutExpo, easeOutQuad, easeOutQuint, ellipse, epicycles, erase, fade, fadeIn, fadeOut, film, flash, fontFor, fourier, fourierPoint, frameInkBounds, frameToSvg, fromSvg, glyphPath, graph, gridPlane3d, group, grow, heatmap, highlightSweep, histogram, image, indicate, infoBox, invert, isFilm, isSuspend, label3d, labeledDot, lagged, legend, line, line3d, lineChart, linePath, linear, linearGradient, lingering, loadFilm, matScale, matrix, midnight, mixColor, morph, morphCode, morphMatching, moveTo, mul, narration, neon, neuralNet, notQuiteThere, numberLine, overshoot, paintFrame, paper, par, parametric, parametricPath, parametricSurface, parseColor, parseFont, parseSvgPath, pathBounds, pathLength, pathToD, pie, plane, point3d, pointAt, points3d, polyPath, polygon, polyline, pulse, radialGradient, ramp, recolor, rect, rectPath, regularPolygon, resolveImageAsset, resolveLook, retime, reverseRing, riemann, rightAngle, ring, ringCenter, ringLength, ringThrough, ripple, rotate, runningStart, rushFrom, rushInto, samplePath, scaleBy, scatter, scene3d, secantLine, segmentCount, seq, setAssetBase, shake, shape, shift, signedArea, slowInto, smooth, smoothBy, smoothPath, smoother, sparkline, sphere, spin, spring, streamLines, subdivideEach, surface, surroundingBox, svgPath, swap, tangentAt, tangentLine, tex, text, thereAndBack, thereAndBackWithPause, to, toPaint, tokenize, tokens, traced, trail3d, transformPath, tree, trimPath, trimRing, typewriter, unionBounds, vanish, vector3d, vectorField, warp, warpPath, wiggle, wipe, write };
2671
+ export type { AngleOptions, Anim, AnimContext, AnimOptions, AreaOptions, ArrayCellsOptions, ArrowStyle, Aspect, AttentionMatrixOptions, Axes3DOptions, AxesOptions, BarChartOptions, BarDatum, BlendMode, Bounds, BraceLabelOptions, CalloutOptions, Canvas2D, Caption, Chapter, ChartOptions, Clip, CodeBlockOptions, CodeToken, ColorInput, CompileOverrides, ComplexPlaneOptions, ConnectorEnd, ConnectorOptions, CounterOptions, DecimalOptions, DrawOp, Ease, Edge, EpicyclesOptions, FadeOptions, FieldFn, FilmCheckOptions, FilmCheckReport, FilmDefinition, FilmDiagnostic, FilmDiagnosticCode, FilmLoadOptions, FilmOptions, FontFamily, FontWeight, FourierTerm, Frame, FromSvgOptions, Gradient, GraphEdgeSpec, GraphNodeSpec, GraphOptions, GridPlaneOptions, HeatmapOptions, HighlightOptions, HistogramOptions, ImageAsset, ImageAssetOptions, ImageCrop, ImageFitOptions, ImageOp, ImageOptions, InfoBoxOptions, InfoRow, LabeledDotOptions, LegendItem, LegendOptions, Line3DStyle, LineChartOptions, LineSeries, LoadedFont, Look, LookName, LookToken, Mat, MatrixOptions, NarrationBeat, NarrationOptions, NarrationScene, NarrationTiming, NarrationWord, NeuralNetOptions, NodeProps, NumberLineOptions, Paint, ParametricFn, Path, PathOp, PieDatum, PieOptions, PlacedBeat, PlaneOptions, PlayOptions, PlayerOptions, Points3DStyle, PropName, Rgba, RiemannOptions, Ring, ScatterOptions, ScatterPoint, Scene3DOptions, SecantOptions, ShapeStyle, Side, SparklineOptions, StageImage, StreamLinesOptions, SurfaceOptions, SurroundOptions, TangentOptions, Target, TexOptions, TextOptions, TokenKind, TokenSpec, TokensOptions, TracedOptions, TreeOptions, TreeSpec, TypewriterOptions, Vec, Vec3, VectorFieldOptions, WipeOptions };