hextimator 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +105 -33
- package/dist/{HextimatePaletteBuilder-BOuHKcVE.d.mts → HextimatePaletteBuilder-xqJwP_G2.d.ts} +42 -26
- package/dist/{chunk-MBVLFPTG.js → chunk-2OMHLWID.js} +183 -88
- package/dist/cli.js +220 -120
- package/dist/index.d.ts +23 -26
- package/dist/index.js +1 -1
- package/dist/react.d.ts +195 -62
- package/dist/react.js +309 -88
- package/fallback.css +74 -0
- package/llms.txt +113 -21
- package/package.json +8 -3
- package/dist/HextimatePaletteBuilder-BOuHKcVE.d.ts +0 -540
- package/dist/index.d.mts +0 -168
- package/dist/react.d.mts +0 -132
|
@@ -841,11 +841,15 @@ function isColorObject(input) {
|
|
|
841
841
|
function buildTokenEntries(palette, options) {
|
|
842
842
|
const colorFormat = options?.colors ?? "hex";
|
|
843
843
|
const entries = [];
|
|
844
|
+
const excludeRoles = new Set(options?.excludeRoles ?? []);
|
|
845
|
+
const excludeVariants = new Set(options?.excludeVariants ?? []);
|
|
844
846
|
const roles = Object.keys(palette);
|
|
845
847
|
for (const role of roles) {
|
|
848
|
+
if (excludeRoles.has(role)) continue;
|
|
846
849
|
const scale = palette[role];
|
|
847
850
|
const variants = Object.keys(scale);
|
|
848
851
|
for (const variant of variants) {
|
|
852
|
+
if (excludeVariants.has(variant)) continue;
|
|
849
853
|
const raw = scale[variant];
|
|
850
854
|
if (!isColorObject(raw)) continue;
|
|
851
855
|
entries.push({
|
|
@@ -1358,6 +1362,27 @@ function generate(color, themeType, options) {
|
|
|
1358
1362
|
}
|
|
1359
1363
|
|
|
1360
1364
|
// src/HextimatePaletteBuilder.ts
|
|
1365
|
+
var NESTED_GEN_KEYS = /* @__PURE__ */ new Set([
|
|
1366
|
+
"light",
|
|
1367
|
+
"dark",
|
|
1368
|
+
"semanticColors",
|
|
1369
|
+
"semanticColorRanges"
|
|
1370
|
+
]);
|
|
1371
|
+
function mergeStyleOptions(...sources) {
|
|
1372
|
+
const result = {};
|
|
1373
|
+
for (const source of sources) {
|
|
1374
|
+
if (!source) continue;
|
|
1375
|
+
for (const [key, value] of Object.entries(source)) {
|
|
1376
|
+
if (value === void 0) continue;
|
|
1377
|
+
if (NESTED_GEN_KEYS.has(key) && typeof value === "object" && value !== null) {
|
|
1378
|
+
result[key] = { ...result[key], ...value };
|
|
1379
|
+
} else {
|
|
1380
|
+
result[key] = value;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
return result;
|
|
1385
|
+
}
|
|
1361
1386
|
var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
1362
1387
|
lightPalette;
|
|
1363
1388
|
darkPalette;
|
|
@@ -1369,18 +1394,95 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1369
1394
|
strongSideVariants = ["strong"];
|
|
1370
1395
|
betweenVariants = [];
|
|
1371
1396
|
presetFormatDefaults;
|
|
1372
|
-
constructor(color
|
|
1397
|
+
constructor(color) {
|
|
1373
1398
|
this.inputColor = color;
|
|
1374
|
-
this.options =
|
|
1375
|
-
this.
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1399
|
+
this.options = {};
|
|
1400
|
+
this.seedOptionsForFork({});
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Merges style options into the builder and regenerates the base palettes,
|
|
1404
|
+
* then replays recorded operations so roles and variants reflect the new style.
|
|
1405
|
+
*/
|
|
1406
|
+
style(partial) {
|
|
1407
|
+
this.operations.push({ method: "style", args: [partial] });
|
|
1408
|
+
this.options = mergeStyleOptions(this.options, partial);
|
|
1409
|
+
this.rebuildFromOperations();
|
|
1410
|
+
return this;
|
|
1411
|
+
}
|
|
1412
|
+
seedOptionsForFork(seededOptions) {
|
|
1413
|
+
this.options = { ...seededOptions };
|
|
1414
|
+
this.lightPalette = generate(
|
|
1415
|
+
this.inputColor,
|
|
1416
|
+
"light",
|
|
1417
|
+
this.resolvedOptions()
|
|
1418
|
+
);
|
|
1419
|
+
this.darkPalette = generate(
|
|
1420
|
+
this.inputColor,
|
|
1421
|
+
"dark",
|
|
1422
|
+
this.resolvedOptions()
|
|
1423
|
+
);
|
|
1424
|
+
this.standaloneTokens.length = 0;
|
|
1425
|
+
this.weakSideVariants.length = 0;
|
|
1426
|
+
this.weakSideVariants.push("weak");
|
|
1427
|
+
this.strongSideVariants.length = 0;
|
|
1428
|
+
this.strongSideVariants.push("strong");
|
|
1429
|
+
this.betweenVariants.length = 0;
|
|
1430
|
+
this.presetFormatDefaults = void 0;
|
|
1431
|
+
this.applyToken("brand-exact", this.inputColor);
|
|
1432
|
+
const colorOKLCH = convert(this.inputColor, "oklch");
|
|
1379
1433
|
const lightFg = { ...colorOKLCH, l: 0.97, c: Math.min(colorOKLCH.c, 0.01) };
|
|
1380
1434
|
const darkFg = { ...colorOKLCH, l: 0.1, c: Math.min(colorOKLCH.c, 0.01) };
|
|
1381
|
-
const brandForeground = calculateContrast(
|
|
1435
|
+
const brandForeground = calculateContrast(this.inputColor, lightFg) >= calculateContrast(this.inputColor, darkFg) ? lightFg : darkFg;
|
|
1382
1436
|
this.applyToken("brand-exact-foreground", brandForeground);
|
|
1383
1437
|
}
|
|
1438
|
+
rebuildFromOperations() {
|
|
1439
|
+
this.seedOptionsForFork(this.options);
|
|
1440
|
+
for (const op of this.operations) {
|
|
1441
|
+
this.replayOperationInPlace(op);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
replayOperationInPlace(op) {
|
|
1445
|
+
switch (op.method) {
|
|
1446
|
+
case "style":
|
|
1447
|
+
return;
|
|
1448
|
+
case "addRole":
|
|
1449
|
+
this.applyRole(...op.args);
|
|
1450
|
+
return;
|
|
1451
|
+
case "addVariant":
|
|
1452
|
+
this.applyVariant(...op.args);
|
|
1453
|
+
return;
|
|
1454
|
+
case "addToken":
|
|
1455
|
+
this.applyToken(...op.args);
|
|
1456
|
+
return;
|
|
1457
|
+
case "simulate":
|
|
1458
|
+
this.lightPalette = simulatePalette(
|
|
1459
|
+
this.lightPalette,
|
|
1460
|
+
op.args[0],
|
|
1461
|
+
op.args[1]
|
|
1462
|
+
);
|
|
1463
|
+
this.darkPalette = simulatePalette(
|
|
1464
|
+
this.darkPalette,
|
|
1465
|
+
op.args[0],
|
|
1466
|
+
op.args[1]
|
|
1467
|
+
);
|
|
1468
|
+
return;
|
|
1469
|
+
case "adaptFor":
|
|
1470
|
+
this.lightPalette = adaptPalette(
|
|
1471
|
+
this.lightPalette,
|
|
1472
|
+
op.args[0],
|
|
1473
|
+
op.args[1]
|
|
1474
|
+
);
|
|
1475
|
+
this.darkPalette = adaptPalette(
|
|
1476
|
+
this.darkPalette,
|
|
1477
|
+
op.args[0],
|
|
1478
|
+
op.args[1]
|
|
1479
|
+
);
|
|
1480
|
+
return;
|
|
1481
|
+
case "preset":
|
|
1482
|
+
this.applyPresetRolesTokensFormat(op.args[0]);
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1384
1486
|
/**
|
|
1385
1487
|
* Adds a custom role with given name and color.
|
|
1386
1488
|
* The color is expanded into a full scale and added to both light and dark palettes.
|
|
@@ -1451,9 +1553,8 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1451
1553
|
*/
|
|
1452
1554
|
preset(preset) {
|
|
1453
1555
|
this.operations.push({ method: "preset", args: [preset] });
|
|
1454
|
-
if (preset.
|
|
1455
|
-
|
|
1456
|
-
Object.assign(this.options, preset.generation, userOptions);
|
|
1556
|
+
if (preset.style) {
|
|
1557
|
+
this.options = mergeStyleOptions(this.options, preset.style);
|
|
1457
1558
|
this.lightPalette = generate(
|
|
1458
1559
|
this.inputColor,
|
|
1459
1560
|
"light",
|
|
@@ -1465,6 +1566,19 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1465
1566
|
this.resolvedOptions()
|
|
1466
1567
|
);
|
|
1467
1568
|
}
|
|
1569
|
+
this.applyPresetRolesTokensFormat(preset);
|
|
1570
|
+
return this;
|
|
1571
|
+
}
|
|
1572
|
+
/**
|
|
1573
|
+
* Records a preset in the operation log and applies roles, variants, tokens, and format.
|
|
1574
|
+
* Does not merge `preset.style` — used when replaying onto a builder whose `this.options` already reflect merged style.
|
|
1575
|
+
*/
|
|
1576
|
+
recordPresetWithoutStyleMerge(preset) {
|
|
1577
|
+
this.operations.push({ method: "preset", args: [preset] });
|
|
1578
|
+
this.applyPresetRolesTokensFormat(preset);
|
|
1579
|
+
}
|
|
1580
|
+
/** Roles, variants, tokens, and format only — `this.options` and base palettes are already correct. */
|
|
1581
|
+
applyPresetRolesTokensFormat(preset) {
|
|
1468
1582
|
for (const role of preset.roles ?? []) {
|
|
1469
1583
|
this.applyRole(role.name, role.color);
|
|
1470
1584
|
}
|
|
@@ -1488,7 +1602,6 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1488
1602
|
}
|
|
1489
1603
|
};
|
|
1490
1604
|
}
|
|
1491
|
-
return this;
|
|
1492
1605
|
}
|
|
1493
1606
|
/**
|
|
1494
1607
|
*
|
|
@@ -1533,42 +1646,19 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1533
1646
|
return this;
|
|
1534
1647
|
}
|
|
1535
1648
|
/**
|
|
1536
|
-
* Creates a new builder instance with the same operations history,
|
|
1537
|
-
*
|
|
1538
|
-
* e.g. `fork('#ff6677')` creates a new builder with the same
|
|
1539
|
-
* roles, variants, tokens, and adjustments, but based on a different input color.
|
|
1540
|
-
*
|
|
1541
|
-
* `fork({ light: { lightness: 0.8 } })` creates a new builder with the same color but different light theme adjustments.
|
|
1649
|
+
* Creates a new builder instance with the same operations history, optionally from a different base color.
|
|
1650
|
+
* To change style options on the fork, chain `.style()` after `.fork()`.
|
|
1542
1651
|
*
|
|
1543
|
-
* @param
|
|
1544
|
-
* @param maybeOptions If the first argument is a color, this can be an optional second argument with generation options to override.
|
|
1545
|
-
* @returns A new builder instance with the same operations history but different base color and/or options.
|
|
1652
|
+
* @param color Optional new accent/brand color. If omitted, the fork uses the same color as this builder.
|
|
1546
1653
|
*/
|
|
1547
|
-
fork(
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
newColor = parse(colorOrOptions);
|
|
1552
|
-
newOptions = {
|
|
1553
|
-
...this.options,
|
|
1554
|
-
...maybeOptions
|
|
1555
|
-
};
|
|
1556
|
-
} else if (colorOrOptions !== void 0 && typeof colorOrOptions === "object" && !Array.isArray(colorOrOptions) && !("space" in colorOrOptions)) {
|
|
1557
|
-
newColor = this.inputColor;
|
|
1558
|
-
newOptions = {
|
|
1559
|
-
...this.options,
|
|
1560
|
-
...colorOrOptions
|
|
1561
|
-
};
|
|
1562
|
-
} else if (colorOrOptions !== void 0) {
|
|
1563
|
-
newColor = parse(colorOrOptions);
|
|
1564
|
-
newOptions = { ...this.options };
|
|
1565
|
-
} else {
|
|
1566
|
-
newColor = this.inputColor;
|
|
1567
|
-
newOptions = { ...this.options };
|
|
1568
|
-
}
|
|
1569
|
-
const builder = new _HextimatePaletteBuilder(newColor, newOptions);
|
|
1654
|
+
fork(color) {
|
|
1655
|
+
const newColor = color !== void 0 ? parse(color) : this.inputColor;
|
|
1656
|
+
const builder = new _HextimatePaletteBuilder(newColor);
|
|
1657
|
+
builder.seedOptionsForFork({ ...this.options });
|
|
1570
1658
|
for (const op of this.operations) {
|
|
1571
1659
|
switch (op.method) {
|
|
1660
|
+
case "style":
|
|
1661
|
+
break;
|
|
1572
1662
|
case "addRole":
|
|
1573
1663
|
builder.addRole(...op.args);
|
|
1574
1664
|
break;
|
|
@@ -1585,7 +1675,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1585
1675
|
builder.adaptFor(...op.args);
|
|
1586
1676
|
break;
|
|
1587
1677
|
case "preset":
|
|
1588
|
-
builder.
|
|
1678
|
+
builder.recordPresetWithoutStyleMerge(op.args[0]);
|
|
1589
1679
|
break;
|
|
1590
1680
|
}
|
|
1591
1681
|
}
|
|
@@ -1947,49 +2037,21 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1947
2037
|
// src/presets/index.ts
|
|
1948
2038
|
var presets_exports = {};
|
|
1949
2039
|
__export(presets_exports, {
|
|
1950
|
-
|
|
2040
|
+
bold: () => bold,
|
|
1951
2041
|
mui: () => mui,
|
|
1952
|
-
|
|
2042
|
+
muted: () => muted,
|
|
2043
|
+
shadcn: () => shadcn,
|
|
2044
|
+
tinted: () => tinted,
|
|
2045
|
+
vibrant: () => vibrant
|
|
1953
2046
|
});
|
|
1954
2047
|
|
|
1955
|
-
// src/presets/
|
|
1956
|
-
var
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
baseMaxChroma: 0.
|
|
1961
|
-
|
|
1962
|
-
light: { lightness: 0.55, maxChroma: 0.14 },
|
|
1963
|
-
dark: { lightness: 0.35, maxChroma: 0.12 }
|
|
1964
|
-
},
|
|
1965
|
-
roles: [
|
|
1966
|
-
{ name: "cta", color: "#ff006e" },
|
|
1967
|
-
{ name: "info", color: "#3a86ff" }
|
|
1968
|
-
],
|
|
1969
|
-
variants: [
|
|
1970
|
-
{ name: "muted", placement: { from: "weak" } },
|
|
1971
|
-
{ name: "vivid", placement: { from: "strong" } }
|
|
1972
|
-
],
|
|
1973
|
-
tokens: [
|
|
1974
|
-
{ name: "surface", value: { from: "base.weak" } },
|
|
1975
|
-
{ name: "surface-raised", value: { from: "base", emphasis: -0.04 } },
|
|
1976
|
-
{ name: "border", value: { from: "base", emphasis: 0.1 } },
|
|
1977
|
-
{ name: "border-subtle", value: { from: "base", emphasis: 0.05 } },
|
|
1978
|
-
{ name: "ring", value: { from: "accent" } },
|
|
1979
|
-
{ name: "cta-ring", value: { from: "cta", chroma: -0.05 } }
|
|
1980
|
-
],
|
|
1981
|
-
format: {
|
|
1982
|
-
as: "css",
|
|
1983
|
-
colors: "hex",
|
|
1984
|
-
roleNames: {
|
|
1985
|
-
base: "bg",
|
|
1986
|
-
accent: "brand",
|
|
1987
|
-
positive: "success",
|
|
1988
|
-
negative: "danger"
|
|
1989
|
-
},
|
|
1990
|
-
variantNames: {
|
|
1991
|
-
foreground: "text"
|
|
1992
|
-
}
|
|
2048
|
+
// src/presets/bold.ts
|
|
2049
|
+
var bold = {
|
|
2050
|
+
style: {
|
|
2051
|
+
light: { lightness: 0.5 },
|
|
2052
|
+
dark: { lightness: 0.8 },
|
|
2053
|
+
baseMaxChroma: 0.06,
|
|
2054
|
+
foregroundMaxChroma: 0.02
|
|
1993
2055
|
}
|
|
1994
2056
|
};
|
|
1995
2057
|
|
|
@@ -2042,7 +2104,18 @@ var mui = {
|
|
|
2042
2104
|
weak: "light",
|
|
2043
2105
|
strong: "dark",
|
|
2044
2106
|
foreground: "contrastText"
|
|
2045
|
-
}
|
|
2107
|
+
},
|
|
2108
|
+
excludeRoles: ["base"]
|
|
2109
|
+
}
|
|
2110
|
+
};
|
|
2111
|
+
|
|
2112
|
+
// src/presets/muted.ts
|
|
2113
|
+
var muted = {
|
|
2114
|
+
style: {
|
|
2115
|
+
light: { maxChroma: 0.08 },
|
|
2116
|
+
dark: { maxChroma: 0.07 },
|
|
2117
|
+
baseMaxChroma: 5e-3,
|
|
2118
|
+
foregroundMaxChroma: 5e-3
|
|
2046
2119
|
}
|
|
2047
2120
|
};
|
|
2048
2121
|
|
|
@@ -2103,7 +2176,29 @@ var shadcn = {
|
|
|
2103
2176
|
},
|
|
2104
2177
|
variantNames: {
|
|
2105
2178
|
foreground: "foreground"
|
|
2106
|
-
}
|
|
2179
|
+
},
|
|
2180
|
+
excludeRoles: ["warning"],
|
|
2181
|
+
excludeVariants: ["strong", "weak"]
|
|
2182
|
+
}
|
|
2183
|
+
};
|
|
2184
|
+
|
|
2185
|
+
// src/presets/tinted.ts
|
|
2186
|
+
var tinted = {
|
|
2187
|
+
style: {
|
|
2188
|
+
baseMaxChroma: 0.05,
|
|
2189
|
+
baseHueShift: 0,
|
|
2190
|
+
foregroundMaxChroma: 0.015
|
|
2191
|
+
}
|
|
2192
|
+
};
|
|
2193
|
+
|
|
2194
|
+
// src/presets/vibrant.ts
|
|
2195
|
+
var vibrant = {
|
|
2196
|
+
style: {
|
|
2197
|
+
light: { maxChroma: 0.2, lightness: 0.6 },
|
|
2198
|
+
dark: { maxChroma: 0.18, lightness: 0.65 },
|
|
2199
|
+
hueShift: 5,
|
|
2200
|
+
baseHueShift: 180,
|
|
2201
|
+
baseMaxChroma: 0.08
|
|
2107
2202
|
}
|
|
2108
2203
|
};
|
|
2109
2204
|
|
|
@@ -2115,10 +2210,10 @@ var HextimateError = class extends Error {
|
|
|
2115
2210
|
this.name = "HextimateError";
|
|
2116
2211
|
}
|
|
2117
2212
|
};
|
|
2118
|
-
function hextimate(color
|
|
2213
|
+
function hextimate(color) {
|
|
2119
2214
|
try {
|
|
2120
2215
|
const parsedColor = parse(color);
|
|
2121
|
-
return new HextimatePaletteBuilder(parsedColor
|
|
2216
|
+
return new HextimatePaletteBuilder(parsedColor);
|
|
2122
2217
|
} catch (e) {
|
|
2123
2218
|
if (e instanceof HextimateError) {
|
|
2124
2219
|
throw e;
|