1use serde_json::{Value, json};
6use ultrafast_graph::{Document, Param};
7
8type P = (&'static str, &'static str, &'static str, &'static str);
10
11const PLACEMENT: &[P] = &[
12 ("position", "vec2", "[0,0]", "where the anchor lands, px"),
13 ("anchor", "vec2", "[0,0]", "pivot in the node's own space, px"),
14 ("scale", "vec2|number", "[1,1]", "scale around the anchor"),
15 ("rotation", "number", "0", "degrees, clockwise"),
16];
17
18const STROKE: &[P] = &[
19 ("stroke", "number", "0", "stroke width px; 0 fills"),
20 ("join", "enum(miter|round|bevel)", "miter", "stroke joins"),
21 ("cap", "enum(butt|round|square)", "butt", "stroke caps"),
22 ("dash", "number[]", "", "dash pattern [on, off, ...] px"),
23 ("dash_offset", "number", "0", "dash phase px"),
24];
25
26struct OpSchema {
27 name: &'static str,
28 summary: &'static str,
29 ports: &'static [&'static str],
30 params: &'static [P],
31 extra: &'static [&'static [P]],
33}
34
35const GRADIENT: &[P] = &[
36 ("kind", "enum(linear|radial|conic)", "linear", "gradient shape"),
37 ("a", "color", "", "start color (with b: a two-stop gradient)"),
38 ("b", "color", "", "end color"),
39 (
40 "stops",
41 "text|number[]",
42 "",
43 "\"0:#ff0000, 1:#0000ff\" or [pos,r,g,b,a,...], up to 8",
44 ),
45 (
46 "space",
47 "enum(linear|srgb)",
48 "linear",
49 "interpolation space; srgb matches CSS/Figma",
50 ),
51 ("start", "vec2", "[0,0]", "linear: start point px"),
52 ("end", "vec2", "[0,h]", "linear: end point px"),
53 ("center", "vec2", "frame center", "radial/conic center px"),
54 ("radius", "number", "max(w,h)/2", "radial radius px"),
55 ("angle", "number", "0", "conic start angle, degrees"),
56];
57
58const SCHEMAS: &[OpSchema] = &[
59 OpSchema {
60 name: "solid",
61 summary: "flat color",
62 ports: &[],
63 params: &[("color", "color", "#000000", "fill color")],
64 extra: &[],
65 },
66 OpSchema {
67 name: "gradient",
68 summary: "linear, radial or conic gradient",
69 ports: &[],
70 params: GRADIENT,
71 extra: &[],
72 },
73 OpSchema {
74 name: "shape",
75 summary: "analytic rectangle / rounded rect / ellipse (SDF, antialiased)",
76 ports: &[],
77 params: &[
78 ("kind", "enum(rect|ellipse|circle)", "rect", "shape"),
79 ("color", "color", "#ffffff", "fill (or stroke) color"),
80 ("center", "vec2", "frame center", "center px"),
81 ("size", "vec2", "[w/4,w/4]", "width and height px"),
82 ("radius", "number", "0", "corner radius px"),
83 ("rotation", "number", "0", "degrees"),
84 (
85 "scale",
86 "number|vec2",
87 "1",
88 "scale about the center (size, corners and stroke)",
89 ),
90 ("opacity", "number", "1", "0..1, fades the shape"),
91 ("stroke", "number", "0", "outline width px; 0 fills"),
92 ("softness", "number", "1", "edge softness in output pixels"),
93 ],
94 extra: &[],
95 },
96 OpSchema {
97 name: "checker",
98 summary: "checkerboard",
99 ports: &[],
100 params: &[
101 ("a", "color", "#333333", "first cell"),
102 ("b", "color", "#666666", "second cell"),
103 ("size", "number", "32", "cell px"),
104 ],
105 extra: &[],
106 },
107 OpSchema {
108 name: "noise",
109 summary: "fractal simplex noise between two colors",
110 ports: &[],
111 params: &[
112 ("a", "color", "#000000", "low color"),
113 ("b", "color", "#ffffff", "high color"),
114 ("scale", "vec2|number", "[200,200]", "px per noise cell"),
115 ("offset", "vec2", "[0,0]", "pan px"),
116 ("evolution", "number", "0", "third noise dimension; animate it"),
117 ("octaves", "number", "4", "1..8"),
118 ],
119 extra: &[],
120 },
121 OpSchema {
122 name: "image",
123 summary: "still image or image sequence",
124 ports: &[],
125 params: &[
126 (
127 "src",
128 "text",
129 "",
130 "file path relative to the document; {frame} / {frame:05} for sequences",
131 ),
132 (
133 "fit",
134 "enum(contain|cover|fill|none)",
135 "contain",
136 "placement in the frame, or in `rect` (cover there by default); only fill stretches",
137 ),
138 (
139 "rect",
140 "vec4",
141 "",
142 "[x,y,w,h] px box the picture goes in, by `fit`; it keeps its aspect ratio",
143 ),
144 ("opacity", "number", "1", "0..1"),
145 (
146 "space",
147 "enum(linear|srgb)",
148 "linear",
149 "interpolation space when scaled; srgb filters the encoded values as browsers do",
150 ),
151 ("fps", "number", "document fps", "sequence frame rate"),
152 ("first_frame", "number", "0", "sequence frame number at local time 0"),
153 ],
154 extra: &[],
155 },
156 OpSchema {
157 name: "video",
158 summary: "video clip, hardware decoded",
159 ports: &[],
160 params: &[
161 ("src", "text", "", "file path"),
162 (
163 "fit",
164 "enum(contain|cover|fill|none)",
165 "contain",
166 "placement in the frame, or in `rect` (cover there by default); only fill stretches",
167 ),
168 (
169 "rect",
170 "vec4",
171 "",
172 "[x,y,w,h] px box the footage goes in, by `fit`; it keeps its aspect ratio",
173 ),
174 ("opacity", "number", "1", "0..1"),
175 (
176 "space",
177 "enum(linear|srgb)",
178 "linear",
179 "interpolation space when scaled; srgb filters the encoded values as browsers do",
180 ),
181 ("start", "number", "0", "source seconds at local time 0"),
182 ("speed", "number", "1", "playback rate"),
183 (
184 "loop",
185 "bool",
186 "false",
187 "wrap at the clip's end (else hold the last frame)",
188 ),
189 (
190 "time",
191 "number",
192 "",
193 "explicit source time (animate for time remapping)",
194 ),
195 ],
196 extra: &[],
197 },
198 OpSchema {
199 name: "path",
200 summary: "vector path (SVG data or preset), GPU exact-coverage raster",
201 ports: &[],
202 params: &[
203 (
204 "to",
205 "text",
206 "",
207 "SVG path data to morph toward; several separated by | to morph through each in turn",
208 ),
209 (
210 "morph",
211 "number",
212 "0",
213 "0 = this path, 1 = `to` (with several targets, 2 = the second, ...); animate it",
214 ),
215 ("d", "text", "", "SVG path data"),
216 (
217 "kind",
218 "enum(star|polygon|circle|line|polyline|polygon_points)",
219 "",
220 "preset instead of d",
221 ),
222 ("center", "vec2", "frame center", "preset center"),
223 ("radius", "number", "h/4", "preset radius"),
224 ("sides", "number", "5 / 6", "star points / polygon sides"),
225 ("inner_radius", "number", "0.45 r", "star inner radius"),
226 (
227 "points",
228 "number[]",
229 "",
230 "flat [x0,y0,x1,y1,...] for line/polyline/polygon_points",
231 ),
232 ("color", "color", "#ffffff", "paint"),
233 (
234 "opacity",
235 "number",
236 "1",
237 "0..1, fades the whole node (animate for fades)",
238 ),
239 ("fill_rule", "enum(nonzero|evenodd)", "nonzero", "fill rule"),
240 ("trim_start", "number", "0", "0..1 of length"),
241 ("trim_end", "number", "1", "0..1 of length (animate for draw-on)"),
242 ],
243 extra: &[STROKE, PLACEMENT],
244 },
245 OpSchema {
246 name: "text",
247 summary: "shaped text, GPU exact-coverage raster",
248 ports: &[],
249 params: &[
250 (
251 "text",
252 "text",
253 "",
254 "content; \\n breaks lines; *word* is emphasis (em_ params), [words]{color=#ffd23f highlight=#ff4d6d} styles a span",
255 ),
256 ("font", "text", "Helvetica Neue", "family name or font file path"),
257 ("weight", "number", "400", "100..900"),
258 ("style", "enum(normal|italic)", "normal", "style"),
259 ("size", "number", "64", "px"),
260 ("color", "color", "#ffffff", "paint"),
261 (
262 "opacity",
263 "number",
264 "1",
265 "0..1, fades the whole node (animate for fades)",
266 ),
267 (
268 "align",
269 "enum(left|center|right)",
270 "left",
271 "horizontal anchor of each line",
272 ),
273 (
274 "valign",
275 "enum(top|middle|baseline|bottom)",
276 "top",
277 "vertical anchor of the block",
278 ),
279 ("width", "number", "", "wrap width px"),
280 ("line_height", "number", "1.2", "multiple of size"),
281 ("tracking", "number", "0", "extra px between glyphs"),
282 ("features", "text", "", "OpenType features, e.g. \"liga=0,ss01\""),
283 (
284 "variations",
285 "text",
286 "",
287 "variable-font axes, e.g. \"wdth=80, opsz=144\" (weight drives wght; opsz follows size unless set)",
288 ),
289 (
290 "axis_<tag>",
291 "number",
292 "axis default",
293 "one variable-font axis, animatable: axis_wdth, axis_SOFT",
294 ),
295 (
296 "stagger",
297 "number",
298 "0",
299 "seconds between glyphs for the glyph_* animators",
300 ),
301 (
302 "stagger_order",
303 "enum(forward|reverse|center|random)",
304 "forward",
305 "which glyphs go first",
306 ),
307 (
308 "glyph_offset",
309 "vec2",
310 "[0,0]",
311 "per-glyph offset px, keyed in glyph time (t - stagger * order)",
312 ),
313 (
314 "glyph_scale",
315 "vec2",
316 "[1,1]",
317 "per-glyph scale about the glyph's center, glyph time",
318 ),
319 (
320 "glyph_rotation",
321 "number",
322 "0",
323 "per-glyph rotation degrees, glyph time",
324 ),
325 ("glyph_opacity", "number", "1", "per-glyph opacity, glyph time"),
326 ("reveal", "number", "all", "glyphs visible (fractional fades)"),
327 ("reveal_softness", "number", "1", "glyphs the reveal fade spans"),
328 ("reveal_offset", "vec2", "[0,0]", "offset of not-yet-revealed glyphs px"),
329 ("fill_rule", "enum(nonzero|evenodd)", "nonzero", "fill rule"),
330 (
331 "skim",
332 "bool",
333 "false",
334 "glanced at, not read (code, data labels): ultrafast review skips its reading-time check",
335 ),
336 (
337 "markup",
338 "bool",
339 "true",
340 "parse inline styling in text: *emphasis* and [words]{color=#ffd23f weight=800 font=\"ultrafast:serif\" style=italic size=80 highlight=#ff4d6d underline=4 underline_color=#fff rise=10 draw=1}",
341 ),
342 ("em_color", "color", "text color", "color of *emphasis*"),
343 (
344 "em_font",
345 "text",
346 "font",
347 "face of *emphasis* (e.g. ultrafast:serif for a serif accent)",
348 ),
349 ("em_weight", "number", "weight", "weight of *emphasis*"),
350 (
351 "em_style",
352 "enum(normal|italic)",
353 "italic when no em_ param is set",
354 "style of *emphasis* (italic is synthesized for faces without one)",
355 ),
356 ("em_size", "number", "size", "size px of *emphasis*"),
357 ("em_highlight", "color", "none", "marker box behind *emphasis*"),
358 ("em_underline", "number", "0", "underline thickness px under *emphasis*"),
359 ("em_underline_color", "color", "em_color", "underline color"),
360 ("em_rise", "number", "0", "baseline shift px of *emphasis* (up)"),
361 (
362 "em_draw",
363 "number",
364 "1",
365 "share of the emphasis highlights and underlines drawn, 0..1, one stroke across lines in reading order (animate it)",
366 ),
367 (
368 "on_path",
369 "text",
370 "",
371 "SVG path data the text follows (closed paths wrap: circular badges); align picks start, middle or end",
372 ),
373 (
374 "path_offset",
375 "number",
376 "0",
377 "px along the path; animate it to run text along",
378 ),
379 (
380 "number",
381 "number",
382 "",
383 "show this value instead of text (animate it: counters)",
384 ),
385 ("decimals", "number", "0", "digits after the point for number"),
386 ("thousands", "text", ",", "group separator for number (\"\" for none)"),
387 ("prefix", "text", "", "before number, e.g. $"),
388 ("suffix", "text", "", "after number, e.g. % or k"),
389 (
390 "scramble",
391 "number",
392 "",
393 "decoding text: animate 0 (all random) to 1 (the text)",
394 ),
395 (
396 "scramble_chars",
397 "text",
398 "A-Z, 0-9, symbols",
399 "characters the undecoded ones cycle through",
400 ),
401 ],
402 extra: &[STROKE, PLACEMENT],
403 },
404 OpSchema {
405 name: "shader",
406 summary: "agent-written Slang: float4 shade(float2 pos, float px)",
407 ports: &["in0", "in1", "in2", "in3"],
408 params: &[
409 (
410 "resolution",
411 "number",
412 "1",
413 "render at this fraction of the frame size and upscale (soft, costly looks; write shaders with pos/size())",
414 ),
415 (
416 "code",
417 "text",
418 "",
419 "Slang source defining shade(); `static const` tables of 64+ numbers are read from the params (editing their values compiles nothing)",
420 ),
421 ("u", "number[]", "", "up to 16 values, param(i)"),
422 ("u0", "number", "", "u0..u15 individually (animatable)"),
423 (
424 "motion_blur",
425 "bool",
426 "false",
427 "true: the format's motion blur samples its clock and animated u values (a shader that moves things); otherwise it holds at the frame's time",
428 ),
429 ],
430 extra: &[],
431 },
432 OpSchema {
433 name: "opacity",
434 summary: "multiply alpha",
435 ports: &["source"],
436 params: &[("opacity", "number", "1", "0..1")],
437 extra: &[],
438 },
439 OpSchema {
440 name: "over",
441 summary: "fg over bg (Porter-Duff)",
442 ports: &["fg", "bg"],
443 params: &[
444 ("opacity", "number", "1", "fg opacity"),
445 ("space", "enum(linear|srgb)", "linear", "blend space"),
446 ],
447 extra: &[],
448 },
449 OpSchema {
450 name: "blend",
451 summary: "blend modes (W3C)",
452 ports: &["fg", "bg"],
453 params: &[
454 (
455 "mode",
456 "enum(normal|multiply|screen|overlay|darken|lighten|color_dodge|color_burn|hard_light|soft_light|difference|exclusion|hue|saturation|color|luminosity|add|subtract|divide)",
457 "normal",
458 "mode",
459 ),
460 ("opacity", "number", "1", "fg opacity"),
461 ("space", "enum(linear|srgb)", "linear", "blend space"),
462 ],
463 extra: &[],
464 },
465 OpSchema {
466 name: "composite",
467 summary: "Porter-Duff operators",
468 ports: &["fg", "bg"],
469 params: &[("operator", "enum(in|out|atop|xor|plus|over)", "over", "operator")],
470 extra: &[],
471 },
472 OpSchema {
473 name: "mask",
474 summary: "track matte",
475 ports: &["source", "matte"],
476 params: &[(
477 "mode",
478 "enum(alpha|alpha_inverted|luma|luma_inverted)",
479 "alpha",
480 "matte channel",
481 )],
482 extra: &[],
483 },
484 OpSchema {
485 name: "mix",
486 summary: "crossfade",
487 ports: &["a", "b"],
488 params: &[("t", "number", "0.5", "0 = a, 1 = b")],
489 extra: &[],
490 },
491 OpSchema {
492 name: "adjust",
493 summary: "exposure, contrast, saturation, hue, brightness, gamma",
494 ports: &["source"],
495 params: &[
496 ("exposure", "number", "0", "stops (linear light)"),
497 ("contrast", "number", "1", "around mid grey"),
498 ("saturation", "number", "1", "0 = grey"),
499 ("hue", "number", "0", "degrees"),
500 ("brightness", "number", "0", "offset"),
501 ("gamma", "number", "1", "gamma"),
502 ],
503 extra: &[],
504 },
505 OpSchema {
506 name: "levels",
507 summary: "input/output levels with gamma",
508 ports: &["source"],
509 params: &[
510 ("in_black", "number", "0", ""),
511 ("in_white", "number", "1", ""),
512 ("gamma", "number", "1", ""),
513 ("out_black", "number", "0", ""),
514 ("out_white", "number", "1", ""),
515 ],
516 extra: &[],
517 },
518 OpSchema {
519 name: "color_matrix",
520 summary: "4x5 matrix on straight linear RGBA",
521 ports: &["source"],
522 params: &[("matrix", "number[]", "identity", "20 numbers, row-major")],
523 extra: &[],
524 },
525 OpSchema {
526 name: "lut",
527 summary: "3D LUT color grade (.cube)",
528 ports: &["source"],
529 params: &[
530 ("src", "text", "", ".cube file (3D LUT)"),
531 ("amount", "number", "1", "0..1 mix with the ungraded image"),
532 (
533 "space",
534 "enum(srgb|linear)",
535 "srgb",
536 "what the LUT expects as input (most grading LUTs: srgb)",
537 ),
538 ],
539 extra: &[],
540 },
541 OpSchema {
542 name: "invert",
543 summary: "invert colors",
544 ports: &["source"],
545 params: &[("amount", "number", "1", "0..1")],
546 extra: &[],
547 },
548 OpSchema {
549 name: "tint",
550 summary: "map luminance between two colors",
551 ports: &["source"],
552 params: &[
553 ("dark", "color", "#000000", "shadows"),
554 ("light", "color", "#ffffff", "highlights"),
555 ],
556 extra: &[],
557 },
558 OpSchema {
559 name: "threshold",
560 summary: "luminance threshold",
561 ports: &["source"],
562 params: &[("level", "number", "0.5", ""), ("softness", "number", "0.01", "")],
563 extra: &[],
564 },
565 OpSchema {
566 name: "crop",
567 summary: "keep a rectangle",
568 ports: &["source"],
569 params: &[
570 ("rect", "vec4", "frame", "[x,y,w,h] px"),
571 ("softness", "number", "1", "edge px"),
572 ],
573 extra: &[],
574 },
575 OpSchema {
576 name: "transform",
577 summary: "2D transform (absorbed into paths/text for sharpness)",
578 ports: &["source"],
579 params: &[
580 ("position", "vec2", "frame center", "where the anchor lands"),
581 ("anchor", "vec2", "frame center", "pivot"),
582 ("scale", "vec2|number", "[1,1]", "scale"),
583 ("rotation", "number", "0", "degrees"),
584 ("skew", "number", "0", "degrees"),
585 ],
586 extra: &[],
587 },
588 OpSchema {
589 name: "corner_pin",
590 summary: "perspective: map the frame (or source_rect) to four corners",
591 ports: &["source"],
592 params: &[
593 ("corners", "number[]", "frame corners", "[tl, tr, br, bl] as 8 numbers"),
594 ("source_rect", "vec4", "frame", "[x,y,w,h] of the source mapped"),
595 ],
596 extra: &[],
597 },
598 OpSchema {
599 name: "wave",
600 summary: "sine displacement",
601 ports: &["source"],
602 params: &[
603 ("amplitude", "number", "10", "px"),
604 ("wavelength", "number", "100", "px"),
605 ("phase", "number", "0", "degrees"),
606 ("direction", "number", "0", "degrees"),
607 ],
608 extra: &[],
609 },
610 OpSchema {
611 name: "twirl",
612 summary: "swirl around a center",
613 ports: &["source"],
614 params: &[
615 ("center", "vec2", "frame center", ""),
616 ("radius", "number", "min(w,h)/2", ""),
617 ("angle", "number", "90", "degrees"),
618 ],
619 extra: &[],
620 },
621 OpSchema {
622 name: "tile",
623 summary: "repeat a region",
624 ports: &["source"],
625 params: &[("origin", "vec2", "[0,0]", ""), ("size", "vec2", "frame", "")],
626 extra: &[],
627 },
628 OpSchema {
629 name: "displace",
630 summary: "displace source by a map's red/green",
631 ports: &["source", "map"],
632 params: &[("amount", "vec2", "[20,20]", "px")],
633 extra: &[],
634 },
635 OpSchema {
636 name: "blur",
637 summary: "gaussian blur",
638 ports: &["source"],
639 params: &[("radius", "number", "8", "sigma px")],
640 extra: &[],
641 },
642 OpSchema {
643 name: "mesh",
644 summary: "3D mesh (scene object for render3d)",
645 ports: &["texture"],
646 params: &[
647 (
648 "primitive",
649 "enum(cube|plane|sphere|cylinder|cone|torus|text|path)",
650 "cube",
651 "unit-sized primitive, or extruded text / SVG path",
652 ),
653 ("text", "text", "", "primitive text: content"),
654 ("font", "text", "Helvetica Neue", "primitive text: family or file"),
655 ("weight", "number", "400", "primitive text: weight"),
656 ("style", "enum(normal|italic)", "normal", "primitive text: style"),
657 ("size", "number", "1", "primitive text: size in world units"),
658 (
659 "align",
660 "enum(left|center|right)",
661 "center",
662 "primitive text: alignment",
663 ),
664 (
665 "tracking",
666 "number",
667 "0",
668 "primitive text: extra spacing (px at 100 px/unit)",
669 ),
670 ("line_height", "number", "1.2", "primitive text: multiple of size"),
671 ("d", "text", "", "primitive path: SVG path data"),
672 ("units", "number", "100", "primitive path: path px per world unit"),
673 ("depth", "number", "0.25", "extrusion depth, world units"),
674 (
675 "bevel",
676 "number",
677 "0",
678 "text/path: 45-degree chamfer on both rims, world units",
679 ),
680 ("src", "text", "", ".gltf/.glb file instead of a primitive"),
681 ("segments", "number", "32", "tessellation"),
682 ("position", "vec3", "[0,0,0]", ""),
683 ("rotation", "vec3", "[0,0,0]", "degrees, X then Y then Z"),
684 ("scale", "vec3|number", "[1,1,1]", ""),
685 ("color", "color", "#cccccc", "base color"),
686 ("metallic", "number", "0", "0..1"),
687 ("roughness", "number", "0.5", "0..1"),
688 ("emissive", "color", "#000000", "emitted light"),
689 (
690 "transmission",
691 "number",
692 "0",
693 "glass: 0..1 of the scene behind seen through it (refracted)",
694 ),
695 (
696 "ior",
697 "number",
698 "1.45",
699 "glass: index of refraction (water 1.33, glass 1.5, diamond 2.4)",
700 ),
701 (
702 "thickness",
703 "number",
704 "0.5",
705 "glass: how far refracted rays travel inside, world units (more bends more)",
706 ),
707 ("dispersion", "number", "0", "glass: color splitting (try 1..2)"),
708 ("opacity", "number", "1", "0..1"),
709 ],
710 extra: &[],
711 },
712 OpSchema {
713 name: "light",
714 summary: "3D light (scene object)",
715 ports: &[],
716 params: &[
717 ("kind", "enum(directional|point)", "directional", ""),
718 ("direction", "vec3", "[0.4,0.8,0.6]", "toward the light (directional)"),
719 ("position", "vec3", "[0,2,2]", "point light position"),
720 ("color", "color", "#ffffff", ""),
721 ("intensity", "number", "3", ""),
722 ],
723 extra: &[],
724 },
725 OpSchema {
726 name: "camera",
727 summary: "3D camera (scene object)",
728 ports: &[],
729 params: &[
730 ("position", "vec3", "[0,0,5]", ""),
731 (
732 "orbit",
733 "vec3",
734 "",
735 "[azimuth, elevation, distance] around target (overrides position)",
736 ),
737 ("target", "vec3", "[0,0,0]", ""),
738 ("up", "vec3", "[0,1,0]", ""),
739 ("fov", "number", "45", "vertical, degrees"),
740 ("near", "number", "0.1", ""),
741 ("far", "number", "1000", ""),
742 ],
743 extra: &[],
744 },
745 OpSchema {
746 name: "render3d",
747 summary: "renders connected meshes/lights/camera (any port names; camera on `camera`)",
748 ports: &["*"],
749 params: &[
750 ("ambient", "number", "0.35", "hemisphere light intensity"),
751 ("sky", "color", "#e6f2ff", "ambient from above"),
752 ("ground", "color", "#5a4d47", "ambient from below"),
753 ("background", "color", "transparent", "clear color"),
754 (
755 "shadows",
756 "bool",
757 "true",
758 "the first directional light casts a shadow map",
759 ),
760 ("shadow_strength", "number", "0.85", "0 = no darkening, 1 = full"),
761 (
762 "shadow_bias",
763 "number",
764 "1",
765 "depth bias in shadow-map texels (raise if surfaces self-shadow)",
766 ),
767 (
768 "environment_intensity",
769 "number",
770 "1",
771 "scale of the image on the `environment` port (equirectangular; lights and reflects)",
772 ),
773 (
774 "environment_rotation",
775 "number",
776 "0",
777 "turns the environment around +y, degrees",
778 ),
779 (
780 "fog",
781 "vec2",
782 "",
783 "[start, end] distance from the camera where surfaces fade into fog_color",
784 ),
785 ("fog_color", "color", "background", "fog color"),
786 (
787 "aperture",
788 "number",
789 "0",
790 "depth of field: blur radius px far from focus (0 = off)",
791 ),
792 (
793 "focus",
794 "number",
795 "camera to target",
796 "depth of field: in-focus distance, world units",
797 ),
798 ],
799 extra: &[],
800 },
801 OpSchema {
802 name: "swarm",
803 summary: "particles that assemble into text (or a path) and scatter: progress 0..1",
804 ports: &[],
805 params: &[
806 ("text", "text", "", "what the particles form (or `d`)"),
807 (
808 "d",
809 "text",
810 "",
811 "SVG path data to form instead of text (offset by position)",
812 ),
813 ("font", "text", "Helvetica Neue", "font family or file"),
814 ("weight", "number", "400", "font weight"),
815 ("style", "enum(normal|italic)", "normal", "font style"),
816 ("tracking", "number", "0", "extra px between glyphs"),
817 ("variations", "text", "", "variable-font axes, as on text"),
818 (
819 "axis_<tag>",
820 "number",
821 "axis default",
822 "one variable-font axis, as on text",
823 ),
824 ("size", "number", "64", "text size px"),
825 ("position", "vec2", "[0,0]", "text position (as `text`)"),
826 ("align", "enum(left|center|right)", "left", "text alignment"),
827 (
828 "valign",
829 "enum(top|middle|baseline|bottom)",
830 "top",
831 "vertical alignment",
832 ),
833 ("count", "number", "4000", "particles"),
834 ("progress", "number", "1", "0 scattered, 1 formed; animate it"),
835 (
836 "stagger",
837 "number",
838 "0.5",
839 "spread of arrival times (fraction of progress)",
840 ),
841 ("scatter", "number", "700", "how far particles start from home, px"),
842 ("origin", "vec2", "", "start every particle from this point instead"),
843 ("turbulence", "number", "40", "drift amplitude while away from home, px"),
844 ("particle_size", "vec2", "[2,3]", "size scattered and formed, px"),
845 ("color", "color", "#ffffff", "color when formed"),
846 ("color_scatter", "color", "color", "color when scattered"),
847 ("shimmer", "number", "0", "0..1 twinkle"),
848 ("stretch", "number", "0", "streak along travel while moving"),
849 ("seed", "number", "1", "random seed"),
850 ("blend", "enum(over|add)", "over", "how particles combine"),
851 ],
852 extra: &[],
853 },
854 OpSchema {
855 name: "particles",
856 summary: "deterministic particle system (closed form: scrub anywhere), drawn as sprites",
857 ports: &["sprite"],
858 params: &[
859 ("seed", "number", "1", "random seed"),
860 ("rate", "number", "60", "particles emitted per second"),
861 ("max", "number", "5000", "cap on particles alive"),
862 ("life", "vec2", "[1.5,2.5]", "lifetime range, s"),
863 ("position", "vec2", "[960,540]", "emitter center px"),
864 ("emitter_size", "vec2", "[0,0]", "emitter rectangle px"),
865 ("direction", "number", "-90", "degrees (-90 = up)"),
866 ("spread", "number", "30", "cone angle, degrees"),
867 ("speed", "vec2", "[200,400]", "initial speed range, px/s"),
868 ("gravity", "vec2", "[0,300]", "px/s^2"),
869 ("drag", "number", "0", "linear drag, 1/s"),
870 ("size", "vec2", "[8,2]", "size at birth and death, px"),
871 ("size_jitter", "number", "0.3", "0..1 random size reduction"),
872 ("spin", "vec2", "[0,0]", "rotation speed range, deg/s"),
873 ("color_start", "color", "#ffffff", "color at birth"),
874 ("color_end", "color", "color_start", "color at death"),
875 ("fade_in", "number", "0.1", "fraction of life fading in"),
876 ("fade_out", "number", "0.3", "fraction of life fading out"),
877 (
878 "shape",
879 "enum(circle|square|spark|sprite)",
880 "circle",
881 "sprite uses the `sprite` input",
882 ),
883 ("stretch", "number", "0", "spark stretch along velocity"),
884 ("blend", "enum(over|add)", "over", "how particles combine"),
885 ("emit_start", "number", "0", "emission start, s (negative pre-warms)"),
886 ("emit_end", "number", "forever", "emission end, s"),
887 ],
888 extra: &[],
889 },
890 OpSchema {
891 name: "fluid",
892 summary: "ink/smoke simulation: `dye` pours color in, `stir` pushes it around; stepped once per frame (exact on export, seekable)",
893 ports: &["dye", "stir"],
894 params: &[
895 (
896 "start",
897 "number",
898 "0",
899 "local time the simulation starts (blank before)",
900 ),
901 (
902 "emit",
903 "number",
904 "6",
905 "how fast `dye` replaces the fluid where it is, per s",
906 ),
907 ("dissipation", "number", "0.15", "dye fade per s"),
908 ("velocity_dissipation", "number", "0.4", "motion fade per s"),
909 (
910 "vorticity",
911 "number",
912 "4",
913 "keeps eddies curling (0 = silky, 10+ = churning)",
914 ),
915 (
916 "turbulence",
917 "number",
918 "0",
919 "curl-noise stirring, px/s^2 (try 400..3000)",
920 ),
921 ("turbulence_scale", "number", "260", "size of the noise eddies, px"),
922 ("wind", "vec2", "[0,0]", "drift of everything, px/s"),
923 ("buoyancy", "number", "0", "dye rises (smoke), px/s^2 per unit alpha"),
924 ("stir", "number", "2500", "push away from the edges of the `stir` image"),
925 ("swirl", "number", "0", "spin around the edges of the `stir` image"),
926 ("resolution", "number", "0.25", "velocity grid, fraction of the frame"),
927 ("dye_resolution", "number", "0.5", "dye grid, fraction of the frame"),
928 (
929 "pressure_iterations",
930 "number",
931 "24",
932 "incompressibility solver iterations",
933 ),
934 ("substeps", "number", "1", "steps per frame (1..8)"),
935 ("seed", "number", "1", "turbulence pattern"),
936 ],
937 extra: &[],
938 },
939 OpSchema {
940 name: "feedback",
941 summary: "agent Slang stepped once per frame on its own previous result: float4 update(float2 pos, float px) with prev(pos), input(i,pos), dt(), step_index()",
942 ports: &["in0", "in1", "in2", "in3"],
943 params: &[
944 ("code", "text", "", "Slang source defining update()"),
945 (
946 "start",
947 "number",
948 "0",
949 "local time the simulation starts (blank before)",
950 ),
951 ("resolution", "number", "1", "state grid, fraction of the frame"),
952 ("substeps", "number", "1", "updates per frame (1..64)"),
953 ("u", "number[]", "", "up to 16 values, param(i)"),
954 ("u0", "number", "", "u0..u15 individually (animatable)"),
955 ],
956 extra: &[],
957 },
958 OpSchema {
959 name: "raymarch",
960 summary: "3D as a signed-distance scene marched per pixel: write float2 map(float3 p) -> (distance, material id); soft shadows, occlusion, a reflection bounce, environment and antialiasing come with it",
961 ports: &["in0", "in1", "in2", "in3"],
962 params: &[
963 (
964 "scene",
965 "text",
966 "",
967 "Slang: float2 map(float3 p) (+ optional void material(float id, float3 p, float3 n, inout float3 albedo, inout float metallic, inout float roughness)); helpers sdSphere, sdBox, sdCylinder, sdTorus, sdCapsule, sdBand, sdPlane, smin, opU, rotX/Y/Z, fbm3, knob(i), layerDistance + extrude (any ultrafast layer as a 3D solid), presetMaterial (ids 0 matte, 1 brass, 2 polished brass, 3 steel, 4 gold, 5 copper, 6 black lacquer, 7 ceramic, 8 rubber, 9 clear glass, 10 chrome; metallic < 0 makes glass); input(i, px) reads in0..in3",
968 ),
969 (
970 "orbit",
971 "vec3",
972 "[30,20,8]",
973 "camera [azimuth, elevation, distance] around target, degrees and world units",
974 ),
975 ("target", "vec3", "[0,0,0]", "what the camera looks at"),
976 ("fov", "number", "35", "vertical, degrees"),
977 ("light", "vec3", "[-4,5,4]", "point light position (casts soft shadows)"),
978 ("light_color", "color", "#fff2e0", "light color"),
979 ("light_intensity", "number", "40", "inverse-square intensity"),
980 (
981 "environment",
982 "enum(studio|room|night|sky|lightbox|horizon)",
983 "studio",
984 "what reflections and ambient light see (lightbox: bars of light, made for glass and chrome)",
985 ),
986 (
987 "background",
988 "text",
989 "environment",
990 "environment, transparent (to composite over 2D), or a color",
991 ),
992 (
993 "background_level",
994 "number",
995 "0.35",
996 "brightness of an environment background",
997 ),
998 ("exposure", "number", "1", "before tone mapping"),
999 ("samples", "number", "2", "rays per pixel (1..8), jittered"),
1000 (
1001 "bounce",
1002 "bool",
1003 "true",
1004 "trace one reflection bounce for glossy surfaces",
1005 ),
1006 (
1007 "ior",
1008 "number",
1009 "1.5",
1010 "glass index of refraction (materials with metallic < 0, preset 9)",
1011 ),
1012 ("dispersion", "number", "1", "glass color splitting (0 none, 2 strong)"),
1013 ("max_distance", "number", "80", "rays stop here"),
1014 (
1015 "k0",
1016 "number",
1017 "",
1018 "k0..k4: free knobs read as knob(0..4) in the scene (animatable)",
1019 ),
1020 ("resolution", "number", "1", "render scale"),
1021 ],
1022 extra: &[],
1023 },
1024 OpSchema {
1025 name: "transition",
1026 summary: "from shot `a` to shot `b` over `duration` s starting `at`: only a renders before, only b after",
1027 ports: &["a", "b"],
1028 params: &[
1029 (
1030 "kind",
1031 "enum(crossfade|dip|wipe|push|slide|iris|zoom|dissolve|glitch|blur)",
1032 "crossfade",
1033 "how: dip goes through `color`; wipe/push/slide move along `direction`; iris opens from `center`; dissolve burns through noise",
1034 ),
1035 ("at", "number", "0", "start, seconds"),
1036 ("duration", "number", "0.8", "seconds"),
1037 ("direction", "number", "0", "degrees: 0 moves rightward, 90 downward"),
1038 ("softness", "number", "per kind", "edge softness (blur: strength)"),
1039 (
1040 "color",
1041 "color",
1042 "#000000",
1043 "dip color; wipe and dissolve edge glow color (dissolve: ember #ff9a4a)",
1044 ),
1045 ("glow", "number", "0 (dissolve 2)", "edge glow strength"),
1046 ("center", "vec2", "frame center", "iris and zoom center px"),
1047 ("grain", "number", "160", "dissolve noise size px"),
1048 (
1049 "ease",
1050 "text|number[]",
1051 "per kind",
1052 "progress easing: a name (in_out_cubic) or [x1, y1, x2, y2]",
1053 ),
1054 ],
1055 extra: &[],
1056 },
1057 OpSchema {
1058 name: "block",
1059 summary: "a ready-made animated block in one house style: title, lower_third, quote, stat, chapter, end_card, and charts: bar_chart, line_chart, donut (place it in time with a timing offset)",
1060 ports: &[],
1061 params: &[
1062 (
1063 "kind",
1064 "enum(title|lower_third|quote|stat|chapter|end_card|bar_chart|line_chart|donut)",
1065 "title",
1066 "which block",
1067 ),
1068 (
1069 "title",
1070 "text",
1071 "",
1072 "title / chapter / end_card / charts (above the chart)",
1073 ),
1074 ("kicker", "text", "", "title, charts: small line above"),
1075 ("subtitle", "text", "", "title: line below"),
1076 ("number", "text", "", "chapter: its number, e.g. 01"),
1077 ("name", "text", "", "lower_third"),
1078 ("role", "text", "", "lower_third"),
1079 ("quote", "text", "", "quote"),
1080 ("author", "text", "", "quote"),
1081 ("value", "number", "0", "stat: counts up to it"),
1082 ("prefix", "text", "", "stat, bar and line values"),
1083 ("suffix", "text", "", "stat, bar and line values"),
1084 ("decimals", "number", "0", "stat, bar and line values"),
1085 ("label", "text", "", "stat"),
1086 ("tagline", "text", "", "end_card"),
1087 ("cta", "text", "", "end_card: a pill button"),
1088 ("logo", "text", "", "end_card: SVG file"),
1089 ("values", "number[]", "", "charts: the data, e.g. [24, 31, 58, 265]"),
1090 (
1091 "labels",
1092 "text",
1093 "",
1094 "charts: one per value, comma separated (or | when labels hold commas)",
1095 ),
1096 (
1097 "highlight",
1098 "number",
1099 "bar, donut: the largest; line: the last",
1100 "charts: index of the value set in the accent and called out (-1: none)",
1101 ),
1102 ("height", "number", "34% of the height", "charts: plot height px"),
1103 (
1104 "max",
1105 "number",
1106 "largest value",
1107 "bar, line: the value at the top of the plot",
1108 ),
1109 ("min", "number", "0 or the smallest", "line: the value at the baseline"),
1110 (
1111 "color",
1112 "color",
1113 "muted (line: accent)",
1114 "bar: other bars; line: the line",
1115 ),
1116 ("area", "bool", "true", "line: fill under the line"),
1117 ("draw_time", "number", "1.6", "line: seconds the line takes to draw"),
1118 (
1119 "colors",
1120 "text",
1121 "accent, then a palette",
1122 "donut: segment colors, comma separated",
1123 ),
1124 ("radius", "number", "fits the plot", "donut: outer radius px"),
1125 ("thickness", "number", "30% of radius", "donut: ring thickness px"),
1126 (
1127 "number_font",
1128 "text",
1129 "ultrafast:wide",
1130 "stat, donut: the big number's face",
1131 ),
1132 ("title_font", "text", "ultrafast:wide", "end_card: the title's face"),
1133 (
1134 "duration",
1135 "number",
1136 "3.5 (lower_third 4, quote 5, chapter 2.5, charts 5)",
1137 "seconds before it exits (end_card stays)",
1138 ),
1139 ("ink", "color", "#f6f3ee", "type color"),
1140 ("muted", "color", "ink at 72%", "secondary type"),
1141 ("accent", "color", "#ff5c7a", "rules, bars, quote mark, pill"),
1142 ("display_font", "text", "ultrafast:display", "headline face"),
1143 ("text_font", "text", "ultrafast:sans", "body face"),
1144 ("mono_font", "text", "ultrafast:mono", "labels"),
1145 ("align", "enum(left|center)", "left", "alignment (end_card is centered)"),
1146 (
1147 "position",
1148 "vec2",
1149 "per kind",
1150 "title/quote/stat: top of the block; lower_third: bottom-left; end_card: center",
1151 ),
1152 ("width", "number", "80% of the width", "wrap width px"),
1153 ("scale", "number", "1", "size multiplier (sizes follow the frame)"),
1154 ("opacity", "number", "1", "0..1"),
1155 ],
1156 extra: &[],
1157 },
1158 OpSchema {
1159 name: "lottie",
1160 summary: "a Lottie (Bodymovin) animation as editable ultrafast nodes: shape layers become paths with Lottie's keyframes, transforms stay vector; loops by default",
1161 ports: &[],
1162 params: &[
1163 ("src", "text", "", "Lottie .json file"),
1164 ("size", "vec2|number", "the animation's size", "fit it into this box px"),
1165 ("loop", "bool", "true", "repeat over its duration"),
1166 ("position", "vec2", "[0,0]", "where its top-left (or anchor) lands px"),
1167 ("anchor", "vec2", "[0,0]", "pivot px in its fitted space"),
1168 ("scale", "vec2|number", "[1,1]", "scale"),
1169 ("rotation", "number", "0", "degrees"),
1170 ("opacity", "number", "1", "0..1"),
1171 ],
1172 extra: &[],
1173 },
1174 OpSchema {
1175 name: "code",
1176 summary: "source code in a panel: syntax-highlighted, optionally typed on with a caret, line numbers, highlighted lines, window chrome",
1177 ports: &[],
1178 params: &[
1179 (
1180 "code",
1181 "text",
1182 "",
1183 "the source (\\n between lines; tabs become 4 spaces)",
1184 ),
1185 (
1186 "language",
1187 "enum(rust|python|js|ts|json|bash|go|swift|c|cpp|slang|sql|css|html|text)",
1188 "text",
1189 "how to color it",
1190 ),
1191 (
1192 "theme",
1193 "enum(ultrafast|paper|mono)",
1194 "ultrafast",
1195 "colors (paper is light)",
1196 ),
1197 ("title", "text", "", "file name in the title bar"),
1198 ("window", "bool", "true", "title bar with three dots"),
1199 ("background", "bool", "true", "the panel and its shadow"),
1200 ("line_numbers", "bool", "true", "gutter numbers"),
1201 ("highlight", "text", "", "lines to mark, e.g. \"3\" or \"2,5-7\""),
1202 ("highlight_at", "number", "0", "when the marked lines light up"),
1203 (
1204 "type_speed",
1205 "number",
1206 "0",
1207 "characters per second typed on (0: all shown)",
1208 ),
1209 ("at", "number", "0", "when typing starts"),
1210 ("caret", "bool", "true", "a blinking caret while and after typing"),
1211 ("font", "text", "ultrafast:mono", "a monospaced face"),
1212 ("size", "number", "30 at 1080p", "px"),
1213 ("line_height", "number", "1.55", "multiple of size"),
1214 ("padding", "number", "1.4 x size", "px inside the panel"),
1215 ("radius", "number", "0.55 x size", "panel corner radius px"),
1216 ("width", "number", "fits the longest line", "panel width px"),
1217 ("position", "vec2", "centered", "top-left of the panel"),
1218 ("opacity", "number", "1", "0..1"),
1219 ],
1220 extra: &[],
1221 },
1222 OpSchema {
1223 name: "stack",
1224 summary: "lays its inputs (in0, in1, ...: text, path, shape, svg or stack) out in a column or row by their measured bounds",
1225 ports: &[
1226 "in0", "in1", "in2", "in3", "in4", "in5", "in6", "in7", "in8", "in9", "in10", "in11", "in12", "in13",
1227 "in14", "in15",
1228 ],
1229 params: &[
1230 ("direction", "enum(column|row)", "column", "stack downward or rightward"),
1231 (
1232 "at",
1233 "number",
1234 "0",
1235 "seconds at which children are measured (when their entrances have landed)",
1236 ),
1237 ("gap", "number", "24", "px between children"),
1238 ("align", "enum(start|center|end)", "start", "children across the stack"),
1239 ("position", "vec2", "[0,0]", "where the block's anchor goes"),
1240 (
1241 "anchor",
1242 "enum(top_left|top|top_right|left|center|right|bottom_left|bottom|bottom_right)",
1243 "top_left",
1244 "which point of the block sits at position",
1245 ),
1246 ],
1247 extra: &[],
1248 },
1249 OpSchema {
1250 name: "clip_camera",
1251 summary: "video framed on its speaker: faces are tracked from the footage (or given), then a follow camera with dead zone and eased pans, cuts on shots and speaker changes, scope zoom, protect mode (blurred cover behind the contained frame)",
1252 ports: &[],
1253 params: &[
1254 ("src", "text", "", "source video"),
1255 (
1256 "faces",
1257 "text",
1258 "tracked from src",
1259 "face tracks, inline as JSON text or a file: {sourceWidth, sourceHeight, fps, frames: [{frame, faces: [{id, x, y, w, h, talk, focus}]}], shots: [{startFrame, endFrame, protect, cinematicScope}]}; omit it and the clip's faces, who is talking and its cuts are tracked from the footage (`ultrafast faces` writes the same)",
1260 ),
1261 ("start", "number", "0", "source seconds where the clip begins"),
1262 ("duration", "number", "document duration", "clip seconds"),
1263 ("tuning", "text", "", "camera tuning overrides as JSON"),
1264 ("opacity", "number", "1", "0..1"),
1265 ],
1266 extra: &[],
1267 },
1268 OpSchema {
1269 name: "captions",
1270 summary: "animated captions from word timings (karaoke, pop, reveal): pages laid out to fit, every word its own text node",
1271 ports: &[],
1272 params: &[
1273 ("src", "text", "", "transcript: Whisper/word JSON, .srt or .vtt"),
1274 (
1275 "words",
1276 "text",
1277 "",
1278 "inline instead: lines of `start end word`, SRT text or JSON",
1279 ),
1280 (
1281 "style",
1282 "enum(karaoke|pop|reveal|plain)",
1283 "karaoke",
1284 "karaoke lights the spoken word; pop pops each word on; reveal fades them on",
1285 ),
1286 ("font", "text", "Helvetica Neue", "family or file"),
1287 ("size", "number", "6.5% of the short side", "px"),
1288 ("weight", "number", "800", "100..900"),
1289 ("color", "color", "#ffffff", "words not yet spoken"),
1290 ("highlight", "color", "#ffd23f", "the word being spoken"),
1291 ("spoken", "color", "color", "words already spoken"),
1292 (
1293 "highlight_background",
1294 "color",
1295 "",
1296 "a rounded pill behind the spoken word",
1297 ),
1298 ("background", "color", "", "a rounded box behind each page"),
1299 ("uppercase", "bool", "false", "set in capitals"),
1300 ("tracking", "number", "0", "extra px between glyphs"),
1301 ("width", "number", "82% of the width", "line width px"),
1302 ("max_lines", "number", "2", "lines per page"),
1303 ("line_height", "number", "1.18", "multiple of size"),
1304 (
1305 "position",
1306 "vec2",
1307 "[w/2, 0.72 h]",
1308 "center of the caption block (moved into `safe` if it would cross it)",
1309 ),
1310 ("align", "enum(left|center|right)", "center", "line alignment"),
1311 (
1312 "safe",
1313 "enum(auto|social|margin|none)",
1314 "auto",
1315 "area pages stay inside: auto is clear of the social apps' buttons and captions on a vertical frame (what `review --safe social` checks) and a 4% margin otherwise; none places them exactly at position",
1316 ),
1317 ("linger", "number", "0.6", "seconds a page stays after its last word"),
1318 ("opacity", "number", "1", "0..1"),
1319 ],
1320 extra: &[],
1321 },
1322 OpSchema {
1323 name: "svg",
1324 summary: "an SVG file (logo, icon, illustration) as vector paths: fills, strokes, gradients, blend modes, and text as outlines in the fonts the text op finds; `ultrafast import-svg` gives the same as editable nodes. It composites in sRGB, like a browser: put it on the film with an `over` in `srgb` space to match one there too",
1325 ports: &[],
1326 params: &[
1327 ("src", "text", "", ".svg file (relative to the document)"),
1328 (
1329 "size",
1330 "vec2|number",
1331 "the SVG's own size",
1332 "fit inside [w, h] px, keeping its aspect",
1333 ),
1334 ("position", "vec2", "[0,0]", "where the anchor lands, px"),
1335 ("anchor", "vec2", "[0,0]", "pivot in the artwork's px (after size)"),
1336 (
1337 "scale",
1338 "vec2|number",
1339 "[1,1]",
1340 "scale around the anchor (stays vector-sharp)",
1341 ),
1342 ("rotation", "number", "0", "degrees, clockwise"),
1343 ("opacity", "number", "1", "0..1"),
1344 ],
1345 extra: &[],
1346 },
1347 OpSchema {
1348 name: "audio",
1349 summary: "sound mixed into exports",
1350 ports: &[],
1351 params: &[
1352 ("src", "text", "", "any media file with audio"),
1353 ("start", "number", "0", "source seconds playing at local time `from`"),
1354 ("gain", "number", "1", "linear, animatable"),
1355 (
1356 "from",
1357 "number",
1358 "0",
1359 "local seconds the sound starts at (silent before)",
1360 ),
1361 (
1362 "duration",
1363 "number",
1364 "0",
1365 "seconds it plays from `from` (0: until the source ends)",
1366 ),
1367 (
1368 "rate",
1369 "number",
1370 "1",
1371 "playback speed with the pitch kept (time stretched)",
1372 ),
1373 ],
1374 extra: &[],
1375 },
1376];
1377
1378fn find(op: &str) -> Option<&'static OpSchema> {
1379 SCHEMAS.iter().find(|s| s.name == op)
1380}
1381
1382pub fn moves_nothing(op: &str, param: &str) -> bool {
1386 match (op, param) {
1387 (_, "opacity" | "glyph_opacity") | ("adjust" | "levels", _) | ("lut" | "invert", "amount") => true,
1388 ("light", "intensity") | ("render3d", "ambient") | ("raymarch", "light_intensity" | "exposure") => true,
1389 _ => find(op).is_some_and(|s| {
1390 s.params
1391 .iter()
1392 .chain(s.extra.iter().flat_map(|e| e.iter()))
1393 .any(|p| p.0 == param && p.1 == "color")
1394 }),
1395 }
1396}
1397
1398fn all_params(s: &OpSchema) -> impl Iterator<Item = &'static P> {
1399 s.params.iter().chain(s.extra.iter().flat_map(|g| g.iter()))
1400}
1401
1402fn op_param(s: &OpSchema, k: &str) -> Option<&'static P> {
1405 all_params(s).find(|p| {
1406 p.0 == k
1407 || (k.starts_with('u') && p.0 == "u0" && k[1..].parse::<u8>().is_ok_and(|i| i < 16))
1408 || (k.starts_with('k') && p.0 == "k0" && k[1..].parse::<u8>().is_ok_and(|i| i < 5))
1409 || (k.starts_with("axis_") && p.0 == "axis_<tag>" && (6..=9).contains(&k.len()))
1410 })
1411}
1412
1413fn component<'a>(doc: &'a Document, op: &str) -> Option<&'a ultrafast_graph::Component> {
1415 doc.components.get(op).or_else(|| {
1416 crate::builtins::components()
1417 .iter()
1418 .find(|(n, _)| n == op)
1419 .map(|(_, c)| c)
1420 })
1421}
1422
1423pub fn unknown_param(doc: &Document, op: &str, k: &str) -> Option<String> {
1427 let hint = |names: &mut dyn Iterator<Item = &str>| {
1428 names
1429 .min_by_key(|n| edit_distance(n, k))
1430 .filter(|n| edit_distance(n, k) <= 3)
1431 .map(|n| format!(" (did you mean `{n}`?)"))
1432 .unwrap_or_default()
1433 };
1434 if let Some(c) = component(doc, op) {
1435 let used = c.nodes.values().any(|n| {
1438 n.params
1439 .values()
1440 .any(|v| matches!(v, Param::Text(s) if s.strip_prefix('$') == Some(k)))
1441 });
1442 return (!c.params.contains_key(k) && !used).then(|| {
1443 format!(
1444 "component `{op}` has no param `{k}`{}",
1445 hint(&mut c.params.keys().map(String::as_str))
1446 )
1447 });
1448 }
1449 let s = find(op)?;
1450 op_param(s, k)
1451 .is_none()
1452 .then(|| format!("`{op}` has no param `{k}`{}", hint(&mut all_params(s).map(|p| p.0))))
1453}
1454
1455pub fn vocabulary() -> Value {
1457 let mut ops: Vec<Value> = SCHEMAS
1458 .iter()
1459 .map(|s| {
1460 json!({
1461 "op": s.name,
1462 "summary": s.summary,
1463 "ports": s.ports,
1464 "params": all_params(s).map(|(n, ty, d, desc)| json!({ "name": n, "type": ty, "default": d, "doc": desc })).collect::<Vec<_>>(),
1465 })
1466 })
1467 .collect();
1468 for (name, c) in crate::builtins::components() {
1469 ops.push(json!({
1470 "op": name,
1471 "summary": crate::builtins::summary(name),
1472 "ports": c.inputs,
1473 "params": c
1474 .params
1475 .iter()
1476 .map(|(k, v)| {
1477 let v = serde_json::to_value(v).unwrap();
1478 let ty = match &v {
1480 Value::Number(_) => "number",
1481 Value::Bool(_) => "bool",
1482 Value::String(s) if s.starts_with('#') => "color",
1483 Value::String(_) => "text",
1484 Value::Array(a) if a.len() == 2 => "vec2",
1485 Value::Array(_) => "vector",
1486 _ => "animated",
1487 };
1488 let default = match &v {
1489 Value::String(s) => s.clone(),
1490 other => other.to_string(),
1491 };
1492 json!({ "name": k, "type": ty, "default": default })
1493 })
1494 .collect::<Vec<_>>(),
1495 }));
1496 }
1497 json!(ops)
1498}
1499
1500#[derive(Debug, Clone)]
1502pub struct Issue {
1503 pub node: String,
1504 pub severity: &'static str,
1505 pub message: String,
1506}
1507
1508pub fn check(doc: &Document) -> Vec<Issue> {
1512 let mut out = Vec::new();
1513 let mut issue = |node: &str, severity: &'static str, message: String| {
1514 out.push(Issue {
1515 node: node.to_string(),
1516 severity,
1517 message,
1518 });
1519 };
1520 let mut graphs: Vec<(String, &std::collections::BTreeMap<String, ultrafast_graph::Node>)> =
1521 vec![(String::new(), &doc.nodes)];
1522 for (name, c) in &doc.components {
1523 graphs.push((format!("{name}/"), &c.nodes));
1524 }
1525 for (prefix, nodes) in graphs {
1526 for (id, node) in nodes {
1527 let path = format!("{prefix}{id}");
1528 if let Some(c) = component(doc, &node.op) {
1529 for k in node.params.keys() {
1530 if let Some(why) = unknown_param(doc, &node.op, k) {
1531 issue(&path, "warning", why);
1532 }
1533 }
1534 for p in node.inputs.keys() {
1535 if !c.inputs.contains(p) {
1536 issue(&path, "warning", format!("component `{}` has no input `{p}`", node.op));
1537 }
1538 }
1539 continue;
1540 }
1541 let Some(schema) = find(&node.op) else {
1542 issue(&path, "error", format!("unknown op `{}`", node.op));
1543 continue;
1544 };
1545 for (k, v) in &node.params {
1546 if prefix.is_empty() || !matches!(v, Param::Text(s) if s.starts_with('$')) {
1547 match op_param(schema, k) {
1548 None => {
1549 let why = unknown_param(doc, &node.op, k).unwrap_or_default();
1550 issue(&path, "warning", format!("{why}; it is ignored"));
1551 }
1552 Some(p) => {
1553 if let Param::Expr { expr } = v {
1554 for e in expr.errors() {
1555 issue(&path, "error", format!("param `{k}`: {e}"));
1556 }
1557 }
1558 if let Some(msg) = type_mismatch(p.1, v) {
1559 issue(&path, "warning", format!("param `{k}`: {msg}"));
1560 }
1561 }
1562 }
1563 }
1564 }
1565 if schema.ports != ["*"] {
1566 for p in node.inputs.keys() {
1567 if !schema.ports.contains(&p.as_str()) {
1568 issue(
1569 &path,
1570 "warning",
1571 format!("`{}` has no input `{p}` (ports: {:?})", node.op, schema.ports),
1572 );
1573 }
1574 }
1575 let optional = matches!(
1576 node.op.as_str(),
1577 "shader" | "raymarch" | "mesh" | "particles" | "fluid" | "feedback" | "stack"
1578 );
1579 for p in schema.ports {
1580 if !optional && !node.inputs.contains_key(*p) {
1581 issue(&path, "error", format!("missing input `{p}`"));
1582 }
1583 }
1584 }
1585 }
1586 }
1587 if let Ok(order) = doc.reachable_topo_order() {
1588 for id in doc.nodes.keys() {
1589 let used_elsewhere = doc.nodes.get(id).is_some_and(|n| n.op == "audio");
1590 if !order.contains(id) && !used_elsewhere {
1591 issue(id, "info", "not reachable from the output (not rendered)".into());
1592 }
1593 }
1594 let mut reach: std::collections::HashMap<&str, (f64, f64)> = std::collections::HashMap::new();
1601 reach.insert(doc.output.as_str(), (0.0, doc.format.duration));
1602 let num = |n: &ultrafast_graph::Node, k: &str, d: f64| match n.params.get(k) {
1603 Some(Param::Number(v)) => *v,
1604 _ => d,
1605 };
1606 for id in order.iter().rev() {
1607 let Some(&(ra, rb)) = reach.get(id.as_str()) else {
1608 continue;
1609 };
1610 let node = &doc.nodes[id];
1611 let window = node.timing.filter(|t| t.has_window()).map(|t| {
1614 (
1615 t.in_point.unwrap_or(f64::NEG_INFINITY),
1616 t.out_point.unwrap_or(f64::INFINITY),
1617 )
1618 });
1619 let through = through_port(doc, id, node);
1620 for (port, src) in &node.inputs {
1621 let (mut a, mut b) = (ra, rb);
1622 if let Some((wa, wb)) = window
1623 && through.as_deref() != Some(port.as_str())
1624 {
1625 a = a.max(wa);
1626 b = b.min(wb);
1627 }
1628 if node.op == "transition" {
1629 let at = num(node, "at", 0.0);
1630 let end = at + num(node, "duration", 0.8);
1631 if port == "a" {
1632 b = b.min(end);
1633 } else if port == "b" {
1634 a = a.max(at);
1635 }
1636 }
1637 if a < b {
1638 let e = reach.entry(src.as_str()).or_insert((a, b));
1639 *e = (e.0.min(a), e.1.max(b));
1640 }
1641 }
1642 }
1643 for id in &order {
1644 let node = &doc.nodes[id];
1645 let Some(w) = node.timing.filter(|t| t.has_window()) else {
1646 continue;
1647 };
1648 if !matches!(
1652 node.op.as_str(),
1653 "crop" | "mask" | "transform" | "corner_pin" | "opacity" | "tile" | "wave" | "twirl" | "displace"
1654 ) {
1655 continue;
1656 }
1657 let Some(port) = through_port(doc, id, node) else {
1658 continue;
1659 };
1660 let Some(src) = node.inputs.get(&port) else { continue };
1661 let (a, b) = visible(doc, src, 0);
1662 let (wa, wb) = (
1663 w.in_point.unwrap_or(f64::NEG_INFINITY),
1664 w.out_point.unwrap_or(f64::INFINITY),
1665 );
1666 let (ra, rb) = reach
1668 .get(id.as_str())
1669 .copied()
1670 .unwrap_or((f64::NEG_INFINITY, f64::INFINITY));
1671 let (a, b) = (a.max(ra), b.min(rb));
1672 let before = a < wa - 1e-6 && a < b;
1673 let after = b > wb + 1e-6 && a < b;
1674 if before || after {
1675 issue(
1676 id,
1677 "warning",
1678 format!(
1679 "outside its window ({}) `{id}` passes `{src}` through as it is, and `{src}` shows {}: give `{src}` the same window, or time a composite above both",
1680 span(wa, wb),
1681 span(a, b)
1682 ),
1683 );
1684 }
1685 }
1686 }
1687 out
1688}
1689
1690fn through_port(doc: &Document, id: &str, n: &ultrafast_graph::Node) -> Option<String> {
1694 let component =
1695 doc.components.contains_key(&n.op) || crate::builtins::components().iter().any(|(name, _)| *name == n.op);
1696 if component {
1697 return n.inputs.contains_key("source").then(|| "source".to_string());
1698 }
1699 let def = crate::ops::resolve(id, n).ok()?;
1700 let ports = crate::ops::connected_ports(def, id, n).ok()?;
1701 let k = crate::ops::passthrough(def, ports.len())?;
1702 ports.get(k).cloned()
1703}
1704
1705fn visible(doc: &Document, id: &str, depth: usize) -> (f64, f64) {
1709 let all = (f64::NEG_INFINITY, f64::INFINITY);
1710 let Some(n) = doc.nodes.get(id) else { return all };
1711 let generator = matches!(
1714 n.op.as_str(),
1715 "particles" | "raymarch" | "render3d" | "swarm" | "fluid" | "feedback"
1716 );
1717 let own = n
1718 .timing
1719 .filter(|t| t.has_window())
1720 .map(|t| {
1721 (
1722 t.in_point.unwrap_or(f64::NEG_INFINITY),
1723 t.out_point.unwrap_or(f64::INFINITY),
1724 )
1725 })
1726 .unwrap_or(all);
1727 if n.inputs.is_empty() || generator || depth > 64 {
1728 return own;
1729 }
1730 let inverted = matches!(n.params.get("mode"), Some(Param::Text(m)) if m.ends_with("inverted"));
1732 if n.op == "mask" && !inverted {
1733 let empty = (f64::INFINITY, f64::NEG_INFINITY);
1734 let src = n
1735 .inputs
1736 .get("source")
1737 .map(|s| visible(doc, s, depth + 1))
1738 .unwrap_or(empty);
1739 let matte = n
1740 .inputs
1741 .get("matte")
1742 .map(|s| visible(doc, s, depth + 1))
1743 .unwrap_or(empty);
1744 let inside = (src.0.max(matte.0).max(own.0), src.1.min(matte.1).min(own.1));
1745 let mut hull = if inside.0 < inside.1 { inside } else { empty };
1746 let film = (0.0, doc.format.duration);
1748 for (a, b) in [(src.0, src.1.min(own.0)), (src.0.max(own.1), src.1)] {
1749 let (a, b) = (a.max(film.0), b.min(film.1));
1750 if a < b {
1751 hull = (hull.0.min(a), hull.1.max(b));
1752 }
1753 }
1754 return hull;
1755 }
1756 if n.op == "transition" {
1757 let num = |k: &str, d: f64| match n.params.get(k) {
1758 Some(Param::Number(v)) => *v,
1759 _ => d,
1760 };
1761 let at = num("at", 0.0);
1762 let end = at + num("duration", 0.8);
1763 let a = n
1764 .inputs
1765 .get("a")
1766 .map(|s| visible(doc, s, depth + 1))
1767 .unwrap_or((f64::INFINITY, f64::NEG_INFINITY));
1768 let b = n
1769 .inputs
1770 .get("b")
1771 .map(|s| visible(doc, s, depth + 1))
1772 .unwrap_or((f64::INFINITY, f64::NEG_INFINITY));
1773 let a = (a.0, a.1.min(end));
1774 let b = (b.0.max(at), b.1);
1775 return (a.0.min(b.0), a.1.max(b.1));
1776 }
1777 let through = n
1780 .timing
1781 .filter(|t| t.has_window())
1782 .and_then(|_| through_port(doc, id, n));
1783 let windowed = n.timing.is_some_and(|t| t.has_window());
1784 let mut hull = (f64::INFINITY, f64::NEG_INFINITY);
1785 for (port, src) in &n.inputs {
1786 let (mut a, mut b) = visible(doc, src, depth + 1);
1787 if windowed && through.as_deref() != Some(port.as_str()) {
1788 a = a.max(own.0);
1789 b = b.min(own.1);
1790 }
1791 if a < b {
1792 hull = (hull.0.min(a), hull.1.max(b));
1793 }
1794 }
1795 hull
1796}
1797
1798fn span(a: f64, b: f64) -> String {
1799 let t = |v: f64, open: &str| {
1800 if v.is_finite() {
1801 format!("{v:.2} s")
1802 } else {
1803 open.to_string()
1804 }
1805 };
1806 format!("{} to {}", t(a, "the start"), t(b, "the end"))
1807}
1808
1809fn type_mismatch(ty: &str, v: &Param) -> Option<String> {
1810 let numeric = !matches!(v, Param::Text(_) | Param::Bool(_));
1811 let len = match v {
1812 Param::Number(_) => Some(1),
1813 Param::Vector(x) => Some(x.len()),
1814 Param::Animated { keys, .. } => keys.first().map(|k| k.v.len()),
1815 p => p.eval(0.0).map(|x| x.len()),
1817 };
1818 let ok = match ty {
1819 "color" => matches!(v, Param::Text(s) if s.starts_with('#')) || matches!(len, Some(3 | 4)),
1820 "number" => len == Some(1),
1821 "vec2" => matches!(len, Some(1 | 2)),
1823 "vec3" => matches!(len, Some(1 | 3)),
1824 "vec4" => matches!(len, Some(1 | 4)),
1825 "vec2|number" => matches!(len, Some(1 | 2)),
1826 "vec3|number" => matches!(len, Some(1 | 3)),
1827 "number[]" => numeric,
1828 "text" => matches!(v, Param::Text(_)),
1829 "text|number[]" => matches!(v, Param::Text(_)) || numeric,
1830 "bool" => matches!(v, Param::Bool(_)),
1831 t if t.starts_with("enum(") => match v {
1832 Param::Text(s) => t[5..t.len() - 1].split('|').any(|o| o == s),
1833 _ => false,
1834 },
1835 _ => true,
1836 };
1837 (!ok).then(|| format!("expected {ty}, got {}", serde_json::to_string(v).unwrap_or_default()))
1838}
1839
1840pub(crate) fn edit_distance(a: &str, b: &str) -> usize {
1843 let (a, b): (Vec<char>, Vec<char>) = (a.chars().collect(), b.chars().collect());
1844 let mut d = vec![vec![0; b.len() + 1]; a.len() + 1];
1845 for (i, row) in d.iter_mut().enumerate() {
1846 row[0] = i;
1847 }
1848 for j in 0..=b.len() {
1849 d[0][j] = j;
1850 }
1851 for i in 1..=a.len() {
1852 for j in 1..=b.len() {
1853 let mut v = (d[i - 1][j] + 1)
1854 .min(d[i][j - 1] + 1)
1855 .min(d[i - 1][j - 1] + (a[i - 1] != b[j - 1]) as usize);
1856 if i > 1 && j > 1 && a[i - 1] == b[j - 2] && a[i - 2] == b[j - 1] {
1857 v = v.min(d[i - 2][j - 2] + 1);
1858 }
1859 d[i][j] = v;
1860 }
1861 }
1862 d[a.len()][b.len()]
1863}
1864
1865#[cfg(test)]
1866mod tests {
1867 use super::*;
1868
1869 #[test]
1870 fn every_op_has_a_schema() {
1871 for d in crate::ops::OPS {
1872 assert!(find(d.name).is_some(), "no schema for {}", d.name);
1873 }
1874 }
1875
1876 #[test]
1877 fn a_swapped_pair_is_one_edit() {
1878 assert_eq!(edit_distance("valeus", "values"), 1);
1879 assert_eq!(edit_distance("valeus", "value"), 2);
1880 assert_eq!(edit_distance("kitten", "sitting"), 3);
1881 assert_eq!(edit_distance("", "ab"), 2);
1882 let doc = Document::from_json(
1883 r#"{"version":1,"format":{"width":100,"height":100,"fps":30,"duration":1},"output":"c",
1884 "nodes":{"c":{"op":"block","params":{"kind":"bar_chart","values":[1],"valeus":[2]}}}}"#,
1885 )
1886 .unwrap();
1887 let msgs: Vec<String> = check(&doc).into_iter().map(|i| i.message).collect();
1888 assert!(
1889 msgs.contains(&"`block` has no param `valeus` (did you mean `values`?); it is ignored".to_string()),
1890 "{msgs:?}"
1891 );
1892 }
1893
1894 #[test]
1895 fn params_a_node_does_take_are_known() {
1896 let doc = Document::from_json(
1897 r#"{"version":1,"format":{"width":100,"height":100,"fps":30,"duration":1},"output":"o",
1898 "components":{"card":{"output":"t","params":{"size":40},
1899 "nodes":{"t":{"op":"text","params":{"text":"$title","size":"$size"}}}}},
1900 "nodes":{"c":{"op":"card","params":{"title":"Hi","sise":30}},
1901 "e":{"op":"block","params":{"kind":"end_card","title_font":"ultrafast:sans"}},
1902 "o":{"op":"over","inputs":{"fg":"c","bg":"e"}}}}"#,
1903 )
1904 .unwrap();
1905 assert_eq!(unknown_param(&doc, "block", "title_font"), None);
1908 assert_eq!(unknown_param(&doc, "card", "title"), None);
1909 assert_eq!(
1910 unknown_param(&doc, "card", "sise").as_deref(),
1911 Some("component `card` has no param `sise` (did you mean `size`?)")
1912 );
1913 let msgs: Vec<String> = check(&doc).into_iter().map(|i| i.message).collect();
1914 assert_eq!(msgs, ["component `card` has no param `sise` (did you mean `size`?)"]);
1915 }
1916
1917 #[test]
1918 fn check_flags_an_effect_that_would_pass_its_source_through() {
1919 let doc = Document::from_json(
1922 r##"{"version":1,"format":{"width":64,"height":64,"fps":30,"duration":3},"output":"o",
1923 "nodes":{"bg":{"op":"solid"},"pic":{"op":"checker"},
1924 "cut":{"op":"crop","params":{"rect":[0,0,32,32]},"inputs":{"source":"pic"},"timing":{"in":1,"out":2}},
1925 "o":{"op":"over","inputs":{"fg":"cut","bg":"bg"}}}}"##,
1926 )
1927 .unwrap();
1928 let found = check(&doc);
1929 assert!(
1930 found
1931 .iter()
1932 .any(|i| i.node == "cut" && i.severity == "warning" && i.message.contains("passes `pic` through")),
1933 "{found:?}"
1934 );
1935 let mut doc = doc;
1937 doc.nodes.get_mut("pic").unwrap().timing = doc.nodes["cut"].timing;
1938 assert!(!check(&doc).iter().any(|i| i.severity == "warning"));
1939 }
1940
1941 #[test]
1942 fn check_flags_typos_and_shapes() {
1943 let doc = Document::from_json(
1944 r##"{"version":1,"format":{"width":8,"height":8,"fps":30,"duration":1},"output":"s",
1945 "nodes":{"s":{"op":"shape","params":{"colour":"#ff0000","radius":[1,2],"kind":"triangle"}},
1946 "x":{"op":"sparkle"}}}"##,
1947 )
1948 .unwrap();
1949 let issues = check(&doc);
1950 let text: Vec<String> = issues.iter().map(|i| format!("{}: {}", i.node, i.message)).collect();
1951 assert!(
1952 text.iter()
1953 .any(|t| t.contains("colour") && t.contains("did you mean `color`")),
1954 "{text:?}"
1955 );
1956 assert!(text.iter().any(|t| t.contains("param `radius`")), "{text:?}");
1957 assert!(text.iter().any(|t| t.contains("param `kind`")), "{text:?}");
1958 assert!(text.iter().any(|t| t.contains("unknown op `sparkle`")), "{text:?}");
1959 }
1960}