Skip to content

pantoken / packages/plugin-kit/src / makeResolver

Fonksyon: makeResolver()

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

Beta

Konstwi yon rezolisè ki elaji referans var(--x) yo an valè fèy konkrè kont base (plis nenpòt overrides). Avèk mode li kole light-dark() sou branch sa a; san li, li kite light-dark() an plas.

Paramèt

base

sèlman lekti Token[]

Gwoup token pou rezoud referans yo kont li.

options?

ResolveOptions

ResolveOptions.

Retounen

Yon fonksyon ki rezoud yon chèn valè.

(value) => string

Egzanp

Elaji yon chèn referans pou rive nan fèy konkrè li

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"

Konprese light-dark() ak yon mòd, oswa kenbe li san youn

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"

Kouch ranplasman ki genyen sou kolizyon non

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"