@ubnt/store.core 9.19.1 → 9.20.0-alpha.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 (405) hide show
  1. package/CHANGELOG.md +205 -1
  2. package/lib/_virtual/_virtual_multi-entry.js +27 -12
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +14 -10
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/attention.svg +5 -5
  7. package/lib/assets/attention2.svg +5 -5
  8. package/lib/assets/close2.svg +2 -3
  9. package/lib/assets/close3.svg +3 -2
  10. package/lib/assets/efg.png +0 -0
  11. package/lib/assets/icon-location-pin.svg +5 -0
  12. package/lib/assets/icons/menu/icon-location-pin.svg.js +27 -0
  13. package/lib/assets/icons/menu/icon-location-pin.svg.js.map +1 -0
  14. package/lib/assets/icons/menu/icon-location-pin.svg.mjs +3 -0
  15. package/lib/assets/icons/menu/icon-location-pin.svg.mjs.map +1 -0
  16. package/lib/assets/pause.svg +3 -3
  17. package/lib/assets/pause2.svg +3 -3
  18. package/lib/assets/ucg-max.png +0 -0
  19. package/lib/assets/udmProMax.jpg +0 -0
  20. package/lib/assets/udmProMax2.jpg +0 -0
  21. package/lib/assets/udmProSpecial.jpg +0 -0
  22. package/lib/assets/udmProSpecial2.jpg +0 -0
  23. package/lib/components/CategoryTabs/CategoryTabs.styles.d.ts +1 -1
  24. package/lib/components/CategoryTabs/CategoryTabs.styles.js +2 -3
  25. package/lib/components/CategoryTabs/CategoryTabs.styles.js.map +1 -1
  26. package/lib/components/CategoryTabs/CategoryTabs.styles.mjs +2 -3
  27. package/lib/components/CategoryTabs/CategoryTabs.styles.mjs.map +1 -1
  28. package/lib/components/Compare/Compare.styles.d.ts +5 -5
  29. package/lib/components/Container/Container.d.ts +1 -1
  30. package/lib/components/Container/Container.js +4 -3
  31. package/lib/components/Container/Container.js.map +1 -1
  32. package/lib/components/Container/Container.mjs +5 -4
  33. package/lib/components/Container/Container.mjs.map +1 -1
  34. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  35. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  36. package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
  37. package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
  38. package/lib/components/Header/AccountMenu/AccountMenu.js +11 -1
  39. package/lib/components/Header/AccountMenu/AccountMenu.js.map +1 -1
  40. package/lib/components/Header/AccountMenu/AccountMenu.mjs +13 -3
  41. package/lib/components/Header/AccountMenu/AccountMenu.mjs.map +1 -1
  42. package/lib/components/Header/Header.js +6 -6
  43. package/lib/components/Header/Header.js.map +1 -1
  44. package/lib/components/Header/Header.mjs +6 -6
  45. package/lib/components/Header/Header.mjs.map +1 -1
  46. package/lib/components/Header/Header.styles.d.ts +2 -2
  47. package/lib/components/Header/Header.types.d.ts +12 -4
  48. package/lib/components/Header/Header.types.js +2 -1
  49. package/lib/components/Header/Header.types.js.map +1 -1
  50. package/lib/components/Header/Header.types.mjs +2 -1
  51. package/lib/components/Header/Header.types.mjs.map +1 -1
  52. package/lib/components/Header/MenuItem/MenuItem.styles.d.ts +1 -1
  53. package/lib/components/Header/MenuItem/MenuItem.styles.js +3 -3
  54. package/lib/components/Header/MenuItem/MenuItem.styles.js.map +1 -1
  55. package/lib/components/Header/MenuItem/MenuItem.styles.mjs +3 -3
  56. package/lib/components/Header/MenuItem/MenuItem.styles.mjs.map +1 -1
  57. package/lib/components/Header/MenuItem/MenuItem.types.d.ts +1 -0
  58. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.styles.d.ts +1 -1
  59. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.styles.d.ts +1 -1
  60. package/lib/components/Header/Navigation/ProMenu/ProMenu.d.ts +2 -0
  61. package/lib/components/Header/Navigation/ProMenu/ProMenu.js +103 -0
  62. package/lib/components/Header/Navigation/ProMenu/ProMenu.js.map +1 -0
  63. package/lib/components/Header/Navigation/ProMenu/ProMenu.mjs +81 -0
  64. package/lib/components/Header/Navigation/ProMenu/ProMenu.mjs.map +1 -0
  65. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.d.ts +23 -0
  66. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.js +121 -0
  67. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.js.map +1 -0
  68. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.mjs +106 -0
  69. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.mjs.map +1 -0
  70. package/lib/components/Header/Navigation/ProMenu/ProMenu.types.d.ts +12 -0
  71. package/lib/components/Header/Navigation/ProMenu/index.d.ts +1 -0
  72. package/lib/components/Header/Navigation/ProMenu/index.js +6 -0
  73. package/lib/components/{ResourceCalculatorV1/components → Header/Navigation/ProMenu}/index.js.map +1 -1
  74. package/lib/components/Header/Navigation/ProMenu/index.mjs +3 -0
  75. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.d.ts +1 -1
  76. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js +92 -95
  77. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js.map +1 -1
  78. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs +92 -95
  79. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs.map +1 -1
  80. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.d.ts +9 -0
  81. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.js +15 -1
  82. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.js.map +1 -1
  83. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.mjs +13 -2
  84. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.mjs.map +1 -1
  85. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.types.d.ts +10 -4
  86. package/lib/components/Header/ProHeader/ProHeader.d.ts +3 -4
  87. package/lib/components/Header/ProHeader/ProHeader.js +247 -120
  88. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  89. package/lib/components/Header/ProHeader/ProHeader.mjs +249 -124
  90. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  91. package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +4 -1
  92. package/lib/components/Header/ProHeader/ProHeader.styles.js +23 -17
  93. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  94. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +21 -18
  95. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  96. package/lib/components/Header/translations/ar.json.js +4 -1
  97. package/lib/components/Header/translations/ar.json.js.map +1 -1
  98. package/lib/components/Header/translations/ar.json.mjs +4 -2
  99. package/lib/components/Header/translations/ar.json.mjs.map +1 -1
  100. package/lib/components/Header/translations/de.json.js +4 -1
  101. package/lib/components/Header/translations/de.json.js.map +1 -1
  102. package/lib/components/Header/translations/de.json.mjs +4 -2
  103. package/lib/components/Header/translations/de.json.mjs.map +1 -1
  104. package/lib/components/Header/translations/el.json.js +4 -1
  105. package/lib/components/Header/translations/el.json.js.map +1 -1
  106. package/lib/components/Header/translations/el.json.mjs +4 -2
  107. package/lib/components/Header/translations/el.json.mjs.map +1 -1
  108. package/lib/components/Header/translations/en.json.js +4 -1
  109. package/lib/components/Header/translations/en.json.js.map +1 -1
  110. package/lib/components/Header/translations/en.json.mjs +4 -2
  111. package/lib/components/Header/translations/en.json.mjs.map +1 -1
  112. package/lib/components/Header/translations/es.json.js +4 -1
  113. package/lib/components/Header/translations/es.json.js.map +1 -1
  114. package/lib/components/Header/translations/es.json.mjs +4 -2
  115. package/lib/components/Header/translations/es.json.mjs.map +1 -1
  116. package/lib/components/Header/translations/fr.json.js +4 -1
  117. package/lib/components/Header/translations/fr.json.js.map +1 -1
  118. package/lib/components/Header/translations/fr.json.mjs +4 -2
  119. package/lib/components/Header/translations/fr.json.mjs.map +1 -1
  120. package/lib/components/Header/translations/it.json.js +4 -1
  121. package/lib/components/Header/translations/it.json.js.map +1 -1
  122. package/lib/components/Header/translations/it.json.mjs +4 -2
  123. package/lib/components/Header/translations/it.json.mjs.map +1 -1
  124. package/lib/components/Header/translations/ja.json.js +4 -1
  125. package/lib/components/Header/translations/ja.json.js.map +1 -1
  126. package/lib/components/Header/translations/ja.json.mjs +4 -2
  127. package/lib/components/Header/translations/ja.json.mjs.map +1 -1
  128. package/lib/components/Header/translations/pt-BR.json.js +4 -1
  129. package/lib/components/Header/translations/pt-BR.json.js.map +1 -1
  130. package/lib/components/Header/translations/pt-BR.json.mjs +4 -2
  131. package/lib/components/Header/translations/pt-BR.json.mjs.map +1 -1
  132. package/lib/components/Header/translations/zh-Hans.json.js +4 -1
  133. package/lib/components/Header/translations/zh-Hans.json.js.map +1 -1
  134. package/lib/components/Header/translations/zh-Hans.json.mjs +4 -2
  135. package/lib/components/Header/translations/zh-Hans.json.mjs.map +1 -1
  136. package/lib/components/Header/translations/zh-Hant-TW.json.js +4 -1
  137. package/lib/components/Header/translations/zh-Hant-TW.json.js.map +1 -1
  138. package/lib/components/Header/translations/zh-Hant-TW.json.mjs +4 -2
  139. package/lib/components/Header/translations/zh-Hant-TW.json.mjs.map +1 -1
  140. package/lib/components/Hero/Hero.styles.d.ts +2 -2
  141. package/lib/components/HeroFadeGallery/HeroFadeGallery.styles.d.ts +1 -1
  142. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.d.ts +1 -1
  143. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.js +3 -1
  144. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +1 -0
  145. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.mjs +3 -1
  146. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +1 -0
  147. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.styles.d.ts +1 -0
  148. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.styles.js +10 -7
  149. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +1 -0
  150. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.styles.mjs +10 -7
  151. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +1 -0
  152. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.types.d.ts +1 -0
  153. package/lib/components/HowToUseSection/HowToUseSection.styles.d.ts +2 -2
  154. package/lib/components/LandingPagePro/LandingPagePro.d.ts +3 -0
  155. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  156. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  157. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  158. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  159. package/lib/components/LandingPagePro/LandingPagePro.styles.d.ts +1 -1
  160. package/lib/components/LayoutRenderer/LayoutRenderer.styles.d.ts +1 -1
  161. package/lib/components/LayoutRendererV1/LayoutRenderer.styles.d.ts +3 -3
  162. package/lib/components/LayoutRendererV2/LayoutRenderer.styles.d.ts +3 -3
  163. package/lib/components/MicrositeSectionWrap/MicrositeSectionWrap.styles.d.ts +1 -1
  164. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.js +1 -1
  165. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.mjs +1 -1
  166. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.js +1 -1
  167. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.mjs +2 -2
  168. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.js +5 -5
  169. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.mjs +2 -2
  170. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
  171. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
  172. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.js +1 -1
  173. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.mjs +2 -2
  174. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
  175. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
  176. package/lib/components/ModelCompareV3/data/CloudGateways.js +6 -6
  177. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +4 -4
  178. package/lib/components/ModelCompareV3/data/products/udmProMax.js +1 -1
  179. package/lib/components/ModelCompareV3/data/products/udmProMax.mjs +1 -1
  180. package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +1 -1
  181. package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +1 -1
  182. package/lib/components/ProductSectionNavigation/ProductSectionNavigation.styles.d.ts +1 -1
  183. package/lib/components/ProductSectionNavigationV2/ProductSectionNavigation.styles.d.ts +1 -1
  184. package/lib/components/ProductTechSpecs/ProductTechSpecs.styles.d.ts +1 -1
  185. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +313 -17
  186. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  187. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +311 -17
  188. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  189. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.d.ts +3 -2
  190. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js +2 -0
  191. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js.map +1 -1
  192. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs +2 -0
  193. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs.map +1 -1
  194. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js +120 -34
  195. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js.map +1 -1
  196. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs +120 -34
  197. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs.map +1 -1
  198. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.d.ts +16 -2
  199. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js +54 -12
  200. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js.map +1 -1
  201. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs +50 -11
  202. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs.map +1 -1
  203. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowLeftPrimary.svg.js +5 -5
  204. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowRightPrimary.svg.js +5 -5
  205. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +2 -2
  206. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
  207. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +2 -2
  208. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
  209. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +2 -0
  210. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
  211. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +2 -0
  212. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
  213. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  214. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  215. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  216. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  217. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  218. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  219. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js +1 -1
  220. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js.map +1 -1
  221. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs +1 -1
  222. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs.map +1 -1
  223. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  224. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js.map +1 -1
  225. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  226. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs.map +1 -1
  227. package/lib/components/ResourceCalculatorV1/ResourceCalculator.js +1 -2
  228. package/lib/components/ResourceCalculatorV1/ResourceCalculator.js.map +1 -1
  229. package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs +1 -2
  230. package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs.map +1 -1
  231. package/lib/{assets/icons/menu/icon-globe.svg.js → components/ResourceCalculatorV1/assets/consoles/efg.png.js} +6 -6
  232. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js.map +1 -0
  233. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs +3 -0
  234. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs.map +1 -0
  235. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js +27 -0
  236. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js.map +1 -0
  237. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs +3 -0
  238. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs.map +1 -0
  239. package/lib/components/ResourceCalculatorV1/translations/en.json.js +6 -4
  240. package/lib/components/ResourceCalculatorV1/translations/en.json.js.map +1 -1
  241. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs +6 -4
  242. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs.map +1 -1
  243. package/lib/components/ResourceCalculatorV1/translations/useResourceCalculatorTranslation.d.ts +2 -2
  244. package/lib/components/VideoPlayerNew/VideoPlayer.js +2 -2
  245. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +2 -2
  246. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  247. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  248. package/lib/components/VideoPlayerNew/assets/pause.svg.js +1 -1
  249. package/lib/components/VideoPlayerNew/assets/pause.svg.mjs +2 -2
  250. package/lib/components/index.d.ts +1 -0
  251. package/lib/components/index.js +2 -0
  252. package/lib/components/index.js.map +1 -1
  253. package/lib/components/index.mjs +2 -0
  254. package/lib/components/index.mjs.map +1 -1
  255. package/lib/constants/proStoreCategories/mapping/index.d.ts +1 -0
  256. package/lib/constants/proStoreCategories/mapping/index.js +15 -10
  257. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  258. package/lib/constants/proStoreCategories/mapping/index.mjs +15 -10
  259. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  260. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +2 -1
  261. package/lib/constants/proStoreCategories/mapping/unifi.js +1 -0
  262. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  263. package/lib/constants/proStoreCategories/mapping/unifi.mjs +1 -0
  264. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  265. package/lib/constants/proStoreCategories/translations/en.json.js +3 -0
  266. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  267. package/lib/constants/proStoreCategories/translations/en.json.mjs +3 -1
  268. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  269. package/lib/constants/proStoreCategories/translations/fr.json.js +1 -1
  270. package/lib/constants/proStoreCategories/translations/fr.json.mjs +1 -1
  271. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +1 -1
  272. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +1 -1
  273. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +1 -1
  274. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +1 -1
  275. package/lib/constants/theme.js +4 -0
  276. package/lib/constants/theme.js.map +1 -1
  277. package/lib/constants/theme.mjs +4 -0
  278. package/lib/constants/theme.mjs.map +1 -1
  279. package/lib/contexts/MenuContext/context.js +1 -1
  280. package/lib/contexts/MenuContext/context.js.map +1 -1
  281. package/lib/contexts/MenuContext/context.mjs +1 -1
  282. package/lib/contexts/MenuContext/context.mjs.map +1 -1
  283. package/lib/helpers/index.d.ts +1 -0
  284. package/lib/helpers/index.js +11 -0
  285. package/lib/helpers/index.js.map +1 -1
  286. package/lib/helpers/index.mjs +1 -0
  287. package/lib/helpers/index.mjs.map +1 -1
  288. package/lib/helpers/product.d.ts +87 -0
  289. package/lib/helpers/product.js +346 -0
  290. package/lib/helpers/product.js.map +1 -0
  291. package/lib/helpers/product.mjs +335 -0
  292. package/lib/helpers/product.mjs.map +1 -0
  293. package/lib/helpers/ux.d.ts +9 -1
  294. package/lib/helpers/ux.js +15 -0
  295. package/lib/helpers/ux.js.map +1 -1
  296. package/lib/helpers/ux.mjs +15 -1
  297. package/lib/helpers/ux.mjs.map +1 -1
  298. package/lib/types/index.d.ts +1 -0
  299. package/lib/types/index.js +2 -0
  300. package/lib/types/index.js.map +1 -1
  301. package/lib/types/index.mjs +1 -0
  302. package/lib/types/index.mjs.map +1 -1
  303. package/lib/types/product.d.ts +87 -0
  304. package/lib/types/product.js +14 -0
  305. package/lib/types/product.js.map +1 -0
  306. package/lib/types/product.mjs +13 -0
  307. package/lib/types/product.mjs.map +1 -0
  308. package/lib/utils/array.d.ts +4 -0
  309. package/lib/utils/array.js +10 -0
  310. package/lib/utils/array.js.map +1 -1
  311. package/lib/utils/array.mjs +10 -1
  312. package/lib/utils/array.mjs.map +1 -1
  313. package/lib/utils/money/allocators/fixedAmount.d.ts +26 -0
  314. package/lib/utils/money/allocators/fixedAmount.js +52 -0
  315. package/lib/utils/money/allocators/fixedAmount.js.map +1 -0
  316. package/lib/utils/money/allocators/fixedAmount.mjs +50 -0
  317. package/lib/utils/money/allocators/fixedAmount.mjs.map +1 -0
  318. package/lib/utils/money/allocators/index.d.ts +2 -0
  319. package/lib/utils/money/allocators/index.js +8 -0
  320. package/lib/utils/money/allocators/index.js.map +1 -0
  321. package/lib/utils/money/allocators/index.mjs +4 -0
  322. package/lib/utils/money/allocators/index.mjs.map +1 -0
  323. package/lib/utils/money/allocators/productAmount.d.ts +13 -0
  324. package/lib/utils/money/allocators/productAmount.js +98 -0
  325. package/lib/utils/money/allocators/productAmount.js.map +1 -0
  326. package/lib/utils/money/allocators/productAmount.mjs +96 -0
  327. package/lib/utils/money/allocators/productAmount.mjs.map +1 -0
  328. package/lib/utils/money/constants.d.ts +56 -25
  329. package/lib/utils/money/constants.js +72 -7
  330. package/lib/utils/money/constants.js.map +1 -1
  331. package/lib/utils/money/constants.mjs +70 -7
  332. package/lib/utils/money/constants.mjs.map +1 -1
  333. package/lib/utils/money/exchangeRate.d.ts +31 -0
  334. package/lib/utils/money/exchangeRate.js +27 -0
  335. package/lib/utils/money/exchangeRate.js.map +1 -0
  336. package/lib/utils/money/exchangeRate.mjs +23 -0
  337. package/lib/utils/money/exchangeRate.mjs.map +1 -0
  338. package/lib/utils/money/format.d.ts +10 -5
  339. package/lib/utils/money/format.js +22 -14
  340. package/lib/utils/money/format.js.map +1 -1
  341. package/lib/utils/money/format.mjs +23 -16
  342. package/lib/utils/money/format.mjs.map +1 -1
  343. package/lib/utils/money/index.d.ts +4 -1
  344. package/lib/utils/money/index.js +26 -8
  345. package/lib/utils/money/index.js.map +1 -1
  346. package/lib/utils/money/index.mjs +8 -4
  347. package/lib/utils/money/index.mjs.map +1 -1
  348. package/lib/utils/money/misc.d.ts +68 -28
  349. package/lib/utils/money/misc.js +35 -64
  350. package/lib/utils/money/misc.js.map +1 -1
  351. package/lib/utils/money/misc.mjs +32 -43
  352. package/lib/utils/money/misc.mjs.map +1 -1
  353. package/lib/utils/money/misc.private.d.ts +23 -0
  354. package/lib/utils/money/misc.private.js +46 -0
  355. package/lib/utils/money/misc.private.js.map +1 -0
  356. package/lib/utils/money/misc.private.mjs +21 -0
  357. package/lib/utils/money/misc.private.mjs.map +1 -0
  358. package/lib/utils/money/shipping.d.ts +5 -0
  359. package/lib/utils/money/shipping.js +8 -0
  360. package/lib/utils/money/shipping.js.map +1 -0
  361. package/lib/utils/money/shipping.mjs +6 -0
  362. package/lib/utils/money/shipping.mjs.map +1 -0
  363. package/lib/utils/money/tax.d.ts +38 -2
  364. package/lib/utils/money/tax.js +46 -10
  365. package/lib/utils/money/tax.js.map +1 -1
  366. package/lib/utils/money/tax.mjs +42 -11
  367. package/lib/utils/money/tax.mjs.map +1 -1
  368. package/lib/utils/money/tax.private.d.ts +17 -0
  369. package/lib/utils/money/tax.private.js +65 -0
  370. package/lib/utils/money/tax.private.js.map +1 -0
  371. package/lib/utils/money/tax.private.mjs +60 -0
  372. package/lib/utils/money/tax.private.mjs.map +1 -0
  373. package/lib/utils/money/types.d.ts +78 -3
  374. package/lib/utils/number.d.ts +1 -1
  375. package/lib/utils/number.js +1 -1
  376. package/lib/utils/number.js.map +1 -1
  377. package/lib/utils/number.mjs +1 -1
  378. package/lib/utils/number.mjs.map +1 -1
  379. package/lib/utils/productSort.d.ts +41 -0
  380. package/lib/utils/productSort.js +67 -0
  381. package/lib/utils/productSort.js.map +1 -0
  382. package/lib/utils/productSort.mjs +60 -0
  383. package/lib/utils/productSort.mjs.map +1 -0
  384. package/package.json +1 -1
  385. package/lib/assets/icons/menu/icon-globe.svg.js.map +0 -1
  386. package/lib/assets/icons/menu/icon-globe.svg.mjs +0 -3
  387. package/lib/assets/icons/menu/icon-globe.svg.mjs.map +0 -1
  388. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +0 -1
  389. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +0 -1
  390. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +0 -1
  391. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +0 -1
  392. package/lib/components/ResourceCalculatorV1/components/index.d.ts +0 -1
  393. package/lib/components/ResourceCalculatorV1/components/index.js +0 -5
  394. package/lib/components/ResourceCalculatorV1/components/index.mjs +0 -3
  395. package/lib/utils/validations.d.ts +0 -15
  396. package/lib/utils/validations.js +0 -23
  397. package/lib/utils/validations.js.map +0 -1
  398. package/lib/utils/validations.mjs +0 -21
  399. package/lib/utils/validations.mjs.map +0 -1
  400. /package/lib/components/{ResourceCalculatorV1/components → Header/Navigation/ProMenu}/index.mjs.map +0 -0
  401. /package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/index.d.ts +0 -0
  402. /package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/index.js +0 -0
  403. /package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/index.js.map +0 -0
  404. /package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/index.mjs +0 -0
  405. /package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/index.mjs.map +0 -0
