@salla.sa/twilight-components 2.14.450 → 2.14.451

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 (320) hide show
  1. package/dist/cjs/{filepond-u7zONIpU.js → filepond-CFAfS398.js} +1 -1
  2. package/dist/cjs/{filepond-plugin-file-poster-DPE2-7A4.js → filepond-plugin-file-poster-CGV3AN8S.js} +1 -1
  3. package/dist/cjs/{filepond-plugin-file-validate-size-QFJIY-td.js → filepond-plugin-file-validate-size-5lxojxa3.js} +1 -1
  4. package/dist/cjs/{filepond-plugin-file-validate-type-CqUNeom7.js → filepond-plugin-file-validate-type-DU3FUIcL.js} +1 -1
  5. package/dist/cjs/{filepond-plugin-image-edit-B2Z3rRkn.js → filepond-plugin-image-edit-DYML2Igz.js} +1 -1
  6. package/dist/cjs/{filepond-plugin-image-exif-orientation-DxoN6Z-R.js → filepond-plugin-image-exif-orientation-PyHdAMQE.js} +1 -1
  7. package/dist/cjs/{filepond-plugin-image-preview-doqEZlz_.js → filepond-plugin-image-preview-B723diKP.js} +1 -1
  8. package/dist/cjs/{functions-CZozSu7O.js → functions-CCmv-cGP.js} +1 -1
  9. package/dist/cjs/{index-CCSZWnkr.js → index-CL8sn0_c.js} +1 -1
  10. package/dist/cjs/{index-tPF0UB3W.js → index-lbHgh2oF.js} +6 -6
  11. package/dist/cjs/index.esm-DOwgk2YK.js +2444 -0
  12. package/dist/cjs/loader.cjs.js +2 -2
  13. package/dist/cjs/salla-accordion-body_2.cjs.entry.js +1 -1
  14. package/dist/cjs/salla-accordion_6.cjs.entry.js +1 -1
  15. package/dist/cjs/salla-add-product-button_5.cjs.entry.js +1 -1
  16. package/dist/cjs/salla-advertisement.cjs.entry.js +1 -1
  17. package/dist/cjs/salla-alert_2.cjs.entry.js +21 -17
  18. package/dist/cjs/salla-app-install-alert.cjs.entry.js +1 -1
  19. package/dist/cjs/salla-apps-icons.cjs.entry.js +1 -1
  20. package/dist/cjs/salla-badge.cjs.entry.js +1 -1
  21. package/dist/cjs/salla-booking-field_7.cjs.entry.js +10 -10
  22. package/dist/cjs/salla-bullet-delivery_2.cjs.entry.js +4611 -24
  23. package/dist/cjs/salla-cart-coupons.cjs.entry.js +1 -1
  24. package/dist/cjs/salla-cart-item-offers_2.cjs.entry.js +1 -1
  25. package/dist/cjs/salla-cashback-banner.cjs.entry.js +1 -1
  26. package/dist/cjs/salla-comment-form_8.cjs.entry.js +1 -1
  27. package/dist/cjs/salla-conditional-offer.cjs.entry.js +1 -1
  28. package/dist/cjs/salla-contacts.cjs.entry.js +1 -1
  29. package/dist/cjs/salla-cookies-bar.cjs.entry.js +1 -1
  30. package/dist/cjs/salla-count-down.cjs.entry.js +1 -1
  31. package/dist/cjs/salla-custom-fields.cjs.entry.js +1 -1
  32. package/dist/cjs/salla-delivery-promise.cjs.entry.js +1 -1
  33. package/dist/cjs/salla-edit-order-button.cjs.entry.js +1 -1
  34. package/dist/cjs/salla-filters-widget.cjs.entry.js +1 -1
  35. package/dist/cjs/salla-filters.cjs.entry.js +1 -1
  36. package/dist/cjs/salla-fulfillment-methods.cjs.entry.js +1 -1
  37. package/dist/cjs/salla-gifting.cjs.entry.js +1 -1
  38. package/dist/cjs/salla-hook.cjs.entry.js +1 -1
  39. package/dist/cjs/salla-infinite-scroll.cjs.entry.js +1 -1
  40. package/dist/cjs/salla-installment.cjs.entry.js +1 -1
  41. package/dist/cjs/salla-list-tile.cjs.entry.js +1 -1
  42. package/dist/cjs/salla-localization-modal.cjs.entry.js +1 -1
  43. package/dist/cjs/salla-login-modal.cjs.entry.js +1 -1
  44. package/dist/cjs/salla-loyalty-banner.cjs.entry.js +2 -2
  45. package/dist/cjs/salla-loyalty-hero_2.cjs.entry.js +2 -2
  46. package/dist/cjs/salla-loyalty-panel.cjs.entry.js +3 -3
  47. package/dist/cjs/salla-loyalty-points-banner.cjs.entry.js +1 -1
  48. package/dist/cjs/salla-loyalty-prize-item.cjs.entry.js +1 -1
  49. package/dist/cjs/salla-loyalty-program.cjs.entry.js +3 -3
  50. package/dist/cjs/salla-loyalty-reward.cjs.entry.js +2 -2
  51. package/dist/cjs/salla-loyalty.cjs.entry.js +1 -1
  52. package/dist/cjs/salla-maintenance-alert.cjs.entry.js +1 -1
  53. package/dist/cjs/salla-map.cjs.entry.js +1 -1
  54. package/dist/cjs/salla-menu.cjs.entry.js +1 -1
  55. package/dist/cjs/salla-metadata.cjs.entry.js +1 -1
  56. package/dist/cjs/salla-multiple-bundle-product-cart_2.cjs.entry.js +1 -1
  57. package/dist/cjs/salla-multiple-bundle-product-options-modal_2.cjs.entry.js +1 -1
  58. package/dist/cjs/salla-multiple-bundle-product.cjs.entry.js +1 -1
  59. package/dist/cjs/salla-next-order-coupon.cjs.entry.js +1 -1
  60. package/dist/cjs/salla-notification-item.cjs.entry.js +1 -1
  61. package/dist/cjs/salla-notifications.cjs.entry.js +1 -1
  62. package/dist/cjs/salla-offer-modal.cjs.entry.js +1 -1
  63. package/dist/cjs/salla-offer.cjs.entry.js +1 -1
  64. package/dist/cjs/salla-order-details-multiple-bundle-product.cjs.entry.js +1 -1
  65. package/dist/cjs/salla-order-details-options.cjs.entry.js +1 -1
  66. package/dist/cjs/salla-order-details.cjs.entry.js +1 -1
  67. package/dist/cjs/salla-order-edit-item.cjs.entry.js +1 -1
  68. package/dist/cjs/salla-order-edit-product-card.cjs.entry.js +1 -1
  69. package/dist/cjs/salla-order-edit.cjs.entry.js +1 -1
  70. package/dist/cjs/salla-order-summary.cjs.entry.js +1 -1
  71. package/dist/cjs/salla-order-totals-card.cjs.entry.js +1 -1
  72. package/dist/cjs/salla-orders.cjs.entry.js +1 -1
  73. package/dist/cjs/salla-payments.cjs.entry.js +1 -1
  74. package/dist/cjs/salla-placeholder.cjs.entry.js +1 -1
  75. package/dist/cjs/salla-price-range.cjs.entry.js +1 -1
  76. package/dist/cjs/salla-product-card-embed.cjs.entry.js +1 -1
  77. package/dist/cjs/salla-product-card_2.cjs.entry.js +1 -1
  78. package/dist/cjs/salla-product-size-guide.cjs.entry.js +1 -1
  79. package/dist/cjs/salla-products-list.cjs.entry.js +1 -1
  80. package/dist/cjs/salla-progress-bar.cjs.entry.js +1 -1
  81. package/dist/cjs/salla-quick-order.cjs.entry.js +1 -1
  82. package/dist/cjs/salla-rating-modal.cjs.entry.js +1 -1
  83. package/dist/cjs/salla-reward-action_4.cjs.entry.js +3 -3
  84. package/dist/cjs/salla-scopes.cjs.entry.js +1 -1
  85. package/dist/cjs/salla-search.cjs.entry.js +1 -1
  86. package/dist/cjs/salla-skeleton.cjs.entry.js +1 -1
  87. package/dist/cjs/salla-slider.cjs.entry.js +1 -1
  88. package/dist/cjs/salla-social-share.cjs.entry.js +1 -1
  89. package/dist/cjs/salla-social.cjs.entry.js +1 -1
  90. package/dist/cjs/salla-tab-content_3.cjs.entry.js +1 -1
  91. package/dist/cjs/salla-tiered-offer.cjs.entry.js +1 -1
  92. package/dist/cjs/salla-tooltip.cjs.entry.js +1 -1
  93. package/dist/cjs/salla-trust-badges.cjs.entry.js +1 -1
  94. package/dist/cjs/salla-user-menu.cjs.entry.js +1 -1
  95. package/dist/cjs/salla-user-profile.cjs.entry.js +1 -1
  96. package/dist/cjs/salla-user-settings.cjs.entry.js +1 -1
  97. package/dist/cjs/salla-verify.cjs.entry.js +1 -1
  98. package/dist/cjs/salla-wallet.cjs.entry.js +1 -1
  99. package/dist/cjs/{tracked-promise-DVCwmpuo.js → tracked-promise-BEZGH5zy.js} +1 -1
  100. package/dist/cjs/twilight.cjs.js +2 -2
  101. package/dist/cjs/{vanilla-picker-DQ8iQ9l5.js → vanilla-picker-DEoSMlkf.js} +1 -1
  102. package/dist/collection/assets/svg/location-tag.svg +10 -0
  103. package/dist/collection/components/salla-bottom-alert/salla-bottom-alert.js +20 -16
  104. package/dist/collection/components/salla-bullet-delivery/api-service.js +6 -0
  105. package/dist/collection/components/salla-bullet-delivery/helpers.js +3 -1
  106. package/dist/collection/components/salla-bullet-delivery/salla-bullet-delivery.css +128 -0
  107. package/dist/collection/components/salla-bullet-delivery/salla-bullet-delivery.js +195 -20
  108. package/dist/components/index.esm.js +2424 -0
  109. package/dist/components/index.js +2 -2
  110. package/dist/components/salla-bottom-alert.js +20 -16
  111. package/dist/components/salla-bullet-delivery.js +4644 -51
  112. package/dist/esm/{filepond-N1L04Plt.js → filepond-CCUaTwJO.js} +1 -1
  113. package/dist/esm/{filepond-plugin-file-poster-2E1WZVzP.js → filepond-plugin-file-poster-C3FfmUV2.js} +1 -1
  114. package/dist/esm/{filepond-plugin-file-validate-size-C0LhcfOR.js → filepond-plugin-file-validate-size-27nMbGKo.js} +1 -1
  115. package/dist/esm/{filepond-plugin-file-validate-type-Be8IgUh8.js → filepond-plugin-file-validate-type-RRO4qH5n.js} +1 -1
  116. package/dist/esm/{filepond-plugin-image-edit-CFFuq7E_.js → filepond-plugin-image-edit-wY6LYrlF.js} +1 -1
  117. package/dist/esm/{filepond-plugin-image-exif-orientation-DPCeA1B5.js → filepond-plugin-image-exif-orientation-OrAkjCVu.js} +1 -1
  118. package/dist/esm/{filepond-plugin-image-preview-CEvNq5JJ.js → filepond-plugin-image-preview-COtDiNmq.js} +1 -1
  119. package/dist/esm/{functions-Ba6VuRnB.js → functions-BBStjquJ.js} +1 -1
  120. package/dist/esm/{index-CrNw20pf.js → index-BAOl7AJU.js} +6 -6
  121. package/dist/esm/{index-IqFJsnTE.js → index-BgFU58I4.js} +1 -1
  122. package/dist/esm/index.esm-BkPzCq-C.js +2424 -0
  123. package/dist/esm/loader.js +3 -3
  124. package/dist/esm/salla-accordion-body_2.entry.js +1 -1
  125. package/dist/esm/salla-accordion_6.entry.js +1 -1
  126. package/dist/esm/salla-add-product-button_5.entry.js +1 -1
  127. package/dist/esm/salla-advertisement.entry.js +1 -1
  128. package/dist/esm/salla-alert_2.entry.js +21 -17
  129. package/dist/esm/salla-app-install-alert.entry.js +1 -1
  130. package/dist/esm/salla-apps-icons.entry.js +1 -1
  131. package/dist/esm/salla-badge.entry.js +1 -1
  132. package/dist/esm/salla-booking-field_7.entry.js +10 -10
  133. package/dist/esm/salla-bullet-delivery_2.entry.js +4646 -59
  134. package/dist/esm/salla-cart-coupons.entry.js +1 -1
  135. package/dist/esm/salla-cart-item-offers_2.entry.js +1 -1
  136. package/dist/esm/salla-cashback-banner.entry.js +1 -1
  137. package/dist/esm/salla-comment-form_8.entry.js +1 -1
  138. package/dist/esm/salla-conditional-offer.entry.js +1 -1
  139. package/dist/esm/salla-contacts.entry.js +1 -1
  140. package/dist/esm/salla-cookies-bar.entry.js +1 -1
  141. package/dist/esm/salla-count-down.entry.js +1 -1
  142. package/dist/esm/salla-custom-fields.entry.js +1 -1
  143. package/dist/esm/salla-delivery-promise.entry.js +1 -1
  144. package/dist/esm/salla-edit-order-button.entry.js +1 -1
  145. package/dist/esm/salla-filters-widget.entry.js +1 -1
  146. package/dist/esm/salla-filters.entry.js +1 -1
  147. package/dist/esm/salla-fulfillment-methods.entry.js +1 -1
  148. package/dist/esm/salla-gifting.entry.js +1 -1
  149. package/dist/esm/salla-hook.entry.js +1 -1
  150. package/dist/esm/salla-infinite-scroll.entry.js +1 -1
  151. package/dist/esm/salla-installment.entry.js +1 -1
  152. package/dist/esm/salla-list-tile.entry.js +1 -1
  153. package/dist/esm/salla-localization-modal.entry.js +1 -1
  154. package/dist/esm/salla-login-modal.entry.js +1 -1
  155. package/dist/esm/salla-loyalty-banner.entry.js +2 -2
  156. package/dist/esm/salla-loyalty-hero_2.entry.js +2 -2
  157. package/dist/esm/salla-loyalty-panel.entry.js +3 -3
  158. package/dist/esm/salla-loyalty-points-banner.entry.js +1 -1
  159. package/dist/esm/salla-loyalty-prize-item.entry.js +1 -1
  160. package/dist/esm/salla-loyalty-program.entry.js +3 -3
  161. package/dist/esm/salla-loyalty-reward.entry.js +2 -2
  162. package/dist/esm/salla-loyalty.entry.js +1 -1
  163. package/dist/esm/salla-maintenance-alert.entry.js +1 -1
  164. package/dist/esm/salla-map.entry.js +1 -1
  165. package/dist/esm/salla-menu.entry.js +1 -1
  166. package/dist/esm/salla-metadata.entry.js +1 -1
  167. package/dist/esm/salla-multiple-bundle-product-cart_2.entry.js +1 -1
  168. package/dist/esm/salla-multiple-bundle-product-options-modal_2.entry.js +1 -1
  169. package/dist/esm/salla-multiple-bundle-product.entry.js +1 -1
  170. package/dist/esm/salla-next-order-coupon.entry.js +1 -1
  171. package/dist/esm/salla-notification-item.entry.js +1 -1
  172. package/dist/esm/salla-notifications.entry.js +1 -1
  173. package/dist/esm/salla-offer-modal.entry.js +1 -1
  174. package/dist/esm/salla-offer.entry.js +1 -1
  175. package/dist/esm/salla-order-details-multiple-bundle-product.entry.js +1 -1
  176. package/dist/esm/salla-order-details-options.entry.js +1 -1
  177. package/dist/esm/salla-order-details.entry.js +1 -1
  178. package/dist/esm/salla-order-edit-item.entry.js +1 -1
  179. package/dist/esm/salla-order-edit-product-card.entry.js +1 -1
  180. package/dist/esm/salla-order-edit.entry.js +1 -1
  181. package/dist/esm/salla-order-summary.entry.js +1 -1
  182. package/dist/esm/salla-order-totals-card.entry.js +1 -1
  183. package/dist/esm/salla-orders.entry.js +1 -1
  184. package/dist/esm/salla-payments.entry.js +1 -1
  185. package/dist/esm/salla-placeholder.entry.js +1 -1
  186. package/dist/esm/salla-price-range.entry.js +1 -1
  187. package/dist/esm/salla-product-card-embed.entry.js +1 -1
  188. package/dist/esm/salla-product-card_2.entry.js +1 -1
  189. package/dist/esm/salla-product-size-guide.entry.js +1 -1
  190. package/dist/esm/salla-products-list.entry.js +1 -1
  191. package/dist/esm/salla-progress-bar.entry.js +1 -1
  192. package/dist/esm/salla-quick-order.entry.js +1 -1
  193. package/dist/esm/salla-rating-modal.entry.js +1 -1
  194. package/dist/esm/salla-reward-action_4.entry.js +3 -3
  195. package/dist/esm/salla-scopes.entry.js +1 -1
  196. package/dist/esm/salla-search.entry.js +1 -1
  197. package/dist/esm/salla-skeleton.entry.js +1 -1
  198. package/dist/esm/salla-slider.entry.js +1 -1
  199. package/dist/esm/salla-social-share.entry.js +1 -1
  200. package/dist/esm/salla-social.entry.js +1 -1
  201. package/dist/esm/salla-tab-content_3.entry.js +1 -1
  202. package/dist/esm/salla-tiered-offer.entry.js +1 -1
  203. package/dist/esm/salla-tooltip.entry.js +1 -1
  204. package/dist/esm/salla-trust-badges.entry.js +1 -1
  205. package/dist/esm/salla-user-menu.entry.js +1 -1
  206. package/dist/esm/salla-user-profile.entry.js +1 -1
  207. package/dist/esm/salla-user-settings.entry.js +1 -1
  208. package/dist/esm/salla-verify.entry.js +1 -1
  209. package/dist/esm/salla-wallet.entry.js +1 -1
  210. package/dist/esm/{tracked-promise-DH7_DYgQ.js → tracked-promise-CPfI_VcX.js} +1 -1
  211. package/dist/esm/twilight.js +3 -3
  212. package/dist/esm/{vanilla-picker-NvsTGeIC.js → vanilla-picker-D6ctFQpu.js} +1 -1
  213. package/dist/twilight/{p-D1BtXmLB.js → p--sGcI7SX.js} +1 -1
  214. package/dist/twilight/{p-33369508.entry.js → p-01359d46.entry.js} +1 -1
  215. package/dist/twilight/{p-ba68d83b.entry.js → p-02668306.entry.js} +1 -1
  216. package/dist/twilight/{p-1184e75d.entry.js → p-02e4b3f7.entry.js} +1 -1
  217. package/dist/twilight/{p-9b14cfd6.entry.js → p-059a362b.entry.js} +1 -1
  218. package/dist/twilight/{p-4896533c.entry.js → p-082ac280.entry.js} +1 -1
  219. package/dist/twilight/{p-e96b8d47.entry.js → p-091ef563.entry.js} +1 -1
  220. package/dist/twilight/p-0bb2ae4a.entry.js +4 -0
  221. package/dist/twilight/{p-9d9da993.entry.js → p-0c2af75c.entry.js} +1 -1
  222. package/dist/twilight/{p-bca94624.entry.js → p-1090cced.entry.js} +1 -1
  223. package/dist/twilight/{p-3d7d52b9.entry.js → p-14319930.entry.js} +1 -1
  224. package/dist/twilight/{p-d36d4dd0.entry.js → p-1b028d1e.entry.js} +1 -1
  225. package/dist/twilight/{p-7f99f835.entry.js → p-1c8f540e.entry.js} +1 -1
  226. package/dist/twilight/{p-eec8f211.entry.js → p-1f98bb26.entry.js} +1 -1
  227. package/dist/twilight/{p-7988b7a5.entry.js → p-20d5f87f.entry.js} +1 -1
  228. package/dist/twilight/{p-5c07ab28.entry.js → p-224d3c26.entry.js} +1 -1
  229. package/dist/twilight/{p-a68644af.entry.js → p-26ef7b3c.entry.js} +1 -1
  230. package/dist/twilight/{p-c1ab6774.entry.js → p-2879b9ac.entry.js} +1 -1
  231. package/dist/twilight/{p-6a5e3e9b.entry.js → p-2b706f7e.entry.js} +1 -1
  232. package/dist/twilight/{p-cf3d3103.entry.js → p-3400cfe4.entry.js} +1 -1
  233. package/dist/twilight/{p-5395aed1.entry.js → p-34bea7ca.entry.js} +1 -1
  234. package/dist/twilight/{p-6ffe65f2.entry.js → p-37ad673f.entry.js} +1 -1
  235. package/dist/twilight/{p-eff611b9.entry.js → p-3829e7fb.entry.js} +1 -1
  236. package/dist/twilight/{p-77c69000.entry.js → p-436ff3dd.entry.js} +1 -1
  237. package/dist/twilight/{p-57a86efd.entry.js → p-4b061d3d.entry.js} +1 -1
  238. package/dist/twilight/{p-f83a4131.entry.js → p-4c67cd2d.entry.js} +1 -1
  239. package/dist/twilight/{p-120ca46f.entry.js → p-4f9a39de.entry.js} +1 -1
  240. package/dist/twilight/{p-5e4a9088.entry.js → p-5165a1aa.entry.js} +1 -1
  241. package/dist/twilight/{p-53b1b8dd.entry.js → p-53c543c6.entry.js} +1 -1
  242. package/dist/twilight/{p-40ea40b7.entry.js → p-56c33728.entry.js} +1 -1
  243. package/dist/twilight/{p-3160ed65.entry.js → p-5851ae3f.entry.js} +1 -1
  244. package/dist/twilight/{p-3feb7ca8.entry.js → p-58d38f43.entry.js} +1 -1
  245. package/dist/twilight/{p-bac02561.entry.js → p-5cd566f6.entry.js} +1 -1
  246. package/dist/twilight/{p-c8ad8625.entry.js → p-5ce3a659.entry.js} +1 -1
  247. package/dist/twilight/{p-ff148d38.entry.js → p-6446fca2.entry.js} +1 -1
  248. package/dist/twilight/{p-81362474.entry.js → p-66026d3b.entry.js} +1 -1
  249. package/dist/twilight/{p-368d6551.entry.js → p-66fc6ca0.entry.js} +1 -1
  250. package/dist/twilight/{p-4c69d380.entry.js → p-69824501.entry.js} +1 -1
  251. package/dist/twilight/{p-446bfa5f.entry.js → p-6bd2e89b.entry.js} +1 -1
  252. package/dist/twilight/p-6e60ba3f.entry.js +4 -0
  253. package/dist/twilight/{p-1726199f.entry.js → p-72770a46.entry.js} +1 -1
  254. package/dist/twilight/{p-b9922101.entry.js → p-76dbef2b.entry.js} +1 -1
  255. package/dist/twilight/{p-771ca405.entry.js → p-77020583.entry.js} +1 -1
  256. package/dist/twilight/{p-84daf1b1.entry.js → p-7a80b4d6.entry.js} +1 -1
  257. package/dist/twilight/{p-db9d3135.entry.js → p-80ac1d80.entry.js} +1 -1
  258. package/dist/twilight/{p-bf7f213d.entry.js → p-87593f7e.entry.js} +1 -1
  259. package/dist/twilight/{p-380c9f58.entry.js → p-8ab015d1.entry.js} +1 -1
  260. package/dist/twilight/{p-46301bdd.entry.js → p-8bbe9a50.entry.js} +1 -1
  261. package/dist/twilight/{p-4508f1ad.entry.js → p-8bd255f1.entry.js} +1 -1
  262. package/dist/twilight/{p-3649da70.entry.js → p-8c06c63a.entry.js} +1 -1
  263. package/dist/twilight/{p-f011898b.entry.js → p-9b9851cc.entry.js} +1 -1
  264. package/dist/twilight/{p-dabf3edb.entry.js → p-9f09fd9c.entry.js} +1 -1
  265. package/dist/twilight/{p-bd790b16.entry.js → p-9f7d63e8.entry.js} +1 -1
  266. package/dist/twilight/{p-033c9e98.entry.js → p-9fff0a8c.entry.js} +1 -1
  267. package/dist/twilight/{p-CrNw20pf.js → p-BAOl7AJU.js} +1 -1
  268. package/dist/twilight/{p-Cb-27f78.js → p-BjvOwYKG.js} +1 -1
  269. package/dist/twilight/p-BkPzCq-C.js +4 -0
  270. package/dist/twilight/{p-SRRlvI95.js → p-C2ha2a9w.js} +1 -1
  271. package/dist/twilight/{p-CcwaGQ9_.js → p-COOk2-xF.js} +1 -1
  272. package/dist/twilight/{p-BGYOHdWO.js → p-CiN9P6Vs.js} +1 -1
  273. package/dist/twilight/{p-CzMGWnoB.js → p-CjFUdilz.js} +1 -1
  274. package/dist/twilight/{p-C0GYDeEy.js → p-DAZuaKqm.js} +1 -1
  275. package/dist/twilight/{p-Cq2l9LEk.js → p-DrBLhfjt.js} +1 -1
  276. package/dist/twilight/{p-3bfc8662.entry.js → p-a07f60cc.entry.js} +1 -1
  277. package/dist/twilight/{p-f7376365.entry.js → p-a16e2ac6.entry.js} +1 -1
  278. package/dist/twilight/{p-82fdf4e7.entry.js → p-a2a8fe83.entry.js} +1 -1
  279. package/dist/twilight/{p-2eb7be80.entry.js → p-a3868737.entry.js} +1 -1
  280. package/dist/twilight/{p-084a6e4a.entry.js → p-a64f0aff.entry.js} +1 -1
  281. package/dist/twilight/p-a83d78fb.entry.js +1019 -0
  282. package/dist/twilight/{p-fc540bfc.entry.js → p-ac57e992.entry.js} +1 -1
  283. package/dist/twilight/{p-42d531d7.entry.js → p-ac9bf5bf.entry.js} +1 -1
  284. package/dist/twilight/{p-1633e09a.entry.js → p-acf12c83.entry.js} +1 -1
  285. package/dist/twilight/{p-886d3ea9.entry.js → p-afd1364b.entry.js} +1 -1
  286. package/dist/twilight/{p-1a624e8e.entry.js → p-b0a99b96.entry.js} +1 -1
  287. package/dist/twilight/{p-c5e14a6d.entry.js → p-b2069f14.entry.js} +1 -1
  288. package/dist/twilight/{p-7679487d.entry.js → p-b42c7823.entry.js} +1 -1
  289. package/dist/twilight/{p-942e5b3e.entry.js → p-b6661dd0.entry.js} +1 -1
  290. package/dist/twilight/{p-2fea82d1.entry.js → p-b929dda0.entry.js} +1 -1
  291. package/dist/twilight/{p-f0320140.entry.js → p-b9385507.entry.js} +1 -1
  292. package/dist/twilight/{p-20ca668a.entry.js → p-bb4205bf.entry.js} +1 -1
  293. package/dist/twilight/{p-09a25c7b.entry.js → p-bec9d32a.entry.js} +1 -1
  294. package/dist/twilight/{p-2774b070.entry.js → p-c69e79ac.entry.js} +1 -1
  295. package/dist/twilight/{p-1fe09ed1.entry.js → p-c82f5b3f.entry.js} +1 -1
  296. package/dist/twilight/{p-d62d8969.entry.js → p-caaff989.entry.js} +1 -1
  297. package/dist/twilight/{p-83b70db5.entry.js → p-d18cb38a.entry.js} +1 -1
  298. package/dist/twilight/{p-9b225829.entry.js → p-d1cabb89.entry.js} +1 -1
  299. package/dist/twilight/{p-4818c549.entry.js → p-db744497.entry.js} +1 -1
  300. package/dist/twilight/{p-a22fd70d.entry.js → p-e0bf3d3e.entry.js} +1 -1
  301. package/dist/twilight/{p-f47cd970.entry.js → p-e632fbe1.entry.js} +1 -1
  302. package/dist/twilight/{p-e034fe03.entry.js → p-e6f50fda.entry.js} +1 -1
  303. package/dist/twilight/{p-50fd3bb0.entry.js → p-e725ca51.entry.js} +1 -1
  304. package/dist/twilight/{p-c42fd7ea.entry.js → p-ea1f6f62.entry.js} +1 -1
  305. package/dist/twilight/{p-4b9070f7.entry.js → p-eb9802ec.entry.js} +1 -1
  306. package/dist/twilight/{p-36b79398.entry.js → p-eeb759a2.entry.js} +1 -1
  307. package/dist/twilight/{p-13160d7a.entry.js → p-f13ab7c3.entry.js} +1 -1
  308. package/dist/twilight/{p-00a2d304.entry.js → p-f9a6bd74.entry.js} +1 -1
  309. package/dist/twilight/{p-oPliK7PL.js → p-fngctMOB.js} +1 -1
  310. package/dist/twilight/{p-BZ_8M_tQ.js → p-nNw4abgW.js} +1 -1
  311. package/dist/twilight/{p-DD5p3dqh.js → p-saXA_VGx.js} +1 -1
  312. package/dist/twilight/twilight.esm.js +1 -1
  313. package/dist/types/components/salla-bullet-delivery/api-service.d.ts +1 -0
  314. package/dist/types/components/salla-bullet-delivery/helpers.d.ts +3 -0
  315. package/dist/types/components/salla-bullet-delivery/interfaces.d.ts +3 -0
  316. package/dist/types/components/salla-bullet-delivery/salla-bullet-delivery.d.ts +23 -1
  317. package/package.json +8 -5
  318. package/dist/twilight/p-94d03d81.entry.js +0 -4
  319. package/dist/twilight/p-a09eb593.entry.js +0 -4
  320. package/dist/twilight/p-d86fb5f9.entry.js +0 -4
