@hyperframes/shader-transitions

中文文档
0.8.226发布于 2026/11/01TypeScriptESM + CJS构建来源已验证

WebGL shader transitions for HyperFrames compositions

原始使用文档
文档目录11 节
  1. Install
  2. Usage
  3. With an existing timeline
  4. Available shaders
  5. API
  6. init(config): GsapTimeline
  7. TransitionConfig
  8. SHADER_NAMES
  9. Distribution
  10. Related packages
  11. License

@hyperframes/shader-transitions

WebGL shader transitions for HyperFrames compositions. Renders GPU-accelerated scene-to-scene transitions using fragment shaders, driven by GSAP timelines.

Install

npm install @hyperframes/shader-transitions

Or load directly via CDN:

<script src="https://cdn.jsdelivr.net/npm/@hyperframes/shader-transitions/dist/index.global.js"></script>

Usage

import { init } from "@hyperframes/shader-transitions";

const tl = init({
  bgColor: "#0a0a0a",
  accentColor: "#ff6b2b",
  scenes: ["scene-1", "scene-2", "scene-3"],
  transitions: [
    { time: 3, shader: "domain-warp", duration: 0.8 },
    { time: 8, shader: "light-leak", duration: 0.7 },
  ],
});

The init() function pre-captures animated scene samples for every transition, composites cached samples with the selected shader during playback, and returns a GSAP timeline. Scene animations keep advancing through shader transitions without running DOM captures in the playback loop. If WebGL is unavailable, it falls back to normal timeline playback without shader compositing.

When the browser exposes Chrome's experimental CanvasDrawElement API, scene capture uses native HTML-in-canvas via drawElementImage(). Other browsers keep using the existing html2canvas fallback. You can feature-detect the native path with isHtmlInCanvasCaptureSupported().

With an existing timeline

Pass your own GSAP timeline to layer transitions onto it:

const tl = gsap.timeline({ paused: true });
// ... add your scene animations ...

init({
  bgColor: "#000",
  scenes: ["intro", "demo", "outro"],
  transitions: [
    { time: 5, shader: "cinematic-zoom" },
    { time: 12, shader: "glitch", duration: 0.5 },
  ],
  timeline: tl,
});

Available shaders

ShaderDescription
domain-warpOrganic noise-based warp with glowing edge
ridged-burnRidged noise burn with sparks and heat glow
whip-panHorizontal motion blur simulating a fast camera pan
sdf-irisCircular iris wipe with glowing ring edge
ripple-wavesConcentric ripple distortion radiating from center
gravitational-lensWarping gravity well with chromatic aberration
cinematic-zoomRadial zoom blur with chromatic fringing
chromatic-splitRGB channel separation expanding from center
glitchDigital glitch with block displacement and scanlines
swirl-vortexSpiral rotation with noise-based warping
thermal-distortionHeat shimmer rising from the bottom
flash-through-whiteFlash to white then reveal the next scene
cross-warp-morphNoise-driven morph blending both scenes
light-leakWarm cinematic light leak with lens flare

API

init(config): GsapTimeline

OptionTypeRequiredDescription
bgColorstringyesFallback background color (hex) for scene capture. Use the composition's body/canvas background — individual scenes set their own background-color via CSS.
accentColorstringnoAccent color (hex) for shader glow effects
scenesstring[]yesElement IDs of each scene, in order
transitionsTransitionConfig[]yesTransition definitions (see below)
timelineGsapTimelinenoExisting timeline to attach transitions to
compositionIdstringnoOverride the data-composition-id for timeline registration
previewCaptureFpsnumbernoBrowser preview pre-capture samples per transition second. Defaults to 30; rendering uses deterministic per-frame compositing instead.

Browser preview capture scale and transition-prep loading UI ownership are controlled by <hyperframes-player> (shader-capture-scale, shader-loading) instead of composition code. Direct non-player previews keep the built-in full-fidelity loading fallback.

Browser previews store captured transition snapshots in IndexedDB using a key derived from composition ID, scene DOM/style signatures, transition timing, capture FPS, scale, and dimensions. On refresh, matching snapshots are reloaded into WebGL textures instead of being captured again. Runtime scene or stylesheet edits mark only adjacent transition caches dirty; recapture is deferred until playback so editing stays responsive.

TransitionConfig

OptionTypeDefaultDescription
timenumber—Start time in seconds
shaderShaderName—Shader name from the table above
durationnumber0.7Transition duration in seconds
easestring"power2.inOut"GSAP easing function

SHADER_NAMES

Array of all available shader name strings, useful for validation or building UIs.

import { SHADER_NAMES } from "@hyperframes/shader-transitions";
// ["domain-warp", "ridged-burn", "whip-pan", ...]

Distribution

FormatFileUse case
ESMdist/index.jsBundlers (Vite, webpack, etc.)
CJSdist/index.cjsNode.js / require()
IIFEdist/index.global.js<script> tag, CDN (global: HyperShader)

All formats include source maps. TypeScript definitions included.

License

MIT

版本与发布记录

@hyperframes/shader-transitions 共发布 552 个版本,首次发布于 2026/04/14;过去 12 个月发布了 552 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.8.226latest2026/11/012 天前
0.8.2252026/11/012 天前
0.8.2242026/11/012 天前
0.8.2232026/10/313 天前
0.8.2222026/10/313 天前
0.8.2212026/10/304 天前

其他发布通道:alpha → 0.7.67-alpha.0,desktop → 0.8.53-desktop.0,hdr → 0.8.190-hdr.1。

关于 @hyperframes/shader-transitions 的常见问题

@hyperframes/shader-transitions 是什么?

超帧合成的WebGL着色器转换

如何安装 @hyperframes/shader-transitions?

在项目目录运行 npm install @hyperframes/shader-transitions,或使用 pnpm add / yarn add / bun add。

@hyperframes/shader-transitions 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@hyperframes/shader-transitions 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@hyperframes/shader-transitions 可以商用吗?

@hyperframes/shader-transitions 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@hyperframes/shader-transitions 还在维护吗?

最新版本 0.8.226 发布于 2026/11/01(2 天前);至今共发布 552 个版本,其中过去 12 个月发布了 552 个;首次发布于 2026/04/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。