@foxy.io/elements 1.34.0-beta.3 → 1.35.0-beta.1

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 (244) hide show
  1. package/dist/cdn/foxy-access-recovery-form.js +1 -1
  2. package/dist/cdn/foxy-address-card.js +1 -1
  3. package/dist/cdn/foxy-address-form.js +1 -1
  4. package/dist/cdn/foxy-admin-subscription-card.js +1 -1
  5. package/dist/cdn/foxy-admin-subscription-form.js +1 -1
  6. package/dist/cdn/foxy-api-browser.js +1 -1
  7. package/dist/cdn/foxy-applied-coupon-code-card.js +1 -1
  8. package/dist/cdn/foxy-applied-coupon-code-form.js +1 -1
  9. package/dist/cdn/foxy-applied-tax-card.js +1 -1
  10. package/dist/cdn/foxy-attribute-card.js +1 -1
  11. package/dist/cdn/foxy-attribute-form.js +1 -1
  12. package/dist/cdn/foxy-billing-address-card.js +1 -1
  13. package/dist/cdn/foxy-cancellation-form.js +1 -1
  14. package/dist/cdn/foxy-cart-card.js +1 -1
  15. package/dist/cdn/foxy-cart-form.js +1 -1
  16. package/dist/cdn/foxy-client-card.js +1 -1
  17. package/dist/cdn/foxy-client-form.js +1 -1
  18. package/dist/cdn/foxy-collection-page.js +1 -1
  19. package/dist/cdn/foxy-collection-pages.js +1 -1
  20. package/dist/cdn/foxy-copy-to-clipboard.js +1 -1
  21. package/dist/cdn/foxy-coupon-card.js +1 -1
  22. package/dist/cdn/foxy-coupon-code-card.js +1 -1
  23. package/dist/cdn/foxy-coupon-code-form.js +1 -1
  24. package/dist/cdn/foxy-coupon-codes-form.js +1 -1
  25. package/dist/cdn/foxy-coupon-detail-card.js +1 -1
  26. package/dist/cdn/foxy-coupon-form.js +1 -1
  27. package/dist/cdn/foxy-custom-field-card.js +1 -1
  28. package/dist/cdn/foxy-custom-field-form.js +1 -1
  29. package/dist/cdn/foxy-customer-card.js +1 -1
  30. package/dist/cdn/foxy-customer-form.js +1 -1
  31. package/dist/cdn/foxy-customer-portal-settings-form.js +1 -1
  32. package/dist/cdn/foxy-customer-portal-settings.js +1 -1
  33. package/dist/cdn/foxy-customer-portal.js +1 -1
  34. package/dist/cdn/foxy-customer.js +1 -1
  35. package/dist/cdn/foxy-customers-table.js +1 -1
  36. package/dist/cdn/foxy-discount-builder.js +1 -1
  37. package/dist/cdn/foxy-discount-card.js +1 -1
  38. package/dist/cdn/foxy-discount-detail-card.js +1 -1
  39. package/dist/cdn/foxy-donation.js +1 -1
  40. package/dist/cdn/foxy-downloadable-card.js +1 -1
  41. package/dist/cdn/foxy-downloadable-form.js +1 -1
  42. package/dist/cdn/foxy-email-template-card.js +1 -1
  43. package/dist/cdn/foxy-email-template-form.js +1 -1
  44. package/dist/cdn/foxy-error-entry-card.js +1 -1
  45. package/dist/cdn/foxy-experimental-add-to-cart-builder.js +1 -0
  46. package/dist/cdn/foxy-filter-attribute-card.js +1 -1
  47. package/dist/cdn/foxy-filter-attribute-form.js +1 -1
  48. package/dist/cdn/foxy-form-dialog.js +1 -1
  49. package/dist/cdn/foxy-generate-codes-form.js +1 -1
  50. package/dist/cdn/foxy-gift-card-card.js +1 -1
  51. package/dist/cdn/foxy-gift-card-code-card.js +1 -1
  52. package/dist/cdn/foxy-gift-card-code-form.js +1 -1
  53. package/dist/cdn/foxy-gift-card-code-log-card.js +1 -1
  54. package/dist/cdn/foxy-gift-card-codes-form.js +1 -1
  55. package/dist/cdn/foxy-gift-card-form.js +1 -1
  56. package/dist/cdn/foxy-i18n-editor.js +1 -1
  57. package/dist/cdn/foxy-i18n.js +1 -1
  58. package/dist/cdn/foxy-integration-card.js +1 -1
  59. package/dist/cdn/foxy-integration-form.js +1 -1
  60. package/dist/cdn/foxy-item-card.js +1 -1
  61. package/dist/cdn/foxy-item-category-card.js +1 -1
  62. package/dist/cdn/foxy-item-category-form.js +1 -1
  63. package/dist/cdn/foxy-item-form.js +1 -1
  64. package/dist/cdn/foxy-item-option-card.js +1 -1
  65. package/dist/cdn/foxy-item-option-form.js +1 -1
  66. package/dist/cdn/foxy-items-form.js +1 -1
  67. package/dist/cdn/foxy-native-integration-card.js +1 -1
  68. package/dist/cdn/foxy-native-integration-form.js +1 -1
  69. package/dist/cdn/foxy-nucleon-element.js +1 -1
  70. package/dist/cdn/foxy-pagination.js +1 -1
  71. package/dist/cdn/foxy-passkey-card.js +1 -1
  72. package/dist/cdn/foxy-passkey-form.js +1 -1
  73. package/dist/cdn/foxy-payment-card-embed.js +1 -1
  74. package/dist/cdn/foxy-payment-card.js +1 -1
  75. package/dist/cdn/foxy-payment-method-card.js +1 -1
  76. package/dist/cdn/foxy-payments-api-fraud-protection-card.js +1 -1
  77. package/dist/cdn/foxy-payments-api-fraud-protection-form.js +1 -1
  78. package/dist/cdn/foxy-payments-api-payment-method-card.js +1 -1
  79. package/dist/cdn/foxy-payments-api-payment-method-form.js +1 -1
  80. package/dist/cdn/foxy-payments-api-payment-preset-card.js +1 -1
  81. package/dist/cdn/foxy-payments-api-payment-preset-form.js +1 -1
  82. package/dist/cdn/foxy-payments-api.js +1 -1
  83. package/dist/cdn/foxy-query-builder.js +1 -1
  84. package/dist/cdn/foxy-report-form.js +1 -1
  85. package/dist/cdn/foxy-reports-table.js +1 -1
  86. package/dist/cdn/foxy-shipment-card.js +1 -1
  87. package/dist/cdn/foxy-shipping-container-card.js +1 -1
  88. package/dist/cdn/foxy-shipping-drop-type-card.js +1 -1
  89. package/dist/cdn/foxy-shipping-method-card.js +1 -1
  90. package/dist/cdn/foxy-shipping-service-card.js +1 -1
  91. package/dist/cdn/foxy-sign-in-form.js +1 -1
  92. package/dist/cdn/foxy-spinner.js +2 -2
  93. package/dist/cdn/foxy-store-card.js +1 -1
  94. package/dist/cdn/foxy-store-form.js +1 -1
  95. package/dist/cdn/foxy-store-shipping-method-form.js +1 -1
  96. package/dist/cdn/foxy-subscription-card.js +1 -1
  97. package/dist/cdn/foxy-subscription-form.js +1 -1
  98. package/dist/cdn/foxy-subscription-settings-form.js +1 -1
  99. package/dist/cdn/foxy-subscriptions-table.js +1 -1
  100. package/dist/cdn/foxy-table.js +1 -1
  101. package/dist/cdn/foxy-tax-card.js +1 -1
  102. package/dist/cdn/foxy-tax-form.js +1 -1
  103. package/dist/cdn/foxy-template-config-form.js +1 -1
  104. package/dist/cdn/foxy-template-form.js +1 -1
  105. package/dist/cdn/foxy-template-set-card.js +1 -1
  106. package/dist/cdn/foxy-template-set-form.js +1 -1
  107. package/dist/cdn/foxy-transaction-card.js +1 -1
  108. package/dist/cdn/foxy-transaction.js +1 -1
  109. package/dist/cdn/foxy-transactions-table.js +7 -7
  110. package/dist/cdn/foxy-update-payment-method-form.js +1 -1
  111. package/dist/cdn/foxy-user-card.js +1 -1
  112. package/dist/cdn/foxy-user-form.js +1 -1
  113. package/dist/cdn/foxy-user-invitation-card.js +1 -1
  114. package/dist/cdn/foxy-user-invitation-form.js +1 -1
  115. package/dist/cdn/foxy-users-table.js +1 -1
  116. package/dist/cdn/foxy-webhook-card.js +1 -1
  117. package/dist/cdn/foxy-webhook-form.js +1 -1
  118. package/dist/cdn/foxy-webhook-log-card.js +1 -1
  119. package/dist/cdn/foxy-webhook-status-card.js +1 -1
  120. package/dist/cdn/{shared-126cb82b.js → shared-018166d0.js} +1 -1
  121. package/dist/cdn/{shared-8e73014c.js → shared-01f85a69.js} +1 -1
  122. package/dist/cdn/{shared-e9e2fd3f.js → shared-066fb69f.js} +1 -1
  123. package/dist/cdn/{shared-1b5f155f.js → shared-0ae33cf9.js} +1 -1
  124. package/dist/cdn/{shared-d735fc99.js → shared-0e2a0b21.js} +1 -1
  125. package/dist/cdn/{shared-4f216dc1.js → shared-112e521b.js} +1 -1
  126. package/dist/cdn/shared-19cd0786.js +1 -0
  127. package/dist/cdn/{shared-6cf39826.js → shared-1c4ddc9b.js} +1 -1
  128. package/dist/cdn/{shared-f8252d03.js → shared-238d397f.js} +1 -1
  129. package/dist/cdn/{shared-370be17b.js → shared-257389e5.js} +4 -4
  130. package/dist/cdn/{shared-a86480c5.js → shared-27e2e59a.js} +1 -1
  131. package/dist/cdn/{shared-527eb17e.js → shared-28b0e29a.js} +1 -1
  132. package/dist/cdn/{shared-869ed25d.js → shared-297e8531.js} +1 -1
  133. package/dist/cdn/{shared-e8df4368.js → shared-2cb3cb3a.js} +1 -1
  134. package/dist/cdn/{shared-851b96ae.js → shared-2f02918d.js} +1 -1
  135. package/dist/cdn/{shared-fceaef95.js → shared-31d8e958.js} +1 -1
  136. package/dist/cdn/{shared-bbd2a4e6.js → shared-32440b17.js} +1 -1
  137. package/dist/cdn/{shared-5245b330.js → shared-363dce45.js} +1 -1
  138. package/dist/cdn/{shared-b62fb09f.js → shared-3713f047.js} +1 -1
  139. package/dist/cdn/shared-44fd89ce.js +1 -0
  140. package/dist/cdn/{shared-e0b00e0f.js → shared-4c4b87c2.js} +1 -1
  141. package/dist/cdn/{shared-3efc6649.js → shared-504f3c65.js} +1 -1
  142. package/dist/cdn/{shared-a34983ea.js → shared-51fd39fa.js} +1 -1
  143. package/dist/cdn/{shared-f57e1679.js → shared-525c1936.js} +1 -1
  144. package/dist/cdn/{shared-16766722.js → shared-53caa399.js} +1 -1
  145. package/dist/cdn/{shared-e6379bd1.js → shared-573d6e21.js} +1 -1
  146. package/dist/cdn/{shared-ae68261f.js → shared-57a98543.js} +1 -1
  147. package/dist/cdn/{shared-3e25035f.js → shared-5d308dd7.js} +1 -1
  148. package/dist/cdn/{shared-e766f6e0.js → shared-5e0b71a2.js} +1 -1
  149. package/dist/cdn/shared-67898669.js +1 -0
  150. package/dist/cdn/{shared-1838736d.js → shared-68fdcf24.js} +1 -1
  151. package/dist/cdn/{shared-f378fe25.js → shared-6de0e9f3.js} +1 -1
  152. package/dist/cdn/{shared-d806ec21.js → shared-70487b4c.js} +1 -1
  153. package/dist/cdn/{shared-7cfd461d.js → shared-7889f2f2.js} +1 -1
  154. package/dist/cdn/{shared-a83e33cd.js → shared-80688cd4.js} +1 -1
  155. package/dist/cdn/{shared-9e9bec09.js → shared-80a7903f.js} +1 -1
  156. package/dist/cdn/{shared-74d9b3d4.js → shared-84761b5b.js} +1 -1
  157. package/dist/cdn/{shared-0db6454a.js → shared-8af5a4f2.js} +1 -1
  158. package/dist/cdn/{shared-1df36027.js → shared-8b838d83.js} +1 -1
  159. package/dist/cdn/{shared-6c4a5133.js → shared-95a7dab8.js} +1 -1
  160. package/dist/cdn/{shared-c176c4fa.js → shared-96886940.js} +1 -1
  161. package/dist/cdn/{shared-6a63a308.js → shared-9f97643d.js} +1 -1
  162. package/dist/cdn/{shared-9421c0d7.js → shared-9fcd36e5.js} +1 -1
  163. package/dist/cdn/{shared-6cf0c762.js → shared-a585bfd3.js} +1 -1
  164. package/dist/cdn/shared-a7617e76.js +1 -0
  165. package/dist/cdn/{shared-0d0fe9c0.js → shared-ab26c69f.js} +1 -1
  166. package/dist/cdn/{shared-46de2ed2.js → shared-b04e9753.js} +1 -1
  167. package/dist/cdn/{shared-a4953186.js → shared-b0d76785.js} +1 -1
  168. package/dist/cdn/{shared-a24264e6.js → shared-b16829cd.js} +1 -1
  169. package/dist/cdn/{shared-7e1768cf.js → shared-b1fa0b61.js} +1 -1
  170. package/dist/cdn/{shared-85803aca.js → shared-b77e1a8a.js} +1 -1
  171. package/dist/cdn/{shared-e8b8c8d0.js → shared-bb3c9e23.js} +1 -1
  172. package/dist/cdn/{shared-7d234de2.js → shared-c5326ab8.js} +1 -1
  173. package/dist/cdn/{shared-921e3f1e.js → shared-c532d615.js} +1 -1
  174. package/dist/cdn/{shared-c1f4a6ef.js → shared-c5cb7e8a.js} +1 -1
  175. package/dist/cdn/{shared-2b6b735d.js → shared-c7740aa2.js} +1 -1
  176. package/dist/cdn/{shared-e7069b0f.js → shared-ce055dce.js} +1 -1
  177. package/dist/cdn/{shared-dbc9aff0.js → shared-cf0ca582.js} +1 -1
  178. package/dist/cdn/{shared-bec65d6d.js → shared-d3a5cb85.js} +2 -2
  179. package/dist/cdn/{shared-23aa2506.js → shared-d973155b.js} +1 -1
  180. package/dist/cdn/{shared-4e6c65e6.js → shared-da393323.js} +1 -1
  181. package/dist/cdn/{shared-0293eba8.js → shared-e77d8d01.js} +1 -1
  182. package/dist/cdn/{shared-2fd6e530.js → shared-eadddff6.js} +1 -1
  183. package/dist/cdn/{shared-51fd3fc6.js → shared-eb7bf7ba.js} +1 -1
  184. package/dist/cdn/{shared-7040eef3.js → shared-ebc72d69.js} +1 -1
  185. package/dist/cdn/{shared-9c479921.js → shared-ec5b614e.js} +1 -1
  186. package/dist/cdn/{shared-a7524277.js → shared-fc6bcfc5.js} +1 -1
  187. package/dist/cdn/{shared-2ddb119e.js → shared-ffc84c84.js} +1 -1
  188. package/dist/cdn/translations/experimental-add-to-cart-builder/en.json +545 -0
  189. package/dist/elements/internal/InternalEditableControl/InternalEditableControl.js +21 -6
  190. package/dist/elements/internal/InternalEditableControl/InternalEditableControl.js.map +1 -1
  191. package/dist/elements/internal/InternalSummaryControl/InternalSummaryControl.d.ts +5 -2
  192. package/dist/elements/internal/InternalSummaryControl/InternalSummaryControl.js +60 -0
  193. package/dist/elements/internal/InternalSummaryControl/InternalSummaryControl.js.map +1 -1
  194. package/dist/elements/public/ExperimentalAddToCartBuilder/ExperimentalAddToCartBuilder.d.ts +46 -0
  195. package/dist/elements/public/ExperimentalAddToCartBuilder/ExperimentalAddToCartBuilder.js +810 -0
  196. package/dist/elements/public/ExperimentalAddToCartBuilder/ExperimentalAddToCartBuilder.js.map +1 -0
  197. package/dist/elements/public/ExperimentalAddToCartBuilder/index.d.ts +14 -0
  198. package/dist/elements/public/ExperimentalAddToCartBuilder/index.js +16 -0
  199. package/dist/elements/public/ExperimentalAddToCartBuilder/index.js.map +1 -0
  200. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionCard/InternalExperimentalAddToCartBuilderCustomOptionCard.d.ts +6 -0
  201. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionCard/InternalExperimentalAddToCartBuilderCustomOptionCard.js +14 -0
  202. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionCard/InternalExperimentalAddToCartBuilderCustomOptionCard.js.map +1 -0
  203. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionCard/index.d.ts +3 -0
  204. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionCard/index.js +5 -0
  205. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionCard/index.js.map +1 -0
  206. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionCard/types.d.ts +11 -0
  207. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionCard/types.js +2 -0
  208. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionCard/types.js.map +1 -0
  209. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionForm/InternalExperimentalAddToCartBuilderCustomOptionForm.d.ts +20 -0
  210. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionForm/InternalExperimentalAddToCartBuilderCustomOptionForm.js +122 -0
  211. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionForm/InternalExperimentalAddToCartBuilderCustomOptionForm.js.map +1 -0
  212. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionForm/index.d.ts +9 -0
  213. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionForm/index.js +11 -0
  214. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionForm/index.js.map +1 -0
  215. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionForm/types.d.ts +11 -0
  216. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionForm/types.js +2 -0
  217. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderCustomOptionForm/types.js.map +1 -0
  218. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderItemControl/InternalExperimentalAddToCartBuilderItemControl.d.ts +11 -0
  219. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderItemControl/InternalExperimentalAddToCartBuilderItemControl.js +379 -0
  220. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderItemControl/InternalExperimentalAddToCartBuilderItemControl.js.map +1 -0
  221. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderItemControl/index.d.ts +19 -0
  222. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderItemControl/index.js +21 -0
  223. package/dist/elements/public/ExperimentalAddToCartBuilder/internal/InternalExperimentalAddToCartBuilderItemControl/index.js.map +1 -0
  224. package/dist/elements/public/ExperimentalAddToCartBuilder/preview.css.d.ts +2 -0
  225. package/dist/elements/public/ExperimentalAddToCartBuilder/preview.css.js +153 -0
  226. package/dist/elements/public/ExperimentalAddToCartBuilder/preview.css.js.map +1 -0
  227. package/dist/elements/public/ExperimentalAddToCartBuilder/types.d.ts +56 -0
  228. package/dist/elements/public/ExperimentalAddToCartBuilder/types.js +2 -0
  229. package/dist/elements/public/ExperimentalAddToCartBuilder/types.js.map +1 -0
  230. package/dist/elements/public/NucleonElement/API.js +3 -1
  231. package/dist/elements/public/NucleonElement/API.js.map +1 -1
  232. package/dist/elements/public/index.d.ts +1 -0
  233. package/dist/elements/public/index.defined.d.ts +1 -0
  234. package/dist/elements/public/index.defined.js +1 -0
  235. package/dist/elements/public/index.defined.js.map +1 -1
  236. package/dist/elements/public/index.js +1 -0
  237. package/dist/elements/public/index.js.map +1 -1
  238. package/dist/mixins/themeable.js +32 -0
  239. package/dist/mixins/themeable.js.map +1 -1
  240. package/package.json +1 -1
  241. package/dist/cdn/shared-0fe1dd67.js +0 -1
  242. package/dist/cdn/shared-41072bad.js +0 -1
  243. package/dist/cdn/shared-88bfb7f5.js +0 -1
  244. package/dist/cdn/shared-c518ece2.js +0 -1
