Skip to content

Verify

Visual verification, Figma comparison, style capture, and report generation.

9 modules

ModuleDescription
標註截圖在截圖上畫出標記框以標示差異
擷取元素樣式從瀏覽器元素擷取計算樣式
比較樣式將擷取的樣式與預期值進行比較
獲取 Figma 樣式從 Figma API 獲取設計標記(標記保留在本地)
生成報告生成 HTML/JSON/Markdown 格式的驗證報告
載入規則集從 YAML 檔案載入驗證規則
執行驗證執行完整設計驗證:擷取 → 比較 → 報告
執行規格驗證動態規格驗證 - 通過 YAML 組合任何模組
視覺差異視覺上比較參考設計與開發網站,標註差異

Modules

標註截圖

verify.annotate

在截圖上畫出標記框以標示差異

Parameters:

NameTypeRequiredDefaultDescription
image_pathstringYes-截圖圖片的路徑
annotationsarrayYes-標註陣列: [{label, x, y, width, height, color?, description?}]
output_pathstringNo-標註後圖片的輸出路徑(預設:加上 _annotated 後綴)

Output:

FieldTypeDescription
output_pathstring標註後圖片的路徑
annotation_countinteger已畫出的標註數量

擷取元素樣式

verify.capture

從瀏覽器元素擷取計算樣式

Parameters:

NameTypeRequiredDefaultDescription
urlstringYes-URL to capture from
selectorstringYes-CSS selector
wait_forstringNo-Wait for selector before capture
viewport_widthnumberNo1280Viewport width
viewport_heightnumberNo800Viewport height

Output:

FieldTypeDescription
elementobjectCaptured element with styles
foundbooleanWhether element was found

比較樣式

verify.compare

將擷取的樣式與預期值進行比較

Parameters:

NameTypeRequiredDefaultDescription
actualobjectYes-Captured element styles (from verify.capture)
expectedobjectYes-Expected styles to compare against
selectorstringNo-Selector for reporting
size_tolerancenumberNo2.0Tolerance for size (px)
spacing_tolerancenumberNo2.0Tolerance for spacing (px)
font_size_tolerancenumberNo1.0Tolerance for font size (px)
color_tolerancenumberNo5Tolerance for color (0-255)
check_typographybooleanNoTrueCheck typography
check_colorsbooleanNoTrueCheck colors
check_spacingbooleanNoTrueCheck spacing
check_sizingbooleanNoFalseCheck sizing

Output:

FieldTypeDescription
passedbooleanWhether comparison passed
violationsarrayList of violations found
error_countnumberNumber of errors
warning_countnumberNumber of warnings

獲取 Figma 樣式

verify.figma

從 Figma API 獲取設計標記(標記保留在本地)

Parameters:

NameTypeRequiredDefaultDescription
file_idstringYes-Figma file key (from URL)
node_idstringNo-Specific node ID to fetch
node_namestringNo-Find node by name
tokenstringNo-Figma token (or use FIGMA_TOKEN env var)

Output:

FieldTypeDescription
nodeobjectFigma node data
styleobjectExtracted style

生成報告

verify.report

生成 HTML/JSON/Markdown 格式的驗證報告

Parameters:

NameTypeRequiredDefaultDescription
resultsarrayYes-Comparison results from verify.compare
namestringNoverify-reportReport name
urlstringNo-URL that was verified
formatstringNohtmlOutput format (html, json, markdown, all)
output_dirstringNo./verify-reportsOutput directory
screenshotsarrayNo-Screenshot paths to include

Output:

FieldTypeDescription
report_pathstringPath to generated report
summaryobjectSummary statistics

載入規則集

verify.ruleset

從 YAML 檔案載入驗證規則

Parameters:

NameTypeRequiredDefaultDescription
pathstringYes-Path to YAML ruleset file

Output:

FieldTypeDescription
rulesetobjectParsed ruleset
rules_countintegerNumber of rules

執行驗證

verify.run

執行完整設計驗證:擷取 → 比較 → 報告

Parameters:

NameTypeRequiredDefaultDescription
urlstringYes-URL to verify
selectorsarrayNo-CSS selectors to verify
ruleset_pathstringNo-Path to YAML ruleset file
expected_stylesobjectNo-Expected styles per selector
figma_file_idstringNo-Figma file ID for comparison
figma_tokenstringNo-Figma token (or FIGMA_TOKEN env)
figma_mappingobjectNo-Selector to Figma node mapping
output_dirstringNo./verify-reportsOutput directory
report_formatstringNohtmlReport format
take_screenshotbooleanNoTrueCapture screenshot
viewport_widthnumberNo1280Viewport width
viewport_heightnumberNo800Viewport height

Output:

FieldTypeDescription
passedbooleanOverall verification passed
summaryobjectSummary statistics
report_pathstringPath to generated report

Example: Example

yaml
url: http://localhost:3000
selectors: ["button[type=\"submit\"]", "input[type=\"email\"]"]

Example: Example

yaml
url: http://localhost:3000
selectors: ["button.primary"]
figma_file_id: abc123xyz
figma_mapping: {"button.primary": "Primary Button"}

Example: Example

yaml
url: http://localhost:3000
ruleset_path: ./design-rules.yaml

執行規格驗證

verify.spec

動態規格驗證 - 通過 YAML 組合任何模組

Parameters:

NameTypeRequiredDefaultDescription
ruleset_pathstringNo-Path to YAML ruleset file
rulesetobjectNo-Inline ruleset object

Output:

FieldTypeDescription
passedboolean
summaryobject
resultsarray

視覺差異

verify.visual_diff

視覺上比較參考設計與開發網站,標註差異

Parameters:

NameTypeRequiredDefaultDescription
reference_urlstringYes-參考設計的 URL 或本地圖片路徑
dev_urlstringYes-要比較的開發網站 URL
output_dirstringNo./verify-reports/visual-diff報告的輸出目錄
focus_areasarrayNo-需要關注的區域(例如:["header", "login form"])
viewport_widthnumberNo1280瀏覽器視窗寬度
viewport_heightnumberNo800瀏覽器視窗高度
modelstringNogpt-4o使用的視覺模型
api_keystringNo-OpenAI API 金鑰(或使用 OPENAI_API_KEY 環境變數)

Output:

FieldTypeDescription
similarity_scorenumber相似度百分比 (0-100)
annotationsarray標註差異的列表
annotated_imagestring標註後截圖的路徑
report_pathstringHTML 報告的路徑
summarystring差異摘要

Released under the Apache 2.0 License.