@eldrajs/theme-cli 0.0.0 → 0.1.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 (483) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/LICENSE +21 -0
  3. package/README.md +26 -1
  4. package/dist/cli.d.ts +1 -0
  5. package/dist/cli.js +203 -0
  6. package/dist/index.d.ts +174 -0
  7. package/dist/index.js +3 -0
  8. package/dist/validate-C6jB8_Oc.js +510 -0
  9. package/package.json +50 -2
  10. package/template/.eldra/block-types.d.ts +429 -0
  11. package/template/.eldra/manifest.json +9377 -0
  12. package/template/.eldra/previews.json +36 -0
  13. package/template/.github/workflows/eldra-deploy.yml +24 -0
  14. package/template/.gitlab-ci.yml +16 -0
  15. package/template/.storybook/eldra.ts +123 -0
  16. package/template/.storybook/i18n.ts +23 -0
  17. package/template/.storybook/main.ts +59 -0
  18. package/template/.storybook/nuxt-link-stub.ts +23 -0
  19. package/template/.storybook/preview.ts +52 -0
  20. package/template/.storybook/shims-vue.d.ts +10 -0
  21. package/template/.storybook/virtual-eldra.d.ts +27 -0
  22. package/template/README.md +288 -0
  23. package/template/app/app.vue +126 -0
  24. package/template/app/assets/main.css +404 -0
  25. package/template/app/components/EldraIcon.vue +66 -0
  26. package/template/app/components/EldraRouterLink.vue +62 -0
  27. package/template/app/components/ui/UiImage.stories.ts +30 -0
  28. package/template/app/components/ui/UiImage.vue +224 -0
  29. package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
  30. package/template/app/composables/iconComponent.ts +84 -0
  31. package/template/app/composables/iconFetcher.ts +14 -0
  32. package/template/app/composables/useBlockData.ts +30 -0
  33. package/template/app/composables/useEditing.ts +31 -0
  34. package/template/app/composables/useEldraIcon.ts +46 -0
  35. package/template/app/composables/useRevalidating.ts +69 -0
  36. package/template/app/composables/useRichTextScrollRegions.ts +80 -0
  37. package/template/app/composables/useStorefront.ts +18 -0
  38. package/template/app/composables/useStorefrontFeedback.ts +49 -0
  39. package/template/app/composables/useUiId.ts +18 -0
  40. package/template/app/composables/useWishlist.ts +42 -0
  41. package/template/app/i18n.d.ts +28 -0
  42. package/template/app/icons.ts +185 -0
  43. package/template/app/pages/[...slug].vue +134 -0
  44. package/template/app/plugins/eldra-i18n.ts +98 -0
  45. package/template/app/plugins/eldra-storefront.ts +288 -0
  46. package/template/app/plugins/eldra-ui-messages.ts +112 -0
  47. package/template/app/storefront/cart.ts +245 -0
  48. package/template/app/storefront/categories.ts +283 -0
  49. package/template/app/storefront/collectionSelector.ts +60 -0
  50. package/template/app/storefront/commerce.ts +58 -0
  51. package/template/app/storefront/demo.ts +1313 -0
  52. package/template/app/storefront/facets.ts +476 -0
  53. package/template/app/storefront/feedback.ts +122 -0
  54. package/template/app/storefront/gateway.ts +2256 -0
  55. package/template/app/storefront/history.ts +233 -0
  56. package/template/app/storefront/money.ts +247 -0
  57. package/template/app/storefront/options.ts +71 -0
  58. package/template/app/storefront/prerender.ts +77 -0
  59. package/template/app/storefront/refresh.ts +222 -0
  60. package/template/app/storefront/toProductCard.ts +154 -0
  61. package/template/app/storefront/types.ts +815 -0
  62. package/template/app/storefront/volatile.ts +211 -0
  63. package/template/app/templates.ts +544 -0
  64. package/template/app/utils/classes.ts +40 -0
  65. package/template/app/utils/links.ts +70 -0
  66. package/template/app/utils/pageStructure.ts +77 -0
  67. package/template/app/utils/pageTitle.ts +37 -0
  68. package/template/app/virtual-eldra.d.ts +12 -0
  69. package/template/bitbucket-pipelines.yml +19 -0
  70. package/template/blocks/announcement-bar/Block.vue +203 -0
  71. package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
  72. package/template/blocks/announcement-bar/block.json +45 -0
  73. package/template/blocks/announcement-bar/mock.json +7 -0
  74. package/template/blocks/announcement-bar/preview.png +0 -0
  75. package/template/blocks/article/Block.vue +317 -0
  76. package/template/blocks/article/__tests__/Block.spec.ts +229 -0
  77. package/template/blocks/article/block.json +148 -0
  78. package/template/blocks/article/mock.json +512 -0
  79. package/template/blocks/article/preview.json +16 -0
  80. package/template/blocks/article/preview.png +0 -0
  81. package/template/blocks/article-list/Block.vue +343 -0
  82. package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
  83. package/template/blocks/article-list/block.json +181 -0
  84. package/template/blocks/article-list/mock.json +68 -0
  85. package/template/blocks/article-list/preview.json +84 -0
  86. package/template/blocks/article-list/preview.png +0 -0
  87. package/template/blocks/breadcrumbs/Block.vue +278 -0
  88. package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
  89. package/template/blocks/breadcrumbs/block.json +89 -0
  90. package/template/blocks/breadcrumbs/mock.json +11 -0
  91. package/template/blocks/breadcrumbs/preview.json +3 -0
  92. package/template/blocks/breadcrumbs/preview.png +0 -0
  93. package/template/blocks/cart/Block.vue +372 -0
  94. package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
  95. package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
  96. package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
  97. package/template/blocks/cart/block.json +74 -0
  98. package/template/blocks/cart/mock.json +11 -0
  99. package/template/blocks/cart/parts/CartLines.vue +257 -0
  100. package/template/blocks/cart/parts/ShippingBar.vue +105 -0
  101. package/template/blocks/cart/parts/Summary.vue +291 -0
  102. package/template/blocks/cart/preview.png +0 -0
  103. package/template/blocks/collection-grid/Block.vue +1832 -0
  104. package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
  105. package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
  106. package/template/blocks/collection-grid/block.json +187 -0
  107. package/template/blocks/collection-grid/mock.json +23 -0
  108. package/template/blocks/collection-grid/parts/groups.ts +861 -0
  109. package/template/blocks/collection-grid/preview.json +7 -0
  110. package/template/blocks/collection-grid/preview.png +0 -0
  111. package/template/blocks/collection-header/Block.vue +533 -0
  112. package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
  113. package/template/blocks/collection-header/block.json +140 -0
  114. package/template/blocks/collection-header/mock.json +28 -0
  115. package/template/blocks/collection-header/preview.json +14 -0
  116. package/template/blocks/collection-header/preview.png +0 -0
  117. package/template/blocks/contact/Block.vue +621 -0
  118. package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
  119. package/template/blocks/contact/block.json +174 -0
  120. package/template/blocks/contact/mock.json +28 -0
  121. package/template/blocks/contact/preview.json +9 -0
  122. package/template/blocks/contact/preview.png +0 -0
  123. package/template/blocks/cta/Block.vue +383 -0
  124. package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
  125. package/template/blocks/cta/block.json +86 -0
  126. package/template/blocks/cta/mock.json +10 -0
  127. package/template/blocks/cta/preview.json +9 -0
  128. package/template/blocks/cta/preview.png +0 -0
  129. package/template/blocks/faq/Block.vue +254 -0
  130. package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
  131. package/template/blocks/faq/block.json +113 -0
  132. package/template/blocks/faq/mock.json +115 -0
  133. package/template/blocks/faq/preview.png +0 -0
  134. package/template/blocks/feature-grid/Block.vue +241 -0
  135. package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
  136. package/template/blocks/feature-grid/block.json +106 -0
  137. package/template/blocks/feature-grid/mock.json +29 -0
  138. package/template/blocks/feature-grid/preview.json +45 -0
  139. package/template/blocks/feature-grid/preview.png +0 -0
  140. package/template/blocks/footer/Block.vue +652 -0
  141. package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
  142. package/template/blocks/footer/block.json +240 -0
  143. package/template/blocks/footer/mock.json +161 -0
  144. package/template/blocks/footer/preview.png +0 -0
  145. package/template/blocks/gallery/Block.vue +416 -0
  146. package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
  147. package/template/blocks/gallery/block.json +87 -0
  148. package/template/blocks/gallery/mock.json +16 -0
  149. package/template/blocks/gallery/preview.json +64 -0
  150. package/template/blocks/gallery/preview.png +0 -0
  151. package/template/blocks/hero/Block.vue +378 -0
  152. package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
  153. package/template/blocks/hero/block.json +146 -0
  154. package/template/blocks/hero/mock.json +11 -0
  155. package/template/blocks/hero/preview.json +55 -0
  156. package/template/blocks/hero/preview.png +0 -0
  157. package/template/blocks/image/Block.vue +232 -0
  158. package/template/blocks/image/__tests__/Block.spec.ts +224 -0
  159. package/template/blocks/image/block.json +67 -0
  160. package/template/blocks/image/mock.json +7 -0
  161. package/template/blocks/image/preview.json +9 -0
  162. package/template/blocks/image/preview.png +0 -0
  163. package/template/blocks/logo-cloud/Block.vue +206 -0
  164. package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
  165. package/template/blocks/logo-cloud/block.json +79 -0
  166. package/template/blocks/logo-cloud/mock.json +15 -0
  167. package/template/blocks/logo-cloud/preview.json +92 -0
  168. package/template/blocks/logo-cloud/preview.png +0 -0
  169. package/template/blocks/navigation/Block.vue +1348 -0
  170. package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
  171. package/template/blocks/navigation/block.json +167 -0
  172. package/template/blocks/navigation/mock.json +191 -0
  173. package/template/blocks/navigation/preview.png +0 -0
  174. package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
  175. package/template/blocks/newsletter/Block.vue +399 -0
  176. package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
  177. package/template/blocks/newsletter/block.json +105 -0
  178. package/template/blocks/newsletter/mock.json +31 -0
  179. package/template/blocks/newsletter/preview.png +0 -0
  180. package/template/blocks/order-status/Block.vue +754 -0
  181. package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
  182. package/template/blocks/order-status/block.json +138 -0
  183. package/template/blocks/order-status/mock.json +19 -0
  184. package/template/blocks/order-status/preview.png +0 -0
  185. package/template/blocks/pricing-table/Block.vue +297 -0
  186. package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
  187. package/template/blocks/pricing-table/block.json +155 -0
  188. package/template/blocks/pricing-table/mock.json +47 -0
  189. package/template/blocks/pricing-table/preview.png +0 -0
  190. package/template/blocks/product-carousel/Block.vue +459 -0
  191. package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
  192. package/template/blocks/product-carousel/block.json +71 -0
  193. package/template/blocks/product-carousel/mock.json +9 -0
  194. package/template/blocks/product-carousel/preview.json +7 -0
  195. package/template/blocks/product-carousel/preview.png +0 -0
  196. package/template/blocks/product-detail/Block.vue +886 -0
  197. package/template/blocks/product-detail/__tests__/Block.spec.ts +1495 -0
  198. package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
  199. package/template/blocks/product-detail/block.json +155 -0
  200. package/template/blocks/product-detail/mock.json +113 -0
  201. package/template/blocks/product-detail/parts/Gallery.vue +181 -0
  202. package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
  203. package/template/blocks/product-detail/preview.png +0 -0
  204. package/template/blocks/product-detail/stock.ts +150 -0
  205. package/template/blocks/quote/Block.vue +206 -0
  206. package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
  207. package/template/blocks/quote/block.json +76 -0
  208. package/template/blocks/quote/mock.json +9 -0
  209. package/template/blocks/quote/preview.json +16 -0
  210. package/template/blocks/quote/preview.png +0 -0
  211. package/template/blocks/rich-text/Block.vue +143 -0
  212. package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
  213. package/template/blocks/rich-text/block.json +57 -0
  214. package/template/blocks/rich-text/mock.json +87 -0
  215. package/template/blocks/rich-text/preview.png +0 -0
  216. package/template/blocks/search/Block.vue +589 -0
  217. package/template/blocks/search/PopularChips.vue +40 -0
  218. package/template/blocks/search/TypeSection.vue +148 -0
  219. package/template/blocks/search/__tests__/Block.spec.ts +718 -0
  220. package/template/blocks/search/__tests__/results.spec.ts +166 -0
  221. package/template/blocks/search/block.json +102 -0
  222. package/template/blocks/search/mock.json +18 -0
  223. package/template/blocks/search/preview.png +0 -0
  224. package/template/blocks/search/results.ts +85 -0
  225. package/template/blocks/split-content/Block.vue +195 -0
  226. package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
  227. package/template/blocks/split-content/block.json +70 -0
  228. package/template/blocks/split-content/mock.json +45 -0
  229. package/template/blocks/split-content/preview.json +58 -0
  230. package/template/blocks/split-content/preview.png +0 -0
  231. package/template/blocks/stats/Block.vue +159 -0
  232. package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
  233. package/template/blocks/stats/block.json +73 -0
  234. package/template/blocks/stats/mock.json +12 -0
  235. package/template/blocks/stats/preview.png +0 -0
  236. package/template/blocks/tabs/Block.vue +278 -0
  237. package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
  238. package/template/blocks/tabs/block.json +97 -0
  239. package/template/blocks/tabs/mock.json +129 -0
  240. package/template/blocks/tabs/preview.json +153 -0
  241. package/template/blocks/tabs/preview.png +0 -0
  242. package/template/blocks/team/Block.vue +288 -0
  243. package/template/blocks/team/__tests__/Block.spec.ts +221 -0
  244. package/template/blocks/team/block.json +125 -0
  245. package/template/blocks/team/mock.json +39 -0
  246. package/template/blocks/team/preview.json +62 -0
  247. package/template/blocks/team/preview.png +0 -0
  248. package/template/blocks/testimonials/Block.vue +408 -0
  249. package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
  250. package/template/blocks/testimonials/block.json +121 -0
  251. package/template/blocks/testimonials/mock.json +46 -0
  252. package/template/blocks/testimonials/preview.json +68 -0
  253. package/template/blocks/testimonials/preview.png +0 -0
  254. package/template/blocks/timeline/Block.vue +274 -0
  255. package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
  256. package/template/blocks/timeline/block.json +98 -0
  257. package/template/blocks/timeline/mock.json +27 -0
  258. package/template/blocks/timeline/preview.png +0 -0
  259. package/template/blocks/trust-strip/Block.vue +330 -0
  260. package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
  261. package/template/blocks/trust-strip/block.json +117 -0
  262. package/template/blocks/trust-strip/mock.json +37 -0
  263. package/template/blocks/trust-strip/preview.png +0 -0
  264. package/template/blocks/video-embed/Block.vue +354 -0
  265. package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
  266. package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
  267. package/template/blocks/video-embed/block.json +94 -0
  268. package/template/blocks/video-embed/embed.ts +84 -0
  269. package/template/blocks/video-embed/mock.json +13 -0
  270. package/template/blocks/video-embed/preview.json +9 -0
  271. package/template/blocks/video-embed/preview.png +0 -0
  272. package/template/blocks/wishlist/Block.vue +367 -0
  273. package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
  274. package/template/blocks/wishlist/block.json +42 -0
  275. package/template/blocks/wishlist/mock.json +9 -0
  276. package/template/blocks/wishlist/preview.png +0 -0
  277. package/template/i18n/en-US.json +602 -0
  278. package/template/i18n/is-IS.json +602 -0
  279. package/template/nuxt.config.ts +148 -0
  280. package/template/package.json +55 -0
  281. package/template/pages/article.page.json +731 -0
  282. package/template/pages/cart.page.json +85 -0
  283. package/template/pages/category.page.json +133 -0
  284. package/template/pages/collection.page.json +194 -0
  285. package/template/pages/home.page.json +353 -0
  286. package/template/pages/product.page.json +323 -0
  287. package/template/pages/products.page.json +144 -0
  288. package/template/pages/search.page.json +83 -0
  289. package/template/pages/wishlist.page.json +88 -0
  290. package/template/public/demo/article-cover.svg +1 -0
  291. package/template/public/demo/article-figure.svg +1 -0
  292. package/template/public/demo/avatar-1.svg +3 -0
  293. package/template/public/demo/avatar-2.svg +3 -0
  294. package/template/public/demo/avatar-3.svg +3 -0
  295. package/template/public/demo/avatar-4.svg +3 -0
  296. package/template/public/demo/avatar-5.svg +3 -0
  297. package/template/public/demo/avatar-6.svg +3 -0
  298. package/template/public/demo/avatar-7.svg +3 -0
  299. package/template/public/demo/avatar-8.svg +3 -0
  300. package/template/public/demo/collection-1.svg +1 -0
  301. package/template/public/demo/collection-2.svg +1 -0
  302. package/template/public/demo/cta-split.svg +1 -0
  303. package/template/public/demo/feature-1.svg +1 -0
  304. package/template/public/demo/feature-2.svg +1 -0
  305. package/template/public/demo/feature-3.svg +1 -0
  306. package/template/public/demo/feature-4.svg +1 -0
  307. package/template/public/demo/gallery-1.svg +1 -0
  308. package/template/public/demo/gallery-2.svg +1 -0
  309. package/template/public/demo/gallery-3.svg +1 -0
  310. package/template/public/demo/gallery-4.svg +1 -0
  311. package/template/public/demo/gallery-5.svg +1 -0
  312. package/template/public/demo/gallery-6.svg +1 -0
  313. package/template/public/demo/gallery-7.svg +1 -0
  314. package/template/public/demo/gallery-8.svg +1 -0
  315. package/template/public/demo/hero-slide-1.svg +1 -0
  316. package/template/public/demo/hero-slide-2.svg +1 -0
  317. package/template/public/demo/hero-slide-3.svg +1 -0
  318. package/template/public/demo/hero-slide-4.svg +1 -0
  319. package/template/public/demo/hero-wide.svg +1 -0
  320. package/template/public/demo/hero.svg +1 -0
  321. package/template/public/demo/logo-1.svg +4 -0
  322. package/template/public/demo/logo-2.svg +4 -0
  323. package/template/public/demo/logo-3.svg +4 -0
  324. package/template/public/demo/logo-4.svg +4 -0
  325. package/template/public/demo/logo-5.svg +4 -0
  326. package/template/public/demo/logo-6.svg +4 -0
  327. package/template/public/demo/logo-7.svg +4 -0
  328. package/template/public/demo/logo-8.svg +4 -0
  329. package/template/public/demo/logo.svg +3 -0
  330. package/template/public/demo/map.svg +1 -0
  331. package/template/public/demo/poster.svg +1 -0
  332. package/template/public/demo/product-1.svg +4 -0
  333. package/template/public/demo/product-10.svg +4 -0
  334. package/template/public/demo/product-11.svg +4 -0
  335. package/template/public/demo/product-12.svg +4 -0
  336. package/template/public/demo/product-2.svg +4 -0
  337. package/template/public/demo/product-3.svg +4 -0
  338. package/template/public/demo/product-4.svg +4 -0
  339. package/template/public/demo/product-5.svg +4 -0
  340. package/template/public/demo/product-6.svg +4 -0
  341. package/template/public/demo/product-7.svg +4 -0
  342. package/template/public/demo/product-8.svg +4 -0
  343. package/template/public/demo/product-9.svg +4 -0
  344. package/template/public/demo/product-square-1.svg +4 -0
  345. package/template/public/demo/product-square-2.svg +4 -0
  346. package/template/public/demo/product-square-3.svg +4 -0
  347. package/template/public/demo/product-square-4.svg +4 -0
  348. package/template/public/demo/product-square-5.svg +4 -0
  349. package/template/public/demo/product-square-6.svg +4 -0
  350. package/template/public/demo/quote-portrait.svg +4 -0
  351. package/template/public/demo/split-1.svg +1 -0
  352. package/template/public/demo/split-2.svg +1 -0
  353. package/template/public/demo/split-3.svg +1 -0
  354. package/template/public/demo/split-4.svg +1 -0
  355. package/template/public/demo/team-1.svg +4 -0
  356. package/template/public/demo/team-2.svg +4 -0
  357. package/template/public/demo/team-3.svg +4 -0
  358. package/template/public/demo/team-4.svg +4 -0
  359. package/template/scripts/demo-images.mjs +393 -0
  360. package/template/scripts/generate-stories.mjs +156 -0
  361. package/template/scripts/previewHash.mjs +125 -0
  362. package/template/scripts/previews.mjs +149 -0
  363. package/template/stories/generated/announcement-bar.stories.ts +44 -0
  364. package/template/stories/generated/article-list.stories.ts +87 -0
  365. package/template/stories/generated/article.stories.ts +27 -0
  366. package/template/stories/generated/breadcrumbs.stories.ts +39 -0
  367. package/template/stories/generated/cart.stories.ts +38 -0
  368. package/template/stories/generated/collection-grid.stories.ts +117 -0
  369. package/template/stories/generated/collection-header.stories.ts +51 -0
  370. package/template/stories/generated/contact.stories.ts +45 -0
  371. package/template/stories/generated/cta.stories.ts +51 -0
  372. package/template/stories/generated/faq.stories.ts +56 -0
  373. package/template/stories/generated/feature-grid.stories.ts +69 -0
  374. package/template/stories/generated/footer.stories.ts +50 -0
  375. package/template/stories/generated/gallery.stories.ts +81 -0
  376. package/template/stories/generated/hero.stories.ts +75 -0
  377. package/template/stories/generated/image.stories.ts +99 -0
  378. package/template/stories/generated/logo-cloud.stories.ts +57 -0
  379. package/template/stories/generated/navigation.stories.ts +62 -0
  380. package/template/stories/generated/newsletter.stories.ts +68 -0
  381. package/template/stories/generated/order-status.stories.ts +32 -0
  382. package/template/stories/generated/pricing-table.stories.ts +44 -0
  383. package/template/stories/generated/product-carousel.stories.ts +75 -0
  384. package/template/stories/generated/product-detail.stories.ts +62 -0
  385. package/template/stories/generated/quote.stories.ts +69 -0
  386. package/template/stories/generated/rich-text.stories.ts +50 -0
  387. package/template/stories/generated/search.stories.ts +56 -0
  388. package/template/stories/generated/split-content.stories.ts +39 -0
  389. package/template/stories/generated/stats.stories.ts +68 -0
  390. package/template/stories/generated/tabs.stories.ts +45 -0
  391. package/template/stories/generated/team.stories.ts +45 -0
  392. package/template/stories/generated/testimonials.stories.ts +69 -0
  393. package/template/stories/generated/timeline.stories.ts +80 -0
  394. package/template/stories/generated/trust-strip.stories.ts +62 -0
  395. package/template/stories/generated/video-embed.stories.ts +63 -0
  396. package/template/stories/generated/wishlist.stories.ts +26 -0
  397. package/template/stories/pages/article.stories.ts +51 -0
  398. package/template/stories/pages/cart.stories.ts +56 -0
  399. package/template/stories/pages/category.stories.ts +56 -0
  400. package/template/stories/pages/collection.stories.ts +51 -0
  401. package/template/stories/pages/home.stories.ts +51 -0
  402. package/template/stories/pages/product.stories.ts +47 -0
  403. package/template/stories/pages/products.stories.ts +58 -0
  404. package/template/stories/pages/search.stories.ts +54 -0
  405. package/template/stories/pages/wishlist.stories.ts +53 -0
  406. package/template/stories/support/pageBlocks.ts +115 -0
  407. package/template/test/blocksEmptyData.spec.ts +52 -0
  408. package/template/test/carouselKeyboard.spec.ts +272 -0
  409. package/template/test/carouselRing.browser.spec.ts +193 -0
  410. package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
  411. package/template/test/cartDrawer.spec.ts +295 -0
  412. package/template/test/cartToast.spec.ts +86 -0
  413. package/template/test/countPill.browser.spec.ts +196 -0
  414. package/template/test/demoImages.spec.ts +140 -0
  415. package/template/test/deps.spec.ts +102 -0
  416. package/template/test/eldraIcon.spec.ts +58 -0
  417. package/template/test/framing.spec.ts +76 -0
  418. package/template/test/i18n.spec.ts +200 -0
  419. package/template/test/iconComponent.spec.ts +91 -0
  420. package/template/test/inlineEditable.spec.ts +334 -0
  421. package/template/test/localePrefix.spec.ts +342 -0
  422. package/template/test/mainCss.spec.ts +107 -0
  423. package/template/test/mockGatewayContract.spec.ts +122 -0
  424. package/template/test/mocks/blocks.ts +20 -0
  425. package/template/test/mocks/breakpoints.ts +7 -0
  426. package/template/test/mocks/manifest.ts +11 -0
  427. package/template/test/moneyFormatting.spec.ts +89 -0
  428. package/template/test/pageTitle.spec.ts +49 -0
  429. package/template/test/pages/article.spec.ts +231 -0
  430. package/template/test/pages/category.spec.ts +185 -0
  431. package/template/test/pages/collection.spec.ts +396 -0
  432. package/template/test/pages/home.spec.ts +295 -0
  433. package/template/test/pages/hydration.spec.ts +557 -0
  434. package/template/test/pages/product.spec.ts +396 -0
  435. package/template/test/pages/seededPages.spec.ts +190 -0
  436. package/template/test/pages/ssr.spec.ts +393 -0
  437. package/template/test/prerenderCommerce.spec.ts +134 -0
  438. package/template/test/prerenderFailure.spec.ts +130 -0
  439. package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
  440. package/template/test/previewsFresh.spec.ts +56 -0
  441. package/template/test/richText.spec.ts +161 -0
  442. package/template/test/richTextTypography.spec.ts +182 -0
  443. package/template/test/setup.ts +21 -0
  444. package/template/test/slugPage.spec.ts +244 -0
  445. package/template/test/slugPageTemplate.spec.ts +194 -0
  446. package/template/test/starter.spec.ts +1416 -0
  447. package/template/test/storefront/cart.spec.ts +404 -0
  448. package/template/test/storefront/categories.spec.ts +235 -0
  449. package/template/test/storefront/collectionSelector.spec.ts +74 -0
  450. package/template/test/storefront/demo.spec.ts +555 -0
  451. package/template/test/storefront/facets.spec.ts +425 -0
  452. package/template/test/storefront/feedback.spec.ts +97 -0
  453. package/template/test/storefront/gateway.spec.ts +2673 -0
  454. package/template/test/storefront/gatewayCart.spec.ts +289 -0
  455. package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
  456. package/template/test/storefront/history.spec.ts +341 -0
  457. package/template/test/storefront/money.spec.ts +171 -0
  458. package/template/test/storefront/toProductCard.spec.ts +138 -0
  459. package/template/test/storefront/volatile.spec.ts +284 -0
  460. package/template/test/support/axe.ts +14 -0
  461. package/template/test/support/dialog.ts +51 -0
  462. package/template/test/support/hydrate.ts +118 -0
  463. package/template/test/support/i18nText.ts +11 -0
  464. package/template/test/support/mockGateway.ts +1017 -0
  465. package/template/test/support/mountBlock.ts +194 -0
  466. package/template/test/support/mountPage.spec.ts +72 -0
  467. package/template/test/support/mountPage.ts +254 -0
  468. package/template/test/support/mountProbe.client.ts +69 -0
  469. package/template/test/support/renderSsr.ts +97 -0
  470. package/template/test/support/staticServer.ts +96 -0
  471. package/template/test/themeIcons.spec.ts +140 -0
  472. package/template/test/toastAnnouncement.spec.ts +133 -0
  473. package/template/test/tokens.spec.ts +102 -0
  474. package/template/test/uiMessagesPlugin.spec.ts +104 -0
  475. package/template/test/useBlockData.spec.ts +46 -0
  476. package/template/test/useEditing.spec.ts +54 -0
  477. package/template/test/useEldraIcon.spec.ts +126 -0
  478. package/template/test/useUiId.spec.ts +40 -0
  479. package/template/tokens.json +149 -0
  480. package/template/tsconfig.json +3 -0
  481. package/template/tsconfig.storybook.json +17 -0
  482. package/template/vitest-axe.d.ts +13 -0
  483. package/template/vitest.config.ts +44 -0
