@blotch/angular-lynx

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

Angular renderer for the Lynx cross-platform native UI framework

原始使用文档
文档目录8 节
  1. Quick Start
  2. Features
  3. Documentation
  4. Routing
  5. Animation API
  6. CSS Transitions
  7. CSS Keyframe Animations
  8. JavaScript Animate API

@blotch/angular-lynx

Angular renderer for Lynx. Write Angular components, render to native iOS, Android, and Web via the Lynx engine.

Quick Start

npm create angular-lynx my-app

Or add to an existing Angular project:

ng add @blotch/angular-lynx

Then work as in any Angular app: ng serve, ng build, ng test, and ng generate component, which makes components with Lynx elements. ng update @blotch/angular-lynx updates every AngularLynx package together.

Features

  • Standalone components with signals, @if/@for/@switch, DI, and pipes
  • Templates written for the browser: common HTML tags render as the Lynx element they stand for (<div> as <view>, <p> as <text>, <img> as <image>), and DOM events Lynx also sends, such as (click) and (input), run
  • Zoneless change detection — signals as the primary reactivity model
  • Full Angular Router with in-memory navigation for Lynx, including routerLink and routerLinkActive on any element
  • Gestures — tap, pan, long-press, fling, pinch, rotation with composition
  • document:, window: and body: listeners, which hear touches anywhere on screen (as pointer, touch and click events) and the window's resize, with window.innerWidth and innerHeight the screen's size
  • Animations — CSS transitions, keyframes, and programmatic animate() API
  • Content projection, portals, @defer, and lazy-loaded routes
  • IntersectionObserver on Lynx elements, from Lynx's exposure events, for code written for the browser
  • <canvas> with WebGL2 for 3D: three.js and angular-three, with pointer events, ResizeObserver and image loading, in apps built with ng build --platform ios|android and the web preview
  • Tailwind CSS 4, with the build rewriting its CSS for Lynx (or Tailwind CSS 3 with @lynx-js/tailwind-preset)

Documentation

Full docs and guides at angularlynx.js.org.


Routing

provideRouter() from @blotch/angular-lynx sets up Angular's Router with in-memory history. Everything else comes from @angular/router, as on the web, routerLink and routerLinkActive included:

import { Component } from '@angular/core';
import { RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS, RouterOutlet, RouterLink, RouterLinkActive],
  template: `
    <view routerLink="/settings" routerLinkActive="active">
      <text>Settings</text>
    </view>
    <router-outlet />
  `,
})
export class App {}
  • A tap on the element navigates: the renderer delivers Lynx's tap to click listeners, as Lynx for Web does, and RouterLink listens for click.
  • While the link's route is active, routerLinkActive adds its classes and LYNX_ELEMENTS adds selected to the element's accessibility-traits, keeping its own (LynxRouterLinkActive). On a component's host, list LynxRouterLinkActive in hostDirectives next to RouterLinkActive.
  • Event handlers can navigate directly, with Router.navigate() or Location.back().

Animation API

Three animation approaches are available, all running natively on the Lynx engine.

CSS Transitions

Apply transition in your stylesheet. Lynx interpolates property changes automatically.

.box {
  background-color: #6200ee;
  transition: background-color 0.5s ease-in-out;
}

.box-active {
  background-color: #03dac6;
}
<view class="box" [class.box-active]="isActive()" (bindtap)="toggle()">
  <text>Tap me</text>
</view>

CSS Keyframe Animations

Define @keyframes in your stylesheet and apply via class toggle.

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.spinning {
  animation: rotate 2s linear infinite;
}
<view class="box" [class.spinning]="spin()">
  <text>Rotating</text>
</view>

JavaScript Animate API

Use element.animate() on a native element reference for programmatic control. Calls the Lynx __ElementAnimate PAPI under the hood.

import { Component, viewChild, type ElementRef } from '@angular/core';
import { type LynxAnimation } from '@blotch/angular-lynx';

@Component({
  selector: 'app-example',
  template: `
    <view #box class="box" (bindtap)="runAnimation()">
      <text>Tap to animate</text>
    </view>
  `,
})
export class ExampleComponent {
  boxRef = viewChild<ElementRef>('box');
  #animation: LynxAnimation | null = null;

  runAnimation(): void {
    const el = this.boxRef();
    if (!el) return;

    // Cancel previous animation before starting a new one.
    this.#animation?.cancel();

    this.#animation = el.nativeElement.animate(
      [
        { transform: 'scale(1)', opacity: 1 },
        { transform: 'scale(1.3)', opacity: 0.7 },
        { transform: 'scale(1)', opacity: 1 },
      ],
      {
        duration: 600,
        easing: 'ease-in-out',
      },
    );
  }
}

animate() API

element.nativeElement.animate(
  keyframes: Record<string, string | number>[],
  options?: number | LynxAnimationOptions,
): LynxAnimation

Parameters:

ParameterTypeDescription
keyframesRecord<string, string | number>[]Array of keyframe objects. Each object maps CSS property names to values.
optionsnumber | LynxAnimationOptionsDuration in ms (shorthand) or full options object.

LynxAnimationOptions:

OptionTypeDescription
durationnumber | stringAnimation duration in milliseconds.
delaynumber | stringDelay before animation starts.
iterations / iterationCountnumber | stringNumber of repetitions. Use Infinity for infinite.
easing / timingFunctionstringEasing function (linear, ease-in, ease-out, ease-in-out, cubic-bezier(...)).
fill / fillModestringHow styles persist after animation (none, forwards, backwards, both).
directionstringPlay direction (normal, reverse, alternate, alternate-reverse).
namestringOptional animation name (auto-generated if omitted).

Returns: LynxAnimation with control methods:

MethodDescription
play()Resume a paused animation.
pause()Pause the animation.
cancel()Cancel and clean up the animation.

Animation Events

Lynx fires standard animation events on elements. Listen in templates using bind-prefixed event names:

<view
  class="animated-box"
  (bindanimationend)="onAnimationEnd($event)"
  (bindtransitionend)="onTransitionEnd($event)"
>
  <text>Animated</text>
</view>

Available events: animationstart, animationend, animationcancel, animationiteration, transitionstart, transitionend, transitioncancel.

Important Notes

  • The animate() API is main-thread only. Calling it on the background thread throws an error.
  • Call animate() straight from an event handler; it doesn't need a setTimeout.

版本与发布记录

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

版本发布日期距今
22.2.18latest2026/11/08今天
22.2.172026/11/08今天
22.2.162026/11/07今天
22.2.152026/11/071 天前
22.2.142026/11/071 天前
22.2.132026/11/062 天前

关于 @blotch/angular-lynx 的常见问题

@blotch/angular-lynx 是什么?

Angular renderer for the Lynx cross-platform native UI framework

如何安装 @blotch/angular-lynx?

在项目目录运行 npm install @blotch/angular-lynx,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/core(^22.2.0)、@angular/common(^22.2.0)、@angular/router(^22.2.0)、@angular/platform-browser(^22.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@blotch/angular-lynx 支持 TypeScript 吗?

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

@blotch/angular-lynx 支持 ESM 还是 CommonJS?

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

@blotch/angular-lynx 可以商用吗?

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

@blotch/angular-lynx 的下载量有多少?

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

@blotch/angular-lynx 还在维护吗?

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