create-abcart-theme 0.0.0-stage → 0.10.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 (253) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +2 -0
  4. package/README.md +64 -2
  5. package/bin/create-abcart-theme.mjs +4 -0
  6. package/package.json +47 -4
  7. package/src/args.mjs +113 -0
  8. package/src/banner.mjs +21 -0
  9. package/src/cli.mjs +119 -0
  10. package/src/create.mjs +82 -0
  11. package/src/package-manager.mjs +32 -0
  12. package/src/style.mjs +17 -0
  13. package/templates/default/.agents/skills/shopify-theme-asset-collector/SKILL.md +125 -0
  14. package/templates/default/.agents/skills/shopify-theme-asset-collector/scripts/collect_public_assets.py +370 -0
  15. package/templates/default/.agents/skills/wocart-docs/SKILL.md +146 -0
  16. package/templates/default/.agents/skills/wocart-theme-from-design/SKILL.md +58 -0
  17. package/templates/default/.agents/skills/wocart-theme-from-design/references/inputs-and-rights.md +47 -0
  18. package/templates/default/.agents/skills/wocart-theme-from-design/references/layout-rtl-and-phone.md +36 -0
  19. package/templates/default/.agents/skills/wocart-theme-from-design/references/measure-the-design.md +60 -0
  20. package/templates/default/.agents/skills/wocart-theme-from-design/references/tokens-sections-content.md +103 -0
  21. package/templates/default/.agents/skills/wocart-theme-from-design/references/verify-and-report.md +102 -0
  22. package/templates/default/.agents/skills/wocart-theme-from-design/scripts/compare-design.cjs +230 -0
  23. package/templates/default/.agents/skills/wocart-theme-from-design/scripts/qa-pages.cjs +219 -0
  24. package/templates/default/.dev.vars.example +12 -0
  25. package/templates/default/AGENTS.md +240 -0
  26. package/templates/default/README.md +184 -0
  27. package/templates/default/_gitignore +11 -0
  28. package/templates/default/astro.config.mjs +85 -0
  29. package/templates/default/package.json +36 -0
  30. package/templates/default/public/fonts/OFL.txt +96 -0
  31. package/templates/default/public/fonts/alexandria-arabic.woff2 +0 -0
  32. package/templates/default/public/fonts/fraunces-latin.woff2 +0 -0
  33. package/templates/default/src/actions/index.ts +22 -0
  34. package/templates/default/src/components/cart/AddToCartButton.astro +45 -0
  35. package/templates/default/src/components/cart/CartDrawer.astro +47 -0
  36. package/templates/default/src/components/cart/CartSummary.astro +11 -0
  37. package/templates/default/src/components/cart/FreeShipping.astro +7 -0
  38. package/templates/default/src/components/checkout/CheckoutMain.astro +29 -0
  39. package/templates/default/src/components/checkout/OrderForm.astro +280 -0
  40. package/templates/default/src/components/checkout/ThankYouMain.astro +68 -0
  41. package/templates/default/src/components/landing/LandingImages.astro +51 -0
  42. package/templates/default/src/components/landing/LandingOrder.astro +46 -0
  43. package/templates/default/src/components/landing/LandingProduct.astro +41 -0
  44. package/templates/default/src/components/listing/ListingMain.astro +93 -0
  45. package/templates/default/src/components/listing/PageMain.astro +52 -0
  46. package/templates/default/src/components/listing/Pagination.astro +31 -0
  47. package/templates/default/src/components/listing/SortControl.astro +35 -0
  48. package/templates/default/src/components/product/BuyBox.astro +96 -0
  49. package/templates/default/src/components/product/Description.astro +24 -0
  50. package/templates/default/src/components/product/Gallery.astro +66 -0
  51. package/templates/default/src/components/product/MobileBuyBar.astro +29 -0
  52. package/templates/default/src/components/product/OfferChoice.astro +66 -0
  53. package/templates/default/src/components/product/ProductMain.astro +40 -0
  54. package/templates/default/src/components/product/ProductReviews.astro +72 -0
  55. package/templates/default/src/components/product/RelatedProducts.astro +30 -0
  56. package/templates/default/src/components/product/blocks/BenefitsBlock.astro +13 -0
  57. package/templates/default/src/components/product/blocks/CollapsibleBlock.astro +20 -0
  58. package/templates/default/src/components/product/blocks/DescriptionBlock.astro +19 -0
  59. package/templates/default/src/components/product/blocks/DetailsBlock.astro +33 -0
  60. package/templates/default/src/components/product/blocks/GalleryBlock.astro +12 -0
  61. package/templates/default/src/components/product/blocks/OrderBlock.astro +30 -0
  62. package/templates/default/src/components/product/blocks/PriceBlock.astro +23 -0
  63. package/templates/default/src/components/product/blocks/RatingBlock.astro +16 -0
  64. package/templates/default/src/components/product/blocks/StockBlock.astro +22 -0
  65. package/templates/default/src/components/product/blocks/TextBlock.astro +11 -0
  66. package/templates/default/src/components/product/blocks/TitleBlock.astro +20 -0
  67. package/templates/default/src/components/reviews/ReviewCard.astro +46 -0
  68. package/templates/default/src/components/reviews/ReviewForm.astro +113 -0
  69. package/templates/default/src/components/reviews/VoiceNote.astro +60 -0
  70. package/templates/default/src/components/sections/CollectionCards.astro +65 -0
  71. package/templates/default/src/components/sections/Countdown.astro +57 -0
  72. package/templates/default/src/components/sections/Faq.astro +44 -0
  73. package/templates/default/src/components/sections/FeaturedProduct.astro +71 -0
  74. package/templates/default/src/components/sections/Hero.astro +99 -0
  75. package/templates/default/src/components/sections/ImageBanner.astro +46 -0
  76. package/templates/default/src/components/sections/ProductGrid.astro +47 -0
  77. package/templates/default/src/components/sections/RichText.astro +35 -0
  78. package/templates/default/src/components/sections/Steps.astro +46 -0
  79. package/templates/default/src/components/sections/Testimonials.astro +57 -0
  80. package/templates/default/src/components/shell/Footer.astro +80 -0
  81. package/templates/default/src/components/shell/Header.astro +89 -0
  82. package/templates/default/src/components/shell/LanguageMenu.astro +33 -0
  83. package/templates/default/src/components/shell/MobileMenu.astro +65 -0
  84. package/templates/default/src/components/shell/SearchDialog.astro +19 -0
  85. package/templates/default/src/components/shell/TopBar.astro +54 -0
  86. package/templates/default/src/components/shell/WhatsAppWidget.astro +111 -0
  87. package/templates/default/src/components/store/ContactMain.astro +79 -0
  88. package/templates/default/src/components/store/SearchMain.astro +56 -0
  89. package/templates/default/src/components/store/TrackOrderMain.astro +161 -0
  90. package/templates/default/src/components/surface/Area.astro +20 -0
  91. package/templates/default/src/components/surface/PreviewBridge.astro +24 -0
  92. package/templates/default/src/components/surface/Sections.astro +35 -0
  93. package/templates/default/src/components/ui/Breadcrumbs.astro +36 -0
  94. package/templates/default/src/components/ui/Button.astro +45 -0
  95. package/templates/default/src/components/ui/EditorPlaceholder.astro +24 -0
  96. package/templates/default/src/components/ui/Icon.astro +93 -0
  97. package/templates/default/src/components/ui/Logo.astro +36 -0
  98. package/templates/default/src/components/ui/Photo.astro +46 -0
  99. package/templates/default/src/components/ui/Price.astro +24 -0
  100. package/templates/default/src/components/ui/ProductCard.astro +41 -0
  101. package/templates/default/src/components/ui/Rating.astro +22 -0
  102. package/templates/default/src/components/ui/Section.astro +34 -0
  103. package/templates/default/src/components/ui/SectionHeading.astro +19 -0
  104. package/templates/default/src/env.d.ts +23 -0
  105. package/templates/default/src/layouts/StoreLayout.astro +145 -0
  106. package/templates/default/src/lib/browser-copy.ts +37 -0
  107. package/templates/default/src/lib/context.ts +89 -0
  108. package/templates/default/src/lib/coupon-notice.ts +47 -0
  109. package/templates/default/src/lib/i18n.ts +32 -0
  110. package/templates/default/src/lib/images.ts +38 -0
  111. package/templates/default/src/lib/listing-query.ts +41 -0
  112. package/templates/default/src/lib/money.ts +16 -0
  113. package/templates/default/src/lib/motion.ts +16 -0
  114. package/templates/default/src/lib/nav.ts +26 -0
  115. package/templates/default/src/lib/offer-tiles.ts +105 -0
  116. package/templates/default/src/lib/order-outcome.ts +66 -0
  117. package/templates/default/src/lib/otp-message.ts +21 -0
  118. package/templates/default/src/lib/products.ts +38 -0
  119. package/templates/default/src/lib/review-refusals.ts +31 -0
  120. package/templates/default/src/lib/store.ts +31 -0
  121. package/templates/default/src/lib/whatsapp.ts +29 -0
  122. package/templates/default/src/middleware.ts +23 -0
  123. package/templates/default/src/pages/404.astro +22 -0
  124. package/templates/default/src/pages/api/abandoned/convert.ts +4 -0
  125. package/templates/default/src/pages/api/abandoned/upsert.ts +4 -0
  126. package/templates/default/src/pages/api/cart/validate.ts +4 -0
  127. package/templates/default/src/pages/api/communes/[wilayaId].ts +4 -0
  128. package/templates/default/src/pages/api/otp/send.ts +4 -0
  129. package/templates/default/src/pages/api/otp/verify.ts +4 -0
  130. package/templates/default/src/pages/api/reviews/[productId].ts +3 -0
  131. package/templates/default/src/pages/api/reviews/eligibility.ts +3 -0
  132. package/templates/default/src/pages/api/reviews/submit.ts +3 -0
  133. package/templates/default/src/pages/api/reviews/upload.ts +3 -0
  134. package/templates/default/src/pages/category/[slug].astro +20 -0
  135. package/templates/default/src/pages/checkout.astro +25 -0
  136. package/templates/default/src/pages/collections/[handle].astro +20 -0
  137. package/templates/default/src/pages/contact.astro +17 -0
  138. package/templates/default/src/pages/index.astro +9 -0
  139. package/templates/default/src/pages/lp/[slug].astro +47 -0
  140. package/templates/default/src/pages/pages/[slug].astro +16 -0
  141. package/templates/default/src/pages/products/[handle].astro +37 -0
  142. package/templates/default/src/pages/products/index.astro +15 -0
  143. package/templates/default/src/pages/robots.txt.ts +9 -0
  144. package/templates/default/src/pages/search.astro +19 -0
  145. package/templates/default/src/pages/sitemap.xml.ts +12 -0
  146. package/templates/default/src/pages/thank-you.astro +33 -0
  147. package/templates/default/src/pages/track-order.astro +17 -0
  148. package/templates/default/src/pages/wocart-preview.astro +43 -0
  149. package/templates/default/src/pages/wocart-revalidate.ts +10 -0
  150. package/templates/default/src/pages/wocart-styles.css.ts +5 -0
  151. package/templates/default/src/pages/wocart-theme.json.ts +5 -0
  152. package/templates/default/src/scripts/cart.ts +371 -0
  153. package/templates/default/src/scripts/checkout/coupon.ts +96 -0
  154. package/templates/default/src/scripts/checkout/delivery.ts +86 -0
  155. package/templates/default/src/scripts/checkout/form.ts +54 -0
  156. package/templates/default/src/scripts/checkout/otp.ts +106 -0
  157. package/templates/default/src/scripts/checkout/picker.ts +169 -0
  158. package/templates/default/src/scripts/checkout/quote.ts +169 -0
  159. package/templates/default/src/scripts/checkout/submit.ts +113 -0
  160. package/templates/default/src/scripts/checkout/tracking.ts +74 -0
  161. package/templates/default/src/scripts/countdown.ts +29 -0
  162. package/templates/default/src/scripts/events.ts +4 -0
  163. package/templates/default/src/scripts/hero.ts +49 -0
  164. package/templates/default/src/scripts/listing.ts +13 -0
  165. package/templates/default/src/scripts/order-form.ts +100 -0
  166. package/templates/default/src/scripts/product.ts +306 -0
  167. package/templates/default/src/scripts/public-config.ts +79 -0
  168. package/templates/default/src/scripts/reviews.ts +358 -0
  169. package/templates/default/src/scripts/site.ts +131 -0
  170. package/templates/default/src/scripts/thank-you.ts +11 -0
  171. package/templates/default/src/scripts/voice-note.ts +94 -0
  172. package/templates/default/src/styles/base.css +1030 -0
  173. package/templates/default/src/styles/checkout.css +1111 -0
  174. package/templates/default/src/styles/global.css +12 -0
  175. package/templates/default/src/styles/product.css +871 -0
  176. package/templates/default/src/styles/reviews.css +533 -0
  177. package/templates/default/src/styles/sections.css +931 -0
  178. package/templates/default/src/styles/shell.css +970 -0
  179. package/templates/default/src/styles/tokens.css +583 -0
  180. package/templates/default/src/theme/api-routes.ts +10 -0
  181. package/templates/default/src/theme/content/catalog.ts +117 -0
  182. package/templates/default/src/theme/content/checkout.ts +168 -0
  183. package/templates/default/src/theme/content/editor.ts +21 -0
  184. package/templates/default/src/theme/content/index.ts +45 -0
  185. package/templates/default/src/theme/content/reviews.ts +76 -0
  186. package/templates/default/src/theme/content/shell.ts +59 -0
  187. package/templates/default/src/theme/content/types.ts +12 -0
  188. package/templates/default/src/theme/documents/catalog.json +11 -0
  189. package/templates/default/src/theme/documents/category.json +11 -0
  190. package/templates/default/src/theme/documents/checkout.json +11 -0
  191. package/templates/default/src/theme/documents/collection.json +11 -0
  192. package/templates/default/src/theme/documents/contact.json +11 -0
  193. package/templates/default/src/theme/documents/footer.area.json +11 -0
  194. package/templates/default/src/theme/documents/header.area.json +16 -0
  195. package/templates/default/src/theme/documents/home.json +313 -0
  196. package/templates/default/src/theme/documents/landing.json +8 -0
  197. package/templates/default/src/theme/documents/page.json +11 -0
  198. package/templates/default/src/theme/documents/product.json +125 -0
  199. package/templates/default/src/theme/documents/search.json +11 -0
  200. package/templates/default/src/theme/documents/thank-you.json +11 -0
  201. package/templates/default/src/theme/documents/track-order.json +11 -0
  202. package/templates/default/src/theme/fields.ts +61 -0
  203. package/templates/default/src/theme/key.ts +11 -0
  204. package/templates/default/src/theme/labels.ts +231 -0
  205. package/templates/default/src/theme/locales.ts +11 -0
  206. package/templates/default/src/theme/palette.ts +14 -0
  207. package/templates/default/src/theme/sections/collection-cards.ts +65 -0
  208. package/templates/default/src/theme/sections/faq.ts +74 -0
  209. package/templates/default/src/theme/sections/featured-product.ts +42 -0
  210. package/templates/default/src/theme/sections/hero.ts +47 -0
  211. package/templates/default/src/theme/sections/image-banner.ts +25 -0
  212. package/templates/default/src/theme/sections/index.ts +40 -0
  213. package/templates/default/src/theme/sections/landing.ts +150 -0
  214. package/templates/default/src/theme/sections/listing.ts +84 -0
  215. package/templates/default/src/theme/sections/product-grid.ts +42 -0
  216. package/templates/default/src/theme/sections/product.ts +297 -0
  217. package/templates/default/src/theme/sections/rich-text.ts +39 -0
  218. package/templates/default/src/theme/sections/shared.ts +54 -0
  219. package/templates/default/src/theme/sections/shell.ts +85 -0
  220. package/templates/default/src/theme/sections/store-pages.ts +101 -0
  221. package/templates/default/src/theme/sections/testimonials.ts +61 -0
  222. package/templates/default/src/theme/sections/thank-you.ts +35 -0
  223. package/templates/default/src/theme/settings.ts +124 -0
  224. package/templates/default/src/theme/theme.ts +65 -0
  225. package/templates/default/tests/fixtures/canvas-tote.json +62 -0
  226. package/templates/default/tests/fixtures/linen-shirt.json +128 -0
  227. package/templates/default/tests/unit/checkout.test.ts +241 -0
  228. package/templates/default/tests/unit/contract.test.ts +169 -0
  229. package/templates/default/tests/unit/contrast.test.ts +68 -0
  230. package/templates/default/tests/unit/copy.test.ts +101 -0
  231. package/templates/default/tests/unit/design-values.test.ts +95 -0
  232. package/templates/default/tests/unit/editability.test.ts +180 -0
  233. package/templates/default/tests/unit/fixtures.ts +91 -0
  234. package/templates/default/tests/unit/footer.test.ts +54 -0
  235. package/templates/default/tests/unit/guards.test.ts +340 -0
  236. package/templates/default/tests/unit/images.test.ts +26 -0
  237. package/templates/default/tests/unit/landing.test.ts +151 -0
  238. package/templates/default/tests/unit/languages.test.ts +42 -0
  239. package/templates/default/tests/unit/middleware.test.ts +53 -0
  240. package/templates/default/tests/unit/offer-tiles.test.ts +75 -0
  241. package/templates/default/tests/unit/render.ts +38 -0
  242. package/templates/default/tests/unit/reviews.test.ts +25 -0
  243. package/templates/default/tests/unit/rules.test.ts +59 -0
  244. package/templates/default/tests/unit/source.ts +75 -0
  245. package/templates/default/tests/unit/store-pages.test.ts +147 -0
  246. package/templates/default/tests/unit/studio.test.ts +202 -0
  247. package/templates/default/tests/unit/testimonials.test.ts +52 -0
  248. package/templates/default/tests/unit/thank-you.test.ts +52 -0
  249. package/templates/default/tests/unit/tracking.test.ts +29 -0
  250. package/templates/default/tests/unit/voice-note.test.ts +42 -0
  251. package/templates/default/tsconfig.json +13 -0
  252. package/templates/default/vitest.config.ts +15 -0
  253. package/templates/default/wrangler.jsonc +17 -0
