// lane/picture-replies: PICTURE-ONLY posts (post-picture.mjs) -- a post of only @mentions and links with an // attachment is drawn as its picture in its own card, never in the slot; a context post's beat comes before the read. import assert from "node:assert/strict"; import { test } from "node:test"; import { isPictureOnly, onlyMentions, pictureBeatSeconds, pictureReplyKnobs, pictureRuleEntry, validatePictureOnly, validatePictureReplyRender } from "./post-picture.mjs"; import { mediaSteps, panelEntry, postCardHtml, postItemPlan, postLayout, readingSeconds, slotMediaOf, validatePostItem, validatePostItems } from "./post-item.mjs"; import { pictureBeats, threadLayout } from "./post-thread.mjs"; const at = (h, m = 0) => `2026-11-02T${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}:00.000Z`; const GIF = { src: "posts-media/furri-x/9/9_1.mp4", kind: "gif", width: 480, height: 270, seconds: 2.53 }; const IMG = { src: "posts-media/kir-x/7/7_1.jpg", kind: "image", width: 1127, height: 500 }; const VID = { src: "posts-media/subj-x/1/1_1.mp4", kind: "video", width: 1080, height: 1200, seconds: 46.3, audio: true }; const WORDS = "then don't antagonize me, that's something the community needs to learn, the worst thing you can do with me is antagonize me"; const base = (o = {}) => ({ type: "post", id: "p-1", post: "subj-x/1", platform: "x", author: "Subject", handle: "subject", date: at(21, 5), text: WORDS, ...o }); const narrate = (e, text = e.text) => ({ ...e, narration: { script: text, pick: 0, takes: [{ file: "narration/posts/1/take-1.wav", engine: "orpheus", voice: "zac", seconds: 8, script: text, parts: [{ n: 1, para: 0, text, start: 0, seconds: 8, role: "post" }] }] } }); const gifParent = { id: "9", author: "Furri", handle: "furri", date: at(20, 58), text: "@subject", media: [GIF] }; const R = { postNarration: { lead: 0.25 } }; test("DETECTION: words of only @mentions and links, with an attachment, are picture-only -- the knob forces or denies it", () => { assert.equal(onlyMentions("@ObviousRises"), true); assert.equal(onlyMentions(" @a @b_c https://t.co/xyz pic.x.com/abc "), true); assert.equal(onlyMentions("@ObviousRises lol"), false); assert.equal(isPictureOnly({ text: "@ObviousRises", media: [GIF] }), true); assert.equal(isPictureOnly({ text: "", media: [IMG] }), true); assert.equal(isPictureOnly({ text: "@ObviousRises", media: [] }), false, "no attachment: a mention, not a picture"); assert.equal(isPictureOnly({ text: "@a look at this", media: [IMG] }), false); assert.equal(isPictureOnly({ text: "@a", media: [IMG], pictureOnly: false }), false); assert.equal(isPictureOnly({ text: "@a look at this", media: [IMG], pictureOnly: true }), true); assert.equal(isPictureOnly({ text: "@a", media: [], pictureOnly: true }), false, "forced with nothing to draw: not"); assert.equal(isPictureOnly({ text: "@a", media: [IMG], paraphrase: "He posts a screenshot." }), false, "a paraphrase is words"); }); test("THE BEAT: a GIF's or a video's own length, an image the rule's 2 s, clamped to 1.5–4 s; the cut's knobs over it", () => { assert.equal(pictureBeatSeconds([GIF]), 2.53); assert.equal(pictureBeatSeconds([{ ...GIF, seconds: 0.8 }]), 1.5); assert.equal(pictureBeatSeconds([VID]), 8, "a video with its sound: up to maxSound"); assert.equal(pictureBeatSeconds([{ ...VID, audio: false }]), 4); assert.equal(pictureBeatSeconds([IMG]), 2); assert.equal(pictureBeatSeconds([IMG], { posts: { pictureReply: { image: 3, max: 5 } } }), 3); assert.deepEqual(pictureReplyKnobs(undefined), { on: true, image: 2, min: 1.5, max: 4, maxSound: 8 }); }); test("A PICTURE-ONLY PARENT (furri's '@subject' and a GIF): its own beat before his read, drawn in its card in full, never in the slot -- the read moved, the take untouched", () => { const e = narrate(base({ parents: [gifParent], media: [VID] })); const L = threadLayout(e, R); assert.deepEqual(L.tiles.map((t) => [t.scope, t.mode, !!t.pic]), [["parent:0", "full", true], ["post", "full", false]]); assert.deepEqual(pictureBeats(e, R, L, 0), [{ scope: "parent:0", t0: 0, t1: 2.53 }]); const plan = postItemPlan(e, R); assert.equal(plan.narration.at, 0.25 + 2.53, "the read starts after the beat (and the lead)"); assert.deepEqual(plan.follow.beats, [{ scope: "parent:0", t0: 0, t1: 2.53 }]); assert.equal(plan.panel, undefined, "the GIF is never in the slot"); assert.deepEqual(plan.pics.map((p) => p.scope), ["parent:0"]); // His own video comes in with his words, not under the GIF's beat. assert.equal(plan.enter, plan.narration.at); assert.equal(plan.steps[0].at, plan.narration.at); // The GIF's tile in full through its beat, small as his read comes; his post revealed for it. const row = (sc) => plan.follow.thread.tiles.find((t) => t.scope === sc); assert.deepEqual([row("parent:0").from, row("parent:0").to, row("parent:0").t0], [[1, 1], [0.62, 0.5], 2.38]); assert.deepEqual([row("post").from, row("post").to, row("post").t0], [[1, 0], [1, 1], 2.38]); // The take's parts are its own: the item is a beat longer. const off = postItemPlan(narrate(base({ parents: [{ ...gifParent, pictureOnly: false }], media: [VID] })), R); assert.equal(Math.round((plan.total - off.total) * 1000) / 1000, 2.53); assert.deepEqual(e.narration.takes[0].parts[0].start, 0); // The card draws the GIF's place in the parent's tile, its mention small. const html = postCardHtml(e, { width: 1920, height: 1080, follow: true, thread: plan.follow.thread, mediaUrl: (s) => `file:///p/${s}`, posters: { [GIF.src]: "file:///p/still.png" } }); assert.match(html, /data-thread-tile="parent:0"[^]*class="ptext tt pmen"[^]*data-post-pic="parent:0" data-pic-kind="gif"[^]*src="file:\/\/\/p\/still.png"/); assert.doesNotMatch(html, /data-thread-media=/, "no chip pointing at the slot"); }); test("THE CUT's RULE OFF (render.posts.pictureReply.on false): the plan as before -- context, the GIF in the slot", () => { const e = narrate(base({ parents: [gifParent], media: [VID] })); const r = { ...R, posts: { pictureReply: { on: false } } }; const plan = postItemPlan(e, r); const denied = postItemPlan(narrate(base({ parents: [{ ...gifParent, pictureOnly: false }], media: [VID] })), R); assert.deepEqual(plan, denied); assert.equal(plan.pics, undefined); assert.ok(plan.panel?.shows?.some((s) => s.scope === "parent:0")); assert.equal(pictureRuleEntry(e, r).parents[0].pictureOnly, false); assert.equal(panelEntry(e, r).parents[0].pictureOnly, false); assert.equal(pictureRuleEntry(e, R), e, "on: the entry itself"); }); test("NOT PICTURE-ONLY: a post with words and a picture plays as before (no key, no beat, its attachment in the slot)", () => { const e = narrate(base({ media: [IMG], parents: [{ id: "8", author: "A", handle: "a", date: at(20), text: "@subject what do you mean by that exactly", media: [GIF] }] })); const plan = postItemPlan(e, R); assert.equal(plan.pics, undefined); assert.equal(plan.follow.beats, undefined); assert.deepEqual(plan, postItemPlan(e, { ...R, posts: { pictureReply: { on: false } } })); assert.equal(slotMediaOf(e)[0], IMG); assert.equal(postLayout(e, { width: 1920, height: 1080 }).mode, "side"); }); test("A PICTURE-ONLY ITEM (Kirsche's '@subject' and a screenshot): its picture in its card at the card's width, no slot; not narrated, it lasts its beat", () => { const e = base({ id: "p-7", post: "kir-x/7", author: "Kir", handle: "kir", text: "@ObviousRises", media: [IMG], panel: "side" }); assert.deepEqual(validatePostItem(e), []); assert.deepEqual(mediaSteps(e), []); assert.deepEqual(slotMediaOf(e), []); const L = postLayout(e, { width: 1920, height: 1080 }); assert.equal(L.mode, "text"); const plan = postItemPlan(e); assert.equal(plan.total, 2); assert.deepEqual(plan.steps, []); assert.deepEqual(plan.pics, [{ scope: "post", media: [IMG] }]); const html = postCardHtml(e, { width: 1920, height: 1080, mediaUrl: (s) => `file:///p/${s}` }); assert.match(html, /class="words pmen" data-post-words="" style="font-size:22px"/); const m = /data-post-pic="post" data-pic-kind="image" data-pic-src="[^"]+" style="width:(\d+)px;height:(\d+)px/.exec(html); assert.ok(m, "the picture drawn in the card"); assert.ok(Number(m[1]) > 900 && Math.abs(Number(m[1]) / Number(m[2]) - 1127 / 500) < 0.02, "at the card's width, its aspect kept"); assert.match(html, / { const kir = base({ id: "p-7", post: "kir-x/7", author: "Kir", handle: "kir", text: "@subject", media: [IMG], parents: [{ id: "1", author: "Subject", handle: "subject", date: at(19), text: WORDS }] }); const n = narrate(kir, "It's amazing how much discourse is just pretending not to understand things."); const plan = postItemPlan(n, R, { prev: base({ post: "subj-x/1" }) }); assert.deepEqual(plan.follow.picReads, [{ scope: "post", t0: plan.narration.at, t1: plan.follow.readEnd }]); const row = (sc) => plan.follow.thread.tiles.find((t) => t.scope === sc); assert.equal(row("parent:0").mode, "carry"); assert.deepEqual(row("parent:0").to, [0.62, 0.5], "the carried post shrinks as the read begins"); assert.deepEqual(row("post").to, [1, 1]); }); test("A PICTURE-ONLY QUOTED post the read does not read: above his post, its own beat", () => { const e = narrate(base({ quoted: { id: "5", author: "Q", handle: "q", date: at(19), text: "", media: [IMG] } })); const L = threadLayout(e, R); assert.deepEqual(L.tiles.map((t) => [t.scope, t.mode, !!t.above]), [["quoted", "full", true], ["post", "full", false]]); const plan = postItemPlan(e, R); assert.deepEqual(plan.follow.beats, [{ scope: "quoted", t0: 0, t1: 2 }]); assert.equal(plan.narration.at, 2.25); }); test("THE KNOBS are refused in the build's words", () => { assert.deepEqual(validatePictureOnly({ id: "p-1", pictureOnly: "yes", parents: [{ pictureOnly: 1 }], quoted: { pictureOnly: null } }).length, 3); assert.deepEqual(validatePictureOnly({ id: "p-1", pictureOnly: true, parents: [{ pictureOnly: false }] }), []); assert.deepEqual(validatePictureReplyRender({ posts: { pictureReply: { on: true, image: 2, min: 1, max: 4 } } }), []); assert.equal(validatePictureReplyRender({ posts: { pictureReply: { on: "x", nope: 1, image: 99, min: 3, max: 2 } } }).length, 4); assert.ok(validatePostItems({ render: { posts: { pictureReply: "on" } }, timeline: [] }).some((x) => /pictureReply/.test(x))); }); import { planContext } from "./post-conversation.mjs"; test("CARRIED AS CONTEXT a picture-only post keeps its picture: the run's next item draws it in its scene tile (small and dim), never in the slot, no beat again, its length unchanged", () => { const g = { group: "kir" }; const kir = narrate(base({ id: "p-7", post: "kir-x/7", author: "Kir", handle: "kir", text: "@subject", date: at(19), media: [IMG], thread: g }), "It's amazing how much discourse is just pretending not to understand things."); const reply = narrate(base({ id: "p-8", post: "subj-x/8", date: at(20), thread: g })); const tl = [kir, reply]; const ctx = planContext(tl, 1, R); const tile = ctx.scene.tiles.find((t) => t.id === "7"); assert.equal(tile.ref.pictureOnly, true); assert.deepEqual(tile.ref.media, [IMG]); const plan = postItemPlan(reply, R, ctx); assert.equal(plan.follow.beats, undefined, "seen already: no beat"); assert.equal(plan.panel, undefined); assert.deepEqual(plan.pics, [{ scope: "conv:7", media: [IMG], post: "kir-x/7" }]); const row = plan.follow.thread.tiles.find((t) => t.scope === "conv:7"); assert.equal(row.mode, "scene"); const html = postCardHtml(reply, { width: 1920, height: 1080, follow: true, thread: plan.follow.thread, mediaUrl: (s) => `file:///p/${s}` }); assert.match(html, /data-thread-tile="conv:7"[^]*class="ptext tt pmen"[^]*data-post-pic="conv:7" data-pic-kind="image"[^]* t.id === "7").ref.pictureOnly, undefined); assert.equal(postItemPlan(reply, off, ctxOff).total, plan.total); // Its channel's markup censors it as context too. const red = { terms: [], markup: { "kir-x/7": { censor: [{ media: 0 }] } } }; assert.match(postCardHtml(reply, { width: 1920, height: 1080, follow: true, thread: plan.follow.thread, mediaUrl: (s) => `file:///p/${s}`, redaction: red }), /data-post-pic="conv:7"[^]*filter:blur/); }); test("A PICTURE-ONLY PARENT CARRIED from the item before (the join) is drawn with its picture, as that item drew it -- no beat", () => { const kir = base({ id: "p-7", post: "kir-x/7", author: "Kir", handle: "kir", text: "@subject", date: at(19), media: [IMG] }); const reply = narrate(base({ id: "p-8", post: "subj-x/8", parents: [{ id: "7", author: "Kir", handle: "kir", date: at(19), text: "@subject", media: [IMG] }] })); const plan = postItemPlan(reply, R, { prev: kir, join: { seconds: 0.6 } }); assert.equal(plan.follow.thread.tiles.find((t) => t.scope === "parent:0").mode, "carry"); assert.equal(plan.follow.beats, undefined); const html = postCardHtml(reply, { width: 1920, height: 1080, follow: true, thread: plan.follow.thread, mediaUrl: (s) => `file:///p/${s}`, join: { size: 40, plain: true } }); assert.match(html, /data-thread-tile="parent:0"[^]*data-join-anchor=""[^]*data-post-pic="parent:0"/); }); import { postSegmentArgs } from "./post-render.mjs"; test("A PICTURE-ONLY VIDEO WITH ITS SOUND speaks through its beat: its whole length up to maxSound (8 s), its sound mixed after the read's mix (never ducked), faded; a GIF and a muted video stay silent and keep the 1.5-4 s rule", () => { const MEME = { src: "posts-media/umtool-sources/74TZdKTkr7E.mp4", kind: "video", width: 1280, height: 720, seconds: 4.92, audio: true }; assert.equal(pictureBeatSeconds([MEME]), 4.92); assert.equal(pictureBeatSeconds([{ ...MEME, seconds: 12 }]), 8); assert.equal(pictureBeatSeconds([{ ...MEME, seconds: 12 }], { posts: { pictureReply: { maxSound: 10 } } }), 10); assert.equal(pictureBeatSeconds([{ ...MEME, audio: false }]), 4); assert.equal(pictureBeatSeconds([{ ...MEME, mute: true }]), 4); assert.equal(pictureBeatSeconds([{ ...GIF, seconds: 6 }]), 4); const e = narrate(base({ parents: [{ ...gifParent, media: [MEME] }], media: [VID] })); const plan = postItemPlan(e, R); assert.deepEqual(plan.follow.beats, [{ scope: "parent:0", t0: 0, t1: 4.92 }]); assert.deepEqual(plan.pics, [{ scope: "parent:0", media: [MEME], sound: { t0: 0, t1: 4.92 } }]); assert.equal(plan.narration.at, 0.25 + 4.92); const L = postLayout(e, { width: 1920, height: 1080 }); const argv = postSegmentArgs({ entry: e, box: { width: 1920, height: 1080 }, plan, layout: L, cards: { read: "r.png" }, files: ["v.mp4"], render: { fps: 30 }, outPath: "o.mp4", narration: { file: "t.wav" }, picSounds: [{ m: MEME, file: "meme.mp4", t0: 0, t1: 4.92 }] }); const fc = argv[argv.indexOf("-filter_complex") + 1]; assert.match(fc, /atrim=0:4\.92,afade=t=in:d=0\.04,afade=t=out:st=4\.8:d=0\.12,adelay=0\|0\[psd0\]/); assert.match(fc, /\[aps\]\[psd0\]amix=inputs=2:normalize=0:duration=first\[a\]/, "after the read's mix, never ducked"); // A GIF: no sound span. assert.equal(postItemPlan(narrate(base({ parents: [gifParent], media: [VID] })), R).pics[0].sound, undefined); // Carried as context (the run's next item): a still -- no sound span. const g = { group: "m" }; const tl = [narrate(base({ id: "p-7", post: "f-x/7", handle: "furri", text: "@subject", date: at(19), media: [MEME], thread: g }), "x"), narrate(base({ id: "p-8", post: "subj-x/8", thread: g }))]; const later = postItemPlan(tl[1], R, planContext(tl, 1, R)); assert.ok(later.pics.every((p) => !p.sound)); });