@studious-creative/yumekit 0.1.9 → 0.1.10

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/index.js CHANGED
@@ -59,6 +59,52 @@ var collapseLeft$1 = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24
59
59
 
60
60
  var comments = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z\"/>\n</svg>\n";
61
61
 
62
+ var compAppbar = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"2\" y=\"3\" width=\"20\" height=\"5\" rx=\"1.5\"/>\n <line x1=\"4\" y1=\"13\" x2=\"20\" y2=\"13\"/>\n <line x1=\"4\" y1=\"17\" x2=\"15\" y2=\"17\"/>\n <line x1=\"4\" y1=\"21\" x2=\"10\" y2=\"21\"/>\n</svg>\n";
63
+
64
+ var compAvatar = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\"/>\n <circle cx=\"12\" cy=\"10\" r=\"3\"/>\n <path d=\"M6 20.5c0-3 2.7-5.5 6-5.5s6 2.5 6 5.5\"/>\n</svg>\n";
65
+
66
+ var compBadge = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"2\" y=\"6\" width=\"16\" height=\"16\" rx=\"2\"/>\n <circle cx=\"20\" cy=\"5\" r=\"3.5\"/>\n</svg>\n";
67
+
68
+ var compButton = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"2\" y=\"7\" width=\"20\" height=\"10\" rx=\"3\"/>\n <line x1=\"8\" y1=\"12\" x2=\"16\" y2=\"12\"/>\n</svg>\n";
69
+
70
+ var compCard = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"3\" y=\"2\" width=\"18\" height=\"20\" rx=\"2\"/>\n <line x1=\"3\" y1=\"8\" x2=\"21\" y2=\"8\"/>\n <line x1=\"7\" y1=\"12\" x2=\"17\" y2=\"12\"/>\n <line x1=\"7\" y1=\"16\" x2=\"13\" y2=\"16\"/>\n</svg>\n";
71
+
72
+ var compCheckbox = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"3\"/>\n <polyline points=\"7 12.5 10.5 16 17 8\"/>\n</svg>\n";
73
+
74
+ var compDialog = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"3\" y=\"5\" width=\"18\" height=\"14\" rx=\"2\"/>\n <line x1=\"7\" y1=\"9\" x2=\"17\" y2=\"9\"/>\n <line x1=\"7\" y1=\"13\" x2=\"13\" y2=\"13\"/>\n</svg>\n";
75
+
76
+ var compDrawer = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"2\" y=\"3\" width=\"20\" height=\"18\" rx=\"2\"/>\n <line x1=\"9\" y1=\"3\" x2=\"9\" y2=\"21\"/>\n <line x1=\"4\" y1=\"8\" x2=\"7\" y2=\"8\"/>\n <line x1=\"4\" y1=\"12\" x2=\"7\" y2=\"12\"/>\n</svg>\n";
77
+
78
+ var compIcon = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M12 2c0 5.52-4.48 10-10 10 5.52 0 10 4.48 10 10 0-5.52 4.48-10 10-10-5.52 0-10-4.48-10-10z\"/>\n</svg>\n";
79
+
80
+ var compInput = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"2\" y=\"6\" width=\"20\" height=\"12\" rx=\"2\"/>\n <line x1=\"6\" y1=\"10\" x2=\"6\" y2=\"14\"/>\n</svg>\n";
81
+
82
+ var compMenu = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"3\" y=\"2\" width=\"18\" height=\"20\" rx=\"2\"/>\n <line x1=\"7\" y1=\"7\" x2=\"17\" y2=\"7\"/>\n <line x1=\"7\" y1=\"12\" x2=\"17\" y2=\"12\"/>\n <line x1=\"7\" y1=\"17\" x2=\"17\" y2=\"17\"/>\n</svg>\n";
83
+
84
+ var compPanelbar = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"2\" y=\"2\" width=\"20\" height=\"20\" rx=\"2\"/>\n <line x1=\"2\" y1=\"9\" x2=\"22\" y2=\"9\"/>\n <line x1=\"2\" y1=\"16\" x2=\"22\" y2=\"16\"/>\n</svg>\n";
85
+
86
+ var compProgress = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"2\" y=\"8\" width=\"20\" height=\"8\" rx=\"4\"/>\n <line x1=\"6\" y1=\"12\" x2=\"13\" y2=\"12\" stroke-width=\"3\" stroke-linecap=\"round\"/>\n</svg>\n";
87
+
88
+ var compRadio = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\"/>\n <circle cx=\"12\" cy=\"12\" r=\"4\" fill=\"currentColor\" stroke=\"none\"/>\n</svg>\n";
89
+
90
+ var compSelect = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"2\" y=\"7\" width=\"20\" height=\"10\" rx=\"2\"/>\n <line x1=\"6\" y1=\"12\" x2=\"13\" y2=\"12\"/>\n <polyline points=\"16 10 18 13 20 10\"/>\n</svg>\n";
91
+
92
+ var compSlider = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <line x1=\"2\" y1=\"12\" x2=\"22\" y2=\"12\"/>\n <circle cx=\"15\" cy=\"12\" r=\"4\"/>\n</svg>\n";
93
+
94
+ var compSwitch = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"2\" y=\"6\" width=\"20\" height=\"12\" rx=\"6\"/>\n <circle cx=\"16\" cy=\"12\" r=\"4\"/>\n</svg>\n";
95
+
96
+ var compTable = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"2\" y=\"3\" width=\"20\" height=\"18\" rx=\"2\"/>\n <line x1=\"2\" y1=\"9\" x2=\"22\" y2=\"9\"/>\n <line x1=\"2\" y1=\"15\" x2=\"22\" y2=\"15\"/>\n <line x1=\"10\" y1=\"3\" x2=\"10\" y2=\"21\"/>\n</svg>\n";
97
+
98
+ var compTabs = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"2\" y=\"9\" width=\"20\" height=\"12\" rx=\"2\"/>\n <path d=\"M5 9V6a1.5 1.5 0 0 1 1.5-1.5h5A1.5 1.5 0 0 1 13 6v3\"/>\n <line x1=\"16\" y1=\"6\" x2=\"20\" y2=\"6\"/>\n</svg>\n";
99
+
100
+ var compTag = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"2\" y=\"7\" width=\"20\" height=\"10\" rx=\"5\"/>\n <line x1=\"15\" y1=\"10\" x2=\"17\" y2=\"14\"/>\n <line x1=\"17\" y1=\"10\" x2=\"15\" y2=\"14\"/>\n</svg>\n";
101
+
102
+ var compTheme = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\"/>\n <path d=\"M12 2a10 10 0 0 1 0 20z\" fill=\"currentColor\"/>\n</svg>\n";
103
+
104
+ var compToast = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"3\" y=\"7\" width=\"18\" height=\"10\" rx=\"2\"/>\n <circle cx=\"8\" cy=\"12\" r=\"2\"/>\n <line x1=\"12\" y1=\"12\" x2=\"18\" y2=\"12\"/>\n</svg>\n";
105
+
106
+ var compTooltip = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M3 5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-5l-2 4-2-4H5a2 2 0 0 1-2-2z\"/>\n</svg>\n";
107
+
62
108
  var compass = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\"/>\n <polygon points=\"16.24 7.76 14.12 14.12 7.76 16.24 9.88 9.88 16.24 7.76\"/>\n</svg>\n";
