badgesmith 1.0.0 → 1.1.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 +11 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -136,6 +136,14 @@ https://badgesmith.bvandrc.workers.dev/?items=book:docs&bold=true&underline=true
|
|
|
136
136
|
https://badgesmith.bvandrc.workers.dev/?items=react-toolkit&bold=true&underline=true&color=none&textColor=0969da
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
+
**Crossed out, for a link that no longer goes anywhere**
|
|
140
|
+
|
|
141
|
+
<a href="https://badgesmith.bvandrc.workers.dev/?items=file-directory:repo&strikethrough=true&color=none&textColor=6E7681&iconColor=6E7681"><img src="https://badgesmith.bvandrc.workers.dev/?items=file-directory:repo&strikethrough=true&color=none&textColor=6E7681&iconColor=6E7681" alt="Crossed out, for a link that no longer goes anywhere"/></a>
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
https://badgesmith.bvandrc.workers.dev/?items=file-directory:repo&strikethrough=true&color=none&textColor=6E7681&iconColor=6E7681
|
|
145
|
+
```
|
|
146
|
+
|
|
139
147
|
**No background, compact, legible on light and dark themes**
|
|
140
148
|
|
|
141
149
|
<a href="https://badgesmith.bvandrc.workers.dev/?items=git-commit:547,git-pull-request:0&color=none&iconColor=6E7681&textColor=6E7681&height=14&padY=0"><img src="https://badgesmith.bvandrc.workers.dev/?items=git-commit:547,git-pull-request:0&color=none&iconColor=6E7681&textColor=6E7681&height=14&padY=0" alt="No background, compact, legible on light and dark themes"/></a>
|
|
@@ -182,6 +190,7 @@ Opening the root with no query returns an HTML page of the same examples as abov
|
|
|
182
190
|
| `iconScale` | `1` | 0.25–1; how large each icon is against its value |
|
|
183
191
|
| `bold` | `false` | `true` or `false`; draws every value in the bold face |
|
|
184
192
|
| `underline` | `false` | `true` or `false`; draws a line under every value |
|
|
193
|
+
| `strikethrough` | `false` | `true` or `false`; draws a line through every value |
|
|
185
194
|
| `radius` | `0` | corner radius; `0` matches shields' flat-square |
|
|
186
195
|
| `font` | `verdana` | `verdana`, `arial`, `times` or `courier` |
|
|
187
196
|
| `fontSize` | from the box | text size in px, independent of `height` |
|
|
@@ -190,6 +199,8 @@ Opening the root with no query returns an HTML page of the same examples as abov
|
|
|
190
199
|
|
|
191
200
|
`underline=true` draws a line under every value, which costs no width: an underline does not change what a glyph advances by, so the measured text stays the right size. It is a presentation attribute rather than CSS, so GitHub's image proxy serves it intact.
|
|
192
201
|
|
|
202
|
+
`strikethrough=true` draws a line through every value instead, at the same cost: none. With `underline=true` as well, both lines are drawn.
|
|
203
|
+
|
|
193
204
|
`font` picks the face every value is drawn in. Only families a reader already has, since the proxy serving these SVGs forbids fetching a font — and only ones whose advance widths are known, because the pill has to be sized before it is drawn. Each face is measured against its own metrics and centred on its own cap height, so the text fits and sits level whichever is chosen. The stacks name a metric-compatible clone after the family itself (`Arial,Liberation Sans,Helvetica,sans-serif`), so a reader without the family still gets the widths the table holds.
|
|
194
205
|
|
|
195
206
|
A run of ordinary spaces in a value collapses to one when the SVG is drawn, and the CSS that would stop that is blocked by the proxy these are served through — so use non-breaking spaces (`%C2%A0`) for a wider gap. They are measured as spaces, which is exactly what they advance as.
|
package/dist/index.d.mts
CHANGED
|
@@ -79,6 +79,15 @@ type BadgeStyle = {
|
|
|
79
79
|
* @default false
|
|
80
80
|
*/
|
|
81
81
|
underline?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Draws a line through every value, as for something no longer on offer.
|
|
84
|
+
*
|
|
85
|
+
* Costs nothing in width, for the same reason an underline does. Combines
|
|
86
|
+
* with `underline`, drawing both lines.
|
|
87
|
+
*
|
|
88
|
+
* @default false
|
|
89
|
+
*/
|
|
90
|
+
strikethrough?: boolean;
|
|
82
91
|
/**
|
|
83
92
|
* How large each icon is against its own value, as a fraction of normal.
|
|
84
93
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -5210,7 +5210,7 @@ const round = (value) => Number(value.toFixed(2));
|
|
|
5210
5210
|
*
|
|
5211
5211
|
* Throws when an item names an icon that does not exist.
|
|
5212
5212
|
*/
|
|
5213
|
-
const renderBadge$1 = ({ items, color = "2f363d", iconColor = "8B949E", textColor = "fff", height = 20, padY, radius = 0, iconSide = "left", iconScale = 1, underline = false, bold = false, font = "verdana", fontSize: fontSizeOverride }) => {
|
|
5213
|
+
const renderBadge$1 = ({ items, color = "2f363d", iconColor = "8B949E", textColor = "fff", height = 20, padY, radius = 0, iconSide = "left", iconScale = 1, underline = false, strikethrough = false, bold = false, font = "verdana", fontSize: fontSizeOverride }) => {
|
|
5214
5214
|
const scale = padY === void 0 ? height / 20 : (height - 2 * padY) / BASE_PROPORTIONS.iconSize;
|
|
5215
5215
|
const { fontSize: scaledFontSize, iconSize, endPad, iconGap, itemGap } = mapValues(BASE_PROPORTIONS, (value) => value * scale);
|
|
5216
5216
|
const fontSize = fontSizeOverride ?? scaledFontSize;
|
|
@@ -5231,12 +5231,14 @@ const renderBadge$1 = ({ items, color = "2f363d", iconColor = "8B949E", textColo
|
|
|
5231
5231
|
};
|
|
5232
5232
|
});
|
|
5233
5233
|
const width = endPad * 2 + sumBy(measured, (m) => m.iconWidth + (m.path && m.value !== void 0 ? iconGap : 0) + m.valueWidth) + itemGap * Math.max(measured.length - 1, 0);
|
|
5234
|
+
const decorations = [underline && "underline", strikethrough && "line-through"].filter(Boolean);
|
|
5235
|
+
const decoration = decorations.length > 0 ? ` text-decoration="${decorations.join(" ")}"` : "";
|
|
5234
5236
|
let x = endPad;
|
|
5235
5237
|
const parts = [];
|
|
5236
5238
|
const baseline = round((height + digitCapRatio(font) * fontSize) / 2);
|
|
5237
5239
|
for (const m of measured) {
|
|
5238
5240
|
const icon = (at) => `<g fill="#${iconColor}" transform="translate(${round(at)} ${round((height - m.iconHeight) / 2)}) scale(${round(m.drawScale)})">${m.path}</g>`;
|
|
5239
|
-
const value = (at) => `<text x="${round(at)}" y="${baseline}" font-family="${fontFamily(font)}" font-size="${round(fontSize)}" fill="#${textColor}"${bold ? " font-weight=\"bold\"" : ""}${
|
|
5241
|
+
const value = (at) => `<text x="${round(at)}" y="${baseline}" font-family="${fontFamily(font)}" font-size="${round(fontSize)}" fill="#${textColor}"${bold ? " font-weight=\"bold\"" : ""}${decoration}>${escapeText(m.value ?? "")}</text>`;
|
|
5240
5242
|
if (!m.path) {
|
|
5241
5243
|
parts.push(value(x));
|
|
5242
5244
|
x += m.valueWidth + itemGap;
|
|
@@ -5319,6 +5321,7 @@ const styleSchema = /* @__PURE__ */ object({
|
|
|
5319
5321
|
iconScale: /* @__PURE__ */ optional(zBounded(.25, 1)),
|
|
5320
5322
|
bold: /* @__PURE__ */ optional(zFlag),
|
|
5321
5323
|
underline: /* @__PURE__ */ optional(zFlag),
|
|
5324
|
+
strikethrough: /* @__PURE__ */ optional(zFlag),
|
|
5322
5325
|
iconSide: /* @__PURE__ */ optional(/* @__PURE__ */ _enum(ICON_SIDES, { error: `must be ${ICON_SIDES.join(" or ")}` })),
|
|
5323
5326
|
radius: /* @__PURE__ */ optional(zBounded(0, 32)),
|
|
5324
5327
|
font: /* @__PURE__ */ optional(/* @__PURE__ */ _enum(BADGE_FONTS, { error: `must be one of ${BADGE_FONTS.join(", ")}` })),
|