paperlint 18.1.0 → 18.2.1

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.
Files changed (100) hide show
  1. package/README.md +2 -2
  2. package/dist/adapters/latex/document-class.d.ts +28 -5
  3. package/dist/adapters/latex/document-class.d.ts.map +1 -1
  4. package/dist/adapters/latex/document-class.js +208 -21
  5. package/dist/adapters/latex/document-class.js.map +1 -1
  6. package/dist/adapters/latex/index.d.ts +4 -4
  7. package/dist/adapters/latex/index.d.ts.map +1 -1
  8. package/dist/adapters/latex/index.js +5 -2
  9. package/dist/adapters/latex/index.js.map +1 -1
  10. package/dist/adapters/latex/parse.d.ts.map +1 -1
  11. package/dist/adapters/latex/parse.js +5 -0
  12. package/dist/adapters/latex/parse.js.map +1 -1
  13. package/dist/adapters/latex/prose.d.ts.map +1 -1
  14. package/dist/adapters/latex/prose.js +20 -4
  15. package/dist/adapters/latex/prose.js.map +1 -1
  16. package/dist/domain/body-pages.d.ts.map +1 -1
  17. package/dist/domain/body-pages.js +4 -2
  18. package/dist/domain/body-pages.js.map +1 -1
  19. package/dist/domain/tex-document.d.ts +52 -4
  20. package/dist/domain/tex-document.d.ts.map +1 -1
  21. package/dist/domain/tex-document.js +9 -0
  22. package/dist/domain/tex-document.js.map +1 -1
  23. package/dist/eslint-rules/latex-language.d.ts +10 -0
  24. package/dist/eslint-rules/latex-language.d.ts.map +1 -1
  25. package/dist/eslint-rules/latex-language.js +41 -2
  26. package/dist/eslint-rules/latex-language.js.map +1 -1
  27. package/dist/ports/latex.d.ts +13 -1
  28. package/dist/ports/latex.d.ts.map +1 -1
  29. package/dist/presets.d.ts +15 -0
  30. package/dist/presets.d.ts.map +1 -1
  31. package/dist/presets.js +9 -0
  32. package/dist/presets.js.map +1 -1
  33. package/dist/tex-requirements.d.ts +2 -0
  34. package/dist/tex-requirements.d.ts.map +1 -1
  35. package/dist/tex-requirements.js +7 -2
  36. package/dist/tex-requirements.js.map +1 -1
  37. package/dist/tex-venue-rules.d.ts +36 -3
  38. package/dist/tex-venue-rules.d.ts.map +1 -1
  39. package/dist/tex-venue-rules.js +181 -33
  40. package/dist/tex-venue-rules.js.map +1 -1
  41. package/docs/rules/cycle/port-done.md +3 -0
  42. package/docs/rules/tex/negated-sentences.md +1 -1
  43. package/docs/rules/tex/template.md +96 -1
  44. package/docs/rules.md +19 -14
  45. package/docs/venues.md +51 -12
  46. package/eslint-rules/latex-language.test.mjs +64 -1
  47. package/eslint-rules/latex-language.ts +44 -2
  48. package/eslint.config.mjs +1 -0
  49. package/fixtures/build-e2e/neurips/PIPELINE-STATUS.md +3 -0
  50. package/fixtures/build-e2e/neurips/expect.json +20 -0
  51. package/fixtures/build-e2e/neurips/paper.tex +60 -0
  52. package/fixtures/build-e2e/neurips/paperlint.json +1 -0
  53. package/fixtures/build-e2e/neurips-nostyle/PIPELINE-STATUS.md +3 -0
  54. package/fixtures/build-e2e/neurips-nostyle/expect.json +26 -0
  55. package/fixtures/build-e2e/neurips-nostyle/paper.tex +56 -0
  56. package/fixtures/build-e2e/neurips-nostyle/paperlint.json +1 -0
  57. package/fixtures/build-e2e/neurips-over/PIPELINE-STATUS.md +3 -0
  58. package/fixtures/build-e2e/neurips-over/expect.json +24 -0
  59. package/fixtures/build-e2e/neurips-over/paper.tex +56 -0
  60. package/fixtures/build-e2e/neurips-over/paperlint.json +1 -0
  61. package/fixtures/real-papers.test.ts +17 -6
  62. package/package.json +3 -1
  63. package/presets/aaai-2027.jsonc +126 -0
  64. package/presets/aaai-2027.md +127 -0
  65. package/presets/aaai-press.jsonc +167 -0
  66. package/presets/aaai-press.md +126 -0
  67. package/presets/aidc-2026.jsonc +11 -11
  68. package/presets/icml-2027.jsonc +111 -0
  69. package/presets/icml-2027.md +130 -0
  70. package/presets/icml-style.jsonc +125 -0
  71. package/presets/icml-style.md +77 -0
  72. package/presets/neurips-2026.jsonc +123 -0
  73. package/presets/neurips-2026.md +137 -0
  74. package/presets/neurips-style.jsonc +113 -0
  75. package/presets/neurips-style.md +85 -0
  76. package/presets/venue-profile.schema.json +6 -0
  77. package/skills/build-label-page/scripts/label-page-browser.test.ts +275 -114
  78. package/src/adapters/latex/document-class.ts +292 -20
  79. package/src/adapters/latex/index.test.ts +310 -0
  80. package/src/adapters/latex/index.ts +12 -3
  81. package/src/adapters/latex/parse.ts +5 -0
  82. package/src/adapters/latex/prose.ts +27 -4
  83. package/src/cli.test.ts +6 -1
  84. package/src/domain/body-pages.test.ts +22 -6
  85. package/src/domain/body-pages.ts +4 -2
  86. package/src/domain/tex-document.ts +64 -5
  87. package/src/folder-venue-rule.test.ts +51 -0
  88. package/src/new-paper.test.ts +2 -2
  89. package/src/paper-settings-commands.test.ts +1 -1
  90. package/src/ports/latex.ts +14 -0
  91. package/src/preset-card-rule.test.ts +44 -27
  92. package/src/presets.test.ts +177 -1
  93. package/src/presets.ts +27 -0
  94. package/src/register-bands.test.ts +2 -2
  95. package/src/rule-cases.test.ts +52 -0
  96. package/src/tex-requirements.harness.ts +17 -3
  97. package/src/tex-requirements.ts +13 -2
  98. package/src/tex-venue-rules.test.ts +1020 -0
  99. package/src/tex-venue-rules.ts +248 -38
  100. package/src/venue-rules.test.ts +369 -2
