@slidevideo/cli 0.3.1 → 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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.9.0
6
+
7
+ - Add storyboard-controlled straight `arrow` annotations with normalized or explicitly anchored target endpoints, endpoint padding, solid or dashed strokes, filled or open arrowheads, and optional `fade` or `draw` motion for Slidev and PowerPoint.
8
+ - Lower the free-tier `slidevideo.io` export watermark alpha from `0.38` to `0.28` for a subtler, more transparent corner mark.
9
+
10
+ ## 0.3.2
11
+
12
+ - Render the free-tier `slidevideo.io` export watermark in bundled Plus Jakarta Sans with adaptive dark-or-light ink based on corner brightness so it stays crisp and transparent on bright and dark slides alike.
13
+ - Check `slidevideo.io/release.json` (with an npm registry fallback) during the 24-hour background update check and honor `DO_NOT_TRACK=1` alongside `SLIDEVIDEO_NO_UPDATE_CHECK=1`.
14
+ - Replace per-segment FFmpeg `adelay`/`amix` narration fan-out in assembly with sequential PCM audio placement so open inputs and memory stay bounded on long storyboards.
15
+ - Bound concurrent TTS synthesis requests per provider, stream-count PCM bytes in `audioDuration` without retaining audio buffers, and skip redundant speech decode passes within a single run.
16
+ - Estimate approximate character-proportional phrase-cue and `follow` timing in `slidevideo play` for uncached segments while clearly labeling approximate cues in CLI, `--json`, and browser status output.
17
+
5
18
  ## 0.3.1
6
19
 
7
20
  - Export speech-aligned `final.vtt` and `final.srt` captions by default on narrated `build` and `assemble` runs, with `--captions <vtt|srt|both|none>` to configure or export during `resolve`.
