@flighthq/sdk

中文文档
0.6.0发布于 2026/11/11MITTypeScriptES Module构建来源已验证近 30 天下载 8740

Single entry point re-exporting all packages

原始使用文档
文档目录10 节
  1. Try It
  2. Getting Started
  3. Animation
  4. Interaction
  5. Sound
  6. Rendering Model
  7. Platform Scope
  8. Engineering Confidence
  9. Examples
  10. Repository

Flight

CI npm

Flight is a modular TypeScript SDK for building interactive applications — designed to be read and written by AI coding agents as well as people. Its more than 150 tree-shakable packages span 2D and 3D graphics, physics, animation, media, input, asset formats, application lifecycle, and desktop/mobile platform APIs.

The API is cellular: explicit passes over plain data, self-identifying names, clear ownership, and no work at import time. A function can be understood in isolation; an application can import one capability without inheriting an engine. Those same properties keep the codebase grepable for agents, portable to compiled targets, and small in production builds.

Build a scene once and choose a renderer — Canvas 2D, DOM, WebGL 2, or WebGPU — by registering only the implementations it uses. Compose the same small primitives into a game, visualization, media experience, desktop tool, or mobile application.

Try It

See Flight render its own live introduction, browse the examples gallery, compare ports from established frameworks, or run the gallery locally:

npm install
npm run examples

Getting Started

npm install @flighthq/sdk

Create a display-object scene, register the renderer kinds you use, update the render graph, then draw:

import { webCanvasRenderSurfaceCreator } from '@flighthq/host-web';
import {
  addNodeChild,
  beginCanvasRenderPass,
  createCanvasElement,
  createCanvasRenderState,
  createCanvasRenderSurface,
  createCanvasScreenRenderTarget,
  createCanvasTextureResolvers,
  createDisplayObject,
  createSprite,
  createTexture,
  canvasSpriteRenderer,
  endCanvasRenderPass,
  getCanvasRenderStateTextureResolvers,
  loadImageResourceFromUrl,
  prepareScene2DRender,
  registerCanvasImageTextureResolver,
  registerNodeRenderer,
  renderCanvasScene2D,
  scene2DCanvasPipeline,
  SpriteKind,
} from '@flighthq/sdk';

const pixelRatio = window.devicePixelRatio || 1;
const canvas = createCanvasElement(webCanvasRenderSurfaceCreator, 550, 400, pixelRatio);
document.body.appendChild(canvas);

// Where the frame lands is a render target; how it is drawn is the render state. They are separate
// values, joined for the duration of a pass.
const screen = createCanvasScreenRenderTarget(
  createCanvasRenderSurface(webCanvasRenderSurfaceCreator, canvas, {
    height: canvas.height / pixelRatio,
    pixelRatio,
    width: canvas.width / pixelRatio,
  }),
);
const state = createCanvasRenderState(
  scene2DCanvasPipeline,
  createCanvasTextureResolvers(webCanvasRenderSurfaceCreator),
  { sceneGraphSyncPolicy: 'requiresInvalidation' },
);
// The background is what the pass clears to — a per-pass colour in linear float RGBA, not a field the
// render state carries around.
const screenClear = { color: [0xee / 0xff, 0xdd / 0xff, 0xcc / 0xff, 1] } as const;

registerCanvasImageTextureResolver(getCanvasRenderStateTextureResolvers(state));
registerNodeRenderer(state, SpriteKind, canvasSpriteRenderer);

const root = createDisplayObject();
root.scaleX = pixelRatio;
root.scaleY = pixelRatio;

const sprite = createSprite();
const image = await loadImageResourceFromUrl('assets/wabbit_alpha.png');
sprite.data.texture = createTexture({ dimension: '2d', source: image });
addNodeChild(root, sprite);

function enterFrame(): void {
  if (prepareScene2DRender(state, root)) {
    const pass = beginCanvasRenderPass(state, screen, screenClear);
    renderCanvasScene2D(pass, root);
    endCanvasRenderPass(pass);
  }

  requestAnimationFrame(enterFrame);
}

enterFrame();

The same scene renders through DOM, WebGL2, or WebGPU by creating the matching render state and registering that backend's renderers — no change to the scene graph itself. The display objects stay plain data; backend work remains explicit.

Animation

