@studious-creative/yumekit 0.1.8 → 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.
@@ -1,79 +1,27 @@
1
- // helpers/slot-utils.js
2
-
3
- /**
4
- * Resolve a CSS custom-property value to a concrete color string.
5
- * Reads from the given element's computed style.
6
- * @param {string} varExpr — e.g. "var(--primary-content--)"
7
- * @param {HTMLElement} el — element to resolve against
8
- * @returns {string} — resolved color or fallback
9
- */
10
- function resolveCSSColor(varExpr, el) {
11
- const match = varExpr.match(/var\(\s*(--[^,)]+)/);
12
- if (!match) return varExpr;
13
- const val = getComputedStyle(el).getPropertyValue(match[1]).trim();
14
- return val || varExpr;
15
- }
16
-
17
- /**
18
- * Parse a CSS color string (#hex, rgb(), etc.) to {r, g, b}.
19
- * Returns null if it can't parse.
20
- */
21
- function parseColor(colorStr) {
22
- // #RGB, #RRGGBB, #RRGGBBAA
23
- const hexMatch = colorStr.match(
24
- /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,
25
- );
26
- if (hexMatch) {
27
- let hex = hexMatch[1];
28
- if (hex.length <= 4) {
29
- hex = hex
30
- .split("")
31
- .map((c) => c + c)
32
- .join("");
33
- }
34
- return {
35
- r: parseInt(hex.slice(0, 2), 16),
36
- g: parseInt(hex.slice(2, 4), 16),
37
- b: parseInt(hex.slice(4, 6), 16),
38
- };
39
- }
40
- // rgb(r, g, b) or rgba(r, g, b, a)
41
- const rgbMatch = colorStr.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);
42
- if (rgbMatch) {
43
- return {
44
- r: parseInt(rgbMatch[1], 10),
45
- g: parseInt(rgbMatch[2], 10),
46
- b: parseInt(rgbMatch[3], 10),
47
- };
48
- }
49
- return null;
50
- }
51
-
52
1
  /**
53
- * Compute relative luminance of an {r,g,b} color (0-255 range).
54
- * Returns a value between 0 (black) and 1 (white).
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]
55
8
  */
56
- function luminance({ r, g, b }) {
57
- const [rs, gs, bs] = [r, g, b].map((c) => {
58
- c /= 255;
59
- return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
60
- });
61
- return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
62
- }
63
-
64
- /**
65
- * Given a background color string, return a CSS value for best contrast text.
66
- * Uses WCAG relative luminance to pick dark or light, referencing theme tokens
67
- * (--neutral-black / --neutral-white) with hardcoded fallbacks.
68
- * @param {string} bgColor — any CSS color string (#hex, rgb(), etc.)
69
- * @returns {string} CSS var() expression for contrasting text color
70
- */
71
- function contrastTextColor(bgColor) {
72
- const parsed = parseColor(bgColor);
73
- if (!parsed) return "var(--neutral-white, #ffffff)";
74
- return luminance(parsed) > 0.179
75
- ? "var(--neutral-black, #000000)"
76
- : "var(--neutral-white, #ffffff)";
9
+ 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;
77
25
  }
78
26
 
79
27
  class YumeTooltip extends HTMLElement {
@@ -152,9 +100,8 @@ class YumeTooltip extends HTMLElement {
152
100
  this._visible = true;
153
101
  const tip = this.shadowRoot.querySelector(".tooltip");
154
102
  if (tip) {
155
- const bg = this._getBg();
156
- const resolvedBg = resolveCSSColor(bg, this);
157
- tip.style.color = contrastTextColor(resolvedBg);
103
+ const [, fg] = getColorVarPair(this.color);
104
+ tip.style.color = fg;
158
105
  tip.classList.add("visible");
159
106
  }
160
107
  }, this.delay);
@@ -185,24 +132,9 @@ class YumeTooltip extends HTMLElement {
185
132
  }
186
133
  }
187
134
 
188
- _getBg() {
189
- const map = {
190
- base: "var(--base-content--, #555)",
191
- primary: "var(--primary-content--, #0070f3)",
192
- secondary: "var(--secondary-content--, #6c757d)",
193
- success: "var(--success-content--, #28a745)",
194
- warning: "var(--warning-content--, #ffc107)",
195
- error: "var(--error-content--, #dc3545)",
196
- help: "var(--help-content--, #6f42c1)",
197
- };
198
- return map[this.color] || map.base;
199
- }
200
-
201
135
  render() {
202
136
  const pos = this.position;
203
- const bg = this._getBg();
204
- const resolvedBg = resolveCSSColor(bg, this);
205
- const fg = contrastTextColor(resolvedBg);
137
+ const [bg, fg] = getColorVarPair(this.color);
206
138
 
207
139
  this.shadowRoot.innerHTML = `
208
140
  <style>
package/dist/icons/all.js CHANGED
@@ -49,6 +49,52 @@ var collapseLeft = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 2
49
49
 
50
50
  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";
51
51
 
52
+ 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";
53
+
54
+ 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";
55
+
56
+ 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";
57
+
58
+ 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";
59
+
60
+ 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";
61
+
62
+ 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";
63
+
64
+ 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";
65
+
66
+ 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";
67
+
68
+ 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";
69
+
70
+ 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";
71
+
72
+ 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";
73
+
74
+ 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";
75
+
76
+ 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";
77
+
78
+ 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";
79
+
80
+ 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";
81
+
82
+ 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";
83
+
84
+ 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";
85
+
86
+ 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";
87
+
88
+ 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";
89
+
90
+ 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";
91
+
92
+ 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";
93
+
94
+ 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";
95
+
96
+ 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";
97
+
52
98
  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";
53
99
 
54
100
  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";
@@ -128,6 +174,29 @@ registerIcons({
128
174
  close,
129
175
  "collapse-left": collapseLeft,
130
176
  comments,
177
+ "comp-appbar": compAppbar,
178
+ "comp-avatar": compAvatar,
179
+ "comp-badge": compBadge,
180
+ "comp-button": compButton,
181
+ "comp-card": compCard,
182
+ "comp-checkbox": compCheckbox,
183
+ "comp-dialog": compDialog,
184
+ "comp-drawer": compDrawer,
185
+ "comp-icon": compIcon,
186
+ "comp-input": compInput,
187
+ "comp-menu": compMenu,
188
+ "comp-panelbar": compPanelbar,
189
+ "comp-progress": compProgress,
190
+ "comp-radio": compRadio,
191
+ "comp-select": compSelect,
192
+ "comp-slider": compSlider,
193
+ "comp-switch": compSwitch,
194
+ "comp-table": compTable,
195
+ "comp-tabs": compTabs,
196
+ "comp-tag": compTag,
197
+ "comp-theme": compTheme,
198
+ "comp-toast": compToast,
199
+ "comp-tooltip": compTooltip,
131
200
  compass,
132
201
  diagram,
133
202
  discord,