vizmatic 0.8.0 → 0.8.3

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 (97) hide show
  1. package/PROMPT.md +10 -9
  2. package/README.md +167 -61
  3. package/ROADMAP.md +5 -4
  4. package/SCIENCE.md +1 -2
  5. package/assets/THIRD_PARTY_LICENSES.md +3 -3
  6. package/assets/fonts/SourceSerif4-24pt-SemiBold.ttf +0 -0
  7. package/assets/licenses/raster-codecs-MIT.txt +2 -2
  8. package/dist/{chunk-ZB3HK7RM.js → chunk-4MXGLMBG.js} +274 -24
  9. package/dist/chunk-GGFDBJ25.js +88 -0
  10. package/dist/{chunk-USDVNKO7.js → chunk-I745F4QK.js} +2323 -357
  11. package/dist/{chunk-DZHX76RS.js → chunk-JZPMGVBP.js} +32 -3
  12. package/dist/cli.js +443 -104
  13. package/dist/index.cjs +1055 -98
  14. package/dist/index.d.cts +216 -4
  15. package/dist/index.d.ts +216 -4
  16. package/dist/index.js +734 -63
  17. package/dist/scene-browser-chunks/chunk-RQNLYYJN.js +70 -0
  18. package/dist/scene-browser-chunks/{scene-browser-layout-M3XSXMV4.js → scene-browser-layout-RC3ECYRK.js} +1 -1
  19. package/dist/scene-browser.js +16 -16
  20. package/dist/scene-cli.js +1 -1
  21. package/dist/scene-runtime.cjs +24 -3
  22. package/dist/scene-runtime.js +1 -1
  23. package/dist/{server-2FYHZ4UO.js → server-Q4COUZHV.js} +3 -3
  24. package/dist/stage-browser/browser.d.ts +8240 -315
  25. package/dist/stage-browser/stage.js +22 -5
  26. package/dist/stage-export.cjs +3640 -298
  27. package/dist/stage-export.d.cts +56 -3
  28. package/dist/stage-export.d.ts +56 -3
  29. package/dist/stage-export.js +677 -149
  30. package/dist/stage.cjs +33026 -7554
  31. package/dist/stage.d.cts +7809 -286
  32. package/dist/stage.d.ts +7809 -286
  33. package/dist/stage.js +26066 -2599
  34. package/dist/{svg-import-C-RG1t7s.d.cts → svg-import-B5BGbC1t.d.cts} +455 -53
  35. package/dist/{svg-import-C-RG1t7s.d.ts → svg-import-B5BGbC1t.d.ts} +455 -53
  36. package/dist/{video-BSwNJZkn.d.ts → video-CiN1MDCS.d.cts} +27 -2
  37. package/dist/{video-BSwNJZkn.d.cts → video-CiN1MDCS.d.ts} +27 -2
  38. package/examples/README.md +1 -1
  39. package/examples/_teaching/layer-stack-connector.ts +36 -0
  40. package/examples/_teaching/layer-stack-recurrence.ts +29 -0
  41. package/examples/_teaching/layer-stack-tiny-gpt.ts +37 -0
  42. package/examples/_teaching/layer-stack-transformer.ts +44 -0
  43. package/examples/catalog-convolution-kernel.tsx +6 -7
  44. package/examples/{aurora-incident.tsx → checkout-incident.tsx} +1 -1
  45. package/examples/films/beam-search.ts +52 -0
  46. package/examples/films/cache-miss.ts +4 -3
  47. package/examples/films/catalog.json +30 -0
  48. package/examples/films/forecast.ts +354 -0
  49. package/examples/films/passage/chunking.ts +40 -0
  50. package/examples/films/passage/evidence.ts +44 -0
  51. package/examples/films/passage/prompt.ts +34 -0
  52. package/examples/films/paxos.ts +596 -0
  53. package/examples/films/taylor-series.ts +1 -1
  54. package/examples/narrated-cues/README.md +32 -0
  55. package/examples/narrated-cues/data/numbers.json +1 -0
  56. package/examples/narrated-cues/film.json +9 -0
  57. package/examples/narrated-cues/film.ts +78 -0
  58. package/examples/narrated-cues/package.json +1 -0
  59. package/examples/narrated-cues/script.json +57 -0
  60. package/examples/narrated-cues/timing.json +1 -0
  61. package/examples/narrated-cues/tsconfig.json +1 -0
  62. package/examples/proofs/decoding-bars.ts +67 -0
  63. package/examples/proofs/pipeline.ts +27 -0
  64. package/examples/proofs/table/evaluation.ts +41 -0
  65. package/examples/proofs/table/ledger.ts +47 -0
  66. package/examples/proofs/table/routing.ts +46 -0
  67. package/package.json +9 -4
  68. package/templates/narrated/README.md +61 -0
  69. package/templates/narrated/data/numbers.json +5 -0
  70. package/templates/narrated/film.json +12 -0
  71. package/templates/narrated/film.ts +14 -0
  72. package/templates/narrated/gitignore +8 -0
  73. package/templates/narrated/package.json +1 -0
  74. package/templates/narrated/scenes/answer.ts +25 -0
  75. package/templates/narrated/scenes/kit.ts +39 -0
  76. package/templates/narrated/scenes/question.ts +31 -0
  77. package/templates/narrated/script.json +26 -0
  78. package/templates/narrated/sources.md +22 -0
  79. package/templates/narrated/timing.json +1 -0
  80. package/templates/narrated/tsconfig.json +1 -0
  81. package/tools/narration/README.md +123 -0
  82. package/tools/narration/beats.py +43 -0
  83. package/tools/narration/checks.py +587 -0
  84. package/tools/narration/draft.py +73 -0
  85. package/tools/narration/film.py +341 -0
  86. package/tools/narration/lag.py +58 -0
  87. package/tools/narration/mix.py +265 -0
  88. package/tools/narration/probe.py +99 -0
  89. package/tools/narration/record.py +33 -0
  90. package/tools/narration/resound.py +170 -0
  91. package/tools/narration/soundbed.py +404 -0
  92. package/tools/narration/sync.py +93 -0
  93. package/tools/narration/transcribe.py +84 -0
  94. package/tools/narration/verify.py +59 -0
  95. package/tools/narration/voice.py +113 -0
  96. package/dist/chunk-6N6P2GJG.js +0 -88
  97. package/dist/scene-browser-chunks/chunk-5MVLYGXM.js +0 -70
