@vernikr/size-report 2.5.0 → 2.6.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 +124 -64
- package/package.json +2 -2
- package/src/check.js +1 -1
- package/src/data.js +0 -18
- package/src/doctor.js +4 -4
- package/src/history.js +3 -9
- package/src/init.js +2 -1
- package/src/locales.js +9 -9
- package/src/metrics.js +45 -63
- package/src/minify.js +2 -2
- package/src/modes.js +8 -8
- package/src/optional.js +2 -2
- package/src/page/app.css +6 -8
- package/src/page/app.js +116 -67
- package/src/page/build.js +161 -19
- package/src/page/panel.js +111 -20
- package/src/page/payload.js +168 -0
- package/src/page/state.js +87 -32
- package/src/page/table.js +260 -73
- package/src/parse.js +1 -1
- package/src/project.js +2 -2
- package/src/strip/guard.js +4 -3
- package/src/strip.js +4 -5
- package/src/table.css +44 -8
- package/src/tokens.js +5 -6
- package/templates/README.md +3 -3
package/src/table.css
CHANGED
|
@@ -1,23 +1,59 @@
|
|
|
1
1
|
/* One type face for the whole table; numbers line up by their digits thanks to tabular-nums rather than through a
|
|
2
|
-
* monospaced font.
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
* monospaced font.
|
|
3
|
+
*
|
|
4
|
+
* The layout is **fixed**, and the widths come from the `<colgroup>` the page builds along with the table (`appCols`):
|
|
5
|
+
* laying this table out as `auto` means measuring every cell of it — 174 468 of them here — to assign the widths of
|
|
6
|
+
* 265 columns.
|
|
7
|
+
*
|
|
8
|
+
* **Both declarations are needed, and the width is the one that is easy to lose.** A fixed layout with `width: auto`
|
|
9
|
+
* falls back to the automatic algorithm — the specification says so, and Chrome does it: the columns' widths are then
|
|
10
|
+
* ignored, the cells are measured all the same, and nothing looks wrong except that nothing is won. `100%` is what
|
|
11
|
+
* gives the table a definite width: it is the window, and the columns are wider than it, so the table keeps the widths
|
|
12
|
+
* it was given (`check` and the browser probe both watch this). */
|
|
13
|
+
table { border-collapse: collapse; font-variant-numeric: tabular-nums; table-layout: fixed; width: 100%; }
|
|
14
|
+
/* A counted width is the **border box** of a column — the padding of its cells and the group's border are inside it
|
|
15
|
+
* (measured in Chrome: `7ch` gave a 47px content box with 4px of padding each side). `--ch` is that count in
|
|
16
|
+
* characters, written by the page per column; `--clip` is the fixed measure a commit's caption is clipped to, and the
|
|
17
|
+
* one a narrow window may shorten (app.css). */
|
|
18
|
+
#grid { --cell-pad: 4px; --col-line: 1px; --clip: 190px; }
|
|
19
|
+
th, td { padding: 2px var(--cell-pad); border-bottom: 1px solid rgba(127, 127, 127, .25); white-space: nowrap; }
|
|
20
|
+
/* The count over-measures a sign and a thin space, which is the safe side: a cell clips nothing, so a column a
|
|
21
|
+
* character short would show a number running over its neighbour. */
|
|
22
|
+
#grid col { width: calc(var(--ch, 0px) + var(--cell-pad) * 2 + var(--col-line)); }
|
|
23
|
+
#grid col.c-commit { width: calc(var(--clip) + var(--cell-pad) * 2 + var(--col-line)); }
|
|
5
24
|
/* A two-row header: both rows stick, so the second is offset by exactly the first one's height (line-height 20 plus the
|
|
6
25
|
* 2px bottom border), or the rows would overlap. */
|
|
7
|
-
thead th { position: sticky; top: 0; z-index: 3; background: Canvas; text-align: center; line-height: 20px; padding: 0
|
|
26
|
+
thead th { position: sticky; top: 0; z-index: 3; background: Canvas; text-align: center; line-height: 20px; padding: 0 var(--cell-pad); }
|
|
8
27
|
thead tr:first-child th { border-bottom-width: 2px; }
|
|
9
28
|
thead tr:last-child th { top: 22px; }
|
|
10
29
|
.num { text-align: right; }
|
|
11
|
-
|
|
30
|
+
/* The group's left border is carried by the first *enabled* metric: four rules instead of the eight combinations of
|
|
31
|
+
* "which of them is first", so switching a metric off moves the border by itself and no line of JS knows about it.
|
|
32
|
+
* The registry holds four metrics (`raw`, `min`, `tok`, `gzip`) — that is the count below, and `test/page-view.test.js`
|
|
33
|
+
* reddens if a fifth name appears. A group's heading (`.gh`) spans its metrics rather than belonging to one, so its
|
|
34
|
+
* own left edge is there while any metric is on (`.m-none` is set when the reader switched them all off). */
|
|
35
|
+
#grid .g { border-left: 0; }
|
|
36
|
+
#grid:not(.m-off-0) .g.m0,
|
|
37
|
+
#grid.m-off-0:not(.m-off-1) .g.m1,
|
|
38
|
+
#grid.m-off-0.m-off-1:not(.m-off-2) .g.m2,
|
|
39
|
+
#grid.m-off-0.m-off-1.m-off-2:not(.m-off-3) .g.m3 { border-left: 1px solid rgba(127, 127, 127, .35); }
|
|
40
|
+
#grid:not(.m-none) .gh { border-left: 1px solid rgba(127, 127, 127, .35); }
|
|
41
|
+
/* A metric switched off hides all of its cells and both of its headings at once — one class on the table instead of a
|
|
42
|
+
* pass over the metric's cells (measured: 265 operations against 56 496). */
|
|
43
|
+
#grid.m-off-0 .m0, #grid.m-off-1 .m1, #grid.m-off-2 .m2, #grid.m-off-3 .m3 { display: none; }
|
|
44
|
+
/* A file's column switched off: its cells and its headings together. The hidden column keeps its place in the markup,
|
|
45
|
+
* so the columns that stay do not move. */
|
|
46
|
+
#grid .off { display: none; }
|
|
12
47
|
/* The sticky left column: an opaque background (Canvas), or numbers would show through the cell when scrolling sideways. A
|
|
13
48
|
* tier above the neighbouring cells (2) and below the header (3); the header's corner is above them all, or the column groups
|
|
14
49
|
* would crawl over the commit column. */
|
|
15
50
|
.c-commit { position: sticky; left: 0; z-index: 2; background: Canvas; text-align: left; font-weight: 400; }
|
|
16
51
|
.c-commit a { color: inherit; }
|
|
17
52
|
thead .c-commit { z-index: 6; }
|
|
18
|
-
/* This block
|
|
19
|
-
*
|
|
20
|
-
|
|
53
|
+
/* This block fills the commit column, whose width is set by the column itself (`#grid col.c-commit`). It took the
|
|
54
|
+
* column's measure with it: the cell's content would otherwise go past its borders and be drawn over the neighbouring
|
|
55
|
+
* numbers, because a table cell clips nothing. */
|
|
56
|
+
.clip { display: flex; align-items: baseline; gap: 6px; width: 100%; }
|
|
21
57
|
.when { flex: none; opacity: .7; }
|
|
22
58
|
.subj { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; display: block; }
|
|
23
59
|
.subj.plain { opacity: .7; }
|
package/src/tokens.js
CHANGED
|
@@ -4,7 +4,7 @@ import { loadOptional } from './optional.js';
|
|
|
4
4
|
/* The tokenizer follows the same discipline as the minifier: an optional dependency, loaded
|
|
5
5
|
* lazily (how that works: `src/optional.js`). One difference: the tokenizer takes any text and
|
|
6
6
|
* has nothing to refuse, so a missing dependency is not a refusal but a different count — an
|
|
7
|
-
* estimate by length,
|
|
7
|
+
* estimate by length, named as such in the metric label.
|
|
8
8
|
*
|
|
9
9
|
* The family is about models, the encoding about the number: the same file counts differently
|
|
10
10
|
* under `cl100k_base` and `o200k_base`, which is why the encoding is chosen next to the family
|
|
@@ -21,8 +21,7 @@ export const TOKEN_DEFAULTS = { family: 'openai', encoding: 'o200k_base' };
|
|
|
21
21
|
/* The estimate without a dictionary. The coefficient was taken from this repository's own
|
|
22
22
|
* texts (Russian documents and code): `README.md` gave 3.1 characters per token, the archived
|
|
23
23
|
* journal `worklog/archive/WORKLOG.md` about 3.0. For Latin script the same estimate overstates
|
|
24
|
-
* the count (about 4 characters per token there), which is why
|
|
25
|
-
* approximation. */
|
|
24
|
+
* the count (about 4 characters per token there), which is why the method says so in words. */
|
|
26
25
|
export const CHARS_PER_TOKEN = 3;
|
|
27
26
|
|
|
28
27
|
/* Formats for which counting tokens makes no sense: a picture, a font or an archive is bytes,
|
|
@@ -53,7 +52,7 @@ function familyOf(settings) {
|
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
/* Counting one text: with the dictionary if there is one, by estimate otherwise. Both answers
|
|
56
|
-
* are a number of text units, and what tells them apart is the metric label (`
|
|
55
|
+
* are a number of text units, and what tells them apart is the metric label (`method`) rather
|
|
57
56
|
* than the value, which is why one cannot be passed off as the other. */
|
|
58
57
|
export function tokenCount(text, settings) {
|
|
59
58
|
const { tool } = tokenizer(settings);
|
|
@@ -70,8 +69,8 @@ export function estimate(text) {
|
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
/* Whether the file is binary, since counting tokens means nothing for it. The list of formats
|
|
73
|
-
* is owned here, so
|
|
74
|
-
*
|
|
72
|
+
* is owned here, so the metric label asks about a file here instead of keeping a list of its
|
|
73
|
+
* own. */
|
|
75
74
|
export function isBinary(file) {
|
|
76
75
|
return BINARY_EXTS.indexOf(path.extname(file).toLowerCase()) >= 0;
|
|
77
76
|
}
|
package/templates/README.md
CHANGED
|
@@ -37,9 +37,9 @@ What is worth knowing about the template's values:
|
|
|
37
37
|
- `metrics: ["raw", "min", "tok"]` — the report's three measurements. `min` is counted by the real minifier
|
|
38
38
|
(`minify.engine: "esbuild"`) and `tok` by the `o200k_base` dictionary. Both travel as optional
|
|
39
39
|
dependencies of the package and are installed by an ordinary installation; without them (an installation
|
|
40
|
-
without the optional dependencies, a platform that has none) the tool still works, but says
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
without the optional dependencies, a platform that has none) the tool still works, but says that the
|
|
41
|
+
numbers were counted another way, and returns **code 4** — that is a named different count rather than an
|
|
42
|
+
error of the settings.
|
|
43
43
|
- `fixCommand` — the command the report's signature and the refusals quote. In the template it is
|
|
44
44
|
`node node_modules/@vernikr/size-report/bin/size.js --write` — the path to the installed package inside
|
|
45
45
|
the project. **The package name as a command cannot stand here:** `npx <name>` in a project without the
|