@slidevideo/cli 0.3.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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([
@@ -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;
@@ -1,4 +1,4 @@
1
- import { activeViewTransform, annotationPaint, hasActiveSpotlight, laserPaint, laserVisible, paintEffects, spotlightAperturesVisible, stampPaint, stampVisible, targetKey, underlineFragmentsVisible, zoomTransformVisible } from '../annotation-paint.js';
1
+ import { activeViewTransform, annotationPaint, arrowPaint, arrowVisible, hasActiveSpotlight, laserPaint, laserVisible, paintEffects, spotlightAperturesVisible, stampPaint, stampVisible, targetKey, underlineFragmentsVisible, zoomTransformVisible } from '../annotation-paint.js';
2
2
  const labels = { loading: 'Loading presentation…', ready: 'Ready', playing: 'Playing', paused: 'Paused', ended: 'Finished', error: 'Playback failed' };
3
3
  const stage = document.querySelector('#stage');
4
4
  const status = document.querySelector('#status');
@@ -371,6 +371,14 @@ function nativePlayer(annotations) {
371
371
  activeEffects.push(painted);
372
372
  break;
373
373
  }
374
+ case 'arrow': {
375
+ const painted = arrowPaint(marker, { viewport: frame.viewport, content: frame.content }, target => targets.get(targetKey(target)));
376
+ if (!arrowVisible(painted)) {
377
+ throw new Error(`Annotation ${marker.id}: ${painted.degenerate_reason ?? 'arrow is clipped outside the slide-content rectangle'}`);
378
+ }
379
+ activeEffects.push(painted);
380
+ break;
381
+ }
374
382
  }
375
383
  }
376
384
  const view = activeViewTransform(activeEffects, frame.position_ms);
@@ -109,7 +109,23 @@ export async function loadStoryboard(file) {
109
109
  requireCondition(badChar === undefined, 'STAMP_GLYPH', `Annotation ${annotation.id}: character ${JSON.stringify(badChar)} is not supported by the bundled ${font} stamp font; use characters covered by the bundled font or appearance.symbol (check, cross, warning, star, info, arrow-right)`, 2, context);
110
110
  }
111
111
  }
112
- if ((annotation.effect === 'underline' || annotation.effect === 'spotlight' || annotation.effect === 'zoom' || annotation.effect === 'laser' || annotation.effect === 'stamp') && annotation.motion && 'duration_ms' in annotation && annotation.duration_ms !== undefined) {
112
+ if (annotation.effect === 'arrow') {
113
+ for (const [role, endpoint] of [['from', annotation.target.from], ['to', annotation.target.to]]) {
114
+ if ('target' in endpoint) {
115
+ if (endpoint.target.type === 'text') {
116
+ requireCondition(endpoint.target.text.trim().length > 0, 'ANNOTATION_TARGET', `Annotation ${annotation.id}: arrow ${role} text target cannot be empty or whitespace`, 2, context);
117
+ }
118
+ if (endpoint.target.type === 'region') {
119
+ const { x, y, width, height } = endpoint.target;
120
+ requireCondition(x + width <= 1 && y + height <= 1, 'ANNOTATION_BOUNDS', `Annotation ${annotation.id}: arrow ${role} region exceeds normalized slide bounds`, 2, context);
121
+ }
122
+ }
123
+ }
124
+ if (!('target' in annotation.target.from) && !('target' in annotation.target.to)) {
125
+ requireCondition(annotation.target.from.x !== annotation.target.to.x || annotation.target.from.y !== annotation.target.to.y, 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: arrow endpoints are coincident`, 2, context);
126
+ }
127
+ }
128
+ if ((annotation.effect === 'underline' || annotation.effect === 'spotlight' || annotation.effect === 'zoom' || annotation.effect === 'laser' || annotation.effect === 'stamp' || annotation.effect === 'arrow') && annotation.motion && 'duration_ms' in annotation && annotation.duration_ms !== undefined) {
113
129
  const inMs = annotation.motion.in_ms ?? 0;
114
130
  const outMs = annotation.motion.out_ms ?? 0;
115
131
  requireCondition(inMs + outMs <= annotation.duration_ms, 'ANNOTATION_MOTION', `Annotation ${annotation.id}: ${annotation.motion.type} motion exceeds annotation duration`, 2, context);
package/dist/timing.js CHANGED
@@ -250,6 +250,22 @@ async function resolveSchedule(story, speech) {
250
250
  ...windowFields,
251
251
  };
252
252
  }
253
+ if (annotation.effect === 'arrow') {
254
+ if (annotation.motion) {
255
+ const inMs = annotation.motion.in_ms ?? 0;
256
+ const outMs = annotation.motion.out_ms ?? 0;
257
+ requireCondition(inMs + outMs <= end - time, 'ANNOTATION_MOTION', `Annotation ${resolvedId}: ${annotation.motion.type} motion exceeds resolved duration (${Math.round(end - time)} ms)`, 2, context);
258
+ }
259
+ return {
260
+ id: resolvedId,
261
+ scene: annotation.scene,
262
+ effect: 'arrow',
263
+ target: target,
264
+ ...(annotation.appearance ? { appearance: annotation.appearance } : {}),
265
+ ...(annotation.motion ? { motion: annotation.motion } : {}),
266
+ ...windowFields,
267
+ };
268
+ }
253
269
  const singleTarget = target;
254
270
  if (annotation.effect === 'underline') {
255
271
  if (annotation.motion) {
@@ -318,6 +334,16 @@ async function resolveSchedule(story, speech) {
318
334
  : pt),
319
335
  };
320
336
  }
337
+ if (t.type === 'connector') {
338
+ const normalizeEndpoint = (ep) => 'target' in ep && ep.target.type === 'text'
339
+ ? { ...ep, target: { ...ep.target, text: normalizeSpaces(ep.target.text) } }
340
+ : ep;
341
+ return {
342
+ ...t,
343
+ from: normalizeEndpoint(t.from),
344
+ to: normalizeEndpoint(t.to),
345
+ };
346
+ }
321
347
  return t.type === 'text' ? { ...t, text: normalizeSpaces(t.text) } : t;
322
348
  };
323
349
  const normalizedTarget = normalizeTarget(annotation.target);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slidevideo/cli",
3
- "version": "0.3.2",
3
+ "version": "0.9.0",
4
4
  "description": "Turn a slide deck into a narrated video.",
5
5
  "license": "SEE LICENSE IN LICENSE-TERMS.md",
6
6
  "type": "module",