eq-internal-tools-ds 0.0.0-stage → 1.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/README.md +10 -2
- package/eq-ds-chart.js +148 -0
- package/eq-ds-inline.css +2921 -0
- package/eq-ds.css +3307 -0
- package/eq-ds.js +8 -0
- package/favicon-luva.svg +1 -0
- package/favicon.svg +1 -0
- package/package.json +10 -4
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# eq-internal-tools-ds 1.3.0
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
EverQuote's Internal Tools Design System, for tools EverQuote staff use. Not for consumer or partner-facing work.
|
|
4
|
+
|
|
5
|
+
In a Claude artifact (which blocks stylesheets from other sites), load the DS with one line in `<head>`, and put `class="eq-app"` on `<body>`:
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<script src="https://cdn.jsdelivr.net/npm/eq-internal-tools-ds@1/eq-ds.js"></script>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Everywhere else, link `https://sarahbrad.github.io/eq-ds/v1/eq-ds.css`. Docs and snippets: the Claude DS artifact and the internal-tools-ds skill.
|
package/eq-ds-chart.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/* Internal Tools DS · Chart.js theme (ships beside eq-ds.css)
|
|
2
|
+
|
|
3
|
+
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.4/dist/chart.umd.min.js"></script>
|
|
4
|
+
<script src="…/eq-ds/v1/eq-ds-chart.js"></script>
|
|
5
|
+
eqChartTheme(Chart); // once, before creating charts
|
|
6
|
+
new Chart(el, { type: 'line', data: { datasets: eqSeries([{ label: 'Quotes', data }]) } });
|
|
7
|
+
|
|
8
|
+
Every value is read from the eq-ds.css tokens at call time, so Light, Dark and the Luva brand
|
|
9
|
+
(data-brand="luva") follow the page. Call eqChartTheme(Chart) again and chart.update() after a theme switch. */
|
|
10
|
+
(function () {
|
|
11
|
+
function tok(name) { return getComputedStyle(document.documentElement).getPropertyValue('--' + name).trim(); }
|
|
12
|
+
function alpha(color, a) {
|
|
13
|
+
var c = document.createElement('canvas').getContext('2d'); c.fillStyle = color; var hex = c.fillStyle;
|
|
14
|
+
if (hex[0] !== '#') return color;
|
|
15
|
+
var n = parseInt(hex.slice(1, 7), 16);
|
|
16
|
+
return 'rgba(' + (n >> 16 & 255) + ',' + (n >> 8 & 255) + ',' + (n & 255) + ',' + a + ')';
|
|
17
|
+
}
|
|
18
|
+
function series(i) { return tok('color-chart-chart-' + ((i % 8) + 1)); }
|
|
19
|
+
|
|
20
|
+
window.eqChartTheme = function (Chart) {
|
|
21
|
+
var d = Chart.defaults;
|
|
22
|
+
d.font = { family: tok('font-sans') || 'Mulish, ui-sans-serif, system-ui, sans-serif', size: 12, lineHeight: 1.5 };
|
|
23
|
+
d.color = tok('color-surfaces-muted-foreground');
|
|
24
|
+
d.borderColor = tok('color-borders-border');
|
|
25
|
+
d.scale.grid.color = tok('color-borders-border');
|
|
26
|
+
d.scale.border.color = tok('color-borders-border');
|
|
27
|
+
d.scale.ticks.color = tok('color-surfaces-muted-foreground');
|
|
28
|
+
d.plugins.legend.labels.color = tok('color-surfaces-secondary-foreground');
|
|
29
|
+
d.plugins.legend.labels.boxWidth = 8;
|
|
30
|
+
d.plugins.legend.labels.boxHeight = 8;
|
|
31
|
+
d.plugins.tooltip.backgroundColor = tok('color-surfaces-inverse');
|
|
32
|
+
d.plugins.tooltip.titleColor = tok('color-surfaces-inverse-foreground');
|
|
33
|
+
d.plugins.tooltip.bodyColor = tok('color-surfaces-inverse-foreground');
|
|
34
|
+
d.elements.line.borderWidth = 2;
|
|
35
|
+
d.elements.point.radius = 4;
|
|
36
|
+
d.elements.point.borderWidth = 2;
|
|
37
|
+
d.elements.point.borderColor = tok('color-surfaces-card');
|
|
38
|
+
d.elements.bar.borderRadius = parseFloat(tok('radius-chip')) || 4;
|
|
39
|
+
d.elements.bar.borderSkipped = 'start';
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/* Colours datasets in order of importance. Options per dataset:
|
|
43
|
+
comparison: true → chart-5, dashed (previous period); area: true → 16% fill;
|
|
44
|
+
target: true → a dashed muted line with no points (no annotation plugin needed).
|
|
45
|
+
Comparison and target series don't use up a series colour. */
|
|
46
|
+
window.eqSeries = function (datasets) {
|
|
47
|
+
var n = 0;
|
|
48
|
+
return datasets.map(function (ds) {
|
|
49
|
+
var c = ds.target ? tok('color-surfaces-muted-foreground') : ds.comparison ? tok('color-chart-chart-5') : series(n++);
|
|
50
|
+
var out = Object.assign({ borderColor: c, backgroundColor: ds.area ? alpha(c, 0.16) : c, pointBackgroundColor: c }, ds);
|
|
51
|
+
if (ds.comparison || ds.target) out.borderDash = [6, 4];
|
|
52
|
+
if (ds.area) out.fill = true;
|
|
53
|
+
if (ds.target) Object.assign(out, { type: 'line', borderWidth: 1.5, pointRadius: 0, pointHoverRadius: 0, fill: false });
|
|
54
|
+
return out;
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/* Target or threshold line for chartjs-plugin-annotation. */
|
|
59
|
+
window.eqTargetLine = function (value, label) {
|
|
60
|
+
return { type: 'line', yMin: value, yMax: value, borderColor: tok('color-surfaces-muted-foreground'), borderDash: [6, 4], borderWidth: 1.5,
|
|
61
|
+
label: label ? { display: true, content: label, color: tok('color-surfaces-muted-foreground'), backgroundColor: 'transparent', position: 'end' } : undefined };
|
|
62
|
+
};
|
|
63
|
+
})();
|
|
64
|
+
|
|
65
|
+
/* eqChart(card, cfg): draws a chart card's chart, HTML legend and Table view from one config, and redraws on a theme change.
|
|
66
|
+
Same code as the Chart snippets; with this file linked, snippets can drop their inline copy. */
|
|
67
|
+
/* eq-ds chart theme (a copy of eq-ds-chart.js) and eqChart(): chart, legend and table from one config. Guarded, so pasting several charts defines it once. */
|
|
68
|
+
window.eqChart || (function () {
|
|
69
|
+
function tok(n) { return getComputedStyle(document.documentElement).getPropertyValue("--" + n).trim(); }
|
|
70
|
+
function alpha(c, a) { var x = document.createElement("canvas").getContext("2d"); x.fillStyle = c; var h = x.fillStyle; if (h[0] !== "#") return c; var n = parseInt(h.slice(1, 7), 16); return "rgba(" + (n >> 16 & 255) + "," + (n >> 8 & 255) + "," + (n & 255) + "," + a + ")"; }
|
|
71
|
+
window.eqChartTheme = window.eqChartTheme || function (Chart) {
|
|
72
|
+
var d = Chart.defaults;
|
|
73
|
+
d.font = { family: tok("font-sans") || "Mulish, ui-sans-serif, system-ui, sans-serif", size: 12, lineHeight: 1.5 };
|
|
74
|
+
d.color = tok("color-surfaces-muted-foreground"); d.borderColor = tok("color-borders-border");
|
|
75
|
+
d.scale.grid.color = tok("color-borders-border"); d.scale.border.color = tok("color-borders-border"); d.scale.ticks.color = tok("color-surfaces-muted-foreground");
|
|
76
|
+
d.plugins.legend.labels.color = tok("color-surfaces-secondary-foreground"); d.plugins.legend.labels.boxWidth = 8; d.plugins.legend.labels.boxHeight = 8;
|
|
77
|
+
d.plugins.tooltip.backgroundColor = tok("color-surfaces-inverse"); d.plugins.tooltip.titleColor = tok("color-surfaces-inverse-foreground"); d.plugins.tooltip.bodyColor = tok("color-surfaces-inverse-foreground");
|
|
78
|
+
d.elements.line.borderWidth = 2; d.elements.point.radius = 4; d.elements.point.borderWidth = 2; d.elements.point.borderColor = tok("color-surfaces-card");
|
|
79
|
+
d.elements.bar.borderRadius = parseFloat(tok("radius-chip")) || 4; d.elements.bar.borderSkipped = "start";
|
|
80
|
+
};
|
|
81
|
+
/* comparison: chart-5 dashed; area: 16% fill; target: a dashed muted line with no points. */
|
|
82
|
+
window.eqSeries = function (datasets) {
|
|
83
|
+
var n = 0;
|
|
84
|
+
return datasets.map(function (ds) {
|
|
85
|
+
var c = ds.target ? tok("color-surfaces-muted-foreground") : ds.comparison ? tok("color-chart-chart-5") : tok("color-chart-chart-" + (n++ % 8 + 1));
|
|
86
|
+
var out = Object.assign({ borderColor: c, backgroundColor: ds.area ? alpha(c, 0.16) : c, pointBackgroundColor: c }, ds);
|
|
87
|
+
if (ds.comparison || ds.target) out.borderDash = [6, 4];
|
|
88
|
+
if (ds.area) out.fill = true;
|
|
89
|
+
if (ds.target) Object.assign(out, { type: "line", borderWidth: 1.5, pointRadius: 0, pointHoverRadius: 0, fill: false });
|
|
90
|
+
return out;
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
window.eqChart = function (card, cfg) {
|
|
94
|
+
if (card.eqChart) card.eqChart.destroy();
|
|
95
|
+
card.eqCfg = cfg = cfg || card.eqCfg;
|
|
96
|
+
var donut = cfg.type === "doughnut", horiz = cfg.horizontal, pct = cfg.percent, fmt = function (v) { return v == null ? "–" : v.toLocaleString() + (cfg.unit || ""); };
|
|
97
|
+
var series = cfg.series.map(function (s) { return Object.assign({ area: cfg.type === "area" && !s.comparison && !s.target }, s); });
|
|
98
|
+
if (pct) series = series.map(function (s) { return Object.assign({}, s, { data: s.data.map(function (v, i) {
|
|
99
|
+
var t = cfg.series.reduce(function (a, x) { return a + (x.target ? 0 : x.data[i]); }, 0); return t ? Math.round(v / t * 1000) / 10 : 0; }) }); });
|
|
100
|
+
eqChartTheme(Chart);
|
|
101
|
+
var ds = donut ? [{ data: series[0].data, backgroundColor: cfg.labels.map(function (_, i) { return tok("color-chart-chart-" + (i % 8 + 1)); }), borderColor: tok("color-surfaces-card"), borderWidth: 2, borderRadius: 0 }]
|
|
102
|
+
: eqSeries(series.map(function (s) { return Object.assign({ order: s.type === "line" || s.target ? 0 : 1, yAxisID: s.axis === "right" ? "y1" : undefined }, s); }));
|
|
103
|
+
var v = horiz ? "x" : "y", k = horiz ? "y" : "x", scales = {}, stacked = !!(cfg.stacked || pct);
|
|
104
|
+
if (!donut) {
|
|
105
|
+
scales[k] = { stacked: stacked, grid: { display: false } };
|
|
106
|
+
scales[v] = { stacked: stacked, beginAtZero: true, max: pct ? 100 : undefined, border: { display: false }, ticks: { maxTicksLimit: 5, callback: function (x) { return x.toLocaleString() + (pct ? "%" : cfg.unit || ""); } } };
|
|
107
|
+
if (series.some(function (s) { return s.axis === "right"; })) scales.y1 = { position: "right", beginAtZero: true, grid: { display: false }, border: { display: false }, ticks: { maxTicksLimit: 5, callback: function (x) { return x.toLocaleString() + (cfg.rightUnit || ""); } } };
|
|
108
|
+
}
|
|
109
|
+
card.eqChart = new Chart(card.querySelector("canvas"), { type: donut ? "doughnut" : cfg.type === "area" ? "line" : cfg.type,
|
|
110
|
+
data: { labels: cfg.labels, datasets: ds },
|
|
111
|
+
options: Object.assign({ responsive: true, maintainAspectRatio: false, indexAxis: horiz ? "y" : "x", scales: scales,
|
|
112
|
+
interaction: donut ? { mode: "nearest", intersect: true } : { mode: "index", intersect: false },
|
|
113
|
+
plugins: { legend: { display: false }, tooltip: { callbacks: { label: function (c) { return " " + (c.dataset.label || c.label) + ": " + fmt(c.raw) + (pct ? "%" : ""); } } } } },
|
|
114
|
+
donut ? { cutout: "72%" } : {}, cfg.options || {}) });
|
|
115
|
+
var legend = card.querySelector(".eq-legend"), table = card.querySelector(".eq-chart-table");
|
|
116
|
+
if (legend) {
|
|
117
|
+
legend.textContent = "";
|
|
118
|
+
var items = donut ? cfg.labels.map(function (l, i) { return { label: l, value: series[0].data[i], color: "var(--color-chart-chart-" + (i % 8 + 1) + ")" }; })
|
|
119
|
+
: (function (n) { return series.map(function (s) { return { label: s.label, marker: s.target || s.comparison ? "dashed" : (s.type || cfg.type) === "line" ? "line" : "square",
|
|
120
|
+
color: s.target ? "var(--color-surfaces-muted-foreground)" : s.comparison ? "var(--color-chart-chart-5)" : "var(--color-chart-chart-" + (n++ % 8 + 1) + ")" }; }); })(0);
|
|
121
|
+
items.forEach(function (it, i) {
|
|
122
|
+
var li = document.createElement("li"), b = document.createElement("button");
|
|
123
|
+
b.type = "button"; b.className = "eq-legend-item"; b.setAttribute("aria-pressed", "true"); b.style.setProperty("--eq-series", it.color);
|
|
124
|
+
if (it.marker && it.marker !== "square") b.dataset.marker = it.marker;
|
|
125
|
+
b.textContent = it.label;
|
|
126
|
+
if (donut) { var val = document.createElement("span"); val.className = "eq-legend-value"; val.textContent = fmt(it.value); b.append(" ", val); }
|
|
127
|
+
b.onclick = function () { var on = b.getAttribute("aria-pressed") !== "true", c = card.eqChart;
|
|
128
|
+
if (donut) c.toggleDataVisibility(i); else c.setDatasetVisibility(i, on); b.setAttribute("aria-pressed", on); c.update(); };
|
|
129
|
+
li.appendChild(b); legend.appendChild(li);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (table) {
|
|
133
|
+
var cols = donut ? [cfg.valueLabel || "Value"] : cfg.series.map(function (s) { return s.label; }), t = document.createElement("table"), tr = t.createTHead().insertRow(), body = t.createTBody();
|
|
134
|
+
t.className = "eq-table eq-table-compact";
|
|
135
|
+
[cfg.labelHeader || ""].concat(cols).forEach(function (c, j) { var th = document.createElement("th"); th.scope = "col"; th.textContent = c; if (j) th.className = "eq-num"; tr.appendChild(th); });
|
|
136
|
+
cfg.labels.forEach(function (l, i) { var r = body.insertRow(); r.insertCell().textContent = l;
|
|
137
|
+
(donut ? [cfg.series[0]] : cfg.series).forEach(function (s) { var td = r.insertCell(); td.className = "eq-num"; td.textContent = fmt(s.data[i]); }); });
|
|
138
|
+
table.textContent = ""; table.appendChild(t);
|
|
139
|
+
}
|
|
140
|
+
if (!card.eqWired) {
|
|
141
|
+
card.eqWired = true;
|
|
142
|
+
card.addEventListener("change", function (e) { if (e.target.closest(".eq-segmented")) card.dataset.view = e.target.value; });
|
|
143
|
+
new MutationObserver(function () { eqChart(card); }).observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme", "data-brand"] });
|
|
144
|
+
matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function () { eqChart(card); });
|
|
145
|
+
}
|
|
146
|
+
return card.eqChart;
|
|
147
|
+
};
|
|
148
|
+
})();
|