@slidevideo/cli 0.3.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ import { ensureStampFonts, measureStampText } from './stamp-fonts.js';
7
7
  import { balancedSum, execute, executionSignal, ffmpegFilterScriptFlags, hashFile, saveJson } from './media.js';
8
8
  import { executable } from './executables.js';
9
9
  import { ProductionError, requireCondition } from './errors.js';
10
- import { activeViewTransform, effectPrimitives, evaluateLaserPosition, evaluateViewTransform, findTargetGeometry, forwardTransformRect, highlightPaint, inverseTransformPoint, laserDirtyBounds, laserDotSample, laserFadeFraction, laserPaint, laserVisible, paintLaser, paintStamp, pointInExpandedAperture, spotlightApertureBounds, spotlightAperturesVisible, spotlightFadeFraction, spotlightMaskSample, spotlightPaint, stampDirtyBounds, stampPaint, stampVisible, underlineFragmentPrimitives, underlineFragmentsVisible, underlinePaint, underlineWipeFractions, zoomPaint, zoomProgress, zoomTransformVisible, } from './annotation-paint.js';
10
+ import { activeViewTransform, arrowDirtyBounds, arrowMotionState, arrowPaint, arrowVisible, effectPrimitives, evaluateLaserPosition, evaluateViewTransform, findTargetGeometry, forwardTransformRect, highlightPaint, inverseTransformPoint, laserDirtyBounds, laserDotSample, laserFadeFraction, laserPaint, laserVisible, paintArrow, paintLaser, paintStamp, pointInExpandedAperture, spotlightApertureBounds, spotlightAperturesVisible, spotlightFadeFraction, spotlightMaskSample, spotlightPaint, stampDirtyBounds, stampPaint, stampVisible, underlineFragmentPrimitives, underlineFragmentsVisible, underlinePaint, underlineWipeFractions, zoomPaint, zoomProgress, zoomTransformVisible, } from './annotation-paint.js';
11
11
  function toRgbPrimitive(paint) {
12
12
  return {
13
13
  ...paint,
@@ -322,6 +322,12 @@ export function annotationApplications(video, schedule, visual, audioOrigin) {
322
322
  requireCondition(stampVisible(painted), 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: stamp is clipped outside the slide-content rectangle`, 5, context);
323
323
  return { ...painted, id: annotation.id, first_frame, end_frame, geometry };
324
324
  }
325
+ if (annotation.effect === 'arrow') {
326
+ const slideGeometry = validateGeometry(annotation, { type: 'slide' }, context);
327
+ const painted = arrowPaint({ target: annotation.target, appearance: annotation.appearance, motion: annotation.motion, start_ms, end_ms }, slideGeometry, target => validateGeometry(annotation, target, { annotation: annotation.id, target }).fragments);
328
+ requireCondition(arrowVisible(painted), 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: ${painted.degenerate_reason ?? 'arrow is clipped outside the slide-content rectangle'}`, 5, context);
329
+ return { ...painted, id: annotation.id, first_frame, end_frame, geometry: slideGeometry };
330
+ }
325
331
  const geometry = validateGeometry(annotation, annotation.target, context);
326
332
  switch (annotation.effect) {
327
333
  case 'highlight': {
@@ -1226,7 +1232,7 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1226
1232
  in_ms: 0,
1227
1233
  out_ms: 0,
1228
1234
  };
1229
- const measureLaserDisk = (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, sampleTimeMs, expectedActive, activeLasers, activeStamps) => {
1235
+ const measureLaserDisk = (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, sampleTimeMs, expectedActive, activeLasers, activeStamps, activeArrows) => {
1230
1236
  const laserForSample = expectedActive ? item : settledLaser;
1231
1237
  const pos = evaluateLaserPosition(laserForSample, sampleTimeMs);
1232
1238
  const r = Math.max(1, item.radius_px - (item.radius_px >= 5 ? 1.5 : 0.5));
@@ -1239,8 +1245,9 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1239
1245
  const rw = right - left;
1240
1246
  const rh = bottom - top;
1241
1247
  let stampRgba;
1242
- if (activeStamps.length > 0 && rw > 0 && rh > 0) {
1243
- ensureStampFonts();
1248
+ if ((activeArrows.length > 0 || activeStamps.length > 0) && rw > 0 && rh > 0) {
1249
+ if (activeStamps.length > 0)
1250
+ ensureStampFonts();
1244
1251
  const stampCanvas = createCanvas(rw, rh);
1245
1252
  const sctx = stampCanvas.getContext('2d');
1246
1253
  sctx.translate(-left, -top);
@@ -1253,6 +1260,8 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1253
1260
  sctx.scale(scale, scale);
1254
1261
  sctx.translate(-s.x, -s.y);
1255
1262
  }
1263
+ for (const entry of activeArrows)
1264
+ paintArrow(sctx, entry.effect, outputTimeMs);
1256
1265
  for (const entry of activeStamps)
1257
1266
  paintStamp(sctx, entry.effect, outputTimeMs);
1258
1267
  stampRgba = sctx.getImageData(0, 0, rw, rh).data;
@@ -1344,8 +1353,8 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1344
1353
  if (item.first_frame - 1 >= 0) {
1345
1354
  const clearStartIndex = item.first_frame - 1;
1346
1355
  const startSampleMs = activeStartFrame * 1000 / video.fps;
1347
- const order = enqueue(clearStartIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1348
- const metrics = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, startSampleMs, false, activeLasers, activeStamps);
1356
+ const order = enqueue(clearStartIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps, activeArrows) => {
1357
+ const metrics = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, startSampleMs, false, activeLasers, activeStamps, activeArrows);
1349
1358
  orderedChecks.push({
1350
1359
  order,
1351
1360
  entry: {
@@ -1366,8 +1375,8 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1366
1375
  }
1367
1376
  {
1368
1377
  const activeIndex = activeStartFrame;
1369
- const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1370
- const metrics = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps);
1378
+ const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps, activeArrows) => {
1379
+ const metrics = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps, activeArrows);
1371
1380
  orderedChecks.push({
1372
1381
  order,
1373
1382
  entry: {
@@ -1393,8 +1402,8 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1393
1402
  else {
1394
1403
  {
1395
1404
  const activeIndex = activeEndFrame;
1396
- const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1397
- const metrics = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps);
1405
+ const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps, activeArrows) => {
1406
+ const metrics = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps, activeArrows);
1398
1407
  orderedChecks.push({
1399
1408
  order,
1400
1409
  entry: {
@@ -1416,8 +1425,8 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1416
1425
  {
1417
1426
  const clearEndIndex = item.end_frame;
1418
1427
  const endSampleMs = activeEndFrame * 1000 / video.fps;
1419
- const order = enqueue(clearEndIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1420
- const metrics = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, endSampleMs, false, activeLasers, activeStamps);
1428
+ const order = enqueue(clearEndIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps, activeArrows) => {
1429
+ const metrics = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, endSampleMs, false, activeLasers, activeStamps, activeArrows);
1421
1430
  orderedChecks.push({
1422
1431
  order,
1423
1432
  entry: {
@@ -1447,10 +1456,10 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1447
1456
  coverage.push(`${item.id}:movement:frame_${midFrame}`);
1448
1457
  const startTimeMs = activeStartFrame * 1000 / video.fps;
1449
1458
  const checkStartCleared = midTimeMs - startTimeMs > item.trail_ms + 1000 / video.fps;
1450
- const order = enqueue(midFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1451
- const atMid = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps);
1459
+ const order = enqueue(midFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps, activeArrows) => {
1460
+ const atMid = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps, activeArrows);
1452
1461
  const atStart = checkStartCleared
1453
- ? measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, startTimeMs, false, activeLasers, activeStamps)
1462
+ ? measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, startTimeMs, false, activeLasers, activeStamps, activeArrows)
1454
1463
  : { passed: true, expected_error: null, opposite_error: null, contrast: null };
1455
1464
  const passed = atMid.passed && atStart.passed;
1456
1465
  orderedChecks.push({
@@ -1482,7 +1491,7 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1482
1491
  ? Math.min(item.end_frame - 1, Math.ceil((item.start_ms + item.in_ms) * video.fps / 1000 - 1e-9))
1483
1492
  : item.first_frame;
1484
1493
  const activeFrame = Math.max(item.first_frame, Math.min(item.end_frame - 1, settleFrame));
1485
- const measureStampPresence = (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, sampleTimeMs, expectedActive, activeLasers, activeStamps) => {
1494
+ const measureStampPresence = (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, sampleTimeMs, expectedActive, activeLasers, activeStamps, activeArrows) => {
1486
1495
  const bounds = stampDirtyBounds(item, sampleTimeMs);
1487
1496
  if (!bounds)
1488
1497
  return { passed: !expectedActive, expected_error: null, opposite_error: null, contrast: null };
@@ -1512,6 +1521,9 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1512
1521
  paintStamp(ctx, item, sampleTimeMs);
1513
1522
  }
1514
1523
  else {
1524
+ for (const entry of activeArrows) {
1525
+ paintArrow(ctx, entry.effect, outputTimeMs);
1526
+ }
1515
1527
  let paintedSelf = false;
1516
1528
  for (const entry of activeStamps) {
1517
1529
  if (entry.index === appIndex) {
@@ -1535,7 +1547,7 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1535
1547
  }
1536
1548
  return ctx.getImageData(0, 0, rw, rh).data;
1537
1549
  };
1538
- const hasOtherTop = activeLasers.length > 0 || activeStamps.some(entry => entry.index !== appIndex);
1550
+ const hasOtherTop = activeArrows.length > 0 || activeLasers.length > 0 || activeStamps.some(entry => entry.index !== appIndex);
1539
1551
  const selfRgba = renderTopLayer(true, true);
1540
1552
  const withRgba = hasOtherTop ? renderTopLayer(true) : selfRgba;
1541
1553
  const withoutRgba = hasOtherTop ? renderTopLayer(false) : undefined;
@@ -1598,8 +1610,8 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1598
1610
  const beforeFrame = item.first_frame - 1;
1599
1611
  const activeSampleTime = activeFrame * 1000 / video.fps;
1600
1612
  coverage.push(`${item.id}:before_start:frame_${beforeFrame}`);
1601
- const order = enqueue(beforeFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1602
- const metrics = measureStampPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, activeSampleTime, false, activeLasers, activeStamps);
1613
+ const order = enqueue(beforeFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps, activeArrows) => {
1614
+ const metrics = measureStampPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, activeSampleTime, false, activeLasers, activeStamps, activeArrows);
1603
1615
  orderedChecks.push({
1604
1616
  order,
1605
1617
  entry: { annotation: item.id, part: 'stamp', boundary: 'before_start', frame_index: beforeFrame, encoded_ms: timestampMs, expected_active: false, ...metrics },
@@ -1609,8 +1621,8 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1609
1621
  }
1610
1622
  if (activeFrame < totalFrames) {
1611
1623
  coverage.push(`${item.id}:start:frame_${activeFrame}`);
1612
- const order = enqueue(activeFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1613
- const metrics = measureStampPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps);
1624
+ const order = enqueue(activeFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps, activeArrows) => {
1625
+ const metrics = measureStampPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps, activeArrows);
1614
1626
  orderedChecks.push({
1615
1627
  order,
1616
1628
  entry: { annotation: item.id, part: 'stamp', boundary: 'start', frame_index: activeFrame, encoded_ms: timestampMs, expected_active: true, ...metrics },
@@ -1622,8 +1634,8 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1622
1634
  if (item.end_frame < totalFrames) {
1623
1635
  const activeSampleTime = activeFrame * 1000 / video.fps;
1624
1636
  coverage.push(`${item.id}:end:frame_${item.end_frame}`);
1625
- const order = enqueue(item.end_frame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1626
- const metrics = measureStampPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, activeSampleTime, false, activeLasers, activeStamps);
1637
+ const order = enqueue(item.end_frame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps, activeArrows) => {
1638
+ const metrics = measureStampPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, activeSampleTime, false, activeLasers, activeStamps, activeArrows);
1627
1639
  orderedChecks.push({
1628
1640
  order,
1629
1641
  entry: { annotation: item.id, part: 'stamp', boundary: 'end', frame_index: item.end_frame, encoded_ms: timestampMs, expected_active: false, ...metrics },
@@ -1634,6 +1646,203 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1634
1646
  }
1635
1647
  break;
1636
1648
  }
1649
+ case 'arrow': {
1650
+ requiredActiveParts.push({ id: item.id, part: 'arrow' });
1651
+ const settleFrame = item.motion_type !== 'none' && item.in_ms > 0
1652
+ ? Math.min(item.end_frame - 1, Math.ceil((item.start_ms + item.in_ms) * video.fps / 1000 - 1e-9))
1653
+ : item.first_frame;
1654
+ const activeFrame = Math.max(item.first_frame, Math.min(item.end_frame - 1, settleFrame));
1655
+ const measureArrowPresence = (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, sampleTimeMs, expectedActive, activeLasers, activeStamps, activeArrows) => {
1656
+ const bounds = arrowDirtyBounds(item, sampleTimeMs);
1657
+ if (!bounds)
1658
+ return { passed: !expectedActive, expected_error: null, opposite_error: null, contrast: null };
1659
+ const outputBounds = activeView ? forwardTransformRect(activeView, bounds) : bounds;
1660
+ const x0 = Math.max(0, Math.floor(outputBounds.x));
1661
+ const y0 = Math.max(0, Math.floor(outputBounds.y));
1662
+ const x1 = Math.min(video.width, Math.ceil(outputBounds.x + outputBounds.width));
1663
+ const y1 = Math.min(video.height, Math.ceil(outputBounds.y + outputBounds.height));
1664
+ const rw = x1 - x0;
1665
+ const rh = y1 - y0;
1666
+ if (rw < 2 || rh < 2)
1667
+ return { passed: false, expected_error: null, opposite_error: null, contrast: null };
1668
+ const renderTopLayer = (includeSelf, onlySelf = false) => {
1669
+ if (!onlySelf && activeStamps.length > 0)
1670
+ ensureStampFonts();
1671
+ const canvas = createCanvas(rw, rh);
1672
+ const ctx = canvas.getContext('2d');
1673
+ ctx.translate(-x0, -y0);
1674
+ if (activeView) {
1675
+ const { content: c, source: s, scale } = activeView;
1676
+ ctx.beginPath();
1677
+ ctx.rect(c.x, c.y, c.width, c.height);
1678
+ ctx.clip();
1679
+ ctx.translate(c.x, c.y);
1680
+ ctx.scale(scale, scale);
1681
+ ctx.translate(-s.x, -s.y);
1682
+ }
1683
+ if (onlySelf) {
1684
+ paintArrow(ctx, item, sampleTimeMs);
1685
+ }
1686
+ else {
1687
+ let paintedSelf = false;
1688
+ for (const entry of activeArrows) {
1689
+ if (entry.index === appIndex) {
1690
+ if (includeSelf) {
1691
+ paintArrow(ctx, item, sampleTimeMs);
1692
+ paintedSelf = true;
1693
+ }
1694
+ continue;
1695
+ }
1696
+ if (includeSelf && !paintedSelf && entry.index > appIndex) {
1697
+ paintArrow(ctx, item, sampleTimeMs);
1698
+ paintedSelf = true;
1699
+ }
1700
+ paintArrow(ctx, entry.effect, outputTimeMs);
1701
+ }
1702
+ if (includeSelf && !paintedSelf)
1703
+ paintArrow(ctx, item, sampleTimeMs);
1704
+ for (const entry of activeStamps) {
1705
+ paintStamp(ctx, entry.effect, outputTimeMs);
1706
+ }
1707
+ for (const entry of activeLasers) {
1708
+ paintLaser(ctx, entry.effect, outputTimeMs);
1709
+ }
1710
+ }
1711
+ return ctx.getImageData(0, 0, rw, rh).data;
1712
+ };
1713
+ const hasOtherTop = activeStamps.length > 0 || activeLasers.length > 0 || activeArrows.some(entry => entry.index !== appIndex);
1714
+ const selfRgba = renderTopLayer(true, true);
1715
+ const withRgba = hasOtherTop ? renderTopLayer(true) : selfRgba;
1716
+ const withoutRgba = hasOtherTop ? renderTopLayer(false) : undefined;
1717
+ const stepX = Math.max(1, Math.floor(rw / 96));
1718
+ const stepY = Math.max(1, Math.floor(rh / 64));
1719
+ let expectedError = 0;
1720
+ let oppositeError = 0;
1721
+ let contrast = 0;
1722
+ let count = 0;
1723
+ for (let ly = 0; ly < rh; ly += stepY) {
1724
+ for (let lx = 0; lx < rw; lx += stepX) {
1725
+ const pOffset = (ly * rw + lx) * 4;
1726
+ const selfAlpha = selfRgba[pOffset + 3] / 255;
1727
+ if (selfAlpha < 0.35)
1728
+ continue;
1729
+ const x = x0 + lx;
1730
+ const y = y0 + ly;
1731
+ const px = x + 0.5;
1732
+ const py = y + 0.5;
1733
+ if (covered.some(rect => inside(rect, px, py)))
1734
+ continue;
1735
+ const pt = activeView ? inverseTransformPoint(activeView, px, py) : { x: px, y: py };
1736
+ const mask = activeSpotlights.length > 0 ? spotlightMaskSample(activeSpotlights, outputTimeMs, pt.x, pt.y) : undefined;
1737
+ const offset = (y * video.width + x) * 3;
1738
+ const withAlpha = withRgba[pOffset + 3] / 255;
1739
+ const withoutAlpha = withoutRgba ? withoutRgba[pOffset + 3] / 255 : 0;
1740
+ for (const channel of [0, 1, 2]) {
1741
+ let under = activeView
1742
+ ? sampleBilinearChannel(baseFrame, video.width, video.height, pt.x - 0.5, pt.y - 0.5, channel)
1743
+ : baseFrame[offset + channel];
1744
+ if (mask && mask.alpha > 0)
1745
+ under = under * (1 - mask.alpha) + mask.rgb[channel] * mask.alpha;
1746
+ for (const list of appPrimitives) {
1747
+ for (const primitive of list) {
1748
+ if (inside(primitive.rectangle, pt.x, pt.y))
1749
+ under = blendChannel(under, primitive, channel);
1750
+ }
1751
+ }
1752
+ const overWith = under * (1 - withAlpha) + withRgba[pOffset + channel] * withAlpha;
1753
+ const overWithout = withoutRgba ? under * (1 - withoutAlpha) + withoutRgba[pOffset + channel] * withoutAlpha : under;
1754
+ const expected = expectedActive ? overWith : overWithout;
1755
+ const opposite = expectedActive ? overWithout : overWith;
1756
+ expectedError += Math.abs(finalFrame[offset + channel] - expected);
1757
+ oppositeError += Math.abs(finalFrame[offset + channel] - opposite);
1758
+ contrast += Math.abs(expected - opposite);
1759
+ count++;
1760
+ }
1761
+ }
1762
+ }
1763
+ const maxError = activeView ? 20 : 18;
1764
+ const passed = count > 0 && contrast / count >= 6 && expectedError / count <= maxError && expectedError < oppositeError * 0.72;
1765
+ return {
1766
+ passed,
1767
+ expected_error: count ? expectedError / count : null,
1768
+ opposite_error: count ? oppositeError / count : null,
1769
+ contrast: count ? contrast / count : null,
1770
+ };
1771
+ };
1772
+ if (item.first_frame > 0) {
1773
+ const beforeFrame = item.first_frame - 1;
1774
+ const activeSampleTime = activeFrame * 1000 / video.fps;
1775
+ coverage.push(`${item.id}:before_start:frame_${beforeFrame}`);
1776
+ const order = enqueue(beforeFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps, activeArrows) => {
1777
+ const metrics = measureArrowPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, activeSampleTime, false, activeLasers, activeStamps, activeArrows);
1778
+ orderedChecks.push({
1779
+ order,
1780
+ entry: { annotation: item.id, part: 'arrow', boundary: 'before_start', frame_index: beforeFrame, encoded_ms: timestampMs, expected_active: false, ...metrics },
1781
+ gap: metrics.passed ? undefined : `${item.id}:arrow:before_start: frame ${beforeFrame} does not confirm arrow absent before start`,
1782
+ });
1783
+ });
1784
+ }
1785
+ if (activeFrame < totalFrames) {
1786
+ coverage.push(`${item.id}:start:frame_${activeFrame}`);
1787
+ const order = enqueue(activeFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps, activeArrows) => {
1788
+ const metrics = measureArrowPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps, activeArrows);
1789
+ orderedChecks.push({
1790
+ order,
1791
+ entry: { annotation: item.id, part: 'arrow', boundary: 'start', frame_index: activeFrame, encoded_ms: timestampMs, expected_active: true, ...metrics },
1792
+ gap: metrics.passed ? undefined : `${item.id}:arrow:start: frame ${activeFrame} does not confirm arrow appearance`,
1793
+ });
1794
+ });
1795
+ checkBoundaryTimestamp(item.id, 'start', item.first_frame, item.start_ms);
1796
+ }
1797
+ if (item.motion_type === 'draw' && item.in_ms > 0) {
1798
+ const lastAvailable = Math.min(item.end_frame, totalFrames) - 1;
1799
+ let midFrame;
1800
+ let bestDist = Infinity;
1801
+ for (let frame = item.first_frame; frame <= lastAvailable; frame++) {
1802
+ const t = frame * 1000 / video.fps;
1803
+ if (t >= item.start_ms + item.in_ms)
1804
+ break;
1805
+ const p = arrowMotionState(item, t).progress;
1806
+ if (p >= 0.2 && p <= 0.75) {
1807
+ const dist = Math.abs(p - 0.5);
1808
+ if (dist < bestDist) {
1809
+ bestDist = dist;
1810
+ midFrame = frame;
1811
+ }
1812
+ }
1813
+ }
1814
+ if (midFrame === undefined) {
1815
+ coverage.push(`${item.id}:draw_in:unobservable_at_${video.fps}fps`);
1816
+ gaps.push(`${item.id}:arrow:draw_in: draw_in (${item.in_ms} ms) has no observable partial frame at ${video.fps} fps`);
1817
+ }
1818
+ else {
1819
+ const drawFrame = midFrame;
1820
+ coverage.push(`${item.id}:draw_in:frame_${drawFrame}`);
1821
+ const order = enqueue(drawFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps, activeArrows) => {
1822
+ const metrics = measureArrowPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps, activeArrows);
1823
+ orderedChecks.push({
1824
+ order,
1825
+ entry: { annotation: item.id, part: 'arrow', boundary: 'draw_in', frame_index: drawFrame, encoded_ms: timestampMs, expected_active: 'partial', ...metrics },
1826
+ gap: metrics.passed ? undefined : `${item.id}:arrow:draw_in: frame ${drawFrame} does not confirm partial arrow draw progression`,
1827
+ });
1828
+ });
1829
+ }
1830
+ }
1831
+ if (item.end_frame < totalFrames) {
1832
+ const activeSampleTime = activeFrame * 1000 / video.fps;
1833
+ coverage.push(`${item.id}:end:frame_${item.end_frame}`);
1834
+ const order = enqueue(item.end_frame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps, activeArrows) => {
1835
+ const metrics = measureArrowPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, activeSampleTime, false, activeLasers, activeStamps, activeArrows);
1836
+ orderedChecks.push({
1837
+ order,
1838
+ entry: { annotation: item.id, part: 'arrow', boundary: 'end', frame_index: item.end_frame, encoded_ms: timestampMs, expected_active: false, ...metrics },
1839
+ gap: metrics.passed ? undefined : `${item.id}:arrow:end: frame ${item.end_frame} does not confirm arrow cleared after end`,
1840
+ });
1841
+ });
1842
+ checkBoundaryTimestamp(item.id, 'end', item.end_frame, item.end_ms);
1843
+ }
1844
+ break;
1845
+ }
1637
1846
  }
1638
1847
  }
1639
1848
  const indices = [...tasksByFrame.keys()].sort((a, b) => a - b);
@@ -1674,6 +1883,7 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1674
1883
  const activeSpotlights = activeApps.filter((app) => app.effect === 'spotlight');
1675
1884
  const activeLasers = [];
1676
1885
  const activeStamps = [];
1886
+ const activeArrows = [];
1677
1887
  for (let idx = 0; idx < applications.length; idx++) {
1678
1888
  const app = applications[idx];
1679
1889
  if (index >= app.first_frame && index < app.end_frame) {
@@ -1681,6 +1891,8 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1681
1891
  activeLasers.push({ index: idx, effect: app });
1682
1892
  else if (app.effect === 'stamp')
1683
1893
  activeStamps.push({ index: idx, effect: app });
1894
+ else if (app.effect === 'arrow')
1895
+ activeArrows.push({ index: idx, effect: app });
1684
1896
  }
1685
1897
  }
1686
1898
  const activeView = activeViewTransform(activeApps, outputTime);
@@ -1688,7 +1900,7 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
1688
1900
  ? effectPrimitives([app], outputTime).map(toRgbPrimitive)
1689
1901
  : []);
1690
1902
  for (const task of tasksByFrame.get(index) ?? []) {
1691
- task.run(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTime, timestampMs, activeLasers, activeStamps);
1903
+ task.run(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTime, timestampMs, activeLasers, activeStamps, activeArrows);
1692
1904
  }
1693
1905
  }
1694
1906
  const [finalEnded, baseEnded] = await Promise.all([
package/dist/cli.js CHANGED
@@ -12,6 +12,7 @@ import { configuredLicense, withExecutables } from './executables.js';
12
12
  import { setup } from './setup.js';
13
13
  import { setupLicense } from './setup-license.js';
14
14
  import { installSkill } from './skill-install.js';
15
+ import { initStoryboard } from './init.js';
15
16
  import { notifyUpdate } from './update-check.js';
16
17
  const commands = ['inspect', 'validate', 'play', 'tts', 'resolve', 'record', 'assemble', 'build'];
17
18
  const documents = new Map([
@@ -60,6 +61,17 @@ skill decks Print the Slidev and PowerPoint deck-compatibility reference
60
61
  current directory (and ./.claude/skills/slidevideo if .claude exists).
61
62
  --json Print document metadata or installation results as JSON.
62
63
  `;
64
+ const initHelp = `slidevideo init --deck <file> [options]
65
+ Create a starter slidevideo.yaml from an existing Slidev or PowerPoint deck.
66
+
67
+ --deck <file> Required .md or .pptx deck to inspect.
68
+ --output <file> Destination storyboard path (default: slidevideo.yaml beside the deck).
69
+ --provider <edge-tts|elevenlabs> Speech provider (default: edge-tts).
70
+ --voice <id> Voice name or ID (default: en-US-AriaNeural for edge-tts).
71
+ --force Overwrite an existing storyboard file.
72
+ --json Print structured result as JSON.
73
+ --quiet Suppress progress on stderr.
74
+ `;
63
75
  function setupChecklist(report, licensed) {
64
76
  const labels = {
65
77
  ffmpeg: 'FFmpeg', ffprobe: 'ffprobe', browser: 'Chromium', python: 'Python environment',
@@ -99,7 +111,7 @@ try {
99
111
  const { values, positionals } = parseArgs({ options: {
100
112
  storyboard: { type: 'string' }, deck: { type: 'string' }, width: { type: 'string' }, height: { type: 'string' }, fps: { type: 'string' }, port: { type: 'string' }, run: { type: 'string' }, 'cache-dir': { type: 'string' }, output: { type: 'string' }, captions: { type: 'string' }, export: { type: 'string' }, 'timeout-minutes': { type: 'string' },
101
113
  browser: { type: 'string' }, python: { type: 'string' }, ffmpeg: { type: 'string' }, ffprobe: { type: 'string' },
102
- presentation: { type: 'string' }, provider: { type: 'string' }, 'voice-id': { type: 'string' }, install: { type: 'boolean' }, project: { type: 'boolean' }, manual: { type: 'boolean' },
114
+ presentation: { type: 'string' }, provider: { type: 'string' }, 'voice-id': { type: 'string' }, voice: { type: 'string' }, force: { type: 'boolean' }, install: { type: 'boolean' }, project: { type: 'boolean' }, manual: { type: 'boolean' },
103
115
  license: { type: 'boolean' },
104
116
  json: { type: 'boolean' }, quiet: { type: 'boolean' }, resume: { type: 'boolean' }, 'no-cache': { type: 'boolean' }, 'verify-timing': { type: 'boolean' }, help: { type: 'boolean', short: 'h' }, version: { type: 'boolean' },
105
117
  }, allowPositionals: true });
@@ -116,17 +128,17 @@ try {
116
128
  console.log(values.json ? JSON.stringify({ version: 1, package_version: version }) : version);
117
129
  }
118
130
  else if (values.help || command === 'help') {
119
- const help = command === 'setup' ? setupHelp : command === 'skill' ? skillHelp : `slidevideo <setup|inspect|validate|play|tts|resolve|record|assemble|build|skill|license|impressum>
131
+ const help = command === 'setup' ? setupHelp : command === 'skill' ? skillHelp : command === 'init' ? initHelp : `slidevideo <setup|init|inspect|validate|play|tts|resolve|record|assemble|build|skill|license|impressum>
120
132
 
121
- --storyboard <file> Required for presentation commands except assemble; inspect also accepts --deck.
122
- --deck <file> Inspect a .md or .pptx deck directly before a storyboard exists.
133
+ --storyboard <file> Required for presentation commands except assemble; inspect and init accept --deck.
134
+ --deck <file> Deck file (.md or .pptx) for inspect or init before a storyboard exists.
123
135
  --width/--height <px> Even viewport or output size (default: 1920x1080; PPTX inspect --deck uses slide size).
124
136
  --fps <15|24|30|60> Output frame rate for record, assemble, or build (default: 30).
125
137
  --run <directory> Run directory (default: runs/YYYYMMDD-HHmmss for build and tts; required for resolve, record, assemble, and build --resume).
126
138
  --cache-dir <dir> Speech cache directory for play, tts, or build (default: .slidevideo/speech beside storyboard).
127
139
  --no-cache Disable speech cache reading and writing for play, tts, or build.
128
140
  --port <number> Local play server port (default: auto).
129
- --output <file> New final MP4 destination for assemble or build.
141
+ --output <file> Output path: new final MP4 for assemble/build, or storyboard path for init.
130
142
  --captions <vtt|srt|both|none> Caption export (default: both for build/assemble with narration; optional for resolve).
131
143
  --resume Reuse intact build stages with matching inputs and mode.
132
144
  --verify-timing Opt in to decoded timing proof for build or record; assemble checks the recorded mode.
@@ -138,8 +150,9 @@ try {
138
150
  --version Package version.
139
151
 
140
152
  setup prepares shared tools and speech providers, and detects Slidev and native PowerPoint support (see setup --help).
153
+ init --deck <file> creates a starter slidevideo.yaml from slide structure and speaker notes (see init --help).
141
154
  Normal production leaves timing unevaluated and the video for user review.
142
- inspect lists slide targets, click counts, media IDs and annotation targets from --deck or --storyboard without recording.
155
+ inspect lists slide targets, click counts, speaker notes, media IDs and annotation targets from --deck or --storyboard without recording.
143
156
  validate checks inputs without recording.
144
157
  play --storyboard <file> serves slides and annotations (with cached audio when available) with Play, Pause and Replay. Ctrl+C stops the server.
145
158
  skill displays or registers (--install) the bundled coding-agent skill; see skill --help for references and options.
@@ -169,12 +182,32 @@ impressum displays the provider's contact details.
169
182
  const result = { version: 1, command, document, path: command === 'skill' ? path : undefined };
170
183
  process.stdout.write(values.json ? JSON.stringify(result) + '\n' : document);
171
184
  }
185
+ else if (command === 'init') {
186
+ requireCondition(positionals.length === 1 && Object.keys(values).every(key => ['deck', 'output', 'provider', 'voice', 'force', 'json', 'quiet', 'browser', 'python', 'ffmpeg', 'ffprobe'].includes(key)), 'OPTION', 'Run slidevideo init --help for init options');
187
+ requireCondition(values.deck !== undefined && values.deck.trim().length > 0, 'OPTION', 'init requires --deck <file>');
188
+ requireCondition(values.output === undefined || values.output.trim().length > 0, 'OPTION', '--output requires a file path');
189
+ const result = await withExecutables(values, () => initStoryboard({
190
+ deck: values.deck,
191
+ output: values.output,
192
+ provider: values.provider,
193
+ voice: values.voice,
194
+ force: values.force,
195
+ }));
196
+ if (values.json)
197
+ console.log(JSON.stringify(result));
198
+ else {
199
+ console.log(`Created ${result.output} (${result.slides} slide${result.slides === 1 ? '' : 's'}, ${result.narrated_slides} narrated).`);
200
+ for (const warning of result.warnings)
201
+ console.log(`Warning: ${warning}`);
202
+ console.log(`Next steps:\n slidevideo play --storyboard ${result.output}\n slidevideo build --storyboard ${result.output}`);
203
+ }
204
+ }
172
205
  else if (command === 'setup' && values.license) {
173
206
  requireCondition(positionals.length === 1 && Object.keys(values).every(key => key === 'license'), 'OPTION', 'Use slidevideo setup --license by itself in a terminal.');
174
207
  await withExecutables({}, setupLicense);
175
208
  }
176
209
  else if (command === 'setup') {
177
- requireCondition(positionals.length === 1 && !['storyboard', 'deck', 'width', 'height', 'fps', 'port', 'run', 'cache-dir', 'no-cache', 'output', 'captions', 'export', 'timeout-minutes', 'resume', 'verify-timing', 'project'].some(key => key in values), 'OPTION', 'Run slidevideo setup --help for setup options');
210
+ requireCondition(positionals.length === 1 && !['storyboard', 'deck', 'width', 'height', 'fps', 'port', 'run', 'cache-dir', 'no-cache', 'output', 'captions', 'export', 'timeout-minutes', 'resume', 'verify-timing', 'project', 'voice', 'force'].some(key => key in values), 'OPTION', 'Run slidevideo setup --help for setup options');
178
211
  let initialChecklist;
179
212
  const report = await withExecutables(values, () => setup(values, current => {
180
213
  initialChecklist = setupChecklist(current, configuredLicense());
@@ -227,7 +260,7 @@ impressum displays the provider's contact details.
227
260
  else {
228
261
  requireCondition(commands.includes(command) && positionals.length === 1, 'COMMAND', 'Run slidevideo --help for available commands');
229
262
  requireCondition(!values.project, 'OPTION', '--project requires slidevideo skill --install');
230
- requireCondition(!['presentation', 'provider', 'voice-id', 'install', 'manual', 'license'].some(key => key in values), 'OPTION', 'Presentation, provider, voice ID, install and license options require setup');
263
+ requireCondition(!['presentation', 'provider', 'voice-id', 'voice', 'force', 'install', 'manual', 'license'].some(key => key in values), 'OPTION', 'Presentation, provider, voice, force, install and license options require setup or init');
231
264
  let timeout;
232
265
  if (values['timeout-minutes'] !== undefined) {
233
266
  const raw = values['timeout-minutes'].trim();
@@ -67,7 +67,7 @@ export function watermarkLayout(output) {
67
67
  const maxTextWidth = Math.max(1, width - Math.min(pad * 2, width - 1));
68
68
  return { text, font, textX, textY, maxTextWidth, rectangle: { x, y, width, height } };
69
69
  }
70
- export function renderWatermarkCanvas(output, fillStyle = 'rgba(255, 255, 255, 0.38)') {
70
+ export function renderWatermarkCanvas(output, fillStyle = 'rgba(255, 255, 255, 0.28)') {
71
71
  const layout = watermarkLayout(output);
72
72
  const canvas = createCanvas(layout.rectangle.width, layout.rectangle.height);
73
73
  const context = canvas.getContext('2d');
@@ -338,7 +338,64 @@ export type StampAnnotationBase = {
338
338
  motion?: StampMotion;
339
339
  };
340
340
  export type StampAnnotation = StampAnnotationBase & AnnotationTiming;
341
- export type Annotation = HighlightAnnotation | UnderlineAnnotation | SpotlightAnnotation | ZoomAnnotation | LaserAnnotation | StampAnnotation;
341
+ export type ConnectorEndpoint = {
342
+ x: number;
343
+ y: number;
344
+ padding?: number;
345
+ } | {
346
+ target: AnnotationTarget;
347
+ anchor: TargetAnchor;
348
+ padding?: number;
349
+ };
350
+ export type ResolvedConnectorEndpoint = {
351
+ x: number;
352
+ y: number;
353
+ padding?: number;
354
+ } | {
355
+ target: ResolvedAnnotationTarget;
356
+ anchor: TargetAnchor;
357
+ padding?: number;
358
+ };
359
+ export type ConnectorTarget = {
360
+ type: 'connector';
361
+ units: 'normalized';
362
+ from: ConnectorEndpoint;
363
+ to: ConnectorEndpoint;
364
+ };
365
+ export type ResolvedConnectorTarget = {
366
+ type: 'connector';
367
+ units: 'normalized';
368
+ from: ResolvedConnectorEndpoint;
369
+ to: ResolvedConnectorEndpoint;
370
+ };
371
+ export type ArrowHead = 'filled' | 'open';
372
+ export type ArrowAppearance = {
373
+ color?: string;
374
+ opacity?: number;
375
+ width?: number;
376
+ style?: 'solid' | 'dashed';
377
+ head?: ArrowHead;
378
+ head_size?: number;
379
+ };
380
+ export type ArrowMotion = {
381
+ type: 'fade';
382
+ in_ms?: number;
383
+ out_ms?: number;
384
+ } | {
385
+ type: 'draw';
386
+ in_ms?: number;
387
+ out_ms?: number;
388
+ };
389
+ export type ArrowAnnotationBase = {
390
+ id: string;
391
+ scene: string;
392
+ effect: 'arrow';
393
+ target: ConnectorTarget;
394
+ appearance?: ArrowAppearance;
395
+ motion?: ArrowMotion;
396
+ };
397
+ export type ArrowAnnotation = ArrowAnnotationBase & AnnotationTiming;
398
+ export type Annotation = HighlightAnnotation | UnderlineAnnotation | SpotlightAnnotation | ZoomAnnotation | LaserAnnotation | StampAnnotation | ArrowAnnotation;
342
399
  export type ResolvedAnnotationWindow = {
343
400
  start_ms: number;
344
401
  end_ms: number;
@@ -371,7 +428,10 @@ export type ResolvedLaserAnnotation = Omit<LaserAnnotationBase, 'target'> & {
371
428
  export type ResolvedStampAnnotation = Omit<StampAnnotationBase, 'target'> & {
372
429
  target: ResolvedStampTarget;
373
430
  } & ResolvedAnnotationWindow;
374
- export type ResolvedAnnotation = ResolvedHighlightAnnotation | ResolvedUnderlineAnnotation | ResolvedSpotlightAnnotation | ResolvedZoomAnnotation | ResolvedLaserAnnotation | ResolvedStampAnnotation;
431
+ export type ResolvedArrowAnnotation = Omit<ArrowAnnotationBase, 'target'> & {
432
+ target: ResolvedConnectorTarget;
433
+ } & ResolvedAnnotationWindow;
434
+ export type ResolvedAnnotation = ResolvedHighlightAnnotation | ResolvedUnderlineAnnotation | ResolvedSpotlightAnnotation | ResolvedZoomAnnotation | ResolvedLaserAnnotation | ResolvedStampAnnotation | ResolvedArrowAnnotation;
375
435
  export type GeometryRequest = {
376
436
  key: string;
377
437
  target: GeometryTarget;
@@ -589,6 +649,7 @@ export interface TtsAdapter {
589
649
  validate(voice: Voice): void;
590
650
  synthesize(segment: Narration, voice: Voice, destination: string): Promise<Omit<SpeechAsset, 'key'>>;
591
651
  }
652
+ export declare function normalizeSpeakerNotes(raw: string | null | undefined): string | undefined;
592
653
  export type PresentationInspection = {
593
654
  dimensions?: Viewport;
594
655
  slides: {
@@ -600,6 +661,7 @@ export type PresentationInspection = {
600
661
  transition_duration_ms?: number;
601
662
  entry_duration_ms?: number;
602
663
  click_durations_ms?: number[];
664
+ notes?: string;
603
665
  }[];
604
666
  media_ids: string[];
605
667
  media?: {
package/dist/contracts.js CHANGED
@@ -1,2 +1,8 @@
1
1
  export const defaultViewport = { width: 1920, height: 1080 };
2
2
  export const defaultVideoOutput = { width: 1920, height: 1080, fps: 30 };
3
+ export function normalizeSpeakerNotes(raw) {
4
+ if (typeof raw !== 'string')
5
+ return undefined;
6
+ const normalized = raw.replace(/\r\n?/g, '\n').trim();
7
+ return normalized.length > 0 ? normalized : undefined;
8
+ }