From fecb1d3976a650d5ce982fb65bc95733ff646da7 Mon Sep 17 00:00:00 2001 From: Morris Date: Sat, 14 Nov 2026 10:15:31 +0800 Subject: [PATCH] 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. --- frontend/src/main.ts | 3 + frontend/src/motion.css | 347 +++++++++++++++++++++++++++++++ frontend/src/motion.ts | 108 ++++++++++ frontend/src/views/Dashboard.vue | 4 +- frontend/src/views/Landing.vue | 24 +-- 5 files changed, 472 insertions(+), 14 deletions(-) create mode 100644 frontend/src/motion.css create mode 100644 frontend/src/motion.ts diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 20c11de..99e9890 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -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(); diff --git a/frontend/src/motion.css b/frontend/src/motion.css new file mode 100644 index 0000000..a84e668 --- /dev/null +++ b/frontend/src/motion.css @@ -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; + } +} diff --git a/frontend/src/motion.ts b/frontend/src/motion.ts new file mode 100644 index 0000000..4c5728b --- /dev/null +++ b/frontend/src/motion.ts @@ -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(); +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(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(); +} diff --git a/frontend/src/views/Dashboard.vue b/frontend/src/views/Dashboard.vue index 4cbc884..ebcd61f 100644 --- a/frontend/src/views/Dashboard.vue +++ b/frontend/src/views/Dashboard.vue @@ -64,7 +64,7 @@ const modules = [ >
{{ error }}
-
+

让想法,有一个开始。

@@ -89,7 +89,7 @@ const modules = [
-
+
我的项目
{{ loading ? "—" : projects.length }} {
-
+
创造的每一步,都在一个地方。
AI 辅助开发
文件与版本
@@ -239,14 +239,14 @@ onMounted(async () => {
透明计费
-
+
ONE WORKSPACE. MORE POSSIBILITIES.

不止生成代码。
让开发过程,连成一条路。

把模型、项目、执行过程与运行配置连接起来,
让你把注意力留给真正想创造的东西。

-
+
@@ -258,7 +258,7 @@ onMounted(async () => {
-
+
FROM IDEA TO WORKSPACE

从一句“我想要”,
到你的下一个作品。

@@ -268,7 +268,7 @@ onMounted(async () => { >创建第一个项目

-
+
-
+
MAKE ROOM FOR YOUR NEXT IDEA

你的下一站,
可以有很多种样子。

-
+
01 / PRESENT

个人品牌与产品展示

@@ -342,14 +342,14 @@ onMounted(async () => {
-
+
CLEAR RESOURCES. CLEAR CHOICES.

选择适合项目的运行空间。

AI 开发与网站托管分别计费,
托管资源与价格由平台实际开放的套餐决定。

-
+
云托管

{{ p.name }}

@@ -394,12 +394,12 @@ onMounted(async () => {
-
+
A LITTLE MORE CLARITY

开始之前,
你可能想了解。

让每一次选择,都更加清楚。

-
+
-
+
YOUR NEXT CHAPTER STARTS HERE

让下一次灵感,有处生长。