Skip to content

pantoken / packages/utils/src / makeResolver

Fonksiyon: makeResolver()

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

Beta

Bir çözümleyici oluşturun; var(--x) referanslarını base karşısında somut yaprak değerlere genişletir (artı herhangi bir overrides). mode ile light-dark()'ü o dala daraltır; olmadan, light-dark() yerinde bırakılır.

Parametreler

base

salt okunur Token[]

Referansları çözerken karşılaştırılacak token kümesi.

options?

ResolveOptions = {}

ResolveOptions.

Döndürür

Bir değer dizesini çözen fonksiyon.

(value) => string

Örnekler

Bir referans zincirini somut yaprağına genişlet

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"

light-dark()'ı bir mod ile daraltın veya mod olmadan koruyun

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"

İsim çakışmalarında kazanan üst yazmaları katmanlayın

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"