Skip to content

pantoken-root / packages/utils/src / resolveTokens

函数: resolveTokens() ​

resolveTokens(base, options?): Map<string, string>

Beta

针对集合解析每个 token 的值(参见 makeResolver),以名称为键。

参数 ​

base ​

只读 Token[]

options? ​

ResolveOptions = {}

返回值 ​

Map<string, string>

示例 ​

将整个 IR 解析为名称 → 值 的映射

ts
import { resolveTokens } from "@pantoken/utils";
import type { Token } from "@pantoken/model";

const ir: Token[] = [
  { name: "--instui-leaf", syntax: "<color>", inherits: true, value: "#0374B5" },
  { name: "--instui-brand", syntax: "*", inherits: true, value: "var(--instui-leaf)" },
  { name: "--instui-bg", syntax: "*", inherits: true, value: "light-dark(#fff, #000)" },
];

const byName = resolveTokens(ir, { mode: "dark" });
byName.get("--instui-brand"); // → "#0374B5"
byName.get("--instui-bg");    // → "#000"