Skip to content

pantoken / packages/plugin-kit/src / makeResolver

Mahi: makeResolver()

makeResolver(base, options?): (value) => string

Beta

Hangaia he kaiwhakatau e whānui ana i ngā tohutoro var(--x) ki ngā uara rau tūturu e whāngai ana ki base (me ngā overrides katoa). Mēnā he mode ka whakakupuketia e ia light-dark() ki taua peka; ki te kore, ka waiho tonu light-dark() i tōna tūranga.

Ngā Tawhā

base

pānui-anake Token[]

Ko te huinga tohu hei whakatau i ngā tohutoro.

options?

ResolveOptions

ResolveOptions.

Whakahokia

He mahi e whakatau ana i tētahi aho uara.

(value) => string

Ngā tauira

Whānuihia tētahi rārangi tohutoro ki tōna rau tūturu

ts
import { makeResolver } 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)" },
];

const resolve = makeResolver(ir);
resolve("var(--instui-brand)"); // → "#0374B5"

Whakapūhia light-dark() ki tētahi aratau, kia noho rānei me te kore aratau

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

const ir: Token[] = [
  { name: "--instui-bg", syntax: "*", inherits: true, value: "light-dark(#fff, #000)" },
];

makeResolver(ir)("var(--instui-bg)");                 // → "light-dark(#fff, #000)"
makeResolver(ir, { mode: "light" })("var(--instui-bg)"); // → "#fff"
makeResolver(ir, { mode: "dark" })("var(--instui-bg)");  // → "#000"

Ngā whakakapi paparanga e toa ana i ngā tukinga ingoa

ts
import { makeResolver } 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)" },
];
const overrides: Token[] = [
  { name: "--instui-leaf", syntax: "<color>", inherits: true, value: "#000" },
];

makeResolver(ir, { overrides })("var(--instui-brand)"); // → "#000"