@domandigital/craft 0.13.0 → 0.14.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.
@@ -6,7 +6,7 @@ import {
6
6
  isCream,
7
7
  normaliseFamily,
8
8
  parseColour
9
- } from "./chunk-GMVXADJ6.js";
9
+ } from "./chunk-GQVEYTBY.js";
10
10
 
11
11
  // src/direction/licences.ts
12
12
  var LICENCES = [
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  loadNull
3
- } from "./chunk-ESCVTKPN.js";
4
- import {
5
- readSnapshot
6
- } from "./chunk-CZDOMIVS.js";
3
+ } from "./chunk-XVBR2UPH.js";
7
4
  import {
8
5
  parseFlags,
9
6
  toJson
10
- } from "./chunk-3VTPI7BU.js";
7
+ } from "./chunk-3OTKMKJQ.js";
8
+ import {
9
+ readSnapshot
10
+ } from "./chunk-WUACK2HX.js";
11
11
  import {
12
12
  COMPONENT_ROLES,
13
13
  auditSnapshot,
@@ -18,7 +18,7 @@ import {
18
18
  groundName,
19
19
  hueName,
20
20
  shapeName
21
- } from "./chunk-GMVXADJ6.js";
21
+ } from "./chunk-GQVEYTBY.js";
22
22
 
23
23
  // src/estate/cli.ts
24
24
  import { existsSync, readFileSync, writeFileSync } from "fs";
@@ -95,7 +95,7 @@ async function snapshotOf(target, cwd) {
95
95
  return snap;
96
96
  }
97
97
  if (!/^https?:\/\//.test(target)) throw new Error(`${target} is neither a URL, a snapshot file, nor a site in the register`);
98
- const { snapshotUrl } = await import("./audit-5TYDYRXV.js");
98
+ const { snapshotUrl } = await import("./audit-6WHR7ZTV.js");
99
99
  return snapshotUrl(target);
100
100
  }
101
101
  var line = (distance, sibling, shared) => `${distance.toFixed(2)}${sibling ? " SIBLING" : ""}${shared.length ? ` shares ${shared.join(", ")}` : ""}`;
@@ -2,10 +2,12 @@ import {
2
2
  decodePng
3
3
  } from "./chunk-JYNXGCYZ.js";
4
4
  import {
5
- SNAPSHOT_VERSION,
6
5
  auditSnapshot,
7
6
  fingerprint
8
- } from "./chunk-GMVXADJ6.js";
7
+ } from "./chunk-GQVEYTBY.js";
8
+ import {
9
+ SNAPSHOT_VERSION
10
+ } from "./chunk-QYBAVU3P.js";
9
11
 
10
12
  // src/audit/collect.ts