@@ -99,6 +99,158 @@ const sharedBrowser = async (): Promise<Browser> =>
99
99
  afterAll(async () => {
100
100
  await launched?.close();
101
101
  });
102
+ /**
103
+ * A page in a context of its own that no request leaves: the page asks Google Fonts for Roboto, and
104
+ * a font that arrives after the cards are drawn reflows them under a test that is measuring them. In
105
+ * CI it arrived between the two reads of one test (run 44507805064): the marked line read in the
106
+ * fallback font, its note in Roboto, the note 17.6 px up inside the line. Refused, the page is drawn
107
+ * once in the machine's own font. A route a test adds later answers first.
108
+ */
109
+ const offlinePage = async (
110
+ options?: Parameters<Browser["newPage"]>[0],
111
+ ): Promise<Page> => {
112
+ const page = await (await sharedBrowser()).newPage(options);
113
+ await page.route("**/*", (r) => r.abort());
114
+ return page;
115
+ };
116
+
117
+ const Box = z
118
+ .object({
119
+ x: z.number(),
120
+ y: z.number(),
121
+ width: z.number(),
122
+ height: z.number(),
123
+ })
124
+ .nullable();
125
+ /**
126
+ * The boxes of several elements, read in one frame, for a check whose requirement IS a distance (the
127
+ * space between two cards, a pointer's path): each `boundingBox()` is a read of its own, and a reflow
128
+ * between two of them (a font arriving, a render) compares boxes of two different layouts. Like
129
+ * `boundingBox()`, null for an element that has no box. Where and in what order things sit is
130
+ * asserted on the page's structure instead (`stacking`, `placeOf`), which no timing moves.
131
+ */
132
+ const boxesInOneFrame = async (of: readonly Locator[]) => {
133
+ const [first] = of;
134
+ assert.ok(first !== undefined);
135
+ const handles = await Promise.all(of.map(async (l) => l.elementHandle()));
136
+ return z.array(Box).parse(
137
+ await first.page().evaluate(
138
+ (els) =>
139
+ els.map((e) => {
140
+ if (e.getClientRects().length === 0) return null;
141
+ const r = e.getBoundingClientRect();
142
+ return { x: r.x, y: r.y, width: r.width, height: r.height };
143
+ }),
144
+ handles,
145
+ ),
146
+ );
147
+ };
148
+
149
+ /**
150
+ * How each element after the first sits against the one before it, read in one call from the
151
+ * structure and the computed style, never from pixels: "stacked" when, under the nearest element
152
+ * holding both, the child holding it comes later, both children are blocks in the flow, and that
153
+ * element lays its children out one under another (a block, or a column flex box). Anything else is
154
+ * named, so a failure says what changed.
155
+ */
156
+ const stacking = async (of: readonly Locator[]) => {
157
+ const [first] = of;
158
+ assert.ok(first !== undefined);
159
+ const handles = await Promise.all(of.map(async (l) => l.elementHandle()));
160
+ return z.array(z.string()).parse(
161
+ await first.page().evaluate((els) => {
162
+ const inFlow = (c: Element) => {
163
+ const st = getComputedStyle(c);
164
+ return (
165
+ !st.display.startsWith("inline") &&
166
+ st.float === "none" &&
167
+ st.position !== "absolute" &&
168
+ st.position !== "fixed"
169
+ );
170
+ };
171
+ const column = (h: Element) => {
172
+ const st = getComputedStyle(h);
173
+ return (
174
+ st.display === "block" ||
175
+ (st.display === "flex" && st.flexDirection === "column")
176
+ );
177
+ };
178
+ // The nearest element holding both, and the child of it that holds one of them.
179
+ const hostOf = (a: Element, b: Element) => {
180
+ let h = a.parentElement;
181
+ while (h !== null && !h.contains(b)) h = h.parentElement;
182
+ return h;
183
+ };
184
+ const childUnder = (host: Element, n: Element) => {
185
+ let c = n;
186
+ while (c.parentElement !== host && c.parentElement !== null)
187
+ c = c.parentElement;
188
+ return c;
189
+ };
190
+ const verdict = (a: Element, b: Element) => {
191
+ const host = hostOf(a, b);
192
+ if (host === null || a.contains(b) || b.contains(a))
193
+ return "one holds the other";
194
+ const [ca, cb] = [childUnder(host, a), childUnder(host, b)];
195
+ const order = Array.from(host.children);
196
+ if (order.indexOf(ca) >= order.indexOf(cb)) return "out of order";
197
+ if (!inFlow(ca) || !inFlow(cb)) return "not a block in the flow";
198
+ const hs = getComputedStyle(host);
199
+ return column(host)
200
+ ? "stacked"
201
+ : `not one under another (${hs.display} ${hs.flexDirection})`;
202
+ };
203
+ return els.slice(1).map((b, i) => {
204
+ const a = els[i];
205
+ return a === undefined ? "no element before it" : verdict(a, b);
206
+ });
207
+ }, handles),
208
+ );
209
+ };
210
+ /** A `data-test-meta` as the page wrote it, read back as JSON. */
211
+ const MetaText = z
212
+ .string()
213
+ .nullable()
214
+ .transform((raw): unknown => JSON.parse(raw ?? "null"));
215
+ const Placed = z.object({
216
+ kind: z.string().nullable(),
217
+ meta: MetaText,
218
+ });
219
+ const Place = z.object({
220
+ after: Placed.nullable(),
221
+ linesBeside: z.number(),
222
+ display: z.string(),
223
+ inFlow: z.boolean(),
224
+ });
225
+ /**
226
+ * Where an element sits in its block, read from the structure: the element right before it (its
227
+ * `data-test` and values), how many code lines share its parent, and whether it is a block in the
228
+ * flow, so it starts on a line of its own right under that element.
229
+ */
230
+ const placeOf = async (l: Locator) =>
231
+ Place.parse(
232
+ await l.evaluate((e) => {
233
+ const prev = e.previousElementSibling;
234
+ const st = getComputedStyle(e);
235
+ return {
236
+ after:
237
+ prev === null
238
+ ? null
239
+ : {
240
+ kind: prev.getAttribute("data-test"),
241
+ meta: prev.getAttribute("data-test-meta"),
242
+ },
243
+ linesBeside: Array.from(e.parentElement?.children ?? []).filter(
244
+ (c) => c.getAttribute("data-test") === "code-line",
245
+ ).length,
246
+ display: st.display,
247
+ inFlow:
248
+ st.float === "none" &&
249
+ st.position !== "absolute" &&
250
+ st.position !== "fixed",
251
+ };
252
+ }),
253
+ );
102
254
 