package/dist/index.cjs CHANGED
@@ -133,6 +133,7 @@ __export(index_exports, {
133
133
  WindowFrame: () => WindowFrame,
134
134
  analyzeAnimationCadence: () => analyzeAnimationCadence,
135
135
  arcSwap: () => arcSwap,
136
+ assertCueReveal: () => assertCueReveal,
136
137
  assertDensity: () => assertDensity,
137
138
  assertTokenHistoryTransition: () => assertTokenHistoryTransition,
138
139
  byteDifferenceState: () => byteDifferenceState,
@@ -143,9 +144,11 @@ __export(index_exports, {
143
144
  chapterMetadata: () => chapterMetadata,
144
145
  checkFrame: () => checkFrame,
145
146
  colors: () => colors,
147
+ combineSoftmaxMass: () => combineSoftmaxMass,
146
148
  compareByteSequences: () => compareByteSequences,
147
149
  compositeColor: () => compositeColor,
148
150
  createCanvasComponents: () => createCanvasComponents,
151
+ createCanvasReadback: () => createCanvasReadback,
149
152
  createCueTrack: () => createCueTrack,
150
153
  createFocusDirector: () => createFocusDirector,
151
154
  createPlotArea: () => createPlotArea,
@@ -155,9 +158,11 @@ __export(index_exports, {
155
158
  createTeachingCategoricalSampling: () => createTeachingCategoricalSampling,
156
159
  createTeachingFocus: () => createTeachingFocus,
157
160
  createTeachingRoutedTransfer: () => createTeachingRoutedTransfer,
161
+ createTeachingTileTransfer: () => createTeachingTileTransfer,
158
162
  createTeachingTokenHistory: () => createTeachingTokenHistory,
159
163
  createTeachingValueChange: () => createTeachingValueChange,
160
164
  createTeachingVectorAccumulation: () => createTeachingVectorAccumulation,
165
+ createTeachingWaveform: () => createTeachingWaveform,
161
166
  cropPixels: () => cropPixels,
162
167
  cropRgbImage: () => cropRgbImage,
163
168
  cropRgbRaster: () => cropRgbRaster,
@@ -212,6 +217,7 @@ __export(index_exports, {
212
217
  lerpArray: () => lerpArray,
213
218
  loadAdditionalAsset: () => loadAdditionalAsset,
214
219
  mapNumberLine: () => mapNumberLine,
220
+ measureRegionChange: () => measureRegionChange,
215
221
  mergeFocusRegions: () => mergeFocusRegions,
216
222
  morphPolyline: () => morphPolyline,
217
223
  multiplyMatrices: () => multiplyMatrices,
@@ -219,6 +225,10 @@ __export(index_exports, {
219
225
  normalizeWatermark: () => normalizeWatermark,
220
226
  parallel: () => parallel,
221
227
  parseDensity: () => parseDensity,
228
+ pcmEnvelope: () => pcmEnvelope,
229
+ planAvcSplice: () => planAvcSplice,
230
+ planMediaExcerpt: () => planMediaExcerpt,
231
+ planSampleCopies: () => planSampleCopies,
222
232
  planTeachingRoutedTransfer: () => planTeachingRoutedTransfer,
223
233
  pointAlongPath: () => pointAlongPath,
224
234
  prepareScene: () => prepareScene,
@@ -237,6 +247,7 @@ __export(index_exports, {
237
247
  renderToPng: () => renderToPng,
238
248
  renderToPngWithOutput: () => renderToPngWithOutput,
239
249
  renderToSvg: () => renderToSvg,
250
+ resolveH264Encoder: () => resolveH264Encoder,
240
251
  rgbChannel: () => rgbChannel,
241
252
  sampleAnimation: () => sampleAnimation,
242
253
  sampleAnimationFrame: () => sampleAnimationFrame,
@@ -250,12 +261,14 @@ __export(index_exports, {
250
261
  setDefaultDensity: () => setDefaultDensity,
251
262
  setDensityResolver: () => setDensityResolver,
252
263
  smoothstep: () => smoothstep,
264
+ softmaxTileMass: () => softmaxTileMass,
253
265
  stableSoftmax: () => stableSoftmax,
254
266
  statusColor: () => statusColor,
255
267
  styles: () => styles,
256
268
  sumForces: () => sumForces,
257
269
  tokenHistoryState: () => tokenHistoryState,
258
270
  toneGradients: () => toneGradients,
271
+ traceCrossCorrelation2d: () => traceCrossCorrelation2d,
259
272
  tracePolyline: () => tracePolyline,
260
273
  transposeMatrix: () => transposeMatrix,
261
274
  tween: () => tween,
@@ -971,6 +984,7 @@ __export(primitives_exports, {
971
984
  scopeDensity: () => scopeDensity,
972
985
  statusColor: () => statusColor,
973
986
  sumForces: () => sumForces,
987
+ traceCrossCorrelation2d: () => traceCrossCorrelation2d,
974
988
  transposeMatrix: () => transposeMatrix,
975
989
  waveValue: () => waveValue
976
990
  });
@@ -12728,6 +12742,45 @@ function stableSoftmax(values, temperature = 1) {
12728
12742
  const total = weights.reduce((sum, value) => sum + value, 0);
12729
12743
  return weights.map((value) => value / total);
12730
12744
  }
12745
+ function combineSoftmaxMass(tiles, reference) {
12746
+ if (reference !== void 0) finite2(reference, "Softmax reference");
12747
+ let largest = -Infinity;
12748
+ for (const tile of tiles) {
12749
+ if (tile.mass === 0 && tile.weightedSum === 0 && tile.reference === -Infinity) continue;
12750
+ finite2(tile.reference, "Tile reference");
12751
+ finite2(tile.mass, "Tile mass");
12752
+ finite2(tile.weightedSum, "Tile weighted sum");
12753
+ if (tile.mass <= 0) throw new Error("A nonempty tile needs positive mass");
12754
+ largest = Math.max(largest, tile.reference);
12755
+ }
12756
+ if (largest === -Infinity) return { reference: -Infinity, mass: 0, weightedSum: 0 };
12757
+ const target = reference ?? largest;
12758
+ if (target < largest) throw new Error("Softmax reference must cover all nonempty tiles");
12759
+ let mass = 0, weightedSum = 0;
12760
+ for (const tile of tiles) {
12761
+ if (tile.mass === 0) continue;
12762
+ const scale = Math.exp(tile.reference - target);
12763
+ mass += scale * tile.mass;
12764
+ weightedSum += scale * tile.weightedSum;
12765
+ }
12766
+ finite2(mass, "Combined mass");
12767
+ finite2(weightedSum, "Combined weighted sum");
12768
+ if (mass < 2 ** -1022) throw new Error("Combined mass is too small at this reference");
12769
+ return { reference: target, mass, weightedSum };
12770
+ }
12771
+ function softmaxTileMass(scores, values, allowed) {
12772
+ if (scores.length !== values.length || allowed !== void 0 && allowed.length !== scores.length) {
12773
+ throw new Error("Scores, values and mask must have equal lengths");
12774
+ }
12775
+ const terms = [];
12776
+ for (let i = 0; i < scores.length; i++) {
12777
+ finite2(scores[i], "Softmax score");
12778
+ finite2(values[i], "Softmax value");
12779
+ if (allowed !== void 0 && typeof allowed[i] !== "boolean") throw new Error("Softmax mask entries must be booleans");
12780
+ if (allowed?.[i] !== false) terms.push({ reference: scores[i], mass: 1, weightedSum: values[i] });
12781
+ }
12782
+ return combineSoftmaxMass(terms);
12783
+ }
12731
12784
  function entropy(probabilities, base = 2) {
12732
12785
  finite2(base, "Entropy base");
12733
12786
  if (base <= 0 || base === 1) throw new Error("Entropy base must be positive and different from one");
@@ -13129,7 +13182,7 @@ function validateMatrix2(matrix, name) {
13129
13182
  }
13130
13183
  return { rows: matrix.length, columns };
13131
13184
  }
13132
- function crossCorrelate2d(input, kernel, options = {}) {
13185
+ function prepareCorrelation(input, kernel, options) {
13133
13186
  const inputShape = validateMatrix2(input, "Input image");
13134
13187
  const kernelShape = validateMatrix2(kernel, "Kernel");
13135
13188
  const stride = options.stride ?? 1;
@@ -13149,24 +13202,51 @@ function crossCorrelate2d(input, kernel, options = {}) {
13149
13202
  const totalPaddingColumns = Math.max((outputColumns - 1) * stride + kernelShape.columns - inputShape.columns, 0);
13150
13203
  const topPadding = Math.floor(totalPaddingRows / 2);
13151
13204
  const leftPadding = Math.floor(totalPaddingColumns / 2);
13152
- const result = Array.from({ length: outputRows }, (_, outputRow) => Array.from({ length: outputColumns }, (_2, outputColumn) => {
13205
+ function sumAt(outputRow, outputColumn, terms) {
13206
+ const top = outputRow * stride - topPadding;
13207
+ const left = outputColumn * stride - leftPadding;
13153
13208
  let sum = 0;
13154
- for (let kernelRow = 0; kernelRow < kernelShape.rows; kernelRow += 1) {
13155
- const inputRow = outputRow * stride + kernelRow - topPadding;
13156
- if (inputRow < 0 || inputRow >= inputShape.rows) continue;
13157
- for (let kernelColumn = 0; kernelColumn < kernelShape.columns; kernelColumn += 1) {
13158
- const inputColumn = outputColumn * stride + kernelColumn - leftPadding;
13159
- if (inputColumn < 0 || inputColumn >= inputShape.columns) continue;
13160
- sum += input[inputRow][inputColumn] * kernel[kernelRow][kernelColumn];
13209
+ for (let r = 0; r < kernelShape.rows; r += 1) {
13210
+ const inputRow = top + r;
13211
+ const outsideRow = inputRow < 0 || inputRow >= inputShape.rows;
13212
+ if (outsideRow && !terms) continue;
13213
+ const pixels = input[inputRow];
13214
+ const weights = kernel[r];
13215
+ const rowTerms = terms?.[r];
13216
+ for (let c = 0; c < weights.length; c += 1) {
13217
+ const inputColumn = left + c;
13218
+ const padded = outsideRow || inputColumn < 0 || inputColumn >= inputShape.columns;
13219
+ const inputValue = padded ? 0 : pixels[inputColumn];
13220
+ const weight = weights[c];
13221
+ const product = padded ? 0 : inputValue * weight;
13222
+ sum += product;
13223
+ rowTerms?.push({ inputRow, inputColumn, inputValue, weight, product, padded });
13161
13224
  }
13162
13225
  }
13163
- if (!Number.isFinite(sum)) {
13164
- throw new Error("Kernel output values must be finite numbers");
13165
- }
13226
+ if (!Number.isFinite(sum)) throw new Error("Kernel output values must be finite numbers");
13166
13227
  return sum;
13167
- }));
13228
+ }
13229
+ return { outputRows, outputColumns, sumAt };
13230
+ }
13231
+ function crossCorrelate2d(input, kernel, options = {}) {
13232
+ const { outputRows, outputColumns, sumAt } = prepareCorrelation(input, kernel, options);
13233
+ const result = [];
13234
+ for (let r = 0; r < outputRows; r += 1) {
13235
+ const row = new Array(outputColumns);
13236
+ for (let c = 0; c < outputColumns; c += 1) row[c] = sumAt(r, c);
13237
+ result.push(row);
13238
+ }
13168
13239
  return result;
13169
13240
  }
13241
+ function traceCrossCorrelation2d(input, kernel, outputRow, outputColumn, options = {}) {
13242
+ const { outputRows, outputColumns, sumAt } = prepareCorrelation(input, kernel, options);
13243
+ if (!Number.isInteger(outputRow) || outputRow < 0 || outputRow >= outputRows || !Number.isInteger(outputColumn) || outputColumn < 0 || outputColumn >= outputColumns) {
13244
+ throw new RangeError(`Kernel output cell (${outputRow}, ${outputColumn}) is outside the ${outputRows} by ${outputColumns} grid`);
13245
+ }
13246
+ const terms = kernel.map(() => []);
13247
+ const sum = sumAt(outputRow, outputColumn, terms);
13248
+ return { outputRow, outputColumn, terms, sum };
13249
+ }
13170
13250
  function gaussianKernel(size, sigma) {
13171
13251
  if (!Number.isSafeInteger(size) || size < 1 || size % 2 === 0) {
13172
13252
  throw new Error("Gaussian kernel size must be a positive odd integer");
@@ -15936,6 +16016,36 @@ var import_path2 = require("path");
15936
16016
  var gifenc = __toESM(require("gifenc"), 1);
15937
16017
  var import_parse_css_color2 = __toESM(require("parse-css-color"), 1);
15938
16018
 
16019
+ // src/region-change.ts
16020
+ function measureRegionChange(reference, current, { width, height, region, tolerance = 12 }) {
16021
+ const bytes = width * height * 4;
16022
+ if (![width, height, bytes].every(Number.isSafeInteger) || width < 1 || height < 1 || reference.length !== bytes || current.length !== bytes) {
16023
+ throw new RangeError("Both RGBA frames must match the given positive pixel dimensions");
16024
+ }
16025
+ const { x, y, width: columns, height: rows } = region;
16026
+ if (![x, y, columns, rows].every(Number.isSafeInteger) || x < 0 || y < 0 || columns < 1 || rows < 1 || x + columns > width || y + rows > height) {
16027
+ throw new RangeError("The region must be a nonempty integer rectangle inside the frame");
16028
+ }
16029
+ if (!Number.isInteger(tolerance) || tolerance < 0 || tolerance > 255) {
16030
+ throw new RangeError("Channel tolerance must be an integer from 0 to 255");
16031
+ }
16032
+ let changedPixels = 0;
16033
+ let left = x + columns, right = -1, top = y + rows, bottom = -1;
16034
+ for (let row = y; row < y + rows; row++) {
16035
+ let i = (row * width + x) * 4;
16036
+ for (let col = x; col < x + columns; col++, i += 4) {
16037
+ if (Math.abs(reference[i] - current[i]) <= tolerance && Math.abs(reference[i + 1] - current[i + 1]) <= tolerance && Math.abs(reference[i + 2] - current[i + 2]) <= tolerance && Math.abs(reference[i + 3] - current[i + 3]) <= tolerance) continue;
16038
+ changedPixels++;
16039
+ left = Math.min(left, col);
16040
+ right = Math.max(right, col);
16041
+ top = Math.min(top, row);
16042
+ bottom = row;
16043
+ }
16044
+ }
16045
+ const bounds4 = changedPixels ? { x: left, y: top, width: right - left + 1, height: bottom - top + 1 } : void 0;
16046
+ return { changedPixels, bounds: bounds4 };
16047
+ }
16048
+
15939
16049
  // src/timeline.ts
15940
16050
  var MIN_FPS = 1;
15941
16051
  var MAX_FPS = 50;
@@ -16373,28 +16483,6 @@ function sharedPalette(frames) {
16373
16483
  }
16374
16484
  return quantize(combined, 256, { format: "rgba4444", oneBitAlpha: true });
16375
16485
  }
16376
- function changedBounds(previous, current, width, height) {
16377
- let minX = width;
16378
- let minY = height;
16379
- let maxX = -1;
16380
- let maxY = -1;
16381
- for (let index = 0; index < current.length; index += 4) {
16382
- if (previous[index] === current[index] && previous[index + 1] === current[index + 1] && previous[index + 2] === current[index + 2] && previous[index + 3] === current[index + 3]) continue;
16383
- const pixel = index / 4;
16384
- const x = pixel % width;
16385
- const y = Math.floor(pixel / width);
16386
- minX = Math.min(minX, x);
16387
- minY = Math.min(minY, y);
16388
- maxX = Math.max(maxX, x);
16389
- maxY = Math.max(maxY, y);
16390
- }
16391
- return maxX < minX ? void 0 : {
16392
- x: minX,
16393
- y: minY,
16394
- width: maxX - minX + 1,
16395
- height: maxY - minY + 1
16396
- };
16397
- }
16398
16486
  function cropFramePixels(pixels, canvasWidth, region) {
16399
16487
  const output = new Uint8Array(region.width * region.height * 4);
16400
16488
  for (let y = 0; y < region.height; y += 1) {
@@ -16405,7 +16493,13 @@ function cropFramePixels(pixels, canvasWidth, region) {
16405
16493
  }
16406
16494
  function deltaPixelFrame(frame, previous, enabled) {
16407
16495
  if (!enabled || !previous) return frame;
16408
- const bounds4 = changedBounds(previous, frame.pixels, frame.width, frame.height);
16496
+ const { width, height } = frame;
16497
+ const { bounds: bounds4 } = measureRegionChange(previous, frame.pixels, {
16498
+ width,
16499
+ height,
16500
+ region: { x: 0, y: 0, width, height },
16501
+ tolerance: 0
16502
+ });
16409
16503
  if (!bounds4 || bounds4.width === frame.width && bounds4.height === frame.height) return frame;
16410
16504
  return {
16411
16505
  ...frame,
@@ -17161,6 +17255,60 @@ function createTeachingTransfer(painter) {
17161
17255
  };
17162
17256
  }
17163
17257
 
17258
+ // src/teaching-waveform.ts
17259
+ function pcmEnvelope(samples, options) {
17260
+ const { sampleRate, bins, startTime = 0 } = options;
17261
+ if (!Number.isSafeInteger(sampleRate) || sampleRate <= 0) throw new Error("PCM sample rate must be a positive integer");
17262
+ if (!Number.isSafeInteger(bins) || bins <= 0) throw new Error("PCM bin count must be a positive integer");
17263
+ if (!Number.isFinite(startTime)) throw new Error("PCM start time must be finite");
17264
+ const count = Math.min(samples.length, bins);
17265
+ const result = [];
17266
+ for (let bin = 0; bin < count; bin++) {
17267
+ const startSample = Math.floor(bin * samples.length / count);
17268
+ const endSample = Math.floor((bin + 1) * samples.length / count);
17269
+ let min = Infinity, max = -Infinity;
17270
+ for (let i = startSample; i < endSample; i++) {
17271
+ const sample = samples[i];
17272
+ if (!Number.isFinite(sample) || Math.abs(sample) > 1) throw new Error("PCM samples must be finite and between -1 and 1");
17273
+ min = Math.min(min, sample);
17274
+ max = Math.max(max, sample);
17275
+ }
17276
+ result.push({ startSample, endSample, min, max });
17277
+ }
17278
+ return { sampleRate, startTime, bins: result };
17279
+ }
17280
+ function createTeachingWaveform(painter) {
17281
+ return function waveform({ x, y, width, height, envelope, domain, color = "#63DEEC", cursorTime, reveal = false, cursorColor = "#FFFFFF" }) {
17282
+ const [from, to] = domain;
17283
+ if (![x, y, width, height, from, to].every(Number.isFinite) || width <= 0 || height <= 0 || to <= from)
17284
+ throw new Error("Waveform requires finite positive bounds and an increasing time domain");
17285
+ if (cursorTime !== void 0 && !Number.isFinite(cursorTime)) throw new Error("Waveform cursor time must be finite");
17286
+ if (reveal && cursorTime === void 0) throw new Error("A waveform reveal requires a cursor time");
17287
+ const project = (t) => x + (t - from) / (to - from) * width;
17288
+ const amplitude = (a) => y + height * (1 - a) / 2;
17289
+ const upper = [], lower = [];
17290
+ for (const bin of envelope.bins) {
17291
+ const start = envelope.startTime + bin.startSample / envelope.sampleRate;
17292
+ const end = envelope.startTime + bin.endSample / envelope.sampleRate;
17293
+ if (start >= to || reveal && end > cursorTime) break;
17294
+ if (end <= from) continue;
17295
+ const left = project(Math.max(from, start)), right = project(Math.min(to, end));
17296
+ upper.push({ x: left, y: amplitude(bin.max) }, { x: right, y: amplitude(bin.max) });
17297
+ lower.push({ x: left, y: amplitude(bin.min) }, { x: right, y: amplitude(bin.min) });
17298
+ }
17299
+ if (upper.length) painter.path([...upper, ...lower.reverse()], {
17300
+ clip: { x, y, width, height },
17301
+ color,
17302
+ width: 1,
17303
+ fill: color,
17304
+ closed: true
17305
+ });
17306
+ const cursorX = cursorTime !== void 0 && cursorTime >= from && cursorTime <= to ? project(cursorTime) : null;
17307
+ if (cursorX !== null) painter.line(cursorX, y, cursorX, y + height, cursorColor, 1);
17308
+ return { cursorX };
17309
+ };
17310
+ }
17311
+
17164
17312
  // src/teaching-grid.ts
17165
17313
  function positive4(value, name) {
17166
17314
  if (!Number.isFinite(value) || value <= 0) throw new Error(`${name} must be finite and positive`);
@@ -17269,6 +17417,110 @@ function createTeachingGrid(painter) {
17269
17417
  };
17270
17418
  }
17271
17419
 
17420
+ // src/teaching-raster-wipe.ts
17421
+ function createTeachingRasterWipe(painter) {
17422
+ return function rasterWipe(options) {
17423
+ const { x, y, width, height, rows, columns, left, right, split, color } = options;
17424
+ if (![x, y, width, height, x + width, y + height].every(Number.isFinite) || width <= 0 || height <= 0) {
17425
+ throw new Error("Raster bounds must be finite and have positive dimensions");
17426
+ }
17427
+ if (![rows, columns, rows * columns].every(Number.isSafeInteger) || rows < 1 || columns < 1) {
17428
+ throw new Error("Raster rows and columns must be positive safe integers");
17429
+ }
17430
+ if (left.length !== rows * columns || right.length !== rows * columns) {
17431
+ throw new Error("Both rasters must match the declared rows and columns");
17432
+ }
17433
+ if (!Number.isFinite(split) || split < 0 || split > 1) {
17434
+ throw new Error("Raster split must be a fraction between zero and one");
17435
+ }
17436
+ const edge = options.snapToPixels ? (v) => Math.ceil(v - 0.5) : (v) => v;
17437
+ const dividerX = edge(x + width * split);
17438
+ for (let row = 0; row < rows; row++) {
17439
+ const top = edge(y + height * (row / rows));
17440
+ const bottom = edge(y + height * ((row + 1) / rows));
17441
+ if (top === bottom) continue;
17442
+ for (let column = 0; column < columns; column++) {
17443
+ const start = edge(x + width * (column / columns));
17444
+ const end = edge(x + width * ((column + 1) / columns));
17445
+ if (start === end) continue;
17446
+ const cut = Math.max(start, Math.min(end, dividerX));
17447
+ const index = row * columns + column;
17448
+ if (start < cut && cut < end) {
17449
+ const leftColor = color(left[index], row, column);
17450
+ const rightColor = color(right[index], row, column);
17451
+ if (leftColor !== rightColor) {
17452
+ painter.rect(start, top, cut - start, bottom - top, leftColor, void 0, 0);
17453
+ painter.rect(cut, top, end - cut, bottom - top, rightColor, void 0, 0);
17454
+ continue;
17455
+ }
17456
+ painter.rect(start, top, end - start, bottom - top, leftColor, void 0, 0);
17457
+ } else {
17458
+ const field = cut === end ? left : right;
17459
+ painter.rect(start, top, end - start, bottom - top, color(field[index], row, column), void 0, 0);
17460
+ }
17461
+ }
17462
+ }
17463
+ return { dividerX };
17464
+ };
17465
+ }
17466
+
17467
+ // src/teaching-tile-transfer.ts
17468
+ function createTeachingTileTransfer(painter) {
17469
+ return (options) => {
17470
+ const { source, target, cells, rowStagger = 0, gap = 3, fontSize = 24 } = options;
17471
+ const rows = cells.length, columns = cells[0]?.length ?? 0;
17472
+ if (!columns || cells.some((row) => row.length !== columns)) throw new Error("A tile requires a nonempty rectangle of cells");
17473
+ if (!Number.isFinite(options.progress)) throw new Error("Tile transfer progress must be finite");
17474
+ if (!Number.isFinite(rowStagger) || rowStagger < 0 || rowStagger >= 1) throw new Error("Tile row stagger must be in [0, 1)");
17475
+ if (!Number.isFinite(gap) || gap < 0 || !Number.isFinite(fontSize) || fontSize <= 0) throw new Error("Invalid tile gap or font size");
17476
+ for (const endpoint2 of [source, target]) {
17477
+ const first = endpoint2.grid.cell(endpoint2.row ?? 0, endpoint2.column ?? 0);
17478
+ endpoint2.grid.cell((endpoint2.row ?? 0) + rows - 1, (endpoint2.column ?? 0) + columns - 1);
17479
+ if (gap >= Math.min(first.width, first.height)) throw new Error("Tile gap must be smaller than a cell at both endpoints");
17480
+ }
17481
+ const clock = Math.max(0, Math.min(1, options.progress));
17482
+ const stagger = rows > 1 ? rowStagger : 0;
17483
+ let arrived = 0;
17484
+ const shapes = cells.map((line, row) => {
17485
+ const delay = rows > 1 ? row / (rows - 1) * stagger : 0;
17486
+ const progress = clock === 1 ? 1 : Math.max(0, Math.min(1, (clock - delay) / (1 - stagger)));
17487
+ if (progress === 1) arrived += columns;
17488
+ return line.map((cell, column) => {
17489
+ const from = source.grid.cell((source.row ?? 0) + row, (source.column ?? 0) + column);
17490
+ const to = target.grid.cell((target.row ?? 0) + row, (target.column ?? 0) + column);
17491
+ const x = from.x + (to.x - from.x) * progress + gap / 2;
17492
+ const y = from.y + (to.y - from.y) * progress + gap / 2;
17493
+ const width = from.width + (to.width - from.width) * progress - gap;
17494
+ const height = from.height + (to.height - from.height) * progress - gap;
17495
+ const shape = painter.rect(
17496
+ x,
17497
+ y,
17498
+ width,
17499
+ height,
17500
+ cell.fill ?? options.fill ?? "#18283B",
17501
+ cell.stroke ?? options.stroke ?? "#63DEEC",
17502
+ 0
17503
+ );
17504
+ if (cell.label !== void 0) {
17505
+ painter.labelScope(
17506
+ { x, y, width, height },
17507
+ () => painter.text(
17508
+ String(cell.label),
17509
+ x + width / 2,
17510
+ y + height / 2 + fontSize * 0.34,
17511
+ fontSize,
17512
+ cell.textColor ?? options.textColor ?? "#FFFFFF",
17513
+ "center"
17514
+ )
17515
+ );
17516
+ }
17517
+ return shape;
17518
+ });
17519
+ });
17520
+ return { cells: shapes, arrived, complete: arrived === rows * columns };
17521
+ };
17522
+ }
17523
+
17272
17524
  // src/teaching-timeline.ts
17273
17525
  function createTeachingTimeline(painter) {
17274
17526
  const target = (id, draw) => id && painter.target ? painter.target(id, draw) : draw();
@@ -18627,9 +18879,12 @@ function createTeachingCanvas(painter) {
18627
18879
  scatter,
18628
18880
  bars,
18629
18881
  flowGraph,
18882
+ waveform: createTeachingWaveform(painter),
18630
18883
  transfer: createTeachingTransfer(painter),
18631
18884
  routedTransfer: createTeachingRoutedTransfer(painter),
18632
18885
  grid: createTeachingGrid(painter),
18886
+ rasterWipe: createTeachingRasterWipe(painter),
18887
+ tileTransfer: createTeachingTileTransfer(painter),
18633
18888
  timeline: createTeachingTimeline(painter),
18634
18889
  allocation: createTeachingAllocation(painter),
18635
18890
  vectorAccumulation: createTeachingVectorAccumulation(painter),
@@ -18681,6 +18936,60 @@ function createCueTrack(options) {
18681
18936
  }
18682
18937
  });
18683
18938
  }
18939
+ function assertCueReveal({ result, phrase, fromFrame, cueFrame, byFrame = cueFrame, visibleAt }) {
18940
+ if (!result.trim() || !phrase.trim()) throw new Error("A cue reveal needs a result and a spoken phrase");
18941
+ if (![fromFrame, cueFrame, byFrame].every(Number.isSafeInteger) || fromFrame < 0 || fromFrame >= cueFrame || cueFrame > byFrame) {
18942
+ throw new RangeError("Cue reveal frames must be safe integers with 0 <= fromFrame < cueFrame <= byFrame");
18943
+ }
18944
+ for (let frame = fromFrame; frame <= byFrame; frame++) {
18945
+ const visible = visibleAt(frame);
18946
+ if (typeof visible !== "boolean") throw new TypeError(`Expected a boolean observation of "${result}" at frame ${frame}`);
18947
+ if (!visible) continue;
18948
+ if (frame < cueFrame) throw new Error(`"${result}" is visible at frame ${frame}, before "${phrase}" permits it at frame ${cueFrame}`);
18949
+ return { lastHiddenFrame: frame - 1, firstVisibleFrame: frame };
18950
+ }
18951
+ throw new Error(`"${result}" is still missing at frame ${byFrame} for "${phrase}" (cue frame ${cueFrame})`);
18952
+ }
18953
+
18954
+ // src/sample-copies.ts
18955
+ function planSampleCopies(sources, destinations) {
18956
+ const positions = /* @__PURE__ */ new Map();
18957
+ const checkPoint = (point) => {
18958
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y)) throw new Error("Sample coordinates must be finite");
18959
+ };
18960
+ for (const source of sources) {
18961
+ if (!source.id.trim() || positions.has(source.id)) throw new Error("Sample sources require unique, nonempty IDs");
18962
+ checkPoint(source);
18963
+ positions.set(source.id, { x: source.x, y: source.y });
18964
+ }
18965
+ const counts2 = /* @__PURE__ */ new Map();
18966
+ const draws = destinations.map(({ sourceId, x, y }) => {
18967
+ const source = positions.get(sourceId);
18968
+ if (!source) throw new Error(`Unknown sample source: ${sourceId}`);
18969
+ checkPoint({ x, y });
18970
+ const occurrence = (counts2.get(sourceId) ?? 0) + 1;
18971
+ counts2.set(sourceId, occurrence);
18972
+ return { sourceId, source, x, y, occurrence };
18973
+ });
18974
+ return {
18975
+ /** At 1.5 draws, the first copy is in its slot and the next is halfway there. */
18976
+ at(drawCount) {
18977
+ if (!Number.isFinite(drawCount)) throw new Error("Sample draw count must be finite");
18978
+ const count = Math.max(0, Math.min(draws.length, drawCount));
18979
+ return draws.slice(0, Math.ceil(count)).map((draw, drawIndex) => {
18980
+ const progress = Math.min(1, count - drawIndex);
18981
+ return {
18982
+ sourceId: draw.sourceId,
18983
+ drawIndex,
18984
+ occurrence: draw.occurrence,
18985
+ progress,
18986
+ x: (1 - progress) * draw.source.x + progress * draw.x,
18987
+ y: (1 - progress) * draw.source.y + progress * draw.y
18988
+ };
18989
+ });
18990
+ }
18991
+ };
18992
+ }
18684
18993
 
18685
18994
  // src/camera-motion.ts
18686
18995
  function clampProgress3(progress) {
@@ -18838,7 +19147,10 @@ function morphPolyline(from, to, progress, options = {}) {
18838
19147
  var import_child_process = require("child_process");
18839
19148
  var import_crypto = require("crypto");
18840
19149
  var import_promises3 = require("fs/promises");
19150
+ var import_net = require("net");
19151
+ var import_readline = require("readline");
18841
19152
  var import_path3 = require("path");
19153
+ var import_promises4 = require("timers/promises");
18842
19154
  var import_resvg_js3 = require("@resvg/resvg-js");
18843
19155
  var import_parse_css_color4 = __toESM(require("parse-css-color"), 1);
18844
19156
  function chapterMetadata(title, chapters, duration) {
@@ -18970,7 +19282,11 @@ function abortError() {
18970
19282
  }
18971
19283
  function withAbort(promise, signal) {
18972
19284
  if (!signal) return promise;
18973
- if (signal.aborted) return Promise.reject(abortError());
19285
+ if (signal.aborted) {
19286
+ promise.catch(() => {
19287
+ });
19288
+ return Promise.reject(abortError());
19289
+ }
18974
19290
  return new Promise((resolvePromise, rejectPromise) => {
18975
19291
  const cleanup = () => signal.removeEventListener("abort", onAbort);
18976
19292
  const onAbort = () => {
@@ -19014,6 +19330,191 @@ async function stopEncoder(child, exited) {
19014
19330
  await exited;
19015
19331
  }
19016
19332
  }
19333
+ var LOOPBACK = "127.0.0.1";
19334
+ async function loopbackPair() {
19335
+ if (process.platform !== "darwin" || process.env.VIZMATIC_FFMPEG_PIPE === "1") return void 0;
19336
+ const server = (0, import_net.createServer)({ allowHalfOpen: true });
19337
+ const sockets = [];
19338
+ let timer;
19339
+ try {
19340
+ return await new Promise((resolvePair, rejectPair) => {
19341
+ timer = setTimeout(() => rejectPair(new Error("The loopback connection timed out.")), 2e3);
19342
+ let ours;
19343
+ let theirs;
19344
+ let connected = false;
19345
+ const finish = () => {
19346
+ if (!ours || !theirs || !connected) return;
19347
+ const pair = theirs.localAddress === LOOPBACK && ours.remoteAddress === theirs.localAddress && ours.remotePort === theirs.localPort;
19348
+ if (pair) resolvePair({ ours, theirs });
19349
+ else rejectPair(new Error("The loopback connection came from another process."));
19350
+ };
19351
+ server.once("error", rejectPair);
19352
+ server.once("connection", (socket) => {
19353
+ server.close();
19354
+ sockets.push(socket);
19355
+ ours = socket;
19356
+ finish();
19357
+ });
19358
+ server.listen(0, LOOPBACK, () => {
19359
+ const address = server.address();
19360
+ if (!address || typeof address === "string") {
19361
+ rejectPair(new Error("The loopback server has no port."));
19362
+ return;
19363
+ }
19364
+ theirs = (0, import_net.connect)(address.port, LOOPBACK);
19365
+ sockets.push(theirs);
19366
+ theirs.once("error", rejectPair);
19367
+ theirs.once("connect", () => {
19368
+ connected = true;
19369
+ finish();
19370
+ });
19371
+ });
19372
+ });
19373
+ } catch {
19374
+ for (const socket of sockets) socket.destroy();
19375
+ return void 0;
19376
+ } finally {
19377
+ if (timer) clearTimeout(timer);
19378
+ server.close();
19379
+ }
19380
+ }
19381
+ var ffmpegOptions = /* @__PURE__ */ new Map();
19382
+ function videoToolboxArgs({ width, height, fps }) {
19383
+ const args = ["-c:v", "h264_videotoolbox", "-allow_sw", "0", "-profile:v", "high", "-q:v", "75", "-g", "250"];
19384
+ const blocks = Math.ceil(width / 16) * Math.ceil(height / 16);
19385
+ if (blocks <= 8192 && blocks * fps <= 245760) args.push("-level:v", "4.0");
19386
+ else if (blocks <= 8704 && blocks * fps <= 522240) args.push("-level:v", "4.2");
19387
+ return args;
19388
+ }
19389
+ async function verifyHardwareFrames(ffmpeg, path, count, fps, signal) {
19390
+ const seen = new Uint8Array(Math.ceil(count / 8));
19391
+ const child = (0, import_child_process.spawn)(ffmpeg, [
19392
+ "-nostdin",
19393
+ "-v",
19394
+ "error",
19395
+ "-xerror",
19396
+ "-copyts",
19397
+ "-i",
19398
+ path,
19399
+ "-map",
19400
+ "0:v:0",
19401
+ "-c:v",
19402
+ "copy",
19403
+ "-avoid_negative_ts",
19404
+ "disabled",
19405
+ "-f",
19406
+ "framecrc",
19407
+ "pipe:1"
19408
+ ], { stdio: ["ignore", "pipe", "pipe"], signal });
19409
+ let timeScale = 0, timeUnit = 0, packets = 0;
19410
+ let stderr = "", invalid = false;
19411
+ child.stderr.on("data", (chunk) => {
19412
+ stderr = (stderr + chunk).slice(-MAX_STDERR_CHARS);
19413
+ });
19414
+ const lines = (0, import_readline.createInterface)({ input: child.stdout });
19415
+ lines.on("line", (line) => {
19416
+ if (line.startsWith("#")) {
19417
+ const clock = /^#tb 0:\s*(\d+)\/(\d+)$/.exec(line);
19418
+ if (clock) {
19419
+ timeUnit = Number(clock[1]);
19420
+ timeScale = Number(clock[2]);
19421
+ }
19422
+ return;
19423
+ }
19424
+ const pts = /^0,\s*-?\d+,\s*(-?\d+),/.exec(line);
19425
+ const index = pts ? Number(pts[1]) * timeUnit * fps / timeScale : NaN;
19426
+ if (!timeScale || !timeUnit || !Number.isSafeInteger(index) || index < 0 || index >= count) {
19427
+ invalid = true;
19428
+ return;
19429
+ }
19430
+ const byte = Math.floor(index / 8), mask = 1 << index % 8;
19431
+ if (seen[byte] & mask) invalid = true;
19432
+ seen[byte] = seen[byte] | mask;
19433
+ packets++;
19434
+ });
19435
+ await new Promise((done, fail) => {
19436
+ child.once("error", fail);
19437
+ child.once("close", (code, sig) => code === 0 ? done() : fail(describeExit(code, sig, stderr)));
19438
+ });
19439
+ if (invalid || packets !== count) {
19440
+ let missing = 0;
19441
+ while (missing < count && seen[Math.floor(missing / 8)] & 1 << missing % 8) missing++;
19442
+ const detail = missing < count ? `; missing frame ${missing}` : "";
19443
+ throw new Error(`VideoToolbox packet timing mismatch: expected ${count} frames at ${fps} fps, found ${packets}${detail}`);
19444
+ }
19445
+ }
19446
+ var hardwareProbes = /* @__PURE__ */ new Map();
19447
+ async function resolveH264Encoder(requested = "libx264", ffmpegPath = "ffmpeg", format = { width: 1920, height: 1080, fps: 30 }) {
19448
+ if (requested === "libx264") return requested;
19449
+ if (requested !== "videotoolbox") throw new Error("h264Encoder must be libx264 or videotoolbox");
19450
+ const { width, height, fps } = format;
19451
+ 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");
19452
+ const key = JSON.stringify([ffmpegPath, width, height, fps]);
19453
+ let probe = hardwareProbes.get(key);
19454
+ if (!probe) {
19455
+ probe = new Promise((done) => {
19456
+ const args = [
19457
+ "-nostdin",
19458
+ "-v",
19459
+ "error",
19460
+ "-f",
19461
+ "lavfi",
19462
+ "-i",
19463
+ `color=size=${width}x${height}:rate=${fps}`,
19464
+ "-frames:v",
19465
+ "1",
19466
+ ...videoToolboxArgs(format),
19467
+ "-pix_fmt",
19468
+ "yuv420p",
19469
+ "-f",
19470
+ "null",
19471
+ "-"
19472
+ ];
19473
+ const child = (0, import_child_process.execFile)(ffmpegPath, args, { timeout: 15e3, killSignal: "SIGKILL", maxBuffer: 65536 }, (error) => {
19474
+ if (error) hardwareProbes.delete(key);
19475
+ done(!error);
19476
+ });
19477
+ child.stdin?.end();
19478
+ });
19479
+ hardwareProbes.set(key, probe);
19480
+ }
19481
+ return await probe ? requested : "libx264";
19482
+ }
19483
+ function hasFfmpegOption(ffmpegPath, component, option) {
19484
+ const key = JSON.stringify([ffmpegPath, component, option]);
19485
+ let answer = ffmpegOptions.get(key);
19486
+ if (!answer) {
19487
+ answer = new Promise((done) => {
19488
+ const child = (0, import_child_process.execFile)(ffmpegPath, ["-hide_banner", "-h", component], { maxBuffer: 1 << 20 }, (error, stdout) => {
19489
+ done(!error && stdout.includes(option));
19490
+ });
19491
+ child.stdin?.end();
19492
+ });
19493
+ ffmpegOptions.set(key, answer);
19494
+ }
19495
+ return answer;
19496
+ }
19497
+ function hasMovieTimescale(ffmpegPath) {
19498
+ return hasFfmpegOption(ffmpegPath, "muxer=mp4", "movie_timescale");
19499
+ }
19500
+ function rgbaIvfHeader(width, height, fps, frames) {
19501
+ const header = Buffer.alloc(32);
19502
+ header.write("DKIF");
19503
+ header.writeUInt16LE(32, 6);
19504
+ header.write("RGBA", 8);
19505
+ header.writeUInt16LE(width, 12);
19506
+ header.writeUInt16LE(height, 14);
19507
+ header.writeUInt32LE(fps, 16);
19508
+ header.writeUInt32LE(1, 20);
19509
+ header.writeUInt32LE(frames, 24);
19510
+ return header;
19511
+ }
19512
+ function rgbaPacketHeader(bytes, index) {
19513
+ const header = Buffer.alloc(12);
19514
+ header.writeUInt32LE(bytes);
19515
+ header.writeBigUInt64LE(BigInt(index), 4);
19516
+ return header;
19517
+ }
19017
19518
  async function renderRgbaVideo(renderFrame2, options) {
19018
19519
  const fps = options.fps ?? 30;
19019
19520
  const schedule = validateTiming(options.duration, fps);
@@ -19028,6 +19529,11 @@ async function renderRgbaVideo(renderFrame2, options) {
19028
19529
  if (!Number.isSafeInteger(expectedBytes)) {
19029
19530
  throw new Error("frame dimensions are too large");
19030
19531
  }
19532
+ const repeat = options.frameIsRepeat;
19533
+ if (repeat !== void 0 && typeof repeat !== "function") throw new Error("frameIsRepeat must be a function");
19534
+ if (repeat && (width > 65535 || height > 65535 || expectedBytes > 2147483647 || schedule.count > 4294967295)) {
19535
+ throw new Error("Timestamped RGBA frames exceed the IVF packet or header limits");
19536
+ }
19031
19537
  if (typeof renderFrame2 !== "function") throw new Error("renderFrame must be a function");
19032
19538
  if (typeof options.outputPath !== "string" || options.outputPath.length === 0) {
19033
19539
  throw new Error("outputPath must be a non-empty path");
@@ -19045,6 +19551,9 @@ async function renderRgbaVideo(renderFrame2, options) {
19045
19551
  if (options.tune !== void 0 && (typeof options.tune !== "string" || options.tune.length === 0)) {
19046
19552
  throw new Error("tune must be a non-empty string when provided");
19047
19553
  }
19554
+ if (options.x264Params !== void 0 && (typeof options.x264Params !== "string" || options.x264Params.length === 0)) {
19555
+ throw new Error("x264Params must be a non-empty string when provided");
19556
+ }
19048
19557
  if (options.audioOffset !== void 0 && (!Number.isFinite(options.audioOffset) || options.audioOffset < 0)) {
19049
19558
  throw new Error("audioOffset must be a non-negative finite number of seconds");
19050
19559
  }
@@ -19053,6 +19562,13 @@ async function renderRgbaVideo(renderFrame2, options) {
19053
19562
  throw new Error("audioPath must be a non-empty path when provided");
19054
19563
  }
19055
19564
  if (options.signal?.aborted) throw abortError();
19565
+ if (codec !== "h264" && (options.h264Encoder !== void 0 || options.requireH264Encoder))
19566
+ throw new Error("h264Encoder applies only to H.264 output");
19567
+ const requested = options.h264Encoder ?? "libx264";
19568
+ const useSoftwareSettings = crf !== 18 || options.x264Params !== void 0 || options.tune !== void 0 && options.tune !== "animation";
19569
+ const h264Encoder = requested === "videotoolbox" && useSoftwareSettings ? "libx264" : await withAbort(resolveH264Encoder(requested, ffmpegPath, { width, height, fps }), options.signal);
19570
+ if (options.requireH264Encoder && requested !== h264Encoder)
19571
+ throw new Error(`Requested H.264 encoder ${requested} is unavailable for these settings`);
19056
19572
  const outputPath = (0, import_path3.resolve)(options.outputPath);
19057
19573
  const outputDirectory = (0, import_path3.dirname)(outputPath);
19058
19574
  await (0, import_promises3.mkdir)(outputDirectory, { recursive: true });
@@ -19067,19 +19583,16 @@ async function renderRgbaVideo(renderFrame2, options) {
19067
19583
  }
19068
19584
  const seconds = formatSeconds(schedule.duration);
19069
19585
  const args = [
19586
+ // If the encoder gets no frame, it must fail. Without this flag, it writes a movie with no frames
19587
+ // and reports success.
19070
19588
  "-hide_banner",
19071
19589
  "-loglevel",
19072
19590
  "error",
19073
19591
  "-nostdin",
19074
19592
  "-y",
19075
- "-f",
19076
- "rawvideo",
19077
- "-pixel_format",
19078
- "rgba",
19079
- "-video_size",
19080
- `${width}x${height}`,
19081
- "-framerate",
19082
- String(fps),
19593
+ "-abort_on",
19594
+ "empty_output",
19595
+ ...repeat ? ["-f", "ivf", "-fpsprobesize", "0", "-probesize", "32", "-analyzeduration", "1"] : ["-f", "rawvideo", "-pixel_format", "rgba", "-video_size", `${width}x${height}`, "-framerate", String(fps)],
19083
19596
  "-i",
19084
19597
  "pipe:0"
19085
19598
  ];
@@ -19114,37 +19627,52 @@ async function renderRgbaVideo(renderFrame2, options) {
19114
19627
  if (options.audioPath) args.push("-map", `${audioInput}:a:0`, "-af", `asetpts=PTS-STARTPTS,apad,atrim=duration=${seconds}`);
19115
19628
  if (captionInput >= 0) args.push("-map", `${captionInput}:0`, "-c:s", "mov_text", "-metadata:s:s:0", "language=eng");
19116
19629
  if (metadataInput >= 0) args.push("-map_metadata", String(metadataInput), "-map_chapters", String(metadataInput));
19117
- args.push("-frames:v", String(schedule.count), "-t", seconds, "-vf", COLOR_FILTER);
19630
+ args.push("-frames:v", String(schedule.count), "-t", seconds, "-vf", repeat ? `${COLOR_FILTER},fps=${fps}` : COLOR_FILTER);
19118
19631
  if (codec === "vp9") {
19119
19632
  args.push("-c:v", "libvpx-vp9", "-crf", String(crf), "-b:v", "0", "-deadline", "good", "-cpu-used", "2", "-row-mt", "1", "-threads:v", String(threads));
19633
+ } else if (h264Encoder === "videotoolbox") {
19634
+ args.push(...videoToolboxArgs({ width, height, fps }));
19120
19635
  } else {
19121
19636
  args.push("-c:v", "libx264", "-preset", preset);
19122
19637
  if (options.tune) args.push("-tune", options.tune);
19123
19638
  if (options.tune === "animation" || /slow|placebo/.test(preset)) args.push("-refs", "4");
19124
- args.push("-crf", String(crf), "-threads:v", String(threads));
19639
+ args.push("-crf", String(crf));
19640
+ if (options.x264Params) args.push("-x264-params", options.x264Params);
19641
+ args.push("-threads:v", String(threads));
19125
19642
  }
19126
19643
  args.push("-pix_fmt", "yuv420p", ...COLOR_TAGS);
19127
19644
  if (options.audioPath) {
19128
19645
  if (codec === "vp9") args.push("-c:a", "libopus", "-b:a", "160k", "-ar", "48000", "-ac", "2");
19129
- else args.push("-c:a", "aac", "-b:a", "192k", "-ar", "48000", "-ac", "2");
19646
+ else {
19647
+ args.push("-c:a", "aac", "-b:a", "384k", "-ar", "48000", "-ac", "2");
19648
+ if (await hasFfmpegOption(ffmpegPath, "encoder=aac", "-aac_pns")) args.push("-aac_pns", "0");
19649
+ }
19650
+ }
19651
+ if (codec === "h264") {
19652
+ args.push("-movflags", "+faststart");
19653
+ if (metadataInput >= 0 && await hasMovieTimescale(ffmpegPath)) args.push("-movie_timescale", "1000");
19130
19654
  }
19131
- if (codec === "h264") args.push("-movflags", "+faststart");
19132
19655
  args.push(tempPath);
19133
19656
  let stderr = "";
19134
19657
  let inputError;
19135
19658
  let child;
19659
+ const pair = await loopbackPair();
19136
19660
  try {
19137
- child = (0, import_child_process.spawn)(ffmpegPath, args, { stdio: ["pipe", "ignore", "pipe"] });
19661
+ child = (0, import_child_process.spawn)(ffmpegPath, args, { stdio: [pair ? pair.theirs : "pipe", "ignore", "pipe"] });
19138
19662
  } catch (error) {
19663
+ pair?.ours.destroy();
19664
+ pair?.theirs.destroy();
19139
19665
  await (0, import_promises3.rm)(tempPath, { force: true });
19140
19666
  for (const path of sidecars) await (0, import_promises3.rm)(path, { force: true });
19141
19667
  throw error;
19142
19668
  }
19669
+ pair?.theirs.destroy();
19670
+ const frameInput = pair ? pair.ours : child.stdin;
19143
19671
  child.stderr?.on("data", (chunk) => {
19144
19672
  stderr += chunk.toString();
19145
19673
  if (stderr.length > MAX_STDERR_CHARS) stderr = stderr.slice(-MAX_STDERR_CHARS);
19146
19674
  });
19147
- child.stdin?.on("error", (error) => {
19675
+ frameInput?.on("error", (error) => {
19148
19676
  inputError = error;
19149
19677
  });
19150
19678
  let exitResult;
@@ -19196,8 +19724,18 @@ async function renderRgbaVideo(renderFrame2, options) {
19196
19724
  });
19197
19725
  }
19198
19726
  try {
19199
- const input = child.stdin;
19727
+ const input = frameInput;
19200
19728
  if (!input) throw new Error("FFmpeg did not provide a frame input stream");
19729
+ const writeFrameBytes = (bytes, index) => {
19730
+ const write = new Promise((done, fail) => {
19731
+ input.write(bytes, (error) => error ? fail(error) : done());
19732
+ });
19733
+ return withAbort(observeEncoder(write, index, true), options.signal);
19734
+ };
19735
+ let packets = 0;
19736
+ let lastPacket = -1;
19737
+ let previous;
19738
+ if (repeat) await writeFrameBytes(rgbaIvfHeader(width, height, fps, schedule.count), 0);
19201
19739
  for (let index = 0; index < schedule.count; index++) {
19202
19740
  const info = frameInfo(index, schedule, fps);
19203
19741
  const rendered = await withAbort(observeEncoder(Promise.resolve(renderFrame2(info)), index, false), options.signal);
@@ -19205,11 +19743,26 @@ async function renderRgbaVideo(renderFrame2, options) {
19205
19743
  throw new Error(`Frame ${index} must contain exactly ${expectedBytes} RGBA bytes`);
19206
19744
  }
19207
19745
  if (inputError) throw describeExit(null, null, inputError.message || stderr);
19208
- const pixels = Buffer.from(rendered.buffer, rendered.byteOffset, rendered.byteLength);
19209
- const write = new Promise((resolvePromise, rejectPromise) => {
19210
- input.write(pixels, (error) => error ? rejectPromise(error) : resolvePromise());
19211
- });
19212
- await withAbort(observeEncoder(write, index, true), options.signal);
19746
+ const hint = repeat?.(info);
19747
+ let unchanged = hint === true;
19748
+ if (hint === "compare") {
19749
+ unchanged = previous?.equals(rendered) === true;
19750
+ if (!unchanged) {
19751
+ previous ??= Buffer.allocUnsafeSlow(expectedBytes);
19752
+ previous.set(rendered);
19753
+ }
19754
+ } else {
19755
+ previous = void 0;
19756
+ }
19757
+ if (!unchanged || index === 0 || index === schedule.count - 1 || index - lastPacket >= 16) {
19758
+ if (repeat) await writeFrameBytes(rgbaPacketHeader(expectedBytes, index), index);
19759
+ const pixels = Buffer.from(rendered.buffer, rendered.byteOffset, rendered.byteLength);
19760
+ await writeFrameBytes(pixels, index);
19761
+ lastPacket = index;
19762
+ packets++;
19763
+ } else if (hint === "compare") {
19764
+ await (0, import_promises4.setImmediate)();
19765
+ }
19213
19766
  if (options.onProgress) {
19214
19767
  await withAbort(observeEncoder(Promise.resolve(options.onProgress(info)), index, false), options.signal);
19215
19768
  }
@@ -19218,6 +19771,7 @@ async function renderRgbaVideo(renderFrame2, options) {
19218
19771
  const exit = await withAbort(exited, options.signal);
19219
19772
  if (exit.error) throw new Error(`Unable to start FFmpeg: ${exit.error.message}`, { cause: exit.error });
19220
19773
  if (exit.code !== 0) throw describeExit(exit.code, exit.signal, stderr);
19774
+ if (h264Encoder === "videotoolbox") await verifyHardwareFrames(ffmpegPath, tempPath, schedule.count, fps, options.signal);
19221
19775
  const outputStat = await (0, import_promises3.stat)(tempPath);
19222
19776
  await (0, import_promises3.chmod)(tempPath, 420);
19223
19777
  await (0, import_promises3.rename)(tempPath, outputPath);
@@ -19229,25 +19783,381 @@ async function renderRgbaVideo(renderFrame2, options) {
19229
19783
  fps,
19230
19784
  bytes: outputStat.size,
19231
19785
  outputPath,
19232
- audioIncluded: options.audioPath !== void 0
19786
+ audioIncluded: options.audioPath !== void 0,
19787
+ ...repeat && { rgbaPackets: packets },
19788
+ ...codec === "h264" ? { h264Encoder } : {}
19233
19789
  };
19234
19790
  } catch (error) {
19235
19791
  await stopEncoder(child, exited);
19236
- if (inputError && error instanceof Error && (error.message === "write EPIPE" || error.code === "EPIPE")) {
19792
+ const code = error?.code;
19793
+ if (inputError && error instanceof Error && (error.message === "write EPIPE" || code === "EPIPE" || code === "ECONNRESET")) {
19237
19794
  throw describeExit(null, null, stderr || inputError.message);
19238
19795
  }
19239
19796
  throw error;
19240
19797
  } finally {
19798
+ pair?.ours.destroy();
19241
19799
  await (0, import_promises3.rm)(tempPath, { force: true });
19242
19800
  for (const path of sidecars) await (0, import_promises3.rm)(path, { force: true });
19243
19801
  }
19244
19802
  }
19245
19803
 
19804
+ // src/canvas-readback.ts
19805
+ var calls = /* @__PURE__ */ new Set([
19806
+ "arc",
19807
+ "beginPath",
19808
+ "clearRect",
19809
+ "clip",
19810
+ "closePath",
19811
+ "fill",
19812
+ "fillRect",
19813
+ "fillText",
19814
+ "lineTo",
19815
+ "moveTo",
19816
+ "restore",
19817
+ "roundRect",
19818
+ "save",
19819
+ "scale",
19820
+ "setLineDash",
19821
+ "stroke"
19822
+ ]);
19823
+ var settings = /* @__PURE__ */ new Set(["fillStyle", "font", "lineCap", "lineJoin", "lineWidth", "strokeStyle", "textAlign", "textBaseline"]);
19824
+ var assign = /* @__PURE__ */ Symbol("assign");
19825
+ var invoke = /* @__PURE__ */ Symbol("invoke");
19826
+ var dash = /* @__PURE__ */ Symbol("dash");
19827
+ var scalar = (v) => typeof v === "string" || typeof v === "boolean" || typeof v === "number" && Number.isFinite(v);
19828
+ function createCanvasReadback(context, readPixels) {
19829
+ let available = true, active = false, tape = [], previous;
19830
+ let pixels, reused = 0, frames = 0;
19831
+ const methods = /* @__PURE__ */ new Map();
19832
+ const disable = () => {
19833
+ available = false;
19834
+ previous = void 0;
19835
+ pixels = void 0;
19836
+ };
19837
+ const observed = new Proxy(context, {
19838
+ get(target, key) {
19839
+ if (!active || typeof key !== "string" || !calls.has(key)) disable();
19840
+ let value;
19841
+ try {
19842
+ value = Reflect.get(target, key, target);
19843
+ } catch (error) {
19844
+ disable();
19845
+ throw error;
19846
+ }
19847
+ if (typeof value === "function") {
19848
+ const descriptor = Reflect.getOwnPropertyDescriptor(target, key);
19849
+ if (descriptor && !descriptor.configurable && "value" in descriptor && !descriptor.writable) {
19850
+ disable();
19851
+ return value;
19852
+ }
19853
+ }
19854
+ if (typeof key !== "string" || !calls.has(key) || typeof value !== "function") {
19855
+ disable();
19856
+ return typeof value === "function" ? value.bind(target) : value;
19857
+ }
19858
+ const fn = value;
19859
+ let cached = methods.get(key);
19860
+ if (!cached || cached.raw !== fn) {
19861
+ if (cached) disable();
19862
+ const wrapped = (...args) => {
19863
+ if (!available) return Reflect.apply(fn, target, args);
19864
+ const isDash = key === "setLineDash" && args.length === 1;
19865
+ if (!active || !isDash && !args.every(scalar)) disable();
19866
+ try {
19867
+ const result = Reflect.apply(fn, target, args);
19868
+ if (available && isDash) {
19869
+ const readDash = Reflect.get(target, "getLineDash", target);
19870
+ if (typeof readDash !== "function") disable();
19871
+ else {
19872
+ const segments = Reflect.apply(readDash, target, []);
19873
+ if (Array.isArray(segments) && segments.every(scalar)) tape.push(dash, segments.length, ...segments);
19874
+ else disable();
19875
+ }
19876
+ } else if (available) tape.push(invoke, key, args.length, ...args);
19877
+ return result;
19878
+ } catch (error) {
19879
+ disable();
19880
+ throw error;
19881
+ }
19882
+ };
19883
+ cached = { raw: fn, wrapped };
19884
+ methods.set(key, cached);
19885
+ }
19886
+ return cached.wrapped;
19887
+ },
19888
+ set(target, key, value) {
19889
+ if (!active || typeof key !== "string" || !settings.has(key) || !scalar(value)) disable();
19890
+ let accepted;
19891
+ try {
19892
+ accepted = Reflect.set(target, key, value, target);
19893
+ } catch (error) {
19894
+ disable();
19895
+ throw error;
19896
+ }
19897
+ if (!accepted) disable();
19898
+ else if (available) tape.push(assign, key, value);
19899
+ return accepted;
19900
+ },
19901
+ defineProperty(target, key, descriptor) {
19902
+ disable();
19903
+ return Reflect.defineProperty(target, key, descriptor);
19904
+ },
19905
+ deleteProperty(target, key) {
19906
+ disable();
19907
+ return Reflect.deleteProperty(target, key);
19908
+ },
19909
+ getOwnPropertyDescriptor(target, key) {
19910
+ disable();
19911
+ return Reflect.getOwnPropertyDescriptor(target, key);
19912
+ },
19913
+ getPrototypeOf(target) {
19914
+ disable();
19915
+ return Reflect.getPrototypeOf(target);
19916
+ },
19917
+ setPrototypeOf(target, proto) {
19918
+ disable();
19919
+ return Reflect.setPrototypeOf(target, proto);
19920
+ }
19921
+ });
19922
+ return {
19923
+ frame(draw) {
19924
+ if (active) throw new Error("Canvas readback is already drawing a frame");
19925
+ tape = [];
19926
+ active = true;
19927
+ try {
19928
+ context.reset();
19929
+ const result = draw(observed);
19930
+ if (result && typeof result.then === "function") throw new TypeError("Canvas drawing must be synchronous");
19931
+ if (available && previous && pixels && tape.length === previous.length && tape.every((v, i) => Object.is(v, previous[i]))) {
19932
+ frames++;
19933
+ reused++;
19934
+ return pixels;
19935
+ }
19936
+ const next = readPixels();
19937
+ frames++;
19938
+ if (available) {
19939
+ pixels = next;
19940
+ previous = tape;
19941
+ }
19942
+ return next;
19943
+ } catch (error) {
19944
+ disable();
19945
+ throw error;
19946
+ } finally {
19947
+ tape = [];
19948
+ active = false;
19949
+ }
19950
+ },
19951
+ stats: () => ({ frames, reused, tracking: available })
19952
+ };
19953
+ }
19954
+
19955
+ // src/avc-splice.ts
19956
+ var import_node_child_process = require("child_process");
19957
+ var import_promises5 = require("fs/promises");
19958
+ var import_node_path = require("path");
19959
+ var formatFields = [
19960
+ "extradata_hash",
19961
+ "profile",
19962
+ "level",
19963
+ "width",
19964
+ "height",
19965
+ "pix_fmt",
19966
+ "field_order",
19967
+ "sample_aspect_ratio",
19968
+ "display_aspect_ratio",
19969
+ "color_range",
19970
+ "color_space",
19971
+ "color_transfer",
19972
+ "color_primaries",
19973
+ "chroma_location",
19974
+ "has_b_frames",
19975
+ "r_frame_rate",
19976
+ "avg_frame_rate",
19977
+ "time_base",
19978
+ "nal_length_size",
19979
+ "side_data_list"
19980
+ ];
19981
+ function command(binary, args, input) {
19982
+ return new Promise((accept, reject) => {
19983
+ const child = (0, import_node_child_process.execFile)(binary, args, { maxBuffer: 64 * 1024 * 1024, encoding: "utf8" }, (err, out) => {
19984
+ if (err) reject(err);
19985
+ else accept(out);
19986
+ });
19987
+ child.stdin?.on("error", (error) => {
19988
+ if (error.code !== "EPIPE") reject(error);
19989
+ });
19990
+ child.stdin?.end(input);
19991
+ });
19992
+ }
19993
+ async function inspect(path) {
19994
+ if (!(await (0, import_promises5.stat)(path)).isFile()) throw new Error("Expected a local MP4 file");
19995
+ const base = ["-v", "error", "-f", "mov", "-protocol_whitelist", "file", "-select_streams", "v"];
19996
+ const info = JSON.parse(await command("ffprobe", [...base, "-show_streams", "-show_data_hash", "sha256", "-of", "json", path]));
19997
+ const [v] = info.streams;
19998
+ if (info.streams.length !== 1 || v.index !== 0 || v.codec_name !== "h264" || v.codec_tag_string !== "avc1" || v.is_avc !== "true" || v.start_pts !== 0 || !v.extradata_hash || v.disposition?.attached_pic)
19999
+ throw new Error("Expected one zero-based avc1 video track at stream index 0");
20000
+ const [baseNum, baseDen] = v.time_base.split("/").map(Number);
20001
+ const [fpsNum, fpsDen] = v.r_frame_rate.split("/").map(Number);
20002
+ const step = fpsDen * baseDen / (fpsNum * baseNum);
20003
+ if (![baseNum, baseDen, fpsNum, fpsDen, step].every((n) => Number.isSafeInteger(n) && n > 0))
20004
+ throw new Error("Expected constant frame duration in track ticks");
20005
+ const packets = JSON.parse(await command("ffprobe", [
20006
+ ...base,
20007
+ "-show_packets",
20008
+ "-show_entries",
20009
+ "packet=pts,dts,duration,pos,size,flags,data_hash,side_data_list",
20010
+ "-show_data_hash",
20011
+ "sha256",
20012
+ "-of",
20013
+ "json",
20014
+ path
20015
+ ])).packets;
20016
+ if (!packets?.length || packets.length !== Number(v.nb_frames) || ![1, 2, 4].includes(Number(v.nal_length_size)))
20017
+ throw new Error("Incomplete AVC packet table");
20018
+ if (packets.some((packet) => packet.side_data_list?.length))
20019
+ throw new Error("AVC packet side data is unsupported for stream-copy planning");
20020
+ return {
20021
+ packets,
20022
+ step,
20023
+ baseNum,
20024
+ baseDen,
20025
+ timeBase: v.time_base,
20026
+ nalBytes: Number(v.nal_length_size),
20027
+ format: JSON.stringify(formatFields.map((field) => v[field])),
20028
+ firstDts: packets[0].dts
20029
+ };
20030
+ }
20031
+ async function checkIdr(path, packet, nalBytes) {
20032
+ if (!packet.flags.includes("K")) throw new Error("Cut must start at an IDR picture");
20033
+ const file = await (0, import_promises5.open)(path, "r");
20034
+ try {
20035
+ const end = Number(packet.pos) + Number(packet.size);
20036
+ let at = Number(packet.pos);
20037
+ let idr = false;
20038
+ const header = Buffer.alloc(nalBytes + 1);
20039
+ while (at < end) {
20040
+ const { bytesRead } = await file.read(header, 0, header.length, at);
20041
+ const size = header.readUIntBE(0, nalBytes);
20042
+ if (bytesRead !== header.length || size === 0 || at + nalBytes + size > end)
20043
+ throw new Error("Invalid AVC NAL length at cut");
20044
+ const type = header[nalBytes] & 31;
20045
+ if (type >= 1 && type <= 4 || type >= 19 && type <= 21)
20046
+ throw new Error("Cut contains a non-IDR slice");
20047
+ if (type === 5) idr = true;
20048
+ at += nalBytes + size;
20049
+ }
20050
+ if (!idr) throw new Error("Cut must start at an IDR picture");
20051
+ } finally {
20052
+ await file.close();
20053
+ }
20054
+ }
20055
+ async function planAvcSplice(segments) {
20056
+ if (!segments.length) throw new Error("Supply at least one frame range");
20057
+ const sources = /* @__PURE__ */ new Map();
20058
+ const lines = ["ffconcat version 1.0"];
20059
+ const expected = [];
20060
+ let frameCount = 0;
20061
+ let format;
20062
+ let firstDts;
20063
+ let timeBase;
20064
+ for (const { path, startFrame, endFrame } of segments) {
20065
+ if (![startFrame, endFrame].every(Number.isSafeInteger) || startFrame < 0 || endFrame <= startFrame)
20066
+ throw new RangeError("Expected a nonempty half-open frame range");
20067
+ const absolute = await (0, import_promises5.realpath)((0, import_node_path.resolve)(path));
20068
+ if (/[\r\n\0]/.test(absolute)) throw new Error("Invalid ffconcat filename");
20069
+ const source = sources.get(absolute) ?? await inspect(absolute);
20070
+ sources.set(absolute, source);
20071
+ const { packets, step, baseNum, baseDen } = source;
20072
+ if (endFrame > packets.length) throw new RangeError("Frame range exceeds the video track");
20073
+ format ??= source.format;
20074
+ firstDts ??= source.firstDts;
20075
+ timeBase ??= source.timeBase;
20076
+ if (source.format !== format || source.firstDts !== firstDts)
20077
+ throw new Error("AVC configuration, presentation format or decode clock differs");
20078
+ await checkIdr(absolute, packets[startFrame], source.nalBytes);
20079
+ if (endFrame < packets.length) await checkIdr(absolute, packets[endFrame], source.nalBytes);
20080
+ const displayed = /* @__PURE__ */ new Set();
20081
+ const shift = (frameCount - startFrame) * step;
20082
+ for (let i = startFrame; i < endFrame; i++) {
20083
+ const p = packets[i];
20084
+ const frame = p.pts / step;
20085
+ if (!Number.isSafeInteger(frame) || frame < startFrame || frame >= endFrame || displayed.has(frame) || /[CD]/.test(p.flags) || p.dts !== firstDts + i * step || p.duration !== step || !/^SHA256:[a-f0-9]{64}$/.test(p.data_hash))
20086
+ throw new Error("Cut crosses a picture dependency or an irregular packet clock");
20087
+ displayed.add(frame);
20088
+ expected.push([p.dts + shift, p.pts + shift, step, p.size, p.data_hash.slice(7)].join(","));
20089
+ }
20090
+ if (packets[startFrame].pts !== startFrame * step || endFrame < packets.length && packets[endFrame].pts !== endFrame * step)
20091
+ throw new Error("IDR does not start at the requested presentation frame");
20092
+ const time = (ticks) => (ticks * baseNum / baseDen).toFixed(6);
20093
+ lines.push("file 'file:" + absolute.replaceAll("'", "'\\''") + "'");
20094
+ if (startFrame) lines.push("inpoint " + time(startFrame * step));
20095
+ if (endFrame < packets.length) lines.push("outpoint " + time(packets[endFrame].dts));
20096
+ lines.push("duration " + time((endFrame - startFrame) * step));
20097
+ frameCount += endFrame - startFrame;
20098
+ }
20099
+ const concatScript = lines.join("\n") + "\n";
20100
+ const audit = await command("ffmpeg", [
20101
+ "-nostdin",
20102
+ "-v",
20103
+ "error",
20104
+ "-xerror",
20105
+ "-copyts",
20106
+ "-f",
20107
+ "concat",
20108
+ "-safe",
20109
+ "0",
20110
+ "-auto_convert",
20111
+ "0",
20112
+ "-protocol_whitelist",
20113
+ "file,pipe",
20114
+ "-i",
20115
+ "pipe:0",
20116
+ "-map",
20117
+ "0:v:0",
20118
+ "-c:v",
20119
+ "copy",
20120
+ "-f",
20121
+ "framehash",
20122
+ "-hash",
20123
+ "sha256",
20124
+ "-"
20125
+ ], concatScript);
20126
+ const auditLines = audit.trimEnd().split(/\r?\n/);
20127
+ if (!auditLines.includes("#tb 0: " + timeBase)) throw new Error("FFmpeg changed the video time base");
20128
+ const actual = auditLines.filter((line) => !line.startsWith("#"));
20129
+ if (actual.length !== expected.length || actual.some((row, i) => row.split(",").slice(1).map((s) => s.trim()).join(",") !== expected[i]))
20130
+ throw new Error("FFmpeg stream copy changed packet clocks or payloads");
20131
+ return { concatScript, frameCount };
20132
+ }
20133
+
20134
+ // src/media-excerpt.ts
20135
+ function planMediaExcerpt({ startFrame, frameCount, fps, sampleRate }) {
20136
+ if (!Number.isSafeInteger(startFrame) || startFrame < 0 || !Number.isSafeInteger(frameCount) || frameCount <= 0)
20137
+ throw new RangeError("Expected a nonnegative startFrame and a positive frameCount");
20138
+ if (![fps, sampleRate].every((rate) => Number.isInteger(rate) && rate > 0 && rate <= 2147483647))
20139
+ throw new RangeError("Expected positive integer source frame and sample rates");
20140
+ const endFrame = startFrame + frameCount;
20141
+ if (!Number.isSafeInteger(endFrame)) throw new RangeError("Frame range exceeds the exact source clock");
20142
+ const sampleAt = (frame) => (BigInt(frame) * BigInt(sampleRate) + BigInt(fps - 1)) / BigInt(fps);
20143
+ const endSample = sampleAt(endFrame);
20144
+ if (endSample > BigInt(Number.MAX_SAFE_INTEGER)) throw new RangeError("Frame range exceeds the exact sample clock");
20145
+ const inputArgs = ["-copyts", "-reinit_filter:v", "0"];
20146
+ const seek = Math.max(0, Math.floor(startFrame / fps) - 1);
20147
+ if (seek > 0) inputArgs.push("-ss", String(seek));
20148
+ inputArgs.push("-t", String(Math.ceil(endFrame / fps) - seek + 1));
20149
+ return {
20150
+ inputArgs,
20151
+ videoFilter: `settb=1/${fps},trim=start_pts=${startFrame}:end_pts=${endFrame},setpts=PTS-STARTPTS`,
20152
+ audioFilter: `atrim=start_pts=${sampleAt(startFrame)}:end_pts=${endSample},asetpts=PTS-STARTPTS`
20153
+ };
20154
+ }
20155
+
19246
20156
  // src/scene-renderer.ts
19247
20157
  var import_react22 = __toESM(require("react"), 1);
19248
- var import_promises4 = require("fs/promises");
20158
+ var import_promises6 = require("fs/promises");
19249
20159
  var import_node_fs = require("fs");
19250
- var import_node_path = require("path");
20160
+ var import_node_path2 = require("path");
19251
20161
  var import_node_url = require("url");
19252
20162
  var import_node_crypto = require("crypto");
19253
20163
  var import_node_zlib = require("zlib");
@@ -19731,11 +20641,18 @@ var componentNames = new Set(SCENE_COMPONENT_NAMES);
19731
20641
  var domTags = new Set(SCENE_DOM_TAGS);
19732
20642
  var localReference = /^#[A-Za-z_][\w:.-]*$/;
19733
20643
  var localPaint = /^url\(\s*#[A-Za-z_][\w:.-]*\s*\)$/;
19734
- var resourceKeys = /^(?:background(?:image)?|fill|stroke|filter|clippath|mask(?:image)?|borderimage(?:source)?|liststyle(?:image)?|cursor|content)$/i;
20644
+ var stylePropertyName = /^(?:--[A-Za-z0-9_-]+|-?[A-Za-z][A-Za-z0-9-]*)$/;
20645
+ var resourceKeys = /^(?:background(?:-?image)?|fill|stroke|filter|clip-?path|mask(?:-?image)?|border-?image(?:-?source)?|list-?style(?:-?image)?|marker(?:-(?:start|mid|end)|start|mid|end)?|shape-?outside|offset-?path|cursor|content)$/i;
20646
+ function isValidSceneStyleProperty(name) {
20647
+ return stylePropertyName.test(name) && !isUnsafeSceneKey(name);
20648
+ }
19735
20649
  function validateResource(value, key, inStyle) {
19736
20650
  if (/^(?:src|href|xlinkhref|xlink:href|srcset|poster|action|formaction)$/i.test(key) && !localReference.test(value)) {
19737
20651
  throw new Error("Scene resource references must be local SVG fragment IDs. External assets are disabled.");
19738
20652
  }
20653
+ if (inStyle && /[;{}]/.test(value)) {
20654
+ throw new Error("Scene CSS cannot contain declaration delimiters.");
20655
+ }
19739
20656
  if ((inStyle || resourceKeys.test(key) || /gradient$/i.test(key)) && (/\\|\/\*/.test(value) || /(?:https?|file|ftp|data|blob|javascript):|\/\//i.test(value) || /url\s*\(/i.test(value) && !localPaint.test(value))) {
19740
20657
  throw new Error("Scene CSS cannot load external resources or escaped resource expressions.");
19741
20658
  }
@@ -19749,6 +20666,7 @@ function validateResolvedSceneResources(props) {
19749
20666
  return;
19750
20667
  }
19751
20668
  if (Array.isArray(input)) {
20669
+ if (style) throw new Error("Scene style values must be strings or numbers.");
19752
20670
  input.forEach((item) => visit(item, key, style, depth + 1));
19753
20671
  return;
19754
20672
  }
@@ -19756,6 +20674,12 @@ function validateResolvedSceneResources(props) {
19756
20674
  for (const [property, value] of Object.entries(input)) {
19757
20675
  if (property === "children") continue;
19758
20676
  if (property === "dangerouslySetInnerHTML" || property === "__html") throw new Error("Resolved scene cannot contain raw HTML.");
20677
+ if (style && !isValidSceneStyleProperty(property)) {
20678
+ throw new Error(`Scene style property ${JSON.stringify(property)} is not allowed.`);
20679
+ }
20680
+ if (style && value !== void 0 && value !== null && typeof value !== "string" && typeof value !== "number") {
20681
+ throw new Error(`Scene style property ${JSON.stringify(property)} must be a string or number.`);
20682
+ }
19759
20683
  visit(value, property, style || /style$/i.test(property), depth + 1);
19760
20684
  }
19761
20685
  }
@@ -19767,7 +20691,10 @@ function validateSceneGraph(value) {
19767
20691
  const visit = (input, depth, key = "", inStyle = false) => {
19768
20692
  if (depth > SCENE_LIMITS.depth) throw new Error(`Scene graph exceeds depth ${SCENE_LIMITS.depth}.`);
19769
20693
  if (++nodes > SCENE_LIMITS.nodes * 32) throw new Error("Scene graph contains too many values.");
19770
- if (input === null || typeof input === "boolean") return input;
20694
+ if (input === null || typeof input === "boolean") {
20695
+ if (inStyle && typeof input === "boolean") throw new Error(`Scene style property ${JSON.stringify(key)} must be a string or number.`);
20696
+ return input;
20697
+ }
19771
20698
  if (typeof input === "number") {
19772
20699
  if (!Number.isFinite(input) || Math.abs(input) > 1e9) throw new Error("Scene numbers must be finite and bounded.");
19773
20700
  return input;
@@ -19777,12 +20704,23 @@ function validateSceneGraph(value) {
19777
20704
  validateResource(input, key, inStyle);
19778
20705
  return input;
19779
20706
  }
19780
- if (Array.isArray(input)) return input.map((item) => visit(item, depth + 1, key, inStyle));
20707
+ if (Array.isArray(input)) {
20708
+ if (inStyle) throw new Error("Scene style values must be strings or numbers.");
20709
+ return input.map((item) => visit(item, depth + 1, key, inStyle));
20710
+ }
19781
20711
  if (!input || typeof input !== "object" || Object.getPrototypeOf(input) !== Object.prototype && Object.getPrototypeOf(input) !== null) throw new Error("Scene props must be plain JSON values.");
19782
20712
  const record2 = input;
19783
20713
  const output = /* @__PURE__ */ Object.create(null);
19784
20714
  for (const [property, item] of Object.entries(record2)) {
19785
20715
  if (isUnsafeSceneKey(property) || /^on/i.test(property) || /^(?:xml:base|xmlBase)$/i.test(property) || property === "dangerouslySetInnerHTML" || property === "ref" || property === "__html") throw new Error(`Scene property ${JSON.stringify(property)} is not allowed.`);
20716
+ if (inStyle) {
20717
+ if (!isValidSceneStyleProperty(property)) {
20718
+ throw new Error(`Scene style property ${JSON.stringify(property)} is not allowed.`);
20719
+ }
20720
+ if (item !== null && typeof item !== "string" && typeof item !== "number") {
20721
+ throw new Error(`Scene style property ${JSON.stringify(property)} must be a string or number.`);
20722
+ }
20723
+ }
19786
20724
  output[property] = visit(item, depth + 1, property, inStyle || /style$/i.test(property));
19787
20725
  }
19788
20726
  if (record2.kind === "vizmatic.element") {
@@ -20036,11 +20974,11 @@ async function sceneAssets() {
20036
20974
  return assetsPromise;
20037
20975
  }
20038
20976
  async function loadSceneAssets() {
20039
- const moduleDir = typeof __dirname !== "undefined" ? __dirname : (0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(void 0));
20040
- const assetDir = (0, import_node_path.join)(moduleDir, "..", "assets");
20977
+ const moduleDir = typeof __dirname !== "undefined" ? __dirname : (0, import_node_path2.dirname)((0, import_node_url.fileURLToPath)(void 0));
20978
+ const assetDir = (0, import_node_path2.join)(moduleDir, "..", "assets");
20041
20979
  const files = /* @__PURE__ */ new Map();
20042
20980
  for (const [name, expected] of Object.entries(assetPins)) {
20043
- const bytes = await (0, import_promises4.readFile)((0, import_node_path.join)(assetDir, name));
20981
+ const bytes = await (0, import_promises6.readFile)((0, import_node_path2.join)(assetDir, name));
20044
20982
  if (await sceneSha256(bytes) !== expected) throw new Error(`Pinned scene asset does not match: ${name}`);
20045
20983
  files.set(name, bytes);
20046
20984
  }
@@ -20061,7 +20999,7 @@ async function loadSceneAssets() {
20061
20999
  style: style ?? "normal",
20062
21000
  data: Uint8Array.from(files.get(`fonts/${filename}`)).buffer
20063
21001
  })),
20064
- fontFiles: fontDefinitions.map(([, filename]) => (0, import_node_path.join)(assetDir, "fonts", filename)),
21002
+ fontFiles: fontDefinitions.map(([, filename]) => (0, import_node_path2.join)(assetDir, "fonts", filename)),
20065
21003
  emoji: JSON.parse((0, import_node_zlib.brotliDecompressSync)(files.get("emoji.json.br")).toString("utf8")),
20066
21004
  sha256: await sceneSha256(JSON.stringify(assetPins))
20067
21005
  };
@@ -20108,7 +21046,13 @@ function serializeSvg(node, budget, depth = 0) {
20108
21046
  validateResolvedSceneResources(node.props);
20109
21047
  const attributes = Object.entries(node.props).filter(([key, value]) => key !== "children" && key !== "key" && value !== void 0 && value !== null).map(([key, value]) => {
20110
21048
  if (key === "style" && typeof value === "object") {
20111
- const style = Object.entries(value).map(([property, item]) => `${svgAttribute(property)}:${String(item)}`).join(";");
21049
+ if (Array.isArray(value)) throw new Error("Unsupported SVG style attribute.");
21050
+ const style = Object.entries(value).filter(([, item]) => item !== void 0 && item !== null).map(([property, item]) => {
21051
+ if (!isValidSceneStyleProperty(property) || typeof item === "object" || typeof item === "function" || /[;{}]/.test(String(item))) {
21052
+ throw new Error(`Scene style property ${JSON.stringify(property)} is not allowed.`);
21053
+ }
21054
+ return `${svgAttribute(property)}:${String(item)}`;
21055
+ }).join(";");
20112
21056
  return ` style="${xml(style)}"`;
20113
21057
  }
20114
21058
  if (!/^[A-Za-z_][\w:.-]*$/.test(key) || typeof value === "object" || typeof value === "function") throw new Error("Unsupported SVG attribute.");
@@ -20208,7 +21152,7 @@ async function renderPreparedFrame(prepared, assets, time, outputScale, includeP
20208
21152
  return { pixels: image.pixels, ...includePng ? { png: image.asPng() } : {} };
20209
21153
  });
20210
21154
  }
20211
- async function outputMetadata(prepared, assets, settings, outputPath, bytes, kind, time) {
21155
+ async function outputMetadata(prepared, assets, settings2, outputPath, bytes, kind, time) {
20212
21156
  const { width, height, duration, fps, frameCount } = prepared.request;
20213
21157
  const digest = (0, import_node_crypto.createHash)("sha256");
20214
21158
  for await (const chunk of (0, import_node_fs.createReadStream)(outputPath)) digest.update(chunk);
@@ -20220,20 +21164,20 @@ async function outputMetadata(prepared, assets, settings, outputPath, bytes, kin
20220
21164
  fontAssetsSha256: assets.sha256,
20221
21165
  kind,
20222
21166
  ...time !== void 0 ? { time } : {},
20223
- ...settings.preview ? { outputScale: settings.outputScale, width: settings.width, height: settings.height, fps: settings.fps, frameCount: settings.frameCount } : {}
21167
+ ...settings2.preview ? { outputScale: settings2.outputScale, width: settings2.width, height: settings2.height, fps: settings2.fps, frameCount: settings2.frameCount } : {}
20224
21168
  })),
20225
21169
  assetSha256: digest.digest("hex"),
20226
21170
  fontAssetsSha256: assets.sha256,
20227
- width: settings.width,
20228
- height: settings.height,
21171
+ width: settings2.width,
21172
+ height: settings2.height,
20229
21173
  duration,
20230
- fps: settings.fps,
20231
- frameCount: settings.frameCount,
21174
+ fps: settings2.fps,
21175
+ frameCount: settings2.frameCount,
20232
21176
  bytes,
20233
- outputPath: (0, import_node_path.resolve)(outputPath),
20234
- ...settings.preview ? {
20235
- outputScale: settings.outputScale,
20236
- ...kind === "mp4" ? { previewFps: settings.fps } : {},
21177
+ outputPath: (0, import_node_path2.resolve)(outputPath),
21178
+ ...settings2.preview ? {
21179
+ outputScale: settings2.outputScale,
21180
+ ...kind === "mp4" ? { previewFps: settings2.fps } : {},
20237
21181
  logicalWidth: width,
20238
21182
  logicalHeight: height,
20239
21183
  logicalFps: fps,
@@ -20242,46 +21186,46 @@ async function outputMetadata(prepared, assets, settings, outputPath, bytes, kin
20242
21186
  };
20243
21187
  }
20244
21188
  async function atomicWrite(outputPath, bytes) {
20245
- const target = (0, import_node_path.resolve)(outputPath);
20246
- await (0, import_promises4.mkdir)((0, import_node_path.dirname)(target), { recursive: true });
20247
- const temporary = (0, import_node_path.join)((0, import_node_path.dirname)(target), `.vizmatic-scene-${(0, import_node_crypto.randomUUID)()}.tmp`);
20248
- const file = await (0, import_promises4.open)(temporary, "wx", 384);
21189
+ const target = (0, import_node_path2.resolve)(outputPath);
21190
+ await (0, import_promises6.mkdir)((0, import_node_path2.dirname)(target), { recursive: true });
21191
+ const temporary = (0, import_node_path2.join)((0, import_node_path2.dirname)(target), `.vizmatic-scene-${(0, import_node_crypto.randomUUID)()}.tmp`);
21192
+ const file = await (0, import_promises6.open)(temporary, "wx", 384);
20249
21193
  try {
20250
21194
  await file.writeFile(bytes);
20251
21195
  await file.close();
20252
- await (0, import_promises4.rename)(temporary, target);
21196
+ await (0, import_promises6.rename)(temporary, target);
20253
21197
  } catch (error) {
20254
21198
  await file.close().catch(() => {
20255
21199
  });
20256
- await (0, import_promises4.rm)(temporary, { force: true });
21200
+ await (0, import_promises6.rm)(temporary, { force: true });
20257
21201
  throw error;
20258
21202
  }
20259
21203
  }
20260
21204
  async function renderSceneFrame(options) {
20261
21205
  if (typeof options.outputPath !== "string" || !options.outputPath) throw new Error("Scene outputPath is required.");
20262
21206
  const prepared = await prepareScene(options);
20263
- const settings = outputSettings(prepared, options.outputScale);
21207
+ const settings2 = outputSettings(prepared, options.outputScale);
20264
21208
  const time = normalizeSceneTime(options.time, prepared.request.duration);
20265
21209
  const assets = await sceneAssets();
20266
- const image = await renderPreparedFrame(prepared, assets, time, settings.outputScale, true);
21210
+ const image = await renderPreparedFrame(prepared, assets, time, settings2.outputScale, true);
20267
21211
  await atomicWrite(options.outputPath, image.png);
20268
- return { ...await outputMetadata(prepared, assets, settings, options.outputPath, image.png.byteLength, "png", time), time };
21212
+ return { ...await outputMetadata(prepared, assets, settings2, options.outputPath, image.png.byteLength, "png", time), time };
20269
21213
  }
20270
21214
  async function renderSceneVideo(options) {
20271
21215
  if (typeof options.outputPath !== "string" || !options.outputPath) throw new Error("Scene outputPath is required.");
20272
21216
  const prepared = await prepareScene(options);
20273
- const settings = outputSettings(prepared, options.outputScale, options.previewFps);
21217
+ const settings2 = outputSettings(prepared, options.outputScale, options.previewFps);
20274
21218
  const assets = await sceneAssets();
20275
21219
  const { duration } = prepared.request;
20276
- const output = await renderRgbaVideo(async (frame) => (await renderPreparedFrame(prepared, assets, frame.time / 1e3, settings.outputScale, false)).pixels, {
20277
- width: settings.width,
20278
- height: settings.height,
21220
+ const output = await renderRgbaVideo(async (frame) => (await renderPreparedFrame(prepared, assets, frame.time / 1e3, settings2.outputScale, false)).pixels, {
21221
+ width: settings2.width,
21222
+ height: settings2.height,
20279
21223
  duration: duration * 1e3,
20280
- fps: settings.fps,
21224
+ fps: settings2.fps,
20281
21225
  outputPath: options.outputPath,
20282
21226
  signal: options.signal
20283
21227
  });
20284
- return { ...await outputMetadata(prepared, assets, settings, options.outputPath, output.bytes, "mp4"), encodedDuration: output.duration / 1e3 };
21228
+ return { ...await outputMetadata(prepared, assets, settings2, options.outputPath, output.bytes, "mp4"), encodedDuration: output.duration / 1e3 };
20285
21229
  }
20286
21230
 
20287
21231
  // src/import-types.ts
@@ -20369,7 +21313,7 @@ function readEndpoint(line, from) {
20369
21313
  { open: "(", close: ")", lossy: true },
20370
21314
  { open: "{", close: "}", lossy: true }
20371
21315
  ];
20372
- const delimiter = delimiters.find(({ open: open3 }) => rest.startsWith(open3));
21316
+ const delimiter = delimiters.find(({ open: open4 }) => rest.startsWith(open4));
20373
21317
  if (!delimiter) return { id, label: id, shape: "rectangle", next: index };
20374
21318
  const content = readDelimited(line, afterId + delimiter.open.length, delimiter.close);
20375
21319
  if (!content) return void 0;
@@ -20840,7 +21784,7 @@ function importD2Graph(source) {
20840
21784
  }
20841
21785
 
20842
21786
  // src/check.ts
20843
- var import_promises5 = require("fs/promises");
21787
+ var import_promises7 = require("fs/promises");
20844
21788
  var import_async_hooks2 = require("async_hooks");
20845
21789
  var import_os2 = require("os");
20846
21790
  var import_path4 = require("path");
@@ -21600,7 +22544,7 @@ async function checkFrame(input, options = {}) {
21600
22544
  });
21601
22545
  const create = input.create ?? (() => input.scene);
21602
22546
  const failOn = options.failOn ?? "error";
21603
- const tempDir = await (0, import_promises5.mkdtemp)((0, import_path4.join)((0, import_os2.tmpdir)(), "vizmatic-check-"));
22547
+ const tempDir = await (0, import_promises7.mkdtemp)((0, import_path4.join)((0, import_os2.tmpdir)(), "vizmatic-check-"));
21604
22548
  const reports = [];
21605
22549
  try {
21606
22550
  for (const [themeIndex, theme] of themes.entries()) {
@@ -21700,7 +22644,7 @@ async function checkFrame(input, options = {}) {
21700
22644
  });
21701
22645
  }
21702
22646
  } finally {
21703
- await (0, import_promises5.rm)(tempDir, { recursive: true, force: true });
22647
+ await (0, import_promises7.rm)(tempDir, { recursive: true, force: true });
21704
22648
  }
21705
22649
  const summary = counts(reports);
21706
22650
  const diagnostics = reports.flatMap(({ diagnostics: themeDiagnostics }) => themeDiagnostics);
@@ -21819,6 +22763,7 @@ async function checkFrame(input, options = {}) {
21819
22763
  WindowFrame,
21820
22764
  analyzeAnimationCadence,
21821
22765
  arcSwap,
22766
+ assertCueReveal,
21822
22767
  assertDensity,
21823
22768
  assertTokenHistoryTransition,
21824
22769
  byteDifferenceState,
@@ -21829,9 +22774,11 @@ async function checkFrame(input, options = {}) {
21829
22774
  chapterMetadata,
21830
22775
  checkFrame,
21831
22776
  colors,
22777
+ combineSoftmaxMass,
21832
22778
  compareByteSequences,
21833
22779
  compositeColor,
21834
22780
  createCanvasComponents,
22781
+ createCanvasReadback,
21835
22782
  createCueTrack,
21836
22783
  createFocusDirector,
21837
22784
  createPlotArea,
@@ -21841,9 +22788,11 @@ async function checkFrame(input, options = {}) {
21841
22788
  createTeachingCategoricalSampling,
21842
22789
  createTeachingFocus,
21843
22790
  createTeachingRoutedTransfer,
22791
+ createTeachingTileTransfer,
21844
22792
  createTeachingTokenHistory,
21845
22793
  createTeachingValueChange,
21846
22794
  createTeachingVectorAccumulation,
22795
+ createTeachingWaveform,
21847
22796
  cropPixels,
21848
22797
  cropRgbImage,
21849
22798
  cropRgbRaster,
@@ -21898,6 +22847,7 @@ async function checkFrame(input, options = {}) {
21898
22847
  lerpArray,
21899
22848
  loadAdditionalAsset,
21900
22849
  mapNumberLine,
22850
+ measureRegionChange,
21901
22851
  mergeFocusRegions,
21902
22852
  morphPolyline,
21903
22853
  multiplyMatrices,
@@ -21905,6 +22855,10 @@ async function checkFrame(input, options = {}) {
21905
22855
  normalizeWatermark,
21906
22856
  parallel,
21907
22857
  parseDensity,
22858
+ pcmEnvelope,
22859
+ planAvcSplice,
22860
+ planMediaExcerpt,
22861
+ planSampleCopies,
21908
22862
  planTeachingRoutedTransfer,
21909
22863
  pointAlongPath,
21910
22864
  prepareScene,
@@ -21923,6 +22877,7 @@ async function checkFrame(input, options = {}) {
21923
22877
  renderToPng,
21924
22878
  renderToPngWithOutput,
21925
22879
  renderToSvg,
22880
+ resolveH264Encoder,
21926
22881
  rgbChannel,
21927
22882
  sampleAnimation,
21928
22883
  sampleAnimationFrame,
@@ -21936,12 +22891,14 @@ async function checkFrame(input, options = {}) {
21936
22891
  setDefaultDensity,
21937
22892
  setDensityResolver,
21938
22893
  smoothstep,
22894
+ softmaxTileMass,
21939
22895
  stableSoftmax,
21940
22896
  statusColor,
21941
22897
  styles,
21942
22898
  sumForces,
21943
22899
  tokenHistoryState,
21944
22900
  toneGradients,
22901
+ traceCrossCorrelation2d,
21945
22902
  tracePolyline,
21946
22903
  transposeMatrix,
21947
22904
  tween,