The application package provides a request-animation-frame loop with typed update and render signals. Host implementations are explicit; in a browser, pass the web host when starting the application:

npm install @flighthq/host-web
import { webHost } from '@flighthq/host-web';
import {
  connectSignal,
  createAppLoop,
  createTween,
  createTweenManager,
  easeOutElastic,
  invalidateNodeRender,
  startAppLoop,
  updateTweens,
} from '@flighthq/sdk';

const manager = createTweenManager();

const tween = createTween(manager, sprite, 1000, { x: 400, alpha: 0 }, { ease: easeOutElastic });
connectSignal(tween.onUpdate, () => invalidateNodeRender(sprite));

const app = createAppLoop();
connectSignal(app.onUpdate, (delta) => updateTweens(manager, delta));
connectSignal(app.onRender, () => {
  if (prepareScene2DRender(state, root)) {
    const pass = beginCanvasRenderPass(state, screen, screenClear);
    renderCanvasScene2D(pass, root);
    endCanvasRenderPass(pass);
  }
});

startAppLoop(webHost, app);

Interaction

Wire up pointer events on any scene node. Register a hit-test strategy once, then create an interaction manager and connect it to the input system:

import {
  attachPointerInput,
  connectInputToInteraction,
  connectInteractionSignal,
  createInputManager,
  createInteractionManager,
  invalidateNodeRender,
  registerDefaultHitTests,
  setNodeHitTestEnabled,
} from '@flighthq/sdk';

registerDefaultHitTests();
setNodeHitTestEnabled(sprite, true);

const interaction = createInteractionManager(root);
const input = createInputManager();
attachPointerInput(input, canvas);
connectInputToInteraction(input, interaction, pixelRatio);

connectInteractionSignal(interaction, sprite, 'onPointerDown', () => {
  sprite.alpha = 0.5;
  invalidateNodeRender(sprite);
});
connectInteractionSignal(interaction, sprite, 'onPointerUp', () => {
  sprite.alpha = 1;
  invalidateNodeRender(sprite);
});

Sound

Load an audio resource with fallback formats, then play it:

import { loadAudioResourceFromUrls, playAudioResource } from '@flighthq/sdk';

const audioContext = new AudioContext();
const sound = await loadAudioResourceFromUrls(audioContext, [{ url: 'assets/click.ogg' }, { url: 'assets/click.mp3' }]);

connectInteractionSignal(interaction, sprite, 'onPointerDown', () => {
  playAudioResource(audioContext, sound);
});

Rendering Model

Flight separates authored data from backend work:

  1. Build a graph from display objects, sprites, text, shapes, tilemaps, particles, or 3D scene nodes.
  2. Create a backend render state for Canvas 2D, DOM, WebGL2, or WebGPU.
  3. Register only the renderers and effect backends the scene needs.
  4. Run the explicit prepare/update pass.
  5. Draw through the selected backend.

Canvas and DOM are lightweight host-web paths. WebGL2 and WebGPU add GPU render targets, cached pipelines, shader/material registries, post-processing, clipping, masking, velocity, render caches, 2D batching, and 3D forward renderers with a 20-material Cook-Torrance PBR + classic/NPR/debug shader library.

Platform Scope

Flight currently spans more than 150 independently importable, publishable packages. The public API can be inspected with:

npm run api
npm run api -- --json

Major areas:

AreaPackages
Core and datatypes, entity, node, signals, math, geometry, color, layout, compression
2D graphicsscene2d, bitmap, shape, path, clip, text, tilemap, quadbatch
3D graphicsscene3d, mesh, materials, shading, lighting, texture, camera, skeleton3d, picking
Renderingrender, Canvas/DOM scene renderers, WebGL 2 and WebGPU cores, and 2D/3D GPU renderers
Effects and imagingadjustments, effects, Canvas/WebGL/WebGPU effect executors, image, image-codec, capture
Texttextlayout, textshaper, textsegment, textbidi, textinput, glyphatlas, bitmapfont, bitmaptext, text-markup
Animation and simulationeasing, tween, spring, animation, timeline, movieclip, spritesheet, motionpath, clock, particles
Games and interactioninput, interaction, collision, physics2d, spatial, flow, statechart, snapshot
Resources and formatsLoaders and structured importers for images, fonts, atlases, tilemaps, particles, SVG, SWF, glTF, OBJ/MTL, 3DS, MD2/MD5, AWD2, and more
Application and mediaapp, audio, video, media, mediasession, intl, log, debug
Platform integrationWeb-first APIs for storage, networking, filesystem, clipboard, dialogs, notifications, sensors, windows, lifecycle, and other OS/device capabilities
Native hostsExplicit Host values for Electron, Tauri, and Capacitor
ToolingCapture and baseline tooling, cross-renderer smoke/parity checks, conformance fixtures, API/export/package/order/portability gates, and bundle-size budgets