@@ -0,0 +1,957 @@
1
+ // @vitest-environment jsdom
2
+ import { readFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { compile } from '@tailwindcss/node';
5
+ import { flushPromises, mount, type VueWrapper } from '@vue/test-utils';
6
+ import { ref, type Ref } from 'vue';
7
+ import { afterEach, describe, expect, it, vi } from 'vitest';
8
+ import { ELDRA_KEY } from '@eldrajs/theme-vue';
9
+ import { ProductCard, Skeleton } from '@eldrajs/ui';
10
+ import { axe } from '../../../test/support/axe';
11
+ import Block from '../Block.vue';
12
+ import mock from '../mock.json';
13
+ import { mountOptions } from '../../../test/support/mountBlock';
14
+ import { STOREFRONT_KEY } from '../../../app/storefront/types';
15
+ import type {
16
+ StorefrontCollectionSelector,
17
+ StorefrontProductListItem,
18
+ StorefrontResult,
19
+ StorefrontSource,
20
+ VolatileKey,
21
+ } from '../../../app/storefront/types';
22
+ import { createDemoStorefront, demoCollectionId, PRODUCTS } from '../../../app/storefront/demo';
23
+ import EldraRouterLink from '../../../app/components/EldraRouterLink.vue';
24
+ import enUS from '../../../i18n/en-US.json';
25
+
26
+ /** The genuinely minimal fixture: only the fields the block requires. */
27
+ const bare = { heading: mock.heading, variant: 'related' };
28
+
29
+ function resolvedResult<T>(
30
+ value: T | null,
31
+ overrides: Partial<
32
+ Pick<StorefrontResult<T>, 'pending' | 'loading' | 'error' | 'revalidating'>
33
+ > = {}
34
+ ): StorefrontResult<T> {
35
+ return {
36
+ data: ref(value) as Ref<T | null>,
37
+ pending: ref(false),
38
+ loading: ref(false),
39
+ error: ref(null),
40
+ revalidating: ref(new Set()) as Ref<ReadonlySet<VolatileKey>>,
41
+ refresh: async () => {},
42
+ ...overrides,
43
+ };
44
+ }
45
+
46
+ /** A `related` catalogue that never resolves — for the loading-state test, which needs a
47
+ * storefront whose `related` stays pending with nothing to show. */
48
+ function pendingResult<T>(): StorefrontResult<T> {
49
+ return resolvedResult<T>(null, { pending: ref(true), loading: ref(true) });
50
+ }
51
+
52
+ const trackedWrappers: VueWrapper[] = [];
53
+ afterEach(() => {
54
+ for (const wrapper of trackedWrappers.splice(0)) wrapper.unmount();
55
+ });
56
+
57
+ function mountBlock(
58
+ data: Record<string, unknown>,
59
+ options: { editing?: boolean; storefront?: StorefrontSource; attach?: boolean } = {}
60
+ ) {
61
+ const opts = mountOptions({ entry: { id: 'e1', data } });
62
+ if (options.editing) {
63
+ const context = opts.global.provide[ELDRA_KEY] as {
64
+ preview: { active: boolean; mode: string };
65
+ };
66
+ context.preview.active = true;
67
+ context.preview.mode = 'edit';
68
+ }
69
+ if (options.storefront) {
70
+ opts.global.provide[STOREFRONT_KEY] = options.storefront;
71
+ }
72
+ const wrapper = mount(Block, options.attach ? { ...opts, attachTo: document.body } : opts);
73
+ trackedWrappers.push(wrapper);
74
+ return wrapper;
75
+ }
76
+
77
+ /** Overrides just `catalog.related` on a real demo storefront — every other method (history,
78
+ * cart, other catalogue calls) stays the real demo behaviour. */
79
+ function withRelated(
80
+ items: Array<StorefrontProductListItem | undefined>,
81
+ options: { productHandle?: string } = {}
82
+ ): StorefrontSource {
83
+ const base = createDemoStorefront({ productHandle: options.productHandle });
84
+ const list = items.filter((item): item is StorefrontProductListItem => item !== undefined);
85
+ return {
86
+ ...base,
87
+ catalog: { ...base.catalog, related: () => resolvedResult(list) },
88
+ };
89
+ }
90
+
91
+ describe('product-carousel block', () => {
92
+ describe('accessibility', () => {
93
+ it('renders the full mock.json content with no axe violations', async () => {
94
+ const viewAllHref = '/collections/knitwear';
95
+ const wrapper = mountBlock({ ...mock, viewAllHref });
96
+ await flushPromises();
97
+ expect(wrapper.text()).toContain(mock.heading);
98
+ // The heading is the "view all" link: its visible text is the heading, the label and its
99
+ // context follow visually hidden, and the anchor points at `viewAllHref`.
100
+ const headingLink = wrapper.get('h2 a');
101
+ expect(headingLink.attributes('href')).toBe(viewAllHref);
102
+ expect(headingLink.text()).toBe(mock.heading);
103
+ expect(headingLink.attributes('aria-label')).toBe(`${mock.heading} — View all products`);
104
+ expect(wrapper.get('h2').text()).toBe(mock.heading);
105
+ expect(wrapper.findAll('a').filter((a) => a.text().includes('View all'))).toHaveLength(0);
106
+ expect(await axe(wrapper.element)).toHaveNoViolations();
107
+ });
108
+
109
+ it('renders the heading as plain text (no link) when viewAllHref is empty — the seeded state', async () => {
110
+ const wrapper = mountBlock(mock);
111
+ await flushPromises();
112
+ expect(wrapper.find('h2 a').exists()).toBe(false);
113
+ expect(wrapper.get('h2').text()).toBe(mock.heading);
114
+ expect(await axe(wrapper.element)).toHaveNoViolations();
115
+ });
116
+
117
+ it('renders the bare, required-fields-only content with no axe violations', async () => {
118
+ const wrapper = mountBlock(bare);
119
+ await flushPromises();
120
+ expect(wrapper.text()).toContain(bare.heading);
121
+ expect(await axe(wrapper.element)).toHaveNoViolations();
122
+ });
123
+
124
+ it.each(['related', 'recently-viewed', 'collection'] as const)(
125
+ 'renders the %s variant with no axe violations',
126
+ async (variant) => {
127
+ const data =
128
+ variant === 'collection'
129
+ ? {
130
+ ...mock,
131
+ variant,
132
+ sourceCollection: { _type: 'collection', slug: 'winter-knitwear' },
133
+ }
134
+ : { ...mock, variant };
135
+ const wrapper = mountBlock(data);
136
+ await flushPromises();
137
+ expect(await axe(wrapper.element)).toHaveNoViolations();
138
+ }
139
+ );
140
+ });
141
+
142
+ it('names the block\u2019s own section and the carousel distinguishably, labels slides "n of N", renders no counter', async () => {
143
+ const wrapper = mountBlock(mock);
144
+ await flushPromises();
145
+
146
+ // The block's `<section>` is named by its own `<h2>`, like every other heading-bearing block —
147
+ // without it "You may also like" was the one region on the home and product pages that
148
+ // landmark navigation could not reach by name.
149
+ const section = wrapper.get('section[data-part="root"]');
150
+ const headingId = section.attributes('aria-labelledby')!;
151
+ expect(headingId).toBeTruthy();
152
+ expect(section.get(`#${headingId}`).text()).toBe(mock.heading);
153
+
154
+ // The nested carousel region therefore cannot carry the same name (axe `landmark-unique`): it
155
+ // describes what it holds instead.
156
+ const region = wrapper.get('[aria-roledescription="carousel"]');
157
+ expect(region.attributes('aria-label')).toBe(`${mock.heading} products`);
158
+ expect(region.attributes('aria-label')).not.toBe(mock.heading);
159
+
160
+ const slides = wrapper.findAll('[aria-roledescription="slide"]');
161
+ expect(slides.length).toBeGreaterThan(1);
162
+ slides.forEach((slide, index) => {
163
+ expect(slide.attributes('aria-label')).toBe(`${index + 1} of ${slides.length}`);
164
+ });
165
+
166
+ // A product row shows several cards at once, so it renders no "n / total" counter (spec
167
+ // "Carousel" → Product row: no dots and no counter).
168
+ expect(wrapper.find('[data-part="counter"]').exists()).toBe(false);
169
+ });
170
+
171
+ describe('related', () => {
172
+ it('excludes the product being viewed and sold-out items (demo catalogue)', async () => {
173
+ const current = PRODUCTS.find((p) => p.handle === 'fisherman-rib-cardigan')!;
174
+ const soldOut = PRODUCTS.find((p) => p.handle === 'linen-tea-towels-pair')!;
175
+ const keep1 = PRODUCTS.find((p) => p.handle === 'ribbed-lambswool-beanie')!;
176
+ const keep2 = PRODUCTS.find((p) => p.handle === 'speckled-latte-mug')!;
177
+ expect(soldOut.available).toBe(false);
178
+
179
+ const storefront = withRelated([current, soldOut, keep1, keep2], {
180
+ productHandle: current.handle,
181
+ });
182
+ const wrapper = mountBlock({ ...mock, variant: 'related' }, { storefront });
183
+ await flushPromises();
184
+
185
+ expect(wrapper.text()).toContain(keep1.title);
186
+ expect(wrapper.text()).toContain(keep2.title);
187
+ expect(wrapper.text()).not.toContain(current.title);
188
+ expect(wrapper.text()).not.toContain(soldOut.title);
189
+ expect(await axe(wrapper.element)).toHaveNoViolations();
190
+ });
191
+
192
+ /**
193
+ * A product's `url` is storefront-derived, not CMS-authored, and used to reach `ProductCard`
194
+ * without passing `safeHref` — the one class of URL in the theme that did. Sanitising now
195
+ * happens once, in `toProductCardEntries` (`app/storefront/toProductCard.ts`): the card's link
196
+ * is required, so an item whose URL does not survive `safeHref` is dropped outright rather than
197
+ * rendered with a link to nowhere. A same-site URL still routes (`link-as` =
198
+ * `EldraRouterLink`); an off-site one stays a plain `<a>`.
199
+ */
200
+ it('drops a product whose url is not a safe href, and only routes same-site ones', async () => {
201
+ const safe = PRODUCTS.find((p) => p.handle === 'ribbed-lambswool-beanie')!;
202
+ const external = { ...PRODUCTS.find((p) => p.handle === 'speckled-latte-mug')! };
203
+ external.url = 'https://elsewhere.example/p/mug';
204
+ const unsafe = { ...PRODUCTS.find((p) => p.handle === 'merino-crew-sweater')! };
205
+ // The exact shape the guard exists for: a scheme `safeHref` rejects.
206
+ unsafe.url = 'javascript:alert(1)';
207
+
208
+ const storefront = withRelated([safe, external, unsafe], {
209
+ productHandle: 'not-a-real-product',
210
+ });
211
+ const wrapper = mountBlock({ ...mock, variant: 'related' }, { storefront });
212
+ await flushPromises();
213
+
214
+ expect(wrapper.text()).toContain(safe.title);
215
+ expect(wrapper.text()).toContain(external.title);
216
+ expect(wrapper.text()).not.toContain(unsafe.title);
217
+
218
+ const hrefs = wrapper.findAll('a').map((a) => a.attributes('href'));
219
+ expect(hrefs).toContain(safe.url);
220
+ expect(hrefs).toContain(external.url);
221
+ expect(wrapper.html()).not.toContain('javascript:');
222
+
223
+ const cards = wrapper.findAllComponents(ProductCard);
224
+ expect(cards).toHaveLength(2);
225
+ expect(cards[0]!.props('linkAs')).toBe(EldraRouterLink);
226
+ expect(cards[1]!.props('linkAs')).toBeUndefined();
227
+ });
228
+ });
229
+
230
+ /**
231
+ * The prerender contract's "final sources at setup time" half (`app/storefront/types.ts`). Three
232
+ * results exist whatever the variant, so what keeps the two it is not showing from reading the
233
+ * storefront is that their sources are empty — and `recentlyViewed` is the one that matters:
234
+ * it is `localStorage`, so an ungated `byHandles` is prerendered over an empty history and
235
+ * re-keyed over a full one in the browser, which is a products read on every product page for a
236
+ * row nobody is looking at (`test/prerenderRefresh.browser.spec.ts` catches it end to end).
237
+ */
238
+ describe('reads only the source its variant shows', () => {
239
+ function recording(options: { productHandle?: string } = {}): {
240
+ storefront: StorefrontSource;
241
+ sources: {
242
+ related?: Ref<string | null>;
243
+ handles?: Ref<string[]>;
244
+ collection?: Ref<StorefrontCollectionSelector | null>;
245
+ };
246
+ } {
247
+ const base = createDemoStorefront(options);
248
+ const sources: {
249
+ related?: Ref<string | null>;
250
+ handles?: Ref<string[]>;
251
+ collection?: Ref<StorefrontCollectionSelector | null>;
252
+ } = {};
253
+ return {
254
+ sources,
255
+ storefront: {
256
+ ...base,
257
+ catalog: {
258
+ ...base.catalog,
259
+ related: (handle, limit) => {
260
+ sources.related = handle;
261
+ return base.catalog.related(handle, limit);
262
+ },
263
+ byHandles: (handles) => {
264
+ sources.handles = handles;
265
+ return base.catalog.byHandles(handles);
266
+ },
267
+ collectionProducts: (collection, opts) => {
268
+ sources.collection = collection;
269
+ return base.catalog.collectionProducts(collection, opts);
270
+ },
271
+ },
272
+ },
273
+ };
274
+ }
275
+
276
+ it('asks about no history and no collection while it is showing related products', async () => {
277
+ const { storefront, sources } = recording({ productHandle: 'merino-crew-sweater' });
278
+ // What a product page looks like by the time this block's setup runs: `product-detail` has
279
+ // recorded the product being viewed, so the demo history is anything but empty.
280
+ expect(storefront.history.recentlyViewed.value.length).toBeGreaterThan(0);
281
+
282
+ mountBlock({ ...mock, variant: 'related' }, { storefront });
283
+ await flushPromises();
284
+
285
+ expect(sources.related?.value).toBe('merino-crew-sweater');
286
+ expect(sources.handles?.value).toEqual([]);
287
+ expect(sources.collection?.value).toBeNull();
288
+ });
289
+
290
+ it('asks about no product and no collection while it is showing recently viewed', async () => {
291
+ const { storefront, sources } = recording({ productHandle: 'merino-crew-sweater' });
292
+ mountBlock({ ...mock, variant: 'recently-viewed' }, { storefront });
293
+ await flushPromises();
294
+
295
+ expect(sources.handles?.value).toEqual(storefront.history.recentlyViewed.value);
296
+ expect(sources.related?.value).toBeNull();
297
+ expect(sources.collection?.value).toBeNull();
298
+ });
299
+
300
+ it('asks about no product and no history while it is showing a collection', async () => {
301
+ const { storefront, sources } = recording({ productHandle: 'merino-crew-sweater' });
302
+ mountBlock(
303
+ {
304
+ ...mock,
305
+ variant: 'collection',
306
+ sourceCollection: { _type: 'collection', slug: 'winter-knitwear' },
307
+ },
308
+ { storefront }
309
+ );
310
+ await flushPromises();
311
+
312
+ expect(sources.collection?.value).toEqual({ slug: 'winter-knitwear' });
313
+ expect(sources.related?.value).toBeNull();
314
+ expect(sources.handles?.value).toEqual([]);
315
+ });
316
+ });
317
+
318
+ describe('recently-viewed', () => {
319
+ it('renders compact 1x1 cards with no swatches or rating, and "Clear history" instead of View all', async () => {
320
+ const wrapper = mountBlock({ ...mock, variant: 'recently-viewed' });
321
+ await flushPromises();
322
+
323
+ const cards = wrapper.findAllComponents(ProductCard);
324
+ expect(cards.length).toBeGreaterThan(1);
325
+ for (const card of cards) {
326
+ expect(card.props('ratio')).toBe('1x1');
327
+ expect(card.props('showSwatches')).toBe(false);
328
+ expect(card.props('showRating')).toBe(false);
329
+ expect(card.props('quickAdd')).toBe(false);
330
+ }
331
+
332
+ expect(wrapper.text()).toContain(enUS.productCarousel.clearHistory);
333
+ expect(wrapper.text()).not.toContain('View all');
334
+ });
335
+
336
+ it('clearing history removes the recently-viewed products from local state', async () => {
337
+ const storefront = createDemoStorefront();
338
+ const wrapper = mountBlock({ ...mock, variant: 'recently-viewed' }, { storefront });
339
+ await flushPromises();
340
+
341
+ await wrapper.get('button').trigger('click');
342
+ expect(storefront.history.recentlyViewed.value).toEqual([]);
343
+ });
344
+
345
+ it('renders nothing with an empty history', async () => {
346
+ const storefront = createDemoStorefront({ recentlyViewed: [] });
347
+ const wrapper = mountBlock({ ...mock, variant: 'recently-viewed' }, { storefront });
348
+ await flushPromises();
349
+ expect(wrapper.find('section').exists()).toBe(false);
350
+ });
351
+ });
352
+
353
+ it('renders nothing with fewer than two products', async () => {
354
+ const only = PRODUCTS.find((p) => p.handle === 'ribbed-lambswool-beanie')!;
355
+ const storefront = withRelated([only], { productHandle: 'not-a-real-product' });
356
+ const wrapper = mountBlock(mock, { storefront });
357
+ await flushPromises();
358
+ expect(wrapper.find('section').exists()).toBe(false);
359
+ });
360
+
361
+ it('the loading state renders four skeleton cards', async () => {
362
+ const base = createDemoStorefront();
363
+ const storefront: StorefrontSource = {
364
+ ...base,
365
+ catalog: { ...base.catalog, related: () => pendingResult() },
366
+ };
367
+ const wrapper = mountBlock(mock, { storefront });
368
+ await flushPromises();
369
+ expect(wrapper.findAllComponents(Skeleton)).toHaveLength(4);
370
+ expect(wrapper.findAllComponents(ProductCard)).toHaveLength(0);
371
+ });
372
+
373
+ describe('keyboard', () => {
374
+ /**
375
+ * The row is a composite widget: one tab stop, arrow keys inside (`@eldrajs/ui`'s `Carousel`,
376
+ * and the spec's own Keyboard rule). The track is not a stop of its own, so the arrows are
377
+ * driven the way a shopper really drives them — from the card's own link, with focus already
378
+ * on it. `test/carouselKeyboard.spec.ts` holds the whole rule across all four blocks that
379
+ * render a `Carousel`; this is the product row's share of it.
380
+ */
381
+ it('ArrowRight/ArrowLeft move between cards from inside one; arrows disable at the ends', async () => {
382
+ const wrapper = mountBlock(mock, { attach: true });
383
+ await flushPromises();
384
+ const track = wrapper.get('[data-part="track"]');
385
+ expect(track.attributes('tabindex')).toBeUndefined();
386
+
387
+ const prevButton = () => wrapper.get('[data-part="prev"]');
388
+ const nextButton = () => wrapper.get('[data-part="next"]');
389
+ const cards = () => Array.from(track.element.children) as HTMLElement[];
390
+ const cardLink = (index: number) =>
391
+ cards()[index]!.querySelector<HTMLElement>('[data-part="link"]')!;
392
+ const slideCount = cards().length;
393
+ const pressOnFocused = async (key: string) => {
394
+ (document.activeElement as HTMLElement).dispatchEvent(
395
+ new KeyboardEvent('keydown', { key, bubbles: true })
396
+ );
397
+ await flushPromises();
398
+ };
399
+
400
+ cardLink(0).focus();
401
+ expect(prevButton().attributes('disabled')).toBeDefined();
402
+ expect(nextButton().attributes('disabled')).toBeUndefined();
403
+
404
+ for (let step = 0; step < slideCount - 1; step += 1) {
405
+ await pressOnFocused('ArrowRight');
406
+ }
407
+ expect(document.activeElement).toBe(cardLink(slideCount - 1));
408
+ expect(prevButton().attributes('disabled')).toBeUndefined();
409
+ expect(nextButton().attributes('disabled')).toBeDefined();
410
+
411
+ await pressOnFocused('ArrowLeft');
412
+ expect(document.activeElement).toBe(cardLink(slideCount - 2));
413
+ expect(nextButton().attributes('disabled')).toBeUndefined();
414
+ });
415
+
416
+ it('never leaves focus on a disabled arrow', async () => {
417
+ const wrapper = mountBlock(mock, { attach: true });
418
+ await flushPromises();
419
+ const nextButton = wrapper.get('[data-part="next"]');
420
+ const slideCount = wrapper.findAll('[aria-roledescription="slide"]').length;
421
+ (nextButton.element as HTMLButtonElement).focus();
422
+ expect(document.activeElement).toBe(nextButton.element);
423
+
424
+ for (let step = 0; step < slideCount - 1; step += 1) {
425
+ await nextButton.trigger('click');
426
+ }
427
+ expect(document.activeElement).toBe(wrapper.get('[data-part="prev"]').element);
428
+ });
429
+
430
+ /**
431
+ * `Tab` stops **once** for the whole row, however many products are in it, and that stop is on
432
+ * the active card's own entry point. Tabbing used to stop once for the track and then once per
433
+ * card — seven presses to get past a six-card row, which is what the one-tab-stop rule exists
434
+ * to stop. The arrow keys are how the other cards are reached (the spec above).
435
+ */
436
+ it('takes one tab stop on the active card, and Tab from it leaves the carousel', async () => {
437
+ const wrapper = mountBlock(
438
+ { ...mock, viewAllHref: '/collections/knitwear' },
439
+ { attach: true }
440
+ );
441
+ await flushPromises();
442
+ const cardLinks = wrapper.findAll('[data-part="link"]');
443
+ expect(cardLinks.length).toBe(wrapper.findAllComponents(ProductCard).length);
444
+
445
+ const track = wrapper.get('[data-part="track"]').element as HTMLElement;
446
+ const cards = Array.from(track.children) as HTMLElement[];
447
+ const tabbable = (root: HTMLElement) =>
448
+ [...root.querySelectorAll<HTMLElement>('a, button:not([disabled]), [tabindex]')].filter(
449
+ (el) => el.getAttribute('tabindex') !== '-1'
450
+ );
451
+
452
+ // Everything `Tab` stops on in the whole block, in document order: the heading link, the
453
+ // enabled arrow (previous is disabled at the start, so it is not a stop), and then the first
454
+ // card's own controls — nothing else inside the track at all, so the next `Tab` after the
455
+ // last of them leaves the carousel for the page below, and `Shift+Tab` from the first goes
456
+ // back to the arrow rather than into another card.
457
+ const stops = tabbable(wrapper.element as HTMLElement);
458
+ const inside = tabbable(track);
459
+ expect(stops[0]!.tagName).toBe('A');
460
+ expect(stops[0]!.getAttribute('href')).toBe('/collections/knitwear');
461
+ expect(stops[1]!.getAttribute('data-part')).toBe('next');
462
+ expect(stops.slice(2)).toEqual(inside);
463
+ expect(inside[0]).toBe(cardLinks[0]!.element);
464
+ for (const el of inside) expect(cards[0]!.contains(el)).toBe(true);
465
+
466
+ // ArrowRight hands that one stop to the next card, and takes it off the first.
467
+ (cardLinks[0]!.element as HTMLElement).focus();
468
+ (document.activeElement as HTMLElement).dispatchEvent(
469
+ new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true })
470
+ );
471
+ await flushPromises();
472
+ expect(document.activeElement).toBe(cardLinks[1]!.element);
473
+ expect(tabbable(cards[0]!)).toHaveLength(0);
474
+ for (const el of tabbable(track)) expect(cards[1]!.contains(el)).toBe(true);
475
+ });
476
+ });
477
+
478
+ it('hides the arrows only when the products fit the view at every width (the smallest perView step)', async () => {
479
+ // recently-viewed with two products fits its base step of 2.4 everywhere: controls hidden.
480
+ const two = createDemoStorefront({ recentlyViewed: PRODUCTS.slice(0, 2).map((p) => p.handle) });
481
+ const compact = mountBlock({ ...mock, variant: 'recently-viewed' }, { storefront: two });
482
+ await flushPromises();
483
+ expect(compact.get('[data-part="prev"]').classes()).toContain('hidden');
484
+ expect(compact.get('[data-part="next"]').classes()).toContain('hidden');
485
+
486
+ // recently-viewed's default six products fit the desktop step (6) but not the mobile one:
487
+ // the controls stay, because a narrower container still has cards to scroll to.
488
+ const six = mountBlock({ ...mock, variant: 'recently-viewed' });
489
+ await flushPromises();
490
+ expect(six.get('[data-part="prev"]').classes()).not.toContain('hidden');
491
+
492
+ // related's default (6 products) exceeds every step: controls stay.
493
+ const related = mountBlock(mock);
494
+ await flushPromises();
495
+ expect(related.get('[data-part="prev"]').classes()).not.toContain('hidden');
496
+ expect(related.get('[data-part="next"]').classes()).not.toContain('hidden');
497
+ });
498
+
499
+ it('never autoplays and never loops (advancing 30s changes nothing)', async () => {
500
+ vi.useFakeTimers();
501
+ try {
502
+ const wrapper = mountBlock(mock);
503
+ await flushPromises();
504
+ // At rest on the first slide, Previous is disabled; 30 s later it still is.
505
+ expect(wrapper.get('[data-part="prev"]').attributes('disabled')).toBeDefined();
506
+
507
+ await vi.advanceTimersByTimeAsync(30_000);
508
+
509
+ expect(wrapper.get('[data-part="prev"]').attributes('disabled')).toBeDefined();
510
+ expect(wrapper.find('[data-part="pause"]').exists()).toBe(false);
511
+ } finally {
512
+ vi.useRealTimers();
513
+ }
514
+ });
515
+
516
+ it('shows the "add a heading" editor hint when heading is empty in edit mode, and renders nothing on the live site', async () => {
517
+ const editing = mountBlock({ ...mock, heading: '' }, { editing: true });
518
+ await flushPromises();
519
+ expect(editing.text()).toContain(enUS.productCarousel.headingHintLabel);
520
+ expect(editing.find('[aria-roledescription="carousel"]').exists()).toBe(false);
521
+
522
+ const live = mountBlock({ ...mock, heading: '' });
523
+ await flushPromises();
524
+ expect(live.find('section').exists()).toBe(false);
525
+ });
526
+
527
+ /**
528
+ * The `collection` variant's source (spec `Starter blocks`): `sourceCollection`
529
+ * is the `reference` field an author picks in Studio, and since version 3 it is
530
+ * the block's **only** source — the `sourceHandle` string field it shipped with
531
+ * is retired (Core keeps its content as `sourceHandle__v2`) and is not read
532
+ * here even when an entry still carries it. The reference's resolved `slug` is
533
+ * used when the value carries one, and its bare id otherwise (a page builder
534
+ * draft overlay, or a depth-0 read); a theme's own seed carries the slug with
535
+ * no id at all.
536
+ */
537
+ describe('the collection variant\u2019s source', () => {
538
+ const WINTER = demoCollectionId('winter-knitwear')!;
539
+ const BEST_SELLERS = demoCollectionId('best-sellers')!;
540
+
541
+ function titles(wrapper: VueWrapper): string[] {
542
+ return wrapper
543
+ .findAllComponents(ProductCard)
544
+ .map((card) => (card.props('product') as { title: string }).title);
545
+ }
546
+
547
+ async function mountCollection(data: Record<string, unknown>, editing = false) {
548
+ const wrapper = mountBlock(
549
+ { ...mock, variant: 'collection', limit: '4', ...data },
550
+ { editing }
551
+ );
552
+ await flushPromises();
553
+ return wrapper;
554
+ }
555
+
556
+ it('uses the reference\u2019s resolved slug', async () => {
557
+ const wrapper = await mountCollection({
558
+ sourceCollection: { id: BEST_SELLERS, _type: 'collection', slug: 'best-sellers' },
559
+ });
560
+ expect(titles(wrapper)).toEqual([
561
+ 'Merino crew sweater',
562
+ 'Speckled latte mug',
563
+ 'Walnut serving board',
564
+ 'Hand-thrown serving bowl',
565
+ ]);
566
+ });
567
+
568
+ it('resolves a stub reference through the storefront by id', async () => {
569
+ const wrapper = await mountCollection({
570
+ sourceCollection: { id: BEST_SELLERS, _type: 'collection' },
571
+ });
572
+ expect(titles(wrapper).slice(0, 2)).toEqual(['Merino crew sweater', 'Speckled latte mug']);
573
+ });
574
+
575
+ it('reads a seed reference, which names the collection by slug and carries no id', async () => {
576
+ // What `pages/home.page.json` ships and Core writes when it cannot resolve
577
+ // the slug against the organisation's catalog.
578
+ const wrapper = await mountCollection({
579
+ sourceCollection: { _type: 'collection', slug: 'best-sellers' },
580
+ });
581
+ expect(titles(wrapper).slice(0, 2)).toEqual(['Merino crew sweater', 'Speckled latte mug']);
582
+ });
583
+
584
+ it('ignores a retired sourceHandle an entry still carries', async () => {
585
+ // The handle field is gone: a value left behind by the old schema must not
586
+ // stand in for the collection an author never picked, or the block would
587
+ // keep showing a collection nobody can see in Studio any more.
588
+ const wrapper = await mountCollection({ sourceHandle: 'best-sellers' });
589
+ expect(wrapper.findAllComponents(ProductCard)).toHaveLength(0);
590
+ expect(wrapper.find('section').exists()).toBe(false);
591
+ });
592
+
593
+ it('lets the picked collection win over a retired handle beside it', async () => {
594
+ const wrapper = await mountCollection({
595
+ sourceCollection: { id: WINTER, _type: 'collection', slug: 'winter-knitwear' },
596
+ sourceHandle: 'best-sellers',
597
+ });
598
+ // winter-knitwear's second product, not best-sellers' — the reference won.
599
+ expect(titles(wrapper).slice(0, 2)).toEqual([
600
+ 'Merino crew sweater',
601
+ 'Fisherman rib cardigan',
602
+ ]);
603
+ });
604
+
605
+ it('renders nothing with no collection picked', async () => {
606
+ const wrapper = await mountCollection({});
607
+ expect(wrapper.find('section').exists()).toBe(false);
608
+ });
609
+
610
+ /** An id no storefront can resolve — what a freshly picked collection looks
611
+ * like in the page builder before the page is published. */
612
+ const UNRESOLVABLE = { id: '00000000-0000-4000-8000-000000000000', _type: 'collection' };
613
+
614
+ it('shows the publish hint in the editor when only an unresolvable id is known', async () => {
615
+ const wrapper = await mountCollection({ sourceCollection: UNRESOLVABLE }, true);
616
+ expect(wrapper.text()).toContain(enUS.storefront.unresolvedCollectionLabel);
617
+ expect(wrapper.findAllComponents(ProductCard)).toHaveLength(0);
618
+ expect(await axe(wrapper.element)).toHaveNoViolations();
619
+ });
620
+
621
+ it('renders nothing at all for a live visitor in that state — never an error', async () => {
622
+ const wrapper = await mountCollection({ sourceCollection: UNRESOLVABLE });
623
+ expect(wrapper.find('section').exists()).toBe(false);
624
+ expect(wrapper.text()).not.toContain(enUS.storefront.unresolvedCollectionLabel);
625
+ });
626
+
627
+ it('keeps the hint out of the way while the request is still pending', async () => {
628
+ const base = createDemoStorefront();
629
+ const wrapper = mountBlock(
630
+ {
631
+ ...mock,
632
+ variant: 'collection',
633
+ limit: '4',
634
+ sourceCollection: UNRESOLVABLE,
635
+ },
636
+ {
637
+ editing: true,
638
+ storefront: {
639
+ ...base,
640
+ catalog: { ...base.catalog, collectionProducts: () => pendingResult() },
641
+ },
642
+ }
643
+ );
644
+ await flushPromises();
645
+ expect(wrapper.text()).not.toContain(enUS.storefront.unresolvedCollectionLabel);
646
+ expect(wrapper.findAllComponents(Skeleton).length).toBeGreaterThan(0);
647
+ });
648
+ });
649
+
650
+ /**
651
+ * The "view all" link, per variant (spec `Starter blocks`, and the `showWhen`
652
+ * conditions in `block.json`):
653
+ *
654
+ * - `collection` derives the destination from the collection an author picked
655
+ * — `/collections/<slug>` — and never reads `viewAllHref`, which Studio does
656
+ * not even offer in this variant. A collection known only by id (a page
657
+ * builder draft overlay, a depth-0 read) has no slug to link to, so the
658
+ * heading stays plain text rather than pointing at `/collections/undefined`.
659
+ * - `related` keeps the authored `viewAllHref`: its row is recommendations,
660
+ * which no single collection page corresponds to.
661
+ * - `recently-viewed` never links at all — the shopper's own history has no
662
+ * page.
663
+ */
664
+ describe('the view-all link', () => {
665
+ const BEST_SELLERS_ID = demoCollectionId('best-sellers')!;
666
+
667
+ async function mountVariant(data: Record<string, unknown>) {
668
+ const wrapper = mountBlock({ ...mock, limit: '4', ...data });
669
+ await flushPromises();
670
+ return wrapper;
671
+ }
672
+
673
+ it('derives the collection variant\u2019s link from the picked collection, ignoring viewAllHref', async () => {
674
+ const wrapper = await mountVariant({
675
+ variant: 'collection',
676
+ sourceCollection: { id: BEST_SELLERS_ID, _type: 'collection', slug: 'best-sellers' },
677
+ viewAllHref: '/authored-somewhere-else',
678
+ });
679
+ expect(wrapper.get('h2 a').attributes('href')).toBe('/collections/best-sellers');
680
+ });
681
+
682
+ it('derives it from a seed reference’s slug as readily as from a resolved one', async () => {
683
+ const wrapper = await mountVariant({
684
+ variant: 'collection',
685
+ sourceCollection: { _type: 'collection', slug: 'best-sellers' },
686
+ viewAllHref: '/authored-somewhere-else',
687
+ });
688
+ expect(wrapper.get('h2 a').attributes('href')).toBe('/collections/best-sellers');
689
+ });
690
+
691
+ it('renders the heading unlinked when the collection is known only by id', async () => {
692
+ const wrapper = await mountVariant({
693
+ variant: 'collection',
694
+ sourceCollection: { id: BEST_SELLERS_ID, _type: 'collection' },
695
+ viewAllHref: '/authored-somewhere-else',
696
+ });
697
+ expect(wrapper.findAllComponents(ProductCard).length).toBeGreaterThan(1);
698
+ expect(wrapper.find('h2 a').exists()).toBe(false);
699
+ expect(wrapper.get('h2').text()).toBe(mock.heading);
700
+ });
701
+
702
+ it('keeps the authored href in the related variant', async () => {
703
+ const wrapper = await mountVariant({ variant: 'related', viewAllHref: '/collections/all' });
704
+ expect(wrapper.get('h2 a').attributes('href')).toBe('/collections/all');
705
+ });
706
+
707
+ it('renders no link at all in recently-viewed', async () => {
708
+ const wrapper = await mountVariant({ variant: 'recently-viewed' });
709
+ expect(wrapper.find('h2 a').exists()).toBe(false);
710
+ });
711
+ });
712
+
713
+ /**
714
+ * The prerendered page's live refresh (`app/storefront/types.ts`): the row's cards are in the
715
+ * HTML from the first paint, and a few hundred milliseconds after mount the storefront swaps in
716
+ * the backend's current prices and stock lines. The row never redraws for it, and it announces
717
+ * the refresh once rather than letting every card speak for itself.
718
+ */
719
+ describe('the volatile refresh', () => {
720
+ /** A `related` catalogue whose result a test can move through its states after mounting. */
721
+ function refreshableSource(): {
722
+ storefront: StorefrontSource;
723
+ revalidating: Ref<ReadonlySet<VolatileKey>>;
724
+ loading: Ref<boolean>;
725
+ pending: Ref<boolean>;
726
+ } {
727
+ const base = createDemoStorefront({ productHandle: 'not-a-real-product' });
728
+ const revalidating = ref<ReadonlySet<VolatileKey>>(new Set());
729
+ const loading = ref(false);
730
+ const pending = ref(false);
731
+ const result = resolvedResult(PRODUCTS.slice(0, 4), { revalidating, loading, pending });
732
+ return {
733
+ storefront: { ...base, catalog: { ...base.catalog, related: () => result } },
734
+ revalidating,
735
+ loading,
736
+ pending,
737
+ };
738
+ }
739
+
740
+ it('keeps every card, marks its price and stock line busy, and draws no skeleton', async () => {
741
+ const { storefront, revalidating } = refreshableSource();
742
+ const wrapper = mountBlock(mock, { storefront });
743
+ await flushPromises();
744
+ const shown = wrapper.findAllComponents(ProductCard).length;
745
+ expect(shown).toBe(4);
746
+
747
+ revalidating.value = new Set(['price', 'stock']);
748
+ await flushPromises();
749
+
750
+ expect(wrapper.findAllComponents(ProductCard)).toHaveLength(shown);
751
+ expect(wrapper.findAllComponents(Skeleton)).toHaveLength(0);
752
+ expect(wrapper.findAll('[data-part="root"][aria-busy="true"]').length).toBeGreaterThanOrEqual(
753
+ shown
754
+ );
755
+ expect(wrapper.findAll('[data-part="spinner"]').length).toBeGreaterThanOrEqual(shown);
756
+ expect(await axe(wrapper.element)).toHaveNoViolations();
757
+ });
758
+
759
+ it('announces once for the whole row, after mount, and never per card', async () => {
760
+ const { storefront, revalidating } = refreshableSource();
761
+ const wrapper = mountBlock(mock, { storefront });
762
+ await flushPromises();
763
+ const region = () => wrapper.get('p.sr-only[role="status"]');
764
+
765
+ // Mounted and empty first: a live region that arrives already holding its message is
766
+ // announced unreliably, which is what a prerendered page would produce if the block read
767
+ // `revalidating` straight through instead of flipping it after mount.
768
+ expect(region().text()).toBe('');
769
+
770
+ revalidating.value = new Set(['stock']);
771
+ await flushPromises();
772
+
773
+ expect(region().text()).toBe(enUS.storefront.updatingValues);
774
+ expect(wrapper.findAll('p.sr-only[role="status"]')).toHaveLength(1);
775
+ // `announce: false` on every card — the per-value regions are gone, not merely empty.
776
+ expect(wrapper.findAll('[data-part="srStatus"]')).toHaveLength(0);
777
+ expect(
778
+ wrapper.findAllComponents(ProductCard).every((card) => card.props('announce') === false)
779
+ ).toBe(true);
780
+ });
781
+
782
+ /**
783
+ * The hydration case, and the reason `useRevalidating` exists
784
+ * (`app/composables/useRevalidating.ts`). A prerendered page's client-side storefront can
785
+ * already be revalidating by the time the block's first render runs, and that first render has
786
+ * to be byte-identical to the server's or Vue repaints the block — and a live region that
787
+ * arrives already holding its message is announced unreliably. Both are the same fix: the flag
788
+ * is false until after mount.
789
+ */
790
+ it('paints the server’s markup first, even when the storefront is already revalidating', async () => {
791
+ const { storefront, revalidating } = refreshableSource();
792
+ revalidating.value = new Set(['price', 'stock']);
793
+
794
+ const wrapper = mountBlock(mock, { storefront });
795
+
796
+ expect(wrapper.find('[data-part="spinner"]').exists()).toBe(false);
797
+ expect(wrapper.get('p.sr-only[role="status"]').text()).toBe('');
798
+
799
+ await flushPromises();
800
+
801
+ expect(wrapper.find('[data-part="spinner"]').exists()).toBe(true);
802
+ expect(wrapper.get('p.sr-only[role="status"]').text()).toBe(enUS.storefront.updatingValues);
803
+ });
804
+
805
+ it('never draws a skeleton over cards the visitor can already see', async () => {
806
+ const { storefront, pending, loading } = refreshableSource();
807
+ const wrapper = mountBlock(mock, { storefront });
808
+ await flushPromises();
809
+
810
+ // Both halves of the rule at once: a storefront that raised `pending` over data the row has
811
+ // must not blank it, and a reload keeps the cards and marks the row busy instead.
812
+ pending.value = true;
813
+ loading.value = true;
814
+ await flushPromises();
815
+
816
+ expect(wrapper.findAllComponents(Skeleton)).toHaveLength(0);
817
+ expect(wrapper.findAllComponents(ProductCard)).toHaveLength(4);
818
+ expect(wrapper.get('section').attributes('aria-busy')).toBe('true');
819
+ expect(
820
+ wrapper.findAllComponents(ProductCard).every((card) => card.props('revalidating') === true)
821
+ ).toBe(true);
822
+ });
823
+ });
824
+
825
+ /**
826
+ * **The first card's focus ring, both axes (fix, 2026-10-04).** `Carousel` reserves the ring's
827
+ * reach as padding on its track, because `overflow-x-auto` forces `overflow-y: auto` too and the
828
+ * track then clips every slide's ring at its own padding box. This block bleeds that track to the
829
+ * screen edge below 48rem, and the way it used to do that — `px-[gutter] … @tablet:px-0` through
830
+ * `classes.track` — took the inline half of the reservation away: `px-*` and `p-*` are different
831
+ * `tailwind-merge` groups, so both classes survived the merge, and `padding-inline` then won in
832
+ * the cascade because Tailwind emits every `padding-inline` rule after every `padding` one. On the
833
+ * deployed site that measured `padding-top: 6px`, `padding-left: 0px` at 1440px, and the first
834
+ * card's ring was cut off flat down its left edge.
835
+ *
836
+ * So this compiles the theme's real stylesheet (the way `test/mainCss.spec.ts` does) over the
837
+ * **resolved class list of a mounted track** and asks what each axis actually computes to at each
838
+ * container breakpoint — the question neither a class-list assertion nor jsdom can answer, since
839
+ * jsdom applies no stylesheet and resolves no container query. Proven by mutation: restoring the
840
+ * old `-mx-/px-/scroll-px-` bleed trio here fails it on the inline axis at every breakpoint.
841
+ */
842
+ describe('the track’s focus-ring reservation', () => {
843
+ const RING_REACH = 'calc(var(--eldra-focus-offset) + var(--eldra-focus-width))';
844
+ // `import.meta.dirname`, not `new URL(..., import.meta.url)`: under jsdom Vite's dev
845
+ // transform rewrites that idiom into a dev-server URL, which no Node read can open —
846
+ // `test/richTextTypography.spec.ts` carries the same note for the same reason.
847
+ const assetsDir = `${join(import.meta.dirname, '../../../app/assets')}/`;
848
+
849
+ /**
850
+ * Every utility rule the build emits, in source order, with the container query it sits under.
851
+ * Only `@layer utilities`: the same stylesheet carries a preflight `padding: 0` and the
852
+ * rich-text `padding-left` of a blockquote, and neither is on this element.
853
+ */
854
+ type Rule = { condition: string; declarations: Array<[string, string]> };
855
+
856
+ function flatten(css: string, condition: string, layer: string, out: Rule[]): void {
857
+ let i = 0;
858
+ while (i < css.length) {
859
+ const open = css.indexOf('{', i);
860
+ if (open === -1) return;
861
+ let depth = 1;
862
+ let j = open + 1;
863
+ while (j < css.length && depth > 0) {
864
+ if (css[j] === '{') depth += 1;
865
+ else if (css[j] === '}') depth -= 1;
866
+ j += 1;
867
+ }
868
+ const head = css.slice(i, open).trim();
869
+ const body = css.slice(open + 1, j - 1);
870
+ const namedLayer = /@layer\s+([\w-]+)\s*$/.exec(head);
871
+ if (head.startsWith('@') || namedLayer) {
872
+ flatten(
873
+ body,
874
+ /@container[^{]*$/.test(head) ? head.slice(head.lastIndexOf('@container')) : condition,
875
+ namedLayer ? namedLayer[1]! : layer,
876
+ out
877
+ );
878
+ } else if (layer === 'utilities') {
879
+ out.push({
880
+ condition,
881
+ declarations: body
882
+ .split(';')
883
+ .map((part) => part.trim())
884
+ .filter((part) => part.includes(':') && !part.includes('{'))
885
+ .map((part) => {
886
+ const at = part.indexOf(':');
887
+ return [part.slice(0, at).trim(), part.slice(at + 1).trim()] as [string, string];
888
+ }),
889
+ });
890
+ }
891
+ i = j;
892
+ }
893
+ }
894
+
895
+ /** The last value to win for `properties`, among the rules that apply at `width`. */
896
+ function resolved(rules: Rule[], width: number, properties: string[]): string | undefined {
897
+ let value: string | undefined;
898
+ for (const rule of rules) {
899
+ const match = /width >= ([\d.]+)rem/.exec(rule.condition);
900
+ if (match && width < Number(match[1]) * 16) continue;
901
+ for (const [property, declared] of rule.declarations) {
902
+ if (properties.includes(property)) value = declared;
903
+ }
904
+ }
905
+ return value;
906
+ }
907
+
908
+ async function trackRules(): Promise<Rule[]> {
909
+ const wrapper = mountBlock(mock);
910
+ await flushPromises();
911
+ const classes = wrapper.get('[data-part="track"]').element.className.split(/\s+/);
912
+ const compiler = await compile(readFileSync(`${assetsDir}main.css`, 'utf8'), {
913
+ base: assetsDir,
914
+ onDependency() {},
915
+ });
916
+ const rules: Rule[] = [];
917
+ flatten(compiler.build(classes), '', '', rules);
918
+ return rules;
919
+ }
920
+
921
+ /** `max(bleed, reach)` can only be at least the reach; the bare reach is exactly it. */
922
+ function reservesTheRing(value: string | undefined): boolean {
923
+ return (
924
+ value === RING_REACH || (value?.startsWith('max(') === true && value.includes(RING_REACH))
925
+ );
926
+ }
927
+
928
+ // 375px: the bled width, where the gutter is the inline reservation. 768px and 1440px: the two
929
+ // container steps above it, where the bleed is off and only the ring's own reach is left.
930
+ for (const width of [375, 768, 1440]) {
931
+ it(`reserves the ring on both axes at ${width}px`, async () => {
932
+ const rules = await trackRules();
933
+ expect(resolved(rules, width, ['padding', 'padding-block', 'padding-top'])).toBe(
934
+ RING_REACH
935
+ );
936
+ const inline = resolved(rules, width, ['padding', 'padding-inline', 'padding-left']);
937
+ expect(reservesTheRing(inline)).toBe(true);
938
+ // Scroll padding has to match the inline padding exactly, or `scroll-snap-align: start`
939
+ // lands on the padding in front of the first slide instead of the slide's own edge — which
940
+ // scrolls that padding past the start and clips the ring all over again.
941
+ expect(resolved(rules, width, ['scroll-padding-inline', 'scroll-padding-left'])).toBe(
942
+ inline
943
+ );
944
+ // And the negative margin that cancels it, so the track's footprint is unchanged.
945
+ expect(resolved(rules, width, ['margin-inline', 'margin-left'])).toBe(
946
+ `calc(${inline} * -1)`
947
+ );
948
+ });
949
+ }
950
+
951
+ it('bleeds to the gutter below 48rem and sits inside the container above it', async () => {
952
+ const rules = await trackRules();
953
+ expect(resolved(rules, 375, ['--eldra-carousel-bleed'])).toBe('var(--eldra-gutter-mobile)');
954
+ expect(resolved(rules, 768, ['--eldra-carousel-bleed'])).toBe('0px');
955
+ });
956
+ });
957
+ });