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
129 changes: 129 additions & 0 deletions src/lib/modules/editor/components/AnimationPanel.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<script lang="ts">
// The Animation tab. An animation here is an effect on an image layer, as in a slide deck's
// animation pane: the list names the layers that carry one, the effect section edits the
// selected one, and the timeline plays or scrubs it on its own clock, apart from the simulator's.
import { PanelSection } from "$lib/shared/components/panel-section";
import { Slider } from "$lib/shared/components/slider";
import { Button } from "$lib/shared/components/button";
import { Icon } from "$lib/shared/components/icon";
import { animOf } from "../core/document/proc";
import { animEndMs } from "../core/render/anim";
import { editorModel } from "../model";
import { t, sourceName } from "../i18n-inspector";
import Animation from "./props/animation.svelte";

const {
$animLayers: layers,
$animCurrent: current,
$animValue: value,
$sim: sim,
select,
simPatched,
animPanelClosed,
} = editorModel;

const anim = $derived($current ? animOf($current) : null);
const end = $derived(anim ? animEndMs(anim) : 0);
const scrub = $derived($sim.scrub);

// the phone's sheet closes without a rightPanelSet: let go of the canvas on the way out
$effect(() => () => animPanelClosed());

const play = () => simPatched({ wakeAt: Date.now(), scrub: null });
const follow = () => simPatched({ scrub: null });
const at = (ms: number) => simPatched({ scrub: { ms, value: scrub?.value ?? null } });
const valueAt = (v: number) => simPatched({ scrub: { ms: scrub?.ms ?? end, value: v } });
</script>

<div class="panel type-small" data-dense>
<PanelSection title={$t.animLayers}>
{#if $layers.length}
<div class="list">
{#each $layers as l (l.id)}
<button
type="button"
class="item type-small"
class:on={l.id === $current?.id}
onclick={() => select(l.id)}
>
<Icon name="wb_twilight" size={18} />
<span
>{l.name || (l.kind === "image" ? sourceName($t, l.meta.source) : $t.animation)}</span
>
</button>
{/each}
</div>
{:else}
<p class="type-caption hint-xs">{$t.animNone}</p>
{/if}
</PanelSection>

{#if $current && anim}
<PanelSection title={$t.animTimeline}>
<div class="row">
<Button size="small" kind="secondary" onClick={play}>
<Icon name="play_arrow" size={18} />
{$t.animPlay}
</Button>
<Button size="small" kind="ghost" disabled={!scrub} onClick={follow}>
<Icon name="sync" size={18} />
{$t.animFollow}
</Button>
</div>
<span class="type-label muted-label">{$t.animAt}</span>
<Slider min={0} max={Math.max(end, 1)} step={10} value={scrub?.ms ?? end} onInput={at} />
{#if $value !== null}
<span class="type-label muted-label">{$t.animValue}</span>
<Slider min={0} max={100} step={1} value={$value} onInput={valueAt} />
{/if}
</PanelSection>
<PanelSection title={$t.animSettings}>
<fieldset class="fields" disabled={Boolean($current.locked)}>
{#if $current.locked}
<p class="type-caption hint-xs">{$t.locked}</p>
{/if}
<Animation layer={$current} />
</fieldset>
</PanelSection>
{/if}
</div>

<style>
.panel {
--control-height: 1.875rem;

display: flex;
flex-direction: column;
}
.fields {
display: contents;
border: none;
margin: 0;
padding: 0;
}
.row {
display: flex;
gap: 0.5rem;
}
.list {
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.item {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.375rem 0.5rem;
border: 0;
border-radius: var(--border-radius);
background: oklch(from var(--color-text) l c h / 7%);
color: var(--color-text);
text-align: start;
cursor: pointer;

&.on {
outline: 2px solid var(--color-text);
}
}
</style>
6 changes: 6 additions & 0 deletions src/lib/modules/editor/components/SimPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { Select } from "$lib/shared/components/select";
import { Switch } from "$lib/shared/components/switch";
import { Icon } from "$lib/shared/components/icon";
import { Button } from "$lib/shared/components/button";
import {
ACCENT_PALETTE,
ID_METRIC,
Expand Down Expand Up @@ -106,6 +107,11 @@
>{$t.slotPlaceholders}</button
>
</div>
<!-- replays the wake sweep of an animated image (0x82, type 2) -->
<Button size="small" kind="secondary" onClick={() => simPatched({ wakeAt: Date.now() })}>
<Icon name="wb_twilight" size={18} />
{$t.wakeScreen}
</Button>
{#if $ids.some(({ id }) => id === 0x99)}
<div>
<span class="type-label muted-label">{$t.theme}</span>
Expand Down
6 changes: 6 additions & 0 deletions src/lib/modules/editor/components/TreePanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
widgetAdded,
numberAdded,
imageAdded,
animatedAdded,
deleteRequested,
duplicateRequested,
copyRequested,
Expand Down Expand Up @@ -295,6 +296,11 @@
<Icon name="image" size={22} />
{$t.emptyImage}
</MenuItem>
<!-- a Watch Pro 2 animated image, from Sun Circle's proven bytes; art comes later -->
<MenuItem onClick={() => animatedAdded()}>
<Icon name="wb_twilight" size={22} />
{$t.animatedLayer}
</MenuItem>
<!-- ten blank frames: the art comes from the inspector, either "regenerate from a font"
or a PNG dropped on a single frame — no ten-file picker any more -->
<MenuItem onClick={() => numberAdded()}>
Expand Down
Loading
Loading