Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ published without one. The same script, with no arguments, holds
Instagram the 4:5 slides and every other platform the 9:16, in one post.
Posts made before keep the old engine, so nothing already sent looks
different. Through PostBridge, every platform gets the 9:16 slides.
- **Short videos with their text on screen** (#657). A video post that has
a hook now offers "Text on screen" above its clip: the hook stands over
the first three seconds and the save line over the last, clear of where
TikTok, Reels and Shorts draw their own buttons, so the video reads with
the sound off. "Save with the words on it" records the clip with its
text as one MP4, in the desktop app or Chrome, and makes it the take that
publishes; the clip without text stays as a take to go back to. Saving
takes as long as the clip.
- **Carousels in your brand's colors** (#657). In the Brand tab, under your
two colors, "Use these colors on carousels" gives new carousel posts your
primary color as the ground of text slides and your secondary behind pill
Expand Down
15 changes: 14 additions & 1 deletion app/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,22 @@ The rules as code are `lib/artifactFormat.js`, and each artifact's own
`drawnByTemplate` decides, and the backend's `drawn_by_template` says the
same. The template's page loads nothing, so its pictures come as data:
URLs from `GET /content/posts/{id}/pictures`, one slide at a time.
- **A stage along time is words over a clip.** The manifest's
`stage.under` names the run's clips (`stageUnder`); `host/TimeStage.jsx`
plays the first in its own `<video>` and lays the template's page over it
with a clear ground, sending the page the clip's time on every frame (one
seek in flight at a time). The page keeps no clock. The second template
is `src/artifacts/captioned-short/`. `lib/stageExport.js` saves one as an
MP4 by recording a canvas in real time: the clip must be a blob: url or on
this origin to be read back, so the app fetches it through
`GET /content/posts/{id}/clip`. A video post's own words map onto the
template in `lib/shortRun.js` (its hook, its save line); the saved file
goes back as a new take (`POST /content/posts/{id}/video/takes`).
- **A brand's version of a template sets values, never code.** A project
keeps its carousel look in `content_brand.carousel` (the template by
range, the values); `lib/carouselBrand.js` works the values out from the
range, the values), and each post a copy from the day it was made
(`carousel_look`): a post is always drawn with its own copy, so a later
change never redraws half of it. `lib/carouselBrand.js` works the values out from the
brand's two colours and holds a saved version to the template's own
`values.schema.json` through `fromTemplate`. One that fails is not used
and the template's own look is drawn. A colour ends up in a stylesheet,
Expand Down
10 changes: 9 additions & 1 deletion app/scripts/check-still-rules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
// The words of those rules are unit-tested. Whether the walk meets every way
// a browser can be asked to load something is not something Node can say: it
// has no parser, and an escape can spell `url` in ways only a parser reads.
// So this runs `sealStill` itself in both engines, on stills that each try
// So this runs `stillMarkup` and `sealStill` itself in both engines, as
// captureStill does, on stills that each try
// one way out, and fails when one is let through or when any request leaves.
// A still that passes is put in the document as the app would put it, so a
// rule that stops refusing shows up twice: as a pass, and as a request.
Expand Down Expand Up @@ -85,6 +86,10 @@ const HOSTILE = {
"a table background": still(frame(`<table background="${OUT}/background"><tr><td>x</td></tr></table>`)),
"a link to follow": still(frame(`<a href="${OUT}/anchor">x</a>`)),
"a second element beside the frame": still(`${frame("")}<img src="${OUT}/sibling">`),
// The parser makes these shadow roots, which a walk of the document never enters.
"a picture in an open shadow root": still(frame(`<div><template shadowrootmode="open" shadowrootclonable><img src="${OUT}/shadow-open"></template></div>`)),
"a stylesheet in a closed shadow root": still(frame(`<div><template shadowrootmode="closed" shadowrootclonable><style>p{background:url(${OUT}/shadow-closed)}</style><p>x</p></template></div>`)),
"a template holding a picture": still(frame(`<template><img src="${OUT}/template"></template>`)),
};