11
13
  function collectInPage() {
@@ -218,7 +220,7 @@ function collectInPage() {
218
220
  let covered = 0;
219
221
  let minX = Infinity;
220
222
  let maxX = -Infinity;
221
- let textBlocks = 0;
223
+ let textBlocks2 = 0;
222
224
  let centred = 0;
223
225
  for (const n of leaves) {
224
226
  const r = box(n);
@@ -230,14 +232,14 @@ function collectInPage() {
230
232
  left += split * r.height;
231
233
  right += (r.width - split) * r.height;
232
234
  if (ownText(n).length > 1) {
233
- textBlocks += 1;
235
+ textBlocks2 += 1;
234
236
  const mid = r.left + r.width / 2;
235
237
  if (style(n).textAlign === "center" || Math.abs(mid - centreX) < vw * 0.03 && r.width < b.width * 0.8) centred += 1;
236
238
  }
237
239
  }
238
240
  const round = (v) => Math.round(v * 1e3) / 1e3;
239
241
  return {
240
- centredShare: textBlocks ? round(centred / textBlocks) : 0,
242
+ centredShare: textBlocks2 ? round(centred / textBlocks2) : 0,
241
243
  mirrorSymmetry: left + right > 0 ? round(1 - Math.abs(left - right) / (left + right)) : 1,
242
244
  whitespaceRatio: round(Math.max(0, 1 - Math.min(1, covered / Math.max(1, b.width * b.height)))),
243
245
  contentWidthRatio: leaves.length ? round(Math.min(1, (maxX - minX) / vw)) : 0,
@@ -302,6 +304,43 @@ function collectInPage() {
302
304
  });
303
305
  return { badges, avatars, carousel };
304
306
  };
307
+ const TEXT_BLOCK = "h1, h2, h3, h4, h5, h6, p, li, blockquote, figcaption, dt, dd, td, th, summary, cite, q";
308
+ const CHROME = "nav, [role=navigation], footer, [role=contentinfo], button, [role=button], [aria-hidden=true], script, style, noscript, template";
309
+ const readable = (el) => {
310
+ if (!shown(el)) return false;
311
+ const r = el.getBoundingClientRect();
312
+ return r.width > 2 && r.height > 2;
313
+ };
314
+ const textBlocks = (scope, limit, keep = () => true) => {
315
+ const out = [];
316
+ const seen = /* @__PURE__ */ new Set();
317
+ const add = (el) => {
318
+ const t = (el.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 300);
319
+ if (t.length < 2 || seen.has(t)) return;
320
+ seen.add(t);
321
+ out.push(t);
322
+ };
323
+ for (const el of Array.from(scope.querySelectorAll(TEXT_BLOCK))) {
324
+ if (out.length >= limit) break;
325
+ if (el.parentElement?.closest(TEXT_BLOCK) || el.closest(CHROME) || !readable(el) || !keep(el)) continue;
326
+ add(el);
327
+ }
328
+ for (const el of Array.from(scope.querySelectorAll("div, span"))) {
329
+ if (out.length >= limit) break;
330
+ if (ownText(el).split(" ").length < 3) continue;
331
+ if (el.closest(TEXT_BLOCK) || el.closest(CHROME) || el.closest("a") || !readable(el) || !keep(el)) continue;
332
+ add(el);
333
+ }
334
+ return out;
335
+ };
336
+ const inChromeHeader = (el) => {
337
+ const h = el.closest("header");
338
+ return Boolean(h && !h.querySelector("h1"));
339
+ };
340
+ const firstScreenText = textBlocks(document.body, 12, (el) => {
341
+ const b = box(el);
342
+ return b.top < vh && b.top + b.height > 0 && !inChromeHeader(el) && !el.closest("a");
343
+ });
305
344
  const kept = blocks.slice(0, 40);
306
345
  const sections = kept.map((el, index) => {
307
346
  const b = box(el);
@@ -330,7 +369,8 @@ function collectInPage() {
330
369
  role: roleOf(el, kind, geometry, b, cards, iconCards, index === kept.length - 1),
331
370
  geometry,
332
371
  ...parts,
333
- figures: numbers
372
+ figures: numbers,
373
+ text: textBlocks(el, 40)
334
374
  };
335
375
  });
336
376
  if (header && sections.length === 0) {
@@ -507,6 +547,7 @@ function collectInPage() {
507
547
  })(),
508
548
  effects,
509
549
  images: images.slice(0, 60),
550
+ firstScreenText,
510
551
  motion: {
511
552
  hiddenSections: sections.filter((s) => s.hiddenAtLoad).length,
512
553
  sections: sections.length,
@@ -0,0 +1,6 @@
1
+ // src/snapshot/types.ts
2
+ var SNAPSHOT_VERSION = 2;
3
+
4
+ export {
5
+ SNAPSHOT_VERSION
6
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SNAPSHOT_VERSION
3
- } from "./chunk-GMVXADJ6.js";
3
+ } from "./chunk-QYBAVU3P.js";
4
4
 
5
5
  // src/snapshot/migrate.ts
6
6
  var READABLE_SNAPSHOT_VERSIONS = [1, 2];
@@ -15,5 +15,6 @@ function readSnapshot(data, source = "snapshot") {
15
15
  }
16
16
 
17
17
  export {
18
+ READABLE_SNAPSHOT_VERSIONS,
18
19
  readSnapshot
19
20
  };
@@ -1,10 +1,10 @@
1
- import {
2
- readSnapshot
3
- } from "./chunk-CZDOMIVS.js";
4
1
  import {
5
2
  parseFlags,
6
3
  toJson
7
- } from "./chunk-3VTPI7BU.js";
4
+ } from "./chunk-3OTKMKJQ.js";
5
+ import {
6
+ readSnapshot
7
+ } from "./chunk-WUACK2HX.js";
8
8
  import {
9
9
  CATALOGUE_VERSION,
10
10
  NULL_VERSION,
@@ -17,7 +17,7 @@ import {
17
17
  hueSwatch,
18
18
  nullPrompt,
19
19
  scanSource
20
- } from "./chunk-GMVXADJ6.js";
20
+ } from "./chunk-GQVEYTBY.js";
21
21
 
22
22
  // src/null/cli.ts
23
23
  import { spawn } from "child_process";
@@ -115,7 +115,7 @@ async function build(flags, io) {
115
115
  const toShoot = ids.filter((id) => existsSync(join(pages, `${id}.html`)) && !existsSync(join(shots, `${id}.json`)));
116
116
  if (toShoot.length) {
117
117
  io.out(`craft null: snapshotting ${toShoot.length} page${toShoot.length === 1 ? "" : "s"}`);
118
- const { snapshotUrls } = await import("./audit-5TYDYRXV.js");
118
+ const { snapshotUrls } = await import("./audit-6WHR7ZTV.js");
119
119
  const results = await snapshotUrls(toShoot.map((id) => pathToFileURL(join(pages, `${id}.html`)).href));
120
120
  results.forEach((r, i) => {
121
121
  const id = toShoot[i];
@@ -4,11 +4,12 @@ import {
4
4
  formatPairs,
5
5
  loadEstate,
6
6
  runEstate
7
- } from "./chunk-K2BZN4GA.js";
8
- import "./chunk-ESCVTKPN.js";
9
- import "./chunk-CZDOMIVS.js";
10
- import "./chunk-3VTPI7BU.js";
11
- import "./chunk-GMVXADJ6.js";
7
+ } from "./chunk-PBK6SYH5.js";
8
+ import "./chunk-XVBR2UPH.js";
9
+ import "./chunk-3OTKMKJQ.js";
10
+ import "./chunk-WUACK2HX.js";
11
+ import "./chunk-GQVEYTBY.js";
12
+ import "./chunk-QYBAVU3P.js";
12
13
  export {
13
14
  formatComponentPairs,
14
15
  formatMatches,
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  DIRECTION_VERSION,
3
3
  validateDirection
4
- } from "./chunk-ZZ5CKOJP.js";
4
+ } from "./chunk-OOZOEWGD.js";
5
5
  import {
6
6
  decodePng
7
7
  } from "./chunk-JYNXGCYZ.js";
8
- import {
9
- readSnapshot
10
- } from "./chunk-CZDOMIVS.js";
11
8
  import {
12
9
  parseFlags,
13
10
  toJson
14
- } from "./chunk-3VTPI7BU.js";
11
+ } from "./chunk-3OTKMKJQ.js";
12
+ import {
13
+ readSnapshot
14
+ } from "./chunk-WUACK2HX.js";
15
15
  import {
16
16
  deltaEOk,
17
17
  fingerprint,
@@ -21,7 +21,8 @@ import {
21
21
  isCream,
22
22
  oklchToRgb,
23
23
  parseColour
24
- } from "./chunk-GMVXADJ6.js";
24
+ } from "./chunk-GQVEYTBY.js";
25
+ import "./chunk-QYBAVU3P.js";
25
26
 
26
27
  // src/direction/cli.ts
27
28
  import { existsSync, readdirSync, readFileSync, writeFileSync } from "fs";
@@ -1,22 +1,19 @@
1
1
  import {
2
2
  validateDirection
3
- } from "./chunk-ZZ5CKOJP.js";
3
+ } from "./chunk-OOZOEWGD.js";
4
4
  import {
5
5
  merge
6
- } from "./chunk-IMB4V34S.js";
7
- import "./chunk-ZLDA2SYB.js";
6
+ } from "./chunk-7T5WR74C.js";
7
+ import "./chunk-Q7ILL2HV.js";
8
8
  import "./chunk-JYNXGCYZ.js";
