@multiplatform.one/theme 10.25.2 → 10.26.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/dist/cjs/theme/createThemes.cjs +41 -2
- package/dist/cjs/theme/createThemes.native.cjs +64 -2
- package/dist/cjs/theme/createThemes.native.js +64 -2
- package/dist/cjs/theme/createThemes.native.js.map +1 -1
- package/dist/esm/theme/createThemes.mjs +41 -2
- package/dist/esm/theme/createThemes.mjs.map +1 -1
- package/dist/esm/theme/createThemes.native.js +64 -2
- package/dist/esm/theme/createThemes.native.js.map +1 -1
- package/package.json +5 -5
- package/src/theme/consumerAccentFill.spec.ts +64 -0
- package/src/theme/createThemes.ts +41 -4
- package/types/theme/createThemes.d.ts.map +1 -1
|
@@ -710,6 +710,45 @@ function holdStateFill(ramp, fill, label, paper) {
|
|
|
710
710
|
].map((index) => ramp[index]).filter((step) => step !== void 0 && labelHolds(label, step));
|
|
711
711
|
return holding.find((step) => (0, import_colorRules.contrastRatio)(luminanceOf(step), paper) >= import_colorRules.minContrastRatio) ?? holding[0] ?? fill;
|
|
712
712
|
}
|
|
713
|
+
function holdConsumerAccentStates(themes) {
|
|
714
|
+
const out = { ...themes };
|
|
715
|
+
for (const scheme of ["light", "dark"]) {
|
|
716
|
+
const base = themes[scheme];
|
|
717
|
+
if (!base) continue;
|
|
718
|
+
const ramp = Array.from({ length: 12 }, (_, index) => base[`accent-${index + 1}`]);
|
|
719
|
+
const paper = luminanceOf(base["color-1"]);
|
|
720
|
+
if (!isFullRamp(ramp) || isAchromaticRamp(ramp) || paper === null) continue;
|
|
721
|
+
const scopeName = `${scheme}_accent`;
|
|
722
|
+
const scope = themes[scopeName];
|
|
723
|
+
if (!scope) continue;
|
|
724
|
+
for (const [name, theme] of Object.entries(themes)) {
|
|
725
|
+
if (name !== scopeName && !name.startsWith(`${scopeName}_`)) continue;
|
|
726
|
+
const held = { ...theme };
|
|
727
|
+
for (const state of [
|
|
728
|
+
"hover",
|
|
729
|
+
"press",
|
|
730
|
+
"focus"
|
|
731
|
+
]) {
|
|
732
|
+
const fillKey = `background-${state}`;
|
|
733
|
+
const inkKey = `color-${state}`;
|
|
734
|
+
const fill = theme[fillKey] ?? scope[fillKey] ?? theme.background ?? scope.background;
|
|
735
|
+
const label = theme[inkKey] ?? scope[inkKey] ?? theme.color ?? scope.color;
|
|
736
|
+
if (labelHolds(label, fill)) continue;
|
|
737
|
+
const pair = holdFillLabel(fill, ramp, [label], paper) ?? holdFillLabel(fill, ramp, [
|
|
738
|
+
scope.color,
|
|
739
|
+
base["color-1"],
|
|
740
|
+
base["color-12"]
|
|
741
|
+
], paper);
|
|
742
|
+
if (!pair) continue;
|
|
743
|
+
held[fillKey] = pair.fill;
|
|
744
|
+
held[inkKey] = pair.label;
|
|
745
|
+
if ((theme[`border-color-${state}`] ?? scope[`border-color-${state}`]) === fill) held[`border-color-${state}`] = pair.fill;
|
|
746
|
+
}
|
|
747
|
+
out[name] = held;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
return out;
|
|
751
|
+
}
|
|
713
752
|
function holdFillLabel(preferred, steps, labels, paper) {
|
|
714
753
|
const preferredLum = luminanceOf(preferred);
|
|
715
754
|
if (preferredLum === null) return void 0;
|
|
@@ -1188,10 +1227,10 @@ function createThemesBuilder(baseTheme, accentTheme, options, accentHue = "blue"
|
|
|
1188
1227
|
} });
|
|
1189
1228
|
return Object.fromEntries(Object.entries(raw).map(([name, theme]) => [name, { ...theme }]));
|
|
1190
1229
|
};
|
|
1191
|
-
const initialTheme = buildRawThemes({
|
|
1230
|
+
const initialTheme = holdConsumerAccentStates(buildRawThemes({
|
|
1192
1231
|
dark: accentTheme.darkPalette,
|
|
1193
1232
|
light: accentTheme.lightPalette
|
|
1194
|
-
});
|
|
1233
|
+
}));
|
|
1195
1234
|
const scrimAlphas = {
|
|
1196
1235
|
light: baseTheme.lightScrims ?? import_base.defaultBaseTheme.lightScrims,
|
|
1197
1236
|
dark: baseTheme.darkScrims ?? import_base.defaultBaseTheme.darkScrims
|
|
@@ -1205,6 +1205,68 @@ function holdStateFill(ramp, fill, label, paper) {
|
|
|
1205
1205
|
return (0, import_colorRules.contrastRatio)(luminanceOf(step), paper) >= import_colorRules.minContrastRatio;
|
|
1206
1206
|
})) !== null && _holding_find !== void 0 ? _holding_find : holding[0]) !== null && _ref !== void 0 ? _ref : fill;
|
|
1207
1207
|
}
|
|
1208
|
+
function holdConsumerAccentStates(themes) {
|
|
1209
|
+
var _loop = function(_i2, _iter2) {
|
|
1210
|
+
var scheme = _iter2[_i2];
|
|
1211
|
+
var base = themes[scheme];
|
|
1212
|
+
if (!base) return "continue";
|
|
1213
|
+
var ramp = Array.from({ length: 12 }, function(_, index) {
|
|
1214
|
+
return base[`accent-${index + 1}`];
|
|
1215
|
+
});
|
|
1216
|
+
var paper = luminanceOf(base["color-1"]);
|
|
1217
|
+
if (!isFullRamp(ramp) || isAchromaticRamp(ramp) || paper === null) return "continue";
|
|
1218
|
+
var scopeName = `${scheme}_accent`;
|
|
1219
|
+
var scope = themes[scopeName];
|
|
1220
|
+
if (!scope) return "continue";
|
|
1221
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
1222
|
+
try {
|
|
1223
|
+
for (var _iterator = Object.entries(themes)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
1224
|
+
var [name, theme] = _step.value;
|
|
1225
|
+
if (name !== scopeName && !name.startsWith(`${scopeName}_`)) continue;
|
|
1226
|
+
var held = { ...theme };
|
|
1227
|
+
for (var _i1 = 0, _iter1 = [
|
|
1228
|
+
"hover",
|
|
1229
|
+
"press",
|
|
1230
|
+
"focus"
|
|
1231
|
+
]; _i1 < _iter1.length; _i1++) {
|
|
1232
|
+
var state = _iter1[_i1];
|
|
1233
|
+
var _ref, _ref1, _theme_fillKey, _ref2, _ref3, _theme_inkKey, _holdFillLabel, _theme_;
|
|
1234
|
+
var fillKey = `background-${state}`;
|
|
1235
|
+
var inkKey = `color-${state}`;
|
|
1236
|
+
var fill = (_ref = (_ref1 = (_theme_fillKey = theme[fillKey]) !== null && _theme_fillKey !== void 0 ? _theme_fillKey : scope[fillKey]) !== null && _ref1 !== void 0 ? _ref1 : theme.background) !== null && _ref !== void 0 ? _ref : scope.background;
|
|
1237
|
+
var label = (_ref2 = (_ref3 = (_theme_inkKey = theme[inkKey]) !== null && _theme_inkKey !== void 0 ? _theme_inkKey : scope[inkKey]) !== null && _ref3 !== void 0 ? _ref3 : theme.color) !== null && _ref2 !== void 0 ? _ref2 : scope.color;
|
|
1238
|
+
if (labelHolds(label, fill)) continue;
|
|
1239
|
+
var pair = (_holdFillLabel = holdFillLabel(fill, ramp, [label], paper)) !== null && _holdFillLabel !== void 0 ? _holdFillLabel : holdFillLabel(fill, ramp, [
|
|
1240
|
+
scope.color,
|
|
1241
|
+
base["color-1"],
|
|
1242
|
+
base["color-12"]
|
|
1243
|
+
], paper);
|
|
1244
|
+
if (!pair) continue;
|
|
1245
|
+
held[fillKey] = pair.fill;
|
|
1246
|
+
held[inkKey] = pair.label;
|
|
1247
|
+
if (((_theme_ = theme[`border-color-${state}`]) !== null && _theme_ !== void 0 ? _theme_ : scope[`border-color-${state}`]) === fill) held[`border-color-${state}`] = pair.fill;
|
|
1248
|
+
}
|
|
1249
|
+
out[name] = held;
|
|
1250
|
+
}
|
|
1251
|
+
} catch (err) {
|
|
1252
|
+
_didIteratorError = true;
|
|
1253
|
+
_iteratorError = err;
|
|
1254
|
+
} finally {
|
|
1255
|
+
try {
|
|
1256
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1257
|
+
_iterator.return();
|
|
1258
|
+
}
|
|
1259
|
+
} finally {
|
|
1260
|
+
if (_didIteratorError) {
|
|
1261
|
+
throw _iteratorError;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1266
|
+
var out = { ...themes };
|
|
1267
|
+
for (var _i = 0, _iter = ["light", "dark"]; _i < _iter.length; _i++) _loop(_i, _iter);
|
|
1268
|
+
return out;
|
|
1269
|
+
}
|
|
1208
1270
|
function holdFillLabel(preferred, steps, labels, paper) {
|
|
1209
1271
|
var preferredLum = luminanceOf(preferred);
|
|
1210
1272
|
if (preferredLum === null) return void 0;
|
|
@@ -1935,10 +1997,10 @@ function createThemesBuilder(baseTheme, accentTheme, options) {
|
|
|
1935
1997
|
return [name2, { ...theme }];
|
|
1936
1998
|
}));
|
|
1937
1999
|
};
|
|
1938
|
-
var initialTheme = buildRawThemes({
|
|
2000
|
+
var initialTheme = holdConsumerAccentStates(buildRawThemes({
|
|
1939
2001
|
dark: accentTheme.darkPalette,
|
|
1940
2002
|
light: accentTheme.lightPalette
|
|
1941
|
-
});
|
|
2003
|
+
}));
|
|
1942
2004
|
var scrimAlphas = {
|
|
1943
2005
|
light: (_baseTheme_lightScrims = baseTheme.lightScrims) !== null && _baseTheme_lightScrims !== void 0 ? _baseTheme_lightScrims : import_base.defaultBaseTheme.lightScrims,
|
|
1944
2006
|
dark: (_baseTheme_darkScrims = baseTheme.darkScrims) !== null && _baseTheme_darkScrims !== void 0 ? _baseTheme_darkScrims : import_base.defaultBaseTheme.darkScrims
|
|
@@ -1205,6 +1205,68 @@ function holdStateFill(ramp, fill, label, paper) {
|
|
|
1205
1205
|
return (0, import_colorRules.contrastRatio)(luminanceOf(step), paper) >= import_colorRules.minContrastRatio;
|
|
1206
1206
|
})) !== null && _holding_find !== void 0 ? _holding_find : holding[0]) !== null && _ref !== void 0 ? _ref : fill;
|
|
1207
1207
|
}
|
|
1208
|
+
function holdConsumerAccentStates(themes) {
|
|
1209
|
+
var _loop = function(_i2, _iter2) {
|
|
1210
|
+
var scheme = _iter2[_i2];
|
|
1211
|
+
var base = themes[scheme];
|
|
1212
|
+
if (!base) return "continue";
|
|
1213
|
+
var ramp = Array.from({ length: 12 }, function(_, index) {
|
|
1214
|
+
return base[`accent-${index + 1}`];
|
|
1215
|
+
});
|
|
1216
|
+
var paper = luminanceOf(base["color-1"]);
|
|
1217
|
+
if (!isFullRamp(ramp) || isAchromaticRamp(ramp) || paper === null) return "continue";
|
|
1218
|
+
var scopeName = `${scheme}_accent`;
|
|
1219
|
+
var scope = themes[scopeName];
|
|
1220
|
+
if (!scope) return "continue";
|
|
1221
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
1222
|
+
try {
|
|
1223
|
+
for (var _iterator = Object.entries(themes)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
1224
|
+
var [name, theme] = _step.value;
|
|
1225
|
+
if (name !== scopeName && !name.startsWith(`${scopeName}_`)) continue;
|
|
1226
|
+
var held = { ...theme };
|
|
1227
|
+
for (var _i1 = 0, _iter1 = [
|
|
1228
|
+
"hover",
|
|
1229
|
+
"press",
|
|
1230
|
+
"focus"
|
|
1231
|
+
]; _i1 < _iter1.length; _i1++) {
|
|
1232
|
+
var state = _iter1[_i1];
|
|
1233
|
+
var _ref, _ref1, _theme_fillKey, _ref2, _ref3, _theme_inkKey, _holdFillLabel, _theme_;
|
|
1234
|
+
var fillKey = `background-${state}`;
|
|
1235
|
+
var inkKey = `color-${state}`;
|
|
1236
|
+
var fill = (_ref = (_ref1 = (_theme_fillKey = theme[fillKey]) !== null && _theme_fillKey !== void 0 ? _theme_fillKey : scope[fillKey]) !== null && _ref1 !== void 0 ? _ref1 : theme.background) !== null && _ref !== void 0 ? _ref : scope.background;
|
|
1237
|
+
var label = (_ref2 = (_ref3 = (_theme_inkKey = theme[inkKey]) !== null && _theme_inkKey !== void 0 ? _theme_inkKey : scope[inkKey]) !== null && _ref3 !== void 0 ? _ref3 : theme.color) !== null && _ref2 !== void 0 ? _ref2 : scope.color;
|
|
1238
|
+
if (labelHolds(label, fill)) continue;
|
|
1239
|
+
var pair = (_holdFillLabel = holdFillLabel(fill, ramp, [label], paper)) !== null && _holdFillLabel !== void 0 ? _holdFillLabel : holdFillLabel(fill, ramp, [
|
|
1240
|
+
scope.color,
|
|
1241
|
+
base["color-1"],
|
|
1242
|
+
base["color-12"]
|
|
1243
|
+
], paper);
|
|
1244
|
+
if (!pair) continue;
|
|
1245
|
+
held[fillKey] = pair.fill;
|
|
1246
|
+
held[inkKey] = pair.label;
|
|
1247
|
+
if (((_theme_ = theme[`border-color-${state}`]) !== null && _theme_ !== void 0 ? _theme_ : scope[`border-color-${state}`]) === fill) held[`border-color-${state}`] = pair.fill;
|
|
1248
|
+
}
|
|
1249
|
+
out[name] = held;
|
|
1250
|
+
}
|
|
1251
|
+
} catch (err) {
|
|
1252
|
+
_didIteratorError = true;
|
|
1253
|
+
_iteratorError = err;
|
|
1254
|
+
} finally {
|
|
1255
|
+
try {
|
|
1256
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1257
|
+
_iterator.return();
|
|
1258
|
+
}
|
|
1259
|
+
} finally {
|
|
1260
|
+
if (_didIteratorError) {
|
|
1261
|
+
throw _iteratorError;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1266
|
+
var out = { ...themes };
|
|
1267
|
+
for (var _i = 0, _iter = ["light", "dark"]; _i < _iter.length; _i++) _loop(_i, _iter);
|
|
1268
|
+
return out;
|
|
1269
|
+
}
|
|
1208
1270
|
function holdFillLabel(preferred, steps, labels, paper) {
|
|
1209
1271
|
var preferredLum = luminanceOf(preferred);
|
|
1210
1272
|
if (preferredLum === null) return void 0;
|
|
@@ -1935,10 +1997,10 @@ function createThemesBuilder(baseTheme, accentTheme, options) {
|
|
|
1935
1997
|
return [name2, { ...theme }];
|
|
1936
1998
|
}));
|
|
1937
1999
|
};
|
|
1938
|
-
var initialTheme = buildRawThemes({
|
|
2000
|
+
var initialTheme = holdConsumerAccentStates(buildRawThemes({
|
|
1939
2001
|
dark: accentTheme.darkPalette,
|
|
1940
2002
|
light: accentTheme.lightPalette
|
|
1941
|
-
});
|
|
2003
|
+
}));
|
|
1942
2004
|
var scrimAlphas = {
|
|
1943
2005
|
light: (_baseTheme_lightScrims = baseTheme.lightScrims) !== null && _baseTheme_lightScrims !== void 0 ? _baseTheme_lightScrims : import_base.defaultBaseTheme.lightScrims,
|
|
1944
2006
|
dark: (_baseTheme_darkScrims = baseTheme.darkScrims) !== null && _baseTheme_darkScrims !== void 0 ? _baseTheme_darkScrims : import_base.defaultBaseTheme.darkScrims
|