create-abcart-theme 0.10.1 → 1.0.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.
Files changed (251) hide show
  1. package/CHANGELOG.md +133 -127
  2. package/LICENSE +202 -202
  3. package/NOTICE +2 -2
  4. package/README.md +65 -65
  5. package/bin/create-abcart-theme.mjs +4 -4
  6. package/package.json +49 -49
  7. package/src/args.mjs +113 -113
  8. package/src/banner.mjs +21 -21
  9. package/src/cli.mjs +119 -119
  10. package/src/create.mjs +85 -82
  11. package/src/package-manager.mjs +32 -32
  12. package/src/style.mjs +17 -17
  13. package/templates/default/.agents/skills/{wocart-docs → abcart-docs}/SKILL.md +146 -146
  14. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/SKILL.md +58 -58
  15. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/inputs-and-rights.md +47 -47
  16. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/layout-rtl-and-phone.md +36 -36
  17. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/measure-the-design.md +60 -60
  18. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/tokens-sections-content.md +103 -103
  19. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/verify-and-report.md +102 -102
  20. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/scripts/compare-design.cjs +230 -230
  21. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/scripts/qa-pages.cjs +219 -219
  22. package/templates/default/.agents/skills/shopify-theme-asset-collector/SKILL.md +125 -125
  23. package/templates/default/.agents/skills/shopify-theme-asset-collector/scripts/collect_public_assets.py +370 -370
  24. package/templates/default/.dev.vars.example +12 -12
  25. package/templates/default/AGENTS.md +240 -240
  26. package/templates/default/README.md +184 -184
  27. package/templates/default/_gitignore +11 -11
  28. package/templates/default/astro.config.mjs +85 -85
  29. package/templates/default/package.json +36 -36
  30. package/templates/default/public/fonts/OFL.txt +96 -96
  31. package/templates/default/src/actions/index.ts +22 -22
  32. package/templates/default/src/components/cart/AddToCartButton.astro +45 -45
  33. package/templates/default/src/components/cart/CartDrawer.astro +47 -47
  34. package/templates/default/src/components/cart/CartSummary.astro +11 -11
  35. package/templates/default/src/components/cart/FreeShipping.astro +7 -7
  36. package/templates/default/src/components/checkout/CheckoutMain.astro +29 -29
  37. package/templates/default/src/components/checkout/OrderForm.astro +280 -280
  38. package/templates/default/src/components/checkout/ThankYouMain.astro +68 -68
  39. package/templates/default/src/components/landing/LandingImages.astro +51 -51
  40. package/templates/default/src/components/landing/LandingOrder.astro +46 -46
  41. package/templates/default/src/components/landing/LandingProduct.astro +41 -41
  42. package/templates/default/src/components/listing/ListingMain.astro +93 -93
  43. package/templates/default/src/components/listing/PageMain.astro +52 -52
  44. package/templates/default/src/components/listing/Pagination.astro +31 -31
  45. package/templates/default/src/components/listing/SortControl.astro +35 -35
  46. package/templates/default/src/components/product/BuyBox.astro +96 -96
  47. package/templates/default/src/components/product/Description.astro +24 -24
  48. package/templates/default/src/components/product/Gallery.astro +66 -66
  49. package/templates/default/src/components/product/MobileBuyBar.astro +29 -29
  50. package/templates/default/src/components/product/OfferChoice.astro +66 -66
  51. package/templates/default/src/components/product/ProductMain.astro +40 -40
  52. package/templates/default/src/components/product/ProductReviews.astro +72 -72
  53. package/templates/default/src/components/product/RelatedProducts.astro +30 -30
  54. package/templates/default/src/components/product/blocks/BenefitsBlock.astro +13 -13
  55. package/templates/default/src/components/product/blocks/CollapsibleBlock.astro +20 -20
  56. package/templates/default/src/components/product/blocks/DescriptionBlock.astro +19 -19
  57. package/templates/default/src/components/product/blocks/DetailsBlock.astro +33 -33
  58. package/templates/default/src/components/product/blocks/GalleryBlock.astro +12 -12
  59. package/templates/default/src/components/product/blocks/OrderBlock.astro +30 -30
  60. package/templates/default/src/components/product/blocks/PriceBlock.astro +23 -23
  61. package/templates/default/src/components/product/blocks/RatingBlock.astro +16 -16
  62. package/templates/default/src/components/product/blocks/StockBlock.astro +22 -22
  63. package/templates/default/src/components/product/blocks/TextBlock.astro +11 -11
  64. package/templates/default/src/components/product/blocks/TitleBlock.astro +20 -20
  65. package/templates/default/src/components/reviews/ReviewCard.astro +46 -46
  66. package/templates/default/src/components/reviews/ReviewForm.astro +113 -113
  67. package/templates/default/src/components/reviews/VoiceNote.astro +60 -60
  68. package/templates/default/src/components/sections/CollectionCards.astro +65 -65
  69. package/templates/default/src/components/sections/Countdown.astro +57 -57
  70. package/templates/default/src/components/sections/Faq.astro +44 -44
  71. package/templates/default/src/components/sections/FeaturedProduct.astro +71 -71
  72. package/templates/default/src/components/sections/Hero.astro +99 -99
  73. package/templates/default/src/components/sections/ImageBanner.astro +46 -46
  74. package/templates/default/src/components/sections/ProductGrid.astro +47 -47
  75. package/templates/default/src/components/sections/RichText.astro +35 -35
  76. package/templates/default/src/components/sections/Steps.astro +46 -46
  77. package/templates/default/src/components/sections/Testimonials.astro +57 -57
  78. package/templates/default/src/components/shell/Footer.astro +80 -80
  79. package/templates/default/src/components/shell/Header.astro +89 -89
  80. package/templates/default/src/components/shell/LanguageMenu.astro +33 -33
  81. package/templates/default/src/components/shell/MobileMenu.astro +65 -65
  82. package/templates/default/src/components/shell/SearchDialog.astro +19 -19
  83. package/templates/default/src/components/shell/TopBar.astro +54 -54
  84. package/templates/default/src/components/shell/WhatsAppWidget.astro +111 -111
  85. package/templates/default/src/components/store/ContactMain.astro +79 -79
  86. package/templates/default/src/components/store/SearchMain.astro +56 -56
  87. package/templates/default/src/components/store/TrackOrderMain.astro +161 -161
  88. package/templates/default/src/components/surface/Area.astro +20 -20
  89. package/templates/default/src/components/surface/PreviewBridge.astro +24 -24
  90. package/templates/default/src/components/surface/Sections.astro +35 -35
  91. package/templates/default/src/components/ui/Breadcrumbs.astro +36 -36
  92. package/templates/default/src/components/ui/Button.astro +45 -45
  93. package/templates/default/src/components/ui/EditorPlaceholder.astro +24 -24
  94. package/templates/default/src/components/ui/Icon.astro +93 -93
  95. package/templates/default/src/components/ui/Logo.astro +36 -36
  96. package/templates/default/src/components/ui/Photo.astro +46 -46
  97. package/templates/default/src/components/ui/Price.astro +24 -24
  98. package/templates/default/src/components/ui/ProductCard.astro +41 -41
  99. package/templates/default/src/components/ui/Rating.astro +22 -22
  100. package/templates/default/src/components/ui/Section.astro +34 -34
  101. package/templates/default/src/components/ui/SectionHeading.astro +19 -19
  102. package/templates/default/src/env.d.ts +23 -23
  103. package/templates/default/src/layouts/StoreLayout.astro +145 -145
  104. package/templates/default/src/lib/browser-copy.ts +37 -37
  105. package/templates/default/src/lib/context.ts +89 -89
  106. package/templates/default/src/lib/coupon-notice.ts +47 -47
  107. package/templates/default/src/lib/i18n.ts +32 -32
  108. package/templates/default/src/lib/images.ts +38 -38
  109. package/templates/default/src/lib/listing-query.ts +41 -41
  110. package/templates/default/src/lib/money.ts +16 -16
  111. package/templates/default/src/lib/motion.ts +16 -16
  112. package/templates/default/src/lib/nav.ts +26 -26
  113. package/templates/default/src/lib/offer-tiles.ts +105 -105
  114. package/templates/default/src/lib/order-outcome.ts +66 -66
  115. package/templates/default/src/lib/otp-message.ts +21 -21
  116. package/templates/default/src/lib/products.ts +38 -38
  117. package/templates/default/src/lib/review-refusals.ts +31 -31
  118. package/templates/default/src/lib/store.ts +31 -31
  119. package/templates/default/src/lib/whatsapp.ts +29 -29
  120. package/templates/default/src/middleware.ts +23 -23
  121. package/templates/default/src/pages/404.astro +22 -22
  122. package/templates/default/src/pages/{wocart-preview.astro → abcart-preview.astro} +43 -43
  123. package/templates/default/src/pages/{wocart-revalidate.ts → abcart-revalidate.ts} +10 -10
  124. package/templates/default/src/pages/{wocart-styles.css.ts → abcart-styles.css.ts} +5 -5
  125. package/templates/default/src/pages/{wocart-theme.json.ts → abcart-theme.json.ts} +5 -5
  126. package/templates/default/src/pages/api/abandoned/convert.ts +4 -4
  127. package/templates/default/src/pages/api/abandoned/upsert.ts +4 -4
  128. package/templates/default/src/pages/api/cart/validate.ts +4 -4
  129. package/templates/default/src/pages/api/communes/[wilayaId].ts +4 -4
  130. package/templates/default/src/pages/api/otp/send.ts +4 -4
  131. package/templates/default/src/pages/api/otp/verify.ts +4 -4
  132. package/templates/default/src/pages/api/reviews/[productId].ts +3 -3
  133. package/templates/default/src/pages/api/reviews/eligibility.ts +3 -3
  134. package/templates/default/src/pages/api/reviews/submit.ts +3 -3
  135. package/templates/default/src/pages/api/reviews/upload.ts +3 -3
  136. package/templates/default/src/pages/category/[slug].astro +20 -20
  137. package/templates/default/src/pages/checkout.astro +25 -25
  138. package/templates/default/src/pages/collections/[handle].astro +20 -20
  139. package/templates/default/src/pages/contact.astro +17 -17
  140. package/templates/default/src/pages/index.astro +9 -9
  141. package/templates/default/src/pages/lp/[slug].astro +47 -47
  142. package/templates/default/src/pages/pages/[slug].astro +16 -16
  143. package/templates/default/src/pages/products/[handle].astro +37 -37
  144. package/templates/default/src/pages/products/index.astro +15 -15
  145. package/templates/default/src/pages/robots.txt.ts +9 -9
  146. package/templates/default/src/pages/search.astro +19 -19
  147. package/templates/default/src/pages/sitemap.xml.ts +12 -12
  148. package/templates/default/src/pages/thank-you.astro +33 -33
  149. package/templates/default/src/pages/track-order.astro +17 -17
  150. package/templates/default/src/scripts/cart.ts +371 -371
  151. package/templates/default/src/scripts/checkout/coupon.ts +96 -96
  152. package/templates/default/src/scripts/checkout/delivery.ts +86 -86
  153. package/templates/default/src/scripts/checkout/form.ts +54 -54
  154. package/templates/default/src/scripts/checkout/otp.ts +106 -106
  155. package/templates/default/src/scripts/checkout/picker.ts +169 -169
  156. package/templates/default/src/scripts/checkout/quote.ts +169 -169
  157. package/templates/default/src/scripts/checkout/submit.ts +113 -113
  158. package/templates/default/src/scripts/checkout/tracking.ts +74 -74
  159. package/templates/default/src/scripts/countdown.ts +29 -29
  160. package/templates/default/src/scripts/events.ts +4 -4
  161. package/templates/default/src/scripts/hero.ts +49 -49
  162. package/templates/default/src/scripts/listing.ts +13 -13
  163. package/templates/default/src/scripts/order-form.ts +100 -100
  164. package/templates/default/src/scripts/product.ts +306 -306
  165. package/templates/default/src/scripts/public-config.ts +79 -79
  166. package/templates/default/src/scripts/reviews.ts +358 -358
  167. package/templates/default/src/scripts/site.ts +131 -131
  168. package/templates/default/src/scripts/thank-you.ts +11 -11
  169. package/templates/default/src/scripts/voice-note.ts +94 -94
  170. package/templates/default/src/styles/base.css +1030 -1030
  171. package/templates/default/src/styles/checkout.css +1111 -1111
  172. package/templates/default/src/styles/global.css +12 -12
  173. package/templates/default/src/styles/product.css +871 -871
  174. package/templates/default/src/styles/reviews.css +533 -533
  175. package/templates/default/src/styles/sections.css +931 -931
  176. package/templates/default/src/styles/shell.css +970 -970
  177. package/templates/default/src/styles/tokens.css +583 -583
  178. package/templates/default/src/theme/api-routes.ts +10 -10
  179. package/templates/default/src/theme/content/catalog.ts +117 -117
  180. package/templates/default/src/theme/content/checkout.ts +168 -168
  181. package/templates/default/src/theme/content/editor.ts +21 -21
  182. package/templates/default/src/theme/content/index.ts +45 -45
  183. package/templates/default/src/theme/content/reviews.ts +76 -76
  184. package/templates/default/src/theme/content/shell.ts +59 -59
  185. package/templates/default/src/theme/content/types.ts +12 -12
  186. package/templates/default/src/theme/documents/catalog.json +11 -11
  187. package/templates/default/src/theme/documents/category.json +11 -11
  188. package/templates/default/src/theme/documents/checkout.json +11 -11
  189. package/templates/default/src/theme/documents/collection.json +11 -11
  190. package/templates/default/src/theme/documents/contact.json +11 -11
  191. package/templates/default/src/theme/documents/footer.area.json +11 -11
  192. package/templates/default/src/theme/documents/header.area.json +16 -16
  193. package/templates/default/src/theme/documents/home.json +313 -313
  194. package/templates/default/src/theme/documents/landing.json +8 -8
  195. package/templates/default/src/theme/documents/page.json +11 -11
  196. package/templates/default/src/theme/documents/product.json +125 -125
  197. package/templates/default/src/theme/documents/search.json +11 -11
  198. package/templates/default/src/theme/documents/thank-you.json +11 -11
  199. package/templates/default/src/theme/documents/track-order.json +11 -11
  200. package/templates/default/src/theme/fields.ts +61 -61
  201. package/templates/default/src/theme/key.ts +11 -11
  202. package/templates/default/src/theme/labels.ts +231 -231
  203. package/templates/default/src/theme/locales.ts +11 -11
  204. package/templates/default/src/theme/palette.ts +14 -14
  205. package/templates/default/src/theme/sections/collection-cards.ts +65 -65
  206. package/templates/default/src/theme/sections/faq.ts +74 -74
  207. package/templates/default/src/theme/sections/featured-product.ts +42 -42
  208. package/templates/default/src/theme/sections/hero.ts +47 -47
  209. package/templates/default/src/theme/sections/image-banner.ts +25 -25
  210. package/templates/default/src/theme/sections/index.ts +40 -40
  211. package/templates/default/src/theme/sections/landing.ts +150 -150
  212. package/templates/default/src/theme/sections/listing.ts +84 -84
  213. package/templates/default/src/theme/sections/product-grid.ts +42 -42
  214. package/templates/default/src/theme/sections/product.ts +297 -297
  215. package/templates/default/src/theme/sections/rich-text.ts +39 -39
  216. package/templates/default/src/theme/sections/shared.ts +54 -54
  217. package/templates/default/src/theme/sections/shell.ts +85 -85
  218. package/templates/default/src/theme/sections/store-pages.ts +101 -101
  219. package/templates/default/src/theme/sections/testimonials.ts +61 -61
  220. package/templates/default/src/theme/sections/thank-you.ts +35 -35
  221. package/templates/default/src/theme/settings.ts +124 -124
  222. package/templates/default/src/theme/theme.ts +65 -65
  223. package/templates/default/tests/fixtures/canvas-tote.json +62 -62
  224. package/templates/default/tests/fixtures/linen-shirt.json +128 -128
  225. package/templates/default/tests/unit/checkout.test.ts +241 -241
  226. package/templates/default/tests/unit/contract.test.ts +170 -169
  227. package/templates/default/tests/unit/contrast.test.ts +68 -68
  228. package/templates/default/tests/unit/copy.test.ts +101 -101
  229. package/templates/default/tests/unit/design-values.test.ts +95 -95
  230. package/templates/default/tests/unit/editability.test.ts +180 -180
  231. package/templates/default/tests/unit/fixtures.ts +91 -91
  232. package/templates/default/tests/unit/footer.test.ts +54 -54
  233. package/templates/default/tests/unit/guards.test.ts +340 -340
  234. package/templates/default/tests/unit/images.test.ts +26 -26
  235. package/templates/default/tests/unit/landing.test.ts +151 -151
  236. package/templates/default/tests/unit/languages.test.ts +42 -42
  237. package/templates/default/tests/unit/middleware.test.ts +53 -53
  238. package/templates/default/tests/unit/offer-tiles.test.ts +75 -75
  239. package/templates/default/tests/unit/render.ts +38 -38
  240. package/templates/default/tests/unit/reviews.test.ts +25 -25
  241. package/templates/default/tests/unit/rules.test.ts +59 -59
  242. package/templates/default/tests/unit/source.ts +75 -75
  243. package/templates/default/tests/unit/store-pages.test.ts +147 -147
  244. package/templates/default/tests/unit/studio.test.ts +202 -202
  245. package/templates/default/tests/unit/testimonials.test.ts +52 -52
  246. package/templates/default/tests/unit/thank-you.test.ts +52 -52
  247. package/templates/default/tests/unit/tracking.test.ts +29 -29
  248. package/templates/default/tests/unit/voice-note.test.ts +42 -42
  249. package/templates/default/tsconfig.json +13 -13
  250. package/templates/default/vitest.config.ts +15 -15
  251. package/templates/default/wrangler.jsonc +16 -16
