UNPKG

@a_ng_d/utils-ui-color-palette

Version:

Core utilities library for UI Color Palette - a color management plugin for design tools. This library provides the foundational color manipulation, contrast calculation, and palette generation features used in the plugin.

78 lines (77 loc) 2.63 kB
var u = Object.defineProperty; var f = (c, s, e) => s in c ? u(c, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[s] = e; var d = (c, s, e) => f(c, typeof s != "symbol" ? s + "" : s, e); class y { constructor({ paletteData: s, system: e }) { d(this, "paletteData"); d(this, "system"); d(this, "makeSystemData", () => { const e = this.computePaths(this.system.schema).map((n) => this.resolveToken(n)); return { schema: this.system.schema, tokens: e, type: "system" }; }); d(this, "computePaths", (s) => { const e = s.groups; return e.length === 0 ? [] : e.reduce( (n, t) => { if (n.length === 0) return t.members.map((r) => [r.id]); const o = []; for (const r of n) for (const i of t.members) o.push([...r, i.id]); return o; }, [] ); }); d(this, "resolveToken", (s) => { const e = this.system.schema.groups, n = s.map((i, m) => { var h; const a = (h = e[m]) == null ? void 0 : h.members.find((l) => l.id === i); return (a == null ? void 0 : a.name) ?? i; }), t = this.findBinding(s), o = (t == null ? void 0 : t.isExcluded) ?? !1, r = this.paletteData.themes.map((i) => { var l; if (!t || o) return { themeId: i.id, shadeId: null }; const m = ((l = t.overrides) == null ? void 0 : l[i.id]) ?? t.ref, a = this.parseRef(m); if (!a) return { themeId: i.id, shadeId: null }; const h = this.shadeExists(i.id, a.colorId, a.shadeName); return { themeId: i.id, shadeId: h ? `${i.id}:${a.colorId}:${a.shadeName}` : null }; }); return { path: s, pathNames: n, description: t == null ? void 0 : t.description, isExcluded: o, refs: r }; }); d(this, "findBinding", (s) => (this.system.bindings ?? []).find( (n) => n.path.length === s.length && n.path.every((t, o) => t === s[o]) )); d(this, "parseRef", (s) => { const e = s.indexOf(":"); if (e === -1) return null; const n = s.slice(0, e), t = s.slice(e + 1); return !n || !t ? null : { colorId: n, shadeName: t }; }); d(this, "shadeExists", (s, e, n) => { const t = this.paletteData.themes.find((r) => r.id === s); if (!t) return !1; const o = t.colors.find((r) => r.id === e); return o ? o.shades.some((r) => r.name === n) : !1; }); this.paletteData = s, this.system = e; } } export { y as default }; //# sourceMappingURL=system.js.map