feat: add a motion system with accessible fallbacks

The UI had almost no motion: two transition declarations in total, no
@keyframes, no animation and no prefers-reduced-motion support. Interactive
states snapped instantly and the landing page was completely static.

Add a self-contained motion layer instead of scattering rules through the
existing stylesheets:

- frontend/src/motion.css holds the tokens, interaction feedback, keyframes
  and the reduced-motion opt-out. It only appends rules; no existing layout
  rule is rewritten, so dropping the import restores the static UI.
- frontend/src/motion.ts implements scroll reveal with IntersectionObserver
  and a MutationObserver for asynchronously rendered content.

Design constraints:

- Animate transform and opacity only, so motion stays on the compositor and
  never forces layout of siblings.
- Never animate the transform of the tilted hero artwork, which would
  override its 3D perspective; it fades in instead.
- Decorative loops are slow and low amplitude, and only where they convey
  "alive" (status dots, hero glow, floating prompt).
- Anchor navigation now uses smooth scrolling with scroll-padding so
  section headings clear the sticky header.

Accessibility and progressive enhancement:

- The hidden state is gated on html.motion-ready, which JS adds only after
  an IntersectionObserver exists. Without JS, in a browser without the
  observer, or with reduced motion requested, content is never hidden.
- prefers-reduced-motion: reduce disables every animation, transition and
  smooth scrolling, and forces revealed content visible.
- The reduced-motion preference is also watched at runtime, so toggling it
  mid-session reveals anything still hidden.

Verified: 27 pages render without console errors, reveal works on every
landing section, hover feedback is measurable, dark mode and mobile layouts
are unaffected, and both reduced-motion and missing-IntersectionObserver
fallbacks keep all content visible.
This commit is contained in:
Morris committed 2026-11-14 10:15:31 +08:00
1 parent 347e723583
commit fecb1d3976
5 files changed
+472 -14

No files matched your search

