@seanyeh77/ui-cli 0.47.0 → 0.47.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 (3) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +12 -0
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -7,7 +7,7 @@ npm i -D @seanyeh77/ui-cli
7
7
  npx playwright install chromium # ui check 與 ui shots 用的瀏覽器;或設定 CHROMIUM_PATH
8
8
  ```
9
9
 
10
- - `ui check <檔案或 URL>`:在 390 px 與 1280 px、淺色與深色打開頁面,檢查 console 錯誤、水平溢出、小於 48 px 的觸控目標、1280 px 時小於 24 px 又擠著別的目標的目標(WCAG 2.5.8)、卡片裡的卡片、原生控制項、被截斷又沒有 Tooltip 或 title 的介面文字、跑出卡片外的文字、同一列工具列或表單欄位不同高、390 px 時置中的兩行以上段落、AppShell 頁面的文件本身也在捲動、沒放進 layer 又蓋過元件的重設 CSS,以及 axe-core 的 WCAG 2.0、2.1、2.2 A 與 AA 規則,有問題時 exit 1。每次量測前等動畫和轉場結束(最多 1.5 s)。頁面沒有 viewport meta 時,390 px 只回報一次「缺 viewport meta」,不檢查觸控目標。
10
+ - `ui check <檔案或 URL>`:在 390 px 與 1280 px、淺色與深色打開頁面,檢查 console 錯誤、水平溢出、小於 48 px 的觸控目標、1280 px 時小於 24 px 又擠著別的目標的目標(WCAG 2.5.8)、卡片裡的卡片、原生控制項、被截斷又沒有 Tooltip 或 title 的介面文字、跑出卡片外的文字、同一列工具列或表單欄位不同高、390 px 時置中的兩行以上段落、AppShell 頁面的文件本身也在捲動、沒放進 layer 又蓋過元件的重設 CSS,以及 axe-core 的 WCAG 2.0、2.1、2.2 A 與 AA 規則,有問題時 exit 1。每次量測前等動畫和轉場結束(最多 1.5 s)。頁面沒有 viewport meta 時,390 px 只回報一次「缺 viewport meta」,不檢查觸控目標。 file:// 頁面的字型被 CORS 擋下時不算 console 錯誤,每頁最後寫一行 note,提醒用 http 開頁面。
11
11
  - 它也會點開每個分頁(`[role=tablist]`)、SettingsLayout 的每個分類,以及工具列與頂欄裡 `[aria-haspopup]` 按鈕的選單,檢查打開後的畫面(淺色、兩種寬度,每頁最多 12 個狀態),只回報原本沒有的問題。
12
12
  - 每個寬度與主題那一行的結果算進頁面和打開的狀態;各狀態的問題列在「after opening …」底下。
13
13
  - `--open <selector>` 點開頁面上第一個符合的元素(對話框、側欄)並檢查,可以重複;`--no-interact` 不自動點分頁、分類和選單;`--no-axe` 不跑 axe-core。`--shots <資料夾>` 存每個寬度與主題的整頁截圖,也存每個打開的狀態。
package/dist/cli.js CHANGED
@@ -749,6 +749,15 @@ async function waitForAnimations(page, cap = 1500) {
749
749
  }, cap);
750
750
  }
751
751
  /** File name of one screenshot. */
752
+ /**
753
+ * A font a file:// page loads from a server, blocked by CORS (the page's origin is null): Chromium logs the CORS
754
+ * error and a failed load of the font file. Not a problem of the page itself; ui check reports it once as a note.
755
+ */
756
+ function isFileFontCors(pageUrl, text, src) {
757
+ if (!pageUrl.startsWith("file:")) return false;
758
+ if (/^Access to font at .* has been blocked by CORS policy/.test(text)) return true;
759
+ return /^Failed to load resource/.test(text) && /\.(?:woff2?|ttf|otf)(?:[?#]|$)/i.test(src);
760
+ }
752
761
  const shotName = (stem, width, theme) => `${stem}-${width}-${theme}.png`;
753
762
  /**
754
763
  * Takes the 4 screenshots of one page (2 widths x 2 themes), each in a fresh context, and returns them by file name.
@@ -1288,6 +1297,7 @@ async function check(targets, opts) {
1288
1297
  const out = [url];
1289
1298
  let bad = false;
1290
1299
  let viewportReported = false;
1300
+ let fontCors = false;
1291
1301
  for (const width of [390, 1280]) for (const theme of ["light", "dark"]) {
1292
1302
  const phone = width === 390;
1293
1303
  const viewport = {
@@ -1309,6 +1319,7 @@ async function check(targets, opts) {
1309
1319
  if (m.type() !== "error") return;
1310
1320
  const src = m.location().url;
1311
1321
  if (/\/favicon\.ico$/.test(src)) return;
1322
+ if (isFileFontCors(url, m.text(), src)) return void (fontCors = true);
1312
1323
  errors.push(src && src !== url ? `${m.text()} (${src})` : m.text());
1313
1324
  });
1314
1325
  const resp = await page.goto(url, { waitUntil: "load" }).catch((e) => {
@@ -1443,6 +1454,7 @@ async function check(targets, opts) {
1443
1454
  await ctx.close();
1444
1455
  }
1445
1456
  }
1457
+ if (fontCors) out.push(" note: fonts were blocked by CORS because the page is a file:// URL; serve the page over http to load fonts");
1446
1458
  return {
1447
1459
  out,
1448
1460
  bad
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seanyeh77/ui-cli",
3
- "version": "0.47.0",
3
+ "version": "0.47.1",
4
4
  "description": "Checks a page against SeanYeh's design system, compares its screenshots with baselines and prints component docs: ui check, ui shots, ui docs, ui list.",
5
5
  "license": "MIT",
6
6
  "author": "Hsiu-An Yeh",
@@ -21,7 +21,7 @@
21
21
  "pixelmatch": "^8.0.0",
22
22
  "playwright": "1.65.0",
23
23
  "pngjs": "^7.0.0",
24
- "@seanyeh77/ui": "^0.47.0"
24
+ "@seanyeh77/ui": "^0.47.1"
25
25
  },
26
26
  "engines": {
27
27
  "node": ">=22"