// What a real template sends. All must pass, and still reach nothing.
Expand All @@ -103,11 +108,14 @@ const SOUND = {

const PAGE = `<!doctype html><html><body><script type="module">
import { sealStill } from "/lib/stageCapture.js";
import { stillMarkup } from "/lib/artifactFormat.js";
import { withFramePolicy } from "/lib/framePolicy.js";
// As lib/stageCapture.js captureStill does it, up to the drawing: parse the
// still in a frame that runs nothing, seal it, and put a still that passed
// into this document.
window.seal = async (html, media) => {
const unparsed = stillMarkup(html);
if (unparsed) return { problems: [unparsed], src: null };
const iframe = document.createElement("iframe");
iframe.setAttribute("sandbox", "allow-same-origin");
document.body.appendChild(iframe);
Expand Down
113 changes: 107 additions & 6 deletions app/src/app/preview/scenes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ import ArtifactView from "@/components/artifacts/host/ArtifactView";
import StageView from "@/components/artifacts/host/StageView";
import { sizeRatio } from "@/lib/artifactFormat";
import { captureSizes } from "@/lib/stageCapture";
import { exportClip, recordType } from "@/lib/stageExport";
import { brandValues } from "@/lib/carouselBrand";
import { SAMPLE_BRAND } from "@/lib/__fixtures__/carouselBrand.mjs";
import CarouselLook from "@/components/content/CarouselLook";
import { ARTIFACTS } from "@/artifacts/index.gen";
import SAMPLE_CAROUSEL from "@/artifacts/carousel/sample.json";
import SAMPLE_SHORT from "@/artifacts/captioned-short/sample.json";
import MemoryTimeline from "@/components/memory/MemoryTimeline";
import PlanKanban from "@/components/content/PlanKanban";
import PlanStrategy from "@/components/content/PlanStrategy";
Expand Down Expand Up @@ -1636,6 +1638,12 @@ function PostVideoScene() {
<PostVideo postId="p0" video={null} takes={[]} />
<PostVideo postId="p1" video={takes[0]} takes={[{ ...takes[0], is_cut: true }]} />
<PostVideo postId="p3" video={takes[1]} takes={takes} />
<PostVideo
postId="p4"
video={{ ...takes[0], duration_seconds: 3 }}
takes={[{ ...takes[0], duration_seconds: 3, is_cut: true }]}
words={{ hook: "Your product photos are costing you sales", close: "Save this for your next shoot" }}
/>
</div>
);
}
Expand Down Expand Up @@ -2321,7 +2329,76 @@ function CarouselLookScene() {
}

// A carousel template from a newer Duct: it runs along time, which this app cannot play yet.
const SHORT_VIDEO = { ...CAROUSEL, manifest: { ...CAROUSEL.manifest, id: "duct/artifacts/captioned-short", stage: { sizes: ["1080x1920"], along: "time", fps: 30, length: { "@path": "/duration" } } } };
const STEPPED = { ...CAROUSEL, manifest: { ...CAROUSEL.manifest, id: "duct/artifacts/tap-through", stage: { sizes: ["1080x1920"], along: "steps", length: { "@path": "/steps" } } } };

// The captioned-short template (src/artifacts/captioned-short), its sample
// words over the preview's own clip.
const SHORT = ARTIFACTS["duct/artifacts/captioned-short"];
const SHORT_CLIP = { type: "resource_link", uri: "duct://assets/preview-clip", name: "preview-clip", mimeType: "video/mp4" };
// The preview's clip is three seconds long, so the sample's nine are played at a third.
const SHORT_SECONDS = 3;
const scaled = (seconds) => Math.round((seconds * SHORT_SECONDS * 100) / SAMPLE_SHORT.duration) / 100;
const SHORT_RUN = {
...SAMPLE_SHORT,
duration: SHORT_SECONDS,
hook: { ...SAMPLE_SHORT.hook, until: scaled(SAMPLE_SHORT.hook.until) },
captions: SAMPLE_SHORT.captions.map((cue) => ({ ...cue, from: scaled(cue.from), to: scaled(cue.to) })),
shots: [{ from: 0, to: SHORT_SECONDS, media: SHORT_CLIP }],
};

function ShortScene({ run = SHORT_RUN }) {
// The clip's url on this origin, known only in the browser.
const [media, setMedia] = useState(null);
useEffect(() => setMedia({ [SHORT_CLIP.uri]: here(CLIP) }), []);
if (!media) return null;
return (
<div className="mx-auto max-w-md p-5">
<StageView artifact={SHORT} run={run} media={media} />
</div>
);
}

/** The export, run on a button: the clip with its words, as one MP4. Preview only. */
function ShortExportScene() {
const [state, setState] = useState({ step: "idle" });
// What this browser records is known only in the browser.
const [type, setType] = useState(undefined);
useEffect(() => setType(recordType()), []);
async function save() {
setState({ step: "saving", done: 0, of: SHORT_SECONDS });
try {
const out = await exportClip({
artifact: SHORT,
run: SHORT_RUN,
media: { [SHORT_CLIP.uri]: here(CLIP) },
onProgress: (done, of) => setState({ step: "saving", done, of }),
});
setState({ step: "done", url: URL.createObjectURL(out.blob), type: out.type, bytes: out.blob.size, seconds: out.seconds });
} catch (e) {
setState({ step: "failed", why: `${e.code || "failed"}: ${e.detail || e.message}` });
}
}
return (
<div className="mx-auto flex max-w-md flex-col gap-4 p-5">
{type !== undefined && (
<p className="text-sm text-muted-foreground" data-record-type={type || "none"}>
{type ? `This browser records ${type}.` : "This browser records no MP4, so the export says so and records nothing."}
</p>
)}
<Button onClick={save} disabled={state.step === "saving"}>Save with the words on it</Button>
{state.step === "saving" && <p className="text-sm tabular-nums">Recording {state.done.toFixed(1)} of {state.of.toFixed(1)} s</p>}
{state.step === "failed" && <p role="alert" data-export="failed" className="text-sm text-destructive">{state.why}</p>}
{state.step === "done" && (
<div data-export="done" data-bytes={state.bytes} data-type={state.type} className="flex flex-col gap-2">
<video src={state.url} controls playsInline className="w-56 rounded-lg border border-border" />
<a href={state.url} download="captioned-short.mp4" className="text-sm underline">
{state.type} · {(state.bytes / 1e6).toFixed(1)} MB · {state.seconds.toFixed(1)} s
</a>
</div>
)}
</div>
);
}

/**
* What a stage would publish: every page drawn to a PNG at each of its
Expand Down Expand Up @@ -2437,6 +2514,30 @@ export const SCENES = [
note: "Each picture was drawn by asking the template's page for that slide as a still and drawing the still in the app, which is the only way out of a sandboxed frame. What to check: there are seven pictures in each row; each matches the same slide in the player at that size; the photo slides carry their picture.",
render: () => <StageStills artifact={CAROUSEL} run={SAMPLE_CAROUSEL} />,
},
{
id: "stage-short",
group: "Artifacts",
title: "A short video with its words on screen",
state: "the template's sample words over the preview's clip",
note: "The captioned-short template (src/artifacts/captioned-short) on a stage along time. The clip is the app's own <video>; the words are the template's page in a sandboxed frame with a clear ground, laid over it. Press play: the hook stands for the first second, then three captions come and go with the clip (the preview's clip is three seconds long). Drag the slider: the clip and the words move together. What to check: the words are clear of the top, the bottom and the right, where TikTok draws its own; they follow no theme (look at it dark: the frame must not turn white).",
render: () => <ShortScene />,
},
{
id: "stage-short-long",
group: "Artifacts",
title: "A short video whose words are too long",
state: "edge: the longest hook and caption, in German",
note: "Words that do not fit are hyphenated, then set smaller, never under 44 px, and never out of their boxes: the hook keeps to the upper part of the frame and the caption to the lower.",
render: () => <ShortScene run={{ ...SHORT_RUN, lang: "de", hook: { text: "Geschwindigkeitsbegrenzungen gelten auch für Lieferfahrräder, Lastenräder und Elektroroller in der ganzen Innenstadt", until: SHORT_SECONDS }, captions: [{ text: "Geschwindigkeitsbegrenzungen gelten auch für Lieferfahrräder und Elektroroller in der Innenstadt, sagt die Straßenverkehrsordnung", from: 0, to: SHORT_SECONDS }] }} />,
},
{
id: "stage-short-export",
group: "Artifacts",
title: "A short video saved with its words on it",
state: "one button: record the clip with the words over it",
note: "The export: every frame is asked of the template as a still, each stretch where the words do not change becomes one picture on a clear ground, and the clip is played onto a canvas under the right picture and recorded with its own sound. It takes as long as the clip. What to check: the saved video is an MP4, as long as the clip, and its words come and go where the preview's do.",
render: () => <ShortExportScene />,
},
{
id: "stage-contract-failed",
group: "Artifacts",
Expand All @@ -2453,11 +2554,11 @@ export const SCENES = [
id: "stage-host-too-old",
group: "Artifacts",
title: "A template this app is too old to play",
state: "error: a stage along time, which this app cannot drive yet",
note: "A template that runs along time (a short video) on an app that only turns pages. It is the app that is behind, not the template that is broken, so the person is told to update.",
state: "error: a stage along steps, a way of moving this app has not learned",
note: "A template from a newer Duct that moves in a way this app cannot drive (it turns pages and plays time). It is the app that is behind, not the template that is broken, so the person is told to update.",
render: () => (
<div className="mx-auto max-w-md p-5">
<StageView artifact={SHORT_VIDEO} run={{ duration: 12 }} />
<StageView artifact={STEPPED} run={{ steps: 4 }} />
</div>
),
},
Expand Down Expand Up @@ -4045,10 +4146,10 @@ export const SCENES = [
},
{
id: "post-video",
state: "no clip · one take · three takes, an older one publishing",
state: "no clip · one take · three takes, an older one publishing · a take the post has words for",
group: "PostViewport",
title: "A video post's clip and its takes",
note: "What a video post shows where a slideshow shows its slides. Before the first clip, an empty state that says what to do. With takes, the player shows one and the strip under it switches between them; watching a take and choosing it are two separate acts, so comparing never changes what publishes. The tick marks the take that goes out.",
note: "What a video post shows where a slideshow shows its slides. Before the first clip, an empty state that says what to do. With takes, the player shows one and the strip under it switches between them; watching a take and choosing it are two separate acts, so comparing never changes what publishes. The tick marks the take that goes out. The last is a post with a hook and a save line: Text on screen shows the take with them over it, and Save with the words on it records the two as one video and makes it the take that publishes (it needs a backend, so here it fails with a sentence).",
render: () => <PostVideoScene />,
},
{
Expand Down
41 changes: 41 additions & 0 deletions app/src/artifacts/captioned-short/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Captioned short

The first template on a stage along time: a short vertical video with its
words on screen. Read this before changing any file here. What a stage is:
[`docs/engineering/artifact-stage.md`](../../../../docs/engineering/artifact-stage.md).

## What is here

| File | What it is |
|---|---|
| `artifact.json` | The manifest: one 9:16 frame, 30 frames a second, the clips that play under it |
| `page.html` | The template: a page that draws the words for one moment, on a clear ground |
| `data.schema.json` | The contract: how long, the hook, the captions, the clips |
| `sample.json` | Words to show before any real video exists (it has no clip) |
| `tests/` | Fixture runs, and `checks.json`: what must hold for each |
| `artifact.lock.json` | Generated: a hash of every file here |

## What must not change

- **The page draws words, never the film.** The host plays the run's clips
(`shots`) under the page, and the page's ground is clear. A page in a
sandbox cannot be handed a film, and a still of words alone needs none.
- **The page is a function of the time it is sent.** It keeps no clock and
plays nothing: the same `at` always draws the same frame, which is what
makes the export match the preview.
- **No word lives in the page**, and every word is written as text.
- **No word is drawn under 44 px**, and every word keeps inside the safe
margins (`--safe-top`, `--safe-bottom`, `--side`): where TikTok, Reels and
Shorts draw their own tabs, captions and buttons.
- **A still is the `look` stylesheet and one `.frame` element**, with no
backslash in `look`. The host refuses a still that could run or load.
- **A caption is WebVTT's cue**: `text`, `from`, `to`, in seconds. One shows
at a time, the first whose time holds the moment.
- **A field added to `data.schema.json` is optional.**

## Changing it

1. Change the file; change `data.schema.json`, `sample.json` and the fixture
runs together when the run's shape changes.
2. `npm --prefix app run artifacts:build`, then `npm --prefix app test`.
3. Look at it: `/preview`, scenes `stage-short` and `stage-short-export`.
53 changes: 53 additions & 0 deletions app/src/artifacts/captioned-short/artifact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"$schema": "https://getduct.ai/schemas/artifact/v1.json",
"id": "duct/artifacts/captioned-short",
"version": "1.0.0",
"title": "Captioned short",
"description": "A short vertical video with its words on screen: a hook over the first seconds and captions timed to the clip, kept clear of where TikTok, Reels and Shorts draw their own buttons. The clip plays under the words. Use for a short video that has to be understood with the sound off.",
"author": {
"name": "Duct",
"handle": "duct"
},
"license": "MIT",
"icons": [
{
"src": "icons/icon.svg",
"sizes": "any",
"type": "image/svg+xml"
}
],
"display": [
"page"
],
"app": {
"kind": "static",
"entry": "page.html",
"data": "data.schema.json"
},
"stage": {
"sizes": [
"1080x1920"
],
"along": "time",
"fps": 30,
"length": {
"@path": "/duration"
},
"under": {
"@path": "/shots"
}
},
"exports": [
"video/mp4",
"image/png"
],
"permissions": {
"connectors": {
"required": [],
"optional": []
},
"model": false,
"actions": false
},
"sample": "sample.json"
}
Loading
Loading