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