From 4bb3465e99fec33a005563ab7870352c606cb40a Mon Sep 17 00:00:00 2001
From: hassan-software-dev
Date: Sun, 29 Nov 2026 17:25:17 +0500
Subject: [PATCH 1/2] Add sideways, straight, quick and repeating effects to
the Animation tab
The gallery grows from ten effects to twenty-eight: quick and nudge
slides, big and top-quarter arcs, a Repeat group that sets the loop bit,
and a Side group of left and right glides, including two nearly straight
slides (radius 8000, a drop of a few pixels over the whole slide).
A sideways path rides R px from where the layer sits, so choosing an
effect now moves the layer to keep the motion centred where it was, as
one undoable edit (withAnimPreset, refused on a locked layer, whole
pixels, exact round trip; Rise and Set never shift it). The preview adds
the layer position to the motion; that the firmware does the same is not
verified on a watch, and the panel says so.
All new effects are marked as not yet tried on a Watch Pro 2. compat.ts
and assertWatchCompat are untouched; every preset is checked against
animIssues and passed through assertWatchCompat in the tests.
Co-Authored-By: Claude Sonnet 5.5
---
.../editor/components/props/animation.svelte | 14 ++-
src/lib/modules/editor/core/document/edits.ts | 33 +++++-
src/lib/modules/editor/core/document/proc.ts | 28 ++++-
src/lib/modules/editor/core/render/anim.ts | 26 +++++
src/lib/modules/editor/i18n-inspector.ts | 110 ++++++++++++++++++
src/lib/modules/editor/model/edit.model.ts | 11 ++
tests/doc-anim.test.ts | 83 ++++++++++++-
7 files changed, 294 insertions(+), 11 deletions(-)
diff --git a/src/lib/modules/editor/components/props/animation.svelte b/src/lib/modules/editor/components/props/animation.svelte
index 76c8e60..26a3f66 100644
--- a/src/lib/modules/editor/components/props/animation.svelte
+++ b/src/lib/modules/editor/components/props/animation.svelte
@@ -28,7 +28,7 @@
import { t } from "../../i18n-inspector";
import { num } from "./patch";
- const { animPatched } = editorModel;
+ const { animPatched, animPresetApplied } = editorModel;
const { layer }: { layer: Layer } = $props();
const anim = $derived(animOf(layer));
@@ -54,7 +54,7 @@
};
});
- const GROUPS = ["slide", "arc"] as const;
+ const GROUPS = ["slide", "arc", "side", "repeat"] as const;
// a card's picture: the preset's own motion, fitted into 0..40 keeping its proportions
const thumb = (patch: Partial) => {
const pts = animPath({ ...STOCK_ANIM, ...patch }, 24);
@@ -73,6 +73,11 @@
let shown = $state(0);
const put = (patch: Partial) => animPatched({ id: layer.id, patch });
+ // An effect is a new geometry, and some ride far from where the layer sits (a sideways glide is
+ // R px off it): the edit moves the layer so the motion stays centred where it was (see
+ // withAnimPreset). ponytail: the simulator adds the layer's position to the motion; that the
+ // firmware does the same is not verified on a watch.
+ const apply = (patch: Partial) => animPresetApplied({ id: layer.id, patch });
// the simple controls go through safeAnim; the advanced fields write what they are given
const putSafe = (patch: Partial) => put(safeAnim(patch));
// tenths of a degree on file, degrees on screen
@@ -106,7 +111,7 @@
class="card type-caption"
class:on={preset === p.id}
aria-pressed={preset === p.id}
- onclick={() => putSafe(p.patch)}
+ onclick={() => apply(p.patch)}
>
{$t.animNoFade}
{#if presetInfo}
{presetInfo.proven ? $t.animProven : $t.animUntested}
+ {#if presetInfo.group === "side"}
+ {$t.animSideNote}
+ {/if}
{/if}
{#if path.length > 1}
diff --git a/src/lib/modules/editor/core/document/edits.ts b/src/lib/modules/editor/core/document/edits.ts
index e0faee4..8a9b896 100644
--- a/src/lib/modules/editor/core/document/edits.ts
+++ b/src/lib/modules/editor/core/document/edits.ts
@@ -5,7 +5,17 @@
// here is keyed by NodeId, which is what makes the layer identity survive an immutable update:
// the old code compared node objects, so any rebuilt parent silently invalidated `sel`.
import { hex, TAG, unhex } from "../format";
-import { PANELS, procOf, RINGS, withAnimBody, animOf, type Anim, type Proc } from "./proc";
+import {
+ PANELS,
+ procOf,
+ RINGS,
+ safeAnim,
+ withAnimBody,
+ animOf,
+ type Anim,
+ type Proc,
+} from "./proc";
+import { keepCentre } from "../render/anim";
import {
framesOf,
isPlaced,
@@ -399,3 +409,24 @@ export function withAnim(doc: Doc, id: NodeId, patch: Partial): Doc {
? doc
: patchLayer(doc, id, { extra } as Partial);
}
+
+/** An effect for a type 2 layer: its fields (kept inside ANIM_LIMITS) and, in the same edit, the
+ * layer's position moved so the motion stays centred where it was. Going from one effect to
+ * another and back leaves the layer where it started, and Rise <-> Set never moves it. A position
+ * outside an int16 is left alone, not wrapped. */
+export function withAnimPreset(doc: Doc, id: NodeId, patch: Partial): Doc {
+ const l = findLayer(doc, id);
+ const a = l && animOf(l);
+
+ if (!l || !a) return doc;
+ const safe = safeAnim(patch);
+ const next = withAnim(doc, id, safe);
+ const now = findLayer(next, id);
+
+ if (next === doc || !now || !("x" in now) || !("y" in now)) return next;
+ const shift = keepCentre(a, { ...a, ...safe });
+ const x = now.x + shift.dx;
+ const y = now.y + shift.dy;
+
+ return Math.abs(x) <= 32767 && Math.abs(y) <= 32767 ? patchLayer(next, id, { x, y }) : next;
+}
diff --git a/src/lib/modules/editor/core/document/proc.ts b/src/lib/modules/editor/core/document/proc.ts
index ef17f45..475af71 100644
--- a/src/lib/modules/editor/core/document/proc.ts
+++ b/src/lib/modules/editor/core/document/proc.ts
@@ -202,9 +202,11 @@ export const animRises = (a: Anim) => a.start <= a.end;
* unproven until the watch tests are back. The arcs use a small radius: from 180 to 360 degrees
* the image goes round half a circle of that radius, bulging left by R, (0, R) -> (-R, 0) ->
* (0, -R) relative to where it is placed; Sun Circle's radius of 3817 makes the same path a
- * nearly straight vertical slide.
+ * nearly straight vertical slide. Near 180 degrees the path runs mostly sideways (the angle
+ * growing moves the image left), but it rides R px below where the layer is placed, so the "side"
+ * group is applied together with a layer shift that keeps the motion where it was.
* ponytail: grow this list from tests on a watch, not from the firmware reading alone. */
-const geo = (R: number, start: number, end: number, duration = 2000) => ({
+const geo = (R: number, start: number, end: number, duration = 2000, flags = 0x88) => ({
duration,
start,
end,
@@ -214,7 +216,7 @@ const geo = (R: number, start: number, end: number, duration = 2000) => ({
raw10: 0,
raw16: R,
raw18: R,
- flags: 0x88,
+ flags,
});
export const ANIM_PRESETS = [
@@ -228,9 +230,27 @@ export const ANIM_PRESETS = [
{ id: "quarterUp", group: "arc", proven: false, patch: geo(200, 2700, 3600) },
{ id: "quarterDown", group: "arc", proven: false, patch: geo(200, 3600, 2700) },
{ id: "dropLong", group: "slide", proven: false, patch: geo(3817, 2600, 2800, 3000) },
+ { id: "quickRise", group: "slide", proven: false, patch: geo(3817, 2645, 2754, 800) },
+ { id: "quickSet", group: "slide", proven: false, patch: geo(3817, 2754, 2645, 800) },
+ { id: "nudgeUp", group: "slide", proven: false, patch: geo(3817, 2680, 2720, 800) },
+ { id: "nudgeDown", group: "slide", proven: false, patch: geo(3817, 2720, 2680, 800) },
+ { id: "arcBig", group: "arc", proven: false, patch: geo(233, 1801, 3600, 2500) },
+ { id: "arcBigBack", group: "arc", proven: false, patch: geo(233, 3600, 1801, 2500) },
+ { id: "quarterTop", group: "arc", proven: false, patch: geo(200, 1801, 2700) },
+ { id: "quarterTopBack", group: "arc", proven: false, patch: geo(200, 2700, 1801) },
+ { id: "glideLeft", group: "side", proven: false, patch: geo(300, 1801, 2100, 1500) },
+ { id: "glideRight", group: "side", proven: false, patch: geo(300, 2100, 1801, 1500) },
+ { id: "glideLeftFar", group: "side", proven: false, patch: geo(600, 1801, 2000, 1800) },
+ { id: "glideRightFar", group: "side", proven: false, patch: geo(600, 2000, 1801, 1800) },
+ { id: "straightLeft", group: "side", proven: false, patch: geo(8000, 1801, 1822, 1500) },
+ { id: "straightRight", group: "side", proven: false, patch: geo(8000, 1822, 1801, 1500) },
+ { id: "loopRise", group: "repeat", proven: false, patch: geo(3817, 2645, 2754, 2000, 0x89) },
+ { id: "loopSet", group: "repeat", proven: false, patch: geo(3817, 2754, 2645, 2000, 0x89) },
+ { id: "loopArc", group: "repeat", proven: false, patch: geo(150, 1801, 3600, 3000, 0x89) },
+ { id: "pulse", group: "repeat", proven: false, patch: geo(3817, 2680, 2720, 600, 0x89) },
] as const satisfies readonly {
id: string;
- group: "slide" | "arc";
+ group: "slide" | "arc" | "side" | "repeat";
proven: boolean;
patch: Partial;
}[];
diff --git a/src/lib/modules/editor/core/render/anim.ts b/src/lib/modules/editor/core/render/anim.ts
index 5e7c616..2123d88 100644
--- a/src/lib/modules/editor/core/render/anim.ts
+++ b/src/lib/modules/editor/core/render/anim.ts
@@ -139,3 +139,29 @@ export function animPath(a: Anim, steps = 48): AnimPlace[] {
}
return out;
}
+
+/** The middle of a motion's bounding box, rounded to whole pixels; the origin when it has none. */
+function centreOf(a: Anim): AnimPlace {
+ // sampled low angle to high, so a motion and its reverse have the same middle
+ const lo = Math.min(wrap(a.start), wrap(a.end));
+ const hi = Math.max(wrap(a.start), wrap(a.end));
+ const pts = animPath({ ...a, start: lo, end: hi }, 24);
+
+ if (!pts.length) return { dx: 0, dy: 0 };
+ const xs = pts.map((p) => p.dx);
+ const ys = pts.map((p) => p.dy);
+
+ return {
+ dx: Math.round((Math.min(...xs) + Math.max(...xs)) / 2),
+ dy: Math.round((Math.min(...ys) + Math.max(...ys)) / 2),
+ };
+}
+
+/** How far to move a layer so that swapping its motion `from` -> `to` keeps the motion centred
+ * where it was. Whole pixels, so going there and back lands exactly where it started. */
+export function keepCentre(from: Anim, to: Anim): AnimPlace {
+ const was = centreOf(from);
+ const now = centreOf(to);
+
+ return { dx: was.dx - now.dx, dy: was.dy - now.dy };
+}
diff --git a/src/lib/modules/editor/i18n-inspector.ts b/src/lib/modules/editor/i18n-inspector.ts
index 4c88ea5..8c2a81d 100644
--- a/src/lib/modules/editor/i18n-inspector.ts
+++ b/src/lib/modules/editor/i18n-inspector.ts
@@ -96,9 +96,13 @@ const en = {
animGroup: {
slide: "Slide",
arc: "Arc",
+ side: "Side",
+ repeat: "Repeat",
},
animNoFade:
"This widget only moves the image: fades and other effects are not available on the watch.",
+ animSideNote:
+ "Choosing an effect moves the layer so its motion stays where it was; a sideways glide starts far from the layer. Whether the watch adds the layer position the way the preview does is not verified.",
animPreset: {
rise: "Rise (stock sun)",
set: "Set (stock moon)",
@@ -110,6 +114,24 @@ const en = {
quarterUp: "Quarter arc up",
quarterDown: "Quarter arc down",
dropLong: "Long drop",
+ quickRise: "Quick rise",
+ quickSet: "Quick set",
+ nudgeUp: "Nudge up",
+ nudgeDown: "Nudge down",
+ arcBig: "Big arc",
+ arcBigBack: "Big arc back",
+ quarterTop: "Top quarter",
+ quarterTopBack: "Top quarter back",
+ glideLeft: "Glide left",
+ glideRight: "Glide right",
+ glideLeftFar: "Long glide left",
+ glideRightFar: "Long glide right",
+ straightLeft: "Straight, right to left",
+ straightRight: "Straight, left to right",
+ loopRise: "Repeat rise",
+ loopSet: "Repeat set",
+ loopArc: "Repeat arc",
+ pulse: "Pulse",
},
animUntested: "Not yet tried on a Watch Pro 2.",
animProven: "Played on a Watch Pro 2.",
@@ -375,9 +397,13 @@ export const t = dict(en, {
animGroup: {
slide: "Скольжение",
arc: "Дуга",
+ side: "В сторону",
+ repeat: "Повтор",
},
animNoFade:
"Этот виджет только перемещает изображение: затухание и другие эффекты на часах недоступны.",
+ animSideNote:
+ "Выбор эффекта сдвигает слой, чтобы движение осталось на прежнем месте; боковое скольжение начинается далеко от слоя. Прибавляет ли часы позицию слоя так же, как предпросмотр, не проверено.",
animPreset: {
rise: "Восход (солнце из Sun Circle)",
set: "Закат (луна из Sun Circle)",
@@ -389,6 +415,24 @@ export const t = dict(en, {
quarterUp: "Четверть дуги вверх",
quarterDown: "Четверть дуги вниз",
dropLong: "Длинный спуск",
+ quickRise: "Быстрый восход",
+ quickSet: "Быстрый закат",
+ nudgeUp: "Толчок вверх",
+ nudgeDown: "Толчок вниз",
+ arcBig: "Большая дуга",
+ arcBigBack: "Большая дуга назад",
+ quarterTop: "Верхняя четверть",
+ quarterTopBack: "Верхняя четверть назад",
+ glideLeft: "Скольжение влево",
+ glideRight: "Скольжение вправо",
+ glideLeftFar: "Длинное скольжение влево",
+ glideRightFar: "Длинное скольжение вправо",
+ straightLeft: "Прямо, справа налево",
+ straightRight: "Прямо, слева направо",
+ loopRise: "Восход по кругу",
+ loopSet: "Закат по кругу",
+ loopArc: "Дуга по кругу",
+ pulse: "Пульс",
},
animUntested: "Ещё не проверено на Watch Pro 2.",
animProven: "Проверено на Watch Pro 2.",
@@ -649,9 +693,13 @@ export const t = dict(en, {
animGroup: {
slide: "Ковзання",
arc: "Дуга",
+ side: "Убік",
+ repeat: "Повтор",
},
animNoFade:
"Цей віджет лише переміщує зображення: згасання й інші ефекти на годиннику недоступні.",
+ animSideNote:
+ "Вибір ефекту зсуває шар, щоб рух залишився на колишньому місці; бічне ковзання починається далеко від шару. Чи додає годинник позицію шару так само, як попередній перегляд, не перевірено.",
animPreset: {
rise: "Схід (сонце з Sun Circle)",
set: "Захід (місяць з Sun Circle)",
@@ -663,6 +711,24 @@ export const t = dict(en, {
quarterUp: "Чверть дуги вгору",
quarterDown: "Чверть дуги вниз",
dropLong: "Довгий спуск",
+ quickRise: "Швидкий схід",
+ quickSet: "Швидкий захід",
+ nudgeUp: "Поштовх вгору",
+ nudgeDown: "Поштовх вниз",
+ arcBig: "Велика дуга",
+ arcBigBack: "Велика дуга назад",
+ quarterTop: "Верхня чверть",
+ quarterTopBack: "Верхня чверть назад",
+ glideLeft: "Ковзання вліво",
+ glideRight: "Ковзання вправо",
+ glideLeftFar: "Довге ковзання вліво",
+ glideRightFar: "Довге ковзання вправо",
+ straightLeft: "Прямо, справа наліво",
+ straightRight: "Прямо, зліва направо",
+ loopRise: "Схід по колу",
+ loopSet: "Захід по колу",
+ loopArc: "Дуга по колу",
+ pulse: "Пульс",
},
animUntested: "Ще не перевірено на Watch Pro 2.",
animProven: "Перевірено на Watch Pro 2.",
@@ -923,9 +989,13 @@ export const t = dict(en, {
animGroup: {
slide: "Deslizamiento",
arc: "Arco",
+ side: "Lateral",
+ repeat: "Repetir",
},
animNoFade:
"Este widget solo mueve la imagen: los fundidos y otros efectos no están disponibles en el reloj.",
+ animSideNote:
+ "Elegir un efecto mueve la capa para que su movimiento siga donde estaba; un deslizamiento lateral empieza lejos de la capa. No está verificado que el reloj sume la posición de la capa como la vista previa.",
animPreset: {
rise: "Salida (sol de Sun Circle)",
set: "Puesta (luna de Sun Circle)",
@@ -937,6 +1007,24 @@ export const t = dict(en, {
quarterUp: "Cuarto de arco arriba",
quarterDown: "Cuarto de arco abajo",
dropLong: "Caída larga",
+ quickRise: "Salida rápida",
+ quickSet: "Puesta rápida",
+ nudgeUp: "Empujón arriba",
+ nudgeDown: "Empujón abajo",
+ arcBig: "Arco grande",
+ arcBigBack: "Arco grande inverso",
+ quarterTop: "Cuarto superior",
+ quarterTopBack: "Cuarto superior inverso",
+ glideLeft: "Deslizar a la izquierda",
+ glideRight: "Deslizar a la derecha",
+ glideLeftFar: "Deslizamiento largo a la izquierda",
+ glideRightFar: "Deslizamiento largo a la derecha",
+ straightLeft: "Recto, de derecha a izquierda",
+ straightRight: "Recto, de izquierda a derecha",
+ loopRise: "Salida repetida",
+ loopSet: "Puesta repetida",
+ loopArc: "Arco repetido",
+ pulse: "Pulso",
},
animUntested: "Aún no probado en un Watch Pro 2.",
animProven: "Probado en un Watch Pro 2.",
@@ -1195,8 +1283,12 @@ export const t = dict(en, {
animGroup: {
slide: "स्लाइड",
arc: "चाप",
+ side: "बग़ल",
+ repeat: "दोहराव",
},
animNoFade: "यह विजेट केवल छवि को हिलाता है: फ़ेड और अन्य प्रभाव घड़ी पर उपलब्ध नहीं हैं।",
+ animSideNote:
+ "प्रभाव चुनने पर परत खिसकती है ताकि गति वहीं रहे जहाँ थी; बग़ल का सरकना परत से दूर शुरू होता है। घड़ी परत की स्थिति को पूर्वावलोकन की तरह जोड़ती है या नहीं, यह जाँचा नहीं गया।",
animPreset: {
rise: "उदय (Sun Circle का सूरज)",
set: "अस्त (Sun Circle का चाँद)",
@@ -1208,6 +1300,24 @@ export const t = dict(en, {
quarterUp: "चौथाई चाप ऊपर",
quarterDown: "चौथाई चाप नीचे",
dropLong: "लंबी गिरावट",
+ quickRise: "तेज़ उदय",
+ quickSet: "तेज़ अस्त",
+ nudgeUp: "हल्का ऊपर",
+ nudgeDown: "हल्का नीचे",
+ arcBig: "बड़ा चाप",
+ arcBigBack: "बड़ा चाप उलटा",
+ quarterTop: "ऊपरी चौथाई",
+ quarterTopBack: "ऊपरी चौथाई उलटा",
+ glideLeft: "बाएँ सरकना",
+ glideRight: "दाएँ सरकना",
+ glideLeftFar: "लंबा बाएँ सरकना",
+ glideRightFar: "लंबा दाएँ सरकना",
+ straightLeft: "सीधा, दाएँ से बाएँ",
+ straightRight: "सीधा, बाएँ से दाएँ",
+ loopRise: "दोहराता उदय",
+ loopSet: "दोहराता अस्त",
+ loopArc: "दोहराता चाप",
+ pulse: "स्पंदन",
},
animUntested: "Watch Pro 2 पर अभी आज़माया नहीं गया।",
animProven: "Watch Pro 2 पर चलकर देखा गया।",
diff --git a/src/lib/modules/editor/model/edit.model.ts b/src/lib/modules/editor/model/edit.model.ts
index f0de155..1bdc0b3 100644
--- a/src/lib/modules/editor/model/edit.model.ts
+++ b/src/lib/modules/editor/model/edit.model.ts
@@ -25,6 +25,7 @@ import {
siblingsOf,
ungroup,
withAnim,
+ withAnimPreset,
withPanel,
wrapInGroup,
} from "../core/document/edits";
@@ -113,6 +114,8 @@ export const panelSet = createEvent<{ id: NodeId; panel: number }>();
export const sourceIdSet = createEvent<{ id: NodeId; source: number }>();
/** The Watch Pro 2 animated image's fields. Through `committed`, so a no-op keeps the undo step. */
export const animPatched = createEvent<{ id: NodeId; patch: Partial }>();
+/** An effect from the gallery: the fields and the layer shift that keeps its motion centred. */
+export const animPresetApplied = createEvent<{ id: NodeId; patch: Partial }>();
/** A layer that was just created and should become the selection. Shared with create.model. */
export const selectAdded = createEvent<{ added: NodeId }>();
@@ -296,6 +299,14 @@ sample({
target: committed,
});
+sample({
+ clock: animPresetApplied,
+ fn: ({ id, patch }) => ({
+ edit: (doc: Doc) => (findLayer(doc, id)?.locked ? doc : withAnimPreset(doc, id, patch)),
+ }),
+ target: committed,
+});
+
sample({
clock: layerFlagsSet,
filter: ({ ids }) => ids.length > 0,
diff --git a/tests/doc-anim.test.ts b/tests/doc-anim.test.ts
index 39d95cb..320b95f 100644
--- a/tests/doc-anim.test.ts
+++ b/tests/doc-anim.test.ts
@@ -16,7 +16,7 @@ import {
encodeAnim,
procOf,
} from "../src/lib/modules/editor/core/document/proc";
-import { withAnim } from "../src/lib/modules/editor/core/document/edits";
+import { withAnim, withAnimPreset } from "../src/lib/modules/editor/core/document/edits";
import {
animEndMs,
animPlace,
@@ -302,7 +302,7 @@ test("no animation edit can change the widget type, whatever the values", async
}
});
-import { animPath } from "../src/lib/modules/editor/core/render/anim";
+import { animPath, keepCentre } from "../src/lib/modules/editor/core/render/anim";
test("every preset is a valid, orbiting, type 2 body whose path the firmware math can draw", async () => {
const { doc } = fromLegacy(parseBin(readFileSync(FILE)));
@@ -312,7 +312,9 @@ test("every preset is a valid, orbiting, type 2 body whose path the firmware mat
const a = { ...STOCK_ANIM, ...p.patch };
expect(animIssues(a)).toEqual([]);
- expect(a.flags).toBe(0x88);
+ expect([0x88, 0x89]).toContain(a.flags);
+ // the repeat group, and only it, sets the loop bit
+ expect(animLoops(a)).toBe(p.group === "repeat");
expect(animPath(a).length).toBe(49);
// the install gate lets a face with that preset through, on every animated layer
let next = doc;
@@ -343,3 +345,78 @@ test("the stock slide and the arcs land where the firmware's formulas put them",
expect(at("quarterUp")[0]).toEqual({ dx: -200, dy: 0 });
expect(at("quarterUp").at(-1)).toEqual({ dx: 0, dy: -200 });
});
+
+test("side glides move sideways, and the layer shift round-trips exactly", () => {
+ const to = (id: string) => ({ ...STOCK_ANIM, ...ANIM_PRESETS.find((p) => p.id === id)!.patch });
+ const left = animPath(to("glideLeft"));
+ const right = animPath(to("glideRight"));
+ const far = animPath(to("glideLeftFar"));
+ const span = (pts: { dx: number; dy: number }[], k: "dx" | "dy") =>
+ Math.max(...pts.map((p) => p[k])) - Math.min(...pts.map((p) => p[k]));
+
+ // the angle growing from 180 moves the image left, the reverse moves it right
+ expect(left[0].dx).toBeGreaterThan(left.at(-1)!.dx);
+ expect(right[0].dx).toBeLessThan(right.at(-1)!.dx);
+ expect(span(left, "dx")).toBeGreaterThan(130);
+ // flat enough to read as sideways, and the long one flatter still
+ expect(span(left, "dy")).toBeLessThan(span(left, "dx") / 3);
+ expect(span(far, "dy") / span(far, "dx")).toBeLessThan(span(left, "dy") / span(left, "dx"));
+
+ // moving the layer by the shift puts the motion's middle back where it was, there and back
+ for (const a of ANIM_PRESETS)
+ for (const b of ANIM_PRESETS) {
+ const ab = keepCentre(to(a.id), to(b.id));
+ const ba = keepCentre(to(b.id), to(a.id));
+
+ expect(ab.dx + ba.dx).toBe(0);
+ expect(ab.dy + ba.dy).toBe(0);
+ }
+ // the two proven presets are the same motion reversed: no shift, so Sun Circle's layers stay put
+ expect(keepCentre(to("rise"), to("set"))).toEqual({ dx: 0, dy: 0 });
+});
+
+test("the straight slides are nearly flat, and flatter than the glides", () => {
+ const to = (id: string) => ({ ...STOCK_ANIM, ...ANIM_PRESETS.find((p) => p.id === id)!.patch });
+ const span = (pts: { dx: number; dy: number }[], k: "dx" | "dy") =>
+ Math.max(...pts.map((p) => p[k])) - Math.min(...pts.map((p) => p[k]));
+ const left = animPath(to("straightLeft"));
+ const right = animPath(to("straightRight"));
+
+ // right to left, then the reverse
+ expect(left[0].dx).toBeGreaterThan(left.at(-1)!.dx);
+ expect(right[0].dx).toBeLessThan(right.at(-1)!.dx);
+ expect(span(left, "dx")).toBeGreaterThan(250);
+ // a drop of a few pixels over the whole slide: as straight as a circle of radius 8000 gets
+ expect(span(left, "dy")).toBeLessThanOrEqual(6);
+ expect(span(left, "dy") / span(left, "dx")).toBeLessThan(
+ span(animPath(to("glideLeftFar")), "dy") / span(animPath(to("glideLeftFar")), "dx"),
+ );
+});
+
+test("withAnimPreset moves the layer to keep the motion centred, and back again", () => {
+ const { doc } = fromLegacy(parseBin(readFileSync(FILE)));
+ const sun = anims(doc).find((l) => bodyOf(l) === SUN)!;
+ const place = (d: Doc) => {
+ const l = anims(d).find((x) => x.id === sun.id) as unknown as { x: number; y: number };
+
+ return { x: l.x, y: l.y };
+ };
+ const glide = ANIM_PRESETS.find((p) => p.id === "glideLeft")!.patch;
+ const rise = ANIM_PRESETS.find((p) => p.id === "rise")!.patch;
+ const there = withAnimPreset(doc, sun.id, glide);
+
+ // a sideways glide rides about R px off the layer, so the layer moves to compensate
+ expect(place(there)).not.toEqual(place(doc));
+ expect(Math.abs(place(there).y - place(doc).y)).toBeGreaterThan(200);
+ // back to the stock motion: same bytes as the stock sun, and the layer is where it started
+ const back = withAnimPreset(there, sun.id, rise);
+
+ expect(place(back)).toEqual(place(doc));
+ expect(bodyOf(anims(back).find((l) => l.id === sun.id)!)).toBe(SUN);
+ // Rise and Set never move Sun Circle's layers
+ expect(
+ place(withAnimPreset(doc, sun.id, ANIM_PRESETS.find((p) => p.id === "set")!.patch)),
+ ).toEqual(place(doc));
+ // an effect that changes nothing hands back the same document (so it keeps its undo step)
+ expect(withAnimPreset(doc, sun.id, rise)).toBe(doc);
+});
From 6830e49a9c5f723800f757d95cb6da03b4c79940 Mon Sep 17 00:00:00 2001
From: hassan-software-dev
Date: Sun, 29 Nov 2026 18:43:58 +0500
Subject: [PATCH 2/2] Leave the Animation tab out of production builds for now
Choosing an effect moves the layer, and an object that is moved
afterwards does not play as the preview shows it, so the tab stays a
development-only tool until a watch agrees with the preview. One flag,
ANIMATION_TAB (import.meta.env.DEV), drops the tab from the right panel
and the phone's panel buttons, and rightPanelSet refuses it in a
production build. Faces with animated layers still open, edit and
install as before; compat.ts is untouched.
Co-Authored-By: Claude Sonnet 5.5
---
src/lib/modules/editor/model/ui.model.ts | 7 +++++
src/lib/modules/editor/pages/editor.svelte | 5 ++--
tests/anim-tab.test.ts | 33 ++++++++++++++++++++++
3 files changed, 43 insertions(+), 2 deletions(-)
create mode 100644 tests/anim-tab.test.ts
diff --git a/src/lib/modules/editor/model/ui.model.ts b/src/lib/modules/editor/model/ui.model.ts
index c9906e2..55289c2 100644
--- a/src/lib/modules/editor/model/ui.model.ts
+++ b/src/lib/modules/editor/model/ui.model.ts
@@ -3,6 +3,12 @@
import { createEvent, createStore, sample } from "effector";
// ---- stores ----
+/** The Animation tab is for development builds only, for now: the effects move the layer, and an
+ * object that is moved afterwards does not play as the preview shows it. Production builds
+ * leave the tab out, and `rightPanelSet` refuses it there too.
+ * ponytail: turn it on again (drop this flag) once a watch agrees with the preview. */
+export const ANIMATION_TAB: boolean = import.meta.env.DEV;
+
/** Right-side panel tab. Driven by the `select` event rather than derived from the selection:
* the selection store also changes when a simulator tweak re-selects the same layer, and
* deriving would flip the tab back to Properties on every input. */
@@ -20,6 +26,7 @@ export const lockAspectToggled = createEvent();
// ---- business logic ----
sample({
clock: rightPanelSet,
+ filter: (tab) => tab !== "anim" || ANIMATION_TAB,
target: $rightPanel,
});
sample({
diff --git a/src/lib/modules/editor/pages/editor.svelte b/src/lib/modules/editor/pages/editor.svelte
index 45d1714..51d6235 100644
--- a/src/lib/modules/editor/pages/editor.svelte
+++ b/src/lib/modules/editor/pages/editor.svelte
@@ -129,6 +129,7 @@
watchFrameToggled,
$rightPanel: rightPanel,
rightPanelSet,
+ ANIMATION_TAB,
$loading: loading,
} = editorModel;
@@ -541,7 +542,7 @@
]);
const panelItems = $derived([
{ value: "props", label: $t.properties },
- { value: "anim", label: $t.animTab, disabled: !$doc },
+ ...(ANIMATION_TAB ? [{ value: "anim", label: $t.animTab, disabled: !$doc }] : []),
{ value: "sim", label: $t.simulator, disabled: !$doc },
]);
const mobileTitle = $derived(
@@ -880,7 +881,7 @@
{#if $doc}
- {#each [["tree", "account_tree", $t.tree], ["props", "tune", $t.propsShort], ["anim", "wb_twilight", $t.animTab], ["sim", "play_arrow", $t.simShort]] as [id, icon, label] (id)}
+ {#each [["tree", "account_tree", $t.tree], ["props", "tune", $t.propsShort], ...(ANIMATION_TAB ? [["anim", "wb_twilight", $t.animTab]] : []), ["sim", "play_arrow", $t.simShort]] as [id, icon, label] (id)}
{
+ vi.unstubAllEnvs();
+ vi.resetModules();
+});
+
+const load = async (dev: boolean) => {
+ vi.stubEnv("DEV", dev);
+ vi.resetModules();
+ return import("../src/lib/modules/editor/model/ui.model");
+};
+
+test("a development build opens the Animation tab", async () => {
+ const ui = await load(true);
+
+ expect(ui.ANIMATION_TAB).toBe(true);
+ ui.rightPanelSet("anim");
+ expect(ui.$rightPanel.getState()).toBe("anim");
+});
+
+test("a production build refuses it, and the other tabs still open", async () => {
+ const ui = await load(false);
+
+ expect(ui.ANIMATION_TAB).toBe(false);
+ ui.rightPanelSet("anim");
+ expect(ui.$rightPanel.getState()).toBe("props");
+ ui.rightPanelSet("sim");
+ expect(ui.$rightPanel.getState()).toBe("sim");
+ ui.rightPanelSet("anim");
+ expect(ui.$rightPanel.getState()).toBe("sim");
+});