repometry 0.4.0 → 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.0",
3
+ "version": "0.4.2",
4
4
  "description": "Track repository metrics without SaaS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -334,11 +334,12 @@
334
334
  .fx-resizing { cursor: col-resize; user-select: none; }
335
335
  .fx-main { display: grid; gap: 1rem; min-width: 0; }
336
336
  /* The aside needs no frame: the splitter and the framed list beside it already set it apart. */
337
- .fx-aside { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow: auto; margin: 0; padding: .125rem .125rem 1rem 0; }
337
+ /* The side column scrolls down only: what it holds wraps or ellipsizes, never pushes it sideways. */
338
+ .fx-aside { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow: hidden auto; margin: 0; padding: .125rem .125rem 1rem 0; }
338
339
  .fx-aside-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: .75rem; }
339
340
  .fx-view .fx-aside-heading h2 { font-size: 1rem; line-height: 1.35; overflow-wrap: anywhere; }
340
341
  .fx-aside-path { grid-column: 1; margin: .125rem 0 0; font-family: var(--mono); font-size: .75rem; color: var(--muted); overflow-wrap: anywhere; }
341
- .fx-aside .fx-close { grid-row: 1; grid-column: 2; justify-content: center; width: 1.75rem; min-height: 1.75rem; margin-right: -.375rem; color: var(--secondary); text-decoration: none; border-radius: 6px; }
342
+ .fx-aside .fx-close { grid-row: 1; grid-column: 2; justify-content: center; width: 1.75rem; min-height: 1.75rem; margin-right: -.125rem; color: var(--secondary); text-decoration: none; border-radius: 6px; }
342
343
  .fx-aside .fx-close::before { content: ""; width: .75rem; height: .75rem; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M1.5 1.5l9 9m0-9l-9 9' stroke='black' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M1.5 1.5l9 9m0-9l-9 9' stroke='black' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat; }
343
344
  .fx-aside .fx-close:hover { color: var(--ink); background: var(--surface-2); }
344
345
  .fx-kv { margin: .75rem 0 0; font-variant-numeric: tabular-nums; }
@@ -459,9 +460,13 @@
459
460
  .src[data-layer="coverage"] .src-line { grid-template-columns: 3.25rem 3rem max-content; }
460
461
  .src[data-layer="coverage"] .src-cov { display: flex; flex: 1; align-self: stretch; align-items: center; justify-content: flex-end;
461
462
  padding-right: .5rem; font-family: var(--sans); font-size: .6875rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
462
- .src-cov-mark-covered { color: var(--cov-hit-ink); background: var(--cov-hit-bg); }
463
- .src-cov-mark-partial { color: var(--cov-part-ink); background: var(--cov-part-bg); }
464
- .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); }
465
470
  .src-target, .src-target:hover { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
466
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); }
467
472
  .src-band-1 { color: var(--heat-ink); background: var(--heat-1); box-shadow: none; }
@@ -102,8 +102,9 @@ export type TokenKind = '' | 'c' | 's' | 'n' | 'k';
102
102
  */
103
103
  export declare function tokenizer(path: string): (line: string) => [TokenKind, string][];
104
104
  /**
105
- * The tint a gap of blank and comment lines takes so a run of one state stays one strip: the state of the measured
106
- * lines on both sides, where they agree. A gap between different states, or at the file's start or end, stays plain.
105
+ * The tint a gap of blank and comment lines takes so the strip has no breaks: the state of the measured line above it,
106
+ * which the gap closes, or for a gap at the file's start, of the line below. A gap beside a line that was not measured
107
+ * takes its other neighbour, and one with no measured neighbour stays plain.
107
108
  */
108
109
  export declare function bridgeStates(states: ReadonlyMap<number, LineState>, codeless: readonly boolean[]): Map<number, LineState>;
109
110
  /** A line with no code: blank, or nothing but comment. */
@@ -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) {
@@ -372,8 +374,9 @@ export function tokenizer(path) {
372
374
  };
373
375
  }
374
376
  /**
375
- * The tint a gap of blank and comment lines takes so a run of one state stays one strip: the state of the measured
376
- * lines on both sides, where they agree. A gap between different states, or at the file's start or end, stays plain.
377
+ * The tint a gap of blank and comment lines takes so the strip has no breaks: the state of the measured line above it,
378
+ * which the gap closes, or for a gap at the file's start, of the line below. A gap beside a line that was not measured
379
+ * takes its other neighbour, and one with no measured neighbour stays plain.
377
380
  */
378
381
  export function bridgeStates(states, codeless) {
379
382
  const bridged = new Map();
@@ -386,10 +389,10 @@ export function bridgeStates(states, codeless) {
386
389
  let end = line;
387
390
  while (end < codeless.length && !states.has(end + 1) && codeless[end])
388
391
  end += 1;
389
- const before = states.get(line - 1);
390
- if (before && before === states.get(end + 1))
392
+ const state = states.get(line - 1) ?? states.get(end + 1);
393
+ if (state)
391
394
  for (let at = line; at <= end; at++)
392
- bridged.set(at, before);
395
+ bridged.set(at, state);
393
396
  line = end + 1;
394
397
  }
395
398
  return bridged;
@@ -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