@zonos/elements 1.3.274 → 1.3.275
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.
- package/dist/cjs/{cart-660e115c.js → cart-73d7ecdc.js} +4 -4
- package/dist/cjs/{cleanHtmlMarkdown-31da84b7.js → cleanHtmlMarkdown-57147de7.js} +180 -356
- package/dist/cjs/{collect-286a9d04.js → collect-32ea7a37.js} +3 -3
- package/dist/cjs/{debounce-7990f5ea.js → debounce-9a712c79.js} +1 -1
- package/dist/cjs/{getBorderRadius-fc683d94.js → getBorderRadius-4da24d7c.js} +1 -1
- package/dist/cjs/{getContrastColor-d5134ef3.js → getContrastColor-2fb235b8.js} +2 -2
- package/dist/cjs/{hasInclusivePrice-b35e81aa.js → hasInclusivePrice-38ebedfb.js} +1 -1
- package/dist/cjs/index.cjs.js +7 -7
- package/dist/cjs/{invoice-f032089f.js → invoice-df662cd1.js} +3 -3
- package/dist/cjs/{isContrastColor-76592c92.js → isContrastColor-ef24b7aa.js} +1 -1
- package/dist/cjs/{isDarkColor-5d6ca405.js → isDarkColor-ebc74b4d.js} +1 -1
- package/dist/cjs/{localization-f4a64f6f.js → localization-09e91031.js} +1 -1
- package/dist/cjs/{paypal-125259ab.js → paypal-11acb15f.js} +5 -5
- package/dist/cjs/{placeTestOrder-02001a99.js → placeTestOrder-e0f80338.js} +2 -2
- package/dist/cjs/{renderCheckoutCurrency-cad156a7.js → renderCheckoutCurrency-d902f973.js} +2 -2
- package/dist/cjs/{submitGtag-4906b161.js → submitGtag-74762255.js} +1 -1
- package/dist/cjs/{throttle-02c2e917.js → throttle-34f7abf1.js} +2 -2
- package/dist/cjs/{updateCheckoutSessionAttributes-47d73942.js → updateCheckoutSessionAttributes-f595319d.js} +1 -1
- package/dist/cjs/zonos-address-display_8.cjs.entry.js +444 -202
- package/dist/cjs/zonos-address_4.cjs.entry.js +7 -7
- package/dist/cjs/zonos-airwallex-payment.cjs.entry.js +6 -6
- package/dist/cjs/zonos-badge.cjs.entry.js +1 -1
- package/dist/cjs/zonos-banner.cjs.entry.js +1 -1
- package/dist/cjs/zonos-button_3.cjs.entry.js +3 -3
- package/dist/cjs/zonos-card_5.cjs.entry.js +8 -8
- package/dist/cjs/zonos-cart-items_12.cjs.entry.js +15 -15
- package/dist/cjs/zonos-checkbox_2.cjs.entry.js +3 -3
- package/dist/cjs/zonos-checkout.cjs.entry.js +10 -10
- package/dist/cjs/zonos-collapse.cjs.entry.js +1 -1
- package/dist/cjs/zonos-collect-cart-items_3.cjs.entry.js +6 -6
- package/dist/cjs/zonos-collect-finish_6.cjs.entry.js +11 -11
- package/dist/cjs/zonos-collect.cjs.entry.js +9 -9
- package/dist/cjs/zonos-controller.cjs.entry.js +6 -6
- package/dist/cjs/zonos-country-flag.cjs.entry.js +2 -2
- package/dist/cjs/zonos-country-select_4.cjs.entry.js +1514 -1692
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +3 -3
- package/dist/cjs/zonos-hello.cjs.entry.js +3 -3
- package/dist/cjs/zonos-input.cjs.entry.js +2 -2
- package/dist/cjs/zonos-invoice-cart-items_2.cjs.entry.js +7 -7
- package/dist/cjs/zonos-invoice-finish_5.cjs.entry.js +11 -11
- package/dist/cjs/zonos-invoice.cjs.entry.js +9 -9
- package/dist/cjs/zonos-language-select_2.cjs.entry.js +2 -2
- package/dist/cjs/zonos-logo.cjs.entry.js +1 -1
- package/dist/cjs/zonos-policy-consent_2.cjs.entry.js +6 -6
- package/dist/cjs/zonos-shipping-rich-radio.cjs.entry.js +5 -5
- package/dist/cjs/zonos-stripe-input.cjs.entry.js +3 -3
- package/dist/cjs/zonos-text.cjs.entry.js +1 -1
- package/dist/cjs/zonos-v-stack.cjs.entry.js +1 -1
- package/dist/esm/{cart-23e29950.js → cart-c3cd0036.js} +4 -4
- package/dist/esm/{cleanHtmlMarkdown-5f7856f2.js → cleanHtmlMarkdown-87d195f6.js} +180 -356
- package/dist/esm/{collect-a235299d.js → collect-a7a4696c.js} +3 -3
- package/dist/esm/{debounce-58e4ff3e.js → debounce-c8d67b17.js} +1 -1
- package/dist/esm/{getBorderRadius-d23f47a6.js → getBorderRadius-dc982fe6.js} +1 -1
- package/dist/esm/{getContrastColor-f0bd5b65.js → getContrastColor-af895b60.js} +2 -2
- package/dist/esm/{hasInclusivePrice-5e106f84.js → hasInclusivePrice-93a88196.js} +1 -1
- package/dist/esm/index.js +7 -7
- package/dist/esm/{invoice-78f069c7.js → invoice-5a07bb03.js} +3 -3
- package/dist/esm/{isContrastColor-fbddacb6.js → isContrastColor-089de6ac.js} +1 -1
- package/dist/esm/{isDarkColor-566f04c5.js → isDarkColor-039ef212.js} +1 -1
- package/dist/esm/{localization-17546792.js → localization-a185c345.js} +1 -1
- package/dist/esm/{paypal-5bc6b0d0.js → paypal-cc558697.js} +5 -5
- package/dist/esm/{placeTestOrder-e842854a.js → placeTestOrder-92847316.js} +2 -2
- package/dist/esm/{renderCheckoutCurrency-e3953f67.js → renderCheckoutCurrency-34aaa81e.js} +2 -2
- package/dist/esm/{submitGtag-c7ea1f2a.js → submitGtag-dc54f5b9.js} +1 -1
- package/dist/esm/{throttle-f09d0659.js → throttle-44bfb6b5.js} +2 -2
- package/dist/esm/{updateCheckoutSessionAttributes-40e301a4.js → updateCheckoutSessionAttributes-e0a282d9.js} +1 -1
- package/dist/esm/zonos-address-display_8.entry.js +444 -202
- package/dist/esm/zonos-address_4.entry.js +7 -7
- package/dist/esm/zonos-airwallex-payment.entry.js +6 -6
- package/dist/esm/zonos-badge.entry.js +1 -1
- package/dist/esm/zonos-banner.entry.js +1 -1
- package/dist/esm/zonos-button_3.entry.js +3 -3
- package/dist/esm/zonos-card_5.entry.js +8 -8
- package/dist/esm/zonos-cart-items_12.entry.js +15 -15
- package/dist/esm/zonos-checkbox_2.entry.js +3 -3
- package/dist/esm/zonos-checkout.entry.js +10 -10
- package/dist/esm/zonos-collapse.entry.js +1 -1
- package/dist/esm/zonos-collect-cart-items_3.entry.js +6 -6
- package/dist/esm/zonos-collect-finish_6.entry.js +11 -11
- package/dist/esm/zonos-collect.entry.js +9 -9
- package/dist/esm/zonos-controller.entry.js +6 -6
- package/dist/esm/zonos-country-flag.entry.js +2 -2
- package/dist/esm/zonos-country-select_4.entry.js +1514 -1692
- package/dist/esm/zonos-hello-dialog.entry.js +3 -3
- package/dist/esm/zonos-hello.entry.js +3 -3
- package/dist/esm/zonos-input.entry.js +2 -2
- package/dist/esm/zonos-invoice-cart-items_2.entry.js +7 -7
- package/dist/esm/zonos-invoice-finish_5.entry.js +11 -11
- package/dist/esm/zonos-invoice.entry.js +9 -9
- package/dist/esm/zonos-language-select_2.entry.js +2 -2
- package/dist/esm/zonos-logo.entry.js +1 -1
- package/dist/esm/zonos-policy-consent_2.entry.js +6 -6
- package/dist/esm/zonos-shipping-rich-radio.entry.js +5 -5
- package/dist/esm/zonos-stripe-input.entry.js +3 -3
- package/dist/esm/zonos-text.entry.js +1 -1
- package/dist/esm/zonos-v-stack.entry.js +1 -1
- package/dist/esm-es5/{cart-23e29950.js → cart-c3cd0036.js} +1 -1
- package/dist/esm-es5/cleanHtmlMarkdown-87d195f6.js +1 -0
- package/dist/esm-es5/{collect-a235299d.js → collect-a7a4696c.js} +1 -1
- package/dist/esm-es5/{debounce-58e4ff3e.js → debounce-c8d67b17.js} +1 -1
- package/dist/esm-es5/{getBorderRadius-d23f47a6.js → getBorderRadius-dc982fe6.js} +1 -1
- package/dist/esm-es5/{getContrastColor-f0bd5b65.js → getContrastColor-af895b60.js} +1 -1
- package/dist/esm-es5/{hasInclusivePrice-5e106f84.js → hasInclusivePrice-93a88196.js} +1 -1
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/{invoice-78f069c7.js → invoice-5a07bb03.js} +1 -1
- package/dist/esm-es5/{isContrastColor-fbddacb6.js → isContrastColor-089de6ac.js} +1 -1
- package/dist/esm-es5/{isDarkColor-566f04c5.js → isDarkColor-039ef212.js} +1 -1
- package/dist/esm-es5/{localization-17546792.js → localization-a185c345.js} +1 -1
- package/dist/esm-es5/{paypal-5bc6b0d0.js → paypal-cc558697.js} +1 -1
- package/dist/esm-es5/{placeTestOrder-e842854a.js → placeTestOrder-92847316.js} +1 -1
- package/dist/esm-es5/{renderCheckoutCurrency-e3953f67.js → renderCheckoutCurrency-34aaa81e.js} +1 -1
- package/dist/esm-es5/{submitGtag-c7ea1f2a.js → submitGtag-dc54f5b9.js} +1 -1
- package/dist/esm-es5/throttle-44bfb6b5.js +1 -0
- package/dist/esm-es5/{updateCheckoutSessionAttributes-40e301a4.js → updateCheckoutSessionAttributes-e0a282d9.js} +1 -1
- package/dist/esm-es5/zonos-address-display_8.entry.js +1 -1
- package/dist/esm-es5/zonos-address_4.entry.js +1 -1
- package/dist/esm-es5/zonos-airwallex-payment.entry.js +1 -1
- package/dist/esm-es5/zonos-badge.entry.js +1 -1
- package/dist/esm-es5/zonos-banner.entry.js +1 -1
- package/dist/esm-es5/zonos-button_3.entry.js +1 -1
- package/dist/esm-es5/zonos-card_5.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_12.entry.js +1 -1
- package/dist/esm-es5/zonos-checkbox_2.entry.js +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-collapse.entry.js +1 -1
- package/dist/esm-es5/zonos-collect-cart-items_3.entry.js +1 -1
- package/dist/esm-es5/zonos-collect-finish_6.entry.js +1 -1
- package/dist/esm-es5/zonos-collect.entry.js +1 -1
- package/dist/esm-es5/zonos-controller.entry.js +1 -1
- package/dist/esm-es5/zonos-country-flag.entry.js +1 -1
- package/dist/esm-es5/zonos-country-select_4.entry.js +1 -1
- package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
- package/dist/esm-es5/zonos-hello.entry.js +1 -1
- package/dist/esm-es5/zonos-input.entry.js +1 -1
- package/dist/esm-es5/zonos-invoice-cart-items_2.entry.js +1 -1
- package/dist/esm-es5/zonos-invoice-finish_5.entry.js +1 -1
- package/dist/esm-es5/zonos-invoice.entry.js +1 -1
- package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
- package/dist/esm-es5/zonos-logo.entry.js +1 -1
- package/dist/esm-es5/zonos-policy-consent_2.entry.js +1 -1
- package/dist/esm-es5/zonos-shipping-rich-radio.entry.js +1 -1
- package/dist/esm-es5/zonos-stripe-input.entry.js +1 -1
- package/dist/esm-es5/zonos-text.entry.js +1 -1
- package/dist/esm-es5/zonos-v-stack.entry.js +1 -1
- package/dist/scripts/analyticsRelayOnInit.js +1 -1
- package/dist/scripts/blurCurrencyOnInit.js +1 -1
- package/dist/scripts/index.js +1 -1
- package/dist/scripts/loadZonos.js +1 -1
- package/dist/scripts/zonos.js +1 -1
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/{p-d25759fb.system.js → p-03c357f5.system.js} +1 -1
- package/dist/zonos-elements/{p-41619f29.js → p-043e9a84.js} +1 -1
- package/dist/zonos-elements/{p-59b10526.entry.js → p-08e78d79.entry.js} +1 -1
- package/dist/zonos-elements/{p-c846a5f3.system.entry.js → p-0ad6a92b.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-b59fc3fa.system.entry.js → p-0e1f13ff.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-306e5499.system.entry.js → p-12396d79.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-c6823974.system.entry.js → p-15097876.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-9f5fb332.js → p-1735a69b.js} +1 -1
- package/dist/zonos-elements/p-1906c8f7.js +1 -0
- package/dist/zonos-elements/{p-055ef910.entry.js → p-1992fd91.entry.js} +1 -1
- package/dist/zonos-elements/p-1de258c3.js +1 -0
- package/dist/zonos-elements/{p-abd485df.entry.js → p-216d31ca.entry.js} +1 -1
- package/dist/zonos-elements/p-29b60bf3.system.js +1 -1
- package/dist/zonos-elements/{p-a1a05de4.system.entry.js → p-29c1703c.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-e9afd736.system.entry.js → p-2b2122bc.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-9574695a.system.js → p-2bdfa429.system.js} +1 -1
- package/dist/zonos-elements/{p-33910e8b.js → p-2c0a627d.js} +1 -1
- package/dist/zonos-elements/p-30e9a6d7.system.js +1 -0
- package/dist/zonos-elements/{p-33d4be28.js → p-34d6eb83.js} +1 -1
- package/dist/zonos-elements/p-35fd0fdb.js +1 -0
- package/dist/zonos-elements/p-387f33ae.js +1 -0
- package/dist/zonos-elements/p-38d2da0d.entry.js +1 -0
- package/dist/zonos-elements/{p-08b48608.entry.js → p-391ea5c2.entry.js} +1 -1
- package/dist/zonos-elements/{p-1a4083be.system.js → p-3980e553.system.js} +1 -1
- package/dist/zonos-elements/p-3b479012.js +1 -0
- package/dist/zonos-elements/{p-896fb969.js → p-3d28353a.js} +1 -1
- package/dist/zonos-elements/{p-328fd90e.entry.js → p-3e058b4e.entry.js} +1 -1
- package/dist/zonos-elements/{p-86a9f048.system.entry.js → p-3e914f69.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-62c68aee.system.js → p-3ea7643b.system.js} +1 -1
- package/dist/zonos-elements/{p-f53c8a9f.entry.js → p-3f8050ab.entry.js} +1 -1
- package/dist/zonos-elements/{p-daf57db3.system.entry.js → p-3fa307d1.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-0a54dae6.system.entry.js → p-429ab545.system.entry.js} +1 -1
- package/dist/zonos-elements/p-4900096c.system.entry.js +1 -0
- package/dist/zonos-elements/{p-f053975e.system.js → p-496accce.system.js} +1 -1
- package/dist/zonos-elements/{p-12a05647.entry.js → p-4efd7178.entry.js} +1 -1
- package/dist/zonos-elements/{p-9cd41234.system.entry.js → p-51b537a6.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-4b371b65.entry.js → p-5427bf51.entry.js} +1 -1
- package/dist/zonos-elements/{p-ad961f5d.entry.js → p-577b543c.entry.js} +1 -1
- package/dist/zonos-elements/{p-10571f94.system.entry.js → p-5aee5de5.system.entry.js} +1 -1
- package/dist/zonos-elements/p-5c30d04b.js +1 -0
- package/dist/zonos-elements/{p-8e77a3cd.system.entry.js → p-5ce8b3c3.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-dcef2202.entry.js → p-5d4201d5.entry.js} +1 -1
- package/dist/zonos-elements/{p-80df7e0b.system.entry.js → p-6146bfaa.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-e548b8ec.entry.js → p-62609f19.entry.js} +1 -1
- package/dist/zonos-elements/{p-97917371.system.entry.js → p-70fd21c4.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-013575f2.entry.js → p-785d6f43.entry.js} +1 -1
- package/dist/zonos-elements/{p-1f31f5a0.system.entry.js → p-79f58524.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-4df08fc4.js → p-7bdce9d4.js} +1 -1
- package/dist/zonos-elements/{p-e8cb382e.entry.js → p-819f182e.entry.js} +1 -1
- package/dist/zonos-elements/{p-14018649.system.js → p-863cfab2.system.js} +2 -2
- package/dist/zonos-elements/{p-4a960329.system.entry.js → p-8873d332.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-c83bc4b3.entry.js → p-8c54aaec.entry.js} +1 -1
- package/dist/zonos-elements/{p-49d8a10f.entry.js → p-9295b932.entry.js} +1 -1
- package/dist/zonos-elements/{p-f0eb6317.system.entry.js → p-93c6c2df.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-d5e66ea6.entry.js → p-96972001.entry.js} +1 -1
- package/dist/zonos-elements/{p-3eba657b.system.entry.js → p-99e8743e.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-42948a52.js → p-9cb80484.js} +1 -1
- package/dist/zonos-elements/{p-31577ebd.entry.js → p-9d80357b.entry.js} +1 -1
- package/dist/zonos-elements/p-a1bd3a53.system.js +1 -0
- package/dist/zonos-elements/p-a1f59d6d.system.entry.js +1 -0
- package/dist/zonos-elements/{p-6c19310e.system.entry.js → p-a2353242.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-e8ec88a9.system.entry.js → p-a33e1549.system.entry.js} +1 -1
- package/dist/zonos-elements/p-a3c116d6.system.js +1 -0
- package/dist/zonos-elements/{p-5aa35d1c.system.entry.js → p-a3d3ce5d.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-27e50593.system.entry.js → p-a44591f6.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-2197d6ab.js → p-a7028453.js} +1 -1
- package/dist/zonos-elements/p-a9d01bfa.entry.js +1 -0
- package/dist/zonos-elements/{p-ccd14aa5.entry.js → p-ac762358.entry.js} +1 -1
- package/dist/zonos-elements/{p-0b59076d.system.entry.js → p-b376aba7.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-cc508de8.entry.js → p-b5f67807.entry.js} +1 -1
- package/dist/zonos-elements/{p-8c4761d1.system.entry.js → p-b9034a75.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-9b003a15.system.entry.js → p-b9359002.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-91b921a4.system.js → p-be233925.system.js} +1 -1
- package/dist/zonos-elements/{p-919c5500.entry.js → p-c68a7f3e.entry.js} +1 -1
- package/dist/zonos-elements/p-cc6ad18a.js +1 -0
- package/dist/zonos-elements/{p-c1463da7.entry.js → p-d1e84608.entry.js} +1 -1
- package/dist/zonos-elements/{p-bf8c98ab.system.js → p-d1f2e532.system.js} +1 -1
- package/dist/zonos-elements/{p-171d0f9f.system.js → p-d62dab88.system.js} +1 -1
- package/dist/zonos-elements/{p-2a1247f4.system.entry.js → p-d6d18115.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-5d65be06.system.js → p-d706852e.system.js} +1 -1
- package/dist/zonos-elements/{p-df55536b.entry.js → p-daab3824.entry.js} +1 -1
- package/dist/zonos-elements/{p-7d9d2407.system.js → p-dab78981.system.js} +1 -1
- package/dist/zonos-elements/{p-990d1495.system.entry.js → p-db65c60b.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-e9c8a235.js → p-e3376f43.js} +1 -1
- package/dist/zonos-elements/{p-45d74be2.system.js → p-e562d953.system.js} +1 -1
- package/dist/zonos-elements/{p-c13d2e3f.entry.js → p-e5f25b27.entry.js} +1 -1
- package/dist/zonos-elements/{p-bc919de1.system.js → p-e977562b.system.js} +1 -1
- package/dist/zonos-elements/{p-1678d8b4.system.entry.js → p-e9e3c951.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-46e72a90.entry.js → p-ee70bd2e.entry.js} +1 -1
- package/dist/zonos-elements/{p-a968ccba.entry.js → p-ee920b9b.entry.js} +1 -1
- package/dist/zonos-elements/{p-3dc3596b.js → p-f1aea919.js} +1 -1
- package/dist/zonos-elements/p-f29bcf8b.system.js +1 -0
- package/dist/zonos-elements/{p-f72642de.entry.js → p-f59514e9.entry.js} +1 -1
- package/dist/zonos-elements/{p-52bd7be3.system.js → p-f61c0eef.system.js} +1 -1
- package/dist/zonos-elements/{p-9c3276c8.entry.js → p-f97da77c.entry.js} +1 -1
- package/dist/zonos-elements/{p-df6fbf3f.entry.js → p-fb830355.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +12 -35
- package/dist/esm-es5/cleanHtmlMarkdown-5f7856f2.js +0 -1
- package/dist/esm-es5/throttle-f09d0659.js +0 -1
- package/dist/zonos-elements/p-14d6542f.system.js +0 -1
- package/dist/zonos-elements/p-18af6aaa.system.js +0 -1
- package/dist/zonos-elements/p-1a105d6e.system.entry.js +0 -1
- package/dist/zonos-elements/p-3b28fc76.js +0 -1
- package/dist/zonos-elements/p-539bc46c.js +0 -1
- package/dist/zonos-elements/p-5dd86dd9.system.js +0 -1
- package/dist/zonos-elements/p-7eb47eb0.entry.js +0 -1
- package/dist/zonos-elements/p-8af57c2a.js +0 -1
- package/dist/zonos-elements/p-90d22087.system.js +0 -1
- package/dist/zonos-elements/p-9581bffb.js +0 -1
- package/dist/zonos-elements/p-ac8cfdc0.js +0 -1
- package/dist/zonos-elements/p-b5c01288.system.entry.js +0 -1
- package/dist/zonos-elements/p-cd34ecf2.js +0 -1
- package/dist/zonos-elements/p-e643346a.entry.js +0 -1
- package/dist/zonos-elements/p-f1cc659c.js +0 -1
- /package/dist/cjs/{zonosStore-45a87908.js → zonosStore-fee716c9.js} +0 -0
- /package/dist/esm/{zonosStore-8e19daff.js → zonosStore-b7d3f9b0.js} +0 -0
- /package/dist/esm-es5/{zonosStore-8e19daff.js → zonosStore-b7d3f9b0.js} +0 -0
- /package/dist/zonos-elements/{p-3e7ee89d.system.js → p-47a1d469.system.js} +0 -0
- /package/dist/zonos-elements/{p-701d9a7c.js → p-9a417eeb.js} +0 -0
|
@@ -3,1807 +3,1629 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const index = require('./index-b1f95d96.js');
|
|
6
|
-
const localization = require('./localization-
|
|
7
|
-
const zonosStore = require('./zonosStore-
|
|
6
|
+
const localization = require('./localization-09e91031.js');
|
|
7
|
+
const zonosStore = require('./zonosStore-fee716c9.js');
|
|
8
8
|
const formatStringWithLinks = require('./formatStringWithLinks-52341fc7.js');
|
|
9
|
-
const isDarkColor = require('./isDarkColor-
|
|
9
|
+
const isDarkColor = require('./isDarkColor-ebc74b4d.js');
|
|
10
10
|
const ILanguage = require('./ILanguage-98b04442.js');
|
|
11
11
|
const classes = require('./classes-b7918f56.js');
|
|
12
12
|
require('./handleFetch-954f30e1.js');
|
|
13
13
|
require('./VarianceTest-bec00ea8.js');
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Fuse.js v7.
|
|
16
|
+
* Fuse.js v7.4.2 - Lightweight fuzzy-search (http://fusejs.io)
|
|
17
17
|
*
|
|
18
|
-
* Copyright (c)
|
|
18
|
+
* Copyright (c) 2026 Kiro Risk (http://kiro.me)
|
|
19
19
|
* All Rights Reserved. Apache Software License 2.0
|
|
20
20
|
*
|
|
21
21
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
//#region src/helpers/typeGuards.ts
|
|
24
24
|
function isArray(value) {
|
|
25
|
-
|
|
26
|
-
? getTag(value) === '[object Array]'
|
|
27
|
-
: Array.isArray(value)
|
|
25
|
+
return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js
|
|
31
|
-
const INFINITY = 1 / 0;
|
|
32
27
|
function baseToString(value) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
let result = value + '';
|
|
38
|
-
return result == '0' && 1 / value == -INFINITY ? '-0' : result
|
|
28
|
+
if (typeof value == "string") return value;
|
|
29
|
+
if (typeof value === "bigint") return value.toString();
|
|
30
|
+
const result = value + "";
|
|
31
|
+
return result == "0" && 1 / value == -Infinity ? "-0" : result;
|
|
39
32
|
}
|
|
40
|
-
|
|
41
33
|
function toString(value) {
|
|
42
|
-
|
|
34
|
+
return value == null ? "" : baseToString(value);
|
|
43
35
|
}
|
|
44
|
-
|
|
45
36
|
function isString(value) {
|
|
46
|
-
|
|
37
|
+
return typeof value === "string";
|
|
47
38
|
}
|
|
48
|
-
|
|
49
39
|
function isNumber(value) {
|
|
50
|
-
|
|
40
|
+
return typeof value === "number";
|
|
51
41
|
}
|
|
52
|
-
|
|
53
|
-
// Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js
|
|
54
42
|
function isBoolean(value) {
|
|
55
|
-
|
|
56
|
-
value === true ||
|
|
57
|
-
value === false ||
|
|
58
|
-
(isObjectLike(value) && getTag(value) == '[object Boolean]')
|
|
59
|
-
)
|
|
43
|
+
return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
|
|
60
44
|
}
|
|
61
|
-
|
|
62
45
|
function isObject(value) {
|
|
63
|
-
|
|
46
|
+
return typeof value === "object";
|
|
64
47
|
}
|
|
65
|
-
|
|
66
|
-
// Checks if `value` is object-like.
|
|
67
48
|
function isObjectLike(value) {
|
|
68
|
-
|
|
49
|
+
return isObject(value) && value !== null;
|
|
69
50
|
}
|
|
70
|
-
|
|
71
51
|
function isDefined(value) {
|
|
72
|
-
|
|
52
|
+
return value !== void 0 && value !== null;
|
|
73
53
|
}
|
|
74
|
-
|
|
75
54
|
function isBlank(value) {
|
|
76
|
-
|
|
55
|
+
return !value.trim().length;
|
|
77
56
|
}
|
|
78
|
-
|
|
79
|
-
// Gets the `toStringTag` of `value`.
|
|
80
|
-
// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js
|
|
81
57
|
function getTag(value) {
|
|
82
|
-
|
|
83
|
-
? value === undefined
|
|
84
|
-
? '[object Undefined]'
|
|
85
|
-
: '[object Null]'
|
|
86
|
-
: Object.prototype.toString.call(value)
|
|
58
|
+
return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
|
|
87
59
|
}
|
|
88
60
|
|
|
89
|
-
|
|
90
|
-
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/core/errorMessages.ts
|
|
91
63
|
const INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
|
|
92
|
-
|
|
93
|
-
const LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) =>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const PATTERN_LENGTH_TOO_LARGE = (max) =>
|
|
97
|
-
`Pattern length exceeds max of ${max}.`;
|
|
98
|
-
|
|
64
|
+
const INVALID_DOC_INDEX = "Invalid doc index: must be a non-negative integer within the bounds of the docs array";
|
|
65
|
+
const LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
|
|
66
|
+
const PATTERN_LENGTH_TOO_LARGE = (max) => `Pattern length exceeds max of ${max}.`;
|
|
99
67
|
const MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
|
|
68
|
+
const INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
|
|
69
|
+
const FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED = "Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.";
|
|
100
70
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/tools/KeyStore.ts
|
|
104
73
|
const hasOwn = Object.prototype.hasOwnProperty;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
keys() {
|
|
131
|
-
return this._keys
|
|
132
|
-
}
|
|
133
|
-
toJSON() {
|
|
134
|
-
return JSON.stringify(this._keys)
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
74
|
+
var KeyStore = class {
|
|
75
|
+
constructor(keys) {
|
|
76
|
+
this._keys = [];
|
|
77
|
+
this._keyMap = {};
|
|
78
|
+
let totalWeight = 0;
|
|
79
|
+
keys.forEach((key) => {
|
|
80
|
+
const obj = createKey(key);
|
|
81
|
+
this._keys.push(obj);
|
|
82
|
+
this._keyMap[obj.id] = obj;
|
|
83
|
+
totalWeight += obj.weight;
|
|
84
|
+
});
|
|
85
|
+
this._keys.forEach((key) => {
|
|
86
|
+
key.weight /= totalWeight;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
get(keyId) {
|
|
90
|
+
return this._keyMap[keyId];
|
|
91
|
+
}
|
|
92
|
+
keys() {
|
|
93
|
+
return this._keys;
|
|
94
|
+
}
|
|
95
|
+
toJSON() {
|
|
96
|
+
return JSON.stringify(this._keys);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
138
99
|
function createKey(key) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
getFn = key.getFn;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return { path, id, weight, src, getFn }
|
|
100
|
+
let path = null;
|
|
101
|
+
let id = null;
|
|
102
|
+
let src = null;
|
|
103
|
+
let weight = 1;
|
|
104
|
+
let getFn = null;
|
|
105
|
+
if (isString(key) || isArray(key)) {
|
|
106
|
+
src = key;
|
|
107
|
+
path = createKeyPath(key);
|
|
108
|
+
id = createKeyId(key);
|
|
109
|
+
} else {
|
|
110
|
+
if (!hasOwn.call(key, "name")) throw new Error(MISSING_KEY_PROPERTY("name"));
|
|
111
|
+
const name = key.name;
|
|
112
|
+
src = name;
|
|
113
|
+
if (hasOwn.call(key, "weight") && key.weight !== void 0) {
|
|
114
|
+
weight = key.weight;
|
|
115
|
+
if (weight <= 0) throw new Error(INVALID_KEY_WEIGHT_VALUE(createKeyId(name)));
|
|
116
|
+
}
|
|
117
|
+
path = createKeyPath(name);
|
|
118
|
+
id = createKeyId(name);
|
|
119
|
+
getFn = key.getFn ?? null;
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
path,
|
|
123
|
+
id,
|
|
124
|
+
weight,
|
|
125
|
+
src,
|
|
126
|
+
getFn
|
|
127
|
+
};
|
|
171
128
|
}
|
|
172
|
-
|
|
173
129
|
function createKeyPath(key) {
|
|
174
|
-
|
|
130
|
+
return isArray(key) ? key : key.split(".");
|
|
175
131
|
}
|
|
176
|
-
|
|
177
132
|
function createKeyId(key) {
|
|
178
|
-
|
|
133
|
+
return isArray(key) ? key.join(".") : key;
|
|
179
134
|
}
|
|
180
135
|
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/helpers/get.ts
|
|
181
138
|
function get(obj, path) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
(isString(value) || isNumber(value) || isBoolean(value))
|
|
206
|
-
) {
|
|
207
|
-
list.push(toString(value));
|
|
208
|
-
} else if (isArray(value)) {
|
|
209
|
-
arr = true;
|
|
210
|
-
// Search each item in the array.
|
|
211
|
-
for (let i = 0, len = value.length; i < len; i += 1) {
|
|
212
|
-
deepGet(value[i], path, index + 1);
|
|
213
|
-
}
|
|
214
|
-
} else if (path.length) {
|
|
215
|
-
// An object. Recurse further.
|
|
216
|
-
deepGet(value, path, index + 1);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
// Backwards compatibility (since path used to be a string)
|
|
222
|
-
deepGet(obj, isString(path) ? path.split('.') : path, 0);
|
|
223
|
-
|
|
224
|
-
return arr ? list : list[0]
|
|
139
|
+
const list = [];
|
|
140
|
+
let arr = false;
|
|
141
|
+
const deepGet = (obj, path, index, arrayIndex) => {
|
|
142
|
+
if (!isDefined(obj)) return;
|
|
143
|
+
if (!path[index]) list.push(arrayIndex !== void 0 ? {
|
|
144
|
+
v: obj,
|
|
145
|
+
i: arrayIndex
|
|
146
|
+
} : obj);
|
|
147
|
+
else {
|
|
148
|
+
const value = obj[path[index]];
|
|
149
|
+
if (!isDefined(value)) return;
|
|
150
|
+
if (index === path.length - 1 && (isString(value) || isNumber(value) || isBoolean(value) || typeof value === "bigint")) list.push(arrayIndex !== void 0 ? {
|
|
151
|
+
v: toString(value),
|
|
152
|
+
i: arrayIndex
|
|
153
|
+
} : toString(value));
|
|
154
|
+
else if (isArray(value)) {
|
|
155
|
+
arr = true;
|
|
156
|
+
for (let i = 0, len = value.length; i < len; i += 1) deepGet(value[i], path, index + 1, i);
|
|
157
|
+
} else if (path.length) deepGet(value, path, index + 1, arrayIndex);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
deepGet(obj, isString(path) ? path.split(".") : path, 0);
|
|
161
|
+
return arr ? list : list[0];
|
|
225
162
|
}
|
|
226
163
|
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/core/config.ts
|
|
227
166
|
const MatchOptions = {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
includeMatches: false,
|
|
232
|
-
// When `true`, the matching function will continue to the end of a search pattern even if
|
|
233
|
-
// a perfect match has already been located in the string.
|
|
234
|
-
findAllMatches: false,
|
|
235
|
-
// Minimum number of characters that must be matched before a result is considered a match
|
|
236
|
-
minMatchCharLength: 1
|
|
167
|
+
includeMatches: false,
|
|
168
|
+
findAllMatches: false,
|
|
169
|
+
minMatchCharLength: 1
|
|
237
170
|
};
|
|
238
|
-
|
|
239
171
|
const BasicOptions = {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
includeScore: false,
|
|
247
|
-
// List of properties that will be searched. This also supports nested properties.
|
|
248
|
-
keys: [],
|
|
249
|
-
// Whether to sort the result list, by score
|
|
250
|
-
shouldSort: true,
|
|
251
|
-
// Default sort function: sort by ascending score, ascending index
|
|
252
|
-
sortFn: (a, b) =>
|
|
253
|
-
a.score === b.score ? (a.idx < b.idx ? -1 : 1) : a.score < b.score ? -1 : 1
|
|
172
|
+
isCaseSensitive: false,
|
|
173
|
+
ignoreDiacritics: false,
|
|
174
|
+
includeScore: false,
|
|
175
|
+
keys: [],
|
|
176
|
+
shouldSort: true,
|
|
177
|
+
sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
|
|
254
178
|
};
|
|
255
|
-
|
|
256
179
|
const FuzzyOptions = {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
// (of both letters and location), a threshold of '1.0' would match anything.
|
|
261
|
-
threshold: 0.6,
|
|
262
|
-
// Determines how close the match must be to the fuzzy location (specified above).
|
|
263
|
-
// An exact letter match which is 'distance' characters away from the fuzzy location
|
|
264
|
-
// would score as a complete mismatch. A distance of '0' requires the match be at
|
|
265
|
-
// the exact location specified, a threshold of '1000' would require a perfect match
|
|
266
|
-
// to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
|
|
267
|
-
distance: 100
|
|
180
|
+
location: 0,
|
|
181
|
+
threshold: .6,
|
|
182
|
+
distance: 100
|
|
268
183
|
};
|
|
269
|
-
|
|
270
184
|
const AdvancedOptions = {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
ignoreLocation: false,
|
|
280
|
-
// When `true`, the calculation for the relevance score (used for sorting) will
|
|
281
|
-
// ignore the field-length norm.
|
|
282
|
-
// More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
|
|
283
|
-
ignoreFieldNorm: false,
|
|
284
|
-
// The weight to determine how much field length norm effects scoring.
|
|
285
|
-
fieldNormWeight: 1
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
var Config = {
|
|
289
|
-
...BasicOptions,
|
|
290
|
-
...MatchOptions,
|
|
291
|
-
...FuzzyOptions,
|
|
292
|
-
...AdvancedOptions
|
|
185
|
+
useExtendedSearch: false,
|
|
186
|
+
useTokenSearch: false,
|
|
187
|
+
tokenize: void 0,
|
|
188
|
+
tokenMatch: "any",
|
|
189
|
+
getFn: get,
|
|
190
|
+
ignoreLocation: false,
|
|
191
|
+
ignoreFieldNorm: false,
|
|
192
|
+
fieldNormWeight: 1
|
|
293
193
|
};
|
|
194
|
+
const Config = Object.freeze({
|
|
195
|
+
...BasicOptions,
|
|
196
|
+
...MatchOptions,
|
|
197
|
+
...FuzzyOptions,
|
|
198
|
+
...AdvancedOptions
|
|
199
|
+
});
|
|
294
200
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
// Field-length norm: the shorter the field, the higher the weight.
|
|
298
|
-
// Set to 3 decimals to reduce index size.
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/tools/fieldNorm.ts
|
|
299
203
|
function norm(weight = 1, mantissa = 3) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
clear() {
|
|
322
|
-
cache.clear();
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
class FuseIndex {
|
|
328
|
-
constructor({
|
|
329
|
-
getFn = Config.getFn,
|
|
330
|
-
fieldNormWeight = Config.fieldNormWeight
|
|
331
|
-
} = {}) {
|
|
332
|
-
this.norm = norm(fieldNormWeight, 3);
|
|
333
|
-
this.getFn = getFn;
|
|
334
|
-
this.isCreated = false;
|
|
335
|
-
|
|
336
|
-
this.setIndexRecords();
|
|
337
|
-
}
|
|
338
|
-
setSources(docs = []) {
|
|
339
|
-
this.docs = docs;
|
|
340
|
-
}
|
|
341
|
-
setIndexRecords(records = []) {
|
|
342
|
-
this.records = records;
|
|
343
|
-
}
|
|
344
|
-
setKeys(keys = []) {
|
|
345
|
-
this.keys = keys;
|
|
346
|
-
this._keysMap = {};
|
|
347
|
-
keys.forEach((key, idx) => {
|
|
348
|
-
this._keysMap[key.id] = idx;
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
create() {
|
|
352
|
-
if (this.isCreated || !this.docs.length) {
|
|
353
|
-
return
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
this.isCreated = true;
|
|
357
|
-
|
|
358
|
-
// List is Array<String>
|
|
359
|
-
if (isString(this.docs[0])) {
|
|
360
|
-
this.docs.forEach((doc, docIndex) => {
|
|
361
|
-
this._addString(doc, docIndex);
|
|
362
|
-
});
|
|
363
|
-
} else {
|
|
364
|
-
// List is Array<Object>
|
|
365
|
-
this.docs.forEach((doc, docIndex) => {
|
|
366
|
-
this._addObject(doc, docIndex);
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
this.norm.clear();
|
|
371
|
-
}
|
|
372
|
-
// Adds a doc to the end of the index
|
|
373
|
-
add(doc) {
|
|
374
|
-
const idx = this.size();
|
|
375
|
-
|
|
376
|
-
if (isString(doc)) {
|
|
377
|
-
this._addString(doc, idx);
|
|
378
|
-
} else {
|
|
379
|
-
this._addObject(doc, idx);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
// Removes the doc at the specified index of the index
|
|
383
|
-
removeAt(idx) {
|
|
384
|
-
this.records.splice(idx, 1);
|
|
385
|
-
|
|
386
|
-
// Change ref index of every subsquent doc
|
|
387
|
-
for (let i = idx, len = this.size(); i < len; i += 1) {
|
|
388
|
-
this.records[i].i -= 1;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
getValueForItemAtKeyId(item, keyId) {
|
|
392
|
-
return item[this._keysMap[keyId]]
|
|
393
|
-
}
|
|
394
|
-
size() {
|
|
395
|
-
return this.records.length
|
|
396
|
-
}
|
|
397
|
-
_addString(doc, docIndex) {
|
|
398
|
-
if (!isDefined(doc) || isBlank(doc)) {
|
|
399
|
-
return
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
let record = {
|
|
403
|
-
v: doc,
|
|
404
|
-
i: docIndex,
|
|
405
|
-
n: this.norm.get(doc)
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
this.records.push(record);
|
|
409
|
-
}
|
|
410
|
-
_addObject(doc, docIndex) {
|
|
411
|
-
let record = { i: docIndex, $: {} };
|
|
412
|
-
|
|
413
|
-
// Iterate over every key (i.e, path), and fetch the value at that key
|
|
414
|
-
this.keys.forEach((key, keyIndex) => {
|
|
415
|
-
let value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
|
|
416
|
-
|
|
417
|
-
if (!isDefined(value)) {
|
|
418
|
-
return
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
if (isArray(value)) {
|
|
422
|
-
let subRecords = [];
|
|
423
|
-
const stack = [{ nestedArrIndex: -1, value }];
|
|
424
|
-
|
|
425
|
-
while (stack.length) {
|
|
426
|
-
const { nestedArrIndex, value } = stack.pop();
|
|
427
|
-
|
|
428
|
-
if (!isDefined(value)) {
|
|
429
|
-
continue
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
if (isString(value) && !isBlank(value)) {
|
|
433
|
-
let subRecord = {
|
|
434
|
-
v: value,
|
|
435
|
-
i: nestedArrIndex,
|
|
436
|
-
n: this.norm.get(value)
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
subRecords.push(subRecord);
|
|
440
|
-
} else if (isArray(value)) {
|
|
441
|
-
value.forEach((item, k) => {
|
|
442
|
-
stack.push({
|
|
443
|
-
nestedArrIndex: k,
|
|
444
|
-
value: item
|
|
445
|
-
});
|
|
446
|
-
});
|
|
447
|
-
} else ;
|
|
448
|
-
}
|
|
449
|
-
record.$[keyIndex] = subRecords;
|
|
450
|
-
} else if (isString(value) && !isBlank(value)) {
|
|
451
|
-
let subRecord = {
|
|
452
|
-
v: value,
|
|
453
|
-
n: this.norm.get(value)
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
record.$[keyIndex] = subRecord;
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
this.records.push(record);
|
|
461
|
-
}
|
|
462
|
-
toJSON() {
|
|
463
|
-
return {
|
|
464
|
-
keys: this.keys,
|
|
465
|
-
records: this.records
|
|
466
|
-
}
|
|
467
|
-
}
|
|
204
|
+
const cache = /* @__PURE__ */ new Map();
|
|
205
|
+
const m = Math.pow(10, mantissa);
|
|
206
|
+
return {
|
|
207
|
+
get(value) {
|
|
208
|
+
let numTokens = 1;
|
|
209
|
+
let inSpace = false;
|
|
210
|
+
for (let i = 0; i < value.length; i++) if (value.charCodeAt(i) === 32) {
|
|
211
|
+
if (!inSpace) {
|
|
212
|
+
numTokens++;
|
|
213
|
+
inSpace = true;
|
|
214
|
+
}
|
|
215
|
+
} else inSpace = false;
|
|
216
|
+
if (cache.has(numTokens)) return cache.get(numTokens);
|
|
217
|
+
const n = Math.round(m / Math.pow(numTokens, .5 * weight)) / m;
|
|
218
|
+
cache.set(numTokens, n);
|
|
219
|
+
return n;
|
|
220
|
+
},
|
|
221
|
+
clear() {
|
|
222
|
+
cache.clear();
|
|
223
|
+
}
|
|
224
|
+
};
|
|
468
225
|
}
|
|
469
226
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
)
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/tools/FuseIndex.ts
|
|
229
|
+
var FuseIndex = class {
|
|
230
|
+
constructor({ getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
231
|
+
this.norm = norm(fieldNormWeight, 3);
|
|
232
|
+
this.getFn = getFn;
|
|
233
|
+
this.isCreated = false;
|
|
234
|
+
this.docs = [];
|
|
235
|
+
this.keys = [];
|
|
236
|
+
this._keysMap = {};
|
|
237
|
+
this.setIndexRecords();
|
|
238
|
+
}
|
|
239
|
+
setSources(docs = []) {
|
|
240
|
+
this.docs = docs;
|
|
241
|
+
}
|
|
242
|
+
setIndexRecords(records = []) {
|
|
243
|
+
this.records = records;
|
|
244
|
+
}
|
|
245
|
+
setKeys(keys = []) {
|
|
246
|
+
this.keys = keys;
|
|
247
|
+
this._keysMap = {};
|
|
248
|
+
keys.forEach((key, idx) => {
|
|
249
|
+
this._keysMap[key.id] = idx;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
create() {
|
|
253
|
+
if (this.isCreated || !this.docs.length) return;
|
|
254
|
+
this.isCreated = true;
|
|
255
|
+
const len = this.docs.length;
|
|
256
|
+
this.records = new Array(len);
|
|
257
|
+
let recordCount = 0;
|
|
258
|
+
if (isString(this.docs[0])) for (let i = 0; i < len; i++) {
|
|
259
|
+
const record = this._createStringRecord(this.docs[i], i);
|
|
260
|
+
if (record) this.records[recordCount++] = record;
|
|
261
|
+
}
|
|
262
|
+
else for (let i = 0; i < len; i++) this.records[recordCount++] = this._createObjectRecord(this.docs[i], i);
|
|
263
|
+
this.records.length = recordCount;
|
|
264
|
+
this.norm.clear();
|
|
265
|
+
}
|
|
266
|
+
add(doc, docIndex) {
|
|
267
|
+
if (!Number.isInteger(docIndex) || docIndex < 0) throw new Error(INVALID_DOC_INDEX);
|
|
268
|
+
if (isString(doc)) {
|
|
269
|
+
const record = this._createStringRecord(doc, docIndex);
|
|
270
|
+
if (record) this.records.push(record);
|
|
271
|
+
return record;
|
|
272
|
+
}
|
|
273
|
+
const record = this._createObjectRecord(doc, docIndex);
|
|
274
|
+
this.records.push(record);
|
|
275
|
+
return record;
|
|
276
|
+
}
|
|
277
|
+
removeAt(idx) {
|
|
278
|
+
if (!Number.isInteger(idx) || idx < 0) throw new Error(INVALID_DOC_INDEX);
|
|
279
|
+
for (let i = 0, len = this.records.length; i < len; i += 1) if (this.records[i].i === idx) {
|
|
280
|
+
this.records.splice(i, 1);
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
for (let i = 0, len = this.records.length; i < len; i += 1) if (this.records[i].i > idx) this.records[i].i -= 1;
|
|
284
|
+
}
|
|
285
|
+
removeAll(indices) {
|
|
286
|
+
const toRemove = /* @__PURE__ */ new Set();
|
|
287
|
+
for (const v of indices) if (Number.isInteger(v) && v >= 0) toRemove.add(v);
|
|
288
|
+
if (toRemove.size === 0) return;
|
|
289
|
+
this.records = this.records.filter((r) => !toRemove.has(r.i));
|
|
290
|
+
const sorted = Array.from(toRemove).sort((a, b) => a - b);
|
|
291
|
+
for (const record of this.records) {
|
|
292
|
+
let lo = 0;
|
|
293
|
+
let hi = sorted.length;
|
|
294
|
+
while (lo < hi) {
|
|
295
|
+
const mid = lo + hi >>> 1;
|
|
296
|
+
if (sorted[mid] < record.i) lo = mid + 1;
|
|
297
|
+
else hi = mid;
|
|
298
|
+
}
|
|
299
|
+
record.i -= lo;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
getValueForItemAtKeyId(item, keyId) {
|
|
303
|
+
return item[this._keysMap[keyId]];
|
|
304
|
+
}
|
|
305
|
+
size() {
|
|
306
|
+
return this.records.length;
|
|
307
|
+
}
|
|
308
|
+
_createStringRecord(doc, docIndex) {
|
|
309
|
+
if (!isDefined(doc) || isBlank(doc)) return null;
|
|
310
|
+
return {
|
|
311
|
+
v: doc,
|
|
312
|
+
i: docIndex,
|
|
313
|
+
n: this.norm.get(doc)
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
_createObjectRecord(doc, docIndex) {
|
|
317
|
+
const record = {
|
|
318
|
+
i: docIndex,
|
|
319
|
+
$: {}
|
|
320
|
+
};
|
|
321
|
+
for (let keyIndex = 0, keyLen = this.keys.length; keyIndex < keyLen; keyIndex++) {
|
|
322
|
+
const key = this.keys[keyIndex];
|
|
323
|
+
const value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
|
|
324
|
+
if (!isDefined(value)) continue;
|
|
325
|
+
if (isArray(value)) {
|
|
326
|
+
const subRecords = [];
|
|
327
|
+
for (let i = 0, len = value.length; i < len; i += 1) {
|
|
328
|
+
const item = value[i];
|
|
329
|
+
if (!isDefined(item)) continue;
|
|
330
|
+
if (isString(item)) {
|
|
331
|
+
if (!isBlank(item)) {
|
|
332
|
+
const subRecord = {
|
|
333
|
+
v: item,
|
|
334
|
+
i,
|
|
335
|
+
n: this.norm.get(item)
|
|
336
|
+
};
|
|
337
|
+
subRecords.push(subRecord);
|
|
338
|
+
}
|
|
339
|
+
} else if (isDefined(item.v)) {
|
|
340
|
+
const text = isString(item.v) ? item.v : toString(item.v);
|
|
341
|
+
if (!isBlank(text)) {
|
|
342
|
+
const subRecord = {
|
|
343
|
+
v: text,
|
|
344
|
+
i: item.i,
|
|
345
|
+
n: this.norm.get(text)
|
|
346
|
+
};
|
|
347
|
+
subRecords.push(subRecord);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
record.$[keyIndex] = subRecords;
|
|
352
|
+
} else if (isString(value) && !isBlank(value)) {
|
|
353
|
+
const subRecord = {
|
|
354
|
+
v: value,
|
|
355
|
+
n: this.norm.get(value)
|
|
356
|
+
};
|
|
357
|
+
record.$[keyIndex] = subRecord;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return record;
|
|
361
|
+
}
|
|
362
|
+
toJSON() {
|
|
363
|
+
return {
|
|
364
|
+
keys: this.keys.map(({ getFn, ...key }) => key),
|
|
365
|
+
records: this.records
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
370
|
+
const myIndex = new FuseIndex({
|
|
371
|
+
getFn,
|
|
372
|
+
fieldNormWeight
|
|
373
|
+
});
|
|
374
|
+
myIndex.setKeys(keys.map(createKey));
|
|
375
|
+
myIndex.setSources(docs);
|
|
376
|
+
myIndex.create();
|
|
377
|
+
return myIndex;
|
|
480
378
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
return myIndex
|
|
379
|
+
function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
380
|
+
const { keys, records } = data;
|
|
381
|
+
const myIndex = new FuseIndex({
|
|
382
|
+
getFn,
|
|
383
|
+
fieldNormWeight
|
|
384
|
+
});
|
|
385
|
+
myIndex.setKeys(keys);
|
|
386
|
+
myIndex.setIndexRecords(records);
|
|
387
|
+
return myIndex;
|
|
491
388
|
}
|
|
492
389
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
)
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
if (!distance) {
|
|
512
|
-
// Dodge divide by zero error.
|
|
513
|
-
return proximity ? 1.0 : accuracy
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
return accuracy + proximity / distance
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/search/bitap/convertMaskToIndices.ts
|
|
392
|
+
function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
|
|
393
|
+
const indices = [];
|
|
394
|
+
let start = -1;
|
|
395
|
+
let end = -1;
|
|
396
|
+
let i = 0;
|
|
397
|
+
for (let len = matchmask.length; i < len; i += 1) {
|
|
398
|
+
const match = matchmask[i];
|
|
399
|
+
if (match && start === -1) start = i;
|
|
400
|
+
else if (!match && start !== -1) {
|
|
401
|
+
end = i - 1;
|
|
402
|
+
if (end - start + 1 >= minMatchCharLength) indices.push([start, end]);
|
|
403
|
+
start = -1;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (matchmask[i - 1] && i - start >= minMatchCharLength) indices.push([start, i - 1]);
|
|
407
|
+
return indices;
|
|
517
408
|
}
|
|
518
409
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
)
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
)
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
while (i < patternLen) {
|
|
603
|
-
matchMask[index + i] = 1;
|
|
604
|
-
i += 1;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
// Reset the best location
|
|
610
|
-
bestLocation = -1;
|
|
611
|
-
|
|
612
|
-
let lastBitArr = [];
|
|
613
|
-
let finalScore = 1;
|
|
614
|
-
let binMax = patternLen + textLen;
|
|
615
|
-
|
|
616
|
-
const mask = 1 << (patternLen - 1);
|
|
617
|
-
|
|
618
|
-
for (let i = 0; i < patternLen; i += 1) {
|
|
619
|
-
// Scan for the best match; each iteration allows for one more error.
|
|
620
|
-
// Run a binary search to determine how far from the match location we can stray
|
|
621
|
-
// at this error level.
|
|
622
|
-
let binMin = 0;
|
|
623
|
-
let binMid = binMax;
|
|
624
|
-
|
|
625
|
-
while (binMin < binMid) {
|
|
626
|
-
const score = computeScore$1(pattern, {
|
|
627
|
-
errors: i,
|
|
628
|
-
currentLocation: expectedLocation + binMid,
|
|
629
|
-
expectedLocation,
|
|
630
|
-
distance,
|
|
631
|
-
ignoreLocation
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
if (score <= currentThreshold) {
|
|
635
|
-
binMin = binMid;
|
|
636
|
-
} else {
|
|
637
|
-
binMax = binMid;
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
// Use the result from this iteration as the maximum for the next.
|
|
644
|
-
binMax = binMid;
|
|
645
|
-
|
|
646
|
-
let start = Math.max(1, expectedLocation - binMid + 1);
|
|
647
|
-
let finish = findAllMatches
|
|
648
|
-
? textLen
|
|
649
|
-
: Math.min(expectedLocation + binMid, textLen) + patternLen;
|
|
650
|
-
|
|
651
|
-
// Initialize the bit array
|
|
652
|
-
let bitArr = Array(finish + 2);
|
|
653
|
-
|
|
654
|
-
bitArr[finish + 1] = (1 << i) - 1;
|
|
655
|
-
|
|
656
|
-
for (let j = finish; j >= start; j -= 1) {
|
|
657
|
-
let currentLocation = j - 1;
|
|
658
|
-
let charMatch = patternAlphabet[text.charAt(currentLocation)];
|
|
659
|
-
|
|
660
|
-
if (computeMatches) {
|
|
661
|
-
// Speed up: quick bool to int conversion (i.e, `charMatch ? 1 : 0`)
|
|
662
|
-
matchMask[currentLocation] = +!!charMatch;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
// First pass: exact match
|
|
666
|
-
bitArr[j] = ((bitArr[j + 1] << 1) | 1) & charMatch;
|
|
667
|
-
|
|
668
|
-
// Subsequent passes: fuzzy match
|
|
669
|
-
if (i) {
|
|
670
|
-
bitArr[j] |=
|
|
671
|
-
((lastBitArr[j + 1] | lastBitArr[j]) << 1) | 1 | lastBitArr[j + 1];
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
if (bitArr[j] & mask) {
|
|
675
|
-
finalScore = computeScore$1(pattern, {
|
|
676
|
-
errors: i,
|
|
677
|
-
currentLocation,
|
|
678
|
-
expectedLocation,
|
|
679
|
-
distance,
|
|
680
|
-
ignoreLocation
|
|
681
|
-
});
|
|
682
|
-
|
|
683
|
-
// This match will almost certainly be better than any existing match.
|
|
684
|
-
// But check anyway.
|
|
685
|
-
if (finalScore <= currentThreshold) {
|
|
686
|
-
// Indeed it is
|
|
687
|
-
currentThreshold = finalScore;
|
|
688
|
-
bestLocation = currentLocation;
|
|
689
|
-
|
|
690
|
-
// Already passed `loc`, downhill from here on in.
|
|
691
|
-
if (bestLocation <= expectedLocation) {
|
|
692
|
-
break
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
// When passing `bestLocation`, don't exceed our current distance from `expectedLocation`.
|
|
696
|
-
start = Math.max(1, 2 * expectedLocation - bestLocation);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
// No hope for a (better) match at greater error levels.
|
|
702
|
-
const score = computeScore$1(pattern, {
|
|
703
|
-
errors: i + 1,
|
|
704
|
-
currentLocation: expectedLocation,
|
|
705
|
-
expectedLocation,
|
|
706
|
-
distance,
|
|
707
|
-
ignoreLocation
|
|
708
|
-
});
|
|
709
|
-
|
|
710
|
-
if (score > currentThreshold) {
|
|
711
|
-
break
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
lastBitArr = bitArr;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
const result = {
|
|
718
|
-
isMatch: bestLocation >= 0,
|
|
719
|
-
// Count exact matches (those with a score of 0) to be "almost" exact
|
|
720
|
-
score: Math.max(0.001, finalScore)
|
|
721
|
-
};
|
|
722
|
-
|
|
723
|
-
if (computeMatches) {
|
|
724
|
-
const indices = convertMaskToIndices(matchMask, minMatchCharLength);
|
|
725
|
-
if (!indices.length) {
|
|
726
|
-
result.isMatch = false;
|
|
727
|
-
} else if (includeMatches) {
|
|
728
|
-
result.indices = indices;
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
return result
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region src/search/bitap/search.ts
|
|
412
|
+
function search(text, pattern, patternAlphabet, { location = Config.location, distance = Config.distance, threshold = Config.threshold, findAllMatches = Config.findAllMatches, minMatchCharLength = Config.minMatchCharLength, includeMatches = Config.includeMatches, ignoreLocation = Config.ignoreLocation } = {}) {
|
|
413
|
+
if (pattern.length > 32) throw new Error(PATTERN_LENGTH_TOO_LARGE(32));
|
|
414
|
+
const patternLen = pattern.length;
|
|
415
|
+
const textLen = text.length;
|
|
416
|
+
const expectedLocation = Math.max(0, Math.min(location, textLen));
|
|
417
|
+
let currentThreshold = threshold;
|
|
418
|
+
let bestLocation = expectedLocation;
|
|
419
|
+
const calcScore = (errors, currentLocation) => {
|
|
420
|
+
const accuracy = errors / patternLen;
|
|
421
|
+
if (ignoreLocation) return accuracy;
|
|
422
|
+
const proximity = Math.abs(expectedLocation - currentLocation);
|
|
423
|
+
if (!distance) return proximity ? 1 : accuracy;
|
|
424
|
+
return accuracy + proximity / distance;
|
|
425
|
+
};
|
|
426
|
+
const computeMatches = minMatchCharLength > 1 || includeMatches;
|
|
427
|
+
const matchMask = computeMatches ? Array(textLen) : [];
|
|
428
|
+
let index;
|
|
429
|
+
while ((index = text.indexOf(pattern, bestLocation)) > -1) {
|
|
430
|
+
const score = calcScore(0, index);
|
|
431
|
+
currentThreshold = Math.min(score, currentThreshold);
|
|
432
|
+
bestLocation = index + patternLen;
|
|
433
|
+
if (computeMatches) {
|
|
434
|
+
let i = 0;
|
|
435
|
+
while (i < patternLen) {
|
|
436
|
+
matchMask[index + i] = 1;
|
|
437
|
+
i += 1;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
bestLocation = -1;
|
|
442
|
+
let lastBitArr = [];
|
|
443
|
+
let finalScore = 1;
|
|
444
|
+
let bestErrors = 0;
|
|
445
|
+
let binMax = patternLen + textLen;
|
|
446
|
+
const mask = 1 << patternLen - 1;
|
|
447
|
+
for (let i = 0; i < patternLen; i += 1) {
|
|
448
|
+
let binMin = 0;
|
|
449
|
+
let binMid = binMax;
|
|
450
|
+
while (binMin < binMid) {
|
|
451
|
+
if (calcScore(i, expectedLocation + binMid) <= currentThreshold) binMin = binMid;
|
|
452
|
+
else binMax = binMid;
|
|
453
|
+
binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
454
|
+
}
|
|
455
|
+
binMax = binMid;
|
|
456
|
+
let start = Math.max(1, expectedLocation - binMid + 1);
|
|
457
|
+
const finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
|
|
458
|
+
const bitArr = Array(finish + 2);
|
|
459
|
+
bitArr[finish + 1] = (1 << i) - 1;
|
|
460
|
+
for (let j = finish; j >= start; j -= 1) {
|
|
461
|
+
const currentLocation = j - 1;
|
|
462
|
+
const charMatch = patternAlphabet[text[currentLocation]];
|
|
463
|
+
bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
|
|
464
|
+
if (i) bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
|
|
465
|
+
if (bitArr[j] & mask) {
|
|
466
|
+
finalScore = calcScore(i, currentLocation);
|
|
467
|
+
if (finalScore <= currentThreshold) {
|
|
468
|
+
currentThreshold = finalScore;
|
|
469
|
+
bestLocation = currentLocation;
|
|
470
|
+
bestErrors = i;
|
|
471
|
+
if (bestLocation <= expectedLocation) break;
|
|
472
|
+
start = Math.max(1, 2 * expectedLocation - bestLocation);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (calcScore(i + 1, expectedLocation) > currentThreshold) break;
|
|
477
|
+
lastBitArr = bitArr;
|
|
478
|
+
}
|
|
479
|
+
if (computeMatches && bestLocation >= 0) {
|
|
480
|
+
const matchEnd = Math.min(textLen - 1, bestLocation + patternLen - 1 + bestErrors);
|
|
481
|
+
for (let k = bestLocation; k <= matchEnd; k += 1) if (patternAlphabet[text[k]]) matchMask[k] = 1;
|
|
482
|
+
}
|
|
483
|
+
const result = {
|
|
484
|
+
isMatch: bestLocation >= 0,
|
|
485
|
+
score: Math.max(.001, finalScore)
|
|
486
|
+
};
|
|
487
|
+
if (computeMatches) {
|
|
488
|
+
const indices = convertMaskToIndices(matchMask, minMatchCharLength);
|
|
489
|
+
if (!indices.length) result.isMatch = false;
|
|
490
|
+
else if (includeMatches) result.indices = indices;
|
|
491
|
+
}
|
|
492
|
+
return result;
|
|
733
493
|
}
|
|
734
494
|
|
|
495
|
+
//#endregion
|
|
496
|
+
//#region src/search/bitap/createPatternAlphabet.ts
|
|
735
497
|
function createPatternAlphabet(pattern) {
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
return mask
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
const stripDiacritics = String.prototype.normalize
|
|
747
|
-
? ((str) => str.normalize('NFD').replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g, ''))
|
|
748
|
-
: ((str) => str);
|
|
749
|
-
|
|
750
|
-
class BitapSearch {
|
|
751
|
-
constructor(
|
|
752
|
-
pattern,
|
|
753
|
-
{
|
|
754
|
-
location = Config.location,
|
|
755
|
-
threshold = Config.threshold,
|
|
756
|
-
distance = Config.distance,
|
|
757
|
-
includeMatches = Config.includeMatches,
|
|
758
|
-
findAllMatches = Config.findAllMatches,
|
|
759
|
-
minMatchCharLength = Config.minMatchCharLength,
|
|
760
|
-
isCaseSensitive = Config.isCaseSensitive,
|
|
761
|
-
ignoreDiacritics = Config.ignoreDiacritics,
|
|
762
|
-
ignoreLocation = Config.ignoreLocation
|
|
763
|
-
} = {}
|
|
764
|
-
) {
|
|
765
|
-
this.options = {
|
|
766
|
-
location,
|
|
767
|
-
threshold,
|
|
768
|
-
distance,
|
|
769
|
-
includeMatches,
|
|
770
|
-
findAllMatches,
|
|
771
|
-
minMatchCharLength,
|
|
772
|
-
isCaseSensitive,
|
|
773
|
-
ignoreDiacritics,
|
|
774
|
-
ignoreLocation
|
|
775
|
-
};
|
|
776
|
-
|
|
777
|
-
pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
778
|
-
pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
|
|
779
|
-
this.pattern = pattern;
|
|
780
|
-
|
|
781
|
-
this.chunks = [];
|
|
782
|
-
|
|
783
|
-
if (!this.pattern.length) {
|
|
784
|
-
return
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
const addChunk = (pattern, startIndex) => {
|
|
788
|
-
this.chunks.push({
|
|
789
|
-
pattern,
|
|
790
|
-
alphabet: createPatternAlphabet(pattern),
|
|
791
|
-
startIndex
|
|
792
|
-
});
|
|
793
|
-
};
|
|
794
|
-
|
|
795
|
-
const len = this.pattern.length;
|
|
796
|
-
|
|
797
|
-
if (len > MAX_BITS) {
|
|
798
|
-
let i = 0;
|
|
799
|
-
const remainder = len % MAX_BITS;
|
|
800
|
-
const end = len - remainder;
|
|
801
|
-
|
|
802
|
-
while (i < end) {
|
|
803
|
-
addChunk(this.pattern.substr(i, MAX_BITS), i);
|
|
804
|
-
i += MAX_BITS;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
if (remainder) {
|
|
808
|
-
const startIndex = len - MAX_BITS;
|
|
809
|
-
addChunk(this.pattern.substr(startIndex), startIndex);
|
|
810
|
-
}
|
|
811
|
-
} else {
|
|
812
|
-
addChunk(this.pattern, 0);
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
searchIn(text) {
|
|
817
|
-
const { isCaseSensitive, ignoreDiacritics, includeMatches } = this.options;
|
|
818
|
-
|
|
819
|
-
text = isCaseSensitive ? text : text.toLowerCase();
|
|
820
|
-
text = ignoreDiacritics ? stripDiacritics(text) : text;
|
|
821
|
-
|
|
822
|
-
// Exact match
|
|
823
|
-
if (this.pattern === text) {
|
|
824
|
-
let result = {
|
|
825
|
-
isMatch: true,
|
|
826
|
-
score: 0
|
|
827
|
-
};
|
|
828
|
-
|
|
829
|
-
if (includeMatches) {
|
|
830
|
-
result.indices = [[0, text.length - 1]];
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
return result
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
// Otherwise, use Bitap algorithm
|
|
837
|
-
const {
|
|
838
|
-
location,
|
|
839
|
-
distance,
|
|
840
|
-
threshold,
|
|
841
|
-
findAllMatches,
|
|
842
|
-
minMatchCharLength,
|
|
843
|
-
ignoreLocation
|
|
844
|
-
} = this.options;
|
|
845
|
-
|
|
846
|
-
let allIndices = [];
|
|
847
|
-
let totalScore = 0;
|
|
848
|
-
let hasMatches = false;
|
|
849
|
-
|
|
850
|
-
this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
|
|
851
|
-
const { isMatch, score, indices } = search(text, pattern, alphabet, {
|
|
852
|
-
location: location + startIndex,
|
|
853
|
-
distance,
|
|
854
|
-
threshold,
|
|
855
|
-
findAllMatches,
|
|
856
|
-
minMatchCharLength,
|
|
857
|
-
includeMatches,
|
|
858
|
-
ignoreLocation
|
|
859
|
-
});
|
|
860
|
-
|
|
861
|
-
if (isMatch) {
|
|
862
|
-
hasMatches = true;
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
totalScore += score;
|
|
866
|
-
|
|
867
|
-
if (isMatch && indices) {
|
|
868
|
-
allIndices = [...allIndices, ...indices];
|
|
869
|
-
}
|
|
870
|
-
});
|
|
871
|
-
|
|
872
|
-
let result = {
|
|
873
|
-
isMatch: hasMatches,
|
|
874
|
-
score: hasMatches ? totalScore / this.chunks.length : 1
|
|
875
|
-
};
|
|
876
|
-
|
|
877
|
-
if (hasMatches && includeMatches) {
|
|
878
|
-
result.indices = allIndices;
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
return result
|
|
882
|
-
}
|
|
498
|
+
const mask = {};
|
|
499
|
+
for (let i = 0, len = pattern.length; i < len; i += 1) {
|
|
500
|
+
const char = pattern.charAt(i);
|
|
501
|
+
mask[char] = (mask[char] || 0) | 1 << len - i - 1;
|
|
502
|
+
}
|
|
503
|
+
return mask;
|
|
883
504
|
}
|
|
884
505
|
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
506
|
+
//#endregion
|
|
507
|
+
//#region src/helpers/mergeIndices.ts
|
|
508
|
+
function mergeIndices(indices) {
|
|
509
|
+
if (indices.length <= 1) return indices;
|
|
510
|
+
indices.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
511
|
+
const merged = [indices[0]];
|
|
512
|
+
for (let i = 1, len = indices.length; i < len; i += 1) {
|
|
513
|
+
const last = merged[merged.length - 1];
|
|
514
|
+
const curr = indices[i];
|
|
515
|
+
if (curr[0] <= last[1] + 1) last[1] = Math.max(last[1], curr[1]);
|
|
516
|
+
else merged.push(curr);
|
|
517
|
+
}
|
|
518
|
+
return merged;
|
|
896
519
|
}
|
|
897
520
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
search(text) {
|
|
998
|
-
const isMatch = !text.startsWith(this.pattern);
|
|
999
|
-
|
|
1000
|
-
return {
|
|
1001
|
-
isMatch,
|
|
1002
|
-
score: isMatch ? 0 : 1,
|
|
1003
|
-
indices: [0, text.length - 1]
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
// Token: .file$
|
|
1009
|
-
|
|
1010
|
-
class SuffixExactMatch extends BaseMatch {
|
|
1011
|
-
constructor(pattern) {
|
|
1012
|
-
super(pattern);
|
|
1013
|
-
}
|
|
1014
|
-
static get type() {
|
|
1015
|
-
return 'suffix-exact'
|
|
1016
|
-
}
|
|
1017
|
-
static get multiRegex() {
|
|
1018
|
-
return /^"(.*)"\$$/
|
|
1019
|
-
}
|
|
1020
|
-
static get singleRegex() {
|
|
1021
|
-
return /^(.*)\$$/
|
|
1022
|
-
}
|
|
1023
|
-
search(text) {
|
|
1024
|
-
const isMatch = text.endsWith(this.pattern);
|
|
1025
|
-
|
|
1026
|
-
return {
|
|
1027
|
-
isMatch,
|
|
1028
|
-
score: isMatch ? 0 : 1,
|
|
1029
|
-
indices: [text.length - this.pattern.length, text.length - 1]
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
// Token: !.file$
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/helpers/diacritics.ts
|
|
523
|
+
const NON_DECOMPOSABLE_MAP = {
|
|
524
|
+
"ł": "l",
|
|
525
|
+
"Ł": "L",
|
|
526
|
+
"đ": "d",
|
|
527
|
+
"Đ": "D",
|
|
528
|
+
"ø": "o",
|
|
529
|
+
"Ø": "O",
|
|
530
|
+
"ħ": "h",
|
|
531
|
+
"Ħ": "H",
|
|
532
|
+
"ŧ": "t",
|
|
533
|
+
"Ŧ": "T",
|
|
534
|
+
"ı": "i",
|
|
535
|
+
"ß": "ss"
|
|
536
|
+
};
|
|
537
|
+
const NON_DECOMPOSABLE_RE = new RegExp("[" + Object.keys(NON_DECOMPOSABLE_MAP).join("") + "]", "g");
|
|
538
|
+
const stripDiacritics = typeof String.prototype.normalize === "function" ? (str) => str.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g, "").replace(NON_DECOMPOSABLE_RE, (ch) => NON_DECOMPOSABLE_MAP[ch]) : (str) => str;
|
|
539
|
+
|
|
540
|
+
//#endregion
|
|
541
|
+
//#region src/search/bitap/index.ts
|
|
542
|
+
var BitapSearch = class {
|
|
543
|
+
constructor(pattern, { location = Config.location, threshold = Config.threshold, distance = Config.distance, includeMatches = Config.includeMatches, findAllMatches = Config.findAllMatches, minMatchCharLength = Config.minMatchCharLength, isCaseSensitive = Config.isCaseSensitive, ignoreDiacritics = Config.ignoreDiacritics, ignoreLocation = Config.ignoreLocation } = {}) {
|
|
544
|
+
this.options = {
|
|
545
|
+
location,
|
|
546
|
+
threshold,
|
|
547
|
+
distance,
|
|
548
|
+
includeMatches,
|
|
549
|
+
findAllMatches,
|
|
550
|
+
minMatchCharLength,
|
|
551
|
+
isCaseSensitive,
|
|
552
|
+
ignoreDiacritics,
|
|
553
|
+
ignoreLocation
|
|
554
|
+
};
|
|
555
|
+
pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
556
|
+
pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
|
|
557
|
+
this.pattern = pattern;
|
|
558
|
+
this.chunks = [];
|
|
559
|
+
if (!this.pattern.length) return;
|
|
560
|
+
const addChunk = (pattern, startIndex) => {
|
|
561
|
+
this.chunks.push({
|
|
562
|
+
pattern,
|
|
563
|
+
alphabet: createPatternAlphabet(pattern),
|
|
564
|
+
startIndex
|
|
565
|
+
});
|
|
566
|
+
};
|
|
567
|
+
const len = this.pattern.length;
|
|
568
|
+
if (len > 32) {
|
|
569
|
+
let i = 0;
|
|
570
|
+
const remainder = len % 32;
|
|
571
|
+
const end = len - remainder;
|
|
572
|
+
while (i < end) {
|
|
573
|
+
addChunk(this.pattern.substr(i, 32), i);
|
|
574
|
+
i += 32;
|
|
575
|
+
}
|
|
576
|
+
if (remainder) {
|
|
577
|
+
const startIndex = len - 32;
|
|
578
|
+
addChunk(this.pattern.substr(startIndex), startIndex);
|
|
579
|
+
}
|
|
580
|
+
} else addChunk(this.pattern, 0);
|
|
581
|
+
}
|
|
582
|
+
searchIn(text) {
|
|
583
|
+
const { isCaseSensitive, ignoreDiacritics, includeMatches } = this.options;
|
|
584
|
+
text = isCaseSensitive ? text : text.toLowerCase();
|
|
585
|
+
text = ignoreDiacritics ? stripDiacritics(text) : text;
|
|
586
|
+
if (this.pattern === text) {
|
|
587
|
+
const result = {
|
|
588
|
+
isMatch: true,
|
|
589
|
+
score: 0
|
|
590
|
+
};
|
|
591
|
+
if (includeMatches) result.indices = [[0, text.length - 1]];
|
|
592
|
+
return result;
|
|
593
|
+
}
|
|
594
|
+
const { location, distance, threshold, findAllMatches, minMatchCharLength, ignoreLocation } = this.options;
|
|
595
|
+
const allIndices = [];
|
|
596
|
+
let totalScore = 0;
|
|
597
|
+
let hasMatches = false;
|
|
598
|
+
this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
|
|
599
|
+
const { isMatch, score, indices } = search(text, pattern, alphabet, {
|
|
600
|
+
location: location + startIndex,
|
|
601
|
+
distance,
|
|
602
|
+
threshold,
|
|
603
|
+
findAllMatches,
|
|
604
|
+
minMatchCharLength,
|
|
605
|
+
includeMatches,
|
|
606
|
+
ignoreLocation
|
|
607
|
+
});
|
|
608
|
+
if (isMatch) hasMatches = true;
|
|
609
|
+
totalScore += score;
|
|
610
|
+
if (isMatch && indices) allIndices.push(...indices);
|
|
611
|
+
});
|
|
612
|
+
const result = {
|
|
613
|
+
isMatch: hasMatches,
|
|
614
|
+
score: hasMatches ? totalScore / this.chunks.length : 1
|
|
615
|
+
};
|
|
616
|
+
if (hasMatches && includeMatches) result.indices = mergeIndices(allIndices);
|
|
617
|
+
return result;
|
|
618
|
+
}
|
|
619
|
+
};
|
|
1035
620
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
return 'inverse-suffix-exact'
|
|
1042
|
-
}
|
|
1043
|
-
static get multiRegex() {
|
|
1044
|
-
return /^!"(.*)"\$$/
|
|
1045
|
-
}
|
|
1046
|
-
static get singleRegex() {
|
|
1047
|
-
return /^!(.*)\$$/
|
|
1048
|
-
}
|
|
1049
|
-
search(text) {
|
|
1050
|
-
const isMatch = !text.endsWith(this.pattern);
|
|
1051
|
-
return {
|
|
1052
|
-
isMatch,
|
|
1053
|
-
score: isMatch ? 0 : 1,
|
|
1054
|
-
indices: [0, text.length - 1]
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/search/extended/matchers.ts
|
|
623
|
+
const MULTI_MATCH_TYPES = new Set(["fuzzy", "include"]);
|
|
624
|
+
function isInverse(type) {
|
|
625
|
+
return type.startsWith("inverse");
|
|
1057
626
|
}
|
|
627
|
+
const matchers = [
|
|
628
|
+
{
|
|
629
|
+
type: "exact",
|
|
630
|
+
multiRegex: /^="(.*)"$/,
|
|
631
|
+
singleRegex: /^=(.*)$/,
|
|
632
|
+
create: (pattern) => ({
|
|
633
|
+
type: "exact",
|
|
634
|
+
search(text) {
|
|
635
|
+
const isMatch = text === pattern;
|
|
636
|
+
return {
|
|
637
|
+
isMatch,
|
|
638
|
+
score: isMatch ? 0 : 1,
|
|
639
|
+
indices: [0, pattern.length - 1]
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
})
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
type: "include",
|
|
646
|
+
multiRegex: /^'"(.*)"$/,
|
|
647
|
+
singleRegex: /^'(.*)$/,
|
|
648
|
+
create: (pattern) => ({
|
|
649
|
+
type: "include",
|
|
650
|
+
search(text) {
|
|
651
|
+
let location = 0;
|
|
652
|
+
let index;
|
|
653
|
+
const indices = [];
|
|
654
|
+
const patternLen = pattern.length;
|
|
655
|
+
while ((index = text.indexOf(pattern, location)) > -1) {
|
|
656
|
+
location = index + patternLen;
|
|
657
|
+
indices.push([index, location - 1]);
|
|
658
|
+
}
|
|
659
|
+
const isMatch = !!indices.length;
|
|
660
|
+
return {
|
|
661
|
+
isMatch,
|
|
662
|
+
score: isMatch ? 0 : 1,
|
|
663
|
+
indices
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
})
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
type: "prefix-exact",
|
|
670
|
+
multiRegex: /^\^"(.*)"$/,
|
|
671
|
+
singleRegex: /^\^(.*)$/,
|
|
672
|
+
create: (pattern) => ({
|
|
673
|
+
type: "prefix-exact",
|
|
674
|
+
search(text) {
|
|
675
|
+
const isMatch = text.startsWith(pattern);
|
|
676
|
+
return {
|
|
677
|
+
isMatch,
|
|
678
|
+
score: isMatch ? 0 : 1,
|
|
679
|
+
indices: [0, pattern.length - 1]
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
})
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
type: "inverse-prefix-exact",
|
|
686
|
+
multiRegex: /^!\^"(.*)"$/,
|
|
687
|
+
singleRegex: /^!\^(.*)$/,
|
|
688
|
+
create: (pattern) => ({
|
|
689
|
+
type: "inverse-prefix-exact",
|
|
690
|
+
search(text) {
|
|
691
|
+
const isMatch = !text.startsWith(pattern);
|
|
692
|
+
return {
|
|
693
|
+
isMatch,
|
|
694
|
+
score: isMatch ? 0 : 1,
|
|
695
|
+
indices: [0, text.length - 1]
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
})
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
type: "inverse-suffix-exact",
|
|
702
|
+
multiRegex: /^!"(.*)"\$$/,
|
|
703
|
+
singleRegex: /^!(.*)\$$/,
|
|
704
|
+
create: (pattern) => ({
|
|
705
|
+
type: "inverse-suffix-exact",
|
|
706
|
+
search(text) {
|
|
707
|
+
const isMatch = !text.endsWith(pattern);
|
|
708
|
+
return {
|
|
709
|
+
isMatch,
|
|
710
|
+
score: isMatch ? 0 : 1,
|
|
711
|
+
indices: [0, text.length - 1]
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
})
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
type: "suffix-exact",
|
|
718
|
+
multiRegex: /^"(.*)"\$$/,
|
|
719
|
+
singleRegex: /^(.*)\$$/,
|
|
720
|
+
create: (pattern) => ({
|
|
721
|
+
type: "suffix-exact",
|
|
722
|
+
search(text) {
|
|
723
|
+
const isMatch = text.endsWith(pattern);
|
|
724
|
+
return {
|
|
725
|
+
isMatch,
|
|
726
|
+
score: isMatch ? 0 : 1,
|
|
727
|
+
indices: [text.length - pattern.length, text.length - 1]
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
})
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
type: "inverse-exact",
|
|
734
|
+
multiRegex: /^!"(.*)"$/,
|
|
735
|
+
singleRegex: /^!(.*)$/,
|
|
736
|
+
create: (pattern) => ({
|
|
737
|
+
type: "inverse-exact",
|
|
738
|
+
search(text) {
|
|
739
|
+
const isMatch = text.indexOf(pattern) === -1;
|
|
740
|
+
return {
|
|
741
|
+
isMatch,
|
|
742
|
+
score: isMatch ? 0 : 1,
|
|
743
|
+
indices: [0, text.length - 1]
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
})
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
type: "fuzzy",
|
|
750
|
+
multiRegex: /^"(.*)"$/,
|
|
751
|
+
singleRegex: /^(.*)$/,
|
|
752
|
+
create: (pattern, options = {}) => {
|
|
753
|
+
const bitap = new BitapSearch(pattern, {
|
|
754
|
+
location: options.location ?? Config.location,
|
|
755
|
+
threshold: options.threshold ?? Config.threshold,
|
|
756
|
+
distance: options.distance ?? Config.distance,
|
|
757
|
+
includeMatches: options.includeMatches ?? Config.includeMatches,
|
|
758
|
+
findAllMatches: options.findAllMatches ?? Config.findAllMatches,
|
|
759
|
+
minMatchCharLength: options.minMatchCharLength ?? Config.minMatchCharLength,
|
|
760
|
+
isCaseSensitive: options.isCaseSensitive ?? Config.isCaseSensitive,
|
|
761
|
+
ignoreDiacritics: options.ignoreDiacritics ?? Config.ignoreDiacritics,
|
|
762
|
+
ignoreLocation: options.ignoreLocation ?? Config.ignoreLocation
|
|
763
|
+
});
|
|
764
|
+
return {
|
|
765
|
+
type: "fuzzy",
|
|
766
|
+
search(text) {
|
|
767
|
+
return bitap.searchIn(text);
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
];
|
|
1058
773
|
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
}
|
|
774
|
+
//#endregion
|
|
775
|
+
//#region src/search/extended/parseQuery.ts
|
|
776
|
+
const matchersLen = matchers.length;
|
|
777
|
+
const ESCAPED_PIPE = "\0";
|
|
778
|
+
const OR_TOKEN = "|";
|
|
779
|
+
function tokenize(pattern) {
|
|
780
|
+
const tokens = [];
|
|
781
|
+
const len = pattern.length;
|
|
782
|
+
let i = 0;
|
|
783
|
+
while (i < len) {
|
|
784
|
+
while (i < len && pattern[i] === " ") i++;
|
|
785
|
+
if (i >= len) break;
|
|
786
|
+
let j = i;
|
|
787
|
+
while (j < len && pattern[j] !== " " && pattern[j] !== "\"") j++;
|
|
788
|
+
if (j < len && pattern[j] === "\"") {
|
|
789
|
+
j++;
|
|
790
|
+
while (j < len) {
|
|
791
|
+
if (pattern[j] === "\"") {
|
|
792
|
+
const next = j + 1;
|
|
793
|
+
if (next >= len || pattern[next] === " ") {
|
|
794
|
+
j++;
|
|
795
|
+
break;
|
|
796
|
+
}
|
|
797
|
+
if (pattern[next] === "$" && (next + 1 >= len || pattern[next + 1] === " ")) {
|
|
798
|
+
j += 2;
|
|
799
|
+
break;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
j++;
|
|
803
|
+
}
|
|
804
|
+
tokens.push(pattern.substring(i, j));
|
|
805
|
+
i = j;
|
|
806
|
+
} else {
|
|
807
|
+
while (j < len && pattern[j] !== " ") j++;
|
|
808
|
+
tokens.push(pattern.substring(i, j));
|
|
809
|
+
i = j;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
return tokens;
|
|
1099
813
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
class IncludeMatch extends BaseMatch {
|
|
1104
|
-
constructor(pattern) {
|
|
1105
|
-
super(pattern);
|
|
1106
|
-
}
|
|
1107
|
-
static get type() {
|
|
1108
|
-
return 'include'
|
|
1109
|
-
}
|
|
1110
|
-
static get multiRegex() {
|
|
1111
|
-
return /^'"(.*)"$/
|
|
1112
|
-
}
|
|
1113
|
-
static get singleRegex() {
|
|
1114
|
-
return /^'(.*)$/
|
|
1115
|
-
}
|
|
1116
|
-
search(text) {
|
|
1117
|
-
let location = 0;
|
|
1118
|
-
let index;
|
|
1119
|
-
|
|
1120
|
-
const indices = [];
|
|
1121
|
-
const patternLen = this.pattern.length;
|
|
1122
|
-
|
|
1123
|
-
// Get all exact matches
|
|
1124
|
-
while ((index = text.indexOf(this.pattern, location)) > -1) {
|
|
1125
|
-
location = index + patternLen;
|
|
1126
|
-
indices.push([index, location - 1]);
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
const isMatch = !!indices.length;
|
|
1130
|
-
|
|
1131
|
-
return {
|
|
1132
|
-
isMatch,
|
|
1133
|
-
score: isMatch ? 0 : 1,
|
|
1134
|
-
indices
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
814
|
+
function getMatch(pattern, exp) {
|
|
815
|
+
const matches = pattern.match(exp);
|
|
816
|
+
return matches ? matches[1] : null;
|
|
1137
817
|
}
|
|
1138
|
-
|
|
1139
|
-
// ❗Order is important. DO NOT CHANGE.
|
|
1140
|
-
const searchers = [
|
|
1141
|
-
ExactMatch,
|
|
1142
|
-
IncludeMatch,
|
|
1143
|
-
PrefixExactMatch,
|
|
1144
|
-
InversePrefixExactMatch,
|
|
1145
|
-
InverseSuffixExactMatch,
|
|
1146
|
-
SuffixExactMatch,
|
|
1147
|
-
InverseExactMatch,
|
|
1148
|
-
FuzzyMatch
|
|
1149
|
-
];
|
|
1150
|
-
|
|
1151
|
-
const searchersLen = searchers.length;
|
|
1152
|
-
|
|
1153
|
-
// Regex to split by spaces, but keep anything in quotes together
|
|
1154
|
-
const SPACE_RE = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/;
|
|
1155
|
-
const OR_TOKEN = '|';
|
|
1156
|
-
|
|
1157
|
-
// Return a 2D array representation of the query, for simpler parsing.
|
|
1158
|
-
// Example:
|
|
1159
|
-
// "^core go$ | rb$ | py$ xy$" => [["^core", "go$"], ["rb$"], ["py$", "xy$"]]
|
|
1160
818
|
function parseQuery(pattern, options = {}) {
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
while (++idx < searchersLen) {
|
|
1190
|
-
const searcher = searchers[idx];
|
|
1191
|
-
let token = searcher.isSingleMatch(queryItem);
|
|
1192
|
-
if (token) {
|
|
1193
|
-
results.push(new searcher(token, options));
|
|
1194
|
-
break
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
return results
|
|
1200
|
-
})
|
|
819
|
+
return pattern.replace(/\\\|/g, ESCAPED_PIPE).split(OR_TOKEN).map((item) => {
|
|
820
|
+
const query = tokenize(item.replace(/\u0000/g, "|").trim()).filter((item) => item && !!item.trim());
|
|
821
|
+
const results = [];
|
|
822
|
+
for (let i = 0, len = query.length; i < len; i += 1) {
|
|
823
|
+
const queryItem = query[i];
|
|
824
|
+
let found = false;
|
|
825
|
+
let idx = -1;
|
|
826
|
+
while (!found && ++idx < matchersLen) {
|
|
827
|
+
const def = matchers[idx];
|
|
828
|
+
const token = getMatch(queryItem, def.multiRegex);
|
|
829
|
+
if (token) {
|
|
830
|
+
results.push(def.create(token, options));
|
|
831
|
+
found = true;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
if (found) continue;
|
|
835
|
+
idx = -1;
|
|
836
|
+
while (++idx < matchersLen) {
|
|
837
|
+
const def = matchers[idx];
|
|
838
|
+
const token = getMatch(queryItem, def.singleRegex);
|
|
839
|
+
if (token) {
|
|
840
|
+
results.push(def.create(token, options));
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
return results;
|
|
846
|
+
});
|
|
1201
847
|
}
|
|
1202
848
|
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
isMatch: false,
|
|
1279
|
-
score: 1
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
const { includeMatches, isCaseSensitive, ignoreDiacritics } = this.options;
|
|
1284
|
-
|
|
1285
|
-
text = isCaseSensitive ? text : text.toLowerCase();
|
|
1286
|
-
text = ignoreDiacritics ? stripDiacritics(text) : text;
|
|
1287
|
-
|
|
1288
|
-
let numMatches = 0;
|
|
1289
|
-
let allIndices = [];
|
|
1290
|
-
let totalScore = 0;
|
|
1291
|
-
|
|
1292
|
-
// ORs
|
|
1293
|
-
for (let i = 0, qLen = query.length; i < qLen; i += 1) {
|
|
1294
|
-
const searchers = query[i];
|
|
1295
|
-
|
|
1296
|
-
// Reset indices
|
|
1297
|
-
allIndices.length = 0;
|
|
1298
|
-
numMatches = 0;
|
|
1299
|
-
|
|
1300
|
-
// ANDs
|
|
1301
|
-
for (let j = 0, pLen = searchers.length; j < pLen; j += 1) {
|
|
1302
|
-
const searcher = searchers[j];
|
|
1303
|
-
const { isMatch, indices, score } = searcher.search(text);
|
|
1304
|
-
|
|
1305
|
-
if (isMatch) {
|
|
1306
|
-
numMatches += 1;
|
|
1307
|
-
totalScore += score;
|
|
1308
|
-
if (includeMatches) {
|
|
1309
|
-
const type = searcher.constructor.type;
|
|
1310
|
-
if (MultiMatchSet.has(type)) {
|
|
1311
|
-
allIndices = [...allIndices, ...indices];
|
|
1312
|
-
} else {
|
|
1313
|
-
allIndices.push(indices);
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
} else {
|
|
1317
|
-
totalScore = 0;
|
|
1318
|
-
numMatches = 0;
|
|
1319
|
-
allIndices.length = 0;
|
|
1320
|
-
break
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
// OR condition, so if TRUE, return
|
|
1325
|
-
if (numMatches) {
|
|
1326
|
-
let result = {
|
|
1327
|
-
isMatch: true,
|
|
1328
|
-
score: totalScore / numMatches
|
|
1329
|
-
};
|
|
1330
|
-
|
|
1331
|
-
if (includeMatches) {
|
|
1332
|
-
result.indices = allIndices;
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
return result
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
// Nothing was matched
|
|
1340
|
-
return {
|
|
1341
|
-
isMatch: false,
|
|
1342
|
-
score: 1
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
849
|
+
//#endregion
|
|
850
|
+
//#region src/search/extended/index.ts
|
|
851
|
+
var ExtendedSearch = class {
|
|
852
|
+
constructor(pattern, { isCaseSensitive = Config.isCaseSensitive, ignoreDiacritics = Config.ignoreDiacritics, includeMatches = Config.includeMatches, minMatchCharLength = Config.minMatchCharLength, ignoreLocation = Config.ignoreLocation, findAllMatches = Config.findAllMatches, location = Config.location, threshold = Config.threshold, distance = Config.distance } = {}) {
|
|
853
|
+
this.query = null;
|
|
854
|
+
this.options = {
|
|
855
|
+
isCaseSensitive,
|
|
856
|
+
ignoreDiacritics,
|
|
857
|
+
includeMatches,
|
|
858
|
+
minMatchCharLength,
|
|
859
|
+
findAllMatches,
|
|
860
|
+
ignoreLocation,
|
|
861
|
+
location,
|
|
862
|
+
threshold,
|
|
863
|
+
distance
|
|
864
|
+
};
|
|
865
|
+
pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
866
|
+
pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
|
|
867
|
+
this.pattern = pattern;
|
|
868
|
+
this.query = parseQuery(this.pattern, this.options);
|
|
869
|
+
}
|
|
870
|
+
static condition(_, options) {
|
|
871
|
+
return options.useExtendedSearch;
|
|
872
|
+
}
|
|
873
|
+
searchIn(text) {
|
|
874
|
+
const query = this.query;
|
|
875
|
+
if (!query) return {
|
|
876
|
+
isMatch: false,
|
|
877
|
+
score: 1
|
|
878
|
+
};
|
|
879
|
+
const { includeMatches, isCaseSensitive, ignoreDiacritics } = this.options;
|
|
880
|
+
text = isCaseSensitive ? text : text.toLowerCase();
|
|
881
|
+
text = ignoreDiacritics ? stripDiacritics(text) : text;
|
|
882
|
+
let numMatches = 0;
|
|
883
|
+
const allIndices = [];
|
|
884
|
+
let totalScore = 0;
|
|
885
|
+
let hasInverse = false;
|
|
886
|
+
for (let i = 0, qLen = query.length; i < qLen; i += 1) {
|
|
887
|
+
const searchers = query[i];
|
|
888
|
+
allIndices.length = 0;
|
|
889
|
+
numMatches = 0;
|
|
890
|
+
hasInverse = false;
|
|
891
|
+
for (let j = 0, pLen = searchers.length; j < pLen; j += 1) {
|
|
892
|
+
const matcher = searchers[j];
|
|
893
|
+
const { isMatch, indices, score } = matcher.search(text);
|
|
894
|
+
if (isMatch) {
|
|
895
|
+
numMatches += 1;
|
|
896
|
+
totalScore += score;
|
|
897
|
+
if (isInverse(matcher.type)) hasInverse = true;
|
|
898
|
+
if (includeMatches) if (MULTI_MATCH_TYPES.has(matcher.type)) allIndices.push(...indices);
|
|
899
|
+
else allIndices.push(indices);
|
|
900
|
+
} else {
|
|
901
|
+
totalScore = 0;
|
|
902
|
+
numMatches = 0;
|
|
903
|
+
allIndices.length = 0;
|
|
904
|
+
hasInverse = false;
|
|
905
|
+
break;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
if (numMatches) {
|
|
909
|
+
const result = {
|
|
910
|
+
isMatch: true,
|
|
911
|
+
score: totalScore / numMatches
|
|
912
|
+
};
|
|
913
|
+
if (hasInverse) result.hasInverse = true;
|
|
914
|
+
if (includeMatches) result.indices = mergeIndices(allIndices);
|
|
915
|
+
return result;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
return {
|
|
919
|
+
isMatch: false,
|
|
920
|
+
score: 1
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
};
|
|
1346
924
|
|
|
925
|
+
//#endregion
|
|
926
|
+
//#region src/core/register.ts
|
|
1347
927
|
const registeredSearchers = [];
|
|
1348
|
-
|
|
1349
928
|
function register(...args) {
|
|
1350
|
-
|
|
929
|
+
registeredSearchers.push(...args);
|
|
1351
930
|
}
|
|
1352
|
-
|
|
1353
931
|
function createSearcher(pattern, options) {
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
return new BitapSearch(pattern, options)
|
|
932
|
+
for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
|
|
933
|
+
const searcherClass = registeredSearchers[i];
|
|
934
|
+
if (searcherClass.condition(pattern, options)) return new searcherClass(pattern, options);
|
|
935
|
+
}
|
|
936
|
+
return new BitapSearch(pattern, options);
|
|
1362
937
|
}
|
|
1363
938
|
|
|
939
|
+
//#endregion
|
|
940
|
+
//#region src/core/queryParser.ts
|
|
1364
941
|
const LogicalOperator = {
|
|
1365
|
-
|
|
1366
|
-
|
|
942
|
+
AND: "$and",
|
|
943
|
+
OR: "$or"
|
|
1367
944
|
};
|
|
1368
|
-
|
|
1369
945
|
const KeyType = {
|
|
1370
|
-
|
|
1371
|
-
|
|
946
|
+
PATH: "$path",
|
|
947
|
+
PATTERN: "$val"
|
|
1372
948
|
};
|
|
1373
|
-
|
|
1374
|
-
const isExpression = (query) =>
|
|
1375
|
-
!!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
|
|
1376
|
-
|
|
949
|
+
const isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
|
|
1377
950
|
const isPath = (query) => !!query[KeyType.PATH];
|
|
1378
|
-
|
|
1379
|
-
const
|
|
1380
|
-
!isArray(query) && isObject(query) && !isExpression(query);
|
|
1381
|
-
|
|
1382
|
-
const convertToExplicit = (query) => ({
|
|
1383
|
-
[LogicalOperator.AND]: Object.keys(query).map((key) => ({
|
|
1384
|
-
[key]: query[key]
|
|
1385
|
-
}))
|
|
1386
|
-
});
|
|
1387
|
-
|
|
1388
|
-
// When `auto` is `true`, the parse function will infer and initialize and add
|
|
1389
|
-
// the appropriate `Searcher` instance
|
|
951
|
+
const isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
|
|
952
|
+
const convertToExplicit = (query) => ({ [LogicalOperator.AND]: Object.keys(query).map((key) => ({ [key]: query[key] })) });
|
|
1390
953
|
function parse(query, options, { auto = true } = {}) {
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
if (isArray(value)) {
|
|
1430
|
-
value.forEach((item) => {
|
|
1431
|
-
node.children.push(next(item));
|
|
1432
|
-
});
|
|
1433
|
-
}
|
|
1434
|
-
});
|
|
1435
|
-
|
|
1436
|
-
return node
|
|
1437
|
-
};
|
|
1438
|
-
|
|
1439
|
-
if (!isExpression(query)) {
|
|
1440
|
-
query = convertToExplicit(query);
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
return next(query)
|
|
954
|
+
const next = (query) => {
|
|
955
|
+
if (isString(query)) {
|
|
956
|
+
const obj = {
|
|
957
|
+
keyId: null,
|
|
958
|
+
pattern: query
|
|
959
|
+
};
|
|
960
|
+
if (auto) obj.searcher = createSearcher(query, options);
|
|
961
|
+
return obj;
|
|
962
|
+
}
|
|
963
|
+
const keys = Object.keys(query);
|
|
964
|
+
const isQueryPath = isPath(query);
|
|
965
|
+
if (!isQueryPath && keys.length > 1 && !isExpression(query)) return next(convertToExplicit(query));
|
|
966
|
+
if (isLeaf(query)) {
|
|
967
|
+
const key = isQueryPath ? query[KeyType.PATH] : keys[0];
|
|
968
|
+
const pattern = isQueryPath ? query[KeyType.PATTERN] : query[key];
|
|
969
|
+
if (!isString(pattern)) throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
|
|
970
|
+
const obj = {
|
|
971
|
+
keyId: createKeyId(key),
|
|
972
|
+
pattern
|
|
973
|
+
};
|
|
974
|
+
if (auto) obj.searcher = createSearcher(pattern, options);
|
|
975
|
+
return obj;
|
|
976
|
+
}
|
|
977
|
+
const node = {
|
|
978
|
+
children: [],
|
|
979
|
+
operator: keys[0]
|
|
980
|
+
};
|
|
981
|
+
keys.forEach((key) => {
|
|
982
|
+
const value = query[key];
|
|
983
|
+
if (isArray(value)) value.forEach((item) => {
|
|
984
|
+
node.children.push(next(item));
|
|
985
|
+
});
|
|
986
|
+
});
|
|
987
|
+
return node;
|
|
988
|
+
};
|
|
989
|
+
if (!isExpression(query)) query = convertToExplicit(query);
|
|
990
|
+
return next(query);
|
|
1444
991
|
}
|
|
1445
992
|
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
) {
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
);
|
|
1461
|
-
});
|
|
1462
|
-
|
|
1463
|
-
result.score = totalScore;
|
|
1464
|
-
});
|
|
993
|
+
//#endregion
|
|
994
|
+
//#region src/core/computeScore.ts
|
|
995
|
+
function computeScoreSingle(matches, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
|
|
996
|
+
let totalScore = 1;
|
|
997
|
+
matches.forEach(({ key, norm, score }) => {
|
|
998
|
+
const weight = key ? key.weight : null;
|
|
999
|
+
totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm));
|
|
1000
|
+
});
|
|
1001
|
+
return totalScore;
|
|
1002
|
+
}
|
|
1003
|
+
function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
|
|
1004
|
+
results.forEach((result) => {
|
|
1005
|
+
result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
|
|
1006
|
+
});
|
|
1465
1007
|
}
|
|
1466
1008
|
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1009
|
+
//#endregion
|
|
1010
|
+
//#region src/tools/MaxHeap.ts
|
|
1011
|
+
var MaxHeap = class {
|
|
1012
|
+
constructor(limit) {
|
|
1013
|
+
this.limit = limit;
|
|
1014
|
+
this.heap = [];
|
|
1015
|
+
}
|
|
1016
|
+
get size() {
|
|
1017
|
+
return this.heap.length;
|
|
1018
|
+
}
|
|
1019
|
+
shouldInsert(score) {
|
|
1020
|
+
return this.size < this.limit || score < this.heap[0].score;
|
|
1021
|
+
}
|
|
1022
|
+
insert(item) {
|
|
1023
|
+
if (this.size < this.limit) {
|
|
1024
|
+
this.heap.push(item);
|
|
1025
|
+
this._bubbleUp(this.size - 1);
|
|
1026
|
+
} else if (item.score < this.heap[0].score) {
|
|
1027
|
+
this.heap[0] = item;
|
|
1028
|
+
this._sinkDown(0);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
extractSorted(sortFn) {
|
|
1032
|
+
return this.heap.sort(sortFn);
|
|
1033
|
+
}
|
|
1034
|
+
_bubbleUp(i) {
|
|
1035
|
+
const heap = this.heap;
|
|
1036
|
+
while (i > 0) {
|
|
1037
|
+
const parent = i - 1 >> 1;
|
|
1038
|
+
if (heap[i].score <= heap[parent].score) break;
|
|
1039
|
+
const tmp = heap[i];
|
|
1040
|
+
heap[i] = heap[parent];
|
|
1041
|
+
heap[parent] = tmp;
|
|
1042
|
+
i = parent;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
_sinkDown(i) {
|
|
1046
|
+
const heap = this.heap;
|
|
1047
|
+
const len = heap.length;
|
|
1048
|
+
let largest = i;
|
|
1049
|
+
do {
|
|
1050
|
+
i = largest;
|
|
1051
|
+
const left = 2 * i + 1;
|
|
1052
|
+
const right = 2 * i + 2;
|
|
1053
|
+
if (left < len && heap[left].score > heap[largest].score) largest = left;
|
|
1054
|
+
if (right < len && heap[right].score > heap[largest].score) largest = right;
|
|
1055
|
+
if (largest !== i) {
|
|
1056
|
+
const tmp = heap[i];
|
|
1057
|
+
heap[i] = heap[largest];
|
|
1058
|
+
heap[largest] = tmp;
|
|
1059
|
+
}
|
|
1060
|
+
} while (largest !== i);
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1494
1063
|
|
|
1495
|
-
|
|
1496
|
-
|
|
1064
|
+
//#endregion
|
|
1065
|
+
//#region src/core/formatMatches.ts
|
|
1066
|
+
function formatMatches(result) {
|
|
1067
|
+
const matches = [];
|
|
1068
|
+
result.matches.forEach((match) => {
|
|
1069
|
+
if (!isDefined(match.indices) || !match.indices.length) return;
|
|
1070
|
+
const obj = {
|
|
1071
|
+
indices: match.indices,
|
|
1072
|
+
value: match.value
|
|
1073
|
+
};
|
|
1074
|
+
if (match.key) obj.key = match.key.id;
|
|
1075
|
+
if (match.idx > -1) obj.refIndex = match.idx;
|
|
1076
|
+
matches.push(obj);
|
|
1077
|
+
});
|
|
1078
|
+
return matches;
|
|
1497
1079
|
}
|
|
1498
1080
|
|
|
1499
|
-
|
|
1500
|
-
|
|
1081
|
+
//#endregion
|
|
1082
|
+
//#region src/core/format.ts
|
|
1083
|
+
function format(results, docs, { includeMatches = Config.includeMatches, includeScore = Config.includeScore } = {}) {
|
|
1084
|
+
return results.map((result) => {
|
|
1085
|
+
const { idx } = result;
|
|
1086
|
+
const data = {
|
|
1087
|
+
item: docs[idx],
|
|
1088
|
+
refIndex: idx
|
|
1089
|
+
};
|
|
1090
|
+
if (includeMatches) data.matches = formatMatches(result);
|
|
1091
|
+
if (includeScore) data.score = result.score;
|
|
1092
|
+
return data;
|
|
1093
|
+
});
|
|
1501
1094
|
}
|
|
1502
1095
|
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
if (includeMatches) transformers.push(transformMatches);
|
|
1514
|
-
if (includeScore) transformers.push(transformScore);
|
|
1515
|
-
|
|
1516
|
-
return results.map((result) => {
|
|
1517
|
-
const { idx } = result;
|
|
1518
|
-
|
|
1519
|
-
const data = {
|
|
1520
|
-
item: docs[idx],
|
|
1521
|
-
refIndex: idx
|
|
1522
|
-
};
|
|
1523
|
-
|
|
1524
|
-
if (transformers.length) {
|
|
1525
|
-
transformers.forEach((transformer) => {
|
|
1526
|
-
transformer(result, data);
|
|
1527
|
-
});
|
|
1528
|
-
}
|
|
1529
|
-
|
|
1530
|
-
return data
|
|
1531
|
-
})
|
|
1096
|
+
//#endregion
|
|
1097
|
+
//#region src/search/token/analyzer.ts
|
|
1098
|
+
const DEFAULT_TOKEN = /[\p{L}\p{M}\p{N}_]+/gu;
|
|
1099
|
+
const warned = /* @__PURE__ */ new WeakSet();
|
|
1100
|
+
function warnNonGlobal(regex) {
|
|
1101
|
+
if (!warned.has(regex)) {
|
|
1102
|
+
warned.add(regex);
|
|
1103
|
+
console.warn(`[Fuse] tokenize regex ${regex} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`);
|
|
1104
|
+
}
|
|
1532
1105
|
}
|
|
1106
|
+
function resolveTokenize(tokenize) {
|
|
1107
|
+
if (typeof tokenize === "function") {
|
|
1108
|
+
let validated = false;
|
|
1109
|
+
return (text) => {
|
|
1110
|
+
const result = tokenize(text);
|
|
1111
|
+
if (!validated) {
|
|
1112
|
+
validated = true;
|
|
1113
|
+
if (!Array.isArray(result) || result.some((t) => typeof t !== "string")) throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(result) ? "array containing non-strings" : typeof result}.`);
|
|
1114
|
+
}
|
|
1115
|
+
return result;
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
if (tokenize instanceof RegExp) {
|
|
1119
|
+
if (!tokenize.global) warnNonGlobal(tokenize);
|
|
1120
|
+
return (text) => text.match(tokenize) || [];
|
|
1121
|
+
}
|
|
1122
|
+
return (text) => text.match(DEFAULT_TOKEN) || [];
|
|
1123
|
+
}
|
|
1124
|
+
function createAnalyzer({ isCaseSensitive = false, ignoreDiacritics = false, tokenize } = {}) {
|
|
1125
|
+
const tokenizeFn = resolveTokenize(tokenize);
|
|
1126
|
+
return { tokenize(text) {
|
|
1127
|
+
if (!isCaseSensitive) text = text.toLowerCase();
|
|
1128
|
+
if (ignoreDiacritics) text = stripDiacritics(text);
|
|
1129
|
+
return tokenizeFn(text);
|
|
1130
|
+
} };
|
|
1131
|
+
}
|
|
1132
|
+
var TokenSearch = class {
|
|
1133
|
+
static condition(_, options) {
|
|
1134
|
+
return options.useTokenSearch;
|
|
1135
|
+
}
|
|
1136
|
+
constructor(pattern, options) {
|
|
1137
|
+
this.options = options;
|
|
1138
|
+
this.analyzer = createAnalyzer({
|
|
1139
|
+
isCaseSensitive: options.isCaseSensitive,
|
|
1140
|
+
ignoreDiacritics: options.ignoreDiacritics,
|
|
1141
|
+
tokenize: options.tokenize
|
|
1142
|
+
});
|
|
1143
|
+
const queryTerms = this.analyzer.tokenize(pattern);
|
|
1144
|
+
const { df, fieldCount } = options._invertedIndex;
|
|
1145
|
+
this.termSearchers = [];
|
|
1146
|
+
this.idfWeights = [];
|
|
1147
|
+
for (const term of queryTerms) {
|
|
1148
|
+
this.termSearchers.push(new BitapSearch(term, {
|
|
1149
|
+
location: options.location,
|
|
1150
|
+
threshold: options.threshold,
|
|
1151
|
+
distance: options.distance,
|
|
1152
|
+
includeMatches: options.includeMatches,
|
|
1153
|
+
findAllMatches: options.findAllMatches,
|
|
1154
|
+
minMatchCharLength: options.minMatchCharLength,
|
|
1155
|
+
isCaseSensitive: options.isCaseSensitive,
|
|
1156
|
+
ignoreDiacritics: options.ignoreDiacritics,
|
|
1157
|
+
ignoreLocation: true
|
|
1158
|
+
}));
|
|
1159
|
+
const docFreq = df.get(term) || 0;
|
|
1160
|
+
const idf = Math.log(1 + (fieldCount - docFreq + .5) / (docFreq + .5));
|
|
1161
|
+
this.idfWeights.push(idf);
|
|
1162
|
+
}
|
|
1163
|
+
this.combineAll = options.tokenMatch === "all";
|
|
1164
|
+
this.numTerms = this.termSearchers.length;
|
|
1165
|
+
this.useMask = this.numTerms <= 31;
|
|
1166
|
+
}
|
|
1167
|
+
searchIn(text) {
|
|
1168
|
+
if (!this.termSearchers.length) return {
|
|
1169
|
+
isMatch: false,
|
|
1170
|
+
score: 1
|
|
1171
|
+
};
|
|
1172
|
+
const allIndices = [];
|
|
1173
|
+
let weightedScore = 0;
|
|
1174
|
+
let maxPossibleScore = 0;
|
|
1175
|
+
let matchedCount = 0;
|
|
1176
|
+
let matchedMask = 0;
|
|
1177
|
+
const matchedTerms = this.combineAll && !this.useMask ? /* @__PURE__ */ new Set() : null;
|
|
1178
|
+
for (let i = 0; i < this.termSearchers.length; i++) {
|
|
1179
|
+
const result = this.termSearchers[i].searchIn(text);
|
|
1180
|
+
const idf = this.idfWeights[i];
|
|
1181
|
+
maxPossibleScore += idf;
|
|
1182
|
+
if (result.isMatch) {
|
|
1183
|
+
matchedCount++;
|
|
1184
|
+
weightedScore += idf * (1 - result.score);
|
|
1185
|
+
if (result.indices) allIndices.push(...result.indices);
|
|
1186
|
+
if (this.combineAll) if (this.useMask) matchedMask |= 1 << i;
|
|
1187
|
+
else matchedTerms.add(i);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
if (matchedCount === 0) return {
|
|
1191
|
+
isMatch: false,
|
|
1192
|
+
score: 1
|
|
1193
|
+
};
|
|
1194
|
+
const normalized = maxPossibleScore > 0 ? 1 - weightedScore / maxPossibleScore : 0;
|
|
1195
|
+
const searchResult = {
|
|
1196
|
+
isMatch: true,
|
|
1197
|
+
score: Math.max(.001, normalized)
|
|
1198
|
+
};
|
|
1199
|
+
if (this.options.includeMatches && allIndices.length) searchResult.indices = mergeIndices(allIndices);
|
|
1200
|
+
if (this.combineAll) {
|
|
1201
|
+
if (this.useMask) searchResult.matchedMask = matchedMask;
|
|
1202
|
+
else searchResult.matchedTerms = matchedTerms;
|
|
1203
|
+
searchResult.termCount = this.numTerms;
|
|
1204
|
+
}
|
|
1205
|
+
return searchResult;
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1533
1208
|
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
add(doc) {
|
|
1566
|
-
if (!isDefined(doc)) {
|
|
1567
|
-
return
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
this._docs.push(doc);
|
|
1571
|
-
this._myIndex.add(doc);
|
|
1572
|
-
}
|
|
1573
|
-
|
|
1574
|
-
remove(predicate = (/* doc, idx */) => false) {
|
|
1575
|
-
const results = [];
|
|
1576
|
-
|
|
1577
|
-
for (let i = 0, len = this._docs.length; i < len; i += 1) {
|
|
1578
|
-
const doc = this._docs[i];
|
|
1579
|
-
if (predicate(doc, i)) {
|
|
1580
|
-
this.removeAt(i);
|
|
1581
|
-
i -= 1;
|
|
1582
|
-
len -= 1;
|
|
1583
|
-
|
|
1584
|
-
results.push(doc);
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
|
-
return results
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
removeAt(idx) {
|
|
1592
|
-
this._docs.splice(idx, 1);
|
|
1593
|
-
this._myIndex.removeAt(idx);
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
getIndex() {
|
|
1597
|
-
return this._myIndex
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
search(query, { limit = -1 } = {}) {
|
|
1601
|
-
const {
|
|
1602
|
-
includeMatches,
|
|
1603
|
-
includeScore,
|
|
1604
|
-
shouldSort,
|
|
1605
|
-
sortFn,
|
|
1606
|
-
ignoreFieldNorm
|
|
1607
|
-
} = this.options;
|
|
1608
|
-
|
|
1609
|
-
let results = isString(query)
|
|
1610
|
-
? isString(this._docs[0])
|
|
1611
|
-
? this._searchStringList(query)
|
|
1612
|
-
: this._searchObjectList(query)
|
|
1613
|
-
: this._searchLogical(query);
|
|
1614
|
-
|
|
1615
|
-
computeScore(results, { ignoreFieldNorm });
|
|
1616
|
-
|
|
1617
|
-
if (shouldSort) {
|
|
1618
|
-
results.sort(sortFn);
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
|
-
if (isNumber(limit) && limit > -1) {
|
|
1622
|
-
results = results.slice(0, limit);
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
return format(results, this._docs, {
|
|
1626
|
-
includeMatches,
|
|
1627
|
-
includeScore
|
|
1628
|
-
})
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
_searchStringList(query) {
|
|
1632
|
-
const searcher = createSearcher(query, this.options);
|
|
1633
|
-
const { records } = this._myIndex;
|
|
1634
|
-
const results = [];
|
|
1635
|
-
|
|
1636
|
-
// Iterate over every string in the index
|
|
1637
|
-
records.forEach(({ v: text, i: idx, n: norm }) => {
|
|
1638
|
-
if (!isDefined(text)) {
|
|
1639
|
-
return
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1643
|
-
|
|
1644
|
-
if (isMatch) {
|
|
1645
|
-
results.push({
|
|
1646
|
-
item: text,
|
|
1647
|
-
idx,
|
|
1648
|
-
matches: [{ score, value: text, norm, indices }]
|
|
1649
|
-
});
|
|
1650
|
-
}
|
|
1651
|
-
});
|
|
1652
|
-
|
|
1653
|
-
return results
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
_searchLogical(query) {
|
|
1657
|
-
|
|
1658
|
-
const expression = parse(query, this.options);
|
|
1659
|
-
|
|
1660
|
-
const evaluate = (node, item, idx) => {
|
|
1661
|
-
if (!node.children) {
|
|
1662
|
-
const { keyId, searcher } = node;
|
|
1663
|
-
|
|
1664
|
-
const matches = this._findMatches({
|
|
1665
|
-
key: this._keyStore.get(keyId),
|
|
1666
|
-
value: this._myIndex.getValueForItemAtKeyId(item, keyId),
|
|
1667
|
-
searcher
|
|
1668
|
-
});
|
|
1669
|
-
|
|
1670
|
-
if (matches && matches.length) {
|
|
1671
|
-
return [
|
|
1672
|
-
{
|
|
1673
|
-
idx,
|
|
1674
|
-
item,
|
|
1675
|
-
matches
|
|
1676
|
-
}
|
|
1677
|
-
]
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
return []
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
const res = [];
|
|
1684
|
-
for (let i = 0, len = node.children.length; i < len; i += 1) {
|
|
1685
|
-
const child = node.children[i];
|
|
1686
|
-
const result = evaluate(child, item, idx);
|
|
1687
|
-
if (result.length) {
|
|
1688
|
-
res.push(...result);
|
|
1689
|
-
} else if (node.operator === LogicalOperator.AND) {
|
|
1690
|
-
return []
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
return res
|
|
1694
|
-
};
|
|
1695
|
-
|
|
1696
|
-
const records = this._myIndex.records;
|
|
1697
|
-
const resultMap = {};
|
|
1698
|
-
const results = [];
|
|
1699
|
-
|
|
1700
|
-
records.forEach(({ $: item, i: idx }) => {
|
|
1701
|
-
if (isDefined(item)) {
|
|
1702
|
-
let expResults = evaluate(expression, item, idx);
|
|
1703
|
-
|
|
1704
|
-
if (expResults.length) {
|
|
1705
|
-
// Dedupe when adding
|
|
1706
|
-
if (!resultMap[idx]) {
|
|
1707
|
-
resultMap[idx] = { idx, item, matches: [] };
|
|
1708
|
-
results.push(resultMap[idx]);
|
|
1709
|
-
}
|
|
1710
|
-
expResults.forEach(({ matches }) => {
|
|
1711
|
-
resultMap[idx].matches.push(...matches);
|
|
1712
|
-
});
|
|
1713
|
-
}
|
|
1714
|
-
}
|
|
1715
|
-
});
|
|
1716
|
-
|
|
1717
|
-
return results
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
_searchObjectList(query) {
|
|
1721
|
-
const searcher = createSearcher(query, this.options);
|
|
1722
|
-
const { keys, records } = this._myIndex;
|
|
1723
|
-
const results = [];
|
|
1724
|
-
|
|
1725
|
-
// List is Array<Object>
|
|
1726
|
-
records.forEach(({ $: item, i: idx }) => {
|
|
1727
|
-
if (!isDefined(item)) {
|
|
1728
|
-
return
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
let matches = [];
|
|
1732
|
-
|
|
1733
|
-
// Iterate over every key (i.e, path), and fetch the value at that key
|
|
1734
|
-
keys.forEach((key, keyIndex) => {
|
|
1735
|
-
matches.push(
|
|
1736
|
-
...this._findMatches({
|
|
1737
|
-
key,
|
|
1738
|
-
value: item[keyIndex],
|
|
1739
|
-
searcher
|
|
1740
|
-
})
|
|
1741
|
-
);
|
|
1742
|
-
});
|
|
1743
|
-
|
|
1744
|
-
if (matches.length) {
|
|
1745
|
-
results.push({
|
|
1746
|
-
idx,
|
|
1747
|
-
item,
|
|
1748
|
-
matches
|
|
1749
|
-
});
|
|
1750
|
-
}
|
|
1751
|
-
});
|
|
1752
|
-
|
|
1753
|
-
return results
|
|
1754
|
-
}
|
|
1755
|
-
_findMatches({ key, value, searcher }) {
|
|
1756
|
-
if (!isDefined(value)) {
|
|
1757
|
-
return []
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
let matches = [];
|
|
1761
|
-
|
|
1762
|
-
if (isArray(value)) {
|
|
1763
|
-
value.forEach(({ v: text, i: idx, n: norm }) => {
|
|
1764
|
-
if (!isDefined(text)) {
|
|
1765
|
-
return
|
|
1766
|
-
}
|
|
1767
|
-
|
|
1768
|
-
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1769
|
-
|
|
1770
|
-
if (isMatch) {
|
|
1771
|
-
matches.push({
|
|
1772
|
-
score,
|
|
1773
|
-
key,
|
|
1774
|
-
value: text,
|
|
1775
|
-
idx,
|
|
1776
|
-
norm,
|
|
1777
|
-
indices
|
|
1778
|
-
});
|
|
1779
|
-
}
|
|
1780
|
-
});
|
|
1781
|
-
} else {
|
|
1782
|
-
const { v: text, n: norm } = value;
|
|
1783
|
-
|
|
1784
|
-
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1785
|
-
|
|
1786
|
-
if (isMatch) {
|
|
1787
|
-
matches.push({ score, key, value: text, norm, indices });
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
|
-
return matches
|
|
1792
|
-
}
|
|
1209
|
+
//#endregion
|
|
1210
|
+
//#region src/search/token/InvertedIndex.ts
|
|
1211
|
+
function addField(index, text, docIdx, analyzer) {
|
|
1212
|
+
const tokens = analyzer.tokenize(text);
|
|
1213
|
+
if (!tokens.length) return;
|
|
1214
|
+
index.fieldCount++;
|
|
1215
|
+
index.docFieldCount.set(docIdx, (index.docFieldCount.get(docIdx) || 0) + 1);
|
|
1216
|
+
const distinctTerms = new Set(tokens);
|
|
1217
|
+
let perDocTerms = index.docTermFieldHits.get(docIdx);
|
|
1218
|
+
if (!perDocTerms) {
|
|
1219
|
+
perDocTerms = /* @__PURE__ */ new Map();
|
|
1220
|
+
index.docTermFieldHits.set(docIdx, perDocTerms);
|
|
1221
|
+
}
|
|
1222
|
+
for (const term of distinctTerms) {
|
|
1223
|
+
perDocTerms.set(term, (perDocTerms.get(term) || 0) + 1);
|
|
1224
|
+
index.df.set(term, (index.df.get(term) || 0) + 1);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
function ingestRecord(index, record, keyCount, analyzer) {
|
|
1228
|
+
const { i: docIdx, v, $: fields } = record;
|
|
1229
|
+
if (v !== void 0) {
|
|
1230
|
+
addField(index, v, docIdx, analyzer);
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
if (!fields) return;
|
|
1234
|
+
for (let keyIdx = 0; keyIdx < keyCount; keyIdx++) {
|
|
1235
|
+
const value = fields[keyIdx];
|
|
1236
|
+
if (!value) continue;
|
|
1237
|
+
if (Array.isArray(value)) for (const sub of value) addField(index, sub.v, docIdx, analyzer);
|
|
1238
|
+
else addField(index, value.v, docIdx, analyzer);
|
|
1239
|
+
}
|
|
1793
1240
|
}
|
|
1241
|
+
function buildInvertedIndex(records, keyCount, analyzer) {
|
|
1242
|
+
const index = {
|
|
1243
|
+
fieldCount: 0,
|
|
1244
|
+
df: /* @__PURE__ */ new Map(),
|
|
1245
|
+
docFieldCount: /* @__PURE__ */ new Map(),
|
|
1246
|
+
docTermFieldHits: /* @__PURE__ */ new Map()
|
|
1247
|
+
};
|
|
1248
|
+
for (const record of records) ingestRecord(index, record, keyCount, analyzer);
|
|
1249
|
+
return index;
|
|
1250
|
+
}
|
|
1251
|
+
function addToInvertedIndex(index, record, keyCount, analyzer) {
|
|
1252
|
+
ingestRecord(index, record, keyCount, analyzer);
|
|
1253
|
+
}
|
|
1254
|
+
function removeFromInvertedIndex(index, docIdx) {
|
|
1255
|
+
const fieldCount = index.docFieldCount.get(docIdx);
|
|
1256
|
+
if (fieldCount === void 0) return;
|
|
1257
|
+
index.fieldCount -= fieldCount;
|
|
1258
|
+
index.docFieldCount.delete(docIdx);
|
|
1259
|
+
const perDocTerms = index.docTermFieldHits.get(docIdx);
|
|
1260
|
+
if (!perDocTerms) return;
|
|
1261
|
+
for (const [term, hits] of perDocTerms) {
|
|
1262
|
+
const next = (index.df.get(term) || 0) - hits;
|
|
1263
|
+
if (next <= 0) index.df.delete(term);
|
|
1264
|
+
else index.df.set(term, next);
|
|
1265
|
+
}
|
|
1266
|
+
index.docTermFieldHits.delete(docIdx);
|
|
1267
|
+
}
|
|
1268
|
+
function removeAndShiftInvertedIndex(index, removedIndices) {
|
|
1269
|
+
if (removedIndices.length === 0) return;
|
|
1270
|
+
const sorted = Array.from(new Set(removedIndices)).sort((a, b) => a - b);
|
|
1271
|
+
for (const idx of sorted) removeFromInvertedIndex(index, idx);
|
|
1272
|
+
const shift = (oldIdx) => {
|
|
1273
|
+
let lo = 0;
|
|
1274
|
+
let hi = sorted.length;
|
|
1275
|
+
while (lo < hi) {
|
|
1276
|
+
const mid = lo + hi >>> 1;
|
|
1277
|
+
if (sorted[mid] < oldIdx) lo = mid + 1;
|
|
1278
|
+
else hi = mid;
|
|
1279
|
+
}
|
|
1280
|
+
return oldIdx - lo;
|
|
1281
|
+
};
|
|
1282
|
+
const firstRemoved = sorted[0];
|
|
1283
|
+
const shiftedDocFieldCount = /* @__PURE__ */ new Map();
|
|
1284
|
+
for (const [oldKey, count] of index.docFieldCount) shiftedDocFieldCount.set(oldKey > firstRemoved ? shift(oldKey) : oldKey, count);
|
|
1285
|
+
index.docFieldCount = shiftedDocFieldCount;
|
|
1286
|
+
const shiftedDocTermFieldHits = /* @__PURE__ */ new Map();
|
|
1287
|
+
for (const [oldKey, terms] of index.docTermFieldHits) shiftedDocTermFieldHits.set(oldKey > firstRemoved ? shift(oldKey) : oldKey, terms);
|
|
1288
|
+
index.docTermFieldHits = shiftedDocTermFieldHits;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
//#endregion
|
|
1292
|
+
//#region src/core/index.ts
|
|
1293
|
+
var Fuse = class {
|
|
1294
|
+
constructor(docs, options, index) {
|
|
1295
|
+
this.options = {
|
|
1296
|
+
...Config,
|
|
1297
|
+
...options
|
|
1298
|
+
};
|
|
1299
|
+
this._keyStore = new KeyStore(this.options.keys);
|
|
1300
|
+
this._docs = docs;
|
|
1301
|
+
this._myIndex = null;
|
|
1302
|
+
this._invertedIndex = null;
|
|
1303
|
+
this.setCollection(docs, index);
|
|
1304
|
+
this._lastQuery = null;
|
|
1305
|
+
this._lastSearcher = null;
|
|
1306
|
+
}
|
|
1307
|
+
_getSearcher(query) {
|
|
1308
|
+
if (this._lastQuery === query) return this._lastSearcher;
|
|
1309
|
+
const searcher = createSearcher(query, this._invertedIndex ? {
|
|
1310
|
+
...this.options,
|
|
1311
|
+
_invertedIndex: this._invertedIndex
|
|
1312
|
+
} : this.options);
|
|
1313
|
+
this._lastQuery = query;
|
|
1314
|
+
this._lastSearcher = searcher;
|
|
1315
|
+
return searcher;
|
|
1316
|
+
}
|
|
1317
|
+
setCollection(docs, index) {
|
|
1318
|
+
this._docs = docs;
|
|
1319
|
+
if (index && !(index instanceof FuseIndex)) throw new Error(INCORRECT_INDEX_TYPE);
|
|
1320
|
+
this._myIndex = index || createIndex(this.options.keys, this._docs, {
|
|
1321
|
+
getFn: this.options.getFn,
|
|
1322
|
+
fieldNormWeight: this.options.fieldNormWeight
|
|
1323
|
+
});
|
|
1324
|
+
if (this.options.useTokenSearch) {
|
|
1325
|
+
const analyzer = createAnalyzer({
|
|
1326
|
+
isCaseSensitive: this.options.isCaseSensitive,
|
|
1327
|
+
ignoreDiacritics: this.options.ignoreDiacritics,
|
|
1328
|
+
tokenize: this.options.tokenize
|
|
1329
|
+
});
|
|
1330
|
+
this._invertedIndex = buildInvertedIndex(this._myIndex.records, this._myIndex.keys.length, analyzer);
|
|
1331
|
+
}
|
|
1332
|
+
this._invalidateSearcherCache();
|
|
1333
|
+
}
|
|
1334
|
+
add(doc) {
|
|
1335
|
+
if (!isDefined(doc)) return;
|
|
1336
|
+
this._docs.push(doc);
|
|
1337
|
+
const record = this._myIndex.add(doc, this._docs.length - 1);
|
|
1338
|
+
if (this._invertedIndex && record) {
|
|
1339
|
+
const analyzer = createAnalyzer({
|
|
1340
|
+
isCaseSensitive: this.options.isCaseSensitive,
|
|
1341
|
+
ignoreDiacritics: this.options.ignoreDiacritics,
|
|
1342
|
+
tokenize: this.options.tokenize
|
|
1343
|
+
});
|
|
1344
|
+
addToInvertedIndex(this._invertedIndex, record, this._myIndex.keys.length, analyzer);
|
|
1345
|
+
}
|
|
1346
|
+
this._invalidateSearcherCache();
|
|
1347
|
+
}
|
|
1348
|
+
remove(predicate = () => false) {
|
|
1349
|
+
const results = [];
|
|
1350
|
+
const indicesToRemove = [];
|
|
1351
|
+
for (let i = 0, len = this._docs.length; i < len; i += 1) if (predicate(this._docs[i], i)) {
|
|
1352
|
+
results.push(this._docs[i]);
|
|
1353
|
+
indicesToRemove.push(i);
|
|
1354
|
+
}
|
|
1355
|
+
if (indicesToRemove.length) {
|
|
1356
|
+
if (this._invertedIndex) removeAndShiftInvertedIndex(this._invertedIndex, indicesToRemove);
|
|
1357
|
+
const toRemove = new Set(indicesToRemove);
|
|
1358
|
+
this._docs = this._docs.filter((_, i) => !toRemove.has(i));
|
|
1359
|
+
this._myIndex.removeAll(indicesToRemove);
|
|
1360
|
+
this._invalidateSearcherCache();
|
|
1361
|
+
}
|
|
1362
|
+
return results;
|
|
1363
|
+
}
|
|
1364
|
+
removeAt(idx) {
|
|
1365
|
+
if (!Number.isInteger(idx) || idx < 0 || idx >= this._docs.length) throw new Error(INVALID_DOC_INDEX);
|
|
1366
|
+
if (this._invertedIndex) removeAndShiftInvertedIndex(this._invertedIndex, [idx]);
|
|
1367
|
+
const doc = this._docs.splice(idx, 1)[0];
|
|
1368
|
+
this._myIndex.removeAt(idx);
|
|
1369
|
+
this._invalidateSearcherCache();
|
|
1370
|
+
return doc;
|
|
1371
|
+
}
|
|
1372
|
+
_invalidateSearcherCache() {
|
|
1373
|
+
this._lastQuery = null;
|
|
1374
|
+
this._lastSearcher = null;
|
|
1375
|
+
}
|
|
1376
|
+
getIndex() {
|
|
1377
|
+
return this._myIndex;
|
|
1378
|
+
}
|
|
1379
|
+
search(query, options) {
|
|
1380
|
+
const { limit = -1 } = options || {};
|
|
1381
|
+
const { includeMatches, includeScore, shouldSort, sortFn, ignoreFieldNorm } = this.options;
|
|
1382
|
+
if (isString(query) && !query.trim()) {
|
|
1383
|
+
let docs = this._docs.map((item, idx) => ({
|
|
1384
|
+
item,
|
|
1385
|
+
refIndex: idx
|
|
1386
|
+
}));
|
|
1387
|
+
if (isNumber(limit) && limit > -1) docs = docs.slice(0, limit);
|
|
1388
|
+
return docs;
|
|
1389
|
+
}
|
|
1390
|
+
const useHeap = isNumber(limit) && limit > 0 && isString(query);
|
|
1391
|
+
let results;
|
|
1392
|
+
if (useHeap) {
|
|
1393
|
+
const heap = new MaxHeap(limit);
|
|
1394
|
+
if (isString(this._docs[0])) this._searchStringList(query, {
|
|
1395
|
+
heap,
|
|
1396
|
+
ignoreFieldNorm
|
|
1397
|
+
});
|
|
1398
|
+
else this._searchObjectList(query, {
|
|
1399
|
+
heap,
|
|
1400
|
+
ignoreFieldNorm
|
|
1401
|
+
});
|
|
1402
|
+
results = heap.extractSorted(sortFn);
|
|
1403
|
+
} else {
|
|
1404
|
+
results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
|
|
1405
|
+
computeScore(results, { ignoreFieldNorm });
|
|
1406
|
+
if (shouldSort) results.sort(sortFn);
|
|
1407
|
+
if (isNumber(limit) && limit > -1) results = results.slice(0, limit);
|
|
1408
|
+
}
|
|
1409
|
+
return format(results, this._docs, {
|
|
1410
|
+
includeMatches,
|
|
1411
|
+
includeScore
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
_searchStringList(query, { heap, ignoreFieldNorm } = {}) {
|
|
1415
|
+
const searcher = this._getSearcher(query);
|
|
1416
|
+
const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
|
|
1417
|
+
const { records } = this._myIndex;
|
|
1418
|
+
const results = heap ? null : [];
|
|
1419
|
+
records.forEach(({ v: text, i: idx, n: norm }) => {
|
|
1420
|
+
if (!isDefined(text)) return;
|
|
1421
|
+
const searchResult = searcher.searchIn(text);
|
|
1422
|
+
if (searchResult.isMatch) {
|
|
1423
|
+
const match = {
|
|
1424
|
+
score: searchResult.score,
|
|
1425
|
+
value: text,
|
|
1426
|
+
norm,
|
|
1427
|
+
indices: searchResult.indices
|
|
1428
|
+
};
|
|
1429
|
+
if (requireAllTokens) {
|
|
1430
|
+
match.matchedMask = searchResult.matchedMask;
|
|
1431
|
+
match.matchedTerms = searchResult.matchedTerms;
|
|
1432
|
+
match.termCount = searchResult.termCount;
|
|
1433
|
+
}
|
|
1434
|
+
const matches = [match];
|
|
1435
|
+
if (!requireAllTokens || this._coversAllTokens(matches)) {
|
|
1436
|
+
const result = {
|
|
1437
|
+
item: text,
|
|
1438
|
+
idx,
|
|
1439
|
+
matches
|
|
1440
|
+
};
|
|
1441
|
+
if (heap) {
|
|
1442
|
+
result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
|
|
1443
|
+
if (heap.shouldInsert(result.score)) heap.insert(result);
|
|
1444
|
+
} else results.push(result);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
});
|
|
1448
|
+
return results;
|
|
1449
|
+
}
|
|
1450
|
+
_searchLogical(query) {
|
|
1451
|
+
const expression = parse(query, this.options);
|
|
1452
|
+
const evaluate = (node, item, idx) => {
|
|
1453
|
+
if (!("children" in node)) {
|
|
1454
|
+
const { keyId, searcher } = node;
|
|
1455
|
+
let matches;
|
|
1456
|
+
if (keyId === null) {
|
|
1457
|
+
matches = [];
|
|
1458
|
+
this._myIndex.keys.forEach((key, keyIndex) => {
|
|
1459
|
+
matches.push(...this._findMatches({
|
|
1460
|
+
key,
|
|
1461
|
+
value: item[keyIndex],
|
|
1462
|
+
searcher
|
|
1463
|
+
}));
|
|
1464
|
+
});
|
|
1465
|
+
} else matches = this._findMatches({
|
|
1466
|
+
key: this._keyStore.get(keyId),
|
|
1467
|
+
value: this._myIndex.getValueForItemAtKeyId(item, keyId),
|
|
1468
|
+
searcher
|
|
1469
|
+
});
|
|
1470
|
+
if (matches && matches.length) return [{
|
|
1471
|
+
idx,
|
|
1472
|
+
item,
|
|
1473
|
+
matches
|
|
1474
|
+
}];
|
|
1475
|
+
return [];
|
|
1476
|
+
}
|
|
1477
|
+
const { children, operator } = node;
|
|
1478
|
+
const res = [];
|
|
1479
|
+
for (let i = 0, len = children.length; i < len; i += 1) {
|
|
1480
|
+
const child = children[i];
|
|
1481
|
+
const result = evaluate(child, item, idx);
|
|
1482
|
+
if (result.length) res.push(...result);
|
|
1483
|
+
else if (operator === LogicalOperator.AND) return [];
|
|
1484
|
+
}
|
|
1485
|
+
return res;
|
|
1486
|
+
};
|
|
1487
|
+
const records = this._myIndex.records;
|
|
1488
|
+
const resultMap = /* @__PURE__ */ new Map();
|
|
1489
|
+
const results = [];
|
|
1490
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1491
|
+
if (isDefined(item)) {
|
|
1492
|
+
const expResults = evaluate(expression, item, idx);
|
|
1493
|
+
if (expResults.length) {
|
|
1494
|
+
if (!resultMap.has(idx)) {
|
|
1495
|
+
resultMap.set(idx, {
|
|
1496
|
+
idx,
|
|
1497
|
+
item,
|
|
1498
|
+
matches: []
|
|
1499
|
+
});
|
|
1500
|
+
results.push(resultMap.get(idx));
|
|
1501
|
+
}
|
|
1502
|
+
expResults.forEach(({ matches }) => {
|
|
1503
|
+
resultMap.get(idx).matches.push(...matches);
|
|
1504
|
+
});
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
return results;
|
|
1509
|
+
}
|
|
1510
|
+
_searchObjectList(query, { heap, ignoreFieldNorm } = {}) {
|
|
1511
|
+
const searcher = this._getSearcher(query);
|
|
1512
|
+
const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
|
|
1513
|
+
const { keys, records } = this._myIndex;
|
|
1514
|
+
const results = heap ? null : [];
|
|
1515
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1516
|
+
if (!isDefined(item)) return;
|
|
1517
|
+
const matches = [];
|
|
1518
|
+
let anyKeyFailed = false;
|
|
1519
|
+
let hasInverse = false;
|
|
1520
|
+
keys.forEach((key, keyIndex) => {
|
|
1521
|
+
const keyMatches = this._findMatches({
|
|
1522
|
+
key,
|
|
1523
|
+
value: item[keyIndex],
|
|
1524
|
+
searcher
|
|
1525
|
+
});
|
|
1526
|
+
if (keyMatches.length) {
|
|
1527
|
+
matches.push(...keyMatches);
|
|
1528
|
+
if (keyMatches[0].hasInverse) hasInverse = true;
|
|
1529
|
+
} else anyKeyFailed = true;
|
|
1530
|
+
});
|
|
1531
|
+
if (hasInverse && anyKeyFailed) return;
|
|
1532
|
+
if (matches.length && (!requireAllTokens || this._coversAllTokens(matches))) {
|
|
1533
|
+
const result = {
|
|
1534
|
+
idx,
|
|
1535
|
+
item,
|
|
1536
|
+
matches
|
|
1537
|
+
};
|
|
1538
|
+
if (heap) {
|
|
1539
|
+
result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
|
|
1540
|
+
if (heap.shouldInsert(result.score)) heap.insert(result);
|
|
1541
|
+
} else results.push(result);
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
return results;
|
|
1545
|
+
}
|
|
1546
|
+
_findMatches({ key, value, searcher }) {
|
|
1547
|
+
if (!isDefined(value)) return [];
|
|
1548
|
+
const matches = [];
|
|
1549
|
+
if (isArray(value)) value.forEach(({ v: text, i: idx, n: norm }) => {
|
|
1550
|
+
if (!isDefined(text)) return;
|
|
1551
|
+
const searchResult = searcher.searchIn(text);
|
|
1552
|
+
if (searchResult.isMatch) {
|
|
1553
|
+
const match = {
|
|
1554
|
+
score: searchResult.score,
|
|
1555
|
+
key,
|
|
1556
|
+
value: text,
|
|
1557
|
+
idx,
|
|
1558
|
+
norm,
|
|
1559
|
+
indices: searchResult.indices,
|
|
1560
|
+
hasInverse: searchResult.hasInverse
|
|
1561
|
+
};
|
|
1562
|
+
if (searchResult.termCount !== void 0) {
|
|
1563
|
+
match.matchedMask = searchResult.matchedMask;
|
|
1564
|
+
match.matchedTerms = searchResult.matchedTerms;
|
|
1565
|
+
match.termCount = searchResult.termCount;
|
|
1566
|
+
}
|
|
1567
|
+
matches.push(match);
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
else {
|
|
1571
|
+
const { v: text, n: norm } = value;
|
|
1572
|
+
const searchResult = searcher.searchIn(text);
|
|
1573
|
+
if (searchResult.isMatch) {
|
|
1574
|
+
const match = {
|
|
1575
|
+
score: searchResult.score,
|
|
1576
|
+
key,
|
|
1577
|
+
value: text,
|
|
1578
|
+
norm,
|
|
1579
|
+
indices: searchResult.indices,
|
|
1580
|
+
hasInverse: searchResult.hasInverse
|
|
1581
|
+
};
|
|
1582
|
+
if (searchResult.termCount !== void 0) {
|
|
1583
|
+
match.matchedMask = searchResult.matchedMask;
|
|
1584
|
+
match.matchedTerms = searchResult.matchedTerms;
|
|
1585
|
+
match.termCount = searchResult.termCount;
|
|
1586
|
+
}
|
|
1587
|
+
matches.push(match);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
return matches;
|
|
1591
|
+
}
|
|
1592
|
+
_coversAllTokens(matches) {
|
|
1593
|
+
const termCount = matches.length ? matches[0].termCount : void 0;
|
|
1594
|
+
if (termCount === void 0) return true;
|
|
1595
|
+
if (termCount <= 31) {
|
|
1596
|
+
let coverage = 0;
|
|
1597
|
+
for (let i = 0; i < matches.length; i++) coverage |= matches[i].matchedMask || 0;
|
|
1598
|
+
return coverage === 2 ** termCount - 1;
|
|
1599
|
+
}
|
|
1600
|
+
const coverage = /* @__PURE__ */ new Set();
|
|
1601
|
+
for (let i = 0; i < matches.length; i++) {
|
|
1602
|
+
const terms = matches[i].matchedTerms;
|
|
1603
|
+
if (terms) for (const t of terms) coverage.add(t);
|
|
1604
|
+
}
|
|
1605
|
+
return coverage.size === termCount;
|
|
1606
|
+
}
|
|
1607
|
+
};
|
|
1794
1608
|
|
|
1795
|
-
|
|
1609
|
+
//#endregion
|
|
1610
|
+
//#region src/entry.ts
|
|
1611
|
+
Fuse.version = "7.4.2";
|
|
1796
1612
|
Fuse.createIndex = createIndex;
|
|
1797
1613
|
Fuse.parseIndex = parseIndex;
|
|
1798
1614
|
Fuse.config = Config;
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1615
|
+
Fuse.match = function(pattern, text, options) {
|
|
1616
|
+
if (options && options.useTokenSearch) throw new Error(FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED);
|
|
1617
|
+
return createSearcher(pattern, {
|
|
1618
|
+
...Config,
|
|
1619
|
+
...options
|
|
1620
|
+
}).searchIn(text);
|
|
1621
|
+
};
|
|
1622
|
+
Fuse.parseQuery = parse;
|
|
1623
|
+
register(ExtendedSearch);
|
|
1624
|
+
register(TokenSearch);
|
|
1625
|
+
Fuse.use = function(...plugins) {
|
|
1626
|
+
plugins.forEach((plugin) => register(plugin));
|
|
1627
|
+
};
|
|
1628
|
+
var entry_default = Fuse;
|
|
1807
1629
|
|
|
1808
1630
|
const GreenCheckDuotoneIcon = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
1809
1631
|
<path d="M7.99996 2.6665C5.05444 2.6665 2.66663 5.05432 2.66663 7.99984C2.66663 10.9454 5.05444 13.3332 7.99996 13.3332C10.9455 13.3332 13.3333 10.9454 13.3333 7.99984C13.3333 5.05432 10.9455 2.6665 7.99996 2.6665Z" fill="#AFF8C3"/>
|
|
@@ -1851,7 +1673,7 @@ const ZonosCountrySelect = class {
|
|
|
1851
1673
|
render() {
|
|
1852
1674
|
const { helloCountryList } = localization.localizationStore;
|
|
1853
1675
|
const countries = helloCountryList ? Object.values(helloCountryList) : [];
|
|
1854
|
-
const fuse = new
|
|
1676
|
+
const fuse = new entry_default(countries, {
|
|
1855
1677
|
includeScore: true,
|
|
1856
1678
|
keys: ['displayName'],
|
|
1857
1679
|
threshold: 0.3,
|