@@ -1,219 +1,219 @@
1
- /**
2
- * Page QA for a running theme: every page the store links to, at a desktop
3
- * width and at a phone width, in one language. It reports what the eye can
4
- * miss in a screenshot and what a check can name:
5
- *
6
- * overflow an element wider than the viewport (outside a swipe row)
7
- * broken an image that did not load
8
- * keys a translation key printed as text
9
- * errors a console error or an uncaught exception
10
- * contrast text below WCAG AA on the surface it is read from
11
- * partial-row a grid whose last row leaves empty columns (a warning)
12
- *
13
- * Usage (Node 20+, Playwright installed where Node can find it):
14
- * BASE=http://localhost:4321 LANG_CODE=ar node qa-pages.cjs
15
- * FRAMES=1 … also save a viewport-sized frame per scroll step
16
- * CHROME=/path/to/chrome optional: a Chromium binary to launch
17
- * PLAYWRIGHT=/path/to/playwright optional: where to load Playwright from
18
- * Exit status 1 when a page has an overflow, a broken image, a leaked key,
19
- * a console error or a contrast failure. Warnings never fail the run.
20
- */
21
- const fs = require("fs");
22
- const path = require("path");
23
- const { chromium } = require(process.env.PLAYWRIGHT || "playwright");
24
-
25
- const BASE = (process.env.BASE || "http://localhost:4321").replace(/\/$/, "");
26
- const LANG = process.env.LANG_CODE || "ar";
27
- const OUT = process.env.OUT || path.join(process.cwd(), "qa-out");
28
- const FRAMES = process.env.FRAMES === "1";
29
- const VIEWPORTS = {
30
- desktop: { viewport: { width: 1440, height: 900 } },
31
- phone: { viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true },
32
- };
33
-
34
- /** Pages to visit: the fixed ones, then the first few the home page links to. */
35
- async function languagePrefix(page) {
36
- await page.goto(`${BASE}/`, { waitUntil: "networkidle" });
37
- const root = await page.getAttribute("html", "lang");
38
- return root === LANG ? "" : `/${LANG}`;
39
- }
40
-
41
- async function discoverRoutes(page, prefix) {
42
- await page.goto(`${BASE}${prefix}/`, { waitUntil: "networkidle" });
43
- const links = await page.$$eval("a[href]", (as) => [...new Set(as.map((a) => a.getAttribute("href")))]);
44
- const internal = [...new Set(links.filter((h) => h && h.startsWith("/")).map((h) => h.split(/[?#]/)[0]))];
45
- const pick = (needle, count) => internal.filter((h) => h.includes(needle)).slice(0, count);
46
- const strip = (href) => href.replace(/^\/(ar|fr|en)(?=\/|$)/, "").replace(/^\//, "");
47
- const routes = [
48
- "",
49
- ...pick("/products/", 2).map(strip),
50
- ...pick("/collections/", 1).map(strip),
51
- ...pick("/pages/", 1).map(strip),
52
- "products",
53
- "search?q=a",
54
- "contact",
55
- "track-order",
56
- "checkout",
57
- "this-page-does-not-exist",
58
- ];
59
- return [...new Set(routes)];
60
- }
61
-
62
- /** The page's own checks, run inside the page. */
63
- const AUDIT = () => {
64
- const vw = window.innerWidth;
65
- const visible = (el) => {
66
- const r = el.getBoundingClientRect();
67
- if (r.width === 0 || r.height === 0) return null;
68
- const cs = getComputedStyle(el);
69
- if (cs.display === "none" || cs.visibility === "hidden") return null;
70
- return { r, cs };
71
- };
72
- const clippedByAncestor = (el) => {
73
- for (let p = el.parentElement; p && p !== document.body; p = p.parentElement) {
74
- const pc = getComputedStyle(p);
75
- if (pc.overflowX !== "visible" && pc.overflow !== "visible") {
76
- const pr = p.getBoundingClientRect();
77
- if (pr.right <= vw + 1 && pr.left >= -1) return true;
78
- }
79
- }
80
- return false;
81
- };
82
- const overflow = [];
83
- for (const el of document.querySelectorAll("body *")) {
84
- const v = visible(el);
85
- if (!v || (v.r.right <= vw + 1 && v.r.left >= -1)) continue;
86
- if (!clippedByAncestor(el)) overflow.push(`${el.tagName.toLowerCase()}.${String(el.className).split(" ")[0]} ${Math.round(v.r.left)}..${Math.round(v.r.right)}`);
87
- }
88
-
89
- const broken = [...document.images].filter((img) => img.complete && img.naturalWidth === 0 && img.getAttribute("src")).map((img) => img.getAttribute("src").slice(0, 90));
90
-
91
- const keys = (document.body.innerText.match(/\b[a-z]{3,}\.[a-z][A-Za-z]{2,}\b/g) || []).filter((k) => /^(cart|checkout|product|order|common|nav|footer|home|search|contact|track|header|offer|reviews|theme|store)\./.test(k));
92
-
93
- const parse = (c) => {
94
- const m = c.match(/rgba?\(([^)]+)\)/);
95
- if (!m) return null;
96
- const p = m[1].split(/[ ,/]+/).filter(Boolean).map(Number);
97
- return { r: p[0], g: p[1], b: p[2], a: p.length > 3 ? p[3] : 1 };
98
- };
99
- const luminance = ({ r, g, b }) => {
100
- const f = (v) => { v /= 255; return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; };
101
- return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b);
102
- };
103
- const over = (top, bottom) => ({ r: top.r * top.a + bottom.r * (1 - top.a), g: top.g * top.a + bottom.g * (1 - top.a), b: top.b * top.a + bottom.b * (1 - top.a), a: 1 });
104
- const surface = (el) => {
105
- const layers = [];
106
- let photo = false;
107
- for (let n = el; n; n = n.parentElement) {
108
- const cs = getComputedStyle(n);
109
- if (cs.backgroundImage !== "none" || (n.querySelector && n.querySelector(":scope > img, :scope > picture"))) photo = true;
110
- const c = parse(cs.backgroundColor);
111
- if (c && c.a > 0) { layers.push(c); if (c.a >= 1) break; }
112
- }
113
- let base = { r: 255, g: 255, b: 255, a: 1 };
114
- for (let i = layers.length - 1; i >= 0; i--) base = over(layers[i], base);
115
- return { base, photo };
116
- };
117
- const contrast = [];
118
- const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
119
- for (let node = walker.nextNode(); node; node = walker.nextNode()) {
120
- if (node.textContent.trim().length < 2) continue;
121
- const el = node.parentElement;
122
- if (!el || ["SCRIPT", "STYLE", "NOSCRIPT"].includes(el.tagName)) continue;
123
- const v = visible(el);
124
- if (!v) continue;
125
- let opacity = 1;
126
- for (let n = el; n; n = n.parentElement) opacity *= parseFloat(getComputedStyle(n).opacity);
127
- if (opacity < 0.99) continue;
128
- const fg0 = parse(v.cs.color);
129
- if (!fg0) continue;
130
- const { base, photo } = surface(el);
131
- const fg = over(fg0, base);
132
- const [hi, lo] = [luminance(fg), luminance(base)].sort((a, b) => b - a);
133
- const ratio = (hi + 0.05) / (lo + 0.05);
134
- const size = parseFloat(v.cs.fontSize);
135
- const large = size >= 24 || (size >= 18.66 && parseInt(v.cs.fontWeight, 10) >= 700);
136
- const need = large ? 3 : 4.5;
137
- if (ratio < need) contrast.push({ ratio: Math.round(ratio * 100) / 100, need, photo, text: node.textContent.trim().slice(0, 40), cls: String(el.className).split(" ")[0] || el.tagName.toLowerCase() });
138
- }
139
-
140
- const partialRows = [];
141
- for (const grid of document.querySelectorAll("[class*='grid'], [class*='cards'], [class*='testimonials']")) {
142
- const cs = getComputedStyle(grid);
143
- if (cs.display !== "grid") continue;
144
- const kids = [...grid.children].filter((k) => visible(k));
145
- if (kids.length < 2) continue;
146
- const rows = new Map();
147
- for (const k of kids) { const top = Math.round(k.getBoundingClientRect().top); rows.set(top, (rows.get(top) || 0) + 1); }
148
- const perRow = Math.max(...rows.values());
149
- const last = rows.get([...rows.keys()].sort((a, b) => b - a)[0]);
150
- if (rows.size > 1 && last < perRow && cs.gridTemplateColumns.split(" ").length === perRow) {
151
- partialRows.push(`${grid.className.split(" ")[0]} last row ${last} of ${perRow}`);
152
- }
153
- }
154
- return { scrollWidth: document.documentElement.scrollWidth, innerWidth: vw, overflow: overflow.slice(0, 8), overflowCount: overflow.length, broken: broken.slice(0, 5), keys: keys.slice(0, 5), contrast, partialRows };
155
- };
156
-
157
- (async () => {
158
- fs.mkdirSync(OUT, { recursive: true });
159
- const launch = process.env.CHROME ? { executablePath: process.env.CHROME } : {};
160
- const browser = await chromium.launch(launch);
161
- const probe = await browser.newPage();
162
- const prefix = await languagePrefix(probe);
163
- const routes = await discoverRoutes(probe, prefix);
164
- await probe.close();
165
- const failures = [];
166
- const warnings = [];
167
- for (const [vpName, vpOpts] of Object.entries(VIEWPORTS)) {
168
- const context = await browser.newContext({ ...vpOpts, locale: LANG === "ar" ? "ar-DZ" : LANG === "fr" ? "fr-DZ" : "en-US" });
169
- for (const route of routes) {
170
- const page = await context.newPage();
171
- const errors = [];
172
- page.on("console", (m) => { if (m.type() === "error") errors.push(m.text()); });
173
- page.on("pageerror", (e) => errors.push(`uncaught ${e.message}`));
174
- const url = `${BASE}${prefix}/${route}`.replace(/\/$/, "");
175
- const label = `${LANG} ${vpName} /${route}`;
176
- try {
177
- await page.goto(url, { waitUntil: "networkidle", timeout: 45000 });
178
- await page.evaluate(async () => {
179
- for (let y = 0; y < document.body.scrollHeight; y += 500) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 40)); }
180
- window.scrollTo(0, 0);
181
- });
182
- await page.waitForTimeout(900);
183
- const info = await page.evaluate(AUDIT);
184
- const realErrors = errors.filter((e) => !/status of 404/.test(e) || !route.includes("this-page-does-not-exist"));
185
- if (info.horizontalScroll || info.scrollWidth > info.innerWidth) failures.push(`${label}: wider than the viewport (${info.scrollWidth}px)`);
186
- if (info.overflowCount) failures.push(`${label}: ${info.overflowCount} overflow, e.g. ${info.overflow.slice(0, 2).join("; ")}`);
187
- if (info.broken.length) failures.push(`${label}: broken images ${info.broken.join(", ")}`);
188
- if (info.keys.length) failures.push(`${label}: translation keys printed ${info.keys.join(", ")}`);
189
- if (realErrors.length) failures.push(`${label}: console errors ${realErrors.slice(0, 2).join(" | ").slice(0, 180)}`);
190
- for (const c of info.contrast) {
191
- const line = `${label}: text "${c.text}" ${c.ratio}:1 (needs ${c.need}) on ${c.cls}${c.photo ? " over a photo, check by eye" : ""}`;
192
- (c.photo ? warnings : failures).push(line);
193
- }
194
- for (const row of info.partialRows) warnings.push(`${label}: ${row}`);
195
- if (FRAMES) {
196
- const dir = path.join(OUT, `${LANG}-${vpName}-${(route || "home").replace(/[^a-z0-9]+/gi, "_")}`);
197
- fs.mkdirSync(dir, { recursive: true });
198
- const h = vpOpts.viewport.height;
199
- const total = await page.evaluate(() => document.documentElement.scrollHeight);
200
- for (let y = 0, i = 0; y < total && i < 14; y += h - 80, i++) {
201
- await page.evaluate((yy) => window.scrollTo(0, yy), y);
202
- await page.waitForTimeout(700);
203
- await page.screenshot({ path: path.join(dir, `${String(i).padStart(2, "0")}.png`) });
204
- }
205
- }
206
- } catch (e) {
207
- failures.push(`${label}: did not load (${e.message.split("\n")[0].slice(0, 120)})`);
208
- }
209
- await page.close();
210
- }
211
- await context.close();
212
- }
213
- await browser.close();
214
- console.log(`routes: ${routes.map((r) => "/" + r).join(" ")}`);
215
- console.log(`page-viewports: ${routes.length * Object.keys(VIEWPORTS).length}`);
216
- console.log(`warnings (${warnings.length}):`); warnings.forEach((w) => console.log(" " + w));
217
- console.log(`failures (${failures.length}):`); failures.forEach((f) => console.log(" " + f));
218
- process.exit(failures.length ? 1 : 0);
219
- })().catch((e) => { console.error("QA could not run:", e.message); process.exit(2); });
1
+ /**
2
+ * Page QA for a running theme: every page the store links to, at a desktop
3
+ * width and at a phone width, in one language. It reports what the eye can
4
+ * miss in a screenshot and what a check can name:
5
+ *
6
+ * overflow an element wider than the viewport (outside a swipe row)
7
+ * broken an image that did not load
8
+ * keys a translation key printed as text
9
+ * errors a console error or an uncaught exception
10
+ * contrast text below WCAG AA on the surface it is read from
11
+ * partial-row a grid whose last row leaves empty columns (a warning)
12
+ *
13
+ * Usage (Node 20+, Playwright installed where Node can find it):
14
+ * BASE=http://localhost:4321 LANG_CODE=ar node qa-pages.cjs
15
+ * FRAMES=1 … also save a viewport-sized frame per scroll step
16
+ * CHROME=/path/to/chrome optional: a Chromium binary to launch
17
+ * PLAYWRIGHT=/path/to/playwright optional: where to load Playwright from
18
+ * Exit status 1 when a page has an overflow, a broken image, a leaked key,
19
+ * a console error or a contrast failure. Warnings never fail the run.
20
+ */
21
+ const fs = require("fs");
22
+ const path = require("path");
23
+ const { chromium } = require(process.env.PLAYWRIGHT || "playwright");
24
+
25
+ const BASE = (process.env.BASE || "http://localhost:4321").replace(/\/$/, "");
26
+ const LANG = process.env.LANG_CODE || "ar";
27
+ const OUT = process.env.OUT || path.join(process.cwd(), "qa-out");
28
+ const FRAMES = process.env.FRAMES === "1";
29
+ const VIEWPORTS = {
30
+ desktop: { viewport: { width: 1440, height: 900 } },
31
+ phone: { viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true },
32
+ };
33
+
34
+ /** Pages to visit: the fixed ones, then the first few the home page links to. */
35
+ async function languagePrefix(page) {
36
+ await page.goto(`${BASE}/`, { waitUntil: "networkidle" });
37
+ const root = await page.getAttribute("html", "lang");
38
+ return root === LANG ? "" : `/${LANG}`;
39
+ }
40
+
41
+ async function discoverRoutes(page, prefix) {
42
+ await page.goto(`${BASE}${prefix}/`, { waitUntil: "networkidle" });
43
+ const links = await page.$$eval("a[href]", (as) => [...new Set(as.map((a) => a.getAttribute("href")))]);
44
+ const internal = [...new Set(links.filter((h) => h && h.startsWith("/")).map((h) => h.split(/[?#]/)[0]))];
45
+ const pick = (needle, count) => internal.filter((h) => h.includes(needle)).slice(0, count);
46
+ const strip = (href) => href.replace(/^\/(ar|fr|en)(?=\/|$)/, "").replace(/^\//, "");
47
+ const routes = [
48
+ "",
49
+ ...pick("/products/", 2).map(strip),
50
+ ...pick("/collections/", 1).map(strip),
51
+ ...pick("/pages/", 1).map(strip),
52
+ "products",
53
+ "search?q=a",
54
+ "contact",
55
+ "track-order",
56
+ "checkout",
57
+ "this-page-does-not-exist",
58
+ ];
59
+ return [...new Set(routes)];
60
+ }
61
+
62
+ /** The page's own checks, run inside the page. */
63
+ const AUDIT = () => {
64
+ const vw = window.innerWidth;
65
+ const visible = (el) => {
66
+ const r = el.getBoundingClientRect();
67
+ if (r.width === 0 || r.height === 0) return null;
68
+ const cs = getComputedStyle(el);
69
+ if (cs.display === "none" || cs.visibility === "hidden") return null;
70
+ return { r, cs };
71
+ };
72
+ const clippedByAncestor = (el) => {
73
+ for (let p = el.parentElement; p && p !== document.body; p = p.parentElement) {
74
+ const pc = getComputedStyle(p);
75
+ if (pc.overflowX !== "visible" && pc.overflow !== "visible") {
76
+ const pr = p.getBoundingClientRect();
77
+ if (pr.right <= vw + 1 && pr.left >= -1) return true;
78
+ }
79
+ }
80
+ return false;
81
+ };
82
+ const overflow = [];
83
+ for (const el of document.querySelectorAll("body *")) {
84
+ const v = visible(el);
85
+ if (!v || (v.r.right <= vw + 1 && v.r.left >= -1)) continue;
86
+ if (!clippedByAncestor(el)) overflow.push(`${el.tagName.toLowerCase()}.${String(el.className).split(" ")[0]} ${Math.round(v.r.left)}..${Math.round(v.r.right)}`);
87
+ }
88
+
89
+ const broken = [...document.images].filter((img) => img.complete && img.naturalWidth === 0 && img.getAttribute("src")).map((img) => img.getAttribute("src").slice(0, 90));
90
+
91
+ const keys = (document.body.innerText.match(/\b[a-z]{3,}\.[a-z][A-Za-z]{2,}\b/g) || []).filter((k) => /^(cart|checkout|product|order|common|nav|footer|home|search|contact|track|header|offer|reviews|theme|store)\./.test(k));
92
+
93
+ const parse = (c) => {
94
+ const m = c.match(/rgba?\(([^)]+)\)/);
95
+ if (!m) return null;
96
+ const p = m[1].split(/[ ,/]+/).filter(Boolean).map(Number);
97
+ return { r: p[0], g: p[1], b: p[2], a: p.length > 3 ? p[3] : 1 };
98
+ };
99
+ const luminance = ({ r, g, b }) => {
100
+ const f = (v) => { v /= 255; return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; };
101
+ return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b);
102
+ };
103
+ const over = (top, bottom) => ({ r: top.r * top.a + bottom.r * (1 - top.a), g: top.g * top.a + bottom.g * (1 - top.a), b: top.b * top.a + bottom.b * (1 - top.a), a: 1 });
104
+ const surface = (el) => {
105
+ const layers = [];
106
+ let photo = false;
107
+ for (let n = el; n; n = n.parentElement) {
108
+ const cs = getComputedStyle(n);
109
+ if (cs.backgroundImage !== "none" || (n.querySelector && n.querySelector(":scope > img, :scope > picture"))) photo = true;
110
+ const c = parse(cs.backgroundColor);
111
+ if (c && c.a > 0) { layers.push(c); if (c.a >= 1) break; }
112
+ }
113
+ let base = { r: 255, g: 255, b: 255, a: 1 };
114
+ for (let i = layers.length - 1; i >= 0; i--) base = over(layers[i], base);
115
+ return { base, photo };
116
+ };
117
+ const contrast = [];
118
+ const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
119
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
120
+ if (node.textContent.trim().length < 2) continue;
121
+ const el = node.parentElement;
122
+ if (!el || ["SCRIPT", "STYLE", "NOSCRIPT"].includes(el.tagName)) continue;
123
+ const v = visible(el);
124
+ if (!v) continue;
125
+ let opacity = 1;
126
+ for (let n = el; n; n = n.parentElement) opacity *= parseFloat(getComputedStyle(n).opacity);
127
+ if (opacity < 0.99) continue;
128
+ const fg0 = parse(v.cs.color);
129
+ if (!fg0) continue;
130
+ const { base, photo } = surface(el);
131
+ const fg = over(fg0, base);
132
+ const [hi, lo] = [luminance(fg), luminance(base)].sort((a, b) => b - a);
133
+ const ratio = (hi + 0.05) / (lo + 0.05);
134
+ const size = parseFloat(v.cs.fontSize);
135
+ const large = size >= 24 || (size >= 18.66 && parseInt(v.cs.fontWeight, 10) >= 700);
136
+ const need = large ? 3 : 4.5;
137
+ if (ratio < need) contrast.push({ ratio: Math.round(ratio * 100) / 100, need, photo, text: node.textContent.trim().slice(0, 40), cls: String(el.className).split(" ")[0] || el.tagName.toLowerCase() });
138
+ }
139
+
140
+ const partialRows = [];
141
+ for (const grid of document.querySelectorAll("[class*='grid'], [class*='cards'], [class*='testimonials']")) {
142
+ const cs = getComputedStyle(grid);
143
+ if (cs.display !== "grid") continue;
144
+ const kids = [...grid.children].filter((k) => visible(k));
145
+ if (kids.length < 2) continue;
146
+ const rows = new Map();
147
+ for (const k of kids) { const top = Math.round(k.getBoundingClientRect().top); rows.set(top, (rows.get(top) || 0) + 1); }
148
+ const perRow = Math.max(...rows.values());
149
+ const last = rows.get([...rows.keys()].sort((a, b) => b - a)[0]);
150
+ if (rows.size > 1 && last < perRow && cs.gridTemplateColumns.split(" ").length === perRow) {
151
+ partialRows.push(`${grid.className.split(" ")[0]} last row ${last} of ${perRow}`);
152
+ }
153
+ }
154
+ return { scrollWidth: document.documentElement.scrollWidth, innerWidth: vw, overflow: overflow.slice(0, 8), overflowCount: overflow.length, broken: broken.slice(0, 5), keys: keys.slice(0, 5), contrast, partialRows };
155
+ };
156
+
157
+ (async () => {
158
+ fs.mkdirSync(OUT, { recursive: true });
159
+ const launch = process.env.CHROME ? { executablePath: process.env.CHROME } : {};
160
+ const browser = await chromium.launch(launch);
161
+ const probe = await browser.newPage();
162
+ const prefix = await languagePrefix(probe);
163
+ const routes = await discoverRoutes(probe, prefix);
164
+ await probe.close();
165
+ const failures = [];
166
+ const warnings = [];
167
+ for (const [vpName, vpOpts] of Object.entries(VIEWPORTS)) {
168
+ const context = await browser.newContext({ ...vpOpts, locale: LANG === "ar" ? "ar-DZ" : LANG === "fr" ? "fr-DZ" : "en-US" });
169
+ for (const route of routes) {
170
+ const page = await context.newPage();
171
+ const errors = [];
172
+ page.on("console", (m) => { if (m.type() === "error") errors.push(m.text()); });
173
+ page.on("pageerror", (e) => errors.push(`uncaught ${e.message}`));
174
+ const url = `${BASE}${prefix}/${route}`.replace(/\/$/, "");
175
+ const label = `${LANG} ${vpName} /${route}`;
176
+ try {
177
+ await page.goto(url, { waitUntil: "networkidle", timeout: 45000 });
178
+ await page.evaluate(async () => {
179
+ for (let y = 0; y < document.body.scrollHeight; y += 500) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 40)); }
180
+ window.scrollTo(0, 0);
181
+ });
182
+ await page.waitForTimeout(900);
183
+ const info = await page.evaluate(AUDIT);
184
+ const realErrors = errors.filter((e) => !/status of 404/.test(e) || !route.includes("this-page-does-not-exist"));
185
+ if (info.horizontalScroll || info.scrollWidth > info.innerWidth) failures.push(`${label}: wider than the viewport (${info.scrollWidth}px)`);
186
+ if (info.overflowCount) failures.push(`${label}: ${info.overflowCount} overflow, e.g. ${info.overflow.slice(0, 2).join("; ")}`);
187
+ if (info.broken.length) failures.push(`${label}: broken images ${info.broken.join(", ")}`);
188
+ if (info.keys.length) failures.push(`${label}: translation keys printed ${info.keys.join(", ")}`);
189
+ if (realErrors.length) failures.push(`${label}: console errors ${realErrors.slice(0, 2).join(" | ").slice(0, 180)}`);
190
+ for (const c of info.contrast) {
191
+ const line = `${label}: text "${c.text}" ${c.ratio}:1 (needs ${c.need}) on ${c.cls}${c.photo ? " over a photo, check by eye" : ""}`;
192
+ (c.photo ? warnings : failures).push(line);
193
+ }
194
+ for (const row of info.partialRows) warnings.push(`${label}: ${row}`);
195
+ if (FRAMES) {
196
+ const dir = path.join(OUT, `${LANG}-${vpName}-${(route || "home").replace(/[^a-z0-9]+/gi, "_")}`);
197
+ fs.mkdirSync(dir, { recursive: true });
198
+ const h = vpOpts.viewport.height;
199
+ const total = await page.evaluate(() => document.documentElement.scrollHeight);
200
+ for (let y = 0, i = 0; y < total && i < 14; y += h - 80, i++) {
201
+ await page.evaluate((yy) => window.scrollTo(0, yy), y);
202
+ await page.waitForTimeout(700);
203
+ await page.screenshot({ path: path.join(dir, `${String(i).padStart(2, "0")}.png`) });
204
+ }
205
+ }
206
+ } catch (e) {
207
+ failures.push(`${label}: did not load (${e.message.split("\n")[0].slice(0, 120)})`);
208
+ }
209
+ await page.close();
210
+ }
211
+ await context.close();
212
+ }
213
+ await browser.close();
214
+ console.log(`routes: ${routes.map((r) => "/" + r).join(" ")}`);
215
+ console.log(`page-viewports: ${routes.length * Object.keys(VIEWPORTS).length}`);
216
+ console.log(`warnings (${warnings.length}):`); warnings.forEach((w) => console.log(" " + w));
217
+ console.log(`failures (${failures.length}):`); failures.forEach((f) => console.log(" " + f));
218
+ process.exit(failures.length ? 1 : 0);
219
+ })().catch((e) => { console.error("QA could not run:", e.message); process.exit(2); });