Skip to content

pantoken / packages/utils/src / makeResolver

फंक्शन: makeResolver()

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

बीटा

एक रिज़ॉल्वर बनाइए जो var(--x) संदर्भों को base के विरुद्ध ठोस लीफ़ मानों तक विस्तारित करे (इसके साथ कोई भी overrides). mode के साथ यह light-dark() को उस शाखा में समेकित करता है; इसके बिना, यह light-dark() को स्थान पर छोड़ देता है।

पैरामीटर

base

पढ़ने के लिए केवल Token[]

संदर्भों को हल करने के लिए टोकन सेट।

options?

ResolveOptions = {}

ResolveOptions.

वापसी

एक फ़ंक्शन जो एक मान स्ट्रिंग को हल करता है।

(value) => string

उदाहरण

संदर्भ श्रृंखला को उसके ठोस अंतिम नोड तक विस्तारित करें

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() को समेकित करें, या इसे बिना मोड के रखें

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"

नाम टकराव में जीतने वाले ओवरराइड्स को परतबद्ध करें

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"