@@ -0,0 +1,87 @@
1
+ import type { Currency } from "../types";
2
+ export declare enum DisplayProductStatus {
3
+ Available = "Available",
4
+ Backorder = "Backorder",
5
+ ComingSoon = "ComingSoon",
6
+ RegionNotAvailable = "RegionNotAvailable",
7
+ SoldOut = "SoldOut",
8
+ Unavailable = "Unavailable"
9
+ }
10
+ export type CollectionSection = {
11
+ id: string;
12
+ productTags: Array<string>;
13
+ title: string;
14
+ };
15
+ export interface Section extends CollectionSection {
16
+ items: Section[];
17
+ }
18
+ export type ProductTagFragment = {
19
+ __typename?: "ProductTag";
20
+ name: string;
21
+ };
22
+ export interface MappedProductSection<T> extends Section {
23
+ items: MappedProductSection<T>[];
24
+ products: T[];
25
+ /**
26
+ * States which is conditionally calculated based on the need.
27
+ * E.g. if it is an optical collection where collection sections
28
+ * are rendered inside the VariantSelector items, we need to
29
+ * know which section does not contain products that are in stock.
30
+ * If all products in the section are out of stock, we need to
31
+ * apply grayed out style to the section button.
32
+ */
33
+ isDisabled?: boolean;
34
+ }
35
+ export interface StorefrontProduct {
36
+ id: string;
37
+ slug: string;
38
+ title: string;
39
+ shortTitle?: string | null;
40
+ collectionSlug?: string | null;
41
+ organizationalCollectionSlug?: string | null;
42
+ proCollectionSlug?: string | null;
43
+ status: DisplayProductStatus;
44
+ options: Array<{
45
+ __typename?: "StorefrontOption";
46
+ id: string;
47
+ title: string;
48
+ slug: string;
49
+ values: Array<{
50
+ __typename?: "StorefrontOptionValue";
51
+ id: string;
52
+ title: string;
53
+ slug: string;
54
+ }>;
55
+ }>;
56
+ tags: Array<{
57
+ __typename?: "ProductTag";
58
+ name: string;
59
+ }>;
60
+ minDisplayPrice: {
61
+ __typename?: "Money";
62
+ amount: number;
63
+ currency: Currency;
64
+ };
65
+ variants: Array<{
66
+ __typename?: "StorefrontProductVariant";
67
+ id: string;
68
+ status: DisplayProductStatus;
69
+ availableInOtherStores: Array<{
70
+ __typename: "StorefrontProductVariantAlternativeStore";
71
+ }>;
72
+ optionValueIds?: Array<string> | null;
73
+ }>;
74
+ }
75
+ export type StorefrontOptionValue = {
76
+ __typename?: "StorefrontOptionValue";
77
+ id: string;
78
+ slug: string;
79
+ title: string;
80
+ };
81
+ export type StorefrontOption = {
82
+ __typename?: "StorefrontOption";
83
+ id: string;
84
+ slug: string;
85
+ title: string;
86
+ values: Array<StorefrontOptionValue>;
87
+ };
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+ "use strict";
3
+
4
+ var DisplayProductStatus = /* @__PURE__ */(DisplayProductStatus2 => {
5
+ DisplayProductStatus2["Available"] = "Available";
6
+ DisplayProductStatus2["Backorder"] = "Backorder";
7
+ DisplayProductStatus2["ComingSoon"] = "ComingSoon";
8
+ DisplayProductStatus2["RegionNotAvailable"] = "RegionNotAvailable";
9
+ DisplayProductStatus2["SoldOut"] = "SoldOut";
10
+ DisplayProductStatus2["Unavailable"] = "Unavailable";
11
+ return DisplayProductStatus2;
12
+ })(DisplayProductStatus || {});
13
+ exports.DisplayProductStatus = DisplayProductStatus;
14
+ //# sourceMappingURL=product.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product.js","sources":["../../src/types/product.ts"],"sourcesContent":["import type { Currency } from \"../types\";\n\n\nexport enum DisplayProductStatus {\n Available = \"Available\",\n Backorder = \"Backorder\",\n ComingSoon = \"ComingSoon\",\n RegionNotAvailable = \"RegionNotAvailable\",\n SoldOut = \"SoldOut\",\n Unavailable = \"Unavailable\",\n}\n\nexport type CollectionSection = {\n id: string;\n productTags: Array<string>;\n title: string;\n};\n\nexport interface Section extends CollectionSection {\n items: Section[];\n}\n\nexport type ProductTagFragment = { __typename?: \"ProductTag\"; name: string };\n\nexport interface MappedProductSection<T> extends Section {\n items: MappedProductSection<T>[];\n products: T[];\n /**\n * States which is conditionally calculated based on the need.\n * E.g. if it is an optical collection where collection sections\n * are rendered inside the VariantSelector items, we need to\n * know which section does not contain products that are in stock.\n * If all products in the section are out of stock, we need to\n * apply grayed out style to the section button.\n */\n isDisabled?: boolean;\n}\n\nexport interface StorefrontProduct {\n id: string;\n slug: string;\n title: string;\n shortTitle?: string | null;\n collectionSlug?: string | null;\n organizationalCollectionSlug?: string | null;\n proCollectionSlug?: string | null;\n status: DisplayProductStatus;\n options: Array<{\n __typename?: \"StorefrontOption\";\n id: string;\n title: string;\n slug: string;\n values: Array<{\n __typename?: \"StorefrontOptionValue\";\n id: string;\n title: string;\n slug: string;\n }>;\n }>;\n tags: Array<{ __typename?: \"ProductTag\"; name: string }>;\n minDisplayPrice: { __typename?: \"Money\"; amount: number; currency: Currency };\n variants: Array<{\n __typename?: \"StorefrontProductVariant\";\n id: string;\n status: DisplayProductStatus;\n availableInOtherStores: Array<{\n __typename: \"StorefrontProductVariantAlternativeStore\";\n }>;\n optionValueIds?: Array<string> | null;\n }>;\n}\n\nexport type StorefrontOptionValue = {\n __typename?: \"StorefrontOptionValue\";\n id: string;\n slug: string;\n title: string;\n};\n\nexport type StorefrontOption = {\n __typename?: \"StorefrontOption\";\n id: string;\n slug: string;\n title: string;\n values: Array<StorefrontOptionValue>;\n};\n"],"names":["DisplayProductStatus"],"mappings":";;;AAGY,IAAAA,oBAAA,GAAA,gBAAAA,qBAAL,IAAA;EACLA,sBAAA,WAAY,CAAA,GAAA,WAAA;EACZA,sBAAA,WAAY,CAAA,GAAA,WAAA;EACZA,sBAAA,YAAa,CAAA,GAAA,YAAA;EACbA,sBAAA,oBAAqB,CAAA,GAAA,oBAAA;EACrBA,sBAAA,SAAU,CAAA,GAAA,SAAA;EACVA,sBAAA,aAAc,CAAA,GAAA,aAAA;EANJA,OAAAA,qBAAAA;AAAA,CAAA,EAAAA,oBAAA,IAAA,CAAA,CAAA,CAAA;"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var DisplayProductStatus = /* @__PURE__ */(DisplayProductStatus2 => {
4
+ DisplayProductStatus2["Available"] = "Available";
5
+ DisplayProductStatus2["Backorder"] = "Backorder";
6
+ DisplayProductStatus2["ComingSoon"] = "ComingSoon";
7
+ DisplayProductStatus2["RegionNotAvailable"] = "RegionNotAvailable";
8
+ DisplayProductStatus2["SoldOut"] = "SoldOut";
9
+ DisplayProductStatus2["Unavailable"] = "Unavailable";
10
+ return DisplayProductStatus2;
11
+ })(DisplayProductStatus || {});
12
+ export { DisplayProductStatus };
13
+ //# sourceMappingURL=product.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product.mjs","sources":["../../src/types/product.ts"],"sourcesContent":["import type { Currency } from \"../types\";\n\n\nexport enum DisplayProductStatus {\n Available = \"Available\",\n Backorder = \"Backorder\",\n ComingSoon = \"ComingSoon\",\n RegionNotAvailable = \"RegionNotAvailable\",\n SoldOut = \"SoldOut\",\n Unavailable = \"Unavailable\",\n}\n\nexport type CollectionSection = {\n id: string;\n productTags: Array<string>;\n title: string;\n};\n\nexport interface Section extends CollectionSection {\n items: Section[];\n}\n\nexport type ProductTagFragment = { __typename?: \"ProductTag\"; name: string };\n\nexport interface MappedProductSection<T> extends Section {\n items: MappedProductSection<T>[];\n products: T[];\n /**\n * States which is conditionally calculated based on the need.\n * E.g. if it is an optical collection where collection sections\n * are rendered inside the VariantSelector items, we need to\n * know which section does not contain products that are in stock.\n * If all products in the section are out of stock, we need to\n * apply grayed out style to the section button.\n */\n isDisabled?: boolean;\n}\n\nexport interface StorefrontProduct {\n id: string;\n slug: string;\n title: string;\n shortTitle?: string | null;\n collectionSlug?: string | null;\n organizationalCollectionSlug?: string | null;\n proCollectionSlug?: string | null;\n status: DisplayProductStatus;\n options: Array<{\n __typename?: \"StorefrontOption\";\n id: string;\n title: string;\n slug: string;\n values: Array<{\n __typename?: \"StorefrontOptionValue\";\n id: string;\n title: string;\n slug: string;\n }>;\n }>;\n tags: Array<{ __typename?: \"ProductTag\"; name: string }>;\n minDisplayPrice: { __typename?: \"Money\"; amount: number; currency: Currency };\n variants: Array<{\n __typename?: \"StorefrontProductVariant\";\n id: string;\n status: DisplayProductStatus;\n availableInOtherStores: Array<{\n __typename: \"StorefrontProductVariantAlternativeStore\";\n }>;\n optionValueIds?: Array<string> | null;\n }>;\n}\n\nexport type StorefrontOptionValue = {\n __typename?: \"StorefrontOptionValue\";\n id: string;\n slug: string;\n title: string;\n};\n\nexport type StorefrontOption = {\n __typename?: \"StorefrontOption\";\n id: string;\n slug: string;\n title: string;\n values: Array<StorefrontOptionValue>;\n};\n"],"names":["DisplayProductStatus"],"mappings":";;AAGY,IAAAA,oBAAA,GAAA,gBAAAA,qBAAL,IAAA;EACLA,sBAAA,WAAY,CAAA,GAAA,WAAA;EACZA,sBAAA,WAAY,CAAA,GAAA,WAAA;EACZA,sBAAA,YAAa,CAAA,GAAA,YAAA;EACbA,sBAAA,oBAAqB,CAAA,GAAA,oBAAA;EACrBA,sBAAA,SAAU,CAAA,GAAA,SAAA;EACVA,sBAAA,aAAc,CAAA,GAAA,aAAA;EANJA,OAAAA,qBAAAA;AAAA,CAAA,EAAAA,oBAAA,IAAA,CAAA,CAAA,CAAA;"}
@@ -28,3 +28,7 @@ export declare const arraySafeIndexFind: <T>(array: T[], index: number) => T | u
28
28
  * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts
