@decocms/parity 0.33.57 → 0.33.59

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 (2) hide show
  1. package/dist/cli.js +172 -31
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -39022,6 +39022,21 @@ var DISABLE_ANIMATIONS_CSS = `
39022
39022
  scroll-behavior: auto !important;
39023
39023
  }
39024
39024
  `;
39025
+ function injectStyleScript(css) {
39026
+ return `
39027
+ (function () {
39028
+ var apply = function () {
39029
+ var style = document.createElement('style');
39030
+ style.textContent = ${JSON.stringify(css)};
39031
+ document.documentElement.appendChild(style);
39032
+ };
39033
+ if (document.documentElement) return apply();
39034
+ new MutationObserver(function (_, o) {
39035
+ if (document.documentElement) { o.disconnect(); apply(); }
39036
+ }).observe(document, { childList: true });
39037
+ })();
39038
+ `;
39039
+ }
39025
39040
  var USER_AGENT_BY_VIEWPORT = {
39026
39041
  mobile: "Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Mobile Safari/537.36",
39027
39042
  tablet: "Mozilla/5.0 (iPad; CPU OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1",
@@ -39167,30 +39182,11 @@ async function newContext(browser, opts) {
39167
39182
  return page;
39168
39183
  };
39169
39184
  }
39170
- await ctx.addInitScript({
39171
- content: `
39172
- try {
39173
- const style = document.createElement('style');
39174
- style.textContent = ${JSON.stringify(DISABLE_ANIMATIONS_CSS)};
39175
- (document.head || document.documentElement).appendChild(style);
39176
- } catch (e) {}
39177
- `
39178
- });
39185
+ if (!opts.keepMotion)
39186
+ await ctx.addInitScript({ content: injectStyleScript(DISABLE_ANIMATIONS_CSS) });
39179
39187
  if (opts.hideScrollbars) {
39180
39188
  await ctx.addInitScript({
39181
- content: `
39182
- (function () {
39183
- var apply = function () {
39184
- var style = document.createElement('style');
39185
- style.textContent = 'html, body, * { scrollbar-width: none !important; } ::-webkit-scrollbar { display: none !important; }';
39186
- document.documentElement.appendChild(style);
39187
- };
39188
- if (document.documentElement) return apply();
39189
- new MutationObserver(function (_, o) {
39190
- if (document.documentElement) { o.disconnect(); apply(); }
39191
- }).observe(document, { childList: true });
39192
- })();
39193
- `
39189
+ content: injectStyleScript("html, body, * { scrollbar-width: none !important; } ::-webkit-scrollbar { display: none !important; }")
39194
39190
  });
39195
39191
  }
39196
39192
  await ctx.addInitScript({ content: CAROUSEL_STABILIZER_INIT_SCRIPT });
@@ -39221,6 +39217,29 @@ var ACCEPT_SELECTORS = [
39221
39217
  'button[id*="accept" i][id*="cookie" i]'
39222
39218
  ];
39223
39219
  var LOOSE_ACCEPT_SELECTOR = 'button:has-text("Aceitar")';
39220
+ function clickConsentButtonByText() {
39221
+ const LABEL = /^(continuar e fechar|aceitar e fechar|continuar|fechar|entendi|ok)$/i;
39222
+ const CONSENT = /cookie/i;
39223
+ const MAX_DEPTH = 4;
39224
+ const MAX_BANNER_TEXT = 1500;
39225
+ for (const b of Array.from(document.querySelectorAll("button, [role='button']"))) {
39226
+ if (!LABEL.test((b.textContent ?? "").replace(/\s+/g, " ").trim()))
39227
+ continue;
39228
+ if (b.checkVisibility && !b.checkVisibility())
39229
+ continue;
39230
+ let el = b.parentElement;
39231
+ for (let d = 0;el && d < MAX_DEPTH; d++, el = el.parentElement) {
39232
+ const text = el.textContent ?? "";
39233
+ if (text.length > MAX_BANNER_TEXT)
39234
+ break;
39235
+ if (CONSENT.test(text)) {
39236
+ b.click();
39237
+ return true;
39238
+ }
39239
+ }
39240
+ }
39241
+ return false;
39242
+ }
39224
39243
  async function acceptCookieBanner(page, opts = {}) {
39225
39244
  const selectors = opts.loose ? [...ACCEPT_SELECTORS, LOOSE_ACCEPT_SELECTOR] : ACCEPT_SELECTORS;
39226
39245
  for (const sel of selectors) {
@@ -39235,6 +39254,12 @@ async function acceptCookieBanner(page, opts = {}) {
39235
39254
  return true;
39236
39255
  }
39237
39256
  }
39257
+ if (await page.evaluate(clickConsentButtonByText).catch(() => false)) {
39258
+ await page.waitForTimeout(300).catch(() => {
39259
+ return;
39260
+ });
39261
+ return true;
39262
+ }
39238
39263
  return false;
39239
39264
  }