103
255
  /** A browser test launches Chromium and types: far above vitest's 5 s default on a slow runner. */
104
256
  const BROWSER_TEST_MS = 60_000;
@@ -110,8 +262,7 @@ async function onApprovalPage(
110
262
  filter: "all" | "next" = "all",
111
263
  ): Promise<void> {
112
264
  const { page: html } = build(setup(name, approval()));
113
- const browser = await sharedBrowser();
114
- const page = await browser.newPage();
265
+ const page = await offlinePage();
115
266
  try {
116
267
  await page.addInitScript(STORE(PRACTICE_DONE, echoMs));
117
268
  await page.goto("about:blank");
@@ -223,8 +374,7 @@ test(
223
374
  "a Keep needs no reason and writes none: the page stays quiet",
224
375
  async () => {
225
376
  const { page: html } = build(setup("browser-keep", approval()));
226
- const browser = await sharedBrowser();
227
- const page = await browser.newPage();
377
+ const page = await offlinePage();
228
378
  try {
229
379
  await page.addInitScript(STORE(PRACTICE_DONE, 20));
230
380
  await page.goto("about:blank");
@@ -265,17 +415,15 @@ const WITNESS = {
265
415
  context: URL_LONG,
266
416
  };
267
417
 
268
- /** Where the line, the rule, reading A, reading B and the question sit on a card, top to bottom. */
269
- const blocksOf = async (card: Locator) =>
270
- Promise.all(
271
- [
272
- ".quote",
273
- ".row:has(.lbl:text-is('Rule'))",
274
- ".reading.a",
275
- ".reading.b",
276
- ".ask",
277
- ].map(async (sel) => card.locator(sel).first().boundingBox()),
278
- );
418
+ /** The line, the rule, reading A, reading B and the question of a card, in reading order. */
419
+ const blocksOf = (card: Locator) =>
420
+ [
421
+ ".quote",
422
+ ".row:has(.lbl:text-is('Rule'))",
423
+ ".reading.a",
424
+ ".reading.b",
425
+ ".ask",
426
+ ].map((sel) => card.locator(sel).first());
279
427
 
280
428
  test(
281
429
  "🔴 at phone width the card reads by position: line, rule, reading A above reading B, then the question; nothing pushes the page sideways",
@@ -283,27 +431,22 @@ test(
283
431
  const { page: html } = build(
284
432
  setup("browser-layout", approval({ items: [WITNESS] })),
285
433
  );
286
- const page = await (
287
- await sharedBrowser()
288
- ).newPage({ viewport: { width: 400, height: 900 } });
434
+ const page = await offlinePage({ viewport: { width: 400, height: 900 } });
289
435
  try {
290
436
  await page.addInitScript(STORE(PRACTICE_DONE, 20));
291
437
  await page.setContent(html, { waitUntil: "domcontentloaded" });
292
438
  const card = page.locator("article.item").last();
293
- const boxes = await blocksOf(card);
294
- const [line, rule, a, b, ask] = boxes;
295
- assert.ok(line && rule && a && b && ask, "every block is on the card");
296
- // Guards: each block below the one before, A and B in one column, a gap before the question.
297
- assert.deepEqual(
298
- boxes
299
- .slice(1)
300
- .map(
301
- (x, i) =>
302
- (x?.y ?? 0) >= (boxes[i]?.y ?? 0) + (boxes[i]?.height ?? 0),
303
- ),
304
- [true, true, true, true],
305
- );
306
- assert.equal(a.x, b.x);
439
+ const blocks = blocksOf(card);
440
+ // Guards: each block under the one before, in one column (A above B, never beside it).
441
+ assert.deepEqual(await stacking(blocks), [
442
+ "stacked",
443
+ "stacked",
444
+ "stacked",
445
+ "stacked",
446
+ ]);
447
+ // The space before the question is the requirement itself, so it is a distance, read in one frame.
448
+ const [b, ask] = await boxesInOneFrame(blocks.slice(3));
449
+ assert.ok(b && ask, "both drawn");
307
450
  assert.ok(ask.y - (b.y + b.height) >= 16, "space before the question");
308
451
  assert.deepEqual(
309
452
  await card
@@ -351,9 +494,7 @@ async function onWitnessPage(
351
494
  ]),
352
495
  );
353
496
  const { page: html } = build(setup(name, cfg));
354
- const page = await (
355
- await sharedBrowser()
356
- ).newPage({ viewport: { width: 400, height: 900 } });
497
+ const page = await offlinePage({ viewport: { width: 400, height: 900 } });
357
498
  try {
358
499
  await page.addInitScript(STORE(practiceDone ? done : {}, 20));
359
500
  await page.goto("about:blank");
@@ -419,13 +560,22 @@ test(
419
560
  );
420
561
  assert.ok(ask.top - said.bottom < 40, JSON.stringify(box));
421
562
  assert.ok(docs.top >= ask.bottom, JSON.stringify(box));
422
- const why = card.locator(".clamped", { hasText: "Why:" });
423
- const folded = (await why.boundingBox())?.height ?? 0;
563
+ // Folded is a CSS state, not a height: clamped to three lines with text cut off, then
564
+ // unclamped with nothing cut off. Each state is read in one call on the one element.
565
+ const why = card.locator("p", { hasText: "Why:" });
566
+ const clamp = async () =>
567
+ why.evaluate((e) => [
568
+ getComputedStyle(e).webkitLineClamp,
569
+ e.scrollHeight > e.clientHeight,
570
+ ]);
571
+ const folded = await clamp();
424
572
  await card.getByRole("button", { name: "more" }).first().click();
425
- const opened = await card.locator("p", { hasText: "Why:" }).boundingBox();
426
- assert.ok(
427
- opened && opened.height > folded,
428
- `${String(folded)} → ${String(opened?.height)}`,
573
+ assert.deepEqual(
574
+ [folded, await clamp()],
575
+ [
576
+ ["3", true],
577
+ ["none", false],
578
+ ],
429
579
  );
430
580
  assert.equal(
431
581
  await page.evaluate(() => document.documentElement.scrollWidth),
@@ -506,7 +656,7 @@ test(
506
656
  { answers: p.expected, source: "page" },
507
657
  ]),
508
658
  );
509
- const page = await (await sharedBrowser()).newPage();
659
+ const page = await offlinePage();
510
660
  try {
511
661
  await page.addInitScript(STORE(done, 20));
512
662
  await page.goto("about:blank");
@@ -558,7 +708,7 @@ test(
558
708
  { answers: p.expected, source: "page" },
559
709
  ]),
560
710
  );
561
- const page = await (await sharedBrowser()).newPage();
711
+ const page = await offlinePage();
562
712
  try {
563
713
  await page.addInitScript(
564
714
  STORE(done, 20, {
@@ -593,7 +743,7 @@ test(
593
743
  "🔴 a stored answer to a question the page no longer asks does not stop the next answer from saving",
594
744
  async () => {
595
745
  const { page: html } = build(setup("browser-stale-question", approval()));
596
- const page = await (await sharedBrowser()).newPage();
746
+ const page = await offlinePage();
597
747
  try {
598
748
  await page.addInitScript(
599
749
  STORE(PRACTICE_DONE, 20, {
@@ -639,7 +789,7 @@ test(
639
789
  approval({ items: ITEMS.slice(0, 2).map(approvalCard) }),
640
790
  ),
641
791
  );
642
- const page = await (await sharedBrowser()).newPage();
792
+ const page = await offlinePage();
643
793
  try {
644
794
  await page.addInitScript(STORE(PRACTICE_DONE, 20));
645
795
  await page.goto("about:blank");
@@ -681,7 +831,7 @@ test(
681
831
  )?.[0];
682
832
  const [first] = Object.keys(key.ids).filter((n) => n !== third);
683
833
  assert.ok(third !== undefined && first !== undefined);
684
- const page = await (await sharedBrowser()).newPage();
834
+ const page = await offlinePage();
685
835
  try {
686
836
  await page.addInitScript(
687
837
  STORE(prefixedPractice("second"), 20, {
@@ -730,7 +880,7 @@ test(
730
880
  "🔴 with answerers and no localStorage the page still works: it asks, and writes under the name picked",
731
881
  async () => {
732
882
  const { page: html } = build(setup("browser-answerers-nols", TWO_PAGE()));
733
- const page = await (await sharedBrowser()).newPage();
883
+ const page = await offlinePage();
734
884
  try {
735
885
  await page.addInitScript(
736
886
  `Object.defineProperty(window, "localStorage", { get: function () { throw new Error("denied"); } });`,
@@ -758,9 +908,7 @@ test(
758
908
  const { page: html } = build(
759
909
  setup("browser-dwell", approval({ min_seconds: 2 })),
760
910
  );
761
- const page = await (
762
- await sharedBrowser()
763
- ).newPage({ viewport: { width: 400, height: 700 } });
911
+ const page = await offlinePage({ viewport: { width: 400, height: 700 } });
764
912
  try {
765
913
  await page.addInitScript(STORE(PRACTICE_DONE, 20));
766
914
  await page.goto("about:blank");
@@ -809,9 +957,7 @@ test(
809
957
  const { page: html } = build(
810
958
  setup("browser-dwell-tall", approval({ min_seconds: 2 })),
811
959
  );
812
- const page = await (
813
- await sharedBrowser()
814
- ).newPage({ viewport: { width: 400, height: 300 } });
960
+ const page = await offlinePage({ viewport: { width: 400, height: 300 } });
815
961
  try {
816
962
  await page.addInitScript(STORE(PRACTICE_DONE, 20));
817
963
  await page.goto("about:blank");
@@ -857,9 +1003,7 @@ test(
857
1003
  const { page: html } = build(
858
1004
  setup("browser-dwell-huge", approval({ min_seconds: 2 })),
859
1005
  );
860
- const page = await (
861
- await sharedBrowser()
862
- ).newPage({ viewport: { width: 400, height: 300 } });
1006
+ const page = await offlinePage({ viewport: { width: 400, height: 300 } });
863
1007
  try {
864
1008
  await page.addInitScript(STORE(PRACTICE_DONE, 20));
865
1009
  await page.goto("about:blank");
@@ -892,9 +1036,7 @@ test(
892
1036
  const { page: html } = build(
893
1037
  setup("browser-dwell-hidden", approval({ min_seconds: 2 })),
894
1038
  );
895
- const page = await (
896
- await sharedBrowser()
897
- ).newPage({ viewport: { width: 400, height: 700 } });
1039
+ const page = await offlinePage({ viewport: { width: 400, height: 700 } });
898
1040
  try {
899
1041
  await page.addInitScript(
900
1042
  `window.__vis = "hidden"; Object.defineProperty(Document.prototype, "visibilityState", { configurable: true, get: function () { return window.__vis; } });`,
@@ -1006,9 +1148,7 @@ async function onV7Page(
1006
1148
  setup(name, withTime ? cfg : R.omit(cfg, ["min_seconds"])),
1007
1149
  );
1008
1150
  const done = ["forbid", "allow", "elsewhere"];
1009
- const page = await (
1010
- await sharedBrowser()
1011
- ).newPage({ viewport: { width: 400, height: 800 } });
1151
+ const page = await offlinePage({ viewport: { width: 400, height: 800 } });
1012
1152
  try {
1013
1153
  await page.addInitScript(
1014
1154
  STORE(
@@ -1056,13 +1196,28 @@ const answerOf = async (card: Locator, value: string) => {
1056
1196
  };
1057
1197
  /** The open note: whether it shows, which term, its box, and the terms marked open. */
1058
1198
  const Tip = z.object({ term: z.string(), open: z.boolean() });
1199
+ const TipRead = z.object({
1200
+ meta: MetaText,
1201
+ box: z.object({ x: z.number(), width: z.number() }).nullable(),
1202
+ });
1059
1203
  const tipNow = async (page: Page) => {
1060
1204
  const tip = page.getByTestId("tip");
1061
1205
  const drawn = (await tip.count()) > 0;
1062
- const state = drawn
1063
- ? Tip.parse(await metaOf(tip))
1064
- : { term: "", open: false };
1065
- const box = drawn && state.open ? await tip.boundingBox() : null;
1206
+ // Whether it is inside the viewport is the requirement, so the box is pixels: read in one call
1207
+ // with the state, so an open state and the box of a note already closing are never mixed.
1208
+ const read = drawn
1209
+ ? TipRead.parse(
1210
+ await tip.evaluate((e) => {
1211
+ const r = e.getBoundingClientRect();
1212
+ return {
1213
+ meta: e.getAttribute("data-test-meta"),
1214
+ box: e.getClientRects().length ? { x: r.x, width: r.width } : null,
1215
+ };
1216
+ }),
1217
+ )
1218
+ : { meta: { term: "", open: false }, box: null };
1219
+ const state = Tip.parse(read.meta);
1220
+ const box = state.open ? read.box : null;
1066
1221
  const expanded = await Promise.all(
1067
1222
  (await allByKind(page, "term")).map(async (t) => ({
1068
1223
  term: Term.parse(t.meta).term,
@@ -1204,16 +1359,18 @@ test.each(PLACEMENTS)(
1204
1359
  await term.evaluate((b, at) => {
1205
1360
  b.scrollIntoView({ block: at, behavior: "instant" });
1206
1361
  }, block);
1207
- const from = await term.boundingBox();
1208
- assert.ok(from !== null);
1362
+ // A pointer moves by pixels, so this test reads boxes: the term's to hover it, then the term's
1363
+ // and the note's in one frame for the path between them.
1364
+ const at = await term.boundingBox();
1365
+ assert.ok(at !== null);
1209
1366
  // At its top left corner: a term that wraps has a box whose middle may lie over another term.
1210
- await page.mouse.move(from.x + 4, from.y + 4);
1367
+ await page.mouse.move(at.x + 4, at.y + 4);
1211
1368
  assert.deepEqual(
1212
1369
  [(await tipNow(page)).term, (await tipNow(page)).open],
1213
1370
  [google.term, true],
1214
1371
  );
1215
- const to = await page.getByTestId("tip").boundingBox();
1216
- assert.ok(to !== null);
1372
+ const [from, to] = await boxesInOneFrame([term, page.getByTestId("tip")]);
1373
+ assert.ok(from && to, "the term and its note are drawn");
1217
1374
  // The other terms do not react while the pointer crosses: only the gap is under test, and
1218
1375
  // which term lies in it depends on how the line wraps. The arrow bridges the gap at the
1219
1376
  // middle of the term, so the crossing is at its right end.
@@ -1315,15 +1472,15 @@ test(
1315
1472
  const lines = await allByKind(depth, "code-line");
1316
1473
  const marked = lines.find((l) => CodeLine.parse(l.meta).marked);
1317
1474
  assert.ok(marked !== undefined, "the marked line is drawn");
1318
- const [hit, note] = [
1319
- await marked.loc.boundingBox(),
1320
- await depth.getByTestId("annotation").boundingBox(),
1321
- ];
1322
- assert.ok(hit && note, "both drawn");
1323
- assert.ok(
1324
- note.y >= hit.y + hit.height && note.y - (hit.y + hit.height) < 16,
1325
- JSON.stringify([hit, note]),
1326
- );
1475
+ // Right under the marked line, inside the code: in the code block's own structure the note
1476
+ // comes right after that line, among the block's lines, as a block of its own in the flow.
1477
+ // Structure, not pixels: no font, render or margin moves it (CI run 44507805064).
1478
+ assert.deepEqual(await placeOf(depth.getByTestId("annotation")), {
1479
+ after: { kind: "code-line", meta: marked.meta },
1480
+ linesBeside: lines.length,
1481
+ display: "block",
1482
+ inFlow: true,
1483
+ });
1327
1484
  assert.deepEqual(
1328
1485
  await annotatedFacts(depth),
1329
1486
  annotatedExpected(fixtureCard("card-depth")),
@@ -1380,9 +1537,9 @@ test(
1380
1537
  BROWSER_TEST_MS,
1381
1538
  );
1382
1539
 
1383
- /** Where a part of a card sits, by its `data-test`: the first one of that kind. */
1384
- const boxOf = async (card: Locator, kind: string) =>
1385
- card.getByTestId(kind).first().boundingBox();
1540
+ /** The parts of a card, by their `data-test`: the first one of each kind. */
1541
+ const partsOf = (card: Locator, kinds: readonly string[]) =>
1542
+ kinds.map((k) => card.getByTestId(k).first());
1386
1543
  const Panel = z.object({
1387
1544
  border: z.number(),
1388
1545
  radius: z.number(),
@@ -1396,15 +1553,13 @@ test(
1396
1553
  async (page, cardOf) => {
1397
1554
  const card = await cardOf("card-docstring");
1398
1555
  const parts = ["quote", "excerpt-path", "question", "answer", "wait"];
1399
- const boxes = await Promise.all(parts.map((k) => boxOf(card, k)));
1400
- // Guards: each part starts below the one before it ends, so the eye never goes back up.
1401
- assert.deepEqual(
1402
- R.zip(boxes, boxes.slice(1)).map(
1403
- ([a, b]) => a !== null && b !== null && b.y >= a.y + a.height,
1404
- ),
1405
- [true, true, true, true],
1406
- JSON.stringify(boxes),
1407
- );
1556
+ // Guards: each part stacked under the one before it, so the eye never goes back up.
1557
+ assert.deepEqual(await stacking(partsOf(card, parts)), [
1558
+ "stacked",
1559
+ "stacked",
1560
+ "stacked",
1561
+ "stacked",
1562
+ ]);
1408
1563
  const status = card.getByTestId("status");
1409
1564
  assert.deepEqual(
1410
1565
  [await metaOf(status), await status.isVisible()],
@@ -1426,9 +1581,8 @@ test(
1426
1581
  JSON.stringify(panel),
1427
1582
  );
1428
1583
  const cards = await page.getByTestId("item").all();
1429
- const [first, second] = await Promise.all(
1430
- cards.slice(0, 2).map(async (c) => c.boundingBox()),
1431
- );
1584
+ // The space between two cards is the requirement itself: a distance, read in one frame.
1585
+ const [first, second] = await boxesInOneFrame(cards.slice(0, 2));
1432
1586
  assert.ok(first && second, "two cards drawn");
1433
1587
  assert.ok(
1434
1588
  second.y - (first.y + first.height) >= 32,
@@ -1562,9 +1716,7 @@ test(
1562
1716
  };
1563
1717
  const { page: html, key } = build(setup("browser-v7-lang", cfg));
1564
1718
  const at = "http://label.test/";
1565
- const page = await (
1566
- await sharedBrowser()
1567
- ).newPage({ viewport: { width: 400, height: 800 } });
1719
+ const page = await offlinePage({ viewport: { width: 400, height: 800 } });
1568
1720
  try {
1569
1721
  // A real origin, so the page has a localStorage; every other request is refused, none leaves.
1570
1722
  await page.route("**/*", (r) =>
@@ -1619,9 +1771,7 @@ test(
1619
1771
  const htmlLang = async (cfg: Record<string, unknown>, dir: string) => {
1620
1772
  const { page: html } = build(setup(dir, cfg));
1621
1773
  const at = "http://label.test/";
1622
- const page = await (
1623
- await sharedBrowser()
1624
- ).newPage({ viewport: { width: 400, height: 800 } });
1774
+ const page = await offlinePage({ viewport: { width: 400, height: 800 } });
1625
1775
  try {
1626
1776
  await page.route("**/*", (r) =>
1627
1777
  r.request().url() === at
@@ -1715,11 +1865,20 @@ const tagsOn = async (card: Locator) =>
1715
1865
  text: await t.loc.textContent(),
1716
1866
  })),
1717
1867
  );
1718
- /** How far a tag's bottom edge is above the top of the block it tags (negative: not above). */
1719
- const gapAbove = async (tag: Locator, block: Locator) => {
1720
- const [t, b] = [await tag.boundingBox(), await block.boundingBox()];
1721
- assert.ok(t !== null && b !== null);
1722
- return b.y - (t.y + t.height);
1868
+ /**
1869
+ * Whether a tag sits right above the block it tags, from the structure: the element right after the
1870
+ * tag is the block, or begins with it, and the two are stacked.
1871
+ */
1872
+ const tagAbove = async (tag: Locator, block: Locator) => {
1873
+ const next = await tag.evaluate(
1874
+ (t, b) => {
1875
+ let n = t.nextElementSibling;
1876
+ while (n !== null && n !== b) n = n.firstElementChild;
1877
+ return n === b;
1878
+ },
1879
+ await block.elementHandle(),
1880
+ );
1881
+ return [next, ...(await stacking([tag, block]))];
1723
1882
  };
1724
1883
 
1725
1884
  test(
@@ -1751,14 +1910,16 @@ test(
1751
1910
  1,
1752
1911
  );
1753
1912
  const tags = docstring.getByTestId("source-tag");
1754
- const gaps = [
1755
- await gapAbove(tags.nth(0), docstring.getByTestId("quote")),
1756
- await gapAbove(tags.nth(2), docstring.getByTestId("excerpt-path")),
1757
- ];
1758
- // Guards: the tag sits above its block, close to it, never beside or below.
1759
- assert.ok(
1760
- gaps.every((g) => g >= 0 && g < 16),
1761
- JSON.stringify(gaps),
1913
+ // Guards: the tag sits right above its block, never beside or below it.
1914
+ assert.deepEqual(
1915
+ [
1916
+ await tagAbove(tags.nth(0), docstring.getByTestId("quote")),
1917
+ await tagAbove(tags.nth(2), docstring.getByTestId("excerpt-path")),
1918
+ ],
1919
+ [
1920
+ [true, "stacked"],
1921
+ [true, "stacked"],
1922
+ ],
1762
1923
  );
1763
1924
  const switchTo = async (lang: string) =>
1764
1925
  (await allByKind(page, "lang-option"))