29
29
  */
30
30
  export declare const normalizeSortResult: (sortResult: number) => number;
31
+ /**
32
+ * Combine multiple sort functions into one
33
+ */
34
+ export declare const combineSorts: <T>(sorts: ((a: T, b: T) => number)[]) => ((a: T, b: T) => number);
@@ -24,9 +24,19 @@ const arraySafeIndexFind = (array, index) => {
24
24
  return array[safeIndex];
25
25
  };
26
26
  const normalizeSortResult = sortResult => number.clamp(sortResult, -1, 1);
27
+ const combineSorts = sorts => (a, b) => {
28
+ for (const sort of sorts) {
29
+ const result = sort(a, b);
30
+ if (result !== 0) {
31
+ return result;
32
+ }
33
+ }
34
+ return 0;
35
+ };
27
36
  exports.areEqualArrays = areEqualArrays;
28
37
  exports.arraySafeIndex = arraySafeIndex;
29
38
  exports.arraySafeIndexFind = arraySafeIndexFind;
39
+ exports.combineSorts = combineSorts;
30
40
  exports.dedupe = dedupe;
31
41
  exports.ensureArray = ensureArray;
32
42
  exports.normalizeSortResult = normalizeSortResult;
@@ -1 +1 @@
1
- {"version":3,"file":"array.js","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp"],"mappings":";;;;AAMO,SAASA,YAAeC,KAAqB,EAAA;EAClD,OAAOC,MAAMC,OAAQ,CAAAF,KAAK,CAAI,GAAAA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOa,MAAAG,MAAA,GAAaC,GAAa,IAAA,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAS1C,MAAAE,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAyB,KAAA;EAC/D,IAAAD,CAAA,CAAEE,MAAW,KAAAD,CAAA,CAAEC,MAAQ,EAAA;IAClB,OAAA,KAAA;EACT;EACI,IAAA,CAACF,EAAEG,KAAM,CAACC,MAAOH,CAAE,CAAAI,QAAA,CAASD,EAAE,CAAC,CAAG,EAAA;IAC7B,OAAA,KAAA;EACT;EACO,OAAA,CAACH,CAAE,CAAAE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAS,CAAAD,EAAE,CAAC,CAAA,GAAI,KAAQ,GAAA,IAAA;AACpD,CAAA;AAOa,MAAAE,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAA0B,KAAA;EACtE,MAAMC,YAAYF,KAAM,CAAAL,MAAA;EAEf,OAAA,CAAAM,KAAA,GAAQC,YAAaA,SAAa,IAAAA,SAAA;AAC7C,CAAA;AAEa,MAAAC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KACkB,KAAA;EACZ,MAAAG,SAAA,GAAYL,cAAe,CAAAC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,MAAAA,CAAAA,KAAM,CAAAD,UAAA,EAAY,IAAI,CAAC,CAAA;;;;;;"}
1
+ {"version":3,"file":"array.js","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n\n/**\n * Combine multiple sort functions into one\n */\nexport const combineSorts =\n <T>(sorts: ((a: T, b: T) => number)[]): ((a: T, b: T) => number) =>\n (a, b) => {\n for (const sort of sorts) {\n const result = sort(a, b);\n\n if (result !== 0) {\n return result;\n }\n }\n\n return 0;\n };\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp","combineSorts","sorts","sort","result"],"mappings":";;;;AAMO,SAASA,YAAeC,KAAqB,EAAA;EAClD,OAAOC,MAAMC,OAAQ,CAAAF,KAAK,CAAI,GAAAA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOa,MAAAG,MAAA,GAAaC,GAAa,IAAA,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAS1C,MAAAE,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAyB,KAAA;EAC/D,IAAAD,CAAA,CAAEE,MAAW,KAAAD,CAAA,CAAEC,MAAQ,EAAA;IAClB,OAAA,KAAA;EACT;EACI,IAAA,CAACF,EAAEG,KAAM,CAACC,MAAOH,CAAE,CAAAI,QAAA,CAASD,EAAE,CAAC,CAAG,EAAA;IAC7B,OAAA,KAAA;EACT;EACO,OAAA,CAACH,CAAE,CAAAE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAS,CAAAD,EAAE,CAAC,CAAA,GAAI,KAAQ,GAAA,IAAA;AACpD,CAAA;AAOa,MAAAE,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAA0B,KAAA;EACtE,MAAMC,YAAYF,KAAM,CAAAL,MAAA;EAEf,OAAA,CAAAM,KAAA,GAAQC,YAAaA,SAAa,IAAAA,SAAA;AAC7C,CAAA;AAEa,MAAAC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KACkB,KAAA;EACZ,MAAAG,SAAA,GAAYL,cAAe,CAAAC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,MAAAA,CAAAA,KAAM,CAAAD,UAAA,EAAY,IAAI,CAAC,CAAA;AAKlB,MAAME,YACX,GAAIC,KACJ,IAAA,CAAChB,GAAGC,CAAM,KAAA;EACR,KAAA,MAAWgB,QAAQD,KAAO,EAAA;IAClB,MAAAE,MAAA,GAASD,IAAK,CAAAjB,CAAA,EAAGC,CAAC,CAAA;IAExB,IAAIiB,WAAW,CAAG,EAAA;MACT,OAAAA,MAAA;IACT;EACF;EAEO,OAAA,CAAA;AACT,CAAA;;;;;;;"}
@@ -22,5 +22,14 @@ const arraySafeIndexFind = (array, index) => {
22
22
  return array[safeIndex];
23
23
  };
