@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.
787 lines (775 loc) • 29.8 kB
JavaScript
var E = Object.defineProperty;
var N = (c, h, a) => h in c ? E(c, h, { enumerable: !0, configurable: !0, writable: !0, value: a }) : c[h] = a;
var b = (c, h, a) => N(c, typeof h != "symbol" ? h + "" : h, a);
import { c as k } from "../../index-Beb8qoyd.js";
const w = (c) => {
const h = c.themes.filter((o) => o.type === "custom theme").length === 0 ? c.themes.filter((o) => o.type === "default theme") : c.themes.filter((o) => o.type === "custom theme"), a = {}, n = (o) => (isNaN(o.hsl[0]) && (o.hsl[0] = 0), isNaN(o.lch[2]) && (o.lch[2] = 0), isNaN(o.oklch[2]) && (o.oklch[2] = 0), {
rgb: {
r: Math.floor(o.rgb[0]),
g: Math.floor(o.rgb[1]),
b: Math.floor(o.rgb[2])
},
gl: {
r: parseFloat(o.gl[0].toFixed(3)),
g: parseFloat(o.gl[1].toFixed(3)),
b: parseFloat(o.gl[2].toFixed(3))
},
lch: {
l: Math.floor(o.lch[0]),
c: Math.floor(o.lch[1]),
h: Math.floor(o.lch[2])
},
oklch: {
l: parseFloat(o.oklch[0].toFixed(3)),
c: parseFloat(o.oklch[1].toFixed(3)),
h: Math.floor(o.oklch[2])
},
lab: {
l: Math.floor(o.lab[0]),
a: Math.floor(o.lab[1]),
b: Math.floor(o.lab[2])
},
oklab: {
l: parseFloat(o.oklab[0].toFixed(3)),
a: parseFloat(o.oklab[1].toFixed(3)),
b: parseFloat(o.oklab[2].toFixed(3))
},
hsl: {
h: Math.floor(o.hsl[0]),
s: Math.floor(o.hsl[1] * 100),
l: Math.floor(o.hsl[2] * 100)
},
hsluv: {
h: Math.floor(o.hsluv[0]),
s: Math.floor(o.hsluv[1]),
l: Math.floor(o.hsluv[2])
},
hex: o.hex,
description: o.description,
type: "color shade/tint"
}), s = (o, e) => ({
rgb: {
r: Math.floor(e.rgb[0]),
g: Math.floor(e.rgb[1]),
b: Math.floor(e.rgb[2])
},
gl: {
r: parseFloat(e.gl[0].toFixed(3)),
g: parseFloat(e.gl[1].toFixed(3)),
b: parseFloat(e.gl[2].toFixed(3))
},
lch: {
l: Math.floor(e.lch[0]),
c: Math.floor(e.lch[1]),
h: Math.floor(e.lch[2])
},
oklch: {
l: parseFloat(e.oklch[0].toFixed(3)),
c: parseFloat(e.oklch[1].toFixed(3)),
h: Math.floor(e.oklch[2])
},
lab: {
l: Math.floor(e.lab[0]),
a: Math.floor(e.lab[1]),
b: Math.floor(e.lab[2])
},
oklab: {
l: parseFloat(e.oklab[0].toFixed(3)),
a: parseFloat(e.oklab[1].toFixed(3)),
b: parseFloat(e.oklab[2].toFixed(3))
},
hsl: {
h: Math.floor(e.hsl[0]),
s: Math.floor(e.hsl[1] * 100),
l: Math.floor(e.hsl[2] * 100)
},
hsluv: {
h: Math.floor(e.hsluv[0]),
s: Math.floor(e.hsluv[1]),
l: Math.floor(e.hsluv[2])
},
hex: e.hex,
alpha: o.alpha,
description: o.description,
type: "color shade/tint"
});
return h[0].type === "custom theme" ? h.forEach((o) => {
a[o.name] = {}, o.colors.forEach((e) => {
const t = e.shades.find(
(i) => i.type === "source color"
);
a[o.name][e.name] = {}, e.shades.forEach((i) => {
i && t && (a[o.name][e.name][i.name] = i.isTransparent ? s(i, t) : n(i));
}), a[o.name][e.name].description = e.description, a[o.name][e.name].type = "color";
}), a[o.name].description = o.description, a[o.name].type = "color mode";
}) : h.forEach((o) => {
o.colors.forEach((e) => {
const t = e.shades.find(
(i) => i.type === "source color"
);
a[e.name] = {}, e.shades.forEach((i) => {
i && t && (a[e.name][i.name] = i.isTransparent ? s(i, t) : n(i));
}), a[e.name].description = e.description, a[e.name].type = "color";
});
}), a.description = c.description, a.type = "color palette", JSON.stringify(a, null, " ");
};
var T = Object.defineProperty, d = (c, h, a) => h in c ? T(c, h, { enumerable: !0, configurable: !0, writable: !0, value: a }) : c[h] = a, C = (c, h, a) => d(c, typeof h != "symbol" ? h + "" : h, a);
class $ {
constructor(h) {
C(this, "string"), C(this, "doSnakeCase", () => this.string.toLowerCase().split(" ").join("_").replace(/[@/$^%#&!?.,;:+=<>(){}"«»]/g, "")), C(this, "doPascalCase", () => this.string.charAt(0).toUpperCase() + this.string.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (a) => a.toUpperCase()).replace(/[@/$^%#&!?.,;:+=<>(){}"«» ]/g, "").slice(1)), C(this, "doKebabCase", () => this.string.toLowerCase().split(" ").join("-").replace(/[@/$^%#&!?.,;:+=<>(){}"«»]/g, "")), C(this, "doCamelCase", () => this.string.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (a) => a.toUpperCase()).replace(/[@/$^%#&!?.,;:+=<>(){}"«» ]/g, "")), this.string = h;
}
}
const v = (c) => {
const h = c.themes.filter((n) => n.type === "custom theme").length === 0 ? c.themes.filter((n) => n.type === "default theme") : c.themes.filter((n) => n.type === "custom theme"), a = [];
return h.forEach((n) => {
const s = [];
n.colors.forEach((o) => {
const e = o.shades.find((t) => t.type === "source color");
s.push(`// ${o.name}`), o.shades.reverse().forEach((t) => {
s.push(
t.isTransparent ? `static let ${new $(o.name).doPascalCase()}${t.name === "source" ? "Source" : t.name} = UIColor(red: ${e == null ? void 0 : e.gl[0].toFixed(
3
)}, green: ${e == null ? void 0 : e.gl[1].toFixed(3)}, blue: ${e == null ? void 0 : e.gl[2].toFixed(
3
)}, alpha: ${t.alpha ?? 1})` : `static let ${new $(o.name).doPascalCase()}${t.name === "source" ? "Source" : t.name} = UIColor(red: ${t.gl[0].toFixed(
3
)}, green: ${t.gl[1].toFixed(3)}, blue: ${t.gl[2].toFixed(
3
)})`
);
}), s.push("");
}), s.pop(), h[0].type === "custom theme" ? a.push(
`// ${n.name}
struct ${new $(n.name).doPascalCase()} {
${s.join(
`
`
)}
}`
) : a.push(`${s.join(`
`)}`);
}), `import UIKit
struct Color {
${a.join(`
`)}
}`;
}, K = (c) => {
const h = c.themes.filter((n) => n.type === "custom theme").length === 0 ? c.themes.filter((n) => n.type === "default theme") : c.themes.filter((n) => n.type === "custom theme");
let a = `@import "tailwindcss";
@theme {
--color-*: initial;
`;
return h[0].type !== "custom theme" ? h.forEach((n) => {
n.colors.forEach((s) => {
const o = s.shades.find(
(l) => l.type === "source color"
), e = new $(s.name).doKebabCase();
a += ` /* ${s.name} */
`, s.shades.sort().forEach((l) => {
const m = l.isTransparent ? k((o == null ? void 0 : o.hex) ?? "#000000").alpha(l.alpha ?? 1).hex() : l.hex, r = new $(l.name).doKebabCase();
a += ` --color-${e}-${r}: ${m};
`;
});
const t = s === n.colors[n.colors.length - 1], i = n === h[h.length - 1];
t && i || (a += `
`);
});
}) : h.forEach((n) => {
const s = new $(n.name).doKebabCase();
n.colors.forEach((o) => {
const e = o.shades.find(
(m) => m.type === "source color"
), t = new $(o.name).doKebabCase();
a += ` /* ${n.name} - ${o.name} */
`, o.shades.forEach((m) => {
const r = m.isTransparent ? k((e == null ? void 0 : e.hex) ?? "#000000").alpha(m.alpha ?? 1).hex() : m.hex, p = new $(m.name).doKebabCase();
a += ` --color-${s}-${t}-${p}: ${r};
`;
});
const i = o === n.colors[n.colors.length - 1], l = n === h[h.length - 1];
i && l || (a += `
`);
});
}), a += `}
`, a;
}, S = (c) => {
const h = c.themes.filter((n) => n.type === "custom theme").length === 0 ? c.themes.filter((n) => n.type === "default theme") : c.themes.filter((n) => n.type === "custom theme"), a = {
theme: {
colors: {}
}
};
return c.themes[0].colors.forEach((n) => {
a.theme.colors[new $(n.name).doKebabCase()] = {};
}), h[0].type === "custom theme" ? h.forEach((n) => {
n.colors.forEach((s) => {
const o = s.shades.find(
(e) => e.type === "source color"
);
a.theme.colors[new $(s.name).doKebabCase()][new $(n.name).doKebabCase()] = {}, s.shades.forEach((e) => {
a.theme.colors[new $(s.name).doKebabCase()][new $(n.name).doKebabCase()][new $(e.name).doKebabCase()] = e.isTransparent ? k((o == null ? void 0 : o.hex) ?? "#000000").alpha(e.alpha ?? 1).hex() : e.hex;
});
});
}) : h.forEach((n) => {
n.colors.forEach((s) => {
const o = s.shades.find(
(e) => e.type === "source color"
);
a.theme.colors[new $(s.name).doKebabCase()] = {}, s.shades.sort().forEach((e) => {
a.theme.colors[new $(s.name).doKebabCase()][new $(e.name).doKebabCase()] = e.isTransparent ? k((o == null ? void 0 : o.hex) ?? "#000000").alpha(e.alpha ?? 1).hex() : e.hex;
});
});
}), `/** @type {import('tailwindcss').Config} */
module.exports = ${JSON.stringify(a, null, " ")}`;
}, L = (c) => {
const h = c.themes.filter((n) => n.type === "custom theme").length === 0 ? c.themes.filter((n) => n.type === "default theme") : c.themes.filter((n) => n.type === "custom theme"), a = [];
return h.forEach((n) => {
n.colors.forEach((s) => {
const o = s.shades.find((t) => t.type === "source color"), e = [];
e.push(
`// ${h[0].type === "custom theme" ? n.name + " - " : ""}${s.name}`
), s.shades.reverse().forEach((t) => {
e.push(
t.isTransparent ? `public let ${h[0].type === "custom theme" ? new $(n.name + " " + s.name).doPascalCase() : new $(s.name).doPascalCase()}${t.name === "source" ? "Source" : t.name} = Color(red: ${o == null ? void 0 : o.gl[0].toFixed(
3
)}, green: ${o == null ? void 0 : o.gl[1].toFixed(3)}, blue: ${t.gl[2].toFixed(
3
)}).opacity(${t.alpha ?? 1})` : `public let ${h[0].type === "custom theme" ? new $(n.name + " " + s.name).doPascalCase() : new $(s.name).doPascalCase()}${t.name === "source" ? "Source" : t.name} = Color(red: ${t.gl[0].toFixed(
3
)}, green: ${t.gl[1].toFixed(3)}, blue: ${t.gl[2].toFixed(
3
)})`
);
}), e.push(""), e.forEach((t) => a.push(t));
});
}), a.pop(), `import SwiftUI
public extension Color {
static let Token = Color.TokenColor()
struct TokenColor {
${a.join(
`
`
)}
}
}`;
}, j = (c) => {
const h = c.themes.filter((s) => s.type === "custom theme").length === 0 ? c.themes.filter((s) => s.type === "default theme") : c.themes.filter((s) => s.type === "custom theme"), a = {
color: {}
}, n = (s, o, e) => ({
type: "color",
value: o.isTransparent ? k(e.hex).alpha(o.alpha ?? 1).hex() : o.hex,
comment: s.description !== "" ? s.description + " - " + o.description : o.description
});
return c.themes[0].colors.forEach((s) => {
a.color[s.name] = {};
}), h[0].type === "custom theme" ? h.forEach((s) => {
s.colors.forEach((o) => {
const e = o.shades.find(
(t) => t.type === "source color"
);
a.color[o.name][s.name] = {}, o.shades.forEach((t) => {
t && e && (a.color[o.name][s.name][t.name] = n(
o,
t,
e
));
});
});
}) : h.forEach((s) => {
s.colors.forEach((o) => {
const e = o.shades.find(
(t) => t.type === "source color"
);
a.color[o.name] = {}, o.shades.forEach((t) => {
t && e && (a.color[o.name][t.name] = n(o, t, e));
});
});
}), JSON.stringify(a, null, " ");
}, H = (c, h) => {
const a = c.themes.filter((r) => r.type === "custom theme").length === 0 ? c.themes.filter((r) => r.type === "default theme") : c.themes.filter((r) => r.type === "custom theme"), n = [], s = [], o = (r) => {
var f;
isNaN(r.hsl[0]) && (r.hsl[0] = 0), isNaN(r.lch[2]) && (r.lch[2] = 0), isNaN(r.oklch[2]) && (r.oklch[2] = 0);
const p = {
RGB: () => `rgb(${Math.floor(r.rgb[0])}, ${Math.floor(
r.rgb[1]
)}, ${Math.floor(r.rgb[2])})`,
HEX: () => r.hex,
HSL: () => `hsl(${Math.floor(r.hsl[0])} ${Math.floor(
r.hsl[1] * 100
)}% ${Math.floor(r.hsl[2] * 100)}%)`,
LCH: () => `lch(${Math.floor(r.lch[0])}% ${Math.floor(
r.lch[1]
)} ${Math.floor(r.lch[2])})`,
OKLCH: () => `oklch(${Math.floor(r.oklch[0] * 100)}% ${r.oklch[1].toFixed(3)} ${Math.floor(r.oklch[2])})`
};
return (f = p[h ?? "RGB"]) == null ? void 0 : f.call(p);
}, e = (r, p) => {
var g;
isNaN(r.hsl[0]) && (r.hsl[0] = 0), isNaN(r.lch[2]) && (r.lch[2] = 0), isNaN(r.oklch[2]) && (r.oklch[2] = 0);
const f = {
RGB: () => {
var u;
return `rgba(${Math.floor(p.rgb[0])}, ${Math.floor(
p.rgb[1]
)}, ${Math.floor(p.rgb[2])}, ${((u = r.alpha) == null ? void 0 : u.toFixed(2)) ?? 1})`;
},
HEX: () => k(p.hex).alpha(r.alpha ?? 1).hex(),
HSL: () => {
var u;
return `hsla(${Math.floor(p.hsl[0])} ${Math.floor(
p.hsl[1] * 100
)}%, ${Math.floor(p.hsl[2] * 100)}% ${((u = r.alpha) == null ? void 0 : u.toFixed(2)) ?? 1})`;
},
LCH: () => {
var u;
return `lch(${Math.floor(p.lch[0])}% ${Math.floor(
p.lch[1]
)} ${Math.floor(p.lch[2])} / ${((u = r.alpha) == null ? void 0 : u.toFixed(2)) ?? 1})`;
},
OKLCH: () => {
var u;
return `oklch(${Math.floor(p.oklch[0 * 100])}% ${p.oklch[1].toFixed(3)} ${Math.floor(p.oklch[2])} / ${((u = r.alpha) == null ? void 0 : u.toFixed(2)) ?? 1})`;
}
};
return (g = f[h ?? "RGB"]) == null ? void 0 : g.call(f);
}, t = a.find(
(r) => r.type === "default theme"
);
if (t) {
const r = [];
return t.colors.forEach((p, f) => {
f > 0 && r.push(""), r.push(`// ${p.name}`), p.shades.reverse().forEach((g) => {
const u = p.shades.find((y) => y.type === "source color"), x = `$${new $(p.name).doKebabCase()}-${g.name}`;
u && r.push(
`${x}: ${g.isTransparent ? e(g, u) : o(g)};`
);
});
}), n.push(r.join(`
`)), n.join(`
`);
}
a.forEach((r) => {
const p = new $(r.name).doKebabCase(), f = [];
f.push(`// ${r.name}`), f.push(`@mixin ${p} {`), r.colors.forEach((g, u) => {
u > 0 && f.push(""), f.push(` // ${g.name}`), g.shades.reverse().forEach((x) => {
const y = g.shades.find((F) => F.type === "source color"), M = `--${new $(g.name).doKebabCase()}-${x.name}`;
y && f.push(
` ${M}: ${x.isTransparent ? e(x, y) : o(x)};`
);
});
}), f.push("}"), n.push(f.join(`
`));
});
const i = /* @__PURE__ */ new Set();
if (a.forEach((r) => {
r.colors.forEach((p) => {
p.shades.forEach((f) => {
if (p.shades.find((u) => u.type === "source color")) {
const x = `--${new $(p.name).doKebabCase()}-${f.name}`;
i.add(x);
}
});
});
}), i.size > 0) {
const r = /* @__PURE__ */ new Map();
i.forEach((p) => {
const f = p.match(/--([a-zA-Z0-9-]+)-([a-zA-Z0-9-]+)/);
if (f) {
const g = f[1];
r.has(g) || r.set(g, []);
const u = `$${p.substring(2)}`;
r.get(g).push(`${u}: var(${p});`);
}
}), r.forEach((p, f) => {
s.push(
`// ${f.charAt(0).toUpperCase() + f.slice(1)}`
), s.push(...p), s.push("");
}), s.length > 0 && s[s.length - 1] === "" && s.pop(), n.push(s.join(`
`));
}
const l = [":root {"];
a.forEach((r, p) => {
const f = new $(r.name).doKebabCase();
l.push(` &[data-theme="${f}"] {
@include ${f};
}`), p !== a.length - 1 && l.push("");
}), l.push("}"), n.push(l.join(`
`));
const m = [];
return a.forEach((r) => {
const p = new $(r.name).doKebabCase();
m.push(`.${p} {
@include ${p};
}`);
}), n.push(m.join(`
`)), n.join(`
`);
}, V = (c) => {
const h = c.themes.filter((n) => n.type === "custom theme").length === 0 ? c.themes.filter((n) => n.type === "default theme") : c.themes.filter((n) => n.type === "custom theme"), a = [];
return h.forEach((n) => {
n.colors.forEach((s) => {
const o = s.shades.find((t) => t.type === "source color"), e = [];
e.push(
`<!--${h[0].type === "custom theme" ? `${n.name} - ${s.name}-->` : `${s.name}-->`}`
), s.shades.reverse().forEach((t) => {
e.push(
`<color name="${h[0].type === "custom theme" ? new $(n.name + " " + s.name).doSnakeCase() : new $(s.name).doSnakeCase()}_${t.name}">${t.isTransparent ? k((o == null ? void 0 : o.hex) ?? "#000000").alpha(t.alpha ?? 1).hex() : t.hex}</color>`
);
}), e.push(""), e.forEach((t) => a.push(t));
});
}), a.pop(), `<?xml version="1.0" encoding="utf-8"?>
<resources>
${a.join(
`
`
)}
</resources>`;
}, B = (c) => {
const h = c.themes.filter((o) => o.type === "custom theme").length === 0 ? c.themes.filter((o) => o.type === "default theme") : c.themes.filter((o) => o.type === "custom theme"), a = {
$themes: [],
$metadata: {
activeThemes: [],
tokenSetOrder: [],
activeSets: []
}
}, n = c.name, s = (o, e, t) => ({
$type: "color",
$value: e.isTransparent ? k(t.hex).alpha(e.alpha ?? 1).hex() : e.hex,
$description: o.description !== "" ? o.description + " - " + e.description : e.description
});
return h[0].type === "custom theme" ? h.forEach((o) => {
o.colors.forEach((e) => {
const t = e.shades.find(
(i) => i.type === "source color"
);
a[`${o.name}/${e.name}`] = {}, e.shades.forEach((i) => {
i && t && (a[`${o.name}/${e.name}`][i.name] = s(
e,
i,
t
));
});
});
}) : h.forEach((o) => {
o.colors.forEach((e) => {
const t = e.shades.find(
(i) => i.type === "source color"
);
a[`${n}/${e.name}`] = {}, e.shades.forEach((i) => {
i && t && (a[`${n}/${e.name}`][i.name] = s(
e,
i,
t
));
});
});
}), JSON.stringify(a, null, " ");
}, R = (c, h) => {
const a = c.themes.filter((l) => l.type === "custom theme").length === 0 ? c.themes.filter((l) => l.type === "default theme") : c.themes.filter((l) => l.type === "custom theme"), n = [], s = (l) => {
var r;
isNaN(l.hsl[0]) && (l.hsl[0] = 0), isNaN(l.lch[2]) && (l.lch[2] = 0), isNaN(l.oklch[2]) && (l.oklch[2] = 0);
const m = {
RGB: () => `rgb(${Math.floor(l.rgb[0])}, ${Math.floor(
l.rgb[1]
)}, ${Math.floor(l.rgb[2])})`,
HEX: () => l.hex,
HSL: () => `hsl(${Math.floor(l.hsl[0])} ${Math.floor(
l.hsl[1] * 100
)}% ${Math.floor(l.hsl[2] * 100)}%)`,
LCH: () => `lch(${Math.floor(l.lch[0])}% ${Math.floor(
l.lch[1]
)} ${Math.floor(l.lch[2])})`,
OKLCH: () => `oklch(${Math.floor(l.oklch[0] * 100)}% ${l.oklch[1].toFixed(3)} ${Math.floor(l.oklch[2])})`
};
return (r = m[h ?? "RGB"]) == null ? void 0 : r.call(m);
}, o = (l, m) => {
var p;
isNaN(l.hsl[0]) && (l.hsl[0] = 0), isNaN(l.lch[2]) && (l.lch[2] = 0), isNaN(l.oklch[2]) && (l.oklch[2] = 0);
const r = {
RGB: () => {
var f;
return `rgba(${Math.floor(m.rgb[0])}, ${Math.floor(
m.rgb[1]
)}, ${Math.floor(m.rgb[2])}, ${((f = l.alpha) == null ? void 0 : f.toFixed(2)) ?? 1})`;
},
HEX: () => k(m.hex).alpha(l.alpha ?? 1).hex(),
HSL: () => {
var f;
return `hsla(${Math.floor(m.hsl[0])}, ${Math.floor(
m.hsl[1] * 100
)}% ${Math.floor(m.hsl[2] * 100)}% ${((f = l.alpha) == null ? void 0 : f.toFixed(2)) ?? 1})`;
},
LCH: () => {
var f;
return `lch(${Math.floor(m.lch[0])}% ${Math.floor(
m.lch[1]
)} ${Math.floor(m.lch[2])} / ${((f = l.alpha) == null ? void 0 : f.toFixed(2)) ?? 1})`;
},
OKLCH: () => {
var f;
return `oklch(${Math.floor(m.oklch[0] * 100)}% ${m.oklch[1].toFixed(3)} ${Math.floor(m.oklch[2])} / ${((f = l.alpha) == null ? void 0 : f.toFixed(2)) ?? 1})`;
}
};
return (p = r[h ?? "RGB"]) == null ? void 0 : p.call(r);
}, e = a.find(
(l) => l.type === "default theme"
);
if (e) {
const l = [];
return e.colors.forEach((m, r) => {
r > 0 && l.push(""), l.push(`// ${m.name}`), m.shades.reverse().forEach((p) => {
const f = m.shades.find((u) => u.type === "source color"), g = `@${new $(m.name).doKebabCase()}-${p.name}`;
f && l.push(
`${g}: ${p.isTransparent ? o(p, f) : s(p)};`
);
});
}), n.push(l.join(`
`)), n.join(`
`);
}
a.forEach((l) => {
const m = new $(l.name).doKebabCase(), r = [];
r.push(`// ${l.name}`), r.push(`.${m}() {`), l.colors.forEach((p, f) => {
f > 0 && r.push(""), r.push(` // ${p.name}`), p.shades.reverse().forEach((g) => {
const u = p.shades.find((y) => y.type === "source color"), x = `@${new $(p.name).doKebabCase()}-${g.name}`;
u && r.push(
` ${x}: ${g.isTransparent ? o(g, u) : s(g)};`
);
});
}), r.push("}"), n.push(r.join(`
`));
});
const t = [":root {"];
a.forEach((l, m) => {
const r = new $(l.name).doKebabCase();
t.push(` &[data-theme="${r}"] {
.${r}();
}`), m !== a.length - 1 && t.push("");
}), t.push("}"), n.push(t.join(`
`));
const i = [];
return a.forEach((l) => {
const m = new $(l.name).doKebabCase();
i.push(`.${m} {
.${m}();
}`);
}), n.push(i.join(`
`)), n.join(`
`);
}, G = (c, h) => {
const a = c.themes.filter((e) => e.type === "custom theme").length === 0 ? c.themes.filter((e) => e.type === "default theme") : c.themes.filter((e) => e.type === "custom theme"), n = {}, s = (e) => {
var i;
isNaN(e.oklch[2]) && (e.oklch[2] = 0);
const t = {
RGB: () => ({
colorSpace: "srgb",
components: [
parseFloat(e.gl[0].toFixed(3)),
parseFloat(e.gl[1].toFixed(3)),
parseFloat(e.gl[2].toFixed(3))
],
hex: e.hex
}),
OKLCH: () => ({
colorSpace: "oklch",
components: [
parseFloat(e.oklch[0].toFixed(3)),
parseFloat(e.oklch[1].toFixed(3)),
parseFloat(e.oklch[2].toFixed(0))
],
hex: e.hex
})
};
return (i = t[h ?? "RGB"]) == null ? void 0 : i.call(t);
}, o = (e, t) => {
var l;
isNaN(t.oklch[2]) && (t.oklch[2] = 0);
const i = {
RGB: () => ({
colorSpace: "srgb",
components: [
parseFloat(e.gl[0].toFixed(3)),
parseFloat(e.gl[1].toFixed(3)),
parseFloat(e.gl[2].toFixed(3))
],
hex: e.hex,
alpha: t.alpha
}),
OKLCH: () => ({
colorSpace: "oklch",
components: [
parseFloat(e.oklch[0].toFixed(3)),
parseFloat(e.oklch[1].toFixed(3)),
parseFloat(e.oklch[2].toFixed(0))
],
hex: e.hex,
alpha: t.alpha
})
};
return (l = i[h ?? "RGB"]) == null ? void 0 : l.call(i);
};
return a[0].type === "custom theme" ? a.forEach((e) => {
e.colors.forEach((t) => {
const i = t.shades.find(
(l) => l.type === "source color"
);
n[t.name] || (n[t.name] = {
$type: "color"
}), t.shades.forEach((l) => {
!n[t.name][l.name] && i && (n[t.name][l.name] = {
$type: "color",
$value: l.isTransparent ? o(i, l) : s(l),
$description: t.description !== "" ? t.description + " - " + l.description : l.description,
$extensions: {
mode: {}
}
}), i && (n[t.name][l.name].$extensions.mode[e.name] = l.isTransparent ? o(i, l) : s(l));
});
});
}) : a.forEach((e) => {
e.colors.forEach((t) => {
const i = t.shades.find(
(l) => l.type === "source color"
);
n[t.name] = {}, t.shades.forEach((l) => {
l && i && (n[t.name][l.name] = {
$type: "color",
$value: l.isTransparent ? o(i, l) : s(l),
$description: t.description !== "" ? t.description + " - " + l.description : l.description
});
});
});
}), JSON.stringify(n, null, " ");
}, A = (c) => {
const h = c.themes.filter((i) => i.type === "custom theme").length === 0 ? c.themes.filter((i) => i.type === "default theme") : c.themes.filter((i) => i.type === "custom theme"), a = [], n = [], s = [], o = [], e = [], t = [];
return h.forEach((i) => {
i.colors.forEach((l) => {
l.shades.forEach((m) => {
s.push(m.name), o.push(Math.floor(m.lch[0])), e.push(Math.floor(m.lch[1])), t.push(Math.floor(m.lch[2]));
}), a.push({
name: l.name,
csv: `${l.name},Lightness,Chroma,Hue
${s.map((m, r) => `${m},${o[r]},${e[r]},${t[r]}`).join(`
`)}`
}), s.splice(0, s.length), o.splice(0, o.length), e.splice(0, e.length), t.splice(0, t.length);
}), n.push({
name: i.name,
colors: a.map((l) => l),
type: i.type
}), a.splice(0, a.length);
}), n;
}, U = (c, h) => {
const a = c.themes.filter((e) => e.type === "custom theme").length === 0 ? c.themes.filter((e) => e.type === "default theme") : c.themes.filter((e) => e.type === "custom theme"), n = [], s = (e) => {
var i;
isNaN(e.hsl[0]) && (e.hsl[0] = 0), isNaN(e.lch[2]) && (e.lch[2] = 0), isNaN(e.oklch[2]) && (e.oklch[2] = 0);
const t = {
RGB: () => `rgb(${Math.floor(e.rgb[0])}, ${Math.floor(
e.rgb[1]
)}, ${Math.floor(e.rgb[2])})`,
HEX: () => e.hex,
HSL: () => `hsl(${Math.floor(e.hsl[0])} ${Math.floor(
e.hsl[1] * 100
)}% ${Math.floor(e.hsl[2] * 100)}%)`,
LCH: () => `lch(${Math.floor(e.lch[0])}% ${Math.floor(
e.lch[1]
)} ${Math.floor(e.lch[2])})`,
OKLCH: () => `oklch(${Math.floor(e.oklch[0] * 100)}% ${e.oklch[1].toFixed(3)} ${Math.floor(e.oklch[2])})`,
P3: () => `color(display-p3 ${e.gl[0].toFixed(3)} ${e.gl[1].toFixed(
3
)} ${e.gl[2].toFixed(3)})`
};
return (i = t[h ?? "RGB"]) == null ? void 0 : i.call(t);
}, o = (e, t) => {
var l;
isNaN(e.hsl[0]) && (e.hsl[0] = 0), isNaN(e.lch[2]) && (e.lch[2] = 0), isNaN(e.oklch[2]) && (e.oklch[2] = 0);
const i = {
RGB: () => {
var m;
return `rgb(${Math.floor(t.rgb[0])}, ${Math.floor(
t.rgb[1]
)}, ${Math.floor(t.rgb[2])} / ${((m = e.alpha) == null ? void 0 : m.toFixed(2)) ?? 1})`;
},
HEX: () => k(t.hex).alpha(e.alpha ?? 1).hex(),
HSL: () => {
var m;
return `hsl(${Math.floor(t.hsl[0])} ${Math.floor(
t.hsl[1] * 100
)}% ${Math.floor(t.hsl[2] * 100)}% / ${((m = e.alpha) == null ? void 0 : m.toFixed(2)) ?? 1})`;
},
LCH: () => {
var m;
return `lch(${Math.floor(t.lch[0])}% ${Math.floor(
t.lch[1]
)} ${Math.floor(t.lch[2])} / ${((m = e.alpha) == null ? void 0 : m.toFixed(2)) ?? 1})`;
},
OKLCH: () => {
var m;
return `oklch(${Math.floor(t.oklch[0 * 100])}% ${t.oklch[1].toFixed(3)} ${Math.floor(t.oklch[2])} / ${((m = e.alpha) == null ? void 0 : m.toFixed(2)) ?? 1})`;
},
P3: () => {
var m;
return `color(display-p3 ${t.gl[0].toFixed(3)} ${t.gl[1].toFixed(
3
)} ${t.gl[2].toFixed(3)} / ${((m = e.alpha) == null ? void 0 : m.toFixed(2)) ?? 1})`;
}
};
return (l = i[h ?? "RGB"]) == null ? void 0 : l.call(i);
};
return a.forEach((e) => {
const t = [];
e.colors.forEach((i) => {
t.push(`/* ${i.name} */`), i.shades.reverse().forEach((l) => {
const m = i.shades.find((r) => r.type === "source color");
m && t.push(
`--${new $(i.name).doKebabCase()}-${l.name}: ${l.isTransparent ? o(l, m) : s(l)};`
);
}), t.push("");
}), t.pop(), n.push(
`${e.type === "custom theme" ? `/* ${e.name} */
` : ""}:root${e.type === "custom theme" ? `[data-theme='${new $(e.name).doKebabCase()}']` : ""} {
${t.join(`
`)}
}`
);
}), n.join(`
`);
}, O = (c) => {
const h = c.themes.filter((n) => n.type === "custom theme").length === 0 ? c.themes.filter((n) => n.type === "default theme") : c.themes.filter((n) => n.type === "custom theme"), a = [];
return h.forEach((n) => {
n.colors.forEach((s) => {
const o = s.shades.find((t) => t.type === "source color"), e = [];
e.push(
`// ${h[0].type === "custom theme" ? n.name + " - " : ""}${s.name}`
), s.shades.reverse().forEach((t) => {
e.push(
`val ${h[0].type === "custom theme" ? new $(n.name + " " + s.name).doSnakeCase() : new $(s.name).doSnakeCase()}_${t.name} = Color(${t.isTransparent ? k((o == null ? void 0 : o.hex) ?? "#000000").alpha(t.alpha ?? 1).hex().replace("#", "0xFF").toUpperCase() : t.hex.replace("#", "0xFF").toUpperCase()})`
);
}), e.push(""), e.forEach((t) => a.push(t));
});
}), a.pop(), `import androidx.compose.ui.graphics.Color
${a.join(`
`)}`;
};
class X {
constructor(h) {
b(this, "paletteData");
b(this, "makeNativeTokens", () => B(this.paletteData));
b(this, "makeDtcgTokens", (h = "RGB") => G(this.paletteData, h));
b(this, "makeStyleDictionaryV3Tokens", () => j(this.paletteData));
b(this, "makeUniversalJson", () => w(this.paletteData));
b(this, "makeCssCustomProps", (h = "RGB") => U(this.paletteData, h));
b(this, "makeScssVariables", (h = "RGB") => H(this.paletteData, h));
b(this, "makeLessVariables", (h = "RGB") => R(this.paletteData, h));
b(this, "makeTailwindV3Config", () => S(this.paletteData));
b(this, "makeTailwindV4Config", () => K(this.paletteData));
b(this, "makeSwiftUI", () => L(this.paletteData));
b(this, "makeUIKit", () => v(this.paletteData));
b(this, "makeCompose", () => O(this.paletteData));
b(this, "makeResources", () => V(this.paletteData));
b(this, "makeCsv", () => A(this.paletteData));
this.paletteData = h;
}
}
export {
X as default
};
//# sourceMappingURL=code.js.map