playwright-director 0.3.0 → 0.5.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.
Files changed (82) hide show
  1. package/README.md +247 -31
  2. package/dist/Tutorial.d.ts +22 -0
  3. package/dist/Tutorial.d.ts.map +1 -1
  4. package/dist/Tutorial.js +72 -2
  5. package/dist/Tutorial.js.map +1 -1
  6. package/dist/client.d.ts +33 -0
  7. package/dist/client.d.ts.map +1 -0
  8. package/dist/client.js +72 -0
  9. package/dist/client.js.map +1 -0
  10. package/dist/fast-forward.d.ts +49 -0
  11. package/dist/fast-forward.d.ts.map +1 -0
  12. package/dist/fast-forward.js +77 -0
  13. package/dist/fast-forward.js.map +1 -0
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/init.js +6 -6
  19. package/dist/init.js.map +1 -1
  20. package/dist/merge.d.ts +4 -0
  21. package/dist/merge.d.ts.map +1 -1
  22. package/dist/merge.js +10 -3
  23. package/dist/merge.js.map +1 -1
  24. package/dist/reporter.d.ts.map +1 -1
  25. package/dist/reporter.js +3 -0
  26. package/dist/reporter.js.map +1 -1
  27. package/dist/site/build-site.d.ts +18 -1
  28. package/dist/site/build-site.d.ts.map +1 -1
  29. package/dist/site/build-site.js +39 -8
  30. package/dist/site/build-site.js.map +1 -1
  31. package/dist/site/embed.d.ts +40 -18
  32. package/dist/site/embed.d.ts.map +1 -1
  33. package/dist/site/embed.js +48 -13
  34. package/dist/site/embed.js.map +1 -1
  35. package/dist/site/generate-manifest.d.ts.map +1 -1
  36. package/dist/site/generate-manifest.js +28 -3
  37. package/dist/site/generate-manifest.js.map +1 -1
  38. package/dist/site/scaffold.d.ts +7 -0
  39. package/dist/site/scaffold.d.ts.map +1 -1
  40. package/dist/site/scaffold.js +33 -7
  41. package/dist/site/scaffold.js.map +1 -1
  42. package/dist/site/scan-tutorials.d.ts +4 -1
  43. package/dist/site/scan-tutorials.d.ts.map +1 -1
  44. package/dist/site/scan-tutorials.js +9 -7
  45. package/dist/site/scan-tutorials.js.map +1 -1
  46. package/dist/site/strings.d.ts +34 -0
  47. package/dist/site/strings.d.ts.map +1 -0
  48. package/dist/site/strings.js +91 -0
  49. package/dist/site/strings.js.map +1 -0
  50. package/dist/site/types.d.ts +27 -1
  51. package/dist/site/types.d.ts.map +1 -1
  52. package/dist/styles.css +50 -0
  53. package/dist/timeline.d.ts +18 -1
  54. package/dist/timeline.d.ts.map +1 -1
  55. package/dist/timeline.js +47 -3
  56. package/dist/timeline.js.map +1 -1
  57. package/dist/tts-provider.js +1 -1
  58. package/dist/voice-dir.d.ts +9 -0
  59. package/dist/voice-dir.d.ts.map +1 -0
  60. package/dist/voice-dir.js +21 -0
  61. package/dist/voice-dir.js.map +1 -0
  62. package/dist/voice.d.ts +3 -0
  63. package/dist/voice.d.ts.map +1 -1
  64. package/dist/voice.js +29 -16
  65. package/dist/voice.js.map +1 -1
  66. package/dist/zoom.js +1 -1
  67. package/dist/zoom.js.map +1 -1
  68. package/package.json +9 -2
  69. package/schemas/embed-v1.schema.json +69 -0
  70. package/skills/tutorialize/SKILL.md +5 -0
  71. package/skills/tutorialize/agent.md +6 -0
  72. package/skills/tutorialize/references/api.md +64 -7
  73. package/skills/tutorialize/references/storytelling.md +24 -0
  74. package/src/styles.css +50 -0
  75. package/templates/site/public/widget.js +278 -141
  76. package/templates/site/src/components/TutorialsHome.astro +36 -8
  77. package/templates/site/src/components/VideoCard.astro +10 -5
  78. package/templates/site/src/components/VideoModal.astro +4 -3
  79. package/templates/site/src/i18n.ts +14 -0
  80. package/templates/site/src/layouts/Base.astro +7 -2
  81. package/templates/site/src/pages/[lang]/index.astro +16 -0
  82. package/templates/site/src/pages/[slug].astro +142 -30