9
9
  import {
10
10
  SIBLING_AT,
11
11
  compareToEstate,
12
12
  loadEstate
13
- } from "./chunk-K2BZN4GA.js";
13
+ } from "./chunk-PBK6SYH5.js";
14
14
  import {
15
15
  loadNull
16
- } from "./chunk-ESCVTKPN.js";
17
- import {
18
- readSnapshot
19
- } from "./chunk-CZDOMIVS.js";
16
+ } from "./chunk-XVBR2UPH.js";
20
17
  import {
21
18
  COPY_FILE,
22
19
  NOT_COPY_DIR,
@@ -27,7 +24,10 @@ import {
27
24
  parseFlags,
28
25
  readPaths,
29
26
  toJson
30
- } from "./chunk-3VTPI7BU.js";
27
+ } from "./chunk-3OTKMKJQ.js";
28
+ import {
29
+ readSnapshot
30
+ } from "./chunk-WUACK2HX.js";
31
31
  import {
32
32
  CATALOGUE,
33
33
  auditSnapshot,
@@ -35,7 +35,8 @@ import {
35
35
  fingerprint,
36
36
  scanSource,
37
37
  typicality
38
- } from "./chunk-GMVXADJ6.js";
38
+ } from "./chunk-GQVEYTBY.js";
39
+ import "./chunk-QYBAVU3P.js";
39
40
 
