Skip to content

pantoken / packages/utils/src / makeResolver

Fušla: makeResolver()

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

Behta

Gurra resolvara mii álggahit var(--x) referenssat konkretalaš bealddevaluvvon vuođđudit base birra (ja mána overrides). mode dađistá light-dark() daŋus; in dáid, lea light-dark() dasto.

Parametera

base

luohtejuvvon Token[]

Tokenheapmi mii leat buohcat referenssat váldit birra.

options?

ResolveOptions = {}

ResolveOptions.

Gullii / Gávdnat

Funkšuvdna mii dáhpáhusit vuođđovuođa.

(value) => string

Exempla

Álggahit referenssašearbmu konkretalaš bealddege

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"

Dađistagat light-dark() modii birra, dahje čuohpat in modii

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"

Lájeri oarjjiheapmi mii váldá name-collisionaide

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"