+3
View File
@@ -28,6 +28,8 @@ import AdminExtensions from "./views/AdminExtensions.vue";
import PluginTools from "./views/PluginTools.vue";
import "./style.css";
import "./landing.css";
import "./motion.css";
import { initMotion } from "./motion";
const router = createRouter({
history: createWebHistory(),
routes: [
@@ -106,3 +108,4 @@ router.beforeEach(async (to) => {
});
app.use(router);
app.mount("#app");
initMotion();
+347
View File
@@ -0,0 +1,347 @@
/* ==========================================================================
Motion system
--------------------------------------------------------------------------
All animation is additive: this file is loaded after style.css / landing.css
and only appends transitions and keyframes. No existing layout rule is
rewritten, so removing this import restores the original static UI.
Rules:
1. Animate only `transform` and `opacity` where possible: they stay on the
compositor and never trigger layout or paint of siblings.
2. No transform on scroll containers or ancestors of sticky/fixed elements
(it would create a containing block and break position:sticky).
3. Decorative motion is slow, low-amplitude and loops only where it conveys
"alive" (status dots, hero glow). No attention-grabbing bouncing.
4. `prefers-reduced-motion: reduce` disables everything, including smooth
scrolling. Scroll reveal is JS-gated so content is visible without JS.
========================================================================== */
:root {
--ease-out: cubic-bezier(0.22, 1, 0.36, 1);
--ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
--dur-fast: 140ms;
--dur: 220ms;
--dur-slow: 420ms;
}
html {
scroll-behavior: smooth;
/* Anchor links (#features, #workflow, ...) must clear the sticky header. */
scroll-padding-top: 96px;
}
/* --------------------------------------------------------------------------
1. Interaction feedback — buttons, links, controls
-------------------------------------------------------------------------- */
.primary,
.secondary {
transition:
background-color var(--dur) var(--ease-in-out),
border-color var(--dur) var(--ease-in-out),
box-shadow var(--dur) var(--ease-out),
transform var(--dur-fast) var(--ease-out);
}
.primary:hover {
transform: translateY(-2px);
box-shadow: 0 7px 16px #3868f526;
}
.secondary:hover {
transform: translateY(-2px);
}
.primary:active,
.secondary:active {
transform: translateY(0) scale(0.985);
transition-duration: var(--dur-fast);
}
.icon-button,
.link,
.text-link,
.landing-login,
.landing-nav-login,
.logout,
.pagination a,
.pagination button,
.breadcrumb button {
transition:
color var(--dur-fast) var(--ease-in-out),
background-color var(--dur-fast) var(--ease-in-out),
opacity var(--dur-fast) var(--ease-in-out);
}
.link:hover,
.text-link:hover,
.landing-login:hover {
opacity: 0.75;
}
/* Form controls: focus ring and border currently snap instantly. */
input,
textarea,
select {
transition:
border-color var(--dur) var(--ease-in-out),
box-shadow var(--dur) var(--ease-out),
background-color var(--dur) var(--ease-in-out);
}
/* --------------------------------------------------------------------------
2. Surfaces — cards, panels, rows
A 1px lift plus a softened shadow reads as "interactive" without motion
sickness. Shadow transitions do paint, but only on hover of one element.
-------------------------------------------------------------------------- */
.project-card,
.stat-card,
.capability,
.guide-step,
.usecase-visual article,
.landing-plan-grid article {
transition:
transform var(--dur) var(--ease-out),
box-shadow var(--dur) var(--ease-out),
border-color var(--dur) var(--ease-in-out);
}
.project-card:hover,
.stat-card:hover,
.capability:hover {
transform: translateY(-3px);
box-shadow: 0 10px 26px #1a396012;
}
.table-scroll tbody tr,
.task-item,
.version-row,
.project-row,
.file-entry,
.event-log > div {
transition: background-color var(--dur-fast) var(--ease-in-out);
}
/* Sidebar navigation: the active item is currently an instant colour swap. */
.member-shell aside nav a {
transition:
background-color var(--dur-fast) var(--ease-in-out),
color var(--dur-fast) var(--ease-in-out),
transform var(--dur-fast) var(--ease-out);
}
.member-shell aside nav a:hover {
transform: translateX(2px);
}
/* --------------------------------------------------------------------------
3. Overlays and feedback banners
-------------------------------------------------------------------------- */
.modal-backdrop {
animation: motion-fade-in var(--dur) var(--ease-out) both;
}
.modal {
animation: motion-rise var(--dur-slow) var(--ease-out) both;
}
.alert,
.notice {
animation: motion-fade-in var(--dur-slow) var(--ease-out) both;
}
/* FAQ chevron already has a transform transition; give it a softer curve. */
.faq-items svg {
transition: transform var(--dur) var(--ease-out);
}
/* Mobile dropdown added for the collapsed landing navigation. */
.landing-nav nav.expanded {
animation: motion-dropdown var(--dur) var(--ease-out) both;
}
/* Captcha refresh: brief feedback that the image actually changed. */
.captcha img {
animation: motion-fade-in var(--dur) var(--ease-out) both;
}
/* --------------------------------------------------------------------------
4. Ambient decoration — landing page
Amplitudes are deliberately tiny; these should be felt, not watched.
-------------------------------------------------------------------------- */
.product-glow {
animation: motion-breathe 7s var(--ease-in-out) infinite;
}
.status-dot,
.notice-dot {
animation: motion-pulse 2.8s var(--ease-in-out) infinite;
}
.floating-prompt {
animation: motion-float 6s var(--ease-in-out) infinite;
will-change: transform;
}
.hero-kicker > span,
.prompt-spark {
animation: motion-breathe 4.5s var(--ease-in-out) infinite;
}
/* Hero artwork is tilted with a perspective transform. Do NOT animate its
transform (it would override the 3D tilt); only fade it in on entry. */
.hero-product {
animation: motion-fade-in var(--dur-slow) var(--ease-out) both;
}
.hero-copy {
animation: motion-rise var(--dur-slow) var(--ease-out) both;
}
/* --------------------------------------------------------------------------
5. Scroll reveal (progressive enhancement)
The hidden state is gated on `html.motion-ready`, which JS sets only after
an IntersectionObserver has been created successfully. Without JS, with a
legacy browser, or with reduced motion, everything stays fully visible.
-------------------------------------------------------------------------- */
html.motion-ready [data-reveal] {
opacity: 0;
transform: translateY(18px);
transition:
opacity var(--dur-slow) var(--ease-out),
transform var(--dur-slow) var(--ease-out);
}
html.motion-ready [data-reveal].is-visible {
opacity: 1;
transform: none;
}
/* Stagger children of a revealed group without a second observer. */
html.motion-ready [data-reveal-group] > * {
opacity: 0;
transform: translateY(14px);
transition:
opacity var(--dur-slow) var(--ease-out),
transform var(--dur-slow) var(--ease-out);
transition-delay: calc(var(--stagger, 0) * 70ms);
}
html.motion-ready [data-reveal-group].is-visible > * {
opacity: 1;
transform: none;
}
/* --------------------------------------------------------------------------
6. Keyframes — opacity / transform only
-------------------------------------------------------------------------- */
@keyframes motion-fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes motion-rise {
from {
opacity: 0;
transform: translateY(14px);
}
to {
opacity: 1;
transform: none;
}
}
@keyframes motion-dropdown {
from {
opacity: 0;
transform: translateY(-8px);
}
to {
opacity: 1;
transform: none;
}
}
@keyframes motion-float {
0%,
100% {
transform: translateY(0);
}
50% {
transform: translateY(-6px);
}
}
@keyframes motion-breathe {
0%,
100% {
opacity: 0.55;
}
50% {
opacity: 1;
}
}
@keyframes motion-pulse {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.35;
}
}
@keyframes motion-spin {
to {
transform: rotate(360deg);
}
}
/* --------------------------------------------------------------------------
7. Accessibility — full opt-out
`animation-duration: 0.01ms` (rather than `animation: none`) keeps the end
state of `both`-filled animations, so no element is left invisible.
-------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
html {
scroll-behavior: auto;
}
*,
*::before,
*::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
transition-delay: 0ms !important;
scroll-behavior: auto !important;
}
html.motion-ready [data-reveal],
html.motion-ready [data-reveal-group] > *,
html.motion-ready [data-reveal].is-visible,
html.motion-ready [data-reveal-group].is-visible > * {
opacity: 1 !important;
transform: none !important;
}
.primary:hover,
.secondary:hover,
.project-card:hover,
.stat-card:hover,
.capability:hover,
.member-shell aside nav a:hover {
transform: none;
}
}
+108
View File
@@ -0,0 +1,108 @@
/**
* Progressive-enhancement scroll reveal.
*
* The hidden state in motion.css is gated on `html.motion-ready`, which this
* module adds only after an IntersectionObserver has been created. If JS is
* disabled, the browser is old, or the user prefers reduced motion, nothing
* is ever hidden.
*/
const REVEAL_SELECTOR = "[data-reveal], [data-reveal-group]";
const registered = new WeakSet<Element>();
let revealObserver: IntersectionObserver | null = null;
let mutationObserver: MutationObserver | null = null;
let pendingScan = 0;
function reducedMotion(): boolean {
return window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
}
function onReveal(entries: IntersectionObserverEntry[]) {
for (const entry of entries) {
if (!entry.isIntersecting) continue;
entry.target.classList.add("is-visible");
// Each element animates once; no need to keep observing it.
revealObserver?.unobserve(entry.target);
}
}
/**
* Register newly mounted reveal targets and assign stagger indices to the
* children of a group. Works for async content (e.g. plans loaded from the
* API) because the parent keeps its `is-visible` class while new children
* inherit the revealed state from the CSS descendant selector.
*/
function scan() {
const root = document.documentElement;
if (!root.classList.contains("motion-ready")) return;
const targets = Array.from(
document.querySelectorAll<HTMLElement>(REVEAL_SELECTOR),
);
for (const element of targets) {
if (element.hasAttribute("data-reveal-group")) {
const children = Array.from(element.children) as HTMLElement[];
children.forEach((child, index) => {
child.style.setProperty("--stagger", String(Math.min(index, 8)));
});
}
if (registered.has(element)) continue;
registered.add(element);
revealObserver?.observe(element);
}
}
function scheduleScan() {
if (pendingScan) return;
pendingScan = requestAnimationFrame(() => {
pendingScan = 0;
scan();
});
}
function disableMotion() {
document.documentElement.classList.remove("motion-ready");
revealObserver?.disconnect();
revealObserver = null;
// Show anything that was mid-transition when the preference changed.
const hidden = Array.from(document.querySelectorAll(REVEAL_SELECTOR));
for (const element of hidden) {
element.classList.add("is-visible");
}
}
export function initMotion() {
if (
reducedMotion() ||
typeof IntersectionObserver === "undefined" ||
document.documentElement.classList.contains("motion-ready")
) {
return;
}
revealObserver = new IntersectionObserver(onReveal, {
// Trigger slightly before the element enters the viewport so the
// transition has time to play while scrolling.
rootMargin: "0px 0px -8% 0px",
threshold: 0.05,
});
document.documentElement.classList.add("motion-ready");
mutationObserver = new MutationObserver(scheduleScan);
mutationObserver.observe(document.getElementById("app") ?? document.body, {
childList: true,
subtree: true,
});
const media = window.matchMedia?.("(prefers-reduced-motion: reduce)");
media?.addEventListener?.("change", (event) => {
if (event.matches) {
disableMotion();
mutationObserver?.disconnect();
mutationObserver = null;
}
});
scan();
}
+2 -2
View File
@@ -64,7 +64,7 @@ const modules = [
>
</div>
<div v-if="error" class="alert error">{{ error }}</div>
<section class="welcome-banner">
<section class="welcome-banner" data-reveal>
<div>
<span class="banner-tag"><i />你的创造空间,已就绪</span>
<h2>让想法,有一个开始。</h2>
@@ -89,7 +89,7 @@ const modules = [
<div class="art-float"><CloudIcon /></div>
</div>
</section>
<section class="stats">
<section class="stats" data-reveal-group>
<div class="stat-card">
<div><span>我的项目</span><FolderKanban :size="18" /></div>
<strong>{{ loading ? "—" : projects.length }}</strong
+12 -12
View File
@@ -231,7 +231,7 @@ onMounted(async () => {
</div>
</div>
</section>
<section class="landing-values">
<section class="landing-values" data-reveal-group>
<span>创造的每一步,都在一个地方。</span>
<div><Code2 :size="18" />AI 辅助开发</div>
<div><GitBranch :size="18" />文件与版本</div>
@@ -239,14 +239,14 @@ onMounted(async () => {
<div><Wallet :size="18" />透明计费</div>
</section>
<section id="features" class="landing-section">
<div class="landing-section-heading">
<div class="landing-section-heading" data-reveal>
<span class="eyebrow">ONE WORKSPACE. MORE POSSIBILITIES.</span>
<h2>不止生成代码。<br />让开发过程,连成一条路。</h2>
<p>
把模型、项目、执行过程与运行配置连接起来,<br />让你把注意力留给真正想创造的东西。
</p>
</div>
<div class="landing-feature-grid">
<div class="landing-feature-grid" data-reveal-group>
<article v-for="f in features" :key="f.title">
<div class="landing-feature-icon">
<component :is="f.icon" :size="24" />
@@ -258,7 +258,7 @@ onMounted(async () => {
</div>
</section>
<section id="workflow" class="landing-section workflow-section">
<div class="workflow-intro">
<div class="workflow-intro" data-reveal>
<span class="eyebrow">FROM IDEA TO WORKSPACE</span>
<h2>从一句“我想要”,<br />到你的下一个作品。</h2>
<p>
@@ -268,7 +268,7 @@ onMounted(async () => {
>创建第一个项目 <ArrowRight :size="15"
/></RouterLink>
</div>
<div class="workflow-steps">
<div class="workflow-steps" data-reveal-group>
<article
v-for="(step, i) in [
[
@@ -299,11 +299,11 @@ onMounted(async () => {
</div>
</section>
<section class="landing-section usecases">
<div class="landing-section-heading">
<div class="landing-section-heading" data-reveal>
<span class="eyebrow">MAKE ROOM FOR YOUR NEXT IDEA</span>
<h2>你的下一站,<br />可以有很多种样子。</h2>
</div>
<div class="usecase-grid">
<div class="usecase-grid" data-reveal-group>
<article>
<span>01 / PRESENT</span>
<h3>个人品牌与产品展示</h3>
@@ -342,14 +342,14 @@ onMounted(async () => {
</div>
</section>
<section id="plans" class="landing-section landing-pricing">
<div class="landing-section-heading">
<div class="landing-section-heading" data-reveal>
<span class="eyebrow">CLEAR RESOURCES. CLEAR CHOICES.</span>
<h2>选择适合项目的运行空间。</h2>
<p>
AI 开发与网站托管分别计费,<br />托管资源与价格由平台实际开放的套餐决定。
</p>
</div>
<div v-if="plans.length" class="landing-plan-grid">
<div v-if="plans.length" class="landing-plan-grid" data-reveal-group>
<article v-for="p in plans" :key="p.id">
<span class="plan-eyebrow">云托管</span>
<h3>{{ p.name }}</h3>
@@ -394,12 +394,12 @@ onMounted(async () => {
</div>
</section>
<section id="questions" class="landing-section landing-faq">
<div>
<div data-reveal>
<span class="eyebrow">A LITTLE MORE CLARITY</span>
<h2>开始之前,<br />你可能想了解。</h2>
<p>让每一次选择,都更加清楚。</p>
</div>
<div class="faq-items">
<div class="faq-items" data-reveal-group>
<article v-for="(q, i) in questions" :key="q[0]">
<button
@click="faq = faq === i ? -1 : i"
@@ -412,7 +412,7 @@ onMounted(async () => {
</article>
</div>
</section>
<section class="landing-cta">
<section class="landing-cta" data-reveal>
<div>
<span class="eyebrow">YOUR NEXT CHAPTER STARTS HERE</span>
<h2>让下一次灵感,有处生长。</h2>