package/README.md CHANGED
@@ -20,7 +20,7 @@ A completed build writes `final.mp4` (plus `final.vtt` and `final.srt` captions
20
20
 
21
21
  To draft or edit a storyboard with a coding agent, run `slidevideo skill --install` to link the bundled skill into `~/.agents/skills/slidevideo` and `~/.claude/skills/slidevideo` when Claude Code is detected, or ask the agent to run `slidevideo skill`. For non-interactive setup, run `slidevideo setup --install --json` and see `slidevideo setup --help` and `slidevideo skill --help` for provider and project flags. Use `slidevideo inspect --deck <file> --json` to list slide names, click counts, media IDs, and highlight targets before creating `slidevideo.yaml`. The CLI includes the skill and its storyboard, deck-compatibility, and recording references.
22
22
 
23
- Interactive calls check npm in the background at most once every 24 hours and show cached update notices on later calls. Stable installations use `latest`; existing alpha installations use `alpha`. Notices include an exact-version upgrade command. If you installed with `--prefix`, add the same `--prefix` option to that command so npm updates the copy on your `PATH`. Set `SLIDEVIDEO_NO_UPDATE_CHECK=1` to disable checks and notices. CI, noninteractive calls, `--json` and `--quiet` skip both.
23
+ CLI commands check `https://slidevideo.io/release.json` (falling back to npm) in the background at most once every 24 hours and show cached update notices on later interactive calls. Stable installations use `latest`; existing alpha installations use `alpha`. Notices include an exact-version upgrade command. If you installed with `--prefix`, add the same `--prefix` option to that command so npm updates the copy on your `PATH`. Set `SLIDEVIDEO_NO_UPDATE_CHECK=1` or `DO_NOT_TRACK=1` to disable checks and notices. CI, `--version`, `--help`, `setup --manual`, read-only `skill` views, `license`, and `impressum` skip both, and `--json` and `--quiet` suppress notices.
24
24
 
25
25
  See the [user manual](https://slidevideo.io/guide.html) for host prerequisites and a first build, and the [changelog](CHANGELOG.md) for release notes. Run `slidevideo --help` for the installed command reference.
26
26
 
@@ -2,7 +2,7 @@
2
2
  import { ref, nextTick, onMounted, onUnmounted } from 'vue'
3
3
  import { useNav } from '@slidev/client'
4
4
  import type { Schedule, ObservedEvent, ScheduledAction, AnnotationGeometry, PresentationInspection } from '../../dist/contracts.js'
5
- import { activeViewTransform, geometryRequests, groupEffectsByBlend, hasActiveLaser, hasActiveSpotlight, hasActiveStamp, paintLasers, paintPrimitives, paintSpotlightMask, paintStamps, type PaintableEffect } from '../../dist/annotation-paint.js'
5
+ import { activeViewTransform, geometryRequests, groupEffectsByBlend, hasActiveArrow, hasActiveLaser, hasActiveSpotlight, hasActiveStamp, paintArrows, paintLasers, paintPrimitives, paintSpotlightMask, paintStamps, type PaintableEffect } from '../../dist/annotation-paint.js'
6
6
  import { geometryCollector, inspectAudienceTargets } from './geometry'
7
7
  import type { createPreview } from './preview'
8
8
  import { playbackEntries } from './playback-entries'
@@ -24,10 +24,11 @@ function postPreviewView(view: ReturnType<typeof activeViewTransform>) {
24
24
  function renderPreview(effects: PaintableEffect[], timeMs: number) {
25
25
  postPreviewView(activeViewTransform(effects, timeMs))
26
26
  const spotlightActive = hasActiveSpotlight(effects, timeMs)
27
+ const arrowActive = hasActiveArrow(effects, timeMs)
27
28
  const stampActive = hasActiveStamp(effects, timeMs)
28
29
  const laserActive = hasActiveLaser(effects, timeMs)
29
30
  const groups = groupEffectsByBlend(effects, timeMs)
30
- const planeCount = (spotlightActive ? 1 : 0) + groups.length + (stampActive ? 1 : 0) + (laserActive ? 1 : 0)
31
+ const planeCount = (spotlightActive ? 1 : 0) + groups.length + (arrowActive ? 1 : 0) + (stampActive ? 1 : 0) + (laserActive ? 1 : 0)
31
32
  while (previewCanvases.length > planeCount) previewCanvases.pop()!.remove()
32
33
  const width = innerWidth
33
34
  const height = innerHeight
@@ -59,6 +60,11 @@ function renderPreview(effects: PaintableEffect[], timeMs: number) {
59
60
  paintPrimitives(context, group.primitives, { backdrop: false })
60
61
  }
61
62
  let topOffset = offset + groups.length
63
+ if (arrowActive) {
64
+ const context = ensurePlane(topOffset, 'normal')
65
+ paintArrows(context, effects, timeMs)
66
+ topOffset += 1
67
+ }
62
68
  if (stampActive) {
63
69
  const context = ensurePlane(topOffset, 'normal')
64
70
  paintStamps(context, effects, timeMs)
@@ -1,5 +1,5 @@
1
1
  import type { AnnotationGeometry, ResolvedAnnotation, Schedule, ScheduledAction } from '../../dist/contracts.js'
2
- import { annotationPaint, findTargetGeometry, geometryRequests, laserPaint, laserVisible, spotlightAperturesVisible, stampPaint, stampVisible, underlineFragmentsVisible, zoomTransformVisible, type PaintableEffect } from '../../dist/annotation-paint.js'
2
+ import { annotationPaint, arrowPaint, arrowVisible, findTargetGeometry, geometryRequests, laserPaint, laserVisible, spotlightAperturesVisible, stampPaint, stampVisible, underlineFragmentsVisible, zoomTransformVisible, type PaintableEffect } from '../../dist/annotation-paint.js'
3
3
  import { playbackEntries } from './playback-entries'
4
4
  import { geometryCollector } from './geometry'
5
5
 
@@ -127,6 +127,16 @@ export function createPreview(
127
127
  output.push(painted)
128
128
  break
129
129
  }
130
+ case 'arrow': {
131
+ const slideRecord = findTargetGeometry(geometry, annotation, { type: 'slide' })
132
+ if (!slideRecord) throw new Error(`Annotation ${annotation.id}: preview slide geometry is unavailable`)
133
+ const painted = arrowPaint(annotation, slideRecord, target => findTargetGeometry(geometry, annotation, target)?.fragments)
134
+ if (!arrowVisible(painted)) {
135
+ throw new Error(`Annotation ${annotation.id}: ${painted.degenerate_reason ?? 'arrow is clipped outside the slide-content rectangle'}`)
136
+ }
137
+ output.push(painted)
138
+ break
139
+ }
130
140
  }
131
141
  }
132
142
  render(output, elapsed())
@@ -2,6 +2,7 @@ import type { Narration, SpeechAsset, TtsAdapter, Voice } from '../contracts.js'
2
2
  export declare class EdgeAdapter implements TtsAdapter {
3
3
  id: string;
4
4
  version: string;
5
+ concurrency: number;
5
6
  validate(voice: Voice): void;
6
7
  synthesize(segment: Narration, voice: Voice, destination: string): Promise<Omit<SpeechAsset, 'key'>>;
7
8
  }
@@ -1,11 +1,12 @@
1
1
  import { rm } from 'node:fs/promises';
2
- import { execute, saveJson, probe, decode, hashFile, audioDuration } from '../media.js';
2
+ import { execute, saveJson, probe, hashFile, audioDuration } from '../media.js';
3
3
  import { ProductionError, requireCondition } from '../errors.js';
4
4
  import { packagePath } from '../installation.js';
5
5
  import { executable } from '../executables.js';
6
6
  export class EdgeAdapter {
7
7
  id = 'edge-tts';
8
8
  version = '7.3.1-adapter-1';
9
+ concurrency = 3;
9
10
  validate(voice) {
10
11
  for (const [key, value] of Object.entries(voice.options ?? {})) {
11
12
  requireCondition(['rate', 'volume', 'pitch'].includes(key), 'VOICE_OPTION', `Edge TTS does not support option ${key}`, 3);
@@ -33,11 +34,11 @@ export class EdgeAdapter {
33
34
  cursor = start + word.text.length;
34
35
  return { ...word, start, end: cursor };
35
36
  });
36
- await decode(destination);
37
37
  const properties = await probe(destination);
38
38
  requireCondition(properties.has_audio && properties.duration_ms > 0, 'TTS_AUDIO', `Edge returned invalid audio for ${segment.id}`, 4);
39
+ const duration_ms = await audioDuration(destination);
39
40
  return {
40
- id: segment.id, audio: destination, sha256: await hashFile(destination), format: 'mp3', duration_ms: await audioDuration(destination),
41
+ id: segment.id, audio: destination, sha256: await hashFile(destination), format: 'mp3', duration_ms,
41
42
  transcript: { original: segment.text, normalized: segment.text },
42
43
  alignment: { form: 'original', granularity: 'word', text: segment.text, units },
43
44
  provenance: { adapter: this.id, version: this.version, provider: this.id, voice: voice.voice, options: voice.options ?? {}, generated_at: new Date().toISOString() },
@@ -3,6 +3,7 @@ export declare function elevenLabsApiKey(environment?: NodeJS.ProcessEnv): strin
3
3
  export declare class ElevenLabsAdapter implements TtsAdapter {
4
4
  id: string;
5
5
  version: string;
6
+ concurrency: number;
6
7
  validate(voice: Voice): void;
7
8
  synthesize(segment: Narration, voice: Voice, destination: string): Promise<Omit<SpeechAsset, 'key'>>;
8
9
  }
@@ -1,13 +1,14 @@
1
1
  import { writeFile } from 'node:fs/promises';
2
2
  import { configuredElevenLabsKey } from '../executables.js';
3
3
  import { requireCondition, ProductionError } from '../errors.js';
4
- import { decode, hashFile, probe, executionSignal, audioDuration } from '../media.js';
4
+ import { hashFile, probe, executionSignal, audioDuration } from '../media.js';
5
5
  export function elevenLabsApiKey(environment = process.env) {
6
6
  return environment.ELEVENLABS_API_KEY ?? environment.ELEVENLABS_KEY ?? configuredElevenLabsKey();
7
7
  }
8
8
  export class ElevenLabsAdapter {
9
9
  id = 'elevenlabs';
10
10
  version = '1';
11
+ concurrency = 2;
11
12
  validate(voice) {
12
13
  const options = voice.options ?? {};
13
14
  for (const key of Object.keys(options))
@@ -50,11 +51,11 @@ export class ElevenLabsAdapter {
50
51
  };
51
52
  }
52
53
  await writeFile(destination, Buffer.from(data.audio_base64, 'base64'));
53
- await decode(destination);
54
54
  const properties = await probe(destination);
55
55
  requireCondition(properties.has_audio && properties.duration_ms > 0, 'TTS_AUDIO', `Invalid generated speech ${segment.id}`, 4);
56
+ const duration_ms = await audioDuration(destination);
56
57
  return {
57
- id: segment.id, audio: destination, sha256: await hashFile(destination), format: 'mp3', duration_ms: await audioDuration(destination),
58
+ id: segment.id, audio: destination, sha256: await hashFile(destination), format: 'mp3', duration_ms,
58
59
  transcript: { original: segment.text, normalized: data.normalized_alignment?.characters.join('') ?? segment.text }, alignment,
59
60
  provenance: { adapter: this.id, version: this.version, provider: this.id, voice: voice.voice, options, generated_at: new Date().toISOString() },
60
61
  };
@@ -377,7 +377,7 @@ export class PowerPointAdapter {
377
377
  }),
378
378
  } : {}),
379
379
  files: [resolve(file), helper, packagePath('tools', 'powerpoint', 'Native.cs'), fileURLToPath(import.meta.url)],
380
- capabilities: ['slide', 'reveal', 'play', 'highlight:region', 'highlight:shape', 'highlight:text', 'underline:region', 'underline:shape', 'underline:text', 'spotlight:region', 'spotlight:shape', 'spotlight:text', 'zoom:region', 'zoom:shape', 'zoom:text', 'laser:path', 'laser:region', 'laser:shape', 'laser:text', 'stamp:point', 'stamp:region', 'stamp:shape', 'stamp:text'],
380
+ capabilities: ['slide', 'reveal', 'play', 'highlight:region', 'highlight:shape', 'highlight:text', 'underline:region', 'underline:shape', 'underline:text', 'spotlight:region', 'spotlight:shape', 'spotlight:text', 'zoom:region', 'zoom:shape', 'zoom:text', 'laser:path', 'laser:region', 'laser:shape', 'laser:text', 'stamp:point', 'stamp:region', 'stamp:shape', 'stamp:text', 'arrow:connector', 'arrow:region', 'arrow:shape', 'arrow:text'],
381
381
  ...(unsupported.length ? { unsupported } : {}),
382
382
  annotation_targets: this.targets(),
383
383
  };
@@ -451,7 +451,9 @@ export class PowerPointAdapter {
451
451
  for (const annotation of story.annotations) {
452
452
  const targets = annotation.target.type === 'path'
453
453
  ? annotation.target.points.flatMap(point => 'target' in point ? [point.target] : [])
454
- : [annotation.target];
454
+ : annotation.target.type === 'connector'
455
+ ? [annotation.target.from, annotation.target.to].flatMap(ep => 'target' in ep ? [ep.target] : [])
456
+ : [annotation.target];
455
457
  for (const target of targets) {
456
458
  requireCondition(target.type !== 'element' && !(target.type === 'text' && target.container?.type === 'element'), 'ANNOTATION_TARGET', `Annotation ${annotation.id} uses a Slidev selector. PowerPoint requires an existing shape ID, text target, or normalized region.`, 3);
457
459
  }
@@ -462,7 +464,9 @@ export class PowerPointAdapter {
462
464
  const slide = this.slide(annotation.slide);
463
465
  const targets = annotation.target.type === 'path'
464
466
  ? annotation.target.points.flatMap(point => 'target' in point ? [point.target] : [])
465
- : [annotation.target];
467
+ : annotation.target.type === 'connector'
468
+ ? [annotation.target.from, annotation.target.to].flatMap(ep => 'target' in ep ? [ep.target] : [])
469
+ : [annotation.target];
466
470
  for (const target of targets) {
467
471
  if (target.type === 'shape') {
468
472
  const candidates = slide.shapes.filter(shape => shape.id === target.id);
@@ -42,7 +42,7 @@ export async function inspectSlidev(deck) {
42
42
  }));
43
43
  requireCondition(new Set(slides.map(s => s.id)).size === slides.length, 'SLIDE_ID', 'Slide names must be unique');
44
44
  const media_ids = parsed.slides.flatMap(slide => [...slide.content.matchAll(/<(?:video|audio)\b[^>]*\bid=["']([^"']+)["']/g)].map(match => match[1]));
45
- return { slides, media_ids, files: await slidevInputs(deck, parsed.headmatter, parsed.files), capabilities: ['slide', 'reveal', 'play', 'highlight:region', 'highlight:element', 'highlight:text', 'underline:region', 'underline:element', 'underline:text', 'spotlight:region', 'spotlight:element', 'spotlight:text', 'zoom:region', 'zoom:element', 'zoom:text', 'laser:path', 'laser:region', 'laser:element', 'laser:text', 'stamp:point', 'stamp:region', 'stamp:element', 'stamp:text'] };
45
+ return { slides, media_ids, files: await slidevInputs(deck, parsed.headmatter, parsed.files), capabilities: ['slide', 'reveal', 'play', 'highlight:region', 'highlight:element', 'highlight:text', 'underline:region', 'underline:element', 'underline:text', 'spotlight:region', 'spotlight:element', 'spotlight:text', 'zoom:region', 'zoom:element', 'zoom:text', 'laser:path', 'laser:region', 'laser:element', 'laser:text', 'stamp:point', 'stamp:region', 'stamp:element', 'stamp:text', 'arrow:connector', 'arrow:region', 'arrow:element', 'arrow:text'] };
46
46
  }
47
47
  export function validateSlidev(story, inspection, options) {
48
48
  const schedule = options?.schedule;
@@ -52,7 +52,9 @@ export function validateSlidev(story, inspection, options) {
52
52
  for (const annotation of story.annotations) {
53
53
  const targets = annotation.target.type === 'path'
54
54
  ? annotation.target.points.flatMap(point => 'target' in point ? [point.target] : [])
55
- : [annotation.target];
55
+ : annotation.target.type === 'connector'
56
+ ? [annotation.target.from, annotation.target.to].flatMap(ep => 'target' in ep ? [ep.target] : [])
57
+ : [annotation.target];
56
58
  for (const target of targets) {
57
59
  requireCondition(target.type !== 'shape' && !(target.type === 'text' && target.container?.type === 'shape'), 'ANNOTATION_TARGET', `Annotation ${annotation.id} uses a PowerPoint shape target unsupported by Slidev`, 3, { annotation: annotation.id });
58
60
  }
@@ -1,4 +1,4 @@
1
- import type { AnnotationGeometry, GeometryRequest, GeometryTarget, LaserInterpolation, Rectangle, ResolvedAnnotation, ResolvedAnnotationTarget, ResolvedHighlightAnnotation, ResolvedLaserAnnotation, ResolvedSpotlightAnnotation, ResolvedStampAnnotation, ResolvedUnderlineAnnotation, ResolvedZoomAnnotation, Schedule, StampFont, StampSymbol, ZoomEasing } from './contracts.js';
1
+ import type { AnnotationGeometry, ArrowHead, GeometryRequest, GeometryTarget, LaserInterpolation, Rectangle, ResolvedAnnotation, ResolvedAnnotationTarget, ResolvedArrowAnnotation, ResolvedHighlightAnnotation, ResolvedLaserAnnotation, ResolvedSpotlightAnnotation, ResolvedStampAnnotation, ResolvedUnderlineAnnotation, ResolvedZoomAnnotation, Schedule, StampFont, StampSymbol, ZoomEasing } from './contracts.js';
2
2
  export type BlendMode = 'source-over' | 'darken';
3
3
  export type AnnotationPaint = {
4
4
  rectangle: Rectangle;
@@ -144,7 +144,30 @@ export type StampEffect = {
144
144
  slide_bounds: Rectangle;
145
145
  overflow_error?: string;
146
146
  };
147
- export type PaintableEffect = HighlightEffect | UnderlineEffect | SpotlightEffect | ZoomEffect | LaserEffect | StampEffect;
147
+ export type ArrowEffect = {
148
+ effect: 'arrow';
149
+ start_ms: number;
150
+ end_ms: number;
151
+ motion_type: 'none' | 'fade' | 'draw';
152
+ in_ms: number;
153
+ out_ms: number;
154
+ start_x: number;
155
+ start_y: number;
156
+ end_x: number;
157
+ end_y: number;
158
+ ux: number;
159
+ uy: number;
160
+ length_px: number;
161
+ color: string;
162
+ opacity: number;
163
+ width_px: number;
164
+ style: 'solid' | 'dashed';
165
+ head: ArrowHead;
166
+ head_size_px: number;
167
+ slide_bounds: Rectangle;
168
+ degenerate_reason?: string;
169
+ };
170
+ export type PaintableEffect = HighlightEffect | UnderlineEffect | SpotlightEffect | ZoomEffect | LaserEffect | StampEffect | ArrowEffect;
148
171
  export type BlendGroup = {
149
172
  blend: BlendMode;
150
173
  primitives: AnnotationPaint[];
@@ -221,6 +244,16 @@ export declare function stampDirtyBounds(effect: StampEffect, timeMs: number): R
221
244
  export declare function paintStamp<FillStyle, StrokeStyle, CompositeOp>(context: EffectCanvas2D<FillStyle, StrokeStyle, CompositeOp>, effect: StampEffect, timeMs: number): void;
222
245
  export declare function hasActiveStamp(effects: readonly PaintableEffect[], timeMs: number): boolean;
223
246
  export declare function paintStamps<FillStyle, StrokeStyle, CompositeOp>(context: EffectCanvas2D<FillStyle, StrokeStyle, CompositeOp>, effects: readonly PaintableEffect[], timeMs: number): void;
247
+ export declare function arrowPaint(annotation: Pick<ResolvedArrowAnnotation, 'target' | 'appearance' | 'motion' | 'start_ms' | 'end_ms'>, slideGeometry: Pick<AnnotationGeometry, 'content' | 'viewport'>, resolveTarget: (target: ResolvedAnnotationTarget) => readonly Rectangle[] | undefined): ArrowEffect;
248
+ export declare function arrowVisible(effect: Pick<ArrowEffect, 'slide_bounds' | 'length_px' | 'width_px' | 'degenerate_reason'>): boolean;
249
+ export declare function arrowMotionState(effect: Pick<ArrowEffect, 'start_ms' | 'end_ms' | 'motion_type' | 'in_ms' | 'out_ms' | 'opacity'>, timeMs: number): {
250
+ opacity: number;
251
+ progress: number;
252
+ };
253
+ export declare function arrowDirtyBounds(effect: ArrowEffect, timeMs: number): Rectangle | undefined;
254
+ export declare function hasActiveArrow(effects: readonly PaintableEffect[], timeMs: number): boolean;
255
+ export declare function paintArrow<FillStyle, StrokeStyle, CompositeOp>(context: EffectCanvas2D<FillStyle, StrokeStyle, CompositeOp>, effect: ArrowEffect, timeMs: number): void;
256
+ export declare function paintArrows<FillStyle, StrokeStyle, CompositeOp>(context: EffectCanvas2D<FillStyle, StrokeStyle, CompositeOp>, effects: readonly PaintableEffect[], timeMs: number): void;
224
257
  export declare function laserDirtyBounds(effect: LaserEffect, timeMs: number): Rectangle | undefined;
225
258
  export declare function hasActiveLaser(effects: readonly PaintableEffect[], timeMs: number): boolean;
226
259
  export declare function paintLaser<FillStyle, StrokeStyle, CompositeOp>(context: EffectCanvas2D<FillStyle, StrokeStyle, CompositeOp>, effect: LaserEffect, timeMs: number): void;
@@ -7,6 +7,10 @@ const DEFAULT_LASER_OPACITY = 0.95;
7
7
  const DEFAULT_LASER_RADIUS = 0.008;
8
8
  const DEFAULT_LASER_GLOW = 0.024;
9
9
  const DEFAULT_LASER_TRAIL_MS = 240;
10
+ const DEFAULT_ARROW_COLOR = '#ff2d2d';
11
+ const DEFAULT_ARROW_OPACITY = 0.95;
12
+ const DEFAULT_ARROW_WIDTH = 0.006;
13
+ const DEFAULT_ARROW_HEAD_SIZE = 0.024;
10
14
  export function targetKey(target) {
11
15
  switch (target.type) {
12
16
  case 'slide':
@@ -55,6 +59,23 @@ export function annotationTargets(annotation) {
55
59
  }
56
60
  return targets;
57
61
  }
62
+ case 'arrow': {
63
+ const seen = new Set();
64
+ const targets = [];
65
+ const push = (t) => {
66
+ const key = targetKey(t);
67
+ if (!seen.has(key)) {
68
+ seen.add(key);
69
+ targets.push(t);
70
+ }
71
+ };
72
+ push({ type: 'slide' });
73
+ if ('target' in annotation.target.from)
74
+ push(annotation.target.from.target);
75
+ if ('target' in annotation.target.to)
76
+ push(annotation.target.to.target);
77
+ return targets;
78
+ }
58
79
  }
59
80
  }
60
81
  export function geometryRequests(schedule) {
@@ -937,6 +958,212 @@ export function paintStamps(context, effects, timeMs) {
937
958
  paintStamp(context, effect, timeMs);
938
959
  }
939
960
  }
961
+ export function arrowPaint(annotation, slideGeometry, resolveTarget) {
962
+ const { appearance, motion } = annotation;
963
+ const { content, viewport } = slideGeometry;
964
+ const clipLeft = Math.max(0, Math.round(content.x));
965
+ const clipTop = Math.max(0, Math.round(content.y));
966
+ const clipRight = Math.min(viewport.width, Math.round(content.x + content.width));
967
+ const clipBottom = Math.min(viewport.height, Math.round(content.y + content.height));
968
+ const slide_bounds = {
969
+ x: clipLeft,
970
+ y: clipTop,
971
+ width: Math.max(0, clipRight - clipLeft),
972
+ height: Math.max(0, clipBottom - clipTop),
973
+ };
974
+ const resolveEndpoint = (endpoint, role) => {
975
+ if ('target' in endpoint) {
976
+ const fragments = resolveTarget(endpoint.target);
977
+ if (!fragments || fragments.length === 0) {
978
+ throw new Error(`Missing geometry for arrow ${role} target ${targetKey(endpoint.target)}`);
979
+ }
980
+ return anchorPoint(fragments, endpoint.anchor, slide_bounds);
981
+ }
982
+ return {
983
+ x: Math.max(slide_bounds.x, Math.min(slide_bounds.x + slide_bounds.width, slide_bounds.x + endpoint.x * slide_bounds.width)),
984
+ y: Math.max(slide_bounds.y, Math.min(slide_bounds.y + slide_bounds.height, slide_bounds.y + endpoint.y * slide_bounds.height)),
985
+ };
986
+ };
987
+ const rawFrom = resolveEndpoint(annotation.target.from, 'from');
988
+ const rawTo = resolveEndpoint(annotation.target.to, 'to');
989
+ const dx = rawTo.x - rawFrom.x;
990
+ const dy = rawTo.y - rawFrom.y;
991
+ const rawLength = Math.hypot(dx, dy);
992
+ const fromPadPx = (annotation.target.from.padding ?? 0) * slide_bounds.height;
993
+ const toPadPx = (annotation.target.to.padding ?? 0) * slide_bounds.height;
994
+ const width_px = Math.max(1, (appearance?.width ?? DEFAULT_ARROW_WIDTH) * slide_bounds.height);
995
+ const head_size_px = Math.max(2, (appearance?.head_size ?? DEFAULT_ARROW_HEAD_SIZE) * slide_bounds.height);
996
+ const base = {
997
+ effect: 'arrow',
998
+ start_ms: annotation.start_ms,
999
+ end_ms: annotation.end_ms,
1000
+ motion_type: motion ? motion.type : 'none',
1001
+ in_ms: motion?.in_ms ?? 0,
1002
+ out_ms: motion?.out_ms ?? 0,
1003
+ color: (appearance?.color ?? DEFAULT_ARROW_COLOR).toLowerCase(),
1004
+ opacity: appearance?.opacity ?? DEFAULT_ARROW_OPACITY,
1005
+ width_px,
1006
+ style: appearance?.style ?? 'solid',
1007
+ head: appearance?.head ?? 'filled',
1008
+ head_size_px,
1009
+ slide_bounds,
1010
+ };
1011
+ if (rawLength <= 1e-6) {
1012
+ return {
1013
+ ...base,
1014
+ start_x: rawFrom.x,
1015
+ start_y: rawFrom.y,
1016
+ end_x: rawTo.x,
1017
+ end_y: rawTo.y,
1018
+ ux: 1,
1019
+ uy: 0,
1020
+ length_px: 0,
1021
+ degenerate_reason: 'arrow endpoints are coincident',
1022
+ };
1023
+ }
1024
+ const length_px = rawLength - fromPadPx - toPadPx;
1025
+ const ux = dx / rawLength;
1026
+ const uy = dy / rawLength;
1027
+ if (length_px <= 1) {
1028
+ return {
1029
+ ...base,
1030
+ start_x: rawFrom.x + ux * fromPadPx,
1031
+ start_y: rawFrom.y + uy * fromPadPx,
1032
+ end_x: rawTo.x - ux * toPadPx,
1033
+ end_y: rawTo.y - uy * toPadPx,
1034
+ ux,
1035
+ uy,
1036
+ length_px: 0,
1037
+ degenerate_reason: 'arrow endpoint padding collapses the arrow to zero length',
1038
+ };
1039
+ }
1040
+ return {
1041
+ ...base,
1042
+ start_x: rawFrom.x + ux * fromPadPx,
1043
+ start_y: rawFrom.y + uy * fromPadPx,
1044
+ end_x: rawTo.x - ux * toPadPx,
1045
+ end_y: rawTo.y - uy * toPadPx,
1046
+ ux,
1047
+ uy,
1048
+ length_px,
1049
+ };
1050
+ }
1051
+ export function arrowVisible(effect) {
1052
+ return effect.slide_bounds.width > 0 && effect.slide_bounds.height > 0 && effect.length_px > 1 && effect.width_px > 0 && !effect.degenerate_reason;
1053
+ }
1054
+ export function arrowMotionState(effect, timeMs) {
1055
+ if (effect.motion_type === 'none')
1056
+ return { opacity: effect.opacity, progress: 1 };
1057
+ const inFrac = effect.in_ms > 0 ? Math.max(0, Math.min(1, (timeMs - effect.start_ms) / effect.in_ms)) : 1;
1058
+ const outFrac = effect.out_ms > 0 ? Math.max(0, Math.min(1, (effect.end_ms - timeMs) / effect.out_ms)) : 1;
1059
+ if (effect.motion_type === 'fade') {
1060
+ return { opacity: effect.opacity * Math.min(inFrac, outFrac), progress: 1 };
1061
+ }
1062
+ return { opacity: effect.opacity * outFrac, progress: inFrac };
1063
+ }
1064
+ export function arrowDirtyBounds(effect, timeMs) {
1065
+ if (!arrowVisible(effect))
1066
+ return undefined;
1067
+ const state = arrowMotionState(effect, timeMs);
1068
+ if (state.opacity <= 1e-6 || state.progress <= 1e-6)
1069
+ return undefined;
1070
+ const curLen = effect.length_px * state.progress;
1071
+ const tipX = effect.start_x + effect.ux * curLen;
1072
+ const tipY = effect.start_y + effect.uy * curLen;
1073
+ const margin = Math.max(effect.width_px, effect.head_size_px * 0.6) + 2;
1074
+ const sb = effect.slide_bounds;
1075
+ const x = Math.max(sb.x, Math.floor(Math.min(effect.start_x, tipX) - margin));
1076
+ const y = Math.max(sb.y, Math.floor(Math.min(effect.start_y, tipY) - margin));
1077
+ const right = Math.min(sb.x + sb.width, Math.ceil(Math.max(effect.start_x, tipX) + margin));
1078
+ const bottom = Math.min(sb.y + sb.height, Math.ceil(Math.max(effect.start_y, tipY) + margin));
1079
+ return right > x && bottom > y ? { x, y, width: right - x, height: bottom - y } : undefined;
1080
+ }
1081
+ export function hasActiveArrow(effects, timeMs) {
1082
+ return effects.some(effect => {
1083
+ if (effect.effect !== 'arrow' || !arrowVisible(effect))
1084
+ return false;
1085
+ const state = arrowMotionState(effect, timeMs);
1086
+ return state.opacity > 1e-6 && state.progress > 1e-6;
1087
+ });
1088
+ }
1089
+ export function paintArrow(context, effect, timeMs) {
1090
+ if (!arrowVisible(effect))
1091
+ return;
1092
+ const state = arrowMotionState(effect, timeMs);
1093
+ if (state.opacity <= 1e-6 || state.progress <= 1e-6)
1094
+ return;
1095
+ const curLen = effect.length_px * state.progress;
1096
+ if (curLen <= 0.5)
1097
+ return;
1098
+ const { start_x, start_y, ux, uy, width_px, head_size_px, slide_bounds: sb } = effect;
1099
+ const px = -uy;
1100
+ const py = ux;
1101
+ const tipX = start_x + ux * curLen;
1102
+ const tipY = start_y + uy * curLen;
1103
+ const effectiveHeadLen = Math.min(head_size_px, curLen);
1104
+ const headHalfW = effectiveHeadLen * 0.45;
1105
+ const baseX = tipX - ux * effectiveHeadLen;
1106
+ const baseY = tipY - uy * effectiveHeadLen;
1107
+ const shaftEnd = effect.head === 'filled'
1108
+ ? Math.max(0, curLen - effectiveHeadLen)
1109
+ : Math.max(0, curLen - width_px * 0.25);
1110
+ context.save();
1111
+ context.beginPath();
1112
+ context.rect(sb.x, sb.y, sb.width, sb.height);
1113
+ context.clip();
1114
+ context.globalCompositeOperation = 'source-over';
1115
+ context.globalAlpha = state.opacity;
1116
+ if (shaftEnd > 0.5) {
1117
+ context.strokeStyle = effect.color;
1118
+ context.lineWidth = width_px;
1119
+ context.lineCap = 'butt';
1120
+ context.lineJoin = 'round';
1121
+ context.beginPath();
1122
+ if (effect.style === 'solid') {
1123
+ context.moveTo(start_x, start_y);
1124
+ context.lineTo(start_x + ux * shaftEnd, start_y + uy * shaftEnd);
1125
+ }
1126
+ else {
1127
+ const dash = Math.max(6, Math.round(width_px * 3));
1128
+ const gap = Math.max(4, Math.round(width_px * 2));
1129
+ for (let pos = 0; pos < shaftEnd; pos += dash + gap) {
1130
+ const segEnd = Math.min(shaftEnd, pos + dash);
1131
+ if (segEnd > pos) {
1132
+ context.moveTo(start_x + ux * pos, start_y + uy * pos);
1133
+ context.lineTo(start_x + ux * segEnd, start_y + uy * segEnd);
1134
+ }
1135
+ }
1136
+ }
1137
+ context.stroke();
1138
+ }
1139
+ if (effect.head === 'filled') {
1140
+ context.fillStyle = effect.color;
1141
+ context.beginPath();
1142
+ context.moveTo(tipX, tipY);
1143
+ context.lineTo(baseX + px * headHalfW, baseY + py * headHalfW);
1144
+ context.lineTo(baseX - px * headHalfW, baseY - py * headHalfW);
1145
+ context.closePath();
1146
+ context.fill();
1147
+ }
1148
+ else {
1149
+ context.strokeStyle = effect.color;
1150
+ context.lineWidth = width_px;
1151
+ context.lineCap = 'round';
1152
+ context.lineJoin = 'round';
1153
+ context.beginPath();
1154
+ context.moveTo(baseX + px * headHalfW, baseY + py * headHalfW);
1155
+ context.lineTo(tipX, tipY);
1156
+ context.lineTo(baseX - px * headHalfW, baseY - py * headHalfW);
1157
+ context.stroke();
1158
+ }
1159
+ context.restore();
1160
+ }
1161
+ export function paintArrows(context, effects, timeMs) {
1162
+ for (const effect of effects) {
1163
+ if (effect.effect === 'arrow')
1164
+ paintArrow(context, effect, timeMs);
1165
+ }
1166
+ }
940
1167
  export function laserDirtyBounds(effect, timeMs) {
941
1168
  const fade = laserFadeFraction(effect, timeMs);
942
1169
  if (fade <= 1e-6 || !laserVisible(effect))
@@ -1373,6 +1600,7 @@ export function effectPrimitives(effects, timeMs) {
1373
1600
  case 'zoom':
1374
1601
  case 'laser':
1375
1602
  case 'stamp':
1603
+ case 'arrow':
1376
1604
  break;
1377
1605
  }
1378
1606
  }
@@ -1430,6 +1658,11 @@ export function effectDirtyBounds(effects, timeMs, extraRectangles, viewport) {
1430
1658
  if (bounds)
1431
1659
  expand(bounds);
1432
1660
  }
1661
+ else if (effect.effect === 'arrow') {
1662
+ const bounds = arrowDirtyBounds(effect, timeMs);
1663
+ if (bounds)
1664
+ expand(bounds);
1665
+ }
1433
1666
  }
1434
1667
  for (const rect of extraRectangles)
1435
1668
  expand(rect);
@@ -1474,6 +1707,7 @@ export function paintEffects(context, effects, timeMs, options) {
1474
1707
  }
1475
1708
  }
1476
1709
  paintPrimitives(context, effectPrimitives(effects, timeMs), { backdrop });
1710
+ paintArrows(context, effects, timeMs);
1477
1711
  paintStamps(context, effects, timeMs);
1478
1712
  paintLasers(context, effects, timeMs);
1479
1713
  }
@@ -1,5 +1,5 @@
1
1
  import type { AnnotationGeometry, Rectangle, Schedule, VideoOutput, VisualArtifact } from './contracts.js';
2
- import { type HighlightEffect, type LaserEffect, type SpotlightEffect, type StampEffect, type UnderlineEffect, type ZoomEffect } from './annotation-paint.js';
2
+ import { type ArrowEffect, type HighlightEffect, type LaserEffect, type SpotlightEffect, type StampEffect, type UnderlineEffect, type ZoomEffect } from './annotation-paint.js';
3
3
  export type { AnnotationPaint } from './annotation-paint.js';
4
4
  export type AppliedHighlightAnnotation = HighlightEffect & {
5
5
  id: string;
@@ -37,7 +37,13 @@ export type AppliedStampAnnotation = StampEffect & {
37
37
  end_frame: number;
38
38
  geometry: AnnotationGeometry;
39
39
  };
40
- export type AppliedAnnotation = AppliedHighlightAnnotation | AppliedUnderlineAnnotation | AppliedSpotlightAnnotation | AppliedZoomAnnotation | AppliedLaserAnnotation | AppliedStampAnnotation;
40
+ export type AppliedArrowAnnotation = ArrowEffect & {
41
+ id: string;
42
+ first_frame: number;
43
+ end_frame: number;
44
+ geometry: AnnotationGeometry;
45
+ };
46
+ export type AppliedAnnotation = AppliedHighlightAnnotation | AppliedUnderlineAnnotation | AppliedSpotlightAnnotation | AppliedZoomAnnotation | AppliedLaserAnnotation | AppliedStampAnnotation | AppliedArrowAnnotation;
41
47
  export declare function annotationApplications(video: VideoOutput, schedule: Schedule, visual: VisualArtifact, audioOrigin: number): AppliedAnnotation[];
42
48
  export declare function verifyAnnotations(file: string, base: string, baseFilter: string, applications: AppliedAnnotation[], video: VideoOutput, directory: string, output: string, overlayBounds?: (frame: number) => Rectangle[], sha256?: string): Promise<{
43
49
  source: string;