@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.
788 lines (776 loc) • 30.1 kB
JavaScript
var E = Object.defineProperty;
var w = (i, h, a) => h in i ? E(i, h, { enumerable: !0, configurable: !0, writable: !0, value: a }) : i[h] = a;
var b = (i, h, a) => w(i, typeof h != "symbol" ? h + "" : h, a);
import { c as k } from "../../index-Beb8qoyd.js";
const N = (i) => {
const h = i.themes.filter((t) => t.type === "custom theme").length === 0 ? i.themes.filter((t) => t.type === "default theme") : i.themes.filter((t) => t.type === "custom theme"), a = {}, l = (t) => (isNaN(t.hsl[0]) && (t.hsl[0] = 0), isNaN(t.lch[2]) && (t.lch[2] = 0), isNaN(t.oklch[2]) && (t.oklch[2] = 0), {
rgb: {
r: Math.floor(t.rgb[0]),
g: Math.floor(t.rgb[1]),
b: Math.floor(t.rgb[2])
},
gl: {
r: parseFloat(t.gl[0].toFixed(3)),
g: parseFloat(t.gl[1].toFixed(3)),
b: parseFloat(t.gl[2].toFixed(3))
},
lch: {
l: Math.floor(t.lch[0]),
c: Math.floor(t.lch[1]),
h: Math.floor(t.lch[2])
},
oklch: {
l: parseFloat(t.oklch[0].toFixed(3)),
c: parseFloat(t.oklch[1].toFixed(3)),
h: Math.floor(t.oklch[2])
},
lab: {
l: Math.floor(t.lab[0]),
a: Math.floor(t.lab[1]),
b: Math.floor(t.lab[2])
},
oklab: {
l: parseFloat(t.oklab[0].toFixed(3)),
a: parseFloat(t.oklab[1].toFixed(3)),
b: parseFloat(t.oklab[2].toFixed(3))
},
hsl: {
h: Math.floor(t.hsl[0]),
s: Math.floor(t.hsl[1] * 100),
l: Math.floor(t.hsl[2] * 100)
},
hsluv: {
h: Math.floor(t.hsluv[0]),
s: Math.floor(t.hsluv[1]),
l: Math.floor(t.hsluv[2])
},
hex: t.hex,
description: t.description,
type: "color shade/tint"
}), s = (t, 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: t.alpha,
description: t.description,
type: "color shade/tint"
});
return h[0].type === "custom theme" ? h.forEach((t) => {
a[t.name] = {}, t.colors.forEach((e) => {
const o = e.shades.find(
(c) => c.type === "source color"
);
a[t.name][e.name] = {}, e.shades.forEach((c) => {
c && o && (a[t.name][e.name][c.name] = c.isTransparent ? s(c, o) : l(c));
}), a[t.name][e.name].description = e.description, a[t.name][e.name].type = "color";
}), a[t.name].description = t.description, a[t.name].type = "color mode";
}) : h.forEach((t) => {
t.colors.forEach((e) => {
const o = e.shades.find(
(c) => c.type === "source color"
);
a[e.name] = {}, e.shades.forEach((c) => {
c && o && (a[e.name][c.name] = c.isTransparent ? s(c, o) : l(c));
}), a[e.name].description = e.description, a[e.name].type = "color";
});
}), a.description = i.description, a.type = "color palette", JSON.stringify(a, null, " ");
};
var T = Object.defineProperty, d = (i, h, a) => h in i ? T(i, h, { enumerable: !0, configurable: !0, writable: !0, value: a }) : i[h] = a, C = (i, h, a) => d(i, 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 = (i) => {
const h = i.themes.filter((l) => l.type === "custom theme").length === 0 ? i.themes.filter((l) => l.type === "default theme") : i.themes.filter((l) => l.type === "custom theme"), a = [];
return h.forEach((l) => {
const s = [];
l.colors.forEach((t) => {
const e = t.shades.find((o) => o.type === "source color");
s.push(`// ${t.name}`), t.shades.reverse().forEach((o) => {
s.push(
o.isTransparent ? `static let ${new $(t.name).doPascalCase()}${o.name === "source" ? "Source" : o.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: ${o.alpha ?? 1})` : `static let ${new $(t.name).doPascalCase()}${o.name === "source" ? "Source" : o.name} = UIColor(red: ${o.gl[0].toFixed(
3
)}, green: ${o.gl[1].toFixed(3)}, blue: ${o.gl[2].toFixed(
3
)})`
);
}), s.push("");
}), s.pop(), h[0].type === "custom theme" ? a.push(
`// ${l.name}
struct ${new $(l.name).doPascalCase()} {
${s.join(
`
`
)}
}`
) : a.push(`${s.join(`
`)}`);
}), `import UIKit
struct Color {
${a.join(`
`)}
}`;
}, S = (i) => {
const h = i.themes.filter((l) => l.type === "custom theme").length === 0 ? i.themes.filter((l) => l.type === "default theme") : i.themes.filter((l) => l.type === "custom theme");
let a = `@import "tailwindcss";
@theme {
--color-*: initial;
`;
return h[0].type !== "custom theme" ? h.forEach((l) => {
l.colors.forEach((s) => {
const t = s.shades.find(
(n) => n.type === "source color"
), e = new $(s.name).doKebabCase();
a += ` /* ${s.name} */
`, s.shades.sort().forEach((n) => {
const m = n.isTransparent ? k((t == null ? void 0 : t.hex) ?? "#000000").alpha(n.alpha ?? 1).hex() : n.hex, r = new $(n.name).doKebabCase();
a += ` --color-${e}-${r}: ${m};
`;
});
const o = s === l.colors[l.colors.length - 1], c = l === h[h.length - 1];
o && c || (a += `
`);
});
}) : h.forEach((l) => {
const s = new $(l.name).doKebabCase();
l.colors.forEach((t) => {
const e = t.shades.find(
(m) => m.type === "source color"
), o = new $(t.name).doKebabCase();
a += ` /* ${l.name} - ${t.name} */
`, t.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}-${o}-${p}: ${r};
`;
});
const c = t === l.colors[l.colors.length - 1], n = l === h[h.length - 1];
c && n || (a += `
`);
});
}), a += `}
`, a;
}, K = (i) => {
const h = i.themes.filter((l) => l.type === "custom theme").length === 0 ? i.themes.filter((l) => l.type === "default theme") : i.themes.filter((l) => l.type === "custom theme"), a = {
theme: {
colors: {}
}
};
return i.themes[0].colors.forEach((l) => {
a.theme.colors[new $(l.name).doKebabCase()] = {};
}), h[0].type === "custom theme" ? h.forEach((l) => {
l.colors.forEach((s) => {
const t = s.shades.find(
(e) => e.type === "source color"
);
a.theme.colors[new $(s.name).doKebabCase()][new $(l.name).doKebabCase()] = {}, s.shades.forEach((e) => {
a.theme.colors[new $(s.name).doKebabCase()][new $(l.name).doKebabCase()][new $(e.name).doKebabCase()] = e.isTransparent ? k((t == null ? void 0 : t.hex) ?? "#000000").alpha(e.alpha ?? 1).hex() : e.hex;
});
});
}) : h.forEach((l) => {
l.colors.forEach((s) => {
const t = 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((t == null ? void 0 : t.hex) ?? "#000000").alpha(e.alpha ?? 1).hex() : e.hex;
});
});
}), `/** @type {import('tailwindcss').Config} */
module.exports = ${JSON.stringify(a, null, " ")}`;
}, L = (i) => {
const h = i.themes.filter((l) => l.type === "custom theme").length === 0 ? i.themes.filter((l) => l.type === "default theme") : i.themes.filter((l) => l.type === "custom theme"), a = [];
return h.forEach((l) => {
l.colors.forEach((s) => {
const t = s.shades.find((o) => o.type === "source color"), e = [];
e.push(
`// ${h[0].type === "custom theme" ? l.name + " - " : ""}${s.name}`
), s.shades.reverse().forEach((o) => {
e.push(
o.isTransparent ? `public let ${h[0].type === "custom theme" ? new $(l.name + " " + s.name).doPascalCase() : new $(s.name).doPascalCase()}${o.name === "source" ? "Source" : o.name} = Color(red: ${t == null ? void 0 : t.gl[0].toFixed(
3
)}, green: ${t == null ? void 0 : t.gl[1].toFixed(3)}, blue: ${o.gl[2].toFixed(
3
)}).opacity(${o.alpha ?? 1})` : `public let ${h[0].type === "custom theme" ? new $(l.name + " " + s.name).doPascalCase() : new $(s.name).doPascalCase()}${o.name === "source" ? "Source" : o.name} = Color(red: ${o.gl[0].toFixed(
3
)}, green: ${o.gl[1].toFixed(3)}, blue: ${o.gl[2].toFixed(
3
)})`
);
}), e.push(""), e.forEach((o) => a.push(o));
});
}), a.pop(), `import SwiftUI
public extension Color {
static let Token = Color.TokenColor()
struct TokenColor {
${a.join(
`
`
)}
}
}`;
}, j = (i) => {
const h = i.themes.filter((s) => s.type === "custom theme").length === 0 ? i.themes.filter((s) => s.type === "default theme") : i.themes.filter((s) => s.type === "custom theme"), a = {
color: {}
}, l = (s, t, e) => ({
type: "color",
value: t.isTransparent ? k(e.hex).alpha(t.alpha ?? 1).hex() : t.hex,
comment: s.description !== "" ? s.description + " - " + t.description : t.description
});
return i.themes[0].colors.forEach((s) => {
a.color[s.name] = {};
}), h[0].type === "custom theme" ? h.forEach((s) => {
s.colors.forEach((t) => {
const e = t.shades.find(
(o) => o.type === "source color"
);
a.color[t.name][s.name] = {}, t.shades.forEach((o) => {
o && e && (a.color[t.name][s.name][o.name] = l(
t,
o,
e
));
});
});
}) : h.forEach((s) => {
s.colors.forEach((t) => {
const e = t.shades.find(
(o) => o.type === "source color"
);
a.color[t.name] = {}, t.shades.forEach((o) => {
o && e && (a.color[t.name][o.name] = l(t, o, e));
});
});
}), JSON.stringify(a, null, " ");
}, H = (i, h) => {
const a = i.themes.filter((r) => r.type === "custom theme").length === 0 ? i.themes.filter((r) => r.type === "default theme") : i.themes.filter((r) => r.type === "custom theme"), l = [], s = [], t = (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 `rgb(${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 `hsl(${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);
}, o = a.find(
(r) => r.type === "default theme"
);
if (o) {
const r = [];
return o.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) : t(g)};`
);
});
}), l.push(r.join(`
`)), l.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) : t(x)};`
);
});
}), f.push("}"), l.push(f.join(`
`));
});
const c = /* @__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}`;
c.add(x);
}
});
});
}), c.size > 0) {
const r = /* @__PURE__ */ new Map();
c.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(), l.push(s.join(`
`));
}
const n = [":root {"];
a.forEach((r, p) => {
const f = new $(r.name).doKebabCase();
n.push(` &[data-theme="${f}"] {
@include ${f};
}`), p !== a.length - 1 && n.push("");
}), n.push("}"), l.push(n.join(`
`));
const m = [];
return a.forEach((r) => {
const p = new $(r.name).doKebabCase();
m.push(`.${p} {
@include ${p};
}`);
}), l.push(m.join(`
`)), l.join(`
`);
}, V = (i) => {
const h = i.themes.filter((l) => l.type === "custom theme").length === 0 ? i.themes.filter((l) => l.type === "default theme") : i.themes.filter((l) => l.type === "custom theme"), a = [];
return h.forEach((l) => {
l.colors.forEach((s) => {
const t = s.shades.find((o) => o.type === "source color"), e = [];
e.push(
`<!--${h[0].type === "custom theme" ? `${l.name} - ${s.name}-->` : `${s.name}-->`}`
), s.shades.reverse().forEach((o) => {
e.push(
`<color name="${h[0].type === "custom theme" ? new $(l.name + " " + s.name).doSnakeCase() : new $(s.name).doSnakeCase()}_${o.name}">${o.isTransparent ? k((t == null ? void 0 : t.hex) ?? "#000000").alpha(o.alpha ?? 1).hex() : o.hex}</color>`
);
}), e.push(""), e.forEach((o) => a.push(o));
});
}), a.pop(), `<?xml version="1.0" encoding="utf-8"?>
<resources>
${a.join(
`
`
)}
</resources>`;
}, B = (i) => {
const h = i.name, a = (e, o, c) => ({
$type: "color",
$value: o.isTransparent ? k(c.hex).alpha(o.alpha ?? 1).hex() : o.hex,
$description: e.description !== "" ? e.description + " - " + o.description : o.description
}), l = (e, o) => ({
name: e,
group: "Modes",
description: o,
selectedTokenSets: {
[`${h}/${e}`]: "enabled"
}
}), s = i.themes.filter((e) => e.type === "custom theme").length === 0 ? i.themes.filter((e) => e.type === "default theme") : i.themes.filter((e) => e.type === "custom theme"), t = {
$themes: s.filter((e) => e.type === "custom theme").map((e) => l(e.name, e.description)),
$metadata: {
activeThemes: [],
tokenSetOrder: s.filter((e) => e.type === "custom theme").map(
(e) => `${new $(h).doSnakeCase()}/${new $(e.name).doSnakeCase()}`
),
activeSets: []
}
};
return s[0].type === "custom theme" ? s.forEach((e) => {
t[`${h}/${e.name}`] = {}, e.colors.forEach((o) => {
const c = o.shades.find(
(n) => n.type === "source color"
);
o.shades.forEach((n) => {
n && c && (t[`${h}/${e.name}`][`${new $(o.name).doSnakeCase()}.${n.name}`] = a(o, n, c));
});
});
}) : s.forEach((e) => {
t[h] = {}, e.colors.forEach((o) => {
const c = o.shades.find(
(n) => n.type === "source color"
);
o.shades.forEach((n) => {
n && c && (t[h][`${new $(o.name).doSnakeCase()}.${n.name}`] = a(o, n, c));
});
});
}), JSON.stringify(t, null, " ");
}, R = (i, h) => {
const a = i.themes.filter((n) => n.type === "custom theme").length === 0 ? i.themes.filter((n) => n.type === "default theme") : i.themes.filter((n) => n.type === "custom theme"), l = [], s = (n) => {
var r;
isNaN(n.hsl[0]) && (n.hsl[0] = 0), isNaN(n.lch[2]) && (n.lch[2] = 0), isNaN(n.oklch[2]) && (n.oklch[2] = 0);
const m = {
RGB: () => `rgb(${Math.floor(n.rgb[0])} ${Math.floor(
n.rgb[1]
)} ${Math.floor(n.rgb[2])})`,
HEX: () => n.hex,
HSL: () => `hsl(${Math.floor(n.hsl[0])} ${Math.floor(
n.hsl[1] * 100
)}% ${Math.floor(n.hsl[2] * 100)}%)`,
LCH: () => `lch(${Math.floor(n.lch[0])}% ${Math.floor(
n.lch[1]
)} ${Math.floor(n.lch[2])})`,
OKLCH: () => `oklch(${Math.floor(n.oklch[0] * 100)}% ${n.oklch[1].toFixed(3)} ${Math.floor(n.oklch[2])})`
};
return (r = m[h ?? "RGB"]) == null ? void 0 : r.call(m);
}, t = (n, m) => {
var p;
isNaN(n.hsl[0]) && (n.hsl[0] = 0), isNaN(n.lch[2]) && (n.lch[2] = 0), isNaN(n.oklch[2]) && (n.oklch[2] = 0);
const r = {
RGB: () => {
var f;
return `rgb(${Math.floor(m.rgb[0])} ${Math.floor(
m.rgb[1]
)} ${Math.floor(m.rgb[2])} / ${((f = n.alpha) == null ? void 0 : f.toFixed(2)) ?? 1})`;
},
HEX: () => k(m.hex).alpha(n.alpha ?? 1).hex(),
HSL: () => {
var f;
return `hsl(${Math.floor(m.hsl[0])} ${Math.floor(
m.hsl[1] * 100
)}% ${Math.floor(m.hsl[2] * 100)}% / ${((f = n.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 = n.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 = n.alpha) == null ? void 0 : f.toFixed(2)) ?? 1})`;
}
};
return (p = r[h ?? "RGB"]) == null ? void 0 : p.call(r);
}, e = a.find(
(n) => n.type === "default theme"
);
if (e) {
const n = [];
return e.colors.forEach((m, r) => {
r > 0 && n.push(""), n.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 && n.push(
`${g}: ${p.isTransparent ? t(p, f) : s(p)};`
);
});
}), l.push(n.join(`
`)), l.join(`
`);
}
a.forEach((n) => {
const m = new $(n.name).doKebabCase(), r = [];
r.push(`// ${n.name}`), r.push(`.${m}() {`), n.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 ? t(g, u) : s(g)};`
);
});
}), r.push("}"), l.push(r.join(`
`));
});
const o = [":root {"];
a.forEach((n, m) => {
const r = new $(n.name).doKebabCase();
o.push(` &[data-theme="${r}"] {
.${r}();
}`), m !== a.length - 1 && o.push("");
}), o.push("}"), l.push(o.join(`
`));
const c = [];
return a.forEach((n) => {
const m = new $(n.name).doKebabCase();
c.push(`.${m} {
.${m}();
}`);
}), l.push(c.join(`
`)), l.join(`
`);
}, G = (i, h) => {
const a = i.themes.filter((e) => e.type === "custom theme").length === 0 ? i.themes.filter((e) => e.type === "default theme") : i.themes.filter((e) => e.type === "custom theme"), l = {}, s = (e) => {
var c;
isNaN(e.oklch[2]) && (e.oklch[2] = 0);
const o = {
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 (c = o[h ?? "RGB"]) == null ? void 0 : c.call(o);
}, t = (e, o) => {
var n;
isNaN(o.oklch[2]) && (o.oklch[2] = 0);
const c = {
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: o.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: o.alpha
})
};
return (n = c[h ?? "RGB"]) == null ? void 0 : n.call(c);
};
return a[0].type === "custom theme" ? a.forEach((e) => {
e.colors.forEach((o) => {
const c = o.shades.find(
(n) => n.type === "source color"
);
l[o.name] || (l[o.name] = {
$type: "color"
}), o.shades.forEach((n) => {
!l[o.name][n.name] && c && (l[o.name][n.name] = {
$type: "color",
$value: n.isTransparent ? t(c, n) : s(n),
$description: o.description !== "" ? o.description + " - " + n.description : n.description,
$extensions: {
mode: {}
}
}), c && (l[o.name][n.name].$extensions.mode[e.name] = n.isTransparent ? t(c, n) : s(n));
});
});
}) : a.forEach((e) => {
e.colors.forEach((o) => {
const c = o.shades.find(
(n) => n.type === "source color"
);
l[o.name] = {}, o.shades.forEach((n) => {
n && c && (l[o.name][n.name] = {
$type: "color",
$value: n.isTransparent ? t(c, n) : s(n),
$description: o.description !== "" ? o.description + " - " + n.description : n.description
});
});
});
}), JSON.stringify(l, null, " ");
}, A = (i) => {
const h = i.themes.filter((c) => c.type === "custom theme").length === 0 ? i.themes.filter((c) => c.type === "default theme") : i.themes.filter((c) => c.type === "custom theme"), a = [], l = [], s = [], t = [], e = [], o = [];
return h.forEach((c) => {
c.colors.forEach((n) => {
n.shades.forEach((m) => {
s.push(m.name), t.push(Math.floor(m.lch[0])), e.push(Math.floor(m.lch[1])), o.push(Math.floor(m.lch[2]));
}), a.push({
name: n.name,
csv: `${n.name},Lightness,Chroma,Hue
${s.map((m, r) => `${m},${t[r]},${e[r]},${o[r]}`).join(`
`)}`
}), s.splice(0, s.length), t.splice(0, t.length), e.splice(0, e.length), o.splice(0, o.length);
}), l.push({
name: c.name,
colors: a.map((n) => n),
type: c.type
}), a.splice(0, a.length);
}), l;
}, U = (i, h) => {
const a = i.themes.filter((e) => e.type === "custom theme").length === 0 ? i.themes.filter((e) => e.type === "default theme") : i.themes.filter((e) => e.type === "custom theme"), l = [], s = (e) => {
var c;
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 o = {
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 (c = o[h ?? "RGB"]) == null ? void 0 : c.call(o);
}, t = (e, o) => {
var n;
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 c = {
RGB: () => {
var m;
return `rgb(${Math.floor(o.rgb[0])} ${Math.floor(
o.rgb[1]
)} ${Math.floor(o.rgb[2])} / ${((m = e.alpha) == null ? void 0 : m.toFixed(2)) ?? 1})`;
},
HEX: () => k(o.hex).alpha(e.alpha ?? 1).hex(),
HSL: () => {
var m;
return `hsl(${Math.floor(o.hsl[0])} ${Math.floor(
o.hsl[1] * 100
)}% ${Math.floor(o.hsl[2] * 100)}% / ${((m = e.alpha) == null ? void 0 : m.toFixed(2)) ?? 1})`;
},
LCH: () => {
var m;
return `lch(${Math.floor(o.lch[0])}% ${Math.floor(
o.lch[1]
)} ${Math.floor(o.lch[2])} / ${((m = e.alpha) == null ? void 0 : m.toFixed(2)) ?? 1})`;
},
OKLCH: () => {
var m;
return `oklch(${Math.floor(o.oklch[0 * 100])}% ${o.oklch[1].toFixed(3)} ${Math.floor(o.oklch[2])} / ${((m = e.alpha) == null ? void 0 : m.toFixed(2)) ?? 1})`;
},
P3: () => {
var m;
return `color(display-p3 ${o.gl[0].toFixed(3)} ${o.gl[1].toFixed(
3
)} ${o.gl[2].toFixed(3)} / ${((m = e.alpha) == null ? void 0 : m.toFixed(2)) ?? 1})`;
}
};
return (n = c[h ?? "RGB"]) == null ? void 0 : n.call(c);
};
return a.forEach((e) => {
const o = [];
e.colors.forEach((c) => {
o.push(`/* ${c.name} */`), c.shades.reverse().forEach((n) => {
const m = c.shades.find((r) => r.type === "source color");
m && o.push(
`--${new $(c.name).doKebabCase()}-${n.name}: ${n.isTransparent ? t(n, m) : s(n)};`
);
}), o.push("");
}), o.pop(), l.push(
`${e.type === "custom theme" ? `/* ${e.name} */
` : ""}:root${e.type === "custom theme" ? `[data-theme='${new $(e.name).doKebabCase()}']` : ""} {
${o.join(`
`)}
}`
);
}), l.join(`
`);
}, O = (i) => {
const h = i.themes.filter((l) => l.type === "custom theme").length === 0 ? i.themes.filter((l) => l.type === "default theme") : i.themes.filter((l) => l.type === "custom theme"), a = [];
return h.forEach((l) => {
l.colors.forEach((s) => {
const t = s.shades.find((o) => o.type === "source color"), e = [];
e.push(
`// ${h[0].type === "custom theme" ? l.name + " - " : ""}${s.name}`
), s.shades.reverse().forEach((o) => {
e.push(
`val ${h[0].type === "custom theme" ? new $(l.name + " " + s.name).doSnakeCase() : new $(s.name).doSnakeCase()}_${o.name} = Color(${o.isTransparent ? k((t == null ? void 0 : t.hex) ?? "#000000").alpha(o.alpha ?? 1).hex().replace("#", "0xFF").toUpperCase() : o.hex.replace("#", "0xFF").toUpperCase()})`
);
}), e.push(""), e.forEach((o) => a.push(o));
});
}), 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", () => N(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", () => K(this.paletteData));
b(this, "makeTailwindV4Config", () => S(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