63
109
 
64
110
  var diagram = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect x=\"3\" y=\"3\" width=\"6\" height=\"6\" rx=\"1\"/>\n <rect x=\"15\" y=\"3\" width=\"6\" height=\"6\" rx=\"1\"/>\n <rect x=\"9\" y=\"15\" width=\"6\" height=\"6\" rx=\"1\"/>\n <line x1=\"6\" y1=\"9\" x2=\"6\" y2=\"15\"/>\n <line x1=\"6\" y1=\"15\" x2=\"9\" y2=\"15\"/>\n <line x1=\"18\" y1=\"9\" x2=\"18\" y2=\"15\"/>\n <line x1=\"18\" y1=\"15\" x2=\"15\" y2=\"15\"/>\n</svg>\n";
@@ -138,6 +184,29 @@ registerIcons({
138
184
  close: close$1,
139
185
  "collapse-left": collapseLeft$1,
140
186
  comments,
187
+ "comp-appbar": compAppbar,
188
+ "comp-avatar": compAvatar,
189
+ "comp-badge": compBadge,
190
+ "comp-button": compButton,
191
+ "comp-card": compCard,
192
+ "comp-checkbox": compCheckbox,
193
+ "comp-dialog": compDialog,
194
+ "comp-drawer": compDrawer,
195
+ "comp-icon": compIcon,
196
+ "comp-input": compInput,
197
+ "comp-menu": compMenu,
198
+ "comp-panelbar": compPanelbar,
199
+ "comp-progress": compProgress,
200
+ "comp-radio": compRadio,
201
+ "comp-select": compSelect,
202
+ "comp-slider": compSlider,
203
+ "comp-switch": compSwitch,
204
+ "comp-table": compTable,
205
+ "comp-tabs": compTabs,
206
+ "comp-tag": compTag,
207
+ "comp-theme": compTheme,
208
+ "comp-toast": compToast,
209
+ "comp-tooltip": compTooltip,
141
210
  compass,
142
211
  diagram,
143
212
  discord,
@@ -1914,9 +1983,58 @@ if (!customElements.get("y-appbar")) {
1914
1983
  customElements.define("y-appbar", YumeAppbar);
1915
1984
  }
1916
1985
 
1986
+ /**
1987
+ * Return a [background, foreground] CSS variable pair for a color scheme.
1988
+ * Background is `--{color}-content--`, foreground is `--{color}-content-inverse`.
1989
+ * @param {string} color — one of base, primary, secondary, success, warning, error, help
1990
+ * @param {string} [fallbackColor="base"] — color to fall back to when `color` is unrecognised.
1991
+ * Use `null` to pass the raw `color` string through as the background instead.
1992
+ * @returns {[string, string]} — [bg var, fg var]
1993
+ */
1994
+ function getColorVarPair(color, fallbackColor = "base") {
1995
+ const map = {
1996
+ base: ["var(--base-content--)", "var(--base-content-inverse)"],
1997
+ primary: ["var(--primary-content--)", "var(--primary-content-inverse)"],
1998
+ secondary: [
1999
+ "var(--secondary-content--)",
2000
+ "var(--secondary-content-inverse)",
2001
+ ],
2002
+ success: ["var(--success-content--)", "var(--success-content-inverse)"],
2003
+ warning: ["var(--warning-content--)", "var(--warning-content-inverse)"],
2004
+ error: ["var(--error-content--)", "var(--error-content-inverse)"],
2005
+ help: ["var(--help-content--)", "var(--help-content-inverse)"],
2006
+ };
2007
+ if (map[color]) return map[color];
2008
+ if (fallbackColor === null) return [color, "var(--base-content-inverse)"];
2009
+ return map[fallbackColor] || map.base;
2010
+ }
2011
+
2012
+ // helpers/slot-utils.js
2013
+ function hideEmptySlotContainers(shadowRoot, slotsConfig = {}) {
2014
+ Object.entries(slotsConfig).forEach(([slotName, containerSelector]) => {
2015
+ const slot = shadowRoot.querySelector(
2016
+ `slot${slotName ? `[name="${slotName}"]` : ":not([name])"}`,
2017
+ );
2018
+ const container = shadowRoot.querySelector(containerSelector);
2019
+
2020
+ if (slot && container) {
2021
+ const assigned = slot
2022
+ .assignedNodes({ flatten: true })
2023
+ .filter((n) => {
2024
+ return !(
2025
+ n.nodeType === Node.TEXT_NODE &&
2026
+ n.textContent.trim() === ""
2027
+ );
2028
+ });
2029
+
2030
+ container.style.display = assigned.length > 0 ? "" : "none";
2031
+ }
2032
+ });
2033
+ }
2034
+
1917
2035
  class YumeAvatar extends HTMLElement {
1918
2036
  static get observedAttributes() {
1919
- return ["src", "alt", "size", "shape"];
2037
+ return ["src", "alt", "size", "shape", "color"];
1920
2038
  }
1921
2039
 
1922
2040
  constructor() {
@@ -1935,7 +2053,9 @@ class YumeAvatar extends HTMLElement {
1935
2053
  const src = this.getAttribute("src");
1936
2054
  const altRaw = this.getAttribute("alt") || "AN";
1937
2055
  const shape = this.getAttribute("shape") || "circle";
2056
+ const color = this.getAttribute("color") || "primary";
1938
2057
  const borderRadius = `var(--component-avatar-border-radius-${shape}, 9999px)`;
2058
+ const [bgColor, textColor] = getColorVarPair(color);
1939
2059
 
1940
2060
  let dimensions;
1941
2061
  const size = this.getAttribute("size") || "medium";
@@ -1984,8 +2104,8 @@ class YumeAvatar extends HTMLElement {
1984
2104
  width: 100%;
1985
2105
  height: 100%;
1986
2106
  border-radius: ${borderRadius};
1987
- background-color: var(--primary-content--, #0576ff);
1988
- color: var(--primary-background-component, #0c0c0d);
2107
+ background-color: ${bgColor};
2108
+ color: ${textColor};
1989
2109
  display: flex;
1990
2110
  align-items: center;
1991
2111
  justify-content: center;
@@ -2165,105 +2285,6 @@ if (!customElements.get("y-badge")) {
2165
2285
  customElements.define("y-badge", YumeBadge);
2166
2286
  }
2167
2287
 
2168
- // helpers/slot-utils.js
2169
- function hideEmptySlotContainers(shadowRoot, slotsConfig = {}) {
2170
- Object.entries(slotsConfig).forEach(([slotName, containerSelector]) => {
2171
- const slot = shadowRoot.querySelector(
2172
- `slot${slotName ? `[name="${slotName}"]` : ":not([name])"}`,
2173
- );
2174
- const container = shadowRoot.querySelector(containerSelector);
2175
-
2176
- if (slot && container) {
2177
- const assigned = slot
2178
- .assignedNodes({ flatten: true })
2179
- .filter((n) => {
2180
- return !(
2181
- n.nodeType === Node.TEXT_NODE &&
2182
- n.textContent.trim() === ""
2183
- );
2184
- });
2185
-
2186
- container.style.display = assigned.length > 0 ? "" : "none";
2187
- }
2188
- });
2189
- }
2190
-
2191
- /**
2192
- * Resolve a CSS custom-property value to a concrete color string.
2193
- * Reads from the given element's computed style.
2194
- * @param {string} varExpr — e.g. "var(--primary-content--)"
2195
- * @param {HTMLElement} el — element to resolve against
2196
- * @returns {string} — resolved color or fallback
2197
- */
2198
- function resolveCSSColor(varExpr, el) {
2199
- const match = varExpr.match(/var\(\s*(--[^,)]+)/);
2200
- if (!match) return varExpr;
2201
- const val = getComputedStyle(el).getPropertyValue(match[1]).trim();
2202
- return val || varExpr;
2203
- }
2204
-
2205
- /**
2206
- * Parse a CSS color string (#hex, rgb(), etc.) to {r, g, b}.
2207
- * Returns null if it can't parse.
2208
- */
2209
- function parseColor(colorStr) {
2210
- // #RGB, #RRGGBB, #RRGGBBAA
2211
- const hexMatch = colorStr.match(
2212
- /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,
2213
- );
2214
- if (hexMatch) {
2215
- let hex = hexMatch[1];
2216
- if (hex.length <= 4) {
2217
- hex = hex
2218
- .split("")
2219
- .map((c) => c + c)
2220
- .join("");
2221
- }
2222
- return {
2223
- r: parseInt(hex.slice(0, 2), 16),
2224
- g: parseInt(hex.slice(2, 4), 16),
2225
- b: parseInt(hex.slice(4, 6), 16),
2226
- };
2227
- }
2228
- // rgb(r, g, b) or rgba(r, g, b, a)
2229
- const rgbMatch = colorStr.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);
2230
- if (rgbMatch) {
2231
- return {
2232
- r: parseInt(rgbMatch[1], 10),
2233
- g: parseInt(rgbMatch[2], 10),
2234
- b: parseInt(rgbMatch[3], 10),
2235
- };
2236
- }
2237
- return null;
2238
- }
2239
-
2240
- /**
2241
- * Compute relative luminance of an {r,g,b} color (0-255 range).
2242
- * Returns a value between 0 (black) and 1 (white).
2243
- */
2244
- function luminance({ r, g, b }) {
2245
- const [rs, gs, bs] = [r, g, b].map((c) => {
2246
- c /= 255;
2247
- return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
2248
- });
2249
- return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
2250
- }
2251
-
2252
- /**
2253
- * Given a background color string, return a CSS value for best contrast text.
2254
- * Uses WCAG relative luminance to pick dark or light, referencing theme tokens
2255
- * (--neutral-black / --neutral-white) with hardcoded fallbacks.
2256
- * @param {string} bgColor — any CSS color string (#hex, rgb(), etc.)
2257
- * @returns {string} CSS var() expression for contrasting text color
2258
- */
2259
- function contrastTextColor(bgColor) {
2260
- const parsed = parseColor(bgColor);
2261
- if (!parsed) return "var(--neutral-white, #ffffff)";
2262
- return luminance(parsed) > 0.179
2263
- ? "var(--neutral-black, #000000)"
2264
- : "var(--neutral-white, #ffffff)";
2265
- }
2266
-
2267
2288
  class YumeCard extends HTMLElement {
2268
2289
  static get observedAttributes() {
2269
2290
  return ["color", "raised"];
@@ -2867,6 +2888,22 @@ class YumeDialog extends HTMLElement {
2867
2888
  dialog.appendChild(body);
2868
2889
  dialog.appendChild(footer);
2869
2890
  this.shadowRoot.appendChild(dialog);
2891
+
2892
+ // Hide slot containers that have no slotted content
2893
+ const hideIfEmpty = (wrapper) => {
2894
+ const slot = wrapper.querySelector("slot");
2895
+ if (!slot) return;
2896
+ const update = () => {
2897
+ const hasContent =
2898
+ slot.assignedNodes({ flatten: true }).length > 0;
2899
+ wrapper.style.display = hasContent ? "" : "none";
2900
+ };
2901
+ slot.addEventListener("slotchange", update);
2902
+ update();
2903
+ };
2904
+ if (!this.closable) hideIfEmpty(header);
2905
+ hideIfEmpty(body);
2906
+ hideIfEmpty(footer);
2870
2907
  }
2871
2908
  }
2872
2909
 
@@ -4063,19 +4100,6 @@ class YumeProgress extends HTMLElement {
4063
4100
  return Math.max(0, Math.min(100, pct));
4064
4101
  }
4065
4102
 
4066
- getBarColor(color) {
4067
- const colorMap = {
4068
- primary: "var(--primary-content--)",
4069
- secondary: "var(--secondary-content--)",
4070
- base: "var(--base-content--)",
4071
- success: "var(--success-content--)",
4072
- warning: "var(--warning-content--)",
4073
- error: "var(--error-content--)",
4074
- help: "var(--help-content--)",
4075
- };
4076
- return colorMap[color] || color;
4077
- }
4078
-
4079
4103
  getSizeVar(size) {
4080
4104
  const map = {
4081
4105
  small: "var(--component-progress-size-small)",
@@ -4103,7 +4127,7 @@ class YumeProgress extends HTMLElement {
4103
4127
  render() {
4104
4128
  const isIndeterminate = this.indeterminate;
4105
4129
  const pct = this.percentage;
4106
- const barColor = this.getBarColor(this.color);
4130
+ const [barColor, barTextColor] = getColorVarPair(this.color, null);
4107
4131
  const sizeVar = this.getSizeVar(this.size);
4108
4132
  const isDisabled = this.disabled;
4109
4133
  const showLabel = this.labelDisplay && !isIndeterminate;
@@ -4181,7 +4205,7 @@ class YumeProgress extends HTMLElement {
4181
4205
  }
4182
4206
 
4183
4207
  .value-label--bar {
4184
- color: var(--base-background-component);
4208
+ color: ${barTextColor};
4185
4209
  width: calc(100% / (${pct || 1} / 100));
4186
4210
  }
4187
4211
 
@@ -6519,11 +6543,9 @@ class YumeToast extends HTMLElement {
6519
6543
  toast.setAttribute("aria-live", "assertive");
6520
6544
  toast.setAttribute("part", "toast");
6521
6545
 
6522
- const bgVar = this._getColorBg(color);
6523
- const resolvedBg = resolveCSSColor(bgVar, this);
6524
- const textColor = contrastTextColor(resolvedBg);
6525
- toast.style.backgroundColor = bgVar;
6526
- toast.style.color = textColor;
6546
+ const [bg, fg] = getColorVarPair(color);
6547
+ toast.style.backgroundColor = bg;
6548
+ toast.style.color = fg;
6527
6549
 
6528
6550
  if (icon) {
6529
6551
  const iconEl = document.createElement("y-icon");
@@ -6622,20 +6644,6 @@ class YumeToast extends HTMLElement {
6622
6644
  return map[pos] || map["bottom-right"];
6623
6645
  }
6624
6646
 
6625
- // "base" inverts the page: light content on dark, dark on light.
6626
- _getColorBg(color) {
6627
- const map = {
6628
- base: "var(--base-content--, #fff)",
6629
- primary: "var(--primary-content--, #0070f3)",
6630
- secondary: "var(--secondary-content--, #6c757d)",
6631
- success: "var(--success-content--, #28a745)",
6632
- warning: "var(--warning-content--, #ffc107)",
6633
- error: "var(--error-content--, #dc3545)",
6634
- help: "var(--help-content--, #6f42c1)",
6635
- };
6636
- return map[color] || map.base;
6637
- }
6638
-
6639
6647
  render() {
6640
6648
  this.shadowRoot.innerHTML = `
6641
6649
  <style>
@@ -6782,9 +6790,8 @@ class YumeTooltip extends HTMLElement {
6782
6790
  this._visible = true;
6783
6791
  const tip = this.shadowRoot.querySelector(".tooltip");
6784
6792
  if (tip) {
6785
- const bg = this._getBg();
6786
- const resolvedBg = resolveCSSColor(bg, this);
6787
- tip.style.color = contrastTextColor(resolvedBg);
6793
+ const [, fg] = getColorVarPair(this.color);
6794
+ tip.style.color = fg;
6788
6795
  tip.classList.add("visible");
6789
6796
  }
6790
6797
  }, this.delay);
@@ -6815,24 +6822,9 @@ class YumeTooltip extends HTMLElement {
6815
6822
  }
6816
6823
  }
6817
6824
 
6818
- _getBg() {
6819
- const map = {
6820
- base: "var(--base-content--, #555)",
6821
- primary: "var(--primary-content--, #0070f3)",
6822
- secondary: "var(--secondary-content--, #6c757d)",
6823
- success: "var(--success-content--, #28a745)",
6824
- warning: "var(--warning-content--, #ffc107)",
6825
- error: "var(--error-content--, #dc3545)",
6826
- help: "var(--help-content--, #6f42c1)",
6827
- };
6828
- return map[this.color] || map.base;
6829
- }
6830
-
6831
6825
  render() {
6832
6826
  const pos = this.position;
6833
- const bg = this._getBg();
6834
- const resolvedBg = resolveCSSColor(bg, this);
6835
- const fg = contrastTextColor(resolvedBg);
6827
+ const [bg, fg] = getColorVarPair(this.color);
6836
6828
 
6837
6829
  this.shadowRoot.innerHTML = `
6838
6830
  <style>
@@ -7003,7 +6995,12 @@ class YumeTheme extends HTMLElement {
7003
6995
  }
7004
6996
 
7005
6997
  this.shadowRoot.innerHTML = `
7006
- <style>${variablesCSS}</style>
6998
+ <style>
6999
+ ${variablesCSS}
7000
+ :host {
7001
+ font-family: var(--font-family-body, sans-serif);
7002
+ }
7003
+ </style>
7007
7004
  ${themeCSS ? `<style>${themeCSS}</style>` : ""}
7008
7005
  <slot></slot>
7009
7006
  `;
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Return a [background, foreground] CSS variable pair for a color scheme.
3
+ * Background is `--{color}-content--`, foreground is `--{color}-content-inverse`.
4
+ * @param {string} color — one of base, primary, secondary, success, warning, error, help
5
+ * @param {string} [fallbackColor="base"] — color to fall back to when `color` is unrecognised.
6
+ * Use `null` to pass the raw `color` string through as the background instead.
7
+ * @returns {[string, string]} — [bg var, fg var]
8
+ */
9
+ export function getColorVarPair(color: string, fallbackColor?: string): [string, string];
1
10
  export function hideEmptySlotContainers(shadowRoot: any, slotsConfig?: {}): void;
2
11
  /**
3
12
  * Resolve a CSS custom-property value to a concrete color string.
@@ -1,3 +1,29 @@
1
+ /**
2
+ * Return a [background, foreground] CSS variable pair for a color scheme.
3
+ * Background is `--{color}-content--`, foreground is `--{color}-content-inverse`.
4
+ * @param {string} color — one of base, primary, secondary, success, warning, error, help
5
+ * @param {string} [fallbackColor="base"] — color to fall back to when `color` is unrecognised.
6
+ * Use `null` to pass the raw `color` string through as the background instead.
7
+ * @returns {[string, string]} — [bg var, fg var]
8
+ */
9
+ export function getColorVarPair(color, fallbackColor = "base") {
10
+ const map = {
11
+ base: ["var(--base-content--)", "var(--base-content-inverse)"],
12
+ primary: ["var(--primary-content--)", "var(--primary-content-inverse)"],
13
+ secondary: [
14
+ "var(--secondary-content--)",
15
+ "var(--secondary-content-inverse)",
16
+ ],
17
+ success: ["var(--success-content--)", "var(--success-content-inverse)"],
18
+ warning: ["var(--warning-content--)", "var(--warning-content-inverse)"],
19
+ error: ["var(--error-content--)", "var(--error-content-inverse)"],
20
+ help: ["var(--help-content--)", "var(--help-content-inverse)"],
21
+ };
22
+ if (map[color]) return map[color];
23
+ if (fallbackColor === null) return [color, "var(--base-content-inverse)"];
24
+ return map[fallbackColor] || map.base;
25
+ }
26
+
1
27
  // helpers/slot-utils.js
2
28
  export function hideEmptySlotContainers(shadowRoot, slotsConfig = {}) {
3
29
  Object.entries(slotsConfig).forEach(([slotName, containerSelector]) => {