Skip to content

The open-source full-stack studio for Opus 5.5 motion video. Reverse engineering for any video. Code video with HTML: recreate, edit and render. BYOA + BYOK · Motion.md · Images, Video, Music & Voice.

fix(templates): reset decision-tree selection during playback

qindong6f7e2e0c55a6
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 86c32a76..d2b97e6b 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -141,6 +141,8 @@ jobs:
run: node --experimental-strip-types --test tests/diagnostics.test.ts tests/install.test.ts tests/npm-installer.test.ts tests/native-runtime.test.ts tests/npm-package.test.ts tests/test-package.test.ts tests/source-install.test.ts tests/bootstrap.test.ts tests/mcp-registry.test.ts tests/mcp-runtime.test.ts tests/mcp-upgrade.test.ts tests/preview.test.ts tests/editor-urls.test.ts tests/workspace-studio.test.ts tests/sync.test.ts tests/phase1.test.ts tests/preview-handoff.test.ts tests/adapters.test.ts tests/package.test.ts tests/recreate-measure.test.ts tests/workflow.test.ts tests/catalog.test.ts tests/prism-templates.test.ts tests/extension-boundary.test.ts tests/connections.test.ts tests/install-guide.test.ts tests/readme-resources.test.ts tests/motion-design-remix.test.ts
- name: Studio regression
run: npm run test:studio -- --maxWorkers=2
+ - name: Built-in template playback regression
+ run: node --experimental-strip-types --test tests/decision-tree.test.ts
- name: Build phase-one ZIP and exercise all public tools
run: |
npm run package:phase1
diff --git a/template-library/decision-tree/compositions/decision_tree.html b/template-library/decision-tree/compositions/decision_tree.html
index daf4ded4..f8e05ab6 100644
--- a/template-library/decision-tree/compositions/decision_tree.html
+++ b/template-library/decision-tree/compositions/decision_tree.html
@@ -85,6 +85,7 @@
/>
</svg>
</div>
+ <div class="selection-border"></div>
</div>
<div id="node-nocode" class="node sticky blue" style="left: 800px; top: 500px">
Try no-code first
@@ -276,6 +277,7 @@
<script>
(function () {
const tl = gsap.timeline({ paused: true });
+ const selectionBorder = document.querySelector("#node-python > .selection-border");
// 1. Root node scales from 0→100% over 0.4s
tl.to("#node-root", { scale: 1, duration: 0.4, ease: "power2.out" });
@@ -347,16 +349,7 @@
);
// 10. Cursor clicks. Selection border appears.
- tl.add(() => {
- const node = document.querySelector("#node-python");
- if (!node) return;
- if (!node.querySelector(".selection-border")) {
- const border = document.createElement("div");
- border.className = "selection-border";
- node.appendChild(border);
- }
- gsap.set(".selection-border", { opacity: 1 });
- }, "hold3+=1");
+ tl.set(selectionBorder, { opacity: 1 }, "hold3+=1");
// Visual click feedback
tl.to(
@@ -415,7 +408,7 @@
{ scale: 0.8, duration: 0.05, yoyo: true, repeat: 1, overwrite: "auto" },
"hold6+=0.3",
);
- tl.to(".selection-border", { opacity: 0, duration: 0.1 }, "hold6+=0.3");
+ tl.to(selectionBorder, { opacity: 0, duration: 0.1 }, "hold6+=0.3");
// 17. 👍 emoji pops in
tl.to("#emoji-thumb", { scale: 1, duration: 0.15, ease: "back.out(2)" }, "hold6+=0.4");
diff --git a/tests/decision-tree.test.ts b/tests/decision-tree.test.ts
new file mode 100644
index 00000000..ccb727a8
--- /dev/null
+++ b/tests/decision-tree.test.ts
@@ -0,0 +1,89 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { mkdtemp, readFile, rm } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+import { JSDOM } from 'jsdom';
+import { copyTemplate } from '../template-library.ts';
+import { pluginRoot } from '../hyperframes.ts';
+
+test('the decision-tree selection follows playback, seeking, replay and loops', async () => {
+ const directory = await mkdtemp(path.join(tmpdir(), 'motion-decision-tree-'));
+ const dom = new JSDOM('<!doctype html><body><div class="selection-border" style="opacity:0.4"></div></body>', {
+ runScripts: 'outside-only',
+ pretendToBeVisual: true,
+ });
+ try {
+ await copyTemplate('decision-tree', directory, pluginRoot);
+ const source = await readFile(path.join(directory, 'compositions/decision_tree.html'), 'utf8');
+ dom.window.document.body.insertAdjacentHTML('beforeend', source);
+ const template = dom.window.document.querySelector('template')!;
+ dom.window.document.body.appendChild(template.content.cloneNode(true));
+ const script = dom.window.document.querySelector('script:not([src])')!.textContent!;
+ const warnings: string[] = [];
+ dom.window.console.warn = (...args) => warnings.push(args.join(' '));
+ dom.window.eval(await readFile(path.join(directory, 'vendor/gsap-3.14.2/dist/gsap.min.js'), 'utf8'));
+ dom.window.eval(script);
+ const timeline = dom.window.__timelines['decision-tree'];
+ const selectedAt = timeline.labels.hold3 + 1;
+ const deselectAt = timeline.labels.hold6 + 0.3;
+ const duration = timeline.duration();
+ assert.equal(selectedAt, 5.45);
+ assert.equal(deselectAt, 7.35);
+ assert.equal(duration, 10.1);
+ const borderOpacity = () => {
+ const borders = dom.window.document.querySelectorAll('#node-python > .selection-border');
+ assert.equal(borders.length, 1, 'playback must retain one selection border');
+ return Number(dom.window.getComputedStyle(borders[0]).opacity);
+ };
+ const assertAt = (time: number, expected: number, suppressEvents: boolean) => {
+ timeline.seek(time, suppressEvents);
+ assert.equal(borderOpacity(), expected, `selection opacity at ${time}s`);
+ };
+ assert.equal(borderOpacity(), 0);
+
+ // Ordinary playback must hide the border after the click-away fade.
+ timeline.seek(0, false);
+ for (let frame = 1; frame <= Math.ceil((deselectAt + 0.2) * 60); frame++) {
+ timeline.time(frame / 60, false);
+ }
+ assert.equal(borderOpacity(), 0);
+
+ // Studio scrubbing suppresses callbacks and can visit frames in either order.
+ for (const suppressEvents of [true, false]) {
+ assertAt(selectedAt - 0.01, 0, suppressEvents);
+ assertAt(selectedAt, 1, suppressEvents);
+ assertAt(deselectAt, 1, suppressEvents);
+ timeline.seek(deselectAt + 0.05, suppressEvents);
+ assert.ok(borderOpacity() > 0 && borderOpacity() < 1, 'deselection retains its 0.1s fade');
+ assertAt(deselectAt + 0.1, 0, suppressEvents);
+ assertAt(selectedAt + 0.1, 1, suppressEvents);
+ assertAt(0, 0, suppressEvents);
+ assertAt(duration, 0, suppressEvents);
+ }
+
+ // Reopening the composition starts with the same hidden selection.
+ timeline.kill();
+ dom.window.eval(script);
+ const replay = dom.window.__timelines['decision-tree'];
+ replay.seek(deselectAt + 0.2);
+ assert.equal(borderOpacity(), 0);
+ replay.restart().pause();
+ assert.equal(borderOpacity(), 0);
+ replay.seek(selectedAt + 0.1);
+ assert.equal(borderOpacity(), 1);
+ replay.repeat(1);
+ replay.totalTime(duration + 0.1, false);
+ assert.equal(borderOpacity(), 0);
+ replay.totalTime(duration + selectedAt + 0.1, false);
+ assert.equal(borderOpacity(), 1);
+ replay.totalTime(duration + deselectAt + 0.2, false);
+ assert.equal(borderOpacity(), 0);
+ assert.equal(dom.window.document.querySelector('body > .selection-border')!.style.opacity, '0.4');
+ assert.deepEqual(warnings, []);
+ } finally {
+ dom.window.gsap?.ticker.sleep();
+ dom.window.close();
+ await rm(directory, { recursive: true, force: true });
+ }
+});