87e8f33b01
Normaliza lang: typescript → ts en funciones frontend y corrige file_path de functions/infra/ → functions/browser/ en funciones CDP. Actualiza referencias cn_typescript_core → cn_ts_core. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1.6 KiB
1.6 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path, props, emits, has_state, framework, variant
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | tested | tests | test_file_path | file_path | props | emits | has_state | framework | variant | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| use_animated_canvas | component | ts | ui | 1.0.0 | impure | useAnimatedCanvas(options: AnimatedCanvasOptions): AnimatedCanvasResult | Hook React para canvas animado a N fps via requestAnimationFrame. Maneja DPR, resize, throttling, y contador de FPS real. |
|
false |
|
false | frontend/functions/ui/use_animated_canvas.tsx |
|
true | react |
|
Ejemplo
const { canvasRef, renderFpsRef } = useAnimatedCanvas({
fps: 100,
draw: (ctx, w, h) => {
// Dibujar lo que sea a 100fps
ctx.fillStyle = '#3b82f6'
ctx.fillRect(0, 0, w * Math.random(), h)
},
})
return <canvas ref={canvasRef} style={{ width: '100%', height: 300 }} />
Notas
- DPR automático: escala el canvas al devicePixelRatio de la pantalla
- Resize automático: detecta cambios de tamaño via getBoundingClientRect
- Throttle configurable: rAF corre a ~144fps nativo, el hook filtra a N fps
- FPS real:
renderFpsRef.currenttiene los FPS medidos (no el target) - drawRef pattern: actualiza el callback sin re-crear el loop de animación