@@ -25,9 +25,9 @@ Or use a fixture that wraps this (the consuming project typically provides a `tu
25
25
  | Option | Type | Default | Description |
26
26
  |---|---|---|---|
27
27
  | `title` | `string` | *required* | Overlay title |
28
- | `lang` | `string` | `'en'` | Language for TTS and UI |
28
+ | `lang` | `string` | `'en'` (`env TUTORIAL_LANG` wins) | Narration + TTS language. `TUTORIAL_LANG=xx` records one spec per language: outputs get `.<lang>`; read `tutorial.lang` to drive the app UI (`?lang=`) |
29
29
  | `translate` | `(key: string) => string` | identity | i18n function — pass your `t()` |
30
- | `audioBaseUrl` | `string` | `'http://localhost:5173'` | Base URL for audio files |
30
+ | `audioBaseUrl` | `string` | `'http://localhost:5173'` | Origin the narration plays from — Playwright serves the clips from `tutorials/.cache/voice` (`TUTORIAL_VOICE_DIR`) |
31
31
  | `testTitle` | `string` | auto | Raw test title (for reporter matching) |
32
32
  | `testFile` | `string` | `''` | Test file path (metadata) |
33
33
  | `projectName` | `string` | `''` | Playwright project name |
@@ -131,6 +131,8 @@ Use these inside step actions instead of raw Playwright calls — they add curso
131
131
  | `tutorial.unhighlight(locator)` | — | Remove highlight |
132
132
  | `tutorial.zoom(locator, options?)` | — | Camera zoom on the element (button, field, whole card), hold `duration` (1500ms), zoom back out. Options: `scale` (auto: fit ~70% of viewport, max 2.5×), `blur` (`true` = 4px, or px), `transition` (600ms per direction) |
133
133
  | `tutorial.zoomIn(locator, options?)` / `tutorial.zoomOut()` | — | Zoom in and stay zoomed — `tutorial.click()` etc. work in the zoomed view — then zoom out. Keep the pair inside one step |
134
+ | `tutorial.fastForward(speed, action, options?)` | — | Run `action` with the final video playing `speed`× faster (VHS look). Returns the action's result. Options: `vhs` (default `true`). See §14 |
135
+ | `tutorial.startFastForward(speed, options?)` / `tutorial.endFastForward()` | — | Explicit start / end markers of a fast-forwarded span. Keep the pair inside one step |
134
136
  | `tutorial.moveMouseToElement(locator)` | — | Animate cursor to element |
135
137
  | `tutorial.showEmailPreview(options)` | — | Simulated email popup |
136
138
  | `tutorial.switchPage(page)` | — | Switch recording to another tab |
@@ -305,7 +307,7 @@ Never override `--reporter` on the CLI — it disables the merge step.
305
307
  ```
306
308
  tutorials/
307
309
  ├── output/
308
- │ └── {name}_timeline.json # Timing + ffmpeg command
310
+ │ └── {name}_timeline.json # Timing (+ fast-forward spans) + ffmpeg command
309
311
  ├── transcripts/
310
312
  │ └── {name}.md # Auto-generated transcript (editable — see below)
311
313
  └── videos/
@@ -315,12 +317,25 @@ tutorials/
315
317
  ```
316
318
 
317
319
  `npx playwright-director build-site` turns this directory into a static gallery
318
- site. Besides the pages, the build emits `widget.js` + `embed/<slug>.json`
320
+ site (no astro needed in the project; `timelines` / `videos` in the site config
321
+ point elsewhere when `TUTORIAL_OUTPUT_DIR` is overridden). Besides the pages, the build emits `widget.js` + `embed/<slug>.json`
319
322
  payloads so any app can embed a tutorial in-app: load
320
323
  `<script src="<site>/widget.js" defer>` and add a `data-tutorial="<slug>"`
321
324
  attribute to any element (slug = video id, i.e. the tutorial `name` plus
322
325
  `-<variant>` if any). `window.PlaywrightDirector.open(slug)` is the programmatic
323
- equivalent.
326
+ equivalent. Apps with their own player use the headless API:
327
+ `PlaywrightDirector.load(slug, { lang })` or, bundled,
328
+ `import { load } from 'playwright-director/client'` — the payload with absolute
329
+ URLs and chapter times (`steps[].at`, seconds). Schema:
330
+ `schemas/embed-v1.schema.json`.
331
+
332
+ Widget: a native modal `<dialog>` (focus trap, Esc, focus returned), chapters
333
+ that seek (arrows/Home/End), fr/en/ar strings picked from `data-tutorial-lang`
334
+ or `<html lang>`. Theme it from the app with `--pd-accent`, `--pd-surface`,
335
+ `--pd-text`, `--pd-muted`, `--pd-border`, `--pd-radius`, `--pd-font`,
336
+ `--pd-focus-ring` on `.playwright-director-widget`. The build writes `_headers`
337
+ (CORS + cache) for Cloudflare Pages / Netlify; `--base=/help/` deploys under a
338
+ sub-path, `-y` never prompts, `--only=<slug>` builds just that tutorial.
324
339
 
325
340
  ### Reviewing & correcting narration
326
341
 
@@ -334,7 +349,8 @@ lines in order (a key used twice corrects each occurrence in turn;
334
349
  boundary and both halves replaced. Texts sourced from an i18n catalog, or a
335
350
  first sentence that is the verbatim step key, are never rewritten — they are
336
351
  reported with their key for a manual fix in the translations. Re-run with
337
- `TUTORIAL_MODE=true` afterwards: only changed TTS clips are regenerated
352
+ `TUTORIAL_MODE=true` afterwards — `npx playwright test -g "<test title>"`
353
+ re-records just that tutorial; only changed TTS clips are regenerated
338
354
  (content-hash caching). `npx tutorial-transcript` (no subcommand) just
339
355
  regenerates the transcripts from the timeline JSON.
340
356
 
@@ -507,7 +523,47 @@ tutorial.step('Turn on reminders', async () => {
507
523
  - Pure decoration: no-op without `TUTORIAL_MODE`, not recorded in the timeline, safe in plain E2E runs.
508
524
  - Don't zoom on every step — 1 to 3 zooms per tutorial, on the moments the viewer must not miss (see `storytelling.md` §9).
509
525
 
510
- ## 14. Checklist
526
+ ## 14. Fast-forward
527
+
528
+ For a stretch nobody wants to watch in real time — a slow generation, an import, a repetitive fill — mark it with start/end markers: ffmpeg plays it `speed`× faster in the final video, VHS-style (`▶▶ ×N` badge, scanlines, rolling tracking band, tape grain, chroma shift). The test still runs at normal speed.
529
+
530
+ ```typescript
531
+ tutorial.step('Generate the quarterly report', async () => {
532
+ await tutorial.click(page.locator('#generate'));
533
+ await tutorial.fastForward(8, async () => {
534
+ await expect(page.locator('#report')).toBeVisible({ timeout: 60_000 });
535
+ });
536
+ }, { explain: 'It takes a while — we skip ahead.' });
537
+
538
+ // Explicit markers
539
+ tutorial.step('Fill the twelve rows', async () => {
540
+ await tutorial.startFastForward(4, { vhs: false }); // plain speed-up, no VHS look
541
+ for (const row of rows) await tutorial.fill(page.locator(`#amount-${row.id}`), row.amount);
542
+ await tutorial.endFastForward();
543
+ });
544
+ ```
545
+
546
+ | Argument / option | Default | Effect |
547
+ |---|---|---|
548
+ | `speed` | — (required, `> 1`) | Playback speed of the span in the final video |
549
+ | `vhs` | `true` | VHS look; `false` = plain speed-up |
550
+
551
+ ### Timing
552
+
553
+ - Any number of spans per video, each with its own speed.
554
+ - A span of `L` ms at speed `S` lasts `L / S` ms on video. Final length = `tape − Σ L × (1 − 1/S)` — predictable to a few ms.
555
+ - Timeline JSON: `totalDurationMs` = final length, `tapeDurationMs` = recorded length, `fastForward[]` = spans (`startMs`/`endMs` tape time, `outputStartMs`/`outputEndMs` video time, `speed`). Step `startMs` values are already video time, so voice clips, transcripts and the gallery need nothing special.
556
+ - `startFastForward()` first **waits for the step's narration clip to finish** — speech is never sped up and never plays over sped-up video. So the step's narration plays at 1×, then the tape speeds up.
557
+
558
+ ### Rules
559
+
560
+ - Call it **inside a step's action** — outside `complete()` it warns and does nothing.
561
+ - Keep the span inside its step; one left open is closed when the step's action returns (before the step screenshot).
562
+ - Say it in the narration ("this takes a moment — let's skip ahead") so the speed-up reads as intentional.
563
+ - Fast-forward the wait, not the payoff: end the span before the result the viewer must see.
564
+ - No-op without `TUTORIAL_MODE` — `fastForward()` just runs the action; a speed `≤ 1` throws in both modes.
565
+
566
+ ## 15. Checklist
511
567
 
512
568
  Before submitting a tutorialized test:
513
569
 
@@ -525,6 +581,7 @@ Before submitting a tutorialized test:
525
581
  - [ ] Video watched — does it feel human?
526
582
  - [ ] Zooms (if any) land on what the narration names, ≤ 3 per tutorial, each `zoomIn` paired with a `zoomOut` in the same step
527
583
  - [ ] Secrets (passwords, API keys) typed with `typeBlurred`, never `fill`/`typeSlowly`
584
+ - [ ] Long waits / repetitive chores wrapped in `fastForward(speed, …)` inside their step, and the narration announces the skip
528
585
 
529
586
  Multi-scene tutorials, additionally:
530
587
 
@@ -221,3 +221,27 @@ A zoom is a beat. Let the narration name the thing *while* the camera pushes in
221
221
  ### Secrets stay secret
222
222
 
223
223
  Passwords, API keys and tokens are typed with `typeBlurred()` — the field is blurred before the first keystroke and stays blurred. Say so in the narration ("type your password — it stays hidden") so the blur reads as intentional, not as a glitch.
224
+
225
+ ## 10. Pacing the Dead Time — Fast-Forward
226
+
227
+ A real app makes the viewer wait: a report generates for 30 seconds, an import churns, twelve rows get filled one by one. In real time that is where viewers drop off. `fastForward(speed, …)` keeps the wait on screen — so the viewer sees that it happens and roughly how long it takes — but plays it sped up, VHS-style.
228
+
229
+ ### When to fast-forward
230
+
231
+ - **A wait the viewer must know about but needn't sit through:** a generation, a sync, an upload. Seeing the progress bar race tells them "this takes a while, it's normal".
232
+ - **Repetition after the first instance:** show the first row filled at normal speed, fast-forward the eleven others.
233
+
234
+ ### When not to
235
+
236
+ - **The payoff.** End the span before the result appears — the viewer must see the report land at 1×.
237
+ - **Anything the narration explains.** The voice is never sped up; it plays first, then the tape speeds up. Fast-forward the silent part.
238
+ - **Short waits** (under ~3s) — a cut is smoother than a 1-second blur of scanlines.
239
+
240
+ ### Pick the speed
241
+
242
+ - `4` — the viewer can still follow what changes (rows filling, a log scrolling).
243
+ - `8`–`16` — pure dead time: a progress bar, a spinner.
244
+
245
+ ### Say it
246
+
247
+ Announce the skip in the step's narration — "this takes a minute — let's skip ahead" — so the speed-up reads as a directing choice, not a glitch.
package/src/styles.css CHANGED
@@ -635,3 +635,53 @@ html[data-tutorial-variant='mobile'] .tutorial-progress {
635
635
  .tutorial-stage[data-layout='split'] .tutorial-scene[data-active='false'] .tutorial-scene-label {
636
636
  opacity: var(--tutorial-scene-inactive-opacity);
637
637
  }
638
+
639
+ /* ── Fast-forward (VHS look) ────────────────────────────────
640
+ Shown by startFastForward() for the span ffmpeg speeds up. Recorded at real
641
+ speed, so --tutorial-ff-roll is already scaled by the speed. */
642
+
643
+ #tutorial-fast-forward {
644
+ position: fixed;
645
+ inset: 0;
646
+ z-index: 2147483646;
647
+ pointer-events: none;
648
+ overflow: hidden;
649
+ }
650
+
651
+ .tutorial-ff-scanlines {
652
+ position: absolute;
653
+ inset: 0;
654
+ background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.1) 0 1px, transparent 1px 3px);
655
+ }
656
+
657
+ .tutorial-ff-tracking {
658
+ position: absolute;
659
+ left: 0;
660
+ right: 0;
661
+ height: 7%;
662
+ top: -10%;
663
+ background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.16) 40%, rgba(255, 255, 255, 0.22) 50%, rgba(255, 255, 255, 0.16) 60%, transparent);
664
+ mix-blend-mode: screen;
665
+ animation: tutorial-ff-roll var(--tutorial-ff-roll, 2.4s) linear infinite;
666
+ }
667
+
668
+ @keyframes tutorial-ff-roll {
669
+ to { top: 110%; }
670
+ }
671
+
672
+ .tutorial-ff-osd {
673
+ position: absolute;
674
+ left: var(--tutorial-ff-osd-left, 32px);
675
+ bottom: var(--tutorial-ff-osd-bottom, 28px);
676
+ font: 700 var(--tutorial-ff-osd-size, 44px)/1 'VCR OSD Mono', 'Courier New', ui-monospace, monospace;
677
+ letter-spacing: 0.06em;
678
+ color: #fff;
679
+ background: var(--tutorial-ff-osd-bg, rgba(0, 0, 0, 0.55));
680
+ padding: 8px 14px 6px;
681
+ border-radius: 6px;
682
+ text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.75), -1px 0 rgba(255, 0, 80, 0.6), 1px 0 rgba(0, 200, 255, 0.6);
683
+ }
684
+
685
+ .tutorial-ff-arrows {
686
+ margin-right: 0.3em;
687
+ }