@@ -0,0 +1,810 @@
1
+ import { TranslatableMixin } from "../../../mixins/translatable.js";
2
+ import { ResponsiveMixin } from "../../../mixins/responsive.js";
3
+ import { decode, encode } from 'html-entities';
4
+ import { InternalForm } from "../../internal/InternalForm/InternalForm.js";
5
+ import { previewCSS } from './preview.css';
6
+ import { html, svg } from 'lit-element';
7
+ import { ifDefined } from 'lit-html/directives/if-defined';
8
+ import { classMap } from "../../../utils/class-map.js";
9
+ import debounce from 'lodash-es/debounce';
10
+ const NS = 'experimental-add-to-cart-builder';
11
+ const Base = ResponsiveMixin(TranslatableMixin(InternalForm, NS));
12
+ /**
13
+ * WARNING: this element is marked as experimental and is subject to change in future releases.
14
+ * We will not be maintaining backwards compatibility for elements in the experimental namespace.
15
+ * If you are using this element, please make sure to use a fixed version of the package in your `package.json`.
16
+ *
17
+ * This element allows you to create an add-to-cart form and link for your store.
18
+ *
19
+ * @element foxy-experimental-add-to-cart-builder
20
+ */
21
+ export class ExperimentalAddToCartBuilder extends Base {
22
+ constructor() {
23
+ super(...arguments);
24
+ /** Default host domain for stores that don't use a custom domain name, e.g. `foxycart.com`. */
25
+ this.defaultDomain = null;
26
+ /** URL of the HMAC encoder endpoint. */
27
+ this.encodeHelper = null;
28
+ /** URL of the `fx:locale_codes` property helper. This will be used to determine the currency code. */
29
+ this.localeCodes = null;
30
+ /** URL of the store this add-to-cart code is created for. */
31
+ this.store = null;
32
+ this.__signingSeparator = `--${Date.now()}${(Math.random() * 100000).toFixed(0)}--`;
33
+ this.__signAsync = debounce(async (html, encodeHelper) => {
34
+ if (html === this.__previousUnsignedCode && this.__previousSignedCode)
35
+ return;
36
+ const isCancelled = () => html !== this.__previousUnsignedCode;
37
+ this.__signingState = 'busy';
38
+ try {
39
+ const res = await new ExperimentalAddToCartBuilder.API(this).fetch(encodeHelper, {
40
+ headers: { 'Content-Type': 'text/plain' },
41
+ method: 'POST',
42
+ body: html,
43
+ });
44
+ if (!isCancelled()) {
45
+ if (res.ok) {
46
+ const result = (await res.json()).result;
47
+ if (!isCancelled()) {
48
+ this.__signingState = 'idle';
49
+ this.__previousSignedCode = result.replace(/value="--OPEN--" data-replace/gi, 'value');
50
+ }
51
+ }
52
+ else {
53
+ this.__signingState = 'fail';
54
+ }
55
+ }
56
+ }
57
+ catch (_a) {
58
+ if (!isCancelled())
59
+ this.__signingState = 'fail';
60
+ }
61
+ }, 500);
62
+ this.__previousUnsignedCode = '';
63
+ this.__previousSignedCode = '';
64
+ this.__signingState = 'idle';
65
+ this.__openState = [];
66
+ }
67
+ static get properties() {
68
+ return {
69
+ ...super.properties,
70
+ defaultDomain: { attribute: 'default-domain' },
71
+ encodeHelper: { attribute: 'encode-helper' },
72
+ localeCodes: { attribute: 'locale-codes' },
73
+ store: {},
74
+ __previousUnsignedCode: { attribute: false },
75
+ __previousSignedCode: { attribute: false },
76
+ __signingState: { attribute: false },
77
+ __openState: { attribute: false },
78
+ };
79
+ }
80
+ renderBody() {
81
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
82
+ const addToCartCode = this.__getAddToCartCode();
83
+ const storeUrl = (_c = (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a._links['fx:store'].href) !== null && _b !== void 0 ? _b : this.store) !== null && _c !== void 0 ? _c : void 0;
84
+ const store = (_d = this.__storeLoader) === null || _d === void 0 ? void 0 : _d.data;
85
+ return html `
86
+ <div class="grid gap-m items-start sm-grid-cols-2 md-grid-cols-3 h-full overflow-auto">
87
+ <div class="space-y-m">
88
+ ${(_e = this.form.items) === null || _e === void 0 ? void 0 : _e.map((product, index) => {
89
+ var _a;
90
+ return html `
91
+ <foxy-internal-summary-control
92
+ layout="details"
93
+ label=${ifDefined(product.name.trim() || void 0)}
94
+ infer="item"
95
+ ?open=${ifDefined(this.__openState[index])}
96
+ @toggle=${(evt) => {
97
+ const details = evt.currentTarget;
98
+ this.__openState[index] = details.open;
99
+ this.__openState = [...this.__openState];
100
+ }}
101
+ >
102
+ <foxy-internal-experimental-add-to-cart-builder-item-control
103
+ item-categories=${ifDefined(store === null || store === void 0 ? void 0 : store._links['fx:item_categories'].href)}
104
+ currency-code=${ifDefined((_a = this.__resolvedCurrencyCode) !== null && _a !== void 0 ? _a : void 0)}
105
+ store=${ifDefined(storeUrl)}
106
+ index=${index}
107
+ infer=""
108
+ @remove=${() => {
109
+ var _a;
110
+ const newProducts = (_a = this.form.items) === null || _a === void 0 ? void 0 : _a.filter((_, i) => i !== index);
111
+ this.edit({ items: newProducts });
112
+ this.__openState = this.__openState.filter((_, i) => i !== index);
113
+ }}
114
+ >
115
+ </foxy-internal-experimental-add-to-cart-builder-item-control>
116
+ </foxy-internal-summary-control>
117
+ `;
118
+ })}
119
+
120
+ <vaadin-button
121
+ class="w-full"
122
+ ?disabled=${this.disabled}
123
+ @click=${() => {
124
+ var _a;
125
+ const newItem = { name: '', price: 0, custom_options: [] };
126
+ const existingItems = (_a = this.form.items) !== null && _a !== void 0 ? _a : [];
127
+ this.edit({ items: [...existingItems, newItem] });
128
+ this.__openState = [...new Array(existingItems.length).fill(false), true];
129
+ }}
130
+ >
131
+ <foxy-i18n infer="add-product" key="caption"></foxy-i18n>
132
+ </vaadin-button>
133
+ </div>
134
+
135
+ <div class="space-y-m md-col-span-2 sticky top-0">
136
+ ${addToCartCode
137
+ ? html `
138
+ <foxy-internal-summary-control infer="preview">
139
+ <div class="flex">
140
+ <iframe
141
+ srcdoc="${previewCSS}${addToCartCode.formHTML}"
142
+ style="margin: calc(-1 * (0.625em + (var(--lumo-border-radius) / 4) - 1px))"
143
+ class=${classMap({
144
+ 'flex-1 transition-all filter': true,
145
+ 'blur-sm': this.__signingState !== 'idle',
146
+ })}
147
+ @load=${(evt) => {
148
+ var _a;
149
+ const iframe = evt.currentTarget;
150
+ const root = (_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.document.documentElement;
151
+ if (root)
152
+ iframe.style.height = root.scrollHeight + 'px';
153
+ }}
154
+ >
155
+ </iframe>
156
+ </div>
157
+
158
+ <div
159
+ class="flex leading-s text-s min-w-0 relative"
160
+ style="gap: calc(0.625em + (var(--lumo-border-radius) / 4) - 1px)"
161
+ >
162
+ <div
163
+ style="font-family: monospace; max-height: calc(8 * (1em * var(--lumo-line-height-s)))"
164
+ class=${classMap({
165
+ 'break-all overflow-auto flex-1 min-w-0 transition-all filter': true,
166
+ 'blur-sm': this.__signingState !== 'idle',
167
+ })}
168
+ >
169
+ <code class="whitespace-pre">${addToCartCode.formHTML}</code>
170
+ </div>
171
+
172
+ <div
173
+ style="top: calc(0.625em + (var(--lumo-border-radius) / 4) - 1px); right: calc(0.625em + (var(--lumo-border-radius) / 4) - 1px)"
174
+ class=${classMap({
175
+ 'absolute right-0 bg-base rounded-s transition-opacity': true,
176
+ 'opacity-0 pointer-events-none': this.__signingState !== 'busy',
177
+ })}
178
+ >
179
+ <div class="bg-contrast-10 rounded-s">
180
+ <foxy-spinner infer="spinner" class="-mx-xs" style="transform: scale(0.8)">
181
+ </foxy-spinner>
182
+ </div>
183
+ </div>
184
+
185
+ <foxy-copy-to-clipboard
186
+ infer="copy-to-clipboard"
187
+ text=${addToCartCode.formHTML}
188
+ class=${classMap({
189
+ 'flex-shrink-0 text-m transition-opacity': true,
190
+ 'opacity-0 pointer-events-none': this.__signingState === 'busy',
191
+ })}
192
+ >
193
+ </foxy-copy-to-clipboard>
194
+ </div>
195
+
196
+ <div
197
+ class="flex items-start text-xs leading-xs text-secondary"
198
+ style="gap: calc(0.625em + (var(--lumo-border-radius) / 4) - 1px)"
199
+ >
200
+ ${svg `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true" class="flex-shrink-0 text-contrast-70" style="width: 1.25em"><path fill-rule="evenodd" d="M15 8A7 7 0 1 1 1 8a7 7 0 0 1 14 0ZM9 5a1 1 0 1 1-2 0 1 1 0 0 1 2 0ZM6.75 8a.75.75 0 0 0 0 1.5h.75v1.75a.75.75 0 0 0 1.5 0v-2.5A.75.75 0 0 0 8.25 8h-1.5Z" clip-rule="evenodd" /></svg>`}
201
+ <p>
202
+ <foxy-i18n infer="" key="edits_tip"></foxy-i18n>
203
+ <a
204
+ target="_blank"
205
+ class="rounded font-medium underline transition-colors cursor-pointer hover-opacity-80 focus-outline-none focus-ring-2 focus-ring-primary-50"
206
+ href="https://wiki.foxycart.com/v/2.0/products"
207
+ >
208
+ <foxy-i18n infer="" key="edits_docs"></foxy-i18n>
209
+ </a>
210
+ </p>
211
+ </div>
212
+ </foxy-internal-summary-control>
213
+
214
+ <foxy-internal-summary-control infer="link">
215
+ <div
216
+ class="flex items-center leading-s min-w-0 relative"
217
+ style="gap: calc(0.625em + (var(--lumo-border-radius) / 4) - 1px)"
218
+ >
219
+ <foxy-i18n infer="" key="direct_link"></foxy-i18n>
220
+
221
+ <a
222
+ target="_blank"
223
+ style="max-width: 30rem"
224
+ href=${addToCartCode.linkHref}
225
+ class=${classMap({
226
+ 'font-medium truncate ml-auto min-w-0 rounded-s': true,
227
+ 'transition-all filter': true,
228
+ 'hover-underline': true,
229
+ 'focus-outline-none focus-ring-2 focus-ring-primary-50': true,
230
+ 'blur-sm': this.__signingState !== 'idle',
231
+ })}
232
+ >
233
+ ${addToCartCode.linkHref}
234
+ </a>
235
+
236
+ <div
237
+ style="top: calc(0.625em + (var(--lumo-border-radius) / 4) - 1px); right: calc(0.625em + (var(--lumo-border-radius) / 4) - 1px)"
238
+ class=${classMap({
239
+ 'absolute right-0 bg-base rounded-s transition-opacity': true,
240
+ 'opacity-0 pointer-events-none': this.__signingState !== 'busy',
241
+ })}
242
+ >
243
+ <div class="bg-contrast-10 rounded-s">
244
+ <foxy-spinner
245
+ infer="spinner"
246
+ state=${this.__signingState === 'fail' ? 'error' : 'busy'}
247
+ class="-mx-xs"
248
+ style="transform: scale(0.8)"
249
+ >
250
+ </foxy-spinner>
251
+ </div>
252
+ </div>
253
+
254
+ <foxy-copy-to-clipboard
255
+ infer="copy-to-clipboard"
256
+ text=${addToCartCode.linkHref}
257
+ class=${classMap({
258
+ 'flex-shrink-0 text-m transition-opacity': true,
259
+ 'opacity-0 pointer-events-none': this.__signingState === 'busy',
260
+ })}
261
+ >
262
+ </foxy-copy-to-clipboard>
263
+ </div>
264
+ </foxy-internal-summary-control>
265
+ `
266
+ : html `
267
+ <foxy-internal-summary-control infer="preview">
268
+ <div class="flex items-center justify-center p-xl">
269
+ <foxy-spinner infer="unavailable" state="empty"></foxy-spinner>
270
+ </div>
271
+ </foxy-internal-summary-control>
272
+ `}
273
+
274
+ <foxy-internal-summary-control infer="cart-settings-group">
275
+ <foxy-internal-resource-picker-control
276
+ layout="summary-item"
277
+ first=${ifDefined((_g = (_f = this.__storeLoader) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g._links['fx:template_sets'].href)}
278
+ infer="template-set-uri"
279
+ item="foxy-template-set-card"
280
+ >
281
+ </foxy-internal-resource-picker-control>
282
+
283
+ <foxy-internal-select-control
284
+ layout="summary-item"
285
+ infer="empty"
286
+ .options=${[
287
+ { label: 'option_false', value: 'false' },
288
+ { label: 'option_true', value: 'true' },
289
+ { label: 'option_reset', value: 'reset' },
290
+ ]}
291
+ >
292
+ </foxy-internal-select-control>
293
+
294
+ <foxy-internal-switch-control
295
+ false-alias="add"
296
+ true-alias="checkout"
297
+ layout="summary-item"
298
+ infer="cart"
299
+ >
300
+ </foxy-internal-switch-control>
301
+ </foxy-internal-summary-control>
302
+ </div>
303
+ </div>
304
+
305
+ <foxy-nucleon
306
+ class="hidden"
307
+ infer=""
308
+ href=${ifDefined(this.__defaultTemplateSetHref)}
309
+ id="defaultTemplateSetLoader"
310
+ @update=${() => this.requestUpdate()}
311
+ >
312
+ </foxy-nucleon>
313
+
314
+ <foxy-nucleon
315
+ class="hidden"
316
+ infer=""
317
+ href=${ifDefined(this.localeCodes)}
318
+ id="localeCodesHelperLoader"
319
+ @update=${() => this.requestUpdate()}
320
+ >
321
+ </foxy-nucleon>
322
+
323
+ <foxy-nucleon
324
+ class="hidden"
325
+ infer=""
326
+ href=${ifDefined((_h = this.form.template_set_uri) !== null && _h !== void 0 ? _h : void 0)}
327
+ id="templateSetLoader"
328
+ @update=${() => this.requestUpdate()}
329
+ >
330
+ </foxy-nucleon>
331
+
332
+ <foxy-nucleon
333
+ class="hidden"
334
+ infer=""
335
+ href=${ifDefined((_l = (_k = (_j = this.data) === null || _j === void 0 ? void 0 : _j._links['fx:store'].href) !== null && _k !== void 0 ? _k : this.store) !== null && _l !== void 0 ? _l : void 0)}
336
+ id="storeLoaderId"
337
+ @update=${() => this.requestUpdate()}
338
+ >
339
+ </foxy-nucleon>
340
+
341
+ ${(_m = this.form.items) === null || _m === void 0 ? void 0 : _m.map((product, index) => {
342
+ return html `
343
+ <foxy-nucleon
344
+ class="hidden"
345
+ infer=""
346
+ href=${ifDefined(product.item_category_uri)}
347
+ id="itemCategoryLoaderProduct${index}"
348
+ @update=${() => this.requestUpdate()}
349
+ >
350
+ </foxy-nucleon>
351
+
352
+ ${product.custom_options.map((option, i) => {
353
+ return html `
354
+ <foxy-nucleon
355
+ class="hidden"
356
+ infer=""
357
+ href=${ifDefined(option.item_category_uri)}
358
+ id="itemCategoryLoaderProduct${index}Option${i}"
359
+ @update=${() => this.requestUpdate()}
360
+ >
361
+ </foxy-nucleon>
362
+ `;
363
+ })}
364
+ `;
365
+ })}
366
+ `;
367
+ }
368
+ updated(changes) {
369
+ var _a, _b;
370
+ super.updated(changes);
371
+ if (this.in('idle') && !((_a = this.form.items) === null || _a === void 0 ? void 0 : _a.length)) {
372
+ this.edit({ items: [{ name: '', price: 0, custom_options: [] }] });
373
+ this.__openState = [true];
374
+ }
375
+ if (((_b = this.form.items) === null || _b === void 0 ? void 0 : _b.length) && !this.__openState.length) {
376
+ this.__openState = [true, ...new Array(this.form.items.length - 1).fill(false)];
377
+ }
378
+ }
379
+ submit() {
380
+ // Do nothing – in this version of the element, this form is not meant to be submitted.
381
+ }
382
+ get __defaultTemplateSetHref() {
383
+ var _a, _b, _c;
384
+ try {
385
+ const url = new URL((_c = (_b = (_a = this.__storeLoader) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b._links['fx:template_sets'].href) !== null && _c !== void 0 ? _c : '');
386
+ url.searchParams.set('code', 'DEFAULT');
387
+ return url.toString();
388
+ }
389
+ catch (_d) {
390
+ return undefined;
391
+ }
392
+ }
393
+ get __resolvedCurrencyCode() {
394
+ var _a, _b, _c, _d;
395
+ const localeCodesLoader = this.renderRoot.querySelector('#localeCodesHelperLoader');
396
+ const currentLocale = (_a = this.__resolvedTemplateSet) === null || _a === void 0 ? void 0 : _a.locale_code;
397
+ const allLocales = (_b = localeCodesLoader === null || localeCodesLoader === void 0 ? void 0 : localeCodesLoader.data) === null || _b === void 0 ? void 0 : _b.values;
398
+ const localeInfo = currentLocale ? allLocales === null || allLocales === void 0 ? void 0 : allLocales[currentLocale] : void 0;
399
+ return localeInfo ? (_d = (_c = /Currency: ([A-Z]{3})/g.exec(localeInfo)) === null || _c === void 0 ? void 0 : _c[1]) === null || _d === void 0 ? void 0 : _d.toUpperCase() : void 0;
400
+ }
401
+ get __resolvedTemplateSet() {
402
+ var _a, _b, _c, _d;
403
+ const $ = (s) => this.renderRoot.querySelector(s);
404
+ return ((_b = (_a = $('#templateSetLoader')) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : (_d = (_c = $('#defaultTemplateSetLoader')) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d._embedded['fx:template_sets'][0]);
405
+ }
406
+ get __resolvedCartUrl() {
407
+ var _a;
408
+ const store = (_a = this.__storeLoader) === null || _a === void 0 ? void 0 : _a.data;
409
+ if (store) {
410
+ if (store.use_remote_domain) {
411
+ return `https://${store.store_domain}/cart`;
412
+ }
413
+ else if (this.defaultDomain !== null) {
414
+ return `https://${store.store_domain}.${this.defaultDomain}/cart`;
415
+ }
416
+ }
417
+ return null;
418
+ }
419
+ get __storeLoader() {
420
+ return this.renderRoot.querySelector('#storeLoaderId');
421
+ }
422
+ __getItemCategoryLoader(productIndex, optionIndex) {
423
+ const prefix = `#itemCategoryLoaderProduct${productIndex}`;
424
+ const selector = typeof optionIndex === 'number' ? `${prefix}Option${optionIndex}` : prefix;
425
+ return this.renderRoot.querySelector(selector);
426
+ }
427
+ __getAddToCartFormHTML() {
428
+ var _a, _b, _c, _d, _e, _f, _g;
429
+ const currencyCode = this.__resolvedCurrencyCode;
430
+ const templateSet = this.__resolvedTemplateSet;
431
+ const cartUrl = this.__resolvedCartUrl;
432
+ const store = (_a = this.__storeLoader) === null || _a === void 0 ? void 0 : _a.data;
433
+ if (!this.defaultDomain || !templateSet || !store || !currencyCode || !cartUrl)
434
+ return '';
435
+ let output = `<form action="${encode(cartUrl)}" method="post" target="_blank">`;
436
+ let level = 1;
437
+ const newline = () => `\n${' '.repeat(level * 2)}`;
438
+ const addHiddenInput = (name, value) => {
439
+ const encodedValue = encode(value);
440
+ const encodedName = encode(name);
441
+ output += `${newline()}<input type="hidden" name="${encodedName}" value="${encodedValue}">`;
442
+ };
443
+ if (templateSet.code !== 'DEFAULT')
444
+ addHiddenInput('template_set', templateSet.code);
445
+ if (this.form.empty)
446
+ addHiddenInput('empty', this.form.empty);
447
+ if (this.form.cart === 'checkout')
448
+ addHiddenInput('cart', 'checkout');
449
+ const items = (_b = this.form.items) !== null && _b !== void 0 ? _b : [];
450
+ const hasMoreThanOneProduct = items.length > 1;
451
+ for (let productIndex = 0; productIndex < items.length; ++productIndex) {
452
+ const itemCategoryLoader = this.__getItemCategoryLoader(productIndex);
453
+ const itemCategory = itemCategoryLoader === null || itemCategoryLoader === void 0 ? void 0 : itemCategoryLoader.data;
454
+ const product = items[productIndex];
455
+ if (!product.name || !product.price)
456
+ return '';
457
+ if (product.item_category_uri && !itemCategory)
458
+ return '';
459
+ const hasConfigurableQuantity = product.quantity_min !== product.quantity_max;
460
+ const hasConfigurablePrice = product.price_configurable;
461
+ const hasConfigurableOptions = product.custom_options.some((v, i, a) => v.value_configurable || a.findIndex(vv => vv.name === v.name) !== i);
462
+ const useFieldset = hasMoreThanOneProduct &&
463
+ (hasConfigurablePrice || hasConfigurableQuantity || hasConfigurableOptions);
464
+ if (useFieldset) {
465
+ output += `${newline()}<fieldset>`;
466
+ level++;
467
+ output += `${newline()}<legend>${encode(product.name)}</legend>`;
468
+ }
469
+ const prefix = productIndex === 0 ? '' : `${productIndex + 1}:`;
470
+ addHiddenInput(`${prefix}name`, product.name);
471
+ const price = `${product.price}${currencyCode}`;
472
+ if (product.price_configurable) {
473
+ const encodedPrice = encode(price);
474
+ output += `${newline()}<label>`;
475
+ level++;
476
+ output += `${newline()}<span>${encode(this.t('preview.price_label'))}</span>`;
477
+ if (store.use_cart_validation) {
478
+ output += `${newline()}<input required name="${prefix}price" value="--OPEN--" data-replace="${encodedPrice}">`;
479
+ }
480
+ else {
481
+ output += `${newline()}<input required name="${prefix}price" value="${encodedPrice}">`;
482
+ }
483
+ level--;
484
+ output += `${newline()}</label>`;
485
+ }
486
+ else {
487
+ addHiddenInput(`${prefix}price`, price);
488
+ }
489
+ if (itemCategory && itemCategory.code !== 'DEFAULT') {
490
+ addHiddenInput(`${prefix}category`, itemCategory.code);
491
+ }
492
+ if (product.code)
493
+ addHiddenInput(`${prefix}code`, product.code);
494
+ if (product.parent_code)
495
+ addHiddenInput(`${prefix}parent_code`, product.parent_code);
496
+ if (product.image) {
497
+ addHiddenInput(`${prefix}image`, product.image);
498
+ if (product.url)
499
+ addHiddenInput(`${prefix}url`, product.url);
500
+ }
501
+ if (product.sub_enabled) {
502
+ if (product.sub_frequency) {
503
+ addHiddenInput(`${prefix}sub_frequency`, product.sub_frequency);
504
+ if (product.sub_startdate) {
505
+ if (product.sub_startdate_format === 'yyyymmdd') {
506
+ const date = new Date(product.sub_startdate);
507
+ const year = date.getFullYear();
508
+ const month = (date.getMonth() + 1).toString().padStart(2, '0');
509
+ const day = date.getDate().toString().padStart(2, '0');
510
+ addHiddenInput(`${prefix}sub_startdate`, `${year}${month}${day}`);
511
+ }
512
+ else {
513
+ addHiddenInput(`${prefix}sub_startdate`, String(product.sub_startdate));
514
+ }
515
+ }
516
+ if (product.sub_enddate) {
517
+ if (product.sub_enddate_format === 'yyyymmdd') {
518
+ const date = new Date(product.sub_enddate);
519
+ const year = date.getFullYear();
520
+ const month = (date.getMonth() + 1).toString().padStart(2, '0');
521
+ const day = date.getDate().toString().padStart(2, '0');
522
+ addHiddenInput(`${prefix}sub_enddate`, `${year}${month}${day}`);
523
+ }
524
+ else {
525
+ addHiddenInput(`${prefix}sub_enddate`, product.sub_enddate);
526
+ }
527
+ }
528
+ }
529
+ }
530
+ if (product.discount_name && product.discount_type && product.discount_details) {
531
+ addHiddenInput(`${prefix}discount_${product.discount_type}`, `${product.discount_name}{${product.discount_details}}`);
532
+ }
533
+ if (product.expires_value) {
534
+ if (product.expires_format === 'timestamp') {
535
+ addHiddenInput(`${prefix}expires`, (product.expires_value / 1000).toFixed(0));
536
+ }
537
+ else {
538
+ addHiddenInput(`${prefix}expires`, product.expires_value.toFixed(0));
539
+ }
540
+ }
541
+ if (product.quantity_min || product.quantity_max) {
542
+ output += `${newline()}<label>`;
543
+ level++;
544
+ output += `${newline()}<span>${encode(this.t('preview.quantity_label'))}</span>`;
545
+ output += `${newline()}<input type="number" name="${encode(`${prefix}quantity`)}"`;
546
+ if (product.expires_format !== 'minutes') {
547
+ if (product.quantity_min)
548
+ output += ` min="${encode(String(product.quantity_min))}"`;
549
+ if (product.quantity_max)
550
+ output += ` max="${encode(String(product.quantity_max))}"`;
551
+ }
552
+ if (store.use_cart_validation) {
553
+ output += ` value="--OPEN--" data-replace="${encode(String((_c = product.quantity) !== null && _c !== void 0 ? _c : 1))}">`;
554
+ }
555
+ else {
556
+ output += ` value="${encode(String((_d = product.quantity) !== null && _d !== void 0 ? _d : 1))}">`;
557
+ }
558
+ level--;
559
+ output += `${newline()}</label>`;
560
+ }
561
+ else if (((_e = product.quantity) !== null && _e !== void 0 ? _e : 1) > 1) {
562
+ addHiddenInput(`${prefix}quantity`, ((_f = product.quantity) !== null && _f !== void 0 ? _f : 1).toString());
563
+ }
564
+ if (product.expires_format !== 'minutes') {
565
+ if (product.quantity_min) {
566
+ addHiddenInput(`${prefix}quantity_min`, product.quantity_min.toFixed(0));
567
+ }
568
+ if (product.quantity_max) {
569
+ addHiddenInput(`${prefix}quantity_max`, product.quantity_max.toFixed(0));
570
+ }
571
+ }
572
+ if (product.length)
573
+ addHiddenInput(`${prefix}length`, product.length.toFixed(3));
574
+ if (product.width)
575
+ addHiddenInput(`${prefix}width`, product.width.toFixed(3));
576
+ if (product.height)
577
+ addHiddenInput(`${prefix}height`, product.height.toFixed(3));
578
+ if (product.weight)
579
+ addHiddenInput(`${prefix}weight`, product.weight.toFixed(3));
580
+ if (store.features_multiship) {
581
+ output += `${newline()}<label>`;
582
+ level++;
583
+ output += `${newline()}<span>${encode(this.t('preview.shipto_label'))}</span>`;
584
+ if (store.use_cart_validation) {
585
+ output += `${newline()}<input name="${prefix}shipto" value="--OPEN--" data-replace="">`;
586
+ }
587
+ else {
588
+ output += `${newline()}<input name="${prefix}shipto" value="">`;
589
+ }
590
+ level--;
591
+ output += `${newline()}</label>`;
592
+ }
593
+ const groupedCustomOptions = product.custom_options.reduce((acc, option) => {
594
+ if (!acc[option.name])
595
+ acc[option.name] = [];
596
+ acc[option.name].push(option);
597
+ return acc;
598
+ }, {});
599
+ for (const optionName in groupedCustomOptions) {
600
+ const group = groupedCustomOptions[optionName];
601
+ if (group.length === 1) {
602
+ const optionIndex = product.custom_options.indexOf(group[0]);
603
+ const itemCategory = (_g = this.__getItemCategoryLoader(productIndex, optionIndex)) === null || _g === void 0 ? void 0 : _g.data;
604
+ const modifiers = this.__getOptionModifiers(group[0], itemCategory !== null && itemCategory !== void 0 ? itemCategory : null, currencyCode);
605
+ const value = `${group[0].value}${modifiers}`;
606
+ const name = `${prefix}${optionName}`;
607
+ if (group[0].value_configurable) {
608
+ output += `${newline()}<label>`;
609
+ level++;
610
+ output += `${newline()}<span>${encode(optionName)}:</span>`;
611
+ output += `${newline()}<input name="${encode(name)}" `;
612
+ if (store.use_cart_validation) {
613
+ output += `value="--OPEN--" data-replace="${encode(value)}">`;
614
+ }
615
+ else {
616
+ output += `value="${encode(value)}">`;
617
+ }
618
+ level--;
619
+ output += `${newline()}</label>`;
620
+ }
621
+ else {
622
+ addHiddenInput(name, value);
623
+ }
624
+ }
625
+ else {
626
+ output += `${newline()}<label>`;
627
+ level++;
628
+ output += `${newline()}<span>${encode(optionName)}:</span>`;
629
+ output += `${newline()}<select name="${prefix}${optionName}">`;
630
+ level++;
631
+ group.forEach(option => {
632
+ var _a;
633
+ const optionIndex = product.custom_options.indexOf(option);
634
+ const itemCategory = (_a = this.__getItemCategoryLoader(productIndex, optionIndex)) === null || _a === void 0 ? void 0 : _a.data;
635
+ const modifiers = this.__getOptionModifiers(option, itemCategory !== null && itemCategory !== void 0 ? itemCategory : null, currencyCode);
636
+ const encodedValue = encode(`${option.value}${modifiers}`);
637
+ const encodedCaption = encode(option.value);
638
+ output += `${newline()}<option value="${encodedValue}">${encodedCaption}</option>`;
639
+ });
640
+ level--;
641
+ output += `${newline()}</select>`;
642
+ level--;
643
+ output += `${newline()}</label>`;
644
+ }
645
+ }
646
+ if (useFieldset) {
647
+ level--;
648
+ output += `${newline()}</fieldset>`;
649
+ }
650
+ }
651
+ const encodedSubmitCaption = encode(this.t('preview.submit_caption'));
652
+ output += `${newline()}<button type="submit">${encodedSubmitCaption}</button>`;
653
+ level--;
654
+ output += `${newline()}</form>`;
655
+ return output;
656
+ }
657
+ __getAddToCartLinkHref() {
658
+ var _a, _b, _c, _d, _e, _f;
659
+ const currencyCode = this.__resolvedCurrencyCode;
660
+ const templateSet = this.__resolvedTemplateSet;
661
+ const cartUrl = this.__resolvedCartUrl;
662
+ const store = (_a = this.__storeLoader) === null || _a === void 0 ? void 0 : _a.data;
663
+ if (!this.defaultDomain || !templateSet || !store || !currencyCode || !cartUrl)
664
+ return '';
665
+ const url = new URL(cartUrl);
666
+ if (templateSet.code !== 'DEFAULT')
667
+ url.searchParams.set('template_set', templateSet.code);
668
+ if (this.form.empty)
669
+ url.searchParams.set('empty', this.form.empty);
670
+ if (this.form.cart === 'checkout')
671
+ url.searchParams.set('cart', 'checkout');
672
+ for (let index = 0; index < ((_c = (_b = this.form.items) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0); ++index) {
673
+ const product = this.form.items[index];
674
+ const prefix = index === 0 ? '' : `${index + 1}:`;
675
+ const itemCategory = (_d = this.__getItemCategoryLoader(index)) === null || _d === void 0 ? void 0 : _d.data;
676
+ if (product.item_category_uri && !itemCategory)
677
+ return '';
678
+ if (itemCategory && itemCategory.code !== 'DEFAULT') {
679
+ url.searchParams.set(`${prefix}category`, itemCategory.code);
680
+ }
681
+ url.searchParams.set(`${prefix}name`, product.name);
682
+ url.searchParams.set(`${prefix}price`, `${product.price}${currencyCode}`);
683
+ if (product.code)
684
+ url.searchParams.set(`${prefix}code`, product.code);
685
+ if (product.parent_code)
686
+ url.searchParams.set(`${prefix}parent_code`, product.parent_code);
687
+ if (product.image) {
688
+ url.searchParams.set(`${prefix}image`, product.image);
689
+ if (product.url)
690
+ url.searchParams.set(`${prefix}url`, product.url);
691
+ }
692
+ if (product.sub_enabled) {
693
+ if (product.sub_frequency) {
694
+ url.searchParams.set(`${prefix}sub_frequency`, product.sub_frequency);
695
+ if (product.sub_startdate) {
696
+ if (product.sub_startdate_format === 'yyyymmdd') {
697
+ const date = new Date(product.sub_startdate);
698
+ const year = date.getFullYear();
699
+ const month = (date.getMonth() + 1).toString().padStart(2, '0');
700
+ const day = date.getDate().toString().padStart(2, '0');
701
+ url.searchParams.set(`${prefix}sub_startdate`, `${year}${month}${day}`);
702
+ }
703
+ else {
704
+ url.searchParams.set(`${prefix}sub_startdate`, String(product.sub_startdate));
705
+ }
706
+ }
707
+ if (product.sub_enddate) {
708
+ if (product.sub_enddate_format === 'yyyymmdd') {
709
+ const date = new Date(product.sub_enddate);
710
+ const year = date.getFullYear();
711
+ const month = (date.getMonth() + 1).toString().padStart(2, '0');
712
+ const day = date.getDate().toString().padStart(2, '0');
713
+ url.searchParams.set(`${prefix}sub_enddate`, `${year}${month}${day}`);
714
+ }
715
+ else {
716
+ url.searchParams.set(`${prefix}sub_enddate`, product.sub_enddate);
717
+ }
718
+ }
719
+ }
720
+ }
721
+ if (product.discount_name && product.discount_type && product.discount_details) {
722
+ url.searchParams.set(`${prefix}discount_${product.discount_type}`, `${product.discount_name}{${product.discount_details}}`);
723
+ }
724
+ if (product.expires_value) {
725
+ if (product.expires_format === 'timestamp') {
726
+ url.searchParams.set(`${prefix}expires`, (product.expires_value / 1000).toFixed(0));
727
+ }
728
+ else {
729
+ url.searchParams.set(`${prefix}expires`, product.expires_value.toFixed(0));
730
+ }
731
+ }
732
+ if (((_e = product.quantity) !== null && _e !== void 0 ? _e : 1) > 1) {
733
+ url.searchParams.set(`${prefix}quantity`, ((_f = product.quantity) !== null && _f !== void 0 ? _f : 1).toFixed(0));
734
+ }
735
+ if (product.expires_format !== 'minutes') {
736
+ if (product.quantity_min) {
737
+ url.searchParams.set(`${prefix}quantity_min`, product.quantity_min.toString());
738
+ }
739
+ if (product.quantity_max) {
740
+ url.searchParams.set(`${prefix}quantity_max`, product.quantity_max.toString());
741
+ }
742
+ }
743
+ if (product.weight)
744
+ url.searchParams.set(`${prefix}weight`, product.weight.toFixed(3));
745
+ if (product.length)
746
+ url.searchParams.set(`${prefix}length`, product.length.toFixed(3));
747
+ if (product.width)
748
+ url.searchParams.set(`${prefix}width`, product.width.toFixed(3));
749
+ if (product.height)
750
+ url.searchParams.set(`${prefix}height`, product.height.toFixed(3));
751
+ product.custom_options.forEach((option, optionIndex) => {
752
+ var _a, _b;
753
+ const itemCategory = (_a = this.__getItemCategoryLoader(index, optionIndex)) === null || _a === void 0 ? void 0 : _a.data;
754
+ const modifiers = this.__getOptionModifiers(option, itemCategory !== null && itemCategory !== void 0 ? itemCategory : null, currencyCode);
755
+ url.searchParams.set(`${prefix}${option.name}`, `${(_b = option.value) !== null && _b !== void 0 ? _b : ''}${modifiers}`);
756
+ });
757
+ }
758
+ return url.toString();
759
+ }
760
+ __getAddToCartCode() {
761
+ var _a;
762
+ const store = (_a = this.__storeLoader) === null || _a === void 0 ? void 0 : _a.data;
763
+ if (!this.encodeHelper || !store)
764
+ return null;
765
+ const formHTML = this.__getAddToCartFormHTML();
766
+ const linkHref = this.__getAddToCartLinkHref();
767
+ if (!formHTML || !linkHref)
768
+ return null;
769
+ const linkHTML = `<a href="${encode(linkHref)}">Add to cart</a>`;
770
+ const unsignedCode = `${formHTML}${this.__signingSeparator}${linkHTML}`;
771
+ if (unsignedCode === this.__previousUnsignedCode && this.__previousSignedCode) {
772
+ const signedCode = this.__previousSignedCode.split(this.__signingSeparator);
773
+ return {
774
+ formHTML: signedCode[0],
775
+ linkHref: decode(signedCode[1].substring(9, signedCode[1].length - 17)),
776
+ };
777
+ }
778
+ this.__previousUnsignedCode = unsignedCode;
779
+ this.__previousSignedCode = '';
780
+ if (store.use_cart_validation)
781
+ this.__signAsync(unsignedCode, this.encodeHelper);
782
+ return { formHTML, linkHref };
783
+ }
784
+ __getOptionModifiers(option, optionItemCategory, currencyCode) {
785
+ if (option.value_configurable)
786
+ return '';
787
+ const modifiers = [];
788
+ if (option.price) {
789
+ const operator = option.replace_price ? ':' : Math.sign(option.price) === -1 ? '-' : '+';
790
+ if (option.replace_price || option.price !== 0)
791
+ modifiers.push(`p${operator}${Math.abs(option.price)}${currencyCode}`);
792
+ }
793
+ if (option.weight) {
794
+ const operator = option.replace_weight ? ':' : Math.sign(option.weight) === -1 ? '-' : '+';
795
+ if (option.replace_weight || option.weight !== 0)
796
+ modifiers.push(`w${operator}${Math.abs(option.weight)}`);
797
+ }
798
+ if (option.item_category_uri && !optionItemCategory)
799
+ return '';
800
+ if (optionItemCategory)
801
+ modifiers.push(`y:${optionItemCategory.code}`);
802
+ if (option.code) {
803
+ const operator = option.replace_code ? ':' : '+';
804
+ if (option.replace_code || option.code !== '')
805
+ modifiers.push(`c${operator}${option.code}`);
806
+ }
807
+ return modifiers.length ? `{${modifiers.join('|')}}` : '';
808
+ }
809
+ }
810
+ //# sourceMappingURL=ExperimentalAddToCartBuilder.js.map