@@ -0,0 +1,370 @@
1
+ #!/usr/bin/env python3
2
+ """Collect the public frontend of Shopify storefront pages into one folder.
3
+
4
+ For each page URL: the HTML source, the stylesheets, scripts, images, fonts and
5
+ SVGs the page and its stylesheets reference, and which homepage section uses
6
+ each of them. Every file is stored once, under assets/, and the manifest lists
7
+ the pages that use it. Standard library only (Python 3.9+).
8
+
9
+ Usage:
10
+ python3 collect_public_assets.py https://store.myshopify.com/ \\
11
+ https://store.myshopify.com/collections/all --out ./store-assets --zip
12
+
13
+ Only URLs the page itself references are downloaded, and robots.txt is obeyed:
14
+ a path it disallows for this client is skipped and reported. The output is a
15
+ reference for measuring a design. It is not theme code and not a licence to
16
+ ship the store's files; see the skill's rights rules.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import argparse
22
+ import hashlib
23
+ import html
24
+ import json
25
+ import os
26
+ import re
27
+ import shutil
28
+ import ssl
29
+ import sys
30
+ import time
31
+ import urllib.error
32
+ import urllib.parse
33
+ import urllib.request
34
+ import urllib.robotparser
35
+ from dataclasses import dataclass, field
36
+ from html.parser import HTMLParser
37
+ from pathlib import Path
38
+
39
+ USER_AGENT = "wocart-asset-collector/1.0 (design reference; the developer owns the rights to use it)"
40
+ MAX_BYTES = 30 * 1024 * 1024
41
+ TIMEOUT = 30
42
+ DELAY = 0.2
43
+ MAX_RESOURCES = 2000
44
+
45
+ def tls_context() -> ssl.SSLContext:
46
+ """Verified TLS: certifi's bundle, else the system bundle. Verification is never turned off."""
47
+ try:
48
+ import certifi
49
+
50
+ return ssl.create_default_context(cafile=certifi.where())
51
+ except ImportError:
52
+ pass
53
+ for bundle in ("/etc/ssl/cert.pem", "/etc/ssl/certs/ca-certificates.crt"):
54
+ if os.path.exists(bundle):
55
+ return ssl.create_default_context(cafile=bundle)
56
+ return ssl.create_default_context()
57
+
58
+
59
+ TLS = tls_context()
60
+
61
+ CSS_URL = re.compile(r"url\(\s*(['\"]?)([^'\")]+)\1\s*\)")
62
+ CSS_IMPORT = re.compile(r"@import\s+(?:url\()?\s*['\"]?([^'\")\s;]+)")
63
+
64
+
65
+ @dataclass
66
+ class Resource:
67
+ url: str
68
+ kind: str
69
+ file: str | None = None
70
+ bytes: int = 0
71
+ status: str = "pending"
72
+ pages: set = field(default_factory=set)
73
+ sections: set = field(default_factory=set)
74
+
75
+
76
+ class Collector:
77
+ def __init__(self, out: Path):
78
+ self.out = out
79
+ self.resources: dict[str, Resource] = {}
80
+ self.failures: list[dict] = []
81
+ self.robots: dict[str, urllib.robotparser.RobotFileParser | None] = {}
82
+ self.pending_css: list[str] = []
83
+ self.last = 0.0
84
+
85
+ def allowed(self, url: str) -> bool:
86
+ parts = urllib.parse.urlsplit(url)
87
+ origin = f"{parts.scheme}://{parts.netloc}"
88
+ if origin not in self.robots:
89
+ parser = urllib.robotparser.RobotFileParser()
90
+ try:
91
+ request = urllib.request.Request(origin + "/robots.txt", headers={"User-Agent": USER_AGENT})
92
+ with urllib.request.urlopen(request, timeout=TIMEOUT, context=TLS) as response:
93
+ parser.parse(response.read().decode("utf-8", "replace").splitlines())
94
+ self.robots[origin] = parser
95
+ except (urllib.error.URLError, TimeoutError, OSError):
96
+ self.robots[origin] = None
97
+ parser = self.robots[origin]
98
+ return parser is None or parser.can_fetch(USER_AGENT, url)
99
+
100
+ def get(self, url: str) -> tuple[bytes, str]:
101
+ wait = DELAY - (time.time() - self.last)
102
+ if wait > 0:
103
+ time.sleep(wait)
104
+ self.last = time.time()
105
+ request = urllib.request.Request(url, headers={"User-Agent": USER_AGENT, "Accept": "text/html,application/xhtml+xml,text/css,application/javascript,image/*,font/*;q=0.9,*/*;q=0.5"})
106
+ with urllib.request.urlopen(request, timeout=TIMEOUT, context=TLS) as response:
107
+ content_type = response.headers.get("Content-Type", "")
108
+ data = response.read(MAX_BYTES + 1)
109
+ if len(data) > MAX_BYTES:
110
+ raise ValueError("larger than the collector's limit")
111
+ return data, content_type
112
+
113
+ def resource(self, url: str, kind: str, page_slug: str, section: str | None) -> Resource | None:
114
+ if not url or url.startswith(("data:", "blob:", "javascript:", "#")):
115
+ return None
116
+ if len(self.resources) >= MAX_RESOURCES and url not in self.resources:
117
+ return None
118
+ item = self.resources.get(url)
119
+ if item is None:
120
+ item = Resource(url=url, kind=kind)
121
+ self.resources[url] = item
122
+ item.pages.add(page_slug)
123
+ if section:
124
+ item.sections.add(section)
125
+ return item
126
+
127
+ def fetch_resource(self, item: Resource) -> None:
128
+ if item.file is not None or item.status not in ("pending",):
129
+ return
130
+ if not self.allowed(item.url):
131
+ item.status = "disallowed by robots.txt"
132
+ self.failures.append({"url": item.url, "reason": item.status})
133
+ return
134
+ digest = hashlib.sha1(item.url.encode()).hexdigest()[:10]
135
+ name = Path(urllib.parse.urlsplit(item.url).path).name or "file"
136
+ name = re.sub(r"[^A-Za-z0-9._-]", "_", name)[:80]
137
+ subfolder = {"css": "css", "js": "js", "font": "fonts", "svg": "svg"}.get(item.kind, "images")
138
+ target = self.out / "assets" / subfolder / f"{digest}-{name}"
139
+ try:
140
+ data, _ = self.get(item.url)
141
+ except (urllib.error.URLError, TimeoutError, OSError, ValueError) as error:
142
+ item.status = f"failed: {error}"
143
+ self.failures.append({"url": item.url, "reason": str(error)})
144
+ return
145
+ target.parent.mkdir(parents=True, exist_ok=True)
146
+ target.write_bytes(data)
147
+ item.file = str(target.relative_to(self.out))
148
+ item.bytes = len(data)
149
+ item.status = "downloaded"
150
+ if item.kind == "css":
151
+ text = data.decode("utf-8", "replace")
152
+ for match in CSS_URL.finditer(text):
153
+ self.queue_css_reference(match.group(2), item.url, item)
154
+ for match in CSS_IMPORT.finditer(text):
155
+ self.queue_css_reference(match.group(1), item.url, item)
156
+
157
+ def queue_css_reference(self, raw: str, base: str, owner: Resource) -> None:
158
+ absolute = urllib.parse.urljoin(base, html.unescape(raw.strip()))
159
+ lower = absolute.lower().split("?")[0]
160
+ kind = "font" if lower.endswith((".woff2", ".woff", ".ttf", ".otf")) else "svg" if lower.endswith(".svg") else "css" if lower.endswith(".css") else "image"
161
+ for page in owner.pages:
162
+ child = self.resource(absolute, kind, page, None)
163
+ if child is not None:
164
+ child.sections |= owner.sections
165
+ self.pending_css.append(absolute)
166
+
167
+
168
+
169
+ class PageParser(HTMLParser):
170
+ def __init__(self, base: str):
171
+ super().__init__(convert_charrefs=True)
172
+ self.base = base
173
+ self.found: list[tuple[str, str, str | None]] = []
174
+ self.sections: list[dict] = []
175
+ self.section_stack: list[dict] = []
176
+ self.heading_for: dict | None = None
177
+ self.title = ""
178
+ self.in_title = False
179
+ self.inline_css = ""
180
+ self.in_style = False
181
+
182
+ def absolute(self, value: str) -> str:
183
+ return urllib.parse.urljoin(self.base, html.unescape(value.strip()))
184
+
185
+ def current_section(self) -> str | None:
186
+ return self.section_stack[-1]["id"] if self.section_stack else None
187
+
188
+ def handle_starttag(self, tag, attrs):
189
+ a = dict(attrs)
190
+ section = self.current_section()
191
+ if tag == "title":
192
+ self.in_title = True
193
+ if tag == "style":
194
+ self.in_style = True
195
+ if tag == "div" and (a.get("id") or "").startswith("shopify-section-"):
196
+ entry = {"id": a["id"], "order": len(self.sections) + 1, "heading": "", "resources": []}
197
+ self.sections.append(entry)
198
+ self.section_stack.append({"id": a["id"], "depth": 1})
199
+ elif self.section_stack and tag == "div":
200
+ self.section_stack[-1]["depth"] += 1
201
+ if tag in ("h1", "h2", "h3") and section and not any(s["id"] == section and s["heading"] for s in self.sections):
202
+ self.heading_for = next(s for s in self.sections if s["id"] == section)
203
+ if tag == "link" and a.get("href"):
204
+ rel = (a.get("rel") or "").lower()
205
+ if "stylesheet" in rel:
206
+ self.found.append((self.absolute(a["href"]), "css", section))
207
+ elif any(r in rel for r in ("icon", "preload", "modulepreload")):
208
+ kind = "font" if (a.get("as") == "font") else "svg" if a["href"].lower().endswith(".svg") else "image" if "icon" in rel else "js"
209
+ self.found.append((self.absolute(a["href"]), kind, section))
210
+ if tag == "script" and a.get("src"):
211
+ self.found.append((self.absolute(a["src"]), "js", section))
212
+ if tag in ("img", "source", "video", "audio"):
213
+ for key in ("src", "poster", "data-src", "data-srcset"):
214
+ if a.get(key):
215
+ self.found.append((self.absolute(a[key]), "image", section))
216
+ for key in ("srcset", "data-srcset"):
217
+ if a.get(key):
218
+ for candidate in a[key].split(","):
219
+ url = candidate.strip().split(" ")[0]
220
+ if url:
221
+ self.found.append((self.absolute(url), "image", section))
222
+ if tag == "meta" and a.get("property") in ("og:image", "og:image:secure_url", "og:video"):
223
+ self.found.append((self.absolute(a.get("content", "")), "image", section))
224
+ if tag == "video" and a.get("poster"):
225
+ self.found.append((self.absolute(a["poster"]), "image", section))
226
+ if a.get("style") and "url(" in a["style"]:
227
+ for match in CSS_URL.finditer(a["style"]):
228
+ self.found.append((self.absolute(match.group(2)), "image", section))
229
+ if tag == "a" and a.get("href") and a["href"].lower().endswith(".pdf"):
230
+ self.found.append((self.absolute(a["href"]), "image", section))
231
+
232
+ def handle_endtag(self, tag):
233
+ if tag == "title":
234
+ self.in_title = False
235
+ if tag == "style":
236
+ self.in_style = False
237
+ if tag == "div" and self.section_stack:
238
+ self.section_stack[-1]["depth"] -= 1
239
+ if self.section_stack[-1]["depth"] <= 0:
240
+ self.section_stack.pop()
241
+ if tag in ("h1", "h2", "h3"):
242
+ self.heading_for = None
243
+
244
+ def handle_data(self, data):
245
+ if self.in_title:
246
+ self.title += data
247
+ if self.in_style:
248
+ self.inline_css += data
249
+ if self.heading_for is not None and data.strip() and not self.heading_for["heading"]:
250
+ self.heading_for["heading"] = " ".join(data.split())
251
+
252
+
253
+ def slug_for(url: str) -> str:
254
+ path = urllib.parse.urlsplit(url).path.strip("/") or "home"
255
+ return re.sub(r"[^A-Za-z0-9]+", "-", path).strip("-").lower() or "home"
256
+
257
+
258
+ def main() -> int:
259
+ parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
260
+ parser.add_argument("urls", nargs="+", help="public storefront page URLs; the first should be the homepage")
261
+ parser.add_argument("--out", default="./store-assets", help="output folder")
262
+ parser.add_argument("--zip", action="store_true", help="also write OUT.zip")
263
+ args = parser.parse_args()
264
+
265
+ out = Path(args.out).resolve()
266
+ if out.exists():
267
+ shutil.rmtree(out)
268
+ (out / "pages").mkdir(parents=True)
269
+ collector = Collector(out)
270
+ pages = []
271
+ section_ids: dict[str, list[str]] = {}
272
+
273
+ for url in args.urls:
274
+ slug = slug_for(url)
275
+ page_dir = out / "pages" / slug
276
+ page_dir.mkdir(parents=True, exist_ok=True)
277
+ entry = {"url": url, "slug": slug, "final_url": url, "title": "", "status": "pending", "sections": [], "navigation": []}
278
+ if not collector.allowed(url):
279
+ entry["status"] = "disallowed by robots.txt"
280
+ collector.failures.append({"url": url, "reason": entry["status"]})
281
+ pages.append(entry)
282
+ continue
283
+ try:
284
+ data, content_type = collector.get(url)
285
+ except (urllib.error.URLError, TimeoutError, OSError, ValueError) as error:
286
+ entry["status"] = f"failed: {error}"
287
+ collector.failures.append({"url": url, "reason": str(error)})
288
+ pages.append(entry)
289
+ continue
290
+ text = data.decode("utf-8", "replace")
291
+ entry["status"] = "downloaded"
292
+ entry["final_url"] = url
293
+ (page_dir / "source.html").write_text(text, encoding="utf-8")
294
+
295
+ page = PageParser(url)
296
+ page.feed(text)
297
+ entry["title"] = " ".join(page.title.split())
298
+ entry["sections"] = [{"order": s["order"], "id": s["id"], "heading": s["heading"], "resources": []} for s in page.sections]
299
+ section_ids[slug] = [s["id"] for s in page.sections]
300
+ entry["navigation"] = sorted({urllib.parse.urljoin(url, h) for h in re.findall(r'href="([^"#]+)"', text) if h.startswith("/")})[:200]
301
+
302
+ for ref, kind, section in page.found:
303
+ resource = collector.resource(ref, kind, slug, section)
304
+ if resource is not None:
305
+ collector.fetch_resource(resource)
306
+ for match in CSS_URL.finditer(page.inline_css):
307
+ resource = collector.resource(urllib.parse.urljoin(url, match.group(2)), "image", slug, None)
308
+ if resource is not None:
309
+ collector.fetch_resource(resource)
310
+
311
+ pages.append(entry)
312
+
313
+ while collector.pending_css:
314
+ css_url = collector.pending_css.pop()
315
+ resource = collector.resources.get(css_url)
316
+ if resource is None:
317
+ resource = collector.resource(css_url, "css", "shared", None)
318
+ if resource is not None:
319
+ collector.fetch_resource(resource)
320
+
321
+ for resource in collector.resources.values():
322
+ if resource.status == "pending":
323
+ collector.fetch_resource(resource)
324
+
325
+ for entry in pages:
326
+ for section in entry["sections"]:
327
+ section["resources"] = sorted(r.url for r in collector.resources.values() if entry["slug"] in r.pages and section["id"] in r.sections)
328
+
329
+ resources = [
330
+ {
331
+ "url": r.url,
332
+ "kind": r.kind,
333
+ "file": r.file,
334
+ "bytes": r.bytes,
335
+ "status": r.status,
336
+ "pages": sorted(r.pages),
337
+ "sections": sorted(r.sections),
338
+ }
339
+ for r in sorted(collector.resources.values(), key=lambda x: (x.kind, x.url))
340
+ ]
341
+ counts: dict[str, int] = {}
342
+ for r in resources:
343
+ if r["status"] == "downloaded":
344
+ counts[r["kind"]] = counts.get(r["kind"], 0) + 1
345
+
346
+ manifest = {
347
+ "collected_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
348
+ "client": USER_AGENT,
349
+ "pages": pages,
350
+ "homepage_sections": pages[0]["sections"] if pages else [],
351
+ "resources": resources,
352
+ "downloaded_by_kind": counts,
353
+ "failures": collector.failures,
354
+ }
355
+ (out / "manifest.json").write_text(json.dumps(manifest, indent=2, ensure_ascii=False), encoding="utf-8")
356
+ (out / "README.txt").write_text(
357
+ "Public storefront reference collected for measuring a design.\n"
358
+ "manifest.json lists every page, section and resource; pages/<slug>/source.html is each page's HTML.\n"
359
+ "Do not ship these files in a theme. Measure from them, and write the theme's own code and tokens.\n",
360
+ encoding="utf-8",
361
+ )
362
+ print(json.dumps({"out": str(out), "pages": len(pages), "resources": counts, "failures": len(collector.failures)}, indent=2))
363
+ if args.zip:
364
+ archive = shutil.make_archive(str(out), "zip", root_dir=out.parent, base_dir=out.name)
365
+ print(f"archive: {archive}")
366
+ return 0
367
+
368
+
369
+ if __name__ == "__main__":
370
+ sys.exit(main())
@@ -0,0 +1,146 @@
1
+ ---
2
+ name: wocart-docs
3
+ description: Where to find the truth about the Wocart SDKs and this theme's contract before you use or state any of it — the starter file that already does it, the installed declaration that defines it, the documentation page that explains it, and the rules the starter's tests enforce. Use before calling an SDK function, adding a field or a section, answering a question about how Wocart behaves, or when a check fails.
4
+ ---
5
+
6
+ # Looking things up in a Wocart theme
7
+
8
+ `wocart-theme-from-design` sends you here before every SDK name, field or
9
+ platform claim, and whenever a check fails. So does `shopify-theme-asset-collector`
10
+ when its output is used to build a theme.
11
+ Return to the step that sent you once you have the answer.
12
+
13
+ ## The rule
14
+
15
+ Look an answer up before any SDK call, field or claim about the platform.
16
+ Three sources agree, and you read them together:
17
+
18
+ 1. **The installed declarations**, `node_modules/@wocart/*/dist/*.d.ts`: every
19
+ export, field and type of the version this theme runs, with its
20
+ documentation comment. They are the final authority.
21
+ 2. **This starter**: its code under `src/`, its tests under `tests/`,
22
+ `AGENTS.md` and `README.md`. It shows how each SDK piece is used, and each
23
+ rule below is enforced by a test.
24
+ 3. **The documentation** at `https://docs.wocart.store`, written from the SDKs
25
+ and around this starter. It explains why things work as they do and how
26
+ the pieces fit. Every page is also Markdown at its URL plus `.md`.
27
+
28
+ If the three ever disagree, the installed declarations win: say so to the
29
+ developer. If the answer is in none of them, stop and ask. Never guess an
30
+ export, a field, a store setting or a platform behaviour.
31
+
32
+ ## Finding an export
33
+
34
+ The packages publish these entry points only (each package's
35
+ `package.json` `exports`):
36
+
37
+ - `@abcart/storefront`, `@abcart/storefront/server` (server only),
38
+ `@abcart/storefront/astro` (server only), `@abcart/storefront/review-media`
39
+ - `@abcart/theme`, `@abcart/theme/astro`, `@abcart/theme/lifecycle`,
40
+ `@abcart/theme/messages`, `@abcart/theme/preview`,
41
+ `@abcart/theme/image-service`, and the four components
42
+ `@abcart/theme/astro/InstanceView.astro`, `@abcart/theme/astro/Blocks.astro`,
43
+ `@abcart/theme/astro/Block.astro` and `@abcart/theme/astro/ThemeStyles.astro`
44
+
45
+ To find a name and read its documentation comment:
46
+
47
+ ```sh
48
+ grep -rn "createQuoter" node_modules/@abcart/storefront/dist/*.d.ts
49
+ grep -rn "type FieldKind" node_modules/@abcart/theme/dist/*.d.ts
50
+ ```
51
+
52
+ Then find how the starter already uses it (`grep -rn "createQuoter" src`),
53
+ and do it the same way.
54
+
55
+ ## SDK names the starter uses
56
+
57
+ Each name below is exported by that entry point in the installed version.
58
+ Check any other name the same way before you use it.
59
+
60
+ | Entry point | Names |
61
+ | --- | --- |
62
+ | `@abcart/storefront` | `storefrontPath`, `localizeHref`, `localeRouting`, `servedLanguage`, `unavailableStoreConfig`, `whatsAppContact`, `canonicalUrl`, `pictureOf`, `mediaImageUrl`, `mediaImageSrcset`, `createQuoter`, `createBrowserAbandonedCheckoutTracker`, `Review`, `PickedImage` |
63
+ | `@abcart/storefront/server` | `createStoreClient`, `readPreviewRequest`, `readRevalidateRequest`, `StoreClient` |
64
+ | `@abcart/storefront/astro` | `resolveStoreRequest`, `resolvePreviewStore`, `runFormAction`, `executePlaceOrder`, `placeOrderInput`, `lookupOrder`, `orderLookupInput`, `notFound` |
65
+ | `@abcart/storefront/review-media` | `createReviewSession` |
66
+ | `@abcart/theme` | `defineTheme`, `defineComponent`, `defineCapabilities`, `resolveSurfaceDocument`, `resolveThemeSettings`, `schemeClass`, `styleClasses`, `richTextToHtml`, `formatMessage`, `pluralFormIssues`, `validateThemeDefinition`, `validatePageData`, `validateThemeManifest`, `themeManifest`, `diffThemeManifests`, `THEME_PREVIEW_PATH`, `SCHEME_MARKER_CLASS`, `FieldKind`, `ResolvedImage`, `StyleValue` |
67
+ | `@abcart/theme/astro` | `createReadCache`, `isPreview`, `themeManifestEndpoint`, `themeStylesEndpoint`, `previewTarget` |
68
+ | `@abcart/theme/lifecycle` | `bindEach`, `onEachPage` |
69
+
70
+ ## Where to look
71
+
72
+ | Question | The starter file that answers it | The declaration to check | Documentation |
73
+ | --- | --- | --- | --- |
74
+ | How is this project laid out, and how does a request become a page? | `AGENTS.md`, `README.md` | | https://docs.wocart.store/sdk/theme/project |
75
+ | How does the theme reach the store? | `src/lib/store.ts` (the only `createStoreClient()`), `src/lib/context.ts`, `src/middleware.ts` | `@abcart/storefront/server`, `@abcart/storefront/astro` | https://docs.wocart.store/sdk/storefront/how-it-works |
76
+ | What does a page know about its store? | `src/lib/context.ts` (`Astro.locals.store`) | `StoreConfig` in `@abcart/storefront` | https://docs.wocart.store/sdk/storefront/config |
77
+ | How is an order placed? | `src/components/checkout/OrderForm.astro`, `src/scripts/order-form.ts`, `src/scripts/checkout/`, `src/actions/index.ts` | `executePlaceOrder`, `placeOrderInput` | https://docs.wocart.store/sdk/storefront/checkout |
78
+ | How are prices, offers and delivery fees shown? | `src/scripts/checkout/quote.ts`, `src/scripts/cart.ts`, `src/pages/api/cart/validate.ts` | `createQuoter` | https://docs.wocart.store/sdk/storefront/basket |
79
+ | Wilayas, communes, delivery types? | `src/scripts/checkout/delivery.ts`, `src/pages/api/communes/[wilayaId].ts` | `@abcart/storefront` | https://docs.wocart.store/sdk/storefront/delivery |
80
+ | Images? | `src/lib/images.ts`, `src/components/ui/Photo.astro` | `pictureOf`, `mediaImageUrl`, `mediaImageSrcset` | https://docs.wocart.store/sdk/theme/images |
81
+ | WhatsApp? | `src/lib/whatsapp.ts` (`storeWhatsApp()`) | `whatsAppContact` | https://docs.wocart.store/sdk/storefront/presentation |
82
+ | Reviews? | `src/components/product/ProductReviews.astro`, `src/scripts/reviews.ts`, `src/pages/api/reviews/` | `createReviewSession` | https://docs.wocart.store/sdk/storefront/reviews |
83
+ | Studio's preview and the revalidation after a publish? | `src/pages/wocart-preview.astro`, `src/pages/wocart-revalidate.ts`, `src/lib/store.ts`, `routeRules` in `astro.config.mjs`, `tests/unit/studio.test.ts` | `readPreviewRequest`, `readRevalidateRequest` | https://docs.wocart.store/sdk/theme/preview |
84
+ | The manifest Studio reads? | `src/theme/theme.ts`, `src/pages/wocart-theme.json.ts` | `themeManifestEndpoint`, `validateThemeManifest` | https://docs.wocart.store/sdk/theme/manifest |
85
+ | Sections, fields, page documents? | `src/theme/sections/`, `src/theme/fields.ts`, `src/theme/documents/`, `src/components/surface/Sections.astro` | `defineComponent`, `FieldKind`, `resolveSurfaceDocument` | https://docs.wocart.store/sdk/theme/fields, https://docs.wocart.store/sdk/theme/composition, https://docs.wocart.store/sdk/theme/pages |
86
+ | Restyling, words, a new field or section? | `src/styles/tokens.css`, `src/theme/settings.ts`, `src/theme/content/`, `src/theme/sections/index.ts` | | https://docs.wocart.store/sdk/theme/customize |
87
+ | Words, translations and plurals? | `src/theme/content/`, `src/lib/i18n.ts`, `src/lib/browser-copy.ts` | `formatMessage`, `pluralFormIssues` | https://docs.wocart.store/sdk/theme/settings-copy |
88
+ | Settings, colours and the look? | `src/theme/palette.ts`, `src/theme/settings.ts`, `src/styles/tokens.css`, `src/components/ui/Section.astro` | `resolveThemeSettings`, `schemeClass`, `styleClasses` | https://docs.wocart.store/sdk/theme/style |
89
+ | Languages and links? | `src/lib/context.ts`, `src/lib/nav.ts` | `storefrontPath`, `localizeHref`, `localeRouting`, `isSingleLanguagePage` | https://docs.wocart.store/sdk/storefront/content |
90
+ | Building and deploying? | `package.json` scripts, `astro.config.mjs`, `wrangler.jsonc`, `README.md` | | https://docs.wocart.store/sdk/theme/starter, https://docs.wocart.store/sdk/theme/production |
91
+ | Testing? | `tests/unit/` | `validateThemeDefinition`, `validatePageData` | https://docs.wocart.store/sdk/theme/testing |
92
+ | Something renders wrong? | The server log: `src/components/surface/Sections.astro` warns about each document issue and section error, and `src/lib/store.ts` warns about each failed store read, both prefixed with the theme key | `RendererIssue` in `@abcart/theme/astro` | https://docs.wocart.store/sdk/theme/troubleshooting |
93
+
94
+ ## The rules the starter relies on
95
+
96
+ Each rule is enforced by a test you can run on its own.
97
+
98
+ | # | Rule | Check |
99
+ | --- | --- | --- |
100
+ | 1 | Import `@wocart/*` through the published entry points only, and find every name in the installed declarations. | `npx vitest run tests/unit/guards.test.ts -t "published entry points only"`, then `npm run check` |
101
+ | 2 | Only `src/lib/store.ts` creates an SDK client, with the theme key. Everything else reads `Astro.locals.store.client`. | `npx vitest run tests/unit/guards.test.ts -t "creates SDK clients in one place only"` |
102
+ | 3 | A store that cannot be read renders the SDK's unavailable store (`unavailableStoreConfig`), built once in `src/middleware.ts`. | `npx vitest run tests/unit/guards.test.ts -t "unavailable store"` |
103
+ | 4 | Every platform page type is a surface with one required main section (twelve surfaces), plus the header and footer areas. | `npx vitest run tests/unit/contract.test.ts -t "every page the platform defines"` |
104
+ | 5 | The product and landing pages always hold an order form, and the theme definition is valid with every content key. | `npx vitest run tests/unit/contract.test.ts -t "is a valid catalog"` and `-t "guarantees an order form"` |
105
+ | 6 | Pages render their saved document, or the theme's default, through `src/components/surface/Sections.astro` (`resolveSurfaceDocument`), and settings through `resolveThemeSettings` (`src/lib/context.ts`). | `npx vitest run tests/unit/contract.test.ts -t "every page, rendered through the SDK"` |
106
+ | 7 | Every word is a copy key in ar, fr and en. A count is a plural message with each language's forms (Arabic has six). No key goes unread. | `npx vitest run tests/unit/copy.test.ts` |
107
+ | 8 | No copy, default or preset states a fact about a store (delivery reach, periods, percentages, hours, phone calls). | `npx vitest run tests/unit/copy.test.ts -t "states no fact about a store"` |
108
+ | 9 | Every link to a platform page uses `storefrontPath` and `localizeHref`, never a hand-written path. | `npx vitest run tests/unit/guards.test.ts -t "storefrontPath"` |
109
+ | 10 | Every WhatsApp link comes from `storeWhatsApp()` in `src/lib/whatsapp.ts`. No file writes a `wa.me` link. | `npx vitest run tests/unit/guards.test.ts -t "is reached one way"` |
110
+ | 11 | Colours come from colour schemes: every section has a `scheme` field, tokens derive from `--wc-color-*` on the SDK's marker class, and every brand value lives in `src/styles/tokens.css`. | `npx vitest run tests/unit/contract.test.ts -t "colour scheme"`, then `npx vitest run tests/unit/guards.test.ts -t "keeps every brand value in tokens.css"` and `-t "scheme marker"` |
111
+ | 12 | A photo a merchant picks is an `image` field, drawn from the store's media delivery (`src/lib/images.ts`). Never type a URL into it, and never hot-link a photo. | `npx vitest run tests/unit/contract.test.ts -t "never type an image URL"`, then `npx vitest run tests/unit/images.test.ts` |
112
+ | 13 | Layout uses logical properties. A physical left or right appears only in a rule that names one direction or the WhatsApp widget's side. | `npx vitest run tests/unit/guards.test.ts -t "logical properties"` |
113
+ | 14 | Browser behaviour binds through `bindEach` and `onEachPage` (`@abcart/theme/lifecycle`), so Studio's preview can swap a section. | `npx vitest run tests/unit/guards.test.ts -t "binds every behaviour through the SDK's lifecycle"` |
114
+ | 15 | Browser code never imports Zod, a schema or a server-only module, and takes only `/lifecycle` and `/messages` from `@abcart/theme`. | `npx vitest run tests/unit/guards.test.ts -t "the theme's browser code"` |
115
+ | 16 | The browser never decides a price, a fee, a discount or an order. The order form posts to the `placeOrder` action, which calls `executePlaceOrder`, and quotes come from `createQuoter`. | `npx vitest run tests/unit/guards.test.ts -t "gives every order form its checkout key"` |
116
+ | 17 | The theme writes nothing to the store's documents, settings or text. Its only routes are the shopper's API calls the browser makes, and Studio's revalidation. | `npx vitest run tests/unit/guards.test.ts -t "mounts a route file at every API path"`, then `npx vitest run tests/unit/studio.test.ts -t "answers only POST"` |
117
+ | 18 | A missing product, collection, category, page or landing page answers with `notFound(Astro)`, never cached. | `npx vitest run tests/unit/guards.test.ts -t "through the SDK's notFound"` |
118
+ | 19 | Every cached page carries the `pages` tag, so a publish shows at once. | `npx vitest run tests/unit/studio.test.ts -t "caches every composed route"` |
119
+ | 20 | The theme builds for Cloudflare Workers and for Vercel from the same code. Never remove a host or a feature. | `npx vitest run tests/unit/guards.test.ts -t "builds for Cloudflare Workers and for Vercel"`, then `npm run build` and `npm run build:vercel` |
120
+ | 21 | No design value is a literal in a stylesheet: sizes, line heights, letter-spacing, weights, colours, radii, shadows, borders, surfaces, filters, aspect ratios, motion and opacity are tokens in `src/styles/tokens.css`. Layout geometry stays in the stylesheets. | `npx vitest run tests/unit/design-values.test.ts -t "names every design value"` |
121
+ | 22 | A script reads every timing it runs from a motion token (`motionMs` in `src/lib/motion.ts`), except the behaviour timers the guard names. | `npx vitest run tests/unit/design-values.test.ts -t "reads every timing"` |
122
+ | 23 | An inline style carries data only (an index, a merchant's value), never a design number of its own. | `npx vitest run tests/unit/design-values.test.ts -t "keeps inline styles"` |
123
+ | 24 | Every motion token a script reads is defined in `tokens.css` with a value. | `npx vitest run tests/unit/design-values.test.ts -t "gives every motion value"` |
124
+ | 25 | A token that reads a colour of the colour scheme is defined in the `:root, .wc-scheme` block, never in the plain `:root` block. | `npx vitest run tests/unit/design-values.test.ts -t "keeps colour-dependent tokens"` |
125
+ | 26 | Done means `npm run check` (0 errors, 0 warnings), `npm test`, `npm run build` and `npm run build:vercel` pass, and you quote their output. | Run all four. |
126
+ | 27 | Every colour scheme keeps its text, headings and accents at WCAG AA (4.5:1) on its background, and its button words on its button. A light band takes dark ink. | `npx vitest run tests/unit/contrast.test.ts` |
127
+ | 28 | A person's name (a reviewer, a testimonial) carries `dir="auto"`, so a Latin name's full stop stays after it. | `npx vitest run tests/unit/rules.test.ts -t "own direction"` |
128
+ | 29 | The add-to-cart confirmation shows only when no cart drawer opens with it, so it never covers the drawer. | `npx vitest run tests/unit/rules.test.ts -t "drawer"` |
129
+ | 30 | A phone-width token is named `-narrow`, never `-phone`; a row of testimonials or reviews fills its row (`repeat(auto-fit, …)`). | `npx vitest run tests/unit/rules.test.ts -t "phone-width"`, then `-t "fills a row"` |
130
+
131
+ A new rule gets a guard test in `tests/unit/`, and you prove the guard by
132
+ breaking the code once and watching it fail.
133
+
134
+ ## Stop and ask instead of going on when
135
+
136
+ - the export, field or option you need is not in the installed declarations;
137
+ - the only way forward is a deep import (`@wocart/*/dist/…`), copying SDK
138
+ code into the theme, a `@ts-ignore`, or a cast that hides an SDK type error;
139
+ - a change would rename `THEME_KEY`, a section type, a field key or a shipped
140
+ instance id, or remove a section, a field or a copy key merchants may have
141
+ edited (that needs a new major version);
142
+ - a check fails and fixing it would mean changing the SDK;
143
+ - a design or a request asks the theme to state a fact about a store;
144
+ - a design asks for a feature the platform does not have (shopper accounts,
145
+ a wishlist, card payments, a blog, a newsletter): leave it out and say so;
146
+ - you cannot run the checks. Say so, and never claim the work is done.
@@ -0,0 +1,58 @@
1
+ ---
2
+ name: wocart-theme-from-design
3
+ description: Build or restyle a Wocart theme from a design, and prove it matches. The design can be a screenshot or image, a live website URL, or a Shopify theme measured with shopify-theme-asset-collector. Use for any new theme that must look like a design, for one section or one look, or for a restyle. Covers the route from an empty folder to a home page on a real store, the design as named tokens, sections, content and claims, right-to-left and phone layouts, and measuring the match. Look SDK names up with wocart-docs.
4
+ ---
5
+
6
+ # Build a Wocart theme from a design
7
+
8
+ This skill is the route for a theme that must match a design. Each step has a reference file with the detail; read it when you reach that step.
9
+
10
+ | Step | Read | What it does |
11
+ | --- | --- | --- |
12
+ | 0 | `references/inputs-and-rights.md` | Ask for the inputs, and set the rights before any content is taken |
13
+ | 1 | `references/measure-the-design.md` | Measure the design: a screenshot, a live URL, or a Shopify theme collected by `shopify-theme-asset-collector` |
14
+ | 2 | `references/tokens-sections-content.md` | Name every design value as a token; map sections; write content and claims; fonts and motion |
15
+ | 3 | `references/layout-rtl-and-phone.md` | Right to left, the layout patterns, and the phone layer |
16
+ | 4 | `references/verify-and-report.md` | Start the project, add a store, check the page, measure the match, and report |
17
+
18
+ For any SDK name, field, platform behaviour or failing check, look it up with `wocart-docs` before you use it. Never guess an export.
19
+
20
+ Read `AGENTS.md` in the project first. Its rules are what `npm test` enforces.
21
+
22
+ ## Be a designer, not a tracer
23
+
24
+ A design is a direction. Capture its character: the rhythm of spacing, the weight of type, how photos meet text. Where the design is silent (hover, a phone layout, an empty state, right to left), design the answer it implies. Change markup and add sections freely. Your limits are the SDK contract, the starter's tests, and the store's own facts.
25
+
26
+ ## Never drift
27
+
28
+ These hold at every step. If one cannot be kept, stop and ask.
29
+
30
+ 1. **The platform is the SDK's.** Import `@wocart/*` through its published entry points. Never copy or deep-import SDK code; a missing capability is reported, not rebuilt.
31
+ 2. **No design value is a literal.** Sizes, weights, colours, radii, shadows, borders, motion and opacity are tokens in `src/styles/tokens.css`; colours are named once in `src/theme/palette.ts`. Layout geometry stays in the stylesheets.
32
+ 3. **Layout is logical** (`inset-inline-start`, `margin-inline-end`), so Arabic mirrors without extra rules.
33
+ 4. **Every word is copy, every photo is an `image` field**, and the theme states no fact about a store.
34
+ 5. **Nothing a merchant saved breaks.** Never rename `THEME_KEY`, a section type, a field key or an instance id. Only add.
35
+ 6. **A failing check is fixed at its cause.** Never weaken, skip or delete a test or a guard.
36
+ 7. **Never copy another site's code, photos, fonts or words** except on the developer's word, and only into test data (`references/inputs-and-rights.md`).
37
+ 8. **Build presentation only.** Translations, prices, media and settings come from the store. Do not invent a platform feature.
38
+ 9. **Done is shown, not claimed.** Quote the commands' output, and list what you did not check.
39
+
40
+ ## Gates
41
+
42
+ Each step ends at a gate. The gates are in `references/verify-and-report.md`. The short form: the project passes its checks before you change it; every design value is a token; the home page lists the design's sections in order; the store shows products, collections, reviews and photos; the match is within its limit at the desktop width; and the four commands pass.
43
+
44
+ ## Scripts
45
+
46
+ Both run against a running page, with Playwright. Set `CHROME` to a Chromium binary and `PLAYWRIGHT` to where Playwright loads from if the defaults do not run.
47
+
48
+ - `scripts/qa-pages.cjs`: every page the home page links to, at desktop and phone widths, in one language. It fails on overflow, broken images, leaked translation keys, console errors, and low contrast.
49
+ - `scripts/compare-design.cjs`: how closely a page matches its design, pixel by pixel, with the worst regions and the section each one falls in.
50
+
51
+ ## Hand-offs
52
+
53
+ - Any SDK name, field, platform behaviour or failing check: `wocart-docs`.
54
+ - A design taken from a Shopify theme: `shopify-theme-asset-collector` first, then step 1 of this skill.
55
+
56
+ ## Unattended builds
57
+
58
+ When the developer leaves the build to run on its own, stop only at a hard stop, commit after each gate, and finish with the report. The message that starts one is in `references/verify-and-report.md`.
@@ -0,0 +1,47 @@
1
+ # Inputs and rights
2
+
3
+ Read this before you start, and again whenever a source changes.
4
+
5
+ ## Ask once, at the start
6
+
7
+ Without an answer, take the default and say so in the report.
8
+
9
+ | Ask | Default |
10
+ | --- | --- |
11
+ | The design: a screenshot or image, a live website URL, or a Shopify theme to measure (see below) | None: there is no build without a design |
12
+ | The theme's folder name and key | The brand's name, lowercase, with hyphens |
13
+ | The store to run it on: API address and key, or a local store | A local store on its own state and port |
14
+ | Whether the photos, logos and words belong to the developer | No: measure the design and take none of its content |
15
+ | Brand colours and font files | Read from the design; open-licence fonts only |
16
+ | The pages | The home page; other pages keep the starter's sections, restyled through tokens |
17
+ | The store's primary language | French, with Arabic and English published |
18
+
19
+ An image cannot give these, so ask for them when they matter:
20
+
21
+ - **Exact colours.** Colours read from an image are estimates. Ask for hex values when precision matters.
22
+ - **Font files and their licence.** A font named from a picture is a guess. Open-licence fonts can be downloaded from their publisher and self-hosted with their licence line.
23
+ - **The logo.** It is the merchant's: uploaded in the store's settings. `src/components/ui/Logo.astro` shows it, or the store's name when there is none.
24
+
25
+ ## Rights
26
+
27
+ You may measure a site's design: its layout, colours, type, spacing and motion. You never copy its code. Its photos, logos and words are taken only on the developer's word, and only into test data.
28
+
29
+ - A reference collected from a site (a live URL, or the output of `shopify-theme-asset-collector`) is for measuring. Do not ship its CSS, JavaScript, fonts, images or text in a theme. Write the theme's own code and tokens, and name the values you measured.
30
+ - A font ships only under its own open licence, self-hosted, with its licence line in `public/fonts/OFL.txt`.
31
+ - A catalogue that the site serves as data is read only within the developer's permission.
32
+
33
+ If the developer has not said they own the photos and words, use neutral copy and placeholders, and say so in the report.
34
+
35
+ ## Shopify references
36
+
37
+ A Shopify theme is a design reference, collected with `shopify-theme-asset-collector`. Run that skill first. It writes a manifest of the homepage sections and their public resources, which you use to map sections (`measure-the-design.md`). Use its output to measure, not to copy.
38
+
39
+ ## What an image cannot give you
40
+
41
+ The developer supplies these. Ask, and do not invent them:
42
+
43
+ - exact colours (hex values);
44
+ - font files and their licences;
45
+ - the logo;
46
+ - photos and their rights;
47
+ - contact details, menus, legal pages and translations.