24
24
  const normalizeSortResult = sortResult => clamp(sortResult, -1, 1);
25
- export { areEqualArrays, arraySafeIndex, arraySafeIndexFind, dedupe, ensureArray, normalizeSortResult };
25
+ const combineSorts = sorts => (a, b) => {
26
+ for (const sort of sorts) {
27
+ const result = sort(a, b);
28
+ if (result !== 0) {
29
+ return result;
30
+ }
31
+ }
32
+ return 0;
33
+ };
34
+ export { areEqualArrays, arraySafeIndex, arraySafeIndexFind, combineSorts, dedupe, ensureArray, normalizeSortResult };
26
35
  //# sourceMappingURL=array.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"array.mjs","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp"],"mappings":";;AAMO,SAASA,YAAeC,KAAqB,EAAA;EAClD,OAAOC,MAAMC,OAAQ,CAAAF,KAAK,CAAI,GAAAA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOa,MAAAG,MAAA,GAAaC,GAAa,IAAA,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAS1C,MAAAE,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAyB,KAAA;EAC/D,IAAAD,CAAA,CAAEE,MAAW,KAAAD,CAAA,CAAEC,MAAQ,EAAA;IAClB,OAAA,KAAA;EACT;EACI,IAAA,CAACF,EAAEG,KAAM,CAACC,MAAOH,CAAE,CAAAI,QAAA,CAASD,EAAE,CAAC,CAAG,EAAA;IAC7B,OAAA,KAAA;EACT;EACO,OAAA,CAACH,CAAE,CAAAE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAS,CAAAD,EAAE,CAAC,CAAA,GAAI,KAAQ,GAAA,IAAA;AACpD,CAAA;AAOa,MAAAE,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAA0B,KAAA;EACtE,MAAMC,YAAYF,KAAM,CAAAL,MAAA;EAEf,OAAA,CAAAM,KAAA,GAAQC,YAAaA,SAAa,IAAAA,SAAA;AAC7C,CAAA;AAEa,MAAAC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KACkB,KAAA;EACZ,MAAAG,SAAA,GAAYL,cAAe,CAAAC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,KAAM,CAAAD,UAAA,EAAY,IAAI,CAAC,CAAA;"}
