@bam.tech/lrud

中文文档
8.0.2发布于 2024/09/17Apache-2.0TypeScriptESM + CJS近 30 天下载 1.5万

Left, Right, Up, Down. A spatial navigation library for devices with input via directional controls

原始使用文档
文档目录9 节
  1. :nut_and_bolt: Maintenance Mode :nut_and_bolt:
  2. Upgrading from V2
  3. Getting Started
  4. Usage
  5. Running the tests
  6. Versioning
  7. Built with
  8. Inspiration
  9. Alternatives

LRUD Build Status

A spatial navigation library for devices with input via directional controls

:nut_and_bolt: Maintenance Mode :nut_and_bolt:

LRUD is now in maintenance mode; existing bugs will be fixed, but new features will not be added. A new library called LRUD Spatial is now available to the Open Source community.

Upgrading from V2

v3 is a major rewrite, covering many new features. However, it unfortunately breaks some backwards compatibility.

We are currently in the process of writing more detailed docs for an upgrade process. However, the main things to note at the minute at;

  • changes in events, which ones are emitted and what they are emitted with
  • removal of grid in favour of isIndexAligned behaviour

Getting Started

git clone [email protected]:bbc/lrud.git lrud
cd lrud
npm install

Lrud is written in Typescript and makes use of mitt.

Usage

npm install lrud
const { Lrud } = require('Lrud')

// create an instance, register some nodes and assign a default focus
var navigation = new Lrud()
navigation
  .registerNode('root', { orientation: 'vertical' })
  .registerNode('item-a', { parent: 'root', isFocusable: true })
  .registerNode('item-b', { parent: 'root', isFocusable: true })
  .assignFocus('item-a')

// handle a key event
document.addEventListener('keypress', (event) => {
  navigation.handleKeyEvent(event)
});

// Lrud will output an event when it handles a move
navigation.on('move', (moveEvent) => {
  myApp.doSomethingOnNodeFocus(moveEvent.enter)
})

See usage docs for details full API details.

For more "full" examples, covering common use cases, check the recipes

Running the tests

All code is written in Typescript, so we make use of a tsconfig.json and jest.config.js to ensure tests run correctly.

Test files are split up fairly arbitrarily, aiming to have larger sets of tests broken into their own file.

npm test

To run a specific test file, use npx jest from the project root.

npx jest src/lrud.test.js

You can also run all the tests with verbose output. This is useful for listing out test scenarios to ensure that behaviour is covered.

npm run test:verbose

You can also run all the tests with coverage output

npm run test:coverage

Several of the tests have associated diagrams, in order to better explain what is being tested. These can be found in ./docs/test-diagrams.

We also have a specific test file (src/build.test.js) in order to ensure that we haven't broken the Typescript/rollup.js build.

Versioning

npm version <patch:minor:major>
npm publish

Built with

Inspiration

Alternatives

License

LRUD is part of the BBC TAL libraries, and available to everyone under the terms of the Apache 2 open source licence (Apache-2.0). Take a look at the LICENSE file in the code.

Copyright (c) 2018 BBC

版本与发布记录

@bam.tech/lrud 共发布 3 个版本,首次发布于 2023/07/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
8.0.2latest2024/09/172 年前
8.0.12023/10/253 年前
8.0.02023/07/173 年前

关于 @bam.tech/lrud 的常见问题

@bam.tech/lrud 是什么?

Left, Right, Up, Down. A spatial navigation library for devices with input via directional controls

如何安装 @bam.tech/lrud?

在项目目录运行 npm install @bam.tech/lrud,或使用 pnpm add / yarn add / bun add。

@bam.tech/lrud 支持 TypeScript 吗?

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

@bam.tech/lrud 支持 ESM 还是 CommonJS?

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

@bam.tech/lrud 可以商用吗?

@bam.tech/lrud 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@bam.tech/lrud 的下载量有多少?

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

@bam.tech/lrud 还在维护吗?

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