@betorigami/game-ui-shared

中文文档
5.0.0发布于 2026/11/05UNLICENSEDTypeScriptES Module近 30 天下载 4892

The Lit components, controllers, translations and wire types shared by every Origami game UI

原始使用文档
文档目录3 节
  1. Consuming
  2. Provider API client
  3. Pinning

@betorigami/game-ui-shared

The Lit components, controllers, translations, wire types and game-module registry shared by every Origami game UI. It was moved out of @betorigami/games, which now holds the host element, the game folders and the registration of their modules.

Consuming

lit, @lit/context and big.js are peer dependencies so that one copy of each is bundled by the host. Importing the package registers every shared custom element.

import { GameComponent, RequiredContext, localeContext, getTranslation } from '@betorigami/game-ui-shared';

Elements read the game context through RequiredContext, one per slice they need (localeContext, sessionContext, limitsContext, servicesContext, skinContext, preferencesContext, layoutContext, walletContext), all provided by <origami-game-provider-wrapper>. Reading a slice outside the wrapper throws. Desktop and mobile styles go in ${desktopContainerQuery} { … } and ${mobileContainerQuery} { … } blocks, after the base rules they override; both query the game-layout container the wrapper provides. Tests give an element its slices with provideTestContexts and change them with updateTestContexts.

A game contributes itself through a GameUiModule:

import { registerGameUiModule, type GameUiModule } from '@betorigami/game-ui-shared';

registerGameUiModule(myGameUiModule);

The shared components reach a game only through that registry: the provider wrapper renders renderGame(), the info modal reads gameInfo and maxMultiplier, the bet-result modal uses extractOutcome, renderOutcome, renderBetDetails and verifierInputs, and the verifier link uses verifierQuery.

A game adds its wire types by module augmentation rather than by editing this package:

declare module '@betorigami/game-ui-shared' {
  interface GameActionData {
    MY_GAME?: MyGameStartAction | EndAction;
  }
}

The package does not read environment variables. A host that wants a different provably-fair verifier calls setVerifierBaseUrl with that URL at startup; a host that does not leaves the built-in default in place.

Provider API client

ProviderApi is a client for provider-api, generated with hey-api from provider-api's OpenAPI spec. Every response is checked against the spec with zod/mini before the caller sees it.

import { ProviderApi } from '@betorigami/game-ui-shared';

const client = ProviderApi.createProviderApiClient({ baseUrl, authToken });
const { data, error } = await ProviderApi.postGamesDicePlay({ client, body });

createProviderApiClient adds the auth token, a fresh X-Origami-Trace id and a REQUEST_TIMEOUT_MS timeout to every request. data is set when the request succeeds and the response matches the spec. Otherwise error holds the error body, which resolveApiErrorCode turns into an ErrorCode. A response that doesn't match the spec throws. Inside this package, import from src/shared/provider-api/provider-api-client instead.

To regenerate it after provider-api's endpoints change:

  1. Start provider-api locally from the backend repo with ENABLE_OPENAPI_DOCS=true, the default in its .env.template. It serves the spec at http://localhost:3000/openapi.json.
  2. Run pnpm run generate:provider-api in this package.
  3. Commit the changes under src/shared/provider-api/generated/.

The settings, including the excluded /internal/* routes, are in openapi-ts.config.ts. Don't edit the generated files by hand.

Pinning

@betorigami/game-calculations supplies the enums of the games that have not yet been extracted. A host must pin the same version of it as this package, or two copies of the engine end up in one bundle and enum identity breaks.

版本与发布记录

@betorigami/game-ui-shared 共发布 58 个版本,首次发布于 2026/09/15;过去 12 个月发布了 58 个版本。

版本发布日期距今
5.0.0latest2026/11/053 天前
0.0.0-sha-d520cd7-202611030454102026/11/035 天前
4.1.12026/11/026 天前
0.0.0-sha-aedb5e8-202610300624332026/10/309 天前
4.1.02026/10/309 天前
0.0.0-sha-712536a-202610300429522026/10/309 天前

其他发布通道:sha-42df7b4 → 0.0.0-sha-42df7b4-20260915040255,sha-94964ff → 0.0.0-sha-94964ff-20260921002349,sha-cf9d324 → 0.0.0-sha-cf9d324-20260923040951,sha-a756e1c → 0.0.0-sha-a756e1c-20260924233718,sha-24ae92d → 0.0.0-sha-24ae92d-20260928035928,sha-94c9a88 → 0.0.0-sha-94c9a88-20260928040717。

关于 @betorigami/game-ui-shared 的常见问题

@betorigami/game-ui-shared 是什么?

The Lit components, controllers, translations and wire types shared by every Origami game UI

如何安装 @betorigami/game-ui-shared?

在项目目录运行 npm install @betorigami/game-ui-shared,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:lit(^3.3.0)、big.js(^7.0.1)、@lit/context(^1.1.5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@betorigami/game-ui-shared 支持 TypeScript 吗?

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

@betorigami/game-ui-shared 支持 ESM 还是 CommonJS?

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

@betorigami/game-ui-shared 可以商用吗?

@betorigami/game-ui-shared 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@betorigami/game-ui-shared 的下载量有多少?

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

@betorigami/game-ui-shared 还在维护吗?

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