repometry 0.4.1 → 0.4.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repometry",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Track repository metrics without SaaS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -460,9 +460,13 @@
460
460
  .src[data-layer="coverage"] .src-line { grid-template-columns: 3.25rem 3rem max-content; }
461
461
  .src[data-layer="coverage"] .src-cov { display: flex; flex: 1; align-self: stretch; align-items: center; justify-content: flex-end;
462
462
  padding-right: .5rem; font-family: var(--sans); font-size: .6875rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
463
- .src-cov-mark-covered { color: var(--cov-hit-ink); background: var(--cov-hit-bg); }
464
- .src-cov-mark-partial { color: var(--cov-part-ink); background: var(--cov-part-bg); }
465
- .src-cov-mark-uncovered { color: var(--cov-miss-ink); background: var(--cov-miss-bg); }
463
+ .src-cov-mark-covered { --cov-bg: var(--cov-hit-bg); color: var(--cov-hit-ink); background: var(--cov-bg); }
464
+ .src-cov-mark-partial { --cov-bg: var(--cov-part-bg); color: var(--cov-part-ink); background: var(--cov-bg); }
465
+ .src-cov-mark-uncovered { --cov-bg: var(--cov-miss-bg); color: var(--cov-miss-ink); background: var(--cov-bg); }
466
+ /* The strip runs from the panel's head to its foot: the first and last cells reach over the code's own padding. */
467
+ .src[data-layer="coverage"] .src-first .src-cov { box-shadow: 0 -.375rem 0 var(--cov-bg); }
468
+ .src[data-layer="coverage"] .src-last .src-cov { box-shadow: 0 .75rem 0 var(--cov-bg); }
469
+ .src[data-layer="coverage"] .src-first.src-last .src-cov { box-shadow: 0 -.375rem 0 var(--cov-bg), 0 .75rem 0 var(--cov-bg); }
466
470
  .src-target, .src-target:hover { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
467
471
  .src-complexity { min-width: 1.375rem; padding: 0 .25rem; font-family: var(--sans); font-size: .6875rem; font-weight: 650; line-height: 1.125rem; text-align: center; border-radius: 4px; color: var(--secondary); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--rule); }
468
472
  .src-band-1 { color: var(--heat-ink); background: var(--heat-1); box-shadow: none; }
@@ -172,6 +172,8 @@ export function renderSource(container, text, options) {
172
172
  fragment.append(box);
173
173
  }
174
174
  }
175
+ rows[0]?.classList.add('src-first');
176
+ rows.at(-1)?.classList.add('src-last');
175
177
  code.append(fragment);
176
178
  container.replaceChildren(code);
177
179
  function reveal(line, scroll = true) {
@@ -1,6 +1,5 @@
1
1
  import { coverageGrade, securityGrade } from '../../../core/model/quality-summary.js';
2
- /** The report's own grade colours, so a badge in a README reads as the report does. */
3
- const colors = { A: '#1f9d5a', B: '#74a83a', C: '#d9a400', D: '#ec8a2c', F: '#db4a3f' };
2
+ const colors = { A: '#5ec269', B: '#74a83a', C: '#d9a400', D: '#ec8a2c', F: '#db4a3f' };
4
3
  const unavailable = '#6b7684';
5
4
  /** The README badges. Security is available when the inspection recorded scanner counts. */
6
5
  export function badges(report, quality, security) {
@@ -20,30 +19,54 @@ export function badges(report, quality, security) {
20
19
  }
21
20
  function badge(name, value, grade) {
22
21
  const fill = grade ? colors[grade] : unavailable;
23
- const labelWidth = Math.max(11, name.length * 7) + 12;
24
- const valueWidth = Math.max(11, value.length * 7) + 12;
22
+ const labelTextWidth = Math.round(textWidth(name));
23
+ const valueTextWidth = Math.round(textWidth(value) * 1.12);
24
+ const padding = 7;
25
+ const labelWidth = labelTextWidth + 2 * padding;
26
+ const valueWidth = valueTextWidth + 2 * padding;
25
27
  const width = labelWidth + valueWidth;
26
- const labelCenter = labelWidth / 2;
27
- const valueCenter = labelWidth + valueWidth / 2;
28
+ const clipId = `${name}-clip`;
29
+ const labelId = `${name}-label`;
30
+ const valueId = `${name}-value`;
28
31
  return Buffer.from(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="20" viewBox="0 0 ${width} 20" role="img" aria-label="${name}: ${value}">
29
32
  <defs>
30
- <clipPath id="badge"><rect width="${width}" height="20" rx="3"/></clipPath>
31
- <linearGradient id="shade" x2="0" y2="100%">
32
- <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
33
- <stop offset="1" stop-color="#000" stop-opacity=".1"/>
33
+ <clipPath id="${clipId}"><rect width="${width}" height="20" rx="3"/></clipPath>
34
+ <linearGradient id="${labelId}" x2="0" y2="100%">
35
+ <stop stop-color="#475265"/>
36
+ <stop offset="1" stop-color="#3a4557"/>
37
+ </linearGradient>
38
+ <linearGradient id="${valueId}" x2="0" y2="100%">
39
+ <stop stop-color="#fff" stop-opacity=".06"/>
40
+ <stop offset="1" stop-color="#000" stop-opacity=".06"/>
34
41
  </linearGradient>
35
42
  </defs>
36
- <g clip-path="url(#badge)">
37
- <rect width="${labelWidth}" height="20" fill="#555"/>
43
+ <g clip-path="url(#${clipId})">
44
+ <rect width="${labelWidth}" height="20" fill="url(#${labelId})"/>
38
45
  <rect x="${labelWidth}" width="${valueWidth}" height="20" fill="${fill}"/>
39
- <rect width="${width}" height="20" fill="url(#shade)"/>
46
+ <rect x="${labelWidth}" width="${valueWidth}" height="20" fill="url(#${valueId})"/>
40
47
  </g>
41
- <g aria-hidden="true" fill="#fff" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11" text-anchor="middle">
42
- <text x="${labelCenter}" y="15" fill="#010101" fill-opacity=".3">${name}</text>
43
- <text x="${valueCenter}" y="15" fill="#010101" fill-opacity=".3">${value}</text>
44
- <text x="${labelCenter}" y="14">${name}</text>
45
- <text x="${valueCenter}" y="14">${value}</text>
48
+ <g aria-hidden="true" fill="#fff" font-family="-apple-system,BlinkMacSystemFont,'Segoe UI','Noto Sans',Helvetica,Arial,sans-serif" font-size="11">
49
+ <text x="${padding}" y="14" font-weight="400" textLength="${labelTextWidth}" lengthAdjust="spacingAndGlyphs">${name}</text>
50
+ <text x="${labelWidth + padding}" y="14" font-weight="700" textLength="${valueTextWidth}" lengthAdjust="spacingAndGlyphs">${value}</text>
46
51
  </g>
47
52
  </svg>\n`);
48
53
  }
54
+ function textWidth(text) {
55
+ let width = 0;
56
+ for (const character of text) {
57
+ if (/[ijl]/.test(character))
58
+ width += 3.4;
59
+ else if (/[mwMW]/.test(character))
60
+ width += 7.6;
61
+ else if (/[A-Z]/.test(character))
62
+ width += 7.4;
63
+ else if (/[0-9%]/.test(character))
64
+ width += 6.6;
65
+ else if (character === '—')
66
+ width += 11;
67
+ else
68
+ width += 6.2;
69
+ }
70
+ return width;
71
+ }
49
72
  //# sourceMappingURL=badges.js.map