@@ -0,0 +1,2444 @@
1
+ /*!
2
+ * Crafted with ❤ by Salla
3
+ */
4
+ 'use strict';
5
+
6
+ const { getOwnPropertyNames, getOwnPropertySymbols } = Object;
7
+ // eslint-disable-next-line @typescript-eslint/unbound-method
8
+ const { hasOwnProperty } = Object.prototype;
9
+ /**
10
+ * Combine two comparators into a single comparators.
11
+ */
12
+ function combineComparators(comparatorA, comparatorB) {
13
+ return function isEqual(a, b, state) {
14
+ return comparatorA(a, b, state) && comparatorB(a, b, state);
15
+ };
16
+ }
17
+ /**
18
+ * Wrap the provided `areItemsEqual` method to manage the circular state, allowing
19
+ * for circular references to be safely included in the comparison without creating
20
+ * stack overflows.
21
+ */
22
+ function createIsCircular(areItemsEqual) {
23
+ return function isCircular(a, b, state) {
24
+ if (!a || !b || typeof a !== 'object' || typeof b !== 'object') {
25
+ return areItemsEqual(a, b, state);
26
+ }
27
+ const { cache } = state;
28
+ const cachedA = cache.get(a);
29
+ const cachedB = cache.get(b);
30
+ if (cachedA && cachedB) {
31
+ return cachedA === b && cachedB === a;
32
+ }
33
+ cache.set(a, b);
34
+ cache.set(b, a);
35
+ const result = areItemsEqual(a, b, state);
36
+ cache.delete(a);
37
+ cache.delete(b);
38
+ return result;
39
+ };
40
+ }
41
+ /**
42
+ * Get the `@@toStringTag` of the value, if it exists.
43
+ */
44
+ function getShortTag(value) {
45
+ return value != null ? value[Symbol.toStringTag] : undefined;
46
+ }
47
+ /**
48
+ * Get the properties to strictly examine, which include both own properties that are
49
+ * not enumerable and symbol properties.
50
+ */
51
+ function getStrictProperties(object) {
52
+ return getOwnPropertyNames(object).concat(getOwnPropertySymbols(object));
53
+ }
54
+ /**
55
+ * Whether the object contains the property passed as an own property.
56
+ */
57
+ const hasOwn =
58
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
59
+ Object.hasOwn || ((object, property) => hasOwnProperty.call(object, property));
60
+ /**
61
+ * Whether the values passed are strictly equal or both NaN.
62
+ */
63
+ function sameValueZeroEqual(a, b) {
64
+ return a === b || (!a && !b && a !== a && b !== b);
65
+ }
66
+
67
+ const PREACT_VNODE = '__v';
68
+ const PREACT_OWNER = '__o';
69
+ const REACT_OWNER = '_owner';
70
+ const { getOwnPropertyDescriptor, keys } = Object;
71
+ /**
72
+ * Whether the array buffers are equal in value.
73
+ */
74
+ function areArrayBuffersEqual(a, b) {
75
+ return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a), new Uint8Array(b));
76
+ }
77
+ /**
78
+ * Whether the arrays are equal in value.
79
+ */
80
+ function areArraysEqual(a, b, state) {
81
+ let index = a.length;
82
+ if (b.length !== index) {
83
+ return false;
84
+ }
85
+ while (index-- > 0) {
86
+ if (!state.equals(a[index], b[index], index, index, a, b, state)) {
87
+ return false;
88
+ }
89
+ }
90
+ return true;
91
+ }
92
+ /**
93
+ * Whether the dataviews are equal in value.
94
+ */
95
+ function areDataViewsEqual(a, b) {
96
+ return (a.byteLength === b.byteLength
97
+ && areTypedArraysEqual(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength)));
98
+ }
99
+ /**
100
+ * Whether the dates passed are equal in value.
101
+ */
102
+ function areDatesEqual(a, b) {
103
+ return sameValueZeroEqual(a.getTime(), b.getTime());
104
+ }
105
+ /**
106
+ * Whether the errors passed are equal in value.
107
+ */
108
+ function areErrorsEqual(a, b) {
109
+ return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack;
110
+ }
111
+ /**
112
+ * Whether the functions passed are equal in value.
113
+ */
114
+ function areFunctionsEqual(a, b) {
115
+ return a === b;
116
+ }
117
+ /**
118
+ * Whether the `Map`s are equal in value.
119
+ */
120
+ function areMapsEqual(a, b, state) {
121
+ const size = a.size;
122
+ if (size !== b.size) {
123
+ return false;
124
+ }
125
+ if (!size) {
126
+ return true;
127
+ }
128
+ const matchedIndices = new Array(size);
129
+ const aIterable = a.entries();
130
+ let aResult;
131
+ let bResult;
132
+ let index = 0;
133
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
134
+ while ((aResult = aIterable.next())) {
135
+ if (aResult.done) {
136
+ break;
137
+ }
138
+ const bIterable = b.entries();
139
+ let hasMatch = false;
140
+ let matchIndex = 0;
141
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
142
+ while ((bResult = bIterable.next())) {
143
+ if (bResult.done) {
144
+ break;
145
+ }
146
+ if (matchedIndices[matchIndex]) {
147
+ matchIndex++;
148
+ continue;
149
+ }
150
+ const aEntry = aResult.value;
151
+ const bEntry = bResult.value;
152
+ if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state)
153
+ && state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) {
154
+ hasMatch = matchedIndices[matchIndex] = true;
155
+ break;
156
+ }
157
+ matchIndex++;
158
+ }
159
+ if (!hasMatch) {
160
+ return false;
161
+ }
162
+ index++;
163
+ }
164
+ return true;
165
+ }
166
+ /**
167
+ * Whether the numbers are equal in value.
168
+ */
169
+ const areNumbersEqual = sameValueZeroEqual;
170
+ /**
171
+ * Whether the objects are equal in value.
172
+ */
173
+ function areObjectsEqual(a, b, state) {
174
+ const properties = keys(a);
175
+ let index = properties.length;
176
+ if (keys(b).length !== index) {
177
+ return false;
178
+ }
179
+ // Decrementing `while` showed faster results than either incrementing or
180
+ // decrementing `for` loop and than an incrementing `while` loop. Declarative
181
+ // methods like `some` / `every` were not used to avoid incurring the garbage
182
+ // cost of anonymous callbacks.
183
+ while (index-- > 0) {
184
+ if (!isPropertyEqual(a, b, state, properties[index])) {
185
+ return false;
186
+ }
187
+ }
188
+ return true;
189
+ }
190
+ /**
191
+ * Whether the objects are equal in value with strict property checking.
192
+ */
193
+ function areObjectsEqualStrict(a, b, state) {
194
+ const properties = getStrictProperties(a);
195
+ let index = properties.length;
196
+ if (getStrictProperties(b).length !== index) {
197
+ return false;
198
+ }
199
+ let property;
200
+ let descriptorA;
201
+ let descriptorB;
202
+ // Decrementing `while` showed faster results than either incrementing or
203
+ // decrementing `for` loop and than an incrementing `while` loop. Declarative
204
+ // methods like `some` / `every` were not used to avoid incurring the garbage
205
+ // cost of anonymous callbacks.
206
+ while (index-- > 0) {
207
+ property = properties[index];
208
+ if (!isPropertyEqual(a, b, state, property)) {
209
+ return false;
210
+ }
211
+ descriptorA = getOwnPropertyDescriptor(a, property);
212
+ descriptorB = getOwnPropertyDescriptor(b, property);
213
+ if ((descriptorA || descriptorB)
214
+ && (!descriptorA
215
+ || !descriptorB
216
+ || descriptorA.configurable !== descriptorB.configurable
217
+ || descriptorA.enumerable !== descriptorB.enumerable
218
+ || descriptorA.writable !== descriptorB.writable)) {
219
+ return false;
220
+ }
221
+ }
222
+ return true;
223
+ }
224
+ /**
225
+ * Whether the primitive wrappers passed are equal in value.
226
+ */
227
+ function arePrimitiveWrappersEqual(a, b) {
228
+ return sameValueZeroEqual(a.valueOf(), b.valueOf());
229
+ }
230
+ /**
231
+ * Whether the regexps passed are equal in value.
232
+ */
233
+ function areRegExpsEqual(a, b) {
234
+ return a.source === b.source && a.flags === b.flags;
235
+ }
236
+ /**
237
+ * Whether the `Set`s are equal in value.
238
+ */
239
+ function areSetsEqual(a, b, state) {
240
+ const size = a.size;
241
+ if (size !== b.size) {
242
+ return false;
243
+ }
244
+ if (!size) {
245
+ return true;
246
+ }
247
+ const matchedIndices = new Array(size);
248
+ const aIterable = a.values();
249
+ let aResult;
250
+ let bResult;
251
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
252
+ while ((aResult = aIterable.next())) {
253
+ if (aResult.done) {
254
+ break;
255
+ }
256
+ const bIterable = b.values();
257
+ let hasMatch = false;
258
+ let matchIndex = 0;
259
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
260
+ while ((bResult = bIterable.next())) {
261
+ if (bResult.done) {
262
+ break;
263
+ }
264
+ if (!matchedIndices[matchIndex]
265
+ && state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) {
266
+ hasMatch = matchedIndices[matchIndex] = true;
267
+ break;
268
+ }
269
+ matchIndex++;
270
+ }
271
+ if (!hasMatch) {
272
+ return false;
273
+ }
274
+ }
275
+ return true;
276
+ }
277
+ /**
278
+ * Whether the TypedArray instances are equal in value.
279
+ */
280
+ function areTypedArraysEqual(a, b) {
281
+ let index = a.byteLength;
282
+ if (b.byteLength !== index || a.byteOffset !== b.byteOffset) {
283
+ return false;
284
+ }
285
+ while (index-- > 0) {
286
+ if (a[index] !== b[index]) {
287
+ return false;
288
+ }
289
+ }
290
+ return true;
291
+ }
292
+ /**
293
+ * Whether the URL instances are equal in value.
294
+ */
295
+ function areUrlsEqual(a, b) {
296
+ return (a.hostname === b.hostname
297
+ && a.pathname === b.pathname
298
+ && a.protocol === b.protocol
299
+ && a.port === b.port
300
+ && a.hash === b.hash
301
+ && a.username === b.username
302
+ && a.password === b.password);
303
+ }
304
+ function isPropertyEqual(a, b, state, property) {
305
+ if ((property === REACT_OWNER || property === PREACT_OWNER || property === PREACT_VNODE)
306
+ && (a.$$typeof || b.$$typeof)) {
307
+ return true;
308
+ }
309
+ return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
310
+ }
311
+
312
+ const ARRAY_BUFFER_TAG = '[object ArrayBuffer]';
313
+ const ARGUMENTS_TAG = '[object Arguments]';
314
+ const BOOLEAN_TAG = '[object Boolean]';
315
+ const DATA_VIEW_TAG = '[object DataView]';
316
+ const DATE_TAG = '[object Date]';
317
+ const ERROR_TAG = '[object Error]';
318
+ const MAP_TAG = '[object Map]';
319
+ const NUMBER_TAG = '[object Number]';
320
+ const OBJECT_TAG = '[object Object]';
321
+ const REG_EXP_TAG = '[object RegExp]';
322
+ const SET_TAG = '[object Set]';
323
+ const STRING_TAG = '[object String]';
324
+ const TYPED_ARRAY_TAGS = {
325
+ '[object Int8Array]': true,
326
+ '[object Uint8Array]': true,
327
+ '[object Uint8ClampedArray]': true,
328
+ '[object Int16Array]': true,
329
+ '[object Uint16Array]': true,
330
+ '[object Int32Array]': true,
331
+ '[object Uint32Array]': true,
332
+ '[object Float16Array]': true,
333
+ '[object Float32Array]': true,
334
+ '[object Float64Array]': true,
335
+ '[object BigInt64Array]': true,
336
+ '[object BigUint64Array]': true,
337
+ };
338
+ const URL_TAG = '[object URL]';
339
+ // eslint-disable-next-line @typescript-eslint/unbound-method
340
+ const toString = Object.prototype.toString;
341
+ /**
342
+ * Create a comparator method based on the type-specific equality comparators passed.
343
+ */
344
+ function createEqualityComparator({ areArrayBuffersEqual, areArraysEqual, areDataViewsEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual, unknownTagComparators, }) {
345
+ /**
346
+ * compare the value of the two objects and return true if they are equivalent in values
347
+ */
348
+ return function comparator(a, b, state) {
349
+ // If the items are strictly equal, no need to do a value comparison.
350
+ if (a === b) {
351
+ return true;
352
+ }
353
+ // If either of the items are nullish and fail the strictly equal check
354
+ // above, then they must be unequal.
355
+ if (a == null || b == null) {
356
+ return false;
357
+ }
358
+ const type = typeof a;
359
+ if (type !== typeof b) {
360
+ return false;
361
+ }
362
+ if (type !== 'object') {
363
+ if (type === 'number') {
364
+ return areNumbersEqual(a, b, state);
365
+ }
366
+ if (type === 'function') {
367
+ return areFunctionsEqual(a, b, state);
368
+ }
369
+ // If a primitive value that is not strictly equal, it must be unequal.
370
+ return false;
371
+ }
372
+ const constructor = a.constructor;
373
+ // Checks are listed in order of commonality of use-case:
374
+ // 1. Common complex object types (plain object, array)
375
+ // 2. Common data values (date, regexp)
376
+ // 3. Less-common complex object types (map, set)
377
+ // 4. Less-common data values (promise, primitive wrappers)
378
+ // Inherently this is both subjective and assumptive, however
379
+ // when reviewing comparable libraries in the wild this order
380
+ // appears to be generally consistent.
381
+ // Constructors should match, otherwise there is potential for false positives
382
+ // between class and subclass or custom object and POJO.
383
+ if (constructor !== b.constructor) {
384
+ return false;
385
+ }
386
+ // `isPlainObject` only checks against the object's own realm. Cross-realm
387
+ // comparisons are rare, and will be handled in the ultimate fallback, so
388
+ // we can avoid capturing the string tag.
389
+ if (constructor === Object) {
390
+ return areObjectsEqual(a, b, state);
391
+ }
392
+ // `isArray()` works on subclasses and is cross-realm, so we can avoid capturing
393
+ // the string tag or doing an `instanceof` check.
394
+ if (Array.isArray(a)) {
395
+ return areArraysEqual(a, b, state);
396
+ }
397
+ // Try to fast-path equality checks for other complex object types in the
398
+ // same realm to avoid capturing the string tag. Strict equality is used
399
+ // instead of `instanceof` because it is more performant for the common
400
+ // use-case. If someone is subclassing a native class, it will be handled
401
+ // with the string tag comparison.
402
+ if (constructor === Date) {
403
+ return areDatesEqual(a, b, state);
404
+ }
405
+ if (constructor === RegExp) {
406
+ return areRegExpsEqual(a, b, state);
407
+ }
408
+ if (constructor === Map) {
409
+ return areMapsEqual(a, b, state);
410
+ }
411
+ if (constructor === Set) {
412
+ return areSetsEqual(a, b, state);
413
+ }
414
+ // Since this is a custom object, capture the string tag to determing its type.
415
+ // This is reasonably performant in modern environments like v8 and SpiderMonkey.
416
+ const tag = toString.call(a);
417
+ if (tag === DATE_TAG) {
418
+ return areDatesEqual(a, b, state);
419
+ }
420
+ // For RegExp, the properties are not enumerable, and therefore will give false positives if
421
+ // tested like a standard object.
422
+ if (tag === REG_EXP_TAG) {
423
+ return areRegExpsEqual(a, b, state);
424
+ }
425
+ if (tag === MAP_TAG) {
426
+ return areMapsEqual(a, b, state);
427
+ }
428
+ if (tag === SET_TAG) {
429
+ return areSetsEqual(a, b, state);
430
+ }
431
+ if (tag === OBJECT_TAG) {
432
+ // The exception for value comparison is custom `Promise`-like class instances. These should
433
+ // be treated the same as standard `Promise` objects, which means strict equality, and if
434
+ // it reaches this point then that strict equality comparison has already failed.
435
+ return typeof a.then !== 'function' && typeof b.then !== 'function' && areObjectsEqual(a, b, state);
436
+ }
437
+ // If a URL tag, it should be tested explicitly. Like RegExp, the properties are not
438
+ // enumerable, and therefore will give false positives if tested like a standard object.
439
+ if (tag === URL_TAG) {
440
+ return areUrlsEqual(a, b, state);
441
+ }
442
+ // If an error tag, it should be tested explicitly. Like RegExp, the properties are not
443
+ // enumerable, and therefore will give false positives if tested like a standard object.
444
+ if (tag === ERROR_TAG) {
445
+ return areErrorsEqual(a, b, state);
446
+ }
447
+ // If an arguments tag, it should be treated as a standard object.
448
+ if (tag === ARGUMENTS_TAG) {
449
+ return areObjectsEqual(a, b, state);
450
+ }
451
+ if (TYPED_ARRAY_TAGS[tag]) {
452
+ return areTypedArraysEqual(a, b, state);
453
+ }
454
+ if (tag === ARRAY_BUFFER_TAG) {
455
+ return areArrayBuffersEqual(a, b, state);
456
+ }
457
+ if (tag === DATA_VIEW_TAG) {
458
+ return areDataViewsEqual(a, b, state);
459
+ }
460
+ // As the penultimate fallback, check if the values passed are primitive wrappers. This
461
+ // is very rare in modern JS, which is why it is deprioritized compared to all other object
462
+ // types.
463
+ if (tag === BOOLEAN_TAG || tag === NUMBER_TAG || tag === STRING_TAG) {
464
+ return arePrimitiveWrappersEqual(a, b, state);
465
+ }
466
+ if (unknownTagComparators) {
467
+ let unknownTagComparator = unknownTagComparators[tag];
468
+ if (!unknownTagComparator) {
469
+ const shortTag = getShortTag(a);
470
+ if (shortTag) {
471
+ unknownTagComparator = unknownTagComparators[shortTag];
472
+ }
473
+ }
474
+ // If the custom config has an unknown tag comparator that matches the captured tag or the
475
+ // @@toStringTag, it is the source of truth for whether the values are equal.
476
+ if (unknownTagComparator) {
477
+ return unknownTagComparator(a, b, state);
478
+ }
479
+ }
480
+ // If not matching any tags that require a specific type of comparison, then we hard-code false because
481
+ // the only thing remaining is strict equality, which has already been compared. This is for a few reasons:
482
+ // - Certain types that cannot be introspected (e.g., `WeakMap`). For these types, this is the only
483
+ // comparison that can be made.
484
+ // - For types that can be introspected, but rarely have requirements to be compared
485
+ // (`ArrayBuffer`, `DataView`, etc.), the cost is avoided to prioritize the common
486
+ // use-cases (may be included in a future release, if requested enough).
487
+ // - For types that can be introspected but do not have an objective definition of what
488
+ // equality is (`Error`, etc.), the subjective decision is to be conservative and strictly compare.
489
+ // In all cases, these decisions should be reevaluated based on changes to the language and
490
+ // common development practices.
491
+ return false;
492
+ };
493
+ }
494
+ /**
495
+ * Create the configuration object used for building comparators.
496
+ */
497
+ function createEqualityComparatorConfig({ circular, createCustomConfig, strict, }) {
498
+ let config = {
499
+ areArrayBuffersEqual,
500
+ areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
501
+ areDataViewsEqual,
502
+ areDatesEqual: areDatesEqual,
503
+ areErrorsEqual: areErrorsEqual,
504
+ areFunctionsEqual: areFunctionsEqual,
505
+ areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
506
+ areNumbersEqual: areNumbersEqual,
507
+ areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
508
+ arePrimitiveWrappersEqual: arePrimitiveWrappersEqual,
509
+ areRegExpsEqual: areRegExpsEqual,
510
+ areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
511
+ areTypedArraysEqual: strict
512
+ ? combineComparators(areTypedArraysEqual, areObjectsEqualStrict)
513
+ : areTypedArraysEqual,
514
+ areUrlsEqual: areUrlsEqual,
515
+ unknownTagComparators: undefined,
516
+ };
517
+ if (createCustomConfig) {
518
+ config = Object.assign({}, config, createCustomConfig(config));
519
+ }
520
+ if (circular) {
521
+ const areArraysEqual = createIsCircular(config.areArraysEqual);
522
+ const areMapsEqual = createIsCircular(config.areMapsEqual);
523
+ const areObjectsEqual = createIsCircular(config.areObjectsEqual);
524
+ const areSetsEqual = createIsCircular(config.areSetsEqual);
525
+ config = Object.assign({}, config, {
526
+ areArraysEqual,
527
+ areMapsEqual,
528
+ areObjectsEqual,
529
+ areSetsEqual,
530
+ });
531
+ }
532
+ return config;
533
+ }
534
+ /**
535
+ * Default equality comparator pass-through, used as the standard `isEqual` creator for
536
+ * use inside the built comparator.
537
+ */
538
+ function createInternalEqualityComparator(compare) {
539
+ return function (a, b, _indexOrKeyA, _indexOrKeyB, _parentA, _parentB, state) {
540
+ return compare(a, b, state);
541
+ };
542
+ }
543
+ /**
544
+ * Create the `isEqual` function used by the consuming application.
545
+ */
546
+ function createIsEqual({ circular, comparator, createState, equals, strict }) {
547
+ if (createState) {
548
+ return function isEqual(a, b) {
549
+ const { cache = circular ? new WeakMap() : undefined, meta } = createState();
550
+ return comparator(a, b, {
551
+ cache,
552
+ equals,
553
+ meta,
554
+ strict,
555
+ });
556
+ };
557
+ }
558
+ if (circular) {
559
+ return function isEqual(a, b) {
560
+ return comparator(a, b, {
561
+ cache: new WeakMap(),
562
+ equals,
563
+ meta: undefined,
564
+ strict,
565
+ });
566
+ };
567
+ }
568
+ const state = {
569
+ cache: undefined,
570
+ equals,
571
+ meta: undefined,
572
+ strict,
573
+ };
574
+ return function isEqual(a, b) {
575
+ return comparator(a, b, state);
576
+ };
577
+ }
578
+
579
+ /**
580
+ * Whether the items passed are deeply-equal in value.
581
+ */
582
+ const deepEqual = createCustomEqual();
583
+ /**
584
+ * Whether the items passed are deeply-equal in value based on strict comparison.
585
+ */
586
+ createCustomEqual({ strict: true });
587
+ /**
588
+ * Whether the items passed are deeply-equal in value, including circular references.
589
+ */
590
+ createCustomEqual({ circular: true });
591
+ /**
592
+ * Whether the items passed are deeply-equal in value, including circular references,
593
+ * based on strict comparison.
594
+ */
595
+ createCustomEqual({
596
+ circular: true,
597
+ strict: true,
598
+ });
599
+ /**
600
+ * Whether the items passed are shallowly-equal in value.
601
+ */
602
+ createCustomEqual({
603
+ createInternalComparator: () => sameValueZeroEqual,
604
+ });
605
+ /**
606
+ * Whether the items passed are shallowly-equal in value based on strict comparison
607
+ */
608
+ createCustomEqual({
609
+ strict: true,
610
+ createInternalComparator: () => sameValueZeroEqual,
611
+ });
612
+ /**
613
+ * Whether the items passed are shallowly-equal in value, including circular references.
614
+ */
615
+ createCustomEqual({
616
+ circular: true,
617
+ createInternalComparator: () => sameValueZeroEqual,
618
+ });
619
+ /**
620
+ * Whether the items passed are shallowly-equal in value, including circular references,
621
+ * based on strict comparison.
622
+ */
623
+ createCustomEqual({
624
+ circular: true,
625
+ createInternalComparator: () => sameValueZeroEqual,
626
+ strict: true,
627
+ });
628
+ /**
629
+ * Create a custom equality comparison method.
630
+ *
631
+ * This can be done to create very targeted comparisons in extreme hot-path scenarios
632
+ * where the standard methods are not performant enough, but can also be used to provide
633
+ * support for legacy environments that do not support expected features like
634
+ * `RegExp.prototype.flags` out of the box.
635
+ */
636
+ function createCustomEqual(options = {}) {
637
+ const { circular = false, createInternalComparator: createCustomInternalComparator, createState, strict = false, } = options;
638
+ const config = createEqualityComparatorConfig(options);
639
+ const comparator = createEqualityComparator(config);
640
+ const equals = createCustomInternalComparator
641
+ ? createCustomInternalComparator(comparator)
642
+ : createInternalEqualityComparator(comparator);
643
+ return createIsEqual({ circular, comparator, createState, equals, strict });
644
+ }
645
+
646
+ const ARRAY_TYPES = [
647
+ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array,
648
+ Int32Array, Uint32Array, Float32Array, Float64Array
649
+ ];
650
+
651
+ /** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor} TypedArrayConstructor */
652
+
653
+ const VERSION = 1; // serialized format version
654
+ const HEADER_SIZE = 8;
655
+
656
+ class KDBush {
657
+
658
+ /**
659
+ * Creates an index from raw `ArrayBuffer` data.
660
+ * @param {ArrayBuffer} data
661
+ */
662
+ static from(data) {
663
+ if (!(data instanceof ArrayBuffer)) {
664
+ throw new Error('Data must be an instance of ArrayBuffer.');
665
+ }
666
+ const [magic, versionAndType] = new Uint8Array(data, 0, 2);
667
+ if (magic !== 0xdb) {
668
+ throw new Error('Data does not appear to be in a KDBush format.');
669
+ }
670
+ const version = versionAndType >> 4;
671
+ if (version !== VERSION) {
672
+ throw new Error(`Got v${version} data when expected v${VERSION}.`);
673
+ }
674
+ const ArrayType = ARRAY_TYPES[versionAndType & 0x0f];
675
+ if (!ArrayType) {
676
+ throw new Error('Unrecognized array type.');
677
+ }
678
+ const [nodeSize] = new Uint16Array(data, 2, 1);
679
+ const [numItems] = new Uint32Array(data, 4, 1);
680
+
681
+ return new KDBush(numItems, nodeSize, ArrayType, data);
682
+ }
683
+
684
+ /**
685
+ * Creates an index that will hold a given number of items.
686
+ * @param {number} numItems
687
+ * @param {number} [nodeSize=64] Size of the KD-tree node (64 by default).
688
+ * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
689
+ * @param {ArrayBuffer} [data] (For internal use only)
690
+ */
691
+ constructor(numItems, nodeSize = 64, ArrayType = Float64Array, data) {
692
+ if (isNaN(numItems) || numItems < 0) throw new Error(`Unpexpected numItems value: ${numItems}.`);
693
+
694
+ this.numItems = +numItems;
695
+ this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);
696
+ this.ArrayType = ArrayType;
697
+ this.IndexArrayType = numItems < 65536 ? Uint16Array : Uint32Array;
698
+
699
+ const arrayTypeIndex = ARRAY_TYPES.indexOf(this.ArrayType);
700
+ const coordsByteSize = numItems * 2 * this.ArrayType.BYTES_PER_ELEMENT;
701
+ const idsByteSize = numItems * this.IndexArrayType.BYTES_PER_ELEMENT;
702
+ const padCoords = (8 - idsByteSize % 8) % 8;
703
+
704
+ if (arrayTypeIndex < 0) {
705
+ throw new Error(`Unexpected typed array class: ${ArrayType}.`);
706
+ }
707
+
708
+ if (data && (data instanceof ArrayBuffer)) { // reconstruct an index from a buffer
709
+ this.data = data;
710
+ this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
711
+ this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
712
+ this._pos = numItems * 2;
713
+ this._finished = true;
714
+ } else { // initialize a new index
715
+ this.data = new ArrayBuffer(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);
716
+ this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
717
+ this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
718
+ this._pos = 0;
719
+ this._finished = false;
720
+
721
+ // set header
722
+ new Uint8Array(this.data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);
723
+ new Uint16Array(this.data, 2, 1)[0] = nodeSize;
724
+ new Uint32Array(this.data, 4, 1)[0] = numItems;
725
+ }
726
+ }
727
+
728
+ /**
729
+ * Add a point to the index.
730
+ * @param {number} x
731
+ * @param {number} y
732
+ * @returns {number} An incremental index associated with the added item (starting from `0`).
733
+ */
734
+ add(x, y) {
735
+ const index = this._pos >> 1;
736
+ this.ids[index] = index;
737
+ this.coords[this._pos++] = x;
738
+ this.coords[this._pos++] = y;
739
+ return index;
740
+ }
741
+
742
+ /**
743
+ * Perform indexing of the added points.
744
+ */
745
+ finish() {
746
+ const numAdded = this._pos >> 1;
747
+ if (numAdded !== this.numItems) {
748
+ throw new Error(`Added ${numAdded} items when expected ${this.numItems}.`);
749
+ }
750
+ // kd-sort both arrays for efficient search
751
+ sort(this.ids, this.coords, this.nodeSize, 0, this.numItems - 1, 0);
752
+
753
+ this._finished = true;
754
+ return this;
755
+ }
756
+
757
+ /**
758
+ * Search the index for items within a given bounding box.
759
+ * @param {number} minX
760
+ * @param {number} minY
761
+ * @param {number} maxX
762
+ * @param {number} maxY
763
+ * @returns {number[]} An array of indices correponding to the found items.
764
+ */
765
+ range(minX, minY, maxX, maxY) {
766
+ if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
767
+
768
+ const {ids, coords, nodeSize} = this;
769
+ const stack = [0, ids.length - 1, 0];
770
+ const result = [];
771
+
772
+ // recursively search for items in range in the kd-sorted arrays
773
+ while (stack.length) {
774
+ const axis = stack.pop() || 0;
775
+ const right = stack.pop() || 0;
776
+ const left = stack.pop() || 0;
777
+
778
+ // if we reached "tree node", search linearly
779
+ if (right - left <= nodeSize) {
780
+ for (let i = left; i <= right; i++) {
781
+ const x = coords[2 * i];
782
+ const y = coords[2 * i + 1];
783
+ if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[i]);
784
+ }
785
+ continue;
786
+ }
787
+
788
+ // otherwise find the middle index
789
+ const m = (left + right) >> 1;
790
+
791
+ // include the middle item if it's in range
792
+ const x = coords[2 * m];
793
+ const y = coords[2 * m + 1];
794
+ if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[m]);
795
+
796
+ // queue search in halves that intersect the query
797
+ if (axis === 0 ? minX <= x : minY <= y) {
798
+ stack.push(left);
799
+ stack.push(m - 1);
800
+ stack.push(1 - axis);
801
+ }
802
+ if (axis === 0 ? maxX >= x : maxY >= y) {
803
+ stack.push(m + 1);
804
+ stack.push(right);
805
+ stack.push(1 - axis);
806
+ }
807
+ }
808
+
809
+ return result;
810
+ }
811
+
812
+ /**
813
+ * Search the index for items within a given radius.
814
+ * @param {number} qx
815
+ * @param {number} qy
816
+ * @param {number} r Query radius.
817
+ * @returns {number[]} An array of indices correponding to the found items.
818
+ */
819
+ within(qx, qy, r) {
820
+ if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
821
+
822
+ const {ids, coords, nodeSize} = this;
823
+ const stack = [0, ids.length - 1, 0];
824
+ const result = [];
825
+ const r2 = r * r;
826
+
827
+ // recursively search for items within radius in the kd-sorted arrays
828
+ while (stack.length) {
829
+ const axis = stack.pop() || 0;
830
+ const right = stack.pop() || 0;
831
+ const left = stack.pop() || 0;
832
+
833
+ // if we reached "tree node", search linearly
834
+ if (right - left <= nodeSize) {
835
+ for (let i = left; i <= right; i++) {
836
+ if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) result.push(ids[i]);
837
+ }
838
+ continue;
839
+ }
840
+
841
+ // otherwise find the middle index
842
+ const m = (left + right) >> 1;
843
+
844
+ // include the middle item if it's in range
845
+ const x = coords[2 * m];
846
+ const y = coords[2 * m + 1];
847
+ if (sqDist(x, y, qx, qy) <= r2) result.push(ids[m]);
848
+
849
+ // queue search in halves that intersect the query
850
+ if (axis === 0 ? qx - r <= x : qy - r <= y) {
851
+ stack.push(left);
852
+ stack.push(m - 1);
853
+ stack.push(1 - axis);
854
+ }
855
+ if (axis === 0 ? qx + r >= x : qy + r >= y) {
856
+ stack.push(m + 1);
857
+ stack.push(right);
858
+ stack.push(1 - axis);
859
+ }
860
+ }
861
+
862
+ return result;
863
+ }
864
+ }
865
+
866
+ /**
867
+ * @param {Uint16Array | Uint32Array} ids
868
+ * @param {InstanceType<TypedArrayConstructor>} coords
869
+ * @param {number} nodeSize
870
+ * @param {number} left
871
+ * @param {number} right
872
+ * @param {number} axis
873
+ */
874
+ function sort(ids, coords, nodeSize, left, right, axis) {
875
+ if (right - left <= nodeSize) return;
876
+
877
+ const m = (left + right) >> 1; // middle index
878
+
879
+ // sort ids and coords around the middle index so that the halves lie
880
+ // either left/right or top/bottom correspondingly (taking turns)
881
+ select(ids, coords, m, left, right, axis);
882
+
883
+ // recursively kd-sort first half and second half on the opposite axis
884
+ sort(ids, coords, nodeSize, left, m - 1, 1 - axis);
885
+ sort(ids, coords, nodeSize, m + 1, right, 1 - axis);
886
+ }
887
+
888
+ /**
889
+ * Custom Floyd-Rivest selection algorithm: sort ids and coords so that
890
+ * [left..k-1] items are smaller than k-th item (on either x or y axis)
891
+ * @param {Uint16Array | Uint32Array} ids
892
+ * @param {InstanceType<TypedArrayConstructor>} coords
893
+ * @param {number} k
894
+ * @param {number} left
895
+ * @param {number} right
896
+ * @param {number} axis
897
+ */
898
+ function select(ids, coords, k, left, right, axis) {
899
+
900
+ while (right > left) {
901
+ if (right - left > 600) {
902
+ const n = right - left + 1;
903
+ const m = k - left + 1;
904
+ const z = Math.log(n);
905
+ const s = 0.5 * Math.exp(2 * z / 3);
906
+ const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
907
+ const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
908
+ const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
909
+ select(ids, coords, k, newLeft, newRight, axis);
910
+ }
911
+
912
+ const t = coords[2 * k + axis];
913
+ let i = left;
914
+ let j = right;
915
+
916
+ swapItem(ids, coords, left, k);
917
+ if (coords[2 * right + axis] > t) swapItem(ids, coords, left, right);
918
+
919
+ while (i < j) {
920
+ swapItem(ids, coords, i, j);
921
+ i++;
922
+ j--;
923
+ while (coords[2 * i + axis] < t) i++;
924
+ while (coords[2 * j + axis] > t) j--;
925
+ }
926
+
927
+ if (coords[2 * left + axis] === t) swapItem(ids, coords, left, j);
928
+ else {
929
+ j++;
930
+ swapItem(ids, coords, j, right);
931
+ }
932
+
933
+ if (j <= k) left = j + 1;
934
+ if (k <= j) right = j - 1;
935
+ }
936
+ }
937
+
938
+ /**
939
+ * @param {Uint16Array | Uint32Array} ids
940
+ * @param {InstanceType<TypedArrayConstructor>} coords
941
+ * @param {number} i
942
+ * @param {number} j
943
+ */
944
+ function swapItem(ids, coords, i, j) {
945
+ swap(ids, i, j);
946
+ swap(coords, 2 * i, 2 * j);
947
+ swap(coords, 2 * i + 1, 2 * j + 1);
948
+ }
949
+
950
+ /**
951
+ * @param {InstanceType<TypedArrayConstructor>} arr
952
+ * @param {number} i
953
+ * @param {number} j
954
+ */
955
+ function swap(arr, i, j) {
956
+ const tmp = arr[i];
957
+ arr[i] = arr[j];
958
+ arr[j] = tmp;
959
+ }
960
+
961
+ /**
962
+ * @param {number} ax
963
+ * @param {number} ay
964
+ * @param {number} bx
965
+ * @param {number} by
966
+ */
967
+ function sqDist(ax, ay, bx, by) {
968
+ const dx = ax - bx;
969
+ const dy = ay - by;
970
+ return dx * dx + dy * dy;
971
+ }
972
+
973
+ const defaultOptions = {
974
+ minZoom: 0, // min zoom to generate clusters on
975
+ maxZoom: 16, // max zoom level to cluster the points on
976
+ minPoints: 2, // minimum points to form a cluster
977
+ radius: 40, // cluster radius in pixels
978
+ extent: 512, // tile extent (radius is calculated relative to it)
979
+ nodeSize: 64, // size of the KD-tree leaf node, affects performance
980
+ log: false, // whether to log timing info
981
+
982
+ // whether to generate numeric ids for input features (in vector tiles)
983
+ generateId: false,
984
+
985
+ // a reduce function for calculating custom cluster properties
986
+ reduce: null, // (accumulated, props) => { accumulated.sum += props.sum; }
987
+
988
+ // properties to use for individual points when running the reducer
989
+ map: props => props // props => ({sum: props.my_value})
990
+ };
991
+
992
+ const fround = Math.fround || (tmp => ((x) => { tmp[0] = +x; return tmp[0]; }))(new Float32Array(1));
993
+
994
+ const OFFSET_ZOOM = 2;
995
+ const OFFSET_ID = 3;
996
+ const OFFSET_PARENT = 4;
997
+ const OFFSET_NUM = 5;
998
+ const OFFSET_PROP = 6;
999
+
1000
+ class Supercluster {
1001
+ constructor(options) {
1002
+ this.options = Object.assign(Object.create(defaultOptions), options);
1003
+ this.trees = new Array(this.options.maxZoom + 1);
1004
+ this.stride = this.options.reduce ? 7 : 6;
1005
+ this.clusterProps = [];
1006
+ }
1007
+
1008
+ load(points) {
1009
+ const {log, minZoom, maxZoom} = this.options;
1010
+
1011
+ if (log) console.time('total time');
1012
+
1013
+ const timerId = `prepare ${ points.length } points`;
1014
+ if (log) console.time(timerId);
1015
+
1016
+ this.points = points;
1017
+
1018
+ // generate a cluster object for each point and index input points into a KD-tree
1019
+ const data = [];
1020
+
1021
+ for (let i = 0; i < points.length; i++) {
1022
+ const p = points[i];
1023
+ if (!p.geometry) continue;
1024
+
1025
+ const [lng, lat] = p.geometry.coordinates;
1026
+ const x = fround(lngX(lng));
1027
+ const y = fround(latY(lat));
1028
+ // store internal point/cluster data in flat numeric arrays for performance
1029
+ data.push(
1030
+ x, y, // projected point coordinates
1031
+ Infinity, // the last zoom the point was processed at
1032
+ i, // index of the source feature in the original input array
1033
+ -1, // parent cluster id
1034
+ 1 // number of points in a cluster
1035
+ );
1036
+ if (this.options.reduce) data.push(0); // noop
1037
+ }
1038
+ let tree = this.trees[maxZoom + 1] = this._createTree(data);
1039
+
1040
+ if (log) console.timeEnd(timerId);
1041
+
1042
+ // cluster points on max zoom, then cluster the results on previous zoom, etc.;
1043
+ // results in a cluster hierarchy across zoom levels
1044
+ for (let z = maxZoom; z >= minZoom; z--) {
1045
+ const now = +Date.now();
1046
+
1047
+ // create a new set of clusters for the zoom and index them with a KD-tree
1048
+ tree = this.trees[z] = this._createTree(this._cluster(tree, z));
1049
+
1050
+ if (log) console.log('z%d: %d clusters in %dms', z, tree.numItems, +Date.now() - now);
1051
+ }
1052
+
1053
+ if (log) console.timeEnd('total time');
1054
+
1055
+ return this;
1056
+ }
1057
+
1058
+ getClusters(bbox, zoom) {
1059
+ let minLng = ((bbox[0] + 180) % 360 + 360) % 360 - 180;
1060
+ const minLat = Math.max(-90, Math.min(90, bbox[1]));
1061
+ let maxLng = bbox[2] === 180 ? 180 : ((bbox[2] + 180) % 360 + 360) % 360 - 180;
1062
+ const maxLat = Math.max(-90, Math.min(90, bbox[3]));
1063
+
1064
+ if (bbox[2] - bbox[0] >= 360) {
1065
+ minLng = -180;
1066
+ maxLng = 180;
1067
+ } else if (minLng > maxLng) {
1068
+ const easternHem = this.getClusters([minLng, minLat, 180, maxLat], zoom);
1069
+ const westernHem = this.getClusters([-180, minLat, maxLng, maxLat], zoom);
1070
+ return easternHem.concat(westernHem);
1071
+ }
1072
+
1073
+ const tree = this.trees[this._limitZoom(zoom)];
1074
+ const ids = tree.range(lngX(minLng), latY(maxLat), lngX(maxLng), latY(minLat));
1075
+ const data = tree.data;
1076
+ const clusters = [];
1077
+ for (const id of ids) {
1078
+ const k = this.stride * id;
1079
+ clusters.push(data[k + OFFSET_NUM] > 1 ? getClusterJSON(data, k, this.clusterProps) : this.points[data[k + OFFSET_ID]]);
1080
+ }
1081
+ return clusters;
1082
+ }
1083
+
1084
+ getChildren(clusterId) {
1085
+ const originId = this._getOriginId(clusterId);
1086
+ const originZoom = this._getOriginZoom(clusterId);
1087
+ const errorMsg = 'No cluster with the specified id.';
1088
+
1089
+ const tree = this.trees[originZoom];
1090
+ if (!tree) throw new Error(errorMsg);
1091
+
1092
+ const data = tree.data;
1093
+ if (originId * this.stride >= data.length) throw new Error(errorMsg);
1094
+
1095
+ const r = this.options.radius / (this.options.extent * Math.pow(2, originZoom - 1));
1096
+ const x = data[originId * this.stride];
1097
+ const y = data[originId * this.stride + 1];
1098
+ const ids = tree.within(x, y, r);
1099
+ const children = [];
1100
+ for (const id of ids) {
1101
+ const k = id * this.stride;
1102
+ if (data[k + OFFSET_PARENT] === clusterId) {
1103
+ children.push(data[k + OFFSET_NUM] > 1 ? getClusterJSON(data, k, this.clusterProps) : this.points[data[k + OFFSET_ID]]);
1104
+ }
1105
+ }
1106
+
1107
+ if (children.length === 0) throw new Error(errorMsg);
1108
+
1109
+ return children;
1110
+ }
1111
+
1112
+ getLeaves(clusterId, limit, offset) {
1113
+ limit = limit || 10;
1114
+ offset = offset || 0;
1115
+
1116
+ const leaves = [];
1117
+ this._appendLeaves(leaves, clusterId, limit, offset, 0);
1118
+
1119
+ return leaves;
1120
+ }
1121
+
1122
+ getTile(z, x, y) {
1123
+ const tree = this.trees[this._limitZoom(z)];
1124
+ const z2 = Math.pow(2, z);
1125
+ const {extent, radius} = this.options;
1126
+ const p = radius / extent;
1127
+ const top = (y - p) / z2;
1128
+ const bottom = (y + 1 + p) / z2;
1129
+
1130
+ const tile = {
1131
+ features: []
1132
+ };
1133
+
1134
+ this._addTileFeatures(
1135
+ tree.range((x - p) / z2, top, (x + 1 + p) / z2, bottom),
1136
+ tree.data, x, y, z2, tile);
1137
+
1138
+ if (x === 0) {
1139
+ this._addTileFeatures(
1140
+ tree.range(1 - p / z2, top, 1, bottom),
1141
+ tree.data, z2, y, z2, tile);
1142
+ }
1143
+ if (x === z2 - 1) {
1144
+ this._addTileFeatures(
1145
+ tree.range(0, top, p / z2, bottom),
1146
+ tree.data, -1, y, z2, tile);
1147
+ }
1148
+
1149
+ return tile.features.length ? tile : null;
1150
+ }
1151
+
1152
+ getClusterExpansionZoom(clusterId) {
1153
+ let expansionZoom = this._getOriginZoom(clusterId) - 1;
1154
+ while (expansionZoom <= this.options.maxZoom) {
1155
+ const children = this.getChildren(clusterId);
1156
+ expansionZoom++;
1157
+ if (children.length !== 1) break;
1158
+ clusterId = children[0].properties.cluster_id;
1159
+ }
1160
+ return expansionZoom;
1161
+ }
1162
+
1163
+ _appendLeaves(result, clusterId, limit, offset, skipped) {
1164
+ const children = this.getChildren(clusterId);
1165
+
1166
+ for (const child of children) {
1167
+ const props = child.properties;
1168
+
1169
+ if (props && props.cluster) {
1170
+ if (skipped + props.point_count <= offset) {
1171
+ // skip the whole cluster
1172
+ skipped += props.point_count;
1173
+ } else {
1174
+ // enter the cluster
1175
+ skipped = this._appendLeaves(result, props.cluster_id, limit, offset, skipped);
1176
+ // exit the cluster
1177
+ }
1178
+ } else if (skipped < offset) {
1179
+ // skip a single point
1180
+ skipped++;
1181
+ } else {
1182
+ // add a single point
1183
+ result.push(child);
1184
+ }
1185
+ if (result.length === limit) break;
1186
+ }
1187
+
1188
+ return skipped;
1189
+ }
1190
+
1191
+ _createTree(data) {
1192
+ const tree = new KDBush(data.length / this.stride | 0, this.options.nodeSize, Float32Array);
1193
+ for (let i = 0; i < data.length; i += this.stride) tree.add(data[i], data[i + 1]);
1194
+ tree.finish();
1195
+ tree.data = data;
1196
+ return tree;
1197
+ }
1198
+
1199
+ _addTileFeatures(ids, data, x, y, z2, tile) {
1200
+ for (const i of ids) {
1201
+ const k = i * this.stride;
1202
+ const isCluster = data[k + OFFSET_NUM] > 1;
1203
+
1204
+ let tags, px, py;
1205
+ if (isCluster) {
1206
+ tags = getClusterProperties(data, k, this.clusterProps);
1207
+ px = data[k];
1208
+ py = data[k + 1];
1209
+ } else {
1210
+ const p = this.points[data[k + OFFSET_ID]];
1211
+ tags = p.properties;
1212
+ const [lng, lat] = p.geometry.coordinates;
1213
+ px = lngX(lng);
1214
+ py = latY(lat);
1215
+ }
1216
+
1217
+ const f = {
1218
+ type: 1,
1219
+ geometry: [[
1220
+ Math.round(this.options.extent * (px * z2 - x)),
1221
+ Math.round(this.options.extent * (py * z2 - y))
1222
+ ]],
1223
+ tags
1224
+ };
1225
+
1226
+ // assign id
1227
+ let id;
1228
+ if (isCluster || this.options.generateId) {
1229
+ // optionally generate id for points
1230
+ id = data[k + OFFSET_ID];
1231
+ } else {
1232
+ // keep id if already assigned
1233
+ id = this.points[data[k + OFFSET_ID]].id;
1234
+ }
1235
+
1236
+ if (id !== undefined) f.id = id;
1237
+
1238
+ tile.features.push(f);
1239
+ }
1240
+ }
1241
+
1242
+ _limitZoom(z) {
1243
+ return Math.max(this.options.minZoom, Math.min(Math.floor(+z), this.options.maxZoom + 1));
1244
+ }
1245
+
1246
+ _cluster(tree, zoom) {
1247
+ const {radius, extent, reduce, minPoints} = this.options;
1248
+ const r = radius / (extent * Math.pow(2, zoom));
1249
+ const data = tree.data;
1250
+ const nextData = [];
1251
+ const stride = this.stride;
1252
+
1253
+ // loop through each point
1254
+ for (let i = 0; i < data.length; i += stride) {
1255
+ // if we've already visited the point at this zoom level, skip it
1256
+ if (data[i + OFFSET_ZOOM] <= zoom) continue;
1257
+ data[i + OFFSET_ZOOM] = zoom;
1258
+
1259
+ // find all nearby points
1260
+ const x = data[i];
1261
+ const y = data[i + 1];
1262
+ const neighborIds = tree.within(data[i], data[i + 1], r);
1263
+
1264
+ const numPointsOrigin = data[i + OFFSET_NUM];
1265
+ let numPoints = numPointsOrigin;
1266
+
1267
+ // count the number of points in a potential cluster
1268
+ for (const neighborId of neighborIds) {
1269
+ const k = neighborId * stride;
1270
+ // filter out neighbors that are already processed
1271
+ if (data[k + OFFSET_ZOOM] > zoom) numPoints += data[k + OFFSET_NUM];
1272
+ }
1273
+
1274
+ // if there were neighbors to merge, and there are enough points to form a cluster
1275
+ if (numPoints > numPointsOrigin && numPoints >= minPoints) {
1276
+ let wx = x * numPointsOrigin;
1277
+ let wy = y * numPointsOrigin;
1278
+
1279
+ let clusterProperties;
1280
+ let clusterPropIndex = -1;
1281
+
1282
+ // encode both zoom and point index on which the cluster originated -- offset by total length of features
1283
+ const id = ((i / stride | 0) << 5) + (zoom + 1) + this.points.length;
1284
+
1285
+ for (const neighborId of neighborIds) {
1286
+ const k = neighborId * stride;
1287
+
1288
+ if (data[k + OFFSET_ZOOM] <= zoom) continue;
1289
+ data[k + OFFSET_ZOOM] = zoom; // save the zoom (so it doesn't get processed twice)
1290
+
1291
+ const numPoints2 = data[k + OFFSET_NUM];
1292
+ wx += data[k] * numPoints2; // accumulate coordinates for calculating weighted center
1293
+ wy += data[k + 1] * numPoints2;
1294
+
1295
+ data[k + OFFSET_PARENT] = id;
1296
+
1297
+ if (reduce) {
1298
+ if (!clusterProperties) {
1299
+ clusterProperties = this._map(data, i, true);
1300
+ clusterPropIndex = this.clusterProps.length;
1301
+ this.clusterProps.push(clusterProperties);
1302
+ }
1303
+ reduce(clusterProperties, this._map(data, k));
1304
+ }
1305
+ }
1306
+
1307
+ data[i + OFFSET_PARENT] = id;
1308
+ nextData.push(wx / numPoints, wy / numPoints, Infinity, id, -1, numPoints);
1309
+ if (reduce) nextData.push(clusterPropIndex);
1310
+
1311
+ } else { // left points as unclustered
1312
+ for (let j = 0; j < stride; j++) nextData.push(data[i + j]);
1313
+
1314
+ if (numPoints > 1) {
1315
+ for (const neighborId of neighborIds) {
1316
+ const k = neighborId * stride;
1317
+ if (data[k + OFFSET_ZOOM] <= zoom) continue;
1318
+ data[k + OFFSET_ZOOM] = zoom;
1319
+ for (let j = 0; j < stride; j++) nextData.push(data[k + j]);
1320
+ }
1321
+ }
1322
+ }
1323
+ }
1324
+
1325
+ return nextData;
1326
+ }
1327
+
1328
+ // get index of the point from which the cluster originated
1329
+ _getOriginId(clusterId) {
1330
+ return (clusterId - this.points.length) >> 5;
1331
+ }
1332
+
1333
+ // get zoom of the point from which the cluster originated
1334
+ _getOriginZoom(clusterId) {
1335
+ return (clusterId - this.points.length) % 32;
1336
+ }
1337
+
1338
+ _map(data, i, clone) {
1339
+ if (data[i + OFFSET_NUM] > 1) {
1340
+ const props = this.clusterProps[data[i + OFFSET_PROP]];
1341
+ return clone ? Object.assign({}, props) : props;
1342
+ }
1343
+ const original = this.points[data[i + OFFSET_ID]].properties;
1344
+ const result = this.options.map(original);
1345
+ return clone && result === original ? Object.assign({}, result) : result;
1346
+ }
1347
+ }
1348
+
1349
+ function getClusterJSON(data, i, clusterProps) {
1350
+ return {
1351
+ type: 'Feature',
1352
+ id: data[i + OFFSET_ID],
1353
+ properties: getClusterProperties(data, i, clusterProps),
1354
+ geometry: {
1355
+ type: 'Point',
1356
+ coordinates: [xLng(data[i]), yLat(data[i + 1])]
1357
+ }
1358
+ };
1359
+ }
1360
+
1361
+ function getClusterProperties(data, i, clusterProps) {
1362
+ const count = data[i + OFFSET_NUM];
1363
+ const abbrev =
1364
+ count >= 10000 ? `${Math.round(count / 1000) }k` :
1365
+ count >= 1000 ? `${Math.round(count / 100) / 10 }k` : count;
1366
+ const propIndex = data[i + OFFSET_PROP];
1367
+ const properties = propIndex === -1 ? {} : Object.assign({}, clusterProps[propIndex]);
1368
+ return Object.assign(properties, {
1369
+ cluster: true,
1370
+ cluster_id: data[i + OFFSET_ID],
1371
+ point_count: count,
1372
+ point_count_abbreviated: abbrev
1373
+ });
1374
+ }
1375
+
1376
+ // longitude/latitude to spherical mercator in [0..1] range
1377
+ function lngX(lng) {
1378
+ return lng / 360 + 0.5;
1379
+ }
1380
+ function latY(lat) {
1381
+ const sin = Math.sin(lat * Math.PI / 180);
1382
+ const y = (0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI);
1383
+ return y < 0 ? 0 : y > 1 ? 1 : y;
1384
+ }
1385
+
1386
+ // spherical mercator to longitude/latitude
1387
+ function xLng(x) {
1388
+ return (x - 0.5) * 360;
1389
+ }
1390
+ function yLat(y) {
1391
+ const y2 = (180 - y * 360) * Math.PI / 180;
1392
+ return 360 * Math.atan(Math.exp(y2)) / Math.PI - 90;
1393
+ }
1394
+
1395
+ /******************************************************************************
1396
+ Copyright (c) Microsoft Corporation.
1397
+
1398
+ Permission to use, copy, modify, and/or distribute this software for any
1399
+ purpose with or without fee is hereby granted.
1400
+
1401
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1402
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1403
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1404
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1405
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1406
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1407
+ PERFORMANCE OF THIS SOFTWARE.
1408
+ ***************************************************************************** */
1409
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
1410
+
1411
+
1412
+ function __rest(s, e) {
1413
+ var t = {};
1414
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
1415
+ t[p] = s[p];
1416
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
1417
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
1418
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
1419
+ t[p[i]] = s[p[i]];
1420
+ }
1421
+ return t;
1422
+ }
1423
+
1424
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1425
+ var e = new Error(message);
1426
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1427
+ };
1428
+
1429
+ /**
1430
+ * Copyright 2023 Google LLC
1431
+ *
1432
+ * Licensed under the Apache License, Version 2.0 (the "License");
1433
+ * you may not use this file except in compliance with the License.
1434
+ * You may obtain a copy of the License at
1435
+ *
1436
+ * http://www.apache.org/licenses/LICENSE-2.0
1437
+ *
1438
+ * Unless required by applicable law or agreed to in writing, software
1439
+ * distributed under the License is distributed on an "AS IS" BASIS,
1440
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1441
+ * See the License for the specific language governing permissions and
1442
+ * limitations under the License.
1443
+ */
1444
+ /**
1445
+ * util class that creates a common set of convenience functions to wrap
1446
+ * shared behavior of Advanced Markers and Markers.
1447
+ */
1448
+ class MarkerUtils {
1449
+ static isAdvancedMarkerAvailable(map) {
1450
+ return (google.maps.marker &&
1451
+ map.getMapCapabilities().isAdvancedMarkersAvailable === true);
1452
+ }
1453
+ static isAdvancedMarker(marker) {
1454
+ return (google.maps.marker &&
1455
+ marker instanceof google.maps.marker.AdvancedMarkerElement);
1456
+ }
1457
+ static setMap(marker, map) {
1458
+ if (this.isAdvancedMarker(marker)) {
1459
+ marker.map = map;
1460
+ }
1461
+ else {
1462
+ marker.setMap(map);
1463
+ }
1464
+ }
1465
+ static getPosition(marker) {
1466
+ // SuperClusterAlgorithm.calculate expects a LatLng instance so we fake it for Adv Markers
1467
+ if (this.isAdvancedMarker(marker)) {
1468
+ if (marker.position) {
1469
+ if (marker.position instanceof google.maps.LatLng) {
1470
+ return marker.position;
1471
+ }
1472
+ // since we can't cast to LatLngLiteral for reasons =(
1473
+ if (Number.isFinite(marker.position.lat) &&
1474
+ Number.isFinite(marker.position.lng)) {
1475
+ return new google.maps.LatLng(marker.position.lat, marker.position.lng);
1476
+ }
1477
+ }
1478
+ // @ts-ignore
1479
+ return new google.maps.LatLng(null);
1480
+ }
1481
+ return marker.getPosition();
1482
+ }
1483
+ static getVisible(marker) {
1484
+ if (this.isAdvancedMarker(marker)) {
1485
+ /**
1486
+ * Always return true for Advanced Markers because the clusterer
1487
+ * uses getVisible as a way to count legacy markers not as an actual
1488
+ * indicator of visibility for some reason. Even when markers are hidden
1489
+ * Marker.getVisible returns `true` and this is used to set the marker count
1490
+ * on the cluster. See the behavior of Cluster.count
1491
+ */
1492
+ return true;
1493
+ }
1494
+ return marker.getVisible();
1495
+ }
1496
+ }
1497
+
1498
+ /**
1499
+ * Copyright 2021 Google LLC
1500
+ *
1501
+ * Licensed under the Apache License, Version 2.0 (the "License");
1502
+ * you may not use this file except in compliance with the License.
1503
+ * You may obtain a copy of the License at
1504
+ *
1505
+ * http://www.apache.org/licenses/LICENSE-2.0
1506
+ *
1507
+ * Unless required by applicable law or agreed to in writing, software
1508
+ * distributed under the License is distributed on an "AS IS" BASIS,
1509
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1510
+ * See the License for the specific language governing permissions and
1511
+ * limitations under the License.
1512
+ */
1513
+ class Cluster {
1514
+ constructor({ markers, position }) {
1515
+ this.markers = [];
1516
+ if (markers)
1517
+ this.markers = markers;
1518
+ if (position) {
1519
+ if (position instanceof google.maps.LatLng) {
1520
+ this._position = position;
1521
+ }
1522
+ else {
1523
+ this._position = new google.maps.LatLng(position);
1524
+ }
1525
+ }
1526
+ }
1527
+ get bounds() {
1528
+ if (this.markers.length === 0 && !this._position) {
1529
+ return;
1530
+ }
1531
+ const bounds = new google.maps.LatLngBounds(this._position, this._position);
1532
+ for (const marker of this.markers) {
1533
+ bounds.extend(MarkerUtils.getPosition(marker));
1534
+ }
1535
+ return bounds;
1536
+ }
1537
+ get position() {
1538
+ // @ts-ignore
1539
+ return this._position || this.bounds.getCenter();
1540
+ }
1541
+ /**
1542
+ * Get the count of **visible** markers.
1543
+ */
1544
+ get count() {
1545
+ return this.markers.filter((m) => MarkerUtils.getVisible(m)).length;
1546
+ }
1547
+ /**
1548
+ * Add a marker to the cluster.
1549
+ */
1550
+ push(marker) {
1551
+ this.markers.push(marker);
1552
+ }
1553
+ /**
1554
+ * Cleanup references and remove marker from map.
1555
+ */
1556
+ delete() {
1557
+ if (this.marker) {
1558
+ MarkerUtils.setMap(this.marker, null);
1559
+ this.marker = undefined;
1560
+ }
1561
+ this.markers.length = 0;
1562
+ }
1563
+ }
1564
+
1565
+ /**
1566
+ * Copyright 2021 Google LLC
1567
+ *
1568
+ * Licensed under the Apache License, Version 2.0 (the "License");
1569
+ * you may not use this file except in compliance with the License.
1570
+ * You may obtain a copy of the License at
1571
+ *
1572
+ * http://www.apache.org/licenses/LICENSE-2.0
1573
+ *
1574
+ * Unless required by applicable law or agreed to in writing, software
1575
+ * distributed under the License is distributed on an "AS IS" BASIS,
1576
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1577
+ * See the License for the specific language governing permissions and
1578
+ * limitations under the License.
1579
+ */
1580
+ /**
1581
+ * A typescript assertion function used in cases where typescript has to be
1582
+ * convinced that the object in question can not be null.
1583
+ *
1584
+ * @param value
1585
+ * @param message
1586
+ */
1587
+ function assertNotNull(value, message = "assertion failed") {
1588
+ if (value === null || value === undefined) {
1589
+ throw Error(message);
1590
+ }
1591
+ }
1592
+
1593
+ /**
1594
+ * Copyright 2021 Google LLC
1595
+ *
1596
+ * Licensed under the Apache License, Version 2.0 (the "License");
1597
+ * you may not use this file except in compliance with the License.
1598
+ * You may obtain a copy of the License at
1599
+ *
1600
+ * http://www.apache.org/licenses/LICENSE-2.0
1601
+ *
1602
+ * Unless required by applicable law or agreed to in writing, software
1603
+ * distributed under the License is distributed on an "AS IS" BASIS,
1604
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1605
+ * See the License for the specific language governing permissions and
1606
+ * limitations under the License.
1607
+ */
1608
+ /**
1609
+ * Returns the markers visible in a padded map viewport
1610
+ *
1611
+ * @param map
1612
+ * @param mapCanvasProjection
1613
+ * @param markers The list of marker to filter
1614
+ * @param viewportPaddingPixels The padding in pixel
1615
+ * @returns The list of markers in the padded viewport
1616
+ */
1617
+ const filterMarkersToPaddedViewport = (map, mapCanvasProjection, markers, viewportPaddingPixels) => {
1618
+ const bounds = map.getBounds();
1619
+ assertNotNull(bounds);
1620
+ const extendedMapBounds = extendBoundsToPaddedViewport(bounds, mapCanvasProjection, viewportPaddingPixels);
1621
+ return markers.filter((marker) => extendedMapBounds.contains(MarkerUtils.getPosition(marker)));
1622
+ };
1623
+ /**
1624
+ * Extends bounds by a number of pixels in each direction
1625
+ */
1626
+ const extendBoundsToPaddedViewport = (bounds, projection, numPixels) => {
1627
+ const { northEast, southWest } = latLngBoundsToPixelBounds(bounds, projection);
1628
+ const extendedPixelBounds = extendPixelBounds({ northEast, southWest }, numPixels);
1629
+ return pixelBoundsToLatLngBounds(extendedPixelBounds, projection);
1630
+ };
1631
+ /**
1632
+ * Gets the extended bounds as a bbox [westLng, southLat, eastLng, northLat]
1633
+ */
1634
+ const getPaddedViewport = (bounds, projection, pixels) => {
1635
+ const extended = extendBoundsToPaddedViewport(bounds, projection, pixels);
1636
+ const ne = extended.getNorthEast();
1637
+ const sw = extended.getSouthWest();
1638
+ return [sw.lng(), sw.lat(), ne.lng(), ne.lat()];
1639
+ };
1640
+ /**
1641
+ * Returns the distance between 2 positions.
1642
+ *
1643
+ * @hidden
1644
+ */
1645
+ const distanceBetweenPoints = (p1, p2) => {
1646
+ const R = 6371; // Radius of the Earth in km
1647
+ const dLat = ((p2.lat - p1.lat) * Math.PI) / 180;
1648
+ const dLon = ((p2.lng - p1.lng) * Math.PI) / 180;
1649
+ const sinDLat = Math.sin(dLat / 2);
1650
+ const sinDLon = Math.sin(dLon / 2);
1651
+ const a = sinDLat * sinDLat +
1652
+ Math.cos((p1.lat * Math.PI) / 180) *
1653
+ Math.cos((p2.lat * Math.PI) / 180) *
1654
+ sinDLon *
1655
+ sinDLon;
1656
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
1657
+ return R * c;
1658
+ };
1659
+ /**
1660
+ * Converts a LatLng bound to pixels.
1661
+ *
1662
+ * @hidden
1663
+ */
1664
+ const latLngBoundsToPixelBounds = (bounds, projection) => {
1665
+ const northEast = projection.fromLatLngToDivPixel(bounds.getNorthEast());
1666
+ const southWest = projection.fromLatLngToDivPixel(bounds.getSouthWest());
1667
+ assertNotNull(northEast);
1668
+ assertNotNull(southWest);
1669
+ return { northEast, southWest };
1670
+ };
1671
+ /**
1672
+ * Extends a pixel bounds by numPixels in all directions.
1673
+ *
1674
+ * @hidden
1675
+ */
1676
+ const extendPixelBounds = ({ northEast, southWest }, numPixels) => {
1677
+ northEast.x += numPixels;
1678
+ northEast.y -= numPixels;
1679
+ southWest.x -= numPixels;
1680
+ southWest.y += numPixels;
1681
+ return { northEast, southWest };
1682
+ };
1683
+ /**
1684
+ * @hidden
1685
+ */
1686
+ const pixelBoundsToLatLngBounds = ({ northEast, southWest }, projection) => {
1687
+ const sw = projection.fromDivPixelToLatLng(southWest);
1688
+ const ne = projection.fromDivPixelToLatLng(northEast);
1689
+ return new google.maps.LatLngBounds(sw, ne);
1690
+ };
1691
+
1692
+ /**
1693
+ * Copyright 2021 Google LLC
1694
+ *
1695
+ * Licensed under the Apache License, Version 2.0 (the "License");
1696
+ * you may not use this file except in compliance with the License.
1697
+ * You may obtain a copy of the License at
1698
+ *
1699
+ * http://www.apache.org/licenses/LICENSE-2.0
1700
+ *
1701
+ * Unless required by applicable law or agreed to in writing, software
1702
+ * distributed under the License is distributed on an "AS IS" BASIS,
1703
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1704
+ * See the License for the specific language governing permissions and
1705
+ * limitations under the License.
1706
+ */
1707
+ /**
1708
+ * @hidden
1709
+ */
1710
+ class AbstractAlgorithm {
1711
+ constructor({ maxZoom = 16 }) {
1712
+ this.maxZoom = maxZoom;
1713
+ }
1714
+ /**
1715
+ * Helper function to bypass clustering based upon some map state such as
1716
+ * zoom, number of markers, etc.
1717
+ *
1718
+ * ```typescript
1719
+ * cluster({markers, map}: AlgorithmInput): Cluster[] {
1720
+ * if (shouldBypassClustering(map)) {
1721
+ * return this.noop({markers})
1722
+ * }
1723
+ * }
1724
+ * ```
1725
+ */
1726
+ noop({ markers, }) {
1727
+ return noop(markers);
1728
+ }
1729
+ }
1730
+ /**
1731
+ * Abstract viewport algorithm proves a class to filter markers by a padded
1732
+ * viewport. This is a common optimization.
1733
+ *
1734
+ * @hidden
1735
+ */
1736
+ class AbstractViewportAlgorithm extends AbstractAlgorithm {
1737
+ constructor(_a) {
1738
+ var { viewportPadding = 60 } = _a, options = __rest(_a, ["viewportPadding"]);
1739
+ super(options);
1740
+ this.viewportPadding = 60;
1741
+ this.viewportPadding = viewportPadding;
1742
+ }
1743
+ calculate({ markers, map, mapCanvasProjection, }) {
1744
+ const zoom = map.getZoom();
1745
+ assertNotNull(zoom);
1746
+ if (zoom >= this.maxZoom) {
1747
+ return {
1748
+ clusters: this.noop({
1749
+ markers,
1750
+ }),
1751
+ changed: false,
1752
+ };
1753
+ }
1754
+ return {
1755
+ clusters: this.cluster({
1756
+ markers: filterMarkersToPaddedViewport(map, mapCanvasProjection, markers, this.viewportPadding),
1757
+ map,
1758
+ mapCanvasProjection,
1759
+ }),
1760
+ };
1761
+ }
1762
+ }
1763
+ /**
1764
+ * @hidden
1765
+ */
1766
+ const noop = (markers) => {
1767
+ const clusters = markers.map((marker) => new Cluster({
1768
+ position: MarkerUtils.getPosition(marker),
1769
+ markers: [marker],
1770
+ }));
1771
+ return clusters;
1772
+ };
1773
+
1774
+ /**
1775
+ * Copyright 2021 Google LLC
1776
+ *
1777
+ * Licensed under the Apache License, Version 2.0 (the "License");
1778
+ * you may not use this file except in compliance with the License.
1779
+ * You may obtain a copy of the License at
1780
+ *
1781
+ * http://www.apache.org/licenses/LICENSE-2.0
1782
+ *
1783
+ * Unless required by applicable law or agreed to in writing, software
1784
+ * distributed under the License is distributed on an "AS IS" BASIS,
1785
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1786
+ * See the License for the specific language governing permissions and
1787
+ * limitations under the License.
1788
+ */
1789
+ /**
1790
+ * The default Grid algorithm historically used in Google Maps marker
1791
+ * clustering.
1792
+ *
1793
+ * The Grid algorithm does not implement caching and markers may flash as the
1794
+ * viewport changes. Instead use {@link SuperClusterAlgorithm}.
1795
+ */
1796
+ class GridAlgorithm extends AbstractViewportAlgorithm {
1797
+ constructor(_a) {
1798
+ var { maxDistance = 40000, gridSize = 40 } = _a, options = __rest(_a, ["maxDistance", "gridSize"]);
1799
+ super(options);
1800
+ this.clusters = [];
1801
+ this.state = { zoom: -1 };
1802
+ this.maxDistance = maxDistance;
1803
+ this.gridSize = gridSize;
1804
+ }
1805
+ calculate({ markers, map, mapCanvasProjection, }) {
1806
+ const zoom = map.getZoom();
1807
+ assertNotNull(zoom);
1808
+ const newState = { zoom };
1809
+ let changed = false;
1810
+ if (this.state.zoom >= this.maxZoom && newState.zoom >= this.maxZoom) ;
1811
+ else {
1812
+ changed = !deepEqual(this.state, newState);
1813
+ }
1814
+ this.state = newState;
1815
+ if (zoom >= this.maxZoom) {
1816
+ return {
1817
+ clusters: this.noop({ markers }),
1818
+ changed,
1819
+ };
1820
+ }
1821
+ return {
1822
+ clusters: this.cluster({
1823
+ markers: filterMarkersToPaddedViewport(map, mapCanvasProjection, markers, this.viewportPadding),
1824
+ map,
1825
+ mapCanvasProjection,
1826
+ }),
1827
+ };
1828
+ }
1829
+ cluster({ markers, map, mapCanvasProjection, }) {
1830
+ this.clusters = [];
1831
+ markers.forEach((marker) => {
1832
+ this.addToClosestCluster(marker, map, mapCanvasProjection);
1833
+ });
1834
+ return this.clusters;
1835
+ }
1836
+ addToClosestCluster(marker, map, projection) {
1837
+ let maxDistance = this.maxDistance; // Some large number
1838
+ let cluster = null;
1839
+ for (let i = 0; i < this.clusters.length; i++) {
1840
+ const candidate = this.clusters[i];
1841
+ assertNotNull(candidate.bounds);
1842
+ const distance = distanceBetweenPoints(candidate.bounds.getCenter().toJSON(), MarkerUtils.getPosition(marker).toJSON());
1843
+ if (distance < maxDistance) {
1844
+ maxDistance = distance;
1845
+ cluster = candidate;
1846
+ }
1847
+ }
1848
+ if (cluster) {
1849
+ assertNotNull(cluster.bounds);
1850
+ if (extendBoundsToPaddedViewport(cluster.bounds, projection, this.gridSize).contains(MarkerUtils.getPosition(marker))) {
1851
+ cluster.push(marker);
1852
+ }
1853
+ else {
1854
+ const cluster = new Cluster({ markers: [marker] });
1855
+ this.clusters.push(cluster);
1856
+ }
1857
+ }
1858
+ else {
1859
+ const cluster = new Cluster({ markers: [marker] });
1860
+ this.clusters.push(cluster);
1861
+ }
1862
+ }
1863
+ }
1864
+
1865
+ /**
1866
+ * Copyright 2021 Google LLC
1867
+ *
1868
+ * Licensed under the Apache License, Version 2.0 (the "License");
1869
+ * you may not use this file except in compliance with the License.
1870
+ * You may obtain a copy of the License at
1871
+ *
1872
+ * http://www.apache.org/licenses/LICENSE-2.0
1873
+ *
1874
+ * Unless required by applicable law or agreed to in writing, software
1875
+ * distributed under the License is distributed on an "AS IS" BASIS,
1876
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1877
+ * See the License for the specific language governing permissions and
1878
+ * limitations under the License.
1879
+ */
1880
+ /**
1881
+ * Noop algorithm does not generate any clusters or filter markers by the an extended viewport.
1882
+ */
1883
+ class NoopAlgorithm extends AbstractAlgorithm {
1884
+ constructor(_a) {
1885
+ var options = __rest(_a, []);
1886
+ super(options);
1887
+ }
1888
+ calculate({ markers, map, mapCanvasProjection, }) {
1889
+ return {
1890
+ clusters: this.cluster({ markers, map, mapCanvasProjection }),
1891
+ changed: false,
1892
+ };
1893
+ }
1894
+ cluster(input) {
1895
+ return this.noop(input);
1896
+ }
1897
+ }
1898
+
1899
+ /**
1900
+ * Copyright 2021 Google LLC
1901
+ *
1902
+ * Licensed under the Apache License, Version 2.0 (the "License");
1903
+ * you may not use this file except in compliance with the License.
1904
+ * You may obtain a copy of the License at
1905
+ *
1906
+ * http://www.apache.org/licenses/LICENSE-2.0
1907
+ *
1908
+ * Unless required by applicable law or agreed to in writing, software
1909
+ * distributed under the License is distributed on an "AS IS" BASIS,
1910
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1911
+ * See the License for the specific language governing permissions and
1912
+ * limitations under the License.
1913
+ */
1914
+ /**
1915
+ * A very fast JavaScript algorithm for geospatial point clustering using KD trees.
1916
+ *
1917
+ * @see https://www.npmjs.com/package/supercluster for more information on options.
1918
+ */
1919
+ class SuperClusterAlgorithm extends AbstractAlgorithm {
1920
+ constructor(_a) {
1921
+ var { maxZoom, radius = 60 } = _a, options = __rest(_a, ["maxZoom", "radius"]);
1922
+ super({ maxZoom });
1923
+ this.markers = [];
1924
+ this.clusters = [];
1925
+ this.state = { zoom: -1 };
1926
+ this.superCluster = new Supercluster(Object.assign({ maxZoom: this.maxZoom, radius }, options));
1927
+ }
1928
+ calculate(input) {
1929
+ let changed = false;
1930
+ let zoom = input.map.getZoom();
1931
+ assertNotNull(zoom);
1932
+ zoom = Math.round(zoom);
1933
+ const state = { zoom: zoom };
1934
+ if (!deepEqual(input.markers, this.markers)) {
1935
+ changed = true;
1936
+ // TODO use proxy to avoid copy?
1937
+ this.markers = [...input.markers];
1938
+ const points = this.markers.map((marker) => {
1939
+ const position = MarkerUtils.getPosition(marker);
1940
+ const coordinates = [position.lng(), position.lat()];
1941
+ return {
1942
+ type: "Feature",
1943
+ geometry: { type: "Point", coordinates },
1944
+ properties: { marker },
1945
+ };
1946
+ });
1947
+ this.superCluster.load(points);
1948
+ }
1949
+ if (!changed) {
1950
+ if (this.state.zoom <= this.maxZoom || state.zoom <= this.maxZoom) {
1951
+ changed = !deepEqual(this.state, state);
1952
+ }
1953
+ }
1954
+ this.state = state;
1955
+ // when input is empty, return right away
1956
+ if (input.markers.length === 0) {
1957
+ this.clusters = [];
1958
+ return { clusters: this.clusters, changed };
1959
+ }
1960
+ if (changed) {
1961
+ this.clusters = this.cluster(input);
1962
+ }
1963
+ return { clusters: this.clusters, changed };
1964
+ }
1965
+ cluster({ map }) {
1966
+ const zoom = map.getZoom();
1967
+ assertNotNull(zoom);
1968
+ return this.superCluster
1969
+ .getClusters([-180, -90, 180, 90], Math.round(zoom))
1970
+ .map((feature) => this.transformCluster(feature));
1971
+ }
1972
+ transformCluster({ geometry: { coordinates: [lng, lat], }, properties, }) {
1973
+ if (properties.cluster) {
1974
+ return new Cluster({
1975
+ markers: this.superCluster
1976
+ .getLeaves(properties.cluster_id, Infinity)
1977
+ .map((leaf) => leaf.properties.marker),
1978
+ position: { lat, lng },
1979
+ });
1980
+ }
1981
+ const marker = properties.marker;
1982
+ return new Cluster({
1983
+ markers: [marker],
1984
+ position: MarkerUtils.getPosition(marker),
1985
+ });
1986
+ }
1987
+ }
1988
+
1989
+ /**
1990
+ * Copyright 2021 Google LLC
1991
+ *
1992
+ * Licensed under the Apache License, Version 2.0 (the "License");
1993
+ * you may not use this file except in compliance with the License.
1994
+ * You may obtain a copy of the License at
1995
+ *
1996
+ * http://www.apache.org/licenses/LICENSE-2.0
1997
+ *
1998
+ * Unless required by applicable law or agreed to in writing, software
1999
+ * distributed under the License is distributed on an "AS IS" BASIS,
2000
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2001
+ * See the License for the specific language governing permissions and
2002
+ * limitations under the License.
2003
+ */
2004
+ /**
2005
+ * A very fast JavaScript algorithm for geospatial point clustering using KD trees.
2006
+ *
2007
+ * @see https://www.npmjs.com/package/supercluster for more information on options.
2008
+ */
2009
+ class SuperClusterViewportAlgorithm extends AbstractViewportAlgorithm {
2010
+ constructor(_a) {
2011
+ var { maxZoom, radius = 60, viewportPadding = 60 } = _a, options = __rest(_a, ["maxZoom", "radius", "viewportPadding"]);
2012
+ super({ maxZoom, viewportPadding });
2013
+ this.markers = [];
2014
+ this.clusters = [];
2015
+ this.superCluster = new Supercluster(Object.assign({ maxZoom: this.maxZoom, radius }, options));
2016
+ this.state = { zoom: -1, view: [0, 0, 0, 0] };
2017
+ }
2018
+ calculate(input) {
2019
+ const state = this.getViewportState(input);
2020
+ let changed = !deepEqual(this.state, state);
2021
+ if (!deepEqual(input.markers, this.markers)) {
2022
+ changed = true;
2023
+ // TODO use proxy to avoid copy?
2024
+ this.markers = [...input.markers];
2025
+ const points = this.markers.map((marker) => {
2026
+ const position = MarkerUtils.getPosition(marker);
2027
+ const coordinates = [position.lng(), position.lat()];
2028
+ return {
2029
+ type: "Feature",
2030
+ geometry: {
2031
+ type: "Point",
2032
+ coordinates,
2033
+ },
2034
+ properties: { marker },
2035
+ };
2036
+ });
2037
+ this.superCluster.load(points);
2038
+ }
2039
+ if (changed) {
2040
+ this.clusters = this.cluster(input);
2041
+ this.state = state;
2042
+ }
2043
+ return { clusters: this.clusters, changed };
2044
+ }
2045
+ cluster(input) {
2046
+ /* recalculate new state because we can't use the cached version. */
2047
+ const state = this.getViewportState(input);
2048
+ return this.superCluster
2049
+ .getClusters(state.view, state.zoom)
2050
+ .map((feature) => this.transformCluster(feature));
2051
+ }
2052
+ transformCluster({ geometry: { coordinates: [lng, lat], }, properties, }) {
2053
+ if (properties.cluster) {
2054
+ return new Cluster({
2055
+ markers: this.superCluster
2056
+ .getLeaves(properties.cluster_id, Infinity)
2057
+ .map((leaf) => leaf.properties.marker),
2058
+ position: { lat, lng },
2059
+ });
2060
+ }
2061
+ const marker = properties.marker;
2062
+ return new Cluster({
2063
+ markers: [marker],
2064
+ position: MarkerUtils.getPosition(marker),
2065
+ });
2066
+ }
2067
+ getViewportState(input) {
2068
+ const mapZoom = input.map.getZoom();
2069
+ const mapBounds = input.map.getBounds();
2070
+ assertNotNull(mapZoom);
2071
+ assertNotNull(mapBounds);
2072
+ return {
2073
+ zoom: Math.round(mapZoom),
2074
+ view: getPaddedViewport(mapBounds, input.mapCanvasProjection, this.viewportPadding),
2075
+ };
2076
+ }
2077
+ }
2078
+
2079
+ /**
2080
+ * Copyright 2021 Google LLC
2081
+ *
2082
+ * Licensed under the Apache License, Version 2.0 (the "License");
2083
+ * you may not use this file except in compliance with the License.
2084
+ * You may obtain a copy of the License at
2085
+ *
2086
+ * http://www.apache.org/licenses/LICENSE-2.0
2087
+ *
2088
+ * Unless required by applicable law or agreed to in writing, software
2089
+ * distributed under the License is distributed on an "AS IS" BASIS,
2090
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2091
+ * See the License for the specific language governing permissions and
2092
+ * limitations under the License.
2093
+ */
2094
+ /**
2095
+ * Provides statistics on all clusters in the current render cycle for use in {@link Renderer.render}.
2096
+ */
2097
+ class ClusterStats {
2098
+ constructor(markers, clusters) {
2099
+ this.markers = { sum: markers.length };
2100
+ const clusterMarkerCounts = clusters.map((a) => a.count);
2101
+ const clusterMarkerSum = clusterMarkerCounts.reduce((a, b) => a + b, 0);
2102
+ this.clusters = {
2103
+ count: clusters.length,
2104
+ markers: {
2105
+ mean: clusterMarkerSum / clusters.length,
2106
+ sum: clusterMarkerSum,
2107
+ min: Math.min(...clusterMarkerCounts),
2108
+ max: Math.max(...clusterMarkerCounts),
2109
+ },
2110
+ };
2111
+ }
2112
+ }
2113
+ class DefaultRenderer {
2114
+ /**
2115
+ * The default render function for the library used by {@link MarkerClusterer}.
2116
+ *
2117
+ * Currently set to use the following:
2118
+ *
2119
+ * ```typescript
2120
+ * // change color if this cluster has more markers than the mean cluster
2121
+ * const color =
2122
+ * count > Math.max(10, stats.clusters.markers.mean)
2123
+ * ? "#ff0000"
2124
+ * : "#0000ff";
2125
+ *
2126
+ * // create svg url with fill color
2127
+ * const svg = window.btoa(`
2128
+ * <svg fill="${color}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240">
2129
+ * <circle cx="120" cy="120" opacity=".6" r="70" />
2130
+ * <circle cx="120" cy="120" opacity=".3" r="90" />
2131
+ * <circle cx="120" cy="120" opacity=".2" r="110" />
2132
+ * <circle cx="120" cy="120" opacity=".1" r="130" />
2133
+ * </svg>`);
2134
+ *
2135
+ * // create marker using svg icon
2136
+ * return new google.maps.Marker({
2137
+ * position,
2138
+ * icon: {
2139
+ * url: `data:image/svg+xml;base64,${svg}`,
2140
+ * scaledSize: new google.maps.Size(45, 45),
2141
+ * },
2142
+ * label: {
2143
+ * text: String(count),
2144
+ * color: "rgba(255,255,255,0.9)",
2145
+ * fontSize: "12px",
2146
+ * },
2147
+ * // adjust zIndex to be above other markers
2148
+ * zIndex: 1000 + count,
2149
+ * });
2150
+ * ```
2151
+ */
2152
+ render({ count, position }, stats, map) {
2153
+ // change color if this cluster has more markers than the mean cluster
2154
+ const color = count > Math.max(10, stats.clusters.markers.mean) ? "#ff0000" : "#0000ff";
2155
+ // create svg literal with fill color
2156
+ const svg = `<svg fill="${color}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240" width="50" height="50">
2157
+ <circle cx="120" cy="120" opacity=".6" r="70" />
2158
+ <circle cx="120" cy="120" opacity=".3" r="90" />
2159
+ <circle cx="120" cy="120" opacity=".2" r="110" />
2160
+ <text x="50%" y="50%" style="fill:#fff" text-anchor="middle" font-size="50" dominant-baseline="middle" font-family="roboto,arial,sans-serif">${count}</text>
2161
+ </svg>`;
2162
+ const title = `Cluster of ${count} markers`,
2163
+ // adjust zIndex to be above other markers
2164
+ zIndex = Number(google.maps.Marker.MAX_ZINDEX) + count;
2165
+ if (MarkerUtils.isAdvancedMarkerAvailable(map)) {
2166
+ // create cluster SVG element
2167
+ const parser = new DOMParser();
2168
+ const svgEl = parser.parseFromString(svg, "image/svg+xml").documentElement;
2169
+ svgEl.setAttribute("transform", "translate(0 25)");
2170
+ const clusterOptions = {
2171
+ map,
2172
+ position,
2173
+ zIndex,
2174
+ title,
2175
+ content: svgEl,
2176
+ };
2177
+ return new google.maps.marker.AdvancedMarkerElement(clusterOptions);
2178
+ }
2179
+ const clusterOptions = {
2180
+ position,
2181
+ zIndex,
2182
+ title,
2183
+ icon: {
2184
+ url: `data:image/svg+xml;base64,${btoa(svg)}`,
2185
+ anchor: new google.maps.Point(25, 25),
2186
+ },
2187
+ };
2188
+ return new google.maps.Marker(clusterOptions);
2189
+ }
2190
+ }
2191
+
2192
+ /**
2193
+ * Copyright 2019 Google LLC. All Rights Reserved.
2194
+ *
2195
+ * Licensed under the Apache License, Version 2.0 (the "License");
2196
+ * you may not use this file except in compliance with the License.
2197
+ * You may obtain a copy of the License at
2198
+ *
2199
+ * http://www.apache.org/licenses/LICENSE-2.0
2200
+ *
2201
+ * Unless required by applicable law or agreed to in writing, software
2202
+ * distributed under the License is distributed on an "AS IS" BASIS,
2203
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2204
+ * See the License for the specific language governing permissions and
2205
+ * limitations under the License.
2206
+ */
2207
+ /**
2208
+ * Extends an object's prototype by another's.
2209
+ *
2210
+ * @param type1 The Type to be extended.
2211
+ * @param type2 The Type to extend with.
2212
+ * @ignore
2213
+ */
2214
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2215
+ function extend(type1, type2) {
2216
+ /* istanbul ignore next */
2217
+ // eslint-disable-next-line prefer-const
2218
+ for (let property in type2.prototype) {
2219
+ type1.prototype[property] = type2.prototype[property];
2220
+ }
2221
+ }
2222
+ /**
2223
+ * @ignore
2224
+ */
2225
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
2226
+ class OverlayViewSafe {
2227
+ constructor() {
2228
+ // MarkerClusterer implements google.maps.OverlayView interface. We use the
2229
+ // extend function to extend MarkerClusterer with google.maps.OverlayView
2230
+ // because it might not always be available when the code is defined so we
2231
+ // look for it at the last possible moment. If it doesn't exist now then
2232
+ // there is no point going ahead :)
2233
+ extend(OverlayViewSafe, google.maps.OverlayView);
2234
+ }
2235
+ }
2236
+
2237
+ /**
2238
+ * Copyright 2021 Google LLC
2239
+ *
2240
+ * Licensed under the Apache License, Version 2.0 (the "License");
2241
+ * you may not use this file except in compliance with the License.
2242
+ * You may obtain a copy of the License at
2243
+ *
2244
+ * http://www.apache.org/licenses/LICENSE-2.0
2245
+ *
2246
+ * Unless required by applicable law or agreed to in writing, software
2247
+ * distributed under the License is distributed on an "AS IS" BASIS,
2248
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2249
+ * See the License for the specific language governing permissions and
2250
+ * limitations under the License.
2251
+ */
2252
+ exports.MarkerClustererEvents = void 0;
2253
+ (function (MarkerClustererEvents) {
2254
+ MarkerClustererEvents["CLUSTERING_BEGIN"] = "clusteringbegin";
2255
+ MarkerClustererEvents["CLUSTERING_END"] = "clusteringend";
2256
+ MarkerClustererEvents["CLUSTER_CLICK"] = "click";
2257
+ MarkerClustererEvents["GMP_CLICK"] = "gmp-click";
2258
+ })(exports.MarkerClustererEvents || (exports.MarkerClustererEvents = {}));
2259
+ const defaultOnClusterClickHandler = (_, cluster, map) => {
2260
+ if (cluster.bounds)
2261
+ map.fitBounds(cluster.bounds);
2262
+ };
2263
+ /**
2264
+ * MarkerClusterer creates and manages per-zoom-level clusters for large amounts
2265
+ * of markers. See {@link MarkerClustererOptions} for more details.
2266
+ *
2267
+ */
2268
+ class MarkerClusterer extends OverlayViewSafe {
2269
+ constructor({ map, markers = [], algorithmOptions = {}, algorithm = new SuperClusterAlgorithm(algorithmOptions), renderer = new DefaultRenderer(), onClusterClick = defaultOnClusterClickHandler, }) {
2270
+ super();
2271
+ /** @see {@link MarkerClustererOptions.map} */
2272
+ this.map = null;
2273
+ this.idleListener = null;
2274
+ this.markers = [...markers];
2275
+ this.clusters = [];
2276
+ this.algorithm = algorithm;
2277
+ this.renderer = renderer;
2278
+ this.onClusterClick = onClusterClick;
2279
+ if (map) {
2280
+ this.setMap(map);
2281
+ }
2282
+ }
2283
+ addMarker(marker, noDraw) {
2284
+ if (this.markers.includes(marker)) {
2285
+ return;
2286
+ }
2287
+ this.markers.push(marker);
2288
+ if (!noDraw) {
2289
+ this.render();
2290
+ }
2291
+ }
2292
+ addMarkers(markers, noDraw) {
2293
+ markers.forEach((marker) => {
2294
+ this.addMarker(marker, true);
2295
+ });
2296
+ if (!noDraw) {
2297
+ this.render();
2298
+ }
2299
+ }
2300
+ removeMarker(marker, noDraw) {
2301
+ const index = this.markers.indexOf(marker);
2302
+ if (index === -1) {
2303
+ // Marker is not in our list of markers, so do nothing:
2304
+ return false;
2305
+ }
2306
+ MarkerUtils.setMap(marker, null);
2307
+ this.markers.splice(index, 1); // Remove the marker from the list of managed markers
2308
+ if (!noDraw) {
2309
+ this.render();
2310
+ }
2311
+ return true;
2312
+ }
2313
+ removeMarkers(markers, noDraw) {
2314
+ let removed = false;
2315
+ markers.forEach((marker) => {
2316
+ removed = this.removeMarker(marker, true) || removed;
2317
+ });
2318
+ if (removed && !noDraw) {
2319
+ this.render();
2320
+ }
2321
+ return removed;
2322
+ }
2323
+ clearMarkers(noDraw) {
2324
+ this.markers.length = 0;
2325
+ if (!noDraw) {
2326
+ this.render();
2327
+ }
2328
+ }
2329
+ /**
2330
+ * Recalculates and draws all the marker clusters.
2331
+ */
2332
+ render() {
2333
+ const map = this.getMap();
2334
+ if (map instanceof google.maps.Map && map.getProjection()) {
2335
+ google.maps.event.trigger(this, exports.MarkerClustererEvents.CLUSTERING_BEGIN, this);
2336
+ const { clusters, changed } = this.algorithm.calculate({
2337
+ markers: this.markers,
2338
+ map,
2339
+ mapCanvasProjection: this.getProjection(),
2340
+ });
2341
+ // Allow algorithms to return flag on whether the clusters/markers have changed.
2342
+ if (changed || changed == undefined) {
2343
+ // Accumulate the markers of the clusters composed of a single marker.
2344
+ // Those clusters directly use the marker.
2345
+ // Clusters with more than one markers use a group marker generated by a renderer.
2346
+ const singleMarker = new Set();
2347
+ for (const cluster of clusters) {
2348
+ if (cluster.markers.length == 1) {
2349
+ singleMarker.add(cluster.markers[0]);
2350
+ }
2351
+ }
2352
+ const groupMarkers = [];
2353
+ // Iterate the clusters that are currently rendered.
2354
+ for (const cluster of this.clusters) {
2355
+ if (cluster.marker == null) {
2356
+ continue;
2357
+ }
2358
+ if (cluster.markers.length == 1) {
2359
+ if (!singleMarker.has(cluster.marker)) {
2360
+ // The marker:
2361
+ // - was previously rendered because it is from a cluster with 1 marker,
2362
+ // - should no more be rendered as it is not in singleMarker.
2363
+ MarkerUtils.setMap(cluster.marker, null);
2364
+ }
2365
+ }
2366
+ else {
2367
+ // Delay the removal of old group markers to avoid flickering.
2368
+ groupMarkers.push(cluster.marker);
2369
+ }
2370
+ }
2371
+ this.clusters = clusters;
2372
+ this.renderClusters();
2373
+ // Delayed removal of the markers of the former groups.
2374
+ requestAnimationFrame(() => groupMarkers.forEach((marker) => MarkerUtils.setMap(marker, null)));
2375
+ }
2376
+ google.maps.event.trigger(this, exports.MarkerClustererEvents.CLUSTERING_END, this);
2377
+ }
2378
+ }
2379
+ onAdd() {
2380
+ const map = this.getMap();
2381
+ assertNotNull(map);
2382
+ this.idleListener = map.addListener("idle", this.render.bind(this));
2383
+ this.render();
2384
+ }
2385
+ onRemove() {
2386
+ if (this.idleListener)
2387
+ google.maps.event.removeListener(this.idleListener);
2388
+ this.reset();
2389
+ }
2390
+ reset() {
2391
+ this.markers.forEach((marker) => MarkerUtils.setMap(marker, null));
2392
+ this.clusters.forEach((cluster) => cluster.delete());
2393
+ this.clusters = [];
2394
+ }
2395
+ renderClusters() {
2396
+ // Generate stats to pass to renderers.
2397
+ const stats = new ClusterStats(this.markers, this.clusters);
2398
+ const map = this.getMap();
2399
+ this.clusters.forEach((cluster) => {
2400
+ if (cluster.markers.length === 1) {
2401
+ cluster.marker = cluster.markers[0];
2402
+ }
2403
+ else {
2404
+ // Generate the marker to represent the group.
2405
+ cluster.marker = this.renderer.render(cluster, stats, map);
2406
+ // Make sure all individual markers are removed from the map.
2407
+ cluster.markers.forEach((marker) => MarkerUtils.setMap(marker, null));
2408
+ if (this.onClusterClick) {
2409
+ // legacy Marker uses 'click' events, whereas AdvancedMarkerElement uses 'gmp-click'
2410
+ const markerClickEventName = MarkerUtils.isAdvancedMarker(cluster.marker)
2411
+ ? exports.MarkerClustererEvents.GMP_CLICK
2412
+ : exports.MarkerClustererEvents.CLUSTER_CLICK;
2413
+ cluster.marker.addListener(markerClickEventName,
2414
+ /* istanbul ignore next */
2415
+ (event) => {
2416
+ google.maps.event.trigger(this, exports.MarkerClustererEvents.CLUSTER_CLICK, cluster);
2417
+ this.onClusterClick(event, cluster, map);
2418
+ });
2419
+ }
2420
+ }
2421
+ MarkerUtils.setMap(cluster.marker, map);
2422
+ });
2423
+ }
2424
+ }
2425
+
2426
+ exports.AbstractAlgorithm = AbstractAlgorithm;
2427
+ exports.AbstractViewportAlgorithm = AbstractViewportAlgorithm;
2428
+ exports.Cluster = Cluster;
2429
+ exports.ClusterStats = ClusterStats;
2430
+ exports.DefaultRenderer = DefaultRenderer;
2431
+ exports.GridAlgorithm = GridAlgorithm;
2432
+ exports.MarkerClusterer = MarkerClusterer;
2433
+ exports.MarkerUtils = MarkerUtils;
2434
+ exports.NoopAlgorithm = NoopAlgorithm;
2435
+ exports.SuperClusterAlgorithm = SuperClusterAlgorithm;
2436
+ exports.SuperClusterViewportAlgorithm = SuperClusterViewportAlgorithm;
2437
+ exports.defaultOnClusterClickHandler = defaultOnClusterClickHandler;
2438
+ exports.distanceBetweenPoints = distanceBetweenPoints;
2439
+ exports.extendBoundsToPaddedViewport = extendBoundsToPaddedViewport;
2440
+ exports.extendPixelBounds = extendPixelBounds;
2441
+ exports.filterMarkersToPaddedViewport = filterMarkersToPaddedViewport;
2442
+ exports.getPaddedViewport = getPaddedViewport;
2443
+ exports.noop = noop;
2444
+ exports.pixelBoundsToLatLngBounds = pixelBoundsToLatLngBounds;