feat: initial commit for Paralax creative engineering system
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
# Creative Performance & Accessibility Engineering
|
||||
|
||||
> **Goal:** Deliver breathtaking cinematic visuals while sustaining a rock-solid 60fps/120fps render loop and uncompromising WCAG AA accessibility.
|
||||
|
||||
---
|
||||
|
||||
## ⏱️ 1. The 16.6ms Frame Budget & The Critical Rendering Path
|
||||
|
||||
To sustain 60 frames per second, the browser has exactly **16.6 milliseconds** to execute all JavaScript, style calculations, layout geometry, painting, and GPU compositing. On modern 120Hz ProMotion displays, this budget shrinks to **8.3ms**.
|
||||
|
||||
```
|
||||
[ JavaScript / Ticker ] ──> [ Style Recalculation ] ──> [ Layout (Reflow) ] ──> [ Paint ] ──> [ Composite ]
|
||||
(GSAP / RAF) (CSS rules matched) (Geometry / Box) (Raster) (GPU Layers)
|
||||
```
|
||||
|
||||
### The Three Classes of CSS Properties:
|
||||
|
||||
| Pipeline Stage | Properties Animated | Performance Impact | Verdict for Creative Animation |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| **Layout (Reflow)** | `width`, `height`, `top`, `left`, `margin`, `padding`, `font-size` | **Catastrophic.** Forces browser to recalculate the geometry of the entire DOM tree on every scroll tick. | **STRICTLY FORBIDDEN** during scroll/motion. |
|
||||
| **Paint** | `color`, `background-color`, `border-color`, `box-shadow` | **Heavy.** Forces CPU rasterization of pixels before uploading textures to the GPU. | Acceptable for single state changes, avoid during continuous 60fps scrub. |
|
||||
| **Composite Only** | `transform` (`x`, `y`, `scale`, `rotate`), `opacity` | **Near Zero Overhead.** Handled directly on the GPU compositor thread without touching layout or paint. | **GOLD STANDARD.** 100% of continuous scroll animations must use these. |
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ 2. Layout Thrashing (Forced Synchronous Layout)
|
||||
|
||||
The most common cause of stutter in creative websites is **reading geometric layout values** immediately followed by **writing styles** in an unbatched loop.
|
||||
|
||||
```tsx
|
||||
// ❌ WRONG: Forces the browser to flush layout calculations repeatedly in a loop
|
||||
elements.forEach((el) => {
|
||||
const height = el.getBoundingClientRect().height; // READ (forces reflow)
|
||||
el.style.transform = `translateY(${height * 0.5}px)`; // WRITE (invalidates layout)
|
||||
});
|
||||
|
||||
// ✅ CORRECT: Batch all reads first, then execute all writes
|
||||
const heights = elements.map((el) => el.getBoundingClientRect().height); // All READS
|
||||
requestAnimationFrame(() => {
|
||||
elements.forEach((el, i) => {
|
||||
el.style.transform = `translateY(${heights[i] * 0.5}px)`; // All WRITES
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ♿ 3. Accessible Motion (`prefers-reduced-motion`)
|
||||
|
||||
Over 30% of users experience vestibular sensitivity, nausea, or visual vertigo from intense parallax, scaling, or sudden camera spins. **Every creative experience must provide an accessible, reduced-motion mode.**
|
||||
|
||||
### React / GSAP Implementation:
|
||||
```tsx
|
||||
import { useGSAP } from '@gsap/react';
|
||||
import gsap from 'gsap';
|
||||
import { ScrollTrigger } from 'gsap/ScrollTrigger';
|
||||
|
||||
export function useAccessibleTimeline(setupAnimation: (tl: gsap.core.Timeline) => void, scope: React.RefObject<any>) {
|
||||
useGSAP(
|
||||
() => {
|
||||
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
|
||||
if (prefersReducedMotion) {
|
||||
// Fallback: Reveal all elements with gentle opacity, no rapid movement or pinned scroll hijacking
|
||||
gsap.to(scope.current?.querySelectorAll('[data-motion-element]'), {
|
||||
opacity: 1,
|
||||
duration: 0.3,
|
||||
stagger: 0.05,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Full cinematic choreography for users without reduced motion preferences
|
||||
const tl = gsap.timeline();
|
||||
setupAnimation(tl);
|
||||
},
|
||||
{ scope }
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
### CSS Guardrail:
|
||||
```css
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
animation-duration: 0.01ms !important;
|
||||
animation-iteration-count: 1 !important;
|
||||
transition-duration: 0.01ms !important;
|
||||
scroll-behavior: auto !important;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 👁️ 4. Keyboard Navigation & Focus in Cinematic Layouts
|
||||
|
||||
Creative websites frequently hide or style native scrollbars, use custom canvas cursors, or pin views. You must ensure:
|
||||
1. **Focusable Elements Remain Visible**: Never remove `:focus-visible` outlines without providing a customized high-contrast focus ring (`outline: 2px solid var(--accent-kinetic)`).
|
||||
2. **Skip Links**: Include an accessible skip link at the top of the DOM:
|
||||
```html
|
||||
<a href="#main-content" class="sr-only focus:not-sr-only focus:fixed focus:top-4 focus:left-4 z-50 bg-black text-white px-4 py-2 rounded">
|
||||
Skip to main narrative
|
||||
</a>
|
||||
```
|
||||
3. **Canvas Accessibility**: A 3D WebGL `<canvas>` or Three.js scene must have hidden semantic HTML mirrors (`aria-label`, descriptions, or invisible interactive buttons with matching tab indices) so screen readers and keyboard users can inspect and navigate the content.
|
||||
Reference in New Issue
Block a user