1
+ {"version":3,"file":"array.mjs","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n\n/**\n * Combine multiple sort functions into one\n */\nexport const combineSorts =\n <T>(sorts: ((a: T, b: T) => number)[]): ((a: T, b: T) => number) =>\n (a, b) => {\n for (const sort of sorts) {\n const result = sort(a, b);\n\n if (result !== 0) {\n return result;\n }\n }\n\n return 0;\n };\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp","combineSorts","sorts","sort","result"],"mappings":";;AAMO,SAASA,YAAeC,KAAqB,EAAA;EAClD,OAAOC,MAAMC,OAAQ,CAAAF,KAAK,CAAI,GAAAA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOa,MAAAG,MAAA,GAAaC,GAAa,IAAA,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAS1C,MAAAE,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAyB,KAAA;EAC/D,IAAAD,CAAA,CAAEE,MAAW,KAAAD,CAAA,CAAEC,MAAQ,EAAA;IAClB,OAAA,KAAA;EACT;EACI,IAAA,CAACF,EAAEG,KAAM,CAACC,MAAOH,CAAE,CAAAI,QAAA,CAASD,EAAE,CAAC,CAAG,EAAA;IAC7B,OAAA,KAAA;EACT;EACO,OAAA,CAACH,CAAE,CAAAE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAS,CAAAD,EAAE,CAAC,CAAA,GAAI,KAAQ,GAAA,IAAA;AACpD,CAAA;AAOa,MAAAE,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAA0B,KAAA;EACtE,MAAMC,YAAYF,KAAM,CAAAL,MAAA;EAEf,OAAA,CAAAM,KAAA,GAAQC,YAAaA,SAAa,IAAAA,SAAA;AAC7C,CAAA;AAEa,MAAAC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KACkB,KAAA;EACZ,MAAAG,SAAA,GAAYL,cAAe,CAAAC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,KAAM,CAAAD,UAAA,EAAY,IAAI,CAAC,CAAA;AAKlB,MAAME,YACX,GAAIC,KACJ,IAAA,CAAChB,GAAGC,CAAM,KAAA;EACR,KAAA,MAAWgB,QAAQD,KAAO,EAAA;IAClB,MAAAE,MAAA,GAASD,IAAK,CAAAjB,CAAA,EAAGC,CAAC,CAAA;IAExB,IAAIiB,WAAW,CAAG,EAAA;MACT,OAAAA,MAAA;IACT;EACF;EAEO,OAAA,CAAA;AACT,CAAA;"}
@@ -0,0 +1,26 @@
1
+ import type { Currency } from "../../../types";
2
+ import type { Cents, Dino, DinoCurrency } from "../types";
3
+ /**
4
+ * Helper class to distribute a fixed amount (e.g. discount) between multiple items.
5
+ * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible
6
+ */
7
+ export declare class FixedAmountAllocator {
8
+ /**
9
+ * How much we have left to allocate for given allocation from the remaining total
10
+ */
11
+ remainingAllocationAmount: Dino;
12
+ /**
13
+ * How much we have left to allocate in total
14
+ */
15
+ remainingTotalAmount: Dino;
16
+ currency: DinoCurrency;
17
+ constructor({ initialAllocateAmount, initialTotalAmount, currency, }: {
18
+ initialAllocateAmount: Cents;
19
+ initialTotalAmount: Cents;
20
+ currency: Currency;
21
+ });
22
+ /**
23
+ * We always allocate biggest share to first item
24
+ */
25
+ allocate(lineItemTotal: Cents, currency: Currency): Dino;
26
+ }
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ var dinero_js = require('dinero.js');
4
+ var errors = require('../../errors.js');
5
+ var misc = require('../misc.js');
6
+ "use strict";
7
+ var __defProp = Object.defineProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value
13
+ }) : obj[key] = value;
14
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
+ class FixedAmountAllocator {
16
+ constructor({
17
+ initialAllocateAmount,
18
+ initialTotalAmount,
19
+ currency
20
+ }) {
21
+ /**
22
+ * How much we have left to allocate for given allocation from the remaining total
23
+ */
24
+ __publicField(this, "remainingAllocationAmount");
25
+ /**
26
+ * How much we have left to allocate in total
27
+ */
28
+ __publicField(this, "remainingTotalAmount");
29
+ __publicField(this, "currency");
30
+ this.remainingAllocationAmount = misc.getDinero(initialAllocateAmount, currency);
31
+ this.remainingTotalAmount = misc.getDinero(initialTotalAmount, currency);
32
+ this.currency = misc.getDineroCurrency(currency);
33
+ }
34
+ /**
35
+ * We always allocate biggest share to first item
36
+ */
37
+ allocate(lineItemTotal, currency) {
38
+ errors.assert(this.currency.code === currency, `Currency mismatch, expected ${currency}, got ${this.currency.code}`);
39
+ const lineItemTotalDinero = misc.getDinero(lineItemTotal, currency);
40
+ if (lineItemTotal === 0) {
41
+ return lineItemTotalDinero;
42
+ }
43
+ const [allocationAmount, remainingAllocationAmount] = dinero_js.allocate(this.remainingAllocationAmount, [lineItemTotal, Math.max(misc.amount(this.remainingTotalAmount) - lineItemTotal, 0)]);
44
+ errors.assert(!!allocationAmount, "Allocation amount is zero");
45
+ errors.assert(!!remainingAllocationAmount, "Remaining allocation remainder is zero");
46
+ this.remainingAllocationAmount = remainingAllocationAmount;
47
+ this.remainingTotalAmount = dinero_js.subtract(this.remainingTotalAmount, lineItemTotalDinero);
48
+ return dinero_js.greaterThan(allocationAmount, lineItemTotalDinero) ? lineItemTotalDinero : allocationAmount;
49
+ }
50
+ }
51
+ exports.FixedAmountAllocator = FixedAmountAllocator;
52
+ //# sourceMappingURL=fixedAmount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixedAmount.js","sources":["../../../../src/utils/money/allocators/fixedAmount.ts"],"sourcesContent":["import { allocate, greaterThan, subtract } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { amount, getDinero, getDineroCurrency } from \"../misc\";\nimport type { Cents, Dino, DinoCurrency } from \"../types\";\n\n/**\n * Helper class to distribute a fixed amount (e.g. discount) between multiple items.\n * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible\n */\nexport class FixedAmountAllocator {\n /**\n * How much we have left to allocate for given allocation from the remaining total\n */\n public remainingAllocationAmount: Dino;\n /**\n * How much we have left to allocate in total\n */\n public remainingTotalAmount: Dino;\n public currency: DinoCurrency;\n\n constructor({\n initialAllocateAmount,\n initialTotalAmount,\n currency,\n }: {\n initialAllocateAmount: Cents;\n initialTotalAmount: Cents;\n currency: Currency;\n }) {\n this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);\n this.remainingTotalAmount = getDinero(initialTotalAmount, currency);\n this.currency = getDineroCurrency(currency);\n }\n\n /**\n * We always allocate biggest share to first item\n */\n allocate(lineItemTotal: Cents, currency: Currency): Dino {\n assert(\n this.currency.code === currency,\n `Currency mismatch, expected ${currency}, got ${this.currency.code}`,\n );\n const lineItemTotalDinero = getDinero(lineItemTotal, currency);\n /**\n * If total price of line items is zero, it means it's free, thus no discount\n * can be calculated (it's either 0 or infinity, but let's go with 0)\n */\n if (lineItemTotal === 0) {\n return lineItemTotalDinero;\n }\n\n const [allocationAmount, remainingAllocationAmount] = allocate(\n this.remainingAllocationAmount,\n [\n lineItemTotal,\n Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0),\n ],\n );\n\n assert(!!allocationAmount, \"Allocation amount is zero\");\n assert(\n !!remainingAllocationAmount,\n \"Remaining allocation remainder is zero\",\n );\n\n this.remainingAllocationAmount = remainingAllocationAmount;\n this.remainingTotalAmount = subtract(\n this.remainingTotalAmount,\n lineItemTotalDinero,\n );\n\n /**\n * The discount amount is evenly split but can still be higher than the line item total\n * Need to ceil the price to be not more than the line item total\n */\n return greaterThan(allocationAmount, lineItemTotalDinero)\n ? lineItemTotalDinero\n : allocationAmount;\n }\n}\n"],"names":["FixedAmountAllocator","constructor","initialAllocateAmount","initialTotalAmount","currency","__publicField","remainingAllocationAmount","getDinero","remainingTotalAmount","getDineroCurrency","allocate","lineItemTotal","assert","code","lineItemTotalDinero","allocationAmount","Math","max","amount","subtract","greaterThan"],"mappings":";;;;;;;;;;;;;;AAWO,MAAMA,oBAAqB,CAAA;EAWhCC,WAAYA,CAAA;IACVC,qBAAA;IACAC,kBAAA;IACAC;EAAA,CAKC,EAAA;IAfH;AAAA;AAAA;IAAOC,aAAA,CAAA,IAAA,EAAA,2BAAA,CAAA;IAIP;AAAA;AAAA;IAAOA,aAAA,CAAA,IAAA,EAAA,sBAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAWA,IAAA,CAAAC,yBAAA,GAA4BC,IAAAA,CAAAA,SAAU,CAAAL,qBAAA,EAAuBE,QAAQ,CAAA;IACrE,IAAA,CAAAI,oBAAA,GAAuBD,IAAAA,CAAAA,SAAU,CAAAJ,kBAAA,EAAoBC,QAAQ,CAAA;IAC7D,IAAA,CAAAA,QAAA,GAAWK,uBAAkBL,QAAQ,CAAA;EAC5C;EAAA;AAAA;AAAA;EAKAM,QAAAA,CAASC,eAAsBP,QAA0B,EAAA;IACvDQ,MAAA,CAAAA,MAAA,CACE,IAAA,CAAKR,SAASS,IAAS,KAAAT,QAAA,EACQ,+BAAAA,QAAiB,SAAA,IAAA,CAAKA,SAASS,IAAI,EAAA,CACpE;IACM,MAAAC,mBAAA,GAAsBP,IAAAA,CAAAA,SAAU,CAAAI,aAAA,EAAeP,QAAQ,CAAA;IAK7D,IAAIO,kBAAkB,CAAG,EAAA;MAChB,OAAAG,mBAAA;IACT;IAEM,MAAA,CAACC,gBAAkB,EAAAT,yBAAyB,CAAI,GAAAI,SAAA,CAAAA,QAAA,CACpD,IAAK,CAAAJ,yBAAA,EACL,CACEK,aAAA,EACAK,KAAKC,GAAI,CAAAC,WAAA,CAAO,KAAKV,oBAAoB,CAAA,GAAIG,eAAe,CAAC,CAAA,CAC/D,CACF;IAEOC,MAAAA,CAAAA,MAAA,CAAA,CAAC,CAACG,gBAAA,EAAkB,2BAA2B,CAAA;IACtDH,MAAA,CAAAA,MAAA,CACE,CAAC,CAACN,yBAAA,EACF,wCAAA,CACF;IAEA,IAAA,CAAKA,yBAA4B,GAAAA,yBAAA;IACjC,IAAA,CAAKE,oBAAuB,GAAAW,SAAA,CAAAA,QAAA,CAC1B,IAAK,CAAAX,oBAAA,EACLM,mBAAA,CACF;IAMA,OAAOM,SAAY,CAAAA,WAAA,CAAAL,gBAAA,EAAkBD,mBAAmB,CAAA,GACpDA,mBACA,GAAAC,gBAAA;EACN;AACF;"}
@@ -0,0 +1,50 @@
1
+ import { allocate, subtract, greaterThan } from 'dinero.js';
2
+ import { assert } from '../../errors.mjs';
3
+ import { getDinero, getDineroCurrency, amount } from '../misc.mjs';
4
+ "use strict";
5
+ var __defProp = Object.defineProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value
11
+ }) : obj[key] = value;
12
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
13
+ class FixedAmountAllocator {
14
+ constructor({
15
+ initialAllocateAmount,
16
+ initialTotalAmount,
17
+ currency
18
+ }) {
19
+ /**
20
+ * How much we have left to allocate for given allocation from the remaining total
21
+ */
22
+ __publicField(this, "remainingAllocationAmount");
23
+ /**
24
+ * How much we have left to allocate in total
25
+ */
26
+ __publicField(this, "remainingTotalAmount");
27
+ __publicField(this, "currency");
28
+ this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);
29
+ this.remainingTotalAmount = getDinero(initialTotalAmount, currency);
30
+ this.currency = getDineroCurrency(currency);
31
+ }
32
+ /**
33
+ * We always allocate biggest share to first item
34
+ */
35
+ allocate(lineItemTotal, currency) {
36
+ assert(this.currency.code === currency, `Currency mismatch, expected ${currency}, got ${this.currency.code}`);
37
+ const lineItemTotalDinero = getDinero(lineItemTotal, currency);
38
+ if (lineItemTotal === 0) {
39
+ return lineItemTotalDinero;
40
+ }
41
+ const [allocationAmount, remainingAllocationAmount] = allocate(this.remainingAllocationAmount, [lineItemTotal, Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0)]);
42
+ assert(!!allocationAmount, "Allocation amount is zero");
43
+ assert(!!remainingAllocationAmount, "Remaining allocation remainder is zero");
44
+ this.remainingAllocationAmount = remainingAllocationAmount;
45
+ this.remainingTotalAmount = subtract(this.remainingTotalAmount, lineItemTotalDinero);
46
+ return greaterThan(allocationAmount, lineItemTotalDinero) ? lineItemTotalDinero : allocationAmount;
47
+ }
48
+ }
49
+ export { FixedAmountAllocator };
50
+ //# sourceMappingURL=fixedAmount.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixedAmount.mjs","sources":["../../../../src/utils/money/allocators/fixedAmount.ts"],"sourcesContent":["import { allocate, greaterThan, subtract } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { amount, getDinero, getDineroCurrency } from \"../misc\";\nimport type { Cents, Dino, DinoCurrency } from \"../types\";\n\n/**\n * Helper class to distribute a fixed amount (e.g. discount) between multiple items.\n * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible\n */\nexport class FixedAmountAllocator {\n /**\n * How much we have left to allocate for given allocation from the remaining total\n */\n public remainingAllocationAmount: Dino;\n /**\n * How much we have left to allocate in total\n */\n public remainingTotalAmount: Dino;\n public currency: DinoCurrency;\n\n constructor({\n initialAllocateAmount,\n initialTotalAmount,\n currency,\n }: {\n initialAllocateAmount: Cents;\n initialTotalAmount: Cents;\n currency: Currency;\n }) {\n this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);\n this.remainingTotalAmount = getDinero(initialTotalAmount, currency);\n this.currency = getDineroCurrency(currency);\n }\n\n /**\n * We always allocate biggest share to first item\n */\n allocate(lineItemTotal: Cents, currency: Currency): Dino {\n assert(\n this.currency.code === currency,\n `Currency mismatch, expected ${currency}, got ${this.currency.code}`,\n );\n const lineItemTotalDinero = getDinero(lineItemTotal, currency);\n /**\n * If total price of line items is zero, it means it's free, thus no discount\n * can be calculated (it's either 0 or infinity, but let's go with 0)\n */\n if (lineItemTotal === 0) {\n return lineItemTotalDinero;\n }\n\n const [allocationAmount, remainingAllocationAmount] = allocate(\n this.remainingAllocationAmount,\n [\n lineItemTotal,\n Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0),\n ],\n );\n\n assert(!!allocationAmount, \"Allocation amount is zero\");\n assert(\n !!remainingAllocationAmount,\n \"Remaining allocation remainder is zero\",\n );\n\n this.remainingAllocationAmount = remainingAllocationAmount;\n this.remainingTotalAmount = subtract(\n this.remainingTotalAmount,\n lineItemTotalDinero,\n );\n\n /**\n * The discount amount is evenly split but can still be higher than the line item total\n * Need to ceil the price to be not more than the line item total\n */\n return greaterThan(allocationAmount, lineItemTotalDinero)\n ? lineItemTotalDinero\n : allocationAmount;\n }\n}\n"],"names":["FixedAmountAllocator","constructor","initialAllocateAmount","initialTotalAmount","currency","__publicField","remainingAllocationAmount","getDinero","remainingTotalAmount","getDineroCurrency","allocate","lineItemTotal","assert","code","lineItemTotalDinero","allocationAmount","Math","max","amount","subtract","greaterThan"],"mappings":";;;;;;;;;;;;AAWO,MAAMA,oBAAqB,CAAA;EAWhCC,WAAYA,CAAA;IACVC,qBAAA;IACAC,kBAAA;IACAC;EAAA,CAKC,EAAA;IAfH;AAAA;AAAA;IAAOC,aAAA,CAAA,IAAA,EAAA,2BAAA,CAAA;IAIP;AAAA;AAAA;IAAOA,aAAA,CAAA,IAAA,EAAA,sBAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAWA,IAAA,CAAAC,yBAAA,GAA4BC,SAAU,CAAAL,qBAAA,EAAuBE,QAAQ,CAAA;IACrE,IAAA,CAAAI,oBAAA,GAAuBD,SAAU,CAAAJ,kBAAA,EAAoBC,QAAQ,CAAA;IAC7D,IAAA,CAAAA,QAAA,GAAWK,kBAAkBL,QAAQ,CAAA;EAC5C;EAAA;AAAA;AAAA;EAKAM,QAAAA,CAASC,eAAsBP,QAA0B,EAAA;IACvDQ,MAAA,CACE,IAAA,CAAKR,SAASS,IAAS,KAAAT,QAAA,EACQ,+BAAAA,QAAiB,SAAA,IAAA,CAAKA,SAASS,IAAI,EAAA,CACpE;IACM,MAAAC,mBAAA,GAAsBP,SAAU,CAAAI,aAAA,EAAeP,QAAQ,CAAA;IAK7D,IAAIO,kBAAkB,CAAG,EAAA;MAChB,OAAAG,mBAAA;IACT;IAEM,MAAA,CAACC,gBAAkB,EAAAT,yBAAyB,CAAI,GAAAI,QAAA,CACpD,IAAK,CAAAJ,yBAAA,EACL,CACEK,aAAA,EACAK,KAAKC,GAAI,CAAAC,MAAA,CAAO,KAAKV,oBAAoB,CAAA,GAAIG,eAAe,CAAC,CAAA,CAC/D,CACF;IAEOC,MAAA,CAAA,CAAC,CAACG,gBAAA,EAAkB,2BAA2B,CAAA;IACtDH,MAAA,CACE,CAAC,CAACN,yBAAA,EACF,wCAAA,CACF;IAEA,IAAA,CAAKA,yBAA4B,GAAAA,yBAAA;IACjC,IAAA,CAAKE,oBAAuB,GAAAW,QAAA,CAC1B,IAAK,CAAAX,oBAAA,EACLM,mBAAA,CACF;IAMA,OAAOM,WAAY,CAAAL,gBAAA,EAAkBD,mBAAmB,CAAA,GACpDA,mBACA,GAAAC,gBAAA;EACN;AACF;"}
@@ -0,0 +1,2 @@
1
+ export * from "./fixedAmount";
2
+ export * from "./productAmount";
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ var fixedAmount = require('./fixedAmount.js');
4
+ var productAmount = require('./productAmount.js');
5
+ "use strict";
6
+ exports.FixedAmountAllocator = fixedAmount.FixedAmountAllocator;
7
+ exports.ProductAmountAllocator = productAmount.ProductAmountAllocator;
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -0,0 +1,4 @@
1
+ export { FixedAmountAllocator } from './fixedAmount.mjs';
2
+ export { ProductAmountAllocator } from './productAmount.mjs';
3
+ "use strict";
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,13 @@
1
+ import type { FullLineItemSummary } from "../types";
2
+ /**
3
+ * Helper class to distribute a total amount for a product
4
+ */
5
+ export declare class ProductAmountAllocator {
6
+ #private;
7
+ /**
8
+ * Remaining quantity to allocate
9
+ */
10
+ quantity: number;
11
+ constructor(productSummary: FullLineItemSummary);
12
+ allocateQty(quantity: number): FullLineItemSummary;
13
+ }
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ var misc = require('../misc.js');
4
+ var fixedAmount = require('./fixedAmount.js');
5
+ "use strict";
6
+ var __defProp = Object.defineProperty;
7
+ var __typeError = msg => {
8
+ throw TypeError(msg);
9
+ };
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value
15
+ }) : obj[key] = value;
16
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
17
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
18
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
19
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
20
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
21
+ var _itemPrice, _currency, _subtotal, _discountAmount, _taxableAmount, _tax, _total;
22
+ class ProductAmountAllocator {
23
+ constructor(productSummary) {
24
+ // #############################################################################
25
+ // Fixed values
26
+ // #############################################################################
27
+ __privateAdd(this, _itemPrice);
28
+ __privateAdd(this, _currency);
29
+ // #############################################################################
30
+ /**
31
+ * Remaining quantity to allocate
32
+ */
33
+ __publicField(this, "quantity");
34
+ // #############################################################################
35
+ // Specific amount allocators
36
+ // #############################################################################
37
+ __privateAdd(this, _subtotal);
38
+ __privateAdd(this, _discountAmount);
39
+ __privateAdd(this, _taxableAmount);
40
+ __privateAdd(this, _tax);
41
+ __privateAdd(this, _total);
42
+ const currency = productSummary.currency;
43
+ const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
44
+ __privateSet(this, _itemPrice, productSummary.itemPrice);
45
+ __privateSet(this, _currency, currency);
46
+ this.quantity = productSummary.quantity;
47
+ __privateSet(this, _subtotal, new fixedAmount.FixedAmountAllocator({
48
+ initialAllocateAmount: productSummary.subtotal,
49
+ initialTotalAmount: priceForAllocation,
50
+ currency
51
+ }));
52
+ __privateSet(this, _discountAmount, new fixedAmount.FixedAmountAllocator({
53
+ initialAllocateAmount: productSummary.discountAmount,
54
+ initialTotalAmount: priceForAllocation,
55
+ currency
56
+ }));
57
+ __privateSet(this, _taxableAmount, new fixedAmount.FixedAmountAllocator({
58
+ initialAllocateAmount: productSummary.taxableAmount,
59
+ initialTotalAmount: priceForAllocation,
60
+ currency
61
+ }));
62
+ __privateSet(this, _tax, new fixedAmount.FixedAmountAllocator({
63
+ initialAllocateAmount: productSummary.tax,
64
+ initialTotalAmount: priceForAllocation,
65
+ currency
66
+ }));
67
+ __privateSet(this, _total, new fixedAmount.FixedAmountAllocator({
68
+ initialAllocateAmount: productSummary.total,
69
+ initialTotalAmount: priceForAllocation,
70
+ currency
71
+ }));
72
+ }
73
+ allocateQty(quantity) {
74
+ let quantityNormalized = Math.max(quantity, 0);
75
+ quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;
76
+ this.quantity = Math.max(this.quantity - quantityNormalized, 0);
77
+ const itemQuantityPrice = __privateGet(this, _itemPrice) * quantityNormalized;
78
+ return {
79
+ itemPrice: __privateGet(this, _itemPrice),
80
+ currency: __privateGet(this, _currency),
81
+ quantity: quantityNormalized,
82
+ subtotal: misc.amount(__privateGet(this, _subtotal).allocate(itemQuantityPrice, __privateGet(this, _currency))),
83
+ discountAmount: misc.amount(__privateGet(this, _discountAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
84
+ taxableAmount: misc.amount(__privateGet(this, _taxableAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
85
+ tax: misc.amount(__privateGet(this, _tax).allocate(itemQuantityPrice, __privateGet(this, _currency))),
86
+ total: misc.amount(__privateGet(this, _total).allocate(itemQuantityPrice, __privateGet(this, _currency)))
87
+ };
88
+ }
89
+ }
90
+ _itemPrice = new WeakMap();
91
+ _currency = new WeakMap();
92
+ _subtotal = new WeakMap();
93
+ _discountAmount = new WeakMap();
94
+ _taxableAmount = new WeakMap();
95
+ _tax = new WeakMap();
96
+ _total = new WeakMap();
97
+ exports.ProductAmountAllocator = ProductAmountAllocator;
98
+ //# sourceMappingURL=productAmount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productAmount.js","sources":["../../../../src/utils/money/allocators/productAmount.ts"],"sourcesContent":["import type { Currency } from \"../../../types\";\nimport { amount } from \"../misc\";\nimport type { Cents, FullLineItemSummary } from \"../types\";\nimport { FixedAmountAllocator } from \"./fixedAmount\";\n\n/**\n * Helper class to distribute a total amount for a product\n */\nexport class ProductAmountAllocator {\n // #############################################################################\n // Fixed values\n // #############################################################################\n readonly #itemPrice: Cents;\n readonly #currency: Currency;\n // #############################################################################\n /**\n * Remaining quantity to allocate\n */\n quantity: number;\n // #############################################################################\n // Specific amount allocators\n // #############################################################################\n #subtotal: FixedAmountAllocator;\n #discountAmount: FixedAmountAllocator;\n #taxableAmount: FixedAmountAllocator;\n #tax: FixedAmountAllocator;\n #total: FixedAmountAllocator;\n\n constructor(productSummary: FullLineItemSummary) {\n const currency = productSummary.currency;\n\n /**\n * Somewhat hackish, just need a stable price that can easily divide later by quantity\n */\n const priceForAllocation =\n productSummary.itemPrice * productSummary.quantity;\n\n this.#itemPrice = productSummary.itemPrice;\n this.#currency = currency;\n this.quantity = productSummary.quantity;\n this.#subtotal = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.subtotal,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#discountAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.discountAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#taxableAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.taxableAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#tax = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.tax,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#total = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.total,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n }\n\n allocateQty(quantity: number): FullLineItemSummary {\n // Calculate remaining allocatable quantity\n let quantityNormalized = Math.max(quantity, 0);\n quantityNormalized =\n this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;\n\n // Adjust remaining qty\n this.quantity = Math.max(this.quantity - quantityNormalized, 0);\n\n // How big of a slice of the total price we need to allocate\n const itemQuantityPrice = this.#itemPrice * quantityNormalized;\n\n return {\n itemPrice: this.#itemPrice,\n currency: this.#currency,\n quantity: quantityNormalized,\n subtotal: amount(\n this.#subtotal.allocate(itemQuantityPrice, this.#currency),\n ),\n discountAmount: amount(\n this.#discountAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n taxableAmount: amount(\n this.#taxableAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),\n total: amount(this.#total.allocate(itemQuantityPrice, this.#currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["_itemPrice","_currency","_subtotal","_discountAmount","_taxableAmount","_tax","_total","ProductAmountAllocator","constructor","productSummary","__privateAdd","__publicField","currency","priceForAllocation","itemPrice","quantity","__privateSet","FixedAmountAllocator","initialAllocateAmount","subtotal","initialTotalAmount","discountAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","__privateGet","amount","allocate","WeakMap"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,eAAA,EAAAC,cAAA,EAAAC,IAAA,EAAAC,MAAA;AAQO,MAAMC,sBAAuB,CAAA;EAoBlCC,YAAYC,cAAqC,EAAA;IAhBjD;IAAA;IAAA;IAASC,YAAA,CAAA,IAAA,EAAAV,UAAA,CAAA;IACAU,YAAA,CAAA,IAAA,EAAAT,SAAA,CAAA;IAKT;IAAA;AAAA;AAAA;IAAAU,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAIA;IAAA;IAAA;IAAAD,YAAA,CAAA,IAAA,EAAAR,SAAA,CAAA;IACAQ,YAAA,CAAA,IAAA,EAAAP,eAAA,CAAA;IACAO,YAAA,CAAA,IAAA,EAAAN,cAAA,CAAA;IACAM,YAAA,CAAA,IAAA,EAAAL,IAAA,CAAA;IACAK,YAAA,CAAA,IAAA,EAAAJ,MAAA,CAAA;IAGE,MAAMM,WAAWH,cAAe,CAAAG,QAAA;IAK1B,MAAAC,kBAAA,GACJJ,cAAe,CAAAK,SAAA,GAAYL,cAAe,CAAAM,QAAA;IAE5CC,YAAA,CAAA,IAAA,EAAKhB,YAAaS,cAAe,CAAAK,SAAA,CAAA;IACjCE,YAAA,CAAA,IAAA,EAAKf,SAAY,EAAAW,QAAA,CAAA;IACjB,IAAA,CAAKG,WAAWN,cAAe,CAAAM,QAAA;IAC1BC,YAAA,CAAA,IAAA,EAAAd,SAAA,EAAY,IAAIe,gCAAqB,CAAA;MACxCC,uBAAuBT,cAAe,CAAAU,QAAA;MACtCC,kBAAoB,EAAAP,kBAAA;MACpBD;IACD,CAAA,CAAA,CAAA;IACII,YAAA,CAAA,IAAA,EAAAb,eAAA,EAAkB,IAAIc,gCAAqB,CAAA;MAC9CC,uBAAuBT,cAAe,CAAAY,cAAA;MACtCD,kBAAoB,EAAAP,kBAAA;MACpBD;IACD,CAAA,CAAA,CAAA;IACII,YAAA,CAAA,IAAA,EAAAZ,cAAA,EAAiB,IAAIa,gCAAqB,CAAA;MAC7CC,uBAAuBT,cAAe,CAAAa,aAAA;MACtCF,kBAAoB,EAAAP,kBAAA;MACpBD;IACD,CAAA,CAAA,CAAA;IACII,YAAA,CAAA,IAAA,EAAAX,IAAA,EAAO,IAAIY,gCAAqB,CAAA;MACnCC,uBAAuBT,cAAe,CAAAc,GAAA;MACtCH,kBAAoB,EAAAP,kBAAA;MACpBD;IACD,CAAA,CAAA,CAAA;IACII,YAAA,CAAA,IAAA,EAAAV,MAAA,EAAS,IAAIW,gCAAqB,CAAA;MACrCC,uBAAuBT,cAAe,CAAAe,KAAA;MACtCJ,kBAAoB,EAAAP,kBAAA;MACpBD;IACD,CAAA,CAAA,CAAA;EACH;EAEAa,YAAYV,QAAuC,EAAA;IAEjD,IAAIW,kBAAqB,GAAAC,IAAA,CAAKC,GAAI,CAAAb,QAAA,EAAU,CAAC,CAAA;IAC7CW,kBAAA,GACE,IAAK,CAAAX,QAAA,GAAWW,kBAAsB,IAAA,CAAA,GAAIA,kBAAqB,GAAA,CAAA;IAGjE,IAAA,CAAKX,WAAWY,IAAK,CAAAC,GAAA,CAAI,IAAK,CAAAb,QAAA,GAAWW,oBAAoB,CAAC,CAAA;IAGxD,MAAAG,iBAAA,GAAoBC,mBAAK9B,UAAa,CAAA,GAAA0B,kBAAA;IAErC,OAAA;MACLZ,WAAWgB,YAAK,CAAA,IAAA,EAAA9B,UAAA,CAAA;MAChBY,UAAUkB,YAAK,CAAA,IAAA,EAAA7B,SAAA,CAAA;MACfc,QAAU,EAAAW,kBAAA;MACVP,QAAU,EAAAY,IAAA,CAAAA,MAAA,CACRD,YAAK,CAAA,IAAA,EAAA5B,SAAA,CAAA,CAAU8B,QAAS,CAAAH,iBAAA,EAAmBC,mBAAK7B,SAAS,CAAA,CAC3D,CAAA;MACAoB,cAAgB,EAAAU,IAAA,CAAAA,MAAA,CACdD,YAAK,CAAA,IAAA,EAAA3B,eAAA,CAAA,CAAgB6B,QAAS,CAAAH,iBAAA,EAAmBC,mBAAK7B,SAAS,CAAA,CACjE,CAAA;MACAqB,aAAe,EAAAS,IAAA,CAAAA,MAAA,CACbD,YAAK,CAAA,IAAA,EAAA1B,cAAA,CAAA,CAAe4B,QAAS,CAAAH,iBAAA,EAAmBC,mBAAK7B,SAAS,CAAA,CAChE,CAAA;MACAsB,GAAA,EAAKQ,YAAOD,YAAK,CAAA,IAAA,EAAAzB,IAAA,CAAA,CAAK2B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC,CAAA;MACjEuB,KAAA,EAAOO,YAAOD,YAAK,CAAA,IAAA,EAAAxB,MAAA,CAAA,CAAO0B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC;IAAA,CACvE;EACF;AACF;AApFWD,UAAA,GAAA,IAAAiC,OAAA,CAAA,CAAA;AACAhC,SAAA,GAAA,IAAAgC,OAAA,CAAA,CAAA;AAST/B,SAAA,GAAA,IAAA+B,OAAA,CAAA,CAAA;AACA9B,eAAA,GAAA,IAAA8B,OAAA,CAAA,CAAA;AACA7B,cAAA,GAAA,IAAA6B,OAAA,CAAA,CAAA;AACA5B,IAAA,GAAA,IAAA4B,OAAA,CAAA,CAAA;AACA3B,MAAA,GAAA,IAAA2B,OAAA,CAAA,CAAA;"}
@@ -0,0 +1,96 @@
1
+ import { amount } from '../misc.mjs';
2
+ import { FixedAmountAllocator } from './fixedAmount.mjs';
3
+ "use strict";
4
+ var __defProp = Object.defineProperty;
5
+ var __typeError = msg => {
6
+ throw TypeError(msg);
7
+ };
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value
13
+ }) : obj[key] = value;
14
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
16
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
17
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
18
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
19
+ var _itemPrice, _currency, _subtotal, _discountAmount, _taxableAmount, _tax, _total;
20
+ class ProductAmountAllocator {
21
+ constructor(productSummary) {
22
+ // #############################################################################
23
+ // Fixed values
24
+ // #############################################################################
25
+ __privateAdd(this, _itemPrice);
26
+ __privateAdd(this, _currency);
27
+ // #############################################################################
28
+ /**
29
+ * Remaining quantity to allocate
30
+ */
31
+ __publicField(this, "quantity");
32
+ // #############################################################################
33
+ // Specific amount allocators
34
+ // #############################################################################
35
+ __privateAdd(this, _subtotal);
36
+ __privateAdd(this, _discountAmount);
37
+ __privateAdd(this, _taxableAmount);
38
+ __privateAdd(this, _tax);
39
+ __privateAdd(this, _total);
40
+ const currency = productSummary.currency;
41
+ const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
42
+ __privateSet(this, _itemPrice, productSummary.itemPrice);
43
+ __privateSet(this, _currency, currency);
44
+ this.quantity = productSummary.quantity;
45
+ __privateSet(this, _subtotal, new FixedAmountAllocator({
46
+ initialAllocateAmount: productSummary.subtotal,
47
+ initialTotalAmount: priceForAllocation,
48
+ currency
49
+ }));
50
+ __privateSet(this, _discountAmount, new FixedAmountAllocator({
51
+ initialAllocateAmount: productSummary.discountAmount,
52
+ initialTotalAmount: priceForAllocation,
53
+ currency
54
+ }));
55
+ __privateSet(this, _taxableAmount, new FixedAmountAllocator({
56
+ initialAllocateAmount: productSummary.taxableAmount,
57
+ initialTotalAmount: priceForAllocation,
58
+ currency
59
+ }));
60
+ __privateSet(this, _tax, new FixedAmountAllocator({
61
+ initialAllocateAmount: productSummary.tax,
62
+ initialTotalAmount: priceForAllocation,
63
+ currency
64
+ }));
65
+ __privateSet(this, _total, new FixedAmountAllocator({
66
+ initialAllocateAmount: productSummary.total,
67
+ initialTotalAmount: priceForAllocation,
68
+ currency
69
+ }));
70
+ }
71
+ allocateQty(quantity) {
72
+ let quantityNormalized = Math.max(quantity, 0);
73
+ quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;
74
+ this.quantity = Math.max(this.quantity - quantityNormalized, 0);
75
+ const itemQuantityPrice = __privateGet(this, _itemPrice) * quantityNormalized;
76
+ return {
77
+ itemPrice: __privateGet(this, _itemPrice),
78
+ currency: __privateGet(this, _currency),
79
+ quantity: quantityNormalized,
80
+ subtotal: amount(__privateGet(this, _subtotal).allocate(itemQuantityPrice, __privateGet(this, _currency))),
81
+ discountAmount: amount(__privateGet(this, _discountAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
82
+ taxableAmount: amount(__privateGet(this, _taxableAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
83
+ tax: amount(__privateGet(this, _tax).allocate(itemQuantityPrice, __privateGet(this, _currency))),
84
+ total: amount(__privateGet(this, _total).allocate(itemQuantityPrice, __privateGet(this, _currency)))
85
+ };
86
+ }
87
+ }
88
+ _itemPrice = new WeakMap();
89
+ _currency = new WeakMap();
90
+ _subtotal = new WeakMap();
91
+ _discountAmount = new WeakMap();
92
+ _taxableAmount = new WeakMap();
93
+ _tax = new WeakMap();
94
+ _total = new WeakMap();
95
+ export { ProductAmountAllocator };
96
+ //# sourceMappingURL=productAmount.mjs.map