All packages are published under @flighthq/. Applications and examples usually import from @flighthq/sdk:

import { addNodeChild, createBitmap, createShape } from '@flighthq/sdk';

Library code should prefer the smallest package root that provides the needed API:

import { createTween, updateTweens } from '@flighthq/tween';

Platform Host values are explicit. Browser applications pass the ready-made webHost or the narrow webHost* values they need; Tauri and Capacitor applications construct tauriHost or capacitorHost from their injected native APIs. The application-facing API remains stable across those hosts.

Engineering Confidence

Flight is pre-release software, so confidence comes from the engineering path behind each change. Code changes are exercised by two unit-test lanes, a full TypeScript build, package and public-API validation, bundle-size budgets, and browser-render smoke and parity checks across DOM, Canvas, WebGL, and WebGPU. Nightly runs add coverage thresholds and generated API-surface checks.

main is a machine-managed known-good pointer: it advances only to commits whose CI run succeeded. Version releases verify that exact tagged commit passed CI before publishing the complete package graph to npm with provenance.

The repository also keeps reliability concerns visible in the design: imports are side-effect-free, feature families use explicit registries, resource ownership and allocation are named, format importers report structured diagnostics, source stays inside a checked compiled-target-portable subset, and render output is tested across interchangeable backends.

Examples

The gallery includes focused examples for shapes, text, interaction, animation, tilemaps, particles, collision, application flow, audio/video, file-format loading, and 3D scenes covering materials, picking, and fire. Where a capability is shared, the gallery lets you switch the same scene among supported renderers.

Build a specific example:

npm run build --workspace=examples/packages/shapes

Run a renderer-specific example dev server:

npm run dev:canvas --workspace=examples/packages/shapes
npm run dev:dom --workspace=examples/packages/shapes
npm run dev:webgl --workspace=examples/packages/shapes
npm run dev:webgpu --workspace=examples/packages/scene3d

Repository

git clone https://github.com/flighthq/flight.git
cd flight
npm install
packages/      Workspace packages published as @flighthq/*
examples/      Standalone Vite example apps
conformance/   Import fixtures and structured conformance checks
tools/         Gallery, functional scenes, capture harness, and repo utilities
scripts/       Validation, API, coverage, ordering, size, and build scripts

Useful checks:

npm run check              # package, type, API, export, portability, docs, and style gates
npm run test               # unit tests across all packages
npm run size               # gzip output size against committed budgets
npm run test:smoke         # fail on browser/runtime/render errors
npm run test:parity        # compare output across render backends
npm run test:regression    # compare output against committed fingerprints

版本与发布记录

@flighthq/sdk 共发布 428 个版本,首次发布于 2026/07/10;过去 12 个月发布了 428 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.0latest2026/11/115 天前
0.7.0-next.5213.ead804bnext2026/11/105 天前
0.7.0-edge.5213.ead804bedge2026/11/105 天前
0.5.1-edge.5211.71b571d2026/11/105 天前
0.5.1-next.5076.44cab462026/11/087 天前
0.5.1-edge.5076.44cab462026/11/087 天前

关于 @flighthq/sdk 的常见问题

@flighthq/sdk 是什么?

Single entry point re-exporting all packages

如何安装 @flighthq/sdk?

在项目目录运行 npm install @flighthq/sdk,或使用 pnpm add / yarn add / bun add。

@flighthq/sdk 支持 TypeScript 吗?

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

@flighthq/sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@flighthq/sdk 可以商用吗?

@flighthq/sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flighthq/sdk 的下载量有多少?

根据 npm 官方下载统计,@flighthq/sdk 在 2026/10/15 – 2026/11/13 这 30 天内被下载 8,740 次,日均约 291 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flighthq/sdk 还在维护吗?

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