pantoken / packages/utils/src / makeResolver
Függvény: makeResolver()
makeResolver(
base,options?): (value) =>string
Béta
Hozzon létre egy feloldót, amely kibővíti a var(--x) referenciákat konkrét levél értékekre a base ellen (plusz bármely overrides). A mode segítségével összecsukja a light-dark()-t erre az ágra; nélküle hagyja a light-dark()-t helyén.
Paraméterek
base
readonly Token[]
A tokenek halmaza a referenciák feloldásához.
options?
ResolveOptions = {}
Visszatérés
Egy függvény, amely egy érték karakterláncot felold.
(value) => string
Példák
Egy referencia lánc kiterjesztése annak konkrét levéléhez
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"Összecsukás light-dark() mód használatával, vagy nélküle
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"Rétegelt felülírások, amelyek a névütközéseken nyernek
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"