@usethrottle/storefront-react 0.0.0-stage → 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 (122) hide show
  1. package/CLAUDE.md +67 -0
  2. package/README.md +119 -2
  3. package/dist/StorefrontProvider-Br4wUHui.d.cts +559 -0
  4. package/dist/StorefrontProvider-DLEPEjg6.d.ts +559 -0
  5. package/dist/account/index.cjs +69 -0
  6. package/dist/account/index.cjs.map +1 -0
  7. package/dist/account/index.d.cts +23 -0
  8. package/dist/account/index.d.ts +23 -0
  9. package/dist/account/index.js +68 -0
  10. package/dist/account/index.js.map +1 -0
  11. package/dist/chunk-2LCPIY2P.cjs +16 -0
  12. package/dist/chunk-2LCPIY2P.cjs.map +1 -0
  13. package/dist/chunk-3A72UY6T.js +2126 -0
  14. package/dist/chunk-3A72UY6T.js.map +1 -0
  15. package/dist/chunk-3JMIVAHN.js +185 -0
  16. package/dist/chunk-3JMIVAHN.js.map +1 -0
  17. package/dist/chunk-4J6AGWNC.cjs +24 -0
  18. package/dist/chunk-4J6AGWNC.cjs.map +1 -0
  19. package/dist/chunk-4U6MYDZV.js +17 -0
  20. package/dist/chunk-4U6MYDZV.js.map +1 -0
  21. package/dist/chunk-66HDJVPS.js +22 -0
  22. package/dist/chunk-66HDJVPS.js.map +1 -0
  23. package/dist/chunk-6X2OZSNV.cjs +83 -0
  24. package/dist/chunk-6X2OZSNV.cjs.map +1 -0
  25. package/dist/chunk-6ZMMZ245.cjs +2127 -0
  26. package/dist/chunk-6ZMMZ245.cjs.map +1 -0
  27. package/dist/chunk-7R37CVAB.cjs +23 -0
  28. package/dist/chunk-7R37CVAB.cjs.map +1 -0
  29. package/dist/chunk-A3IFWQUV.js +368 -0
  30. package/dist/chunk-A3IFWQUV.js.map +1 -0
  31. package/dist/chunk-AYC2YK4E.cjs +95 -0
  32. package/dist/chunk-AYC2YK4E.cjs.map +1 -0
  33. package/dist/chunk-AZV5U7YB.cjs +18 -0
  34. package/dist/chunk-AZV5U7YB.cjs.map +1 -0
  35. package/dist/chunk-CE2SKNQP.cjs +71 -0
  36. package/dist/chunk-CE2SKNQP.cjs.map +1 -0
  37. package/dist/chunk-D76CRI4X.js +2175 -0
  38. package/dist/chunk-D76CRI4X.js.map +1 -0
  39. package/dist/chunk-DOAII637.cjs +186 -0
  40. package/dist/chunk-DOAII637.cjs.map +1 -0
  41. package/dist/chunk-DYHHAOMG.cjs +17 -0
  42. package/dist/chunk-DYHHAOMG.cjs.map +1 -0
  43. package/dist/chunk-EYSVU5SJ.js +196 -0
  44. package/dist/chunk-EYSVU5SJ.js.map +1 -0
  45. package/dist/chunk-HSUUDZWS.js +37 -0
  46. package/dist/chunk-HSUUDZWS.js.map +1 -0
  47. package/dist/chunk-HZ6VEN6Q.cjs +101 -0
  48. package/dist/chunk-HZ6VEN6Q.cjs.map +1 -0
  49. package/dist/chunk-IJOTLGPT.js +16 -0
  50. package/dist/chunk-IJOTLGPT.js.map +1 -0
  51. package/dist/chunk-ISDATHVC.js +219 -0
  52. package/dist/chunk-ISDATHVC.js.map +1 -0
  53. package/dist/chunk-LW2A6USV.js +100 -0
  54. package/dist/chunk-LW2A6USV.js.map +1 -0
  55. package/dist/chunk-M4YXSLRG.cjs +369 -0
  56. package/dist/chunk-M4YXSLRG.cjs.map +1 -0
  57. package/dist/chunk-NDUEJJLP.cjs +2176 -0
  58. package/dist/chunk-NDUEJJLP.cjs.map +1 -0
  59. package/dist/chunk-NNE4FYRT.js +820 -0
  60. package/dist/chunk-NNE4FYRT.js.map +1 -0
  61. package/dist/chunk-NW3EFHY2.js +15 -0
  62. package/dist/chunk-NW3EFHY2.js.map +1 -0
  63. package/dist/chunk-NZRUQUN5.js +167 -0
  64. package/dist/chunk-NZRUQUN5.js.map +1 -0
  65. package/dist/chunk-P6HHE57S.cjs +38 -0
  66. package/dist/chunk-P6HHE57S.cjs.map +1 -0
  67. package/dist/chunk-PHY7AY27.cjs +197 -0
  68. package/dist/chunk-PHY7AY27.cjs.map +1 -0
  69. package/dist/chunk-PNJOFFTL.cjs +128 -0
  70. package/dist/chunk-PNJOFFTL.cjs.map +1 -0
  71. package/dist/chunk-PXZQ4ONA.js +127 -0
  72. package/dist/chunk-PXZQ4ONA.js.map +1 -0
  73. package/dist/chunk-Q3VTUBPP.js +82 -0
  74. package/dist/chunk-Q3VTUBPP.js.map +1 -0
  75. package/dist/chunk-Q3XFD5UI.js +45 -0
  76. package/dist/chunk-Q3XFD5UI.js.map +1 -0
  77. package/dist/chunk-QM7KTT7F.js +94 -0
  78. package/dist/chunk-QM7KTT7F.js.map +1 -0
  79. package/dist/chunk-RLWZOLXL.js +70 -0
  80. package/dist/chunk-RLWZOLXL.js.map +1 -0
  81. package/dist/chunk-SV53BRP2.js +23 -0
  82. package/dist/chunk-SV53BRP2.js.map +1 -0
  83. package/dist/chunk-VWXJO427.cjs +821 -0
  84. package/dist/chunk-VWXJO427.cjs.map +1 -0
  85. package/dist/chunk-WIIOJDHR.cjs +220 -0
  86. package/dist/chunk-WIIOJDHR.cjs.map +1 -0
  87. package/dist/chunk-XQHGFWLG.cjs +46 -0
  88. package/dist/chunk-XQHGFWLG.cjs.map +1 -0
  89. package/dist/chunk-ZHCXI2ZZ.cjs +168 -0
  90. package/dist/chunk-ZHCXI2ZZ.cjs.map +1 -0
  91. package/dist/index-RSj2Rg62.d.cts +8 -0
  92. package/dist/index-RSj2Rg62.d.ts +8 -0
  93. package/dist/index.cjs +2829 -0
  94. package/dist/index.cjs.map +1 -0
  95. package/dist/index.d.cts +1718 -0
  96. package/dist/index.d.ts +1718 -0
  97. package/dist/index.js +2828 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/metadata-QhKw-tvz.d.cts +188 -0
  100. package/dist/metadata-QhKw-tvz.d.ts +188 -0
  101. package/dist/next/client.cjs +84 -0
  102. package/dist/next/client.cjs.map +1 -0
  103. package/dist/next/client.d.cts +40 -0
  104. package/dist/next/client.d.ts +40 -0
  105. package/dist/next/client.js +83 -0
  106. package/dist/next/client.js.map +1 -0
  107. package/dist/next/index.cjs +1090 -0
  108. package/dist/next/index.cjs.map +1 -0
  109. package/dist/next/index.d.cts +218 -0
  110. package/dist/next/index.d.ts +218 -0
  111. package/dist/next/index.js +1049 -0
  112. package/dist/next/index.js.map +1 -0
  113. package/dist/server/index.cjs +994 -0
  114. package/dist/server/index.cjs.map +1 -0
  115. package/dist/server/index.d.cts +229 -0
  116. package/dist/server/index.d.ts +229 -0
  117. package/dist/server/index.js +951 -0
  118. package/dist/server/index.js.map +1 -0
  119. package/dist/styles.css +2111 -0
  120. package/dist/use-part-DCfFk7kf.d.ts +24 -0
  121. package/dist/use-part-DgjPBL_O.d.cts +24 -0
  122. package/package.json +121 -3
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/unstyled.tsx","../src/parts/use-part.ts","../src/parts/sync.ts","../src/parts/frame.ts","../src/parts/merch.ts","../src/parts/pages.ts","../src/parts/pieces.ts","../src/parts/product.ts","../src/parts/shop.ts","../src/parts/shopper.ts","../src/parts/site.ts","../src/parts/index.ts","../src/strings/frame.ts","../src/strings/merch.ts","../src/strings/pages.ts","../src/strings/pieces.ts","../src/strings/product.ts","../src/strings/shop.ts","../src/strings/shopper.ts","../src/strings/en.ts","../src/provider/context.ts","../src/strings/localization.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { ReactNode } from 'react';\n\n/** True under `<Unstyled>` or a component's `unstyled` prop: parts drop their `tsf-<key>` base class. */\nexport const UnstyledContext = createContext(false);\n\n/** Whether the base `tsf-<part>` classes are dropped here (inside `<Unstyled>`). */\nexport function useUnstyled(): boolean {\n return useContext(UnstyledContext);\n}\n\n/** Renders its children with the package's base classes removed; `data-throttle-part` stays. */\nexport function Unstyled(props: { children?: ReactNode }) {\n return <UnstyledContext.Provider value={true}>{props.children}</UnstyledContext.Provider>;\n}\n","import { useAppearance } from '@usethrottle/ui';\nimport { useUnstyled } from '../unstyled';\nimport type { StorefrontPartKey } from './index';\n\n/** The part class prefix. A constant, not `useClassPrefix()`: a part's class must not change under a nested auth provider. */\nconst PART_PREFIX = 'tsf-';\n\n/** Extra class names keyed by part key (`{ 'product-card-title': 'text-lg' }`). Appended after the part's own classes, so they win. */\nexport type PartClassNames = Partial<Record<StorefrontPartKey, string>>;\n\n/** The styling props every storefront component takes and hands to `usePart`. */\nexport type UsePartLocal = {\n /** Extra class names per part, keyed by part key. Applied after `appearance.parts`. */\n classNames?: PartClassNames;\n /** Extra class names for the component's root element, applied last. */\n className?: string;\n /** Overrides the ambient `<Unstyled>` for this part. */\n unstyled?: boolean;\n};\n\n/**\n * The attributes of one part. The class order is the base `tsf-<key>` (dropped\n * when unstyled), then `appearance.parts[key]`, then `classNames[key]`, then\n * `className`, so the most local one is last.\n */\nexport function usePart(\n key: StorefrontPartKey,\n local?: UsePartLocal,\n): { className: string | undefined; 'data-throttle-part': StorefrontPartKey } {\n const { parts } = useAppearance();\n const ambient = useUnstyled();\n const unstyled = local?.unstyled ?? ambient;\n const className =\n [unstyled ? undefined : `${PART_PREFIX}${key}`, parts[key], local?.classNames?.[key], local?.className]\n .filter(Boolean)\n .join(' ') || undefined;\n return { className, 'data-throttle-part': key };\n}\n","/**\n * The DOM attributes that are part of the storefront-react contract (R2): the\n * Phase 1 `SEL` set a store's sync tests read. Components emit them natively,\n * so any store built on them stays sync-testable. Home attributes\n * (`hero-heading`, home shelves) belong to the store's own home.\n */\nexport const SYNC_ATTRIBUTES = [\n 'data-throttle-setting',\n 'data-theme-accent',\n 'data-theme-radius',\n 'data-menu',\n 'data-listing',\n 'data-listing-page-size',\n 'data-sort-option',\n 'data-product-card',\n 'data-product-handle',\n 'data-card-rating',\n 'data-badge',\n 'data-stock-words',\n 'data-section',\n 'data-section-title',\n 'data-string-key',\n 'data-filter-key',\n 'data-filter-display',\n 'data-filter-label',\n 'data-locale-option',\n 'data-currency-option',\n 'data-collection-title',\n 'data-category-handle',\n 'data-category-parent',\n 'data-review-id',\n] as const;\n\n/** The name of a `data-*` attribute components emit so an automated sync test can find them. */\nexport type SyncAttribute = (typeof SYNC_ATTRIBUTES)[number];\n","/** Part keys of the store frame. */\nexport const FRAME_PARTS = [\n 'skip-link',\n 'store-frame',\n 'store-frame-main',\n 'announcement-bar',\n 'announcement-bar-text',\n 'announcement-bar-dismiss',\n 'header',\n 'header-bar',\n 'header-menu-button',\n 'header-brand',\n 'header-logo',\n 'header-store-name',\n 'header-search',\n 'header-actions',\n 'header-nav-row',\n 'header-prefs',\n 'header-drawer-top',\n 'header-drawer-title',\n 'header-drawer-close',\n 'category-nav',\n 'category-nav-list',\n 'category-nav-item',\n 'category-nav-link',\n 'category-nav-toggle',\n 'category-nav-panel',\n 'category-nav-child',\n 'search-box',\n 'search-box-input',\n 'search-box-panel',\n 'search-box-list',\n 'search-box-group',\n 'search-box-group-label',\n 'search-box-option',\n 'search-box-thumb',\n 'search-box-option-name',\n 'search-box-option-meta',\n 'search-box-all',\n 'search-box-none',\n 'search-box-status',\n 'locale-switch',\n 'locale-switch-label',\n 'locale-switch-select',\n 'currency-switch',\n 'currency-switch-label',\n 'currency-switch-select',\n 'cart-button',\n 'cart-button-count',\n 'account-button',\n 'footer',\n 'footer-brand',\n 'footer-extra',\n 'footer-nav',\n 'footer-list',\n 'footer-item',\n 'footer-link',\n 'footer-sublist',\n 'footer-copyright',\n] as const;\n","/** Part keys of the merchandising sections. */\nexport const MERCH_PARTS = [\n 'merch-skeleton',\n 'merch-skeleton-item',\n 'collection-shelf',\n 'collection-shelf-header',\n 'collection-shelf-eyebrow',\n 'collection-shelf-title',\n 'collection-shelf-link',\n 'collection-shelf-grid',\n 'collection-shelf-item',\n 'featured-product',\n 'featured-product-media',\n 'featured-product-media-link',\n 'featured-product-placeholder',\n 'featured-product-body',\n 'featured-product-title',\n 'featured-product-rating',\n 'featured-product-price',\n 'featured-product-from',\n 'featured-product-description',\n 'featured-product-link',\n 'product-carousel',\n 'product-carousel-header',\n 'product-carousel-eyebrow',\n 'product-carousel-title',\n 'product-carousel-controls',\n 'product-carousel-prev',\n 'product-carousel-next',\n 'product-carousel-track',\n 'product-carousel-item',\n 'category-directory',\n 'category-directory-list',\n 'category-directory-item',\n 'category-directory-link',\n 'category-directory-image',\n 'category-directory-name',\n 'category-directory-count',\n 'category-directory-children',\n 'reviews-list',\n 'reviews-list-items',\n 'reviews-list-item',\n 'reviews-list-head',\n 'reviews-list-title',\n 'reviews-list-body',\n 'reviews-list-meta',\n 'reviews-list-author',\n 'reviews-list-verified',\n 'reviews-list-date',\n 'reviews-list-product',\n 'reviews-list-reply',\n] as const;\n","/** Part keys of the pages (search, not-found, account). */\nexport const PAGES_PARTS = [\n 'search-results',\n 'search-results-title',\n 'search-results-prompt',\n 'not-found',\n 'not-found-code',\n 'not-found-title',\n 'not-found-body',\n 'not-found-actions',\n 'not-found-link',\n 'account-page',\n 'account-page-title',\n 'account-page-setup-notice',\n 'account-page-setup-title',\n 'account-page-setup-body',\n] as const;\n","/** Part keys of the pieces. */\nexport const PIECES_PARTS = [\n 'product-card',\n 'product-card-row',\n 'product-card-media',\n 'product-card-media-link',\n 'product-card-image',\n 'product-card-image-alt',\n 'product-card-placeholder',\n 'product-card-badges',\n 'product-card-actions',\n 'product-card-body',\n 'product-card-brand',\n 'product-card-title',\n 'product-card-title-link',\n 'product-card-swatches',\n 'product-card-swatch-more',\n 'product-card-rating',\n 'product-card-price',\n 'product-card-from',\n 'product-card-unpriced',\n 'star-rating',\n 'star-rating-stars',\n 'star-rating-count',\n 'product-badge',\n 'swatch',\n 'money',\n 'money-compare',\n 'price',\n 'price-label',\n 'price-hint',\n 'image',\n 'rich-text',\n 'link',\n] as const;\n","/** Part keys of the product area, `<component>-<part>`. A drift test keeps this list and what renders equal. */\nexport const PRODUCT_PARTS = [\n 'add-to-cart',\n 'add-to-cart-button',\n 'add-to-cart-message',\n 'buy-box',\n 'buy-box-actions',\n 'buy-box-kicker',\n 'buy-box-price',\n 'buy-box-rating',\n 'buy-box-sku',\n 'buy-box-summary',\n 'buy-box-title',\n 'category-list',\n 'category-list-item',\n 'category-list-link',\n 'gallery',\n 'gallery-counter',\n 'gallery-enlarge',\n 'gallery-item',\n 'gallery-next',\n 'gallery-placeholder',\n 'gallery-previous',\n 'gallery-stage',\n 'gallery-thumb',\n 'gallery-thumbs',\n 'gallery-thumbs-item',\n 'gallery-video',\n 'lightbox',\n 'lightbox-counter',\n 'lightbox-next',\n 'lightbox-previous',\n 'lightbox-stage',\n 'lightbox-title',\n 'product-breadcrumbs',\n 'product-breadcrumbs-current',\n 'product-breadcrumbs-item',\n 'product-breadcrumbs-link',\n 'product-breadcrumbs-list',\n 'product-page',\n 'product-page-main',\n 'product-review',\n 'product-review-author',\n 'product-review-body',\n 'product-review-date',\n 'product-review-header',\n 'product-review-reply',\n 'product-review-title',\n 'product-reviews',\n 'product-reviews-average',\n 'product-reviews-clear',\n 'product-reviews-controls',\n 'product-reviews-empty',\n 'product-reviews-error',\n 'product-reviews-gate',\n 'product-reviews-histogram',\n 'product-reviews-histogram-bar',\n 'product-reviews-histogram-count',\n 'product-reviews-histogram-fill',\n 'product-reviews-histogram-row',\n 'product-reviews-list',\n 'product-reviews-load-more',\n 'product-reviews-main',\n 'product-reviews-summary',\n 'product-section',\n 'product-section-body',\n 'product-section-title',\n 'product-section-trigger',\n 'product-sections',\n 'product-specs',\n 'product-specs-label',\n 'product-specs-row',\n 'product-specs-value',\n 'quantity-decrease',\n 'quantity-field',\n 'quantity-increase',\n 'quantity-input',\n 'related-products',\n 'related-products-item',\n 'review-form',\n 'review-form-error',\n 'review-form-field',\n 'review-form-star',\n 'review-form-star-input',\n 'review-form-stars',\n 'review-form-submit',\n 'review-form-textarea',\n 'review-form-thanks',\n 'review-form-title',\n 'shipping-section',\n 'sticky-add-to-cart',\n 'sticky-add-to-cart-button',\n 'sticky-add-to-cart-price',\n 'sticky-add-to-cart-title',\n 'stock-status',\n 'tag-list',\n 'tag-list-item',\n 'tag-list-link',\n 'variant-option',\n 'variant-option-chosen',\n 'variant-option-legend',\n 'variant-option-name',\n 'variant-option-values',\n 'variant-picker',\n 'variant-value',\n 'variant-value-label',\n] as const;\n","/** Part keys of the shop-all sections. */\nexport const SHOP_PARTS = [\n 'shop-all',\n 'shop-all-heading',\n 'shop-all-description',\n 'shop-all-breadcrumbs',\n 'shop-all-breadcrumb-list',\n 'shop-all-breadcrumb',\n 'shop-all-breadcrumb-link',\n 'shop-all-controls',\n 'shop-all-tools',\n 'shop-all-body',\n 'shop-all-main',\n 'live-region',\n 'result-count',\n 'sort-select',\n 'sort-select-label',\n 'sort-select-input',\n 'filter-sidebar',\n 'filter-sidebar-head',\n 'filter-sidebar-title',\n 'filter-clear',\n 'filter-bar',\n 'filter-bar-more',\n 'filter-drawer-trigger',\n 'filter-drawer-count',\n 'filter-drawer-head',\n 'filter-drawer-title',\n 'filter-drawer-close',\n 'filter-drawer-body',\n 'filter-drawer-foot',\n 'filter-drawer-apply',\n 'facet',\n 'facet-heading',\n 'facet-toggle',\n 'facet-trigger',\n 'facet-panel',\n 'facet-label',\n 'facet-selected',\n 'facet-body',\n 'facet-search',\n 'facet-fieldset',\n 'facet-legend',\n 'facet-options',\n 'facet-option',\n 'facet-option-label',\n 'facet-option-input',\n 'facet-option-text',\n 'facet-option-count',\n 'facet-empty',\n 'facet-show-all',\n 'facet-select',\n 'facet-boolean',\n 'facet-range',\n 'facet-range-fields',\n 'facet-range-field',\n 'facet-range-input',\n 'facet-range-error',\n 'facet-range-hint',\n 'facet-range-actions',\n 'facet-range-apply',\n 'facet-range-clear',\n 'active-filters',\n 'active-filter',\n 'active-filter-remove',\n 'active-filters-clear',\n 'product-grid',\n 'product-grid-pages',\n 'product-grid-item',\n 'product-grid-skeleton',\n 'product-grid-skeleton-item',\n 'product-grid-empty',\n 'product-grid-error',\n 'product-grid-retry',\n 'pagination',\n 'pagination-list',\n 'pagination-item',\n 'pagination-link',\n 'pagination-step',\n 'pagination-gap',\n 'pagination-more',\n 'pagination-crawl',\n] as const;\n","/** Part keys of the shopper areas: cart drawer, quick add, quick view, recently viewed and compare. */\nexport const SHOPPER_PARTS = [\n 'cart-drawer',\n 'cart-drawer-top',\n 'cart-drawer-title',\n 'cart-drawer-close',\n 'cart-drawer-body',\n 'cart-status',\n 'cart-error',\n 'cart-loading',\n 'cart-empty',\n 'cart-empty-text',\n 'cart-lines',\n 'cart-line',\n 'cart-line-media',\n 'cart-line-body',\n 'cart-line-name',\n 'cart-line-price',\n 'cart-line-note',\n 'cart-line-quantity',\n 'cart-line-decrease',\n 'cart-line-count',\n 'cart-line-increase',\n 'cart-line-total',\n 'cart-line-remove',\n 'cart-footer',\n 'cart-subtotal',\n 'cart-subtotal-label',\n 'cart-subtotal-amount',\n 'cart-checkout',\n 'cart-continue',\n 'quick-add',\n 'quick-add-button',\n 'quick-add-panel',\n 'quick-add-title',\n 'quick-add-message',\n 'quick-view',\n 'quick-view-title',\n 'quick-view-body',\n 'quick-view-gallery',\n 'quick-view-details',\n 'quick-view-link',\n 'quick-view-message',\n 'recently-viewed',\n 'recently-viewed-title',\n 'recently-viewed-list',\n 'recently-viewed-item',\n 'compare',\n 'compare-header',\n 'compare-title',\n 'compare-clear',\n 'compare-scroll',\n 'compare-table',\n 'compare-caption',\n 'compare-row',\n 'compare-label',\n 'compare-product',\n 'compare-product-media',\n 'compare-product-link',\n 'compare-product-remove',\n 'compare-cell',\n 'compare-empty',\n 'compare-button',\n] as const;\n","/** Part keys of the site-level pieces the provider and outlets render. */\nexport const SITE_PARTS = ['storefront-root', 'slot-outlet'] as const;\n","import { FRAME_PARTS } from './frame';\nimport { MERCH_PARTS } from './merch';\nimport { PAGES_PARTS } from './pages';\nimport { PIECES_PARTS } from './pieces';\nimport { PRODUCT_PARTS } from './product';\nimport { SHOP_PARTS } from './shop';\nimport { SHOPPER_PARTS } from './shopper';\nimport { SITE_PARTS } from './site';\n\n/** Every part key, kebab-case `<component>-<part>`. A drift test keeps what renders and what is listed equal. */\nexport const STOREFRONT_PART_KEYS = [\n ...SITE_PARTS,\n ...PIECES_PARTS,\n ...SHOP_PARTS,\n ...PRODUCT_PARTS,\n ...FRAME_PARTS,\n ...MERCH_PARTS,\n ...SHOPPER_PARTS,\n ...PAGES_PARTS,\n] as const;\n\n/**\n * One part key: `data-throttle-part=\"<key>\"` and the class `tsf-<key>`. A versioned contract: a key is never renamed in a minor release.\n */\nexport type StorefrontPartKey = (typeof STOREFRONT_PART_KEYS)[number];\n\nexport { usePart } from './use-part';\nexport type { PartClassNames, UsePartLocal } from './use-part';\nexport { SYNC_ATTRIBUTES } from './sync';\nexport type { SyncAttribute } from './sync';\n","/** English text of the store frame. A key reads `frame.<group>.<name>`, such as `frame.search.label`. */\nexport const FRAME_STRINGS = {\n skipLink: 'Skip to main content',\n announcement: {\n label: 'Announcement',\n dismiss: 'Dismiss announcement',\n },\n header: {\n mainNav: 'Main',\n categoriesNav: 'Categories',\n closeMenu: 'Close menu',\n home: '{store}, home',\n homeNoName: 'Home',\n },\n nav: {\n submenu: '{name} submenu',\n },\n search: {\n label: 'Search the shop',\n suggestions: 'Search suggestions',\n products: 'Products',\n categories: 'Categories',\n brands: 'Brands',\n tags: 'Tags',\n collections: 'Collections',\n searchFor: 'Search for “{q}”',\n none: 'No quick matches for “{q}”.',\n announceNone: 'No quick matches.',\n announceOne: '1 suggestion',\n announceMany: '{count} suggestions',\n productCount: '{count} products',\n productCountOne: '1 product',\n },\n locale: { label: 'Language' },\n currency: { label: 'Currency' },\n cart: {\n label: 'Cart, {count} items',\n labelOne: 'Cart, 1 item',\n },\n footer: { label: 'Footer' },\n} as const;\n","/** English text of the merchandising sections. A key reads `merch.<group>.<name>`, such as `merch.carousel.next`. */\nexport const MERCH_STRINGS = {\n viewAll: 'View all',\n viewAllNamed: 'View all {title}',\n viewProduct: 'View product',\n carousel: {\n label: 'Products',\n previous: 'Previous products',\n next: 'Next products',\n slide: '{n} of {total}',\n },\n categories: {\n label: 'Categories',\n count: '{count} products',\n countOne: '1 product',\n },\n reviews: {\n label: 'Reviews',\n verified: 'Verified purchase',\n reply: 'Reply from the store',\n forProduct: 'on {product}',\n },\n} as const;\n","/** English text of the pages. A key reads `pages.<group>.<name>`, such as `pages.notFound.body`. */\nexport const PAGES_STRINGS = {\n notFound: {\n code: '404',\n body: 'It may have moved, or it may never have existed.',\n shop: 'Browse the shop',\n home: 'Home',\n },\n search: {\n prompt: 'Type something to search the shop.',\n },\n account: {\n signIn: 'Sign in',\n signUp: 'Create an account',\n setupTitle: 'Account pages are not set up yet',\n setupBody:\n 'Sign-in and account pages need your Throttle publishable key. Add it under Connections in the Builder, or pass throttlePublishableKey to the StorefrontProvider.',\n },\n} as const;\n","/** English text of the pieces. A key reads `pieces.<group>.<name>`, such as `pieces.rating.label`. */\nexport const PIECES_STRINGS = {\n rating: {\n label: '{value} out of 5 stars',\n labelWithCount: '{value} out of 5 stars, {count} reviews',\n labelWithOne: '{value} out of 5 stars, 1 review',\n count: '({count})',\n },\n price: {\n customer: 'Your price',\n verifyEmail: 'Verify your email to see your price',\n compareAt: 'Original price',\n from: 'From',\n unavailable: 'Not sold in this currency',\n },\n card: {\n moreSwatches: '+{count}',\n moreSwatchesLabel: '{count} more colours',\n },\n} as const;\n","/**\n * English text of the product page. A key reads `product.<group>.<name>`, such\n * as `product.gallery.next`. The group names avoid the catalog's own\n * `product.*` strings (`product.quantity`, `product.reviews`, ...) so the two never collide.\n */\nexport const PRODUCT_STRINGS = {\n gallery: {\n label: '{title}: photos',\n photoAlt: '{title}, photo {n}',\n thumbs: 'Photo thumbnails',\n showPhoto: 'Show photo {n} of {count}',\n previous: 'Previous photo',\n next: 'Next photo',\n enlarge: 'Enlarge photo',\n close: 'Close',\n counter: '{n} / {count}',\n lightboxTitle: '{title}: enlarged photos',\n video: '{title}, video',\n },\n options: {\n soldOut: ', sold out',\n unavailableWith: ', not made with {others}',\n chooseOne: 'Choose {option}',\n },\n stockStatus: {\n noCurrency: 'Not available in {currency}',\n noCurrencyAny: 'Not available',\n noCombination: 'This combination is not available',\n },\n quantityInput: {\n decrease: 'One fewer',\n increase: 'One more',\n },\n cartAdd: {\n adding: 'Adding…',\n added: 'Added {quantity} × {title} to your cart',\n onlyLeft: 'Only {count} left',\n outOfStock: 'Out of stock',\n failed: 'We could not add this to your cart. Try again in a moment.',\n },\n sections: {\n label: 'Product details',\n },\n crumbs: {\n label: 'Breadcrumb',\n home: 'Home',\n },\n sticky: {\n label: 'Add to cart',\n },\n reviewList: {\n ratingsByStars: 'Ratings by stars',\n filterRating: 'Show {rating}-star reviews, {count} in all',\n clearFilter: 'Show all reviews',\n sortLabel: 'Sort by',\n sortNewest: 'Newest',\n sortHighest: 'Highest rated',\n sortLowest: 'Lowest rated',\n loadMore: 'Load more reviews',\n loading: 'Loading reviews',\n loadFailed: 'We could not load the reviews. Try again in a moment.',\n verified: 'Verified buyer',\n reply: 'Reply from the store',\n noneForRating: 'No reviews with this rating.',\n average: '{value} out of 5',\n ratingLabel: 'Rated {rating} out of 5',\n gateSignIn: 'Sign in to write a review.',\n gateReviewsDisabled: 'Reviews are closed for this shop.',\n gateEmailNotVerified: 'Verify your email address to write a review.',\n gateAlreadyReviewed: 'You have reviewed this one already. Thank you.',\n gateNotVerifiedBuyer: 'Reviews come from customers who bought this. Once your order is paid, you can write one.',\n gateUnknown: 'You cannot review this product.',\n gateFailed: 'We could not check whether you can review this just now.',\n },\n reviewForm: {\n rating: 'Your rating',\n star: '{n} stars',\n starOne: '1 star',\n title: 'Title (optional)',\n body: 'Your review',\n name: 'Name shown',\n submit: 'Send review',\n sending: 'Sending…',\n thanksPending: 'Thanks, your review is awaiting moderation.',\n thanksLive: 'Thanks, your review is live.',\n needRating: 'Choose a rating from 1 to 5 stars.',\n needBody: 'Write a few words about it.',\n needName: 'Add the name to show with your review.',\n errorAlready: 'You have reviewed this one already.',\n errorNotBuyer: 'Only customers who bought this can review it.',\n errorEmail: 'Verify your email address first.',\n errorBusy: 'Too many reviews at once. Try again in a few minutes.',\n errorGeneric: 'Your review did not send. Try again in a moment.',\n },\n} as const;\n","/** English text of the shop-all sections. A key reads `shop.<name>`, such as `shop.resultsAnnounce`. */\nexport const SHOP_STRINGS = {\n resultsAnnounce: '{count} results',\n countOne: '{count} product',\n moreFilters: 'More filters',\n showResults: 'Show {count} results',\n showResultsLoading: 'Show results',\n closeFilters: 'Close filters',\n showAll: 'Show all ({count})',\n showFewer: 'Show fewer',\n searchFacet: 'Search {name}',\n noFacetMatch: 'No matches',\n valueCount: '{count} products',\n selectedCount: '{count} selected',\n removeFilter: 'Remove filter: {label}',\n rangeBetween: '{min} to {max}',\n rangeFrom: '{min} and up',\n rangeUpTo: 'up to {max}',\n rangeMin: 'Min',\n rangeMax: 'Max',\n rangeInvalid: 'Enter numbers only.',\n rangeClear: 'Clear',\n any: 'Any',\n breadcrumbs: 'Breadcrumb',\n paginationLabel: 'Pagination',\n pageLabel: 'Page {page}',\n errorLoading: 'We could not load the products.',\n retry: 'Try again',\n loadingProducts: 'Loading products',\n pastEnd: 'There are no products on this page.',\n} as const;\n","/**\n * English text of the cart drawer, quick add, quick view, recently viewed and compare. A key reads\n * `shopper.<group>.<name>`, such as `shopper.cart.subtotal`. The cart title, checkout and continue\n * shopping words are the catalog's own (`cart.title`, `cart.checkout`, `cart.continueShopping`, `empty.cart`).\n */\nexport const SHOPPER_STRINGS = {\n cart: {\n close: 'Close cart',\n lines: 'Items in your cart',\n loading: 'Loading your cart',\n subtotal: 'Subtotal',\n decrease: 'Decrease quantity of {name}',\n increase: 'Increase quantity of {name}',\n quantity: 'Quantity of {name}',\n remove: 'Remove {name}',\n removeText: 'Remove',\n removed: 'Removed {name} from your cart.',\n updated: 'Quantity of {name} is now {quantity}.',\n onlyLeft: 'Only {count} available',\n unavailable: 'No longer available',\n updateFailed: 'We could not update your cart. Try again.',\n checkoutFailed: 'We could not start checkout. Try again.',\n pricesChanged: 'Some prices changed. Review your cart, then check out again.',\n checkingOut: 'Taking you to checkout',\n },\n quickAdd: {\n button: 'Quick add',\n buttonFor: 'Quick add {title}',\n choose: 'Choose options',\n chooseFor: 'Choose options for {title}',\n panelFor: 'Options for {title}',\n added: 'Added {title} to your cart.',\n failed: 'We could not add this. Try again.',\n unavailable: 'This product is not available.',\n },\n quickView: {\n title: 'Quick view: {title}',\n loadingTitle: 'Quick view',\n viewDetails: 'View full details',\n closeLabel: 'Close quick view',\n notFound: 'This product is not available.',\n },\n recent: {\n title: 'Recently viewed',\n },\n compare: {\n button: 'Compare',\n buttonFor: 'Compare {title}',\n full: 'You can compare up to {max} products.',\n title: 'Compare products',\n caption: 'Comparison of {count} products',\n clear: 'Clear all',\n remove: 'Remove {title} from the comparison',\n needMore: 'Choose at least 2 products to compare.',\n spec: 'Specification',\n price: 'Price',\n availability: 'Availability',\n brand: 'Brand',\n rating: 'Rating',\n none: '–',\n loadFailed: 'We could not load these products. Try again.',\n },\n} as const;\n","import { FRAME_STRINGS } from './frame';\nimport { MERCH_STRINGS } from './merch';\nimport { PAGES_STRINGS } from './pages';\nimport { PIECES_STRINGS } from './pieces';\nimport { PRODUCT_STRINGS } from './product';\nimport { SHOP_STRINGS } from './shop';\nimport { SHOPPER_STRINGS } from './shopper';\nimport type { DeepPartial } from '@usethrottle/ui';\nimport type { StringKey } from '@usethrottle/catalog';\n\n/** The package's own English text, one object per area; a key reads `<area>.<name>`, such as `shop.resultsAnnounce`. */\nexport const SF_STRINGS_EN = {\n pieces: PIECES_STRINGS,\n shop: SHOP_STRINGS,\n product: PRODUCT_STRINGS,\n frame: FRAME_STRINGS,\n merch: MERCH_STRINGS,\n shopper: SHOPPER_STRINGS,\n pages: PAGES_STRINGS,\n};\n\n/** The English table with every leaf widened from its literal, so a translation is any string. */\nexport type SfStrings = Widen<typeof SF_STRINGS_EN>;\ntype Widen<T> = { -readonly [K in keyof T]: T[K] extends string ? string : Widen<T[K]> };\n\ntype Leaves<T, Prefix extends string = ''> = {\n [K in keyof T & string]: T[K] extends string ? `${Prefix}${K}` : Leaves<T[K], `${Prefix}${K}.`>;\n}[keyof T & string];\n\n/** The dotted leaf paths of `SF_STRINGS_EN`, for example `'shop.resultsAnnounce'`. */\nexport type SfLocalKey = Leaves<typeof SF_STRINGS_EN>;\n\n/** A catalog string (`cart.title`) or one of this package's own. */\nexport type SfStringKey = StringKey | SfLocalKey;\n\ntype Head<K> = K extends `${infer H}.${string}` ? H : never;\n/** A catalog key's override, nested by its dotted path: `{ cart: { title: 'Basket' } }`. */\ntype CatalogLocalization = {\n [H in Head<StringKey>]?: { [K in StringKey as K extends `${H}.${infer T}` ? T : never]?: string };\n};\n\n/** What the `localization` prop takes: any subset of the English table, plus any catalog string by its dotted path. */\nexport type StorefrontLocalization = DeepPartial<SfStrings> & CatalogLocalization;\n","import type { CatalogClient } from '@usethrottle/catalog';\nimport type { ThrottleAppearance } from '@usethrottle/ui';\nimport { createContext, useContext } from 'react';\nimport type { StorefrontAnalytics } from '../analytics/types';\nimport type { LinkComponent } from '../link';\nimport type { StorefrontPartKey } from '../parts';\nimport type { NormalizedSettings } from '../settings/normalize';\nimport type { ResolvedSiteDesign } from '../site/resolve';\nimport type { StorefrontRouter } from './router';\n\n/** Appearance for the storefront: `parts` take storefront part keys, `elements` reach auth components inside. Its `variables` / `darkVariables` override the theme mapping. */\nexport type StorefrontAppearance = ThrottleAppearance<string, StorefrontPartKey>;\n\n/** Where analytics events go. */\nexport type AnalyticsSink = StorefrontAnalytics;\n\n/** Everything `StorefrontProvider` resolved, as `useStorefront()` returns it. */\nexport type StorefrontContextValue = {\n settings: NormalizedSettings;\n site: ResolvedSiteDesign;\n preset: ResolvedSiteDesign['preset'];\n scheme: ResolvedSiteDesign['scheme'];\n dir: 'ltr' | 'rtl';\n locale: string;\n currency: string | undefined;\n client: CatalogClient;\n router: StorefrontRouter;\n analytics: AnalyticsSink;\n Link: LinkComponent;\n /** Whether the catalog's lists carry ratings; a card shows its rating only when this and `card.showRating` hold. */\n reviewsOnLists: boolean;\n throttlePublishableKey: string | null;\n};\n\nexport const StorefrontContext = createContext<StorefrontContextValue | null>(null);\n\n/** Everything the provider resolved. Throws outside a `StorefrontProvider`. */\nexport function useStorefront(): StorefrontContextValue {\n const value = useContext(StorefrontContext);\n if (!value) throw new Error('useStorefront() was called outside a <StorefrontProvider>.');\n return value;\n}\n","import { createLocalization } from '@usethrottle/ui';\nimport { SF_STRINGS_EN, type SfStrings } from './en';\n\n/** This package's copy contexts (private: auth has its own, so a store can localise each separately). */\nexport const { LocalizationProvider: SfLocalizationProvider, useCopy: useSfCopy } =\n createLocalization<SfStrings>(SF_STRINGS_EN as SfStrings);\n"],"mappings":";;;AAAA,SAAS,eAAe,kBAAkB;AAajC;AATF,IAAM,kBAAkB,cAAc,KAAK;AAG3C,SAAS,cAAuB;AACrC,SAAO,WAAW,eAAe;AACnC;AAGO,SAAS,SAAS,OAAiC;AACxD,SAAO,oBAAC,gBAAgB,UAAhB,EAAyB,OAAO,MAAO,gBAAM,UAAS;AAChE;;;ACdA,SAAS,qBAAqB;AAK9B,IAAM,cAAc;AAoBb,SAAS,QACd,KACA,OAC4E;AAC5E,QAAM,EAAE,MAAM,IAAI,cAAc;AAChC,QAAM,UAAU,YAAY;AAC5B,QAAM,WAAW,OAAO,YAAY;AACpC,QAAM,YACJ,CAAC,WAAW,SAAY,GAAG,WAAW,GAAG,GAAG,IAAI,MAAM,GAAG,GAAG,OAAO,aAAa,GAAG,GAAG,OAAO,SAAS,EACnG,OAAO,OAAO,EACd,KAAK,GAAG,KAAK;AAClB,SAAO,EAAE,WAAW,sBAAsB,IAAI;AAChD;;;AC/BO,IAAM,kBAAkB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;AC9BO,IAAM,cAAc;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;AC1DO,IAAM,cAAc;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;AClDO,IAAM,cAAc;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;ACfO,IAAM,eAAe;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;ACjCO,IAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;ACzGO,IAAM,aAAa;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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createContext, useContext } from "react";
5
+ var CartDrawerContext = createContext({ open: false, setOpen: () => {
6
+ } });
7
+ function useCartDrawer() {
8
+ return useContext(CartDrawerContext);
9
+ }
10
+
11
+ export {
12
+ CartDrawerContext,
13
+ useCartDrawer
14
+ };
15
+ //# sourceMappingURL=chunk-NW3EFHY2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/provider/cart-drawer.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\n\nexport type CartDrawerState = { open: boolean; setOpen(open: boolean): void };\n\nexport const CartDrawerContext = createContext<CartDrawerState>({ open: false, setOpen: () => {} });\n\n/** Whether the cart drawer is open, and a way to change it. `StorefrontProvider` owns the state. */\nexport function useCartDrawer(): CartDrawerState {\n return useContext(CartDrawerContext);\n}\n"],"mappings":";;;AAAA,SAAS,eAAe,kBAAkB;AAInC,IAAM,oBAAoB,cAA+B,EAAE,MAAM,OAAO,SAAS,MAAM;AAAC,EAAE,CAAC;AAG3F,SAAS,gBAAiC;AAC/C,SAAO,WAAW,iBAAiB;AACrC;","names":[]}
@@ -0,0 +1,167 @@
1
+ "use client";
2
+ import {
3
+ useCompare
4
+ } from "./chunk-PXZQ4ONA.js";
5
+ import {
6
+ MERCH_STALE_MS,
7
+ orderByHandles
8
+ } from "./chunk-3JMIVAHN.js";
9
+ import {
10
+ Price,
11
+ StarRating,
12
+ routeHref
13
+ } from "./chunk-LW2A6USV.js";
14
+ import "./chunk-IJOTLGPT.js";
15
+ import {
16
+ Image
17
+ } from "./chunk-HSUUDZWS.js";
18
+ import {
19
+ useStrings
20
+ } from "./chunk-Q3XFD5UI.js";
21
+ import {
22
+ usePart,
23
+ useStorefront
24
+ } from "./chunk-NNE4FYRT.js";
25
+
26
+ // src/shopper/CompareTable.tsx
27
+ import { useProducts } from "@usethrottle/catalog/react";
28
+ import { Icon } from "@usethrottle/ui";
29
+ import { useMemo } from "react";
30
+ import { jsx, jsxs } from "react/jsx-runtime";
31
+ import { createElement } from "react";
32
+ var humanise = (key) => {
33
+ const words = key.replace(/_/g, " ").trim();
34
+ return words.charAt(0).toUpperCase() + words.slice(1);
35
+ };
36
+ function attributeRows(products) {
37
+ const rows = /* @__PURE__ */ new Map();
38
+ for (const product of products) {
39
+ for (const variant of product.variants ?? []) {
40
+ const labels = variant.attributeLabels;
41
+ for (const key of Object.keys(variant.attributes ?? {})) {
42
+ if (!rows.has(key)) rows.set(key, { key, label: labels?.[key] ?? humanise(key) });
43
+ }
44
+ }
45
+ }
46
+ return [...rows.values()];
47
+ }
48
+ function attributeValues(product, key, yes, no) {
49
+ const out = [];
50
+ for (const variant of product.variants ?? []) {
51
+ const value = variant.attributes?.[key];
52
+ if (value === void 0) continue;
53
+ const text = typeof value === "boolean" ? value ? yes : no : String(value);
54
+ if (!out.includes(text)) out.push(text);
55
+ }
56
+ return out;
57
+ }
58
+ function Cell({ children, ...local }) {
59
+ const part = usePart("compare-cell", local);
60
+ return /* @__PURE__ */ jsx("td", { ...part, children });
61
+ }
62
+ function CompareTable(props) {
63
+ const { classNames, unstyled, className } = props;
64
+ const local = { classNames, unstyled };
65
+ const { t } = useStrings();
66
+ const { settings, Link: Anchor, reviewsOnLists } = useStorefront();
67
+ const { items, toggle, clear } = useCompare();
68
+ const ready = items.length >= 2;
69
+ const query = useProducts(
70
+ { handles: items, limit: Math.max(1, items.length), fields: "full" },
71
+ { enabled: ready, staleTimeMs: MERCH_STALE_MS }
72
+ );
73
+ const products = useMemo(() => ready && query.data ? orderByHandles(query.data.products, items) : [], [ready, query.data, items]);
74
+ const rows = useMemo(() => attributeRows(products), [products]);
75
+ const root = usePart("compare", { ...local, className });
76
+ const header = usePart("compare-header", local);
77
+ const title = usePart("compare-title", local);
78
+ const clearPart = usePart("compare-clear", local);
79
+ const scroll = usePart("compare-scroll", local);
80
+ const table = usePart("compare-table", local);
81
+ const caption = usePart("compare-caption", local);
82
+ const row = usePart("compare-row", local);
83
+ const label = usePart("compare-label", local);
84
+ const product = usePart("compare-product", local);
85
+ const media = usePart("compare-product-media", local);
86
+ const link = usePart("compare-product-link", local);
87
+ const remove = usePart("compare-product-remove", local);
88
+ const empty = usePart("compare-empty", local);
89
+ const heading = /* @__PURE__ */ jsxs("div", { ...header, children: [
90
+ /* @__PURE__ */ jsx("h2", { ...title, children: t("shopper.compare.title") }),
91
+ items.length > 0 ? /* @__PURE__ */ jsx("button", { type: "button", ...clearPart, onClick: clear, children: t("shopper.compare.clear") }) : null
92
+ ] });
93
+ if (!ready) {
94
+ return /* @__PURE__ */ jsxs("section", { ...root, "data-section": "compare", "data-section-title": t("shopper.compare.title"), children: [
95
+ heading,
96
+ /* @__PURE__ */ jsx("p", { ...empty, children: t("shopper.compare.needMore") })
97
+ ] });
98
+ }
99
+ if (query.error && !query.data) {
100
+ return /* @__PURE__ */ jsxs("section", { ...root, "data-section": "compare", "data-section-title": t("shopper.compare.title"), children: [
101
+ heading,
102
+ /* @__PURE__ */ jsx("p", { ...empty, role: "alert", children: t("shopper.compare.loadFailed") })
103
+ ] });
104
+ }
105
+ if (!query.data) return null;
106
+ if (products.length < 2) {
107
+ return /* @__PURE__ */ jsxs("section", { ...root, "data-section": "compare", "data-section-title": t("shopper.compare.title"), children: [
108
+ heading,
109
+ /* @__PURE__ */ jsx("p", { ...empty, children: t("shopper.compare.needMore") })
110
+ ] });
111
+ }
112
+ const words = settings.stock.words;
113
+ const availability = (p) => p.availability === "in_stock" ? words.inStock : p.availability === "out_of_stock" ? words.outOfStock : p.availability === "backorder" ? words.backorder : p.availability === "preorder" ? words.preorder : "";
114
+ const showRating = reviewsOnLists && settings.card.showRating && products.some((p) => p.rating && p.rating.count > 0);
115
+ const showBrand = products.some((p) => p.brand);
116
+ const none = t("shopper.compare.none");
117
+ const yes = t("boolean.yes");
118
+ const no = t("boolean.no");
119
+ const labelRow = (text, key, cell) => /* @__PURE__ */ createElement("tr", { ...row, key, "data-compare-row": key }, /* @__PURE__ */ jsx("th", { ...label, scope: "row", children: text }), products.map((p) => /* @__PURE__ */ jsx(Cell, { ...local, children: cell(p) }, p.handle)));
120
+ return /* @__PURE__ */ jsxs("section", { ...root, "data-section": "compare", "data-section-title": t("shopper.compare.title"), children: [
121
+ heading,
122
+ /* @__PURE__ */ jsx("div", { ...scroll, tabIndex: 0, role: "region", "aria-label": t("shopper.compare.title"), children: /* @__PURE__ */ jsxs("table", { ...table, children: [
123
+ /* @__PURE__ */ jsx("caption", { ...caption, children: t("shopper.compare.caption", { count: products.length }) }),
124
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { ...row, children: [
125
+ /* @__PURE__ */ jsx("th", { ...label, scope: "col", children: t("shopper.compare.spec") }),
126
+ products.map((p) => {
127
+ const name = p.title ?? p.handle;
128
+ const image = p.images?.[0];
129
+ return /* @__PURE__ */ createElement("th", { ...product, key: p.handle, scope: "col", "data-compare-handle": p.handle }, image ? /* @__PURE__ */ jsx("div", { ...media, children: /* @__PURE__ */ jsx(Image, { src: image.url, alt: "", aspectRatio: 1, ...local }) }) : null, /* @__PURE__ */ jsx(Anchor, { ...link, href: routeHref(settings, "product", p.handle), children: name }), /* @__PURE__ */ jsx(
130
+ "button",
131
+ {
132
+ type: "button",
133
+ ...remove,
134
+ "aria-label": t("shopper.compare.remove", { title: name }),
135
+ onClick: () => toggle(p.handle),
136
+ children: /* @__PURE__ */ jsx(Icon, { name: "close", size: 16 })
137
+ }
138
+ ));
139
+ })
140
+ ] }) }),
141
+ /* @__PURE__ */ jsxs("tbody", { children: [
142
+ labelRow(
143
+ t("shopper.compare.price"),
144
+ "price",
145
+ (p) => p.priceRange ? /* @__PURE__ */ jsx(Price, { minor: p.priceRange.minMinor, currency: p.priceRange.currency, ...local }) : none
146
+ ),
147
+ labelRow(t("shopper.compare.availability"), "availability", (p) => availability(p) || none),
148
+ showBrand ? labelRow(t("shopper.compare.brand"), "brand", (p) => p.brand || none) : null,
149
+ showRating ? labelRow(
150
+ t("shopper.compare.rating"),
151
+ "rating",
152
+ (p) => p.rating && p.rating.count > 0 && p.rating.average !== null ? /* @__PURE__ */ jsx(StarRating, { value: p.rating.average, count: p.rating.count, size: "sm", ...local }) : none
153
+ ) : null,
154
+ rows.map(
155
+ (r) => labelRow(r.label, `attr:${r.key}`, (p) => {
156
+ const values = attributeValues(p, r.key, yes, no);
157
+ return values.length > 0 ? values.join(", ") : none;
158
+ })
159
+ )
160
+ ] })
161
+ ] }) })
162
+ ] });
163
+ }
164
+ export {
165
+ CompareTable
166
+ };
167
+ //# sourceMappingURL=chunk-NZRUQUN5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shopper/CompareTable.tsx"],"sourcesContent":["import type { ListProduct } from '@usethrottle/catalog';\nimport { useProducts } from '@usethrottle/catalog/react';\nimport { Icon } from '@usethrottle/ui';\nimport { useMemo } from 'react';\nimport { MERCH_STALE_MS } from '../merch/use-merch';\nimport { orderByHandles } from '../merch/product-source';\nimport { usePart } from '../parts';\nimport { Image } from '../pieces/Image';\nimport { Price } from '../pieces/Price';\nimport { StarRating } from '../pieces/StarRating';\nimport { useStorefront } from '../provider/context';\nimport { useStrings } from '../strings';\nimport { routeHref } from '../url/routes';\nimport { useCompare } from './CompareButton';\nimport type { CompareProps } from './Compare';\n\ntype Local = Pick<CompareProps, 'classNames' | 'unstyled'>;\ntype Attribute = string | number | boolean;\ntype AttributeRow = { key: string; label: string };\n\n/** `water_proof` as `Water proof`: the label of an attribute the catalog gave none for. */\nconst humanise = (key: string): string => {\n const words = key.replace(/_/g, ' ').trim();\n return words.charAt(0).toUpperCase() + words.slice(1);\n};\n\n/** The attribute keys any compared product carries, in first-seen order, with a readable label. */\nfunction attributeRows(products: readonly ListProduct[]): AttributeRow[] {\n const rows = new Map<string, AttributeRow>();\n for (const product of products) {\n for (const variant of product.variants ?? []) {\n const labels = (variant as { attributeLabels?: Record<string, string> }).attributeLabels;\n for (const key of Object.keys(variant.attributes ?? {})) {\n if (!rows.has(key)) rows.set(key, { key, label: labels?.[key] ?? humanise(key) });\n }\n }\n }\n return [...rows.values()];\n}\n\n/** The values of one attribute across a product's variants, each once, in variant order. */\nfunction attributeValues(product: ListProduct, key: string, yes: string, no: string): string[] {\n const out: string[] = [];\n for (const variant of product.variants ?? []) {\n const value = (variant.attributes as Record<string, Attribute> | undefined)?.[key];\n if (value === undefined) continue;\n const text = typeof value === 'boolean' ? (value ? yes : no) : String(value);\n if (!out.includes(text)) out.push(text);\n }\n return out;\n}\n\nfunction Cell({ children, ...local }: Local & { children: React.ReactNode }) {\n const part = usePart('compare-cell', local);\n return <td {...part}>{children}</td>;\n}\n\n/** The compared products in a table. Drawn by `Compare`, which loads this file on first use. */\nexport function CompareTable(props: CompareProps) {\n const { classNames, unstyled, className } = props;\n const local = { classNames, unstyled };\n const { t } = useStrings();\n const { settings, Link: Anchor, reviewsOnLists } = useStorefront();\n const { items, toggle, clear } = useCompare();\n const ready = items.length >= 2;\n // One request for every product, with the attributes of their variants.\n const query = useProducts(\n { handles: items, limit: Math.max(1, items.length), fields: 'full' },\n { enabled: ready, staleTimeMs: MERCH_STALE_MS },\n );\n const products = useMemo(() => (ready && query.data ? orderByHandles(query.data.products, items) : []), [ready, query.data, items]);\n const rows = useMemo(() => attributeRows(products), [products]);\n\n const root = usePart('compare', { ...local, className });\n const header = usePart('compare-header', local);\n const title = usePart('compare-title', local);\n const clearPart = usePart('compare-clear', local);\n const scroll = usePart('compare-scroll', local);\n const table = usePart('compare-table', local);\n const caption = usePart('compare-caption', local);\n const row = usePart('compare-row', local);\n const label = usePart('compare-label', local);\n const product = usePart('compare-product', local);\n const media = usePart('compare-product-media', local);\n const link = usePart('compare-product-link', local);\n const remove = usePart('compare-product-remove', local);\n const empty = usePart('compare-empty', local);\n\n const heading = (\n <div {...header}>\n <h2 {...title}>{t('shopper.compare.title')}</h2>\n {items.length > 0 ? (\n <button type=\"button\" {...clearPart} onClick={clear}>\n {t('shopper.compare.clear')}\n </button>\n ) : null}\n </div>\n );\n\n if (!ready) {\n return (\n <section {...root} data-section=\"compare\" data-section-title={t('shopper.compare.title')}>\n {heading}\n <p {...empty}>{t('shopper.compare.needMore')}</p>\n </section>\n );\n }\n if (query.error && !query.data) {\n return (\n <section {...root} data-section=\"compare\" data-section-title={t('shopper.compare.title')}>\n {heading}\n <p {...empty} role=\"alert\">{t('shopper.compare.loadFailed')}</p>\n </section>\n );\n }\n if (!query.data) return null;\n if (products.length < 2) {\n // Fewer than two of the chosen handles still exist in the catalog.\n return (\n <section {...root} data-section=\"compare\" data-section-title={t('shopper.compare.title')}>\n {heading}\n <p {...empty}>{t('shopper.compare.needMore')}</p>\n </section>\n );\n }\n\n const words = settings.stock.words;\n const availability = (p: ListProduct): string =>\n p.availability === 'in_stock' ? words.inStock\n : p.availability === 'out_of_stock' ? words.outOfStock\n : p.availability === 'backorder' ? words.backorder\n : p.availability === 'preorder' ? words.preorder\n : '';\n const showRating = reviewsOnLists && settings.card.showRating && products.some((p) => p.rating && p.rating.count > 0);\n const showBrand = products.some((p) => p.brand);\n const none = t('shopper.compare.none');\n const yes = t('boolean.yes');\n const no = t('boolean.no');\n\n const labelRow = (text: string, key: string, cell: (p: ListProduct) => React.ReactNode) => (\n <tr {...row} key={key} data-compare-row={key}>\n <th {...label} scope=\"row\">{text}</th>\n {products.map((p) => (\n <Cell key={p.handle} {...local}>{cell(p)}</Cell>\n ))}\n </tr>\n );\n\n return (\n <section {...root} data-section=\"compare\" data-section-title={t('shopper.compare.title')}>\n {heading}\n <div {...scroll} tabIndex={0} role=\"region\" aria-label={t('shopper.compare.title')}>\n <table {...table}>\n <caption {...caption}>{t('shopper.compare.caption', { count: products.length })}</caption>\n <thead>\n <tr {...row}>\n <th {...label} scope=\"col\">{t('shopper.compare.spec')}</th>\n {products.map((p) => {\n const name = p.title ?? p.handle;\n const image = p.images?.[0];\n return (\n <th {...product} key={p.handle} scope=\"col\" data-compare-handle={p.handle}>\n {image ? (\n <div {...media}>\n <Image src={image.url} alt=\"\" aspectRatio={1} {...local} />\n </div>\n ) : null}\n <Anchor {...link} href={routeHref(settings, 'product', p.handle)}>{name}</Anchor>\n <button\n type=\"button\"\n {...remove}\n aria-label={t('shopper.compare.remove', { title: name })}\n onClick={() => toggle(p.handle)}\n >\n <Icon name=\"close\" size={16} />\n </button>\n </th>\n );\n })}\n </tr>\n </thead>\n <tbody>\n {labelRow(t('shopper.compare.price'), 'price', (p) =>\n p.priceRange ? (\n <Price minor={p.priceRange.minMinor} currency={p.priceRange.currency} {...local} />\n ) : (\n none\n ),\n )}\n {labelRow(t('shopper.compare.availability'), 'availability', (p) => availability(p) || none)}\n {showBrand ? labelRow(t('shopper.compare.brand'), 'brand', (p) => p.brand || none) : null}\n {showRating\n ? labelRow(t('shopper.compare.rating'), 'rating', (p) =>\n p.rating && p.rating.count > 0 && p.rating.average !== null ? (\n <StarRating value={p.rating.average} count={p.rating.count} size=\"sm\" {...local} />\n ) : (\n none\n ),\n )\n : null}\n {rows.map((r) =>\n labelRow(r.label, `attr:${r.key}`, (p) => {\n const values = attributeValues(p, r.key, yes, no);\n return values.length > 0 ? values.join(', ') : none;\n }),\n )}\n </tbody>\n </table>\n </div>\n </section>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,mBAAmB;AAC5B,SAAS,YAAY;AACrB,SAAS,eAAe;AAmDf,cAmCL,YAnCK;AAsFL;AAvHJ,IAAM,WAAW,CAAC,QAAwB;AACxC,QAAM,QAAQ,IAAI,QAAQ,MAAM,GAAG,EAAE,KAAK;AAC1C,SAAO,MAAM,OAAO,CAAC,EAAE,YAAY,IAAI,MAAM,MAAM,CAAC;AACtD;AAGA,SAAS,cAAc,UAAkD;AACvE,QAAM,OAAO,oBAAI,IAA0B;AAC3C,aAAW,WAAW,UAAU;AAC9B,eAAW,WAAW,QAAQ,YAAY,CAAC,GAAG;AAC5C,YAAM,SAAU,QAAyD;AACzE,iBAAW,OAAO,OAAO,KAAK,QAAQ,cAAc,CAAC,CAAC,GAAG;AACvD,YAAI,CAAC,KAAK,IAAI,GAAG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UAAU,EAAE,OAAO,QAAQ,KAAK,EAAE,OAAO,YAAY,OACrD,oBAAC,cAAW,OAAO,EAAE,OAAO,SAAS,OAAO,EAAE,OAAO,OAAO,MAAK,MAAM,GAAG,OAAO,IAEjF;AAAA,QAEJ,IACA;AAAA,QACH,KAAK;AAAA,UAAI,CAAC,MACT,SAAS,EAAE,OAAO,QAAQ,EAAE,GAAG,IAAI,CAAC,MAAM;AACxC,kBAAM,SAAS,gBAAgB,GAAG,EAAE,KAAK,KAAK,EAAE;AAChD,mBAAO,OAAO,SAAS,IAAI,OAAO,KAAK,IAAI,IAAI;AAAA,UACjD,CAAC;AAAA,QACH;AAAA,SACF;AAAA,OACF,GACF;AAAA,KACF;AAEJ;","names":[]}
@@ -0,0 +1,38 @@
1
+ "use client";
2
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
3
+
4
+
5
+ var _chunkVWXJO427cjs = require('./chunk-VWXJO427.cjs');
6
+
7
+ // src/pieces/Image.tsx
8
+ var _jsxruntime = require('react/jsx-runtime');
9
+ function cssAspectRatio(ratio) {
10
+ if (!Number.isFinite(ratio) || ratio <= 0) return "1 / 1";
11
+ for (let height = 1; height <= 20; height += 1) {
12
+ const width = Math.round(ratio * height);
13
+ if (width > 0 && Math.abs(width / height - ratio) < 1e-6) return `${width} / ${height}`;
14
+ }
15
+ return String(ratio);
16
+ }
17
+ function Image({ src, alt, aspectRatio, sizes, srcSet, priority, classNames, className, unstyled }) {
18
+ const part = _chunkVWXJO427cjs.usePart.call(void 0, "image", { classNames, className, unstyled });
19
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
20
+ "img",
21
+ {
22
+ ...part,
23
+ src,
24
+ alt,
25
+ srcSet,
26
+ sizes: srcSet ? sizes : void 0,
27
+ style: { aspectRatio: cssAspectRatio(aspectRatio) },
28
+ loading: priority ? "eager" : "lazy",
29
+ fetchPriority: priority ? "high" : void 0,
30
+ decoding: "async"
31
+ }
32
+ );
33
+ }
34
+
35
+
36
+
37
+ exports.Image = Image;
38
+ //# sourceMappingURL=chunk-P6HHE57S.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/chunk-P6HHE57S.cjs","../src/pieces/Image.tsx"],"names":[],"mappings":"AAAA,qFAAY;AACZ;AACE;AACF,wDAA6B;AAC7B;AACA;AC2BI,+CAAA;AAbG,SAAS,cAAA,CAAe,KAAA,EAAuB;AACpD,EAAA,GAAA,CAAI,CAAC,MAAA,CAAO,QAAA,CAAS,KAAK,EAAA,GAAK,MAAA,GAAS,CAAA,EAAG,OAAO,OAAA;AAClD,EAAA,IAAA,CAAA,IAAS,OAAA,EAAS,CAAA,EAAG,OAAA,GAAU,EAAA,EAAI,OAAA,GAAU,CAAA,EAAG;AAC9C,IAAA,MAAM,MAAA,EAAQ,IAAA,CAAK,KAAA,CAAM,MAAA,EAAQ,MAAM,CAAA;AACvC,IAAA,GAAA,CAAI,MAAA,EAAQ,EAAA,GAAK,IAAA,CAAK,GAAA,CAAI,MAAA,EAAQ,OAAA,EAAS,KAAK,EAAA,EAAI,IAAA,EAAM,OAAO,CAAA,EAAA;AACnE,EAAA;AACmB,EAAA;AACrB;AAGwE;AACL,EAAA;AAE/D,EAAA;AAAC,IAAA;AAAA,IAAA;AACK,MAAA;AACJ,MAAA;AACA,MAAA;AACA,MAAA;AACwB,MAAA;AAC0B,MAAA;AACpB,MAAA;AACK,MAAA;AAC1B,MAAA;AAAA,IAAA;AACX,EAAA;AAEJ;ADZsE;AACA;AACA;AACA","file":"/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/chunk-P6HHE57S.cjs","sourcesContent":[null,"import { usePart, type UsePartLocal } from '../parts';\n\n/** A picture that reserves its space: `aspectRatio` is required and becomes an inline `aspect-ratio`. */\nexport type ImageProps = UsePartLocal & {\n /** The image URL. */\n src: string;\n /** The alternative text. Pass an empty string for a purely decorative picture. */\n alt: string;\n /** Width over height. Space is reserved from it, so the layout does not move when the image loads. */\n aspectRatio: number;\n /** The `sizes` attribute, for a responsive `srcSet`. */\n sizes?: string;\n /** The `srcset` attribute: the same picture at several widths. */\n srcSet?: string;\n /** The largest paint of the page: loaded eagerly, fetched first. */\n priority?: boolean;\n};\n\n/** `0.8` as `\"4 / 5\"`: the ratio of the smallest whole numbers that match, else the number itself. */\nexport function cssAspectRatio(ratio: number): string {\n if (!Number.isFinite(ratio) || ratio <= 0) return '1 / 1';\n for (let height = 1; height <= 20; height += 1) {\n const width = Math.round(ratio * height);\n if (width > 0 && Math.abs(width / height - ratio) < 1e-6) return `${width} / ${height}`;\n }\n return String(ratio);\n}\n\n/** An image that always reserves its space (an inline `aspect-ratio`). */\nexport function Image({ src, alt, aspectRatio, sizes, srcSet, priority, classNames, className, unstyled }: ImageProps) {\n const part = usePart('image', { classNames, className, unstyled });\n return (\n <img\n {...part}\n src={src}\n alt={alt}\n srcSet={srcSet}\n sizes={srcSet ? sizes : undefined}\n style={{ aspectRatio: cssAspectRatio(aspectRatio) }}\n loading={priority ? 'eager' : 'lazy'}\n fetchPriority={priority ? 'high' : undefined}\n decoding=\"async\"\n />\n );\n}\n"]}
@@ -0,0 +1,197 @@
1
+ "use client";
2
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
3
+
4
+
5
+
6
+ var _chunkNDUEJJLPcjs = require('./chunk-NDUEJJLP.cjs');
7
+
8
+
9
+ var _chunkDOAII637cjs = require('./chunk-DOAII637.cjs');
10
+
11
+
12
+
13
+ var _chunkHZ6VEN6Qcjs = require('./chunk-HZ6VEN6Q.cjs');
14
+
15
+
16
+ var _chunkDYHHAOMGcjs = require('./chunk-DYHHAOMG.cjs');
17
+
18
+
19
+ var _chunkXQHGFWLGcjs = require('./chunk-XQHGFWLG.cjs');
20
+
21
+
22
+
23
+ var _chunkVWXJO427cjs = require('./chunk-VWXJO427.cjs');
24
+
25
+ // src/shopper/QuickAdd.tsx
26
+ var _react = require('@usethrottle/catalog/react');
27
+ var _react3 = require('react');
28
+ var _reactdom = require('react-dom');
29
+ var _jsxruntime = require('react/jsx-runtime');
30
+ var PANEL_GAP = 8;
31
+ var FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
32
+ function anchorFor(button, dir) {
33
+ const rect = button.getBoundingClientRect();
34
+ const below = rect.top < window.innerHeight / 2;
35
+ const inlineEnd = Math.max(PANEL_GAP, dir === "rtl" ? rect.left : window.innerWidth - rect.right);
36
+ return {
37
+ host: button.closest(".tsf-root"),
38
+ style: {
39
+ position: "fixed",
40
+ insetInlineEnd: inlineEnd,
41
+ ...below ? { insetBlockStart: rect.bottom + PANEL_GAP } : { insetBlockEnd: window.innerHeight - rect.top + PANEL_GAP },
42
+ maxBlockSize: `calc(100vh - ${2 * PANEL_GAP}px)`
43
+ }
44
+ };
45
+ }
46
+ function QuickAdd({ product, ...local }) {
47
+ const { currency, settings, dir } = _chunkVWXJO427cjs.useStorefront.call(void 0, );
48
+ const { t } = _chunkXQHGFWLGcjs.useStrings.call(void 0, );
49
+ const track = _chunkDYHHAOMGcjs.useTrack.call(void 0, );
50
+ const cart = _react.useCart.call(void 0, currency ? { currency } : void 0);
51
+ const title = _nullishCoalesce(product.title, () => ( product.handle));
52
+ const panelId = _react3.useId.call(void 0, );
53
+ const trigger = _react3.useRef.call(void 0, null);
54
+ const panelRef = _react3.useRef.call(void 0, null);
55
+ const [anchor, setAnchor] = _react3.useState.call(void 0, null);
56
+ const open = anchor !== null;
57
+ const [busy, setBusy] = _react3.useState.call(void 0, false);
58
+ const [message, setMessage] = _react3.useState.call(void 0, null);
59
+ const soldOut = product.availability === "out_of_stock";
60
+ const single = (_nullishCoalesce(product.variantCount, () => ( _optionalChain([product, 'access', _ => _.variants, 'optionalAccess', _2 => _2.length])))) === 1;
61
+ const part = _chunkVWXJO427cjs.usePart.call(void 0, "quick-add", local);
62
+ const button = _chunkVWXJO427cjs.usePart.call(void 0, "quick-add-button", local);
63
+ const panel = _chunkVWXJO427cjs.usePart.call(void 0, "quick-add-panel", local);
64
+ const heading = _chunkVWXJO427cjs.usePart.call(void 0, "quick-add-title", local);
65
+ const status = _chunkVWXJO427cjs.usePart.call(void 0, "quick-add-message", local);
66
+ const close = _react3.useCallback.call(void 0, () => {
67
+ setAnchor(null);
68
+ _optionalChain([trigger, 'access', _3 => _3.current, 'optionalAccess', _4 => _4.focus, 'call', _5 => _5()]);
69
+ }, []);
70
+ _react3.useEffect.call(void 0, () => {
71
+ if (!open) return;
72
+ const away = (event) => {
73
+ if (event.target instanceof Node && _optionalChain([panelRef, 'access', _6 => _6.current, 'optionalAccess', _7 => _7.contains, 'call', _8 => _8(event.target)])) return;
74
+ setAnchor(null);
75
+ };
76
+ const onKey = (event) => {
77
+ if (event.key === "Escape") close();
78
+ };
79
+ const onPointer = (event) => {
80
+ const target = event.target;
81
+ if (!_optionalChain([panelRef, 'access', _9 => _9.current, 'optionalAccess', _10 => _10.contains, 'call', _11 => _11(target)]) && !_optionalChain([trigger, 'access', _12 => _12.current, 'optionalAccess', _13 => _13.contains, 'call', _14 => _14(target)])) setAnchor(null);
82
+ };
83
+ _optionalChain([panelRef, 'access', _15 => _15.current, 'optionalAccess', _16 => _16.focus, 'call', _17 => _17()]);
84
+ document.addEventListener("keydown", onKey);
85
+ document.addEventListener("mousedown", onPointer);
86
+ window.addEventListener("scroll", away, true);
87
+ window.addEventListener("resize", away);
88
+ return () => {
89
+ document.removeEventListener("keydown", onKey);
90
+ document.removeEventListener("mousedown", onPointer);
91
+ window.removeEventListener("scroll", away, true);
92
+ window.removeEventListener("resize", away);
93
+ };
94
+ }, [open, close]);
95
+ const panelNode = anchor && !single ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
96
+ "div",
97
+ {
98
+ ...panel,
99
+ ref: panelRef,
100
+ id: panelId,
101
+ role: "group",
102
+ tabIndex: -1,
103
+ "aria-label": t("shopper.quickAdd.panelFor", { title }),
104
+ style: anchor.style,
105
+ onKeyDown: (event) => {
106
+ if (event.key !== "Tab") return;
107
+ const items = [...event.currentTarget.querySelectorAll(FOCUSABLE)];
108
+ const at = document.activeElement;
109
+ const leaving = event.shiftKey ? at === event.currentTarget || at === items[0] : at === items.at(-1) || items.length === 0;
110
+ if (!leaving) return;
111
+ event.preventDefault();
112
+ close();
113
+ },
114
+ children: [
115
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { ...heading, children: title }),
116
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkNDUEJJLPcjs.QuietRouter, { pathname: _chunkHZ6VEN6Qcjs.routeHref.call(void 0, settings, "product", product.handle), children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkNDUEJJLPcjs.ProductPage.Root, { handle: product.handle, ...local, children: [
117
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkNDUEJJLPcjs.ProductPage.VariantPicker, { ...local }),
118
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkNDUEJJLPcjs.ProductPage.AddToCart, { ...local })
119
+ ] }) })
120
+ ]
121
+ }
122
+ ) : null;
123
+ const [asked, setAsked] = _react3.useState.call(void 0, false);
124
+ const read = _react.useProduct.call(void 0, asked && single && !_optionalChain([product, 'access', _18 => _18.variants, 'optionalAccess', _19 => _19.length]) ? product.handle : null, { staleTimeMs: _chunkDOAII637cjs.MERCH_STALE_MS });
125
+ const readVariants = read.data && "product" in read.data ? read.data.product.variants : void 0;
126
+ const variants = _optionalChain([product, 'access', _20 => _20.variants, 'optionalAccess', _21 => _21.length]) ? product.variants : readVariants;
127
+ const add = _react3.useCallback.call(void 0,
128
+ async (sku) => {
129
+ try {
130
+ if (!sku) {
131
+ setMessage({ tone: "refused", text: t("shopper.quickAdd.unavailable") });
132
+ return;
133
+ }
134
+ await cart.add(sku, 1);
135
+ const cur = _nullishCoalesce(_optionalChain([product, 'access', _22 => _22.priceRange, 'optionalAccess', _23 => _23.currency]), () => ( currency));
136
+ if (cur) track("add_to_cart", { currency: cur, items: [{ ..._chunkHZ6VEN6Qcjs.toGa4Item.call(void 0, product, { variantSku: sku, quantity: 1 }), item_id: sku }] });
137
+ setMessage({ tone: "ok", text: t("shopper.quickAdd.added", { title }) });
138
+ } catch (error) {
139
+ if (error instanceof DOMException && error.name === "AbortError") return;
140
+ setMessage({ tone: "refused", text: t("shopper.quickAdd.failed") });
141
+ } finally {
142
+ setBusy(false);
143
+ }
144
+ },
145
+ [cart, currency, product, t, title, track]
146
+ );
147
+ const waiting = _react3.useRef.call(void 0, false);
148
+ _react3.useEffect.call(void 0, () => {
149
+ if (!waiting.current) return;
150
+ if (variants) {
151
+ waiting.current = false;
152
+ void add(_optionalChain([variants, 'access', _24 => _24[0], 'optionalAccess', _25 => _25.sku]));
153
+ } else if (read.error) {
154
+ waiting.current = false;
155
+ setMessage({ tone: "refused", text: t("shopper.quickAdd.failed") });
156
+ setBusy(false);
157
+ }
158
+ }, [variants, read.error, add, t]);
159
+ const addOne = () => {
160
+ if (busy) return;
161
+ setBusy(true);
162
+ setMessage(null);
163
+ if (variants) {
164
+ void add(_optionalChain([variants, 'access', _26 => _26[0], 'optionalAccess', _27 => _27.sku]));
165
+ } else {
166
+ waiting.current = true;
167
+ setAsked(true);
168
+ }
169
+ };
170
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { ...part, "data-quick-add": product.handle, children: [
171
+ soldOut ? null : /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
172
+ "button",
173
+ {
174
+ ...button,
175
+ ref: trigger,
176
+ type: "button",
177
+ "aria-label": t(single ? "shopper.quickAdd.buttonFor" : "shopper.quickAdd.chooseFor", { title }),
178
+ "aria-expanded": single ? void 0 : open,
179
+ "aria-controls": single || !open ? void 0 : panelId,
180
+ "aria-disabled": busy || void 0,
181
+ "data-adding": busy ? "true" : void 0,
182
+ onClick: (event) => {
183
+ if (single) addOne();
184
+ else setAnchor(open ? null : anchorFor(event.currentTarget, dir));
185
+ },
186
+ children: single ? t("shopper.quickAdd.button") : t("shopper.quickAdd.choose")
187
+ }
188
+ ),
189
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { ...status, role: "status", "aria-live": "polite", "data-tone": _optionalChain([message, 'optionalAccess', _28 => _28.tone]), children: _optionalChain([message, 'optionalAccess', _29 => _29.text]) }),
190
+ panelNode && _optionalChain([anchor, 'optionalAccess', _30 => _30.host]) ? _reactdom.createPortal.call(void 0, panelNode, anchor.host) : panelNode
191
+ ] });
192
+ }
193
+
194
+
195
+
196
+ exports.QuickAdd = QuickAdd;
197
+ //# sourceMappingURL=chunk-PHY7AY27.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/chunk-PHY7AY27.cjs","../src/shopper/QuickAdd.tsx"],"names":[],"mappings":"AAAA,6rBAAY;AACZ;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACtBA,mDAAoC;AACpC,+BAAgE;AAEhE,qCAA6B;AA8HrB,+CAAA;AA1GR,IAAM,UAAA,EAAY,CAAA;AAClB,IAAM,UAAA,EAAY,2IAAA;AAElB,SAAS,SAAA,CAAU,MAAA,EAAqB,GAAA,EAAiC;AACvE,EAAA,MA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AA,EAAA,EAAY,OAAA;AAAA,QAC7C,eAAA,EAAe,KAAA,GAAQ,KAAA,CAAA;AAAA,QACvB,aAAA,EAAa,KAAA,EAAO,OAAA,EAAS,KAAA,CAAA;AAAA,QAC7B,OAAA,EAAS,CAAC,KAAA,EAAA,GAAU;AAClB,UAAA,GAAA,CAAI,MAAA,EAAQ,MAAA,CAAO,CAAA;AAAA,UAAA,KACd,SAAA,CAAU,KAAA,EAAO,KAAA,EAAO,SAAA,CAAU,KAAA,CAAM,aAAA,EAAe,GAAG,CAAC,CAAA;AAAA,QAClE,CAAA;AAAA,QAEC,QAAA,EAAA,OAAA,EAAS,CAAA,CAAE,yBAAyB,EAAA,EAAI,CAAA,CAAE,yBAAyB;AAAA,MAAA;AAAA,IACtE,CAAA;AAAA,oBAEF,6BAAA,GAAC,EAAA,EAAG,GAAG,MAAA,EAAQ,IAAA,EAAK,QAAA,EAAS,WAAA,EAAU,QAAA,EAAS,WAAA,kBAAW,OAAA,+BAAS,MAAA,EACjE,QAAA,kBAAA,OAAA,+BAAS,OAAA,CACZ,CAAA;AAAA,IACC,UAAA,mBAAa,MAAA,+BAAQ,OAAA,EAAO,oCAAA,SAAa,EAAW,MAAA,CAAO,IAAI,EAAA,EAAI;AAAA,EAAA,EAAA,CACtE,CAAA;AAEJ;AD9BA;AACA;AACE;AACF,4BAAC","file":"/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/chunk-PHY7AY27.cjs","sourcesContent":[null,"import type { ListProduct } from '@usethrottle/catalog';\nimport { useCart, useProduct } from '@usethrottle/catalog/react';\nimport { useCallback, useEffect, useId, useRef, useState } from 'react';\nimport type { CSSProperties } from 'react';\nimport { createPortal } from 'react-dom';\nimport { toGa4Item } from '../analytics/items';\nimport { useTrack } from '../analytics/use-track';\nimport { MERCH_STALE_MS } from '../merch/use-merch';\nimport { usePart, type UsePartLocal } from '../parts';\nimport { ProductPage } from '../product';\nimport { useStorefront } from '../provider/context';\nimport { useStrings } from '../strings';\nimport { routeHref } from '../url/routes';\nimport { QuietRouter } from './quiet-router';\n\n/** The quick add button of a card: a one-click add for a product with one variant, an options panel for the rest. */\nexport type QuickAddProps = UsePartLocal & {\n /** The product the card shows. */\n product: ListProduct;\n};\n\n/** Where the options panel sits: in the storefront root (the card's picture clips whatever overflows it), by the button. */\ntype PanelAnchor = { host: HTMLElement | null; style: CSSProperties };\n\nconst PANEL_GAP = 8;\nconst FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\nfunction anchorFor(button: HTMLElement, dir: 'ltr' | 'rtl'): PanelAnchor {\n const rect = button.getBoundingClientRect();\n const below = rect.top < window.innerHeight / 2;\n const inlineEnd = Math.max(PANEL_GAP, dir === 'rtl' ? rect.left : window.innerWidth - rect.right);\n return {\n host: button.closest<HTMLElement>('.tsf-root'),\n style: {\n position: 'fixed',\n insetInlineEnd: inlineEnd,\n ...(below ? { insetBlockStart: rect.bottom + PANEL_GAP } : { insetBlockEnd: window.innerHeight - rect.top + PANEL_GAP }),\n maxBlockSize: `calc(100vh - ${2 * PANEL_GAP}px)`,\n },\n };\n}\n\n/**\n * Adds a product to the cart from its card. A product with one variant is added at once (one\n * quantity); otherwise the button opens a small panel with the product's options and its own add\n * button. The sold-out product has no quick add.\n *\n * Keyboard: opening the panel moves focus into it. Tab through its controls; Tab past the last control or\n * Shift+Tab out of the first closes the panel and returns focus to the button, so the next Tab continues\n * from the card (the panel sits at the end of the storefront root, not after the button). Escape also closes\n * it and returns focus to the button, and so does a click outside.\n */\nexport function QuickAdd({ product, ...local }: QuickAddProps) {\n const { currency, settings, dir } = useStorefront();\n const { t } = useStrings();\n const track = useTrack();\n const cart = useCart(currency ? { currency } : undefined);\n const title = product.title ?? product.handle;\n const panelId = useId();\n const trigger = useRef<HTMLButtonElement>(null);\n const panelRef = useRef<HTMLDivElement>(null);\n const [anchor, setAnchor] = useState<PanelAnchor | null>(null);\n const open = anchor !== null;\n const [busy, setBusy] = useState(false);\n const [message, setMessage] = useState<{ tone: 'ok' | 'refused'; text: string } | null>(null);\n\n const soldOut = product.availability === 'out_of_stock';\n const single = (product.variantCount ?? product.variants?.length) === 1;\n\n const part = usePart('quick-add', local);\n const button = usePart('quick-add-button', local);\n const panel = usePart('quick-add-panel', local);\n const heading = usePart('quick-add-title', local);\n const status = usePart('quick-add-message', local);\n\n const close = useCallback(() => {\n setAnchor(null);\n trigger.current?.focus();\n }, []);\n\n useEffect(() => {\n if (!open) return;\n // The panel is placed once, from the button: moving the page or the window closes it.\n const away = (event: Event) => {\n if (event.target instanceof Node && panelRef.current?.contains(event.target)) return;\n setAnchor(null);\n };\n const onKey = (event: KeyboardEvent) => {\n if (event.key === 'Escape') close();\n };\n const onPointer = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!panelRef.current?.contains(target) && !trigger.current?.contains(target)) setAnchor(null);\n };\n panelRef.current?.focus();\n document.addEventListener('keydown', onKey);\n document.addEventListener('mousedown', onPointer);\n window.addEventListener('scroll', away, true);\n window.addEventListener('resize', away);\n return () => {\n document.removeEventListener('keydown', onKey);\n document.removeEventListener('mousedown', onPointer);\n window.removeEventListener('scroll', away, true);\n window.removeEventListener('resize', away);\n };\n }, [open, close]);\n\n const panelNode =\n anchor && !single ? (\n <div\n {...panel}\n ref={panelRef}\n id={panelId}\n role=\"group\"\n tabIndex={-1}\n aria-label={t('shopper.quickAdd.panelFor', { title })}\n style={anchor.style}\n onKeyDown={(event) => {\n // The panel sits at the end of the storefront root, not after the button: leaving it either way\n // would land far from the card. Tab past its last control, or Shift+Tab out of its first, closes it\n // and returns to the button, so the next Tab continues from the card.\n if (event.key !== 'Tab') return;\n const items = [...event.currentTarget.querySelectorAll<HTMLElement>(FOCUSABLE)];\n const at = document.activeElement;\n const leaving = event.shiftKey ? at === event.currentTarget || at === items[0] : at === items.at(-1) || items.length === 0;\n if (!leaving) return;\n event.preventDefault();\n close();\n }}\n >\n <p {...heading}>{title}</p>\n <QuietRouter pathname={routeHref(settings, 'product', product.handle)}>\n <ProductPage.Root handle={product.handle} {...local}>\n <ProductPage.VariantPicker {...local} />\n <ProductPage.AddToCart {...local} />\n </ProductPage.Root>\n </QuietRouter>\n </div>\n ) : null;\n\n // A list answer names no SKU. The product is read through the hook cache, on the first click only\n // (one request, then kept for an hour like the other reads), so a second click needs no request.\n const [asked, setAsked] = useState(false);\n const read = useProduct(asked && single && !product.variants?.length ? product.handle : null, { staleTimeMs: MERCH_STALE_MS });\n const readVariants = read.data && 'product' in read.data ? read.data.product.variants : undefined;\n const variants = product.variants?.length ? product.variants : readVariants;\n\n const add = useCallback(\n async (sku: string | undefined) => {\n try {\n if (!sku) {\n setMessage({ tone: 'refused', text: t('shopper.quickAdd.unavailable') });\n return;\n }\n await cart.add(sku, 1);\n const cur = product.priceRange?.currency ?? currency;\n // A list product has no variants to price from, so the item is the product's with this variant's SKU.\n if (cur) track('add_to_cart', { currency: cur, items: [{ ...toGa4Item(product, { variantSku: sku, quantity: 1 }), item_id: sku }] });\n setMessage({ tone: 'ok', text: t('shopper.quickAdd.added', { title }) });\n } catch (error) {\n if (error instanceof DOMException && error.name === 'AbortError') return;\n setMessage({ tone: 'refused', text: t('shopper.quickAdd.failed') });\n } finally {\n setBusy(false);\n }\n },\n [cart, currency, product, t, title, track],\n );\n\n // The click that had to wait for the product finishes here.\n const waiting = useRef(false);\n useEffect(() => {\n if (!waiting.current) return;\n if (variants) {\n waiting.current = false;\n void add(variants[0]?.sku);\n } else if (read.error) {\n waiting.current = false;\n setMessage({ tone: 'refused', text: t('shopper.quickAdd.failed') });\n setBusy(false);\n }\n }, [variants, read.error, add, t]);\n\n const addOne = () => {\n if (busy) return;\n setBusy(true);\n setMessage(null);\n if (variants) {\n void add(variants[0]?.sku);\n } else {\n waiting.current = true;\n setAsked(true);\n }\n };\n\n return (\n <div {...part} data-quick-add={product.handle}>\n {soldOut ? null : (\n <button\n {...button}\n ref={trigger}\n type=\"button\"\n aria-label={t(single ? 'shopper.quickAdd.buttonFor' : 'shopper.quickAdd.chooseFor', { title })}\n aria-expanded={single ? undefined : open}\n aria-controls={single || !open ? undefined : panelId}\n aria-disabled={busy || undefined}\n data-adding={busy ? 'true' : undefined}\n onClick={(event) => {\n if (single) addOne();\n else setAnchor(open ? null : anchorFor(event.currentTarget, dir));\n }}\n >\n {single ? t('shopper.quickAdd.button') : t('shopper.quickAdd.choose')}\n </button>\n )}\n <p {...status} role=\"status\" aria-live=\"polite\" data-tone={message?.tone}>\n {message?.text}\n </p>\n {panelNode && anchor?.host ? createPortal(panelNode, anchor.host) : panelNode}\n </div>\n );\n}\n"]}