39240
39265
 
@@ -44576,6 +44601,14 @@ async function dismissOverlays(page, ctx) {
44576
44601
  const sels = overlaySelectorsFor(ctx.rc);
44577
44602
  dlog2(ctx, ` dismissOverlays: checking ${sels.length} selector(s)…`);
44578
44603
  const dismissals = [];
44604
+ if (await acceptCookieBanner(page).catch(() => false)) {
44605
+ dismissals.push({
44606
+ reason: "selector-match",
44607
+ tag: "cookie-consent",
44608
+ method: "close-button",
44609
+ dismissed: true
44610
+ });
44611
+ }
44579
44612
  for (const sel of sels) {
44580
44613
  try {
44581
44614
  const overlay = page.locator(sel).first();
@@ -67542,7 +67575,7 @@ async function migrateCommand(opts) {
67542
67575
  let platformSeen = null;
67543
67576
  let assetsResolved = null;
67544
67577
  for (const vp of viewports) {
67545
- const ctx = await newContext(browser, { viewport: vp });
67578
+ const ctx = await newContext(browser, { viewport: vp, keepMotion: true });
67546
67579
  const page = await ctx.newPage();
67547
67580
  try {
67548
67581
  await page.goto(opts.url, { waitUntil: "domcontentloaded", timeout: 30000 });
@@ -67763,7 +67796,7 @@ async function capturePages(browser, viewport, resolvedPages, theme, cfg) {
67763
67796
  const blocksByPath = new Map;
67764
67797
  const contentMap = {};
67765
67798
  for (const target of resolvedPages) {
67766
- const ctx = await newContext(browser, { viewport });
67799
+ const ctx = await newContext(browser, { viewport, keepMotion: true });
67767
67800
  const page = await ctx.newPage();
67768
67801
  const pageComponents = [];
67769
67802
  try {
@@ -70969,6 +71002,46 @@ function findingsTable(findings, omitted, lang) {
70969
71002
  const tail = omitted > 0 ? `<p class="annotation">${L2(`+${omitted} achado(s) além dos mostrados — veja report.json.`, `+${omitted} more finding(s) beyond those shown — see report.json.`, lang)}</p>` : "";
70970
71003
  return `<table class="grid compact"><thead><tr><th>${L2("Sev", "Sev", lang)}</th><th>${L2("Categoria", "Category", lang)}</th><th>${L2("Achado", "Finding", lang)}</th></tr></thead><tbody>${rows}</tbody></table>${tail}`;
70971
71004
  }
71005
+ var CELL_CLASS = {
71006
+ ok: "cell-ok",
71007
+ new: "cell-new",
71008
+ warn: "cell-warn",
71009
+ gap: "cell-gap"
71010
+ };
71011
+ var PILL_CLASS = {
71012
+ ok: "pill-good",
71013
+ new: "pill-lime",
71014
+ warn: "pill-warn",
71015
+ gap: "pill-bad"
71016
+ };
71017
+ function blockPages(blocks, lang) {
71018
+ const eyebrow = L2("Blocos", "Blocks", lang);
71019
+ if (blocks.rows.length === 0) {
71020
+ return [
71021
+ page(eyebrow, L2("Mapa de calor dos componentes", "Component heat map", lang), `<p class="annotation">${L2("O migration-plan.json foi lido, mas não lista nenhum componente — não há o que mostrar aqui.", "migration-plan.json was read but lists no components — there is nothing to show here.", lang)}</p>`)
71022
+ ];
71023
+ }
71024
+ const byName = new Map(blocks.rows.map((r) => [r.component, r]));
71025
+ const legend = `<div class="legend">${[
71026
+ ["ok", "feito", "done"],
71027
+ ["new", "upgrade", "upgrade"],
71028
+ ["warn", "parcial / as-is / skipped", "partial / as-is / skipped"],
71029
+ ["gap", "pendente", "pending"]
71030
+ ].map(([tone, pt, en]) => `<span class="lg"><i class="cell ${CELL_CLASS[tone]}"></i>${L2(pt, en, lang)}</span>`).join("")}</div>`;
71031
+ const zones = blocks.zones.map((z) => {
71032
+ const label = z.zone === "global" ? L2("Global (header, footer, nav)", "Global (header, footer, nav)", lang) : z.zone === "unassigned" ? L2("Sem página", "Unassigned", lang) : esc3(z.zone);
71033
+ const cells = z.components.map((name) => {
71034
+ const tone = byName.get(name)?.tone ?? "gap";
71035
+ return `<div class="cell ${CELL_CLASS[tone]}">${esc3(name)}</div>`;
71036
+ }).join("");
71037
+ return `<div class="zone"><div class="zone-head"><b>${label}</b><span class="zone-score num">${z.settled}/${z.components.length}</span></div><div class="cells">${cells}</div></div>`;
71038
+ }).join("");
71039
+ const rows = blocks.rows.map((r) => `<tr><td>${esc3(r.component)}</td><td>${esc3(r.role)}</td><td><span class="pill ${PILL_CLASS[r.tone]}">${esc3(r.status)}</span></td><td>${r.verified ? esc3(r.verified) : "—"}</td><td>${esc3(r.note)}</td></tr>`).join("");
71040
+ return [
71041
+ page(eyebrow, L2("Mapa de calor dos componentes", "Component heat map", lang), legend + zones, L2(`${blocks.rows.length} componentes do migration-plan.json, agrupados pela página em que a captura os viu. O placar de cada zona conta done e upgrade.`, `${blocks.rows.length} components from migration-plan.json, grouped by the page the capture saw them on. Each zone's score counts done and upgrade.`, lang)),
71042
+ page(eyebrow, L2("Bloco a bloco", "Block by block", lang), `<table class="grid compact"><thead><tr><th>${L2("Componente", "Component", lang)}</th><th>${L2("Papel", "Role", lang)}</th><th>${L2("Status", "Status", lang)}</th><th>${L2("Verificado", "Verified", lang)}</th><th>${L2("Nota", "Note", lang)}</th></tr></thead><tbody>${rows}</tbody></table>`, L2("Status como o plano registra. Verificado vazio (—) quer dizer que ninguém mediu, não que passou.", "Status as the plan records it. An empty verified (—) means nobody measured it, not that it passed.", lang))
71043
+ ];
71044
+ }
70972
71045
  function renderDeckHtml(model, lang = "en") {
70973
71046
  const pages = [];
70974
71047
  pages.push(`<section class="page cover"><div class="page-inner">
@@ -70987,6 +71060,8 @@ function renderDeckHtml(model, lang = "en") {
70987
71060
  }
70988
71061
  const moduleRows = model.modules.map((m) => `<tr><td>${esc3(m.module)}</td><td><b class="num">${m.score}</b></td><td><span class="pill pill-${m.tone === "good" ? "good" : m.tone === "warn" ? "warn" : m.tone === "neutral" ? "neutral" : "bad"}">${esc3(m.status)}</span></td></tr>`).join("");
70989
71062
  pages.push(page(L2("Sumário executivo", "Executive summary", lang), L2("Onde a migração está", "Where the migration stands", lang), tiles(model.headline, lang) + (moduleRows ? `<h3 class="sub">${L2("Score por módulo", "Score per module", lang)}</h3>` + `<table class="grid"><tbody>${moduleRows}</tbody></table>` : "")));
71063
+ if (model.blocks)
71064
+ pages.push(...blockPages(model.blocks, lang));
70990
71065
  pages.push(page(L2("Achados", "Findings", lang), L2("O que a validação encontrou", "What the validation found", lang), findingsTable(model.findings, model.findingsOmitted, lang)));
70991
71066
  if (model.visual) {
70992
71067
  pages.push(page(L2("Visual", "Visual", lang), L2("Paridade visual", "Visual parity", lang), tiles([
@@ -71050,7 +71125,52 @@ function toneForStatus(status) {
71050
71125
  return "neutral";
71051
71126
  return "bad";
71052
71127
  }
71053
- function buildDeckModel(run) {
71128
+ var TONE_BY_STATUS = {
71129
+ done: "ok",
71130
+ upgrade: "new",
71131
+ partial: "warn",
71132
+ "as-is": "warn",
71133
+ skipped: "warn",
71134
+ pending: "gap"
71135
+ };
71136
+ function buildDeckBlocks(plan) {
71137
+ const rows = plan.components.map((c) => ({
71138
+ component: c.name,
71139
+ role: c.role,
71140
+ status: c.status,
71141
+ tone: TONE_BY_STATUS[c.status] ?? "gap",
71142
+ verified: c.verified?.verdict ?? null,
71143
+ note: c.reference?.note ?? ""
71144
+ }));
71145
+ const byKey = new Map(rows.map((r) => [key(r.component), r]));
71146
+ const isGlobal = new Set(rows.filter((_, i) => plan.components[i]?.scope === "global"));
71147
+ const zones = [];
71148
+ const push = (zone, members) => {
71149
+ if (members.length === 0)
71150
+ return;
71151
+ zones.push({
71152
+ zone,
71153
+ components: members.map((m) => m.component),
71154
+ settled: members.filter((m) => m.tone === "ok" || m.tone === "new").length
71155
+ });
71156
+ };
71157
+ push("global", [...isGlobal]);
71158
+ const placed = new Set;
71159
+ for (const page of plan.pages) {
71160
+ const members = new Set;
71161
+ for (const name of page.components ?? []) {
71162
+ const row = byKey.get(key(name));
71163
+ if (row && !isGlobal.has(row))
71164
+ members.add(row);
71165
+ }
71166
+ for (const m of members)
71167
+ placed.add(m);
71168
+ push(page.path, [...members]);
71169
+ }
71170
+ push("unassigned", rows.filter((r) => !isGlobal.has(r) && !placed.has(r)));
71171
+ return { rows, zones };
71172
+ }
71173
+ function buildDeckModel(run, plan = null) {
71054
71174
  const v = run.verdict;
71055
71175
  const source = run.topIssues.length > 0 ? run.topIssues : run.issues;
71056
71176
  const ranked = [...source].sort(bySeverity);
@@ -71109,7 +71229,8 @@ function buildDeckModel(run) {
71109
71229
  pagesChecked: run.visualDiff.pagesChecked,
71110
71230
  pagesPassed: run.visualDiff.pagesPassed,
71111
71231
  pagesWithDiffs: run.visualDiff.pagesWithDiffs
71112
- } : null
71232
+ } : null,
71233
+ blocks: plan ? buildDeckBlocks(plan) : null
71113
71234
  };
71114
71235
  }
71115
71236
  var SEVERITY_ORDER4 = { critical: 0, high: 1, medium: 2, low: 3 };
@@ -71283,7 +71404,20 @@ async function reportCommand(runId, opts) {
71283
71404
  console.error(chalk27.red(`failed to load run: ${err.message}`));
71284
71405
  return 1;
71285
71406
  }
71286
- const html = renderDeckHtml(buildDeckModel(run), opts.lang ?? "en");
71407
+ let plan = null;
71408
+ if (opts.planDir) {
71409
+ try {
71410
+ plan = loadPlan(opts.planDir);
71411
+ } catch (err) {
71412
+ console.error(chalk27.red(`failed to read migration-plan.json: ${err.message}`));
71413
+ return 1;
71414
+ }
71415
+ if (!plan) {
71416
+ console.error(chalk27.red(`no migration-plan.json in ${opts.planDir}`));
71417
+ return 1;
71418
+ }
71419
+ }
71420
+ const html = renderDeckHtml(buildDeckModel(run, plan), opts.lang ?? "en");
71287
71421
  const dest = opts.out ?? join36(paths.runDir, "deck.html");
71288
71422
  writeFileSync28(dest, html, "utf8");
71289
71423
  console.log(`${chalk27.green("✓")} deck → ${dest}`);
@@ -71761,7 +71895,10 @@ function isHarnessSide(explicitSelector) {
71761
71895
  return !explicitSelector;
71762
71896
  }
71763
71897
  async function gatherBenchSide(browser, opts) {
71764
- const ctx = await newContext(browser, { viewport: opts.viewport });
71898
+ const ctx = await newContext(browser, {
71899
+ viewport: opts.viewport,
71900
+ keepMotion: true
71901
+ });
71765
71902
  const page = await ctx.newPage();
71766
71903
  const side = {
71767
71904
  url: opts.url,
@@ -76498,7 +76635,10 @@ async function readDelta(page, selector, base) {
76498
76635
  };
76499
76636
  }
76500
76637
  async function gatherStates(browser, opts) {
76501
- const ctx = await newContext(browser, { viewport: opts.viewport });
76638
+ const ctx = await newContext(browser, {
76639
+ viewport: opts.viewport,
76640
+ keepMotion: true
76641
+ });
76502
76642
  const page = await ctx.newPage();
76503
76643
  const out = {
76504
76644
  motion: { found: false, error: "not read" },
@@ -77557,7 +77697,7 @@ program.command("serve").argument("<runId>", "Run ID to serve").description("Spa
77557
77697
  program.command("event").argument("<type>", "Event type: phase-change | dispatch | bench | score | note | …").description("Record a migration event into <dir>/events.jsonl — the sanctioned emission path for hooks and the orchestrator. The cockpit daemon tails this file into its live activity feed.").option("--dir <dir>", "Directory holding events.jsonl (the target's .parity/)", ".parity").option("--data <json>", `JSON object of event fields, e.g. '{"agent":"porter","component":"hero"}'`).action((type, opts) => {
77558
77698
  process.exit(eventCommand(type, opts));
77559
77699
  });
77560
- program.command("report").argument("<runId>", "Run ID to open").description("Open the HTML report for a run in the default browser. With --section, extract a single tab to stdout instead — useful for agents that need just the SEO/Network/Vitals slice without parsing the whole report. Issue #74.").option("--output <dir>", "Output directory", "./parity-output").option("--section <name>", "Extract one tab to stdout instead of opening the report. Valid names: summary, visualdiff, seo, sidebyside, issues, vitals, cache, checks, prompt, pages, console, network, diff.").option("--json", "Pair with --section to emit a normalized JSON projection of the section (from report.json) instead of the raw HTML slice.").option("--deck", "Render the presentation deck instead: one topic per full-viewport page, advanced sideways, in a single self-contained HTML file. For showing the result to someone rather than debugging it. Issue #290.", false).option("--out <path>", "Where to write the deck (default: deck.html in the run dir)").option("--lang <pt|en>", "Initial deck language; the in-page toggle still switches live", "en").option("--open", "Open the rendered deck in the browser", false).action(async (runId, opts) => {
77700
+ program.command("report").argument("<runId>", "Run ID to open").description("Open the HTML report for a run in the default browser. With --section, extract a single tab to stdout instead — useful for agents that need just the SEO/Network/Vitals slice without parsing the whole report. Issue #74.").option("--output <dir>", "Output directory", "./parity-output").option("--section <name>", "Extract one tab to stdout instead of opening the report. Valid names: summary, visualdiff, seo, sidebyside, issues, vitals, cache, checks, prompt, pages, console, network, diff.").option("--json", "Pair with --section to emit a normalized JSON projection of the section (from report.json) instead of the raw HTML slice.").option("--deck", "Render the presentation deck instead: one topic per full-viewport page, advanced sideways, in a single self-contained HTML file. For showing the result to someone rather than debugging it. Issue #290.", false).option("--out <path>", "Where to write the deck (default: deck.html in the run dir)").option("--lang <pt|en>", "Initial deck language; the in-page toggle still switches live", "en").option("--open", "Open the rendered deck in the browser", false).option("--plan-dir <dir>", "With --deck: dir holding migration-plan.json. Adds the component heat map (grouped by page, plus global) and the block-by-block table. Without it those pages are omitted, not drawn empty. Issue #291.").action(async (runId, opts) => {
77561
77701
  process.exit(await reportCommand(runId, {
77562
77702
  output: opts.output,
77563
77703
  section: opts.section,
@@ -77565,7 +77705,8 @@ program.command("report").argument("<runId>", "Run ID to open").description("Ope
77565
77705
  deck: Boolean(opts.deck),
77566
77706
  out: opts.out,
77567
77707
  lang: opts.lang === "pt" ? "pt" : "en",
77568
- open: Boolean(opts.open)
77708
+ open: Boolean(opts.open),
77709
+ planDir: opts.planDir
77569
77710
  }));
77570
77711
  });
77571
77712
  function buildCompareCommand(name, deprecated) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/parity",
3
- "version": "0.33.57",
3
+ "version": "0.33.59",
4
4
  "description": "E2E parity validator for site migrations. Compares prod vs cand and reports UI, functional, SEO, visual, and Web Vitals deltas with an LLM-ranked HTML report.",
5
5
  "type": "module",
6
6
  "license": "MIT",