40
41
  // src/report/cli.ts
41
42
  import { existsSync, readFileSync, writeFileSync } from "fs";
@@ -262,7 +263,7 @@ async function runReport(command, args, io) {
262
263
  if (/\.json$/i.test(target2) && existsSync(local)) {
263
264
  snap = readSnapshot(JSON.parse(readFileSync(local, "utf8")), target2);
264
265
  } else {
265
- const { snapshotUrl } = await import("./audit-5TYDYRXV.js");
266
+ const { snapshotUrl } = await import("./audit-6WHR7ZTV.js");
266
267
  snap = await snapshotUrl(target2);
267
268
  }
268
269
  const fp = fingerprint(snap);
@@ -4,13 +4,14 @@ import {
4
4
  merge,
5
5
  resolvePages,
6
6
  runAudit
7
- } from "./chunk-IMB4V34S.js";
8
- import "./chunk-ZLDA2SYB.js";
7
+ } from "./chunk-7T5WR74C.js";
8
+ import "./chunk-Q7ILL2HV.js";
9
9
  import "./chunk-JYNXGCYZ.js";
10
- import "./chunk-ESCVTKPN.js";
11
- import "./chunk-CZDOMIVS.js";
12
- import "./chunk-3VTPI7BU.js";
13
- import "./chunk-GMVXADJ6.js";
10
+ import "./chunk-XVBR2UPH.js";
11
+ import "./chunk-3OTKMKJQ.js";
12
+ import "./chunk-WUACK2HX.js";
13
+ import "./chunk-GQVEYTBY.js";
14
+ import "./chunk-QYBAVU3P.js";
14
15
  export {
15
16
  describeComponents,
16
17
  describeFingerprint,
@@ -6,10 +6,11 @@ import {
6
6
  nullPath,
7
7
  runHarvest,
8
8
  runNull
9
- } from "./chunk-ESCVTKPN.js";
10
- import "./chunk-CZDOMIVS.js";
11
- import "./chunk-3VTPI7BU.js";
12
- import "./chunk-GMVXADJ6.js";
9
+ } from "./chunk-XVBR2UPH.js";
10
+ import "./chunk-3OTKMKJQ.js";
11
+ import "./chunk-WUACK2HX.js";
12
+ import "./chunk-GQVEYTBY.js";
13
+ import "./chunk-QYBAVU3P.js";
13
14
  export {
14
15
  describeTypicality,
15
16
  formatHarvest,
package/dist/cli.js CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  run
4
- } from "./chunk-3VTPI7BU.js";
5
- import "./chunk-GMVXADJ6.js";
4
+ } from "./chunk-3OTKMKJQ.js";
5
+ import "./chunk-GQVEYTBY.js";
6
+ import "./chunk-QYBAVU3P.js";
6
7
 
7
8
  // src/cli.ts
8
9
  process.stdout.on("error", (error) => {